@tryghost/shade 0.0.0-stage → 0.1.0-alpha.1

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 (546) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +142 -2
  3. package/es/app.js +4 -0
  4. package/es/assets/images/index.js +2 -0
  5. package/es/components/layout/error-page.js +40 -0
  6. package/es/components/layout/error-page.js.map +1 -0
  7. package/es/components/layout/heading.js +80 -0
  8. package/es/components/layout/heading.js.map +1 -0
  9. package/es/components/page-templates/detail-page.js +73 -0
  10. package/es/components/page-templates/detail-page.js.map +1 -0
  11. package/es/components/page-templates/large-page-title.js +89 -0
  12. package/es/components/page-templates/large-page-title.js.map +1 -0
  13. package/es/components/page-templates/list-page.js +174 -0
  14. package/es/components/page-templates/list-page.js.map +1 -0
  15. package/es/components/page-templates/modal-page.js +32 -0
  16. package/es/components/page-templates/modal-page.js.map +1 -0
  17. package/es/components/patterns/color-picker.js +328 -0
  18. package/es/components/patterns/color-picker.js.map +1 -0
  19. package/es/components/patterns/dirty-confirm-dialog.js +44 -0
  20. package/es/components/patterns/dirty-confirm-dialog.js.map +1 -0
  21. package/es/components/patterns/filter-bar-context.js +8 -0
  22. package/es/components/patterns/filter-bar-context.js.map +1 -0
  23. package/es/components/patterns/filter-bar.js +67 -0
  24. package/es/components/patterns/filter-bar.js.map +1 -0
  25. package/es/components/patterns/filters-helpers.js +415 -0
  26. package/es/components/patterns/filters-helpers.js.map +1 -0
  27. package/es/components/patterns/filters.js +1816 -0
  28. package/es/components/patterns/filters.js.map +1 -0
  29. package/es/components/patterns/gh-chart.js +152 -0
  30. package/es/components/patterns/gh-chart.js.map +1 -0
  31. package/es/components/patterns/image-upload-variants.js +13 -0
  32. package/es/components/patterns/image-upload-variants.js.map +1 -0
  33. package/es/components/patterns/image-upload.js +63 -0
  34. package/es/components/patterns/image-upload.js.map +1 -0
  35. package/es/components/patterns/kpi-card.js +46 -0
  36. package/es/components/patterns/kpi-card.js.map +1 -0
  37. package/es/components/patterns/kpi-tabs.js +61 -0
  38. package/es/components/patterns/kpi-tabs.js.map +1 -0
  39. package/es/components/patterns/page-header-large-title.js +13 -0
  40. package/es/components/patterns/page-header-large-title.js.map +1 -0
  41. package/es/components/patterns/page-header.js +375 -0
  42. package/es/components/patterns/page-header.js.map +1 -0
  43. package/es/components/patterns/setting-group-variants.js +22 -0
  44. package/es/components/patterns/setting-group-variants.js.map +1 -0
  45. package/es/components/patterns/setting-group.js +103 -0
  46. package/es/components/patterns/setting-group.js.map +1 -0
  47. package/es/components/patterns/settings-modal-variants.js +37 -0
  48. package/es/components/patterns/settings-modal-variants.js.map +1 -0
  49. package/es/components/patterns/settings-modal.js +192 -0
  50. package/es/components/patterns/settings-modal.js.map +1 -0
  51. package/es/components/patterns/share-modal.js +264 -0
  52. package/es/components/patterns/share-modal.js.map +1 -0
  53. package/es/components/patterns/use-dirty-confirmation.js +35 -0
  54. package/es/components/patterns/use-dirty-confirmation.js.map +1 -0
  55. package/es/components/patterns/view-bar.js +40 -0
  56. package/es/components/patterns/view-bar.js.map +1 -0
  57. package/es/components/primitives/box.js +25 -0
  58. package/es/components/primitives/box.js.map +1 -0
  59. package/es/components/primitives/container.js +35 -0
  60. package/es/components/primitives/container.js.map +1 -0
  61. package/es/components/primitives/grid.js +26 -0
  62. package/es/components/primitives/grid.js.map +1 -0
  63. package/es/components/primitives/index.js +7 -0
  64. package/es/components/primitives/inline.js +17 -0
  65. package/es/components/primitives/inline.js.map +1 -0
  66. package/es/components/primitives/stack.js +17 -0
  67. package/es/components/primitives/stack.js.map +1 -0
  68. package/es/components/primitives/text.js +48 -0
  69. package/es/components/primitives/text.js.map +1 -0
  70. package/es/components/primitives/types.js +56 -0
  71. package/es/components/primitives/types.js.map +1 -0
  72. package/es/components/ui/accordion.js +37 -0
  73. package/es/components/ui/accordion.js.map +1 -0
  74. package/es/components/ui/action-list.js +56 -0
  75. package/es/components/ui/action-list.js.map +1 -0
  76. package/es/components/ui/alert-dialog.js +80 -0
  77. package/es/components/ui/alert-dialog.js.map +1 -0
  78. package/es/components/ui/animated-number.js +14 -0
  79. package/es/components/ui/animated-number.js.map +1 -0
  80. package/es/components/ui/avatar.js +52 -0
  81. package/es/components/ui/avatar.js.map +1 -0
  82. package/es/components/ui/badge-variants.js +32 -0
  83. package/es/components/ui/badge-variants.js.map +1 -0
  84. package/es/components/ui/badge.js +22 -0
  85. package/es/components/ui/badge.js.map +1 -0
  86. package/es/components/ui/banner-variants.js +34 -0
  87. package/es/components/ui/banner-variants.js.map +1 -0
  88. package/es/components/ui/banner.js +37 -0
  89. package/es/components/ui/banner.js.map +1 -0
  90. package/es/components/ui/breadcrumb.js +64 -0
  91. package/es/components/ui/breadcrumb.js.map +1 -0
  92. package/es/components/ui/button-variants.js +137 -0
  93. package/es/components/ui/button-variants.js.map +1 -0
  94. package/es/components/ui/button.js +35 -0
  95. package/es/components/ui/button.js.map +1 -0
  96. package/es/components/ui/calendar.js +119 -0
  97. package/es/components/ui/calendar.js.map +1 -0
  98. package/es/components/ui/card-variants.js +13 -0
  99. package/es/components/ui/card-variants.js.map +1 -0
  100. package/es/components/ui/card.js +98 -0
  101. package/es/components/ui/card.js.map +1 -0
  102. package/es/components/ui/chart.js +188 -0
  103. package/es/components/ui/chart.js.map +1 -0
  104. package/es/components/ui/checkbox.js +21 -0
  105. package/es/components/ui/checkbox.js.map +1 -0
  106. package/es/components/ui/code-editor-view.js +150 -0
  107. package/es/components/ui/code-editor-view.js.map +1 -0
  108. package/es/components/ui/code-editor.js +18 -0
  109. package/es/components/ui/code-editor.js.map +1 -0
  110. package/es/components/ui/combobox.js +37 -0
  111. package/es/components/ui/combobox.js.map +1 -0
  112. package/es/components/ui/command.js +91 -0
  113. package/es/components/ui/command.js.map +1 -0
  114. package/es/components/ui/context-menu.js +82 -0
  115. package/es/components/ui/context-menu.js.map +1 -0
  116. package/es/components/ui/copy-field.js +142 -0
  117. package/es/components/ui/copy-field.js.map +1 -0
  118. package/es/components/ui/data-list.js +103 -0
  119. package/es/components/ui/data-list.js.map +1 -0
  120. package/es/components/ui/dialog.js +49 -0
  121. package/es/components/ui/dialog.js.map +1 -0
  122. package/es/components/ui/dropdown-menu.js +86 -0
  123. package/es/components/ui/dropdown-menu.js.map +1 -0
  124. package/es/components/ui/dropzone-variants.js +30 -0
  125. package/es/components/ui/dropzone-variants.js.map +1 -0
  126. package/es/components/ui/dropzone.js +55 -0
  127. package/es/components/ui/dropzone.js.map +1 -0
  128. package/es/components/ui/empty-indicator.js +42 -0
  129. package/es/components/ui/empty-indicator.js.map +1 -0
  130. package/es/components/ui/field.js +118 -0
  131. package/es/components/ui/field.js.map +1 -0
  132. package/es/components/ui/flag.js +30 -0
  133. package/es/components/ui/flag.js.map +1 -0
  134. package/es/components/ui/floating-sidebar-metrics.js +56 -0
  135. package/es/components/ui/floating-sidebar-metrics.js.map +1 -0
  136. package/es/components/ui/floating-sidebar.js +522 -0
  137. package/es/components/ui/floating-sidebar.js.map +1 -0
  138. package/es/components/ui/form-context.js +25 -0
  139. package/es/components/ui/form-context.js.map +1 -0
  140. package/es/components/ui/form.js +75 -0
  141. package/es/components/ui/form.js.map +1 -0
  142. package/es/components/ui/hover-card.js +20 -0
  143. package/es/components/ui/hover-card.js.map +1 -0
  144. package/es/components/ui/icon.js +2 -0
  145. package/es/components/ui/image-overlay-button.js +14 -0
  146. package/es/components/ui/image-overlay-button.js.map +1 -0
  147. package/es/components/ui/indicator-variants.js +63 -0
  148. package/es/components/ui/indicator-variants.js.map +1 -0
  149. package/es/components/ui/indicator.js +26 -0
  150. package/es/components/ui/indicator.js.map +1 -0
  151. package/es/components/ui/input-group-variants.js +25 -0
  152. package/es/components/ui/input-group-variants.js.map +1 -0
  153. package/es/components/ui/input-group.js +90 -0
  154. package/es/components/ui/input-group.js.map +1 -0
  155. package/es/components/ui/input-surface.js +51 -0
  156. package/es/components/ui/input-surface.js.map +1 -0
  157. package/es/components/ui/input.js +18 -0
  158. package/es/components/ui/input.js.map +1 -0
  159. package/es/components/ui/kbd.js +29 -0
  160. package/es/components/ui/kbd.js.map +1 -0
  161. package/es/components/ui/label.js +17 -0
  162. package/es/components/ui/label.js.map +1 -0
  163. package/es/components/ui/link.js +30 -0
  164. package/es/components/ui/link.js.map +1 -0
  165. package/es/components/ui/loading-indicator.js +50 -0
  166. package/es/components/ui/loading-indicator.js.map +1 -0
  167. package/es/components/ui/metric-value.js +39 -0
  168. package/es/components/ui/metric-value.js.map +1 -0
  169. package/es/components/ui/multi-select-combobox.js +205 -0
  170. package/es/components/ui/multi-select-combobox.js.map +1 -0
  171. package/es/components/ui/navbar.js +41 -0
  172. package/es/components/ui/navbar.js.map +1 -0
  173. package/es/components/ui/no-value-label.js +19 -0
  174. package/es/components/ui/no-value-label.js.map +1 -0
  175. package/es/components/ui/pagemenu.js +138 -0
  176. package/es/components/ui/pagemenu.js.map +1 -0
  177. package/es/components/ui/popover.js +24 -0
  178. package/es/components/ui/popover.js.map +1 -0
  179. package/es/components/ui/preview-chrome-variants.js +13 -0
  180. package/es/components/ui/preview-chrome-variants.js.map +1 -0
  181. package/es/components/ui/preview-chrome.js +27 -0
  182. package/es/components/ui/preview-chrome.js.map +1 -0
  183. package/es/components/ui/radio-group-variants.js +14 -0
  184. package/es/components/ui/radio-group-variants.js.map +1 -0
  185. package/es/components/ui/radio-group.js +33 -0
  186. package/es/components/ui/radio-group.js.map +1 -0
  187. package/es/components/ui/select-variants.js +45 -0
  188. package/es/components/ui/select-variants.js.map +1 -0
  189. package/es/components/ui/select.js +90 -0
  190. package/es/components/ui/select.js.map +1 -0
  191. package/es/components/ui/separator.js +17 -0
  192. package/es/components/ui/separator.js.map +1 -0
  193. package/es/components/ui/sheet.js +67 -0
  194. package/es/components/ui/sheet.js.map +1 -0
  195. package/es/components/ui/sidebar-context.js +12 -0
  196. package/es/components/ui/sidebar-context.js.map +1 -0
  197. package/es/components/ui/sidebar.js +384 -0
  198. package/es/components/ui/sidebar.js.map +1 -0
  199. package/es/components/ui/simple-pagination.js +68 -0
  200. package/es/components/ui/simple-pagination.js.map +1 -0
  201. package/es/components/ui/skeleton.js +77 -0
  202. package/es/components/ui/skeleton.js.map +1 -0
  203. package/es/components/ui/sonner.js +29 -0
  204. package/es/components/ui/sonner.js.map +1 -0
  205. package/es/components/ui/sortable-list.js +107 -0
  206. package/es/components/ui/sortable-list.js.map +1 -0
  207. package/es/components/ui/sticky-footer.js +29 -0
  208. package/es/components/ui/sticky-footer.js.map +1 -0
  209. package/es/components/ui/switch.js +34 -0
  210. package/es/components/ui/switch.js.map +1 -0
  211. package/es/components/ui/table.js +81 -0
  212. package/es/components/ui/table.js.map +1 -0
  213. package/es/components/ui/tabs-variants.js +19 -0
  214. package/es/components/ui/tabs-variants.js.map +1 -0
  215. package/es/components/ui/tabs.js +157 -0
  216. package/es/components/ui/tabs.js.map +1 -0
  217. package/es/components/ui/textarea.js +17 -0
  218. package/es/components/ui/textarea.js.map +1 -0
  219. package/es/components/ui/time-picker.js +28 -0
  220. package/es/components/ui/time-picker.js.map +1 -0
  221. package/es/components/ui/toggle-group.js +52 -0
  222. package/es/components/ui/toggle-group.js.map +1 -0
  223. package/es/components/ui/toggle-variants.js +34 -0
  224. package/es/components/ui/toggle-variants.js.map +1 -0
  225. package/es/components/ui/toggle.js +29 -0
  226. package/es/components/ui/toggle.js.map +1 -0
  227. package/es/components/ui/token-field.js +14 -0
  228. package/es/components/ui/token-field.js.map +1 -0
  229. package/es/components/ui/tooltip.js +116 -0
  230. package/es/components/ui/tooltip.js.map +1 -0
  231. package/es/components/ui/trend-badge.js +77 -0
  232. package/es/components/ui/trend-badge.js.map +1 -0
  233. package/es/components.js +79 -0
  234. package/es/hooks/use-global-dirty-state.js +21 -0
  235. package/es/hooks/use-global-dirty-state.js.map +1 -0
  236. package/es/hooks/use-mobile.js +23 -0
  237. package/es/hooks/use-mobile.js.map +1 -0
  238. package/es/hooks/use-simple-pagination.js +45 -0
  239. package/es/hooks/use-simple-pagination.js.map +1 -0
  240. package/es/icon-BJcGsQ4b.js +185 -0
  241. package/es/icon-BJcGsQ4b.js.map +1 -0
  242. package/es/images-CUcakpOD.js +124 -0
  243. package/es/images-CUcakpOD.js.map +1 -0
  244. package/es/index.js +113 -0
  245. package/es/lib/ds-utils.js +214 -0
  246. package/es/lib/ds-utils.js.map +1 -0
  247. package/es/lib/overlay-escape.js +13 -0
  248. package/es/lib/overlay-escape.js.map +1 -0
  249. package/es/lib/utils.js +2 -0
  250. package/es/page-templates.js +5 -0
  251. package/es/patterns.js +19 -0
  252. package/es/primitives.js +9 -0
  253. package/es/providers/global-dirty-state-provider.js +25 -0
  254. package/es/providers/global-dirty-state-provider.js.map +1 -0
  255. package/es/providers/header-tooltip-provider.js +24 -0
  256. package/es/providers/header-tooltip-provider.js.map +1 -0
  257. package/es/providers/shade-context.js +19 -0
  258. package/es/providers/shade-context.js.map +1 -0
  259. package/es/providers/shade-provider.js +64 -0
  260. package/es/providers/shade-provider.js.map +1 -0
  261. package/es/shade-app.js +28 -0
  262. package/es/shade-app.js.map +1 -0
  263. package/es/shade-scope.js +20 -0
  264. package/es/shade-scope.js.map +1 -0
  265. package/es/tokens.js +370 -0
  266. package/es/tokens.js.map +1 -0
  267. package/es/utils.js +7 -0
  268. package/package.json +150 -3
  269. package/preflight.css +422 -0
  270. package/styles-published.css +2 -0
  271. package/styles.css +299 -0
  272. package/tailwind.theme.css +472 -0
  273. package/theme-variables.css +287 -0
  274. package/tokens.css +3 -0
  275. package/types/app.d.ts +6 -0
  276. package/types/app.d.ts.map +1 -0
  277. package/types/assets/images/index.d.ts +10 -0
  278. package/types/assets/images/index.d.ts.map +1 -0
  279. package/types/components/layout/error-page.d.ts +10 -0
  280. package/types/components/layout/error-page.d.ts.map +1 -0
  281. package/types/components/layout/heading.d.ts +29 -0
  282. package/types/components/layout/heading.d.ts.map +1 -0
  283. package/types/components/page-templates/detail-page.d.ts +32 -0
  284. package/types/components/page-templates/detail-page.d.ts.map +1 -0
  285. package/types/components/page-templates/large-page-title.d.ts +43 -0
  286. package/types/components/page-templates/large-page-title.d.ts.map +1 -0
  287. package/types/components/page-templates/list-page.d.ts +44 -0
  288. package/types/components/page-templates/list-page.d.ts.map +1 -0
  289. package/types/components/page-templates/modal-page.d.ts +13 -0
  290. package/types/components/page-templates/modal-page.d.ts.map +1 -0
  291. package/types/components/patterns/color-picker.d.ts +48 -0
  292. package/types/components/patterns/color-picker.d.ts.map +1 -0
  293. package/types/components/patterns/dirty-confirm-dialog.d.ts +16 -0
  294. package/types/components/patterns/dirty-confirm-dialog.d.ts.map +1 -0
  295. package/types/components/patterns/filter-bar-context.d.ts +4 -0
  296. package/types/components/patterns/filter-bar-context.d.ts.map +1 -0
  297. package/types/components/patterns/filter-bar.d.ts +27 -0
  298. package/types/components/patterns/filter-bar.d.ts.map +1 -0
  299. package/types/components/patterns/filters-helpers.d.ts +7 -0
  300. package/types/components/patterns/filters-helpers.d.ts.map +1 -0
  301. package/types/components/patterns/filters.d.ts +262 -0
  302. package/types/components/patterns/filters.d.ts.map +1 -0
  303. package/types/components/patterns/gh-chart.d.ts +44 -0
  304. package/types/components/patterns/gh-chart.d.ts.map +1 -0
  305. package/types/components/patterns/image-upload-variants.d.ts +5 -0
  306. package/types/components/patterns/image-upload-variants.d.ts.map +1 -0
  307. package/types/components/patterns/image-upload.d.ts +15 -0
  308. package/types/components/patterns/image-upload.d.ts.map +1 -0
  309. package/types/components/patterns/kpi-card.d.ts +12 -0
  310. package/types/components/patterns/kpi-card.d.ts.map +1 -0
  311. package/types/components/patterns/kpi-tabs.d.ts +26 -0
  312. package/types/components/patterns/kpi-tabs.d.ts.map +1 -0
  313. package/types/components/patterns/page-header-large-title.d.ts +14 -0
  314. package/types/components/patterns/page-header-large-title.d.ts.map +1 -0
  315. package/types/components/patterns/page-header.d.ts +99 -0
  316. package/types/components/patterns/page-header.d.ts.map +1 -0
  317. package/types/components/patterns/setting-group-variants.d.ts +6 -0
  318. package/types/components/patterns/setting-group-variants.d.ts.map +1 -0
  319. package/types/components/patterns/setting-group.d.ts +22 -0
  320. package/types/components/patterns/setting-group.d.ts.map +1 -0
  321. package/types/components/patterns/settings-modal-variants.d.ts +8 -0
  322. package/types/components/patterns/settings-modal-variants.d.ts.map +1 -0
  323. package/types/components/patterns/settings-modal.d.ts +50 -0
  324. package/types/components/patterns/settings-modal.d.ts.map +1 -0
  325. package/types/components/patterns/share-modal.d.ts +56 -0
  326. package/types/components/patterns/share-modal.d.ts.map +1 -0
  327. package/types/components/patterns/use-dirty-confirmation.d.ts +3 -0
  328. package/types/components/patterns/use-dirty-confirmation.d.ts.map +1 -0
  329. package/types/components/patterns/view-bar.d.ts +13 -0
  330. package/types/components/patterns/view-bar.d.ts.map +1 -0
  331. package/types/components/primitives/box.d.ts +12 -0
  332. package/types/components/primitives/box.d.ts.map +1 -0
  333. package/types/components/primitives/container.d.ts +11 -0
  334. package/types/components/primitives/container.d.ts.map +1 -0
  335. package/types/components/primitives/grid.d.ts +12 -0
  336. package/types/components/primitives/grid.d.ts.map +1 -0
  337. package/types/components/primitives/index.d.ts +10 -0
  338. package/types/components/primitives/index.d.ts.map +1 -0
  339. package/types/components/primitives/inline.d.ts +13 -0
  340. package/types/components/primitives/inline.d.ts.map +1 -0
  341. package/types/components/primitives/stack.d.ts +10 -0
  342. package/types/components/primitives/stack.d.ts.map +1 -0
  343. package/types/components/primitives/text.d.ts +18 -0
  344. package/types/components/primitives/text.d.ts.map +1 -0
  345. package/types/components/primitives/types.d.ts +10 -0
  346. package/types/components/primitives/types.d.ts.map +1 -0
  347. package/types/components/ui/accordion.d.ts +8 -0
  348. package/types/components/ui/accordion.d.ts.map +1 -0
  349. package/types/components/ui/action-list.d.ts +21 -0
  350. package/types/components/ui/action-list.d.ts.map +1 -0
  351. package/types/components/ui/alert-dialog.d.ts +24 -0
  352. package/types/components/ui/alert-dialog.d.ts.map +1 -0
  353. package/types/components/ui/animated-number.d.ts +6 -0
  354. package/types/components/ui/animated-number.d.ts.map +1 -0
  355. package/types/components/ui/avatar.d.ts +17 -0
  356. package/types/components/ui/avatar.d.ts.map +1 -0
  357. package/types/components/ui/badge-variants.d.ts +7 -0
  358. package/types/components/ui/badge-variants.d.ts.map +1 -0
  359. package/types/components/ui/badge.d.ts +9 -0
  360. package/types/components/ui/badge.d.ts.map +1 -0
  361. package/types/components/ui/banner-variants.d.ts +6 -0
  362. package/types/components/ui/banner-variants.d.ts.map +1 -0
  363. package/types/components/ui/banner.d.ts +24 -0
  364. package/types/components/ui/banner.d.ts.map +1 -0
  365. package/types/components/ui/breadcrumb.d.ts +20 -0
  366. package/types/components/ui/breadcrumb.d.ts.map +1 -0
  367. package/types/components/ui/button-variants.d.ts +8 -0
  368. package/types/components/ui/button-variants.d.ts.map +1 -0
  369. package/types/components/ui/button.d.ts +9 -0
  370. package/types/components/ui/button.d.ts.map +1 -0
  371. package/types/components/ui/calendar.d.ts +15 -0
  372. package/types/components/ui/calendar.d.ts.map +1 -0
  373. package/types/components/ui/card-variants.d.ts +5 -0
  374. package/types/components/ui/card-variants.d.ts.map +1 -0
  375. package/types/components/ui/card.d.ts +16 -0
  376. package/types/components/ui/card.d.ts.map +1 -0
  377. package/types/components/ui/chart.d.ts +90 -0
  378. package/types/components/ui/chart.d.ts.map +1 -0
  379. package/types/components/ui/checkbox.d.ts +5 -0
  380. package/types/components/ui/checkbox.d.ts.map +1 -0
  381. package/types/components/ui/code-editor-view.d.ts +17 -0
  382. package/types/components/ui/code-editor-view.d.ts.map +1 -0
  383. package/types/components/ui/code-editor.d.ts +7 -0
  384. package/types/components/ui/code-editor.d.ts.map +1 -0
  385. package/types/components/ui/combobox.d.ts +10 -0
  386. package/types/components/ui/combobox.d.ts.map +1 -0
  387. package/types/components/ui/command.d.ts +22 -0
  388. package/types/components/ui/command.d.ts.map +1 -0
  389. package/types/components/ui/context-menu.d.ts +29 -0
  390. package/types/components/ui/context-menu.d.ts.map +1 -0
  391. package/types/components/ui/copy-field.d.ts +19 -0
  392. package/types/components/ui/copy-field.d.ts.map +1 -0
  393. package/types/components/ui/data-list.d.ts +53 -0
  394. package/types/components/ui/data-list.d.ts.map +1 -0
  395. package/types/components/ui/dialog.d.ts +20 -0
  396. package/types/components/ui/dialog.d.ts.map +1 -0
  397. package/types/components/ui/dropdown-menu.d.ts +28 -0
  398. package/types/components/ui/dropdown-menu.d.ts.map +1 -0
  399. package/types/components/ui/dropzone-variants.d.ts +7 -0
  400. package/types/components/ui/dropzone-variants.d.ts.map +1 -0
  401. package/types/components/ui/dropzone.d.ts +28 -0
  402. package/types/components/ui/dropzone.d.ts.map +1 -0
  403. package/types/components/ui/empty-indicator.d.ts +16 -0
  404. package/types/components/ui/empty-indicator.d.ts.map +1 -0
  405. package/types/components/ui/field.d.ts +25 -0
  406. package/types/components/ui/field.d.ts.map +1 -0
  407. package/types/components/ui/flag.d.ts +11 -0
  408. package/types/components/ui/flag.d.ts.map +1 -0
  409. package/types/components/ui/floating-sidebar-metrics.d.ts +54 -0
  410. package/types/components/ui/floating-sidebar-metrics.d.ts.map +1 -0
  411. package/types/components/ui/floating-sidebar.d.ts +72 -0
  412. package/types/components/ui/floating-sidebar.d.ts.map +1 -0
  413. package/types/components/ui/form-context.d.ts +24 -0
  414. package/types/components/ui/form-context.d.ts.map +1 -0
  415. package/types/components/ui/form.d.ts +14 -0
  416. package/types/components/ui/form.d.ts.map +1 -0
  417. package/types/components/ui/hover-card.d.ts +7 -0
  418. package/types/components/ui/hover-card.d.ts.map +1 -0
  419. package/types/components/ui/icon.d.ts +13 -0
  420. package/types/components/ui/icon.d.ts.map +1 -0
  421. package/types/components/ui/image-overlay-button.d.ts +7 -0
  422. package/types/components/ui/image-overlay-button.d.ts.map +1 -0
  423. package/types/components/ui/indicator-variants.d.ts +11 -0
  424. package/types/components/ui/indicator-variants.d.ts.map +1 -0
  425. package/types/components/ui/indicator.d.ts +9 -0
  426. package/types/components/ui/indicator.d.ts.map +1 -0
  427. package/types/components/ui/input-group-variants.d.ts +6 -0
  428. package/types/components/ui/input-group-variants.d.ts.map +1 -0
  429. package/types/components/ui/input-group.d.ts +18 -0
  430. package/types/components/ui/input-group.d.ts.map +1 -0
  431. package/types/components/ui/input-surface.d.ts +43 -0
  432. package/types/components/ui/input-surface.d.ts.map +1 -0
  433. package/types/components/ui/input.d.ts +4 -0
  434. package/types/components/ui/input.d.ts.map +1 -0
  435. package/types/components/ui/kbd.d.ts +10 -0
  436. package/types/components/ui/kbd.d.ts.map +1 -0
  437. package/types/components/ui/label.d.ts +6 -0
  438. package/types/components/ui/label.d.ts.map +1 -0
  439. package/types/components/ui/link.d.ts +15 -0
  440. package/types/components/ui/link.d.ts.map +1 -0
  441. package/types/components/ui/loading-indicator.d.ts +12 -0
  442. package/types/components/ui/loading-indicator.d.ts.map +1 -0
  443. package/types/components/ui/metric-value.d.ts +16 -0
  444. package/types/components/ui/metric-value.d.ts.map +1 -0
  445. package/types/components/ui/multi-select-combobox.d.ts +80 -0
  446. package/types/components/ui/multi-select-combobox.d.ts.map +1 -0
  447. package/types/components/ui/navbar.d.ts +18 -0
  448. package/types/components/ui/navbar.d.ts.map +1 -0
  449. package/types/components/ui/no-value-label.d.ts +14 -0
  450. package/types/components/ui/no-value-label.d.ts.map +1 -0
  451. package/types/components/ui/pagemenu.d.ts +18 -0
  452. package/types/components/ui/pagemenu.d.ts.map +1 -0
  453. package/types/components/ui/popover.d.ts +9 -0
  454. package/types/components/ui/popover.d.ts.map +1 -0
  455. package/types/components/ui/preview-chrome-variants.d.ts +5 -0
  456. package/types/components/ui/preview-chrome-variants.d.ts.map +1 -0
  457. package/types/components/ui/preview-chrome.d.ts +8 -0
  458. package/types/components/ui/preview-chrome.d.ts.map +1 -0
  459. package/types/components/ui/radio-group-variants.d.ts +5 -0
  460. package/types/components/ui/radio-group-variants.d.ts.map +1 -0
  461. package/types/components/ui/radio-group.d.ts +9 -0
  462. package/types/components/ui/radio-group.d.ts.map +1 -0
  463. package/types/components/ui/select-variants.d.ts +7 -0
  464. package/types/components/ui/select-variants.d.ts.map +1 -0
  465. package/types/components/ui/select.d.ts +20 -0
  466. package/types/components/ui/select.d.ts.map +1 -0
  467. package/types/components/ui/separator.d.ts +5 -0
  468. package/types/components/ui/separator.d.ts.map +1 -0
  469. package/types/components/ui/sheet.d.ts +26 -0
  470. package/types/components/ui/sheet.d.ts.map +1 -0
  471. package/types/components/ui/sidebar-context.d.ts +15 -0
  472. package/types/components/ui/sidebar-context.d.ts.map +1 -0
  473. package/types/components/ui/sidebar.d.ts +56 -0
  474. package/types/components/ui/sidebar.d.ts.map +1 -0
  475. package/types/components/ui/simple-pagination.d.ts +16 -0
  476. package/types/components/ui/simple-pagination.d.ts.map +1 -0
  477. package/types/components/ui/skeleton.d.ts +15 -0
  478. package/types/components/ui/skeleton.d.ts.map +1 -0
  479. package/types/components/ui/sonner.d.ts +5 -0
  480. package/types/components/ui/sonner.d.ts.map +1 -0
  481. package/types/components/ui/sortable-list.d.ts +39 -0
  482. package/types/components/ui/sortable-list.d.ts.map +1 -0
  483. package/types/components/ui/sticky-footer.d.ts +10 -0
  484. package/types/components/ui/sticky-footer.d.ts.map +1 -0
  485. package/types/components/ui/switch.d.ts +11 -0
  486. package/types/components/ui/switch.d.ts.map +1 -0
  487. package/types/components/ui/table.d.ts +21 -0
  488. package/types/components/ui/table.d.ts.map +1 -0
  489. package/types/components/ui/tabs-variants.d.ts +5 -0
  490. package/types/components/ui/tabs-variants.d.ts.map +1 -0
  491. package/types/components/ui/tabs.d.ts +21 -0
  492. package/types/components/ui/tabs.d.ts.map +1 -0
  493. package/types/components/ui/textarea.d.ts +4 -0
  494. package/types/components/ui/textarea.d.ts.map +1 -0
  495. package/types/components/ui/time-picker.d.ts +11 -0
  496. package/types/components/ui/time-picker.d.ts.map +1 -0
  497. package/types/components/ui/toggle-group.d.ts +17 -0
  498. package/types/components/ui/toggle-group.d.ts.map +1 -0
  499. package/types/components/ui/toggle-variants.d.ts +8 -0
  500. package/types/components/ui/toggle-variants.d.ts.map +1 -0
  501. package/types/components/ui/toggle.d.ts +11 -0
  502. package/types/components/ui/toggle.d.ts.map +1 -0
  503. package/types/components/ui/token-field.d.ts +8 -0
  504. package/types/components/ui/token-field.d.ts.map +1 -0
  505. package/types/components/ui/tooltip.d.ts +19 -0
  506. package/types/components/ui/tooltip.d.ts.map +1 -0
  507. package/types/components/ui/trend-badge.d.ts +13 -0
  508. package/types/components/ui/trend-badge.d.ts.map +1 -0
  509. package/types/components.d.ts +81 -0
  510. package/types/components.d.ts.map +1 -0
  511. package/types/hooks/use-global-dirty-state.d.ts +12 -0
  512. package/types/hooks/use-global-dirty-state.d.ts.map +1 -0
  513. package/types/hooks/use-mobile.d.ts +2 -0
  514. package/types/hooks/use-mobile.d.ts.map +1 -0
  515. package/types/hooks/use-simple-pagination.d.ts +45 -0
  516. package/types/hooks/use-simple-pagination.d.ts.map +1 -0
  517. package/types/index.d.ts +6 -0
  518. package/types/index.d.ts.map +1 -0
  519. package/types/lib/ds-utils.d.ts +36 -0
  520. package/types/lib/ds-utils.d.ts.map +1 -0
  521. package/types/lib/overlay-escape.d.ts +8 -0
  522. package/types/lib/overlay-escape.d.ts.map +1 -0
  523. package/types/lib/utils.d.ts +2 -0
  524. package/types/lib/utils.d.ts.map +1 -0
  525. package/types/page-templates.d.ts +6 -0
  526. package/types/page-templates.d.ts.map +1 -0
  527. package/types/patterns.d.ts +23 -0
  528. package/types/patterns.d.ts.map +1 -0
  529. package/types/primitives.d.ts +4 -0
  530. package/types/primitives.d.ts.map +1 -0
  531. package/types/providers/global-dirty-state-provider.d.ts +5 -0
  532. package/types/providers/global-dirty-state-provider.d.ts.map +1 -0
  533. package/types/providers/header-tooltip-provider.d.ts +4 -0
  534. package/types/providers/header-tooltip-provider.d.ts.map +1 -0
  535. package/types/providers/shade-context.d.ts +13 -0
  536. package/types/providers/shade-context.d.ts.map +1 -0
  537. package/types/providers/shade-provider.d.ts +11 -0
  538. package/types/providers/shade-provider.d.ts.map +1 -0
  539. package/types/shade-app.d.ts +17 -0
  540. package/types/shade-app.d.ts.map +1 -0
  541. package/types/shade-scope.d.ts +4 -0
  542. package/types/shade-scope.d.ts.map +1 -0
  543. package/types/tokens.d.ts +4 -0
  544. package/types/tokens.d.ts.map +1 -0
  545. package/types/utils.d.ts +7 -0
  546. package/types/utils.d.ts.map +1 -0
@@ -0,0 +1,1816 @@
1
+ "use client";
2
+ import { cn } from "../../lib/ds-utils.js";
3
+ import { useShade } from "../../providers/shade-context.js";
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip.js";
5
+ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "../ui/dropdown-menu.js";
6
+ import { PageHeader } from "./page-header.js";
7
+ import { useFilterBarContext } from "./filter-bar-context.js";
8
+ import { Calendar as Calendar$1 } from "../ui/calendar.js";
9
+ import { DEFAULT_I18N, createFilter, createOperatorsFromI18n } from "./filters-helpers.js";
10
+ import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from "../ui/command.js";
11
+ import { MultiSelectCombobox } from "../ui/multi-select-combobox.js";
12
+ import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover.js";
13
+ import { Switch } from "../ui/switch.js";
14
+ import { AlertCircle, Calendar, Check, Funnel, FunnelPlus, ListFilter, ListFilterPlus, Loader2, Plus, X } from "lucide-react";
15
+ import { createContext, forwardRef, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
16
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
17
+ import { cva } from "class-variance-authority";
18
+ //#region src/components/patterns/filters.tsx
19
+ var FilterContext = createContext({
20
+ hasFilters: false,
21
+ controlRadius: "md",
22
+ variant: "outline",
23
+ size: "md",
24
+ radius: "md",
25
+ i18n: DEFAULT_I18N,
26
+ cursorPointer: true,
27
+ className: void 0,
28
+ showAddButton: true,
29
+ addButtonText: void 0,
30
+ addButtonIcon: void 0,
31
+ addButtonClassName: void 0,
32
+ addButtonVariant: void 0,
33
+ addButton: void 0,
34
+ showSearchInput: true,
35
+ trigger: void 0,
36
+ allowMultiple: true
37
+ });
38
+ var useFilterContext = () => useContext(FilterContext);
39
+ var SEARCH_RESET_DELAY_MS = 200;
40
+ var filterInputVariants = cva([
41
+ "relative flex shrink-0 items-center text-foreground outline-hidden transition",
42
+ "has-[[data-slot=filters-input]:focus-visible]:ring-focus-ring/30",
43
+ "has-[[data-slot=filters-input]:focus-visible]:border-focus-ring",
44
+ "has-[[data-slot=filters-input]:focus-visible]:outline-hidden",
45
+ "has-[[data-slot=filters-input]:focus-visible]:ring-[3px]",
46
+ "has-[[data-slot=filters-input]:focus-visible]:z-1",
47
+ "has-[[data-slot=filters-input]:[aria-invalid=true]]:border",
48
+ "has-[[data-slot=filters-input]:[aria-invalid=true]]:border-solid",
49
+ "has-[[data-slot=filters-input]:[aria-invalid=true]]:border-destructive/60",
50
+ "has-[[data-slot=filters-input]:[aria-invalid=true]]:ring-destructive/10",
51
+ "dark:has-[[data-slot=filters-input]:[aria-invalid=true]]:border-destructive",
52
+ "dark:has-[[data-slot=filters-input]:[aria-invalid=true]]:ring-destructive/20"
53
+ ], {
54
+ variants: {
55
+ variant: {
56
+ solid: "border-0 bg-secondary",
57
+ outline: "border border-border bg-background"
58
+ },
59
+ size: {
60
+ lg: "h-10 px-2.5 text-sm has-[[data-slot=filters-prefix]]:ps-0 has-[[data-slot=filters-suffix]]:pe-0",
61
+ md: "h-(--control-height) px-2.5 has-[[data-slot=filters-prefix]]:ps-0 has-[[data-slot=filters-suffix]]:pe-0",
62
+ sm: "h-8 px-2 text-xs has-[[data-slot=filters-prefix]]:ps-0 has-[[data-slot=filters-suffix]]:pe-0"
63
+ },
64
+ cursorPointer: {
65
+ true: "cursor-pointer",
66
+ false: ""
67
+ }
68
+ },
69
+ defaultVariants: {
70
+ variant: "outline",
71
+ size: "md",
72
+ cursorPointer: true
73
+ }
74
+ });
75
+ var filterRemoveButtonVariants = cva(["inline-flex shrink-0 items-center justify-center text-muted-foreground transition hover:text-foreground", "focus-visible:ring-1 focus-visible:ring-focus-ring focus-visible:outline-hidden"], {
76
+ variants: {
77
+ variant: {
78
+ solid: "bg-secondary",
79
+ outline: "border border-s-0 border-border hover:bg-secondary"
80
+ },
81
+ size: {
82
+ lg: "size-10 [&_svg:not([class*=size-])]:size-4",
83
+ md: "size-(--control-height) [&_svg:not([class*=size-])]:size-3.5",
84
+ sm: "size-8 [&_svg:not([class*=size-])]:size-3"
85
+ },
86
+ cursorPointer: {
87
+ true: "cursor-pointer",
88
+ false: ""
89
+ },
90
+ radius: {
91
+ md: "rounded-e-md",
92
+ full: "rounded-e-full"
93
+ }
94
+ },
95
+ defaultVariants: {
96
+ variant: "outline",
97
+ size: "md",
98
+ radius: "md",
99
+ cursorPointer: true
100
+ }
101
+ });
102
+ var filterAddButtonVariants = cva([
103
+ "inline-flex shrink-0 items-center justify-center text-foreground transition",
104
+ "[&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 [&_svg]:stroke-[1.5px]",
105
+ "focus-visible:ring-1 focus-visible:ring-focus-ring focus-visible:outline-hidden"
106
+ ], {
107
+ variants: {
108
+ variant: {
109
+ solid: "border border-input hover:bg-secondary/60",
110
+ outline: "border border-control-border hover:bg-interactive-hover",
111
+ ghost: "border border-transparent hover:bg-button-hover",
112
+ secondary: "border border-transparent bg-tab-active text-secondary-foreground hover:bg-secondary"
113
+ },
114
+ size: {
115
+ lg: "h-10 gap-1.5 px-4 text-sm [&_svg:not([class*=size-])]:size-4",
116
+ md: "h-(--control-height) gap-1.5 px-2.5 text-base [&_svg:not([class*=size-])]:size-4",
117
+ sm: "h-8 gap-1.5 px-2.5 text-xs [&_svg:not([class*=size-])]:size-3.5"
118
+ },
119
+ radius: {
120
+ md: "rounded-md",
121
+ full: "rounded-full"
122
+ },
123
+ cursorPointer: {
124
+ true: "cursor-pointer",
125
+ false: ""
126
+ }
127
+ },
128
+ defaultVariants: {
129
+ variant: "outline",
130
+ size: "md",
131
+ cursorPointer: true
132
+ }
133
+ });
134
+ var filterOperatorVariants = cva(["relative flex shrink-0 items-center whitespace-nowrap text-muted-foreground transition hover:text-foreground focus-visible:z-1 data-[state=open]:text-foreground", "focus-visible:ring-1 focus-visible:ring-focus-ring focus-visible:outline-hidden"], {
135
+ variants: {
136
+ variant: {
137
+ solid: "bg-secondary",
138
+ outline: "border border-e-0 border-border bg-background hover:bg-secondary data-[state=open]:bg-secondary [&+[data-slot=filters-remove]]:border-s"
139
+ },
140
+ size: {
141
+ lg: "h-10 gap-1.5 px-4 text-sm",
142
+ md: "h-(--control-height) gap-0.5 px-2.5",
143
+ sm: "h-8 gap-1 px-2.5 text-xs"
144
+ },
145
+ cursorPointer: {
146
+ true: "cursor-pointer",
147
+ false: ""
148
+ },
149
+ readOnly: {
150
+ true: "pointer-events-none text-muted-foreground hover:text-muted-foreground",
151
+ false: ""
152
+ }
153
+ },
154
+ defaultVariants: {
155
+ variant: "outline",
156
+ size: "md",
157
+ cursorPointer: true,
158
+ readOnly: false
159
+ }
160
+ });
161
+ var filterFieldLabelVariants = cva(["pointer-events-none flex shrink-0 items-center gap-1.5 px-1.5 py-1 text-foreground", "[&_svg:not([class*=size-])]:size-4"], {
162
+ variants: {
163
+ variant: {
164
+ solid: "bg-secondary",
165
+ outline: "border border-e-0 border-border"
166
+ },
167
+ size: {
168
+ lg: "h-10 gap-1.5 px-2 text-sm [&_svg:not([class*=size-])]:size-4",
169
+ md: "h-(--control-height) gap-1.5 px-2.5 [&_svg:not([class*=size-])]:size-4",
170
+ sm: "h-8 gap-0.5 px-2.5 text-xs [&_svg:not([class*=size-])]:size-3.5"
171
+ },
172
+ radius: {
173
+ md: "rounded-s-md",
174
+ full: "rounded-s-full"
175
+ }
176
+ },
177
+ defaultVariants: {
178
+ variant: "outline",
179
+ size: "md"
180
+ }
181
+ });
182
+ var filterFieldValueVariants = cva([
183
+ "relative flex min-w-0 shrink items-center gap-1 text-foreground transition focus-visible:z-1",
184
+ "focus-visible:ring-1 focus-visible:ring-focus-ring focus-visible:outline-hidden",
185
+ "has-[[data-slot=filters-input]:focus-visible]:ring-focus-ring/30",
186
+ "has-[[data-slot=filters-input]:focus-visible]:border-focus-ring",
187
+ "has-[[data-slot=filters-input]:focus-visible]:outline-hidden",
188
+ "has-[[data-slot=filters-input]:focus-visible]:ring-[3px]",
189
+ "has-[[data-slot=filters-input]:focus-visible]:z-1",
190
+ "has-[[data-slot=filters-input][aria-invalid=true]]:border",
191
+ "has-[[data-slot=filters-input][aria-invalid=true]]:border-solid",
192
+ "has-[[data-slot=filters-input][aria-invalid=true]]:border-destructive/60",
193
+ "has-[[data-slot=filters-input][aria-invalid=true]]:ring-destructive/10",
194
+ "dark:has-[[data-slot=filters-input][aria-invalid=true]]:border-destructive",
195
+ "dark:has-[[data-slot=filters-input][aria-invalid=true]]:ring-destructive/20"
196
+ ], {
197
+ variants: {
198
+ variant: {
199
+ solid: "bg-secondary",
200
+ outline: "border border-border bg-background hover:bg-secondary has-[[data-slot=switch]]:hover:bg-transparent has-[>[data-slot=filters-input-wrapper]]:hover:bg-background"
201
+ },
202
+ size: {
203
+ lg: "h-10 gap-1.5 px-2 text-sm [&_svg:not([class*=size-])]:size-4",
204
+ md: "h-(--control-height) gap-1.5 px-2.5 [&_svg:not([class*=size-])]:size-4",
205
+ sm: "h-8 gap-0.5 px-2.5 text-xs [&_svg:not([class*=size-])]:size-3.5"
206
+ },
207
+ cursorPointer: {
208
+ true: "cursor-pointer has-[[data-slot=switch]]:cursor-default has-[>[data-slot=filters-input-wrapper]]:cursor-text",
209
+ false: ""
210
+ },
211
+ readOnly: {
212
+ true: "pointer-events-none text-muted-foreground hover:bg-background",
213
+ false: ""
214
+ }
215
+ },
216
+ defaultVariants: {
217
+ variant: "outline",
218
+ size: "md",
219
+ cursorPointer: true,
220
+ readOnly: false
221
+ }
222
+ });
223
+ var filterFieldAddonVariants = cva("flex shrink-0 items-center justify-center text-foreground", {
224
+ variants: {
225
+ variant: {
226
+ solid: "",
227
+ outline: ""
228
+ },
229
+ size: {
230
+ lg: "h-10 px-4 text-sm",
231
+ md: "h-(--control-height) px-2.5",
232
+ sm: "h-8 px-2.5 text-xs"
233
+ }
234
+ },
235
+ defaultVariants: {
236
+ variant: "outline",
237
+ size: "md"
238
+ }
239
+ });
240
+ var filterFieldBetweenVariants = cva("flex shrink-0 items-center text-muted-foreground", {
241
+ variants: {
242
+ variant: {
243
+ solid: "bg-secondary",
244
+ outline: "border border-x-0 border-border bg-background"
245
+ },
246
+ size: {
247
+ lg: "h-10 px-4 text-sm",
248
+ md: "h-(--control-height) px-2.5",
249
+ sm: "h-8 px-2.5 text-xs"
250
+ }
251
+ },
252
+ defaultVariants: {
253
+ variant: "outline",
254
+ size: "md"
255
+ }
256
+ });
257
+ var filtersContainerVariants = cva("relative flex flex-wrap items-center", {
258
+ variants: {
259
+ variant: {
260
+ solid: "gap-2",
261
+ outline: ""
262
+ },
263
+ size: {
264
+ sm: "gap-1.5",
265
+ md: "gap-2.5",
266
+ lg: "gap-3.5"
267
+ }
268
+ },
269
+ defaultVariants: {
270
+ variant: "outline",
271
+ size: "md"
272
+ }
273
+ });
274
+ var filterItemVariants = cva("flex max-w-[calc(100vw-32px)] items-center", {
275
+ variants: { variant: {
276
+ solid: "gap-px",
277
+ outline: ""
278
+ } },
279
+ defaultVariants: { variant: "outline" }
280
+ });
281
+ function FilterInput({ field, onChange, onBlur, onKeyDown, onInputChange, className, inputRef, ...props }) {
282
+ const context = useFilterContext();
283
+ const [isValid, setIsValid] = useState(true);
284
+ const [validationMessage, setValidationMessage] = useState("");
285
+ const validateInput = (value, pattern) => {
286
+ if (!pattern || !value) return true;
287
+ return new RegExp(pattern).test(value);
288
+ };
289
+ const getValidationMessage = (fieldType, hasCustomPattern = false) => {
290
+ if ((fieldType === "text" || fieldType === "number") && hasCustomPattern) return context.i18n.validation.invalid;
291
+ switch (fieldType) {
292
+ case "email": return context.i18n.validation.invalidEmail;
293
+ case "url": return context.i18n.validation.invalidUrl;
294
+ case "tel": return context.i18n.validation.invalidTel;
295
+ default: return context.i18n.validation.invalid;
296
+ }
297
+ };
298
+ const handleChange = (e) => {
299
+ onChange?.(e);
300
+ };
301
+ const handleBlur = (e) => {
302
+ const value = e.target.value;
303
+ const pattern = field?.pattern || props.pattern;
304
+ if (value && pattern) {
305
+ let valid = true;
306
+ if (field?.validation) valid = field.validation(value);
307
+ else valid = validateInput(value, pattern);
308
+ setIsValid(valid);
309
+ const hasCustomPattern = !!(field?.pattern || props.pattern);
310
+ setValidationMessage(valid ? "" : getValidationMessage(field?.type || "", hasCustomPattern));
311
+ } else {
312
+ setIsValid(true);
313
+ setValidationMessage("");
314
+ }
315
+ if (onInputChange) onInputChange(e);
316
+ onBlur?.(e);
317
+ };
318
+ const handleKeyDown = (e) => {
319
+ if (!isValid && ![
320
+ "Tab",
321
+ "Escape",
322
+ "Enter",
323
+ "ArrowUp",
324
+ "ArrowDown",
325
+ "ArrowLeft",
326
+ "ArrowRight"
327
+ ].includes(e.key)) {
328
+ setIsValid(true);
329
+ setValidationMessage("");
330
+ }
331
+ if (e.key === "Enter" && onInputChange) onInputChange({
332
+ ...e,
333
+ target: e.target,
334
+ currentTarget: e.currentTarget
335
+ });
336
+ onKeyDown?.(e);
337
+ };
338
+ return /* @__PURE__ */ jsxs("div", {
339
+ className: cn("w-36", filterInputVariants({
340
+ variant: context.variant,
341
+ size: context.size
342
+ }), className),
343
+ "data-slot": "filters-input-wrapper",
344
+ children: [
345
+ field?.prefix && /* @__PURE__ */ jsx("div", {
346
+ className: filterFieldAddonVariants({
347
+ variant: context.variant,
348
+ size: context.size
349
+ }),
350
+ "data-slot": "filters-prefix",
351
+ children: field.prefix
352
+ }),
353
+ /* @__PURE__ */ jsxs("div", {
354
+ className: "flex w-full items-stretch",
355
+ children: [/* @__PURE__ */ jsx("input", {
356
+ ref: inputRef,
357
+ "aria-describedby": !isValid && validationMessage ? `${field?.key || "input"}-error` : void 0,
358
+ "aria-invalid": !isValid,
359
+ autoComplete: "off",
360
+ className: "w-full bg-transparent outline-hidden dark:!bg-transparent",
361
+ "data-form-type": "other",
362
+ "data-lpignore": "true",
363
+ "data-slot": "filters-input",
364
+ "data-1p-ignore": true,
365
+ onBlur: handleBlur,
366
+ onChange: handleChange,
367
+ onKeyDown: handleKeyDown,
368
+ ...props
369
+ }), !isValid && validationMessage && /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
370
+ asChild: true,
371
+ children: /* @__PURE__ */ jsx("div", {
372
+ className: "absolute top-1/2 right-2 flex -translate-y-1/2 items-center",
373
+ children: /* @__PURE__ */ jsx(AlertCircle, { className: "size-3.5 text-destructive" })
374
+ })
375
+ }), /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: validationMessage }) })] })]
376
+ }),
377
+ field?.suffix && /* @__PURE__ */ jsx("div", {
378
+ className: cn(filterFieldAddonVariants({
379
+ variant: context.variant,
380
+ size: context.size
381
+ })),
382
+ "data-slot": "filters-suffix",
383
+ children: field.suffix
384
+ })
385
+ ]
386
+ });
387
+ }
388
+ var parseFilterDateValue = (value) => {
389
+ const match = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
390
+ if (!match) return;
391
+ const [, yearPart, monthPart, dayPart] = match;
392
+ const year = Number(yearPart);
393
+ const month = Number(monthPart);
394
+ const day = Number(dayPart);
395
+ const date = new Date(year, month - 1, day);
396
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) return;
397
+ return date;
398
+ };
399
+ var formatFilterDateValue = (date) => {
400
+ if (!date) return "";
401
+ return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
402
+ };
403
+ function FilterDatePicker({ field, value, onChange, className, embedded = false }) {
404
+ const context = useFilterContext();
405
+ const [open, setOpen] = useState(false);
406
+ const parsed = useMemo(() => parseFilterDateValue(value), [value]);
407
+ const [month, setMonth] = useState(parsed);
408
+ const inputRef = useRef(null);
409
+ const lastLocalCommitRef = useRef(value);
410
+ const [localValue, setLocalValue] = useState(value);
411
+ useEffect(() => {
412
+ if (parsed) setMonth(parsed);
413
+ }, [parsed]);
414
+ useEffect(() => {
415
+ if (value === lastLocalCommitRef.current) return;
416
+ if (document.activeElement !== inputRef.current) {
417
+ setLocalValue(value);
418
+ lastLocalCommitRef.current = value;
419
+ }
420
+ }, [value]);
421
+ const notifyInputChange = (nextValue, input = inputRef.current) => {
422
+ if (!field?.onInputChange || !input) return;
423
+ field.onInputChange({
424
+ target: {
425
+ ...input,
426
+ value: nextValue
427
+ },
428
+ currentTarget: {
429
+ ...input,
430
+ value: nextValue
431
+ }
432
+ });
433
+ };
434
+ const handleInputChange = (e) => {
435
+ setLocalValue(e.target.value);
436
+ };
437
+ const handleInputBlur = (e) => {
438
+ const inputValue = e.target.value;
439
+ const parsedInputValue = parseFilterDateValue(inputValue);
440
+ const dateValue = inputValue && !parsedInputValue ? formatFilterDateValue(/* @__PURE__ */ new Date()) : inputValue;
441
+ if (parsedInputValue) setMonth(parsedInputValue);
442
+ else if (dateValue) setMonth(parseFilterDateValue(dateValue));
443
+ if (dateValue !== inputValue) {
444
+ if (inputRef.current) inputRef.current.value = dateValue;
445
+ setLocalValue(dateValue);
446
+ }
447
+ if (dateValue !== value) {
448
+ lastLocalCommitRef.current = dateValue;
449
+ onChange(dateValue);
450
+ }
451
+ notifyInputChange(dateValue, e.target);
452
+ };
453
+ const handleSelect = (date) => {
454
+ if (!date) {
455
+ lastLocalCommitRef.current = "";
456
+ if (inputRef.current) inputRef.current.value = "";
457
+ setLocalValue("");
458
+ onChange("");
459
+ notifyInputChange("");
460
+ return;
461
+ }
462
+ const formatted = formatFilterDateValue(date);
463
+ lastLocalCommitRef.current = formatted;
464
+ if (inputRef.current) inputRef.current.value = formatted;
465
+ setMonth(date);
466
+ setLocalValue(formatted);
467
+ onChange(formatted);
468
+ notifyInputChange(formatted);
469
+ setOpen(false);
470
+ };
471
+ return /* @__PURE__ */ jsxs("div", {
472
+ className: cn(embedded ? "flex w-full min-w-0 items-center" : cn("w-32", filterInputVariants({
473
+ variant: context.variant,
474
+ size: context.size,
475
+ cursorPointer: false
476
+ })), className),
477
+ "data-slot": "filters-input-wrapper",
478
+ children: [
479
+ field?.prefix && /* @__PURE__ */ jsx("div", {
480
+ className: filterFieldAddonVariants({
481
+ variant: context.variant,
482
+ size: context.size
483
+ }),
484
+ "data-slot": "filters-prefix",
485
+ children: field.prefix
486
+ }),
487
+ /* @__PURE__ */ jsx("div", {
488
+ className: "flex w-full min-w-0 items-stretch",
489
+ children: /* @__PURE__ */ jsx("input", {
490
+ ref: inputRef,
491
+ autoComplete: "off",
492
+ className: "w-full min-w-0 bg-transparent outline-hidden dark:!bg-transparent",
493
+ "data-slot": "filters-input",
494
+ inputMode: "numeric",
495
+ pattern: "\\d{4}-\\d{2}-\\d{2}",
496
+ placeholder: "YYYY-MM-DD",
497
+ type: "text",
498
+ value: localValue,
499
+ onBlur: handleInputBlur,
500
+ onChange: handleInputChange
501
+ })
502
+ }),
503
+ /* @__PURE__ */ jsxs(Popover, {
504
+ open,
505
+ onOpenChange: setOpen,
506
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
507
+ asChild: true,
508
+ children: /* @__PURE__ */ jsx("button", {
509
+ "aria-label": "Open calendar",
510
+ className: cn(filterFieldAddonVariants({
511
+ variant: context.variant,
512
+ size: context.size
513
+ }), "cursor-pointer text-muted-foreground transition-colors hover:text-foreground"),
514
+ "data-slot": "filters-suffix",
515
+ type: "button",
516
+ children: /* @__PURE__ */ jsx(Calendar, { className: "size-3.5" })
517
+ })
518
+ }), /* @__PURE__ */ jsx(PopoverContent, {
519
+ align: "center",
520
+ className: "w-auto overflow-hidden p-0",
521
+ sideOffset: 4,
522
+ children: /* @__PURE__ */ jsx(Calendar$1, {
523
+ captionLayout: "dropdown-months",
524
+ mode: "single",
525
+ month,
526
+ selected: parsed,
527
+ onMonthChange: setMonth,
528
+ onSelect: handleSelect
529
+ })
530
+ })]
531
+ })
532
+ ]
533
+ });
534
+ }
535
+ function FilterRemoveButton({ className, icon = /* @__PURE__ */ jsx(X, {}), ...props }) {
536
+ const context = useFilterContext();
537
+ return /* @__PURE__ */ jsx("button", {
538
+ className: cn(filterRemoveButtonVariants({
539
+ variant: context.variant,
540
+ size: context.size,
541
+ cursorPointer: context.cursorPointer,
542
+ radius: context.radius
543
+ }), className),
544
+ "data-slot": "filters-remove",
545
+ ...props,
546
+ type: "button",
547
+ children: icon
548
+ });
549
+ }
550
+ var isFieldGroup = (item) => {
551
+ return "fields" in item && Array.isArray(item.fields);
552
+ };
553
+ var isGroupLevelField = (field) => {
554
+ return Boolean(field.group && field.fields);
555
+ };
556
+ var flattenFields = (fields) => {
557
+ return fields.reduce((acc, item) => {
558
+ if (isFieldGroup(item)) return [...acc, ...item.fields];
559
+ if (isGroupLevelField(item)) return [...acc, ...item.fields];
560
+ return [...acc, item];
561
+ }, []);
562
+ };
563
+ var getFieldsMap = (fields) => {
564
+ return flattenFields(fields).reduce((acc, field) => {
565
+ if (field.key) acc[field.key] = field;
566
+ return acc;
567
+ }, {});
568
+ };
569
+ var getOperatorsForField = (field, values, i18n) => {
570
+ if (field.operators) return field.operators;
571
+ const operators = createOperatorsFromI18n(i18n);
572
+ let fieldType = field.type || "select";
573
+ if (fieldType === "select" && values.length > 1) fieldType = "multiselect";
574
+ if (fieldType === "multiselect" || field.type === "multiselect") return operators.multiselect;
575
+ return operators[fieldType] || operators.select;
576
+ };
577
+ function SegmentDropdown({ trigger, options, value, onChange, readOnly, ariaLabel, testId }) {
578
+ const context = useFilterContext();
579
+ if (readOnly) return /* @__PURE__ */ jsx("div", {
580
+ "aria-label": ariaLabel,
581
+ className: filterOperatorVariants({
582
+ variant: context.variant,
583
+ size: context.size,
584
+ readOnly: true
585
+ }),
586
+ "data-testid": testId,
587
+ children: trigger
588
+ });
589
+ return /* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
590
+ "aria-label": ariaLabel,
591
+ className: filterOperatorVariants({
592
+ variant: context.variant,
593
+ size: context.size
594
+ }),
595
+ "data-testid": testId,
596
+ children: trigger
597
+ }), /* @__PURE__ */ jsx(DropdownMenuContent, {
598
+ align: "start",
599
+ className: "w-fit min-w-fit",
600
+ children: options.map((option) => /* @__PURE__ */ jsxs(DropdownMenuItem, {
601
+ className: "flex items-center justify-between",
602
+ onClick: () => onChange(option.value),
603
+ children: [/* @__PURE__ */ jsx("span", { children: option.label }), /* @__PURE__ */ jsx(Check, { className: `ms-auto text-primary ${option.value === value ? "opacity-100" : "opacity-0"}` })]
604
+ }, option.value))
605
+ })] });
606
+ }
607
+ function FilterOperatorDropdown({ field, operator, values, onChange }) {
608
+ const context = useFilterContext();
609
+ const operators = getOperatorsForField(field, values, context.i18n);
610
+ const operatorLabel = operators.find((op) => op.value === operator)?.label || context.i18n.helpers.formatOperator(operator);
611
+ return /* @__PURE__ */ jsx(SegmentDropdown, {
612
+ options: operators,
613
+ readOnly: field.readOnly || field.hideOperatorSelect || operators.length === 1,
614
+ trigger: operatorLabel,
615
+ value: operator,
616
+ onChange
617
+ });
618
+ }
619
+ function FilterSegmentSelect({ value, options, onChange, placeholder, ariaLabel, className, testId, readOnly }) {
620
+ const selected = options.find((option) => option.value === value);
621
+ return /* @__PURE__ */ jsx(SegmentDropdown, {
622
+ ariaLabel,
623
+ options,
624
+ readOnly,
625
+ testId,
626
+ trigger: /* @__PURE__ */ jsx("span", {
627
+ className: cn(selected ? void 0 : "text-muted-foreground", className),
628
+ children: selected ? selected.label : placeholder
629
+ }),
630
+ value,
631
+ onChange
632
+ });
633
+ }
634
+ function FilterSegmentMultiSelect({ values, options, onChange, placeholder, searchPlaceholder, ariaLabel, className, testId, readOnly }) {
635
+ const context = useFilterContext();
636
+ const selected = options.filter((option) => values.includes(option.value));
637
+ let text = placeholder ?? context.i18n.select;
638
+ if (selected.length === 1) text = selected[0].label;
639
+ else if (selected.length > 1) text = `${selected.length} ${context.i18n.selectedCount}`;
640
+ const trigger = /* @__PURE__ */ jsx("span", {
641
+ className: cn("truncate", selected.length ? void 0 : "text-muted-foreground", className),
642
+ children: text
643
+ });
644
+ if (readOnly) return /* @__PURE__ */ jsx("div", {
645
+ "aria-label": ariaLabel,
646
+ className: filterOperatorVariants({
647
+ variant: context.variant,
648
+ size: context.size,
649
+ readOnly: true
650
+ }),
651
+ "data-testid": testId,
652
+ children: trigger
653
+ });
654
+ return /* @__PURE__ */ jsxs(Popover, { children: [/* @__PURE__ */ jsx(PopoverTrigger, {
655
+ "aria-label": ariaLabel,
656
+ className: cn("max-w-60", filterOperatorVariants({
657
+ variant: context.variant,
658
+ size: context.size
659
+ })),
660
+ "data-testid": testId,
661
+ children: trigger
662
+ }), /* @__PURE__ */ jsx(PopoverContent, {
663
+ align: "start",
664
+ className: "w-64 p-0",
665
+ children: /* @__PURE__ */ jsx(MultiSelectCombobox, {
666
+ i18n: {
667
+ searchPlaceholder: searchPlaceholder ?? context.i18n.placeholders.searchField(ariaLabel ?? ""),
668
+ noResultsFound: context.i18n.noResultsFound,
669
+ loading: context.i18n.loading,
670
+ loadMore: context.i18n.loadMore
671
+ },
672
+ options,
673
+ values,
674
+ onChange
675
+ })
676
+ })] });
677
+ }
678
+ function FilterSegmentInput({ value, onChange, placeholder, ariaLabel, className, testId, readOnly }) {
679
+ const context = useFilterContext();
680
+ return /* @__PURE__ */ jsx("div", {
681
+ className: cn("w-36", filterInputVariants({
682
+ variant: context.variant,
683
+ size: context.size
684
+ }), className),
685
+ "data-slot": "filters-input-wrapper",
686
+ children: readOnly ? /* @__PURE__ */ jsx("span", {
687
+ "aria-label": ariaLabel,
688
+ className: "block w-full truncate text-muted-foreground",
689
+ "data-slot": "filters-input",
690
+ "data-testid": testId,
691
+ children: value || placeholder
692
+ }) : /* @__PURE__ */ jsx("input", {
693
+ "aria-label": ariaLabel,
694
+ autoComplete: "off",
695
+ className: "w-full bg-transparent outline-hidden",
696
+ "data-slot": "filters-input",
697
+ "data-testid": testId,
698
+ placeholder,
699
+ value,
700
+ onChange: (event) => onChange(event.target.value)
701
+ })
702
+ });
703
+ }
704
+ var TYPED_VALUE_FIELD_TYPES = [
705
+ "text",
706
+ "number",
707
+ "email",
708
+ "url",
709
+ "tel"
710
+ ];
711
+ function SelectOptionsSearchInput({ searchable, label, searchInput, isSearching, className, onSearchChange }) {
712
+ const context = useFilterContext();
713
+ if (!searchable) return null;
714
+ return /* @__PURE__ */ jsxs("div", {
715
+ className: "relative",
716
+ children: [/* @__PURE__ */ jsx(CommandInput, {
717
+ className,
718
+ placeholder: context.i18n.placeholders.searchField(label || ""),
719
+ value: searchInput,
720
+ onValueChange: onSearchChange
721
+ }), isSearching && /* @__PURE__ */ jsx(Loader2, { className: "pointer-events-none absolute top-1/2 right-3 size-4 -translate-y-1/2 animate-spin text-muted-foreground" })]
722
+ });
723
+ }
724
+ function filterOptionsBySearchInput(options, searchInput) {
725
+ const normalizedSearch = searchInput.trim().toLowerCase();
726
+ if (!normalizedSearch) return options;
727
+ return options.filter((option) => {
728
+ return option.label.toLowerCase().includes(normalizedSearch) || option.detail?.toLowerCase().includes(normalizedSearch);
729
+ });
730
+ }
731
+ /**
732
+ * What a row's tooltip says. The detail is not rendered beside the label, so
733
+ * this is the only place it surfaces — enough to tell two same-named options
734
+ * apart when you need to, without spending row width on it always.
735
+ */
736
+ function optionTitle(option) {
737
+ return option.detail ? `${option.label} — ${option.detail}` : option.label;
738
+ }
739
+ function SelectOptionsList({ contextLabel, selectedOptions, unselectedOptions, isInitialLoad, isLoadingMore, hasMore, onLoadMore, onSelectSelected, onSelectUnselected }) {
740
+ const context = useFilterContext();
741
+ return /* @__PURE__ */ jsxs(CommandList, {
742
+ className: "outline-hidden",
743
+ children: [
744
+ isInitialLoad ? /* @__PURE__ */ jsxs("div", {
745
+ className: "flex items-center justify-center py-6 text-muted-foreground",
746
+ children: [/* @__PURE__ */ jsx(Loader2, { className: "mr-2 size-4 animate-spin" }), context.i18n.loading]
747
+ }) : /* @__PURE__ */ jsx(CommandEmpty, { children: context.i18n.noResultsFound }),
748
+ selectedOptions.length > 0 && /* @__PURE__ */ jsx(CommandGroup, {
749
+ heading: contextLabel,
750
+ children: selectedOptions.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
751
+ className: "group flex items-center gap-2",
752
+ onSelect: () => onSelectSelected(option),
753
+ children: [
754
+ option.icon && option.icon,
755
+ /* @__PURE__ */ jsx("span", {
756
+ className: "min-w-0 flex-1 truncate text-accent-foreground",
757
+ title: optionTitle(option),
758
+ children: option.label
759
+ }),
760
+ /* @__PURE__ */ jsx(Check, { className: "shrink-0 text-primary" })
761
+ ]
762
+ }, String(option.value)))
763
+ }),
764
+ unselectedOptions.length > 0 && /* @__PURE__ */ jsxs(Fragment$1, { children: [selectedOptions.length > 0 && /* @__PURE__ */ jsx(CommandSeparator, {}), /* @__PURE__ */ jsx(CommandGroup, { children: unselectedOptions.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
765
+ className: "group flex items-center gap-2",
766
+ keywords: [option.label, ...option.detail ? [option.detail] : []],
767
+ value: String(option.value),
768
+ onSelect: () => onSelectUnselected(option),
769
+ children: [option.icon && option.icon, /* @__PURE__ */ jsx("span", {
770
+ className: "min-w-0 flex-1 truncate text-accent-foreground",
771
+ title: optionTitle(option),
772
+ children: option.label
773
+ })]
774
+ }, String(option.value))) })] }),
775
+ hasMore && /* @__PURE__ */ jsxs(Fragment$1, { children: [(selectedOptions.length > 0 || unselectedOptions.length > 0) && /* @__PURE__ */ jsx(CommandSeparator, {}), /* @__PURE__ */ jsx("div", {
776
+ className: "p-1.5",
777
+ children: /* @__PURE__ */ jsxs("button", {
778
+ className: "flex w-full items-center justify-center rounded-menu-item px-2.5 py-1.5 text-muted-foreground hover:bg-interactive-hover hover:text-accent-foreground disabled:opacity-50",
779
+ disabled: isLoadingMore,
780
+ type: "button",
781
+ onClick: onLoadMore,
782
+ children: [isLoadingMore && /* @__PURE__ */ jsx(Loader2, { className: "mr-2 size-4 animate-spin" }), isLoadingMore ? context.i18n.loading : context.i18n.loadMore]
783
+ })
784
+ })] })
785
+ ]
786
+ });
787
+ }
788
+ function ResolvedSelectOptionsPopover({ field, values, onChange, onClose, inline = false, searchInput, onSearchChange, shouldClientFilter, isInitialLoad, isSearching, isLoadingMore, hasMore, onLoadMore }) {
789
+ const [open, setOpen] = useState(false);
790
+ const [cachedSelectedOptions, setCachedSelectedOptions] = useState([]);
791
+ const context = useFilterContext();
792
+ const isMultiSelect = field.type === "multiselect" || values.length > 1;
793
+ const effectiveValues = useMemo(() => field.value ?? values, [field.value, values]);
794
+ useEffect(() => {
795
+ if (open && field.searchable !== false) setTimeout(() => {
796
+ const input = document.querySelector("[cmdk-input]");
797
+ if (input) input.focus();
798
+ }, 0);
799
+ }, [open, field.searchable]);
800
+ const optionsFromField = useMemo(() => field.options?.filter((opt) => effectiveValues.includes(opt.value)) || [], [field.options, effectiveValues]);
801
+ useEffect(() => {
802
+ if (effectiveValues.length === 0) {
803
+ setCachedSelectedOptions([]);
804
+ return;
805
+ }
806
+ if (optionsFromField.length > 0) setCachedSelectedOptions((prev) => {
807
+ const result = [];
808
+ for (const value of effectiveValues) {
809
+ const option = optionsFromField.find((opt) => opt.value === value) ?? prev.find((opt) => opt.value === value);
810
+ if (option) result.push(option);
811
+ }
812
+ return result;
813
+ });
814
+ }, [optionsFromField, effectiveValues]);
815
+ const selectedOptions = useMemo(() => {
816
+ if (effectiveValues.length === 0) return [];
817
+ return cachedSelectedOptions.length > 0 ? cachedSelectedOptions : optionsFromField;
818
+ }, [
819
+ cachedSelectedOptions,
820
+ effectiveValues.length,
821
+ optionsFromField
822
+ ]);
823
+ const visibleSelectedOptions = useMemo(() => {
824
+ return filterOptionsBySearchInput(selectedOptions, searchInput);
825
+ }, [searchInput, selectedOptions]);
826
+ const unselectedOptions = field.options?.filter((opt) => !effectiveValues.includes(opt.value)) || [];
827
+ const handleSearchChange = (value) => {
828
+ onSearchChange(value);
829
+ };
830
+ const handleClose = () => {
831
+ setOpen(false);
832
+ setTimeout(() => onSearchChange(""), SEARCH_RESET_DELAY_MS);
833
+ onClose?.();
834
+ };
835
+ if (inline) return /* @__PURE__ */ jsx("div", {
836
+ className: "w-full",
837
+ children: /* @__PURE__ */ jsxs(Command, {
838
+ shouldFilter: shouldClientFilter,
839
+ children: [/* @__PURE__ */ jsx(SelectOptionsSearchInput, {
840
+ className: "h-(--control-height) pr-8",
841
+ isSearching,
842
+ label: field.label,
843
+ searchable: field.searchable !== false,
844
+ searchInput,
845
+ onSearchChange: handleSearchChange
846
+ }), /* @__PURE__ */ jsx(SelectOptionsList, {
847
+ contextLabel: field.label || "Selected",
848
+ hasMore,
849
+ isInitialLoad,
850
+ isLoadingMore,
851
+ selectedOptions: visibleSelectedOptions,
852
+ unselectedOptions,
853
+ onLoadMore,
854
+ onSelectSelected: (option) => {
855
+ if (isMultiSelect) {
856
+ const next = effectiveValues.filter((v) => v !== option.value);
857
+ if (field.onValueChange) field.onValueChange(next);
858
+ else onChange(next);
859
+ } else if (field.onValueChange) field.onValueChange([]);
860
+ else onChange([]);
861
+ },
862
+ onSelectUnselected: (option) => {
863
+ if (isMultiSelect) {
864
+ const newValues = [...effectiveValues, option.value];
865
+ if (field.maxSelections && newValues.length > field.maxSelections) return;
866
+ if (field.onValueChange) field.onValueChange(newValues);
867
+ else onChange(newValues);
868
+ if (field.autoCloseOnSelect) onClose?.();
869
+ } else {
870
+ if (field.onValueChange) field.onValueChange([option.value]);
871
+ else onChange([option.value]);
872
+ onClose?.();
873
+ }
874
+ }
875
+ })]
876
+ })
877
+ });
878
+ return /* @__PURE__ */ jsxs(Popover, {
879
+ open,
880
+ onOpenChange: (isOpen) => {
881
+ setOpen(isOpen);
882
+ if (!isOpen) setTimeout(() => onSearchChange(""), SEARCH_RESET_DELAY_MS);
883
+ },
884
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
885
+ className: cn(filterFieldValueVariants({
886
+ variant: context.variant,
887
+ size: context.size,
888
+ cursorPointer: context.cursorPointer
889
+ }), field.triggerClassName ?? "max-w-60"),
890
+ "data-slot": "filters-value",
891
+ children: /* @__PURE__ */ jsx("div", {
892
+ className: "flex min-w-0 items-center gap-1.5",
893
+ children: field.customValueRenderer ? field.customValueRenderer(values, field.options || []) : /* @__PURE__ */ jsxs(Fragment$1, { children: [selectedOptions.length > 0 && selectedOptions.some((option) => option.icon) && /* @__PURE__ */ jsx("div", {
894
+ className: cn("flex shrink-0 items-center -space-x-0.5", field.selectedOptionsClassName),
895
+ children: selectedOptions.slice(0, 3).map((option) => /* @__PURE__ */ jsx("div", { children: option.icon }, String(option.value)))
896
+ }), selectedOptions.length === 1 ? /* @__PURE__ */ jsx("span", {
897
+ className: "min-w-0 truncate text-accent-foreground",
898
+ title: selectedOptions[0].detail ? `${selectedOptions[0].label} - ${selectedOptions[0].detail}` : selectedOptions[0].label,
899
+ children: selectedOptions[0].label
900
+ }) : selectedOptions.length > 1 ? `${selectedOptions.length} ${context.i18n.selectedCount}` : context.i18n.select] })
901
+ })
902
+ }), /* @__PURE__ */ jsx(PopoverContent, {
903
+ align: "start",
904
+ className: cn("data-[state=closed]:animation-none! p-0 data-[state=closed]:duration-0!", field.className || "w-[200px]"),
905
+ children: /* @__PURE__ */ jsxs(Command, {
906
+ shouldFilter: shouldClientFilter,
907
+ children: [/* @__PURE__ */ jsx(SelectOptionsSearchInput, {
908
+ className: "h-(--control-height) pr-8",
909
+ isSearching,
910
+ label: field.label,
911
+ searchable: field.searchable !== false,
912
+ searchInput,
913
+ onSearchChange: handleSearchChange
914
+ }), /* @__PURE__ */ jsx(SelectOptionsList, {
915
+ hasMore,
916
+ isInitialLoad,
917
+ isLoadingMore,
918
+ selectedOptions: visibleSelectedOptions,
919
+ unselectedOptions,
920
+ onLoadMore,
921
+ onSelectSelected: (option) => {
922
+ if (isMultiSelect) onChange(values.filter((v) => v !== option.value));
923
+ else onChange([]);
924
+ if (!isMultiSelect) {
925
+ setOpen(false);
926
+ handleClose();
927
+ }
928
+ },
929
+ onSelectUnselected: (option) => {
930
+ if (isMultiSelect) {
931
+ const newValues = [...values, option.value];
932
+ if (field.maxSelections && newValues.length > field.maxSelections) return;
933
+ onChange(newValues);
934
+ if (field.autoCloseOnSelect) handleClose();
935
+ } else {
936
+ onChange([option.value]);
937
+ setOpen(false);
938
+ handleClose();
939
+ }
940
+ }
941
+ })]
942
+ })
943
+ })]
944
+ });
945
+ }
946
+ function ValueSourceSelectOptionsPopover({ field, values, onChange, onClose, inline = false, searchInput, onSearchChange }) {
947
+ const effectiveValues = useMemo(() => field.value ?? values, [field.value, values]);
948
+ const sourceState = field.valueSource.useOptions({
949
+ query: searchInput,
950
+ selectedValues: effectiveValues
951
+ });
952
+ return /* @__PURE__ */ jsx(ResolvedSelectOptionsPopover, {
953
+ field: useMemo(() => ({
954
+ ...field,
955
+ options: sourceState.options
956
+ }), [field, sourceState.options]),
957
+ hasMore: sourceState.hasMore,
958
+ inline,
959
+ isInitialLoad: sourceState.isInitialLoad,
960
+ isLoadingMore: sourceState.isLoadingMore,
961
+ isSearching: sourceState.isSearching,
962
+ searchInput,
963
+ shouldClientFilter: false,
964
+ values,
965
+ onChange,
966
+ onClose,
967
+ onLoadMore: sourceState.loadMore,
968
+ onSearchChange
969
+ });
970
+ }
971
+ function SelectOptionsPopover({ field, values, onChange, onClose, inline = false }) {
972
+ const [searchInput, setSearchInput] = useState("");
973
+ const staticOptionsCount = field.options?.length ?? 0;
974
+ if (field.valueSource) return /* @__PURE__ */ jsx(ValueSourceSelectOptionsPopover, {
975
+ field,
976
+ inline,
977
+ searchInput,
978
+ values,
979
+ onChange,
980
+ onClose,
981
+ onSearchChange: setSearchInput
982
+ }, field.valueSource.id);
983
+ return /* @__PURE__ */ jsx(ResolvedSelectOptionsPopover, {
984
+ field,
985
+ hasMore: false,
986
+ inline,
987
+ isInitialLoad: !!field.isLoading && staticOptionsCount === 0,
988
+ isLoadingMore: false,
989
+ isSearching: !!field.isLoading && staticOptionsCount > 0,
990
+ searchInput,
991
+ shouldClientFilter: true,
992
+ values,
993
+ onChange,
994
+ onClose,
995
+ onLoadMore: () => {},
996
+ onSearchChange: setSearchInput
997
+ });
998
+ }
999
+ function FilterValueSelector({ field, values, onChange, operator, onOperatorChange, readOnly, autoFocus }) {
1000
+ const [open, setOpen] = useState(false);
1001
+ const [searchInput, setSearchInput] = useState("");
1002
+ const context = useFilterContext();
1003
+ const valueInputRef = useRef(null);
1004
+ useEffect(() => {
1005
+ if (open && field.searchable !== false) setTimeout(() => {
1006
+ const input = document.querySelector("[cmdk-input]");
1007
+ if (input) input.focus();
1008
+ }, 0);
1009
+ }, [open, field.searchable]);
1010
+ useEffect(() => {
1011
+ if (autoFocus) valueInputRef.current?.focus();
1012
+ }, [autoFocus]);
1013
+ if (operator === "empty" || operator === "not_empty") return null;
1014
+ if (field.customRenderer) {
1015
+ if (field.renderOperatorInValue) return /* @__PURE__ */ jsx(Fragment$1, { children: field.customRenderer({
1016
+ field,
1017
+ values,
1018
+ onChange,
1019
+ operator,
1020
+ onOperatorChange,
1021
+ readOnly
1022
+ }) });
1023
+ return /* @__PURE__ */ jsx("div", {
1024
+ className: cn(filterFieldValueVariants({
1025
+ variant: context.variant,
1026
+ size: context.size,
1027
+ cursorPointer: field.staticValue ? false : context.cursorPointer,
1028
+ readOnly
1029
+ }), field.staticValue && "pointer-events-none"),
1030
+ "data-slot": "filters-value",
1031
+ children: field.customRenderer({
1032
+ field,
1033
+ values,
1034
+ onChange,
1035
+ operator,
1036
+ onOperatorChange,
1037
+ readOnly
1038
+ })
1039
+ });
1040
+ }
1041
+ if (readOnly) return /* @__PURE__ */ jsx("div", {
1042
+ className: filterFieldValueVariants({
1043
+ variant: context.variant,
1044
+ size: context.size,
1045
+ cursorPointer: context.cursorPointer,
1046
+ readOnly: true
1047
+ }),
1048
+ "data-slot": "filters-value",
1049
+ children: field.customValueRenderer ? field.customValueRenderer(values, field.options ?? []) : values.map((currentValue) => {
1050
+ const option = field.options?.find((candidate) => candidate.value === currentValue);
1051
+ return option ? option.label : String(currentValue);
1052
+ }).filter(Boolean).join(", ")
1053
+ });
1054
+ if (field.type === "boolean") {
1055
+ const isChecked = values[0] === true;
1056
+ const onLabel = field.onLabel || context.i18n.true;
1057
+ const offLabel = field.offLabel || context.i18n.false;
1058
+ return /* @__PURE__ */ jsx("div", {
1059
+ className: filterFieldValueVariants({
1060
+ variant: context.variant,
1061
+ size: context.size,
1062
+ cursorPointer: context.cursorPointer
1063
+ }),
1064
+ "data-slot": "filters-value",
1065
+ children: /* @__PURE__ */ jsxs("div", {
1066
+ className: "flex items-center gap-2",
1067
+ children: [/* @__PURE__ */ jsx(Switch, {
1068
+ checked: isChecked,
1069
+ size: "sm",
1070
+ onCheckedChange: (checked) => onChange([checked])
1071
+ }), field.onLabel && field.offLabel && /* @__PURE__ */ jsx("span", {
1072
+ className: "text-xs text-muted-foreground",
1073
+ children: isChecked ? onLabel : offLabel
1074
+ })]
1075
+ })
1076
+ });
1077
+ }
1078
+ if (field.type === "time") {
1079
+ if (operator === "between") {
1080
+ const startTime = values[0] || "";
1081
+ const endTime = values[1] || "";
1082
+ return /* @__PURE__ */ jsxs("div", {
1083
+ className: "flex items-center",
1084
+ "data-slot": "filters-item",
1085
+ children: [
1086
+ /* @__PURE__ */ jsx(FilterInput, {
1087
+ className: field.className,
1088
+ field,
1089
+ type: "time",
1090
+ value: startTime,
1091
+ onChange: (e) => onChange([e.target.value, endTime]),
1092
+ onInputChange: field.onInputChange
1093
+ }),
1094
+ /* @__PURE__ */ jsx("div", {
1095
+ className: filterFieldBetweenVariants({
1096
+ variant: context.variant,
1097
+ size: context.size
1098
+ }),
1099
+ "data-slot": "filters-between",
1100
+ children: context.i18n.to
1101
+ }),
1102
+ /* @__PURE__ */ jsx(FilterInput, {
1103
+ className: field.className,
1104
+ field,
1105
+ type: "time",
1106
+ value: endTime,
1107
+ onChange: (e) => onChange([startTime, e.target.value]),
1108
+ onInputChange: field.onInputChange
1109
+ })
1110
+ ]
1111
+ });
1112
+ }
1113
+ return /* @__PURE__ */ jsx(FilterInput, {
1114
+ className: field.className,
1115
+ field,
1116
+ type: "time",
1117
+ value: values[0] || "",
1118
+ onChange: (e) => onChange([e.target.value]),
1119
+ onInputChange: field.onInputChange
1120
+ });
1121
+ }
1122
+ if (field.type === "datetime") {
1123
+ if (operator === "between") {
1124
+ const startDateTime = values[0] || "";
1125
+ const endDateTime = values[1] || "";
1126
+ return /* @__PURE__ */ jsxs("div", {
1127
+ className: "flex items-center",
1128
+ "data-slot": "filters-item",
1129
+ children: [
1130
+ /* @__PURE__ */ jsx(FilterInput, {
1131
+ className: cn("w-36 max-w-full", field.className),
1132
+ field,
1133
+ type: "datetime-local",
1134
+ value: startDateTime,
1135
+ onChange: (e) => onChange([e.target.value, endDateTime]),
1136
+ onInputChange: field.onInputChange
1137
+ }),
1138
+ /* @__PURE__ */ jsx("div", {
1139
+ className: filterFieldBetweenVariants({
1140
+ variant: context.variant,
1141
+ size: context.size
1142
+ }),
1143
+ "data-slot": "filters-between",
1144
+ children: context.i18n.to
1145
+ }),
1146
+ /* @__PURE__ */ jsx(FilterInput, {
1147
+ className: cn("w-36 max-w-full", field.className),
1148
+ field,
1149
+ type: "datetime-local",
1150
+ value: endDateTime,
1151
+ onChange: (e) => onChange([startDateTime, e.target.value]),
1152
+ onInputChange: field.onInputChange
1153
+ })
1154
+ ]
1155
+ });
1156
+ }
1157
+ return /* @__PURE__ */ jsx(FilterInput, {
1158
+ className: cn("w-36 max-w-full", field.className),
1159
+ field,
1160
+ type: "datetime-local",
1161
+ value: values[0] || "",
1162
+ onChange: (e) => onChange([e.target.value]),
1163
+ onInputChange: field.onInputChange
1164
+ });
1165
+ }
1166
+ if ([
1167
+ "email",
1168
+ "url",
1169
+ "tel"
1170
+ ].includes(field.type || "")) {
1171
+ const getInputType = () => {
1172
+ switch (field.type) {
1173
+ case "email": return "email";
1174
+ case "url": return "url";
1175
+ case "tel": return "tel";
1176
+ default: return "text";
1177
+ }
1178
+ };
1179
+ const getPattern = () => {
1180
+ switch (field.type) {
1181
+ case "email": return "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$";
1182
+ case "url": return "^https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)$";
1183
+ case "tel": return "^[\\+]?[1-9][\\d]{0,15}$";
1184
+ default: return;
1185
+ }
1186
+ };
1187
+ return /* @__PURE__ */ jsx(FilterInput, {
1188
+ className: field.className,
1189
+ field,
1190
+ inputRef: valueInputRef,
1191
+ pattern: field.pattern || getPattern(),
1192
+ placeholder: field.placeholder || context.i18n.placeholders.enterField(field.type || "text"),
1193
+ type: getInputType(),
1194
+ value: values[0] || "",
1195
+ onChange: (e) => onChange([e.target.value]),
1196
+ onInputChange: field.onInputChange
1197
+ });
1198
+ }
1199
+ if (field.type === "daterange") {
1200
+ const startDate = values[0] || "";
1201
+ const endDate = values[1] || "";
1202
+ return /* @__PURE__ */ jsxs("div", {
1203
+ className: filterFieldValueVariants({
1204
+ variant: context.variant,
1205
+ size: context.size,
1206
+ cursorPointer: context.cursorPointer
1207
+ }),
1208
+ "data-slot": "filters-value",
1209
+ children: [
1210
+ /* @__PURE__ */ jsx(FilterDatePicker, {
1211
+ className: cn("max-w-full", field.className),
1212
+ field,
1213
+ value: startDate,
1214
+ onChange: (v) => onChange([v, endDate])
1215
+ }),
1216
+ /* @__PURE__ */ jsx("div", {
1217
+ className: filterFieldBetweenVariants({
1218
+ variant: context.variant,
1219
+ size: context.size
1220
+ }),
1221
+ "data-slot": "filters-between",
1222
+ children: context.i18n.to
1223
+ }),
1224
+ /* @__PURE__ */ jsx(FilterDatePicker, {
1225
+ className: cn("max-w-full", field.className),
1226
+ field,
1227
+ value: endDate,
1228
+ onChange: (v) => onChange([startDate, v])
1229
+ })
1230
+ ]
1231
+ });
1232
+ }
1233
+ if (field.type === "text" || field.type === "number") {
1234
+ if (field.type === "number" && operator === "between") {
1235
+ const minVal = values[0] || "";
1236
+ const maxVal = values[1] || "";
1237
+ return /* @__PURE__ */ jsxs("div", {
1238
+ className: "flex items-center",
1239
+ "data-slot": "filters-item",
1240
+ children: [
1241
+ /* @__PURE__ */ jsx(FilterInput, {
1242
+ className: cn("w-16 max-w-full", field.className),
1243
+ field,
1244
+ inputRef: valueInputRef,
1245
+ max: field.max,
1246
+ min: field.min,
1247
+ pattern: field.pattern,
1248
+ placeholder: context.i18n.min,
1249
+ step: field.step,
1250
+ type: "number",
1251
+ value: minVal,
1252
+ onChange: (e) => onChange([e.target.value, maxVal]),
1253
+ onInputChange: field.onInputChange
1254
+ }),
1255
+ /* @__PURE__ */ jsx("div", {
1256
+ className: filterFieldBetweenVariants({
1257
+ variant: context.variant,
1258
+ size: context.size
1259
+ }),
1260
+ "data-slot": "filters-between",
1261
+ children: context.i18n.to
1262
+ }),
1263
+ /* @__PURE__ */ jsx(FilterInput, {
1264
+ className: cn("w-16 max-w-full", field.className),
1265
+ field,
1266
+ max: field.max,
1267
+ min: field.min,
1268
+ pattern: field.pattern,
1269
+ placeholder: context.i18n.max,
1270
+ step: field.step,
1271
+ type: "number",
1272
+ value: maxVal,
1273
+ onChange: (e) => onChange([minVal, e.target.value]),
1274
+ onInputChange: field.onInputChange
1275
+ })
1276
+ ]
1277
+ });
1278
+ }
1279
+ return /* @__PURE__ */ jsx("div", {
1280
+ className: "flex items-center",
1281
+ "data-slot": "filters-item",
1282
+ children: /* @__PURE__ */ jsx(FilterInput, {
1283
+ className: cn("w-36", field.className),
1284
+ field,
1285
+ inputRef: valueInputRef,
1286
+ max: field.type === "number" ? field.max : void 0,
1287
+ min: field.type === "number" ? field.min : void 0,
1288
+ pattern: field.pattern,
1289
+ placeholder: field.placeholder,
1290
+ step: field.type === "number" ? field.step : void 0,
1291
+ type: field.type === "number" ? "number" : "text",
1292
+ value: values[0] || "",
1293
+ onChange: (e) => onChange([e.target.value]),
1294
+ onInputChange: field.onInputChange
1295
+ })
1296
+ });
1297
+ }
1298
+ if (field.type === "date") return /* @__PURE__ */ jsx(FilterDatePicker, {
1299
+ className: field.className,
1300
+ field,
1301
+ value: values[0] || "",
1302
+ onChange: (v) => onChange([v])
1303
+ });
1304
+ if (field.type === "select" || field.type === "multiselect") return /* @__PURE__ */ jsx(SelectOptionsPopover, {
1305
+ field,
1306
+ values,
1307
+ onChange
1308
+ });
1309
+ const isMultiSelect = values.length > 1;
1310
+ const selectedOptions = field.options?.filter((opt) => values.includes(opt.value)) || [];
1311
+ const unselectedOptions = field.options?.filter((opt) => !values.includes(opt.value)) || [];
1312
+ return /* @__PURE__ */ jsxs(Popover, {
1313
+ open,
1314
+ onOpenChange: (isOpen) => {
1315
+ setOpen(isOpen);
1316
+ if (!isOpen) setTimeout(() => setSearchInput(""), SEARCH_RESET_DELAY_MS);
1317
+ },
1318
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
1319
+ className: filterFieldValueVariants({
1320
+ variant: context.variant,
1321
+ size: context.size,
1322
+ cursorPointer: context.cursorPointer
1323
+ }),
1324
+ "data-slot": "filters-value",
1325
+ children: /* @__PURE__ */ jsx("div", {
1326
+ className: "flex w-full min-w-0 items-center gap-1.5",
1327
+ children: field.customValueRenderer ? field.customValueRenderer(values, field.options || []) : /* @__PURE__ */ jsxs(Fragment$1, { children: [selectedOptions.length > 0 && /* @__PURE__ */ jsx("div", {
1328
+ className: "flex shrink-0 items-center -space-x-1.5",
1329
+ children: selectedOptions.slice(0, 3).map((option) => /* @__PURE__ */ jsx("div", { children: option.icon }, String(option.value)))
1330
+ }), selectedOptions.length === 1 ? /* @__PURE__ */ jsx("span", {
1331
+ className: "min-w-0 truncate text-accent-foreground",
1332
+ title: selectedOptions[0].detail ? `${selectedOptions[0].label} - ${selectedOptions[0].detail}` : selectedOptions[0].label,
1333
+ children: selectedOptions[0].label
1334
+ }) : selectedOptions.length > 1 ? `${selectedOptions.length} ${context.i18n.selectedCount}` : context.i18n.select] })
1335
+ })
1336
+ }), /* @__PURE__ */ jsx(PopoverContent, {
1337
+ className: cn("data-[state=closed]:animation-none! w-36 p-0 data-[state=closed]:duration-0!", field.popoverContentClassName),
1338
+ children: /* @__PURE__ */ jsxs(Command, { children: [field.searchable !== false && /* @__PURE__ */ jsx(CommandInput, {
1339
+ className: "h-(--control-height)",
1340
+ placeholder: context.i18n.placeholders.searchField(field.label || ""),
1341
+ value: searchInput,
1342
+ onValueChange: setSearchInput
1343
+ }), /* @__PURE__ */ jsxs(CommandList, {
1344
+ className: "outline-hidden",
1345
+ children: [
1346
+ /* @__PURE__ */ jsx(CommandEmpty, { children: context.i18n.noResultsFound }),
1347
+ selectedOptions.length > 0 && /* @__PURE__ */ jsx(CommandGroup, { children: selectedOptions.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
1348
+ className: "group flex items-center gap-2",
1349
+ onSelect: () => {
1350
+ if (isMultiSelect) onChange(values.filter((v) => v !== option.value));
1351
+ else onChange([]);
1352
+ if (!isMultiSelect) setOpen(false);
1353
+ },
1354
+ children: [
1355
+ option.icon && option.icon,
1356
+ /* @__PURE__ */ jsx("span", {
1357
+ className: "truncate text-accent-foreground",
1358
+ children: option.label
1359
+ }),
1360
+ /* @__PURE__ */ jsx(Check, { className: "ms-auto text-primary" })
1361
+ ]
1362
+ }, String(option.value))) }),
1363
+ unselectedOptions.length > 0 && /* @__PURE__ */ jsxs(Fragment$1, { children: [selectedOptions.length > 0 && /* @__PURE__ */ jsx(CommandSeparator, {}), /* @__PURE__ */ jsx(CommandGroup, { children: unselectedOptions.map((option) => /* @__PURE__ */ jsxs(CommandItem, {
1364
+ className: "group flex items-center gap-2",
1365
+ value: option.label,
1366
+ onSelect: () => {
1367
+ if (isMultiSelect) {
1368
+ const newValues = [...values, option.value];
1369
+ if (field.maxSelections && newValues.length > field.maxSelections) return;
1370
+ onChange(newValues);
1371
+ } else {
1372
+ onChange([option.value]);
1373
+ setOpen(false);
1374
+ }
1375
+ },
1376
+ children: [
1377
+ option.icon && option.icon,
1378
+ /* @__PURE__ */ jsx("span", {
1379
+ className: "truncate text-accent-foreground",
1380
+ children: option.label
1381
+ }),
1382
+ /* @__PURE__ */ jsx(Check, { className: "ms-auto text-primary opacity-0" })
1383
+ ]
1384
+ }, String(option.value))) })] })
1385
+ ]
1386
+ })] })
1387
+ })]
1388
+ });
1389
+ }
1390
+ var FiltersContent = ({ filters, fields, onChange }) => {
1391
+ const context = useFilterContext();
1392
+ const fieldsMap = useMemo(() => getFieldsMap(fields), [fields]);
1393
+ const updateFilter = useCallback((filterId, updates) => {
1394
+ onChange(filters.map((filter) => {
1395
+ if (filter.id === filterId) {
1396
+ const updatedFilter = {
1397
+ ...filter,
1398
+ ...updates
1399
+ };
1400
+ if (updates.operator === "empty" || updates.operator === "not_empty") updatedFilter.values = [];
1401
+ return updatedFilter;
1402
+ }
1403
+ return filter;
1404
+ }));
1405
+ }, [filters, onChange]);
1406
+ const removeFilter = useCallback((filterId) => {
1407
+ onChange(filters.filter((filter) => filter.id !== filterId));
1408
+ }, [filters, onChange]);
1409
+ return /* @__PURE__ */ jsx("div", {
1410
+ className: cn(filtersContainerVariants({
1411
+ variant: context.variant,
1412
+ size: context.size
1413
+ }), filters.length > 0 && "w-full", context.className),
1414
+ children: filters.map((filter) => {
1415
+ const field = fieldsMap[filter.field];
1416
+ if (!field) return null;
1417
+ return /* @__PURE__ */ jsxs("div", {
1418
+ className: filterItemVariants({ variant: context.variant }),
1419
+ "data-slot": "filter-item",
1420
+ children: [
1421
+ /* @__PURE__ */ jsxs("div", {
1422
+ className: filterFieldLabelVariants({
1423
+ variant: context.variant,
1424
+ size: context.size,
1425
+ radius: context.radius
1426
+ }),
1427
+ children: [field.icon, field.pillLabel ?? field.label]
1428
+ }),
1429
+ !field.renderOperatorInValue && /* @__PURE__ */ jsx(FilterOperatorDropdown, {
1430
+ field,
1431
+ operator: filter.operator,
1432
+ values: filter.values,
1433
+ onChange: (operator) => updateFilter(filter.id, { operator })
1434
+ }),
1435
+ /* @__PURE__ */ jsx(FilterValueSelector, {
1436
+ field,
1437
+ operator: filter.operator,
1438
+ readOnly: field.readOnly,
1439
+ values: filter.values,
1440
+ onChange: (values) => updateFilter(filter.id, { values }),
1441
+ onOperatorChange: (operator) => updateFilter(filter.id, { operator })
1442
+ }),
1443
+ /* @__PURE__ */ jsx(FilterRemoveButton, { onClick: () => removeFilter(filter.id) })
1444
+ ]
1445
+ }, filter.id);
1446
+ })
1447
+ });
1448
+ };
1449
+ var FilterAddButton = forwardRef(({ className, label, icon, ...props }, ref) => {
1450
+ const context = useFilterContext();
1451
+ const { controlShape, isAdmin7 } = useShade();
1452
+ const isInFilterBar = useFilterBarContext();
1453
+ const isPillFilterBar = isInFilterBar && isAdmin7;
1454
+ const iconOnly = isPillFilterBar && context.hasFilters;
1455
+ const buttonLabel = label ?? context.addButtonText ?? context.i18n.addFilter;
1456
+ return /* @__PURE__ */ jsxs("button", {
1457
+ ref,
1458
+ "aria-label": iconOnly ? buttonLabel : void 0,
1459
+ className: cn(filterAddButtonVariants({
1460
+ variant: context.addButtonVariant ?? context.variant,
1461
+ size: context.size,
1462
+ cursorPointer: context.cursorPointer,
1463
+ radius: context.controlRadius
1464
+ }), isPillFilterBar && "h-7 text-sm! [&_svg]:size-3", isAdmin7 && !isInFilterBar && "font-medium", isAdmin7 && (iconOnly ? "aspect-square border-0 !px-0 shadow-none" : context.addButtonVariant === "ghost" || context.addButtonVariant === "secondary" ? "border-0 px-3 shadow-none active:shadow-none" : "border-0 px-3 shadow-control-outline active:shadow-control-outline-pressed"), context.addButtonClassName, className),
1465
+ "data-control-shape": controlShape,
1466
+ "data-slot": "filters-add",
1467
+ title: context.i18n.addFilterTitle,
1468
+ type: "button",
1469
+ ...props,
1470
+ children: [iconOnly ? /* @__PURE__ */ jsx(Plus, {}) : icon ?? context.addButtonIcon ?? /* @__PURE__ */ jsx(Plus, {}), !iconOnly && buttonLabel]
1471
+ });
1472
+ });
1473
+ FilterAddButton.displayName = "FilterAddButton";
1474
+ var FiltersTrigger = forwardRef(({ collapseLabel = false, fallbackStyle = "list", fallbackClassName, className, ...props }, ref) => {
1475
+ const { hasFilters, keyboardShortcut } = useFilterContext();
1476
+ const { isAdmin7 } = useShade();
1477
+ if (isAdmin7 && !hasFilters) return /* @__PURE__ */ jsx(PageHeader.FilterTrigger, {
1478
+ ref,
1479
+ className,
1480
+ shortcut: keyboardShortcut?.toUpperCase(),
1481
+ ...props
1482
+ });
1483
+ const iconStyle = isAdmin7 && fallbackStyle === "funnel" ? "list" : fallbackStyle;
1484
+ const Icon = iconStyle === "list" ? hasFilters ? ListFilterPlus : ListFilter : hasFilters || fallbackStyle === "funnel-plus" ? FunnelPlus : Funnel;
1485
+ return /* @__PURE__ */ jsx(FilterAddButton, {
1486
+ ref,
1487
+ className: cn(!isAdmin7 && cn(collapseLabel && !hasFilters && "min-w-[34px] gap-0 !px-3 text-[0px] data-[control-shape=pill]:aspect-square data-[control-shape=pill]:h-(--control-height) data-[control-shape=pill]:!px-0 data-[control-shape=pill]:text-[0px]! lg:min-w-0 lg:gap-1.5 lg:px-3 lg:text-base lg:data-[control-shape=pill]:aspect-auto lg:data-[control-shape=pill]:!px-3 lg:data-[control-shape=pill]:text-base! data-[control-shape=pill]:[&_svg]:size-4", hasFilters && (fallbackStyle === "list" ? "gap-0 !px-3 text-[0px]" : "border-none"), fallbackClassName), className),
1488
+ icon: /* @__PURE__ */ jsx(Icon, { className: iconStyle === "list" ? "size-4" : void 0 }),
1489
+ label: hasFilters ? "Add filter" : "Filter",
1490
+ ...props
1491
+ });
1492
+ });
1493
+ FiltersTrigger.displayName = "Filters.Trigger";
1494
+ function Filters({ filters, fields, onChange, className, showAddButton = true, addButtonText, addButtonIcon, addButtonClassName, addButtonVariant, addButton, showClearButton = false, clearButtonText, clearButtonIcon, clearButtonClassName, clearButton, onClear, variant = "outline", size = "md", radius, i18n, showSearchInput = true, cursorPointer = true, trigger, allowMultiple = true, popoverContentClassName, popoverAlign = "start", keyboardShortcut, onActiveFieldChange }) {
1495
+ const { controlShape, isAdmin7 } = useShade();
1496
+ const [addFilterOpen, setAddFilterOpen] = useState(false);
1497
+ const [selectedFieldKeyForOptions, setSelectedFieldKeyForOptions] = useState(null);
1498
+ const [tempSelectedValues, setTempSelectedValues] = useState([]);
1499
+ const [autoFocusFilterId, setAutoFocusFilterId] = useState(null);
1500
+ const [fieldSearch, setFieldSearch] = useState("");
1501
+ const [expandedGroups, setExpandedGroups] = useState(/* @__PURE__ */ new Set());
1502
+ const filterRadius = radius ?? "md";
1503
+ const controlRadius = radius ?? (isAdmin7 ? "full" : "md");
1504
+ useEffect(() => {
1505
+ onActiveFieldChange?.(selectedFieldKeyForOptions);
1506
+ }, [selectedFieldKeyForOptions, onActiveFieldChange]);
1507
+ useEffect(() => {
1508
+ if (!keyboardShortcut) return;
1509
+ const handleKeyDown = (e) => {
1510
+ const target = e.target;
1511
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.isContentEditable) return;
1512
+ if (e.key.toLowerCase() === keyboardShortcut.toLowerCase() && !e.metaKey && !e.ctrlKey && !e.altKey) {
1513
+ e.preventDefault();
1514
+ setAddFilterOpen((prev) => !prev);
1515
+ }
1516
+ };
1517
+ window.addEventListener("keydown", handleKeyDown);
1518
+ return () => window.removeEventListener("keydown", handleKeyDown);
1519
+ }, [keyboardShortcut]);
1520
+ useEffect(() => {
1521
+ if (addFilterOpen) setTimeout(() => {
1522
+ const input = document.querySelector("[cmdk-input]");
1523
+ if (input) input.focus();
1524
+ else {
1525
+ const command = document.querySelector("[cmdk-root]");
1526
+ if (command) command.focus();
1527
+ }
1528
+ }, 0);
1529
+ }, [
1530
+ addFilterOpen,
1531
+ selectedFieldKeyForOptions,
1532
+ showSearchInput
1533
+ ]);
1534
+ const mergedI18n = {
1535
+ ...DEFAULT_I18N,
1536
+ ...i18n,
1537
+ operators: {
1538
+ ...DEFAULT_I18N.operators,
1539
+ ...i18n?.operators
1540
+ },
1541
+ placeholders: {
1542
+ ...DEFAULT_I18N.placeholders,
1543
+ ...i18n?.placeholders
1544
+ },
1545
+ validation: {
1546
+ ...DEFAULT_I18N.validation,
1547
+ ...i18n?.validation
1548
+ }
1549
+ };
1550
+ const fieldsMap = useMemo(() => getFieldsMap(fields), [fields]);
1551
+ const selectedFieldForOptions = selectedFieldKeyForOptions ? fieldsMap[selectedFieldKeyForOptions] : null;
1552
+ const updateFilter = useCallback((filterId, updates) => {
1553
+ onChange(filters.map((filter) => {
1554
+ if (filter.id === filterId) {
1555
+ const updatedFilter = {
1556
+ ...filter,
1557
+ ...updates
1558
+ };
1559
+ if (updates.operator === "empty" || updates.operator === "not_empty") updatedFilter.values = [];
1560
+ return updatedFilter;
1561
+ }
1562
+ return filter;
1563
+ }));
1564
+ }, [filters, onChange]);
1565
+ const removeFilter = useCallback((filterId) => {
1566
+ onChange(filters.filter((filter) => filter.id !== filterId));
1567
+ }, [filters, onChange]);
1568
+ const closeFilterPopover = useCallback(() => {
1569
+ setAddFilterOpen(false);
1570
+ setSelectedFieldKeyForOptions(null);
1571
+ setTempSelectedValues([]);
1572
+ setFieldSearch("");
1573
+ setExpandedGroups(/* @__PURE__ */ new Set());
1574
+ }, []);
1575
+ const addFilter = useCallback((fieldKey) => {
1576
+ const field = fieldsMap[fieldKey];
1577
+ if (!field?.key) return;
1578
+ if (field.type === "select" || field.type === "multiselect") {
1579
+ setSelectedFieldKeyForOptions(field.key);
1580
+ setTempSelectedValues([]);
1581
+ return;
1582
+ }
1583
+ const defaultOperator = field.defaultOperator || (field.type === "daterange" || field.type === "numberrange" ? "between" : "is");
1584
+ let defaultValues = [];
1585
+ if (field.defaultValue !== void 0) defaultValues = [field.defaultValue];
1586
+ else if ([
1587
+ "text",
1588
+ "number",
1589
+ "date",
1590
+ "email",
1591
+ "url",
1592
+ "tel",
1593
+ "time",
1594
+ "datetime"
1595
+ ].includes(field.type || "")) defaultValues = [""];
1596
+ else if (field.type === "daterange") defaultValues = ["", ""];
1597
+ else if (field.type === "numberrange") defaultValues = [field.min || 0, field.max || 100];
1598
+ else if (field.type === "boolean") defaultValues = [false];
1599
+ const newFilter = createFilter(fieldKey, defaultOperator, defaultValues);
1600
+ onChange([...filters, newFilter]);
1601
+ if (TYPED_VALUE_FIELD_TYPES.includes(field.type || "")) setAutoFocusFilterId(newFilter.id);
1602
+ closeFilterPopover();
1603
+ }, [
1604
+ allowMultiple,
1605
+ closeFilterPopover,
1606
+ fieldsMap,
1607
+ filters,
1608
+ onChange
1609
+ ]);
1610
+ const addFilterWithOption = useCallback((field, values) => {
1611
+ if (!field.key) return;
1612
+ const defaultOperator = field.defaultOperator || (field.type === "multiselect" ? "is_any_of" : "is");
1613
+ const newFilter = createFilter(field.key, defaultOperator, values);
1614
+ onChange([...filters, newFilter]);
1615
+ closeFilterPopover();
1616
+ }, [
1617
+ closeFilterPopover,
1618
+ filters,
1619
+ onChange
1620
+ ]);
1621
+ const isOfferable = useCallback((field) => {
1622
+ if (field.readOnly) return false;
1623
+ if (allowMultiple) return true;
1624
+ return !filters.some((filter) => filter.field === field.key);
1625
+ }, [allowMultiple, filters]);
1626
+ const selectableFields = useMemo(() => {
1627
+ return flattenFields(fields).filter((field) => {
1628
+ if (!field.key || field.type === "separator") return false;
1629
+ return isOfferable(field);
1630
+ });
1631
+ }, [fields, isOfferable]);
1632
+ const renderPickerGroup = (groupKey, heading, groupFields, previewLimit) => {
1633
+ if (groupFields.length === 0) return null;
1634
+ const searching = fieldSearch.trim().length > 0;
1635
+ const capped = previewLimit !== void 0 && !searching && !expandedGroups.has(groupKey) && groupFields.length > previewLimit;
1636
+ const visibleFields = capped ? groupFields.slice(0, previewLimit) : groupFields;
1637
+ const hiddenCount = groupFields.length - visibleFields.length;
1638
+ return /* @__PURE__ */ jsxs(CommandGroup, {
1639
+ heading,
1640
+ children: [visibleFields.map((field, fieldIndex) => {
1641
+ if (field.type === "separator") return /* @__PURE__ */ jsx(CommandSeparator, {}, field.key ?? `${groupKey}-separator-${fieldIndex}`);
1642
+ return /* @__PURE__ */ jsxs(CommandItem, {
1643
+ className: "min-w-0",
1644
+ onSelect: () => field.key && addFilter(field.key),
1645
+ children: [field.icon, /* @__PURE__ */ jsx("span", {
1646
+ className: "truncate",
1647
+ children: field.label
1648
+ })]
1649
+ }, field.key ?? `${groupKey}-field-${fieldIndex}`);
1650
+ }), capped && /* @__PURE__ */ jsx(CommandItem, {
1651
+ className: "min-w-0 text-muted-foreground",
1652
+ value: `${groupKey}-show-more`,
1653
+ onSelect: () => setExpandedGroups((prev) => {
1654
+ const next = new Set(prev);
1655
+ next.add(groupKey);
1656
+ return next;
1657
+ }),
1658
+ children: /* @__PURE__ */ jsx("span", {
1659
+ className: "truncate",
1660
+ children: mergedI18n.showMore(hiddenCount)
1661
+ })
1662
+ })]
1663
+ }, groupKey);
1664
+ };
1665
+ return /* @__PURE__ */ jsx(FilterContext.Provider, {
1666
+ value: {
1667
+ hasFilters: filters.length > 0,
1668
+ controlRadius,
1669
+ keyboardShortcut,
1670
+ variant,
1671
+ size,
1672
+ radius: filterRadius,
1673
+ i18n: mergedI18n,
1674
+ cursorPointer,
1675
+ className,
1676
+ showAddButton,
1677
+ addButtonText,
1678
+ addButtonIcon,
1679
+ addButtonClassName,
1680
+ addButtonVariant,
1681
+ addButton,
1682
+ showSearchInput,
1683
+ trigger,
1684
+ allowMultiple
1685
+ },
1686
+ children: /* @__PURE__ */ jsxs("div", {
1687
+ className: cn(filtersContainerVariants({
1688
+ variant,
1689
+ size
1690
+ }), filters.length > 0 && "w-full", showClearButton && filters.length > 0 && "sm:pr-24", className),
1691
+ children: [
1692
+ filters.map((filter) => {
1693
+ const field = fieldsMap[filter.field];
1694
+ if (!field) return null;
1695
+ return /* @__PURE__ */ jsxs("div", {
1696
+ className: cn(filterItemVariants({ variant }), isAdmin7 && "text-sm [--control-height:calc(var(--spacing)*7)] [&_*]:text-sm!"),
1697
+ "data-slot": "filter-item",
1698
+ children: [
1699
+ /* @__PURE__ */ jsxs("div", {
1700
+ className: filterFieldLabelVariants({
1701
+ variant,
1702
+ size,
1703
+ radius: filterRadius
1704
+ }),
1705
+ children: [field.icon, field.pillLabel ?? field.label]
1706
+ }),
1707
+ !field.renderOperatorInValue && /* @__PURE__ */ jsx(FilterOperatorDropdown, {
1708
+ field,
1709
+ operator: filter.operator,
1710
+ values: filter.values,
1711
+ onChange: (operator) => updateFilter(filter.id, { operator })
1712
+ }),
1713
+ /* @__PURE__ */ jsx(FilterValueSelector, {
1714
+ autoFocus: filter.id === autoFocusFilterId,
1715
+ field,
1716
+ operator: filter.operator,
1717
+ readOnly: field.readOnly,
1718
+ values: filter.values,
1719
+ onChange: (values) => updateFilter(filter.id, { values }),
1720
+ onOperatorChange: (operator) => updateFilter(filter.id, { operator })
1721
+ }),
1722
+ /* @__PURE__ */ jsx(FilterRemoveButton, { onClick: () => removeFilter(filter.id) })
1723
+ ]
1724
+ }, filter.id);
1725
+ }),
1726
+ showAddButton && selectableFields.length > 0 && /* @__PURE__ */ jsxs(Popover, {
1727
+ open: addFilterOpen,
1728
+ onOpenChange: (open) => {
1729
+ setAddFilterOpen(open);
1730
+ if (!open) {
1731
+ setSelectedFieldKeyForOptions(null);
1732
+ setTempSelectedValues([]);
1733
+ setFieldSearch("");
1734
+ setExpandedGroups(/* @__PURE__ */ new Set());
1735
+ }
1736
+ },
1737
+ children: [/* @__PURE__ */ jsx(PopoverTrigger, {
1738
+ asChild: true,
1739
+ children: addButton ?? /* @__PURE__ */ jsx(FilterAddButton, {})
1740
+ }), /* @__PURE__ */ jsx(PopoverContent, {
1741
+ align: popoverAlign,
1742
+ className: cn("data-[state=closed]:animation-none! p-0 data-[state=closed]:duration-0!", selectedFieldForOptions?.className || popoverContentClassName || "w-[220px]"),
1743
+ children: selectedFieldForOptions ? /* @__PURE__ */ jsx(SelectOptionsPopover, {
1744
+ field: selectedFieldForOptions.type === "multiselect" ? {
1745
+ ...selectedFieldForOptions,
1746
+ type: "select"
1747
+ } : selectedFieldForOptions,
1748
+ inline: true,
1749
+ values: tempSelectedValues,
1750
+ onChange: (values) => addFilterWithOption(selectedFieldForOptions, values),
1751
+ onClose: closeFilterPopover
1752
+ }) : /* @__PURE__ */ jsxs(Command, {
1753
+ className: "outline-hidden",
1754
+ tabIndex: showSearchInput ? void 0 : 0,
1755
+ children: [showSearchInput && /* @__PURE__ */ jsx(CommandInput, {
1756
+ className: "h-(--control-height)",
1757
+ placeholder: mergedI18n.searchFields,
1758
+ value: fieldSearch,
1759
+ onValueChange: setFieldSearch
1760
+ }), /* @__PURE__ */ jsxs(CommandList, {
1761
+ className: "outline-hidden",
1762
+ children: [/* @__PURE__ */ jsx(CommandEmpty, { children: mergedI18n.noFieldsFound }), fields.map((item, index) => {
1763
+ if (isFieldGroup(item)) {
1764
+ const groupFields = item.fields.filter((field) => {
1765
+ if (field.type === "separator") return true;
1766
+ return isOfferable(field);
1767
+ });
1768
+ return renderPickerGroup(item.group || `group-${index}`, item.group || "Fields", groupFields, item.previewLimit);
1769
+ }
1770
+ if (isGroupLevelField(item)) {
1771
+ const groupFields = item.fields.filter((field) => {
1772
+ if (field.type === "separator") return true;
1773
+ return isOfferable(field);
1774
+ });
1775
+ return renderPickerGroup(item.group || `group-${index}`, item.group || "Fields", groupFields, item.previewLimit);
1776
+ }
1777
+ const field = item;
1778
+ if (field.type === "separator") return /* @__PURE__ */ jsx(CommandSeparator, {}, field.key || `flat-separator-${field.label || index}`);
1779
+ if (!isOfferable(field)) return null;
1780
+ return /* @__PURE__ */ jsxs(CommandItem, {
1781
+ className: "min-w-0",
1782
+ onSelect: () => field.key && addFilter(field.key),
1783
+ children: [field.icon, /* @__PURE__ */ jsx("span", {
1784
+ className: "truncate",
1785
+ children: field.label
1786
+ })]
1787
+ }, field.key);
1788
+ })]
1789
+ })]
1790
+ })
1791
+ })]
1792
+ }),
1793
+ showClearButton && filters.length > 0 && (clearButton ? clearButton : /* @__PURE__ */ jsxs("button", {
1794
+ className: cn(filterAddButtonVariants({
1795
+ variant,
1796
+ size,
1797
+ cursorPointer,
1798
+ radius: controlRadius
1799
+ }), isAdmin7 && "h-7 text-sm! [&_svg]:size-3", "border-0 bg-transparent hover:bg-transparent hover:text-foreground", isAdmin7 && "px-3 shadow-control-outline active:shadow-control-outline-pressed", "sm:absolute sm:top-0 sm:right-0", clearButtonClassName),
1800
+ "data-control-shape": controlShape,
1801
+ type: "button",
1802
+ onClick: () => {
1803
+ if (onClear) onClear();
1804
+ else onChange([]);
1805
+ },
1806
+ children: [clearButtonIcon || /* @__PURE__ */ jsx(X, {}), clearButtonText || mergedI18n.clearFilters]
1807
+ }))
1808
+ ]
1809
+ })
1810
+ });
1811
+ }
1812
+ Filters.Trigger = FiltersTrigger;
1813
+ //#endregion
1814
+ export { FilterDatePicker, FilterSegmentInput, FilterSegmentMultiSelect, FilterSegmentSelect, Filters, FiltersContent };
1815
+
1816
+ //# sourceMappingURL=filters.js.map