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
xiugai
tonytonychopper1239e2d51ace17c
diff --git a/examples/univer-sheet-ts/package.json b/examples/univer-sheet-ts/package.jsonindex ed44990cc7..273ebeaafa 100644--- a/examples/univer-sheet-ts/package.json+++ b/examples/univer-sheet-ts/package.json@@ -50,7 +50,8 @@"@univerjs/sheets-plugin-formula": "workspace:^0.0.1","@univerjs/sheets-plugin-import-xlsx": "workspace:^0.0.1","@univerjs/sheets-plugin-numfmt": "workspace:^0.0.1",+ "@univerjs/sheets-plugin-find": "workspace:^0.0.1","@univerjs/ui-plugin-sheets": "workspace:^0.0.1","preact": "^10.12.1"}-}\ No newline at end of file+}diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex fd7be3883b..f4440350af 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -2,12 +2,7 @@ import { UniverSheet, UniverDoc, UniverSlide, Univer } from '@univerjs/core';import { RenderEngine } from '@univerjs/base-render';import { SheetPlugin } from '@univerjs/base-sheets';import { SheetUIPlugin } from '@univerjs/ui-plugin-sheets';-import {- DEFAULT_FORMULA_DATA,- DEFAULT_FORMULA_DATA_DEMO,- DEFAULT_FORMULA_DATA_DEMO1,- FormulaPlugin,-} from '@univerjs/sheets-plugin-formula';+import { DEFAULT_FORMULA_DATA, DEFAULT_FORMULA_DATA_DEMO, DEFAULT_FORMULA_DATA_DEMO1, FormulaPlugin } from '@univerjs/sheets-plugin-formula';import { NumfmtPlugin } from '@univerjs/sheets-plugin-numfmt';import {DEFAULT_WORKBOOK_DATA,@@ -19,8 +14,8 @@ import {DEFAULT_WORKBOOK_DATA_DOWN,} from '@univerjs/common-plugin-data';import { ClipboardPlugin } from '@univerjs/sheets-plugin-clipboard';-import { BaseComponentPlugin } from '@univerjs/base-ui';import { ImportXlsxPlugin } from '@univerjs/sheets-plugin-import-xlsx';+import { FindPlugin } from '@univerjs/sheets-plugin-find';const uiDefaultConfigDemo = {container: 'universheet',@@ -68,6 +63,7 @@ univer.install(}));FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO).installTo(universheet);+FindPlugin.create().installTo(universheet);// sheets-plugin-ui univer.install(new SheetsUI)// sheets-plugin-ui univer.install(new SheetsUI// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);diff --git a/package.json b/package.jsonindex 10827d367a..256bd6b127 100644--- a/package.json+++ b/package.json@@ -28,7 +28,7 @@"postinstall": "node scripts/postinstall.js","prepare": "husky install","pre-lint": "lint-staged",- "lint": "eslint ./packages/core/src --ext .ts,.tsx",+ "lint": "eslint ./packages/cores/src --ext .ts,.tsx","lint-and-fix": "eslint ./packages/core/src --ext .ts,.tsx --fix"},"author": "DreamNum <[email protected]>",diff --git a/packages/base-ui/src/Basics/Register/CellInputRegister/CellInputExtensionManager.ts b/packages/base-ui/src/Basics/Register/CellInputRegister/CellInputExtensionManager.tsindex 7e9bba2e02..f4d7c9131e 100644--- a/packages/base-ui/src/Basics/Register/CellInputRegister/CellInputExtensionManager.ts+++ b/packages/base-ui/src/Basics/Register/CellInputRegister/CellInputExtensionManager.ts@@ -4,8 +4,19 @@ import { BaseCellInputExtension, BaseCellInputExtensionFactory } from './CellInpimport { CellInputExtensionRegister } from './CellInputExtensionRegister';export class CellInputExtensionManager {+ static register: CellInputExtensionRegister;+private _cellInputExtensionFactoryList: BaseCellInputExtensionFactory[];+ static create(): CellInputExtensionRegister {+ if (!this.register) {+ this.register = new CellInputExtensionRegister();+ this.register.initialize();+ }++ return this.register;+ }+/*** inject cell position* @param row@@ -44,15 +55,4 @@ export class CellInputExtensionManager {}return extension;}-- static register: CellInputExtensionRegister;-- static create(): CellInputExtensionRegister {- if (!this.register) {- this.register = new CellInputExtensionRegister();- this.register.initialize();- }-- return this.register;- }}diff --git a/packages/base-ui/src/Basics/Register/CellInputRegister/RegistryFactory.ts b/packages/base-ui/src/Basics/Register/CellInputRegister/RegistryFactory.tsindex deac37e549..51517f0f23 100644--- a/packages/base-ui/src/Basics/Register/CellInputRegister/RegistryFactory.ts+++ b/packages/base-ui/src/Basics/Register/CellInputRegister/RegistryFactory.ts@@ -2,6 +2,10 @@class Registry {private _data: any[] = [];+ static create() {+ return new Registry();+ }+add(dataInstance: any) {this._data.push(dataInstance);}@@ -14,10 +18,6 @@ class Registry {getData() {return this._data;}-- static create() {- return new Registry();- }}export const REGISTRY_CELL_INPUT_FACTORY = Registry.create();diff --git a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.tsindex 21f6abeb38..043956ff33 100644--- a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts+++ b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts@@ -30,21 +30,6 @@ export class DragAndDropExtensionManager {this._checkExtension(data);}- /**- * Execute when the action is matched- * @param command- * @returns- */- private _checkExtension(data: IDragAndDropData[]) {- if (!this._DragAndDropExtensionFactoryList) return false;- this._DragAndDropExtensionFactoryList.forEach((extensionFactory) => {- const extension = extensionFactory.check(data);- if (extension !== false) {- extension.execute();- }- });- }-dragResolver(evt: DragEvent) {return new Promise((resolve: (data: IDragAndDropData[]) => void, reject) => {if (!evt.dataTransfer) return;@@ -83,4 +68,19 @@ export class DragAndDropExtensionManager {resolve(dataList);});}++ /**+ * Execute when the action is matched+ * @param command+ * @returns+ */+ private _checkExtension(data: IDragAndDropData[]) {+ if (!this._DragAndDropExtensionFactoryList) return false;+ this._DragAndDropExtensionFactoryList.forEach((extensionFactory) => {+ const extension = extensionFactory.check(data);+ if (extension !== false) {+ extension.execute();+ }+ });+ }}diff --git a/packages/base-ui/src/Components/Drag/Drag.tsx b/packages/base-ui/src/Components/Drag/Drag.tsxindex f94384fc01..10695b236e 100644--- a/packages/base-ui/src/Components/Drag/Drag.tsx+++ b/packages/base-ui/src/Components/Drag/Drag.tsx@@ -20,6 +20,8 @@ interface IState {}class Drag extends Component<BaseDragProps, IState> {+ root = createRef();+initialize() {this.state = {left: '',@@ -35,8 +37,6 @@ class Drag extends Component<BaseDragProps, IState> {};}- root = createRef();-onMouseUp(e: MouseEvent) {window.removeEventListener('mousemove', this.onMouseMove);}diff --git a/packages/base-ui/src/Components/Icon/index.tsx b/packages/base-ui/src/Components/Icon/index.tsxindex af3286fb98..dc000e261e 100644--- a/packages/base-ui/src/Components/Icon/index.tsx+++ b/packages/base-ui/src/Components/Icon/index.tsx@@ -73,3 +73,4 @@ export * from './Format';export * from './Font';export * from './Cell';export * from './Text';+export * from './Sheet';diff --git a/packages/base-ui/src/Components/SearchTree/SearchTree.tsx b/packages/base-ui/src/Components/SearchTree/SearchTree.tsxindex 40613e4e78..35f37f2e92 100644--- a/packages/base-ui/src/Components/SearchTree/SearchTree.tsx+++ b/packages/base-ui/src/Components/SearchTree/SearchTree.tsx@@ -16,6 +16,8 @@ interface IState {}class SearchTree extends Component<BaseSearchTreeProps, IState> {+ input = createRef();+initialize(props: BaseSearchTreeProps) {this.state = {searchValue: '',@@ -27,8 +29,6 @@ class SearchTree extends Component<BaseSearchTreeProps, IState> {};}- input = createRef();-setLocale() {const locale = this.context.locale;diff --git a/packages/base-ui/src/Components/Ul/Ul.tsx b/packages/base-ui/src/Components/Ul/Ul.tsxindex 25623256c1..beb019d193 100644--- a/packages/base-ui/src/Components/Ul/Ul.tsx+++ b/packages/base-ui/src/Components/Ul/Ul.tsx@@ -1,6 +1,5 @@import { Component, createRef, cloneElement, VNode } from '../../Framework';-import { JSXComponent } from '../../BaseComponent';-import { BaseUlProps, UlComponent } from '../../Interfaces';+import { BaseUlProps } from '../../Interfaces';import { debounce } from '../../Utils';import * as Icon from '../Icon';import styles from './index.module.less';@@ -24,17 +23,6 @@ export class Ul extends Component<BaseUlProps, UlState> {resizeUl: any;- protected initialize(props: BaseUlProps) {- this.state = {- style: {- display: 'none',- },- posStyle: {},- };-- this.resizeUl = debounce(this.getStyle, 200);- }-filterChildren = (node: HTMLElement) => {let flag;Array.from(node.children).forEach((item) => {@@ -194,7 +182,7 @@ export class Ul extends Component<BaseUlProps, UlState> {getIcon = (item: JSX.Element | string | null | undefined) => {let icon = item;if (typeof icon === 'string' && /Icon$/.test(icon)) {- icon = Icon.IconMap[icon];+ icon = Icon[icon];}return <span className={styles.submenuArrow}>{icon}</span>;};@@ -270,10 +258,15 @@ export class Ul extends Component<BaseUlProps, UlState> {</ul>);}-}-export class UniverUl implements UlComponent {- render(): JSXComponent<BaseUlProps> {- return Ul;+ protected initialize(props: BaseUlProps) {+ this.state = {+ style: {+ display: 'none',+ },+ posStyle: {},+ };++ this.resizeUl = debounce(this.getStyle, 200);}}diff --git a/packages/base-ui/src/Interfaces/Checkbox.ts b/packages/base-ui/src/Interfaces/Checkbox.tsindex 6b2786605d..5947326a2a 100644--- a/packages/base-ui/src/Interfaces/Checkbox.ts+++ b/packages/base-ui/src/Interfaces/Checkbox.ts@@ -15,7 +15,7 @@ export interface CheckboxComponent extends BaseComponent<BaseCheckboxProps> {render(): JSXComponent<BaseCheckboxProps>;}-type options = {+export type BaseCheckboxGroupOptions = {checked?: boolean;disabled?: boolean;name?: string;@@ -26,7 +26,7 @@ type options = {export interface BaseCheckboxGroupProps extends BaseComponentProps {disabled?: boolean;name?: string;- options: options[];+ options: BaseCheckboxGroupOptions[];onChange?: (value: string[]) => void;}diff --git a/packages/base-ui/src/Interfaces/Tooltip.ts b/packages/base-ui/src/Interfaces/Tooltip.tsindex 4082e39c9b..2f0f8b76cc 100644--- a/packages/base-ui/src/Interfaces/Tooltip.ts+++ b/packages/base-ui/src/Interfaces/Tooltip.ts@@ -2,12 +2,12 @@ import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponenimport { ComponentChildren } from '../Framework';export interface BaseTooltipProps extends BaseComponentProps {+ [index: number]: string;title?: string;children: ComponentChildren;placement?: string;color?: string;styles?: {};- [index: number]: string;}export interface TooltipComponent extends BaseComponent<BaseTooltipProps> {diff --git a/packages/base-ui/src/Utils/util.ts b/packages/base-ui/src/Utils/util.tsindex 0216c6aecc..d3411e24d2 100644--- a/packages/base-ui/src/Utils/util.ts+++ b/packages/base-ui/src/Utils/util.ts@@ -11,12 +11,8 @@ export function isElement(element: any) {export const isDOM =typeof HTMLElement === 'object'- ? function (obj: any) {- return obj instanceof HTMLElement;- }- : function (obj: any) {- return obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';- };+ ? (obj: any) => obj instanceof HTMLElement+ : (obj: any) => obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';/*** DOM selector@@ -150,7 +146,7 @@ export const getNodeindex = (elm: any) => [...elm.parentNode.children].indexOf(e// 防抖export function debounce(fn: Function, time: number) {let timer: any = null;- return function (...arg: any) {+ return (...arg: any) => {clearTimeout(timer);timer = setTimeout(() => {fn(...arg);diff --git a/packages/sheets-plugin-find/package.json b/packages/sheets-plugin-find/package.jsonindex 1c24d0db31..2c4177112d 100644--- a/packages/sheets-plugin-find/package.json+++ b/packages/sheets-plugin-find/package.json@@ -53,6 +53,7 @@"@univerjs/base-ui": "workspace:^0.0.1","@univerjs/common-plugin-data": "workspace:^0.0.1","@univerjs/core": "workspace:^0.0.1",+ "@univerjs/ui-plugin-sheets": "workspace:^0.0.1","preact": "^10.12.1"}}diff --git a/packages/sheets-plugin-find/src/Controller/FindController.ts b/packages/sheets-plugin-find/src/Controller/FindController.tsindex 64f1e5225a..f77ba12a65 100644--- a/packages/sheets-plugin-find/src/Controller/FindController.ts+++ b/packages/sheets-plugin-find/src/Controller/FindController.ts@@ -1,6 +1,4 @@-import { BaseComponentRender } from '@univerjs/base-ui';-import { IToolbarItemProps, SheetPlugin } from '@univerjs/base-sheets';-import { PLUGIN_NAMES } from '@univerjs/core';+import { IToolbarItemProps } from '@univerjs/ui-plugin-sheets';import { FIND_PLUGIN_NAME } from '../Const/PLUGIN_NAME';import { FindPlugin } from '../FindPlugin';@@ -9,84 +7,25 @@ export class FindController {private _findList: IToolbarItemProps;- private _render: BaseComponentRender;-- private _sheetPlugin: SheetPlugin;-constructor(plugin: FindPlugin) {this._plugin = plugin;- this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;this._findList = {name: FIND_PLUGIN_NAME,- type: 4,- tooltipLocale: 'find.findLabel',+ toolbarType: 1,+ tooltip: 'find.findLabel',+ unActive: true,+ customLabel: {+ name: 'SearchIcon',+ },show: true,- label: 'SearchIcon',- children: [- {- locale: 'find.find',- suffix: 'SearchIcon',- onClick: () => {- this.showModal('find', true);- },- },- // {- // locale: 'find.replace',- // suffix: 'ReplaceIcon',- // onClick: () => {- // // this.showFind('replace');- // },- // },- // {- // locale: 'find.location',- // suffix: 'LocationIcon',- // border: true,- // onClick: () => {- // // this.showLocation();- // },- // },- // {- // locale: 'find.formula',- // suffixLocale: 'find.locationExample',- // onClick: () => {},- // },- // {- // locale: 'find.date',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.number',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.string',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.error',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.condition',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.rowSpan',- // suffixLocale: 'find.locationExample',- // },- // {- // locale: 'find.columnSpan',- // suffixLocale: 'find.locationExample',- // },- ],- hideSelectedIcon: true,+ onClick: () => {+ this._plugin.getFindModalController().showModal(true);+ },};-- this._sheetPlugin.addToolButton(this._findList);}- showModal(name: string, show: boolean) {- this._plugin.getFindModalController().showModal(name, show);+ getFindList() {+ return this._findList;}}diff --git a/packages/sheets-plugin-find/src/Controller/FindModalController.ts b/packages/sheets-plugin-find/src/Controller/FindModalController.tsindex 6bd641d178..b0ee35a674 100644--- a/packages/sheets-plugin-find/src/Controller/FindModalController.ts+++ b/packages/sheets-plugin-find/src/Controller/FindModalController.ts@@ -1,120 +1,34 @@-import { BaseComponentRender, ComponentChildren } from '@univerjs/base-ui';-import { SheetPlugin } from '@univerjs/base-sheets';-import { PLUGIN_NAMES } from '@univerjs/core';+import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';import { FIND_PLUGIN_NAME } from '../Const/PLUGIN_NAME';import { FindPlugin } from '../FindPlugin';import { FindModal } from '../View/UI/FindModal';-import { SearchContent } from '../View/UI/SearchContent';--interface GroupProps {- locale: string;- label?: string;- type?: string;-}--export interface ModalDataProps {- name: string;- title?: string;- locale: string;- show: boolean;- children: ComponentChildren | string;- onCancel: () => void;- group: GroupProps[];-}export class FindModalController {private _plugin: FindPlugin;- private _render: BaseComponentRender;-private _findModal: FindModal;- private _sheetPlugin: SheetPlugin;-- private _modalData: ModalDataProps[];-constructor(plugin: FindPlugin) {this._plugin = plugin;- this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;-- this._modalData = [- // {- // locale: 'find.location',- // show: false,- // group: [- // {- // locale: 'button.confirm',- // type: 'primary',- // },- // {- // locale: 'button.cancel',- // },- // ],- // children: <LocationContent config={props.config} />,- // onCancel: () => this.showModal(0, false),- // },- {- name: 'find',- locale: 'find.findLabel',- show: false,- group: [- {- locale: 'button.cancel',- type: 'primary',- },- {- locale: 'button.cancel',- },- ],- children: FIND_PLUGIN_NAME + SearchContent.name,- onCancel: () => {},- },- ];-- this._initRegisterComponent();- this.init();+ this._initialize();}- init() {- const plugin = this._sheetPlugin.getPluginByName<FindPlugin>(FIND_PLUGIN_NAME)!;-- plugin.getObserver('onFindModalDidMountObservable')!.add((component) => {- this._findModal = component;-- this.resetModalData();- });+ getComponent(ref: FindModal) {+ this._findModal = ref;}- // 注册自定义组件- private _initRegisterComponent() {- this._sheetPlugin.registerModal(FIND_PLUGIN_NAME + FindModal.name, 100, FindModal);- this._sheetPlugin.registerComponent(FIND_PLUGIN_NAME + SearchContent.name, SearchContent, { activeKey: 'find' });+ showModal(show: boolean) {+ this._findModal?.showFindModal(show);}- // 转化为渲染数据- resetModalData() {- const locale = this._plugin.getContext().getLocale();-- this._modalData.forEach((item) => {- item.title = locale.get(item.locale);- if (item.group && item.group.length) {- item.group.forEach((ele) => {- ele.label = locale.get(ele.locale);- });- }+ private _initialize() {+ const sheetUiPlugin = this._plugin.getContext().getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);+ sheetUiPlugin.addSlot(FIND_PLUGIN_NAME + FindModal.name, {+ component: FindModal,+ props: {+ getComponent: this.getComponent.bind(this),+ },});-- this._findModal.setModal(this._modalData);- }-- // 显示/关闭弹窗- showModal(name: string, show: boolean) {- const index = this._modalData.findIndex((item) => item.name === name);- if (index > -1) {- this._modalData[index].show = show;-- this._findModal.setModal(this._modalData);- }}}diff --git a/packages/sheets-plugin-find/src/FindPlugin.ts b/packages/sheets-plugin-find/src/FindPlugin.tsindex 8f9b79f39b..d54243230f 100644--- a/packages/sheets-plugin-find/src/FindPlugin.ts+++ b/packages/sheets-plugin-find/src/FindPlugin.ts@@ -1,5 +1,7 @@import { SheetContext, UniverSheet, Plugin, Worksheet } from '@univerjs/core';// import { TextFinder } from './Domain/TextFind';+import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';+import { Icon } from '@univerjs/base-ui';import { FindType } from './IData/IFind';import { FIND_PLUGIN_NAME } from './Const/PLUGIN_NAME';import { FindController } from './Controller/FindController';@@ -7,7 +9,6 @@ import en from './Locale/en';import zh from './Locale/zh';import { FindPluginObserve, install } from './Basic/Observer';import { FindModalController } from './Controller/FindModalController';-import { SearchContentController } from './Controller/SearchContentController';export interface IFindPluginConfig {}@@ -16,8 +17,6 @@ export class FindPlugin extends Plugin<FindPluginObserve> {private _findModalController: FindModalController;- private _searchContentController: SearchContentController;-constructor(config?: IFindPluginConfig) {super(FIND_PLUGIN_NAME);}@@ -28,19 +27,23 @@ export class FindPlugin extends Plugin<FindPluginObserve> {installTo(universheetInstance: UniverSheet) {universheetInstance.installPlugin(this);- }- initialize(): void {+ this._findModalController = new FindModalController(this);+ this._findController = new FindController(this);+const context = this.getContext();+ let sheetPlugin = context.getUniver().getGlobalContext().getPluginManager().getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME);+ sheetPlugin?.UIDidMount(() => {+ sheetPlugin.getComponentManager().register('SearchIcon', Icon.SearchIcon);+ sheetPlugin.addToolButton(this._findController.getFindList());+ });+ }- context.getLocale().load({+ initialize(): void {+ this.getLocale().load({en,zh,});-- this._findModalController = new FindModalController(this);- this._findController = new FindController(this);- this._searchContentController = new SearchContentController(this);}createTextFinder(workSheet: Worksheet, type: FindType, text: string) {diff --git a/packages/sheets-plugin-find/src/IData/IFind.ts b/packages/sheets-plugin-find/src/IData/IFind.tsindex 021d034ab1..363c43c20f 100644--- a/packages/sheets-plugin-find/src/IData/IFind.ts+++ b/packages/sheets-plugin-find/src/IData/IFind.ts@@ -1,8 +1,3 @@import { FormatType } from '@univerjs/core';-export type IConfig = {};-export type FindType = FormatType | 'null' | 'text' | 'condition' | 'intervalRow' | 'intervalColumn';--// Types for props-export type IProps = { config: IConfig };diff --git a/packages/sheets-plugin-find/src/Locale/en.ts b/packages/sheets-plugin-find/src/Locale/en.tsindex c6cbddd3e0..8537000001 100644--- a/packages/sheets-plugin-find/src/Locale/en.ts+++ b/packages/sheets-plugin-find/src/Locale/en.ts@@ -2,7 +2,9 @@ export default {find: {findLabel: 'Find and replace',find: 'Find',+ advanced: 'Advanced Find',replace: 'Replace',+ replaceWith: 'Replace With',goto: 'Go to',location: 'Location',formula: 'Formula',@@ -20,6 +22,10 @@ export default {findTextbox: 'Find Content',replaceTextbox: 'Replace Content',+ matchCase: 'Match case',+ matchAll: 'Match entire cell contents',+ matchInFormula: 'Also search within formulas',+regexTextbox: 'Regular Expression',wholeTextbox: 'Whole word',distinguishTextbox: 'Case sensitive',diff --git a/packages/sheets-plugin-find/src/Locale/zh.ts b/packages/sheets-plugin-find/src/Locale/zh.tsindex dbaef0759a..0354101712 100644--- a/packages/sheets-plugin-find/src/Locale/zh.ts+++ b/packages/sheets-plugin-find/src/Locale/zh.ts@@ -2,7 +2,9 @@ export default {find: {findLabel: '查找替换',find: '查找',+ advanced: '高级查找',replace: '替换',+ replaceWith: '替换为',goto: '转到',location: '定位条件',formula: '公式',@@ -23,6 +25,9 @@ export default {regexTextbox: '正则表达式匹配',wholeTextbox: '整词匹配',distinguishTextbox: '区分大小写匹配',+ matchCase: '匹配大小写',+ matchAll: '匹配整个单元格内容',+ matchInFormula: '也在公式中搜索',allReplaceBtn: '全部替换',replaceBtn: '替换',diff --git a/packages/sheets-plugin-find/src/View/UI/FindModal.tsx b/packages/sheets-plugin-find/src/View/UI/FindModal.tsxindex 3eefdd0c1b..761c16f284 100644--- a/packages/sheets-plugin-find/src/View/UI/FindModal.tsx+++ b/packages/sheets-plugin-find/src/View/UI/FindModal.tsx@@ -1,51 +1,68 @@-import { BaseComponentRender, BaseComponentSheet, Component, ModalProps } from '@univerjs/base-ui';-import { PLUGIN_NAMES } from '@univerjs/core';-import { SheetPlugin } from '@univerjs/base-sheets';-import { IProps } from '../../IData/IFind';-import { FindPlugin } from '../../FindPlugin';-import { FIND_PLUGIN_NAME } from '../../Const/PLUGIN_NAME';-import { ModalDataProps } from '../../Controller/FindModalController';+import { BaseCheckboxGroupOptions, BaseComponentProps, CheckboxGroup, Component, Icon, Input, Modal, Select } from '@univerjs/base-ui';+import styles from './index.module.less';++// Types for props+export interface IProps extends BaseComponentProps {}// Types for stateinterface IState {- modalData: ModalProps[];+ show: boolean;+ title: string;+ hideAdvanced: boolean;}export class FindModal extends Component<IProps, IState> {- Render: BaseComponentRender;-active = 'find';+ private _matchGroup: BaseCheckboxGroupOptions[] = [];+initialize(props: IProps) {- // super(props);- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;- this.Render = component.getComponentRender();+ this._matchGroup = [+ {+ name: '',+ label: 'find.matchCase',+ value: '1',+ },+ {+ name: '',+ label: 'find.matchAll',+ value: '2',+ },+ {+ name: '',+ label: 'find.matchInFormula',+ value: '3',+ },+ ];this.state = {- modalData: [],+ show: false,+ title: 'find.find',+ hideAdvanced: true,};}componentDidMount() {- const plugin = this._context.getPluginManager().getPluginByName<FindPlugin>(FIND_PLUGIN_NAME)!;- plugin.getObserver('onFindModalDidMountObservable')!.notifyObservers(this);+ this.props.getComponent?.(this);}- setModal(modalData: ModalDataProps[]) {- const SheetPlugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;-- modalData.forEach((item) => {- const component = SheetPlugin.getRegisterComponent(item.children as string);- if (component) {- const Label = component.component;- const props = component.props ?? {};- item.children = <Label {...props} />;- }+ showFindModal(show: boolean) {+ this.setState({+ show,});+ }- this.setState({- modalData,+ // 国际化checkbox+ getMatchGroup() {+ const arr = JSON.parse(JSON.stringify(this._matchGroup));+ arr.forEach((element: BaseCheckboxGroupOptions) => {+ element.label = this.getLocale(element.label as string);});+ return arr;+ }++ handleChange(value) {+ console.dir(value);}/**@@ -54,20 +71,33 @@ export class FindModal extends Component<IProps, IState> {* @returns {void}*/render() {- const Modal = this.Render.renderFunction('Modal');- const { modalData } = this.state;+ const { show, title, hideAdvanced } = this.state;// Set Provider for entire Containerreturn (- <>- {modalData.map((item) => {- if (!item.show) return;- return (- <Modal title={item.title} visible={item.show} group={item.group} onCancel={item.onCancel}>- {item.children}- </Modal>- );- })}- </>+ <Modal className={styles.findModal} isDrag footer={false} title={this.getLocale(title)} visible={show}>+ <div className={styles.findAdvance} style={{ display: hideAdvanced ? 'block' : 'none' }}>+ <Input></Input>+ <p>+ {this.getLocale('find.replace')}/{this.getLocale('find.advanced')}+ <Icon.Format.NextIcon />+ </p>+ </div>+ <div className={styles.box}>+ <span>{this.getLocale('find.find')}</span>+ <Input></Input>+ </div>+ <div className={styles.box}>+ <span>{this.getLocale('find.replaceWith')}</span>+ <Input></Input>+ </div>+ <div className={styles.box}>+ <span>{this.getLocale('find.replaceWith')}</span>+ <Select></Select>+ </div>+ <div>+ <CheckboxGroup options={this.getMatchGroup()} onChange={this.handleChange}></CheckboxGroup>+ </div>+ </Modal>);}}diff --git a/packages/sheets-plugin-find/src/View/UI/index.module.less b/packages/sheets-plugin-find/src/View/UI/index.module.lessindex dabc56de4e..6479b0d5b7 100644--- a/packages/sheets-plugin-find/src/View/UI/index.module.less+++ b/packages/sheets-plugin-find/src/View/UI/index.module.less@@ -1,81 +1,16 @@-.location-content {- .radio-wrap {- padding: 0.5rem 0;-- .radio-left {- display: block;-- .label {- height: auto;- }-- .circle {- width: 0.8em;- height: 0.8em;- }-- .active {- .fork {- width: 0.4em;- height: 0.4em;- }- }-- .checkbox-group {- padding: 0 1em;-- .checkbox-wrapper {- .check-box {- .checkbox-inner {- width: 12px;- height: 12px;- }- }- }- }- }+.find-modal {+ input {+ height: 36px;+ border: 1px solid #dadce0;+ border-radius: 4px;}-}--.tab-box {- padding: 0.5em;- border: 1px solid var(--gray-5);- .input-box {- display: flex;- justify-content: space-around;- margin-bottom: 1em;-- .text-box {- div {- &:first-child {- margin: 0.5rem 0;- }-- span {- margin-right: 0.4em;- }-- input {- width: auto;- line-height: normal;- }- }- }-- .checkbox-group {- flex-direction: column;-- label {- margin-bottom: 0.8em;- }+ .find-advance {+ p {+ text-align: center;+ cursor: pointer;}}- .btn-box {- button {- margin-right: 0.5em;- padding: 0 0.5em;- }- }-}+ .box {}+}\ No newline at end of filediff --git a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.tsindex edcfbe02e8..944b69055a 100644--- a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts+++ b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts@@ -38,7 +38,6 @@ interface CustomComponent {funParams?: FunParams;calcLocale?: string;range?: string;- onTableClick?: () => void;placeholderLocale?: string;titleLocale?: string;confirmTextLocale?: string;@@ -124,7 +123,6 @@ export class SearchFormulaController {funParams: this._funParams,calcLocale: 'formula.formulaMore.calculationResult',range: 'A1:B10',- onTableClick: () => this.showCellRangeModal(true),},},},diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.tsindex 95a8bbd681..4b804c57c5 100644--- a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts+++ b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts@@ -50,6 +50,31 @@ export enum AnimateStatus {}export class Animate {+ protected _config: AnimateConfig;++ protected _status: AnimateStatus;++ protected _start: number;++ protected _handle: number;++ protected _delayHandle: NodeJS.Timeout;++ constructor(config: Partial<AnimateConfig>) {+ this._config = {+ ...CONFIG,+ ...config,+ };+ if (this._config.loop) {+ this._config.complete = () => {+ /*noop*/+ };+ this._config.success = () => {+ this.request();+ };+ }+ }+static success(...animates: Animate[]): Promise<void> {let successNumber = 0;return new Promise<void>((resolve) => {@@ -74,15 +99,26 @@ export class Animate {});}- protected _config: AnimateConfig;-- protected _status: AnimateStatus;-- protected _start: number;-- protected _handle: number;+ request(): void {+ if (this._config.delay === 0) {+ this._status = AnimateStatus.Request;+ this._start = Date.now();+ this._fakeHandle();+ } else {+ this._delayHandle && clearTimeout(this._delayHandle);+ this._delayHandle = setTimeout(() => {+ this._status = AnimateStatus.Request;+ this._start = Date.now();+ this._fakeHandle();+ }, this._config.delay);+ }+ }- protected _delayHandle: NodeJS.Timeout;+ cancel(): void {+ this._status = AnimateStatus.Cancel;+ this._delayHandle && clearTimeout(this._delayHandle);+ cancelAnimationFrame(this._handle);+ }protected _fakeHandle(): void {let times = Date.now() - this._start;@@ -109,40 +145,4 @@ export class Animate {this._fakeHandle();});}-- constructor(config: Partial<AnimateConfig>) {- this._config = {- ...CONFIG,- ...config,- };- if (this._config.loop) {- this._config.complete = () => {- /*noop*/- };- this._config.success = () => {- this.request();- };- }- }-- request(): void {- if (this._config.delay === 0) {- this._status = AnimateStatus.Request;- this._start = Date.now();- this._fakeHandle();- } else {- this._delayHandle && clearTimeout(this._delayHandle);- this._delayHandle = setTimeout(() => {- this._status = AnimateStatus.Request;- this._start = Date.now();- this._fakeHandle();- }, this._config.delay);- }- }-- cancel(): void {- this._status = AnimateStatus.Cancel;- this._delayHandle && clearTimeout(this._delayHandle);- cancelAnimationFrame(this._handle);- }}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex b3a0f4a412..7d385c0789 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -55,43 +55,6 @@ export class SheetContainerUIController {this._rightMenuController = new RightMenuUIController(this._plugin, this._config.layout?.rightMenuConfig);this._countBarController = new CountBarUIController(this._plugin);this._sheetBarController = new SheetBarUIController(this._plugin);-- // 初始化UI- // const config = {- // context: this._plugin.getContext(),- // config: this._config,- // changeLocale: this.changeLocale,- // getComponent: this.getComponent,- // // 其余组件的props- // methods: {- // toolbar: {- // getComponent: this._toolbarController.getComponent,- // },- // cellEditor: {- // getComponent: this._cellEditorUIController.getComponent,- // },- // formulaBar: {- // getComponent: this._formulaBarUIController.getComponent,- // },- // infoBar: {- // getComponent: this._infoBarController.getComponent,- // // renameSheet: this._infoBarController.renameSheet,- // },- // rightMenu: {- // // getComponent: this._rightMenuController.getComponent,- // },- // countBar: {- // // getComponent: this._countBarController.getComponent,- // },- // sheetBar: {- // // getComponent: this._sheetBarController.getComponent,- // // addSheet: this._sheetBarController.addSheet,- // // selectSheet: this._sheetBarController.selectSheet,- // // changeSheetName: this._sheetBarController.changeSheetName,- // },- // },- // };- // UI.create(config);}getUIConfig() {@@ -189,6 +152,10 @@ export class SheetContainerUIController {return this._slotController;}+ getToolbarController() {+ return this._toolbarController;+ }+UIDidMount(cb: Function) {if (this._sheetContainer) return cb(this._sheetContainer);diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.tsindex 8c6eeba77f..bec04a524f 100644--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts@@ -462,9 +462,8 @@ export class ToolbarUIController {// 增加toolbar配置addToolbarConfig(config: IToolbarItemProps) {const index = this._toolList.findIndex((item) => item.name === config.name);- if (index > -1) {- this._toolList.push(config);- }+ if (index > -1) return;+ this._toolList.push(config);}// 删除toolbar配置@@ -477,7 +476,7 @@ export class ToolbarUIController {// 刷新toolbarsetToolbar() {- this._toolbar.setToolbar(this._toolList);+ this._toolbar?.setToolbar(this._toolList);}setUIObserve<T>(msg: UIObserver<T>) {diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsindex ae29ea2e75..f7791ca13c 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts@@ -7,6 +7,7 @@ import { zh, en } from './Locale';import { AppUIController } from './Controller/AppUIController';import { Fx } from './View/FormulaBar';import { SlotComponentProps } from './Controller/SlotController';+import { IToolbarItemProps } from './Controller';export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {private _appUIController: AppUIController;@@ -115,4 +116,12 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {addSlot(name: string, slot: SlotComponentProps, cb?: () => void) {this._appUIController.getSheetContainerController().getMainSlotController().addSlot(name, slot, cb);}++ addToolButton(config: IToolbarItemProps) {+ this._appUIController.getSheetContainerController().getToolbarController().addToolbarConfig(config);+ }++ deleteToolButton(name: string) {+ this._appUIController.getSheetContainerController().getToolbarController().deleteToolbarConfig(name);+ }}diff --git a/packages/ui-plugin-sheets/src/View/SideGroup/SideGroup.tsx b/packages/ui-plugin-sheets/src/View/SideGroup/SideGroup.tsxindex 14bef033e4..9946d88c25 100644--- a/packages/ui-plugin-sheets/src/View/SideGroup/SideGroup.tsx+++ b/packages/ui-plugin-sheets/src/View/SideGroup/SideGroup.tsx@@ -1,58 +1,58 @@-import { Component } from '@univerjs/base-ui';-import { PLUGIN_NAMES } from '@univerjs/core';-import { SideProps } from '../../../Controller/SideGroupController';-import { SheetPlugin } from '../../../SheetPlugin';--interface IState {- sideGroup: any[];-}--interface SideRenderProps extends SideProps {- side?: any;-}--export class SideGroup extends Component<any, IState> {- initialize() {- this.state = {- sideGroup: [],- };- }-- componentDidMount(): void {- this._context.getObserverManager().getObserver<SideGroup>('onSideGroupDidMountObservable')?.notifyObservers(this);- }-- setSideGroup(group: SideRenderProps[]) {- const plugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);-- const sideGroup = group.map((item) => {- const Side = plugin?.getRegisterComponent(item.name);- if (Side) {- item.side = <Side></Side>;- }- return item;- });-- this.setState({- sideGroup,- });- }-- render() {- const { sideGroup } = this.state;- return (- <div>- {sideGroup.map((item) => {- if (item.show) {- return (- <div onClick={() => item.onClick(item.name)} style={{ zIndex: item.zIndex }}>- {item.side}- </div>- );- }- return <></>;- })}- </div>- );- }-}+// import { Component } from '@univerjs/base-ui';+// import { PLUGIN_NAMES } from '@univerjs/core';+// import { SideProps } from '../../../Controller/SideGroupController';+// import { SheetPlugin } from '../../../SheetPlugin';++// interface IState {+// sideGroup: any[];+// }++// interface SideRenderProps extends SideProps {+// side?: any;+// }++// export class SideGroup extends Component<any, IState> {+// initialize() {+// this.state = {+// sideGroup: [],+// };+// }++// componentDidMount(): void {+// this._context.getObserverManager().getObserver<SideGroup>('onSideGroupDidMountObservable')?.notifyObservers(this);+// }++// setSideGroup(group: SideRenderProps[]) {+// const plugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);++// const sideGroup = group.map((item) => {+// const Side = plugin?.getRegisterComponent(item.name);+// if (Side) {+// item.side = <Side></Side>;+// }+// return item;+// });++// this.setState({+// sideGroup,+// });+// }++// render() {+// const { sideGroup } = this.state;+// return (+// <div>+// {sideGroup.map((item) => {+// if (item.show) {+// return (+// <div onClick={() => item.onClick(item.name)} style={{ zIndex: item.zIndex }}>+// {item.side}+// </div>+// );+// }+// return <></>;+// })}+// </div>+// );+// }+// }