@rkmodules/rules 0.0.118 → 0.0.120

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
@@ -5,8 +5,8 @@ var React = require('react');
5
5
  var react = require('@xyflow/react');
6
6
  var katex = require('katex');
7
7
  var classNames = require('classnames');
8
- var rcin = require('rc-input-number');
9
8
  var useInner = require('@rkmodules/use-inner');
9
+ var rcin = require('rc-input-number');
10
10
  var useLongPress = require('use-long-press');
11
11
  var zustand = require('zustand');
12
12
  var middleware = require('zustand/middleware');
@@ -1751,6 +1751,28 @@ var listInput = {
1751
1751
  }); },
1752
1752
  };
1753
1753
 
1754
+ var uniqueItems = {
1755
+ name: "uniqueItems",
1756
+ label: "Unique Items",
1757
+ description: "Removes duplicate items from a list",
1758
+ inputs: {
1759
+ items: "any",
1760
+ },
1761
+ outputs: {
1762
+ unique: "any",
1763
+ },
1764
+ impl: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
1765
+ var _c = _b.items, items = _c === void 0 ? {} : _c;
1766
+ return __generator(this, function (_d) {
1767
+ return [2 /*return*/, {
1768
+ unique: mapTreeBranch(items, function (items) {
1769
+ return Array.from(new Set(items));
1770
+ }),
1771
+ }];
1772
+ });
1773
+ }); },
1774
+ };
1775
+
1754
1776
  var _a$6;
1755
1777
  var primitives$6 = (_a$6 = {},
1756
1778
  _a$6[listInput.name] = listInput,
@@ -1760,6 +1782,7 @@ var primitives$6 = (_a$6 = {},
1760
1782
  _a$6[relativeItem.name] = relativeItem,
1761
1783
  _a$6[relativeItems.name] = relativeItems,
1762
1784
  _a$6[concat.name] = concat,
1785
+ _a$6[uniqueItems.name] = uniqueItems,
1763
1786
  _a$6);
1764
1787
 
1765
1788
  var splitGroup = {
@@ -2314,12 +2337,87 @@ var objectEntries = {
2314
2337
  }); },
2315
2338
  };
2316
2339
 
2340
+ var arrayToList = {
2341
+ name: "arrayToList",
2342
+ label: "Array to List",
2343
+ description: "Separates array",
2344
+ inputs: {
2345
+ items: "any",
2346
+ },
2347
+ params: {
2348
+ split: { type: "boolean", default: false, label: "split groups" },
2349
+ },
2350
+ outputs: {
2351
+ arrays: "any",
2352
+ },
2353
+ impl: function (_a, params_1) { return __awaiter(void 0, [_a, params_1], void 0, function (_b, params) {
2354
+ var _c = _b.items, items = _c === void 0 ? {} : _c;
2355
+ return __generator(this, function (_d) {
2356
+ if (params.split) {
2357
+ items = graftTree(items);
2358
+ }
2359
+ return [2 /*return*/, {
2360
+ arrays: mapTreeBranch(items, function (items) {
2361
+ return items.flat();
2362
+ }),
2363
+ }];
2364
+ });
2365
+ }); },
2366
+ };
2367
+
2368
+ var explodeObject = {
2369
+ name: "explodeObject",
2370
+ label: "Explode Object",
2371
+ description: "Separates all fields of an object",
2372
+ nodeType: "DynamicOutput",
2373
+ inputs: {
2374
+ object: "any",
2375
+ },
2376
+ params: {
2377
+ split: { type: "boolean", default: false, label: "split groups" },
2378
+ },
2379
+ outputs: {
2380
+ // values: "any",
2381
+ },
2382
+ impl: function (_a, params_1) { return __awaiter(void 0, [_a, params_1], void 0, function (_b, params) {
2383
+ var outputs;
2384
+ var _c = _b.object, object = _c === void 0 ? {} : _c;
2385
+ return __generator(this, function (_d) {
2386
+ outputs = {};
2387
+ if (params.split) {
2388
+ object = graftTree(object);
2389
+ }
2390
+ forEachBranch(object, function (branch, path) {
2391
+ branch.forEach(function (obj, index) {
2392
+ if (!obj)
2393
+ return;
2394
+ var props = obj || {};
2395
+ Object.entries(props).forEach(function (_a) {
2396
+ var _b = __read(_a, 2), key = _b[0], value = _b[1];
2397
+ if (key[0] === "_")
2398
+ return;
2399
+ if (!outputs[key]) {
2400
+ outputs[key] = {};
2401
+ }
2402
+ [].concat(value).forEach(function (v) {
2403
+ pushItem(outputs[key], path, v);
2404
+ });
2405
+ });
2406
+ });
2407
+ });
2408
+ return [2 /*return*/, outputs];
2409
+ });
2410
+ }); },
2411
+ };
2412
+
2317
2413
  var _a$1;
2318
2414
  var primitives$1 = (_a$1 = {},
2319
2415
  _a$1[object.name] = object,
2320
2416
  _a$1[listToArray.name] = listToArray,
2417
+ _a$1[arrayToList.name] = arrayToList,
2321
2418
  _a$1[mergeObject.name] = mergeObject,
2322
2419
  _a$1[objectEntries.name] = objectEntries,
2420
+ _a$1[explodeObject.name] = explodeObject,
2323
2421
  _a$1);
2324
2422
 
2325
2423
  var Lib = {
@@ -5656,11 +5754,11 @@ var InputText = React.memo(function (_a) {
5656
5754
  });
5657
5755
  function Control(_a) {
5658
5756
  var _b;
5659
- var value = _a.value, vardef = _a.vardef, onChange = _a.onChange;
5757
+ var value = _a.value, vardef = _a.vardef, data = _a.data, onChange = _a.onChange;
5660
5758
  var customControls = useControls();
5661
5759
  if (vardef.type in customControls) {
5662
5760
  var ControlComponent = customControls[vardef.type];
5663
- return (React.createElement(ControlComponent, { value: value, vardef: vardef, onChange: onChange }));
5761
+ return (React.createElement(ControlComponent, { value: value, vardef: vardef, onChange: onChange, data: data }));
5664
5762
  }
5665
5763
  if (vardef.options) {
5666
5764
  return (React.createElement("select", { value: value || "", onChange: function (e) { return onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value); } }, vardef.options.map(function (option) { return (React.createElement("option", { key: option, value: option }, option)); })));
@@ -5704,7 +5802,7 @@ var Input = function (_a) {
5704
5802
  "--type-color": "var(--color-".concat(normalized.type, ")"),
5705
5803
  }, onClick: onClick },
5706
5804
  React.createElement("span", { className: styles$1.PortLabel }, normalized.label || name),
5707
- !isRef && (React.createElement(Control, { vardef: normalized, value: value, onChange: handleInputChange(name) }))));
5805
+ !isRef && (React.createElement(Control, { vardef: normalized, value: value, onChange: handleInputChange(name), data: data }))));
5708
5806
  };
5709
5807
 
5710
5808
  var Param = function (_a) {
@@ -5723,7 +5821,7 @@ var Param = function (_a) {
5723
5821
  "--type-color": "var(--color-".concat(normalized.type, ")"),
5724
5822
  }, onClick: onClick },
5725
5823
  React.createElement("span", { className: styles$1.PortLabel }, normalized.label || name),
5726
- !isRef && (React.createElement(Control, { vardef: normalized, value: value, onChange: handleParamChange(name) }))));
5824
+ !isRef && (React.createElement(Control, { vardef: normalized, value: value, onChange: handleParamChange(name), data: data }))));
5727
5825
  };
5728
5826
 
5729
5827
  var Output = function (_a) {
@@ -5883,7 +5981,7 @@ function GenericNode(_a) {
5883
5981
  var engine = useEngine();
5884
5982
  var _d = __read(React.useState({}), 2), result = _d[0], setResult = _d[1];
5885
5983
  var _e = __read(React.useState(null), 2), duration = _e[0], setDuration = _e[1];
5886
- var _f = __read(React.useState(((_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0]) || null), 2), focus = _f[0], setFocus = _f[1];
5984
+ var _f = __read(useInner(((_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0]) || null, [outputs, data.outputDefs]), 2), focus = _f[0], setFocus = _f[1];
5887
5985
  var _g = __read(React.useState(false), 2), showPreview = _g[0], setShowPreview = _g[1];
5888
5986
  var previewValue = focus ? result[focus] : Object.values(result)[0];
5889
5987
  React.useEffect(function () {
@@ -5899,17 +5997,17 @@ function GenericNode(_a) {
5899
5997
  React.createElement("div", { className: styles.Description }, data.description),
5900
5998
  children,
5901
5999
  React.createElement("div", { className: styles.Ports },
5902
- outputEntries.map(function (_a) {
6000
+ outputEntries.map(function (_a, index) {
5903
6001
  var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
5904
- return (React.createElement(Output, { key: name, name: name, varDef: varDef, id: id, onClick: function () { return setFocus(name); }, focus: showPreview && focus === name }));
6002
+ return (React.createElement(Output, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, onClick: function () { return setFocus(name); }, focus: showPreview && focus === name }));
5905
6003
  }),
5906
- inputEntries.map(function (_a) {
6004
+ inputEntries.map(function (_a, index) {
5907
6005
  var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
5908
- return (React.createElement(Input, { key: name, name: name, varDef: varDef, id: id, data: data }));
6006
+ return (React.createElement(Input, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data }));
5909
6007
  }),
5910
- paramEntries.map(function (_a) {
6008
+ paramEntries.map(function (_a, index) {
5911
6009
  var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
5912
- return (React.createElement(Param, { key: name, name: name, varDef: varDef, id: id, data: data }));
6010
+ return (React.createElement(Param, { key: "".concat(name, "_").concat(index), name: name, varDef: varDef, id: id, data: data }));
5913
6011
  })),
5914
6012
  React.createElement("div", { className: classNames(styles.PreviewHead, (_b = {},
5915
6013
  _b[styles.expanded] = showPreview,
@@ -6525,14 +6623,14 @@ var ConnectionLine = (function (_a) {
6525
6623
  */
6526
6624
  var emptyObject = {};
6527
6625
  function FlowInner(_a) {
6528
- 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, onChange = _a.onChange, onClick = _a.onClick, onSelect = _a.onSelect, onInit = _a.onInit;
6529
- var _d = __read(React.useState(null), 2), instance = _d[0], setInstance = _d[1];
6626
+ 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, onSelect = _a.onSelect, onInit = _a.onInit;
6627
+ var _e = __read(React.useState(null), 2), instance = _e[0], setInstance = _e[1];
6530
6628
  var handleInit = function (instance) {
6531
6629
  setInstance(instance);
6532
6630
  onInit === null || onInit === void 0 ? void 0 : onInit(instance);
6533
6631
  };
6534
6632
  var updatePosition = useUpdatePositions(fn);
6535
- var _e = __read(usePositions(fn), 2), positions = _e[0], setPositions = _e[1];
6633
+ var _f = __read(usePositions(fn), 2), positions = _f[0], setPositions = _f[1];
6536
6634
  var options = React.useMemo(function () {
6537
6635
  var handleDataChange = function (id) { return function (newData) {
6538
6636
  onChange === null || onChange === void 0 ? void 0 : onChange(function (fn) {
@@ -6562,7 +6660,7 @@ function FlowInner(_a) {
6562
6660
  React.useEffect(function () {
6563
6661
  setPositions(__assign(__assign({}, positions), defaultPositions));
6564
6662
  }, [defaultPositions]);
6565
- var _f = useFlow(fn, engine, options), nodes = _f.nodes, edges = _f.edges, setNodes = _f.setNodes, setEdges = _f.setEdges;
6663
+ var _g = useFlow(fn, engine, options), nodes = _g.nodes, edges = _g.edges, setNodes = _g.setNodes, setEdges = _g.setEdges;
6566
6664
  // node selection handler
6567
6665
  var handleSelect = React.useCallback(function (_a) {
6568
6666
  var nodes = _a.nodes;
@@ -6572,7 +6670,7 @@ function FlowInner(_a) {
6572
6670
  onChange: handleSelect,
6573
6671
  });
6574
6672
  // dropping nodes
6575
- var _g = __read(useDrop({
6673
+ var _h = __read(useDrop({
6576
6674
  accept: "flow-node",
6577
6675
  drop: function (item, monitor) {
6578
6676
  var pos = monitor.getClientOffset();
@@ -6592,7 +6690,7 @@ function FlowInner(_a) {
6592
6690
  isOver: monitor.isOver(),
6593
6691
  };
6594
6692
  },
6595
- }), 2); _g[0].isOver; var drop = _g[1];
6693
+ }), 2); _h[0].isOver; var drop = _h[1];
6596
6694
  // connecting nodes
6597
6695
  var onConnect = React.useCallback(function (params) {
6598
6696
  var _a, _b;
@@ -6659,7 +6757,7 @@ function FlowInner(_a) {
6659
6757
  return react.applyEdgeChanges(changes, edgesSnapshot);
6660
6758
  });
6661
6759
  }, []);
6662
- return (React.createElement(react.ReactFlow, { ref: drop, nodes: nodes, edges: edges, nodeTypes: nodeTypes, onNodesChange: onNodesChange, onEdgesChange: onEdgesChange, onNodesDelete: onNodesDelete, onEdgesDelete: onEdgesDelete, onNodeDragStop: function (e, n) { return updatePosition(n.id, n.position); }, onConnect: onConnect, onInit: handleInit, onPaneClick: handleClick, fitView: center || fitView, fitViewOptions: {
6760
+ 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, fitView: center || fitView, fitViewOptions: {
6663
6761
  minZoom: fitView ? undefined : 1,
6664
6762
  maxZoom: fitView ? undefined : 1,
6665
6763
  },