Skip to content

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.

pull

tonytonychopper1230c83e7d4b4b4
diff --git a/examples/univer-sheet-ts/src/main.tsx b/examples/univer-sheet-ts/src/main.tsx
index e4e325a274..31cf75a939 100644
--- a/examples/univer-sheet-ts/src/main.tsx
+++ b/examples/univer-sheet-ts/src/main.tsx
@@ -42,22 +42,26 @@ const uiDefaultConfigDemo = {
},
};
+const univerConfig = {
+ container: 'universheet',
+};
+
const univer = new Univer();
univer.install(new RenderEngine());
univer.install(new UniverComponentSheet());
-univer.install(new BaseComponentPlugin());
+univer.install(new BaseComponentPlugin(univerConfig));
// 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);
+// 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());
+// univerSheetDemo.installPlugin(new ClipboardPlugin());
+// univerSheetDemo.installPlugin(new ImportXlsxPlugin());
diff --git a/examples/univer-vanilla-ts/src/main.tsx b/examples/univer-vanilla-ts/src/main.tsx
index 1edee0d239..dfa4f08d89 100644
--- a/examples/univer-vanilla-ts/src/main.tsx
+++ b/examples/univer-vanilla-ts/src/main.tsx
@@ -1,107 +1,32 @@
-import { UniverSheet, UniverDoc, UniverSlide } from '@univer/core';
+import { UniverSheet, UniverDoc, UniverSlide, Univer } from '@univer/core';
import { RenderEngine } from '@univer/base-render';
import { UniverComponentSheet } from '@univer/style-univer';
import { SheetPlugin } from '@univer/base-sheets';
-import { DocPlugin } from '@univer/base-docs';
-import { SlidePlugin } from '@univer/base-slides';
import {
DEFAULT_FORMULA_DATA,
+ DEFAULT_FORMULA_DATA_DEMO,
+ DEFAULT_FORMULA_DATA_DEMO1,
FormulaPlugin,
} from '@univer/sheets-plugin-formula';
import { NumfmtPlugin } from '@univer/sheets-plugin-numfmt';
import {
DEFAULT_WORKBOOK_DATA,
+ DEFAULT_WORKBOOK_DATA_DEMO,
+ DEFAULT_WORKBOOK_DATA_DEMO1,
+ DEFAULT_WORKBOOK_DATA_DEMO2,
+ DEFAULT_WORKBOOK_DATA_DEMO3,
+ DEFAULT_WORKBOOK_DATA_DEMO4,
DEFAULT_WORKBOOK_DATA_DOWN,
} from '@univer/common-plugin-data';
import { ClipboardPlugin } from '@univer/sheets-plugin-clipboard';
import { BaseComponentPlugin } from '@univer/base-component';
import { ImportXlsxPlugin } from '@univer/sheets-plugin-import-xlsx';
-const uiDefaultConfigUp = {
- container: 'universheet-up',
- layout: {
- innerRight: false,
- outerLeft: false,
- toolBarConfig: {
- paintFormat: false,
- currencyFormat: false,
- percentageFormat: false,
- numberDecrease: false,
- numberIncrease: false,
- moreFormats: false,
- },
- },
-
- selections: {
- 'sheet-01': [
- {
- selection: {
- startRow: 0,
- endRow: 0,
- startColumn: 3,
- endColumn: 3,
- },
- cell: {
- row: 0,
- column: 3,
- },
- },
- ],
- },
+const univerConfig = {
+ container: 'universheet',
};
-// sheet up
-const univerSheetUp = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA);
-univerSheetUp.installPlugin(new RenderEngine());
-
-univerSheetUp.installPlugin(new UniverComponentSheet());
-univerSheetUp.installPlugin(new SheetPlugin(uiDefaultConfigUp));
-univerSheetUp.installPlugin(new BaseComponentPlugin());
-univerSheetUp.installPlugin(new NumfmtPlugin());
-FormulaPlugin.create(DEFAULT_FORMULA_DATA).installTo(univerSheetUp);
-
-univerSheetUp.installPlugin(new ClipboardPlugin());
-univerSheetUp.installPlugin(new ImportXlsxPlugin());
-
-// sheet down
-const univerSheetDown = UniverSheet.newInstance();
-univerSheetDown.installPlugin(new RenderEngine());
-univerSheetDown.installPlugin(new UniverComponentSheet());
-
-univerSheetDown.installPlugin(
- new SheetPlugin({
- container: 'universheet-down',
- })
-);
-univerSheetDown.installPlugin(new BaseComponentPlugin());
-univerSheetDown.installPlugin(new NumfmtPlugin());
-FormulaPlugin.create().installTo(univerSheetDown);
-
-univerSheetDown.installPlugin(new ClipboardPlugin());
-
-// doc
-
-const docPluginConfig = {
- container: 'univerdoc',
-};
-const univerDoc = UniverDoc.newInstance();
-
-univerDoc.installPlugin(new RenderEngine());
-univerDoc.installPlugin(new UniverComponentSheet());
-
-univerDoc.installPlugin(new DocPlugin(docPluginConfig));
-univerDoc.installPlugin(new BaseComponentPlugin());
-
-// SlidePlugin
-
-const slidePluginConfig = {
- container: 'universlide',
-};
-
-const univerSlide = UniverSlide.newInstance();
-
-univerSlide.installPlugin(new RenderEngine());
-univerSlide.installPlugin(new UniverComponentSheet());
-
-univerSlide.installPlugin(new SlidePlugin(slidePluginConfig));
-univerSlide.installPlugin(new BaseComponentPlugin());
+const univer = new Univer();
+univer.install(new RenderEngine());
+univer.install(new UniverComponentSheet());
+univer.install(new BaseComponentPlugin(univerConfig));
diff --git a/package.json b/package.json
index 14a0b98d55..9dc54b0740 100644
--- a/package.json
+++ b/package.json
@@ -8,10 +8,14 @@
"test:ui": "pnpm run --filter @univer/style-univer test",
"test:e2e": "pnpm run --filter @univer/base-sheets test:play",
"dev": "node scripts/dev",
- "dev:sheet": "pnpm run --filter univer-sheet-ts dev",
- "dev:doc": "pnpm run --filter univer-doc-ts dev",
- "dev:slide": "pnpm run --filter univer-slide-ts dev",
- "dev:all": "pnpm run --filter univer-vanilla-ts 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: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",
+ "d": "pnpm run --filter univer-vanilla-ts dev",
"api": "node scripts/api",
"lighthouse-dev": "start /B node scripts/dev && lighthouse http://127.0.0.1:3103 --output html --output-path ./report.html",
"build": "node scripts/build.js",
diff --git a/packages/base-component/package.json b/packages/base-component/package.json
index dae7e685bf..4b61735e36 100644
--- a/packages/base-component/package.json
+++ b/packages/base-component/package.json
@@ -51,7 +51,9 @@
},
"dependencies": {
"@univer/base-render": "workspace:^0.0.1",
+ "@univer/base-sheets": "workspace:^0.0.1",
"@univer/core": "workspace:^0.0.1",
+ "@univer/style-univer": "workspace:^0.0.1",
"css-vars-ponyfill": "^2.4.6",
"nanoid": "^4.0.0",
"preact": "^10.5.14",
diff --git a/packages/base-component/src/BaseComponent.ts b/packages/base-component/src/BaseComponent.ts
index 67483dbbbf..f57738be95 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 { ComponentClass, ForwardFn } from './Framework';
+import { ComponentChildren, ComponentClass, ForwardFn } from './Framework';
import { Description } from './Components';
// TODO Button const enum
@@ -9,7 +9,10 @@ export interface BaseComponentSheet extends BasePlugin {
getComponentRender(): BaseComponentRender;
getComponentFactory(): BaseComponentFactory;
}
-export interface BaseComponentProps {}
+export interface BaseComponentProps {
+ getSelfRef?: (ref: ComponentChildren) => void; //获取自身组件
+ id?: string; // 组件id
+}
export interface BaseComponent<T = any> {
render(): JSXComponent<T>;
diff --git a/packages/base-component/src/BaseComponentPlugin.ts b/packages/base-component/src/BaseComponentPlugin.ts
index ef79757289..c56838120c 100644
--- a/packages/base-component/src/BaseComponentPlugin.ts
+++ b/packages/base-component/src/BaseComponentPlugin.ts
@@ -1,12 +1,18 @@
import { Plugin, UniverSheet, UniverDoc, UniverSlide, PLUGIN_NAMES } from '@univer/core';
-
+import { UniverConfig } from './Basics/Interfaces/UniverConfig';
import { RegisterManager } from './Common/RegisterManager';
+import { UniverContainerController } from './Controller/UniverContainerController';
export class BaseComponentPlugin extends Plugin {
private _registerManager: RegisterManager;
- constructor() {
+ private _config: UniverConfig;
+
+ private _univerContainerController: UniverContainerController;
+
+ constructor(config: Partial<UniverConfig> = {}) {
super(PLUGIN_NAMES.BASE_COMPONENT);
+ this._config = config;
}
static create() {
@@ -18,11 +24,22 @@ export class BaseComponentPlugin extends Plugin {
}
initialize(): void {
- const context = this.getContext();
-
+ this._univerContainerController = new UniverContainerController(this);
this.setRegisterManager();
}
+ /**
+ * get univer config
+ */
+ getConfig() {
+ return this._config;
+ }
+
+ /**
+ * get sheetPlugin
+ */
+ getSheetPlugin() {}
+
setRegisterManager() {
this._registerManager = new RegisterManager(this);
}
diff --git a/packages/base-component/src/Basics/Interfaces/UniverConfig.ts b/packages/base-component/src/Basics/Interfaces/UniverConfig.ts
new file mode 100644
index 0000000000..09a7e17e20
--- /dev/null
+++ b/packages/base-component/src/Basics/Interfaces/UniverConfig.ts
@@ -0,0 +1,103 @@
+import { ContextBase } from '@univer/core';
+
+/**
+ * ShowContainerConfig
+ */
+export interface IShowContainerConfig {
+ outerLeft?: boolean;
+
+ outerRight?: boolean;
+
+ header?: boolean;
+
+ footer?: boolean;
+
+ innerLeft?: boolean;
+
+ innerRight?: boolean;
+
+ frozenHeaderLT?: boolean;
+
+ frozenHeaderRT?: boolean;
+
+ frozenHeaderLM?: boolean;
+
+ frozenContent?: boolean;
+
+ infoBar?: boolean;
+
+ formulaBar?: boolean;
+
+ countBar?: boolean;
+
+ sheetBar?: boolean;
+
+ // Whether to show the toolbar
+ toolBar?: boolean;
+
+ rightMenu?: boolean;
+
+ 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
+ */
+export interface IHideRightMenuConfig {
+ hideInsertRow?: boolean;
+ hideInsertColumn?: boolean;
+ hideAddRowTop?: boolean;
+ hideAddRowBottom?: boolean;
+ hideAddColumnLeft?: boolean;
+ hideAddColumnRight?: boolean;
+ hideDeleteRow?: boolean;
+ hideDeleteColumn?: boolean;
+ hideHideRow?: boolean;
+ hideShowRow?: boolean;
+ hideRowHeight?: boolean;
+ hideHideColumn?: boolean;
+ hideShowColumn?: boolean;
+ hideColumnWidth?: boolean;
+ hideDeleteCell?: boolean;
+ hideClearContent?: boolean;
+ hideMatrix?: boolean;
+}
+
+export interface ILayout {
+ sheetContainerConfig?: IShowContainerConfig;
+ toolBarConfig?: IShowToolBarConfig;
+ rightMenuConfig?: IHideRightMenuConfig;
+}
+
+export interface UniverConfig {
+ container?: HTMLElement | string;
+ layout?: ILayout;
+ skin?: string;
+ context?: ContextBase;
+}
diff --git a/packages/base-component/src/Basics/Interfaces/index.ts b/packages/base-component/src/Basics/Interfaces/index.ts
index 50f46389e8..82f490a101 100644
--- a/packages/base-component/src/Basics/Interfaces/index.ts
+++ b/packages/base-component/src/Basics/Interfaces/index.ts
@@ -2,4 +2,5 @@
export * from './IClipboardData';
export * from './IDragAndDropData';
export * from './PasteType';
+export * from './UniverConfig';
// @endindex
diff --git a/packages/base-component/src/Common/ComponentManager.ts b/packages/base-component/src/Common/ComponentManager.ts
new file mode 100644
index 0000000000..08002be864
--- /dev/null
+++ b/packages/base-component/src/Common/ComponentManager.ts
@@ -0,0 +1,3 @@
+export class ComponentManager {
+ private _componentList: any[] = [];
+}
diff --git a/packages/base-component/src/Controller/UniverContainerController.ts b/packages/base-component/src/Controller/UniverContainerController.ts
new file mode 100644
index 0000000000..df514799c5
--- /dev/null
+++ b/packages/base-component/src/Controller/UniverContainerController.ts
@@ -0,0 +1,52 @@
+import { SheetPlugin } from '@univer/base-sheets';
+import { LocaleType, Workbook } from '@univer/core';
+import { BaseComponentPlugin } from '../BaseComponentPlugin';
+import { UniverConfig } from '../Basics';
+import { UI } from '../UI';
+
+export class UniverContainerController {
+ private _plugin: BaseComponentPlugin;
+
+ private _sheetPlugin: SheetPlugin;
+
+ private _config: UniverConfig;
+
+ constructor(plugin: BaseComponentPlugin) {
+ this._plugin = plugin;
+
+ this._config = this._plugin.getConfig();
+ // 初始化UI
+ const config = {
+ config: this._config,
+ changeSkin: this.changeSkin,
+ changeLocale: this.changeLocale,
+ };
+ UI.create(config);
+ }
+
+ /**
+ * Change skin
+ * @param {String} lang new skin
+ */
+ changeSkin = () => {
+ // publish
+ this._plugin.getContext().getObserverManager().getObserver<Workbook>('onAfterChangeUISkinObservable')?.notifyObservers(this._plugin.getContext().getWorkBook());
+ };
+
+ /**
+ * Change language
+ * @param {String} lang new language
+ *
+ * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771
+ *
+ */
+ changeLocale = (locale: string) => {
+ this._plugin
+ .getContext()
+ .getLocale()
+ .change(locale as LocaleType);
+
+ // publish
+ this._plugin.getContext().getContextObserver('onAfterChangeUILocaleObservable')?.notifyObservers();
+ };
+}
diff --git a/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx b/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx
new file mode 100644
index 0000000000..9b1ff0e6d6
--- /dev/null
+++ b/packages/base-component/src/UI/UniverContainer/UniverContainer.tsx
@@ -0,0 +1,292 @@
+import { IShowContainerConfig, UniverConfig } from '../../Basics';
+
+// app context for skin and Locale
+import { Component } from '../../Framework';
+
+export interface BaseSheetContainerProps {
+ config: UniverConfig;
+ changeSkin: () => void;
+ changeLocale: (locale: string) => void;
+}
+
+// Types for state
+interface IState {
+ layout: IShowContainerConfig;
+ currentLocale: string;
+ currentSkin: string;
+}
+
+/**
+ * One universheet instance DOM container
+ */
+export class UniverContainer extends Component<BaseSheetContainerProps, IState> {
+ render() {
+ return <div>12345</div>;
+ }
+ // 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/UniverContainer/index.module.less b/packages/base-component/src/UI/UniverContainer/index.module.less
new file mode 100644
index 0000000000..100caac0a5
--- /dev/null
+++ b/packages/base-component/src/UI/UniverContainer/index.module.less
@@ -0,0 +1,77 @@
+.layout-container {
+ // theme
+ background-color: var(--bg);
+ color: var(--text-color);
+ height: 100%;
+
+ .content-container-horizontal {
+ display: flex;
+ min-height: 14em;
+ position: relative;
+
+ .content-inner-left-container {
+ // position: relative;
+ width: 50%;
+ padding-right: 10px;
+ flex: none;
+
+ .hover-cursor {
+ position: absolute;
+ right: 0;
+ top: 0;
+ height: 100%;
+ width: 10px;
+ background: gray;
+ cursor: e-resize;
+ }
+ }
+
+ .content-inner-right-container {
+ width: 50%;
+ flex: 1;
+ // position: relative;
+ }
+ }
+
+ .content-container-vertical {
+ display: flex;
+ flex-direction: column;
+ min-height: 14em;
+ position: relative;
+
+ .content-inner-left-container {
+ // position: relative;
+ height: 50%;
+ padding-bottom: 10px;
+ flex: none;
+
+ .hover-cursor {
+ position: absolute;
+ left: 0;
+ bottom: 0;
+ height: 10px;
+ width: 100%;
+ background: gray;
+ cursor: n-resize;
+ }
+ }
+
+ .content-inner-right-container {
+ height: 50%;
+ flex: 1;
+ }
+ }
+
+ .main-content {
+ background: var(--bg);
+ }
+
+ .outer-right-container {
+ // position: relative;
+ flex: 0 0 280px;
+ > div {
+ position: absolute;
+ width: 100%;
+ }
+ }
+}
diff --git a/packages/base-component/src/UI/UniverContainer/index.ts b/packages/base-component/src/UI/UniverContainer/index.ts
new file mode 100644
index 0000000000..2d4a88ebe5
--- /dev/null
+++ b/packages/base-component/src/UI/UniverContainer/index.ts
@@ -0,0 +1 @@
+export * from './UniverContainer';
diff --git a/packages/base-component/src/UI/index.tsx b/packages/base-component/src/UI/index.tsx
new file mode 100644
index 0000000000..f615e41d24
--- /dev/null
+++ b/packages/base-component/src/UI/index.tsx
@@ -0,0 +1,35 @@
+import { render } from '../Framework';
+import { isElement } from '../Utils';
+import { BaseSheetContainerProps, UniverContainer } from './UniverContainer';
+
+export class UI {
+ constructor(props: BaseSheetContainerProps) {
+ this._initialize(props);
+ }
+
+ static create(props: BaseSheetContainerProps) {
+ return new UI(props);
+ }
+
+ private _initialize(props: BaseSheetContainerProps) {
+ let univerContainer: HTMLElement;
+ const container = props.config.container;
+
+ if (typeof container === 'string') {
+ const containerDOM = document.getElementById(container);
+ if (containerDOM == null) {
+ univerContainer = document.createElement('div');
+ univerContainer.id = container;
+ } else {
+ univerContainer = containerDOM;
+ }
+ } else if (isElement(container)) {
+ univerContainer = container!;
+ } else {
+ univerContainer = document.createElement('div');
+ univerContainer.id = 'univer';
+ }
+
+ render(<UniverContainer {...props} />, univerContainer);
+ }
+}
diff --git a/packages/base-component/src/Utils/util.ts b/packages/base-component/src/Utils/util.ts
index e9766096b2..fa6739e52f 100644
--- a/packages/base-component/src/Utils/util.ts
+++ b/packages/base-component/src/Utils/util.ts
@@ -139,7 +139,7 @@ export function joinClassNames(...args: any) {
}
}
} else {
- result += ` ${item}`;
+ result += item ? ` ${item}` : '';
}
});
return result;
diff --git a/packages/base-sheets/index.html b/packages/base-sheets/index.html
index 42e83ba0bc..d319769a37 100644
--- a/packages/base-sheets/index.html
+++ b/packages/base-sheets/index.html
@@ -19,7 +19,7 @@
<div id="app" style="z-index: 1; position: fixed; font-size: 20px; color: green;"></div>
<!-- <div id="universheet-demo-demo" style="height: 100vh;"></div> -->
<div id="universheet-demo-up" style="height: 100%;"></div>
- <!-- <div id="universheet-demo-down" style="height: 50vh;"></div> -->
+ <div id="universheet-demo-down" style="height: 50vh;"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
diff --git a/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts b/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
index d95342e048..6d0f571eab 100644
--- a/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
+++ b/packages/base-sheets/src/Controller/Selection/ColumnTitleController.ts
@@ -1,4 +1,4 @@
-import { IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
+import { CURSOR_TYPE, Group, IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
import { Nullable } from '@univer/core';
import { DragLineDirection } from './DragLineController';
import { SelectionManager } from './SelectionManager';
@@ -16,26 +16,58 @@ export class ColumnTitleController {
private _currentWidth: number = 0;
- private _highlightItem: Rect;
+ private _highlightItem: Group;
+
+ private _content: Rect;
+
+ private _Item: Rect;
constructor(manager: SelectionManager) {
this._manager = manager;
this._leftTopWidth = this._manager.getSheetView().getSpreadsheetLeftTopPlaceholder().getState().width;
// 创建高亮item
- this._highlightItem = new Rect('HighLightColumnTitle', {
+ this._content = new Rect('HighLightContent', {
width: 0,
height: this._manager.getSheetView().getSpreadsheetSkeleton().columnTitleHeight,
left: 0,
fill: 'rgb(220,220,220,0.5)',
});
-
+ this._Item = new Rect('HighLightItem', {
+ width: 5,
+ height: this._manager.getSheetView().getSpreadsheetSkeleton().columnTitleHeight,
+ left: 0,
+ fill: 'rgb(220,220,220,0.5)',
+ });
+ this._highlightItem = new Group('HighLightColumnTitle', this._content, this._Item);
this._highlightItem.hide();
- this._highlightItem.evented = false;
-
const scene = this._manager.getScene();
scene.addObject(this._highlightItem, 3);
+
+ this._initialize();
+ }
+
+ // 拖拽图标
+ private _initialize() {
+ this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.hide();
+ });
+ this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.cursor = CURSOR_TYPE.COLUMN_RESIZE;
+ });
+ this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.resetCursor();
+ });
+ this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.pointerDown(evt);
+ });
}
pointerDown(e: IPointerEvent | IMouseEvent) {
@@ -45,7 +77,7 @@ export class ColumnTitleController {
this._startOffsetY = evtOffsetY;
const scrollXY = main.getAncestorScrollXY(this._startOffsetX, this._startOffsetY);
const contentRef = this._manager.getPlugin().getSheetContainerControl().getContentRef();
- const clientX = e.clientX - scrollXY.x - this._leftTopWidth - contentRef.current!.getBoundingClientRect().left;
+ const clientX = e.clientX + scrollXY.x - this._leftTopWidth - contentRef.current!.getBoundingClientRect().left;
const columnWidthAccumulation = main.getSkeleton()?.columnWidthAccumulation ?? [];
for (let i = 0; i < columnWidthAccumulation?.length; i++) {
@@ -68,7 +100,10 @@ export class ColumnTitleController {
direction: DragLineDirection.VERTICAL,
end,
start,
- dragUp: this.setColumnWidth.bind(this),
+ dragUp: (width, e) => {
+ this.setColumnWidth(width);
+ this.highlightColumnTitle(e);
+ },
});
this._manager.getDragLineControl().dragDown(e);
}
@@ -111,7 +146,7 @@ export class ColumnTitleController {
this._startOffsetY = evtOffsetY;
const scrollXY = main.getAncestorScrollXY(this._startOffsetX, this._startOffsetY);
const contentRef = this._manager.getPlugin().getSheetContainerControl().getContentRef();
- const clientX = e.clientX - scrollXY.x - this._leftTopWidth - contentRef.current!.getBoundingClientRect().left;
+ const clientX = e.clientX + scrollXY.x - this._leftTopWidth - contentRef.current!.getBoundingClientRect().left;
const columnWidthAccumulation = main.getSkeleton()?.columnWidthAccumulation ?? [];
for (let i = 0; i < columnWidthAccumulation?.length; i++) {
@@ -129,15 +164,18 @@ export class ColumnTitleController {
left = this._leftTopWidth + columnWidthAccumulation[this._index - 1];
}
+ this._content.transformByState({
+ width: this._currentWidth - 5,
+ });
+
+ this._Item.transformByState({
+ left: this._currentWidth - 5,
+ });
+
this._highlightItem.transformByState({
width: this._currentWidth,
left,
});
-
this._highlightItem.show();
}
-
- unHighlightColumnTitle() {
- this._highlightItem.hide();
- }
}
diff --git a/packages/base-sheets/src/Controller/Selection/DragLineController.ts b/packages/base-sheets/src/Controller/Selection/DragLineController.ts
index 8a3436c038..915be64c5e 100644
--- a/packages/base-sheets/src/Controller/Selection/DragLineController.ts
+++ b/packages/base-sheets/src/Controller/Selection/DragLineController.ts
@@ -1,4 +1,4 @@
-import { Group, IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
+import { CURSOR_TYPE, Group, IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
import { Nullable, Observer } from '@univer/core';
import { SelectionManager } from './SelectionManager';
@@ -29,7 +29,7 @@ interface Option {
direction: DragLineDirection;
end: number; // 当前列/行尾距离屏幕距离
start: number; //当前列/行首距离屏幕距离
- dragUp: (distance: Nullable<number>) => void;
+ dragUp: (distance: Nullable<number>, e: IPointerEvent | IMouseEvent) => void;
}
export class DragLineController {
@@ -53,12 +53,16 @@ export class DragLineController {
private _start: number;
- private _dragUp: (distance: Nullable<number>) => void;
+ private _dragUp: (distance: Nullable<number>, e: IPointerEvent | IMouseEvent) => void;
constructor(manager: SelectionManager) {
this._manager = manager;
}
+ getDragLine() {
+ return this._dragLine;
+ }
+
create(option: Option) {
const { direction, end, dragUp, start } = option;
this._direction = direction;
@@ -139,6 +143,7 @@ export class DragLineController {
dragMoving(e: IPointerEvent | IMouseEvent) {
if (this._direction) {
+ this._dragLine.cursor = CURSOR_TYPE.ROW_RESIZE;
if (e.clientY < this._state.distance && this._state.distance - e.clientY >= this._end - this._start - 5) {
//留一丝空隙
return;
@@ -147,6 +152,7 @@ export class DragLineController {
top: e.clientY - this._state.distance,
});
} else {
+ this._dragLine.cursor = CURSOR_TYPE.COLUMN_RESIZE;
if (e.clientX < this._state.distance && this._state.distance - e.clientX >= this._end - this._start - 5) {
//留一丝空隙
return;
@@ -170,7 +176,7 @@ export class DragLineController {
distance = null;
}
}
- this._dragUp(distance);
+ this._dragUp(distance, e);
this._dragLine.dispose();
}
}
diff --git a/packages/base-sheets/src/Controller/Selection/RowTitleController.ts b/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
index 24c33cb00e..c3aebe171d 100644
--- a/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
+++ b/packages/base-sheets/src/Controller/Selection/RowTitleController.ts
@@ -1,4 +1,4 @@
-import { IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
+import { CURSOR_TYPE, Group, IMouseEvent, IPointerEvent, Rect } from '@univer/base-render';
import { Nullable } from '@univer/core';
import { DragLineDirection } from './DragLineController';
import { SelectionManager } from './SelectionManager';
@@ -16,27 +16,60 @@ export class RowTitleController {
private _currentHeight: number = 0;
- private _highlightItem: Rect;
+ private _highlightItem: Group;
+
+ private _content: Rect;
+
+ private _Item: Rect;
constructor(manager: SelectionManager) {
this._manager = manager;
this._leftTopHeight = this._manager.getSheetView().getSpreadsheetLeftTopPlaceholder().getState().height;
+ const width = this._manager.getSheetView().getSpreadsheetSkeleton().rowTitleWidth;
// 创建高亮item
- this._highlightItem = new Rect('HighLightRowTitle', {
- width: this._manager.getSheetView().getSpreadsheetSkeleton().rowTitleWidth,
+ this._content = new Rect('RowTitleContent', {
+ width,
height: 0,
top: 0,
fill: 'rgb(220,220,220,0.5)',
});
-
+ this._Item = new Rect('RowTitleItem', {
+ width,
+ height: 5,
+ top: 0,
+ fill: 'rgb(220,220,220,0.5)',
+ });
+ this._highlightItem = new Group('RowTitleGroup', this._content, this._Item);
this._highlightItem.hide();
- this._highlightItem.evented = false;
-
const scene = this._manager.getScene();
scene.addObject(this._highlightItem, 3);
+
+ this._initialize();
+ }
+
+ // 拖拽图标
+ private _initialize() {
+ this._highlightItem.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.show();
+ });
+ this._highlightItem.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._highlightItem.hide();
+ });
+ this._Item.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.cursor = CURSOR_TYPE.ROW_RESIZE;
+ });
+ this._Item.onPointerLeaveObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this._Item.resetCursor();
+ });
+ this._Item.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.pointerDown(evt);
+ });
}
pointerDown(e: IPointerEvent | IMouseEvent) {
@@ -130,6 +163,14 @@ export class RowTitleController {
top = this._leftTopHeight + rowHeightAccumulation[this._index - 1];
}
+ this._content.transformByState({
+ height: this._currentHeight - 5,
+ });
+
+ this._Item.transformByState({
+ top: this._currentHeight - 5,
+ });
+
this._highlightItem.transformByState({
height: this._currentHeight,
top,
@@ -137,8 +178,4 @@ export class RowTitleController {
this._highlightItem.show();
}
-
- unHighlightRowTitle() {
- this._highlightItem.hide();
- }
}
diff --git a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
index ff7b975b46..cda65b8005 100644
--- a/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
+++ b/packages/base-sheets/src/Controller/Selection/SelectionManager.ts
@@ -640,34 +640,16 @@ export class SelectionManager {
private _rowEventInitial() {
const row = this._rowComponent;
- row.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._rowTitleControl.pointerDown(evt);
- });
row.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
this._rowTitleControl.highlightRowTitle(evt);
});
- row.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._rowTitleControl.highlightRowTitle(evt);
- });
- row.onPointerLeaveObserver.add(() => {
- this._rowTitleControl.unHighlightRowTitle();
- });
}
private _columnEventInitial() {
const column = this._columnComponent;
- column.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._columnTitleControl.pointerDown(evt);
- });
column.onPointerEnterObserver.add((evt: IPointerEvent | IMouseEvent) => {
this._columnTitleControl.highlightColumnTitle(evt);
});
- column.onPointerMoveObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this._columnTitleControl.highlightColumnTitle(evt);
- });
- column.onPointerLeaveObserver.add(() => {
- this._columnTitleControl.unHighlightColumnTitle();
- });
}
private _leftTopEventInitial() {
diff --git a/packages/base-sheets/src/Controller/SheetBarController.ts b/packages/base-sheets/src/Controller/SheetBarController.ts
index 71031893c4..b10b232ec9 100644
--- a/packages/base-sheets/src/Controller/SheetBarController.ts
+++ b/packages/base-sheets/src/Controller/SheetBarController.ts
@@ -1,8 +1,15 @@
-import { BaseUlProps } from '@univer/base-component';
+import { BaseMenuItem, BaseUlProps } from '@univer/base-component';
import { ACTION_NAMES, CommandManager, NameGen, Nullable, PLUGIN_NAMES, SheetActionBase } from '@univer/core';
+import { ColorPicker } from '@univer/style-univer';
import { SheetBarModel } from '../Model/SheetBarModel';
import { SheetBar } from '../View/UI/SheetBar';
import { SheetPlugin } from '../SheetPlugin';
+import styles from '../View/UI/SheetBar/index.module.less';
+
+interface CustomComponent {
+ name: string;
+ props?: Record<string, any>;
+}
interface SheetUlProps extends BaseUlProps {
index: string;
@@ -10,6 +17,12 @@ interface SheetUlProps extends BaseUlProps {
sheetId: string;
}
+interface SheetUl extends BaseMenuItem {
+ locale?: string;
+ customLabel?: CustomComponent;
+ children?: SheetUl[];
+}
+
class SheetBarUIController {
private _barControl: SheetBarControl;
@@ -21,7 +34,7 @@ class SheetBarUIController {
private _sheetList: SheetUlProps[];
- private _sheetUl: BaseUlProps[];
+ private _sheetUl: SheetUl[];
private _menuList: SheetUlProps[];
@@ -31,68 +44,74 @@ class SheetBarUIController {
*/
constructor(barControl: SheetBarControl) {
this._barControl = barControl;
+ const pluginName = barControl.getPlugin().getPluginName();
+
this._sheetUl = [
{
locale: 'sheetConfig.delete',
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.deleteSheet();
},
},
{
locale: 'sheetConfig.copy',
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.copySheet();
},
},
{
locale: 'sheetConfig.rename',
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.reNameSheet();
},
},
{
locale: 'sheetConfig.changeColor',
- icon: 'RightIcon',
+ border: true,
+ className: styles.selectColorPickerParent,
children: [
{
- selectType: 'jsx',
- label: 'ColorPicker',
- onClick: (color: string) => {
- barControl.setSheetColor(color);
+ customLabel: {
+ name: pluginName + ColorPicker.name,
+ props: {
+ onClick: (color: string) => {
+ barControl.setSheetColor(color);
+ },
+ lang: {
+ collapseLocale: 'colorPicker.collapse',
+ customColorLocale: 'colorPicker.customColor',
+ confirmColorLocale: 'colorPicker.confirmColor',
+ cancelColorLocale: 'colorPicker.cancelColor',
+ changeLocale: 'colorPicker.change',
+ },
+ },
},
+ className: styles.selectColorPicker,
},
],
},
{
locale: 'sheetConfig.hide',
- border: true,
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.hideSheet();
},
},
{
locale: 'sheetConfig.unhide',
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.unHideSheet();
},
+ border: true,
},
{
locale: 'sheetConfig.moveLeft',
- border: true,
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.moveSheet('left');
},
},
{
locale: 'sheetConfig.moveRight',
- onClick: (...arg) => {
- arg[1].ref.hideSelect();
+ onClick: () => {
barControl.moveSheet('right');
},
},
@@ -101,6 +120,63 @@ class SheetBarUIController {
this._initializeObserver();
}
+ resetLabel(label: string[] | string) {
+ const locale = this._barControl.getPlugin().getContext().getLocale();
+
+ let str = '';
+
+ if (label instanceof Array) {
+ label.forEach((item) => {
+ if (item.includes('.')) {
+ str += locale.get(item);
+ } else {
+ str += item;
+ }
+ });
+ } else {
+ if (label.includes('.')) {
+ str = locale.get(label);
+ } else {
+ str += label;
+ }
+ }
+
+ return str;
+ }
+
+ findLocale(obj: any) {
+ for (let k in obj) {
+ if (k === 'locale') {
+ obj.label = this.resetLabel(obj[k]);
+ } else if (k.endsWith('Locale')) {
+ const index = k.indexOf('Locale');
+ obj[k.slice(0, index)] = this.resetLabel(obj[k]);
+ } else if (!obj[k].$$typeof) {
+ if (Object.prototype.toString.call(obj[k]) === '[object Object]') {
+ this.findLocale(obj[k]);
+ } else if (Object.prototype.toString.call(obj[k]) === '[object Array]') {
+ obj[k] = this.resetSheetUl(obj[k]);
+ }
+ }
+ }
+
+ return obj;
+ }
+
+ resetSheetUl(sheetUl: SheetUl[]) {
+ for (let i = 0; i < sheetUl.length; i++) {
+ let item = sheetUl[i];
+
+ item = this.findLocale(item);
+
+ if (item.children) {
+ item.children = this.resetSheetUl(item.children);
+ }
+ }
+
+ return sheetUl;
+ }
+
/**
* 获取菜单列表
*/
@@ -135,7 +211,7 @@ class SheetBarUIController {
// manager.requiredObserver<SheetBar>('onSheetBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET);
manager.requiredObserver<SheetBar>('onSheetBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET).add((component) => {
this._sheetBar = component;
- this.resetSheetUl();
+ this._sheetUl = this.resetSheetUl(this._sheetUl);
this._sheetBar.setValue({
sheetList: this._sheetList,
sheetUl: this._sheetUl,
@@ -164,87 +240,12 @@ class SheetBarUIController {
});
});
context.getContextObserver('onAfterChangeUILocaleObservable').add(() => {
- this.resetSheetUl();
+ this._sheetUl = this.resetSheetUl(this._sheetUl);
this._sheetBar.setValue({
sheetUl: this._sheetUl,
});
});
- // context.getContextObserver('onAfterInsertSheetObservable').add(() => {
- // // update data
- // this._initializeData();
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onSheetTabColorChangeObservable').add(() => {
- // // update data
- // this._initializeData();
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onAfterRemoveSheetObservable').add((event) => {
- // const activeSheet = plugin.getContext().getWorkBook().getActiveSheet();
- // if (activeSheet) {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // // update canvas
- // plugin.getCanvasView().updateToSheet(activeSheet);
- // plugin.getMainComponent().makeDirty(true);
- // }
- // });
- // context.getContextObserver('onAfterChangeSheetNameObservable').add(() => {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onAfterChangeActiveSheetObservable').add(() => {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onShowSheetObservable').add(() => {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onSheetOrderObservable').add(() => {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
- // context.getContextObserver('onHideSheetObservable').add(() => {
- // // update data;
- // this._initializeData();
- // // set ui bar sheetList;
- // this._sheetBar.setValue({
- // sheetList: this._sheetList,
- // menuList: this._menuList,
- // });
- // });
+
CommandManager.getActionObservers().add((actionEvent) => {
const action = actionEvent.action as SheetActionBase<any>;
const workbook = action.getWorkBook();
@@ -284,7 +285,6 @@ class SheetBarUIController {
hidden: sheet.isSheetHidden(),
selected: sheet.getStatus() === 1,
onClick: (e: MouseEvent) => {
- console.log('000000000');
const target = e.currentTarget as HTMLDivElement;
this._dataId = target.dataset.id as string;
sheet.showSheet();
@@ -296,7 +296,6 @@ class SheetBarUIController {
.map((sheet, index) => ({
sheetId: sheet.getSheetId(),
label: sheet.getName(),
- icon: 'NextIcon',
index: String(index),
selected: sheet.getStatus() === 1,
color: sheet.getTabColor() as string,
@@ -315,82 +314,16 @@ class SheetBarUIController {
this._dataId = sheets[this._sheetIndex].getSheetId();
}
- /**
- * reset sheet ui
- */
- resetSheetUl() {
- const locale = this._barControl.getPlugin().context.getLocale();
- this._sheetUl.forEach((item: BaseUlProps) => {
- item.label = locale.get(item.locale as string);
- });
- }
-
/**
* 选中sheet
* @param args
*/
- selectSheet(...args: any[]) {
- // const index = args[1].index;
- // this._menuList.forEach((item) => {
- // item.selected = false;
- // });
- // this._menuList[index].selected = true;
- // this._menuList[index].hidden = false;
- // this._sheetList.forEach((item) => {
- // item.selected = false;
- // if (item.index === this._menuList[index].index) {
- // item.hideLi = false;
- // item.selected = true;
- // }
- // });
- // this._sheetBar.setValue({ sheetList: this._sheetList, menuList: this._menuList });
- }
+ selectSheet() {}
/**
* 删除sheet
*/
- deleteSheet() {
- // const index = this._sheetList.findIndex((item) => item.index === this._dataId);
- //
- // let length = 0;
- // this._menuList.forEach((item) => {
- // if (!item.hidden) {
- // length++;
- // }
- // });
- // if (length === 1) {
- // alert('至少需要一个sheet');
- // return;
- // }
- //
- // let selectIndex: number = 0;
- // let flag = false;
- // for (let i = index; i < this._menuList.length; i++) {
- // if (!this._menuList[i].hidden) {
- // selectIndex = i;
- // flag = true;
- // break;
- // }
- // }
- // if (!flag) {
- // for (let i = index - 1; i > -1; i--) {
- // if (!this._menuList[i].hidden) {
- // selectIndex = i;
- // break;
- // }
- // }
- // }
- //
- // this._sheetList[selectIndex].selected = true;
- // this._sheetList.splice(index, 1);
- //
- // this._sheetBar.setValue(
- // {
- // sheetList: this._sheetList,
- // },
- // () => this.sortMenu(selectIndex)
- // );
- }
+ deleteSheet() {}
/**
* 排序menu list
@@ -398,36 +331,12 @@ class SheetBarUIController {
* @param hidden
* @param hideIndex
*/
- sortMenu(index: number, hidden?: boolean, hideIndex?: number) {
- // const menu: SheetUlProps[] = [];
- // this._sheetList.forEach((item) => {
- // this._menuList.forEach((ele) => {
- // if (item.index === ele.index) {
- // ele.selected = false;
- // ele.label = item.label;
- // menu.push(ele);
- // }
- // });
- // });
- // if (hidden && hideIndex) {
- // menu[hideIndex].hidden = true;
- // }
- // menu[index].selected = true;
- // this._sheetBar.setValue({
- // menuList: this._menuList,
- // });
- }
+ sortMenu(index: number, hidden?: boolean, hideIndex?: number) {}
/**
* 复制sheet
*/
- copySheet() {
- // const index = this._sheetList.findIndex((item) => item.index === this._dataId);
- // this.addSheet(`${index + 1}`, {
- // label: `${this._sheetList[index].label}副本`,
- // index: `${this._sheetIndex}`,
- // });
- }
+ copySheet() {}
/**
* 增加sheet
@@ -435,39 +344,6 @@ class SheetBarUIController {
* @param config
*/
addSheet(position?: string, config?: SheetUlProps): void {
- // this._menuList.forEach((item) => {
- // item.selected = false;
- // });
- // if (position) {
- // if (config) {
- // this._sheetList.splice(+position, 0, { ...config, icon: 'NextIcon' });
- // this._menuList.splice(+position, 0, { ...config, selected: true });
- // } else {
- // this._sheetList.splice(+position, 0, {
- // label: `sheet${this._sheetIndex}`,
- // icon: 'NextIcon',
- // index: `${this._sheetIndex}`,
- // });
- // this._menuList.splice(+position, 0, {
- // label: `sheet${this._sheetIndex}`,
- // selected: true,
- // index: `${this._sheetIndex}`,
- // });
- // }
- // } else {
- // this._sheetList.push({
- // label: `sheet${this._sheetIndex}`,
- // icon: 'NextIcon',
- // index: `${this._sheetIndex}`,
- // });
- // this._menuList.push({
- // label: `sheet${this._sheetIndex}`,
- // selected: true,
- // index: `${this._sheetIndex}`,
- // });
- // }
- //
- // this._sheetIndex++;
this._sheetBar.setValue({ sheetList: this._sheetList, menuList: this._menuList }, () => {
this._sheetBar.overGrid();
});
@@ -483,44 +359,7 @@ class SheetBarUIController {
/**
* 隐藏sheet
*/
- hideSheet() {
- // const index = this._sheetList.findIndex((item) => item.index === this._dataId);
- // let length = 0;
- // this._menuList.forEach((item) => {
- // if (!item.hidden) {
- // length++;
- // }
- // });
- // if (length === 1) {
- // alert('至少需要一个sheet');
- // return;
- // }
- // let selectIndex: number = 0;
- // let flag = false;
- // for (let i = index + 1; i < this._menuList.length; i++) {
- // if (!this._menuList[i].hidden) {
- // selectIndex = i;
- // flag = true;
- // break;
- // }
- // }
- // if (!flag) {
- // for (let i = index - 1; i > -1; i--) {
- // if (!this._menuList[i].hidden) {
- // selectIndex = i;
- // break;
- // }
- // }
- // }
- // this._sheetList[index].hideLi = true;
- // this._sheetList[selectIndex].selected = true;
- // this._sheetBar.setValue(
- // {
- // sheetList: this._sheetList,
- // },
- // () => this.sortMenu(selectIndex, true, index)
- // );
- }
+ hideSheet() {}
/**
* 取消隐藏sheet
@@ -533,41 +372,13 @@ class SheetBarUIController {
* 向左向右移动sheet
* @param direct
*/
- moveSheet(direct: string) {
- // const index = this._sheetList.findIndex((item) => item.index === this._dataId);
- // if (direct === 'left') {
- // if (!index) return;
- // const item = this._sheetList.splice(index - 1, 1)[0];
- // this._sheetList.splice(index, 0, item);
- // } else {
- // if (index === this._sheetList.length - 1) return;
- // const item = this._sheetList.splice(index, 1)[0];
- // this._sheetList.splice(index + 1, 0, item);
- // }
- // this._sheetBar.setValue(
- // {
- // sheetList: this._sheetList,
- // },
- // () => this.sortMenu(index)
- // );
- }
+ moveSheet(direct: string) {}
/**
* 重命名sheet
* @param e
*/
- changeSheetName(e: Event) {
- // const target = e.target as HTMLDivElement;
- // const index = this._sheetList.findIndex((item) => item.index === this._dataId);
- // this._sheetList[index].label = target.innerText;
- //
- // this._sheetBar.setValue(
- // {
- // sheetList: this._sheetList,
- // },
- // () => this.sortMenu(index)
- // );
- }
+ changeSheetName(e: Event) {}
/**
* 右击显示菜单
diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.ts
index 438b5ad091..5eb743de0f 100644
--- a/packages/base-sheets/src/Controller/SheetContainerController.ts
+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts
@@ -86,10 +86,6 @@ export class SheetContainerController {
this._initialize();
this._defaultLayout = this._config.layout?.sheetContainerConfig || DefaultSheetContainerConfig;
- // this._defaultLayout =
- // this._config.layout === 'auto'
- // ? Tools.deepClone(DefaultSheetContainerConfig) // The defaultLayout must be cloned, otherwise the layout object will be referenced in multiple instances
- // : Tools.deepMerge(DefaultSheetContainerConfig, this._config.layout?.sheetContainerConfig);
}
private _initialize() {
diff --git a/packages/base-sheets/src/SheetPlugin.tsx b/packages/base-sheets/src/SheetPlugin.tsx
index bd6fb0a884..03e74a2d4f 100644
--- a/packages/base-sheets/src/SheetPlugin.tsx
+++ b/packages/base-sheets/src/SheetPlugin.tsx
@@ -93,7 +93,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve, SheetContext> {
constructor(config: Partial<ISheetPluginConfig> = {}) {
super(PLUGIN_NAMES.SPREADSHEET);
- this._config = Tools.deepMerge(DEFAULT_SPREADSHEET_PLUGIN_DATA, config);
+ this._config = Tools.deepMerge({}, DEFAULT_SPREADSHEET_PLUGIN_DATA, config);
}
register(engineInstance: Engine) {
diff --git a/packages/base-sheets/src/View/UI/SheetBar/SheetBar.tsx b/packages/base-sheets/src/View/UI/SheetBar/SheetBar.tsx
index 7dd69eb035..d0fac65fc2 100644
--- a/packages/base-sheets/src/View/UI/SheetBar/SheetBar.tsx
+++ b/packages/base-sheets/src/View/UI/SheetBar/SheetBar.tsx
@@ -1,13 +1,15 @@
-import { BaseComponentRender, BaseComponentSheet, BaseSheetBarProps, BaseUlProps, Component, createRef, RefObject } from '@univer/base-component';
+import { BaseComponentRender, BaseComponentSheet, BaseMenuItem, BaseSheetBarProps, Component, createRef, RefObject } from '@univer/base-component';
import { Nullable, Observer, PLUGIN_NAMES, Workbook } from '@univer/core';
-import { Ul } from '@univer/style-univer';
+import { Menu } from '@univer/style-univer';
import { SlideTabBar } from '../../../Basics/SlideTabBar/SlideTabBar';
+import { SheetPlugin } from '../../../SheetPlugin';
import styles from './index.module.less';
+import { SheetBarMenu } from './SheetBarMenu';
type SheetState = {
sheetList: BaseSheetBarProps[];
menuList: BaseSheetBarProps[];
- sheetUl: BaseUlProps[];
+ sheetUl: BaseMenuItem[];
addSheet: Nullable<() => void>;
selectSheet: Nullable<() => void>;
contextMenu: Nullable<(e: Event) => void>;
@@ -52,85 +54,53 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
}
- jointJsx(list: BaseSheetBarProps[] | BaseUlProps[]) {
- list.forEach((item: any) => {
- if (item.icon && typeof item.icon === 'string' && /Icon$/.test(item.icon)) {
- const Icon = this._render.renderFunction(item.icon);
- item.icon = <Icon />;
- }
- if (item.selectType && item.selectType === 'jsx') {
- const JSX: any = this._render.renderFunction(item.label);
- // ColorPicker
- item.label = (
- <JSX
- style={{ visibility: 'visible', marginTop: '-60px', marginLeft: '-50px' }}
- onClick={(color: string) => {
- item.onClick(color);
- }}
- />
- );
+ resetLabel(list: any) {
+ const plugin = this._context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET);
+
+ for (let i = 0; i < list.length; i++) {
+ const item = list[i];
+
+ // 优先寻找自定义组件
+ if (item.customLabel) {
+ const Label = plugin?.getRegisterComponent(item.customLabel.name);
+ if (Label) {
+ const props = item.customLabel.props ?? {};
+ item.label = <Label {...props} />;
+ }
}
- if (item.children && item.children.length > 0) {
- this.jointJsx(item.children);
+
+ if (item.children) {
+ item.children = this.resetLabel(item.children);
}
- });
+ }
+ return list;
}
// setstate
setValue = (value: any, fn?: () => void) => {
- const { sheetList, menuList, sheetUl } = value;
+ let { sheetList, menuList, sheetUl } = value;
if (sheetList) {
- this.jointJsx(sheetList);
+ sheetList = this.resetLabel(sheetList);
}
if (menuList) {
- this.jointJsx(menuList);
+ menuList = this.resetLabel(menuList);
}
if (sheetUl) {
- this.jointJsx(sheetUl);
+ sheetUl = this.resetLabel(sheetUl);
}
this.setState((prevState) => ({ ...value }), fn);
};
// 点击按钮左右滑动
scrollLeft = (e: MouseEvent) => {
- // let scroll = this.sheetContentRef.current;
- // if (parseFloat(scroll.style.left) + 50 >= 0) {
- // scroll.style.left = '0px';
- // return;
- // }
- // scroll.style.left = `${parseFloat(scroll.style.left) + 50}px`;
this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() - 50);
};
scrollRight = (e: MouseEvent) => {
- // let scroll = this.sheetContentRef.current;
- // let width = scroll.scrollWidth;
- // let container = this.sheetContainerRef.current;
- // if (width <= container.offsetWidth) {
- // return;
- // }
- // const scrollLeft = parseFloat(scroll.style.left);
- // if (width - Math.abs(scrollLeft) <= container.offsetWidth) {
- // return;
- // }
- // if (width - Math.abs(scrollLeft) - container.offsetWidth <= 50) {
- // scroll.style.left = `${scrollLeft - (width - Math.abs(scrollLeft) - container.offsetWidth)}px`;
- // } else {
- // scroll.style.left = `${scrollLeft - 50}px`;
- // }
this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() + 50);
};
- overGrid = () => {
- // // 超过范围向左移动
- // const scroll = this.sheetContentRef.current;
- // const width = scroll.scrollWidth;
- // const container = this.sheetBarContentRef.current;
- // if (width <= container.offsetWidth / 2) {
- // return;
- // }
- // scroll.style.left = `${container.offsetWidth / 2 - width}px`;
- };
+ overGrid = () => {};
// 右击显示菜单
contextMenu = (e: MouseEvent) => {
@@ -139,10 +109,10 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
};
// 显示下拉
- showSelect = (e: MouseEvent, ref: RefObject<Ul>) => {
+ showSelect = (e: MouseEvent, ref: RefObject<Menu>) => {
e.stopImmediatePropagation();
const current = ref.current;
- if (current) current.showSelect();
+ if (current) current.showMenu(true);
// 点击外部隐藏子组件
window.addEventListener('click', this.hideSelect);
};
@@ -151,8 +121,8 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
hideSelect = (e: MouseEvent) => {
const current = this.ref.current;
const ulCurrent = this.ulRef.current;
- if (current) current.hideSelect();
- if (ulCurrent) ulCurrent.hideSelect();
+ if (current) current.showMenu(false);
+ if (ulCurrent) ulCurrent.showMenu(false);
window.removeEventListener('click', this.hideSelect);
};
@@ -169,7 +139,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
const currentRect = currentTarget.getBoundingClientRect();
const left = `${currentRect.left}px`;
const bottom = `${currentRect.height}px`;
- const ul = this.ulRef.current.ulRef.current;
+ const ul = this.ulRef.current.base;
ul.style.left = left;
ul.style.bottom = bottom;
ul.style.top = 'auto';
@@ -184,14 +154,6 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
if (item) {
item.editor();
}
- // const sheetContentDiv = this.sheetContentRef.current.querySelectorAll('div');
- // Array.from(sheetContentDiv).forEach((node: any) => {
- // if (node.dataset.id === id) {
- // const span = node.querySelector('span');
- // const dblclick = new MouseEvent('dblclick');
- // span?.dispatchEvent(dblclick);
- // }
- // });
};
changeEditable = (e: MouseEvent) => {
@@ -262,10 +224,10 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
if (!addSheet || !selectSheet || !contextMenu) return;
const Button = this._render.renderFunction('Button');
- const Ul = this._render.renderFunction('Ul');
const AddIcon = this._render.renderFunction('AddIcon');
const MenuIcon = this._render.renderFunction('MenuIcon');
const NextIcon = this._render.renderFunction('NextIcon');
+ const Menu = this._render.renderFunction('Menu');
return (
<div className={styles.sheetBar} ref={this.slideTabRoot}>
@@ -274,9 +236,9 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<Button className={styles.sheetBarOptionsButton} onClick={addSheet} type="text">
<AddIcon style={{ fontSize: '20px' }} />
</Button>
- <Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.showSelect(e, this.ref)} type="text">
+ <Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.ref.current.showMenu(true)} type="text">
<MenuIcon style={{ fontSize: '20px' }} />
- <Ul onClick={selectSheet} children={menuList} ref={this.ref} style={{ bottom: '2.2rem', left: '0' }}></Ul>
+ <SheetBarMenu onClick={selectSheet} menu={menuList} ref={this.ref}></SheetBarMenu>
</Button>
</div>
@@ -297,7 +259,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
<span style={{ padding: '2px 5px 2px 5px' }}>{item.label}</span>
</div>
<div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={contextMenu}>
- {item.icon}
+ <NextIcon />
</div>
</div>
<div className={`${styles.slideTabFooter}`}>
@@ -308,7 +270,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</div>
{/* mouse right button context menu */}
- <Ul children={sheetUl} ref={this.ulRef}></Ul>
+ <Menu className={styles.sheetUl} menu={sheetUl} ref={this.ulRef} />
{/* prev next scroll button */}
<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>
diff --git a/packages/base-sheets/src/View/UI/SheetBar/SheetBarMenu.tsx b/packages/base-sheets/src/View/UI/SheetBar/SheetBarMenu.tsx
new file mode 100644
index 0000000000..7c8dc166b6
--- /dev/null
+++ b/packages/base-sheets/src/View/UI/SheetBar/SheetBarMenu.tsx
@@ -0,0 +1,82 @@
+import { BaseComponentRender, BaseComponentSheet, Component, joinClassNames, JSX } from '@univer/base-component';
+import styles from './index.module.less';
+
+interface SheetBarMenuItem {
+ label?: string;
+ hide?: boolean;
+ selected?: boolean;
+ index?: string;
+ sheetId?: string;
+ onClick?: (e?: MouseEvent) => void;
+}
+
+export interface SheetBarMenuProps {
+ menu: SheetBarMenuItem[];
+ style?: JSX.CSSProperties;
+ onClick?: (e?: MouseEvent) => void;
+}
+
+interface IState {
+ show: boolean;
+}
+
+export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {
+ private _render: BaseComponentRender;
+
+ initialize() {
+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;
+ this._render = component.getComponentRender();
+
+ this.state = {
+ show: false,
+ };
+ }
+
+ handleClick(e: MouseEvent, item: SheetBarMenuItem) {
+ const { onClick } = this.props;
+ if (item.onClick) {
+ item.onClick(e);
+ }
+ onClick?.(e);
+ this.showMenu(false);
+ window.removeEventListener('click', this.hideMenu);
+ }
+
+ hideMenu = () => {
+ this.showMenu(false);
+ };
+
+ showMenu(show: boolean) {
+ this.setState(
+ {
+ show,
+ },
+ () => {
+ if (show) {
+ window.addEventListener('click', this.hideMenu, true);
+ }
+ }
+ );
+ }
+
+ render() {
+ const { menu, style } = this.props;
+ const { show } = this.state;
+ const CheckIcon = this._render.renderFunction('CheckIcon');
+ const HideIcon = this._render.renderFunction('HideIcon');
+
+ return (
+ <ul className={styles.sheetBarMenu} style={{ ...style, display: show ? 'block' : ' none' }}>
+ {menu.map((item) => (
+ <li onClick={(e) => this.handleClick(e, item)} className={joinClassNames(styles.sheetBarMenuItem, item.hide ? styles.sheetBarMenuItemHide : '')}>
+ <span className={styles.sheetBarMenuIcon}>
+ {item.hide ? <HideIcon /> : ''}
+ {item.selected ? <CheckIcon /> : ''}
+ </span>
+ {item.label}
+ </li>
+ ))}
+ </ul>
+ );
+ }
+}
diff --git a/packages/base-sheets/src/View/UI/SheetBar/index.module.css b/packages/base-sheets/src/View/UI/SheetBar/index.module.css
new file mode 100644
index 0000000000..93f982d224
--- /dev/null
+++ b/packages/base-sheets/src/View/UI/SheetBar/index.module.css
@@ -0,0 +1,171 @@
+.sheet-bar {
+ position: relative;
+ height: 31px;
+ display: flex;
+ flex-direction: row;
+ background-color: var(--bg);
+}
+.sheet-bar-options {
+ border-right: 1px solid var(--border-color-base);
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ padding-right: 5px;
+}
+.sheet-bar-options-button {
+ padding: 0;
+ margin: 0;
+ border: none;
+ height: initial;
+ line-height: initial;
+ padding-right: 2px;
+}
+.sheet_bar_scroll_button {
+ border: none;
+ border-left: 1px solid var(--border-color-base);
+ padding-left: 5px;
+}
+.slide-tab-bar {
+ user-select: none;
+ max-width: 100%;
+ height: 100%;
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ overflow: auto;
+ overflow-y: hidden;
+ scrollbar-width: none;
+}
+.slide-tab-bar::-webkit-scrollbar {
+ display: none;
+}
+/**
+ 高亮标记
+ */
+.slide-tab-active {
+ position: relative;
+}
+/**
+ Tab Item
+*/
+.slide-tab-item {
+ user-select: none;
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+ cursor: pointer;
+ height: 100%;
+ background-color: var(--bg);
+}
+.slide-tab-item:first-child .slide-tab-divider {
+ opacity: 0;
+}
+.slide-tab-item:hover {
+ background: #efefef;
+}
+.slide-tab-item:hover .slide-tab-divider {
+ opacity: 0;
+}
+.slide-tab-item:hover + .slide-tab-item .slide-tab-divider {
+ opacity: 0;
+}
+/**
+ 内容区域
+*/
+.slide-tab-content {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ flex-grow: 1;
+}
+.slide-tab-title {
+ font-size: 14px;
+ color: #676464;
+ margin-right: 3px;
+ margin-left: 6px;
+}
+.slide-tab-icon {
+ width: 16px;
+ height: 16px;
+ font-size: 15px;
+ color: #a1a1a1;
+ margin-right: 6px;
+}
+.slide-tab-divider {
+ width: 1px;
+ height: 16px;
+ background: var(--border-color-base);
+}
+.slide-tab-active .slide-tab-content {
+ background: #efefef;
+ color: #222;
+}
+.slide-tab-active .slide-tab-divider {
+ opacity: 0;
+}
+.slide-tab-active + .slide-tab-item .slide-tab-divider {
+ opacity: 0;
+}
+/**
+ 底部区域
+ */
+.slide-tab-footer {
+ height: auto;
+ width: 100%;
+ flex-grow: 0;
+}
+.slide-tab-active-bar {
+ height: 2px;
+ width: 100%;
+}
+.slide-tab-active .slide-tab-active-bar {
+ background: #d0d0d0;
+}
+.sheet-ul .cols-menuitem {
+ text-align: left;
+ padding: 5px 5px 5px 25px;
+}
+.sheet-ul .select-color-picker-parent .select-item-content {
+ width: 100%;
+}
+.sheet-ul .select-color-picker-parent ul {
+ padding: 0;
+}
+.sheet-ul .select-color-picker-parent .select-color-picker {
+ padding: 0;
+}
+.sheet-ul .select-color-picker-parent .select-color-picker .select-item {
+ padding: 0;
+}
+.sheet-bar-menu {
+ position: absolute;
+ bottom: 120%;
+ left: 0;
+ padding: 0;
+ border: 1px solid rgba(0, 0, 0, 0.2);
+ border-radius: 0;
+ transition: opacity 218ms;
+ background: var(--bg);
+ margin: 0;
+ outline: 0;
+ z-index: 100;
+ box-sizing: border-box;
+ user-select: none;
+}
+.sheet-bar-menu li {
+ list-style: none;
+}
+.sheet-bar-menu .sheet-bar-menu-item {
+ position: relative;
+ padding: 5px 10px 5px 20px;
+}
+.sheet-bar-menu .sheet-bar-menu-item .sheet-bar-menu-icon {
+ position: absolute;
+ left: 5px;
+ top: 50%;
+ transform: translateY(-50%);
+}
+.sheet-bar-menu .sheet-bar-menu-item-hide {
+ pointer-events: none;
+ color: #eee;
+}
diff --git a/packages/base-sheets/src/View/UI/SheetBar/index.module.less b/packages/base-sheets/src/View/UI/SheetBar/index.module.less
index b4c9d9b8e9..305ced0125 100644
--- a/packages/base-sheets/src/View/UI/SheetBar/index.module.less
+++ b/packages/base-sheets/src/View/UI/SheetBar/index.module.less
@@ -40,6 +40,7 @@
overflow-y: hidden;
scrollbar-width: none;
}
+
.slide-tab-bar::-webkit-scrollbar {
display: none;
}
@@ -63,16 +64,20 @@
height: 100%;
background-color: var(--bg);
}
+
.slide-tab-item:first-child .slide-tab-divider {
opacity: 0;
}
+
.slide-tab-item:hover {
background: #efefef;
}
+
.slide-tab-item:hover .slide-tab-divider {
opacity: 0;
}
-.slide-tab-item:hover + .slide-tab-item .slide-tab-divider {
+
+.slide-tab-item:hover+.slide-tab-item .slide-tab-divider {
opacity: 0;
}
@@ -85,12 +90,14 @@
align-items: center;
flex-grow: 1;
}
+
.slide-tab-title {
font-size: 14px;
color: #676464;
margin-right: 3px;
margin-left: 6px;
}
+
.slide-tab-icon {
width: 16px;
height: 16px;
@@ -98,19 +105,23 @@
color: #a1a1a1;
margin-right: 6px;
}
+
.slide-tab-divider {
width: 1px;
height: 16px;
background: var(--border-color-base);
}
+
.slide-tab-active .slide-tab-content {
background: #efefef;
color: #222;
}
+
.slide-tab-active .slide-tab-divider {
opacity: 0;
}
-.slide-tab-active + .slide-tab-item .slide-tab-divider {
+
+.slide-tab-active+.slide-tab-item .slide-tab-divider {
opacity: 0;
}
@@ -122,10 +133,74 @@
width: 100%;
flex-grow: 0;
}
+
.slide-tab-active-bar {
height: 2px;
width: 100%;
}
+
.slide-tab-active .slide-tab-active-bar {
background: #d0d0d0;
}
+
+.sheet-ul {
+ .cols-menuitem {
+ text-align: left;
+ padding: 5px 5px 5px 25px;
+ }
+
+ .select-color-picker-parent {
+ .select-item-content {
+ width: 100%;
+ }
+
+ ul {
+ padding: 0;
+ }
+
+ .select-color-picker {
+ padding: 0;
+
+ .select-item {
+ padding: 0;
+ }
+ }
+ }
+}
+
+.sheet-bar-menu {
+ position: absolute;
+ bottom: 120%;
+ left: 0;
+ padding: 0;
+ border: 1px solid rgba(0, 0, 0, 0.2);
+ border-radius: 0;
+ transition: opacity 218ms;
+ background: var(--bg);
+ margin: 0;
+ outline: 0;
+ z-index: 100;
+ box-sizing: border-box;
+ user-select: none;
+
+ li {
+ list-style: none;
+ }
+
+ .sheet-bar-menu-item {
+ position: relative;
+ padding: 5px 10px 5px 20px;
+
+ .sheet-bar-menu-icon {
+ position: absolute;
+ left: 5px;
+ top: 50%;
+ transform: translateY(-50%);
+ }
+
+ &-hide {
+ pointer-events: none;
+ color: #eee;
+ }
+ }
+}
\ No newline at end of file
diff --git a/packages/base-sheets/src/main.tsx b/packages/base-sheets/src/main.tsx
index 974585d1ab..c1f14c81c9 100644
--- a/packages/base-sheets/src/main.tsx
+++ b/packages/base-sheets/src/main.tsx
@@ -1,9 +1,9 @@
import { UniverSheet } from '@univer/core';
import { RenderEngine } from '@univer/base-render';
import { UniverComponentSheet } from '@univer/style-univer';
-// import { NumfmtPlugin } from '@univer/sheets-plugin-numfmt';
-import { DEFAULT_WORKBOOK_DATA } from '@univer/common-plugin-data';
-// import { DEFAULT_FORMULA_DATA, FormulaPlugin } from '@univer/sheets-plugin-formula';
+import { NumfmtPlugin } from '@univer/sheets-plugin-numfmt';
+import { DEFAULT_WORKBOOK_DATA, DEFAULT_WORKBOOK_DATA_DOWN } from '@univer/common-plugin-data';
+import { DEFAULT_FORMULA_DATA, DEFAULT_FORMULA_DATA_DOWN, FormulaPlugin } from '@univer/sheets-plugin-formula';
import { SheetPlugin } from './SheetPlugin';
const uiDefaultConfigUp = {
@@ -77,8 +77,8 @@ const uiDefaultConfigDown = {
container: 'universheet-demo-down',
layout: {
sheetContainerConfig: {
- infoBar: true,
- formulaBar: true,
+ infoBar: false,
+ formulaBar: false,
toolBar: true,
sheetBar: true,
countBar: true,
@@ -103,13 +103,13 @@ const uiDefaultConfigDown = {
},
};
-// const univerSheetDown = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DOWN);
-// univerSheetDown.installPlugin(new RenderEngine());
-// univerSheetDown.installPlugin(new UniverComponentSheet());
+const univerSheetDown = UniverSheet.newInstance(DEFAULT_WORKBOOK_DATA_DOWN);
+univerSheetDown.installPlugin(new RenderEngine());
+univerSheetDown.installPlugin(new UniverComponentSheet());
-// univerSheetDown.installPlugin(new SheetPlugin(uiDefaultConfigDown));
-// univerSheetDown.installPlugin(new NumfmtPlugin());
-// FormulaPlugin.create(DEFAULT_FORMULA_DATA_DOWN).installTo(univerSheetDown);
+univerSheetDown.installPlugin(new SheetPlugin(uiDefaultConfigDown));
+univerSheetDown.installPlugin(new NumfmtPlugin());
+FormulaPlugin.create(DEFAULT_FORMULA_DATA_DOWN).installTo(univerSheetDown);
// const uiDefaultConfigDemo = {
// container: 'universheet-demo-demo',