From a230d343ab90f978b120a13fb09dc9141a45050e Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Fri, 9 Dec 2022 20:56:01 -0800 Subject: [PATCH] Fix connection line type. --- packages/editor/src/components/index.tsx | 6 +-- packages/mindplot/.eslintrc.json | 46 ++++++++++--------- packages/mindplot/src/@types/custom.d.ts | 1 + .../src/components/ActionDispatcher.ts | 2 +- .../mindplot/src/components/ConnectionLine.ts | 39 ++++++++-------- .../mindplot/src/components/EmojiCharIcon.ts | 2 +- packages/mindplot/src/components/IconGroup.ts | 2 +- .../mindplot/src/components/Relationship.ts | 6 +-- .../mindplot/src/components/ScreenManager.ts | 2 +- packages/mindplot/src/components/Topic.ts | 2 +- .../src/components/model/RelationshipModel.ts | 4 +- .../persistence/XMLSerializerFactory.ts | 1 - .../persistence/XMLSerializerTango.ts | 4 +- packages/mindplot/src/index.ts | 1 + 14 files changed, 60 insertions(+), 58 deletions(-) diff --git a/packages/editor/src/components/index.tsx b/packages/editor/src/components/index.tsx index 5a2ca375..aeabb1cb 100644 --- a/packages/editor/src/components/index.tsx +++ b/packages/editor/src/components/index.tsx @@ -89,10 +89,8 @@ const Editor = ({ model.registerEvents(setCanvasUpdate, capability); }) .catch((e) => { - console.error(JSON.stringify(e)); - window.newrelic?.noticeError( - new Error(`Unexpected error loading map ${mapInfo.getId()} = ${JSON.stringify(e)}`), - ); + console.error(e); + window.newrelic?.noticeError(e); }); setModel(model); } diff --git a/packages/mindplot/.eslintrc.json b/packages/mindplot/.eslintrc.json index 3fae3a03..72d93e56 100644 --- a/packages/mindplot/.eslintrc.json +++ b/packages/mindplot/.eslintrc.json @@ -22,23 +22,25 @@ "@typescript-eslint" ], "rules": { - // ignore errors when a line finishes with (setting this value to 0 ignores all errors) - "operator-linebreak": [ - "error", "after", { - "overrides": { - "+": "ignore", - "-": "ignore", - ":": "ignore", - "*": "ignore", - "?": "ignore", - ">": "ignore", - "||": "ignore", - "&&": "ignore", - "(": "ignore" - } - } - ], - "object-curly-newline": "off", + // ignore errors when a line finishes with (setting this value to 0 ignores all errors) + "operator-linebreak": [ + "error", + "after", + { + "overrides": { + "+": "ignore", + "-": "ignore", + ":": "ignore", + "*": "ignore", + "?": "ignore", + ">": "ignore", + "||": "ignore", + "&&": "ignore", + "(": "ignore" + } + } + ], + "object-curly-newline": "off", "no-underscore-dangle": "off", "no-plusplus": "off", "no-param-reassign": "off", @@ -48,10 +50,10 @@ ], "class-methods-use-this": "off", "no-console": "off", - // codebase contains many this aliases, fix in the future? + "@typescript-eslint/no-explicit-any": "error", + "@typescript-eslint/no-unused-vars": "error", "@typescript-eslint/no-this-alias": "off", - // Remove once migration is completed ... - "@typescript-eslint/no-explicit-any": "warn", + "@typescript-eslint/no-non-null-assertion": "off", "import/extensions": [ "error", "ignorePackages", @@ -62,7 +64,7 @@ "tsx": "never" } ], - "implicit-arrow-linebreak": "off" + "implicit-arrow-linebreak": "off" }, "settings": { "import/resolver": { @@ -77,4 +79,4 @@ } } } -} +} \ No newline at end of file diff --git a/packages/mindplot/src/@types/custom.d.ts b/packages/mindplot/src/@types/custom.d.ts index 2ff57beb..957d9d84 100644 --- a/packages/mindplot/src/@types/custom.d.ts +++ b/packages/mindplot/src/@types/custom.d.ts @@ -1,4 +1,5 @@ declare module '*.svg' { + // eslint-disable-next-line @typescript-eslint/no-explicit-any const content: any; export default content; } diff --git a/packages/mindplot/src/components/ActionDispatcher.ts b/packages/mindplot/src/components/ActionDispatcher.ts index 4e99a739..5499782f 100644 --- a/packages/mindplot/src/components/ActionDispatcher.ts +++ b/packages/mindplot/src/components/ActionDispatcher.ts @@ -21,7 +21,7 @@ import { $assert } from '@wisemapping/core-js'; import Point from '@wisemapping/web2d'; import { Mindmap } from '..'; import CommandContext from './CommandContext'; -import RelationshipControlPoints, { PivotType } from './RelationshipControlPoints'; +import { PivotType } from './RelationshipControlPoints'; import Events from './Events'; import NodeModel from './model/NodeModel'; import RelationshipModel from './model/RelationshipModel'; diff --git a/packages/mindplot/src/components/ConnectionLine.ts b/packages/mindplot/src/components/ConnectionLine.ts index 1131ecfd..9775bcf1 100644 --- a/packages/mindplot/src/components/ConnectionLine.ts +++ b/packages/mindplot/src/components/ConnectionLine.ts @@ -16,7 +16,7 @@ * limitations under the License. */ -import { $assert, $defined } from '@wisemapping/core-js'; +import { $assert } from '@wisemapping/core-js'; import { Point, CurvedLine, PolyLine, Line } from '@wisemapping/web2d'; import { TopicShape } from './model/INodeModel'; import RelationshipModel from './model/RelationshipModel'; @@ -24,18 +24,26 @@ import Topic from './Topic'; import TopicConfig from './TopicConfig'; import Workspace from './Workspace'; +// eslint-disable-next-line no-shadow +export enum LineType { + SIMPLE, + POLYLINE, + CURVED, + SIMPLE_CURVED, +} + class ConnectionLine { protected _targetTopic: Topic; protected _sourceTopic: Topic; - protected _lineType: number; + protected _lineType: LineType; protected _line2d: Line; protected _model: RelationshipModel; - constructor(sourceNode: Topic, targetNode: Topic, lineType?: number) { + constructor(sourceNode: Topic, targetNode: Topic) { $assert(targetNode, 'parentNode node can not be null'); $assert(sourceNode, 'childNode node can not be null'); $assert(sourceNode !== targetNode, 'Circular connection'); @@ -46,11 +54,11 @@ class ConnectionLine { let line: Line; const ctrlPoints = this._getCtrlPoints(sourceNode, targetNode); if (targetNode.getType() === 'CentralTopic') { - line = this._createLine(lineType, ConnectionLine.CURVED); + line = this._createLine(LineType.CURVED); line.setSrcControlPoint(ctrlPoints[0]); line.setDestControlPoint(ctrlPoints[1]); } else { - line = this._createLine(lineType, ConnectionLine.SIMPLE_CURVED); + line = this._createLine(LineType.SIMPLE_CURVED); line.setSrcControlPoint(ctrlPoints[0]); line.setDestControlPoint(ctrlPoints[1]); } @@ -69,24 +77,25 @@ class ConnectionLine { return [new Point(deltaX, 0), new Point(-deltaX, 0)]; } - protected _createLine(lineTypeParam: number, defaultStyle: number): Line { - const lineType = $defined(lineTypeParam) ? lineTypeParam : defaultStyle; + protected _createLine(lineType: LineType): Line { this._lineType = lineType; let line: ConnectionLine; switch (lineType) { - case ConnectionLine.POLYLINE: + case LineType.POLYLINE: line = new PolyLine(); break; - case ConnectionLine.CURVED: + case LineType.CURVED: line = new CurvedLine(); break; - case ConnectionLine.SIMPLE_CURVED: + case LineType.SIMPLE_CURVED: line = new CurvedLine(); (line as CurvedLine).setStyle(CurvedLine.SIMPLE_LINE); break; - default: + case LineType.SIMPLE: line = new Line(); break; + default: + throw new Error(`Unexpected line type. ${lineType}`); } return line; } @@ -205,14 +214,6 @@ class ConnectionLine { this._line2d.moveToFront(); } - static SIMPLE = 0; - - static POLYLINE = 1; - - static CURVED = 2; - - static SIMPLE_CURVED = 3; - static getStrokeColor = () => '#495879'; } diff --git a/packages/mindplot/src/components/EmojiCharIcon.ts b/packages/mindplot/src/components/EmojiCharIcon.ts index 990c4a16..1e3c18b6 100644 --- a/packages/mindplot/src/components/EmojiCharIcon.ts +++ b/packages/mindplot/src/components/EmojiCharIcon.ts @@ -81,7 +81,7 @@ class EmojiCharIcon implements Icon { return this.group.getPosition(); } - addEvent(type: string, fnc: any): void { + addEvent(type: string, fnc: (e: object) => void): void { this.element.addEvent(type, fnc); } diff --git a/packages/mindplot/src/components/IconGroup.ts b/packages/mindplot/src/components/IconGroup.ts index 6a2efc6d..71f8aecd 100644 --- a/packages/mindplot/src/components/IconGroup.ts +++ b/packages/mindplot/src/components/IconGroup.ts @@ -31,7 +31,7 @@ ORDER_BY_TYPE.set('link', 2); class IconGroup { private _icons: ImageIcon[]; - private _group: any; + private _group; private _removeTip: IconGroupRemoveTip; diff --git a/packages/mindplot/src/components/Relationship.ts b/packages/mindplot/src/components/Relationship.ts index d5960f52..adc3a2dd 100644 --- a/packages/mindplot/src/components/Relationship.ts +++ b/packages/mindplot/src/components/Relationship.ts @@ -17,7 +17,7 @@ */ import { $assert, $defined } from '@wisemapping/core-js'; import { Arrow, Point, CurvedLine } from '@wisemapping/web2d'; -import ConnectionLine from './ConnectionLine'; +import ConnectionLine, { LineType } from './ConnectionLine'; import RelationshipControlPoints from './RelationshipControlPoints'; import RelationshipModel from './model/RelationshipModel'; import PositionType from './PositionType'; @@ -48,7 +48,7 @@ class Relationship extends ConnectionLine { $assert(sourceNode, 'sourceNode can not be null'); $assert(targetNode, 'targetNode can not be null'); - super(sourceNode, targetNode, model.getLineType()); + super(sourceNode, targetNode); this.setModel(model); const strokeColor = Relationship.getStrokeColor(); @@ -62,7 +62,7 @@ class Relationship extends ConnectionLine { this._line2d.setTestId(`${model.getFromNode()}-${model.getToNode()}-relationship`); // Build focus shape ... - this._focusShape = this._createLine(this.getLineType(), ConnectionLine.SIMPLE_CURVED); + this._focusShape = this._createLine(LineType.SIMPLE_CURVED); this._focusShape.setStroke(8, 'solid', '#3f96ff'); this._focusShape.setIsSrcControlPointCustom(false); this._focusShape.setIsDestControlPointCustom(false); diff --git a/packages/mindplot/src/components/ScreenManager.ts b/packages/mindplot/src/components/ScreenManager.ts index 390de950..1ed35f81 100644 --- a/packages/mindplot/src/components/ScreenManager.ts +++ b/packages/mindplot/src/components/ScreenManager.ts @@ -16,7 +16,7 @@ * limitations under the License. */ import $ from 'jquery'; -import { $assert, $defined } from '@wisemapping/core-js'; +import { $assert } from '@wisemapping/core-js'; import { Point } from '@wisemapping/web2d'; // https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo // https://web.dev/uses-passive-event-listeners/?utm_source=lighthouse&utm_medium=lr diff --git a/packages/mindplot/src/components/Topic.ts b/packages/mindplot/src/components/Topic.ts index ed1e6e0f..13d25de6 100644 --- a/packages/mindplot/src/components/Topic.ts +++ b/packages/mindplot/src/components/Topic.ts @@ -629,7 +629,7 @@ abstract class Topic extends NodeGraph { group.setTestId(model.getId()); } - _registerDefaultListenersToElement(elem: ElementClass, topic: Topic) { + private _registerDefaultListenersToElement(elem: ElementClass, topic: Topic) { const mouseOver = function mouseOver() { if (topic.isMouseEventsEnabled()) { topic.handleMouseOver(); diff --git a/packages/mindplot/src/components/model/RelationshipModel.ts b/packages/mindplot/src/components/model/RelationshipModel.ts index 3fb8686c..95238fe3 100644 --- a/packages/mindplot/src/components/model/RelationshipModel.ts +++ b/packages/mindplot/src/components/model/RelationshipModel.ts @@ -17,7 +17,7 @@ */ import { $assert, $defined } from '@wisemapping/core-js'; import Point from '@wisemapping/web2d'; -import ConnectionLine from '../ConnectionLine'; +import { LineType } from '../ConnectionLine'; class RelationshipModel { static _nextUuid = 0; @@ -47,7 +47,7 @@ class RelationshipModel { this._id = RelationshipModel._nextUUID(); this._sourceTargetId = sourceTopicId; this._targetTopicId = targetTopicId; - this._lineType = ConnectionLine.SIMPLE_CURVED; + this._lineType = LineType.SIMPLE_CURVED; this._srcCtrlPoint = null; this._destCtrlPoint = null; this._endArrow = true; diff --git a/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts b/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts index 0735617d..5e6b8b84 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts +++ b/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts @@ -15,7 +15,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { $assert } from '@wisemapping/core-js'; import ModelCodeName from './ModelCodeName'; import Beta2PelaMigrator from './Beta2PelaMigrator'; import Pela2TangoMigrator from './Pela2TangoMigrator'; diff --git a/packages/mindplot/src/components/persistence/XMLSerializerTango.ts b/packages/mindplot/src/components/persistence/XMLSerializerTango.ts index 6643ad41..49aae2ef 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializerTango.ts +++ b/packages/mindplot/src/components/persistence/XMLSerializerTango.ts @@ -19,7 +19,7 @@ import { $assert, $defined, createDocument } from '@wisemapping/core-js'; import { Point } from '@wisemapping/web2d'; import Mindmap from '../model/Mindmap'; import { TopicShape } from '../model/INodeModel'; -import ConnectionLine from '../ConnectionLine'; +import { LineType } from '../ConnectionLine'; import FeatureModelFactory from '../model/FeatureModelFactory'; import NodeModel from '../model/NodeModel'; import RelationshipModel from '../model/RelationshipModel'; @@ -207,7 +207,7 @@ class XMLSerializerTango implements XMLMindmapSerializer { const lineType = relationship.getLineType(); result.setAttribute('lineType', lineType.toString()); - if (lineType === ConnectionLine.CURVED || lineType === ConnectionLine.SIMPLE_CURVED) { + if (lineType === LineType.CURVED || lineType === LineType.SIMPLE_CURVED) { if ($defined(relationship.getSrcCtrlPoint())) { const srcPoint = relationship.getSrcCtrlPoint(); result.setAttribute('srcCtrlPoint', `${Math.round(srcPoint.x)},${Math.round(srcPoint.y)}`); diff --git a/packages/mindplot/src/index.ts b/packages/mindplot/src/index.ts index a7454486..3ccf87af 100644 --- a/packages/mindplot/src/index.ts +++ b/packages/mindplot/src/index.ts @@ -58,6 +58,7 @@ declare global { var designer: Designer; } +// eslint-disable-next-line @typescript-eslint/no-explicit-any const globalAny: any = global; globalAny.jQuery = jquery; // WebComponent registration