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,
|
DesignerOptionsBuilder,
|
||||||
Designer,
|
Designer,
|
||||||
DesignerKeyboard,
|
DesignerKeyboard,
|
||||||
|
EditorRenderMode,
|
||||||
} from '@wisemapping/mindplot';
|
} from '@wisemapping/mindplot';
|
||||||
import './global-styled.css';
|
import './global-styled.css';
|
||||||
import { EditorModeType } from '@wisemapping/mindplot/src/components/DesignerOptionsBuilder';
|
|
||||||
import I18nMsg from './classes/i18n-msg';
|
import I18nMsg from './classes/i18n-msg';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -21,7 +21,7 @@ declare global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type EditorOptions = {
|
export type EditorOptions = {
|
||||||
mode: EditorModeType,
|
mode: EditorRenderMode,
|
||||||
locale: string,
|
locale: string,
|
||||||
zoom?: number,
|
zoom?: number,
|
||||||
locked?: boolean,
|
locked?: boolean,
|
||||||
|
@ -16,15 +16,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import { $assert } from '@wisemapping/core-js';
|
import { $assert } from '@wisemapping/core-js';
|
||||||
|
import EditorRenderMode from './EditorRenderMode';
|
||||||
import PersistenceManager from './PersistenceManager';
|
import PersistenceManager from './PersistenceManager';
|
||||||
import SizeType from './SizeType';
|
import SizeType from './SizeType';
|
||||||
|
|
||||||
export type EditorModeType = 'viewonly' | 'edition' | 'showcase';
|
|
||||||
|
|
||||||
export type DesignerOptions = {
|
export type DesignerOptions = {
|
||||||
zoom: number,
|
zoom: number,
|
||||||
containerSize?: SizeType,
|
containerSize?: SizeType,
|
||||||
mode: EditorModeType,
|
mode: EditorRenderMode,
|
||||||
mapId?: string,
|
mapId?: string,
|
||||||
container: string,
|
container: string,
|
||||||
persistenceManager?: PersistenceManager,
|
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 TextExporterFactory from './components/export/TextExporterFactory';
|
||||||
import Exporter from './components/export/Exporter';
|
import Exporter from './components/export/Exporter';
|
||||||
import DesignerKeyboard from './components/DesignerKeyboard';
|
import DesignerKeyboard from './components/DesignerKeyboard';
|
||||||
|
import EditorRenderMode from './components/EditorRenderMode';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
buildDesigner,
|
buildDesigner,
|
||||||
@ -53,6 +54,7 @@ export {
|
|||||||
LocalStorageManager,
|
LocalStorageManager,
|
||||||
DesignerOptionsBuilder,
|
DesignerOptionsBuilder,
|
||||||
buildDesigner,
|
buildDesigner,
|
||||||
|
EditorRenderMode,
|
||||||
TextExporterFactory,
|
TextExporterFactory,
|
||||||
ImageExporterFactory,
|
ImageExporterFactory,
|
||||||
Exporter,
|
Exporter,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Mindmap, PersistenceManager } from '@wisemapping/mindplot';
|
import { EditorRenderMode, Mindmap, PersistenceManager } from '@wisemapping/mindplot';
|
||||||
import Client, {
|
import Client, {
|
||||||
AccountInfo,
|
AccountInfo,
|
||||||
BasicMapInfo,
|
BasicMapInfo,
|
||||||
@ -130,8 +130,8 @@ class CacheDecoratorClient implements Client {
|
|||||||
return this.client.revertHistory(id, cid);
|
return this.client.revertHistory(id, cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
buildPersistenceManager(isTryMode: boolean): PersistenceManager {
|
buildPersistenceManager(mode: EditorRenderMode): PersistenceManager {
|
||||||
return this.client.buildPersistenceManager(isTryMode);
|
return this.client.buildPersistenceManager(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
removePersistenceManager(): void {
|
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';
|
import { Locale, LocaleCode } from '../app-i18n';
|
||||||
|
|
||||||
export type NewUser = {
|
export type NewUser = {
|
||||||
@ -109,7 +109,7 @@ interface Client {
|
|||||||
|
|
||||||
fetchMindmap(id: number): Mindmap;
|
fetchMindmap(id: number): Mindmap;
|
||||||
|
|
||||||
buildPersistenceManager(isTryMode: boolean): PersistenceManager;
|
buildPersistenceManager(mode: EditorRenderMode): PersistenceManager;
|
||||||
removePersistenceManager(): void;
|
removePersistenceManager(): void;
|
||||||
|
|
||||||
onSessionExpired(callback?: () => void): () => 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 { PersistenceError } from '@wisemapping/mindplot/src/components/PersistenceManager';
|
||||||
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
||||||
import Client, {
|
import Client, {
|
||||||
@ -611,13 +611,13 @@ export default class RestClient implements Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buildPersistenceManager(isTryMode: boolean): PersistenceManager {
|
buildPersistenceManager(editorMode: EditorRenderMode): PersistenceManager {
|
||||||
if (this.persistenceManager) {
|
if (this.persistenceManager) {
|
||||||
return this.persistenceManager;
|
return this.persistenceManager;
|
||||||
}
|
}
|
||||||
// TODO: Move globals out, make urls configurable
|
// TODO: Move globals out, make urls configurable
|
||||||
let persistence: PersistenceManager;
|
let persistence: PersistenceManager;
|
||||||
if (!isTryMode) {
|
if (editorMode === 'edition') {
|
||||||
persistence = new RESTPersistenceManager({
|
persistence = new RESTPersistenceManager({
|
||||||
documentUrl: '/c/restful/maps/{id}/document',
|
documentUrl: '/c/restful/maps/{id}/document',
|
||||||
revertUrl: '/c/restful/maps/{id}/history/latest',
|
revertUrl: '/c/restful/maps/{id}/history/latest',
|
||||||
|
@ -21,16 +21,16 @@ const EditorPage = ({ isTryMode }: EditorPropsType): React.ReactElement => {
|
|||||||
const userLocale = AppI18n.getUserLocale();
|
const userLocale = AppI18n.getUserLocale();
|
||||||
const client: Client = useSelector(activeInstance);
|
const client: Client = useSelector(activeInstance);
|
||||||
const [persistenceManager, setPersistenceManager] = React.useState<PersistenceManager>();
|
const [persistenceManager, setPersistenceManager] = React.useState<PersistenceManager>();
|
||||||
|
const { mapId, options } = EditorOptionsBulder.build(userLocale.code, hotkey, isTryMode);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
ReactGA.pageview(window.location.pathname + window.location.search);
|
ReactGA.pageview(window.location.pathname + window.location.search);
|
||||||
const persistence = client.buildPersistenceManager(isTryMode);
|
const persistence = client.buildPersistenceManager(options.mode);
|
||||||
setPersistenceManager(persistence);
|
setPersistenceManager(persistence);
|
||||||
return () => client.removePersistenceManager();
|
return () => client.removePersistenceManager();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// As temporal hack, editor properties are propagated from global variables...
|
// As temporal hack, editor properties are propagated from global variables...
|
||||||
const { mapId, options } = EditorOptionsBulder.build(userLocale.code, hotkey, isTryMode);
|
|
||||||
return persistenceManager ? (
|
return persistenceManager ? (
|
||||||
<>
|
<>
|
||||||
<Editor onAction={setActiveDialog}
|
<Editor onAction={setActiveDialog}
|
||||||
|
Loading…
Reference in New Issue
Block a user