@rkmodules/rules 0.0.162 → 0.0.164

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -587,6 +587,30 @@ function mergeTrees() {
587
587
  return out;
588
588
  }
589
589
 
590
+ function mergeWithOrder() {
591
+ var objects = [];
592
+ for (var _i = 0; _i < arguments.length; _i++) {
593
+ objects[_i] = arguments[_i];
594
+ }
595
+ var merged = {};
596
+ var keys = [];
597
+ objects.forEach(function (obj) {
598
+ Object.keys(obj).forEach(function (key) {
599
+ if (!keys.includes(key)) {
600
+ keys.push(key);
601
+ }
602
+ });
603
+ });
604
+ keys.forEach(function (key) {
605
+ for (var i = objects.length - 1; i >= 0; i--) {
606
+ if (key in objects[i]) {
607
+ merged[key] = objects[i][key];
608
+ break;
609
+ }
610
+ }
611
+ });
612
+ return merged;
613
+ }
590
614
  function isReference(value) {
591
615
  return (typeof value === "string" && !!value.match(/^<([\w\.]+)>$/)
592
616
  // value.startsWith("<") &&
@@ -7057,16 +7081,22 @@ OutputNode.displayName = "OutputNode";
7057
7081
 
7058
7082
  var DynamicOutput = React.memo(function (_a) {
7059
7083
  var id = _a.id, data = _a.data, selected = _a.selected;
7060
- var _b = __read(React.useState({}), 2), outputs = _b[0], setOutputs = _b[1];
7084
+ var outputDefs = data.outputDefs || {};
7085
+ Object.keys(data.outputs || {}).forEach(function (key) {
7086
+ if (!outputDefs[key]) {
7087
+ outputDefs[key] = { type: "any", label: key };
7088
+ }
7089
+ });
7090
+ var _b = __read(React.useState(outputDefs), 2), outputs = _b[0], setOutputs = _b[1];
7061
7091
  var engine = useEngine();
7062
7092
  React.useEffect(function () {
7063
7093
  return engine.subscribe("functionResult", function (event) {
7064
7094
  if (event.name === id) {
7065
7095
  var result = event.result || {};
7066
- setOutputs(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7096
+ setOutputs(mergeWithOrder(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7067
7097
  name,
7068
7098
  { type: "any", label: name },
7069
- ]; })));
7099
+ ]; })), outputs));
7070
7100
  }
7071
7101
  });
7072
7102
  }, []);
@@ -7293,6 +7323,7 @@ function createNode(engine, id, fncall, options) {
7293
7323
  description: calledFn === null || calledFn === void 0 ? void 0 : calledFn.description,
7294
7324
  inputs: fncall.inputs,
7295
7325
  params: fncall.params,
7326
+ outputs: {},
7296
7327
  inputDefs: __assign(__assign({}, fncall.inputDefs), calledFn === null || calledFn === void 0 ? void 0 : calledFn.inputs),
7297
7328
  paramDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.params) || {},
7298
7329
  outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
@@ -7314,6 +7345,16 @@ function createEdge(nodeId, ref) {
7314
7345
  targetHandle: "".concat(nodeId, "-").concat(safeName(ref.name)),
7315
7346
  };
7316
7347
  }
7348
+ function addOutputToNode(nodes, ref, targetId) {
7349
+ var _a;
7350
+ var node = nodes[ref.refNode];
7351
+ if (!node) {
7352
+ console.warn("Node not found: " + ref.refNode);
7353
+ console.log(nodes, ref, targetId);
7354
+ return;
7355
+ }
7356
+ node.data.outputs = __assign(__assign({}, node.data.outputs), (_a = {}, _a[ref.refField] = "".concat(targetId, ".").concat(ref.name), _a));
7357
+ }
7317
7358
  /**
7318
7359
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
7319
7360
  * using setFn
@@ -7344,6 +7385,7 @@ var useFlowState = create$1(function (set, get) { return ({
7344
7385
  }
7345
7386
  var oldKeys = Object.keys((oldFn === null || oldFn === void 0 ? void 0 : oldFn.body) || {});
7346
7387
  var newKeys = Object.keys(fn.body || {});
7388
+ var edgesToAdd = [];
7347
7389
  // remove all the nodes that were removed
7348
7390
  Object.keys(nodes).forEach(function (key) {
7349
7391
  if (!newKeys.includes(key)) {
@@ -7375,7 +7417,7 @@ var useFlowState = create$1(function (set, get) { return ({
7375
7417
  // add edges
7376
7418
  var refs = getReferences(fncall.inputs || {});
7377
7419
  refs.forEach(function (ref) {
7378
- edges.push(createEdge(key_1, ref));
7420
+ edgesToAdd.push([key_1, ref]);
7379
7421
  });
7380
7422
  }
7381
7423
  // make sure there is an input node if inputs are defined
@@ -7400,7 +7442,7 @@ var useFlowState = create$1(function (set, get) { return ({
7400
7442
  // add edges
7401
7443
  var refs = getReferences(fncall.inputs || {});
7402
7444
  refs.forEach(function (ref) {
7403
- edges.push(createEdge(key, ref));
7445
+ edgesToAdd.push([key, ref]);
7404
7446
  });
7405
7447
  });
7406
7448
  // update the changed nodes
@@ -7422,9 +7464,14 @@ var useFlowState = create$1(function (set, get) { return ({
7422
7464
  edges = edges === null || edges === void 0 ? void 0 : edges.filter(function (e) { return e.target !== key; });
7423
7465
  // add the edge
7424
7466
  refs.forEach(function (ref) {
7425
- edges.push(createEdge(key, ref));
7467
+ edgesToAdd.push([key, ref]);
7426
7468
  });
7427
7469
  });
7470
+ edgesToAdd.forEach(function (_a) {
7471
+ var _b = __read(_a, 2), nodeId = _b[0], ref = _b[1];
7472
+ edges.push(createEdge(nodeId, ref));
7473
+ addOutputToNode(nodes, ref, nodeId);
7474
+ });
7428
7475
  // console.log("final graph", nodes, edges);
7429
7476
  // update the function, nodes and edges
7430
7477
  set({ fn: fn, nodes: nodes, edges: edges });
@@ -7489,7 +7536,7 @@ var ConnectionLine = (function (_a) {
7489
7536
  */
7490
7537
  var emptyObject = {};
7491
7538
  function FlowInner(_a) {
7492
- var fn = _a.function, _b = _a.positions, defaultPositions = _b === void 0 ? emptyObject : _b, engine = _a.engine, _c = _a.center, center = _c === void 0 ? true : _c, fitView = _a.fitView, _d = _a.customNodes, customNodes = _d === void 0 ? {} : _d, onChange = _a.onChange, onClick = _a.onClick, onContextMenu = _a.onContextMenu, onSelect = _a.onSelect, onInit = _a.onInit;
7539
+ var fn = _a.function, _b = _a.positions, defaultPositions = _b === void 0 ? emptyObject : _b, engine = _a.engine, _c = _a.center, center = _c === void 0 ? true : _c, fitView = _a.fitView, _d = _a.customNodes, customNodes = _d === void 0 ? {} : _d, onChange = _a.onChange, onClick = _a.onClick, onContextMenu = _a.onContextMenu, onMouseMove = _a.onMouseMove, onSelect = _a.onSelect, onInit = _a.onInit;
7493
7540
  var _e = __read(React.useState(null), 2), instance = _e[0], setInstance = _e[1];
7494
7541
  var handleInit = function (instance) {
7495
7542
  setInstance(instance);
@@ -7593,21 +7640,30 @@ function FlowInner(_a) {
7593
7640
  }, [onChange, fn]);
7594
7641
  // handle canvas clicks to be able to place nodes
7595
7642
  var handleClick = function (e) {
7596
- if (instance) {
7643
+ if (instance && onClick) {
7597
7644
  var position = instance.screenToFlowPosition({
7598
7645
  x: e.clientX,
7599
7646
  y: e.clientY,
7600
7647
  });
7601
- onClick === null || onClick === void 0 ? void 0 : onClick(e, position);
7648
+ onClick(e, position);
7602
7649
  }
7603
7650
  };
7604
7651
  var handleContextMenu = function (e) {
7605
- if (instance) {
7652
+ if (instance && onContextMenu) {
7653
+ var position = instance.screenToFlowPosition({
7654
+ x: e.clientX,
7655
+ y: e.clientY,
7656
+ });
7657
+ onContextMenu(e, position);
7658
+ }
7659
+ };
7660
+ var handleMouseMove = function (e) {
7661
+ if (instance && onMouseMove) {
7606
7662
  var position = instance.screenToFlowPosition({
7607
7663
  x: e.clientX,
7608
7664
  y: e.clientY,
7609
7665
  });
7610
- onContextMenu === null || onContextMenu === void 0 ? void 0 : onContextMenu(e, position);
7666
+ onMouseMove(e, position);
7611
7667
  }
7612
7668
  };
7613
7669
  var onNodesChange = React.useCallback(function (changes) {
@@ -7630,7 +7686,7 @@ function FlowInner(_a) {
7630
7686
  return applyEdgeChanges(changes, edgesSnapshot);
7631
7687
  });
7632
7688
  }, []);
7633
- return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: __assign(__assign({}, nodeTypes), customNodes), onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: handleInit, onPaneClick: handleClick, onPaneContextMenu: handleContextMenu, fitView: center || fitView, fitViewOptions: {
7689
+ return (React.createElement(ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: __assign(__assign({}, nodeTypes), customNodes), onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: handleInit, onPaneClick: handleClick, onPaneContextMenu: handleContextMenu, onPaneMouseMove: handleMouseMove, fitView: center || fitView, fitViewOptions: {
7634
7690
  minZoom: fitView ? undefined : 1,
7635
7691
  maxZoom: fitView ? undefined : 1,
7636
7692
  },
@@ -8686,5 +8742,5 @@ function DDContext(_a) {
8686
8742
  return React.createElement(DndProvider, { backend: HTML5Backend }, children);
8687
8743
  }
8688
8744
 
8689
- export { DDContext, DISCARD, Engine, Flow, FlowContext, GenericNode, Input, InputBoolean, InputNumber, InputSelect, InputString, InputText, Lib, Output, Param, binaryOnTree, binaryOnTreeBranch, broadCast, deRefEdgeHandle, ensureBranch, expandTree, forEachBranch, forEachItem, getBranch, getBranches, getItem, getPaths, getPositions, getReferences, getValue$1 as getValue, getVariable, graftTree, hasReference, interpolate, isEmpty, isEmptyTree, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, nAryOnTree, nAryOnTreeBranch, normalizePaths, normalizeVarDef, parseReference, primitives, pushItem, safeName, sameShape, simplifyTree$1 as simplifyTree, toArray, topSort, treeSize, treeStats, trimTree, uid$1 as uid, useControls, useDraggableNode, useEngine, useFlow, useFunction, useGraphedFunction, usePositions, usePrompts, useUpdatePositions, useVariable, variableStore };
8745
+ export { DDContext, DISCARD, Engine, Flow, FlowContext, GenericNode, Input, InputBoolean, InputNumber, InputSelect, InputString, InputText, Lib, Output, Param, binaryOnTree, binaryOnTreeBranch, broadCast, deRefEdgeHandle, ensureBranch, expandTree, forEachBranch, forEachItem, getBranch, getBranches, getItem, getPaths, getPositions, getReferences, getValue$1 as getValue, getVariable, graftTree, hasReference, interpolate, isEmpty, isEmptyTree, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, mergeWithOrder, nAryOnTree, nAryOnTreeBranch, normalizePaths, normalizeVarDef, parseReference, primitives, pushItem, safeName, sameShape, simplifyTree$1 as simplifyTree, toArray, topSort, treeSize, treeStats, trimTree, uid$1 as uid, useControls, useDraggableNode, useEngine, useFlow, useFunction, useGraphedFunction, usePositions, usePrompts, useUpdatePositions, useVariable, variableStore };
8690
8746
  //# sourceMappingURL=index.esm.mjs.map