1 import {PluginBase} from "../plugin-base";
2 import {SelectionPlugin} from "../selection/selection";
3 import {StepModel, WorkflowInputParameterModel, WorkflowOutputParameterModel} from "cwlts/models";
5 export class DeletionPlugin extends PluginBase {
7 private boundDeleteFunction = this.onDelete.bind(this);
10 this.attachDeleteBehavior();
13 onEditableStateChange(enable: boolean) {
15 this.attachDeleteBehavior();
17 this.detachDeleteBehavior();
21 private attachDeleteBehavior() {
23 this.detachDeleteBehavior();
24 window.addEventListener("keyup", this.boundDeleteFunction, true);
27 private detachDeleteBehavior() {
28 window.removeEventListener("keyup", this.boundDeleteFunction, true);
31 private onDelete(ev: KeyboardEvent) {
32 if ((ev.which !== 8 && ev.which !== 46) || !(ev.target instanceof SVGElement)) {
36 this.deleteSelection();
39 public deleteSelection() {
40 const selection = this.workflow.getPlugin(SelectionPlugin);
42 if (!selection || !this.workflow.editingEnabled) {
46 const selected = selection.getSelection();
47 selected.forEach((type, id) => {
48 if (type === "node") {
49 const model = this.workflow.model.findById(id);
51 if (model instanceof StepModel) {
52 this.workflow.model.removeStep(model);
53 selection.clearSelection();
55 } else if (model instanceof WorkflowInputParameterModel) {
56 this.workflow.model.removeInput(model);
57 selection.clearSelection();
59 } else if (model instanceof WorkflowOutputParameterModel) {
61 this.workflow.model.removeOutput(model);
62 selection.clearSelection();
65 const [source, destination] = id.split(SelectionPlugin.edgePortsDelimiter);
66 this.workflow.model.disconnect(source, destination);
67 selection.clearSelection();
73 this.detachDeleteBehavior();