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): formula prompt
Dushusir86969524208e
diff --git a/packages/base-ui/src/Basics/CSS/Skin/dark.module.less b/packages/base-ui/src/Basics/CSS/Skin/dark.module.lessindex 7a83f1a3a1..57b56f2f93 100644--- a/packages/base-ui/src/Basics/CSS/Skin/dark.module.less+++ b/packages/base-ui/src/Basics/CSS/Skin/dark.module.less@@ -54,6 +54,7 @@--primary-color-hover: @primary-color-hover;--link-color: @link-color;--bg: @bg;+ --bg-hover: @bg-hover;--font-size: @font-size-base;--heading-color: @heading-color;--text-color: @text-color;diff --git a/packages/base-ui/src/Basics/CSS/Skin/default.module.less b/packages/base-ui/src/Basics/CSS/Skin/default.module.lessindex 373d1729fc..a81dc7668f 100644--- a/packages/base-ui/src/Basics/CSS/Skin/default.module.less+++ b/packages/base-ui/src/Basics/CSS/Skin/default.module.less@@ -54,6 +54,7 @@--primary-color-hover: @primary-color-hover;--link-color: @link-color;--bg: @bg;+ --bg-hover: @bg-hover;--font-size: @font-size-base;--heading-color: @heading-color;--text-color: @text-color;diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.tsindex 45632fe68f..472e30b295 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts@@ -1,4 +1,4 @@-import { $$ } from '@univerjs/base-ui';+import { $$, getRefElement } 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';@@ -124,41 +124,64 @@ export class FormulaPromptController {const formula = this.cellInputHandler.getFormula();let helpFormula = this.cellInputHandler.getHelpFormula();- const left = parseInt(this.richTextEle.style.left);- const top = parseInt(this.richTextEle.style.top) + parseInt(this.richTextEle.style.minHeight);+ let height = parseInt(this.richTextEle.style.minHeight);+ let width = parseInt(this.richTextEle.style.minWidth);+ let left = parseInt(this.richTextEle.style.left);+ let top = parseInt(this.richTextEle.style.top) + height;++ // Get the viewport width/height of the Main SheetContainer+ const sheetContainer = getRefElement(this._sheetUIPlugin.getAppUIController().getSheetContainerController().getContentRef());+ const screenW = sheetContainer.offsetWidth;+ const screenH = sheetContainer.offsetHeight;++ // Parse out a reasonable display position, and the list cannot be hiddenconst position = {left,top,};+ const getPosition = (component: SearchFunction | HelpFunction) => {+ // Get the width/height of the list+ const searchFunctionEle = getRefElement(component.getContentRef());+ const rootW = searchFunctionEle.offsetWidth;+ // const rootW = this._searchFunction?.base?.offsetWidth;+ const rootH = searchFunctionEle.offsetHeight;++ // right is true, indicating that the width from the lower left corner of the cell to the right border of the browser can hold the SearchFunction. Otherwise, the component is placed on the left.+ // bottom is true, indicating that the height from the lower left corner of the cell to the lower border of the browser can place the SearchFunction. Otherwise, the component is put on top.+ const right = screenW - left > rootW;+ const bottom = screenH - top > rootH;++ if (!right) {+ left -= rootW - width;+ }+ if (!bottom) {+ top -= rootH + height;+ }++ return {+ left,+ top,+ };+ };+if (formula[0]) {- this._searchFunction.updateState(true, formula, 0, position);+ this._searchFunction.updateState(true, formula, 0, position, () => {+ const position = getPosition(this._searchFunction);+ this._searchFunction.updateState(true, formula, 0, position);+ });this._helpFunction.updateState(false);- // this.setState({- // formula,- // searchActive: true,- // helpFormulaActive: false,- // });} else if (helpFormula[0]) {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._helpFunction.updateState(true, helpFormula[1] as number, functionInfo, position, () => {+ const position = getPosition(this._helpFunction);+ this._helpFunction.updateState(true, helpFormula[1] as number, functionInfo, position);+ });this._searchFunction.updateState(false);-- // this.setState({- // formulaName: (helpFormula[0] as string).toUpperCase(),- // paramIndex: helpFormula[1] as number,- // helpFormulaActive: true,- // searchActive: false,- // });} else {this._searchFunction.updateState(false, formula);this._helpFunction.updateState(false);- // this.setState({- // formula,- // searchActive: false,- // helpFormulaActive: false,- // });}}const value = this.cellInputHandler.getInputValue();@@ -171,12 +194,6 @@ export class FormulaPromptController {if (searchFunctionState.searchActive) {const func = searchFunctionState.formula[searchFunctionState.selectIndex] as any;this.cellInputHandler.searchFunctionEnter(func.n);- // this.setState({- // formulaName: this.state.formula[this.state.funIndex].n,- // paramIndex: 0,- // helpFormulaActive: true,- // searchActive: false,- // });}}}diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsxindex de52eef35b..1890ab575a 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx@@ -1,4 +1,4 @@-import { Component } from '@univerjs/base-ui';+import { Component, createRef } from '@univerjs/base-ui';import { FormulaParamType, FormulaType } from '../../../Basic';import styles from './index.module.less';@@ -18,6 +18,8 @@ interface IState {}export class HelpFunction extends Component<IProps, IState> {+ contentRef = createRef<HTMLDivElement>();+initialize() {this.state = {activeIndex: 0,@@ -34,19 +36,26 @@ export class HelpFunction extends Component<IProps, IState> {componentDidMount() {}- updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionInfo: FormulaType = {}, position = { left: 0, top: 0 }) {- this.setState({- helpFormulaActive,- functionInfo,- activeIndex,- position,- });+ updateState(helpFormulaActive: boolean, activeIndex: number = 0, functionInfo: FormulaType = {}, position = { left: 0, top: 0 }, cb?: () => void) {+ this.setState(+ {+ helpFormulaActive,+ functionInfo,+ activeIndex,+ position,+ },+ cb+ );}getState() {return this.state;}+ getContentRef() {+ return this.contentRef;+ }+render(props: IProps, state: IState) {const { activeIndex, functionInfo, helpFormulaActive, position } = state;@@ -54,6 +63,7 @@ export class HelpFunction extends Component<IProps, IState> {<divclassName={styles.helpFunction}style={{ display: helpFormulaActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}+ ref={this.contentRef}><div class={styles.helpFunctionTitle}><Help title={functionInfo.n} value={functionInfo.p} type="name" active={activeIndex} />diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsxindex 8f5b3b92d1..61036657c6 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx@@ -1,4 +1,4 @@-import { BaseComponentProps, Component } from '@univerjs/base-ui';+import { BaseComponentProps, Component, createRef } from '@univerjs/base-ui';import styles from './index.module.less';interface IProps extends BaseComponentProps {}@@ -18,6 +18,8 @@ interface IState {}export class SearchFunction extends Component<IProps, IState> {+ contentRef = createRef<HTMLUListElement>();+initialize() {this.state = {lang: '',@@ -40,14 +42,18 @@ export class SearchFunction extends Component<IProps, IState> {onKeyDown(event: Event) {}+ getContentRef() {+ return this.contentRef;+ }+/**** @param searchActive* @param formula* @param selectIndex*/- updateState(searchActive: boolean, formula: [] = [], selectIndex: number = 0, position = { left: 0, top: 0 }) {- this.setState({ searchActive, formula, selectIndex, position });+ updateState(searchActive: boolean, formula: [] = [], selectIndex: number = 0, position = { left: 0, top: 0 }, cb?: () => void) {+ this.setState({ searchActive, formula, selectIndex, position }, cb);}getState() {@@ -61,6 +67,7 @@ export class SearchFunction extends Component<IProps, IState> {className={styles.searchFunction}onKeyDown={this.onKeyDown.bind(this)}style={{ display: searchActive ? 'block' : 'none', position: 'absolute', left: `${position.left}px`, top: `${position.top}px` }}+ ref={this.contentRef}>{formula.map((item: any, i: number) => (<li className={selectIndex === i ? styles.searchFunctionActive : ''}>diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/index.module.less b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/index.module.lessindex daf50e5a08..45309e9d14 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/index.module.less+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/index.module.less@@ -5,11 +5,17 @@font-size: 14px;z-index: 1003;width: 300px;+ list-style: none;+ margin: 0;+ padding: 0;+ > li {+ padding: 5px 10px;+ }.formula-detail {display: none;}.search-function-active {- background-color: aqua;+ background-color: var(--bg-hover);.formula-detail {display: block;@@ -45,6 +51,6 @@}}.help-function-active {- background-color: aqua;+ background-color: #fff9b2;}}