@lerianstudio/sindarian-ui 2.0.0-beta.24 → 2.0.0-beta.26

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 (337) hide show
  1. package/dist/charts/chart.js +4 -231
  2. package/dist/charts/index.js +1 -11
  3. package/dist/components/breadcrumb/get-breadcrumb-paths.js +1 -18
  4. package/dist/components/breadcrumb/index.js +1 -37
  5. package/dist/components/card/account-card/index.js +1 -69
  6. package/dist/components/card/basic-card/index.js +1 -20
  7. package/dist/components/card/dashboard-card/index.js +1 -20
  8. package/dist/components/card/entity-card/index.js +1 -68
  9. package/dist/components/card/index.js +1 -20
  10. package/dist/components/dialog/confirmation-dialog/index.d.ts.map +1 -1
  11. package/dist/components/dialog/confirmation-dialog/index.js +1 -96
  12. package/dist/components/dialog/confirmation-dialog/use-confirm-dialog.js +1 -55
  13. package/dist/components/dialog/index.js +1 -19
  14. package/dist/components/dialog/large-dialog/index.d.ts +2 -2
  15. package/dist/components/dialog/large-dialog/index.d.ts.map +1 -1
  16. package/dist/components/dialog/large-dialog/index.js +1 -21
  17. package/dist/components/entity-box/index.js +1 -67
  18. package/dist/components/entity-data-table/index.js +1 -20
  19. package/dist/components/form/combo-box-field/index.js +1 -35
  20. package/dist/components/form/country-field/index.js +1 -11
  21. package/dist/components/form/date-picker-field/index.js +1 -83
  22. package/dist/components/form/date-range-field/index.js +1 -58
  23. package/dist/components/form/date-time-picker-field/index.js +1 -114
  24. package/dist/components/form/file-upload-field/index.js +1 -69
  25. package/dist/components/form/index.js +1 -31
  26. package/dist/components/form/input-field/index.js +1 -96
  27. package/dist/components/form/otp-field/index.js +1 -19
  28. package/dist/components/form/pagination-limit-field/index.js +1 -10
  29. package/dist/components/form/password-field/index.d.ts.map +1 -1
  30. package/dist/components/form/password-field/index.js +1 -16
  31. package/dist/components/form/radio-group-field/index.js +1 -36
  32. package/dist/components/form/renderable-label.js +1 -57
  33. package/dist/components/form/select-field/index.js +1 -68
  34. package/dist/components/form/state-field/index.js +1 -42
  35. package/dist/components/form/switch-field/index.js +1 -16
  36. package/dist/components/form/textarea-field/index.js +1 -23
  37. package/dist/components/page/index.js +1 -20
  38. package/dist/components/page-header/index.js +1 -80
  39. package/dist/components/pagination/index.js +1 -10
  40. package/dist/components/table/id-table-cell.js +1 -109
  41. package/dist/components/table/index.js +1 -19
  42. package/dist/components/table/locked-table-actions.js +1 -41
  43. package/dist/components/table/name-table-cell.js +1 -58
  44. package/dist/components/ui/accordion/index.js +1 -62
  45. package/dist/components/ui/alert/index.js +1 -45
  46. package/dist/components/ui/alert-dialog/index.js +1 -84
  47. package/dist/components/ui/autocomplete/index.js +1 -440
  48. package/dist/components/ui/autosize-textarea/index.js +1 -89
  49. package/dist/components/ui/avatar/index.js +1 -51
  50. package/dist/components/ui/badge/index.js +1 -83
  51. package/dist/components/ui/breadcrumb/index.js +1 -35
  52. package/dist/components/ui/button/index.js +1 -65
  53. package/dist/components/ui/button/styles.css +2 -1
  54. package/dist/components/ui/calendar/index.js +1 -118
  55. package/dist/components/ui/card/index.js +1 -32
  56. package/dist/components/ui/checkbox/index.js +1 -44
  57. package/dist/components/ui/collapsible/index.js +1 -50
  58. package/dist/components/ui/command/index.js +1 -95
  59. package/dist/components/ui/copy-field/index.js +1 -163
  60. package/dist/components/ui/dialog/index.d.ts +4 -1
  61. package/dist/components/ui/dialog/index.d.ts.map +1 -1
  62. package/dist/components/ui/dialog/index.js +1 -80
  63. package/dist/components/ui/dialog/styles.css +2 -1
  64. package/dist/components/ui/dropdown-menu/index.js +1 -110
  65. package/dist/components/ui/field/index.js +1 -82
  66. package/dist/components/ui/file-upload/index.js +1 -574
  67. package/dist/components/ui/form.js +1 -162
  68. package/dist/components/ui/hover-card/index.js +1 -51
  69. package/dist/components/ui/icon-button/index.js +1 -35
  70. package/dist/components/ui/input/adornment.js +1 -21
  71. package/dist/components/ui/input/index.js +1 -99
  72. package/dist/components/ui/input/styles.css +29 -12
  73. package/dist/components/ui/label/index.js +1 -45
  74. package/dist/components/ui/lerian-wordmark/index.js +1 -7
  75. package/dist/components/ui/loading-button/index.js +1 -9
  76. package/dist/components/ui/multiple-select/index.js +1 -235
  77. package/dist/components/ui/otp-input/index.js +1 -62
  78. package/dist/components/ui/paper/index.js +1 -8
  79. package/dist/components/ui/paper-collapsible/index.js +1 -24
  80. package/dist/components/ui/popover/index.js +1 -55
  81. package/dist/components/ui/progress/index.js +1 -66
  82. package/dist/components/ui/qr-code/index.js +1 -27
  83. package/dist/components/ui/radio-group/index.js +1 -48
  84. package/dist/components/ui/scroll-area/index.js +1 -49
  85. package/dist/components/ui/select/index.js +1 -119
  86. package/dist/components/ui/select/styles.css +6 -3
  87. package/dist/components/ui/separator/index.js +1 -43
  88. package/dist/components/ui/sheet/index.d.ts +7 -2
  89. package/dist/components/ui/sheet/index.d.ts.map +1 -1
  90. package/dist/components/ui/sheet/index.js +1 -136
  91. package/dist/components/ui/sidebar/index.js +1 -27
  92. package/dist/components/ui/sidebar/next-router.cjs +1 -119
  93. package/dist/components/ui/sidebar/sidebar-back-button.js +1 -8
  94. package/dist/components/ui/sidebar/sidebar-components.js +1 -23
  95. package/dist/components/ui/sidebar/sidebar-expand-button.js +1 -49
  96. package/dist/components/ui/sidebar/sidebar-item-button.js +1 -21
  97. package/dist/components/ui/sidebar/sidebar-item-collapsible.js +1 -52
  98. package/dist/components/ui/sidebar/sidebar-item-icon-button.js +1 -18
  99. package/dist/components/ui/sidebar/sidebar-item.js +1 -44
  100. package/dist/components/ui/sidebar/sidebar-provider.js +1 -201
  101. package/dist/components/ui/sidebar/sidebar-root.d.ts +3 -1
  102. package/dist/components/ui/sidebar/sidebar-root.d.ts.map +1 -1
  103. package/dist/components/ui/sidebar/sidebar-root.js +1 -130
  104. package/dist/components/ui/sidebar/sidebar-router.js +1 -126
  105. package/dist/components/ui/sidebar/sidebar-trigger.js +1 -57
  106. package/dist/components/ui/skeleton/index.js +1 -8
  107. package/dist/components/ui/stepper/index.js +1 -29
  108. package/dist/components/ui/switch/index.js +1 -43
  109. package/dist/components/ui/table/index.js +1 -56
  110. package/dist/components/ui/tabs/index.js +1 -55
  111. package/dist/components/ui/textarea/index.js +1 -8
  112. package/dist/components/ui/time-picker/index.js +1 -85
  113. package/dist/components/ui/toast/index.js +1 -3
  114. package/dist/components/ui/toast/toaster.js +1 -16
  115. package/dist/components/ui/toggle-group/index.js +1 -156
  116. package/dist/components/ui/tooltip/index.js +1 -81
  117. package/dist/domain/blotter/index.js +1 -20
  118. package/dist/domain/delinquency-aging/aging-buckets.js +1 -120
  119. package/dist/domain/delinquency-aging/index.js +1 -222
  120. package/dist/domain/figure/index.js +1 -19
  121. package/dist/domain/format.js +1 -137
  122. package/dist/domain/index.js +1 -43
  123. package/dist/domain/key-id/index.js +1 -174
  124. package/dist/domain/ledger-sheet/index.js +1 -28
  125. package/dist/domain/money-diff.js +1 -48
  126. package/dist/domain/money-math.js +1 -104
  127. package/dist/domain/money-text/index.js +1 -123
  128. package/dist/domain/section-label/index.js +1 -17
  129. package/dist/domain/status-rail/index.js +1 -76
  130. package/dist/domain/threshold-gauge/index.js +1 -161
  131. package/dist/enterprise/alert-banner/index.js +1 -24
  132. package/dist/enterprise/app-shell/index.js +1 -87
  133. package/dist/enterprise/cursor-pager/index.js +1 -26
  134. package/dist/enterprise/data-table/column-size.js +1 -103
  135. package/dist/enterprise/data-table/index.d.ts.map +1 -1
  136. package/dist/enterprise/data-table/index.js +1 -345
  137. package/dist/enterprise/date-range-picker/index.js +1 -115
  138. package/dist/enterprise/detail-panel/index.js +1 -20
  139. package/dist/enterprise/empty-state/index.d.ts +6 -1
  140. package/dist/enterprise/empty-state/index.d.ts.map +1 -1
  141. package/dist/enterprise/empty-state/index.js +1 -13
  142. package/dist/enterprise/index.js +1 -39
  143. package/dist/enterprise/number-input/index.js +1 -252
  144. package/dist/enterprise/search-input/index.js +1 -121
  145. package/dist/enterprise/stat-card/index.js +1 -75
  146. package/dist/enterprise/status-badge/index.js +1 -120
  147. package/dist/enterprise/use-is-mobile.js +1 -68
  148. package/dist/enterprise/virtualized-table/index.js +1 -141
  149. package/dist/esm/charts/chart.js +4 -190
  150. package/dist/esm/charts/index.js +1 -3
  151. package/dist/esm/components/breadcrumb/get-breadcrumb-paths.js +1 -12
  152. package/dist/esm/components/breadcrumb/index.js +1 -30
  153. package/dist/esm/components/card/account-card/index.js +1 -53
  154. package/dist/esm/components/card/basic-card/index.js +1 -14
  155. package/dist/esm/components/card/dashboard-card/index.js +1 -14
  156. package/dist/esm/components/card/entity-card/index.js +1 -52
  157. package/dist/esm/components/card/index.js +1 -4
  158. package/dist/esm/components/dialog/confirmation-dialog/index.d.ts.map +1 -1
  159. package/dist/esm/components/dialog/confirmation-dialog/index.js +1 -60
  160. package/dist/esm/components/dialog/confirmation-dialog/use-confirm-dialog.js +1 -49
  161. package/dist/esm/components/dialog/index.js +1 -3
  162. package/dist/esm/components/dialog/large-dialog/index.d.ts +2 -2
  163. package/dist/esm/components/dialog/large-dialog/index.d.ts.map +1 -1
  164. package/dist/esm/components/dialog/large-dialog/index.js +1 -16
  165. package/dist/esm/components/entity-box/index.js +1 -56
  166. package/dist/esm/components/entity-data-table/index.js +1 -17
  167. package/dist/esm/components/form/combo-box-field/index.js +1 -28
  168. package/dist/esm/components/form/country-field/index.js +1 -7
  169. package/dist/esm/components/form/date-picker-field/index.js +1 -43
  170. package/dist/esm/components/form/date-range-field/index.js +1 -18
  171. package/dist/esm/components/form/date-time-picker-field/index.js +1 -74
  172. package/dist/esm/components/form/file-upload-field/index.js +1 -65
  173. package/dist/esm/components/form/index.js +1 -15
  174. package/dist/esm/components/form/input-field/index.js +1 -92
  175. package/dist/esm/components/form/otp-field/index.js +1 -15
  176. package/dist/esm/components/form/pagination-limit-field/index.js +1 -6
  177. package/dist/esm/components/form/password-field/index.d.ts.map +1 -1
  178. package/dist/esm/components/form/password-field/index.js +1 -10
  179. package/dist/esm/components/form/radio-group-field/index.js +1 -32
  180. package/dist/esm/components/form/renderable-label.js +1 -54
  181. package/dist/esm/components/form/select-field/index.js +1 -64
  182. package/dist/esm/components/form/state-field/index.js +1 -35
  183. package/dist/esm/components/form/switch-field/index.js +1 -12
  184. package/dist/esm/components/form/textarea-field/index.js +1 -19
  185. package/dist/esm/components/page/index.js +1 -15
  186. package/dist/esm/components/page-header/index.js +1 -71
  187. package/dist/esm/components/pagination/index.js +1 -6
  188. package/dist/esm/components/table/id-table-cell.js +1 -105
  189. package/dist/esm/components/table/index.js +1 -3
  190. package/dist/esm/components/table/locked-table-actions.js +1 -37
  191. package/dist/esm/components/table/name-table-cell.js +1 -54
  192. package/dist/esm/components/ui/accordion/index.js +1 -24
  193. package/dist/esm/components/ui/alert/index.js +1 -38
  194. package/dist/esm/components/ui/alert-dialog/index.js +1 -39
  195. package/dist/esm/components/ui/autocomplete/index.js +1 -392
  196. package/dist/esm/components/ui/autosize-textarea/index.js +1 -51
  197. package/dist/esm/components/ui/avatar/index.js +1 -14
  198. package/dist/esm/components/ui/badge/index.js +1 -79
  199. package/dist/esm/components/ui/breadcrumb/index.js +1 -27
  200. package/dist/esm/components/ui/button/index.js +1 -60
  201. package/dist/esm/components/ui/calendar/index.js +1 -82
  202. package/dist/esm/components/ui/card/index.js +1 -24
  203. package/dist/esm/components/ui/checkbox/index.js +1 -9
  204. package/dist/esm/components/ui/collapsible/index.js +1 -13
  205. package/dist/esm/components/ui/command/index.js +1 -51
  206. package/dist/esm/components/ui/copy-field/index.js +1 -127
  207. package/dist/esm/components/ui/dialog/index.d.ts +4 -1
  208. package/dist/esm/components/ui/dialog/index.d.ts.map +1 -1
  209. package/dist/esm/components/ui/dialog/index.js +1 -36
  210. package/dist/esm/components/ui/dropdown-menu/index.js +1 -60
  211. package/dist/esm/components/ui/field/index.js +1 -71
  212. package/dist/esm/components/ui/file-upload/index.js +1 -536
  213. package/dist/esm/components/ui/form.js +1 -118
  214. package/dist/esm/components/ui/hover-card/index.js +1 -14
  215. package/dist/esm/components/ui/icon-button/index.js +1 -31
  216. package/dist/esm/components/ui/input/adornment.js +1 -17
  217. package/dist/esm/components/ui/input/index.js +1 -60
  218. package/dist/esm/components/ui/label/index.js +1 -10
  219. package/dist/esm/components/ui/lerian-wordmark/index.js +1 -4
  220. package/dist/esm/components/ui/loading-button/index.js +1 -7
  221. package/dist/esm/components/ui/multiple-select/index.js +1 -196
  222. package/dist/esm/components/ui/otp-input/index.js +1 -21
  223. package/dist/esm/components/ui/paper/index.js +1 -5
  224. package/dist/esm/components/ui/paper-collapsible/index.js +1 -19
  225. package/dist/esm/components/ui/popover/index.js +1 -17
  226. package/dist/esm/components/ui/progress/index.js +1 -31
  227. package/dist/esm/components/ui/qr-code/index.js +1 -24
  228. package/dist/esm/components/ui/radio-group/index.js +1 -12
  229. package/dist/esm/components/ui/scroll-area/index.js +1 -13
  230. package/dist/esm/components/ui/select/index.js +1 -74
  231. package/dist/esm/components/ui/separator/index.js +1 -8
  232. package/dist/esm/components/ui/sheet/index.d.ts +7 -2
  233. package/dist/esm/components/ui/sheet/index.d.ts.map +1 -1
  234. package/dist/esm/components/ui/sheet/index.js +1 -92
  235. package/dist/esm/components/ui/sidebar/index.js +1 -11
  236. package/dist/esm/components/ui/sidebar/next-router.cjs +1 -119
  237. package/dist/esm/components/ui/sidebar/sidebar-back-button.js +1 -5
  238. package/dist/esm/components/ui/sidebar/sidebar-components.js +1 -15
  239. package/dist/esm/components/ui/sidebar/sidebar-expand-button.js +1 -42
  240. package/dist/esm/components/ui/sidebar/sidebar-item-button.js +1 -18
  241. package/dist/esm/components/ui/sidebar/sidebar-item-collapsible.js +1 -44
  242. package/dist/esm/components/ui/sidebar/sidebar-item-icon-button.js +1 -14
  243. package/dist/esm/components/ui/sidebar/sidebar-item.js +1 -40
  244. package/dist/esm/components/ui/sidebar/sidebar-provider.js +1 -193
  245. package/dist/esm/components/ui/sidebar/sidebar-root.d.ts +3 -1
  246. package/dist/esm/components/ui/sidebar/sidebar-root.d.ts.map +1 -1
  247. package/dist/esm/components/ui/sidebar/sidebar-root.js +1 -126
  248. package/dist/esm/components/ui/sidebar/sidebar-router.js +1 -89
  249. package/dist/esm/components/ui/sidebar/sidebar-trigger.js +1 -53
  250. package/dist/esm/components/ui/skeleton/index.js +1 -6
  251. package/dist/esm/components/ui/stepper/index.js +1 -20
  252. package/dist/esm/components/ui/switch/index.js +1 -8
  253. package/dist/esm/components/ui/table/index.js +1 -44
  254. package/dist/esm/components/ui/tabs/index.js +1 -17
  255. package/dist/esm/components/ui/textarea/index.js +1 -6
  256. package/dist/esm/components/ui/time-picker/index.js +1 -49
  257. package/dist/esm/components/ui/toast/index.js +1 -2
  258. package/dist/esm/components/ui/toast/toaster.js +1 -13
  259. package/dist/esm/components/ui/toggle-group/index.js +1 -120
  260. package/dist/esm/components/ui/tooltip/index.js +1 -43
  261. package/dist/esm/domain/blotter/index.js +1 -16
  262. package/dist/esm/domain/delinquency-aging/aging-buckets.js +1 -115
  263. package/dist/esm/domain/delinquency-aging/index.js +1 -218
  264. package/dist/esm/domain/figure/index.js +1 -15
  265. package/dist/esm/domain/format.js +1 -128
  266. package/dist/esm/domain/index.js +1 -19
  267. package/dist/esm/domain/key-id/index.js +1 -169
  268. package/dist/esm/domain/ledger-sheet/index.js +1 -24
  269. package/dist/esm/domain/money-diff.js +1 -45
  270. package/dist/esm/domain/money-math.js +1 -98
  271. package/dist/esm/domain/money-text/index.js +1 -118
  272. package/dist/esm/domain/section-label/index.js +1 -14
  273. package/dist/esm/domain/status-rail/index.js +1 -71
  274. package/dist/esm/domain/threshold-gauge/index.js +1 -157
  275. package/dist/esm/enterprise/alert-banner/index.js +1 -21
  276. package/dist/esm/enterprise/app-shell/index.js +1 -51
  277. package/dist/esm/enterprise/cursor-pager/index.js +1 -23
  278. package/dist/esm/enterprise/data-table/column-size.js +1 -97
  279. package/dist/esm/enterprise/data-table/index.d.ts.map +1 -1
  280. package/dist/esm/enterprise/data-table/index.js +1 -342
  281. package/dist/esm/enterprise/date-range-picker/index.js +1 -112
  282. package/dist/esm/enterprise/detail-panel/index.js +1 -17
  283. package/dist/esm/enterprise/empty-state/index.d.ts +6 -1
  284. package/dist/esm/enterprise/empty-state/index.d.ts.map +1 -1
  285. package/dist/esm/enterprise/empty-state/index.js +1 -10
  286. package/dist/esm/enterprise/index.js +1 -22
  287. package/dist/esm/enterprise/number-input/index.js +1 -214
  288. package/dist/esm/enterprise/search-input/index.js +1 -85
  289. package/dist/esm/enterprise/stat-card/index.js +1 -72
  290. package/dist/esm/enterprise/status-badge/index.js +1 -116
  291. package/dist/esm/enterprise/use-is-mobile.js +1 -31
  292. package/dist/esm/enterprise/virtualized-table/index.js +1 -138
  293. package/dist/esm/hooks/use-click-away.js +1 -22
  294. package/dist/esm/hooks/use-pagination.js +1 -38
  295. package/dist/esm/hooks/use-stepper.js +1 -22
  296. package/dist/esm/hooks/use-time.js +1 -13
  297. package/dist/esm/hooks/use-toast.js +1 -107
  298. package/dist/esm/index.js +1 -77
  299. package/dist/esm/lib/storage/get-storage-object.js +1 -17
  300. package/dist/esm/lib/storage/get-storage.js +1 -14
  301. package/dist/esm/lib/storage/index.js +1 -2
  302. package/dist/esm/lib/typography.js +1 -31
  303. package/dist/esm/lib/utils.js +1 -41
  304. package/dist/esm/theme/get-theme-script.js +1 -41
  305. package/dist/esm/theme/index.js +1 -4
  306. package/dist/esm/theme/mode-toggle.js +1 -45
  307. package/dist/esm/theme/theme-provider.js +1 -122
  308. package/dist/esm/toast/helpers.js +1 -36
  309. package/dist/esm/toast/index.js +1 -4
  310. package/dist/esm/types/metadata-type.js +1 -1
  311. package/dist/esm/utils/countries.cjs +1 -17
  312. package/dist/esm/utils/country-utils.js +1 -18
  313. package/dist/esm/utils/currency-codes.js +1 -181
  314. package/dist/globals.css +1 -0
  315. package/dist/hooks/use-click-away.js +1 -29
  316. package/dist/hooks/use-pagination.js +1 -41
  317. package/dist/hooks/use-stepper.js +1 -26
  318. package/dist/hooks/use-time.js +1 -20
  319. package/dist/hooks/use-toast.js +1 -111
  320. package/dist/index.js +1 -96
  321. package/dist/lib/storage/get-storage-object.js +1 -23
  322. package/dist/lib/storage/get-storage.js +1 -17
  323. package/dist/lib/storage/index.js +1 -18
  324. package/dist/lib/typography.js +1 -34
  325. package/dist/lib/utils.js +1 -45
  326. package/dist/theme/get-theme-script.js +1 -44
  327. package/dist/theme/index.js +1 -11
  328. package/dist/theme/mode-toggle.js +1 -48
  329. package/dist/theme/theme-provider.js +1 -160
  330. package/dist/toast/helpers.js +1 -41
  331. package/dist/toast/index.js +1 -10
  332. package/dist/tokens.css +7 -4
  333. package/dist/types/metadata-type.js +1 -2
  334. package/dist/utils/countries.cjs +1 -17
  335. package/dist/utils/country-utils.js +1 -25
  336. package/dist/utils/currency-codes.js +1 -184
  337. package/package.json +4 -3
@@ -1,574 +1 @@
1
- 'use client';
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || (function () {
20
- var ownKeys = function(o) {
21
- ownKeys = Object.getOwnPropertyNames || function (o) {
22
- var ar = [];
23
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
- return ar;
25
- };
26
- return ownKeys(o);
27
- };
28
- return function (mod) {
29
- if (mod && mod.__esModule) return mod;
30
- var result = {};
31
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
- __setModuleDefault(result, mod);
33
- return result;
34
- };
35
- })();
36
- Object.defineProperty(exports, "__esModule", { value: true });
37
- exports.MultipleFileUpload = exports.FileUpload = void 0;
38
- exports.validateFile = validateFile;
39
- exports.humanizeSize = humanizeSize;
40
- const jsx_runtime_1 = require("react/jsx-runtime");
41
- /**
42
- * FileUpload — a controlled "pick a file, hand it back" primitive. The defining
43
- * job: select one file (by click, keyboard, or drag-and-drop), validate it
44
- * against an accept filter + a byte ceiling, and emit `{ file, text }`.
45
- *
46
- * `readAs` decides whether the bytes are decoded on the way through. `'text'`
47
- * (the default) reads UTF-8 via FileReader.readAsText, which is what a PEM/CSV
48
- * host wants. `'none'` hands the `File` over untouched and is the only mode a
49
- * BINARY file can use: a PDF, XLSX or PFX put through readAsText decodes into
50
- * replacement-character garbage, and that garbage string is then retained for
51
- * as long as the host holds the value — 20 MiB of PDF became a useless 20 MiB
52
- * string, and the host still had to read the file a second time to get at the
53
- * real bytes.
54
- *
55
- * The real `<input type="file">` IS the accessible control: it is `sr-only`
56
- * (visually hidden) but focusable and labelable — never `aria-hidden`, never
57
- * `tabIndex={-1}`. The FormControl-injected ARIA (`id`, `aria-invalid`,
58
- * `aria-required`, `aria-describedby`) flows onto the input via `...rest`, so
59
- * react-hook-form's `field.ref` (forwarded here) focuses the real control on
60
- * error and FormLabel's `htmlFor` names it. The styled zone is a plain `<div>`
61
- * with a click handler, NOT a wrapping `<label>`: a label would contribute its
62
- * text to the input's accessible name and double-name it alongside a field's
63
- * own label. Keyboard users Tab to the focusable input and Enter/Space opens
64
- * the picker natively, so no key proxy is needed. Drag-and-drop is an
65
- * enhancement layered on the zone.
66
- *
67
- * Errors are DUAL by design and both announced: size/type/read failures are
68
- * the primitive's own concern, surfaced inline via `role="alert"` so it works
69
- * standalone outside a form; a form wrapper (FileUploadField) adds the
70
- * react-hook-form validation surface separately. A rejected pick never writes
71
- * a value, so it cannot masquerade as valid. `accept` is validated against
72
- * BOTH extension and MIME because the native `accept` attribute is only a
73
- * browser hint and is bypassable via drag-drop.
74
- *
75
- * A host that already announces the rejection itself — a toast in its own
76
- * locale, driven off `onError` — silences this one by returning nothing from
77
- * `labels.error`. Two announcements for one event, in two languages, is the
78
- * accessibility defect; the wording is not.
79
- */
80
- const React = __importStar(require("react"));
81
- const lucide_react_1 = require("lucide-react");
82
- const icon_button_1 = require("../../../components/ui/icon-button");
83
- const utils_1 = require("../../../lib/utils");
84
- /**
85
- * Validate a chosen file against an accept filter and a byte ceiling. Exported
86
- * so hosts can pre-validate before handing a file over. `accept` is matched
87
- * against BOTH the filename extension and the MIME type — a `.pem`/`text/plain`
88
- * style filter passes if EITHER matches a token. When `accept` is omitted, any
89
- * type passes. Returns the first error, or null when the file is acceptable.
90
- */
91
- function validateFile(file, opts) {
92
- const { accept, maxSizeBytes } = opts;
93
- if (typeof maxSizeBytes === 'number' && file.size > maxSizeBytes) {
94
- return { kind: 'too-large', file, maxSizeBytes };
95
- }
96
- if (accept && accept.trim() !== '' && !matchesAccept(file, accept)) {
97
- return { kind: 'wrong-type', file, accept };
98
- }
99
- return null;
100
- }
101
- /**
102
- * Does the file satisfy a comma-separated accept list? Each token is either a
103
- * dot-extension (`.pem`, case-insensitive against the filename), an exact MIME
104
- * (`text/plain`), or a MIME wildcard (`text/*`). True if ANY token matches.
105
- */
106
- function matchesAccept(file, accept) {
107
- const name = file.name.toLowerCase();
108
- const mime = file.type.toLowerCase();
109
- return accept
110
- .split(',')
111
- .map((t) => t.trim().toLowerCase())
112
- .filter((t) => t !== '')
113
- .some((token) => {
114
- if (token.startsWith('.'))
115
- return name.endsWith(token);
116
- if (token.endsWith('/*'))
117
- return mime.startsWith(token.slice(0, -1));
118
- return mime === token;
119
- });
120
- }
121
- /**
122
- * Humanize a byte count for the selected-file chip. Binary units, 1 decimal.
123
- * Exported so a `labels.error` override can format `maxSizeBytes` exactly the
124
- * way the chip and the default message do, instead of re-deriving binary units.
125
- */
126
- function humanizeSize(bytes) {
127
- if (bytes < 1024)
128
- return `${bytes} B`;
129
- const units = ['KB', 'MB', 'GB'];
130
- let size = bytes / 1024;
131
- let unit = 0;
132
- while (size >= 1024 && unit < units.length - 1) {
133
- size /= 1024;
134
- unit += 1;
135
- }
136
- return `${size.toFixed(1)} ${units[unit]}`;
137
- }
138
- /** The default English announcement for each rejection kind. */
139
- function defaultErrorMessage(error) {
140
- switch (error.kind) {
141
- case 'too-large':
142
- return `File is too large (max ${humanizeSize(error.maxSizeBytes)}).`;
143
- case 'wrong-type':
144
- return `File type not allowed (expected ${error.accept}).`;
145
- case 'read-failed':
146
- return 'Could not read the file.';
147
- }
148
- }
149
- exports.FileUpload = React.forwardRef(function FileUpload({ accept, maxSizeBytes, value, readAs = 'text', labels, onSelect, onError, disabled = false, id, className, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, 'aria-describedby': ariaDescribedby, 'aria-label': ariaLabel, ...rest }, ref) {
150
- const internalRef = React.useRef(null);
151
- React.useImperativeHandle(ref, () => internalRef.current);
152
- const reactId = React.useId();
153
- const inputId = id ?? reactId;
154
- const errorId = `${inputId}-file-upload-error`;
155
- const [dragActive, setDragActive] = React.useState(false);
156
- const [error, setError] = React.useState(null);
157
- // The destructive styling is driven by the consumer's aria-invalid OR the
158
- // component's own validation/read error — a self-detected bad pick must read
159
- // as invalid even outside a form.
160
- const invalid = ariaInvalid || error !== null;
161
- // Resolve the announcement BEFORE deciding whether the alert exists: a
162
- // consumer that returns nothing is opting out of this surface entirely,
163
- // and an association pointing at an unrendered node is worse than none.
164
- const resolved = error
165
- ? labels?.error
166
- ? labels.error(error)
167
- : defaultErrorMessage(error)
168
- : null;
169
- const errorText = resolved ? resolved : null;
170
- // Radix Slot OVERWRITES aria-describedby (it does not merge), so merge the
171
- // primitive's own role=alert error id with the FormControl-injected one so
172
- // both associations coexist on the input. A plain join, never `cn` —
173
- // tailwind-merge treats these as class names and would drop an id that
174
- // happens to look like a conflicting utility.
175
- const describedBy = [ariaDescribedby, errorText ? errorId : undefined]
176
- .filter(Boolean)
177
- .join(' ') || undefined;
178
- // Last-resolved-wins: a slow read for pick A must not overwrite a newer
179
- // pick B. Track the active reader and abort any in-flight read first.
180
- const readerRef = React.useRef(null);
181
- const handleFile = (file) => {
182
- if (!file)
183
- return;
184
- readerRef.current?.abort();
185
- const validationError = validateFile(file, { accept, maxSizeBytes });
186
- if (validationError) {
187
- setError(validationError);
188
- onError?.(validationError);
189
- return;
190
- }
191
- // Binary path: no decode, no reader, no retained garbage string. The
192
- // stale-rejection clear still has to happen here — the alert is this
193
- // component's own state and a good pick must retire it.
194
- if (readAs === 'none') {
195
- readerRef.current = null;
196
- setError(null);
197
- onSelect({ file, text: '' });
198
- return;
199
- }
200
- const reader = new FileReader();
201
- readerRef.current = reader;
202
- reader.onload = () => {
203
- if (readerRef.current !== reader)
204
- return;
205
- readerRef.current = null;
206
- setError(null);
207
- onSelect({ file, text: String(reader.result ?? '') });
208
- };
209
- reader.onerror = () => {
210
- if (readerRef.current !== reader)
211
- return;
212
- readerRef.current = null;
213
- const readError = { kind: 'read-failed', file };
214
- setError(readError);
215
- onError?.(readError);
216
- };
217
- reader.readAsText(file);
218
- };
219
- const onInputChange = (event) => {
220
- const file = event.target.files?.[0];
221
- // Release the FileList the moment it has been read. The browser fires
222
- // `change` only when the selection DIFFERS from what the input already
223
- // holds, so keeping it meant re-picking the same file after a host reset
224
- // (or retrying a rejected one) was silently a no-op — the picker opened,
225
- // the user chose the file, and nothing happened.
226
- event.target.value = '';
227
- handleFile(file);
228
- };
229
- // `preventDefault` FIRST, and unconditionally. Returning before it does
230
- // not merely refuse the drop: nothing cancels the browser's OWN action for
231
- // a dropped file, so the window navigates to the file and whatever the
232
- // page held unsaved is gone. A zone the host turned off has to swallow the
233
- // drop, never hand it back to the browser. `dropEffect` says so to the
234
- // cursor while the file is still in the air.
235
- const onDragOver = (event) => {
236
- event.preventDefault();
237
- if (disabled) {
238
- event.dataTransfer.dropEffect = 'none';
239
- return;
240
- }
241
- setDragActive(true);
242
- };
243
- const onDragLeave = (event) => {
244
- event.preventDefault();
245
- setDragActive(false);
246
- };
247
- const onDrop = (event) => {
248
- event.preventDefault();
249
- // Cleared before the gate, not after, so a host that disables the zone
250
- // mid-drag does not leave it highlighted for a drag that can no longer
251
- // land.
252
- setDragActive(false);
253
- if (disabled)
254
- return;
255
- handleFile(event.dataTransfer.files?.[0]);
256
- };
257
- // Mouse convenience only: clicking the styled zone opens the picker. A
258
- // click that ORIGINATED on the input already opens it natively and bubbles
259
- // up to here — re-firing .click() would open the picker twice, so ignore it.
260
- const openPicker = (event) => {
261
- if (disabled || event.target === internalRef.current)
262
- return;
263
- internalRef.current?.click();
264
- };
265
- const clear = () => {
266
- readerRef.current?.abort();
267
- readerRef.current = null;
268
- setError(null);
269
- onSelect(null);
270
- // Reset the native input so re-picking the same filename fires onChange.
271
- if (internalRef.current)
272
- internalRef.current.value = '';
273
- };
274
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)('space-y-2', className), children: [(0, jsx_runtime_1.jsxs)("div", { onClick: openPicker, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop, className: (0, utils_1.cn)('border-input-border bg-card focus-within:ring-ring focus-within:ring-offset-background aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-within:ring-destructive flex w-full items-center gap-3 rounded-md border px-3 py-4 text-sm shadow-xs transition-colors focus-within:ring-2 focus-within:ring-offset-1 focus-within:outline-none', dragActive &&
275
- 'border-ring ring-ring ring-offset-background ring-2 ring-offset-1', disabled
276
- ? 'border-muted bg-muted/30 cursor-not-allowed shadow-none'
277
- : 'cursor-pointer'), "aria-invalid": invalid || undefined, children: [(0, jsx_runtime_1.jsx)("input", { ref: internalRef, id: inputId, type: "file", accept: accept, disabled: disabled, className: "sr-only", "aria-invalid": invalid || undefined, "aria-required": ariaRequired || undefined, "aria-describedby": describedBy, "aria-label": ariaLabel, onChange: onInputChange, ...rest }), (0, jsx_runtime_1.jsx)(lucide_react_1.Upload, { className: "text-muted-foreground size-4 shrink-0", "aria-hidden": "true" }), value ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-foreground font-medium", children: value.file.name }), ' ', (0, jsx_runtime_1.jsx)("span", { className: "text-muted-foreground tabular-nums", children: humanizeSize(value.file.size) })] }), (0, jsx_runtime_1.jsx)(icon_button_1.IconButton, { type: "button", variant: "plain", size: "small", disabled: disabled, "aria-label": labels?.remove?.trim() ? labels.remove : 'Remove file', onClick: (event) => {
278
- // Don't bubble to the zone's openPicker and re-open the dialog.
279
- event.stopPropagation();
280
- clear();
281
- }, children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { className: "size-4", "aria-hidden": "true" }) })] })) : ((0, jsx_runtime_1.jsxs)("span", { className: "text-muted-foreground", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-foreground font-medium", children: labels?.action ?? 'Choose a file' }), ' ', labels?.hint ?? 'or drag and drop'] }))] }), errorText ? ((0, jsx_runtime_1.jsx)("p", { id: errorId, role: "alert", className: "text-system-error-h1a text-xs font-medium", children: errorText })) : null] }));
282
- });
283
- exports.FileUpload.displayName = 'FileUpload';
284
- /** The default English announcement for each rejection kind. */
285
- function defaultMultipleErrorMessage(error) {
286
- if (error.kind === 'too-many') {
287
- return `Too many files (max ${error.maxFiles}). ${error.file.name} was not added.`;
288
- }
289
- return defaultErrorMessage(error);
290
- }
291
- /** The default zone copy once the cap is reached, in grammatical English. */
292
- function defaultFullMessage(maxFiles) {
293
- return maxFiles === 1
294
- ? 'Maximum of 1 file reached.'
295
- : `Maximum of ${maxFiles} files reached.`;
296
- }
297
- /**
298
- * MultipleFileUpload: the plural sibling of FileUpload. Pick SEVERAL files,
299
- * accumulate them across repeated picks, validate each one, cap the total, and
300
- * hand back `FileUploadResult[]`.
301
- *
302
- * A SIBLING COMPONENT, not a `multiple` flag. This library already answers
303
- * "this one takes many" that way (`Select` / `MultipleSelect`), and FileUpload
304
- * strips `'multiple'` from its props on purpose: single-file is its contract,
305
- * not a default it happens to have. A boolean would have forced every prop
306
- * here into a union that means one thing when the flag is set and another when
307
- * it is not: `value` as `Result | Result[] | null`, a `maxFiles` that is
308
- * meaningless in half the configurations, and a remove control whose
309
- * accessible name is fixed copy in one mode and per-file in the other. The
310
- * plural props follow the house shape for plural components: `value?: T[]`
311
- * with `onValueChange?: (values: T[]) => void`.
312
- *
313
- * WHERE THE LINE SITS: this component owns SELECTION and nothing after it.
314
- * Choosing, validating, capping, listing and removing are its job; uploading
315
- * is not. That split is not squeamishness about scope, it is where the
316
- * knowledge actually lives. An upload needs an endpoint, an auth scheme, a
317
- * concurrency policy, a retry policy and, very often, a parent id that does
318
- * not exist yet when the files are chosen: the motivating host stages evidence
319
- * files while a form is being filled and can only upload them against the id
320
- * that its create call returns afterwards. None of that is knowable from
321
- * inside a library primitive, and a component that guessed would have to be
322
- * fought rather than used. So the host keeps its own per-file record with
323
- * status and retry, and this component keeps the part a form can hold and
324
- * validate: the chosen files. `FileUploadResult[]` is a value; an upload state
325
- * machine is not.
326
- *
327
- * ACCUMULATION is the defining behaviour. A second pick ADDS to the selection
328
- * rather than replacing it, because a user assembling five documents does it
329
- * in two or three trips to the file dialog, not one. Everything else follows
330
- * from that: room is measured against what is already selected, and the batch
331
- * that overflows the cap still contributes the files that fit.
332
- *
333
- * A BATCH SURVIVES ITS OWN CASUALTIES. One file rejected for type, size or a
334
- * failed read does not discard the rest of the batch, and it does not consume
335
- * a slot either: validation runs over the WHOLE batch before the cap is
336
- * applied, so a file that was never eligible cannot cost an eligible one its
337
- * place, and `'too-many'` always names a file a slot would genuinely have
338
- * taken. The alternative punishes
339
- * a user for a mistake in one file by throwing away four good ones, and hands
340
- * back no way to tell which was which. Every rejection is reported through
341
- * `onError` and announced together in one `role="alert"`.
342
- *
343
- * Accessibility follows the sibling BELOW THE CAP: the real `<input
344
- * type="file">` is `sr-only` but focusable and labelable, and never
345
- * `aria-hidden`, so FormControl-injected ARIA and react-hook-form's focus on
346
- * error both work while the picker is enabled. At the cap that changes, and
347
- * the paragraph below says how.
348
- * The file list sits OUTSIDE the click zone, so activating a remove control
349
- * cannot also reopen the picker, and each remove control is named after its
350
- * own file: a column of identical "Remove file" buttons tells a screen-reader
351
- * user nothing about which row they are on.
352
- *
353
- * AT THE CAP the picker takes the native `disabled` attribute, and that DOES
354
- * take it out of the tab order. This is the one state in which the input is
355
- * not a focus target, and the one state in which focus-on-error cannot land on
356
- * it, so it is a real cost rather than a free win. The cap has no counterpart
357
- * in the single-file sibling, so the precedent followed here is
358
- * `DateRangePicker`'s trigger: a control whose only job is to open a dialog has
359
- * no state worth keeping focusable, and native `disabled` is what both removes
360
- * it from the tab order and keeps the dialog shut. The alternative, an enabled
361
- * picker that opens the file dialog and then refuses every file with
362
- * `too-many`, is a control that lies about being available. What keeps the cap
363
- * from being a dead end is the escape hatch: the remove controls answer to
364
- * `disabled` alone and NEVER to the cap, so they stay focusable and removing
365
- * one file reopens the picker.
366
- */
367
- exports.MultipleFileUpload = React.forwardRef(function MultipleFileUpload({ accept, maxSizeBytes, maxFiles, value = [], readAs = 'text', labels, onValueChange, onError, disabled = false, id, className, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, 'aria-describedby': ariaDescribedby, 'aria-label': ariaLabel, ...rest }, ref) {
368
- const internalRef = React.useRef(null);
369
- React.useImperativeHandle(ref, () => internalRef.current);
370
- const reactId = React.useId();
371
- const inputId = id ?? reactId;
372
- const errorId = `${inputId}-file-upload-error`;
373
- const [dragActive, setDragActive] = React.useState(false);
374
- const [errors, setErrors] = React.useState([]);
375
- // The authoritative base for the next append. Props win on every render, so
376
- // the host stays in control; the commit below also writes through, so a
377
- // second batch that settles before the host has re-rendered still appends to
378
- // the first batch's result instead of overwriting it.
379
- const valueRef = React.useRef(value);
380
- React.useEffect(() => {
381
- valueRef.current = value;
382
- });
383
- // Superseding is NOT the contract here the way it is in the single-file
384
- // sibling — batches accumulate, so an in-flight read is never stale. The
385
- // readers are tracked for the one case that does have to stop them: an
386
- // unmount. A read that lands afterwards would settle its batch and commit,
387
- // calling the host's `onValueChange` for a component that no longer exists.
388
- const readersRef = React.useRef(new Set());
389
- React.useEffect(() => () => {
390
- for (const reader of readersRef.current)
391
- reader.abort();
392
- readersRef.current.clear();
393
- }, []);
394
- const invalid = ariaInvalid || errors.length > 0;
395
- // Resolve the announcements BEFORE deciding whether the alert exists: a
396
- // consumer that returns nothing for every rejection is opting out of this
397
- // surface, and an association pointing at an unrendered node is worse than
398
- // none.
399
- const messages = errors
400
- .map((failure) => labels?.error
401
- ? labels.error(failure)
402
- : defaultMultipleErrorMessage(failure))
403
- .filter((message) => Boolean(message));
404
- // A plain join, never `cn`: tailwind-merge treats these as class names and
405
- // would drop an id that happens to look like a conflicting utility.
406
- const describedBy = [ariaDescribedby, messages.length > 0 ? errorId : undefined]
407
- .filter(Boolean)
408
- .join(' ') || undefined;
409
- const full = maxFiles !== undefined && value.length >= maxFiles;
410
- // Removing must stay possible at the cap, so only the PICKER closes.
411
- const pickerDisabled = disabled || full;
412
- const roomFor = (selected) => maxFiles === undefined
413
- ? Number.POSITIVE_INFINITY
414
- : Math.max(maxFiles - selected, 0);
415
- // The cap is enforced HERE, at the only place that appends, because only the
416
- // commit knows the base it lands on. `ingest` measures room too, but for an
417
- // asynchronous batch it measures it BEFORE any read settles: two overlapping
418
- // batches both see the pre-commit selection and would each believe they fit.
419
- const commit = (accepted, rejections) => {
420
- const room = roomFor(valueRef.current.length);
421
- const fitting = accepted.slice(0, room);
422
- const overflow = accepted[room];
423
- const failures = overflow !== undefined && maxFiles !== undefined
424
- ? [
425
- ...rejections,
426
- { kind: 'too-many', file: overflow.file, maxFiles }
427
- ]
428
- : rejections;
429
- setErrors(failures);
430
- for (const rejection of failures)
431
- onError?.(rejection);
432
- if (fitting.length === 0)
433
- return;
434
- const next = [...valueRef.current, ...fitting];
435
- valueRef.current = next;
436
- onValueChange(next);
437
- };
438
- const ingest = (incoming) => {
439
- if (incoming.length === 0)
440
- return;
441
- const room = roomFor(valueRef.current.length);
442
- const rejections = [];
443
- // Validate EVERY file BEFORE the cap is applied. Slicing to the remaining
444
- // room first would let a file that was never eligible consume a slot a
445
- // good file could have used — one bad pick costing a good one, which is
446
- // the opposite of a batch surviving its own casualties — and it would
447
- // leave every file past the slice window neither validated nor reported.
448
- // Validation is pure metadata (size and accept), so running it over files
449
- // that may not fit costs nothing.
450
- const eligible = [];
451
- for (const file of incoming) {
452
- const rejection = validateFile(file, { accept, maxSizeBytes });
453
- // Continue rather than abort: one bad file must not cost the good ones.
454
- if (rejection) {
455
- rejections.push(rejection);
456
- continue;
457
- }
458
- eligible.push(file);
459
- }
460
- // The cap then applies to the SURVIVORS. One rejection for the batch,
461
- // naming the FIRST eligible file that did not fit: naming one already
462
- // refused for its size or type would blame the cap for the wrong thing,
463
- // and repeating it per overflowing file buries the actionable part.
464
- if (eligible.length > room && maxFiles !== undefined) {
465
- rejections.push({ kind: 'too-many', file: eligible[room], maxFiles });
466
- }
467
- const candidates = eligible.slice(0, room);
468
- // Binary path: no decode, no reader, no retained garbage string.
469
- if (readAs === 'none') {
470
- commit(candidates.map((file) => ({ file, text: '' })), rejections);
471
- return;
472
- }
473
- if (candidates.length === 0) {
474
- commit([], rejections);
475
- return;
476
- }
477
- // Slot-per-candidate so the emitted batch keeps PICK order regardless of
478
- // the order the reads settle in. A null slot is a read that failed; the
479
- // batch commits once every read has settled, one way or the other.
480
- const slots = new Array(candidates.length).fill(null);
481
- let remaining = candidates.length;
482
- const settle = () => {
483
- remaining -= 1;
484
- if (remaining > 0)
485
- return;
486
- const accepted = [];
487
- const readFailures = [];
488
- slots.forEach((slot, index) => {
489
- if (slot)
490
- accepted.push(slot);
491
- else
492
- readFailures.push({ kind: 'read-failed', file: candidates[index] });
493
- });
494
- commit(accepted, [...rejections, ...readFailures]);
495
- };
496
- candidates.forEach((file, index) => {
497
- const reader = new FileReader();
498
- readersRef.current.add(reader);
499
- // Deliberately no `onabort` handler: an aborted read must NOT settle,
500
- // or the batch would commit at exactly the moment we are stopping it.
501
- reader.onload = () => {
502
- readersRef.current.delete(reader);
503
- slots[index] = { file, text: String(reader.result ?? '') };
504
- settle();
505
- };
506
- reader.onerror = () => {
507
- readersRef.current.delete(reader);
508
- settle();
509
- };
510
- reader.readAsText(file);
511
- });
512
- };
513
- const onInputChange = (event) => {
514
- const files = Array.from(event.target.files ?? []);
515
- // Release the FileList the moment it has been read, or re-picking the same
516
- // file is silently a no-op: the browser fires `change` only when the
517
- // selection DIFFERS from what the input already holds.
518
- event.target.value = '';
519
- ingest(files);
520
- };
521
- // `preventDefault` FIRST, and unconditionally. Returning before it does
522
- // not merely refuse the drop: nothing cancels the browser's OWN action for
523
- // a dropped file, so the window navigates to the file and whatever the
524
- // page held unsaved is gone. A zone the host turned off has to swallow the
525
- // drop, never hand it back to the browser. `dropEffect` says so to the
526
- // cursor while the file is still in the air.
527
- const onDragOver = (event) => {
528
- event.preventDefault();
529
- if (disabled) {
530
- event.dataTransfer.dropEffect = 'none';
531
- return;
532
- }
533
- setDragActive(true);
534
- };
535
- const onDragLeave = (event) => {
536
- event.preventDefault();
537
- setDragActive(false);
538
- };
539
- const onDrop = (event) => {
540
- event.preventDefault();
541
- // Cleared before the gate, not after, so a host that disables the zone
542
- // mid-drag does not leave it highlighted for a drag that can no longer
543
- // land.
544
- setDragActive(false);
545
- if (disabled)
546
- return;
547
- // Deliberately NOT gated on `full`: a drop onto a full zone is answered
548
- // with the too-many rejection, which says why, instead of nothing at all.
549
- ingest(Array.from(event.dataTransfer.files ?? []));
550
- };
551
- // Mouse convenience only. A click that ORIGINATED on the input already opens
552
- // the picker natively and bubbles up here, so ignore it or it opens twice.
553
- const openPicker = (event) => {
554
- if (pickerDisabled || event.target === internalRef.current)
555
- return;
556
- internalRef.current?.click();
557
- };
558
- const removeAt = (index) => {
559
- // By index, not by name: two files can share a filename and identity is
560
- // what the row actually stands for.
561
- const next = valueRef.current.filter((_, position) => position !== index);
562
- valueRef.current = next;
563
- onValueChange(next);
564
- };
565
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, utils_1.cn)('space-y-2', className), children: [(0, jsx_runtime_1.jsxs)("div", { onClick: openPicker, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop, className: (0, utils_1.cn)('border-input-border bg-card focus-within:ring-ring focus-within:ring-offset-background aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-within:ring-destructive flex w-full items-center gap-3 rounded-md border px-3 py-4 text-sm shadow-xs transition-colors focus-within:ring-2 focus-within:ring-offset-1 focus-within:outline-none', dragActive &&
566
- 'border-ring ring-ring ring-offset-background ring-2 ring-offset-1', pickerDisabled
567
- ? 'border-muted bg-muted/30 cursor-not-allowed shadow-none'
568
- : 'cursor-pointer'), "aria-invalid": invalid || undefined, children: [(0, jsx_runtime_1.jsx)("input", { ref: internalRef, id: inputId, type: "file", multiple: true, accept: accept, disabled: pickerDisabled, className: "sr-only", "aria-invalid": invalid || undefined, "aria-required": ariaRequired || undefined, "aria-describedby": describedBy, "aria-label": ariaLabel, onChange: onInputChange, ...rest }), (0, jsx_runtime_1.jsx)(lucide_react_1.Upload, { className: "text-muted-foreground size-4 shrink-0", "aria-hidden": "true" }), full && maxFiles !== undefined ? ((0, jsx_runtime_1.jsx)("span", { className: "text-muted-foreground", children: labels?.full
569
- ? labels.full(maxFiles)
570
- : defaultFullMessage(maxFiles) })) : ((0, jsx_runtime_1.jsxs)("span", { className: "text-muted-foreground", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-foreground font-medium", children: labels?.action ?? 'Choose files' }), ' ', labels?.hint ?? 'or drag and drop'] }))] }), value.length > 0 ? ((0, jsx_runtime_1.jsx)("ul", { className: "space-y-1", children: value.map((entry, index) => ((0, jsx_runtime_1.jsxs)("li", { className: "flex items-center gap-3 text-sm", children: [(0, jsx_runtime_1.jsxs)("span", { className: "min-w-0 flex-1 truncate", children: [(0, jsx_runtime_1.jsx)("span", { className: "text-foreground font-medium", children: entry.file.name }), ' ', (0, jsx_runtime_1.jsx)("span", { className: "text-muted-foreground tabular-nums", children: humanizeSize(entry.file.size) })] }), (0, jsx_runtime_1.jsx)(icon_button_1.IconButton, { type: "button", variant: "plain", size: "small", disabled: disabled, "aria-label": labels?.remove
571
- ? labels.remove(entry.file)
572
- : `Remove ${entry.file.name}`, onClick: () => removeAt(index), children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { className: "size-4", "aria-hidden": "true" }) })] }, `${entry.file.name}-${index}`))) })) : null, messages.length > 0 ? ((0, jsx_runtime_1.jsx)("div", { id: errorId, role: "alert", className: "space-y-1", children: messages.map((message, index) => ((0, jsx_runtime_1.jsx)("p", { className: "text-system-error-h1a text-xs font-medium", children: message }, index))) })) : null] }));
573
- });
574
- exports.MultipleFileUpload.displayName = 'MultipleFileUpload';
1
+ "use client";"use strict";var __createBinding=this&&this.__createBinding||(Object.create?(function(r,n,a,e){if(e===void 0)e=a;var i=Object.getOwnPropertyDescriptor(n,a);if(!i||("get"in i?!n.__esModule:i.writable||i.configurable)){i={enumerable:true,get:function(){return n[a]}}}Object.defineProperty(r,e,i)}):(function(r,n,a,e){if(e===void 0)e=a;r[e]=n[a]}));var __setModuleDefault=this&&this.__setModuleDefault||(Object.create?(function(r,n){Object.defineProperty(r,"default",{enumerable:true,value:n})}):function(r,n){r["default"]=n});var __importStar=this&&this.__importStar||(function(){var r=function(n){r=Object.getOwnPropertyNames||function(a){var e=[];for(var i in a)if(Object.prototype.hasOwnProperty.call(a,i))e[e.length]=i;return e};return r(n)};return function(n){if(n&&n.__esModule)return n;var a={};if(n!=null){for(var e=r(n),i=0;i<e.length;i++)if(e[i]!=="default")__createBinding(a,n,e[i])}__setModuleDefault(a,n);return a}})();Object.defineProperty(exports,"__esModule",{value:true});exports.MultipleFileUpload=exports.FileUpload=void 0;exports.validateFile=validateFile;exports.humanizeSize=humanizeSize;const jsx_runtime_1=require("react/jsx-runtime");const React=__importStar(require("react"));const lucide_react_1=require("lucide-react");const icon_button_1=require("../../../components/ui/icon-button");const utils_1=require("../../../lib/utils");function validateFile(r,n){const{accept:a,maxSizeBytes:e}=n;if(typeof e==="number"&&r.size>e){return{kind:"too-large",file:r,maxSizeBytes:e}}if(a&&a.trim()!==""&&!matchesAccept(r,a)){return{kind:"wrong-type",file:r,accept:a}}return null}function matchesAccept(r,n){const a=r.name.toLowerCase();const e=r.type.toLowerCase();return n.split(",").map(i=>i.trim().toLowerCase()).filter(i=>i!=="").some(i=>{if(i.startsWith("."))return a.endsWith(i);if(i.endsWith("/*"))return e.startsWith(i.slice(0,-1));return e===i})}function humanizeSize(r){if(r<1024)return`${r} B`;const n=["KB","MB","GB"];let a=r/1024;let e=0;while(a>=1024&&e<n.length-1){a/=1024;e+=1}return`${a.toFixed(1)} ${n[e]}`}function defaultErrorMessage(r){switch(r.kind){case"too-large":return`File is too large (max ${humanizeSize(r.maxSizeBytes)}).`;case"wrong-type":return`File type not allowed (expected ${r.accept}).`;case"read-failed":return"Could not read the file."}}exports.FileUpload=React.forwardRef(function r({accept:n,maxSizeBytes:a,value:e,readAs:i="text",labels:v,onSelect:l,onError:M,disabled:b=false,id:D,className:W,"aria-invalid":H,"aria-required":K,"aria-describedby":X,"aria-label":G,...Y},J){const j=React.useRef(null);React.useImperativeHandle(J,()=>j.current);const I=React.useId();const $=D??I;const R=`${$}-file-upload-error`;const[E,z]=React.useState(false);const[w,y]=React.useState(null);const S=H||w!==null;const c=w?v?.error?v.error(w):defaultErrorMessage(w):null;const p=c?c:null;const U=[X,p?R:void 0].filter(Boolean).join(" ")||void 0;const u=React.useRef(null);const A=o=>{if(!o)return;u.current?.abort();const N=validateFile(o,{accept:n,maxSizeBytes:a});if(N){y(N);M?.(N);return}if(i==="none"){u.current=null;y(null);l({file:o,text:""});return}const m=new FileReader;u.current=m;m.onload=()=>{if(u.current!==m)return;u.current=null;y(null);l({file:o,text:String(m.result??"")})};m.onerror=()=>{if(u.current!==m)return;u.current=null;const q={kind:"read-failed",file:o};y(q);M?.(q)};m.readAsText(o)};const P=o=>{const N=o.target.files?.[0];o.target.value="";A(N)};const O=o=>{o.preventDefault();if(b){o.dataTransfer.dropEffect="none";return}z(true)};const T=o=>{o.preventDefault();z(false)};const B=o=>{o.preventDefault();z(false);if(b)return;A(o.dataTransfer.files?.[0])};const k=o=>{if(b||o.target===j.current)return;j.current?.click()};const Q=()=>{u.current?.abort();u.current=null;y(null);l(null);if(j.current)j.current.value=""};return(0,jsx_runtime_1.jsxs)("div",{className:(0,utils_1.cn)("space-y-2",W),children:[(0,jsx_runtime_1.jsxs)("div",{onClick:k,onDragOver:O,onDragLeave:T,onDrop:B,className:(0,utils_1.cn)("border-input-border bg-card focus-within:ring-ring focus-within:ring-offset-background aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-within:ring-destructive flex w-full items-center gap-3 rounded-md border px-3 py-4 text-sm shadow-xs transition-colors focus-within:ring-2 focus-within:ring-offset-1 focus-within:outline-none",E&&"border-ring ring-ring ring-offset-background ring-2 ring-offset-1",b?"border-muted bg-muted/30 cursor-not-allowed shadow-none":"cursor-pointer"),"aria-invalid":S||void 0,children:[(0,jsx_runtime_1.jsx)("input",{ref:j,id:$,type:"file",accept:n,disabled:b,className:"sr-only","aria-invalid":S||void 0,"aria-required":K||void 0,"aria-describedby":U,"aria-label":G,onChange:P,...Y}),(0,jsx_runtime_1.jsx)(lucide_react_1.Upload,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":"true"}),e?(0,jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment,{children:[(0,jsx_runtime_1.jsxs)("span",{className:"min-w-0 flex-1 truncate",children:[(0,jsx_runtime_1.jsx)("span",{className:"text-foreground font-medium",children:e.file.name})," ",(0,jsx_runtime_1.jsx)("span",{className:"text-muted-foreground tabular-nums",children:humanizeSize(e.file.size)})]}),(0,jsx_runtime_1.jsx)(icon_button_1.IconButton,{type:"button",variant:"plain",size:"small",disabled:b,"aria-label":v?.remove?.trim()?v.remove:"Remove file",onClick:o=>{o.stopPropagation();Q()},children:(0,jsx_runtime_1.jsx)(lucide_react_1.X,{className:"size-4","aria-hidden":"true"})})]}):(0,jsx_runtime_1.jsxs)("span",{className:"text-muted-foreground",children:[(0,jsx_runtime_1.jsx)("span",{className:"text-foreground font-medium",children:v?.action??"Choose a file"})," ",v?.hint??"or drag and drop"]})]}),p?(0,jsx_runtime_1.jsx)("p",{id:R,role:"alert",className:"text-system-error-h1a text-xs font-medium",children:p}):null]})});exports.FileUpload.displayName="FileUpload";function defaultMultipleErrorMessage(r){if(r.kind==="too-many"){return`Too many files (max ${r.maxFiles}). ${r.file.name} was not added.`}return defaultErrorMessage(r)}function defaultFullMessage(r){return r===1?"Maximum of 1 file reached.":`Maximum of ${r} files reached.`}exports.MultipleFileUpload=React.forwardRef(function r({accept:n,maxSizeBytes:a,maxFiles:e,value:i=[],readAs:v="text",labels:l,onValueChange:M,onError:b,disabled:D=false,id:W,className:H,"aria-invalid":K,"aria-required":X,"aria-describedby":G,"aria-label":Y,...J},j){const I=React.useRef(null);React.useImperativeHandle(j,()=>I.current);const $=React.useId();const R=W??$;const E=`${R}-file-upload-error`;const[z,w]=React.useState(false);const[y,S]=React.useState([]);const c=React.useRef(i);React.useEffect(()=>{c.current=i});const p=React.useRef(new Set);React.useEffect(()=>()=>{for(const t of p.current)t.abort();p.current.clear()},[]);const U=K||y.length>0;const u=y.map(t=>l?.error?l.error(t):defaultMultipleErrorMessage(t)).filter(t=>Boolean(t));const A=[G,u.length>0?E:void 0].filter(Boolean).join(" ")||void 0;const P=e!==void 0&&i.length>=e;const O=D||P;const T=t=>e===void 0?Number.POSITIVE_INFINITY:Math.max(e-t,0);const B=(t,s)=>{const g=T(c.current.length);const h=t.slice(0,g);const x=t[g];const C=x!==void 0&&e!==void 0?[...s,{kind:"too-many",file:x.file,maxFiles:e}]:s;S(C);for(const L of C)b?.(L);if(h.length===0)return;const F=[...c.current,...h];c.current=F;M(F)};const k=t=>{if(t.length===0)return;const s=T(c.current.length);const g=[];const h=[];for(const d of t){const _=validateFile(d,{accept:n,maxSizeBytes:a});if(_){g.push(_);continue}h.push(d)}if(h.length>s&&e!==void 0){g.push({kind:"too-many",file:h[s],maxFiles:e})}const x=h.slice(0,s);if(v==="none"){B(x.map(d=>({file:d,text:""})),g);return}if(x.length===0){B([],g);return}const C=new Array(x.length).fill(null);let F=x.length;const L=()=>{F-=1;if(F>0)return;const d=[];const _=[];C.forEach((f,Z)=>{if(f)d.push(f);else _.push({kind:"read-failed",file:x[Z]})});B(d,[...g,..._])};x.forEach((d,_)=>{const f=new FileReader;p.current.add(f);f.onload=()=>{p.current.delete(f);C[_]={file:d,text:String(f.result??"")};L()};f.onerror=()=>{p.current.delete(f);L()};f.readAsText(d)})};const Q=t=>{const s=Array.from(t.target.files??[]);t.target.value="";k(s)};const o=t=>{t.preventDefault();if(D){t.dataTransfer.dropEffect="none";return}w(true)};const N=t=>{t.preventDefault();w(false)};const m=t=>{t.preventDefault();w(false);if(D)return;k(Array.from(t.dataTransfer.files??[]))};const q=t=>{if(O||t.target===I.current)return;I.current?.click()};const V=t=>{const s=c.current.filter((g,h)=>h!==t);c.current=s;M(s)};return(0,jsx_runtime_1.jsxs)("div",{className:(0,utils_1.cn)("space-y-2",H),children:[(0,jsx_runtime_1.jsxs)("div",{onClick:q,onDragOver:o,onDragLeave:N,onDrop:m,className:(0,utils_1.cn)("border-input-border bg-card focus-within:ring-ring focus-within:ring-offset-background aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-within:ring-destructive flex w-full items-center gap-3 rounded-md border px-3 py-4 text-sm shadow-xs transition-colors focus-within:ring-2 focus-within:ring-offset-1 focus-within:outline-none",z&&"border-ring ring-ring ring-offset-background ring-2 ring-offset-1",O?"border-muted bg-muted/30 cursor-not-allowed shadow-none":"cursor-pointer"),"aria-invalid":U||void 0,children:[(0,jsx_runtime_1.jsx)("input",{ref:I,id:R,type:"file",multiple:true,accept:n,disabled:O,className:"sr-only","aria-invalid":U||void 0,"aria-required":X||void 0,"aria-describedby":A,"aria-label":Y,onChange:Q,...J}),(0,jsx_runtime_1.jsx)(lucide_react_1.Upload,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":"true"}),P&&e!==void 0?(0,jsx_runtime_1.jsx)("span",{className:"text-muted-foreground",children:l?.full?l.full(e):defaultFullMessage(e)}):(0,jsx_runtime_1.jsxs)("span",{className:"text-muted-foreground",children:[(0,jsx_runtime_1.jsx)("span",{className:"text-foreground font-medium",children:l?.action??"Choose files"})," ",l?.hint??"or drag and drop"]})]}),i.length>0?(0,jsx_runtime_1.jsx)("ul",{className:"space-y-1",children:i.map((t,s)=>(0,jsx_runtime_1.jsxs)("li",{className:"flex items-center gap-3 text-sm",children:[(0,jsx_runtime_1.jsxs)("span",{className:"min-w-0 flex-1 truncate",children:[(0,jsx_runtime_1.jsx)("span",{className:"text-foreground font-medium",children:t.file.name})," ",(0,jsx_runtime_1.jsx)("span",{className:"text-muted-foreground tabular-nums",children:humanizeSize(t.file.size)})]}),(0,jsx_runtime_1.jsx)(icon_button_1.IconButton,{type:"button",variant:"plain",size:"small",disabled:D,"aria-label":l?.remove?l.remove(t.file):`Remove ${t.file.name}`,onClick:()=>V(s),children:(0,jsx_runtime_1.jsx)(lucide_react_1.X,{className:"size-4","aria-hidden":"true"})})]},`${t.file.name}-${s}`))}):null,u.length>0?(0,jsx_runtime_1.jsx)("div",{id:E,role:"alert",className:"space-y-1",children:u.map((t,s)=>(0,jsx_runtime_1.jsx)("p",{className:"text-system-error-h1a text-xs font-medium",children:t},s))}):null]})});exports.MultipleFileUpload.displayName="MultipleFileUpload";