@mono-lit/helper 0.0.9 → 0.0.10

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 (161) hide show
  1. package/dist/accordion-core-DaNyPWRr.js +277 -0
  2. package/dist/alert-core-DWtHbX_-.js +134 -0
  3. package/dist/breadcrumb-list-core-Dh68T8Cf.js +747 -0
  4. package/dist/{mono-button-CLkHg3WW.js → button-core-DerXg84Q.js} +3 -276
  5. package/dist/button-dropdown-core-DKYEOyjy.js +654 -0
  6. package/dist/button-utils-D5-66M02.js +63 -0
  7. package/dist/card-utils-l80qAmrN.js +312 -0
  8. package/dist/chart-core-DV7hD3ZY.js +801 -0
  9. package/dist/checkbox-utils-DKdrhAzF.js +337 -0
  10. package/dist/chip-utils-DpRrd7Zj.js +403 -0
  11. package/dist/{data-source-controller-C6C4ej_M.js → data-source-controller-DS_JLrmS.js} +1 -1
  12. package/dist/{data-source-options-fxT5QIX4.js → data-source-options-DJUNU26C.js} +6 -6
  13. package/dist/{data-source-read-BL266IW0.js → data-source-read-uKJpRAzx.js} +2 -2
  14. package/dist/date-core-CyuSyvvG.js +734 -0
  15. package/dist/drawer-core-DbFWvNln.js +759 -0
  16. package/dist/dropdown-core-BCH1pK14.js +511 -0
  17. package/dist/dropdown-table-core-SfHUJVFq.js +1342 -0
  18. package/dist/export.js +1 -1
  19. package/dist/{field-path-BabiMrrA.js → field-path-DK2VBWHl.js} +1 -1
  20. package/dist/field-tooltip.css_raw-DVblekCl.js +5 -0
  21. package/dist/{field-validation.css_raw-Cx6SGrfP.js → field-validation.css_raw-BU7C6173.js} +1 -170
  22. package/dist/file-upload-core-Cz_dBQMx.js +624 -0
  23. package/dist/filter-builder-core-DyWjbBP7.js +381 -0
  24. package/dist/{filter-builder-B6Y2mmbM.js → filter-builder-vbqIuPhX.js} +1 -1
  25. package/dist/{filter-eval-ChDSaAUH.js → filter-eval-CqeBnMYh.js} +1 -1
  26. package/dist/{filter-odata-Bi27XUpQ.js → filter-odata-GsczYKNC.js} +1 -1
  27. package/dist/{hydration-flush-BaE9gN3C.js → hydration-flush-Volt9X7Q.js} +2 -1071
  28. package/dist/index.js +11 -11
  29. package/dist/{index.node-DTqDBca7.js → index.node-Csy9zrr1.js} +4 -4
  30. package/dist/index.node.js +11 -11
  31. package/dist/input-utils-BglY-k0H.js +1145 -0
  32. package/dist/menu-core-DkAYuCZ2.js +831 -0
  33. package/dist/modal-core-CSBSPN_m.js +844 -0
  34. package/dist/mono-button-DVvZ03P-.js +280 -0
  35. package/dist/{mono-button.shadow-DqZMpcqY.js → mono-button.shadow-BANxMGln.js} +6 -594
  36. package/dist/{mono-data-chart-NKPdAgVq.js → mono-data-chart-ChF4J9RT.js} +6 -6
  37. package/dist/{mono-data-dropdown-B2iRpJuI.js → mono-data-dropdown-Bgj2PDfm.js} +1 -1
  38. package/dist/{mono-data-grid-llJCX9MC.js → mono-data-grid-DJkp96N-.js} +144 -46
  39. package/dist/{mono-event-BPku9HpS.js → mono-event-CAZf0F_k.js} +14 -9
  40. package/dist/{mono-form-controller-BrA10erm.js → mono-form-controller-DxZLvyg6.js} +2 -1
  41. package/dist/mono-table-checkbox-core-BKOMx8R5.js +5288 -0
  42. package/dist/nav-core-B5qU2dzn.js +225 -0
  43. package/dist/{normalize-error-D93O4q8g.js → normalize-error-BEcd1tmS.js} +2 -2
  44. package/dist/otp-core-DXg3vFLh.js +758 -0
  45. package/dist/radio-utils-Dk9Tl1jz.js +319 -0
  46. package/dist/rich-text-editor-core-Ddd_QaLn.js +1280 -0
  47. package/dist/select-utils-BgArYHk8.js +2140 -0
  48. package/dist/sidebar-core-CD6txDo3.js +583 -0
  49. package/dist/slider-core-vcWr321-.js +1014 -0
  50. package/dist/src/components/dropdown-table/dropdown-table-core.d.ts +2 -2
  51. package/dist/src/components/dropdown-table/dropdown-table-types.d.ts +1 -1
  52. package/dist/src/components/dropdown-table/index.d.ts +1 -1
  53. package/dist/src/components/dropdown-table/index.shadow.d.ts +1 -1
  54. package/dist/src/components/dropdown-table/mono-data-dropdown.d.ts +1 -1
  55. package/dist/src/components/form/form-types.d.ts +9 -3
  56. package/dist/src/components/input/input-core.d.ts +1 -1
  57. package/dist/src/components/input/input-types.d.ts +1 -1
  58. package/dist/src/components/otp/otp-core.d.ts +1 -1
  59. package/dist/src/components/select/select-core.d.ts +1 -1
  60. package/dist/src/components/select/select-types.d.ts +1 -1
  61. package/dist/src/components/slider/slider-core.d.ts +1 -1
  62. package/dist/src/components/slider/slider-types.d.ts +1 -1
  63. package/dist/src/components/table/filter-suggestion.d.ts +171 -0
  64. package/dist/src/components/table/index.d.ts +5 -4
  65. package/dist/src/components/table/index.shadow.d.ts +5 -4
  66. package/dist/src/components/table/mono-data-grid.d.ts +22 -3
  67. package/dist/src/components/table/mono-table-empty-core.d.ts +37 -0
  68. package/dist/src/components/table/mono-table-search-core.d.ts +22 -3
  69. package/dist/src/components/table/table-types.d.ts +74 -4
  70. package/dist/src/components/tag-input/tag-input-core.d.ts +1 -1
  71. package/dist/src/components/tag-input/tag-input-types.d.ts +1 -1
  72. package/dist/src/components/textarea/textarea-core.d.ts +1 -1
  73. package/dist/src/composables/mono-event.d.ts +7 -1
  74. package/dist/src/entries/index.d.ts +8 -6
  75. package/dist/src/entries/index.node.d.ts +8 -6
  76. package/dist/src/search/index.d.ts +1 -1
  77. package/dist/src/utils/group-count.d.ts +36 -0
  78. package/dist/switch-utils-CTZ4id2V.js +338 -0
  79. package/dist/tabs-core-r5-B8k_N.js +317 -0
  80. package/dist/tag-input-utils-D2JA90DQ.js +3060 -0
  81. package/dist/textarea-utils-VU1KeXm8.js +821 -0
  82. package/dist/ui/accordion.js +2 -274
  83. package/dist/ui/alert.js +2 -131
  84. package/dist/ui/breadcrumb.js +4 -745
  85. package/dist/ui/button-dropdown.js +4 -652
  86. package/dist/ui/button.js +2 -63
  87. package/dist/ui/card.js +2 -310
  88. package/dist/ui/chart.js +4 -800
  89. package/dist/ui/checkbox.js +4 -335
  90. package/dist/ui/chip.js +4 -402
  91. package/dist/ui/date.js +3 -732
  92. package/dist/ui/drawer.js +3 -757
  93. package/dist/ui/dropdown-table.js +5 -1341
  94. package/dist/ui/dropdown.js +4 -509
  95. package/dist/ui/file-upload.js +3 -622
  96. package/dist/ui/filter.js +5 -380
  97. package/dist/ui/form.js +1 -1
  98. package/dist/ui/index.css +118 -1
  99. package/dist/ui/input.js +3 -1141
  100. package/dist/ui/menu.js +4 -828
  101. package/dist/ui/modal.js +4 -843
  102. package/dist/ui/nav.js +4 -223
  103. package/dist/ui/otp.js +4 -756
  104. package/dist/ui/radio.js +4 -317
  105. package/dist/ui/rich-text-editor.js +4 -1278
  106. package/dist/ui/select.js +5 -2138
  107. package/dist/ui/shadow/accordion.js +4 -273
  108. package/dist/ui/shadow/alert.js +4 -130
  109. package/dist/ui/shadow/breadcrumb.js +5 -744
  110. package/dist/ui/shadow/button-dropdown.js +6 -652
  111. package/dist/ui/shadow/button.js +3 -63
  112. package/dist/ui/shadow/card.js +4 -309
  113. package/dist/ui/shadow/chart.js +6 -1576
  114. package/dist/ui/shadow/checkbox.js +4 -334
  115. package/dist/ui/shadow/chip.js +4 -396
  116. package/dist/ui/shadow/date.js +7 -731
  117. package/dist/ui/shadow/drawer.js +4 -756
  118. package/dist/ui/shadow/dropdown-table.js +8 -1762
  119. package/dist/ui/shadow/dropdown.js +4 -508
  120. package/dist/ui/shadow/file-upload.js +4 -620
  121. package/dist/ui/shadow/filter.js +7 -379
  122. package/dist/ui/shadow/input.js +6 -1140
  123. package/dist/ui/shadow/menu.js +5 -828
  124. package/dist/ui/shadow/modal.js +6 -1063
  125. package/dist/ui/shadow/nav.js +5 -223
  126. package/dist/ui/shadow/otp.js +6 -754
  127. package/dist/ui/shadow/radio.js +4 -316
  128. package/dist/ui/shadow/rich-text-editor.js +4 -1276
  129. package/dist/ui/shadow/select.js +6 -2136
  130. package/dist/ui/shadow/sidebar.js +5 -581
  131. package/dist/ui/shadow/slider.js +5 -1010
  132. package/dist/ui/shadow/switch.js +4 -335
  133. package/dist/ui/shadow/table.js +10 -4501
  134. package/dist/ui/shadow/tabs.js +6 -315
  135. package/dist/ui/shadow/tag-input.js +7 -3057
  136. package/dist/ui/shadow/textarea.js +6 -817
  137. package/dist/ui/sidebar.js +3 -581
  138. package/dist/ui/slider.js +4 -1012
  139. package/dist/ui/switch.js +4 -336
  140. package/dist/ui/table.js +9 -4502
  141. package/dist/ui/tabs.js +4 -315
  142. package/dist/ui/tag-input.js +5 -3058
  143. package/dist/ui/textarea.js +4 -819
  144. package/dist/vue.d.ts +3 -2
  145. package/package.json +3 -3
  146. package/dist/chip-strip-bNfLn52Z.js +0 -215
  147. package/dist/data-source-controller-Dx6IQ2CN.js +0 -243
  148. package/dist/data-source-options-BM4r4PRw.js +0 -558
  149. package/dist/data-source-read-HyBCRg1t.js +0 -242
  150. package/dist/excel-BXzr3uI1.js +0 -784
  151. package/dist/export-ixRdCS2y.js +0 -2388
  152. package/dist/field-tooltip-addon-CWCp19mJ.js +0 -702
  153. package/dist/field-tooltip.css_raw-U5UeTa2d.js +0 -269
  154. package/dist/filter-builder-C0T3pMx2.js +0 -208
  155. package/dist/form-control-core-BbiACMtL.js +0 -226
  156. package/dist/icon-ClxnYhBG.js +0 -19
  157. package/dist/import-Dc4eXC02.js +0 -612
  158. package/dist/light-slots-_no0r2Z-.js +0 -246
  159. package/dist/markdown-uGlE_OfJ.js +0 -20191
  160. package/dist/mono-data-grid-e9ZVBlNN.js +0 -4240
  161. package/dist/normalize-error-BmLbgANw.js +0 -1048
@@ -1,1048 +0,0 @@
1
- import { a as parseFieldPath, c as toODataClause, n as isPath, t as getFieldValue } from "./field-path-BabiMrrA.js";
2
-
3
- //#region src/search/filter-eval.ts
4
- /**
5
- * Compile a devextreme filter expression (the array form `monoFilterBuilder`
6
- * emits via `changed({ type: 'array' })`) into a client-side row predicate, so a
7
- * built filter can narrow an array-backed grid the same way a remote store would
8
- * narrow from a `$filter`. Remote devextreme stores read the array directly; this
9
- * is the client-side mirror for sources that only accept a `(row) => boolean`.
10
- *
11
- * The grammar handled is exactly the subset `treeToArray` produces: `[field, op,
12
- * value]` triples, `'and'` / `'or'` joined groups, `['!', expr]` negation, with
13
- * `between` / `in` / blank checks already expanded to those primitives.
14
- */
15
- function compileFilterPredicate(expr) {
16
- if (!Array.isArray(expr) || expr.length === 0) return null;
17
- const fn = build(expr);
18
- return (row) => !!fn(row);
19
- }
20
- /** AND-combine two optional devextreme filter expressions (either may be null). */
21
- function andFilters(a, b) {
22
- if (a == null && b == null) return null;
23
- if (a == null) return b;
24
- if (b == null) return a;
25
- return [
26
- a,
27
- "and",
28
- b
29
- ];
30
- }
31
- /**
32
- * AND-combine optional row predicates — the array-source twin of `andFilters`.
33
- *
34
- * Returns the lone member UNWRAPPED when only one is present, so a caller that
35
- * compares the result by reference (the grid's compose memo) sees the same
36
- * function back and does not treat "nothing changed" as a change.
37
- */
38
- function andPredicates(...fns) {
39
- const kept = fns.filter((f) => typeof f === "function");
40
- if (!kept.length) return null;
41
- if (kept.length === 1) return kept[0];
42
- return (row, index) => kept.every((f) => f(row, index));
43
- }
44
- /**
45
- * Join expressions with `and` / `or`, dropping nulls and returning a lone member
46
- * unwrapped — devextreme's filter arrays interleave the join token between
47
- * members (`[a, 'or', b, 'or', c]`) rather than nesting pairs.
48
- */
49
- function joinFilters(parts, join) {
50
- const kept = parts.filter((p) => p != null);
51
- if (!kept.length) return null;
52
- if (kept.length === 1) return kept[0];
53
- const out = [];
54
- kept.forEach((p, i) => {
55
- if (i) out.push(join);
56
- out.push(p);
57
- });
58
- return out;
59
- }
60
- const CMP = /* @__PURE__ */ new Set([
61
- "=",
62
- "<>",
63
- ">",
64
- ">=",
65
- "<",
66
- "<=",
67
- "==",
68
- "!=",
69
- "eq",
70
- "ne",
71
- "gt",
72
- "ge",
73
- "lt",
74
- "le"
75
- ]);
76
- const STR = /* @__PURE__ */ new Set([
77
- "contains",
78
- "notcontains",
79
- "startswith",
80
- "endswith"
81
- ]);
82
- /** A triple is `[field, op, value]`; a group starts with an array member. */
83
- function isTriple(node) {
84
- return Array.isArray(node) && node.length === 3 && typeof node[0] === "string" && typeof node[1] === "string" && (CMP.has(node[1]) || STR.has(String(node[1]).toLowerCase()));
85
- }
86
- function build(expr) {
87
- if (!Array.isArray(expr) || expr.length === 0) return () => true;
88
- if (expr.length === 2 && (expr[0] === "!" || expr[0] === "not")) {
89
- const inner = build(expr[1]);
90
- return (row) => !inner(row);
91
- }
92
- if (isTriple(expr)) {
93
- const [field, op, value] = expr;
94
- return (row) => match(getFieldValue(row, field), op, value);
95
- }
96
- const members = [];
97
- const joins = [];
98
- for (const part of expr) {
99
- const t = typeof part === "string" ? part.toLowerCase() : "";
100
- if (t === "and" || t === "&" || t === "or" || t === "|") {
101
- joins.push(t === "or" || t === "|" ? "or" : "and");
102
- continue;
103
- }
104
- members.push(part);
105
- }
106
- const fns = members.map((m) => build(m));
107
- if (!fns.length) return () => true;
108
- return (row) => {
109
- let acc = fns[0](row);
110
- for (let i = 0; i < joins.length; i += 1) {
111
- const next = fns[i + 1](row);
112
- acc = joins[i] === "or" ? acc || next : acc && next;
113
- }
114
- return acc;
115
- };
116
- }
117
- /** Coerce two values for ordered comparison: numbers when both parse, else strings. */
118
- function pair(a, b) {
119
- const na = Number(a);
120
- const nb = Number(b);
121
- if (a !== "" && b !== "" && !Number.isNaN(na) && !Number.isNaN(nb)) return [na, nb];
122
- return [String(a ?? ""), String(b ?? "")];
123
- }
124
- /** OData keyword → the symbol token the switch below is written against. */
125
- const OP_ALIAS = {
126
- eq: "=",
127
- ne: "<>",
128
- gt: ">",
129
- ge: ">=",
130
- lt: "<",
131
- le: "<="
132
- };
133
- function match(raw, op, value) {
134
- const lower = op.toLowerCase();
135
- const token = OP_ALIAS[lower] ?? lower;
136
- if (value === null || value === void 0) {
137
- const blank = raw === null || raw === void 0 || raw === "";
138
- return token === "=" || token === "==" ? blank : !blank;
139
- }
140
- const raws = String(raw ?? "");
141
- const vals = String(value ?? "");
142
- switch (token) {
143
- case "=":
144
- case "==": {
145
- const [a, b] = pair(raw, value);
146
- return a === b;
147
- }
148
- case "<>":
149
- case "!=": {
150
- const [a, b] = pair(raw, value);
151
- return a !== b;
152
- }
153
- case ">":
154
- case ">=":
155
- case "<":
156
- case "<=": {
157
- const [a, b] = pair(raw, value);
158
- if (typeof a === "string" && typeof b === "string") {}
159
- switch (token) {
160
- case ">": return a > b;
161
- case ">=": return a >= b;
162
- case "<": return a < b;
163
- default: return a <= b;
164
- }
165
- }
166
- case "contains": return raws.toLowerCase().includes(vals.toLowerCase());
167
- case "notcontains": return !raws.toLowerCase().includes(vals.toLowerCase());
168
- case "startswith": return raws.toLowerCase().startsWith(vals.toLowerCase());
169
- case "endswith": return raws.toLowerCase().endsWith(vals.toLowerCase());
170
- default: return false;
171
- }
172
- }
173
-
174
- //#endregion
175
- //#region src/search/search-expr.ts
176
- /**
177
- * Search-expression entries: the fields a typed term is matched against.
178
- *
179
- * One grammar, shared by every component that searches data — `monoDataGrid`'s
180
- * `searchExpr`, and the `search-value` prop on `mono-select`, `mono-tag-input`
181
- * and `mono-dropdown-table`. An entry may be:
182
- *
183
- * - a plain column name (`'Nama'`)
184
- * - a **path** (`'Company.Name'`, `'Transaction.[1].Name'`, `'Transaction.[*].Price'`)
185
- * - a **`*` pattern** (`'*'`, `'Company.*'`, `'*.*'`, `'*.[*].*'`)
186
- * - a **`{ field, custom }` clause builder**
187
- *
188
- * An entry is normally just a column name, and every column is searched the same
189
- * way — `contains(<col>,'<term>')`. That is wrong for any column whose data isn't
190
- * free text: a **boolean** can't take `contains` at all, and a **coded** column
191
- * stores something the user never types (a `Month` of `0..11` can never match the
192
- * string `"Jan"`).
193
- *
194
- * So an entry may instead be `{ field, custom }`, where `custom` receives the live
195
- * term and returns the clause to use for that column:
196
- *
197
- * ```ts
198
- * const MONTHS = ['Jan', 'Feb', 'Mar', …]
199
- *
200
- * searchExpr: [
201
- * 'Code',
202
- * 'Nama',
203
- * { field: 'Active', custom: ({ field, value }) => `${field} eq ${value}` },
204
- * { field: 'Month', custom: ({ field, value }) => [field, '=', MONTHS.indexOf(value)] },
205
- * ]
206
- * ```
207
- *
208
- * A custom column takes part in the plain search box like any other, so it runs on
209
- * every term. **Return `null`/`undefined` to opt out** of one — which is what makes
210
- * the `Month` example workable: `"Jan"` → `0`, `"zzz"` → `-1` → return `null` and
211
- * the column simply drops out of that query instead of matching nothing.
212
- *
213
- * | `custom` returns | remote (devextreme store) | array / in-memory |
214
- * | --- | --- | --- |
215
- * | `[field, op, value]`, or a nested `and`/`or` array | used as-is | compiled to a predicate |
216
- * | `(row) => boolean` | warn + skip | used as the predicate |
217
- * | `"Active eq true"` (raw OData) | wrapped as `[raw]` | warn + skip |
218
- * | `null` / `undefined` / `false` | skipped | skipped |
219
- *
220
- * Only the explicit `{ field, custom }` shape is accepted — a `{ Month: fn }` map
221
- * is not, so there is exactly one form to read and to type.
222
- *
223
- * An entry may also be a **`*` pattern**, resolved against the loaded rows so a
224
- * grid can search everything without listing columns:
225
- *
226
- * ```ts
227
- * searchExpr: ['*'] // every top-level field
228
- * searchExpr: ['*', '*.[*].*'] // …plus every field of every array expand
229
- * searchExpr: ['*', '*.*'] // …plus every field of every object expand
230
- * searchExpr: ['*', { field: 'Month', custom }] // the explicit entry wins for Month
231
- * ```
232
- *
233
- * Patterns read literally, segment by segment — `'*.[*].*'` covers the expand ONLY.
234
- * See {@link expandWildcard} for the type rule that keeps a remote `$filter` valid.
235
- *
236
- * This module is pure: types + stateless helpers, no controller state, mirroring
237
- * `field-path.ts`.
238
- */
239
- /** Entries already warned about, so a per-keystroke path can't flood the console. */
240
- const warned = /* @__PURE__ */ new WeakSet();
241
- function warnOnce(key, message) {
242
- if (warned.has(key)) return;
243
- warned.add(key);
244
- console.warn(`[@mono-lit/helper] ${message}`);
245
- }
246
- /** Malformed entries are warned about once each, keyed by the object itself. */
247
- function isCustomEntry(entry) {
248
- if (typeof entry !== "object" || entry === null) return false;
249
- const e = entry;
250
- if (typeof e.field === "string" && e.field && typeof e.custom === "function") return true;
251
- warnOnce(entry, `searchExpr: ignoring an entry that is neither a column name nor { field, custom } — ${JSON.stringify(Object.keys(entry))}. The { Field: fn } shorthand is not supported.`);
252
- return false;
253
- }
254
- /** Every usable entry, in the order written. Strings and customs, malformed dropped. */
255
- function normalizeSearchExpr(expr) {
256
- if (expr == null) return [];
257
- const list = Array.isArray(expr) ? expr : [expr];
258
- const out = [];
259
- for (const entry of list) if (typeof entry === "string") {
260
- if (entry) out.push(entry);
261
- } else if (isCustomEntry(entry)) out.push(entry);
262
- return out;
263
- }
264
- /**
265
- * The plain column names only — no `{ field, custom }` entries, no `*` patterns.
266
- *
267
- * This is what a SOURCE may be handed: `monoArraySource`, `storeGroupSource` and
268
- * devextreme all type `searchExpr` as `string | string[]` and feed it straight to
269
- * `toODataClause` — an object entry would serialize to garbage and a `'*'` would
270
- * be searched as a column literally named `*`. Both are resolved by the controller
271
- * instead.
272
- */
273
- function plainSearchColumns(expr) {
274
- return normalizeSearchExpr(expr).filter((e) => typeof e === "string" && !isWildcardPattern(e));
275
- }
276
- /** The field name an entry covers. */
277
- function searchEntryField(entry) {
278
- return typeof entry === "string" ? entry : entry.field;
279
- }
280
- /** The entry declaring `field`, if any — used to resolve a column-bound term. */
281
- function searchEntryFor(expr, field) {
282
- return normalizeSearchExpr(expr).find((e) => searchEntryField(e) === field);
283
- }
284
- /** Whether any entry brings its own builder (so folding must be bypassed). */
285
- function hasCustomSearch(expr) {
286
- return normalizeSearchExpr(expr).some((e) => typeof e !== "string");
287
- }
288
- /** Whether `field` is a `*` pattern rather than a concrete column/path. */
289
- function isWildcardPattern(field) {
290
- if (typeof field !== "string" || !field.includes("*")) return false;
291
- return parseFieldPath(field).segments.some((s) => s.kind === "key" && s.name === "*");
292
- }
293
- /** A value that can be searched as-is (anything that isn't a container). */
294
- function isLeaf(value) {
295
- return value !== null && typeof value !== "object";
296
- }
297
- const isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
298
- /** How many rows to sample when resolving a pattern (row 0 alone may be sparse). */
299
- const SAMPLE_ROWS = 20;
300
- /**
301
- * Resolve a `*` pattern against real rows, returning the concrete field paths it
302
- * covers — `'*.[*].*'` over `{ Detail: [{ Bulan, Ket }] }` gives
303
- * `['Detail.[*].Bulan', 'Detail.[*].Ket']`, which the existing path machinery
304
- * already knows how to match client-side and translate to an OData lambda.
305
- *
306
- * `textOnly` drops every leaf that isn't a string. A REMOTE source needs that:
307
- * `contains(Price,'x')` is not valid OData and would reject the whole request, so
308
- * a wildcard never emits a clause for a numeric/boolean/date column. Give such a
309
- * column an explicit `{ field, custom }` entry instead. In-memory sources compare
310
- * stringified values, so they keep every leaf.
311
- *
312
- * A field that is `null`/`undefined` in every sampled row is skipped — there is
313
- * nothing to type it by.
314
- */
315
- function expandWildcard(pattern, rows, textOnly) {
316
- const { segments } = parseFieldPath(pattern);
317
- const found = /* @__PURE__ */ new Set();
318
- for (const row of rows.slice(0, SAMPLE_ROWS)) {
319
- let candidates = [{
320
- path: [],
321
- value: row
322
- }];
323
- for (const seg of segments) {
324
- const next = [];
325
- for (const { path, value } of candidates) {
326
- if (value == null) continue;
327
- if (seg.kind === "wildcard") {
328
- if (Array.isArray(value)) for (const el of value) next.push({
329
- path: [...path, "[*]"],
330
- value: el
331
- });
332
- } else if (seg.kind === "index") {
333
- if (Array.isArray(value)) next.push({
334
- path: [...path, `[${seg.index}]`],
335
- value: value[seg.index]
336
- });
337
- } else if (seg.name === "*") {
338
- if (isPlainObject(value)) for (const key of Object.keys(value)) next.push({
339
- path: [...path, key],
340
- value: value[key]
341
- });
342
- } else if (isPlainObject(value)) next.push({
343
- path: [...path, seg.name],
344
- value: value[seg.name]
345
- });
346
- }
347
- candidates = next;
348
- if (!candidates.length) break;
349
- }
350
- for (const { path, value } of candidates) {
351
- if (!path.length || !isLeaf(value)) continue;
352
- if (textOnly && typeof value !== "string") continue;
353
- found.add(path.join("."));
354
- }
355
- }
356
- return [...found];
357
- }
358
- /**
359
- * The entries a search actually runs over: every `*` pattern replaced by the
360
- * concrete fields it resolves to, in place.
361
- *
362
- * **An explicitly named field always wins.** A field named anywhere in the list —
363
- * as a plain string or as `{ field, custom }` — is dropped from every pattern
364
- * expansion regardless of order, so `['*', { field: 'Name', custom }]` and
365
- * `[{ field: 'Name', custom }, '*']` both search `Name` with the custom, exactly
366
- * once, at the position it was written.
367
- */
368
- function resolveSearchEntries(expr, options = {}) {
369
- const entries = normalizeSearchExpr(expr);
370
- if (!entries.some((e) => typeof e === "string" && isWildcardPattern(e))) return entries;
371
- const { rows = [], textOnly = false } = options;
372
- const explicit = new Set(entries.filter((e) => typeof e !== "string" || !isWildcardPattern(e)).map((e) => searchEntryField(e)));
373
- const out = [];
374
- const seen = /* @__PURE__ */ new Set();
375
- for (const entry of entries) {
376
- if (typeof entry === "string" && isWildcardPattern(entry)) {
377
- for (const field of expandWildcard(entry, rows, textOnly)) {
378
- if (explicit.has(field) || seen.has(field)) continue;
379
- seen.add(field);
380
- out.push(field);
381
- }
382
- continue;
383
- }
384
- const field = searchEntryField(entry);
385
- if (seen.has(field)) continue;
386
- seen.add(field);
387
- out.push(entry);
388
- }
389
- return out;
390
- }
391
- /** Whether any entry is a `*` pattern (so folding must be bypassed). */
392
- function hasWildcardSearch(expr) {
393
- return normalizeSearchExpr(expr).some((e) => typeof e === "string" && isWildcardPattern(e));
394
- }
395
- /** Run the builder, guarding against a throw in consumer code. */
396
- function runCustom(entry, value, operation) {
397
- try {
398
- return entry.custom({
399
- field: entry.field,
400
- value,
401
- operation
402
- });
403
- } catch (error) {
404
- warnOnce(entry, `searchExpr custom for "${entry.field}" threw — column skipped. ${error}`);
405
- return null;
406
- }
407
- }
408
- /**
409
- * The devextreme filter clause for one custom entry + term, or `null` to skip it.
410
- *
411
- * A raw string is wrapped as `[raw]` — the single-member raw-passthrough clause
412
- * devextreme honours inside a filter array, the same shape `toODataClause` emits
413
- * for a wildcard lambda, so it slots into the OR/AND groups unchanged.
414
- */
415
- function customRemoteClause(entry, value, operation) {
416
- const result = runCustom(entry, value, operation);
417
- if (result == null || result === false) return null;
418
- if (typeof result === "string") return result ? [result] : null;
419
- if (Array.isArray(result)) return result.length ? result : null;
420
- if (typeof result === "function") warnOnce(entry, `searchExpr custom for "${entry.field}" returned a predicate function, which a remote source can't send — column skipped. Return a filter array or an OData string for remote sources.`);
421
- return null;
422
- }
423
- /**
424
- * The client-side row predicate for one custom entry + term, or `null` to skip it.
425
- *
426
- * Filter arrays go through `compileFilterPredicate`, which already understands
427
- * nested `and`/`or` groups, `['!', …]` negation and path fields — so the SAME
428
- * `[field, op, value]` a remote source receives also narrows an array source.
429
- */
430
- function customPredicate(entry, value, operation) {
431
- const result = runCustom(entry, value, operation);
432
- if (result == null || result === false) return null;
433
- if (typeof result === "function") return result;
434
- if (Array.isArray(result)) return result.length ? compileFilterPredicate(result) : null;
435
- if (typeof result === "string") warnOnce(entry, `searchExpr custom for "${entry.field}" returned the raw OData string ${JSON.stringify(result)}, which only a remote source can use — column skipped for this in-memory source. Return a filter array to support both.`);
436
- return null;
437
- }
438
-
439
- //#endregion
440
- //#region src/search/data-search.ts
441
- /**
442
- * The shared search engine — one implementation of "match a typed term against
443
- * a set of fields", used by every component that searches data.
444
- *
445
- * `monoDataGrid` grew this pipeline first (paths, `*` patterns, `{ field, custom }`
446
- * clause builders); this module lifts the reusable half out of the grid so
447
- * `mono-select`, `mono-tag-input` and `mono-dropdown-table` share it verbatim
448
- * rather than each re-deriving a weaker version.
449
- *
450
- * ## The `search-value` grammar
451
- *
452
- * A component's `search-value` prop accepts either form, interchangeably:
453
- *
454
- * ```ts
455
- * // array — the full grammar, including custom clause builders
456
- * :search-value.prop="['Company.Name', 'Transaction.[*].Price', '*.[*].*']"
457
- *
458
- * // comma-separated string — the same thing from plain HTML
459
- * search-value="Company.Name,Transaction.[*].Price,*.[*].*"
460
- * ```
461
- *
462
- * Whitespace around a comma is trimmed, so `'a, b, c'` and `'a,b,c'` are equal.
463
- * A comma is never part of a path or a pattern, so splitting on it is lossless —
464
- * only `{ field, custom }` entries need the array form.
465
- *
466
- * ## The two output shapes
467
- *
468
- * A search has to be expressed twice, because the two source kinds evaluate it in
469
- * different places:
470
- *
471
- * - **remote** (a devextreme store): a `$filter` expression → {@link searchRemoteFilter}
472
- * - **array / in-memory**: a `(row) => boolean` → {@link searchRowPredicate}
473
- *
474
- * Both are built from the SAME resolved entry list, so the two paths can't drift.
475
- *
476
- * ## Why a source can't always do it itself
477
- *
478
- * devextreme folds `searchValue` + `searchExpr` into the request on its own, which
479
- * is cheaper and is kept for the common case. But folding emits exactly
480
- * `contains(<col>,'<term>')` per column, so it cannot express a nav path
481
- * (`Job/Name`), a collection lambda (`Nav/any(...)`) or a custom clause.
482
- * {@link isFoldableSearch} decides; {@link MonoSourceSearch} routes.
483
- */
484
- /** The default devextreme search operation. */
485
- const DEFAULT_SEARCH_OPERATION = "contains";
486
- /**
487
- * Split the string form of `search-value` on commas.
488
- *
489
- * Kept separate from {@link resolveSearchFields} so a component can show a user
490
- * what its raw prop parsed to without also resolving `*` patterns against data.
491
- */
492
- function parseSearchValue(value) {
493
- if (value == null) return [];
494
- if (Array.isArray(value)) return normalizeSearchExpr(value);
495
- if (typeof value !== "string") return [];
496
- return normalizeSearchExpr(value.split(",").map((s) => s.trim()).filter(Boolean));
497
- }
498
- /** The spellings, in the order a merge reads them. */
499
- const SEARCH_FIELDS_KEYS = [
500
- "searchExpr",
501
- "search-expr",
502
- "searchValue",
503
- "search-value"
504
- ];
505
- /**
506
- * Merge every spelling present into one entry list, de-duplicated by field name.
507
- *
508
- * They all mean the same thing, so passing two of them means the union rather
509
- * than one silently shadowing the other. Order only decides *position* among
510
- * equal field names — first occurrence wins, so a `{ field, custom }` entry
511
- * written under one spelling isn't displaced by a plain column under another.
512
- *
513
- * Returns **`undefined` when none of the keys is present**, which callers rely on
514
- * to mean "not configured at all" — distinctly different from `[]` ("configured,
515
- * but empty"). The grid uses that difference to decide whether to leave a data
516
- * source's own `searchExpr` alone.
517
- */
518
- function mergeSearchFields(src) {
519
- if (!src) return void 0;
520
- let present = false;
521
- const out = [];
522
- const seen = /* @__PURE__ */ new Set();
523
- for (const key of SEARCH_FIELDS_KEYS) {
524
- const raw = src[key];
525
- if (raw === void 0) continue;
526
- present = true;
527
- for (const entry of parseSearchValue(raw)) {
528
- const field = searchEntryField(entry);
529
- if (seen.has(field)) continue;
530
- seen.add(field);
531
- out.push(entry);
532
- }
533
- }
534
- return present ? out : void 0;
535
- }
536
- /** The default when nothing is configured: every top-level field. */
537
- const DEFAULT_SEARCH_FIELDS = ["*"];
538
- /**
539
- * The entries a search actually runs over: the prop parsed, the fallbacks applied
540
- * when it's empty, and every `*` pattern expanded against `rows`.
541
- *
542
- * Call this **once per query**, never per row — a pattern samples up to 20 rows,
543
- * so resolving inside a row loop is O(rows × fields) on every keystroke.
544
- */
545
- function resolveSearchFields(options = {}) {
546
- const { searchValue, fallbackFields = [], rows = [], remote = false, defaultToWildcard = false } = options;
547
- let entries = parseSearchValue(searchValue);
548
- if (!entries.length) {
549
- const fallbacks = fallbackFields.filter((f) => typeof f === "string" && !!f);
550
- entries = defaultToWildcard ? [...DEFAULT_SEARCH_FIELDS, ...fallbacks] : fallbacks;
551
- }
552
- if (!entries.length) return [];
553
- return resolveSearchEntries(entries, {
554
- rows,
555
- textOnly: remote
556
- });
557
- }
558
- /**
559
- * Whether a source's own `searchValue`/`searchExpr` folding can express these
560
- * entries — true only for plain top-level column names.
561
- *
562
- * A path needs a nav selector or an `any()` lambda and a custom brings its own
563
- * clause; folding would silently search either with a flat `contains` instead.
564
- */
565
- function isFoldableSearch(entries) {
566
- return entries.every((e) => typeof e === "string" && !isPath(e) && !isWildcardPattern(e));
567
- }
568
- /** The plain column names among `entries` — what a source may safely be handed. */
569
- function plainSearchFields(entries) {
570
- return entries.filter((e) => typeof e === "string" && !isWildcardPattern(e));
571
- }
572
- /** Compare one resolved value against the needle using a devextreme operation. */
573
- function matchesValue(value, needle, operation) {
574
- const s = String(value ?? "").toLowerCase();
575
- const n = needle.toLowerCase();
576
- if (operation === "startswith") return s.startsWith(n);
577
- if (operation === "endswith") return s.endsWith(n);
578
- if (operation === "=" || operation === "equals") return s === n;
579
- if (operation === "notcontains") return !s.includes(n);
580
- return s.includes(n);
581
- }
582
- /**
583
- * Read a field off a row, path-aware. A wildcard path resolves to an array of
584
- * every match, so the caller matches if ANY element hits.
585
- */
586
- function readSearchField(row, field) {
587
- const raw = isPath(field) ? getFieldValue(row, field) : row?.[field];
588
- return Array.isArray(raw) ? raw : [raw];
589
- }
590
- /**
591
- * The client-side row test for one query, or `null` when there is nothing to
592
- * match on.
593
- *
594
- * `null` means "no opinion" — the caller should keep every row rather than filter
595
- * them all away, which is what a component with no configured fields wants.
596
- */
597
- function searchRowPredicate(entries, query, operation = DEFAULT_SEARCH_OPERATION) {
598
- const needle = String(query ?? "").trim();
599
- if (!needle || !entries.length) return null;
600
- return (row) => entries.some((entry) => {
601
- if (typeof entry === "string") return readSearchField(row, entry).some((v) => matchesValue(v, needle, operation));
602
- const pred = customPredicate(entry, needle, operation);
603
- return pred ? pred(row) : false;
604
- });
605
- }
606
- /**
607
- * The devextreme `$filter` expression for one query — an OR across every entry —
608
- * or `null` when there is nothing to send.
609
- */
610
- function searchRemoteFilter(entries, query, operation = DEFAULT_SEARCH_OPERATION) {
611
- const needle = String(query ?? "").trim();
612
- if (!needle || !entries.length) return null;
613
- const clauses = entries.map((entry) => typeof entry === "string" ? toODataClause(entry, operation, needle) : customRemoteClause(entry, needle, operation)).filter((c) => c != null);
614
- return joinFilters(clauses, "or");
615
- }
616
- /**
617
- * Applies a search to a bound DataSource, choosing between the source's own
618
- * folding and a controller-built `$filter`.
619
- *
620
- * The reason this needs to be an object rather than a function is the **base
621
- * filter**: when the search can't be folded it has to live in `source.filter()`,
622
- * which is also where the consumer's own filter lives. So the consumer's filter is
623
- * captured and every search re-composes from that snapshot — otherwise each
624
- * keystroke would AND another search clause onto the previous one and the filter
625
- * would grow without bound.
626
- *
627
- * The snapshot is not taken once and kept. Before every apply (and every clear)
628
- * the live `filter()` is compared against what this instance last WROTE: if it
629
- * differs, the consumer changed the filter in the meantime — a watcher scoping
630
- * the source — and that becomes the new base. Snapshotting only at `bind()` made
631
- * the next keystroke overwrite such a filter with the stale one, and "restored"
632
- * the stale one on clear.
633
- *
634
- * ```ts
635
- * private _search = new MonoSourceSearch()
636
- * // on `dataSource` change:
637
- * this._search.bind(this.dataSource)
638
- * // on a (debounced) query:
639
- * await this._search.apply(this.dataSource, {
640
- * query, searchValue: this.searchValue, fallbackFields: [...], rows, remote: true,
641
- * })
642
- * ```
643
- */
644
- var MonoSourceSearch = class {
645
- constructor() {
646
- this._source = null;
647
- this._baseFilter = null;
648
- this._wroteFilter = false;
649
- this._lastWritten = null;
650
- }
651
- /**
652
- * Snapshot a source's own filter. Safe to call repeatedly — the snapshot is
653
- * only (re)taken when the source identity actually changes, so it can be driven
654
- * straight from a `willUpdate` branch. A change on the SAME source is picked up
655
- * by `_syncBase` at the next apply/clear instead.
656
- */
657
- bind(source) {
658
- if (source === this._source) return;
659
- this._source = source ?? null;
660
- this._baseFilter = source?.filter?.() ?? null;
661
- this._lastWritten = this._baseFilter;
662
- this._wroteFilter = false;
663
- }
664
- /**
665
- * Adopt a filter the consumer set on the source since the last write —
666
- * anything the source holds that is not what this instance last put there.
667
- * `_writeFilter` records what the source HOLDS after a write (read back), so a
668
- * source that ignores writes reads back as its own last write and is never
669
- * re-adopted, and one that normalises compares against its normalised value.
670
- */
671
- _syncBase(s) {
672
- if (typeof s.filter !== "function") return;
673
- const live = s.filter() ?? null;
674
- if (live === this._lastWritten) return;
675
- this._baseFilter = live;
676
- this._wroteFilter = false;
677
- }
678
- /** Write `filter()` and remember what the source holds afterwards. */
679
- _writeFilter(s, value) {
680
- s.filter?.(value);
681
- this._lastWritten = s.filter?.() ?? null;
682
- }
683
- /**
684
- * Undo whatever this instance wrote onto the source, then forget it.
685
- *
686
- * `reset()` alone is not enough at teardown. With `defaultToWildcard`, a `'*'`
687
- * entry is never foldable, so the search is AND-ed into `source.filter()` — the
688
- * same slot the CONSUMER's own filter lives in. Only `apply()` ever restores the
689
- * captured base (and only when the next apply happens to be foldable), so an
690
- * element torn down mid-query used to leave its clause behind on a DataSource
691
- * the app still owns and shares.
692
- *
693
- * Deliberately does NOT `load()`: teardown must not issue a request. The next
694
- * consumer of the source reloads on its own terms.
695
- */
696
- clear(source) {
697
- const s = source ?? this._source;
698
- if (s) {
699
- this._syncBase(s);
700
- s.searchValue?.(null);
701
- if (this._wroteFilter) this._writeFilter(s, this._baseFilter ?? null);
702
- }
703
- this.reset();
704
- }
705
- /** Forget the captured state without touching the source. */
706
- reset() {
707
- this._source = null;
708
- this._baseFilter = null;
709
- this._lastWritten = null;
710
- this._wroteFilter = false;
711
- }
712
- /**
713
- * Push `query` onto `source` and reload it. Returns the resolved entries so a
714
- * caller can reuse them for its own client-side rendering without re-resolving.
715
- */
716
- async apply(source, options) {
717
- const s = source;
718
- if (!s) return [];
719
- this.bind(source);
720
- this._syncBase(s);
721
- const operation = options.operation || "contains";
722
- const entries = resolveSearchFields({
723
- ...options,
724
- remote: options.remote ?? true
725
- });
726
- const query = String(options.query ?? "").trim();
727
- if (isFoldableSearch(entries)) {
728
- s.searchOperation?.(operation);
729
- s.searchExpr?.(plainSearchFields(entries));
730
- s.searchValue?.(query || null);
731
- if (this._wroteFilter) {
732
- this._writeFilter(s, this._baseFilter ?? null);
733
- this._wroteFilter = false;
734
- }
735
- } else {
736
- s.searchValue?.(null);
737
- const expr = searchRemoteFilter(entries, query, operation);
738
- this._writeFilter(s, andFilters(this._baseFilter ?? null, expr));
739
- this._wroteFilter = expr != null;
740
- }
741
- s.pageIndex?.(0);
742
- await Promise.resolve(s.load?.());
743
- return entries;
744
- }
745
- };
746
-
747
- //#endregion
748
- //#region src/utils/normalize-error.ts
749
- /** Fields worth reading off an object that is not an `Error`. */
750
- const MESSAGE_KEYS = [
751
- "message",
752
- "statusText",
753
- "errorMessage",
754
- "error",
755
- "detail"
756
- ];
757
- const text = (value) => typeof value === "string" && value.trim() ? value.trim() : "";
758
- const isObject = (value) => value !== null && typeof value === "object";
759
- /**
760
- * A readable message for `raw`, or `fallback` when nothing legible can be found.
761
- *
762
- * Never throws, and never returns an empty string — a caller rendering this into
763
- * an error bar has to have something to render, and a blank bar is worse than a
764
- * generic one.
765
- */
766
- function normalizeError(raw, fallback = "Request failed") {
767
- if (raw == null) return fallback;
768
- if (raw instanceof Error) {
769
- const own = text(raw.message);
770
- if (own) return own;
771
- } else {
772
- if (typeof raw === "string") return text(raw) || fallback;
773
- if (typeof raw === "number" || typeof raw === "boolean") return String(raw);
774
- }
775
- if (isObject(raw)) {
776
- const obj = raw;
777
- for (const key of MESSAGE_KEYS) {
778
- const hit = text(obj[key]);
779
- if (hit) return hit;
780
- }
781
- const response = obj.response;
782
- if (isObject(response)) {
783
- const nested = text(response.statusText) || text(response.message);
784
- if (nested) return nested;
785
- }
786
- const status = errorStatus(obj);
787
- if (status !== void 0 && status > 0) return `HTTP ${status}`;
788
- if (raw instanceof Error) return text(raw.name) || fallback;
789
- return fallback;
790
- }
791
- return text(String(raw)) || fallback;
792
- }
793
- /**
794
- * What the bar says for a status. English; an app puts its own language in
795
- * ONCE with `setErrorMessages()` rather than on every table.
796
- */
797
- const DEFAULT_ERROR_MESSAGES = Object.freeze({
798
- network: "Could not reach the server. Check your connection and try again.",
799
- 400: "The server rejected the request.",
800
- 401: "Your session has expired. Please sign in again.",
801
- 403: "You do not have permission to view this data.",
802
- 404: "The requested data could not be found.",
803
- 408: "The server took too long to respond. Please try again.",
804
- 409: "The request conflicts with the current state of the data.",
805
- 422: "The server could not process the request.",
806
- 429: "Too many requests. Please wait a moment and try again.",
807
- 500: "Something went wrong on the server. Please try again later.",
808
- 502: "The server is temporarily unavailable. Please try again later.",
809
- 503: "The server is temporarily unavailable. Please try again later.",
810
- 504: "The server took too long to respond. Please try again later.",
811
- default: "Request failed"
812
- });
813
- let globalMessages = null;
814
- /**
815
- * App-wide wording, merged over the defaults; `null` restores them. A grid's own
816
- * `errorMessages` merges over this in turn, so a single table can still differ.
817
- */
818
- function setErrorMessages(messages) {
819
- globalMessages = messages ? { ...messages } : null;
820
- }
821
- /** Defaults ← app-wide ← `local`, same shape as the filter builder's `resolveTexts`. */
822
- function resolveErrorMessages(local) {
823
- const merged = { ...DEFAULT_ERROR_MESSAGES };
824
- for (const layer of [globalMessages, local]) {
825
- if (!layer) continue;
826
- for (const key of Object.keys(layer)) {
827
- const value = layer[key];
828
- if (typeof value === "string" && value.trim()) merged[key] = value;
829
- }
830
- }
831
- return merged;
832
- }
833
- /**
834
- * The standard reason phrases. Not shown to anyone — they are what `describeError`
835
- * uses to recognise that an error's text is ONLY the phrase for its status
836
- * (`Error('Forbidden')` + `httpStatus: 403`), which adds nothing to the preset and
837
- * so is not a detail worth appending.
838
- */
839
- const REASON_PHRASES = {
840
- 400: "Bad Request",
841
- 401: "Unauthorized",
842
- 402: "Payment Required",
843
- 403: "Forbidden",
844
- 404: "Not Found",
845
- 405: "Method Not Allowed",
846
- 408: "Request Timeout",
847
- 409: "Conflict",
848
- 410: "Gone",
849
- 412: "Precondition Failed",
850
- 413: "Payload Too Large",
851
- 415: "Unsupported Media Type",
852
- 422: "Unprocessable Entity",
853
- 429: "Too Many Requests",
854
- 500: "Internal Server Error",
855
- 501: "Not Implemented",
856
- 502: "Bad Gateway",
857
- 503: "Service Unavailable",
858
- 504: "Gateway Timeout"
859
- };
860
- /** Texts a transport mints for "no answer at all" — a status of 0 in words. */
861
- const NETWORK_TEXTS = [
862
- "failed to fetch",
863
- "networkerror when attempting to fetch resource",
864
- "load failed",
865
- "network error",
866
- "unspecified network error",
867
- "network connection timeout",
868
- "network request failed"
869
- ];
870
- const toStatus = (value) => {
871
- if (value === null || value === void 0 || value === "") return void 0;
872
- const n = Number(value);
873
- return Number.isInteger(n) && n >= 0 && n < 1e3 ? n : void 0;
874
- };
875
- /**
876
- * The HTTP status an error carries, `0` for a network failure, `undefined` when
877
- * it has none.
878
- *
879
- * Reads the fields the common transports use — devextreme's `httpStatus`, a
880
- * fetch `Response` / axios error's `status` and `response.status`, ofetch's
881
- * `statusCode`, an OData error body's numeric `code` — on an `Error` instance as
882
- * readily as on a plain object, since devextreme `extend()`s them onto an
883
- * `Error`.
884
- */
885
- function errorStatus(raw) {
886
- if (!isObject(raw)) return void 0;
887
- const response = isObject(raw.response) ? raw.response : void 0;
888
- const direct = toStatus(raw.httpStatus) ?? toStatus(raw.status) ?? toStatus(raw.statusCode) ?? toStatus(response?.status) ?? toStatus(response?.statusCode);
889
- if (direct !== void 0) return direct;
890
- const details = isObject(raw.errorDetails) ? raw.errorDetails : void 0;
891
- const code = toStatus(details?.code);
892
- if (code !== void 0 && code >= 400) return code;
893
- const own = (raw instanceof Error ? text(raw.message) : text(raw.message)).toLowerCase();
894
- if (own && NETWORK_TEXTS.some((t) => own.includes(t))) return 0;
895
- }
896
- /** A JSON response body handed over as text (an XHR's `responseText`), parsed; else undefined. */
897
- function parseBody(value) {
898
- if (typeof value !== "string") return void 0;
899
- const s = value.trim();
900
- if (!s.startsWith("{") && !s.startsWith("[")) return void 0;
901
- try {
902
- return JSON.parse(s);
903
- } catch {
904
- return;
905
- }
906
- }
907
- /** The "same message" key: case, spacing and trailing punctuation do not make two texts different. */
908
- const messageKey = (value) => value.toLowerCase().replace(/\s+/g, " ").replace(/[\s.!:;,]+$/, "").trim();
909
- /**
910
- * Keep each message once. Two texts are the same message when they match after
911
- * {@link messageKey}, and a text another kept one already CONTAINS adds nothing
912
- * ("Not found" next to "Not found: Order 42") — the longer, more specific one wins
913
- * and keeps its place in the order the messages were found.
914
- */
915
- function uniqueMessages(found) {
916
- const kept = [];
917
- for (const t of found) {
918
- const key = messageKey(t);
919
- if (!key) continue;
920
- if (kept.some((k) => k.key.includes(key))) continue;
921
- const swallowed = kept.findIndex((k) => key.includes(k.key));
922
- if (swallowed >= 0) {
923
- kept[swallowed] = {
924
- text: t,
925
- key
926
- };
927
- for (let i = kept.length - 1; i > swallowed; i--) if (key.includes(kept[i].key)) kept.splice(i, 1);
928
- continue;
929
- }
930
- kept.push({
931
- text: t,
932
- key
933
- });
934
- }
935
- return kept.map((k) => k.text);
936
- }
937
- /**
938
- * Every message an error carries, combined the way `monoFetch`'s
939
- * `extractErrorMessage` does it: each key whose name contains "message"
940
- * (`message`, `errorMessage`, `Message`, …) holding text — or OData's
941
- * `{ message: { value } }` — at any depth up to 3, plus a JSON body still in
942
- * `responseText` / `responseJSON` / `response`, plus an `Error`'s own
943
- * (non-enumerable) `message`. The usual body fields `detail` / `title` and a
944
- * plain-text `response.data` count too.
945
- *
946
- * Deduplicated by {@link uniqueMessages}, transport boilerplate ("Bad Request",
947
- * "Failed to fetch") dropped, in the order found.
948
- */
949
- function collectErrorMessages(raw, status = errorStatus(raw)) {
950
- const found = [];
951
- const add = (value) => {
952
- const t = text(value);
953
- if (t) found.push(t);
954
- };
955
- const seen = /* @__PURE__ */ new Set();
956
- const visit = (val, depth) => {
957
- if (!isObject(val) || depth > 3 || seen.has(val)) return;
958
- seen.add(val);
959
- if (val instanceof Error) add(val.message);
960
- for (const [k, v] of Object.entries(val)) {
961
- if (/message/i.test(k)) {
962
- if (typeof v === "string") add(v);
963
- else if (isObject(v) && typeof v.value === "string") add(v.value);
964
- } else if (k === "detail" || k === "title" || k === "errorDetail") add(v);
965
- else if (k === "responseText" || k === "response" || k === "data" || k === "_data") {
966
- if (typeof v === "string") {
967
- const body = parseBody(v);
968
- if (body !== void 0) visit(body, depth + 1);
969
- else if (k !== "response") add(v);
970
- }
971
- }
972
- if (isObject(v)) visit(v, depth + 1);
973
- }
974
- };
975
- if (typeof raw === "string") add(raw);
976
- else visit(raw, 0);
977
- return uniqueMessages(found).filter((t) => !isBoilerplate(t, status));
978
- }
979
- /** Is `value` nothing more than the reason phrase / a generic label for `status`? */
980
- function isBoilerplate(value, status) {
981
- const v = value.toLowerCase();
982
- if (!v || v === "error" || v === "unknown error" || v === "request failed") return true;
983
- if (/^http\s*\d{3}$/.test(v)) return true;
984
- if (NETWORK_TEXTS.some((t) => v.includes(t))) return true;
985
- if (status !== void 0) {
986
- const phrase = REASON_PHRASES[status]?.toLowerCase();
987
- if (phrase && (v === phrase || v === `${status} ${phrase}` || v === `${status}`)) return true;
988
- if (v === String(status)) return true;
989
- }
990
- return Object.values(REASON_PHRASES).some((p) => p.toLowerCase() === v);
991
- }
992
- /**
993
- * The one line a field shows for `err`: what the server said, every distinct
994
- * message combined (`monoFetch` style), or the headline when it said nothing.
995
- */
996
- function errorText(err, separator = " · ") {
997
- return err.messages.length ? err.messages.join(separator) : err.message;
998
- }
999
- /** The hover text: the headline, then everything the server said, each once. */
1000
- function errorTitle(err) {
1001
- return uniqueMessages([err.message, ...err.messages]).join("\n");
1002
- }
1003
- /**
1004
- * The line a person should read for `raw`.
1005
- *
1006
- * Order: a preset for the status (`'network'` for 0) → the error's own text →
1007
- * `messages.default`. When a preset is the headline, whatever the server said
1008
- * on top of the status becomes `detail`; without a preset, the raw text IS the
1009
- * headline and only a distinct server body is a detail. Never throws, never
1010
- * returns an empty `message`.
1011
- */
1012
- function describeError(raw, messages) {
1013
- const texts = resolveErrorMessages(messages);
1014
- const status = errorStatus(raw);
1015
- const fallback = texts.default || DEFAULT_ERROR_MESSAGES.default;
1016
- const rawText = normalizeError(raw, fallback);
1017
- const preset = status === void 0 ? void 0 : status === 0 ? texts.network : texts[status];
1018
- const said = collectErrorMessages(raw, status).filter((m) => m !== preset);
1019
- if (preset) {
1020
- const out = {
1021
- message: preset,
1022
- status,
1023
- messages: said
1024
- };
1025
- if (said.length) out.detail = said.join("\n\n");
1026
- return out;
1027
- }
1028
- const message = rawText || fallback;
1029
- const rest = said.filter((m) => messageKey(m) !== messageKey(message));
1030
- const out = {
1031
- message,
1032
- messages: said
1033
- };
1034
- if (status !== void 0) out.status = status;
1035
- if (rest.length) out.detail = rest.join("\n\n");
1036
- return out;
1037
- }
1038
- /**
1039
- * A load a newer load superseded (devextreme rejects it with `'canceled'`).
1040
- * Not a failure — nothing should be shown for it.
1041
- */
1042
- function isCanceled(err) {
1043
- if (!err) return false;
1044
- return err === "canceled" || err.name === "canceled" || err.message === "canceled" || err.__id === "canceled";
1045
- }
1046
-
1047
- //#endregion
1048
- export { resolveSearchEntries as C, compileFilterPredicate as D, andPredicates as E, joinFilters as O, plainSearchColumns as S, andFilters as T, expandWildcard as _, errorTitle as a, isWildcardPattern as b, resolveErrorMessages as c, MonoSourceSearch as d, mergeSearchFields as f, customRemoteClause as g, customPredicate as h, errorText as i, setErrorMessages as l, searchRowPredicate as m, describeError as n, isCanceled as o, resolveSearchFields as p, errorStatus as r, normalizeError as s, DEFAULT_ERROR_MESSAGES as t, DEFAULT_SEARCH_FIELDS as u, hasCustomSearch as v, searchEntryFor as w, normalizeSearchExpr as x, hasWildcardSearch as y };