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
feat(sheets-drawing-ui): change cell-image resize to render phase (#4809)
ZhangWeia4aee931c0ac
diff --git a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.tsindex 7702f2ed2c..ecec2a7cdb 100644--- a/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts+++ b/packages/sheets-drawing-ui/src/controllers/sheet-cell-image.controller.ts@@ -14,17 +14,17 @@* limitations under the License.*/-import type { ICellData, IDocDrawingBase, IRange, Nullable } from '@univerjs/core';+import type { ICellData, IDocDrawingBase, Nullable } from '@univerjs/core';import type { IReplaceSnapshotCommandParams } from '@univerjs/docs-ui';import type { IImageData } from '@univerjs/drawing';-import type { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams, ISetWorksheetColWidthMutationParams, ISetWorksheetRowAutoHeightMutationParams, ISetWorksheetRowHeightMutationParams, ISetWorksheetRowIsAutoHeightMutationParams, ISheetLocationBase } from '@univerjs/sheets';+import type { ISheetLocationBase } from '@univerjs/sheets';import type { IEditorBridgeServiceVisibleParam } from '@univerjs/sheets-ui';-import { Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, ICommandService, Inject, Injector, InterceptorEffectEnum, IUniverInstanceService, Range } from '@univerjs/core';+import { Disposable, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_ZEN_EDITOR_UNIT_ID_KEY, ICommandService, Inject, Injector, InterceptorEffectEnum } from '@univerjs/core';import { DocDrawingController } from '@univerjs/docs-drawing';import { ReplaceSnapshotCommand } from '@univerjs/docs-ui';import { IDrawingManagerService } from '@univerjs/drawing';import { DeviceInputEventType } from '@univerjs/engine-render';-import { AddWorksheetMergeMutation, AFTER_CELL_EDIT, getSheetCommandTarget, InterceptCellContentPriority, INTERCEPTOR_POINT, RemoveWorksheetMergeMutation, SetWorksheetColWidthMutation, SetWorksheetRowAutoHeightMutation, SetWorksheetRowHeightMutation, SetWorksheetRowIsAutoHeightMutation, SheetInterceptorService } from '@univerjs/sheets';+import { InterceptCellContentPriority, INTERCEPTOR_POINT, SheetInterceptorService } from '@univerjs/sheets';import { IEditorBridgeService, SetCellEditVisibleOperation } from '@univerjs/sheets-ui';import { getDrawingSizeByCell } from './sheet-drawing-update.controller';@@ -67,7 +67,6 @@ export class SheetCellImageController extends Disposable {constructor(@ICommandService private readonly _commandService: ICommandService,@Inject(SheetInterceptorService) private readonly _sheetInterceptorService: SheetInterceptorService,- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,@Inject(Injector) private readonly _injector: Injector,@IDrawingManagerService private readonly _drawingManagerService: IDrawingManagerService,@Inject(DocDrawingController) private readonly _docDrawingController: DocDrawingController,@@ -75,9 +74,7 @@ export class SheetCellImageController extends Disposable {) {super();- this._initHandleResize();this._handleInitEditor();- this._handleWriteCell();this._initCellContentInterceptor();this._initDisableEdit();}@@ -98,54 +95,6 @@ export class SheetCellImageController extends Disposable {}));}- private _initHandleResize() {- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {- let sheetTarget: Nullable<ReturnType<typeof getSheetCommandTarget>>;- let ranges: IRange[] = [];- if (commandInfo.id === SetWorksheetRowHeightMutation.id) {- const params = commandInfo.params as ISetWorksheetRowHeightMutationParams;- ranges = params.ranges;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- } else if (commandInfo.id === SetWorksheetColWidthMutation.id) {- const params = commandInfo.params as ISetWorksheetColWidthMutationParams;- ranges = params.ranges;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- } else if (commandInfo.id === SetWorksheetRowIsAutoHeightMutation.id) {- const params = commandInfo.params as ISetWorksheetRowIsAutoHeightMutationParams;- ranges = params.ranges;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- } else if (commandInfo.id === SetWorksheetRowAutoHeightMutation.id) {- const params = commandInfo.params as ISetWorksheetRowAutoHeightMutationParams;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- ranges = params.rowsAutoHeightInfo.map((info) => ({- startRow: info.row,- endRow: info.row,- startColumn: 0,- endColumn: 9999,- }));- } else if (commandInfo.id === AddWorksheetMergeMutation.id) {- const params = commandInfo.params as IAddWorksheetMergeMutationParams;- ranges = params.ranges;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- } else if (commandInfo.id === RemoveWorksheetMergeMutation.id) {- const params = commandInfo.params as IRemoveWorksheetMergeMutationParams;- ranges = params.ranges;- sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId: params.unitId, subUnitId: params.subUnitId });- }-- if (sheetTarget && (ranges.length)) {- ranges.forEach((range) => {- const normalizedRange = Range.transformRange(range, sheetTarget.worksheet);- for (let row = normalizedRange.startRow; row <= normalizedRange.endRow; row++) {- for (let col = normalizedRange.startColumn; col <= normalizedRange.endColumn; col++) {- resizeImageByCell(this._injector, { unitId: sheetTarget.unitId, subUnitId: sheetTarget.subUnitId, row, col }, sheetTarget.worksheet.getCellRaw(row, col));- }- }- });- }- }));- }-private _handleInitEditor() {this.disposeWithMe(this._editorBridgeService.visible$.subscribe((param) => {if (!param.visible) {@@ -170,16 +119,6 @@ export class SheetCellImageController extends Disposable {}));}- private _handleWriteCell() {- this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(AFTER_CELL_EDIT, {- priority: 9999,- handler: (cell, context, next) => {- resizeImageByCell(this._injector, { unitId: context.unitId, subUnitId: context.subUnitId, row: context.row, col: context.col }, cell);- return next(cell);- },- }));- }-private _initCellContentInterceptor() {this.disposeWithMe(this._sheetInterceptorService.intercept(@@ -192,8 +131,9 @@ export class SheetCellImageController extends Disposable {if (!cell.interceptorStyle) {cell.interceptorStyle = {};}-cell.interceptorStyle.tr = { a: 0 };++ resizeImageByCell(this._injector, { unitId: pos.unitId, subUnitId: pos.subUnitId, row: pos.row, col: pos.col }, cell);}return next(cell);