Skip to content

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.

Revert "feat(sheet): add debugger snapshot feature (#660)" (#667)

Gpound.liu75b2671cd6b7
diff --git a/examples/sheets/src/sheets-plugin-debugger/commands/operations/saveSnapshot.operations.ts b/examples/sheets/src/sheets-plugin-debugger/commands/operations/saveSnapshot.operations.ts
deleted file mode 100644
index 29068cbe94..0000000000
--- a/examples/sheets/src/sheets-plugin-debugger/commands/operations/saveSnapshot.operations.ts
+++ /dev/null
@@ -1,53 +0,0 @@
-// eslint-disable-next-line import/no-extraneous-dependencies
-import type { ICommand, IStyleData, IWorkbookData } from '@univerjs/core';
-import { CommandType, IPersistenceService, IUniverInstanceService, ObjectMatrix } from '@univerjs/core';
-import type { IAccessor } from '@wendellhu/redi';
-
-export interface ISetEditableCommandParams {
- value: 'sheet' | 'workbook';
-}
-
-const filterStyle = (workbookData: IWorkbookData) => {
- const sheets = workbookData.sheets;
- const cacheStyle: Record<string, IStyleData> = {};
- Object.keys(sheets).forEach((sheetId) => {
- const sheet = sheets[sheetId];
- new ObjectMatrix(sheet.cellData).forValue((_r, _c, value) => {
- const s = value.s;
- if (s && typeof s === 'string') {
- const style = workbookData.styles[s];
- if (style) {
- cacheStyle[s] = style;
- }
- }
- });
- });
- workbookData.styles = cacheStyle;
- return workbookData;
-};
-export const SaveSnapshotOptions: ICommand = {
- id: 'debugger.operation.saveSnapshot',
- type: CommandType.OPERATION,
- handler: async (accessor: IAccessor, params: ISetEditableCommandParams) => {
- const univerInstanceService = accessor.get(IUniverInstanceService);
- const localPersistenceService = accessor.get(IPersistenceService);
- const workbook = univerInstanceService.getCurrentUniverSheetInstance();
- const worksheet = workbook.getActiveSheet();
- const snapshot = localPersistenceService.saveWorkBook(workbook);
-
- switch (params.value) {
- case 'sheet': {
- const sheetId = worksheet.getSheetId();
- const sheet = snapshot.sheets[sheetId];
- snapshot.sheets = { [sheetId]: sheet };
- snapshot.sheetOrder = [sheetId];
- break;
- }
- }
- const text = JSON.stringify(filterStyle(snapshot), null, 2);
- console.log(text);
- navigator.clipboard.writeText(text);
-
- return true;
- },
-};
diff --git a/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts b/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts
index 026d52df8e..7f326c3845 100644
--- a/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts
+++ b/examples/sheets/src/sheets-plugin-debugger/controllers/debugger.controller.ts
@@ -1,4 +1,4 @@
-import { Disposable, ICommandService, IPersistenceService, LocalPersistenceService } from '@univerjs/core';
+import { Disposable, ICommandService } from '@univerjs/core';
import { IMenuService } from '@univerjs/ui';
import { Inject, Injector } from '@wendellhu/redi';
@@ -7,7 +7,6 @@ import { DialogOperation } from '../commands/operations/dialog.operation';
import { LocaleOperation } from '../commands/operations/locale.operation';
import { MessageOperation } from '../commands/operations/message.operation';
import { NotificationOperation } from '../commands/operations/notification.operation';
-import { SaveSnapshotOptions } from '../commands/operations/saveSnapshot.operations';
import { SetEditable } from '../commands/operations/set.editable.operation';
import { SidebarOperation } from '../commands/operations/sidebar.operation';
import { ThemeOperation } from '../commands/operations/theme.operation';
@@ -17,7 +16,6 @@ import {
LocaleMenuItemFactory,
MessageMenuItemFactory,
NotificationMenuItemFactory,
- SaveSnapshotSetEditableMenuItemFactory,
SetEditableMenuItemFactory,
SidebarMenuItemFactory,
ThemeMenuItemFactory,
@@ -41,10 +39,7 @@ export class DebuggerController extends Disposable {
MessageOperation,
SidebarOperation,
SetEditable,
- SaveSnapshotOptions,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
-
- this._injector.add([IPersistenceService, { useClass: LocalPersistenceService }]);
}
private _initializeContextMenu() {
@@ -57,7 +52,6 @@ export class DebuggerController extends Disposable {
ConfirmMenuItemFactory,
SidebarMenuItemFactory,
SetEditableMenuItemFactory,
- SaveSnapshotSetEditableMenuItemFactory,
].forEach((factory) => {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
diff --git a/examples/sheets/src/sheets-plugin-debugger/controllers/menu.ts b/examples/sheets/src/sheets-plugin-debugger/controllers/menu.ts
index 2991fa09ff..f49fbff556 100644
--- a/examples/sheets/src/sheets-plugin-debugger/controllers/menu.ts
+++ b/examples/sheets/src/sheets-plugin-debugger/controllers/menu.ts
@@ -9,7 +9,6 @@ import { DialogOperation } from '../commands/operations/dialog.operation';
import { LocaleOperation } from '../commands/operations/locale.operation';
import { MessageOperation } from '../commands/operations/message.operation';
import { NotificationOperation } from '../commands/operations/notification.operation';
-import { SaveSnapshotOptions } from '../commands/operations/saveSnapshot.operations';
import { SetEditable } from '../commands/operations/set.editable.operation';
import { SidebarOperation } from '../commands/operations/sidebar.operation';
import { ThemeOperation } from '../commands/operations/theme.operation';
@@ -169,22 +168,3 @@ export function SetEditableMenuItemFactory(accessor: IAccessor): IMenuSelectorIt
],
};
}
-
-export function SaveSnapshotSetEditableMenuItemFactory(accessor: IAccessor): IMenuSelectorItem {
- return {
- id: SaveSnapshotOptions.id,
- type: MenuItemType.SELECTOR,
- title: 'debugger.snapshot',
- positions: [MenuPosition.TOOLBAR_OTHERS],
- selections: [
- {
- label: 'saveWorkbook',
- value: 'workbook',
- },
- {
- label: 'saveSheet',
- value: 'sheet',
- },
- ],
- };
-}
diff --git a/examples/sheets/src/sheets-plugin-debugger/locale/en-US.ts b/examples/sheets/src/sheets-plugin-debugger/locale/en-US.ts
index 01830251f0..bd20541881 100644
--- a/examples/sheets/src/sheets-plugin-debugger/locale/en-US.ts
+++ b/examples/sheets/src/sheets-plugin-debugger/locale/en-US.ts
@@ -8,6 +8,5 @@ export default {
confirm: 'Confirm',
sidebar: 'Sidebar',
editable: 'Editable',
- snapshot: 'Snapshot',
},
};
diff --git a/examples/sheets/src/sheets-plugin-debugger/locale/zh-CN.ts b/examples/sheets/src/sheets-plugin-debugger/locale/zh-CN.ts
index e3134f2f2f..52bfc3f209 100644
--- a/examples/sheets/src/sheets-plugin-debugger/locale/zh-CN.ts
+++ b/examples/sheets/src/sheets-plugin-debugger/locale/zh-CN.ts
@@ -8,6 +8,5 @@ export default {
confirm: '确认框',
sidebar: '侧边栏',
editable: '编辑权限',
- snapshot: '快照',
},
};
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 9acfbf7435..8a76edc926 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -77,7 +77,6 @@ export * from './shared';
// #region sheet
export type { IComposeInterceptors, IInterceptor, InterceptorHandler } from './common/interceptor';
export { composeInterceptors, createInterceptorKey, InterceptorManager } from './common/interceptor';
-export { IPersistenceService, LocalPersistenceService } from './services/resource-manager/local-persistence.service';
export { Range } from './sheets/range';
export {
deserializeRangeWithSheet,
diff --git a/packages/core/src/services/resource-manager/local-persistence.service.ts b/packages/core/src/services/resource-manager/local-persistence.service.ts
deleted file mode 100644
index e83531ec9d..0000000000
--- a/packages/core/src/services/resource-manager/local-persistence.service.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import { createIdentifier, Inject } from '@wendellhu/redi';
-
-import { Disposable } from '../../shared';
-import type { Workbook } from '../../sheets/workbook';
-import type { IWorkbookData } from '../../types/interfaces/i-workbook-data';
-import { IUniverInstanceService } from '../instance/instance.service';
-import { LifecycleStages, OnLifecycle } from '../lifecycle/lifecycle';
-import { IResourceManagerService } from './type';
-
-export interface IPersistenceService {
- saveWorkBook: (workbook: Workbook) => IWorkbookData;
-}
-
-export const IPersistenceService = createIdentifier<IPersistenceService>('LocalPersistenceService');
-
-@OnLifecycle(LifecycleStages.Ready, LocalPersistenceService)
-export class LocalPersistenceService extends Disposable implements IPersistenceService {
- constructor(
- @Inject(IResourceManagerService) private _resourceManagerService: IResourceManagerService,
- @Inject(IUniverInstanceService) private _univerInstanceService: IUniverInstanceService
- ) {
- super();
- this._initWorkBook();
- }
-
- private _initWorkBook() {
- this._univerInstanceService.sheetAdded$.subscribe((workbook) => this._initWorkbookFromSnapshot(workbook));
- const workbooks = this._univerInstanceService.getAllUniverSheetsInstance();
- workbooks.forEach((workbook) => {
- this._initWorkbookFromSnapshot(workbook);
- });
- }
-
- private _initWorkbookFromSnapshot(workbook: Workbook) {
- const workbookId = workbook.getUnitId();
- const snapshot = workbook.getSnapshot();
- const resources = this._resourceManagerService.getAllResource(workbookId);
- resources.forEach((resource) => {
- const resourceSnapshot = (snapshot.resources || []).find((item) => item.name === resource.resourceName);
- if (resourceSnapshot) {
- const model = resource.hook.parseJson(resourceSnapshot.data);
- resource.hook.onChange(workbookId, model);
- }
- });
- }
-
- saveWorkBook(workbook: Workbook) {
- const snapshot = { ...workbook.getSnapshot() };
- const unitId = workbook.getUnitId();
- const resourceHooks = this._resourceManagerService.getAllResource(workbook.getUnitId());
- const resources = resourceHooks.map((resourceHook) => {
- const data = resourceHook.hook.toJson(unitId);
- return {
- name: resourceHook.resourceName,
- data,
- };
- });
- snapshot.resources = resources;
- return snapshot;
- }
-}
diff --git a/packages/sheets/src/services/numfmt/numfmt.service.ts b/packages/sheets/src/services/numfmt/numfmt.service.ts
index c7039be15b..0cb44bd300 100644
--- a/packages/sheets/src/services/numfmt/numfmt.service.ts
+++ b/packages/sheets/src/services/numfmt/numfmt.service.ts
@@ -17,7 +17,7 @@ import { Subject } from 'rxjs';
import type { FormatType, INumfmtItem, INumfmtService, IRefItem, ISnapshot } from './type';
const SHEET_NUMFMT_PLUGIN = 'SHEET_NUMFMT_PLUGIN';
-@OnLifecycle(LifecycleStages.Starting, NumfmtService)
+@OnLifecycle(LifecycleStages.Ready, NumfmtService)
export class NumfmtService extends Disposable implements INumfmtService {
/**
* Map<unitID ,<sheetId ,ObjectMatrix>>