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
modify actionOperation
dream-numc5ace07c1068
diff --git a/packages/core/src/Command/ActionBase.ts b/packages/core/src/Command/ActionBase.tsindex 82ce7b4c32..5c909d67ce 100644--- a/packages/core/src/Command/ActionBase.ts+++ b/packages/core/src/Command/ActionBase.ts@@ -10,14 +10,13 @@ export interface IActionData {convertor?: object[];rangeRef?: string;memberId?: string;- operation?: ActionOperation;+ operation?: ActionOperationType;}/*** Action Operation Type*/-export enum ActionOperation {-+export enum ActionOperationType {/*** send obs*/@@ -36,7 +35,7 @@ export enum ActionOperation {/*** default obs*/- DEFAULT_ACTION = 1 | 2 | 3+ DEFAULT_ACTION = 1 | 2 | 3,}/**@@ -57,7 +56,7 @@ export abstract class ActionBase<protected _oldActionData: O;- protected _operation: ActionOperation;+ protected _operation: ActionOperationType;protected constructor(actionData: D,@@ -67,7 +66,7 @@ export abstract class ActionBase<this._doActionData = actionData;this._workbook = workbook;this._observers = observers;- this._operation = ActionOperation.OBSERVER_ACTION;+ this._operation = ActionOperationType.OBSERVER_ACTION;}abstract redo(): void;@@ -96,16 +95,16 @@ export abstract class ActionBase<return this._workbook;}- hasOperation(operation: ActionOperation): boolean {+ hasOperation(operation: ActionOperationType): boolean {return (this._operation & operation) === operation;}// TODO how to use- addOperation(operation: ActionOperation) {+ addOperation(operation: ActionOperationType) {this._operation |= operation;}- removeOperation(operation: ActionOperation) {+ removeOperation(operation: ActionOperationType) {this._operation &= ~operation;}}diff --git a/packages/core/src/Command/ActionOperation.ts b/packages/core/src/Command/ActionOperation.tsnew file mode 100644index 0000000000..97aca5e2a7--- /dev/null+++ b/packages/core/src/Command/ActionOperation.ts@@ -0,0 +1,69 @@+import { ActionOperationType, IActionData } from './ActionBase';++export class ActionOperation<T extends IActionData> {+ protected _action: T;++ static hasObserver<U extends IActionData>(action: U): boolean {+ if (action.operation) {+ return (+ (action.operation & ActionOperationType.OBSERVER_ACTION) ===+ ActionOperationType.OBSERVER_ACTION+ );+ }+ return false;+ }++ static hasUndo<U extends IActionData>(action: U): boolean {+ if (action.operation) {+ return (+ (action.operation & ActionOperationType.UNDO_ACTION) ===+ ActionOperationType.UNDO_ACTION+ );+ }+ return false;+ }++ static hasCollaboration<U extends IActionData>(action: U): boolean {+ if (action.operation) {+ return (+ (action.operation & ActionOperationType.SERVER_ACTION) ===+ ActionOperationType.SERVER_ACTION+ );+ }+ return false;+ }++ static make<U extends IActionData>(action: U) {+ action.operation = ActionOperationType.DEFAULT_ACTION;+ return new ActionOperation<U>(action);+ }++ protected constructor(action: T) {+ this._action = action;+ }++ removeObserver() {+ if (this._action.operation) {+ this._action.operation &= ~ActionOperationType.OBSERVER_ACTION;+ }+ return this;+ }++ removeUndo() {+ if (this._action.operation) {+ this._action.operation &= ~ActionOperationType.UNDO_ACTION;+ }+ return this;+ }++ removeCollaboration() {+ if (this._action.operation) {+ this._action.operation &= ~ActionOperationType.SERVER_ACTION;+ }+ return this;+ }++ getAction(): T {+ return this._action;+ }+}diff --git a/packages/core/src/Command/Operation.ts b/packages/core/src/Command/Operation.tsdeleted file mode 100644index 88ec17d5ad..0000000000--- a/packages/core/src/Command/Operation.ts+++ /dev/null@@ -1,69 +0,0 @@-import { ActionOperation, IActionData } from './ActionBase';--export class Operation {- protected _action: IActionData;-- static hasObserver(action: IActionData): boolean {- if (action.operation) {- return (- (action.operation & ActionOperation.OBSERVER_ACTION) ===- ActionOperation.OBSERVER_ACTION- );- }- return false;- }-- static hasUndo(action: IActionData): boolean {- if (action.operation) {- return (- (action.operation & ActionOperation.UNDO_ACTION) ===- ActionOperation.UNDO_ACTION- );- }- return false;- }-- static hasCollaboration(action: IActionData): boolean {- if (action.operation) {- return (- (action.operation & ActionOperation.SERVER_ACTION) ===- ActionOperation.SERVER_ACTION- );- }- return false;- }-- static make(action: IActionData): Operation {- action.operation = ActionOperation.DEFAULT_ACTION;- return new Operation(action);- }-- protected constructor(action: IActionData) {- this._action = action;- }-- removeObserver(): Operation {- if (this._action.operation) {- this._action.operation &= ~ActionOperation.OBSERVER_ACTION;- }- return this;- }-- removeUndo(): Operation {- if (this._action.operation) {- this._action.operation &= ~ActionOperation.UNDO_ACTION;- }- return this;- }-- removeCollaboration(): Operation {- if (this._action.operation) {- this._action.operation &= ~ActionOperation.SERVER_ACTION;- }- return this;- }-- getAction(): IActionData {- return this._action;- }-}diff --git a/packages/core/src/Command/index.ts b/packages/core/src/Command/index.tsindex ad38526f42..ef187fa7c0 100644--- a/packages/core/src/Command/index.ts+++ b/packages/core/src/Command/index.ts@@ -8,6 +8,7 @@ export * from './UndoManager';export * from './ActionExtensionManager';export * from './ActionExtensionFactory';export * from '../Sheets/Action/index';+export * from './ActionOperation';/* eslint-disable import/first */import './RegisterAction';diff --git a/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts b/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.tsindex cb223e14d6..29ebc96bd2 100644--- a/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts+++ b/packages/core/src/Sheets/Action/SetWorkSheetActivateAction.ts@@ -1,7 +1,11 @@import { SetWorkSheetActivate } from '../Apply';import { ACTION_NAMES } from '../../Const/ACTION_NAMES';import { Workbook } from '../Domain';-import { ActionBase, ActionOperation, IActionData } from '../../Command/ActionBase';+import {+ ActionBase,+ ActionOperationType,+ IActionData,+} from '../../Command/ActionBase';import { ActionObservers, ActionType } from '../../Command/ActionObservers';import { BooleanNumber } from '../../Enum';@@ -46,7 +50,7 @@ export class SetWorkSheetActivateAction extends ActionBase<convertor: [],};this.validate();- this.removeOperation(ActionOperation.SERVER_ACTION);+ this.removeOperation(ActionOperationType.SERVER_ACTION);}do(): ISheetStatus {diff --git a/packages/core/test/Command/ActionOperation.test.ts b/packages/core/test/Command/ActionOperation.test.tsnew file mode 100644index 0000000000..2ef4f04007--- /dev/null+++ b/packages/core/test/Command/ActionOperation.test.ts@@ -0,0 +1,22 @@+import { IActionData } from '../../src';+import { ActionOperation } from '../../src/Command/ActionOperation';++test('ActionOperation case1', () => {+ const operation1 = ActionOperation.make<IActionData>({+ sheetId: 'sheet1',+ actionName: 'testAction',+ });+ expect(ActionOperation.hasObserver(operation1.getAction())).toBeTruthy();+ expect(ActionOperation.hasUndo(operation1.getAction())).toBeTruthy();+ expect(ActionOperation.hasCollaboration(operation1.getAction())).toBeTruthy();++ const operation2 = ActionOperation.make({+ sheetId: 'sheet1',+ actionName: 'testAction',+ })+ .removeUndo()+ .removeObserver();+ expect(ActionOperation.hasUndo(operation2.getAction())).toBeFalsy();+ expect(ActionOperation.hasObserver(operation2.getAction())).toBeFalsy();+ expect(ActionOperation.hasCollaboration(operation1.getAction())).toBeTruthy();+});diff --git a/packages/core/test/Command/Operation.test.ts b/packages/core/test/Command/Operation.test.tsdeleted file mode 100644index 1127683f47..0000000000--- a/packages/core/test/Command/Operation.test.ts+++ /dev/null@@ -1,21 +0,0 @@-import { Operation } from '../../src/Command/Operation';--test('operation case1', () => {- const operation1 = Operation.make({- sheetId: 'sheet1',- actionName: 'testAction',- });- expect(Operation.hasObserver(operation1.getAction())).toBeTruthy();- expect(Operation.hasUndo(operation1.getAction())).toBeTruthy();- expect(Operation.hasCollaboration(operation1.getAction())).toBeTruthy();-- const operation2 = Operation.make({- sheetId: 'sheet1',- actionName: 'testAction',- })- .removeUndo()- .removeObserver();- expect(Operation.hasUndo(operation2.getAction())).toBeFalsy();- expect(Operation.hasObserver(operation2.getAction())).toBeFalsy();- expect(Operation.hasCollaboration(operation1.getAction())).toBeTruthy();-});diff --git a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts b/packages/sheets-plugin-formula/src/Controller/FirstLoader.tsindex 6de0908f5d..0c74603546 100644--- a/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts+++ b/packages/sheets-plugin-formula/src/Controller/FirstLoader.ts@@ -1,4 +1,4 @@-import { ACTION_NAMES, ISetRangeDataActionData, SheetsCommand } from '@univer/core';+import { ActionOperation, ACTION_NAMES, ISetRangeDataActionData, SheetsCommand } from '@univer/core';import { FormulaController } from './FormulaController';export function firstLoader(formulaController: FormulaController) {@@ -21,24 +21,24 @@ export function firstLoader(formulaController: FormulaController) {for (let i = 0, len = sheetIds.length; i < len; i++) {const sheetId = sheetIds[i];const cellData = sheetData[sheetId];- cellData.forEach((row, rowArray) => {- rowArray.forEach((column, mainCell) => {- actionList.push({- actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,- sheetId,- rangeData: {- startColumn: column,- endColumn: column,- startRow: row,- endRow: row,+ cellData.forValue((row, column, mainCell) => {+ const action = {+ actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,+ sheetId,+ rangeData: {+ startColumn: column,+ endColumn: column,+ startRow: row,+ endRow: row,+ },+ cellValue: {+ [row]: {+ [column]: mainCell,},- cellValue: {- [row]: {- [column]: mainCell,- },- },- });- });+ },+ };++ actionList.push(ActionOperation.make<ISetRangeDataActionData>(action).removeCollaboration().removeUndo().getAction());});}diff --git a/packages/sheets-plugin-formula/src/Controller/UpdateListener.ts b/packages/sheets-plugin-formula/src/Controller/UpdateListener.tsindex e69de29bb2..02e4b4ffc1 100644--- a/packages/sheets-plugin-formula/src/Controller/UpdateListener.ts+++ b/packages/sheets-plugin-formula/src/Controller/UpdateListener.ts@@ -0,0 +1,5 @@+import { FormulaController } from './FormulaController';++export class UpdateListener {+ constructor(private _formulaController: FormulaController) {}+}diff --git a/packages/sheets-plugin-formula/src/Model/FormulaActionExtensionFactory.ts b/packages/sheets-plugin-formula/src/Model/FormulaActionExtensionFactory.tsnew file mode 100644index 0000000000..38a8e4a8f0--- /dev/null+++ b/packages/sheets-plugin-formula/src/Model/FormulaActionExtensionFactory.ts@@ -0,0 +1,26 @@+import { ACTION_NAMES, Plugin, BaseActionExtension, BaseActionExtensionFactory, ISetRangeDataActionData, IActionData } from '@univer/core';++export class FormulaActionExtension extends BaseActionExtension<ISetRangeDataActionData> {+ execute() {}+}++export class FormulaActionExtensionFactory extends BaseActionExtensionFactory<ISetRangeDataActionData> {+ private _plugin: Plugin;++ get zIndex(): number {+ return 2;+ }++ get actionName(): ACTION_NAMES {+ return ACTION_NAMES.SET_RANGE_DATA_ACTION;+ }++ constructor(plugin: Plugin) {+ super();+ this._plugin = plugin;+ }++ create(actionData: ISetRangeDataActionData, actionDataList: IActionData[]): BaseActionExtension<ISetRangeDataActionData> {+ return new FormulaActionExtension(actionData, actionDataList);+ }+}