mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-23 15:17:57 +01:00
20658d3a69
feat: add custom hook useEditor to initialize editor * feat: add custom hook useEditor to initialize editor Approved-by: Paulo Veiga
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import '../css/viewmode.css';
|
|
import React from 'react';
|
|
import { LocalStorageManager, Designer } from '@wisemapping/mindplot';
|
|
import MapInfoImpl from './MapInfoImpl';
|
|
import { createRoot } from 'react-dom/client';
|
|
import Editor, { EditorOptions, useEditor } from '../../../../src';
|
|
|
|
const initialization = (designer: Designer) => {
|
|
designer.addEvent('loadSuccess', () => {
|
|
const elem = document.getElementById('mindmap-comp');
|
|
if (elem) {
|
|
elem.classList.add('ready');
|
|
}
|
|
|
|
// Code for selector of map.
|
|
const mapSelectElem = document.getElementById('map-select') as HTMLSelectElement;
|
|
if (mapSelectElem) {
|
|
mapSelectElem.addEventListener('change', (e) => {
|
|
// @ts-ignore
|
|
const selectMap = e.target?.value;
|
|
window.location.href = `${window.location.pathname}?id=${selectMap}`;
|
|
});
|
|
|
|
Array.from(mapSelectElem.options).forEach((option) => {
|
|
option.selected = option.value === mapId;
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
// Obtain map id from query param
|
|
const params = new URLSearchParams(window.location.search.substring(1));
|
|
const mapId = params.get('id') || 'welcome';
|
|
const persistence = new LocalStorageManager('samples/{id}.wxml', false);
|
|
const options: EditorOptions = {
|
|
mode: 'viewonly',
|
|
locale: 'en',
|
|
enableKeyboardEvents: true,
|
|
enableAppBar: false,
|
|
};
|
|
|
|
const mapInfo = new MapInfoImpl(mapId, 'Develop Map Title', false);
|
|
|
|
const Playground = () => {
|
|
const editor = useEditor({
|
|
mapInfo,
|
|
options,
|
|
persistenceManager: persistence,
|
|
});
|
|
return (
|
|
<Editor
|
|
editor={editor}
|
|
onAction={(action) => console.log('action called:', action)}
|
|
onLoad={initialization}
|
|
/>
|
|
);
|
|
};
|
|
|
|
const container = document.getElementById('root');
|
|
const root = createRoot(container!);
|
|
|
|
root.render(<Playground />);
|