@projectstorm/react-diagrams-core
Version:
This workspace houses the default models
32 lines • 1.41 kB
JavaScript
import { Action, InputType, MoveItemsState } from '@projectstorm/react-canvas-core';
import _forEach from 'lodash/forEach';
import { PointModel } from '../entities/link/PointModel';
import { PortModel } from '../entities/port/PortModel';
export class DragDiagramItemsState extends MoveItemsState {
constructor() {
super();
this.registerAction(new Action({
type: InputType.MOUSE_UP,
fire: (event) => {
const item = this.engine.getMouseElement(event.event);
if (item instanceof PortModel) {
_forEach(this.initialPositions, (position) => {
if (position.item instanceof PointModel) {
const link = position.item.getParent();
// only care about the last links
if (link.getLastPoint() !== position.item) {
return;
}
if (link.getSourcePort().canLinkToPort(item)) {
link.setTargetPort(item);
item.reportPosition();
this.engine.repaintCanvas();
}
}
});
}
}
}));
}
}
//# sourceMappingURL=DragDiagramItemsState.js.map