mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +01:00
Fix drag problme
This commit is contained in:
parent
5d107ef841
commit
60e7b3d7e2
@ -18,6 +18,7 @@
|
|||||||
import { $assert, $defined } from '@wisemapping/core-js';
|
import { $assert, $defined } from '@wisemapping/core-js';
|
||||||
import DragTopic from './DragTopic';
|
import DragTopic from './DragTopic';
|
||||||
import EventBusDispatcher from './layout/EventBusDispatcher';
|
import EventBusDispatcher from './layout/EventBusDispatcher';
|
||||||
|
import Topic from './Topic';
|
||||||
import Workspace from './Workspace';
|
import Workspace from './Workspace';
|
||||||
|
|
||||||
class DragManager {
|
class DragManager {
|
||||||
@ -44,7 +45,7 @@ class DragManager {
|
|||||||
DragTopic.init(this._workspace);
|
DragTopic.init(this._workspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
add(node) {
|
add(topic: Topic) {
|
||||||
// Add behaviour ...
|
// Add behaviour ...
|
||||||
const workspace = this._workspace;
|
const workspace = this._workspace;
|
||||||
const screen = workspace.getScreenManager();
|
const screen = workspace.getScreenManager();
|
||||||
@ -57,7 +58,7 @@ class DragManager {
|
|||||||
|
|
||||||
// Set initial position.
|
// Set initial position.
|
||||||
const layoutManager = me._eventDispatcher.getLayoutManager();
|
const layoutManager = me._eventDispatcher.getLayoutManager();
|
||||||
const dragNode = node.createDragNode(layoutManager);
|
const dragNode = topic.createDragNode(layoutManager);
|
||||||
|
|
||||||
// Register mouse move listener ...
|
// Register mouse move listener ...
|
||||||
const mouseMoveListener = dragManager._buildMouseMoveListener(
|
const mouseMoveListener = dragManager._buildMouseMoveListener(
|
||||||
@ -67,7 +68,7 @@ class DragManager {
|
|||||||
|
|
||||||
// Register mouse up listeners ...
|
// Register mouse up listeners ...
|
||||||
const mouseUpListener = dragManager._buildMouseUpListener(
|
const mouseUpListener = dragManager._buildMouseUpListener(
|
||||||
workspace, node, dragNode, dragManager,
|
workspace, topic, dragNode, dragManager,
|
||||||
);
|
);
|
||||||
screen.addEvent('mouseup', mouseUpListener);
|
screen.addEvent('mouseup', mouseUpListener);
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ class DragManager {
|
|||||||
window.document.body.style.cursor = 'move';
|
window.document.body.style.cursor = 'move';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
node.addEvent('mousedown', mouseDownListener);
|
topic.addEvent('mousedown', mouseDownListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
@ -114,10 +115,10 @@ class DragManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _buildMouseUpListener(workspace: Workspace, node, dragNode, dragManager: DragManager) {
|
protected _buildMouseUpListener(workspace: Workspace, topic: Topic, dragNode, dragManager: DragManager) {
|
||||||
const screen = workspace.getScreenManager();
|
const screen = workspace.getScreenManager();
|
||||||
const me = this;
|
const me = this;
|
||||||
const result = (event) => {
|
const result = (event: Event) => {
|
||||||
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
|
$assert(dragNode.isDragTopic, 'dragNode must be an DragTopic');
|
||||||
|
|
||||||
// Remove all the events.
|
// Remove all the events.
|
||||||
@ -154,7 +155,7 @@ class DragManager {
|
|||||||
* - dragging
|
* - dragging
|
||||||
* - enddragging
|
* - enddragging
|
||||||
*/
|
*/
|
||||||
addEvent(type, listener) {
|
addEvent(type: string, listener) {
|
||||||
this._listeners[type] = listener;
|
this._listeners[type] = listener;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ class DragTopicCommand extends Command {
|
|||||||
const origPosition = topic.getPosition();
|
const origPosition = topic.getPosition();
|
||||||
|
|
||||||
// Disconnect topic ..
|
// Disconnect topic ..
|
||||||
if ($defined(origParentTopic) && origParentTopic.getId() !== this._parentId) {
|
if ($defined(origParentTopic)) {
|
||||||
commandContext.disconnect(topic);
|
commandContext.disconnect(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,17 +76,15 @@ class DragTopicCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally, connect topic ...
|
// Finally, connect topic ...
|
||||||
if (!$defined(origParentTopic) || origParentTopic.getId() !== this._parentId) {
|
if ($defined(this._parentId)) {
|
||||||
if ($defined(this._parentId)) {
|
const parentTopic = commandContext.findTopics([this._parentId])[0];
|
||||||
const parentTopic = commandContext.findTopics([this._parentId])[0];
|
commandContext.connect(topic, parentTopic);
|
||||||
commandContext.connect(topic, parentTopic);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Backup old parent id ...
|
// Backup old parent id ...
|
||||||
this._parentId = null;
|
this._parentId = null;
|
||||||
if ($defined(origParentTopic)) {
|
if ($defined(origParentTopic)) {
|
||||||
this._parentId = origParentTopic.getId();
|
this._parentId = origParentTopic.getId();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
topic.setVisibility(true);
|
topic.setVisibility(true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user