diff --git a/packages/mindplot/src/components/Command.ts b/packages/mindplot/src/components/Command.ts index a1cb6feb..a5677ca0 100644 --- a/packages/mindplot/src/components/Command.ts +++ b/packages/mindplot/src/components/Command.ts @@ -23,7 +23,7 @@ abstract class Command { static _uuid: number; - private _discardDuplicated: string; + private _discardDuplicated: string | undefined; constructor() { this._id = Command._nextUUID(); @@ -46,7 +46,7 @@ abstract class Command { return this._uuid; } - getDiscardDuplicated(): string { + getDiscardDuplicated(): string | undefined { return this._discardDuplicated; } diff --git a/packages/mindplot/src/components/DesignerKeyboard.ts b/packages/mindplot/src/components/DesignerKeyboard.ts index 1f84f1e1..ec77efdb 100644 --- a/packages/mindplot/src/components/DesignerKeyboard.ts +++ b/packages/mindplot/src/components/DesignerKeyboard.ts @@ -219,7 +219,7 @@ class DesignerKeyboard extends Keyboard { }); } - private _goToBrother(designer: Designer, node: Topic, direction) { + private _goToBrother(designer: Designer, node: Topic, direction: 'UP' | 'DOWN') { const parent = node.getParent(); if (parent) { const brothers = parent.getChildren(); @@ -227,19 +227,19 @@ class DesignerKeyboard extends Keyboard { let target = node; const { y } = node.getPosition(); const { x } = node.getPosition(); - let dist = null; + let dist: number | null = null; for (let i = 0; i < brothers.length; i++) { const sameSide = x * brothers[i].getPosition().x >= 0; if (brothers[i] !== node && sameSide) { const brother = brothers[i]; const brotherY = brother.getPosition().y; if (direction === 'DOWN' && brotherY > y) { - let distancia = y - brotherY; - if (distancia < 0) { - distancia *= -1; + let distance = y - brotherY; + if (distance < 0) { + distance *= -1; } - if (dist == null || dist > distancia) { - dist = distancia; + if (dist == null || dist > distance) { + dist = distance; target = brothers[i]; } } else if (direction === 'UP' && brotherY < y) { diff --git a/packages/mindplot/src/components/DesignerModel.ts b/packages/mindplot/src/components/DesignerModel.ts index 3b1ac42e..2f0c1ef3 100644 --- a/packages/mindplot/src/components/DesignerModel.ts +++ b/packages/mindplot/src/components/DesignerModel.ts @@ -107,7 +107,7 @@ class DesignerModel extends Events { // Add node only if it's valid. if (isValid) { result.push(topic.getId()); - } else { + } else if (errorMsg) { $notify(errorMsg); } }); diff --git a/packages/mindplot/src/components/DragConnector.ts b/packages/mindplot/src/components/DragConnector.ts index 2690f869..62b27c6f 100644 --- a/packages/mindplot/src/components/DragConnector.ts +++ b/packages/mindplot/src/components/DragConnector.ts @@ -100,8 +100,8 @@ class DragConnector { const av = me._isVerticallyAligned(a.getSize(), aPos, sPos); const bv = me._isVerticallyAligned(b.getSize(), bPos, sPos); return ( - me._proximityWeight(av, a, sPos, currentConnection) - - me._proximityWeight(bv, b, sPos, currentConnection) + me._proximityWeight(av, a, sPos, currentConnection!) - + me._proximityWeight(bv, b, sPos, currentConnection!) ); }); return topics; diff --git a/packages/mindplot/src/components/DragPivot.ts b/packages/mindplot/src/components/DragPivot.ts index ccbfbfd0..2d751281 100644 --- a/packages/mindplot/src/components/DragPivot.ts +++ b/packages/mindplot/src/components/DragPivot.ts @@ -29,7 +29,7 @@ class DragPivot { private _isVisible: boolean; - private _targetTopic: Topic; + private _targetTopic: Topic | null; private _connectRect: Rect; @@ -57,7 +57,7 @@ class DragPivot { return this._isVisible; } - getTargetTopic(): Topic { + getTargetTopic(): Topic | null { return this._targetTopic; } @@ -91,7 +91,7 @@ class DragPivot { // Calculate pivot connection point ... const size = this._size; - const targetPosition = targetTopic.getPosition(); + const targetPosition = targetTopic!.getPosition(); const line = this._getConnectionLine(); // Update Line position. @@ -106,7 +106,7 @@ class DragPivot { // Make line visible only when the position has been already changed. // This solve several strange effects ;) - const targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint); + const targetPoint = targetTopic!.workoutIncomingConnectionPoint(pivotPoint); line.setTo(targetPoint.x, targetPoint.y); } diff --git a/packages/mindplot/src/components/DragTopic.ts b/packages/mindplot/src/components/DragTopic.ts index d7aee43b..3bd775f0 100644 --- a/packages/mindplot/src/components/DragTopic.ts +++ b/packages/mindplot/src/components/DragTopic.ts @@ -73,14 +73,14 @@ class DragTopic { if (this.isConnected() && !this.isFreeLayoutOn()) { const parent = this.getConnectedToTopic(); const predict = this._layoutManager.predict( - parent.getId(), + parent!.getId(), this._draggedNode.getId(), this.getPosition(), ); if (this._order !== predict.order) { const dragPivot = this._getDragPivot(); const pivotPosition = predict.position; - dragPivot.connectTo(parent, pivotPosition); + dragPivot.connectTo(parent!, pivotPosition); this.setOrder(predict.order); } } @@ -191,7 +191,7 @@ class DragTopic { } } - getConnectedToTopic(): Topic { + getConnectedToTopic(): Topic | null { const dragPivot = this._getDragPivot(); return dragPivot.getTargetTopic(); } diff --git a/packages/mindplot/src/components/IconGroup.ts b/packages/mindplot/src/components/IconGroup.ts index 71f8aecd..15e48340 100644 --- a/packages/mindplot/src/components/IconGroup.ts +++ b/packages/mindplot/src/components/IconGroup.ts @@ -97,7 +97,7 @@ class IconGroup { icons.push(icon); this._icons = icons.sort( (a, b) => - ORDER_BY_TYPE.get(a.getModel().getType()) - ORDER_BY_TYPE.get(b.getModel().getType()), + ORDER_BY_TYPE.get(a.getModel().getType())! - ORDER_BY_TYPE.get(b.getModel().getType())!, ); // Add all the nodes back ... @@ -115,7 +115,7 @@ class IconGroup { } private _findIconFromModel(iconModel: FeatureModel) { - let result = null; + let result: ImageIcon | null = null; this._icons.forEach((icon) => { const elModel = icon.getModel(); diff --git a/packages/mindplot/src/components/WidgetManager.ts b/packages/mindplot/src/components/WidgetManager.ts index 821b9382..7dd4aa6d 100644 --- a/packages/mindplot/src/components/WidgetManager.ts +++ b/packages/mindplot/src/components/WidgetManager.ts @@ -24,9 +24,11 @@ abstract class WidgetManager { linkModel?: LinkModel, noteModel?: NoteModel, ) { - const webcomponentShadowRoot = $($('#mindmap-comp')[0].shadowRoot); + const { shadowRoot } = $('#mindmap-comp')[0]; + const webcomponentShadowRoot = $(shadowRoot!); + let tooltip = webcomponentShadowRoot.find('#mindplot-svg-tooltip'); - if (!tooltip.length) { + if (!tooltip.length || !tooltip) { webcomponentShadowRoot.append( '
' + '
' + @@ -48,7 +50,7 @@ abstract class WidgetManager { }); } - mindmapElement.addEvent('mouseenter', (evt) => { + mindmapElement.addEvent('mouseenter', (evt: MouseEvent) => { webcomponentShadowRoot.find('#mindplot-svg-tooltip-title').html(title); if (linkModel) { webcomponentShadowRoot @@ -63,8 +65,9 @@ abstract class WidgetManager { webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-note').css({ display: 'block' }); webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-link').css({ display: 'none' }); } - const targetRect = evt.target.getBoundingClientRect(); - const newX = Math.max(0, targetRect.left + targetRect.width / 2 - tooltip.width() / 2); + const targetRect = (evt.target as Element).getBoundingClientRect(); + const width = tooltip.width() || 0; + const newX = Math.max(0, targetRect.left + targetRect.width / 2 - width / 2); const newY = Math.max(0, targetRect.bottom); tooltip.css({ top: newY, left: newX, position: 'absolute' }); tooltip.css({ display: 'block' }); @@ -77,11 +80,11 @@ abstract class WidgetManager { }); } - createTooltipForLink(topic: Topic, linkModel: LinkModel, linkIcon: LinkIcon) { + createTooltipForLink(_topic: Topic, linkModel: LinkModel, linkIcon: LinkIcon) { this.createTooltip(linkIcon.getElement().peer, $msg('LINK'), linkModel, undefined); } - createTooltipForNote(topic: Topic, noteModel: NoteModel, noteIcon: NoteIcon): void { + createTooltipForNote(_topic: Topic, noteModel: NoteModel, noteIcon: NoteIcon): void { this.createTooltip(noteIcon.getElement().peer, $msg('NOTE'), undefined, noteModel); } diff --git a/packages/mindplot/src/components/commands/DragTopicCommand.ts b/packages/mindplot/src/components/commands/DragTopicCommand.ts index 8c97c250..7737291d 100644 --- a/packages/mindplot/src/components/commands/DragTopicCommand.ts +++ b/packages/mindplot/src/components/commands/DragTopicCommand.ts @@ -24,7 +24,7 @@ import Topic from '../Topic'; class DragTopicCommand extends Command { private _topicsId: number; - private _parentId: number; + private _parentId: number | null; private _position: Point; @@ -73,14 +73,14 @@ class DragTopicCommand extends Command { } // Finally, connect topic ... - if ($defined(this._parentId)) { + if (this._parentId != null) { const parentTopic = commandContext.findTopics([this._parentId])[0]; commandContext.connect(topic, parentTopic); } // Backup old parent id ... this._parentId = null; - if ($defined(origParentTopic)) { + if (origParentTopic != null) { this._parentId = origParentTopic.getId(); } topic.setVisibility(true); diff --git a/packages/mindplot/src/components/commands/MoveControlPointCommand.ts b/packages/mindplot/src/components/commands/MoveControlPointCommand.ts index 4c657a76..ba0ab312 100644 --- a/packages/mindplot/src/components/commands/MoveControlPointCommand.ts +++ b/packages/mindplot/src/components/commands/MoveControlPointCommand.ts @@ -24,7 +24,7 @@ import CommandContext from '../CommandContext'; class MoveControlPointCommand extends Command { private _ctrIndex: PivotType; - private _controlPoint: PositionType; + private _controlPoint: PositionType | null; private _modelId: number; diff --git a/packages/mindplot/src/components/layout/ChildrenSorterStrategy.ts b/packages/mindplot/src/components/layout/ChildrenSorterStrategy.ts index e07fd91c..6b958fea 100644 --- a/packages/mindplot/src/components/layout/ChildrenSorterStrategy.ts +++ b/packages/mindplot/src/components/layout/ChildrenSorterStrategy.ts @@ -20,17 +20,22 @@ import Node from './Node'; import PositionType from '../PositionType'; abstract class ChildrenSorterStrategy { - abstract computeChildrenIdByHeights(treeSet: RootedTreeSet, node: Node); + abstract computeChildrenIdByHeights(treeSet: RootedTreeSet, node: Node): void; - abstract computeOffsets(treeSet: RootedTreeSet, node: Node); + abstract computeOffsets(treeSet: RootedTreeSet, node: Node): void; abstract insert(treeSet: RootedTreeSet, parent: Node, child: Node, order: number): void; abstract detach(treeSet: RootedTreeSet, node: Node): void; - abstract predict(treeSet: RootedTreeSet, parent, node: Node | null, position: PositionType); + abstract predict( + treeSet: RootedTreeSet, + parent, + node: Node | null, + position: PositionType | null, + ): void; - abstract verify(treeSet: RootedTreeSet, node: Node); + abstract verify(treeSet: RootedTreeSet, node: Node): void; abstract getChildDirection(treeSet: RootedTreeSet, node: Node): 1 | -1; diff --git a/packages/mindplot/src/components/persistence/XMLSerializerTango.ts b/packages/mindplot/src/components/persistence/XMLSerializerTango.ts index 49aae2ef..c3037ba1 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializerTango.ts +++ b/packages/mindplot/src/components/persistence/XMLSerializerTango.ts @@ -475,7 +475,10 @@ class XMLSerializerTango implements XMLMindmapSerializer { return value !== null ? value : ''; } - static _deserializeRelationship(domElement: Element, mindmap: Mindmap): RelationshipModel | null { + private static _deserializeRelationship( + domElement: Element, + mindmap: Mindmap, + ): RelationshipModel { const srcId = Number.parseInt(domElement.getAttribute('srcTopicId')!, 10); const destId = Number.parseInt(domElement.getAttribute('destTopicId')!, 10); const lineType = Number.parseInt(domElement.getAttribute('lineType')!, 10);