cx 23.4.3 → 23.4.4

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/data.js ADDED
@@ -0,0 +1,2109 @@
1
+ import {
2
+ isString,
3
+ isObject,
4
+ isFunction,
5
+ Format,
6
+ isDigit,
7
+ quoteStr,
8
+ Component,
9
+ isArray,
10
+ isDefined,
11
+ SubscriberList,
12
+ isUndefined,
13
+ expandFatArrows,
14
+ } from "cx/util";
15
+
16
+ var emptyFn = function emptyFn() {};
17
+ function createAccessorModelProxy(chain) {
18
+ if (chain === void 0) {
19
+ chain = "";
20
+ }
21
+ var lastOp = null;
22
+ var proxy = new Proxy(emptyFn, {
23
+ get: function get(_, name) {
24
+ if (typeof name !== "string") return proxy;
25
+ switch (name) {
26
+ case "isAccessorChain":
27
+ return true;
28
+ case "toString":
29
+ case "valueOf":
30
+ case "nameOf":
31
+ lastOp = name;
32
+ return proxy;
33
+ }
34
+ var newChain = chain;
35
+ if (newChain.length > 0) newChain += ".";
36
+ newChain += name;
37
+ return createAccessorModelProxy(newChain);
38
+ },
39
+ apply: function apply() {
40
+ switch (lastOp) {
41
+ case "nameOf":
42
+ var lastDotIndex = chain.lastIndexOf(".");
43
+ return lastDotIndex > 0 ? chain.substring(lastDotIndex + 1) : chain;
44
+ default:
45
+ return chain;
46
+ }
47
+ },
48
+ });
49
+ return proxy;
50
+ }
51
+ function isAccessorChain(value) {
52
+ return value != null && !!value.isAccessorChain;
53
+ }
54
+
55
+ var bindingCache = {};
56
+ var Binding = /*#__PURE__*/ (function () {
57
+ function Binding(path) {
58
+ this.path = path;
59
+ this.parts = path.split(".");
60
+ var body = "return (x";
61
+ var selector = "x";
62
+ for (var i = 0; i < this.parts.length; i++) {
63
+ if (this.parts[i][0] >= "0" && this.parts[i][0] <= "9") selector += "[" + this.parts[i] + "]";
64
+ else selector += "." + this.parts[i];
65
+ if (i + 1 < this.parts.length) body += " && " + selector;
66
+ else body += " ? " + selector + " : undefined";
67
+ }
68
+ body += ")";
69
+ this.value = new Function("x", body);
70
+ }
71
+ var _proto = Binding.prototype;
72
+ _proto.set = function set(state, value) {
73
+ var cv = this.value(state);
74
+ if (cv === value) return state;
75
+ var ns = Object.assign({}, state);
76
+ var o = ns;
77
+ for (var i = 0; i < this.parts.length; i++) {
78
+ var part = this.parts[i];
79
+ var no = i == this.parts.length - 1 ? value : Object.assign({}, o[part]);
80
+ o[part] = no;
81
+ o = no;
82
+ }
83
+ return ns;
84
+ };
85
+ _proto["delete"] = function _delete(state) {
86
+ var ns = Object.assign({}, state);
87
+ var o = ns;
88
+ var part;
89
+ for (var i = 0; i < this.parts.length - 1; i++) {
90
+ part = this.parts[i];
91
+ var no = Object.assign({}, o[part]);
92
+ o[part] = no;
93
+ o = no;
94
+ }
95
+ part = this.parts[this.parts.length - 1];
96
+ if (!o.hasOwnProperty(part)) return state;
97
+ delete o[part];
98
+ return ns;
99
+ };
100
+ Binding.get = function get(path) {
101
+ if (isString(path)) {
102
+ var b = bindingCache[path];
103
+ if (b) return b;
104
+ b = new Binding(path);
105
+ bindingCache[path] = b;
106
+ return b;
107
+ }
108
+ if (isObject(path) && isString(path.bind)) return this.get(path.bind);
109
+ if (path instanceof Binding) return path;
110
+ if (isAccessorChain(path)) return this.get(path.toString());
111
+ throw new Error("Invalid binding definition provided.");
112
+ };
113
+ return Binding;
114
+ })();
115
+ function isBinding(value) {
116
+ if (isObject(value) && isString(value.bind)) return true;
117
+ if (value && value.isAccessorChain) return true;
118
+ return value instanceof Binding;
119
+ }
120
+
121
+ function ownKeys(object, enumerableOnly) {
122
+ var keys = Object.keys(object);
123
+ if (Object.getOwnPropertySymbols) {
124
+ var symbols = Object.getOwnPropertySymbols(object);
125
+ enumerableOnly &&
126
+ (symbols = symbols.filter(function (sym) {
127
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
128
+ })),
129
+ keys.push.apply(keys, symbols);
130
+ }
131
+ return keys;
132
+ }
133
+ function _objectSpread2(target) {
134
+ for (var i = 1; i < arguments.length; i++) {
135
+ var source = null != arguments[i] ? arguments[i] : {};
136
+ i % 2
137
+ ? ownKeys(Object(source), !0).forEach(function (key) {
138
+ _defineProperty(target, key, source[key]);
139
+ })
140
+ : Object.getOwnPropertyDescriptors
141
+ ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source))
142
+ : ownKeys(Object(source)).forEach(function (key) {
143
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
144
+ });
145
+ }
146
+ return target;
147
+ }
148
+ function _defineProperty(obj, key, value) {
149
+ key = _toPropertyKey(key);
150
+ if (key in obj) {
151
+ Object.defineProperty(obj, key, {
152
+ value: value,
153
+ enumerable: true,
154
+ configurable: true,
155
+ writable: true,
156
+ });
157
+ } else {
158
+ obj[key] = value;
159
+ }
160
+ return obj;
161
+ }
162
+ function _inheritsLoose(subClass, superClass) {
163
+ subClass.prototype = Object.create(superClass.prototype);
164
+ subClass.prototype.constructor = subClass;
165
+ _setPrototypeOf(subClass, superClass);
166
+ }
167
+ function _setPrototypeOf(o, p) {
168
+ _setPrototypeOf = Object.setPrototypeOf
169
+ ? Object.setPrototypeOf.bind()
170
+ : function _setPrototypeOf(o, p) {
171
+ o.__proto__ = p;
172
+ return o;
173
+ };
174
+ return _setPrototypeOf(o, p);
175
+ }
176
+ function _isNativeReflectConstruct() {
177
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
178
+ if (Reflect.construct.sham) return false;
179
+ if (typeof Proxy === "function") return true;
180
+ try {
181
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
182
+ return true;
183
+ } catch (e) {
184
+ return false;
185
+ }
186
+ }
187
+ function _construct(Parent, args, Class) {
188
+ if (_isNativeReflectConstruct()) {
189
+ _construct = Reflect.construct.bind();
190
+ } else {
191
+ _construct = function _construct(Parent, args, Class) {
192
+ var a = [null];
193
+ a.push.apply(a, args);
194
+ var Constructor = Function.bind.apply(Parent, a);
195
+ var instance = new Constructor();
196
+ if (Class) _setPrototypeOf(instance, Class.prototype);
197
+ return instance;
198
+ };
199
+ }
200
+ return _construct.apply(null, arguments);
201
+ }
202
+ function _assertThisInitialized(self) {
203
+ if (self === void 0) {
204
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
205
+ }
206
+ return self;
207
+ }
208
+ function _toPrimitive(input, hint) {
209
+ if (typeof input !== "object" || input === null) return input;
210
+ var prim = input[Symbol.toPrimitive];
211
+ if (prim !== undefined) {
212
+ var res = prim.call(input, hint || "default");
213
+ if (typeof res !== "object") return res;
214
+ throw new TypeError("@@toPrimitive must return a primitive value.");
215
+ }
216
+ return (hint === "string" ? String : Number)(input);
217
+ }
218
+ function _toPropertyKey(arg) {
219
+ var key = _toPrimitive(arg, "string");
220
+ return typeof key === "symbol" ? key : String(key);
221
+ }
222
+
223
+ function computable() {
224
+ var _ref;
225
+ if (arguments.length == 0)
226
+ throw new Error("computable requires at least a compute function to be passed in arguments.");
227
+ var compute = ((_ref = arguments.length - 1), _ref < 0 || arguments.length <= _ref ? undefined : arguments[_ref]);
228
+ if (typeof compute != "function") throw new Error("Last argument to the computable function should be a function.");
229
+ var inputs = [],
230
+ a;
231
+ for (var i = 0; i + 1 < arguments.length; i++) {
232
+ a = i < 0 || arguments.length <= i ? undefined : arguments[i];
233
+ if (isString(a) || isAccessorChain(a)) inputs.push(Binding.get(a.toString()).value);
234
+ else if (a.memoize) inputs.push(a.memoize());
235
+ else if (isFunction(a)) inputs.push(a);
236
+ else throw new Error("Invalid selector type '" + typeof a + "' received.");
237
+ }
238
+ function memoize(warmupData) {
239
+ var lastValue,
240
+ lastArgs =
241
+ warmupData &&
242
+ inputs.map(function (s) {
243
+ return s(warmupData);
244
+ });
245
+ return function (data) {
246
+ var dirty = false;
247
+ if (!lastArgs) {
248
+ lastArgs = Array.from({
249
+ length: inputs.length,
250
+ });
251
+ dirty = true;
252
+ }
253
+ for (var _i = 0; _i < inputs.length; _i++) {
254
+ var v = inputs[_i](data);
255
+ if (v === lastArgs[_i]) continue;
256
+ lastArgs[_i] = v;
257
+ dirty = true;
258
+ }
259
+ if (dirty) lastValue = compute.apply(null, lastArgs);
260
+ return lastValue;
261
+ };
262
+ }
263
+ var selector = function selector(data) {
264
+ return compute.apply(
265
+ null,
266
+ inputs.map(function (s) {
267
+ return s(data);
268
+ })
269
+ );
270
+ };
271
+ selector.memoize = memoize;
272
+ return selector;
273
+ }
274
+
275
+ /*
276
+ Helper usage example
277
+
278
+ Expression.registerHelper('_', _);
279
+ let e = Expression.compile('_.min({data})');
280
+ */
281
+
282
+ var expCache = {},
283
+ helpers = {},
284
+ helperNames = [],
285
+ helperValues = [],
286
+ expFatArrows = null;
287
+ function getExpr(expr) {
288
+ if (expr.memoize) return expr;
289
+ function memoize() {
290
+ var lastValue,
291
+ lastRunBindings = {},
292
+ lastRunResults = {},
293
+ getters = {},
294
+ currentData,
295
+ len = -1;
296
+ var get = function get(bindingWithFormat) {
297
+ var getter = getters[bindingWithFormat];
298
+ if (!getter) {
299
+ var binding = bindingWithFormat,
300
+ format;
301
+ var colonIndex = bindingWithFormat.indexOf(":");
302
+ if (colonIndex != -1) {
303
+ format = Format.parse(bindingWithFormat.substring(colonIndex + 1));
304
+ binding = bindingWithFormat.substring(0, colonIndex);
305
+ } else {
306
+ var nullSeparatorIndex = bindingWithFormat.indexOf(":");
307
+ if (nullSeparatorIndex != -1) {
308
+ format = Format.parse(bindingWithFormat.substring(nullSeparatorIndex));
309
+ binding = bindingWithFormat.substring(0, nullSeparatorIndex - 1);
310
+ }
311
+ }
312
+ var b = Binding.get(binding);
313
+ getter = function getter(data) {
314
+ var value = b.value(data);
315
+ lastRunBindings[len] = b.value;
316
+ lastRunResults[len] = value;
317
+ len++;
318
+ return value;
319
+ };
320
+ if (format) {
321
+ var valueGetter = getter;
322
+ getter = function getter(data) {
323
+ return format(valueGetter(data));
324
+ };
325
+ }
326
+ getters[bindingWithFormat] = getter;
327
+ }
328
+ return getter(currentData);
329
+ };
330
+ return function (data) {
331
+ var i = 0;
332
+ for (; i < len; i++) if (lastRunBindings[i](data) !== lastRunResults[i]) break;
333
+ if (i !== len) {
334
+ len = 0;
335
+ currentData = data;
336
+ lastValue = expr(get);
337
+ }
338
+ return lastValue;
339
+ };
340
+ }
341
+ var result = memoize();
342
+ result.memoize = memoize;
343
+ return result;
344
+ }
345
+ function expression(str) {
346
+ if (isFunction(str)) return getExpr(str);
347
+ var r = expCache[str];
348
+ if (r) return r;
349
+ var quote = false;
350
+ var termStart = -1,
351
+ curlyBrackets = 0,
352
+ percentExpression;
353
+ var fb = ["return ("];
354
+ var args = {};
355
+ var formats = [];
356
+ var subExpr = 0;
357
+ for (var i = 0; i < str.length; i++) {
358
+ var c = str[i];
359
+ switch (c) {
360
+ case "{":
361
+ if (curlyBrackets > 0) curlyBrackets++;
362
+ else {
363
+ if (!quote && termStart < 0 && (str[i + 1] != "{" || str[i - 1] == "%")) {
364
+ termStart = i + 1;
365
+ curlyBrackets = 1;
366
+ percentExpression = str[i - 1] == "%";
367
+ if (percentExpression) fb.pop(); //%
368
+ } else if (str[i - 1] != "{") fb.push(c);
369
+ }
370
+ break;
371
+ case "}":
372
+ if (termStart >= 0) {
373
+ if (--curlyBrackets == 0) {
374
+ var term = str.substring(termStart, i);
375
+ var formatStart = 0;
376
+ if (term[0] == "[") formatStart = term.indexOf("]");
377
+ var colon = term.indexOf(":", formatStart > 0 ? formatStart : 0);
378
+ var binding = colon == -1 ? term : term.substring(0, colon);
379
+ var format = colon == -1 ? null : term.substring(colon + 1);
380
+ if (colon == -1) {
381
+ var nullSepIndex = binding.indexOf("|", formatStart);
382
+ if (nullSepIndex != -1) {
383
+ format = binding.substring(nullSepIndex);
384
+ binding = binding.substring(0, nullSepIndex);
385
+ }
386
+ }
387
+ var argName = binding.replace(/\./g, "_");
388
+ if (isDigit(argName[0])) argName = "$" + argName;
389
+ if (percentExpression || (binding[0] == "[" && binding[binding.length - 1] == "]")) {
390
+ argName = "expr" + ++subExpr;
391
+ args[argName] = expression(percentExpression ? binding : binding.substring(1, binding.length - 1));
392
+ } else args[argName] = binding;
393
+ if (format) {
394
+ var formatter = "fmt" + formats.length;
395
+ fb.push(formatter, "(", argName, ", ", quoteStr(format), ")");
396
+ formats.push(Format.parse(format));
397
+ } else fb.push(argName);
398
+ termStart = -1;
399
+ }
400
+ } else fb.push(c);
401
+ break;
402
+ case '"':
403
+ case "'":
404
+ if (curlyBrackets == 0) {
405
+ if (!quote) quote = c;
406
+ else if (str[i - 1] != "\\" && quote == c) quote = false;
407
+ fb.push(c);
408
+ }
409
+ break;
410
+ default:
411
+ if (termStart < 0) fb.push(c);
412
+ break;
413
+ }
414
+ }
415
+ fb.push(")");
416
+ var body = fb.join("");
417
+ if (expFatArrows) body = expFatArrows(body);
418
+
419
+ //console.log(body);
420
+ var keys = Object.keys(args);
421
+ try {
422
+ var _Function;
423
+ var compute = (_Function = _construct(
424
+ Function,
425
+ formats
426
+ .map(function (f, i) {
427
+ return "fmt" + i;
428
+ })
429
+ .concat(keys, helperNames, [body])
430
+ )).bind.apply(_Function, [Format].concat(formats, helperValues));
431
+ var selector = computable.apply(
432
+ void 0,
433
+ keys
434
+ .map(function (k) {
435
+ return args[k];
436
+ })
437
+ .concat([compute])
438
+ );
439
+ expCache[str] = selector;
440
+ return selector;
441
+ } catch (err) {
442
+ throw new Error("Failed to parse expression: '" + str + "'. Error: " + err.message);
443
+ }
444
+ }
445
+ var Expression = {
446
+ get: function get(str) {
447
+ return expression(str);
448
+ },
449
+ compile: function compile(str) {
450
+ return this.get(str).memoize();
451
+ },
452
+ registerHelper: function registerHelper(name, helper) {
453
+ helpers[name] = helper;
454
+ helperNames = Object.keys(helpers);
455
+ helperValues = helperNames.map(function (n) {
456
+ return helpers[n];
457
+ });
458
+ },
459
+ };
460
+ function plugFatArrowExpansion(impl) {
461
+ expFatArrows = impl;
462
+ }
463
+ function invalidateExpressionCache() {
464
+ expCache = {};
465
+ }
466
+
467
+ function plus(str) {
468
+ return str.length ? str + " + " : str;
469
+ }
470
+ var tplCache = {};
471
+ function stringTemplate(str) {
472
+ var expr = tplCache[str];
473
+ if (expr) return expr;
474
+ expr = "";
475
+ var termStart = -1,
476
+ quoteStart = 0,
477
+ term,
478
+ bracketsOpen = 0,
479
+ percentSign;
480
+ for (var i = 0; i < str.length; i++) {
481
+ var c = str[i];
482
+ switch (c) {
483
+ case "{":
484
+ if (termStart < 0) {
485
+ if (str[i + 1] == "{" && str[i - 1] != "%") {
486
+ expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "{");
487
+ i++;
488
+ quoteStart = i + 1;
489
+ } else {
490
+ termStart = i + 1;
491
+ percentSign = str[i - 1] == "%";
492
+ if (i > quoteStart) expr = plus(expr) + quoteStr(str.substring(quoteStart, percentSign ? i - 1 : i));
493
+ bracketsOpen = 1;
494
+ }
495
+ } else bracketsOpen++;
496
+ break;
497
+ case "}":
498
+ if (termStart >= 0) {
499
+ if (--bracketsOpen == 0) {
500
+ term = str.substring(termStart, i);
501
+ if (term.indexOf(":") == -1) {
502
+ var nullSepIndex = term.indexOf("|");
503
+ if (nullSepIndex == -1) term += ":s";
504
+ else term = term.substring(0, nullSepIndex) + ":s" + term.substring(nullSepIndex);
505
+ }
506
+ expr = plus(expr) + (percentSign ? "%{" : "{") + term + "}";
507
+ termStart = -1;
508
+ quoteStart = i + 1;
509
+ bracketsOpen = 0;
510
+ }
511
+ } else if (str[i + 1] == "}") {
512
+ expr = plus(expr) + quoteStr(str.substring(quoteStart, i) + "}");
513
+ i++;
514
+ quoteStart = i + 1;
515
+ }
516
+ break;
517
+ }
518
+ }
519
+ if (quoteStart < str.length) expr = plus(expr) + quoteStr(str.substring(quoteStart));
520
+ return (tplCache[str] = expression(expr));
521
+ }
522
+ var StringTemplate = {
523
+ get: function get(str) {
524
+ return stringTemplate(str);
525
+ },
526
+ compile: function compile(str) {
527
+ return stringTemplate(str).memoize();
528
+ },
529
+ format: function format(_format) {
530
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
531
+ args[_key - 1] = arguments[_key];
532
+ }
533
+ return stringTemplate(_format)(args);
534
+ },
535
+ };
536
+ function invalidateStringTemplateCache() {
537
+ tplCache = {};
538
+ }
539
+
540
+ var Ref = /*#__PURE__*/ (function (_Component) {
541
+ _inheritsLoose(Ref, _Component);
542
+ function Ref(config) {
543
+ var _this;
544
+ _this = _Component.call(this, config) || this;
545
+ _this.get = _this.get.bind(_assertThisInitialized(_this));
546
+ if (_this.set) _this.set = _this.set.bind(_assertThisInitialized(_this));
547
+ return _this;
548
+ }
549
+ var _proto = Ref.prototype;
550
+ _proto.get = function get() {
551
+ throw new Error("Ref's get method is not implemented.");
552
+ };
553
+ _proto.init = function init(value) {
554
+ if (this.get() === undefined) this.set(value);
555
+ };
556
+ _proto.toggle = function toggle() {
557
+ this.set(!this.get());
558
+ };
559
+ _proto.update = function update(cb) {
560
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
561
+ args[_key - 1] = arguments[_key];
562
+ }
563
+ this.set(cb.apply(void 0, [this.get()].concat(args)));
564
+ };
565
+ _proto.as = function as(config) {
566
+ return Ref.create(config, {
567
+ get: this.get,
568
+ set: this.set,
569
+ });
570
+ };
571
+ _proto.ref = function ref(path) {
572
+ var _this2 = this;
573
+ var binding = Binding.get(path);
574
+ return Ref.create({
575
+ get: function get() {
576
+ return binding.value(_this2.get());
577
+ },
578
+ set: function set(value) {
579
+ var data = _this2.get();
580
+ var newData = binding.set(data, value);
581
+ if (data === newData) return false;
582
+ return _this2.set(newData);
583
+ },
584
+ });
585
+ };
586
+
587
+ //allows the function to be passed as a selector, e.g. to computable or addTrigger
588
+ _proto.memoize = function memoize() {
589
+ return this.get;
590
+ };
591
+ return Ref;
592
+ })(Component);
593
+ Ref.prototype.isRef = true;
594
+ Ref.factory = function (alias, config, more) {
595
+ if (isFunction(alias)) {
596
+ var cfg = _objectSpread2(_objectSpread2({}, config), more);
597
+ if (cfg.store) Object.assign(cfg, cfg.store.getMethods());
598
+ var result = alias(cfg);
599
+ if (result instanceof Ref) return result;
600
+ return this.create(_objectSpread2(_objectSpread2(_objectSpread2({}, config), more), result));
601
+ }
602
+ return this.create(_objectSpread2(_objectSpread2({}, config), more));
603
+ };
604
+
605
+ var StoreRef = /*#__PURE__*/ (function (_Ref) {
606
+ _inheritsLoose(StoreRef, _Ref);
607
+ function StoreRef(config) {
608
+ var _this;
609
+ _this = _Ref.call(this, config) || this;
610
+ if (isAccessorChain(_this.path)) _this.path = _this.path.toString();
611
+ return _this;
612
+ }
613
+ var _proto = StoreRef.prototype;
614
+ _proto.get = function get() {
615
+ return this.store.get(this.path);
616
+ };
617
+ _proto.set = function set(value) {
618
+ return this.store.set(this.path, value);
619
+ };
620
+ _proto.init = function init(value) {
621
+ return this.store.init(this.path, value);
622
+ };
623
+ _proto.toggle = function toggle() {
624
+ return this.store.toggle(this.path);
625
+ };
626
+ _proto["delete"] = function _delete() {
627
+ return this.store["delete"](this.path);
628
+ };
629
+ _proto.update = function update() {
630
+ var _this$store;
631
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
632
+ args[_key] = arguments[_key];
633
+ }
634
+ return (_this$store = this.store).update.apply(_this$store, [this.path].concat(args));
635
+ };
636
+
637
+ //allows the function to be passed as a selector, e.g. to computable or addTrigger
638
+ _proto.memoize = function memoize() {
639
+ return this.get;
640
+ };
641
+ _proto.ref = function ref(path) {
642
+ return new StoreRef({
643
+ path: this.path + "." + path,
644
+ store: this.store,
645
+ });
646
+ };
647
+ _proto.as = function as(config) {
648
+ return StoreRef.create(config, {
649
+ path: this.path,
650
+ store: this.store,
651
+ get: this.get,
652
+ set: this.set,
653
+ });
654
+ };
655
+ return StoreRef;
656
+ })(Ref);
657
+
658
+ var View = /*#__PURE__*/ (function () {
659
+ function View(config) {
660
+ Object.assign(this, config);
661
+ this.cache = {
662
+ version: -1,
663
+ };
664
+ if (this.store) this.setStore(this.store);
665
+ }
666
+ var _proto = View.prototype;
667
+ _proto.getData = function getData() {
668
+ throw new Error("abstract method");
669
+ };
670
+ _proto.init = function init(path, value) {
671
+ if (typeof path == "object" && path != null) {
672
+ var changed = false;
673
+ for (var key in path)
674
+ if (path.hasOwnProperty(key) && this.get(key) === undefined && this.setItem(key, path[key])) changed = true;
675
+ return changed;
676
+ }
677
+ var binding = Binding.get(path);
678
+ if (this.get(binding.path) === undefined) return this.setItem(binding.path, value);
679
+ return false;
680
+ };
681
+ _proto.set = function set(path, value) {
682
+ if (isObject(path)) {
683
+ var changed = false;
684
+ for (var key in path) if (path.hasOwnProperty(key) && this.setItem(key, path[key])) changed = true;
685
+ return changed;
686
+ }
687
+ var binding = Binding.get(path);
688
+ return this.setItem(binding.path, value);
689
+ };
690
+ _proto.copy = function copy(from, to) {
691
+ var value = this.get(from);
692
+ this.set(to, value);
693
+ };
694
+ _proto.move = function move(from, to) {
695
+ var _this = this;
696
+ this.batch(function () {
697
+ _this.copy(from, to);
698
+ _this["delete"](from);
699
+ });
700
+ };
701
+
702
+ //protected
703
+ _proto.setItem = function setItem(path, value) {
704
+ if (this.store) return this.store.setItem(path, value);
705
+ throw new Error("abstract method");
706
+ };
707
+ _proto["delete"] = function _delete(path) {
708
+ var _this2 = this;
709
+ if (arguments.length > 1) path = Array.from(arguments);
710
+ if (isArray(path))
711
+ return path
712
+ .map(function (arg) {
713
+ return _this2["delete"](arg);
714
+ })
715
+ .some(Boolean);
716
+ var binding = Binding.get(path);
717
+ return this.deleteItem(binding.path);
718
+ };
719
+
720
+ //protected
721
+ _proto.deleteItem = function deleteItem(path) {
722
+ if (this.store) return this.store.deleteItem(path);
723
+ throw new Error("abstract method");
724
+ };
725
+ _proto.clear = function clear() {
726
+ if (this.store) return this.store.clear();
727
+ throw new Error("abstract method");
728
+ };
729
+ _proto.get = function get(path) {
730
+ var storeData = this.getData();
731
+ if (arguments.length > 1) path = Array.from(arguments);
732
+ if (isArray(path))
733
+ return path.map(function (arg) {
734
+ return Binding.get(arg).value(storeData);
735
+ });
736
+ return Binding.get(path).value(storeData);
737
+ };
738
+ _proto.toggle = function toggle(path) {
739
+ return this.set(path, !this.get(path));
740
+ };
741
+ _proto.update = function update(path, updateFn) {
742
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
743
+ args[_key - 2] = arguments[_key];
744
+ }
745
+ if (arguments.length == 1 && isFunction(path))
746
+ return this.load(path.apply(null, [this.getData(), updateFn].concat(args)));
747
+ return this.set(path, updateFn.apply(null, [this.get(path)].concat(args)));
748
+ };
749
+ _proto.batch = function batch(callback) {
750
+ var dirty = this.silently(callback);
751
+ if (dirty) this.notify();
752
+ return dirty;
753
+ };
754
+ _proto.silently = function silently(callback) {
755
+ if (this.store) return this.store.silently(callback);
756
+ throw new Error("abstract method");
757
+ };
758
+ _proto.notify = function notify(path) {
759
+ if (this.notificationsSuspended) this.dirty = true;
760
+ else this.doNotify(path);
761
+ };
762
+ _proto.doNotify = function doNotify(path) {
763
+ if (this.store) return this.store.notify(path);
764
+ throw new Error("abstract method");
765
+ };
766
+ _proto.subscribe = function subscribe(callback) {
767
+ if (this.store) return this.store.subscribe(callback);
768
+ throw new Error("abstract method");
769
+ };
770
+ _proto.load = function load(data) {
771
+ return this.batch(function (store) {
772
+ for (var key in data) store.set(key, data[key]);
773
+ });
774
+ };
775
+ _proto.dispatch = function dispatch(action) {
776
+ if (this.store) return this.store.dispatch(action);
777
+ throw new Error("The underlying store doesn't support dispatch.");
778
+ };
779
+ _proto.getMeta = function getMeta() {
780
+ return this.meta;
781
+ };
782
+ _proto.setStore = function setStore(store) {
783
+ this.store = store;
784
+ this.meta = store.getMeta();
785
+ };
786
+ _proto.ref = function ref(path, defaultValue) {
787
+ if (isDefined(defaultValue)) this.init(path, defaultValue);
788
+ return StoreRef.create({
789
+ store: this,
790
+ path: path,
791
+ });
792
+ };
793
+ _proto.getMethods = function getMethods() {
794
+ return {
795
+ getData: this.getData.bind(this),
796
+ set: this.set.bind(this),
797
+ get: this.get.bind(this),
798
+ update: this.update.bind(this),
799
+ delete: this["delete"].bind(this),
800
+ toggle: this.toggle.bind(this),
801
+ init: this.init.bind(this),
802
+ ref: this.ref.bind(this),
803
+ mutate: this.ref.bind(this),
804
+ };
805
+ };
806
+ return View;
807
+ })();
808
+ View.prototype.sealed = false; //indicate that data should be copied before virtual items are added
809
+
810
+ //Immer integration point
811
+ View.prototype.mutate = function () {
812
+ throw new Error(
813
+ "Mutate requires Immer. Please install 'immer' and 'cx-immer' packages and enable store mutation by calling enableImmerMutate()."
814
+ );
815
+ };
816
+
817
+ var SubscribableView = /*#__PURE__*/ (function (_View) {
818
+ _inheritsLoose(SubscribableView, _View);
819
+ function SubscribableView(config) {
820
+ var _this;
821
+ _this = _View.call(this, config) || this;
822
+ _this.subscribers = new SubscriberList();
823
+ _this.changes = [];
824
+ return _this;
825
+ }
826
+ var _proto = SubscribableView.prototype;
827
+ _proto.subscribe = function subscribe(callback) {
828
+ return this.subscribers.subscribe(callback);
829
+ };
830
+ _proto.unsubscribeAll = function unsubscribeAll() {
831
+ this.subscribers.clear();
832
+ };
833
+ _proto.doNotify = function doNotify(path) {
834
+ var _this2 = this;
835
+ if (this.notificationsSuspended) return;
836
+ if (!this.async) {
837
+ this.subscribers.notify([path]);
838
+ } else {
839
+ this.changes.push(path || "");
840
+ if (!this.scheduled) {
841
+ this.scheduled = true;
842
+ setTimeout(function () {
843
+ _this2.scheduled = false;
844
+ var changes = _this2.changes;
845
+ _this2.changes = [];
846
+ _this2.subscribers.notify(changes);
847
+ }, 0);
848
+ }
849
+ }
850
+ };
851
+ _proto.silently = function silently(callback) {
852
+ this.notificationsSuspended = (this.notificationsSuspended || 0) + 1;
853
+ var wasDirty = this.dirty,
854
+ dirty;
855
+ this.dirty = false;
856
+ try {
857
+ callback(this);
858
+ } finally {
859
+ this.notificationsSuspended--;
860
+ dirty = this.dirty;
861
+ this.dirty = wasDirty;
862
+ }
863
+ return dirty;
864
+ };
865
+ return SubscribableView;
866
+ })(View);
867
+ SubscribableView.prototype.async = false;
868
+
869
+ var Store = /*#__PURE__*/ (function (_SubscribableView) {
870
+ _inheritsLoose(Store, _SubscribableView);
871
+ function Store(config) {
872
+ var _this;
873
+ if (config === void 0) {
874
+ config = {};
875
+ }
876
+ _this = _SubscribableView.call(this, config) || this;
877
+ _this.data = config.data || {};
878
+ _this.meta = {
879
+ version: 0,
880
+ };
881
+ return _this;
882
+ }
883
+ var _proto = Store.prototype;
884
+ _proto.getData = function getData() {
885
+ return this.data;
886
+ };
887
+ _proto.setItem = function setItem(path, value) {
888
+ var next = Binding.get(path).set(this.data, value);
889
+ if (next != this.data) {
890
+ this.data = next;
891
+ this.meta.version++;
892
+ this.notify(path);
893
+ return true;
894
+ }
895
+ return false;
896
+ };
897
+ _proto.deleteItem = function deleteItem(path) {
898
+ var next = Binding.get(path)["delete"](this.data);
899
+ if (next != this.data) {
900
+ this.data = next;
901
+ this.meta.version++;
902
+ this.notify(path);
903
+ return true;
904
+ }
905
+ return false;
906
+ };
907
+ _proto.clear = function clear() {
908
+ this.data = {};
909
+ this.meta.version++;
910
+ this.notify();
911
+ };
912
+ return Store;
913
+ })(SubscribableView);
914
+ Store.prototype.async = false;
915
+
916
+ var ExposedRecordView = /*#__PURE__*/ (function (_View) {
917
+ _inheritsLoose(ExposedRecordView, _View);
918
+ function ExposedRecordView() {
919
+ return _View.apply(this, arguments) || this;
920
+ }
921
+ var _proto = ExposedRecordView.prototype;
922
+ _proto.getData = function getData() {
923
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.itemIndex === this.itemIndex)
924
+ return this.cache.result;
925
+ this.cache.result = this.embed(this.store.getData());
926
+ this.cache.version = this.meta.version;
927
+ this.cache.itemIndex = this.itemIndex;
928
+ return this.cache.result;
929
+ };
930
+ _proto.embed = function embed(data) {
931
+ var collection = this.collectionBinding.value(data);
932
+ var record = collection[this.itemIndex];
933
+ var copy = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
934
+ copy[this.recordName] = record;
935
+ if (this.indexName) copy[this.indexName] = this.itemIndex;
936
+ return copy;
937
+ };
938
+ _proto.setIndex = function setIndex(index) {
939
+ this.itemIndex = index;
940
+ };
941
+ _proto.setItem = function setItem(path, value) {
942
+ if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
943
+ var storeData = this.store.getData();
944
+ var collection = this.collectionBinding.value(storeData);
945
+ var data = this.embed(storeData);
946
+ var d = Binding.get(path).set(data, value);
947
+ if (d === data) return false;
948
+ var record = d[this.recordName];
949
+ var newCollection = [].concat(
950
+ collection.slice(0, this.itemIndex),
951
+ [record],
952
+ collection.slice(this.itemIndex + 1)
953
+ );
954
+ return this.store.setItem(this.collectionBinding.path, newCollection);
955
+ }
956
+ return this.store.setItem(path, value);
957
+ };
958
+ _proto.deleteItem = function deleteItem(path) {
959
+ var storeData, collection, newCollection;
960
+ if (path == this.recordName) {
961
+ storeData = this.store.getData();
962
+ collection = this.collectionBinding.value(storeData);
963
+ newCollection = [].concat(collection.slice(0, this.itemIndex), collection.slice(this.itemIndex + 1));
964
+ return this.store.setItem(this.collectionBinding.path, newCollection);
965
+ } else if (path.indexOf(this.recordName + ".") == 0) {
966
+ storeData = this.store.getData();
967
+ collection = this.collectionBinding.value(storeData);
968
+ var data = this.embed(storeData);
969
+ var d = Binding.get(path)["delete"](data);
970
+ if (d === data) return false;
971
+ var record = d[this.recordName];
972
+ newCollection = [].concat(collection.slice(0, this.itemIndex), [record], collection.slice(this.itemIndex + 1));
973
+ return this.store.setItem(this.collectionBinding.path, newCollection);
974
+ }
975
+ return this.store.deleteItem(path);
976
+ };
977
+ return ExposedRecordView;
978
+ })(View);
979
+ ExposedRecordView.prototype.immutable = false;
980
+
981
+ var ExposedValueView = /*#__PURE__*/ (function (_View) {
982
+ _inheritsLoose(ExposedValueView, _View);
983
+ function ExposedValueView() {
984
+ return _View.apply(this, arguments) || this;
985
+ }
986
+ var _proto = ExposedValueView.prototype;
987
+ _proto.getData = function getData() {
988
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.key === this.key)
989
+ return this.cache.result;
990
+ var data = this.store.getData();
991
+ var container = this.containerBinding.value(data) || {};
992
+ var record = container[this.key];
993
+ this.cache.version = this.meta.version;
994
+ this.cache.key = this.key;
995
+ this.cache.result = this.sealed || this.immutable || this.store.sealed ? _objectSpread2({}, data) : data;
996
+ this.cache.result[this.recordName] = record;
997
+ return this.cache.result;
998
+ };
999
+ _proto.setKey = function setKey(key) {
1000
+ this.key = key;
1001
+ };
1002
+ _proto.getKey = function getKey() {
1003
+ return this.key;
1004
+ };
1005
+ _proto.setItem = function setItem(path, value) {
1006
+ if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
1007
+ var data = this.getData();
1008
+ var d = Binding.get(path).set(data, value);
1009
+ if (d === data) return false;
1010
+ var container = this.containerBinding.value(d);
1011
+ var record = d[this.recordName];
1012
+ var newContainer = Object.assign({}, container);
1013
+ newContainer[this.key] = record;
1014
+ return this.store.setItem(this.containerBinding.path, newContainer);
1015
+ }
1016
+ return this.store.setItem(path, value);
1017
+ };
1018
+ _proto.deleteItem = function deleteItem(path) {
1019
+ var data, container, newContainer;
1020
+ if (path == this.recordName) {
1021
+ data = this.getData();
1022
+ container = this.containerBinding.value(data);
1023
+ if (!container || !container.hasOwnProperty(path)) return false;
1024
+ newContainer = Object.assign({}, container);
1025
+ delete newContainer[this.key];
1026
+ this.store.set(this.containerBinding.path, newContainer);
1027
+ } else if (path.indexOf(this.recordName + ".") == 0) {
1028
+ data = this.getData();
1029
+ var d = Binding.get(path)["delete"](data);
1030
+ if (d === data) return false;
1031
+ container = this.containerBinding.value(d);
1032
+ var record = d[this.recordName];
1033
+ newContainer = Object.assign({}, container);
1034
+ newContainer[this.key] = record;
1035
+ return this.store.setItem(this.containerBinding.path, newContainer);
1036
+ }
1037
+ return this.store.deleteItem(path);
1038
+ };
1039
+ return ExposedValueView;
1040
+ })(View);
1041
+ ExposedValueView.prototype.immutable = false;
1042
+
1043
+ var ReadOnlyDataView = /*#__PURE__*/ (function (_View) {
1044
+ _inheritsLoose(ReadOnlyDataView, _View);
1045
+ function ReadOnlyDataView() {
1046
+ return _View.apply(this, arguments) || this;
1047
+ }
1048
+ var _proto = ReadOnlyDataView.prototype;
1049
+ _proto.getData = function getData() {
1050
+ if (this.sealed && this.meta.version === this.cache.version && this.cache.data === this.data)
1051
+ return this.cache.result;
1052
+ var data = this.store.getData();
1053
+ this.cache.result =
1054
+ this.sealed || this.immutable || this.store.sealed
1055
+ ? Object.assign({}, data, this.getAdditionalData(data))
1056
+ : Object.assign(data, this.getAdditionalData(data));
1057
+ this.cache.version = this.meta.version;
1058
+ this.cache.data = this.data;
1059
+ return this.cache.result;
1060
+ };
1061
+ _proto.getAdditionalData = function getAdditionalData() {
1062
+ return this.data;
1063
+ };
1064
+ _proto.setData = function setData(data) {
1065
+ this.data = data;
1066
+ };
1067
+ return ReadOnlyDataView;
1068
+ })(View);
1069
+ ReadOnlyDataView.prototype.immutable = false;
1070
+
1071
+ var AugmentedViewBase = /*#__PURE__*/ (function (_View) {
1072
+ _inheritsLoose(AugmentedViewBase, _View);
1073
+ function AugmentedViewBase() {
1074
+ return _View.apply(this, arguments) || this;
1075
+ }
1076
+ var _proto = AugmentedViewBase.prototype;
1077
+ _proto.getData = function getData() {
1078
+ if (this.meta.version === this.cache.version && this.sealed) return this.cache.result;
1079
+ var parentStoreData = this.store.getData();
1080
+ var result = this.getBaseData(parentStoreData);
1081
+ this.embedAugmentData(result, parentStoreData);
1082
+ this.cache.result = result;
1083
+ this.cache.parentStoreData = parentStoreData;
1084
+ this.cache.version = this.meta.version;
1085
+ return this.cache.result;
1086
+ };
1087
+ _proto.getBaseData = function getBaseData(parentStoreData) {
1088
+ if (this.sealed || this.immutable || this.store.sealed) return _objectSpread2({}, parentStoreData);
1089
+ return parentStoreData;
1090
+ };
1091
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1092
+ throw new Error("abstract");
1093
+ };
1094
+ _proto.isExtraKey = function isExtraKey(key) {
1095
+ throw new Error("abstract");
1096
+ };
1097
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1098
+ throw new Error("abstract");
1099
+ };
1100
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1101
+ throw new Error("abstract");
1102
+ };
1103
+ _proto.setItem = function setItem(path, value) {
1104
+ var binding = Binding.get(path);
1105
+ if (this.isExtraKey(binding.parts[0])) {
1106
+ var bindingRoot = binding.parts[0];
1107
+ var newValue = value;
1108
+ if (binding.parts.length > 1) {
1109
+ var data = {};
1110
+ this.embedAugmentData(data, this.store.getData());
1111
+ newValue = binding.set(data, value)[bindingRoot];
1112
+ }
1113
+ return this.setExtraKeyValue(bindingRoot, newValue);
1114
+ }
1115
+ return _View.prototype.setItem.call(this, path, value);
1116
+ };
1117
+ _proto.deleteItem = function deleteItem(path) {
1118
+ var binding = Binding.get(path);
1119
+ if (this.isExtraKey(binding.parts[0])) {
1120
+ var bindingRoot = binding.parts[0];
1121
+ if (binding.parts.length == 1) return this.deleteExtraKeyValue(bindingRoot);
1122
+ var data = {};
1123
+ this.embedAugmentData(data, this.store.getData());
1124
+ var newValue = binding["delete"](data)[bindingRoot];
1125
+ return this.setExtraKeyValue(bindingRoot, newValue);
1126
+ }
1127
+ return _View.prototype.deleteItem.call(this, path);
1128
+ };
1129
+ return AugmentedViewBase;
1130
+ })(View);
1131
+ AugmentedViewBase.prototype.immutable = false;
1132
+
1133
+ var NestedDataView = /*#__PURE__*/ (function (_AugmentedViewBase) {
1134
+ _inheritsLoose(NestedDataView, _AugmentedViewBase);
1135
+ function NestedDataView() {
1136
+ return _AugmentedViewBase.apply(this, arguments) || this;
1137
+ }
1138
+ var _proto = NestedDataView.prototype;
1139
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1140
+ if (this.nestedData) {
1141
+ var nested = this.nestedData.getSelector()(parentStoreData);
1142
+ for (var key in nested) result[key] = nested[key];
1143
+ }
1144
+ };
1145
+ _proto.isExtraKey = function isExtraKey(key) {
1146
+ return this.nestedData && this.nestedData.containsKey(key);
1147
+ };
1148
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1149
+ this.nestedData.setItem(key, value);
1150
+ };
1151
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1152
+ this.setExtraKeyValue(key, undefined);
1153
+ };
1154
+ return NestedDataView;
1155
+ })(AugmentedViewBase);
1156
+
1157
+ var ZoomIntoPropertyView = /*#__PURE__*/ (function (_NestedDataView) {
1158
+ _inheritsLoose(ZoomIntoPropertyView, _NestedDataView);
1159
+ function ZoomIntoPropertyView() {
1160
+ return _NestedDataView.apply(this, arguments) || this;
1161
+ }
1162
+ var _proto = ZoomIntoPropertyView.prototype;
1163
+ _proto.getBaseData = function getBaseData(parentStoreData) {
1164
+ var x = this.binding.value(parentStoreData);
1165
+ if (x != null && typeof x != "object") throw new Error("Zoomed value must be an object.");
1166
+ return _objectSpread2({}, x);
1167
+ };
1168
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1169
+ result[this.rootName] = parentStoreData;
1170
+ _NestedDataView.prototype.embedAugmentData.call(this, result, parentStoreData);
1171
+ };
1172
+ _proto.setItem = function setItem(path, value) {
1173
+ if (path.indexOf(this.rootName + ".") == 0) this.store.setItem(path.substring(this.rootName.length + 1), value);
1174
+ else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.setItem.call(this, path, value);
1175
+ else _NestedDataView.prototype.setItem.call(this, this.binding.path + "." + path, value);
1176
+ };
1177
+ _proto.deleteItem = function deleteItem(path) {
1178
+ if (path.indexOf(this.rootName + ".") == 0) this.store.deleteItem(path.substring(this.rootName.length + 1));
1179
+ else if (this.isExtraKey(Binding.get(path).parts[0])) _NestedDataView.prototype.deleteItem.call(this, path);
1180
+ else _NestedDataView.prototype.deleteItem.call(this, this.binding.path + "." + path);
1181
+ };
1182
+ return ZoomIntoPropertyView;
1183
+ })(NestedDataView);
1184
+ ZoomIntoPropertyView.prototype.rootName = "$root";
1185
+
1186
+ function createStructuredSelector(selector, constants) {
1187
+ var keys = Object.keys(selector);
1188
+ if (keys.length == 0)
1189
+ return function () {
1190
+ return constants;
1191
+ };
1192
+ function memoize() {
1193
+ var lastResult = Object.assign({}, constants);
1194
+ var memoizedSelectors = {};
1195
+ keys.forEach(function (key) {
1196
+ memoizedSelectors[key] = selector[key].memoize ? selector[key].memoize() : selector[key];
1197
+ lastResult[key] = undefined;
1198
+ });
1199
+ return function (data) {
1200
+ var result = lastResult,
1201
+ k,
1202
+ v,
1203
+ i;
1204
+ for (i = 0; i < keys.length; i++) {
1205
+ k = keys[i];
1206
+ v = memoizedSelectors[k](data);
1207
+ if (result === lastResult) {
1208
+ if (v === lastResult[k]) continue;
1209
+ result = Object.assign({}, lastResult);
1210
+ }
1211
+ result[k] = v;
1212
+ }
1213
+ return (lastResult = result);
1214
+ };
1215
+ }
1216
+ function evaluate(data) {
1217
+ var result = Object.assign({}, constants);
1218
+ for (var i = 0; i < keys.length; i++) {
1219
+ result[keys[i]] = selector[keys[i]](data);
1220
+ }
1221
+ return result;
1222
+ }
1223
+ evaluate.memoize = memoize;
1224
+ return evaluate;
1225
+ }
1226
+
1227
+ function isSelector(config) {
1228
+ if (config == null) return true;
1229
+ switch (typeof config) {
1230
+ case "object":
1231
+ if (config.type || config.$type) return false;
1232
+ return !!(config.bind || config.tpl || config.expr || config.get);
1233
+ case "function":
1234
+ return true;
1235
+ case "string":
1236
+ return true;
1237
+ case "number":
1238
+ return true;
1239
+ case "boolean":
1240
+ return true;
1241
+ }
1242
+ return false;
1243
+ }
1244
+
1245
+ var undefinedF = function undefinedF() {
1246
+ return undefined;
1247
+ };
1248
+ var nullF = function nullF() {
1249
+ return null;
1250
+ };
1251
+ function getSelector(config) {
1252
+ if (config === undefined) return undefinedF;
1253
+ if (config === null) return nullF;
1254
+ switch (typeof config) {
1255
+ case "object":
1256
+ if (isArray(config)) {
1257
+ var _selectors = config.map(function (x) {
1258
+ return getSelector(x);
1259
+ });
1260
+ return function (data) {
1261
+ return _selectors.map(function (elementSelector) {
1262
+ return elementSelector(data);
1263
+ });
1264
+ };
1265
+ }
1266
+
1267
+ //toString converts accessor chains to binding paths
1268
+ if (config.bind) return Binding.get(config.bind.toString()).value;
1269
+ if (config.tpl) return StringTemplate.get(config.tpl);
1270
+ if (config.expr) return Expression.get(config.expr);
1271
+ if (config.get) return config.get;
1272
+ var selectors = {};
1273
+ var constants = {};
1274
+ for (var key in config) {
1275
+ if (isSelector(config[key])) selectors[key] = getSelector(config[key]);
1276
+ else constants[key] = config[key];
1277
+ }
1278
+ return createStructuredSelector(selectors, constants);
1279
+ case "function":
1280
+ if (isAccessorChain(config)) return Binding.get(config.toString()).value;
1281
+ return config;
1282
+ default:
1283
+ return function () {
1284
+ return config;
1285
+ };
1286
+ }
1287
+ }
1288
+
1289
+ function defaultValue(pv) {
1290
+ if (typeof pv == "object" && pv && pv.structured) return pv.defaultValue;
1291
+ return pv;
1292
+ }
1293
+ function getSelectorConfig(props, values, nameMap) {
1294
+ var functions = {},
1295
+ structures = {},
1296
+ defaultValues = {},
1297
+ constants,
1298
+ p,
1299
+ v,
1300
+ pv,
1301
+ constant = true;
1302
+ for (p in props) {
1303
+ v = values[p];
1304
+ pv = props[p];
1305
+ if (isUndefined(v) && pv && (pv.bind || pv.tpl || pv.expr)) v = pv;
1306
+ if (v === null) {
1307
+ if (!constants) constants = {};
1308
+ constants[p] = null;
1309
+ } else if (typeof v == "object") {
1310
+ if (v.bind) {
1311
+ if (isUndefined(v.defaultValue) && v != pv) v.defaultValue = defaultValue(pv);
1312
+ if (isDefined(v.defaultValue)) defaultValues[v.bind] = v.defaultValue;
1313
+ nameMap[p] = v.bind;
1314
+ functions[p] = Binding.get(v.bind).value;
1315
+ constant = false;
1316
+ } else if (v.expr) {
1317
+ functions[p] = Expression.get(v.expr);
1318
+ constant = false;
1319
+ } else if (v.get) {
1320
+ functions[p] = v.get;
1321
+ constant = false;
1322
+ } else if (v.tpl) {
1323
+ functions[p] = StringTemplate.get(v.tpl);
1324
+ constant = false;
1325
+ } else if (pv && typeof pv == "object" && pv.structured) {
1326
+ if (isArray(v)) functions[p] = getSelector(v);
1327
+ else {
1328
+ var s = getSelectorConfig(v, v, {});
1329
+ structures[p] = s;
1330
+ Object.assign(defaultValues, s.defaultValues);
1331
+ }
1332
+ constant = false;
1333
+ } else {
1334
+ if (!constants) constants = {};
1335
+ constants[p] = v;
1336
+ }
1337
+ } else if (isFunction(v)) {
1338
+ if (isAccessorChain(v)) {
1339
+ var path = v.toString();
1340
+ nameMap[p] = path;
1341
+ functions[p] = Binding.get(path).value;
1342
+ } else functions[p] = v;
1343
+ constant = false;
1344
+ } else {
1345
+ if (isUndefined(v)) {
1346
+ if (isUndefined(pv)) continue;
1347
+ v = defaultValue(pv);
1348
+ }
1349
+ if (isUndefined(v)) continue;
1350
+ if (!constants) constants = {};
1351
+ constants[p] = v;
1352
+ }
1353
+ }
1354
+ return {
1355
+ functions: functions,
1356
+ structures: structures,
1357
+ defaultValues: defaultValues,
1358
+ constants: constants,
1359
+ constant: constant,
1360
+ };
1361
+ }
1362
+ function createSelector(_ref) {
1363
+ var functions = _ref.functions,
1364
+ structures = _ref.structures,
1365
+ constants = _ref.constants;
1366
+ _ref.defaultValues;
1367
+ var selector = {};
1368
+ for (var n in functions) {
1369
+ selector[n] = functions[n];
1370
+ }
1371
+ for (var _n in structures) selector[_n] = createSelector(structures[_n]);
1372
+ return createStructuredSelector(selector, constants);
1373
+ }
1374
+ var StructuredSelector = /*#__PURE__*/ (function () {
1375
+ function StructuredSelector(_ref2) {
1376
+ var props = _ref2.props,
1377
+ values = _ref2.values;
1378
+ this.nameMap = {};
1379
+ this.config = getSelectorConfig(props, values, this.nameMap);
1380
+ }
1381
+ var _proto = StructuredSelector.prototype;
1382
+ _proto.init = function init(store) {
1383
+ store.init(this.config.defaultValues);
1384
+ };
1385
+ _proto.create = function create(memoize) {
1386
+ if (memoize === void 0) {
1387
+ memoize = true;
1388
+ }
1389
+ var selector = createSelector(this.config);
1390
+ if (memoize && selector.memoize) return selector.memoize();
1391
+ return selector;
1392
+ };
1393
+ _proto.createStoreSelector = function createStoreSelector() {
1394
+ if (this.config.constant) {
1395
+ var result = _objectSpread2({}, this.config.constants);
1396
+ return function () {
1397
+ return result;
1398
+ };
1399
+ }
1400
+ var selector = this.create();
1401
+ return function (store) {
1402
+ return selector(store.getData());
1403
+ };
1404
+ };
1405
+ return StructuredSelector;
1406
+ })();
1407
+
1408
+ var AggregateFunction = /*#__PURE__*/ (function () {
1409
+ function AggregateFunction() {}
1410
+ AggregateFunction.sum = function sum() {
1411
+ return new Sum();
1412
+ };
1413
+ AggregateFunction.avg = function avg() {
1414
+ return new Avg();
1415
+ };
1416
+ AggregateFunction.count = function count() {
1417
+ return new Count();
1418
+ };
1419
+ AggregateFunction.distinct = function distinct() {
1420
+ return new Distinct();
1421
+ };
1422
+ AggregateFunction.min = function min() {
1423
+ return new Min();
1424
+ };
1425
+ AggregateFunction.max = function max() {
1426
+ return new Max();
1427
+ };
1428
+ return AggregateFunction;
1429
+ })();
1430
+ var Sum = /*#__PURE__*/ (function () {
1431
+ function Sum() {}
1432
+ var _proto = Sum.prototype;
1433
+ _proto.process = function process(value) {
1434
+ this.empty = false;
1435
+ if (!isNaN(value)) this.result += value;
1436
+ else this.invalid = true;
1437
+ };
1438
+ _proto.getResult = function getResult() {
1439
+ if (this.invalid) return null;
1440
+ return this.result;
1441
+ };
1442
+ return Sum;
1443
+ })();
1444
+ Sum.prototype.result = 0;
1445
+ Sum.prototype.empty = true;
1446
+ var Avg = /*#__PURE__*/ (function () {
1447
+ function Avg() {}
1448
+ var _proto2 = Avg.prototype;
1449
+ _proto2.process = function process(value, count) {
1450
+ if (count === void 0) {
1451
+ count = 1;
1452
+ }
1453
+ this.empty = false;
1454
+ if (!isNaN(value) && !isNaN(count)) {
1455
+ this.result += value * count;
1456
+ this.count += count;
1457
+ } else this.invalid = true;
1458
+ };
1459
+ _proto2.getResult = function getResult() {
1460
+ if (this.empty || this.invalid || this.count == 0) return null;
1461
+ return this.result / this.count;
1462
+ };
1463
+ return Avg;
1464
+ })();
1465
+ Avg.prototype.result = 0;
1466
+ Avg.prototype.count = 0;
1467
+ Avg.prototype.empty = true;
1468
+ var Count = /*#__PURE__*/ (function () {
1469
+ function Count() {}
1470
+ var _proto3 = Count.prototype;
1471
+ _proto3.process = function process(value) {
1472
+ if (value != null) this.result++;
1473
+ };
1474
+ _proto3.getResult = function getResult() {
1475
+ return this.result;
1476
+ };
1477
+ return Count;
1478
+ })();
1479
+ Count.prototype.result = 0;
1480
+ var Distinct = /*#__PURE__*/ (function () {
1481
+ function Distinct() {
1482
+ this.values = {};
1483
+ }
1484
+ var _proto4 = Distinct.prototype;
1485
+ _proto4.process = function process(value) {
1486
+ if (value == null || this.values[value]) return;
1487
+ this.values[value] = true;
1488
+ this.empty = false;
1489
+ this.result++;
1490
+ };
1491
+ _proto4.getResult = function getResult() {
1492
+ if (this.empty || this.invalid) return null;
1493
+ return this.result;
1494
+ };
1495
+ return Distinct;
1496
+ })();
1497
+ Distinct.prototype.result = 0;
1498
+ Distinct.prototype.empty = true;
1499
+ var Max = /*#__PURE__*/ (function () {
1500
+ function Max() {}
1501
+ var _proto5 = Max.prototype;
1502
+ _proto5.process = function process(value) {
1503
+ if (!isNaN(value)) {
1504
+ if (this.empty) this.result = value;
1505
+ else if (value > this.result) this.result = value;
1506
+ this.empty = false;
1507
+ } else if (value != null) this.invalid = true;
1508
+ };
1509
+ _proto5.getResult = function getResult() {
1510
+ if (this.empty || this.invalid) return null;
1511
+ return this.result;
1512
+ };
1513
+ return Max;
1514
+ })();
1515
+ Max.prototype.result = 0;
1516
+ Max.prototype.empty = true;
1517
+ var Min = /*#__PURE__*/ (function () {
1518
+ function Min() {}
1519
+ var _proto6 = Min.prototype;
1520
+ _proto6.process = function process(value) {
1521
+ if (!isNaN(value)) {
1522
+ if (this.empty) this.result = value;
1523
+ else if (value < this.result) this.result = value;
1524
+ this.empty = false;
1525
+ } else if (value != null) this.invalid = true;
1526
+ };
1527
+ _proto6.getResult = function getResult() {
1528
+ if (this.empty || this.invalid) return null;
1529
+ return this.result;
1530
+ };
1531
+ return Min;
1532
+ })();
1533
+ Min.prototype.result = 0;
1534
+ Min.prototype.empty = true;
1535
+
1536
+ /*
1537
+ 'column': {
1538
+ index: 0,
1539
+ sort: 'asc',
1540
+ group: true
1541
+ aggregate: 'count'
1542
+ }
1543
+ */
1544
+
1545
+ function transform(o, f) {
1546
+ var res = {};
1547
+ for (var k in o) res[k] = f(o[k], k);
1548
+ return res;
1549
+ }
1550
+ var Grouper = /*#__PURE__*/ (function () {
1551
+ function Grouper(key, aggregates, dataGetter, nameGetter) {
1552
+ this.keys = Object.keys(key).map(function (k) {
1553
+ return {
1554
+ name: k,
1555
+ value: getSelector(key[k]),
1556
+ };
1557
+ });
1558
+ if (nameGetter) this.nameGetter = getSelector(nameGetter);
1559
+ this.dataGetter =
1560
+ dataGetter ||
1561
+ function (x) {
1562
+ return x;
1563
+ };
1564
+ this.aggregates =
1565
+ aggregates &&
1566
+ transform(aggregates, function (prop) {
1567
+ if (!AggregateFunction[prop.type]) throw new Error("Unknown aggregate function '" + prop.type + "'.");
1568
+ return {
1569
+ value: getSelector(prop.value),
1570
+ weight: getSelector(prop.weight || 1),
1571
+ type: prop.type,
1572
+ };
1573
+ });
1574
+ this.reset();
1575
+ }
1576
+ var _proto = Grouper.prototype;
1577
+ _proto.reset = function reset() {
1578
+ this.groups = this.initGroup(this.keys.length == 0);
1579
+ };
1580
+ _proto.initGroup = function initGroup(leaf) {
1581
+ if (!leaf) return {};
1582
+ return {
1583
+ records: [],
1584
+ indexes: [],
1585
+ aggregates:
1586
+ this.aggregates &&
1587
+ transform(this.aggregates, function (prop) {
1588
+ var f = AggregateFunction[prop.type];
1589
+ return {
1590
+ processor: f(),
1591
+ value: prop.value,
1592
+ weight: prop.weight,
1593
+ };
1594
+ }),
1595
+ };
1596
+ };
1597
+ _proto.process = function process(record, index) {
1598
+ var data = this.dataGetter(record);
1599
+ var key = this.keys.map(function (k) {
1600
+ return k.value(data);
1601
+ });
1602
+ var g = this.groups;
1603
+ for (var i = 0; i < key.length; i++) {
1604
+ var sg = g[key[i]];
1605
+ if (!sg) {
1606
+ sg = g[key[i]] = this.initGroup(i + 1 == key.length);
1607
+ if (this.nameGetter) sg.name = this.nameGetter(data);
1608
+ }
1609
+ g = sg;
1610
+ }
1611
+ g.records.push(record);
1612
+ g.indexes.push(index);
1613
+ if (g.aggregates) {
1614
+ for (var k in g.aggregates)
1615
+ g.aggregates[k].processor.process(g.aggregates[k].value(data), g.aggregates[k].weight(data));
1616
+ }
1617
+ };
1618
+ _proto.processAll = function processAll(records, indexes) {
1619
+ var _this = this;
1620
+ if (indexes) {
1621
+ for (var i = 0; i < records.length; i++) this.process(records[i], indexes[i]);
1622
+ } else
1623
+ records.forEach(function (r, i) {
1624
+ return _this.process(r, i);
1625
+ });
1626
+ };
1627
+ _proto.report = function report(g, path, level, results) {
1628
+ var _this2 = this;
1629
+ if (level == this.keys.length) {
1630
+ var key = {};
1631
+ this.keys.forEach(function (k, i) {
1632
+ return (key[k.name] = path[i]);
1633
+ });
1634
+ results.push({
1635
+ key: key,
1636
+ name: g.name,
1637
+ records: g.records,
1638
+ indexes: g.indexes,
1639
+ aggregates: transform(g.aggregates, function (p) {
1640
+ return p.processor.getResult();
1641
+ }),
1642
+ });
1643
+ } else {
1644
+ Object.keys(g).forEach(function (k) {
1645
+ return _this2.report(g[k], [].concat(path, [k]), level + 1, results);
1646
+ });
1647
+ }
1648
+ };
1649
+ _proto.getResults = function getResults() {
1650
+ var g = this.groups;
1651
+ var results = [];
1652
+ this.report(g, [], 0, results);
1653
+ return results;
1654
+ };
1655
+ return Grouper;
1656
+ })();
1657
+
1658
+ function defaultCompare(av, bv) {
1659
+ if (av == null) {
1660
+ if (bv == null) return 0;
1661
+ return -1;
1662
+ }
1663
+ if (bv == null || av > bv) return 1;
1664
+ if (av < bv) return -1;
1665
+ return 0;
1666
+ }
1667
+
1668
+ function getComparer(sorters, dataAccessor, comparer) {
1669
+ var resolvedSorters = (sorters || []).map(function (s) {
1670
+ var selector = isDefined(s.value)
1671
+ ? getSelector(s.value)
1672
+ : s.field
1673
+ ? function (x) {
1674
+ return x[s.field];
1675
+ }
1676
+ : function () {
1677
+ return null;
1678
+ };
1679
+ return {
1680
+ getter: dataAccessor
1681
+ ? function (x) {
1682
+ return selector(dataAccessor(x));
1683
+ }
1684
+ : selector,
1685
+ factor: s.direction && s.direction[0].toLowerCase() == "d" ? -1 : 1,
1686
+ compare: s.comparer || s.compare || comparer || defaultCompare,
1687
+ };
1688
+ });
1689
+ return function (a, b) {
1690
+ var d, av, bv;
1691
+ for (var i = 0; i < resolvedSorters.length; i++) {
1692
+ d = resolvedSorters[i];
1693
+ av = d.getter(a);
1694
+ bv = d.getter(b);
1695
+
1696
+ // show nulls always on the bottom
1697
+ if (av == null) {
1698
+ if (bv == null) continue;
1699
+ else return 1;
1700
+ }
1701
+ if (bv == null) return -1;
1702
+ var r = d.compare(av, bv);
1703
+ if (r == 0) continue;
1704
+ return d.factor * r;
1705
+ }
1706
+ return 0;
1707
+ };
1708
+ }
1709
+ function indexSorter(sorters, dataAccessor, compare) {
1710
+ var cmp = getComparer(sorters, dataAccessor, compare);
1711
+ return function (data) {
1712
+ var result = Array.from(
1713
+ {
1714
+ length: data.length,
1715
+ },
1716
+ function (v, k) {
1717
+ return k;
1718
+ }
1719
+ );
1720
+ result.sort(function (ia, ib) {
1721
+ return cmp(data[ia], data[ib]);
1722
+ });
1723
+ return result;
1724
+ };
1725
+ }
1726
+ function sorter(sorters, dataAccessor, compare) {
1727
+ var cmp = getComparer(sorters, dataAccessor, compare);
1728
+ return function (data) {
1729
+ var result = [].concat(data);
1730
+ result.sort(cmp);
1731
+ return result;
1732
+ };
1733
+ }
1734
+
1735
+ function enableFatArrowExpansion() {
1736
+ plugFatArrowExpansion(expandFatArrows);
1737
+ }
1738
+
1739
+ function append(array) {
1740
+ for (var _len = arguments.length, items = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1741
+ items[_key - 1] = arguments[_key];
1742
+ }
1743
+ if (items.length == 0) return array;
1744
+ if (!array) return items;
1745
+ return [].concat(array, items);
1746
+ }
1747
+
1748
+ function merge(item, data) {
1749
+ var result = item;
1750
+ if (data) for (var key in data) result = Binding.get(key).set(result, data[key]);
1751
+ return result;
1752
+ }
1753
+
1754
+ function filter(array, callback) {
1755
+ if (array == null) return array;
1756
+ var result = array.filter(callback);
1757
+ if (result.length == array.length) return array;
1758
+ return result;
1759
+ }
1760
+
1761
+ function updateArray(array, updateCallback, itemFilter, removeFilter) {
1762
+ if (!array) return array;
1763
+ var newArray = [];
1764
+ var dirty = false;
1765
+ for (var index = 0; index < array.length; index++) {
1766
+ var item = array[index];
1767
+ if (removeFilter && removeFilter(item, index)) {
1768
+ dirty = true;
1769
+ continue;
1770
+ }
1771
+ if (!itemFilter || itemFilter(item, index)) {
1772
+ var newItem = updateCallback(item, index);
1773
+ newArray.push(newItem);
1774
+ if (newItem !== item) dirty = true;
1775
+ } else newArray.push(item);
1776
+ }
1777
+ return dirty ? newArray : array;
1778
+ }
1779
+
1780
+ function updateTree(array, updateCallback, itemFilter, childrenField, removeFilter) {
1781
+ return updateArray(
1782
+ array,
1783
+ function (item) {
1784
+ var _objectSpread2$1;
1785
+ if (!itemFilter || itemFilter(item)) item = updateCallback(item);
1786
+ var children = item[childrenField];
1787
+ if (!Array.isArray(children)) return item;
1788
+ var updatedChildren = updateTree(children, updateCallback, itemFilter, childrenField, removeFilter);
1789
+ if (updatedChildren != children)
1790
+ return _objectSpread2(
1791
+ _objectSpread2({}, item),
1792
+ {},
1793
+ ((_objectSpread2$1 = {}), (_objectSpread2$1[childrenField] = updatedChildren), _objectSpread2$1)
1794
+ );
1795
+ return item;
1796
+ },
1797
+ null,
1798
+ removeFilter
1799
+ );
1800
+ }
1801
+
1802
+ function removeTreeNodes(array, criteria, childrenField) {
1803
+ if (childrenField === void 0) {
1804
+ childrenField = "$children";
1805
+ }
1806
+ return updateTree(
1807
+ array,
1808
+ null,
1809
+ function () {
1810
+ return false;
1811
+ },
1812
+ childrenField,
1813
+ criteria
1814
+ );
1815
+ }
1816
+
1817
+ function findTreeNode(array, criteria, childrenField) {
1818
+ if (childrenField === void 0) {
1819
+ childrenField = "$children";
1820
+ }
1821
+ if (!Array.isArray(array)) return false;
1822
+ for (var i = 0; i < array.length; i++) {
1823
+ if (criteria(array[i])) return array[i];
1824
+ var child = findTreeNode(array[i][childrenField], criteria, childrenField);
1825
+ if (child) return child;
1826
+ }
1827
+ return false;
1828
+ }
1829
+
1830
+ function moveElement(array, sourceIndex, targetIndex) {
1831
+ if (targetIndex == sourceIndex) return array;
1832
+ var el = array[sourceIndex];
1833
+ var res = [].concat(array);
1834
+ if (sourceIndex < targetIndex) {
1835
+ for (var i = sourceIndex; i + 1 < targetIndex; i++) res[i] = res[i + 1];
1836
+ targetIndex--;
1837
+ } else {
1838
+ for (var _i = sourceIndex; _i > targetIndex; _i--) res[_i] = res[_i - 1];
1839
+ }
1840
+ res[targetIndex] = el;
1841
+ return res;
1842
+ }
1843
+
1844
+ function insertElement(array, index) {
1845
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1846
+ args[_key - 2] = arguments[_key];
1847
+ }
1848
+ return [].concat(array.slice(0, index), args, array.slice(index));
1849
+ }
1850
+
1851
+ function findTreePath(array, criteria, childrenField, currentPath) {
1852
+ if (childrenField === void 0) {
1853
+ childrenField = "$children";
1854
+ }
1855
+ if (currentPath === void 0) {
1856
+ currentPath = [];
1857
+ }
1858
+ if (!Array.isArray(array)) return false;
1859
+ for (var i = 0; i < array.length; i++) {
1860
+ currentPath.push(array[i]);
1861
+ if (criteria(array[i])) return currentPath;
1862
+ var childPath = findTreePath(array[i][childrenField], criteria, childrenField, currentPath);
1863
+ if (childPath) return childPath;
1864
+ currentPath.pop();
1865
+ }
1866
+ return false;
1867
+ }
1868
+
1869
+ function diffArrays(oldArray, newArray, keyFn) {
1870
+ if (!keyFn)
1871
+ keyFn = function keyFn(e) {
1872
+ return e;
1873
+ };
1874
+ var map = new Map();
1875
+ for (var i = 0; i < oldArray.length; i++) map.set(keyFn(oldArray[i]), oldArray[i]);
1876
+ var added = [],
1877
+ changed = [],
1878
+ unchanged = [];
1879
+ for (var _i = 0; _i < newArray.length; _i++) {
1880
+ var el = newArray[_i];
1881
+ var k = keyFn(el);
1882
+ var old = map.get(k);
1883
+ if (isUndefined(old)) added.push(el);
1884
+ else {
1885
+ map["delete"](k);
1886
+ if (el == old) unchanged.push(el);
1887
+ else
1888
+ changed.push({
1889
+ before: old,
1890
+ after: el,
1891
+ });
1892
+ }
1893
+ }
1894
+ var removed = Array.from(map.values());
1895
+ return {
1896
+ added: added,
1897
+ changed: changed,
1898
+ unchanged: unchanged,
1899
+ removed: removed,
1900
+ };
1901
+ }
1902
+
1903
+ var ArrayRef = /*#__PURE__*/ (function (_Ref) {
1904
+ _inheritsLoose(ArrayRef, _Ref);
1905
+ function ArrayRef() {
1906
+ return _Ref.apply(this, arguments) || this;
1907
+ }
1908
+ var _proto = ArrayRef.prototype;
1909
+ _proto.append = function append$1() {
1910
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1911
+ args[_key] = arguments[_key];
1912
+ }
1913
+ this.update.apply(this, [append].concat(args));
1914
+ };
1915
+ _proto.insert = function insert(index) {
1916
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1917
+ args[_key2 - 1] = arguments[_key2];
1918
+ }
1919
+ this.update.apply(this, [insertElement].concat(args));
1920
+ };
1921
+ _proto.filter = function filter(predicate) {
1922
+ this.update(function (array) {
1923
+ return array.filter(function (a) {
1924
+ return predicate(a);
1925
+ });
1926
+ });
1927
+ };
1928
+ _proto.move = function move(fromIndex, toIndex) {
1929
+ this.update(moveElement, fromIndex, toIndex);
1930
+ };
1931
+ _proto.clear = function clear() {
1932
+ this.set([]);
1933
+ };
1934
+ _proto.sort = function sort(compare) {
1935
+ var data = this.get();
1936
+ if (!data) return;
1937
+ var x = [].concat(data);
1938
+ x.sort(compare);
1939
+ this.set(x);
1940
+ };
1941
+ return ArrayRef;
1942
+ })(Ref);
1943
+
1944
+ var StoreProxy = /*#__PURE__*/ (function (_View) {
1945
+ _inheritsLoose(StoreProxy, _View);
1946
+ function StoreProxy(getStore) {
1947
+ var _this;
1948
+ _this =
1949
+ _View.call(this, {
1950
+ store: getStore(),
1951
+ }) || this;
1952
+ Object.defineProperty(_assertThisInitialized(_this), "store", {
1953
+ get: getStore,
1954
+ });
1955
+ return _this;
1956
+ }
1957
+ var _proto = StoreProxy.prototype;
1958
+ _proto.getData = function getData() {
1959
+ return this.store.getData();
1960
+ };
1961
+ return StoreProxy;
1962
+ })(View);
1963
+
1964
+ var ArrayElementView = /*#__PURE__*/ (function (_AugmentedViewBase) {
1965
+ _inheritsLoose(ArrayElementView, _AugmentedViewBase);
1966
+ function ArrayElementView() {
1967
+ return _AugmentedViewBase.apply(this, arguments) || this;
1968
+ }
1969
+ var _proto = ArrayElementView.prototype;
1970
+ _proto.isExtraKey = function isExtraKey(key) {
1971
+ return key == this.recordAlias || key == this.indexAlias || key == this.lengthAlias;
1972
+ };
1973
+ _proto.deleteExtraKeyValue = function deleteExtraKeyValue(key) {
1974
+ if (key != this.recordAlias) throw new Error("Field " + key + " cannot be deleted.");
1975
+ var array = this.arrayAccessor.get(this.store.getData());
1976
+ if (!array) return false;
1977
+ var newArray = [].concat(array.slice(0, this.itemIndex), array.slice(this.itemIndex + 1));
1978
+ return this.arrayAccessor.set(newArray, this.store);
1979
+ };
1980
+ _proto.setExtraKeyValue = function setExtraKeyValue(key, value) {
1981
+ if (key != this.recordAlias) throw new Error("Field " + key + " is read-only.");
1982
+ var array = this.arrayAccessor.get(this.store.getData());
1983
+ if (!array || value === array[this.itemIndex]) return false;
1984
+ var newArray = [].concat(array.slice(0, this.itemIndex), [value], array.slice(this.itemIndex + 1));
1985
+ return this.arrayAccessor.set(newArray, this.store);
1986
+ };
1987
+ _proto.embedAugmentData = function embedAugmentData(result, parentStoreData) {
1988
+ var array = this.arrayAccessor.get(parentStoreData);
1989
+ if (!isArray(array)) return;
1990
+ result[this.recordAlias] = array[this.itemIndex];
1991
+ result[this.indexAlias] = this.itemIndex;
1992
+ result[this.lengthAlias] = array.length;
1993
+ };
1994
+ _proto.setIndex = function setIndex(itemIndex) {
1995
+ this.itemIndex = itemIndex;
1996
+ };
1997
+ return ArrayElementView;
1998
+ })(AugmentedViewBase);
1999
+ ArrayElementView.prototype.recordAlias = "$record";
2000
+ ArrayElementView.prototype.indexAlias = "$index";
2001
+ ArrayElementView.prototype.lengthAlias = "$length";
2002
+
2003
+ /*
2004
+ Accessor provides a common ground between refs and bindings.
2005
+ Refs offer simplicity, bindings have better performance with more arguments.
2006
+ Accessor works as a common interface which works with both patterns.
2007
+ */
2008
+
2009
+ function getAccessor(accessor, options) {
2010
+ if (accessor == null) return null;
2011
+ if (isObject(accessor)) {
2012
+ if (accessor.isAccessor || accessor.isRef) return accessor;
2013
+ if (isBinding(accessor)) {
2014
+ var binding = Binding.get(accessor);
2015
+ return {
2016
+ get: binding.value,
2017
+ set: function set(v, store) {
2018
+ return store.set(binding.path, v);
2019
+ },
2020
+ isAccessor: true,
2021
+ };
2022
+ }
2023
+ }
2024
+ if (isAccessorChain(accessor)) {
2025
+ var _binding = Binding.get(accessor);
2026
+ return {
2027
+ get: _binding.value,
2028
+ set: function set(v, store) {
2029
+ return store.set(_binding.path, v);
2030
+ },
2031
+ isAccessor: true,
2032
+ };
2033
+ }
2034
+ if (isSelector(accessor)) {
2035
+ var selector = getSelector(accessor);
2036
+ if (accessor && accessor.set)
2037
+ return {
2038
+ get: selector,
2039
+ isAccessor: true,
2040
+ bindInstance: function bindInstance(instance) {
2041
+ return {
2042
+ get: selector,
2043
+ set: function set(value) {
2044
+ return accessor.set(value, instance);
2045
+ },
2046
+ isAccessor: true,
2047
+ };
2048
+ },
2049
+ };
2050
+ return {
2051
+ get: selector,
2052
+ isAccessor: true,
2053
+ };
2054
+ }
2055
+ return {
2056
+ get: function get() {
2057
+ return accessor;
2058
+ },
2059
+ };
2060
+ }
2061
+
2062
+ export {
2063
+ ArrayElementView,
2064
+ ArrayRef,
2065
+ AugmentedViewBase,
2066
+ Binding,
2067
+ ExposedRecordView,
2068
+ ExposedValueView,
2069
+ Expression,
2070
+ Grouper,
2071
+ NestedDataView,
2072
+ ReadOnlyDataView,
2073
+ Ref,
2074
+ Store,
2075
+ StoreProxy,
2076
+ StringTemplate,
2077
+ StructuredSelector,
2078
+ SubscribableView,
2079
+ View,
2080
+ ZoomIntoPropertyView,
2081
+ append,
2082
+ computable,
2083
+ createAccessorModelProxy,
2084
+ defaultCompare,
2085
+ diffArrays,
2086
+ enableFatArrowExpansion,
2087
+ expression,
2088
+ filter,
2089
+ findTreeNode,
2090
+ findTreePath,
2091
+ getAccessor,
2092
+ getComparer,
2093
+ getSelector,
2094
+ indexSorter,
2095
+ insertElement,
2096
+ invalidateExpressionCache,
2097
+ invalidateStringTemplateCache,
2098
+ isAccessorChain,
2099
+ isBinding,
2100
+ isSelector,
2101
+ merge,
2102
+ moveElement,
2103
+ plugFatArrowExpansion,
2104
+ removeTreeNodes,
2105
+ sorter,
2106
+ stringTemplate,
2107
+ updateArray,
2108
+ updateTree,
2109
+ };