@difizen/ai-flow
Version:
Scalable, out-of-the-box, agent-oriented flow
90 lines (88 loc) • 3.13 kB
JavaScript
import isWrappedWithClass from "../../utils/wrappedClass";
import { cloneDeep } from 'lodash';
export function handleUndo(e, undo) {
if (!isWrappedWithClass(e, 'noflow')) {
e.preventDefault();
e.stopImmediatePropagation();
undo();
}
}
export function handleRedo(e, redo) {
if (!isWrappedWithClass(e, 'noflow')) {
e.preventDefault();
e.stopImmediatePropagation();
redo();
}
}
// export function handleGroup(e: KeyboardEvent) {
// if (selectionMenuVisible) {
// e.preventDefault();
// (e as unknown as Event).stopImmediatePropagation();
// handleGroupNode();
// }
// }
export function handleDuplicate(e, paste, nodes, position) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
var selectedNode = nodes.filter(function (obj) {
return obj.selected;
});
if (selectedNode.length > 0) {
paste({
nodes: selectedNode,
edges: []
}, {
x: position.current.x,
y: position.current.y
});
}
}
export function handleCopy(e, lastSelection, setLastCopiedSelection) {
var multipleSelection = lastSelection !== null && lastSelection !== void 0 && lastSelection.nodes ? (lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.nodes.length) > 0 : false;
if (!isWrappedWithClass(e, 'noflow') && (isWrappedWithClass(e, 'react-flow__node') || multipleSelection)) {
var _window$getSelection;
e.preventDefault();
e.stopImmediatePropagation();
if (((_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 ? void 0 : _window$getSelection.toString().length) === 0 && lastSelection) {
setLastCopiedSelection(cloneDeep(lastSelection));
}
}
}
export function handleCut(e, lastSelection, setLastCopiedSelection) {
if (!isWrappedWithClass(e, 'noflow')) {
var _window$getSelection2;
e.preventDefault();
e.stopImmediatePropagation();
if (((_window$getSelection2 = window.getSelection()) === null || _window$getSelection2 === void 0 ? void 0 : _window$getSelection2.toString().length) === 0 && lastSelection) {
setLastCopiedSelection(cloneDeep(lastSelection), true);
}
}
}
export function handlePaste(e, lastCopiedSelection, takeSnapshot, paste, position) {
if (!isWrappedWithClass(e, 'noflow')) {
var _window$getSelection3;
e.preventDefault();
e.stopImmediatePropagation();
if (((_window$getSelection3 = window.getSelection()) === null || _window$getSelection3 === void 0 ? void 0 : _window$getSelection3.toString().length) === 0 && lastCopiedSelection) {
takeSnapshot();
paste(lastCopiedSelection, {
x: position.current.x,
y: position.current.y
});
}
}
}
export function handleDelete(e, lastSelection, deleteNode, deleteEdge, takeSnapshot) {
if (!isWrappedWithClass(e, 'nodelete') && lastSelection) {
e.preventDefault();
e.stopImmediatePropagation();
takeSnapshot();
deleteNode(lastSelection.nodes.map(function (node) {
return node.id;
}));
deleteEdge(lastSelection.edges.map(function (edge) {
return edge.id;
}));
}
}