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.

feat(formula): register description (#458)

Dushusir3c624d330276
diff --git a/packages/base-formula-engine/src/basics/function.ts b/packages/base-formula-engine/src/basics/function.ts
index 1e82dd00b9..8ee85fd968 100644
--- a/packages/base-formula-engine/src/basics/function.ts
+++ b/packages/base-formula-engine/src/basics/function.ts
@@ -111,14 +111,6 @@ export interface IFunctionParam {
* false: not repeatable
*/
repeat: BooleanNumber;
-
- /**
- * Parameter types
- *
- * include ['range', 'rangeall', 'rangenumber', 'rangestring', 'rangedatetime', 'rangedate', 'string']
- * Detected before each calculation
- */
- type: string;
}
export interface IFunctionInfo {
@@ -147,12 +139,6 @@ export interface IFunctionInfo {
*/
abstract: string;
- /**
- * [Minimum number of parameters, maximum number of parameters]
- * Detected before each calculation of the function
- */
- parameterRange: [min: number, max: number];
-
/**
* Function params
*/
diff --git a/packages/base-formula-engine/src/services/formula-engine.service.ts b/packages/base-formula-engine/src/services/formula-engine.service.ts
index 6449c5dbec..95b9e202c0 100644
--- a/packages/base-formula-engine/src/services/formula-engine.service.ts
+++ b/packages/base-formula-engine/src/services/formula-engine.service.ts
@@ -17,7 +17,7 @@ import { UnionNodeFactory } from '../ast-node/union-node';
import { ValueNodeFactory } from '../ast-node/value-node';
import { IFormulaDatasetConfig } from '../basics/common';
import { ErrorType } from '../basics/error-type';
-import { FUNCTION_NAMES } from '../basics/function';
+import { FUNCTION_NAMES, IFunctionInfo } from '../basics/function';
import { FormulaDependencyGenerator } from '../dependency/formula-dependency';
import {
Average,
@@ -50,8 +50,7 @@ export class FormulaEngineService extends Disposable {
constructor(@Inject(Injector) private readonly _injector: Injector) {
super();
this._initializeDependencies();
-
- this.initializeFunctions();
+ this._initializeFunctions();
}
override dispose(): void {}
@@ -113,6 +112,13 @@ export class FormulaEngineService extends Disposable {
return this.functionService.getExecutor(functionName);
}
+ /**
+ * Use register to register function description
+ */
+ registerDescription(...descriptions: IFunctionInfo[]) {
+ this.functionService.registerDescriptions(...descriptions);
+ }
+
/**
* Obtain all function descriptions registered to the formulaEngineService.
* @returns
@@ -265,7 +271,7 @@ export class FormulaEngineService extends Disposable {
});
}
- private initializeFunctions() {
+ private _initializeFunctions() {
// new Sum(this._injector, FUNCTION_NAMES.SUM)
const functions: BaseFunction[] = [
// base function
diff --git a/packages/base-ui/src/views/components/doc-bars/Button/index.module.less b/packages/base-ui/src/views/components/doc-bars/Button/index.module.less
index 9ee16d9141..75eacb9590 100644
--- a/packages/base-ui/src/views/components/doc-bars/Button/index.module.less
+++ b/packages/base-ui/src/views/components/doc-bars/Button/index.module.less
@@ -21,7 +21,6 @@
&:not([disabled]):hover {
background-color: rgb(var(--grey-100));
- border-color: transparent;
}
&[disabled] {
@@ -30,8 +29,6 @@
}
&-active {
- color: rgb(var(--text-color));
background-color: rgb(var(--grey-100));
- border-color: transparent;
}
}
diff --git a/packages/base-ui/tsconfig.json b/packages/base-ui/tsconfig.json
index f35fde7a9a..25041d51bd 100644
--- a/packages/base-ui/tsconfig.json
+++ b/packages/base-ui/tsconfig.json
@@ -7,8 +7,5 @@
"esModuleInterop": true,
"strictPropertyInitialization": false,
},
- "include": [
- "src/**/*",
- "test/**/*.test.(ts|tsx|js)"
- ]
+ "include": ["src/**/*"]
}
diff --git a/packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.ts
index c550d7251b..83e9f9e1a7 100644
--- a/packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.ts
+++ b/packages/sheets-plugin-formula-ui/src/commands/operations/editor-formula.operation.ts
@@ -3,6 +3,7 @@
import { DeviceInputEventType } from '@univerjs/base-render';
import { KeyCode } from '@univerjs/base-ui';
import { CommandType, Direction, IOperation } from '@univerjs/core';
+import { IEditorBridgeService } from '@univerjs/ui-plugin-sheets';
import { IFormulaPromptService } from '../../services/prompt.service';
@@ -11,12 +12,13 @@ export interface ISelectEditorFormulaOperationParam {
keycode?: KeyCode;
}
-export const SelectEditorFormluaOperation: IOperation<ISelectEditorFormulaOperationParam> = {
- id: 'formula.operation.select-editor-formula',
+export const SelectEditorFormulaOperation: IOperation<ISelectEditorFormulaOperationParam> = {
+ id: 'formula-ui.operation.select-editor-formula',
type: CommandType.OPERATION,
handler: (accessor, params) => {
- const { keycode } = params;
+ const { eventType, keycode } = params;
const formulaPromptService = accessor.get(IFormulaPromptService);
+ const editorBridgeService = accessor.get(IEditorBridgeService);
switch (keycode) {
case KeyCode.ARROW_DOWN:
@@ -27,7 +29,17 @@ export const SelectEditorFormluaOperation: IOperation<ISelectEditorFormulaOperat
break;
case KeyCode.ENTER:
case KeyCode.TAB:
- formulaPromptService.accept(true);
+ if (formulaPromptService.isSearching()) {
+ formulaPromptService.accept(true);
+ } else {
+ const editorBridgeParameters = {
+ visible: false,
+ eventType,
+ keycode,
+ };
+
+ editorBridgeService.changeVisible(editorBridgeParameters);
+ }
break;
default:
break;
diff --git a/packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.ts
index a1c15e84f2..4621195c9b 100644
--- a/packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.ts
+++ b/packages/sheets-plugin-formula-ui/src/commands/operations/help-function.operation.ts
@@ -4,7 +4,7 @@ import { IAccessor } from '@wendellhu/redi';
import { IFormulaPromptService, IHelpFunctionCommandParams } from '../../services/prompt.service';
export const HelpFunctionOperation: ICommand = {
- id: 'formula.operation.help-function',
+ id: 'formula-ui.operation.help-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: IHelpFunctionCommandParams) => {
const promptService = accessor.get(IFormulaPromptService);
diff --git a/packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.ts
index 516c04fb29..2bd9000269 100644
--- a/packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.ts
+++ b/packages/sheets-plugin-formula-ui/src/commands/operations/insert-function.operation.ts
@@ -9,7 +9,7 @@ export interface IInsertFunctionCommandParams {
}
export const InsertFunctionOperation: ICommand = {
- id: 'formula.operation.insert-function',
+ id: 'formula-ui.operation.insert-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: IInsertFunctionCommandParams) => true,
};
diff --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.ts
index fd96d08a80..388bf47bcb 100644
--- 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.ts
@@ -5,7 +5,7 @@ import { IAccessor } from '@wendellhu/redi';
import { MORE_FUNCTIONS_COMPONENT } from '../../views/more-functions/interface';
export const MoreFunctionsOperation: ICommand = {
- id: 'formula.operation.more-functions',
+ id: 'formula-ui.operation.more-functions',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor) => {
const sidebarService = accessor.get(ISidebarService);
diff --git a/packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.ts b/packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.ts
index e289eae66d..0915b76ad3 100644
--- a/packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.ts
+++ b/packages/sheets-plugin-formula-ui/src/commands/operations/search-function.operation.ts
@@ -4,7 +4,7 @@ import { IAccessor } from '@wendellhu/redi';
import { IFormulaPromptService, ISearchFunctionParams } from '../../services/prompt.service';
export const SearchFunctionOperation: ICommand = {
- id: 'formula.operation.search-function',
+ id: 'formula-ui.operation.search-function',
type: CommandType.OPERATION,
handler: async (accessor: IAccessor, params: ISearchFunctionParams) => {
const promptService = accessor.get(IFormulaPromptService);
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.ts
index 99233ed499..94ba4b0c5d 100644
--- a/packages/sheets-plugin-formula-ui/src/controllers/formula-ui.controller.ts
+++ b/packages/sheets-plugin-formula-ui/src/controllers/formula-ui.controller.ts
@@ -9,7 +9,7 @@ import { Disposable, ICommandService, LifecycleStages, OnLifecycle } from '@univ
import { Inject, Injector } from '@wendellhu/redi';
import { connectInjector } from '@wendellhu/redi/react-bindings';
-import { SelectEditorFormluaOperation } from '../commands/operations/editor-formula.operation';
+import { SelectEditorFormulaOperation } 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';
@@ -54,7 +54,7 @@ export class FormulaUIController extends Disposable {
MoreFunctionsOperation,
SearchFunctionOperation,
HelpFunctionOperation,
- SelectEditorFormluaOperation,
+ SelectEditorFormulaOperation,
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
}
diff --git a/packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.ts b/packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.ts
index 9badc7a0b7..764e00de54 100644
--- a/packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.ts
+++ b/packages/sheets-plugin-formula-ui/src/controllers/prompt.controller.ts
@@ -1,9 +1,9 @@
-import { TextSelectionManagerService } from '@univerjs/base-docs';
import { FormulaEngineService, IFunctionInfo, ISequenceNode, sequenceNodeType } from '@univerjs/base-formula-engine';
import {
DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
IRenderManagerService,
+ ITextSelectionRenderManager,
} from '@univerjs/base-render';
import { ISelectionWithStyle, NORMAL_SELECTION_PLUGIN_NAME, SelectionManagerService } from '@univerjs/base-sheets';
import {
@@ -36,9 +36,8 @@ import { Inject } from '@wendellhu/redi';
import { HelpFunctionOperation } from '../commands/operations/help-function.operation';
import { SearchFunctionOperation } from '../commands/operations/search-function.operation';
import { FORMULA_REF_SELECTION_PLUGIN_NAME, getFormulaRefSelectionStyle } from '../common/selection';
-import { FUNCTION_LIST } from '../services/function-list';
-import { IFormulaPromptService, ISearchItem } from '../services/prompt.service';
-import { getFunctionName } from './util';
+import { IDescriptionService, ISearchItem } from '../services/description.service';
+import { IFormulaPromptService } from '../services/prompt.service';
interface IFunctionPanelParam {
visibleSearch: boolean;
@@ -69,7 +68,7 @@ export class PromptController extends Disposable {
@ICommandService private readonly _commandService: ICommandService,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@IContextService private readonly _contextService: IContextService,
- @Inject(TextSelectionManagerService) private readonly _textSelectionManagerService: TextSelectionManagerService,
+ @ITextSelectionRenderManager private readonly _textSelectionRenderManager: ITextSelectionRenderManager,
@Inject(IEditorBridgeService) private readonly _editorBridgeService: EditorBridgeService,
@Inject(IFormulaPromptService) private readonly _formulaPromptService: IFormulaPromptService,
@Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,
@@ -78,7 +77,8 @@ export class PromptController extends Disposable {
@Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
@Inject(SheetSkeletonManagerService) private readonly _sheetSkeletonManagerService: SheetSkeletonManagerService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService,
- @Inject(ISelectionRenderService) private readonly _selectionRenderService: ISelectionRenderService
+ @Inject(ISelectionRenderService) private readonly _selectionRenderService: ISelectionRenderService,
+ @Inject(IDescriptionService) private readonly _descriptionService: IDescriptionService
) {
super();
@@ -126,7 +126,7 @@ export class PromptController extends Disposable {
private _initialCursorSync() {
this.disposeWithMe(
toDisposable(
- this._textSelectionManagerService.textSelectionInfo$.subscribe(() => {
+ this._textSelectionRenderManager.textSelection$.subscribe(() => {
if (this._editorBridgeService.isVisible().visible === false) {
return;
}
@@ -194,14 +194,13 @@ export class PromptController extends Disposable {
const searchText = currentInputValue.substring(1);
// TODO@Dushusir: remove after use real text info
- const matchList = ['SUMIF', 'TAN', 'TANH'];
+ const matchList = ['SUM', 'AVERAGE'];
// help function
if (matchList.includes(searchText)) {
const paramIndex = Math.random() > 0.5 ? 0 : 1;
- const functionInfo = this._getFunctionInfo(searchText);
-
+ const functionInfo = this._descriptionService.getFunctionInfo(searchText);
param = {
visibleSearch: false,
visibleHelp: !!functionInfo,
@@ -209,16 +208,16 @@ export class PromptController extends Disposable {
paramIndex,
functionInfo,
};
+ } else {
+ const searchList = this._descriptionService.getSearchListByName(searchText);
+ param = {
+ visibleSearch: searchList.length > 0,
+ visibleHelp: false,
+ searchText,
+ paramIndex: 0,
+ searchList,
+ };
}
-
- const searchList = this._getSearchList(searchText);
- param = {
- visibleSearch: searchList.length > 0,
- visibleHelp: false,
- searchText,
- paramIndex: 0,
- searchList,
- };
}
this._commandService.executeCommand(SearchFunctionOperation.id, {
@@ -239,22 +238,6 @@ export class PromptController extends Disposable {
});
}
- private _getSearchList(searchText: string) {
- const searchList: ISearchItem[] = [];
- FUNCTION_LIST.forEach((item) => {
- const functionName = getFunctionName(item, this._localeService);
- if (functionName.indexOf(searchText) > -1) {
- searchList.push({ name: functionName, desc: this._localeService.t(item.abstract) as string });
- }
- });
-
- return searchList;
- }
-
- private _getFunctionInfo(searchText: string) {
- return FUNCTION_LIST.find((item) => getFunctionName(item, this._localeService) === searchText);
- }
-
/**
*
* @param body the body object of the current input box
diff --git a/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.ts b/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.ts
index 53c49c06da..cf261f9abb 100644
--- a/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.ts
+++ b/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.ts
@@ -2,7 +2,7 @@ import { DeviceInputEventType } from '@univerjs/base-render';
import { IShortcutItem, KeyCode } from '@univerjs/base-ui';
import { whenEditorInputFormulaActivated } from '@univerjs/ui-plugin-sheets';
-import { SelectEditorFormluaOperation } from '../../commands/operations/editor-formula.operation';
+import { SelectEditorFormulaOperation } from '../../commands/operations/editor-formula.operation';
export const PROMPT_SELECTION_KEYCODE_LIST = [
KeyCode.ARROW_DOWN,
@@ -17,7 +17,7 @@ export function promptSelectionShortcutItem() {
const shortcutList: IShortcutItem[] = [];
for (const keycode of PROMPT_SELECTION_KEYCODE_LIST) {
shortcutList.push({
- id: SelectEditorFormluaOperation.id,
+ id: SelectEditorFormulaOperation.id,
binding: keycode,
preconditions: (contextService) => whenEditorInputFormulaActivated(contextService),
staticParameters: {
diff --git a/packages/sheets-plugin-formula-ui/src/controllers/util.ts b/packages/sheets-plugin-formula-ui/src/controllers/util.ts
deleted file mode 100644
index 0be660aa38..0000000000
--- a/packages/sheets-plugin-formula-ui/src/controllers/util.ts
+++ /dev/null
@@ -1,18 +0,0 @@
-import { IFunctionInfo } from '@univerjs/base-formula-engine';
-import { LocaleService } from '@univerjs/core';
-
-// TODO@Dushusir: merged to service/utils
-export function getFunctionName(item: IFunctionInfo, localeService: LocaleService) {
- let functionName = '';
- if (item.aliasFunctionName) {
- functionName = localeService.t(item.aliasFunctionName) as string;
-
- if (functionName === item.aliasFunctionName) {
- functionName = item.functionName;
- }
- } else {
- functionName = item.functionName;
- }
-
- return functionName;
-}
diff --git a/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts b/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts
index 18dc1b847a..91e9c33b79 100644
--- a/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts
+++ b/packages/sheets-plugin-formula-ui/src/formula-ui-plugin.ts
@@ -1,3 +1,4 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
import { IUniverInstanceService, LocaleService, Plugin, PluginType } from '@univerjs/core';
import { Dependency, Inject, Injector } from '@wendellhu/redi';
@@ -5,14 +6,18 @@ 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 { DescriptionService, IDescriptionService } from './services/description.service';
import { FormulaPromptService, IFormulaPromptService } from './services/prompt.service';
// TODO@Dushusir: user config IFunctionInfo, we will register all function info in formula engine
+interface IFormulaUIConfig {
+ description: IFunctionInfo[];
+}
export class FormulaUIPlugin extends Plugin {
static override type = PluginType.Sheet;
constructor(
- private _config: undefined,
+ private _config: Partial<IFormulaUIConfig>,
@Inject(Injector) override readonly _injector: Injector,
@Inject(LocaleService) private readonly _localeService: LocaleService,
@IUniverInstanceService private readonly _currentUniverService: IUniverInstanceService
@@ -25,9 +30,12 @@ export class FormulaUIPlugin extends Plugin {
enUS,
});
+ const descriptionService = this._injector.createInstance(DescriptionService, this._config?.description || []);
+
const dependencies: Dependency[] = [
// services
[IFormulaPromptService, { useClass: FormulaPromptService }],
+ [IDescriptionService, { useValue: descriptionService }],
// controllers
[FormulaUIController],
[PromptController],
diff --git a/packages/sheets-plugin-formula-ui/src/locale/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/en-US.ts
index 545cb19dc4..82ce080f79 100644
--- a/packages/sheets-plugin-formula-ui/src/locale/en-US.ts
+++ b/packages/sheets-plugin-formula-ui/src/locale/en-US.ts
@@ -1,3 +1,19 @@
+import arrayEnUS from './function-list/array/en-US';
+import compatibilityEnUS from './function-list/compatibility/en-US';
+import cubeEnUS from './function-list/cube/en-US';
+import databaseEnUS from './function-list/database/en-US';
+import dateEnUS from './function-list/date/en-US';
+import engineeringEnUS from './function-list/engineering/en-US';
+import financialEnUS from './function-list/financial/en-US';
+import informationEnUS from './function-list/information/en-US';
+import logicalEnUS from './function-list/logical/en-US';
+import lookupEnUS from './function-list/lookup/en-US';
+import mathEnUS from './function-list/math/en-US';
+import statisticalEnUS from './function-list/statistical/en-US';
+import textEnUS from './function-list/text/en-US';
+import univerEnUS from './function-list/univer/en-US';
+import webEnUS from './function-list/web/en-US';
+
export default {
formula: {
insert: {
@@ -10,49 +26,29 @@ export default {
more: 'More Functions...',
},
functionList: {
- SUMIF: {
- description: 'Returns a conditional sum across a range.',
- abstract: 'A conditional sum across a range.',
- functionParameter: {
- range: {
- name: 'range',
- detail: 'The range which is tested against `criterion`.',
- },
- criterion: {
- name: 'criterion',
- detail: 'The pattern or test to apply to `range`.',
- },
- sum_range: {
- name: 'sum_range',
- detail: 'The range to be summed, if different from `range`.',
- },
- },
- },
- TAN: {
- description: 'Returns the tangent of an angle provided in radians.',
- abstract: 'Tangent of an angle provided in radians.',
- functionParameter: {
- angle: {
- name: 'angle',
- detail: 'The angle to find the tangent of, in radians.',
- },
- },
- },
- // TANH: {
- // description: 'Returns the hyperbolic tangent of any real number.',
- // abstract: 'Hyperbolic tangent of any real number.',
- // functionParameter: {
- // value: {
- // name: 'value',
- // detail: 'Any real value to calculate the hyperbolic tangent of.',
- // },
- // },
- // },
+ ...financialEnUS,
+ ...dateEnUS,
+ ...mathEnUS,
+ ...statisticalEnUS,
+ ...lookupEnUS,
+ ...databaseEnUS,
+ ...textEnUS,
+ ...logicalEnUS,
+ ...informationEnUS,
+ ...engineeringEnUS,
+ ...cubeEnUS,
+ ...compatibilityEnUS,
+ ...webEnUS,
+ ...arrayEnUS,
+ ...univerEnUS,
},
- formulaMore: {
+ prompt: {
helpExample: 'EXAMPLE',
helpAbstract: 'ABOUT',
-
+ required: 'Required.',
+ optional: 'Optional.',
+ },
+ functionType: {
financial: 'Financial',
date: 'Date & Time',
math: 'Math & Trig',
@@ -68,13 +64,14 @@ export default {
web: 'Web',
array: 'Array',
univer: 'Univer',
-
- searchFunctionPlaceholder: 'Search function',
},
moreFunctions: {
confirm: 'Confirm',
prev: 'Previous',
next: 'Next',
+ searchFunctionPlaceholder: 'Search function',
+ allFunctions: 'All Functions',
+ syntax: 'SYNTAX',
},
},
};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/array/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/array/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/array/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/array/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/array/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/array/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/compatibility/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/cube/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/database/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/database/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/database/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/database/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/database/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/database/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/date/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/date/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/date/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/date/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/date/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/date/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/engineering/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/financial/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/information/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/information/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/information/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/information/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/information/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/information/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/logical/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/lookup/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/math/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/math/en-US.ts
new file mode 100644
index 0000000000..53c8e2db7d
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/math/en-US.ts
@@ -0,0 +1,16 @@
+export default {
+ SUM: {
+ description: 'You can add individual values, cell references or ranges or a mix of all three.',
+ abstract: 'Adds its arguments',
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number you want to add. The number can be like 4, a cell reference like B6, or a cell range like B2:B8.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'This is the second number you want to add. You can specify up to 255 numbers in this way.',
+ },
+ },
+ },
+};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/math/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/math/zh-CN.ts
new file mode 100644
index 0000000000..a8a8735cb0
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/math/zh-CN.ts
@@ -0,0 +1,16 @@
+export default {
+ SUM: {
+ description: '将单个值、单元格引用或是区域相加,或者将三者的组合相加。',
+ abstract: '求参数的和',
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要相加的第一个数字。 该数字可以是 4 之类的数字,B6 之类的单元格引用或 B2:B8 之类的单元格范围。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '这是要相加的第二个数字。 可以按照这种方式最多指定 255 个数字。',
+ },
+ },
+ },
+};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/en-US.ts
new file mode 100644
index 0000000000..183926d97a
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/en-US.ts
@@ -0,0 +1,59 @@
+export default {
+ AVERAGE: {
+ description: 'Returns the average (arithmetic mean) of the arguments.',
+ abstract: 'Returns the average of its arguments',
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number, cell reference, or range for which you want the average.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'Additional numbers, cell references or ranges for which you want the average, up to a maximum of 255.',
+ },
+ },
+ },
+ COUNT: {
+ description:
+ 'Counts the number of cells that contain numbers, and counts numbers within the list of arguments.',
+ abstract: 'Counts how many numbers are in the list of arguments',
+ functionParameter: {
+ value1: {
+ name: 'value1',
+ detail: 'The first item, cell reference, or range within which you want to count numbers.',
+ },
+ value2: {
+ name: 'value2',
+ detail: 'Up to 255 additional items, cell references, or ranges within which you want to count numbers.',
+ },
+ },
+ },
+ MAX: {
+ description: 'Returns the largest value in a set of values.',
+ abstract: 'Returns the maximum value in a list of arguments',
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number, cell reference, or range to calculate the maximum value from.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'Additional numbers, cell references or ranges to calculate the maximum value from, up to a maximum of 255.',
+ },
+ },
+ },
+ MIN: {
+ description: 'Returns the smallest number in a set of values.',
+ abstract: 'Returns the minimum value in a list of arguments',
+ functionParameter: {
+ number1: {
+ name: 'number1',
+ detail: 'The first number, cell reference, or range to calculate the minimum value from.',
+ },
+ number2: {
+ name: 'number2',
+ detail: 'Additional numbers, cell references or ranges to calculate the minimum value from, up to a maximum of 255.',
+ },
+ },
+ },
+};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/zh-CN.ts
new file mode 100644
index 0000000000..6660f0f3bb
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/statistical/zh-CN.ts
@@ -0,0 +1,58 @@
+export default {
+ AVERAGE: {
+ description: '返回参数的平均值(算术平均值)。',
+ abstract: '返回参数平均值',
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要计算平均值的第一个数字、单元格引用或单元格区域。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '要计算平均值的其他数字、单元格引用或单元格区域,最多可包含 255 个。',
+ },
+ },
+ },
+ COUNT: {
+ description: '计算包含数字的单元格个数以及参数列表中数字的个数。',
+ abstract: '计算参数列表中数字的个数',
+ functionParameter: {
+ value1: {
+ name: '值1',
+ detail: '要计算其中数字的个数的第一项、单元格引用或区域。',
+ },
+ value2: {
+ name: '值2',
+ detail: '要计算其中数字的个数的其他项、单元格引用或区域,最多可包含 255 个。',
+ },
+ },
+ },
+ MAX: {
+ description: '返回一组值中的最大值。',
+ abstract: '返回参数列表中的最大值',
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要计算最大值的第一个数字、单元格引用或单元格区域。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '要计算最大值的其他数字、单元格引用或单元格区域,最多可包含 255 个。',
+ },
+ },
+ },
+ MIN: {
+ description: '返回一组值中的最小值。',
+ abstract: '返回参数列表中的最小值',
+ functionParameter: {
+ number1: {
+ name: '数值1',
+ detail: '要计算最小值的第一个数字、单元格引用或单元格区域。',
+ },
+ number2: {
+ name: '数值2',
+ detail: '要计算最小值的其他数字、单元格引用或单元格区域,最多可包含 255 个。',
+ },
+ },
+ },
+};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/text/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/text/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/text/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/text/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/text/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/text/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/univer/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/web/en-US.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/web/en-US.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/web/en-US.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/function-list/web/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/function-list/web/zh-CN.ts
new file mode 100644
index 0000000000..ff8b4c5632
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/locale/function-list/web/zh-CN.ts
@@ -0,0 +1 @@
+export default {};
diff --git a/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
index cf383d4427..1c0b3a8419 100644
--- a/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
+++ b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
@@ -1,3 +1,19 @@
+import arrayZhCN from './function-list/array/zh-CN';
+import compatibilityZhCN from './function-list/compatibility/zh-CN';
+import cubeZhCN from './function-list/cube/zh-CN';
+import databaseZhCN from './function-list/database/zh-CN';
+import dateZhCN from './function-list/date/zh-CN';
+import engineeringZhCN from './function-list/engineering/zh-CN';
+import financialZhCN from './function-list/financial/zh-CN';
+import informationZhCN from './function-list/information/zh-CN';
+import logicalZhCN from './function-list/logical/zh-CN';
+import lookupZhCN from './function-list/lookup/zh-CN';
+import mathZhCN from './function-list/math/zh-CN';
+import statisticalZhCN from './function-list/statistical/zh-CN';
+import textZhCN from './function-list/text/zh-CN';
+import univerZhCN from './function-list/univer/zh-CN';
+import webZhCN from './function-list/web/zh-CN';
+
export default {
formula: {
insert: {
@@ -9,52 +25,32 @@ export default {
min: '最小值',
more: '更多函数...',
},
-
functionList: {
- SUMIF: {
- description: '对范围中符合指定条件的值求和。',
- abstract: '对范围中符合指定条件的值求和。',
- functionParameter: {
- range: {
- name: '范围',
- detail: '要根据条件进行检测的范围。',
- },
- criterion: {
- name: '条件',
- detail: '要应用于范围的模式或测试条件。\n\n如果范围包含的是要检测的文本,则条件必须为字符串。条件可以包含通配符,包括用于匹配单个字符的?或用于匹配零个或连续多个字符的*。要匹配问号星号本身,请在该字符前面加上波浪号(~)前缀(即~?和~*)。字符串条件必须用引号括起来。函数会检查范围中的每个单元格与条件是否相等或匹配(如果使用了通配符)。\n\n如果范围包含的是要检测的数字,则条件可以是字符串也可以是数字。如果给定的条件是一个数字,则检查范围中的每个单元格是否等于条件。另外,条件也可能是包含数字的字符串(也将对其进行相等检测),或者带有以下前缀的数字:=(检查是否相等)、>(检查范围单元格的值是否大于条件值)或<(检查范围单元格的值是否小于条件值)',
- },
- sum_range: {
- name: '求和范围',
- detail: '要求和的范围(如果与范围不同)。',
- },
- },
- },
- TAN: {
- description: '返回已知角度的正切值。',
- abstract: '返回已知角度的正切值。',
- functionParameter: {
- angle: {
- name: '角度',
- detail: '要求其正切值的角度,以弧度表示。',
- },
- },
- },
- // TANH: {
- // description: '返回给定实数的双曲正切值。',
- // abstract: '返回给定实数的双曲正切值。',
- // functionParameter: {
- // value: {
- // name: '值',
- // detail: '要计算其双曲正切值的实数。',
- // },
- // },
- // },
+ ...financialZhCN,
+ ...dateZhCN,
+ ...mathZhCN,
+ ...statisticalZhCN,
+ ...lookupZhCN,
+ ...databaseZhCN,
+ ...textZhCN,
+ ...logicalZhCN,
+ ...informationZhCN,
+ ...engineeringZhCN,
+ ...cubeZhCN,
+ ...compatibilityZhCN,
+ ...webZhCN,
+ ...arrayZhCN,
+ ...univerZhCN,
},
- formulaMore: {
+ prompt: {
helpExample: '示例',
helpAbstract: '简介',
+ required: '必需。',
+ optional: '可选。',
+ },
+ functionType: {
financial: '财务',
date: '日期与时间',
math: '数学与三角函数',
@@ -70,14 +66,15 @@ export default {
web: 'Web',
array: '数组',
univer: 'Univer',
-
- searchFunctionPlaceholder: '搜索函数',
},
moreFunctions: {
- confirm: '确定',
+ confirm: '应用',
prev: '上一步',
next: '下一步',
+ searchFunctionPlaceholder: '搜索函数',
+ allFunctions: '全部函数',
+ syntax: '语法',
},
},
};
diff --git a/packages/sheets-plugin-formula-ui/src/services/description.service.ts b/packages/sheets-plugin-formula-ui/src/services/description.service.ts
new file mode 100644
index 0000000000..29c180cf86
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/description.service.ts
@@ -0,0 +1,116 @@
+import { FormulaEngineService, IFunctionInfo } from '@univerjs/base-formula-engine';
+import { LocaleService } from '@univerjs/core';
+import { createIdentifier, IDisposable, Inject } from '@wendellhu/redi';
+
+import { FUNCTION_LIST } from './function-list/function-list';
+import { getFunctionName } from './utils';
+
+export interface ISearchItem {
+ name: string;
+ desc: string;
+}
+
+export interface IDescriptionService {
+ /**
+ * get all descriptions
+ */
+ getDescriptions(): Map<string, IFunctionInfo>;
+
+ /**
+ * get function info by name
+ * @param searchText
+ */
+ getFunctionInfo(searchText: string): IFunctionInfo | undefined;
+
+ /**
+ * get search list by name
+ * @param searchText
+ * @returns
+ */
+ getSearchListByName(searchText: string): ISearchItem[];
+
+ /**
+ * get search list by type, if type is -1, return all
+ * @param type
+ * @returns
+ */
+ getSearchListByType(type: number): ISearchItem[];
+}
+
+export const IDescriptionService = createIdentifier<IDescriptionService>('formula-ui.description-service');
+
+export class DescriptionService implements IDescriptionService, IDisposable {
+ constructor(
+ private _description: IFunctionInfo[],
+ @Inject(FormulaEngineService) private readonly _formulaEngineService: FormulaEngineService,
+ @Inject(LocaleService) private readonly _localeService: LocaleService
+ ) {
+ this._initialize();
+ this._registerDescription();
+ }
+
+ dispose(): void {
+ this._localeService.localeChanged$.complete();
+ }
+
+ getDescriptions() {
+ return this._formulaEngineService.getDescriptions();
+ }
+
+ getFunctionInfo(searchText: string) {
+ const functionList = this._formulaEngineService.getDescriptions();
+ return functionList.get(searchText.toLocaleUpperCase());
+ }
+
+ getSearchListByName(searchText: string) {
+ const searchList: ISearchItem[] = [];
+ const functionList = this._formulaEngineService.getDescriptions();
+ searchText = searchText.toLocaleUpperCase();
+ functionList.forEach((item) => {
+ const { functionName, abstract } = item;
+ if (functionName.indexOf(searchText) > -1) {
+ searchList.push({ name: functionName, desc: abstract });
+ }
+ });
+
+ return searchList;
+ }
+
+ getSearchListByType(type: number) {
+ const searchList: ISearchItem[] = [];
+ const functionList = this._formulaEngineService.getDescriptions();
+ functionList.forEach((item) => {
+ const { functionName, functionType, abstract } = item;
+ if (functionType === type || type === -1) {
+ searchList.push({ name: functionName, desc: abstract });
+ }
+ });
+
+ return searchList;
+ }
+
+ private _initialize() {
+ this._localeService.localeChanged$.subscribe(() => {
+ this._registerDescription();
+ });
+ }
+
+ private _registerDescription() {
+ const localeService = this._localeService;
+ const functionList = FUNCTION_LIST.concat(this._description || []);
+ const functionListLocale = functionList.map((functionInfo) => ({
+ functionName: getFunctionName(functionInfo, localeService),
+ functionType: functionInfo.functionType,
+ description: localeService.t(functionInfo.description),
+ abstract: localeService.t(functionInfo.abstract),
+ functionParameter: functionInfo.functionParameter.map((item) => ({
+ name: localeService.t(item.name),
+ detail: localeService.t(item.detail),
+ example: item.example,
+ require: item.require,
+ repeat: item.repeat,
+ })),
+ }));
+ this._formulaEngineService.registerDescription(...functionListLocale);
+ }
+}
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list.ts b/packages/sheets-plugin-formula-ui/src/services/function-list.ts
deleted file mode 100644
index fd6c2c8f80..0000000000
--- a/packages/sheets-plugin-formula-ui/src/services/function-list.ts
+++ /dev/null
@@ -1,79 +0,0 @@
-import { IFunctionInfo } from '@univerjs/base-formula-engine';
-
-// TODO@Dushusir: register custom function
-// TODO@Dushusir: register custom locale file
-export interface IFunctionDescription {
- [functionName: string]: IFunctionInfo;
-}
-
-export const FUNCTION_LIST: IFunctionInfo[] = [
- {
- functionName: 'SUMIF',
- aliasFunctionName: 'formula.functionList.SUMIF.aliasFunctionName',
- functionType: 0,
- description: 'formula.functionList.SUMIF.description',
- abstract: 'formula.functionList.SUMIF.abstract',
- parameterRange: [2, 3],
- functionParameter: [
- {
- name: 'formula.functionList.SUMIF.functionParameter.range.name',
- detail: 'formula.functionList.SUMIF.functionParameter.range.detail',
- example: 'A1:A10',
- require: 1,
- repeat: 0,
- type: 'range',
- },
- {
- name: 'formula.functionList.SUMIF.functionParameter.criterion.name',
- detail: 'formula.functionList.SUMIF.functionParameter.criterion.detail',
- example: '">20"',
- require: 1,
- repeat: 0,
- type: 'rangeall',
- },
- {
- name: 'formula.functionList.SUMIF.functionParameter.sum_range.name',
- detail: 'formula.functionList.SUMIF.functionParameter.sum_range.detail',
- example: 'B1:B10',
- require: 0,
- repeat: 0,
- type: 'range',
- },
- ],
- },
- {
- functionName: 'TAN',
- aliasFunctionName: 'formula.functionList.TAN.aliasFunctionName',
- functionType: 0,
- description: 'formula.functionList.TAN.description',
- abstract: 'formula.functionList.TAN.abstract',
- parameterRange: [1, 1],
- functionParameter: [
- {
- name: 'formula.functionList.TAN.functionParameter.angle.name',
- detail: 'formula.functionList.TAN.functionParameter.angle.detail',
- example: '45*PI()/180',
- require: 1,
- repeat: 0,
- type: 'rangenumber',
- },
- ],
- },
- {
- functionName: 'TANH',
- functionType: 0,
- description: 'formula.functionList.TANH.description',
- abstract: 'formula.functionList.TANH.abstract',
- parameterRange: [1, 1],
- functionParameter: [
- {
- name: 'formula.functionList.TANH.functionParameter.value.name',
- detail: 'formula.functionList.TANH.functionParameter.value.detail',
- example: 'A2',
- require: 1,
- repeat: 0,
- type: 'rangenumber',
- },
- ],
- },
-];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/array.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/array.ts
new file mode 100644
index 0000000000..b49b9b30df
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/array.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_ARRAY: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/compatibility.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/compatibility.ts
new file mode 100644
index 0000000000..9d734e9bb1
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/compatibility.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_COMPATIBILITY: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/cube.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/cube.ts
new file mode 100644
index 0000000000..beb80e92e0
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/cube.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_CUBE: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/database.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/database.ts
new file mode 100644
index 0000000000..33dde5d26e
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/database.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_DATABASE: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/date.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/date.ts
new file mode 100644
index 0000000000..d5d005074b
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/date.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_DATE: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/engineering.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/engineering.ts
new file mode 100644
index 0000000000..7ea6a9b0c7
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/engineering.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_ENGINEERING: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/financial.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/financial.ts
new file mode 100644
index 0000000000..1c3e878c0d
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/financial.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_FINANCIAL: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/function-list.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/function-list.ts
new file mode 100644
index 0000000000..270d171165
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/function-list.ts
@@ -0,0 +1,35 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+import { FUNCTION_LIST_ARRAY } from './array';
+import { FUNCTION_LIST_COMPATIBILITY } from './compatibility';
+import { FUNCTION_LIST_CUBE } from './cube';
+import { FUNCTION_LIST_DATABASE } from './database';
+import { FUNCTION_LIST_DATE } from './date';
+import { FUNCTION_LIST_ENGINEERING } from './engineering';
+import { FUNCTION_LIST_FINANCIAL } from './financial';
+import { FUNCTION_LIST_INFORMATION } from './information';
+import { FUNCTION_LIST_LOGICAL } from './logical';
+import { FUNCTION_LIST_LOOKUP } from './lookup';
+import { FUNCTION_LIST_MATH } from './math';
+import { FUNCTION_LIST_STATISTICAL } from './statistical';
+import { FUNCTION_LIST_TEXT } from './text';
+import { FUNCTION_LIST_UNIVER } from './univer';
+import { FUNCTION_LIST_WEB } from './web';
+
+export const FUNCTION_LIST: IFunctionInfo[] = [
+ ...FUNCTION_LIST_FINANCIAL,
+ ...FUNCTION_LIST_DATE,
+ ...FUNCTION_LIST_MATH,
+ ...FUNCTION_LIST_STATISTICAL,
+ ...FUNCTION_LIST_LOOKUP,
+ ...FUNCTION_LIST_DATABASE,
+ ...FUNCTION_LIST_TEXT,
+ ...FUNCTION_LIST_LOGICAL,
+ ...FUNCTION_LIST_INFORMATION,
+ ...FUNCTION_LIST_ENGINEERING,
+ ...FUNCTION_LIST_CUBE,
+ ...FUNCTION_LIST_COMPATIBILITY,
+ ...FUNCTION_LIST_WEB,
+ ...FUNCTION_LIST_ARRAY,
+ ...FUNCTION_LIST_UNIVER,
+];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/information.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/information.ts
new file mode 100644
index 0000000000..a07e5cf3e4
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/information.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_INFORMATION: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/logical.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/logical.ts
new file mode 100644
index 0000000000..5b5a5672be
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/logical.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_LOGICAL: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/lookup.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/lookup.ts
new file mode 100644
index 0000000000..6287b1647d
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/lookup.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_LOOKUP: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/math.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/math.ts
new file mode 100644
index 0000000000..c9ea410f04
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/math.ts
@@ -0,0 +1,27 @@
+import { FUNCTION_NAMES, FunctionType, IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_MATH: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES.SUM,
+ aliasFunctionName: 'formula.functionList.SUM.aliasFunctionName',
+ functionType: FunctionType.Math,
+ description: 'formula.functionList.SUM.description',
+ abstract: 'formula.functionList.SUM.abstract',
+ functionParameter: [
+ {
+ name: 'formula.functionList.SUM.functionParameter.number1.name',
+ detail: 'formula.functionList.SUM.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.SUM.functionParameter.number2.name',
+ detail: 'formula.functionList.SUM.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/statistical.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/statistical.ts
new file mode 100644
index 0000000000..37d3e91cd9
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/statistical.ts
@@ -0,0 +1,96 @@
+import { FUNCTION_NAMES, FunctionType, IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_STATISTICAL: IFunctionInfo[] = [
+ {
+ functionName: FUNCTION_NAMES.AVERAGE,
+ aliasFunctionName: 'formula.functionList.AVERAGE.aliasFunctionName',
+ functionType: FunctionType.Statistical,
+ description: 'formula.functionList.AVERAGE.description',
+ abstract: 'formula.functionList.AVERAGE.abstract',
+ functionParameter: [
+ {
+ name: 'formula.functionList.AVERAGE.functionParameter.number1.name',
+ detail: 'formula.functionList.AVERAGE.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.AVERAGE.functionParameter.number2.name',
+ detail: 'formula.functionList.AVERAGE.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ {
+ functionName: FUNCTION_NAMES.MAX,
+ aliasFunctionName: 'formula.functionList.MAX.aliasFunctionName',
+ functionType: FunctionType.Statistical,
+ description: 'formula.functionList.MAX.description',
+ abstract: 'formula.functionList.MAX.abstract',
+ functionParameter: [
+ {
+ name: 'formula.functionList.MAX.functionParameter.number1.name',
+ detail: 'formula.functionList.MAX.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MAX.functionParameter.number2.name',
+ detail: 'formula.functionList.MAX.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ {
+ functionName: FUNCTION_NAMES.COUNT,
+ aliasFunctionName: 'formula.functionList.COUNT.aliasFunctionName',
+ functionType: FunctionType.Statistical,
+ description: 'formula.functionList.COUNT.description',
+ abstract: 'formula.functionList.COUNT.abstract',
+ functionParameter: [
+ {
+ name: 'formula.functionList.COUNT.functionParameter.value1.name',
+ detail: 'formula.functionList.COUNT.functionParameter.value1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.COUNT.functionParameter.value2.name',
+ detail: 'formula.functionList.COUNT.functionParameter.value2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+ {
+ functionName: FUNCTION_NAMES.MIN,
+ aliasFunctionName: 'formula.functionList.MIN.aliasFunctionName',
+ functionType: FunctionType.Statistical,
+ description: 'formula.functionList.MIN.description',
+ abstract: 'formula.functionList.MIN.abstract',
+ functionParameter: [
+ {
+ name: 'formula.functionList.MIN.functionParameter.number1.name',
+ detail: 'formula.functionList.MIN.functionParameter.number1.detail',
+ example: 'A1:A20',
+ require: 1,
+ repeat: 0,
+ },
+ {
+ name: 'formula.functionList.MIN.functionParameter.number2.name',
+ detail: 'formula.functionList.MIN.functionParameter.number2.detail',
+ example: 'B2:B10',
+ require: 0,
+ repeat: 1,
+ },
+ ],
+ },
+];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/text.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/text.ts
new file mode 100644
index 0000000000..0fc7f7e142
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/text.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_TEXT: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/univer.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/univer.ts
new file mode 100644
index 0000000000..21942f7983
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/univer.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_UNIVER: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/function-list/web.ts b/packages/sheets-plugin-formula-ui/src/services/function-list/web.ts
new file mode 100644
index 0000000000..a80be6ddc9
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/services/function-list/web.ts
@@ -0,0 +1,3 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
+
+export const FUNCTION_LIST_WEB: IFunctionInfo[] = [];
diff --git a/packages/sheets-plugin-formula-ui/src/services/prompt.service.ts b/packages/sheets-plugin-formula-ui/src/services/prompt.service.ts
index e324e8b5f2..8f6821e2d8 100644
--- a/packages/sheets-plugin-formula-ui/src/services/prompt.service.ts
+++ b/packages/sheets-plugin-formula-ui/src/services/prompt.service.ts
@@ -3,10 +3,7 @@ import { Direction } from '@univerjs/core';
import { createIdentifier, IDisposable } from '@wendellhu/redi';
import { Observable, Subject } from 'rxjs';
-export interface ISearchItem {
- name: string;
- desc: string;
-}
+import { ISearchItem } from './description.service';
export interface ISearchFunctionParams {
/**
@@ -101,7 +98,7 @@ export interface IFormulaPromptService {
dispose(): void;
}
-export const IFormulaPromptService = createIdentifier<FormulaPromptService>('univer.formula-prompt-service');
+export const IFormulaPromptService = createIdentifier<FormulaPromptService>('formula-ui.prompt-service');
export class FormulaPromptService implements IFormulaPromptService, IDisposable {
private readonly _search$ = new Subject<ISearchFunctionParams>();
@@ -124,6 +121,10 @@ export class FormulaPromptService implements IFormulaPromptService, IDisposable
readonly acceptFormulaName$ = this._acceptFormulaName$.asObservable();
+ private _searching: boolean = false;
+
+ private _helping: boolean = false;
+
dispose(): void {
this._search$.complete();
this._help$.complete();
@@ -133,13 +134,23 @@ export class FormulaPromptService implements IFormulaPromptService, IDisposable
}
search(param: ISearchFunctionParams) {
+ this._searching = param.visible;
this._search$.next(param);
}
+ isSearching() {
+ return this._searching;
+ }
+
help(param: IHelpFunctionCommandParams) {
+ this._helping = param.visible;
this._help$.next(param);
}
+ isHelping() {
+ return this._helping;
+ }
+
navigate(param: INavigateParam) {
this._navigate$.next(param);
}
diff --git a/packages/sheets-plugin-formula-ui/src/services/utils.ts b/packages/sheets-plugin-formula-ui/src/services/utils.ts
index e60bd30b4c..6e2a3813ef 100644
--- a/packages/sheets-plugin-formula-ui/src/services/utils.ts
+++ b/packages/sheets-plugin-formula-ui/src/services/utils.ts
@@ -1,3 +1,4 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
import { LocaleService } from '@univerjs/core';
export function getFunctionTypeValues(
@@ -7,7 +8,22 @@ export function getFunctionTypeValues(
return Object.keys(enumObj)
.filter((key) => isNaN(Number(key)))
.map((key) => ({
- label: localeService.t(`formula.formulaMore.${key.toLocaleLowerCase()}`),
+ label: localeService.t(`formula.functionType.${key.toLocaleLowerCase()}`),
value: `${enumObj[key]}`,
}));
}
+
+export function getFunctionName(item: IFunctionInfo, localeService: LocaleService) {
+ let functionName = '';
+ if (item.aliasFunctionName) {
+ functionName = localeService.t(item.aliasFunctionName);
+
+ if (functionName === item.aliasFunctionName) {
+ functionName = item.functionName;
+ }
+ } else {
+ functionName = item.functionName;
+ }
+
+ return functionName;
+}
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.tsx
deleted file mode 100644
index 1634a3183e..0000000000
--- a/packages/sheets-plugin-formula-ui/src/views/more-functions/InputParams.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-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.tsx
index f12c13f806..aee4075b06 100644
--- a/packages/sheets-plugin-formula-ui/src/views/more-functions/MoreFunctions.tsx
+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/MoreFunctions.tsx
@@ -1,3 +1,4 @@
+import { IFunctionInfo } from '@univerjs/base-formula-engine';
import { ISidebarService } from '@univerjs/base-ui';
import { LocaleService } from '@univerjs/core';
import { Button } from '@univerjs/design';
@@ -5,39 +6,43 @@ import { useDependency } from '@wendellhu/redi/react-bindings';
import { useState } from 'react';
import styles from './index.module.less';
-import { InputParams } from './InputParams';
+import { InputParams } from './input-params/InputParams';
import { SelectFunction } from './select-function/SelectFunction';
export function MoreFunctions() {
const [selectFunction, setSelectFunction] = useState<boolean>(true);
const [inputParams, setInputParams] = useState<boolean>(false);
+ const [params, setParams] = useState<string[]>([]);
+ const [functionInfo, setFunctionInfo] = useState<IFunctionInfo | null>(null);
const localeService = useDependency(LocaleService);
const sidebarService = useDependency(ISidebarService);
function handleClickNextPrev() {
+ if (selectFunction) {
+ // TODO@Dushusir: insert function
+ }
+
setSelectFunction(!selectFunction);
setInputParams(!inputParams);
}
function handleConfirm() {
- sidebarService.close();
+ // TODO@Dushusir: save function `=${functionInfo?.functionName}(${params.join(',')})`
}
return (
<div className={styles.formulaMoreFunctions}>
- {selectFunction && <SelectFunction></SelectFunction>}
- {inputParams && <InputParams></InputParams>}
- <div>
+ {selectFunction && <SelectFunction onChange={setFunctionInfo}></SelectFunction>}
+ {inputParams && <InputParams functionInfo={functionInfo} onChange={setParams}></InputParams>}
+ <div className={styles.formulaMoreFunctionsOperation}>
{selectFunction && (
<Button type="primary" onClick={handleClickNextPrev}>
{localeService.t('formula.moreFunctions.next')}
</Button>
)}
{inputParams && (
- <Button type="text" onClick={handleClickNextPrev}>
- {localeService.t('formula.moreFunctions.prev')}
- </Button>
+ <Button onClick={handleClickNextPrev}>{localeService.t('formula.moreFunctions.prev')}</Button>
)}
{inputParams && (
<Button type="primary" onClick={handleConfirm}>
diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx b/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
new file mode 100644
index 0000000000..a5714676ec
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
@@ -0,0 +1,16 @@
+import styles from './index.module.less';
+
+interface IParamsProps {
+ className?: string;
+ title?: string;
+ value?: string | React.ReactElement;
+}
+
+export function FunctionParams(props: IParamsProps) {
+ return (
+ <div className={styles.formulaFunctionParams}>
+ <div className={`${styles.formulaFunctionParamsTitle} ${props.className}`}>{props.title}</div>
+ <div className={styles.formulaFunctionParamsDetail}>{props.value}</div>
+ </div>
+ );
+}
diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/index.module.less b/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/index.module.less
new file mode 100644
index 0000000000..35414f9554
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/index.module.less
@@ -0,0 +1,14 @@
+.formula-function-params {
+ margin: var(--margin-xs) 0;
+ font-size: var(--font-size-xxs);
+
+ &-title {
+ font-weight: 500;
+ color: rgb(var(--text-color-secondary));
+ }
+
+ &-detail {
+ font-weight: 400;
+ color: rgb(var(--text-color));
+ }
+}
\ No newline at end of file
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.less
index 00a719eab1..c61f4f4566 100644
--- 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.less
@@ -3,4 +3,13 @@
flex-direction: column;
justify-content: space-between;
height: 100%;
+
+ &-operation {
+ display: flex;
+ justify-content: flex-end;
+
+ >button{
+ margin: 0 0 var(--margin-lg) var(--margin-base);
+ }
+ }
}
\ No newline at end of file
diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/InputParams.tsx b/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/InputParams.tsx
new file mode 100644
index 0000000000..6553724c70
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/InputParams.tsx
@@ -0,0 +1,52 @@
+import { IFunctionInfo, IFunctionParam } from '@univerjs/base-formula-engine';
+import { RangeSelector } from '@univerjs/ui-plugin-sheets';
+import { useState } from 'react';
+
+import { FunctionParams } from '../function-params/FunctionParams';
+import styles from './index.module.less';
+
+export interface IInputParamsProps {
+ functionInfo: IFunctionInfo | null;
+ onChange: (params: string[]) => void;
+}
+
+export function InputParams(props: IInputParamsProps) {
+ const { functionInfo, onChange } = props;
+ const [params, setParams] = useState<string[]>([]);
+ const [activeIndex, setActiveIndex] = useState(0);
+
+ function handleRangeChange(range: string, paramIndex: number) {
+ const newParams = [...params];
+ newParams[paramIndex] = range;
+ setParams(newParams);
+ onChange(newParams);
+ }
+
+ return (
+ <div className={styles.formulaInputParams}>
+ <div className={styles.formulaInputParamsList}>
+ {functionInfo &&
+ functionInfo.functionParameter &&
+ functionInfo.functionParameter.map((item: IFunctionParam, i: number) => (
+ <div key={i}>
+ <div className={styles.formulaInputParamsListItemName}>{item.name}</div>
+
+ <div className={styles.formulaInputParamsListItemSelector}>
+ <RangeSelector
+ onChange={(range: string) => handleRangeChange(range, i)}
+ onActive={() => setActiveIndex(i)}
+ />
+ </div>
+ </div>
+ ))}
+ </div>
+
+ <div className={styles.formulaInputParamsInfo}>
+ <FunctionParams
+ title={functionInfo?.functionParameter[activeIndex].name}
+ value={functionInfo?.functionParameter[activeIndex].detail}
+ />
+ </div>
+ </div>
+ );
+}
diff --git a/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/index.module.less b/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/index.module.less
new file mode 100644
index 0000000000..7b4e71873a
--- /dev/null
+++ b/packages/sheets-plugin-formula-ui/src/views/more-functions/input-params/index.module.less
@@ -0,0 +1,11 @@
+.formula-input-params {
+ &-list-item{
+ &-name{
+ font-size: var(--font-size-sm);
+ }
+
+ &-selector{
+ margin: var(--margin-xxs) 0 var(--margin-xs) 0;
+ }
+ }
+}
\ No newline at end of file
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.tsx
index 0c57b29afc..9e3a69b559 100644
--- 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.tsx
@@ -1,42 +1,51 @@
-import { FunctionType, IFunctionInfo } from '@univerjs/base-formula-engine';
+import { FunctionType, IFunctionInfo, IFunctionParam } from '@univerjs/base-formula-engine';
import { LocaleService } from '@univerjs/core';
import { Input, Select } from '@univerjs/design';
+import { CheckMarkSingle } from '@univerjs/icons';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import { useState } from 'react';
+import React, { useEffect, useState } from 'react';
-import { getFunctionName } from '../../../controllers/util';
-import { FUNCTION_LIST } from '../../../services/function-list';
+import { IDescriptionService, ISearchItem } from '../../../services/description.service';
import { getFunctionTypeValues } from '../../../services/utils';
+import { FunctionParams } from '../function-params/FunctionParams';
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 interface ISelectFunctionProps {
+ onChange: (functionInfo: IFunctionInfo) => void;
}
-export function SelectFunction() {
- const [selectList, setSelectList] = useState<string[]>([]);
+export function SelectFunction(props: ISelectFunctionProps) {
+ const { onChange } = props;
+ const allTypeValue = '-1';
const [searchText, setSearchText] = useState<string>('');
+ const [selectList, setSelectList] = useState<ISearchItem[]>([]);
const [active, setActive] = useState(0);
+ const [typeSelected, setTypeSelected] = useState(allTypeValue);
+ const [nameSelected, setNameSelected] = useState(0);
const [functionInfo, setFunctionInfo] = useState<IFunctionInfo | null>(null);
+ const descriptionService = useDependency(IDescriptionService);
const localeService = useDependency(LocaleService);
+
const options = getFunctionTypeValues(FunctionType, localeService);
+ options.unshift({
+ label: localeService.t(`formula.moreFunctions.allFunctions`),
+ value: allTypeValue,
+ });
+
+ const required = localeService.t('formula.prompt.required');
+ const optional = localeService.t('formula.prompt.optional');
+
+ useEffect(() => {
+ handleSelectChange(allTypeValue);
+ }, []);
+
+ useEffect(() => {
+ setCurrentFunctionInfo(0);
+ }, [selectList]);
const highlightSearchText = (text: string) => {
- const regex = new RegExp(`(${searchText})`);
+ const regex = new RegExp(`(${searchText.toLocaleUpperCase()})`);
const parts = text.split(regex).filter(Boolean);
- console.info('parts', parts, searchText);
return parts.map((part: string, index: number) => {
if (part.match(regex)) {
@@ -50,23 +59,47 @@ export function SelectFunction() {
});
};
+ const setCurrentFunctionInfo = (selectedIndex: number) => {
+ if (selectList.length === 0) {
+ setFunctionInfo(null);
+ return;
+ }
+
+ setNameSelected(selectedIndex);
+ const functionInfo = descriptionService.getFunctionInfo(selectList[selectedIndex].name);
+ if (!functionInfo) {
+ setFunctionInfo(null);
+ return;
+ }
+
+ setFunctionInfo(functionInfo);
+ onChange(functionInfo);
+ };
+
function handleSelectChange(value: string) {
- console.info('value=====', value);
+ setTypeSelected(value);
+ const selectList = descriptionService.getSearchListByType(+value);
+ setSelectList(selectList);
}
+ // TODO@Dushusir: debounce
function handleSearchInputChange(value: string) {
setSearchText(value);
- const selectList = getSearchList(value, localeService);
- // console.info('搜索===', selectList, searchText);
+ const selectList = descriptionService.getSearchListByName(value);
setSelectList(selectList);
- setActive(0);
- const functionInfo = getFunctionInfo(selectList[active], localeService);
- if (!functionInfo) return;
- setFunctionInfo(functionInfo);
}
- function handleClickSelectItem(value: string) {
- console.info('value=====', value);
+ function handleSelectListKeyDown(e: React.KeyboardEvent<HTMLUListElement> | React.KeyboardEvent<HTMLInputElement>) {
+ e.stopPropagation();
+ if (e.key === 'ArrowDown') {
+ const nextActive = active + 1;
+ setActive(nextActive === selectList.length ? 0 : nextActive);
+ } else if (e.key === 'ArrowUp') {
+ const nextActive = active - 1;
+ setActive(nextActive === -1 ? selectList.length - 1 : nextActive);
+ } else if (e.key === 'Enter') {
+ setCurrentFunctionInfo(active);
+ }
}
const handleLiMouseEnter = (index: number) => {
@@ -76,21 +109,24 @@ export function SelectFunction() {
const handleLiMouseLeave = () => {
setActive(-1);
};
+
return (
<div>
- <div>
- <Select value="select" options={options} onChange={handleSelectChange}></Select>
+ <div className={styles.formulaSelectFunctionSelect}>
+ <Select value={typeSelected} options={options} onChange={handleSelectChange}></Select>
<Input
- placeholder={localeService.t(`formula.formulaMore.searchFunctionPlaceholder`)}
- onKeyDown={(e) => e.stopPropagation()}
+ placeholder={localeService.t(`formula.moreFunctions.searchFunctionPlaceholder`)}
+ onKeyDown={handleSelectListKeyDown}
value={searchText}
onChange={handleSearchInputChange}
+ size="large"
+ allowClear
></Input>
</div>
- <ul className={styles.formulaSelectFunctionResult}>
- {selectList.map((item, index) => (
+ <ul className={styles.formulaSelectFunctionResult} onKeyDown={handleSelectListKeyDown} tabIndex={-1}>
+ {selectList.map(({ name }, index) => (
<li
key={index}
className={
@@ -98,14 +134,66 @@ export function SelectFunction() {
? `${styles.formulaSelectFunctionResultItem} ${styles.formulaSelectFunctionResultItemActive}`
: styles.formulaSelectFunctionResultItem
}
- // onMouseEnter={() => handleLiMouseEnter(index)}
- // onMouseLeave={handleLiMouseLeave}
- onClick={() => handleClickSelectItem(item)}
+ onMouseEnter={() => handleLiMouseEnter(index)}
+ onMouseLeave={handleLiMouseLeave}
+ onClick={() => setCurrentFunctionInfo(index)}
>
- <span className={styles.formulaSelectFunctionResultItemName}>{highlightSearchText(item)}</span>
+ {nameSelected === index && (
+ <CheckMarkSingle className={styles.formulaSelectFunctionResultItemSelected} />
+ )}
+ <span className={styles.formulaSelectFunctionResultItemName}>{highlightSearchText(name)}</span>
</li>
))}
</ul>
+
+ {functionInfo && (
+ <div className={styles.formulaSelectFunctionContent}>
+ <FunctionParams title={functionInfo.functionName} value={functionInfo.description} />
+
+ <FunctionParams
+ title={localeService.t('formula.moreFunctions.syntax')}
+ value={<Help prefix={functionInfo.functionName} value={functionInfo.functionParameter} />}
+ />
+
+ <FunctionParams
+ title={localeService.t('formula.prompt.helpExample')}
+ value={`${functionInfo.functionName}(${functionInfo.functionParameter
+ .map((item) => item.example)
+ .join(',')})`}
+ />
+
+ {functionInfo.functionParameter &&
+ functionInfo.functionParameter.map((item: IFunctionParam, i: number) => (
+ <FunctionParams
+ key={i}
+ title={item.name}
+ value={`${item.require ? required : optional} ${item.detail}`}
+ />
+ ))}
+ </div>
+ )}
</div>
);
}
+
+interface IHelpProps {
+ prefix?: string;
+ value?: IFunctionParam[];
+}
+
+const Help = (props: IHelpProps) => {
+ const { prefix, value } = props;
+ return (
+ <div>
+ <span>{prefix}(</span>
+ {value &&
+ value.map((item: IFunctionParam, i: number) => (
+ <span key={i}>
+ <span>{item.repeat ? `[${item.name},...]` : item.name}</span>
+ {i === value.length - 1 ? '' : ','}
+ </span>
+ ))}
+ )
+ </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.less
index 2c127edc4b..ae7dcbc95f 100644
--- 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.less
@@ -1,21 +1,41 @@
+@result-height: 364px;
+@result-item-padding-left: 28px;
+@selected-icon-left: 6px;
+
.formula-select-function {
+ &-select {
+ display: flex;
+ gap: 10%;
+ align-items: center;
+ justify-content: space-between;
+
+ }
+
&-result {
+ user-select: none;
+
box-sizing: border-box;
width: 100%;
+ height: @result-height;
margin: 0;
+ margin-top: var(--margin-xs);
padding: var(--padding-base);
- font-size: var(--font-size-sm);
list-style: none;
+ border: 1px solid rgb(var(--border-color));
+ border-radius: var(--border-radius-base);
outline: none;
&-item {
cursor: pointer;
+ position: relative;
+
box-sizing: border-box;
- padding: var(--padding-sm);
+ padding: var(--padding-sm) @result-item-padding-left;
+ font-size: var(--font-size-xs);
color: rgb(var(--text-color));
border-radius: var(--border-radius-base);
@@ -28,10 +48,26 @@
}
}
+ &-selected {
+ position: absolute;
+ top: 50%;
+ left: @selected-icon-left;
+ transform: translateY(-50%);
+
+ display: inline-flex;
+
+ font-size: var(--font-size-lg);
+ color: rgb(var(--success-color));
+ }
+
&-active {
background-color: rgb(var(--bg-color-hover));
}
}
}
+ &-content {
+ overflow-y: auto;
+ }
+
}
\ No newline at end of file
diff --git a/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsx b/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsx
index 966e51ac93..63e92db3cb 100644
--- a/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsx
+++ b/packages/sheets-plugin-formula-ui/src/views/prompt/help-function/HelpFunction.tsx
@@ -20,6 +20,8 @@ export function HelpFunction() {
const promptService = useDependency(IFormulaPromptService);
const cellEditorManagerService = useDependency(ICellEditorManagerService);
const localeService = useDependency(LocaleService);
+ const required = localeService.t('formula.prompt.required');
+ const optional = localeService.t('formula.prompt.optional');
useEffect(() => {
const subscription = promptService.help$.subscribe((params: IHelpFunctionCommandParams) => {
@@ -33,18 +35,16 @@ export function HelpFunction() {
}
const localeInfo: IFunctionInfo = {
- functionName: functionInfo.functionName as string,
+ functionName: functionInfo.functionName,
functionType: functionInfo.functionType,
- description: localeService.t(functionInfo.description) as string,
- abstract: localeService.t(functionInfo.abstract) as string,
- parameterRange: functionInfo.parameterRange,
+ description: localeService.t(functionInfo.description),
+ abstract: localeService.t(functionInfo.abstract),
functionParameter: functionInfo.functionParameter.map((item) => ({
- name: localeService.t(item.name) as string,
- detail: localeService.t(item.detail) as string,
+ name: localeService.t(item.name),
+ detail: localeService.t(item.detail),
example: item.example,
require: item.require,
repeat: item.repeat,
- type: item.type,
})),
};
const { startX = 0, startY = 0, endY = 0 } = selection;
@@ -75,9 +75,8 @@ export function HelpFunction() {
<div className={styles.formulaHelpFunction}>
<div className={styles.formulaHelpFunctionTitle}>
<Help
- title={functionInfo.functionName}
+ prefix={functionInfo.functionName}
value={functionInfo.functionParameter}
- type="name"
active={paramIndex}
onClick={handleSwitchActive}
/>
@@ -104,13 +103,13 @@ export function HelpFunction() {
>
<div className={styles.formulaHelpFunctionContentInner}>
<Params
- title={localeService.t('formula.formulaMore.helpExample') as string}
+ title={localeService.t('formula.prompt.helpExample')}
value={`${functionInfo.functionName}(${functionInfo.functionParameter
.map((item) => item.example)
.join(',')})`}
/>
<Params
- title={localeService.t('formula.formulaMore.helpAbstract') as string}
+ title={localeService.t('formula.prompt.helpAbstract')}
value={functionInfo.description}
/>
{functionInfo &&
@@ -120,8 +119,7 @@ export function HelpFunction() {
key={i}
className={paramIndex === i ? styles.formulaHelpFunctionActive : ''}
title={item.name}
- value={item.detail}
- active={paramIndex}
+ value={`${item.require ? required : optional} ${item.detail}`}
/>
))}
</div>
@@ -153,7 +151,6 @@ interface IParamsProps {
className?: string;
title?: string;
value?: string;
- active?: number;
}
const Params = (props: IParamsProps) => (
@@ -164,21 +161,17 @@ const Params = (props: IParamsProps) => (
);
interface IHelpProps {
- title?: string;
+ prefix?: string;
value?: IFunctionParam[];
- type: string;
active: number;
onClick: (paramIndex: number) => void;
}
const Help = (props: IHelpProps) => {
- const { title, value, type, active, onClick } = props;
+ const { prefix, value, active, onClick } = props;
return (
<div>
- <span>
- {title}
- {'('}
- </span>
+ <span>{prefix}(</span>
{value &&
value.map((item: IFunctionParam, i: number) => (
// TODO@Dushusir: more params needs to be active
@@ -187,12 +180,12 @@ const Help = (props: IHelpProps) => {
className={active === i ? styles.formulaHelpFunctionActive : ''}
onClick={() => onClick(i)}
>
- {(item as any)[`${type}`]}
+ {item.repeat ? `[${item.name},...]` : item.name}
</span>
{i === value.length - 1 ? '' : ','}
</span>
))}
- <span>{')'}</span>
+ )
</div>
);
};
diff --git a/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsx b/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsx
index 6caa0223d4..f09fe0886f 100644
--- a/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsx
+++ b/packages/sheets-plugin-formula-ui/src/views/prompt/search-function/SearchFunction.tsx
@@ -4,12 +4,8 @@ import { ICellEditorManagerService } from '@univerjs/ui-plugin-sheets';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useState } from 'react';
-import {
- IFormulaPromptService,
- INavigateParam,
- ISearchFunctionParams,
- ISearchItem,
-} from '../../../services/prompt.service';
+import { ISearchItem } from '../../../services/description.service';
+import { IFormulaPromptService, INavigateParam, ISearchFunctionParams } from '../../../services/prompt.service';
import styles from './index.module.less';
export function SearchFunction() {
diff --git a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts b/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts
index d78ef2963f..2710f3d419 100644
--- a/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts
+++ b/packages/sheets-plugin-formula/src/controllers/calculate.controller.ts
@@ -128,7 +128,6 @@ export class CalculateController extends Disposable {
const engine = this._formulaEngineService;
const { sheetData, sheetNameMap } = this._getSheetData();
// Add mutation after calculating the formula
- // TODO@Dushusir: use new service after engine refactor
engine
.execute(unitId, {
unitData: {
diff --git a/packages/ui-plugin-sheets/src/components/range-selector/RangeSelector.tsx b/packages/ui-plugin-sheets/src/components/range-selector/RangeSelector.tsx
new file mode 100644
index 0000000000..a7e65849fa
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/components/range-selector/RangeSelector.tsx
@@ -0,0 +1,79 @@
+import { SelectionManagerService } from '@univerjs/base-sheets';
+import { LocaleService } from '@univerjs/core';
+import { Tooltip } from '@univerjs/design';
+import { SelectRangeSingle } from '@univerjs/icons';
+import { useDependency } from '@wendellhu/redi/react-bindings';
+import { useEffect, useRef, useState } from 'react';
+
+import styles from './index.module.less';
+
+export interface IRangeSelectorProps {
+ onChange: (range: string) => void;
+ onActive: (active: boolean) => void;
+}
+
+export function RangeSelector(props: IRangeSelectorProps) {
+ const { onChange, onActive } = props;
+ const [active, setActive] = useState(false);
+ const editableRef = useRef<HTMLDivElement>(null);
+ const localeService = useDependency(LocaleService);
+ const textSelectionManagerService = useDependency(SelectionManagerService);
+
+ useEffect(() => {
+ if (active) {
+ onActive(active);
+ const subscribe = textSelectionManagerService.selectionInfo$.subscribe((selectionInfo) => {
+ // TODO@Dushusir: get range text info from selectionInfo
+ const rangeTextList = ['A1', 'B2:C3', 'Sheet2!A1:B2', 'D10:E11,F1:G2,H3:I4'];
+ const randomIndex = Math.floor(Math.random() * rangeTextList.length);
+ const range = rangeTextList[randomIndex];
+
+ if (editableRef.current) {
+ editableRef.current.innerHTML = range;
+ }
+ });
+
+ return () => {
+ subscribe.unsubscribe();
+ };
+ }
+
+ onChange(editableRef.current?.innerHTML || '');
+ }, [active]);
+
+ function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {
+ e.stopPropagation();
+ if (e.key === 'Enter') {
+ e.preventDefault();
+ e.currentTarget.blur();
+ setActive(false);
+ }
+ }
+
+ function handleFocus() {
+ setActive(true);
+ }
+
+ function handleClick() {
+ setActive(!active);
+ }
+
+ return (
+ <div className={active ? `${styles.rangeSelector} ${styles.rangeSelectorActive}` : styles.rangeSelector}>
+ <div
+ ref={editableRef}
+ className={styles.rangeSelectorEditor}
+ contentEditable
+ data-placeholder={localeService.t('rangeSelector.placeholder')}
+ onKeyDown={handleKeyDown}
+ onFocus={handleFocus}
+ ></div>
+
+ <Tooltip title={localeService.t('rangeSelector.tooltip')} placement="bottom">
+ <button className={styles.rangeSelectorIcon} onClick={handleClick}>
+ <SelectRangeSingle />
+ </button>
+ </Tooltip>
+ </div>
+ );
+}
diff --git a/packages/ui-plugin-sheets/src/components/range-selector/index.module.less b/packages/ui-plugin-sheets/src/components/range-selector/index.module.less
new file mode 100644
index 0000000000..69c25128b6
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/components/range-selector/index.module.less
@@ -0,0 +1,81 @@
+@padding-top-bottom: 6px;
+@height: 20px;
+@width: 218px;
+@icon-size: 24px;
+
+.range-selector {
+ overflow: hidden;
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+
+ padding: @padding-top-bottom var(--padding-sm) @padding-top-bottom var(--padding-base);
+
+
+ border: 1px solid rgb(var(--border-color));
+ border-radius: var(--border-radius-base);
+
+ &-editor {
+ cursor: text;
+
+ overflow: hidden;
+ display: inline-block;
+
+ width: @width;
+ height: @height;
+
+ font-size: var(--font-size-xs);
+ line-height: @height;
+ text-wrap: nowrap;
+
+ border: 0;
+ outline: 0;
+
+ &::selection {
+ color: rgb(var(--color-white));
+ background-color: rgb(var(--primary-color));
+ }
+
+ &:empty::before {
+ content: attr(data-placeholder);
+ color: rgb(var(--grey-400))
+ }
+ }
+
+ &-icon {
+ cursor: pointer;
+
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ width: @icon-size;
+ height: @icon-size;
+ padding: 0;
+
+ font-size: var(--font-size-lg);
+ color: rgb(var(--text-color));
+
+ background-color: transparent;
+ border: none;
+ border-radius: var(--border-radius-base);
+ outline: none;
+
+ &:not([disabled]):hover {
+ background-color: rgb(var(--grey-100));
+ }
+
+ &[disabled] {
+ cursor: not-allowed;
+ color: rgb(var(--grey-200));
+ }
+ }
+
+ &-active {
+ border-color: rgb(var(--primary-color));
+
+ .range-selector-icon {
+ color: rgb(var(--primary-color));
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/ui-plugin-sheets/src/index.ts b/packages/ui-plugin-sheets/src/index.ts
index cb9b8d7cf0..8103fac111 100644
--- a/packages/ui-plugin-sheets/src/index.ts
+++ b/packages/ui-plugin-sheets/src/index.ts
@@ -1,6 +1,7 @@
export * from './basics';
export { getEditorObject } from './basics/editor/get-editor-object';
export { SetCellEditVisibleArrowOperation } from './commands/operations/cell-edit.operation';
+export { RangeSelector } from './components/range-selector/RangeSelector';
export { whenEditorInputFormulaActivated } from './controllers/shortcuts/utils';
export {
getCoordByCell,
diff --git a/packages/ui-plugin-sheets/src/locale/en-US.ts b/packages/ui-plugin-sheets/src/locale/en-US.ts
index fc4bc513ad..6530b18b99 100644
--- a/packages/ui-plugin-sheets/src/locale/en-US.ts
+++ b/packages/ui-plugin-sheets/src/locale/en-US.ts
@@ -552,4 +552,9 @@ export default {
formatOnly: 'Format Only',
noFormat: 'No Format',
},
+
+ rangeSelector: {
+ placeholder: 'Select range or input value',
+ tooltip: 'Select range',
+ },
};
diff --git a/packages/ui-plugin-sheets/src/locale/zh-CN.ts b/packages/ui-plugin-sheets/src/locale/zh-CN.ts
index a84557606d..986face369 100644
--- a/packages/ui-plugin-sheets/src/locale/zh-CN.ts
+++ b/packages/ui-plugin-sheets/src/locale/zh-CN.ts
@@ -416,4 +416,8 @@ export default {
formatOnly: '仅填充格式',
noFormat: '不带格式填充',
},
+ rangeSelector: {
+ placeholder: '选择范围或输入值',
+ tooltip: '选择范围',
+ },
};
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
index 8866414c7e..4674a787ec 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-button/index.module.less
@@ -21,7 +21,6 @@
&:not([disabled]):hover {
background-color: rgb(var(--bg-color-hover));
- border-color: transparent;
}
&[disabled] {
diff --git a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
index 64ff55bdeb..f413242234 100644
--- a/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
+++ b/packages/ui-plugin-sheets/src/views/sheet-bar/sheet-bar-tabs/index.module.less
@@ -48,7 +48,6 @@ Tab Item, Put outside to be compatible with drag styles
&-edit {
cursor: text;
- border-color: rgb(var(--primary-color));
outline: none;
&::selection {