@rkmodules/rules 0.0.101 → 0.0.103

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
@@ -267,6 +267,74 @@ function getItem(tree, path, index) {
267
267
  return branch[index];
268
268
  }
269
269
  }
270
+ /**
271
+ * gets number of dimensions (max depth of the tree) and their sizes (group sizes at each level)
272
+ * @param tree
273
+ * @returns
274
+ */
275
+ function treeStats(tree) {
276
+ var paths = getPaths(tree);
277
+ var dimensions = 0;
278
+ var branchSizes = {};
279
+ paths.forEach(function (path) {
280
+ var _a;
281
+ var segments = path.split(";").map(function (seg) { return parseInt(seg, 10); });
282
+ // find max depth, which is the number of dimensions
283
+ dimensions = Math.max(dimensions, segments.length);
284
+ segments.forEach(function (seg, index) {
285
+ if (!index)
286
+ return;
287
+ var prefix = segments.slice(0, index).join(";");
288
+ if (!branchSizes[prefix]) {
289
+ branchSizes[prefix] = 1;
290
+ }
291
+ else {
292
+ branchSizes[prefix] += 1;
293
+ }
294
+ });
295
+ branchSizes[path] = ((_a = getBranch(tree, path)) === null || _a === void 0 ? void 0 : _a.length) || 0;
296
+ });
297
+ return { dimensions: dimensions, branchSizes: branchSizes };
298
+ }
299
+ function normalizePaths(tree) {
300
+ var paths = getPaths(tree);
301
+ var spaths = paths.map(function (p) { return p.split(";").map(function (seg) { return parseInt(seg, 10); }); });
302
+ var maxLength = Math.max.apply(Math, __spreadArray([], __read(spaths.map(function (p) { return p.length; })), false));
303
+ var lastSPath;
304
+ var lastNPath;
305
+ var npaths = [];
306
+ spaths.forEach(function (p, index) {
307
+ if (index === 0) {
308
+ // start with a full zero path
309
+ lastNPath = Array(maxLength).fill(0);
310
+ npaths.push(lastNPath.join(";"));
311
+ }
312
+ else {
313
+ // start with all zeros
314
+ var n = Array(maxLength).fill(0);
315
+ for (var i = 0; i < maxLength; i++) {
316
+ if (p[i] > lastSPath[i]) {
317
+ // increment the segment, all the rest are zeros, so we can stop
318
+ n[i] = lastNPath[i] + 1;
319
+ break;
320
+ }
321
+ else {
322
+ // same segment, copy over
323
+ n[i] = lastNPath[i];
324
+ }
325
+ }
326
+ lastNPath = n;
327
+ npaths.push(lastNPath.join(";"));
328
+ }
329
+ lastSPath = p;
330
+ });
331
+ var normalized = {};
332
+ paths.forEach(function (path, index) {
333
+ var branch = getBranch(tree, path);
334
+ normalized[npaths[index]] = branch || [];
335
+ });
336
+ return normalized;
337
+ }
270
338
  function forEachBranch(tree, fn) {
271
339
  var paths = getPaths(tree);
272
340
  paths.forEach(function (path, i) {
@@ -2297,11 +2365,13 @@ var Engine = /** @class */ (function () {
2297
2365
  return newFn;
2298
2366
  }
2299
2367
  if (!fn) {
2300
- throw new Error("Function ".concat(to === null || to === void 0 ? void 0 : to.name, " not found in index, which is unexpected as you are deleting an edge to it."));
2368
+ console.warn("Function ".concat(to === null || to === void 0 ? void 0 : to.name, " not found in index, which is unexpected as you are deleting an edge to it."));
2369
+ return newFn;
2301
2370
  }
2302
2371
  if (to.inputs && to.inputs[toField] === "<".concat(fromNode, ".").concat(fromField, ">")) {
2303
- // revert to default value if exists
2372
+ // delete the incoming edge
2304
2373
  delete to.inputs[toField];
2374
+ // revert to default value if exists
2305
2375
  if ((_a = fn.inputs) === null || _a === void 0 ? void 0 : _a[toField]) {
2306
2376
  var normDef = normalizeVarDef(fn.inputs[toField]);
2307
2377
  if (normDef.default !== undefined) {
@@ -7270,5 +7340,5 @@ function DDContext(_a) {
7270
7340
  return React.createElement(DndProvider, { backend: HTML5Backend }, children);
7271
7341
  }
7272
7342
 
7273
- export { DDContext, DISCARD, Engine, Flow, Lib, binaryOnTree, binaryOnTreeBranch, broadCast, expandTree, forEachBranch, forEachItem, getBranch, getBranches, getItem, getPaths, getPositions, getReferences, getValue$1 as getValue, getVariable, graftTree, hasReference, interpolate, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, nAryOnTree, nAryOnTreeBranch, normalizeVarDef, parseReference, primitives, pushItem, sameShape, simplifyTree$1 as simplifyTree, toArray, topSort, treeSize, trimTree, uid$1 as uid, useDraggableNode, useFlow, useFunction, usePositions, useUpdatePositions, useVariable, variableStore };
7343
+ export { DDContext, DISCARD, Engine, Flow, Lib, binaryOnTree, binaryOnTreeBranch, broadCast, expandTree, forEachBranch, forEachItem, getBranch, getBranches, getItem, getPaths, getPositions, getReferences, getValue$1 as getValue, getVariable, graftTree, hasReference, interpolate, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, nAryOnTree, nAryOnTreeBranch, normalizePaths, normalizeVarDef, parseReference, primitives, pushItem, sameShape, simplifyTree$1 as simplifyTree, toArray, topSort, treeSize, treeStats, trimTree, uid$1 as uid, useDraggableNode, useFlow, useFunction, usePositions, useUpdatePositions, useVariable, variableStore };
7274
7344
  //# sourceMappingURL=index.esm.js.map