mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +01:00
Extract editor render as type.
This commit is contained in:
parent
63b9b0e353
commit
0629f6f87b
@ -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,
|
||||
|
@ -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,
|
||||
|
2
packages/mindplot/src/components/EditorRenderMode.ts
Normal file
2
packages/mindplot/src/components/EditorRenderMode.ts
Normal file
@ -0,0 +1,2 @@
|
||||
type EditorRenderMode = 'viewonly' | 'edition' | 'showcase';
|
||||
export default EditorRenderMode;
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
|
@ -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',
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user