2021-12-23 19:51:26 +01:00
|
|
|
/*
|
2021-12-25 23:39:34 +01:00
|
|
|
* Copyright [2021] [wisemapping]
|
2021-12-23 19:51:26 +01:00
|
|
|
*
|
|
|
|
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
|
|
|
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
|
|
|
* "powered by wisemapping" text requirement on every single page;
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the license at
|
|
|
|
*
|
|
|
|
* http://www.wisemapping.org/license
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
import { $assert } from '@wisemapping/core-js';
|
|
|
|
import $ from 'jquery';
|
|
|
|
import PersistenceManager from './PersistenceManager';
|
|
|
|
import Designer from './Designer';
|
|
|
|
import Menu from './widget/Menu';
|
2021-12-25 21:15:56 +01:00
|
|
|
import { $notifyModal } from './widget/ModalDialogNotifier';
|
2021-12-23 19:51:26 +01:00
|
|
|
import { $msg } from './Messages';
|
2022-01-09 19:43:04 +01:00
|
|
|
import { DesignerOptions } from './DesignerOptionsBuilder';
|
2021-12-23 19:51:26 +01:00
|
|
|
|
|
|
|
let designer = null;
|
|
|
|
|
2022-01-09 19:43:04 +01:00
|
|
|
export function buildDesigner(options: DesignerOptions): Designer {
|
2021-12-24 01:35:46 +01:00
|
|
|
const divContainer = $(`#${options.container}`);
|
|
|
|
$assert(divContainer, 'container could not be null');
|
2021-12-23 19:51:26 +01:00
|
|
|
|
|
|
|
// Register load events ...
|
2021-12-24 01:35:46 +01:00
|
|
|
designer = new Designer(options, divContainer);
|
2021-12-23 19:51:26 +01:00
|
|
|
designer.addEvent('loadSuccess', () => {
|
2022-01-09 19:43:04 +01:00
|
|
|
// @ts-ignore
|
2021-12-23 19:51:26 +01:00
|
|
|
window.mindmapLoadReady = true;
|
|
|
|
console.log('Map loadded successfully');
|
|
|
|
});
|
|
|
|
|
2022-01-09 19:43:04 +01:00
|
|
|
const onerrorFn = (message:string, url, lineNo) => {
|
2021-12-23 19:51:26 +01:00
|
|
|
// Close loading dialog ...
|
2022-01-09 19:43:04 +01:00
|
|
|
// @ts-ignore
|
2021-12-23 19:51:26 +01:00
|
|
|
if (window.waitDialog) {
|
2022-01-09 19:43:04 +01:00
|
|
|
// @ts-ignore
|
2022-01-13 17:13:05 +01:00
|
|
|
window.waitDialog.close();
|
2022-01-09 19:43:04 +01:00
|
|
|
// @ts-ignore
|
2021-12-23 19:51:26 +01:00
|
|
|
window.waitDialog = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open error dialog only in case of mindmap loading errors. The rest of the error are reported but not display the dialog.
|
|
|
|
// Remove this in the near future.
|
2022-01-09 19:43:04 +01:00
|
|
|
// @ts-ignore
|
2021-12-23 19:51:26 +01:00
|
|
|
if (!window.mindmapLoadReady) {
|
|
|
|
$notifyModal($msg('UNEXPECTED_ERROR_LOADING'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
window.onerror = onerrorFn;
|
|
|
|
|
|
|
|
// Configure default persistence manager ...
|
|
|
|
const persistence = options.persistenceManager;
|
2021-12-23 20:41:39 +01:00
|
|
|
$assert(persistence, 'persistence must be defined');
|
2021-12-23 19:51:26 +01:00
|
|
|
PersistenceManager.init(persistence);
|
|
|
|
|
|
|
|
// Register toolbar event ...
|
|
|
|
if ($('#toolbar').length) {
|
2022-01-09 19:43:04 +01:00
|
|
|
const menu = new Menu(designer, 'toolbar', options.mapId);
|
2021-12-23 19:51:26 +01:00
|
|
|
|
|
|
|
// If a node has focus, focus can be move to another node using the keys.
|
|
|
|
designer._cleanScreen = function _cleanScreen() {
|
|
|
|
menu.clear();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return designer;
|
|
|
|
}
|
|
|
|
|
2022-01-13 17:13:05 +01:00
|
|
|
export default buildDesigner;
|