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(sheet): drawing load (#2692)

Univer2c5011e17bf9
diff --git a/packages/drawing/src/services/drawing-manager-impl.service.ts b/packages/drawing/src/services/drawing-manager-impl.service.ts
index 594f6efa63..cfc72042af 100644
--- a/packages/drawing/src/services/drawing-manager-impl.service.ts
+++ b/packages/drawing/src/services/drawing-manager-impl.service.ts
@@ -169,7 +169,16 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawing
registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>) {
this.drawingManagerData[unitId] = data;
+ }
+
+ initializeNotification(unitId: string) {
const drawings: T[] = [];
+ const data = this.drawingManagerData[unitId];
+
+ if (data == null) {
+ return;
+ }
+
Object.keys(data).forEach((subUnitId) => {
this._establishDrawingMap(unitId, subUnitId);
@@ -177,6 +186,8 @@ export class UnitDrawingService<T extends IDrawingParam> implements IUnitDrawing
Object.keys(subUnitData.data).forEach((drawingId) => {
const drawing = subUnitData.data[drawingId];
+ drawing.unitId = unitId;
+ drawing.subUnitId = subUnitId;
drawings.push(drawing);
});
});
diff --git a/packages/drawing/src/services/drawing-manager.service.ts b/packages/drawing/src/services/drawing-manager.service.ts
index 3d82b14a61..6f01f23176 100644
--- a/packages/drawing/src/services/drawing-manager.service.ts
+++ b/packages/drawing/src/services/drawing-manager.service.ts
@@ -185,6 +185,8 @@ export interface IUnitDrawingService<T extends IDrawingParam> extends IUnitNorma
removeDrawingDataForUnit(unitId: string): void;
registerDrawingData(unitId: string, data: IDrawingSubunitMap<T>): void;
+ initializeNotification(unitId: string): void;
+
getDrawingData(unitId: string, subUnitId: string): IDrawingMapItemData<T>;
getDrawingByParam(param: Nullable<IDrawingSearch>): Nullable<T>;
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
index a48dea36ae..981a013d9c 100644
--- a/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
+++ b/packages/sheets-drawing-ui/src/controllers/sheet-drawing-update.controller.ts
@@ -404,5 +404,6 @@ export class SheetDrawingUpdateController extends Disposable implements IRenderM
const unitId = params[0].unitId;
this._drawingManagerService.registerDrawingData(unitId, this._sheetDrawingService.getDrawingDataForUnit(unitId));
+ this._drawingManagerService.initializeNotification(unitId);
}
}
diff --git a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
index 6408d5777c..56658e143e 100644
--- a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
+++ b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-import { Disposable, ICommandService, IResourceManagerService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
+import { Disposable, ICommandService, IResourceManagerService, IUniverInstanceService, LifecycleService, LifecycleStages, OnLifecycle, UniverInstanceType } from '@univerjs/core';
import type { IDrawingSubunitMap } from '@univerjs/drawing';
import { IDrawingManagerService } from '@univerjs/drawing';
+import { Inject } from '@wendellhu/redi';
import type { ISheetDrawing } from '../services/sheet-drawing.service';
import { ISheetDrawingService } from '../services/sheet-drawing.service';
import { SetDrawingApplyMutation } from '../commands/mutations/set-drawing-apply.mutation';
@@ -34,12 +35,14 @@ export class SheetsDrawingLoadController extends Disposable {
}
}
-@OnLifecycle(LifecycleStages.Steady, SheetsDrawingController)
+@OnLifecycle(LifecycleStages.Ready, SheetsDrawingController)
export class SheetsDrawingController extends Disposable {
constructor(
@ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService,
@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,
- @IResourceManagerService private _resourceManagerService: IResourceManagerService
+ @IResourceManagerService private _resourceManagerService: IResourceManagerService,
+ @Inject(LifecycleService) private _lifecycleService: LifecycleService,
+ @IUniverInstanceService private _univerInstanceService: IUniverInstanceService
) {
super();
@@ -48,6 +51,8 @@ export class SheetsDrawingController extends Disposable {
private _init(): void {
this._initSnapshot();
+
+ this._drawingInitializeListener();
}
private _initSnapshot() {
@@ -84,4 +89,18 @@ export class SheetsDrawingController extends Disposable {
})
);
}
+
+ private _drawingInitializeListener() {
+ this.disposeWithMe(
+ this._lifecycleService.lifecycle$.subscribe((stage) => {
+ if (stage === LifecycleStages.Steady) {
+ const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)?.getUnitId();
+ if (!unitId) {
+ return;
+ }
+ this._sheetDrawingService.initializeNotification(unitId);
+ }
+ })
+ );
+ }
}