2022-02-22 06:37:00 +01:00
|
|
|
import React, { useEffect } from 'react';
|
2022-01-25 19:10:40 +01:00
|
|
|
import Toolbar, { ToolbarActionType } from './components/toolbar';
|
|
|
|
import Footer from './components/footer';
|
|
|
|
import { IntlProvider } from 'react-intl';
|
2022-01-31 22:07:59 +01:00
|
|
|
import {
|
|
|
|
$notify,
|
|
|
|
buildDesigner,
|
|
|
|
PersistenceManager,
|
|
|
|
DesignerOptionsBuilder,
|
2022-02-13 04:15:51 +01:00
|
|
|
Designer,
|
|
|
|
DesignerKeyboard,
|
2022-02-25 17:51:05 +01:00
|
|
|
EditorRenderMode,
|
2022-01-31 22:07:59 +01:00
|
|
|
} from '@wisemapping/mindplot';
|
2022-02-21 06:25:18 +01:00
|
|
|
import './global-styled.css';
|
2022-02-25 16:33:37 +01:00
|
|
|
import I18nMsg from './classes/i18n-msg';
|
2022-02-25 21:29:17 +01:00
|
|
|
import Messages from '@wisemapping/mindplot/src/components/Messages';
|
2022-02-04 20:26:54 +01:00
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
declare global {
|
2022-02-04 20:26:54 +01:00
|
|
|
// used in mindplot
|
|
|
|
var designer: Designer;
|
|
|
|
var accountEmail: string;
|
2022-01-25 19:10:40 +01:00
|
|
|
}
|
2020-12-05 08:47:02 +01:00
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
export type EditorOptions = {
|
2022-02-25 17:51:05 +01:00
|
|
|
mode: EditorRenderMode,
|
2022-02-22 06:37:00 +01:00
|
|
|
locale: string,
|
|
|
|
zoom?: number,
|
|
|
|
locked?: boolean,
|
|
|
|
lockedMsg?: string;
|
|
|
|
mapTitle: string;
|
|
|
|
enableKeyboardEvents: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type EditorProps = {
|
|
|
|
mapId: string;
|
|
|
|
options: EditorOptions;
|
2022-02-21 03:50:03 +01:00
|
|
|
persistenceManager: PersistenceManager;
|
2022-02-25 16:33:37 +01:00
|
|
|
onAction: (action: ToolbarActionType) => void;
|
|
|
|
onLoad?: (designer: Designer) => void;
|
2022-01-25 19:10:40 +01:00
|
|
|
};
|
|
|
|
|
2022-02-06 20:12:20 +01:00
|
|
|
const Editor = ({
|
2022-01-25 19:10:40 +01:00
|
|
|
mapId,
|
2022-02-22 06:37:00 +01:00
|
|
|
options,
|
2022-02-21 03:50:03 +01:00
|
|
|
persistenceManager,
|
2022-02-22 06:37:00 +01:00
|
|
|
onAction,
|
2022-02-25 16:33:37 +01:00
|
|
|
onLoad,
|
2022-02-22 06:37:00 +01:00
|
|
|
}: EditorProps) => {
|
2022-02-25 16:33:37 +01:00
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
useEffect(() => {
|
2022-02-25 16:33:37 +01:00
|
|
|
// Change page title ...
|
|
|
|
document.title = `${options.mapTitle} | WiseMapping `;
|
|
|
|
|
|
|
|
// Load mindmap ...
|
|
|
|
const designer = onLoadDesigner(mapId, options, persistenceManager);
|
|
|
|
// Has extended actions been customized ...
|
|
|
|
if (onLoad) {
|
|
|
|
onLoad(designer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load mindmap ...
|
|
|
|
const instance = PersistenceManager.getInstance();
|
|
|
|
const mindmap = instance.load(mapId);
|
|
|
|
designer.loadMap(mindmap);
|
|
|
|
|
|
|
|
if (options.locked) {
|
2022-02-26 02:55:26 +01:00
|
|
|
$notify(options.lockedMsg, false);
|
2022-02-25 16:33:37 +01:00
|
|
|
}
|
2022-02-06 20:12:20 +01:00
|
|
|
}, []);
|
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (options.enableKeyboardEvents) {
|
2022-02-13 04:15:51 +01:00
|
|
|
DesignerKeyboard.resume();
|
|
|
|
} else {
|
|
|
|
DesignerKeyboard.pause();
|
|
|
|
}
|
2022-02-22 06:37:00 +01:00
|
|
|
}, [options.enableKeyboardEvents]);
|
2022-02-25 16:33:37 +01:00
|
|
|
const onLoadDesigner = (mapId: string, options: EditorOptions, persistenceManager: PersistenceManager): Designer => {
|
|
|
|
const buildOptions = DesignerOptionsBuilder.buildOptions({
|
|
|
|
persistenceManager,
|
|
|
|
mode: options.mode,
|
|
|
|
mapId: mapId,
|
|
|
|
container: 'mindplot',
|
|
|
|
zoom: options.zoom,
|
|
|
|
locale: options.locale,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Build designer ...
|
|
|
|
return buildDesigner(buildOptions);
|
|
|
|
};
|
|
|
|
|
|
|
|
const locale = options.locale;
|
|
|
|
const msg = I18nMsg.loadLocaleData(locale);
|
2022-02-26 02:55:26 +01:00
|
|
|
const mindplotStyle = (options.mode === 'viewonly') ? { top: 0 } : { top: 'inherit' };
|
2022-01-25 19:10:40 +01:00
|
|
|
return (
|
2022-02-25 16:33:37 +01:00
|
|
|
<IntlProvider locale={locale} messages={msg}>
|
2022-02-25 21:29:17 +01:00
|
|
|
{(options.mode !== 'viewonly') &&
|
|
|
|
<Toolbar
|
|
|
|
editorMode={options.mode}
|
|
|
|
onAction={onAction}
|
|
|
|
/>
|
|
|
|
}
|
2022-02-26 02:55:26 +01:00
|
|
|
<div id="mindplot" style={mindplotStyle}></div>
|
2022-02-25 21:29:17 +01:00
|
|
|
<Footer editorMode={options.mode} />
|
2022-02-26 02:55:26 +01:00
|
|
|
</IntlProvider >
|
2022-01-25 19:10:40 +01:00
|
|
|
);
|
2022-01-31 22:07:59 +01:00
|
|
|
}
|
2022-02-06 20:12:20 +01:00
|
|
|
export default Editor;
|