Extract editor render as type.

This commit is contained in:
Paulo Gustavo Veiga 2022-02-25 08:51:05 -08:00
parent 63b9b0e353
commit 0629f6f87b
8 changed files with 18 additions and 15 deletions

View File

@ -9,9 +9,9 @@ import {
DesignerOptionsBuilder,
Designer,
DesignerKeyboard,
EditorRenderMode,
} from '@wisemapping/mindplot';
import './global-styled.css';
import { EditorModeType } from '@wisemapping/mindplot/src/components/DesignerOptionsBuilder';
import I18nMsg from './classes/i18n-msg';
declare global {
@ -21,7 +21,7 @@ declare global {
}
export type EditorOptions = {
mode: EditorModeType,
mode: EditorRenderMode,
locale: string,
zoom?: number,
locked?: boolean,

View File

@ -16,15 +16,14 @@
* limitations under the License.
*/
import { $assert } from '@wisemapping/core-js';
import EditorRenderMode from './EditorRenderMode';
import PersistenceManager from './PersistenceManager';
import SizeType from './SizeType';
export type EditorModeType = 'viewonly' | 'edition' | 'showcase';
export type DesignerOptions = {
zoom: number,
containerSize?: SizeType,
mode: EditorModeType,
mode: EditorRenderMode,
mapId?: string,
container: string,
persistenceManager?: PersistenceManager,

View File

@ -0,0 +1,2 @@
type EditorRenderMode = 'viewonly' | 'edition' | 'showcase';
export default EditorRenderMode;

View File

@ -29,6 +29,7 @@ import ImageExporterFactory from './components/export/ImageExporterFactory';
import TextExporterFactory from './components/export/TextExporterFactory';
import Exporter from './components/export/Exporter';
import DesignerKeyboard from './components/DesignerKeyboard';
import EditorRenderMode from './components/EditorRenderMode';
import {
buildDesigner,
@ -53,6 +54,7 @@ export {
LocalStorageManager,
DesignerOptionsBuilder,
buildDesigner,
EditorRenderMode,
TextExporterFactory,
ImageExporterFactory,
Exporter,

View File

@ -1,4 +1,4 @@
import { Mindmap, PersistenceManager } from '@wisemapping/mindplot';
import { EditorRenderMode, Mindmap, PersistenceManager } from '@wisemapping/mindplot';
import Client, {
AccountInfo,
BasicMapInfo,
@ -130,8 +130,8 @@ class CacheDecoratorClient implements Client {
return this.client.revertHistory(id, cid);
}
buildPersistenceManager(isTryMode: boolean): PersistenceManager {
return this.client.buildPersistenceManager(isTryMode);
buildPersistenceManager(mode: EditorRenderMode): PersistenceManager {
return this.client.buildPersistenceManager(mode);
}
removePersistenceManager(): void {

View File

@ -1,4 +1,4 @@
import { Mindmap, PersistenceManager } from '@wisemapping/mindplot';
import { EditorRenderMode, Mindmap, PersistenceManager } from '@wisemapping/mindplot';
import { Locale, LocaleCode } from '../app-i18n';
export type NewUser = {
@ -109,7 +109,7 @@ interface Client {
fetchMindmap(id: number): Mindmap;
buildPersistenceManager(isTryMode: boolean): PersistenceManager;
buildPersistenceManager(mode: EditorRenderMode): PersistenceManager;
removePersistenceManager(): void;
onSessionExpired(callback?: () => void): () => void;

View File

@ -1,4 +1,4 @@
import { LocalStorageManager, Mindmap, PersistenceManager, RESTPersistenceManager } from '@wisemapping/mindplot';
import { EditorRenderMode, LocalStorageManager, Mindmap, PersistenceManager, RESTPersistenceManager } from '@wisemapping/mindplot';
import { PersistenceError } from '@wisemapping/mindplot/src/components/PersistenceManager';
import axios, { AxiosInstance, AxiosResponse } from 'axios';
import Client, {
@ -611,13 +611,13 @@ export default class RestClient implements Client {
}
}
buildPersistenceManager(isTryMode: boolean): PersistenceManager {
buildPersistenceManager(editorMode: EditorRenderMode): PersistenceManager {
if (this.persistenceManager) {
return this.persistenceManager;
}
// TODO: Move globals out, make urls configurable
let persistence: PersistenceManager;
if (!isTryMode) {
if (editorMode === 'edition') {
persistence = new RESTPersistenceManager({
documentUrl: '/c/restful/maps/{id}/document',
revertUrl: '/c/restful/maps/{id}/history/latest',

View File

@ -21,16 +21,16 @@ const EditorPage = ({ isTryMode }: EditorPropsType): React.ReactElement => {
const userLocale = AppI18n.getUserLocale();
const client: Client = useSelector(activeInstance);
const [persistenceManager, setPersistenceManager] = React.useState<PersistenceManager>();
const { mapId, options } = EditorOptionsBulder.build(userLocale.code, hotkey, isTryMode);
useEffect(() => {
ReactGA.pageview(window.location.pathname + window.location.search);
const persistence = client.buildPersistenceManager(isTryMode);
const persistence = client.buildPersistenceManager(options.mode);
setPersistenceManager(persistence);
return () => client.removePersistenceManager();
}, []);
// As temporal hack, editor properties are propagated from global variables...
const { mapId, options } = EditorOptionsBulder.build(userLocale.code, hotkey, isTryMode);
return persistenceManager ? (
<>
<Editor onAction={setActiveDialog}