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(facade): fix FWorksheet.removeFloatDom api (#6904)
wpxp1234561b4edb9156fe
diff --git a/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.pngindex d542a21683..50422d45a1 100644Binary files a/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-scroll.spec.ts-snapshots/mergedCellsRenderingScrolling-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.pngindex 0b7cbe981d..17d1af21ae 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/dark-mode-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.pngindex c7c875e75d..da6b630f18 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/default-sheet-fullpage-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.pngindex 7e1ed3c1a3..1bf4c21cb6 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/defaultstyle-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.pngindex 7a5130ae41..1bf4c21cb6 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/facade-sheet-hooks-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.pngindex a03e1b9f4a..9beaff315f 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-force-string-cell-ci-chromium-linux.png differdiff --git a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.pngindex a9396b0651..80950cb48e 100644Binary files a/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png and b/e2e/visual-comparison/sheets/sheets-visual-comparison.spec.ts-snapshots/set-text-format-number-cell-ci-chromium-linux.png differdiff --git a/examples/src/sheets/custom/custom-float-dom/component.tsx b/examples/src/sheets/custom/custom-float-dom/component.tsxnew file mode 100644index 0000000000..7eae5b20b1--- /dev/null+++ b/examples/src/sheets/custom/custom-float-dom/component.tsx@@ -0,0 +1,36 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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.+ */++export const RangeLoading = () => {+ const divStyle = {+ width: '100%',+ height: '100%',+ backgroundColor: '#fff',+ border: '1px solid #ccc',+ boxSizing: 'border-box' as const,+ display: 'flex',+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center' as const,+ transformOrigin: 'top left',+ };++ return (+ <div style={divStyle}>+ Loading...+ </div>+ );+};diff --git a/examples/src/sheets/custom/custom-float-dom/float-dom.ts b/examples/src/sheets/custom/custom-float-dom/float-dom.tsnew file mode 100644index 0000000000..9a9462381c--- /dev/null+++ b/examples/src/sheets/custom/custom-float-dom/float-dom.ts@@ -0,0 +1,39 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 type { Univer } from '@univerjs/core';+import type { FUniver } from '@univerjs/core/facade';+import { RangeLoading } from './component';++export function insertFloatDom(univer: Univer, univerAPI: FUniver) {+ univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {+ if (stage === univerAPI.Enum.LifecycleStages.Steady) {+ univerAPI.registerComponent('RangeLoading', RangeLoading);++ const fWorkbook = univerAPI.getActiveWorkbook()!;+ const fWorksheet = fWorkbook.getActiveSheet();+ const fRange = fWorksheet.getRange('A1:C3');+ const disposable = fWorksheet.addFloatDomToRange(fRange, { componentKey: 'RangeLoading' }, {}, 'myRangeLoading');+ console.warn('Float DOM', disposable);+ // remove float dom+ // if (disposable) {+ // disposable.dispose();+ // //or+ // fWorksheet.removeFloatDom(disposable.id);+ // }+ }+ });+}diff --git a/examples/src/sheets/custom/custom-range-popup.tsx b/examples/src/sheets/custom/custom-range-popup/custom-range-popup.tsxsimilarity index 100%rename from examples/src/sheets/custom/custom-range-popup.tsxrename to examples/src/sheets/custom/custom-range-popup/custom-range-popup.tsxdiff --git a/examples/src/sheets/custom/simple-range-popup.tsx b/examples/src/sheets/custom/custom-range-popup/simple-range-popup.tsxsimilarity index 100%rename from examples/src/sheets/custom/simple-range-popup.tsxrename to examples/src/sheets/custom/custom-range-popup/simple-range-popup.tsxdiff --git a/examples/src/sheets/main.ts b/examples/src/sheets/main.tsindex 5e7185d660..5f5d7def56 100644--- a/examples/src/sheets/main.ts+++ b/examples/src/sheets/main.ts@@ -52,10 +52,11 @@ import { UniverSheetsZenEditorPlugin } from '@univerjs/sheets-zen-editor';import { UniverUIPlugin } from '@univerjs/ui';import { UniverVue3AdapterPlugin } from '@univerjs/ui-adapter-vue3';import { UniverWebComponentAdapterPlugin } from '@univerjs/ui-adapter-web-component';+import { insertFloatDom } from './custom/custom-float-dom/float-dom';+import { simpleRangePopupDemo } from './custom/custom-range-popup/simple-range-popup';import { customRegisterEvent } from './custom/custom-register-event';import { UniverSheetsCustomShortcutPlugin } from './custom/custom-shortcut';import ImportCSVButtonPlugin from './custom/import-csv-button';-import { simpleRangePopupDemo } from './custom/simple-range-popup';import '@univerjs/sheets/facade';import '@univerjs/ui/facade';@@ -209,6 +210,7 @@ function createNewInstance() {customRegisterEvent(univer, window.univerAPI!);// customRangePopups(univer, window.univerAPI!);simpleRangePopupDemo(univer, window.univerAPI!);+ insertFloatDom(univer, window.univerAPI!);}createNewInstance();diff --git a/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts b/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.tsnew file mode 100644index 0000000000..5f6d08d9cc--- /dev/null+++ b/packages/sheets-drawing-ui/src/facade/__tests__/f-worksheet.spec.ts@@ -0,0 +1,39 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { describe, expect, it, vi } from 'vitest';+import { SheetCanvasFloatDomManagerService } from '../../services/canvas-float-dom-manager.service';+import { FWorksheetDrawingUIMixin } from '../f-worksheet';++describe('FWorksheetDrawingUIMixin', () => {+ it('delegates float dom removal to the manager service', () => {+ const removeFloatDom = vi.fn();++ const instance = Object.create(FWorksheetDrawingUIMixin.prototype) as any;+ instance._injector = {+ get: (token: unknown) => {+ if (token === SheetCanvasFloatDomManagerService) {+ return { removeFloatDom };+ }++ throw new Error('unexpected token');+ },+ };++ expect(instance.removeFloatDom('float-dom-1')).toBe(instance);+ expect(removeFloatDom).toHaveBeenCalledWith('float-dom-1');+ });+});diff --git a/packages/sheets-drawing-ui/src/facade/f-worksheet.ts b/packages/sheets-drawing-ui/src/facade/f-worksheet.tsindex 69488334cf..45b8000dea 100644--- a/packages/sheets-drawing-ui/src/facade/f-worksheet.ts+++ b/packages/sheets-drawing-ui/src/facade/f-worksheet.ts@@ -21,7 +21,7 @@ import type { IFComponentKey } from '@univerjs/sheets-ui/facade';import type { FRange } from '@univerjs/sheets/facade';import type { ISaveCellImagesOptions } from './f-range';import { SheetSkeletonService } from '@univerjs/sheets';-import { ISheetDrawingService, RemoveSheetDrawingCommand, SetSheetDrawingCommand, transformToAxisAlignPosition, transformToDrawingPosition } from '@univerjs/sheets-drawing';+import { ISheetDrawingService, SetSheetDrawingCommand, transformToAxisAlignPosition, transformToDrawingPosition } from '@univerjs/sheets-drawing';import { FileNamePart, IBatchSaveImagesService, SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';import { transformComponentKey } from '@univerjs/sheets-ui/facade';import { FWorksheet } from '@univerjs/sheets/facade';@@ -580,28 +580,7 @@ export class FWorksheetDrawingUIMixin extends FWorksheet implements IFWorksheetDoverride removeFloatDom(id: string): this {const floatDomService = this._injector.get(SheetCanvasFloatDomManagerService);- const info = floatDomService.getFloatDomInfo(id);- if (!info) return this;-- const { unitId, subUnitId } = info;- const drawingService = this._injector.get(ISheetDrawingService);- const drawing = drawingService.getDrawingByParam({- unitId,- subUnitId,- drawingId: id,- });-- if (!drawing) return this;-- // Then delete it- const res = this._commandService.syncExecuteCommand(RemoveSheetDrawingCommand.id, {- unitId,- drawings: [drawing],- });-- if (!res) {- throw new Error('removeFloatDom failed');- }+ floatDomService.removeFloatDom(id);return this;}diff --git a/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts b/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.tsnew file mode 100644index 0000000000..c292dee1a7--- /dev/null+++ b/packages/sheets-drawing-ui/src/services/__tests__/canvas-float-dom-manager.service.spec.ts@@ -0,0 +1,91 @@+/**+ * Copyright 2023-present DreamNum Co., Ltd.+ *+ * 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 { DrawingApplyType, SetDrawingApplyMutation } from '@univerjs/sheets-drawing';+import { describe, expect, it, vi } from 'vitest';+import { SheetCanvasFloatDomManagerService } from '../canvas-float-dom-manager.service';++function createService(drawing: unknown) {+ const dispose = vi.fn();+ const removeObject = vi.fn();+ const syncExecuteCommand = vi.fn(() => true);+ const getDrawingByParam = vi.fn(() => drawing);+ const getBatchRemoveOp = vi.fn(() => ({+ unitId: 'unit-1',+ subUnitId: 'sheet-1',+ redo: ['redo-op'],+ objects: ['object-1'],+ }));+ const service = Object.create(SheetCanvasFloatDomManagerService.prototype) as any;++ service._domLayerInfoMap = new Map([+ ['float-dom-1', {+ unitId: 'unit-1',+ subUnitId: 'sheet-1',+ dispose: { dispose },+ rect: { id: 'rect-1' },+ }],+ ]);+ service._drawingManagerService = { getDrawingByParam };+ service._commandService = { syncExecuteCommand };+ service._sheetDrawingService = { getBatchRemoveOp };+ service._getSceneAndTransformerByDrawingSearch = vi.fn(() => ({+ scene: { removeObject },+ }));++ return { service, dispose, removeObject, syncExecuteCommand, getDrawingByParam, getBatchRemoveOp };+}++describe('SheetCanvasFloatDomManagerService', () => {+ it('removes drawing-backed float doms through the shared remove path', () => {+ const drawing = {+ unitId: 'unit-1',+ subUnitId: 'sheet-1',+ drawingId: 'float-dom-1',+ };+ const { service, dispose, removeObject, syncExecuteCommand, getDrawingByParam, getBatchRemoveOp } = createService(drawing);++ service.removeFloatDom('float-dom-1');++ expect(dispose).toHaveBeenCalledTimes(1);+ expect(removeObject).toHaveBeenCalledWith({ id: 'rect-1' });+ expect(getDrawingByParam).toHaveBeenCalledWith({+ unitId: 'unit-1',+ subUnitId: 'sheet-1',+ drawingId: 'float-dom-1',+ });+ expect(getBatchRemoveOp).toHaveBeenCalledWith([drawing]);+ expect(syncExecuteCommand).toHaveBeenCalledWith(SetDrawingApplyMutation.id, {+ unitId: 'unit-1',+ subUnitId: 'sheet-1',+ op: ['redo-op'],+ objects: ['object-1'],+ type: DrawingApplyType.REMOVE,+ });+ expect(service.getFloatDomInfo('float-dom-1')).toBeUndefined();+ });++ it('removes runtime-only float doms directly', () => {+ const { service, dispose, removeObject, syncExecuteCommand } = createService(null);++ service.removeFloatDom('float-dom-1');++ expect(dispose).toHaveBeenCalledTimes(1);+ expect(removeObject).toHaveBeenCalledWith({ id: 'rect-1' });+ expect(syncExecuteCommand).not.toHaveBeenCalled();+ expect(service.getFloatDomInfo('float-dom-1')).toBeUndefined();+ });+});diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.tsindex d6bcc1d3f7..610a3b25e4 100644--- a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts@@ -751,6 +751,10 @@ export class SheetCanvasFloatDomManagerService extends Disposable {}}+ removeFloatDom(id: string, removeDrawing = true) {+ this._removeDom(id, removeDrawing);+ }+// eslint-disable-next-line max-lines-per-function, complexityaddFloatDomToRange(range: IRange, config: ICanvasFloatDom, domAnchor: Partial<IDOMAnchor>, propId?: string) {const target = getSheetCommandTarget(this._univerInstanceService, {@@ -908,6 +912,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {domAnchor,unitId,subUnitId,+ id: drawingId,} as unknown as ICanvasFloatDomInfo;const initedPosition = calcSheetFloatDomPosition(domRect, renderObject.renderUnit.scene, skeletonParam.skeleton, target.worksheet, floatDomInfo);@@ -1149,6 +1154,7 @@ export class SheetCanvasFloatDomManagerService extends Disposable {// position$,unitId,subUnitId,+ id: drawingId,boundsOfViewArea,domAnchor: domLayoutParam,scrollDirectionResponse: ScrollDirectionResponse.HORIZONTAL,