cx 26.3.3 → 26.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/build/charts/helpers/SnapPointFinder.d.ts +2 -2
  2. package/build/charts/helpers/SnapPointFinder.d.ts.map +1 -1
  3. package/build/charts/helpers/ValueAtFinder.d.ts +4 -4
  4. package/build/charts/helpers/ValueAtFinder.d.ts.map +1 -1
  5. package/build/charts/helpers/ValueAtFinder.js +5 -2
  6. package/build/data/createAccessorModelProxy.d.ts +11 -6
  7. package/build/data/createAccessorModelProxy.d.ts.map +1 -1
  8. package/build/data/createAccessorModelProxy.js +3 -1
  9. package/build/jsx-runtime.d.ts +1 -2
  10. package/build/jsx-runtime.d.ts.map +1 -1
  11. package/build/ui/createFunctionalComponent.d.ts +1 -4
  12. package/build/ui/createFunctionalComponent.d.ts.map +1 -1
  13. package/build/widgets/form/Calendar.d.ts +0 -1
  14. package/build/widgets/form/Calendar.d.ts.map +1 -1
  15. package/build/widgets/form/Calendar.js +22 -14
  16. package/build/widgets/form/TimeList.d.ts +1 -3
  17. package/build/widgets/form/TimeList.d.ts.map +1 -1
  18. package/build/widgets/index.d.ts +1 -3
  19. package/build/widgets/index.d.ts.map +1 -1
  20. package/build/widgets/index.js +1 -3
  21. package/build/widgets/overlay/Overlay.d.ts +1 -1
  22. package/build/widgets/overlay/Overlay.d.ts.map +1 -1
  23. package/build/widgets/overlay/Overlay.js +19 -10
  24. package/build/widgets/overlay/Window.d.ts.map +1 -1
  25. package/build/widgets/overlay/Window.js +11 -5
  26. package/dist/charts.css +256 -256
  27. package/dist/manifest.js +728 -737
  28. package/dist/widgets.css +6 -14
  29. package/dist/widgets.js +13 -26
  30. package/package.json +1 -1
  31. package/src/charts/BarGraph.scss +31 -31
  32. package/src/charts/Legend.scss +57 -57
  33. package/src/charts/LegendEntry.scss +35 -35
  34. package/src/charts/LineGraph.scss +28 -28
  35. package/src/charts/helpers/SnapPointFinder.ts +136 -136
  36. package/src/charts/helpers/ValueAtFinder.ts +72 -72
  37. package/src/charts/variables.scss +1 -2
  38. package/src/data/createAccessorModelProxy.ts +66 -66
  39. package/src/ui/DataProxy.ts +55 -55
  40. package/src/ui/Rescope.ts +50 -50
  41. package/src/ui/adapter/ArrayAdapter.ts +229 -229
  42. package/src/ui/exprHelpers.ts +96 -96
  43. package/src/util/scss/include.scss +40 -27
  44. package/src/widgets/Button.maps.scss +103 -103
  45. package/src/widgets/Sandbox.ts +104 -104
  46. package/src/widgets/drag-drop/variables.scss +1 -2
  47. package/src/widgets/form/Calendar.tsx +772 -772
  48. package/src/widgets/form/ColorField.scss +112 -117
  49. package/src/widgets/form/DateTimeField.scss +111 -125
  50. package/src/widgets/form/LookupField.scss +228 -251
  51. package/src/widgets/form/MonthField.scss +113 -122
  52. package/src/widgets/form/NumberField.scss +72 -80
  53. package/src/widgets/form/Select.scss +104 -117
  54. package/src/widgets/form/TextField.scss +66 -78
  55. package/src/widgets/form/variables.scss +110 -111
  56. package/src/widgets/grid/Grid.tsx +3885 -4428
  57. package/src/widgets/grid/variables.scss +47 -48
  58. package/src/widgets/index.ts +63 -63
  59. package/src/widgets/nav/Menu.variables.scss +1 -2
  60. package/src/widgets/nav/Tab.ts +6 -4
  61. package/src/widgets/nav/variables.scss +1 -2
  62. package/src/widgets/overlay/Overlay.tsx +1028 -1028
  63. package/src/widgets/overlay/Window.tsx +320 -320
  64. package/src/widgets/overlay/variables.scss +1 -2
  65. package/src/widgets/variables.scss +61 -62
@@ -1,55 +1,55 @@
1
- import { AccessorChain } from "../data";
2
- import { NestedDataView } from "../data/NestedDataView";
3
- import { StructuredProp, WritableProp } from "./Prop";
4
- import { PureContainerBase, PureContainerConfig } from "./PureContainer";
5
- import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
-
7
- export interface DataProxyConfig extends PureContainerConfig {
8
- /** Data object with computed values to be exposed in the local store. */
9
- data?: StructuredProp;
10
-
11
- /** Binding to a value to be exposed under the `alias` name. */
12
- value?: WritableProp<any>;
13
-
14
- /** Alias name under which `value` is exposed in the local store. */
15
- alias?: string | AccessorChain<any>;
16
-
17
- /** Indicate that parent store data should not be mutated. */
18
- immutable?: boolean;
19
-
20
- /** Indicate that local store data should not be mutated. */
21
- sealed?: boolean;
22
- }
23
-
24
- export class DataProxy extends PureContainerBase<DataProxyConfig> {
25
- declare data?: any;
26
- declare alias?: string;
27
- declare value?: any;
28
- declare immutable: boolean;
29
- declare sealed: boolean;
30
-
31
- init() {
32
- if (!this.data) this.data = {};
33
-
34
- if (this.alias) this.data[this.alias] = this.value;
35
-
36
- super.init();
37
- }
38
-
39
- initInstance(context: any, instance: any) {
40
- instance.store = new NestedDataView({
41
- store: instance.parentStore,
42
- nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
43
- immutable: this.immutable,
44
- sealed: this.sealed,
45
- });
46
- super.initInstance(context, instance);
47
- }
48
-
49
- applyParentStore(instance: any) {
50
- instance.store.setStore(instance.parentStore);
51
- }
52
- }
53
-
54
- DataProxy.prototype.immutable = false;
55
- DataProxy.prototype.sealed = false;
1
+ import { AccessorChain } from "../data";
2
+ import { NestedDataView } from "../data/NestedDataView";
3
+ import { StructuredProp, WritableProp } from "./Prop";
4
+ import { PureContainerBase, PureContainerConfig } from "./PureContainer";
5
+ import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
+
7
+ export interface DataProxyConfig extends PureContainerConfig {
8
+ /** Data object with computed values to be exposed in the local store. */
9
+ data?: StructuredProp;
10
+
11
+ /** Binding to a value to be exposed under the `alias` name. */
12
+ value?: WritableProp<any>;
13
+
14
+ /** Alias name under which `value` is exposed in the local store. */
15
+ alias?: string | AccessorChain<any>;
16
+
17
+ /** Indicate that parent store data should not be mutated. */
18
+ immutable?: boolean;
19
+
20
+ /** Indicate that local store data should not be mutated. */
21
+ sealed?: boolean;
22
+ }
23
+
24
+ export class DataProxy extends PureContainerBase<DataProxyConfig> {
25
+ declare data?: any;
26
+ declare alias?: string;
27
+ declare value?: any;
28
+ declare immutable: boolean;
29
+ declare sealed: boolean;
30
+
31
+ init() {
32
+ if (!this.data) this.data = {};
33
+
34
+ if (this.alias) this.data[this.alias] = this.value;
35
+
36
+ super.init();
37
+ }
38
+
39
+ initInstance(context: any, instance: any) {
40
+ instance.store = new NestedDataView({
41
+ store: instance.parentStore,
42
+ nestedData: new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true }),
43
+ immutable: this.immutable,
44
+ sealed: this.sealed,
45
+ });
46
+ super.initInstance(context, instance);
47
+ }
48
+
49
+ applyParentStore(instance: any) {
50
+ instance.store.setStore(instance.parentStore);
51
+ }
52
+ }
53
+
54
+ DataProxy.prototype.immutable = false;
55
+ DataProxy.prototype.sealed = false;
package/src/ui/Rescope.ts CHANGED
@@ -1,50 +1,50 @@
1
- import { Widget } from "./Widget";
2
- import { PureContainerBase, PureContainerConfig } from "./PureContainer";
3
- import { Binding } from "../data/Binding";
4
- import { ZoomIntoPropertyView } from "../data/ZoomIntoPropertyView";
5
- import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
- import { isObject } from "../util/isObject";
7
- import { StructuredProp } from "./Prop";
8
- import { AccessorChain } from "../data/createAccessorModelProxy";
9
-
10
- export interface RescopeConfig extends PureContainerConfig {
11
- bind: string | AccessorChain<any>;
12
- rootName?: string | AccessorChain<any>;
13
- rootAlias?: string | AccessorChain<any>;
14
- data?: StructuredProp;
15
- }
16
-
17
- export class Rescope extends PureContainerBase<RescopeConfig> {
18
- declare bind: string;
19
- declare binding: any;
20
- declare rootAlias?: string;
21
- declare rootName: string;
22
- declare data?: any;
23
-
24
- init() {
25
- this.binding = Binding.get(this.bind);
26
- if (this.rootAlias) this.rootName = this.rootAlias;
27
- super.init();
28
- }
29
-
30
- initInstance(context: any, instance: any) {
31
- instance.store = new ZoomIntoPropertyView({
32
- store: instance.parentStore,
33
- binding: this.binding,
34
- rootName: this.rootName,
35
- nestedData: isObject(this.data)
36
- ? new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true })
37
- : undefined,
38
- });
39
- super.initInstance(context, instance);
40
- }
41
-
42
- applyParentStore(instance: any) {
43
- instance.store.setStore(instance.parentStore);
44
- }
45
- }
46
-
47
- Rescope.prototype.bind = "$page";
48
- Rescope.prototype.rootName = "$root";
49
-
50
- Widget.alias("rescope", Rescope);
1
+ import { Widget } from "./Widget";
2
+ import { PureContainerBase, PureContainerConfig } from "./PureContainer";
3
+ import { Binding } from "../data/Binding";
4
+ import { ZoomIntoPropertyView } from "../data/ZoomIntoPropertyView";
5
+ import { StructuredInstanceDataAccessor } from "./StructuredInstanceDataAccessor";
6
+ import { isObject } from "../util/isObject";
7
+ import { StructuredProp } from "./Prop";
8
+ import { AccessorChain } from "../data/createAccessorModelProxy";
9
+
10
+ export interface RescopeConfig extends PureContainerConfig {
11
+ bind: string | AccessorChain<any>;
12
+ rootName?: string | AccessorChain<any>;
13
+ rootAlias?: string | AccessorChain<any>;
14
+ data?: StructuredProp;
15
+ }
16
+
17
+ export class Rescope extends PureContainerBase<RescopeConfig> {
18
+ declare bind: string;
19
+ declare binding: any;
20
+ declare rootAlias?: string;
21
+ declare rootName: string;
22
+ declare data?: any;
23
+
24
+ init() {
25
+ this.binding = Binding.get(this.bind);
26
+ if (this.rootAlias) this.rootName = this.rootAlias;
27
+ super.init();
28
+ }
29
+
30
+ initInstance(context: any, instance: any) {
31
+ instance.store = new ZoomIntoPropertyView({
32
+ store: instance.parentStore,
33
+ binding: this.binding,
34
+ rootName: this.rootName,
35
+ nestedData: isObject(this.data)
36
+ ? new StructuredInstanceDataAccessor({ instance, data: this.data, useParentStore: true })
37
+ : undefined,
38
+ });
39
+ super.initInstance(context, instance);
40
+ }
41
+
42
+ applyParentStore(instance: any) {
43
+ instance.store.setStore(instance.parentStore);
44
+ }
45
+ }
46
+
47
+ Rescope.prototype.bind = "$page";
48
+ Rescope.prototype.rootName = "$root";
49
+
50
+ Widget.alias("rescope", Rescope);
@@ -1,229 +1,229 @@
1
- import { DataAdapter, DataAdapterRecord, DataAdapterConfig } from "./DataAdapter";
2
- import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
- import { sorter } from "../../data/comparer";
4
- import { isArray } from "../../util/isArray";
5
- import { ArrayElementView } from "../../data/ArrayElementView";
6
- import { Accessor, getAccessor } from "../../data/getAccessor";
7
- import { Culture } from "../Culture";
8
- import { isDefined, isObject } from "../../util";
9
- import { RenderingContext } from "../RenderingContext";
10
- import { Instance } from "../Instance";
11
- import { View } from "../../data/View";
12
- import { Prop, Sorter, CollatorOptions } from "../Prop";
13
-
14
- export interface RecordStoreCache {
15
- recordStoreCache: WeakMap<any, View>;
16
- cacheByKey: Record<string | number, View>;
17
- recordsAccessor?: Accessor;
18
- }
19
-
20
- export interface ArrayAdapterConfig extends DataAdapterConfig {
21
- recordsBinding?: Prop<any[]>;
22
- recordsAccessor?: Accessor | string;
23
- keyField?: string;
24
- cacheByKeyField?: boolean;
25
- sortOptions?: CollatorOptions;
26
- preserveOrder?: boolean;
27
- }
28
-
29
- export interface ExtendedSorter extends Sorter {
30
- comparer?: (a: any, b: any) => number;
31
- sortOptions?: CollatorOptions;
32
- }
33
-
34
- export interface ResolvedSorter {
35
- getter: (x: any) => any;
36
- factor: number;
37
- compare: (a: any, b: any) => number;
38
- }
39
-
40
- export class ArrayAdapter<T = any> extends DataAdapter<T> {
41
- declare public recordsAccessor: Accessor;
42
- declare public recordsBinding?: Prop<T[]>;
43
- declare public keyField: string | null;
44
- declare public cacheByKeyField: boolean;
45
- declare public sortOptions?: CollatorOptions;
46
- declare public preserveOrder?: boolean;
47
- declare isTreeAdapter: boolean;
48
-
49
- declare protected sorter?: (data: DataAdapterRecord<T>[]) => DataAdapterRecord<T>[];
50
-
51
- constructor(config?: ArrayAdapterConfig) {
52
- super(config);
53
- }
54
-
55
- public init(): void {
56
- this.recordsAccessor = this.recordsBinding ? getAccessor(this.recordsBinding) : getAccessor(this.recordsAccessor);
57
- this.recordName = this.recordName?.toString() || "$record";
58
- this.indexName = this.indexName?.toString() || "$index";
59
- }
60
-
61
- public initInstance(context: RenderingContext, instance: Instance & Partial<RecordStoreCache>): void {
62
- if (!instance.recordStoreCache) {
63
- instance.recordStoreCache = new WeakMap();
64
- instance.cacheByKey = {};
65
- }
66
-
67
- if (!instance.recordsAccessor && this.recordsAccessor) {
68
- instance.recordsAccessor = this.recordsAccessor.bindInstance
69
- ? this.recordsAccessor.bindInstance(instance)
70
- : this.recordsAccessor;
71
- }
72
- }
73
-
74
- public getRecords(
75
- context: RenderingContext,
76
- instance: Instance & Partial<RecordStoreCache>,
77
- records: T[],
78
- parentStore: View,
79
- ): DataAdapterRecord<T>[] {
80
- if (!instance.recordStoreCache) {
81
- this.initInstance(context, instance);
82
- }
83
-
84
- return this.mapRecords(context, instance, records, parentStore, instance.recordsAccessor);
85
- }
86
-
87
- public mapRecords(
88
- context: RenderingContext,
89
- instance: Instance & Partial<RecordStoreCache>,
90
- records: T[],
91
- parentStore: View,
92
- recordsAccessor?: Accessor,
93
- ): DataAdapterRecord<T>[] {
94
- let result: DataAdapterRecord<T>[] = [];
95
-
96
- if (!instance.recordStoreCache) {
97
- this.initInstance(context, instance);
98
- }
99
-
100
- if (isArray(records)) {
101
- records.forEach((data, index) => {
102
- if (this.filterFn && !this.filterFn(data)) return;
103
-
104
- const record = this.mapRecord(context, instance, data, parentStore, recordsAccessor, index);
105
- result.push(record);
106
- });
107
- }
108
-
109
- if (this.sorter && !this.preserveOrder) {
110
- result = this.sorter(result);
111
- }
112
-
113
- return result;
114
- }
115
-
116
- public mapRecord(
117
- context: RenderingContext,
118
- instance: Instance & Partial<RecordStoreCache>,
119
- data: T,
120
- parentStore: View,
121
- recordsAccessor: Accessor | undefined,
122
- index: number,
123
- ): DataAdapterRecord<T> {
124
- const key = this.cacheByKeyField && this.keyField && isObject(data) ? (data as any)[this.keyField] : null;
125
- let recordStore = key != null ? instance.cacheByKey![key] : instance.recordStoreCache!.get(data);
126
-
127
- if (recordsAccessor) {
128
- if (!recordStore) {
129
- recordStore = new ArrayElementView({
130
- store: parentStore,
131
- arrayAccessor: recordsAccessor,
132
- itemIndex: index,
133
- recordAlias: this.recordName,
134
- indexAlias: this.indexName,
135
- immutable: this.immutable,
136
- sealed: this.sealed,
137
- });
138
- } else {
139
- (recordStore as ArrayElementView).setStore(parentStore);
140
- (recordStore as ArrayElementView).setIndex(index);
141
- }
142
- } else {
143
- if (!recordStore) {
144
- recordStore = new ReadOnlyDataView({
145
- store: parentStore,
146
- data: {
147
- [this.recordName]: data,
148
- [this.indexName]: index,
149
- },
150
- immutable: this.immutable,
151
- sealed: this.sealed,
152
- });
153
- } else {
154
- (recordStore as ReadOnlyDataView).setStore(parentStore);
155
- (recordStore as ReadOnlyDataView).setData({
156
- [this.recordName]: data,
157
- [this.indexName]: index,
158
- });
159
- }
160
- }
161
-
162
- if (key != null) {
163
- instance.cacheByKey![key] = recordStore;
164
- } else if (isObject(data)) {
165
- instance.recordStoreCache!.set(data, recordStore);
166
- }
167
-
168
- return {
169
- store: recordStore,
170
- index: index,
171
- data: data,
172
- type: "data",
173
- key: this.keyField && isObject(data) ? (data as any)[this.keyField] : index,
174
- };
175
- }
176
-
177
- public setFilter(filterFn?: (data: T) => boolean): void {
178
- this.filterFn = filterFn;
179
- }
180
-
181
- public getComparer(sortOptions?: CollatorOptions): ((a: any, b: any) => number) | undefined {
182
- return sortOptions ? Culture.getComparer(sortOptions) : undefined;
183
- }
184
-
185
- public buildSorter(sorters: ExtendedSorter[]): void {
186
- if (isArray(sorters) && sorters.length > 0) {
187
- let dataAccessor: (x: DataAdapterRecord<T>) => any;
188
- let fieldValueMapper: (x: ExtendedSorter) => Prop<any>;
189
-
190
- if (sorters.every((x) => x.field && x.value == null)) {
191
- dataAccessor = (x) => x.data;
192
- fieldValueMapper = (x) => ({ bind: x.field! });
193
- } else {
194
- dataAccessor = (x) => x.store.getData();
195
- fieldValueMapper = (x) => ({ bind: this.recordName + "." + x.field });
196
- }
197
-
198
- this.sorter = sorter(
199
- sorters.map((x) => {
200
- const s: ExtendedSorter = Object.assign({}, x);
201
- if (s.field && s.value == null) {
202
- s.value = fieldValueMapper(s);
203
- }
204
- if (!s.comparer) {
205
- s.comparer = this.getComparer(isDefined(s.sortOptions) ? s.sortOptions : this.sortOptions);
206
- }
207
- return s;
208
- }),
209
- dataAccessor,
210
- );
211
- } else {
212
- this.sorter = undefined;
213
- }
214
- }
215
-
216
- public sort(sorters?: Sorter[] | ExtendedSorter[]): void {
217
- if (sorters) {
218
- this.buildSorter(sorters as ExtendedSorter[]);
219
- }
220
- }
221
- }
222
-
223
- ArrayAdapter.prototype.immutable = false;
224
- ArrayAdapter.prototype.sealed = false;
225
- ArrayAdapter.prototype.keyField = null;
226
- ArrayAdapter.prototype.cacheByKeyField = true;
227
- ArrayAdapter.prototype.isTreeAdapter = false;
228
-
229
- ArrayAdapter.autoInit = true;
1
+ import { DataAdapter, DataAdapterRecord, DataAdapterConfig } from "./DataAdapter";
2
+ import { ReadOnlyDataView } from "../../data/ReadOnlyDataView";
3
+ import { sorter } from "../../data/comparer";
4
+ import { isArray } from "../../util/isArray";
5
+ import { ArrayElementView } from "../../data/ArrayElementView";
6
+ import { Accessor, getAccessor } from "../../data/getAccessor";
7
+ import { Culture } from "../Culture";
8
+ import { isDefined, isObject } from "../../util";
9
+ import { RenderingContext } from "../RenderingContext";
10
+ import { Instance } from "../Instance";
11
+ import { View } from "../../data/View";
12
+ import { Prop, Sorter, CollatorOptions } from "../Prop";
13
+
14
+ export interface RecordStoreCache {
15
+ recordStoreCache: WeakMap<any, View>;
16
+ cacheByKey: Record<string | number, View>;
17
+ recordsAccessor?: Accessor;
18
+ }
19
+
20
+ export interface ArrayAdapterConfig extends DataAdapterConfig {
21
+ recordsBinding?: Prop<any[]>;
22
+ recordsAccessor?: Accessor | string;
23
+ keyField?: string;
24
+ cacheByKeyField?: boolean;
25
+ sortOptions?: CollatorOptions;
26
+ preserveOrder?: boolean;
27
+ }
28
+
29
+ export interface ExtendedSorter extends Sorter {
30
+ comparer?: (a: any, b: any) => number;
31
+ sortOptions?: CollatorOptions;
32
+ }
33
+
34
+ export interface ResolvedSorter {
35
+ getter: (x: any) => any;
36
+ factor: number;
37
+ compare: (a: any, b: any) => number;
38
+ }
39
+
40
+ export class ArrayAdapter<T = any> extends DataAdapter<T> {
41
+ declare public recordsAccessor: Accessor;
42
+ declare public recordsBinding?: Prop<T[]>;
43
+ declare public keyField: string | null;
44
+ declare public cacheByKeyField: boolean;
45
+ declare public sortOptions?: CollatorOptions;
46
+ declare public preserveOrder?: boolean;
47
+ declare isTreeAdapter: boolean;
48
+
49
+ declare protected sorter?: (data: DataAdapterRecord<T>[]) => DataAdapterRecord<T>[];
50
+
51
+ constructor(config?: ArrayAdapterConfig) {
52
+ super(config);
53
+ }
54
+
55
+ public init(): void {
56
+ this.recordsAccessor = this.recordsBinding ? getAccessor(this.recordsBinding) : getAccessor(this.recordsAccessor);
57
+ this.recordName = this.recordName?.toString() || "$record";
58
+ this.indexName = this.indexName?.toString() || "$index";
59
+ }
60
+
61
+ public initInstance(context: RenderingContext, instance: Instance & Partial<RecordStoreCache>): void {
62
+ if (!instance.recordStoreCache) {
63
+ instance.recordStoreCache = new WeakMap();
64
+ instance.cacheByKey = {};
65
+ }
66
+
67
+ if (!instance.recordsAccessor && this.recordsAccessor) {
68
+ instance.recordsAccessor = this.recordsAccessor.bindInstance
69
+ ? this.recordsAccessor.bindInstance(instance)
70
+ : this.recordsAccessor;
71
+ }
72
+ }
73
+
74
+ public getRecords(
75
+ context: RenderingContext,
76
+ instance: Instance & Partial<RecordStoreCache>,
77
+ records: T[],
78
+ parentStore: View,
79
+ ): DataAdapterRecord<T>[] {
80
+ if (!instance.recordStoreCache) {
81
+ this.initInstance(context, instance);
82
+ }
83
+
84
+ return this.mapRecords(context, instance, records, parentStore, instance.recordsAccessor);
85
+ }
86
+
87
+ public mapRecords(
88
+ context: RenderingContext,
89
+ instance: Instance & Partial<RecordStoreCache>,
90
+ records: T[],
91
+ parentStore: View,
92
+ recordsAccessor?: Accessor,
93
+ ): DataAdapterRecord<T>[] {
94
+ let result: DataAdapterRecord<T>[] = [];
95
+
96
+ if (!instance.recordStoreCache) {
97
+ this.initInstance(context, instance);
98
+ }
99
+
100
+ if (isArray(records)) {
101
+ records.forEach((data, index) => {
102
+ if (this.filterFn && !this.filterFn(data)) return;
103
+
104
+ const record = this.mapRecord(context, instance, data, parentStore, recordsAccessor, index);
105
+ result.push(record);
106
+ });
107
+ }
108
+
109
+ if (this.sorter && !this.preserveOrder) {
110
+ result = this.sorter(result);
111
+ }
112
+
113
+ return result;
114
+ }
115
+
116
+ public mapRecord(
117
+ context: RenderingContext,
118
+ instance: Instance & Partial<RecordStoreCache>,
119
+ data: T,
120
+ parentStore: View,
121
+ recordsAccessor: Accessor | undefined,
122
+ index: number,
123
+ ): DataAdapterRecord<T> {
124
+ const key = this.cacheByKeyField && this.keyField && isObject(data) ? (data as any)[this.keyField] : null;
125
+ let recordStore = key != null ? instance.cacheByKey![key] : instance.recordStoreCache!.get(data);
126
+
127
+ if (recordsAccessor) {
128
+ if (!recordStore) {
129
+ recordStore = new ArrayElementView({
130
+ store: parentStore,
131
+ arrayAccessor: recordsAccessor,
132
+ itemIndex: index,
133
+ recordAlias: this.recordName,
134
+ indexAlias: this.indexName,
135
+ immutable: this.immutable,
136
+ sealed: this.sealed,
137
+ });
138
+ } else {
139
+ (recordStore as ArrayElementView).setStore(parentStore);
140
+ (recordStore as ArrayElementView).setIndex(index);
141
+ }
142
+ } else {
143
+ if (!recordStore) {
144
+ recordStore = new ReadOnlyDataView({
145
+ store: parentStore,
146
+ data: {
147
+ [this.recordName]: data,
148
+ [this.indexName]: index,
149
+ },
150
+ immutable: this.immutable,
151
+ sealed: this.sealed,
152
+ });
153
+ } else {
154
+ (recordStore as ReadOnlyDataView).setStore(parentStore);
155
+ (recordStore as ReadOnlyDataView).setData({
156
+ [this.recordName]: data,
157
+ [this.indexName]: index,
158
+ });
159
+ }
160
+ }
161
+
162
+ if (key != null) {
163
+ instance.cacheByKey![key] = recordStore;
164
+ } else if (isObject(data)) {
165
+ instance.recordStoreCache!.set(data, recordStore);
166
+ }
167
+
168
+ return {
169
+ store: recordStore,
170
+ index: index,
171
+ data: data,
172
+ type: "data",
173
+ key: this.keyField && isObject(data) ? (data as any)[this.keyField] : index,
174
+ };
175
+ }
176
+
177
+ public setFilter(filterFn?: (data: T) => boolean): void {
178
+ this.filterFn = filterFn;
179
+ }
180
+
181
+ public getComparer(sortOptions?: CollatorOptions): ((a: any, b: any) => number) | undefined {
182
+ return sortOptions ? Culture.getComparer(sortOptions) : undefined;
183
+ }
184
+
185
+ public buildSorter(sorters: ExtendedSorter[]): void {
186
+ if (isArray(sorters) && sorters.length > 0) {
187
+ let dataAccessor: (x: DataAdapterRecord<T>) => any;
188
+ let fieldValueMapper: (x: ExtendedSorter) => Prop<any>;
189
+
190
+ if (sorters.every((x) => x.field && x.value == null)) {
191
+ dataAccessor = (x) => x.data;
192
+ fieldValueMapper = (x) => ({ bind: x.field! });
193
+ } else {
194
+ dataAccessor = (x) => x.store.getData();
195
+ fieldValueMapper = (x) => ({ bind: this.recordName + "." + x.field });
196
+ }
197
+
198
+ this.sorter = sorter(
199
+ sorters.map((x) => {
200
+ const s: ExtendedSorter = Object.assign({}, x);
201
+ if (s.field && s.value == null) {
202
+ s.value = fieldValueMapper(s);
203
+ }
204
+ if (!s.comparer) {
205
+ s.comparer = this.getComparer(isDefined(s.sortOptions) ? s.sortOptions : this.sortOptions);
206
+ }
207
+ return s;
208
+ }),
209
+ dataAccessor,
210
+ );
211
+ } else {
212
+ this.sorter = undefined;
213
+ }
214
+ }
215
+
216
+ public sort(sorters?: Sorter[] | ExtendedSorter[]): void {
217
+ if (sorters) {
218
+ this.buildSorter(sorters as ExtendedSorter[]);
219
+ }
220
+ }
221
+ }
222
+
223
+ ArrayAdapter.prototype.immutable = false;
224
+ ArrayAdapter.prototype.sealed = false;
225
+ ArrayAdapter.prototype.keyField = null;
226
+ ArrayAdapter.prototype.cacheByKeyField = true;
227
+ ArrayAdapter.prototype.isTreeAdapter = false;
228
+
229
+ ArrayAdapter.autoInit = true;