@rkmodules/rules 0.0.61 → 0.0.62
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 +77 -40
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +77 -41
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/DataTree/index.d.ts +3 -0
- package/dist/lib/DataTree/util.d.ts +1 -1
- package/dist/lib/Engine/util.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -237,6 +237,9 @@ function isSingleTon(value) {
|
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
239
239
|
* turns a value or array of values into a tree
|
|
240
|
+
* - a single value becomes a tree with one branch "0" and one item
|
|
241
|
+
* - an array of values becomes a tree with one branch "0" and the items in the array
|
|
242
|
+
* - a tree is returned as is
|
|
240
243
|
*/
|
|
241
244
|
function broadCast(value) {
|
|
242
245
|
if (Array.isArray(value)) {
|
|
@@ -401,30 +404,42 @@ function toArray(a) {
|
|
|
401
404
|
* @param b
|
|
402
405
|
* @returns
|
|
403
406
|
*/
|
|
404
|
-
function mergeTrees(
|
|
405
|
-
var
|
|
406
|
-
var
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
for (var _c = __values(Object.entries(b)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
410
|
-
var _e = __read(_d.value, 2), k = _e[0], arr = _e[1];
|
|
411
|
-
out[k] = ((_b = out[k]) !== null && _b !== void 0 ? _b : []).concat(arr);
|
|
412
|
-
}
|
|
407
|
+
function mergeTrees() {
|
|
408
|
+
var others = [];
|
|
409
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
410
|
+
others[_i] = arguments[_i];
|
|
413
411
|
}
|
|
414
|
-
|
|
415
|
-
|
|
412
|
+
var a = others.shift() || { 0: [] };
|
|
413
|
+
var out = __assign({}, a);
|
|
414
|
+
others.forEach(function (b) {
|
|
415
|
+
var e_1, _a;
|
|
416
|
+
var _b;
|
|
416
417
|
try {
|
|
417
|
-
|
|
418
|
+
for (var _c = __values(Object.entries(b)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
419
|
+
var _e = __read(_d.value, 2), k = _e[0], arr = _e[1];
|
|
420
|
+
out[k] = ((_b = out[k]) !== null && _b !== void 0 ? _b : []).concat(arr);
|
|
421
|
+
}
|
|
418
422
|
}
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
424
|
+
finally {
|
|
425
|
+
try {
|
|
426
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
427
|
+
}
|
|
428
|
+
finally { if (e_1) throw e_1.error; }
|
|
429
|
+
}
|
|
430
|
+
});
|
|
421
431
|
return out;
|
|
422
432
|
}
|
|
423
433
|
|
|
424
434
|
function isReference(value) {
|
|
425
|
-
return (typeof value === "string" &&
|
|
426
|
-
|
|
427
|
-
|
|
435
|
+
return (typeof value === "string" && !!value.match(/^<([\w\.]+)>$/)
|
|
436
|
+
// value.startsWith("<") &&
|
|
437
|
+
// value.endsWith(">")
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
function hasReference(value) {
|
|
441
|
+
var _a;
|
|
442
|
+
return typeof value === "string" && !!((_a = value.match) === null || _a === void 0 ? void 0 : _a.call(value, /<(.*?)>/g));
|
|
428
443
|
}
|
|
429
444
|
function parseReference(ref) {
|
|
430
445
|
return ref.slice(1, -1);
|
|
@@ -444,29 +459,35 @@ function getValue$1(obj, path) {
|
|
|
444
459
|
return value;
|
|
445
460
|
}
|
|
446
461
|
function interpolateValue(value, scope) {
|
|
462
|
+
// interpolating arrays
|
|
447
463
|
if (Array.isArray(value)) {
|
|
448
464
|
if (!value.length)
|
|
449
|
-
return
|
|
450
|
-
if (
|
|
451
|
-
//
|
|
452
|
-
var
|
|
453
|
-
|
|
465
|
+
return [];
|
|
466
|
+
if (value.every(isTree)) {
|
|
467
|
+
// array of trees: merge the trees into one
|
|
468
|
+
var tree = mergeTrees.apply(void 0, __spreadArray([], __read(value), false));
|
|
469
|
+
// then interpolate each value in the tree in case there are references
|
|
470
|
+
return mapTree(tree, function (v) { return interpolateValue(v, scope); });
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
// array of other values: interpolate to an array of trees
|
|
474
|
+
var mappedValue = value.map(function (v) {
|
|
475
|
+
return broadCast(interpolateValue(v, scope));
|
|
476
|
+
});
|
|
477
|
+
if (!mappedValue.every(isTree)) {
|
|
454
478
|
// this is a bit of a hack when the values were all plain values
|
|
455
479
|
// in that case, just return them, which will result in a single tree
|
|
456
|
-
return
|
|
480
|
+
return mappedValue;
|
|
457
481
|
}
|
|
458
482
|
// then, for each value, combine the branches with the same index
|
|
459
|
-
return
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
// combine the trees into one
|
|
463
|
-
var tree = value.reduce(function (acc, t) { return mergeTrees(acc, t); });
|
|
464
|
-
return mapTree(tree, function (v) { return interpolateValue(v, scope); });
|
|
483
|
+
return mergeTrees.apply(void 0, __spreadArray([], __read(mappedValue), false));
|
|
465
484
|
}
|
|
466
485
|
}
|
|
486
|
+
// a tree is mapped over each value
|
|
467
487
|
if (isTree(value)) {
|
|
468
488
|
return mapTree(value, function (v) { return interpolateValue(v, scope); });
|
|
469
489
|
}
|
|
490
|
+
// an object is interpolated recursively
|
|
470
491
|
if (typeof value === "object" && value !== null) {
|
|
471
492
|
if (Object.keys(value).length === 0) {
|
|
472
493
|
return {};
|
|
@@ -481,18 +502,33 @@ function interpolateValue(value, scope) {
|
|
|
481
502
|
}));
|
|
482
503
|
});
|
|
483
504
|
}
|
|
484
|
-
if (
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
505
|
+
if (hasReference(value)) {
|
|
506
|
+
if (isReference(value)) {
|
|
507
|
+
// it's a simple reference string
|
|
508
|
+
var parts_1 = parseReference(value).split(".");
|
|
509
|
+
var mappedValue = getValue$1(scope, parts_1.slice(0, 2).join("."));
|
|
510
|
+
if (parts_1.length > 2) {
|
|
511
|
+
// deep interpolate
|
|
512
|
+
mappedValue = mapTree(mappedValue, function (v) {
|
|
513
|
+
return getValue$1(v, parts_1.slice(2).join("."));
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return mappedValue;
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
// it's a template string, break up as an array of strings and references and interpolate each to a tree
|
|
520
|
+
var strings = value.split(/(<.*?>)/);
|
|
521
|
+
var trees = strings.map(function (str) {
|
|
522
|
+
return broadCast(interpolateValue(str, scope));
|
|
523
|
+
});
|
|
524
|
+
// create a combined string for each item, filling in missing items witht the last
|
|
525
|
+
var combined = nAryOnTree(trees, function (items) {
|
|
526
|
+
return items.join("");
|
|
527
|
+
}, true);
|
|
528
|
+
return combined;
|
|
529
|
+
}
|
|
494
530
|
}
|
|
495
|
-
return
|
|
531
|
+
return value;
|
|
496
532
|
}
|
|
497
533
|
function interpolate(inputs, scope) {
|
|
498
534
|
return Object.fromEntries(Object.entries(inputs).map(function (_a) {
|
|
@@ -5111,5 +5147,5 @@ function DDContext(_a) {
|
|
|
5111
5147
|
return React.createElement(DndProvider, { backend: HTML5Backend }, children);
|
|
5112
5148
|
}
|
|
5113
5149
|
|
|
5114
|
-
export { DDContext, DISCARD, Engine, Flow, Lib, binaryOnTree, binaryOnTreeBranch, broadCast, expandTree, getBranch, getReferences, getValue$1 as getValue, graftTree, interpolate, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, nAryOnTree, nAryOnTreeBranch, normalizeVarDef, parseReference, primitives, sameShape, simplifyTree, toArray, topSort, treeSize, trimTree, uid$1 as uid, useDraggableNode, useFlow, useFunction, usePositions, useUpdatePositions, useVariable };
|
|
5150
|
+
export { DDContext, DISCARD, Engine, Flow, Lib, binaryOnTree, binaryOnTreeBranch, broadCast, expandTree, getBranch, getReferences, getValue$1 as getValue, graftTree, hasReference, interpolate, isReference, isSingleTon, isTree, mapTree, mapTreeBranch, nAryOnTree, nAryOnTreeBranch, normalizeVarDef, parseReference, primitives, sameShape, simplifyTree, toArray, topSort, treeSize, trimTree, uid$1 as uid, useDraggableNode, useFlow, useFunction, usePositions, useUpdatePositions, useVariable };
|
|
5115
5151
|
//# sourceMappingURL=index.esm.js.map
|