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
refactor: add set worksheet active controller (#692)
Wenzhao Hu2f10c2dd9bc7
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex e16882a79a..c9c0cc3704 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -3,8 +3,8 @@"editor.codeActionsOnSave": {"mode": "explicit",- "source.fixAll.eslint": true,- "source.fixAll.stylelint": true,+ "source.fixAll.eslint": "explicit",+ "source.fixAll.stylelint": "explicit"},"editor.formatOnSave": false,"javascript.preferences.importModuleSpecifier": "relative",diff --git a/packages/core/src/services/command/command.service.ts b/packages/core/src/services/command/command.service.tsindex 6b48413721..3566df53ec 100644--- a/packages/core/src/services/command/command.service.ts+++ b/packages/core/src/services/command/command.service.ts@@ -100,8 +100,12 @@ export interface IOperationInfo<T extends object = object> {export interface IExecutionOptions {/** This mutation should only be executed on the local machine. */+ // TODO@wzhudev: remove to `onlyLocal`local?: boolean;+ /** From collaboration peers. */+ fromCollab?: boolean;+[key: PropertyKey]: string | number | boolean | undefined;}@@ -121,9 +125,15 @@ export interface ICommandService {syncExecuteCommand<P extends object = object, R = boolean>(id: string, params?: P, options?: IExecutionOptions): R;/**- * Register a callback function that will be executed when a command is executed.+ * Register a callback function that will be executed after a command is executed.*/onCommandExecuted(listener: CommandListener): IDisposable;++ /**+ * Register a callback function that will be executed before a command is executed.+ * @param listener+ */+ beforeCommandExecuted(listener: CommandListener): IDisposable;}export const ICommandService = createIdentifier<ICommandService>('anywhere.command-service');@@ -163,6 +173,7 @@ interface ICommandExecutionStackItem extends ICommandInfo {}export class CommandService implements ICommandService {private readonly _commandRegistry: CommandRegistry;+ private readonly _beforeCommandExecutionListeners: CommandListener[] = [];private readonly _commandExecutedListeners: CommandListener[] = [];private _multiCommandDisposables = new Map<string, IDisposable>();@@ -186,6 +197,19 @@ export class CommandService implements ICommandService {return this._registerMultiCommand(command);}+ beforeCommandExecuted(listener: CommandListener): IDisposable {+ if (this._beforeCommandExecutionListeners.indexOf(listener) === -1) {+ this._beforeCommandExecutionListeners.push(listener);++ return toDisposable(() => {+ const index = this._beforeCommandExecutionListeners.indexOf(listener);+ this._beforeCommandExecutionListeners.splice(index, 1);+ });+ }++ throw new Error('Could not add a listener twice.');+ }+onCommandExecuted(listener: (commandInfo: ICommandInfo) => void): IDisposable {if (this._commandExecutedListeners.indexOf(listener) === -1) {this._commandExecutedListeners.push(listener);@@ -214,11 +238,13 @@ export class CommandService implements ICommandService {};const stackItemDisposable = this._pushCommandExecutionStack(commandInfo);- const result = await this._execute<P, R>(command as ICommand<P, R>, params);- stackItemDisposable.dispose();+ this._beforeCommandExecutionListeners.forEach((listener) => listener(commandInfo, options));+ const result = await this._execute<P, R>(command as ICommand<P, R>, params);this._commandExecutedListeners.forEach((listener) => listener(commandInfo, options));+ stackItemDisposable.dispose();+return result;}diff --git a/packages/core/src/sheets/workbook.ts b/packages/core/src/sheets/workbook.tsindex 35d8c75d38..4e4f59e085 100644--- a/packages/core/src/sheets/workbook.ts+++ b/packages/core/src/sheets/workbook.ts@@ -159,15 +159,24 @@ export class Workbook extends Disposable {return sheetOrder.findIndex((id) => id === sheetId);}- getActiveSheet(): Worksheet {+ getRawActiveSheet(): Nullable<string> {const { sheetOrder } = this._snapshot;const activeSheetId = sheetOrder.find((sheetId) => {const worksheet = this._worksheets.get(sheetId) as Worksheet;return worksheet.getStatus() === BooleanNumber.TRUE;});++ return activeSheetId;+ }++ getActiveSheet(): Worksheet {+ const { sheetOrder } = this._snapshot;+ const activeSheetId = this.getRawActiveSheet();+if (!activeSheetId) {return this._worksheets.get(sheetOrder[0]) as Worksheet;}+return this._worksheets.get(activeSheetId) as Worksheet;}@@ -225,6 +234,11 @@ export class Workbook extends Disposable {return this._worksheets.get(sheetId);}+ getSheetByIndex(index: number): Nullable<Worksheet> {+ const { sheetOrder } = this._snapshot;+ return this._worksheets.get(sheetOrder[index]);+ }+getHiddenWorksheets(): string[] {return this.getSheets().filter((s) => s.getConfig().hidden === BooleanNumber.TRUE)diff --git a/packages/core/src/types/interfaces/i-worksheet-data.ts b/packages/core/src/types/interfaces/i-worksheet-data.tsindex 291d8a1f0e..b92f01b1c6 100644--- a/packages/core/src/types/interfaces/i-worksheet-data.ts+++ b/packages/core/src/types/interfaces/i-worksheet-data.ts@@ -53,6 +53,10 @@ export interface IWorksheetData {mergeData: IRange[];hideRow: [];hideColumn: [];+ /**+ * If the worksheet is the active one.+ * @deprecated this should be removed+ */status: BooleanNumber;cellData: ObjectMatrixPrimitiveType<ICellData>;rowData: ObjectArrayType<Partial<IRowData>>; // TODO:配置文件不能为ObjectArray实例,应该是纯json配置 @jerrydiff --git a/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.tsnew file mode 100644index 0000000000..018ae4e0f6--- /dev/null+++ b/packages/sheets-ui/src/controllers/active-worksheet/active-worksheet.controller.ts@@ -0,0 +1,185 @@+import type { IMutationInfo, Workbook } from '@univerjs/core';+import { Disposable, ICommandService, IUniverInstanceService, LifecycleStages, OnLifecycle } from '@univerjs/core';+import type {+ IInsertSheetMutationParams,+ IRemoveSheetMutationParams,+ ISetWorksheetActiveOperationParams,+ ISetWorksheetHideMutationParams,+} from '@univerjs/sheets';+import {+ InsertSheetMutation,+ RemoveSheetMutation,+ SetWorksheetActiveOperation,+ SetWorksheetHideMutation,+} from '@univerjs/sheets';++/**+ * This controller is responsible for changing the active worksheet when+ * worksheet tab related mutations executes. We cannot write this logic in+ * commands because it does not take collaborative editing into consideration.+ */+@OnLifecycle(LifecycleStages.Ready, ActiveWorksheetController)+export class ActiveWorksheetController extends Disposable {+ private _previousSheetIndex = -1;++ constructor(+ @ICommandService private readonly _commandService: ICommandService,+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService+ ) {+ super();++ this.disposeWithMe(+ this._commandService.onCommandExecuted((command, options) => {+ if (command.id === RemoveSheetMutation.id) {+ return this._beforeAdjustActiveSheetOnRemoveSheet(+ command as IMutationInfo<IRemoveSheetMutationParams>+ );+ }+ })+ );++ this.disposeWithMe(+ this._commandService.onCommandExecuted((command, options) => {+ if (command.id === RemoveSheetMutation.id) {+ return this._adjustActiveSheetOnRemoveSheet(command as IMutationInfo<IRemoveSheetMutationParams>);+ }+ if (+ command.id === SetWorksheetHideMutation.id &&+ (command.params as ISetWorksheetHideMutationParams).hidden+ ) {+ return this._adjustActiveSheetOnHideSheet(+ command as IMutationInfo<ISetWorksheetHideMutationParams>+ );+ }++ // It is a mutation that we comes from the collaboration peer so we should not handle them.+ if (options?.local) {+ return;+ }++ // We only handle the local mutations, for+ // * add / copy sheet+ // * set sheet visible+ if (command.id === InsertSheetMutation.id) {+ return this._adjustActiveSheetOnInsertSheet(command as IMutationInfo<IInsertSheetMutationParams>);+ }+ if (+ command.id === SetWorksheetHideMutation.id &&+ !(command.params as ISetWorksheetHideMutationParams).hidden+ ) {+ return this._adjustActiveSheetOnShowSheet(+ command as IMutationInfo<ISetWorksheetHideMutationParams>+ );+ }+ })+ );+ }++ private _adjustActiveSheetOnHideSheet(mutation: IMutationInfo<ISetWorksheetHideMutationParams>) {+ // If the active sheet is hidden, we need to change the active sheet to the next sheet.+ const { workbookId, worksheetId } = mutation.params;+ const workbook = this._univerInstanceService.getUniverSheetInstance(workbookId);+ if (!workbook) {+ return;+ }++ const activeSheet = workbook?.getRawActiveSheet();+ if (activeSheet !== worksheetId) {+ return;+ }++ const activeIndex = workbook.getActiveSheetIndex();+ const nextId = findTheNextUnhiddenSheet(workbook, activeIndex);++ this._switchToNextSheet(workbookId, nextId);+ }++ private _beforeAdjustActiveSheetOnRemoveSheet(mutation: IMutationInfo<IRemoveSheetMutationParams>) {+ const { workbookId, worksheetId } = mutation.params;+ const workbook = this._univerInstanceService.getUniverSheetInstance(workbookId);+ if (!workbook) {+ return;+ }++ const worksheet = workbook.getSheetBySheetId(worksheetId);+ if (!worksheet) {+ return;+ }++ this._previousSheetIndex = workbook.getSheetIndex(worksheet);+ }++ private _adjustActiveSheetOnRemoveSheet(mutation: IMutationInfo<IRemoveSheetMutationParams>) {+ if (this._previousSheetIndex === -1) {+ return;+ }++ // If the active sheet is removed, we need to change the active sheet to the previous sheet.+ // But how to decide which one is the previous sheet? We store the deleted sheet' index+ // in the `IRemoteSheetMutationParams` and use it to decide the previous sheet.++ // If the selected sheet is not the deleted one, we don't have to do things.+ const { workbookId } = mutation.params;+ const workbook = this._univerInstanceService.getUniverSheetInstance(workbookId);+ if (!workbook) {+ return;+ }++ // The deleted sheet is not the currently active sheet, we don't have to do things.+ const activeSheet = workbook.getRawActiveSheet();+ if (activeSheet) {+ return;+ }++ const previousIndex = this._previousSheetIndex;+ const nextIndex = previousIndex >= 1 ? previousIndex - 1 : 0;+ const nextSheet = workbook.getSheetByIndex(nextIndex);+ if (!nextSheet) {+ throw new Error('[ActiveWorksheetController]: cannot find the next sheet!');+ }++ this._switchToNextSheet(workbookId, nextSheet.getSheetId());+ }++ private _adjustActiveSheetOnInsertSheet(mutation: IMutationInfo<IInsertSheetMutationParams>) {+ // This is simple, just change the active sheet to the unhidden sheet.+ const { workbookId, sheet } = mutation.params;+ this._switchToNextSheet(workbookId, sheet.id);+ }++ private _adjustActiveSheetOnShowSheet(mutation: IMutationInfo<ISetWorksheetHideMutationParams>) {+ // This is simple, just change the active sheet to the unhidden sheet.+ const { workbookId, worksheetId } = mutation.params;+ this._switchToNextSheet(workbookId, worksheetId);+ }++ private _switchToNextSheet(workbookId: string, worksheetId: string): void {+ this._commandService.executeCommand(SetWorksheetActiveOperation.id, {+ workbookId,+ worksheetId,+ } as ISetWorksheetActiveOperationParams);+ }+}++function findTheNextUnhiddenSheet(workbook: Workbook, startIndex: number): string {+ const countOfSheets = workbook.getSheetSize();++ // First look to 0 index, then look to the end.+ for (let i = startIndex; i > -1; i--) {+ const sheet = workbook.getSheetByIndex(i)!;+ if (!sheet.getConfig().hidden) {+ return sheet.getSheetId();+ }+ }++ for (let i = startIndex; i < countOfSheets; i++) {+ const sheet = workbook.getSheetByIndex(i)!;+ if (!sheet.getConfig().hidden) {+ return sheet.getSheetId();+ }+ }++ throw new Error(+ '[ActiveWorksheetController]: could not find the next unhidden sheet! Collaboration error perhaps.'+ );+}diff --git a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts b/packages/sheets-ui/src/controllers/editor-bridge.controller.tsindex 1c77d5616f..a2724fa93a 100644--- a/packages/sheets-ui/src/controllers/editor-bridge.controller.ts+++ b/packages/sheets-ui/src/controllers/editor-bridge.controller.ts@@ -15,7 +15,7 @@ import {COMMAND_LISTENER_SKELETON_CHANGE,NORMAL_SELECTION_PLUGIN_NAME,SelectionManagerService,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,} from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';@@ -254,7 +254,7 @@ export class EditorBridgeController extends Disposable {this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => {- if (command.id === SetWorksheetActivateMutation.id) {+ if (command.id === SetWorksheetActiveOperation.id) {this._keepVisibleHideEditor();} else if (updateCommandList.includes(command.id)) {this._hideEditor();diff --git a/packages/sheets-ui/src/controllers/freeze.controller.ts b/packages/sheets-ui/src/controllers/freeze.controller.tsindex b5385a61cf..ac27d1d31f 100644--- a/packages/sheets-ui/src/controllers/freeze.controller.ts+++ b/packages/sheets-ui/src/controllers/freeze.controller.ts@@ -23,7 +23,7 @@ import {SelectionManagerService,SetFrozenCommand,SetFrozenMutation,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,SetWorksheetRowAutoHeightMutation,} from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';@@ -965,7 +965,7 @@ export class FreezeController extends Disposable {this.disposeWithMe(toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((param) => {- if (![SetWorksheetActivateMutation.id].includes(param?.commandId || '')) {+ if (![SetWorksheetActiveOperation.id].includes(param?.commandId || '')) {return;}this._refreshCurrent();diff --git a/packages/sheets-ui/src/controllers/sheet-render.controller.ts b/packages/sheets-ui/src/controllers/sheet-render.controller.tsindex 9cda47f650..46b98237b9 100644--- a/packages/sheets-ui/src/controllers/sheet-render.controller.ts+++ b/packages/sheets-ui/src/controllers/sheet-render.controller.ts@@ -13,7 +13,7 @@ import {COMMAND_LISTENER_SKELETON_CHANGE,COMMAND_LISTENER_VALUE_CHANGE,SelectionManagerService,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,} from '@univerjs/sheets';import { Inject } from '@wendellhu/redi';@@ -111,7 +111,7 @@ export class SheetRenderController extends Disposable {return;}- if (command.id !== SetWorksheetActivateMutation.id) {+ if (command.id !== SetWorksheetActiveOperation.id) {this._sheetSkeletonManagerService.makeDirty({unitId,diff --git a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.tsindex f6123450ec..119fc2037b 100644--- a/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts+++ b/packages/sheets-ui/src/services/mark-selection/mark-selection.service.ts@@ -2,7 +2,7 @@ import type { ICommandInfo } from '@univerjs/core';import { Disposable, ICommandService, IUniverInstanceService, ThemeService, Tools } from '@univerjs/core';import { IRenderManagerService } from '@univerjs/engine-render';import type { ISelectionWithStyle } from '@univerjs/sheets';-import { SelectionManagerService, SetRangeValuesMutation, SetWorksheetActivateMutation } from '@univerjs/sheets';+import { SelectionManagerService, SetRangeValuesMutation, SetWorksheetActiveOperation } from '@univerjs/sheets';import { createIdentifier, Inject } from '@wendellhu/redi';import { SetCellEditVisibleOperation } from '../../commands/operations/cell-edit.operation';@@ -111,7 +111,7 @@ export class MarkSelectionService extends Disposable implements IMarkSelectionSe}private _addRefreshListener() {- const refreshCommands = [SetWorksheetActivateMutation.id];+ const refreshCommands = [SetWorksheetActiveOperation.id];this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => {if (refreshCommands.includes(command.id)) {diff --git a/packages/sheets-ui/src/sheets-ui-plugin.ts b/packages/sheets-ui/src/sheets-ui-plugin.tsindex a9793fc0ec..b58dd10c53 100644--- a/packages/sheets-ui/src/sheets-ui-plugin.ts+++ b/packages/sheets-ui/src/sheets-ui-plugin.ts@@ -4,6 +4,7 @@ import { Inject, Injector } from '@wendellhu/redi';import { filter } from 'rxjs/operators';import { SHEET_UI_PLUGIN_NAME } from './basics';+import { ActiveWorksheetController } from './controllers/active-worksheet/active-worksheet.controller';import { AutoFillController } from './controllers/auto-fill.controller';import { AutoHeightController } from './controllers/auto-height.controller';import { SheetClipboardController } from './controllers/clipboard/clipboard.controller';@@ -88,6 +89,7 @@ export class SheetsUIPlugin extends Plugin {[IMarkSelectionService, { useClass: MarkSelectionService }],// controllers+ [ActiveWorksheetController],[AutoHeightController],[EditorBridgeController],[EndEditController],diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsxindex 6418bc4b68..5d9eb5e1fe 100644--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-menu/SheetBarMenu.tsx@@ -6,7 +6,7 @@ import {InsertSheetMutation,RemoveSheetMutation,SetWorksheetActivateCommand,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,SetWorksheetHideMutation,SetWorksheetNameMutation,SetWorksheetOrderMutation,@@ -86,7 +86,7 @@ export function SheetBarMenu(props: ISheetBarMenuProps) {case SetWorksheetNameMutation.id:case InsertSheetMutation.id:case SetWorksheetOrderMutation.id:- case SetWorksheetActivateMutation.id:+ case SetWorksheetActiveOperation.id:statusInit();break;default:diff --git a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsxindex f863c8fd4c..d16edac79d 100644--- a/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx+++ b/packages/sheets-ui/src/views/sheet-bar/sheet-bar-tabs/SheetBarTabs.tsx@@ -5,7 +5,7 @@ import {RemoveSheetMutation,SetTabColorMutation,SetWorksheetActivateCommand,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,SetWorksheetHideMutation,SetWorksheetNameCommand,SetWorksheetNameMutation,@@ -127,7 +127,7 @@ export function SheetBarTabs() {case SetWorksheetNameMutation.id:case InsertSheetMutation.id:case SetWorksheetOrderMutation.id:- case SetWorksheetActivateMutation.id:+ case SetWorksheetActiveOperation.id:statusInit();break;default:diff --git a/packages/sheets/src/basics/const/command-listener-const.ts b/packages/sheets/src/basics/const/command-listener-const.tsindex 093de7b3d9..fb2168d6f3 100644--- a/packages/sheets/src/basics/const/command-listener-const.ts+++ b/packages/sheets/src/basics/const/command-listener-const.ts@@ -5,20 +5,20 @@ import { RemoveColMutation, RemoveRowMutation } from '../../commands/mutations/rimport { SetColHiddenMutation, SetColVisibleMutation } from '../../commands/mutations/set-col-visible.mutation';import { SetRangeValuesMutation } from '../../commands/mutations/set-range-values.mutation';import { SetRowHiddenMutation, SetRowVisibleMutation } from '../../commands/mutations/set-row-visible.mutation';-import { SetWorksheetActivateMutation } from '../../commands/mutations/set-worksheet-activate.mutation';import { SetWorksheetColWidthMutation } from '../../commands/mutations/set-worksheet-col-width.mutation';import {SetWorksheetRowAutoHeightMutation,SetWorksheetRowHeightMutation,SetWorksheetRowIsAutoHeightMutation,} from '../../commands/mutations/set-worksheet-row-height.mutation';+import { SetWorksheetActiveOperation } from '../../commands/operations/set-worksheet-active.operation';export const COMMAND_LISTENER_SKELETON_CHANGE = [SetWorksheetRowHeightMutation.id,SetWorksheetRowIsAutoHeightMutation.id,SetWorksheetRowAutoHeightMutation.id,SetWorksheetColWidthMutation.id,- SetWorksheetActivateMutation.id,+ SetWorksheetActiveOperation.id,InsertRowMutation.id,RemoveRowMutation.id,InsertColMutation.id,diff --git a/packages/sheets/src/commands/commands/__tests__/copy-worksheet.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/copy-worksheet.command.spec.tsindex 634a128210..24be1aa7a8 100644--- a/packages/sheets/src/commands/commands/__tests__/copy-worksheet.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/copy-worksheet.command.spec.ts@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../../mutations/remove-sheet.mutation';-import { SetWorksheetActivateMutation } from '../../mutations/set-worksheet-activate.mutation';+import { SetWorksheetActiveOperation } from '../../operations/set-worksheet-active.operation';import { CopySheetCommand } from '../copy-worksheet.command';import { RemoveSheetCommand } from '../remove-sheet.command';import { SetWorksheetActivateCommand } from '../set-worksheet-activate.command';@@ -25,7 +25,7 @@ describe('Test copy worksheet commands', () => {commandService = get(ICommandService);commandService.registerCommand(CopySheetCommand);commandService.registerCommand(InsertSheetMutation);- commandService.registerCommand(SetWorksheetActivateMutation);+ commandService.registerCommand(SetWorksheetActiveOperation);commandService.registerCommand(SetWorksheetActivateCommand);commandService.registerCommand(RemoveSheetCommand);commandService.registerCommand(RemoveSheetMutation);diff --git a/packages/sheets/src/commands/commands/__tests__/remove-sheet.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/remove-sheet.command.spec.tsindex b9998a7b74..d2f6f07434 100644--- a/packages/sheets/src/commands/commands/__tests__/remove-sheet.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/remove-sheet.command.spec.ts@@ -6,7 +6,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../../mutations/remove-sheet.mutation';-import { SetWorksheetActivateMutation } from '../../mutations/set-worksheet-activate.mutation';+import { SetWorksheetActiveOperation } from '../../operations/set-worksheet-active.operation';import { InsertSheetCommand } from '../insert-sheet.command';import { RemoveSheetCommand } from '../remove-sheet.command';import { SetWorksheetActivateCommand } from '../set-worksheet-activate.command';@@ -28,7 +28,7 @@ describe('Test remove worksheet commands', () => {commandService.registerCommand(InsertSheetCommand);commandService.registerCommand(InsertSheetMutation);commandService.registerCommand(SetWorksheetActivateCommand);- commandService.registerCommand(SetWorksheetActivateMutation);+ commandService.registerCommand(SetWorksheetActiveOperation);});afterEach(() => {diff --git a/packages/sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.tsindex 8a29282554..8c8132626b 100644--- a/packages/sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts@@ -4,8 +4,8 @@ import type { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';-import { SetWorksheetActivateMutation } from '../../mutations/set-worksheet-activate.mutation';import { SetWorksheetHideMutation } from '../../mutations/set-worksheet-hide.mutation';+import { SetWorksheetActiveOperation } from '../../operations/set-worksheet-active.operation';import { InsertSheetCommand } from '../insert-sheet.command';import { SetWorksheetActivateCommand } from '../set-worksheet-activate.command';import { SetWorksheetHideCommand } from '../set-worksheet-hide.command';@@ -25,7 +25,7 @@ describe('Test set worksheet hide commands', () => {commandService.registerCommand(SetWorksheetHideCommand);commandService.registerCommand(SetWorksheetHideMutation);commandService.registerCommand(SetWorksheetActivateCommand);- commandService.registerCommand(SetWorksheetActivateMutation);+ commandService.registerCommand(SetWorksheetActiveOperation);commandService.registerCommand(InsertSheetCommand);commandService.registerCommand(InsertSheetMutation);});diff --git a/packages/sheets/src/commands/commands/__tests__/set-worksheet-order.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-worksheet-order.command.spec.tsindex 15e9e8e446..5a58dabb75 100644--- a/packages/sheets/src/commands/commands/__tests__/set-worksheet-order.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-worksheet-order.command.spec.ts@@ -5,8 +5,8 @@ import type { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';-import { SetWorksheetActivateMutation } from '../../mutations/set-worksheet-activate.mutation';import { SetWorksheetOrderMutation } from '../../mutations/set-worksheet-order.mutation';+import { SetWorksheetActiveOperation } from '../../operations/set-worksheet-active.operation';import { InsertSheetCommand } from '../insert-sheet.command';import { SetWorksheetActivateCommand } from '../set-worksheet-activate.command';import { SetWorksheetOrderCommand } from '../set-worksheet-order.command';@@ -26,7 +26,7 @@ describe('Test set worksheet order commands', () => {commandService.registerCommand(SetWorksheetOrderCommand);commandService.registerCommand(SetWorksheetOrderMutation);commandService.registerCommand(SetWorksheetActivateCommand);- commandService.registerCommand(SetWorksheetActivateMutation);+ commandService.registerCommand(SetWorksheetActiveOperation);commandService.registerCommand(InsertSheetCommand);commandService.registerCommand(InsertSheetMutation);});diff --git a/packages/sheets/src/commands/commands/__tests__/set-worksheet-show.command.spec.ts b/packages/sheets/src/commands/commands/__tests__/set-worksheet-show.command.spec.tsindex fde2ad843a..e903233edd 100644--- a/packages/sheets/src/commands/commands/__tests__/set-worksheet-show.command.spec.ts+++ b/packages/sheets/src/commands/commands/__tests__/set-worksheet-show.command.spec.ts@@ -5,8 +5,8 @@ import type { Injector } from '@wendellhu/redi';import { afterEach, beforeEach, describe, expect, it } from 'vitest';import { InsertSheetMutation } from '../../mutations/insert-sheet.mutation';-import { SetWorksheetActivateMutation } from '../../mutations/set-worksheet-activate.mutation';import { SetWorksheetHideMutation } from '../../mutations/set-worksheet-hide.mutation';+import { SetWorksheetActiveOperation } from '../../operations/set-worksheet-active.operation';import { InsertSheetCommand } from '../insert-sheet.command';import { SetWorksheetActivateCommand } from '../set-worksheet-activate.command';import { SetWorksheetHideCommand } from '../set-worksheet-hide.command';@@ -25,7 +25,7 @@ describe('Test set worksheet show commands', () => {commandService = get(ICommandService);commandService.registerCommand(InsertSheetCommand);commandService.registerCommand(InsertSheetMutation);- commandService.registerCommand(SetWorksheetActivateMutation);+ commandService.registerCommand(SetWorksheetActiveOperation);commandService.registerCommand(SetWorksheetActivateCommand);commandService.registerCommand(SetWorksheetHideCommand);commandService.registerCommand(SetWorksheetHideMutation);diff --git a/packages/sheets/src/commands/commands/copy-worksheet.command.ts b/packages/sheets/src/commands/commands/copy-worksheet.command.tsindex b8fa78edad..2549951beb 100644--- a/packages/sheets/src/commands/commands/copy-worksheet.command.ts+++ b/packages/sheets/src/commands/commands/copy-worksheet.command.ts@@ -8,11 +8,6 @@ import type {} from '../../basics/interfaces/mutation-interface';import { InsertSheetMutation, InsertSheetUndoMutationFactory } from '../mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../mutations/remove-sheet.mutation';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import {- SetWorksheetActivateMutation,- SetWorksheetUnActivateMutationFactory,-} from '../mutations/set-worksheet-activate.mutation';export interface ICopySheetCommandParams {workbookId?: string;@@ -43,7 +38,7 @@ export const CopySheetCommand: ICommand = {if (!worksheet) return false;const config = Tools.deepClone(worksheet.getConfig());- config.name += '副本'; //Todo: 文字国际化+ config.name += '副本'; // TODO: 文字国际化config.id = Tools.generateRandomId();const sheetIndex = workbook.getSheetIndex(worksheet);@@ -59,28 +54,11 @@ export const CopySheetCommand: ICommand = {);const insertResult = commandService.syncExecuteCommand(InsertSheetMutation.id, insertSheetMutationParams);- const setSheetActiveMutationParams: ISetWorksheetActivateMutationParams = {- workbookId,- worksheetId: config.id,- };-- const undoMutationParams: ISetWorksheetActivateMutationParams = SetWorksheetUnActivateMutationFactory(- accessor,- setSheetActiveMutationParams- );- const result = commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, setSheetActiveMutationParams);-- if (insertResult && result) {+ if (insertResult) {undoRedoService.pushUndoRedo({unitID: workbookId,- undoMutations: [- { id: SetWorksheetActivateMutation.id, params: undoMutationParams },- { id: RemoveSheetMutation.id, params: removeSheetMutationParams },- ],- redoMutations: [- { id: SetWorksheetActivateMutation.id, params: setSheetActiveMutationParams },- { id: InsertSheetMutation.id, params: insertSheetMutationParams },- ],+ undoMutations: [{ id: RemoveSheetMutation.id, params: removeSheetMutationParams }],+ redoMutations: [{ id: InsertSheetMutation.id, params: insertSheetMutationParams }],});return true;}diff --git a/packages/sheets/src/commands/commands/insert-sheet.command.ts b/packages/sheets/src/commands/commands/insert-sheet.command.tsindex 8a6b9322f2..32a8d527b1 100644--- a/packages/sheets/src/commands/commands/insert-sheet.command.ts+++ b/packages/sheets/src/commands/commands/insert-sheet.command.ts@@ -15,11 +15,6 @@ import type {} from '../../basics/interfaces/mutation-interface';import { InsertSheetMutation, InsertSheetUndoMutationFactory } from '../mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../mutations/remove-sheet.mutation';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import {- SetWorksheetActivateMutation,- SetWorksheetUnActivateMutationFactory,-} from '../mutations/set-worksheet-activate.mutation';export interface InsertSheetCommandParams {workbookId?: string;@@ -75,30 +70,11 @@ export const InsertSheetCommand: ICommand = {// execute do mutations and add undo mutations to undo stack if completedconst result = commandService.syncExecuteCommand(InsertSheetMutation.id, insertSheetMutationParams);- const setSheetActiveMutationParams: ISetWorksheetActivateMutationParams = {- workbookId,- worksheetId: sheetConfig.id,- };- const undoMutationParams: ISetWorksheetActivateMutationParams = SetWorksheetUnActivateMutationFactory(- accessor,- setSheetActiveMutationParams- );- const activateResult = commandService.syncExecuteCommand(- SetWorksheetActivateMutation.id,- setSheetActiveMutationParams- );-- if (result && activateResult) {+ if (result) {undoRedoService.pushUndoRedo({unitID: workbookId,- undoMutations: [- { id: SetWorksheetActivateMutation.id, params: undoMutationParams },- { id: RemoveSheetMutation.id, params: removeSheetMutationParams },- ],- redoMutations: [- { id: InsertSheetMutation.id, params: insertSheetMutationParams },- { id: SetWorksheetActivateMutation.id, params: setSheetActiveMutationParams },- ],+ undoMutations: [{ id: RemoveSheetMutation.id, params: removeSheetMutationParams }],+ redoMutations: [{ id: InsertSheetMutation.id, params: insertSheetMutationParams }],});return true;diff --git a/packages/sheets/src/commands/commands/remove-sheet.command.ts b/packages/sheets/src/commands/commands/remove-sheet.command.tsindex 6b6169994f..3818f1d830 100644--- a/packages/sheets/src/commands/commands/remove-sheet.command.ts+++ b/packages/sheets/src/commands/commands/remove-sheet.command.ts@@ -15,11 +15,7 @@ import type {import { SheetInterceptorService } from '../../services/sheet-interceptor/sheet-interceptor.service';import { InsertSheetMutation } from '../mutations/insert-sheet.mutation';import { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from '../mutations/remove-sheet.mutation';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import {- SetWorksheetActivateMutation,- SetWorksheetUnActivateMutationFactory,-} from '../mutations/set-worksheet-activate.mutation';+import type { ISetWorksheetActiveOperationParams } from '../operations/set-worksheet-active.operation';export interface IRemoveSheetCommandParams {workbookId?: string;@@ -58,20 +54,11 @@ export const RemoveSheetCommand: ICommand = {const index = workbook.getSheetIndex(worksheet);const activateSheetId = workbook.getConfig().sheetOrder[index + 1];- const activeSheetMutationParams: ISetWorksheetActivateMutationParams = {+ const activeSheetMutationParams: ISetWorksheetActiveOperationParams = {workbookId,worksheetId: activateSheetId,};- const activeMutationParams: ISetWorksheetActivateMutationParams = SetWorksheetUnActivateMutationFactory(- accessor,- activeSheetMutationParams- );- const activeResult = commandService.syncExecuteCommand(- SetWorksheetActivateMutation.id,- activeSheetMutationParams- );-// prepare do mutationsconst RemoveSheetMutationParams: IRemoveSheetMutationParams = {worksheetId,@@ -85,19 +72,11 @@ export const RemoveSheetCommand: ICommand = {id: RemoveSheetCommand.id,params: { workbookId, worksheetId },});- const redos = [- { id: RemoveSheetMutation.id, params: RemoveSheetMutationParams },- { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },- ...intercepted.redos,- ];- const undos = [- ...intercepted.undos,- { id: InsertSheetMutation.id, params: InsertSheetMutationParams },- { id: SetWorksheetActivateMutation.id, params: activeMutationParams },- ];+ const redos = [{ id: RemoveSheetMutation.id, params: RemoveSheetMutationParams }, ...intercepted.redos];+ const undos = [...intercepted.undos, { id: InsertSheetMutation.id, params: InsertSheetMutationParams }];const result = sequenceExecute(redos, commandService);- if (result && activeResult) {+ if (result) {undoRedoService.pushUndoRedo({unitID: workbookId,undoMutations: undos,diff --git a/packages/sheets/src/commands/commands/set-worksheet-activate.command.ts b/packages/sheets/src/commands/commands/set-worksheet-activate.command.tsindex dd910b0cd2..d3ea0653a7 100644--- a/packages/sheets/src/commands/commands/set-worksheet-activate.command.ts+++ b/packages/sheets/src/commands/commands/set-worksheet-activate.command.ts@@ -1,9 +1,9 @@import type { ICommand } from '@univerjs/core';-import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';+import { CommandType, ICommandService, IUniverInstanceService } from '@univerjs/core';import type { IAccessor } from '@wendellhu/redi';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import { SetWorksheetActivateMutation } from '../mutations/set-worksheet-activate.mutation';+import type { ISetWorksheetActiveOperationParams } from '../operations/set-worksheet-active.operation';+import { SetWorksheetActiveOperation } from '../operations/set-worksheet-active.operation';export interface ISetWorksheetActivateCommandParams {workbookId?: string;@@ -16,7 +16,6 @@ export const SetWorksheetActivateCommand: ICommand = {handler: async (accessor: IAccessor, params?: ISetWorksheetActivateCommandParams) => {const commandService = accessor.get(ICommandService);- const undoRedoService = accessor.get(IUndoRedoService);const univerInstanceService = accessor.get(IUniverInstanceService);let workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();@@ -31,11 +30,11 @@ export const SetWorksheetActivateCommand: ICommand = {worksheetId = params.worksheetId ?? worksheetId;}- const redoMutationParams: ISetWorksheetActivateMutationParams = {+ const redoMutationParams: ISetWorksheetActiveOperationParams = {workbookId,worksheetId,};- return commandService.syncExecuteCommand(SetWorksheetActivateMutation.id, redoMutationParams);+ return commandService.syncExecuteCommand(SetWorksheetActiveOperation.id, redoMutationParams);},};diff --git a/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts b/packages/sheets/src/commands/commands/set-worksheet-hide.command.tsindex 43dd908f04..f368e0b400 100644--- a/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts+++ b/packages/sheets/src/commands/commands/set-worksheet-hide.command.ts@@ -1,12 +1,14 @@import type { ICommand } from '@univerjs/core';-import { BooleanNumber, CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';+import {+ BooleanNumber,+ CommandType,+ ErrorService,+ ICommandService,+ IUndoRedoService,+ IUniverInstanceService,+} from '@univerjs/core';import type { IAccessor } from '@wendellhu/redi';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import {- SetWorksheetActivateMutation,- SetWorksheetUnActivateMutationFactory,-} from '../mutations/set-worksheet-activate.mutation';import type { ISetWorksheetHideMutationParams } from '../mutations/set-worksheet-hide.mutation';import { SetWorksheetHideMutation, SetWorksheetHideMutationFactory } from '../mutations/set-worksheet-hide.mutation';@@ -22,6 +24,7 @@ export const SetWorksheetHideCommand: ICommand = {const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);const univerInstanceService = accessor.get(IUniverInstanceService);+ const errorService = accessor.get(ErrorService);const workbookId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();let worksheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();@@ -46,35 +49,20 @@ export const SetWorksheetHideCommand: ICommand = {const undoMutationParams = SetWorksheetHideMutationFactory(accessor, redoMutationParams);- const index = workbook.getSheetIndex(worksheet);- const activateSheetId = workbook.getConfig().sheetOrder[index + 1];-- if (!activateSheetId) return false;+ const worksheets = workbook.getSheets();+ const visibleWorksheets = worksheets.filter((sheet) => sheet.getConfig().hidden === BooleanNumber.FALSE);+ if (visibleWorksheets.length === 1) {+ errorService.emit('No visible sheet after you hide this.');+ return false;+ }const result = commandService.syncExecuteCommand(SetWorksheetHideMutation.id, redoMutationParams);- const activeSheetMutationParams: ISetWorksheetActivateMutationParams = {- workbookId,- worksheetId: activateSheetId,- };-- const unActiveMutationParams = SetWorksheetUnActivateMutationFactory(accessor, activeSheetMutationParams);- const activeResult = commandService.syncExecuteCommand(- SetWorksheetActivateMutation.id,- activeSheetMutationParams- );-- if (result && activeResult) {+ if (result) {undoRedoService.pushUndoRedo({unitID: workbookId,- undoMutations: [- { id: SetWorksheetActivateMutation.id, params: unActiveMutationParams },- { id: SetWorksheetHideMutation.id, params: undoMutationParams },- ],- redoMutations: [- { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },- { id: SetWorksheetHideMutation.id, params: redoMutationParams },- ],+ undoMutations: [{ id: SetWorksheetHideMutation.id, params: undoMutationParams }],+ redoMutations: [{ id: SetWorksheetHideMutation.id, params: redoMutationParams }],});return true;}diff --git a/packages/sheets/src/commands/commands/set-worksheet-show.command.ts b/packages/sheets/src/commands/commands/set-worksheet-show.command.tsindex f09862ffab..e74d1bea38 100644--- a/packages/sheets/src/commands/commands/set-worksheet-show.command.ts+++ b/packages/sheets/src/commands/commands/set-worksheet-show.command.ts@@ -2,13 +2,13 @@ import type { ICommand } from '@univerjs/core';import { BooleanNumber, CommandType, ICommandService, IUndoRedoService, IUniverInstanceService } from '@univerjs/core';import type { IAccessor } from '@wendellhu/redi';-import type { ISetWorksheetActivateMutationParams } from '../mutations/set-worksheet-activate.mutation';-import {- SetWorksheetActivateMutation,- SetWorksheetUnActivateMutationFactory,-} from '../mutations/set-worksheet-activate.mutation';import type { ISetWorksheetHideMutationParams } from '../mutations/set-worksheet-hide.mutation';import { SetWorksheetHideMutation, SetWorksheetHideMutationFactory } from '../mutations/set-worksheet-hide.mutation';+import type { ISetWorksheetActiveOperationParams } from '../operations/set-worksheet-active.operation';+import {+ SetWorksheetActiveOperation,+ // SetWorksheetUnActivateMutationFactory,+} from '../operations/set-worksheet-active.operation';export interface ISetWorksheetShowCommandParams {value?: string;@@ -51,14 +51,14 @@ export const SetWorksheetShowCommand: ICommand = {const undoMutationParams = SetWorksheetHideMutationFactory(accessor, redoMutationParams);const result = commandService.syncExecuteCommand(SetWorksheetHideMutation.id, redoMutationParams);- const activeSheetMutationParams: ISetWorksheetActivateMutationParams = {+ const activeSheetMutationParams: ISetWorksheetActiveOperationParams = {workbookId,worksheetId,};- const unActiveMutationParams = SetWorksheetUnActivateMutationFactory(accessor, activeSheetMutationParams);+ // const unActiveMutationParams = SetWorksheetUnActivateMutationFactory(accessor, activeSheetMutationParams);const activeResult = commandService.syncExecuteCommand(- SetWorksheetActivateMutation.id,+ SetWorksheetActiveOperation.id,activeSheetMutationParams);@@ -67,10 +67,10 @@ export const SetWorksheetShowCommand: ICommand = {unitID: workbookId,undoMutations: [{ id: SetWorksheetHideMutation.id, params: undoMutationParams },- { id: SetWorksheetActivateMutation.id, params: unActiveMutationParams },+ // { id: SetWorksheetActiveOperation.id, params: unActiveMutationParams },],redoMutations: [- { id: SetWorksheetActivateMutation.id, params: activeSheetMutationParams },+ // { id: SetWorksheetActiveOperation.id, params: activeSheetMutationParams },{ id: SetWorksheetHideMutation.id, params: redoMutationParams },],});diff --git a/packages/sheets/src/commands/mutations/set-worksheet-activate.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-activate.mutation.tsdeleted file mode 100644index 7f975a7ef0..0000000000--- a/packages/sheets/src/commands/mutations/set-worksheet-activate.mutation.ts+++ /dev/null@@ -1,59 +0,0 @@-import type { IMutation, Nullable, Worksheet } from '@univerjs/core';-import { BooleanNumber, CommandType, IUniverInstanceService } from '@univerjs/core';-import type { IAccessor } from '@wendellhu/redi';--export interface ISetWorksheetActivateMutationParams {- workbookId: string;- worksheetId: string;-}--export const SetWorksheetUnActivateMutationFactory = (- accessor: IAccessor,- params: ISetWorksheetActivateMutationParams-): ISetWorksheetActivateMutationParams => {- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.workbookId);-- if (universheet == null) {- throw new Error('universheet is null error!');- }-- const worksheets = universheet.getWorksheets();- let activate: Nullable<Worksheet> = null;-- for (const [, worksheet] of worksheets) {- if (worksheet.getStatus() === BooleanNumber.TRUE) {- activate = worksheet;- break;- }- }-- if (activate == null) {- throw new Error('not found activate worksheet!');- }-- return {- workbookId: params.workbookId,- worksheetId: activate.getSheetId(),- };-};--export const SetWorksheetActivateMutation: IMutation<ISetWorksheetActivateMutationParams> = {- id: 'sheet.mutation.set-worksheet-activate',- type: CommandType.MUTATION,- handler: (accessor, params) => {- const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.workbookId);-- if (!universheet) return false;-- const worksheets = universheet.getWorksheets();-- for (const [, worksheet] of worksheets) {- if (worksheet.getSheetId() === params.worksheetId) {- worksheet.getConfig().status = BooleanNumber.TRUE;- } else {- worksheet.getConfig().status = BooleanNumber.FALSE;- }- }- return true;- },-};diff --git a/packages/sheets/src/commands/operations/set-worksheet-active.operation.ts b/packages/sheets/src/commands/operations/set-worksheet-active.operation.tsnew file mode 100644index 0000000000..c2bc8a4535--- /dev/null+++ b/packages/sheets/src/commands/operations/set-worksheet-active.operation.ts@@ -0,0 +1,28 @@+import type { IOperation } from '@univerjs/core';+import { BooleanNumber, CommandType, IUniverInstanceService } from '@univerjs/core';++export interface ISetWorksheetActiveOperationParams {+ workbookId: string;+ worksheetId: string;+}++export const SetWorksheetActiveOperation: IOperation<ISetWorksheetActiveOperationParams> = {+ id: 'sheet.operation.set-worksheet-active',+ type: CommandType.OPERATION,+ handler: (accessor, params) => {+ const universheet = accessor.get(IUniverInstanceService).getUniverSheetInstance(params.workbookId);+ if (!universheet) return false;++ // TODO: this should be changed to a inner state+ const worksheets = universheet.getWorksheets();+ for (const [, worksheet] of worksheets) {+ if (worksheet.getSheetId() === params.worksheetId) {+ worksheet.getConfig().status = BooleanNumber.TRUE;+ } else {+ worksheet.getConfig().status = BooleanNumber.FALSE;+ }+ }++ return true;+ },+};diff --git a/packages/sheets/src/controllers/basic-worksheet.controller.ts b/packages/sheets/src/controllers/basic-worksheet.controller.tsindex 202653752a..2634462f6f 100644--- a/packages/sheets/src/controllers/basic-worksheet.controller.ts+++ b/packages/sheets/src/controllers/basic-worksheet.controller.ts@@ -83,7 +83,6 @@ import { SetFrozenMutation } from '../commands/mutations/set-frozen.mutation';import { SetRangeValuesMutation } from '../commands/mutations/set-range-values.mutation';import { SetRowHiddenMutation, SetRowVisibleMutation } from '../commands/mutations/set-row-visible.mutation';import { SetTabColorMutation } from '../commands/mutations/set-tab-color.mutation';-import { SetWorksheetActivateMutation } from '../commands/mutations/set-worksheet-activate.mutation';import { SetWorksheetColWidthMutation } from '../commands/mutations/set-worksheet-col-width.mutation';import { SetWorksheetHideMutation } from '../commands/mutations/set-worksheet-hide.mutation';import { SetWorksheetNameMutation } from '../commands/mutations/set-worksheet-name.mutation';@@ -93,6 +92,7 @@ import {SetWorksheetRowHeightMutation,SetWorksheetRowIsAutoHeightMutation,} from '../commands/mutations/set-worksheet-row-height.mutation';+import { SetWorksheetActiveOperation } from '../commands/operations/set-worksheet-active.operation';import { MAX_CELL_PER_SHEET_DEFAULT, MAX_CELL_PER_SHEET_KEY } from './config/config';export interface IStyleTypeValue<T> {@@ -183,7 +183,7 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetTextWrapCommand,SetVerticalTextAlignCommand,SetWorksheetActivateCommand,- SetWorksheetActivateMutation,+ SetWorksheetActiveOperation,SetWorksheetColWidthMutation,SetWorksheetHideCommand,SetWorksheetHideMutation,diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex 45625ed4e8..7beb98122f 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -205,8 +205,6 @@ export { type ISetRangeValuesRangeMutationParams } from './commands/mutations/seexport { SetRowHiddenMutation, SetRowVisibleMutation } from './commands/mutations/set-row-visible.mutation';export { SetTabColorMutation } from './commands/mutations/set-tab-color.mutation';export { type ISetTabColorMutationParams } from './commands/mutations/set-tab-color.mutation';-export { SetWorksheetActivateMutation } from './commands/mutations/set-worksheet-activate.mutation';-export { type ISetWorksheetActivateMutationParams } from './commands/mutations/set-worksheet-activate.mutation';export {type ISetWorksheetColWidthMutationParams,SetWorksheetColWidthMutation,@@ -230,6 +228,8 @@ export {SetWorksheetRowIsAutoHeightMutation,} from './commands/mutations/set-worksheet-row-height.mutation';export { type ISetSelectionsOperationParams, SetSelectionsOperation } from './commands/operations/selection.operation';+export { SetWorksheetActiveOperation } from './commands/operations/set-worksheet-active.operation';+export { type ISetWorksheetActiveOperationParams } from './commands/operations/set-worksheet-active.operation';export { type ISheetCommandSharedParams } from './commands/utils/interface';export { getAddMergeMutationRangeByType } from './controllers/merge-cell.controller';export { enUS, zhCN } from './locale';diff --git a/packages/uniscript/src/services/command/batch-command.service.ts b/packages/uniscript/src/services/command/batch-command.service.tsindex 8258931966..dcc385dac7 100644--- a/packages/uniscript/src/services/command/batch-command.service.ts+++ b/packages/uniscript/src/services/command/batch-command.service.ts@@ -2,6 +2,10 @@ import type { CommandListener, ICommand, ICommandService, IExecutionOptions } frimport type { IDisposable } from '@wendellhu/redi';export class BatchCommandService implements ICommandService {+ beforeCommandExecuted(listener: CommandListener): IDisposable {+ throw new Error('Method not implemented.');+ }+registerCommand(command: ICommand<object, boolean>): IDisposable {throw new Error('Method not implemented.');}