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
move ui
tonytonychopper123ef36f2eb44fd
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsxindex 31cf75a939..9f1a9cf9b3 100644--- a/examples/univer-sheet-ts/src/main.tsx+++ b/examples/univer-sheet-ts/src/main.tsx@@ -47,21 +47,43 @@ const univerConfig = {};const univer = new Univer();-univer.install(new RenderEngine());univer.install(new UniverComponentSheet());-univer.install(new BaseComponentPlugin(univerConfig));-// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);+// const sheet = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);+// const component = new BaseComponentPlugin(univerConfig);+// univer.install(component);+// sheet.installPlugin(new RenderEngine());+// sheet.installPlugin(+// new SheetPlugin(component, {+// selections: {+// 'sheet-0001': [+// {+// selection: {+// startRow: 2,+// endRow: 2,+// startColumn: 3,+// endColumn: 3,+// },+// cell: {+// row: 2,+// column: 3,+// },+// },+// ],+// },+// })+// );+const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO1);// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO2);// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO3);// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);-// univerSheetDemo.installPlugin(new RenderEngine());-// univerSheetDemo.installPlugin(new UniverComponentSheet());-// univerSheetDemo.installPlugin(new SheetPlugin(uiDefaultConfigDemo));+univerSheetDemo.installPlugin(new RenderEngine());+univerSheetDemo.installPlugin(new UniverComponentSheet());+univerSheetDemo.installPlugin(new SheetPlugin(uiDefaultConfigDemo));// univerSheetDemo.installPlugin(new BaseComponentPlugin());// univerSheetDemo.installPlugin(new NumfmtPlugin());// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO).installTo(univerSheetDemo);// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO1).installTo(univerSheetDemo);-// univerSheetDemo.installPlugin(new ClipboardPlugin());-// univerSheetDemo.installPlugin(new ImportXlsxPlugin());+univerSheetDemo.installPlugin(new ClipboardPlugin());+univerSheetDemo.installPlugin(new ImportXlsxPlugin());diff --git a/examples/univer-vanilla-ts/index.html b/examples/univer-vanilla-ts/index.htmlindex 483c6ffb49..ca8cfb667c 100644--- a/examples/univer-vanilla-ts/index.html+++ b/examples/univer-vanilla-ts/index.html@@ -25,16 +25,7 @@<body><div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>-- <div class="univer-container">- <div id="universheet-up"></div>- <div id="univerdoc"></div>- </div>-- <div class="univer-container">- <div id="universheet-down"></div>- <div id="universlide"></div>- </div>+ <div id="universheet" style="height: 100%;"></div><script type="module" src="/src/main.tsx"></script></body>diff --git a/examples/univer-vanilla-ts/src/main.tsx b/examples/univer-vanilla-ts/src/main.tsxindex dfa4f08d89..000f3bcbbe 100644--- a/examples/univer-vanilla-ts/src/main.tsx+++ b/examples/univer-vanilla-ts/src/main.tsx@@ -22,11 +22,68 @@ import { ClipboardPlugin } from '@univer/sheets-plugin-clipboard';import { BaseComponentPlugin } from '@univer/base-component';import { ImportXlsxPlugin } from '@univer/sheets-plugin-import-xlsx';+const uiDefaultConfigDemo = {+ container: 'universheet',+ selections: {+ 'sheet-0001': [+ {+ selection: {+ startRow: 2,+ endRow: 2,+ startColumn: 3,+ endColumn: 3,+ },+ cell: {+ row: 2,+ column: 3,+ },+ },+ ],+ },+};+const univerConfig = {container: 'universheet',};const univer = new Univer();-univer.install(new RenderEngine());univer.install(new UniverComponentSheet());-univer.install(new BaseComponentPlugin(univerConfig));+const sheet = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);+const component = new BaseComponentPlugin(univerConfig);+univer.install(component);+sheet.installPlugin(new RenderEngine());+sheet.installPlugin(+ new SheetPlugin(component, {+ selections: {+ 'sheet-0001': [+ {+ selection: {+ startRow: 2,+ endRow: 2,+ startColumn: 3,+ endColumn: 3,+ },+ cell: {+ row: 2,+ column: 3,+ },+ },+ ],+ },+ })+);+// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);+// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO1);+// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO2);+// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO3);+// const univerSheetDemo = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DEMO);+// univerSheetDemo.installPlugin(new RenderEngine());+// univerSheetDemo.installPlugin(new UniverComponentSheet());+// univerSheetDemo.installPlugin(new SheetPlugin(uiDefaultConfigDemo));+// univerSheetDemo.installPlugin(new BaseComponentPlugin());+// univerSheetDemo.installPlugin(new NumfmtPlugin());+// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO).installTo(univerSheetDemo);+// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DEMO1).installTo(univerSheetDemo);++// univerSheetDemo.installPlugin(new ClipboardPlugin());+// univerSheetDemo.installPlugin(new ImportXlsxPlugin());diff --git a/package.json b/package.jsonindex 9dc54b0740..32e1d07540 100644--- a/package.json+++ b/package.json@@ -8,10 +8,8 @@"test:ui": "pnpm run --filter @univer/style-univer test","test:e2e": "pnpm run --filter @univer/base-sheets test:play","dev": "node scripts/dev",- "dev:demo": "pnpm run --filter univer-sheet-ts dev",- "dev:demosheet": "pnpm run --filter univer-sheet-ts dev",- "dev:demodoc": "pnpm run --filter univer-doc-ts dev",- "dev:demoslide": "pnpm run --filter univer-slide-ts dev",+ "dev:sheet": "pnpm run --filter univer-sheet-ts dev",+ "dev:all": "pnpm run --filter univer-vanilla-ts dev","dev:preact": "pnpm run --filter univer-sheet-preact dev","dev:doc": "pnpm run --filter @univer/base-docs dev","dev:slide": "pnpm run --filter @univer/base-slides dev",diff --git a/packages/base-component/src/BaseComponent.ts b/packages/base-component/src/BaseComponent.tsindex f57738be95..9e52ac667d 100644--- a/packages/base-component/src/BaseComponent.ts+++ b/packages/base-component/src/BaseComponent.ts@@ -1,5 +1,5 @@import { BasePlugin } from '@univer/core';-import { ComponentChildren, ComponentClass, ForwardFn } from './Framework';+import { ComponentClass, ForwardFn } from './Framework';import { Description } from './Components';// TODO Button const enum@@ -10,7 +10,7 @@ export interface BaseComponentSheet extends BasePlugin {getComponentFactory(): BaseComponentFactory;}export interface BaseComponentProps {- getSelfRef?: (ref: ComponentChildren) => void; //获取自身组件+ getComponent?: (ref: any) => void; //获取自身组件id?: string; // 组件id}diff --git a/packages/base-component/src/BaseComponentPlugin.ts b/packages/base-component/src/BaseComponentPlugin.tsindex c56838120c..11958e56df 100644--- a/packages/base-component/src/BaseComponentPlugin.ts+++ b/packages/base-component/src/BaseComponentPlugin.ts@@ -1,9 +1,12 @@+import { SheetPlugin } from '@univer/base-sheets';import { Plugin, UniverSheet, UniverDoc, UniverSlide, PLUGIN_NAMES } from '@univer/core';import { UniverConfig } from './Basics/Interfaces/UniverConfig';+import { UniverSheetConfig } from './Basics/Interfaces/UniverSheetConfig';+import { BaseComponentPluginObserve, installObserver } from './Basics/Observer';import { RegisterManager } from './Common/RegisterManager';import { UniverContainerController } from './Controller/UniverContainerController';-export class BaseComponentPlugin extends Plugin {+export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {private _registerManager: RegisterManager;private _config: UniverConfig;@@ -24,6 +27,7 @@ export class BaseComponentPlugin extends Plugin {}initialize(): void {+ installObserver(this);this._univerContainerController = new UniverContainerController(this);this.setRegisterManager();}@@ -35,10 +39,16 @@ export class BaseComponentPlugin extends Plugin {return this._config;}+ getUniverContainerController() {+ return this._univerContainerController;+ }+/*** get sheetPlugin*/- getSheetPlugin() {}+ getSheetPlugin() {+ return this.getPluginByName<SheetPlugin>('spreadsheet')!;+ }setRegisterManager() {this._registerManager = new RegisterManager(this);@@ -52,6 +62,10 @@ export class BaseComponentPlugin extends Plugin {return this._registerManager;}+ addSheet(config: UniverSheetConfig) {+ this._univerContainerController.addSheet(config);+ }+onMounted(): void {this.initialize();}diff --git a/packages/base-component/src/Basics/Const/ToolBar/DefaultToolbarConfig.ts b/packages/base-component/src/Basics/Const/ToolBar/DefaultToolbarConfig.tsnew file mode 100644index 0000000000..1f6536c122--- /dev/null+++ b/packages/base-component/src/Basics/Const/ToolBar/DefaultToolbarConfig.ts@@ -0,0 +1,23 @@+export const DefaultToolbarConfig = {+ undoRedo: true, // Undo redo+ paintFormat: true, // Format brush+ currencyFormat: true, // currency format+ percentageFormat: true, // Percentage format+ numberDecrease: true, // 'Decrease the number of decimal places'+ numberIncrease: true, // 'Increase the number of decimal places+ moreFormats: true, // 'More Formats'+ font: true, // 'font'+ fontSize: true, // 'Font size'+ bold: true, // 'Bold (Ctrl+B)'+ italic: true, // 'Italic (Ctrl+I)'+ strikethrough: true, // 'Strikethrough (Alt+Shift+5)'+ underline: true, // 'Underline (Alt+Shift+6)'+ textColor: true, // 'Text color'+ fillColor: true, // 'Cell color'+ border: true, // 'border'+ mergeCell: true, // 'Merge cells'+ horizontalAlignMode: true, // 'Horizontal alignment'+ verticalAlignMode: true, // 'Vertical alignment'+ textWrapMode: true, // 'Wrap mode'+ textRotateMode: true, // 'Text Rotation Mode'+};diff --git a/packages/base-component/src/Basics/Interfaces/ToolbarConfig/BaseToolBarConfig.ts b/packages/base-component/src/Basics/Interfaces/ToolbarConfig/BaseToolBarConfig.tsnew file mode 100644index 0000000000..26a09043a7--- /dev/null+++ b/packages/base-component/src/Basics/Interfaces/ToolbarConfig/BaseToolBarConfig.ts@@ -0,0 +1,61 @@+import { BaseSelectChildrenProps, BaseSelectProps } from '@univer/base-sheets';+import { BaseTextButtonProps } from '@univer/base-sheets/src/View/UI/Common/TextButton/TextButton';++export interface ToolBarConfig extends SheetToolBarConfig, DocToolBarConfig, SlideToolBarConfig {}++export interface BaseToolBarConfig {+ undoRedo?: boolean; // Undo redo+ paintFormat?: boolean; // Format brush+ currencyFormat?: boolean; // currency format+ percentageFormat?: boolean; // Percentage format+ numberDecrease?: boolean; // 'Decrease the number of decimal places'+ numberIncrease?: boolean; // 'Increase the number of decimal places+ font?: boolean; // 'font'+ fontSize?: boolean; // 'Font size'+ bold?: boolean; // 'Bold (Ctrl+B)'+ italic?: boolean; // 'Italic (Ctrl+I)'+ strikethrough?: boolean; // 'Strikethrough (Alt+Shift+5)'+ underline?: boolean; // 'Underline (Alt+Shift+6)'+ textColor?: boolean; // 'Text color'+ fillColor?: boolean; // 'Cell color'+ border?: boolean; // 'border'+ horizontalAlignMode?: boolean; // 'Horizontal alignment'+ verticalAlignMode?: boolean; // 'Vertical alignment'+ textWrapMode?: boolean; // 'Wrap mode'+ textRotateMode?: boolean; // 'Text Rotation Mode'+}++export interface SheetToolBarConfig extends BaseToolBarConfig {+ mergeCell?: boolean; // 'Merge cells'+}++export interface DocToolBarConfig extends BaseToolBarConfig {}++export interface SlideToolBarConfig extends BaseToolBarConfig {}++// 继承基础下拉属性,添加国际化+export interface BaseToolBarSelectChildrenProps extends BaseSelectChildrenProps {+ locale?: string;+ suffixLocale?: string;+ children?: BaseToolBarSelectChildrenProps[];+}++export interface BaseToolBarSelectProps extends BaseSelectProps {+ locale?: string;+ suffixLocale?: string;+ children?: BaseToolBarSelectChildrenProps[];+}++enum ToolbarType {+ SELECT,+ BUTTON,+}++export interface IToolBarItemProps extends BaseToolBarSelectProps, BaseTextButtonProps {+ show?: boolean; //是否显示按钮+ toolbarType?: ToolbarType;+ locale?: string; //label国际化+ tooltipLocale?: string; //tooltip国际化 TODO: need right label+ tooltip?: string; //tooltip文字+ border?: boolean;+}diff --git a/packages/base-component/src/Basics/Interfaces/UniverConfig.ts b/packages/base-component/src/Basics/Interfaces/UniverConfig.tsindex 09a7e17e20..3f41b85202 100644--- a/packages/base-component/src/Basics/Interfaces/UniverConfig.ts+++ b/packages/base-component/src/Basics/Interfaces/UniverConfig.ts@@ -1,4 +1,5 @@import { ContextBase } from '@univer/core';+import { ToolBarConfig } from './ToolbarConfig/BaseToolBarConfig';/*** ShowContainerConfig@@ -40,32 +41,6 @@ export interface IShowContainerConfig {contentSplit?: boolean | string;}-/**- * ToolBarConfig- */-export interface IShowToolBarConfig {- undoRedo?: boolean; // Undo redo- paintFormat?: boolean; // Format brush- currencyFormat?: boolean; // currency format- percentageFormat?: boolean; // Percentage format- numberDecrease?: boolean; // 'Decrease the number of decimal places'- numberIncrease?: boolean; // 'Increase the number of decimal places- font?: boolean; // 'font'- fontSize?: boolean; // 'Font size'- bold?: boolean; // 'Bold (Ctrl+B)'- italic?: boolean; // 'Italic (Ctrl+I)'- strikethrough?: boolean; // 'Strikethrough (Alt+Shift+5)'- underline?: boolean; // 'Underline (Alt+Shift+6)'- textColor?: boolean; // 'Text color'- fillColor?: boolean; // 'Cell color'- border?: boolean; // 'border'- mergeCell?: boolean; // 'Merge cells'- horizontalAlignMode?: boolean; // 'Horizontal alignment'- verticalAlignMode?: boolean; // 'Vertical alignment'- textWrapMode?: boolean; // 'Wrap mode'- textRotateMode?: boolean; // 'Text Rotation Mode'-}-/*** RightMenuConfig*/@@ -91,7 +66,7 @@ export interface IHideRightMenuConfig {export interface ILayout {sheetContainerConfig?: IShowContainerConfig;- toolBarConfig?: IShowToolBarConfig;+ toolBarConfig?: ToolBarConfig;rightMenuConfig?: IHideRightMenuConfig;}@@ -99,5 +74,6 @@ export interface UniverConfig {container?: HTMLElement | string;layout?: ILayout;skin?: string;+ locale?: string;context?: ContextBase;}diff --git a/packages/base-component/src/Basics/Interfaces/UniverSheetConfig.ts b/packages/base-component/src/Basics/Interfaces/UniverSheetConfig.tsnew file mode 100644index 0000000000..74848407ad--- /dev/null+++ b/packages/base-component/src/Basics/Interfaces/UniverSheetConfig.ts@@ -0,0 +1,5 @@+import { SheetToolBarConfig } from './ToolbarConfig/BaseToolBarConfig';++export interface UniverSheetConfig {+ toolBarConfig?: SheetToolBarConfig;+}diff --git a/packages/base-component/src/Basics/Observer.ts b/packages/base-component/src/Basics/Observer.tsnew file mode 100644index 0000000000..1fe88689a6--- /dev/null+++ b/packages/base-component/src/Basics/Observer.ts@@ -0,0 +1,19 @@+import { Observable } from '@univer/core';+import { BaseComponentPlugin } from '../BaseComponentPlugin';++export type BaseComponentPluginObserve = {+ onAfterChangeUISkinObservable: Observable<void>;+ onAfterChangeUILocaleObservable: Observable<void>;+ onAfterUniverContainerDidMountObservable: Observable<void>;+};++export function uninstallObserver(plugin: BaseComponentPlugin) {+ plugin.deleteObserve('onAfterChangeUISkinObservable');+ plugin.deleteObserve('onAfterChangeUILocaleObservable');+ plugin.deleteObserve('onAfterUniverContainerDidMountObservable');+}++export function installObserver(plugin: BaseComponentPlugin) {+ plugin.pushToObserve('onAfterChangeUISkinObservable');+ plugin.pushToObserve('onAfterUniverContainerDidMountObservable');+}diff --git a/packages/base-component/src/Common/ComponentManager.ts b/packages/base-component/src/Common/ComponentManager.tsindex 08002be864..6fecb95896 100644--- a/packages/base-component/src/Common/ComponentManager.ts+++ b/packages/base-component/src/Common/ComponentManager.ts@@ -1,3 +1,15 @@export class ComponentManager {- private _componentList: any[] = [];+ private _componentList: Map<string, any>;++ register(name: string, component: any) {+ this._componentList.set(name, component);+ }++ get(name: string) {+ this._componentList.get(name);+ }++ delete(name: string) {+ this._componentList.delete(name);+ }}diff --git a/packages/base-component/src/Controller/ToolbarController.ts b/packages/base-component/src/Controller/ToolbarController.tsnew file mode 100644index 0000000000..1cf44ebded--- /dev/null+++ b/packages/base-component/src/Controller/ToolbarController.ts@@ -0,0 +1,52 @@+import { BaseComponentPlugin } from '../BaseComponentPlugin';+import { DefaultToolbarConfig } from '../Basics/Const/ToolBar/DefaultToolbarConfig';+import { IToolBarItemProps, SheetToolBarConfig, ToolBarConfig } from '../Basics/Interfaces/ToolbarConfig/BaseToolBarConfig';++export class ToolBarController {+ private _plugin: BaseComponentPlugin;++ private _currentConfig: ToolBarConfig;++ private _configList: Map<string, ToolBarConfig>;++ private _toolList: IToolBarItemProps[];++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._currentConfig = DefaultToolbarConfig;++ this._toolList = [+ {+ toolbarType: 1,+ tooltipLocale: 'toolbar.undo',+ name: 'undo',+ customLabel: {+ name: 'ForwardIcon',+ },+ show: this._currentConfig.undoRedo,+ onClick: () => {},+ },+ ];+ }++ // 增加toolbar配置+ addToolbarConfig(id: string, config?: SheetToolBarConfig) {+ if (!config) {+ config = DefaultToolbarConfig;+ }+ this._configList.set(id, config);+ }++ // 删除toolbar配置+ deleteToolbarConfig(id: string) {+ this._configList.delete(id);+ }++ // 设置当前toolbar配置+ setCurrentToolbarConfig(id: string) {+ const config = this._configList.get(id);+ if (!config) return;+ this._currentConfig = config;+ }+}diff --git a/packages/base-component/src/Controller/UniverContainerController.ts b/packages/base-component/src/Controller/UniverContainerController.tsindex df514799c5..0ec2657e54 100644--- a/packages/base-component/src/Controller/UniverContainerController.ts+++ b/packages/base-component/src/Controller/UniverContainerController.ts@@ -1,13 +1,19 @@-import { SheetPlugin } from '@univer/base-sheets';-import { LocaleType, Workbook } from '@univer/core';+import { RenderEngine } from '@univer/base-render';+import { CanvasView } from '@univer/base-sheets';+import { LocaleType, PLUGIN_NAMES } from '@univer/core';import { BaseComponentPlugin } from '../BaseComponentPlugin';import { UniverConfig } from '../Basics';+import { UniverSheetConfig } from '../Basics/Interfaces/UniverSheetConfig';import { UI } from '../UI';+import { UniverContainer } from '../UI/UniverContainer';+import { ToolBarController } from './ToolbarController';export class UniverContainerController {private _plugin: BaseComponentPlugin;- private _sheetPlugin: SheetPlugin;+ private _univerContainer: UniverContainer;++ private _toolbarController: ToolBarController;private _config: UniverConfig;@@ -20,17 +26,41 @@ export class UniverContainerController {config: this._config,changeSkin: this.changeSkin,changeLocale: this.changeLocale,+ getComponent: this.getComponent,+ mountCanvas: this.mountCanvas,};UI.create(config);++ this._toolbarController = new ToolBarController(this._plugin);}+ getComponent = (ref: UniverContainer) => {+ this._univerContainer = ref;+ this._plugin.getObserver('onAfterUniverContainerDidMountObservable')!.notifyObservers();+ };++ mountCanvas = (container: HTMLElement) => {+ const engine = this._plugin.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;+ engine.setContainer(container);+ new CanvasView(engine, this._plugin.getSheetPlugin());++ window.addEventListener('resize', () => {+ engine.resize();+ });++ // should be clear+ setTimeout(() => {+ engine.resize();+ }, 0);+ };+/*** Change skin* @param {String} lang new skin*/changeSkin = () => {// publish- this._plugin.getContext().getObserverManager().getObserver<Workbook>('onAfterChangeUISkinObservable')?.notifyObservers(this._plugin.getContext().getWorkBook());+ this._plugin.getObserver('onAfterChangeUISkinObservable')!.notifyObservers();};/**@@ -47,6 +77,12 @@ export class UniverContainerController {.change(locale as LocaleType);// publish- this._plugin.getContext().getContextObserver('onAfterChangeUILocaleObservable')?.notifyObservers();+ this._plugin.getObserver('onAfterChangeUILocaleObservable')!.notifyObservers();};++ addSheet(config: UniverSheetConfig) {}++ getContentRef() {+ return this._univerContainer.getContentRef();+ }}diff --git a/packages/base-component/src/UI/ToolBar/Const.ts b/packages/base-component/src/UI/ToolBar/Const.tsnew file mode 100644index 0000000000..76d834f9a7--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/Const.ts@@ -0,0 +1,432 @@+export const FONT_SIZE_CHILDREN = [+ {+ label: '9',+ value: 9,+ },+ {+ label: '10',+ value: 10,+ },+ {+ label: '11',+ value: 11,+ },+ {+ label: '12',+ value: 12,+ },+ {+ label: '14',+ value: 14,+ },+ {+ label: '16',+ value: 16,+ },+ {+ label: '18',+ value: 18,+ },+ {+ label: '20',+ value: 20,+ },++ {+ label: '22',+ value: 22,+ },+ {+ label: '24',+ value: 24,+ },+ {+ label: '26',+ value: 26,+ },+ {+ label: '28',+ value: 28,+ },+ {+ label: '36',+ value: 36,+ },+ {+ label: '48',+ value: 48,+ },+ {+ label: '72',+ value: 72,+ },+];++export const FONT_FAMILY_CHILDREN = [+ {+ locale: 'fontFamily.TimesNewRoman',+ style: { 'font-family': 'Times New Roman' },+ value: 'Times New Roman',+ selected: true,+ },+ {+ locale: 'fontFamily.Arial',+ style: { 'font-family': 'Arial' },+ value: 'Arial',+ },+ {+ locale: 'fontFamily.Tahoma',+ style: { 'font-family': 'Tahoma' },+ value: 'Tahoma',+ },+ {+ locale: 'fontFamily.Verdana',+ style: { 'font-family': 'Verdana' },+ value: 'Verdana',+ },+ {+ locale: 'fontFamily.MicrosoftAccorblack',+ style: { 'font-family': '微软雅黑' },+ value: '微软雅黑',+ },+ {+ locale: 'fontFamily.SimSun',+ style: { 'font-family': '宋体' },+ value: '宋体',+ },+ {+ locale: 'fontFamily.SimHei',+ style: { 'font-family': '黑体' },+ value: '黑体',+ },+ {+ locale: 'fontFamily.Kaiti',+ style: { 'font-family': '楷体' },+ value: '楷体',+ },+ {+ locale: 'fontFamily.FangSong',+ style: { 'font-family': '仿宋' },+ value: '仿宋',+ },+ {+ locale: 'fontFamily.NSimSun',+ style: { 'font-family': '新宋体' },+ value: '新宋体',+ },+ {+ locale: 'fontFamily.STXinwei',+ style: { 'font-family': '华文新魏' },+ value: '华文新魏',+ },+ {+ locale: 'fontFamily.STXingkai',+ style: { 'font-family': '华文行楷' },+ value: '华文行楷',+ },+ {+ locale: 'fontFamily.STLiti',+ style: { 'font-family': '华文隶书' },+ value: '华文隶书',+ },+ {+ locale: 'fontFamily.HanaleiFill',+ style: { 'font-family': 'HanaleiFill' },+ value: 'HanaleiFill',+ },+ {+ locale: 'fontFamily.Anton',+ style: { 'font-family': 'Anton' },+ value: 'Anton',+ },+ {+ locale: 'fontFamily.Pacifico',+ style: { 'font-family': 'Pacifico' },+ value: 'Pacifico',+ },+];++export const BORDER_LINE_CHILDREN = [+ {+ locale: 'borderLine.borderTop',+ customSuffix: {+ name: 'TopBorderIcon',+ },+ value: 'top',+ },+ {+ locale: 'borderLine.borderBottom',+ customSuffix: {+ name: 'BottomBorderIcon',+ },+ value: 'bottom',+ },+ {+ locale: 'borderLine.borderLeft',+ customSuffix: {+ name: 'LeftBorderIcon',+ },+ value: 'left',+ },+ {+ locale: 'borderLine.borderRight',+ customSuffix: {+ name: 'RightBorderIcon',+ },+ value: 'right',+ border: true,+ },+ {+ locale: 'borderLine.borderNone',+ customSuffix: {+ name: 'NoneBorderIcon',+ },+ value: 'none',+ },+ {+ locale: 'borderLine.borderAll',+ customSuffix: {+ name: 'FullBorderIcon',+ },+ value: 'all',+ selected: true,+ },+ {+ locale: 'borderLine.borderOutside',+ customSuffix: {+ name: 'OuterBorderIcon',+ },+ value: 'outside',+ },+ {+ locale: 'borderLine.borderInside',+ customSuffix: {+ name: 'InnerBorderIcon',+ },+ value: 'inside',+ },+ {+ locale: 'borderLine.borderHorizontal',+ customSuffix: {+ name: 'StripingBorderIcon',+ },+ value: 'horizontal',+ },+ {+ locale: 'borderLine.borderVertical',+ customSuffix: {+ name: 'VerticalBorderIcon',+ },+ value: 'vertical',+ },+];++export const BORDER_SIZE_CHILDREN = [+ {+ locale: 'borderLine.borderNone',+ value: '',+ },+ {+ customLabel: {+ name: 'BorderThin',+ },+ value: 'BorderThin',+ },+ {+ customLabel: {+ name: 'BorderHair',+ },+ value: 'BorderHair',+ },+ {+ customLabel: {+ name: 'BorderDotted',+ },+ value: 'BorderDotted',+ },+ {+ customLabel: {+ name: 'BorderDashed',+ },+ value: 'BorderDashed',+ },+ {+ customLabel: {+ name: 'BorderDashDot',+ },+ value: 'BorderDashDot',+ },+ {+ customLabel: {+ name: 'BorderDashDotDot',+ },+ value: 'BorderDashDotDot',+ },+ {+ customLabel: {+ name: 'BorderMedium',+ },+ value: 'BorderMedium',+ },+ {+ customLabel: {+ name: 'BorderMediumDashed',+ },+ value: 'BorderMediumDashed',+ },+ {+ customLabel: {+ name: 'BorderMediumDashDot',+ },+ value: 'BorderMediumDashDot',+ },+ {+ customLabel: {+ name: 'BorderMediumDashDotDot',+ },+ value: 'BorderMediumDashDotDot',+ },+ {+ customLabel: {+ name: 'BorderThick',+ },+ value: 'BorderThick',+ },+];++export const MERGE_CHILDREN = [+ {+ locale: 'merge.all',+ value: 'all',+ },+ {+ locale: 'merge.vertical',+ value: 'vertical',+ },+ {+ locale: 'merge.horizontal',+ value: 'horizontal',+ },+ {+ locale: 'merge.cancel',+ value: 'cancel',+ },+];++export const HORIZONTAL_ALIGN_CHILDREN = [+ {+ locale: 'align.left',+ customSuffix: {+ name: 'LeftAlignIcon',+ },+ value: 1,+ },+ {+ locale: 'align.center',+ selected: true,+ customSuffix: {+ name: 'CenterAlignIcon',+ },+ value: 2,+ },+ {+ locale: 'align.right',+ customSuffix: {+ name: 'RightAlignIcon',+ },+ value: 3,+ },+];++export const VERTICAL_ALIGN_CHILDREN = [+ {+ locale: 'align.top',+ customSuffix: {+ name: 'TopVerticalIcon',+ },+ value: 1,+ },+ {+ locale: 'align.middle',+ customSuffix: {+ name: 'CenterVerticalIcon',+ },+ value: 2,+ },+ {+ locale: 'align.bottom',+ customSuffix: {+ name: 'BottomVerticalIcon',+ },+ value: 3,+ },+];++export const TEXT_WRAP_CHILDREN = [+ {+ locale: 'textWrap.overflow',+ customSuffix: {+ name: 'OverflowIcon',+ },+ value: 1,+ },+ {+ locale: 'textWrap.wrap',+ customSuffix: {+ name: 'BrIcon',+ },+ value: 3,+ },+ {+ locale: 'textWrap.clip',+ customSuffix: {+ name: 'CutIcon',+ },+ value: 2,+ },+];++export const TEXT_ROTATE_CHILDREN = [+ {+ locale: 'textRotate.none',+ customSuffix: {+ name: 'TextRotateIcon',+ },+ value: 0,+ },+ {+ locale: 'textRotate.angleUp',+ customSuffix: {+ name: 'TextRotateAngleUpIcon',+ },+ value: -45,+ },+ {+ locale: 'textRotate.angleDown',+ customSuffix: {+ name: 'TextRotateAngleDownIcon',+ },+ value: 45,+ },+ {+ locale: 'textRotate.vertical',+ customSuffix: {+ name: 'TextRotateVerticalIcon',+ },+ value: 'v',+ },+ {+ locale: 'textRotate.rotationUp',+ customSuffix: {+ name: 'TextRotateRotationUpIcon',+ },+ value: -90,+ },+ {+ locale: 'textRotate.rotationDown',+ customSuffix: {+ name: 'TextRotateRotationDownIcon',+ },+ value: 90,+ },+];diff --git a/packages/base-component/src/UI/ToolBar/DataBar.tsx b/packages/base-component/src/UI/ToolBar/DataBar.tsxnew file mode 100644index 0000000000..f0f4350aa8--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/DataBar.tsx@@ -0,0 +1,22 @@+type BarProps = {+ list: Array<Record<string, string>>;+ img: string;+ onClick?: (item: {}, index: number) => void;+};++export const DataBar = (props: BarProps) => {+ const { list, img, onClick } = props;+ const background = `url(${img}) no-repeat`;++ let handleClick = (item: {}, index: number) => {+ onClick?.call(this, item, index);+ };++ return (+ <div style="display: flex;">+ {list.map((item, index) => (+ <div onClick={() => handleClick(item, index)} style={{ width: '28px', height: '26px', background, backgroundPosition: `${item.x} ${item.y}` }}></div>+ ))}+ </div>+ );+};diff --git a/packages/base-component/src/UI/ToolBar/SingleButton.tsx b/packages/base-component/src/UI/ToolBar/SingleButton.tsxnew file mode 100644index 0000000000..094f67b014--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/SingleButton.tsx@@ -0,0 +1,68 @@+import { BaseSingleButtonProps, Component, JSXComponent, SingleButtonComponent } from '@univer/base-component';+import { Button, Tooltip } from '@univer/style-univer';++import styles from './index.module.less';++export interface SingleButtonProps {+ label?: string | JSX.Element;+ icon?: JSX.Element | string | null | undefined;+ tooltip?: string;+ name?: string;+ key?: string;+ onClick?: (...arg: any[]) => void;+ active?: boolean;+ triggerUpdate?: (func: Function) => void;+}+export interface IState {+ active: boolean;+}++class SingleButton extends Component<SingleButtonProps, IState> {+ initialize(props: SingleButtonProps): void {+ // Mount update function, when updating the selection range, the cell formats corresponding to different ranges are different, and the toolbar status and values need to be updated in real time+ const { triggerUpdate, active } = props;+ triggerUpdate && triggerUpdate(this.update.bind(this));++ this.state = {+ active: active || false,+ };+ }++ update(active: boolean) {+ this.setState({ active });+ }++ onClick() {+ this.setState(+ (prevState: IState) => ({+ active: !prevState.active,+ }),+ () => {+ this.props.onClick && this.props.onClick(this.state.active);+ }+ );+ }++ render() {+ const { name, tooltip, label, icon, onClick, key } = this.props;+ const { active } = this.state;+ return (+ <div className={styles.singleButton} key={key}>+ <Tooltip title={tooltip!} placement={'bottom'}>+ <Button type="text" onClick={() => this.onClick()} active={active}>+ {label}+ {icon}+ </Button>+ </Tooltip>+ </div>+ );+ }+}++export class UniverSingleButton implements SingleButtonComponent {+ render(): JSXComponent<BaseSingleButtonProps> {+ return SingleButton;+ }+}++export { SingleButton };diff --git a/packages/base-component/src/UI/ToolBar/ToolBar-zh.md b/packages/base-component/src/UI/ToolBar/ToolBar-zh.mdnew file mode 100644index 0000000000..8e7e52bc10--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/ToolBar-zh.md@@ -0,0 +1,92 @@+---+category: Components+type: 定制+title: ToolBar+subtitle: 工具栏+cover: ''+---++## 介绍++工具栏++## API++工具栏的属性说明如下:++| 属性 | 说明 | 类型 | 默认值 |+| ---------- | --------------------- | --------------------------- | -------------------------- |+| style | 自定义 css 央样式对象 | `JSX.CSSProperties` | - |+| config | 配置项 | `IShowToolBarConfig` | `IShowToolBarConfig` |+| forwardRef | preact refs 引用 | `RefObject<HTMLDivElement>` | - |+| func | 回调挂载 | `object` | `{ addButton: Function; }` |++`IShowToolBarConfig`包含以下配置,默认都为 `true`,可以指定想隐藏的工具栏按钮为`false`++```json+{+ "undoRedo": false, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏+ "paintFormat": false, //格式刷+ "currencyFormat": false, //货币格式+ "percentageFormat": false, //百分比格式+ "numberDecrease": false, // '减少小数位数'+ "numberIncrease": false, // '增加小数位数+ "moreFormats": false, // '更多格式'+ "font": false, // '字体'+ "fontSize": false, // '字号大小'+ "bold": false, // '粗体 (Ctrl+B)'+ "italic": false, // '斜体 (Ctrl+I)'+ "strikethrough": false, // '删除线 (Alt+Shift+5)'+ "underline": false, // '下划线 (Alt+Shift+6)'+ "textColor": false, // '文本颜色'+ "fillColor": false, // '单元格颜色'+ "border": false, // '边框'+ "mergeCell": false, // '合并单元格'+ "horizontalAlignMode": false, // '水平对齐方式'+ "verticalAlignMode": false, // '垂直对齐方式'+ "textWrapMode": false, // '换行方式'+ "textRotateMode": false // '文本旋转方式'+}+```++以下这些配置已经分配到各个插件中了++```json+{+ "link": false, // '插入链接'+ "image": false, // '插入图片'+ "chart": false, // '图表'+ "comment": false, //'批注'+ "pivotTable": false, //'数据透视表'+ "function": false, // '公式'+ "frozenMode": false, // '冻结方式'+ "sort": false, // '排序'+ "filter": false, // '筛选'+ "conditionalalFormat": false, // '条件格式'+ "dataValidation": false, // '数据验证'+ "splitColumn": false, // '分列'+ "screenshot": false, // '截图'+ "findAndReplace": false, // '查找替换'+ "protection": false, // '工作表保护'+ "print": false // '打印'+}+```++## 案例++```jsx+import { ToolBar } from '@univer/style-univer';++const SheetContainer = () => {+ return (+ <ToolBar+ style={{+ display: layout.toolBar ? 'block' : 'none',+ }}+ config={layout.toolBarConfig!}+ func={{ addButton }}+ ref={this.toolBarRef}+ ></ToolBar>+ );+};+```diff --git a/packages/base-component/src/UI/ToolBar/ToolBar.md b/packages/base-component/src/UI/ToolBar/ToolBar.mdnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/base-component/src/UI/ToolBar/ToolBar.tsx b/packages/base-component/src/UI/ToolBar/ToolBar.tsxnew file mode 100644index 0000000000..1546cb9dda--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/ToolBar.tsx@@ -0,0 +1,283 @@+import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, Component, createRef, debounce } from '@univer/base-component';+import { PLUGIN_NAMES } from '@univer/core';+import { IToolBarItemProps } from '../../../Model/ToolBarModel';+import { SheetPlugin } from '../../../SheetPlugin';+import { Select } from '../Common/Select/Select';+import { TextButton } from '../Common/TextButton/TextButton';+import styles from './index.module.less';++interface IProps extends BaseComponentProps {+ style?: JSX.CSSProperties;+ toolList: IToolBarItemProps[];+}++interface IState {+ toolList: IToolBarItemProps[];+ moreToolList: IToolBarItemProps[];+ defaultToolList: IToolBarItemProps[];+ showMore: boolean;+ toolbarListWidths: number[];+ moreText: Record<string, string>;+}++export class ToolBar extends Component<IProps, IState> {+ toolbarRef = createRef();++ moreBtnRef = createRef();++ moreToolRef = createRef();++ SelectRef = createRef();++ private _render: BaseComponentRender;++ clientWidth = 0;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ this.state = {+ // Button contains main button and drop down arrow, translation file contains main and right+ showMore: false,+ toolList: [],+ defaultToolList: [],+ moreToolList: [],+ toolbarListWidths: [],+ moreText: {},+ };+ }++ /**+ * show more tool buttons+ *+ * TODO : 点击其他地方需要隐藏more buttons+ */+ showMore = () => {+ let showMore = this.state.showMore;+ this.setState({ showMore: !showMore });++ if (!showMore) {+ document.addEventListener('click', this.hide, true);+ }+ };++ hide = (e: Event) => {+ if (this.moreToolRef.current.contains(e.target)) return;+ e.stopImmediatePropagation();+ this.setState({ showMore: false });+ document.removeEventListener('click', this.hide, true);+ };++ /**+ * Gets the distance of each button from the parent element+ */+ debounceSetToolbarListWidth = debounce(() => {+ this.setToolbarListWidth();+ }, 50);++ setToolbarListWidth = () => {+ if (!this.clientWidth) {+ this.clientWidth = document.documentElement.clientWidth;+ }+ const list = this.toolbarRef.current.querySelectorAll(`.${styles.toolbarWarp} > div`);+ const moreButtonWidth = this.moreBtnRef.current.clientWidth;+ let width = 60 + moreButtonWidth;+ let index = null;++ const clientWidth = document.documentElement.clientWidth;+ if (clientWidth <= this.clientWidth) {+ // 向左resize+ this.clientWidth = clientWidth;+ for (let i = 0; i < list.length; i++) {+ width += list[i].clientWidth + 6;++ if (width > clientWidth) {+ index = i;+ break;+ }+ }+ if (index !== null) {+ this.setState(+ {+ defaultToolList: this.state.toolList.slice(0, index),+ moreToolList: index ? this.state.toolList.slice(index) : [],+ },+ () => {+ this.resetUl();+ this.forceUpdate();+ }+ );+ }+ } else {+ // 向右resize+ this.clientWidth = clientWidth;+ if (this.state.moreToolList.length) {+ let toolWidth = 30 + moreButtonWidth;+ for (let i = 0; i < list.length; i++) {+ toolWidth += list[i].clientWidth + 6;+ }++ const moreList = this.moreToolRef.current.querySelectorAll(`.${styles.moreTool} > div`);+ let moreIndex = null;+ let last = false; //最后一个元素++ for (let i = 0; i < moreList.length; i++) {+ toolWidth += moreList[i].clientWidth + 6;++ if (toolWidth > clientWidth) {+ moreIndex = i;+ break;+ } else if (i === moreList.length - 1) {+ moreIndex = i;+ last = true;+ }+ }++ if (moreIndex !== null) {+ this.setState(+ {+ defaultToolList: this.state.defaultToolList.concat(this.state.moreToolList.slice(0, last ? moreIndex + 1 : moreIndex)),+ moreToolList: last ? [] : this.state.moreToolList.slice(moreIndex),+ },+ () => {+ this.resetUl();+ this.forceUpdate();+ }+ );+ }+ }+ }+ };++ resetLabel = (toolList: any[]) => {+ const plugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);++ for (let i = 0; i < toolList.length; i++) {+ const item = toolList[i];++ // 优先寻找自定义组件+ if (item.customLabel) {+ const Label = plugin?.getRegisterComponent(item.customLabel.name);+ if (Label) {+ const props = item.customLabel.props ?? {};+ item.label = <Label {...props} />;+ }+ }++ if (item.customSuffix) {+ const Suffix = plugin?.getRegisterComponent(item.customSuffix.name);+ if (Suffix) {+ const props = item.customSuffix.props ?? {};+ item.suffix = <Suffix {...props} />;+ }+ }++ if (item.children) {+ item.children = this.resetLabel(item.children);+ }+ }+ return toolList;+ };++ setToolBar = (toolList: any[], moreText: Record<string, string>) => {+ toolList = this.resetLabel(toolList);++ this.setState(+ {+ toolList,+ defaultToolList: toolList,+ moreText,+ },+ () => {+ this.setToolbarListWidth();+ }+ );+ };++ resetUl = () => {+ const wrapper = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)?.getSheetContainerControl().getContentRef().current!;+ const height = `${(wrapper as HTMLDivElement).offsetHeight}px`;+ const ul = this.toolbarRef.current.querySelectorAll('ul');+ for (let i = 0; i < ul.length; i++) {+ ul[i].style.maxHeight = height;+ }+ };++ componentDidMount() {+ this._context.getObserverManager().getObserver<ToolBar>('onToolBarDidMountObservable')?.notifyObservers(this);+ window.addEventListener('resize', this.debounceSetToolbarListWidth);+ }++ componentWillUnmount() {+ window.removeEventListener('resize', this.debounceSetToolbarListWidth);+ }++ // 渲染dom+ getToolBarList(list: IToolBarItemProps[]) {+ const Tooltip = this._render.renderFunction('Tooltip');++ return list.map((item) => {+ if (item.toolbarType) {+ if (item.show) {+ return (+ <Tooltip title={item.tooltip} placement={'bottom'}>+ <TextButton active={item.active} label={item.label} onClick={item.onClick}></TextButton>+ </Tooltip>+ );+ }+ } else {+ if (item.show) {+ return (+ <Select+ tooltip={item.tooltip}+ type={item.type}+ display={item.display}+ children={item.children}+ customLabel={item.customLabel}+ customSuffix={item.customSuffix}+ label={item.label}+ onClick={item.onClick}+ onKeyUp={item.onKeyUp}+ defaultColor={item.defaultColor}+ hideSelectedIcon={item.hideSelectedIcon}+ className={item.className}+ ></Select>+ );+ }+ }+ return null;+ });+ }++ render() {+ const { defaultToolList, moreToolList, moreText, showMore } = this.state;++ const Button = this._render.renderFunction('Button');+ const Container = this._render.renderFunction('Container');+ const Tooltip = this._render.renderFunction('Tooltip');++ return (+ <Container style={{ position: 'relative' }}>+ <div className={`${styles.toolbarWarp} ${styles.toolbar}`} ref={this.toolbarRef}>+ {this.getToolBarList(defaultToolList)}++ <div ref={this.moreBtnRef} className={styles.moreButton} style={{ visibility: moreToolList.length ? 'visible' : 'hidden' }}>+ <Tooltip title={moreText.tip} placement={'bottom'}>+ <Button type="text" onClick={this.showMore}>+ <div style={{ fontSize: '14px' }}>{moreText.more}</div>+ </Button>+ </Tooltip>+ </div>+ </div>++ {moreToolList.length ? (+ <div style={{ visibility: showMore ? 'visible' : 'hidden' }} className={`${styles.moreTool} ${styles.toolbar}`} ref={this.moreToolRef}>+ {this.getToolBarList(moreToolList)}+ </div>+ ) : (+ ''+ )}+ </Container>+ );+ }+}diff --git a/packages/base-component/src/UI/ToolBar/index.less b/packages/base-component/src/UI/ToolBar/index.lessnew file mode 100644index 0000000000..ce9e6d429b--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/index.less@@ -0,0 +1,310 @@+.universheet-wa-editor.toolbar {+ height: 32px;+ background: var(--bg);+ position: relative;+ padding: 5px 0 3px 15px;+ border-bottom: 1px solid var(--bg);+ white-space: nowrap;+ transition: all 0.2s;+ box-sizing: initial;++ span[role='img'] {+ font-size: 24px;+ display: inline-block;+ }++ span[role='img'].univericon-nextIcon {+ font-size: 13px;+ }++ span[role='img'].univericon-rightIcon {+ font-size: 13px;+ }++ .universheet-toolbar-left-skin {+ width: 15px;+ position: absolute;+ left: 0;+ top: 1px;+ bottom: 1px;+ }++ .universheet-inline-block {+ display: inline-block;+ }++ .universheet-flex {+ display: flex;+ }++ .universheet-toolbar-button,+ .universheet-toolbar-menu-button {+ vertical-align: middle;++ &:hover {+ background: rgba(0, 0, 0, 0.06);+ }++ button {+ min-width: 26px;+ height: 26px;+ padding: 0;+ border: none;+ .toolbar-button();++ span {+ height: 100%;+ vertical-align: text-bottom;+ }+ }+ }++ .universheet-toolbar-button-outer-box,+ .universheet-toolbar-menu-button-outer-box {+ .outer-inner-box();+ }++ .universheet-toolbar-select {+ position: relative;+ }++ .universheet-toolbar-button-inner-box,+ .universheet-toolbar-menu-button-inner-box {+ padding: 0 2px;+ padding: 0;+ text-align: center;+ height: 26px;+ min-width: 26px;+ font-size: 12px;+ }++ .universheet-toolbar-menu-button-caption {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ margin-left: 1px;+ text-align: center;+ height: 100%;+ }++ .universheet-toolbar-menu-button-text {+ width: 55px !important;+ }++ .universheet-toolbar-separator {+ line-height: normal;+ list-style: none;+ outline: 0;+ overflow: hidden;+ padding: 0;+ text-decoration: none;+ width: 0;+ height: 20px;+ vertical-align: top;+ border-left: 1px solid #e0e0e0;+ margin: 5px 1px;+ }++ .universheet-toolbar-combo-button {+ font-weight: 700;+ vertical-align: inherit;+ margin: 0 1px;+ .toolbar-button();+ }++ .universheet-toolbar-combo-button-inner-box,+ .universheet-toolbar-combo-button-outer-box {+ .outer-inner-box();+ }++ .universheet-toolbar-zoom-combobox .universheet-toolbar-combo-button-caption {+ width: 36px !important;+ }++ .universheet-toolbar-combo-button-caption {+ padding: 0;+ margin: 0 0 0 -3px;+ }++ .universheet-toolbar-textinput {+ -webkit-border-radius: 1px;+ -moz-border-radius: 1px;+ border-radius: 1px;+ border: 1px solid #d9d9d9;+ border-top: 1px solid silver;+ font-size: 13px;+ height: 25px;+ padding: 1px 0 1px 8px;+ }++ .universheet-toolbar-combo-button-input {+ background: 0 0;+ border: 1px solid transparent !important;+ color: var(--text-color);+ font-family: Arial, sans-serif !important;+ font-size: 11px !important;+ font-weight: 700 !important;+ height: 20px !important;+ overflow: hidden !important;+ color: rgba(0, 0, 0, 0.7);+ height: 22px !important;+ width: 22px;+ }++ .universheet-cols-menu {+ .menu-button();+ width: 252px;+ left: 0;+ top: 26px;+ display: none;+ }++ .universheet-cols-menu .universheet-cols-menuitem-hover,+ .universheet-cols-menu .universheet-cols-menuitem:hover {+ background-color: #efefef;+ }++ .universheet-cols-menu .universheet-cols-menuitem {+ position: relative;+ color: var(--text-color);+ cursor: pointer;+ list-style: none;+ margin: 0;+ padding: 1px 6em 1px 20px;+ white-space: nowrap;+ padding-left: 8px;+ vertical-align: middle;+ padding-right: 24px;+ user-select: none;+ line-height: 16px;+ }++ .universheet-submenu-arrow {+ -webkit-transition: all 218ms;+ -moz-transition: all 218ms;+ -o-transition: all 218ms;+ transition: all 218ms;+ font-size: 12px;+ left: auto;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ padding-right: 0;+ position: absolute;+ text-align: right;+ opacity: 0.5;+ color: #000;+ user-select: none;+ font-family: Arial;+ }++ .universheet-toolbar-dblbutton {+ .universheet-toolbar-next-button {+ border-left: 1px solid transparent;+ position: relative;++ .universheet-next-menu {+ position: absolute;+ z-index: 100;+ background-color: #fff;+ box-shadow: var(--box-shadow-base);+ font-size: 12px;+ width: fit-content;++ .univer-menu-item > div {+ width: 100%;+ display: flex;+ justify-content: space-between;+ box-sizing: border-box;+ padding: 0 5px 0 0;++ .universheet-next-menu-icon {+ width: 25px;++ & ~ div {+ flex: 1;+ display: flex;+ justify-content: space-between;+ align-items: center;+ }+ }+ }++ svg {+ font-size: 24px;+ vertical-align: top;+ }+ }++ svg {+ font-size: 12px;+ vertical-align: middle;+ }+ }++ .universheet-color-bottom {+ width: 10px;+ margin: 0 auto;+ outline: 2px solid;+ position: relative;+ bottom: 7px;+ }++ button.univer-btn {+ min-width: 15px;++ &:active {+ background: transparent !important;+ }+ }++ :hover .universheet-toolbar-next-button {+ border-left: 1px solid #e0e0e0;+ }+ }+}++// 重复样式+.outer-inner-box() {+ border: 0;+ vertical-align: top;+ margin: 0;+ padding: 0;+}++.toolbar-button() {+ -webkit-border-radius: 2px;+ -moz-border-radius: 2px;+ border-radius: 2px;+ -webkit-user-select: none;+ -moz-user-select: none;+ -ms-user-select: none;+ background: 0;+ border: 1px solid transparent;+ outline: 0;+ padding: 0;+ list-style: none;+ font-size: 11px;+ text-decoration: none;+ cursor: default;+ height: 26px;+ line-height: 26px;+ color: var(--text-color);+}++.menu-button() {+ border-radius: 0;+ box-shadow: 0 2px 4px rgb(0 0 0 / 20%);+ transition: opacity 218ms;+ background: #fff;+ border: 1px solid rgba(0, 0, 0, 0.2);+ cursor: default;+ font-size: 13px;+ margin: 0;+ outline: 0;+ padding: 6px 0;+ position: absolute;+ z-index: 100;+ box-sizing: border-box;+ user-select: none;+}diff --git a/packages/base-component/src/UI/ToolBar/index.module.css b/packages/base-component/src/UI/ToolBar/index.module.cssnew file mode 100644index 0000000000..8245552da9--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/index.module.css@@ -0,0 +1,98 @@+.toolbar-warp {+ max-height: fit-content;+ width: 100%;+ overflow: unset;+ box-sizing: border-box;+ font-size: var(--font-size);+ background-color: var(--bg);+ position: relative;+ display: flex;+ align-items: center;+ border-bottom: 1px solid var(--border-color-base);+}+.toolbar-warp .single-button.more-hide {+ display: none;+}+.toolbar-warp .single-button.more-show {+ display: block;+}+.toolbar {+ max-width: 100%;+ color: var(--text-color);+ padding: 0 15px;+ height: 40px;+ position: relative;+ display: flex;+ align-items: center;+}+.toolbar > div {+ height: 26px;+ display: inline-block;+ vertical-align: middle;+ margin: 0 3px;+ cursor: pointer;+}+.toolbar > div.select-button:hover {+ background-color: #efefef;+}+.toolbar .cols-menu {+ overflow-y: auto;+}+.toolbar .select-label-string .drop-content > div {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ width: 90px;+}+.toolbar .select-double-string .drop-content > div {+ width: 24px;+}+.toolbar .select-color-picker-parent .select-item-content {+ width: 100%;+}+.toolbar .select-color-picker-parent ul {+ padding: 0;+}+.toolbar .select-color-picker-parent .select-color-picker {+ padding: 0;+}+.toolbar .select-color-picker-parent .select-color-picker .select-item {+ padding: 0;+}+.toolbar .select-line-bold-parent .select-item-content {+ width: 100%;+}+.toolbar button {+ padding: 0;+ height: 26px;+}+.toolbar span[role='img'].univericon-nextIcon {+ font-size: 12px;+}+.more-button {+ position: absolute;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ padding: 0px;+ line-height: 1;+}+.more-button.more-show {+ display: block;+}+.more-tool {+ padding: 0 10px;+ background-color: var(--bg);+ box-shadow: var(--box-shadow-base);+ position: absolute;+ right: 2em;+ top: 40px;+ z-index: 100;+}+.more-tool.more-show {+ display: flex;+}+.more-tool button {+ padding: 0px;+ line-height: 1;+}diff --git a/packages/base-component/src/UI/ToolBar/index.module.less b/packages/base-component/src/UI/ToolBar/index.module.lessnew file mode 100644index 0000000000..9a11e2623e--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/index.module.less@@ -0,0 +1,139 @@+.toolbar-warp {+ max-height: fit-content;+ width: 100%;+ overflow: unset;+ box-sizing: border-box;+ font-size: var(--font-size);+ background-color: var(--bg);+ position: relative;+ display: flex;+ align-items: center;+ border-bottom: 1px solid var(--border-color-base);++ .single-button {+ &.more-hide {+ display: none;+ }++ &.more-show {+ display: block;+ }+ }+}++.toolbar {+ max-width: 100%;+ color: var(--text-color);+ padding: 0 15px;+ height: 40px;+ position: relative;+ display: flex;+ align-items: center;++ >div {+ height: 26px;+ display: inline-block;+ vertical-align: middle;+ margin: 0 3px;+ cursor: pointer;++ &.select-button:hover {+ background-color: #efefef;+ }+ }++ .cols-menu {+ overflow-y: auto;+ }++ .select-label-string {+ .drop-content {+ >div {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ width: 90px;+ }+ }+ }++ .select-double-string {+ .drop-content {+ >div {+ width: 24px;+ }+ }+ }++ .select-color-picker-parent {+ .select-item-content {+ width: 100%;+ }++ ul {+ padding: 0;+ }++ .select-color-picker {+ padding: 0;++ .select-item {+ padding: 0;+ }+ }+ }++ .select-line-bold-parent {+ .select-item-content {+ width: 100%;+ }+ }++ button {+ padding: 0;+ height: 26px;+ }++ span[role='img'].univericon-nextIcon {+ font-size: 12px;+ }+}++.more-button {+ position: absolute;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ .button();++ &.more-show {+ display: block;+ }+}++.more-tool {+ // height: 40px;+ // display: none;+ // align-items: center;+ padding: 0 10px;+ background-color: var(--bg);+ box-shadow: var(--box-shadow-base);+ position: absolute;+ right: 2em;+ top: 40px;+ z-index: 100;++ &.more-show {+ display: flex;+ }++ button {+ .button();+ // font-size: 24px;+ }+}++.button() {+ padding: 0px;+ line-height: 1;+}\ No newline at end of filediff --git a/packages/base-component/src/UI/ToolBar/index.ts b/packages/base-component/src/UI/ToolBar/index.tsnew file mode 100644index 0000000000..a6b74775e1--- /dev/null+++ b/packages/base-component/src/UI/ToolBar/index.ts@@ -0,0 +1,2 @@+export * from './ToolBar';+export * from './SingleButton';diff --git a/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx b/packages/base-component/src/UI/UniverContainer/UniverContainer.tsxindex 9b1ff0e6d6..2993084d04 100644--- a/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx+++ b/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx@@ -1,12 +1,21 @@+import { Tools } from '@univer/core';+import { Container, Content, Footer, Header, Layout, Sider } from '@univer/style-univer';+import cssVars from 'css-vars-ponyfill';+import defaultSkin from '@univer/style-univer/assets/css/skin/default.module.less';+import darkSkin from '@univer/style-univer/assets/css/skin/dark.module.less';+import greenSkin from '@univer/style-univer/assets/css/skin/green.module.less';+import { BaseComponentProps } from '../../BaseComponent';import { IShowContainerConfig, UniverConfig } from '../../Basics';+import { AppContext } from '../../Common';+import { Component, createRef } from '../../Framework';+import style from './index.module.less';-// app context for skin and Locale-import { Component } from '../../Framework';--export interface BaseSheetContainerProps {+export interface BaseSheetContainerProps extends BaseComponentProps {config: UniverConfig;+ container?: HTMLElement;changeSkin: () => void;changeLocale: (locale: string) => void;+ mountCanvas?: (container: HTMLElement) => void;}// Types for state@@ -20,273 +29,281 @@ interface IState {* One universheet instance DOM container*/export class UniverContainer extends Component<BaseSheetContainerProps, IState> {+ leftContentLeft: number;++ leftContentTop: number;++ rightBorderX: number;++ rightBorderY: number;++ splitLeftRef = createRef<HTMLDivElement>();++ contentRef = createRef<HTMLDivElement>();++ constructor(props: BaseSheetContainerProps) {+ super(props, { coreContext: props.config.context });+ const defaultSkin = props.config.skin ?? 'default';+ // init state+ this.state = {+ layout: {},+ currentLocale: props.config.locale ?? 'zh',+ currentSkin: defaultSkin,+ };+ this.changeSkin(props.container!, defaultSkin);+ }++ componentDidMount() {+ this.props.getComponent?.(this);+ // this.props.mountCanvas?.(this.getContentRef().current!);+ }++ /**+ * split mouse down+ * @param e+ */+ handleSplitBarMouseDown = (e: MouseEvent) => {+ e = e || window.event; // Compatible with IE browser+ // Store the current mouse position+ this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;+ this.leftContentTop = this.splitLeftRef.current?.getBoundingClientRect().top!;+ const mainContainer = this.splitLeftRef.current?.parentElement;+ this.rightBorderX = mainContainer?.getBoundingClientRect()?.width!;+ this.rightBorderY = mainContainer?.getBoundingClientRect()?.height!;+ document.addEventListener('mousemove', this.handleSplitBarMouseMove, false);+ document.addEventListener('mouseup', this.handleSplitBarMouseUp, false);+ };++ /**+ * split mouse move+ * @param e+ */+ handleSplitBarMouseMove = (e: MouseEvent) => {+ e = e || window.event; // Compatible with IE browser+ let diffLeft = e.clientX - this.leftContentLeft;+ let diffTop = e.clientY - this.leftContentTop;+ // Prevent crossing borders+ diffLeft = diffLeft >= this.rightBorderX ? this.rightBorderX : diffLeft;+ diffTop = diffTop >= this.rightBorderY ? this.rightBorderY : diffTop;+ // set new width+ if (this.state.layout.contentSplit === 'vertical') {+ this.splitLeftRef.current!.style.height = `${diffTop}px`;+ } else {+ this.splitLeftRef.current!.style.width = `${diffLeft}px`;+ }+ };++ /**+ * split mouse up+ * @param e+ */+ handleSplitBarMouseUp = (e: MouseEvent) => {+ document.removeEventListener('mousemove', this.handleSplitBarMouseMove, false);+ document.removeEventListener('mouseup', this.handleSplitBarMouseUp, false);+ };++ getContentRef() {+ return this.contentRef;+ }++ getSplitLeftRef() {+ return this.splitLeftRef;+ }++ handleChangeSkin(e: Event) {+ const { changeSkin } = this.props;+ const target = e.target as HTMLSelectElement;+ const skin = target.value;+ this.setState(+ {+ currentSkin: skin,+ },+ () => {+ this.changeSkin(this.props.container!, skin);+ }+ );+ changeSkin();+ }++ /**+ * Modify Dom Skin+ */+ changeSkin(container: HTMLElement, skin: string) {+ // Collect all skins+ let root = document.documentElement;+ // get all skins+ const skins = {+ default: defaultSkin,+ dark: darkSkin,+ green: greenSkin,+ };+ // 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(container.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(+ `#${container.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;+ }+ }+ }+ }++ setLocale(e: Event) {+ const { changeLocale } = this.props;+ const target = e.target as HTMLSelectElement;+ const locale = target.value;+ // You must use setState to trigger the re-rendering of the child component+ this.setState(+ {+ currentLocale: locale,+ },+ () => {+ changeLocale(locale);+ }+ );+ }++ /**+ * Render the component's HTML+ *+ * @returns {void}+ */render() {- return <div>12345</div>;+ const { context } = this.props.config;+ const { layout, currentLocale, currentSkin } = this.state;+ // Set Provider for entire Container+ return (+ <AppContext.Provider+ value={{+ coreContext: context,+ }}+ >+ <Container className={style.layoutContainer}>+ <Layout>+ <Sider style={{ display: layout.outerLeft ? 'block' : 'none' }}></Sider>+ <Layout className={style.mainContent} style={{ position: 'relative' }}>+ <Header style={{ display: layout.header ? 'block' : 'none' }}>+ {/* {layout.infoBar && <InfoBar></InfoBar>}+ {layout.toolBar && <ToolBar toolList={[]}></ToolBar>}+ {layout.formulaBar && <FormulaBar></FormulaBar>} */}+ </Header>+ <Layout>+ <Sider+ style={{+ display: layout.innerLeft ? 'block' : 'none',+ }}+ >+ {/* innerLeft */}+ </Sider>+ <Content className={layout.contentSplit === 'vertical' ? style.contentContainerVertical : style.contentContainerHorizontal}>+ {/* extend main content */}+ {/* <ModalGroup></ModalGroup> */}+ {!!layout.contentSplit && (+ <Container ref={this.splitLeftRef} className={style.contentInnerLeftContainer}>+ <div className={style.hoverCursor} onMouseDown={this.handleSplitBarMouseDown}></div>+ </Container>+ )}+ <Container ref={this.contentRef} className={style.contentInnerRightContainer}>+ {/* <RightMenu /> */}+ <div style={{ position: 'fixed', right: '200px', top: '10px', fontSize: '14px' }}>+ <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>皮肤</span>+ <select value={currentSkin} onChange={this.handleChangeSkin.bind(this)} style={{ width: 55 }}>+ <option value="default">默认</option>+ <option value="dark">暗黑</option>+ <option value="green">绿色</option>+ </select>+ <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>语言</span>+ <select value={currentLocale} onChange={this.setLocale.bind(this)} style={{ width: 55 }}>+ <option value="en">English</option>+ <option value="zh">中文</option>+ </select>+ </div>+ </Container>+ </Content>+ <Sider+ style={{+ display: layout.innerRight ? 'block' : 'none',+ }}+ >+ {/* innerRight */}+ {/* <SideGroup></SideGroup> */}+ </Sider>+ </Layout>+ <Footer+ style={{+ display: layout.footer ? 'block' : 'none',+ }}+ >+ {/* {layout.sheetBar && <SheetBar></SheetBar>} */}+ {/* {layout.countBar && <CountBar></CountBar>} */}+ </Footer>+ </Layout>+ <Sider+ style={{+ display: layout.outerRight ? 'block' : 'none',+ }}+ className={style.outerRightContainer}+ ></Sider>+ </Layout>+ </Container>+ </AppContext.Provider>+ );}- // splitLeftRef = createRef<HTMLDivElement>();- // contentRef = createRef<HTMLDivElement>();- // layoutContainerRef = createRef<HTMLDivElement>();- // leftContentLeft: number;- // leftContentTop: number;- // rightBorderX: number;- // rightBorderY: number;- // private _render: BaseComponentRender;- // constructor(props: BaseSheetContainerProps) {- // super(props, { coreContext: props.config.context });- // const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;- // this._render = component.getComponentRender();- // // init state- // this.state = {- // layout: {},- // currentLocale: '',- // currentSkin: props.config.skin,- // };- // this.changeSkin(props.config.container, props.config.skin);- // }- // getContentRef() {- // return this.contentRef;- // }- // getSplitLeftRef() {- // return this.splitLeftRef;- // }- // getLayoutContainerRef() {- // return this.layoutContainerRef;- // }- // /**- // * split mouse down- // * @param e- // */- // handleSplitBarMouseDown = (e: MouseEvent) => {- // e = e || window.event; // Compatible with IE browser- // // Store the current mouse position- // this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;- // this.leftContentTop = this.splitLeftRef.current?.getBoundingClientRect().top!;- // const mainContainer = this.splitLeftRef.current?.parentElement;- // this.rightBorderX = mainContainer?.getBoundingClientRect()?.width!;- // this.rightBorderY = mainContainer?.getBoundingClientRect()?.height!;- // document.addEventListener('mousemove', this.handleSplitBarMouseMove, false);- // document.addEventListener('mouseup', this.handleSplitBarMouseUp, false);- // };- // handleChangeSkin(e: Event) {- // const { changeSkin } = this.props;- // const target = e.target as HTMLSelectElement;- // const skin = target.value;- // this.setState(- // {- // currentSkin: skin,- // },- // () => {- // this.changeSkin(this.props.config.container, skin);- // }- // );- // changeSkin();- // }- // /**- // * Modify Dom Skin- // */- // changeSkin(container: HTMLElement, skin: string) {- // // Collect all skins- // let root = document.documentElement;- // // get all skins- // const skins = {- // default: defaultSkin,- // dark: darkSkin,- // green: greenSkin,- // };- // // 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(container.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(- // `#${container.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;- // }- // }- // }- // }- // setLocale(e: Event) {- // const { changeLocale } = this.props;- // const target = e.target as HTMLSelectElement;- // const locale = target.value;- // // You must use setState to trigger the re-rendering of the child component- // this.setState(- // {- // currentLocale: locale,- // },- // () => {- // changeLocale(locale);- // }- // );- // }- // /**- // * split mouse move- // * @param e- // */- // handleSplitBarMouseMove = (e: MouseEvent) => {- // e = e || window.event; // Compatible with IE browser- // let diffLeft = e.clientX - this.leftContentLeft;- // let diffTop = e.clientY - this.leftContentTop;- // // Prevent crossing borders- // diffLeft = diffLeft >= this.rightBorderX ? this.rightBorderX : diffLeft;- // diffTop = diffTop >= this.rightBorderY ? this.rightBorderY : diffTop;- // // set new width- // if (this.state.layout.contentSplit === 'vertical') {- // this.splitLeftRef.current!.style.height = `${diffTop}px`;- // } else {- // this.splitLeftRef.current!.style.width = `${diffLeft}px`;- // }- // };- // /**- // * split mouse up- // * @param e- // */- // handleSplitBarMouseUp = (e: MouseEvent) => {- // document.removeEventListener('mousemove', this.handleSplitBarMouseMove, false);- // document.removeEventListener('mouseup', this.handleSplitBarMouseUp, false);- // };- // componentDidMount() {- // this.getContext().getPluginManager().getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET).getObserver('onSheetContainerDidMountObservable')?.notifyObservers(this);- // }- // /**- // * Render the component's HTML- // *- // * @returns {void}- // */- // render() {- // const { context } = this.props.config;- // const { layout, currentLocale, currentSkin } = this.state;- // // Set Provider for entire Container- // return (- // <AppContext.Provider- // value={{- // coreContext: context,- // }}- // >- // <Container ref={this.layoutContainerRef} className={style.layoutContainer}>- // <Layout>- // <Sider style={{ display: layout.outerLeft ? 'block' : 'none' }}></Sider>- // <Layout className={style.mainContent} style={{ position: 'relative' }}>- // <Header style={{ display: layout.header ? 'block' : 'none' }}>- // {layout.infoBar && <InfoBar></InfoBar>}- // {layout.toolBar && <ToolBar toolList={[]}></ToolBar>}- // {layout.formulaBar && <FormulaBar></FormulaBar>}- // </Header>- // <Layout>- // <Sider- // style={{- // display: layout.innerLeft ? 'block' : 'none',- // }}- // >- // {/* innerLeft */}- // </Sider>- // <Content className={layout.contentSplit === 'vertical' ? style.contentContainerVertical : style.contentContainerHorizontal}>- // {/* extend main content */}- // <ModalGroup></ModalGroup>- // {!!layout.contentSplit && (- // <Container ref={this.splitLeftRef} className={style.contentInnerLeftContainer}>- // <div className={style.hoverCursor} onMouseDown={this.handleSplitBarMouseDown}></div>- // </Container>- // )}- // <Container ref={this.contentRef} className={style.contentInnerRightContainer}>- // <RightMenu />- // <div style={{ position: 'fixed', right: '200px', top: '10px', fontSize: '14px' }}>- // <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>皮肤</span>- // <select value={currentSkin} onChange={this.handleChangeSkin.bind(this)} style={{ width: 55 }}>- // <option value="default">默认</option>- // <option value="dark">暗黑</option>- // <option value="green">绿色</option>- // </select>- // <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>语言</span>- // <select value={currentLocale} onChange={this.setLocale.bind(this)} style={{ width: 55 }}>- // <option value="en">English</option>- // <option value="zh">中文</option>- // </select>- // </div>- // </Container>- // </Content>- // <Sider- // style={{- // display: layout.innerRight ? 'block' : 'none',- // }}- // >- // {/* innerRight */}- // <SideGroup></SideGroup>- // </Sider>- // </Layout>- // <Footer- // style={{- // display: layout.footer ? 'block' : 'none',- // }}- // >- // {layout.sheetBar && <SheetBar></SheetBar>}- // {layout.countBar && <CountBar></CountBar>}- // </Footer>- // </Layout>- // <Sider- // style={{- // display: layout.outerRight ? 'block' : 'none',- // }}- // className={style.outerRightContainer}- // ></Sider>- // </Layout>- // </Container>- // </AppContext.Provider>- // );- // }}diff --git a/packages/base-component/src/UI/index.tsx b/packages/base-component/src/UI/index.tsxindex f615e41d24..144926d7fd 100644--- a/packages/base-component/src/UI/index.tsx+++ b/packages/base-component/src/UI/index.tsx@@ -30,6 +30,8 @@ export class UI {univerContainer.id = 'univer';}+ props.container = univerContainer;+render(<UniverContainer {...props} />, univerContainer);}}diff --git "a/packages/base-sheets/src/SheetPlugin\345\211\257\346\234\254.tsx" "b/packages/base-sheets/src/SheetPlugin\345\211\257\346\234\254.tsx"new file mode 100644index 0000000000..c2367bd630--- /dev/null+++ "b/packages/base-sheets/src/SheetPlugin\345\211\257\346\234\254.tsx"@@ -0,0 +1,216 @@+import { BaseComponentPlugin } from '@univer/base-component';+import { Engine, RenderEngine } from '@univer/base-render';+import { SheetContext, Plugin, PLUGIN_NAMES } from '@univer/core';++import { SheetPluginObserve, uninstall } from './Basics/Observer';+import { RightMenuProps } from './Model/RightMenuModel';+import { en, zh } from './Locale';+import { CANVAS_VIEW_KEY } from './View/Render/BaseView';+import { CanvasView } from './View/Render/CanvasView';+import { RightMenuController, InfoBarController, SheetBarControl, CellEditorController, SheetContainerController, ToolBarController } from './Controller';+import { IToolBarItemProps } from './Model/ToolBarModel';+import { ModalGroupController } from './Controller/ModalGroupController';+import { ISheetPluginConfig } from './Basics';+import { FormulaBarController } from './Controller/FormulaBarController';+import { NamedRangeActionExtensionFactory } from './Basics/Register/NamedRangeActionExtension';++/**+ * The main sheet base, construct the sheet container and layout, mount the rendering engine+ */++export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {+ private _config: ISheetPluginConfig;++ private _canvasEngine: Engine;++ private _canvasView: CanvasView;++ private _rightMenuControl: RightMenuController;++ private _toolBarControl: ToolBarController;++ private _infoBarControl: InfoBarController;++ private _formulaBarController: FormulaBarController;++ private _sheetBarControl: SheetBarControl;++ private _cellEditorController: CellEditorController;++ private _sheetContainerController: SheetContainerController;++ private _modalGroupController: ModalGroupController;++ private _componentList: Map<string, any>;++ private _namedRangeActionExtensionFactory: NamedRangeActionExtensionFactory;++ private _component: BaseComponentPlugin;++ constructor(component: BaseComponentPlugin, config: any) {+ super(PLUGIN_NAMES.SPREADSHEET);+ this._component = component;++ this._config = config;+ }++ initialize(context: SheetContext): void {+ this.context = context;++ /**+ * load more Locale object+ */+ context.getLocale().load({+ en,+ zh,+ });++ const engine = this.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;++ let container = this._component.getUniverContainerController().getContentRef().current!;++ this._canvasEngine = engine;++ engine.setContainer(container);+ window.addEventListener('resize', () => {+ engine.resize();+ });++ // should be clear+ setTimeout(() => {+ engine.resize();+ }, 0);++ if (this._canvasView == null) {+ this._canvasView = new CanvasView(engine, this);+ }++ this.registerExtension();+ }++ get config() {+ return this._config;+ }++ onMounted(ctx: SheetContext): void {+ this.initialize(ctx);+ }++ onDestroy(): void {+ super.onDestroy();+ uninstall(this);++ const actionRegister = this.context.getCommandManager().getActionExtensionManager().getRegister();+ actionRegister.delete(this._namedRangeActionExtensionFactory);+ }++ registerExtension() {+ const actionRegister = this.context.getCommandManager().getActionExtensionManager().getRegister();+ this._namedRangeActionExtensionFactory = new NamedRangeActionExtensionFactory(this);+ actionRegister.add(this._namedRangeActionExtensionFactory);+ }++ getCanvasEngine() {+ return this._canvasEngine;+ }++ getCanvasView() {+ return this._canvasView;+ }++ getMainScene() {+ return this._canvasEngine.getScene(CANVAS_VIEW_KEY.MAIN_SCENE);+ }++ getSheetView() {+ return this.getCanvasView().getSheetView();+ }++ getSelectionManager() {+ return this.getSheetView()?.getSelectionManager();+ }++ getCurrentControls() {+ return this.getSelectionManager()?.getCurrentControls();+ }++ getSelectionShape() {+ return this._canvasEngine;+ }++ getMainComponent() {+ return this.getSheetView().getSpreadsheet();+ }++ getLeftTopComponent() {+ return this.getSheetView().getSpreadsheetLeftTopPlaceholder();+ }++ getRowComponent() {+ return this.getSheetView().getSpreadsheetRowTitle();+ }++ getColumnComponent() {+ return this.getSheetView().getSpreadsheetColumnTitle();+ }++ getSpreadsheetSkeleton() {+ return this.getSheetView().getSpreadsheetSkeleton();+ }++ getWorkbook() {+ return this.context.getWorkBook();+ }++ getRightMenuControl() {+ return this._rightMenuControl;+ }++ getToolBarControl() {+ return this._toolBarControl;+ }++ getInfoBarControl() {+ return this._infoBarControl;+ }++ getSheetBarControl() {+ return this._sheetBarControl;+ }++ getCellEditorController() {+ return this._cellEditorController;+ }++ getFormulaBarController() {+ return this._formulaBarController;+ }++ getModalGroupControl() {+ return this._modalGroupController;+ }++ getSheetContainerControl() {+ return this._sheetContainerController;+ }++ addRightMenu(item: RightMenuProps[] | RightMenuProps) {+ this._rightMenuControl && this._rightMenuControl.addItem(item);+ }++ addToolButton(config: IToolBarItemProps) {+ this._toolBarControl && this._toolBarControl.addToolButton(config);+ }++ registerComponent(name: string, component: any, props?: any) {+ this._componentList.set(name, component);+ }++ getRegisterComponent(name: string) {+ return this._componentList.get(name);+ }++ registerModal(name: string, component: any) {+ this._modalGroupController.addModal(name, component);+ }+}diff --git a/packages/base-sheets/src/View/Render/CanvasView.ts b/packages/base-sheets/src/View/Render/CanvasView.tsindex b8b063b530..5a4c5a04e9 100644--- a/packages/base-sheets/src/View/Render/CanvasView.ts+++ b/packages/base-sheets/src/View/Render/CanvasView.ts@@ -18,7 +18,8 @@ export class CanvasView {private _initialize() {const engine = this._engine;const context = this._plugin.getContext();- const workbook = context.getWorkBook();+ // const workbook = context.getWorkBook();+ const workbook = this._plugin.getWorkbook();let worksheet = workbook.getActiveSheet();if (!worksheet) {worksheet = workbook.getSheets()[0];