2022-10-08 06:52:39 +02:00
|
|
|
/*
|
|
|
|
* Copyright [2021] [wisemapping]
|
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2022-11-03 03:56:37 +01:00
|
|
|
import React, { ReactElement, useCallback, useEffect, useState } from 'react';
|
2022-10-08 05:22:27 +02:00
|
|
|
import Popover from '@mui/material/Popover';
|
2022-10-08 22:46:52 +02:00
|
|
|
import Model from '../classes/model/editor';
|
2022-11-17 04:27:11 +01:00
|
|
|
import { Vortex } from 'react-loader-spinner';
|
2022-10-08 05:22:27 +02:00
|
|
|
|
|
|
|
import { IntlProvider } from 'react-intl';
|
2022-10-12 06:49:24 +02:00
|
|
|
import {
|
|
|
|
PersistenceManager,
|
|
|
|
Designer,
|
|
|
|
DesignerKeyboard,
|
|
|
|
MindplotWebComponent,
|
|
|
|
EditorRenderMode,
|
|
|
|
} from '@wisemapping/mindplot';
|
|
|
|
|
2022-10-08 05:22:27 +02:00
|
|
|
import I18nMsg from '../classes/i18n-msg';
|
|
|
|
import { theme as defaultEditorTheme } from '../theme';
|
2022-11-03 03:56:37 +01:00
|
|
|
// eslint-disable-next-line no-restricted-imports
|
2022-10-08 05:22:27 +02:00
|
|
|
import ThemeProvider from '@mui/material/styles/ThemeProvider';
|
|
|
|
import { Theme } from '@mui/material/styles';
|
2022-10-08 19:12:07 +02:00
|
|
|
import { Notifier } from './warning-dialog/styled';
|
|
|
|
import WarningDialog from './warning-dialog';
|
2022-10-08 05:22:27 +02:00
|
|
|
import DefaultWidgetManager from '../classes/default-widget-manager';
|
|
|
|
import AppBar from './app-bar';
|
2022-10-08 19:12:07 +02:00
|
|
|
import Capability from '../classes/action/capability';
|
2022-10-12 06:49:24 +02:00
|
|
|
import { ToolbarActionType } from './toolbar/ToolbarActionType';
|
2022-10-22 02:23:32 +02:00
|
|
|
import MapInfo from '../classes/model/map-info';
|
2022-10-23 17:18:41 +02:00
|
|
|
import EditorToolbar from './editor-toolbar';
|
|
|
|
import ZoomPanel from './zoom-panel';
|
2022-11-17 04:27:11 +01:00
|
|
|
import { SpinnerCentered } from './style';
|
2022-10-12 06:49:24 +02:00
|
|
|
|
2022-10-22 02:23:32 +02:00
|
|
|
export type EditorOptions = {
|
2022-10-12 06:49:24 +02:00
|
|
|
mode: EditorRenderMode;
|
|
|
|
locale: string;
|
|
|
|
enableKeyboardEvents: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
type EditorProps = {
|
2022-10-22 02:23:32 +02:00
|
|
|
mapInfo: MapInfo;
|
2022-10-12 06:49:24 +02:00
|
|
|
options: EditorOptions;
|
|
|
|
persistenceManager: PersistenceManager;
|
|
|
|
onAction: (action: ToolbarActionType) => void;
|
|
|
|
onLoad?: (designer: Designer) => void;
|
|
|
|
theme?: Theme;
|
|
|
|
accountConfiguration?: React.ReactElement;
|
|
|
|
};
|
2022-10-08 05:22:27 +02:00
|
|
|
|
|
|
|
const Editor = ({
|
2022-10-22 02:23:32 +02:00
|
|
|
mapInfo,
|
2022-10-08 05:22:27 +02:00
|
|
|
options,
|
|
|
|
persistenceManager,
|
|
|
|
onAction,
|
|
|
|
theme,
|
|
|
|
accountConfiguration,
|
2022-11-03 03:56:37 +01:00
|
|
|
}: EditorProps): ReactElement => {
|
2022-10-22 02:23:32 +02:00
|
|
|
const [model, setModel] = useState<Model | undefined>();
|
2022-10-23 09:15:44 +02:00
|
|
|
|
|
|
|
// This is required to redraw in case of chansges in the canvas...
|
2022-11-03 03:56:37 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-10-22 02:23:32 +02:00
|
|
|
const [canvasUpdate, setCanvasUpdate] = useState<number>();
|
2022-10-08 05:22:27 +02:00
|
|
|
const editorTheme: Theme = theme ? theme : defaultEditorTheme;
|
2022-11-03 03:56:37 +01:00
|
|
|
const [popoverOpen, popoverTarget, widgetManager] = DefaultWidgetManager.useCreate();
|
2022-10-22 02:23:32 +02:00
|
|
|
const capability = new Capability(options.mode, mapInfo.isLocked());
|
2022-10-08 19:12:07 +02:00
|
|
|
|
2022-10-08 23:18:41 +02:00
|
|
|
const mindplotRef = useCallback((component: MindplotWebComponent) => {
|
2022-10-10 02:44:55 +02:00
|
|
|
const model = new Model(component);
|
2022-11-17 06:12:33 +01:00
|
|
|
|
|
|
|
// Force refresh after map load ...
|
|
|
|
model.loadMindmap(mapInfo.getId(), persistenceManager, widgetManager).then(() => {
|
|
|
|
setCanvasUpdate(Date.now());
|
|
|
|
});
|
2022-10-10 02:44:55 +02:00
|
|
|
setModel(model);
|
2022-10-08 05:22:27 +02:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (options.enableKeyboardEvents) {
|
|
|
|
DesignerKeyboard.resume();
|
|
|
|
} else {
|
|
|
|
DesignerKeyboard.pause();
|
|
|
|
}
|
|
|
|
}, [options.enableKeyboardEvents]);
|
|
|
|
|
2022-10-08 23:18:41 +02:00
|
|
|
// Initialize locate ...
|
2022-10-08 05:22:27 +02:00
|
|
|
const locale = options.locale;
|
|
|
|
const msg = I18nMsg.loadLocaleData(locale);
|
|
|
|
return (
|
|
|
|
<ThemeProvider theme={editorTheme}>
|
|
|
|
<IntlProvider locale={locale} messages={msg}>
|
2022-10-10 06:00:53 +02:00
|
|
|
<AppBar
|
2022-10-10 06:33:26 +02:00
|
|
|
model={model}
|
2022-10-22 02:23:32 +02:00
|
|
|
mapInfo={mapInfo}
|
2022-10-10 06:33:26 +02:00
|
|
|
capability={capability}
|
|
|
|
onAction={onAction}
|
|
|
|
accountConfig={accountConfiguration}
|
2022-10-10 06:00:53 +02:00
|
|
|
/>
|
|
|
|
|
2022-10-08 05:22:27 +02:00
|
|
|
<Popover
|
|
|
|
id="popover"
|
|
|
|
open={popoverOpen}
|
|
|
|
anchorEl={popoverTarget}
|
|
|
|
onClose={widgetManager.handleClose}
|
|
|
|
anchorOrigin={{
|
|
|
|
vertical: 'bottom',
|
|
|
|
horizontal: 'left',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{widgetManager.getEditorContent()}
|
|
|
|
</Popover>
|
2022-10-22 02:23:32 +02:00
|
|
|
|
2022-10-23 09:15:44 +02:00
|
|
|
<EditorToolbar model={model} capability={capability} />
|
|
|
|
<ZoomPanel model={model} capability={capability} />
|
2022-10-08 22:46:52 +02:00
|
|
|
|
2022-10-08 05:22:27 +02:00
|
|
|
<mindplot-component
|
|
|
|
ref={mindplotRef}
|
|
|
|
id="mindmap-comp"
|
|
|
|
mode={options.mode}
|
|
|
|
locale={options.locale}
|
2022-10-22 02:23:32 +02:00
|
|
|
/>
|
2022-10-08 22:46:52 +02:00
|
|
|
|
2022-10-22 02:23:32 +02:00
|
|
|
<Notifier id="headerNotifier" />
|
2022-10-08 22:46:52 +02:00
|
|
|
<WarningDialog
|
|
|
|
capability={capability}
|
2022-10-22 02:23:32 +02:00
|
|
|
message={mapInfo.isLocked() ? mapInfo.getLockedMessage() : ''}
|
|
|
|
/>
|
2022-11-17 04:27:11 +01:00
|
|
|
|
2022-11-17 06:12:33 +01:00
|
|
|
{!model?.isMapLoadded() && (
|
2022-11-17 04:27:11 +01:00
|
|
|
<SpinnerCentered>
|
|
|
|
<Vortex
|
|
|
|
visible={true}
|
|
|
|
height="160"
|
|
|
|
width="160"
|
|
|
|
ariaLabel="vortex-loading"
|
|
|
|
colors={['#ffde1a', '#ffce00', '#ffa700', '#ff8d00', '#ff7400', '#ffde1a']}
|
|
|
|
/>
|
|
|
|
</SpinnerCentered>
|
|
|
|
)}
|
2022-10-08 05:22:27 +02:00
|
|
|
</IntlProvider>
|
|
|
|
</ThemeProvider>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
export default Editor;
|