Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
flush
jerryd2590698f334
diff --git a/.vscode/settings.json b/.vscode/settings.jsonindex b7ef461629..5ff9f0c898 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -71,5 +71,8 @@"typescript.preferences.importModuleSpecifier": "relative","[xml]": {"editor.defaultFormatter": "redhat.vscode-xml"+ },+ "[typescript]": {+ "editor.defaultFormatter": "vscode.typescript-language-features"}}diff --git a/packages/base-sheets/src/Locale/zh.ts b/packages/base-sheets/src/Locale/zh.tsindex 410b39a524..ac0a278601 100644--- a/packages/base-sheets/src/Locale/zh.ts+++ b/packages/base-sheets/src/Locale/zh.ts@@ -6,7 +6,7 @@ export default {two: '二',three: '三',},-+ // toolbar.undotoolbar: {undo: '撤销',redo: '重做',diff --git a/packages/base-ui/src/Common/EventManager.ts b/packages/base-ui/src/Common/EventManager.tsindex 371af92dff..b9211de82d 100644--- a/packages/base-ui/src/Common/EventManager.ts+++ b/packages/base-ui/src/Common/EventManager.ts@@ -14,5 +14,6 @@ export class EventManager {this._observerManager.addObserver('onUIChangeObservable', 'core', new Observable());this._observerManager.addObserver('onAfterChangeUILocaleObservable', 'core', new Observable());this._observerManager.addObserver('onViewComponentFocusChange', 'core', new Observable());+ this._observerManager.addObserver('onViewComponentFocusChange', 'core', new Observable());}}diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.tsnew file mode 100644index 0000000000..95a8bbd681--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts@@ -0,0 +1,148 @@+const Tween = {+ easeOutStrong(t: number, b: number, c: number, d: number): number {+ return -c * ((t = t / d - 1) * t * t * t - 1) + b;+ },+ backOut(t: number, b: number, c: number, d: number, s: number): number {+ if (typeof s === 'undefined') {+ s = 0.7;+ }+ return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;+ },+};++export interface AnimateConfig {+ loop: boolean;+ begin: number;+ end: number;+ duration: number;+ delay: number;+ type: string;+ receive: (v: number) => void;+ success: (v: number) => void;+ cancel: (v: number) => void;+ complete: (v: number) => void;+}++const CONFIG: AnimateConfig = {+ loop: false,+ begin: 0,+ end: 0,+ duration: 300,+ delay: 0,+ type: 'easeOutStrong',+ receive(v) {+ /*noop*/+ },+ success(v) {+ /*noop*/+ },+ cancel(v) {+ /*noop*/+ },+ complete(v) {+ /*noop*/+ },+};++export enum AnimateStatus {+ Request,+ Cancel,+}++export class Animate {+ static success(...animates: Animate[]): Promise<void> {+ let successNumber = 0;+ return new Promise<void>((resolve) => {+ for (let i = 0; i < animates.length; i++) {+ let animate = animates[i];+ let config = animate._config;+ let success = config.success;+ let loop = config.loop;+ if (loop) {+ continue;+ }+ config.success = (v) => {+ successNumber++;+ if (success) {+ success.call(animate, v);+ }+ if (successNumber === animates.length) {+ resolve();+ }+ };+ }+ });+ }++ protected _config: AnimateConfig;++ protected _status: AnimateStatus;++ protected _start: number;++ protected _handle: number;++ protected _delayHandle: NodeJS.Timeout;++ protected _fakeHandle(): void {+ let times = Date.now() - this._start;+ times = times >= this._config.duration ? this._config.duration : times;++ let val = Tween[this._config.type](times, this._config.begin, this._config.end - this._config.begin, this._config.duration, 0.7);+ let fix = val.toFixed(2);++ this._config.receive(fix);++ if (this._status === AnimateStatus.Cancel) {+ this._config.cancel(fix);+ this._config.complete(fix);+ return;+ }++ if (times === this._config.duration) {+ this._config.success(fix);+ this._config.complete(fix);+ return;+ }++ this._handle = requestAnimationFrame(() => {+ this._fakeHandle();+ });+ }++ constructor(config: Partial<AnimateConfig>) {+ this._config = {+ ...CONFIG,+ ...config,+ };+ if (this._config.loop) {+ this._config.complete = () => {+ /*noop*/+ };+ this._config.success = () => {+ this.request();+ };+ }+ }++ request(): void {+ if (this._config.delay === 0) {+ this._status = AnimateStatus.Request;+ this._start = Date.now();+ this._fakeHandle();+ } else {+ this._delayHandle && clearTimeout(this._delayHandle);+ this._delayHandle = setTimeout(() => {+ this._status = AnimateStatus.Request;+ this._start = Date.now();+ this._fakeHandle();+ }, this._config.delay);+ }+ }++ cancel(): void {+ this._status = AnimateStatus.Cancel;+ this._delayHandle && clearTimeout(this._delayHandle);+ cancelAnimationFrame(this._handle);+ }+}diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.tsnew file mode 100644index 0000000000..9c9ba345d1--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts@@ -0,0 +1,29 @@+import { SlideTabBar } from './SlideTabBar';++export class SlideScrollbar {+ protected _slideTabBar: SlideTabBar;++ protected _scrollX: number;++ constructor(slideTabBar: SlideTabBar) {+ const primeval = slideTabBar.primeval();+ this._scrollX = primeval.scrollLeft;+ this._slideTabBar = slideTabBar;+ }++ scrollX(x: number): void {+ const primeval = this._slideTabBar.primeval();+ primeval.scrollLeft = x;+ this._scrollX = primeval.scrollLeft;+ }++ scrollRight(): void {+ const primeval = this._slideTabBar.primeval();+ primeval.scrollLeft = primeval.scrollWidth;+ this._scrollX = primeval.scrollLeft;+ }++ getScrollX(): number {+ return this._scrollX;+ }+}diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.tsnew file mode 100644index 0000000000..df64933449--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.ts@@ -0,0 +1,411 @@+import { SlideScrollbar } from './SlideScrollbar';+import { SlideTabItem } from './SlideTabItem';++export interface SlideTabBarConfig {+ slideTabBarClassName: string;+ slideTabBarItemActiveClassName: string;+ slideTabBarItemClassName: string;+ slideTabRoot: HTMLElement;+ activeClassNameAutoController: boolean;+ slideTabBarItemAutoSort: boolean;+ onSlideEnd: (event: MouseEvent) => void;+ onChangeName: (event: FocusEvent) => void;+}++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;++ _slideTabItems: SlideTabItem[];++ _config: SlideTabBarConfig;++ _downActionX: number;++ _moveActionX: number;++ _compareIndex: number | null;++ _activeTabItem: SlideTabItem | null;++ _moveAction: (e: MouseEvent) => void;++ _upAction: (e: MouseEvent) => void;++ _downAction: (e: MouseEvent) => void;++ _wheelAction: (e: WheelEvent) => void;++ _scrollIncremental: number;++ _compareDirection: number;++ _autoScrollTime: number | null;++ _slideScrollbar: SlideScrollbar;++ _hasEditItem(): boolean {+ for (let index = 0; index < this._slideTabItems.length; index++) {+ const element = this._slideTabItems[index];+ if (element.isEditMode()) {+ return true;+ }+ }+ return false;+ }++ _autoScrollFrame(): void {+ if (this._activeTabItem) {+ this._compareDirection = this._activeTabItem.translateX(this._moveActionX);+ switch (this._compareDirection) {+ case 1: {+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);+ this._compareRight();+ break;+ }+ case 0: {+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);+ this._compareIndex = this._activeTabItemIndex;+ break;+ }+ case -1: {+ this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + this._scrollIncremental);+ this._compareLeft();+ break;+ }+ }+ }+ this._autoScrollTime = requestAnimationFrame(() => {+ this._autoScrollFrame();+ });+ }++ _startAutoScroll(): void {+ if (this._autoScrollTime == null) {+ this._autoScrollFrame();+ }+ }++ _closeAutoScroll(): void {+ if (this._autoScrollTime) {+ cancelAnimationFrame(this._autoScrollTime);+ }+ this._autoScrollTime = null;+ }++ _scrollLeft(event: MouseEvent): void {+ const boundingRect = this.getBoundingRect();+ const boundingLine = 10;+ const x = event.pageX - boundingRect.x;+ if (x < boundingLine) {+ this._scrollIncremental = -Math.min(Math.abs(x - boundingLine) * 0.1, 50);+ }+ }++ _scrollRight(event: MouseEvent): void {+ const boundingRect = this.getBoundingRect();+ const boundingLine = 10;+ const x = event.pageX - boundingRect.x;+ if (x > boundingRect.width - boundingLine) {+ this._scrollIncremental = Math.min(Math.abs(x - (boundingRect.width - boundingLine)) * 0.1, 50);+ }+ }++ _sortedItems(): void {+ if (this._activeTabItem != null && this._activeTabItemIndex != null && this._compareIndex != null) {+ // data array list sort+ this._slideTabItems.splice(this._activeTabItemIndex, 1);+ this._slideTabItems.splice(this._compareIndex, 0, this._activeTabItem);++ // dom list sort+ if (this._config.slideTabBarItemAutoSort) {+ for (let i = 0; i < this._slideTabItems.length; i++) {+ let item = this._slideTabItems[i];+ let next = this._slideTabItems[i + 1];+ if (next) {+ item.after(next);+ }+ }+ }+ }+ }++ _compareLeft(): void {+ if (this._activeTabItem && this._activeTabItemIndex) {+ let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));+ let length = this._slideTabItems.length;+ let collect = [];++ // collect compare item+ for (let i = 0; i < splice; i++) {+ if (i >= splice) {+ break;+ }+ collect.push(this._slideTabItems[i]);+ }++ // reset right+ for (let i = splice + 1; i < length; i++) {+ this._slideTabItems[i].animate().translateX(0);+ }++ // diff item midline+ let notFound = true;+ for (let i = collect.length - 1; i >= 0; i--) {+ let item = collect[i];+ if (SlideTabItem.midline(this._activeTabItem) < item.getMidLine()) {+ item.animate().translateX(this._activeTabItem.getWidth());+ this._compareIndex = i;+ notFound = false;+ } else {+ item.animate().translateX(0);+ if (notFound) {+ this._compareIndex = this._activeTabItemIndex;+ }+ }+ }+ }+ }++ _compareRight(): void {+ if (this._activeTabItem) {+ let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));+ let length = this._slideTabItems.length;+ let collect = [];++ // collect compare item+ for (let i = splice + 1; i < length; i++) {+ collect.push(this._slideTabItems[i]);+ }++ // reset left+ for (let i = 0; i < splice; i++) {+ this._slideTabItems[i].animate().translateX(0);+ }++ // diff item midline+ let notFound = true;+ for (let i = 0; i < collect.length; i++) {+ let item = collect[i];+ if (SlideTabItem.midline(this._activeTabItem) > item.getMidLine()) {+ item.animate().translateX(-this._activeTabItem.getWidth());+ this._compareIndex = splice + i + 1;+ notFound = false;+ } else {+ item.animate().translateX(0);+ if (notFound) {+ this._compareIndex = this._activeTabItemIndex;+ }+ }+ }+ }+ }++ _initialize(): void {+ document.addEventListener('mousemove', this._moveAction);+ document.addEventListener('mouseup', this._upAction);+ this._slideTabBar.addEventListener('wheel', this._wheelAction);+ this._slideTabItems.forEach((item) => {+ item.addEventListener('mousedown', this._downAction);+ });+ }++ 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;+ }++ updateItems(): void {+ for (let i = 0; i < this._slideTabItems.length; i++) {+ this._slideTabItems[i].animate().cancel();+ this._slideTabItems[i].translateX(0);+ this._slideTabItems[i].update();+ }+ }++ getScrollbar(): SlideScrollbar {+ return this._slideScrollbar;+ }++ getConfig(): SlideTabBarConfig {+ return this._config;+ }++ getBoundingRect(): DOMRect {+ return this._slideTabBar.getBoundingClientRect();+ }++ getSlideTabItems(): SlideTabItem[] {+ return this._slideTabItems;+ }++ destroy(): void {+ document.removeEventListener('mousemove', this._moveAction);+ document.removeEventListener('mouseup', this._upAction);+ document.removeEventListener('wheel', this._wheelAction);+ this._slideTabItems.forEach((item) => {+ item.removeEventListener('mousedown', this._downAction);+ });+ }+}diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.tsnew file mode 100644index 0000000000..9bd9728591--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.ts@@ -0,0 +1,223 @@+import { SlideTabBar } from './SlideTabBar';+import { Animate } from './Animate';+import { SlideScrollbar } from './SlideScrollbar';++export interface SlideTabItemAnimate {+ translateX: (x: number) => void;+ cancel: () => void;+}++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;++ _midline: number;++ _translateX: number;++ _scrollbar: SlideScrollbar;++ _slideTabBar: SlideTabBar;++ _editMode: boolean;++ _placeholder: HTMLElement | null;++ constructor(slideTabItem: HTMLElement, slideTabBar: SlideTabBar) {+ this._slideTabItem = slideTabItem;+ this._animate = null;+ this._translateX = 0;+ this._editMode = false;+ this._slideTabBar = slideTabBar;+ this._placeholder = null;+ this._scrollbar = slideTabBar.getScrollbar();+ this.update();+ }++ isEditMode(): boolean {+ return this._editMode;+ }++ classList(): DOMTokenList {+ return this._slideTabItem.classList;+ }++ primeval(): HTMLElement {+ return this._slideTabItem;+ }++ translateX(x: number) {+ this._translateX = x;+ this._slideTabItem.style.transform = `translateX(${x}px)`;+ return this.getTranslateXDirection();+ }++ editor(callback?: (event: FocusEvent) => void): void {+ if (this._editMode === false) {+ let input = this.primeval().querySelector('span');++ let blurAction = (focusEvent: FocusEvent) => {+ this._editMode = false;++ if (input) {+ input.removeAttribute('contentEditable');+ input.removeEventListener('blur', blurAction);+ input.removeEventListener('input', inputAction);+ }++ this._slideTabBar.updateItems();++ if (this._slideTabBar.getConfig().onChangeName) {+ this._slideTabBar.getConfig().onChangeName(focusEvent);+ }++ if (callback) {+ callback(focusEvent);+ }+ };++ let inputAction = () => {+ if (input) {+ const brs = input.querySelectorAll('br');+ if (brs.length > 0) {+ brs.forEach((br) => {+ if (input) {+ input.removeChild(br);+ }+ });+ input.blur();+ }+ }+ };++ if (input) {+ input.setAttribute('contentEditable', 'true');+ input.addEventListener('blur', blurAction);+ input.addEventListener('input', inputAction);+ this._editMode = true;+ SlideTabBar.keepLastIndex(input);+ }+ }+ }++ animate(): SlideTabItemAnimate {+ return {+ translateX: (x: number) => {+ if (this._translateX !== x) {+ if (this._animate) {+ this._animate.cancel();+ this._animate = null;+ }+ this._animate = new Animate({+ begin: this._translateX,+ end: x,+ receive: (val: number) => {+ this._slideTabItem.style.transform = `translateX(${val}px)`;+ },+ });+ this._translateX = x;+ this._animate.request();+ }+ },+ cancel: () => {+ if (this._animate) {+ this._animate.cancel();+ this._animate = null;+ }+ },+ };+ }++ after(other: SlideTabItem) {+ this._slideTabItem.after(other._slideTabItem || other);+ }++ update() {+ this._midline = SlideTabItem.midline(this);+ }++ disableFixed() {+ if (this._placeholder) {+ const primeval = this._slideTabBar.primeval();++ this._slideTabItem.style.removeProperty('position');+ this._slideTabItem.style.removeProperty('left');+ this._slideTabItem.style.removeProperty('top');+ this._slideTabItem.style.removeProperty('width');+ this._slideTabItem.style.removeProperty('height');+ this._slideTabItem.style.removeProperty('box-shadow');+ this._slideTabItem.style.removeProperty('background');++ this._placeholder.after(this._slideTabItem);+ primeval.removeChild(this._placeholder);+ this._placeholder = null;+ }+ }++ enableFixed() {+ const placeholder = document.createElement('div');+ const boundingRect = this.getBoundingRect();++ this._placeholder = placeholder;+ this._placeholder.style.width = `${boundingRect.width}px`;+ this._placeholder.style.height = `${boundingRect.height}px`;+ this._placeholder.style.flexShrink = '0';++ this._slideTabItem.style.left = `${boundingRect.x - this.getScrollbar().getScrollX()}px`;+ this._slideTabItem.style.top = `${boundingRect.y}px`;+ this._slideTabItem.style.width = `${boundingRect.width}px`;+ this._slideTabItem.style.height = `${boundingRect.height}px`;+ this._slideTabItem.style.background = getComputedStyle(this._slideTabItem).background;+ this._slideTabItem.style.boxShadow = '0px 0px 1px 1px rgba(82,82,82,0.1)';+ this._slideTabItem.style.position = 'fixed';++ this._slideTabItem.after(placeholder);+ document.body.appendChild(this._slideTabItem);+ }++ addEventListener<K extends keyof HTMLElementEventMap>(type: K, action: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions) {+ this._slideTabItem.addEventListener(type, action, options);+ }++ removeEventListener<K extends keyof HTMLElementEventMap>(type: K, action: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions) {+ this._slideTabItem.removeEventListener(type, action, options);+ }++ getScrollbar() {+ return this._scrollbar;+ }++ getMidLine() {+ return this._midline;+ }++ getBoundingRect() {+ const boundingClientRect = this._slideTabItem.getBoundingClientRect();+ boundingClientRect.x += this._scrollbar.getScrollX();+ return boundingClientRect;+ }++ getWidth() {+ return this.getBoundingRect().width;+ }++ getTranslateXDirection() {+ const midline = SlideTabItem.midline(this);+ return midline > this._midline ? 1 : midline < this._midline ? -1 : 0;+ }++ equals(other: SlideTabItem | null) {+ return other && other._slideTabItem === this._slideTabItem;+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.tsindex 6431403a3e..837d17a30d 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts@@ -1,7 +1,7 @@-import { BaseMenuItem, BaseUlProps } from '@univerjs/base-ui';+import { BaseMenuItem, BaseUlProps, ColorPicker } from '@univerjs/base-ui';import { Nullable, Plugin, ACTION_NAMES, CommandManager, SheetActionBase } from '@univerjs/core';import { SheetBar } from "../View/SheetBar";-import styles from '../View/UI/SheetBar/index.module.less';+import styles from '../View/SheetBar/index.module.less';interface CustomComponent {name: string;@@ -35,52 +35,37 @@ export class SheetBarUIController {protected _plugin: Plugin;- protected _initializeObs() {- const plugin = this._plugin;- const manager = context.getObserverManager();- const context = plugin.getContext();- const workbook = context.getWorkBook();- const unitId = workbook.getUnitId();- // manager.requiredObserver<SheetBar>('onSheetBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET);- manager.requiredObserver<SheetBar>('onSheetBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET).add((component) => {-- });- context.getContextObserver('onAfterChangeUILocaleObservable').add(() => {- this._sheetUl = this.resetSheetUl(this._sheetUl);- this._sheetBar.setValue({- sheetUl: this._sheetUl,- });- });- CommandManager.getActionObservers().add((actionEvent: any) => {- const action = actionEvent.action as SheetActionBase<any>;- const workbook = action.getWorkBook();- const actionUnitId = workbook.getUnitId();- if (unitId !== actionUnitId) return;-- const { data } = actionEvent;- switch (data.actionName) {- case ACTION_NAMES.SET_SHEET_ORDER_ACTION:- case ACTION_NAMES.INSERT_SHEET_ACTION:- case ACTION_NAMES.SET_TAB_COLOR_ACTION:- case ACTION_NAMES.REMOVE_SHEET_ACTION:- case ACTION_NAMES.SET_WORKSHEET_NAME_ACTION:- case ACTION_NAMES.SET_WORKSHEET_ACTIVATE_ACTION:- case ACTION_NAMES.SET_WORKSHEET_STATUS_ACTION: {- // update data;- this._initializeData();- // set ui bar sheetList;- this._sheetBar.setValue({- sheetList: this._sheetList,- menuList: this._menuList,- });- break;+ protected _refreshSheetBarUI(): void {+ this._sheetBar.setValue({+ sheetList: this._sheetList,+ sheetUl: this._sheetUl,+ menuList: this._menuList,+ addSheet: () => {+ // this._barControl.addSheet();+ },+ selectSheet: (event: Event, data: { item: SheetUlProps }) => {+ this._dataId = data.item.sheetId;+ const sheet = this._plugin.getContext().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: (e: Event) => {+ //this._barControl.changeSheetName(e);+ },+ dragEnd: (elements: HTMLDivElement[]) => {+ //this._barControl.dragEnd(elements);+ },});}- protected _initializeData() {- const workbook = this._plugin.getWorkbook();+ protected _refreshSheetData(): void {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();const sheets = workbook.getSheets();this._menuList = sheets.map((sheet, index) => ({label: sheet.getName(),@@ -95,29 +80,33 @@ export class SheetBarUIController {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;+ 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();- },- }));+ sheet.activate();+ },+ }));this._sheetIndex = sheets.findIndex((sheet) => sheet.getStatus() === 1);this._dataId = sheets[this._sheetIndex].getSheetId();}+ protected _refreshComponent(): void {+ this._sheetUl = this.resetSheetUl(this._sheetUl);+ this._refreshSheetData();+ this._refreshSheetBarUI();+ }+constructor(plugin: Plugin) {this._plugin = plugin;this._sheetUl = [@@ -190,39 +179,36 @@ export class SheetBarUIController {},},];- this._initializeObs();- this._initializeData();+ CommandManager.getActionObservers().add((event) => {+ const action = event.action as SheetActionBase<any>;+ const data = event.data;+ const workbook = action.getWorkBook();+ const unitId = workbook.getUnitId();+ const currentWorkbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const currentUnitId = currentWorkbook.getUnitId();+ if (unitId === currentUnitId) {+ switch (data.actionName) {+ case ACTION_NAMES.SET_SHEET_ORDER_ACTION:+ case ACTION_NAMES.INSERT_SHEET_ACTION:+ case ACTION_NAMES.SET_TAB_COLOR_ACTION:+ case ACTION_NAMES.REMOVE_SHEET_ACTION:+ case ACTION_NAMES.SET_WORKSHEET_NAME_ACTION:+ case ACTION_NAMES.SET_WORKSHEET_ACTIVATE_ACTION:+ case ACTION_NAMES.SET_WORKSHEET_STATUS_ACTION: {+ // update data;+ this._refreshSheetData();+ // set ui bar sheetList;+ this._refreshSheetBarUI();+ break;+ }+ }+ }+ });}getComponent = (ref: SheetBar) => {this._sheetBar = ref;- this._sheetUl = this.resetSheetUl(this._sheetUl);- this._sheetBar.setValue({- sheetList: this._sheetList,- sheetUl: this._sheetUl,- menuList: this._menuList,- addSheet: () => {- // this._barControl.addSheet();- },- selectSheet: (event: Event, data: { item: SheetUlProps }) => {- this._dataId = data.item.sheetId;- const sheet = this._plugin.getContext().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: (e: Event) => {- //this._barControl.changeSheetName(e);- },- dragEnd: (elements: HTMLDivElement[]) => {- //this._barControl.dragEnd(elements);- },- });+ this._refreshComponent();};resetLabel(label: string[] | string) {diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex c40c1f69ea..9bcb34ad9f 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -81,10 +81,10 @@ export class SheetContainerUIController {// getComponent: this._countBarController.getComponent,},sheetBar: {- // getComponent: this._sheetBarController.getComponent,- // addSheet: this._sheetBarController.addSheet,- // selectSheet: this._sheetBarController.selectSheet,- // changeSheetName: this._sheetBarController.changeSheetName,+ getComponent: this._sheetBarController.getComponent,+ addSheet: this._sheetBarController.addSheet,+ selectSheet: this._sheetBarController.selectSheet,+ changeSheetName: this._sheetBarController.changeSheetName,},},};diff --git a/packages/ui-plugin-sheets/src/Locale/en.ts b/packages/ui-plugin-sheets/src/Locale/en.tsindex 796ed2d38d..a03b77ee0b 100644--- a/packages/ui-plugin-sheets/src/Locale/en.ts+++ b/packages/ui-plugin-sheets/src/Locale/en.ts@@ -5,4 +5,4 @@ export default {two: 'two',three: 'three',},-};+};\ No newline at end of filediff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsxindex 916b9144c6..cb2a6f6aaf 100644--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx@@ -1,12 +1,8 @@+import { AppContext, AppContextValues, BaseComponentPlugin, BaseComponentRender, BaseComponentSheet, BaseMenuItem, BaseSheetBarProps, Button, Component, createRef, Icon, Menu, PreactContext, RefObject } from '@univerjs/base-ui';+import { SheetBarMenu } from './SheetBarMenu';import { Nullable, Observer, PLUGIN_NAMES, Workbook } from '@univerjs/core';-import { Menu } from '@univerjs/style-univer';-import { BaseComponentPlugin } from '../..';-import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';-import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';-import { BaseMenuItem, BaseSheetBarProps } from '../../Components';-import { Component, createRef, RefObject } from '../../Framework';import styles from './index.module.less';-import { SheetBarMenu } from './SheetBarMenu';+import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';type SheetState = {sheetList: BaseSheetBarProps[];@@ -29,16 +25,11 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {slideTabBar: SlideTabBar;- private _render: BaseComponentRender;-private _localeObserver: Nullable<Observer<Workbook>>;private _renderKey: number = 1;initialize(props: BaseSheetBarProps) {- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;- this._render = component.getComponentRender();-this.state = {sheetList: [],sheetUl: [],@@ -47,7 +38,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {}resetLabel(list: any) {- const componentManager = this._context.getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getComponentManager();+ const componentManager = this.getContext().getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getComponentManager();for (let i = 0; i < list.length; i++) {const item = list[i];@@ -203,21 +194,16 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {if (!sheetList.length) return;- const Button = this._render.renderFunction('Button');- const AddIcon = this._render.renderFunction('AddIcon');- const MenuIcon = this._render.renderFunction('MenuIcon');- const NextIcon = this._render.renderFunction('NextIcon');- const Menu = this._render.renderFunction('Menu');-+ debugger;return (<div className={styles.sheetBar} ref={this.slideTabRoot}>{/* user options button */}<div className={styles.sheetBarOptions}><Button className={styles.sheetBarOptionsButton} onClick={addSheet} type="text">- <AddIcon style={{ fontSize: '20px' }} />+ <Icon.Math.AddIcon style={{ fontSize: '20px' }} /></Button><Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.ref.current.showMenu(true)} type="text">- <MenuIcon style={{ fontSize: '20px' }} />+ <Icon.MenuIcon style={{ fontSize: '20px' }} /><SheetBarMenu onClick={selectSheet} menu={menuList} ref={this.ref}></SheetBarMenu></Button></div>@@ -239,7 +225,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {<span style={{ padding: '2px 5px 2px 5px' }}>{item.label}</span></div><div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.contextMenu}>- <NextIcon />+ <Icon.NextIcon /></div></div><div className={`${styles.slideTabFooter}`}>@@ -255,10 +241,10 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {{/* prev next scroll button */}<div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}><Button type="text" className={styles.sheetBarOptionsButton} onClick={this.scrollLeft}>- <NextIcon rotate={90} style={{ padding: '5px' }} />+ <Icon.NextIcon rotate={90} style={{ padding: '5px' }} /></Button><Button type="text" className={styles.sheetBarOptionsButton} onClick={this.scrollRight}>- <NextIcon rotate={-90} style={{ padding: '5px' }} />+ <Icon.NextIcon rotate={-90} style={{ padding: '5px' }} /></Button></div></div>diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsxindex 0245150d9b..e5d60ba0d1 100644--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx@@ -1,5 +1,4 @@-import { BaseComponentRender, BaseComponentSheet, Component } from '@univerjs/base-ui';-import { joinClassNames } from '../../Utils';+import { Component, Icon, joinClassNames } from '@univerjs/base-ui';import styles from './index.module.less';interface SheetBarMenuItem {@@ -22,12 +21,7 @@ interface IState {}export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {- private _render: BaseComponentRender;-initialize() {- const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;- this._render = component.getComponentRender();-this.state = {show: false,};@@ -49,9 +43,7 @@ export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {showMenu(show: boolean) {this.setState(- {- show,- },+ {show},() => {if (show) {window.addEventListener('click', this.hideMenu, true);@@ -63,16 +55,14 @@ export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {render() {const { menu, style } = this.props;const { show } = this.state;- const CheckIcon = this._render.renderFunction('CheckIcon');- const HideIcon = this._render.renderFunction('HideIcon');-+return (<ul className={styles.sheetBarMenu} style={{ ...style, display: show ? 'block' : ' none' }}>{menu.map((item) => (<li onClick={(e) => this.handleClick(e, item)} className={joinClassNames(styles.sheetBarMenuItem, item.hide ? styles.sheetBarMenuItemHide : '')}><span className={styles.sheetBarMenuIcon}>- {item.hide ? <HideIcon /> : ''}- {item.selected ? <CheckIcon /> : ''}+ {item.hide ? <Icon.HideIcon /> : ''}+ {item.selected ? <Icon.Data.CheckIcon /> : ''}</span>{item.label}</li>diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsxindex ade567c65d..45f6e2d02a 100644--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx@@ -197,7 +197,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps, IState> {display: config.footer ? 'block' : 'none',}}>- {/* {config.sheetBar && <SheetBar {...methods.sheetBar}></SheetBar>} */}+ {config.sheetBar && <SheetBar {...methods.sheetBar}></SheetBar>}{/* {config.countBar && <CountBar {...methods.countBar}></CountBar>} */}</Footer></Layout>