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-01-31 22:07:59 +01:00
|
|
|
} from '@wisemapping/mindplot';
|
2022-02-05 23:10:37 +01:00
|
|
|
import FR from './compiled-lang/fr.json';
|
|
|
|
import ES from './compiled-lang/es.json';
|
|
|
|
import EN from './compiled-lang/en.json';
|
|
|
|
import DE from './compiled-lang/de.json';
|
2022-02-21 06:25:18 +01:00
|
|
|
import './global-styled.css';
|
2022-02-22 06:37:00 +01:00
|
|
|
import { EditorModeType } from '@wisemapping/mindplot/src/components/DesignerOptionsBuilder';
|
2022-01-30 11:37:14 +01:00
|
|
|
|
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 = {
|
|
|
|
mode: EditorModeType,
|
|
|
|
locale: string,
|
|
|
|
zoom?: number,
|
|
|
|
locked?: boolean,
|
|
|
|
lockedMsg?: string;
|
|
|
|
mapTitle: string;
|
|
|
|
enableKeyboardEvents: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type EditorProps = {
|
|
|
|
mapId: string;
|
|
|
|
options: EditorOptions;
|
2022-01-25 19:10:40 +01:00
|
|
|
onAction: (action: ToolbarActionType) => void;
|
2022-02-21 03:50:03 +01:00
|
|
|
persistenceManager: PersistenceManager;
|
2022-02-22 06:37:00 +01:00
|
|
|
initCallback?: (mapId: string, options: EditorOptions, persistenceManager: PersistenceManager) => void;
|
2022-01-25 19:10:40 +01:00
|
|
|
};
|
|
|
|
|
2022-02-06 20:12:20 +01:00
|
|
|
const loadLocaleData = (locale: string) => {
|
2022-02-04 20:26:54 +01:00
|
|
|
switch (locale) {
|
2022-02-05 23:10:37 +01:00
|
|
|
case 'fr':
|
|
|
|
return FR;
|
|
|
|
case 'en':
|
|
|
|
return EN;
|
|
|
|
case 'es':
|
|
|
|
return ES;
|
|
|
|
case 'de':
|
|
|
|
return DE;
|
|
|
|
default:
|
|
|
|
return EN;
|
2022-02-04 20:26:54 +01:00
|
|
|
}
|
2022-02-05 23:10:37 +01:00
|
|
|
}
|
2022-02-04 20:26:54 +01:00
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
const defaultCallback = (mapId: string, options: EditorOptions, persistenceManager: PersistenceManager) => {
|
2022-01-30 11:37:14 +01:00
|
|
|
// Change page title ...
|
2022-02-22 06:37:00 +01:00
|
|
|
document.title = `${options.mapTitle} | WiseMapping `;
|
2022-01-30 11:37:14 +01:00
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
const buildOptions = DesignerOptionsBuilder.buildOptions({
|
2022-02-21 03:50:03 +01:00
|
|
|
persistenceManager,
|
2022-02-22 06:37:00 +01:00
|
|
|
mode: options.mode,
|
|
|
|
mapId: mapId,
|
2022-01-25 19:10:40 +01:00
|
|
|
container: 'mindplot',
|
2022-02-22 06:37:00 +01:00
|
|
|
zoom: options.zoom,
|
|
|
|
locale: options.locale,
|
2022-01-25 19:10:40 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
// Build designer ...
|
2022-02-22 06:37:00 +01:00
|
|
|
const designer = buildDesigner(buildOptions);
|
2022-01-25 19:10:40 +01:00
|
|
|
|
|
|
|
// Load map from XML file persisted on disk...
|
|
|
|
const instance = PersistenceManager.getInstance();
|
2022-02-22 06:37:00 +01:00
|
|
|
const mindmap = instance.load(mapId);
|
2022-01-25 19:10:40 +01:00
|
|
|
designer.loadMap(mindmap);
|
|
|
|
|
2022-02-22 06:37:00 +01:00
|
|
|
if (options.locked) {
|
|
|
|
$notify(options.lockedMsg);
|
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
|
|
|
initCallback = defaultCallback,
|
|
|
|
onAction,
|
|
|
|
}: EditorProps) => {
|
|
|
|
useEffect(() => {
|
|
|
|
initCallback(mapId, options, persistenceManager);
|
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-13 04:15:51 +01:00
|
|
|
|
2022-01-25 19:10:40 +01:00
|
|
|
return (
|
2022-02-22 06:37:00 +01:00
|
|
|
<IntlProvider locale={options.locale} messages={loadLocaleData(options.locale)}>
|
2022-01-31 22:07:59 +01:00
|
|
|
<Toolbar
|
2022-02-22 06:37:00 +01:00
|
|
|
isTryMode={options.mode === 'showcase'}
|
2022-01-31 22:07:59 +01:00
|
|
|
onAction={onAction}
|
|
|
|
/>
|
2022-01-25 19:10:40 +01:00
|
|
|
<div id="mindplot"></div>
|
2022-02-22 06:37:00 +01:00
|
|
|
<Footer showTryPanel={options.mode === 'showcase'} />
|
2022-01-25 19:10:40 +01:00
|
|
|
</IntlProvider>
|
|
|
|
);
|
2022-01-31 22:07:59 +01:00
|
|
|
}
|
2022-02-06 20:12:20 +01:00
|
|
|
export default Editor;
|