From 61c7900f05733de7ab8f1e27d0f4c3f96a4c4d96 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Thu, 24 Nov 2022 16:51:30 -0800 Subject: [PATCH] Continue refactor. --- packages/mindplot/src/components/Command.ts | 4 +- .../mindplot/src/components/ControlPoint.ts | 55 +++++++++---------- packages/mindplot/src/components/Designer.ts | 21 +++---- .../src/components/DesignerUndoManager.ts | 4 +- .../src/components/MultilineTextEditor.ts | 2 +- .../mindplot/src/components/ScreenManager.ts | 13 ++--- .../components/StandaloneActionDispatcher.ts | 12 ++-- .../mindplot/src/components/TopicFactory.ts | 2 +- .../mindplot/src/components/WidgetManager.ts | 9 ++- packages/mindplot/src/components/Workspace.ts | 4 +- .../commands/AddFeatureToTopicCommand.ts | 4 +- .../components/commands/AddTopicCommand.ts | 6 +- .../src/components/commands/DeleteCommand.ts | 11 ++-- .../commands/GenericFunctionCommand.ts | 11 ++-- .../src/components/export/MDExporter.ts | 28 ++++++---- .../src/components/export/SVGExporter.ts | 31 ++++++----- .../src/components/export/freemind/Font.ts | 6 +- .../src/components/layout/RootedTreeSet.ts | 8 +-- .../mindplot/src/components/model/IMindmap.ts | 2 +- .../src/components/model/INodeModel.ts | 3 +- .../persistence/XMLSerializerFactory.ts | 4 +- 21 files changed, 124 insertions(+), 116 deletions(-) diff --git a/packages/mindplot/src/components/Command.ts b/packages/mindplot/src/components/Command.ts index 46bf5a05..a1cb6feb 100644 --- a/packages/mindplot/src/components/Command.ts +++ b/packages/mindplot/src/components/Command.ts @@ -46,11 +46,11 @@ abstract class Command { return this._uuid; } - get discardDuplicated(): string { + getDiscardDuplicated(): string { return this._discardDuplicated; } - set discardDuplicated(value: string) { + setDiscardDuplicated(value: string) { this._discardDuplicated = value; } } diff --git a/packages/mindplot/src/components/ControlPoint.ts b/packages/mindplot/src/components/ControlPoint.ts index b9aab58b..c33b6565 100644 --- a/packages/mindplot/src/components/ControlPoint.ts +++ b/packages/mindplot/src/components/ControlPoint.ts @@ -21,6 +21,7 @@ import { $defined } from '@wisemapping/core-js'; import Shape from './util/Shape'; import ActionDispatcher from './ActionDispatcher'; import Workspace from './Workspace'; +import PositionType from './PositionType'; class ControlPoint { private control1: Elipse; @@ -37,15 +38,15 @@ class ControlPoint { private _workspace: Workspace; - private _endPoint: any[]; + private _endPoint: PositionType[]; - private _orignalCtrlPoint: any; + private _orignalCtrlPoint: PositionType[]; - private _controls: any; + private _controls: PositionType[]; - private _mouseMoveFunction: (e: Event) => void; + private _mouseMoveFunction: (e: MouseEvent) => void; - private _mouseUpFunction: (e: Event) => void; + private _mouseUpFunction: (e: MouseEvent) => void; constructor() { this.control1 = new Elipse({ @@ -73,25 +74,24 @@ class ControlPoint { ]; this._isBinded = false; - const me = this; - this._controlPointsController[0].addEvent('mousedown', (event) => { - me._mouseDown(event, ControlPoint.FROM, me); + this._controlPointsController[0].addEvent('mousedown', (event: MouseEvent) => { + this._mouseDown(event, ControlPoint.FROM); }); - this._controlPointsController[0].addEvent('click', (event) => { - me._mouseClick(event); + this._controlPointsController[0].addEvent('click', (event: MouseEvent) => { + this._mouseClick(event); }); - this._controlPointsController[0].addEvent('dblclick', (event) => { - me._mouseClick(event); + this._controlPointsController[0].addEvent('dblclick', (event: MouseEvent) => { + this._mouseClick(event); }); - this._controlPointsController[1].addEvent('mousedown', (event) => { - me._mouseDown(event, ControlPoint.TO, me); + this._controlPointsController[1].addEvent('mousedown', (event: MouseEvent) => { + this._mouseDown(event, ControlPoint.TO); }); - this._controlPointsController[1].addEvent('click', (event) => { - me._mouseClick(event); + this._controlPointsController[1].addEvent('click', (event: MouseEvent) => { + this._mouseClick(event); }); - this._controlPointsController[1].addEvent('dblclick', (event) => { - me._mouseClick(event); + this._controlPointsController[1].addEvent('dblclick', (event: MouseEvent) => { + this._mouseClick(event); }); } @@ -103,8 +103,7 @@ class ControlPoint { this._createControlPoint(); this._endPoint = []; this._orignalCtrlPoint = []; - this._orignalCtrlPoint[0] = { ...this._controls[0] }; - this._orignalCtrlPoint[1] = { ...this._controls[1] }; + [this._orignalCtrlPoint[0], this._orignalCtrlPoint[1]] = this._controls; this._endPoint[0] = { ...this._line.getLine().getFrom() }; this._endPoint[1] = { ...this._line.getLine().getTo() }; } @@ -146,16 +145,16 @@ class ControlPoint { // Overwrite default behaviour ... } - private _mouseDown(event: Event, point, me) { + private _mouseDown(event: MouseEvent, point: number) { if (!this._isBinded) { this._isBinded = true; this._mouseMoveFunction = (e) => { - me._mouseMoveEvent(e, point, me); + this._mouseMoveEvent(e, point); }; this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction); - this._mouseUpFunction = (e: Event) => { - me._mouseUp(e, point, me); + this._mouseUpFunction = (e: MouseEvent) => { + this._mouseUp(e, MouseEvent); }; this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction); } @@ -224,22 +223,22 @@ class ControlPoint { } removeFromWorkspace(workspace: Workspace) { - this._workspace = null; + this._workspace!; workspace.removeChild(this._controlPointsController[0]); workspace.removeChild(this._controlPointsController[1]); workspace.removeChild(this._controlLines[0]); workspace.removeChild(this._controlLines[1]); } - getControlPoint(index: number): ControlPoint { + getControlPoint(index: number): PositionType { return this._controls[index]; } - getOriginalEndPoint(index: number) { + getOriginalEndPoint(index: number): PositionType { return this._endPoint[index]; } - getOriginalCtrlPoint(index: number): ControlPoint { + getOriginalCtrlPoint(index: number): PositionType { return this._orignalCtrlPoint[index]; } diff --git a/packages/mindplot/src/components/Designer.ts b/packages/mindplot/src/components/Designer.ts index 3bfa32c7..e4ac853f 100644 --- a/packages/mindplot/src/components/Designer.ts +++ b/packages/mindplot/src/components/Designer.ts @@ -408,7 +408,7 @@ class Designer extends Events { $notify($msg('CLIPBOARD_IS_EMPTY')); return; } - this._actionDispatcher.addTopics(this._clipboard); + this._actionDispatcher.addTopics(this._clipboard, null); this._clipboard = []; } @@ -589,10 +589,9 @@ class Designer extends Events { // Init layout manager ... const size = { width: 25, height: 25 }; const layoutManager = new LayoutManager(mindmap.getCentralTopic().getId(), size); - const me = this; layoutManager.addEvent('change', (event) => { const id = event.getId(); - const topic = me.getModel().findTopicById(id); + const topic = this.getModel().findTopicById(id); if (topic) { topic.setPosition(event.getPosition()); topic.setOrder(event.getOrder()); @@ -728,23 +727,21 @@ class Designer extends Events { // Build relationship line .... const result = new Relationship(sourceTopic!, targetTopic!, model); - const me = this; - result.addEvent('ontblur', () => { - const topics = me.getModel().filterSelectedTopics(); - const rels = me.getModel().filterSelectedRelationships(); + const topics = this.getModel().filterSelectedTopics(); + const rels = this.getModel().filterSelectedRelationships(); if (topics.length === 0 || rels.length === 0) { - me.fireEvent('onblur'); + this.fireEvent('onblur'); } }); result.addEvent('ontfocus', () => { - const topics = me.getModel().filterSelectedTopics(); - const rels = me.getModel().filterSelectedRelationships(); + const topics = this.getModel().filterSelectedTopics(); + const rels = this.getModel().filterSelectedRelationships(); if (topics.length === 1 || rels.length === 1) { - me.fireEvent('onfocus'); + this.fireEvent('onfocus'); } }); @@ -771,7 +768,7 @@ class Designer extends Events { const model = node.getModel(); model.deleteNode(); - if ($defined(parent)) { + if (parent) { this.goToNode(parent); } } diff --git a/packages/mindplot/src/components/DesignerUndoManager.ts b/packages/mindplot/src/components/DesignerUndoManager.ts index 7972b15a..f81934be 100644 --- a/packages/mindplot/src/components/DesignerUndoManager.ts +++ b/packages/mindplot/src/components/DesignerUndoManager.ts @@ -35,10 +35,10 @@ class DesignerUndoManager { enqueue(command: Command) { $assert(command, 'Command can not be null'); const { length } = this._undoQueue; - if (command.discardDuplicated && length > 0) { + if (command.getDiscardDuplicated() && length > 0) { // Skip duplicated events ... const lastItem = this._undoQueue[length - 1]; - if (lastItem.discardDuplicated !== command.discardDuplicated) { + if (lastItem.getDiscardDuplicated() !== command.getDiscardDuplicated()) { this._undoQueue.push(command); } } else { diff --git a/packages/mindplot/src/components/MultilineTextEditor.ts b/packages/mindplot/src/components/MultilineTextEditor.ts index 5cd554f4..c0358395 100644 --- a/packages/mindplot/src/components/MultilineTextEditor.ts +++ b/packages/mindplot/src/components/MultilineTextEditor.ts @@ -173,7 +173,7 @@ class EditorComponent extends Events { this._containerElem.offset({ top, left }); // Set editor's initial text ... - const text = topic.getText() || defaultText; + const text = defaultText || topic.getText(); this._setText(text); // Set the element focus and select the current text ... diff --git a/packages/mindplot/src/components/ScreenManager.ts b/packages/mindplot/src/components/ScreenManager.ts index 0b5b5323..390de950 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 } from '@wisemapping/core-js'; +import { $assert, $defined } 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 @@ -100,8 +100,8 @@ class ScreenManager { private tocuchEvents = ['touchstart', 'touchend', 'touchmove']; getWorkspaceMousePosition(event: MouseEvent | TouchEvent): Point { - let x: number; - let y: number; + let x: number | null = null; + let y: number | null = null; if (this.mouseEvents.includes(event.type)) { // Retrieve current mouse position. @@ -113,11 +113,8 @@ class ScreenManager { } // if value is zero assert throws error - if (x !== 0) { - $assert(x, `clientX can not be null, eventType= ${event.type}`); - } - if (y !== 0) { - $assert(y, `clientY can not be null, eventType= ${event.type}`); + if (x === null || y === null) { + throw new Error(`Coordinated can not be null, eventType= ${event.type}`); } // Adjust the deviation of the container positioning ... diff --git a/packages/mindplot/src/components/StandaloneActionDispatcher.ts b/packages/mindplot/src/components/StandaloneActionDispatcher.ts index f38c9b77..95e57f08 100644 --- a/packages/mindplot/src/components/StandaloneActionDispatcher.ts +++ b/packages/mindplot/src/components/StandaloneActionDispatcher.ts @@ -52,7 +52,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { this._actionRunner = new DesignerActionRunner(commandContext, this); } - addTopics(models: NodeModel[], parentTopicsId: number[] = undefined) { + addTopics(models: NodeModel[], parentTopicsId: number[] | null) { const command = new AddTopicCommand(models, parentTopicsId); this.execute(command); } @@ -106,7 +106,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { topic.setFontStyle(style, true); return result; }; - const command = new GenericFunctionCommand(commandFunc, topicsIds); + const command = new GenericFunctionCommand(commandFunc, topicsIds, null); this.execute(command); } @@ -153,7 +153,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { }; const command = new GenericFunctionCommand(commandFunc, topicsIds, color); - command.discardDuplicated = 'fontColorCommandId'; + command.setDiscardDuplicated('fontColorCommandId'); this.execute(command); } @@ -169,7 +169,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { }; const command = new GenericFunctionCommand(commandFunc, topicsIds, color); - command.discardDuplicated = 'backColor'; + command.setDiscardDuplicated('backColor'); this.execute(command); } @@ -185,7 +185,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { }; const command = new GenericFunctionCommand(commandFunc, topicsIds, color); - command.discardDuplicated = 'borderColorCommandId'; + command.setDiscardDuplicated('borderColorCommandId'); this.execute(command); } @@ -234,7 +234,7 @@ class StandaloneActionDispatcher extends ActionDispatcher { return result; }; - const command = new GenericFunctionCommand(commandFunc, topicsIds); + const command = new GenericFunctionCommand(commandFunc, topicsIds, null); this.execute(command); } diff --git a/packages/mindplot/src/components/TopicFactory.ts b/packages/mindplot/src/components/TopicFactory.ts index 03a7199c..fb00ac89 100644 --- a/packages/mindplot/src/components/TopicFactory.ts +++ b/packages/mindplot/src/components/TopicFactory.ts @@ -20,7 +20,7 @@ class TopicFactory { } else { $assert(false, `unsupported node type:${type}`); } - return result; + return result!; } } diff --git a/packages/mindplot/src/components/WidgetManager.ts b/packages/mindplot/src/components/WidgetManager.ts index a713f3e9..821b9382 100644 --- a/packages/mindplot/src/components/WidgetManager.ts +++ b/packages/mindplot/src/components/WidgetManager.ts @@ -70,7 +70,8 @@ abstract class WidgetManager { tooltip.css({ display: 'block' }); evt.stopPropagation(); }); - mindmapElement.addEvent('mouseleave', (evt) => { + + mindmapElement.addEvent('mouseleave', (evt: MouseEvent) => { tooltip.css({ display: 'none' }); evt.stopPropagation(); }); @@ -100,7 +101,11 @@ abstract class WidgetManager { }); } - abstract showEditorForLink(topic: Topic, linkModel: LinkModel, linkIcon: LinkIcon): void; + abstract showEditorForLink( + topic: Topic, + linkModel: LinkModel | null, + linkIcon: LinkIcon | null, + ): void; abstract showEditorForNote( topic: Topic, diff --git a/packages/mindplot/src/components/Workspace.ts b/packages/mindplot/src/components/Workspace.ts index b4b7c29c..2bb48914 100644 --- a/packages/mindplot/src/components/Workspace.ts +++ b/packages/mindplot/src/components/Workspace.ts @@ -182,8 +182,8 @@ class Workspace { const workspace = this._workspace; const divContainer = this._screenManager.getContainer(); - const containerWidth = divContainer.width(); - const containerHeight = divContainer.height(); + const containerWidth = divContainer.width()!; + const containerHeight = divContainer.height()!; const newVisibleAreaSize = { width: containerWidth, height: containerHeight }; // - svg must fit container size diff --git a/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.ts b/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.ts index 8aea8d7b..245351d1 100644 --- a/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.ts +++ b/packages/mindplot/src/components/commands/AddFeatureToTopicCommand.ts @@ -28,7 +28,7 @@ class AddFeatureToTopicCommand extends Command { private _attributes: object; - private _featureModel: FeatureModel; + private _featureModel: FeatureModel | null; /* * @classdesc This command class handles do/undo of adding features to topics, e.g. an @@ -65,7 +65,7 @@ class AddFeatureToTopicCommand extends Command { undoExecute(commandContext: CommandContext) { const topic = commandContext.findTopics([this._topicId])[0]; - topic.removeFeature(this._featureModel); + topic.removeFeature(this._featureModel!); } } diff --git a/packages/mindplot/src/components/commands/AddTopicCommand.ts b/packages/mindplot/src/components/commands/AddTopicCommand.ts index 0e405a09..e94386cf 100644 --- a/packages/mindplot/src/components/commands/AddTopicCommand.ts +++ b/packages/mindplot/src/components/commands/AddTopicCommand.ts @@ -29,7 +29,7 @@ class AddTopicCommand extends Command { * @classdesc This command class handles do/undo of adding one or multiple topics to * the mindmap. */ - constructor(models: NodeModel[], parentTopicsId: number[]) { + constructor(models: NodeModel[], parentTopicsId: number[] | null) { $assert(models, 'models can not be null'); $assert( parentTopicsId == null || parentTopicsId.length === models.length, @@ -48,7 +48,7 @@ class AddTopicCommand extends Command { const topic = commandContext.createTopic(model); // Connect to topic ... - if (me._parentsIds) { + if (this._parentsIds) { const parentId = me._parentsIds[index]; if ($defined(parentId)) { const parentTopic = commandContext.findTopics([parentId])[0]; @@ -70,7 +70,7 @@ class AddTopicCommand extends Command { undoExecute(commandContext: CommandContext) { // Delete disconnected the nodes. Create a copy of the topics ... - const clonedModel = []; + const clonedModel: NodeModel[] = []; this._models.forEach((model) => { clonedModel.push(model.clone()); }); diff --git a/packages/mindplot/src/components/commands/DeleteCommand.ts b/packages/mindplot/src/components/commands/DeleteCommand.ts index 775107f7..b3fa6d9d 100644 --- a/packages/mindplot/src/components/commands/DeleteCommand.ts +++ b/packages/mindplot/src/components/commands/DeleteCommand.ts @@ -73,11 +73,12 @@ class DeleteCommand extends Command { const clonedModel = model.clone(); this._deletedTopicModels.push(clonedModel); const outTopic = topic.getOutgoingConnectedTopic(); - let outTopicId = null; + + let outTopicId: number | null = null; if (outTopic != null) { outTopicId = outTopic.getId(); + this._parentTopicIds.push(outTopicId); } - this._parentTopicIds.push(outTopicId); // Finally, delete the topic from the workspace... commandContext.deleteTopic(topic); @@ -161,14 +162,14 @@ class DeleteCommand extends Command { } private _collectInDepthRelationships(topic: Topic): Relationship[] { - let result = []; - result = result.concat(topic.getRelationships()); + let result: Relationship[] = []; + result.push(...topic.getRelationships()); const children = topic.getChildren(); const rels: Relationship[][] = children.map((t: Topic) => this._collectInDepthRelationships(t)); // flatten and concact - result = result.concat([].concat(...rels)); + result.push(...rels.flat()); if (result.length > 0) { // Filter for unique ... diff --git a/packages/mindplot/src/components/commands/GenericFunctionCommand.ts b/packages/mindplot/src/components/commands/GenericFunctionCommand.ts index 17751212..1c0c5592 100644 --- a/packages/mindplot/src/components/commands/GenericFunctionCommand.ts +++ b/packages/mindplot/src/components/commands/GenericFunctionCommand.ts @@ -20,7 +20,7 @@ import Command from '../Command'; import CommandContext from '../CommandContext'; import Topic from '../Topic'; -type CommandTypes = string | object | boolean | number; +type CommandTypes = string | object | boolean | number | null; class GenericFunctionCommand extends Command { private _value: CommandTypes; @@ -36,7 +36,7 @@ class GenericFunctionCommand extends Command { constructor( commandFunc: (topic: Topic, value: CommandTypes) => CommandTypes, topicsIds: number[], - value: CommandTypes = undefined, + value: CommandTypes, ) { $assert(commandFunc, 'commandFunc must be defined'); $assert($defined(topicsIds), 'topicsIds must be defined'); @@ -51,15 +51,14 @@ class GenericFunctionCommand extends Command { /** * Overrides abstract parent method */ - execute(commandContext: CommandContext) { + execute(commandContext: CommandContext): void { if (!this._applied) { const topics = commandContext.findTopics(this._topicsIds); if (topics != null) { - const me = this; topics.forEach((topic: Topic) => { - const oldValue = me._commandFunc(topic, me._value); - me._oldValues.push(oldValue); + const oldValue = this._commandFunc(topic, this._value); + this._oldValues.push(oldValue); }); } this._applied = true; diff --git a/packages/mindplot/src/components/export/MDExporter.ts b/packages/mindplot/src/components/export/MDExporter.ts index bcaa4f25..af00b552 100644 --- a/packages/mindplot/src/components/export/MDExporter.ts +++ b/packages/mindplot/src/components/export/MDExporter.ts @@ -41,21 +41,25 @@ class MDExporter extends Exporter { // Add cental node as text ... const centralTopic = this.mindmap.getCentralTopic(); - const centralText = this.normalizeText(centralTopic.getText()); - // Traverse all the branches ... - let result = `# ${centralText}\n\n`; - result += this.traverseBranch('', centralTopic.getChildren()); + const centralTopicText = centralTopic.getText(); + let result = ''; + if (centralTopicText) { + const centralText = this.normalizeText(centralTopicText); - // White footnotes: - if (this.footNotes.length > 0) { - result += '\n\n\n'; - this.footNotes.forEach((note, index) => { - result += `[^${index + 1}]: ${this.normalizeText(note)}`; - }); + // Traverse all the branches ... + result = `# ${centralText}\n\n`; + result += this.traverseBranch('', centralTopic.getChildren()); + + // White footnotes: + if (this.footNotes.length > 0) { + result += '\n\n\n'; + this.footNotes.forEach((note, index) => { + result += `[^${index + 1}]: ${this.normalizeText(note)}`; + }); + } + result += '\n'; } - result += '\n'; - return Promise.resolve(result); } diff --git a/packages/mindplot/src/components/export/SVGExporter.ts b/packages/mindplot/src/components/export/SVGExporter.ts index f72de06c..f53eb9d4 100644 --- a/packages/mindplot/src/components/export/SVGExporter.ts +++ b/packages/mindplot/src/components/export/SVGExporter.ts @@ -68,23 +68,26 @@ class SVGExporter extends Exporter { const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect')); const translates: SizeType[] = rectElems.map((rect: Element) => { const g = rect.parentElement; - const transformStr = g.getAttribute('transform'); - - // Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000) - const match = transformStr.match(SVGExporter.regexpTranslate); + const transformStr = g?.getAttribute('transform'); let result: SizeType = { width: 0, height: 0 }; - if (match !== null) { - result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) }; + if (transformStr) { + // Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000) + const match = transformStr.match(SVGExporter.regexpTranslate); + if (match !== null) { + result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) }; - // Add rect size ... - if (result.width > 0) { - const rectWidth = Number.parseFloat(rect.getAttribute('width')); - result.width += rectWidth; - } + // Add rect size ... + const widthAttr = rect.getAttribute('width'); + if (result.width > 0 && widthAttr) { + const rectWidth = Number.parseFloat(widthAttr); + result.width += rectWidth; + } - if (result.height > 0) { - const rectHeight = Number.parseFloat(rect.getAttribute('height')); - result.height += rectHeight; + const heightAttr = rect.getAttribute('height'); + if (result.height > 0 && heightAttr) { + const rectHeight = Number.parseFloat(heightAttr); + result.height += rectHeight; + } } } return result; diff --git a/packages/mindplot/src/components/export/freemind/Font.ts b/packages/mindplot/src/components/export/freemind/Font.ts index 3ba3defc..bcab647e 100644 --- a/packages/mindplot/src/components/export/freemind/Font.ts +++ b/packages/mindplot/src/components/export/freemind/Font.ts @@ -7,15 +7,15 @@ export default class Font { protected SIZE: string; - getBold(): string { + getBold(): string | undefined { return this.BOLD; } - getItalic(): string { + getItalic(): string | undefined { return this.ITALIC; } - getName(): string { + getName(): string | undefined { return this.NAME; } diff --git a/packages/mindplot/src/components/layout/RootedTreeSet.ts b/packages/mindplot/src/components/layout/RootedTreeSet.ts index efc7c3fb..1919e203 100644 --- a/packages/mindplot/src/components/layout/RootedTreeSet.ts +++ b/packages/mindplot/src/components/layout/RootedTreeSet.ts @@ -110,7 +110,7 @@ class RootedTreeSet { $assert($defined(id), 'id can not be null'); const graphs = this._rootNodes; - let result = null; + let result: Node | null = null; for (let i = 0; i < graphs.length; i++) { const node = graphs[i]; result = this._find(id, node); @@ -123,7 +123,7 @@ class RootedTreeSet { throw new Error(`node could not be found id:${id}\n,RootedTreeSet${this.dump()}`); } - return result; + return result!; } private _find(id: number, parent: Node): Node { @@ -131,7 +131,7 @@ class RootedTreeSet { return parent; } - let result = null; + let result: Node | null = null; const children = parent._children; for (let i = 0; i < children.length; i++) { const child = children[i]; @@ -139,7 +139,7 @@ class RootedTreeSet { if (result) break; } - return result; + return result!; } /** diff --git a/packages/mindplot/src/components/model/IMindmap.ts b/packages/mindplot/src/components/model/IMindmap.ts index 95a15e59..c36569ea 100644 --- a/packages/mindplot/src/components/model/IMindmap.ts +++ b/packages/mindplot/src/components/model/IMindmap.ts @@ -67,7 +67,7 @@ abstract class IMindmap { $assert(child, 'Child can not be null.'); $assert(parent, 'Child model seems to be already connected'); - parent.removeChild(child); + parent?.removeChild(child); this.addBranch(child); } diff --git a/packages/mindplot/src/components/model/INodeModel.ts b/packages/mindplot/src/components/model/INodeModel.ts index 44c7b405..d84b349f 100644 --- a/packages/mindplot/src/components/model/INodeModel.ts +++ b/packages/mindplot/src/components/model/INodeModel.ts @@ -46,7 +46,8 @@ abstract class INodeModel { abstract getFeatures(): FeatureModel[]; setId(id?: number): void { - if (!$defined(id)) { + if (id === null || id === undefined) { + // Assign a new one ... const newId = INodeModel._nextUUID(); this.putProperty('id', newId); } else { diff --git a/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts b/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts index a6c43b55..0735617d 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts +++ b/packages/mindplot/src/components/persistence/XMLSerializerFactory.ts @@ -89,7 +89,9 @@ class XMLSerializerFactory { result = new migrator(result); } } - $assert(result, `Cound not find serialized for ${version}`); + if (!result) { + throw new Error(`Cound not find serialized for ${version}`); + } return result; } }