@nanahoshi/mona-ui 0.24.5 → 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.
Files changed (78) hide show
  1. package/README.md +2 -0
  2. package/fesm2022/nanahoshi-mona-ui-calendar.mjs +196 -137
  3. package/fesm2022/nanahoshi-mona-ui-check-box.mjs +14 -4
  4. package/fesm2022/nanahoshi-mona-ui-date-input.mjs +164 -3
  5. package/fesm2022/nanahoshi-mona-ui-date-picker.mjs +124 -140
  6. package/fesm2022/nanahoshi-mona-ui-datetime-picker.mjs +205 -202
  7. package/fesm2022/nanahoshi-mona-ui-filter.mjs +233 -231
  8. package/fesm2022/{nanahoshi-mona-ui-grid-grid-footer-row.component-BMCM0W8s.mjs → nanahoshi-mona-ui-grid-grid-footer-row.component-vXXNWmEN.mjs} +24 -12
  9. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-DDgNmgE0.mjs +208 -0
  10. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-Dzf6Vbs_.mjs +1100 -0
  11. package/fesm2022/{nanahoshi-mona-ui-grid-grid-virtual-list.component-C2kf5MwO.mjs → nanahoshi-mona-ui-grid-grid-virtual-list.component-DAPNqnWV.mjs} +34 -21
  12. package/fesm2022/{nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-Dh42tUui.mjs → nanahoshi-mona-ui-grid-nanahoshi-mona-ui-grid-B9rmDLq8.mjs} +2564 -927
  13. package/fesm2022/nanahoshi-mona-ui-grid.mjs +1 -1
  14. package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +39 -8
  15. package/fesm2022/nanahoshi-mona-ui-internal-tree.mjs +1 -1
  16. package/fesm2022/nanahoshi-mona-ui-list-view.mjs +3 -6
  17. package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +33 -8
  18. package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +33 -8
  19. package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +33 -8
  20. package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +33 -8
  21. package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +33 -8
  22. package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +33 -8
  23. package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +33 -8
  24. package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +33 -8
  25. package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +33 -8
  26. package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +33 -8
  27. package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +33 -8
  28. package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +33 -8
  29. package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +33 -8
  30. package/fesm2022/nanahoshi-mona-ui-numeric-text-box.mjs +195 -122
  31. package/fesm2022/nanahoshi-mona-ui-pager.mjs +367 -463
  32. package/fesm2022/nanahoshi-mona-ui-query.mjs +317 -122
  33. package/fesm2022/nanahoshi-mona-ui-time-picker.mjs +149 -167
  34. package/fesm2022/nanahoshi-mona-ui-time-selector.mjs +182 -137
  35. package/i18n/catalogs/en-US.messages.json +36 -11
  36. package/locales/ar-sa/ar-sa.messages.json +33 -8
  37. package/locales/de-de/de-de.messages.json +33 -8
  38. package/locales/es-es/es-es.messages.json +33 -8
  39. package/locales/fr-fr/fr-fr.messages.json +33 -8
  40. package/locales/id-id/id-id.messages.json +33 -8
  41. package/locales/it-it/it-it.messages.json +33 -8
  42. package/locales/ja-jp/ja-jp.messages.json +33 -8
  43. package/locales/ko-kr/ko-kr.messages.json +33 -8
  44. package/locales/pt-br/pt-br.messages.json +33 -8
  45. package/locales/ru-ru/ru-ru.messages.json +33 -8
  46. package/locales/tr-tr/tr-tr.messages.json +33 -8
  47. package/locales/zh-cn/zh-cn.messages.json +33 -8
  48. package/locales/zh-tw/zh-tw.messages.json +33 -8
  49. package/package.json +2 -2
  50. package/types/nanahoshi-mona-ui-calendar.d.ts +30 -11
  51. package/types/nanahoshi-mona-ui-check-box.d.ts +11 -1
  52. package/types/nanahoshi-mona-ui-date-input.d.ts +74 -3
  53. package/types/nanahoshi-mona-ui-date-picker.d.ts +61 -33
  54. package/types/nanahoshi-mona-ui-datetime-picker.d.ts +79 -38
  55. package/types/nanahoshi-mona-ui-filter.d.ts +54 -32
  56. package/types/nanahoshi-mona-ui-grid.d.ts +359 -110
  57. package/types/nanahoshi-mona-ui-i18n.d.ts +47 -6
  58. package/types/nanahoshi-mona-ui-list-view.d.ts +1 -2
  59. package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +31 -6
  60. package/types/nanahoshi-mona-ui-locales-de-de.d.ts +31 -6
  61. package/types/nanahoshi-mona-ui-locales-es-es.d.ts +31 -6
  62. package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +31 -6
  63. package/types/nanahoshi-mona-ui-locales-id-id.d.ts +31 -6
  64. package/types/nanahoshi-mona-ui-locales-it-it.d.ts +31 -6
  65. package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +31 -6
  66. package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +31 -6
  67. package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +31 -6
  68. package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +31 -6
  69. package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +31 -6
  70. package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +31 -6
  71. package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +31 -6
  72. package/types/nanahoshi-mona-ui-numeric-text-box.d.ts +57 -16
  73. package/types/nanahoshi-mona-ui-pager.d.ts +159 -76
  74. package/types/nanahoshi-mona-ui-query.d.ts +45 -14
  75. package/types/nanahoshi-mona-ui-time-picker.d.ts +72 -42
  76. package/types/nanahoshi-mona-ui-time-selector.d.ts +78 -46
  77. package/fesm2022/nanahoshi-mona-ui-grid-grid-list.component-BSlV8Sua.mjs +0 -176
  78. package/fesm2022/nanahoshi-mona-ui-grid-grid-row.component-CTOdnH29.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 compositeDescriptorToPredicate = (descriptor, fieldSelector) => {
5
- return (item) => {
6
- const filters = descriptor.filters;
7
- const logic = descriptor.logic;
8
- if (logic === "and") {
9
- return filters.every(f => processFilter(f, item, fieldSelector));
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
- else if (logic === "or") {
12
- return filters.some(f => processFilter(f, item, fieldSelector));
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
- else {
15
- return false;
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
- const descriptorToPredicate = (descriptor, fieldSelector) => {
20
- return (item) => {
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
- const value = source != null ? source[descriptor.field] : undefined;
23
- switch (descriptor.operator) {
24
- case "eq":
25
- return equateValues(value, descriptor.value);
26
- case "neq":
27
- return !equateValues(value, descriptor.value);
28
- case "gt":
29
- if (value == null || descriptor.value == null)
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
- return compareOrdered(value, descriptor.value) > 0;
32
- case "gte":
33
- if (value == null || descriptor.value == null)
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
- return compareOrdered(value, descriptor.value) >= 0;
36
- case "lt":
37
- if (value == null || descriptor.value == null)
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
- return compareOrdered(value, descriptor.value) < 0;
40
- case "lte":
41
- if (value == null || descriptor.value == null)
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
- return compareOrdered(value, descriptor.value) <= 0;
44
- case "startswith":
45
- return typeof value === "string" && typeof descriptor.value === "string"
46
- ? value.toLowerCase().startsWith(descriptor.value.toLowerCase())
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
- const isDate = (value) => value instanceof Date || value instanceof DateTime;
88
- const toDateOnly = (date) => {
89
- const dt = date instanceof DateTime ? date : DateTime.fromJSDate(date);
90
- return dt.startOf("day");
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
- const equateValues = (a, b) => {
93
- if (a == null && b == null)
94
- return true;
95
- if (a == null || b == null)
96
- return false;
97
- if (isDate(a) && isDate(b))
98
- return toDateOnly(a).valueOf() === toDateOnly(b).valueOf();
99
- return a === b;
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 compareOrdered = (a, b) => {
102
- if (isDate(a) && isDate(b))
103
- return toDateOnly(a).valueOf() - toDateOnly(b).valueOf();
104
- return a - b;
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
- const processFilter = (f, item, fieldSelector) => {
107
- if (f.hasOwnProperty("field")) {
108
- return descriptorToPredicate(f, fieldSelector)(item);
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
- else {
111
- return compositeDescriptorToPredicate(f, fieldSelector)(item);
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
- constructor(iterable) {
118
- this.iterable = iterable;
119
- this.#enumerator = new QueryEnumerator(() => iterable);
289
+ #iterable;
290
+ constructor(iterable, options) {
291
+ this.#iterable = iterable;
292
+ this.#enumerator = new QueryEnumerator(() => iterable, options);
120
293
  }
121
- *[Symbol.iterator]() {
122
- yield* this.iterable;
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
- static from(iterable) {
125
- return new Query(iterable);
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
- constructor(iterable) {
316
+ #options;
317
+ constructor(iterable, options = {}) {
139
318
  super(iterable);
319
+ this.#options = options;
140
320
  }
141
321
  filter(filter, fieldSelector) {
142
- return new QueryEnumerator(() => this.filterGenerator(filter, fieldSelector));
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
- return new QueryEnumerator(() => this.sortGenerator(descriptor, fieldSelector));
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
- yield* result;
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