@rkmodules/rules 0.0.60 → 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.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)) {
@@ -257,14 +260,14 @@ function getBranch(tree, path) {
257
260
  * @returns
258
261
  */
259
262
  function mapTree(tree, fn) {
260
- return nAryOnTree([tree], function (_a, _b, index) {
263
+ return nAryOnTree([tree], function mapTreeCallback(_a, _b, index) {
261
264
  var _c = __read(_a, 1), item = _c[0];
262
265
  var _d = __read(_b, 1), path = _d[0];
263
266
  return fn(item, path, index);
264
267
  });
265
268
  }
266
269
  function mapTreeBranch(tree, fn) {
267
- return nAryOnTreeBranch([tree], function (_a, _b) {
270
+ return nAryOnTreeBranch([tree], function mapTreeBranchCallback(_a, _b) {
268
271
  var _c = __read(_a, 1), branch = _c[0];
269
272
  var _d = __read(_b, 1), path = _d[0];
270
273
  return fn(branch, path);
@@ -317,7 +320,7 @@ function nAryOnTreeBranch(trees, fn) {
317
320
  * @returns
318
321
  */
319
322
  function nAryOnTree(trees, fn, fill) {
320
- return nAryOnTreeBranch(trees, function (branches, paths) {
323
+ return nAryOnTreeBranch(trees, function nAryOnTreeCallback(branches, paths) {
321
324
  var maxLength = Math.max.apply(Math, __spreadArray([], __read(branches.map(function (b) { return b.length; })), false));
322
325
  if (maxLength === 0)
323
326
  return; // Skip empty branches
@@ -354,7 +357,7 @@ function nAryOnTree(trees, fn, fill) {
354
357
  * @returns
355
358
  */
356
359
  function binaryOnTreeBranch(treeA, treeB, fn) {
357
- return nAryOnTreeBranch([treeA, treeB], function (_a, _b) {
360
+ return nAryOnTreeBranch([treeA, treeB], function binaryOnTreeBranchCallback(_a, _b) {
358
361
  var _c = __read(_a, 2), branchA = _c[0], branchB = _c[1];
359
362
  var _d = __read(_b, 2), pathA = _d[0], pathB = _d[1];
360
363
  return fn(branchA, branchB, pathA, pathB);
@@ -373,7 +376,7 @@ function binaryOnTreeBranch(treeA, treeB, fn) {
373
376
  * @returns
374
377
  */
375
378
  function binaryOnTree(treeA, treeB, fn, fill) {
376
- return nAryOnTree([treeA, treeB], function (_a, _b, index) {
379
+ return nAryOnTree([treeA, treeB], function binaryOnTreeCallback(_a, _b, index) {
377
380
  var _c = __read(_a, 2), itemA = _c[0], itemB = _c[1];
378
381
  var _d = __read(_b, 2), pathA = _d[0], pathB = _d[1];
379
382
  return fn(itemA, itemB, pathA, pathB, index);
@@ -401,30 +404,42 @@ function toArray(a) {
401
404
  * @param b
402
405
  * @returns
403
406
  */
404
- function mergeTrees(a, b) {
405
- var e_1, _a;
406
- var _b;
407
- var out = __assign({}, a);
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
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
415
- finally {
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
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
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
- finally { if (e_1) throw e_1.error; }
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
- value.startsWith("<") &&
427
- value.endsWith(">"));
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 broadCast([]);
450
- if (!value.every(isTree)) {
451
- // interpolate to an array of trees
452
- var mappedValue_1 = value.map(function (v) { return interpolateValue(v, scope); });
453
- if (!mappedValue_1.every(isTree)) {
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 mappedValue_1;
480
+ return mappedValue;
457
481
  }
458
482
  // then, for each value, combine the branches with the same index
459
- return nAryOnTreeBranch(mappedValue_1, function (branches) { return branches.flat(); });
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 (!isReference(value)) {
485
- return value;
486
- }
487
- var parts = parseReference(value).split(".");
488
- var mappedValue = getValue$1(scope, parts.slice(0, 2).join("."));
489
- if (parts.length > 2) {
490
- // deep interpolate
491
- mappedValue = mapTree(mappedValue, function (v) {
492
- return getValue$1(v, parts.slice(2).join("."));
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 mappedValue;
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