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(formula): more functions component, separate plugins for calculation and UI (#440)
Dushusir6f5df245b058
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERSindex 40c33206c7..6715de5ea8 100644--- a/.github/CODEOWNERS+++ b/.github/CODEOWNERS@@ -32,3 +32,4 @@ packages/ui-plugin-slides @jikkai @wzhudevpackages/base-formula-engine @DR-Univerpackages/base-numfmt-engine @Gggpoundpackages/sheets-plugin-formula @DR-Univer+packages/sheets-plugin-formula-ui @DR-Univer @Dushusirdiff --git a/docs/architecture.md b/docs/architecture.mdindex ac267126da..8430a1e35b 100644--- a/docs/architecture.md+++ b/docs/architecture.md@@ -29,7 +29,7 @@ import { SheetPlugin } from '@univerjs/base-sheets';import { UIPlugin } from '@univerjs/base-ui';import { LocaleType, Univer } from '@univerjs/core';import { greenTheme } from '@univerjs/design';-import { FormulaPlugin } from '@univerjs/sheets-plugin-formula';+import { FormulaPlugin } from '@univerjs/sheets-plugin-formula-ui';import { SheetUIPlugin } from '@univerjs/ui-plugin-sheets';const univer = new Univer({diff --git a/examples/univer-sheet-ts/package.json b/examples/univer-sheet-ts/package.jsonindex 3c476cb130..fd3b2ae671 100644--- a/examples/univer-sheet-ts/package.json+++ b/examples/univer-sheet-ts/package.json@@ -28,6 +28,7 @@"@univerjs/sheets-plugin-debugger": "workspace:*","@univerjs/sheets-plugin-find": "workspace:*","@univerjs/sheets-plugin-formula": "workspace:*",+ "@univerjs/sheets-plugin-formula-ui": "workspace:*","@univerjs/sheets-plugin-import-xlsx": "workspace:*","@univerjs/sheets-plugin-numfmt": "workspace:*","@univerjs/ui-plugin-docs": "workspace:*",diff --git a/examples/univer-sheet-ts/src/locales.ts b/examples/univer-sheet-ts/src/locales.tsindex 7dc4d4d8c1..5874e1ada3 100644--- a/examples/univer-sheet-ts/src/locales.ts+++ b/examples/univer-sheet-ts/src/locales.ts@@ -5,7 +5,7 @@ import { Tools } from '@univerjs/core';import DeisgnZH from '@univerjs/design/locale/zh-CN';import SheetDebuggerPluginZhCN from '@univerjs/sheets-plugin-debugger/locale/zh-CN';import FindPluginZhCN from '@univerjs/sheets-plugin-find/locale/zh-CN';-import FormulaPluginZhCN from '@univerjs/sheets-plugin-formula/locale/zh-CN';+import FormulaPluginZhCN from '@univerjs/sheets-plugin-formula-ui/locale/zh-CN';import ImportXlsxPluginZhCN from '@univerjs/sheets-plugin-import-xlsx/locale/zh-CN';import NumberfmtPluginZhCN from '@univerjs/sheets-plugin-numfmt/locale/zh-CN';import DocUIPluginZhCN from '@univerjs/ui-plugin-docs/locale/zh-CN';diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex 4a4593f8fb..b36ee3431c 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -9,6 +9,7 @@ import { IUniverRPCMainThreadPluginConfig, UniverRPCMainThreadPlugin } from '@unimport { DebuggerPlugin } from '@univerjs/sheets-plugin-debugger';// import { FindPlugin } from '@univerjs/sheets-plugin-find';import { FormulaPlugin } from '@univerjs/sheets-plugin-formula';+import { FormulaUIPlugin } from '@univerjs/sheets-plugin-formula-ui';// import { ImagePlugin } from '@univerjs/sheets-plugin-image';// import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';// import { NumfmtPlugin } from '@univerjs/sheets-plugin-numfmt';@@ -43,6 +44,7 @@ univer.registerPlugin(DebuggerPlugin);// univer.registerPlugin(NumfmtPlugin);// univer.registerPlugin(FindPlugin);univer.registerPlugin(FormulaPlugin);+univer.registerPlugin(FormulaUIPlugin);univer.registerPlugin(UniverRPCMainThreadPlugin, {workerURL: './worker.js',} as IUniverRPCMainThreadPluginConfig);diff --git a/packages/base-formula-engine/src/basics/common.ts b/packages/base-formula-engine/src/basics/common.tsindex 377140da4a..0947e81d76 100644--- a/packages/base-formula-engine/src/basics/common.ts+++ b/packages/base-formula-engine/src/basics/common.ts@@ -58,7 +58,7 @@ export interface IUnitSheetNameMap {*/export interface IFormulaDataItem {f: string; // formulaString- si: string; // formulaId,+ // si: string; // formulaId,// row: number;// column: number;// sheetId: string;diff --git a/packages/base-formula-engine/src/basics/function.ts b/packages/base-formula-engine/src/basics/function.tsindex 196e8bbd15..1e82dd00b9 100644--- a/packages/base-formula-engine/src/basics/function.ts+++ b/packages/base-formula-engine/src/basics/function.ts@@ -1,21 +1,83 @@import { BooleanNumber } from '@univerjs/core';+/**+ * Function type, refer to https://support.microsoft.com/en-us/office/excel-functions-by-category-5f91f4e9-7b42-46d2-9bd1-63f26a86c0eb+ */export enum FunctionType {+ /**+ * Financial Functions+ */++ Financial,+ /**+ * Date and Time Functions+ */+ Date,++ /**+ * Math and Trigonometry Functions+ */Math,++ /**+ * Statistical Functions+ */Statistical,++ /**+ * Lookup and Reference Functions+ */Lookup,- DataMining,++ /**+ * Database Functions+ */Database,- Date,- Filter,- Financial,- Engineering,- Logical,- Operator,++ /**+ * Text Functions+ */Text,- Parser,++ /**+ * Logical Functions+ */+ Logical,++ /**+ * Information Functions+ */+ Information,++ /**+ * Engineering Functions+ */+ Engineering,++ /**+ * Cube Functions+ */+ Cube,++ /**+ * Compatibility Functions+ */+ Compatibility,++ /**+ * Web Functions+ */+ Web,++ /**+ * Array Functions+ */Array,- Other,++ /**+ * Univer-specific functions+ */+ Univer,}export interface IFunctionParam {diff --git a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.tsindex e3c970ede7..f20703353c 100644--- a/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts+++ b/packages/base-sheets/src/commands/mutations/set-range-values.mutation.ts@@ -94,6 +94,14 @@ export const SetRangeValuesUndoMutationFactory = (function setNull(value: Nullable<ICellData>) {if (value == null) return null;+ if (value.f === undefined) {+ value.f = null;+ }++ if (value.si === undefined) {+ value.si = null;+ }+if (value.p === undefined) {value.p = null;}@@ -141,6 +149,14 @@ export const SetRangeValuesMutation: IMutation<ISetRangeValuesMutationParams, bo} else {const oldVal = cellMatrix.getValue(row, col) || {};+ if (newVal.f !== undefined) {+ oldVal.f = newVal.f;+ }++ if (newVal.si !== undefined) {+ oldVal.si = newVal.si;+ }+if (newVal.p !== undefined) {oldVal.p = newVal.p;}diff --git a/packages/base-ui/src/Common/ComponentManager.ts b/packages/base-ui/src/Common/ComponentManager.tsindex ec9cff636d..f68d9951aa 100644--- a/packages/base-ui/src/Common/ComponentManager.ts+++ b/packages/base-ui/src/Common/ComponentManager.ts@@ -6,10 +6,12 @@ import {AllBorderSingle,AutoHeight,AutowrapSingle,+ AvgSingle,BoldSingle,BrushSingle,CancelMergeSingle,ClearFormat,+ CntSingle,Copy,DeleteCellMoveDown,DeleteCellShiftLeft,@@ -36,7 +38,9 @@ import {LeftJustifyingSingle,LeftRotationFortyFiveDegreesSingle,LeftRotationNinetyDegreesSingle,+ MaxSingle,MergeAllSingle,+ MinSingle,NoBorderSingle,NoColor,NoRotationSingle,@@ -52,6 +56,7 @@ import {RightRotationFortyFiveDegreesSingle,RightRotationNinetyDegreesSingle,StrikethroughSingle,+ SumSingle,TruncationSingle,UnderlineSingle,UndoSingle,@@ -133,6 +138,11 @@ export class ComponentManager {AutoHeight,AdjustHeight,AdjustWidth,+ AvgSingle,+ CntSingle,+ MaxSingle,+ MinSingle,+ SumSingle,};for (const k in iconList) {diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.tsindex f1d47dbb32..98315d310d 100644--- a/packages/core/src/shared/common.ts+++ b/packages/core/src/shared/common.ts@@ -130,6 +130,10 @@ export function isFormulaString(value: any): boolean {return Tools.isString(value) && value.indexOf('=') === 0 && value.length > 1;}+export function isFormulaId(value: any): boolean {+ return Tools.isString(value) && value.indexOf('=') === -1 && value.length === 6;+}+/*** move to Styles.getStyleByCell*/diff --git a/packages/core/src/types/interfaces/i-cell-data.ts b/packages/core/src/types/interfaces/i-cell-data.tsindex 3b2ef1a1f5..93ddfe89b8 100644--- a/packages/core/src/types/interfaces/i-cell-data.ts+++ b/packages/core/src/types/interfaces/i-cell-data.ts@@ -27,7 +27,8 @@ export interface ICellData {m?: Nullable<string>; // formatted value// Usually the type is automatically determined based on the data, or the user directly specifiest?: Nullable<CellValueType>; // 0 string, 1 number, 2 boolean, 3 force string, green icon, set null for cell clear all- // f?: string; // formula '=SUM(1)'+ f?: Nullable<string>; // formula '=SUM(1)'+ si?: Nullable<string>; // formula id/*** format*/@@ -55,10 +56,11 @@ export interface ICellData {// eslint-disable-next-line @typescript-eslint/no-explicit-anyexport function isICellData(value: any): value is ICellData {return (- value &&- ((value as ICellData).s !== undefined ||- (value as ICellData).p !== undefined ||- (value as ICellData).v !== undefined)+ (value &&+ ((value as ICellData).s !== undefined ||+ (value as ICellData).p !== undefined ||+ (value as ICellData).v !== undefined)) ||+ (value as ICellData).f !== undefined);}diff --git a/packages/sheets-plugin-formula-ui/README.md b/packages/sheets-plugin-formula-ui/README.mdnew file mode 100644index 0000000000..fc2ed1a4af--- /dev/null+++ b/packages/sheets-plugin-formula-ui/README.md@@ -0,0 +1,14 @@+# @univerjs/sheets-plugin-formula-ui++## Introduction++Univer sheets-plugin-formula-ui++## Usage+### Installation+```shell+npm i @univerjs/sheets-plugin-formula-ui+```++### API+Check [Univer](https://github.com/dream-num/univer/)diff --git a/packages/sheets-plugin-formula/esbuild.config.mjs b/packages/sheets-plugin-formula-ui/esbuild.config.mjssimilarity index 100%rename from packages/sheets-plugin-formula/esbuild.config.mjsrename to packages/sheets-plugin-formula-ui/esbuild.config.mjsdiff --git a/packages/sheets-plugin-formula-ui/package.json b/packages/sheets-plugin-formula-ui/package.jsonnew file mode 100644index 0000000000..6092e1828c--- /dev/null+++ b/packages/sheets-plugin-formula-ui/package.json@@ -0,0 +1,48 @@+{+ "name": "@univerjs/sheets-plugin-formula-ui",+ "version": "0.0.1",+ "author": "DreamNum <[email protected]>",+ "license": "MIT",+ "main": "./src/index.ts",+ "module": "./src/index.ts",+ "exports": {+ ".": "./src/index.ts",+ "./*": "./src/*",+ "./locale/*": "./src/locale/*.ts"+ },+ "directories": {+ "lib": "lib"+ },+ "files": [+ "lib"+ ],+ "private": true,+ "type": "module",+ "scripts": {},+ "dependencies": {+ "@univerjs/base-docs": "workspace:*",+ "@univerjs/base-formula-engine": "workspace:*",+ "@univerjs/base-render": "workspace:*",+ "@univerjs/base-sheets": "workspace:*",+ "@univerjs/base-ui": "workspace:*",+ "@univerjs/core": "workspace:*",+ "@univerjs/design": "workspace:*",+ "@univerjs/icons": "^0.1.7",+ "@univerjs/ui-plugin-sheets": "workspace:*",+ "@wendellhu/redi": "^0.12.11",+ "react": "^18.2.0",+ "react-dom": "^18.2.0",+ "rxjs": "^7.8.1"+ },+ "devDependencies": {+ "@types/node": "^20.9.0",+ "@types/react": "^18.2.37",+ "@types/react-dom": "^18.2.15",+ "@vitest/coverage-istanbul": "^0.34.6",+ "esbuild": "^0.19.5",+ "happy-dom": "^12.10.3",+ "less": "^4.2.0",+ "ts-node": "^10.9.1",+ "vitest": "^0.34.6"+ }+}diff --git a/packages/sheets-plugin-formula/src/commands/operations/editor-formula.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/commands/operations/editor-formula.operation.tsrename to packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.tsdiff --git a/packages/sheets-plugin-formula/src/commands/operations/help-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/commands/operations/help-function.operation.tsrename to packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.tsdiff --git a/packages/sheets-plugin-formula/src/commands/operations/insert-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/commands/operations/insert-function.operation.tsrename to packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.tsdiff --git a/packages/sheets-plugin-formula-ui/src/commands/operations/more-functions.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/more-functions.operation.tsnew file mode 100644index 0000000000..fd96d08a80--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/commands/operations/more-functions.operation.ts@@ -0,0 +1,20 @@+import { ISidebarService } from '@univerjs/base-ui';+import { CommandType, ICommand } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { MORE_FUNCTIONS_COMPONENT } from '../../views/more-functions/interface';++export const MoreFunctionsOperation: ICommand = {+ id: 'formula.operation.more-functions',+ type: CommandType.OPERATION,+ handler: async (accessor: IAccessor) => {+ const sidebarService = accessor.get(ISidebarService);++ sidebarService.open({+ header: { title: 'formula.insert.tooltip' },+ children: { label: MORE_FUNCTIONS_COMPONENT },+ });++ return true;+ },+};diff --git a/packages/sheets-plugin-formula/src/commands/operations/search-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/commands/operations/search-function.operation.tsrename to packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.tsdiff --git a/packages/sheets-plugin-formula-ui/src/common/plugin-name.ts b/packages/sheets-plugin-formula-ui/src/common/plugin-name.tsnew file mode 100644index 0000000000..944ac89a99--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/common/plugin-name.ts@@ -0,0 +1 @@+export const FORMULA_UI_PLUGIN_NAME = 'formula-ui';diff --git a/packages/sheets-plugin-formula-ui/src/controllers/formula-ui.controller.ts b/packages/sheets-plugin-formula-ui/src/controllers/formula-ui.controller.tsnew file mode 100644index 0000000000..99233ed499--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/controllers/formula-ui.controller.ts@@ -0,0 +1,76 @@+import {+ ComponentManager,+ IDesktopUIController,+ IMenuService,+ IShortcutService,+ IUIController,+} from '@univerjs/base-ui';+import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';+import { Inject, Injector } from '@wendellhu/redi';+import { connectInjector } from '@wendellhu/redi/react-bindings';++import { SelectEditorFormluaOperation } from '../commands/operations/editor-formula.operation';+import { HelpFunctionOperation } from '../commands/operations/help-function.operation';+import { InsertFunctionOperation } from '../commands/operations/insert-function.operation';+import { MoreFunctionsOperation } from '../commands/operations/more-functions.operation';+import { SearchFunctionOperation } from '../commands/operations/search-function.operation';+import { RenderFormulaPromptContent } from '../views/FormulaPromptContainer';+import { MORE_FUNCTIONS_COMPONENT } from '../views/more-functions/interface';+import { MoreFunctions } from '../views/more-functions/MoreFunctions';+import { InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory } from './menu';+import { promptSelectionShortcutItem } from './shortcuts/prompt.shortcut';++@OnLifecycle(LifecycleStages.Ready, FormulaUIController)+export class FormulaUIController extends Disposable {+ constructor(+ @Inject(Injector) private readonly _injector: Injector,+ @IMenuService private readonly _menuService: IMenuService,+ @ICommandService private readonly _commandService: ICommandService,+ @IShortcutService private readonly _shortcutService: IShortcutService,+ @IUIController private readonly _uiController: IDesktopUIController,+ @Inject(ComponentManager) private readonly _componentManager: ComponentManager+ ) {+ super();++ this._initialize();+ }++ private _initialize(): void {+ this._registerCommands();+ this._registerMenus();+ this._registerShortcuts();+ this._registerComponents();+ }++ private _registerMenus(): void {+ [InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory].forEach((factory) => {+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));+ });+ }++ private _registerCommands(): void {+ [+ InsertFunctionOperation,+ MoreFunctionsOperation,+ SearchFunctionOperation,+ HelpFunctionOperation,+ SelectEditorFormluaOperation,+ ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));+ }++ private _registerShortcuts(): void {+ [...promptSelectionShortcutItem()].forEach((item) => {+ this.disposeWithMe(this._shortcutService.registerShortcut(item));+ });+ }++ private _registerComponents(): void {+ this.disposeWithMe(+ this._uiController.registerContentComponent(() =>+ connectInjector(RenderFormulaPromptContent, this._injector)+ )+ );++ this._componentManager.register(MORE_FUNCTIONS_COMPONENT, MoreFunctions);+ }+}diff --git a/packages/sheets-plugin-formula/src/controllers/menu.ts b/packages/sheets-plugin-formula-ui/src/controllers/menu.tssimilarity index 89%rename from packages/sheets-plugin-formula/src/controllers/menu.tsrename to packages/sheets-plugin-formula-ui/src/controllers/menu.tsindex ecc349fb79..4dfb3a08a3 100644--- a/packages/sheets-plugin-formula/src/controllers/menu.ts+++ b/packages/sheets-plugin-formula-ui/src/controllers/menu.ts@@ -16,22 +16,27 @@ export function InsertFunctionMenuItemFactory(accessor: IAccessor): IMenuItem {{label: 'SUM',value: 'SUM',+ icon: 'SumSingle',},{label: 'AVERAGE',value: 'AVERAGE',+ icon: 'AvgSingle',},{label: 'COUNT',value: 'COUNT',+ icon: 'CntSingle',},{label: 'MAX',value: 'MAX',+ icon: 'MaxSingle',},{label: 'MIN',value: 'MIN',+ icon: 'MinSingle',},],};diff --git a/packages/sheets-plugin-formula/src/controllers/prompt.controller.ts b/packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/controllers/prompt.controller.tsrename to packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.tsdiff --git a/packages/sheets-plugin-formula/src/controllers/shortcuts/prompt.shortcut.ts b/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/controllers/shortcuts/prompt.shortcut.tsrename to packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.tsdiff --git a/packages/sheets-plugin-formula/src/controllers/util.ts b/packages/sheets-plugin-formula-ui/src/controllers/util.tssimilarity index 92%rename from packages/sheets-plugin-formula/src/controllers/util.tsrename to packages/sheets-plugin-formula-ui/src/controllers/util.tsindex f11059d702..0be660aa38 100644--- a/packages/sheets-plugin-formula/src/controllers/util.ts+++ b/packages/sheets-plugin-formula-ui/src/controllers/util.ts@@ -1,6 +1,7 @@import { IFunctionInfo } from '@univerjs/base-formula-engine';import { LocaleService } from '@univerjs/core';+// TODO@Dushusir: merged to service/utilsexport function getFunctionName(item: IFunctionInfo, localeService: LocaleService) {let functionName = '';if (item.aliasFunctionName) {diff --git a/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts b/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.tsnew file mode 100644index 0000000000..18dc1b847a--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts@@ -0,0 +1,42 @@+import { IUniverInstanceService, LocaleService, Plugin, PluginType } from '@univerjs/core';+import { Dependency, Inject, Injector } from '@wendellhu/redi';++import { FORMULA_UI_PLUGIN_NAME } from './common/plugin-name';+import { FormulaUIController } from './controllers/formula-ui.controller';+import { PromptController } from './controllers/prompt.controller';+import { enUS } from './locale';+import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';++// TODO@Dushusir: user config IFunctionInfo, we will register all function info in formula engine+export class FormulaUIPlugin extends Plugin {+ static override type = PluginType.Sheet;++ constructor(+ private _config: undefined,+ @Inject(Injector) override readonly _injector: Injector,+ @Inject(LocaleService) private readonly _localeService: LocaleService,+ @IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService+ ) {+ super(FORMULA_UI_PLUGIN_NAME);+ }++ initialize(): void {+ this._localeService.load({+ enUS,+ });++ const dependencies: Dependency[] = [+ // services+ [IFormulaPromptService, { useClass: FormulaPromptService }],+ // controllers+ [FormulaUIController],+ [PromptController],+ ];++ dependencies.forEach((dependency) => this._injector.add(dependency));+ }++ override onReady(): void {+ this.initialize();+ }+}diff --git a/packages/sheets-plugin-formula-ui/src/index.ts b/packages/sheets-plugin-formula-ui/src/index.tsnew file mode 100644index 0000000000..4e740586ba--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/index.ts@@ -0,0 +1 @@+export { FormulaUIPlugin } from './formula-ui-plugin';diff --git a/packages/sheets-plugin-formula/src/locale/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/en-US.tssimilarity index 74%rename from packages/sheets-plugin-formula/src/locale/en-US.tsrename to packages/sheets-plugin-formula-ui/src/locale/en-US.tsindex 32f9d77594..545cb19dc4 100644--- a/packages/sheets-plugin-formula/src/locale/en-US.ts+++ b/packages/sheets-plugin-formula-ui/src/locale/en-US.ts@@ -49,10 +49,32 @@ export default {// },// },},-formulaMore: {helpExample: 'EXAMPLE',helpAbstract: 'ABOUT',++ financial: 'Financial',+ date: 'Date & Time',+ math: 'Math & Trig',+ statistical: 'Statistical',+ lookup: 'Lookup & Reference',+ database: 'Database',+ text: 'Text',+ logical: 'Logical',+ information: 'Information',+ engineering: 'Engineering',+ cube: 'Cube',+ compatibility: 'Compatibility',+ web: 'Web',+ array: 'Array',+ univer: 'Univer',++ searchFunctionPlaceholder: 'Search function',+ },+ moreFunctions: {+ confirm: 'Confirm',+ prev: 'Previous',+ next: 'Next',},},};diff --git a/packages/sheets-plugin-formula/src/locale/index.ts b/packages/sheets-plugin-formula-ui/src/locale/index.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/locale/index.tsrename to packages/sheets-plugin-formula-ui/src/locale/index.tsdiff --git a/packages/sheets-plugin-formula/src/locale/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.tssimilarity index 80%rename from packages/sheets-plugin-formula/src/locale/zh-CN.tsrename to packages/sheets-plugin-formula-ui/src/locale/zh-CN.tsindex b7abccee4c..cf383d4427 100644--- a/packages/sheets-plugin-formula/src/locale/zh-CN.ts+++ b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts@@ -54,6 +54,30 @@ export default {formulaMore: {helpExample: '示例',helpAbstract: '简介',++ financial: '财务',+ date: '日期与时间',+ math: '数学与三角函数',+ statistical: '统计',+ lookup: '查找与引用',+ database: '数据库',+ text: '文本',+ logical: '逻辑',+ information: '信息',+ engineering: '工程',+ cube: '多维数据集',+ compatibility: '兼容性',+ web: 'Web',+ array: '数组',+ univer: 'Univer',++ searchFunctionPlaceholder: '搜索函数',+ },++ moreFunctions: {+ confirm: '确定',+ prev: '上一步',+ next: '下一步',},},};diff --git a/packages/sheets-plugin-formula/src/services/function-list.ts b/packages/sheets-plugin-formula-ui/src/services/function-list.tssimilarity index 92%rename from packages/sheets-plugin-formula/src/services/function-list.tsrename to packages/sheets-plugin-formula-ui/src/services/function-list.tsindex e8e6fc1163..fd6c2c8f80 100644--- a/packages/sheets-plugin-formula/src/services/function-list.ts+++ b/packages/sheets-plugin-formula-ui/src/services/function-list.ts@@ -1,23 +1,5 @@import { IFunctionInfo } from '@univerjs/base-formula-engine';-export enum FunctionType {- Math,- Statistical,- Lookup,- DataMining,- Database,- Date,- Filter,- Financial,- Engineering,- Logical,- Operator,- Text,- Parser,- Array,- Other,-}-// TODO@Dushusir: register custom function// TODO@Dushusir: register custom locale fileexport interface IFunctionDescription {diff --git a/packages/sheets-plugin-formula/src/services/prompt.service.ts b/packages/sheets-plugin-formula-ui/src/services/prompt.service.tssimilarity index 100%rename from packages/sheets-plugin-formula/src/services/prompt.service.tsrename to packages/sheets-plugin-formula-ui/src/services/prompt.service.tsdiff --git a/packages/sheets-plugin-formula-ui/src/services/utils.ts b/packages/sheets-plugin-formula-ui/src/services/utils.tsnew file mode 100644index 0000000000..e60bd30b4c--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/services/utils.ts@@ -0,0 +1,13 @@+import { LocaleService } from '@univerjs/core';++export function getFunctionTypeValues(+ enumObj: any,+ localeService: LocaleService+): Array<{ label: string; value: string }> {+ return Object.keys(enumObj)+ .filter((key) => isNaN(Number(key)))+ .map((key) => ({+ label: localeService.t(`formula.formulaMore.${key.toLocaleLowerCase()}`),+ value: `${enumObj[key]}`,+ }));+}diff --git a/packages/sheets-plugin-formula/src/views/FormulaContainer.tsx b/packages/sheets-plugin-formula-ui/src/views/FormulaPromptContainer.tsxsimilarity index 84%rename from packages/sheets-plugin-formula/src/views/FormulaContainer.tsxrename to packages/sheets-plugin-formula-ui/src/views/FormulaPromptContainer.tsxindex 74415e8b45..99060ec652 100644--- a/packages/sheets-plugin-formula/src/views/FormulaContainer.tsx+++ b/packages/sheets-plugin-formula-ui/src/views/FormulaPromptContainer.tsx@@ -1,7 +1,7 @@import { HelpFunction } from './prompt/help-function/HelpFunction';import { SearchFunction } from './prompt/search-function/SearchFunction';-export function RenderFormulaContent() {+export function RenderFormulaPromptContent() {return (<><SearchFunction />diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/InputParams.tsx b/packages/sheets-plugin-formula-ui/src/views/more-functions/InputParams.tsxnew file mode 100644index 0000000000..1634a3183e--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/InputParams.tsx@@ -0,0 +1,3 @@+export function InputParams() {+ return <div>Input params</div>;+}diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/MoreFunctions.tsx b/packages/sheets-plugin-formula-ui/src/views/more-functions/MoreFunctions.tsxnew file mode 100644index 0000000000..f12c13f806--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/MoreFunctions.tsx@@ -0,0 +1,50 @@+import { ISidebarService } from '@univerjs/base-ui';+import { LocaleService } from '@univerjs/core';+import { Button } from '@univerjs/design';+import { useDependency } from '@wendellhu/redi/react-bindings';+import { useState } from 'react';++import styles from './index.module.less';+import { InputParams } from './InputParams';+import { SelectFunction } from './select-function/SelectFunction';++export function MoreFunctions() {+ const [selectFunction, setSelectFunction] = useState<boolean>(true);+ const [inputParams, setInputParams] = useState<boolean>(false);++ const localeService = useDependency(LocaleService);+ const sidebarService = useDependency(ISidebarService);++ function handleClickNextPrev() {+ setSelectFunction(!selectFunction);+ setInputParams(!inputParams);+ }++ function handleConfirm() {+ sidebarService.close();+ }++ return (+ <div className={styles.formulaMoreFunctions}>+ {selectFunction && <SelectFunction></SelectFunction>}+ {inputParams && <InputParams></InputParams>}+ <div>+ {selectFunction && (+ <Button type="primary" onClick={handleClickNextPrev}>+ {localeService.t('formula.moreFunctions.next')}+ </Button>+ )}+ {inputParams && (+ <Button type="text" onClick={handleClickNextPrev}>+ {localeService.t('formula.moreFunctions.prev')}+ </Button>+ )}+ {inputParams && (+ <Button type="primary" onClick={handleConfirm}>+ {localeService.t('formula.moreFunctions.confirm')}+ </Button>+ )}+ </div>+ </div>+ );+}diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/index.module.less b/packages/sheets-plugin-formula-ui/src/views/more-functions/index.module.lessnew file mode 100644index 0000000000..00a719eab1--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/index.module.less@@ -0,0 +1,6 @@+.formula-more-functions {+ display: flex;+ flex-direction: column;+ justify-content: space-between;+ height: 100%;+}\ No newline at end of filediff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/interface.ts b/packages/sheets-plugin-formula-ui/src/views/more-functions/interface.tsnew file mode 100644index 0000000000..6e7244878a--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/interface.ts@@ -0,0 +1,3 @@+import { FORMULA_UI_PLUGIN_NAME } from '../../common/plugin-name';++export const MORE_FUNCTIONS_COMPONENT = `${FORMULA_UI_PLUGIN_NAME}_MORE_FUNCTIONS_COMPONENT`;diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx b/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/SelectFunction.tsxnew file mode 100644index 0000000000..0c57b29afc--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/SelectFunction.tsx@@ -0,0 +1,111 @@+import { FunctionType, IFunctionInfo } from '@univerjs/base-formula-engine';+import { LocaleService } from '@univerjs/core';+import { Input, Select } from '@univerjs/design';+import { useDependency } from '@wendellhu/redi/react-bindings';+import { useState } from 'react';++import { getFunctionName } from '../../../controllers/util';+import { FUNCTION_LIST } from '../../../services/function-list';+import { getFunctionTypeValues } from '../../../services/utils';+import styles from './index.module.less';++export function getSearchList(searchText: string, localeService: LocaleService) {+ const searchList: string[] = [];+ FUNCTION_LIST.forEach((item) => {+ const functionName = getFunctionName(item, localeService);+ if (functionName.indexOf(searchText.toLocaleUpperCase()) > -1) {+ searchList.push(functionName);+ }+ });++ return searchList;+}++function getFunctionInfo(functionName: string, localeService: LocaleService) {+ return FUNCTION_LIST.find((item) => getFunctionName(item, localeService) === functionName);+}++export function SelectFunction() {+ const [selectList, setSelectList] = useState<string[]>([]);+ const [searchText, setSearchText] = useState<string>('');+ const [active, setActive] = useState(0);+ const [functionInfo, setFunctionInfo] = useState<IFunctionInfo | null>(null);+ const localeService = useDependency(LocaleService);+ const options = getFunctionTypeValues(FunctionType, localeService);++ const highlightSearchText = (text: string) => {+ const regex = new RegExp(`(${searchText})`);+ const parts = text.split(regex).filter(Boolean);+ console.info('parts', parts, searchText);++ return parts.map((part: string, index: number) => {+ if (part.match(regex)) {+ return (+ <span key={index} className={styles.formulaSelectFunctionResultItemNameLight}>+ {part}+ </span>+ );+ }+ return part;+ });+ };++ function handleSelectChange(value: string) {+ console.info('value=====', value);+ }++ function handleSearchInputChange(value: string) {+ setSearchText(value);+ const selectList = getSearchList(value, localeService);+ // console.info('搜索===', selectList, searchText);+ setSelectList(selectList);+ setActive(0);+ const functionInfo = getFunctionInfo(selectList[active], localeService);+ if (!functionInfo) return;+ setFunctionInfo(functionInfo);+ }++ function handleClickSelectItem(value: string) {+ console.info('value=====', value);+ }++ const handleLiMouseEnter = (index: number) => {+ setActive(index);+ };++ const handleLiMouseLeave = () => {+ setActive(-1);+ };+ return (+ <div>+ <div>+ <Select value="select" options={options} onChange={handleSelectChange}></Select>++ <Input+ placeholder={localeService.t(`formula.formulaMore.searchFunctionPlaceholder`)}+ onKeyDown={(e) => e.stopPropagation()}+ value={searchText}+ onChange={handleSearchInputChange}+ ></Input>+ </div>++ <ul className={styles.formulaSelectFunctionResult}>+ {selectList.map((item, index) => (+ <li+ key={index}+ className={+ active === index+ ? `${styles.formulaSelectFunctionResultItem} ${styles.formulaSelectFunctionResultItemActive}`+ : styles.formulaSelectFunctionResultItem+ }+ // onMouseEnter={() => handleLiMouseEnter(index)}+ // onMouseLeave={handleLiMouseLeave}+ onClick={() => handleClickSelectItem(item)}+ >+ <span className={styles.formulaSelectFunctionResultItemName}>{highlightSearchText(item)}</span>+ </li>+ ))}+ </ul>+ </div>+ );+}diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/index.module.less b/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/index.module.lessnew file mode 100644index 0000000000..2c127edc4b--- /dev/null+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/select-function/index.module.less@@ -0,0 +1,37 @@+.formula-select-function {+ &-result {+ box-sizing: border-box;+ width: 100%;+ margin: 0;+ padding: var(--padding-base);++ font-size: var(--font-size-sm);+ list-style: none;++ outline: none;++ &-item {+ cursor: pointer;++ box-sizing: border-box;+ padding: var(--padding-sm);++ color: rgb(var(--text-color));++ border-radius: var(--border-radius-base);++ transition: background .2s;++ &-name {+ &-light {+ color: rgb(var(--error-color));+ }+ }++ &-active {+ background-color: rgb(var(--bg-color-hover));+ }+ }+ }++}\ No newline at end of filediff --git a/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsx b/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsxsimilarity index 99%rename from packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsxrename to packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsxindex 1487cb1988..966e51ac93 100644--- a/packages/sheets-plugin-formula/src/views/prompt/help-function/HelpFunction.tsx+++ b/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsx@@ -60,9 +60,9 @@ export function HelpFunction() {};}, []);- const handleSwitchActive = (paramIndex: number) => {+ function handleSwitchActive(paramIndex: number) {setParamIndex(paramIndex);- };+ }return (<>diff --git a/packages/sheets-plugin-formula/src/views/prompt/help-function/index.module.less b/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/index.module.lesssimilarity index 100%rename from packages/sheets-plugin-formula/src/views/prompt/help-function/index.module.lessrename to packages/sheets-plugin-formula-ui/src/views/prompt/help-function/index.module.lessdiff --git a/packages/sheets-plugin-formula/src/views/prompt/search-function/SearchFunction.tsx b/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsxsimilarity index 97%rename from packages/sheets-plugin-formula/src/views/prompt/search-function/SearchFunction.tsxrename to packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsxindex 20e4eb78d6..6caa0223d4 100644--- a/packages/sheets-plugin-formula/src/views/prompt/search-function/SearchFunction.tsx+++ b/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsx@@ -72,13 +72,13 @@ export function SearchFunction() {};}, []);- const handleLiMouseEnter = (index: number) => {+ function handleLiMouseEnter(index: number) {setActive(index);- };+ }- const handleLiMouseLeave = () => {+ function handleLiMouseLeave() {setActive(-1);- };+ }return (<Dropdowndiff --git a/packages/sheets-plugin-formula/src/views/prompt/search-function/index.module.less b/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/index.module.lesssimilarity index 100%rename from packages/sheets-plugin-formula/src/views/prompt/search-function/index.module.lessrename to packages/sheets-plugin-formula-ui/src/views/prompt/search-function/index.module.lessdiff --git a/packages/sheets-plugin-formula/tsconfig.json b/packages/sheets-plugin-formula-ui/tsconfig.jsonsimilarity index 57%rename from packages/sheets-plugin-formula/tsconfig.jsonrename to packages/sheets-plugin-formula-ui/tsconfig.jsonindex 3e80c72c70..595404a5fd 100644--- a/packages/sheets-plugin-formula/tsconfig.json+++ b/packages/sheets-plugin-formula-ui/tsconfig.json@@ -9,5 +9,5 @@},"include": ["src/**/*"- ]+, "../sheets-plugin-formula/src/controllers/calculate.controller.ts", "../sheets-plugin-formula/src/commands/mutations/set-formula-data.mutation.ts", "../sheets-plugin-formula/src/controllers/formula.controller.ts" ]}\ No newline at end of filediff --git a/packages/sheets-plugin-formula/vitest.config copy.ts b/packages/sheets-plugin-formula-ui/vitest.config copy.tssimilarity index 100%rename from packages/sheets-plugin-formula/vitest.config copy.tsrename to packages/sheets-plugin-formula-ui/vitest.config copy.tsdiff --git a/packages/sheets-plugin-formula/vitest.config.ts b/packages/sheets-plugin-formula-ui/vitest.config.tssimilarity index 100%rename from packages/sheets-plugin-formula/vitest.config.tsrename to packages/sheets-plugin-formula-ui/vitest.config.tsdiff --git a/packages/sheets-plugin-formula/package.json b/packages/sheets-plugin-formula/package.jsonindex 6f7cd31647..1763acb9a7 100644--- a/packages/sheets-plugin-formula/package.json+++ b/packages/sheets-plugin-formula/package.json@@ -18,31 +18,10 @@],"private": true,"type": "module",- "scripts": {},"dependencies": {- "@univerjs/base-docs": "workspace:*","@univerjs/base-formula-engine": "workspace:*",- "@univerjs/base-render": "workspace:*","@univerjs/base-sheets": "workspace:*",- "@univerjs/base-ui": "workspace:*","@univerjs/core": "workspace:*",- "@univerjs/design": "workspace:*",- "@univerjs/icons": "^0.1.12",- "@univerjs/ui-plugin-sheets": "workspace:*",- "@wendellhu/redi": "^0.12.11",- "react": "^18.2.0",- "react-dom": "^18.2.0",- "rxjs": "^7.8.1"- },- "devDependencies": {- "@types/node": "^20.9.0",- "@types/react": "^18.2.37",- "@types/react-dom": "^18.2.15",- "@vitest/coverage-istanbul": "^0.34.6",- "esbuild": "^0.19.5",- "happy-dom": "^12.10.3",- "less": "^4.2.0",- "ts-node": "^10.9.1",- "vitest": "^0.34.6"+ "@wendellhu/redi": "^0.12.11"}}diff --git a/packages/sheets-plugin-formula/src/commands/operations/more-functions.operation.ts b/packages/sheets-plugin-formula/src/commands/operations/more-functions.operation.tsdeleted file mode 100644index b371695b24..0000000000--- a/packages/sheets-plugin-formula/src/commands/operations/more-functions.operation.ts+++ /dev/null@@ -1,8 +0,0 @@-import { CommandType, ICommand } from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';--export const MoreFunctionsOperation: ICommand = {- id: 'formula.operation.more-functions',- type: CommandType.OPERATION,- handler: async (accessor: IAccessor) => true,-};diff --git a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts b/packages/sheets-plugin-formula/src/controllers/calculate.controller.tsindex 0ab0e40032..d78ef2963f 100644--- a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts+++ b/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts@@ -5,6 +5,7 @@ import {ICommandInfo,ICommandService,IRange,+ isFormulaId,isFormulaString,IUnitRange,IUniverInstanceService,@@ -16,7 +17,6 @@ import {} from '@univerjs/core';import { Inject } from '@wendellhu/redi';-import { ISetFormulaDataMutationParams, SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';import { FormulaDataModel } from '../models/formula-data.model';@OnLifecycle(LifecycleStages.Starting, CalculateController)@@ -58,7 +58,7 @@ export class CalculateController extends Disposable {const { worksheetId: sheetId, workbookId: unitId, cellValue } = params;if (cellValue == null) return;- const formulaData = Tools.deepClone(this._formulaDataModel.getFormulaData());+ const formulaData = this._formulaDataModel.getFormulaData();const unitRange: IUnitRange[] = [];let isCalculate = false;@@ -72,13 +72,19 @@ export class CalculateController extends Disposable {const cellData = new ObjectMatrix(formulaData[unitId][sheetId]);const rangeMatrix = new ObjectMatrix(cellValue);+ const formulaIdMap = new Map<string, string>(); // Connect the formula and IDlet isArrayFormula = false;// update formula string,Any modification to cellData will be linked to formulaDatarangeMatrix.forValue((r, c, cell) => {const arrayFormCellRangeData = this._checkArrayFormulaValue(r, c);- const formulaString = cell?.m;- if (arrayFormCellRangeData && formulaString === '') {++ const formulaString = cell?.f || '';+ const formulaId = cell?.si || '';+ if (!formulaString && formulaId) {+ isCalculate = true;+ cellData.setValue(r, c, { f: formulaId });+ } else if (arrayFormCellRangeData && formulaString === '') {isArrayFormula = true;isCalculate = true;@@ -93,7 +99,19 @@ export class CalculateController extends Disposable {}} else if (isFormulaString(formulaString)) {isCalculate = true;- cellData.setValue(r, c, { f: formulaString as string, si: '' });+ cellData.setValue(r, c, { f: formulaString });++ if (isFormulaId(formulaId)) {+ formulaIdMap.set(formulaId, formulaString);+ }+ }+ });++ // Convert the formula ID to formula string+ cellData.forValue((r, c, cell) => {+ const formulaId = cell?.f || '';+ if (formulaIdMap.has(formulaId)) {+ cellData.setValue(r, c, { f: formulaIdMap.get(formulaId) as string });}});@@ -137,7 +155,7 @@ export class CalculateController extends Disposable {const sheetIds = Object.keys(sheetData);- // 1. Update each calculated value, possibly involving all cells+ // Update each calculated value, possibly involving all cellsconst redoMutationsInfo: ICommandInfo[] = [];sheetIds.forEach((sheetId) => {const cellData = sheetData[sheetId];@@ -153,16 +171,6 @@ export class CalculateController extends Disposable {});});- // 2. Update formula data- const setFormulaDataMutation: ISetFormulaDataMutationParams = {- formulaData,- };-- redoMutationsInfo.push({- id: SetFormulaDataMutation.id,- params: setFormulaDataMutation,- });-const result = redoMutationsInfo.every((m) => this._commandService.executeCommand(m.id, m.params));return result;});diff --git a/packages/sheets-plugin-formula/src/controllers/formula.controller.ts b/packages/sheets-plugin-formula/src/controllers/formula.controller.tsindex 9b17435050..1bce2467ab 100644--- a/packages/sheets-plugin-formula/src/controllers/formula.controller.ts+++ b/packages/sheets-plugin-formula/src/controllers/formula.controller.ts@@ -1,27 +1,10 @@-import { IDesktopUIController, IMenuService, IShortcutService, IUIController } from '@univerjs/base-ui';import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univerjs/core';-import { Inject, Injector } from '@wendellhu/redi';-import { connectInjector } from '@wendellhu/redi/react-bindings';import { SetFormulaDataMutation } from '../commands/mutations/set-formula-data.mutation';-import { SelectEditorFormluaOperation } from '../commands/operations/editor-formula.operation';-import { HelpFunctionOperation } from '../commands/operations/help-function.operation';-import { InsertFunctionOperation } from '../commands/operations/insert-function.operation';-import { MoreFunctionsOperation } from '../commands/operations/more-functions.operation';-import { SearchFunctionOperation } from '../commands/operations/search-function.operation';-import { RenderFormulaContent } from '../views/FormulaContainer';-import { InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory } from './menu';-import { promptSelectionShortcutItem } from './shortcuts/prompt.shortcut';@OnLifecycle(LifecycleStages.Ready, FormulaController)export class FormulaController extends Disposable {- constructor(- @Inject(Injector) private readonly _injector: Injector,- @IMenuService private readonly _menuService: IMenuService,- @ICommandService private readonly _commandService: ICommandService,- @IShortcutService private readonly _shortcutService: IShortcutService,- @IUIController private readonly _uiController: IDesktopUIController- ) {+ constructor(@ICommandService private readonly _commandService: ICommandService) {super();this._initialize();@@ -29,37 +12,11 @@ export class FormulaController extends Disposable {private _initialize(): void {this._registerCommands();- this._registerMenus();- this._registerShortcuts();- this._registerComponents();- }-- private _registerMenus(): void {- [InsertFunctionMenuItemFactory, MoreFunctionsMenuItemFactory].forEach((factory) => {- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));- });}private _registerCommands(): void {- [- InsertFunctionOperation,- MoreFunctionsOperation,- SearchFunctionOperation,- HelpFunctionOperation,- SelectEditorFormluaOperation,- SetFormulaDataMutation,- ].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));- }-- private _registerShortcuts(): void {- [...promptSelectionShortcutItem()].forEach((item) => {- this.disposeWithMe(this._shortcutService.registerShortcut(item));- });- }-- private _registerComponents(): void {- this.disposeWithMe(- this._uiController.registerContentComponent(() => connectInjector(RenderFormulaContent, this._injector))+ [SetFormulaDataMutation].forEach((command) =>+ this.disposeWithMe(this._commandService.registerCommand(command)));}}diff --git a/packages/sheets-plugin-formula/src/formula-plugin.ts b/packages/sheets-plugin-formula/src/formula-plugin.tsindex 6deca1ae06..e8e5514a8e 100644--- a/packages/sheets-plugin-formula/src/formula-plugin.ts+++ b/packages/sheets-plugin-formula/src/formula-plugin.ts@@ -1,55 +1,35 @@-import { IUniverInstanceService, LocaleService, Plugin, PluginType } from '@univerjs/core';+import { IUniverInstanceService, Plugin, PluginType } from '@univerjs/core';import { Dependency, Inject, Injector } from '@wendellhu/redi';import { FORMULA_PLUGIN_NAME } from './common/plugin-name';import { CalculateController } from './controllers/calculate.controller';import { FormulaController } from './controllers/formula.controller';-import { PromptController } from './controllers/prompt.controller';-import { enUS } from './locale';import { FormulaDataModel, IFormulaConfig } from './models/formula-data.model';-import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';-// TODO@Dushusir: user config IFunctionInfo, we will register all function info in formula engineexport class FormulaPlugin extends Plugin {static override type = PluginType.Sheet;- private _formulaController!: FormulaController;-constructor(private _config: IFormulaConfig,@Inject(Injector) override readonly _injector: Injector,- @Inject(LocaleService) private readonly _localeService: LocaleService,@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService) {super(FORMULA_PLUGIN_NAME);}initialize(): void {- this._localeService.load({- enUS,- });-const dependencies: Dependency[] = [// models[FormulaDataModel, { useFactory: () => this._injector.createInstance(FormulaDataModel, this._config) }],- // services- [IFormulaPromptService, { useClass: FormulaPromptService }],// controllers[FormulaController],- [PromptController],[CalculateController],];dependencies.forEach((dependency) => this._injector.add(dependency));}- override onStarting(_injector: Injector): void {}-- override onRendered(): void {}-override onReady(): void {this.initialize();}-- override onDestroy(): void {}}diff --git a/packages/ui-plugin-sheets/src/controllers/editor/editing.controller.ts b/packages/ui-plugin-sheets/src/controllers/editor/editing.controller.tsindex f5013a9db5..c43b649b25 100644--- a/packages/ui-plugin-sheets/src/controllers/editor/editing.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/editor/editing.controller.ts@@ -77,25 +77,21 @@ export class EditingController extends Disposable {9: {8: {f: '=sum(A1:C3)',- si: '',},},20: {8: {f: '=1+(3*4=4)*5+1',- si: '',},},22: {8: {f: '=1--1',- si: '',},},23: {8: {f: '=1--1%',- si: '',},},},diff --git a/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts b/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.tsindex c7662ce425..f8f9461566 100644--- a/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts+++ b/packages/ui-plugin-sheets/src/controllers/editor/end-edit.controller.ts@@ -20,6 +20,7 @@ import {ICommandInfo,ICommandService,IContextService,+ isFormulaString,IUniverInstanceService,LifecycleStages,Nullable,@@ -161,8 +162,12 @@ export class EndEditController extends Disposable {return;}- cellData.v = newDataStream;- cellData.m = newDataStream;+ if (isFormulaString(newDataStream)) {+ cellData.f = newDataStream;+ } else {+ cellData.v = newDataStream;+ cellData.m = newDataStream;+ }}this._commandService.executeCommand(SetRangeValuesCommand.id, {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 6e1f6d2273..0219f44983 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -246,6 +246,9 @@ importers:'@univerjs/sheets-plugin-formula':specifier: workspace:*version: link:../../packages/sheets-plugin-formula+ '@univerjs/sheets-plugin-formula-ui':+ specifier: workspace:*+ version: link:../../packages/sheets-plugin-formula-ui'@univerjs/sheets-plugin-import-xlsx':specifier: workspace:*version: link:../../packages/sheets-plugin-import-xlsx@@ -953,6 +956,21 @@ importers:version: 0.34.6([email protected])([email protected])packages/sheets-plugin-formula:+ dependencies:+ '@univerjs/base-formula-engine':+ specifier: workspace:*+ version: link:../base-formula-engine+ '@univerjs/base-sheets':+ specifier: workspace:*+ version: link:../base-sheets+ '@univerjs/core':+ specifier: workspace:*+ version: link:../core+ '@wendellhu/redi':+ specifier: ^0.12.11+ version: 0.12.11++ packages/sheets-plugin-formula-ui:dependencies:'@univerjs/base-docs':specifier: workspace:*@@ -976,8 +994,8 @@ importers:specifier: workspace:*version: link:../design'@univerjs/icons':- specifier: ^0.1.12- version: 0.1.12([email protected])([email protected])+ specifier: ^0.1.7+ version: 0.1.7([email protected])([email protected])'@univerjs/ui-plugin-sheets':specifier: workspace:*version: link:../ui-plugin-sheets@@ -5806,6 +5824,16 @@ packages:react-dom: 18.2.0([email protected])dev: false+ resolution: {integrity: sha512-jFzcqluGXPrNmbQ0GaB/aXrDtis+bV5igyWcYvx8/3ZIuwddQ0MVy//O4DulhV42Tc5XJMdRKeN41+iBHLiYXQ==}+ peerDependencies:+ react: '*'+ react-dom: '*'+ dependencies:+ react: 18.2.0+ react-dom: 18.2.0([email protected])+ dev: false+/@vitejs/[email protected]([email protected]):resolution: {integrity: sha512-AfgcRL8ZBhAlc3BFdigClmTUMISmmzHn7sB2h9U1odvc5U/MjWXsAaz18b/WoppUTDBzxOJwo2VdClfUcItu9g==}engines: {node: ^14.18.0 || >=16.0.0}