@bayonai/mui-design 1.9.0 → 1.10.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 (296) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +18 -0
  3. package/package.json +1 -1
  4. package/dist/cjs/actions/ActionMenu.d.ts +0 -24
  5. package/dist/cjs/actions/ActionMenu.js +0 -36
  6. package/dist/cjs/actions/DialogActionButtons.d.ts +0 -23
  7. package/dist/cjs/actions/DialogActionButtons.js +0 -33
  8. package/dist/cjs/actions/LoadingIconButton.d.ts +0 -11
  9. package/dist/cjs/actions/LoadingIconButton.js +0 -10
  10. package/dist/cjs/actions/StickyActionFooter.d.ts +0 -14
  11. package/dist/cjs/actions/StickyActionFooter.js +0 -27
  12. package/dist/cjs/actions/StickySubmitButton.d.ts +0 -10
  13. package/dist/cjs/actions/StickySubmitButton.js +0 -10
  14. package/dist/cjs/actions/index.d.ts +0 -5
  15. package/dist/cjs/actions/index.js +0 -18
  16. package/dist/cjs/client.d.ts +0 -4
  17. package/dist/cjs/client.js +0 -21
  18. package/dist/cjs/components/BayonFlowVisual.d.ts +0 -12
  19. package/dist/cjs/components/BayonFlowVisual.js +0 -87
  20. package/dist/cjs/components/BayonThemeModeToggle.d.ts +0 -6
  21. package/dist/cjs/components/BayonThemeModeToggle.js +0 -34
  22. package/dist/cjs/components/IconTooltipButton.d.ts +0 -10
  23. package/dist/cjs/components/IconTooltipButton.js +0 -50
  24. package/dist/cjs/components/panels.d.ts +0 -37
  25. package/dist/cjs/components/panels.js +0 -92
  26. package/dist/cjs/drawers/BottomDrawer.d.ts +0 -16
  27. package/dist/cjs/drawers/BottomDrawer.js +0 -43
  28. package/dist/cjs/drawers/MobileBottomDrawer.d.ts +0 -20
  29. package/dist/cjs/drawers/MobileBottomDrawer.js +0 -102
  30. package/dist/cjs/drawers/MobileBottomDrawerHeader.d.ts +0 -11
  31. package/dist/cjs/drawers/MobileBottomDrawerHeader.js +0 -36
  32. package/dist/cjs/drawers/ResponsiveDrawer.d.ts +0 -25
  33. package/dist/cjs/drawers/ResponsiveDrawer.js +0 -22
  34. package/dist/cjs/drawers/WorkspaceSidePane.d.ts +0 -29
  35. package/dist/cjs/drawers/WorkspaceSidePane.js +0 -222
  36. package/dist/cjs/drawers/WorkspaceSidePaneRoot.d.ts +0 -1
  37. package/dist/cjs/drawers/WorkspaceSidePaneRoot.js +0 -93
  38. package/dist/cjs/drawers/drawerAppearance.d.ts +0 -8
  39. package/dist/cjs/drawers/drawerAppearance.js +0 -10
  40. package/dist/cjs/drawers/index.d.ts +0 -7
  41. package/dist/cjs/drawers/index.js +0 -19
  42. package/dist/cjs/drawers/useVisualViewportBottomInset.d.ts +0 -6
  43. package/dist/cjs/drawers/useVisualViewportBottomInset.js +0 -33
  44. package/dist/cjs/drawers/workspaceSidePaneGeometry.d.ts +0 -11
  45. package/dist/cjs/drawers/workspaceSidePaneGeometry.js +0 -15
  46. package/dist/cjs/feedback/StatusNotice.d.ts +0 -13
  47. package/dist/cjs/feedback/StatusNotice.js +0 -62
  48. package/dist/cjs/feedback/index.d.ts +0 -1
  49. package/dist/cjs/feedback/index.js +0 -7
  50. package/dist/cjs/index.d.ts +0 -9
  51. package/dist/cjs/index.js +0 -25
  52. package/dist/cjs/internal/DialogChoiceTile.d.ts +0 -20
  53. package/dist/cjs/internal/DialogChoiceTile.js +0 -60
  54. package/dist/cjs/links/LinkAddressPreview.d.ts +0 -19
  55. package/dist/cjs/links/LinkAddressPreview.js +0 -80
  56. package/dist/cjs/links/index.d.ts +0 -3
  57. package/dist/cjs/links/index.js +0 -9
  58. package/dist/cjs/links/useLinkAddressPreview.d.ts +0 -26
  59. package/dist/cjs/links/useLinkAddressPreview.js +0 -162
  60. package/dist/cjs/location/GeographicLocationField.d.ts +0 -26
  61. package/dist/cjs/location/GeographicLocationField.js +0 -49
  62. package/dist/cjs/location/GoogleMapsAttribution.d.ts +0 -1
  63. package/dist/cjs/location/GoogleMapsAttribution.js +0 -12
  64. package/dist/cjs/location/MetadataFieldGroup.d.ts +0 -5
  65. package/dist/cjs/location/MetadataFieldGroup.js +0 -13
  66. package/dist/cjs/location/MetadataValueField.d.ts +0 -23
  67. package/dist/cjs/location/MetadataValueField.js +0 -27
  68. package/dist/cjs/location/SearchInputAction.d.ts +0 -9
  69. package/dist/cjs/location/SearchInputAction.js +0 -14
  70. package/dist/cjs/location/TemplateBadge.d.ts +0 -5
  71. package/dist/cjs/location/TemplateBadge.js +0 -9
  72. package/dist/cjs/location/VenueSearchDialog.d.ts +0 -33
  73. package/dist/cjs/location/VenueSearchDialog.js +0 -112
  74. package/dist/cjs/location/index.d.ts +0 -6
  75. package/dist/cjs/location/index.js +0 -20
  76. package/dist/cjs/package.json +0 -3
  77. package/dist/cjs/pending/PendingChangesDialogShell.d.ts +0 -2
  78. package/dist/cjs/pending/PendingChangesDialogShell.js +0 -16
  79. package/dist/cjs/pending/PendingChangesDialogView.d.ts +0 -2
  80. package/dist/cjs/pending/PendingChangesDialogView.js +0 -140
  81. package/dist/cjs/pending/PendingChangesIndicatorView.d.ts +0 -10
  82. package/dist/cjs/pending/PendingChangesIndicatorView.js +0 -27
  83. package/dist/cjs/pending/index.d.ts +0 -3
  84. package/dist/cjs/pending/index.js +0 -9
  85. package/dist/cjs/pending/types.d.ts +0 -55
  86. package/dist/cjs/pending/types.js +0 -2
  87. package/dist/cjs/pricing/PlanUpgradeDialog.d.ts +0 -17
  88. package/dist/cjs/pricing/PlanUpgradeDialog.js +0 -22
  89. package/dist/cjs/pricing/PricingTable.d.ts +0 -28
  90. package/dist/cjs/pricing/PricingTable.js +0 -60
  91. package/dist/cjs/pricing/index.d.ts +0 -3
  92. package/dist/cjs/pricing/index.js +0 -8
  93. package/dist/cjs/providers/BayonThemeProvider.d.ts +0 -20
  94. package/dist/cjs/providers/BayonThemeProvider.js +0 -163
  95. package/dist/cjs/sections/ExpandableSectionToggle.d.ts +0 -12
  96. package/dist/cjs/sections/ExpandableSectionToggle.js +0 -32
  97. package/dist/cjs/sections/index.d.ts +0 -2
  98. package/dist/cjs/sections/index.js +0 -7
  99. package/dist/cjs/styles/pageStyles.d.ts +0 -15
  100. package/dist/cjs/styles/pageStyles.js +0 -103
  101. package/dist/cjs/swipe/SwipeActionRow.d.ts +0 -8
  102. package/dist/cjs/swipe/SwipeActionRow.js +0 -123
  103. package/dist/cjs/swipe/index.d.ts +0 -1
  104. package/dist/cjs/swipe/index.js +0 -8
  105. package/dist/cjs/theme/components.d.ts +0 -2
  106. package/dist/cjs/theme/components.js +0 -123
  107. package/dist/cjs/theme/createBayonTheme.d.ts +0 -4
  108. package/dist/cjs/theme/createBayonTheme.js +0 -45
  109. package/dist/cjs/theme/palette.d.ts +0 -146
  110. package/dist/cjs/theme/palette.js +0 -109
  111. package/dist/cjs/theme/shadows.d.ts +0 -2
  112. package/dist/cjs/theme/shadows.js +0 -21
  113. package/dist/cjs/theme/types.d.ts +0 -47
  114. package/dist/cjs/theme/types.js +0 -2
  115. package/dist/cjs/theme/typography.d.ts +0 -2
  116. package/dist/cjs/theme/typography.js +0 -58
  117. package/dist/cjs/toasts/ActionToast.d.ts +0 -11
  118. package/dist/cjs/toasts/ActionToast.js +0 -12
  119. package/dist/cjs/toasts/Toast.d.ts +0 -16
  120. package/dist/cjs/toasts/Toast.js +0 -55
  121. package/dist/cjs/toasts/index.d.ts +0 -5
  122. package/dist/cjs/toasts/index.js +0 -12
  123. package/dist/cjs/toasts/useUpwardToastDismiss.d.ts +0 -15
  124. package/dist/cjs/toasts/useUpwardToastDismiss.js +0 -73
  125. package/dist/cjs/uploads/CameraCaptureDialog.d.ts +0 -22
  126. package/dist/cjs/uploads/CameraCaptureDialog.js +0 -187
  127. package/dist/cjs/uploads/FileRow.d.ts +0 -10
  128. package/dist/cjs/uploads/FileRow.js +0 -23
  129. package/dist/cjs/uploads/FileSwipeActionRow.d.ts +0 -1
  130. package/dist/cjs/uploads/FileSwipeActionRow.js +0 -11
  131. package/dist/cjs/uploads/FileThumbnail.d.ts +0 -5
  132. package/dist/cjs/uploads/FileThumbnail.js +0 -104
  133. package/dist/cjs/uploads/FileUpload.d.ts +0 -26
  134. package/dist/cjs/uploads/FileUpload.js +0 -98
  135. package/dist/cjs/uploads/FileViewer.d.ts +0 -9
  136. package/dist/cjs/uploads/FileViewer.js +0 -155
  137. package/dist/cjs/uploads/ImageCropDialog.d.ts +0 -26
  138. package/dist/cjs/uploads/ImageCropDialog.js +0 -215
  139. package/dist/cjs/uploads/ImageInfoPanel.d.ts +0 -24
  140. package/dist/cjs/uploads/ImageInfoPanel.js +0 -41
  141. package/dist/cjs/uploads/ImageUploadQualityDialog.d.ts +0 -13
  142. package/dist/cjs/uploads/ImageUploadQualityDialog.js +0 -57
  143. package/dist/cjs/uploads/UploadProgressRing.d.ts +0 -24
  144. package/dist/cjs/uploads/UploadProgressRing.js +0 -32
  145. package/dist/cjs/uploads/cameraCropPresentation.d.ts +0 -2
  146. package/dist/cjs/uploads/cameraCropPresentation.js +0 -12
  147. package/dist/cjs/uploads/index.d.ts +0 -12
  148. package/dist/cjs/uploads/index.js +0 -24
  149. package/dist/cjs/utils/createBayonEmotionCache.d.ts +0 -1
  150. package/dist/cjs/utils/createBayonEmotionCache.js +0 -21
  151. package/dist/esm/actions/ActionMenu.js +0 -30
  152. package/dist/esm/actions/DialogActionButtons.js +0 -24
  153. package/dist/esm/actions/LoadingIconButton.js +0 -7
  154. package/dist/esm/actions/StickyActionFooter.js +0 -24
  155. package/dist/esm/actions/StickySubmitButton.js +0 -7
  156. package/dist/esm/actions/index.js +0 -7
  157. package/dist/esm/client.js +0 -5
  158. package/dist/esm/components/BayonFlowVisual.js +0 -81
  159. package/dist/esm/components/BayonThemeModeToggle.js +0 -28
  160. package/dist/esm/components/IconTooltipButton.js +0 -11
  161. package/dist/esm/components/panels.js +0 -76
  162. package/dist/esm/drawers/BottomDrawer.js +0 -37
  163. package/dist/esm/drawers/MobileBottomDrawer.js +0 -95
  164. package/dist/esm/drawers/MobileBottomDrawerHeader.js +0 -30
  165. package/dist/esm/drawers/ResponsiveDrawer.js +0 -19
  166. package/dist/esm/drawers/WorkspaceSidePane.js +0 -216
  167. package/dist/esm/drawers/WorkspaceSidePaneRoot.js +0 -90
  168. package/dist/esm/drawers/drawerAppearance.js +0 -7
  169. package/dist/esm/drawers/index.js +0 -8
  170. package/dist/esm/drawers/useVisualViewportBottomInset.js +0 -29
  171. package/dist/esm/drawers/workspaceSidePaneGeometry.js +0 -11
  172. package/dist/esm/feedback/StatusNotice.js +0 -56
  173. package/dist/esm/feedback/index.js +0 -3
  174. package/dist/esm/index.js +0 -9
  175. package/dist/esm/internal/DialogChoiceTile.js +0 -54
  176. package/dist/esm/links/LinkAddressPreview.js +0 -74
  177. package/dist/esm/links/index.js +0 -4
  178. package/dist/esm/links/useLinkAddressPreview.js +0 -159
  179. package/dist/esm/location/GeographicLocationField.js +0 -43
  180. package/dist/esm/location/GoogleMapsAttribution.js +0 -9
  181. package/dist/esm/location/MetadataFieldGroup.js +0 -9
  182. package/dist/esm/location/MetadataValueField.js +0 -23
  183. package/dist/esm/location/SearchInputAction.js +0 -8
  184. package/dist/esm/location/TemplateBadge.js +0 -6
  185. package/dist/esm/location/VenueSearchDialog.js +0 -109
  186. package/dist/esm/location/index.js +0 -7
  187. package/dist/esm/pending/PendingChangesDialogShell.js +0 -10
  188. package/dist/esm/pending/PendingChangesDialogView.js +0 -134
  189. package/dist/esm/pending/PendingChangesIndicatorView.js +0 -21
  190. package/dist/esm/pending/index.js +0 -4
  191. package/dist/esm/pending/types.js +0 -1
  192. package/dist/esm/pricing/PlanUpgradeDialog.js +0 -19
  193. package/dist/esm/pricing/PricingTable.js +0 -54
  194. package/dist/esm/pricing/index.js +0 -3
  195. package/dist/esm/providers/BayonThemeProvider.js +0 -123
  196. package/dist/esm/sections/ExpandableSectionToggle.js +0 -26
  197. package/dist/esm/sections/index.js +0 -3
  198. package/dist/esm/styles/pageStyles.js +0 -100
  199. package/dist/esm/swipe/SwipeActionRow.js +0 -116
  200. package/dist/esm/swipe/index.js +0 -3
  201. package/dist/esm/theme/components.js +0 -120
  202. package/dist/esm/theme/createBayonTheme.js +0 -41
  203. package/dist/esm/theme/palette.js +0 -106
  204. package/dist/esm/theme/shadows.js +0 -18
  205. package/dist/esm/theme/types.js +0 -1
  206. package/dist/esm/theme/typography.js +0 -55
  207. package/dist/esm/toasts/ActionToast.js +0 -9
  208. package/dist/esm/toasts/Toast.js +0 -52
  209. package/dist/esm/toasts/index.js +0 -5
  210. package/dist/esm/toasts/useUpwardToastDismiss.js +0 -69
  211. package/dist/esm/uploads/CameraCaptureDialog.js +0 -181
  212. package/dist/esm/uploads/FileRow.js +0 -17
  213. package/dist/esm/uploads/FileSwipeActionRow.js +0 -7
  214. package/dist/esm/uploads/FileThumbnail.js +0 -98
  215. package/dist/esm/uploads/FileUpload.js +0 -92
  216. package/dist/esm/uploads/FileViewer.js +0 -149
  217. package/dist/esm/uploads/ImageCropDialog.js +0 -212
  218. package/dist/esm/uploads/ImageInfoPanel.js +0 -35
  219. package/dist/esm/uploads/ImageUploadQualityDialog.js +0 -51
  220. package/dist/esm/uploads/UploadProgressRing.js +0 -29
  221. package/dist/esm/uploads/cameraCropPresentation.js +0 -5
  222. package/dist/esm/uploads/index.js +0 -11
  223. package/dist/esm/utils/createBayonEmotionCache.js +0 -15
  224. package/dist/types/actions/ActionMenu.d.ts +0 -24
  225. package/dist/types/actions/DialogActionButtons.d.ts +0 -23
  226. package/dist/types/actions/LoadingIconButton.d.ts +0 -11
  227. package/dist/types/actions/StickyActionFooter.d.ts +0 -14
  228. package/dist/types/actions/StickySubmitButton.d.ts +0 -10
  229. package/dist/types/actions/index.d.ts +0 -5
  230. package/dist/types/client.d.ts +0 -4
  231. package/dist/types/components/BayonFlowVisual.d.ts +0 -12
  232. package/dist/types/components/BayonThemeModeToggle.d.ts +0 -6
  233. package/dist/types/components/IconTooltipButton.d.ts +0 -10
  234. package/dist/types/components/panels.d.ts +0 -37
  235. package/dist/types/drawers/BottomDrawer.d.ts +0 -16
  236. package/dist/types/drawers/MobileBottomDrawer.d.ts +0 -20
  237. package/dist/types/drawers/MobileBottomDrawerHeader.d.ts +0 -11
  238. package/dist/types/drawers/ResponsiveDrawer.d.ts +0 -25
  239. package/dist/types/drawers/WorkspaceSidePane.d.ts +0 -29
  240. package/dist/types/drawers/WorkspaceSidePaneRoot.d.ts +0 -1
  241. package/dist/types/drawers/drawerAppearance.d.ts +0 -8
  242. package/dist/types/drawers/index.d.ts +0 -7
  243. package/dist/types/drawers/useVisualViewportBottomInset.d.ts +0 -6
  244. package/dist/types/drawers/workspaceSidePaneGeometry.d.ts +0 -11
  245. package/dist/types/feedback/StatusNotice.d.ts +0 -13
  246. package/dist/types/feedback/index.d.ts +0 -1
  247. package/dist/types/index.d.ts +0 -9
  248. package/dist/types/internal/DialogChoiceTile.d.ts +0 -20
  249. package/dist/types/links/LinkAddressPreview.d.ts +0 -19
  250. package/dist/types/links/index.d.ts +0 -3
  251. package/dist/types/links/useLinkAddressPreview.d.ts +0 -26
  252. package/dist/types/location/GeographicLocationField.d.ts +0 -26
  253. package/dist/types/location/GoogleMapsAttribution.d.ts +0 -1
  254. package/dist/types/location/MetadataFieldGroup.d.ts +0 -5
  255. package/dist/types/location/MetadataValueField.d.ts +0 -23
  256. package/dist/types/location/SearchInputAction.d.ts +0 -9
  257. package/dist/types/location/TemplateBadge.d.ts +0 -5
  258. package/dist/types/location/VenueSearchDialog.d.ts +0 -33
  259. package/dist/types/location/index.d.ts +0 -6
  260. package/dist/types/pending/PendingChangesDialogShell.d.ts +0 -2
  261. package/dist/types/pending/PendingChangesDialogView.d.ts +0 -2
  262. package/dist/types/pending/PendingChangesIndicatorView.d.ts +0 -10
  263. package/dist/types/pending/index.d.ts +0 -3
  264. package/dist/types/pending/types.d.ts +0 -55
  265. package/dist/types/pricing/PlanUpgradeDialog.d.ts +0 -17
  266. package/dist/types/pricing/PricingTable.d.ts +0 -28
  267. package/dist/types/pricing/index.d.ts +0 -3
  268. package/dist/types/providers/BayonThemeProvider.d.ts +0 -20
  269. package/dist/types/sections/ExpandableSectionToggle.d.ts +0 -12
  270. package/dist/types/sections/index.d.ts +0 -2
  271. package/dist/types/styles/pageStyles.d.ts +0 -15
  272. package/dist/types/swipe/SwipeActionRow.d.ts +0 -8
  273. package/dist/types/swipe/index.d.ts +0 -1
  274. package/dist/types/theme/components.d.ts +0 -2
  275. package/dist/types/theme/createBayonTheme.d.ts +0 -4
  276. package/dist/types/theme/palette.d.ts +0 -146
  277. package/dist/types/theme/shadows.d.ts +0 -2
  278. package/dist/types/theme/types.d.ts +0 -47
  279. package/dist/types/theme/typography.d.ts +0 -2
  280. package/dist/types/toasts/ActionToast.d.ts +0 -11
  281. package/dist/types/toasts/Toast.d.ts +0 -16
  282. package/dist/types/toasts/index.d.ts +0 -5
  283. package/dist/types/toasts/useUpwardToastDismiss.d.ts +0 -15
  284. package/dist/types/uploads/CameraCaptureDialog.d.ts +0 -22
  285. package/dist/types/uploads/FileRow.d.ts +0 -10
  286. package/dist/types/uploads/FileSwipeActionRow.d.ts +0 -1
  287. package/dist/types/uploads/FileThumbnail.d.ts +0 -5
  288. package/dist/types/uploads/FileUpload.d.ts +0 -26
  289. package/dist/types/uploads/FileViewer.d.ts +0 -9
  290. package/dist/types/uploads/ImageCropDialog.d.ts +0 -26
  291. package/dist/types/uploads/ImageInfoPanel.d.ts +0 -24
  292. package/dist/types/uploads/ImageUploadQualityDialog.d.ts +0 -13
  293. package/dist/types/uploads/UploadProgressRing.d.ts +0 -24
  294. package/dist/types/uploads/cameraCropPresentation.d.ts +0 -2
  295. package/dist/types/uploads/index.d.ts +0 -12
  296. package/dist/types/utils/createBayonEmotionCache.d.ts +0 -1
@@ -1,69 +0,0 @@
1
- "use client";
2
- import { useCallback, useMemo, useRef, useState, } from "react";
3
- export const TOAST_UPWARD_DISMISS_DISTANCE_PX = 64;
4
- export function useUpwardToastDismiss({ onDismiss, transform, }) {
5
- const pointerStartYRef = useRef(null);
6
- const [isDragging, setIsDragging] = useState(false);
7
- const [swipeOffsetY, setSwipeOffsetY] = useState(0);
8
- const resetDrag = useCallback(() => {
9
- pointerStartYRef.current = null;
10
- setIsDragging(false);
11
- setSwipeOffsetY(0);
12
- }, []);
13
- const onPointerDown = useCallback((event) => {
14
- if (!onDismiss || isInteractiveTarget(event.target)) {
15
- return;
16
- }
17
- pointerStartYRef.current = event.clientY;
18
- setIsDragging(true);
19
- event.currentTarget.setPointerCapture(event.pointerId);
20
- }, [onDismiss]);
21
- const onPointerMove = useCallback((event) => {
22
- if (!onDismiss || pointerStartYRef.current === null) {
23
- return;
24
- }
25
- event.preventDefault();
26
- setSwipeOffsetY(Math.min(0, event.clientY - pointerStartYRef.current));
27
- }, [onDismiss]);
28
- const onPointerUp = useCallback((event) => {
29
- const pointerStartY = pointerStartYRef.current;
30
- if (!onDismiss || pointerStartY === null) {
31
- return;
32
- }
33
- const upwardDistance = pointerStartY - event.clientY;
34
- resetDrag();
35
- if (upwardDistance >= TOAST_UPWARD_DISMISS_DISTANCE_PX) {
36
- onDismiss();
37
- }
38
- }, [onDismiss, resetDrag]);
39
- const pointerHandlers = useMemo(() => onDismiss
40
- ? {
41
- onPointerCancel: resetDrag,
42
- onPointerDown,
43
- onPointerMove,
44
- onPointerUp,
45
- }
46
- : undefined, [onDismiss, onPointerDown, onPointerMove, onPointerUp, resetDrag]);
47
- const sx = useMemo(() => onDismiss
48
- ? {
49
- // Product decision: direct manipulation is reserved for the toast
50
- // surface; nested actions such as Undo retain their normal taps.
51
- animation: isDragging ? "none" : undefined,
52
- touchAction: "none",
53
- transform: `${transform ? `${transform} ` : ""}translateY(${swipeOffsetY}px)`,
54
- transition: isDragging
55
- ? "none"
56
- : "transform 160ms cubic-bezier(0.2, 0, 0, 1)",
57
- userSelect: "none",
58
- WebkitTouchCallout: "none",
59
- WebkitUserSelect: "none",
60
- willChange: isDragging ? "transform" : "auto",
61
- }
62
- : undefined, [isDragging, onDismiss, swipeOffsetY, transform]);
63
- return { pointerHandlers, sx };
64
- }
65
- function isInteractiveTarget(target) {
66
- var _a;
67
- const element = target;
68
- return Boolean((_a = element === null || element === void 0 ? void 0 : element.closest) === null || _a === void 0 ? void 0 : _a.call(element, "button, a, input, select, textarea, [role='button']"));
69
- }
@@ -1,181 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useCallback, useEffect, useId, useRef, useState } from "react";
4
- import { Box, Dialog, DialogContent, DialogTitle, Typography, } from "@mui/material";
5
- import CameraAltIcon from "@mui/icons-material/CameraAlt";
6
- import { DialogActionButtons, DialogActionProgress, DialogCloseButton, } from "./cameraCropPresentation.js";
7
- import { StatusNotice } from "./cameraCropPresentation.js";
8
- const DEFAULT_LABELS = {
9
- title: "Take photo",
10
- close: "Close camera",
11
- preview: "Camera preview",
12
- capture: "Take photo",
13
- opening: "Opening camera…",
14
- ready: "Take a photo, then adjust its crop.",
15
- denied: "Camera access was denied. Allow camera access in your browser, then reopen the camera, or choose a photo.",
16
- unavailable: "The camera is unavailable. Check that it is connected and not in use, then reopen the camera, or choose a photo.",
17
- previewError: "The camera preview could not start. Close the camera and try again, or choose a photo.",
18
- captureError: "The photo could not be captured. Close the camera and try again, or choose a photo.",
19
- };
20
- /** Owns camera resources only; the host owns crop, upload and persistence. */
21
- export function CameraCaptureDialog({ onClose, onCapture, labels, facingMode = "user", fileName = "camera.jpg", previewMaxHeight = "50dvh", }) {
22
- const copy = { ...DEFAULT_LABELS, ...labels };
23
- const copyRef = useRef(copy);
24
- // Publish copy after commit so abandoned renders cannot change async feedback.
25
- useEffect(() => {
26
- copyRef.current = copy;
27
- });
28
- // Product decision: changing copy must never request camera permission again.
29
- const initialFacingMode = useRef(facingMode);
30
- const titleId = useId();
31
- const video = useRef(null);
32
- const stream = useRef(null);
33
- const active = useRef(true);
34
- const capturing = useRef(false);
35
- const [ready, setReady] = useState(false);
36
- const [busy, setBusy] = useState(false);
37
- const [error, setError] = useState(null);
38
- const attachPreview = useCallback((preview) => {
39
- video.current = preview;
40
- const acquired = stream.current;
41
- if (!preview || !acquired || !active.current)
42
- return;
43
- // Dialog portals can mount after permission resolves. Attach from both sides
44
- // of that race so an accepted camera never waits forever for its preview.
45
- preview.srcObject = acquired;
46
- void preview
47
- .play()
48
- .then(() => {
49
- if (active.current &&
50
- stream.current === acquired &&
51
- video.current === preview &&
52
- preview.readyState >= 2)
53
- setReady(true);
54
- })
55
- .catch((cause) => {
56
- if (!active.current ||
57
- stream.current !== acquired ||
58
- video.current !== preview)
59
- return;
60
- console.error("[CameraCaptureDialog] Could not play camera preview.", {
61
- cause,
62
- });
63
- acquired.getTracks().forEach((track) => track.stop());
64
- stream.current = null;
65
- preview.srcObject = null;
66
- setReady(false);
67
- setError(copyRef.current.previewError);
68
- });
69
- }, []);
70
- function stop() {
71
- var _a;
72
- (_a = stream.current) === null || _a === void 0 ? void 0 : _a.getTracks().forEach((track) => track.stop());
73
- stream.current = null;
74
- if (video.current)
75
- video.current.srcObject = null;
76
- }
77
- function close() {
78
- active.current = false;
79
- stop();
80
- onClose();
81
- }
82
- useEffect(() => {
83
- let cancelled = false;
84
- active.current = true;
85
- // Camera consent follows the explicit menu action. Every owned stream, including
86
- // a permission result arriving after dismissal, must stop before leaving capture.
87
- async function start() {
88
- var _a;
89
- try {
90
- if (!((_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.getUserMedia))
91
- throw new Error("Camera API unavailable");
92
- const acquired = await navigator.mediaDevices.getUserMedia({
93
- video: { facingMode: initialFacingMode.current },
94
- audio: false,
95
- });
96
- if (cancelled || !active.current) {
97
- acquired.getTracks().forEach((track) => track.stop());
98
- return;
99
- }
100
- stream.current = acquired;
101
- attachPreview(video.current);
102
- }
103
- catch (cause) {
104
- if (cancelled || !active.current)
105
- return;
106
- console.error("[CameraCaptureDialog] Could not start camera.", {
107
- cause,
108
- });
109
- stop();
110
- const denied = cause instanceof DOMException &&
111
- (cause.name === "NotAllowedError" || cause.name === "SecurityError");
112
- setError(denied ? copyRef.current.denied : copyRef.current.unavailable);
113
- }
114
- }
115
- void start();
116
- return () => {
117
- cancelled = true;
118
- active.current = false;
119
- stop();
120
- };
121
- }, [attachPreview]);
122
- function capture() {
123
- if (!ready || error || capturing.current || !active.current)
124
- return;
125
- capturing.current = true;
126
- setBusy(true);
127
- try {
128
- const preview = video.current;
129
- if (!preview || !preview.videoWidth || !preview.videoHeight)
130
- throw new Error("Camera frame is not ready");
131
- const canvas = document.createElement("canvas");
132
- canvas.width = preview.videoWidth;
133
- canvas.height = preview.videoHeight;
134
- const context = canvas.getContext("2d");
135
- if (!context)
136
- throw new Error("Camera capture canvas is unavailable");
137
- context.drawImage(preview, 0, 0);
138
- canvas.toBlob((blob) => {
139
- if (!active.current)
140
- return;
141
- if (!blob) {
142
- console.error("[CameraCaptureDialog] Camera capture returned no image.");
143
- setError(copyRef.current.captureError);
144
- setBusy(false);
145
- capturing.current = false;
146
- return;
147
- }
148
- active.current = false;
149
- stop();
150
- // Capture only prepares the existing crop flow; it never uploads or publishes.
151
- onCapture(new File([blob], fileName, { type: "image/jpeg" }));
152
- }, "image/jpeg", 0.92);
153
- }
154
- catch (cause) {
155
- console.error("[CameraCaptureDialog] Could not capture photo.", {
156
- cause,
157
- });
158
- setError(copyRef.current.captureError);
159
- setBusy(false);
160
- capturing.current = false;
161
- }
162
- }
163
- return (_jsxs(Dialog, { open: true, fullWidth: true, maxWidth: "xs", onClose: close, "aria-labelledby": titleId, onKeyDown: (event) => {
164
- if (event.key === "Enter") {
165
- event.stopPropagation();
166
- if (!(event.target instanceof HTMLButtonElement))
167
- event.preventDefault();
168
- }
169
- }, children: [_jsxs(DialogTitle, { id: titleId, sx: { pr: 7 }, children: [copy.title, _jsx(DialogCloseButton, { label: copy.close, onClose: close })] }), _jsxs(DialogContent, { children: [_jsx(Box, { component: "video", ref: attachPreview, autoPlay: true, muted: true, playsInline: true, "aria-label": copy.preview, onLoadedData: () => {
170
- var _a;
171
- if (active.current &&
172
- stream.current &&
173
- ((_a = video.current) === null || _a === void 0 ? void 0 : _a.srcObject) === stream.current)
174
- setReady(true);
175
- }, sx: {
176
- width: "100%",
177
- maxHeight: previewMaxHeight,
178
- bgcolor: "action.hover",
179
- borderRadius: 1,
180
- } }), error ? (_jsx(StatusNotice, { tone: "error", message: error })) : (_jsx(Typography, { variant: "body2", color: "text.secondary", role: "status", children: ready ? copy.ready : copy.opening }))] }), _jsx(DialogActionButtons, { confirmLabel: copy.capture, confirmDisabled: !ready || Boolean(error) || busy, confirmIcon: busy ? _jsx(DialogActionProgress, {}) : _jsx(CameraAltIcon, {}), onConfirm: capture })] }));
181
- }
@@ -1,17 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import DeleteOutlineRoundedIcon from "@mui/icons-material/DeleteOutlineRounded";
4
- import { Box, ButtonBase, IconButton, Stack, Typography } from "@mui/material";
5
- import { SwipeActionRow } from "./FileSwipeActionRow.js";
6
- export function FileRow({ attachment, canDelete, onDelete, onPreview, thumbnail, sizeLabel, }) {
7
- return (_jsx(SwipeActionRow, { canDelete: canDelete, onDelete: () => onDelete(attachment), dataComponent: "attachment-row-swipe-container", children: _jsxs(Stack, { direction: "row", sx: { alignItems: "center", gap: 1, minHeight: 56, px: 1.5 }, children: [_jsxs(ButtonBase, { "aria-label": `Preview attachment ${attachment.fileName}`, "data-component": "attachment-preview-target", onClick: () => onPreview(attachment), sx: {
8
- alignItems: "center",
9
- borderRadius: 1,
10
- flex: 1,
11
- gap: 1,
12
- justifyContent: "flex-start",
13
- minWidth: 0,
14
- p: 0.5,
15
- textAlign: "left",
16
- }, children: [thumbnail, _jsxs(Box, { sx: { flex: 1, minWidth: 0 }, children: [_jsx(Typography, { noWrap: true, sx: { color: "text.primary", fontSize: 14 }, children: attachment.fileName }), _jsx(Typography, { color: "text.secondary", sx: { fontSize: 12 }, children: sizeLabel })] })] }), canDelete ? (_jsx(IconButton, { "aria-label": `Delete attachment ${attachment.fileName}`, onClick: () => onDelete(attachment), size: "small", children: _jsx(DeleteOutlineRoundedIcon, { fontSize: "small" }) })) : null] }) }));
17
- }
@@ -1,7 +0,0 @@
1
- "use client";
2
- // The shared MUI row preserves the file adapter's error.main/common.white delete
3
- // surface, background.paper content, spacing(2), Delete label, 160ms easing and
4
- // reduced-motion behavior. Its gesture contract is the same: 12px direction lock,
5
- // 72px delete threshold, 104px cap, pan-y, cancellation and click suppression.
6
- // Keep one gesture implementation and the host's existing MUI theme context.
7
- export { SwipeActionRow } from "../swipe/SwipeActionRow.js";
@@ -1,98 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import InsertDriveFileRoundedIcon from "@mui/icons-material/InsertDriveFileRounded";
4
- import { Box, CircularProgress, Stack, Typography } from "@mui/material";
5
- import { useEffect, useState } from "react";
6
- const rasterTypes = new Set([
7
- "image/jpeg",
8
- "image/png",
9
- "image/gif",
10
- "image/webp",
11
- ]);
12
- export function FileThumbnail({ attachment, loadFile, }) {
13
- var _a;
14
- const { blobUrl, contentType, id } = attachment;
15
- const [preview, setPreview] = useState(null);
16
- const [failedSource, setFailedSource] = useState(null);
17
- const source = `${id}/${blobUrl}`;
18
- const isRaster = rasterTypes.has(contentType);
19
- const url = failedSource !== source && isRaster
20
- ? blobUrl.startsWith("blob:")
21
- ? blobUrl
22
- : (preview === null || preview === void 0 ? void 0 : preview.source) === source
23
- ? preview.url
24
- : null
25
- : null;
26
- const loadingPreview = isRaster &&
27
- !blobUrl.startsWith("blob:") &&
28
- failedSource !== source &&
29
- (preview === null || preview === void 0 ? void 0 : preview.source) !== source;
30
- useEffect(() => {
31
- if (!rasterTypes.has(contentType) || blobUrl.startsWith("blob:"))
32
- return;
33
- const controller = new AbortController();
34
- let objectUrl;
35
- // Only raster decoders receive authenticated bytes; never embed documents or SVG.
36
- // Host loaders may fail before returning a promise; both failures use the fallback.
37
- void (async () => {
38
- try {
39
- const blob = await loadFile(attachment, controller.signal);
40
- if (controller.signal.aborted)
41
- return;
42
- objectUrl = URL.createObjectURL(new Blob([blob], { type: contentType }));
43
- // A successful current attempt supersedes an earlier failure for this source.
44
- setFailedSource(null);
45
- setPreview({ source, url: objectUrl });
46
- }
47
- catch (error) {
48
- if (!controller.signal.aborted) {
49
- console.error("[AttachmentPreview] Unable to load image thumbnail.", {
50
- attachmentId: id,
51
- error,
52
- });
53
- setFailedSource(source);
54
- }
55
- }
56
- })();
57
- return () => {
58
- controller.abort();
59
- if (objectUrl)
60
- URL.revokeObjectURL(objectUrl);
61
- };
62
- }, [attachment, blobUrl, contentType, id, source, loadFile]);
63
- return url ? (_jsx(Box, { component: "img", src: url, alt: "", onError: () => {
64
- console.error("[AttachmentPreview] Unable to decode image thumbnail.", {
65
- attachmentId: id,
66
- });
67
- setFailedSource(source);
68
- }, sx: {
69
- width: 40,
70
- height: 40,
71
- flexShrink: 0,
72
- objectFit: "cover",
73
- borderRadius: 1,
74
- outline: "1px solid",
75
- outlineColor: (theme) => theme.palette.mode === "dark"
76
- ? "rgba(255,255,255,0.1)"
77
- : "rgba(0,0,0,0.1)",
78
- } })) : loadingPreview ? (_jsx(Stack, { "aria-label": "Loading attachment preview", sx: {
79
- alignItems: "center",
80
- bgcolor: "action.hover",
81
- borderRadius: 1,
82
- flexShrink: 0,
83
- height: 40,
84
- justifyContent: "center",
85
- width: 40,
86
- }, children: _jsx(CircularProgress, { size: 18 }) })) : (_jsxs(Stack, { "aria-hidden": true, sx: {
87
- width: 40,
88
- height: 40,
89
- flexShrink: 0,
90
- alignItems: "center",
91
- justifyContent: "center",
92
- bgcolor: "action.hover",
93
- borderRadius: 1,
94
- color: "text.secondary",
95
- }, children: [_jsx(InsertDriveFileRoundedIcon, { sx: { fontSize: 20 } }), _jsx(Typography, { sx: { fontSize: 9, fontWeight: 600, maxWidth: 36 }, noWrap: true, children: attachment.fileName.includes(".")
96
- ? (_a = attachment.fileName.split(".").pop()) === null || _a === void 0 ? void 0 : _a.slice(0, 5).toUpperCase()
97
- : "FILE" })] }));
98
- }
@@ -1,92 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useUploadLock } from "@bayonai/file-uploads/hooks";
4
- import AddRoundedIcon from "@mui/icons-material/AddRounded";
5
- import AttachFileRoundedIcon from "@mui/icons-material/AttachFileRounded";
6
- import { Box, ButtonBase, CircularProgress, IconButton, LinearProgress, Stack, Typography, } from "@mui/material";
7
- import { useRef, useState, } from "react";
8
- export function FileUpload({ attachments, canUpload = true, onUploadAttachment, label, accept, errorMessage, renderFile, renderViewer, RowShell, FieldIcon, colors, }) {
9
- const inputRef = useRef(null);
10
- const [previewAttachment, setPreviewAttachment] = useState(null);
11
- const [uploadError, setUploadError] = useState(null);
12
- const { busy: uploading, tryStart, finish } = useUploadLock();
13
- const countLabel = attachments.length
14
- ? `${attachments.length} attached file${attachments.length === 1 ? "" : "s"}`
15
- : canUpload
16
- ? "Add a file"
17
- : "No files";
18
- if (!canUpload && attachments.length === 0) {
19
- return null;
20
- }
21
- async function handleFileChange(fileList) {
22
- if (!canUpload)
23
- return;
24
- const file = fileList === null || fileList === void 0 ? void 0 : fileList[0];
25
- if (!file) {
26
- return;
27
- }
28
- if (!tryStart())
29
- return;
30
- setUploadError(null);
31
- try {
32
- await onUploadAttachment(file);
33
- }
34
- catch (error) {
35
- console.error("[AttachmentSection] Attachment upload failed.", {
36
- error,
37
- fileName: file.name,
38
- });
39
- setUploadError(errorMessage(error));
40
- }
41
- finally {
42
- finish();
43
- if (inputRef.current) {
44
- inputRef.current.value = "";
45
- }
46
- }
47
- }
48
- function openFilePicker() {
49
- var _a;
50
- if (!canUpload || uploading)
51
- return;
52
- (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
53
- }
54
- function handlePreviewAttachment(attachment) {
55
- setUploadError(null);
56
- setPreviewAttachment(attachment);
57
- }
58
- return (_jsxs(Box, { children: [_jsxs(Box, { sx: { position: "relative" }, children: [_jsxs(RowShell, { hasBottomBorder: attachments.length === 0, children: [_jsx(FieldIcon, { ariaLabel: `Add a file to ${label}`, onClick: canUpload && !uploading ? openFilePicker : undefined, children: _jsx(AttachFileRoundedIcon, {}) }), canUpload && uploading ? (_jsx(CircularProgress, { "aria-label": "Uploading attachment", size: 16, sx: { color: "primary.main" } })) : null, canUpload ? (_jsx(ButtonBase, { "aria-label": `Add a file to ${label}`, component: "button", disabled: uploading, onClick: openFilePicker, sx: {
59
- color: colors.text,
60
- display: "block",
61
- flex: 1,
62
- fontSize: 13,
63
- minWidth: 0,
64
- overflow: "hidden",
65
- textAlign: "left",
66
- textOverflow: "ellipsis",
67
- transition: `color ${colors.transition}`,
68
- whiteSpace: "nowrap",
69
- "&:hover": { color: "text.primary" },
70
- "&.Mui-disabled": {
71
- color: colors.text,
72
- },
73
- }, children: uploading ? "Uploading file..." : countLabel })) : (_jsx(Typography, { noWrap: true, sx: {
74
- color: colors.text,
75
- flex: 1,
76
- fontSize: 13,
77
- }, children: countLabel })), canUpload ? (_jsxs(_Fragment, { children: [_jsx(IconButton, { "aria-label": `Upload attachment to ${label}`, disabled: uploading, onClick: openFilePicker, size: "small", sx: { color: colors.text }, children: _jsx(AddRoundedIcon, { fontSize: "small" }) }), _jsx(Box, { accept: accept, component: "input", onChange: (event) => void handleFileChange(event.target.files), ref: inputRef, sx: { display: "none" }, type: "file" })] })) : null] }), canUpload && uploading ? (_jsx(LinearProgress, { "aria-label": "Attachment upload progress", "data-component": "attachment-upload-progress", sx: {
78
- bottom: 0,
79
- height: 2,
80
- left: 0,
81
- position: "absolute",
82
- right: 0,
83
- } })) : null] }), attachments.length ? (_jsxs(_Fragment, { children: [_jsx(Box, { "aria-hidden": true, sx: {
84
- borderTop: 1,
85
- borderColor: colors.divider,
86
- mx: "10%",
87
- } }), _jsx(Stack, { sx: {
88
- borderBottom: 1,
89
- borderColor: colors.divider,
90
- py: 0.5,
91
- }, children: attachments.map((attachment) => (_jsx(Box, { children: renderFile(attachment, handlePreviewAttachment) }, attachment.id))) })] })) : null, uploadError ? (_jsx(Typography, { color: "error", sx: { fontSize: 12, px: 1.5, py: 0.75 }, children: uploadError })) : null, renderViewer(previewAttachment, () => setPreviewAttachment(null))] }));
92
- }
@@ -1,149 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
- import { createElement as _createElement } from "react";
4
- import CloseRoundedIcon from "@mui/icons-material/CloseRounded";
5
- import DownloadRoundedIcon from "@mui/icons-material/DownloadRounded";
6
- import { Box, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, IconButton, Typography, } from "@mui/material";
7
- import { useEffect, useState } from "react";
8
- const rasterImageTypes = new Set([
9
- "image/jpeg",
10
- "image/png",
11
- "image/gif",
12
- "image/webp",
13
- ]);
14
- function getPreviewKind(contentType) {
15
- if (rasterImageTypes.has(contentType))
16
- return "image";
17
- if (contentType === "application/pdf")
18
- return "pdf";
19
- if (contentType.startsWith("text/") || contentType === "application/json") {
20
- return "text";
21
- }
22
- if (contentType.startsWith("audio/"))
23
- return "audio";
24
- if (contentType.startsWith("video/"))
25
- return "video";
26
- return null;
27
- }
28
- export function FileViewer(props) {
29
- const { attachment } = props;
30
- const fileKey = attachment
31
- ? `${attachment.id}/${attachment.blobUrl}`
32
- : "closed";
33
- // Product decision: file-specific loading and error state belongs to the
34
- // viewer. Consumers may replace the selected file without coordinating a
35
- // React key or clearing state from the previous selection.
36
- return _createElement(FileViewerState, { ...props, key: fileKey });
37
- }
38
- function FileViewerState({ attachment, onClose, loadFile, onDownload, }) {
39
- const [downloadError, setDownloadError] = useState(null);
40
- const [downloading, setDownloading] = useState(false);
41
- async function download() {
42
- if (!attachment || downloading)
43
- return;
44
- setDownloading(true);
45
- setDownloadError(null);
46
- try {
47
- await onDownload(attachment);
48
- }
49
- catch (error) {
50
- console.error("[FileViewer] Download failed.", {
51
- fileId: attachment.id,
52
- error,
53
- });
54
- setDownloadError("Could not download this file. Check your connection and try downloading again.");
55
- }
56
- finally {
57
- setDownloading(false);
58
- }
59
- }
60
- const previewKind = attachment
61
- ? getPreviewKind(attachment.contentType)
62
- : null;
63
- return (_jsxs(Dialog, { fullWidth: true, maxWidth: "md", onClose: onClose, open: Boolean(attachment), children: [_jsxs(DialogTitle, { sx: { pr: 6 }, children: [attachment === null || attachment === void 0 ? void 0 : attachment.fileName, _jsx(IconButton, { "aria-label": "Close attachment preview", onClick: onClose, sx: { position: "absolute", right: 8, top: 8 }, children: _jsx(CloseRoundedIcon, {}) })] }), _jsx(DialogContent, { dividers: true, sx: { minHeight: 240 }, children: attachment ? (_jsx(AttachmentViewerContent, { attachment: attachment, loadFile: loadFile, previewKind: previewKind })) : null }), downloadError ? (_jsx(Typography, { role: "alert", color: "error", sx: { px: 3 }, children: downloadError })) : null, _jsx(DialogActions, { children: attachment ? (_jsx(IconButton, { "aria-label": "Download attachment", disabled: downloading, onClick: () => void download(), children: _jsx(DownloadRoundedIcon, {}) })) : null })] }));
64
- }
65
- function AttachmentViewerContent({ attachment, previewKind, loadFile, }) {
66
- if (!previewKind) {
67
- return (_jsx(Typography, { color: "text.secondary", children: "This file type can\u2019t be displayed here. Download it to open it in a compatible app." }));
68
- }
69
- return (_jsx(LoadableAttachmentPreview, { attachment: attachment, previewKind: previewKind, loadFile: loadFile }));
70
- }
71
- function LoadableAttachmentPreview({ attachment, previewKind, loadFile, }) {
72
- const [attempt, setAttempt] = useState();
73
- // A replacement loader starts a fresh attempt even for the same attachment.
74
- const preview = (attempt === null || attempt === void 0 ? void 0 : attempt.attachment) === attachment && attempt.loadFile === loadFile
75
- ? attempt.result
76
- : undefined;
77
- const previewUrl = (preview === null || preview === void 0 ? void 0 : preview.kind) === "url" ? preview.value : undefined;
78
- function handleMediaDecodeError() {
79
- console.error("[FileViewer] Browser could not decode the file preview.", {
80
- contentType: attachment.contentType,
81
- fileId: attachment.id,
82
- previewKind,
83
- });
84
- setAttempt({ attachment, loadFile, result: { kind: "error" } });
85
- }
86
- useEffect(() => {
87
- let objectUrl = null;
88
- const controller = new AbortController();
89
- const { signal } = controller;
90
- const publish = (result) => {
91
- if (!signal.aborted)
92
- setAttempt({ attachment, loadFile, result });
93
- };
94
- void (async () => {
95
- try {
96
- const blob = attachment.blobUrl.startsWith("blob:")
97
- ? await fetch(attachment.blobUrl, { signal }).then((response) => {
98
- if (!response.ok)
99
- throw new Error("Local attachment blob is unavailable.");
100
- return response.blob();
101
- })
102
- : await loadFile(attachment, signal);
103
- if (signal.aborted)
104
- return;
105
- if (previewKind === "text") {
106
- const content = await blob.text();
107
- publish({ kind: "text", value: content });
108
- return;
109
- }
110
- objectUrl = attachment.blobUrl.startsWith("blob:")
111
- ? attachment.blobUrl
112
- : URL.createObjectURL(new Blob([blob], { type: attachment.contentType }));
113
- publish({ kind: "url", value: objectUrl });
114
- }
115
- catch (caughtError) {
116
- if (!signal.aborted) {
117
- console.error("[FileViewer] Unable to load the file preview.", {
118
- contentType: attachment.contentType,
119
- error: caughtError,
120
- fileId: attachment.id,
121
- });
122
- publish({ kind: "error" });
123
- }
124
- }
125
- })();
126
- return () => {
127
- controller.abort();
128
- if (objectUrl && !attachment.blobUrl.startsWith("blob:")) {
129
- URL.revokeObjectURL(objectUrl);
130
- }
131
- };
132
- }, [attachment, previewKind, loadFile]);
133
- return (_jsx(_Fragment, { children: !preview ? (_jsx(Box, { sx: { display: "grid", minHeight: 200, placeItems: "center" }, children: _jsx(CircularProgress, { "aria-label": "Loading attachment preview" }) })) : preview.kind === "error" ? (_jsx(Typography, { color: "error", role: "alert", children: "Unable to display this file. You can download it instead." })) : previewKind === "image" ? (_jsx(Box, { alt: attachment.fileName, component: "img", onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: {
134
- display: "block",
135
- maxHeight: "65vh",
136
- maxWidth: "100%",
137
- mx: "auto",
138
- } })) : previewKind === "pdf" ? (_jsx(Box, { component: "iframe", referrerPolicy: "no-referrer",
139
- // Product decision: PDFs are collaborator-controlled active-format
140
- // documents. Keep their browsing context opaque and block scripts,
141
- // forms, popups and top-level navigation while retaining preview.
142
- sandbox: "", src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, title: "Attachment preview", sx: { border: 0, height: "65vh", width: "100%" } })) : previewKind === "text" ? (_jsx(Box, { component: "pre", sx: {
143
- fontFamily: "monospace",
144
- fontSize: 13,
145
- m: 0,
146
- overflow: "auto",
147
- whiteSpace: "pre-wrap",
148
- }, children: preview.kind === "text" ? preview.value : undefined })) : previewKind === "audio" ? (_jsx(Box, { component: "audio", controls: true, onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: { width: "100%" } })) : (_jsx(Box, { component: "video", controls: true, onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: { maxHeight: "65vh", maxWidth: "100%", width: "100%" } })) }));
149
- }