Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix: fix slide errors

Wenzhao Hu0145ea553aea
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 0de52c3e7f..0cdd4eb906 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,6 +1,7 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
+ "editor.rulers": [120],
"javascript.preferences.importModuleSpecifier": "relative",
"typescript.preferences.importModuleSpecifier": "relative",
"commentTranslate.targetLanguage": "zh-CN",
diff --git a/packages/engine-render/src/render-manager/render-manager.service.ts b/packages/engine-render/src/render-manager/render-manager.service.ts
index dfd3ce9338..04566eedac 100644
--- a/packages/engine-render/src/render-manager/render-manager.service.ts
+++ b/packages/engine-render/src/render-manager/render-manager.service.ts
@@ -127,10 +127,10 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
const dependencies = this._renderDependencies.get(type)!;
dependencies.push(...deps);
- for (const [renderUnitId, render] of this._renderMap) {
- const renderType = this._univerInstanceService.getUnitType(renderUnitId);
+ for (const [_, render] of this._renderMap) {
+ const renderType = render.type;
if (renderType === type) {
- (render as RenderUnit).addRenderDependencies(deps);
+ this._tryAddRenderDependencies(render, deps);
}
}
@@ -147,23 +147,10 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
const dependencies = this._renderDependencies.get(type)!;
dependencies.push(ctor);
- for (const [renderUnitId, render] of this._renderMap) {
- if (type === UniverInstanceType.UNIVER_SLIDE) {
- // const renderType = this._univerInstanceService.getUnitType(renderUnitId);
- // renderUnitId slide_test cover_1 rect_1....
- const unit = this._univerInstanceService.getUnit(renderUnitId);
- if (unit && unit.type === type) {
- (render as RenderUnit).addRenderDependencies([ctor]);
- }
- } else {
- try {
- const renderType = this._univerInstanceService.getUnitType(renderUnitId);
- if (renderType === type) {
- (render as RenderUnit).addRenderDependencies([ctor]);
- }
- } catch (e) {
- console.error('error', e);
- }
+ for (const [_, render] of this._renderMap) {
+ const renderType = render.type;
+ if (renderType === type) {
+ this._tryAddRenderDependencies(render, [ctor]);
}
}
@@ -210,6 +197,12 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
return this.getRenderById(current.getUnitId())?.with(id);
}
+ private _tryAddRenderDependencies(renderer: IRender, deps: Dependency[]): void {
+ if (renderer instanceof RenderUnit) {
+ renderer.addRenderDependencies(deps);
+ }
+ }
+
private _createRender(unitId: string, engine: Engine, isMainScene: boolean = true): IRender {
const existItem = this.getRenderById(unitId);
let shouldDestroyEngine = true;
@@ -243,11 +236,12 @@ export class RenderManagerService extends Disposable implements IRenderManagerSe
isMainScene,
});
- (renderUnit as RenderUnit).addRenderDependencies(ctors);
+ this._tryAddRenderDependencies(renderUnit, ctors);
} else {
// For slide pages
renderUnit = {
unitId,
+ type: UniverInstanceType.UNIVER_SLIDE,
engine,
scene,
mainComponent: null,
diff --git a/packages/engine-render/src/render-manager/render-unit.ts b/packages/engine-render/src/render-manager/render-unit.ts
index 1eefdc3586..a95bc61a5c 100644
--- a/packages/engine-render/src/render-manager/render-unit.ts
+++ b/packages/engine-render/src/render-manager/render-unit.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType } from '@univerjs/core';
+import type { Dependency, DependencyIdentifier, IDisposable, Nullable, UnitModel, UnitType, UniverInstanceType } from '@univerjs/core';
import { Disposable, Inject, Injector, isClassDependencyItem } from '@univerjs/core';
import type { Engine } from '../engine';
import type { Scene } from '../scene';
@@ -22,6 +22,7 @@ import type { RenderComponentType } from './render-manager.service';
export interface IRender {
unitId: string;
+ type: UniverInstanceType;
engine: Engine;
scene: Scene;
mainComponent: Nullable<RenderComponentType>;
diff --git a/packages/slides-ui/src/controllers/slide-ui.controller.ts b/packages/slides-ui/src/controllers/slide-ui.controller.ts
index 4f379440ac..7b5977c86c 100644
--- a/packages/slides-ui/src/controllers/slide-ui.controller.ts
+++ b/packages/slides-ui/src/controllers/slide-ui.controller.ts
@@ -15,7 +15,7 @@
*/
import type { DependencyOverride } from '@univerjs/core';
-import { connectInjector, Disposable, ICommandService, Inject, Injector } from '@univerjs/core';
+import { connectInjector, Disposable, ICommandService, Inject, Injector, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { AddImageSingle, GraphSingle, TextSingle } from '@univerjs/icons';
import type { MenuConfig } from '@univerjs/ui';
import { BuiltInUIPart, ComponentManager, IMenuService, IShortcutService, IUIPartsService } from '@univerjs/ui';
@@ -51,6 +51,7 @@ export const DefaultSlidesDrawingConfig: IUniverSlidesDrawingConfig = {
* This controller registers UI parts of slide workbench to the base-ui workbench.
*/
// @OnLifecycle(LifecycleStages.Ready, SlideUIController)
+@OnLifecycle(LifecycleStages.Ready, SlideUIController)
export class SlideUIController extends Disposable {
constructor(
private readonly _config: Partial<IUniverSlidesDrawingConfig>,
diff --git a/packages/slides-ui/src/services/slide-editor-bridge.service.ts b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
index 7c2a484315..c67de57e9e 100644
--- a/packages/slides-ui/src/services/slide-editor-bridge.service.ts
+++ b/packages/slides-ui/src/services/slide-editor-bridge.service.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IDisposable, IDocumentBody, IDocumentData, IDocumentSettings, IDocumentStyle, IParagraph, IParagraphStyle, IPosition, Nullable, UnitModel } from '@univerjs/core';
+import type { IDisposable, IDocumentBody, IDocumentData, IDocumentSettings, IDocumentStyle, IParagraph, IParagraphStyle, IPosition, Nullable } from '@univerjs/core';
import {
createIdentifier,
Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
@@ -23,13 +23,10 @@ import {
FOCUSING_EDITOR_STANDALONE,
FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE,
IContextService,
- Inject,
- IUniverInstanceService,
- ThemeService,
VerticalAlign,
} from '@univerjs/core';
-import type { Engine, IDocumentLayoutObject, IRenderContext, RichText, Scene } from '@univerjs/engine-render';
-import { DeviceInputEventType, IRenderManagerService } from '@univerjs/engine-render';
+import type { Engine, IDocumentLayoutObject, RichText, Scene } from '@univerjs/engine-render';
+import { DeviceInputEventType } from '@univerjs/engine-render';
import type { KeyCode } from '@univerjs/ui';
import { IEditorService } from '@univerjs/ui';
import type { Observable } from 'rxjs';
@@ -111,10 +108,6 @@ export class SlideEditorBridgeService extends Disposable implements ISlideEditor
private _currentEditRectInfo: ISetEditorInfo;
constructor(
- private readonly _renderContext: IRenderContext<UnitModel>,
- @IRenderManagerService private readonly _renderManagerService: IRenderManagerService,
- @Inject(ThemeService) private readonly _themeService: ThemeService,
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@IEditorService private readonly _editorService: IEditorService,
@IContextService private readonly _contextService: IContextService
) {
diff --git a/packages/slides-ui/src/slides-ui-plugin.ts b/packages/slides-ui/src/slides-ui-plugin.ts
index bd9a60ccb1..a4a9f33432 100644
--- a/packages/slides-ui/src/slides-ui-plugin.ts
+++ b/packages/slides-ui/src/slides-ui-plugin.ts
@@ -61,14 +61,13 @@ export class UniverSlidesUIPlugin extends Plugin {
// This controller should be registered in Ready stage.
// this controller would add a new RenderUnit (__INTERNAL_EDITOR__DOCS_NORMAL)
- // so this new RenderUnit does not have ISlideEditorBridgeService & ISlideEditorManagerService if editorservice were create in renderManagerService
- [
- SlideUIController,
- ],
+ // so this new RenderUnit does not have ISlideEditorBridgeService & ISlideEditorManagerService if
+ // editorservice were create in renderManagerService
+ [SlideUIController],
[SlideRenderController],
[SlidePopupMenuController],
] as Dependency[]).forEach((m) => {
- this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SLIDE, m));
+ this._injector.add(m);
});
}