From 34101b4ec93b56635f555084becaecf0afe98da9 Mon Sep 17 00:00:00 2001
From: Dushusir <1414556676@qq.com>
Date: Fri, 17 Nov 2023 20:39:39 +0800
Subject: [PATCH] feat(formula): select function, range selector
---
packages/base-ui/src/components/index.ts | 1 -
.../range-selector/RangeSelector.tsx | 11 ---
.../range-selector/index.module.less | 3 -
.../doc-bars/Button/index.module.less | 3 -
packages/base-ui/tsconfig.json | 2 +-
.../design/src/components/input/Input.tsx | 19 +++--
.../design/src/components/select/Select.tsx | 6 +-
.../operations/editor-formula.operation.ts | 2 +-
.../src/controllers/formula-ui.controller.ts | 4 +-
.../controllers/shortcuts/prompt.shortcut.ts | 4 +-
.../src/locale/zh-CN.ts | 2 +-
.../views/more-functions/MoreFunctions.tsx | 15 ++--
.../function-params/FunctionParams.tsx | 16 ++++
.../function-params/index.module.less | 14 ++++
.../views/more-functions/index.module.less | 9 +++
.../input-params/InputParams.tsx | 48 ++++++++---
.../input-params/index.module.less | 10 ++-
.../select-function/SelectFunction.tsx | 51 ++++++------
.../select-function/index.module.less | 55 +++++++------
.../range-selector/RangeSelector.tsx | 79 ++++++++++++++++++
.../range-selector/index.module.less | 81 +++++++++++++++++++
packages/ui-plugin-sheets/src/index.ts | 1 +
packages/ui-plugin-sheets/src/locale/en-US.ts | 5 ++
packages/ui-plugin-sheets/src/locale/zh-CN.ts | 4 +
.../sheet-bar-button/index.module.less | 1 -
.../sheet-bar-tabs/index.module.less | 1 -
26 files changed, 346 insertions(+), 101 deletions(-)
delete mode 100644 packages/base-ui/src/components/range-selector/RangeSelector.tsx
delete mode 100644 packages/base-ui/src/components/range-selector/index.module.less
create mode 100644 packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/FunctionParams.tsx
create mode 100644 packages/sheets-plugin-formula-ui/src/views/more-functions/function-params/index.module.less
create mode 100644 packages/ui-plugin-sheets/src/components/range-selector/RangeSelector.tsx
create mode 100644 packages/ui-plugin-sheets/src/components/range-selector/index.module.less
diff --git a/packages/base-ui/src/components/index.ts b/packages/base-ui/src/components/index.ts
index cebc8c48815a..62db8296f85f 100644
--- a/packages/base-ui/src/components/index.ts
+++ b/packages/base-ui/src/components/index.ts
@@ -1,3 +1,2 @@
export * from './custom-label';
export * from './menu';
-export * from './range-selector/RangeSelector';
diff --git a/packages/base-ui/src/components/range-selector/RangeSelector.tsx b/packages/base-ui/src/components/range-selector/RangeSelector.tsx
deleted file mode 100644
index 7cecc04a66ff..000000000000
--- a/packages/base-ui/src/components/range-selector/RangeSelector.tsx
+++ /dev/null
@@ -1,11 +0,0 @@
-import { Input } from '@univerjs/design';
-
-import styles from './index.module.less';
-
-export function RangeSelector() {
- return (
-
-
-
- );
-}
diff --git a/packages/base-ui/src/components/range-selector/index.module.less b/packages/base-ui/src/components/range-selector/index.module.less
deleted file mode 100644
index 6323c025f0d8..000000000000
--- a/packages/base-ui/src/components/range-selector/index.module.less
+++ /dev/null
@@ -1,3 +0,0 @@
-.range-selector {
- display: flex;
-}
\ No newline at end of file
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 9ee16d914170..75eacb959036 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 f35fde7a9a04..c145687492da 100644
--- a/packages/base-ui/tsconfig.json
+++ b/packages/base-ui/tsconfig.json
@@ -10,5 +10,5 @@
"include": [
"src/**/*",
"test/**/*.test.(ts|tsx|js)"
- ]
+, "../ui-plugin-sheets/src/components/range-selector" ]
}
diff --git a/packages/design/src/components/input/Input.tsx b/packages/design/src/components/input/Input.tsx
index 9817ef06e7a1..0a4a84616e67 100644
--- a/packages/design/src/components/input/Input.tsx
+++ b/packages/design/src/components/input/Input.tsx
@@ -5,6 +5,9 @@ import RcInput from 'rc-input';
import styles from './index.module.less';
export interface IInputProps {
+ /** Semantic DOM class */
+ className?: string;
+
/**
* The input affix wrapper style
*/
@@ -65,6 +68,7 @@ export interface IInputProps {
export function Input(props: IInputProps) {
const {
+ className,
affixWrapperStyle,
type = 'text',
placeholder,
@@ -82,12 +86,15 @@ export function Input(props: IInputProps) {
onChange?.(value);
}
- const _className = clsx({
- [styles.inputAffixWrapperMini]: size === 'mini',
- [styles.inputAffixWrapperSmall]: size === 'small',
- [styles.inputAffixWrapperMiddle]: size === 'middle',
- [styles.inputAffixWrapperLarge]: size === 'large',
- });
+ const _className = clsx(
+ {
+ [styles.inputAffixWrapperMini]: size === 'mini',
+ [styles.inputAffixWrapperSmall]: size === 'small',
+ [styles.inputAffixWrapperMiddle]: size === 'middle',
+ [styles.inputAffixWrapperLarge]: size === 'large',
+ },
+ className
+ );
return (
mountContainer}
options={options}
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 ae5e4fc9d64b..83e9f9e1a72b 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
@@ -12,7 +12,7 @@ export interface ISelectEditorFormulaOperationParam {
keycode?: KeyCode;
}
-export const SelectEditorFormluaOperation: IOperation = {
+export const SelectEditorFormulaOperation: IOperation = {
id: 'formula-ui.operation.select-editor-formula',
type: CommandType.OPERATION,
handler: (accessor, params) => {
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 99233ed499e3..94ba4b0c5db9 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/shortcuts/prompt.shortcut.ts b/packages/sheets-plugin-formula-ui/src/controllers/shortcuts/prompt.shortcut.ts
index 53c49c06da8a..cf261f9abb26 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/locale/zh-CN.ts b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
index d1c58ff074c3..1c0b3a8419d7 100644
--- a/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
+++ b/packages/sheets-plugin-formula-ui/src/locale/zh-CN.ts
@@ -69,7 +69,7 @@ export default {
},
moreFunctions: {
- confirm: '确定',
+ confirm: '应用',
prev: '上一步',
next: '下一步',
searchFunctionPlaceholder: '搜索函数',
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 fc80fa8235d6..aee4075b063a 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
@@ -12,34 +12,37 @@ import { SelectFunction } from './select-function/SelectFunction';
export function MoreFunctions() {
const [selectFunction, setSelectFunction] = useState(true);
const [inputParams, setInputParams] = useState(false);
+ const [params, setParams] = useState([]);
const [functionInfo, setFunctionInfo] = useState(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 (
{selectFunction &&
}
- {inputParams &&
}
-
+ {inputParams &&
}
+
{selectFunction && (
)}
{inputParams && (
-
+
)}
{inputParams && (