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;
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;
}

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();
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) {

View File

@ -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);
}
});

View File

@ -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;

View File

@ -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);
}

View File

@ -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();
}

View File

@ -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();

View File

@ -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(
'<div id="mindplot-svg-tooltip" class="mindplot-svg-tooltip">' +
'<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);
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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);