cx 26.4.2 → 26.4.3
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/build/jsx-dev-runtime.d.ts +1 -0
- package/build/jsx-dev-runtime.d.ts.map +1 -1
- package/build/jsx-dev-runtime.js +1 -0
- package/dist/manifest.js +889 -889
- package/package.json +1 -1
- package/src/charts/BarGraph.scss +31 -31
- package/src/charts/Legend.scss +57 -57
- package/src/charts/LegendEntry.scss +35 -35
- package/src/charts/LineGraph.scss +28 -28
- package/src/charts/helpers/SnapPointFinder.ts +136 -136
- package/src/charts/helpers/ValueAtFinder.ts +72 -72
- package/src/data/createAccessorModelProxy.ts +66 -66
- package/src/jsx-dev-runtime.ts +1 -0
- package/src/ui/DataProxy.ts +55 -55
- package/src/ui/Repeater.spec.tsx +181 -181
- package/src/ui/Rescope.ts +50 -50
- package/src/ui/adapter/ArrayAdapter.ts +229 -229
- package/src/ui/exprHelpers.ts +96 -96
- package/src/util/scss/include.scss +69 -69
- package/src/widgets/Button.maps.scss +103 -103
- package/src/widgets/Sandbox.ts +104 -104
- package/src/widgets/form/Calendar.tsx +772 -772
- package/src/widgets/form/ColorField.scss +112 -112
- package/src/widgets/form/DateTimeField.scss +111 -111
- package/src/widgets/form/LookupField.maps.scss +26 -26
- package/src/widgets/form/LookupField.scss +227 -227
- package/src/widgets/form/MonthField.scss +113 -113
- package/src/widgets/form/NumberField.scss +72 -72
- package/src/widgets/form/Select.scss +104 -104
- package/src/widgets/form/TextField.scss +66 -66
- package/src/widgets/grid/Grid.scss +657 -657
- package/src/widgets/grid/variables.scss +47 -47
- package/src/widgets/index.ts +63 -63
- package/src/widgets/nav/MenuItem.scss +150 -150
- package/src/widgets/nav/MenuItem.tsx +525 -525
- package/src/widgets/nav/Tab.ts +122 -122
- package/src/widgets/overlay/Overlay.tsx +1029 -1029
- package/src/widgets/variables.scss +61 -61
|
@@ -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;
|
package/src/ui/exprHelpers.ts
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { computable } from "../data/computable";
|
|
2
|
-
import { AccessorChain } from "../data/createAccessorModelProxy";
|
|
3
|
-
import { Selector } from "../data/Selector";
|
|
4
|
-
import { Format } from "../util/Format";
|
|
5
|
-
import { expr } from "./expr";
|
|
6
|
-
|
|
7
|
-
/** Returns a selector that converts the value to boolean using !! */
|
|
8
|
-
export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
9
|
-
return expr(arg, (x) => !!x);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Returns a selector that checks if the value is falsy using ! */
|
|
13
|
-
export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
14
|
-
return expr(arg, (x) => !x);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/** Returns a selector that checks if the value is strictly true (=== true) */
|
|
18
|
-
export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
|
|
19
|
-
return expr(arg, (x) => x === true);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Returns a selector that checks if the value is strictly false (=== false) */
|
|
23
|
-
export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
|
|
24
|
-
return expr(arg, (x) => x === false);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** Returns a selector that checks if the value is not null or undefined (x != null) */
|
|
28
|
-
export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
29
|
-
return expr(arg, (x) => x != null);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
|
|
33
|
-
export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
|
|
34
|
-
return expr(arg, (x) => x == null || x.length === 0);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
|
|
38
|
-
export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
|
|
39
|
-
return expr(arg, (x) => x != null && x.length > 0);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** Returns a selector that checks if the value is less than the given value */
|
|
43
|
-
export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
44
|
-
return expr(arg, (x) => x < value);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Returns a selector that checks if the value is less than or equal to the given value */
|
|
48
|
-
export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
49
|
-
return expr(arg, (x) => x <= value);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** Returns a selector that checks if the value is greater than the given value */
|
|
53
|
-
export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
54
|
-
return expr(arg, (x) => x > value);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Returns a selector that checks if the value is greater than or equal to the given value */
|
|
58
|
-
export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
59
|
-
return expr(arg, (x) => x >= value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** Returns a selector that checks if the value equals the given value using == */
|
|
63
|
-
export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
64
|
-
return expr(arg, (x) => x == value);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Returns a selector that checks if the value does not equal the given value using != */
|
|
68
|
-
export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
69
|
-
return expr(arg, (x) => x != value);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** Returns a selector that checks if the value strictly equals the given value using === */
|
|
73
|
-
export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
74
|
-
return expr(arg, (x) => x === value);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Returns a selector that checks if the value strictly does not equal the given value using !== */
|
|
78
|
-
export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
79
|
-
return expr(arg, (x) => x !== value);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** Returns a selector that formats the value using the specified format string.
|
|
83
|
-
* Format strings use semicolon-separated syntax: "formatType;param1;param2"
|
|
84
|
-
* @param arg - The accessor chain to the value
|
|
85
|
-
* @param fmt - The format string
|
|
86
|
-
* @param nullText - Optional text to display for null/undefined values
|
|
87
|
-
* @example
|
|
88
|
-
* format(m.price, "n;2") // formats as number with 2 decimal places
|
|
89
|
-
* format(m.date, "d") // formats as date
|
|
90
|
-
* format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
|
|
91
|
-
* format(m.value, "n;2", "N/A") // shows "N/A" for null values
|
|
92
|
-
*/
|
|
93
|
-
export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
|
|
94
|
-
let f = nullText != null ? `${fmt}|${nullText}` : fmt;
|
|
95
|
-
return computable(arg, (x) => Format.value(x, f));
|
|
96
|
-
}
|
|
1
|
+
import { computable } from "../data/computable";
|
|
2
|
+
import { AccessorChain } from "../data/createAccessorModelProxy";
|
|
3
|
+
import { Selector } from "../data/Selector";
|
|
4
|
+
import { Format } from "../util/Format";
|
|
5
|
+
import { expr } from "./expr";
|
|
6
|
+
|
|
7
|
+
/** Returns a selector that converts the value to boolean using !! */
|
|
8
|
+
export function truthy<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
9
|
+
return expr(arg, (x) => !!x);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Returns a selector that checks if the value is falsy using ! */
|
|
13
|
+
export function falsy<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
14
|
+
return expr(arg, (x) => !x);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Returns a selector that checks if the value is strictly true (=== true) */
|
|
18
|
+
export function isTrue(arg: AccessorChain<any>): Selector<boolean> {
|
|
19
|
+
return expr(arg, (x) => x === true);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Returns a selector that checks if the value is strictly false (=== false) */
|
|
23
|
+
export function isFalse(arg: AccessorChain<any>): Selector<boolean> {
|
|
24
|
+
return expr(arg, (x) => x === false);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Returns a selector that checks if the value is not null or undefined (x != null) */
|
|
28
|
+
export function hasValue<V>(arg: AccessorChain<V>): Selector<boolean> {
|
|
29
|
+
return expr(arg, (x) => x != null);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Returns a selector that checks if a string or array is empty (null, undefined, or length === 0) */
|
|
33
|
+
export function isEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
|
|
34
|
+
return expr(arg, (x) => x == null || x.length === 0);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Returns a selector that checks if a string or array is non-empty (not null/undefined and length > 0) */
|
|
38
|
+
export function isNonEmpty(arg: AccessorChain<string | any[] | null | undefined>): Selector<boolean> {
|
|
39
|
+
return expr(arg, (x) => x != null && x.length > 0);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Returns a selector that checks if the value is less than the given value */
|
|
43
|
+
export function lessThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
44
|
+
return expr(arg, (x) => x < value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Returns a selector that checks if the value is less than or equal to the given value */
|
|
48
|
+
export function lessThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
49
|
+
return expr(arg, (x) => x <= value);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Returns a selector that checks if the value is greater than the given value */
|
|
53
|
+
export function greaterThan<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
54
|
+
return expr(arg, (x) => x > value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Returns a selector that checks if the value is greater than or equal to the given value */
|
|
58
|
+
export function greaterThanOrEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
59
|
+
return expr(arg, (x) => x >= value);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Returns a selector that checks if the value equals the given value using == */
|
|
63
|
+
export function equal<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
64
|
+
return expr(arg, (x) => x == value);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Returns a selector that checks if the value does not equal the given value using != */
|
|
68
|
+
export function notEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
69
|
+
return expr(arg, (x) => x != value);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Returns a selector that checks if the value strictly equals the given value using === */
|
|
73
|
+
export function strictEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
74
|
+
return expr(arg, (x) => x === value);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Returns a selector that checks if the value strictly does not equal the given value using !== */
|
|
78
|
+
export function strictNotEqual<V>(arg: AccessorChain<V>, value: V): Selector<boolean> {
|
|
79
|
+
return expr(arg, (x) => x !== value);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Returns a selector that formats the value using the specified format string.
|
|
83
|
+
* Format strings use semicolon-separated syntax: "formatType;param1;param2"
|
|
84
|
+
* @param arg - The accessor chain to the value
|
|
85
|
+
* @param fmt - The format string
|
|
86
|
+
* @param nullText - Optional text to display for null/undefined values
|
|
87
|
+
* @example
|
|
88
|
+
* format(m.price, "n;2") // formats as number with 2 decimal places
|
|
89
|
+
* format(m.date, "d") // formats as date
|
|
90
|
+
* format(m.value, "p;0;2") // formats as percentage with 0-2 decimal places
|
|
91
|
+
* format(m.value, "n;2", "N/A") // shows "N/A" for null values
|
|
92
|
+
*/
|
|
93
|
+
export function format<V>(arg: AccessorChain<V>, fmt: string, nullText?: string): Selector<string> {
|
|
94
|
+
let f = nullText != null ? `${fmt}|${nullText}` : fmt;
|
|
95
|
+
return computable(arg, (x) => Format.value(x, f));
|
|
96
|
+
}
|