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
style(sheets-plugin-formula): fix ts error (#196)
Dushusir92c54ce8ec0b
diff --git a/packages/sheets-plugin-formula/index.html b/packages/sheets-plugin-formula/index.htmldeleted file mode 100644index dfd279c1b4..0000000000--- a/packages/sheets-plugin-formula/index.html+++ /dev/null@@ -1,18 +0,0 @@-<!DOCTYPE html>-<html lang="en">--<head>- <meta charset="UTF-8" />- <link rel="icon" type="image/svg+xml" href="favicon.svg" />- <meta name="viewport" content="width=device-width, initial-scale=1.0" />- <title>UniverSheet</title>-</head>--<body>- <div id="app"></div>- <div id="universheet-demo-up"></div>- <div id="universheet-demo-down"></div>- <script type="module" src="/src/main.tsx"></script>-</body>--</html>\ No newline at end of filediff --git a/packages/sheets-plugin-formula/src/Basics/Interfaces/IFormula.ts b/packages/sheets-plugin-formula/src/Basics/Interfaces/IFormula.tsindex 863ecc1335..811eb9fb01 100644--- a/packages/sheets-plugin-formula/src/Basics/Interfaces/IFormula.ts+++ b/packages/sheets-plugin-formula/src/Basics/Interfaces/IFormula.ts@@ -1,5 +1,4 @@import { FormulaDataType } from '@univerjs/base-formula-engine';-import { ComponentChildren } from '@univerjs/base-ui';import { FormulaType } from '../Const/FunctionList';@@ -65,5 +64,5 @@ export interface SearchFormulaModalData {titleLocale?: string;onCancel?: () => void;children: ICustomComponent;- modal?: ComponentChildren; // 渲染的组件+ modal?: React.ReactNode; // 渲染的组件}diff --git a/packages/sheets-plugin-formula/src/Basics/Register/FormulaCellEditExtension.ts b/packages/sheets-plugin-formula/src/Basics/Register/FormulaCellEditExtension.tsindex d08f066c6a..72dbf44239 100644--- a/packages/sheets-plugin-formula/src/Basics/Register/FormulaCellEditExtension.ts+++ b/packages/sheets-plugin-formula/src/Basics/Register/FormulaCellEditExtension.ts@@ -1,6 +1,5 @@import { BaseCellEditExtension, BaseCellEditExtensionFactory, ICell } from '@univerjs/base-ui';import { ICurrentUniverService, ISelectionRange, Nullable } from '@univerjs/core';-import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';import { Inject, Injector } from '@wendellhu/redi';import { FormulaController } from '../../Controller/FormulaController';@@ -21,8 +20,7 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactor@Inject(Injector) private readonly _sheetInjector: Injector,@ICurrentUniverService private readonly _currentUniverService: ICurrentUniverService,@Inject(FormulaController) private readonly _formulaController: FormulaController,- @Inject(FormulaPromptController) private readonly _formulaPromptController: FormulaPromptController,- @Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController+ @Inject(FormulaPromptController) private readonly _formulaPromptController: FormulaPromptController) {super();}@@ -93,7 +91,7 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactorif (row >= startRow && row < endRow && column >= startColumn && column < endColumn) {formula = '';// .getFormulaBarUIController().getFormulaBar().setFormulaContent(str);- this._sheetContainerUIController.getFormulaBarUIController().getFormulaBar().setFormulaContent('');+ // this._sheetContainerUIController.getFormulaBarUIController().getFormulaBar().setFormulaContent('');return false;}});diff --git a/packages/sheets-plugin-formula/src/Basics/Register/index.ts b/packages/sheets-plugin-formula/src/Basics/Register/index.tsindex 33f16a664e..6b387e1c53 100644--- a/packages/sheets-plugin-formula/src/Basics/Register/index.ts+++ b/packages/sheets-plugin-formula/src/Basics/Register/index.ts@@ -1,5 +1,4 @@// @index('./*.ts', f => `export * from '${f.path}'`)-export * from './FormulaActionExtension';export * from './FormulaCellEditExtension';export * from './FormulaCellInputExtension';// @endindexdiff --git a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.tsindex 4e443e36a0..e74f506ab8 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts@@ -1,6 +1,5 @@import { ComponentManager, SlotManager } from '@univerjs/base-ui';import { ObserverManager } from '@univerjs/core';-import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';import { Inject } from '@wendellhu/redi';import { FORMULA_PLUGIN_NAME, FunList } from '../Basics';@@ -20,7 +19,6 @@ export class FormulaPromptController {private _helpFunction: HelpFunction;constructor(- @Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController,@Inject(ObserverManager) private readonly _observerManager: ObserverManager,@Inject(ComponentManager) private _componentManager: ComponentManager,@Inject(SlotManager) private readonly _slotManager: SlotManager@@ -161,7 +159,8 @@ export class FormulaPromptController {const width = parseInt(this.richTextEle.style.minWidth);let left = parseInt(this.richTextEle.style.left);let top = parseInt(this.richTextEle.style.top) + height;- const sheetContainer = this._sheetContainerUIController.getContentRef().current;+ // const sheetContainer = this._sheetContainerUIController.getContentRef().current;+ const sheetContainer: any = null; // FIXME get container position?if (!sheetContainer) return;diff --git a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.tsindex b7db1bc00e..2a78b2031d 100644--- a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts+++ b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts@@ -1,6 +1,5 @@import { ComponentManager } from '@univerjs/base-ui';import { ISelection, ObserverManager } from '@univerjs/core';-import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';import { Inject } from '@wendellhu/redi';import {@@ -27,7 +26,6 @@ export class SearchFormulaController {private _cellRangeModalData: SearchFormulaModalData;constructor(- @Inject(SheetContainerUIController) private readonly _sheetContainerUIController: SheetContainerUIController,@Inject(ComponentManager) private readonly _componentManager: ComponentManager,@Inject(ObserverManager) private readonly _observerManager: ObserverManager) {@@ -143,16 +141,16 @@ export class SearchFormulaController {}private _initRegisterComponent() {- this._sheetContainerUIController- .getMainSlotController()- .addSlot(FORMULA_PLUGIN_NAME + SearchFormulaModal.name, {- component: SearchFormulaModal,- props: {- getComponent: (ref: SearchFormulaModal) => {- this._formulaModal = ref;- },- },- });+ // this._sheetContainerUIController+ // .getMainSlotController()+ // .addSlot(FORMULA_PLUGIN_NAME + SearchFormulaModal.name, {+ // component: SearchFormulaModal,+ // props: {+ // getComponent: (ref: SearchFormulaModal) => {+ // this._formulaModal = ref;+ // },+ // },+ // });this._componentManager.register(FORMULA_PLUGIN_NAME + SearchItem.name, SearchItem);this._componentManager.register(FORMULA_PLUGIN_NAME + SearchFormulaContent.name, SearchFormulaContent);}diff --git a/packages/sheets-plugin-formula/src/Model/Action/SetFormulaRangeDataAction.ts b/packages/sheets-plugin-formula/src/Model/Action/SetFormulaRangeDataAction.tsdeleted file mode 100644index 2b729a8235..0000000000--- a/packages/sheets-plugin-formula/src/Model/Action/SetFormulaRangeDataAction.ts+++ /dev/null@@ -1,46 +0,0 @@-import { FormulaDataType } from '@univerjs/base-formula-engine';-import { ActionObservers, CommandUnit, ISheetActionData, SheetActionBase } from '@univerjs/core';--import { FormulaController } from '../../Controller/FormulaController';-import { SetFormulaRangeData } from '../Apply/SetFormulaRangeData';--export interface ISetFormulaRangeActionData extends ISheetActionData {- formulaData: FormulaDataType;-}--export class SetFormulaRangeDataAction extends SheetActionBase<- ISetFormulaRangeActionData,- ISetFormulaRangeActionData,- FormulaDataType-> {- constructor(actionData: ISetFormulaRangeActionData, commandUnit: CommandUnit, observers: ActionObservers) {- super(actionData, commandUnit, observers);- this._doActionData = {- ...actionData,- };- this._oldActionData = {- ...actionData,- formulaData: this.do(),- };- }-- do(): FormulaDataType {- return this.redo();- }-- redo(): FormulaDataType {- const { _workbook } = this;- const { formulaData, injector } = this._doActionData;- return SetFormulaRangeData(_workbook, formulaData, injector!.get(FormulaController));- }-- undo(): void {- const { _workbook } = this;- const { formulaData, injector } = this._oldActionData;- SetFormulaRangeData(_workbook, formulaData, injector!.get(FormulaController));- }-- validate(): boolean {- return false;- }-}diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsxindex f75aa79e23..bb88eb6fb0 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaLabel.tsx@@ -6,7 +6,7 @@ interface IProps {}export class FormulaLabel extends Component<IProps> {- render() {+ override render() {// const SumIcon = this._render.renderFunction('SumIcon');const { label } = this.props;diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsxindex 718a0f08a1..0dfe7f11bb 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/HelpFunction.tsx@@ -72,7 +72,7 @@ export class HelpFunction extends Component<IProps, IState> {return this.contentRef;}- render() {+ override render() {const { activeIndex, functionInfo, helpFormulaActive, position } = this.state;return (@@ -143,7 +143,7 @@ interface IHelpProps {interface IHelpState {}class Help extends Component<IHelpProps, IHelpState> {- render() {+ override render() {return (<div><span>diff --git a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsxindex e003fad34a..f8e4de287c 100644--- a/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/FormulaPrompt/SearchFunction.tsx@@ -50,8 +50,6 @@ export class SearchFunction extends Component<IProps, IState> {override componentWillUpdate(nextProps: any) {}- onKeyDown(event: Event) {}-getContentRef() {return this.contentRef;}@@ -76,12 +74,11 @@ export class SearchFunction extends Component<IProps, IState> {return this.state;}- render() {+ override render() {const { selectIndex, formula, searchActive, position } = this.state;return (<ulclassName={styles.searchFunction}- onKeyDown={this.onKeyDown.bind(this)}style={{display: searchActive ? 'block' : 'none',position: 'absolute',diff --git a/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx b/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsxindex b9a568fd31..3303a6fd9d 100644--- a/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/IfGenerate/ifGenerate.tsx@@ -1,10 +1,9 @@import {AppContext,- BaseButtonProps,BaseModalProps,BaseSelectProps,Button,- FunctionComponent,+ IBaseButtonProps,Modal,Select,} from '@univerjs/base-ui';@@ -17,7 +16,7 @@ import styles from './index.module.less';interface IProps {visible: boolean;onOk: () => void;- onCancel: (e: Event) => void;+ onCancel: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void;config: IConfig;}@@ -30,11 +29,11 @@ interface IState {class IfGenerate extends Component<IProps, IState> {static override contextType = AppContext;- Button: FunctionComponent<BaseButtonProps>;+ Button: IBaseButtonProps;- Modal: FunctionComponent<BaseModalProps>;+ Modal: BaseModalProps;- Select: FunctionComponent<BaseSelectProps>;+ Select: BaseSelectProps;private _localeObserver: Nullable<Observer<Workbook>>;@@ -58,29 +57,28 @@ class IfGenerate extends Component<IProps, IState> {*/override UNSAFE_componentWillMount() {this.setLocale();- this._localeObserver = this.context.observerManager- .requiredObserver('onAfterChangeUILocaleObservable', 'core')- ?.add(() => {- this.setLocale();- });+ const observerManager = (this.context as any).injector!.get('observerManager');+ this._localeObserver = observerManager.requiredObserver('onAfterChangeUILocaleObservable', 'core')?.add(() => {+ this.setLocale();+ });}/*** destory*/override componentWillUnmount() {- this.context.observerManager- .requiredObserver('onAfterChangeUILocaleObservable', 'core')- ?.remove(this._localeObserver);+ const observerManager = (this.context as any).injector!.get('observerManager');+ observerManager.requiredObserver('onAfterChangeUILocaleObservable', 'core')?.remove(this._localeObserver);}setLocale() {- const locale = this.context.localeService.getLocale().get('formula');+ const localeService = (this.context as any).injector!.get('localeService');+ const locale = localeService.getLocale().get('formula');this.setState({ locale });}- render() {+ override render() {const { locale } = this.state;return (<Modaldiff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsxindex 5a88d8d425..e47b49189f 100644--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaContent.tsx@@ -15,7 +15,7 @@ interface IState {}export class SearchFormulaContent extends Component<IProps, IState> {- functionListRef = createRef();+ functionListRef = createRef<HTMLDivElement>();constructor(props: IProps) {super(props);@@ -77,12 +77,14 @@ export class SearchFormulaContent extends Component<IProps, IState> {}highLightLi(index: number) {- const item = this.functionListRef.current.querySelectorAll(`.${styles.functionListsItem}`);+ const item = this.functionListRef.current?.querySelectorAll(`.${styles.functionListsItem}`);+ if (!item) return;+for (let i = 0; i < item.length; i++) {item[i].classList.remove(styles.functionListsItemActive);}- item[index].classList.add(styles.functionListsItemActive);- item[index].click();+ (item[index] as HTMLElement).classList.add(styles.functionListsItemActive);+ (item[index] as HTMLElement).click();}handleClick(item: FormulaType, index: number) {@@ -119,7 +121,7 @@ export class SearchFormulaContent extends Component<IProps, IState> {return functionList as FormulaType[];}- render() {+ override render() {const { functionList } = this.state;return (diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsxindex 1828867279..5207759b2a 100644--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchFormulaModal.tsx@@ -1,4 +1,4 @@-import { BaseComponentProps, Modal } from '@univerjs/base-ui';+import { BaseComponentProps, Modal, ModalButtonGroup } from '@univerjs/base-ui';import { Component } from 'react';import { SearchFormulaModalData } from '../../../Basics/Interfaces/IFormula';@@ -26,7 +26,7 @@ export class SearchFormulaModal extends Component<IProps, IState> {}setModal(modalData: SearchFormulaModalData[]) {- const componentManager = this.context.componentManager;+ const componentManager = (this.context as any).injector!.get('componentManager');modalData.forEach((item) => {const Label = componentManager?.get(item.children.name!);@@ -41,7 +41,7 @@ export class SearchFormulaModal extends Component<IProps, IState> {});}- render() {+ override render() {const { modalData } = this.state;// Set Provider for entire Containerreturn (@@ -55,7 +55,7 @@ export class SearchFormulaModal extends Component<IProps, IState> {mask={item.mask}title={item.label?.funParams.n}visible={item.show}- group={item.group}+ group={item.group as ModalButtonGroup[]} // FIXME type erroronCancel={item.onCancel}>{item.modal}diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsxindex 7202e7caef..61e90d5ada 100644--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx+++ b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/SearchItem.tsx@@ -32,6 +32,9 @@ export class SearchItem extends Component<IProps, IState> {override componentDidMount() {const { funParams } = this.props;const description = funParams?.funParams.p?.[0];++ if (!description) return;+this.setState({description,});@@ -41,6 +44,8 @@ export class SearchItem extends Component<IProps, IState> {const { funParams } = this.props;const description = funParams?.funParams.p?.[index];+ if (!description) return;+this.setState({description,index,@@ -55,7 +60,7 @@ export class SearchItem extends Component<IProps, IState> {});}- render() {+ override render() {const { funParams, calc } = this.props;const { description, rangeList } = this.state;@@ -80,6 +85,7 @@ export class SearchItem extends Component<IProps, IState> {) as unknown as string}value={rangeList[index]}+ onClick={() => {}}/></div><span>={'{}'}</span>diff --git a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.css b/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.cssdeleted file mode 100644index bfa67c614c..0000000000--- a/packages/sheets-plugin-formula/src/View/UI/SearchFormulaModal/index.module.css+++ /dev/null@@ -1,88 +0,0 @@-.function-modal {- font-size: 14px;-}-.function-modal > div {- margin-bottom: 10px;-}-.function-modal .function-search input {- width: 100%;- height: 24px;- line-height: 24px;- border: 1px solid #d4d4d4;- padding: 0 10px;- box-sizing: border-box;- font-size: 12px;-}-.function-modal .function-select {- display: flex;- align-items: center;-}-.function-modal .function-select .function-label {- margin-bottom: 0;-}-.function-modal .function-select .function-selector {- border: 1px solid var(--border-color-base);- border-radius: var(--border-radius-base);-}-.function-modal .function-select .function-selector .select-button {- margin: 0;-}-.function-modal .function-list .function-lists {- width: 100%;- height: 170px;- border: 1px solid #d4d4d4;- overflow-y: auto;- margin: 0;- padding: 0;-}-.function-modal .function-list .function-lists .function-lists-item {- padding: 5px;- border-bottom: 1px solid #d4d4d4;- cursor: pointer;- list-style: none;-}-.function-modal .function-list .function-lists .function-lists-item-active {- background-color: var(--primary-color);- color: #fff;-}-.function-modal .function-list .function-lists .function-lists-item:hover {- background-color: var(--primary-color-hover);- color: #fff;-}-.function-modal .function-label {- margin-right: 10px;- margin-bottom: 10px;-}-.function-param-modal .function-param-list {- border: 1px solid;- padding: 0.5 em;-}-.function-param-modal .function-param-list > div {- display: flex;- padding: 5px 0;-}-.function-param-modal .function-param-list > div > span {- flex: 1;-}-.function-param-modal .function-param-list > div > span:first-child {- text-align: right;-}-.function-param-modal .function-param-list > div input {- flex: 1;-}-.function-param-modal .function-param-desc {- margin: 1em 0;-}-.function-param-modal .function-param-desc .function-param-desc-details {- padding: 10px;- height: 100px;- overflow: auto;- margin-top: 1em;- box-sizing: border-box;- font-size: 12px;-}-.function-btn .btn {- padding: 5px;- line-height: 1;- font-size: 14px;-}