mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-12-22 19:53:49 +01:00
Move commands to TS.
This commit is contained in:
parent
560aa567c5
commit
2b40f429b4
@ -1,111 +0,0 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/*
|
||||
* Copyright [2021] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import Events from './Events';
|
||||
|
||||
class ActionDispatcher extends Events {
|
||||
constructor(commandContext) {
|
||||
$assert(commandContext, 'commandContext can not be null');
|
||||
super();
|
||||
}
|
||||
|
||||
addRelationship(model, mindmap) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
addTopics(models, parentTopicId) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
deleteEntities(topicsIds, relIds) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
dragTopic(topicId, position, order, parentTopic) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
moveTopic(topicId, position) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
moveControlPoint(ctrlPoint, point) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFontFamilyToTopic(topicIds, fontFamily) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFontStyleToTopic(topicsIds) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFontColorToTopic(topicsIds, color) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFontSizeToTopic(topicsIds, size) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeBackgroundColorToTopic(topicsIds, color) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeBorderColorToTopic(topicsIds, color) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeShapeTypeToTopic(topicsIds, shapeType) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFontWeightToTopic(topicsIds) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeTextToTopic(topicsIds, text) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
shrinkBranch(topicsIds, collapse) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
addFeatureToTopic(topicId, type, attributes) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
changeFeatureToTopic(topicId, featureId, attributes) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
|
||||
removeFeatureFromTopic(topicId, featureId) {
|
||||
throw new Error('method must be implemented.');
|
||||
}
|
||||
}
|
||||
|
||||
ActionDispatcher.setInstance = (dispatcher) => {
|
||||
ActionDispatcher._instance = dispatcher;
|
||||
};
|
||||
|
||||
ActionDispatcher.getInstance = () => ActionDispatcher._instance;
|
||||
|
||||
export default ActionDispatcher;
|
82
packages/mindplot/src/components/ActionDispatcher.ts
Normal file
82
packages/mindplot/src/components/ActionDispatcher.ts
Normal file
@ -0,0 +1,82 @@
|
||||
/* eslint-disable import/no-cycle */
|
||||
/* eslint-disable no-use-before-define */
|
||||
/*
|
||||
* Copyright [2021] [wisemapping]
|
||||
*
|
||||
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
|
||||
* It is basically the Apache License, Version 2.0 (the "License") plus the
|
||||
* "powered by wisemapping" text requirement on every single page;
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the license at
|
||||
*
|
||||
* http://www.wisemapping.org/license
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import Point from '@wisemapping/web2d';
|
||||
import { Mindmap } from '..';
|
||||
import CommandContext from './CommandContext';
|
||||
import Events from './Events';
|
||||
import NodeModel from './model/NodeModel';
|
||||
import RelationshipModel from './model/RelationshipModel';
|
||||
import Topic from './Topic';
|
||||
|
||||
abstract class ActionDispatcher extends Events {
|
||||
static _instance: ActionDispatcher;
|
||||
|
||||
constructor(commandContext: CommandContext) {
|
||||
$assert(commandContext, 'commandContext can not be null');
|
||||
super();
|
||||
}
|
||||
|
||||
abstract addRelationship(model: RelationshipModel, mindmap: Mindmap);
|
||||
|
||||
abstract addTopics(models: NodeModel[], parentTopicId: any[]);
|
||||
|
||||
abstract deleteEntities(topicsIds: number[], relIds: number[]);
|
||||
|
||||
abstract dragTopic(topicId: number, position: Point, order: number, parentTopic: Topic);
|
||||
|
||||
abstract moveTopic(topicId: number, position: any);
|
||||
|
||||
abstract moveControlPoint(ctrlPoint: this, point: any);
|
||||
|
||||
abstract changeFontFamilyToTopic(topicIds: number[], fontFamily: string);
|
||||
|
||||
abstract changeFontStyleToTopic(topicsIds: number[]);
|
||||
|
||||
abstract changeFontColorToTopic(topicsIds: number[], color: string);
|
||||
|
||||
abstract changeFontSizeToTopic(topicsIds: number[], size: number);
|
||||
|
||||
abstract changeBackgroundColorToTopic(topicsIds: number[], color: string);
|
||||
|
||||
abstract changeBorderColorToTopic(topicsIds: number[], color: string);
|
||||
|
||||
abstract changeShapeTypeToTopic(topicsIds: number[], shapeType: string);
|
||||
|
||||
abstract changeFontWeightToTopic(topicsIds: number[]);
|
||||
|
||||
abstract changeTextToTopic(topicsIds: number[], text: string);
|
||||
|
||||
abstract shrinkBranch(topicsIds: number[], collapse: boolean);
|
||||
|
||||
abstract addFeatureToTopic(topicId: number, type: string, attributes: object);
|
||||
|
||||
abstract changeFeatureToTopic(topicId: number, featureId: any, attributes: object);
|
||||
|
||||
abstract removeFeatureFromTopic(topicId: number, featureId: number);
|
||||
|
||||
static setInstance = (dispatcher: ActionDispatcher) => {
|
||||
this._instance = dispatcher;
|
||||
};
|
||||
|
||||
static getInstance = (): ActionDispatcher => ActionDispatcher._instance;
|
||||
}
|
||||
|
||||
export default ActionDispatcher;
|
@ -16,42 +16,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $defined } from '@wisemapping/core-js';
|
||||
import CommandContext from './CommandContext';
|
||||
|
||||
abstract class Command {
|
||||
private _id: number;
|
||||
|
||||
static _uuid: number;
|
||||
|
||||
class Command {
|
||||
/**
|
||||
* @classdesc The command base class for handling do/undo mindmap operations
|
||||
* @constructs
|
||||
*/
|
||||
constructor() {
|
||||
this._id = Command._nextUUID();
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
execute(commandContext) {
|
||||
throw new Error('execute must be implemented.');
|
||||
}
|
||||
abstract execute(commandContext:CommandContext):void;
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
undoExecute(commandContext) {
|
||||
throw new Error('undo must be implemented.');
|
||||
}
|
||||
abstract undoExecute(commandContext:CommandContext):void;
|
||||
|
||||
/**
|
||||
* Returns the unique id of this command
|
||||
* @returns {Number} command id
|
||||
*/
|
||||
getId() {
|
||||
getId():number {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
static _nextUUID() {
|
||||
if (!$defined(this._uuid)) {
|
||||
this._uuid = 1;
|
||||
}
|
||||
this._uuid += 1;
|
||||
return this._uuid;
|
||||
}
|
||||
}
|
||||
|
||||
Command._nextUUID = function _nextUUID() {
|
||||
if (!$defined(Command._uuid)) {
|
||||
Command._uuid = 1;
|
||||
}
|
||||
|
||||
Command._uuid += 1;
|
||||
return Command._uuid;
|
||||
};
|
||||
|
||||
export default Command;
|
@ -16,16 +16,32 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Point from '@wisemapping/web2d';
|
||||
import { Designer } from '..';
|
||||
import EventBus from './layout/EventBus';
|
||||
import NodeModel from './model/NodeModel';
|
||||
import RelationshipModel from './model/RelationshipModel';
|
||||
import Relationship from './Relationship';
|
||||
import Topic from './Topic';
|
||||
|
||||
class CommandContext {
|
||||
constructor(designer) {
|
||||
private _designer: Designer;
|
||||
|
||||
constructor(designer: Designer) {
|
||||
$assert(designer, 'designer can not be null');
|
||||
this._designer = designer;
|
||||
}
|
||||
|
||||
public get designer(): Designer {
|
||||
return this._designer;
|
||||
}
|
||||
|
||||
public set designer(value: Designer) {
|
||||
this._designer = value;
|
||||
}
|
||||
|
||||
/** */
|
||||
findTopics(topicIds) {
|
||||
findTopics(topicIds: number[]): Topic[] {
|
||||
$assert($defined(topicIds), 'topicsIds can not be null');
|
||||
const topicsIds = Array.isArray(topicIds) ? topicIds : [topicIds];
|
||||
const designerTopics = this._designer.getModel().getTopics();
|
||||
@ -45,51 +61,51 @@ class CommandContext {
|
||||
}
|
||||
|
||||
/** */
|
||||
deleteTopic(topic) {
|
||||
deleteTopic(topic: Topic) {
|
||||
this._designer.removeTopic(topic);
|
||||
}
|
||||
|
||||
/** */
|
||||
createTopic(model) {
|
||||
createTopic(model: NodeModel) {
|
||||
$assert(model, 'model can not be null');
|
||||
return this._designer.nodeModelToTopic(model);
|
||||
}
|
||||
|
||||
/** */
|
||||
createModel() {
|
||||
const mindmap = this._designer.getMindmap();
|
||||
return mindmap.createNode('MainTopic');
|
||||
}
|
||||
// /** */
|
||||
// createModel() {
|
||||
// const mindmap = this._designer.getMindmap();
|
||||
// return mindmap.createNode('MainTopic');
|
||||
// }
|
||||
|
||||
/** */
|
||||
addTopic(topic) {
|
||||
addTopic(topic: Topic) {
|
||||
const mindmap = this._designer.getMindmap();
|
||||
return mindmap.addBranch(topic.getModel());
|
||||
}
|
||||
|
||||
/** */
|
||||
connect(childTopic, parentTopic) {
|
||||
childTopic.connectTo(parentTopic, this._designer._workspace);
|
||||
connect(childTopic: Topic, parentTopic: Topic) {
|
||||
childTopic.connectTo(parentTopic, this._designer.getWorkSpace());
|
||||
}
|
||||
|
||||
/** */
|
||||
disconnect(topic) {
|
||||
topic.disconnect(this._designer._workspace);
|
||||
disconnect(topic: Topic) {
|
||||
topic.disconnect(this._designer.getWorkSpace());
|
||||
}
|
||||
|
||||
/** */
|
||||
addRelationship(model) {
|
||||
addRelationship(model: RelationshipModel) {
|
||||
$assert(model, 'model cannot be null');
|
||||
return this._designer.addRelationship(model);
|
||||
}
|
||||
|
||||
/** */
|
||||
deleteRelationship(relationship) {
|
||||
deleteRelationship(relationship: Relationship) {
|
||||
this._designer.deleteRelationship(relationship);
|
||||
}
|
||||
|
||||
/** */
|
||||
findRelationships(relationshipIds) {
|
||||
findRelationships(relationshipIds: number[]) {
|
||||
$assert($defined(relationshipIds), 'relId can not be null');
|
||||
const relIds = Array.isArray(relationshipIds) ? relationshipIds : [relationshipIds];
|
||||
|
||||
@ -98,7 +114,7 @@ class CommandContext {
|
||||
}
|
||||
|
||||
/** */
|
||||
moveTopic(topic, position) {
|
||||
moveTopic(topic: Topic, position: Point) {
|
||||
$assert(topic, 'topic cannot be null');
|
||||
$assert(position, 'position cannot be null');
|
||||
EventBus.instance.fireEvent(EventBus.events.NodeMoveEvent, {
|
||||
@ -107,5 +123,4 @@ class CommandContext {
|
||||
});
|
||||
}
|
||||
}
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export default CommandContext;
|
@ -75,9 +75,9 @@ class Designer extends Events {
|
||||
|
||||
private _relPivot: RelationshipPivot;
|
||||
|
||||
private _clipboard: any[];
|
||||
private _clipboard: NodeModel[];
|
||||
|
||||
private _cleanScreen: any;
|
||||
private _cleanScreen: () => void;
|
||||
|
||||
constructor(options: DesignerOptions, divElement: JQuery) {
|
||||
$assert(options, 'options must be defined');
|
||||
@ -281,11 +281,11 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?mindplot.Topic} currentObject
|
||||
* @param {Event=} event
|
||||
* sets focus to the given currentObject and removes it from any other objects if not
|
||||
* triggered with Ctrl pressed
|
||||
*/
|
||||
* @param {?mindplot.Topic} currentObject
|
||||
* @param {Event=} event
|
||||
* sets focus to the given currentObject and removes it from any other objects if not
|
||||
* triggered with Ctrl pressed
|
||||
*/
|
||||
onObjectFocusEvent(currentObject: Topic = null, event = null): void {
|
||||
// Close node editors ..
|
||||
const topics = this.getModel().getTopics();
|
||||
@ -580,9 +580,9 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mindplot.Mindmap} mindmap
|
||||
* @throws will throw an error if mindmapModel is null or undefined
|
||||
*/
|
||||
* @param {mindplot.Mindmap} mindmap
|
||||
* @throws will throw an error if mindmapModel is null or undefined
|
||||
*/
|
||||
loadMap(mindmap: Mindmap): void {
|
||||
$assert(mindmap, 'mindmapModel can not be null');
|
||||
this._mindmap = mindmap;
|
||||
@ -625,11 +625,11 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
undo(): void {
|
||||
this._actionDispatcher._actionRunner.undo();
|
||||
this._actionDispatcher.actionRunner.undo();
|
||||
}
|
||||
|
||||
redo(): void {
|
||||
this._actionDispatcher._actionRunner.redo();
|
||||
this._actionDispatcher.actionRunner.redo();
|
||||
}
|
||||
|
||||
/** */
|
||||
@ -637,7 +637,7 @@ class Designer extends Events {
|
||||
return this._options.readOnly;
|
||||
}
|
||||
|
||||
nodeModelToTopic(nodeModel: NodeModel):Topic {
|
||||
nodeModelToTopic(nodeModel: NodeModel): Topic {
|
||||
$assert(nodeModel, 'Node model can not be null');
|
||||
let children = nodeModel.getChildren().slice();
|
||||
children = children.sort((a, b) => a.getOrder() - b.getOrder());
|
||||
@ -655,12 +655,12 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the relationship created to the model
|
||||
* @throws will throw an error if model is null or undefined
|
||||
*/
|
||||
private _relationshipModelToRelationship(model: RelationshipModel):Relationship {
|
||||
* @private
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the relationship created to the model
|
||||
* @throws will throw an error if model is null or undefined
|
||||
*/
|
||||
private _relationshipModelToRelationship(model: RelationshipModel): Relationship {
|
||||
$assert(model, 'Node model can not be null');
|
||||
|
||||
const result = this._buildRelationshipShape(model);
|
||||
@ -678,20 +678,20 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the relationship added to the mindmap
|
||||
*/
|
||||
addRelationship(model: RelationshipModel):Relationship {
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the relationship added to the mindmap
|
||||
*/
|
||||
addRelationship(model: RelationshipModel): Relationship {
|
||||
const mindmap = this.getMindmap();
|
||||
mindmap.addRelationship(model);
|
||||
return this._relationshipModelToRelationship(model);
|
||||
}
|
||||
|
||||
/**
|
||||
* deletes the relationship from the linked topics, DesignerModel, Workspace and Mindmap
|
||||
* @param {mindplot.Relationship} rel the relationship to delete
|
||||
*/
|
||||
deleteRelationship(rel: Relationship):void {
|
||||
* deletes the relationship from the linked topics, DesignerModel, Workspace and Mindmap
|
||||
* @param {mindplot.Relationship} rel the relationship to delete
|
||||
*/
|
||||
deleteRelationship(rel: Relationship): void {
|
||||
const sourceTopic = rel.getSourceTopic();
|
||||
sourceTopic.deleteRelationship(rel);
|
||||
|
||||
@ -706,12 +706,12 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the new relationship with events registered
|
||||
* @throws will throw an error if the target topic cannot be found
|
||||
*/
|
||||
private _buildRelationshipShape(model: RelationshipModel):Relationship {
|
||||
* @private
|
||||
* @param {mindplot.model.RelationshipModel} model
|
||||
* @return {mindplot.Relationship} the new relationship with events registered
|
||||
* @throws will throw an error if the target topic cannot be found
|
||||
*/
|
||||
private _buildRelationshipShape(model: RelationshipModel): Relationship {
|
||||
const dmodel = this.getModel();
|
||||
|
||||
const sourceTopicId = model.getFromNode();
|
||||
@ -755,9 +755,9 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mindplot.Topic} node the topic to remove
|
||||
* removes the given topic and its children from Workspace, DesignerModel and NodeModel
|
||||
*/
|
||||
* @param {mindplot.Topic} node the topic to remove
|
||||
* removes the given topic and its children from Workspace, DesignerModel and NodeModel
|
||||
*/
|
||||
removeTopic(node) {
|
||||
if (!node.isCentralTopic()) {
|
||||
const parent = node._parent;
|
||||
@ -782,8 +782,8 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
* @private
|
||||
*/
|
||||
_resetEdition() {
|
||||
const screenManager = this._workspace.getScreenManager();
|
||||
screenManager.fireEvent('update');
|
||||
@ -839,18 +839,19 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontColor(color) {
|
||||
changeFontColor(color: string) {
|
||||
$assert(color, 'color can not be null');
|
||||
|
||||
const topicsIds = this.getModel()
|
||||
.filterTopicsIds();
|
||||
|
||||
if (topicsIds.length > 0) {
|
||||
this._actionDispatcher.changeFontColorToTopic(topicsIds, color);
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
changeBackgroundColor(color) {
|
||||
changeBackgroundColor(color: string) {
|
||||
const validateFunc = (topic) => topic.getShapeType() !== TopicShape.LINE;
|
||||
const validateError = 'Color can not be set to line topics.';
|
||||
|
||||
@ -910,9 +911,9 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* lets the selected topic open the link editor where the user can define or modify an
|
||||
* existing link
|
||||
*/
|
||||
* lets the selected topic open the link editor where the user can define or modify an
|
||||
* existing link
|
||||
*/
|
||||
addLink() {
|
||||
const model = this.getModel();
|
||||
const topic = model.selectedTopic();
|
||||
@ -933,9 +934,9 @@ class Designer extends Events {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {mindplot.Topic} node
|
||||
* sets the focus to the given node
|
||||
*/
|
||||
* @param {mindplot.Topic} node
|
||||
* sets the focus to the given node
|
||||
*/
|
||||
goToNode(node) {
|
||||
node.setOnFocus(true);
|
||||
this.onObjectFocusEvent(node);
|
||||
|
@ -106,7 +106,7 @@ class DesignerModel extends Events {
|
||||
this._relationships.push(rel);
|
||||
}
|
||||
|
||||
filterTopicsIds(validate: (topic: Topic) => boolean = null, errorMsg = null): Topic[] {
|
||||
filterTopicsIds(validate: (topic: Topic) => boolean = null, errorMsg = null): number[] {
|
||||
const result = [];
|
||||
const topics = this.filterSelectedTopics();
|
||||
|
||||
|
@ -92,8 +92,8 @@ class DragManager {
|
||||
|
||||
event.preventDefault();
|
||||
};
|
||||
|
||||
// allowed param reassign to avoid risks of existing code relying in this side-effect
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
dragManager._mouseMoveListener = result;
|
||||
return result;
|
||||
}
|
||||
@ -110,10 +110,8 @@ class DragManager {
|
||||
|
||||
// Help GC
|
||||
// allowed param reassign to avoid risks of existing code relying in this side-effect
|
||||
/* eslint-disable no-param-reassign */
|
||||
dragManager._mouseMoveListener = null;
|
||||
dragManager._mouseUpListener = null;
|
||||
/* eslint-enable no-param-reassign */
|
||||
|
||||
workspace.enableWorkspaceEvents(true);
|
||||
// Change the cursor to the default.
|
||||
@ -130,7 +128,6 @@ class DragManager {
|
||||
me._isDragInProcess = false;
|
||||
}
|
||||
};
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
dragManager._mouseUpListener = result;
|
||||
return result;
|
||||
}
|
||||
|
@ -28,17 +28,17 @@ class RelationshipPivot {
|
||||
|
||||
private _designer: Designer;
|
||||
|
||||
private _mouseMoveEvent: any;
|
||||
private _mouseMoveEvent: MouseEvent;
|
||||
|
||||
private _onClickEvent: any;
|
||||
private _onClickEvent: (event: MouseEvent) => void;
|
||||
|
||||
private _onTopicClick: any;
|
||||
private _onTopicClick: (event: MouseEvent) => void;;
|
||||
|
||||
private _sourceTopic: Topic;
|
||||
|
||||
private _pivot: any;
|
||||
|
||||
private _startArrow: any;
|
||||
private _startArrow: Arrow;
|
||||
|
||||
constructor(workspace: Workspace, designer: Designer) {
|
||||
$assert(workspace, 'workspace can not be null');
|
||||
|
@ -17,13 +17,14 @@
|
||||
*/
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import { Point } from '@wisemapping/web2d';
|
||||
import Topic from './Topic';
|
||||
|
||||
class ScreenManager {
|
||||
private _divContainer: JQuery;
|
||||
|
||||
private _padding: { x: number; y: number; };
|
||||
|
||||
private _clickEvents: ((event: UIEvent)=>void)[];
|
||||
private _clickEvents: ((event: UIEvent) => void)[];
|
||||
|
||||
private _scale: number;
|
||||
|
||||
@ -47,7 +48,7 @@ class ScreenManager {
|
||||
/**
|
||||
* Return the current visibile area in the browser.
|
||||
*/
|
||||
getVisibleBrowserSize():{width:number, height:number} {
|
||||
getVisibleBrowserSize(): { width: number, height: number } {
|
||||
return {
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight - Number.parseInt(this._divContainer.css('top'), 10),
|
||||
@ -59,7 +60,7 @@ class ScreenManager {
|
||||
this._scale = scale;
|
||||
}
|
||||
|
||||
addEvent(eventType: string, listener:any) {
|
||||
addEvent(eventType: string, listener: any) {
|
||||
if (eventType === 'click') this._clickEvents.push(listener);
|
||||
else this._divContainer.bind(eventType, listener);
|
||||
}
|
||||
@ -83,7 +84,7 @@ class ScreenManager {
|
||||
}
|
||||
}
|
||||
|
||||
_getElementPosition(elem: { getPosition: () => any; }) {
|
||||
private _getElementPosition(elem: Topic) {
|
||||
// Retrieve current element position.
|
||||
const elementPosition = elem.getPosition();
|
||||
let { x } = elementPosition;
|
||||
|
@ -16,6 +16,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $defined, $assert } from '@wisemapping/core-js';
|
||||
import { Point } from '@wisemapping/web2d';
|
||||
import ActionDispatcher from './ActionDispatcher';
|
||||
import DesignerActionRunner from './DesignerActionRunner';
|
||||
import AddTopicCommand from './commands/AddTopicCommand';
|
||||
@ -28,39 +29,52 @@ import GenericFunctionCommand from './commands/GenericFunctionCommand';
|
||||
import MoveControlPointCommand from './commands/MoveControlPointCommand';
|
||||
import ChangeFeatureToTopicCommand from './commands/ChangeFeatureToTopicCommand';
|
||||
import EventBus from './layout/EventBus';
|
||||
import CommandContext from './CommandContext';
|
||||
import NodeModel from './model/NodeModel';
|
||||
import RelationshipModel from './model/RelationshipModel';
|
||||
import Topic from './Topic';
|
||||
import Command from './Command';
|
||||
|
||||
class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
constructor(commandContext) {
|
||||
private _actionRunner: DesignerActionRunner;
|
||||
|
||||
public get actionRunner(): DesignerActionRunner {
|
||||
return this._actionRunner;
|
||||
}
|
||||
|
||||
public set actionRunner(value: DesignerActionRunner) {
|
||||
this._actionRunner = value;
|
||||
}
|
||||
|
||||
constructor(commandContext: CommandContext) {
|
||||
super(commandContext);
|
||||
this._actionRunner = new DesignerActionRunner(commandContext, this);
|
||||
}
|
||||
|
||||
/** */
|
||||
addTopics(models, parentTopicsId) {
|
||||
addTopics(models: NodeModel[], parentTopicsId: number[] = undefined) {
|
||||
const command = new AddTopicCommand(models, parentTopicsId);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
addRelationship(model) {
|
||||
addRelationship(model: RelationshipModel) {
|
||||
const command = new AddRelationshipCommand(model);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
deleteEntities(topicsIds, relIds) {
|
||||
deleteEntities(topicsIds: number[], relIds: number[]) {
|
||||
const command = new DeleteCommand(topicsIds, relIds);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
dragTopic(topicId, position, order, parentTopic) {
|
||||
dragTopic(topicId: number, position: Point, order: number, parentTopic: Topic) {
|
||||
const command = new DragTopicCommand(topicId, position, order, parentTopic);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
moveTopic(topicId, position) {
|
||||
moveTopic(topicId: number, position: Point) {
|
||||
$assert($defined(topicId), 'topicsId can not be null');
|
||||
$assert($defined(position), 'position can not be null');
|
||||
|
||||
@ -73,19 +87,19 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
return result;
|
||||
};
|
||||
|
||||
const command = new GenericFunctionCommand(commandFunc, topicId, position);
|
||||
const command = new GenericFunctionCommand(commandFunc, [topicId], position);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
moveControlPoint(ctrlPoint, point) {
|
||||
moveControlPoint(ctrlPoint: Point, point: Point) {
|
||||
const command = new MoveControlPointCommand(ctrlPoint, point);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontStyleToTopic(topicsIds) {
|
||||
const commandFunc = (topic) => {
|
||||
changeFontStyleToTopic(topicsIds: number[]) {
|
||||
const commandFunc = (topic: Topic) => {
|
||||
const result = topic.getFontStyle();
|
||||
const style = result === 'italic' ? 'normal' : 'italic';
|
||||
topic.setFontStyle(style, true);
|
||||
@ -96,10 +110,10 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeTextToTopic(topicsIds, text) {
|
||||
changeTextToTopic(topicsIds: number[], text: string) {
|
||||
$assert($defined(topicsIds), 'topicsIds can not be null');
|
||||
|
||||
const commandFunc = (topic, value) => {
|
||||
const commandFunc = (topic: Topic, value: object) => {
|
||||
const result = topic.getText();
|
||||
topic.setText(value);
|
||||
return result;
|
||||
@ -111,11 +125,11 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontFamilyToTopic(topicIds, fontFamily) {
|
||||
changeFontFamilyToTopic(topicIds: number[], fontFamily: string) {
|
||||
$assert(topicIds, 'topicIds can not be null');
|
||||
$assert(fontFamily, 'fontFamily can not be null');
|
||||
|
||||
const commandFunc = (topic, commandFontFamily) => {
|
||||
const commandFunc = (topic: Topic, commandFontFamily: string) => {
|
||||
const result = topic.getFontFamily();
|
||||
topic.setFontFamily(commandFontFamily, true);
|
||||
|
||||
@ -128,7 +142,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontColorToTopic(topicsIds, color) {
|
||||
changeFontColorToTopic(topicsIds: number[], color: string) {
|
||||
$assert(topicsIds, 'topicIds can not be null');
|
||||
$assert(color, 'color can not be null');
|
||||
|
||||
@ -144,7 +158,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeBackgroundColorToTopic(topicsIds, color) {
|
||||
changeBackgroundColorToTopic(topicsIds: number[], color: string) {
|
||||
$assert(topicsIds, 'topicIds can not be null');
|
||||
$assert(color, 'color can not be null');
|
||||
|
||||
@ -160,7 +174,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeBorderColorToTopic(topicsIds, color) {
|
||||
changeBorderColorToTopic(topicsIds: number[], color: string): void {
|
||||
$assert(topicsIds, 'topicIds can not be null');
|
||||
$assert(color, 'topicIds can not be null');
|
||||
|
||||
@ -176,7 +190,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontSizeToTopic(topicsIds, size) {
|
||||
changeFontSizeToTopic(topicsIds: number[], size: number) {
|
||||
$assert(topicsIds, 'topicIds can not be null');
|
||||
$assert(size, 'size can not be null');
|
||||
|
||||
@ -193,7 +207,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeShapeTypeToTopic(topicsIds, shapeType) {
|
||||
changeShapeTypeToTopic(topicsIds: number[], shapeType: string) {
|
||||
$assert(topicsIds, 'topicsIds can not be null');
|
||||
$assert(shapeType, 'shapeType can not be null');
|
||||
|
||||
@ -208,7 +222,7 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFontWeightToTopic(topicsIds) {
|
||||
changeFontWeightToTopic(topicsIds: number[]) {
|
||||
$assert(topicsIds, 'topicsIds can not be null');
|
||||
|
||||
const commandFunc = (topic) => {
|
||||
@ -225,38 +239,38 @@ class StandaloneActionDispatcher extends ActionDispatcher {
|
||||
}
|
||||
|
||||
/** */
|
||||
shrinkBranch(topicsIds, collapse) {
|
||||
shrinkBranch(topicsIds: number[], collapse: boolean) {
|
||||
$assert(topicsIds, 'topicsIds can not be null');
|
||||
|
||||
const commandFunc = (topic, isShrink) => {
|
||||
const commandFunc = (topic: Topic, isShrink: boolean) => {
|
||||
topic.setChildrenShrunken(isShrink);
|
||||
return !isShrink;
|
||||
};
|
||||
|
||||
const command = new GenericFunctionCommand(commandFunc, topicsIds, collapse);
|
||||
this.execute(command, false);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
addFeatureToTopic(topicId, featureType, attributes) {
|
||||
addFeatureToTopic(topicId: number, featureType: string, attributes) {
|
||||
const command = new AddFeatureToTopicCommand(topicId, featureType, attributes);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
changeFeatureToTopic(topicId, featureId, attributes) {
|
||||
changeFeatureToTopic(topicId: number, featureId: number, attributes) {
|
||||
const command = new ChangeFeatureToTopicCommand(topicId, featureId, attributes);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
removeFeatureFromTopic(topicId, featureId) {
|
||||
removeFeatureFromTopic(topicId: number, featureId: number) {
|
||||
const command = new RemoveFeatureFromTopicCommand(topicId, featureId);
|
||||
this.execute(command);
|
||||
}
|
||||
|
||||
/** */
|
||||
execute(command) {
|
||||
execute(command: Command) {
|
||||
this._actionRunner.execute(command);
|
||||
}
|
||||
}
|
@ -17,8 +17,17 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
|
||||
class AddFeatureToTopicCommand extends Command {
|
||||
private _topicId: number;
|
||||
|
||||
private _featureType: string;
|
||||
|
||||
private _attributes: object;
|
||||
|
||||
private _featureModel: any;
|
||||
|
||||
/*
|
||||
* @classdesc This command class handles do/undo of adding features to topics, e.g. an
|
||||
* icon or a note. For a reference of existing features, refer to {@link mindplot.TopicFeature}
|
||||
@ -29,7 +38,7 @@ class AddFeatureToTopicCommand extends Command {
|
||||
* @extends mindplot.Command
|
||||
* @see mindplot.model.FeatureModel and subclasses
|
||||
*/
|
||||
constructor(topicId, featureType, attributes) {
|
||||
constructor(topicId: number, featureType: string, attributes: object) {
|
||||
$assert($defined(topicId), 'topicId can not be null');
|
||||
$assert(featureType, 'featureType can not be null');
|
||||
$assert(attributes, 'attributes can not be null');
|
||||
@ -44,8 +53,8 @@ class AddFeatureToTopicCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicId)[0];
|
||||
execute(commandContext: CommandContext) {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
|
||||
// Feature must be created only one time.
|
||||
if (!this._featureModel) {
|
||||
@ -59,8 +68,8 @@ class AddFeatureToTopicCommand extends Command {
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicId)[0];
|
||||
undoExecute(commandContext: CommandContext) {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
topic.removeFeature(this._featureModel);
|
||||
}
|
||||
}
|
@ -17,15 +17,15 @@
|
||||
*/
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import RelationshipModel from '../model/RelationshipModel';
|
||||
|
||||
class AddRelationshipCommand extends Command {
|
||||
private _model: RelationshipModel;
|
||||
|
||||
/**
|
||||
* @classdesc This command class handles do/undo of adding a relationship to a topic.
|
||||
* @constructs
|
||||
* @param {XMLDOM} model
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(model) {
|
||||
constructor(model:RelationshipModel) {
|
||||
$assert(model, 'Relationship model can not be null');
|
||||
|
||||
super();
|
@ -17,18 +17,19 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
import NodeModel from '../model/NodeModel';
|
||||
|
||||
class AddTopicCommand extends Command {
|
||||
private _models: NodeModel[];
|
||||
|
||||
private _parentsIds: number[];
|
||||
|
||||
/**
|
||||
* @classdesc This command class handles do/undo of adding one or multiple topics to
|
||||
* the mindmap.
|
||||
* @constructs
|
||||
* @param {Array<mindplot.model.NodeModel>} models one or multiple models
|
||||
* @param {Array<String>} parentTopicsId ids of the parent topics to add the children to, or null
|
||||
* when attaching a dragged node or a node/branch from clipboard
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(models, parentTopicsId) {
|
||||
constructor(models: NodeModel[], parentTopicsId: number[]) {
|
||||
$assert(models, 'models can not be null');
|
||||
$assert(parentTopicsId == null || parentTopicsId.length === models.length, 'parents and models must have the same size');
|
||||
|
||||
@ -40,7 +41,7 @@ class AddTopicCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
execute(commandContext: CommandContext) {
|
||||
const me = this;
|
||||
this._models.forEach((model, index) => {
|
||||
// Add a new topic ...
|
||||
@ -50,7 +51,7 @@ class AddTopicCommand extends Command {
|
||||
if (me._parentsIds) {
|
||||
const parentId = me._parentsIds[index];
|
||||
if ($defined(parentId)) {
|
||||
const parentTopic = commandContext.findTopics(parentId)[0];
|
||||
const parentTopic = commandContext.findTopics([parentId])[0];
|
||||
commandContext.connect(topic, parentTopic);
|
||||
}
|
||||
} else {
|
||||
@ -58,7 +59,7 @@ class AddTopicCommand extends Command {
|
||||
}
|
||||
|
||||
// Select just created node ...
|
||||
const designer = commandContext._designer;
|
||||
const { designer } = commandContext;
|
||||
designer.onObjectFocusEvent(topic);
|
||||
topic.setOnFocus(true);
|
||||
|
||||
@ -71,7 +72,7 @@ class AddTopicCommand extends Command {
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
undoExecute(commandContext: CommandContext) {
|
||||
// Delete disconnected the nodes. Create a copy of the topics ...
|
||||
const clonedModel = [];
|
||||
this._models.forEach((model) => {
|
||||
@ -79,9 +80,9 @@ class AddTopicCommand extends Command {
|
||||
});
|
||||
|
||||
// Finally, remove the nodes ...
|
||||
this._models.forEach((model) => {
|
||||
this._models.forEach((model: NodeModel) => {
|
||||
const topicId = model.getId();
|
||||
const topic = commandContext.findTopics(topicId)[0];
|
||||
const topic = commandContext.findTopics([topicId])[0];
|
||||
commandContext.deleteTopic(topic);
|
||||
});
|
||||
|
@ -17,19 +17,16 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
|
||||
class ChangeFeatureToTopicCommand extends Command {
|
||||
/**
|
||||
* @extends mindplot.Command
|
||||
* @constructs
|
||||
* @param topicId
|
||||
* @param featureId
|
||||
* @param attributes
|
||||
* @throws will throw an error if topicId is null or undefined
|
||||
* @throws will throw an error if featureId is null or undefined
|
||||
* @throws will throw an error if attributes is null or undefined
|
||||
*/
|
||||
constructor(topicId, featureId, attributes) {
|
||||
private _featureId: number;
|
||||
|
||||
private _topicId: number;
|
||||
|
||||
private _attributes: any;
|
||||
|
||||
constructor(topicId: number, featureId: number, attributes: any) {
|
||||
$assert($defined(topicId), 'topicId can not be null');
|
||||
$assert($defined(featureId), 'featureId can not be null');
|
||||
$assert($defined(attributes), 'attributes can not be null');
|
||||
@ -43,8 +40,8 @@ class ChangeFeatureToTopicCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicId)[0];
|
||||
execute(commandContext: CommandContext) {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
const feature = topic.findFeatureById(this._featureId);
|
||||
|
||||
const oldAttributes = feature.getAttributes();
|
||||
@ -56,7 +53,7 @@ class ChangeFeatureToTopicCommand extends Command {
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
undoExecute(commandContext: any) {
|
||||
this.execute(commandContext);
|
||||
}
|
||||
}
|
@ -17,16 +17,20 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
|
||||
class DeleteCommand extends Command {
|
||||
/**
|
||||
* @classdesc This command class handles do/undo of deleting a topic.
|
||||
* @constructs
|
||||
* @param {Array<String>} topicIds ids of the topics to delete
|
||||
* @param {Array<String>} relIds ids of the relationships connected to the topics
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(topicIds, relIds) {
|
||||
private _relIds: number[];
|
||||
|
||||
private _topicIds: number[];
|
||||
|
||||
private _deletedTopicModels: any[];
|
||||
|
||||
private _deletedRelModel: any[];
|
||||
|
||||
private _parentTopicIds: any[];
|
||||
|
||||
constructor(topicIds: number[], relIds: number[]) {
|
||||
$assert($defined(relIds), 'topicIds can not be null');
|
||||
|
||||
super();
|
||||
@ -40,7 +44,7 @@ class DeleteCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
execute(commandContext: CommandContext) {
|
||||
// If a parent has been selected for deletion, the children must be excluded from the delete ...
|
||||
const topics = this._filterChildren(this._topicIds, commandContext);
|
||||
|
||||
@ -89,7 +93,7 @@ class DeleteCommand extends Command {
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
undoExecute(commandContext: CommandContext) {
|
||||
// Add all the topics ...
|
||||
this._deletedTopicModels.forEach((model) => {
|
||||
commandContext.createTopic(model);
|
@ -16,19 +16,25 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Point from '@wisemapping/web2d';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
import Topic from '../Topic';
|
||||
|
||||
class DragTopicCommand extends Command {
|
||||
private _topicsId: number;
|
||||
|
||||
private _parentId: any;
|
||||
|
||||
private _position: Point;
|
||||
|
||||
private _order: number;
|
||||
|
||||
/**
|
||||
* @classdesc This command class handles do/undo of dragging a topic to a new position.
|
||||
* @constructs
|
||||
* @param {String} topicId id of the topic to drag
|
||||
* @param {Object} position
|
||||
* @param {Number} order the order property (children are displayed in order from 0 to n)
|
||||
* @param {mindplot.Topic} parentTopic the topic to be made the dragged topic's new parent
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(topicId, position, order, parentTopic) {
|
||||
constructor(topicId: number, position: Point, order: number, parentTopic: Topic) {
|
||||
$assert(topicId, 'topicId must be defined');
|
||||
super();
|
||||
|
||||
@ -44,8 +50,8 @@ class DragTopicCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicsId)[0];
|
||||
execute(commandContext: CommandContext): void {
|
||||
const topic = commandContext.findTopics([this._topicsId])[0];
|
||||
topic.setVisibility(false);
|
||||
|
||||
// Save old position ...
|
||||
@ -89,11 +95,7 @@ class DragTopicCommand extends Command {
|
||||
this._position = origPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
undoExecute(commandContext: CommandContext): void {
|
||||
this.execute(commandContext);
|
||||
}
|
||||
}
|
@ -17,20 +17,23 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
import Topic from '../Topic';
|
||||
|
||||
class GenericFunctionCommand extends Command {
|
||||
/**
|
||||
* @classdesc This command handles do/undo of different actions, e.g. moving topics to
|
||||
* a different position, changing text or font,... (for full reference check the
|
||||
* StandaloneActionDispatcher i.e. the ActionDispatcher subclass in use)
|
||||
* @constructs
|
||||
* @param {Function} commandFunc the function the command shall execute
|
||||
* @param {String|Array<String>} topicsIds the ids of the topics affected
|
||||
* @param {Object} [value] value arbitrary value necessary for the execution of the function,
|
||||
* e.g. color, font family or text
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(commandFunc, topicsIds, value) {
|
||||
private _discardDuplicated: string;
|
||||
|
||||
private _value: string | object | boolean | number;
|
||||
|
||||
private _topicsId: number[];
|
||||
|
||||
private _commandFunc: (topic: Topic, value: string | object | boolean | number) => string | object | boolean;
|
||||
|
||||
private _oldValues: any[];
|
||||
|
||||
private _applied: boolean;
|
||||
|
||||
constructor(commandFunc: (topic: Topic, value: string | object | boolean) => string | object | boolean, topicsIds: number[], value: string | object | boolean | number = undefined) {
|
||||
$assert(commandFunc, 'commandFunc must be defined');
|
||||
$assert($defined(topicsIds), 'topicsIds must be defined');
|
||||
|
||||
@ -39,58 +42,51 @@ class GenericFunctionCommand extends Command {
|
||||
this._topicsId = topicsIds;
|
||||
this._commandFunc = commandFunc;
|
||||
this._oldValues = [];
|
||||
this.discardDuplicated = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
if (!this.applied) {
|
||||
let topics = null;
|
||||
try {
|
||||
topics = commandContext.findTopics(this._topicsId);
|
||||
} catch (e) {
|
||||
if (this._commandFunc.commandType !== 'changeTextToTopic') {
|
||||
// Workaround: For some reason, there is a combination of events that involves
|
||||
// making some modification and firing out of focus event. This is causing
|
||||
// that a remove node try to be removed.
|
||||
// In some other life, I will come with the solution. Almost aways occurs with IE9.
|
||||
// I could be related with some change of order in sets o something similar.
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
execute(commandContext: CommandContext) {
|
||||
if (!this._applied) {
|
||||
const topics = commandContext.findTopics(this._topicsId);
|
||||
|
||||
if (topics != null) {
|
||||
const me = this;
|
||||
topics.forEach((topic) => {
|
||||
topics.forEach((topic: Topic) => {
|
||||
const oldValue = me._commandFunc(topic, me._value);
|
||||
me._oldValues.push(oldValue);
|
||||
});
|
||||
}
|
||||
this.applied = true;
|
||||
this._applied = true;
|
||||
} else {
|
||||
throw new Error('Command can not be applied two times in a row.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
if (this.applied) {
|
||||
undoExecute(commandContext: CommandContext): void {
|
||||
if (this._applied) {
|
||||
const topics = commandContext.findTopics(this._topicsId);
|
||||
|
||||
topics.forEach(((topic, index) => {
|
||||
topics.forEach(((topic: Topic, index: number) => {
|
||||
this._commandFunc(topic, this._oldValues[index]);
|
||||
}));
|
||||
|
||||
this.applied = false;
|
||||
this._applied = false;
|
||||
this._oldValues = [];
|
||||
} else {
|
||||
throw new Error('undo can not be applied.');
|
||||
}
|
||||
}
|
||||
|
||||
public get disardDuplicated(): string {
|
||||
return this._discardDuplicated;
|
||||
}
|
||||
|
||||
public set discardDuplicated(value: string) {
|
||||
this._discardDuplicated = value;
|
||||
}
|
||||
}
|
||||
|
||||
export default GenericFunctionCommand;
|
@ -17,20 +17,32 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import ControlPoint from '../ControlPoint';
|
||||
|
||||
class MoveControlPointCommand extends Command {
|
||||
private _ctrlPointControler: ControlPoint;
|
||||
|
||||
private _line: any;
|
||||
|
||||
private _controlPoint: any;
|
||||
|
||||
private _oldControlPoint: any;
|
||||
|
||||
private _originalEndPoint: any;
|
||||
|
||||
private _wasCustom: any;
|
||||
|
||||
private _endPoint: any;
|
||||
|
||||
private _point: number;
|
||||
|
||||
/**
|
||||
* @classdesc This command handles do/undo of changing the control points of a relationship
|
||||
* arrow. These are the two points that appear when the relationship is on focus. They
|
||||
* influence how the arrow is drawn (not the source or the destination topic nor the arrow
|
||||
* direction)
|
||||
* @constructs
|
||||
* @param {ControlPoint} ctrlPointController
|
||||
* @param {Number} point 0 for the destination control point, 1 for the source control point
|
||||
* @param ctrlPointController {ControlPoint}
|
||||
* @param point {Number} 0 for the destination control point, 1 for the source control point
|
||||
*/
|
||||
constructor(ctrlPointController, point) {
|
||||
* @classdesc This command handles do/undo of changing the control points of a relationship
|
||||
* arrow. These are the two points that appear when the relationship is on focus. They
|
||||
* influence how the arrow is drawn (not the source or the destination topic nor the arrow
|
||||
* direction)
|
||||
*/
|
||||
constructor(ctrlPointController: ControlPoint, point: number) {
|
||||
$assert(ctrlPointController, 'line can not be null');
|
||||
$assert($defined(point), 'point can not be null');
|
||||
|
@ -17,17 +17,20 @@
|
||||
*/
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import Command from '../Command';
|
||||
import CommandContext from '../CommandContext';
|
||||
|
||||
class RemoveFeatureFromTopicCommand extends Command {
|
||||
private _topicId: number;
|
||||
|
||||
private _featureId: number;
|
||||
|
||||
private _oldFeature: any;
|
||||
|
||||
/**
|
||||
* @classdesc This command handles do/undo of removing a feature from a topic, e.g. an icon or
|
||||
* a note. For a reference of existing features, refer to {@link mindplot.TopicFeature}.
|
||||
* @constructs
|
||||
* @param {String} topicId id of the topic to remove the feature from
|
||||
* @param {String} featureId id of the feature to remove
|
||||
* @extends mindplot.Command
|
||||
*/
|
||||
constructor(topicId, featureId) {
|
||||
constructor(topicId: number, featureId: number) {
|
||||
$assert($defined(topicId), 'topicId can not be null');
|
||||
$assert(featureId, 'iconModel can not be null');
|
||||
|
||||
@ -40,8 +43,8 @@ class RemoveFeatureFromTopicCommand extends Command {
|
||||
/**
|
||||
* Overrides abstract parent method
|
||||
*/
|
||||
execute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicId)[0];
|
||||
execute(commandContext:CommandContext):void {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
const feature = topic.findFeatureById(this._featureId);
|
||||
topic.removeFeature(feature);
|
||||
this._oldFeature = feature;
|
||||
@ -51,8 +54,8 @@ class RemoveFeatureFromTopicCommand extends Command {
|
||||
* Overrides abstract parent method
|
||||
* @see {@link mindplot.Command.undoExecute}
|
||||
*/
|
||||
undoExecute(commandContext) {
|
||||
const topic = commandContext.findTopics(this._topicId)[0];
|
||||
undoExecute(commandContext:CommandContext) {
|
||||
const topic = commandContext.findTopics([this._topicId])[0];
|
||||
topic.addFeature(this._oldFeature);
|
||||
this._oldFeature = null;
|
||||
}
|
@ -81,8 +81,7 @@ abstract class IMindmap {
|
||||
|
||||
abstract deleteRelationship(relationship: RelationshipModel): void;
|
||||
|
||||
/** */
|
||||
inspect() {
|
||||
inspect():string {
|
||||
let result = '';
|
||||
result = '{ ';
|
||||
|
||||
@ -103,19 +102,15 @@ abstract class IMindmap {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param target
|
||||
*/
|
||||
copyTo(target) {
|
||||
const source = this;
|
||||
const version = source.getVersion();
|
||||
copyTo(target:IMindmap) {
|
||||
const version = this.getVersion();
|
||||
target.setVersion(version);
|
||||
|
||||
const desc = this.getDescription();
|
||||
target.setDescription(desc);
|
||||
|
||||
// Then the rest of the branches ...
|
||||
const sbranchs = source.getBranches();
|
||||
const sbranchs = this.getBranches();
|
||||
sbranchs.forEach((snode) => {
|
||||
const tnode = target.createNode(snode.getType(), snode.getId());
|
||||
snode.copyTo(tnode);
|
||||
|
@ -37,6 +37,7 @@ class NodeModel extends INodeModel {
|
||||
$assert(type, 'Node type can not be null');
|
||||
$assert(mindmap, 'mindmap can not be null');
|
||||
super(mindmap);
|
||||
|
||||
this._properties = {};
|
||||
this.setId(id);
|
||||
this.setType(type);
|
||||
|
@ -15,7 +15,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/* eslint-disable import/no-unresolved */
|
||||
import jquery from 'jquery';
|
||||
import * as DesignerBuilder from './components/DesignerBuilder';
|
||||
import Mindmap from './components/model/Mindmap';
|
||||
|
Loading…
Reference in New Issue
Block a user