From c2b94b86969e47fdeeb06907b58f196244c308aa Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 2 Dec 2021 21:23:14 -0800 Subject: [PATCH] Fix global import in core-js --- packages/web2d/src/components/CurvedLine.js | 12 ++-- packages/web2d/src/components/Element.js | 15 +++-- packages/web2d/src/components/ElementClass.js | 15 +++-- packages/web2d/src/components/Font.js | 1 + packages/web2d/src/components/Group.js | 11 ++-- packages/web2d/src/components/Rect.js | 5 +- packages/web2d/src/components/Text.js | 56 +++++++++---------- packages/web2d/src/components/Workspace.js | 14 ++--- packages/web2d/src/components/header.js | 23 -------- .../src/components/peer/svg/ArrowPeer.js | 19 +++---- .../src/components/peer/svg/CurvedLinePeer.js | 22 ++++---- .../src/components/peer/svg/ElementPeer.js | 29 +++++----- .../src/components/peer/svg/ElipsePeer.js | 12 ++-- .../web2d/src/components/peer/svg/Font.js | 10 ++-- .../src/components/peer/svg/GroupPeer.js | 12 ++-- .../web2d/src/components/peer/svg/LinePeer.js | 8 +-- .../src/components/peer/svg/PolyLinePeer.js | 28 +++++----- .../web2d/src/components/peer/svg/RectPeer.js | 10 ++-- .../web2d/src/components/peer/svg/TextPeer.js | 14 ++--- .../src/components/peer/svg/WorkspacePeer.js | 12 ++-- .../src/components/peer/utils/EventUtils.js | 6 +- 21 files changed, 140 insertions(+), 194 deletions(-) delete mode 100644 packages/web2d/src/components/header.js diff --git a/packages/web2d/src/components/CurvedLine.js b/packages/web2d/src/components/CurvedLine.js index e8fab830..1a7218a9 100644 --- a/packages/web2d/src/components/CurvedLine.js +++ b/packages/web2d/src/components/CurvedLine.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $assert } from '@wisemapping/core-js'; import Element from './Element'; import Toolkit from './Toolkit'; -const core = coreJs(); - const CurvedLine = new Class({ Extends: Element, initialize(attributes) { @@ -45,15 +43,15 @@ const CurvedLine = new Class({ }, setFrom(x, y) { - core.Function.$assert(!Number.isNaN(x), 'x must be defined'); - core.Function.$assert(!Number.isNaN(y), 'y must be defined'); + $assert(!Number.isNaN(x), 'x must be defined'); + $assert(!Number.isNaN(y), 'y must be defined'); this.peer.setFrom(x, y); }, setTo(x, y) { - core.Function.$assert(!Number.isNaN(x), 'x must be defined'); - core.Function.$assert(!Number.isNaN(y), 'y must be defined'); + $assert(!Number.isNaN(x), 'x must be defined'); + $assert(!Number.isNaN(y), 'y must be defined'); this.peer.setTo(x, y); }, diff --git a/packages/web2d/src/components/Element.js b/packages/web2d/src/components/Element.js index 7badf95f..126c842e 100644 --- a/packages/web2d/src/components/Element.js +++ b/packages/web2d/src/components/Element.js @@ -15,9 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import CoreJS from '@wisemapping/core-js'; -const core = CoreJS(); +import { $defined } from '@wisemapping/core-js'; const Element = new Class({ initialize(peer, attributes) { @@ -26,7 +25,7 @@ const Element = new Class({ throw new Error('Element peer can not be null'); } - if (core.Function.$defined(attributes)) { + if ($defined(attributes)) { this._initialize(attributes); } }, @@ -39,7 +38,7 @@ const Element = new Class({ if (Object.prototype.hasOwnProperty.call(attributes, key)) { const funcName = this._attributeNameToFuncName(key, 'set'); let funcArgs = batchExecute[funcName]; - if (!core.Function.$defined(funcArgs)) { + if (!$defined(funcArgs)) { funcArgs = []; } @@ -59,7 +58,7 @@ const Element = new Class({ // eslint-disable-next-line guard-for-in for (const key in batchExecute) { const func = this[key]; - if (!core.Function.$defined(func)) { + if (!$defined(func)) { throw new Error(`Could not find function: ${key}`); } func.apply(this, batchExecute[key]); @@ -172,7 +171,7 @@ const Element = new Class({ _attributeNameToFuncName(attributeKey, prefix) { const signature = Element._propertyNameToSignature[attributeKey]; - if (!core.Function.$defined(signature)) { + if (!$defined(signature)) { throw new Error(`Unsupported attribute: ${attributeKey}`); } @@ -229,12 +228,12 @@ const Element = new Class({ const getterResult = getter.apply(this, []); const attibuteName = signature[2]; - if (!core.Function.$defined(attibuteName)) { + if (!$defined(attibuteName)) { throw new Error(`Could not find attribute mapping for:${key}`); } const result = getterResult[attibuteName]; - if (!core.Function.$defined(result)) { + if (!$defined(result)) { throw new Error(`Could not find attribute with name:${attibuteName}`); } diff --git a/packages/web2d/src/components/ElementClass.js b/packages/web2d/src/components/ElementClass.js index e2b96c71..cb31ec6f 100644 --- a/packages/web2d/src/components/ElementClass.js +++ b/packages/web2d/src/components/ElementClass.js @@ -15,9 +15,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import CoreJS from '@wisemapping/core-js'; -const core = CoreJS(); +import { $defined } from '@wisemapping/core-js'; class ElementClass { constructor(peer, attributes) { @@ -26,7 +25,7 @@ class ElementClass { throw new Error('Element peer can not be null'); } - if (core.Function.$defined(attributes)) { + if ($defined(attributes)) { this._initialize(attributes); } } @@ -39,7 +38,7 @@ class ElementClass { if (Object.prototype.hasOwnProperty.call(attributes, key)) { const funcName = this._attributeNameToFuncName(key, 'set'); let funcArgs = batchExecute[funcName]; - if (!core.Function.$defined(funcArgs)) { + if (!$defined(funcArgs)) { funcArgs = []; } @@ -59,7 +58,7 @@ class ElementClass { // eslint-disable-next-line guard-for-in for (const key in batchExecute) { const func = this[key]; - if (!core.Function.$defined(func)) { + if (!$defined(func)) { throw new Error(`Could not find function: ${key}`); } func.apply(this, batchExecute[key]); @@ -175,7 +174,7 @@ class ElementClass { // eslint-disable-next-line class-methods-use-this _attributeNameToFuncName(attributeKey, prefix) { const signature = Element._propertyNameToSignature[attributeKey]; - if (!core.Function.$defined(signature)) { + if (!$defined(signature)) { throw new Error(`Unsupported attribute: ${attributeKey}`); } @@ -232,12 +231,12 @@ class ElementClass { const getterResult = getter.apply(this, []); const attibuteName = signature[2]; - if (!core.Function.$defined(attibuteName)) { + if (!$defined(attibuteName)) { throw new Error(`Could not find attribute mapping for:${key}`); } const result = getterResult[attibuteName]; - if (!core.Function.$defined(result)) { + if (!$defined(result)) { throw new Error(`Could not find attribute with name:${attibuteName}`); } diff --git a/packages/web2d/src/components/Font.js b/packages/web2d/src/components/Font.js index 251baefd..f249907b 100644 --- a/packages/web2d/src/components/Font.js +++ b/packages/web2d/src/components/Font.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import Toolkit from './Toolkit'; import TransformUtil from './peer/utils/TransformUtils'; diff --git a/packages/web2d/src/components/Group.js b/packages/web2d/src/components/Group.js index ebef3728..d2df1ae2 100644 --- a/packages/web2d/src/components/Group.js +++ b/packages/web2d/src/components/Group.js @@ -15,12 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; + +import { $defined } from '@wisemapping/core-js'; import Element from './Element'; import Toolkit from './Toolkit'; -const core = coreJs(); - /** * A group object can be used to collect shapes. */ @@ -48,7 +47,7 @@ const Group = new Class({ * Remove an element as a child to the object. */ removeChild(element) { - if (!core.Function.$defined(element)) { + if (!$defined(element)) { throw new Error('Child element can not be null'); } @@ -68,7 +67,7 @@ const Group = new Class({ * Appends an element as a child to the object. */ append(element) { - if (!core.Function.$defined(element)) { + if (!$defined(element)) { throw Error('Child element can not be null'); } @@ -130,7 +129,7 @@ const Group = new Class({ }, appendDomChild(DomElement) { - if (!core.Function.$defined(DomElement)) { + if (!$defined(DomElement)) { throw new Error('Child element can not be null'); } diff --git a/packages/web2d/src/components/Rect.js b/packages/web2d/src/components/Rect.js index 570cffe9..fd9b9981 100644 --- a/packages/web2d/src/components/Rect.js +++ b/packages/web2d/src/components/Rect.js @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + import ElementClass from './ElementClass'; import Toolkit from './Toolkit'; @@ -25,9 +26,7 @@ import Toolkit from './Toolkit'; * For rounded rectangles, radius of the ellipse used to round off the corners of the rectangle. */ class Rect extends ElementClass { - constructor(arc, attributes) { - if (arc && arc > 1) { throw new Error('Arc must be 0<=arc<=1'); } @@ -49,7 +48,7 @@ class Rect extends ElementClass { super(peer, defaultAttributes); } - getType() { + static getType() { return 'Rect'; } diff --git a/packages/web2d/src/components/Text.js b/packages/web2d/src/components/Text.js index d79ef2ba..3371563d 100644 --- a/packages/web2d/src/components/Text.js +++ b/packages/web2d/src/components/Text.js @@ -15,89 +15,87 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; -import Element from './Element'; + +import { $assert } from '@wisemapping/core-js'; +import ElementClass from './ElementClass'; import Toolkit from './Toolkit'; import Font from './Font'; -const core = coreJs(); - -const Text = new Class({ - Extends: Element, - initialize(attributes) { +class Text extends ElementClass { + constructor(attributes) { const peer = Toolkit.createText(Font); - this.parent(peer, attributes); - }, + super(peer, attributes); + } - getType() { + static getType() { return 'Text'; - }, + } setText(text) { this.peer.setText(text); - }, + } setTextAlignment(align) { - core.Function.$assert(align, 'align can not be null'); + $assert(align, 'align can not be null'); this.peer.setTextAlignment(align); - }, + } setTextSize(width, height) { this.peer.setContentSize(width, height); - }, + } getText() { return this.peer.getText(); - }, + } setFont(font, size, style, weight) { this.peer.setFont(font, size, style, weight); - }, + } setColor(color) { this.peer.setColor(color); - }, + } getColor() { return this.peer.getColor(); - }, + } setStyle(style) { this.peer.setStyle(style); - }, + } setWeight(weight) { this.peer.setWeight(weight); - }, + } setFontFamily(family) { this.peer.setFontFamily(family); - }, + } getFont() { return this.peer.getFont(); - }, + } setSize(size) { this.peer.setSize(size); - }, + } getHtmlFontSize() { return this.peer.getHtmlFontSize(); - }, + } getWidth() { return this.peer.getWidth(); - }, + } getHeight() { return parseInt(this.peer.getHeight(), 10); - }, + } getFontHeight() { const lines = this.peer.getText().split('\n').length; return Math.round(this.getHeight() / lines); - }, -}); + } +} export default Text; diff --git a/packages/web2d/src/components/Workspace.js b/packages/web2d/src/components/Workspace.js index 94e613e7..c58ba341 100644 --- a/packages/web2d/src/components/Workspace.js +++ b/packages/web2d/src/components/Workspace.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import Element from './Element'; import Toolkit from './Toolkit'; -const core = coreJs(); - const Workspace = new Class({ Extends: Element, initialize(attributes) { @@ -52,7 +50,7 @@ const Workspace = new Class({ * Appends an element as a child to the object. */ append(element) { - if (!core.Function.$defined(element)) { + if (!$defined(element)) { throw new Error('Child element can not be null'); } const elementType = element.getType(); @@ -68,7 +66,7 @@ const Workspace = new Class({ }, addItAsChildTo(element) { - if (!core.Function.$defined(element)) { + if (!$defined(element)) { throw new Error('Workspace div container can not be null'); } element.append(this._htmlContainer); @@ -100,11 +98,11 @@ const Workspace = new Class({ */ setSize(width, height) { // HTML container must have the size of the group element. - if (core.Function.$defined(width)) { + if ($defined(width)) { this._htmlContainer.css('width', width); } - if (core.Function.$defined(height)) { + if ($defined(height)) { this._htmlContainer.css('height', height); } this.peer.setSize(width, height); @@ -183,7 +181,7 @@ const Workspace = new Class({ * Remove an element as a child to the object. */ removeChild(element) { - if (!core.Function.$defined(element)) { + if (!$defined(element)) { throw new Error('Child element can not be null'); } diff --git a/packages/web2d/src/components/header.js b/packages/web2d/src/components/header.js deleted file mode 100644 index 3886543c..00000000 --- a/packages/web2d/src/components/header.js +++ /dev/null @@ -1,23 +0,0 @@ -/* -* Copyright [2021] [wisemapping] -* -* Licensed under WiseMapping Public License, Version 1.0 (the "License"). -* It is basically the Apache License, Version 2.0 (the "License") plus the -* "powered by wisemapping" text requirement on every single page; -* you may not use this file except in compliance with the License. -* You may obtain a copy of the license at -* -* http://www.wisemapping.org/license -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -const web2d = {}; -web2d.peer = { - svg: {}, -}; -web2d.peer.utils = {}; diff --git a/packages/web2d/src/components/peer/svg/ArrowPeer.js b/packages/web2d/src/components/peer/svg/ArrowPeer.js index bcc31f6e..e4b3a16a 100644 --- a/packages/web2d/src/components/peer/svg/ArrowPeer.js +++ b/packages/web2d/src/components/peer/svg/ArrowPeer.js @@ -15,12 +15,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; + +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; import Point from '../../Point'; -const core = coreJs(); - const ArrowPeer = new Class({ Extends: ElementPeer, initialize() { @@ -52,10 +51,10 @@ const ArrowPeer = new Class({ setDashed(isDashed, length, spacing) { if ( - core.Function.$defined(isDashed) + $defined(isDashed) && isDashed - && core.Function.$defined(length) - && core.Function.$defined(spacing) + && $defined(length) + && $defined(spacing) ) { this._native.setAttribute('stroke-dasharray', `${length},${spacing}`); } else { @@ -79,10 +78,10 @@ const ArrowPeer = new Class({ let xp; let yp; if ( - core.Function.$defined(this._fromPoint.x) - && core.Function.$defined(this._fromPoint.y) - && core.Function.$defined(this._controlPoint.x) - && core.Function.$defined(this._controlPoint.y) + $defined(this._fromPoint.x) + && $defined(this._fromPoint.y) + && $defined(this._controlPoint.x) + && $defined(this._controlPoint.y) ) { if (this._controlPoint.y === 0) this._controlPoint.y = 1; diff --git a/packages/web2d/src/components/peer/svg/CurvedLinePeer.js b/packages/web2d/src/components/peer/svg/CurvedLinePeer.js index 4c86e341..c4b5bcf1 100644 --- a/packages/web2d/src/components/peer/svg/CurvedLinePeer.js +++ b/packages/web2d/src/components/peer/svg/CurvedLinePeer.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; import Point from '../../Point'; -const core = coreJs(); - const CurvedLinePeer = new Class({ Extends: ElementPeer, initialize() { @@ -38,7 +36,7 @@ const CurvedLinePeer = new Class({ setSrcControlPoint(control) { this._customControlPoint_1 = true; const change = this._control1.x !== control.x || this._control1.y !== control.y; - if (core.Function.$defined(control.x)) { + if ($defined(control.x)) { this._control1 = control; this._control1.x = parseInt(this._control1.x, 10); this._control1.y = parseInt(this._control1.y, 10); @@ -49,7 +47,7 @@ const CurvedLinePeer = new Class({ setDestControlPoint(control) { this._customControlPoint_2 = true; const change = this._control2.x !== control.x || this._control2.y !== control.y; - if (core.Function.$defined(control.x)) { + if ($defined(control.x)) { this._control2 = control; this._control2.x = parseInt(this._control2.x, 10); this._control2.y = parseInt(this._control2.y, 10); @@ -150,10 +148,10 @@ const CurvedLinePeer = new Class({ _updatePath(avoidControlPointFix) { if ( - core.Function.$defined(this._x1) - && core.Function.$defined(this._y1) - && core.Function.$defined(this._x2) - && core.Function.$defined(this._y2) + $defined(this._x1) + && $defined(this._y1) + && $defined(this._x2) + && $defined(this._y2) ) { this._calculateAutoControlPoints(avoidControlPointFix); const path = `M${this._x1},${this._y1} C${this._control1.x + this._x1},${this._control1.y + this._y1 @@ -209,14 +207,14 @@ const CurvedLinePeer = new Class({ ); if ( !this._customControlPoint_1 - && !(core.Function.$defined(avoidControlPointFix) && avoidControlPointFix === 0) + && !($defined(avoidControlPointFix) && avoidControlPointFix === 0) ) { this._control1.x = defaultpoints[0].x; this._control1.y = defaultpoints[0].y; } if ( !this._customControlPoint_2 - && !(core.Function.$defined(avoidControlPointFix) && avoidControlPointFix === 1) + && !($defined(avoidControlPointFix) && avoidControlPointFix === 1) ) { this._control2.x = defaultpoints[1].x; this._control2.y = defaultpoints[1].y; @@ -224,7 +222,7 @@ const CurvedLinePeer = new Class({ }, setDashed(length, spacing) { - if (core.Function.$defined(length) && core.Function.$defined(spacing)) { + if ($defined(length) && $defined(spacing)) { this._native.setAttribute('stroke-dasharray', `${length},${spacing}`); } else { this._native.setAttribute('stroke-dasharray', ''); diff --git a/packages/web2d/src/components/peer/svg/ElementPeer.js b/packages/web2d/src/components/peer/svg/ElementPeer.js index c445df59..80df7399 100644 --- a/packages/web2d/src/components/peer/svg/ElementPeer.js +++ b/packages/web2d/src/components/peer/svg/ElementPeer.js @@ -15,13 +15,12 @@ * 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 EventUtils from '../utils/EventUtils'; import TransformUtil from '../utils/TransformUtils'; import Element from '../../Element'; -const core = CoreJS(); - const ElementPeer = new Class({ initialize(svgElement) { this._native = svgElement; @@ -45,7 +44,7 @@ const ElementPeer = new Class({ getChildren() { let result = this._children; - if (!core.Function.$defined(result)) { + if (!$defined(result)) { result = []; this._children = result; } @@ -82,7 +81,7 @@ const ElementPeer = new Class({ const oldLength = children.length; children.erase(elementPeer); - core.Function.$assert( + $assert( children.length < oldLength, `element could not be removed:${elementPeer}`, ); @@ -112,12 +111,12 @@ const ElementPeer = new Class({ }, setSize(width, height) { - if (core.Function.$defined(width) && this._size.width !== parseInt(width, 10)) { + if ($defined(width) && this._size.width !== parseInt(width, 10)) { this._size.width = parseInt(width, 10); this._native.setAttribute('width', parseInt(width, 10)); } - if (core.Function.$defined(height) && this._size.height !== parseInt(height, 10)) { + if ($defined(height) && this._size.height !== parseInt(height, 10)) { this._size.height = parseInt(height, 10); this._native.setAttribute('height', parseInt(height, 10)); } @@ -130,10 +129,10 @@ const ElementPeer = new Class({ }, setFill(color, opacity) { - if (core.Function.$defined(color)) { + if ($defined(color)) { this._native.setAttribute('fill', color); } - if (core.Function.$defined(opacity)) { + if ($defined(opacity)) { this._native.setAttribute('fill-opacity', opacity); } }, @@ -159,13 +158,13 @@ const ElementPeer = new Class({ }, setStroke(width, style, color, opacity) { - if (core.Function.$defined(width)) { + if ($defined(width)) { this._native.setAttribute('stroke-width', `${width}px`); } - if (core.Function.$defined(color)) { + if ($defined(color)) { this._native.setAttribute('stroke', color); } - if (core.Function.$defined(style)) { + if ($defined(style)) { // Scale the dash array in order to be equal to VML. In VML, stroke style doesn't scale. const dashArrayPoints = this.__stokeStyleToStrokDasharray[style]; const scale = 1 / TransformUtil.workoutScale(this).width; @@ -186,7 +185,7 @@ const ElementPeer = new Class({ this._stokeStyle = style; } - if (core.Function.$defined(opacity)) { + if ($defined(opacity)) { this._native.setAttribute('stroke-opacity', opacity); } }, @@ -214,7 +213,7 @@ const ElementPeer = new Class({ attachChangeEventListener(type, listener) { const listeners = this.getChangeEventListeners(type); - if (!core.Function.$defined(listener)) { + if (!$defined(listener)) { throw new Error('Listener can not be null'); } listeners.push(listener); @@ -222,7 +221,7 @@ const ElementPeer = new Class({ getChangeEventListeners(type) { let listeners = this._changeListeners[type]; - if (!core.Function.$defined(listeners)) { + if (!$defined(listeners)) { listeners = []; this._changeListeners[type] = listeners; } diff --git a/packages/web2d/src/components/peer/svg/ElipsePeer.js b/packages/web2d/src/components/peer/svg/ElipsePeer.js index e59d993c..39a6c72d 100644 --- a/packages/web2d/src/components/peer/svg/ElipsePeer.js +++ b/packages/web2d/src/components/peer/svg/ElipsePeer.js @@ -15,11 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; -const core = coreJs(); - const ElipsePeer = new Class({ Extends: ElementPeer, initialize() { @@ -31,11 +29,11 @@ const ElipsePeer = new Class({ setSize(width, height) { this.parent(width, height); - if (core.Function.$defined(width)) { + if ($defined(width)) { this._native.setAttribute('rx', width / 2); } - if (core.Function.$defined(height)) { + if ($defined(height)) { this._native.setAttribute('ry', height / 2); } @@ -49,11 +47,11 @@ const ElipsePeer = new Class({ const cx = (size.width / 2) + pcx; const cy = (size.height / 2) + pcy; - if (core.Function.$defined(cx)) { + if ($defined(cx)) { this._native.setAttribute('cx', cx); } - if (core.Function.$defined(cy)) { + if ($defined(cy)) { this._native.setAttribute('cy', cy); } }, diff --git a/packages/web2d/src/components/peer/svg/Font.js b/packages/web2d/src/components/peer/svg/Font.js index ecc79081..0be3ee2c 100644 --- a/packages/web2d/src/components/peer/svg/Font.js +++ b/packages/web2d/src/components/peer/svg/Font.js @@ -15,9 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import CoreJS from '@wisemapping/core-js'; - -const core = CoreJS(); +import { $defined } from '@wisemapping/core-js'; const Font = new Class({ initialize() { @@ -27,13 +25,13 @@ const Font = new Class({ }, init(args) { - if (core.Function.$defined(args.size)) { + if ($defined(args.size)) { this._size = parseInt(args.size, 10); } - if (core.Function.$defined(args.style)) { + if ($defined(args.style)) { this._style = args.style; } - if (core.Function.$defined(args.weight)) { + if ($defined(args.weight)) { this._weight = args.weight; } }, diff --git a/packages/web2d/src/components/peer/svg/GroupPeer.js b/packages/web2d/src/components/peer/svg/GroupPeer.js index cd29c4bb..4d7ff075 100644 --- a/packages/web2d/src/components/peer/svg/GroupPeer.js +++ b/packages/web2d/src/components/peer/svg/GroupPeer.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; import EventUtils from '../utils/EventUtils'; -const core = coreJs(); - const GroupPeer = new Class({ Extends: ElementPeer, initialize() { @@ -103,11 +101,11 @@ const GroupPeer = new Class({ setCoordOrigin(x, y) { const change = x !== this._coordOrigin.x || y !== this._coordOrigin.y; - if (core.Function.$defined(x)) { + if ($defined(x)) { this._coordOrigin.x = x; } - if (core.Function.$defined(y)) { + if ($defined(y)) { this._coordOrigin.y = y; } if (change) { @@ -125,11 +123,11 @@ const GroupPeer = new Class({ setPosition(x, y) { const change = x !== this._position.x || y !== this._position.y; - if (core.Function.$defined(x)) { + if ($defined(x)) { this._position.x = parseInt(x, 10); } - if (core.Function.$defined(y)) { + if ($defined(y)) { this._position.y = parseInt(y, 10); } if (change) { diff --git a/packages/web2d/src/components/peer/svg/LinePeer.js b/packages/web2d/src/components/peer/svg/LinePeer.js index 400d0b84..17074dba 100644 --- a/packages/web2d/src/components/peer/svg/LinePeer.js +++ b/packages/web2d/src/components/peer/svg/LinePeer.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; import Point from '../../Point'; -const core = coreJs(); - const LinePeer = new Class({ Extends: ElementPeer, initialize() { @@ -55,11 +53,11 @@ const LinePeer = new Class({ * http://www.zvon.org/HowTo/Output/howto_jj_svg_27.html?at=marker-end */ setArrowStyle(startStyle, endStyle) { - if (core.Function.$defined(startStyle)) { + if ($defined(startStyle)) { // Todo: This must be implemented ... } - if (core.Function.$defined(endStyle)) { + if ($defined(endStyle)) { // Todo: This must be implemented ... } }, diff --git a/packages/web2d/src/components/peer/svg/PolyLinePeer.js b/packages/web2d/src/components/peer/svg/PolyLinePeer.js index eb30f591..2c55eb81 100644 --- a/packages/web2d/src/components/peer/svg/PolyLinePeer.js +++ b/packages/web2d/src/components/peer/svg/PolyLinePeer.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import * as PolyLineUtils from '../utils/PolyLineUtils'; import ElementPeer from './ElementPeer'; -const core = coreJs(); - const PolyLinePeer = new Class({ Extends: ElementPeer, initialize() { @@ -71,10 +69,10 @@ const PolyLinePeer = new Class({ _updateStraightPath() { if ( - core.Function.$defined(this._x1) - && core.Function.$defined(this._x2) - && core.Function.$defined(this._y1) - && core.Function.$defined(this._y2) + $defined(this._x1) + && $defined(this._x2) + && $defined(this._y1) + && $defined(this._y2) ) { const path = PolyLineUtils.buildStraightPath.call( this, @@ -94,10 +92,10 @@ const PolyLinePeer = new Class({ const x2 = this._x2; const y2 = this._y2; if ( - core.Function.$defined(x1) - && core.Function.$defined(x2) - && core.Function.$defined(y1) - && core.Function.$defined(y2) + $defined(x1) + && $defined(x2) + && $defined(y1) + && $defined(y2) ) { const diff = x2 - x1; const middlex = diff / 2 + x1; @@ -118,10 +116,10 @@ const PolyLinePeer = new Class({ _updateCurvePath() { if ( - core.Function.$defined(this._x1) - && core.Function.$defined(this._x2) - && core.Function.$defined(this._y1) - && core.Function.$defined(this._y2) + $defined(this._x1) + && $defined(this._x2) + && $defined(this._y1) + && $defined(this._y2) ) { const path = PolyLineUtils.buildCurvedPath.call( this, diff --git a/packages/web2d/src/components/peer/svg/RectPeer.js b/packages/web2d/src/components/peer/svg/RectPeer.js index 12e7ae60..6e53bffe 100644 --- a/packages/web2d/src/components/peer/svg/RectPeer.js +++ b/packages/web2d/src/components/peer/svg/RectPeer.js @@ -15,11 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; -const core = coreJs(); - /** * http://www.w3.org/TR/SVG/shapes.html#RectElement */ @@ -33,10 +31,10 @@ const RectPeer = new Class({ }, setPosition(x, y) { - if (core.Function.$defined(x)) { + if ($defined(x)) { this._native.setAttribute('x', parseInt(x, 10)); } - if (core.Function.$defined(y)) { + if ($defined(y)) { this._native.setAttribute('y', parseInt(y, 10)); } }, @@ -51,7 +49,7 @@ const RectPeer = new Class({ this.parent(width, height); const min = width < height ? width : height; - if (core.Function.$defined(this._arc)) { + if ($defined(this._arc)) { // Transform percentages to SVG format. const arc = (min / 2) * this._arc; this._native.setAttribute('rx', arc); diff --git a/packages/web2d/src/components/peer/svg/TextPeer.js b/packages/web2d/src/components/peer/svg/TextPeer.js index e0e8e4f4..c4c25ff2 100644 --- a/packages/web2d/src/components/peer/svg/TextPeer.js +++ b/packages/web2d/src/components/peer/svg/TextPeer.js @@ -15,11 +15,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; -const core = coreJs(); - const TextPeer = new Class({ Extends: ElementPeer, initialize(Font) { @@ -39,7 +37,7 @@ const TextPeer = new Class({ }, getTextAlignment() { - return core.Function.$defined(this._textAlign) ? this._textAlign : 'left'; + return $defined(this._textAlign) ? this._textAlign : 'left'; }, setText(text) { @@ -86,16 +84,16 @@ const TextPeer = new Class({ }, setFont(font, size, style, weight) { - if (core.Function.$defined(font)) { + if ($defined(font)) { this._font = new this.Font(font, this); } - if (core.Function.$defined(style)) { + if ($defined(style)) { this._font.setStyle(style); } - if (core.Function.$defined(weight)) { + if ($defined(weight)) { this._font.setWeight(weight); } - if (core.Function.$defined(size)) { + if ($defined(size)) { this._font.setSize(size); } this._updateFontStyle(); diff --git a/packages/web2d/src/components/peer/svg/WorkspacePeer.js b/packages/web2d/src/components/peer/svg/WorkspacePeer.js index 30dcedb4..5958bb0a 100644 --- a/packages/web2d/src/components/peer/svg/WorkspacePeer.js +++ b/packages/web2d/src/components/peer/svg/WorkspacePeer.js @@ -15,12 +15,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import coreJs from '@wisemapping/core-js'; +import { $defined } from '@wisemapping/core-js'; import ElementPeer from './ElementPeer'; import EventUtils from '../utils/EventUtils'; -const core = coreJs(); - const WorkspacePeer = new Class({ Extends: ElementPeer, initialize(element) { @@ -58,11 +56,11 @@ const WorkspacePeer = new Class({ if (viewBox != null) { coords = viewBox.split(/ /); } - if (core.Function.$defined(width)) { + if ($defined(width)) { coords[2] = width; } - if (core.Function.$defined(height)) { + if ($defined(height)) { coords[3] = height; } @@ -89,11 +87,11 @@ const WorkspacePeer = new Class({ coords = viewBox.split(/ /); } - if (core.Function.$defined(x)) { + if ($defined(x)) { coords[0] = x; } - if (core.Function.$defined(y)) { + if ($defined(y)) { coords[1] = y; } diff --git a/packages/web2d/src/components/peer/utils/EventUtils.js b/packages/web2d/src/components/peer/utils/EventUtils.js index 6e559a1c..f0dd7a2d 100644 --- a/packages/web2d/src/components/peer/utils/EventUtils.js +++ b/packages/web2d/src/components/peer/utils/EventUtils.js @@ -15,14 +15,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import CoreJS from '@wisemapping/core-js'; - -const core = CoreJS(); +import { $defined } from '@wisemapping/core-js'; const EventUtils = { broadcastChangeEvent(elementPeer, type) { const listeners = elementPeer.getChangeEventListeners(type); - if (core.Function.$defined(listeners)) { + if ($defined(listeners)) { for (let i = 0; i < listeners.length; i++) { const listener = listeners[i]; listener.call(elementPeer, null);