@kumix/ui 0.3.7 → 0.3.8

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 (173) hide show
  1. package/README.md +25 -24
  2. package/dist/cascader-types-BnH6wYD-.d.ts +183 -0
  3. package/dist/cascader-types-BnH6wYD-.d.ts.map +1 -0
  4. package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
  5. package/dist/components/motion/animated-sidebar.js +12 -3
  6. package/dist/components/motion/animated-sidebar.js.map +1 -1
  7. package/dist/components/motion/attachment-upload.d.ts.map +1 -1
  8. package/dist/components/motion/attachment-upload.js +9 -5
  9. package/dist/components/motion/attachment-upload.js.map +1 -1
  10. package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
  11. package/dist/components/motion/bottom-sheet.js +77 -74
  12. package/dist/components/motion/bottom-sheet.js.map +1 -1
  13. package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
  14. package/dist/components/motion/center-morph-modal.js +82 -88
  15. package/dist/components/motion/center-morph-modal.js.map +1 -1
  16. package/dist/components/motion/command-palette.d.ts.map +1 -1
  17. package/dist/components/motion/command-palette.js +48 -26
  18. package/dist/components/motion/command-palette.js.map +1 -1
  19. package/dist/components/motion/drawer.d.ts.map +1 -1
  20. package/dist/components/motion/drawer.js +30 -30
  21. package/dist/components/motion/drawer.js.map +1 -1
  22. package/dist/components/motion/loader.js +20 -22
  23. package/dist/components/motion/loader.js.map +1 -1
  24. package/dist/components/motion/morphing-modal.d.ts.map +1 -1
  25. package/dist/components/motion/morphing-modal.js +83 -83
  26. package/dist/components/motion/morphing-modal.js.map +1 -1
  27. package/dist/components/motion/morphing-search.d.ts +28 -0
  28. package/dist/components/motion/morphing-search.d.ts.map +1 -0
  29. package/dist/components/motion/morphing-search.js +418 -0
  30. package/dist/components/motion/morphing-search.js.map +1 -0
  31. package/dist/components/motion/project-folder.js +20 -20
  32. package/dist/components/motion/project-folder.js.map +1 -1
  33. package/dist/components/reui/badge.d.ts +1 -1
  34. package/dist/components/reui/cascader/cascader-async.d.ts +90 -0
  35. package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
  36. package/dist/components/reui/cascader/cascader-async.js +549 -0
  37. package/dist/components/reui/cascader/cascader-async.js.map +1 -0
  38. package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
  39. package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
  40. package/dist/components/reui/cascader/cascader-columns.js +135 -0
  41. package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
  42. package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
  43. package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
  44. package/dist/components/reui/cascader/cascader-context.js +59 -0
  45. package/dist/components/reui/cascader/cascader-context.js.map +1 -0
  46. package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
  47. package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
  48. package/dist/components/reui/cascader/cascader-footer.js +456 -0
  49. package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
  50. package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
  51. package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
  52. package/dist/components/reui/cascader/cascader-i18n.js +68 -0
  53. package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
  54. package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
  55. package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
  56. package/dist/components/reui/cascader/cascader-item.js +530 -0
  57. package/dist/components/reui/cascader/cascader-item.js.map +1 -0
  58. package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
  59. package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
  60. package/dist/components/reui/cascader/cascader-lib.js +576 -0
  61. package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
  62. package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
  63. package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
  64. package/dist/components/reui/cascader/cascader-nav.js +312 -0
  65. package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
  66. package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
  67. package/dist/components/reui/cascader/cascader-types.js +2 -0
  68. package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
  69. package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
  70. package/dist/components/reui/cascader/cascader-virtual.js +240 -0
  71. package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
  72. package/dist/components/reui/cascader/cascader.d.ts +322 -0
  73. package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
  74. package/dist/components/reui/cascader/cascader.js +1459 -0
  75. package/dist/components/reui/cascader/cascader.js.map +1 -0
  76. package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
  77. package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
  78. package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
  79. package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
  80. package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
  81. package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
  82. package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
  83. package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
  84. package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
  85. package/dist/components/reui/filters/filters-advanced.js +1191 -0
  86. package/dist/components/reui/filters/filters-advanced.js.map +1 -0
  87. package/dist/components/reui/filters/filters-builder.d.ts +43 -0
  88. package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
  89. package/dist/components/reui/filters/filters-builder.js +152 -0
  90. package/dist/components/reui/filters/filters-builder.js.map +1 -0
  91. package/dist/components/reui/filters/filters-chip.d.ts +79 -0
  92. package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
  93. package/dist/components/reui/filters/filters-chip.js +553 -0
  94. package/dist/components/reui/filters/filters-chip.js.map +1 -0
  95. package/dist/components/reui/filters/filters-context.d.ts +290 -0
  96. package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
  97. package/dist/components/reui/filters/filters-context.js +277 -0
  98. package/dist/components/reui/filters/filters-context.js.map +1 -0
  99. package/dist/components/reui/filters/filters-date.d.ts +43 -0
  100. package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
  101. package/dist/components/reui/filters/filters-date.js +143 -0
  102. package/dist/components/reui/filters/filters-date.js.map +1 -0
  103. package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
  104. package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
  105. package/dist/components/reui/filters/filters-dnd.js +454 -0
  106. package/dist/components/reui/filters/filters-dnd.js.map +1 -0
  107. package/dist/components/reui/filters/filters-draft.d.ts +2 -0
  108. package/dist/components/reui/filters/filters-draft.js +128 -0
  109. package/dist/components/reui/filters/filters-draft.js.map +1 -0
  110. package/dist/components/reui/filters/filters-editors.d.ts +91 -0
  111. package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
  112. package/dist/components/reui/filters/filters-editors.js +773 -0
  113. package/dist/components/reui/filters/filters-editors.js.map +1 -0
  114. package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
  115. package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
  116. package/dist/components/reui/filters/filters-i18n.js +127 -0
  117. package/dist/components/reui/filters/filters-i18n.js.map +1 -0
  118. package/dist/components/reui/filters/filters-lib.d.ts +171 -0
  119. package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
  120. package/dist/components/reui/filters/filters-lib.js +336 -0
  121. package/dist/components/reui/filters/filters-lib.js.map +1 -0
  122. package/dist/components/reui/filters/filters-operators.d.ts +49 -0
  123. package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
  124. package/dist/components/reui/filters/filters-operators.js +300 -0
  125. package/dist/components/reui/filters/filters-operators.js.map +1 -0
  126. package/dist/components/reui/filters/filters-query.d.ts +132 -0
  127. package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
  128. package/dist/components/reui/filters/filters-query.js +476 -0
  129. package/dist/components/reui/filters/filters-query.js.map +1 -0
  130. package/dist/components/reui/filters/filters-types.d.ts +452 -0
  131. package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
  132. package/dist/components/reui/filters/filters-types.js +2 -0
  133. package/dist/components/reui/filters/filters.d.ts +114 -0
  134. package/dist/components/reui/filters/filters.d.ts.map +1 -0
  135. package/dist/components/reui/filters/filters.js +638 -0
  136. package/dist/components/reui/filters/filters.js.map +1 -0
  137. package/dist/components/reui/frame.d.ts +1 -1
  138. package/dist/components/reui/gantt/gantt-bar.js +1 -1
  139. package/dist/components/reui/gantt/gantt-nav.js +1 -1
  140. package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
  141. package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
  142. package/dist/components/reui/gantt/gantt-view.js +1 -1
  143. package/dist/components/ui/attachment.d.ts +1 -1
  144. package/dist/components/ui/badge.d.ts +1 -1
  145. package/dist/components/ui/bubble.d.ts +1 -1
  146. package/dist/components/ui/button-group.d.ts +1 -1
  147. package/dist/components/ui/button.d.ts +2 -2
  148. package/dist/components/ui/checkbox.js +1 -1
  149. package/dist/components/ui/checkbox.js.map +1 -1
  150. package/dist/components/ui/field.d.ts +1 -1
  151. package/dist/components/ui/field.js +2 -2
  152. package/dist/components/ui/field.js.map +1 -1
  153. package/dist/components/ui/item.d.ts +1 -1
  154. package/dist/components/ui/radio-group.js +1 -1
  155. package/dist/components/ui/radio-group.js.map +1 -1
  156. package/dist/components/ui/sidebar.d.ts +1 -1
  157. package/dist/components/ui/sidebar.js +1 -1
  158. package/dist/components/ui/switch.js +1 -1
  159. package/dist/components/ui/switch.js.map +1 -1
  160. package/dist/components/ui/toggle.d.ts +1 -1
  161. package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
  162. package/dist/filters-draft-DEAl3TO-.d.ts.map +1 -0
  163. package/dist/lib/text-shimmer.d.ts +2 -2
  164. package/dist/lib/text-shimmer.d.ts.map +1 -1
  165. package/dist/lib/text-shimmer.js +2 -2
  166. package/dist/lib/text-shimmer.js.map +1 -1
  167. package/dist/presence-gate-BekdC4Bo.js +24 -0
  168. package/dist/presence-gate-BekdC4Bo.js.map +1 -0
  169. package/package.json +9 -9
  170. package/dist/components/reui/filters.d.ts +0 -176
  171. package/dist/components/reui/filters.d.ts.map +0 -1
  172. package/dist/components/reui/filters.js +0 -1223
  173. package/dist/components/reui/filters.js.map +0 -1
@@ -0,0 +1,336 @@
1
+ "use client";
2
+ import { collapseCascaderPath } from "../cascader/cascader-lib.js";
3
+ //#region src/components/reui/filters/filters-lib.tsx
4
+ /**
5
+ * One menu size for the chip's kebab and the builder's three menus, which draw
6
+ * the same rows. `w-max` OVERRIDES the shadcn content width, which pins to the
7
+ * anchor and hides horizontal overflow, so a menu hung off a 28px icon button
8
+ * CUT every longer row. Floor 128px, down from 224px: the rows run about 130px,
9
+ * and five of the eight styles already floor a dropdown there (luma, maia and
10
+ * sera sit at 192px). The 24rem cap stops a pathological label pushing the menu
11
+ * off the side of a phone. Past it a row truncates rather than wraps, since a
12
+ * wrapped row changes HEIGHT and would slide the destructive row under the
13
+ * pointer: `min-w-0` lets a row shrink below its content at all (a flex child's
14
+ * floor is its content otherwise) and the label span carries `truncate`, see
15
+ * `FILTER_MENU_LABEL_CLASS`.
16
+ */
17
+ const FILTER_MENU_CLASS = "w-max min-w-32 max-w-[min(24rem,calc(100vw-2rem))] [&_[data-slot=dropdown-menu-item]]:min-w-0";
18
+ /**
19
+ * What a menu row's LABEL wears, and it has to be a real span: `text-overflow`
20
+ * needs a block container, not the anonymous flex item a bare text child is.
21
+ * `min-w-0` so the span can shrink below its own content.
22
+ */
23
+ const FILTER_MENU_LABEL_CLASS = "min-w-0 truncate";
24
+ /**
25
+ * The FIELD PICKER's panel, shared by the Add filter popover and the advanced
26
+ * row's attribute cell so one schema is never drawn at two widths. `w-auto`
27
+ * grows to the longest row, so the 224px floor (down from 256px) only decides
28
+ * the reported case: a flat schema of short names in a mostly empty panel.
29
+ * Measured: 224px still clears the search input, the breadcrumb and a leaf
30
+ * row's icon-plus-label.
31
+ */
32
+ const FILTER_FIELD_PICKER_CLASS = "w-auto min-w-56 p-0";
33
+ /** Root key for `childrenOf`; a control char cannot collide with a field id. */
34
+ const FILTER_ROOT_KEY = "\0root";
35
+ /** Separator between path segments in the flat map keys. */
36
+ const PATH_SEPARATOR = "\0";
37
+ function joinFilterPath(path) {
38
+ return path.join(PATH_SEPARATOR);
39
+ }
40
+ function splitFilterPath(key) {
41
+ return key === "" ? [] : key.split(PATH_SEPARATOR);
42
+ }
43
+ /** The joined key of a path's parent, or `FILTER_ROOT_KEY` at the top level. */
44
+ function parentFilterKey(path) {
45
+ return path.length <= 1 ? FILTER_ROOT_KEY : joinFilterPath(path.slice(0, -1));
46
+ }
47
+ /**
48
+ * A content hash of the schema, used to skip a rebuild. Identity alone is
49
+ * useless: every block and example declares `fields` as an inline literal, so a
50
+ * memo keyed on the array misses on every parent render. Render props (`icon`,
51
+ * `renderValue`, a component-valued `editor`) are hashed by PRESENCE only,
52
+ * because inline JSX recreates them: swapping one's body keeps serving the
53
+ * previous field objects, so change a structural field or give `fields` a
54
+ * stable identity.
55
+ */
56
+ function computeFilterSchemaSignature(fields) {
57
+ const parts = [];
58
+ const walk = (list, depth) => {
59
+ for (const field of list) {
60
+ parts.push(depth + ":" + field.id + "|" + (field.label ?? "") + "|" + (field.type ?? "") + "|" + (field.defaultOperator ?? "") + "|" + (field.column ?? "") + "|" + (field.selectable ? "1" : "0") + (field.disabled ? "1" : "0") + (field.icon ? "1" : "0") + (field.renderValue ? "1" : "0") + (field.loadOptions ? "1" : "0") + (field.resolveValues ? "1" : "0") + "|" + (typeof field.editor === "string" ? field.editor : field.editor ? "fn" : "") + "|" + (field.keywords?.join(",") ?? "") + "|" + (field.count ?? "") + "|" + (field.options ? field.options.map((option) => `${option.value}~${option.label}${option.exclusive ? "~x" : ""}`).join(",") : "") + "|" + (Array.isArray(field.operators) ? field.operators.map((operator) => operator.value).join(",") : field.operators ? "fn" : ""));
61
+ if (field.fields?.length) walk(field.fields, depth + 1);
62
+ }
63
+ };
64
+ walk(fields, 0);
65
+ return parts.join("\n");
66
+ }
67
+ const EMPTY_INDEX = {
68
+ byPath: /* @__PURE__ */ new Map(),
69
+ childrenOf: /* @__PURE__ */ new Map(),
70
+ parentOf: /* @__PURE__ */ new Map(),
71
+ all: [],
72
+ roots: [],
73
+ signature: ""
74
+ };
75
+ /**
76
+ * Normalizes a field schema into flat maps. When `previous`'s signature
77
+ * matches, the PREVIOUS OBJECT is returned: an equal-but-new one would leave
78
+ * every downstream memo missing exactly as often as before. Duplicate sibling
79
+ * ids are ignored after the first, as the cascader does for node values, and
80
+ * `findFilterSchemaIssues` reports them in development.
81
+ */
82
+ function buildFilterIndex(fields, previous, precomputedSignature) {
83
+ const signature = precomputedSignature ?? computeFilterSchemaSignature(fields);
84
+ if (previous && previous.signature === signature) return previous;
85
+ if (fields.length === 0) return {
86
+ ...EMPTY_INDEX,
87
+ signature
88
+ };
89
+ const byPath = /* @__PURE__ */ new Map();
90
+ const childrenOf = /* @__PURE__ */ new Map();
91
+ const parentOf = /* @__PURE__ */ new Map();
92
+ const all = [];
93
+ const roots = [];
94
+ const walk = (list, parentPath, parentKey) => {
95
+ const accepted = [];
96
+ const seen = /* @__PURE__ */ new Set();
97
+ for (const field of list) {
98
+ if (seen.has(field.id)) continue;
99
+ seen.add(field.id);
100
+ const path = [...parentPath, field.id];
101
+ const key = joinFilterPath(path);
102
+ if (byPath.has(key)) continue;
103
+ byPath.set(key, field);
104
+ parentOf.set(key, parentKey === "\0root" ? "" : parentKey);
105
+ all.push({
106
+ field,
107
+ path
108
+ });
109
+ accepted.push(field);
110
+ if (field.fields?.length) walk(field.fields, path, key);
111
+ }
112
+ childrenOf.set(parentKey, accepted);
113
+ if (parentKey === "\0root") roots.push(...accepted);
114
+ };
115
+ walk(fields, [], FILTER_ROOT_KEY);
116
+ return {
117
+ byPath,
118
+ childrenOf,
119
+ parentOf,
120
+ all,
121
+ roots,
122
+ signature
123
+ };
124
+ }
125
+ function getFilterField(index, path) {
126
+ return index.byPath.get(joinFilterPath(path));
127
+ }
128
+ /** The ancestor chain for a path, root first and the field itself last. */
129
+ function getFilterFieldChain(index, path) {
130
+ const chain = [];
131
+ for (let i = 1; i <= path.length; i++) {
132
+ const field = index.byPath.get(joinFilterPath(path.slice(0, i)));
133
+ if (!field) break;
134
+ chain.push(field);
135
+ }
136
+ return chain;
137
+ }
138
+ /** Child fields of a path. Pass an empty path for the root level. */
139
+ function getFilterChildren(index, path) {
140
+ const key = path.length === 0 ? FILTER_ROOT_KEY : joinFilterPath(path);
141
+ return index.childrenOf.get(key) ?? [];
142
+ }
143
+ function isFilterBranch(field) {
144
+ return Boolean(field.fields?.length);
145
+ }
146
+ /**
147
+ * Whether a field DECLARES itself filterable on: leaves always, a branch only
148
+ * with `selectable`. The shipped pickers ignore it, see `isFilterFieldPickable`.
149
+ */
150
+ function isFilterFieldSelectable(field) {
151
+ if (field.disabled) return false;
152
+ return isFilterBranch(field) ? Boolean(field.selectable) : true;
153
+ }
154
+ /**
155
+ * Whether the SHIPPED pickers may commit a field: leaves only. A row that both
156
+ * drills in and commits cannot disambiguate a click - its chevron and child
157
+ * count promise "opens a list", so the press that opened it also filtered on
158
+ * the parent and dismissed the picker. `selectable` stays honoured by
159
+ * `isFilterFieldSelectable` for a chrome that separates the two.
160
+ */
161
+ function isFilterFieldPickable(field) {
162
+ if (field.disabled) return false;
163
+ return !isFilterBranch(field);
164
+ }
165
+ /** Trailing count for a branch row. */
166
+ function getFilterFieldCount(field) {
167
+ return field.count ?? field.fields?.length ?? 0;
168
+ }
169
+ /** Renders a path as "Name > First" using the caller's separator. */
170
+ function formatFilterPath(index, path, separator) {
171
+ const chain = getFilterFieldChain(index, path);
172
+ if (chain.length === 0) return path.join(separator);
173
+ return chain.map((field) => field.label).join(separator);
174
+ }
175
+ /**
176
+ * Shortens an ancestor chain to at most `maxSegments` names, on the cascader's
177
+ * arithmetic so the chip's path and the builder's attribute cell cannot round
178
+ * differently. The adapter is POSITIONAL because a `FilterField`'s `id` is
179
+ * unique only among its siblings, so the index is the only key that survives a
180
+ * collapser keyed on `value`. Default `"none"`: no upgrade shortens a path.
181
+ */
182
+ function collapseFilterPath(chain, options = {}) {
183
+ return collapseCascaderPath(chain.map((field, index) => ({
184
+ value: String(index),
185
+ label: field.label
186
+ })), {
187
+ maxSegments: options.maxSegments,
188
+ collapse: options.collapse ?? "none"
189
+ }).map((segment) => segment.type === "node" ? {
190
+ type: "field",
191
+ field: chain[Number(segment.node.value)]
192
+ } : {
193
+ type: "ellipsis",
194
+ hidden: segment.hidden.map((node) => chain[Number(node.value)])
195
+ });
196
+ }
197
+ /**
198
+ * Which of the three forms the combinator slot before rule `index` takes. A
199
+ * group has exactly ONE combinator, so only one slot may be interactive: three
200
+ * editable "and"s down a column would imply three independent choices.
201
+ */
202
+ function filterCombinatorSlot(index) {
203
+ if (index === 0) return "where";
204
+ return index === 1 ? "toggle" : "echo";
205
+ }
206
+ /** `toLocaleLowerCase`, so Turkish dotted and dotless i fold as a reader expects. */
207
+ function foldFilterText(text) {
208
+ return text.toLocaleLowerCase();
209
+ }
210
+ function normalizeFilterQuery(query) {
211
+ return foldFilterText(query.trim());
212
+ }
213
+ /** Whether a field matches a normalized query, by label or keywords. */
214
+ function matchesFilterQuery(field, normalizedQuery) {
215
+ if (normalizedQuery === "") return true;
216
+ if (foldFilterText(field.label).includes(normalizedQuery)) return true;
217
+ if (field.keywords) {
218
+ for (const keyword of field.keywords) if (foldFilterText(keyword).includes(normalizedQuery)) return true;
219
+ }
220
+ return false;
221
+ }
222
+ /**
223
+ * Filters one level, preserving input order. Unused here like
224
+ * `searchFilterDeep`: kept so a consumer's own picker need not re-implement the
225
+ * fold and the keyword matching.
226
+ */
227
+ function filterFilterLevel(fields, normalizedQuery) {
228
+ if (normalizedQuery === "") return fields;
229
+ return fields.filter((field) => matchesFilterQuery(field, normalizedQuery));
230
+ }
231
+ /**
232
+ * Searches every SELECTABLE field at any depth, because a result the user
233
+ * cannot pick is a dead end. Unused here - the shipped picker is the cascader
234
+ * and delegates deep search to it - but it keeps a consumer's own picker from
235
+ * re-implementing the fold, the keyword matching and the selectable rule.
236
+ */
237
+ function searchFilterDeep(index, normalizedQuery, limit = 200) {
238
+ if (normalizedQuery === "") return [];
239
+ const results = [];
240
+ for (const entry of index.all) {
241
+ if (results.length >= limit) break;
242
+ if (!isFilterFieldSelectable(entry.field)) continue;
243
+ if (matchesFilterQuery(entry.field, normalizedQuery)) results.push(entry);
244
+ }
245
+ return results;
246
+ }
247
+ /** Filters an option list by a normalized query, by label or keywords. */
248
+ function filterFilterOptions(options, normalizedQuery) {
249
+ if (normalizedQuery === "") return options;
250
+ return options.filter((option) => {
251
+ if (foldFilterText(option.label).includes(normalizedQuery)) return true;
252
+ if (option.keywords) {
253
+ for (const keyword of option.keywords) if (foldFilterText(keyword).includes(normalizedQuery)) return true;
254
+ }
255
+ return false;
256
+ });
257
+ }
258
+ /**
259
+ * The None rule, as pure algebra over two selections: pick the `exclusive`
260
+ * option and it is the only pick, pick anything else and it goes. Written
261
+ * against the DELTA, not the result, which is what makes it total: an empty
262
+ * delta is a removal, including UNTICKING the exclusive row; an exclusive
263
+ * arrival is the whole answer; an ordinary arrival drops every exclusive value,
264
+ * restored ones included; both at once gives it to the LAST exclusive.
265
+ * `isExclusive` is a lookup, not an array, because a query hiding the None row
266
+ * while it stays SELECTED would answer "not exclusive" for the value the click
267
+ * must clear. Never applied on read - a saved view is the consumer's data - so
268
+ * it heals on the first ordinary pick, and only while `isExclusive` can ANSWER:
269
+ * a None row on a `loadOptions` field belongs in the static `options`.
270
+ */
271
+ function applyFilterExclusiveSelection(next, previous, isExclusive) {
272
+ const held = new Set(previous);
273
+ const added = next.filter((value) => !held.has(value));
274
+ if (added.length === 0) return next;
275
+ let arrived = null;
276
+ for (const value of added) if (isExclusive(value)) arrived = value;
277
+ if (arrived !== null) return [arrived];
278
+ const kept = next.filter((value) => !isExclusive(value));
279
+ return kept.length === next.length ? next : kept;
280
+ }
281
+ /**
282
+ * Builds a deterministic id generator. `Date.now()` and `Math.random()`, as the
283
+ * old `createFilter` used, give the server and the client different ids for the
284
+ * same query, so any page shipping default filters hydrated mismatched.
285
+ */
286
+ function createFilterIdFactory(seed) {
287
+ let counter = 0;
288
+ return () => {
289
+ counter += 1;
290
+ return `${seed}${counter}`;
291
+ };
292
+ }
293
+ const warned = /* @__PURE__ */ new Set();
294
+ /** Warns once per key. Never throws, and is a no-op in production. */
295
+ function warnFilterOnce(key, message) {
296
+ if (process.env.NODE_ENV === "production") return;
297
+ if (warned.has(key)) return;
298
+ warned.add(key);
299
+ console.warn(`[filters] ${message}`);
300
+ }
301
+ /** Clears the warn-once memory. For tests. */
302
+ function resetFilterWarnings() {
303
+ warned.clear();
304
+ }
305
+ /** Reported, never thrown: a bad schema must degrade, not blank the page. */
306
+ function findFilterSchemaIssues(fields, resolveOperators) {
307
+ const duplicatePaths = [];
308
+ const emptyIds = [];
309
+ const emptyBranches = [];
310
+ const unknownDefaultOperators = [];
311
+ const walk = (list, parentPath) => {
312
+ const seen = /* @__PURE__ */ new Set();
313
+ for (const field of list) {
314
+ const label = [...parentPath, field.id].join(".");
315
+ if (!field.id) emptyIds.push(label);
316
+ else if (seen.has(field.id)) duplicatePaths.push(label);
317
+ seen.add(field.id);
318
+ if (field.selectable && field.fields && field.fields.length === 0) emptyBranches.push(label);
319
+ if (field.defaultOperator) {
320
+ if (!resolveOperators(field).some((op) => op.value === field.defaultOperator)) unknownDefaultOperators.push(`${label} -> ${field.defaultOperator}`);
321
+ }
322
+ if (field.fields?.length) walk(field.fields, [...parentPath, field.id]);
323
+ }
324
+ };
325
+ walk(fields, []);
326
+ return {
327
+ duplicatePaths,
328
+ emptyIds,
329
+ emptyBranches,
330
+ unknownDefaultOperators
331
+ };
332
+ }
333
+ //#endregion
334
+ export { FILTER_FIELD_PICKER_CLASS, FILTER_MENU_CLASS, FILTER_MENU_LABEL_CLASS, FILTER_ROOT_KEY, applyFilterExclusiveSelection, buildFilterIndex, collapseFilterPath, computeFilterSchemaSignature, createFilterIdFactory, filterCombinatorSlot, filterFilterLevel, filterFilterOptions, findFilterSchemaIssues, foldFilterText, formatFilterPath, getFilterChildren, getFilterField, getFilterFieldChain, getFilterFieldCount, isFilterBranch, isFilterFieldPickable, isFilterFieldSelectable, joinFilterPath, matchesFilterQuery, normalizeFilterQuery, parentFilterKey, resetFilterWarnings, searchFilterDeep, splitFilterPath, warnFilterOnce };
335
+
336
+ //# sourceMappingURL=filters-lib.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters-lib.js","names":[],"sources":["../../../../src/components/reui/filters/filters-lib.tsx"],"sourcesContent":["\"use client\";\n\nimport { collapseCascaderPath } from \"../cascader/cascader-lib\";\nimport type { CascaderCollapse } from \"../cascader/cascader-types\";\nimport type { FilterField, FilterIndex, FilterOperator, FilterOption } from \"./filters-types\";\n\n/* -------------------------------------------------------------------------- */\n/* Menus */\n/* -------------------------------------------------------------------------- */\n\n/**\n * One menu size for the chip's kebab and the builder's three menus, which draw\n * the same rows. `w-max` OVERRIDES the shadcn content width, which pins to the\n * anchor and hides horizontal overflow, so a menu hung off a 28px icon button\n * CUT every longer row. Floor 128px, down from 224px: the rows run about 130px,\n * and five of the eight styles already floor a dropdown there (luma, maia and\n * sera sit at 192px). The 24rem cap stops a pathological label pushing the menu\n * off the side of a phone. Past it a row truncates rather than wraps, since a\n * wrapped row changes HEIGHT and would slide the destructive row under the\n * pointer: `min-w-0` lets a row shrink below its content at all (a flex child's\n * floor is its content otherwise) and the label span carries `truncate`, see\n * `FILTER_MENU_LABEL_CLASS`.\n */\nexport const FILTER_MENU_CLASS =\n \"w-max min-w-32 max-w-[min(24rem,calc(100vw-2rem))] [&_[data-slot=dropdown-menu-item]]:min-w-0\";\n\n/**\n * What a menu row's LABEL wears, and it has to be a real span: `text-overflow`\n * needs a block container, not the anonymous flex item a bare text child is.\n * `min-w-0` so the span can shrink below its own content.\n */\nexport const FILTER_MENU_LABEL_CLASS = \"min-w-0 truncate\";\n\n/**\n * The FIELD PICKER's panel, shared by the Add filter popover and the advanced\n * row's attribute cell so one schema is never drawn at two widths. `w-auto`\n * grows to the longest row, so the 224px floor (down from 256px) only decides\n * the reported case: a flat schema of short names in a mostly empty panel.\n * Measured: 224px still clears the search input, the breadcrumb and a leaf\n * row's icon-plus-label.\n */\nexport const FILTER_FIELD_PICKER_CLASS = \"w-auto min-w-56 p-0\";\n\n/* -------------------------------------------------------------------------- */\n/* Paths */\n/* -------------------------------------------------------------------------- */\n\n/** Root key for `childrenOf`; a control char cannot collide with a field id. */\nexport const FILTER_ROOT_KEY = \"\\u0000root\";\n\n/** Separator between path segments in the flat map keys. */\nconst PATH_SEPARATOR = \"\\u0000\";\n\nexport function joinFilterPath(path: readonly string[]): string {\n return path.join(PATH_SEPARATOR);\n}\n\nexport function splitFilterPath(key: string): string[] {\n return key === \"\" ? [] : key.split(PATH_SEPARATOR);\n}\n\n/** The joined key of a path's parent, or `FILTER_ROOT_KEY` at the top level. */\nexport function parentFilterKey(path: readonly string[]): string {\n return path.length <= 1 ? FILTER_ROOT_KEY : joinFilterPath(path.slice(0, -1));\n}\n\n/* -------------------------------------------------------------------------- */\n/* Signature */\n/* -------------------------------------------------------------------------- */\n\n/**\n * A content hash of the schema, used to skip a rebuild. Identity alone is\n * useless: every block and example declares `fields` as an inline literal, so a\n * memo keyed on the array misses on every parent render. Render props (`icon`,\n * `renderValue`, a component-valued `editor`) are hashed by PRESENCE only,\n * because inline JSX recreates them: swapping one's body keeps serving the\n * previous field objects, so change a structural field or give `fields` a\n * stable identity.\n */\nexport function computeFilterSchemaSignature<V, O>(fields: readonly FilterField<V, O>[]): string {\n const parts: string[] = [];\n\n const walk = (list: readonly FilterField<V, O>[], depth: number) => {\n for (const field of list) {\n parts.push(\n depth +\n \":\" +\n field.id +\n \"|\" +\n (field.label ?? \"\") +\n \"|\" +\n (field.type ?? \"\") +\n \"|\" +\n (field.defaultOperator ?? \"\") +\n \"|\" +\n (field.column ?? \"\") +\n \"|\" +\n (field.selectable ? \"1\" : \"0\") +\n (field.disabled ? \"1\" : \"0\") +\n (field.icon ? \"1\" : \"0\") +\n (field.renderValue ? \"1\" : \"0\") +\n (field.loadOptions ? \"1\" : \"0\") +\n (field.resolveValues ? \"1\" : \"0\") +\n \"|\" +\n (typeof field.editor === \"string\" ? field.editor : field.editor ? \"fn\" : \"\") +\n \"|\" +\n (field.keywords?.join(\",\") ?? \"\") +\n \"|\" +\n (field.count ?? \"\") +\n \"|\" +\n // Options are part of the shape, and `exclusive` rides along: it\n // decides what a pick DOES, so turning it on must force a rebuild.\n (field.options\n ? field.options\n .map((option) => `${option.value}~${option.label}${option.exclusive ? \"~x\" : \"\"}`)\n .join(\",\")\n : \"\") +\n \"|\" +\n (Array.isArray(field.operators)\n ? field.operators.map((operator) => operator.value).join(\",\")\n : field.operators\n ? \"fn\"\n : \"\"),\n );\n if (field.fields?.length) walk(field.fields, depth + 1);\n }\n };\n\n walk(fields, 0);\n return parts.join(\"\\n\");\n}\n\n/* -------------------------------------------------------------------------- */\n/* Index */\n/* -------------------------------------------------------------------------- */\n\nconst EMPTY_INDEX: FilterIndex<never, never> = {\n byPath: new Map(),\n childrenOf: new Map(),\n parentOf: new Map(),\n all: [],\n roots: [],\n signature: \"\",\n};\n\n/**\n * Normalizes a field schema into flat maps. When `previous`'s signature\n * matches, the PREVIOUS OBJECT is returned: an equal-but-new one would leave\n * every downstream memo missing exactly as often as before. Duplicate sibling\n * ids are ignored after the first, as the cascader does for node values, and\n * `findFilterSchemaIssues` reports them in development.\n */\nexport function buildFilterIndex<V = unknown, O = unknown>(\n fields: readonly FilterField<V, O>[],\n previous?: FilterIndex<V, O> | null,\n /** A signature the caller already computed, to avoid walking twice. */\n precomputedSignature?: string,\n): FilterIndex<V, O> {\n const signature = precomputedSignature ?? computeFilterSchemaSignature(fields);\n if (previous && previous.signature === signature) return previous;\n if (fields.length === 0) {\n return { ...(EMPTY_INDEX as unknown as FilterIndex<V, O>), signature };\n }\n\n const byPath = new Map<string, FilterField<V, O>>();\n const childrenOf = new Map<string, FilterField<V, O>[]>();\n const parentOf = new Map<string, string>();\n const all: { field: FilterField<V, O>; path: string[] }[] = [];\n const roots: FilterField<V, O>[] = [];\n\n const walk = (list: readonly FilterField<V, O>[], parentPath: string[], parentKey: string) => {\n const accepted: FilterField<V, O>[] = [];\n const seen = new Set<string>();\n\n for (const field of list) {\n if (seen.has(field.id)) continue;\n seen.add(field.id);\n\n const path = [...parentPath, field.id];\n const key = joinFilterPath(path);\n if (byPath.has(key)) continue;\n\n byPath.set(key, field);\n parentOf.set(key, parentKey === FILTER_ROOT_KEY ? \"\" : parentKey);\n all.push({ field, path });\n accepted.push(field);\n\n if (field.fields?.length) walk(field.fields, path, key);\n }\n\n childrenOf.set(parentKey, accepted);\n if (parentKey === FILTER_ROOT_KEY) roots.push(...accepted);\n };\n\n walk(fields, [], FILTER_ROOT_KEY);\n\n return { byPath, childrenOf, parentOf, all, roots, signature };\n}\n\nexport function getFilterField<V, O>(\n index: FilterIndex<V, O>,\n path: readonly string[],\n): FilterField<V, O> | undefined {\n return index.byPath.get(joinFilterPath(path));\n}\n\n/** The ancestor chain for a path, root first and the field itself last. */\nexport function getFilterFieldChain<V, O>(\n index: FilterIndex<V, O>,\n path: readonly string[],\n): FilterField<V, O>[] {\n const chain: FilterField<V, O>[] = [];\n for (let i = 1; i <= path.length; i++) {\n const field = index.byPath.get(joinFilterPath(path.slice(0, i)));\n if (!field) break;\n chain.push(field);\n }\n return chain;\n}\n\n/** Child fields of a path. Pass an empty path for the root level. */\nexport function getFilterChildren<V, O>(\n index: FilterIndex<V, O>,\n path: readonly string[],\n): FilterField<V, O>[] {\n const key = path.length === 0 ? FILTER_ROOT_KEY : joinFilterPath(path);\n return index.childrenOf.get(key) ?? [];\n}\n\nexport function isFilterBranch<V, O>(field: FilterField<V, O>): boolean {\n return Boolean(field.fields?.length);\n}\n\n/**\n * Whether a field DECLARES itself filterable on: leaves always, a branch only\n * with `selectable`. The shipped pickers ignore it, see `isFilterFieldPickable`.\n */\nexport function isFilterFieldSelectable<V, O>(field: FilterField<V, O>): boolean {\n if (field.disabled) return false;\n return isFilterBranch(field) ? Boolean(field.selectable) : true;\n}\n\n/**\n * Whether the SHIPPED pickers may commit a field: leaves only. A row that both\n * drills in and commits cannot disambiguate a click - its chevron and child\n * count promise \"opens a list\", so the press that opened it also filtered on\n * the parent and dismissed the picker. `selectable` stays honoured by\n * `isFilterFieldSelectable` for a chrome that separates the two.\n */\nexport function isFilterFieldPickable<V, O>(field: FilterField<V, O>): boolean {\n if (field.disabled) return false;\n return !isFilterBranch(field);\n}\n\n/** Trailing count for a branch row. */\nexport function getFilterFieldCount<V, O>(field: FilterField<V, O>): number {\n return field.count ?? field.fields?.length ?? 0;\n}\n\n/** Renders a path as \"Name > First\" using the caller's separator. */\nexport function formatFilterPath<V, O>(\n index: FilterIndex<V, O>,\n path: readonly string[],\n separator: string,\n): string {\n const chain = getFilterFieldChain(index, path);\n if (chain.length === 0) return path.join(separator);\n return chain.map((field) => field.label).join(separator);\n}\n\n/** How a path is shortened; the cascader's own union, so the two cannot drift. */\nexport type FilterPathCollapse = CascaderCollapse;\n\nexport type FilterPathSegment<V = unknown, O = unknown> =\n | { type: \"field\"; field: FilterField<V, O> }\n /** The run that was elided, kept so a host can surface it. */\n | { type: \"ellipsis\"; hidden: FilterField<V, O>[] };\n\n/**\n * Shortens an ancestor chain to at most `maxSegments` names, on the cascader's\n * arithmetic so the chip's path and the builder's attribute cell cannot round\n * differently. The adapter is POSITIONAL because a `FilterField`'s `id` is\n * unique only among its siblings, so the index is the only key that survives a\n * collapser keyed on `value`. Default `\"none\"`: no upgrade shortens a path.\n */\nexport function collapseFilterPath<V, O>(\n chain: readonly FilterField<V, O>[],\n options: { maxSegments?: number; collapse?: FilterPathCollapse } = {},\n): FilterPathSegment<V, O>[] {\n const segments = collapseCascaderPath(\n chain.map((field, index) => ({ value: String(index), label: field.label })),\n { maxSegments: options.maxSegments, collapse: options.collapse ?? \"none\" },\n );\n return segments.map((segment) =>\n segment.type === \"node\"\n ? { type: \"field\" as const, field: chain[Number(segment.node.value)] }\n : {\n type: \"ellipsis\" as const,\n hidden: segment.hidden.map((node) => chain[Number(node.value)]),\n },\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Combinator */\n/* -------------------------------------------------------------------------- */\n\nexport type FilterCombinatorSlot = \"where\" | \"toggle\" | \"echo\";\n\n/**\n * Which of the three forms the combinator slot before rule `index` takes. A\n * group has exactly ONE combinator, so only one slot may be interactive: three\n * editable \"and\"s down a column would imply three independent choices.\n */\nexport function filterCombinatorSlot(index: number): FilterCombinatorSlot {\n if (index === 0) return \"where\";\n return index === 1 ? \"toggle\" : \"echo\";\n}\n\n/* -------------------------------------------------------------------------- */\n/* Matching */\n/* -------------------------------------------------------------------------- */\n\n/** `toLocaleLowerCase`, so Turkish dotted and dotless i fold as a reader expects. */\nexport function foldFilterText(text: string): string {\n return text.toLocaleLowerCase();\n}\n\nexport function normalizeFilterQuery(query: string): string {\n return foldFilterText(query.trim());\n}\n\n/** Whether a field matches a normalized query, by label or keywords. */\nexport function matchesFilterQuery<V, O>(\n field: FilterField<V, O>,\n normalizedQuery: string,\n): boolean {\n if (normalizedQuery === \"\") return true;\n if (foldFilterText(field.label).includes(normalizedQuery)) return true;\n if (field.keywords) {\n for (const keyword of field.keywords) {\n if (foldFilterText(keyword).includes(normalizedQuery)) return true;\n }\n }\n return false;\n}\n\n/**\n * Filters one level, preserving input order. Unused here like\n * `searchFilterDeep`: kept so a consumer's own picker need not re-implement the\n * fold and the keyword matching.\n */\nexport function filterFilterLevel<V, O>(\n fields: readonly FilterField<V, O>[],\n normalizedQuery: string,\n): FilterField<V, O>[] {\n if (normalizedQuery === \"\") return fields as FilterField<V, O>[];\n return fields.filter((field) => matchesFilterQuery(field, normalizedQuery));\n}\n\n/**\n * Searches every SELECTABLE field at any depth, because a result the user\n * cannot pick is a dead end. Unused here - the shipped picker is the cascader\n * and delegates deep search to it - but it keeps a consumer's own picker from\n * re-implementing the fold, the keyword matching and the selectable rule.\n */\nexport function searchFilterDeep<V, O>(\n index: FilterIndex<V, O>,\n normalizedQuery: string,\n limit = 200,\n): { field: FilterField<V, O>; path: string[] }[] {\n if (normalizedQuery === \"\") return [];\n const results: { field: FilterField<V, O>; path: string[] }[] = [];\n for (const entry of index.all) {\n if (results.length >= limit) break;\n if (!isFilterFieldSelectable(entry.field)) continue;\n if (matchesFilterQuery(entry.field, normalizedQuery)) results.push(entry);\n }\n return results;\n}\n\n/** Filters an option list by a normalized query, by label or keywords. */\nexport function filterFilterOptions<O>(\n options: readonly FilterOption<O>[],\n normalizedQuery: string,\n): FilterOption<O>[] {\n if (normalizedQuery === \"\") return options as FilterOption<O>[];\n return options.filter((option) => {\n if (foldFilterText(option.label).includes(normalizedQuery)) return true;\n if (option.keywords) {\n for (const keyword of option.keywords) {\n if (foldFilterText(keyword).includes(normalizedQuery)) return true;\n }\n }\n return false;\n });\n}\n\n/* -------------------------------------------------------------------------- */\n/* Exclusive options */\n/* -------------------------------------------------------------------------- */\n\n/**\n * The None rule, as pure algebra over two selections: pick the `exclusive`\n * option and it is the only pick, pick anything else and it goes. Written\n * against the DELTA, not the result, which is what makes it total: an empty\n * delta is a removal, including UNTICKING the exclusive row; an exclusive\n * arrival is the whole answer; an ordinary arrival drops every exclusive value,\n * restored ones included; both at once gives it to the LAST exclusive.\n * `isExclusive` is a lookup, not an array, because a query hiding the None row\n * while it stays SELECTED would answer \"not exclusive\" for the value the click\n * must clear. Never applied on read - a saved view is the consumer's data - so\n * it heals on the first ordinary pick, and only while `isExclusive` can ANSWER:\n * a None row on a `loadOptions` field belongs in the static `options`.\n */\nexport function applyFilterExclusiveSelection(\n next: readonly string[],\n previous: readonly string[],\n isExclusive: (value: string) => boolean,\n): string[] {\n const held = new Set(previous);\n const added = next.filter((value) => !held.has(value));\n if (added.length === 0) return next as string[];\n\n let arrived: string | null = null;\n for (const value of added) {\n if (isExclusive(value)) arrived = value;\n }\n if (arrived !== null) return [arrived];\n\n const kept = next.filter((value) => !isExclusive(value));\n // The same array when nothing was exclusive, which is nearly every call: a\n // fresh one would commit a new value on every toggle of an ordinary row.\n return kept.length === next.length ? (next as string[]) : kept;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Ids */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Builds a deterministic id generator. `Date.now()` and `Math.random()`, as the\n * old `createFilter` used, give the server and the client different ids for the\n * same query, so any page shipping default filters hydrated mismatched.\n */\nexport function createFilterIdFactory(seed: string): () => string {\n let counter = 0;\n return () => {\n counter += 1;\n return `${seed}${counter}`;\n };\n}\n\n/* -------------------------------------------------------------------------- */\n/* Development checks */\n/* -------------------------------------------------------------------------- */\n\nconst warned = new Set<string>();\n\n/** Warns once per key. Never throws, and is a no-op in production. */\nexport function warnFilterOnce(key: string, message: string): void {\n if (process.env.NODE_ENV === \"production\") return;\n if (warned.has(key)) return;\n warned.add(key);\n console.warn(`[filters] ${message}`);\n}\n\n/** Clears the warn-once memory. For tests. */\nexport function resetFilterWarnings(): void {\n warned.clear();\n}\n\nexport interface FilterSchemaIssues {\n /** Ids that are empty, or that collide with a sibling. */\n duplicatePaths: string[];\n emptyIds: string[];\n /** Branches that declare `selectable` but hold no children. */\n emptyBranches: string[];\n /** Fields whose `defaultOperator` is not in their operator list. */\n unknownDefaultOperators: string[];\n}\n\n/** Reported, never thrown: a bad schema must degrade, not blank the page. */\nexport function findFilterSchemaIssues<V, O>(\n fields: readonly FilterField<V, O>[],\n resolveOperators: (field: FilterField<V, O>) => FilterOperator[],\n): FilterSchemaIssues {\n const duplicatePaths: string[] = [];\n const emptyIds: string[] = [];\n const emptyBranches: string[] = [];\n const unknownDefaultOperators: string[] = [];\n\n const walk = (list: readonly FilterField<V, O>[], parentPath: string[]) => {\n const seen = new Set<string>();\n for (const field of list) {\n const label = [...parentPath, field.id].join(\".\");\n if (!field.id) emptyIds.push(label);\n else if (seen.has(field.id)) duplicatePaths.push(label);\n seen.add(field.id);\n\n if (field.selectable && field.fields && field.fields.length === 0) {\n emptyBranches.push(label);\n }\n\n if (field.defaultOperator) {\n const operators = resolveOperators(field);\n if (!operators.some((op) => op.value === field.defaultOperator)) {\n unknownDefaultOperators.push(`${label} -> ${field.defaultOperator}`);\n }\n }\n\n if (field.fields?.length) walk(field.fields, [...parentPath, field.id]);\n }\n };\n\n walk(fields, []);\n return { duplicatePaths, emptyIds, emptyBranches, unknownDefaultOperators };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,MAAa,oBACX;;;;;;AAOF,MAAa,0BAA0B;;;;;;;;;AAUvC,MAAa,4BAA4B;;AAOzC,MAAa,kBAAkB;;AAG/B,MAAM,iBAAiB;AAEvB,SAAgB,eAAe,MAAiC;CAC9D,OAAO,KAAK,KAAK,cAAc;AACjC;AAEA,SAAgB,gBAAgB,KAAuB;CACrD,OAAO,QAAQ,KAAK,CAAC,IAAI,IAAI,MAAM,cAAc;AACnD;;AAGA,SAAgB,gBAAgB,MAAiC;CAC/D,OAAO,KAAK,UAAU,IAAI,kBAAkB,eAAe,KAAK,MAAM,GAAG,EAAE,CAAC;AAC9E;;;;;;;;;;AAeA,SAAgB,6BAAmC,QAA8C;CAC/F,MAAM,QAAkB,CAAC;CAEzB,MAAM,QAAQ,MAAoC,UAAkB;EAClE,KAAK,MAAM,SAAS,MAAM;GACxB,MAAM,KACJ,QACE,MACA,MAAM,KACN,OACC,MAAM,SAAS,MAChB,OACC,MAAM,QAAQ,MACf,OACC,MAAM,mBAAmB,MAC1B,OACC,MAAM,UAAU,MACjB,OACC,MAAM,aAAa,MAAM,QACzB,MAAM,WAAW,MAAM,QACvB,MAAM,OAAO,MAAM,QACnB,MAAM,cAAc,MAAM,QAC1B,MAAM,cAAc,MAAM,QAC1B,MAAM,gBAAgB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wB;AAC5E"}
@@ -0,0 +1,49 @@
1
+ import { FilterField, FilterOperator, FilterValueType } from "./filters-types.js";
2
+ //#region src/components/reui/filters/filters-operators.d.ts
3
+ /**
4
+ * Every operator label, keyed by value. Split from `FilterLabels`: operator
5
+ * wording is reworded per domain, chrome copy is translated once per app.
6
+ */
7
+ type FilterOperatorLabels = Record<string, string>;
8
+ declare const DEFAULT_FILTER_OPERATOR_LABELS: FilterOperatorLabels;
9
+ declare const DEFAULT_FILTER_VALUE_TYPE: FilterValueType;
10
+ /**
11
+ * Builds the operator catalog for one set of labels. Callers memoize on the
12
+ * label object: the old primitive built its equivalent inside
13
+ * `getOperatorsForField`, keyed on a `values` array that was fresh after every
14
+ * filter update, so every miss reallocated four arrays of 27 objects each.
15
+ */
16
+ declare function createFilterOperators(labels: FilterOperatorLabels): Record<FilterValueType, FilterOperator[]>;
17
+ declare const DEFAULT_FILTER_OPERATORS: Record<FilterValueType, FilterOperator[]>;
18
+ /**
19
+ * The operators for a field: its own `operators` wins, array or function,
20
+ * otherwise the catalog entry for its `type`. No implicit select to multiselect
21
+ * promotion by selection count: that changed the list as the user picked.
22
+ */
23
+ declare function resolveFilterOperators<V, O>(field: FilterField<V, O>, catalog?: Record<FilterValueType, FilterOperator[]>): FilterOperator[];
24
+ declare function visibleFilterOperators(operators: readonly FilterOperator[]): FilterOperator[];
25
+ declare function getFilterOperator(operators: readonly FilterOperator[], value: string | null | undefined): FilterOperator | undefined;
26
+ declare function getFilterArity(operator: FilterOperator | undefined): FilterOperator["arity"];
27
+ declare function operatorTakesValue(operator: FilterOperator | undefined): boolean;
28
+ /**
29
+ * The operator a field starts with: `defaultOperator` when it names one the
30
+ * field offers, otherwise the first visible operator. Falling back rather than
31
+ * trusting the schema keeps the rule out of a state its own list cannot show.
32
+ */
33
+ declare function getDefaultFilterOperator<V, O>(field: FilterField<V, O>, operators: readonly FilterOperator[]): string | null;
34
+ /**
35
+ * Negating a rule: swap to the declared `inverse` so the chip reads "does not
36
+ * contain", else toggle `negated` so Negate still works without an inverse.
37
+ */
38
+ declare function negateFilterOperator(operator: FilterOperator | undefined, operators: readonly FilterOperator[], negated: boolean | undefined): {
39
+ operator: string | null;
40
+ negated: boolean;
41
+ };
42
+ /**
43
+ * Reshapes a value when arity changes: widening "is" to "is any of" keeps what
44
+ * the user picked, narrowing keeps the first of them, `"none"` always drops it.
45
+ */
46
+ declare function coerceFilterValue(value: unknown, from: FilterOperator | undefined, to: FilterOperator | undefined): unknown;
47
+ //#endregion
48
+ export { DEFAULT_FILTER_OPERATORS, DEFAULT_FILTER_OPERATOR_LABELS, DEFAULT_FILTER_VALUE_TYPE, FilterOperatorLabels, coerceFilterValue, createFilterOperators, getDefaultFilterOperator, getFilterArity, getFilterOperator, negateFilterOperator, operatorTakesValue, resolveFilterOperators, visibleFilterOperators };
49
+ //# sourceMappingURL=filters-operators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters-operators.d.ts","names":[],"sources":["../../../../src/components/reui/filters/filters-operators.tsx"],"mappings":";;;;;;KAQY,uBAAuB;cAEtB,gCAAgC;cAyFhC,2BAA2B;;;;;;;iBAQxB,sBACd,QAAQ,uBACP,OAAO,iBAAiB;cAad,0BAA0B,OAAO,iBAAiB;;;;;;iBAQ/C,uBAAuB,GAAG,GACxC,OAAO,YAAY,GAAG,IACtB,UAAS,OAAO,iBAAiB,oBAChC;iBAMa,uBAAuB,oBAAoB,mBAAmB;iBAI9D,kBACd,oBAAoB,kBACpB,mCACC;iBAKa,eAAe,UAAU,6BAA6B;iBAItD,mBAAmB,UAAU;;;;;;iBAS7B,yBAAyB,GAAG,GAC1C,OAAO,YAAY,GAAG,IACtB,oBAAoB;;;;;iBAcN,qBACd,UAAU,4BACV,oBAAoB,kBACpB;EACG;EAAyB;;;;;;iBAYd,kBACd,gBACA,MAAM,4BACN,IAAI"}