@rkmodules/rules 0.0.117 → 0.0.119

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 = {
@@ -1849,7 +1872,7 @@ var mergeTree = {
1849
1872
  name: "mergeTree",
1850
1873
  label: "Merge Tree",
1851
1874
  description: "Merge groups with the same index into a single tree.",
1852
- nodeType: "Merge",
1875
+ nodeType: "DynamicInput",
1853
1876
  inputs: {},
1854
1877
  outputs: {
1855
1878
  result: "any",
@@ -2216,7 +2239,7 @@ var mergeObject = {
2216
2239
  name: "mergeObject",
2217
2240
  label: "Merge Object",
2218
2241
  description: "Merges objects in groups",
2219
- nodeType: "Merge",
2242
+ nodeType: "DynamicInput",
2220
2243
  inputs: {},
2221
2244
  outputs: {
2222
2245
  object: "any",
@@ -2289,11 +2312,112 @@ var listToArray = {
2289
2312
  }); },
2290
2313
  };
2291
2314
 
2315
+ var objectEntries = {
2316
+ name: "objectEntries",
2317
+ label: "Entries",
2318
+ description: "Gets keys and pairs of an object",
2319
+ inputs: {
2320
+ object: "any",
2321
+ },
2322
+ outputs: {
2323
+ keys: "string",
2324
+ values: "any",
2325
+ },
2326
+ impl: function (_a) { return __awaiter(void 0, [_a], void 0, function (_b) {
2327
+ var keys, values;
2328
+ var _c = _b.object, object = _c === void 0 ? {} : _c;
2329
+ return __generator(this, function (_d) {
2330
+ keys = mapTree(object, function (obj) { return Object.keys(obj); });
2331
+ values = mapTree(object, function (obj) { return Object.values(obj); });
2332
+ return [2 /*return*/, {
2333
+ keys: keys,
2334
+ values: values,
2335
+ }];
2336
+ });
2337
+ }); },
2338
+ };
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
+
2292
2413
  var _a$1;
2293
2414
  var primitives$1 = (_a$1 = {},
2294
2415
  _a$1[object.name] = object,
2295
2416
  _a$1[listToArray.name] = listToArray,
2417
+ _a$1[arrayToList.name] = arrayToList,
2296
2418
  _a$1[mergeObject.name] = mergeObject,
2419
+ _a$1[objectEntries.name] = objectEntries,
2420
+ _a$1[explodeObject.name] = explodeObject,
2297
2421
  _a$1);
2298
2422
 
2299
2423
  var Lib = {
@@ -5857,7 +5981,7 @@ function GenericNode(_a) {
5857
5981
  var engine = useEngine();
5858
5982
  var _d = __read(React.useState({}), 2), result = _d[0], setResult = _d[1];
5859
5983
  var _e = __read(React.useState(null), 2), duration = _e[0], setDuration = _e[1];
5860
- 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];
5861
5985
  var _g = __read(React.useState(false), 2), showPreview = _g[0], setShowPreview = _g[1];
5862
5986
  var previewValue = focus ? result[focus] : Object.values(result)[0];
5863
5987
  React.useEffect(function () {
@@ -6083,54 +6207,17 @@ InputNode.displayName = "InputNode";
6083
6207
  function uid() {
6084
6208
  return Math.random().toString(36).substring(2, 15);
6085
6209
  }
6086
- var Merge = React.memo(function (_a) {
6087
- var _b;
6088
- var _c;
6210
+ var DynamicInput = React.memo(function (_a) {
6089
6211
  var id = _a.id, data = _a.data, selected = _a.selected;
6090
- var outputEntries = Object.entries(data.outputDefs || {});
6091
- var focus = (_c = outputEntries[0]) === null || _c === void 0 ? void 0 : _c[0];
6092
- var _d = __read(React.useState(false), 2), showPreview = _d[0], setShowPreview = _d[1];
6093
- var engine = useEngine();
6094
- var _e = __read(React.useState({}), 2), result = _e[0], setResult = _e[1];
6095
- var _f = __read(React.useState(null), 2), duration = _f[0], setDuration = _f[1];
6096
- var previewValue = focus ? result[focus] : Object.values(result)[0];
6097
- React.useEffect(function () {
6098
- return engine.subscribe("functionResult", function (event) {
6099
- var _a;
6100
- if (event.name === id) {
6101
- setResult(event.result || {});
6102
- setDuration((_a = event.duration) !== null && _a !== void 0 ? _a : null);
6103
- }
6104
- });
6105
- }, []);
6106
6212
  var inputs = Object.fromEntries(Object.keys(data.inputs || {}).map(function (name, i) { return [
6107
6213
  name,
6108
6214
  { type: "any", label: "D".concat(i + 1) },
6109
6215
  ]; }));
6110
6216
  var inputCount = Object.keys(inputs).length;
6111
6217
  inputs[uid()] = { type: "any", label: "D".concat(inputCount + 1) };
6112
- var outputs = __assign({}, (data.outputDefs || {}));
6113
- return (React.createElement(NodeContainer, { label: data.label, selected: selected, id: id },
6114
- React.createElement("div", { className: styles.Description }, data.description),
6115
- React.createElement("div", { className: styles.Ports },
6116
- Object.entries(outputs || {}).map(function (_a) {
6117
- var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6118
- return (React.createElement(Output, { key: name, name: name, varDef: varDef, id: id }));
6119
- }),
6120
- Object.entries(inputs || {}).map(function (_a) {
6121
- var _b = __read(_a, 2), name = _b[0], varDef = _b[1];
6122
- return (React.createElement(Input, { key: name, name: name, varDef: varDef, id: id, data: data }));
6123
- })),
6124
- React.createElement("div", { className: classNames(styles.PreviewHead, (_b = {},
6125
- _b[styles.expanded] = showPreview,
6126
- _b)), onClick: function () { return setShowPreview(!showPreview); } }, "Preview"),
6127
- showPreview && (React.createElement("div", { className: styles.Preview },
6128
- React.createElement(TreeView, { value: previewValue }),
6129
- duration !== null && (React.createElement("div", { className: styles.Duration },
6130
- duration.toFixed(2),
6131
- " ms"))))));
6218
+ return (React.createElement(GenericNode, { inputs: inputs, id: id, data: data, selected: selected }));
6132
6219
  });
6133
- Merge.displayName = "MergeNode";
6220
+ DynamicInput.displayName = "DynamicInputNode";
6134
6221
 
6135
6222
  /**
6136
6223
  * todo: create a factory for output component
@@ -6230,11 +6317,28 @@ var OutputNode = React.memo(function (_a) {
6230
6317
  });
6231
6318
  OutputNode.displayName = "OutputNode";
6232
6319
 
6320
+ var DynamicOutput = React.memo(function (_a) {
6321
+ var id = _a.id, data = _a.data, selected = _a.selected;
6322
+ var _b = __read(React.useState({}), 2), outputs = _b[0], setOutputs = _b[1];
6323
+ var engine = useEngine();
6324
+ React.useEffect(function () {
6325
+ return engine.subscribe("functionResult", function (event) {
6326
+ if (event.name === id) {
6327
+ var result = event.result || {};
6328
+ setOutputs(Object.fromEntries(Object.keys(result).map(function (name, i) { return [name, "any"]; })));
6329
+ }
6330
+ });
6331
+ }, []);
6332
+ return (React.createElement(GenericNode, { outputs: outputs, id: id, data: data, selected: selected }));
6333
+ });
6334
+ DynamicOutput.displayName = "DynamicOutputNode";
6335
+
6233
6336
  var nodeTypes = {
6234
6337
  Default: Default,
6235
6338
  Calc: Calc,
6236
6339
  Log: Log,
6237
- Merge: Merge,
6340
+ DynamicInput: DynamicInput,
6341
+ DynamicOutput: DynamicOutput,
6238
6342
  Input: InputNode,
6239
6343
  Output: OutputNode,
6240
6344
  };
@@ -7713,6 +7817,7 @@ exports.DDContext = DDContext;
7713
7817
  exports.DISCARD = DISCARD;
7714
7818
  exports.Engine = Engine;
7715
7819
  exports.Flow = Flow;
7820
+ exports.GenericNode = GenericNode;
7716
7821
  exports.Lib = Lib;
7717
7822
  exports.binaryOnTree = binaryOnTree;
7718
7823
  exports.binaryOnTreeBranch = binaryOnTreeBranch;