Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
chore(formula): helpFunction,searchFunction
Dushusir990efda8f97b
diff --git a/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts b/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.tsindex dd511c8333..0703c201c0 100644--- a/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts+++ b/packages/sheets-plugin-formula/src/Basic/Const/FunctionList.ts@@ -1,22 +1,37 @@-interface P {+export interface FormulaParamType {+ /**+ * formula param name locale key+ */name?: string;+ /**+ * formula param detail description locale key+ */detail?: string;example?: string;require?: string;repeat?: string;type?: string;}-interface FunctionList {++export interface FormulaType {+ /**+ * formula name+ */n?: string;t?: number;+ /**+ * detail description locale key+ */d?: string;- dLocale?: string;a?: string;m?: number[];- p?: P[];+ /**+ * formula params locale key+ */+ p?: FormulaParamType[];}-const SelectCategoryType = [+export const SelectCategoryType = [{locale: 'formula.formulaMore.Math',},@@ -67,25 +82,25 @@ const SelectCategoryType = [},];-const FunList = [+export const FunList: FormulaType[] = [{n: 'SUMIF',t: 0,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',p: [{- nameLocale: 'formula.functionList.SUMIF.p.range.name',- detailLocale: 'formula.functionList.SUMIF.p.range.detail',+ name: 'formula.functionList.SUMIF.p.range.name',+ detail: 'formula.functionList.SUMIF.p.range.detail',example: 'A1:A10',},{- nameLocale: 'formula.functionList.SUMIF.p.rangeAll.name',- detailLocale: 'formula.functionList.SUMIF.p.rangeAll.detail',+ name: 'formula.functionList.SUMIF.p.rangeAll.name',+ detail: 'formula.functionList.SUMIF.p.rangeAll.detail',example: '">20"',},{- nameLocale: 'formula.functionList.SUMIF.p.range1.name',- detailLocale: 'formula.functionList.SUMIF.p.range1.detail',+ name: 'formula.functionList.SUMIF.p.range1.name',+ detail: 'formula.functionList.SUMIF.p.range1.detail',example: 'B1:B10',},],@@ -93,40 +108,40 @@ const FunList = [{n: 'SUMIF1',t: 1,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF2',t: 2,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF3',t: 3,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF4',t: 4,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF5',t: 5,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF6',t: 6,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},{n: 'SUMIF7',t: 7,- dLocale: 'formula.functionList.SUMIF.d',+ d: 'formula.functionList.SUMIF.d',},];-export { SelectCategoryType, FunList };+// export { SelectCategoryType, FunList };-export type { FunctionList, P };+// export type { FunctionList, P };diff --git a/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts b/packages/sheets-plugin-formula/src/Controller/CellInputHandler.tsindex 70721ef524..b2c20398b3 100644--- a/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts+++ b/packages/sheets-plugin-formula/src/Controller/CellInputHandler.ts@@ -1,6 +1,6 @@import { $$, getNodeindex, xssDeal } from '@univerjs/base-ui';import { Nullable, Tools } from '@univerjs/core';-import { lang } from './locale';+import { FunList } from '../Basic';/*** Random color for formula cell input@@ -524,9 +524,8 @@ export class CellInputHandler {if (i === funcstack.length - 1) {// function_str += str;if (_this.iscelldata(str.trim())) {- function_str += `<span class="universheet-formula-functionrange-cell" rangeindex="${_this.functionHTMLIndex}" dir="auto" style="color:${- LUCKY_COLOR[_this.functionHTMLIndex]- };">${str}</span>`;+ function_str += `<span class="universheet-formula-functionrange-cell" rangeindex="${_this.functionHTMLIndex}" dir="auto" style="color:${LUCKY_COLOR[_this.functionHTMLIndex]+ };">${str}</span>`;_this.functionHTMLIndex++;} else if (matchConfig.dquote > 0) {function_str += `${str}</span>`;@@ -697,10 +696,10 @@ export class CellInputHandler {searchFunction($editer: HTMLElement) {let _this = this;- const locale = 'zh';+ // const locale = 'zh';this.formula = [];- let functionlist = lang[`${locale}`];+ // let functionlist = lang[`${locale}`];let $cell = _this.getrangeseleciton();@@ -725,10 +724,12 @@ export class CellInputHandler {};let result_i = 0;- for (let i = 0; i < functionlist.length; i++) {- let item = functionlist[i];+ for (let i = 0; i < FunList.length; i++) {+ let item = FunList[i];let n = item.n;+ if (!n) continue;+if (n === searchtxt) {result.f.unshift(item);result_i++;@@ -754,11 +755,11 @@ export class CellInputHandler {helpFunctionExe($editer: HTMLElement, currSelection: HTMLSpanElement) {let _this = this;- const locale = 'zh';- let functionlist = lang[`${locale}`];if (document.querySelectorAll('#universheet-formula-help-c').length === 0) {- for (let i = 0; i < functionlist.length; i++) {- _this.functionlistPosition[functionlist[i].n] = i;+ for (let i = 0; i < FunList.length; i++) {+ const n = FunList[i].n;+ if (!n) continue;+ _this.functionlistPosition[n] = i;}}if (!currSelection) {diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsindex 4dd41e5ccb..d5a2e33888 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts@@ -20,6 +20,8 @@ export class FormulaController {private _sheetPlugin: SheetPlugin;+ private _sheetUIPlugin: SheetUIPlugin;+private _activeSheetId: string;private _arrayFormulaLineControls: ArrayFormulaLineControl[] = [];@@ -31,9 +33,11 @@ export class FormulaController {this._sheetPlugin = this._plugin.getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);+ this._sheetUIPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);+this._activeSheetId = this._sheetPlugin.getWorkbook().getActiveSheet().getSheetId();- this._initRegisterComponent();+ // this._initRegisterComponent();// this._sheetPlugin.addToolButton({// name: FORMULA_PLUGIN_NAME,diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.tsindex 1cf06aa6fa..45632fe68f 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts@@ -2,7 +2,7 @@ import { $$ } from '@univerjs/base-ui';import { SheetPlugin } from '@univerjs/base-sheets';import { KeyCode, PLUGIN_NAMES, SheetContext } from '@univerjs/core';import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';-import { FORMULA_PLUGIN_NAME } from '../Basic';+import { FORMULA_PLUGIN_NAME, FunList } from '../Basic';import { FormulaPlugin } from '../FormulaPlugin';import { HelpFunction, SearchFunction } from '../View/UI/FormulaPrompt';import { CellInputHandler } from './CellInputHandler';@@ -31,12 +31,11 @@ export class FormulaPromptController {this._sheetUIPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);- this._initialize();this._initRegisterComponent();+ this._initialize();}private _initRegisterComponent() {- console.info('searchFunction====11');this._sheetUIPlugin.getAppUIController().getSheetContainerController()@@ -47,15 +46,21 @@ export class FormulaPromptController {.getSheetContainerController().getMainSlotController().getSlot(FORMULA_PLUGIN_NAME + SearchFunction.name);-- console.info('searchFunction====', searchFunction);+ this._searchFunction = searchFunction;});this._sheetUIPlugin.getAppUIController().getSheetContainerController().getMainSlotController()- .addSlot(FORMULA_PLUGIN_NAME + HelpFunction.name, HelpFunction);+ .addSlot(FORMULA_PLUGIN_NAME + HelpFunction.name, HelpFunction, () => {+ const helpFunction = this._sheetUIPlugin+ .getAppUIController()+ .getSheetContainerController()+ .getMainSlotController()+ .getSlot(FORMULA_PLUGIN_NAME + HelpFunction.name);+ this._helpFunction = helpFunction;+ });}private _initialize() {@@ -135,7 +140,9 @@ export class FormulaPromptController {// helpFormulaActive: false,// });} else if (helpFormula[0]) {- this._helpFunction.updateState(true, helpFormula[1] as number, (helpFormula[0] as string).toUpperCase(), position);+ const functionName = (helpFormula[0] as string).toUpperCase();+ const functionInfo = FunList.find((item: any) => item.n === functionName) || {};+ this._helpFunction.updateState(true, helpFormula[1] as number, functionInfo, position);this._searchFunction.updateState(false);// this.setState({@@ -174,15 +181,5 @@ export class FormulaPromptController {}}});-- this._plugin.getObserver('onSearchFunctionDidMountObservable')!.add((component) => {- this._searchFunction = component;- console.log('get search function', component);- });- this._plugin.getObserver('onHelpFunctionDidMountObservable')!.add((component) => {- this._helpFunction = component;-- console.log('get help function', component);- });}}diff --git a/packages/sheets-plugin-formula/src/Controller/locale/en.ts b/packages/sheets-plugin-formula/src/Controller/locale/en.tsdeleted file mode 100644index cd21a0a093..0000000000--- a/packages/sheets-plugin-formula/src/Controller/locale/en.ts+++ /dev/null@@ -1,60 +0,0 @@-export const en = [- {- n: 'SUM',- t: 0,- d: 'Returns the sum of a series of numbers and/or cells.',- a: 'Sum of a series of numbers and/or cells.',- m: [1, 255],- p: [- {- name: 'value1',- detail: 'The first number or range to add together.',- example: 'A2:A100',- require: 'm',- repeat: 'n',- type: 'rangeAll',- },- {- name: 'value2',- detail: 'Additional numbers or ranges to add to `value1`.',- example: '2',- require: 'o',- repeat: 'y',- type: 'rangeAll',- },- ],- },- {- n: 'SUBTOTAL',- t: 0,- d: 'Returns a subtotal for a vertical range of cells using a specified aggregation function.',- a: 'Subtotal for a range using a specific function.',- m: [2, 256],- p: [- {- name: 'function_code',- detail: 'The function to use in subtotal aggregation.',- example: '1',- require: 'm',- repeat: 'n',- type: 'rangeNumber',- },- {- name: 'range1',- detail: 'The first range over which to calculate a subtotal.',- example: 'A2:A5',- require: 'm',- repeat: 'n',- type: 'range',- },- {- name: 'range2',- detail: 'Additional ranges over which to calculate subtotals.',- example: 'B2:B8',- require: 'o',- repeat: 'y',- type: 'range',- },- ],- },-];diff --git a/packages/sheets-plugin-formula/src/Controller/locale/index.ts b/packages/sheets-plugin-formula/src/Controller/locale/index.tsdeleted file mode 100644index 60434497fe..0000000000--- a/packages/sheets-plugin-formula/src/Controller/locale/index.ts+++ /dev/null@@ -1,4 +0,0 @@-import { zh } from './zh';-import { en } from './en';--export const lang = { zh, en };diff --git a/packages/sheets-plugin-formula/src/Controller/locale/zh.ts b/packages/sheets-plugin-formula/src/Controller/locale/zh.tsdeleted file mode 100644index 244c3dc7cf..0000000000--- a/packages/sheets-plugin-formula/src/Controller/locale/zh.ts+++ /dev/null@@ -1,60 +0,0 @@-export const zh = [- {- n: 'SUM',- t: 0,- d: '返回一组数值和/或单元格的总和。',- a: '返回一组数值和/或单元格的总和。',- m: [1, 255],- p: [- {- name: '值1',- detail: '要相加的第一个数值或范围。',- example: 'A2:A100',- require: 'm',- repeat: 'n',- type: 'rangeAll',- },- {- name: '值2',- detail: '[可选] - 要相加的其他数值或范围。',- example: '2',- require: 'o',- repeat: 'y',- type: 'rangeAll',- },- ],- },- {- n: 'SUBTOTAL',- t: 0,- d: '使用指定的汇总函数,返回一系列纵向单元格的分类汇总。',- a: '使用指定的汇总函数',- m: [2, 256],- p: [- {- name: '函数代码',- detail: '用于计算分类汇总的函数。\n\n1代表AVERAGE\n\n2代表COUNT\n\n3代表COUNTA\n\n4代表MAX\n\n5代表MIN\n\n6代表PRODUCT\n\n7代表STDEV\n\n8代表STDEVP\n\n9代表SUM\n\n10代表VAR\n\n11代表VARP\n\n通过在这些2位代码前附加10(对于1位代码)或1(对于2位代码),可以将隐藏值忽略。例如,102代表忽略隐藏单元格的COUNT,而110则代表忽略隐藏值的VAR。',- example: '1',- require: 'm',- repeat: 'n',- type: 'rangeNumber',- },- {- name: '范围1',- detail: '要计算分类汇总的第一个范围。',- example: 'A2:A5',- require: 'm',- repeat: 'n',- type: 'range',- },- {- name: '范围2',- detail: '[可选] - 要计算分类汇总的其他范围。',- example: 'B2:B8',- require: 'o',- repeat: 'y',- type: 'range',- },- ],- },-];diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsxindex c52f6a84de..de52eef35b 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx@@ -1,25 +1,7 @@import { Component } from '@univerjs/base-ui';-import { FORMULA_PLUGIN_NAME } from '../../../Basic';-import { lang } from '../../../Controller/locale';-import { FormulaPlugin } from '../../../FormulaPlugin';+import { FormulaParamType, FormulaType } from '../../../Basic';import styles from './index.module.less';-type Formula = {- n: string;- t: number;- d: string;- a: string;- m: number[];- p: Array<{- name: string;- detail: string;- example: string;- require: string;- repeat: string;- type: string;- }>;-};-interface IProps {funName: any;paramIndex: number;@@ -27,10 +9,7 @@ interface IProps {interface IState {activeIndex: number;- lang: string;- locale: [];- formula: [];- functionInfo: any;+ functionInfo: FormulaType;helpFormulaActive: boolean;position: {left: number;@@ -42,10 +21,7 @@ export class HelpFunction extends Component<IProps, IState> {initialize() {this.state = {activeIndex: 0,- lang: '',- locale: [],- formula: [],- functionInfo: null,+ functionInfo: {},helpFormulaActive: false,position: {left: 0,@@ -54,17 +30,11 @@ export class HelpFunction extends Component<IProps, IState> {};}- componentWillMount() {- this.setLocale();- }+ componentWillMount() {}- componentDidMount() {- const plugin = this._context.getPluginManager().getPluginByName<FormulaPlugin>(FORMULA_PLUGIN_NAME)!;- plugin.getObserver('onHelpFunctionDidMountObservable')!.notifyObservers(this);- }+ componentDidMount() {}- updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionName: string = '', position = { left: 0, top: 0 }) {- const functionInfo = this.state.formula.find((item: any) => item.n === functionName) || {};+ updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionInfo: FormulaType = {}, position = { left: 0, top: 0 }) {this.setState({helpFormulaActive,functionInfo,@@ -77,15 +47,6 @@ export class HelpFunction extends Component<IProps, IState> {return this.state;}- setLocale() {- const locale = this._context.getLocale().options.currentLocale as string;- this.setState({- lang: locale,- formula: lang[`${locale}`],- functionInfo: lang[`${locale}`][0],- });- }-render(props: IProps, state: IState) {const { activeIndex, functionInfo, helpFormulaActive, position } = state;@@ -98,14 +59,19 @@ export class HelpFunction extends Component<IProps, IState> {<Help title={functionInfo.n} value={functionInfo.p} type="name" active={activeIndex} /></div><div className={styles.helpFunctionContent}>- <div>示例</div>+ <div>{this.getLocale('formula.formulaMore.helpExample')}</div><Help title={functionInfo.n} value={functionInfo.p} type="example" active={activeIndex} />- <Params title="摘要" value={functionInfo.d} />+ <Params title={this.getLocale('formula.formulaMore.helpAbstract')} value={this.getLocale(functionInfo.d)} /><>{functionInfo &&functionInfo.p &&- functionInfo.p.map((item: any, i: number) => (- <Params className={activeIndex === i ? styles.helpFunctionActive : ''} title={item.name} value={item.detail} active={activeIndex} />+ functionInfo.p.map((item: FormulaParamType, i: number) => (+ <Params+ className={activeIndex === i ? styles.helpFunctionActive : ''}+ title={this.getLocale(item.name)}+ value={this.getLocale(item.detail)}+ active={activeIndex}+ />))}</></div>@@ -113,19 +79,46 @@ export class HelpFunction extends Component<IProps, IState> {);}}-const Params = (props: any) => (++interface IParamsProps {+ className?: string;+ title?: string;+ value?: string;+ active?: number;+}++interface IParamsState {}++const Params = (props: IParamsProps) => (<div className={`${styles.helpFunctionContentParams} ${props.className}`}><div className={styles.helpFunctionContentTitle}>{props.title}</div><div className={styles.helpFunctionContentDetail}>{props.value}</div></div>);-const Help = (props: any) => (- <div>- <span>- {props.title}- {'('}- </span>- {props.value && props.value.map((item: any, i: number) => <span className={props.active === i ? styles.helpFunctionActive : ''}>{item[`${props.type}`]},</span>)}- <span>{')'}</span>- </div>-);++interface IHelpProps {+ title?: string;+ value?: FormulaParamType[];+ type: string;+ active: number;+}++interface IHelpState {}++class Help extends Component<IHelpProps, IHelpState> {+ render(props: IHelpProps, state: IHelpState) {+ return (+ <div>+ <span>+ {props.title}+ {'('}+ </span>+ {props.value &&+ props.value.map((item: FormulaParamType, i: number) => (+ <span className={props.active === i ? styles.helpFunctionActive : ''}>{this.getLocale(item[`${props.type}`])},</span>+ ))}+ <span>{')'}</span>+ </div>+ );+ }+}diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsxindex b87be0b7db..8f5b3b92d1 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx@@ -34,9 +34,7 @@ export class SearchFunction extends Component<IProps, IState> {};}- componentDidMount() {- this.props.getComponent?.(this);- }+ componentDidMount() {}componentWillUpdate(nextProps: any) {}@@ -67,7 +65,7 @@ export class SearchFunction extends Component<IProps, IState> {{formula.map((item: any, i: number) => (<li className={selectIndex === i ? styles.searchFunctionActive : ''}><div className={styles.formulaName}>{item.n}</div>- <div className={styles.formulaDetail}>{item.a}</div>+ <div className={styles.formulaDetail}>{this.getLocale(item.d)}</div></li>))}</ul>diff --git a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsxindex c7b5f1e6d6..c43dc3b92d 100644--- a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx+++ b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx@@ -32,14 +32,10 @@ export class Slot extends Component<BaseComponentProps, IState> {getRender(slotGroup: Map<string, any>) {const group: JSX.Element[] = [];- slotGroup.forEach((k) => {+ slotGroup.forEach((v, k) => {const Slot = slotGroup.get(k);- group.push(<Slot ref={(ele: any) => this.refMap.set(k, ele)}></Slot>);+ Slot && group.push(<Slot ref={(ele: any) => this.refMap.set(k, ele)}></Slot>);});- // for (let k in slotGroup) {- // const A = slotGroup.get(k);- // group.push(<A ref={(ele: any) => this.refMap.set(k, ele)}></A>);- // }return group;}