Improve build default options

This commit is contained in:
Paulo Gustavo Veiga 2021-12-23 16:35:46 -08:00
parent b853748e0c
commit 5e461c5da3
7 changed files with 41 additions and 34 deletions

View File

@ -29,11 +29,11 @@ global.$ = $;
let designer = null; let designer = null;
export function buildDesigner(options) { export function buildDesigner(options) {
const container = $(`#${options.container}`); const divContainer = $(`#${options.container}`);
$assert(container, 'container could not be null'); $assert(divContainer, 'container could not be null');
// Register load events ... // Register load events ...
designer = new Designer(options, container); designer = new Designer(options, divContainer);
designer.addEvent('loadSuccess', () => { designer.addEvent('loadSuccess', () => {
window.mindmapLoadReady = true; window.mindmapLoadReady = true;
console.log('Map loadded successfully'); console.log('Map loadded successfully');
@ -72,8 +72,9 @@ export function buildDesigner(options) {
return designer; return designer;
} }
export function buildDefaultOptions(persistence, readOnly = false) { export function buildOptions(options) {
$assert(persistence, 'persistence must be defined'); $assert(options.persistenceManager, 'persistence must be defined');
// Set workspace screen size as default. In this way, resize issues are solved. // Set workspace screen size as default. In this way, resize issues are solved.
const containerSize = { const containerSize = {
height: Number.parseInt(window.screen.height, 10), height: Number.parseInt(window.screen.height, 10),
@ -84,27 +85,28 @@ export function buildDefaultOptions(persistence, readOnly = false) {
height: Number.parseInt(window.innerHeight - 70, 10), // Footer and Header height: Number.parseInt(window.innerHeight - 70, 10), // Footer and Header
width: Number.parseInt(window.innerWidth, 10), width: Number.parseInt(window.innerWidth, 10),
}; };
return {
readOnly, const defaultOptions = {
readOnly: false,
zoom: 0.85, zoom: 0.85,
saveOnLoad: true, saveOnLoad: true,
size: containerSize, size: containerSize,
viewPort, viewPort,
container: 'mindplot', container: 'mindplot',
locale: 'en', locale: 'en',
persistenceManager: persistence,
}; };
return { ...defaultOptions, ...options };
} }
export async function loadOptions(jsonConf, persistence, readOnly = false) { export async function loadOptions(jsonConf, options) {
const result = await $.ajax({ const result = await $.ajax({
url: jsonConf, url: jsonConf,
dataType: 'json', dataType: 'json',
method: 'get', method: 'get',
}); });
result.readOnly = readOnly;
result.persistenceManager = persistence; return { ...result, ...buildOptions(options) };
return result;
} }
export function loadExample(exampleFn) { export function loadExample(exampleFn) {

View File

@ -1,22 +1,13 @@
import { $notify } from '@wisemapping/core-js'; import { $notify } from '@wisemapping/core-js';
import { buildDesigner, buildDefaultOptions } from './components/DesignerBuilder'; import { buildDesigner, buildOptions } from './components/DesignerBuilder';
import RESTPersistenceManager from './components/RestPersistenceManager'; import RESTPersistenceManager from './components/RestPersistenceManager';
import PersistenceManager from './components/PersistenceManager'; import PersistenceManager from './components/PersistenceManager';
import LocalStorageManager from './components/LocalStorageManager'; import LocalStorageManager from './components/LocalStorageManager';
global.memoryPersistence = false;
global.readOnlyMode = false;
global.userOptions = {};
global.locale = 'us';
global.mindmapLocked = false;
global.mapLockedMessage = 'map locked';
global.lockSession = 111111;
global.lockTimestamp = 11111;
// Configure designer options ... // Configure designer options ...
let persistenceManager; let p;
if (!global.memoryPersistence && !global.readOnlyMode) { if (!global.memoryPersistence && !global.readOnlyMode) {
persistenceManager = new RESTPersistenceManager( p = 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',
@ -26,11 +17,12 @@ if (!global.memoryPersistence && !global.readOnlyMode) {
}, },
); );
} else { } else {
// persistenceManager = new LocalStorageManager('c/restful/maps/{id}${hid != null ? '/' : ''}${hid != null ? hid : ''}/document/xml${principal != null ? '' : '-pub'}", true);
// @todo: review ... // @todo: review ...
persistenceManager = new LocalStorageManager('c/restful/maps/{id}', true); // persistenceManager = new LocalStorageManager('c/restful/maps/{id}${hid != null ? '/' : ''}${hid != null ? hid : ''}/document/xml${principal != null ? '' : '-pub'}", true);
p = new LocalStorageManager('c/restful/maps/{id}', true);
} }
const options = buildDefaultOptions(persistenceManager, false);
const options = buildOptions({ persistenceManager: p, isReadOnly: global.isReadOnly || false });
options.zoom = global.userOptions.zoom; options.zoom = global.userOptions.zoom;
// Set map id ... // Set map id ...
@ -45,5 +37,5 @@ const mindmap = persistence.load(global.mapId);
designer.loadMap(mindmap); designer.loadMap(mindmap);
if (global.mindmapLocked) { if (global.mindmapLocked) {
$notify(global.mappL, false); $notify(global.mindmapLockedMsg, false);
} }

View File

@ -1,10 +1,10 @@
import '../css/editor.less'; import '../css/editor.less';
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder'; import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
import { PersistenceManager, LocalStorageManager } from '../../../../src'; import { PersistenceManager, LocalStorageManager } from '../../../../src';
const example = async () => { const example = async () => {
const p = new LocalStorageManager('samples/{id}.xml'); const p = new LocalStorageManager('samples/{id}.xml');
const options = buildDefaultOptions(p); const options = buildOptions({ persistenceManager: p });
const designer = buildDesigner(options); const designer = buildDesigner(options);
designer.addEvent('loadSuccess', () => { designer.addEvent('loadSuccess', () => {

View File

@ -1,11 +1,11 @@
import '../css/embedded.less'; import '../css/embedded.less';
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder'; import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
import { PersistenceManager, LocalStorageManager } from '../../../../src'; import { PersistenceManager, LocalStorageManager } from '../../../../src';
const example = async () => { const example = async () => {
// Options has been defined in by a external ile ? // Options has been defined in by a external ile ?
const p = new LocalStorageManager('samples/{id}.xml'); const p = new LocalStorageManager('samples/{id}.xml');
const options = buildDefaultOptions(p); const options = buildOptions({ persistenceManager: p });
const designer = buildDesigner(options); const designer = buildDesigner(options);
designer.addEvent('loadSuccess', () => { designer.addEvent('loadSuccess', () => {

View File

@ -1,16 +1,17 @@
import '../css/embedded.less'; import '../css/embedded.less';
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder'; import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
import { PersistenceManager, LocalStorageManager } from '../../../../src'; import { PersistenceManager, LocalStorageManager } from '../../../../src';
const example = async () => { const example = async () => {
const p = new LocalStorageManager('samples/{id}.xml'); const p = new LocalStorageManager('samples/{id}.xml');
const options = buildDefaultOptions(p, true); const options = buildOptions({ persistenceManager: p, readOnly: false });
const mapId = 'welcome'; const mapId = 'welcome';
const designer = buildDesigner(options); const designer = buildDesigner(options);
designer.addEvent('loadSuccess', () => { designer.addEvent('loadSuccess', () => {
document.getElementById('mindplot').classList.add('ready'); document.getElementById('mindplot').classList.add('ready');
}); });
// Load map from XML file persisted on disk... // Load map from XML file persisted on disk...
const persistence = PersistenceManager.getInstance(); const persistence = PersistenceManager.getInstance();
const mindmap = persistence.load(mapId); const mindmap = persistence.load(mapId);

View File

@ -13,6 +13,10 @@ module.exports = {
optimization: { optimization: {
usedExports: true, usedExports: true,
}, },
entry: {
mindplot: './src/index.js',
loader: './src/indexLoader.js',
},
mode: 'production', mode: 'production',
devtool: 'source-map', devtool: 'source-map',
module: { module: {

View File

@ -4476,6 +4476,14 @@ compression-webpack-plugin@^7.1.2:
schema-utils "^3.0.0" schema-utils "^3.0.0"
serialize-javascript "^5.0.1" serialize-javascript "^5.0.1"
compression-webpack-plugin@^9.2.0:
version "9.2.0"
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-9.2.0.tgz#57fd539d17c5907eebdeb4e83dcfe2d7eceb9ef6"
integrity sha512-R/Oi+2+UHotGfu72fJiRoVpuRifZT0tTC6UqFD/DUo+mv8dbOow9rVOuTvDv5nPPm3GZhHL/fKkwxwIHnJ8Nyw==
dependencies:
schema-utils "^4.0.0"
serialize-javascript "^6.0.0"
compression@^1.7.4: compression@^1.7.4:
version "1.7.4" version "1.7.4"
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f" resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"