@nanahoshi/mona-ui 0.24.6 → 0.24.7
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/fesm2022/nanahoshi-mona-ui-check-box.mjs +14 -4
- package/fesm2022/nanahoshi-mona-ui-filter.mjs +233 -231
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-CD_ODHpU.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs} +24 -12
- package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs +208 -0
- package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs +1100 -0
- package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-Sa1aAtJ-.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs} +34 -21
- package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-BvUM9nPt.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs} +2564 -927
- package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +39 -8
- package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +1 -1
- package/fesm2022/nanahoshi-mona-ui-list-view.mjs +3 -6
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +33 -8
- package/fesm2022/nanahoshi-mona-ui-pager.mjs +367 -463
- package/fesm2022/nanahoshi-mona-ui-query.mjs +317 -122
- package/i18n/catalogs/en-US.messages.json +36 -11
- package/locales/ar-sa/ar-sa.messages.json +33 -8
- package/locales/de-de/de-de.messages.json +33 -8
- package/locales/es-es/es-es.messages.json +33 -8
- package/locales/fr-fr/fr-fr.messages.json +33 -8
- package/locales/id-id/id-id.messages.json +33 -8
- package/locales/it-it/it-it.messages.json +33 -8
- package/locales/ja-jp/ja-jp.messages.json +33 -8
- package/locales/ko-kr/ko-kr.messages.json +33 -8
- package/locales/pt-br/pt-br.messages.json +33 -8
- package/locales/ru-ru/ru-ru.messages.json +33 -8
- package/locales/tr-tr/tr-tr.messages.json +33 -8
- package/locales/zh-cn/zh-cn.messages.json +33 -8
- package/locales/zh-tw/zh-tw.messages.json +33 -8
- package/package.json +1 -1
- package/types/nanahoshi-mona-ui-check-box.d.ts +11 -1
- package/types/nanahoshi-mona-ui-filter.d.ts +54 -32
- package/types/nanahoshi-mona-ui-grid.d.ts +359 -110
- package/types/nanahoshi-mona-ui-i18n.d.ts +47 -6
- package/types/nanahoshi-mona-ui-list-view.d.ts +1 -2
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +31 -6
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +31 -6
- package/types/nanahoshi-mona-ui-pager.d.ts +159 -76
- package/types/nanahoshi-mona-ui-query.d.ts +45 -14
- package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-0jN7I1jo.mjs +0 -176
- package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-BI_iE7pl.mjs +0 -946
|
@@ -1,128 +1,306 @@
|
|
|
1
|
-
import { Enumerator } from '@mirei/ts-collections';
|
|
2
1
|
import { DateTime } from 'luxon';
|
|
2
|
+
import { Enumerator } from '@mirei/ts-collections';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const collatorCache = new Map();
|
|
5
|
+
const localeCache = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Compares two field values with one total order, so sorts, group orders and min/max agree:
|
|
8
|
+
* - empty values come first and are equal to each other: null, undefined, NaN, invalid dates, and values
|
|
9
|
+
* with no natural order (objects, arrays, symbols, functions);
|
|
10
|
+
* - then booleans, numbers and bigints (by value), dates (`Date` or luxon `DateTime`, by time),
|
|
11
|
+
* and strings (by the locale, with digits compared by value: "item 2" before "item 10").
|
|
12
|
+
*/
|
|
13
|
+
function compareValues(left, right, options) {
|
|
14
|
+
const leftRank = rankOf(left);
|
|
15
|
+
const rightRank = rankOf(right);
|
|
16
|
+
if (leftRank !== rightRank) {
|
|
17
|
+
return leftRank - rightRank;
|
|
18
|
+
}
|
|
19
|
+
switch (leftRank) {
|
|
20
|
+
case 0 /* ValueRank.Empty */:
|
|
21
|
+
return 0;
|
|
22
|
+
case 1 /* ValueRank.Boolean */:
|
|
23
|
+
return Number(left) - Number(right);
|
|
24
|
+
case 2 /* ValueRank.Number */: {
|
|
25
|
+
const a = left;
|
|
26
|
+
const b = right;
|
|
27
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
10
28
|
}
|
|
11
|
-
|
|
12
|
-
return
|
|
29
|
+
case 3 /* ValueRank.Date */:
|
|
30
|
+
return Math.sign(timeOf(left) - timeOf(right));
|
|
31
|
+
default:
|
|
32
|
+
return getCollator(options?.locale, "sort").compare(left, right);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
function getCollator(locale, kind) {
|
|
37
|
+
const resolved = resolveLocale(locale);
|
|
38
|
+
const key = `${resolved ?? ""}|${kind}`;
|
|
39
|
+
let collator = collatorCache.get(key);
|
|
40
|
+
if (collator == null) {
|
|
41
|
+
collator =
|
|
42
|
+
kind === "sort"
|
|
43
|
+
? new Intl.Collator(resolved, { numeric: true, usage: "sort" })
|
|
44
|
+
: new Intl.Collator(resolved, { sensitivity: "accent", usage: "search" });
|
|
45
|
+
collatorCache.set(key, collator);
|
|
46
|
+
}
|
|
47
|
+
return collator;
|
|
48
|
+
}
|
|
49
|
+
/** @internal An invalid locale falls back to the runtime's locale instead of throwing. */
|
|
50
|
+
function resolveLocale(locale) {
|
|
51
|
+
if (locale == null || locale === "") {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
if (!localeCache.has(locale)) {
|
|
55
|
+
let resolved;
|
|
56
|
+
try {
|
|
57
|
+
resolved = Intl.getCanonicalLocales(locale)[0];
|
|
13
58
|
}
|
|
14
|
-
|
|
15
|
-
|
|
59
|
+
catch {
|
|
60
|
+
resolved = undefined;
|
|
16
61
|
}
|
|
17
|
-
|
|
62
|
+
localeCache.set(locale, resolved);
|
|
63
|
+
}
|
|
64
|
+
return localeCache.get(locale);
|
|
65
|
+
}
|
|
66
|
+
function rankOf(value) {
|
|
67
|
+
if (value == null) {
|
|
68
|
+
return 0 /* ValueRank.Empty */;
|
|
69
|
+
}
|
|
70
|
+
switch (typeof value) {
|
|
71
|
+
case "boolean":
|
|
72
|
+
return 1 /* ValueRank.Boolean */;
|
|
73
|
+
case "number":
|
|
74
|
+
return Number.isNaN(value) ? 0 /* ValueRank.Empty */ : 2 /* ValueRank.Number */;
|
|
75
|
+
case "bigint":
|
|
76
|
+
return 2 /* ValueRank.Number */;
|
|
77
|
+
case "string":
|
|
78
|
+
return 4 /* ValueRank.String */;
|
|
79
|
+
default:
|
|
80
|
+
if (value instanceof Date || value instanceof DateTime) {
|
|
81
|
+
return Number.isNaN(timeOf(value)) ? 0 /* ValueRank.Empty */ : 3 /* ValueRank.Date */;
|
|
82
|
+
}
|
|
83
|
+
return 0 /* ValueRank.Empty */;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function timeOf(value) {
|
|
87
|
+
if (value instanceof Date) {
|
|
88
|
+
return value.getTime();
|
|
89
|
+
}
|
|
90
|
+
if (value instanceof DateTime) {
|
|
91
|
+
return value.isValid ? value.toMillis() : Number.NaN;
|
|
92
|
+
}
|
|
93
|
+
return Number.NaN;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Builds the predicate for a composite once; its children are compiled up front.
|
|
98
|
+
* An empty composite matches everything.
|
|
99
|
+
*/
|
|
100
|
+
const compositeDescriptorToPredicate = (descriptor, fieldSelector, options = {}) => {
|
|
101
|
+
const predicates = descriptor.filters.map(filter => isFilterDescriptor(filter)
|
|
102
|
+
? descriptorToPredicate(filter, fieldSelector, options)
|
|
103
|
+
: compositeDescriptorToPredicate(filter, fieldSelector, options));
|
|
104
|
+
if (predicates.length === 0) {
|
|
105
|
+
return () => true;
|
|
106
|
+
}
|
|
107
|
+
return descriptor.logic === "or"
|
|
108
|
+
? (item) => predicates.some(predicate => predicate(item))
|
|
109
|
+
: (item) => predicates.every(predicate => predicate(item));
|
|
18
110
|
};
|
|
19
|
-
|
|
20
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Builds the predicate for one field.
|
|
113
|
+
* - `eq`, `neq`, `in` and `notin` compare strings ignoring case (not accents), numbers with numeric
|
|
114
|
+
* strings by value, and dates (`Date`, luxon, ISO strings, timestamps) by day.
|
|
115
|
+
* - `gt`, `gte`, `lt`, `lte`, `between` and `notbetween` order the same way; they never match an empty value.
|
|
116
|
+
* - `contains`, `startswith` and `endswith` ignore case with the locale's rules; `doesnotcontain` treats
|
|
117
|
+
* an empty value as "".
|
|
118
|
+
*/
|
|
119
|
+
const descriptorToPredicate = (descriptor, fieldSelector, options = {}) => {
|
|
120
|
+
const locale = resolveLocale(options.locale);
|
|
121
|
+
const read = (item) => {
|
|
21
122
|
const source = fieldSelector ? fieldSelector(item) : item;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
123
|
+
return source != null && typeof source === "object"
|
|
124
|
+
? source[descriptor.field]
|
|
125
|
+
: undefined;
|
|
126
|
+
};
|
|
127
|
+
switch (descriptor.operator) {
|
|
128
|
+
case "eq":
|
|
129
|
+
return item => equateValues(read(item), descriptor.value, locale);
|
|
130
|
+
case "neq":
|
|
131
|
+
return item => !equateValues(read(item), descriptor.value, locale);
|
|
132
|
+
case "gt":
|
|
133
|
+
return item => compareOrdered(read(item), descriptor.value, locale) > 0;
|
|
134
|
+
case "gte":
|
|
135
|
+
return item => compareOrdered(read(item), descriptor.value, locale) >= 0;
|
|
136
|
+
case "lt":
|
|
137
|
+
return item => compareOrdered(read(item), descriptor.value, locale) < 0;
|
|
138
|
+
case "lte":
|
|
139
|
+
return item => compareOrdered(read(item), descriptor.value, locale) <= 0;
|
|
140
|
+
case "startswith":
|
|
141
|
+
case "endswith":
|
|
142
|
+
case "contains":
|
|
143
|
+
case "doesnotcontain": {
|
|
144
|
+
const operator = descriptor.operator;
|
|
145
|
+
const search = typeof descriptor.value === "string" ? lowercase(descriptor.value, locale) : null;
|
|
146
|
+
return item => {
|
|
147
|
+
if (search == null) {
|
|
30
148
|
return false;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
149
|
+
}
|
|
150
|
+
const value = read(item);
|
|
151
|
+
if (operator === "doesnotcontain") {
|
|
152
|
+
return value == null || (typeof value === "string" && !lowercase(value, locale).includes(search));
|
|
153
|
+
}
|
|
154
|
+
if (typeof value !== "string") {
|
|
34
155
|
return false;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
156
|
+
}
|
|
157
|
+
const text = lowercase(value, locale);
|
|
158
|
+
return operator === "contains"
|
|
159
|
+
? text.includes(search)
|
|
160
|
+
: operator === "startswith"
|
|
161
|
+
? text.startsWith(search)
|
|
162
|
+
: text.endsWith(search);
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
case "isfalse":
|
|
166
|
+
return item => read(item) === false;
|
|
167
|
+
case "istrue":
|
|
168
|
+
return item => read(item) === true;
|
|
169
|
+
case "isnull":
|
|
170
|
+
return item => read(item) == null;
|
|
171
|
+
case "isnotnull":
|
|
172
|
+
return item => read(item) != null;
|
|
173
|
+
case "isempty":
|
|
174
|
+
return item => read(item) === "";
|
|
175
|
+
case "isnotempty":
|
|
176
|
+
return item => read(item) !== "";
|
|
177
|
+
case "isnullorempty":
|
|
178
|
+
return item => isNullOrEmpty(read(item));
|
|
179
|
+
case "isnotnullorempty":
|
|
180
|
+
return item => !isNullOrEmpty(read(item));
|
|
181
|
+
case "in":
|
|
182
|
+
case "notin": {
|
|
183
|
+
const candidates = Array.isArray(descriptor.value) ? descriptor.value : [];
|
|
184
|
+
const included = (item) => {
|
|
185
|
+
const value = read(item);
|
|
186
|
+
return candidates.some(candidate => equateValues(value, candidate, locale));
|
|
187
|
+
};
|
|
188
|
+
return descriptor.operator === "in" ? included : item => !included(item);
|
|
189
|
+
}
|
|
190
|
+
case "between":
|
|
191
|
+
case "notbetween": {
|
|
192
|
+
const operator = descriptor.operator;
|
|
193
|
+
const [from, to] = Array.isArray(descriptor.value)
|
|
194
|
+
? descriptor.value
|
|
195
|
+
: [null, null];
|
|
196
|
+
return item => {
|
|
197
|
+
const value = read(item);
|
|
198
|
+
if (isEmptyValue(value)) {
|
|
38
199
|
return false;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
200
|
+
}
|
|
201
|
+
const afterFrom = from == null ? 0 : compareOrdered(value, from, locale);
|
|
202
|
+
const beforeTo = to == null ? 0 : compareOrdered(to, value, locale);
|
|
203
|
+
if (Number.isNaN(afterFrom) || Number.isNaN(beforeTo)) {
|
|
42
204
|
return false;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
: false;
|
|
48
|
-
case "endswith":
|
|
49
|
-
return typeof value === "string" && typeof descriptor.value === "string"
|
|
50
|
-
? value.toLowerCase().endsWith(descriptor.value.toLowerCase())
|
|
51
|
-
: false;
|
|
52
|
-
case "contains":
|
|
53
|
-
return typeof value === "string" && typeof descriptor.value === "string"
|
|
54
|
-
? value.toLowerCase().includes(descriptor.value.toLowerCase())
|
|
55
|
-
: false;
|
|
56
|
-
case "doesnotcontain":
|
|
57
|
-
return typeof value === "string" && typeof descriptor.value === "string"
|
|
58
|
-
? !value.toLowerCase().includes(descriptor.value.toLowerCase())
|
|
59
|
-
: false;
|
|
60
|
-
case "isfalse":
|
|
61
|
-
return value === false;
|
|
62
|
-
case "istrue":
|
|
63
|
-
return value === true;
|
|
64
|
-
case "isnull":
|
|
65
|
-
return value == null;
|
|
66
|
-
case "isnotnull":
|
|
67
|
-
return value != null;
|
|
68
|
-
case "isempty":
|
|
69
|
-
return value === "";
|
|
70
|
-
case "isnotempty":
|
|
71
|
-
return value !== "";
|
|
72
|
-
case "isnullorempty":
|
|
73
|
-
return value == null || value === "";
|
|
74
|
-
case "isnotnullorempty":
|
|
75
|
-
return value != null && value !== "";
|
|
76
|
-
case "in":
|
|
77
|
-
return Array.isArray(descriptor.value) && descriptor.value.includes(value);
|
|
78
|
-
case "notin":
|
|
79
|
-
return !Array.isArray(descriptor.value) || !descriptor.value.includes(value);
|
|
80
|
-
case "function":
|
|
81
|
-
return descriptor.predicate(value);
|
|
82
|
-
default:
|
|
83
|
-
return false;
|
|
205
|
+
}
|
|
206
|
+
const inRange = afterFrom >= 0 && beforeTo >= 0;
|
|
207
|
+
return operator === "between" ? inRange : !inRange;
|
|
208
|
+
};
|
|
84
209
|
}
|
|
85
|
-
|
|
210
|
+
case "function":
|
|
211
|
+
return item => descriptor.predicate(read(item));
|
|
212
|
+
default:
|
|
213
|
+
return () => false;
|
|
214
|
+
}
|
|
86
215
|
};
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
216
|
+
/** @internal */
|
|
217
|
+
const isFilterDescriptor = (filter) => Object.hasOwn(filter, "field");
|
|
218
|
+
const isNullOrEmpty = (value) => value == null || value === "";
|
|
219
|
+
const isEmptyValue = (value) => value == null || (typeof value === "number" && Number.isNaN(value));
|
|
220
|
+
const isDateLike = (value) => value instanceof Date || value instanceof DateTime;
|
|
221
|
+
const lowercase = (value, locale) => value.toLocaleLowerCase(locale);
|
|
222
|
+
/** The start of the value's day, or NaN when it isn't a date. */
|
|
223
|
+
const toDay = (value) => {
|
|
224
|
+
let dateTime = null;
|
|
225
|
+
if (value instanceof DateTime) {
|
|
226
|
+
dateTime = value;
|
|
227
|
+
}
|
|
228
|
+
else if (value instanceof Date) {
|
|
229
|
+
dateTime = DateTime.fromJSDate(value);
|
|
230
|
+
}
|
|
231
|
+
else if (typeof value === "string") {
|
|
232
|
+
dateTime = DateTime.fromISO(value.trim());
|
|
233
|
+
}
|
|
234
|
+
else if (typeof value === "number" && Number.isFinite(value)) {
|
|
235
|
+
dateTime = DateTime.fromMillis(value);
|
|
236
|
+
}
|
|
237
|
+
return dateTime?.isValid ? dateTime.startOf("day").toMillis() : Number.NaN;
|
|
91
238
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
if (
|
|
98
|
-
return
|
|
99
|
-
|
|
239
|
+
/** A finite number from a number or a numeric string, or NaN. */
|
|
240
|
+
const toNumber = (value) => {
|
|
241
|
+
if (typeof value === "number") {
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
if (typeof value === "bigint") {
|
|
245
|
+
return Number(value);
|
|
246
|
+
}
|
|
247
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
248
|
+
return Number(value);
|
|
249
|
+
}
|
|
250
|
+
return Number.NaN;
|
|
100
251
|
};
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
252
|
+
const isNumeric = (value) => typeof value === "number" || typeof value === "bigint";
|
|
253
|
+
const equateValues = (a, b, locale) => {
|
|
254
|
+
if (a == null || b == null) {
|
|
255
|
+
return a == null && b == null;
|
|
256
|
+
}
|
|
257
|
+
if (isDateLike(a) || isDateLike(b)) {
|
|
258
|
+
const left = toDay(a);
|
|
259
|
+
return !Number.isNaN(left) && left === toDay(b);
|
|
260
|
+
}
|
|
261
|
+
if (isNumeric(a) || isNumeric(b)) {
|
|
262
|
+
const left = toNumber(a);
|
|
263
|
+
return !Number.isNaN(left) && left === toNumber(b);
|
|
264
|
+
}
|
|
265
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
266
|
+
return getCollator(locale, "equality").compare(a, b) === 0;
|
|
267
|
+
}
|
|
268
|
+
return a === b;
|
|
105
269
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
270
|
+
/** Negative, zero or positive; NaN when the values can't be ordered (so every comparison is false). */
|
|
271
|
+
const compareOrdered = (a, b, locale) => {
|
|
272
|
+
if (isEmptyValue(a) || isEmptyValue(b)) {
|
|
273
|
+
return Number.NaN;
|
|
109
274
|
}
|
|
110
|
-
|
|
111
|
-
return
|
|
275
|
+
if (isDateLike(a) || isDateLike(b)) {
|
|
276
|
+
return toDay(a) - toDay(b);
|
|
112
277
|
}
|
|
278
|
+
if (isNumeric(a) || isNumeric(b)) {
|
|
279
|
+
return toNumber(a) - toNumber(b);
|
|
280
|
+
}
|
|
281
|
+
if (typeof a === "string" && typeof b === "string") {
|
|
282
|
+
return getCollator(locale, "equality").compare(a, b);
|
|
283
|
+
}
|
|
284
|
+
return Number.NaN;
|
|
113
285
|
};
|
|
114
286
|
|
|
115
287
|
class Query {
|
|
116
288
|
#enumerator;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.#
|
|
289
|
+
#iterable;
|
|
290
|
+
constructor(iterable, options) {
|
|
291
|
+
this.#iterable = iterable;
|
|
292
|
+
this.#enumerator = new QueryEnumerator(() => iterable, options);
|
|
120
293
|
}
|
|
121
|
-
|
|
122
|
-
|
|
294
|
+
/**
|
|
295
|
+
* @description Starts a query over the given items.
|
|
296
|
+
* @param iterable The items to filter and sort.
|
|
297
|
+
* @param options `locale` sets how strings are compared and lowercased; it defaults to the runtime's locale.
|
|
298
|
+
*/
|
|
299
|
+
static from(iterable, options = {}) {
|
|
300
|
+
return new Query(iterable, options);
|
|
123
301
|
}
|
|
124
|
-
|
|
125
|
-
|
|
302
|
+
*[Symbol.iterator]() {
|
|
303
|
+
yield* this.#iterable;
|
|
126
304
|
}
|
|
127
305
|
filter(filter, fieldSelector) {
|
|
128
306
|
return this.#enumerator.filter(filter, fieldSelector);
|
|
@@ -135,41 +313,58 @@ class Query {
|
|
|
135
313
|
}
|
|
136
314
|
}
|
|
137
315
|
class QueryEnumerator extends Enumerator {
|
|
138
|
-
|
|
316
|
+
#options;
|
|
317
|
+
constructor(iterable, options = {}) {
|
|
139
318
|
super(iterable);
|
|
319
|
+
this.#options = options;
|
|
140
320
|
}
|
|
141
321
|
filter(filter, fieldSelector) {
|
|
142
|
-
|
|
322
|
+
const predicate = isFilterDescriptor(filter)
|
|
323
|
+
? descriptorToPredicate(filter, fieldSelector, this.#options)
|
|
324
|
+
: compositeDescriptorToPredicate(filter, fieldSelector, this.#options);
|
|
325
|
+
return new QueryEnumerator(() => this.where(predicate), this.#options);
|
|
143
326
|
}
|
|
144
327
|
run() {
|
|
145
328
|
return Array.from(this);
|
|
146
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Sorts by every descriptor in turn with one stable comparison, so later descriptors order the rows
|
|
332
|
+
* that tie on earlier ones. Without a custom `sort`, values compare with {@link compareValues}:
|
|
333
|
+
* empty values first ascending (last descending), strings by the locale.
|
|
334
|
+
*/
|
|
147
335
|
sort(descriptor, fieldSelector) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*filterGenerator(filter, fieldSelector) {
|
|
151
|
-
const predicate = filter.hasOwnProperty("field")
|
|
152
|
-
? descriptorToPredicate(filter, fieldSelector)
|
|
153
|
-
: compositeDescriptorToPredicate(filter, fieldSelector);
|
|
154
|
-
yield* this.where(predicate);
|
|
155
|
-
}
|
|
156
|
-
*sortGenerator(descriptor, fieldSelector) {
|
|
157
|
-
let result = descriptor[0].dir === "asc"
|
|
158
|
-
? this.orderBy(d => (fieldSelector ? fieldSelector(d) : d)[descriptor[0].field], descriptor[0].sort)
|
|
159
|
-
: this.orderByDescending(d => (fieldSelector ? fieldSelector(d) : d)[descriptor[0].field], descriptor[0].sort);
|
|
160
|
-
for (let i = 1; i < descriptor.length; i++) {
|
|
161
|
-
result =
|
|
162
|
-
descriptor[i].dir === "asc"
|
|
163
|
-
? result.thenBy(d => (fieldSelector ? fieldSelector(d) : d)[descriptor[i].field], descriptor[i].sort)
|
|
164
|
-
: result.thenByDescending(d => (fieldSelector ? fieldSelector(d) : d)[descriptor[i].field], descriptor[i].sort);
|
|
336
|
+
if (descriptor.length === 0) {
|
|
337
|
+
return this;
|
|
165
338
|
}
|
|
166
|
-
|
|
339
|
+
return new QueryEnumerator(() => this.#sortItems(descriptor, fieldSelector), this.#options);
|
|
340
|
+
}
|
|
341
|
+
#sortItems(descriptors, fieldSelector) {
|
|
342
|
+
const entries = Array.from(this, item => {
|
|
343
|
+
const source = fieldSelector ? fieldSelector(item) : item;
|
|
344
|
+
return { item, values: descriptors.map(d => readField(source, d.field)) };
|
|
345
|
+
});
|
|
346
|
+
entries.sort((left, right) => {
|
|
347
|
+
for (let index = 0; index < descriptors.length; index++) {
|
|
348
|
+
const descriptor = descriptors[index];
|
|
349
|
+
const a = left.values[index];
|
|
350
|
+
const b = right.values[index];
|
|
351
|
+
const result = descriptor.sort ? descriptor.sort(a, b) : compareValues(a, b, this.#options);
|
|
352
|
+
if (result !== 0 && !Number.isNaN(result)) {
|
|
353
|
+
return descriptor.dir === "desc" ? -result : result;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return 0;
|
|
357
|
+
});
|
|
358
|
+
return entries.map(entry => entry.item);
|
|
167
359
|
}
|
|
168
360
|
}
|
|
361
|
+
function readField(source, field) {
|
|
362
|
+
return source != null && typeof source === "object" ? source[field] : undefined;
|
|
363
|
+
}
|
|
169
364
|
|
|
170
365
|
/**
|
|
171
366
|
* Generated bundle index. Do not edit.
|
|
172
367
|
*/
|
|
173
368
|
|
|
174
|
-
export { Query };
|
|
369
|
+
export { Query, compareValues };
|
|
175
370
|
//# sourceMappingURL=nanahoshi-mona-ui-query.mjs.map
|
|
@@ -189,34 +189,51 @@
|
|
|
189
189
|
"isNull": "Is null",
|
|
190
190
|
"isNullOrEmpty": "Is null or empty",
|
|
191
191
|
"isTrue": "Is true",
|
|
192
|
+
"logic": "Combine conditions",
|
|
193
|
+
"operator": "Operator",
|
|
192
194
|
"or": "OR",
|
|
193
|
-
"
|
|
195
|
+
"secondOperator": "Second operator",
|
|
196
|
+
"secondValue": "Second value",
|
|
197
|
+
"startsWith": "Starts with",
|
|
198
|
+
"value": "Value"
|
|
194
199
|
},
|
|
195
200
|
"grid": {
|
|
196
201
|
"all": "(All)",
|
|
197
202
|
"apply": "Apply",
|
|
198
203
|
"cancel": "Cancel",
|
|
199
|
-
"
|
|
204
|
+
"cancelNewRow": "Cancel new row",
|
|
205
|
+
"cancelRowEdit": "Cancel editing row {rowNumber}",
|
|
206
|
+
"clearFilter": "Clear filter for {column}",
|
|
207
|
+
"collapseDetail": "Collapse details of row {rowNumber}",
|
|
208
|
+
"columnGrouped": "Grouped by {column}",
|
|
209
|
+
"columnMoved": "{column} moved to position {position}",
|
|
200
210
|
"columns": "Columns",
|
|
201
211
|
"columnsSelected": "{count} selected columns",
|
|
212
|
+
"commandColumnTitle": "Commands",
|
|
202
213
|
"delete": "Delete",
|
|
203
|
-
"deleteRowConfirmation": "Are you sure you want to delete
|
|
214
|
+
"deleteRowConfirmation": "Are you sure you want to delete row {rowNumber}?",
|
|
204
215
|
"deleteRowTitle": "Delete row?",
|
|
216
|
+
"details": "Details",
|
|
205
217
|
"dragColumnHeaderToGroup": "Drag a column header here to group",
|
|
206
218
|
"edit": "Edit",
|
|
207
|
-
"editRow": "Edit row",
|
|
219
|
+
"editRow": "Edit row {rowNumber}",
|
|
220
|
+
"expandDetail": "Expand details of row {rowNumber}",
|
|
208
221
|
"fieldValidationError": "Invalid value.",
|
|
209
222
|
"filterByColumn": "Filter by {column}",
|
|
223
|
+
"filterByColumnFiltered": "Filter by {column}, filtered",
|
|
224
|
+
"filterOperator": "Filter operator for {column}: {operator}",
|
|
210
225
|
"filterPlaceholder": "Filter...",
|
|
226
|
+
"group": "Group",
|
|
227
|
+
"loading": "Loading",
|
|
211
228
|
"modified": "Modified",
|
|
212
229
|
"moveAsNext": "Move as next",
|
|
213
230
|
"moveAsPrevious": "Move as previous",
|
|
214
231
|
"moveRow": "Move row",
|
|
215
232
|
"noData": "No data",
|
|
216
233
|
"remove": "Remove",
|
|
217
|
-
"removeRow": "Remove row",
|
|
234
|
+
"removeRow": "Remove row {rowNumber}",
|
|
218
235
|
"reorderRow": "Reorder row {rowNumber}",
|
|
219
|
-
"resizeColumn": "Resize column",
|
|
236
|
+
"resizeColumn": "Resize {column}",
|
|
220
237
|
"rowReorder": "Row reorder",
|
|
221
238
|
"rowReorderDisabled": "Row reordering is disabled.",
|
|
222
239
|
"rowReorderDisabledEditing": "Finish editing to reorder rows.",
|
|
@@ -231,9 +248,12 @@
|
|
|
231
248
|
"rowReorderMoved": "Moved row {fromRowNumber} to position {toPosition}.",
|
|
232
249
|
"rowValidationError": "This row has validation errors.",
|
|
233
250
|
"save": "Save",
|
|
234
|
-
"
|
|
251
|
+
"saveNewRow": "Save new row",
|
|
252
|
+
"saveRow": "Save row {rowNumber}",
|
|
235
253
|
"selectAllRows": "Select all rows",
|
|
236
|
-
"selectRow": "Select row {rowNumber}"
|
|
254
|
+
"selectRow": "Select row {rowNumber}",
|
|
255
|
+
"sortOrder": "Sort order {position}",
|
|
256
|
+
"toolbar": "Grid toolbar"
|
|
237
257
|
},
|
|
238
258
|
"list": {
|
|
239
259
|
"filterList": "Filter list",
|
|
@@ -270,17 +290,22 @@
|
|
|
270
290
|
},
|
|
271
291
|
"pager": {
|
|
272
292
|
"firstPageLabel": "First page",
|
|
273
|
-
"
|
|
274
|
-
"
|
|
293
|
+
"itemsPerPageLabel": "Items per page",
|
|
294
|
+
"jumpBackwardLabel": "Jump back {pages, plural, one {# page} other {# pages}}",
|
|
295
|
+
"jumpForwardLabel": "Jump forward {pages, plural, one {# page} other {# pages}}",
|
|
275
296
|
"lastPageLabel": "Last page",
|
|
276
297
|
"nextPageLabel": "Next page",
|
|
277
298
|
"ofText": "of",
|
|
299
|
+
"pageInputPrefix": "Page",
|
|
300
|
+
"pageInputSuffix": "of {totalPages}",
|
|
278
301
|
"pageLabel": "Page {page}",
|
|
302
|
+
"pageSelectLabel": "Page",
|
|
279
303
|
"pageSizeLabel": "{pageSize} / page",
|
|
280
304
|
"pageStatus": "Page {page} of {totalPages}",
|
|
281
305
|
"pageText": "Page",
|
|
306
|
+
"pagerLabel": "Pagination",
|
|
282
307
|
"previousPageLabel": "Previous page",
|
|
283
|
-
"rangeStatus": "{start} - {end} of {total} items"
|
|
308
|
+
"rangeStatus": "{start} - {end} of {total, plural, one {# item} other {# items}}"
|
|
284
309
|
},
|
|
285
310
|
"rating": {
|
|
286
311
|
"notRated": "Not rated",
|