mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-25 07:47:55 +01:00
Continue refactor.
This commit is contained in:
parent
bd25cec139
commit
61c7900f05
@ -46,11 +46,11 @@ abstract class Command {
|
|||||||
return this._uuid;
|
return this._uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
get discardDuplicated(): string {
|
getDiscardDuplicated(): string {
|
||||||
return this._discardDuplicated;
|
return this._discardDuplicated;
|
||||||
}
|
}
|
||||||
|
|
||||||
set discardDuplicated(value: string) {
|
setDiscardDuplicated(value: string) {
|
||||||
this._discardDuplicated = value;
|
this._discardDuplicated = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import { $defined } from '@wisemapping/core-js';
|
|||||||
import Shape from './util/Shape';
|
import Shape from './util/Shape';
|
||||||
import ActionDispatcher from './ActionDispatcher';
|
import ActionDispatcher from './ActionDispatcher';
|
||||||
import Workspace from './Workspace';
|
import Workspace from './Workspace';
|
||||||
|
import PositionType from './PositionType';
|
||||||
|
|
||||||
class ControlPoint {
|
class ControlPoint {
|
||||||
private control1: Elipse;
|
private control1: Elipse;
|
||||||
@ -37,15 +38,15 @@ class ControlPoint {
|
|||||||
|
|
||||||
private _workspace: Workspace;
|
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() {
|
constructor() {
|
||||||
this.control1 = new Elipse({
|
this.control1 = new Elipse({
|
||||||
@ -73,25 +74,24 @@ class ControlPoint {
|
|||||||
];
|
];
|
||||||
|
|
||||||
this._isBinded = false;
|
this._isBinded = false;
|
||||||
const me = this;
|
this._controlPointsController[0].addEvent('mousedown', (event: MouseEvent) => {
|
||||||
this._controlPointsController[0].addEvent('mousedown', (event) => {
|
this._mouseDown(event, ControlPoint.FROM);
|
||||||
me._mouseDown(event, ControlPoint.FROM, me);
|
|
||||||
});
|
});
|
||||||
this._controlPointsController[0].addEvent('click', (event) => {
|
this._controlPointsController[0].addEvent('click', (event: MouseEvent) => {
|
||||||
me._mouseClick(event);
|
this._mouseClick(event);
|
||||||
});
|
});
|
||||||
this._controlPointsController[0].addEvent('dblclick', (event) => {
|
this._controlPointsController[0].addEvent('dblclick', (event: MouseEvent) => {
|
||||||
me._mouseClick(event);
|
this._mouseClick(event);
|
||||||
});
|
});
|
||||||
|
|
||||||
this._controlPointsController[1].addEvent('mousedown', (event) => {
|
this._controlPointsController[1].addEvent('mousedown', (event: MouseEvent) => {
|
||||||
me._mouseDown(event, ControlPoint.TO, me);
|
this._mouseDown(event, ControlPoint.TO);
|
||||||
});
|
});
|
||||||
this._controlPointsController[1].addEvent('click', (event) => {
|
this._controlPointsController[1].addEvent('click', (event: MouseEvent) => {
|
||||||
me._mouseClick(event);
|
this._mouseClick(event);
|
||||||
});
|
});
|
||||||
this._controlPointsController[1].addEvent('dblclick', (event) => {
|
this._controlPointsController[1].addEvent('dblclick', (event: MouseEvent) => {
|
||||||
me._mouseClick(event);
|
this._mouseClick(event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +103,7 @@ class ControlPoint {
|
|||||||
this._createControlPoint();
|
this._createControlPoint();
|
||||||
this._endPoint = [];
|
this._endPoint = [];
|
||||||
this._orignalCtrlPoint = [];
|
this._orignalCtrlPoint = [];
|
||||||
this._orignalCtrlPoint[0] = { ...this._controls[0] };
|
[this._orignalCtrlPoint[0], this._orignalCtrlPoint[1]] = this._controls;
|
||||||
this._orignalCtrlPoint[1] = { ...this._controls[1] };
|
|
||||||
this._endPoint[0] = { ...this._line.getLine().getFrom() };
|
this._endPoint[0] = { ...this._line.getLine().getFrom() };
|
||||||
this._endPoint[1] = { ...this._line.getLine().getTo() };
|
this._endPoint[1] = { ...this._line.getLine().getTo() };
|
||||||
}
|
}
|
||||||
@ -146,16 +145,16 @@ class ControlPoint {
|
|||||||
// Overwrite default behaviour ...
|
// Overwrite default behaviour ...
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mouseDown(event: Event, point, me) {
|
private _mouseDown(event: MouseEvent, point: number) {
|
||||||
if (!this._isBinded) {
|
if (!this._isBinded) {
|
||||||
this._isBinded = true;
|
this._isBinded = true;
|
||||||
this._mouseMoveFunction = (e) => {
|
this._mouseMoveFunction = (e) => {
|
||||||
me._mouseMoveEvent(e, point, me);
|
this._mouseMoveEvent(e, point);
|
||||||
};
|
};
|
||||||
|
|
||||||
this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction);
|
this._workspace.getScreenManager().addEvent('mousemove', this._mouseMoveFunction);
|
||||||
this._mouseUpFunction = (e: Event) => {
|
this._mouseUpFunction = (e: MouseEvent) => {
|
||||||
me._mouseUp(e, point, me);
|
this._mouseUp(e, MouseEvent);
|
||||||
};
|
};
|
||||||
this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction);
|
this._workspace.getScreenManager().addEvent('mouseup', this._mouseUpFunction);
|
||||||
}
|
}
|
||||||
@ -224,22 +223,22 @@ class ControlPoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
removeFromWorkspace(workspace: Workspace) {
|
removeFromWorkspace(workspace: Workspace) {
|
||||||
this._workspace = null;
|
this._workspace!;
|
||||||
workspace.removeChild(this._controlPointsController[0]);
|
workspace.removeChild(this._controlPointsController[0]);
|
||||||
workspace.removeChild(this._controlPointsController[1]);
|
workspace.removeChild(this._controlPointsController[1]);
|
||||||
workspace.removeChild(this._controlLines[0]);
|
workspace.removeChild(this._controlLines[0]);
|
||||||
workspace.removeChild(this._controlLines[1]);
|
workspace.removeChild(this._controlLines[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
getControlPoint(index: number): ControlPoint {
|
getControlPoint(index: number): PositionType {
|
||||||
return this._controls[index];
|
return this._controls[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
getOriginalEndPoint(index: number) {
|
getOriginalEndPoint(index: number): PositionType {
|
||||||
return this._endPoint[index];
|
return this._endPoint[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
getOriginalCtrlPoint(index: number): ControlPoint {
|
getOriginalCtrlPoint(index: number): PositionType {
|
||||||
return this._orignalCtrlPoint[index];
|
return this._orignalCtrlPoint[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,7 +408,7 @@ class Designer extends Events {
|
|||||||
$notify($msg('CLIPBOARD_IS_EMPTY'));
|
$notify($msg('CLIPBOARD_IS_EMPTY'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._actionDispatcher.addTopics(this._clipboard);
|
this._actionDispatcher.addTopics(this._clipboard, null);
|
||||||
this._clipboard = [];
|
this._clipboard = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,10 +589,9 @@ class Designer extends Events {
|
|||||||
// Init layout manager ...
|
// Init layout manager ...
|
||||||
const size = { width: 25, height: 25 };
|
const size = { width: 25, height: 25 };
|
||||||
const layoutManager = new LayoutManager(mindmap.getCentralTopic().getId(), size);
|
const layoutManager = new LayoutManager(mindmap.getCentralTopic().getId(), size);
|
||||||
const me = this;
|
|
||||||
layoutManager.addEvent('change', (event) => {
|
layoutManager.addEvent('change', (event) => {
|
||||||
const id = event.getId();
|
const id = event.getId();
|
||||||
const topic = me.getModel().findTopicById(id);
|
const topic = this.getModel().findTopicById(id);
|
||||||
if (topic) {
|
if (topic) {
|
||||||
topic.setPosition(event.getPosition());
|
topic.setPosition(event.getPosition());
|
||||||
topic.setOrder(event.getOrder());
|
topic.setOrder(event.getOrder());
|
||||||
@ -728,23 +727,21 @@ class Designer extends Events {
|
|||||||
|
|
||||||
// Build relationship line ....
|
// Build relationship line ....
|
||||||
const result = new Relationship(sourceTopic!, targetTopic!, model);
|
const result = new Relationship(sourceTopic!, targetTopic!, model);
|
||||||
const me = this;
|
|
||||||
|
|
||||||
result.addEvent('ontblur', () => {
|
result.addEvent('ontblur', () => {
|
||||||
const topics = me.getModel().filterSelectedTopics();
|
const topics = this.getModel().filterSelectedTopics();
|
||||||
const rels = me.getModel().filterSelectedRelationships();
|
const rels = this.getModel().filterSelectedRelationships();
|
||||||
|
|
||||||
if (topics.length === 0 || rels.length === 0) {
|
if (topics.length === 0 || rels.length === 0) {
|
||||||
me.fireEvent('onblur');
|
this.fireEvent('onblur');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
result.addEvent('ontfocus', () => {
|
result.addEvent('ontfocus', () => {
|
||||||
const topics = me.getModel().filterSelectedTopics();
|
const topics = this.getModel().filterSelectedTopics();
|
||||||
const rels = me.getModel().filterSelectedRelationships();
|
const rels = this.getModel().filterSelectedRelationships();
|
||||||
|
|
||||||
if (topics.length === 1 || rels.length === 1) {
|
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();
|
const model = node.getModel();
|
||||||
model.deleteNode();
|
model.deleteNode();
|
||||||
|
|
||||||
if ($defined(parent)) {
|
if (parent) {
|
||||||
this.goToNode(parent);
|
this.goToNode(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,10 +35,10 @@ class DesignerUndoManager {
|
|||||||
enqueue(command: Command) {
|
enqueue(command: Command) {
|
||||||
$assert(command, 'Command can not be null');
|
$assert(command, 'Command can not be null');
|
||||||
const { length } = this._undoQueue;
|
const { length } = this._undoQueue;
|
||||||
if (command.discardDuplicated && length > 0) {
|
if (command.getDiscardDuplicated() && length > 0) {
|
||||||
// Skip duplicated events ...
|
// Skip duplicated events ...
|
||||||
const lastItem = this._undoQueue[length - 1];
|
const lastItem = this._undoQueue[length - 1];
|
||||||
if (lastItem.discardDuplicated !== command.discardDuplicated) {
|
if (lastItem.getDiscardDuplicated() !== command.getDiscardDuplicated()) {
|
||||||
this._undoQueue.push(command);
|
this._undoQueue.push(command);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -173,7 +173,7 @@ class EditorComponent extends Events {
|
|||||||
this._containerElem.offset({ top, left });
|
this._containerElem.offset({ top, left });
|
||||||
|
|
||||||
// Set editor's initial text ...
|
// Set editor's initial text ...
|
||||||
const text = topic.getText() || defaultText;
|
const text = defaultText || topic.getText();
|
||||||
this._setText(text);
|
this._setText(text);
|
||||||
|
|
||||||
// Set the element focus and select the current text ...
|
// Set the element focus and select the current text ...
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import { $assert } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import { Point } from '@wisemapping/web2d';
|
import { Point } from '@wisemapping/web2d';
|
||||||
// https://stackoverflow.com/questions/60357083/does-not-use-passive-listeners-to-improve-scrolling-performance-lighthouse-repo
|
// 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
|
// https://web.dev/uses-passive-event-listeners/?utm_source=lighthouse&utm_medium=lr
|
||||||
@ -100,8 +100,8 @@ class ScreenManager {
|
|||||||
private tocuchEvents = ['touchstart', 'touchend', 'touchmove'];
|
private tocuchEvents = ['touchstart', 'touchend', 'touchmove'];
|
||||||
|
|
||||||
getWorkspaceMousePosition(event: MouseEvent | TouchEvent): Point {
|
getWorkspaceMousePosition(event: MouseEvent | TouchEvent): Point {
|
||||||
let x: number;
|
let x: number | null = null;
|
||||||
let y: number;
|
let y: number | null = null;
|
||||||
|
|
||||||
if (this.mouseEvents.includes(event.type)) {
|
if (this.mouseEvents.includes(event.type)) {
|
||||||
// Retrieve current mouse position.
|
// Retrieve current mouse position.
|
||||||
@ -113,11 +113,8 @@ class ScreenManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if value is zero assert throws error
|
// if value is zero assert throws error
|
||||||
if (x !== 0) {
|
if (x === null || y === null) {
|
||||||
$assert(x, `clientX can not be null, eventType= ${event.type}`);
|
throw new Error(`Coordinated can not be null, eventType= ${event.type}`);
|
||||||
}
|
|
||||||
if (y !== 0) {
|
|
||||||
$assert(y, `clientY can not be null, eventType= ${event.type}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adjust the deviation of the container positioning ...
|
// Adjust the deviation of the container positioning ...
|
||||||
|
@ -52,7 +52,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
this._actionRunner = new DesignerActionRunner(commandContext, this);
|
this._actionRunner = new DesignerActionRunner(commandContext, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
addTopics(models: NodeModel[], parentTopicsId: number[] = undefined) {
|
addTopics(models: NodeModel[], parentTopicsId: number[] | null) {
|
||||||
const command = new AddTopicCommand(models, parentTopicsId);
|
const command = new AddTopicCommand(models, parentTopicsId);
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
topic.setFontStyle(style, true);
|
topic.setFontStyle(style, true);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
const command = new GenericFunctionCommand(commandFunc, topicsIds);
|
const command = new GenericFunctionCommand(commandFunc, topicsIds, null);
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
||||||
command.discardDuplicated = 'fontColorCommandId';
|
command.setDiscardDuplicated('fontColorCommandId');
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +169,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
||||||
command.discardDuplicated = 'backColor';
|
command.setDiscardDuplicated('backColor');
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
const command = new GenericFunctionCommand(commandFunc, topicsIds, color);
|
||||||
command.discardDuplicated = 'borderColorCommandId';
|
command.setDiscardDuplicated('borderColorCommandId');
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const command = new GenericFunctionCommand(commandFunc, topicsIds);
|
const command = new GenericFunctionCommand(commandFunc, topicsIds, null);
|
||||||
this.execute(command);
|
this.execute(command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class TopicFactory {
|
|||||||
} else {
|
} else {
|
||||||
$assert(false, `unsupported node type:${type}`);
|
$assert(false, `unsupported node type:${type}`);
|
||||||
}
|
}
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +70,8 @@ abstract class WidgetManager {
|
|||||||
tooltip.css({ display: 'block' });
|
tooltip.css({ display: 'block' });
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
});
|
});
|
||||||
mindmapElement.addEvent('mouseleave', (evt) => {
|
|
||||||
|
mindmapElement.addEvent('mouseleave', (evt: MouseEvent) => {
|
||||||
tooltip.css({ display: 'none' });
|
tooltip.css({ display: 'none' });
|
||||||
evt.stopPropagation();
|
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(
|
abstract showEditorForNote(
|
||||||
topic: Topic,
|
topic: Topic,
|
||||||
|
@ -182,8 +182,8 @@ class Workspace {
|
|||||||
const workspace = this._workspace;
|
const workspace = this._workspace;
|
||||||
|
|
||||||
const divContainer = this._screenManager.getContainer();
|
const divContainer = this._screenManager.getContainer();
|
||||||
const containerWidth = divContainer.width();
|
const containerWidth = divContainer.width()!;
|
||||||
const containerHeight = divContainer.height();
|
const containerHeight = divContainer.height()!;
|
||||||
const newVisibleAreaSize = { width: containerWidth, height: containerHeight };
|
const newVisibleAreaSize = { width: containerWidth, height: containerHeight };
|
||||||
|
|
||||||
// - svg must fit container size
|
// - svg must fit container size
|
||||||
|
@ -28,7 +28,7 @@ class AddFeatureToTopicCommand extends Command {
|
|||||||
|
|
||||||
private _attributes: object;
|
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
|
* @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) {
|
undoExecute(commandContext: CommandContext) {
|
||||||
const topic = commandContext.findTopics([this._topicId])[0];
|
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
|
* @classdesc This command class handles do/undo of adding one or multiple topics to
|
||||||
* the mindmap.
|
* the mindmap.
|
||||||
*/
|
*/
|
||||||
constructor(models: NodeModel[], parentTopicsId: number[]) {
|
constructor(models: NodeModel[], parentTopicsId: number[] | null) {
|
||||||
$assert(models, 'models can not be null');
|
$assert(models, 'models can not be null');
|
||||||
$assert(
|
$assert(
|
||||||
parentTopicsId == null || parentTopicsId.length === models.length,
|
parentTopicsId == null || parentTopicsId.length === models.length,
|
||||||
@ -48,7 +48,7 @@ class AddTopicCommand extends Command {
|
|||||||
const topic = commandContext.createTopic(model);
|
const topic = commandContext.createTopic(model);
|
||||||
|
|
||||||
// Connect to topic ...
|
// Connect to topic ...
|
||||||
if (me._parentsIds) {
|
if (this._parentsIds) {
|
||||||
const parentId = me._parentsIds[index];
|
const parentId = me._parentsIds[index];
|
||||||
if ($defined(parentId)) {
|
if ($defined(parentId)) {
|
||||||
const parentTopic = commandContext.findTopics([parentId])[0];
|
const parentTopic = commandContext.findTopics([parentId])[0];
|
||||||
@ -70,7 +70,7 @@ class AddTopicCommand extends Command {
|
|||||||
|
|
||||||
undoExecute(commandContext: CommandContext) {
|
undoExecute(commandContext: CommandContext) {
|
||||||
// Delete disconnected the nodes. Create a copy of the topics ...
|
// Delete disconnected the nodes. Create a copy of the topics ...
|
||||||
const clonedModel = [];
|
const clonedModel: NodeModel[] = [];
|
||||||
this._models.forEach((model) => {
|
this._models.forEach((model) => {
|
||||||
clonedModel.push(model.clone());
|
clonedModel.push(model.clone());
|
||||||
});
|
});
|
||||||
|
@ -73,11 +73,12 @@ class DeleteCommand extends Command {
|
|||||||
const clonedModel = model.clone();
|
const clonedModel = model.clone();
|
||||||
this._deletedTopicModels.push(clonedModel);
|
this._deletedTopicModels.push(clonedModel);
|
||||||
const outTopic = topic.getOutgoingConnectedTopic();
|
const outTopic = topic.getOutgoingConnectedTopic();
|
||||||
let outTopicId = null;
|
|
||||||
|
let outTopicId: number | null = null;
|
||||||
if (outTopic != null) {
|
if (outTopic != null) {
|
||||||
outTopicId = outTopic.getId();
|
outTopicId = outTopic.getId();
|
||||||
|
this._parentTopicIds.push(outTopicId);
|
||||||
}
|
}
|
||||||
this._parentTopicIds.push(outTopicId);
|
|
||||||
|
|
||||||
// Finally, delete the topic from the workspace...
|
// Finally, delete the topic from the workspace...
|
||||||
commandContext.deleteTopic(topic);
|
commandContext.deleteTopic(topic);
|
||||||
@ -161,14 +162,14 @@ class DeleteCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _collectInDepthRelationships(topic: Topic): Relationship[] {
|
private _collectInDepthRelationships(topic: Topic): Relationship[] {
|
||||||
let result = [];
|
let result: Relationship[] = [];
|
||||||
result = result.concat(topic.getRelationships());
|
result.push(...topic.getRelationships());
|
||||||
|
|
||||||
const children = topic.getChildren();
|
const children = topic.getChildren();
|
||||||
const rels: Relationship[][] = children.map((t: Topic) => this._collectInDepthRelationships(t));
|
const rels: Relationship[][] = children.map((t: Topic) => this._collectInDepthRelationships(t));
|
||||||
|
|
||||||
// flatten and concact
|
// flatten and concact
|
||||||
result = result.concat([].concat(...rels));
|
result.push(...rels.flat());
|
||||||
|
|
||||||
if (result.length > 0) {
|
if (result.length > 0) {
|
||||||
// Filter for unique ...
|
// Filter for unique ...
|
||||||
|
@ -20,7 +20,7 @@ import Command from '../Command';
|
|||||||
import CommandContext from '../CommandContext';
|
import CommandContext from '../CommandContext';
|
||||||
import Topic from '../Topic';
|
import Topic from '../Topic';
|
||||||
|
|
||||||
type CommandTypes = string | object | boolean | number;
|
type CommandTypes = string | object | boolean | number | null;
|
||||||
|
|
||||||
class GenericFunctionCommand extends Command {
|
class GenericFunctionCommand extends Command {
|
||||||
private _value: CommandTypes;
|
private _value: CommandTypes;
|
||||||
@ -36,7 +36,7 @@ class GenericFunctionCommand extends Command {
|
|||||||
constructor(
|
constructor(
|
||||||
commandFunc: (topic: Topic, value: CommandTypes) => CommandTypes,
|
commandFunc: (topic: Topic, value: CommandTypes) => CommandTypes,
|
||||||
topicsIds: number[],
|
topicsIds: number[],
|
||||||
value: CommandTypes = undefined,
|
value: CommandTypes,
|
||||||
) {
|
) {
|
||||||
$assert(commandFunc, 'commandFunc must be defined');
|
$assert(commandFunc, 'commandFunc must be defined');
|
||||||
$assert($defined(topicsIds), 'topicsIds must be defined');
|
$assert($defined(topicsIds), 'topicsIds must be defined');
|
||||||
@ -51,15 +51,14 @@ class GenericFunctionCommand extends Command {
|
|||||||
/**
|
/**
|
||||||
* Overrides abstract parent method
|
* Overrides abstract parent method
|
||||||
*/
|
*/
|
||||||
execute(commandContext: CommandContext) {
|
execute(commandContext: CommandContext): void {
|
||||||
if (!this._applied) {
|
if (!this._applied) {
|
||||||
const topics = commandContext.findTopics(this._topicsIds);
|
const topics = commandContext.findTopics(this._topicsIds);
|
||||||
|
|
||||||
if (topics != null) {
|
if (topics != null) {
|
||||||
const me = this;
|
|
||||||
topics.forEach((topic: Topic) => {
|
topics.forEach((topic: Topic) => {
|
||||||
const oldValue = me._commandFunc(topic, me._value);
|
const oldValue = this._commandFunc(topic, this._value);
|
||||||
me._oldValues.push(oldValue);
|
this._oldValues.push(oldValue);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this._applied = true;
|
this._applied = true;
|
||||||
|
@ -41,21 +41,25 @@ class MDExporter extends Exporter {
|
|||||||
|
|
||||||
// Add cental node as text ...
|
// Add cental node as text ...
|
||||||
const centralTopic = this.mindmap.getCentralTopic();
|
const centralTopic = this.mindmap.getCentralTopic();
|
||||||
const centralText = this.normalizeText(centralTopic.getText());
|
|
||||||
|
|
||||||
// Traverse all the branches ...
|
const centralTopicText = centralTopic.getText();
|
||||||
let result = `# ${centralText}\n\n`;
|
let result = '';
|
||||||
result += this.traverseBranch('', centralTopic.getChildren());
|
if (centralTopicText) {
|
||||||
|
const centralText = this.normalizeText(centralTopicText);
|
||||||
|
|
||||||
// White footnotes:
|
// Traverse all the branches ...
|
||||||
if (this.footNotes.length > 0) {
|
result = `# ${centralText}\n\n`;
|
||||||
result += '\n\n\n';
|
result += this.traverseBranch('', centralTopic.getChildren());
|
||||||
this.footNotes.forEach((note, index) => {
|
|
||||||
result += `[^${index + 1}]: ${this.normalizeText(note)}`;
|
// 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);
|
return Promise.resolve(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,23 +68,26 @@ class SVGExporter extends Exporter {
|
|||||||
const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect'));
|
const rectElems = Array.from(this.svgElement.querySelectorAll('g>rect'));
|
||||||
const translates: SizeType[] = rectElems.map((rect: Element) => {
|
const translates: SizeType[] = rectElems.map((rect: Element) => {
|
||||||
const g = rect.parentElement;
|
const g = rect.parentElement;
|
||||||
const transformStr = g.getAttribute('transform');
|
const transformStr = g?.getAttribute('transform');
|
||||||
|
|
||||||
// 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 };
|
let result: SizeType = { width: 0, height: 0 };
|
||||||
if (match !== null) {
|
if (transformStr) {
|
||||||
result = { width: Number.parseFloat(match[1]), height: Number.parseFloat(match[2]) };
|
// 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 ...
|
// Add rect size ...
|
||||||
if (result.width > 0) {
|
const widthAttr = rect.getAttribute('width');
|
||||||
const rectWidth = Number.parseFloat(rect.getAttribute('width'));
|
if (result.width > 0 && widthAttr) {
|
||||||
result.width += rectWidth;
|
const rectWidth = Number.parseFloat(widthAttr);
|
||||||
}
|
result.width += rectWidth;
|
||||||
|
}
|
||||||
|
|
||||||
if (result.height > 0) {
|
const heightAttr = rect.getAttribute('height');
|
||||||
const rectHeight = Number.parseFloat(rect.getAttribute('height'));
|
if (result.height > 0 && heightAttr) {
|
||||||
result.height += rectHeight;
|
const rectHeight = Number.parseFloat(heightAttr);
|
||||||
|
result.height += rectHeight;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -7,15 +7,15 @@ export default class Font {
|
|||||||
|
|
||||||
protected SIZE: string;
|
protected SIZE: string;
|
||||||
|
|
||||||
getBold(): string {
|
getBold(): string | undefined {
|
||||||
return this.BOLD;
|
return this.BOLD;
|
||||||
}
|
}
|
||||||
|
|
||||||
getItalic(): string {
|
getItalic(): string | undefined {
|
||||||
return this.ITALIC;
|
return this.ITALIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
getName(): string {
|
getName(): string | undefined {
|
||||||
return this.NAME;
|
return this.NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class RootedTreeSet {
|
|||||||
$assert($defined(id), 'id can not be null');
|
$assert($defined(id), 'id can not be null');
|
||||||
|
|
||||||
const graphs = this._rootNodes;
|
const graphs = this._rootNodes;
|
||||||
let result = null;
|
let result: Node | null = null;
|
||||||
for (let i = 0; i < graphs.length; i++) {
|
for (let i = 0; i < graphs.length; i++) {
|
||||||
const node = graphs[i];
|
const node = graphs[i];
|
||||||
result = this._find(id, node);
|
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()}`);
|
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 {
|
private _find(id: number, parent: Node): Node {
|
||||||
@ -131,7 +131,7 @@ class RootedTreeSet {
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = null;
|
let result: Node | null = null;
|
||||||
const children = parent._children;
|
const children = parent._children;
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
const child = children[i];
|
const child = children[i];
|
||||||
@ -139,7 +139,7 @@ class RootedTreeSet {
|
|||||||
if (result) break;
|
if (result) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,7 +67,7 @@ abstract class IMindmap {
|
|||||||
$assert(child, 'Child can not be null.');
|
$assert(child, 'Child can not be null.');
|
||||||
$assert(parent, 'Child model seems to be already connected');
|
$assert(parent, 'Child model seems to be already connected');
|
||||||
|
|
||||||
parent.removeChild(child);
|
parent?.removeChild(child);
|
||||||
this.addBranch(child);
|
this.addBranch(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +46,8 @@ abstract class INodeModel {
|
|||||||
abstract getFeatures(): FeatureModel[];
|
abstract getFeatures(): FeatureModel[];
|
||||||
|
|
||||||
setId(id?: number): void {
|
setId(id?: number): void {
|
||||||
if (!$defined(id)) {
|
if (id === null || id === undefined) {
|
||||||
|
// Assign a new one ...
|
||||||
const newId = INodeModel._nextUUID();
|
const newId = INodeModel._nextUUID();
|
||||||
this.putProperty('id', newId);
|
this.putProperty('id', newId);
|
||||||
} else {
|
} else {
|
||||||
|
@ -89,7 +89,9 @@ class XMLSerializerFactory {
|
|||||||
result = new migrator(result);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user