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

57 lines
1.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';
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');
});
// 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;