cx 22.3.4 → 22.3.5

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.
Files changed (45) hide show
  1. package/dist/data.js +94 -25
  2. package/dist/manifest.js +474 -468
  3. package/dist/ui.js +27 -6
  4. package/dist/widgets.js +1 -1
  5. package/package.json +1 -1
  6. package/src/core.d.ts +41 -6
  7. package/src/data/Binding.d.ts +4 -3
  8. package/src/data/Binding.js +12 -8
  9. package/src/data/Store.d.ts +5 -5
  10. package/src/data/Store.js +2 -2
  11. package/src/data/StoreRef.js +2 -0
  12. package/src/data/StructuredSelector.js +43 -57
  13. package/src/data/StructuredSelector.spec.js +54 -39
  14. package/src/data/View.d.ts +40 -16
  15. package/src/data/View.js +27 -19
  16. package/src/data/comparer.js +15 -10
  17. package/src/data/computable.d.ts +27 -4
  18. package/src/data/computable.js +2 -1
  19. package/src/data/computable.spec.js +8 -0
  20. package/src/data/createAccessorModelProxy.d.ts +6 -0
  21. package/src/data/createAccessorModelProxy.js +24 -0
  22. package/src/data/createAccessorModelProxy.spec.tsx +23 -0
  23. package/src/data/createStructuredSelector.js +9 -8
  24. package/src/data/getAccessor.js +24 -15
  25. package/src/data/getSelector.js +4 -1
  26. package/src/data/getSelector.spec.js +7 -0
  27. package/src/data/index.d.ts +2 -0
  28. package/src/data/index.js +2 -0
  29. package/src/ui/Controller.d.ts +13 -8
  30. package/src/ui/Instance.d.ts +6 -6
  31. package/src/ui/Instance.js +6 -5
  32. package/src/ui/Repeater.d.ts +25 -15
  33. package/src/ui/Restate.spec.js +0 -1
  34. package/src/ui/adapter/ArrayAdapter.d.ts +9 -10
  35. package/src/ui/adapter/ArrayAdapter.js +30 -37
  36. package/src/ui/bind.d.ts +3 -2
  37. package/src/ui/bind.js +4 -3
  38. package/src/ui/expr.d.ts +23 -2
  39. package/src/ui/expr.js +16 -4
  40. package/src/widgets/AccessorBindings.spec.tsx +66 -0
  41. package/src/widgets/HtmlElement.d.ts +1 -1
  42. package/src/widgets/List.d.ts +36 -24
  43. package/src/widgets/form/ValidationGroup.spec.js +1 -1
  44. package/src/widgets/grid/Grid.d.ts +86 -68
  45. package/src/widgets/grid/Grid.js +1 -1
package/dist/data.js CHANGED
@@ -13,23 +13,51 @@ import {
13
13
  expandFatArrows
14
14
  } from "cx/util";
15
15
 
16
+ function createAccessorModelProxy(chain) {
17
+ var _this = this;
18
+
19
+ if (chain === void 0) {
20
+ chain = "";
21
+ }
22
+
23
+ var proxy = new Proxy(function() {}, {
24
+ get: function get(target, name) {
25
+ if (name === "isAccessorChain") return true;
26
+ if (typeof name !== "string") return _this;
27
+ if (name === "toString" || name === "valueOf") return proxy;
28
+ var newChain = chain;
29
+ if (newChain.length > 0) newChain += ".";
30
+ newChain += name;
31
+ return createAccessorModelProxy(newChain);
32
+ },
33
+ apply: function apply() {
34
+ return chain;
35
+ }
36
+ });
37
+ proxy.isAccessorChain = true;
38
+ return proxy;
39
+ }
40
+ function isAccessorChain(value) {
41
+ return value != null && !!value.isAccessorChain;
42
+ }
43
+
16
44
  var bindingCache = {};
17
45
  var Binding = /*#__PURE__*/ (function() {
18
46
  function Binding(path) {
19
47
  this.path = path;
20
48
  this.parts = path.split(".");
21
- var fstr = "return (x";
22
- var cpath = "x";
49
+ var body = "return (x";
50
+ var selector = "x";
23
51
 
24
52
  for (var i = 0; i < this.parts.length; i++) {
25
- if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") cpath += "[" + this.parts[i] + "]";
26
- else cpath += "." + this.parts[i];
27
- if (i + 1 < this.parts.length) fstr += " && " + cpath;
28
- else fstr += " ? " + cpath + " : undefined";
53
+ if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
54
+ else selector += "." + this.parts[i];
55
+ if (i + 1 < this.parts.length) body += " && " + selector;
56
+ else body += " ? " + selector + " : undefined";
29
57
  }
30
58
 
31
- fstr += ")";
32
- this.value = new Function("x", fstr);
59
+ body += ")";
60
+ this.value = new Function("x", body);
33
61
  }
34
62
 
35
63
  var _proto = Binding.prototype;
@@ -79,6 +107,7 @@ var Binding = /*#__PURE__*/ (function() {
79
107
 
80
108
  if (isObject(path) && isString(path.bind)) return this.get(path.bind);
81
109
  if (path instanceof Binding) return path;
110
+ if (isAccessorChain(path)) return this.get(path.toString());
82
111
  throw new Error("Invalid binding definition provided.");
83
112
  };
84
113
 
@@ -86,6 +115,7 @@ var Binding = /*#__PURE__*/ (function() {
86
115
  })();
87
116
  function isBinding(value) {
88
117
  if (isObject(value) && isString(value.bind)) return true;
118
+ if (value && value.isAccessorChain) return true;
89
119
  return value instanceof Binding;
90
120
  }
91
121
 
@@ -207,7 +237,7 @@ function computable() {
207
237
 
208
238
  for (var i = 0; i + 1 < arguments.length; i++) {
209
239
  a = i < 0 || arguments.length <= i ? undefined : arguments[i];
210
- if (isString(a)) inputs.push(Binding.get(a).value);
240
+ if (isString(a) || isAccessorChain(a)) inputs.push(Binding.get(a.toString()).value);
211
241
  else if (a.memoize) inputs.push(a.memoize());
212
242
  else if (isFunction(a)) inputs.push(a);
213
243
  else throw new Error("Invalid selector type '" + typeof a + "' received.");
@@ -652,7 +682,11 @@ var StoreRef = /*#__PURE__*/ (function(_Ref) {
652
682
  _inheritsLoose(StoreRef, _Ref);
653
683
 
654
684
  function StoreRef(config) {
655
- return _Ref.call(this, config) || this;
685
+ var _this;
686
+
687
+ _this = _Ref.call(this, config) || this;
688
+ if (isAccessorChain(_this.path)) _this.path = _this.path.toString();
689
+ return _this;
656
690
  }
657
691
 
658
692
  var _proto = StoreRef.prototype;
@@ -726,8 +760,7 @@ var View = /*#__PURE__*/ (function() {
726
760
  };
727
761
 
728
762
  _proto.init = function init(path, value) {
729
- if (path instanceof Binding) path = path.path;
730
- else if (typeof path == "object" && path != null) {
763
+ if (typeof path == "object" && path != null) {
731
764
  var changed = false;
732
765
 
733
766
  for (var key in path) {
@@ -736,13 +769,14 @@ var View = /*#__PURE__*/ (function() {
736
769
 
737
770
  return changed;
738
771
  }
739
- if (this.get(path) === undefined) return this.setItem(path, value);
772
+
773
+ var binding = Binding.get(path);
774
+ if (this.get(binding.path) === undefined) return this.setItem(binding.path, value);
740
775
  return false;
741
776
  };
742
777
 
743
778
  _proto.set = function set(path, value) {
744
- if (path instanceof Binding) path = path.path;
745
- else if (typeof path == "object" && path != null) {
779
+ if (isObject(path)) {
746
780
  var changed = false;
747
781
 
748
782
  for (var key in path) {
@@ -751,7 +785,9 @@ var View = /*#__PURE__*/ (function() {
751
785
 
752
786
  return changed;
753
787
  }
754
- return this.setItem(path, value);
788
+
789
+ var binding = Binding.get(path);
790
+ return this.setItem(binding.path, value);
755
791
  };
756
792
 
757
793
  _proto.copy = function copy(from, to) {
@@ -777,15 +813,15 @@ var View = /*#__PURE__*/ (function() {
777
813
  _proto["delete"] = function _delete(path) {
778
814
  var _this2 = this;
779
815
 
780
- if (path instanceof Binding) path = path.path;
781
- else if (arguments.length > 1) path = Array.from(arguments);
816
+ if (arguments.length > 1) path = Array.from(arguments);
782
817
  if (isArray(path))
783
818
  return path
784
819
  .map(function(arg) {
785
- return _this2.deleteItem(arg);
820
+ return _this2["delete"](arg);
786
821
  })
787
822
  .some(Boolean);
788
- return this.deleteItem(path);
823
+ var binding = Binding.get(path);
824
+ return this.deleteItem(binding.path);
789
825
  }; //protected
790
826
 
791
827
  _proto.deleteItem = function deleteItem(path) {
@@ -817,6 +853,8 @@ var View = /*#__PURE__*/ (function() {
817
853
  args[_key - 2] = arguments[_key];
818
854
  }
819
855
 
856
+ if (arguments.length == 1 && isFunction(path))
857
+ return this.load(path.apply(null, [this.getData(), updateFn].concat(args)));
820
858
  return this.set(path, updateFn.apply(null, [this.get(path)].concat(args)));
821
859
  };
822
860
 
@@ -885,13 +923,21 @@ var View = /*#__PURE__*/ (function() {
885
923
  delete: this["delete"].bind(this),
886
924
  toggle: this.toggle.bind(this),
887
925
  init: this.init.bind(this),
888
- ref: this.ref.bind(this)
926
+ ref: this.ref.bind(this),
927
+ mutate: this.ref.bind(this)
889
928
  };
890
929
  };
891
930
 
892
931
  return View;
893
932
  })();
894
933
  View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
934
+ //Immer integration point
935
+
936
+ View.prototype.mutate = function() {
937
+ throw new Error(
938
+ "Mutate requires Immer. Please install 'immer' and 'cx-immer' packages and enable store mutation by calling enableImmerMutate()."
939
+ );
940
+ };
895
941
 
896
942
  var SubscribableView = /*#__PURE__*/ (function(_View) {
897
943
  _inheritsLoose(SubscribableView, _View);
@@ -1450,9 +1496,9 @@ function getSelector(config) {
1450
1496
  return elementSelector(data);
1451
1497
  });
1452
1498
  };
1453
- }
1499
+ } //toString converts accessor chains to binding paths
1454
1500
 
1455
- if (config.bind) return Binding.get(config.bind).value;
1501
+ if (config.bind) return Binding.get(config.bind.toString()).value;
1456
1502
  if (config.tpl) return StringTemplate.get(config.tpl);
1457
1503
  if (config.expr) return Expression.get(config.expr);
1458
1504
  if (config.get) return config.get;
@@ -1467,6 +1513,7 @@ function getSelector(config) {
1467
1513
  return createStructuredSelector(selectors, constants);
1468
1514
 
1469
1515
  case "function":
1516
+ if (isAccessorChain(config)) return Binding.get(config.toString()).value;
1470
1517
  return config;
1471
1518
 
1472
1519
  default:
@@ -1528,7 +1575,12 @@ function getSelectorConfig(props, values, nameMap) {
1528
1575
  constants[p] = v;
1529
1576
  }
1530
1577
  } else if (isFunction(v)) {
1531
- functions[p] = v;
1578
+ if (isAccessorChain(v)) {
1579
+ var path = v.toString();
1580
+ nameMap[p] = path;
1581
+ functions[p] = Binding.get(path).value;
1582
+ } else functions[p] = v;
1583
+
1532
1584
  constant = false;
1533
1585
  } else {
1534
1586
  if (isUndefined(v)) {
@@ -1965,7 +2017,10 @@ function getComparer(sorters, dataAccessor, comparer) {
1965
2017
  for (var i = 0; i < data.length; i++) {
1966
2018
  d = data[i];
1967
2019
  av = d.getter(a);
1968
- bv = d.getter(b);
2020
+ bv = d.getter(b); // show nulls always on the bottom
2021
+
2022
+ if (av == null) return bv == null ? 0 : 1;
2023
+ if (bv == null) return -1;
1969
2024
  var r = d.compare(av, bv);
1970
2025
  if (r == 0) continue;
1971
2026
  return d.factor * r;
@@ -2325,6 +2380,18 @@ function getAccessor(accessor, options) {
2325
2380
  }
2326
2381
  }
2327
2382
 
2383
+ if (isAccessorChain(accessor)) {
2384
+ var _binding = Binding.get(accessor);
2385
+
2386
+ return {
2387
+ get: _binding.value,
2388
+ set: function set(v, store) {
2389
+ return store.set(_binding.path, v);
2390
+ },
2391
+ isAccessor: true
2392
+ };
2393
+ }
2394
+
2328
2395
  if (isSelector(accessor)) {
2329
2396
  var selector = getSelector(accessor);
2330
2397
  if (accessor && accessor.set)
@@ -2375,6 +2442,7 @@ export {
2375
2442
  ZoomIntoPropertyView,
2376
2443
  append,
2377
2444
  computable,
2445
+ createAccessorModelProxy,
2378
2446
  defaultCompare,
2379
2447
  diffArrays,
2380
2448
  enableFatArrowExpansion,
@@ -2388,6 +2456,7 @@ export {
2388
2456
  insertElement,
2389
2457
  invalidateExpressionCache,
2390
2458
  invalidateStringTemplateCache,
2459
+ isAccessorChain,
2391
2460
  isBinding,
2392
2461
  isSelector,
2393
2462
  merge,