From d4da83497b3e80be64e95f932770742307029671 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 3 Dec 2021 10:58:25 -0800 Subject: [PATCH] Convert to classess --- packages/mindplot/.eslintrc.json | 1 + .../src/components/ActionDispatcher.js | 7 +- packages/mindplot/src/components/Designer.js | 58 +- .../src/components/DesignerActionRunner.js | 17 +- packages/mindplot/src/components/Messages.js | 27 +- .../src/components/PersistenceManager.js | 8 +- .../src/components/RelationshipPivot.js | 3 +- .../mindplot/src/components/ScreenManager.js | 27 +- .../components/StandaloneActionDispatcher.js | 33 +- packages/mindplot/src/components/Workspace.js | 37 +- packages/mindplot/src/components/footer.js | 2 + .../src/components/model/FeatureModel.js | 26 +- .../mindplot/src/components/model/IMindmap.js | 53 +- .../src/components/model/INodeModel.js | 600 +++++++++--------- .../src/components/model/IconModel.js | 20 +- .../src/components/model/LinkModel.js | 24 +- .../mindplot/src/components/model/Mindmap.js | 52 +- .../src/components/model/NodeModel.js | 66 +- .../src/components/model/NoteModel.js | 20 +- .../src/components/model/RelationshipModel.js | 197 +++--- .../persistence/XMLSerializer_Beta.js | 49 +- .../persistence/XMLSerializer_Pela.js | 113 ++-- .../mindplot/src/components/util/Shape.js | 16 +- .../components/widget/ColorPalettePanel.js | 5 +- .../mindplot/src/components/widget/IMenu.js | 3 +- .../widget/KeyboardShortcutTooltip.js | 1 + .../mindplot/src/components/widget/Menu.js | 1 + .../src/components/widget/ToolbarItem.js | 1 + .../src/components/widget/ToolbarNotifier.js | 18 +- .../src/components/widget/ToolbarPaneItem.js | 9 +- packages/mindplot/src/mindplot.js | 26 +- .../test/playground/map-render/js/editor.js | 49 +- 32 files changed, 745 insertions(+), 824 deletions(-) diff --git a/packages/mindplot/.eslintrc.json b/packages/mindplot/.eslintrc.json index 89fb77f1..894ba395 100644 --- a/packages/mindplot/.eslintrc.json +++ b/packages/mindplot/.eslintrc.json @@ -19,6 +19,7 @@ "plugins": ["only-warn"], "rules": { "no-underscore-dangle": "off", + "no-plusplus": "off", "import/no-extraneous-dependencies": ["error", {"devDependencies": ["!cypress/**/*.js"]}] }, "settings": { diff --git a/packages/mindplot/src/components/ActionDispatcher.js b/packages/mindplot/src/components/ActionDispatcher.js index 447806fc..ed0ffc14 100644 --- a/packages/mindplot/src/components/ActionDispatcher.js +++ b/packages/mindplot/src/components/ActionDispatcher.js @@ -16,6 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import Events from './Events'; // noinspection JSUnusedLocalSymbols @@ -102,12 +103,10 @@ const ActionDispatcher = new Class({ }, }); -ActionDispatcher.setInstance = function (dispatcher) { +ActionDispatcher.setInstance = (dispatcher) => { ActionDispatcher._instance = dispatcher; }; -ActionDispatcher.getInstance = function () { - return ActionDispatcher._instance; -}; +ActionDispatcher.getInstance = () => ActionDispatcher._instance; export default ActionDispatcher; diff --git a/packages/mindplot/src/components/Designer.js b/packages/mindplot/src/components/Designer.js index f2a46912..42191529 100644 --- a/packages/mindplot/src/components/Designer.js +++ b/packages/mindplot/src/components/Designer.js @@ -15,6 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; + import Events from './Events'; import Messages from './Messages'; @@ -35,7 +37,7 @@ import Relationship from './Relationship'; import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher'; import TopicFeature from './TopicFeature'; -import NodeGraphUtils from './NodeGraphUtils'; +import { create } from './NodeGraphUtils'; import EventBus from './layout/EventBus'; import EventBusDispatcher from './layout/EventBusDispatcher'; @@ -129,7 +131,7 @@ const Designer = new Class( * forwards to the TopicEventDispatcher or the parent Events class, depending on the type */ addEvent(type, listener) { - if (type == TopicEvent.EDIT || type == TopicEvent.CLICK) { + if (type === TopicEvent.EDIT || type === TopicEvent.CLICK) { const editor = TopicEventDispatcher.getInstance(); editor.addEvent(type, listener); } else { @@ -238,7 +240,7 @@ const Designer = new Class( */ _buildNodeGraph(model, readOnly) { // Create node graph ... - const topic = NodeGraphUtils.create(model, { readOnly }); + const topic = create(model, { readOnly }); this.getModel().addTopic(topic); const me = this; // Add Topic events ... @@ -249,7 +251,7 @@ const Designer = new Class( }); // Register node listeners ... - if (topic.getType() != INodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { // Central Topic doesn't support to be dragged this._dragManager.add(topic); } @@ -265,7 +267,7 @@ const Designer = new Class( const topics = this.getModel().getTopics(); for (let i = 0; i < topics.length; i++) { const t = topics[i]; - if (t.getModel() == targetTopicModel) { + if (t.getModel() === targetTopicModel) { targetTopic = t; // Disconnect the node. It will be connected again later ... model.disconnect(); @@ -280,7 +282,7 @@ const Designer = new Class( const topics = me.getModel().filterSelectedTopics(); const rels = me.getModel().filterSelectedRelationships(); - if (topics.length == 0 || rels.length == 0) { + if (topics.length === 0 || rels.length === 0) { me.fireEvent('onblur'); } }); @@ -289,7 +291,7 @@ const Designer = new Class( const topics = me.getModel().filterSelectedTopics(); const rels = me.getModel().filterSelectedRelationships(); - if (topics.length == 1 || rels.length == 1) { + if (topics.length === 1 || rels.length === 1) { me.fireEvent('onfocus'); } }); @@ -315,7 +317,7 @@ const Designer = new Class( _.each(objects, (object) => { // Disable all nodes on focus but not the current if Ctrl key isn't being pressed if (!$defined(event) || (!event.ctrlKey && !event.metaKey)) { - if (object.isOnFocus() && object != currentObject) { + if (object.isOnFocus() && object !== currentObject) { object.setOnFocus(false); } } @@ -357,7 +359,9 @@ const Designer = new Class( * zoom out by the given factor, or 1.2, if undefined */ zoomOut(factor) { - if (!factor) factor = 1.2; + if (!factor) { + factor = 1.2; + } const model = this.getModel(); const scale = model.getZoom() * factor; @@ -414,7 +418,7 @@ const Designer = new Class( /** paste clipboard contents to the mindmap */ pasteClipboard() { - if (this._clipboard.length == 0) { + if (this._clipboard.length === 0) { $notify($msg('CLIPBOARD_IS_EMPTY')); return; } @@ -430,14 +434,14 @@ const Designer = new Class( /** collapse the subtree of the selected topic */ shrinkSelectedBranch() { const nodes = this.getModel().filterSelectedTopics(); - if (nodes.length <= 0 || nodes.length != 1) { + if (nodes.length <= 0 || nodes.length !== 1) { // If there are more than one node selected, $notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED_COLLAPSE')); return; } // Execute event ... const topic = nodes[0]; - if (topic.getType() != INodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { this._actionDispatcher.shrinkBranch([topic.getId()], !topic.areChildrenShrunken()); } }, @@ -450,7 +454,7 @@ const Designer = new Class( $notify($msg('ONE_TOPIC_MUST_BE_SELECTED')); return; } - if (nodes.length != 1) { + if (nodes.length !== 1) { // If there are more than one node selected, $notify($msg('ONLY_ONE_TOPIC_MUST_BE_SELECTED')); return; @@ -470,7 +474,7 @@ const Designer = new Class( */ _copyNodeProps(sourceModel, targetModel) { // I don't copy the font size if the target is the source is the central topic. - if (sourceModel.getType() != INodeModel.CENTRAL_TOPIC_TYPE) { + if (sourceModel.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { const fontSize = sourceModel.getFontSize(); if (fontSize) { targetModel.setFontSize(fontSize); @@ -585,7 +589,7 @@ const Designer = new Class( // Hack: if parent is central topic, add node below not on opposite side. // This should be done in the layout - if (parentTopic.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (parentTopic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { siblingModel.setOrder(topic.getOrder() + 2); } @@ -601,10 +605,11 @@ const Designer = new Class( */ _createSiblingModel(topic) { let result = null; + let model = null; const parentTopic = topic.getOutgoingConnectedTopic(); if (parentTopic != null) { // Create a new node ... - var model = topic.getModel(); + model = topic.getModel(); const mindmap = model.getMindmap(); result = mindmap.createNode(); @@ -812,7 +817,7 @@ const Designer = new Class( const topics = me.getModel().filterSelectedTopics(); const rels = me.getModel().filterSelectedRelationships(); - if (topics.length == 0 || rels.length == 0) { + if (topics.length === 0 || rels.length === 0) { me.fireEvent('onblur'); } }); @@ -821,7 +826,7 @@ const Designer = new Class( const topics = me.getModel().filterSelectedTopics(); const rels = me.getModel().filterSelectedRelationships(); - if (topics.length == 1 || rels.length == 1) { + if (topics.length === 1 || rels.length === 1) { me.fireEvent('onfocus'); } }); @@ -881,7 +886,7 @@ const Designer = new Class( $notify($msg('ENTITIES_COULD_NOT_BE_DELETED')); return; } - if (topics.length == 1 && topics[0].isCentralTopic()) { + if (topics.length === 1 && topics[0].isCentralTopic()) { $notify($msg('CENTRAL_TOPIC_CAN_NOT_BE_DELETED')); return; } @@ -927,9 +932,7 @@ const Designer = new Class( /** */ changeBackgroundColor(color) { - const validateFunc = function (topic) { - return topic.getShapeType() != TopicShape.LINE; - }; + const validateFunc = (topic) => topic.getShapeType() !== TopicShape.LINE; const validateError = 'Color can not be set to line topics.'; const topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); @@ -940,9 +943,7 @@ const Designer = new Class( /** */ changeBorderColor(color) { - const validateFunc = function (topic) { - return topic.getShapeType() != TopicShape.LINE; - }; + const validateFunc = (topic) => topic.getShapeType() !== TopicShape.LINE; const validateError = 'Color can not be set to line topics.'; const topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); if (topicsIds.length > 0) { @@ -960,11 +961,8 @@ const Designer = new Class( /** */ changeTopicShape(shape) { - const validateFunc = function (topic) { - return !( - topic.getType() == INodeModel.CENTRAL_TOPIC_TYPE && shape == TopicShape.LINE - ); - }; + const validateFunc = (topic) => !(topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE && shape === TopicShape.LINE + ); const validateError = 'Central Topic shape can not be changed to line figure.'; const topicsIds = this.getModel().filterTopicsIds(validateFunc, validateError); diff --git a/packages/mindplot/src/components/DesignerActionRunner.js b/packages/mindplot/src/components/DesignerActionRunner.js index 6cd3401e..92486934 100644 --- a/packages/mindplot/src/components/DesignerActionRunner.js +++ b/packages/mindplot/src/components/DesignerActionRunner.js @@ -15,17 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import DesignerUndoManager from './DesignerUndoManager'; import EventBus from './layout/EventBus'; -const DesignerActionRunner = new Class({ - initialize(commandContext, notifier) { +class DesignerActionRunner { + constructor(commandContext, notifier) { $assert(commandContext, 'commandContext can not be null'); this._undoManager = new DesignerUndoManager(); this._context = commandContext; this._notifier = notifier; - }, + } execute(command) { $assert(command, 'command can not be null'); @@ -33,24 +34,24 @@ const DesignerActionRunner = new Class({ this._undoManager.enqueue(command); this.fireChangeEvent(); EventBus.instance.fireEvent(EventBus.events.DoLayout); - }, + } undo() { this._undoManager.execUndo(this._context); this.fireChangeEvent(); EventBus.instance.fireEvent(EventBus.events.DoLayout); - }, + } redo() { this._undoManager.execRedo(this._context); this.fireChangeEvent(); EventBus.instance.fireEvent(EventBus.events.DoLayout); - }, + } fireChangeEvent() { const event = this._undoManager.buildEvent(); this._notifier.fireEvent('modelUpdate', event); - }, -}); + } +} export default DesignerActionRunner; diff --git a/packages/mindplot/src/components/Messages.js b/packages/mindplot/src/components/Messages.js index 2d9c162f..b76a09fa 100644 --- a/packages/mindplot/src/components/Messages.js +++ b/packages/mindplot/src/components/Messages.js @@ -15,22 +15,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $defined } from '@wisemapping/core-js'; -const Messages = new Class({ +class Messages { + static init(locale) { + let userLocale = $defined(locale) ? locale : 'en'; + let bundle = Messages.BUNDLES[locale]; -}); - -Messages.init = (locale) => { - locale = $defined(locale) ? locale : 'en'; - let bundle = Messages.BUNDLES[locale]; - if (bundle == null && locale.indexOf('_') !== -1) { - // Try to locate without the specialization ... - locale = locale.substring(0, locale.indexOf('_')); - bundle = Messages.BUNDLES[locale]; + if (bundle == null && locale.indexOf('_') !== -1) { + // Try to locate without the specialization ... + userLocale = locale.substring(0, locale.indexOf('_')); + bundle = Messages.BUNDLES[locale]; + } + global.locale = userLocale; + Messages.__bundle = bundle || {}; } - Messages.__bundle = bundle || {}; -}; +} +// @Todo: fix global assignment. global.$msg = function $msg(key) { if (!Messages.__bundle) { Messages.init('en'); @@ -40,5 +42,4 @@ global.$msg = function $msg(key) { }; Messages.BUNDLES = {}; - export default Messages; diff --git a/packages/mindplot/src/components/PersistenceManager.js b/packages/mindplot/src/components/PersistenceManager.js index 59c63683..f61064bb 100644 --- a/packages/mindplot/src/components/PersistenceManager.js +++ b/packages/mindplot/src/components/PersistenceManager.js @@ -15,13 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Core from '@wisemapping/core-js'; +import { $assert, innerXML } from '@wisemapping/core-js'; import XMLSerializerFactory from './persistence/XMLSerializerFactory'; -const core = Core(); - const PersistenceManager = new Class({ - initialize() {}, + initialize() { }, save(mindmap, editorProperties, saveHistory, events, sync) { $assert(mindmap, 'mindmap can not be null'); @@ -32,7 +30,7 @@ const PersistenceManager = new Class({ const serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap); const domMap = serializer.toXML(mindmap); - const mapXml = core.Utils.innerXML(domMap); + const mapXml = innerXML(domMap); const pref = JSON.stringify(editorProperties); try { diff --git a/packages/mindplot/src/components/RelationshipPivot.js b/packages/mindplot/src/components/RelationshipPivot.js index 375b310f..c32f0bc4 100644 --- a/packages/mindplot/src/components/RelationshipPivot.js +++ b/packages/mindplot/src/components/RelationshipPivot.js @@ -16,7 +16,8 @@ * limitations under the License. */ import web2d from '@wisemapping/web2d'; - +import { $assert } from '@wisemapping/core-js'; +import Relationship from './Relationship'; import INodeModel from './model/INodeModel'; import Shape from './util/Shape'; diff --git a/packages/mindplot/src/components/ScreenManager.js b/packages/mindplot/src/components/ScreenManager.js index 36d8e227..78414018 100644 --- a/packages/mindplot/src/components/ScreenManager.js +++ b/packages/mindplot/src/components/ScreenManager.js @@ -15,10 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import web2d from '@wisemapping/web2d'; -const ScreenManager = new Class({ - initialize(divElement) { +class ScreenManager { + constructor(divElement) { $assert(divElement, 'can not be null'); this._divContainer = divElement; this._padding = { x: 0, y: 0 }; @@ -33,17 +34,17 @@ const ScreenManager = new Class({ event.stopPropagation(); event.preventDefault(); }); - }, + } setScale(scale) { $assert(scale, 'Screen scale can not be null'); this._scale = scale; - }, + } addEvent(event, listener) { if (event === 'click') this._clickEvents.push(listener); else this._divContainer.bind(event, listener); - }, + } removeEvent(event, listener) { if (event === 'click') { @@ -51,7 +52,7 @@ const ScreenManager = new Class({ } else { this._divContainer.unbind(event, listener); } - }, + } fireEvent(type, event) { if (type === 'click') { @@ -61,7 +62,7 @@ const ScreenManager = new Class({ } else { this._divContainer.trigger(type, event); } - }, + } _getElementPosition(elem) { // Retrieve current element position. @@ -79,7 +80,7 @@ const ScreenManager = new Class({ // Remove decimal part.. return { x, y }; - }, + } getWorkspaceIconPosition(e) { // Retrieve current icon position. @@ -114,7 +115,7 @@ const ScreenManager = new Class({ // Remove decimal part.. return { x: x + topicPosition.x, y: y + topicPosition.y }; - }, + } getWorkspaceMousePosition(event) { // Retrieve current mouse position. @@ -136,16 +137,16 @@ const ScreenManager = new Class({ // Remove decimal part.. return new web2d.Point(x, y); - }, + } getContainer() { return this._divContainer; - }, + } setOffset(x, y) { this._padding.x = x; this._padding.y = y; - }, -}); + } +} export default ScreenManager; diff --git a/packages/mindplot/src/components/StandaloneActionDispatcher.js b/packages/mindplot/src/components/StandaloneActionDispatcher.js index 53cefe27..740e4f5c 100644 --- a/packages/mindplot/src/components/StandaloneActionDispatcher.js +++ b/packages/mindplot/src/components/StandaloneActionDispatcher.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $defined, $assert } from '@wisemapping/core-js'; import ActionDispatcher from './ActionDispatcher'; import DesignerActionRunner from './DesignerActionRunner'; import AddTopicCommand from './commands/AddTopicCommand'; @@ -27,6 +28,7 @@ import GenericFunctionCommand from './commands/GenericFunctionCommand'; import MoveControlPointCommand from './commands/MoveControlPointCommand'; import ChangeFeatureToTopicCommand from './commands/ChangeFeatureToTopicCommand'; import NodeModel from './model/NodeModel'; +import EventBus from './layout/EventBus'; const StandaloneActionDispatcher = new Class( /** @lends StandaloneActionDispatcher */ { @@ -70,7 +72,7 @@ const StandaloneActionDispatcher = new Class( $assert($defined(topicId), 'topicsId can not be null'); $assert($defined(position), 'position can not be null'); - const commandFunc = function (topic, value) { + const commandFunc = (topic, value) => { const result = topic.getPosition(); EventBus.instance.fireEvent(EventBus.events.NodeMoveEvent, { node: topic.getModel(), @@ -91,7 +93,7 @@ const StandaloneActionDispatcher = new Class( /** */ changeFontStyleToTopic(topicsIds) { - const commandFunc = function (topic) { + const commandFunc = (topic) => { const result = topic.getFontStyle(); const style = result === 'italic' ? 'normal' : 'italic'; topic.setFontStyle(style, true); @@ -105,7 +107,7 @@ const StandaloneActionDispatcher = new Class( changeTextToTopic(topicsIds, text) { $assert($defined(topicsIds), 'topicsIds can not be null'); - const commandFunc = function (topic, value) { + const commandFunc = (topic, value) => { const result = topic.getText(); topic.setText(value); return result; @@ -121,7 +123,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicIds, 'topicIds can not be null'); $assert(fontFamily, 'fontFamily can not be null'); - const commandFunc = function (topic, fontFamily) { + const commandFunc = (topic, fontFamily) => { const result = topic.getFontFamily(); topic.setFontFamily(fontFamily, true); @@ -138,7 +140,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicsIds, 'topicIds can not be null'); $assert(color, 'color can not be null'); - const commandFunc = function (topic, color) { + const commandFunc = (topic, color) => { const result = topic.getFontColor(); topic.setFontColor(color, true); return result; @@ -154,7 +156,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicsIds, 'topicIds can not be null'); $assert(color, 'color can not be null'); - const commandFunc = function (topic, color) { + const commandFunc = (topic, color) => { const result = topic.getBackgroundColor(); topic.setBackgroundColor(color); return result; @@ -170,7 +172,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicsIds, 'topicIds can not be null'); $assert(color, 'topicIds can not be null'); - const commandFunc = function (topic, color) { + const commandFunc = (topic, color) => { const result = topic.getBorderColor(); topic.setBorderColor(color); return result; @@ -186,7 +188,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicsIds, 'topicIds can not be null'); $assert(size, 'size can not be null'); - const commandFunc = function (topic, size) { + const commandFunc = (topic, size) => { const result = topic.getFontSize(); topic.setFontSize(size, true); @@ -203,7 +205,7 @@ const StandaloneActionDispatcher = new Class( $assert(topicsIds, 'topicsIds can not be null'); $assert(shapeType, 'shapeType can not be null'); - const commandFunc = function (topic, shapeType) { + const commandFunc = (topic, shapeType) => { const result = topic.getShapeType(); topic.setShapeType(shapeType, true); return result; @@ -217,7 +219,7 @@ const StandaloneActionDispatcher = new Class( changeFontWeightToTopic(topicsIds) { $assert(topicsIds, 'topicsIds can not be null'); - const commandFunc = function (topic) { + const commandFunc = (topic) => { const result = topic.getFontWeight(); const weight = result === 'bold' ? 'normal' : 'bold'; topic.setFontWeight(weight, true); @@ -234,7 +236,7 @@ const StandaloneActionDispatcher = new Class( shrinkBranch(topicsIds, collapse) { $assert(topicsIds, 'topicsIds can not be null'); - const commandFunc = function (topic, isShrink) { + const commandFunc = (topic, isShrink) => { topic.setChildrenShrunken(isShrink); return !isShrink; }; @@ -293,12 +295,9 @@ const CommandContext = new Class( const ids = designerTopics.map((topic) => topic.getId()); $assert( result.length === topicsIds.length, - `Could not find topic. Result:${ - result - }, Filter Criteria:${ - topicsIds - }, Current Topics: [${ - ids + `Could not find topic. Result:${result + }, Filter Criteria:${topicsIds + }, Current Topics: [${ids }]`, ); } diff --git a/packages/mindplot/src/components/Workspace.js b/packages/mindplot/src/components/Workspace.js index 80c3be05..80d8d672 100644 --- a/packages/mindplot/src/components/Workspace.js +++ b/packages/mindplot/src/components/Workspace.js @@ -15,10 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import web2d from '@wisemapping/web2d'; -const Workspace = new Class({ - initialize(screenManager, zoom) { +class Workspace { + constructor(screenManager, zoom) { // Create a suitable container ... $assert(screenManager, 'Div container can not be null'); $assert(zoom, 'zoom container can not be null'); @@ -41,7 +42,7 @@ const Workspace = new Class({ // Register drag events ... this._registerDragEvents(); this._eventsEnabled = true; - }, + } _createWorkspace() { // Initialize workspace ... @@ -60,7 +61,7 @@ const Workspace = new Class({ }; web2d.Toolkit.init(); return new web2d.Workspace(workspaceProfile); - }, + } append(shape) { if ($defined(shape.addToWorkspace)) { @@ -68,7 +69,7 @@ const Workspace = new Class({ } else { this._workspace.append(shape); } - }, + } removeChild(shape) { // Element is a node, not a web2d element? @@ -77,21 +78,21 @@ const Workspace = new Class({ } else { this._workspace.removeChild(shape); } - }, + } addEvent(type, listener) { this._workspace.addEvent(type, listener); - }, + } removeEvent(type, listener) { $assert(type, 'type can not be null'); $assert(listener, 'listener can not be null'); this._workspace.removeEvent(type, listener); - }, + } getSize() { return this._workspace.getCoordSize(); - }, + } setZoom(zoom, center) { this._zoom = zoom; @@ -134,23 +135,23 @@ const Workspace = new Class({ // Some changes in the screen. Let's fire an update event... this._screenManager.fireEvent('update'); - }, + } getScreenManager() { return this._screenManager; - }, + } enableWorkspaceEvents(value) { this._eventsEnabled = value; - }, + } isWorkspaceEventsEnabled() { return this._eventsEnabled; - }, + } dumpNativeChart() { return this._workspace.dumpNativeChart(); - }, + } _registerDragEvents() { const workspace = this._workspace; @@ -191,7 +192,7 @@ const Workspace = new Class({ screenManager.addEvent('mousemove', workspace._mouseMoveListener); // Register mouse up listeners ... - workspace._mouseUpListener = function (event) { + workspace._mouseUpListener = function () { screenManager.removeEvent('mousemove', workspace._mouseMoveListener); screenManager.removeEvent('mouseup', workspace._mouseUpListener); workspace._mouseUpListener = null; @@ -214,11 +215,11 @@ const Workspace = new Class({ } }; screenManager.addEvent('mousedown', mouseDownListener); - }, + } setViewPort(size) { this._viewPort = size; - }, -}); + } +} export default Workspace; diff --git a/packages/mindplot/src/components/footer.js b/packages/mindplot/src/components/footer.js index 4ddae25c..cd288c72 100644 --- a/packages/mindplot/src/components/footer.js +++ b/packages/mindplot/src/components/footer.js @@ -1,3 +1,5 @@ +import $ from '@libraries/jquery-2.1.0'; + try { $(document).trigger('loadcomplete', 'mind'); } catch (e) { diff --git a/packages/mindplot/src/components/model/FeatureModel.js b/packages/mindplot/src/components/model/FeatureModel.js index ac93b60c..ca3e0860 100644 --- a/packages/mindplot/src/components/model/FeatureModel.js +++ b/packages/mindplot/src/components/model/FeatureModel.js @@ -16,14 +16,14 @@ * limitations under the License. */ -const FeatureModel = new Class(/** @lends FeatureModel */{ +class FeatureModel { /** * @constructs * @param type * @throws will throw an exception if type is null or undefined * assigns a unique id and the given type to the new model */ - initialize(type) { + constructor(type) { $assert(type, 'type can not be null'); this._id = FeatureModel._nextUUID(); @@ -31,51 +31,49 @@ const FeatureModel = new Class(/** @lends FeatureModel */{ this._attributes = {}; // Create type method ... - this[`is${$.camelCase(type)}Model`] = function () { - return true; - }; - }, + this[`is${$.camelCase(type)}Model`] = () => true; + } /** */ getAttributes() { return Object.clone(this._attributes); - }, + } /** */ setAttributes(attributes) { for (key in attributes) { this[`set${key.capitalize()}`](attributes[key]); } - }, + } /** */ setAttribute(key, value) { $assert(key, 'key id can not be null'); this._attributes[key] = value; - }, + } /** */ getAttribute(key) { $assert(key, 'key id can not be null'); return this._attributes[key]; - }, + } /** */ getId() { return this._id; - }, + } /** */ setId(id) { this._id = id; - }, + } /** */ getType() { return this._type; - }, -}); + } +} FeatureModel._nextUUID = function _nextUUID() { if (!$defined(FeatureModel._uuid)) { diff --git a/packages/mindplot/src/components/model/IMindmap.js b/packages/mindplot/src/components/model/IMindmap.js index 90a39cbd..5d328eea 100644 --- a/packages/mindplot/src/components/model/IMindmap.js +++ b/packages/mindplot/src/components/model/IMindmap.js @@ -16,69 +16,60 @@ * limitations under the License. */ -const IMindmap = new Class(/** @lends IMindmap */{ - /** - * @constructs - * @abstract - */ - initialize() { - throw 'Unsupported operation'; - }, - - /** */ +class IMindmap { getCentralTopic() { return this.getBranches()[0]; - }, + } /** @abstract */ getDescription() { throw 'Unsupported operation'; - }, + } /** @abstract */ setDescription(value) { throw 'Unsupported operation'; - }, + } /** @abstract */ getId() { throw 'Unsupported operation'; - }, + } /** @abstract */ setId(id) { throw 'Unsupported operation'; - }, + } /** @abstract */ getVersion() { throw 'Unsupported operation'; - }, + } /** @abstract */ setVersion(version) { throw 'Unsupported operation'; - }, + } /** @abstract */ addBranch(nodeModel) { throw 'Unsupported operation'; - }, + } /** @abstract */ getBranches() { throw 'Unsupported operation'; - }, + } /** @abstract */ removeBranch(node) { throw 'Unsupported operation'; - }, + } /** @abstract */ getRelationships() { throw 'Unsupported operation'; - }, + } /** * @param parent @@ -94,7 +85,7 @@ const IMindmap = new Class(/** @lends IMindmap */{ // Remove from the branch ... this.removeBranch(child); - }, + } /** * @param child @@ -108,32 +99,32 @@ const IMindmap = new Class(/** @lends IMindmap */{ parent.removeChild(child); this.addBranch(child); - }, + } /** @abstract */ hasAlreadyAdded(node) { throw 'Unsupported operation'; - }, + } /** @abstract */ createNode(type, id) { throw 'Unsupported operation'; - }, + } /** @abstract */ createRelationship(fromNode, toNode) { throw 'Unsupported operation'; - }, + } /** @abstract */ addRelationship(rel) { throw 'Unsupported operation'; - }, + } /** @abstract */ deleteRelationship(relationship) { throw 'Unsupported operation'; - }, + } /** */ inspect() { @@ -155,7 +146,7 @@ const IMindmap = new Class(/** @lends IMindmap */{ result = `${result} } `; return result; - }, + } /** * @param target @@ -175,7 +166,7 @@ const IMindmap = new Class(/** @lends IMindmap */{ snode.copyTo(tnode); target.addBranch(tnode); }); - }, -}); + } +} export default IMindmap; diff --git a/packages/mindplot/src/components/model/INodeModel.js b/packages/mindplot/src/components/model/INodeModel.js index c8ac8556..0002a4dc 100644 --- a/packages/mindplot/src/components/model/INodeModel.js +++ b/packages/mindplot/src/components/model/INodeModel.js @@ -1,11 +1,3 @@ -/* eslint-disable no-shadow */ -/* eslint-disable no-throw-literal */ -/* eslint-disable no-unused-vars */ -/* eslint-disable no-eval */ -/* eslint-disable radix */ -/* eslint-disable no-restricted-globals */ -/* eslint-disable no-param-reassign */ -/* eslint-disable no-underscore-dangle */ /* * Copyright [2015] [wisemapping] * @@ -23,365 +15,357 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $assert, $defined } from '@wisemapping/core-js'; import _ from '../../../../../libraries/underscore-min'; -const core = coreJs(); +class INodeModel { + constructor(mindmap) { + $assert(mindmap && mindmap.getBranches, 'mindmap can not be null'); + this._mindmap = mindmap; + } -const INodeModel = new Class( - /** @lends INodeModel */ { - /** - * @constructs - * @param mindmap - */ - initialize(mindmap) { - core.Function.$assert(mindmap && mindmap.getBranches, 'mindmap can not be null'); - this._mindmap = mindmap; - }, + /** */ + getId() { + return this.getProperty('id'); + } - /** */ - getId() { - return this.getProperty('id'); - }, + /** */ + setId(id) { + if ($defined(id) && id > INodeModel._uuid) { + INodeModel._uuid = id; + } + if (!$defined(id)) { + id = INodeModel._nextUUID(); + } - /** */ - setId(id) { - if (core.Function.$defined(id) && id > INodeModel._uuid) { - INodeModel._uuid = id; - } - if (!core.Function.$defined(id)) { - id = INodeModel._nextUUID(); - } + this.putProperty('id', id); + } - this.putProperty('id', id); - }, + /** */ + getType() { + return this.getProperty('type'); + } - /** */ - getType() { - return this.getProperty('type'); - }, + /** */ + setType(type) { + this.putProperty('type', type); + } - /** */ - setType(type) { - this.putProperty('type', type); - }, + /** */ + setText(text) { + this.putProperty('text', text); + } - /** */ - setText(text) { - this.putProperty('text', text); - }, + /** */ + getText() { + return this.getProperty('text'); + } - /** */ - getText() { - return this.getProperty('text'); - }, + /** */ + setPosition(x, y) { + $assert(!Number.isNaN(parseInt(x, 10)), `x position is not valid:${x}`); + $assert(!Number.isNaN(parseInt(y, 10)), `y position is not valid:${y}`); + this.putProperty('position', `{x:${parseInt(x, 10)},y:${parseInt(y, 10)}}`); + } - /** */ - setPosition(x, y) { - core.Function.$assert(!isNaN(parseInt(x)), `x position is not valid:${x}`); - core.Function.$assert(!isNaN(parseInt(y)), `y position is not valid:${y}`); - this.putProperty('position', `{x:${parseInt(x)},y:${parseInt(y)}}`); - }, + /** */ + getPosition() { + const value = this.getProperty('position'); + let result = null; + if (value != null) { + result = eval(`(${value})`); + } + return result; + } - /** */ - getPosition() { - const value = this.getProperty('position'); - let result = null; - if (value != null) { - result = eval(`(${value})`); - } - return result; - }, + /** */ + setImageSize(width, height) { + this.putProperty('imageSize', `{width:${width},height:${height}}`); + } - /** */ - setImageSize(width, height) { - this.putProperty('imageSize', `{width:${width},height:${height}}`); - }, + /** */ + getImageSize() { + const value = this.getProperty('imageSize'); + let result = null; + if (value != null) { + result = eval(`(${value})`); + } + return result; + } - /** */ - getImageSize() { - const value = this.getProperty('imageSize'); - let result = null; - if (value != null) { - result = eval(`(${value})`); - } - return result; - }, + /** */ + setImageUrl(url) { + this.putProperty('imageUrl', url); + } - /** */ - setImageUrl(url) { - this.putProperty('imageUrl', url); - }, + /** */ + getMetadata() { + return this.getProperty('metadata'); + } - /** */ - getMetadata() { - return this.getProperty('metadata'); - }, + /** */ + setMetadata(json) { + this.putProperty('metadata', json); + } - /** */ - setMetadata(json) { - this.putProperty('metadata', json); - }, + /** */ + getImageUrl() { + return this.getProperty('imageUrl'); + } - /** */ - getImageUrl() { - return this.getProperty('imageUrl'); - }, + /** */ + getMindmap() { + return this._mindmap; + } - /** */ - getMindmap() { - return this._mindmap; - }, + /** + * lets the mindmap handle the disconnect node operation + * @see mindplot.model.IMindmap.disconnect + */ + disconnect() { + const mindmap = this.getMindmap(); + mindmap.disconnect(this); + } - /** - * lets the mindmap handle the disconnect node operation - * @see mindplot.model.IMindmap.disconnect - */ - disconnect() { - const mindmap = this.getMindmap(); - mindmap.disconnect(this); - }, + /** */ + getShapeType() { + return this.getProperty('shapeType'); + } - /** */ - getShapeType() { - return this.getProperty('shapeType'); - }, + /** */ + setShapeType(type) { + this.putProperty('shapeType', type); + } - /** */ - setShapeType(type) { - this.putProperty('shapeType', type); - }, + /** */ + setOrder(value) { + $assert( + (typeof value === 'number' && isFinite(value)) || value == null, + 'Order must be null or a number', + ); + this.putProperty('order', value); + } - /** */ - setOrder(value) { - core.Function.$assert( - (typeof value === 'number' && isFinite(value)) || value == null, - 'Order must be null or a number', - ); - this.putProperty('order', value); - }, + /** */ + getOrder() { + return this.getProperty('order'); + } - /** */ - getOrder() { - return this.getProperty('order'); - }, + /** */ + setFontFamily(fontFamily) { + this.putProperty('fontFamily', fontFamily); + } - /** */ - setFontFamily(fontFamily) { - this.putProperty('fontFamily', fontFamily); - }, + /** */ + getFontFamily() { + return this.getProperty('fontFamily'); + } - /** */ - getFontFamily() { - return this.getProperty('fontFamily'); - }, + /** */ + setFontStyle(fontStyle) { + this.putProperty('fontStyle', fontStyle); + } - /** */ - setFontStyle(fontStyle) { - this.putProperty('fontStyle', fontStyle); - }, + /** */ + getFontStyle() { + return this.getProperty('fontStyle'); + } - /** */ - getFontStyle() { - return this.getProperty('fontStyle'); - }, + /** */ + setFontWeight(weight) { + this.putProperty('fontWeight', weight); + } - /** */ - setFontWeight(weight) { - this.putProperty('fontWeight', weight); - }, + /** */ + getFontWeight() { + return this.getProperty('fontWeight'); + } - /** */ - getFontWeight() { - return this.getProperty('fontWeight'); - }, + /** */ + setFontColor(color) { + this.putProperty('fontColor', color); + } - /** */ - setFontColor(color) { - this.putProperty('fontColor', color); - }, + /** */ + getFontColor() { + return this.getProperty('fontColor'); + } - /** */ - getFontColor() { - return this.getProperty('fontColor'); - }, + /** */ + setFontSize(size) { + this.putProperty('fontSize', size); + } - /** */ - setFontSize(size) { - this.putProperty('fontSize', size); - }, + /** */ + getFontSize() { + return this.getProperty('fontSize'); + } - /** */ - getFontSize() { - return this.getProperty('fontSize'); - }, + /** */ + getBorderColor() { + return this.getProperty('borderColor'); + } - /** */ - getBorderColor() { - return this.getProperty('borderColor'); - }, + /** */ + setBorderColor(color) { + this.putProperty('borderColor', color); + } - /** */ - setBorderColor(color) { - this.putProperty('borderColor', color); - }, + /** */ + getBackgroundColor() { + return this.getProperty('backgroundColor'); + } - /** */ - getBackgroundColor() { - return this.getProperty('backgroundColor'); - }, + /** */ + setBackgroundColor(color) { + this.putProperty('backgroundColor', color); + } - /** */ - setBackgroundColor(color) { - this.putProperty('backgroundColor', color); - }, + /** */ + areChildrenShrunken() { + const result = this.getProperty('shrunken'); + $defined(result) ? result : false; + } - /** */ - areChildrenShrunken() { - const result = this.getProperty('shrunken'); - return core.Function.$defined(result) ? result : false; - }, + /** + * @return {Boolean} true if the children nodes are hidden by the shrink option + */ + setChildrenShrunken(value) { + this.putProperty('shrunken', value); + } - /** - * @return {Boolean} true if the children nodes are hidden by the shrink option - */ - setChildrenShrunken(value) { - this.putProperty('shrunken', value); - }, + /** + * @return {Boolean} true + */ + isNodeModel() { + return true; + } - /** - * @return {Boolean} true - */ - isNodeModel() { - return true; - }, + /** + * @return {Boolean} true if the node model has a parent assigned to it + */ + isConnected() { + return this.getParent() != null; + } - /** - * @return {Boolean} true if the node model has a parent assigned to it - */ - isConnected() { - return this.getParent() != null; - }, + /** @abstract */ + append(node) { + throw 'Unsupported operation'; + } - /** @abstract */ - append(node) { - throw 'Unsupported operation'; - }, + /** + * lets the mindmap handle the connect node operation + * @throws will throw an error if parent is null or undefined + * @see mindplot.model.IMindmap.connect + */ + connectTo(parent) { + $assert(parent, 'parent can not be null'); + const mindmap = this.getMindmap(); + mindmap.connect(parent, this); + } - /** - * lets the mindmap handle the connect node operation - * @throws will throw an error if parent is null or undefined - * @see mindplot.model.IMindmap.connect - */ - connectTo(parent) { - core.Function.$assert(parent, 'parent can not be null'); - const mindmap = this.getMindmap(); - mindmap.connect(parent, this); - }, + /** + * @param target + * @return target + */ + copyTo(target) { + const source = this; + // Copy properties ... + const keys = source.getPropertiesKeys(); + _.each(keys, (key) => { + const value = source.getProperty(key); + target.putProperty(key, value); + }); - /** - * @param target - * @return target - */ - copyTo(target) { - const source = this; - // Copy properties ... - const keys = source.getPropertiesKeys(); - _.each(keys, (key) => { - const value = source.getProperty(key); - target.putProperty(key, value); - }); + // Copy children ... + const children = this.getChildren(); + const tmindmap = target.getMindmap(); - // Copy children ... - const children = this.getChildren(); - const tmindmap = target.getMindmap(); + _.each((children, snode) => { + const tnode = tmindmap.createNode(snode.getType(), snode.getId()); + snode.copyTo(tnode); + target.append(tnode); + }); - _.each((children, snode) => { - const tnode = tmindmap.createNode(snode.getType(), snode.getId()); - snode.copyTo(tnode); - target.append(tnode); - }); + return target; + } - return target; - }, + /** + * lets parent handle the delete node operation, or, if none defined, calls the mindmap to + * remove the respective branch + */ + deleteNode() { + const mindmap = this.getMindmap(); - /** - * lets parent handle the delete node operation, or, if none defined, calls the mindmap to - * remove the respective branch - */ - deleteNode() { - const mindmap = this.getMindmap(); + // console.log("Before:" + mindmap.inspect()); + const parent = this.getParent(); + if ($defined(parent)) { + parent.removeChild(this); + } else { + // If it has not parent, it must be an isolate topic ... + mindmap.removeBranch(this); + } + // It's an isolated node. It must be a hole branch ... + // console.log("After:" + mindmap.inspect()); + } - // console.log("Before:" + mindmap.inspect()); - const parent = this.getParent(); - if (core.Function.$defined(parent)) { - parent.removeChild(this); - } else { - // If it has not parent, it must be an isolate topic ... - mindmap.removeBranch(this); - } - // It's an isolated node. It must be a hole branch ... - // console.log("After:" + mindmap.inspect()); - }, + /** @abstract */ + getPropertiesKeys() { + throw 'Unsupported operation'; + } - /** @abstract */ - getPropertiesKeys() { - throw 'Unsupported operation'; - }, + /** @abstract */ + putProperty(key, value) { + throw 'Unsupported operation'; + } - /** @abstract */ - putProperty(key, value) { - throw 'Unsupported operation'; - }, + /** @abstract */ + setParent(parent) { + throw 'Unsupported operation'; + } - /** @abstract */ - setParent(parent) { - throw 'Unsupported operation'; - }, + /** @abstract */ + getChildren() { + throw 'Unsupported operation'; + } - /** @abstract */ - getChildren() { - throw 'Unsupported operation'; - }, + /** @abstract */ + getParent() { + throw 'Unsupported operation'; + } - /** @abstract */ - getParent() { - throw 'Unsupported operation'; - }, + /** @abstract */ + clone() { + throw 'Unsupported operation'; + } - /** @abstract */ - clone() { - throw 'Unsupported operation'; - }, + /** */ + inspect() { + let result = `{ type: ${this.getType()} , id: ${this.getId()} , text: ${this.getText()}`; - /** */ - inspect() { - let result = `{ type: ${this.getType()} , id: ${this.getId()} , text: ${this.getText()}`; - - const children = this.getChildren(); - if (children.length > 0) { - result = `${result}, children: {(size:${children.length}`; - _.each(children, (node) => { - result = `${result}=> (`; - const keys = node.getPropertiesKeys(); - _.each(keys, (key) => { - const value = node.getProperty(key); - result = `${result + key}:${value},`; - }); - result = `${result}}`; + const children = this.getChildren(); + if (children.length > 0) { + result = `${result}, children: {(size:${children.length}`; + _.each(children, (node) => { + result = `${result}=> (`; + const keys = node.getPropertiesKeys(); + _.each(keys, (key) => { + const value = node.getProperty(key); + result = `${result + key}:${value},`; }); - } + result = `${result}}`; + }); + } - result = `${result} }`; - return result; - }, + result = `${result} }`; + return result; + } - /** @abstract */ - removeChild(child) { - throw 'Unsupported operation'; - }, - }, -); + /** @abstract */ + removeChild(child) { + throw 'Unsupported operation'; + } +} /** * @enum {String} @@ -418,7 +402,7 @@ INodeModel.MAIN_TOPIC_TO_MAIN_TOPIC_DISTANCE = 220; * @todo: This method must be implemented. (unascribed) */ INodeModel._nextUUID = () => { - if (!core.Function.$defined(INodeModel._uuid)) { + if (!$defined(INodeModel._uuid)) { INodeModel._uuid = 0; } diff --git a/packages/mindplot/src/components/model/IconModel.js b/packages/mindplot/src/components/model/IconModel.js index 279be526..4896a7a7 100644 --- a/packages/mindplot/src/components/model/IconModel.js +++ b/packages/mindplot/src/components/model/IconModel.js @@ -17,29 +17,23 @@ */ import FeatureModel from './FeatureModel'; -const IconModel = new Class(/** @lends IconModel */{ - Extends: FeatureModel, - /** - * @constructs - * @param attributes - * @extends mindplot.model.FeatureModel - */ - initialize(attributes) { - this.parent(IconModel.FEATURE_TYPE); +class IconModel extends FeatureModel { + constructor(attributes) { + super(IconModel.FEATURE_TYPE); this.setIconType(attributes.id); - }, + } /** @return the icon type id */ getIconType() { return this.getAttribute('id'); - }, + } /** @param {String} iconType the icon type id */ setIconType(iconType) { $assert(iconType, 'iconType id can not be null'); this.setAttribute('id', iconType); - }, -}); + } +} /** * @constant diff --git a/packages/mindplot/src/components/model/LinkModel.js b/packages/mindplot/src/components/model/LinkModel.js index 588e20b0..9e698fae 100644 --- a/packages/mindplot/src/components/model/LinkModel.js +++ b/packages/mindplot/src/components/model/LinkModel.js @@ -17,22 +17,16 @@ */ import FeatureModel from './FeatureModel'; -const LinkModel = new Class(/** @lends LinkModel */{ - Extends: FeatureModel, - /** - * @constructs - * @param attributes - * @extends mindplot.model.FeatureModel - */ - initialize(attributes) { - this.parent(LinkModel.FEATURE_TYPE); +class LinkModel extends FeatureModel { + constructor(attributes) { + super(LinkModel.FEATURE_TYPE); this.setUrl(attributes.url); - }, + } /** @return {String} the url attribute value */ getUrl() { return this.getAttribute('url'); - }, + } /** * @param {String} url a URL provided by the user to set the link to @@ -46,7 +40,7 @@ const LinkModel = new Class(/** @lends LinkModel */{ const type = fixedUrl.contains('mailto:') ? 'mail' : 'url'; this.setAttribute('urlType', type); - }, + } // url format is already checked in LinkEditor.checkUrl _fixUrl(url) { @@ -55,7 +49,7 @@ const LinkModel = new Class(/** @lends LinkModel */{ result = `http://${result}`; } return result; - }, + } /** * @param {String} urlType the url type, either 'mail' or 'url' @@ -64,8 +58,8 @@ const LinkModel = new Class(/** @lends LinkModel */{ setUrlType(urlType) { $assert(urlType, 'urlType can not be null'); this.setAttribute('urlType', urlType); - }, -}); + } +} /** * @constant diff --git a/packages/mindplot/src/components/model/Mindmap.js b/packages/mindplot/src/components/model/Mindmap.js index fe4074b2..5967e758 100644 --- a/packages/mindplot/src/components/model/Mindmap.js +++ b/packages/mindplot/src/components/model/Mindmap.js @@ -21,52 +21,46 @@ import NodeModel from './NodeModel'; import RelationshipModel from './RelationshipModel'; import ModelCodeName from '../persistence/ModelCodeName'; -const Mindmap = new Class(/** @lends Mindmap */{ - Extends: IMindmap, - /** - * @constructs - * @param id - * @param version - * @extends mindplot.model.IMindmap - */ - initialize(id, version) { +class Mindmap extends IMindmap { + constructor(id, version) { + super(); $assert(id, 'Id can not be null'); this._branches = []; this._description = null; this._relationships = []; this._version = $defined(version) ? version : ModelCodeName.TANGO; this._id = id; - }, + } /** */ getDescription() { return this._description; - }, + } /** */ setDescription(value) { this._description = value; - }, + } /** */ getId() { return this._id; - }, + } /** */ setId(id) { this._id = id; - }, + } /** */ getVersion() { return this._version; - }, + } /** */ setVersion(version) { this._version = version; - }, + } /** * @param {mindplot.model.NodeModel} nodeModel @@ -76,7 +70,7 @@ const Mindmap = new Class(/** @lends Mindmap */{ addBranch(nodeModel) { $assert(nodeModel && nodeModel.isNodeModel(), 'Add node must be invoked with model objects'); const branches = this.getBranches(); - if (branches.length == 0) { + if (branches.length === 0) { $assert(nodeModel.getType() == INodeModel.CENTRAL_TOPIC_TYPE, 'First element must be the central topic'); nodeModel.setPosition(0, 0); } else { @@ -84,7 +78,7 @@ const Mindmap = new Class(/** @lends Mindmap */{ } this._branches.push(nodeModel); - }, + } /** * @param nodeModel @@ -92,17 +86,17 @@ const Mindmap = new Class(/** @lends Mindmap */{ removeBranch(nodeModel) { $assert(nodeModel && nodeModel.isNodeModel(), 'Remove node must be invoked with model objects'); return this._branches.erase(nodeModel); - }, + } /** */ getBranches() { return this._branches; - }, + } /** */ getRelationships() { return this._relationships; - }, + } /** * @param node @@ -119,7 +113,7 @@ const Mindmap = new Class(/** @lends Mindmap */{ break; } } - }, + } /** * @param type @@ -129,7 +123,7 @@ const Mindmap = new Class(/** @lends Mindmap */{ createNode(type, id) { type = !$defined(type) ? INodeModel.MAIN_TOPIC_TYPE : type; return new NodeModel(type, this, id); - }, + } /** * @param sourceNodeId @@ -143,21 +137,21 @@ const Mindmap = new Class(/** @lends Mindmap */{ $assert($defined(targetNodeId), 'to node cannot be null'); return new RelationshipModel(sourceNodeId, targetNodeId); - }, + } /** * @param relationship */ addRelationship(relationship) { this._relationships.push(relationship); - }, + } /** * @param relationship */ deleteRelationship(relationship) { this._relationships.erase(relationship); - }, + } /** * @param id @@ -173,14 +167,14 @@ const Mindmap = new Class(/** @lends Mindmap */{ } } return result; - }, -}); + } +} /** * @param mapId * @return an empty mindmap with central topic only */ -Mindmap.buildEmpty = function (mapId) { +Mindmap.buildEmpty = (mapId) => { const result = new Mindmap(mapId); const node = result.createNode(INodeModel.CENTRAL_TOPIC_TYPE, 0); result.addBranch(node); diff --git a/packages/mindplot/src/components/model/NodeModel.js b/packages/mindplot/src/components/model/NodeModel.js index 6933ea22..afb9ead9 100644 --- a/packages/mindplot/src/components/model/NodeModel.js +++ b/packages/mindplot/src/components/model/NodeModel.js @@ -18,27 +18,19 @@ import INodeModel from './INodeModel'; import TopicFeature from '../TopicFeature'; -const NodeModel = new Class(/** @lends NodeModel */{ - Extends: INodeModel, - /** - * @constructs - * @param {String} type node type - * @param mindmap - * @param id - */ - initialize(type, mindmap, id) { +class NodeModel extends INodeModel { + constructor(type, mindmap, id) { $assert(type, 'Node type can not be null'); $assert(mindmap, 'mindmap can not be null'); + super(mindmap); this._properties = {}; - - this.parent(mindmap); this.setId(id); this.setType(type); this.areChildrenShrunken(false); this._children = []; this._feature = []; - }, + } /** * @param type @@ -47,7 +39,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ */ createFeature(type, attributes) { return TopicFeature.createModel(type, attributes); - }, + } /** * @param feature @@ -56,12 +48,12 @@ const NodeModel = new Class(/** @lends NodeModel */{ addFeature(feature) { $assert(feature, 'feature can not be null'); this._feature.push(feature); - }, + } /** */ getFeatures() { return this._feature; - }, + } /** * @param feature @@ -72,8 +64,8 @@ const NodeModel = new Class(/** @lends NodeModel */{ $assert(feature, 'feature can not be null'); const size = this._feature.length; this._feature = this._feature.filter((f) => feature.getId() != f.getId()); - $assert(size - 1 == this._feature.length, 'Could not be removed ...'); - }, + $assert(size - 1 === this._feature.length, 'Could not be removed ...'); + } /** * @param {String} type the feature type, e.g. icon or link @@ -81,8 +73,8 @@ const NodeModel = new Class(/** @lends NodeModel */{ */ findFeatureByType(type) { $assert(type, 'type can not be null'); - return this._feature.filter((feature) => feature.getType() == type); - }, + return this._feature.filter((feature) => feature.getType() === type); + } /** * @param {String} id @@ -92,15 +84,15 @@ const NodeModel = new Class(/** @lends NodeModel */{ */ findFeatureById(id) { $assert($defined(id), 'id can not be null'); - const result = this._feature.filter((feature) => feature.getId() == id); - $assert(result.length == 1, `Feature could not be found:${id}`); + const result = this._feature.filter((feature) => feature.getId() === id); + $assert(result.length === 1, `Feature could not be found:${id}`); return result[0]; - }, + } /** */ getPropertiesKeys() { return Object.keys(this._properties); - }, + } /** * @param key @@ -110,19 +102,19 @@ const NodeModel = new Class(/** @lends NodeModel */{ putProperty(key, value) { $defined(key, 'key can not be null'); this._properties[key] = value; - }, + } /** */ getProperties() { return this._properties; - }, + } /** */ getProperty(key) { $defined(key, 'key can not be null'); const result = this._properties[key]; return !$defined(result) ? null : result; - }, + } /** * @return {mindplot.model.NodeModel} an identical clone of the NodeModel @@ -138,7 +130,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ result._properties = Object.clone(this._properties); result._feature = this._feature.clone(); return result; - }, + } /** * Similar to clone, assign new id to the elements ... @@ -158,7 +150,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ result._feature = this._feature.clone(); return result; - }, + } /** * @param {mindplot.model.NodeModel} child @@ -168,7 +160,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object'); this._children.push(child); child._parent = this; - }, + } /** * @param {mindplot.model.NodeModel} child @@ -178,23 +170,23 @@ const NodeModel = new Class(/** @lends NodeModel */{ $assert(child && child.isNodeModel(), 'Only NodeModel can be appended to Mindmap object.'); this._children.erase(child); child._parent = null; - }, + } /** */ getChildren() { return this._children; - }, + } /** */ getParent() { return this._parent; - }, + } /** */ setParent(parent) { - $assert(parent != this, 'The same node can not be parent and child if itself.'); + $assert(parent !== this, 'The same node can not be parent and child if itself.'); this._parent = parent; - }, + } _isChildNode(node) { let result = false; @@ -211,7 +203,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ } } return result; - }, + } /** * @id @@ -232,7 +224,7 @@ const NodeModel = new Class(/** @lends NodeModel */{ } } return result; - }, -}); + } +} export default NodeModel; diff --git a/packages/mindplot/src/components/model/NoteModel.js b/packages/mindplot/src/components/model/NoteModel.js index eb0751ff..85278610 100644 --- a/packages/mindplot/src/components/model/NoteModel.js +++ b/packages/mindplot/src/components/model/NoteModel.js @@ -17,30 +17,24 @@ */ import FeatureModel from './FeatureModel'; -const NoteModel = new Class(/** @lends NoteModel */{ - Extends: FeatureModel, - /** - * @constructs - * @param attributes - * @extends mindplot.model.FeatureModel - */ - initialize(attributes) { - this.parent(NoteModel.FEATURE_TYPE); +class NoteModel extends FeatureModel { + constructor(attributes) { + super(NoteModel.FEATURE_TYPE); const noteText = attributes.text ? attributes.text : ' '; this.setText(noteText); - }, + } /** */ getText() { return this.getAttribute('text'); - }, + } /** */ setText(text) { $assert(text, 'text can not be null'); this.setAttribute('text', text); - }, -}); + } +} /** * @constant diff --git a/packages/mindplot/src/components/model/RelationshipModel.js b/packages/mindplot/src/components/model/RelationshipModel.js index 5d6b44e2..a8b4a94d 100644 --- a/packages/mindplot/src/components/model/RelationshipModel.js +++ b/packages/mindplot/src/components/model/RelationshipModel.js @@ -17,130 +17,121 @@ */ import ConnectionLine from '../ConnectionLine'; -const RelationshipModel = new Class( - /** @lends RelationshipModel */ { - /** - * @constructs - * @param sourceTopicId - * @param targetTopicId - * @throws will throw an error if sourceTopicId is null or undefined - * @throws will throw an error if targetTopicId is null or undefined - */ - initialize(sourceTopicId, targetTopicId) { - $assert($defined(sourceTopicId), 'from node type can not be null'); - $assert($defined(targetTopicId), 'to node type can not be null'); +class RelationshipModel { + constructor(sourceTopicId, targetTopicId) { + $assert($defined(sourceTopicId), 'from node type can not be null'); + $assert($defined(targetTopicId), 'to node type can not be null'); - this._id = RelationshipModel._nextUUID(); - this._sourceTargetId = sourceTopicId; - this._targetTopicId = targetTopicId; - this._lineType = ConnectionLine.SIMPLE_CURVED; - this._srcCtrlPoint = null; - this._destCtrlPoint = null; - this._endArrow = true; - this._startArrow = false; - }, + this._id = RelationshipModel._nextUUID(); + this._sourceTargetId = sourceTopicId; + this._targetTopicId = targetTopicId; + this._lineType = ConnectionLine.SIMPLE_CURVED; + this._srcCtrlPoint = null; + this._destCtrlPoint = null; + this._endArrow = true; + this._startArrow = false; + } - /** */ - getFromNode() { - return this._sourceTargetId; - }, + /** */ + getFromNode() { + return this._sourceTargetId; + } - /** */ - getToNode() { - return this._targetTopicId; - }, + /** */ + getToNode() { + return this._targetTopicId; + } - /** */ - getId() { - $assert(this._id, 'id is null'); - return this._id; - }, + /** */ + getId() { + $assert(this._id, 'id is null'); + return this._id; + } - /** */ - getLineType() { - return this._lineType; - }, + /** */ + getLineType() { + return this._lineType; + } - /** */ - setLineType(lineType) { - this._lineType = lineType; - }, + /** */ + setLineType(lineType) { + this._lineType = lineType; + } - /** */ - getSrcCtrlPoint() { - return this._srcCtrlPoint; - }, + /** */ + getSrcCtrlPoint() { + return this._srcCtrlPoint; + } - /** */ - setSrcCtrlPoint(srcCtrlPoint) { - this._srcCtrlPoint = srcCtrlPoint; - }, + /** */ + setSrcCtrlPoint(srcCtrlPoint) { + this._srcCtrlPoint = srcCtrlPoint; + } - /** */ - getDestCtrlPoint() { - return this._destCtrlPoint; - }, + /** */ + getDestCtrlPoint() { + return this._destCtrlPoint; + } - /** */ - setDestCtrlPoint(destCtrlPoint) { - this._destCtrlPoint = destCtrlPoint; - }, + /** */ + setDestCtrlPoint(destCtrlPoint) { + this._destCtrlPoint = destCtrlPoint; + } - /** */ - getEndArrow() { - return this._endArrow; - }, + /** */ + getEndArrow() { + return this._endArrow; + } - /** */ - setEndArrow(endArrow) { - this._endArrow = endArrow; - }, + /** */ + setEndArrow(endArrow) { + this._endArrow = endArrow; + } - /** */ - getStartArrow() { - return this._startArrow; - }, + /** */ + getStartArrow() { + return this._startArrow; + } - /** */ - setStartArrow(startArrow) { - this._startArrow = startArrow; - }, + /** */ + setStartArrow(startArrow) { + this._startArrow = startArrow; + } - /** - * @return a clone of the relationship model - */ - clone() { - const result = new RelationshipModel(this._sourceTargetId, this._targetTopicId); - result._id = this._id; - result._lineType = this._lineType; - result._srcCtrlPoint = this._srcCtrlPoint; - result._destCtrlPoint = this._destCtrlPoint; - result._endArrow = this._endArrow; - result._startArrow = this._startArrow; - return result; - }, + /** + * @return a clone of the relationship model + */ + clone() { + const result = new RelationshipModel(this._sourceTargetId, this._targetTopicId); + result._id = this._id; + result._lineType = this._lineType; + result._srcCtrlPoint = this._srcCtrlPoint; + result._destCtrlPoint = this._destCtrlPoint; + result._endArrow = this._endArrow; + result._startArrow = this._startArrow; + return result; + } - /** - * @return {String} textual information about the relationship's source and target node - */ - inspect() { - return ( - `(fromNode:${ - this.getFromNode().getId() - } , toNode: ${ - this.getToNode().getId() - })` - ); - }, - }, -); + /** + * @return {String} textual information about the relationship's source and target node + */ + inspect() { + return ( + `(fromNode:${this.getFromNode().getId() + } , toNode: ${this.getToNode().getId() + })` + ); + } +} -RelationshipModel._nextUUID = function _nextUUID() { +function _nextUUID() { if (!$defined(RelationshipModel._uuid)) { RelationshipModel._uuid = 0; } RelationshipModel._uuid += 1; return RelationshipModel._uuid; -}; +} + +RelationshipModel._nextUUID = _nextUUID; export default RelationshipModel; diff --git a/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js b/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js index 95366151..c063efc2 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js +++ b/packages/mindplot/src/components/persistence/XMLSerializer_Beta.js @@ -14,19 +14,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Core from '@wisemapping/core-js'; +import { createDocument, innerXML } from '@wisemapping/core-js'; import ModelCodeName from './ModelCodeName'; import Mindmap from '../model/Mindmap'; import INodeModel from '../model/INodeModel'; import TopicFeature from '../TopicFeature'; -const core = Core(); - const XMLSerializer_Beta = new Class({ toXML(mindmap) { $assert(mindmap, 'Can not save a null mindmap'); - const document = core.Utils.createDocument(); + const document = createDocument(); // Store map attributes ... const mapElem = document.createElement('map'); @@ -51,11 +49,11 @@ const XMLSerializer_Beta = new Class({ const parentTopic = document.createElement('topic'); // Set topic attributes... - if (topic.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute('central', true); } else { const parent = topic.getParent(); - if (parent == null || parent.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (parent == null || parent.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { const pos = topic.getPosition(); parentTopic.setAttribute('position', `${pos.x},${pos.y}`); } else { @@ -98,10 +96,10 @@ const XMLSerializer_Beta = new Class({ if ( $defined(fontFamily) - || $defined(fontSize) - || $defined(fontColor) - || $defined(fontWeight) - || $defined(fontStyle) + || $defined(fontSize) + || $defined(fontColor) + || $defined(fontWeight) + || $defined(fontStyle) ) { parentTopic.setAttribute('fontStyle', font); } @@ -176,16 +174,15 @@ const XMLSerializer_Beta = new Class({ // Is a valid object ? const { documentElement } = dom; $assert( - documentElement.nodeName != 'parsererror', + documentElement.nodeName !== 'parsererror', `Error while parsing: '${documentElement.childNodes[0].nodeValue}`, ); // Is a wisemap?. $assert( - documentElement.tagName == XMLSerializer_Beta.MAP_ROOT_NODE, - `This seem not to be a map document. Root Tag: '${documentElement.tagName},',HTML:${ - dom.innerHTML - },XML:${core.Utils.innerXML(dom)}`, + documentElement.tagName === XMLSerializer_Beta.MAP_ROOT_NODE, + `This seem not to be a map document. Root Tag: '${documentElement.tagName},',HTML:${dom.innerHTML + },XML:${innerXML(dom)}`, ); // Start the loading process ... @@ -196,7 +193,7 @@ const XMLSerializer_Beta = new Class({ const children = documentElement.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == 1) { + if (child.nodeType === 1) { const topic = this._deserializeNode(child, mindmap); mindmap.addBranch(topic); } @@ -219,7 +216,7 @@ const XMLSerializer_Beta = new Class({ const order = domElem.getAttribute('order'); if ($defined(order)) { - topic.setOrder(parseInt(order)); + topic.setOrder(parseInt(order, 10)); } const shape = domElem.getAttribute('shape'); @@ -277,24 +274,24 @@ const XMLSerializer_Beta = new Class({ const children = domElem.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == 1) { + if (child.nodeType === 1) { $assert( - child.tagName == 'topic' - || child.tagName == 'icon' - || child.tagName == 'link' - || child.tagName == 'note', + child.tagName === 'topic' + || child.tagName === 'icon' + || child.tagName === 'link' + || child.tagName === 'note', `Illegal node type:${child.tagName}`, ); - if (child.tagName == 'topic') { + if (child.tagName === 'topic') { const childTopic = this._deserializeNode(child, mindmap); childTopic.connectTo(topic); - } else if (child.tagName == 'icon') { + } else if (child.tagName === 'icon') { const icon = this._deserializeIcon(child, topic); topic.addFeature(icon); - } else if (child.tagName == 'link') { + } else if (child.tagName === 'link') { const link = this._deserializeLink(child, topic); topic.addFeature(link); - } else if (child.tagName == 'note') { + } else if (child.tagName === 'note') { const note = this._deserializeNote(child, topic); topic.addFeature(note); } diff --git a/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js b/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js index b263c5cf..3efdbb9c 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js +++ b/packages/mindplot/src/components/persistence/XMLSerializer_Pela.js @@ -15,18 +15,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Core from '@wisemapping/core-js'; +import { $assert, createDocument } from '@wisemapping/core-js'; import web2d from '@wisemapping/web2d'; import Mindmap from '../model/Mindmap'; import INodeModel, { TopicShape } from '../model/INodeModel'; import TopicFeature from '../TopicFeature'; import ConnectionLine from '../ConnectionLine'; -const core = Core(); - /** * @class */ +// eslint-disable-next-line camelcase const XMLSerializer_Pela = new Class( /** @lends XMLSerializer_Pela */ { /** @@ -37,7 +36,7 @@ const XMLSerializer_Pela = new Class( toXML(mindmap) { $assert(mindmap, 'Can not save a null mindmap'); - const document = core.Utils.createDocument(); + const document = createDocument(); // Store map attributes ... const mapElem = document.createElement('map'); @@ -67,7 +66,7 @@ const XMLSerializer_Pela = new Class( const relationship = relationships[j]; if ( mindmap.findNodeById(relationship.getFromNode()) !== null - && mindmap.findNodeById(relationship.getToNode()) !== null + && mindmap.findNodeById(relationship.getToNode()) !== null ) { // Isolated relationships are not persisted .... const relationDom = this._relationshipToXML(document, relationship); @@ -83,14 +82,14 @@ const XMLSerializer_Pela = new Class( const parentTopic = document.createElement('topic'); // Set topic attributes... - if (topic.getType() == INodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.getType() === INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute('central', 'true'); } else { const pos = topic.getPosition(); parentTopic.setAttribute('position', `${pos.x},${pos.y}`); const order = topic.getOrder(); - if (typeof order === 'number' && isFinite(order)) { parentTopic.setAttribute('order', order); } + if (typeof order === 'number' && Number.isFinite(order)) { parentTopic.setAttribute('order', order); } } const text = topic.getText(); @@ -102,17 +101,16 @@ const XMLSerializer_Pela = new Class( if ($defined(shape)) { parentTopic.setAttribute('shape', shape); - if (shape == TopicShape.IMAGE) { + if (shape === TopicShape.IMAGE) { parentTopic.setAttribute( 'image', - `${topic.getImageSize().width},${ - topic.getImageSize().height + `${topic.getImageSize().width},${topic.getImageSize().height }:${topic.getImageUrl()}`, ); } } - if (topic.areChildrenShrunken() && topic.getType() != INodeModel.CENTRAL_TOPIC_TYPE) { + if (topic.areChildrenShrunken() && topic.getType() !== INodeModel.CENTRAL_TOPIC_TYPE) { parentTopic.setAttribute('shrink', 'true'); } @@ -139,10 +137,10 @@ const XMLSerializer_Pela = new Class( if ( $defined(fontFamily) - || $defined(fontSize) - || $defined(fontColor) - || $defined(fontWeight) - || $defined(fontStyle) + || $defined(fontSize) + || $defined(fontColor) + || $defined(fontWeight) + || $defined(fontStyle) ) { parentTopic.setAttribute('fontStyle', font); } @@ -173,7 +171,7 @@ const XMLSerializer_Pela = new Class( for (const key in attributes) { const value = attributes[key]; - if (key == 'text') { + if (key === 'text') { const cdata = document.createCDATASection(this.rmXmlInv(value)); featureDom.appendChild(cdata); } else { @@ -194,7 +192,7 @@ const XMLSerializer_Pela = new Class( }, _noteTextToXML(document, elem, text) { - if (text.indexOf('\n') == -1) { + if (text.indexOf('\n') === -1) { elem.setAttribute('text', this.rmXmlInv(text)); } else { const textDom = document.createElement('text'); @@ -211,7 +209,7 @@ const XMLSerializer_Pela = new Class( const lineType = relationship.getLineType(); result.setAttribute('lineType', lineType); - if (lineType == ConnectionLine.CURVED || lineType == ConnectionLine.SIMPLE_CURVED) { + if (lineType === ConnectionLine.CURVED || lineType === ConnectionLine.SIMPLE_CURVED) { if ($defined(relationship.getSrcCtrlPoint())) { const srcPoint = relationship.getSrcCtrlPoint(); result.setAttribute( @@ -233,13 +231,13 @@ const XMLSerializer_Pela = new Class( }, /** - * @param dom - * @param mapId - * @throws will throw an error if dom is null or undefined - * @throws will throw an error if mapId is null or undefined - * @throws will throw an error if the document element is not consistent with a wisemap's root - * element - */ + * @param dom + * @param mapId + * @throws will throw an error if dom is null or undefined + * @throws will throw an error if mapId is null or undefined + * @throws will throw an error if the document element is not consistent with a wisemap's root + * element + */ loadFromDom(dom, mapId) { $assert(dom, 'dom can not be null'); $assert(mapId, 'mapId can not be null'); @@ -248,7 +246,7 @@ const XMLSerializer_Pela = new Class( // Is a wisemap?. $assert( - rootElem.tagName == XMLSerializer_Pela.MAP_ROOT_NODE, + rootElem.tagName === XMLSerializer_Pela.MAP_ROOT_NODE, 'This seem not to be a map document.', ); @@ -260,15 +258,21 @@ const XMLSerializer_Pela = new Class( const children = rootElem.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == 1) { + if (child.nodeType === 1) { switch (child.tagName) { - case 'topic': - var topic = this._deserializeNode(child, mindmap); + case 'topic': { + const topic = this._deserializeNode(child, mindmap); mindmap.addBranch(topic); break; - case 'relationship': - var relationship = this._deserializeRelationship(child, mindmap); - if (relationship != null) mindmap.addRelationship(relationship); + } + case 'relationship': { + const relationship = this._deserializeRelationship(child, mindmap); + if (relationship != null) { + mindmap.addRelationship(relationship); + } + break; + } + default: break; } } @@ -286,7 +290,7 @@ const XMLSerializer_Pela = new Class( // Load attributes... let id = domElem.getAttribute('id'); if ($defined(id)) { - id = parseInt(id); + id = parseInt(id, 10); } if (this._idsMap[id]) { @@ -332,7 +336,7 @@ const XMLSerializer_Pela = new Class( if ($defined(shape)) { topic.setShapeType(shape); - if (shape == TopicShape.IMAGE) { + if (shape === TopicShape.IMAGE) { const image = domElem.getAttribute('image'); const size = image.substring(0, image.indexOf(':')); const url = image.substring(image.indexOf(':') + 1, image.length); @@ -354,14 +358,14 @@ const XMLSerializer_Pela = new Class( } const order = domElem.getAttribute('order'); - if ($defined(order) && order != 'NaN') { + if ($defined(order) && order !== 'NaN') { // Hack for broken maps ... - topic.setOrder(parseInt(order)); + topic.setOrder(parseInt(order, 10)); } const isShrink = domElem.getAttribute('shrink'); // Hack: Some production maps has been stored with the central topic collapsed. This is a bug. - if ($defined(isShrink) && type != INodeModel.CENTRAL_TOPIC_TYPE) { + if ($defined(isShrink) && type !== INodeModel.CENTRAL_TOPIC_TYPE) { topic.setChildrenShrunken(isShrink); } @@ -380,8 +384,8 @@ const XMLSerializer_Pela = new Class( const children = domElem.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == Node.ELEMENT_NODE) { - if (child.tagName == 'topic') { + if (child.nodeType === Node.ELEMENT_NODE) { + if (child.tagName === 'topic') { const childTopic = this._deserializeNode(child, mindmap); childTopic.connectTo(topic); } else if (TopicFeature.isSupported(child.tagName)) { @@ -403,7 +407,7 @@ const XMLSerializer_Pela = new Class( const featureType = child.tagName; const feature = TopicFeature.createModel(featureType, attributes); topic.addFeature(feature); - } else if (child.tagName == 'text') { + } else if (child.tagName === 'text') { const nodeText = this._deserializeNodeText(child); topic.setText(nodeText); } @@ -418,7 +422,7 @@ const XMLSerializer_Pela = new Class( const children = domElem.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == Node.CDATA_SECTION_NODE) { + if (child.nodeType === Node.CDATA_SECTION_NODE) { value = child.nodeValue; } } @@ -427,7 +431,7 @@ const XMLSerializer_Pela = new Class( value = unescape(value); // Hack for empty nodes ... - if (value == '') { + if (value === '') { value = ' '; } } @@ -440,7 +444,7 @@ const XMLSerializer_Pela = new Class( let value = null; for (let i = 0; i < children.length; i++) { const child = children[i]; - if (child.nodeType == Node.CDATA_SECTION_NODE) { + if (child.nodeType === Node.CDATA_SECTION_NODE) { value = child.nodeValue; } } @@ -453,10 +457,9 @@ const XMLSerializer_Pela = new Class( const lineType = domElement.getAttribute('lineType'); const srcCtrlPoint = domElement.getAttribute('srcCtrlPoint'); const destCtrlPoint = domElement.getAttribute('destCtrlPoint'); - const endArrow = domElement.getAttribute('endArrow'); - const startArrow = domElement.getAttribute('startArrow'); + // If for some reason a relationship lines has source and dest nodes the same, don't import it. - if (srcId == destId) { + if (srcId === destId) { return null; } // Is the connections points valid ?. If it's not, do not load the relationship ... @@ -466,10 +469,10 @@ const XMLSerializer_Pela = new Class( const model = mindmap.createRelationship(srcId, destId); model.setLineType(lineType); - if ($defined(srcCtrlPoint) && srcCtrlPoint != '') { + if ($defined(srcCtrlPoint) && srcCtrlPoint !== '') { model.setSrcCtrlPoint(web2d.Point.fromString(srcCtrlPoint)); } - if ($defined(destCtrlPoint) && destCtrlPoint != '') { + if ($defined(destCtrlPoint) && destCtrlPoint !== '') { model.setDestCtrlPoint(web2d.Point.fromString(destCtrlPoint)); } model.setEndArrow('false'); @@ -489,18 +492,18 @@ const XMLSerializer_Pela = new Class( * @return The in String, stripped of non-valid characters. */ rmXmlInv(str) { - if (str == null || str == undefined) return null; + if (str == null || str === undefined) return null; let result = ''; for (let i = 0; i < str.length; i++) { const c = str.charCodeAt(i); if ( - c == 0x9 - || c == 0xa - || c == 0xd - || (c >= 0x20 && c <= 0xd7ff) - || (c >= 0xe000 && c <= 0xfffd) - || (c >= 0x10000 && c <= 0x10ffff) + c === 0x9 + || c === 0xa + || c === 0xd + || (c >= 0x20 && c <= 0xd7ff) + || (c >= 0xe000 && c <= 0xfffd) + || (c >= 0x10000 && c <= 0x10ffff) ) { result += str.charAt(i); } diff --git a/packages/mindplot/src/components/util/Shape.js b/packages/mindplot/src/components/util/Shape.js index 0aa4f3e4..1949d5ce 100644 --- a/packages/mindplot/src/components/util/Shape.js +++ b/packages/mindplot/src/components/util/Shape.js @@ -16,23 +16,21 @@ * limitations under the License. */ import web2d from '@wisemapping/web2d'; -import coreJs from '@wisemapping/core-js'; +import { $assert, $defined } from '@wisemapping/core-js'; import { TopicShape } from '../model/INodeModel'; import TopicConfig from '../TopicConfig'; -const core = coreJs(); - const Shape = { isAtRight(sourcePoint, targetPoint) { - core.Function.$assert(sourcePoint, 'Source can not be null'); - core.Function.$assert(targetPoint, 'Target can not be null'); + $assert(sourcePoint, 'Source can not be null'); + $assert(targetPoint, 'Target can not be null'); return sourcePoint.x < targetPoint.x; }, calculateRectConnectionPoint(rectCenterPoint, rectSize, isAtRight) { - core.Function.$assert(rectCenterPoint, 'rectCenterPoint can not be null'); - core.Function.$assert(rectSize, 'rectSize can not be null'); - core.Function.$assert(core.Function.$defined(isAtRight), 'isRight can not be null'); + $assert(rectCenterPoint, 'rectCenterPoint can not be null'); + $assert(rectSize, 'rectSize can not be null'); + $assert($defined(isAtRight), 'isRight can not be null'); // Node is placed at the right ? const result = new web2d.Point(); @@ -115,7 +113,7 @@ const Shape = { }, workoutIncomingConnectionPoint(targetNode, sourcePosition) { - core.Function.$assert(sourcePosition, 'sourcePoint can not be null'); + $assert(sourcePosition, 'sourcePoint can not be null'); const pos = targetNode.getPosition(); const size = targetNode.getSize(); diff --git a/packages/mindplot/src/components/widget/ColorPalettePanel.js b/packages/mindplot/src/components/widget/ColorPalettePanel.js index f928a654..63d647a8 100644 --- a/packages/mindplot/src/components/widget/ColorPalettePanel.js +++ b/packages/mindplot/src/components/widget/ColorPalettePanel.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert, $defined } from '@wisemapping/core-js'; import ToolbarPaneItem from './ToolbarPaneItem'; const ColorPalettePanel = new Class({ @@ -89,11 +90,11 @@ const ColorPalettePanel = new Class({ let modelValue = model.getValue(); _.each(colorCells, (elem) => { const color = $(elem).css('background-color').rgbToHex(); - if (modelValue != null && modelValue[0] == 'r') { + if (modelValue != null && modelValue[0] === 'r') { modelValue = modelValue.rgbToHex(); } - if (modelValue != null && modelValue.toUpperCase() == color.toUpperCase()) { + if (modelValue != null && modelValue.toUpperCase() === color.toUpperCase()) { $(elem).parent().attr('class', 'palette-cell palette-cell-selected'); } }); diff --git a/packages/mindplot/src/components/widget/IMenu.js b/packages/mindplot/src/components/widget/IMenu.js index d592baba..4d30d595 100644 --- a/packages/mindplot/src/components/widget/IMenu.js +++ b/packages/mindplot/src/components/widget/IMenu.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from "@wisemapping/core-js"; import PersistenceManager from '../PersistenceManager'; const IMenu = new Class({ @@ -90,7 +91,7 @@ const IMenu = new Class({ if (saveHistory) { saveElem.css('cursor', 'pointer'); - if (error.severity != 'FATAL') { + if (error.severity !== 'FATAL') { $notify(error.message); } else { $notifyModal(error.message); diff --git a/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js b/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js index 03cfd3cf..df55697e 100644 --- a/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js +++ b/packages/mindplot/src/components/widget/KeyboardShortcutTooltip.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import FloatingTip from './FloatingTip'; const KeyboardShortcutTooltip = new Class({ diff --git a/packages/mindplot/src/components/widget/Menu.js b/packages/mindplot/src/components/widget/Menu.js index 84d7a341..3df5523d 100644 --- a/packages/mindplot/src/components/widget/Menu.js +++ b/packages/mindplot/src/components/widget/Menu.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $defined } from '@wisemapping/core-js'; import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; import IMenu from './IMenu'; import FontFamilyPanel from './FontFamilyPanel'; diff --git a/packages/mindplot/src/components/widget/ToolbarItem.js b/packages/mindplot/src/components/widget/ToolbarItem.js index 72cb40b9..68b25a0b 100644 --- a/packages/mindplot/src/components/widget/ToolbarItem.js +++ b/packages/mindplot/src/components/widget/ToolbarItem.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import Events from '../Events'; const ToolbarItem = new Class({ diff --git a/packages/mindplot/src/components/widget/ToolbarNotifier.js b/packages/mindplot/src/components/widget/ToolbarNotifier.js index 4a674993..0c39d2b1 100644 --- a/packages/mindplot/src/components/widget/ToolbarNotifier.js +++ b/packages/mindplot/src/components/widget/ToolbarNotifier.js @@ -16,16 +16,18 @@ * limitations under the License. */ -const ToolbarNotifier = new Class({ - initialize() { +import $ from '@libraries/jquery-2.1.0'; + +class ToolbarNotifier { + constructor() { this.container = $('#headerNotifier'); - }, + } hide() { this.container.hide(); - }, + } - logMessage(msg, fade) { + logMessage(msg) { $assert(msg, 'msg can not be null'); // In case of print,embedded no message is displayed .... if (this.container && !this.container.data('transitioning')) { @@ -38,11 +40,11 @@ const ToolbarNotifier = new Class({ this.container.show().fadeOut(5000); } this.container.data('transitioning', false); - }, -}); + } +} const toolbarNotifier = new ToolbarNotifier(); -const $notify = function (msg) { +const $notify = (msg) => { toolbarNotifier.logMessage(msg); }; diff --git a/packages/mindplot/src/components/widget/ToolbarPaneItem.js b/packages/mindplot/src/components/widget/ToolbarPaneItem.js index 10a03cec..02d2c56d 100644 --- a/packages/mindplot/src/components/widget/ToolbarPaneItem.js +++ b/packages/mindplot/src/components/widget/ToolbarPaneItem.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { $assert } from '@wisemapping/core-js'; import ToolbarItem from './ToolbarItem'; import FloatingTip from './FloatingTip'; @@ -25,10 +26,10 @@ const ToolbarPaneItem = new Class({ $assert(model, 'model can not be null'); this._model = model; const me = this; - const fn = function () { - // Is the panel being displayed ? - me.isVisible() ? me.hide() : me.show(); + const fn = () => { + return me.isVisible() ? me.hide() : me.show(); }; + this.parent(buttonId, fn, { topicAction: true, relAction: false }); this._panelElem = this._init(); this._visible = false; @@ -118,7 +119,7 @@ const ToolbarPaneItem = new Class({ }, buildPanel: function () { - throw 'Method must be implemented'; + throw new Error('Method must be implemented'); }.protect(), }); diff --git a/packages/mindplot/src/mindplot.js b/packages/mindplot/src/mindplot.js index 69ede71a..b4756339 100644 --- a/packages/mindplot/src/mindplot.js +++ b/packages/mindplot/src/mindplot.js @@ -1,26 +1,6 @@ +/* eslint-disable no-unused-vars */ import '@libraries/mootools-core-1.4.5'; -import $ from '@libraries/jquery-2.1.0'; import _ from '@libraries/underscore-min'; -import coreJs from '@wisemapping/core-js'; - -import commands from '@commands'; -import layout from '@layout'; -import models from '@model'; -import persistence from '@persistence'; -import widget from '@widget'; -import component from '@components'; - -global.$ = $; -global.JQuery = $; -global._ = _; -global.core = coreJs(); - -export default { - commands, - layout, - models, - persistence, - widget, - ...component, -}; +import Mindmap from './components/model/Mindmap'; +import PersistenceManager from './components/PersistenceManager'; diff --git a/packages/mindplot/test/playground/map-render/js/editor.js b/packages/mindplot/test/playground/map-render/js/editor.js index 75f57f95..bc8be3ad 100644 --- a/packages/mindplot/test/playground/map-render/js/editor.js +++ b/packages/mindplot/test/playground/map-render/js/editor.js @@ -15,8 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -import mindplot from '../../../../src/mindplot'; +import { $assert } from '@wisemapping/core-js'; +import Mindmap from '../../../../src/components/model/Mindmap'; +import PersistenceManager from '../../../../src/components/PersistenceManager'; +import $ from '@libraries/jquery-2.1.0' let designer = null; @@ -191,28 +193,27 @@ global.editor.WaitDialog = new Class({ // Show loading dialog ... $(() => { - global.jQuery = global.$; - import('./bootstrap').then(() => { - global.waitDialog = new global.editor.WaitDialog(); - global.waitDialog.show(); + import('./bootstrap').then(() => { + global.waitDialog = new global.editor.WaitDialog(); + global.waitDialog.show(); - // from viewmode.html --------- - var mapId = 'welcome'; - // Set readonly option ... - var options = loadDesignerOptions(); - options.readOnly = true; - var designer = buildDesigner(options); + // from viewmode.html --------- + var mapId = 'welcome'; + // Set readonly option ... + var options = loadDesignerOptions(); + options.readOnly = true; + var designer = buildDesigner(options); - // Load map from XML file persisted on disk... - var persistence = mindplot.PersistenceManager.getInstance(); - var mindmap; - try { - mindmap = persistence.load(mapId); - } catch (e) { - // If the map could not be loaded, create a new empty map... - mindmap = mindplot.model.Mindmap.buildEmpty(mapId); - } - designer.loadMap(mindmap); - // from viewmode.html --------- - }); + // Load map from XML file persisted on disk... + var persistence = PersistenceManager.getInstance(); + var mindmap; + try { + mindmap = persistence.load(mapId); + } catch (e) { + // If the map could not be loaded, create a new empty map... + mindmap = Mindmap.buildEmpty(mapId); + } + designer.loadMap(mindmap); + // from viewmode.html --------- + }); });