Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(sheet): rename / reorder / unhide worksheet item in sheetbar (#204)

YuHongdf77a54f2e8d
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts
new file mode 100644
index 0000000000..70a1b2d225
--- /dev/null
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-tab-color.command.spec.ts
@@ -0,0 +1,49 @@
+import { ICommandService, ICurrentUniverService, RedoCommand, UndoCommand, Univer } from '@univerjs/core';
+import { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import { SetTabColorMutation } from '../../..';
+import { SetTabColorCommand } from '../set-tab-color.command';
+import { createCommandTestBed } from './create-command-test-bed';
+
+describe('Test tab color commands', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+
+ beforeEach(() => {
+ const testBed = createCommandTestBed();
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetTabColorCommand);
+ commandService.registerCommand(SetTabColorMutation);
+ });
+
+ afterEach(() => {
+ univer.dispose();
+ });
+
+ describe('Set several specific colors', () => {
+ function getTabColor() {
+ return get(ICurrentUniverService).getUniverSheetInstance('test')?.getActiveSheet()?.getTabColor();
+ }
+
+ describe('correct situations', () => {
+ it('will set tab color', async () => {
+ expect(await commandService.executeCommand(SetTabColorCommand.id, { value: '#cccccc' })).toBeTruthy();
+ expect(getTabColor()).toBe('#cccccc');
+
+ expect(await commandService.executeCommand(SetTabColorCommand.id, { value: 'red' })).toBeTruthy();
+ expect(getTabColor()).toBe('red');
+ // undo
+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
+ expect(getTabColor()).toBe('#cccccc');
+ // redo
+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
+ expect(getTabColor()).toBe('red');
+ });
+ });
+ });
+});
diff --git a/packages/base-sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts b/packages/base-sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts
new file mode 100644
index 0000000000..deef06e595
--- /dev/null
+++ b/packages/base-sheets/src/commands/commands/__tests__/set-worksheet-hide.command.spec.ts
@@ -0,0 +1,78 @@
+import {
+ BooleanNumber,
+ ICommandService,
+ ICurrentUniverService,
+ RedoCommand,
+ UndoCommand,
+ Univer,
+} from '@univerjs/core';
+import { Injector } from '@wendellhu/redi';
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+
+import {
+ InsertSheetCommand,
+ InsertSheetMutation,
+ SetWorksheetActivateCommand,
+ SetWorksheetActivateMutation,
+ SetWorksheetHideCommand,
+ SetWorksheetHideMutation,
+} from '../../..';
+import { createCommandTestBed } from './create-command-test-bed';
+
+describe('Test set worksheet hide commands', () => {
+ let univer: Univer;
+ let get: Injector['get'];
+ let commandService: ICommandService;
+
+ beforeEach(() => {
+ const testBed = createCommandTestBed();
+ univer = testBed.univer;
+ get = testBed.get;
+
+ commandService = get(ICommandService);
+ commandService.registerCommand(SetWorksheetHideCommand);
+ commandService.registerCommand(SetWorksheetHideMutation);
+ commandService.registerCommand(SetWorksheetActivateCommand);
+ commandService.registerCommand(SetWorksheetActivateMutation);
+ commandService.registerCommand(InsertSheetCommand);
+ commandService.registerCommand(InsertSheetMutation);
+ });
+
+ afterEach(() => {
+ univer.dispose();
+ });
+
+ describe('Set worksheet hide', () => {
+ it('will set current acitve worksheet hidden', async () => {
+ const workbook = get(ICurrentUniverService).getCurrentUniverSheetInstance();
+ if (!workbook) throw new Error('This is an error');
+
+ const targetActiveSheet = workbook.getActiveSheet();
+ const targetSheetId = targetActiveSheet?.getSheetId();
+
+ expect(
+ await commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId: targetSheetId })
+ ).toBeTruthy();
+
+ expect(await commandService.executeCommand(InsertSheetCommand.id, {})).toBeTruthy();
+
+ expect(
+ await commandService.executeCommand(SetWorksheetActivateCommand.id, { worksheetId: targetSheetId })
+ ).toBeTruthy();
+ expect(
+ await commandService.executeCommand(SetWorksheetHideCommand.id, {
+ worksheetId: targetSheetId,
+ })
+ ).toBeTruthy();
+
+ expect(targetActiveSheet?.getConfig().hidden).toBe(BooleanNumber.TRUE);
+
+ // undo
+ expect(await commandService.executeCommand(UndoCommand.id)).toBeTruthy();
+ expect(targetActiveSheet?.getConfig().hidden).toBe(BooleanNumber.FALSE);
+ // redo
+ expect(await commandService.executeCommand(RedoCommand.id)).toBeTruthy();
+ expect(targetActiveSheet?.getConfig().hidden).toBe(BooleanNumber.TRUE);
+ });
+ });
+});
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.ts
index d9ad6a2880..337d630827 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
@@ -4,7 +4,6 @@ import { IAccessor } from '@wendellhu/redi';
import {
ISetWorksheetActivateMutationParams,
SetWorksheetActivateMutation,
- SetWorksheetUnActivateMutationFactory,
} from '../mutations/set-worksheet-activate.mutation';
export interface ISetWorksheetActivateCommandParams {
@@ -37,7 +36,7 @@ export const SetWorksheetActivateCommand: ICommand = {
workbookId,
worksheetId,
};
- const undoMutationParams = SetWorksheetUnActivateMutationFactory(accessor, redoMutationParams);
+ // const undoMutationParams = SetWorksheetUnActivateMutationFactory(accessor, redoMutationParams);
const result = commandService.executeCommand(SetWorksheetActivateMutation.id, redoMutationParams);
// no need
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.ts
index 1a5a2262f8..f4bf5474e4 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
@@ -58,11 +58,14 @@ export const SetWorksheetHideCommand: ICommand = {
};
const undoMutationParams = SetWorksheetHideMutationFactory(accessor, redoMutationParams);
- const result = commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams);
const index = workbook.getSheetIndex(worksheet);
const activateSheetId = workbook.getConfig().sheetOrder[index + 1];
+ if (!activateSheetId) return false;
+
+ const result = commandService.executeCommand(SetWorksheetHideMutation.id, redoMutationParams);
+
const activeSheetMutationParams: ISetWorksheetActivateMutationParams = {
workbookId,
worksheetId: activateSheetId,
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.ts
index a5f7b69779..57f8ee7e65 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
@@ -20,7 +20,7 @@ import {
} from '../mutations/set-worksheet-hide.mutation';
export interface ISetWorksheetShowCommandParams {
- worksheetId?: string;
+ value?: string;
}
export const SetWorksheetShowCommand: ICommand = {
@@ -40,7 +40,7 @@ export const SetWorksheetShowCommand: ICommand = {
.getSheetId();
if (params) {
- worksheetId = params.worksheetId ?? worksheetId;
+ worksheetId = params.value ?? worksheetId;
}
const workbook = currentUniverService.getUniverSheetInstance(workbookId);
diff --git a/packages/base-ui/src/Components/Menu/Menu.tsx b/packages/base-ui/src/Components/Menu/Menu.tsx
index ea392e6247..8080d8f015 100644
--- a/packages/base-ui/src/Components/Menu/Menu.tsx
+++ b/packages/base-ui/src/Components/Menu/Menu.tsx
@@ -344,7 +344,7 @@
// }
import { isRealNum } from '@univerjs/core';
import React, { useContext, useEffect, useRef, useState } from 'react';
-import { of } from 'rxjs';
+import { isObservable, of } from 'rxjs';
import { AppContext } from '../../Common/AppContext';
import {
@@ -711,6 +711,18 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
setInputValue(newValue);
};
+ let selections: Array<IValueOption | ICustomComponentOption>;
+ if (menuItem.type === MenuItemType.SELECTOR) {
+ if (isObservable(menuItem.selections)) {
+ selections = useObservable<Array<IValueOption | ICustomComponentOption>>(
+ menuItem.selections || of([]),
+ [],
+ true
+ );
+ } else {
+ selections = menuItem.selections || [];
+ }
+ }
const renderButtonType = () => {
const item = menuItem as IDisplayMenuItem<IMenuButtonItem>;
const { title, display, label } = item;
@@ -760,7 +772,7 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
min={item.min}
></NeoCustomLabel>
{item.shortcut && ` (${item.shortcut})`}
- {(menuItems.length > 0 || (item as IMenuSelectorItem).selections?.length) && (
+ {(menuItems.length > 0 || selections?.length > 0) && (
<Menu
show={itemShow}
onOptionSelect={(v) => {
@@ -769,7 +781,7 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
setItemShow(false); // hide current menu
}}
menuId={item.id}
- options={item.selections}
+ options={selections}
display={item.display}
parent={true}
></Menu>
@@ -795,7 +807,7 @@ export function MenuItem({ menuItem, index, onClick }: IMenuItemProps) {
display={item.display}
label={item.label}
></NeoCustomLabel>
- {(menuItems.length > 0 || (item as IMenuSelectorItem<unknown>).selections?.length) && (
+ {(menuItems.length > 0 || selections?.length) && (
<Menu
show={itemShow}
menuId={item.id}
diff --git a/packages/base-ui/src/Components/Tabs/Tabs.tsx b/packages/base-ui/src/Components/Tabs/Tabs.tsx
index 4d22a96eae..e95607234f 100644
--- a/packages/base-ui/src/Components/Tabs/Tabs.tsx
+++ b/packages/base-ui/src/Components/Tabs/Tabs.tsx
@@ -80,6 +80,10 @@ export interface IBaseTabsProps {
* @default false
*/
draggable?: boolean;
+ /**
+ * Re-render when it changes
+ */
+ reRenderString?: string;
}
interface ITabInfo {
@@ -390,7 +394,10 @@ export const Tabs = React.memo(
</div>
);
},
- (prev, next) => prev.children.length === next.children.length && prev.activeKey === next.activeKey
+ (prev, next) =>
+ prev.children.length === next.children.length &&
+ prev.activeKey === next.activeKey &&
+ prev.reRenderString === next.reRenderString
);
// tab content
diff --git a/packages/base-ui/src/services/menu/menu.ts b/packages/base-ui/src/services/menu/menu.ts
index dc3de4f367..e133358670 100644
--- a/packages/base-ui/src/services/menu/menu.ts
+++ b/packages/base-ui/src/services/menu/menu.ts
@@ -118,7 +118,9 @@ export interface IMenuSelectorItem<V = MenuItemDefaultValueType> extends IMenuIt
// 一个是一个特殊组件,比如 color picker,选中后直接使用其 value 触发 command
// 一个是其他 menu 的 id,直接渲染成其他的 menu
/** Options or IDs of registered components. */
- selections?: Array<IValueOption | ICustomComponentOption>;
+ selections?:
+ | Array<IValueOption | ICustomComponentOption>
+ | Observable<Array<IValueOption | ICustomComponentOption>>;
}
export function isMenuSelectorItem<T extends MenuItemDefaultValueType>(v: IMenuItem): v is IMenuSelectorItem<T> {
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 1c4cc9cfca..d9ae956693 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -12,6 +12,7 @@ import { LifecycleService } from '../services/lifecycle/lifecycle.service';
import { LocaleService } from '../services/locale/locale.service';
import { DesktopLogService, ILogService } from '../services/log/log.service';
import { DesktopPermissionService, IPermissionService } from '../services/permission/permission.service';
+import { ISheetBarService, SheetBarService } from '../services/sheetbar/sheetbar.service';
import { ThemeService } from '../services/theme/theme.service';
import { IUndoRedoService, LocalUndoRedoService } from '../services/undoredo/undoredo.service';
import { Workbook } from '../Sheets/Domain/Workbook';
@@ -176,6 +177,7 @@ export class Univer {
[IPermissionService, { useClass: DesktopPermissionService }],
[IConfigService, { useClass: ConfigService }],
[IContextService, { useClass: ContextService }],
+ [ISheetBarService, { useClass: SheetBarService }],
]);
}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 4af92a35f5..cfe74ba41c 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -24,6 +24,7 @@ export { LifecycleService } from './services/lifecycle/lifecycle.service';
export { LocaleService } from './services/locale/locale.service';
export { DesktopLogService, ILogService } from './services/log/log.service';
export { DesktopPermissionService, IPermissionService } from './services/permission/permission.service';
+export { ISheetBarService, SheetBarService } from './services/sheetbar/sheetbar.service';
export { ThemeService } from './services/theme/theme.service';
export {
type IUndoRedoCommandInfos,
diff --git a/packages/core/src/services/current.service.ts b/packages/core/src/services/current.service.ts
index d5cccca9a3..12006c45dc 100644
--- a/packages/core/src/services/current.service.ts
+++ b/packages/core/src/services/current.service.ts
@@ -6,6 +6,7 @@ import { Nullable } from '../Shared';
import { Disposable } from '../Shared/lifecycle';
import { Workbook } from '../Sheets/Domain/Workbook';
import { SlideModel } from '../Slides/Domain/SlideModel';
+import { BooleanNumber } from '../Types/Enum';
import { IDocumentData } from '../Types/Interfaces';
import { FOCUSING_DOC, FOCUSING_SHEET, FOCUSING_SLIDE } from './context/context';
import { IContextService } from './context/context.service';
@@ -14,6 +15,11 @@ export interface IUniverHandler {
createUniverDoc(data: Partial<IDocumentData>): DocumentModel;
}
+export interface IWorksheetDiscriptor {
+ id: string;
+ name: string;
+}
+
/**
* ICurrentUniverService holds all the current univer instances. And it also manages
* the focused univer instance.
@@ -54,6 +60,7 @@ export interface ICurrentUniverService {
getFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null;
focusUniverInstance(id: string | null): void;
+ getCurrentUniverHiddenWorksheets(): IWorksheetDiscriptor[];
}
export const ICurrentUniverService = createIdentifier<ICurrentUniverService>('univer.current');
@@ -196,4 +203,14 @@ export class CurrentUniverService extends Disposable implements ICurrentUniverSe
getFocusedUniverInstance(): Workbook | DocumentModel | SlideModel | null {
return this._focused;
}
+
+ getCurrentUniverHiddenWorksheets(): IWorksheetDiscriptor[] {
+ return this.getCurrentUniverSheetInstance()
+ .getSheets()
+ .filter((s) => s.getConfig().hidden === BooleanNumber.TRUE)
+ .map((s) => ({
+ id: s.getConfig().name,
+ name: s.getConfig().id,
+ }));
+ }
}
diff --git a/packages/core/src/services/sheetbar/sheetbar.service.ts b/packages/core/src/services/sheetbar/sheetbar.service.ts
new file mode 100644
index 0000000000..29ffe7525c
--- /dev/null
+++ b/packages/core/src/services/sheetbar/sheetbar.service.ts
@@ -0,0 +1,28 @@
+import { createIdentifier } from '@wendellhu/redi';
+import { BehaviorSubject, Observable } from 'rxjs';
+
+import { Disposable } from '../../Shared/lifecycle';
+
+export interface ISheetBarService {
+ renameId$: Observable<string>;
+ setRenameId(id: string): void;
+}
+
+export const ISheetBarService = createIdentifier<ISheetBarService>('univer.sheetbar-service');
+
+export class SheetBarService extends Disposable implements ISheetBarService {
+ readonly renameId$: Observable<string>;
+
+ private readonly _renameId$: BehaviorSubject<string>;
+
+ constructor() {
+ super();
+
+ this._renameId$ = new BehaviorSubject('');
+ this.renameId$ = this._renameId$.asObservable();
+ }
+
+ setRenameId(renameId: string): void {
+ this._renameId$.next(renameId);
+ }
+}
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
index 302eb67e40..f0866022c0 100644
--- a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx
@@ -1,4 +1,5 @@
import {
+ InsertSheetCommand,
InsertSheetMutation,
RemoveSheetMutation,
SetTabColorMutation,
@@ -15,11 +16,12 @@ import {
BaseMenuItem,
BaseSelectProps,
Button,
- CustomLabel,
Icon,
IDisplayMenuItem,
IMenuItem,
Menu,
+ TabPane,
+ Tabs,
} from '@univerjs/base-ui';
import { BooleanNumber, ICommandService, ICurrentUniverService, IKeyValue } from '@univerjs/core';
import { IDisposable } from '@wendellhu/redi';
@@ -27,6 +29,7 @@ import { Component, createRef } from 'react';
import { SheetMenuPosition } from '../../controller/menu/menu';
import styles from './index.module.less';
+import { InputEdit } from './input-edit';
import { ISheetBarMenuItem, SheetBarMenu } from './SheetBarMenu';
export interface BaseSheetBarProps extends BaseComponentProps, Omit<BaseSelectProps, 'children'> {
@@ -50,6 +53,7 @@ type SheetState = {
sheetUl: BaseMenuItem[];
menuItems: Array<IDisplayMenuItem<IMenuItem>>;
showMenu: boolean;
+ showManageMenu: boolean;
menuStyle: React.CSSProperties;
activeKey: string;
};
@@ -92,6 +96,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
menuList: [],
menuItems: [],
showMenu: false,
+ showManageMenu: false,
menuStyle: {},
activeKey: '',
};
@@ -202,43 +207,43 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
return currentSheet?.sheetId;
}
- // getSheetBarItem(item: BaseSheetBarProps) {
- // return (
- // <div
- // onMouseDown={item.onMouseDown}
- // onContextMenu={this.contextMenu}
- // key={item.sheetId}
- // data-id={item.sheetId}
- // className={`${styles.slideTabItem} ${item.selected ? styles.slideTabActive : ''}`}
- // >
- // <div className={`${styles.slideTabContent}`}>
- // <div className={`${styles.slideTabDivider}`}></div>
- // <div className={`${styles.slideTabTitle}`}>
- // <span className={`${styles.slideTabSpan}`} style={{ padding: '2px 5px 2px 5px' }}>
- // <CustomLabel label={item.label} />
- // </span>
- // </div>
- // <div
- // className={`${styles.slideTabIcon}`}
- // data-slide-skip="true"
- // style={{ lineHeight: 1 }}
- // data-id={item.sheetId}
- // onMouseDown={(e) => {
- // this.onContextMenuClick(e);
- // }}
- // >
- // <Icon.NextIcon />
- // </div>
- // </div>
- // <div className={`${styles.slideTabFooter}`}>
- // <div
- // className={`${styles.slideTabActiveBar}`}
- // style={item.color ? { background: item.color } : {}}
- // ></div>
- // </div>
- // </div>
- // );
- // }
+ getSheetBarItem(item: BaseSheetBarProps) {
+ return (
+ <div
+ onMouseDown={item.onMouseDown}
+ onContextMenu={this.onContextMenuClick}
+ key={item.sheetId}
+ data-id={item.sheetId}
+ className={`${styles.slideTabItem}`}
+ >
+ <div className={`${styles.slideTabContent}`}>
+ <div className={`${styles.slideTabDivider}`}></div>
+ <div className={`${styles.slideTabTitle}`}>
+ <span className={`${styles.slideTabSpan}`} style={{ padding: '2px 5px 2px 5px' }}>
+ <InputEdit sheetId={item.sheetId} sheetName={item.label as string} />
+ </span>
+ </div>
+ <div
+ className={`${styles.slideTabIcon}`}
+ data-slide-skip="true"
+ style={{ lineHeight: 1 }}
+ data-id={item.sheetId}
+ onMouseDown={(e) => {
+ this.onContextMenuClick(e);
+ }}
+ >
+ <Icon.NextIcon />
+ </div>
+ </div>
+ <div className={`${styles.slideTabFooter}`}>
+ <div
+ className={`${styles.slideTabActiveBar}`}
+ style={item.color ? { background: item.color } : {}}
+ ></div>
+ </div>
+ </div>
+ );
+ }
/**
* Update worksheet info.
@@ -277,9 +282,9 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
color: (sheet.getTabColor() as string) ?? undefined,
onMouseDown: () => {
const worksheetId = sheet.getSheetId();
- // this.setState({
- // activeKey: worksheetId,
- // });
+ this.setState({
+ activeKey: worksheetId,
+ });
commandService.executeCommand(SetWorksheetActivateCommand.id, {
workbookId: workbook.getUnitId(),
@@ -287,12 +292,14 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
});
},
}));
+ const activeKey = sheetListItems.find((item) => item.selected)?.sheetId || '';
// TODO: update state to the component, including active sheet index
this.setState({
menuList: worksheetMenuItems,
sheetList: sheetListItems,
+ activeKey,
});
}
@@ -319,16 +326,28 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
});
}
+ private _addSheet() {
+ const commandService = this.context.injector.get(ICommandService);
+ commandService.executeCommand(InsertSheetCommand.id, {});
+ }
+
override render() {
- const { sheetList, menuList, sheetUl, showMenu, menuStyle, activeKey } = this.state;
+ const { sheetList, menuList, sheetUl, showMenu, showManageMenu, menuStyle, activeKey } = this.state;
- const { addSheet } = this.props;
+ const reRenderString = sheetList
+ .map((item) => `${item?.color?.toString()}${item?.label?.toString()}`)
+ .join('-');
return (
<div className={styles.sheetBar}>
<div className={styles.sheetBarOptions}>
{/* add sheet button */}
- <Button className={styles.sheetBarOptionsButton} onClick={addSheet}>
+ <Button
+ className={styles.sheetBarOptionsButton}
+ onClick={() => {
+ this._addSheet();
+ }}
+ >
<Icon.Math.AddIcon style={{ fontSize: '20px' }} />
</Button>
{/* all sheets button */}
@@ -339,7 +358,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</div>
{/* user s button */}
- {/* <Tabs draggable className={styles.slideTabBar} activeKey={activeKey}>
+ <Tabs draggable className={styles.slideTabBar} activeKey={activeKey} reRenderString={reRenderString}>
{sheetList.map((item) => (
<TabPane
key={item.sheetId}
@@ -348,8 +367,8 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
className={styles.sheetBarTabPane}
></TabPane>
))}
- </Tabs> */}
- <div className={styles.slideTabBar}>
+ </Tabs>
+ {/* <div className={styles.slideTabBar}>
{sheetList.map((item) => (
<div
onMouseDown={item.onMouseDown}
@@ -383,7 +402,7 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
</div>
</div>
))}
- </div>
+ </div> */}
{/* context menu */}
<Menu
@@ -397,7 +416,14 @@ export class SheetBar extends Component<BaseSheetBarProps, SheetState> {
const commandService: ICommandService = (this.context as IKeyValue).injector.get(
ICommandService
);
- commandService.executeCommand(commandId as string, { value });
+ commandService.executeCommand(commandId as string, { value, worksheetId: activeKey });
+ }}
+ />
+ <Menu
+ menuId={SheetMenuPosition.WORKSHEET_MANAGE_MENU}
+ show={showManageMenu}
+ onOptionSelect={(params) => {
+ // TODO: handle menu item click
}}
/>
diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx
new file mode 100644
index 0000000000..eb6ea5a908
--- /dev/null
+++ b/packages/ui-plugin-sheets/src/View/SheetBar/input-edit.tsx
@@ -0,0 +1,68 @@
+import { SetWorksheetNameCommand } from '@univerjs/base-sheets';
+import { AppContext } from '@univerjs/base-ui';
+import { useObservable } from '@univerjs/base-ui/Components/hooks/observable.js';
+import { ICommandService, ICurrentUniverService, ISheetBarService } from '@univerjs/core';
+import { useContext, useState } from 'react';
+
+interface IBaseInputProps {
+ sheetId: string | undefined;
+ sheetName: string;
+}
+export function InputEdit(props: IBaseInputProps) {
+ const context = useContext(AppContext);
+ const sheetbarService = context.injector.get(ISheetBarService);
+ const renameId = useObservable(sheetbarService.renameId$, '');
+ const oldValue = props.sheetName;
+ const [val, setVal] = useState(props.sheetName || '');
+ const changeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
+ setVal(e.target.value);
+ };
+ const blur = () => {
+ submit();
+ };
+
+ const submit = () => {
+ if (val !== oldValue) {
+ const commandService = context.injector.get(ICommandService);
+ const currentUniverService = context.injector.get(ICurrentUniverService);
+ const workbookId = currentUniverService.getCurrentUniverSheetInstance()?.getUnitId();
+ commandService.executeCommand(SetWorksheetNameCommand.id, {
+ worksheetId: props.sheetId,
+ workbookId,
+ name: val,
+ });
+ }
+
+ sheetbarService.setRenameId('');
+ };
+
+ const keydown = (ev: React.KeyboardEvent<HTMLInputElement>) => {
+ if (ev.key !== undefined && ev.key === 'Enter') {
+ return submit();
+ }
+ if (ev.keyCode !== undefined && ev.keyCode === 13) {
+ return submit();
+ }
+ };
+
+ const isRenaming = renameId === props.sheetId;
+ return isRenaming ? (
+ <input
+ type="text"
+ draggable={false}
+ value={val}
+ onMouseDown={(e) => {
+ e.stopPropagation();
+ }}
+ autoFocus
+ onChange={changeValue}
+ onBlur={blur}
+ onKeyDown={keydown}
+ onClick={(e) => {
+ e.stopPropagation();
+ }}
+ />
+ ) : (
+ <span>{props.sheetName}</span>
+ );
+}
diff --git a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
index cfbd1ba8fe..de2b24595b 100644
--- a/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
+++ b/packages/ui-plugin-sheets/src/commands/commands/rename.command.ts
@@ -1,10 +1,18 @@
-import { CommandType, ICommand } from '@univerjs/core';
+import { CommandType, ICommand, ISheetBarService } from '@univerjs/core';
import { IAccessor } from '@wendellhu/redi';
+interface IRenameCommandParams {
+ worksheetId: string;
+}
+
export const RenameSheetCommand: ICommand = {
id: 'ui-sheet.command.rename-sheet',
type: CommandType.OPERATION,
- handler: async (accessor: IAccessor) =>
- // FIXME: direct rename sheetbar not calling SheetBarService
- true,
+ handler: async (accessor: IAccessor, params?: IRenameCommandParams) => {
+ const sheetBarService = accessor.get(ISheetBarService);
+ if (params) {
+ sheetBarService.setRenameId(params.worksheetId);
+ }
+ return true;
+ },
};
diff --git a/packages/ui-plugin-sheets/src/controller/menu/menu.ts b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
index 9dce0a93ce..4f45ad520c 100644
--- a/packages/ui-plugin-sheets/src/controller/menu/menu.ts
+++ b/packages/ui-plugin-sheets/src/controller/menu/menu.ts
@@ -33,6 +33,7 @@ import {
SetWorksheetRowHeightCommand,
SetWorksheetRowHideCommand,
SetWorksheetRowShowCommand,
+ SetWorksheetShowCommand,
} from '@univerjs/base-sheets';
import {
ColorPicker,
@@ -65,7 +66,6 @@ import { map } from 'rxjs/operators';
import { SHEET_UI_PLUGIN_NAME } from '../../Basics/Const/PLUGIN_NAME';
import { RenameSheetCommand } from '../../commands/commands/rename.command';
-import { ShowMenuListCommand } from '../../commands/commands/unhide.command';
export const CONTEXT_MENU_INPUT_LABEL = 'CONTEXT_MENU_INPUT';
@@ -76,6 +76,7 @@ export enum SheetMenuPosition {
ROW_HEADER_CONTEXT_MENU = 'rowHeaderContextMenu',
COL_HEADER_CONTEXT_MENU = 'colHeaderContextMenu',
SHEET_BAR = 'sheetBar',
+ WORKSHEET_MANAGE_MENU = 'worksheetManageMenu',
}
export function UndoMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
@@ -1223,11 +1224,47 @@ export function HideSheetMenuItemFactory(): IMenuButtonItem {
};
}
-export function UnHideSheetMenuItemFactory(): IMenuButtonItem {
+export function UnHideSheetMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<any> {
+ const currentUniverService = accessor.get(ICurrentUniverService);
+ const commandService = accessor.get(ICommandService);
+ const hiddenList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({
+ label: s.name,
+ value: s.id,
+ }));
+
return {
- id: ShowMenuListCommand.id,
- type: MenuItemType.BUTTON,
+ id: SetWorksheetShowCommand.id,
+ type: MenuItemType.SELECTOR,
positions: [SheetMenuPosition.SHEET_BAR],
title: 'sheetConfig.unhide',
+ selectType: SelectTypes.NEO,
+ disabled$: new Observable((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id !== SetWorksheetHideCommand.id && c.id !== SetWorksheetShowCommand.id) {
+ return;
+ }
+ const newList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({
+ label: s.name,
+ value: s.id,
+ }));
+ subscriber.next(newList.length === 0);
+ });
+ subscriber.next(hiddenList.length === 0);
+ return disposable.dispose;
+ }),
+ selections: new Observable((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id !== SetWorksheetHideCommand.id && c.id !== SetWorksheetShowCommand.id) {
+ return;
+ }
+ const newList = currentUniverService.getCurrentUniverHiddenWorksheets().map((s) => ({
+ label: s.name,
+ value: s.id,
+ }));
+ subscriber.next(newList);
+ });
+ subscriber.next(hiddenList);
+ return disposable.dispose;
+ }),
};
}