cx 25.5.1 → 25.6.0

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/charts.js +40 -21
  2. package/dist/manifest.js +771 -771
  3. package/dist/ui.js +0 -15
  4. package/dist/widgets.js +34 -25
  5. package/package.json +1 -1
  6. package/src/charts/LineGraph.js +1 -1
  7. package/src/charts/axis/NumericAxis.d.ts +46 -46
  8. package/src/charts/helpers/PointReducer.d.ts +9 -0
  9. package/src/charts/helpers/PointReducer.js +36 -22
  10. package/src/data/AugmentedViewBase.js +77 -77
  11. package/src/data/ExposedRecordView.js +75 -75
  12. package/src/data/ExposedValueView.js +73 -73
  13. package/src/data/Ref.d.ts +24 -24
  14. package/src/data/Ref.spec.js +79 -79
  15. package/src/data/StoreRef.spec.js +24 -24
  16. package/src/data/StructuredDataAccessor.d.ts +7 -7
  17. package/src/data/SubscribableView.js +54 -54
  18. package/src/ui/Container.js +154 -154
  19. package/src/ui/DataProxy.js +31 -45
  20. package/src/ui/DetachedScope.js +98 -98
  21. package/src/ui/Instance.d.ts +72 -72
  22. package/src/ui/Instance.js +623 -623
  23. package/src/ui/IsolatedScope.js +30 -30
  24. package/src/ui/Repeater.js +109 -109
  25. package/src/ui/Rescope.js +35 -35
  26. package/src/ui/Restate.js +167 -167
  27. package/src/ui/Widget.js +184 -184
  28. package/src/ui/adapter/ArrayAdapter.js +152 -152
  29. package/src/ui/adapter/TreeAdapter.js +101 -101
  30. package/src/ui/createFunctionalComponent.d.ts +1 -1
  31. package/src/ui/index.d.ts +42 -42
  32. package/src/ui/layout/exploreChildren.d.ts +12 -12
  33. package/src/ui/layout/exploreChildren.js +27 -27
  34. package/src/util/debounce.js +18 -18
  35. package/src/util/validatedDebounce.js +19 -19
  36. package/src/widgets/Button.js +118 -118
  37. package/src/widgets/List.js +594 -594
  38. package/src/widgets/form/Calendar.d.ts +86 -86
  39. package/src/widgets/form/Checkbox.js +5 -2
  40. package/src/widgets/form/MonthField.d.ts +5 -0
  41. package/src/widgets/form/MonthField.js +1 -0
  42. package/src/widgets/form/MonthPicker.d.ts +13 -0
  43. package/src/widgets/form/MonthPicker.js +25 -21
  44. package/src/widgets/grid/Grid.js +3421 -3421
  45. package/src/widgets/nav/Route.js +102 -102
package/dist/ui.js CHANGED
@@ -2981,21 +2981,6 @@ var DataProxy = /*#__PURE__*/ (function (_PureContainer) {
2981
2981
  _proto.init = function init() {
2982
2982
  if (!this.data) this.data = {};
2983
2983
  if (this.alias) this.data[this.alias] = this.value;
2984
-
2985
- // nesting is required to avoid resetting the store on every render and recalculating the data
2986
- this.container = PureContainer.create({
2987
- type: PureContainer,
2988
- items: this.children || this.items,
2989
- layout: this.layout,
2990
- controller: this.controller,
2991
- outerLayout: this.outerLayout,
2992
- ws: this.ws,
2993
- });
2994
- this.children = [this.container];
2995
- delete this.items;
2996
- delete this.controller;
2997
- delete this.outerLayout;
2998
- this.layout = UseParentLayout;
2999
2984
  _PureContainer.prototype.init.call(this);
3000
2985
  };
3001
2986
  _proto.initInstance = function initInstance(context, instance) {
package/dist/widgets.js CHANGED
@@ -7340,7 +7340,10 @@ var Checkbox = /*#__PURE__*/ (function (_Field) {
7340
7340
  "label",
7341
7341
  {
7342
7342
  className: data.classNames,
7343
- onMouseDown: stopPropagation,
7343
+ onMouseDown: function onMouseDown(e) {
7344
+ e.stopPropagation();
7345
+ if (_this.unfocusable) e.preventDefault();
7346
+ },
7344
7347
  onMouseMove: function onMouseMove(e) {
7345
7348
  return tooltipMouseMove$1.apply(void 0, [e].concat(getFieldTooltip(instance)));
7346
7349
  },
@@ -10881,6 +10884,7 @@ MonthPicker.prototype.range = false;
10881
10884
  MonthPicker.prototype.startYear = 1980;
10882
10885
  MonthPicker.prototype.endYear = 2030;
10883
10886
  MonthPicker.prototype.bufferSize = 15;
10887
+ MonthPicker.prototype.hideQuarters = false;
10884
10888
 
10885
10889
  // Localization
10886
10890
  MonthPicker.prototype.maxValueErrorText = "Select {0:d} or before.";
@@ -10913,7 +10917,7 @@ var MonthPickerComponent = /*#__PURE__*/ (function (_VDOM$Component) {
10913
10917
  cursorQuarter: cursor.getMonth() / 3,
10914
10918
  column: "M",
10915
10919
  start: widget.startYear,
10916
- end: widget.startYear + widget.bufferSize,
10920
+ end: Math.min(widget.startYear + widget.bufferSize, widget.endYear),
10917
10921
  };
10918
10922
  _this.handleMouseDown = _this.handleMouseDown.bind(_this);
10919
10923
  _this.handleMouseUp = _this.handleMouseUp.bind(_this);
@@ -11234,13 +11238,14 @@ var MonthPickerComponent = /*#__PURE__*/ (function (_VDOM$Component) {
11234
11238
  };
11235
11239
  _proto2.render = function render() {
11236
11240
  var _this3 = this;
11237
- var _this$props$instance = this.props.instance,
11238
- data = _this$props$instance.data,
11239
- widget = _this$props$instance.widget;
11241
+ var instance = this.props.instance;
11242
+ var data = instance.data,
11243
+ widget = instance.widget;
11240
11244
  var CSS = widget.CSS,
11241
11245
  baseClass = widget.baseClass,
11242
11246
  startYear = widget.startYear,
11243
- endYear = widget.endYear;
11247
+ endYear = widget.endYear,
11248
+ hideQuarters = widget.hideQuarters;
11244
11249
  var years = [];
11245
11250
  var _this$state2 = this.state,
11246
11251
  start = _this$state2.start,
@@ -11324,23 +11329,27 @@ var MonthPickerComponent = /*#__PURE__*/ (function (_VDOM$Component) {
11324
11329
  ),
11325
11330
  );
11326
11331
  }
11327
- row.push(
11328
- /*#__PURE__*/ jsx(
11329
- "th",
11330
- {
11331
- className: CSS.state({
11332
- cursor:
11333
- showCursor && this.state.column == "Q" && y == this.state.cursorYear && q == this.state.cursorQuarter,
11334
- }),
11335
- "data-point": "Y-" + y + "-Q-" + q,
11336
- onMouseEnter: this.handleMouseEnter,
11337
- onMouseDown: this.handleMouseDown,
11338
- onMouseUp: this.handleMouseUp,
11339
- children: "Q" + (q + 1),
11340
- },
11341
- "q" + q,
11342
- ),
11343
- );
11332
+ if (!hideQuarters)
11333
+ row.push(
11334
+ /*#__PURE__*/ jsx(
11335
+ "th",
11336
+ {
11337
+ className: CSS.state({
11338
+ cursor:
11339
+ showCursor &&
11340
+ this.state.column == "Q" &&
11341
+ y == this.state.cursorYear &&
11342
+ q == this.state.cursorQuarter,
11343
+ }),
11344
+ "data-point": "Y-" + y + "-Q-" + q,
11345
+ onMouseEnter: this.handleMouseEnter,
11346
+ onMouseDown: this.handleMouseDown,
11347
+ onMouseUp: this.handleMouseUp,
11348
+ children: "Q" + (q + 1),
11349
+ },
11350
+ "q" + q,
11351
+ ),
11352
+ );
11344
11353
  rows.push(row);
11345
11354
  }
11346
11355
  years.push(rows);
@@ -12156,7 +12165,7 @@ var MonthField = /*#__PURE__*/ (function (_Field) {
12156
12165
  {
12157
12166
  data: instance.data,
12158
12167
  instance: instance,
12159
- monthPicker: {
12168
+ monthPicker: _extends({}, this.monthPickerOptions, {
12160
12169
  value: this.value,
12161
12170
  from: this.from,
12162
12171
  to: this.to,
@@ -12169,7 +12178,7 @@ var MonthField = /*#__PURE__*/ (function (_Field) {
12169
12178
  maxExclusiveErrorText: this.maxExclusiveErrorText,
12170
12179
  minValueErrorText: this.minValueErrorText,
12171
12180
  minExclusiveErrorText: this.minExclusiveErrorText,
12172
- },
12181
+ }),
12173
12182
  label: this.labelPlacement && getContent(this.renderLabel(context, instance, "label")),
12174
12183
  help: this.helpPlacement && getContent(this.renderHelp(context, instance, "help")),
12175
12184
  icon: this.renderIcon(context, instance, "icon"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cx",
3
- "version": "25.5.1",
3
+ "version": "25.6.0",
4
4
  "description": "Advanced JavaScript UI framework for admin and dashboard applications with ready to use grid, form and chart components.",
5
5
  "main": "index.js",
6
6
  "jsnext:main": "src/index.js",
@@ -103,7 +103,7 @@ export class LineGraph extends Widget {
103
103
  if (context.pointReducer && isArray(data.data)) {
104
104
  data.data.forEach((p, index) => {
105
105
  if (data.area && this.y0Field)
106
- context.pointReducer(p[this.xField], p[this.y0Field], data.name, p, data, index);
106
+ context.pointReducer(p[this.xField], p[this.y0Field], data.name, p, data.data, index);
107
107
  context.pointReducer(p[this.xField], p[this.yField], data.name, p, data.data, index);
108
108
  });
109
109
  }
@@ -1,46 +1,46 @@
1
- import * as Cx from "../../core";
2
- import { AxisProps } from "./Axis";
3
-
4
- interface NumericAxisProps extends AxisProps {
5
- /** Minimum value. */
6
- min?: Cx.NumberProp;
7
-
8
- /** Maximum value. */
9
- max?: Cx.NumberProp;
10
-
11
- /** Set to `true` to normalize the input range. */
12
- normalized?: Cx.BooleanProp;
13
-
14
- /** Number used to divide values before rendering axis labels. Default value is `1`. */
15
- labelDivisor?: Cx.NumberProp;
16
-
17
- /** Base CSS class to be applied to the element. Defaults to `numericaxis`. */
18
- baseClass?: string;
19
-
20
- tickDivisions?: Array<number[]>;
21
-
22
- /** A number ranged between `0-2`. `0` means that the range is aligned with the lowest ticks. Default value is `1`, which means that the range is aligned with medium ticks. Use value `2` to align with major ticks. */
23
- snapToTicks?: 0 | 1 | 2;
24
-
25
- /** Value format. Default is `n`. */
26
- format?: Cx.StringProp;
27
-
28
- /** Size of a zone reserved for labels for both lower and upper end of the axis. */
29
- deadZone?: Cx.NumberProp;
30
-
31
- /** Size of a zone reserved for labels near the upper (higher) end of the axis. */
32
- upperDeadZone?: Cx.NumberProp;
33
-
34
- /** Size of a zone reserved for labels near the lower end of the axis. */
35
- lowerDeadZone?: Cx.NumberProp;
36
-
37
- /** Specifies minimum value increment between labels. Useful when formatting is not flexible enough, i.e. set to 1 for integer axes to avoid duplicate labels. */
38
- minLabelTickSize?: number;
39
- }
40
-
41
- export class NumericAxis extends Cx.Widget<NumericAxisProps> {
42
- static XY(): {
43
- x: { type: NumericAxis };
44
- y: { type: NumericAxis; vertical: true };
45
- };
46
- }
1
+ import * as Cx from "../../core";
2
+ import { AxisProps } from "./Axis";
3
+
4
+ interface NumericAxisProps extends AxisProps {
5
+ /** Minimum value. */
6
+ min?: Cx.NumberProp;
7
+
8
+ /** Maximum value. */
9
+ max?: Cx.NumberProp;
10
+
11
+ /** Set to `true` to normalize the input range. */
12
+ normalized?: Cx.BooleanProp;
13
+
14
+ /** Number used to divide values before rendering axis labels. Default value is `1`. */
15
+ labelDivisor?: Cx.NumberProp;
16
+
17
+ /** Base CSS class to be applied to the element. Defaults to `numericaxis`. */
18
+ baseClass?: string;
19
+
20
+ tickDivisions?: Array<number[]>;
21
+
22
+ /** A number ranged between `0-2`. `0` means that the range is aligned with the lowest ticks. Default value is `1`, which means that the range is aligned with medium ticks. Use value `2` to align with major ticks. */
23
+ snapToTicks?: 0 | 1 | 2;
24
+
25
+ /** Value format. Default is `n`. */
26
+ format?: Cx.StringProp;
27
+
28
+ /** Size of a zone reserved for labels for both lower and upper end of the axis. */
29
+ deadZone?: Cx.NumberProp;
30
+
31
+ /** Size of a zone reserved for labels near the upper (higher) end of the axis. */
32
+ upperDeadZone?: Cx.NumberProp;
33
+
34
+ /** Size of a zone reserved for labels near the lower end of the axis. */
35
+ lowerDeadZone?: Cx.NumberProp;
36
+
37
+ /** Specifies minimum value increment between labels. Useful when formatting is not flexible enough, i.e. set to 1 for integer axes to avoid duplicate labels. */
38
+ minLabelTickSize?: number;
39
+ }
40
+
41
+ export class NumericAxis extends Cx.Widget<NumericAxisProps> {
42
+ static XY(): {
43
+ x: { type: NumericAxis };
44
+ y: { type: NumericAxis; vertical: true };
45
+ };
46
+ }
@@ -10,6 +10,15 @@ export interface PointReducerProps extends Cx.PureContainerProps {
10
10
 
11
11
  /** A callback function used to process accumulated information and write results. */
12
12
  onReduce?: (accumulator: Cx.Record, instance?: Instance) => void;
13
+
14
+ /** Parameters that trigger filter predicate re-creation. */
15
+ filterParams?: StructuredProp;
16
+
17
+ /** A callback function used to create a predicate for filtering points. */
18
+ onCreatePointFilter?: (
19
+ filterParams: any,
20
+ instance: Instance,
21
+ ) => (x: number, y: number, name: string, data: any, array?: any[], index?: number) => boolean;
13
22
  }
14
23
 
15
24
  export class PointReducer extends Cx.Widget<PointReducerProps> {}
@@ -1,34 +1,48 @@
1
1
  import { PureContainer } from "../../ui/PureContainer";
2
2
 
3
3
  export class PointReducer extends PureContainer {
4
+ declareData() {
5
+ super.declareData(...arguments, {
6
+ filterParams: {
7
+ structured: true,
8
+ },
9
+ });
10
+ }
11
+
12
+ prepareData(context, instance) {
13
+ super.prepareData(context, instance);
14
+
15
+ instance.resetAccumulator = () => {
16
+ let accumulator = {};
17
+ if (this.onInitAccumulator) {
18
+ instance.invoke("onInitAccumulator", accumulator, instance);
19
+ instance.accumulator = accumulator;
20
+ }
21
+ };
22
+
23
+ if (this.onCreatePointFilter)
24
+ instance.pointFilter = instance.invoke("onCreatePointFilter", instance.data.filterParams, instance);
25
+ }
26
+
4
27
  explore(context, instance) {
28
+ instance.resetAccumulator();
29
+
5
30
  let parentPointReducer = context.pointReducer;
6
31
  instance.parentPointTracker = parentPointReducer;
7
32
 
8
- if (!instance.pointReducer) {
9
- let onMap = this.onMap && instance.getCallback("onMap");
10
- let accumulator = {};
11
- instance.resetAccumulator = () => {
12
- accumulator = {};
13
- if (this.onInitAccumulator) instance.invoke("onInitAccumulator", accumulator, instance);
14
- };
15
-
16
- let pointFilter = null;
17
- if (this.onCreatePointFilter) pointFilter = instance.invoke("onCreatePointFilter", instance);
18
-
19
- instance.pointReducer = (x, y, name, data, array, index) => {
20
- if (!pointFilter || pointFilter(x, y, name, data, array, index))
21
- onMap(accumulator, x, y, name, data, array, index);
22
- if (parentPointReducer) parentPointReducer(x, y, name, data, array, index);
23
- };
24
- instance.write = () => {
25
- if (this.onReduce) instance.invoke("onReduce", accumulator, instance);
26
- };
27
- }
33
+ let pointFilter = instance.pointFilter;
34
+ let accumulator = instance.accumulator;
35
+ let onMap = this.onMap && instance.getCallback("onMap");
36
+ instance.pointReducer = (x, y, name, data, array, index) => {
37
+ if (!pointFilter || pointFilter(x, y, name, data, array, index))
38
+ onMap(accumulator, x, y, name, data, array, index);
39
+ if (parentPointReducer) parentPointReducer(x, y, name, data, array, index);
40
+ };
41
+ instance.write = () => {
42
+ if (this.onReduce) instance.invoke("onReduce", accumulator, instance);
43
+ };
28
44
 
29
- instance.resetAccumulator();
30
45
  context.push("pointReducer", instance.pointReducer);
31
-
32
46
  super.explore(context, instance);
33
47
  }
34
48
 
@@ -1,77 +1,77 @@
1
- import { View } from "./View";
2
- import { Binding } from "./Binding";
3
-
4
- export class AugmentedViewBase extends View {
5
- getData() {
6
- if (this.sealed && this.meta.version === this.cache.version && this.meta === this.store.meta)
7
- return this.cache.result;
8
- let parentStoreData = this.store.getData();
9
- let result = this.getBaseData(parentStoreData);
10
- this.embedAugmentData(result, parentStoreData);
11
- this.cache.result = result;
12
- this.cache.parentStoreData = parentStoreData;
13
- this.cache.version = this.meta.version;
14
- this.meta = this.store.meta;
15
- return this.cache.result;
16
- }
17
-
18
- getBaseData(parentStoreData) {
19
- if (this.sealed || this.immutable || this.store.sealed) return { ...parentStoreData };
20
- return parentStoreData;
21
- }
22
-
23
- embedAugmentData(result, parentStoreData) {
24
- throw new Error("abstract");
25
- }
26
-
27
- isExtraKey(key) {
28
- throw new Error("abstract");
29
- }
30
-
31
- // Stores which need to support nested aliases should override this method
32
- getExtraKeyBinding(key) {
33
- let binding = Binding.get(key);
34
- return this.isExtraKey(binding.parts[0]) ? Binding.get(binding.parts[0]) : null;
35
- }
36
-
37
- setExtraKeyValue(key, value) {
38
- throw new Error("abstract");
39
- }
40
-
41
- deleteExtraKeyValue(key) {
42
- throw new Error("abstract");
43
- }
44
-
45
- setItem(path, value) {
46
- let extraKeyBinding = this.getExtraKeyBinding(path);
47
- if (extraKeyBinding) {
48
- let binding = Binding.get(path);
49
- let newValue = value;
50
- if (binding.parts.length > extraKeyBinding.parts.length) {
51
- let data = {};
52
- this.embedAugmentData(data, this.store.getData());
53
- let binding = Binding.get(path);
54
- data = binding.set(data, value);
55
- newValue = extraKeyBinding.value(data);
56
- }
57
- return this.setExtraKeyValue(extraKeyBinding.path, newValue);
58
- }
59
- return super.setItem(path, value);
60
- }
61
-
62
- deleteItem(path) {
63
- let extraKeyBinding = this.getExtraKeyBinding(path);
64
- if (extraKeyBinding) {
65
- if (path == extraKeyBinding.path) return this.deleteExtraKeyValue(extraKeyBinding.path);
66
- let data = {};
67
- this.embedAugmentData(data, this.store.getData());
68
- let binding = Binding.get(path);
69
- data = binding.delete(data);
70
- let newValue = extraKeyBinding.value(data);
71
- return this.setExtraKeyValue(extraKeyBinding.path, newValue);
72
- }
73
- return super.deleteItem(path);
74
- }
75
- }
76
-
77
- AugmentedViewBase.prototype.immutable = false;
1
+ import { View } from "./View";
2
+ import { Binding } from "./Binding";
3
+
4
+ export class AugmentedViewBase extends View {
5
+ getData() {
6
+ if (this.sealed && this.meta.version === this.cache.version && this.meta === this.store.meta)
7
+ return this.cache.result;
8
+ let parentStoreData = this.store.getData();
9
+ let result = this.getBaseData(parentStoreData);
10
+ this.embedAugmentData(result, parentStoreData);
11
+ this.cache.result = result;
12
+ this.cache.parentStoreData = parentStoreData;
13
+ this.cache.version = this.meta.version;
14
+ this.meta = this.store.meta;
15
+ return this.cache.result;
16
+ }
17
+
18
+ getBaseData(parentStoreData) {
19
+ if (this.sealed || this.immutable || this.store.sealed) return { ...parentStoreData };
20
+ return parentStoreData;
21
+ }
22
+
23
+ embedAugmentData(result, parentStoreData) {
24
+ throw new Error("abstract");
25
+ }
26
+
27
+ isExtraKey(key) {
28
+ throw new Error("abstract");
29
+ }
30
+
31
+ // Stores which need to support nested aliases should override this method
32
+ getExtraKeyBinding(key) {
33
+ let binding = Binding.get(key);
34
+ return this.isExtraKey(binding.parts[0]) ? Binding.get(binding.parts[0]) : null;
35
+ }
36
+
37
+ setExtraKeyValue(key, value) {
38
+ throw new Error("abstract");
39
+ }
40
+
41
+ deleteExtraKeyValue(key) {
42
+ throw new Error("abstract");
43
+ }
44
+
45
+ setItem(path, value) {
46
+ let extraKeyBinding = this.getExtraKeyBinding(path);
47
+ if (extraKeyBinding) {
48
+ let binding = Binding.get(path);
49
+ let newValue = value;
50
+ if (binding.parts.length > extraKeyBinding.parts.length) {
51
+ let data = {};
52
+ this.embedAugmentData(data, this.store.getData());
53
+ let binding = Binding.get(path);
54
+ data = binding.set(data, value);
55
+ newValue = extraKeyBinding.value(data);
56
+ }
57
+ return this.setExtraKeyValue(extraKeyBinding.path, newValue);
58
+ }
59
+ return super.setItem(path, value);
60
+ }
61
+
62
+ deleteItem(path) {
63
+ let extraKeyBinding = this.getExtraKeyBinding(path);
64
+ if (extraKeyBinding) {
65
+ if (path == extraKeyBinding.path) return this.deleteExtraKeyValue(extraKeyBinding.path);
66
+ let data = {};
67
+ this.embedAugmentData(data, this.store.getData());
68
+ let binding = Binding.get(path);
69
+ data = binding.delete(data);
70
+ let newValue = extraKeyBinding.value(data);
71
+ return this.setExtraKeyValue(extraKeyBinding.path, newValue);
72
+ }
73
+ return super.deleteItem(path);
74
+ }
75
+ }
76
+
77
+ AugmentedViewBase.prototype.immutable = false;
@@ -1,75 +1,75 @@
1
- import { View } from "./View";
2
- import { Binding } from "./Binding";
3
-
4
- export class ExposedRecordView extends View {
5
- getData() {
6
- if (
7
- this.sealed &&
8
- this.meta.version === this.cache.version &&
9
- this.cache.itemIndex === this.itemIndex &&
10
- this.meta === this.store.meta
11
- )
12
- return this.cache.result;
13
-
14
- this.cache.result = this.embed(this.store.getData());
15
- this.cache.version = this.meta.version;
16
- this.cache.itemIndex = this.itemIndex;
17
- this.meta = this.store.meta;
18
- return this.cache.result;
19
- }
20
-
21
- embed(data) {
22
- const collection = this.collectionBinding.value(data);
23
- const record = collection[this.itemIndex];
24
- const copy = this.sealed || this.immutable || this.store.sealed ? { ...data } : data;
25
- copy[this.recordName] = record;
26
- if (this.indexName) copy[this.indexName] = this.itemIndex;
27
- return copy;
28
- }
29
-
30
- setIndex(index) {
31
- this.itemIndex = index;
32
- }
33
-
34
- setItem(path, value) {
35
- if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
36
- const storeData = this.store.getData();
37
- const collection = this.collectionBinding.value(storeData);
38
- const data = this.embed(storeData);
39
- const d = Binding.get(path).set(data, value);
40
- if (d === data) return false;
41
- const record = d[this.recordName];
42
- const newCollection = [
43
- ...collection.slice(0, this.itemIndex),
44
- record,
45
- ...collection.slice(this.itemIndex + 1),
46
- ];
47
- return this.store.setItem(this.collectionBinding.path, newCollection);
48
- }
49
- return this.store.setItem(path, value);
50
- }
51
-
52
- deleteItem(path) {
53
- let storeData, collection, newCollection;
54
-
55
- if (path == this.recordName) {
56
- storeData = this.store.getData();
57
- collection = this.collectionBinding.value(storeData);
58
- newCollection = [...collection.slice(0, this.itemIndex), ...collection.slice(this.itemIndex + 1)];
59
- return this.store.setItem(this.collectionBinding.path, newCollection);
60
- } else if (path.indexOf(this.recordName + ".") == 0) {
61
- storeData = this.store.getData();
62
- collection = this.collectionBinding.value(storeData);
63
- const data = this.embed(storeData);
64
- const d = Binding.get(path).delete(data);
65
- if (d === data) return false;
66
- const record = d[this.recordName];
67
- newCollection = [...collection.slice(0, this.itemIndex), record, ...collection.slice(this.itemIndex + 1)];
68
- return this.store.setItem(this.collectionBinding.path, newCollection);
69
- }
70
-
71
- return this.store.deleteItem(path);
72
- }
73
- }
74
-
75
- ExposedRecordView.prototype.immutable = false;
1
+ import { View } from "./View";
2
+ import { Binding } from "./Binding";
3
+
4
+ export class ExposedRecordView extends View {
5
+ getData() {
6
+ if (
7
+ this.sealed &&
8
+ this.meta.version === this.cache.version &&
9
+ this.cache.itemIndex === this.itemIndex &&
10
+ this.meta === this.store.meta
11
+ )
12
+ return this.cache.result;
13
+
14
+ this.cache.result = this.embed(this.store.getData());
15
+ this.cache.version = this.meta.version;
16
+ this.cache.itemIndex = this.itemIndex;
17
+ this.meta = this.store.meta;
18
+ return this.cache.result;
19
+ }
20
+
21
+ embed(data) {
22
+ const collection = this.collectionBinding.value(data);
23
+ const record = collection[this.itemIndex];
24
+ const copy = this.sealed || this.immutable || this.store.sealed ? { ...data } : data;
25
+ copy[this.recordName] = record;
26
+ if (this.indexName) copy[this.indexName] = this.itemIndex;
27
+ return copy;
28
+ }
29
+
30
+ setIndex(index) {
31
+ this.itemIndex = index;
32
+ }
33
+
34
+ setItem(path, value) {
35
+ if (path == this.recordName || path.indexOf(this.recordName + ".") == 0) {
36
+ const storeData = this.store.getData();
37
+ const collection = this.collectionBinding.value(storeData);
38
+ const data = this.embed(storeData);
39
+ const d = Binding.get(path).set(data, value);
40
+ if (d === data) return false;
41
+ const record = d[this.recordName];
42
+ const newCollection = [
43
+ ...collection.slice(0, this.itemIndex),
44
+ record,
45
+ ...collection.slice(this.itemIndex + 1),
46
+ ];
47
+ return this.store.setItem(this.collectionBinding.path, newCollection);
48
+ }
49
+ return this.store.setItem(path, value);
50
+ }
51
+
52
+ deleteItem(path) {
53
+ let storeData, collection, newCollection;
54
+
55
+ if (path == this.recordName) {
56
+ storeData = this.store.getData();
57
+ collection = this.collectionBinding.value(storeData);
58
+ newCollection = [...collection.slice(0, this.itemIndex), ...collection.slice(this.itemIndex + 1)];
59
+ return this.store.setItem(this.collectionBinding.path, newCollection);
60
+ } else if (path.indexOf(this.recordName + ".") == 0) {
61
+ storeData = this.store.getData();
62
+ collection = this.collectionBinding.value(storeData);
63
+ const data = this.embed(storeData);
64
+ const d = Binding.get(path).delete(data);
65
+ if (d === data) return false;
66
+ const record = d[this.recordName];
67
+ newCollection = [...collection.slice(0, this.itemIndex), record, ...collection.slice(this.itemIndex + 1)];
68
+ return this.store.setItem(this.collectionBinding.path, newCollection);
69
+ }
70
+
71
+ return this.store.deleteItem(path);
72
+ }
73
+ }
74
+
75
+ ExposedRecordView.prototype.immutable = false;