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(sheet): add disabled status on toolbar menu items (#993)
zhangw16a9fbe34aff
diff --git a/packages/sheets-formula/src/controllers/menu.ts b/packages/sheets-formula/src/controllers/menu.tsindex 22bc54ef80..c1180e2ff5 100644--- a/packages/sheets-formula/src/controllers/menu.ts+++ b/packages/sheets-formula/src/controllers/menu.ts@@ -15,6 +15,7 @@*/import { UniverInstanceType } from '@univerjs/core';+import { getCurrentSheetDisabled$ } from '@univerjs/sheets';import { PASTE_SPECIAL_MENU_ID } from '@univerjs/sheets-ui';import type { IMenuItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';@@ -60,6 +61,7 @@ export function InsertFunctionMenuItemFactory(accessor: IAccessor): IMenuItem {},],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}diff --git a/packages/sheets-numfmt/src/menu/menu.ts b/packages/sheets-numfmt/src/menu/menu.tsindex c0e29b3d37..9166202b7f 100644--- a/packages/sheets-numfmt/src/menu/menu.ts+++ b/packages/sheets-numfmt/src/menu/menu.ts@@ -16,7 +16,13 @@import { ICommandService, IUniverInstanceService, LocaleService, UniverInstanceType } from '@univerjs/core';import { AddDigitsSingle, MoreDownSingle, ReduceDigitsSingle, RmbSingle } from '@univerjs/icons';-import { INumfmtService, RemoveNumfmtMutation, SelectionManagerService, SetNumfmtMutation } from '@univerjs/sheets';+import {+ getCurrentSheetDisabled$,+ INumfmtService,+ RemoveNumfmtMutation,+ SelectionManagerService,+ SetNumfmtMutation,+} from '@univerjs/sheets';import type { ComponentManager, IMenuSelectorItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';import type { IAccessor } from '@wendellhu/redi';@@ -45,6 +51,7 @@ export const CurrencyMenuItem = (componentManager: ComponentManager) => {group: MenuGroup.TOOLBAR_FORMULAS_INSERT,positions: [MenuPosition.TOOLBAR_START],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};};};@@ -61,6 +68,7 @@ export const AddDecimalMenuItem = (componentManager: ComponentManager) => {positions: [MenuPosition.TOOLBAR_START],group: MenuGroup.TOOLBAR_FORMULAS_INSERT,hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),});};export const SubtractDecimalMenuItem = (componentManager: ComponentManager) => {@@ -75,6 +83,7 @@ export const SubtractDecimalMenuItem = (componentManager: ComponentManager) => {group: MenuGroup.TOOLBAR_FORMULAS_INSERT,positions: [MenuPosition.TOOLBAR_START],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),});};@@ -149,6 +158,7 @@ export const FactoryOtherMenuItem = (componentManager: ComponentManager) => {],value$,hidden$: getMenuHiddenObservable(_accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(_accessor),} as IMenuSelectorItem;};};diff --git a/packages/sheets-ui/src/components/font-size/FontSize.tsx b/packages/sheets-ui/src/components/font-size/FontSize.tsxindex 7fe9dd4a58..ad1f8c5ae9 100644--- a/packages/sheets-ui/src/components/font-size/FontSize.tsx+++ b/packages/sheets-ui/src/components/font-size/FontSize.tsx@@ -15,13 +15,16 @@*/import { InputNumber } from '@univerjs/design';+import { useObservable } from '@univerjs/ui';import React, { useMemo, useState } from 'react';+import { Observable } from 'rxjs';import styles from './index.module.less';import type { IFontSizeProps } from './interface';export const FontSize = (props: IFontSizeProps) => {- const { value, min, max, onChange } = props;+ const { value, min, max, onChange, disabled$ } = props;+ const disabled = useObservable(disabled$ ?? new Observable<boolean>((sub) => sub.next(false)));const [realValue, setRealValue] = useState<number>(Number(value ?? 0));const _value = useMemo(() => Number(value ?? realValue), [value]);@@ -50,6 +53,7 @@ export const FontSize = (props: IFontSizeProps) => {max={max}onKeyDown={handleStopPropagation}onChange={handleChange}+ disabled={disabled}/></div>);diff --git a/packages/sheets-ui/src/components/font-size/interface.ts b/packages/sheets-ui/src/components/font-size/interface.tsindex 672725cd74..3898867e73 100644--- a/packages/sheets-ui/src/components/font-size/interface.ts+++ b/packages/sheets-ui/src/components/font-size/interface.ts@@ -15,6 +15,7 @@*/import type { ICustomComponentProps } from '@univerjs/ui';+import type { Observable } from 'rxjs';import { COMPONENT_PREFIX } from '../const';@@ -28,4 +29,6 @@ export interface IFontSizeProps extends ICustomComponentProps<string> {max: number;onChange: (value: string) => void;++ disabled$?: Observable<boolean>;}diff --git a/packages/sheets-ui/src/controllers/menu/border.menu.ts b/packages/sheets-ui/src/controllers/menu/border.menu.tsindex 7a6d85125a..a2d8d4a47c 100644--- a/packages/sheets-ui/src/controllers/menu/border.menu.ts+++ b/packages/sheets-ui/src/controllers/menu/border.menu.ts@@ -16,7 +16,7 @@import { ICommandService, UniverInstanceType } from '@univerjs/core';import type { IBorderInfo } from '@univerjs/sheets';-import { BorderStyleManagerService, SetBorderBasicCommand } from '@univerjs/sheets';+import { BorderStyleManagerService, getCurrentSheetDisabled$, SetBorderBasicCommand } from '@univerjs/sheets';import type { IMenuSelectorItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';import type { IAccessor } from '@wendellhu/redi';@@ -29,6 +29,8 @@ export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSelconst borderStyleManagerService = accessor.get(BorderStyleManagerService);+ const disabled$ = getCurrentSheetDisabled$(accessor);+return {id: SetBorderBasicCommand.id,icon: new Observable<string>((subscriber) => {@@ -69,5 +71,6 @@ export function CellBorderSelectorMenuItemFactory(accessor: IAccessor): IMenuSel],value$: borderStyleManagerService.borderInfo$,hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$,};}diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.tsindex e84863cf3e..1a1f3d5f32 100644--- a/packages/sheets-ui/src/controllers/menu/menu.ts+++ b/packages/sheets-ui/src/controllers/menu/menu.ts@@ -33,6 +33,7 @@ import {} from '@univerjs/core';import { SetInlineFormatCommand, SetTextSelectionsOperation, TextSelectionManagerService } from '@univerjs/docs';import {+ getCurrentSheetDisabled$,ResetBackgroundColorCommand,ResetTextColorCommand,SelectionManagerService,@@ -54,7 +55,6 @@ import {SetTextWrapCommand,SetVerticalTextAlignCommand,SetWorksheetRowIsAutoHeightCommand,- SheetPermissionService,} from '@univerjs/sheets';import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';import {@@ -108,7 +108,6 @@ export enum SheetMenuPosition {export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonItem {const formatPainterService = accessor.get(IFormatPainterService);- const univerInstanceService = accessor.get(IUniverInstanceService);return {id: SetOnceFormatPainterCommand.id,@@ -134,17 +133,15 @@ export function FormatPainterMenuItemFactory(accessor: IAccessor): IMenuButtonIt};}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {const commandService = accessor.get(ICommandService);- const sheetPermissionService = accessor.get(SheetPermissionService);const univerInstanceService = accessor.get(IUniverInstanceService);const contextService = accessor.get(IContextService);const selectionManagerService = accessor.get(SelectionManagerService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();return {id: SetRangeBoldCommand.id,@@ -154,14 +151,7 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {title: 'Set bold',tooltip: 'toolbar.bold',positions: [MenuPosition.TOOLBAR_START],- disabled$: new Observable<boolean>((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$: getCurrentSheetDisabled$(accessor),activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;@@ -207,10 +197,8 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);- const sheetPermissionService = accessor.get(SheetPermissionService);const contextService = accessor.get(IContextService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();+return {id: SetRangeItalicCommand.id,group: MenuGroup.TOOLBAR_FORMAT,@@ -219,14 +207,7 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {title: 'Set italic',tooltip: 'toolbar.italic',positions: [MenuPosition.TOOLBAR_START],- disabled$: new Observable<boolean>((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$: getCurrentSheetDisabled$(accessor),activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;@@ -270,10 +251,8 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {const commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);- const sheetPermissionService = accessor.get(SheetPermissionService);const contextService = accessor.get(IContextService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();+return {id: SetRangeUnderlineCommand.id,group: MenuGroup.TOOLBAR_FORMAT,@@ -282,14 +261,7 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {title: 'Set underline',tooltip: 'toolbar.underline',positions: [MenuPosition.TOOLBAR_START],- disabled$: new Observable<boolean>((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$: getCurrentSheetDisabled$(accessor),activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;@@ -333,10 +305,8 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItconst commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);- const sheetPermissionService = accessor.get(SheetPermissionService);const contextService = accessor.get(IContextService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();+return {id: SetRangeStrickThroughCommand.id,group: MenuGroup.TOOLBAR_FORMAT,@@ -345,14 +315,7 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIttitle: 'Set strike through',tooltip: 'toolbar.strikethrough',positions: [MenuPosition.TOOLBAR_START],- disabled$: new Observable<boolean>((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$: getCurrentSheetDisabled$(accessor),activated$: new Observable<boolean>((subscriber) => {const disposable = commandService.onCommandExecuted((c) => {const id = c.id;@@ -531,9 +494,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelconst commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);- const sheetPermissionService = accessor.get(SheetPermissionService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();+return {id: SetRangeFontFamilyCommand.id,tooltip: 'toolbar.font',@@ -542,14 +503,7 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSellabel: FONT_FAMILY_COMPONENT,positions: [MenuPosition.TOOLBAR_START],selections: FONT_FAMILY_CHILDREN,- disabled$: new Observable((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$: getCurrentSheetDisabled$(accessor),value$: new Observable((subscriber) => {const defaultValue = FONT_FAMILY_CHILDREN[0].value;@@ -581,10 +535,9 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelecconst commandService = accessor.get(ICommandService);const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);- const sheetPermissionService = accessor.get(SheetPermissionService);const contextService = accessor.get(IContextService);- const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();- const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();++ const disabled$ = getCurrentSheetDisabled$(accessor);return {id: SetRangeFontSizeCommand.id,@@ -596,18 +549,12 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelecprops: {min: 1,max: 400,+ disabled$,},},positions: [MenuPosition.TOOLBAR_START],selections: FONT_SIZE_CHILDREN,- disabled$: new Observable<boolean>((subscriber) => {- const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {- subscriber.next(!e.value);- });- return () => {- permission$?.unsubscribe();- };- }),+ disabled$,value$: new Observable((subscriber) => {const DEFAULT_SIZE = 14;const disposable = commandService.onCommandExecuted((c) => {@@ -649,13 +596,14 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec};}-export function ResetTextColorMenuItemFactory(): IMenuButtonItem {+export function ResetTextColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {id: ResetTextColorCommand.id,type: MenuItemType.BUTTON,title: 'toolbar.resetColor',icon: 'NoColor',positions: SetRangeTextColorCommand.id,+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -692,16 +640,18 @@ export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelereturn disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}-export function ResetBackgroundColorMenuItemFactory(): IMenuButtonItem {+export function ResetBackgroundColorMenuItemFactory(accessor: IAccessor): IMenuButtonItem {return {id: ResetBackgroundColorCommand.id,type: MenuItemType.BUTTON,title: 'toolbar.resetColor',icon: 'NoColor',positions: SetBackgroundColorCommand.id,+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -737,6 +687,7 @@ export function BackgroundColorSelectorMenuItemFactory(accessor: IAccessor): IMereturn disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -793,6 +744,7 @@ export function HorizontalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectreturn disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -817,6 +769,7 @@ export const VERTICAL_ALIGN_CHILDREN = [export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<VerticalAlign> {const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);+return {id: SetVerticalTextAlignCommand.id,icon: VERTICAL_ALIGN_CHILDREN[0].icon,@@ -848,6 +801,7 @@ export function VerticalAlignMenuItemFactory(accessor: IAccessor): IMenuSelectorreturn disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -870,8 +824,9 @@ export const TEXT_WRAP_CHILDREN = [];export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<WrapStrategy> {- const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);+return {id: SetTextWrapCommand.id,tooltip: 'toolbar.textWrapMode.main',@@ -903,6 +858,7 @@ export function WrapTextMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<return disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}@@ -940,8 +896,8 @@ export const TEXT_ROTATE_CHILDREN = [];export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number | string> {- const univerInstanceService = accessor.get(IUniverInstanceService);const selectionManagerService = accessor.get(SelectionManagerService);+ const univerInstanceService = accessor.get(IUniverInstanceService);return {id: SetTextRotationCommand.id,@@ -978,6 +934,7 @@ export function TextRotateMenuItemFactory(accessor: IAccessor): IMenuSelectorItereturn disposable.dispose;}),hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}diff --git a/packages/sheets-ui/src/controllers/menu/merge.menu.ts b/packages/sheets-ui/src/controllers/menu/merge.menu.tsindex 4ebd7cd679..e9b6258282 100644--- a/packages/sheets-ui/src/controllers/menu/merge.menu.ts+++ b/packages/sheets-ui/src/controllers/menu/merge.menu.ts@@ -15,7 +15,7 @@*/import { UniverInstanceType } from '@univerjs/core';-import { RemoveWorksheetMergeCommand } from '@univerjs/sheets';+import { getCurrentSheetDisabled$, RemoveWorksheetMergeCommand } from '@univerjs/sheets';import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';import type { IAccessor } from '@wendellhu/redi';@@ -28,6 +28,8 @@ import {} from '../../commands/commands/add-worksheet-merge.command';export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {+ const disabled$ = getCurrentSheetDisabled$(accessor);+return {id: AddWorksheetMergeCommand.id,icon: 'MergeAllSingle',@@ -37,6 +39,7 @@ export function CellMergeMenuItemFactory(accessor: IAccessor): IMenuSelectorItemtype: MenuItemType.SUBITEMS,// selections: [...MERGE_CHILDREN],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$,};}export function CellMergeAllMenuItemFactory(accessor: IAccessor): IMenuButtonItem<string> {diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.tsindex 3918e7f46b..8d09c05242 100644--- a/packages/sheets/src/index.ts+++ b/packages/sheets/src/index.ts@@ -45,7 +45,7 @@ export {export { alignToMergedCellsBorders, getCellAtRowCol } from './commands/commands/utils/selection-utils';export { MAX_CELL_PER_SHEET_KEY } from './controllers/config/config';export { BorderStyleManagerService, type IBorderInfo } from './services/border-style-manager.service';-export { SheetEditablePermission, SheetPermissionService } from './services/permission';+export { getCurrentSheetDisabled$, SheetEditablePermission, SheetPermissionService } from './services/permission';export {NORMAL_SELECTION_PLUGIN_NAME,SelectionManagerService,diff --git a/packages/sheets/src/services/permission/index.ts b/packages/sheets/src/services/permission/index.tsindex 017ad18697..9a70367152 100644--- a/packages/sheets/src/services/permission/index.ts+++ b/packages/sheets/src/services/permission/index.ts@@ -16,3 +16,4 @@export { SheetEditablePermission } from './permission-point';export { SheetPermissionService } from './sheet-permission.service';+export * from './tool';diff --git a/packages/sheets/src/services/permission/tool.ts b/packages/sheets/src/services/permission/tool.tsnew file mode 100644index 0000000000..e964351f7a--- /dev/null+++ b/packages/sheets/src/services/permission/tool.ts@@ -0,0 +1,37 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { IUniverInstanceService } from '@univerjs/core';+import type { IAccessor } from '@wendellhu/redi';+import { Observable } from 'rxjs';++import { SheetPermissionService } from './sheet-permission.service';++export function getCurrentSheetDisabled$(accessor: IAccessor) {+ const univerInstanceService = accessor.get(IUniverInstanceService);+ const sheetPermissionService = accessor.get(SheetPermissionService);+ const unitId = univerInstanceService.getCurrentUniverSheetInstance().getUnitId();+ const sheetId = univerInstanceService.getCurrentUniverSheetInstance().getActiveSheet().getSheetId();++ return new Observable<boolean>((subscriber) => {+ const permission$ = sheetPermissionService.getEditable$(unitId, sheetId)?.subscribe((e) => {+ subscriber.next(!e.value);+ });+ return () => {+ permission$?.unsubscribe();+ };+ });+}diff --git a/packages/ui/src/controllers/shortcut-display/menu.ts b/packages/ui/src/controllers/shortcut-display/menu.tsindex b787911e77..1ff8872efd 100644--- a/packages/ui/src/controllers/shortcut-display/menu.ts+++ b/packages/ui/src/controllers/shortcut-display/menu.ts@@ -31,5 +31,6 @@ export function ShortcutPanelMenuItemFactory(accessor: IAccessor): IMenuButtonIttype: MenuItemType.BUTTON,positions: [MenuPosition.TOOLBAR_START],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ // disabled$: getCurrentSheetDisabled$(accessor),};}diff --git a/packages/ui/src/services/menu/menu.ts b/packages/ui/src/services/menu/menu.tsindex 65050fd3eb..cb25683086 100644--- a/packages/ui/src/services/menu/menu.ts+++ b/packages/ui/src/services/menu/menu.ts@@ -81,7 +81,7 @@ interface IMenuItemBase<V> {| {name: string;hoverable?: boolean;- props?: Record<string, string | number | Array<{ [x: string | number]: string }>>;+ props?: Record<string, any>;}; // custom component, send to CustomLabel label propertyhidden$?: Observable<boolean>;diff --git a/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx b/packages/ui/src/views/components/doc-bars/ToolbarItem.tsxindex a26b797649..0a20d1dfd7 100644--- a/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx+++ b/packages/ui/src/views/components/doc-bars/ToolbarItem.tsx@@ -105,6 +105,10 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:function renderSelectorType(menuType: MenuItemType) {function handleSelect(option: IValueOption) {+ if (disabled) {+ return;+ }+let commandId = id;const value = option;@@ -116,11 +120,18 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:}function handleChange(value: string | number) {+ if (disabled) {+ return;+ }+const commandId = id;handleCommandExecuted(commandId, { value });}function handleClick() {+ if (disabled) {+ return;+ }if (menuType === MenuItemType.BUTTON_SELECTOR) {const commandId = id;handleCommandExecuted(commandId, { value });@@ -128,7 +139,12 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:}return menuType === MenuItemType.BUTTON_SELECTOR ? (- <div className={styles.toolbarItemSelectButton}>+ <div+ className={`${styles.toolbarItemSelectButton} ${+ disabled ? styles.toolbarItemSelectButtonDisabled : ''+ }`}+ data-disabled={disabled}+ ><div className={styles.toolbarItemSelectButtonLabel} onClick={handleClick}><CustomLabelicon={iconToDisplay}@@ -139,16 +155,25 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:/></div><Dropdown+ visible={disabled ? false : undefined}overlay={<Menu menuType={id} options={options} onOptionSelect={handleSelect} value={value} />}>- <div className={styles.toolbarItemSelectButtonArrow}>+ <div+ className={`${styles.toolbarItemSelectButtonArrow} ${+ disabled ? styles.toolbarItemSelectButtonArrowDisabled : ''+ }`}+ data-disabled={disabled}+ ><MoreDownSingle /></div></Dropdown></div>) : (- <Dropdown overlay={<Menu menuType={id} options={options} onOptionSelect={handleSelect} value={value} />}>- <div className={styles.toolbarItemSelect}>+ <Dropdown+ visible={disabled ? false : undefined}+ overlay={<Menu menuType={id} options={options} onOptionSelect={handleSelect} value={value} />}+ >+ <div className={`${styles.toolbarItemSelect} ${disabled ? styles.toolbarItemSelectDisabled : ''}`}><CustomLabelicon={iconToDisplay}title={title!}@@ -156,7 +181,11 @@ export const ToolbarItem = forwardRef((props: IDisplayMenuItem<IMenuItem>, ref:label={label}onChange={handleChange}/>- <div className={styles.toolbarItemSelectArrow}>+ <div+ className={`${styles.toolbarItemSelectArrow} ${+ disabled ? styles.toolbarItemSelectArrowDisabled : ''+ }`}+ ><MoreDownSingle /></div></div>diff --git a/packages/ui/src/views/components/doc-bars/index.module.less b/packages/ui/src/views/components/doc-bars/index.module.lessindex c00c31241b..a37e912f46 100644--- a/packages/ui/src/views/components/doc-bars/index.module.less+++ b/packages/ui/src/views/components/doc-bars/index.module.less@@ -158,6 +158,11 @@border-radius: var(--border-radius-base);+ &-disabled {+ cursor: not-allowed;+ color: rgb(var(--grey-200));+ }+&:hover {background-color: rgb(var(--grey-100));@@ -226,6 +231,11 @@border-radius: var(--border-radius-base);+ &-disabled {+ cursor: not-allowed;+ color: rgb(var(--grey-200));+ }+&:hover {background-color: rgb(var(--grey-100));border-radius: var(--border-radius-base);@@ -239,7 +249,16 @@font-size: 10px;color: rgb(var(--grey-400));++ &-disabled {+ cursor: not-allowed;+ color: rgb(var(--grey-200));+ }}++}++}}diff --git a/packages/uniscript/src/controllers/menu.ts b/packages/uniscript/src/controllers/menu.tsindex 497d74a70d..6f468b694f 100644--- a/packages/uniscript/src/controllers/menu.ts+++ b/packages/uniscript/src/controllers/menu.ts@@ -15,6 +15,7 @@*/import { UniverInstanceType } from '@univerjs/core';+import { getCurrentSheetDisabled$ } from '@univerjs/sheets';import type { IMenuButtonItem } from '@univerjs/ui';import { getMenuHiddenObservable, MenuItemType, MenuPosition } from '@univerjs/ui';import type { IAccessor } from '@wendellhu/redi';@@ -30,5 +31,6 @@ export function UniscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {type: MenuItemType.BUTTON,positions: [MenuPosition.TOOLBAR_START],hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.SHEET),+ disabled$: getCurrentSheetDisabled$(accessor),};}