@kumix/ui 0.3.6 → 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 (305) 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/agents/ai-sidebar.d.ts +17 -1
  5. package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
  6. package/dist/components/agents/ai-sidebar.js +90 -14
  7. package/dist/components/agents/ai-sidebar.js.map +1 -1
  8. package/dist/components/agents/chat-app.d.ts +10 -5
  9. package/dist/components/agents/chat-app.d.ts.map +1 -1
  10. package/dist/components/agents/chat-app.js +54 -5
  11. package/dist/components/agents/chat-app.js.map +1 -1
  12. package/dist/components/agents/citations.d.ts.map +1 -1
  13. package/dist/components/agents/citations.js +5 -6
  14. package/dist/components/agents/citations.js.map +1 -1
  15. package/dist/components/agents/tool-approval.d.ts.map +1 -1
  16. package/dist/components/agents/tool-approval.js +1 -1
  17. package/dist/components/agents/tool-approval.js.map +1 -1
  18. package/dist/components/motion/action-swap.d.ts.map +1 -1
  19. package/dist/components/motion/action-swap.js +2 -2
  20. package/dist/components/motion/action-swap.js.map +1 -1
  21. package/dist/components/motion/animated-sidebar.d.ts.map +1 -1
  22. package/dist/components/motion/animated-sidebar.js +13 -3
  23. package/dist/components/motion/animated-sidebar.js.map +1 -1
  24. package/dist/components/motion/attachment-upload.d.ts.map +1 -1
  25. package/dist/components/motion/attachment-upload.js +9 -5
  26. package/dist/components/motion/attachment-upload.js.map +1 -1
  27. package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
  28. package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
  29. package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
  30. package/dist/components/motion/availability-scheduler/day-row.js +18 -8
  31. package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
  32. package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
  33. package/dist/components/motion/availability-scheduler/index.js +27 -5
  34. package/dist/components/motion/availability-scheduler/index.js.map +1 -1
  35. package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
  36. package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
  37. package/dist/components/motion/availability-scheduler/time-select.js +3 -1
  38. package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
  39. package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
  40. package/dist/components/motion/bottom-sheet.js +78 -74
  41. package/dist/components/motion/bottom-sheet.js.map +1 -1
  42. package/dist/components/motion/center-morph-modal.d.ts.map +1 -1
  43. package/dist/components/motion/center-morph-modal.js +82 -88
  44. package/dist/components/motion/center-morph-modal.js.map +1 -1
  45. package/dist/components/motion/command-palette.d.ts.map +1 -1
  46. package/dist/components/motion/command-palette.js +51 -27
  47. package/dist/components/motion/command-palette.js.map +1 -1
  48. package/dist/components/motion/context-menu.d.ts.map +1 -1
  49. package/dist/components/motion/context-menu.js +16 -6
  50. package/dist/components/motion/context-menu.js.map +1 -1
  51. package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
  52. package/dist/components/motion/cylinder-carousel.js +4 -3
  53. package/dist/components/motion/cylinder-carousel.js.map +1 -1
  54. package/dist/components/motion/drawer.d.ts.map +1 -1
  55. package/dist/components/motion/drawer.js +30 -30
  56. package/dist/components/motion/drawer.js.map +1 -1
  57. package/dist/components/motion/expandable-action-bar.d.ts +6 -0
  58. package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
  59. package/dist/components/motion/expandable-action-bar.js +38 -9
  60. package/dist/components/motion/expandable-action-bar.js.map +1 -1
  61. package/dist/components/motion/hold-action-button.d.ts +1 -1
  62. package/dist/components/motion/hold-action-button.d.ts.map +1 -1
  63. package/dist/components/motion/hold-action-button.js +64 -50
  64. package/dist/components/motion/hold-action-button.js.map +1 -1
  65. package/dist/components/motion/loader.js +20 -22
  66. package/dist/components/motion/loader.js.map +1 -1
  67. package/dist/components/motion/morphing-modal.d.ts.map +1 -1
  68. package/dist/components/motion/morphing-modal.js +83 -83
  69. package/dist/components/motion/morphing-modal.js.map +1 -1
  70. package/dist/components/motion/morphing-search.d.ts +28 -0
  71. package/dist/components/motion/morphing-search.d.ts.map +1 -0
  72. package/dist/components/motion/morphing-search.js +418 -0
  73. package/dist/components/motion/morphing-search.js.map +1 -0
  74. package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
  75. package/dist/components/motion/morphing-tabs.js +59 -18
  76. package/dist/components/motion/morphing-tabs.js.map +1 -1
  77. package/dist/components/motion/notification-stack.d.ts.map +1 -1
  78. package/dist/components/motion/notification-stack.js +28 -11
  79. package/dist/components/motion/notification-stack.js.map +1 -1
  80. package/dist/components/motion/popover-morph.d.ts.map +1 -1
  81. package/dist/components/motion/popover-morph.js +26 -11
  82. package/dist/components/motion/popover-morph.js.map +1 -1
  83. package/dist/components/motion/popover.d.ts.map +1 -1
  84. package/dist/components/motion/popover.js +39 -28
  85. package/dist/components/motion/popover.js.map +1 -1
  86. package/dist/components/motion/preview-rail.d.ts.map +1 -1
  87. package/dist/components/motion/preview-rail.js +42 -13
  88. package/dist/components/motion/preview-rail.js.map +1 -1
  89. package/dist/components/motion/project-folder.js +20 -20
  90. package/dist/components/motion/project-folder.js.map +1 -1
  91. package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
  92. package/dist/components/motion/pull-to-refresh.js +8 -7
  93. package/dist/components/motion/pull-to-refresh.js.map +1 -1
  94. package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
  95. package/dist/components/motion/range-slider-bubble.js +2 -1
  96. package/dist/components/motion/range-slider-bubble.js.map +1 -1
  97. package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
  98. package/dist/components/motion/range-slider-fluid.js +2 -1
  99. package/dist/components/motion/range-slider-fluid.js.map +1 -1
  100. package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
  101. package/dist/components/motion/range-slider-ruler.js +2 -1
  102. package/dist/components/motion/range-slider-ruler.js.map +1 -1
  103. package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
  104. package/dist/components/motion/range-slider-wave.js +2 -1
  105. package/dist/components/motion/range-slider-wave.js.map +1 -1
  106. package/dist/components/motion/range-slider.d.ts.map +1 -1
  107. package/dist/components/motion/range-slider.js +2 -1
  108. package/dist/components/motion/range-slider.js.map +1 -1
  109. package/dist/components/motion/select.d.ts +15 -1
  110. package/dist/components/motion/select.d.ts.map +1 -1
  111. package/dist/components/motion/select.js +15 -4
  112. package/dist/components/motion/select.js.map +1 -1
  113. package/dist/components/motion/slide-action-button.d.ts.map +1 -1
  114. package/dist/components/motion/slide-action-button.js +3 -2
  115. package/dist/components/motion/slide-action-button.js.map +1 -1
  116. package/dist/components/motion/swipeable-list.d.ts.map +1 -1
  117. package/dist/components/motion/swipeable-list.js +2 -1
  118. package/dist/components/motion/swipeable-list.js.map +1 -1
  119. package/dist/components/motion/table/index.d.ts.map +1 -1
  120. package/dist/components/motion/table/index.js +64 -6
  121. package/dist/components/motion/table/index.js.map +1 -1
  122. package/dist/components/motion/table/table-header.d.ts.map +1 -1
  123. package/dist/components/motion/table/table-header.js +3 -2
  124. package/dist/components/motion/table/table-header.js.map +1 -1
  125. package/dist/components/motion/text-reveal.d.ts.map +1 -1
  126. package/dist/components/motion/text-reveal.js +72 -48
  127. package/dist/components/motion/text-reveal.js.map +1 -1
  128. package/dist/components/motion/tooltip.d.ts.map +1 -1
  129. package/dist/components/motion/tooltip.js +35 -15
  130. package/dist/components/motion/tooltip.js.map +1 -1
  131. package/dist/components/motion/wheel-picker.d.ts.map +1 -1
  132. package/dist/components/motion/wheel-picker.js +4 -3
  133. package/dist/components/motion/wheel-picker.js.map +1 -1
  134. package/dist/components/reui/badge.d.ts +1 -1
  135. package/dist/components/reui/cascader/cascader-async.d.ts +90 -0
  136. package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -0
  137. package/dist/components/reui/cascader/cascader-async.js +549 -0
  138. package/dist/components/reui/cascader/cascader-async.js.map +1 -0
  139. package/dist/components/reui/cascader/cascader-columns.d.ts +29 -0
  140. package/dist/components/reui/cascader/cascader-columns.d.ts.map +1 -0
  141. package/dist/components/reui/cascader/cascader-columns.js +135 -0
  142. package/dist/components/reui/cascader/cascader-columns.js.map +1 -0
  143. package/dist/components/reui/cascader/cascader-context.d.ts +193 -0
  144. package/dist/components/reui/cascader/cascader-context.d.ts.map +1 -0
  145. package/dist/components/reui/cascader/cascader-context.js +59 -0
  146. package/dist/components/reui/cascader/cascader-context.js.map +1 -0
  147. package/dist/components/reui/cascader/cascader-footer.d.ts +85 -0
  148. package/dist/components/reui/cascader/cascader-footer.d.ts.map +1 -0
  149. package/dist/components/reui/cascader/cascader-footer.js +456 -0
  150. package/dist/components/reui/cascader/cascader-footer.js.map +1 -0
  151. package/dist/components/reui/cascader/cascader-i18n.d.ts +17 -0
  152. package/dist/components/reui/cascader/cascader-i18n.d.ts.map +1 -0
  153. package/dist/components/reui/cascader/cascader-i18n.js +68 -0
  154. package/dist/components/reui/cascader/cascader-i18n.js.map +1 -0
  155. package/dist/components/reui/cascader/cascader-item.d.ts +115 -0
  156. package/dist/components/reui/cascader/cascader-item.d.ts.map +1 -0
  157. package/dist/components/reui/cascader/cascader-item.js +530 -0
  158. package/dist/components/reui/cascader/cascader-item.js.map +1 -0
  159. package/dist/components/reui/cascader/cascader-lib.d.ts +141 -0
  160. package/dist/components/reui/cascader/cascader-lib.d.ts.map +1 -0
  161. package/dist/components/reui/cascader/cascader-lib.js +576 -0
  162. package/dist/components/reui/cascader/cascader-lib.js.map +1 -0
  163. package/dist/components/reui/cascader/cascader-nav.d.ts +59 -0
  164. package/dist/components/reui/cascader/cascader-nav.d.ts.map +1 -0
  165. package/dist/components/reui/cascader/cascader-nav.js +312 -0
  166. package/dist/components/reui/cascader/cascader-nav.js.map +1 -0
  167. package/dist/components/reui/cascader/cascader-types.d.ts +2 -0
  168. package/dist/components/reui/cascader/cascader-types.js +2 -0
  169. package/dist/components/reui/cascader/cascader-virtual.d.ts +65 -0
  170. package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -0
  171. package/dist/components/reui/cascader/cascader-virtual.js +240 -0
  172. package/dist/components/reui/cascader/cascader-virtual.js.map +1 -0
  173. package/dist/components/reui/cascader/cascader.d.ts +322 -0
  174. package/dist/components/reui/cascader/cascader.d.ts.map +1 -0
  175. package/dist/components/reui/cascader/cascader.js +1459 -0
  176. package/dist/components/reui/cascader/cascader.js.map +1 -0
  177. package/dist/components/reui/event-calendar/event-calendar-event.d.ts +28 -47
  178. package/dist/components/reui/event-calendar/event-calendar-event.d.ts.map +1 -1
  179. package/dist/components/reui/event-calendar/event-calendar-event.js +26 -44
  180. package/dist/components/reui/event-calendar/event-calendar-event.js.map +1 -1
  181. package/dist/components/reui/event-calendar/event-calendar-nav.js +1 -1
  182. package/dist/components/reui/event-calendar/event-calendar-types.d.ts +19 -57
  183. package/dist/components/reui/event-calendar/event-calendar-types.d.ts.map +1 -1
  184. package/dist/components/reui/filters/filters-advanced.d.ts +52 -0
  185. package/dist/components/reui/filters/filters-advanced.d.ts.map +1 -0
  186. package/dist/components/reui/filters/filters-advanced.js +1191 -0
  187. package/dist/components/reui/filters/filters-advanced.js.map +1 -0
  188. package/dist/components/reui/filters/filters-builder.d.ts +43 -0
  189. package/dist/components/reui/filters/filters-builder.d.ts.map +1 -0
  190. package/dist/components/reui/filters/filters-builder.js +152 -0
  191. package/dist/components/reui/filters/filters-builder.js.map +1 -0
  192. package/dist/components/reui/filters/filters-chip.d.ts +79 -0
  193. package/dist/components/reui/filters/filters-chip.d.ts.map +1 -0
  194. package/dist/components/reui/filters/filters-chip.js +553 -0
  195. package/dist/components/reui/filters/filters-chip.js.map +1 -0
  196. package/dist/components/reui/filters/filters-context.d.ts +290 -0
  197. package/dist/components/reui/filters/filters-context.d.ts.map +1 -0
  198. package/dist/components/reui/filters/filters-context.js +277 -0
  199. package/dist/components/reui/filters/filters-context.js.map +1 -0
  200. package/dist/components/reui/filters/filters-date.d.ts +43 -0
  201. package/dist/components/reui/filters/filters-date.d.ts.map +1 -0
  202. package/dist/components/reui/filters/filters-date.js +143 -0
  203. package/dist/components/reui/filters/filters-date.js.map +1 -0
  204. package/dist/components/reui/filters/filters-dnd.d.ts +101 -0
  205. package/dist/components/reui/filters/filters-dnd.d.ts.map +1 -0
  206. package/dist/components/reui/filters/filters-dnd.js +454 -0
  207. package/dist/components/reui/filters/filters-dnd.js.map +1 -0
  208. package/dist/components/reui/filters/filters-draft.d.ts +2 -0
  209. package/dist/components/reui/filters/filters-draft.js +128 -0
  210. package/dist/components/reui/filters/filters-draft.js.map +1 -0
  211. package/dist/components/reui/filters/filters-editors.d.ts +91 -0
  212. package/dist/components/reui/filters/filters-editors.d.ts.map +1 -0
  213. package/dist/components/reui/filters/filters-editors.js +773 -0
  214. package/dist/components/reui/filters/filters-editors.js.map +1 -0
  215. package/dist/components/reui/filters/filters-i18n.d.ts +24 -0
  216. package/dist/components/reui/filters/filters-i18n.d.ts.map +1 -0
  217. package/dist/components/reui/filters/filters-i18n.js +127 -0
  218. package/dist/components/reui/filters/filters-i18n.js.map +1 -0
  219. package/dist/components/reui/filters/filters-lib.d.ts +171 -0
  220. package/dist/components/reui/filters/filters-lib.d.ts.map +1 -0
  221. package/dist/components/reui/filters/filters-lib.js +336 -0
  222. package/dist/components/reui/filters/filters-lib.js.map +1 -0
  223. package/dist/components/reui/filters/filters-operators.d.ts +49 -0
  224. package/dist/components/reui/filters/filters-operators.d.ts.map +1 -0
  225. package/dist/components/reui/filters/filters-operators.js +300 -0
  226. package/dist/components/reui/filters/filters-operators.js.map +1 -0
  227. package/dist/components/reui/filters/filters-query.d.ts +132 -0
  228. package/dist/components/reui/filters/filters-query.d.ts.map +1 -0
  229. package/dist/components/reui/filters/filters-query.js +476 -0
  230. package/dist/components/reui/filters/filters-query.js.map +1 -0
  231. package/dist/components/reui/filters/filters-types.d.ts +452 -0
  232. package/dist/components/reui/filters/filters-types.d.ts.map +1 -0
  233. package/dist/components/reui/filters/filters-types.js +2 -0
  234. package/dist/components/reui/filters/filters.d.ts +114 -0
  235. package/dist/components/reui/filters/filters.d.ts.map +1 -0
  236. package/dist/components/reui/filters/filters.js +638 -0
  237. package/dist/components/reui/filters/filters.js.map +1 -0
  238. package/dist/components/reui/frame.d.ts +1 -1
  239. package/dist/components/reui/gantt/gantt-bar.js +1 -1
  240. package/dist/components/reui/gantt/gantt-nav.js +1 -1
  241. package/dist/components/reui/gantt/gantt-types.d.ts +25 -71
  242. package/dist/components/reui/gantt/gantt-types.d.ts.map +1 -1
  243. package/dist/components/reui/gantt/gantt-view.js +1 -1
  244. package/dist/components/reui/icon-tile.d.ts +1 -1
  245. package/dist/components/ui/badge.d.ts +1 -1
  246. package/dist/components/ui/bubble.d.ts +1 -1
  247. package/dist/components/ui/button.d.ts +2 -2
  248. package/dist/components/ui/checkbox.js +1 -1
  249. package/dist/components/ui/checkbox.js.map +1 -1
  250. package/dist/components/ui/field.js +2 -2
  251. package/dist/components/ui/field.js.map +1 -1
  252. package/dist/components/ui/item.d.ts +2 -2
  253. package/dist/components/ui/marker.d.ts +1 -1
  254. package/dist/components/ui/radio-group.js +1 -1
  255. package/dist/components/ui/radio-group.js.map +1 -1
  256. package/dist/components/ui/sidebar.d.ts +1 -1
  257. package/dist/components/ui/sidebar.js +1 -1
  258. package/dist/components/ui/switch.js +1 -1
  259. package/dist/components/ui/switch.js.map +1 -1
  260. package/dist/components/ui/tabs.d.ts +1 -1
  261. package/dist/components/ui/toggle.d.ts +1 -1
  262. package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
  263. package/dist/copy-menu-1FKoMc9o.js.map +1 -0
  264. package/dist/filters-draft-DEAl3TO-.d.ts +70 -0
  265. package/dist/filters-draft-DEAl3TO-.d.ts.map +1 -0
  266. package/dist/hooks/use-dismiss.d.ts +34 -0
  267. package/dist/hooks/use-dismiss.d.ts.map +1 -0
  268. package/dist/hooks/use-dismiss.js +78 -0
  269. package/dist/hooks/use-dismiss.js.map +1 -0
  270. package/dist/hooks/use-favicon.d.ts +17 -0
  271. package/dist/hooks/use-favicon.d.ts.map +1 -0
  272. package/dist/hooks/use-favicon.js +35 -0
  273. package/dist/hooks/use-favicon.js.map +1 -0
  274. package/dist/hooks/use-hover-gesture.d.ts +38 -0
  275. package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
  276. package/dist/hooks/use-hover-gesture.js +46 -0
  277. package/dist/hooks/use-hover-gesture.js.map +1 -0
  278. package/dist/hooks/use-slider.d.ts.map +1 -1
  279. package/dist/hooks/use-slider.js +3 -2
  280. package/dist/hooks/use-slider.js.map +1 -1
  281. package/dist/hooks/use-tap-gesture.d.ts +47 -0
  282. package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
  283. package/dist/hooks/use-tap-gesture.js +51 -0
  284. package/dist/hooks/use-tap-gesture.js.map +1 -0
  285. package/dist/hooks/use-touch-capable.d.ts +15 -0
  286. package/dist/hooks/use-touch-capable.d.ts.map +1 -0
  287. package/dist/hooks/use-touch-capable.js +29 -0
  288. package/dist/hooks/use-touch-capable.js.map +1 -0
  289. package/dist/lib/text-shimmer.d.ts +2 -2
  290. package/dist/lib/text-shimmer.d.ts.map +1 -1
  291. package/dist/lib/text-shimmer.js +2 -2
  292. package/dist/lib/text-shimmer.js.map +1 -1
  293. package/dist/lib/touch.d.ts +66 -0
  294. package/dist/lib/touch.d.ts.map +1 -0
  295. package/dist/lib/touch.js +79 -0
  296. package/dist/lib/touch.js.map +1 -0
  297. package/dist/presence-gate-BekdC4Bo.js +24 -0
  298. package/dist/presence-gate-BekdC4Bo.js.map +1 -0
  299. package/dist/types-smkWN_7x.d.ts.map +1 -1
  300. package/package.json +9 -9
  301. package/dist/components/reui/filters.d.ts +0 -176
  302. package/dist/components/reui/filters.d.ts.map +0 -1
  303. package/dist/components/reui/filters.js +0 -1223
  304. package/dist/components/reui/filters.js.map +0 -1
  305. package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
@@ -0,0 +1,277 @@
1
+ "use client";
2
+ import * as React$1 from "react";
3
+ //#region src/components/reui/filters/filters-context.tsx
4
+ /** `disabled` and `readOnly` are NOT two words for one state. `disabled` is
5
+ * the native attribute: not operable, out of the tab order. `readOnly` blocks
6
+ * MUTATION and preserves NAVIGATION, because a read-only bar exists so a
7
+ * keyboard or screen reader user can walk the chips and find out what the
8
+ * view is filtered by. Collapsing the two once put the native attribute on
9
+ * all thirteen advanced-builder cell controls while the roving tab stop sat
10
+ * on a disabled element, so not one row could be reached from the keyboard.
11
+ *
12
+ * So a mutating control keeps its tab stop and wears `aria-disabled` plus
13
+ * `data-readonly` (`filterReadOnlyProps`), this repo's convention for
14
+ * "present, focusable, not operable". `aria-readonly` is never used, being
15
+ * disallowed on the button, group and toolbar roles, so the BAR says it in
16
+ * prose through `labels.readOnly`. The refusal itself is enforced once, where
17
+ * all fourteen query writes pass through `emit` in `filters.tsx`. */
18
+ function isFilterLocked(state) {
19
+ return state.disabled || state.readOnly;
20
+ }
21
+ /** What a MUTATING control wears while the bar is read only. `null` when the
22
+ * bar is disabled, because the native attribute already says it. A
23
+ * conditional spread, not explicit `undefined`s: `aria-disabled="false"` on
24
+ * an enabled control is noise, and `data-readonly` is a presence hook. */
25
+ function filterReadOnlyProps(state) {
26
+ if (state.disabled || !state.readOnly) return null;
27
+ return {
28
+ "aria-disabled": true,
29
+ "data-readonly": ""
30
+ };
31
+ }
32
+ /** ONE ladder, keyed off `size`, for every control the chrome renders, because
33
+ * the alternative already happened: five advanced-builder cells took
34
+ * `actions.size` while seven sites hardcoded `icon-sm` and three `sm`, giving
35
+ * one row three heights. Nothing here is a pixel - each value is a shadcn
36
+ * size NAME that `Button` resolves per style, since the control-height ladder
37
+ * is per style (nova 7/8, sera 9/10, mira 6/7, and so on), and the glyph size
38
+ * rides the same name, so pinning an icon size in here would fight the style
39
+ * rather than match it. Two rungs only: `lg` would make the bar taller than
40
+ * the style's own default control height (want taller, pick a taller STYLE),
41
+ * and `icon-xs` is a 20-24px square in most styles, too small for a chip's
42
+ * own label to clear. */
43
+ const FILTER_CONTROL_SIZES = {
44
+ sm: {
45
+ button: "sm",
46
+ icon: "icon-sm"
47
+ },
48
+ default: {
49
+ button: "default",
50
+ icon: "icon"
51
+ }
52
+ };
53
+ /** The pair for a bar's size, off anything with a `size`, so a
54
+ * consumer-composed chrome uses the same ladder as the shipped one. The
55
+ * fallback is for JavaScript callers: a `"lg"` TypeScript would have rejected
56
+ * must still draw buttons rather than throw on `.button`. */
57
+ function filterControlSizes(state) {
58
+ return FILTER_CONTROL_SIZES[state.size] ?? FILTER_CONTROL_SIZES.default;
59
+ }
60
+ const FilterActionsContext = React$1.createContext(null);
61
+ function useFilterActions() {
62
+ const context = React$1.useContext(FilterActionsContext);
63
+ if (!context) throw new Error("useFilterActions must be used inside <Filters>");
64
+ return context;
65
+ }
66
+ const FilterStateContext = React$1.createContext(null);
67
+ function useFilterState() {
68
+ const context = React$1.useContext(FilterStateContext);
69
+ if (!context) throw new Error("useFilterState must be used inside <Filters>");
70
+ return context;
71
+ }
72
+ const FilterRenderContext = React$1.createContext({});
73
+ function useFilterRender() {
74
+ return React$1.useContext(FilterRenderContext);
75
+ }
76
+ const NO_FOCUS = {
77
+ id: null,
78
+ segment: null,
79
+ autoOpen: false
80
+ };
81
+ function createFilterFocusStore() {
82
+ let snapshot = NO_FOCUS;
83
+ const listeners = /* @__PURE__ */ new Set();
84
+ return {
85
+ subscribe(onStoreChange) {
86
+ listeners.add(onStoreChange);
87
+ return () => {
88
+ listeners.delete(onStoreChange);
89
+ };
90
+ },
91
+ getSnapshot() {
92
+ return snapshot;
93
+ },
94
+ set(next) {
95
+ if (next.id === snapshot.id && next.segment === snapshot.segment && next.autoOpen === snapshot.autoOpen) return;
96
+ snapshot = next;
97
+ for (const listener of listeners) listener();
98
+ }
99
+ };
100
+ }
101
+ /** A shared, permanently empty store, so the hook degrades to "nothing
102
+ * focused" outside a `Filters`. Nothing ever writes to it: each root creates
103
+ * and writes its own. */
104
+ const FALLBACK_FOCUS_STORE = createFilterFocusStore();
105
+ const FilterFocusContext = React$1.createContext(FALLBACK_FOCUS_STORE);
106
+ /** Whether rows may be reordered at all, published once for the subtree. Two
107
+ * files have to agree about it: the builder gates the grip and Alt+Arrow,
108
+ * while the row and group menus commit the same mutator by a third route, so
109
+ * gating only the builder left it off for a pointer and on from a menu. */
110
+ const FilterReorderContext = React$1.createContext(false);
111
+ const FilterReorderProvider = FilterReorderContext.Provider;
112
+ function useFilterReorderable() {
113
+ return React$1.useContext(FilterReorderContext);
114
+ }
115
+ function createFilterRowStateStore() {
116
+ const touched = /* @__PURE__ */ new Set();
117
+ const pending = /* @__PURE__ */ new Set();
118
+ const listeners = /* @__PURE__ */ new Set();
119
+ let version = 0;
120
+ const notify = () => {
121
+ version += 1;
122
+ for (const listener of listeners) listener();
123
+ };
124
+ return {
125
+ subscribe: (listener) => {
126
+ listeners.add(listener);
127
+ return () => listeners.delete(listener);
128
+ },
129
+ version: () => version,
130
+ has: (id) => touched.has(id),
131
+ mark: (id) => {
132
+ if (touched.has(id)) return;
133
+ touched.add(id);
134
+ notify();
135
+ },
136
+ unmark: (id) => {
137
+ if (!touched.delete(id)) return;
138
+ notify();
139
+ },
140
+ isPending: (id) => pending.has(id),
141
+ markPending: (id) => {
142
+ if (pending.has(id)) return;
143
+ pending.add(id);
144
+ notify();
145
+ },
146
+ resolvePending: (id) => {
147
+ if (!pending.delete(id)) return;
148
+ notify();
149
+ },
150
+ reset: () => {
151
+ if (touched.size === 0 && pending.size === 0) return;
152
+ touched.clear();
153
+ pending.clear();
154
+ notify();
155
+ }
156
+ };
157
+ }
158
+ const FALLBACK_ROW_STATE_STORE = createFilterRowStateStore();
159
+ const FilterRowStateContext = React$1.createContext(FALLBACK_ROW_STATE_STORE);
160
+ const FilterRowStateProvider = FilterRowStateContext.Provider;
161
+ /** The store itself, for handlers that write without subscribing. */
162
+ function useFilterRowStateStore() {
163
+ return React$1.useContext(FilterRowStateContext);
164
+ }
165
+ /** Whether THIS rule is still waiting for its attribute. */
166
+ function useFilterRowPending(id) {
167
+ const store = React$1.useContext(FilterRowStateContext);
168
+ return React$1.useSyncExternalStore(store.subscribe, () => store.isPending(id), () => false);
169
+ }
170
+ /** Whether THIS rule may show an error yet. */
171
+ function useFilterTouched(id) {
172
+ const store = React$1.useContext(FilterRowStateContext);
173
+ return React$1.useSyncExternalStore(store.subscribe, () => store.has(id), () => false);
174
+ }
175
+ /** The whole focus snapshot, so the caller re-renders on EVERY move anywhere
176
+ * in the row. A chip wants `useFilterChipFocused` or `useFilterSegmentFocus`
177
+ * below instead. */
178
+ function useFilterFocus() {
179
+ const store = React$1.useContext(FilterFocusContext);
180
+ return React$1.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
181
+ }
182
+ /** The store itself, for event handlers that write without subscribing. */
183
+ function useFilterFocusStore() {
184
+ return React$1.useContext(FilterFocusContext);
185
+ }
186
+ /** The segment of THIS chip that should open itself, or null. */
187
+ function useFilterChipAutoOpen(id) {
188
+ const store = React$1.useContext(FilterFocusContext);
189
+ return React$1.useSyncExternalStore(store.subscribe, () => {
190
+ const snapshot = store.getSnapshot();
191
+ return snapshot.autoOpen && snapshot.id === id ? snapshot.segment : null;
192
+ }, () => null);
193
+ }
194
+ /** Whether the row holds no focus, so the first chip keeps the tab stop. */
195
+ function useFilterFocusEmpty() {
196
+ const store = React$1.useContext(FilterFocusContext);
197
+ return React$1.useSyncExternalStore(store.subscribe, () => store.getSnapshot().id === null, () => true);
198
+ }
199
+ /** Whether THIS chip owns the row's tab stop. */
200
+ function useFilterChipFocused(id) {
201
+ const store = React$1.useContext(FilterFocusContext);
202
+ return React$1.useSyncExternalStore(store.subscribe, () => store.getSnapshot().id === id, () => false);
203
+ }
204
+ /** Which segment of THIS rule owns the tab stop, or null when another rule
205
+ * does. A chip needs one boolean, but an advanced row is a grid ROW whose tab
206
+ * stop is a (row, column) pair, and the column has to come from this store
207
+ * too or the chromes disagree about where focus is after an edit. */
208
+ function useFilterSegmentFocus(id) {
209
+ const store = React$1.useContext(FilterFocusContext);
210
+ return React$1.useSyncExternalStore(store.subscribe, () => {
211
+ const snapshot = store.getSnapshot();
212
+ return snapshot.id === id ? snapshot.segment : null;
213
+ }, () => null);
214
+ }
215
+ function createFilterResolutionStore() {
216
+ const resolved = /* @__PURE__ */ new Map();
217
+ const claimed = /* @__PURE__ */ new Map();
218
+ const listeners = /* @__PURE__ */ new Set();
219
+ let version = 0;
220
+ const bucket = (fieldKey) => {
221
+ let map = resolved.get(fieldKey);
222
+ if (!map) {
223
+ map = /* @__PURE__ */ new Map();
224
+ resolved.set(fieldKey, map);
225
+ }
226
+ return map;
227
+ };
228
+ return {
229
+ subscribe(onStoreChange) {
230
+ listeners.add(onStoreChange);
231
+ return () => {
232
+ listeners.delete(onStoreChange);
233
+ };
234
+ },
235
+ getVersion() {
236
+ return version;
237
+ },
238
+ get(fieldKey, value) {
239
+ return resolved.get(fieldKey)?.get(value);
240
+ },
241
+ set(fieldKey, options) {
242
+ const map = bucket(fieldKey);
243
+ let landed = false;
244
+ for (const option of options) {
245
+ if (!map.has(option.value)) landed = true;
246
+ map.set(option.value, option);
247
+ }
248
+ if (!landed) return;
249
+ version += 1;
250
+ for (const listener of listeners) listener();
251
+ },
252
+ claim(fieldKey, values) {
253
+ let set = claimed.get(fieldKey);
254
+ if (!set) {
255
+ set = /* @__PURE__ */ new Set();
256
+ claimed.set(fieldKey, set);
257
+ }
258
+ const map = resolved.get(fieldKey);
259
+ const fresh = [];
260
+ for (const value of values) {
261
+ if (set.has(value) || map?.has(value)) continue;
262
+ set.add(value);
263
+ fresh.push(value);
264
+ }
265
+ return fresh;
266
+ },
267
+ release(fieldKey, values) {
268
+ const set = claimed.get(fieldKey);
269
+ if (!set) return;
270
+ for (const value of values) set.delete(value);
271
+ }
272
+ };
273
+ }
274
+ //#endregion
275
+ export { FilterActionsContext, FilterFocusContext, FilterRenderContext, FilterReorderProvider, FilterRowStateProvider, FilterStateContext, createFilterFocusStore, createFilterResolutionStore, createFilterRowStateStore, filterControlSizes, filterReadOnlyProps, isFilterLocked, useFilterActions, useFilterChipAutoOpen, useFilterChipFocused, useFilterFocus, useFilterFocusEmpty, useFilterFocusStore, useFilterRender, useFilterReorderable, useFilterRowPending, useFilterRowStateStore, useFilterSegmentFocus, useFilterState, useFilterTouched };
276
+
277
+ //# sourceMappingURL=filters-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters-context.js","names":["React"],"sources":["../../../../src/components/reui/filters/filters-context.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\n\nimport type { FilterDraftAction } from \"./filters-draft\";\nimport type { FilterPathCollapse } from \"./filters-lib\";\nimport type {\n FilterCombinator,\n FilterDraft,\n FilterDraftStep,\n FilterEditor,\n FilterEditorRegistry,\n FilterEmptyStateContext,\n FilterField,\n FilterIndex,\n FilterLabels,\n FilterOperator,\n FilterOption,\n FilterQuery,\n FilterRule,\n FilterValueDisplayContext,\n FilterValueType,\n} from \"./filters-types\";\n\n/** Four publishing channels, not one, so a chip never re-renders at the rate\n * of the fastest: `actions` republishes on a schema, labels or config change,\n * `state` on every query edit and keystroke, `render` on a `renderValue` /\n * `renderChip` identity change, `focus` on every arrow key. The reorder flag\n * and the row-state store further down are contexts too, but not channels the\n * query is published through. */\n\n/* -------------------------------------------------------------------------- */\n/* Actions */\n/* -------------------------------------------------------------------------- */\n\n/** Stable for the life of the component, bar a config change. Every mutator\n * reads a latest-props ref rather than closing over the state it needs, so a\n * keystroke rebuilds no handler and no memoized chip re-renders. The two lock\n * flags are published rather than kept only in that ref: a refusal that lives\n * in a ref arrives one commit late. The two resolvers are the deliberate\n * exception: they are read DURING render, so they memoize on the values they\n * read instead of going through the ref. Every mutator is also the MUTATION\n * BOUNDARY - `disabled` and `readOnly` are enforced here, not at the call\n * sites that draw the buttons, so a route added next month is refused by\n * construction rather than by remembering. See `isFilterLocked`. */\nexport interface FilterActionsContextValue<V = unknown, O = unknown> {\n /** Normalized schema. Also on the state context, from the same memo. */\n index: FilterIndex<V, O>;\n labels: FilterLabels;\n operatorCatalog: Record<FilterValueType, FilterOperator[]>;\n editors: FilterEditorRegistry;\n size: \"sm\" | \"default\";\n /** The bar is off: nothing operable, and the controls leave the tab order. */\n disabled: boolean;\n /** Readable and navigable, but not changeable. See `isFilterLocked`. */\n readOnly: boolean;\n\n /** Which chrome is drawing, so a chip kebab can hide its convert row. */\n variant: \"basic\" | \"advanced\";\n\n /** Consumer classes for the menus and the field picker, merged AFTER the\n * primitive's own defaults so a consumer `w-*` wins through tailwind-merge\n * rather than on source order. On the context: four chromes mount the same\n * menu, and a per-chrome prop is set in four places and missed in a fifth. */\n menuClassName: string | undefined;\n fieldPickerClassName: string | undefined;\n\n /** Turns on the chip kebab's \"Convert to advanced filter\" row: present means\n * offered. A callback with no boolean beside it, since only the consumer\n * can switch chromes. Changes no query, so it skips the mutation boundary,\n * which is safe only because it is handed no setter: a consumer's handler\n * has no route to the query at all. */\n convertToAdvanced: (() => void) | undefined;\n\n /** Path shortening, published so BOTH chromes render the same path. */\n pathCollapse: FilterPathCollapse;\n maxPathSegments: number;\n\n /** Operators for a field, memoized on the catalog and the schema. */\n resolveOperators: (field: FilterField<V, O>) => FilterOperator[];\n resolveEditor: (\n field: FilterField<V, O>,\n operator: FilterOperator | undefined,\n ) => FilterEditor<V, O> | undefined;\n /** Value-to-label store shared by every `useFilterOptions` under the root. */\n resolution: FilterResolutionStore;\n\n /** Appends a rule. Defaults to the ROOT group. The parent is a parameter\n * rather than always the root because a nested group's add button is the\n * keyboard path into that group, and routing it through the root then\n * moving it would be two edits and two announcements for one action. */\n addRule: (rule: FilterRule<V>, parentId?: string) => void;\n /** Appends an empty group and returns its id, so the caller can focus it.\n * Returns an EMPTY STRING when the bar is disabled or read only, the one\n * mutator that has to report its refusal: focusing a group that was never\n * created strands the tab stop. `\"\"` rather than `string | null` keeps the\n * callers that already test the id honest without widening a published\n * signature. */\n addGroup: (parentId?: string, combinator?: FilterCombinator) => string;\n updateRule: (id: string, updates: Partial<Omit<FilterRule<V>, \"id\" | \"type\">>) => void;\n /** Removes a rule OR a group, and prunes the groups that empties. Node-level\n * rather than rule-level because a chip only ever removes a rule, while a\n * builder row's trash and a group header's trash are the same button on two\n * kinds of node. */\n removeNode: (id: string) => void;\n duplicateNode: (id: string) => void;\n negateRule: (id: string) => void;\n /** Reorders within the node's own parent. Out of range moves are no-ops. */\n moveNode: (id: string, delta: number) => void;\n /** Moves a node into another group, at an index. The drag-and-drop half. */\n moveNodeTo: (id: string, parentId: string, index: number) => void;\n /** Copies a node into another group, at an index. The Alt-drag half, apart\n * from `duplicateNode` (which copies BESIDE, with no destination): the two\n * composed would emit two queries for one gesture, and a controlled\n * consumer would persist a tree the user never asked for. */\n copyNodeTo: (id: string, parentId: string, index: number) => void;\n /** Nests one node in a new group. The keyboard half of the same idea. */\n wrapNodeInGroup: (id: string, combinator?: FilterCombinator) => void;\n /** Dissolves a group into its parent. The inverse of `wrapNodeInGroup`. */\n unwrapGroup: (groupId: string) => void;\n setCombinator: (groupId: string, combinator: FilterCombinator) => void;\n toggleCombinator: (groupId: string) => void;\n clearQuery: () => void;\n\n openCreate: () => void;\n openAmend: (id: string, step: FilterDraftStep) => void;\n closeDraft: () => void;\n dispatchDraft: (action: FilterDraftAction<V>) => void;\n\n /** Writes the bar's live region, for a change no visible surface reports: an\n * editor's popover is the one place something destructive happens to rows\n * the user is not on, with focus, name and text unchanged afterwards. Not a\n * query write, so it skips `emit` and asks the lock nothing. */\n announce: (message: string) => void;\n\n /** Getters for event handlers, so a handler never closes over stale state. */\n getQuery: () => FilterQuery<V>;\n getDraft: () => FilterDraft<V> | null;\n /** Fresh id from the SSR-safe factory. */\n nextId: () => string;\n}\n\n/* -------------------------------------------------------------------------- */\n/* The mutation lock */\n/* -------------------------------------------------------------------------- */\n\n/** `disabled` and `readOnly` are NOT two words for one state. `disabled` is\n * the native attribute: not operable, out of the tab order. `readOnly` blocks\n * MUTATION and preserves NAVIGATION, because a read-only bar exists so a\n * keyboard or screen reader user can walk the chips and find out what the\n * view is filtered by. Collapsing the two once put the native attribute on\n * all thirteen advanced-builder cell controls while the roving tab stop sat\n * on a disabled element, so not one row could be reached from the keyboard.\n *\n * So a mutating control keeps its tab stop and wears `aria-disabled` plus\n * `data-readonly` (`filterReadOnlyProps`), this repo's convention for\n * \"present, focusable, not operable\". `aria-readonly` is never used, being\n * disallowed on the button, group and toolbar roles, so the BAR says it in\n * prose through `labels.readOnly`. The refusal itself is enforced once, where\n * all fourteen query writes pass through `emit` in `filters.tsx`. */\nexport function isFilterLocked(state: { disabled: boolean; readOnly: boolean }): boolean {\n return state.disabled || state.readOnly;\n}\n\n/** What a MUTATING control wears while the bar is read only. `null` when the\n * bar is disabled, because the native attribute already says it. A\n * conditional spread, not explicit `undefined`s: `aria-disabled=\"false\"` on\n * an enabled control is noise, and `data-readonly` is a presence hook. */\nexport function filterReadOnlyProps(state: { disabled: boolean; readOnly: boolean }) {\n if (state.disabled || !state.readOnly) return null;\n return { \"aria-disabled\": true, \"data-readonly\": \"\" } as const;\n}\n\n/* -------------------------------------------------------------------------- */\n/* The size ladder */\n/* -------------------------------------------------------------------------- */\n\n/** The two shadcn button sizes one filters size resolves to. Two rungs because\n * shadcn ships a separate ladder for labelled and for icon-only buttons, and\n * pairing them keeps a row's kebab as tall as the cell beside it. */\nexport interface FilterControlSizes {\n /** Labelled buttons: the row cells, both triggers, the panel footer. */\n button: \"sm\" | \"default\";\n /** Icon-only buttons, and also the CHIP's height: a chip is an\n * `items-stretch` `ButtonGroup` and no style gives its text segment a\n * height, so the segments stretch to the kebab, the one child that has one.\n * Sizing the kebab sizes the pill. */\n icon: \"icon-sm\" | \"icon\";\n}\n\n/** ONE ladder, keyed off `size`, for every control the chrome renders, because\n * the alternative already happened: five advanced-builder cells took\n * `actions.size` while seven sites hardcoded `icon-sm` and three `sm`, giving\n * one row three heights. Nothing here is a pixel - each value is a shadcn\n * size NAME that `Button` resolves per style, since the control-height ladder\n * is per style (nova 7/8, sera 9/10, mira 6/7, and so on), and the glyph size\n * rides the same name, so pinning an icon size in here would fight the style\n * rather than match it. Two rungs only: `lg` would make the bar taller than\n * the style's own default control height (want taller, pick a taller STYLE),\n * and `icon-xs` is a 20-24px square in most styles, too small for a chip's\n * own label to clear. */\nconst FILTER_CONTROL_SIZES: Record<\"sm\" | \"default\", FilterControlSizes> = {\n sm: { button: \"sm\", icon: \"icon-sm\" },\n default: { button: \"default\", icon: \"icon\" },\n};\n\n/** The pair for a bar's size, off anything with a `size`, so a\n * consumer-composed chrome uses the same ladder as the shipped one. The\n * fallback is for JavaScript callers: a `\"lg\"` TypeScript would have rejected\n * must still draw buttons rather than throw on `.button`. */\nexport function filterControlSizes(state: { size: \"sm\" | \"default\" }): FilterControlSizes {\n return FILTER_CONTROL_SIZES[state.size] ?? FILTER_CONTROL_SIZES.default;\n}\n\nconst FilterActionsContext = React.createContext<FilterActionsContextValue | null>(null);\n\nexport function useFilterActions<V = unknown, O = unknown>(): FilterActionsContextValue<V, O> {\n const context = React.useContext(FilterActionsContext);\n if (!context) {\n throw new Error(\"useFilterActions must be used inside <Filters>\");\n }\n return context as unknown as FilterActionsContextValue<V, O>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* State */\n/* -------------------------------------------------------------------------- */\n\n/** Volatile by construction: typing one character into a value editor\n * republishes it. Subscribe from the bar and the panel, never from a chip. */\nexport interface FilterStateContextValue<V = unknown> {\n query: FilterQuery<V>;\n draft: FilterDraft<V> | null;\n ruleCount: number;\n /** Live region text. Empty except immediately after an announced change. */\n announcement: string;\n /** How many announcements have been made, so a REPEATED one is still heard:\n * `aria-live` reports a DOM mutation and React writes nothing when the\n * string is unchanged, so the chrome keys the region's contents on this. A\n * counter rather than a timestamp: it is compared for identity, never read\n * as a value, and is stable across a rerender that a clock is not. */\n announcementSeq: number;\n}\n\nconst FilterStateContext = React.createContext<FilterStateContextValue | null>(null);\n\nexport function useFilterState<V = unknown>(): FilterStateContextValue<V> {\n const context = React.useContext(FilterStateContext);\n if (!context) {\n throw new Error(\"useFilterState must be used inside <Filters>\");\n }\n return context as unknown as FilterStateContextValue<V>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Render */\n/* -------------------------------------------------------------------------- */\n\n/** Consumer render overrides, on their own channel. They must be\n * always-current closures yet change identity on every parent render when\n * written inline, so isolating them re-renders only what calls them. */\nexport interface FilterRenderContextValue<V = unknown, O = unknown> {\n renderValue?: (context: FilterValueDisplayContext<V, O>) => React.ReactNode;\n renderChip?: (rule: FilterRule<V>) => React.ReactNode;\n renderEmpty?: (context: FilterEmptyStateContext) => React.ReactNode;\n}\n\nconst FilterRenderContext = React.createContext<FilterRenderContextValue>({});\n\nexport function useFilterRender<V = unknown, O = unknown>(): FilterRenderContextValue<V, O> {\n return React.useContext(FilterRenderContext) as FilterRenderContextValue<V, O>;\n}\n\n/* -------------------------------------------------------------------------- */\n/* Focus store */\n/* -------------------------------------------------------------------------- */\n\n/** Which chip currently owns the row's single tab stop. */\nexport interface FilterFocus {\n id: string | null;\n /** Which cell inside that row, for restoring focus after an edit. A chip\n * draws only `field`, `operator`, `value` and `menu`; the rest are advanced\n * builder cells, where a GROUP header is a row too (its `field` is the\n * combinator sentence). One union, because the chromes share the store. */\n segment:\n | \"combinator\"\n | \"field\"\n | \"operator\"\n | \"value\"\n | \"add\"\n | \"menu\"\n | \"ungroup\"\n | \"remove\"\n | \"drag\"\n | null;\n /** Open that segment's popover, not merely focus it. Picking a field commits\n * the rule straight away and the chip appears with no condition yet, so the\n * operator menu has to open ON THE CHIP without a second click. */\n autoOpen: boolean;\n}\n\n/** An external store, deliberately NOT React state. A roving tabindex\n * republishes on every arrow key, and `setState` would re-render the whole\n * bar to move one outline. The SELECTOR hooks below each narrow to one value,\n * so arrowing across forty chips re-renders two components. `useFilterFocus`\n * is the exception: it returns the whole snapshot. */\nexport interface FilterFocusStore {\n subscribe: (onStoreChange: () => void) => () => void;\n getSnapshot: () => FilterFocus;\n /** No-ops when nothing changed. */\n set: (next: FilterFocus) => void;\n}\n\nconst NO_FOCUS: FilterFocus = { id: null, segment: null, autoOpen: false };\n\nexport function createFilterFocusStore(): FilterFocusStore {\n let snapshot: FilterFocus = NO_FOCUS;\n const listeners = new Set<() => void>();\n\n return {\n subscribe(onStoreChange) {\n listeners.add(onStoreChange);\n return () => {\n listeners.delete(onStoreChange);\n };\n },\n // The SAME object until something actually changes, which is what\n // `useSyncExternalStore` requires to avoid an infinite render loop.\n getSnapshot() {\n return snapshot;\n },\n set(next) {\n if (\n next.id === snapshot.id &&\n next.segment === snapshot.segment &&\n next.autoOpen === snapshot.autoOpen\n ) {\n return;\n }\n snapshot = next;\n for (const listener of listeners) listener();\n },\n };\n}\n\n/** A shared, permanently empty store, so the hook degrades to \"nothing\n * focused\" outside a `Filters`. Nothing ever writes to it: each root creates\n * and writes its own. */\nconst FALLBACK_FOCUS_STORE = createFilterFocusStore();\n\nconst FilterFocusContext = React.createContext<FilterFocusStore>(FALLBACK_FOCUS_STORE);\n\n/* -------------------------------------------------------------------------- */\n/* Reordering */\n/* -------------------------------------------------------------------------- */\n\n/** Whether rows may be reordered at all, published once for the subtree. Two\n * files have to agree about it: the builder gates the grip and Alt+Arrow,\n * while the row and group menus commit the same mutator by a third route, so\n * gating only the builder left it off for a pointer and on from a menu. */\nconst FilterReorderContext = React.createContext(false);\n\nexport const FilterReorderProvider = FilterReorderContext.Provider;\n\nexport function useFilterReorderable(): boolean {\n return React.useContext(FilterReorderContext);\n}\n\n/* -------------------------------------------------------------------------- */\n/* Touched */\n/* -------------------------------------------------------------------------- */\n\n/** Which rules the user has actually edited the VALUE of, which decides WHEN\n * an error may appear: \"Add filter\" mints a row with no value, so flagging\n * every invalid row turns the builder red before the user did anything wrong.\n * An issue is still COLLECTED for every rule - the footer count,\n * `onQueryChange` and tree validity do not change - and only DRAWN once the\n * user has committed a value. An external store for the focus store's reason,\n * keyed by rule id and never pruned: a stale id costs one Set entry, and\n * reconciling against the query on every commit is hot-path work. */\nexport interface FilterRowStateStore {\n subscribe: (listener: () => void) => () => void;\n /** Bumped on every write. What a memo depends on, since the Sets are mutable. */\n version: () => number;\n /** Whether this rule has had a value committed to it by the user. */\n has: (id: string) => boolean;\n mark: (id: string) => void;\n /** Starts this rule over. Changing a rule's ATTRIBUTE resets its operator\n * and its value, so it has to reset this too, or the row stays warned about\n * a value that no longer exists on a field the user navigated away from. */\n unmark: (id: string) => void;\n /** Whether this rule is still being CREATED: minted by Add filter and not\n * yet given an attribute. The row enters the query with a guessed field to\n * keep the tree valid, so while pending the builder draws only that cell. */\n isPending: (id: string) => boolean;\n markPending: (id: string) => void;\n /** The attribute was chosen. The rest of the row appears. */\n resolvePending: (id: string) => void;\n /** Forgets everything. The bar's own Clear all, and a whole-tree replace. */\n reset: () => void;\n}\n\nexport function createFilterRowStateStore(): FilterRowStateStore {\n const touched = new Set<string>();\n const pending = new Set<string>();\n const listeners = new Set<() => void>();\n let version = 0;\n const notify = () => {\n version += 1;\n for (const listener of listeners) listener();\n };\n return {\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n version: () => version,\n has: (id) => touched.has(id),\n mark: (id) => {\n if (touched.has(id)) return;\n touched.add(id);\n notify();\n },\n unmark: (id) => {\n if (!touched.delete(id)) return;\n notify();\n },\n isPending: (id) => pending.has(id),\n markPending: (id) => {\n if (pending.has(id)) return;\n pending.add(id);\n notify();\n },\n resolvePending: (id) => {\n if (!pending.delete(id)) return;\n notify();\n },\n reset: () => {\n if (touched.size === 0 && pending.size === 0) return;\n touched.clear();\n pending.clear();\n notify();\n },\n };\n}\n\nconst FALLBACK_ROW_STATE_STORE = createFilterRowStateStore();\n\nconst FilterRowStateContext = React.createContext<FilterRowStateStore>(FALLBACK_ROW_STATE_STORE);\n\nexport const FilterRowStateProvider = FilterRowStateContext.Provider;\n\n/** The store itself, for handlers that write without subscribing. */\nexport function useFilterRowStateStore(): FilterRowStateStore {\n return React.useContext(FilterRowStateContext);\n}\n\n/** Whether THIS rule is still waiting for its attribute. */\nexport function useFilterRowPending(id: string): boolean {\n const store = React.useContext(FilterRowStateContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => store.isPending(id),\n () => false,\n );\n}\n\n/** Whether THIS rule may show an error yet. */\nexport function useFilterTouched(id: string): boolean {\n const store = React.useContext(FilterRowStateContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => store.has(id),\n () => false,\n );\n}\n\n/** The whole focus snapshot, so the caller re-renders on EVERY move anywhere\n * in the row. A chip wants `useFilterChipFocused` or `useFilterSegmentFocus`\n * below instead. */\nexport function useFilterFocus(): FilterFocus {\n const store = React.useContext(FilterFocusContext);\n return React.useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);\n}\n\n/** The store itself, for event handlers that write without subscribing. */\nexport function useFilterFocusStore(): FilterFocusStore {\n return React.useContext(FilterFocusContext);\n}\n\n/** The segment of THIS chip that should open itself, or null. */\nexport function useFilterChipAutoOpen(id: string): FilterFocus[\"segment\"] | null {\n const store = React.useContext(FilterFocusContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => {\n const snapshot = store.getSnapshot();\n return snapshot.autoOpen && snapshot.id === id ? snapshot.segment : null;\n },\n () => null,\n );\n}\n\n/** Whether the row holds no focus, so the first chip keeps the tab stop. */\nexport function useFilterFocusEmpty(): boolean {\n const store = React.useContext(FilterFocusContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => store.getSnapshot().id === null,\n () => true,\n );\n}\n\n/** Whether THIS chip owns the row's tab stop. */\nexport function useFilterChipFocused(id: string): boolean {\n const store = React.useContext(FilterFocusContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => store.getSnapshot().id === id,\n () => false,\n );\n}\n\n/** Which segment of THIS rule owns the tab stop, or null when another rule\n * does. A chip needs one boolean, but an advanced row is a grid ROW whose tab\n * stop is a (row, column) pair, and the column has to come from this store\n * too or the chromes disagree about where focus is after an edit. */\nexport function useFilterSegmentFocus(id: string): FilterFocus[\"segment\"] {\n const store = React.useContext(FilterFocusContext);\n return React.useSyncExternalStore(\n store.subscribe,\n () => {\n const snapshot = store.getSnapshot();\n return snapshot.id === id ? snapshot.segment : null;\n },\n () => null,\n );\n}\n\n/* -------------------------------------------------------------------------- */\n/* Resolution store */\n/* -------------------------------------------------------------------------- */\n\n/** The instance-wide value-to-label store. `useFilterOptions` caches per HOOK\n * INSTANCE, and a chip's display and its editor are two instances, so a\n * `loadOptions`-only field rendered its raw id the moment the menu closed.\n * Every instance under one root writes here, and `resolveValues` results land\n * here too. External rather than React state because labels arrive from\n * effects and promises at their own pace, and the version bumps only when a\n * NEW label lands, so a subscriber re-renders once per page of results. */\nexport interface FilterResolutionStore {\n subscribe: (onStoreChange: () => void) => () => void;\n getVersion: () => number;\n /** The option behind a stored value, or undefined while unresolved. */\n get: (fieldKey: string, value: string) => FilterOption | undefined;\n /** Records options under a field key. New values bump the version. */\n set: (fieldKey: string, options: readonly FilterOption[]) => void;\n /** Marks values as resolving and returns the subset nobody has claimed yet,\n * so two chips holding the same id issue ONE request. Claims are permanent\n * for values a fulfilled resolve did not return, which stops an id the\n * server does not know from being re-asked forever. */\n claim: (fieldKey: string, values: readonly string[]) => string[];\n /** Releases claims after a FAILED resolve, so a later mount may retry. */\n release: (fieldKey: string, values: readonly string[]) => void;\n}\n\nexport function createFilterResolutionStore(): FilterResolutionStore {\n const resolved = new Map<string, Map<string, FilterOption>>();\n const claimed = new Map<string, Set<string>>();\n const listeners = new Set<() => void>();\n let version = 0;\n\n const bucket = (fieldKey: string) => {\n let map = resolved.get(fieldKey);\n if (!map) {\n map = new Map();\n resolved.set(fieldKey, map);\n }\n return map;\n };\n\n return {\n subscribe(onStoreChange) {\n listeners.add(onStoreChange);\n return () => {\n listeners.delete(onStoreChange);\n };\n },\n getVersion() {\n return version;\n },\n get(fieldKey, value) {\n return resolved.get(fieldKey)?.get(value);\n },\n set(fieldKey, options) {\n const map = bucket(fieldKey);\n let landed = false;\n for (const option of options) {\n if (!map.has(option.value)) landed = true;\n map.set(option.value, option);\n }\n if (!landed) return;\n version += 1;\n for (const listener of listeners) listener();\n },\n claim(fieldKey, values) {\n let set = claimed.get(fieldKey);\n if (!set) {\n set = new Set();\n claimed.set(fieldKey, set);\n }\n const map = resolved.get(fieldKey);\n const fresh: string[] = [];\n for (const value of values) {\n if (set.has(value) || map?.has(value)) continue;\n set.add(value);\n fresh.push(value);\n }\n return fresh;\n },\n release(fieldKey, values) {\n const set = claimed.get(fieldKey);\n if (!set) return;\n for (const value of values) set.delete(value);\n },\n };\n}\n\nexport { FilterActionsContext, FilterFocusContext, FilterRenderContext, FilterStateContext };\n"],"mappings":";;;;;;;;;;;;;;;;;AAgKA,SAAgB,eAAe,OAA0D;CACvF,OAAO,MAAM,YAAY,MAAM;AACjC;;;;;AAMA,SAAgB,oBAAoB,OAAiD;CACnF,IAAI,MAAM,YAAY,CAAC,MAAM,UAAU,OAAO;CAC9C,OAAO;EAAE,iBAAiB;EAAM,iBAAiB;CAAG;AACtD;;;;;;;;;;;;AA8BA,MAAM,uBAAqE;CACzE,IAAI;EAAE,QAAQ;EAAM,MAAM;CAAU;CACpC,SAAS;EAAE,QAAQ;EAAW,MAAM;CAAO;AAC7C;;;;;AAMA,SAAgB,mBAAmB,OAAuD;CACxF,OAAO,qBAAqB,MAAM,SAAS,qBAAqB;AAClE;AAEA,MAAM,uBAAuBA,QAAM,cAAgD,IAAI;AAEvF,SAAgB,mBAA8E;CAC5F,MAAM,UAAUA,QAAM,WAAW,oBAAoB;CACrD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,gDAAgD;CAElE,OAAO;AACT;AAsBA,MAAM,qBAAqBA,QAAM,cAA8C,IAAI;AAEnF,SAAgB,iBAA0D;CACxE,MAAM,UAAUA,QAAM,WAAW,kBAAkB;CACnD,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,8CAA8C;CAEhE,OAAO;AACT;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GAC9B;GACA,IAAI,CAAC,QAAQ;GACb,WAAW;GACX,KAAK,MAAM,YAAY,WAAW,SAAS;EAC7C;EACA,MAAM,UAAU,QAAQ;GACtB,IAAI,MAAM,QAAQ,IAAI,QAAQ;GAC9B,IAAI,CAAC,KAAK;IACR,sBAAM,IAAI,IAAI;IACd,QAAQ,IAAI,UAAU,GAAG;GAC3B;GACA,MAAM,MAAM,SAAS,IAAI,QAAQ;GACjC,MAAM,QAAkB,CAAC;GACzB,KAAK,MAAM,SAAS,QAAQ;IAC1B,IAAI,IAAI,IAAI,KAAK,KAAK,KAAK,IAAI,KAAK,GAAG;IACvC,IAAI,IAAI,KAAK;IACb,MAAM,KAAK,KAAK;GAClB;GACA,OAAO;EACT;EACA,QAAQ,UAAU,QAAQ;GACxB,MAAM,MAAM,QAAQ,IAAI,QAAQ;GAChC,IAAI,CAAC,KAAK;GACV,KAAK,MAAM,SAAS,QAAQ,IAAI,OAAO,KAAK;EAC9C;CACF;AACF"}
@@ -0,0 +1,43 @@
1
+ //#region src/components/reui/filters/filters-date.d.ts
2
+ /**
3
+ * A date filter value. NOT a `Date`: a filter gets persisted (saved views,
4
+ * shared URLs), and a resolved `Date` would freeze "created today" into one
5
+ * fixed day. An absolute pick still stores one day, because "on 14 August"
6
+ * does mean that day.
7
+ */
8
+ interface FilterDateValue {
9
+ /** An absolute day, `yyyy-MM-dd`. Mutually exclusive with `relative`. */
10
+ date?: string;
11
+ /** A token re-resolved on every read. */
12
+ relative?: FilterRelativeDate;
13
+ /** Optional time of day, `HH:mm`. */
14
+ time?: string;
15
+ }
16
+ /** A calendar offset from now, resolved at read time. */
17
+ interface FilterRelativeDate {
18
+ unit: "day" | "week" | "month" | "year";
19
+ offset: number;
20
+ }
21
+ declare const FILTER_DATE_FORMAT = "yyyy-MM-dd";
22
+ declare const RELATIVE_TODAY: FilterRelativeDate;
23
+ declare const RELATIVE_TOMORROW: FilterRelativeDate;
24
+ declare const RELATIVE_YESTERDAY: FilterRelativeDate;
25
+ declare const RELATIVE_NEXT_WEEK: FilterRelativeDate;
26
+ declare function applyFilterRelative(relative: FilterRelativeDate, now: Date): Date;
27
+ declare function resolveFilterDate(value: FilterDateValue | undefined, now?: Date): Date | null;
28
+ declare function toFilterDateValue(date: Date, time?: string): FilterDateValue;
29
+ /**
30
+ * Parses a typed phrase, or null when nothing matches. Relative phrasing gives
31
+ * a RELATIVE value and an explicit date an ABSOLUTE one; flattening the two is
32
+ * what freezes a saved view.
33
+ */
34
+ declare function parseFilterDate(text: string, now?: Date): FilterDateValue | null;
35
+ /**
36
+ * Human wording for a value. Relative values render as their phrase, not the
37
+ * resolved day, so a chip reading "is today" does not go stale tomorrow.
38
+ */
39
+ declare function formatFilterDate(value: FilterDateValue | undefined, now?: Date, pattern?: string): string;
40
+ declare function isFilterTime(time: string): boolean;
41
+ //#endregion
42
+ export { FILTER_DATE_FORMAT, FilterDateValue, FilterRelativeDate, RELATIVE_NEXT_WEEK, RELATIVE_TODAY, RELATIVE_TOMORROW, RELATIVE_YESTERDAY, applyFilterRelative, formatFilterDate, isFilterTime, parseFilterDate, resolveFilterDate, toFilterDateValue };
43
+ //# sourceMappingURL=filters-date.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters-date.d.ts","names":[],"sources":["../../../../src/components/reui/filters/filters-date.tsx"],"mappings":";;;;;;;UAmBiB;;EAEf;;EAEA,WAAW;;EAEX;;;UAIe;EACf;EACA;;cAGW;cAEA,gBAAgB;cAChB,mBAAmB;cACnB,oBAAoB;cAIpB,oBAAoB;iBAKjB,oBAAoB,UAAU,oBAAoB,KAAK,OAAO;iBAQ9D,kBACd,OAAO,6BACP,MAAK,OACJ;iBAUa,kBAAkB,MAAM,MAAM,gBAAgB;;;;;;iBAiC9C,gBAAgB,cAAc,MAAK,OAAoB;;;;;iBAqEvD,iBACd,OAAO,6BACP,MAAK,MACL;iBAsBc,aAAa"}
@@ -0,0 +1,143 @@
1
+ "use client";
2
+ import { addDays, addMonths, addWeeks, addYears, format, isValid, parse, startOfDay } from "date-fns";
3
+ //#region src/components/reui/filters/filters-date.tsx
4
+ const FILTER_DATE_FORMAT = "yyyy-MM-dd";
5
+ const RELATIVE_TODAY = {
6
+ unit: "day",
7
+ offset: 0
8
+ };
9
+ const RELATIVE_TOMORROW = {
10
+ unit: "day",
11
+ offset: 1
12
+ };
13
+ const RELATIVE_YESTERDAY = {
14
+ unit: "day",
15
+ offset: -1
16
+ };
17
+ const RELATIVE_NEXT_WEEK = {
18
+ unit: "week",
19
+ offset: 1
20
+ };
21
+ function applyFilterRelative(relative, now) {
22
+ const base = startOfDay(now);
23
+ if (relative.unit === "day") return addDays(base, relative.offset);
24
+ if (relative.unit === "week") return addWeeks(base, relative.offset);
25
+ if (relative.unit === "month") return addMonths(base, relative.offset);
26
+ return addYears(base, relative.offset);
27
+ }
28
+ function resolveFilterDate(value, now = /* @__PURE__ */ new Date()) {
29
+ if (!value) return null;
30
+ if (value.relative) return applyFilterRelative(value.relative, now);
31
+ if (value.date) {
32
+ const parsed = parse(value.date, FILTER_DATE_FORMAT, now);
33
+ return isValid(parsed) ? parsed : null;
34
+ }
35
+ return null;
36
+ }
37
+ function toFilterDateValue(date, time) {
38
+ const value = { date: format(date, FILTER_DATE_FORMAT) };
39
+ if (time) value.time = time;
40
+ return value;
41
+ }
42
+ const WEEKDAYS = [
43
+ "sunday",
44
+ "monday",
45
+ "tuesday",
46
+ "wednesday",
47
+ "thursday",
48
+ "friday",
49
+ "saturday"
50
+ ];
51
+ /**
52
+ * Typed formats, most specific first. `date-selector.tsx` overlaps on a few
53
+ * of these, but its parser is a callback inside the component returning a
54
+ * `DateSelectorValue`, so there is nothing importable.
55
+ */
56
+ const EXPLICIT_FORMATS = [
57
+ "yyyy-MM-dd",
58
+ "MM/dd/yyyy",
59
+ "M/d/yyyy",
60
+ "dd/MM/yyyy",
61
+ "MMMM d, yyyy",
62
+ "MMM d, yyyy",
63
+ "MMMM d",
64
+ "MMM d",
65
+ "d MMMM yyyy",
66
+ "d MMM yyyy"
67
+ ];
68
+ /**
69
+ * Parses a typed phrase, or null when nothing matches. Relative phrasing gives
70
+ * a RELATIVE value and an explicit date an ABSOLUTE one; flattening the two is
71
+ * what freezes a saved view.
72
+ */
73
+ function parseFilterDate(text, now = /* @__PURE__ */ new Date()) {
74
+ const input = text.trim().toLowerCase().replace(/\s+/g, " ");
75
+ if (!input) return null;
76
+ if (input === "today" || input === "now") return { relative: RELATIVE_TODAY };
77
+ if (input === "tomorrow") return { relative: RELATIVE_TOMORROW };
78
+ if (input === "yesterday") return { relative: RELATIVE_YESTERDAY };
79
+ const nextLast = input.match(/^(next|last|this) (day|week|month|year)$/);
80
+ if (nextLast) {
81
+ const direction = nextLast[1] === "next" ? 1 : nextLast[1] === "last" ? -1 : 0;
82
+ return { relative: {
83
+ unit: nextLast[2],
84
+ offset: direction
85
+ } };
86
+ }
87
+ const counted = input.match(/^(?:in )?(\d+) (day|week|month|year)s?(?: ago)?$/);
88
+ if (counted) {
89
+ const magnitude = Number.parseInt(counted[1], 10);
90
+ const past = input.endsWith("ago");
91
+ return { relative: {
92
+ unit: counted[2],
93
+ offset: past ? -magnitude : magnitude
94
+ } };
95
+ }
96
+ const weekday = input.match(/^(?:(next|last|this) )?([a-z]+)$/);
97
+ if (weekday) {
98
+ const index = WEEKDAYS.indexOf(weekday[2]);
99
+ if (index !== -1) {
100
+ let delta = index - startOfDay(now).getDay();
101
+ if (weekday[1] === "last") {
102
+ if (delta >= 0) delta -= 7;
103
+ } else if (delta <= 0) delta += 7;
104
+ return { relative: {
105
+ unit: "day",
106
+ offset: delta
107
+ } };
108
+ }
109
+ }
110
+ for (const pattern of EXPLICIT_FORMATS) {
111
+ const parsed = parse(input, pattern, now);
112
+ if (isValid(parsed)) return toFilterDateValue(parsed);
113
+ }
114
+ return null;
115
+ }
116
+ /**
117
+ * Human wording for a value. Relative values render as their phrase, not the
118
+ * resolved day, so a chip reading "is today" does not go stale tomorrow.
119
+ */
120
+ function formatFilterDate(value, now = /* @__PURE__ */ new Date(), pattern = "MMM d, yyyy") {
121
+ if (!value) return "";
122
+ if (value.relative) {
123
+ const { unit, offset } = value.relative;
124
+ if (unit === "day" && offset === 0) return "today";
125
+ if (unit === "day" && offset === 1) return "tomorrow";
126
+ if (unit === "day" && offset === -1) return "yesterday";
127
+ const plural = Math.abs(offset) === 1 ? unit : `${unit}s`;
128
+ if (offset > 0) return `in ${offset} ${plural}`;
129
+ if (offset < 0) return `${Math.abs(offset)} ${plural} ago`;
130
+ return `this ${unit}`;
131
+ }
132
+ const resolved = resolveFilterDate(value, now);
133
+ if (!resolved) return "";
134
+ const day = format(resolved, pattern);
135
+ return value.time ? `${day} ${value.time}` : day;
136
+ }
137
+ function isFilterTime(time) {
138
+ return /^([01]\d|2[0-3]):[0-5]\d$/.test(time);
139
+ }
140
+ //#endregion
141
+ export { FILTER_DATE_FORMAT, RELATIVE_NEXT_WEEK, RELATIVE_TODAY, RELATIVE_TOMORROW, RELATIVE_YESTERDAY, applyFilterRelative, formatFilterDate, isFilterTime, parseFilterDate, resolveFilterDate, toFilterDateValue };
142
+
143
+ //# sourceMappingURL=filters-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filters-date.js","names":[],"sources":["../../../../src/components/reui/filters/filters-date.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n addDays,\n addMonths,\n addWeeks,\n addYears,\n format,\n isValid,\n parse,\n startOfDay,\n} from \"date-fns\";\n\n/**\n * A date filter value. NOT a `Date`: a filter gets persisted (saved views,\n * shared URLs), and a resolved `Date` would freeze \"created today\" into one\n * fixed day. An absolute pick still stores one day, because \"on 14 August\"\n * does mean that day.\n */\nexport interface FilterDateValue {\n /** An absolute day, `yyyy-MM-dd`. Mutually exclusive with `relative`. */\n date?: string;\n /** A token re-resolved on every read. */\n relative?: FilterRelativeDate;\n /** Optional time of day, `HH:mm`. */\n time?: string;\n}\n\n/** A calendar offset from now, resolved at read time. */\nexport interface FilterRelativeDate {\n unit: \"day\" | \"week\" | \"month\" | \"year\";\n offset: number;\n}\n\nexport const FILTER_DATE_FORMAT = \"yyyy-MM-dd\";\n\nexport const RELATIVE_TODAY: FilterRelativeDate = { unit: \"day\", offset: 0 };\nexport const RELATIVE_TOMORROW: FilterRelativeDate = { unit: \"day\", offset: 1 };\nexport const RELATIVE_YESTERDAY: FilterRelativeDate = {\n unit: \"day\",\n offset: -1,\n};\nexport const RELATIVE_NEXT_WEEK: FilterRelativeDate = {\n unit: \"week\",\n offset: 1,\n};\n\nexport function applyFilterRelative(relative: FilterRelativeDate, now: Date): Date {\n const base = startOfDay(now);\n if (relative.unit === \"day\") return addDays(base, relative.offset);\n if (relative.unit === \"week\") return addWeeks(base, relative.offset);\n if (relative.unit === \"month\") return addMonths(base, relative.offset);\n return addYears(base, relative.offset);\n}\n\nexport function resolveFilterDate(\n value: FilterDateValue | undefined,\n now: Date = new Date(),\n): Date | null {\n if (!value) return null;\n if (value.relative) return applyFilterRelative(value.relative, now);\n if (value.date) {\n const parsed = parse(value.date, FILTER_DATE_FORMAT, now);\n return isValid(parsed) ? parsed : null;\n }\n return null;\n}\n\nexport function toFilterDateValue(date: Date, time?: string): FilterDateValue {\n const value: FilterDateValue = { date: format(date, FILTER_DATE_FORMAT) };\n if (time) value.time = time;\n return value;\n}\n\n// ----- natural language input -----\n\nconst WEEKDAYS = [\"sunday\", \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\"];\n\n/**\n * Typed formats, most specific first. `date-selector.tsx` overlaps on a few\n * of these, but its parser is a callback inside the component returning a\n * `DateSelectorValue`, so there is nothing importable.\n */\nconst EXPLICIT_FORMATS = [\n \"yyyy-MM-dd\",\n \"MM/dd/yyyy\",\n \"M/d/yyyy\",\n \"dd/MM/yyyy\",\n \"MMMM d, yyyy\",\n \"MMM d, yyyy\",\n \"MMMM d\",\n \"MMM d\",\n \"d MMMM yyyy\",\n \"d MMM yyyy\",\n];\n\n/**\n * Parses a typed phrase, or null when nothing matches. Relative phrasing gives\n * a RELATIVE value and an explicit date an ABSOLUTE one; flattening the two is\n * what freezes a saved view.\n */\nexport function parseFilterDate(text: string, now: Date = new Date()): FilterDateValue | null {\n const input = text.trim().toLowerCase().replace(/\\s+/g, \" \");\n if (!input) return null;\n\n if (input === \"today\" || input === \"now\") return { relative: RELATIVE_TODAY };\n if (input === \"tomorrow\") return { relative: RELATIVE_TOMORROW };\n if (input === \"yesterday\") return { relative: RELATIVE_YESTERDAY };\n\n const nextLast = input.match(/^(next|last|this) (day|week|month|year)$/);\n if (nextLast) {\n const direction = nextLast[1] === \"next\" ? 1 : nextLast[1] === \"last\" ? -1 : 0;\n return {\n relative: {\n unit: nextLast[2] as FilterRelativeDate[\"unit\"],\n offset: direction,\n },\n };\n }\n\n // \"in 3 days\" / \"3 days ago\" / \"in 2 weeks\"\n const counted = input.match(/^(?:in )?(\\d+) (day|week|month|year)s?(?: ago)?$/);\n if (counted) {\n const magnitude = Number.parseInt(counted[1], 10);\n const past = input.endsWith(\"ago\");\n return {\n relative: {\n unit: counted[2] as FilterRelativeDate[\"unit\"],\n offset: past ? -magnitude : magnitude,\n },\n };\n }\n\n // \"next tuesday\" / \"last friday\" / bare \"tuesday\"\n const weekday = input.match(/^(?:(next|last|this) )?([a-z]+)$/);\n if (weekday) {\n const index = WEEKDAYS.indexOf(weekday[2]);\n if (index !== -1) {\n const today = startOfDay(now);\n const current = today.getDay();\n let delta = index - current;\n const qualifier = weekday[1];\n\n if (qualifier === \"last\") {\n // Always strictly in the past.\n if (delta >= 0) delta -= 7;\n } else {\n // \"next\"/\"this\" and a bare weekday all mean the NEXT one, not today.\n if (delta <= 0) delta += 7;\n }\n\n return { relative: { unit: \"day\", offset: delta } };\n }\n }\n\n for (const pattern of EXPLICIT_FORMATS) {\n const parsed = parse(input, pattern, now);\n if (isValid(parsed)) {\n // \"Aug 14\" has no year, so it takes the reference year.\n return toFilterDateValue(parsed);\n }\n }\n\n return null;\n}\n\n/**\n * Human wording for a value. Relative values render as their phrase, not the\n * resolved day, so a chip reading \"is today\" does not go stale tomorrow.\n */\nexport function formatFilterDate(\n value: FilterDateValue | undefined,\n now: Date = new Date(),\n pattern = \"MMM d, yyyy\",\n): string {\n if (!value) return \"\";\n\n if (value.relative) {\n const { unit, offset } = value.relative;\n if (unit === \"day\" && offset === 0) return \"today\";\n if (unit === \"day\" && offset === 1) return \"tomorrow\";\n if (unit === \"day\" && offset === -1) return \"yesterday\";\n\n const plural = Math.abs(offset) === 1 ? unit : `${unit}s`;\n if (offset > 0) return `in ${offset} ${plural}`;\n if (offset < 0) return `${Math.abs(offset)} ${plural} ago`;\n return `this ${unit}`;\n }\n\n const resolved = resolveFilterDate(value, now);\n if (!resolved) return \"\";\n const day = format(resolved, pattern);\n return value.time ? `${day} ${value.time}` : day;\n}\n\nexport function isFilterTime(time: string): boolean {\n return /^([01]\\d|2[0-3]):[0-5]\\d$/.test(time);\n}\n"],"mappings":";;;AAkCA,MAAa,qBAAqB;AAElC,MAAa,iBAAqC;CAAE,MAAM;CAAO,QAAQ;AAAE;AAC3E,MAAa,oBAAwC;CAAE,MAAM;CAAO,QAAQ;AAAE;AAC9E,MAAa,qBAAyC;CACpD,MAAM;CACN,QAAQ;AACV;AACA,MAAa,qBAAyC;CACpD,MAAM;CACN,QAAQ;AACV;AAEA,SAAgB,oBAAoB,UAA8B,KAAiB;CACjF,MAAM,OAAO,WAAW,GAAG;CAC3B,IAAI,SAAS,SAAS,OAAO,OAAO,QAAQ,MAAM,SAAS,MAAM;CACjE,IAAI,SAAS,SAAS,QAAQ,OAAO,SAAS,MAAM,SAAS,MAAM;CACnE,IAAI,SAAS,SAAS,SAAS,OAAO,UAAU,MAAM,SAAS,MAAM;CACrE,OAAO,SAAS,MAAM,SAAS,MAAM;AACvC;AAEA,SAAgB,kBACd,OACA,sBAAY,IAAI,KAAK,GACR;CACb,IAAI,CAAC,OAAO,OAAO;CACnB,IAAI,MAAM,UAAU,OAAO,oBAAoB,MAAM,UAAU,GAAG;CACl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