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.

chore(core): command action opreration

Dushusirfaf3701c247a
diff --git a/.github/contributing-zh.md b/.github/contributing-zh.md
index 458836b177..ae05cbe9e8 100644
--- a/.github/contributing-zh.md
+++ b/.github/contributing-zh.md
@@ -1242,6 +1242,11 @@ npm run build
pnpm publish --filter @univerjs/core
```
+使用 Verdaccio 本地测试发包使用
+```shell
+pnpm publish --filter @univerjs/core --registry http://localhost:4873/
+```
+
or
```shell
diff --git a/packages/base-render/package.json b/packages/base-render/package.json
index e952b09874..490e00b820 100644
--- a/packages/base-render/package.json
+++ b/packages/base-render/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/base-render",
"version": "0.0.1",
"description": "UniverSheet normal base-render",
- "keywords": ["render","canvas"],
+ "keywords": ["univer","render","canvas"],
"author": "DreamNum <[email protected]>",
"license": "MIT",
"main": "./src/index.ts",
@@ -11,7 +11,8 @@
"publishConfig": {
"main": "./lib/univer-base-render.cjs.js",
"module": "./lib/univer-base-render.es.js",
- "types": "./lib/index.d.ts"
+ "types": "./lib/index.d.ts",
+ "access": "public"
},
"exports": {
".": "./src/index.ts",
diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.json
index f050e83402..b51907f559 100644
--- a/packages/base-sheets/package.json
+++ b/packages/base-sheets/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/base-sheets",
"version": "0.0.1",
"description": "UniverSheet normal base-sheets",
- "keywords": [],
+ "keywords": ["univer","sheets","spreadsheet"],
"author": "DreamNum <[email protected]>",
"license": "MIT",
"main": "./src/index.ts",
@@ -11,7 +11,8 @@
"publishConfig": {
"main": "./lib/univer-base-sheets.cjs.js",
"module": "./lib/univer-base-sheets.es.js",
- "types": "./lib/index.d.ts"
+ "types": "./lib/index.d.ts",
+ "access": "public"
},
"exports": {
".": "./src/index.ts",
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index 7e4c08f5ee..b8ecefca9b 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -1,5 +1,19 @@
import { IMouseEvent, IPointerEvent, Rect, Spreadsheet, SpreadsheetColumnTitle, SpreadsheetRowTitle, ScrollTimer } from '@univerjs/base-render';
-import { Nullable, Observer, Worksheet, ISelection, makeCellToSelection, IRangeData, RangeList, Range, IRangeCellData, ICellInfo, Command, Direction } from '@univerjs/core';
+import {
+ Nullable,
+ Observer,
+ Worksheet,
+ ISelection,
+ makeCellToSelection,
+ IRangeData,
+ RangeList,
+ Range,
+ IRangeCellData,
+ ICellInfo,
+ Command,
+ Direction,
+ ActionOperation,
+} from '@univerjs/core';
import { ACTION_NAMES, ISelectionsConfig } from '../../Basics';
import { ISelectionModelValue, ISetSelectionValueActionData, SetSelectionValueAction } from '../../Model/Action/SetSelectionValueAction';
import { SelectionModel } from '../../Model/SelectionModel';
@@ -147,7 +161,7 @@ export class SelectionManager {
* Renders all controls of the currently active sheet
* @returns
*/
- renderCurrentControls(models?: SelectionModel[]) {
+ renderCurrentControls(command: boolean = true, models?: SelectionModel[]) {
const worksheetId = this.getWorksheetId();
if (worksheetId) {
if (this._selectionControls) {
@@ -192,7 +206,7 @@ export class SelectionManager {
this._selectionControls.push(control);
});
- this.setSelectionModel();
+ command && this.setSelectionModel();
}
}
@@ -274,17 +288,19 @@ export class SelectionManager {
const workbook = this._worksheet.getContext().getWorkBook();
const commandManager = workbook.getCommandManager();
- const value: ISetSelectionValueActionData = {
+ let action: ISetSelectionValueActionData = {
sheetId: this._worksheet.getSheetId(),
actionName: SetSelectionValueAction.NAME,
selections: models,
};
+ action = ActionOperation.make<ISetSelectionValueActionData>(action).removeUndo().getAction();
+
const command = new Command(
{
WorkBookUnit: workbook,
},
- value
+ action
);
commandManager.invoke(command);
}
@@ -311,17 +327,19 @@ export class SelectionManager {
const workbook = this._worksheet.getContext().getWorkBook();
const commandManager = workbook.getCommandManager();
- const value: ISetSelectionValueActionData = {
+ let action: ISetSelectionValueActionData = {
sheetId: this._worksheet.getSheetId(),
actionName: ACTION_NAMES.SET_SELECTION_VALUE_ACTION,
selections: selectionModelsValue,
};
+ action = ActionOperation.make<ISetSelectionValueActionData>(action).removeUndo().getAction();
+
const command = new Command(
{
WorkBookUnit: workbook,
},
- value
+ action
);
commandManager.invoke(command);
}
diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.ts
index 4f3fb95bb5..4a17879d8a 100644
--- a/packages/base-sheets/src/Controller/SheetContainerController.ts
+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts
@@ -33,6 +33,7 @@ export class SheetContainerController {
if (canvasView) {
canvasView.updateToSheet(worksheet);
plugin.getMainComponent().makeDirty(true);
+ plugin.getSelectionManager().renderCurrentControls(false);
}
} catch (error) {
console.info(error);
diff --git a/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts b/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts
index c56504c2a0..ac1c44f16e 100644
--- a/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts
+++ b/packages/base-sheets/src/Model/Apply/SetSelectionValue.ts
@@ -13,11 +13,9 @@ import { ISelectionModelValue } from '../Action/SetSelectionValueAction';
* @internal
*/
export function SetSelectionValue(worksheet: Worksheet, selections: ISelectionModelValue[]): ISelectionModelValue[] {
- const selectionManager = worksheet.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)?.getSelectionManager();
+ const selectionManager = worksheet.getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET).getSelectionManager();
- if (!selectionManager) return [];
-
- const result = selectionManager?.getCurrentModelsValue();
+ const result = selectionManager.getCurrentModelsValue();
selectionManager.setModels(selections);
diff --git a/packages/base-ui/package.json b/packages/base-ui/package.json
index 9c6c267a05..7add120988 100644
--- a/packages/base-ui/package.json
+++ b/packages/base-ui/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/base-ui",
"version": "0.0.1",
"description": "UniverSheet normal plugin UI manager",
- "keywords": [],
+ "keywords": ["univer","ui"],
"author": "DreamNum <[email protected]>",
"license": "MIT",
"main": "./src/index.ts",
@@ -11,7 +11,8 @@
"publishConfig": {
"main": "./lib/univer-base-ui.cjs.js",
"module": "./lib/univer-base-ui.es.js",
- "types": "./lib/index.d.ts"
+ "types": "./lib/index.d.ts",
+ "access": "public"
},
"exports": {
".": "./src/index.ts",
diff --git a/packages/core/package.json b/packages/core/package.json
index 60245fdf3b..3197f47b7b 100644
--- a/packages/core/package.json
+++ b/packages/core/package.json
@@ -2,6 +2,7 @@
"name": "@univerjs/core",
"version": "0.0.1",
"description": "Univer core",
+ "keywords": ["univer","core","sheets","docs","slides","excel","word","ppt"],
"author": "DreamNum <[email protected]>",
"main": "./src/index.ts",
"module": "./src/index.ts",
@@ -10,7 +11,6 @@
"main": "./lib/univer-core.js",
"module": "./lib/univer-core.mjs",
"types": "./lib/index.d.ts",
- "registry": "https://registry.npmjs.org/",
"access": "public"
},
"exports": {
diff --git a/packages/core/src/Command/ActionOperation.ts b/packages/core/src/Command/ActionOperation.ts
index 8cb674065a..045fe021b7 100644
--- a/packages/core/src/Command/ActionOperation.ts
+++ b/packages/core/src/Command/ActionOperation.ts
@@ -10,7 +10,7 @@ export class ActionOperation<T extends IActionData> {
ActionOperationType.OBSERVER_ACTION
);
}
- return false;
+ return true;
}
static hasUndo<U extends IActionData>(action: U): boolean {
@@ -20,7 +20,7 @@ export class ActionOperation<T extends IActionData> {
ActionOperationType.UNDO_ACTION
);
}
- return false;
+ return true;
}
static hasCollaboration<U extends IActionData>(action: U): boolean {
@@ -30,7 +30,7 @@ export class ActionOperation<T extends IActionData> {
ActionOperationType.SERVER_ACTION
);
}
- return false;
+ return true;
}
static hasExtension<U extends IActionData>(action: U): boolean {
@@ -40,7 +40,7 @@ export class ActionOperation<T extends IActionData> {
ActionOperationType.EXTENSION_ACTION
);
}
- return false;
+ return true;
}
static make<U extends IActionData>(action: U) {
diff --git a/packages/core/src/Command/CommandManager.ts b/packages/core/src/Command/CommandManager.ts
index dd65d3fa81..a5f74390b5 100644
--- a/packages/core/src/Command/CommandManager.ts
+++ b/packages/core/src/Command/CommandManager.ts
@@ -7,6 +7,7 @@ import { CommandObservers } from './CommandObservers';
import { CommandInjectorObservers } from './CommandInjectorObservers';
import { ContextBase } from '../Basics/ContextBase';
import { Command } from './Command';
+import { ActionOperation } from './ActionOperation';
/**
* Manage command
@@ -90,9 +91,17 @@ export class CommandManager {
const ActionClass = CommandManager.getAction(data.actionName);
const observers = CommandManager.getActionObservers();
const action = new ActionClass(data, _unit, observers);
- _actionList.push(action);
+
+ if (ActionOperation.hasUndo(data)) {
+ _actionList.push(action);
+ }
});
command.invoke();
+
+ if (_actionList.length === 0) {
+ return;
+ }
+
_undoManager.push(command);
// server.pushMessageQueue(command.getDoData());
}
diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
index 441bd18fcf..ee482a075f 100644
--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts
@@ -51,7 +51,7 @@ export class FormulaPromptController {
.getSheetContainerController()
.getMainSlotController()
.getSlot(FORMULA_PLUGIN_NAME + SearchFunction.name);
- console.info('searchFunction====', searchFunction);
+ this._searchFunction = searchFunction;
}
);
@@ -59,9 +59,20 @@ export class FormulaPromptController {
.getAppUIController()
.getSheetContainerController()
.getMainSlotController()
- .addSlot(FORMULA_PLUGIN_NAME + HelpFunction.name, {
- component: HelpFunction,
- });
+ .addSlot(
+ FORMULA_PLUGIN_NAME + HelpFunction.name,
+ {
+ component: HelpFunction,
+ },
+ () => {
+ const helpFunction = this._sheetUIPlugin
+ .getAppUIController()
+ .getSheetContainerController()
+ .getMainSlotController()
+ .getSlot(FORMULA_PLUGIN_NAME + HelpFunction.name);
+ this._helpFunction = helpFunction;
+ }
+ );
}
private _initialize() {
diff --git a/packages/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.json
index 7de1323ac9..2b80bb3a46 100644
--- a/packages/ui-plugin-sheets/package.json
+++ b/packages/ui-plugin-sheets/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/ui-plugin-sheets",
"version": "0.0.1",
"description": "UniverSheet normal ui-plugin-sheets",
- "keywords": [],
+ "keywords": ["univer","ui","sheets"],
"author": "DreamNum <[email protected]>",
"license": "MIT",
"main": "./src/index.ts",
@@ -11,7 +11,8 @@
"publishConfig": {
"main": "./lib/univer-ui-plugin-sheets.cjs.js",
"module": "./lib/univer-ui-plugin-sheets.es.js",
- "types": "./lib/index.d.ts"
+ "types": "./lib/index.d.ts",
+ "access": "public"
},
"exports": {
".": "./src/index.ts",
diff --git a/scripts/link.js b/scripts/link.js
index 1f82bac5c1..8e3775119f 100644
--- a/scripts/link.js
+++ b/scripts/link.js
@@ -7,7 +7,7 @@ const linkTargets = [
'@univerjs/base-ui', // success
'@univerjs/base-sheets', // success
- '@univerjs/common-plugin-data',
+ // '@univerjs/common-plugin-data',
// '@univerjs/sheets-plugin-format',
// '@univerjs/sheets-plugin-formula',
@@ -27,7 +27,7 @@ const linkTargets = [
// '@univerjs/sheets-plugin-split-column', // success
// '@univerjs/style-google',
- '@univerjs/style-univer', // success
+ '@univerjs/ui-plugin-sheets', // success
// '@univerjs/style-office365',
// '@univerjs/style-mobile',
];