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(ui-plugin-sheets):1. load default skin, 2.formula cell editor
Dushusirfab44773253d
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex d49e1bf9b5..ccac81519e 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -78,6 +78,8 @@ universheet.installPlugin(},}));+FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO1).installTo(universheet);+// universheet.installPlugin(new FormulaPlugin(DEFAULT_FORMULA_DATA_DEMO));// // ui TODO: 不要安装// univer.install(new UniverComponentSheet());diff --git a/packages/base-sheets/package.json b/packages/base-sheets/package.jsonindex 8b9126e77a..22794ef3f0 100644--- a/packages/base-sheets/package.json+++ b/packages/base-sheets/package.json@@ -52,7 +52,6 @@"@univerjs/base-render": "workspace:^0.0.1","@univerjs/common-plugin-data": "workspace:^0.0.1","@univerjs/core": "workspace:^0.0.1",- "css-vars-ponyfill": "^2.4.6","nanoid": "4.0.0","preact": "^10.5.14"}diff --git a/packages/base-ui/src/Basics/Interfaces/index.ts b/packages/base-ui/src/Basics/Interfaces/index.tsindex 6bb95e7b5c..dcf4f4f278 100644--- a/packages/base-ui/src/Basics/Interfaces/index.ts+++ b/packages/base-ui/src/Basics/Interfaces/index.ts@@ -1,6 +1,7 @@// @index(['./*.ts','./**/index.ts'], f => `export * from '${f.path}'`)+export * from './Cell';+export * from './ComponentConfig/index';export * from './IClipboardData';export * from './IDragAndDropData';export * from './PasteType';-export * from './ComponentConfig';// @endindexdiff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.tsindex 97370ffb42..86522584d4 100644--- a/packages/core/src/Basics/Univer.ts+++ b/packages/core/src/Basics/Univer.ts@@ -62,6 +62,10 @@ export class Univer {return this._univerSlides;}+ /**+ * get active universheet+ * @returns+ */getCurrentUniverSheetInstance() {return this._univerSheets[0];}diff --git a/packages/sheets-plugin-formula/package.json b/packages/sheets-plugin-formula/package.jsonindex 56be71adaf..5270de74dd 100644--- a/packages/sheets-plugin-formula/package.json+++ b/packages/sheets-plugin-formula/package.json@@ -45,12 +45,13 @@"vite-plugin-external": "1.2.3"},"dependencies": {- "@univerjs/base-ui": "workspace:^0.0.1","@univerjs/base-formula-engine": "workspace:^0.0.1","@univerjs/base-render": "workspace:^0.0.1","@univerjs/base-sheets": "workspace:^0.0.1",+ "@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","css-vars-ponyfill": "^2.4.6","preact": "^10.5.14","react-colorful": "^5.3.0"diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.tsindex 84c0171c93..8fa3af30b3 100644--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellEditExtension.ts@@ -1,6 +1,7 @@-import { BaseCellEditExtension, BaseCellEditExtensionFactory, ICell, SheetPlugin } from '@univerjs/base-sheets';import { IFormulaData } from '@univerjs/base-formula-engine';-import { IRangeData, Nullable, PLUGIN_NAMES } from '@univerjs/core';+import { BaseCellEditExtension, BaseCellEditExtensionFactory, ICell } from '@univerjs/base-ui';+import { IRangeData, Nullable } from '@univerjs/core';+import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '@univerjs/ui-plugin-sheets';import { FormulaPlugin } from '../../FormulaPlugin';export class FormulaCellEditExtension extends BaseCellEditExtension {@@ -79,8 +80,10 @@ export class FormulaCellEditExtensionFactory extends BaseCellEditExtensionFactorthis._plugin.getContext().getPluginManager()- .getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)- .getFormulaBarController()+ .getRequirePluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)+ .getAppUIController()+ .getSheetContainerController()+ .getFormulaBarUIController().getFormulaBar().setFormulaContent('');return false;diff --git a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.tsindex 023a349b8f..e5eca5ac01 100644--- a/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts+++ b/packages/sheets-plugin-formula/src/Basic/Register/FormulaCellInputExtension.ts@@ -1,5 +1,5 @@-import { BaseCellInputExtension, BaseCellInputExtensionFactory, ICell } from '@univerjs/base-sheets';import { IFormulaData } from '@univerjs/base-formula-engine';+import { BaseCellInputExtension, BaseCellInputExtensionFactory, ICell } from '@univerjs/base-ui';import { IRangeData, Nullable } from '@univerjs/core';import { FormulaPlugin } from '../../FormulaPlugin';diff --git a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts b/packages/sheets-plugin-formula/src/Controller/FormulaController.tsindex 458ff3d8d1..1fb7fe87c4 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaController.ts@@ -32,7 +32,7 @@ export class FormulaController {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 0052f1206e..a2fa21c0dd 100644--- a/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts+++ b/packages/sheets-plugin-formula/src/Controller/FormulaPromptController.ts@@ -27,7 +27,7 @@ export class FormulaPromptController {this._sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;this._initialize();- this._initRegisterComponent();+ // this._initRegisterComponent();}private _initRegisterComponent() {diff --git a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.tsindex b9664c2e67..cf5c204ab6 100644--- a/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts+++ b/packages/sheets-plugin-formula/src/Controller/SearchFormulaModalController.ts@@ -157,7 +157,7 @@ export class SearchFormulaController {},};- this._initRegisterComponent();+ // this._initRegisterComponent();this._initialize();}@@ -177,7 +177,7 @@ export class SearchFormulaController {const sheetPlugin = this._plugin.getContext().getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;sheetPlugin.getObserver('onChangeSelectionObserver')?.add((selection) => {const info = selection.getCurrentCellInfo();- this._searchItem.changeRange(info?.startColumn.toString() ?? '');+ // this._searchItem.changeRange(info?.startColumn.toString() ?? '');});}diff --git a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx b/packages/sheets-plugin-formula/src/FormulaPlugin.tsxindex dde0627f72..cc9c80ba4c 100644--- a/packages/sheets-plugin-formula/src/FormulaPlugin.tsx+++ b/packages/sheets-plugin-formula/src/FormulaPlugin.tsx@@ -1,6 +1,6 @@import { SheetContext, IOCContainer, UniverSheet, Plugin } from '@univerjs/core';-import { CellEditExtensionManager, CellInputExtensionManager } from '@univerjs/base-sheets';import { FormulaEnginePlugin } from '@univerjs/base-formula-engine';+import { CellEditExtensionManager, CellInputExtensionManager } from '@univerjs/base-ui';import { zh, en } from './Locale';import { IFormulaConfig } from './Basic/Interfaces/IFormula';diff --git a/packages/ui-plugin-sheets/package.json b/packages/ui-plugin-sheets/package.jsonindex 7efc5871f5..c350f6a6c8 100644--- a/packages/ui-plugin-sheets/package.json+++ b/packages/ui-plugin-sheets/package.json@@ -55,6 +55,7 @@"@univerjs/base-render": "workspace:^0.0.1","@univerjs/core": "workspace:^0.0.1","@univerjs/base-sheets": "workspace:^0.0.1",+ "css-vars-ponyfill": "^2.4.6","preact": "^10.5.14"}}diff --git a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.tsindex e18af7f4c6..8de7f626db 100644--- a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts@@ -235,7 +235,7 @@ export class CellEditorUIController {this._richTextEle.style.minHeight = `${endY - startY}px`;this._richTextEle.style.borderWidth = '2px';- const univerContainerContentRef = this._plugin.getSheetContainerController().getContentRef();+ const univerContainerContentRef = this._plugin.getAppUIController().getSheetContainerController().getContentRef();const sheetContentRect = getRefElement(univerContainerContentRef).getBoundingClientRect();this._richTextEle.style.maxWidth = `${sheetContentRect.width - startX + scrollX}px`;diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex f183ff183c..395e790e72 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -43,8 +43,6 @@ export class SheetContainerUIController {this._initialize();- console.log('sheet container init!');-this._toolbarController = new ToolbarUIController(this._plugin, this._config.layout?.toolbarConfig);this._cellEditorUIController = new CellEditorUIController(this._plugin);this._formulaBarUIController = new FormulaBarUIController(this._plugin);@@ -179,4 +177,11 @@ export class SheetContainerUIController {getEventManager() {return this._eventManager;}++ getCellEditorUIController() {+ return this._cellEditorUIController+ }+ getFormulaBarUIController() {+ return this._formulaBarUIController+ }}diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsxindex 974674fb99..faa28e17f9 100644--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx@@ -8,6 +8,9 @@ import { FormulaBar } from '../FormulaBar';import { RichText } from '../RichText';import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider } from '@univerjs/base-ui';import { ISheetUIPluginConfig } from '../../Basics';+import defaultSkin from '@univerjs/base-ui/Basics/CSS/Skin/default.module.less';+import { Tools } from '@univerjs/core';+import cssVars from 'css-vars-ponyfill';export interface BaseSheetContainerProps extends BaseComponentProps {config: ISheetUIPluginConfig;@@ -31,6 +34,11 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {contentRef = createRef<HTMLDivElement>();+ constructor(props: BaseSheetContainerProps) {+ super();+ this.changeSkin(props.config.container as string, 'default');+ }+componentDidMount() {this.props.getComponent?.(this);}@@ -88,6 +96,100 @@ export class SheetContainer extends Component<BaseSheetContainerProps> {return this.splitLeftRef;}+ /**+ * Modify Dom Skin+ */+ changeSkin(container: HTMLElement | string, skin: string) {+ // Collect all skins+ let root = document.documentElement;++ const id = typeof container === 'string' ? container : container.id;++ // get all skins+ const skins = {+ default: defaultSkin,+ };++ // current skin set by user+ let currentSkin = skins[skin];++ // transform "primaryColor" to "--primary-color"+ currentSkin = Object.fromEntries(Object.keys(currentSkin).map((item) => [`--${item.replace(/([A-Z0-9])/g, '-$1').toLowerCase()}`, currentSkin[item]]));++ // ie11 does not support css variables, use css-vars-ponyfill to handle+ if (Tools.isIEBrowser()) {+ cssVars({+ // Options...++ // The container is invalid as rootElement, so the default setting is root.+ // Disadvantages: In ie11, only one set of skins can be used for multiple workbooks, and it is the skin set by the last workbook+ rootElement: root, // default++ variables: currentSkin,+ });+ } else {+ // set css variable+ let sheet = getSkinStyleSheet(id);++ /**+ * covert object to style, remove " and replace , to ;+ *+ * Example:+ *+ * before: {--primary-color:"#0188fb",--primary-color-hover:"#5391ff"}+ * after: {--primary-color:#0188fb;--primary-color-hover:#5391ff;}+ */++ sheet.insertRule(+ `#${id} ${JSON.stringify(currentSkin)+ .replace(/"/g, '')+ .replace(/,(?=--)/g, ';')}`+ );+ }++ /**+ * get skin style sheet+ * @param id+ * @returns+ */++ function getSkinStyleSheet(id: string) {+ const title = 'universheet-skin-style';+ // avoid duplicates+ for (let i = 0; i < document.styleSheets.length; i++) {+ if (document.styleSheets[i].title === title) {+ deleteStyleRuleIndexBySelector(document.styleSheets[i], id);++ return document.styleSheets[i];+ }+ }+ const head = document.head || document.getElementsByTagName('head')[0];+ const styleEle = document.createElement('style');+ styleEle.title = title;+ head.appendChild(styleEle);++ return document.styleSheets[document.styleSheets.length - 1];+ }++ /**+ * delete style rule in universheet-skin-style+ * @param skinStyleSheet+ * @param id+ */+ function deleteStyleRuleIndexBySelector(skinStyleSheet: CSSStyleSheet, id: string) {+ let index = 0;+ for (let i = 0; i < skinStyleSheet.cssRules.length; i++) {+ const rule = skinStyleSheet.cssRules[i];++ if (rule instanceof CSSStyleRule && rule.selectorText === `#${id}`) {+ index = i;+ skinStyleSheet.deleteRule(index);+ break;+ }+ }+ }+ }+/*** Render the component's HTML*diff --git a/packages/ui-plugin-sheets/src/index.ts b/packages/ui-plugin-sheets/src/index.tsindex 2a03c88802..2218efe867 100644--- a/packages/ui-plugin-sheets/src/index.ts+++ b/packages/ui-plugin-sheets/src/index.ts@@ -1 +1,3 @@+export * from './Basics';+export * from './Controller';export * from './SheetUIPlugin';