wisemapping-frontend/packages/mindplot/src/components/DesignerBuilder.ts

89 lines
2.9 KiB
TypeScript
Raw Normal View History

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';
import { DesignerOptions } from './DesignerOptionsBuilder';
2021-12-23 19:51:26 +01:00
2022-01-26 07:33:39 +01:00
let designer: Designer;
2021-12-23 19:51:26 +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-31 01:05:22 +01:00
globalThis.mindmapLoadReady = true;
2021-12-23 19:51:26 +01:00
console.log('Map loadded successfully');
});
2022-02-04 06:16:55 +01:00
const onerrorFn = (msg: string, url: string, lineNo: number, columnNo: number, error: Error) => {
const message = [
`Message: ${msg}`,
`URL: ${url}`,
`Line: ${lineNo}`,
`Column: ${columnNo}`,
].join(' - ');
2022-02-12 17:39:33 +01:00
console.error(message);
2022-02-04 06:16:55 +01:00
// Send error to server ...
$.ajax({
method: 'post',
url: '/c/restful/logger/editor',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
data: JSON.stringify({
2022-02-12 19:49:11 +01:00
jsErrorMsg: `${error.name} - ${error.message}`,
jsStack: error.stack,
2022-02-04 06:16:55 +01:00
userAgent: navigator.userAgent,
mapId: options.mapId,
}),
});
2022-02-12 18:38:46 +01:00
2021-12-23 19:51:26 +01:00
// 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-31 01:05:22 +01:00
if (!globalThis.mindmapLoadReady) {
2021-12-23 19:51:26 +01:00
$notifyModal($msg('UNEXPECTED_ERROR_LOADING'));
}
};
2022-02-13 07:02:46 +01:00
// window.onerror = onerrorFn;
2021-12-23 19:51:26 +01:00
// 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) {
const menu = new Menu(designer, 'toolbar');
2021-12-23 19:51:26 +01:00
// If a node has focus, focus can be move to another node using the keys.
2022-01-26 07:33:39 +01:00
designer.cleanScreen = () => {
2021-12-23 19:51:26 +01:00
menu.clear();
};
}
return designer;
}
export default buildDesigner;