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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-drawing): drawing on uni mode (#3009)
zhangw96446951aa81
diff --git a/packages/drawing-ui/src/controllers/image-update.controller.ts b/packages/drawing-ui/src/controllers/image-update.controller.tsindex beeb8e3416..acf404a10f 100644--- a/packages/drawing-ui/src/controllers/image-update.controller.ts+++ b/packages/drawing-ui/src/controllers/image-update.controller.ts@@ -203,7 +203,7 @@ export class ImageUpdateController extends Disposable {(params).forEach(async (param) => {const { unitId, subUnitId, drawingId } = param;const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);- const currentSubUnitId = getCurrentUnitInfo(this._currentUniverService)?.subUnitId;+ const currentSubUnitId = getCurrentUnitInfo(this._currentUniverService, unitId)?.subUnitId;if (renderObject == null || currentSubUnitId !== subUnitId) {return;diff --git a/packages/drawing-ui/src/controllers/utils.ts b/packages/drawing-ui/src/controllers/utils.tsindex 6ced585bf6..a420550c45 100644--- a/packages/drawing-ui/src/controllers/utils.ts+++ b/packages/drawing-ui/src/controllers/utils.ts@@ -56,8 +56,8 @@ export function insertGroupObject(objectParam: IDrawingSearch, object: BaseObjec);}-export function getCurrentUnitInfo(currentUniverService: IUniverInstanceService) {- const current = currentUniverService.getFocusedUnit();+export function getCurrentUnitInfo(currentUniverService: IUniverInstanceService, propUnitId?: string) {+ const current = propUnitId ? currentUniverService.getUnit(propUnitId) : currentUniverService.getFocusedUnit();if (current == null) {return;}diff --git a/packages/sheets-drawing-ui/src/basics/transform-position.ts b/packages/sheets-drawing-ui/src/basics/transform-position.tsindex 127ea9b306..4f47a2d5b1 100644--- a/packages/sheets-drawing-ui/src/basics/transform-position.ts+++ b/packages/sheets-drawing-ui/src/basics/transform-position.ts@@ -18,7 +18,7 @@ import type { Nullable } from '@univerjs/core';import type { ITransformState } from '@univerjs/drawing';import { precisionTo } from '@univerjs/engine-render';import type { ISheetDrawingPosition } from '@univerjs/sheets-drawing';-import type { ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';+import { attachRangeWithCoord, type ISheetSelectionRenderService, type SheetSkeletonManagerService } from '@univerjs/sheets-ui';export function drawingPositionToTransform(position: ISheetDrawingPosition,@@ -27,8 +27,9 @@ export function drawingPositionToTransform(const { from, to, flipY = false, flipX = false, angle = 0, skewX = 0, skewY = 0 } = position;const { column: fromColumn, columnOffset: fromColumnOffset, row: fromRow, rowOffset: fromRowOffset } = from;const { column: toColumn, columnOffset: toColumnOffset, row: toRow, rowOffset: toRowOffset } = to;+ const skeleton = sheetSkeletonManagerService.getCurrentSkeleton()!;- const startSelectionCell = sheetSkeletonManagerService.attachRangeWithCoord({+ const startSelectionCell = attachRangeWithCoord(skeleton, {startColumn: fromColumn,endColumn: fromColumn,startRow: fromRow,@@ -39,7 +40,7 @@ export function drawingPositionToTransform(return;}- const endSelectionCell = sheetSkeletonManagerService.attachRangeWithCoord({+ const endSelectionCell = attachRangeWithCoord(skeleton, {startColumn: toColumn,endColumn: toColumn,startRow: toRow,@@ -68,7 +69,6 @@ export function drawingPositionToTransform(height = 0;}- const skeleton = sheetSkeletonManagerService.getCurrentSkeleton()!;const sheetWidth = skeleton.rowHeaderWidth + skeleton.columnTotalWidth;const sheetHeight = skeleton.columnHeaderHeight + skeleton.rowTotalHeight;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.tsindex a47d1c07a3..7a06d3a93d 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@@ -25,7 +25,7 @@ import { SheetsSelectionsService } from '@univerjs/sheets';import { attachRangeWithCoord, ISheetSelectionRenderService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';import { IMessageService } from '@univerjs/ui';import { MessageType } from '@univerjs/design';-import type { IRenderContext } from '@univerjs/engine-render';+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';import type { IInsertImageOperationParams } from '../commands/operations/insert-image.operation';import { InsertCellImageOperation, InsertFloatImageOperation } from '../commands/operations/insert-image.operation';import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-drawing.command';@@ -37,7 +37,7 @@ import { GroupSheetDrawingCommand } from '../commands/commands/group-sheet-drawiimport { UngroupSheetDrawingCommand } from '../commands/commands/ungroup-sheet-drawing.command';import { drawingPositionToTransform, transformToDrawingPosition } from '../basics/transform-position';-export class SheetDrawingUpdateController extends Disposable {+export class SheetDrawingUpdateController extends Disposable implements IRenderModule {private readonly _workbookSelections: WorkbookSelections;constructor(private readonly _context: IRenderContext<Workbook>,@@ -368,7 +368,7 @@ export class SheetDrawingUpdateController extends Disposable {(params).forEach((param) => {const drawingParam = this._sheetDrawingService.getDrawingByParam(param) as ISheetDrawing;- if (drawingParam == null) {+ if (drawingParam == null || drawingParam.unitId !== this._context.unitId) {return;}diff --git a/packages/sheets-drawing/package.json b/packages/sheets-drawing/package.jsonindex 9a06d6f082..ed68b0ce33 100644--- a/packages/sheets-drawing/package.json+++ b/packages/sheets-drawing/package.json@@ -60,11 +60,13 @@"peerDependencies": {"@univerjs/core": "workspace:*","@univerjs/drawing": "workspace:*",+ "@univerjs/engine-render": "workspace:*","rxjs": ">=7.0.0"},"devDependencies": {"@univerjs/core": "workspace:*","@univerjs/drawing": "workspace:*",+ "@univerjs/engine-render": "workspace:*","@univerjs/shared": "workspace:*","@univerjs/sheets": "workspace:*","typescript": "^5.5.4",diff --git a/packages/sheets-drawing/src/controllers/render-controllers/sheet-drawing.render-controller.ts b/packages/sheets-drawing/src/controllers/render-controllers/sheet-drawing.render-controller.tsnew file mode 100644index 0000000000..48264b46bb--- /dev/null+++ b/packages/sheets-drawing/src/controllers/render-controllers/sheet-drawing.render-controller.ts@@ -0,0 +1,44 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { Disposable, Inject, LifecycleService, LifecycleStages, UniverInstanceType } from '@univerjs/core';+import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';+import { filter, first } from 'rxjs';+import { ISheetDrawingService } from '../../services/sheet-drawing.service';++export class SheetsDrawingRenderController extends Disposable implements IRenderModule {+ constructor(+ private _context: IRenderContext,+ @ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService,+ @Inject(LifecycleService) private _lifecycleService: LifecycleService+ ) {+ super();++ this._init();+ }++ private _init(): void {+ this._drawingInitializeListener();+ }++ private _drawingInitializeListener() {+ this._lifecycleService.lifecycle$.pipe(filter((e) => e === LifecycleStages.Steady), first()).subscribe(() => {+ if (this._context.type === UniverInstanceType.UNIVER_SHEET) {+ this._sheetDrawingService.initializeNotification(this._context.unitId);+ }+ });+ }+}diff --git a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.tsindex 0aeb174373..c3e32433df 100644--- a/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts+++ b/packages/sheets-drawing/src/controllers/sheet-drawing.controller.ts@@ -14,10 +14,9 @@* limitations under the License.*/-import { Disposable, ICommandService, Inject, IResourceManagerService, IUniverInstanceService, LifecycleService, 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 { filter, first } from 'rxjs/operators';import type { ISheetDrawing } from '../services/sheet-drawing.service';import { ISheetDrawingService } from '../services/sheet-drawing.service';import { SetDrawingApplyMutation } from '../commands/mutations/set-drawing-apply.mutation';@@ -27,32 +26,14 @@ export const SHEET_DRAWING_PLUGIN = 'SHEET_DRAWING_PLUGIN';@OnLifecycle(LifecycleStages.Starting, SheetsDrawingLoadController)export class SheetsDrawingLoadController extends Disposable {constructor(- @ICommandService private readonly _commandService: ICommandService- ) {- super();-- this.disposeWithMe(this._commandService.registerCommand(SetDrawingApplyMutation));- }-}--@OnLifecycle(LifecycleStages.Starting, SheetsDrawingController)-export class SheetsDrawingController extends Disposable {- constructor(+ @ICommandService private readonly _commandService: ICommandService,@ISheetDrawingService private readonly _sheetDrawingService: ISheetDrawingService,@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,- @IResourceManagerService private _resourceManagerService: IResourceManagerService,- @Inject(LifecycleService) private _lifecycleService: LifecycleService,- @IUniverInstanceService private _univerInstanceService: IUniverInstanceService+ @IResourceManagerService private _resourceManagerService: IResourceManagerService) {super();-- this._init();- }-- private _init(): void {this._initSnapshot();-- this._drawingInitializeListener();+ this.disposeWithMe(this._commandService.registerCommand(SetDrawingApplyMutation));}private _initSnapshot() {@@ -89,14 +70,5 @@ export class SheetsDrawingController extends Disposable {}));}-- private _drawingInitializeListener() {- this._lifecycleService.lifecycle$.pipe(filter((e) => e === LifecycleStages.Steady), first()).subscribe(() => {- const unitId = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)?.getUnitId();- if (!unitId) {- return;- }- this._sheetDrawingService.initializeNotification(unitId);- });- }}+diff --git a/packages/sheets-drawing/src/plugin.ts b/packages/sheets-drawing/src/plugin.tsindex f712c956f7..5e7557044e 100644--- a/packages/sheets-drawing/src/plugin.ts+++ b/packages/sheets-drawing/src/plugin.ts@@ -16,8 +16,10 @@import { Inject, Injector, Plugin, UniverInstanceType } from '@univerjs/core';import type { Dependency } from '@univerjs/core';-import { SHEET_DRAWING_PLUGIN, SheetsDrawingController, SheetsDrawingLoadController } from './controllers/sheet-drawing.controller';+import { IRenderManagerService } from '@univerjs/engine-render';+import { SHEET_DRAWING_PLUGIN, SheetsDrawingLoadController } from './controllers/sheet-drawing.controller';import { ISheetDrawingService, SheetDrawingService } from './services/sheet-drawing.service';+import { SheetsDrawingRenderController } from './controllers/render-controllers/sheet-drawing.render-controller';export class UniverSheetsDrawingPlugin extends Plugin {static override pluginName = SHEET_DRAWING_PLUGIN;@@ -25,7 +27,8 @@ export class UniverSheetsDrawingPlugin extends Plugin {constructor(private readonly _config: unknown,- @Inject(Injector) override readonly _injector: Injector+ @Inject(Injector) override readonly _injector: Injector,+ @IRenderManagerService private readonly _renderManagerService: IRenderManagerService) {super();}@@ -33,8 +36,13 @@ export class UniverSheetsDrawingPlugin extends Plugin {override onStarting(): void {([[SheetsDrawingLoadController],- [SheetsDrawingController],[ISheetDrawingService, { useClass: SheetDrawingService }],] as Dependency[]).forEach((dependency) => this._injector.add(dependency));}++ override onRendered(): void {+ ([[SheetsDrawingRenderController]] as Dependency[]).forEach((m) => {+ this.disposeWithMe(this._renderManagerService.registerRenderModule(UniverInstanceType.UNIVER_SHEET, m));+ });+ }}diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 55ed5f923b..902449d87e 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1882,6 +1882,9 @@ importers:'@univerjs/drawing':specifier: workspace:*version: link:../drawing+ '@univerjs/engine-render':+ specifier: workspace:*+ version: link:../engine-render'@univerjs/shared':specifier: workspace:*version: link:../../common/shared