From eb4e6e3e719021ff7e436ed6ddcea313a4e32e34 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Mon, 21 Feb 2022 21:37:00 -0800 Subject: [PATCH] Clean up editor global variables. --- packages/editor/src/index.tsx | 94 ++++++++----------- .../test/playground/map-render/js/editor.jsx | 43 --------- .../test/playground/map-render/js/editor.tsx | 49 ++++++++++ .../playground/map-render/js/viewmode.jsx | 49 ---------- .../playground/map-render/js/viewmode.tsx | 67 +++++++++++++ packages/mindplot/src/components/Designer.ts | 4 +- .../src/components/DesignerOptionsBuilder.ts | 6 +- packages/mindplot/src/indexLoader.ts | 2 +- packages/webapp/src/@types/index.d.ts | 12 ++- packages/webapp/src/app.tsx | 15 +-- .../webapp/src/classes/app-config/index.ts | 5 + .../editor-page/EditorOptiosBuider.ts | 38 ++++++++ .../src/components/editor-page/index.tsx | 47 +++++----- packages/webapp/src/redux/editorSlice.ts | 2 +- 14 files changed, 248 insertions(+), 185 deletions(-) delete mode 100644 packages/editor/test/playground/map-render/js/editor.jsx create mode 100644 packages/editor/test/playground/map-render/js/editor.tsx delete mode 100644 packages/editor/test/playground/map-render/js/viewmode.jsx create mode 100644 packages/editor/test/playground/map-render/js/viewmode.tsx create mode 100644 packages/webapp/src/components/editor-page/EditorOptiosBuider.ts diff --git a/packages/editor/src/index.tsx b/packages/editor/src/index.tsx index 76520f51..ae4a29e9 100644 --- a/packages/editor/src/index.tsx +++ b/packages/editor/src/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import Toolbar, { ToolbarActionType } from './components/toolbar'; import Footer from './components/footer'; import { IntlProvider } from 'react-intl'; @@ -15,35 +15,31 @@ import ES from './compiled-lang/es.json'; import EN from './compiled-lang/en.json'; import DE from './compiled-lang/de.json'; import './global-styled.css'; +import { EditorModeType } from '@wisemapping/mindplot/src/components/DesignerOptionsBuilder'; + declare global { - var memoryPersistence: boolean; - var readOnly: boolean; - var lockTimestamp: string; - var lockSession: string; - var historyId: string; - var isAuth: boolean; - var mapId: number; - var userOptions: { zoom: string | number } | null; - var locale: string; - var mindmapLocked: boolean; - var mindmapLockedMsg: string; - var mapTitle: string; - // used in mindplot var designer: Designer; var accountEmail: string; } -export type EditorPropsType = { - initCallback?: (locale: string, persistenceManager: PersistenceManager) => void; - mapId?: number; - isTryMode: boolean; - readOnlyMode: boolean; - locale?: string; +export type EditorOptions = { + mode: EditorModeType, + locale: string, + zoom?: number, + locked?: boolean, + lockedMsg?: string; + mapTitle: string; + enableKeyboardEvents: boolean; +} + +export type EditorProps = { + mapId: string; + options: EditorOptions; onAction: (action: ToolbarActionType) => void; - hotkeys?: boolean; persistenceManager: PersistenceManager; + initCallback?: (mapId: string, options: EditorOptions, persistenceManager: PersistenceManager) => void; }; const loadLocaleData = (locale: string) => { @@ -61,68 +57,60 @@ const loadLocaleData = (locale: string) => { } } -const initMindplot = (locale: string, persistenceManager: PersistenceManager) => { +const defaultCallback = (mapId: string, options: EditorOptions, persistenceManager: PersistenceManager) => { // Change page title ... - document.title = `${global.mapTitle} | WiseMapping `; + document.title = `${options.mapTitle} | WiseMapping `; - const params = new URLSearchParams(window.location.search.substring(1)); - - const zoomParam = Number.parseFloat(params.get('zoom')); - const options = DesignerOptionsBuilder.buildOptions({ + const buildOptions = DesignerOptionsBuilder.buildOptions({ persistenceManager, - readOnly: Boolean(global.readOnly || false), - mapId: String(global.mapId), + mode: options.mode, + mapId: mapId, container: 'mindplot', - zoom: - zoomParam || - (global.userOptions?.zoom != undefined - ? Number.parseFloat(global.userOptions.zoom as string) - : 0.8), - locale: locale, + zoom: options.zoom, + locale: options.locale, }); // Build designer ... - const designer = buildDesigner(options); + const designer = buildDesigner(buildOptions); // Load map from XML file persisted on disk... const instance = PersistenceManager.getInstance(); - const mindmap = instance.load(String(global.mapId)); + const mindmap = instance.load(mapId); designer.loadMap(mindmap); - if (global.mindmapLocked) { - $notify(global.mindmapLockedMsg); + if (options.locked) { + $notify(options.lockedMsg); } }; const Editor = ({ - initCallback = initMindplot, mapId, - isTryMode: isTryMode, - locale = 'en', - onAction, - hotkeys = true, + options, persistenceManager, -}: EditorPropsType): React.ReactElement => { - React.useEffect(() => { - initCallback(locale, persistenceManager); + initCallback = defaultCallback, + onAction, +}: EditorProps) => { + useEffect(() => { + initCallback(mapId, options, persistenceManager); }, []); - React.useEffect(() => { - if (hotkeys) { + useEffect(() => { + if (options.enableKeyboardEvents) { + console.log("options.enableKeyboardEvents"+options.enableKeyboardEvents) DesignerKeyboard.resume(); } else { DesignerKeyboard.pause(); } - }, [hotkeys]); + }, [options.enableKeyboardEvents]); return ( - +
-