@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.
package/dist/index.cjs.js CHANGED
@@ -589,6 +589,30 @@ function mergeTrees() {
589
589
  return out;
590
590
  }
591
591
 
592
+ function mergeWithOrder() {
593
+ var objects = [];
594
+ for (var _i = 0; _i < arguments.length; _i++) {
595
+ objects[_i] = arguments[_i];
596
+ }
597
+ var merged = {};
598
+ var keys = [];
599
+ objects.forEach(function (obj) {
600
+ Object.keys(obj).forEach(function (key) {
601
+ if (!keys.includes(key)) {
602
+ keys.push(key);
603
+ }
604
+ });
605
+ });
606
+ keys.forEach(function (key) {
607
+ for (var i = objects.length - 1; i >= 0; i--) {
608
+ if (key in objects[i]) {
609
+ merged[key] = objects[i][key];
610
+ break;
611
+ }
612
+ }
613
+ });
614
+ return merged;
615
+ }
592
616
  function isReference(value) {
593
617
  return (typeof value === "string" && !!value.match(/^<([\w\.]+)>$/)
594
618
  // value.startsWith("<") &&
@@ -7059,16 +7083,22 @@ OutputNode.displayName = "OutputNode";
7059
7083
 
7060
7084
  var DynamicOutput = React.memo(function (_a) {
7061
7085
  var id = _a.id, data = _a.data, selected = _a.selected;
7062
- var _b = __read(React.useState({}), 2), outputs = _b[0], setOutputs = _b[1];
7086
+ var outputDefs = data.outputDefs || {};
7087
+ Object.keys(data.outputs || {}).forEach(function (key) {
7088
+ if (!outputDefs[key]) {
7089
+ outputDefs[key] = { type: "any", label: key };
7090
+ }
7091
+ });
7092
+ var _b = __read(React.useState(outputDefs), 2), outputs = _b[0], setOutputs = _b[1];
7063
7093
  var engine = useEngine();
7064
7094
  React.useEffect(function () {
7065
7095
  return engine.subscribe("functionResult", function (event) {
7066
7096
  if (event.name === id) {
7067
7097
  var result = event.result || {};
7068
- setOutputs(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7098
+ setOutputs(mergeWithOrder(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
7069
7099
  name,
7070
7100
  { type: "any", label: name },
7071
- ]; })));
7101
+ ]; })), outputs));
7072
7102
  }
7073
7103
  });
7074
7104
  }, []);
@@ -7295,6 +7325,7 @@ function createNode(engine, id, fncall, options) {
7295
7325
  description: calledFn === null || calledFn === void 0 ? void 0 : calledFn.description,
7296
7326
  inputs: fncall.inputs,
7297
7327
  params: fncall.params,
7328
+ outputs: {},
7298
7329
  inputDefs: __assign(__assign({}, fncall.inputDefs), calledFn === null || calledFn === void 0 ? void 0 : calledFn.inputs),
7299
7330
  paramDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.params) || {},
7300
7331
  outputDefs: (calledFn === null || calledFn === void 0 ? void 0 : calledFn.outputs) || {},
@@ -7316,6 +7347,16 @@ function createEdge(nodeId, ref) {
7316
7347
  targetHandle: "".concat(nodeId, "-").concat(safeName(ref.name)),
7317
7348
  };
7318
7349
  }
7350
+ function addOutputToNode(nodes, ref, targetId) {
7351
+ var _a;
7352
+ var node = nodes[ref.refNode];
7353
+ if (!node) {
7354
+ console.warn("Node not found: " + ref.refNode);
7355
+ console.log(nodes, ref, targetId);
7356
+ return;
7357
+ }
7358
+ node.data.outputs = __assign(__assign({}, node.data.outputs), (_a = {}, _a[ref.refField] = "".concat(targetId, ".").concat(ref.name), _a));
7359
+ }
7319
7360
  /**
7320
7361
  * flow state stores nodes and edges for the flow graph these can be updated when the function changes
7321
7362
  * using setFn
@@ -7346,6 +7387,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7346
7387
  }
7347
7388
  var oldKeys = Object.keys((oldFn === null || oldFn === void 0 ? void 0 : oldFn.body) || {});
7348
7389
  var newKeys = Object.keys(fn.body || {});
7390
+ var edgesToAdd = [];
7349
7391
  // remove all the nodes that were removed
7350
7392
  Object.keys(nodes).forEach(function (key) {
7351
7393
  if (!newKeys.includes(key)) {
@@ -7377,7 +7419,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7377
7419
  // add edges
7378
7420
  var refs = getReferences(fncall.inputs || {});
7379
7421
  refs.forEach(function (ref) {
7380
- edges.push(createEdge(key_1, ref));
7422
+ edgesToAdd.push([key_1, ref]);
7381
7423
  });
7382
7424
  }
7383
7425
  // make sure there is an input node if inputs are defined
@@ -7402,7 +7444,7 @@ var useFlowState = zustand.create(function (set, get) { return ({
7402
7444
  // add edges
7403
7445
  var refs = getReferences(fncall.inputs || {});
7404
7446
  refs.forEach(function (ref) {
7405
- edges.push(createEdge(key, ref));
7447
+ edgesToAdd.push([key, ref]);
7406
7448
  });
7407
7449
  });
7408
7450
  // update the changed nodes
@@ -7424,9 +7466,14 @@ var useFlowState = zustand.create(function (set, get) { return ({
7424
7466
  edges = edges === null || edges === void 0 ? void 0 : edges.filter(function (e) { return e.target !== key; });
7425
7467
  // add the edge
7426
7468
  refs.forEach(function (ref) {
7427
- edges.push(createEdge(key, ref));
7469
+ edgesToAdd.push([key, ref]);
7428
7470
  });
7429
7471
  });
7472
+ edgesToAdd.forEach(function (_a) {
7473
+ var _b = __read(_a, 2), nodeId = _b[0], ref = _b[1];
7474
+ edges.push(createEdge(nodeId, ref));
7475
+ addOutputToNode(nodes, ref, nodeId);
7476
+ });
7430
7477
  // console.log("final graph", nodes, edges);
7431
7478
  // update the function, nodes and edges
7432
7479
  set({ fn: fn, nodes: nodes, edges: edges });
@@ -7491,7 +7538,7 @@ var ConnectionLine = (function (_a) {
7491
7538
  */
7492
7539
  var emptyObject = {};
7493
7540
  function FlowInner(_a) {
7494
- 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;
7541
+ 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;
7495
7542
  var _e = __read(React.useState(null), 2), instance = _e[0], setInstance = _e[1];
7496
7543
  var handleInit = function (instance) {
7497
7544
  setInstance(instance);
@@ -7595,21 +7642,30 @@ function FlowInner(_a) {
7595
7642
  }, [onChange, fn]);
7596
7643
  // handle canvas clicks to be able to place nodes
7597
7644
  var handleClick = function (e) {
7598
- if (instance) {
7645
+ if (instance && onClick) {
7599
7646
  var position = instance.screenToFlowPosition({
7600
7647
  x: e.clientX,
7601
7648
  y: e.clientY,
7602
7649
  });
7603
- onClick === null || onClick === void 0 ? void 0 : onClick(e, position);
7650
+ onClick(e, position);
7604
7651
  }
7605
7652
  };
7606
7653
  var handleContextMenu = function (e) {
7607
- if (instance) {
7654
+ if (instance && onContextMenu) {
7655
+ var position = instance.screenToFlowPosition({
7656
+ x: e.clientX,
7657
+ y: e.clientY,
7658
+ });
7659
+ onContextMenu(e, position);
7660
+ }
7661
+ };
7662
+ var handleMouseMove = function (e) {
7663
+ if (instance && onMouseMove) {
7608
7664
  var position = instance.screenToFlowPosition({
7609
7665
  x: e.clientX,
7610
7666
  y: e.clientY,
7611
7667
  });
7612
- onContextMenu === null || onContextMenu === void 0 ? void 0 : onContextMenu(e, position);
7668
+ onMouseMove(e, position);
7613
7669
  }
7614
7670
  };
7615
7671
  var onNodesChange = React.useCallback(function (changes) {
@@ -7632,7 +7688,7 @@ function FlowInner(_a) {
7632
7688
  return react.applyEdgeChanges(changes, edgesSnapshot);
7633
7689
  });
7634
7690
  }, []);
7635
- return (React.createElement(react.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: {
7691
+ return (React.createElement(react.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: {
7636
7692
  minZoom: fitView ? undefined : 1,
7637
7693
  maxZoom: fitView ? undefined : 1,
7638
7694
  },
@@ -8729,6 +8785,7 @@ exports.isSingleTon = isSingleTon;
8729
8785
  exports.isTree = isTree;
8730
8786
  exports.mapTree = mapTree;
8731
8787
  exports.mapTreeBranch = mapTreeBranch;
8788
+ exports.mergeWithOrder = mergeWithOrder;
8732
8789
  exports.nAryOnTree = nAryOnTree;
8733
8790
  exports.nAryOnTreeBranch = nAryOnTreeBranch;
8734
8791
  exports.normalizePaths = normalizePaths;