mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-10 17:33:24 +01:00
Continue refactor.
This commit is contained in:
parent
bd25cec139
commit
61c7900f05
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 ...
|
||||
|
@ -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 ...
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ class TopicFactory {
|
||||
} else {
|
||||
$assert(false, `unsupported node type:${type}`);
|
||||
}
|
||||
return result;
|
||||
return result!;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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!);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
// 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 ...
|
||||
|
@ -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;
|
||||
|
@ -41,10 +41,14 @@ class MDExporter extends Exporter {
|
||||
|
||||
// Add cental node as text ...
|
||||
const centralTopic = this.mindmap.getCentralTopic();
|
||||
const centralText = this.normalizeText(centralTopic.getText());
|
||||
|
||||
const centralTopicText = centralTopic.getText();
|
||||
let result = '';
|
||||
if (centralTopicText) {
|
||||
const centralText = this.normalizeText(centralTopicText);
|
||||
|
||||
// Traverse all the branches ...
|
||||
let result = `# ${centralText}\n\n`;
|
||||
result = `# ${centralText}\n\n`;
|
||||
result += this.traverseBranch('', centralTopic.getChildren());
|
||||
|
||||
// White footnotes:
|
||||
@ -55,7 +59,7 @@ class MDExporter extends Exporter {
|
||||
});
|
||||
}
|
||||
result += '\n';
|
||||
|
||||
}
|
||||
return Promise.resolve(result);
|
||||
}
|
||||
|
||||
|
@ -68,25 +68,28 @@ 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');
|
||||
|
||||
const transformStr = g?.getAttribute('transform');
|
||||
let result: SizeType = { width: 0, height: 0 };
|
||||
if (transformStr) {
|
||||
// Looking to parse translate(220.00000,279.00000) scale(1.00000,1.00000)
|
||||
const match = transformStr.match(SVGExporter.regexpTranslate);
|
||||
let result: SizeType = { width: 0, height: 0 };
|
||||
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'));
|
||||
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'));
|
||||
const heightAttr = rect.getAttribute('height');
|
||||
if (result.height > 0 && heightAttr) {
|
||||
const rectHeight = Number.parseFloat(heightAttr);
|
||||
result.height += rectHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
});
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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!;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user