diff --git a/packages/editor/src/classes/model/editor/index.ts b/packages/editor/src/classes/model/editor/index.ts index ba19faa2..7fc18a7c 100644 --- a/packages/editor/src/classes/model/editor/index.ts +++ b/packages/editor/src/classes/model/editor/index.ts @@ -24,6 +24,10 @@ class Editor { this.component = mindplotComponent; } + isMapLoadded(): boolean { + return this.component.getDesigner()?.getMindmap() != null; + } + save(minor: boolean) { this.component.save(minor); } diff --git a/packages/editor/src/components/index.tsx b/packages/editor/src/components/index.tsx index 61ca9209..185a64a5 100644 --- a/packages/editor/src/components/index.tsx +++ b/packages/editor/src/components/index.tsx @@ -81,7 +81,7 @@ const Editor = ({ const msg = I18nMsg.loadLocaleData(locale); const menubarConfiguration = buildAppBarConfig( - model?.getDesigner(), + model, options.mapTitle, capability, onAction, diff --git a/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx b/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx index 5ba07b3f..6061b3bf 100644 --- a/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx +++ b/packages/editor/src/components/toolbar/toolbarConfigBuilder.tsx @@ -48,6 +48,7 @@ import TopicNote from '../action-widget/pane/topic-note'; import IconPicker from '../action-widget/pane/icon-picker'; import FontFamilySelector from '../action-widget/button/font-family-selector'; import Capability from '../../classes/action/capability'; +import Editor from '../../classes/model/editor'; export type ToolbarActionType = 'export' | 'publish' | 'history' | 'print' | 'share' | 'info'; @@ -348,18 +349,18 @@ export function buildZoomToolbarConfig(capability: Capability, designer: Designe } export function buildAppBarConfig( - designer: Designer, + model: Editor, mapTitle: string, capability: Capability, onAction: (type: ToolbarActionType) => void, accountConfiguration, save: () => void, ): ActionConfig[] { - if (!designer) { - return []; - } + const appBarDivisor = { + render: () => , + }; - let commonConfiguration: ActionConfig[] = [ + return [ { icon: , tooltip: $msg('BACK_TO_MAP_LIST'), @@ -382,14 +383,6 @@ export function buildAppBarConfig( ), }, - ]; - - const appBarDivisor = { - render: () => , - }; - - return [ - ...commonConfiguration, null, { render: () => ( @@ -403,6 +396,7 @@ export function buildAppBarConfig( > ), visible: !capability.isHidden('undo-changes'), + disabled: () => !model?.isMapLoadded(), }, { render: () => ( @@ -416,6 +410,7 @@ export function buildAppBarConfig( > ), visible: !capability.isHidden('redo-changes'), + disabled: () => !model?.isMapLoadded(), }, null, { @@ -423,6 +418,7 @@ export function buildAppBarConfig( tooltip: $msg('SAVE') + ' (' + $msg('CTRL') + ' + S)', onClick: save, visible: !capability.isHidden('save'), + disabled: () => !model?.isMapLoadded(), }, { icon: ,