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
feat(sheet-numfmt-plugin):numfmt plugin optimization
eiji-thf825dc501fd6
diff --git a/packages/core/src/Command/ActionBase.ts b/packages/core/src/Command/ActionBase.tsindex 23c29471b7..82ce7b4c32 100644--- a/packages/core/src/Command/ActionBase.ts+++ b/packages/core/src/Command/ActionBase.ts@@ -10,12 +10,14 @@ export interface IActionData {convertor?: object[];rangeRef?: string;memberId?: string;+ operation?: ActionOperation;}/*** Action Operation Type*/export enum ActionOperation {+/*** send obs*/@@ -30,6 +32,11 @@ export enum ActionOperation {* push to UNDO/REDO stack*/UNDO_ACTION = 3,++ /**+ * default obs+ */+ DEFAULT_ACTION = 1 | 2 | 3}/**diff --git a/packages/core/src/Command/Operation.ts b/packages/core/src/Command/Operation.tsnew file mode 100644index 0000000000..88ec17d5ad--- /dev/null+++ b/packages/core/src/Command/Operation.ts@@ -0,0 +1,69 @@+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/SheetsCommand.ts b/packages/core/src/Command/SheetsCommand.tsindex ec89e60794..025a9fd435 100644--- a/packages/core/src/Command/SheetsCommand.ts+++ b/packages/core/src/Command/SheetsCommand.ts@@ -8,11 +8,11 @@ import {ActionExtensionManager} from "./ActionExtensionManager";* Execute the undo-redo command*/export class SheetsCommand extends CommandBase {- protected _workbook: Workbook;+ protected unit: Workbook | docs|slider;constructor(workbook: Workbook, ...list: IActionData[]) {super();- this._workbook = workbook;+ this.unit = workbook;this._actions = [];// TODO inject and invokediff --git a/packages/core/test/Command/Operation.test.ts b/packages/core/test/Command/Operation.test.tsnew file mode 100644index 0000000000..1127683f47--- /dev/null+++ b/packages/core/test/Command/Operation.test.ts@@ -0,0 +1,21 @@+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();+});