mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 14:47:56 +01:00
Add not null control for mindplot initialization
This commit is contained in:
parent
966d817a02
commit
b9de729053
@ -78,7 +78,14 @@ const Editor = ({
|
|||||||
const [popoverOpen, popoverTarget, widgetManager] = DefaultWidgetManager.useCreate();
|
const [popoverOpen, popoverTarget, widgetManager] = DefaultWidgetManager.useCreate();
|
||||||
const capability = new Capability(options.mode, mapInfo.isLocked());
|
const capability = new Capability(options.mode, mapInfo.isLocked());
|
||||||
|
|
||||||
const mindplotRef = useCallback((component: MindplotWebComponent) => {
|
const mindplotRef: (component: MindplotWebComponent) => void = useCallback(
|
||||||
|
(component: MindplotWebComponent) => {
|
||||||
|
if (!component) {
|
||||||
|
const error = new Error(`Unexpected error during initialization. ${component}`);
|
||||||
|
window.newrelic?.noticeError(error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
const model = new Model(component);
|
const model = new Model(component);
|
||||||
|
|
||||||
// Force refresh after map load ...
|
// Force refresh after map load ...
|
||||||
@ -95,7 +102,9 @@ const Editor = ({
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
setModel(model);
|
setModel(model);
|
||||||
}, []);
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (options.enableKeyboardEvents) {
|
if (options.enableKeyboardEvents) {
|
||||||
|
@ -2,20 +2,18 @@ import Designer from './Designer';
|
|||||||
import buildDesigner from './DesignerBuilder';
|
import buildDesigner from './DesignerBuilder';
|
||||||
import DesignerOptionsBuilder from './DesignerOptionsBuilder';
|
import DesignerOptionsBuilder from './DesignerOptionsBuilder';
|
||||||
import EditorRenderMode from './EditorRenderMode';
|
import EditorRenderMode from './EditorRenderMode';
|
||||||
import LocalStorageManager from './LocalStorageManager';
|
|
||||||
import PersistenceManager from './PersistenceManager';
|
import PersistenceManager from './PersistenceManager';
|
||||||
import WidgetManager from './WidgetManager';
|
import WidgetManager from './WidgetManager';
|
||||||
import mindplotStyles from './styles/mindplot-styles';
|
import mindplotStyles from './styles/mindplot-styles';
|
||||||
import { $notify } from './widget/ToolbarNotifier';
|
import { $notify } from './widget/ToolbarNotifier';
|
||||||
import { $msg } from './Messages';
|
import { $msg } from './Messages';
|
||||||
import DesignerKeyboard from './DesignerKeyboard';
|
import DesignerKeyboard from './DesignerKeyboard';
|
||||||
|
import LocalStorageManager from './LocalStorageManager';
|
||||||
const defaultPersistenceManager = () => new LocalStorageManager('map.xml', false, false);
|
|
||||||
|
|
||||||
export type MindplotWebComponentInterface = {
|
export type MindplotWebComponentInterface = {
|
||||||
id: string;
|
id: string;
|
||||||
mode: string;
|
mode: string;
|
||||||
ref: any;
|
ref: (component: object) => void;
|
||||||
locale?: string;
|
locale?: string;
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@ -35,12 +33,15 @@ class MindplotWebComponent extends HTMLElement {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._shadowRoot = this.attachShadow({ mode: 'open' });
|
this._shadowRoot = this.attachShadow({ mode: 'open' });
|
||||||
|
|
||||||
const mindplotStylesElement = document.createElement('style');
|
const mindplotStylesElement = document.createElement('style');
|
||||||
mindplotStylesElement.innerHTML = mindplotStyles;
|
mindplotStylesElement.innerHTML = mindplotStyles;
|
||||||
this._shadowRoot.appendChild(mindplotStylesElement);
|
this._shadowRoot.appendChild(mindplotStylesElement);
|
||||||
|
|
||||||
const wrapper = document.createElement('div');
|
const wrapper = document.createElement('div');
|
||||||
wrapper.setAttribute('class', 'wise-editor');
|
wrapper.setAttribute('class', 'wise-editor');
|
||||||
wrapper.setAttribute('id', 'mindplot');
|
wrapper.setAttribute('id', 'mindplot');
|
||||||
|
|
||||||
this._shadowRoot.appendChild(wrapper);
|
this._shadowRoot.appendChild(wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +60,8 @@ class MindplotWebComponent extends HTMLElement {
|
|||||||
buildDesigner(persistence?: PersistenceManager, widgetManager?: WidgetManager) {
|
buildDesigner(persistence?: PersistenceManager, widgetManager?: WidgetManager) {
|
||||||
const editorRenderMode = this.getAttribute('mode') as EditorRenderMode;
|
const editorRenderMode = this.getAttribute('mode') as EditorRenderMode;
|
||||||
const locale = this.getAttribute('locale');
|
const locale = this.getAttribute('locale');
|
||||||
const persistenceManager = persistence || defaultPersistenceManager();
|
|
||||||
|
const persistenceManager = persistence || new LocalStorageManager('map.xml', false, false);
|
||||||
const mode = editorRenderMode || 'viewonly';
|
const mode = editorRenderMode || 'viewonly';
|
||||||
const options = DesignerOptionsBuilder.buildOptions({
|
const options = DesignerOptionsBuilder.buildOptions({
|
||||||
persistenceManager,
|
persistenceManager,
|
||||||
@ -97,26 +99,19 @@ class MindplotWebComponent extends HTMLElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setSaveRequired(arg0: boolean) {
|
setSaveRequired(value: boolean) {
|
||||||
this.saveRequired = arg0;
|
this.saveRequired = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSaveRequired() {
|
getSaveRequired() {
|
||||||
return this.saveRequired;
|
return this.saveRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Load map in designer throught persistence manager instance
|
|
||||||
* @param id the map id to be loaded.
|
|
||||||
*/
|
|
||||||
loadMap(id: string): Promise<void> {
|
loadMap(id: string): Promise<void> {
|
||||||
const instance = PersistenceManager.getInstance();
|
const instance = PersistenceManager.getInstance();
|
||||||
return instance.load(id).then((mindmap) => this._designer.loadMap(mindmap));
|
return instance.load(id).then((mindmap) => this._designer.loadMap(mindmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* save the map
|
|
||||||
*/
|
|
||||||
save(saveHistory: boolean) {
|
save(saveHistory: boolean) {
|
||||||
if (!saveHistory && !this.getSaveRequired()) return;
|
if (!saveHistory && !this.getSaveRequired()) return;
|
||||||
console.log('Saving...');
|
console.log('Saving...');
|
||||||
@ -146,22 +141,6 @@ class MindplotWebComponent extends HTMLElement {
|
|||||||
this.setSaveRequired(false);
|
this.setSaveRequired(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
discardChanges() {
|
|
||||||
// Avoid autosave before leaving the page ....
|
|
||||||
// this.setRequireChange(false);
|
|
||||||
|
|
||||||
// Finally call discard function ...
|
|
||||||
const persistenceManager = PersistenceManager.getInstance();
|
|
||||||
const mindmap = this._designer.getMindmap();
|
|
||||||
persistenceManager.discardChanges(mindmap.getId());
|
|
||||||
|
|
||||||
// Unlock map ...
|
|
||||||
this.unlockMap();
|
|
||||||
|
|
||||||
// Reload the page ...
|
|
||||||
window.location.reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
unlockMap() {
|
unlockMap() {
|
||||||
const mindmap = this._designer.getMindmap();
|
const mindmap = this._designer.getMindmap();
|
||||||
const persistenceManager = PersistenceManager.getInstance();
|
const persistenceManager = PersistenceManager.getInstance();
|
||||||
|
Loading…
Reference in New Issue
Block a user