From f95e65f21bb1f9d17a454ba47f0584b856cc5728 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Tue, 14 Dec 2021 17:54:11 -0800 Subject: [PATCH] Remove global refernece to $msg --- packages/mindplot/src/components/Designer.js | 18 +++++++----------- packages/mindplot/src/components/Messages.js | 3 ++- packages/mindplot/src/components/NoteIcon.js | 1 + .../src/components/RestPersistenceManager.js | 1 + packages/mindplot/src/components/TopicStyle.js | 1 + .../libraries/bootstrap/BootstrapDialog.js | 4 ++-- .../mindplot/src/components/widget/IMenu.js | 1 + .../src/components/widget/LinkEditor.js | 1 + .../src/components/widget/LinkIconTooltip.js | 1 + .../mindplot/src/components/widget/Menu.js | 2 +- .../src/components/widget/NoteEditor.js | 1 + .../test/playground/map-render/js/loader.js | 2 ++ 12 files changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/mindplot/src/components/Designer.js b/packages/mindplot/src/components/Designer.js index 987e1ce4..97995ccd 100644 --- a/packages/mindplot/src/components/Designer.js +++ b/packages/mindplot/src/components/Designer.js @@ -17,9 +17,9 @@ */ import { $assert, $defined } from '@wisemapping/core-js'; import $ from 'jquery'; +import Messages, { $msg } from './Messages'; import Events from './Events'; -import Messages from './Messages'; import StandaloneActionDispatcher from './StandaloneActionDispatcher'; import CommandContext from './CommandContext'; @@ -258,19 +258,15 @@ class Designer extends Events { if (isConnected) { // Improve this ... const targetTopicModel = model.getParent(); - let targetTopic = null; + // Find target topic with the same model ... const topics = this.getModel().getTopics(); - for (let i = 0; i < topics.length; i++) { - const t = topics[i]; - if (t.getModel() === targetTopicModel) { - targetTopic = t; - // Disconnect the node. It will be connected again later ... - model.disconnect(); - break; - } + const targetTopic = topics.find((t) => t.getModel() === targetTopicModel); + if (targetTopic) { + model.disconnect(); + } else { + $assert(targetTopic, 'Could not find a topic to connect'); } - $assert(targetTopic, 'Could not find a topic to connect'); topic.connectTo(targetTopic, this._workspace); } diff --git a/packages/mindplot/src/components/Messages.js b/packages/mindplot/src/components/Messages.js index b76a09fa..c8fbcb1b 100644 --- a/packages/mindplot/src/components/Messages.js +++ b/packages/mindplot/src/components/Messages.js @@ -33,7 +33,7 @@ class Messages { } // @Todo: fix global assignment. -global.$msg = function $msg(key) { +const $msg = function $msg(key) { if (!Messages.__bundle) { Messages.init('en'); } @@ -43,3 +43,4 @@ global.$msg = function $msg(key) { Messages.BUNDLES = {}; export default Messages; +export { $msg }; diff --git a/packages/mindplot/src/components/NoteIcon.js b/packages/mindplot/src/components/NoteIcon.js index 2bd14bbc..53990af9 100644 --- a/packages/mindplot/src/components/NoteIcon.js +++ b/packages/mindplot/src/components/NoteIcon.js @@ -17,6 +17,7 @@ */ import { $assert } from '@wisemapping/core-js'; import $ from 'jquery'; +import { $msg } from './Messages'; import Icon from './Icon'; import FloatingTip from './widget/FloatingTip'; diff --git a/packages/mindplot/src/components/RestPersistenceManager.js b/packages/mindplot/src/components/RestPersistenceManager.js index 810a479a..2db4f103 100644 --- a/packages/mindplot/src/components/RestPersistenceManager.js +++ b/packages/mindplot/src/components/RestPersistenceManager.js @@ -16,6 +16,7 @@ * limitations under the License. */ import { $assert } from '@wisemapping/core-js'; +import { $msg } from './Messages'; import PersistenceManager from './PersistenceManager'; class RESTPersistenceManager extends PersistenceManager{ diff --git a/packages/mindplot/src/components/TopicStyle.js b/packages/mindplot/src/components/TopicStyle.js index 05049773..9e378a31 100644 --- a/packages/mindplot/src/components/TopicStyle.js +++ b/packages/mindplot/src/components/TopicStyle.js @@ -16,6 +16,7 @@ * limitations under the License. */ import { $assert, $defined } from '@wisemapping/core-js'; +import { $msg } from './Messages'; import { TopicShape } from './model/INodeModel'; class TopicStyle { diff --git a/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js index 9834e1fc..298748dd 100644 --- a/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js +++ b/packages/mindplot/src/components/libraries/bootstrap/BootstrapDialog.js @@ -1,5 +1,5 @@ import Options from '../../Options'; - +import { $msg } from '../../Messages'; import $ from 'jquery'; class BootstrapDialog extends Options { @@ -36,7 +36,7 @@ class BootstrapDialog extends Options { content.append(footer); } this._native.find('.modal-dialog').append(content); - this._native.on('hidden.bs.modal', function () { + this._native.on('hidden.bs.modal', function remove() { $(this).remove(); }); this._native.on('shown.bs.modal', this.onDialogShown); diff --git a/packages/mindplot/src/components/widget/IMenu.js b/packages/mindplot/src/components/widget/IMenu.js index 1c1fb0e6..5b497553 100644 --- a/packages/mindplot/src/components/widget/IMenu.js +++ b/packages/mindplot/src/components/widget/IMenu.js @@ -16,6 +16,7 @@ * limitations under the License. */ import { $assert } from '@wisemapping/core-js'; +import { $msg } from '../Messages'; import PersistenceManager from '../PersistenceManager'; import { $notify } from './ToolbarNotifier'; import $notifyModal from './ModalDialogNotifier'; diff --git a/packages/mindplot/src/components/widget/LinkEditor.js b/packages/mindplot/src/components/widget/LinkEditor.js index 7fa84908..f11000bc 100644 --- a/packages/mindplot/src/components/widget/LinkEditor.js +++ b/packages/mindplot/src/components/widget/LinkEditor.js @@ -17,6 +17,7 @@ */ import $ from 'jquery'; import { $assert } from '@wisemapping/core-js'; +import { $msg } from '../Messages'; import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; class LinkEditor extends BootstrapDialog { diff --git a/packages/mindplot/src/components/widget/LinkIconTooltip.js b/packages/mindplot/src/components/widget/LinkIconTooltip.js index 19a9d2dd..3701a8d8 100644 --- a/packages/mindplot/src/components/widget/LinkIconTooltip.js +++ b/packages/mindplot/src/components/widget/LinkIconTooltip.js @@ -17,6 +17,7 @@ */ import { $assert } from "@wisemapping/core-js"; import $ from 'jquery'; +import { $msg } from '../Messages'; import FloatingTip from './FloatingTip'; class LinkIconTooltip extends FloatingTip { diff --git a/packages/mindplot/src/components/widget/Menu.js b/packages/mindplot/src/components/widget/Menu.js index 12e82e08..134e90a9 100644 --- a/packages/mindplot/src/components/widget/Menu.js +++ b/packages/mindplot/src/components/widget/Menu.js @@ -16,8 +16,8 @@ * limitations under the License. */ import $ from 'jquery'; - import { $defined } from '@wisemapping/core-js'; +import { $msg } from '../Messages'; import BootstrapDialogRequest from "../libraries/bootstrap/BootstrapDialogRequest"; import IMenu from './IMenu'; import FontFamilyPanel from './FontFamilyPanel'; diff --git a/packages/mindplot/src/components/widget/NoteEditor.js b/packages/mindplot/src/components/widget/NoteEditor.js index 4b9c583b..6bafdf82 100644 --- a/packages/mindplot/src/components/widget/NoteEditor.js +++ b/packages/mindplot/src/components/widget/NoteEditor.js @@ -18,6 +18,7 @@ import { $assert } from '@wisemapping/core-js'; import BootstrapDialog from '../libraries/bootstrap/BootstrapDialog'; import $ from 'jquery'; +import { $msg } from '../Messages'; class NoteEditor extends BootstrapDialog { constructor(model) { diff --git a/packages/mindplot/test/playground/map-render/js/loader.js b/packages/mindplot/test/playground/map-render/js/loader.js index cf5959fd..455fbc4a 100644 --- a/packages/mindplot/test/playground/map-render/js/loader.js +++ b/packages/mindplot/test/playground/map-render/js/loader.js @@ -18,6 +18,8 @@ import { $assert } from '@wisemapping/core-js'; import { PersistenceManager, Designer, LocalStorageManager, Menu } from '../../../../src/'; import * as mindplot from '../../../../src/'; +import { $msg } from '../../../../src/components/Messages'; + import $notifyModal from '../../../../src/components/widget/ModalDialogNotifier'; import $ from 'jquery';