UNPKG

@eccenca/gui-elements

Version:

GUI elements based on other libraries, usable in React application, written in Typescript.

135 lines 7.16 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React from "react"; import { CLASSPREFIX as eccgui } from "../../../configuration/constants.js"; import { ReactFlowMarkers } from "../../../extensions/react-flow/markers/ReactFlowMarkers.js"; import { ReactFlowVersions } from "../../../extensions/react-flow/versionsupport.js"; import { ReactFlowHotkeyContext } from "../extensions/ReactFlowHotkeyContext.js"; import { useReactFlowScrollOnDragV9 } from "../extensions/scrollOnDragHook.js"; import * as graphConfig from "./../configuration/graph.js"; import * as linkingConfig from "./../configuration/linking.js"; import * as unspecifiedConfig from "./../configuration/unspecified.js"; import * as workflowConfig from "./../configuration/workflow.js"; import { ReactFlowV9Container } from "./ReactFlowV9.js"; import { ReactFlowV12Container } from "./ReactFlowV12.js"; /** * `ReactFlow` container extension that includes pre-configured nodes and edges for * Corporate Memory tools. * * @param T The concrete type of the corresponding version, i.e. either one of ReactFlowExtendedPropsV9 or ReactFlowExtendedPropsV12 */ var ReactFlowExtendedPlain = function (_a, outerRef) { var _b = _a.configuration, configuration = _b === void 0 ? "unspecified" : _b, _c = _a.flowVersion, flowVersion = _c === void 0 ? ReactFlowVersions.V9 : _c, dropzoneFor = _a.dropzoneFor, scrollOnDrag = _a.scrollOnDrag, children = _a.children, className = _a.className, selectionKeyCode = _a.selectionKeyCode, multiSelectionKeyCode = _a.multiSelectionKeyCode, deleteKeyCode = _a.deleteKeyCode, zoomActivationKeyCode = _a.zoomActivationKeyCode, originalProps = __rest(_a, ["configuration", "flowVersion", "dropzoneFor", "scrollOnDrag", "children", "className", "selectionKeyCode", "multiSelectionKeyCode", "deleteKeyCode", "zoomActivationKeyCode"]); var innerRef = React.useRef(null); React.useImperativeHandle(outerRef, function () { return innerRef.current; }, []); React.useEffect(function () { var reactflowContainer = innerRef === null || innerRef === void 0 ? void 0 : innerRef.current; if (reactflowContainer && dropzoneFor) { var addDragover_1 = function (event) { reactflowContainer.classList.add("".concat(eccgui, "-graphviz__canvas--draghover")); event.preventDefault(); }; var removeDragover_1 = function (event) { if (reactflowContainer === event.target) { reactflowContainer.classList.remove("".concat(eccgui, "-graphviz__canvas--draghover")); } }; reactflowContainer.addEventListener("dragover", addDragover_1); reactflowContainer.addEventListener("dragleave", removeDragover_1); reactflowContainer.addEventListener("drop", removeDragover_1); return function () { reactflowContainer.removeEventListener("dragover", addDragover_1); reactflowContainer.removeEventListener("dragleave", removeDragover_1); reactflowContainer.removeEventListener("drop", removeDragover_1); }; } return; }, [innerRef, dropzoneFor]); /** If the hot keys should be disabled. By default, they are always disabled. */ var hotKeysDisabled = React.useContext(ReactFlowHotkeyContext).hotKeysDisabled; var configReactFlow = { unspecified: unspecifiedConfig, graph: graphConfig, workflow: workflowConfig, linking: linkingConfig, }; var sharedProperties = { className: "".concat(eccgui, "-graphviz__canvas") + " ".concat(eccgui, "-configuration--colors__react-flow-").concat(configuration) + (className ? " ".concat(className) : ""), nodeTypes: configReactFlow[configuration].nodeTypes, edgeTypes: configReactFlow[configuration].edgeTypes, "data-dropzone-for": dropzoneFor ? dropzoneFor.join(" ") : undefined, }; var keyCodeConfig = {}; switch (flowVersion) { case "v9": keyCodeConfig = { selectionKeyCode: hotKeysDisabled ? undefined : selectionKeyCode, deleteKeyCode: hotKeysDisabled ? undefined : deleteKeyCode, multiSelectionKeyCode: hotKeysDisabled ? undefined : multiSelectionKeyCode, zoomActivationKeyCode: hotKeysDisabled ? undefined : zoomActivationKeyCode, }; break; case "v12": keyCodeConfig = { selectionKeyCode: hotKeysDisabled ? null : selectionKeyCode, deleteKeyCode: hotKeysDisabled ? null : deleteKeyCode, multiSelectionKeyCode: hotKeysDisabled ? null : multiSelectionKeyCode, zoomActivationKeyCode: hotKeysDisabled ? null : zoomActivationKeyCode, }; break; } var scrollOnDragFunctions = {}; switch (flowVersion) { case "v9": scrollOnDragFunctions = useReactFlowScrollOnDragV9({ reactFlowProps: originalProps, scrollOnDrag: scrollOnDrag, }); break; // should not be necessary for v12 } var containerConfig = __assign(__assign(__assign(__assign({}, sharedProperties), keyCodeConfig), originalProps), scrollOnDragFunctions); switch (flowVersion) { case "v9": return (React.createElement(ReactFlowV9Container, __assign({ ref: innerRef }, containerConfig), children, React.createElement(ReactFlowMarkers, null))); case "v12": return (React.createElement(ReactFlowV12Container, __assign({ ref: innerRef }, containerConfig), children, React.createElement(ReactFlowMarkers, null))); default: return React.createElement("div", null); } }; /** Hack to make the Type Parameter work with the forward ref. */ export var ReactFlowExtended = React.forwardRef(ReactFlowExtendedPlain); /** * @deprecated (v26) use `ReactFlowExtended` */ export var ReactFlow = ReactFlowExtended; /** Classes that when set for an element, prevent that they trigger react-flow dragging, wheel and panning actions. */ export var preventReactFlowActionsClasses = "nodrag nopan nowheel"; //# sourceMappingURL=ReactFlow.js.map