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
fix(ui): refactor toolbar, context menu, sheetbar command for upper plugins (#108)
Dushusir59c3a7dd47e2
diff --git a/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts b/packages/base-sheets/src/Basics/SlideTabBar/Animate.tsdeleted file mode 100644index 249051a9f1..0000000000--- a/packages/base-sheets/src/Basics/SlideTabBar/Animate.ts+++ /dev/null@@ -1,148 +0,0 @@-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 {- 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) => {- 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();- }- };- }- });- }-- 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);- }-- 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();- });- }-}diff --git a/packages/base-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts b/packages/base-sheets/src/Basics/SlideTabBar/SlideScrollbar.tsdeleted file mode 100644index 7be0373502..0000000000--- a/packages/base-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts+++ /dev/null@@ -1,29 +0,0 @@-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/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.tsdeleted file mode 100644index 13b039bde8..0000000000--- a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabBar.ts+++ /dev/null@@ -1,411 +0,0 @@-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 {- protected _activeTabItemIndex: number | null;-- protected _slideTabBar: HTMLElement;-- protected _slideTabItems: SlideTabItem[];-- protected _config: SlideTabBarConfig;-- protected _downActionX: number;-- protected _moveActionX: number;-- protected _compareIndex: number | null;-- protected _activeTabItem: SlideTabItem | null;-- protected _moveAction: (e: MouseEvent) => void;-- protected _upAction: (e: MouseEvent) => void;-- protected _downAction: (e: MouseEvent) => void;-- protected _wheelAction: (e: WheelEvent) => void;-- protected _scrollIncremental: number;-- protected _compareDirection: number;-- protected _autoScrollTime: number | null;-- protected _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();- }- });- }-- 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);- });- }-- protected _hasEditItem(): boolean {- for (let index = 0; index < this._slideTabItems.length; index++) {- const element = this._slideTabItems[index];- if (element.isEditMode()) {- return true;- }- }- return false;- }-- protected _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();- });- }-- protected _startAutoScroll(): void {- if (this._autoScrollTime == null) {- this._autoScrollFrame();- }- }-- protected _closeAutoScroll(): void {- if (this._autoScrollTime) {- cancelAnimationFrame(this._autoScrollTime);- }- this._autoScrollTime = null;- }-- protected _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);- }- }-- protected _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);- }- }-- protected _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);- }- }- }- }- }-- protected _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;- }- }- }- }- }-- protected _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;- }- }- }- }- }-- protected _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);- });- }-}diff --git a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.tsdeleted file mode 100644index 3284c38c1d..0000000000--- a/packages/base-sheets/src/Basics/SlideTabBar/SlideTabItem.ts+++ /dev/null@@ -1,223 +0,0 @@-import { SlideTabBar } from './SlideTabBar';-import { Animate } from './Animate';-import { SlideScrollbar } from './SlideScrollbar';--export interface SlideTabItemAnimate {- translateX: (x: number) => void;- cancel: () => void;-}--export class SlideTabItem {- protected _slideTabItem: HTMLElement;-- protected _animate: Animate | null;-- protected _midline: number;-- protected _translateX: number;-- protected _scrollbar: SlideScrollbar;-- protected _slideTabBar: SlideTabBar;-- protected _editMode: boolean;-- protected _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();- }-- 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;- }-- 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/base-sheets/src/Commands/Commands/add-worksheet-merge.command.ts b/packages/base-sheets/src/Commands/Commands/add-worksheet-merge.command.tsindex 286a627248..e708874f69 100644--- a/packages/base-sheets/src/Commands/Commands/add-worksheet-merge.command.ts+++ b/packages/base-sheets/src/Commands/Commands/add-worksheet-merge.command.ts@@ -78,13 +78,13 @@ export const AddWorksheetMergeCommand: ICommand = {URI: 'sheet',undo() {return (commandService.executeCommand(RemoveWorksheetMergeMutation.id, undoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);return false;});},redo() {return (commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.tsindex 64b046ae9c..881ab514c6 100644--- a/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts+++ b/packages/base-sheets/src/Commands/Commands/clear-selection-content.command.ts@@ -2,6 +2,7 @@ import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedimport { IAccessor } from '@wendellhu/redi';import { ISelectionManager } from '../../Services/tokens';+import { ISetRangeStyleMutationParams, SetRangeStyleMutation, SetRangeStyleUndoMutationFactory } from '../Mutations/set-range-styles.mutation';import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';/**@@ -23,6 +24,15 @@ export const ClearSelectionContentCommand: ICommand = {return false;}+ const cleanStyleMutationParams: ISetRangeStyleMutationParams = {+ range: selections,+ worksheetId: worksheet.getSheetId(),+ workbookId: workbook.getUnitId(),+ };+ const setStyleMutationParams: ISetRangeStyleMutationParams = SetRangeStyleUndoMutationFactory(accessor, cleanStyleMutationParams);++ const cleanResult = commandService.executeCommand(SetRangeStyleMutation.id, cleanStyleMutationParams);+const clearMutationParams: ISetRangeValuesMutationParams = {rangeData: selections,worksheetId: worksheet.getSheetId(),@@ -30,13 +40,17 @@ export const ClearSelectionContentCommand: ICommand = {const undoClearMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, clearMutationParams);const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);- if (result) {++ if (result && cleanResult) {undoRedoService.pushUndoRedo({// 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面// 通过勾子可以 hook 外部 controller 的代码来增加新的 actionURI: 'sheet', // TODO: this URI is fakeundo() {- return commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams);+ return (commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetRangeStyleMutation.id, setStyleMutationParams);+ return false;+ });},redo() {return commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);diff --git a/packages/base-sheets/src/Commands/Commands/copy-worksheet.command.ts b/packages/base-sheets/src/Commands/Commands/copy-worksheet.command.tsindex 99bcf9e885..9758bf5d3e 100644--- a/packages/base-sheets/src/Commands/Commands/copy-worksheet.command.ts+++ b/packages/base-sheets/src/Commands/Commands/copy-worksheet.command.ts@@ -56,14 +56,14 @@ export const CopySheetCommand: ICommand = {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return (commandService.executeCommand(RemoveSheetMutation.id, removeSheetMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetActivateMutation.id, undoMutationParams);+ return (commandService.executeCommand(SetWorksheetActivateMutation.id, undoMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(RemoveSheetMutation.id, removeSheetMutationParams);return false;});},redo() {- return (commandService.executeCommand(InsertSheetMutation.id, insertSheetMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetActivateMutation.id, setSheetActiveMutationParams);+ return (commandService.executeCommand(SetWorksheetActivateMutation.id, setSheetActiveMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(InsertSheetMutation.id, insertSheetMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/delete-range-move-left.command.ts b/packages/base-sheets/src/Commands/Commands/delete-range-move-left.command.tsindex c928f871c0..9d7409b000 100644--- a/packages/base-sheets/src/Commands/Commands/delete-range-move-left.command.ts+++ b/packages/base-sheets/src/Commands/Commands/delete-range-move-left.command.ts@@ -1,10 +1,10 @@-import { IAccessor } from '@wendellhu/redi';import { CommandType, Dimension, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService, Nullable } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';-import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutations/delete-range.mutation';-import { InsertRangeMutation } from '../Mutations/insert-range.mutation';import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';import { ISelectionManager } from '../../Services/tokens';+import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutations/delete-range.mutation';+import { InsertRangeMutation } from '../Mutations/insert-range.mutation';/*** The command to delete range.diff --git a/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts b/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.tsindex ee551da3f4..89a2225a9b 100644--- a/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts+++ b/packages/base-sheets/src/Commands/Commands/delete-range-move-up.command.ts@@ -1,10 +1,10 @@-import { IAccessor } from '@wendellhu/redi';import { CommandType, Dimension, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService, Nullable } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';-import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutations/delete-range.mutation';-import { InsertRangeMutation } from '../Mutations/insert-range.mutation';import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';import { ISelectionManager } from '../../Services/tokens';+import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutations/delete-range.mutation';+import { InsertRangeMutation } from '../Mutations/insert-range.mutation';/*** The command to delete range.diff --git a/packages/base-sheets/src/Commands/Commands/insert-range-move-down.command.ts b/packages/base-sheets/src/Commands/Commands/insert-range-move-down.command.tsindex b6040adfe0..d443865503 100644--- a/packages/base-sheets/src/Commands/Commands/insert-range-move-down.command.ts+++ b/packages/base-sheets/src/Commands/Commands/insert-range-move-down.command.ts@@ -1,10 +1,10 @@-import { IAccessor } from '@wendellhu/redi';import { CommandType, Dimension, ICellData, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService, ObjectMatrix } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';-import { DeleteRangeMutation } from '../Mutations/delete-range.mutation';-import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../Mutations/insert-range.mutation';import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';import { ISelectionManager } from '../../Services/tokens';+import { DeleteRangeMutation } from '../Mutations/delete-range.mutation';+import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../Mutations/insert-range.mutation';/*** The command to insert range.diff --git a/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.tsindex 78aec3e981..b76a53c991 100644--- a/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts+++ b/packages/base-sheets/src/Commands/Commands/insert-row-col.command.ts@@ -1,20 +1,32 @@-import { CommandType, ICommand, ICommandService, ICurrentUniverService, IRangeData, IUndoRedoService } from '@univerjs/core';+import { CommandType, Dimension, ICellData, ICommand, ICommandService, ICurrentUniverService, IRangeData, IUndoRedoService, Nullable, ObjectMatrix, Tools } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { IInsertColMutationParams, IInsertRowMutationParams, IRemoveColMutationParams, IRemoveRowMutationParams } from '../../Basics/Interfaces/MutationInterface';+import {+ IAddWorksheetMergeMutationParams,+ IDeleteRangeMutationParams,+ IInsertColMutationParams,+ IInsertRangeMutationParams,+ IInsertRowMutationParams,+ IRemoveColMutationParams,+ IRemoveRowMutationParams,+ IRemoveWorksheetMergeMutationParams,+} from '../../Basics/Interfaces/MutationInterface';import { ISelectionManager } from '../../Services/tokens';+import { AddWorksheetMergeMutation, AddWorksheetMergeMutationFactory } from '../Mutations/add-worksheet-merge.mutation';+import { DeleteRangeMutation } from '../Mutations/delete-range.mutation';+import { InsertRangeMutation, InsertRangeUndoMutationFactory } from '../Mutations/insert-range.mutation';import { InsertColMutation, InsertColMutationFactory, InsertRowMutation, InsertRowMutationFactory } from '../Mutations/insert-row-col.mutation';import { RemoveColMutation, RemoveRowMutation } from '../Mutations/remove-row-col.mutation';+import { RemoveWorksheetMergeMutation, RemoveWorksheetMergeMutationFactory } from '../Mutations/remove-worksheet-merge.mutation';export interface InsertRowCommandParams {- rowCount: number;+ value: number;}export interface InsertRowCommandBaseParams {workbookId: string;worksheetId: string;- rowCount: number;- rowIndex: number;+ range: IRangeData;}export const InsertRowCommand: ICommand = {@@ -33,29 +45,98 @@ export const InsertRowCommand: ICommand = {const redoMutationParams: IInsertRowMutationParams = {workbookId: params.workbookId,worksheetId: params.worksheetId,- ranges: [- {- startRow: params.rowIndex,- endRow: params.rowIndex + params.rowCount - 1,- startColumn: 0,- endColumn: 0,- },- ],+ ranges: [params.range],};const undoMutationParams: IRemoveRowMutationParams = InsertRowMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(InsertRowMutation.id, redoMutationParams);- if (result) {++ const { startRow, endRow, startColumn, endColumn } = params.range;+ const cellValue = new ObjectMatrix<ICellData>();+ for (let i = startRow; i <= endRow; i++) {+ for (let j = startColumn; j <= endColumn; j++) {+ cellValue.setValue(i, j, { v: '', m: '' });+ }+ }++ const insertRangeMutationParams: IInsertRangeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ range: [params.range],+ shiftDimension: Dimension.ROWS,+ cellValue: cellValue.getData(),+ };++ const deleteRangeMutationParams: Nullable<IDeleteRangeMutationParams> = InsertRangeUndoMutationFactory(accessor, insertRangeMutationParams);+ if (!deleteRangeMutationParams) return false;+ const deleteResult = commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);++ const mergeData = Tools.deepClone(worksheet.getConfig().mergeData);+ for (let i = 0; i < mergeData.length; i++) {+ const merge = mergeData[i];+ const count = endRow - startRow + 1;+ if (startRow > merge.endRow) {+ continue;+ } else if (endRow < merge.startRow) {+ merge.startRow += count;+ merge.endRow += count;+ } else {+ merge.endRow += count;+ }+ }++ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ ranges: Tools.deepClone(worksheet.getConfig().mergeData),+ };+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveWorksheetMergeMutationFactory(accessor, removeMergeMutationParams);+ const removeResult = commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);++ const addMergeMutationParams: IAddWorksheetMergeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ ranges: mergeData,+ };+ const deleteMergeMutationParams: IRemoveWorksheetMergeMutationParams = AddWorksheetMergeMutationFactory(accessor, addMergeMutationParams);+ const mergeResult = commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);++ if (result && deleteResult && removeResult && mergeResult) {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return commandService.executeCommand(RemoveRowMutation.id, undoMutationParams);+ return (commandService.executeCommand(DeleteRangeMutation.id, deleteRangeMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveRowMutation.id, undoMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, deleteMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);+ return fase;+ });},redo() {- return commandService.executeCommand(InsertRowMutation.id, redoMutationParams);+ return (commandService.executeCommand(InsertRowMutation.id, redoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);+ return false;+ });},});return true;}+return false;},};@@ -85,14 +166,18 @@ export const InsertRowBeforeCommand: ICommand<InsertRowCommandParams> = {let count = range.endRow - range.startRow + 1;if (params) {- count = params.rowCount;+ count = params.value ?? 1;}const insertRowParams: InsertRowCommandBaseParams = {workbookId,worksheetId,- rowCount: count,- rowIndex: range.startRow,+ range: {+ startRow: range.startRow,+ endRow: range.startRow + count - 1,+ startColumn: 0,+ endColumn: worksheet.getLastColumn(),+ },};return commandService.executeCommand(InsertRowCommand.id, insertRowParams);@@ -124,14 +209,18 @@ export const InsertRowAfterCommand: ICommand<InsertRowCommandParams> = {let count = range.endRow - range.startRow + 1;if (params) {- count = params.rowCount;+ count = params.value ?? 1;}const insertRowParams: InsertRowCommandBaseParams = {workbookId,worksheetId,- rowCount: count,- rowIndex: range.endRow + 1,+ range: {+ startRow: range.endRow + 1,+ endRow: range.endRow + count,+ startColumn: 0,+ endColumn: worksheet.getLastColumn(),+ },};return commandService.executeCommand(InsertRowCommand.id, insertRowParams);@@ -139,14 +228,13 @@ export const InsertRowAfterCommand: ICommand<InsertRowCommandParams> = {};export interface InsertColCommandParams {- colCount: number;+ value: number;}export interface InsertColCommandBaseParams {- colIndex: number;- colCount: number;workbookId: string;worksheetId: string;+ range: IRangeData;}export const InsertColCommand: ICommand<InsertColCommandBaseParams> = {@@ -165,25 +253,93 @@ export const InsertColCommand: ICommand<InsertColCommandBaseParams> = {const redoMutationParams: IInsertColMutationParams = {workbookId: params.workbookId,worksheetId: params.worksheetId,- ranges: [- {- startRow: 0,- endRow: 0,- startColumn: params.colIndex,- endColumn: params.colIndex + params.colCount - 1,- },- ],+ ranges: [params.range],};const undoMutationParams: IRemoveColMutationParams = InsertColMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(InsertColMutation.id, redoMutationParams);- if (result) {++ const { startRow, endRow, startColumn, endColumn } = params.range;+ const cellValue = new ObjectMatrix<ICellData>();+ for (let i = startRow; i <= endRow; i++) {+ for (let j = startColumn; j <= endColumn; j++) {+ cellValue.setValue(i, j, { v: '', m: '' });+ }+ }++ const insertRangeMutationParams: IInsertRangeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ range: [params.range],+ shiftDimension: Dimension.COLUMNS,+ cellValue: cellValue.getData(),+ };++ const deleteRangeMutationParams: Nullable<IDeleteRangeMutationParams> = InsertRangeUndoMutationFactory(accessor, insertRangeMutationParams);+ if (!deleteRangeMutationParams) return false;+ const deleteResult = commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);++ const mergeData = Tools.deepClone(worksheet.getConfig().mergeData);+ for (let i = 0; i < mergeData.length; i++) {+ const merge = mergeData[i];+ const count = endColumn - startColumn + 1;+ if (startColumn > merge.endColumn) {+ continue;+ } else if (endColumn < merge.startColumn) {+ merge.startColumn += count;+ merge.endColumn += count;+ } else {+ merge.endColumn += count;+ }+ }++ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ ranges: Tools.deepClone(worksheet.getConfig().mergeData),+ };+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveWorksheetMergeMutationFactory(accessor, removeMergeMutationParams);+ const removeResult = commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);++ const addMergeMutationParams: IAddWorksheetMergeMutationParams = {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ ranges: mergeData,+ };+ const deleteMergeMutationParams: IRemoveWorksheetMergeMutationParams = AddWorksheetMergeMutationFactory(accessor, addMergeMutationParams);+ const mergeResult = commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);++ if (result && deleteResult && removeResult && mergeResult) {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return commandService.executeCommand(RemoveColMutation.id, undoMutationParams);+ return (commandService.executeCommand(DeleteRangeMutation.id, deleteRangeMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveColMutation.id, undoMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, deleteMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);+ return fase;+ });},redo() {- return commandService.executeCommand(InsertColMutation.id, redoMutationParams);+ return (commandService.executeCommand(InsertColMutation.id, redoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);+ return false;+ });},});@@ -218,15 +374,20 @@ export const InsertColBeforeCommand: ICommand<InsertColCommandParams> = {let count = range.endColumn - range.startColumn + 1;if (params) {- count = params.colCount;+ count = params.value ?? 1;}const insertColParams: InsertColCommandBaseParams = {workbookId,worksheetId,- colCount: count,- colIndex: range.startColumn,+ range: {+ startColumn: range.startColumn,+ endColumn: range.startColumn + count - 1,+ startRow: 0,+ endRow: worksheet.getLastColumn(),+ },};+return commandService.executeCommand(InsertColCommand.id, insertColParams);},};@@ -256,15 +417,20 @@ export const InsertColAfterCommand: ICommand<InsertColCommandParams> = {let count = range.endColumn - range.startColumn + 1;if (params) {- count = params.colCount;+ count = params.value ?? 1;}const insertColParams: InsertColCommandBaseParams = {workbookId,worksheetId,- colCount: count,- colIndex: range.endColumn + 1,+ range: {+ startColumn: range.endColumn + 1,+ endColumn: range.endColumn + count,+ startRow: 0,+ endRow: worksheet.getLastColumn(),+ },};+return commandService.executeCommand(InsertColCommand.id, insertColParams);},};diff --git a/packages/base-sheets/src/Commands/Commands/insert-sheet.command.ts b/packages/base-sheets/src/Commands/Commands/insert-sheet.command.tsindex 229c3db780..8990bf9b89 100644--- a/packages/base-sheets/src/Commands/Commands/insert-sheet.command.ts+++ b/packages/base-sheets/src/Commands/Commands/insert-sheet.command.ts@@ -4,6 +4,7 @@ import { IAccessor } from '@wendellhu/redi';import { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../Basics/Interfaces/MutationInterface';import { InsertSheetMutation, InsertSheetUndoMutationFactory } from '../Mutations/insert-sheet.mutation';import { RemoveSheetMutation } from '../Mutations/remove-sheet.mutation';+import { ISetWorksheetActivateMutationParams, SetWorksheetActivateMutation, SetWorksheetUnActivateMutationFactory } from '../Mutations/set-worksheet-activate.mutation';export interface InsertSheetCommandParams {workbookId?: string;@@ -32,38 +33,51 @@ export const InsertSheetCommand: ICommand = {if (!workbook) return false;let index = workbook.getSheets().length;- let config = Tools.deepClone(DEFAULT_WORKSHEET);+ let sheetConfig = Tools.deepClone(DEFAULT_WORKSHEET);if (params) {index = params.index ?? index;if (params.sheet) {- config = params.sheet;+ sheetConfig = params.sheet;} else {- config.id = Tools.generateRandomId();- config.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名+ sheetConfig.id = Tools.generateRandomId();+ sheetConfig.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名}} else {- config.id = Tools.generateRandomId();- config.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名+ sheetConfig.id = Tools.generateRandomId();+ sheetConfig.name = `工作表${++workbook.getSheets().length}`; // Todo: 表名}// prepare do mutationsconst insertSheetMutationParams: IInsertSheetMutationParams = {index,- sheet: config,+ sheet: sheetConfig,workbookId,};const removeSheetMutationParams: IRemoveSheetMutationParams = InsertSheetUndoMutationFactory(accessor, insertSheetMutationParams);-// execute do mutations and add undo mutations to undo stack if completedconst result = commandService.executeCommand(InsertSheetMutation.id, insertSheetMutationParams);- if (result) {++ const setSheetActiveMutationParams: ISetWorksheetActivateMutationParams = {+ workbookId,+ worksheetId: sheetConfig.id,+ };+ const undoMutationParams: ISetWorksheetActivateMutationParams = SetWorksheetUnActivateMutationFactory(accessor, setSheetActiveMutationParams);+ const activateResult = commandService.executeCommand(SetWorksheetActivateMutation.id, setSheetActiveMutationParams);++ if (result && activateResult) {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return commandService.executeCommand(RemoveSheetMutation.id, removeSheetMutationParams);+ return (commandService.executeCommand(SetWorksheetActivateMutation.id, undoMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(RemoveSheetMutation.id, removeSheetMutationParams);+ return false;+ });},redo() {- return commandService.executeCommand(InsertSheetMutation.id, insertSheetMutationParams);+ return (commandService.executeCommand(InsertSheetMutation.id, insertSheetMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetWorksheetActivateMutation.id, setSheetActiveMutationParams);+ return false;+ });},});diff --git a/packages/base-sheets/src/Commands/Commands/move-columns-to.command.ts b/packages/base-sheets/src/Commands/Commands/move-columns-to.command.tsindex 0e874895eb..e7f9e1cb40 100644--- a/packages/base-sheets/src/Commands/Commands/move-columns-to.command.ts+++ b/packages/base-sheets/src/Commands/Commands/move-columns-to.command.ts@@ -1,9 +1,10 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISelectionManager } from '../../Services/tokens';+import { IInsertColMutationParams, IRemoveColMutationParams } from '../../Basics/Interfaces/MutationInterface';-import { IRemoveColMutationFactory, RemoveColMutation } from '../Mutations/remove-row-col.mutation';+import { ISelectionManager } from '../../Services/tokens';import { InsertColMutation, InsertColMutationFactory } from '../Mutations/insert-row-col.mutation';+import { IRemoveColMutationFactory, RemoveColMutation } from '../Mutations/remove-row-col.mutation';export interface IMoveColumnsToCommandParams {destinationIndex: number;@@ -71,13 +72,13 @@ export const MoveColumnsToCommand: ICommand = {URI: 'sheet', // TODO: this URI is fakeundo() {return (commandService.executeCommand(InsertColMutation.id, undoRemoveColumnMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(RemoveColMutation.id, undoMutationParams);+ if (res) return commandService.executeCommand(RemoveColMutation.id, undoMutationParams);return false;});},redo() {return (commandService.executeCommand(RemoveColMutation.id, removeColumnMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(InsertColMutation.id, insertColMutationParams);+ if (res) return commandService.executeCommand(InsertColMutation.id, insertColMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/move-range-to.command.ts b/packages/base-sheets/src/Commands/Commands/move-range-to.command.tsindex 5709c8d147..9cc57924d1 100644--- a/packages/base-sheets/src/Commands/Commands/move-range-to.command.ts+++ b/packages/base-sheets/src/Commands/Commands/move-range-to.command.ts@@ -1,7 +1,8 @@import { CommandType, ICellData, ICommand, ICommandService, ICurrentUniverService, IRangeData, IUndoRedoService, ObjectMatrix } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';+import { ISelectionManager } from '../../Services/tokens';+import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';export interface IMoveRangeToCommandParams {destinationRange: IRangeData;@@ -66,13 +67,13 @@ export const MoveRangeToCommand: ICommand = {URI: 'sheet', // TODO: this URI is fakeundo() {return (commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, undoMutationParams);+ if (res) return commandService.executeCommand(SetRangeValuesMutation.id, undoMutationParams);return false;});},redo() {return (commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);+ if (res) return commandService.executeCommand(SetRangeValuesMutation.id, setRangeValuesMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/move-rows-to.command.ts b/packages/base-sheets/src/Commands/Commands/move-rows-to.command.tsindex 4a6dbc16e9..3b78c978bb 100644--- a/packages/base-sheets/src/Commands/Commands/move-rows-to.command.ts+++ b/packages/base-sheets/src/Commands/Commands/move-rows-to.command.ts@@ -1,9 +1,10 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISelectionManager } from '../../Services/tokens';+import { IInsertRowMutationParams, IRemoveRowMutationParams } from '../../Basics/Interfaces/MutationInterface';-import { IRemoveRowMutationFactory, RemoveRowMutation } from '../Mutations/remove-row-col.mutation';+import { ISelectionManager } from '../../Services/tokens';import { InsertRowMutation, InsertRowMutationFactory } from '../Mutations/insert-row-col.mutation';+import { IRemoveRowMutationFactory, RemoveRowMutation } from '../Mutations/remove-row-col.mutation';export interface IMoveRowsToCommandParams {destinationIndex: number;@@ -71,13 +72,13 @@ export const MoveRowsToCommand: ICommand = {URI: 'sheet', // TODO: this URI is fakeundo() {return (commandService.executeCommand(InsertRowMutation.id, undoRemoveRowMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(RemoveRowMutation.id, undoMutationParams);+ if (res) return commandService.executeCommand(RemoveRowMutation.id, undoMutationParams);return false;});},redo() {return (commandService.executeCommand(RemoveRowMutation.id, removeRowMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(InsertRowMutation.id, insertRowMutationParams);+ if (res) return commandService.executeCommand(InsertRowMutation.id, insertRowMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/remove-row-col.command.ts b/packages/base-sheets/src/Commands/Commands/remove-row-col.command.tsindex f2d70249a9..935cf64a39 100644--- a/packages/base-sheets/src/Commands/Commands/remove-row-col.command.ts+++ b/packages/base-sheets/src/Commands/Commands/remove-row-col.command.ts@@ -1,10 +1,23 @@-import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';+import { CommandType, Dimension, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService, Nullable, Rectangle, Tools } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { IInsertColMutationParams, IInsertRowMutationParams, IRemoveColMutationParams, IRemoveRowMutationParams } from '../../Basics/Interfaces/MutationInterface';++import {+ IAddWorksheetMergeMutationParams,+ IDeleteRangeMutationParams,+ IInsertColMutationParams,+ IInsertRangeMutationParams,+ IInsertRowMutationParams,+ IRemoveColMutationParams,+ IRemoveRowMutationParams,+ IRemoveWorksheetMergeMutationParams,+} from '../../Basics/Interfaces/MutationInterface';+import { ISelectionManager } from '../../Services/tokens';+import { AddWorksheetMergeMutation, AddWorksheetMergeMutationFactory } from '../Mutations/add-worksheet-merge.mutation';+import { DeleteRangeMutation, DeleteRangeUndoMutationFactory } from '../Mutations/delete-range.mutation';+import { InsertRangeMutation } from '../Mutations/insert-range.mutation';import { InsertColMutation, InsertRowMutation } from '../Mutations/insert-row-col.mutation';import { IRemoveColMutationFactory, IRemoveRowMutationFactory, RemoveColMutation, RemoveRowMutation } from '../Mutations/remove-row-col.mutation';-import { ISelectionManager } from '../../Services/tokens';-import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';+import { RemoveWorksheetMergeMutation, RemoveWorksheetMergeMutationFactory } from '../Mutations/remove-worksheet-merge.mutation';export const RemoveRowCommand: ICommand = {type: CommandType.COMMAND,@@ -24,6 +37,11 @@ export const RemoveRowCommand: ICommand = {const worksheet = workbook.getSheetBySheetId(worksheetId);if (!worksheet) return false;+ selections.forEach((item) => {+ item.startColumn = 0;+ item.endColumn = worksheet.getMaxColumns();+ });+const redoMutationParams: IRemoveRowMutationParams = {workbookId,worksheetId,@@ -33,29 +51,91 @@ export const RemoveRowCommand: ICommand = {const undoMutationParams: IInsertRowMutationParams = IRemoveRowMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(RemoveRowMutation.id, redoMutationParams);- const removeRangeValueMutationParams: ISetRangeValuesMutationParams = {+ const deleteRangeValueMutationParams: IDeleteRangeMutationParams = {workbookId,worksheetId,- rangeData: selections,+ range: selections,+ shiftDimension: Dimension.ROWS,};- const undoRemoveRangeValueMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, removeRangeValueMutationParams);- const removeResult = commandService.executeCommand(SetRangeValuesMutation.id, removeRangeValueMutationParams);+ const insertRangeMutationParams: Nullable<IInsertRangeMutationParams> = DeleteRangeUndoMutationFactory(accessor, deleteRangeValueMutationParams);+ if (!insertRangeMutationParams) return false;+ const deleteResult = commandService.executeCommand(DeleteRangeMutation.id, deleteRangeValueMutationParams);++ const mergeData = Tools.deepClone(worksheet.getConfig().mergeData);+ for (let i = 0; i < mergeData.length; i++) {+ const merge = mergeData[i];+ for (let j = 0; j < selections.length; j++) {+ const { startRow, endRow } = selections[j];+ const count = endRow - startRow + 1;+ if (endRow < merge.startRow) {+ merge.startRow -= count;+ } else if (startRow > merge.endRow) {+ continue;+ } else if (startRow < merge.startRow && endRow > merge.endRow) {+ mergeData.splice(i);+ i--;+ } else {+ const intersects = Rectangle.getIntersects(selections[j], merge)!;+ const interLength = intersects.endRow - intersects.startRow + 1;+ const length = merge.endRow - merge.startRow + 1;+ if (interLength === length) {+ mergeData.splice(i);+ i--;+ } else {+ merge.endRow -= intersects.endRow - intersects.startRow + 1;+ }+ }+ }+ }+ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {+ workbookId,+ worksheetId,+ ranges: Tools.deepClone(worksheet.getConfig().mergeData),+ };+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveWorksheetMergeMutationFactory(accessor, removeMergeMutationParams);+ const removeResult = commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);- if (result && removeResult) {+ const addMergeMutationParams: IAddWorksheetMergeMutationParams = {+ workbookId,+ worksheetId,+ ranges: mergeData,+ };+ const deleteMergeMutationParams: IRemoveWorksheetMergeMutationParams = AddWorksheetMergeMutationFactory(accessor, addMergeMutationParams);+ const mergeResult = commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);++ if (result && deleteResult && removeResult && mergeResult) {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return (commandService.executeCommand(InsertRowMutation.id, undoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, undoRemoveRangeValueMutationParams);- return false;- });+ return (commandService.executeCommand(InsertRowMutation.id, undoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, deleteMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);+ return fase;+ });},redo() {- return (commandService.executeCommand(RemoveRowMutation.id, redoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, removeRangeValueMutationParams);- return false;- });+ return (commandService.executeCommand(RemoveRowMutation.id, redoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(DeleteRangeMutation.id, deleteRangeValueMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);+ return false;+ });},});return true;@@ -82,6 +162,11 @@ export const RemoveColCommand: ICommand = {const worksheet = workbook.getSheetBySheetId(worksheetId);if (!worksheet) return false;+ selections.forEach((item) => {+ item.startRow = 0;+ item.endRow = worksheet.getMaxRows();+ });+const redoMutationParams: IRemoveColMutationParams = {workbookId,worksheetId,@@ -91,29 +176,91 @@ export const RemoveColCommand: ICommand = {const undoMutationParams: IInsertColMutationParams = IRemoveColMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(RemoveColMutation.id, redoMutationParams);- const removeRangeValueMutationParams: ISetRangeValuesMutationParams = {+ const deleteRangeValueMutationParams: IDeleteRangeMutationParams = {workbookId,worksheetId,- rangeData: selections,+ range: selections,+ shiftDimension: Dimension.COLUMNS,};+ const insertRangeMutationParams: Nullable<IInsertRangeMutationParams> = DeleteRangeUndoMutationFactory(accessor, deleteRangeValueMutationParams);+ if (!insertRangeMutationParams) return false;+ const deleteResult = commandService.executeCommand(DeleteRangeMutation.id, deleteRangeValueMutationParams);++ const mergeData = Tools.deepClone(worksheet.getConfig().mergeData);+ for (let i = 0; i < mergeData.length; i++) {+ const merge = mergeData[i];+ for (let j = 0; j < selections.length; j++) {+ const { startColumn, endColumn } = selections[j];+ const count = endColumn - startColumn + 1;+ if (endColumn < merge.startColumn) {+ merge.startColumn -= count;+ } else if (startColumn > merge.endColumn) {+ continue;+ } else if ((startColumn < merge.startColumn && endColumn > merge.endColumn) || (startColumn === merge.startColumn && endColumn === merge.endColumn)) {+ mergeData.splice(i);+ i--;+ } else {+ const intersects = Rectangle.getIntersects(selections[j], merge)!;+ const interLength = intersects.endColumn - intersects.startColumn + 1;+ const length = endColumn - startColumn + 1;+ if (interLength === length) {+ mergeData.splice(i);+ i--;+ } else {+ merge.endColumn -= intersects.endColumn - intersects.startColumn + 1;+ }+ }+ }+ }- const undoRemoveRangeValueMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, removeRangeValueMutationParams);- const removeResult = commandService.executeCommand(SetRangeValuesMutation.id, removeRangeValueMutationParams);+ const removeMergeMutationParams: IRemoveWorksheetMergeMutationParams = {+ workbookId,+ worksheetId,+ ranges: Tools.deepClone(worksheet.getConfig().mergeData),+ };+ const undoRemoveMergeMutationParams: IAddWorksheetMergeMutationParams = RemoveWorksheetMergeMutationFactory(accessor, removeMergeMutationParams);+ const removeResult = commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);++ const addMergeMutationParams: IAddWorksheetMergeMutationParams = {+ workbookId,+ worksheetId,+ ranges: mergeData,+ };+ const deleteMergeMutationParams: IRemoveWorksheetMergeMutationParams = AddWorksheetMergeMutationFactory(accessor, addMergeMutationParams);+ const mergeResult = commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);- if (result && removeResult) {+ if (result && deleteResult && removeResult && mergeResult) {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return (commandService.executeCommand(InsertColMutation.id, undoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, undoRemoveRangeValueMutationParams);- return false;- });+ return (commandService.executeCommand(InsertColMutation.id, undoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(InsertRangeMutation.id, insertRangeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, deleteMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, undoRemoveMergeMutationParams);+ return fase;+ });},redo() {- return (commandService.executeCommand(RemoveColMutation.id, redoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetRangeValuesMutation.id, removeRangeValueMutationParams);- return false;- });+ return (commandService.executeCommand(RemoveColMutation.id, redoMutationParams) as Promise<boolean>)+ .then((res) => {+ if (res) return commandService.executeCommand(DeleteRangeMutation.id, deleteRangeValueMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(RemoveWorksheetMergeMutation.id, removeMergeMutationParams);+ return false;+ })+ .then((res) => {+ if (res) return commandService.executeCommand(AddWorksheetMergeMutation.id, addMergeMutationParams);+ return false;+ });},});diff --git a/packages/base-sheets/src/Commands/Commands/remove-sheet.command.ts b/packages/base-sheets/src/Commands/Commands/remove-sheet.command.tsindex 05c7292ef0..5f8c6a1302 100644--- a/packages/base-sheets/src/Commands/Commands/remove-sheet.command.ts+++ b/packages/base-sheets/src/Commands/Commands/remove-sheet.command.ts@@ -5,7 +5,6 @@ import { IInsertSheetMutationParams, IRemoveSheetMutationParams } from '../../Baimport { InsertSheetMutation } from '../Mutations/insert-sheet.mutation';import { RemoveSheetMutation, RemoveSheetUndoMutationFactory } from '../Mutations/remove-sheet.mutation';import { ISetWorksheetActivateMutationParams, SetWorksheetActivateMutation, SetWorksheetUnActivateMutationFactory } from '../Mutations/set-worksheet-activate.mutation';-import { SetWorksheetHideMutation } from '../Mutations/set-worksheet-hide.mutation';export interface RemoveSheetCommandParams {workbookId?: string;@@ -43,7 +42,7 @@ export const RemoveSheetCommand: ICommand = {worksheetId: activateSheetId,};- const unActiveMutationParams = SetWorksheetUnActivateMutationFactory(accessor, activeSheetMutationParams);+ const activeMutationParams: ISetWorksheetActivateMutationParams = SetWorksheetUnActivateMutationFactory(accessor, activeSheetMutationParams);const activeResult = commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams);// prepare do mutations@@ -59,14 +58,14 @@ export const RemoveSheetCommand: ICommand = {undoRedoService.pushUndoRedo({URI: 'sheet',undo() {- return (commandService.executeCommand(SetWorksheetHideMutation.id, unActiveMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(InsertSheetMutation.id, InsertSheetMutationParams);+ return (commandService.executeCommand(InsertSheetMutation.id, InsertSheetMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetWorksheetActivateMutation.id, activeMutationParams);return false;});},redo() {return (commandService.executeCommand(RemoveSheetMutation.id, RemoveSheetMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams);+ if (res) return commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/remove-worksheet-merge.command.ts b/packages/base-sheets/src/Commands/Commands/remove-worksheet-merge.command.tsindex 15afa8143a..5c9b054ebd 100644--- a/packages/base-sheets/src/Commands/Commands/remove-worksheet-merge.command.ts+++ b/packages/base-sheets/src/Commands/Commands/remove-worksheet-merge.command.ts@@ -1,9 +1,10 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams } from '../../Basics/Interfaces/MutationInterface';+import { ISelectionManager } from '../../Services/tokens';import { AddWorksheetMergeMutation } from '../Mutations/add-worksheet-merge.mutation';import { RemoveWorksheetMergeMutation, RemoveWorksheetMergeMutationFactory } from '../Mutations/remove-worksheet-merge.mutation';-import { ISelectionManager } from '../../Services/tokens';export const RemoveWorksheetMergeCommand: ICommand = {type: CommandType.COMMAND,@@ -45,6 +46,6 @@ export const RemoveWorksheetMergeCommand: ICommand = {});return true;}- return true;+ return false;},};diff --git a/packages/base-sheets/src/Commands/Commands/set-border-command.ts b/packages/base-sheets/src/Commands/Commands/set-border-command.tsindex 88e66047d8..e58b286149 100644--- a/packages/base-sheets/src/Commands/Commands/set-border-command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-border-command.ts@@ -2,6 +2,7 @@ import {BorderStyleTypes,BorderType,CommandType,+ IBorderData,IBorderStyleData,ICommand,ICommandService,@@ -15,9 +16,9 @@ import {} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISetRangeValuesMutationParams, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from '../Mutations/set-range-values.mutation';import { BorderStyleManagerService } from '../../Services/border-style-manager.service';import { ISelectionManager } from '../../Services/tokens';+import { ISetBorderStylesMutationParams, SetBorderStylesMutation, SetBorderStylesUndoMutationFactory } from '../Mutations/set-border-styles.mutatio';function forEach(rangeData: IRangeData, action: (row: number, column: number) => void): void {const { startRow, startColumn, endRow, endColumn } = rangeData;@@ -53,10 +54,10 @@ export const SetBorderPositionCommand: ICommand<ISetBorderPositionCommandParams>workbookId: workbook.getUnitId(),worksheetId: workbook.getActiveSheet().getSheetId(),range: selections[0],- top: value === BorderType.TOP || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.HORIZONTAL,- left: value === BorderType.LEFT || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.VERTICAL,- bottom: value === BorderType.BOTTOM || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.HORIZONTAL,- right: value === BorderType.RIGHT || value === BorderType.ALL || value === BorderType.OUTSIDE || value === BorderType.VERTICAL,+ top: value === BorderType.TOP || value === BorderType.ALL || value === BorderType.OUTSIDE,+ left: value === BorderType.LEFT || value === BorderType.ALL || value === BorderType.OUTSIDE,+ bottom: value === BorderType.BOTTOM || value === BorderType.ALL || value === BorderType.OUTSIDE,+ right: value === BorderType.RIGHT || value === BorderType.ALL || value === BorderType.OUTSIDE,vertical: value === BorderType.VERTICAL || value === BorderType.ALL || value === BorderType.INSIDE,horizontal: value === BorderType.HORIZONTAL || value === BorderType.ALL || value === BorderType.INSIDE,style: borderInfo.style,@@ -109,6 +110,13 @@ export interface ISetBorderCommandParams {style?: BorderStyleTypes;}+function setStyleValue(matrix: ObjectMatrix<IStyleData>, row: number, column: number, defaultStyle: IBorderData) {+ const style = matrix.getValue(row, column);+ matrix.setValue(row, column, {+ bd: style?.bd ? Object.assign(style.bd, defaultStyle) : defaultStyle,+ });+}+/*** The command to clear content in current selected ranges.*/@@ -119,8 +127,16 @@ export const SetBorderCommand: ICommand<ISetBorderCommandParams> = {handler: async (accessor: IAccessor, params: ISetBorderCommandParams) => {const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);+ const currentUniverService = accessor.get(ICurrentUniverService);const { top, left, bottom, right, vertical, horizontal, color = 'black', style = BorderStyleTypes.DASH_DOT, workbookId, worksheetId, range } = params;++ const workbook = currentUniverService.getUniverSheetInstance(params.workbookId)?.getWorkBook();+ if (!workbook) return false;+ const worksheet = workbook.getSheetBySheetId(params.worksheetId);+ if (!worksheet) return false;+ const sheetMatrix = worksheet.getCellMatrix();const rangeData = range;+ const styles = Tools.deepClone(workbook.getStyles());// Cells in the surrounding range may need to clear the borderconst topRangeOut = {@@ -180,11 +196,7 @@ export const SetBorderCommand: ICommand<ISetBorderCommandParams> = {endColumn: rangeData.endColumn,};- const mtr = new ObjectMatrix<IStyleData>();- const mlr = new ObjectMatrix<IStyleData>();- const mbr = new ObjectMatrix<IStyleData>();- const mrr = new ObjectMatrix<IStyleData>();- const mcr = new ObjectMatrix<IStyleData>();+ const mr = new ObjectMatrix<IStyleData>();const border: IBorderStyleData = {s: style,@@ -193,189 +205,137 @@ export const SetBorderCommand: ICommand<ISetBorderCommandParams> = {},};- if (top === true || top === false) {- // Probably to the border, there are no surrounding cells+ if (top) {// Clear the bottom border of the top rangeforEach(topRangeOut, (row, column) => {- mtr.setValue(row, column, { bd: { b: null } });+ setStyleValue(mr, row, column, { b: null });});- // first rowforEach(topRange, (row, column) => {- // update- if (top === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (top === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: null },- });- mcr.setValue(row, column, style);- }+ setStyleValue(mr, row, column, {+ t: Tools.deepClone(border),+ });});}- if (bottom === true || bottom === false) {- // Probably to the border, there are no surrounding cells+ if (bottom) {// Clear the top border of the lower rangeforEach(bottomRangeOut, (row, column) => {- mbr.setValue(row, column, { bd: { t: null } });+ setStyleValue(mr, row, column, { t: null });});- // the last rowforEach(bottomRange, (row, column) => {- // update- if (bottom === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (bottom === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: null },- });- mcr.setValue(row, column, style);- }+ setStyleValue(mr, row, column, {+ b: Tools.deepClone(border),+ });});}- if (left === true || left === false) {- // Probably to the border, there are no surrounding cells+ if (left) {// Clear the right border of the left rangeforEach(leftRangeOut, (row, column) => {- mlr.setValue(row, column, { bd: { r: null } });+ setStyleValue(mr, row, column, { r: null });});- // first columnforEach(leftRange, (row, column) => {- // update- if (left === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (left === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: null },- });- mcr.setValue(row, column, style);- }+ setStyleValue(mr, row, column, {+ l: Tools.deepClone(border),+ });});}- if (right === true || right === false) {- // Probably to the border, there are no surrounding cells+ if (right) {// Clear the left border of the right rangeforEach(rightRangeOut, (row, column) => {- mrr.setValue(row, column, { bd: { l: null } });+ setStyleValue(mr, row, column, { l: null });});- // last columnforEach(rightRange, (row, column) => {- // update- if (right === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (right === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: null },- });- mcr.setValue(row, column, style);- }+ setStyleValue(mr, row, column, {+ r: Tools.deepClone(border),+ });});}-// inner vertical border- if (vertical === true || vertical === false) {- // current range+ if (vertical) {forEach(rangeData, (row, column) => {- // Set the right border except the last columnif (column !== rangeData.endColumn) {- // update- if (vertical === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (vertical === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { r: null },- });- mcr.setValue(row, column, style);- }- }-- // Except for the first column, clear the left border- if (column !== rangeData.startColumn) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { l: null },+ setStyleValue(mr, row, column, {+ r: Tools.deepClone(border),});- mcr.setValue(row, column, style);}});}// inner horizontal border- if (horizontal === true || horizontal === false) {- // current range+ if (horizontal) {forEach(rangeData, (row, column) => {- // Except for the last row, set the bottom borderif (row !== rangeData.endRow) {- // update- if (horizontal === true) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: Tools.deepClone(border) },- });- mcr.setValue(row, column, style);- }- // delete- else if (horizontal === false) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { b: null },- });- mcr.setValue(row, column, style);- }+ setStyleValue(mr, row, column, {+ b: Tools.deepClone(border),+ });}+ });+ }- // Except for the first row, clear the top border- if (row !== rangeData.startRow) {- const style = Tools.deepMerge(mcr.getValue(row, column) || {}, {- bd: { t: null },- });- mcr.setValue(row, column, style);+ if (!top && !bottom && !left && !right && !vertical && !horizontal) {+ forEach(topRangeOut, (row, column) => {+ setStyleValue(mr, row, column, { b: null });+ });+ forEach(topRange, (row, column) => {+ setStyleValue(mr, row, column, { t: null });+ });++ forEach(bottomRangeOut, (row, column) => {+ setStyleValue(mr, row, column, { t: null });+ });+ forEach(bottomRange, (row, column) => {+ setStyleValue(mr, row, column, { b: null });+ });++ forEach(leftRangeOut, (row, column) => {+ setStyleValue(mr, row, column, { r: null });+ });+ forEach(leftRange, (row, column) => {+ setStyleValue(mr, row, column, { l: null });+ });++ forEach(rightRangeOut, (row, column) => {+ setStyleValue(mr, row, column, { l: null });+ });+ forEach(rightRange, (row, column) => {+ setStyleValue(mr, row, column, { r: null });+ });++ forEach(rangeData, (row, column) => {+ if (column !== rangeData.endColumn) {+ setStyleValue(mr, row, column, { r: null });+ }+ });++ forEach(rangeData, (row, column) => {+ if (row !== rangeData.endRow) {+ setStyleValue(mr, row, column, { b: null });}});}- const clearMutationParams: ISetRangeValuesMutationParams = {- rangeData: range,- worksheetId,+ const setBorderStylesMutationParams: ISetBorderStylesMutationParams = {workbookId,+ worksheetId,+ value: mr.getData(),};- const undoClearMutationParams: ISetRangeValuesMutationParams = SetRangeValuesUndoMutationFactory(accessor, clearMutationParams);++ const undoSetBorderStylesMutationParams: ISetBorderStylesMutationParams = SetBorderStylesUndoMutationFactory(accessor, setBorderStylesMutationParams);// execute do mutations and add undo mutations to undo stack if completed- const result = commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);+ const result = commandService.executeCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);if (result) {undoRedoService.pushUndoRedo({// 如果有多个 mutation 构成一个封装项目,那么要封装在同一个 undo redo element 里面// 通过勾子可以 hook 外部 controller 的代码来增加新的 actionURI: 'sheet', // TODO: this URI is fakeundo() {- return commandService.executeCommand(SetRangeValuesMutation.id, undoClearMutationParams);+ return commandService.executeCommand(SetBorderStylesMutation.id, undoSetBorderStylesMutationParams);},redo() {- return commandService.executeCommand(SetRangeValuesMutation.id, clearMutationParams);+ return commandService.executeCommand(SetBorderStylesMutation.id, setBorderStylesMutationParams);},});diff --git a/packages/base-sheets/src/Commands/Commands/set-border-styles-command.ts b/packages/base-sheets/src/Commands/Commands/set-border-styles-command.tsindex 784ffb94e1..b8a058d9cd 100644--- a/packages/base-sheets/src/Commands/Commands/set-border-styles-command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-border-styles-command.ts@@ -1,5 +1,6 @@import {BorderStyleTypes,+ BorderType,CommandType,IBorderStyleData,ICommand,@@ -13,8 +14,10 @@ import {Tools,} from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISetBorderStylesMutationParams, SetBorderStylesMutation, SetBorderStylesUndoMutationFactory } from '../Mutations/set-border-styles.mutatio';++import { BorderStyleManagerService } from '../../Services/border-style-manager.service';import { ISelectionManager } from '../../Services/tokens';+import { ISetBorderStylesMutationParams, SetBorderStylesMutation, SetBorderStylesUndoMutationFactory } from '../Mutations/set-border-styles.mutatio';export interface ISetBorderCommandParams {workbookId?: string;@@ -42,8 +45,8 @@ function forEach(rangeData: IRangeData, action: (row: number, column: number) =>/*** The command to clear content in current selected ranges.*/-export const SetBorderStylesCommand: ICommand = {- id: 'sheet.command.set-border-styles',+export const SetBorderCommand: ICommand = {+ id: 'sheet.command.set-border',type: CommandType.COMMAND,// eslint-disable-next-line max-lines-per-functionhandler: async (accessor: IAccessor, params: ISetBorderCommandParams) => {@@ -329,3 +332,113 @@ export const SetBorderStylesCommand: ICommand = {return false;},};++interface ISetBorderType {+ type: BorderType;+}++export const SetBorderTypeCommand: ICommand = {+ id: 'sheet.command.set-border-types',+ type: CommandType.COMMAND,+ // eslint-disable-next-line max-lines-per-function+ handler: async (accessor: IAccessor, params?: ISetBorderType) => {+ const commandService = accessor.get(ICommandService);+ const borderService = accessor.get(BorderStyleManagerService);+ const type = params ? params.type : BorderType.ALL;+ borderService.setType(type);++ let top = null;+ let left = null;+ let bottom = null;+ let right = null;+ let vertical = null;+ let horizontal = null;++ switch (type) {+ case BorderType.TOP:+ top = true;+ break;+ case BorderType.BOTTOM:+ bottom = true;+ break;+ case BorderType.LEFT:+ left = true;+ break;+ case BorderType.RIGHT:+ right = true;+ break;+ case BorderType.NONE:+ top = false;+ left = false;+ bottom = false;+ right = false;+ vertical = false;+ horizontal = false;+ break;+ case BorderType.ALL:+ top = true;+ left = true;+ bottom = true;+ right = true;+ vertical = true;+ horizontal = true;+ break;+ case BorderType.OUTSIDE:+ top = true;+ left = true;+ bottom = true;+ right = true;+ break;+ case BorderType.INSIDE:+ vertical = true;+ horizontal = true;+ break;+ case BorderType.HORIZONTAL:+ horizontal = true;+ break;+ case BorderType.VERTICAL:+ vertical = true;+ break;++ default:+ break;+ }++ const { color, style } = borderService.getBorderInfo();+ const setBorderParams: ISetBorderCommandParams = { top, left, bottom, right, vertical, horizontal, color, style };++ return commandService.executeCommand(SetBorderCommand.id, setBorderParams);+ },+};++interface ISetBorderStyle {+ style: BorderStyleTypes;+}++export const SetBorderStyleCommand: ICommand = {+ id: 'sheet.command.set-border-styles',+ type: CommandType.COMMAND,+ // eslint-disable-next-line max-lines-per-function+ handler: async (accessor: IAccessor, params?: ISetBorderStyle) => {+ const borderService = accessor.get(BorderStyleManagerService);+ const style = params ? params.style : BorderStyleTypes.THIN;+ borderService.setStyle(style);+ return true;+ },+};++interface ISetBorderColor {+ color: string;+}++export const SetBorderColorCommand: ICommand = {+ id: 'sheet.command.set-border-color',+ type: CommandType.COMMAND,+ // eslint-disable-next-line max-lines-per-function+ handler: async (accessor: IAccessor, params?: ISetBorderColor) => {+ const borderService = accessor.get(BorderStyleManagerService);+ const color = params ? params.color : '#000';+ borderService.setColor(color);+ return true;+ },+};diff --git a/packages/base-sheets/src/Commands/Commands/set-frozen-cancel.command.ts b/packages/base-sheets/src/Commands/Commands/set-frozen-cancel.command.tsnew file mode 100644index 0000000000..6db786a701--- /dev/null+++ b/packages/base-sheets/src/Commands/Commands/set-frozen-cancel.command.ts@@ -0,0 +1,61 @@+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { ISetFrozenColumnsMutationParams, SetFrozenColumnsMutation, SetFrozenColumnsMutationFactory } from '../Mutations/set-frozen-columns.mutation';+import { ISetFrozenRowsMutationParams, SetFrozenRowsMutation, SetFrozenRowsMutationFactory } from '../Mutations/set-frozen-rows.mutation';++export const SetFrozenCancelCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.set-frozen-cancel',+ handler: async (accessor: IAccessor) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const currentUniverService = accessor.get(ICurrentUniverService);++ const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();+ const worksheetId = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();++ const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();+ if (!workbook) return false;+ const worksheet = workbook.getSheetBySheetId(worksheetId);+ if (!worksheet) return false;++ const cancelColumnMutationParams: ISetFrozenColumnsMutationParams = {+ workbookId,+ worksheetId,+ numColumns: -1,+ };++ const frozenColumnMutationParams: ISetFrozenColumnsMutationParams = SetFrozenColumnsMutationFactory(accessor, cancelColumnMutationParams);+ const frozenResult = commandService.executeCommand(SetFrozenColumnsMutation.id, cancelColumnMutationParams);++ const redoMutationParams: ISetFrozenRowsMutationParams = {+ workbookId,+ worksheetId,+ numRows: -1,+ };++ const undoMutationParams: ISetFrozenRowsMutationParams = SetFrozenRowsMutationFactory(accessor, redoMutationParams);+ const result = commandService.executeCommand(SetFrozenRowsMutation.id, redoMutationParams);++ if (result && frozenResult) {+ undoRedoService.pushUndoRedo({+ URI: 'sheet',+ undo() {+ return (commandService.executeCommand(SetFrozenColumnsMutation.id, frozenColumnMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetFrozenRowsMutation.id, undoMutationParams);+ return false;+ });+ },+ redo() {+ return (commandService.executeCommand(SetFrozenColumnsMutation.id, cancelColumnMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetFrozenRowsMutation.id, redoMutationParams);+ return false;+ });+ },+ });+ return true;+ }+ return false;+ },+};diff --git a/packages/base-sheets/src/Commands/Commands/set-frozen-columns.command.ts b/packages/base-sheets/src/Commands/Commands/set-frozen-columns.command.tsnew file mode 100644index 0000000000..45046cdf54--- /dev/null+++ b/packages/base-sheets/src/Commands/Commands/set-frozen-columns.command.ts@@ -0,0 +1,49 @@+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { ISetFrozenColumnsMutationParams, SetFrozenColumnsMutation, SetFrozenColumnsMutationFactory } from '../Mutations/set-frozen-columns.mutation';++interface ISetFrozenColumnsCommandParams {+ value: number;+}++export const SetFrozenColumnsCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.set-frozen-columns',+ handler: async (accessor: IAccessor, params: ISetFrozenColumnsCommandParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const currentUniverService = accessor.get(ICurrentUniverService);++ const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();+ const worksheetId = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();++ const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();+ if (!workbook) return false;+ const worksheet = workbook.getSheetBySheetId(worksheetId);+ if (!worksheet) return false;++ const redoMutationParams: ISetFrozenColumnsMutationParams = {+ workbookId,+ worksheetId,+ numColumns: params.value,+ };++ const undoMutationParams: ISetFrozenColumnsMutationParams = SetFrozenColumnsMutationFactory(accessor, redoMutationParams);+ const result = commandService.executeCommand(SetFrozenColumnsMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: 'sheet',+ undo() {+ return commandService.executeCommand(SetFrozenColumnsMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.executeCommand(SetFrozenColumnsMutation.id, redoMutationParams);+ },+ });+ return true;+ }+ return false;+ },+};diff --git a/packages/base-sheets/src/Commands/Commands/set-frozen-rows.command.ts b/packages/base-sheets/src/Commands/Commands/set-frozen-rows.command.tsnew file mode 100644index 0000000000..6554a225d2--- /dev/null+++ b/packages/base-sheets/src/Commands/Commands/set-frozen-rows.command.ts@@ -0,0 +1,49 @@+import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { ISetFrozenRowsMutationParams, SetFrozenRowsMutation, SetFrozenRowsMutationFactory } from '../Mutations/set-frozen-rows.mutation';++interface ISetFrozenRowsCommandParams {+ value: number;+}++export const SetFrozenRowsCommand: ICommand = {+ type: CommandType.COMMAND,+ id: 'sheet.command.set-frozen-rows',+ handler: async (accessor: IAccessor, params: ISetFrozenRowsCommandParams) => {+ const commandService = accessor.get(ICommandService);+ const undoRedoService = accessor.get(IUndoRedoService);+ const currentUniverService = accessor.get(ICurrentUniverService);++ const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();+ const worksheetId = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();++ const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();+ if (!workbook) return false;+ const worksheet = workbook.getSheetBySheetId(worksheetId);+ if (!worksheet) return false;++ const redoMutationParams: ISetFrozenRowsMutationParams = {+ workbookId,+ worksheetId,+ numRows: params.value,+ };++ const undoMutationParams: ISetFrozenRowsMutationParams = SetFrozenRowsMutationFactory(accessor, redoMutationParams);+ const result = commandService.executeCommand(SetFrozenRowsMutation.id, redoMutationParams);++ if (result) {+ undoRedoService.pushUndoRedo({+ URI: 'sheet',+ undo() {+ return commandService.executeCommand(SetFrozenRowsMutation.id, undoMutationParams);+ },+ redo() {+ return commandService.executeCommand(SetFrozenRowsMutation.id, redoMutationParams);+ },+ });+ return true;+ }+ return false;+ },+};diff --git a/packages/base-sheets/src/Commands/Commands/set-style.command.ts b/packages/base-sheets/src/Commands/Commands/set-style.command.tsindex a09b48af41..2fdcd37443 100644--- a/packages/base-sheets/src/Commands/Commands/set-style.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-style.command.ts@@ -1,4 +1,3 @@-import { IAccessor } from '@wendellhu/redi';import {BooleanNumber,CommandType,@@ -18,9 +17,10 @@ import {VerticalAlign,WrapStrategy,} from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';-import { ISetRangeStyleMutationParams, SetRangeStyleMutation, SetRangeStyleUndoMutationFactory } from '../Mutations/set-range-styles.mutation';import { ISelectionManager } from '../../Services/tokens';+import { ISetRangeStyleMutationParams, SetRangeStyleMutation, SetRangeStyleUndoMutationFactory } from '../Mutations/set-range-styles.mutation';export interface IStyleTypeValue<T> {type: keyof IStyleData;diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-activate.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-activate.command.tsindex 84a0d16866..244981fc39 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-activate.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-activate.command.ts@@ -31,18 +31,20 @@ export const SetWorksheetActivateCommand: ICommand = {};const undoMutationParams = SetWorksheetUnActivateMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(SetWorksheetActivateMutation.id, redoMutationParams);- if (result) {- undoRedoService.pushUndoRedo({- URI: 'sheet',- undo() {- return commandService.executeCommand(SetWorksheetActivateMutation.id, undoMutationParams);- },- redo() {- return commandService.executeCommand(SetWorksheetActivateMutation.id, redoMutationParams);- },- });- return true;- }++ // no need+ // if (result) {+ // undoRedoService.pushUndoRedo({+ // URI: 'sheet',+ // undo() {+ // return commandService.executeCommand(SetWorksheetActivateMutation.id, undoMutationParams);+ // },+ // redo() {+ // return commandService.executeCommand(SetWorksheetActivateMutation.id, redoMutationParams);+ // },+ // });+ // return true;+ // }return true;},};diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.tsindex c8c58c889a..96401a8be6 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-col-width.command.ts@@ -1,19 +1,21 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISetWorksheetColWidthMutationParams, SetWorksheetColWidthMutation, SetWorksheetColWidthMutationFactory } from '../Mutations/set-worksheet-col-width.mutation';+import { ISelectionManager } from '../../Services/tokens';+import { ISetWorksheetColWidthMutationParams, SetWorksheetColWidthMutation, SetWorksheetColWidthMutationFactory } from '../Mutations/set-worksheet-col-width.mutation';/*** TODO@Dushusir 支持多个选区*/export interface SetWorksheetColWidthCommandParams {- colWidth: number;+ value: number;}export const SetWorksheetColWidthCommand: ICommand = {type: CommandType.COMMAND,id: 'sheet.command.set-worksheet-col-width',handler: async (accessor: IAccessor, params: SetWorksheetColWidthCommandParams) => {+ console.info('sheet.command.set-worksheet-col-width', params);const selectionManager = accessor.get(ISelectionManager);const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);@@ -28,7 +30,7 @@ export const SetWorksheetColWidthCommand: ICommand = {worksheetId,workbookId,ranges: selections,- colWidth: params.colWidth,+ colWidth: params.value,};const undoMutationParams: ISetWorksheetColWidthMutationParams = SetWorksheetColWidthMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(SetWorksheetColWidthMutation.id, redoMutationParams);diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-hide.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-hide.command.tsindex ef4ed9028e..c250fdb299 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-hide.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-hide.command.ts@@ -57,13 +57,13 @@ export const SetWorksheetHideCommand: ICommand = {URI: 'sheet',undo() {return (commandService.executeCommand(SetWorksheetActivateMutation.id, unActiveMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetHideMutation.id, undoMutationParams);+ if (res) return commandService.executeCommand(SetWorksheetHideMutation.id, undoMutationParams);return false;});},redo() {- return (commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams);+ return (commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-name.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-name.command.tsindex 9d69d74691..638242e450 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-name.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-name.command.ts@@ -1,5 +1,6 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { ISetWorksheetNameMutationParams, SetWorksheetNameMutation, SetWorksheetNameMutationFactory } from '../Mutations/set-worksheet-name.mutation';export interface SetWorksheetNameCommandParams {diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.tsindex 80e1252835..486dee7435 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-row-height.command.ts@@ -1,35 +1,37 @@import { CommandType, ICommand, ICommandService, ICurrentUniverService, IUndoRedoService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { ISetWorksheetRowHeightMutationParams, SetWorksheetRowHeightMutation, SetWorksheetRowHeightMutationFactory } from '../Mutations/set-worksheet-row-height.mutation';+import { ISelectionManager } from '../../Services/tokens';+import { ISetWorksheetRowHeightMutationParams, SetWorksheetRowHeightMutation, SetWorksheetRowHeightMutationFactory } from '../Mutations/set-worksheet-row-height.mutation';/*** TODO@Dushusir 支持多个选区*/export interface SetWorksheetRowHeightCommandParams {- rowHeight: number;+ value: number;}export const SetWorksheetRowHeightCommand: ICommand = {type: CommandType.COMMAND,id: 'sheet.command.set-worksheet-row-height',handler: async (accessor: IAccessor, params: SetWorksheetRowHeightCommandParams) => {+ console.info('sheet.command.set-worksheet-row-height==========', params);const selectionManager = accessor.get(ISelectionManager);const commandService = accessor.get(ICommandService);const undoRedoService = accessor.get(IUndoRedoService);const currentUniverService = accessor.get(ICurrentUniverService);const selections = selectionManager.getCurrentSelections();+ console.info('current selections', selections);if (!selections.length) return false;const workbookId = currentUniverService.getCurrentUniverSheetInstance().getUnitId();const worksheetId = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet().getSheetId();-const redoMutationParams: ISetWorksheetRowHeightMutationParams = {worksheetId,workbookId,ranges: selections,- rowHeight: params.rowHeight,+ rowHeight: params.value,};const undoMutationParams: ISetWorksheetRowHeightMutationParams = SetWorksheetRowHeightMutationFactory(accessor, redoMutationParams);const result = commandService.executeCommand(SetWorksheetRowHeightMutation.id, redoMutationParams);diff --git a/packages/base-sheets/src/Commands/Commands/set-worksheet-show.command.ts b/packages/base-sheets/src/Commands/Commands/set-worksheet-show.command.tsindex c8fca997e3..5a2836ded2 100644--- a/packages/base-sheets/src/Commands/Commands/set-worksheet-show.command.ts+++ b/packages/base-sheets/src/Commands/Commands/set-worksheet-show.command.ts@@ -27,7 +27,6 @@ export const SetWorksheetShowCommand: ICommand = {const workbook = currentUniverService.getUniverSheetInstance(workbookId)?.getWorkBook();if (!workbook) return false;const worksheet = workbook.getSheetBySheetId(worksheetId);- if (!worksheet) return false;const hidden = worksheet.getConfig().hidden;if (hidden === BooleanNumber.FALSE) return false;@@ -54,13 +53,13 @@ export const SetWorksheetShowCommand: ICommand = {URI: 'sheet',undo() {return (commandService.executeCommand(SetWorksheetActivateMutation.id, unActiveMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetHideMutation.id, undoMutationParams);+ if (res) return commandService.executeCommand(SetWorksheetHideMutation.id, undoMutationParams);return false;});},redo() {- return (commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams) as Promise<boolean>).then((res) => {- if (res) commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams);+ return (commandService.executeCommand(SetWorksheetActivateMutation.id, activeSheetMutationParams) as Promise<boolean>).then((res) => {+ if (res) return commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams);return false;});},diff --git a/packages/base-sheets/src/Commands/Mutations/add-worksheet-merge.mutation.ts b/packages/base-sheets/src/Commands/Mutations/add-worksheet-merge.mutation.tsindex fe8c7b72e5..8713280a94 100644--- a/packages/base-sheets/src/Commands/Mutations/add-worksheet-merge.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/add-worksheet-merge.mutation.ts@@ -1,5 +1,6 @@import { CommandType, ICurrentUniverService, IMutation } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams } from '../../Basics/Interfaces/MutationInterface';export const AddWorksheetMergeMutationFactory = (accessor: IAccessor, params: IAddWorksheetMergeMutationParams): IRemoveWorksheetMergeMutationParams => {@@ -28,12 +29,15 @@ export const AddWorksheetMergeMutation: IMutation<IAddWorksheetMergeMutationParathrow new Error('universheet is null error!');}- const config = universheet.getWorkBook().getSheetBySheetId(params.worksheetId)?.getConfig()!;+ const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);+ if (!worksheet) return false;+ const config = worksheet.getConfig()!;const mergeConfigData = config.mergeData;const mergeAppendData = params.ranges;for (let i = 0; i < mergeAppendData.length; i++) {mergeConfigData.push(mergeAppendData[i]);}+return true;},};diff --git a/packages/base-sheets/src/Commands/Mutations/delete-range.mutation.ts b/packages/base-sheets/src/Commands/Mutations/delete-range.mutation.tsindex cb51550c24..eeb9ec7c81 100644--- a/packages/base-sheets/src/Commands/Mutations/delete-range.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/delete-range.mutation.ts@@ -1,6 +1,6 @@-import { CommandType, IMutation, ICurrentUniverService, ObjectMatrix, Tools, Nullable, ICellData, Dimension } from '@univerjs/core';-+import { CommandType, Dimension, ICellData, ICurrentUniverService, IMutation, Nullable, ObjectMatrix, Tools } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';/**diff --git a/packages/base-sheets/src/Commands/Mutations/insert-range.mutation.ts b/packages/base-sheets/src/Commands/Mutations/insert-range.mutation.tsindex 7af6f39703..b57769af8a 100644--- a/packages/base-sheets/src/Commands/Mutations/insert-range.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/insert-range.mutation.ts@@ -1,6 +1,6 @@-import { CommandType, IMutation, ICurrentUniverService, ICellData, Dimension } from '@univerjs/core';-+import { CommandType, Dimension, ICellData, ICurrentUniverService, IMutation } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IDeleteRangeMutationParams, IInsertRangeMutationParams } from '../../Basics/Interfaces/MutationInterface';/**@@ -41,14 +41,15 @@ export const InsertRangeMutation: IMutation<IInsertRangeMutationParams, boolean>for (let r = lastEndRow; r >= startRow; r--) {for (let c = startColumn; c <= endColumn; c++) {// get value blow current range+const value = cellMatrix.getValue(r, c);- cellMatrix.setValue(r + rows, c, value as ICellData);+ cellMatrix.setValue(r + rows, c, value || {});}}// insert cell value from userfor (let r = endRow; r >= startRow; r--) {for (let c = startColumn; c <= endColumn; c++) {- cellMatrix.setValue(r, c, params.cellValue[r - startRow][c - startColumn]);+ cellMatrix.setValue(r, c, params.cellValue[r][c]);}}} else if (params.shiftDimension === Dimension.COLUMNS) {@@ -68,7 +69,7 @@ export const InsertRangeMutation: IMutation<IInsertRangeMutationParams, boolean>// }for (let r = startRow; r <= endRow; r++) {for (let c = endColumn; c >= startColumn; c--) {- cellMatrix.setValue(r, c, params.cellValue[r - startRow][c - startColumn]);+ cellMatrix.setValue(r, c, params.cellValue[r][c]);}}}diff --git a/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts b/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.tsindex a51dcb4874..12eeb8136d 100644--- a/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/insert-row-col.mutation.ts@@ -1,5 +1,6 @@-import { CommandType, ICurrentUniverService, IMutation, ObjectArray, ObjectMatrix } from '@univerjs/core';+import { CommandType, ICurrentUniverService, IMutation, ObjectArray } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IInsertColMutationParams, IInsertRowMutationParams, IRemoveColMutationParams, IRemoveRowMutationParams } from '../../Basics/Interfaces/MutationInterface';export const InsertRowMutationFactory = (accessor: IAccessor, params: IInsertRowMutationParams): IRemoveRowMutationParams => {@@ -44,21 +45,17 @@ export const InsertRowMutation: IMutation<IInsertRowMutationParams> = {const rowIndex = range.startRow;const rowCount = range.endRow - range.startRow + 1;- if (params.rowInfo) {- for (let j = rowIndex; j < rowIndex + rowCount; j++) {- const defaultRowInfo = {- h: defaultRowHeight,- hd: 0,- };+ for (let j = rowIndex; j < rowIndex + rowCount; j++) {+ const defaultRowInfo = {+ h: defaultRowHeight,+ hd: 0,+ };+ if (params.rowInfo) {rowWrapper.insert(j, params.rowInfo.get(j) ?? defaultRowInfo);+ } else {+ rowWrapper.insert(j, defaultRowInfo);}- } else {- rowWrapper.inserts(rowIndex, new ObjectArray(rowCount));}-- const cellPrimitive = worksheet!.getCellMatrix().toJSON();- const cellWrapper = new ObjectMatrix(cellPrimitive);- cellWrapper.insertRowCount(rowIndex, rowCount);}return true;@@ -103,21 +100,17 @@ export const InsertColMutation: IMutation<IInsertColMutationParams> = {const colCount = range.endColumn - range.startColumn + 1;const defaultColWidth = worksheet.getConfig().defaultColumnWidth;- if (params.colInfo) {- for (let j = colIndex; j < colIndex + colCount; j++) {- const defaultColInfo = {- w: defaultColWidth,- hd: 0,- };+ for (let j = colIndex; j < colIndex + colCount; j++) {+ const defaultColInfo = {+ w: defaultColWidth,+ hd: 0,+ };+ if (params.colInfo) {columnWrapper.insert(j, params.colInfo.get(j) ?? defaultColInfo);+ } else {+ columnWrapper.insert(j, defaultColInfo);}- } else {- columnWrapper.inserts(colIndex, new ObjectArray(colCount));}-- const cellPrimitive = worksheet!.getCellMatrix().toJSON();- const cellWrapper = new ObjectMatrix(cellPrimitive);- cellWrapper.insertColumnCount(colIndex, colCount);}return true;diff --git a/packages/base-sheets/src/Commands/Mutations/remove-row-col.mutation.ts b/packages/base-sheets/src/Commands/Mutations/remove-row-col.mutation.tsindex 84acd186d7..f1ba22c34a 100644--- a/packages/base-sheets/src/Commands/Mutations/remove-row-col.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/remove-row-col.mutation.ts@@ -1,5 +1,6 @@import { CommandType, IColumnData, ICurrentUniverService, IMutation, IRowData, ObjectArray } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IInsertColMutationParams, IInsertRowMutationParams, IRemoveColMutationParams, IRemoveRowMutationParams } from '../../Basics/Interfaces/MutationInterface';export const IRemoveRowMutationFactory = (accessor: IAccessor, params: IRemoveRowMutationParams): IInsertRowMutationParams => {diff --git a/packages/base-sheets/src/Commands/Mutations/remove-worksheet-merge.mutation.ts b/packages/base-sheets/src/Commands/Mutations/remove-worksheet-merge.mutation.tsindex f77e8c514f..acd61a699e 100644--- a/packages/base-sheets/src/Commands/Mutations/remove-worksheet-merge.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/remove-worksheet-merge.mutation.ts@@ -1,5 +1,6 @@import { CommandType, ICurrentUniverService, IMutation, Rectangle } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';+import { IAddWorksheetMergeMutationParams, IRemoveWorksheetMergeMutationParams } from '../../Basics/Interfaces/MutationInterface';export const RemoveWorksheetMergeMutationFactory = (accessor: IAccessor, params: IRemoveWorksheetMergeMutationParams): IAddWorksheetMergeMutationParams => {diff --git a/packages/base-sheets/src/Commands/Mutations/set-frozen-columns.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-frozen-columns.mutation.tsnew file mode 100644index 0000000000..900fefed4b--- /dev/null+++ b/packages/base-sheets/src/Commands/Mutations/set-frozen-columns.mutation.ts@@ -0,0 +1,50 @@+import { CommandType, ICurrentUniverService, IMutation } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++export interface ISetFrozenColumnsMutationParams {+ workbookId: string;+ worksheetId: string;+ numColumns: number;+}++export const SetFrozenColumnsMutationFactory = (accessor: IAccessor, params: ISetFrozenColumnsMutationParams): ISetFrozenColumnsMutationParams => {+ const currentUniverService = accessor.get(ICurrentUniverService);+ const universheet = currentUniverService.getUniverSheetInstance(params.workbookId);++ if (universheet == null) {+ throw new Error('universheet is null error!');+ }+ const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);++ if (worksheet == null) {+ throw new Error('worksheet is null error!');+ }+ const config = worksheet.getConfig();+ const oldStatus = config.freezeColumn;++ return {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ numColumns: oldStatus,+ };+};++export const SetFrozenColumnsMutation: IMutation<ISetFrozenColumnsMutationParams> = {+ id: 'sheet.mutation.set-frozen-columns',+ type: CommandType.MUTATION,+ handler: async (accessor: IAccessor, params: ISetFrozenColumnsMutationParams) => {+ const currentUniverService = accessor.get(ICurrentUniverService);+ const universheet = currentUniverService.getUniverSheetInstance(params.workbookId);++ if (universheet == null) {+ throw new Error('universheet is null error!');+ }++ const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);+ if (!worksheet) return false;+ const config = worksheet.getConfig();+ config.freezeColumn = params.numColumns;++ return true;+ },+};diff --git a/packages/base-sheets/src/Commands/Mutations/set-frozen-rows.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-frozen-rows.mutation.tsnew file mode 100644index 0000000000..6fca5e7e1c--- /dev/null+++ b/packages/base-sheets/src/Commands/Mutations/set-frozen-rows.mutation.ts@@ -0,0 +1,50 @@+import { CommandType, ICurrentUniverService, IMutation } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++export interface ISetFrozenRowsMutationParams {+ workbookId: string;+ worksheetId: string;+ numRows: number;+}++export const SetFrozenRowsMutationFactory = (accessor: IAccessor, params: ISetFrozenRowsMutationParams): ISetFrozenRowsMutationParams => {+ const currentUniverService = accessor.get(ICurrentUniverService);+ const universheet = currentUniverService.getUniverSheetInstance(params.workbookId);++ if (universheet == null) {+ throw new Error('universheet is null error!');+ }+ const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);++ if (worksheet == null) {+ throw new Error('worksheet is null error!');+ }+ const config = worksheet.getConfig();+ const oldStatus = config.freezeRow;++ return {+ workbookId: params.workbookId,+ worksheetId: params.worksheetId,+ numRows: oldStatus,+ };+};++export const SetFrozenRowsMutation: IMutation<ISetFrozenRowsMutationParams> = {+ id: 'sheet.mutation.set-frozen-rows',+ type: CommandType.MUTATION,+ handler: async (accessor: IAccessor, params: ISetFrozenRowsMutationParams) => {+ const currentUniverService = accessor.get(ICurrentUniverService);+ const universheet = currentUniverService.getUniverSheetInstance(params.workbookId);++ if (universheet == null) {+ throw new Error('universheet is null error!');+ }++ const worksheet = universheet.getWorkBook().getSheetBySheetId(params.worksheetId);+ if (!worksheet) return false;+ const config = worksheet.getConfig();+ config.freezeRow = params.numRows;++ return true;+ },+};diff --git a/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.tsindex 4efe5b4fd9..fc2dd2609b 100644--- a/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/set-range-styles.mutation.ts@@ -1,26 +1,25 @@import {CommandType,- IMutation,- IStyleData,- ICurrentUniverService,- ObjectMatrix,- Tools,- Nullable,IBorderData,- IKeyValue,+ ICurrentUniverService,IDocumentData,- ITextStyle,+ IKeyValue,+ IMutation,IRangeData,+ IStyleData,+ ITextStyle,+ Nullable,+ ObjectMatrix,ObjectMatrixPrimitiveType,+ Tools,} from '@univerjs/core';-import { IAccessor } from '@wendellhu/redi';export interface ISetRangeStyleMutationParams {workbookId: string;worksheetId: string;range: IRangeData[];- value: ObjectMatrixPrimitiveType<IStyleData>;+ value?: ObjectMatrixPrimitiveType<IStyleData>;}/**@@ -34,17 +33,23 @@ export const SetRangeStyleUndoMutationFactory = (accessor: IAccessor, params: ISconst currentUniverService = accessor.get(ICurrentUniverService);const workbook = currentUniverService.getCurrentUniverSheetInstance().getWorkBook();const worksheet = currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getSheetBySheetId(params.worksheetId);- const cellMatrix = worksheet?.getCellMatrix();+ if (worksheet == null) {+ throw new Error('error');+ }+ const cellMatrix = worksheet.getCellMatrix();const styles = workbook.getStyles();+ const value = params.value ?? null;+const undoData = new ObjectMatrix<IStyleData>();for (let i = 0; i < params.range.length; i++) {const { startRow, endRow, startColumn, endColumn } = params.range[i];for (let r = startRow; r <= endRow; r++) {for (let c = startColumn; c <= endColumn; c++) {- const cell = cellMatrix?.getValue(r, c) || {};+ const cell = cellMatrix.getValue(r, c) || {};const old = styles.getStyleByCell(cell);- undoData.setValue(r - startRow, c - startColumn, transformStyle(old, params.value[r - startRow][c - startColumn] as Nullable<IStyleData>));+ const test = transformStyle(old, value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null);+ undoData.setValue(r - startRow, c - startColumn, test);}}}@@ -67,6 +72,7 @@ export const SetRangeStyleMutation: IMutation<ISetRangeStyleMutationParams, boolconst cellMatrix = worksheet.getCellMatrix();const styles = workbook.getStyles();+ const value = params.value ?? null;for (let i = 0; i < params.range.length; i++) {const { startRow, endRow, startColumn, endColumn } = params.range[i];@@ -82,7 +88,7 @@ export const SetRangeStyleMutation: IMutation<ISetRangeStyleMutationParams, bool}// set style- const merge = mergeStyle(old, params.value[r - startRow][c - startColumn] as Nullable<IStyleData>);+ const merge = mergeStyle(old, value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null);// then remove nullmerge && Tools.removeNull(merge);@@ -96,7 +102,7 @@ export const SetRangeStyleMutation: IMutation<ISetRangeStyleMutationParams, bool// When the rich text sets the cell style, you need to modify the style of all rich text// TODO redo/undo use setRangeData to undo rich text settingif (cell.p) {- mergeRichTextStyle(cell.p, params.value[r - startRow][c - startColumn] as Nullable<IStyleData>);+ mergeRichTextStyle(cell.p, value ? (value[r - startRow][c - startColumn] as Nullable<IStyleData>) : null);}cellMatrix.setValue(r, c, cell);@@ -190,7 +196,9 @@ export function mergeStyle(oldStyle: Nullable<IStyleData>, newStyle: Nullable<IS// overline/strikethrough/underline add colorif ('cl' in backupStyle) {if (['ul', 'ol', 'st'].includes(k)) {- backupStyle[k].cl = backupStyle.cl;+ if (backupStyle[k]) {+ backupStyle[k].cl = backupStyle.cl;+ }}}}diff --git a/packages/base-sheets/src/Commands/Mutations/set-tab-color.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-tab-color.mutation.tsindex edca40f18e..7badc67e19 100644--- a/packages/base-sheets/src/Commands/Mutations/set-tab-color.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/set-tab-color.mutation.ts@@ -30,7 +30,6 @@ export const SetTabColorMutation: IMutation<ISetTabColorMutationParams> = {if (!worksheet) return false;worksheet.getConfig().tabColor = params.color;- console.log(worksheet);return true;},};diff --git a/packages/base-sheets/src/Commands/Mutations/set-worksheet-col-width.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-worksheet-col-width.mutation.tsindex 549d0a3f8f..e10dc169cb 100644--- a/packages/base-sheets/src/Commands/Mutations/set-worksheet-col-width.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/set-worksheet-col-width.mutation.ts@@ -26,7 +26,7 @@ export const SetWorksheetColWidthMutationFactory = (accessor: IAccessor, params:for (let i = 0; i < ranges.length; i++) {const range = ranges[i];for (let j = range.startColumn; j < range.endColumn + 1; j++) {- const column = manager.getColumnOrCreate(i);+ const column = manager.getColumnOrCreate(j);colWidth.set(j, column.w);}}@@ -58,7 +58,7 @@ export const SetWorksheetColWidthMutation: IMutation<ISetWorksheetColWidthMutatifor (let i = 0; i < ranges.length; i++) {const range = ranges[i];for (let j = range.startColumn; j < range.endColumn + 1; j++) {- const column = manager.getColumnOrCreate(i);+ const column = manager.getColumnOrCreate(j);if (typeof params.colWidth === 'number') {column.w = params.colWidth;} else {diff --git a/packages/base-sheets/src/Commands/Mutations/set-worksheet-row-height.mutation.ts b/packages/base-sheets/src/Commands/Mutations/set-worksheet-row-height.mutation.tsindex 4b29c23896..e44e57ac8e 100644--- a/packages/base-sheets/src/Commands/Mutations/set-worksheet-row-height.mutation.ts+++ b/packages/base-sheets/src/Commands/Mutations/set-worksheet-row-height.mutation.ts@@ -26,7 +26,7 @@ export const SetWorksheetRowHeightMutationFactory = (accessor: IAccessor, paramsfor (let i = 0; i < ranges.length; i++) {const range = ranges[i];for (let j = range.startRow; j < range.endRow + 1; j++) {- const row = manager.getRowOrCreate(i);+ const row = manager.getRowOrCreate(j);rowHeight.set(j, row.h);}}@@ -58,7 +58,7 @@ export const SetWorksheetRowHeightMutation: IMutation<ISetWorksheetRowHeightMutafor (let i = 0; i < ranges.length; i++) {const range = ranges[i];for (let j = range.startRow; j < range.endRow + 1; j++) {- const row = manager.getRowOrCreate(i);+ const row = manager.getRowOrCreate(j);if (typeof params.rowHeight === 'number') {row.h = params.rowHeight;} else {diff --git a/packages/base-sheets/src/Controller/BasicWorkbook.controller.ts b/packages/base-sheets/src/Controller/BasicWorkbook.controller.tsindex b60d8fb877..469d78c620 100644--- a/packages/base-sheets/src/Controller/BasicWorkbook.controller.ts+++ b/packages/base-sheets/src/Controller/BasicWorkbook.controller.ts@@ -3,8 +3,6 @@ import { IDisposable, Inject, SkipSelf } from '@wendellhu/redi';import { InsertSheetCommand } from '../Commands/Commands/insert-sheet.command';import { RemoveSheetCommand } from '../Commands/Commands/remove-sheet.command';-import { InsertSheetMutation } from '../Commands/Mutations/insert-sheet.mutation';-import { RemoveSheetMutation } from '../Commands/Mutations/remove-sheet.mutation';/*** The controller to provide the most basic sheet CRUD methods to other modules of sheet modules.@@ -12,11 +10,6 @@ import { RemoveSheetMutation } from '../Commands/Mutations/remove-sheet.mutationexport class BasicWorkbookController extends Disposable implements IDisposable {constructor(@ICommandService private readonly _commandService: ICommandService, @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager) {super();-- this.disposeWithMe(_commandService.registerCommand(InsertSheetCommand));- this.disposeWithMe(_commandService.registerCommand(InsertSheetMutation));- this.disposeWithMe(_commandService.registerCommand(RemoveSheetCommand));- this.disposeWithMe(_commandService.registerCommand(RemoveSheetMutation));}onInitialize() {}diff --git a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts b/packages/base-sheets/src/Controller/BasicWorksheet.controller.tsindex 7fd84f9282..6d6b2d9302 100644--- a/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts+++ b/packages/base-sheets/src/Controller/BasicWorksheet.controller.ts@@ -13,8 +13,17 @@ import { DeleteRangeMoveLeftCommand } from '../Commands/Commands/delete-range-moimport { DeleteRangeMoveUpCommand } from '../Commands/Commands/delete-range-move-up.command';import { InsertRangeMoveDownCommand } from '../Commands/Commands/insert-range-move-down.command';import { InsertRangeMoveRightCommand } from '../Commands/Commands/insert-range-move-right.command';-import { InsertColCommand } from '../Commands/Commands/insert-row-col.command';+import {+ InsertColAfterCommand,+ InsertColBeforeCommand,+ InsertColCommand,+ InsertRowAfterCommand,+ InsertRowBeforeCommand,+ InsertRowCommand,+} from '../Commands/Commands/insert-row-col.command';+import { InsertSheetCommand } from '../Commands/Commands/insert-sheet.command';import { RemoveColCommand, RemoveRowCommand } from '../Commands/Commands/remove-row-col.command';+import { RemoveSheetCommand } from '../Commands/Commands/remove-sheet.command';import { RemoveWorksheetMergeCommand } from '../Commands/Commands/remove-worksheet-merge.command';import { SetBorderColorCommand, SetBorderCommand, SetBorderPositionCommand, SetBorderStyleCommand } from '../Commands/Commands/set-border-command';import { SetRangeFormattedValueCommand } from '../Commands/Commands/set-range-formatted-value.command';@@ -45,8 +54,11 @@ import { AddWorksheetMergeMutation } from '../Commands/Mutations/add-worksheet-mimport { DeleteRangeMutation } from '../Commands/Mutations/delete-range.mutation';import { InsertRangeMutation } from '../Commands/Mutations/insert-range.mutation';import { InsertColMutation, InsertRowMutation } from '../Commands/Mutations/insert-row-col.mutation';+import { InsertSheetMutation } from '../Commands/Mutations/insert-sheet.mutation';import { RemoveColMutation, RemoveRowMutation } from '../Commands/Mutations/remove-row-col.mutation';+import { RemoveSheetMutation } from '../Commands/Mutations/remove-sheet.mutation';import { RemoveWorksheetMergeMutation } from '../Commands/Mutations/remove-worksheet-merge.mutation';+import { SetBorderStylesMutation } from '../Commands/Mutations/set-border-styles.mutatio';import { SetRangeFormattedValueMutation } from '../Commands/Mutations/set-range-formatted-value.mutation';import { SetRangeStyleMutation } from '../Commands/Mutations/set-range-styles.mutation';import { SetRangeValuesMutation } from '../Commands/Mutations/set-range-values.mutation';@@ -91,10 +103,15 @@ export class BasicWorksheetController extends Disposable implements IDisposableSetWorksheetHideCommand,SetWorksheetHideMutation,+ InsertRowCommand,+ InsertRowBeforeCommand,+ InsertRowAfterCommand,InsertRowMutation,RemoveRowCommand,RemoveRowMutation,InsertColCommand,+ InsertColBeforeCommand,+ InsertColAfterCommand,InsertColMutation,RemoveColCommand,RemoveColMutation,@@ -129,15 +146,19 @@ export class BasicWorksheetController extends Disposable implements IDisposableResetBackgroundColorCommand,SetHorizontalTextAlignCommand,SetVerticalTextAlignCommand,-SetBorderCommand,SetBorderColorCommand,SetBorderStyleCommand,SetBorderPositionCommand,+ SetBorderStylesMutation,CopySheetCommand,SetTabColorCommand,SetTabColorMutation,SetWorksheetShowCommand,+ RemoveSheetCommand,+ RemoveSheetMutation,+ InsertSheetCommand,+ InsertSheetMutation,].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}diff --git a/packages/base-sheets/src/Controller/SheetBarController.ts b/packages/base-sheets/src/Controller/SheetBarController.tsindex b3b68b03cb..1a2b278bf8 100644--- a/packages/base-sheets/src/Controller/SheetBarController.ts+++ b/packages/base-sheets/src/Controller/SheetBarController.ts@@ -1,7 +1,8 @@-import { UIObserver, ObserverManager, LocaleService, ICurrentUniverService, GenName, ICommandService } from '@univerjs/core';+import { GenName, ICommandService, ICurrentUniverService, LocaleService, ObserverManager, UIObserver } from '@univerjs/core';import { Inject, SkipSelf } from '@wendellhu/redi';-import { SetWorksheetNameCommand } from '../Commands/Commands/set-worksheet-name.command';+import { InsertSheetCommand } from '../Commands/Commands/insert-sheet.command';+import { SetWorksheetNameCommand } from '../Commands/Commands/set-worksheet-name.command';export class SheetBarController {constructor(diff --git a/packages/base-sheets/src/Controller/SheetContainerController.ts b/packages/base-sheets/src/Controller/SheetContainerController.tsindex dab71c28da..d9ba24f5c8 100644--- a/packages/base-sheets/src/Controller/SheetContainerController.ts+++ b/packages/base-sheets/src/Controller/SheetContainerController.ts@@ -2,10 +2,14 @@ import { Disposable, ICommandInfo, ICommandService, ICurrentUniverService } fromimport { Inject } from '@wendellhu/redi';import { SetWorksheetActivateMutation } from '../Commands/Mutations/set-worksheet-activate.mutation';+import { SetWorksheetColWidthMutation } from '../Commands/Mutations/set-worksheet-col-width.mutation';+import { SetWorksheetRowHeightMutation } from '../Commands/Mutations/set-worksheet-row-height.mutation';import { ISelectionManager } from '../Services/tokens';import { CanvasView } from '../View';import { SelectionManager } from './Selection';+const updateCommandList = [SetWorksheetRowHeightMutation.id, SetWorksheetColWidthMutation.id, SetWorksheetActivateMutation.id];+export class SheetContainerController extends Disposable {constructor(@ISelectionManager private readonly _selectionManager: SelectionManager,@@ -21,11 +25,15 @@ export class SheetContainerController extends Disposable {private _initialize() {this.disposeWithMe(this._commandService.onCommandExecuted((command: ICommandInfo) => {- this.canvasView.getSheetView().getSpreadsheet().makeDirty(true);-- if (command.id === SetWorksheetActivateMutation.id) {- this.canvasView.updateToSheet(this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet());+ // refresh selection and worksheet canvas view+ if (updateCommandList.includes(command.id)) {+ const worksheet = this._currentUniverService.getCurrentUniverSheetInstance().getWorkBook().getActiveSheet();+ this._selectionManager.updateToSheet(worksheet);+ this.canvasView.updateToSheet(worksheet);+ this._selectionManager.renderCurrentControls(false);}++ this.canvasView.getSheetView().getSpreadsheet().makeDirty(true);}));}diff --git a/packages/base-sheets/src/Services/border-style-manager.service.ts b/packages/base-sheets/src/Services/border-style-manager.service.tsindex 7a4d5d5b43..9063bb2af4 100644--- a/packages/base-sheets/src/Services/border-style-manager.service.ts+++ b/packages/base-sheets/src/Services/border-style-manager.service.ts@@ -1,6 +1,6 @@-import { BehaviorSubject } from 'rxjs';import { BorderStyleTypes, BorderType } from '@univerjs/core';import { IDisposable } from '@wendellhu/redi';+import { BehaviorSubject } from 'rxjs';export interface IBorderInfo {type: BorderType;@@ -27,6 +27,11 @@ export class BorderStyleManagerService implements IDisposable {this._borderInfo$.complete();}+ setType(type: BorderType): void {+ this._borderInfo.type = type;+ this.refresh();+ }+setColor(color: string): void {this._borderInfo.color = color;this.refresh();diff --git a/packages/base-sheets/src/SheetPlugin.ts b/packages/base-sheets/src/SheetPlugin.tsindex 65e0cda717..b7350531ac 100644--- a/packages/base-sheets/src/SheetPlugin.ts+++ b/packages/base-sheets/src/SheetPlugin.ts@@ -103,6 +103,7 @@ export class SheetPlugin extends Plugin<SheetPluginObserve> {// this._hideColumnController = this._injector.get(HideColumnController);this._injector.get(BasicWorksheetController);+ this._injector.get(BasicWorkbookController);}initCanvasView() {diff --git a/packages/base-sheets/src/index.ts b/packages/base-sheets/src/index.tsindex 85ab01ecd6..f169800c08 100644--- a/packages/base-sheets/src/index.ts+++ b/packages/base-sheets/src/index.ts@@ -26,7 +26,16 @@ export { SetSelectionsOperation } from './Commands/Operations/selection.operatioexport { ClearSelectionContentCommand } from './Commands/Commands/clear-selection-content.command';export { DeleteRangeMoveLeftCommand } from './Commands/Commands/delete-range-move-left.command';export { DeleteRangeMoveUpCommand } from './Commands/Commands/delete-range-move-up.command';-export { InsertColCommand, InsertColCommandParams, InsertRowCommand, InsertRowCommandParams } from './Commands/Commands/insert-row-col.command';+export {+ InsertColAfterCommand,+ InsertColBeforeCommand,+ InsertColCommand,+ InsertColCommandParams,+ InsertRowAfterCommand,+ InsertRowBeforeCommand,+ InsertRowCommand,+ InsertRowCommandParams,+} from './Commands/Commands/insert-row-col.command';export { InsertSheetCommand } from './Commands/Commands/insert-sheet.command';export { RemoveColCommand, RemoveRowCommand } from './Commands/Commands/remove-row-col.command';export {@@ -74,6 +83,12 @@ export { RemoveSheetCommand } from './Commands/Commands/remove-sheet.command';export { RemoveWorksheetMergeCommand } from './Commands/Commands/remove-worksheet-merge.command';export { SetTabColorCommand } from './Commands/Commands/set-tab-color.command';export { SetWorksheetHideCommand } from './Commands/Commands/set-worksheet-hide.command';+export { SetWorksheetNameCommand } from './Commands/Commands/set-worksheet-name.command';export { SetWorksheetRowHideCommand } from './Commands/Commands/set-worksheet-row-hide.command';export { SetWorksheetRowShowCommand } from './Commands/Commands/set-worksheet-row-show.command';export { SetWorksheetShowCommand } from './Commands/Commands/set-worksheet-show.command';+export { SetTabColorMutation } from './Commands/Mutations/set-tab-color.mutation';+export { SetWorksheetActivateMutation } from './Commands/Mutations/set-worksheet-activate.mutation';+export { SetWorksheetHideMutation } from './Commands/Mutations/set-worksheet-hide.mutation';+export { SetWorksheetNameMutation } from './Commands/Mutations/set-worksheet-name.mutation';+export { SetWorksheetOrderMutation } from './Commands/Mutations/set-worksheet-order.mutation';diff --git a/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.tsdeleted file mode 100644index 947c64dbc5..0000000000--- a/packages/base-ui/src/Basics/SlideTabBar/SlideTabBar.ts+++ /dev/null@@ -1,411 +0,0 @@-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 {- _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;-- 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];- 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);- });- }-- 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/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.tsdeleted file mode 100644index 216fc0786e..0000000000--- a/packages/base-ui/src/Basics/SlideTabBar/SlideTabItem.ts+++ /dev/null@@ -1,223 +0,0 @@-import { SlideTabBar } from './SlideTabBar';-import { Animate } from './Animate';-import { SlideScrollbar } from './SlideScrollbar';--export interface SlideTabItemAnimate {- translateX: (x: number) => void;- cancel: () => void;-}--export class SlideTabItem {- _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();- }-- 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;- }-- 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/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsxindex 3bf16ea76c..fed7c909c0 100644--- a/packages/base-ui/src/Components/Menu/Menu.tsx+++ b/packages/base-ui/src/Components/Menu/Menu.tsx@@ -113,10 +113,6 @@ export class Menu extends Component<BaseMenuProps, IBaseMenuState> {};handleItemClick = (item: IMenuButtonItem) => {- // When there is no need to execute the command, execute click- if (item.onClick) {- item.onClick();- }this.showMenu(false);};@@ -309,9 +305,8 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {* user input change value from CustomLabel* @param e*/- onChange = (e: Event) => {- const targetValue = (e.target as HTMLInputElement).value;- const value = isRealNum(targetValue) ? parseInt(targetValue) : targetValue;+ onChange = (v: string | number) => {+ const value = isRealNum(v) && typeof v === 'string' ? parseInt(v) : v;this.setState({value,@@ -344,7 +339,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}disabled={disabled}onClick={() => {- commandService.executeCommand(item.id);+ commandService.executeCommand(item.id, { value: this.state.value });onClick();}}>@@ -354,8 +349,9 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {title={title}label={label}onChange={(v) => {- commandService.executeCommand(item.id, { value: v });- onClick();+ this.onChange(v);+ // commandService.executeCommand(item.id, { value });+ // onClick();}}></NeoCustomLabel></li>@@ -401,6 +397,7 @@ export class MenuItem extends Component<IMenuItemProps, IMenuItemState> {className={joinClassNames(styles.colsMenuitem, disabled ? styles.colsMenuitemDisabled : '')}onMouseEnter={(e) => this.mouseEnter(e, index)}onMouseLeave={(e) => this.mouseLeave(e, index)}+ onClick={(e) => this.handleClick(e, item, index)}><NeoCustomLabel title={item.title} value={item.title} icon={item.icon} display={item.display} label={item.label}></NeoCustomLabel>{(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (diff --git a/packages/base-ui/src/Interfaces/Select.ts b/packages/base-ui/src/Interfaces/Select.tsindex f3d86a9da8..eda2daa9e5 100644--- a/packages/base-ui/src/Interfaces/Select.ts+++ b/packages/base-ui/src/Interfaces/Select.ts@@ -10,7 +10,7 @@// tooltipRight?: string;// onClick?: (...arg: any[]) => void;// onKeyUp?: (...arg: any[]) => void;-// onDown?: (...arg: any[]) => void;+// onMouseDown?: (...arg: any[]) => void;// triggerUpdate?: (func: Function) => void;// needChange?: boolean;// selectType?: ISelectButtonType;diff --git a/packages/base-ui/src/Interfaces/SheetBar.ts b/packages/base-ui/src/Interfaces/SheetBar.tsindex f106911309..ac96008ae5 100644--- a/packages/base-ui/src/Interfaces/SheetBar.ts+++ b/packages/base-ui/src/Interfaces/SheetBar.ts@@ -1,4 +1,5 @@import { BooleanNumber } from '@univerjs/core';+import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';import { BaseSelectProps } from '../Components';@@ -10,9 +11,9 @@ export interface BaseSheetBarProps extends BaseComponentProps, Omit<BaseSelectPrstyle?: JSX.CSSProperties;hidden?: BooleanNumber;addSheet?: () => void;- onDown?: () => void;- selectSheet?: () => void;- changeSheetName?: (e: Event) => void;+ onMouseDown?: () => void;+ selectSheet?: (slideItemIndex: number) => void;+ changeSheetName?: (sheetId: string, name: string) => void;dragEnd?: (elements: HTMLElement[]) => void;selected?: boolean;}diff --git a/packages/base-ui/src/Interfaces/Ul.ts b/packages/base-ui/src/Interfaces/Ul.tsindex 3f21e746f4..c5a17dbdb0 100644--- a/packages/base-ui/src/Interfaces/Ul.ts+++ b/packages/base-ui/src/Interfaces/Ul.ts@@ -1,4 +1,5 @@import { BooleanNumber } from '@univerjs/core';+import { BaseComponent, BaseComponentProps, JSXComponent } from '../BaseComponent';export interface BaseUlProps extends BaseComponentProps {@@ -16,7 +17,7 @@ export interface BaseUlProps extends BaseComponentProps {children?: BaseUlProps[];onClick?: (...arg: any[]) => void;onKeyUp?: (...any: any[]) => void;- onDown?: (...any: any[]) => void;+ onMouseDown?: (...any: any[]) => void;style?: JSX.CSSProperties;showSelect?: (e: MouseEvent) => void;getParent?: any;diff --git a/packages/base-ui/src/index.ts b/packages/base-ui/src/index.tsindex c040a6a5de..a9d0f7af41 100644--- a/packages/base-ui/src/index.ts+++ b/packages/base-ui/src/index.ts@@ -1,29 +1,28 @@+export * from './BaseComponent';export * from './Basics';export * from './Common';-export * from './Interfaces';+export * from './Components';+export { SharedController } from './controllers/shared-shortcut.controller';export * from './Enum';-export * from './Utils';export * from './Helpers';-export * from './Components';-export * from './BaseComponent';-export * from './UIPlugin';-+export * from './Interfaces';export {- ICustomComponentProps,ICustomComponentOption,+ ICustomComponentProps,+ IDisplayMenuItem,IMenuButtonItem,IMenuItem,+ IMenuItemFactory,IMenuSelectorItem,+ isCustomComponentOption,+ isValueOptions,IValueOption,MenuItemType,MenuPosition,- IDisplayMenuItem,- isCustomComponentOption,- isValueOptions,} from './services/menu/menu';-export { IMenuService, DesktopMenuService } from './services/menu/menu.service';+export { DesktopMenuService, IMenuService } from './services/menu/menu.service';+export { DesktopPlatformService, IPlatformService } from './services/platform/platform.service';export { KeyCode, MetaKeys } from './services/shortcut/keycode';-export { IShortcutService, IShortcutItem, DesktopShortcutService } from './services/shortcut/shortcut.service';-export { IPlatformService, DesktopPlatformService } from './services/platform/platform.service';--export { SharedController } from './controllers/shared-shortcut.controller';+export { DesktopShortcutService, IShortcutItem, IShortcutService } from './services/shortcut/shortcut.service';+export * from './UIPlugin';+export * from './Utils';diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.tsindex 89a91e1518..414d09135c 100644--- a/packages/base-ui/src/services/menu/menu.ts+++ b/packages/base-ui/src/services/menu/menu.ts@@ -59,10 +59,6 @@ export interface IMenuButtonItem<V = undefined> extends IMenuItemBase<V> {type: MenuItemType.BUTTON;activated$?: Observable<boolean>;-- // TODO@wzhudev: I may deprecate this- // eslint-disable-next-line @typescript-eslint/no-explicit-any- onClick?: (...arg: any) => void; // menu button click callback, does not trigger command. e.g. sheet bar rename}export function isMenuButtonItem(v: IMenuItem): v is IMenuButtonItem {diff --git a/packages/core/src/Shared/Rectangle.ts b/packages/core/src/Shared/Rectangle.tsindex 8cfcefb7e2..1fae11d07d 100644--- a/packages/core/src/Shared/Rectangle.ts+++ b/packages/core/src/Shared/Rectangle.ts@@ -1,5 +1,6 @@import { IRangeData } from '../Types/Interfaces';import { Tools } from './Tools';+import { Nullable } from './Types';/*** A square area containing four position information: startRow, startColumn, endRow, and endColumn@@ -67,6 +68,69 @@ export class Rectangle implements IRangeData {return zx <= x && zy <= y;}+ static getIntersects(src: IRangeData, target: IRangeData): Nullable<IRangeData> {+ const currentStartRow = src.startRow;+ const currentEndRow = src.endRow;+ const currentStartColumn = src.startColumn;+ const currentEndColumn = src.endColumn;++ const incomingStartRow = target.startRow;+ const incomingEndRow = target.endRow;+ const incomingStartColumn = target.startColumn;+ const incomingEndColumn = target.endColumn;++ let startColumn;+ let startRow;+ let endColumn;+ let endRow;+ if (incomingStartRow <= currentEndRow) {+ if (incomingStartRow >= currentStartRow) {+ startRow = incomingStartRow;+ } else {+ startRow = currentStartRow;+ }+ } else {+ return null;+ }++ if (incomingEndRow >= currentStartRow) {+ if (incomingEndRow >= currentEndRow) {+ endRow = currentEndRow;+ } else {+ endRow = incomingEndRow;+ }+ } else {+ return null;+ }++ if (incomingStartColumn <= currentEndColumn) {+ if (incomingStartColumn > currentStartColumn) {+ startColumn = incomingStartColumn;+ } else {+ startColumn = currentStartColumn;+ }+ } else {+ return null;+ }++ if (incomingEndColumn >= currentStartColumn) {+ if (incomingEndColumn >= currentEndColumn) {+ endColumn = currentEndColumn;+ } else {+ endColumn = incomingEndColumn;+ }+ } else {+ return null;+ }++ return {+ startRow,+ endRow,+ startColumn,+ endColumn,+ };+ }+intersects(rectangle: Rectangle): boolean {return Rectangle.intersects(this, rectangle);}diff --git a/packages/core/src/Sheets/Domain/Range.ts b/packages/core/src/Sheets/Domain/Range.tsindex 2520818a14..992eea1152 100644--- a/packages/core/src/Sheets/Domain/Range.ts+++ b/packages/core/src/Sheets/Domain/Range.ts@@ -2,7 +2,7 @@ import { ICurrentUniverService } from '../../services/current.service';import { Nullable, ObjectMatrix, ObjectMatrixPrimitiveType, Tools } from '../../Shared';import { DEFAULT_RANGE, DEFAULT_STYLES } from '../../Types/Const';import { BooleanNumber, Dimension, Direction, FontItalic, FontWeight, HorizontalAlign, VerticalAlign, WrapStrategy } from '../../Types/Enum';-import { IBorderData, ICellData, IDocumentData, IRangeData, IRangeType, IStyleData, ITextDecoration } from '../../Types/Interfaces';+import { IBorderData, ICellData, IDocumentData, IRangeData, IRangeType, IStyleData, ITextDecoration, ITextRotation } from '../../Types/Interfaces';import type { Worksheet } from './Worksheet';/**@@ -631,7 +631,7 @@ export class Range {* Returns the text rotation settings for the top left cell of the range.*/// getTextRotation(): number {- getTextRotation() {+ getTextRotation(): ITextRotation {return this.getTextRotations()[0][0];}@@ -639,8 +639,8 @@ export class Range {* Returns the text rotation settings for the cells in the range.*/// getTextRotations(): number[][] {- getTextRotations() {- return this._getStyles('tr');+ getTextRotations(): ITextRotation[][] {+ return this._getStyles('tr') as ITextRotation[][];}/**diff --git a/packages/sheets-plugin-find/src/Controller/FindController.ts b/packages/sheets-plugin-find/src/Controller/FindController.tsindex 38b0aa720e..e9744fe751 100644--- a/packages/sheets-plugin-find/src/Controller/FindController.ts+++ b/packages/sheets-plugin-find/src/Controller/FindController.ts@@ -1,38 +1,34 @@-import { ComponentManager, Icon, IMenuService } from '@univerjs/base-ui';-import { Disposable, ICommandService } from '@univerjs/core';-import { IToolbarItemProps, SheetContainerUIController } from '@univerjs/ui-plugin-sheets';-import { IDisposable, Inject, Injector } from '@wendellhu/redi';--import { HideModalCommand, ShowModalCommand } from '../commands/show-modal.command';-import { FIND_PLUGIN_NAME } from '../Const/PLUGIN_NAME';-import { FindModalController } from './FindModalController';-import { FindMenuItemFactory } from './menu';--export class FindController extends Disposable implements IDisposable {-- constructor(- @Inject(FindModalController) private _findModalController: FindModalController,- @Inject(SheetContainerUIController) private _uiController: SheetContainerUIController,- @Inject(ComponentManager) private readonly _componentManager: ComponentManager,- @Inject(Injector) private readonly _injector: Injector,- @IMenuService private readonly _menuService: IMenuService,- @ICommandService private readonly _commandService: ICommandService- ) {- super();- this._componentManager.register('SearchIcon', Icon.SearchIcon);- const toolbar = this._uiController.getToolbarController();-- this._initializeContextMenu();-- // TODO@Dushusir maybe trigger once in ui-plugin-sheets?- toolbar.setToolbar();-- [ShowModalCommand, HideModalCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));- }-- private _initializeContextMenu() {- [FindMenuItemFactory].forEach((factory) => {- this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));- });- }-}+import { ComponentManager, Icon, IMenuService } from '@univerjs/base-ui';+import { Disposable, ICommandService } from '@univerjs/core';+import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';+import { IDisposable, Inject, Injector } from '@wendellhu/redi';++import { HideModalOperation, ShowModalOperation } from '../commands/operations/show-modal.operation';+import { FindModalController } from './FindModalController';+import { FindMenuItemFactory } from './menu';++export class FindController extends Disposable implements IDisposable {+ constructor(+ @Inject(FindModalController) private _findModalController: FindModalController,+ @Inject(SheetContainerUIController) private _uiController: SheetContainerUIController,+ @Inject(ComponentManager) private readonly _componentManager: ComponentManager,+ @Inject(Injector) private readonly _injector: Injector,+ @IMenuService private readonly _menuService: IMenuService,+ @ICommandService private readonly _commandService: ICommandService+ ) {+ super();+ this._componentManager.register('SearchIcon', Icon.SearchIcon);+ const toolbar = this._uiController.getToolbarController();++ this._initializeContextMenu();+ toolbar.setToolbar();++ [ShowModalOperation, HideModalOperation].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));+ }++ private _initializeContextMenu() {+ [FindMenuItemFactory].forEach((factory) => {+ this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));+ });+ }+}diff --git a/packages/sheets-plugin-find/src/Controller/menu.ts b/packages/sheets-plugin-find/src/Controller/menu.tsindex f2bea09437..2fddd00ce9 100644--- a/packages/sheets-plugin-find/src/Controller/menu.ts+++ b/packages/sheets-plugin-find/src/Controller/menu.ts@@ -1,11 +1,11 @@import { IMenuButtonItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';import { IAccessor } from '@wendellhu/redi';-import { ShowModalCommand } from '../commands/show-modal.command';+import { ShowModalOperation } from '../commands/operations/show-modal.operation';export function FindMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: ShowModalCommand.id,+ id: ShowModalOperation.id,type: MenuItemType.BUTTON,icon: 'SearchIcon',title: 'find.findLabel',diff --git a/packages/sheets-plugin-find/src/commands/show-modal.command.ts b/packages/sheets-plugin-find/src/commands/operations/show-modal.operation.tssimilarity index 69%rename from packages/sheets-plugin-find/src/commands/show-modal.command.tsrename to packages/sheets-plugin-find/src/commands/operations/show-modal.operation.tsindex 61adcf2d28..d4f2e93c80 100644--- a/packages/sheets-plugin-find/src/commands/show-modal.command.ts+++ b/packages/sheets-plugin-find/src/commands/operations/show-modal.operation.ts@@ -1,10 +1,10 @@import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { FindService } from '../services/find.service';+import { FindService } from '../../services/find.service';-export const ShowModalCommand: ICommand = {- id: 'find.command.show-modal',+export const ShowModalOperation: ICommand = {+ id: 'find.operation.show-modal',type: CommandType.OPERATION,handler: async (accessor: IAccessor) => {const findService = accessor.get(FindService);@@ -12,8 +12,8 @@ export const ShowModalCommand: ICommand = {return true;},};-export const HideModalCommand: ICommand = {- id: 'find.command.hide-modal',+export const HideModalOperation: ICommand = {+ id: 'find.operation.hide-modal',type: CommandType.OPERATION,handler: async (accessor: IAccessor) => {const findService = accessor.get(FindService);diff --git a/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts b/packages/sheets-plugin-image/src/Controller/OverGridImageController.tsindex e06e006c33..f2156ea96f 100644--- a/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts+++ b/packages/sheets-plugin-image/src/Controller/OverGridImageController.ts@@ -4,7 +4,7 @@ import { SheetContainerUIController } from '@univerjs/ui-plugin-sheets';import { Inject, Injector } from '@wendellhu/redi';import { IOverGridImageProperty } from '../Basics';-import { UploadCommand } from '../commands/upload.command';+import { UploadOperation } from '../commands/operations/upload.operation';import { IImagePluginData } from '../Symbol';import { ImportImageMenuItemFactory } from './menu';@@ -26,7 +26,7 @@ export class OverGridImageController extends Disposable {this._initializeContextMenu();toolbar.setToolbar();- [UploadCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));+ [UploadOperation].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}private _initializeContextMenu() {diff --git a/packages/sheets-plugin-image/src/Controller/menu.ts b/packages/sheets-plugin-image/src/Controller/menu.tsindex 02dd7de7f0..ea1ccc4874 100644--- a/packages/sheets-plugin-image/src/Controller/menu.ts+++ b/packages/sheets-plugin-image/src/Controller/menu.ts@@ -1,11 +1,11 @@import { IMenuButtonItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';import { IAccessor } from '@wendellhu/redi';-import { UploadCommand } from '../commands/upload.command';+import { UploadOperation } from '../commands/operations/upload.operation';export function ImportImageMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: UploadCommand.id,+ id: UploadOperation.id,type: MenuItemType.BUTTON,icon: 'ImageIcon',title: 'Image', // FIXME use translationdiff --git a/packages/sheets-plugin-image/src/commands/upload.command.ts b/packages/sheets-plugin-image/src/commands/operations/upload.operation.tssimilarity index 68%rename from packages/sheets-plugin-image/src/commands/upload.command.tsrename to packages/sheets-plugin-image/src/commands/operations/upload.operation.tsindex c6d11cda28..16ed6fcd75 100644--- a/packages/sheets-plugin-image/src/commands/upload.command.ts+++ b/packages/sheets-plugin-image/src/commands/operations/upload.operation.ts@@ -1,10 +1,10 @@import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { UploadService } from '../services/upload.service';+import { UploadService } from '../../services/upload.service';-export const UploadCommand: ICommand = {- id: 'image.command.upload',+export const UploadOperation: ICommand = {+ id: 'image.operation.upload',type: CommandType.OPERATION,handler: async (accessor: IAccessor) => {const uploadService = accessor.get(UploadService);diff --git a/packages/sheets-plugin-import-xlsx/src/Controller/ImportXlsxController.ts b/packages/sheets-plugin-import-xlsx/src/Controller/ImportXlsxController.tsindex 4a84867de6..373b6bf445 100644--- a/packages/sheets-plugin-import-xlsx/src/Controller/ImportXlsxController.ts+++ b/packages/sheets-plugin-import-xlsx/src/Controller/ImportXlsxController.ts@@ -3,7 +3,7 @@ import { Disposable, ICommandService } from '@univerjs/core';import { IToolbarItemProps, SheetContainerUIController } from '@univerjs/ui-plugin-sheets';import { Inject, Injector } from '@wendellhu/redi';-import { UploadCommand } from '../commands/upload.command';+import { UploadOperation } from '../commands/operations/upload.operation';import { ImportMenuItemFactory } from './menu';export class ImportXlsxController extends Disposable {@@ -22,7 +22,7 @@ export class ImportXlsxController extends Disposable {this._initializeContextMenu();toolbar.setToolbar();- [UploadCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));+ [UploadOperation].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}private _initializeContextMenu() {diff --git a/packages/sheets-plugin-import-xlsx/src/Controller/menu.ts b/packages/sheets-plugin-import-xlsx/src/Controller/menu.tsindex a252a0b044..0b3a205f4e 100644--- a/packages/sheets-plugin-import-xlsx/src/Controller/menu.ts+++ b/packages/sheets-plugin-import-xlsx/src/Controller/menu.ts@@ -1,11 +1,11 @@import { IMenuButtonItem, MenuItemType, MenuPosition } from '@univerjs/base-ui';import { IAccessor } from '@wendellhu/redi';-import { UploadCommand } from '../commands/upload.command';+import { UploadOperation } from '../commands/operations/upload.operation';export function ImportMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: UploadCommand.id,+ id: UploadOperation.id,type: MenuItemType.BUTTON,title: 'importXlsx.import',tooltip: 'importXlsx.tooltip',diff --git a/packages/sheets-plugin-import-xlsx/src/commands/upload.command.ts b/packages/sheets-plugin-import-xlsx/src/commands/operations/upload.operation.tssimilarity index 68%rename from packages/sheets-plugin-import-xlsx/src/commands/upload.command.tsrename to packages/sheets-plugin-import-xlsx/src/commands/operations/upload.operation.tsindex 0f37f23793..cb29f37c59 100644--- a/packages/sheets-plugin-import-xlsx/src/commands/upload.command.ts+++ b/packages/sheets-plugin-import-xlsx/src/commands/operations/upload.operation.ts@@ -1,10 +1,10 @@import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { UploadService } from '../services/upload.service';+import { UploadService } from '../../services/upload.service';-export const UploadCommand: ICommand = {- id: 'import.command.upload',+export const UploadOperation: ICommand = {+ id: 'import.operation.upload',type: CommandType.OPERATION,handler: async (accessor: IAccessor) => {const uploadService = accessor.get(UploadService);diff --git a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.tsindex 124ff4940c..b5a3ca4a1c 100644--- a/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/NumfmtController.ts@@ -14,8 +14,8 @@ import {import { Inject, Injector } from '@wendellhu/redi';import { NUMFMT_PLUGIN_NAME } from '../Basics/Const';-import { SetNumfmtRangeDataCommand } from '../commands/set-numfmt-range-data.command';-import { ShowModalCommand } from '../commands/show-modal.command';+import { SetNumfmtRangeDataCommand } from '../commands/commands/set-numfmt-range-data.command';+import { ShowModalOperation } from '../commands/operations/show-modal.operation';import { NumfmtModel } from '../Model';import { INumfmtPluginData } from '../Symbol';import { FormatItem } from '../View/UI/FormatItem';@@ -108,7 +108,7 @@ export class NumfmtController extends Disposable {this._initializeContextMenu();- [ShowModalCommand, SetNumfmtRangeDataCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));+ [ShowModalOperation, SetNumfmtRangeDataCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}getNumfmtBySheetIdConfig(sheetId: string): ObjectMatrixPrimitiveType<string> {diff --git a/packages/sheets-plugin-numfmt/src/Controller/menu.ts b/packages/sheets-plugin-numfmt/src/Controller/menu.tsindex 5af546d02d..38d3878b59 100644--- a/packages/sheets-plugin-numfmt/src/Controller/menu.ts+++ b/packages/sheets-plugin-numfmt/src/Controller/menu.ts@@ -4,8 +4,8 @@ import { ICommandService, IPermissionService } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';import { DEFAULT_DATA, MORE_FORMATS_SELECTIONS } from '../Basics/Const/DEFAULT_DATA';-import { SetNumfmtRangeDataCommand } from '../commands/set-numfmt-range-data.command';-import { ShowModalCommand } from '../commands/show-modal.command';+import { SetNumfmtRangeDataCommand } from '../commands/commands/set-numfmt-range-data.command';+import { ShowModalOperation } from '../commands/operations/show-modal.operation';export function NumfmtRangeDataMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {const permissionService = accessor.get(IPermissionService);@@ -66,7 +66,7 @@ export function OpenMoreFormatsModalMenuItemFactory(accessor: IAccessor): IMenuSconst selectionManager = accessor.get(ISelectionManager);return {// 2. suffix- id: ShowModalCommand.id,+ id: ShowModalOperation.id,title: 'defaultFmt.CustomFormats.text',positions: SetNumfmtRangeDataCommand.id,display: DisplayTypes.LABEL,diff --git a/packages/sheets-plugin-numfmt/src/commands/set-numfmt-range-data.command.ts b/packages/sheets-plugin-numfmt/src/commands/commands/set-numfmt-range-data.command.tssimilarity index 100%rename from packages/sheets-plugin-numfmt/src/commands/set-numfmt-range-data.command.tsrename to packages/sheets-plugin-numfmt/src/commands/commands/set-numfmt-range-data.command.tsdiff --git a/packages/sheets-plugin-numfmt/src/commands/show-modal.command.ts b/packages/sheets-plugin-numfmt/src/commands/operations/show-modal.operation.tssimilarity index 74%rename from packages/sheets-plugin-numfmt/src/commands/show-modal.command.tsrename to packages/sheets-plugin-numfmt/src/commands/operations/show-modal.operation.tsindex dd39b63306..d6ab69adf3 100644--- a/packages/sheets-plugin-numfmt/src/commands/show-modal.command.ts+++ b/packages/sheets-plugin-numfmt/src/commands/operations/show-modal.operation.ts@@ -1,14 +1,14 @@import { CommandType, ICommand } from '@univerjs/core';import { IAccessor } from '@wendellhu/redi';-import { NumfmtService } from '../services/numfmt.service';+import { NumfmtService } from '../../services/numfmt.service';export interface ShowModalCommandParams {value: string;}-export const ShowModalCommand: ICommand<ShowModalCommandParams> = {- id: 'numfmt.command.show-modal',+export const ShowModalOperation: ICommand<ShowModalCommandParams> = {+ id: 'numfmt.operation.show-modal',type: CommandType.OPERATION,handler: async (accessor: IAccessor, params: ShowModalCommandParams) => {const { value } = params;diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.tsdeleted file mode 100644index a5d0e4e8ba..0000000000--- a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/Animate.ts+++ /dev/null@@ -1,148 +0,0 @@-const Tween: Record<string, Function> = {- 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 {- 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) => {- 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();- }- };- }- });- }-- 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);- }-- 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();- });- }-}diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts b/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.tsdeleted file mode 100644index 9c9ba345d1..0000000000--- a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideScrollbar.ts+++ /dev/null@@ -1,29 +0,0 @@-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/Controller/RightMenuUIController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.tsindex 070320503e..3ea1bd7c01 100644--- a/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuUIController.ts@@ -1,7 +1,6 @@import { IMouseEvent, IPointerEvent } from '@univerjs/base-render';import { CanvasView } from '@univerjs/base-sheets';-import { BaseMenuItem, ComponentManager, ICustomLabelType, IMenuService, MenuPosition } from '@univerjs/base-ui';-import { IMenuItemFactory } from '@univerjs/base-ui/src/services/menu/menu';+import { BaseMenuItem, ComponentManager, ICustomLabelType, IMenuItemFactory, IMenuService, MenuPosition } from '@univerjs/base-ui';import { Disposable } from '@univerjs/core';import { Inject, Injector } from '@wendellhu/redi';import { ComponentChildren } from 'preact';diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarUIController.tssimilarity index 57%rename from packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.tsrename to packages/ui-plugin-sheets/src/Controller/SheetBarUIController.tsindex b277d49996..6e625c36eb 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetBarUIContruller.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarUIController.ts@@ -1,11 +1,25 @@-import { InsertSheetMutation, RemoveSheetMutation, SetWorksheetActivateCommand, SetWorksheetOrderCommand } from '@univerjs/base-sheets';-import { BaseMenuItem, BaseUlProps, ColorPicker, ComponentManager, ICustomComponent, IMenuService } from '@univerjs/base-ui';-import { Disposable, ICommandService, ICurrentUniverService, Nullable, ObserverManager, UIObserver } from '@univerjs/core';+import {+ InsertSheetMutation,+ RemoveSheetMutation,+ SetTabColorMutation,+ SetWorksheetActivateCommand,+ SetWorksheetActivateMutation,+ SetWorksheetHideMutation,+ SetWorksheetNameCommand,+ SetWorksheetNameMutation,+ SetWorksheetOrderCommand,+ SetWorksheetOrderMutation,+ SetWorksheetShowCommand,+} from '@univerjs/base-sheets';+import { BaseMenuItem, BaseUlProps, ColorPicker, ComponentManager, ICustomComponent, IMenuItemFactory, IMenuService } from '@univerjs/base-ui';+import { Disposable, ICommandService, ICurrentUniverService, IKeyValue, IWorksheetConfig, Nullable, ObserverManager, UIObserver } from '@univerjs/core';import { Inject, Injector, SkipSelf } from '@wendellhu/redi';import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const';+import { RenameSheetCommand } from '../commands/rename.command';+import { ShowMenuListCommand } from '../commands/unhide.command';import { SheetBar } from '../View/SheetBar';-import styles from '../View/SheetBar/index.module.less';+import { ISheetBarMenuItem } from '../View/SheetBar/SheetBarMenu';import {ChangeColorSheetMenuItemFactory,@@ -30,8 +44,6 @@ export interface SheetUlProps extends BaseUlProps {export class SheetBarUIController extends Disposable {protected _sheetBar: SheetBar;- protected _sheetUl: SheetUl[];-protected _dataId: string;protected _sheetIndex: number;@@ -50,64 +62,6 @@ export class SheetBarUIController extends Disposable {@IMenuService private readonly _menuService: IMenuService) {super();- const that = this;- this._sheetUl = [- {- label: 'sheetConfig.delete',- onClick: () => {- that.setUIObserve('onUIChangeObservable', { name: 'deleteSheet', value: this._dataId });- },- },- {- label: 'sheetConfig.copy',- onClick: () => {- that.setUIObserve('onUIChangeObservable', { name: 'copySheet' });- },- },- {- label: 'sheetConfig.rename',- onClick: () => {- this._sheetBar.reNameSheet(this._dataId);- },- },- {- label: 'sheetConfig.changeColor',- border: true,- className: styles.selectColorPickerParent,- children: [- {- label: {- name: SHEET_UI_PLUGIN_NAME + ColorPicker.name,- props: {- onClick: (color: string) => {- this.setUIObserve('onUIChangeObservable', {- name: 'changeSheetColor',- value: {- color,- sheetId: this._dataId,- },- });- },- },- },- className: styles.selectColorPicker,- },- ],- },- {- label: 'sheetConfig.hide',- onClick: () => {- that.setUIObserve('onUIChangeObservable', { name: 'hideSheet', value: this._dataId });- },- },- {- label: 'sheetConfig.unhide',- onClick: () => {- this._sheetBar.ref.current.showMenu(true);- that.setUIObserve('onUIChangeObservable', { name: 'unHideSheet', value: this._dataId });- },- },- ];this._initializeContextMenu();@@ -116,13 +70,50 @@ export class SheetBarUIController extends Disposable {this.disposeWithMe(this._commandService.onCommandExecuted((params) => {const { id } = params;+ let worksheetId;+ if (params.params) {+ const mutationParams: IKeyValue = params.params;+ worksheetId = mutationParams.worksheetId;+ }switch (id) {- case InsertSheetMutation.id:+ case SetTabColorMutation.id:+ this._refreshComponent();++ break;+ case SetWorksheetHideMutation.id:+ this._refreshComponent();++ this.setMenuListHide(worksheetId);++ break;case RemoveSheetMutation.id:- // update data;- this._refreshSheetData();- // set ui bar sheetList;- this._refreshSheetBarUI();+ this._refreshComponent();++ this.setMenuListDelete(worksheetId);++ break;+ case SetWorksheetNameMutation.id:+ this._refreshComponent();++ this.setMenuListLabel(worksheetId, (params?.params as IKeyValue).name);++ break;+ case InsertSheetMutation.id:+ this._refreshComponent();++ this.setMenuListInsert((params?.params as IKeyValue).index, (params?.params as IKeyValue).sheet, (params?.params as IKeyValue).workbookId);+ // Usually after the insert sheet operation, the activation operation is triggered. If it is placed after activate mutation, it will affect double-click+ this._sheetBar.setSlideTabActive((params?.params as IKeyValue).sheet.id);++ break;+ case SetWorksheetOrderMutation.id:+ this._refreshComponent();++ this.setMenuListOrder();++ break;+ case SetWorksheetActivateMutation.id:+ this.setMenuListSelect(worksheetId);break;@@ -133,6 +124,8 @@ export class SheetBarUIController extends Disposable {);this._componentManager.register(SHEET_UI_PLUGIN_NAME + ColorPicker.name, ColorPicker);++ [ShowMenuListCommand, RenameSheetCommand].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));}getComponent = (ref: SheetBar) => {@@ -160,7 +153,11 @@ export class SheetBarUIController extends Disposable {return this._menuList;}- selectSheet() {}+ selectSheet = (sheetIndex: number) => {+ const worksheetId = this._sheetList.find((sheet) => sheet.index === String(sheetIndex))?.sheetId;+ if (!worksheetId) return;+ this._commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId });+ };deleteSheet() {}@@ -189,14 +186,8 @@ export class SheetBarUIController extends Disposable {moveSheet(direct: string) {}- changeSheetName = (event: Event) => {- this.setUIObserve('onUIChangeObservable', {- name: 'renameSheet',- value: {- sheetId: this._dataId,- sheetName: (event.target as HTMLElement).innerText,- },- });+ changeSheetName = (worksheetId: string, name: string) => {+ this._commandService.executeCommand(SetWorksheetNameCommand.id, { name, worksheetId });};contextMenu(e: MouseEvent) {@@ -224,10 +215,57 @@ export class SheetBarUIController extends Disposable {});};+ showMenuList(show: boolean) {+ this._sheetBar.showMenuList(show);+ }++ setMenuListSelect(worksheetId: string) {+ this._sheetBar.ref.current.selectItem(worksheetId);+ }++ setMenuListHide(worksheetId: string) {+ this._sheetBar.ref.current.hideItem(worksheetId);+ }++ setMenuListDelete(worksheetId: string) {+ this._sheetBar.ref.current.deleteItem(worksheetId);+ }++ setMenuListLabel(worksheetId: string, label: string) {+ this._sheetBar.ref.current.setItemLabel(worksheetId, label);+ }++ setMenuListInsert(index: number, sheet: IWorksheetConfig, workbookId: string) {+ const item = {+ label: sheet.name,+ index: String(index),+ sheetId: sheet.id,+ hide: sheet.hidden === 1,+ selected: sheet.status === 1,+ onClick: (e?: MouseEvent) => {+ if (e) {+ const target = e.currentTarget as HTMLDivElement;+ this._dataId = target.dataset.id as string;+ const worksheetId = sheet.id;+ this._commandService.executeCommand(SetWorksheetShowCommand.id, {+ workbookId,+ worksheetId,+ });+ // update tab item+ this._sheetBar.setSlideTabActive(worksheetId);+ }+ },+ };+ this._sheetBar.ref.current.insertItem(index, item);+ }++ setMenuListOrder() {+ this._sheetBar.ref.current.setItemOrder(this._menuList);+ }+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;@@ -246,10 +284,10 @@ export class SheetBarUIController extends Disposable {this._dataId = target.dataset.id as string;//this._barControl.contextMenu(e);},- changeSheetName: (event: Event) => {},- dragEnd: (elements: HTMLDivElement[]) => {- //this._barControl.dragEnd(elements);- },+ // changeSheetName: (event: Event) => {},+ // dragEnd: (elements: HTMLDivElement[]) => {+ // //this._barControl.dragEnd(elements);+ // },});// this._sheetBar.setSheetUlNeo(this._menuService.getMenuItems(MenuPosition.SHEET_BAR));@@ -269,12 +307,19 @@ export class SheetBarUIController extends Disposable {if (e) {const target = e.currentTarget as HTMLDivElement;this._dataId = target.dataset.id as string;- sheet.showSheet();- // sheet.activate();- this._commandService.executeCommand(SetWorksheetActivateCommand.id, {+ const worksheetId = sheet.getSheetId();+ // command+ // this._commandService.executeCommand(SetWorksheetActivateCommand.id, {+ // workbookId: workbook.getUnitId(),+ // worksheetId,+ // });+ this._commandService.executeCommand(SetWorksheetShowCommand.id, {workbookId: workbook.getUnitId(),- worksheetId: sheet.getSheetId(),+ worksheetId,});++ // update tab item+ this._sheetBar.setSlideTabActive(worksheetId);}},}));@@ -287,19 +332,10 @@ export class SheetBarUIController extends Disposable {index: String(index),selected: sheet.getStatus() === 1,color: sheet.getTabColor() as string,- onDown: (e: MouseEvent) => {+ onMouseDown: (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._commandService.executeCommand(SetWorksheetActivateCommand.id, {- workbookId: workbook.getUnitId(),- worksheetId: sheet.getSheetId(),- });- },}));this._sheetIndex = sheets.findIndex((sheet) => sheet.getStatus() === 1);if (this._sheetIndex > -1) {@@ -313,14 +349,16 @@ export class SheetBarUIController extends Disposable {}private _initializeContextMenu() {- [- DeleteSheetMenuItemFactory,- CopySheetMenuItemFactory,- RenameSheetMenuItemFactory,- ChangeColorSheetMenuItemFactory,- HideSheetMenuItemFactory,- UnHideSheetMenuItemFactory,- ].forEach((factory) => {+ (+ [+ DeleteSheetMenuItemFactory,+ CopySheetMenuItemFactory,+ RenameSheetMenuItemFactory,+ ChangeColorSheetMenuItemFactory,+ HideSheetMenuItemFactory,+ UnHideSheetMenuItemFactory,+ ] as IMenuItemFactory[]+ ).forEach((factory) => {this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));});}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex ca3ffbd5ce..586404d851 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -1,176 +1,176 @@-import { Inject, Injector, Self, SkipSelf } from '@wendellhu/redi';--import { ComponentManager, DragManager, getRefElement, Prompt, SlotManager } from '@univerjs/base-ui';-import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';--import { ISheetUIPluginConfig } from '../Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig';-import { SheetContainer } from '../View';-import { CellEditorUIController } from './CellEditorUIController';-import { CountBarUIController } from './CountBarUIController';-import { FormulaBarUIController } from './FormulaBarUIController';-import { InfoBarUIController } from './InfoBarUIController';-import { RightMenuUIController } from './RightMenuUIController';-import { SheetBarUIController } from './SheetBarUIContruller';-import { SlotController } from './SlotController';-import { ToolbarUIController } from './ToolbarUIController';--// NOTE: is this class necessary? Could be merged to AppUIConrainer-export class SheetContainerUIController {- private _sheetContainer: SheetContainer;-- private _toolbarController: ToolbarUIController;-- private _slotController: SlotController;-- // private _slotManager: SlotManager;-- private _cellEditorUIController: CellEditorUIController;-- private _formulaBarUIController: FormulaBarUIController;-- private _infoBarController: InfoBarUIController;-- private _rightMenuController: RightMenuUIController;-- private _countBarController: CountBarUIController;-- private _sheetBarController: SheetBarUIController;-- private _config: ISheetUIPluginConfig;-- constructor(- config: ISheetUIPluginConfig,- @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,- @Inject(LocaleService) private readonly _localeService: LocaleService,- @Self() @Inject(ObserverManager) private readonly _observerManager: ObserverManager,- @Inject(Injector) private readonly _injector: Injector,- @Inject(ComponentManager) private readonly _componentManager: ComponentManager,- @Inject(SlotManager) private readonly _slotManager: SlotManager,- @Inject(DragManager) private readonly _dragManager: DragManager- ) {- this._config = config;-- this._slotController = new SlotController();- // this._slotManager = new SlotManager();- this._toolbarController = this._injector.createInstance(ToolbarUIController, this._config.layout?.toolbarConfig);- this._cellEditorUIController = this._injector.createInstance(CellEditorUIController, () => this.getContentRef());- this._formulaBarUIController = this._injector.createInstance(FormulaBarUIController);- this._infoBarController = this._injector.createInstance(InfoBarUIController);- this._rightMenuController = this._injector.createInstance(RightMenuUIController, this._config.layout?.rightMenuConfig);- this._countBarController = this._injector.createInstance(CountBarUIController);- this._sheetBarController = this._injector.createInstance(SheetBarUIController);- // this._dragManager = this._injector.createInstance(DragManager);-- // 插入prompt组件- this._componentManager.register(Prompt.name, Prompt);- this._slotManager.setSlotComponent('main', {- name: Prompt.name,- component: {- name: Prompt.name,- },- });- }-- getUIConfig() {- const config = {- injector: this._injector,- config: this._config,- changeLocale: this.changeLocale,- getComponent: this.getComponent,- // 其余组件的props- methods: {- toolbar: {- getComponent: this._toolbarController.getComponent,- },- cellEditor: {- getComponent: this._cellEditorUIController.getComponent,- },- formulaBar: {- getComponent: this._formulaBarUIController.getComponent,- },- infoBar: {- getComponent: this._infoBarController.getComponent,- // renameSheet: this._infoBarController.renameSheet,- },- rightMenu: {- getComponent: this._rightMenuController.getComponent,- },- countBar: {- getComponent: this._countBarController.getComponent,- onChange: this._countBarController.onChange,- },- sheetBar: {- getComponent: this._sheetBarController.getComponent,- addSheet: this._sheetBarController.addSheet,- selectSheet: this._sheetBarController.selectSheet,- dragEnd: this._sheetBarController.dragEnd,- changeSheetName: this._sheetBarController.changeSheetName,- },- slot: {- // getComponent: this._slotController.getComponent,- getComponent: this._slotManager.getComponent,- },- },- };- return config;- }-- // 获取SheetContainer组件- getComponent = (ref: SheetContainer) => {- this._sheetContainer = ref;-- this._observerManager.getObserver<SheetContainer>('onUIDidMount')?.notifyObservers(this._sheetContainer);- this._globalObserverManager.requiredObserver<boolean>('onUIDidMountObservable', 'core').notifyObservers(true);-- this.setSheetContainer();- };-- /**- * Change language- * @param {String} lang new language- *- * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771- *- */- changeLocale = (locale: string) => {- this._localeService.getLocale().change(locale as LocaleType);-- // publish- this._globalObserverManager.requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();- };-- getContentRef() {- return this._sheetContainer.getContentRef();- }-- getCellEditorUIController() {- return this._cellEditorUIController;- }-- getFormulaBarUIController() {- return this._formulaBarUIController;- }-- getMainSlotController() {- return this._slotController;- }-- getSlotManager() {- return this._slotManager;- }-- getToolbarController() {- return this._toolbarController;- }-- UIDidMount(cb: Function) {- if (this._sheetContainer) return cb(this._sheetContainer);-- this._observerManager.getObserver('onUIDidMount')?.add(() => cb(this._sheetContainer));- }-- private setSheetContainer() {- // handle drag event- this._dragManager.handleDragAction(getRefElement(this._sheetContainer));- }-}+import { ComponentManager, DragManager, getRefElement, Prompt, SlotManager } from '@univerjs/base-ui';+import { LocaleService, LocaleType, ObserverManager } from '@univerjs/core';+import { Inject, Injector, Self, SkipSelf } from '@wendellhu/redi';++import { ISheetUIPluginConfig } from '../Basics/Interfaces/ComponentConfig/ISheetUIPluginConfig';+import { SheetContainer } from '../View';+import { CellEditorUIController } from './CellEditorUIController';+import { CountBarUIController } from './CountBarUIController';+import { FormulaBarUIController } from './FormulaBarUIController';+import { InfoBarUIController } from './InfoBarUIController';+import { RightMenuUIController } from './RightMenuUIController';+import { SheetBarUIController } from './SheetBarUIController';+import { SlotController } from './SlotController';+import { ToolbarUIController } from './ToolbarUIController';++// NOTE: is this class necessary? Could be merged to AppUIConrainer+export class SheetContainerUIController {+ private _sheetContainer: SheetContainer;++ private _toolbarController: ToolbarUIController;++ private _slotController: SlotController;++ // private _slotManager: SlotManager;++ private _cellEditorUIController: CellEditorUIController;++ private _formulaBarUIController: FormulaBarUIController;++ private _infoBarController: InfoBarUIController;++ private _rightMenuController: RightMenuUIController;++ private _countBarController: CountBarUIController;++ private _sheetBarController: SheetBarUIController;++ private _config: ISheetUIPluginConfig;++ constructor(+ config: ISheetUIPluginConfig,+ @SkipSelf() @Inject(ObserverManager) private readonly _globalObserverManager: ObserverManager,+ @Inject(LocaleService) private readonly _localeService: LocaleService,+ @Self() @Inject(ObserverManager) private readonly _observerManager: ObserverManager,+ @Inject(Injector) private readonly _injector: Injector,+ @Inject(ComponentManager) private readonly _componentManager: ComponentManager,+ @Inject(SlotManager) private readonly _slotManager: SlotManager,+ @Inject(DragManager) private readonly _dragManager: DragManager+ ) {+ this._config = config;++ this._slotController = new SlotController();+ // this._slotManager = new SlotManager();+ this._toolbarController = this._injector.createInstance(ToolbarUIController, this._config.layout?.toolbarConfig);+ this._cellEditorUIController = this._injector.createInstance(CellEditorUIController, () => this.getContentRef());+ this._formulaBarUIController = this._injector.createInstance(FormulaBarUIController);+ this._infoBarController = this._injector.createInstance(InfoBarUIController);+ this._rightMenuController = this._injector.createInstance(RightMenuUIController, this._config.layout?.rightMenuConfig);+ this._countBarController = this._injector.createInstance(CountBarUIController);+ this._sheetBarController = this._injector.createInstance(SheetBarUIController);+ this._injector.add([SheetBarUIController, { useFactory: () => this._sheetBarController }]);+ // this._dragManager = this._injector.createInstance(DragManager);++ // 插入prompt组件+ this._componentManager.register(Prompt.name, Prompt);+ this._slotManager.setSlotComponent('main', {+ name: Prompt.name,+ component: {+ name: Prompt.name,+ },+ });+ }++ getUIConfig() {+ const config = {+ injector: this._injector,+ config: this._config,+ changeLocale: this.changeLocale,+ getComponent: this.getComponent,+ // 其余组件的props+ methods: {+ toolbar: {+ getComponent: this._toolbarController.getComponent,+ },+ cellEditor: {+ getComponent: this._cellEditorUIController.getComponent,+ },+ formulaBar: {+ getComponent: this._formulaBarUIController.getComponent,+ },+ infoBar: {+ getComponent: this._infoBarController.getComponent,+ // renameSheet: this._infoBarController.renameSheet,+ },+ rightMenu: {+ getComponent: this._rightMenuController.getComponent,+ },+ countBar: {+ getComponent: this._countBarController.getComponent,+ onChange: this._countBarController.onChange,+ },+ sheetBar: {+ getComponent: this._sheetBarController.getComponent,+ addSheet: this._sheetBarController.addSheet,+ selectSheet: this._sheetBarController.selectSheet,+ dragEnd: this._sheetBarController.dragEnd,+ changeSheetName: this._sheetBarController.changeSheetName,+ },+ slot: {+ // getComponent: this._slotController.getComponent,+ getComponent: this._slotManager.getComponent,+ },+ },+ };+ return config;+ }++ // 获取SheetContainer组件+ getComponent = (ref: SheetContainer) => {+ this._sheetContainer = ref;++ this._observerManager.getObserver<SheetContainer>('onUIDidMount')?.notifyObservers(this._sheetContainer);+ this._globalObserverManager.requiredObserver<boolean>('onUIDidMountObservable', 'core').notifyObservers(true);++ this.setSheetContainer();+ };++ /**+ * Change language+ * @param {String} lang new language+ *+ * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771+ *+ */+ changeLocale = (locale: string) => {+ this._localeService.getLocale().change(locale as LocaleType);++ // publish+ this._globalObserverManager.requiredObserver('onAfterChangeUILocaleObservable', 'core')!.notifyObservers();+ };++ getContentRef() {+ return this._sheetContainer.getContentRef();+ }++ getCellEditorUIController() {+ return this._cellEditorUIController;+ }++ getFormulaBarUIController() {+ return this._formulaBarUIController;+ }++ getMainSlotController() {+ return this._slotController;+ }++ getSlotManager() {+ return this._slotManager;+ }++ getToolbarController() {+ return this._toolbarController;+ }++ UIDidMount(cb: Function) {+ if (this._sheetContainer) return cb(this._sheetContainer);++ this._observerManager.getObserver('onUIDidMount')?.add(() => cb(this._sheetContainer));+ }++ private setSheetContainer() {+ // handle drag event+ this._dragManager.handleDragAction(getRefElement(this._sheetContainer));+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/menu.ts b/packages/ui-plugin-sheets/src/Controller/menu.tsindex 7a79ba3dbc..14427d8135 100644--- a/packages/ui-plugin-sheets/src/Controller/menu.ts+++ b/packages/ui-plugin-sheets/src/Controller/menu.ts@@ -3,8 +3,8 @@ import {CopySheetCommand,DeleteRangeMoveLeftCommand,DeleteRangeMoveUpCommand,- InsertColCommand,- InsertRowCommand,+ InsertColAfterCommand,+ InsertRowAfterCommand,ISelectionManager,RemoveColCommand,RemoveRowCommand,@@ -31,9 +31,7 @@ import {SetWorksheetRowHeightCommand,SetWorksheetRowHideCommand,SetWorksheetRowShowCommand,- SetWorksheetShowCommand,} from '@univerjs/base-sheets';-import { ISetHorizontalTextAlignCommandParams, ISetTextWrapCommandParams, ISetVerticalTextAlignCommandParams } from '@univerjs/base-sheets/src/Commands/Commands/set-style.command';import { ColorPicker, DisplayTypes, IMenuButtonItem, IMenuSelectorItem, MenuItemType, MenuPosition, SelectTypes } from '@univerjs/base-ui';import {FontItalic,@@ -52,6 +50,8 @@ import { Observable } from 'rxjs';import { map } from 'rxjs/operators';import { SHEET_UI_PLUGIN_NAME } from '../Basics/Const/PLUGIN_NAME';+import { RenameSheetCommand } from '../commands/rename.command';+import { ShowMenuListCommand } from '../commands/unhide.command';import { RightMenuInput } from '../View';import { FONT_FAMILY_CHILDREN, FONT_SIZE_CHILDREN, HORIZONTAL_ALIGN_CHILDREN, TEXT_ROTATE_CHILDREN, TEXT_WRAP_CHILDREN, VERTICAL_ALIGN_CHILDREN } from '../View/Toolbar/Const';@@ -469,6 +469,7 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMe// }export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<HorizontalAlign> {+ const selectionManager = accessor.get(ISelectionManager);return {id: SetHorizontalTextAlignCommand.id,title: 'horizontalAlignMode',@@ -481,10 +482,15 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectselections: HORIZONTAL_ALIGN_CHILDREN,value$: new Observable<HorizontalAlign>((subscriber) => {const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {- if (c.id === SetHorizontalTextAlignCommand.id) {- const align = (c.params as ISetHorizontalTextAlignCommandParams).value;- subscriber.next(align);+ const id = c.id;+ if (id !== SetHorizontalTextAlignCommand.id && id !== SetSelectionsOperation.id) {+ return;}++ const range = selectionManager.getCurrentCell();+ const ha = range?.getHorizontalAlignment();++ subscriber.next(ha ?? HorizontalAlign.LEFT);});subscriber.next(HorizontalAlign.LEFT);@@ -495,6 +501,7 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelect}export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<VerticalAlign> {+ const selectionManager = accessor.get(ISelectionManager);return {id: SetVerticalTextAlignCommand.id,title: 'verticalAlignMode',@@ -507,10 +514,15 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorselections: VERTICAL_ALIGN_CHILDREN,value$: new Observable<VerticalAlign>((subscriber) => {const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {- if (c.id === SetVerticalTextAlignCommand.id) {- const align = (c.params as ISetVerticalTextAlignCommandParams).value;- subscriber.next(align);+ const id = c.id;+ if (id !== SetVerticalTextAlignCommand.id && id !== SetSelectionsOperation.id) {+ return;}++ const range = selectionManager.getCurrentCell();+ const va = range?.getVerticalAlignment();++ subscriber.next(va ?? VerticalAlign.TOP);});subscriber.next(VerticalAlign.TOP);@@ -521,6 +533,7 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelector}export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<WrapStrategy> {+ const selectionManager = accessor.get(ISelectionManager);return {id: SetTextWrapCommand.id,title: 'textWrapMode',@@ -533,10 +546,15 @@ export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<display: DisplayTypes.ICON,value$: new Observable((subscriber) => {const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {- if (c.id === SetTextWrapCommand.id) {- const wrap = (c.params as ISetTextWrapCommandParams).value;- subscriber.next(wrap ?? WrapStrategy.OVERFLOW);+ const id = c.id;+ if (id !== SetTextWrapCommand.id && id !== SetSelectionsOperation.id) {+ return;}++ const range = selectionManager.getCurrentCell();+ const ws = range?.getWrapStrategy();++ subscriber.next(ws ?? WrapStrategy.OVERFLOW);});subscriber.next(WrapStrategy.OVERFLOW);@@ -547,6 +565,7 @@ export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<}export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number | string> {+ const selectionManager = accessor.get(ISelectionManager);return {id: SetTextRotationCommand.id,title: 'textRotateMode',@@ -559,10 +578,15 @@ export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItepositions: [MenuPosition.TOOLBAR],value$: new Observable<number | string>((subscriber) => {const disposable = accessor.get(ICommandService).onCommandExecuted((c) => {- if (c.id === SetTextRotationCommand.id) {- const rotation = (c.params as { value: number | string }).value;- subscriber.next(rotation ?? 0);+ const id = c.id;+ if (id !== SetTextRotationCommand.id && id !== SetSelectionsOperation.id) {+ return;}++ const range = selectionManager.getCurrentCell();+ const tr = range?.getTextRotation();++ subscriber.next((tr && tr.a) ?? 0);});subscriber.next(0);@@ -583,7 +607,7 @@ export function ClearSelectionMenuItemFactory(accessor: IAccessor): IMenuButtonIexport function InsertRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: InsertRowCommand.id,+ id: InsertRowAfterCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.insertRow',@@ -592,7 +616,7 @@ export function InsertRowMenuItemFactory(accessor: IAccessor): IMenuButtonItem {export function InsertColMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: InsertColCommand.id,+ id: InsertColAfterCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.CONTEXT_MENU],title: 'rightClick.insertColumn',@@ -752,7 +776,6 @@ export function DeleteSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItemexport function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- // TODO@Dushusir use real command idid: CopySheetCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],@@ -760,23 +783,15 @@ export function CopySheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {};}-// TODO@Dushusir onClick to rename tab-// No need to trigger command after clicking,maybe no need Command id?export function RenameSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: 'RenameSheetCommand.id',+ id: RenameSheetCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],title: 'sheetConfig.rename',- onClick: () => {- // TODO@Dushusir 这里能监听到点击事件,但是无法触发到 this._sheetBar.reNameSheet(this._dataId);- // 或许不应该通过这里的onClick直接更新UI?- console.info('rename=========');- },};}-// TODO@Dushusir add commandexport function ChangeColorSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {return {id: SetTabColorCommand.id,@@ -802,10 +817,9 @@ export function HideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {};}-// TODO@Dushusir use show worksheet commandexport function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {- id: SetWorksheetShowCommand.id,+ id: ShowMenuListCommand.id,type: MenuItemType.BUTTON,positions: [MenuPosition.SHEET_BAR],title: 'sheetConfig.unhide',diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsindex e322575091..d7ee4bec36 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.ts+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.ts@@ -1,28 +1,30 @@-import { Dependency, Inject, Injector } from '@wendellhu/redi';-import { Plugin, Tools, PluginType, LocaleService, IUndoRedoService } from '@univerjs/core';+import { IRenderingEngine } from '@univerjs/base-render';import {ComponentManager,+ DesktopMenuService,+ DesktopPlatformService,+ DesktopShortcutService,+ DragManager,getRefElement,+ IMenuService,+ IPlatformService,+ IShortcutService,KeyboardManager,+ SharedController,SlotComponent,- ZIndexManager,SlotManager,- DragManager,- IShortcutService,- DesktopShortcutService,- SharedController,- IPlatformService,- DesktopPlatformService,- IMenuService,- DesktopMenuService,+ ZIndexManager,} from '@univerjs/base-ui';-import { IRenderingEngine } from '@univerjs/base-render';-import { DefaultSheetUIConfig, installObserver, ISheetUIPluginConfig, SheetUIPluginObserve, SHEET_UI_PLUGIN_NAME } from './Basics';+import { IUndoRedoService, LocaleService, Plugin, PluginType, Tools } from '@univerjs/core';+import { Dependency, Inject, Injector } from '@wendellhu/redi';++import { DefaultSheetUIConfig, installObserver, ISheetUIPluginConfig, SHEET_UI_PLUGIN_NAME, SheetUIPluginObserve } from './Basics';import { AppUIController } from './Controller/AppUIController';-import { Fx } from './View/FormulaBar';-import { SlotComponentProps } from './Controller/SlotController';-import { zh, en } from './Locale';import { DesktopSheetShortcutController } from './Controller/shortcut.controller';+import { SlotComponentProps } from './Controller/SlotController';+import { en, zh } from './Locale';+import { SheetBarService } from './services/sheet-bar.service';+import { Fx } from './View/FormulaBar';export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {static override type = PluginType.Sheet;@@ -156,6 +158,7 @@ export class SheetUIPlugin extends Plugin<SheetUIPluginObserve> {[SharedController],[IMenuService, { useClass: DesktopMenuService }],[DesktopSheetShortcutController],+ [SheetBarService],];dependencies.forEach((d) => this._injector.add(d));diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsxindex c62277fe3f..48b8871607 100644--- a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx@@ -13,7 +13,7 @@ export class RightMenuInput extends Component<IProps> {render() {const { prefix, suffix, value } = this.props;return (- <div onClick={(e) => this.handleClick(e)}>+ <div><CustomLabel label={prefix} /><Input type="number" placeholder="1" value={value} onClick={(e) => e.stopPropagation()} onChange={this.onChange.bind(this)}></Input><CustomLabel label={suffix} />@@ -21,12 +21,13 @@ export class RightMenuInput extends Component<IProps> {);}- private handleClick(e: Event) {- e.stopPropagation();- this.props.onChange?.(this.value);- }+ // private handleClick(e: Event) {+ // e.stopPropagation();+ // this.props.onChange?.(this.value);+ // }private onChange(e: Event) {- this.value = (e.target as HTMLInputElement).value;+ const value = (e.target as HTMLInputElement).value;+ this.props.onChange(value);}}diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsxindex 98b2b30dc3..054e5a8765 100644--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx@@ -1,9 +1,11 @@-import { BaseMenuItem, BaseSheetBarProps, Button, CustomLabel, Icon, IDisplayMenuItem, IMenuItem, Menu, MenuPosition } from '@univerjs/base-ui';+import { SetWorksheetActivateCommand } from '@univerjs/base-sheets';+import { AppContext, BaseMenuItem, BaseSheetBarProps, Button, CustomLabel, Icon, IDisplayMenuItem, IMenuItem, Menu, MenuPosition } from '@univerjs/base-ui';+import { ICommandService } from '@univerjs/core';import { Component, createRef, RefObject } from 'preact';-import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';import styles from './index.module.less';import { ISheetBarMenuItem, SheetBarMenu } from './SheetBarMenu';+import { SlideTabBar } from './SlideTabBar/SlideTabBar';type SheetState = {sheetList: BaseSheetBarProps[];@@ -13,6 +15,8 @@ type SheetState = {};export class SheetBar extends Component<BaseSheetBarProps, SheetState> {+ static override contextType = AppContext;+ref = createRef();ulRef = createRef();@@ -76,10 +80,39 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {overGrid = () => {};- // 右击显示菜单+ // Right click to display menucontextMenu = (e: MouseEvent) => {e.preventDefault();- this.showUlList(e);+ const target = e.currentTarget as HTMLDivElement;+ const worksheetId = target.dataset.id as string;++ // after show ul,activate DOM+ this.showUlList(e, () => {+ this.setSlideTabActive(worksheetId);+ });++ // activate command+ const commandService: ICommandService = this.context.injector.get(ICommandService);+ commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId });+ };++ // Click the button to display the menu, if it is not in the current sheet, only switch the sheet after clicking+ onContextMenuClick = (e: MouseEvent) => {+ e.preventDefault();++ const target = e.currentTarget as HTMLDivElement;+ const worksheetId = target.dataset.id as string;++ const currentSheetId = this.getCurrentSheetId();++ if (worksheetId === currentSheetId) {+ this.showUlList(e);+ } else {+ this.setSlideTabActive(worksheetId);+ // activate command+ const commandService: ICommandService = this.context.injector.get(ICommandService);+ commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId });+ }};// 显示下拉@@ -99,7 +132,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {};// 点击不同sheet页显示ullist- showUlList = (e: MouseEvent) => {+ showUlList = (e: MouseEvent, cb?: () => void) => {new Promise<void>((resolve) => {const target = e.currentTarget as HTMLDivElement;const id = target.dataset.id as string;@@ -116,6 +149,8 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {ul.style.bottom = bottom;ul.style.top = 'auto';ul.style.right = 'auto';++ cb && cb();}});};@@ -128,20 +163,21 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {}};- changeEditable = (e: MouseEvent) => {- const target = e.target as HTMLDivElement;- let listener: (event: Event) => void;- target.contentEditable = 'true';- target.focus();- target.addEventListener(- 'blur',- (listener = (event) => {- this.props.changeSheetName?.(e);- target.contentEditable = 'false';- target.removeEventListener('blur', listener);- })- );- };+ // no need+ // changeEditable = (e: MouseEvent) => {+ // const target = e.target as HTMLDivElement;+ // let listener: (event: Event) => void;+ // target.contentEditable = 'true';+ // target.focus();+ // target.addEventListener(+ // 'blur',+ // (listener = (event) => {+ // this.props.changeSheetName?.(e);+ // target.contentEditable = 'false';+ // target.removeEventListener('blur', listener);+ // })+ // );+ // };override componentDidUpdate() {if (this.slideTabBar) {@@ -153,12 +189,16 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {slideTabBarItemClassName: 'univer-slide-tab-item',slideTabBarItemAutoSort: true,slideTabRoot: this.slideTabRoot.current,- onChangeName: (event: Event) => {- this.props.changeSheetName?.(event);+ activeClassNameAutoController: true,+ onChangeName: (sheetId: string, name: string) => {+ this.props.changeSheetName?.(sheetId, name);},onSlideEnd: (event: Event) => {this.props.dragEnd?.(this.slideTabBar.getSlideTabItems().map((item) => item.primeval()));},+ onItemClick: (slideItemIndex: number) => {+ this.props.selectSheet?.(slideItemIndex);+ },});}@@ -166,6 +206,35 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {this.props.getComponent?.(this);}+ // Convenient for controller to control sheetBarMenu+ showMenuList(show: boolean) {+ this.ref.current.showMenu(show);+ }++ setSlideTabActive(sheetId: string, cb?: () => void) {+ this.setState((prevState, props) => {+ const prevSheetList = prevState.sheetList;+ const currentSheetList = prevSheetList.map((sheet) => {+ if (sheet.sheetId === sheetId) {+ sheet.selected = true;+ } else {+ sheet.selected = false;+ }+ return sheet;+ });+ return {+ ...prevState,+ sheetList: currentSheetList,+ };+ }, cb);+ }++ getCurrentSheetId() {+ const sheetList = this.state.sheetList;+ const currentSheet = sheetList.find((sheet) => sheet.selected);+ return currentSheet?.sheetId;+ }+render(props: BaseSheetBarProps, state: SheetState) {const { sheetList, menuList, sheetUl } = state;const { addSheet, selectSheet } = this.props;@@ -189,8 +258,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {<div className={styles.slideTabBar} ref={this.sheetContainerRef}>{sheetList.map((item) => (<div- onMouseDown={item.onDown}- onClick={item.onClick}+ onMouseDown={item.onMouseDown}onContextMenu={this.contextMenu}data-id={item.sheetId}key={this._renderKey++}@@ -203,7 +271,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {<CustomLabel label={item.label} /></span></div>- <div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.contextMenu}>+ <div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.onContextMenuClick}><Icon.NextIcon /></div></div>diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsxindex 87bc63059c..4bfdcc3cb5 100644--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx@@ -1,5 +1,6 @@import { CustomLabel, Icon, joinClassNames } from '@univerjs/base-ui';import { Component } from 'preact';+import styles from './index.module.less';export interface ISheetBarMenuItem {@@ -19,6 +20,7 @@ export interface ISheetBarMenuProps {interface IState {show: boolean;+ menu: ISheetBarMenuItem[];}export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {@@ -28,8 +30,10 @@ export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {}initialize() {+ const { menu } = this.props;this.state = {show: false,+ menu,};}@@ -42,6 +46,7 @@ export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {onClick?.(e);this.showMenu(false);window.removeEventListener('click', this.hideMenu, true);+ this.selectItem(item.sheetId as string);}hideMenu = () => {@@ -54,9 +59,93 @@ export class SheetBarMenu extends Component<ISheetBarMenuProps, IState> {});}+ selectItem(sheetId: string) {+ this.setState((prevState, props) => {+ const menu = prevState.menu;+ const currenMenu = menu.map((sheet) => {+ if (sheet.sheetId === sheetId) {+ sheet.selected = true;+ sheet.hide = false;+ } else {+ sheet.selected = false;+ }++ return sheet;+ });+ return {+ ...prevState,+ menu: currenMenu,+ };+ });+ }++ hideItem(sheetId: string) {+ this.setState((prevState, props) => {+ const menu = prevState.menu;+ const currenMenu = menu.map((sheet) => {+ if (sheet.sheetId === sheetId) {+ sheet.hide = true;+ sheet.selected = false;+ }++ return sheet;+ });+ return {+ ...prevState,+ menu: currenMenu,+ };+ });+ }++ deleteItem(sheetId: string) {+ this.setState((prevState, props) => {+ const menu = prevState.menu;+ const currenMenu = menu.filter((item) => item.sheetId !== sheetId);+ return {+ ...prevState,+ menu: currenMenu,+ };+ });+ }++ setItemLabel(sheetId: string, label: string) {+ this.setState((prevState, props) => {+ const menu = prevState.menu;+ const currenMenu = menu.map((sheet) => {+ if (sheet.sheetId === sheetId) {+ sheet.label = label;+ }++ return sheet;+ });+ return {+ ...prevState,+ menu: currenMenu,+ };+ });+ }++ insertItem(index: number, item: ISheetBarMenuItem) {+ this.setState((prevState, props) => {+ const menu = prevState.menu;+ menu.splice(index, 1, item);+ return {+ ...prevState,+ menu,+ };+ });+ }++ setItemOrder(menu: ISheetBarMenuItem[]) {+ this.setState((prevState, props) => ({+ ...prevState,+ menu,+ }));+ }+render() {- const { menu, style } = this.props;- const { show } = this.state;+ const { style } = this.props;+ const { show, menu } = this.state;return (<ul className={styles.sheetBarMenu} style={{ ...style, display: show ? 'block' : ' none' }}>@@ -80,7 +169,7 @@ function EffIcon(props: { item: ISheetBarMenuItem }) {return <Icon.HideIcon />;}if (props.item.selected) {- return <Icon.Data.CheckIcon className={styles.sheetBarMenuSvg} />;+ return <Icon.Format.CorrectIcon className={styles.sheetBarMenuSvg} />;}return <></>;}diff --git a/packages/base-ui/src/Basics/SlideTabBar/Animate.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.tssimilarity index 100%rename from packages/base-ui/src/Basics/SlideTabBar/Animate.tsrename to packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/Animate.tsdiff --git a/packages/base-ui/src/Basics/SlideTabBar/SlideScrollbar.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideScrollbar.tssimilarity index 100%rename from packages/base-ui/src/Basics/SlideTabBar/SlideScrollbar.tsrename to packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideScrollbar.tsdiff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabBar.tssimilarity index 90%rename from packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.tsrename to packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabBar.tsindex a4068ed3f5..e8047cada9 100644--- a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabBar.ts+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabBar.ts@@ -9,7 +9,8 @@ export interface SlideTabBarConfig {activeClassNameAutoController: boolean;slideTabBarItemAutoSort: boolean;onSlideEnd: (event: MouseEvent) => void;- onChangeName: (event: FocusEvent) => void;+ onChangeName: (sheetId: string, name: string) => void;+ onItemClick: (slideItemIndex: number) => void;}export class SlideTabBar {@@ -68,6 +69,36 @@ export class SlideTabBar {this._slideScrollbar = new SlideScrollbar(this);this._slideTabItems = SlideTabItem.make(slideTabItems, this);+ this.initDownAction();+ this.initUpAction();+ this.initMoveAction();+ this.initWheelAction();++ 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();+ }+ });+ }++ initDownAction() {let lastPageX = 0;let lastPageY = 0;let lastTime = 0;@@ -118,6 +149,8 @@ export class SlideTabBar {item.classList().remove(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');});this._activeTabItem.classList().add(this._config.slideTabBarItemActiveClassName ?? 'slide-tab-active');+ // send current item index to sheet bar+ this._config.onItemClick && this._config.onItemClick(slideItemIndex);}this._activeTabItem.enableFixed();this._startAutoScroll();@@ -136,7 +169,9 @@ export class SlideTabBar {lastTime = current;}};+ }+ initUpAction() {this._upAction = (upEvent: MouseEvent) => {if (this._activeTabItem) {this._closeAutoScroll();@@ -149,7 +184,7 @@ export class SlideTabBar {}// fix bug- let event = new MouseEvent('click', {+ const event = new MouseEvent('click', {view: window,bubbles: true,cancelable: true,@@ -164,7 +199,9 @@ export class SlideTabBar {this._activeTabItem = null;}};+ }+ initMoveAction() {this._moveAction = (moveEvent) => {if (this._activeTabItem) {this._moveActionX = moveEvent.pageX - this._downActionX;@@ -173,7 +210,9 @@ export class SlideTabBar {this._scrollRight(moveEvent);}};+ }+ initWheelAction() {this._wheelAction = (wheelEvent: WheelEvent) => {if (wheelEvent.deltaY > 0) {this._slideScrollbar.scrollX(this._slideScrollbar.getScrollX() + wheelEvent.deltaY);@@ -181,29 +220,6 @@ export class SlideTabBar {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();- }- });}primeval(): HTMLElement {@@ -234,6 +250,16 @@ export class SlideTabBar {return this._slideTabItems;}+ setActiveItem(slideItemIndex: number) {+ this._compareIndex = slideItemIndex;+ this._activeTabItem = this._slideTabItems[slideItemIndex];+ this._activeTabItemIndex = slideItemIndex;+ this._slideTabItems.forEach((item) => {+ item.classList().remove('slide-tab-active');+ });+ this._activeTabItem.classList().add('slide-tab-active');+ }+destroy(): void {document.removeEventListener('mousemove', this._moveAction);document.removeEventListener('mouseup', this._upAction);@@ -319,8 +345,8 @@ export class SlideTabBar {// dom list sortif (this._config.slideTabBarItemAutoSort) {for (let i = 0; i < this._slideTabItems.length; i++) {- let item = this._slideTabItems[i];- let next = this._slideTabItems[i + 1];+ const item = this._slideTabItems[i];+ const next = this._slideTabItems[i + 1];if (next) {item.after(next);}@@ -331,9 +357,9 @@ export class SlideTabBar {protected _compareLeft(): void {if (this._activeTabItem && this._activeTabItemIndex) {- let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));- let length = this._slideTabItems.length;- let collect = [];+ const splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));+ const length = this._slideTabItems.length;+ const collect = [];// collect compare itemfor (let i = 0; i < splice; i++) {@@ -351,7 +377,7 @@ export class SlideTabBar {// diff item midlinelet notFound = true;for (let i = collect.length - 1; i >= 0; i--) {- let item = collect[i];+ const item = collect[i];if (SlideTabItem.midline(this._activeTabItem) < item.getMidLine()) {item.animate().translateX(this._activeTabItem.getWidth());this._compareIndex = i;@@ -368,9 +394,9 @@ export class SlideTabBar {protected _compareRight(): void {if (this._activeTabItem) {- let splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));- let length = this._slideTabItems.length;- let collect = [];+ const splice = this._slideTabItems.findIndex((item) => item.equals(this._activeTabItem));+ const length = this._slideTabItems.length;+ const collect = [];// collect compare itemfor (let i = splice + 1; i < length; i++) {@@ -385,7 +411,7 @@ export class SlideTabBar {// diff item midlinelet notFound = true;for (let i = 0; i < collect.length; i++) {- let item = collect[i];+ const item = collect[i];if (SlideTabItem.midline(this._activeTabItem) > item.getMidLine()) {item.animate().translateX(-this._activeTabItem.getWidth());this._compareIndex = splice + i + 1;diff --git a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.ts b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.tssimilarity index 94%rename from packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.tsrename to packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.tsindex 216fc0786e..1112c1f9a8 100644--- a/packages/ui-plugin-sheets/src/Basics/SlideTabBar/SlideTabItem.ts+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SlideTabBar/SlideTabItem.ts@@ -1,6 +1,6 @@-import { SlideTabBar } from './SlideTabBar';import { Animate } from './Animate';import { SlideScrollbar } from './SlideScrollbar';+import { SlideTabBar } from './SlideTabBar';export interface SlideTabItemAnimate {translateX: (x: number) => void;@@ -40,7 +40,7 @@ export class SlideTabItem {}static make(nodeList: NodeList, slideTabBar: SlideTabBar): SlideTabItem[] {- let result: SlideTabItem[] = [];+ const result: SlideTabItem[] = [];nodeList.forEach((item) => result.push(new SlideTabItem(item as HTMLElement, slideTabBar)));return result;}@@ -65,9 +65,9 @@ export class SlideTabItem {editor(callback?: (event: FocusEvent) => void): void {if (this._editMode === false) {- let input = this.primeval().querySelector('span');+ const input = this.primeval().querySelector('span');- let blurAction = (focusEvent: FocusEvent) => {+ const blurAction = (focusEvent: FocusEvent) => {this._editMode = false;if (input) {@@ -78,8 +78,9 @@ export class SlideTabItem {this._slideTabBar.updateItems();- if (this._slideTabBar.getConfig().onChangeName) {- this._slideTabBar.getConfig().onChangeName(focusEvent);+ if (this._slideTabBar.getConfig().onChangeName && this._slideTabItem.dataset.id) {+ const name = (event.target as HTMLElement).innerText;+ this._slideTabBar.getConfig().onChangeName(this._slideTabItem.dataset.id, name);}if (callback) {diff --git a/packages/ui-plugin-sheets/src/commands/rename.command.ts b/packages/ui-plugin-sheets/src/commands/rename.command.tsnew file mode 100644index 0000000000..e44088022a--- /dev/null+++ b/packages/ui-plugin-sheets/src/commands/rename.command.ts@@ -0,0 +1,16 @@+import { CommandType, ICommand } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { SheetBarService } from '../services/sheet-bar.service';++export const RenameSheetCommand: ICommand = {+ id: 'ui-sheet.command.rename-sheet',+ type: CommandType.OPERATION,+ handler: async (accessor: IAccessor) => {+ const sheetBarService = accessor.get(SheetBarService);+ const sheetBarController = sheetBarService.getSheetBarUIController();+ const sheetBar = sheetBarController.getSheetBar();+ sheetBar.reNameSheet(sheetBarController.getDataId());+ return true;+ },+};diff --git a/packages/ui-plugin-sheets/src/commands/unhide.command.ts b/packages/ui-plugin-sheets/src/commands/unhide.command.tsnew file mode 100644index 0000000000..546bdbf547--- /dev/null+++ b/packages/ui-plugin-sheets/src/commands/unhide.command.ts@@ -0,0 +1,14 @@+import { CommandType, ICommand } from '@univerjs/core';+import { IAccessor } from '@wendellhu/redi';++import { SheetBarService } from '../services/sheet-bar.service';++export const ShowMenuListCommand: ICommand = {+ id: 'ui-sheet.command.show-menu-list',+ type: CommandType.OPERATION,+ handler: async (accessor: IAccessor) => {+ const sheetBarService = accessor.get(SheetBarService);+ sheetBarService.showMenuList(true);+ return true;+ },+};diff --git a/packages/ui-plugin-sheets/src/services/sheet-bar.service.ts b/packages/ui-plugin-sheets/src/services/sheet-bar.service.tsnew file mode 100644index 0000000000..8ce77e9d16--- /dev/null+++ b/packages/ui-plugin-sheets/src/services/sheet-bar.service.ts@@ -0,0 +1,15 @@+import { Inject } from '@wendellhu/redi';++import { SheetBarUIController } from '../Controller/SheetBarUIController';++export class SheetBarService {+ constructor(@Inject(SheetBarUIController) private _sheetBarUIController: SheetBarUIController) {}++ showMenuList(show: boolean) {+ this._sheetBarUIController.showMenuList(show);+ }++ getSheetBarUIController() {+ return this._sheetBarUIController;+ }+}