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: fix debugger plugin (#6506)
wpxp1234561444b4601493
diff --git a/common/debugger/src/controllers/config.schema.ts b/common/debugger/src/controllers/config.schema.tsindex 7fbd730629..6ba54c02a4 100644--- a/common/debugger/src/controllers/config.schema.ts+++ b/common/debugger/src/controllers/config.schema.ts@@ -15,6 +15,7 @@*/import type { MenuConfig } from '@univerjs/ui';+import { UniverInstanceType } from '@univerjs/core';export const DEBUGGER_PLUGIN_CONFIG_KEY = 'debugger.config';@@ -23,6 +24,7 @@ export const configSymbol = Symbol(DEBUGGER_PLUGIN_CONFIG_KEY);export interface IUniverDebuggerConfig {menu?: MenuConfig;fab?: boolean;+ fabEntryUnitType?: UniverInstanceType;performanceMonitor?: {enabled: boolean;};@@ -30,6 +32,7 @@ export interface IUniverDebuggerConfig {export const defaultPluginConfig: IUniverDebuggerConfig = {fab: true,+ fabEntryUnitType: UniverInstanceType.UNIVER_SHEET,performanceMonitor: {enabled: true,},diff --git a/common/debugger/src/views/Fab.tsx b/common/debugger/src/views/Fab.tsxindex 1544da734c..1190e5cf0e 100644--- a/common/debugger/src/views/Fab.tsx+++ b/common/debugger/src/views/Fab.tsx@@ -37,6 +37,11 @@ import { useUser } from './use-user';import { useWatermark } from './use-watermark';export function Fab() {+ const configService = useDependency(IConfigService);+ const configs = configService.getConfig<IUniverDebuggerConfig>(DEBUGGER_PLUGIN_CONFIG_KEY);+ const performanceMonitor = configs?.performanceMonitor;+ const fabEntryUnitType = configs?.fabEntryUnitType;+const locale = useLocale();const darkMode = useDarkMode();const theme = useTheme();@@ -45,18 +50,14 @@ export function Fab() {const message = useMessage();const dialog = useDialog();const sidebar = useSidebar();- const floatingDom = useFloatingDom();- const cellContent = useCellContent();+ const floatingDom = useFloatingDom(fabEntryUnitType);+ const cellContent = useCellContent(fabEntryUnitType);const units = useUnits();const snapshot = useSnapshot();const editable = useEditable();const user = useUser();const dispose = useDispose();- const configService = useDependency(IConfigService);- const configs = configService.getConfig<IUniverDebuggerConfig>(DEBUGGER_PLUGIN_CONFIG_KEY);- const performanceMonitor = configs?.performanceMonitor;-const univerInstanceService = useDependency(IUniverInstanceService);const unitType = univerInstanceService.getFocusedUnit()?.type;if (!unitType) return null;@@ -72,12 +73,12 @@ export function Fab() {dialog,sidebar,{ type: 'separator' },- unitType === UniverInstanceType.UNIVER_SHEET && floatingDom,- unitType === UniverInstanceType.UNIVER_SHEET && cellContent,- unitType === UniverInstanceType.UNIVER_SHEET && units,+ (fabEntryUnitType === UniverInstanceType.UNIVER_SHEET || fabEntryUnitType === UniverInstanceType.UNIVER_DOC) && floatingDom,+ fabEntryUnitType === UniverInstanceType.UNIVER_SHEET && cellContent,+ fabEntryUnitType === UniverInstanceType.UNIVER_SHEET && units,snapshot,editable,- unitType === UniverInstanceType.UNIVER_SHEET && user,+ fabEntryUnitType === UniverInstanceType.UNIVER_SHEET && user,dispose,].filter((item) => item !== null) as IDropdownMenuProps['items'];diff --git a/common/debugger/src/views/use-cell-content.ts b/common/debugger/src/views/use-cell-content.tsindex 059d91901f..cde56e284b 100644--- a/common/debugger/src/views/use-cell-content.ts+++ b/common/debugger/src/views/use-cell-content.ts@@ -14,16 +14,17 @@* limitations under the License.*/-import { ILogService, IUniverInstanceService, ObjectMatrix, Range } from '@univerjs/core';+import { ILogService, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';import { getSheetCommandTarget, SheetsSelectionsService } from '@univerjs/sheets';import { useDependency } from '@univerjs/ui';-export function useCellContent() {+export function useCellContent(fabEntryUnitType?: UniverInstanceType) {const logService = useDependency(ILogService);- const selectionManagerService = useDependency(SheetsSelectionsService);+ const selectionManagerService = fabEntryUnitType === UniverInstanceType.UNIVER_SHEET ? useDependency(SheetsSelectionsService) : null;const univerInstanceService = useDependency(IUniverInstanceService);const onSelect = () => {+ if (!selectionManagerService) return;const selections = selectionManagerService.getCurrentSelections();const target = getSheetCommandTarget(univerInstanceService);const matrix = new ObjectMatrix();diff --git a/common/debugger/src/views/use-floating-dom.ts b/common/debugger/src/views/use-floating-dom.tsindex 4aab6a392a..444973cd0b 100644--- a/common/debugger/src/views/use-floating-dom.ts+++ b/common/debugger/src/views/use-floating-dom.ts@@ -19,15 +19,17 @@ import { DocFloatDomController } from '@univerjs/docs-drawing-ui';import { SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';import { useDependency } from '@univerjs/ui';-export function useFloatingDom() {+export function useFloatingDom(entryUnitType?: UniverInstanceType) {const univerInstanceService = useDependency(IUniverInstanceService);- const floatDomService = useDependency(SheetCanvasFloatDomManagerService);- const floatDomController = useDependency(DocFloatDomController);+ const floatDomService = entryUnitType === UniverInstanceType.UNIVER_SHEET ? useDependency(SheetCanvasFloatDomManagerService) : null;+ const floatDomController = entryUnitType === UniverInstanceType.UNIVER_DOC ? useDependency(DocFloatDomController) : null;const onSelect = () => {- const currentSheet = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);- if (currentSheet) {- floatDomService.addFloatDomToPosition({+ if (entryUnitType === UniverInstanceType.UNIVER_SHEET) {+ const currentSheet = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);+ if (!currentSheet) return;++ floatDomService?.addFloatDomToPosition({allowTransform: true,initPosition: {startX: 200,@@ -40,8 +42,11 @@ export function useFloatingDom() {aa: '128',},});- } else {- floatDomController.insertFloatDom({+ } else if (entryUnitType === UniverInstanceType.UNIVER_DOC) {+ const currentDoc = univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC);+ if (!currentDoc) return;++ floatDomController?.insertFloatDom({allowTransform: true,componentKey: 'ImageDemo',data: {diff --git a/examples/src/docs/main.ts b/examples/src/docs/main.tsindex ed1316db6f..c49adddc49 100644--- a/examples/src/docs/main.ts+++ b/examples/src/docs/main.ts@@ -30,6 +30,8 @@ import { DEFAULT_DOCUMENT_DATA_SIMPLE } from '@univerjs/mockdata';import zhCN from '@univerjs/mockdata/locales/zh-CN';import { UniverUIPlugin } from '@univerjs/ui';+import '@univerjs/docs-ui/facade';+import '../global.css';/* eslint-disable node/prefer-global/process */@@ -70,7 +72,9 @@ univer.registerPlugin(UniverDocsQuickInsertUIPlugin);if (!IS_E2E) {univer.createUnit(UniverInstanceType.UNIVER_DOC, DEFAULT_DOCUMENT_DATA_SIMPLE);- univer.registerPlugin(UniverDebuggerPlugin);+ univer.registerPlugin(UniverDebuggerPlugin, {+ fabEntryUnitType: UniverInstanceType.UNIVER_DOC,+ });} else {univer.registerPlugin(UniverDebuggerPlugin, {fab: false,