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
chore: add debug command to load snapshot from local json (#3373)
Wenzhao Hufc9645f1cd54
diff --git a/packages/debugger/src/commands/commands/unit.command.ts b/packages/debugger/src/commands/commands/unit.command.tsindex ee3d0416d4..45231d0b72 100644--- a/packages/debugger/src/commands/commands/unit.command.ts+++ b/packages/debugger/src/commands/commands/unit.command.ts@@ -14,8 +14,10 @@* limitations under the License.*/-import { CommandType, type ICommand, IUniverInstanceService, type Univer, UniverInstanceType } from '@univerjs/core';+import type { ICommand, IWorkbookData, Univer, Workbook } from '@univerjs/core';+import { CommandType, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';import type { FUniver } from '@univerjs/facade';+import { IFileOpenerService } from '@univerjs/ui';declare global {// eslint-disable-next-line ts/naming-convention@@ -58,3 +60,18 @@ export const CreateEmptySheetCommand: ICommand = {return true;},};++export const LoadSheetSnapshotCommand: ICommand = {+ id: 'debugger.command.load-sheet-snapshot',+ type: CommandType.COMMAND,+ handler: async (accessor) => {+ const fileOpenerService = accessor.get(IFileOpenerService);+ const snapshotFile = await fileOpenerService.openFile({ multiple: false, accept: '.json' });+ if (snapshotFile.length === 1) return false;++ const text = await snapshotFile[0].text();+ const instanceService = accessor.get(IUniverInstanceService);+ instanceService.createUnit<IWorkbookData, Workbook>(UniverInstanceType.UNIVER_SHEET, JSON.parse(text));+ return true;+ },+};diff --git a/packages/debugger/src/controllers/debugger.controller.ts b/packages/debugger/src/controllers/debugger.controller.tsindex 890050a4bc..3b7233e115 100644--- a/packages/debugger/src/controllers/debugger.controller.ts+++ b/packages/debugger/src/controllers/debugger.controller.ts@@ -32,7 +32,7 @@ import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-// @ts-ignoreimport VueI18nIcon from '../components/VueI18nIcon.vue';-import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand } from '../commands/commands/unit.command';+import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand, LoadSheetSnapshotCommand } from '../commands/commands/unit.command';import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';import { ImageDemo } from '../components/Image';import { ChangeUserCommand } from '../commands/operations/change-user.operation';@@ -67,6 +67,7 @@ export class DebuggerController extends Disposable {DisposeUniverCommand,DisposeCurrentUnitCommand,CreateEmptySheetCommand,+ LoadSheetSnapshotCommand,CreateFloatDomCommand,ChangeUserCommand,ShowCellContentOperation,diff --git a/packages/debugger/src/controllers/menu.schema.ts b/packages/debugger/src/controllers/menu.schema.tsindex 3b04018d52..f66934f759 100644--- a/packages/debugger/src/controllers/menu.schema.ts+++ b/packages/debugger/src/controllers/menu.schema.ts@@ -26,6 +26,7 @@ import {DisposeUniverItemFactory,FLOAT_DOM_ITEM_MENU_ID,FloatDomMenuItemFactory,+ LoadSheetSnapshotMenuItemFactory,LocaleMenuItemFactory,MessageMenuItemFactory,NotificationMenuItemFactory,@@ -45,7 +46,7 @@ import { MessageOperation } from '../commands/operations/message.operation';import { SaveSnapshotOptions } from '../commands/operations/save-snapshot.operations';import { SetEditable } from '../commands/operations/set.editable.operation';import { SidebarOperation } from '../commands/operations/sidebar.operation';-import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand } from '../commands/commands/unit.command';+import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand, LoadSheetSnapshotCommand } from '../commands/commands/unit.command';import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';import { ChangeUserCommand } from '../commands/operations/change-user.operation';import { ShowCellContentOperation } from '../commands/operations/cell.operation';@@ -103,6 +104,10 @@ export const menuSchema: MenuSchemaType = {order: 2,menuItemFactory: CreateEmptySheetMenuItemFactory,},+ [LoadSheetSnapshotCommand.id]: {+ order: 3,+ menuItemFactory: LoadSheetSnapshotMenuItemFactory,+ },},[FLOAT_DOM_ITEM_MENU_ID]: {order: 10,diff --git a/packages/debugger/src/controllers/menu.ts b/packages/debugger/src/controllers/menu.tsindex 16dc0523f9..30e3a808b4 100644--- a/packages/debugger/src/controllers/menu.ts+++ b/packages/debugger/src/controllers/menu.ts@@ -29,7 +29,7 @@ import { SaveSnapshotOptions } from '../commands/operations/save-snapshot.operatimport { SetEditable } from '../commands/operations/set.editable.operation';import { SidebarOperation } from '../commands/operations/sidebar.operation';import { ThemeOperation } from '../commands/operations/theme.operation';-import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand } from '../commands/commands/unit.command';+import { CreateEmptySheetCommand, DisposeCurrentUnitCommand, DisposeUniverCommand, LoadSheetSnapshotCommand } from '../commands/commands/unit.command';import { CreateFloatDomCommand } from '../commands/commands/float-dom.command';import { ChangeUserCommand, UnitRole } from '../commands/operations/change-user.operation';import { ShowCellContentOperation } from '../commands/operations/cell.operation';@@ -222,7 +222,7 @@ export function SaveSnapshotSetEditableMenuItemFactory(accessor: IAccessor): IMeexport const UNIT_ITEM_MENU_ID = 'debugger.unit-menu-item';-export function UnitMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {+export function UnitMenuItemFactory(): IMenuSelectorItem {return {id: UNIT_ITEM_MENU_ID,title: 'Dispose',@@ -231,7 +231,7 @@ export function UnitMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {};}-export function DisposeUniverItemFactory(_accessor: IAccessor): IMenuButtonItem {+export function DisposeUniverItemFactory(): IMenuButtonItem {return {id: DisposeUniverCommand.id,title: 'Dispose Univer',@@ -241,7 +241,7 @@ export function DisposeUniverItemFactory(_accessor: IAccessor): IMenuButtonItem};}-export function DisposeCurrentUnitMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+export function DisposeCurrentUnitMenuItemFactory(): IMenuButtonItem {return {id: DisposeCurrentUnitCommand.id,title: 'Dispose Current Unit',@@ -251,7 +251,7 @@ export function DisposeCurrentUnitMenuItemFactory(accessor: IAccessor): IMenuBut};}-export function CreateEmptySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {+export function CreateEmptySheetMenuItemFactory(): IMenuButtonItem {return {id: CreateEmptySheetCommand.id,title: 'Create Another Sheet',@@ -261,6 +261,16 @@ export function CreateEmptySheetMenuItemFactory(accessor: IAccessor): IMenuButto};}+export function LoadSheetSnapshotMenuItemFactory(): IMenuButtonItem {+ return {+ id: LoadSheetSnapshotCommand.id,+ title: 'Load Snapshot',+ tooltip: 'Load Snapshot',+ icon: 'CR',+ type: MenuItemType.BUTTON,+ };+}+export const FLOAT_DOM_ITEM_MENU_ID = 'debugger.float-dom-menu-item';export function FloatDomMenuItemFactory(): IMenuSelectorItem {