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