Fix nullable support

This commit is contained in:
Paulo Gustavo Veiga 2022-12-09 22:39:53 -08:00
parent a230d343ab
commit 132fb97078
12 changed files with 48 additions and 37 deletions

View File

@ -23,7 +23,7 @@ abstract class Command {
static _uuid: number; static _uuid: number;
private _discardDuplicated: string; private _discardDuplicated: string | undefined;
constructor() { constructor() {
this._id = Command._nextUUID(); this._id = Command._nextUUID();
@ -46,7 +46,7 @@ abstract class Command {
return this._uuid; return this._uuid;
} }
getDiscardDuplicated(): string { getDiscardDuplicated(): string | undefined {
return this._discardDuplicated; return this._discardDuplicated;
} }

View File

@ -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(); const parent = node.getParent();
if (parent) { if (parent) {
const brothers = parent.getChildren(); const brothers = parent.getChildren();
@ -227,19 +227,19 @@ class DesignerKeyboard extends Keyboard {
let target = node; let target = node;
const { y } = node.getPosition(); const { y } = node.getPosition();
const { x } = node.getPosition(); const { x } = node.getPosition();
let dist = null; let dist: number | null = null;
for (let i = 0; i < brothers.length; i++) { for (let i = 0; i < brothers.length; i++) {
const sameSide = x * brothers[i].getPosition().x >= 0; const sameSide = x * brothers[i].getPosition().x >= 0;
if (brothers[i] !== node && sameSide) { if (brothers[i] !== node && sameSide) {
const brother = brothers[i]; const brother = brothers[i];
const brotherY = brother.getPosition().y; const brotherY = brother.getPosition().y;
if (direction === 'DOWN' && brotherY > y) { if (direction === 'DOWN' && brotherY > y) {
let distancia = y - brotherY; let distance = y - brotherY;
if (distancia < 0) { if (distance < 0) {
distancia *= -1; distance *= -1;
} }
if (dist == null || dist > distancia) { if (dist == null || dist > distance) {
dist = distancia; dist = distance;
target = brothers[i]; target = brothers[i];
} }
} else if (direction === 'UP' && brotherY < y) { } else if (direction === 'UP' && brotherY < y) {

View File

@ -107,7 +107,7 @@ class DesignerModel extends Events {
// Add node only if it's valid. // Add node only if it's valid.
if (isValid) { if (isValid) {
result.push(topic.getId()); result.push(topic.getId());
} else { } else if (errorMsg) {
$notify(errorMsg); $notify(errorMsg);
} }
}); });

View File

@ -100,8 +100,8 @@ class DragConnector {
const av = me._isVerticallyAligned(a.getSize(), aPos, sPos); const av = me._isVerticallyAligned(a.getSize(), aPos, sPos);
const bv = me._isVerticallyAligned(b.getSize(), bPos, sPos); const bv = me._isVerticallyAligned(b.getSize(), bPos, sPos);
return ( return (
me._proximityWeight(av, a, sPos, currentConnection) - me._proximityWeight(av, a, sPos, currentConnection!) -
me._proximityWeight(bv, b, sPos, currentConnection) me._proximityWeight(bv, b, sPos, currentConnection!)
); );
}); });
return topics; return topics;

View File

@ -29,7 +29,7 @@ class DragPivot {
private _isVisible: boolean; private _isVisible: boolean;
private _targetTopic: Topic; private _targetTopic: Topic | null;
private _connectRect: Rect; private _connectRect: Rect;
@ -57,7 +57,7 @@ class DragPivot {
return this._isVisible; return this._isVisible;
} }
getTargetTopic(): Topic { getTargetTopic(): Topic | null {
return this._targetTopic; return this._targetTopic;
} }
@ -91,7 +91,7 @@ class DragPivot {
// Calculate pivot connection point ... // Calculate pivot connection point ...
const size = this._size; const size = this._size;
const targetPosition = targetTopic.getPosition(); const targetPosition = targetTopic!.getPosition();
const line = this._getConnectionLine(); const line = this._getConnectionLine();
// Update Line position. // Update Line position.
@ -106,7 +106,7 @@ class DragPivot {
// Make line visible only when the position has been already changed. // Make line visible only when the position has been already changed.
// This solve several strange effects ;) // This solve several strange effects ;)
const targetPoint = targetTopic.workoutIncomingConnectionPoint(pivotPoint); const targetPoint = targetTopic!.workoutIncomingConnectionPoint(pivotPoint);
line.setTo(targetPoint.x, targetPoint.y); line.setTo(targetPoint.x, targetPoint.y);
} }

View File

@ -73,14 +73,14 @@ class DragTopic {
if (this.isConnected() && !this.isFreeLayoutOn()) { if (this.isConnected() && !this.isFreeLayoutOn()) {
const parent = this.getConnectedToTopic(); const parent = this.getConnectedToTopic();
const predict = this._layoutManager.predict( const predict = this._layoutManager.predict(
parent.getId(), parent!.getId(),
this._draggedNode.getId(), this._draggedNode.getId(),
this.getPosition(), this.getPosition(),
); );
if (this._order !== predict.order) { if (this._order !== predict.order) {
const dragPivot = this._getDragPivot(); const dragPivot = this._getDragPivot();
const pivotPosition = predict.position; const pivotPosition = predict.position;
dragPivot.connectTo(parent, pivotPosition); dragPivot.connectTo(parent!, pivotPosition);
this.setOrder(predict.order); this.setOrder(predict.order);
} }
} }
@ -191,7 +191,7 @@ class DragTopic {
} }
} }
getConnectedToTopic(): Topic { getConnectedToTopic(): Topic | null {
const dragPivot = this._getDragPivot(); const dragPivot = this._getDragPivot();
return dragPivot.getTargetTopic(); return dragPivot.getTargetTopic();
} }

View File

@ -97,7 +97,7 @@ class IconGroup {
icons.push(icon); icons.push(icon);
this._icons = icons.sort( this._icons = icons.sort(
(a, b) => (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 ... // Add all the nodes back ...
@ -115,7 +115,7 @@ class IconGroup {
} }
private _findIconFromModel(iconModel: FeatureModel) { private _findIconFromModel(iconModel: FeatureModel) {
let result = null; let result: ImageIcon | null = null;
this._icons.forEach((icon) => { this._icons.forEach((icon) => {
const elModel = icon.getModel(); const elModel = icon.getModel();

View File

@ -24,9 +24,11 @@ abstract class WidgetManager {
linkModel?: LinkModel, linkModel?: LinkModel,
noteModel?: NoteModel, noteModel?: NoteModel,
) { ) {
const webcomponentShadowRoot = $($('#mindmap-comp')[0].shadowRoot); const { shadowRoot } = $('#mindmap-comp')[0];
const webcomponentShadowRoot = $(shadowRoot!);
let tooltip = webcomponentShadowRoot.find('#mindplot-svg-tooltip'); let tooltip = webcomponentShadowRoot.find('#mindplot-svg-tooltip');
if (!tooltip.length) { if (!tooltip.length || !tooltip) {
webcomponentShadowRoot.append( webcomponentShadowRoot.append(
'<div id="mindplot-svg-tooltip" class="mindplot-svg-tooltip">' + '<div id="mindplot-svg-tooltip" class="mindplot-svg-tooltip">' +
'<div id="mindplot-svg-tooltip-title" class="mindplot-svg-tooltip-title"></div>' + '<div id="mindplot-svg-tooltip-title" class="mindplot-svg-tooltip-title"></div>' +
@ -48,7 +50,7 @@ abstract class WidgetManager {
}); });
} }
mindmapElement.addEvent('mouseenter', (evt) => { mindmapElement.addEvent('mouseenter', (evt: MouseEvent) => {
webcomponentShadowRoot.find('#mindplot-svg-tooltip-title').html(title); webcomponentShadowRoot.find('#mindplot-svg-tooltip-title').html(title);
if (linkModel) { if (linkModel) {
webcomponentShadowRoot webcomponentShadowRoot
@ -63,8 +65,9 @@ abstract class WidgetManager {
webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-note').css({ display: 'block' }); webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-note').css({ display: 'block' });
webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-link').css({ display: 'none' }); webcomponentShadowRoot.find('#mindplot-svg-tooltip-content-link').css({ display: 'none' });
} }
const targetRect = evt.target.getBoundingClientRect(); const targetRect = (evt.target as Element).getBoundingClientRect();
const newX = Math.max(0, targetRect.left + targetRect.width / 2 - tooltip.width() / 2); const width = tooltip.width() || 0;
const newX = Math.max(0, targetRect.left + targetRect.width / 2 - width / 2);
const newY = Math.max(0, targetRect.bottom); const newY = Math.max(0, targetRect.bottom);
tooltip.css({ top: newY, left: newX, position: 'absolute' }); tooltip.css({ top: newY, left: newX, position: 'absolute' });
tooltip.css({ display: 'block' }); 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); 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); this.createTooltip(noteIcon.getElement().peer, $msg('NOTE'), undefined, noteModel);
} }

View File

@ -24,7 +24,7 @@ import Topic from '../Topic';
class DragTopicCommand extends Command { class DragTopicCommand extends Command {
private _topicsId: number; private _topicsId: number;
private _parentId: number; private _parentId: number | null;
private _position: Point; private _position: Point;
@ -73,14 +73,14 @@ class DragTopicCommand extends Command {
} }
// Finally, connect topic ... // Finally, connect topic ...
if ($defined(this._parentId)) { if (this._parentId != null) {
const parentTopic = commandContext.findTopics([this._parentId])[0]; const parentTopic = commandContext.findTopics([this._parentId])[0];
commandContext.connect(topic, parentTopic); commandContext.connect(topic, parentTopic);
} }
// Backup old parent id ... // Backup old parent id ...
this._parentId = null; this._parentId = null;
if ($defined(origParentTopic)) { if (origParentTopic != null) {
this._parentId = origParentTopic.getId(); this._parentId = origParentTopic.getId();
} }
topic.setVisibility(true); topic.setVisibility(true);

View File

@ -24,7 +24,7 @@ import CommandContext from '../CommandContext';
class MoveControlPointCommand extends Command { class MoveControlPointCommand extends Command {
private _ctrIndex: PivotType; private _ctrIndex: PivotType;
private _controlPoint: PositionType; private _controlPoint: PositionType | null;
private _modelId: number; private _modelId: number;

View File

@ -20,17 +20,22 @@ import Node from './Node';
import PositionType from '../PositionType'; import PositionType from '../PositionType';
abstract class ChildrenSorterStrategy { 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 insert(treeSet: RootedTreeSet, parent: Node, child: Node, order: number): void;
abstract detach(treeSet: RootedTreeSet, node: Node): 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; abstract getChildDirection(treeSet: RootedTreeSet, node: Node): 1 | -1;

View File

@ -475,7 +475,10 @@ class XMLSerializerTango implements XMLMindmapSerializer {
return value !== null ? value : ''; 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 srcId = Number.parseInt(domElement.getAttribute('srcTopicId')!, 10);
const destId = Number.parseInt(domElement.getAttribute('destTopicId')!, 10); const destId = Number.parseInt(domElement.getAttribute('destTopicId')!, 10);
const lineType = Number.parseInt(domElement.getAttribute('lineType')!, 10); const lineType = Number.parseInt(domElement.getAttribute('lineType')!, 10);