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.

fix: (ui-plugin-sheet) bug

tonytonychopper1230f60cf9f4e30
diff --git a/packages/base-ui/src/BaseComponent.ts b/packages/base-ui/src/BaseComponent.ts
index b93457a97d..623e481d90 100644
--- a/packages/base-ui/src/BaseComponent.ts
+++ b/packages/base-ui/src/BaseComponent.ts
@@ -52,6 +52,7 @@ export interface BaseButtonProps extends BaseComponentProps {
children?: any;
className?: string;
style?: JSX.CSSProperties;
+ unActive?: boolean;
}
export interface BaseCellRangeModalProps extends BaseComponentProps {
placeholderProps?: string;
diff --git a/packages/base-ui/src/BaseComponentPlugin.ts b/packages/base-ui/src/BaseComponentPlugin.ts
index 33bcd68cc6..0892cc085a 100644
--- a/packages/base-ui/src/BaseComponentPlugin.ts
+++ b/packages/base-ui/src/BaseComponentPlugin.ts
@@ -2,12 +2,9 @@ import { Plugin, UniverSheet, UniverDoc, UniverSlide, PLUGIN_NAMES, Tools } from
import { Context } from '@univerjs/core/src/Basics/Context';
import { UniverConfig } from './Basics';
import { DefaultUniverConfig } from './Basics/Const/ComponentConfig/DefaultUniverConfig';
-import { DefaultUniverSheetConfig } from './Basics/Const/ComponentConfig/DefaultUniverSheetConfig';
-import { UniverSheetConfig } from './Basics/Interfaces/ComponentConfig/UniverSheetConfig';
import { BaseComponentPluginObserve, installObserver } from './Basics/Observer';
import { Locale } from './Basics/Shared/Locale';
import { ComponentManager } from './Common/ComponentManager';
-import { UniverContainerController } from './Controller/UniverContainerController';
import { en, zh } from './Locale';
export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {
@@ -17,8 +14,6 @@ export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {
private _locale: Locale;
- private _univerContainerController: UniverContainerController;
-
constructor(config: Partial<UniverConfig> = {}) {
super(PLUGIN_NAMES.BASE_COMPONENT);
this._config = Tools.deepMerge({}, DefaultUniverConfig, config);
@@ -43,9 +38,6 @@ export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {
});
// 初始自定义组件管理器
// this._componentManager = new ComponentManager();
- // this._univerContainerController = new UniverContainerController(this);
-
- this.addSheet();
}
/**
@@ -55,17 +47,6 @@ export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {
return this._config;
}
- /**
- * 获取国际化信息
- */
- getLocale(): Locale {
- return this._locale;
- }
-
- getUniverContainerController() {
- return this._univerContainerController;
- }
-
/**
* 自定义组件管理
*/
@@ -73,14 +54,11 @@ export class BaseComponentPlugin extends Plugin<BaseComponentPluginObserve> {
return this._componentManager;
}
- addSheet(config: UniverSheetConfig = {}) {
- config = Tools.deepMerge({}, DefaultUniverSheetConfig, config);
- this._univerContainerController.addSheet(config);
- }
-
onMounted(ctx: Context): void {
this.initialize(ctx);
}
- onDestroy(): void {}
+ onDestroy(): void {
+ //
+ }
}
diff --git a/packages/base-ui/src/Basics/Const/index.ts b/packages/base-ui/src/Basics/Const/index.ts
index 8b13789179..e69de29bb2 100644
--- a/packages/base-ui/src/Basics/Const/index.ts
+++ b/packages/base-ui/src/Basics/Const/index.ts
@@ -1 +0,0 @@
-
diff --git a/packages/base-ui/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts b/packages/base-ui/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts
index 461a1bb319..9e95cd41b3 100644
--- a/packages/base-ui/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts
+++ b/packages/base-ui/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts
@@ -28,8 +28,8 @@ export interface SheetToolbarConfig extends BaseToolbarConfig {
mergeCell?: boolean; // 'Merge cells'
}
-export interface DocToolbarConfig extends BaseToolbarConfig {}
+export interface DocToolbarConfig extends BaseToolbarConfig { }
-export interface SlideToolbarConfig extends BaseToolbarConfig {}
+export interface SlideToolbarConfig extends BaseToolbarConfig { }
-export interface ToolbarConfig extends SheetToolbarConfig, DocToolbarConfig, SlideToolbarConfig {}
+export interface ToolbarConfig extends SheetToolbarConfig, DocToolbarConfig, SlideToolbarConfig { }
diff --git a/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionFactory.ts b/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionFactory.ts
index fd467237ca..adbd1a9f98 100644
--- a/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionFactory.ts
+++ b/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionFactory.ts
@@ -5,7 +5,9 @@ import { ICell } from '../../Interfaces/Cell';
* Modify cell value
*/
export class BaseCellEditExtension {
- constructor(protected _cell: ICell, protected _value: string) {}
+ constructor(protected _cell: ICell, protected _value: string) {
+ //
+ }
getCell(): ICell {
return this._cell;
@@ -14,19 +16,19 @@ export class BaseCellEditExtension {
/**
* Modify the value
*/
- setValue(value: string) {}
+ // setValue(value: string) { }
/**
* Execute the core logic after the check is successful
*/
- execute() {}
+ // execute() { }
}
/**
* Determine whether to intercept and create BaseCellEditExtension
*/
export class BaseCellEditExtensionFactory<T extends Plugin = Plugin> {
- constructor(protected _plugin: T) {}
+ // constructor(protected _plugin: T) { }
get zIndex() {
return 0;
diff --git a/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionManager.ts b/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionManager.ts
index e948e079ce..33a4983ee3 100644
--- a/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionManager.ts
+++ b/packages/base-ui/src/Basics/Register/CellEditRegister/CellEditExtensionManager.ts
@@ -4,8 +4,19 @@ import { BaseCellEditExtension, BaseCellEditExtensionFactory } from './CellEditE
import { CellEditExtensionRegister } from './CellEditExtensionRegister';
export class CellEditExtensionManager {
+ static register: CellEditExtensionRegister;
+
private _cellEditExtensionFactoryList: BaseCellEditExtensionFactory[];
+ static create(): CellEditExtensionRegister {
+ if (!this.register) {
+ this.register = new CellEditExtensionRegister();
+ this.register.initialize();
+ }
+
+ return this.register;
+ }
+
/**
* inject cell position
* @param row
@@ -43,15 +54,4 @@ export class CellEditExtensionManager {
}
return extension;
}
-
- static register: CellEditExtensionRegister;
-
- static create(): CellEditExtensionRegister {
- if (!this.register) {
- this.register = new CellEditExtensionRegister();
- this.register.initialize();
- }
-
- return this.register;
- }
}
diff --git a/packages/base-ui/src/Basics/Register/CellEditRegister/RegistryFactory.ts b/packages/base-ui/src/Basics/Register/CellEditRegister/RegistryFactory.ts
index 2b0cb7e4d2..1fc67328d5 100644
--- a/packages/base-ui/src/Basics/Register/CellEditRegister/RegistryFactory.ts
+++ b/packages/base-ui/src/Basics/Register/CellEditRegister/RegistryFactory.ts
@@ -2,6 +2,10 @@
class Registry {
private _data: any[] = [];
+ static create() {
+ return new Registry();
+ }
+
add(dataInstance: any) {
this._data.push(dataInstance);
}
@@ -14,10 +18,6 @@ class Registry {
getData() {
return this._data;
}
-
- static create() {
- return new Registry();
- }
}
export const REGISTRY_CELL_EDIT_FACTORY = Registry.create();
diff --git a/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionFactory.ts b/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionFactory.ts
index c1b6992009..0a3c6b0207 100644
--- a/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionFactory.ts
+++ b/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionFactory.ts
@@ -6,19 +6,19 @@ import { IClipboardData } from '../../Interfaces/IClipboardData';
*/
export class BaseClipboardExtension<T extends Plugin = Plugin> {
// protected _json: IKeyValue;
- constructor(protected _data: IClipboardData, protected _plugin: T) {}
+ constructor(protected _data: IClipboardData, protected _plugin: T) { }
/**
* Execute the core logic after the check is successful
*/
- execute() {}
+ execute() { }
}
/**
* Determine whether to intercept and create BaseClipboardExtension
*/
export class BaseClipboardExtensionFactory<T extends Plugin = Plugin> {
- constructor(protected _plugin: T) {}
+ constructor(protected _plugin: T) { }
get zIndex() {
return 0;
diff --git a/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionManager.ts b/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionManager.ts
index 02300e8409..349ef9b746 100644
--- a/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionManager.ts
+++ b/packages/base-ui/src/Basics/Register/Clipboard/ClipboardExtensionManager.ts
@@ -10,14 +10,14 @@ export class ClipboardExtensionManager {
// mounted on the instance
private _register: ClipboardExtensionRegister;
- getRegister(): ClipboardExtensionRegister {
- return this._register;
- }
-
constructor() {
this._register = new ClipboardExtensionRegister();
}
+ getRegister(): ClipboardExtensionRegister {
+ return this._register;
+ }
+
/**
* inject all actions
* @param command
@@ -35,25 +35,6 @@ export class ClipboardExtensionManager {
}
}
- /**
- * Execute when the action is matched
- * @param command
- * @returns
- */
- private _checkExtension(data: IClipboardData) {
- if (!this._clipboardExtensionFactoryList) return false;
-
- let extension: BaseClipboardExtension | false = false;
- for (let index = 0; index < this._clipboardExtensionFactoryList.length; index++) {
- const extensionFactory = this._clipboardExtensionFactoryList[index];
- extension = extensionFactory.check(data);
- if (extension !== false) {
- break;
- }
- }
- return extension;
- }
-
pasteResolver(evt?: ClipboardEvent) {
return new Promise((resolve: (value: IClipboardData) => void, reject) => {
Clipboard.read(evt).then((file: Array<PasteType | null> | null) => {
@@ -75,4 +56,23 @@ export class ClipboardExtensionManager {
});
});
}
+
+ /**
+ * Execute when the action is matched
+ * @param command
+ * @returns
+ */
+ private _checkExtension(data: IClipboardData) {
+ if (!this._clipboardExtensionFactoryList) return false;
+
+ let extension: BaseClipboardExtension | false = false;
+ for (let index = 0; index < this._clipboardExtensionFactoryList.length; index++) {
+ const extensionFactory = this._clipboardExtensionFactoryList[index];
+ extension = extensionFactory.check(data);
+ if (extension !== false) {
+ break;
+ }
+ }
+ return extension;
+ }
}
diff --git a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionFactory.ts b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionFactory.ts
index 335e7b9645..9352a7faa6 100644
--- a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionFactory.ts
+++ b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionFactory.ts
@@ -6,19 +6,19 @@ import { IDragAndDropData } from '../../Interfaces';
*/
export class BaseDragAndDropExtension<T extends Plugin = Plugin> {
// protected _json: IKeyValue;
- constructor(protected _data: File[], protected _plugin: T) {}
+ constructor(protected _data: File[], protected _plugin: T) { }
/**
* Execute the core logic after the check is successful
*/
- execute() {}
+ execute() { }
}
/**
* Determine whether to intercept and create BaseDragAndDropExtension
*/
export class BaseDragAndDropExtensionFactory<T extends Plugin = Plugin> {
- constructor(protected _plugin: T) {}
+ constructor(protected _plugin: T) { }
get zIndex() {
return 0;
diff --git a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts
index 7416f15333..21f6abeb38 100644
--- a/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts
+++ b/packages/base-ui/src/Basics/Register/DragAndDrop/DragAndDropExtensionManager.ts
@@ -8,14 +8,14 @@ export class DragAndDropExtensionManager {
// mounted on the instance
private _register: DragAndDropExtensionRegister;
- getRegister(): DragAndDropExtensionRegister {
- return this._register;
- }
-
constructor() {
this._register = new DragAndDropExtensionRegister();
}
+ getRegister(): DragAndDropExtensionRegister {
+ return this._register;
+ }
+
/**
* inject all actions
* @param command
diff --git a/packages/base-ui/src/Basics/Shared/Locale.ts b/packages/base-ui/src/Basics/Shared/Locale.ts
index 7b0d38860e..20d88705f0 100644
--- a/packages/base-ui/src/Basics/Shared/Locale.ts
+++ b/packages/base-ui/src/Basics/Shared/Locale.ts
@@ -61,6 +61,22 @@ export class Locale {
};
}
+ /**
+ * get value from Locale object and key
+ * @param locale - A specified language pack
+ * @param key - Specify key
+ * @returns Get the translation corresponding to the Key
+ *
+ * @private
+ */
+ private static getValue(locale: object, key: string): Nullable<string | object> {
+ try {
+ return locale[key] ? locale[key] : key.split('.').reduce((a, b) => a[b], locale);
+ } catch (error) {
+ console.error('Key %s not found', key);
+ }
+ }
+
initialize(locale: Nullable<LocaleType>) {
this.options = {
// use config first, or get language setting from browser
@@ -124,20 +140,4 @@ export class Locale {
change(locale: LocaleType): void {
this.options.currentLocale = locale;
}
-
- /**
- * get value from Locale object and key
- * @param locale - A specified language pack
- * @param key - Specify key
- * @returns Get the translation corresponding to the Key
- *
- * @private
- */
- private static getValue(locale: object, key: string): Nullable<string | object> {
- try {
- return locale[key] ? locale[key] : key.split('.').reduce((a, b) => a[b], locale);
- } catch (error) {
- console.error('Key %s not found', key);
- }
- }
}
diff --git a/packages/base-ui/src/Basics/SlideTabBar/Animate.ts b/packages/base-ui/src/Basics/SlideTabBar/Animate.ts
index 95a8bbd681..4b804c57c5 100644
--- a/packages/base-ui/src/Basics/SlideTabBar/Animate.ts
+++ b/packages/base-ui/src/Basics/SlideTabBar/Animate.ts
@@ -50,6 +50,31 @@ export enum AnimateStatus {
}
export class Animate {
+ protected _config: AnimateConfig;
+
+ protected _status: AnimateStatus;
+
+ protected _start: number;
+
+ protected _handle: number;
+
+ protected _delayHandle: NodeJS.Timeout;
+
+ constructor(config: Partial<AnimateConfig>) {
+ this._config = {
+ ...CONFIG,
+ ...config,
+ };
+ if (this._config.loop) {
+ this._config.complete = () => {
+ /*noop*/
+ };
+ this._config.success = () => {
+ this.request();
+ };
+ }
+ }
+
static success(...animates: Animate[]): Promise<void> {
let successNumber = 0;
return new Promise<void>((resolve) => {
@@ -74,15 +99,26 @@ export class Animate {
});
}
- protected _config: AnimateConfig;
-
- protected _status: AnimateStatus;
-
- protected _start: number;
-
- protected _handle: number;
+ request(): void {
+ if (this._config.delay === 0) {
+ this._status = AnimateStatus.Request;
+ this._start = Date.now();
+ this._fakeHandle();
+ } else {
+ this._delayHandle && clearTimeout(this._delayHandle);
+ this._delayHandle = setTimeout(() => {
+ this._status = AnimateStatus.Request;
+ this._start = Date.now();
+ this._fakeHandle();
+ }, this._config.delay);
+ }
+ }
- protected _delayHandle: NodeJS.Timeout;
+ cancel(): void {
+ this._status = AnimateStatus.Cancel;
+ this._delayHandle && clearTimeout(this._delayHandle);
+ cancelAnimationFrame(this._handle);
+ }
protected _fakeHandle(): void {
let times = Date.now() - this._start;
@@ -109,40 +145,4 @@ export class Animate {
this._fakeHandle();
});
}
-
- constructor(config: Partial<AnimateConfig>) {
- this._config = {
- ...CONFIG,
- ...config,
- };
- if (this._config.loop) {
- this._config.complete = () => {
- /*noop*/
- };
- this._config.success = () => {
- this.request();
- };
- }
- }
-
- request(): void {
- if (this._config.delay === 0) {
- this._status = AnimateStatus.Request;
- this._start = Date.now();
- this._fakeHandle();
- } else {
- this._delayHandle && clearTimeout(this._delayHandle);
- this._delayHandle = setTimeout(() => {
- this._status = AnimateStatus.Request;
- this._start = Date.now();
- this._fakeHandle();
- }, this._config.delay);
- }
- }
-
- cancel(): void {
- this._status = AnimateStatus.Cancel;
- this._delayHandle && clearTimeout(this._delayHandle);
- cancelAnimationFrame(this._handle);
- }
}
diff --git a/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts
index df64933449..947c64dbc5 100644
--- a/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts
+++ b/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts
@@ -13,27 +13,6 @@ export interface SlideTabBarConfig {
}
export class SlideTabBar {
- static checkedSkipSlide(event: MouseEvent): boolean {
- let parent: HTMLElement | null = event.target as HTMLElement;
- while (parent != null && parent !== document.body) {
- if (parent.getAttribute('data-slide-skip')) {
- return true;
- }
- parent = parent.parentElement;
- }
- return false;
- }
-
- static keepLastIndex(inputHtml: HTMLElement) {
- setTimeout(() => {
- const range = window.getSelection();
- if (range) {
- range.selectAllChildren(inputHtml);
- range.collapseToEnd();
- }
- });
- }
-
_activeTabItemIndex: number | null;
_slideTabBar: HTMLElement;
@@ -66,6 +45,167 @@ export class SlideTabBar {
_slideScrollbar: SlideScrollbar;
+ constructor(config: Partial<SlideTabBarConfig>) {
+ if (config.slideTabRoot == null) {
+ throw new Error('not found slide-tab-bar root element');
+ }
+
+ const slideTabBar = config.slideTabRoot.querySelector(`.${config.slideTabBarClassName ?? 'slide-tab-bar'}`);
+ const slideTabItems = config.slideTabRoot.querySelectorAll(`.${config.slideTabBarItemClassName ?? 'slide-tab-item'}`);
+
+ if (slideTabBar == null) {
+ throw new Error('not found slide-tab-bar');
+ }
+
+ this._config = config as SlideTabBarConfig;
+ this._activeTabItem = null;
+ this._downActionX = 0;
+ this._moveActionX = 0;
+ this._compareDirection = 0;
+ this._compareIndex = 0;
+ this._activeTabItemIndex = 0;
+ this._slideTabBar = slideTabBar as HTMLElement;
+ this._slideScrollbar = new SlideScrollbar(this);
+ this._slideTabItems = SlideTabItem.make(slideTabItems, this);
+
+ let lastPageX = 0;
+ let lastPageY = 0;
+ let lastTime = 0;
+ this._downAction = (downEvent: MouseEvent) => {
+ if (downEvent.button === 2) {
+ lastPageX = 0;
+ lastTime = 0;
+ lastPageY = 0;
+ return;
+ }
+
+ const { pageX, pageY } = downEvent;
+ const current = Date.now();
+ const diffTime = current - lastTime <= 800;
+ const diffPageX = pageX === lastPageX;
+ const diffPageY = pageY === lastPageY;
+
+ // double click
+ if (diffTime && diffPageX && diffPageY) {
+ const slideItem = this._slideTabItems.find((item) => item.equals(new SlideTabItem(downEvent.currentTarget as HTMLElement, this)));
+ if (slideItem) {
+ // user editor
+ slideItem.editor();
+ }
+
+ lastTime = 0;
+ lastPageX = 0;
+ lastPageY = 0;
+ } else {
+ // not item is edit mode
+ if (!this._hasEditItem()) {
+ if (SlideTabBar.checkedSkipSlide(downEvent)) {
+ lastPageX = 0;
+ lastTime = 0;
+ lastPageY = 0;
+ return;
+ }
+ const slideItemIndex = this._slideTabItems.findIndex((item) => item.equals(new SlideTabItem(downEvent.currentTarget as HTMLElement, this)));
+ if (slideItemIndex > -1) {
+ this._compareIndex = slideItemIndex;
+ this._downActionX = downEvent.pageX;
+ this._moveActionX = 0;
+ this._scrollIncremental = 0;
+ this._activeTabItem = this._slideTabItems[slideItemIndex];
+ this._activeTabItemIndex = slideItemIndex;
+ if (this._config.activeClassNameAutoController) {
+ this._slideTabItems.forEach((item) => {
+ item.classList().remove(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');
+ });
+ this._activeTabItem.classList().add(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');
+ }
+ this._activeTabItem.enableFixed();
+ this._startAutoScroll();
+ } else {
+ this.updateItems();
+ this._activeTabItemIndex = 0;
+ this._downActionX = 0;
+ this._scrollIncremental = 0;
+ this._compareIndex = 0;
+ this._activeTabItem = null;
+ }
+ }
+
+ lastPageX = pageX;
+ lastPageY = pageY;
+ lastTime = current;
+ }
+ };
+
+ this._upAction = (upEvent: MouseEvent) => {
+ if (this._activeTabItem) {
+ this._closeAutoScroll();
+ this._activeTabItem.disableFixed();
+ this._sortedItems();
+ this.updateItems();
+
+ if (this._config.onSlideEnd && this._activeTabItemIndex !== this._compareIndex) {
+ this._config.onSlideEnd(upEvent);
+ }
+
+ // fix bug
+ let event = new MouseEvent('click', {
+ view: window,
+ bubbles: true,
+ cancelable: true,
+ });
+ this._activeTabItem.primeval().dispatchEvent(event);
+
+ this._scrollIncremental = 0;
+ this._activeTabItemIndex = 0;
+ this._downActionX = 0;
+ this._moveActionX = 0;
+ this._compareIndex = 0;
+ this._activeTabItem = null;
+ }
+ };
+
+ this._moveAction = (moveEvent) => {
+ if (this._activeTabItem) {
+ this._moveActionX = moveEvent.pageX - this._downActionX;
+ this._scrollIncremental = 0;
+ this._scrollLeft(moveEvent);
+ this._scrollRight(moveEvent);
+ }
+ };
+
+ this._wheelAction = (wheelEvent: WheelEvent) => {
+ if (wheelEvent.deltaY > 0) {
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + wheelEvent.deltaY);
+ } else {
+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + wheelEvent.deltaY);
+ }
+ };
+
+ this._initialize();
+ }
+
+ static checkedSkipSlide(event: MouseEvent): boolean {
+ let parent: HTMLElement | null = event.target as HTMLElement;
+ while (parent != null && parent !== document.body) {
+ if (parent.getAttribute('data-slide-skip')) {
+ return true;
+ }
+ parent = parent.parentElement;
+ }
+ return false;
+ }
+
+ static keepLastIndex(inputHtml: HTMLElement) {
+ setTimeout(() => {
+ const range = window.getSelection();
+ if (range) {
+ range.selectAllChildren(inputHtml);
+ range.collapseToEnd();
+ }
+ });
+ }
+
_hasEditItem(): boolean {
for (let index = 0; index < this._slideTabItems.length; index++) {
const element = this._slideTabItems[index];
@@ -232,146 +372,6 @@ export class SlideTabBar {
});
}
- constructor(config: Partial<SlideTabBarConfig>) {
- if (config.slideTabRoot == null) {
- throw new Error('not found slide-tab-bar root element');
- }
-
- const slideTabBar = config.slideTabRoot.querySelector(`.${config.slideTabBarClassName ?? 'slide-tab-bar'}`);
- const slideTabItems = config.slideTabRoot.querySelectorAll(`.${config.slideTabBarItemClassName ?? 'slide-tab-item'}`);
-
- if (slideTabBar == null) {
- throw new Error('not found slide-tab-bar');
- }
-
- this._config = config as SlideTabBarConfig;
- this._activeTabItem = null;
- this._downActionX = 0;
- this._moveActionX = 0;
- this._compareDirection = 0;
- this._compareIndex = 0;
- this._activeTabItemIndex = 0;
- this._slideTabBar = slideTabBar as HTMLElement;
- this._slideScrollbar = new SlideScrollbar(this);
- this._slideTabItems = SlideTabItem.make(slideTabItems, this);
-
- let lastPageX = 0;
- let lastPageY = 0;
- let lastTime = 0;
- this._downAction = (downEvent: MouseEvent) => {
- if (downEvent.button === 2) {
- lastPageX = 0;
- lastTime = 0;
- lastPageY = 0;
- return;
- }
-
- const { pageX, pageY } = downEvent;
- const current = Date.now();
- const diffTime = current - lastTime <= 800;
- const diffPageX = pageX === lastPageX;
- const diffPageY = pageY === lastPageY;
-
- // double click
- if (diffTime && diffPageX && diffPageY) {
- const slideItem = this._slideTabItems.find((item) => item.equals(new SlideTabItem(downEvent.currentTarget as HTMLElement, this)));
- if (slideItem) {
- // user editor
- slideItem.editor();
- }
-
- lastTime = 0;
- lastPageX = 0;
- lastPageY = 0;
- } else {
- // not item is edit mode
- if (!this._hasEditItem()) {
- if (SlideTabBar.checkedSkipSlide(downEvent)) {
- lastPageX = 0;
- lastTime = 0;
- lastPageY = 0;
- return;
- }
- const slideItemIndex = this._slideTabItems.findIndex((item) => item.equals(new SlideTabItem(downEvent.currentTarget as HTMLElement, this)));
- if (slideItemIndex > -1) {
- this._compareIndex = slideItemIndex;
- this._downActionX = downEvent.pageX;
- this._moveActionX = 0;
- this._scrollIncremental = 0;
- this._activeTabItem = this._slideTabItems[slideItemIndex];
- this._activeTabItemIndex = slideItemIndex;
- if (this._config.activeClassNameAutoController) {
- this._slideTabItems.forEach((item) => {
- item.classList().remove(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');
- });
- this._activeTabItem.classList().add(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');
- }
- this._activeTabItem.enableFixed();
- this._startAutoScroll();
- } else {
- this.updateItems();
- this._activeTabItemIndex = 0;
- this._downActionX = 0;
- this._scrollIncremental = 0;
- this._compareIndex = 0;
- this._activeTabItem = null;
- }
- }
-
- lastPageX = pageX;
- lastPageY = pageY;
- lastTime = current;
- }
- };
-
- this._upAction = (upEvent: MouseEvent) => {
- if (this._activeTabItem) {
- this._closeAutoScroll();
- this._activeTabItem.disableFixed();
- this._sortedItems();
- this.updateItems();
-
- if (this._config.onSlideEnd && this._activeTabItemIndex !== this._compareIndex) {
- this._config.onSlideEnd(upEvent);
- }
-
- // fix bug
- let event = new MouseEvent('click', {
- view: window,
- bubbles: true,
- cancelable: true,
- });
- this._activeTabItem.primeval().dispatchEvent(event);
-
- this._scrollIncremental = 0;
- this._activeTabItemIndex = 0;
- this._downActionX = 0;
- this._moveActionX = 0;
- this._compareIndex = 0;
- this._activeTabItem = null;
- }
- };
-
- this._moveAction = (moveEvent) => {
- if (this._activeTabItem) {
- this._moveActionX = moveEvent.pageX - this._downActionX;
- this._scrollIncremental = 0;
- this._scrollLeft(moveEvent);
- this._scrollRight(moveEvent);
- }
- };
-
- this._wheelAction = (wheelEvent: WheelEvent) => {
- if (wheelEvent.deltaY > 0) {
- this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + wheelEvent.deltaY);
- } else {
- this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + wheelEvent.deltaY);
- }
- };
-
- this._initialize();
- }
-
primeval(): HTMLElement {
return this._slideTabBar;
}
diff --git a/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts
index 9bd9728591..216fc0786e 100644
--- a/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts
+++ b/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts
@@ -8,16 +8,6 @@ export interface SlideTabItemAnimate {
}
export class SlideTabItem {
- static midline(item: SlideTabItem) {
- return item.getBoundingRect().x + item.getBoundingRect().width / 2;
- }
-
- static make(nodeList: NodeList, slideTabBar: SlideTabBar): SlideTabItem[] {
- let result: SlideTabItem[] = [];
- nodeList.forEach((item) => result.push(new SlideTabItem(item as HTMLElement, slideTabBar)));
- return result;
- }
-
_slideTabItem: HTMLElement;
_animate: Animate | null;
@@ -45,6 +35,16 @@ export class SlideTabItem {
this.update();
}
+ static midline(item: SlideTabItem) {
+ return item.getBoundingRect().x + item.getBoundingRect().width / 2;
+ }
+
+ static make(nodeList: NodeList, slideTabBar: SlideTabBar): SlideTabItem[] {
+ let result: SlideTabItem[] = [];
+ nodeList.forEach((item) => result.push(new SlideTabItem(item as HTMLElement, slideTabBar)));
+ return result;
+ }
+
isEditMode(): boolean {
return this._editMode;
}
diff --git a/packages/base-ui/src/Common/DragManager.ts b/packages/base-ui/src/Common/DragManager.ts
index 13f2075b4f..005c4ec57f 100644
--- a/packages/base-ui/src/Common/DragManager.ts
+++ b/packages/base-ui/src/Common/DragManager.ts
@@ -12,11 +12,6 @@ export class DragManager {
this._installObserver();
}
- private _installObserver() {
- // Drag
- this._observerManager.addObserver('onDropObservable', 'core', new Observable());
- }
-
/**
* init Drag listener
*
@@ -35,4 +30,9 @@ export class DragManager {
element.addEventListener('drop', DropEvent);
element.addEventListener('dragover', DragOverEvent);
}
+
+ private _installObserver() {
+ // Drag
+ this._observerManager.addObserver('onDropObservable', 'core', new Observable());
+ }
}
diff --git a/packages/base-ui/src/Common/KeyboardManager.ts b/packages/base-ui/src/Common/KeyboardManager.ts
index 66b51b1a91..26e78c1453 100644
--- a/packages/base-ui/src/Common/KeyboardManager.ts
+++ b/packages/base-ui/src/Common/KeyboardManager.ts
@@ -19,18 +19,6 @@ export class KeyboardManager {
this._installObserver();
}
- private _installObserver() {
- // keyboard
- this._observerManager.addObserver('onKeyDownObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyUpObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyCopyObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyPasteObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyCutObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyCompositionStartObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyCompositionUpdateObservable', 'core', new Observable());
- this._observerManager.addObserver('onKeyCompositionEndObservable', 'core', new Observable());
- }
-
/**
* init keyboard listener
*
@@ -76,4 +64,16 @@ export class KeyboardManager {
element.addEventListener('compositionupdate', keyboardCompositionUpdateEvent);
element.addEventListener('compositionend', keyboardCompositionEndEvent);
}
+
+ private _installObserver() {
+ // keyboard
+ this._observerManager.addObserver('onKeyDownObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyUpObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyCopyObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyPasteObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyCutObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyCompositionStartObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyCompositionUpdateObservable', 'core', new Observable());
+ this._observerManager.addObserver('onKeyCompositionEndObservable', 'core', new Observable());
+ }
}
diff --git a/packages/base-ui/src/Components/Button/Button.tsx b/packages/base-ui/src/Components/Button/Button.tsx
index bacaab3765..50a2eef128 100644
--- a/packages/base-ui/src/Components/Button/Button.tsx
+++ b/packages/base-ui/src/Components/Button/Button.tsx
@@ -59,7 +59,7 @@ class Button extends Component<BaseButtonProps, IState> {
getClass() {
const { isActive } = this.state;
- const { type, shape, danger, block, loading, size, className } = this.props;
+ const { type, shape, danger, block, loading, size, className, unActive } = this.props;
return joinClassNames(
styles.btn,
{
@@ -76,20 +76,25 @@ class Button extends Component<BaseButtonProps, IState> {
}
handleClick = (e: MouseEvent) => {
- const { disabled, onClick } = this.props;
+ const { disabled, onClick, unActive } = this.props;
if (disabled) {
e.preventDefault();
return;
}
+ if (unActive) {
+ onClick?.(e);
+ return;
+ }
+
this.setState(
{
isActive: !this.state.isActive,
},
() => {
if (onClick) {
- onClick.call(null, this.state.isActive);
+ onClick.call(null, e, this.state.isActive);
}
}
);
diff --git a/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx b/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx
index 3f1a5b2a75..7b45e6b627 100644
--- a/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx
+++ b/packages/base-ui/src/Components/CellRangeModal/CellRangeModal.tsx
@@ -1,4 +1,4 @@
-import { SheetContext, Nullable, Observer, Workbook, Worksheet } from '@univerjs/core';
+import { SheetContext, Workbook, Worksheet } from '@univerjs/core';
import { BaseCellRangeModalProps, CellRangeModalComponent, JSXComponent } from '../../BaseComponent';
import { Component, createRef } from '../../Framework';
import { Icon, Input, Modal, ModalProps } from '../index';
@@ -20,10 +20,6 @@ type placeholder = {
};
export class CellRangeModal extends Component<BaseCellRangeModalProps, CellModalState> {
- private _localeObserver: Nullable<Observer<Workbook>>;
-
- private _localeObserver1: Nullable<Observer<Worksheet>>;
-
ref = createRef();
// refProp = createRef();
diff --git a/packages/base-ui/src/Components/ColorButton/ColorButton.tsx b/packages/base-ui/src/Components/ColorButton/ColorButton.tsx
deleted file mode 100644
index da703cabb3..0000000000
--- a/packages/base-ui/src/Components/ColorButton/ColorButton.tsx
+++ /dev/null
@@ -1,24 +0,0 @@
-import { JSXComponent } from '../../BaseComponent';
-import { BaseColorButtonProps, ColorButtonComponent } from '../../Interfaces';
-import { ColorPicker } from '../ColorPicker';
-import * as Icon from '../Icon';
-import styles from './index.module.less';
-
-// type Iprops = {
-// color: string;
-// };
-export function ColorButton(props: BaseColorButtonProps) {
- const { color } = props;
- return (
- <div className={styles.colorButton}>
- <ColorPicker color={color} onClick={(color) => {}} onCancel={() => {}} />
- <Icon.Format.NextIcon />
- </div>
- );
-}
-
-export class UniverColorButton implements ColorButtonComponent {
- render(): JSXComponent<BaseColorButtonProps> {
- return ColorButton;
- }
-}
diff --git a/packages/base-ui/src/Components/ColorButton/index.module.less b/packages/base-ui/src/Components/ColorButton/index.module.less
deleted file mode 100644
index 47be2f838c..0000000000
--- a/packages/base-ui/src/Components/ColorButton/index.module.less
+++ /dev/null
@@ -1,7 +0,0 @@
-@import '../../Basics/CSS/Skin/base.module.less';
-
-.color-button {
- padding: 2px;
- border: 1px solid @gray-15;
- cursor: pointer;
-}
diff --git a/packages/base-ui/src/Components/ColorButton/index.ts b/packages/base-ui/src/Components/ColorButton/index.ts
deleted file mode 100644
index 23a32673b2..0000000000
--- a/packages/base-ui/src/Components/ColorButton/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './ColorButton';
diff --git a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
index cefbec0936..b591587ffd 100644
--- a/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
+++ b/packages/base-ui/src/Components/Dropdown/Dropdown.tsx
@@ -17,14 +17,9 @@ export class Dropdown extends Component<BaseDropdownProps, IState> {
IconRef = createRef<HTMLDivElement>();
- protected initialize() {
- this.state = {
- menuStyle: {},
- };
- }
-
handleClick = (e: MouseEvent) => {
this.props.onClick?.();
+ this.props.onMainClick?.();
const { icon } = this.props;
if (!icon) {
this.MenuRef.current?.showMenu(true);
@@ -35,9 +30,13 @@ export class Dropdown extends Component<BaseDropdownProps, IState> {
this.MenuRef.current?.showMenu(true);
};
- hideMenu = (e: MouseEvent) => {
+ hideMenu = () => {
+ this.MenuRef.current?.showMenu(false);
+ };
+
+ hideMenuClick = (e: MouseEvent) => {
if (!this.DropRef.current || !this.DropRef.current?.contains(e.target as Node)) {
- this.MenuRef.current?.showMenu(false);
+ this.hideMenu();
}
};
@@ -60,11 +59,11 @@ export class Dropdown extends Component<BaseDropdownProps, IState> {
this.setState({
menuStyle: style,
});
- window.addEventListener('click', this.hideMenu);
+ window.addEventListener('click', this.hideMenuClick, true);
}
componentWillUnmount() {
- window.removeEventListener('click', this.hideMenu);
+ window.removeEventListener('click', this.hideMenuClick, true);
}
render() {
@@ -90,6 +89,12 @@ export class Dropdown extends Component<BaseDropdownProps, IState> {
</div>
);
}
+
+ protected initialize() {
+ this.state = {
+ menuStyle: {},
+ };
+ }
}
export class UniverDropdown implements DropdownComponent {
diff --git a/packages/base-ui/src/Components/Input/input.tsx b/packages/base-ui/src/Components/Input/input.tsx
index ca0dc72c7d..469814cc01 100644
--- a/packages/base-ui/src/Components/Input/input.tsx
+++ b/packages/base-ui/src/Components/Input/input.tsx
@@ -55,9 +55,11 @@ export class Input extends Component<BaseInputProps, IState> {
onChange(e);
};
- handleKeyUp = (e: KeyboardEvent) => {
- const { onKeyUp } = this.props;
- onKeyUp?.(e);
+ handlePressEnter = (e: KeyboardEvent) => {
+ const { onPressEnter } = this.props;
+ if (e.key === 'Enter') {
+ onPressEnter?.(e);
+ }
};
onFocus = (e: Event) => {
@@ -117,7 +119,7 @@ export class Input extends Component<BaseInputProps, IState> {
onClick={this.onClick}
readonly={readonly}
id={id}
- onKeyUp={this.handleKeyUp}
+ onKeyUp={this.handlePressEnter}
></input>
);
}
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index 369ad926ec..02d2948c28 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -8,13 +8,6 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
private _refs: Menu[] = [];
- protected initialize() {
- this.state = {
- show: false,
- posStyle: {},
- };
- }
-
getMenuRef = () => this._MenuRef;
handleClick = (e: MouseEvent, item: BaseMenuItem, index: number) => {
@@ -142,4 +135,11 @@ export class Menu extends Component<BaseMenuProps, BaseMenuState> {
</ul>
);
}
+
+ protected initialize() {
+ this.state = {
+ show: false,
+ posStyle: {},
+ };
+ }
}
diff --git a/packages/base-ui/src/Components/Select/Select.tsx b/packages/base-ui/src/Components/Select/Select.tsx
index d4984e231a..bcb9059f39 100644
--- a/packages/base-ui/src/Components/Select/Select.tsx
+++ b/packages/base-ui/src/Components/Select/Select.tsx
@@ -1,5 +1,5 @@
import { Icon } from '..';
-import { ComponentChildren, Component } from '../../Framework';
+import { ComponentChildren, Component, createRef, RefObject } from '../../Framework';
import { BaseMenuItem } from '../../Interfaces';
import { Dropdown } from '../Dropdown';
import { Input } from '../Input';
@@ -26,7 +26,7 @@ interface CustomComponent {
}
export interface BaseSelectChildrenProps extends BaseItemProps {
- onKeyUp?: (...arg: any) => void;
+ onPressEnter?: (...arg: any) => void;
children?: BaseSelectChildrenProps[];
unSelectable?: boolean; //选中后不生效事件
customLabel?: CustomComponent;
@@ -40,7 +40,8 @@ export interface BaseSelectProps {
display?: DisplayTypes;
label?: ComponentChildren;
onClick?: (...arg: any) => void; //下拉Ul点击事件
- onKeyUp?: (...arg: any) => void;
+ onPressEnter?: (...arg: any) => void;
+ onMainClick?: () => void; // 非功能按钮事件
defaultColor?: string;
hideSelectedIcon?: boolean;
className?: string;
@@ -62,7 +63,7 @@ export class Select extends Component<BaseSelectProps, IState> {
onClick: (...arg: any) => void;
- onKeyUp: (...arg: any[]) => void;
+ onPressEnter: (...arg: any[]) => void;
initialize() {
const { children = [], hideSelectedIcon } = this.props;
@@ -175,9 +176,9 @@ export class Select extends Component<BaseSelectProps, IState> {
});
};
- this.onKeyUp = (e: KeyboardEvent) => {
+ this.onPressEnter = (e: KeyboardEvent) => {
const value = (e.currentTarget as HTMLInputElement).value;
- this.props.onKeyUp?.(value);
+ this.props.onPressEnter?.(value);
getLabel(value);
};
} else if (type === 2) {
@@ -270,26 +271,32 @@ export class Select extends Component<BaseSelectProps, IState> {
// 普通下拉
getSingle = () => {
const { content, menu } = this.state;
- const { className = '', tooltip } = this.props;
+ const { className = '', tooltip, onMainClick } = this.props;
return (
<div className={`${styles.selectSingle} ${className}`}>
- <Dropdown tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
+ <Dropdown onMainClick={onMainClick} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
<div>{content}</div>
</Dropdown>
</div>
);
};
+ handlePressEnter = (e: KeyboardEvent, ref: RefObject<Dropdown>) => {
+ this.onPressEnter(e);
+ ref.current?.hideMenu();
+ };
+
//Input下拉
getInput = () => {
const { content, menu } = this.state;
- const { className = '', tooltip } = this.props;
+ const { className = '', tooltip, onMainClick } = this.props;
+ const ref = createRef<Dropdown>();
return (
<div className={`${styles.selectInput} ${className}`}>
- <Dropdown tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
- <Input onKeyUp={this.onKeyUp} type="number" value={content as string} />
+ <Dropdown onMainClick={onMainClick} ref={ref} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} showArrow>
+ <Input onPressEnter={(e) => this.handlePressEnter(e, ref)} onBlur={this.onPressEnter} type="number" value={content as string} />
</Dropdown>
</div>
);
@@ -297,11 +304,11 @@ export class Select extends Component<BaseSelectProps, IState> {
getDouble = () => {
const { content, menu } = this.state;
- const { className = '', tooltip } = this.props;
+ const { className = '', tooltip, onClick } = this.props;
return (
<div className={`${styles.selectDouble} ${className}`}>
- <Dropdown tooltip={tooltip} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
+ <Dropdown onClick={onClick} tooltip={tooltip} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
<div className={styles.selectLabel}>{content}</div>
</Dropdown>
</div>
@@ -322,12 +329,12 @@ export class Select extends Component<BaseSelectProps, IState> {
};
getDoubleFix = () => {
- const { label, className = '', tooltip } = this.props;
+ const { label, className = '', tooltip, onClick } = this.props;
const { menu } = this.state;
return (
<div className={`${styles.selectDouble} ${className}`}>
- <Dropdown tooltip={tooltip} onClick={this.onClick} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
+ <Dropdown tooltip={tooltip} onClick={onClick} menu={{ menu, onClick: this.onClick }} icon={<Icon.NextIcon />}>
<div className={styles.selectLabel}>{label}</div>
</Dropdown>
</div>
diff --git a/packages/base-ui/src/Components/Tooltip/Tooltip.tsx b/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
index b79d1219b8..1caf9cb2d0 100644
--- a/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
+++ b/packages/base-ui/src/Components/Tooltip/Tooltip.tsx
@@ -1,6 +1,5 @@
import { Component, createRef } from '../../Framework';
-import { JSXComponent } from '../../BaseComponent';
-import { BaseTooltipProps, TooltipComponent } from '../../Interfaces';
+import { BaseTooltipProps } from '../../Interfaces';
import style from './index.module.less';
import { joinClassNames } from '../../Utils';
@@ -18,6 +17,7 @@ interface TooltipState {
placementClassName: string | undefined;
top: number | string;
left: number | string;
+ show: boolean;
}
const placementClassNames: { [index: string]: string } = {
@@ -28,17 +28,18 @@ const placementClassNames: { [index: string]: string } = {
};
export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
+ tooltip = createRef<HTMLDivElement>();
+
initialize(props: BaseTooltipProps) {
this.state = {
placement: props.placement || 'top',
placementClassName: joinClassNames(style.tooltipTitle, placementClassNames[props.placement || 'top']),
top: '',
left: '',
+ show: false,
};
}
- tooltip = createRef<HTMLDivElement>();
-
handleMouseOver() {
if (this.tooltip && this.tooltip.current) {
let tooltipInfo = this.tooltip.current.getBoundingClientRect();
@@ -49,30 +50,40 @@ export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
this.setState({
top: top + 10,
left: left / 2,
+ show: true,
});
} else if (this.state.placement === 'left') {
this.setState({
top: top / 2,
left: left + 5,
+ show: true,
});
} else if (this.state.placement === 'right') {
this.setState({
top: top / 2,
left: -left - 10,
+ show: true,
});
} else {
this.setState({
top: -top - 20,
left: left / 2,
+ show: true,
});
}
}
}
+ handleMouseLeave() {
+ this.setState({
+ show: false,
+ });
+ }
+
render() {
return (
<div ref={this.tooltip} className={style.tooltipGroup} style={this.props.styles}>
- <div className={style.tooltipBody} onMouseEnter={this.handleMouseOver.bind(this)}>
+ <div className={style.tooltipBody} onMouseEnter={this.handleMouseOver.bind(this)} onMouseLeave={this.handleMouseLeave.bind(this)}>
{this.props.children}
</div>
@@ -82,6 +93,7 @@ export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
style={{
top: `${this.state.top}px`,
left: `${this.state.left}px`,
+ display: `${this.state.show ? 'block' : 'none'}`,
}}
>
{this.props.title}
@@ -92,9 +104,3 @@ export class Tooltip extends Component<BaseTooltipProps, TooltipState> {
);
}
}
-
-export class UniverTooltip implements TooltipComponent {
- render(): JSXComponent<BaseTooltipProps> {
- return Tooltip;
- }
-}
diff --git a/packages/base-ui/src/Components/Tooltip/index.module.less b/packages/base-ui/src/Components/Tooltip/index.module.less
index da0e2882a2..8323d18f94 100644
--- a/packages/base-ui/src/Components/Tooltip/index.module.less
+++ b/packages/base-ui/src/Components/Tooltip/index.module.less
@@ -27,7 +27,7 @@
height: 100%;
display: inline-flex;
- &:hover ~ .tooltip-title {
+ &:hover~.tooltip-title {
position: absolute;
display: inline-block;
z-index: 500;
@@ -89,4 +89,4 @@
transform: translateY(-50%);
pointer-events: none;
}
-}
+}
\ No newline at end of file
diff --git a/packages/base-ui/src/Components/Tooltip/index.ts b/packages/base-ui/src/Components/Tooltip/index.ts
index 53162b998d..525ac0dcd0 100644
--- a/packages/base-ui/src/Components/Tooltip/index.ts
+++ b/packages/base-ui/src/Components/Tooltip/index.ts
@@ -1,3 +1,3 @@
-import { UniverTooltip, Tooltip } from './Tooltip';
+import { Tooltip } from './Tooltip';
-export { Tooltip, UniverTooltip };
+export { Tooltip };
diff --git a/packages/base-ui/src/Framework/Preact.ts b/packages/base-ui/src/Framework/Preact.ts
index 70ccc13817..89ea23d2cf 100644
--- a/packages/base-ui/src/Framework/Preact.ts
+++ b/packages/base-ui/src/Framework/Preact.ts
@@ -15,8 +15,6 @@ abstract class Component<P = {}, S = {}> extends PreactComponent<P, S> {
this.initialize(props);
}
- protected initialize(props?: P): void { }
-
getContext(): Context {
return this.context.context;
}
@@ -25,6 +23,10 @@ abstract class Component<P = {}, S = {}> extends PreactComponent<P, S> {
if (!name) return;
return this.getContext().getLocale().get(name);
}
+
+ protected initialize(props?: P): void {
+ //
+ }
}
abstract class PureComponent<P = {}, S = {}> extends PreactPureComponent<P, S> {
@@ -37,8 +39,6 @@ abstract class PureComponent<P = {}, S = {}> extends PreactPureComponent<P, S> {
this.initialize(props);
}
- protected initialize(props?: P): void { }
-
getContext(): Context {
return this.context.context;
}
@@ -46,6 +46,10 @@ abstract class PureComponent<P = {}, S = {}> extends PreactPureComponent<P, S> {
getLocale(name: string) {
return this.getContext().getLocale().get(name);
}
+
+ protected initialize(props?: P): void {
+ //
+ }
}
export { render, Component, forwardRef, createRef, PureComponent, cloneElement, useRef, useState, useEffect, toChildArray };
diff --git a/packages/base-ui/src/IData/IMainData.ts b/packages/base-ui/src/IData/IMainData.ts
deleted file mode 100644
index c2b80e1c99..0000000000
--- a/packages/base-ui/src/IData/IMainData.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { ISlotElementType } from '../Enum/ISlotElement';
-
-export interface IMainProps {
- /**
- * plugin name
- */
- name: string;
- /**
- * plugin type
- */
- type: ISlotElementType;
- /**
- * 支持
- * 1. JSX.Element,直接渲染组件
- * 2. HTML 元素
- * 3. HTML 字符串,直接渲染为HTML
- * 4. 非HTML 字符串,直接渲染内容
- */
- content: JSX.Element | HTMLElement | string;
-
- show?: boolean;
-}
-
-export interface IMainState extends IMainProps {
- /**
- * show or hide
- */
- show: boolean;
-
- /**
- * Adjust the z-index according to the order shown
- */
- zIndex: number;
-}
diff --git a/packages/base-ui/src/IData/ISiderData.ts b/packages/base-ui/src/IData/ISiderData.ts
deleted file mode 100644
index 6df9f05ef4..0000000000
--- a/packages/base-ui/src/IData/ISiderData.ts
+++ /dev/null
@@ -1,33 +0,0 @@
-import { JSX } from 'preact';
-import { ISlotElementType } from '../Enum';
-
-export interface ISlotProps {
- /**
- * plugin name
- */
- name: string;
- /**
- * plugin type
- */
- type: ISlotElementType; // input doube
- /**
- * 支持
- * 1. JSX.Element,直接渲染组件
- * 2. HTML 元素
- * 3. HTML 字符串,直接渲染为HTML
- * 4. 非HTML 字符串,直接渲染内容
- */
- label: JSX.Element | HTMLElement | string;
-}
-
-export interface ISiderState extends ISlotProps {
- /**
- * show or hide
- */
- show: boolean;
-
- /**
- * Adjust the z-index according to the order shown
- */
- zIndex: number;
-}
diff --git a/packages/base-ui/src/IData/index.ts b/packages/base-ui/src/IData/index.ts
index 58ffe7921e..06df97e07c 100644
--- a/packages/base-ui/src/IData/index.ts
+++ b/packages/base-ui/src/IData/index.ts
@@ -1,4 +1,2 @@
// @index('./*.ts', f => `export * from '${f.path}'`)
-export * from './IMainData';
-export * from './ISiderData';
// @endindex
diff --git a/packages/base-ui/src/Interfaces/Dropdown.ts b/packages/base-ui/src/Interfaces/Dropdown.ts
index 4199c97b36..5e37eb6de8 100644
--- a/packages/base-ui/src/Interfaces/Dropdown.ts
+++ b/packages/base-ui/src/Interfaces/Dropdown.ts
@@ -9,6 +9,7 @@ export interface BaseDropdownProps {
showArrow?: boolean;
icon?: ComponentChildren;
onClick?: () => void;
+ onMainClick?: () => void; //非功能按钮事件
tooltip?: string;
}
diff --git a/packages/base-ui/src/Interfaces/Input.ts b/packages/base-ui/src/Interfaces/Input.ts
index 1a2c320554..775bbdd170 100644
--- a/packages/base-ui/src/Interfaces/Input.ts
+++ b/packages/base-ui/src/Interfaces/Input.ts
@@ -6,7 +6,7 @@ export interface BaseInputProps extends BaseComponentProps {
value?: string;
placeholder?: string;
onChange?: (e: Event) => void;
- onKeyUp?: (e: KeyboardEvent) => void;
+ onPressEnter?: (e: KeyboardEvent) => void;
bordered?: boolean;
disabled?: boolean;
// maxLength?: number;
diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig.ts
index d3c22c53c0..0a46384cc5 100644
--- a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig.ts
+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig.ts
@@ -1,7 +1,7 @@
+import { LocaleType } from '@univerjs/core';
import { SheetRightMenuConfig } from './RightMenuConfig';
import { SheetContainerConfig } from './SheetContainerConfig';
import { SheetToolbarConfig } from './ToolbarConfig';
-import { LocaleType } from '@univerjs/core';
export interface ILayout {
sheetContainerConfig?: SheetContainerConfig;
diff --git a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
index 60b8b633db..7ace5073ca 100644
--- a/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/CellEditorUIController.ts
@@ -6,14 +6,6 @@ import { SheetUIPlugin } from '../SheetUIPlugin';
import { RichText } from '../View/RichText';
export class CellEditorUIController {
- private _plugin: SheetUIPlugin;
-
- private _sheetPlugin: SheetPlugin;
-
- private _cellEditExtensionManager: CellEditExtensionManager;
-
- private _keyboardManager: KeyboardManager;
-
// Is it in editing state
isEditMode: boolean;
@@ -23,139 +15,19 @@ export class CellEditorUIController {
_richText: RichText;
- constructor(plugin: SheetUIPlugin) {
- this._plugin = plugin;
- this._sheetPlugin = plugin.getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
-
- this._initialize();
- }
-
- private _initialize() {
- // this._initRegisterComponent();
- // If other plugins are loaded asynchronously, they may be initialized after the rendering layer is loaded, and they will not receive obs listeners.
-
- const main = this._sheetPlugin.getMainComponent();
-
- main.onDblclickObserver.add((evt: IPointerEvent | IMouseEvent) => {
- // Prevent left + right double click
- if (evt.button !== 2) {
- this.enterEditMode();
- }
- });
- main.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- this.exitEditMode();
- evt.preventDefault();
- });
-
- this._cellEditExtensionManager = new CellEditExtensionManager();
-
- this._keyboardManager = new KeyboardManager(this._plugin);
-
- // this._richTextEditEle
- }
-
- private _initRichText() {
- this._richTextEle = getRefElement(this._richText.container);
- this._richTextEditEle = $$('div', this._richTextEle);
-
- // // focus
- this._richTextEditEle.focus();
-
- // this.focusEditEle();
- this.hideEditContainer();
-
- // init event
- // this._handleKeyboardAction();
- this._keyboardManager.handleKeyboardAction(this._richTextEditEle);
- this._handleKeyboardObserver();
-
- // Get the display status of the formula prompt box
- this._richText.hooks.set('onKeyDown', (event: KeyboardEvent) => {
- this._plugin.getObserver('onRichTextKeyDownObservable')?.notifyObservers(event);
- });
- // Get the display status of the formula prompt box
- this._richText.hooks.set('onKeyUp', (event: KeyboardEvent) => {
- this._plugin.getObserver('onRichTextKeyUpObservable')?.notifyObservers(event);
- });
- }
-
- private _handleKeyboardObserver() {
- const onKeyDownObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<KeyboardEvent>('onKeyDownObservable', 'core');
- const onKeyCompositionStartObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<CompositionEvent>('onKeyCompositionStartObservable', 'core');
-
- if (onKeyDownObservable && !onKeyDownObservable.hasObservers()) {
- onKeyDownObservable.add((evt: KeyboardEvent) => {
- if (!evt.ctrlKey && isKeyPrintable(evt.key)) {
- // character key
- this.enterEditMode(true);
- } else {
- // control key
- switch (evt.key) {
- case 'Enter':
- if (this.isEditMode) {
- this.exitEditMode();
-
- const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCellModel();
- if (!currentCell?.isMerged) {
- // move to cell below
- this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);
- }
- } else {
- this.enterEditMode();
- }
- break;
-
- case 'Space':
- if (!this.isEditMode) {
- this.enterEditMode(true);
- }
- break;
-
- case 'ArrowUp':
- if (!this.isEditMode) {
- this._sheetPlugin.getSelectionManager().move(Direction.TOP);
- }
- break;
-
- case 'ArrowDown':
- if (!this.isEditMode) {
- this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);
- }
- break;
+ private _plugin: SheetUIPlugin;
- case 'ArrowLeft':
- if (!this.isEditMode) {
- this._sheetPlugin.getSelectionManager().move(Direction.LEFT);
- }
- break;
+ private _sheetPlugin: SheetPlugin;
- case 'ArrowRight':
- if (!this.isEditMode) {
- this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);
- }
- break;
+ private _cellEditExtensionManager: CellEditExtensionManager;
- case 'Tab':
- if (!this.isEditMode) {
- this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);
- }
- evt.preventDefault();
- break;
+ private _keyboardManager: KeyboardManager;
- default:
- break;
- }
- }
- });
- }
+ constructor(plugin: SheetUIPlugin) {
+ this._plugin = plugin;
+ this._sheetPlugin = plugin.getUniver().getCurrentUniverSheetInstance().context.getPluginManager().getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)!;
- if (onKeyCompositionStartObservable && !onKeyCompositionStartObservable.hasObservers()) {
- onKeyCompositionStartObservable.add((evt: CompositionEvent) => {
- if (!this.isEditMode) {
- this.enterEditMode(true);
- }
- });
- }
+ this._initialize();
}
// Get the RichText component
@@ -163,6 +35,7 @@ export class CellEditorUIController {
this._richText = ref;
this._initRichText();
};
+
getCellEditor() {
return this._richText;
}
@@ -316,10 +189,138 @@ export class CellEditorUIController {
}
getRichTextEle() {
- return this._richTextEle
+ return this._richTextEle;
}
getRichTextEditEle() {
- return this._richTextEditEle
+ return this._richTextEditEle;
+ }
+
+ private _initialize() {
+ // this._initRegisterComponent();
+ // If other plugins are loaded asynchronously, they may be initialized after the rendering layer is loaded, and they will not receive obs listeners.
+
+ const main = this._sheetPlugin.getMainComponent();
+
+ main.onDblclickObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ // Prevent left + right double click
+ if (evt.button !== 2) {
+ this.enterEditMode();
+ }
+ });
+ main.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ this.exitEditMode();
+ evt.preventDefault();
+ });
+
+ this._cellEditExtensionManager = new CellEditExtensionManager();
+
+ this._keyboardManager = new KeyboardManager(this._plugin);
+
+ // this._richTextEditEle
+ }
+
+ private _initRichText() {
+ this._richTextEle = getRefElement(this._richText.container);
+ this._richTextEditEle = $$('div', this._richTextEle);
+
+ // // focus
+ this._richTextEditEle.focus();
+
+ // this.focusEditEle();
+ this.hideEditContainer();
+
+ // init event
+ // this._handleKeyboardAction();
+ this._keyboardManager.handleKeyboardAction(this._richTextEditEle);
+ this._handleKeyboardObserver();
+
+ // Get the display status of the formula prompt box
+ this._richText.hooks.set('onKeyDown', (event: KeyboardEvent) => {
+ this._plugin.getObserver('onRichTextKeyDownObservable')?.notifyObservers(event);
+ });
+ // Get the display status of the formula prompt box
+ this._richText.hooks.set('onKeyUp', (event: KeyboardEvent) => {
+ this._plugin.getObserver('onRichTextKeyUpObservable')?.notifyObservers(event);
+ });
+ }
+
+ private _handleKeyboardObserver() {
+ const onKeyDownObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<KeyboardEvent>('onKeyDownObservable', 'core');
+ const onKeyCompositionStartObservable = this._plugin.getGlobalContext().getObserverManager().getObserver<CompositionEvent>('onKeyCompositionStartObservable', 'core');
+
+ if (onKeyDownObservable && !onKeyDownObservable.hasObservers()) {
+ onKeyDownObservable.add((evt: KeyboardEvent) => {
+ if (!evt.ctrlKey && isKeyPrintable(evt.key)) {
+ // character key
+ this.enterEditMode(true);
+ } else {
+ // control key
+ switch (evt.key) {
+ case 'Enter':
+ if (this.isEditMode) {
+ this.exitEditMode();
+
+ const currentCell = this._sheetPlugin.getSelectionManager().getCurrentCellModel();
+ if (!currentCell?.isMerged) {
+ // move to cell below
+ this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);
+ }
+ } else {
+ this.enterEditMode();
+ }
+ break;
+
+ case 'Space':
+ if (!this.isEditMode) {
+ this.enterEditMode(true);
+ }
+ break;
+
+ case 'ArrowUp':
+ if (!this.isEditMode) {
+ this._sheetPlugin.getSelectionManager().move(Direction.TOP);
+ }
+ break;
+
+ case 'ArrowDown':
+ if (!this.isEditMode) {
+ this._sheetPlugin.getSelectionManager().move(Direction.BOTTOM);
+ }
+ break;
+
+ case 'ArrowLeft':
+ if (!this.isEditMode) {
+ this._sheetPlugin.getSelectionManager().move(Direction.LEFT);
+ }
+ break;
+
+ case 'ArrowRight':
+ if (!this.isEditMode) {
+ this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);
+ }
+ break;
+
+ case 'Tab':
+ if (!this.isEditMode) {
+ this._sheetPlugin.getSelectionManager().move(Direction.RIGHT);
+ }
+ evt.preventDefault();
+ break;
+
+ default:
+ break;
+ }
+ }
+ });
+ }
+
+ if (onKeyCompositionStartObservable && !onKeyCompositionStartObservable.hasObservers()) {
+ onKeyCompositionStartObservable.add((evt: CompositionEvent) => {
+ if (!this.isEditMode) {
+ this.enterEditMode(true);
+ }
+ });
+ }
}
}
diff --git a/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
index a91e03e473..cc79ba1ab4 100644
--- a/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts
@@ -4,57 +4,8 @@ import { CountBar } from '../View/CountBar';
export class CountBarUIController {
protected _countBar: CountBar;
- protected _plugin: Plugin;
- protected _totalRangeList(rangeList: RangeList): void {
- let rectList = rangeList.getRangeList();
- let recList: string[] = [];
- let plugin = this._plugin;
- let workbook = plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
- let worksheet = workbook.getActiveSheet();
- let cellMatrix = worksheet.getCellMatrix();
- let avg = 0;
- let total = 0;
- let count = 0;
- for (let i = 0; i < rectList.length; i++) {
- let rect = rectList[i];
- for (let r = rect.startRow; r <= rect.endRow; r++) {
- for (let c = rect.startColumn; c <= rect.endColumn; c++) {
- if (recList.includes(`${r}${c}`)) {
- continue;
- }
- const cell = cellMatrix.getValue(r, c);
- if (cell) {
- let value = parseFloat(cell.v as string);
- // eslint-disable-next-line no-restricted-globals
- if (!isNaN(value)) {
- count += 1;
- total += value;
- }
- }
- recList.push(`${r}${c}`);
- }
- }
- }
- if (count > 0) {
- avg = total / count;
- }
- this._countBar.setState({
- content: `平均数:${Tools.numberFixed(avg, 2)} 计数:${Tools.numberFixed(total, 2)} 数量:${count}`,
- });
- }
-
- protected _refreshCountBarUI(): void {
-
- }
-
- protected _refreshComponent(): void {
- this._refreshCountBarUI();
- }
-
- protected _setUIObserve<T>(type: string, msg: UIObserver<T>) {
- this._plugin.getContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core').notifyObservers(msg);
- }
+ protected _plugin: Plugin;
constructor(plugin: Plugin) {
this._plugin = plugin;
@@ -74,11 +25,11 @@ export class CountBarUIController {
}
}
});
- const manager = plugin.getContext()
+ const manager = plugin
+ .getContext()
.getUniver()
.getCurrentUniverSheetInstance()
- .context
- .getPluginManager()
+ .context.getPluginManager()
.getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)
.getSelectionManager();
plugin.getObserver('onChangeSelectionObserver')?.add(() => {
@@ -92,7 +43,7 @@ export class CountBarUIController {
// changeRatio
onChange = (v: string) => {
this._setUIObserve('onUIChangeObservable', { name: 'changeZoom', value: Tools.numberFixed(parseFloat(v) / 100, 2) });
- }
+ };
// 刷新组件
setCountBar(content: string) {
@@ -107,4 +58,51 @@ export class CountBarUIController {
this._refreshComponent();
};
+ protected _totalRangeList(rangeList: RangeList): void {
+ let rectList = rangeList.getRangeList();
+ let recList: string[] = [];
+ let plugin = this._plugin;
+ let workbook = plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ let worksheet = workbook.getActiveSheet();
+ let cellMatrix = worksheet.getCellMatrix();
+ let avg = 0;
+ let total = 0;
+ let count = 0;
+ for (let i = 0; i < rectList.length; i++) {
+ let rect = rectList[i];
+ for (let r = rect.startRow; r <= rect.endRow; r++) {
+ for (let c = rect.startColumn; c <= rect.endColumn; c++) {
+ if (recList.includes(`${r}${c}`)) {
+ continue;
+ }
+ const cell = cellMatrix.getValue(r, c);
+ if (cell) {
+ let value = parseFloat(cell.v as string);
+ // eslint-disable-next-line no-restricted-globals
+ if (!isNaN(value)) {
+ count += 1;
+ total += value;
+ }
+ }
+ recList.push(`${r}${c}`);
+ }
+ }
+ }
+ if (count > 0) {
+ avg = total / count;
+ }
+ this._countBar.setState({
+ content: `平均数:${Tools.numberFixed(avg, 2)} 计数:${Tools.numberFixed(total, 2)} 数量:${count}`,
+ });
+ }
+
+ protected _refreshCountBarUI(): void { }
+
+ protected _refreshComponent(): void {
+ this._refreshCountBarUI();
+ }
+
+ protected _setUIObserve<T>(type: string, msg: UIObserver<T>) {
+ this._plugin.getContext().getObserverManager().requiredObserver<UIObserver<T>>(type, 'core').notifyObservers(msg);
+ }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
index 5d156f4fd1..d37ae7c0de 100644
--- a/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/FormulaBarUIController.ts
@@ -1,8 +1,8 @@
-import { SheetPlugin, SelectionControl } from "@univerjs/base-sheets";
-import { CellInputExtensionManager } from "@univerjs/base-ui";
-import { INamedRange, PLUGIN_NAMES } from "@univerjs/core";
-import { SheetUIPlugin } from "..";
-import { FormulaBar } from "../View/FormulaBar";
+import { SheetPlugin, SelectionControl } from '@univerjs/base-sheets';
+import { CellInputExtensionManager } from '@univerjs/base-ui';
+import { INamedRange, PLUGIN_NAMES } from '@univerjs/core';
+import { SheetUIPlugin } from '..';
+import { FormulaBar } from '../View/FormulaBar';
export class FormulaBarUIController {
private _formulaBar: FormulaBar;
@@ -22,8 +22,18 @@ export class FormulaBarUIController {
this._initialize();
}
- private _initialize() {
+ // 获取Toolbar组件
+ getComponent = (ref: FormulaBar) => {
+ this._formulaBar = ref;
+
+ this._initFormulaBar();
+ };
+
+ getFormulaBar() {
+ return this._formulaBar;
+ }
+ private _initialize() {
this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add((selectionControl: SelectionControl) => {
const currentCell = selectionControl.model.currentCell;
@@ -89,15 +99,4 @@ export class FormulaBarUIController {
this._formulaBar.setNamedRanges(list);
}
-
- // 获取Toolbar组件
- getComponent = (ref: FormulaBar) => {
- this._formulaBar = ref;
-
- this._initFormulaBar();
- };
-
- getFormulaBar() {
- return this._formulaBar;
- }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts b/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
index d4880fad0d..4d3c31b97e 100644
--- a/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/InfoBarUIController.ts
@@ -25,31 +25,6 @@ export class InfoBarUIController {
private _infoList: BaseInfoBarProps;
- private _refreshComponent(): void {
- const name = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getConfig().name;
- this._infoBarModel = new InfoBarModel(name);
- this._infoList = {
- back: {
- locale: 'info.return',
- },
- rename: {
- locale: 'info.tips',
- },
- update: {
- locale: 'info.detailUpdate',
- },
- save: {
- locale: 'info.detailSave',
- },
- sheet: {
- label: name,
- onBlur: (e) => {
- this.setSheetName(e);
- },
- },
- };
- }
-
constructor(plugin: Plugin) {
this._plugin = plugin;
}
@@ -75,4 +50,29 @@ export class InfoBarUIController {
const name = target.value;
this._infoBarModel.setName(name);
}
+
+ private _refreshComponent(): void {
+ const name = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getConfig().name;
+ this._infoBarModel = new InfoBarModel(name);
+ this._infoList = {
+ back: {
+ locale: 'info.return',
+ },
+ rename: {
+ locale: 'info.tips',
+ },
+ update: {
+ locale: 'info.detailUpdate',
+ },
+ save: {
+ locale: 'info.detailSave',
+ },
+ sheet: {
+ label: name,
+ onBlur: (e) => {
+ this.setSheetName(e);
+ },
+ },
+ };
+ }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
index 44c341cb4d..79ba8bc119 100644
--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts
@@ -5,7 +5,7 @@ import { PLUGIN_NAMES, Tools, UIObserver } from '@univerjs/core';
import { SheetUIPlugin } from '..';
import { DefaultRightMenuConfig, SheetRightMenuConfig } from '../Basics';
import { RightMenu, RightMenuInput, RightMenuItem } from '../View';
-import styles from '../View/RightMenu/index.module.less'
+import styles from '../View/RightMenu/index.module.less';
export interface CustomLabelOptions extends BaseSelectChildrenProps {
locale?: string;
@@ -30,13 +30,13 @@ export interface RightMenuProps extends BaseMenuItem {
children?: RightMenuProps[];
suffix?: string;
border?: boolean;
- locale?: string
+ locale?: string;
}
export class RightMenuUIController {
private _plugin: SheetUIPlugin;
- private _sheetPlugin: SheetPlugin
+ private _sheetPlugin: SheetPlugin;
private _rightMenu: RightMenu;
@@ -51,7 +51,6 @@ export class RightMenuUIController {
this._config = Tools.deepMerge({}, DefaultRightMenuConfig, config);
-
this._menuList = [
{
label: 'rightClick.insertRow',
@@ -69,7 +68,7 @@ export class RightMenuUIController {
props: {
prefix: 'rightClick.toTopAdd',
suffix: 'rightClick.row',
- }
+ },
},
show: this._config.AddRowTop,
},
@@ -294,18 +293,6 @@ export class RightMenuUIController {
this._initialize();
}
- private _initialize() {
- this._plugin.getComponentManager().register(RightMenuInput.name, RightMenuInput)
- this._plugin.getComponentManager().register(RightMenuItem.name, RightMenuItem)
-
- this._sheetPlugin.getMainComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
- if (evt.button === 2) {
- evt.preventDefault()
- this._rightMenu.handleContextMenu(evt);
- }
- });
- }
-
// 获取RightMenu组件
getComponent = (ref: RightMenu) => {
this._rightMenu = ref;
@@ -356,7 +343,7 @@ export class RightMenuUIController {
const height = (e.target as HTMLInputElement).value;
const msg = {
name: 'setRowHeight',
- value: height
+ value: height,
};
this.setUIObserve(msg);
}
@@ -368,7 +355,7 @@ export class RightMenuUIController {
const width = (e.target as HTMLInputElement).value;
const msg = {
name: 'setColumnWidth',
- value: width
+ value: width,
};
this.setUIObserve(msg);
}
@@ -393,4 +380,16 @@ export class RightMenuUIController {
};
this.setUIObserve(msg);
}
+
+ private _initialize() {
+ this._plugin.getComponentManager().register(RightMenuInput.name, RightMenuInput);
+ this._plugin.getComponentManager().register(RightMenuItem.name, RightMenuItem);
+
+ this._sheetPlugin.getMainComponent().onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {
+ if (evt.button === 2) {
+ evt.preventDefault();
+ this._rightMenu.handleContextMenu(evt);
+ }
+ });
+ }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
index 8f8d048cfc..8c86eef601 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts
@@ -1,7 +1,21 @@
import { BaseMenuItem, BaseUlProps, ColorPicker } from '@univerjs/base-ui';
-import { Nullable, Plugin, CommandManager, SheetActionBase, UIObserver, SetSheetOrderAction, InsertSheetAction, SetWorkSheetNameAction, SetTabColorAction, SetWorkSheetHideAction, SetWorkSheetActivateAction, SetWorkSheetStatusAction, RemoveSheetAction } from '@univerjs/core';
+import {
+ Nullable,
+ Plugin,
+ CommandManager,
+ SheetActionBase,
+ UIObserver,
+ SetSheetOrderAction,
+ InsertSheetAction,
+ SetWorkSheetNameAction,
+ SetTabColorAction,
+ SetWorkSheetHideAction,
+ SetWorkSheetActivateAction,
+ SetWorkSheetStatusAction,
+ RemoveSheetAction,
+} from '@univerjs/core';
import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '..';
-import { SheetBar } from "../View/SheetBar";
+import { SheetBar } from '../View/SheetBar';
import styles from '../View/SheetBar/index.module.less';
interface CustomComponent {
@@ -36,77 +50,6 @@ export class SheetBarUIController {
protected _menuList: SheetUlProps[];
- protected _refreshSheetBarUI(): void {
- this._sheetBar.setValue({
- sheetList: this._sheetList,
- sheetUl: this._sheetUl,
- menuList: this._menuList,
- selectSheet: (event: Event, data: { item: SheetUlProps }) => {
- this._dataId = data.item.sheetId;
- const sheet = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._dataId);
- if (sheet) {
- sheet.activate();
- }
- },
- contextMenu: (e: MouseEvent) => {
- const target = e.currentTarget as HTMLDivElement;
- this._dataId = target.dataset.id as string;
- //this._barControl.contextMenu(e);
- },
- changeSheetName: (event: Event) => {
-
- },
- dragEnd: (elements: HTMLDivElement[]) => {
- //this._barControl.dragEnd(elements);
- },
- });
- }
-
- protected _refreshSheetData(): void {
- const workbook = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
- const sheets = workbook.getSheets();
- this._menuList = sheets.map((sheet, index) => ({
- label: sheet.getName(),
- index: String(index),
- sheetId: sheet.getSheetId(),
- hidden: sheet.isSheetHidden(),
- selected: sheet.getStatus() === 1,
- onClick: (e: MouseEvent) => {
- const target = e.currentTarget as HTMLDivElement;
- this._dataId = target.dataset.id as string;
- sheet.showSheet();
- sheet.activate();
- },
- }));
- this._sheetList = sheets.filter((sheet) => !sheet.isSheetHidden()).map((sheet, index) => ({
- sheetId: sheet.getSheetId(),
- label: sheet.getName(),
- index: String(index),
- selected: sheet.getStatus() === 1,
- color: sheet.getTabColor() as string,
- onDown: (e: MouseEvent) => {
- const target = e.currentTarget as HTMLDivElement;
- this._dataId = target.dataset.id as string;
- },
- onClick: (e: MouseEvent) => {
- const target = e.currentTarget as HTMLDivElement;
- this._dataId = target.dataset.id as string;
-
- sheet.activate();
- },
- }));
- this._sheetIndex = sheets.findIndex((sheet) => sheet.getStatus() === 1);
- if (this._sheetIndex > -1) {
- this._dataId = sheets[this._sheetIndex].getSheetId();
- }
- }
-
- protected _refreshComponent(): void {
- this._sheetUl = this.resetSheetUl(this._sheetUl);
- this._refreshSheetData();
- this._refreshSheetBarUI();
- }
-
constructor(plugin: Plugin) {
let that = this;
this._plugin = plugin;
@@ -142,8 +85,9 @@ export class SheetBarUIController {
this.setUIObserve('onUIChangeObservable', {
name: 'changeSheetColor',
value: {
- color, sheetId: this._dataId
- }
+ color,
+ sheetId: this._dataId,
+ },
});
},
},
@@ -161,13 +105,16 @@ export class SheetBarUIController {
{
locale: 'sheetConfig.unhide',
onClick: () => {
- this._sheetBar.ref.current.showMenu(true)
+ this._sheetBar.ref.current.showMenu(true);
that.setUIObserve('onUIChangeObservable', { name: 'unHideSheet', value: this._dataId });
},
border: true,
- }
+ },
];
- this._plugin.getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager().register(this._plugin.getPluginName() + ColorPicker.name, ColorPicker)
+ this._plugin
+ .getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)
+ ?.getComponentManager()
+ .register(this._plugin.getPluginName() + ColorPicker.name, ColorPicker);
CommandManager.getActionObservers().add((event) => {
const action = event.action as SheetActionBase<any>;
const data = event.data;
@@ -195,7 +142,10 @@ export class SheetBarUIController {
}
}
});
- this._plugin.getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager().register(this._plugin.getPluginName() + ColorPicker.name, ColorPicker)
+ this._plugin
+ .getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)
+ ?.getComponentManager()
+ .register(this._plugin.getPluginName() + ColorPicker.name, ColorPicker);
}
getComponent = (ref: SheetBar) => {
@@ -278,52 +228,41 @@ export class SheetBarUIController {
return sheetUl;
}
- selectSheet() {
-
- }
-
- deleteSheet() {
-
- }
-
- sortMenu(index: number, hidden?: boolean, hideIndex?: number) {
+ selectSheet() { }
- }
+ deleteSheet() { }
- copySheet() {
+ sortMenu(index: number, hidden?: boolean, hideIndex?: number) { }
- }
+ copySheet() { }
addSheet = (position?: string, config?: SheetUlProps): void => {
this.setUIObserve('onUIChangeObservable', {
name: 'addSheet',
value: {
position,
- config
- }
+ config,
+ },
});
- }
-
- hideSheet() {
+ };
- }
+ hideSheet() { }
unHideSheet() {
this._sheetBar.ref.current.showSelect();
}
- moveSheet(direct: string) {
-
- }
+ moveSheet(direct: string) { }
changeSheetName = (event: Event) => {
this.setUIObserve('onUIChangeObservable', {
- name: 'renameSheet', value: {
+ name: 'renameSheet',
+ value: {
sheetId: this._dataId,
- sheetName: (event.target as HTMLElement).innerText
- }
+ sheetName: (event.target as HTMLElement).innerText,
+ },
});
- }
+ };
contextMenu(e: MouseEvent) {
this._sheetBar.contextMenu(e);
@@ -343,5 +282,76 @@ export class SheetBarUIController {
this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().setSheetOrder(ele.sheetId, index);
}
});
+ };
+
+ protected _refreshSheetBarUI(): void {
+ this._sheetBar.setValue({
+ sheetList: this._sheetList,
+ sheetUl: this._sheetUl,
+ menuList: this._menuList,
+ selectSheet: (event: Event, data: { item: SheetUlProps }) => {
+ this._dataId = data.item.sheetId;
+ const sheet = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(this._dataId);
+ if (sheet) {
+ sheet.activate();
+ }
+ },
+ contextMenu: (e: MouseEvent) => {
+ const target = e.currentTarget as HTMLDivElement;
+ this._dataId = target.dataset.id as string;
+ //this._barControl.contextMenu(e);
+ },
+ changeSheetName: (event: Event) => { },
+ dragEnd: (elements: HTMLDivElement[]) => {
+ //this._barControl.dragEnd(elements);
+ },
+ });
+ }
+
+ protected _refreshSheetData(): void {
+ const workbook = this._plugin.getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ const sheets = workbook.getSheets();
+ this._menuList = sheets.map((sheet, index) => ({
+ label: sheet.getName(),
+ index: String(index),
+ sheetId: sheet.getSheetId(),
+ hidden: sheet.isSheetHidden(),
+ selected: sheet.getStatus() === 1,
+ onClick: (e: MouseEvent) => {
+ const target = e.currentTarget as HTMLDivElement;
+ this._dataId = target.dataset.id as string;
+ sheet.showSheet();
+ sheet.activate();
+ },
+ }));
+ this._sheetList = sheets
+ .filter((sheet) => !sheet.isSheetHidden())
+ .map((sheet, index) => ({
+ sheetId: sheet.getSheetId(),
+ label: sheet.getName(),
+ index: String(index),
+ selected: sheet.getStatus() === 1,
+ color: sheet.getTabColor() as string,
+ onDown: (e: MouseEvent) => {
+ const target = e.currentTarget as HTMLDivElement;
+ this._dataId = target.dataset.id as string;
+ },
+ onClick: (e: MouseEvent) => {
+ const target = e.currentTarget as HTMLDivElement;
+ this._dataId = target.dataset.id as string;
+
+ sheet.activate();
+ },
+ }));
+ this._sheetIndex = sheets.findIndex((sheet) => sheet.getStatus() === 1);
+ if (this._sheetIndex > -1) {
+ this._dataId = sheets[this._sheetIndex].getSheetId();
+ }
}
-}
\ No newline at end of file
+
+ protected _refreshComponent(): void {
+ this._sheetUl = this.resetSheetUl(this._sheetUl);
+ this._refreshSheetData();
+ this._refreshSheetBarUI();
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
index 017910213d..b3a0f4a412 100644
--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts
@@ -1,9 +1,9 @@
import { SheetPlugin } from '@univerjs/base-sheets';
import { DragManager, EventManager, getRefElement } from '@univerjs/base-ui';
-import { LocaleType, PLUGIN_NAMES, UIObserver, UniverSheet } from '@univerjs/core';
+import { LocaleType, PLUGIN_NAMES, UniverSheet } from '@univerjs/core';
import { ISheetUIPluginConfig } from '../Basics';
import { SheetUIPlugin } from '../SheetUIPlugin';
-import { SheetContainer, UI } from '../View';
+import { SheetContainer } from '../View';
import { CellEditorUIController } from './CellEditorUIController';
import { CountBarUIController } from './CountBarUIController';
import { FormulaBarUIController } from './FormulaBarUIController';
@@ -47,7 +47,7 @@ export class SheetContainerUIController {
this._initialize();
- this._slotController = new SlotController(this._plugin)
+ this._slotController = new SlotController();
this._toolbarController = new ToolbarUIController(this._plugin, this._config.layout?.toolbarConfig);
this._cellEditorUIController = new CellEditorUIController(this._plugin);
this._formulaBarUIController = new FormulaBarUIController(this._plugin);
@@ -94,18 +94,6 @@ export class SheetContainerUIController {
// UI.create(config);
}
- private _initialize() {
- this._dragManager = new DragManager(this._plugin);
- this._eventManager = new EventManager(this._plugin);
-
- this.setEventManager();
- }
-
- private _initSheetContainer() {
- // handle drag event
- this._dragManager.handleDragAction(getRefElement(this._sheetContainer));
- }
-
getUIConfig() {
const config = {
context: this._plugin.getContext(),
@@ -143,7 +131,7 @@ export class SheetContainerUIController {
},
slot: {
getComponent: this._slotController.getComponent,
- }
+ },
},
};
return config;
@@ -152,7 +140,7 @@ export class SheetContainerUIController {
// 获取SheetContainer组件
getComponent = (ref: SheetContainer) => {
this._sheetContainer = ref;
- this._plugin.getObserver('onUIDidMount')?.notifyObservers(this._sheetContainer)
+ this._plugin.getObserver('onUIDidMount')?.notifyObservers(this._sheetContainer);
this._initSheetContainer();
};
@@ -190,22 +178,32 @@ export class SheetContainerUIController {
}
getCellEditorUIController() {
- return this._cellEditorUIController
+ return this._cellEditorUIController;
}
getFormulaBarUIController() {
- return this._formulaBarUIController
+ return this._formulaBarUIController;
}
getMainSlotController() {
- return this._slotController
+ return this._slotController;
}
UIDidMount(cb: Function) {
- if (this._sheetContainer) return cb(this._sheetContainer)
+ if (this._sheetContainer) return cb(this._sheetContainer);
- this._plugin.getObserver('onUIDidMount')?.add(() => {
- return cb(this._sheetContainer)
- })
+ this._plugin.getObserver('onUIDidMount')?.add(() => cb(this._sheetContainer));
+ }
+
+ private _initialize() {
+ this._dragManager = new DragManager(this._plugin);
+ this._eventManager = new EventManager(this._plugin);
+
+ this.setEventManager();
+ }
+
+ private _initSheetContainer() {
+ // handle drag event
+ this._dragManager.handleDragAction(getRefElement(this._sheetContainer));
}
}
diff --git a/packages/ui-plugin-sheets/src/Controller/SlotController.ts b/packages/ui-plugin-sheets/src/Controller/SlotController.ts
index 083c3a20fe..f7047ac08c 100644
--- a/packages/ui-plugin-sheets/src/Controller/SlotController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/SlotController.ts
@@ -1,12 +1,12 @@
-import { IKeyValue } from "@univerjs/core";
-import { Slot } from "../View";
+import { IKeyValue } from '@univerjs/core';
+import { Slot } from '../View';
export type SlotComponentProps = {
- component: Function,
- props?: IKeyValue
-}
+ component: Function;
+ props?: IKeyValue;
+};
-export type SlotGroupProps = Map<string, SlotComponentProps>
+export type SlotGroupProps = Map<string, SlotComponentProps>;
export class SlotController {
private _slotGroup: SlotGroupProps = new Map();
@@ -14,16 +14,16 @@ export class SlotController {
private _slot: Slot;
getComponent = (ref: Slot) => {
- this._slot = ref
- }
+ this._slot = ref;
+ };
addSlot<O, T = null>(name: string, slot: SlotComponentProps, cb?: () => void) {
- if (this._slotGroup.get(name)) return
+ if (this._slotGroup.get(name)) return;
this._slotGroup.set(name, {
component: slot.component,
- props: slot.props ?? {}
- })
- this.setSlot(cb)
+ props: slot.props ?? {},
+ });
+ this.setSlot(cb);
}
getSlot(name: string) {
@@ -32,8 +32,8 @@ export class SlotController {
}
removeSlot(name: string) {
- this._slotGroup.delete(name)
- this.setSlot()
+ this._slotGroup.delete(name);
+ this.setSlot();
}
setSlot(cb?: () => void) {
diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
index 576524fe75..0e6b87983a 100644
--- a/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarUIController.ts
@@ -1,10 +1,36 @@
-import { BorderInfo, SelectionControl, SheetPlugin } from '@univerjs/base-sheets';
+import { BorderInfo, SheetPlugin } from '@univerjs/base-sheets';
import { BaseSelectChildrenProps, BaseSelectProps, ColorPicker, ComponentChildren } from '@univerjs/base-ui';
-import { BorderType, DEFAULT_STYLES, FontItalic, FontStyleType, FontWeight, HorizontalAlign, IBorderData, IKeyValue, PLUGIN_NAMES, Range, Tools, UIObserver, VerticalAlign, WrapStrategy } from '@univerjs/core';
+import {
+ BorderType,
+ CommandManager,
+ DEFAULT_STYLES,
+ HorizontalAlign,
+ IKeyValue,
+ ISheetActionData,
+ PLUGIN_NAMES,
+ SheetActionBase,
+ Tools,
+ UIObserver,
+ VerticalAlign,
+ WrapStrategy,
+ Range,
+ FontWeight,
+ FontItalic,
+} from '@univerjs/core';
import { SheetUIPlugin } from '..';
import { DefaultToolbarConfig, SheetToolbarConfig, SHEET_UI_PLUGIN_NAME } from '../Basics';
import { ColorSelect, LineBold, LineColor, Toolbar } from '../View';
-import { BORDER_LINE_CHILDREN, BORDER_SIZE_CHILDREN, FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN, HORIZONTAL_ALIGN_CHILDREN, MERGE_CHILDREN, TEXT_ROTATE_CHILDREN, TEXT_WRAP_CHILDREN, VERTICAL_ALIGN_CHILDREN } from '../View/ToolBar/Const';
+import {
+ BORDER_LINE_CHILDREN,
+ BORDER_SIZE_CHILDREN,
+ FONT_FAMILY_CHILDREN,
+ FONT_SIZE_CHILDREN,
+ HORIZONTAL_ALIGN_CHILDREN,
+ MERGE_CHILDREN,
+ TEXT_ROTATE_CHILDREN,
+ TEXT_WRAP_CHILDREN,
+ VERTICAL_ALIGN_CHILDREN,
+} from '../View/Toolbar/Const';
import styles from '../View/ToolBar/index.module.less';
// 继承基础下拉属性,添加国际化
@@ -25,6 +51,7 @@ enum ToolbarType {
export interface IToolbarItemProps extends BaseToolbarSelectProps {
active?: boolean;
+ unActive?: boolean; //button不需保持状态
show?: boolean; //是否显示按钮
toolbarType?: ToolbarType;
tooltip?: string; //tooltip文字
@@ -32,7 +59,6 @@ export interface IToolbarItemProps extends BaseToolbarSelectProps {
suffix?: ComponentChildren;
}
-
export class ToolbarUIController {
private _plugin: SheetUIPlugin;
@@ -50,13 +76,17 @@ export class ToolbarUIController {
private _colorSelect1: ColorSelect;
+ private _textColor: string = '#000';
+
private _colorSelect2: ColorSelect;
+ private _background: string = '#fff';
+
private _borderInfo: BorderInfo = {
- type: BorderType.TOP,
+ type: BorderType.ALL,
color: '#000',
- style: 1
- } //存储边框信息
+ style: 1,
+ }; //存储边框信息
constructor(plugin: SheetUIPlugin, config?: SheetToolbarConfig) {
this._plugin = plugin;
@@ -70,21 +100,29 @@ export class ToolbarUIController {
toolbarType: 1,
tooltip: 'toolbar.undo',
name: 'undo',
+ unActive: true,
customLabel: {
name: 'ForwardIcon',
},
show: this._config.undo,
- onClick: () => this.setUndo(),
+ onClick: () => {
+ this.setUndo();
+ this.hideTooltip();
+ },
},
{
toolbarType: 1,
tooltip: 'toolbar.redo',
+ unActive: true,
customLabel: {
name: 'BackIcon',
},
name: 'redo',
show: this._config.redo,
- onClick: () => this.setRedo(),
+ onClick: () => {
+ this.setRedo();
+ this.hideTooltip();
+ },
},
{
type: 0,
@@ -93,6 +131,9 @@ export class ToolbarUIController {
name: 'font',
show: this._config.font,
border: true,
+ onMainClick: () => {
+ this.hideTooltip();
+ },
onClick: (fontFamily: string) => {
this.setFontFamily(fontFamily);
},
@@ -107,8 +148,12 @@ export class ToolbarUIController {
onClick: (fontSize: number) => {
this.setFontSize(fontSize);
},
- onKeyUp: (fontSize: number) => {
+ onMainClick: () => {
+ this.hideTooltip();
+ },
+ onPressEnter: (fontSize: number) => {
this.setFontSize(fontSize);
+ this.hideTooltip();
},
children: FONT_SIZE_CHILDREN,
},
@@ -121,8 +166,9 @@ export class ToolbarUIController {
active: false,
name: 'bold',
show: this._config.bold,
- onClick: (isBold: boolean) => {
+ onClick: (e, isBold: boolean) => {
this.setFontWeight(isBold);
+ this.hideTooltip();
},
},
{
@@ -133,8 +179,9 @@ export class ToolbarUIController {
},
name: 'italic',
show: this._config.italic,
- onClick: (isItalic: boolean) => {
- this.setFontStyle(isItalic)
+ onClick: (e, isItalic: boolean) => {
+ this.setFontStyle(isItalic);
+ this.hideTooltip();
},
},
{
@@ -145,8 +192,12 @@ export class ToolbarUIController {
},
name: 'strikethrough',
show: this._config.strikethrough,
- onClick: (isStrikethrough: boolean) => {
- this.setStrikeThrough(isStrikethrough)
+ onClick: (e, isStrikethrough: boolean) => {
+ this.hideTooltip();
+ const strikethroughItem = this._toolList.find((item) => item.name === 'strikethrough');
+ if (!strikethroughItem) return;
+ strikethroughItem.active = isStrikethrough;
+ this.setStrikeThrough(isStrikethrough);
},
},
{
@@ -157,8 +208,12 @@ export class ToolbarUIController {
},
name: 'underline',
show: this._config.underline,
- onClick: (isUnderLine: boolean) => {
- this.setUnderline(isUnderLine)
+ onClick: (e, isUnderLine: boolean) => {
+ this.hideTooltip();
+ const underlineItem = this._toolList.find((item) => item.name === 'underline');
+ if (!underlineItem) return;
+ underlineItem.active = isUnderLine;
+ this.setUnderline(isUnderLine);
},
},
{
@@ -168,7 +223,7 @@ export class ToolbarUIController {
name: SHEET_UI_PLUGIN_NAME + ColorSelect.name,
props: {
getComponent: (ref: ColorSelect) => {
- this._colorSelect1 = ref
+ this._colorSelect1 = ref;
},
color: '#000',
customLabel: {
@@ -176,6 +231,15 @@ export class ToolbarUIController {
},
},
},
+ onClick: () => {
+ this.hideTooltip();
+ const textColor = this._toolList.find((item) => item.name === 'textColor');
+ if (!textColor) return;
+ if (!textColor.customLabel) return;
+ if (!textColor.customLabel.props) return;
+ textColor.customLabel.props.color = this._textColor;
+ this.changeColor(this._textColor);
+ },
hideSelectedIcon: true,
className: styles.selectColorPickerParent,
children: [
@@ -185,7 +249,7 @@ export class ToolbarUIController {
props: {
onClick: (color: string, e: MouseEvent) => {
this._colorSelect1.setColor(color);
- this.setFontColor(color)
+ this._textColor = color;
},
},
},
@@ -202,7 +266,7 @@ export class ToolbarUIController {
name: SHEET_UI_PLUGIN_NAME + ColorSelect.name,
props: {
getComponent: (ref: ColorSelect) => {
- this._colorSelect2 = ref
+ this._colorSelect2 = ref;
},
color: '#fff',
customLabel: {
@@ -210,6 +274,15 @@ export class ToolbarUIController {
},
},
},
+ onClick: () => {
+ this.hideTooltip();
+ const fillColor = this._toolList.find((item) => item.name === 'fillColor');
+ if (!fillColor) return;
+ if (!fillColor.customLabel) return;
+ if (!fillColor.customLabel.props) return;
+ fillColor.customLabel.props.color = this._background;
+ this.setBackground(this._background);
+ },
hideSelectedIcon: true,
className: styles.selectColorPickerParent,
children: [
@@ -219,8 +292,8 @@ export class ToolbarUIController {
props: {
onClick: (color: string, e: MouseEvent) => {
this._colorSelect2.setColor(color);
- this.setBackground(color)
- }
+ this._background = color;
+ },
},
},
className: styles.selectColorPicker,
@@ -236,19 +309,23 @@ export class ToolbarUIController {
tooltip: 'toolbar.border.main',
className: styles.selectDoubleString,
onClick: (value: string) => {
- this._borderInfo.type = value as BorderType
- this.setBorder()
+ if (value) {
+ this._borderInfo.type = value as BorderType;
+ }
+ this.hideTooltip();
+ this.setBorder();
},
name: 'border',
children: [
...BORDER_LINE_CHILDREN,
{
+ name: 'borderColor',
customLabel: {
name: SHEET_UI_PLUGIN_NAME + LineColor.name,
props: {
color: '#000',
label: 'borderLine.borderColor',
- getComponent: (ref: LineColor) => this._lineColor = ref
+ getComponent: (ref: LineColor) => (this._lineColor = ref),
},
},
unSelectable: true,
@@ -259,8 +336,14 @@ export class ToolbarUIController {
name: SHEET_UI_PLUGIN_NAME + ColorPicker.name,
props: {
onClick: (color: string, e: MouseEvent) => {
- this._lineColor.setColor(color)
- this._borderInfo.color = color
+ this._lineColor.setColor(color);
+ this._borderInfo.color = color;
+ const borderItem = this._toolList.find((item) => item.name === 'border');
+ const lineColor = borderItem?.children?.find((item) => item.name === 'borderColor');
+ if (!lineColor) return;
+ if (!lineColor.customLabel) return;
+ if (!lineColor.customLabel.props) return;
+ lineColor.customLabel.props.color = color;
},
},
},
@@ -277,13 +360,13 @@ export class ToolbarUIController {
props: {
img: 0,
label: 'borderLine.borderSize',
- getComponent: (ref: LineBold) => this._lineBold = ref
+ getComponent: (ref: LineBold) => (this._lineBold = ref),
},
},
onClick: (...arg) => {
- arg[0].stopPropagation()
- this._lineBold.setImg(BORDER_SIZE_CHILDREN[arg[2]].customLabel?.name)
- this._borderInfo.style = arg[1]
+ arg[0].stopPropagation();
+ this._lineBold.setImg(BORDER_SIZE_CHILDREN[arg[2]].customLabel?.name);
+ this._borderInfo.style = arg[1];
},
className: styles.selectLineBoldParent,
unSelectable: true,
@@ -300,6 +383,7 @@ export class ToolbarUIController {
show: this._config.mergeCell,
onClick: (value: string) => {
this.setMerge(value);
+ this.hideTooltip();
},
name: 'mergeCell',
children: MERGE_CHILDREN,
@@ -313,6 +397,7 @@ export class ToolbarUIController {
show: this._config.horizontalAlignMode,
onClick: (value: HorizontalAlign) => {
this.setHorizontalAlignment(value);
+ this.hideTooltip();
},
children: HORIZONTAL_ALIGN_CHILDREN,
},
@@ -325,6 +410,7 @@ export class ToolbarUIController {
show: this._config.verticalAlignMode,
onClick: (value: VerticalAlign) => {
this.setVerticalAlignment(value);
+ this.hideTooltip();
},
children: VERTICAL_ALIGN_CHILDREN,
},
@@ -337,6 +423,7 @@ export class ToolbarUIController {
show: this._config.textWrapMode,
onClick: (value: WrapStrategy) => {
this.setWrapStrategy(value);
+ this.hideTooltip();
},
children: TEXT_WRAP_CHILDREN,
},
@@ -349,6 +436,7 @@ export class ToolbarUIController {
show: this._config.textRotateMode,
onClick: (value: number | string) => {
this.setTextRotation(value);
+ this.hideTooltip();
},
children: TEXT_ROTATE_CHILDREN,
},
@@ -357,125 +445,6 @@ export class ToolbarUIController {
this._initialize();
}
- private _initialize() {
- this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + ColorSelect.name, ColorSelect)
- this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker)
- this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineColor.name, LineColor)
- this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineBold.name, LineBold)
-
- this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add((selectionControl: SelectionControl) => {
- const manager = this._sheetPlugin.getSelectionManager();
- const range = manager?.getCurrentCell();
- if (range) {
- this._changeToolbarState(range);
- }
- });
- }
-
- private _changeToolbarState(range: Range): void {
- const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
- const worksheet = workbook.getActiveSheet();
- if (worksheet) {
- const isBold = range.getFontWeight();
- const IsItalic = range.getFontStyle()
- const strikeThrough = range.getStrikeThrough();
- const fontSize = range.getFontSize();
- const fontWeight = range.getFontWeight();
- const fontName = range.getFontFamily();
- const fontItalic = range.getFontStyle();
- // const fontColor = range.getFontColor();
- // const background = range.getBackground();
- const underline = range.getUnderline();
- const horizontalAlign = range.getHorizontalAlignment() ?? HorizontalAlign.LEFT;
- const verticalAlign = range.getVerticalAlignment() ?? VerticalAlign.BOTTOM;
- const rotation = range.getTextRotation();
- const warp = range.getWrapStrategy() ?? WrapStrategy.CLIP;
-
- const bold = this._toolList.find((item) => item.name === 'bold')
- const italic = this._toolList.find((item) => item.name === 'italic')
- const textRotateModeItem = this._toolList.find((item) => item.name === 'textRotateMode');
- const fontSizeItem = this._toolList.find((item) => item.name === 'fontSize');
- const fontNameItem = this._toolList.find((item) => item.name === 'font');
- const fontBoldItem = this._toolList.find((item) => item.name === 'bold');
- const fontItalicItem = this._toolList.find((item) => item.name === 'italic');
- // const textColor = this._toolList.find((item) => item.name === 'textColor')
- // const fillColor = this._toolList.find((item) => item.name === 'fillColor')
- const strikethroughItem = this._toolList.find((item) => item.name === 'strikethrough');
- const underlineItem = this._toolList.find((item) => item.name === 'underline');
- const horizontalAlignModeItem = this._toolList.find((item) => item.name === 'horizontalAlignMode');
- const verticalAlignModeItem = this._toolList.find((item) => item.name === 'verticalAlignMode');
- const textWrapMode = this._toolList.find((item) => item.name === 'textWrapMode');
- // const border = this._toolList.find((item) => item.name === 'border')
-
- if (bold) {
- bold.active = isBold === FontWeight.BOLD
- }
-
- if (italic) {
- italic.active = IsItalic === FontItalic.ITALIC
- }
-
- if (strikethroughItem) {
- strikethroughItem.active = !!(strikeThrough && strikeThrough.s);
- }
- if (fontNameItem) {
- fontNameItem.children?.forEach((item) => {
- item.selected = fontName === item.value;
- });
- }
- if (fontSizeItem) {
- fontSizeItem.label = fontSize.toString()
- }
- if (fontBoldItem) {
- fontBoldItem.active = !!fontWeight;
- }
- if (fontItalicItem) {
- fontItalicItem.active = !!fontItalic;
- }
- // if (textColor) {
- // const label = textColor.customLabel
- // if (label && label.props) {
- // label.props.color = fontColor
- // }
- // }
- // if (fillColor) {
- // const label = fillColor.customLabel
- // if (label && label.props) {
- // label.props.color = background
- // }
- // }
- if (underlineItem) {
- underlineItem.active = !!(underline && underline.s);
- }
- if (horizontalAlignModeItem) {
- horizontalAlignModeItem.children?.forEach((item) => {
- item.selected = horizontalAlign === item.value;
- });
- }
- if (textRotateModeItem) {
- textRotateModeItem.children?.forEach((item) => {
- if (rotation.v) {
- item.selected = item.value === 'v'
- } else {
- item.selected = rotation.a === item.value;
- }
- });
- }
- if (verticalAlignModeItem) {
- verticalAlignModeItem.children?.forEach((item) => {
- item.selected = verticalAlign === item.value;
- });
- }
- if (textWrapMode) {
- textWrapMode.children?.forEach((item) => {
- item.selected = warp === item.value;
- });
- }
-
- this.setToolbar();
- }
- }
-
// 获取Toolbar组件
getComponent = (ref: Toolbar) => {
this._toolbar = ref;
@@ -507,6 +476,18 @@ export class ToolbarUIController {
this._plugin.getContext().getObserverManager().requiredObserver<UIObserver<T>>('onUIChangeObservable', 'core').notifyObservers(msg);
}
+ changeColor(color: string) {
+ const strikethroughItem = this._toolList.find((item) => item.name === 'strikethrough');
+ const underlineItem = this._toolList.find((item) => item.name === 'underline');
+ this.setFontColor(color);
+ if (underlineItem) {
+ this.setUnderline(underlineItem.active ?? false);
+ }
+ if (strikethroughItem) {
+ this.setStrikeThrough(strikethroughItem.active ?? false);
+ }
+ }
+
setUndo() {
const msg = {
name: 'undo',
@@ -585,7 +566,6 @@ export class ToolbarUIController {
this.setUIObserve(msg);
}
-
setMerge(value: string) {
const msg = {
name: 'merge',
@@ -633,4 +613,146 @@ export class ToolbarUIController {
};
this.setUIObserve<IKeyValue>(msg);
}
+
+ hideTooltip() {
+ const dom = this._toolbar.base as HTMLDivElement;
+ const tooltip = dom.querySelectorAll(`.${styles.tooltipTitle}.${styles.bottom}`);
+ tooltip.forEach((item) => {
+ (item as HTMLSpanElement).style.display = 'none';
+ });
+ }
+
+ private _changeToolbarState(range: Range): void {
+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();
+ const worksheet = workbook.getActiveSheet();
+ if (worksheet) {
+ const isBold = range.getFontWeight();
+ const IsItalic = range.getFontStyle();
+ const strikeThrough = range.getStrikeThrough();
+ const fontSize = range.getFontSize();
+ const fontWeight = range.getFontWeight();
+ const fontName = range.getFontFamily();
+ const fontItalic = range.getFontStyle();
+ // const fontColor = range.getFontColor();
+ // const background = range.getBackground();
+ const underline = range.getUnderline();
+ const horizontalAlign = range.getHorizontalAlignment() ?? HorizontalAlign.LEFT;
+ const verticalAlign = range.getVerticalAlignment() ?? VerticalAlign.BOTTOM;
+ const rotation = range.getTextRotation();
+ const warp = range.getWrapStrategy() ?? WrapStrategy.CLIP;
+
+ const bold = this._toolList.find((item) => item.name === 'bold');
+ const italic = this._toolList.find((item) => item.name === 'italic');
+ const textRotateModeItem = this._toolList.find((item) => item.name === 'textRotateMode');
+ const fontSizeItem = this._toolList.find((item) => item.name === 'fontSize');
+ const fontNameItem = this._toolList.find((item) => item.name === 'font');
+ const fontBoldItem = this._toolList.find((item) => item.name === 'bold');
+ const fontItalicItem = this._toolList.find((item) => item.name === 'italic');
+ // const textColor = this._toolList.find((item) => item.name === 'textColor')
+ // const fillColor = this._toolList.find((item) => item.name === 'fillColor')
+ const strikethroughItem = this._toolList.find((item) => item.name === 'strikethrough');
+ const underlineItem = this._toolList.find((item) => item.name === 'underline');
+ const horizontalAlignModeItem = this._toolList.find((item) => item.name === 'horizontalAlignMode');
+ const verticalAlignModeItem = this._toolList.find((item) => item.name === 'verticalAlignMode');
+ const textWrapMode = this._toolList.find((item) => item.name === 'textWrapMode');
+
+ if (bold) {
+ bold.active = isBold === FontWeight.BOLD;
+ }
+
+ if (italic) {
+ italic.active = IsItalic === FontItalic.ITALIC;
+ }
+
+ if (strikethroughItem) {
+ strikethroughItem.active = !!(strikeThrough && strikeThrough.s);
+ }
+ if (fontNameItem) {
+ fontNameItem.children?.forEach((item) => {
+ item.selected = fontName === item.value;
+ });
+ }
+ if (fontSizeItem) {
+ fontSizeItem.label = fontSize.toString();
+ }
+ if (fontBoldItem) {
+ fontBoldItem.active = !!fontWeight;
+ }
+ if (fontItalicItem) {
+ fontItalicItem.active = !!fontItalic;
+ }
+ // if (textColor) {
+ // const label = textColor.customLabel
+ // if (label && label.props) {
+ // label.props.color = fontColor
+ // }
+ // }
+ // if (fillColor) {
+ // const label = fillColor.customLabel
+ // if (label && label.props) {
+ // label.props.color = background
+ // }
+ // }
+ if (underlineItem) {
+ underlineItem.active = !!(underline && underline.s);
+ }
+ if (horizontalAlignModeItem) {
+ horizontalAlignModeItem.children?.forEach((item) => {
+ item.selected = horizontalAlign === item.value;
+ });
+ }
+ if (textRotateModeItem) {
+ textRotateModeItem.children?.forEach((item) => {
+ if (rotation.v) {
+ item.selected = item.value === 'v';
+ } else {
+ item.selected = rotation.a === item.value;
+ }
+ });
+ }
+ if (verticalAlignModeItem) {
+ verticalAlignModeItem.children?.forEach((item) => {
+ item.selected = verticalAlign === item.value;
+ });
+ }
+ if (textWrapMode) {
+ textWrapMode.children?.forEach((item) => {
+ item.selected = warp === item.value;
+ });
+ }
+
+ this.setToolbar();
+ }
+ }
+
+ private _initialize() {
+ this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + ColorSelect.name, ColorSelect);
+ this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);
+ this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineColor.name, LineColor);
+ this._plugin.getComponentManager().register(SHEET_UI_PLUGIN_NAME + LineBold.name, LineBold);
+
+ // this._sheetPlugin.getObserver('onChangeSelectionObserver')?.add(() => {
+ // const manager = this._sheetPlugin.getSelectionManager();
+ // const range = manager?.getCurrentCell();
+ // if (range) {
+ // this._changeToolbarState(range);
+ // }
+ // });
+
+ CommandManager.getCommandObservers().add(({ actions }) => {
+ if (!actions || actions.length === 0) return;
+ const action = actions[0] as SheetActionBase<ISheetActionData, ISheetActionData, void>;
+
+ const currentUnitId = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook().getUnitId();
+ const actionUnitId = action.getWorkBook().getUnitId();
+
+ if (currentUnitId !== actionUnitId) return;
+
+ const manager = this._sheetPlugin.getSelectionManager();
+ const range = manager?.getCurrentCell();
+ if (range) {
+ this._changeToolbarState(range);
+ }
+ });
+ }
}
diff --git a/packages/ui-plugin-sheets/src/Controller/index.ts b/packages/ui-plugin-sheets/src/Controller/index.ts
index f6606b1a1d..a44f2c9e73 100644
--- a/packages/ui-plugin-sheets/src/Controller/index.ts
+++ b/packages/ui-plugin-sheets/src/Controller/index.ts
@@ -1,4 +1,3 @@
-export * from './InfoBarUIController';
export * from './RightMenuUIController';
export * from './ToolbarUIController';
export * from './SheetContainerUIController';
diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
index 23fe8f26bf..35c660be18 100644
--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts
@@ -1,9 +1,9 @@
import { Plugin, UniverSheet, Tools, PLUGIN_NAMES } from '@univerjs/core';
-import { zh, en } from './Locale';
-import { DefaultSheetUiConfig, installObserver, ISheetUIPluginConfig, SheetUIPluginObserve, SHEET_UI_PLUGIN_NAME } from './Basics';
import { Context } from '@univerjs/core/src/Basics/Context';
import { ComponentManager, getRefElement, RegisterManager } from '@univerjs/base-ui';
-import { Engine, RenderEngine } from '@univerjs/base-render';
+import { RenderEngine } from '@univerjs/base-render';
+import { DefaultSheetUiConfig, installObserver, ISheetUIPluginConfig, SheetUIPluginObserve, SHEET_UI_PLUGIN_NAME } from './Basics';
+import { zh, en } from './Locale';
import { AppUIController } from './Controller/AppUIController';
export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
@@ -65,13 +65,13 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve, Context> {
}, 0);
}
- initUI() {}
+ initUI() { }
onMounted(ctx: Context): void {
this.initialize(ctx);
}
- onDestroy(): void {}
+ onDestroy(): void { }
getAppUIController() {
return this._appUIController;
diff --git a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
index 40a353d3c9..6bca2a8166 100644
--- a/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/ColorSelect/ColorSelect.tsx
@@ -1,5 +1,4 @@
import { BaseComponentProps, Component, ComponentChildren } from '@univerjs/base-ui';
-import { PLUGIN_NAMES } from '@univerjs/core';
import { SheetUIPlugin } from '../../..';
import { SHEET_UI_PLUGIN_NAME } from '../../../Basics';
import styles from './index.module.less';
diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
index dc089d245a..9d22f176df 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineBold.tsx
@@ -1,4 +1,4 @@
-import { BaseComponentProps, BaseComponentRender, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
import { SheetUIPlugin } from '../../..';
import { SHEET_UI_PLUGIN_NAME } from '../../../Basics';
diff --git a/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx b/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
index 4ec8233898..6d5ac26047 100644
--- a/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
+++ b/packages/ui-plugin-sheets/src/View/Common/Line/LineColor.tsx
@@ -1,4 +1,4 @@
-import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, Component, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, Component, Icon } from '@univerjs/base-ui';
interface IState {
color: string;
diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
index ff934bc237..7d06542f18 100644
--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx
@@ -5,7 +5,7 @@ import styles from './index.module.less';
interface CountState {
zoom: number;
content: string;
-};
+}
interface CountBarProps extends BaseCountBarProps {
onChange?: (value: string) => void;
diff --git a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
index b2c94d47af..f0780bd7cf 100644
--- a/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/FormulaBar/FormulaBar.tsx
@@ -1,4 +1,4 @@
-import { BaseComponentProps, BaseComponentRender, BaseComponentSheet, BaseSelectChildrenProps, Component, debounce, Icon } from '@univerjs/base-ui';
+import { BaseComponentProps, BaseComponentRender, BaseSelectChildrenProps, Component, debounce, Icon } from '@univerjs/base-ui';
import styles from './index.module.less';
type FormulaState = {
@@ -55,7 +55,6 @@ export class FormulaBar extends Component<BaseFormulaBarProps, FormulaState> {
}
render(props: BaseFormulaBarProps, state: FormulaState) {
-
// TODO: formula bar top left menu: 1. cell edit formula ,use formula list 2. cell selection ,use named range, 3. cell edit no formula, disable select
const { namedRanges } = state;
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
index d0fd4a4229..4d53fac0a2 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx
@@ -16,6 +16,8 @@ interface IState {
export class RightMenu extends Component<BaseRightMenuProps, IState> {
ulRef = createRef();
+ root = createRef();
+
initialize() {
this.state = {
visible: false,
@@ -26,8 +28,6 @@ export class RightMenu extends Component<BaseRightMenuProps, IState> {
};
}
- root = createRef();
-
// 转换成渲染需要的数据
resetMenuList(children: RightMenuProps[], replace: RightMenuProps[]) {
const componentManager = this.getContext().getPluginManager().getPluginByName<SheetUIPlugin>(SHEET_UI_PLUGIN_NAME)?.getComponentManager();
diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
index 93328b60eb..13caab51df 100644
--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx
@@ -21,7 +21,7 @@ export class RightMenuInput extends Component<IProps> {
return (
<div>
{this.getLocale(prefix)}
- <Input onKeyUp={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>
+ <Input onPressEnter={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>
{this.getLocale(suffix)}
</div>
);
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index 1e7182044c..7260266a8d 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -1,21 +1,6 @@
-import {
- AppContext,
- AppContextValues,
- BaseComponentPlugin,
- BaseComponentRender,
- BaseComponentSheet,
- BaseMenuItem,
- BaseSheetBarProps,
- Button,
- Component,
- createRef,
- Icon,
- Menu,
- PreactContext,
- RefObject,
-} from '@univerjs/base-ui';
+import { BaseMenuItem, BaseSheetBarProps, Button, Component, createRef, Icon, Menu, RefObject } from '@univerjs/base-ui';
+import { Nullable, Observer, Workbook } from '@univerjs/core';
import { SheetBarMenu } from './SheetBarMenu';
-import { Nullable, Observer, PLUGIN_NAMES, Workbook } from '@univerjs/core';
import styles from './index.module.less';
import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';
import { SheetUIPlugin, SHEET_UI_PLUGIN_NAME } from '../..';
@@ -41,6 +26,17 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
slideTabBar: SlideTabBar;
+ // 先生成移动对象的副本,移动对象固定定位,达到边界的时候将副本移位
+ time = 0;
+
+ target: any = null;
+
+ cloneTarget: any = null;
+
+ startLeft: number;
+
+ startClientX: number;
+
private _localeObserver: Nullable<Observer<Workbook>>;
private _renderKey: number = 1;
@@ -191,17 +187,6 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
this.props.getComponent?.(this);
}
- // 先生成移动对象的副本,移动对象固定定位,达到边界的时候将副本移位
- time = 0;
-
- target: any = null;
-
- cloneTarget: any = null;
-
- startLeft: number;
-
- startClientX: number;
-
render(props: BaseSheetBarProps, state: SheetState) {
const { sheetList, menuList, sheetUl } = state;
const { addSheet, selectSheet } = this.props;
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
index 00111d8cc5..b1dc7fb94a 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx
@@ -44,7 +44,7 @@ export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {
showMenu(show: boolean) {
this.setState({ show }, () => {
- if (true) window.addEventListener('click', this.hideMenu, true);
+ if (this.state.show) window.addEventListener('click', this.hideMenu, true);
});
}
diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
index 4b9a8e82b5..557c9cb7fb 100644
--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx
@@ -1,17 +1,17 @@
+import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
+import defaultSkin from '@univerjs/base-ui/Basics/CSS/Skin/default.module.less';
+import { Tools } from '@univerjs/core';
+import cssVars from 'css-vars-ponyfill';
import style from './index.module.less';
-import { Toolbar } from '../Toolbar';
import { InfoBar } from '../InfoBar';
import { RightMenu } from '../RightMenu';
import { CountBar } from '../CountBar';
import { SheetBar } from '../SheetBar';
import { FormulaBar } from '../FormulaBar';
import { RichText } from '../RichText';
-import { BaseComponentProps, Component, Container, Content, createRef, Footer, Header, Layout, Sider } from '@univerjs/base-ui';
import { ISheetUIPluginConfig } from '../../Basics';
-import defaultSkin from '@univerjs/base-ui/Basics/CSS/Skin/default.module.less';
-import { Tools } from '@univerjs/core';
-import cssVars from 'css-vars-ponyfill';
import { Slot } from '../Slot/Slot';
+import { Toolbar } from '../Toolbar';
export interface BaseSheetContainerProps extends BaseComponentProps {
config: ISheetUIPluginConfig;
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts b/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts
index 39a8bab1df..c2db56e735 100644
--- a/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts
+++ b/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts
@@ -1,4 +1,4 @@
-import { BorderStyleTypes } from "@univerjs/core";
+import { BorderStyleTypes } from '@univerjs/core';
export const FONT_SIZE_CHILDREN = [
{
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx
index 9427e79870..aacc52a51f 100644
--- a/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx
@@ -30,6 +30,13 @@ export class Toolbar extends Component<IProps, IState> {
clientWidth = 0;
+ /**
+ * Gets the distance of each button from the parent element
+ */
+ debounceSetToolbarListWidth = debounce(() => {
+ this.setToolbarListWidth();
+ }, 50);
+
initialize() {
this.state = {
// Button contains main button and drop down arrow, translation file contains main and right
@@ -62,13 +69,6 @@ export class Toolbar extends Component<IProps, IState> {
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;
@@ -217,7 +217,7 @@ export class Toolbar extends Component<IProps, IState> {
if (item.show) {
return (
<Tooltip title={this.getLocale(item.tooltip)} placement={'bottom'}>
- <Button className={styles.textButton} type="text" active={item.active} onClick={item.onClick}>
+ <Button unActive={item.unActive} className={styles.textButton} type="text" active={item.active} onClick={item.onClick}>
{item.label}
</Button>
</Tooltip>
@@ -235,7 +235,8 @@ export class Toolbar extends Component<IProps, IState> {
customSuffix={item.customSuffix}
label={item.label}
onClick={item.onClick}
- onKeyUp={item.onKeyUp}
+ onPressEnter={item.onPressEnter}
+ onMainClick={item.onMainClick}
defaultColor={item.defaultColor}
hideSelectedIcon={item.hideSelectedIcon}
className={item.className}
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css
index 1379b5148c..9e3a5b2d04 100644
--- a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css
+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css
@@ -114,3 +114,9 @@
padding: 0px;
line-height: 1;
}
+.tooltip-title {
+ display: none;
+}
+.bottom {
+ display: none;
+}
diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less
index 648d0fef8b..96ebf0100e 100644
--- a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less
+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less
@@ -161,4 +161,12 @@
.button() {
padding: 0px;
line-height: 1;
+}
+
+.tooltip-title {
+ display: none;
+}
+
+.bottom {
+ display: none;
}
\ No newline at end of file