@godxjp/ui 19.6.0 → 20.1.0

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 (326) hide show
  1. package/README.md +8 -2
  2. package/dist/app/theme-axes.d.ts +2 -0
  3. package/dist/app/theme-axes.js +45 -0
  4. package/dist/components/charts/chart-cartesian.d.ts +2 -1
  5. package/dist/components/charts/chart-cartesian.js +52 -3
  6. package/dist/components/charts/chart-category-axis.d.ts +55 -0
  7. package/dist/components/charts/chart-category-axis.js +93 -0
  8. package/dist/components/charts/chart-frame.d.ts +10 -1
  9. package/dist/components/charts/chart-frame.js +19 -3
  10. package/dist/components/charts/compact-bar-trend.d.ts +1 -1
  11. package/dist/components/charts/compact-bar-trend.js +2 -0
  12. package/dist/components/charts/pie-chart.d.ts +1 -1
  13. package/dist/components/charts/pie-chart.js +12 -1
  14. package/dist/components/charts/recharts-peer.d.ts +49 -0
  15. package/dist/components/charts/recharts-peer.js +45 -0
  16. package/dist/components/data-display/card.d.ts +14 -3
  17. package/dist/components/data-display/card.js +22 -4
  18. package/dist/components/data-display/code-block.js +6 -2
  19. package/dist/components/data-display/collapsible.d.ts +23 -4
  20. package/dist/components/data-display/collapsible.js +119 -4
  21. package/dist/components/data-display/data-table.d.ts +39 -4
  22. package/dist/components/data-display/data-table.js +802 -270
  23. package/dist/components/data-display/descriptions.d.ts +27 -6
  24. package/dist/components/data-display/descriptions.js +58 -17
  25. package/dist/components/data-display/index.d.ts +5 -1
  26. package/dist/components/data-display/index.js +4 -0
  27. package/dist/components/data-display/legend.d.ts +15 -0
  28. package/dist/components/data-display/legend.js +11 -0
  29. package/dist/components/data-display/list-row.d.ts +10 -1
  30. package/dist/components/data-display/list-row.js +8 -2
  31. package/dist/components/data-display/popover.d.ts +60 -7
  32. package/dist/components/data-display/popover.js +268 -39
  33. package/dist/components/data-display/progress.d.ts +50 -2
  34. package/dist/components/data-display/progress.js +57 -9
  35. package/dist/components/data-display/range-timeline.d.ts +38 -0
  36. package/dist/components/data-display/range-timeline.js +161 -0
  37. package/dist/components/data-display/scroll-area.js +13 -2
  38. package/dist/components/data-display/service-launcher-card.js +10 -10
  39. package/dist/components/data-display/table.d.ts +11 -3
  40. package/dist/components/data-display/table.js +48 -18
  41. package/dist/components/data-display/tree-list.js +4 -9
  42. package/dist/components/data-entry/calendar.d.ts +2 -2
  43. package/dist/components/data-entry/calendar.js +79 -33
  44. package/dist/components/data-entry/cascader.d.ts +1 -1
  45. package/dist/components/data-entry/cascader.js +188 -24
  46. package/dist/components/data-entry/checkbox.d.ts +19 -6
  47. package/dist/components/data-entry/checkbox.js +55 -16
  48. package/dist/components/data-entry/choice-option.d.ts +1 -1
  49. package/dist/components/data-entry/color-picker.d.ts +1 -1
  50. package/dist/components/data-entry/color-picker.js +17 -5
  51. package/dist/components/data-entry/control-appearance.d.ts +64 -0
  52. package/dist/components/data-entry/control-appearance.js +39 -0
  53. package/dist/components/data-entry/control-surface.d.ts +61 -0
  54. package/dist/components/data-entry/control-surface.js +39 -0
  55. package/dist/components/data-entry/date-picker.d.ts +1 -1
  56. package/dist/components/data-entry/date-picker.js +344 -113
  57. package/dist/components/data-entry/date-range-picker.d.ts +2 -2
  58. package/dist/components/data-entry/date-range-picker.js +278 -140
  59. package/dist/components/data-entry/field.js +0 -1
  60. package/dist/components/data-entry/form-field.d.ts +1 -1
  61. package/dist/components/data-entry/form-field.js +39 -4
  62. package/dist/components/data-entry/form.d.ts +4 -0
  63. package/dist/components/data-entry/form.js +5 -3
  64. package/dist/components/data-entry/index.d.ts +7 -3
  65. package/dist/components/data-entry/index.js +10 -1
  66. package/dist/components/data-entry/input-otp.d.ts +1 -1
  67. package/dist/components/data-entry/input.d.ts +12 -34
  68. package/dist/components/data-entry/input.js +92 -24
  69. package/dist/components/data-entry/label.d.ts +3 -2
  70. package/dist/components/data-entry/label.js +23 -10
  71. package/dist/components/data-entry/month-picker.d.ts +2 -2
  72. package/dist/components/data-entry/month-picker.js +47 -10
  73. package/dist/components/data-entry/month-range-picker.d.ts +2 -2
  74. package/dist/components/data-entry/month-range-picker.js +51 -11
  75. package/dist/components/data-entry/number-input.d.ts +7 -0
  76. package/dist/components/data-entry/number-input.js +147 -98
  77. package/dist/components/data-entry/password-input.d.ts +1 -1
  78. package/dist/components/data-entry/radio.d.ts +1 -1
  79. package/dist/components/data-entry/radio.js +61 -13
  80. package/dist/components/data-entry/search-input.d.ts +1 -1
  81. package/dist/components/data-entry/search-input.js +16 -2
  82. package/dist/components/data-entry/search-select.d.ts +2 -2
  83. package/dist/components/data-entry/search-select.js +209 -78
  84. package/dist/components/data-entry/select.d.ts +22 -4
  85. package/dist/components/data-entry/select.js +215 -163
  86. package/dist/components/data-entry/slider.d.ts +9 -1
  87. package/dist/components/data-entry/slider.js +87 -9
  88. package/dist/components/data-entry/switch.d.ts +3 -0
  89. package/dist/components/data-entry/switch.js +29 -3
  90. package/dist/components/data-entry/textarea.d.ts +14 -56
  91. package/dist/components/data-entry/textarea.js +80 -33
  92. package/dist/components/data-entry/time-picker.d.ts +2 -2
  93. package/dist/components/data-entry/time-picker.js +333 -109
  94. package/dist/components/data-entry/time-range-picker.d.ts +5 -0
  95. package/dist/components/data-entry/time-range-picker.js +89 -0
  96. package/dist/components/data-entry/transfer.d.ts +1 -1
  97. package/dist/components/data-entry/transfer.js +99 -31
  98. package/dist/components/data-entry/tree-select-strategy.d.ts +1 -1
  99. package/dist/components/data-entry/tree-select.d.ts +1 -1
  100. package/dist/components/data-entry/tree-select.js +197 -92
  101. package/dist/components/data-entry/tree-utils.d.ts +1 -1
  102. package/dist/components/data-entry/tree-utils.js +7 -14
  103. package/dist/components/data-entry/upload-files.d.ts +2 -0
  104. package/dist/components/data-entry/upload-files.js +31 -0
  105. package/dist/components/data-entry/upload-request.d.ts +4 -0
  106. package/dist/components/data-entry/upload-request.js +53 -0
  107. package/dist/components/data-entry/upload-types.d.ts +28 -0
  108. package/dist/components/data-entry/upload-types.js +2 -0
  109. package/dist/components/data-entry/upload.d.ts +2 -2
  110. package/dist/components/data-entry/upload.js +482 -117
  111. package/dist/components/feedback/dialog.d.ts +105 -38
  112. package/dist/components/feedback/dialog.js +268 -193
  113. package/dist/components/feedback/overlay-close-focus.d.ts +31 -0
  114. package/dist/components/feedback/overlay-close-focus.js +31 -0
  115. package/dist/components/feedback/overlay-header-tone.d.ts +1 -1
  116. package/dist/components/feedback/sheet.d.ts +53 -11
  117. package/dist/components/feedback/sheet.js +150 -81
  118. package/dist/components/feedback/tooltip.d.ts +51 -7
  119. package/dist/components/feedback/tooltip.js +107 -25
  120. package/dist/components/general/button.d.ts +1 -1
  121. package/dist/components/general/button.js +7 -3
  122. package/dist/components/general/index.d.ts +1 -0
  123. package/dist/components/general/index.js +2 -0
  124. package/dist/components/general/logo.d.ts +17 -0
  125. package/dist/components/general/logo.js +22 -16
  126. package/dist/components/general/typography.d.ts +3 -0
  127. package/dist/components/general/typography.js +15 -1
  128. package/dist/components/general/visually-hidden.d.ts +3 -0
  129. package/dist/components/general/visually-hidden.js +9 -0
  130. package/dist/components/layout/app-launcher.d.ts +34 -0
  131. package/dist/components/layout/app-launcher.js +228 -0
  132. package/dist/components/layout/app-shell.d.ts +3 -1
  133. package/dist/components/layout/app-shell.js +69 -12
  134. package/dist/components/layout/aspect-ratio.js +0 -1
  135. package/dist/components/layout/auth-divider.js +0 -1
  136. package/dist/components/layout/breadcrumb.d.ts +14 -2
  137. package/dist/components/layout/breadcrumb.js +46 -4
  138. package/dist/components/layout/flex.d.ts +1 -1
  139. package/dist/components/layout/flex.js +41 -3
  140. package/dist/components/layout/index.d.ts +3 -0
  141. package/dist/components/layout/index.js +5 -1
  142. package/dist/components/layout/nav-surface.d.ts +26 -0
  143. package/dist/components/layout/nav-surface.js +17 -0
  144. package/dist/components/layout/org-switcher.d.ts +5 -1
  145. package/dist/components/layout/org-switcher.js +25 -4
  146. package/dist/components/layout/page-container.d.ts +1 -1
  147. package/dist/components/layout/page-container.js +5 -3
  148. package/dist/components/layout/responsive-grid.d.ts +16 -2
  149. package/dist/components/layout/responsive-grid.js +29 -2
  150. package/dist/components/layout/separator.js +0 -1
  151. package/dist/components/layout/sidebar.js +4 -1
  152. package/dist/components/layout/split-pane.d.ts +14 -1
  153. package/dist/components/layout/split-pane.js +26 -13
  154. package/dist/components/layout/topbar-item.d.ts +3 -0
  155. package/dist/components/layout/topbar-item.js +19 -5
  156. package/dist/components/layout/topbar.d.ts +1 -1
  157. package/dist/components/layout/topbar.js +27 -6
  158. package/dist/components/navigation/app-setting-picker.js +21 -2
  159. package/dist/components/navigation/app-setting-toggle.d.ts +16 -0
  160. package/dist/components/navigation/app-setting-toggle.js +96 -0
  161. package/dist/components/navigation/dropdown-menu.d.ts +227 -18
  162. package/dist/components/navigation/dropdown-menu.js +402 -118
  163. package/dist/components/navigation/index.d.ts +2 -0
  164. package/dist/components/navigation/index.js +2 -0
  165. package/dist/components/navigation/pagination-utils.d.ts +2 -1
  166. package/dist/components/navigation/pagination.d.ts +2 -2
  167. package/dist/components/navigation/pagination.js +155 -83
  168. package/dist/components/navigation/steps.d.ts +2 -2
  169. package/dist/components/navigation/steps.js +29 -4
  170. package/dist/components/navigation/tabs.d.ts +29 -16
  171. package/dist/components/navigation/tabs.js +374 -144
  172. package/dist/components/ui/accordion.d.ts +50 -5
  173. package/dist/components/ui/accordion.js +239 -33
  174. package/dist/components/ui/aspect-ratio.d.ts +23 -2
  175. package/dist/components/ui/aspect-ratio.js +15 -13
  176. package/dist/components/ui/avatar.d.ts +29 -4
  177. package/dist/components/ui/avatar.js +111 -25
  178. package/dist/components/ui/hover-card.d.ts +42 -4
  179. package/dist/components/ui/hover-card.js +183 -27
  180. package/dist/components/ui/input-otp.d.ts +26 -28
  181. package/dist/components/ui/input-otp.js +50 -7
  182. package/dist/components/ui/label.js +0 -1
  183. package/dist/components/ui/password-input.d.ts +36 -2
  184. package/dist/components/ui/password-input.js +27 -7
  185. package/dist/components/ui/rating.d.ts +25 -0
  186. package/dist/components/ui/rating.js +67 -27
  187. package/dist/components/ui/segmented.d.ts +12 -3
  188. package/dist/components/ui/segmented.js +17 -2
  189. package/dist/components/ui/separator.d.ts +12 -2
  190. package/dist/components/ui/separator.js +30 -9
  191. package/dist/components/ui/tag-input.d.ts +45 -0
  192. package/dist/components/ui/tag-input.js +109 -27
  193. package/dist/components/ui/toggle-group.d.ts +50 -5
  194. package/dist/components/ui/toggle-group.js +79 -20
  195. package/dist/components/ui/toggle.d.ts +31 -5
  196. package/dist/components/ui/toggle.js +42 -3
  197. package/dist/form/form-context.d.ts +29 -0
  198. package/dist/form/form-context.js +44 -4
  199. package/dist/form/form-field-array.d.ts +22 -0
  200. package/dist/form/form-field-array.js +50 -0
  201. package/dist/form/form-field-control.d.ts +2 -1
  202. package/dist/form/form-field-control.js +116 -40
  203. package/dist/form/form-root.d.ts +2 -1
  204. package/dist/form/form-root.js +142 -23
  205. package/dist/form/index.d.ts +3 -1
  206. package/dist/form/index.js +12 -1
  207. package/dist/i18n/messages/en.json +64 -5
  208. package/dist/i18n/messages/ja.json +64 -5
  209. package/dist/i18n/messages/vi.json +64 -5
  210. package/dist/inertia/index.d.ts +20 -0
  211. package/dist/inertia/index.js +60 -1
  212. package/dist/lib/control-styles.d.ts +25 -3
  213. package/dist/lib/control-styles.js +9 -3
  214. package/dist/lib/datetime/picker-format.d.ts +8 -0
  215. package/dist/lib/datetime/picker-format.js +54 -0
  216. package/dist/lib/slot.d.ts +32 -0
  217. package/dist/lib/slot.js +22 -0
  218. package/dist/lib/variants.d.ts +22 -3
  219. package/dist/lib/variants.js +56 -1
  220. package/dist/props/components/app.prop.d.ts +25 -1
  221. package/dist/props/components/charts.prop.d.ts +21 -0
  222. package/dist/props/components/data-display.prop.d.ts +72 -4
  223. package/dist/props/components/data-entry.prop.d.ts +718 -46
  224. package/dist/props/components/form.prop.d.ts +142 -4
  225. package/dist/props/components/general.prop.d.ts +17 -1
  226. package/dist/props/components/index.d.ts +3 -3
  227. package/dist/props/components/layout.prop.d.ts +281 -11
  228. package/dist/props/components/navigation.prop.d.ts +114 -4
  229. package/dist/props/registry.d.ts +397 -11
  230. package/dist/props/registry.js +526 -11
  231. package/dist/props/vocabulary/content.prop.d.ts +1 -1
  232. package/dist/props/vocabulary/data.prop.d.ts +179 -1
  233. package/dist/props/vocabulary/index.d.ts +5 -5
  234. package/dist/props/vocabulary/interaction.prop.d.ts +68 -3
  235. package/dist/props/vocabulary/layout.prop.d.ts +57 -1
  236. package/dist/props/vocabulary/navigation.prop.d.ts +40 -0
  237. package/dist/props/vocabulary/shared.prop.d.ts +33 -0
  238. package/dist/styles/badge-layout.css +2 -1
  239. package/dist/styles/card-layout.css +26 -4
  240. package/dist/styles/chart-layout.css +15 -0
  241. package/dist/styles/control.css +657 -15
  242. package/dist/styles/core.css +5 -2
  243. package/dist/styles/data-display-layout.css +313 -6
  244. package/dist/styles/data-entry-layout.css +13 -0
  245. package/dist/styles/focus-ring.css +4 -0
  246. package/dist/styles/index.css +5 -2
  247. package/dist/styles/layout.css +327 -4
  248. package/dist/styles/navigation-layout.css +227 -0
  249. package/dist/styles/shell-layout.css +369 -13
  250. package/dist/styles/table-layout.css +95 -6
  251. package/dist/styles/text-layout.css +10 -4
  252. package/dist/tokens/base.css +2 -1
  253. package/dist/tokens/components/badge.css +1 -0
  254. package/dist/tokens/components/chart.css +6 -0
  255. package/dist/tokens/components/control.css +79 -2
  256. package/dist/tokens/components/data-display.css +20 -0
  257. package/dist/tokens/components/descriptions.css +11 -0
  258. package/dist/tokens/components/flex.css +8 -0
  259. package/dist/tokens/components/navigation.css +55 -0
  260. package/dist/tokens/components/shell.css +53 -3
  261. package/dist/tokens/components/table.css +14 -0
  262. package/dist/tokens/foundation.css +2 -0
  263. package/dist/tokens/semantic/layout.css +9 -0
  264. package/docs/COMPONENTS.md +9 -3
  265. package/docs/CONSUMER-RULES.md +13 -0
  266. package/docs/DESIGN-AUTHORITY.md +145 -83
  267. package/docs/DEVELOPMENT.md +4 -3
  268. package/docs/FORMS.md +151 -6
  269. package/docs/FRAME-COVERAGE-REPORT.md +32 -17
  270. package/docs/README.md +15 -15
  271. package/docs/STANDARDS-vocabulary-tokens.md +1 -1
  272. package/docs/TESTING.md +15 -6
  273. package/docs/WHAT-BELONGS-HERE.md +179 -0
  274. package/docs/charts/cjk-category-axis.tsx +81 -0
  275. package/docs/data-display/card/index.tsx +22 -0
  276. package/docs/data-display/data-table/examples/antd-parity.tsx +257 -0
  277. package/docs/data-display/data-table/index.tsx +23 -0
  278. package/docs/data-display/descriptions.tsx +41 -0
  279. package/docs/data-display/legend.tsx +145 -0
  280. package/docs/data-display/progress.tsx +32 -0
  281. package/docs/data-display/scroll-area.tsx +31 -25
  282. package/docs/data-display/table.tsx +104 -45
  283. package/docs/data-display/timeline.tsx +41 -0
  284. package/docs/data-entry/date-picker.tsx +85 -0
  285. package/docs/data-entry/date-range-picker.tsx +26 -0
  286. package/docs/data-entry/form-dynamic-fields.tsx +199 -0
  287. package/docs/data-entry/form.tsx +74 -4
  288. package/docs/data-entry/input-otp.tsx +24 -0
  289. package/docs/data-entry/input.tsx +46 -1
  290. package/docs/data-entry/month-range-picker.tsx +1 -1
  291. package/docs/data-entry/segmented.tsx +1 -1
  292. package/docs/data-entry/select.tsx +29 -2
  293. package/docs/data-entry/switch.tsx +41 -0
  294. package/docs/data-entry/textarea.tsx +38 -0
  295. package/docs/data-entry/time-picker.tsx +85 -1
  296. package/docs/data-entry/time-range-picker.tsx +55 -0
  297. package/docs/data-entry/transfer.tsx +17 -0
  298. package/docs/data-entry/upload.tsx +56 -12
  299. package/docs/feedback/sheet.tsx +1 -1
  300. package/docs/feedback/tooltip.tsx +1 -1
  301. package/docs/general/activity.tsx +2 -2
  302. package/docs/general/button/index.tsx +14 -1
  303. package/docs/general/typography.tsx +14 -1
  304. package/docs/layout/app-launcher.tsx +151 -0
  305. package/docs/layout/app-shell-arrangements.tsx +225 -0
  306. package/docs/layout/app-shell.tsx +11 -0
  307. package/docs/layout/aspect-ratio.tsx +1 -1
  308. package/docs/layout/flex.tsx +50 -0
  309. package/docs/layout/responsive-grid.tsx +21 -1
  310. package/docs/layout/topbar.tsx +5 -9
  311. package/docs/navigation/app-setting-picker.tsx +37 -1
  312. package/docs/navigation/app-setting-toggle.tsx +111 -0
  313. package/docs/navigation/breadcrumb.tsx +48 -0
  314. package/docs/navigation/dropdown-menu.tsx +21 -0
  315. package/docs/navigation/pagination.tsx +52 -0
  316. package/docs/navigation/steps.tsx +37 -0
  317. package/docs/navigation/tabs.tsx +97 -1
  318. package/docs/query/button-refetch.tsx +1 -0
  319. package/package.json +28 -8
  320. package/scripts/_agent-setup.mjs +182 -3
  321. package/scripts/consumer-rule.md +98 -0
  322. package/scripts/guinea-pig-skill.md +322 -0
  323. package/scripts/init-guinea-pig.mjs +84 -0
  324. package/scripts/postinstall.mjs +13 -2
  325. package/scripts/ui-audit.mjs +351 -37
  326. /package/dist/tokens/{antd.generated.css → derived.css} +0 -0
@@ -1,7 +1,16 @@
1
1
  "use client";
2
- import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  import * as React from "react";
4
- import { Camera, ImagePlus, RotateCcw, Trash2, Upload as UploadIcon, X } from "lucide-react";
4
+ import {
5
+ Camera,
6
+ Download,
7
+ Eye,
8
+ ImagePlus,
9
+ RotateCcw,
10
+ Trash2,
11
+ Upload as UploadIcon,
12
+ X
13
+ } from "lucide-react";
5
14
  import { useTranslation } from "../../i18n/use-translation.js";
6
15
  import { formatBytes } from "../../lib/format.js";
7
16
  import { cn } from "../../lib/utils.js";
@@ -10,11 +19,16 @@ import { controlIconClass } from "../../lib/control-styles.js";
10
19
  import { Button } from "../general/button.js";
11
20
  import { UploadCropDialog } from "./upload-crop-dialog.js";
12
21
  import {
22
+ UPLOAD_LIST_IGNORE,
13
23
  createUploadItem,
14
24
  revokePreviewUrl
15
25
  } from "./upload-types.js";
26
+ import { readDroppedFiles } from "./upload-files.js";
27
+ import { uploadRequest } from "./upload-request.js";
28
+ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "../feedback/dialog.js";
29
+ import { Progress } from "../data-display/progress.js";
16
30
  import { useUploadDraft } from "./use-upload-draft.js";
17
- import { collectUploadCommitActions, createUploadItem as createUploadItem2 } from "./upload-types.js";
31
+ import { collectUploadCommitActions, createUploadItem as createUploadItem2, UPLOAD_LIST_IGNORE as UPLOAD_LIST_IGNORE2 } from "./upload-types.js";
18
32
  import { useUploadDraft as useUploadDraft2 } from "./use-upload-draft.js";
19
33
  function defaultAcceptForVariant(variant) {
20
34
  if (variant === "avatar" || variant === "avatar-crop" || variant === "picture" || variant === "picture-card") {
@@ -29,9 +43,9 @@ function defaultMaxCount(variant) {
29
43
  function fileMatchesAccept(file, accept) {
30
44
  if (!accept) return true;
31
45
  return accept.split(",").some((rule) => {
32
- const trimmed = rule.trim();
33
- if (trimmed.endsWith("/*")) return file.type.startsWith(trimmed.slice(0, -1));
34
- return file.type === trimmed || file.name.endsWith(trimmed);
46
+ const trimmed = rule.trim().toLowerCase();
47
+ if (trimmed.endsWith("/*")) return file.type.toLowerCase().startsWith(trimmed.slice(0, -1));
48
+ return file.type.toLowerCase() === trimmed || trimmed.startsWith(".") && file.name.toLowerCase().endsWith(trimmed);
35
49
  });
36
50
  }
37
51
  function useUploadList(controlled, defaultValue, onValueChange) {
@@ -50,29 +64,6 @@ function useUploadList(controlled, defaultValue, onValueChange) {
50
64
  );
51
65
  return [items, setItems];
52
66
  }
53
- async function runUpload(file, item, onUpload, setItems) {
54
- const uid = item.uid;
55
- setItems((prev) => prev.map((it) => it.uid === uid ? { ...it, status: "uploading" } : it));
56
- try {
57
- const result = await onUpload(file, item);
58
- setItems(
59
- (prev) => prev.map(
60
- (it) => it.uid === uid ? {
61
- ...it,
62
- status: "done",
63
- mediaId: result.mediaId,
64
- previewUrl: result.previewUrl ?? it.previewUrl,
65
- file: void 0
66
- } : it
67
- )
68
- );
69
- } catch (err) {
70
- const message = err instanceof Error ? err.message : String(err);
71
- setItems(
72
- (prev) => prev.map((it) => it.uid === uid ? { ...it, status: "error", error: message } : it)
73
- );
74
- }
75
- }
76
67
  function Upload({
77
68
  variant = "dropzone",
78
69
  triggerSize,
@@ -84,7 +75,26 @@ function Upload({
84
75
  multiple: multipleProp,
85
76
  maxCount: maxCountProp,
86
77
  maxSizeBytes,
87
- disabled,
78
+ disabled: disabledProp,
79
+ readOnly = false,
80
+ directory = false,
81
+ pastable = false,
82
+ openFileDialogOnClick = true,
83
+ name,
84
+ action,
85
+ method,
86
+ headers,
87
+ data,
88
+ withCredentials,
89
+ beforeUpload,
90
+ onReject,
91
+ onRemove,
92
+ onPreview,
93
+ onDownload,
94
+ previewFile,
95
+ onDrop,
96
+ showUploadList = true,
97
+ itemRender,
88
98
  removable = true,
89
99
  onUpload,
90
100
  id,
@@ -93,13 +103,19 @@ function Upload({
93
103
  ...ariaProps
94
104
  }) {
95
105
  const { t } = useTranslation();
96
- const inputA11y = resolveFieldA11y(ariaProps, t("dataEntry.upload.inputLabel"));
106
+ const disabled = disabledProp || readOnly;
107
+ const triggerOwnsAriaLabel = variant === "button";
108
+ const inputA11y = resolveFieldA11y(
109
+ triggerOwnsAriaLabel ? { ...ariaProps, "aria-label": void 0 } : ariaProps,
110
+ t("dataEntry.upload.inputLabel")
111
+ );
97
112
  const accept = acceptProp ?? defaultAcceptForVariant(variant);
98
113
  const maxCount = maxCountProp ?? defaultMaxCount(variant);
99
114
  const multiple = multipleProp ?? (maxCount === 1 ? false : true);
100
115
  const inputRef = React.useRef(null);
101
116
  const [dragActive, setDragActive] = React.useState(false);
102
117
  const [cropFile, setCropFile] = React.useState(null);
118
+ const [previewItem, setPreviewItem] = React.useState(null);
103
119
  const [items, setItems] = useUploadList(value, defaultValue, onValueChange);
104
120
  const isSingleAvatar = variant === "avatar" || variant === "avatar-crop" || variant === "picture" && maxCount === 1;
105
121
  const singleItem = isSingleAvatar ? items[0] ?? null : null;
@@ -109,49 +125,271 @@ function Upload({
109
125
  setItems(next ? [next] : []);
110
126
  }
111
127
  });
112
- const pickFiles = (fileList) => {
113
- if (!fileList?.length || disabled) return;
114
- const slotsLeft = maxCount != null ? Math.max(0, maxCount - items.length) : fileList.length;
115
- const candidates = Array.from(fileList).slice(0, multiple ? slotsLeft || fileList.length : 1);
116
- for (const file of candidates) {
117
- if (!fileMatchesAccept(file, accept)) continue;
118
- if (maxSizeBytes != null && file.size > maxSizeBytes) continue;
119
- if (variant === "avatar-crop") {
120
- setCropFile(file);
121
- return;
128
+ const cropAutomatic = React.useRef(true);
129
+ const requests = React.useRef(/* @__PURE__ */ new Map());
130
+ const mounted = React.useRef(true);
131
+ const queue = React.useRef(Promise.resolve());
132
+ const selectionGeneration = React.useRef(0);
133
+ const initialItems = React.useRef(value ?? defaultValue ?? []);
134
+ const current = React.useRef({ items, disabled });
135
+ current.current = { items, disabled };
136
+ const ownedUrls = React.useRef(/* @__PURE__ */ new Set());
137
+ const [rejection, setRejection] = React.useState();
138
+ React.useEffect(() => {
139
+ mounted.current = true;
140
+ const active = requests.current;
141
+ const urls = ownedUrls.current;
142
+ return () => {
143
+ mounted.current = false;
144
+ active.forEach((controller) => controller.abort());
145
+ active.clear();
146
+ urls.forEach((url) => URL.revokeObjectURL(url));
147
+ };
148
+ }, []);
149
+ React.useEffect(() => {
150
+ for (const [uid, controller] of requests.current) {
151
+ if (!items.some((item2) => item2.uid === uid && !item2.pendingDelete)) {
152
+ controller.abort();
153
+ requests.current.delete(uid);
122
154
  }
123
- if (isSingleAvatar) {
124
- const baseline = items[0];
125
- const item3 = createUploadItem(file, {
155
+ }
156
+ }, [items]);
157
+ const updateItems = (update) => {
158
+ if (!mounted.current) return;
159
+ setItems((previous) => {
160
+ const next = update(previous);
161
+ current.current.items = next;
162
+ return next;
163
+ });
164
+ };
165
+ const startUpload = async (item2) => {
166
+ if (!item2.file || !onUpload && !action || current.current.disabled) return;
167
+ const controller = new AbortController();
168
+ requests.current.get(item2.uid)?.abort();
169
+ requests.current.set(item2.uid, controller);
170
+ const isCurrent = () => mounted.current && !controller.signal.aborted && requests.current.get(item2.uid) === controller;
171
+ updateItems(
172
+ (previous) => previous.map(
173
+ (entry) => entry.uid === item2.uid ? { ...entry, status: "uploading", percent: 0, error: void 0 } : entry
174
+ )
175
+ );
176
+ try {
177
+ const context = {
178
+ signal: controller.signal,
179
+ onProgress: (percent) => {
180
+ if (!isCurrent() || !Number.isFinite(percent)) return;
181
+ updateItems(
182
+ (previous) => previous.map(
183
+ (entry) => entry.uid === item2.uid ? { ...entry, percent: Math.max(0, Math.min(100, percent)) } : entry
184
+ )
185
+ );
186
+ }
187
+ };
188
+ const result = onUpload ? await onUpload(item2.file, item2, context) : await uploadRequest(
189
+ item2.file,
190
+ { action, method, headers, data, name, withCredentials },
191
+ context
192
+ );
193
+ if (!isCurrent()) return;
194
+ updateItems(
195
+ (previous) => previous.map(
196
+ (entry) => entry.uid === item2.uid ? {
197
+ ...entry,
198
+ ...result,
199
+ previewUrl: result.previewUrl ?? entry.previewUrl,
200
+ status: "done",
201
+ percent: 100,
202
+ file: void 0
203
+ } : entry
204
+ )
205
+ );
206
+ } catch (error) {
207
+ if (!isCurrent()) return;
208
+ updateItems(
209
+ (previous) => previous.map(
210
+ (entry) => entry.uid === item2.uid ? {
211
+ ...entry,
212
+ status: "error",
213
+ error: error instanceof Error ? error.message : String(error)
214
+ } : entry
215
+ )
216
+ );
217
+ } finally {
218
+ if (requests.current.get(item2.uid) === controller) requests.current.delete(item2.uid);
219
+ }
220
+ };
221
+ const cancelUpload = (uid) => {
222
+ requests.current.get(uid)?.abort();
223
+ requests.current.delete(uid);
224
+ updateItems(
225
+ (previous) => previous.map(
226
+ (item2) => item2.uid === uid ? { ...item2, status: "idle", percent: void 0 } : item2
227
+ )
228
+ );
229
+ };
230
+ const rejectFile = (file, reason, error) => {
231
+ setRejection(
232
+ t(
233
+ `dataEntry.upload.reject${reason[0].toUpperCase()}${reason.slice(1)}`,
234
+ { name: file.name }
235
+ )
236
+ );
237
+ onReject?.({ file, reason, error });
238
+ };
239
+ const pickFiles = (fileList) => {
240
+ if (!fileList?.length || current.current.disabled) return;
241
+ const files = Array.from(fileList);
242
+ const generation = selectionGeneration.current;
243
+ queue.current = queue.current.then(async () => {
244
+ setRejection(void 0);
245
+ for (const original of multiple ? files : files.slice(0, 1)) {
246
+ if (!mounted.current || current.current.disabled || generation !== selectionGeneration.current)
247
+ return;
248
+ if (!fileMatchesAccept(original, accept)) {
249
+ rejectFile(original, "accept");
250
+ continue;
251
+ }
252
+ if (maxSizeBytes != null && original.size > maxSizeBytes) {
253
+ rejectFile(original, "size");
254
+ continue;
255
+ }
256
+ let file = original;
257
+ let automatic = true;
258
+ try {
259
+ const decision = await beforeUpload?.(file, files);
260
+ if (decision === UPLOAD_LIST_IGNORE) continue;
261
+ if (decision === false) automatic = false;
262
+ if (decision instanceof Blob)
263
+ file = decision instanceof File ? decision : new File([decision], original.name, {
264
+ type: decision.type,
265
+ lastModified: original.lastModified
266
+ });
267
+ } catch (error) {
268
+ rejectFile(original, "beforeUpload", error);
269
+ continue;
270
+ }
271
+ if (!mounted.current || current.current.disabled || generation !== selectionGeneration.current)
272
+ return;
273
+ if (maxSizeBytes != null && file.size > maxSizeBytes) {
274
+ rejectFile(file, "size");
275
+ continue;
276
+ }
277
+ if (maxCount !== 1 && maxCount != null && current.current.items.length >= maxCount) {
278
+ rejectFile(file, "count");
279
+ continue;
280
+ }
281
+ if (variant === "avatar-crop") {
282
+ cropAutomatic.current = automatic;
283
+ setCropFile(file);
284
+ return;
285
+ }
286
+ const baseline = isSingleAvatar ? current.current.items[0] : void 0;
287
+ const item2 = createUploadItem(file, {
288
+ relativePath: original.webkitRelativePath || void 0,
126
289
  pendingReplace: Boolean(baseline?.mediaId),
127
290
  replacesMediaId: baseline?.mediaId
128
291
  });
129
- setItems([item3]);
130
- if (onUpload) void runUpload(file, item3, onUpload, setItems);
131
- return;
292
+ if (item2.previewUrl?.startsWith("blob:")) ownedUrls.current.add(item2.previewUrl);
293
+ updateItems((previous) => maxCount === 1 ? [item2] : [...previous, item2]);
294
+ if (previewFile)
295
+ void previewFile(file).then((url) => {
296
+ updateItems(
297
+ (previous) => previous.map(
298
+ (entry) => entry.uid === item2.uid ? { ...entry, previewUrl: url } : entry
299
+ )
300
+ );
301
+ }).catch(() => {
302
+ });
303
+ if (automatic) void startUpload(item2);
132
304
  }
133
- const item2 = createUploadItem(file);
134
- setItems((prev) => [...prev, item2]);
135
- if (onUpload) void runUpload(file, item2, onUpload, setItems);
136
- }
305
+ }).catch(() => {
306
+ });
137
307
  };
138
- const removeItem = (uid) => {
308
+ const removeItem = async (uid) => {
309
+ if (current.current.disabled) return;
310
+ const target = current.current.items.find((item2) => item2.uid === uid);
311
+ if (!target) return;
312
+ try {
313
+ if (await onRemove?.(target) === false) return;
314
+ } catch {
315
+ return;
316
+ }
317
+ if (!mounted.current || current.current.disabled || !current.current.items.some((item2) => item2.uid === uid))
318
+ return;
319
+ requests.current.get(uid)?.abort();
320
+ requests.current.delete(uid);
139
321
  if (isSingleAvatar) {
140
322
  draft.markRemove();
141
323
  return;
142
324
  }
143
- setItems((prev) => {
144
- const target = prev.find((it) => it.uid === uid);
145
- revokePreviewUrl(target);
146
- return prev.filter((it) => it.uid !== uid);
147
- });
325
+ revokePreviewUrl(target);
326
+ updateItems((previous) => previous.filter((item2) => item2.uid !== uid));
327
+ };
328
+ React.useEffect(() => {
329
+ const form = inputRef.current?.form;
330
+ if (!form || !name) return;
331
+ const appendFiles = (event) => {
332
+ if (disabledProp) return;
333
+ for (const item2 of current.current.items) {
334
+ if (item2.file && !item2.pendingDelete) event.formData.append(name, item2.file, item2.name);
335
+ }
336
+ };
337
+ form.addEventListener("formdata", appendFiles);
338
+ return () => form.removeEventListener("formdata", appendFiles);
339
+ }, [name, disabledProp]);
340
+ React.useEffect(() => {
341
+ const form = inputRef.current?.form;
342
+ if (!form) return;
343
+ const reset = (event) => {
344
+ queueMicrotask(() => {
345
+ if (!mounted.current || event.defaultPrevented) return;
346
+ selectionGeneration.current += 1;
347
+ queue.current = Promise.resolve();
348
+ requests.current.forEach((controller) => controller.abort());
349
+ requests.current.clear();
350
+ setCropFile(null);
351
+ setRejection(void 0);
352
+ if (value === void 0) updateItems(() => initialItems.current);
353
+ });
354
+ };
355
+ form.addEventListener("reset", reset);
356
+ return () => form.removeEventListener("reset", reset);
357
+ });
358
+ React.useEffect(() => {
359
+ if (name) inputRef.current?.dispatchEvent(new Event("input", { bubbles: true }));
360
+ }, [items, name]);
361
+ const pasteProps = {
362
+ onPaste: (event) => {
363
+ if (!pastable || disabled || !event.clipboardData.files.length) return;
364
+ event.preventDefault();
365
+ pickFiles(event.clipboardData.files);
366
+ }
367
+ };
368
+ const showPreview = (item2) => {
369
+ if (onPreview) onPreview(item2);
370
+ else if (item2.previewUrl) setPreviewItem(item2);
148
371
  };
372
+ const list = showUploadList && items.length > 0 ? /* @__PURE__ */ jsx(
373
+ UploadFileList,
374
+ {
375
+ items,
376
+ onRemove: removable && !disabled ? removeItem : void 0,
377
+ onStart: !disabled && (onUpload || action) ? startUpload : void 0,
378
+ onCancel: !disabled ? cancelUpload : void 0,
379
+ onPreview: showPreview,
380
+ hasCustomPreview: Boolean(onPreview),
381
+ onDownload,
382
+ itemRender,
383
+ showThumbnails: variant === "picture"
384
+ }
385
+ ) : null;
149
386
  const hiddenInput = /* @__PURE__ */ jsx(
150
387
  "input",
151
388
  {
152
389
  ref: inputRef,
153
390
  id,
154
391
  type: "file",
392
+ ...directory ? { webkitdirectory: "", directory: "" } : {},
155
393
  className: "sr-only",
156
394
  accept,
157
395
  multiple: multiple && !isSingleAvatar,
@@ -166,18 +404,41 @@ function Upload({
166
404
  const uploadingCount = items.filter((it) => it.status === "uploading").length;
167
405
  const doneCount = items.filter((it) => it.status === "done").length;
168
406
  const errorCount = items.filter((it) => it.status === "error").length;
169
- const liveRegion = /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", "data-slot": "upload-status", children: errorCount > 0 ? t("dataEntry.upload.statusFailed", { count: errorCount }) : uploadingCount > 0 ? t("dataEntry.upload.statusUploading", { count: uploadingCount }) : items.length > 0 ? t("dataEntry.upload.statusReady", { count: items.length, done: doneCount }) : "" });
407
+ const liveRegion = /* @__PURE__ */ jsxs(Fragment, { children: [
408
+ /* @__PURE__ */ jsx(
409
+ Dialog,
410
+ {
411
+ open: previewItem != null,
412
+ onOpenChange: (open) => {
413
+ if (!open) setPreviewItem(null);
414
+ },
415
+ children: /* @__PURE__ */ jsxs(DialogContent, { "aria-describedby": void 0, children: [
416
+ /* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: previewItem?.name ?? t("dataEntry.upload.preview") }) }),
417
+ previewItem?.previewUrl && /* @__PURE__ */ jsx(
418
+ "img",
419
+ {
420
+ src: previewItem.previewUrl,
421
+ alt: previewItem.name,
422
+ className: "ui-upload-picture-img"
423
+ }
424
+ )
425
+ ] })
426
+ }
427
+ ),
428
+ /* @__PURE__ */ jsx("span", { "aria-live": "polite", className: "sr-only", "data-slot": "upload-status", children: rejection ?? (errorCount > 0 ? t("dataEntry.upload.statusFailed", { count: errorCount }) : uploadingCount > 0 ? t("dataEntry.upload.statusUploading", { count: uploadingCount }) : items.length > 0 ? t("dataEntry.upload.statusReady", { count: items.length, done: doneCount }) : "") })
429
+ ] });
170
430
  const openPicker = () => {
171
- if (!disabled) inputRef.current?.click();
431
+ if (!disabled && openFileDialogOnClick) inputRef.current?.click();
172
432
  };
173
433
  if (variant === "dropzone") {
174
- return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm", className), children: [
434
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-stack-sm", className), children: [
175
435
  hiddenInput,
176
436
  liveRegion,
437
+ rejection && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: rejection }),
177
438
  /* @__PURE__ */ jsxs(
178
439
  "div",
179
440
  {
180
- role: "button",
441
+ role: openFileDialogOnClick ? "button" : "group",
181
442
  tabIndex: disabled ? -1 : 0,
182
443
  "aria-disabled": disabled,
183
444
  "aria-label": t("dataEntry.upload.dropzoneLabel"),
@@ -190,13 +451,17 @@ function Upload({
190
451
  },
191
452
  onDragOver: (e) => {
192
453
  e.preventDefault();
193
- setDragActive(true);
454
+ if (!disabled) setDragActive(true);
194
455
  },
195
456
  onDragLeave: () => setDragActive(false),
196
457
  onDrop: (e) => {
197
458
  e.preventDefault();
198
459
  setDragActive(false);
199
- pickFiles(e.dataTransfer.files);
460
+ onDrop?.(e);
461
+ if (disabled) return;
462
+ void readDroppedFiles(e.dataTransfer, directory).then(pickFiles).catch(() => {
463
+ if (mounted.current) setRejection(t("dataEntry.upload.readFailed"));
464
+ });
200
465
  },
201
466
  "data-drag-active": dragActive ? "" : void 0,
202
467
  "data-disabled": disabled ? "" : void 0,
@@ -208,15 +473,17 @@ function Upload({
208
473
  ]
209
474
  }
210
475
  ),
211
- items.length > 0 && /* @__PURE__ */ jsx(UploadFileList, { items, onRemove: removable ? removeItem : void 0 })
476
+ list
212
477
  ] });
213
478
  }
214
479
  if (variant === "button") {
215
480
  const iconOnly = typeof triggerSize === "string" && triggerSize.startsWith("icon");
216
481
  const label = children ?? t("dataEntry.upload.buttonLabel");
217
- return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm", className), children: [
482
+ const triggerAriaLabel = ariaProps["aria-label"] ?? (iconOnly ? typeof label === "string" ? label : t("dataEntry.upload.buttonLabel") : void 0);
483
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-stack-sm", className), children: [
218
484
  hiddenInput,
219
485
  liveRegion,
486
+ rejection && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: rejection }),
220
487
  /* @__PURE__ */ jsxs(
221
488
  Button,
222
489
  {
@@ -225,7 +492,7 @@ function Upload({
225
492
  size: triggerSize,
226
493
  disabled,
227
494
  onClick: openPicker,
228
- "aria-label": iconOnly ? typeof label === "string" ? label : void 0 : void 0,
495
+ "aria-label": triggerAriaLabel,
229
496
  children: [
230
497
  /* @__PURE__ */ jsx(
231
498
  UploadIcon,
@@ -239,19 +506,24 @@ function Upload({
239
506
  ]
240
507
  }
241
508
  ),
242
- items.length > 0 && /* @__PURE__ */ jsx(UploadFileList, { items, onRemove: removable ? removeItem : void 0 })
509
+ list
243
510
  ] });
244
511
  }
245
512
  if (variant === "picture-card") {
246
513
  const canAdd = maxCount == null || items.length < maxCount;
247
- return /* @__PURE__ */ jsxs("div", { className: cn("ui-upload-grid", className), children: [
514
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-upload-grid", className), children: [
248
515
  hiddenInput,
249
516
  liveRegion,
250
- items.map((item2) => /* @__PURE__ */ jsx(
517
+ rejection && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: rejection }),
518
+ (showUploadList ? items : []).map((item2) => /* @__PURE__ */ jsx(
251
519
  UploadPictureCard,
252
520
  {
253
521
  item: item2,
254
- onRemove: removable ? () => removeItem(item2.uid) : void 0
522
+ onStart: !disabled && (onUpload || action) ? () => void startUpload(item2) : void 0,
523
+ onCancel: !disabled ? () => cancelUpload(item2.uid) : void 0,
524
+ onPreview: onPreview || item2.previewUrl ? () => showPreview(item2) : void 0,
525
+ onDownload: onDownload ? () => onDownload(item2) : void 0,
526
+ onRemove: removable && !disabled ? () => void removeItem(item2.uid) : void 0
255
527
  },
256
528
  item2.uid
257
529
  )),
@@ -272,11 +544,21 @@ function Upload({
272
544
  )
273
545
  ] });
274
546
  }
547
+ if (variant === "picture" && !isSingleAvatar) {
548
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-stack-sm", className), children: [
549
+ hiddenInput,
550
+ liveRegion,
551
+ rejection && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: rejection }),
552
+ /* @__PURE__ */ jsx(Button, { type: "button", disabled, variant: triggerVariant, onClick: openPicker, children: children ?? t("dataEntry.upload.addImage") }),
553
+ list
554
+ ] });
555
+ }
275
556
  if (variant === "picture") {
276
557
  const item2 = draft.state.display;
277
- return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm ui-upload-picture", className), children: [
558
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-stack-sm ui-upload-picture", className), children: [
278
559
  hiddenInput,
279
560
  liveRegion,
561
+ rejection && /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive", children: rejection }),
280
562
  item2?.previewUrl && !item2.pendingDelete ? /* @__PURE__ */ jsxs("div", { className: "ui-upload-picture-frame", children: [
281
563
  /* @__PURE__ */ jsx("img", { src: item2.previewUrl, alt: "", className: "ui-upload-picture-img" }),
282
564
  item2.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "ui-upload-overlay ui-upload-picture-overlay", children: t("dataEntry.upload.uploading") }),
@@ -299,7 +581,7 @@ function Upload({
299
581
  }
300
582
  const item = draft.state.display;
301
583
  const showPlaceholder = !item?.previewUrl || item.pendingDelete;
302
- return /* @__PURE__ */ jsxs("div", { className: cn("ui-stack-sm items-start", className), children: [
584
+ return /* @__PURE__ */ jsxs("div", { ...pasteProps, className: cn("ui-stack-sm items-start", className), children: [
303
585
  hiddenInput,
304
586
  liveRegion,
305
587
  /* @__PURE__ */ jsx(
@@ -309,6 +591,12 @@ function Upload({
309
591
  onOpenChange: (open) => !open && setCropFile(null),
310
592
  file: cropFile,
311
593
  onConfirm: (cropped) => {
594
+ if (!mounted.current || current.current.disabled) return;
595
+ if (maxSizeBytes != null && cropped.size > maxSizeBytes) {
596
+ rejectFile(cropped, "size");
597
+ setCropFile(null);
598
+ return;
599
+ }
312
600
  const baseline = items[0];
313
601
  const item2 = createUploadItem(cropped, {
314
602
  pendingReplace: Boolean(baseline?.mediaId),
@@ -316,7 +604,8 @@ function Upload({
316
604
  });
317
605
  setItems([item2]);
318
606
  setCropFile(null);
319
- if (onUpload) void runUpload(cropped, item2, onUpload, setItems);
607
+ if (item2.previewUrl?.startsWith("blob:")) ownedUrls.current.add(item2.previewUrl);
608
+ if (cropAutomatic.current) void startUpload(item2);
320
609
  }
321
610
  }
322
611
  ),
@@ -342,7 +631,7 @@ function Upload({
342
631
  {
343
632
  type: "button",
344
633
  disabled,
345
- onClick: () => draft.markRemove(),
634
+ onClick: () => void removeItem(item.uid),
346
635
  className: "ui-upload-avatar-remove",
347
636
  "aria-label": t("dataEntry.upload.removeAvatar"),
348
637
  children: /* @__PURE__ */ jsx(Trash2, { className: "ui-upload-remove-icon", "aria-hidden": "true" })
@@ -377,59 +666,135 @@ function UploadDraftActions({
377
666
  }
378
667
  return null;
379
668
  }
380
- function UploadPictureCard({ item, onRemove }) {
669
+ function UploadPictureCard({
670
+ item,
671
+ onRemove,
672
+ onStart,
673
+ onCancel,
674
+ onPreview,
675
+ onDownload
676
+ }) {
381
677
  const { t } = useTranslation();
382
- return /* @__PURE__ */ jsxs("div", { className: "ui-upload-tile", children: [
383
- item.previewUrl ? /* @__PURE__ */ jsx("img", { src: item.previewUrl, alt: "", className: "ui-upload-avatar-image" }) : /* @__PURE__ */ jsx("div", { className: "ui-upload-tile-placeholder", children: "\u2026" }),
384
- item.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "ui-upload-overlay", children: "\u2026" }),
385
- onRemove && /* @__PURE__ */ jsx(
386
- "button",
387
- {
388
- type: "button",
389
- onClick: onRemove,
390
- className: "ui-upload-tile-remove",
391
- "aria-label": t("dataEntry.upload.removeImage"),
392
- children: /* @__PURE__ */ jsx(X, { className: "ui-upload-remove-icon", "aria-hidden": "true" })
393
- }
394
- )
678
+ return /* @__PURE__ */ jsxs("div", { className: "ui-upload-picture-item ui-stack-xs", children: [
679
+ /* @__PURE__ */ jsxs("div", { className: "ui-upload-tile", children: [
680
+ item.previewUrl ? /* @__PURE__ */ jsx("img", { src: item.previewUrl, alt: "", className: "ui-upload-avatar-image" }) : /* @__PURE__ */ jsx("div", { className: "ui-upload-tile-placeholder", children: /* @__PURE__ */ jsx(ImagePlus, { "aria-hidden": "true" }) }),
681
+ item.status === "uploading" && /* @__PURE__ */ jsx("div", { className: "ui-upload-overlay", children: /* @__PURE__ */ jsx(Progress, { value: item.percent ?? 0, "aria-label": t("dataEntry.upload.uploading") }) }),
682
+ onRemove && /* @__PURE__ */ jsx(
683
+ "button",
684
+ {
685
+ type: "button",
686
+ onClick: onRemove,
687
+ className: "ui-upload-tile-remove",
688
+ "aria-label": t("dataEntry.upload.removeImage"),
689
+ children: /* @__PURE__ */ jsx(X, { className: "ui-upload-remove-icon", "aria-hidden": "true" })
690
+ }
691
+ )
692
+ ] }),
693
+ item.status === "error" && /* @__PURE__ */ jsx("span", { role: "alert", className: "text-destructive", children: item.error }),
694
+ /* @__PURE__ */ jsxs("div", { className: "ui-inline-xs", children: [
695
+ onCancel && item.status === "uploading" && /* @__PURE__ */ jsx(
696
+ Button,
697
+ {
698
+ type: "button",
699
+ size: "icon-xs",
700
+ variant: "ghost",
701
+ onClick: onCancel,
702
+ "aria-label": t("dataEntry.upload.cancel"),
703
+ children: /* @__PURE__ */ jsx(X, { "aria-hidden": "true" })
704
+ }
705
+ ),
706
+ onStart && item.file && (item.status === "idle" || item.status === "error") && /* @__PURE__ */ jsx(
707
+ Button,
708
+ {
709
+ type: "button",
710
+ size: "icon-xs",
711
+ variant: "ghost",
712
+ onClick: onStart,
713
+ "aria-label": t(
714
+ item.status === "error" ? "dataEntry.upload.retry" : "dataEntry.upload.start"
715
+ ),
716
+ children: /* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": "true" })
717
+ }
718
+ ),
719
+ onPreview && /* @__PURE__ */ jsx(
720
+ Button,
721
+ {
722
+ type: "button",
723
+ size: "icon-xs",
724
+ variant: "ghost",
725
+ onClick: onPreview,
726
+ "aria-label": t("dataEntry.upload.preview"),
727
+ children: /* @__PURE__ */ jsx(Eye, { "aria-hidden": "true" })
728
+ }
729
+ ),
730
+ onDownload && /* @__PURE__ */ jsx(
731
+ Button,
732
+ {
733
+ type: "button",
734
+ size: "icon-xs",
735
+ variant: "ghost",
736
+ onClick: onDownload,
737
+ "aria-label": t("dataEntry.upload.download"),
738
+ children: /* @__PURE__ */ jsx(Download, { "aria-hidden": "true" })
739
+ }
740
+ )
741
+ ] })
395
742
  ] });
396
743
  }
397
744
  function UploadFileList({
398
745
  items,
399
- onRemove
746
+ onRemove,
747
+ onStart,
748
+ onCancel,
749
+ onPreview,
750
+ hasCustomPreview,
751
+ onDownload,
752
+ itemRender,
753
+ showThumbnails
400
754
  }) {
401
755
  const { t } = useTranslation();
402
- return /* @__PURE__ */ jsx("ul", { className: "ui-stack-xs", children: items.map((item) => /* @__PURE__ */ jsxs("li", { className: "ui-upload-row", children: [
403
- /* @__PURE__ */ jsxs("div", { className: "ui-upload-row-main", children: [
404
- /* @__PURE__ */ jsx("div", { className: "truncate font-medium", children: item.name }),
405
- /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground text-xs", children: [
406
- formatBytes(item.size),
407
- item.status === "uploading" && " \xB7 \u2026",
408
- item.status === "error" && item.error && /* @__PURE__ */ jsxs("span", { className: "text-destructive", children: [
409
- " \xB7 ",
410
- item.error
756
+ return /* @__PURE__ */ jsx("ul", { className: "ui-stack-xs", children: items.map((item) => {
757
+ const node = /* @__PURE__ */ jsxs("div", { className: "ui-upload-row", children: [
758
+ showThumbnails && item.previewUrl && /* @__PURE__ */ jsx("img", { src: item.previewUrl, alt: "", className: "ui-upload-list-thumb" }),
759
+ /* @__PURE__ */ jsxs("div", { className: "ui-upload-row-main", children: [
760
+ /* @__PURE__ */ jsx("div", { className: "truncate font-medium", children: item.name }),
761
+ /* @__PURE__ */ jsxs("div", { className: "text-muted-foreground text-xs", children: [
762
+ formatBytes(item.size),
763
+ item.status === "error" && item.error && /* @__PURE__ */ jsxs("span", { role: "alert", className: "text-destructive", children: [
764
+ " ",
765
+ "\xB7 ",
766
+ item.error
767
+ ] })
411
768
  ] }),
412
- item.mediaId && /* @__PURE__ */ jsxs("span", { className: "text-muted-foreground", children: [
413
- " \xB7 ",
414
- item.mediaId.slice(0, 8),
415
- "\u2026"
416
- ] })
417
- ] })
418
- ] }),
419
- onRemove && /* @__PURE__ */ jsx(
420
- Button,
421
- {
422
- type: "button",
423
- size: "sm",
424
- variant: "ghost",
425
- "aria-label": t("dataEntry.upload.removeFile", { name: item.name }),
426
- onClick: () => onRemove(item.uid),
427
- children: /* @__PURE__ */ jsx(X, { className: "ui-upload-row-icon", "aria-hidden": "true" })
428
- }
429
- )
430
- ] }, item.uid)) });
769
+ item.status === "uploading" && /* @__PURE__ */ jsx(Progress, { value: item.percent ?? 0, "aria-label": t("dataEntry.upload.uploading") })
770
+ ] }),
771
+ onPreview && (hasCustomPreview || item.previewUrl) && /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => onPreview(item), children: t("dataEntry.upload.preview") }),
772
+ onDownload && /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => onDownload(item), children: t("dataEntry.upload.download") }),
773
+ onStart && item.file && item.status !== "uploading" && item.status !== "done" && /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => onStart(item), children: t(item.status === "error" ? "dataEntry.upload.retry" : "dataEntry.upload.start") }),
774
+ onCancel && item.status === "uploading" && /* @__PURE__ */ jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => onCancel(item.uid), children: t("dataEntry.upload.cancel") }),
775
+ onRemove && /* @__PURE__ */ jsx(
776
+ Button,
777
+ {
778
+ type: "button",
779
+ size: "sm",
780
+ variant: "ghost",
781
+ "aria-label": t("dataEntry.upload.removeFile", { name: item.name }),
782
+ onClick: () => onRemove(item.uid),
783
+ children: /* @__PURE__ */ jsx(X, { className: "ui-upload-row-icon", "aria-hidden": "true" })
784
+ }
785
+ )
786
+ ] });
787
+ return /* @__PURE__ */ jsx("li", { children: itemRender ? itemRender(node, item, items, {
788
+ remove: () => onRemove?.(item.uid),
789
+ preview: () => onPreview?.(item),
790
+ download: () => onDownload?.(item),
791
+ upload: () => onStart?.(item),
792
+ cancel: () => onCancel?.(item.uid)
793
+ }) : node }, item.uid);
794
+ }) });
431
795
  }
432
796
  export {
797
+ UPLOAD_LIST_IGNORE2 as UPLOAD_LIST_IGNORE,
433
798
  Upload,
434
799
  collectUploadCommitActions,
435
800
  createUploadItem2 as createUploadItem,