@rkmodules/rules 0.0.144 → 0.0.146

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
@@ -609,9 +609,14 @@ function getValue$1(obj, path) {
609
609
  return;
610
610
  }
611
611
  var parts = path.split(".");
612
- var value = obj[parts.shift() || ""];
613
- while (parts.length && value) {
614
- value = value[parts.shift() || ""];
612
+ var key = parts.shift() || "";
613
+ var safeObj = Object.fromEntries(Object.entries(obj).map(function (_a) {
614
+ var _b = __read(_a, 2), k = _b[0], v = _b[1];
615
+ return [safeName(k), v];
616
+ }));
617
+ var value = safeObj[key];
618
+ if (parts.length) {
619
+ return getValue$1(value, parts.join("."));
615
620
  }
616
621
  return value;
617
622
  }
@@ -2577,7 +2582,6 @@ var explodeObject = {
2577
2582
  var _b = __read(_a, 2), key = _b[0], value = _b[1];
2578
2583
  if (key[0] === "_")
2579
2584
  return;
2580
- key = safeName(key);
2581
2585
  if (!outputs[key]) {
2582
2586
  outputs[key] = {};
2583
2587
  }
@@ -6294,13 +6298,14 @@ var Input = function (_a) {
6294
6298
  var normalized = normalizeVarDef(varDef);
6295
6299
  var value = (_b = data.inputs) === null || _b === void 0 ? void 0 : _b[name];
6296
6300
  var isRef = isReference(value);
6301
+ var portId = "".concat(id, "-").concat(safeName(name));
6297
6302
  var handleInputChange = function (param) { return function (value) {
6298
6303
  var _a;
6299
6304
  data.onChange({
6300
6305
  inputs: __assign(__assign({}, data.inputs), (_a = {}, _a[param] = value, _a)),
6301
6306
  });
6302
6307
  }; };
6303
- return (React.createElement(react.Handle, { type: "target", position: react.Position.Left, id: "".concat(id, "-").concat(name), className: classNames(styles$1.Input, styles$1.Port, styles$1["type-".concat(normalized.type)]), style: {
6308
+ return (React.createElement(react.Handle, { type: "target", position: react.Position.Left, id: portId, className: classNames(styles$1.Input, styles$1.Port, styles$1["type-".concat(normalized.type)]), style: {
6304
6309
  "--type-color": "var(--color-".concat(normalized.type, ")"),
6305
6310
  }, onClick: onClick },
6306
6311
  React.createElement("span", { className: styles$1.PortLabel }, normalized.label || name),
@@ -6329,7 +6334,8 @@ var Param = function (_a) {
6329
6334
  var Output = function (_a) {
6330
6335
  var name = _a.name, varDef = _a.varDef, id = _a.id, onClick = _a.onClick, focus = _a.focus;
6331
6336
  var normalized = normalizeVarDef(varDef);
6332
- return (React.createElement(react.Handle, { type: "source", position: react.Position.Right, id: "".concat(id, "-").concat(name), className: classNames(styles$1.Output, styles$1.Port, styles$1["type-".concat(normalized.type)]), style: {
6337
+ var portId = "".concat(id, "-").concat(safeName(name));
6338
+ return (React.createElement(react.Handle, { type: "source", position: react.Position.Right, id: portId, className: classNames(styles$1.Output, styles$1.Port, styles$1["type-".concat(normalized.type)]), style: {
6333
6339
  "--type-color": "var(--color-".concat(normalized.type, ")"),
6334
6340
  }, onClick: onClick },
6335
6341
  React.createElement("span", { className: styles$1.PortLabel },
@@ -6511,9 +6517,9 @@ function GenericNode(_a) {
6511
6517
  var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6512
6518
  return (React.createElement(Param, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data }));
6513
6519
  })),
6514
- React.createElement("div", { className: classNames(styles.PreviewHead, (_b = {},
6520
+ !!outputEntries.length && (React.createElement("div", { className: classNames(styles.PreviewHead, (_b = {},
6515
6521
  _b[styles.expanded] = showPreview,
6516
- _b)), onClick: function () { return setShowPreview(!showPreview); } }, "Preview"),
6522
+ _b)), onClick: function () { return setShowPreview(!showPreview); } }, "Preview")),
6517
6523
  showPreview && (React.createElement("div", { className: styles.Preview },
6518
6524
  React.createElement(TreeView, { value: previewValue }),
6519
6525
  duration !== null && (React.createElement("div", { className: styles.Duration },
@@ -6738,10 +6744,29 @@ DynamicInput.displayName = "DynamicInputNode";
6738
6744
  * - create input node
6739
6745
  */
6740
6746
  var OutputNode = React.memo(function (_a) {
6747
+ var _b;
6748
+ var _c;
6741
6749
  var id = _a.id, data = _a.data, selected = _a.selected;
6742
6750
  var engine = useEngine();
6743
6751
  var fn = useGraphedFunction();
6744
6752
  var prompt = usePrompts().prompt;
6753
+ // const inputEntries = Object.entries(inputs || data.inputDefs || {});
6754
+ var outputEntries = Object.entries(data.outputDefs || {});
6755
+ var paramEntries = Object.entries(data.paramDefs || {});
6756
+ var _d = __read(React.useState({}), 2), result = _d[0], setResult = _d[1];
6757
+ var _e = __read(React.useState(null), 2), duration = _e[0], setDuration = _e[1];
6758
+ var _f = __read(useInner(((_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0]) || null, [data.outputDefs]), 2), focus = _f[0], setFocus = _f[1];
6759
+ var _g = __read(React.useState(false), 2), showPreview = _g[0], setShowPreview = _g[1];
6760
+ var previewValue = focus ? result[focus] : Object.values(result)[0];
6761
+ React.useEffect(function () {
6762
+ return engine.subscribe("functionResult", function (event) {
6763
+ var _a;
6764
+ if (event.name === id) {
6765
+ setResult(event.result || {});
6766
+ setDuration((_a = event.duration) !== null && _a !== void 0 ? _a : null);
6767
+ }
6768
+ });
6769
+ }, []);
6745
6770
  var inputs = Object.fromEntries(Object.entries(data.inputs || {}).map(function (_a, i) {
6746
6771
  var _b, _c;
6747
6772
  var _d = __read(_a, 2), name = _d[0], ref = _d[1];
@@ -6786,6 +6811,8 @@ var OutputNode = React.memo(function (_a) {
6786
6811
  }
6787
6812
  });
6788
6813
  }); };
6814
+ // TODO: this seems specifically for the output node only, adjusting the main rule IO spec,
6815
+ // we need to change the current function spec instead
6789
6816
  var onAdd = function () { return __awaiter(void 0, void 0, void 0, function () {
6790
6817
  var newName;
6791
6818
  var _a;
@@ -6805,6 +6832,8 @@ var OutputNode = React.memo(function (_a) {
6805
6832
  }
6806
6833
  });
6807
6834
  }); };
6835
+ // TODO: this seems specifically for the output node only, adjusting the main rule IO spec,
6836
+ // we need to change the current function spec instead
6808
6837
  var onDelete = function (name) {
6809
6838
  var _a;
6810
6839
  (_a = data.onIOChange) === null || _a === void 0 ? void 0 : _a.call(data, function (fn) {
@@ -6815,20 +6844,37 @@ var OutputNode = React.memo(function (_a) {
6815
6844
  };
6816
6845
  return (React.createElement(NodeContainer, { label: data.label, selected: selected, id: id, noDelete: true },
6817
6846
  React.createElement("div", { className: styles.Description }, data.description),
6818
- React.createElement("div", { className: styles.Ports }, Object.entries(inputs || {}).map(function (_a) {
6819
- var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6820
- return (React.createElement(react.Handle, { key: name, type: "target", position: react.Position.Left, id: "".concat(id, "-").concat(name), className: classNames(styles$1.Input, styles$1.Port, styles$1["type-".concat(varDef.type)]), style: {
6821
- "--type-color": "var(--color-".concat(varDef.type, ")"),
6822
- } },
6823
- React.createElement("span", { className: styles$1.PortLabel }, name),
6824
- React.createElement("div", { style: { display: "flex" } },
6825
- React.createElement("span", { style: { flex: 1 } }),
6826
- React.createElement(Menu, { handle: React.createElement("button", null, "...") },
6827
- React.createElement(MenuItem, { onClick: function () { return onRename(name); } }, "Rename"),
6828
- React.createElement(MenuItem, { onClick: function () { return onDelete(name); } }, "Delete")))));
6829
- })),
6847
+ React.createElement("div", { className: styles.Ports },
6848
+ outputEntries.map(function (_a, index) {
6849
+ var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6850
+ return (React.createElement(Output, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, onClick: function () { return setFocus(name); }, focus: showPreview && focus === name }));
6851
+ }),
6852
+ Object.entries(inputs || {}).map(function (_a) {
6853
+ var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6854
+ return (React.createElement(react.Handle, { key: name, type: "target", position: react.Position.Left, id: "".concat(id, "-").concat(name), className: classNames(styles$1.Input, styles$1.Port, styles$1["type-".concat(varDef.type)]), style: {
6855
+ "--type-color": "var(--color-".concat(varDef.type, ")"),
6856
+ } },
6857
+ React.createElement("span", { className: styles$1.PortLabel }, name),
6858
+ React.createElement("div", { style: { display: "flex" } },
6859
+ React.createElement("span", { style: { flex: 1 } }),
6860
+ React.createElement(Menu, { handle: React.createElement("button", null, "...") },
6861
+ React.createElement(MenuItem, { onClick: function () { return onRename(name); } }, "Rename"),
6862
+ React.createElement(MenuItem, { onClick: function () { return onDelete(name); } }, "Delete")))));
6863
+ }),
6864
+ paramEntries.map(function (_a, index) {
6865
+ var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6866
+ return (React.createElement(Param, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data }));
6867
+ })),
6830
6868
  React.createElement("div", { className: styles.Body },
6831
- React.createElement("button", { onClick: function () { return onAdd(); } }, "+"))));
6869
+ React.createElement("button", { onClick: function () { return onAdd(); } }, "+")),
6870
+ !!outputEntries.length && (React.createElement("div", { className: classNames(styles.PreviewHead, (_b = {},
6871
+ _b[styles.expanded] = showPreview,
6872
+ _b)), onClick: function () { return setShowPreview(!showPreview); } }, "Preview")),
6873
+ showPreview && (React.createElement("div", { className: styles.Preview },
6874
+ React.createElement(TreeView, { value: previewValue }),
6875
+ duration !== null && (React.createElement("div", { className: styles.Duration },
6876
+ duration.toFixed(2),
6877
+ " ms"))))));
6832
6878
  });
6833
6879
  OutputNode.displayName = "OutputNode";
6834
6880
 
@@ -6841,7 +6887,7 @@ var DynamicOutput = React.memo(function (_a) {
6841
6887
  if (event.name === id) {
6842
6888
  var result = event.result || {};
6843
6889
  setOutputs(Object.fromEntries(Object.keys(result).map(function (name, i) { return [
6844
- safeName(name),
6890
+ name,
6845
6891
  { type: "any", label: name },
6846
6892
  ]; })));
6847
6893
  }
@@ -6947,9 +6993,9 @@ function updateNodeArguments(node, inputs, params) {
6947
6993
  * returns an object with the source node id, target node id, source field name and target field name
6948
6994
  */
6949
6995
  function deRefEdgeHandle(handle) {
6950
- var match = handle.match(/^(.+)-(.+)$/);
6996
+ var match = handle.match(/^(.+?)-(.+)$/);
6951
6997
  if (!match) {
6952
- throw new Error("Invalid handle format");
6998
+ throw new Error("Invalid handle format" + handle);
6953
6999
  }
6954
7000
  return { node: match[1], field: match[2] };
6955
7001
  }
@@ -6981,8 +7027,8 @@ function createEdge(nodeId, ref) {
6981
7027
  id: "".concat(ref.path, "-").concat(nodeId, ".").concat(ref.name),
6982
7028
  source: ref.refNode,
6983
7029
  target: nodeId,
6984
- sourceHandle: "".concat(ref.refNode, "-").concat(ref.refField),
6985
- targetHandle: "".concat(nodeId, "-").concat(ref.name),
7030
+ sourceHandle: "".concat(ref.refNode, "-").concat(safeName(ref.refField)),
7031
+ targetHandle: "".concat(nodeId, "-").concat(safeName(ref.name)),
6986
7032
  };
6987
7033
  }
6988
7034
  /**