@rkmodules/rules 0.0.101 → 0.0.102
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 +70 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +69 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/DataTree/index.d.ts +12 -2
- package/package.json +1 -1
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) {
|
|
@@ -7270,5 +7338,5 @@ function DDContext(_a) {
|
|
|
7270
7338
|
return React.createElement(DndProvider, { backend: HTML5Backend }, children);
|
|
7271
7339
|
}
|
|
7272
7340
|
|
|
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 };
|
|
7341
|
+
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
7342
|
//# sourceMappingURL=index.esm.js.map
|