@bayonai/mui-design 1.10.0 → 1.10.2
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.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/actions/ActionMenu.d.ts +24 -0
- package/dist/cjs/actions/ActionMenu.js +36 -0
- package/dist/cjs/actions/DialogActionButtons.d.ts +23 -0
- package/dist/cjs/actions/DialogActionButtons.js +33 -0
- package/dist/cjs/actions/LoadingIconButton.d.ts +11 -0
- package/dist/cjs/actions/LoadingIconButton.js +10 -0
- package/dist/cjs/actions/StickyActionFooter.d.ts +14 -0
- package/dist/cjs/actions/StickyActionFooter.js +27 -0
- package/dist/cjs/actions/StickySubmitButton.d.ts +10 -0
- package/dist/cjs/actions/StickySubmitButton.js +10 -0
- package/dist/cjs/actions/index.d.ts +5 -0
- package/dist/cjs/actions/index.js +18 -0
- package/dist/cjs/client.d.ts +4 -0
- package/dist/cjs/client.js +21 -0
- package/dist/cjs/components/BayonFlowVisual.d.ts +12 -0
- package/dist/cjs/components/BayonFlowVisual.js +87 -0
- package/dist/cjs/components/BayonThemeModeToggle.d.ts +6 -0
- package/dist/cjs/components/BayonThemeModeToggle.js +34 -0
- package/dist/cjs/components/IconTooltipButton.d.ts +10 -0
- package/dist/cjs/components/IconTooltipButton.js +50 -0
- package/dist/cjs/components/panels.d.ts +37 -0
- package/dist/cjs/components/panels.js +92 -0
- package/dist/cjs/drawers/BottomDrawer.d.ts +16 -0
- package/dist/cjs/drawers/BottomDrawer.js +43 -0
- package/dist/cjs/drawers/MobileBottomDrawer.d.ts +20 -0
- package/dist/cjs/drawers/MobileBottomDrawer.js +102 -0
- package/dist/cjs/drawers/MobileBottomDrawerHeader.d.ts +11 -0
- package/dist/cjs/drawers/MobileBottomDrawerHeader.js +36 -0
- package/dist/cjs/drawers/ResponsiveDrawer.d.ts +25 -0
- package/dist/cjs/drawers/ResponsiveDrawer.js +22 -0
- package/dist/cjs/drawers/WorkspaceSidePane.d.ts +31 -0
- package/dist/cjs/drawers/WorkspaceSidePane.js +228 -0
- package/dist/cjs/drawers/WorkspaceSidePaneRoot.d.ts +1 -0
- package/dist/cjs/drawers/WorkspaceSidePaneRoot.js +93 -0
- package/dist/cjs/drawers/drawerAppearance.d.ts +8 -0
- package/dist/cjs/drawers/drawerAppearance.js +10 -0
- package/dist/cjs/drawers/index.d.ts +7 -0
- package/dist/cjs/drawers/index.js +19 -0
- package/dist/cjs/drawers/useVisualViewportBottomInset.d.ts +6 -0
- package/dist/cjs/drawers/useVisualViewportBottomInset.js +33 -0
- package/dist/cjs/drawers/workspaceSidePaneGeometry.d.ts +11 -0
- package/dist/cjs/drawers/workspaceSidePaneGeometry.js +15 -0
- package/dist/cjs/feedback/StatusNotice.d.ts +13 -0
- package/dist/cjs/feedback/StatusNotice.js +62 -0
- package/dist/cjs/feedback/index.d.ts +1 -0
- package/dist/cjs/feedback/index.js +7 -0
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/internal/DialogChoiceTile.d.ts +20 -0
- package/dist/cjs/internal/DialogChoiceTile.js +60 -0
- package/dist/cjs/links/LinkAddressPreview.d.ts +21 -0
- package/dist/cjs/links/LinkAddressPreview.js +130 -0
- package/dist/cjs/links/index.d.ts +3 -0
- package/dist/cjs/links/index.js +9 -0
- package/dist/cjs/links/useLinkAddressPreview.d.ts +26 -0
- package/dist/cjs/links/useLinkAddressPreview.js +171 -0
- package/dist/cjs/location/GeographicLocationField.d.ts +26 -0
- package/dist/cjs/location/GeographicLocationField.js +49 -0
- package/dist/cjs/location/GoogleMapsAttribution.d.ts +1 -0
- package/dist/cjs/location/GoogleMapsAttribution.js +12 -0
- package/dist/cjs/location/MetadataFieldGroup.d.ts +5 -0
- package/dist/cjs/location/MetadataFieldGroup.js +13 -0
- package/dist/cjs/location/MetadataValueField.d.ts +23 -0
- package/dist/cjs/location/MetadataValueField.js +27 -0
- package/dist/cjs/location/SearchInputAction.d.ts +9 -0
- package/dist/cjs/location/SearchInputAction.js +14 -0
- package/dist/cjs/location/TemplateBadge.d.ts +5 -0
- package/dist/cjs/location/TemplateBadge.js +9 -0
- package/dist/cjs/location/VenueSearchDialog.d.ts +33 -0
- package/dist/cjs/location/VenueSearchDialog.js +112 -0
- package/dist/cjs/location/index.d.ts +6 -0
- package/dist/cjs/location/index.js +20 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pending/PendingChangesDialogShell.d.ts +2 -0
- package/dist/cjs/pending/PendingChangesDialogShell.js +16 -0
- package/dist/cjs/pending/PendingChangesDialogView.d.ts +2 -0
- package/dist/cjs/pending/PendingChangesDialogView.js +140 -0
- package/dist/cjs/pending/PendingChangesIndicatorView.d.ts +10 -0
- package/dist/cjs/pending/PendingChangesIndicatorView.js +27 -0
- package/dist/cjs/pending/index.d.ts +3 -0
- package/dist/cjs/pending/index.js +9 -0
- package/dist/cjs/pending/types.d.ts +55 -0
- package/dist/cjs/pending/types.js +2 -0
- package/dist/cjs/pricing/PlanUpgradeDialog.d.ts +17 -0
- package/dist/cjs/pricing/PlanUpgradeDialog.js +22 -0
- package/dist/cjs/pricing/PricingTable.d.ts +28 -0
- package/dist/cjs/pricing/PricingTable.js +60 -0
- package/dist/cjs/pricing/index.d.ts +3 -0
- package/dist/cjs/pricing/index.js +8 -0
- package/dist/cjs/providers/BayonThemeProvider.d.ts +20 -0
- package/dist/cjs/providers/BayonThemeProvider.js +163 -0
- package/dist/cjs/sections/ExpandableSectionToggle.d.ts +12 -0
- package/dist/cjs/sections/ExpandableSectionToggle.js +32 -0
- package/dist/cjs/sections/index.d.ts +2 -0
- package/dist/cjs/sections/index.js +7 -0
- package/dist/cjs/styles/pageStyles.d.ts +15 -0
- package/dist/cjs/styles/pageStyles.js +103 -0
- package/dist/cjs/swipe/SwipeActionRow.d.ts +8 -0
- package/dist/cjs/swipe/SwipeActionRow.js +123 -0
- package/dist/cjs/swipe/index.d.ts +1 -0
- package/dist/cjs/swipe/index.js +8 -0
- package/dist/cjs/theme/components.d.ts +2 -0
- package/dist/cjs/theme/components.js +123 -0
- package/dist/cjs/theme/createBayonTheme.d.ts +4 -0
- package/dist/cjs/theme/createBayonTheme.js +45 -0
- package/dist/cjs/theme/palette.d.ts +146 -0
- package/dist/cjs/theme/palette.js +109 -0
- package/dist/cjs/theme/shadows.d.ts +2 -0
- package/dist/cjs/theme/shadows.js +21 -0
- package/dist/cjs/theme/types.d.ts +47 -0
- package/dist/cjs/theme/types.js +2 -0
- package/dist/cjs/theme/typography.d.ts +2 -0
- package/dist/cjs/theme/typography.js +58 -0
- package/dist/cjs/toasts/ActionToast.d.ts +11 -0
- package/dist/cjs/toasts/ActionToast.js +12 -0
- package/dist/cjs/toasts/Toast.d.ts +16 -0
- package/dist/cjs/toasts/Toast.js +55 -0
- package/dist/cjs/toasts/index.d.ts +5 -0
- package/dist/cjs/toasts/index.js +12 -0
- package/dist/cjs/toasts/useUpwardToastDismiss.d.ts +15 -0
- package/dist/cjs/toasts/useUpwardToastDismiss.js +73 -0
- package/dist/cjs/uploads/CameraCaptureDialog.d.ts +22 -0
- package/dist/cjs/uploads/CameraCaptureDialog.js +187 -0
- package/dist/cjs/uploads/FileRow.d.ts +10 -0
- package/dist/cjs/uploads/FileRow.js +23 -0
- package/dist/cjs/uploads/FileSwipeActionRow.d.ts +1 -0
- package/dist/cjs/uploads/FileSwipeActionRow.js +11 -0
- package/dist/cjs/uploads/FileThumbnail.d.ts +5 -0
- package/dist/cjs/uploads/FileThumbnail.js +104 -0
- package/dist/cjs/uploads/FileUpload.d.ts +26 -0
- package/dist/cjs/uploads/FileUpload.js +98 -0
- package/dist/cjs/uploads/FileViewer.d.ts +9 -0
- package/dist/cjs/uploads/FileViewer.js +173 -0
- package/dist/cjs/uploads/ImageCropDialog.d.ts +26 -0
- package/dist/cjs/uploads/ImageCropDialog.js +215 -0
- package/dist/cjs/uploads/ImageInfoPanel.d.ts +24 -0
- package/dist/cjs/uploads/ImageInfoPanel.js +41 -0
- package/dist/cjs/uploads/ImageUploadQualityDialog.d.ts +13 -0
- package/dist/cjs/uploads/ImageUploadQualityDialog.js +57 -0
- package/dist/cjs/uploads/UploadProgressRing.d.ts +24 -0
- package/dist/cjs/uploads/UploadProgressRing.js +32 -0
- package/dist/cjs/uploads/cameraCropPresentation.d.ts +2 -0
- package/dist/cjs/uploads/cameraCropPresentation.js +12 -0
- package/dist/cjs/uploads/index.d.ts +12 -0
- package/dist/cjs/uploads/index.js +24 -0
- package/dist/cjs/utils/createBayonEmotionCache.d.ts +1 -0
- package/dist/cjs/utils/createBayonEmotionCache.js +21 -0
- package/dist/esm/actions/ActionMenu.js +30 -0
- package/dist/esm/actions/DialogActionButtons.js +24 -0
- package/dist/esm/actions/LoadingIconButton.js +7 -0
- package/dist/esm/actions/StickyActionFooter.js +24 -0
- package/dist/esm/actions/StickySubmitButton.js +7 -0
- package/dist/esm/actions/index.js +7 -0
- package/dist/esm/client.js +5 -0
- package/dist/esm/components/BayonFlowVisual.js +81 -0
- package/dist/esm/components/BayonThemeModeToggle.js +28 -0
- package/dist/esm/components/IconTooltipButton.js +11 -0
- package/dist/esm/components/panels.js +76 -0
- package/dist/esm/drawers/BottomDrawer.js +37 -0
- package/dist/esm/drawers/MobileBottomDrawer.js +95 -0
- package/dist/esm/drawers/MobileBottomDrawerHeader.js +30 -0
- package/dist/esm/drawers/ResponsiveDrawer.js +19 -0
- package/dist/esm/drawers/WorkspaceSidePane.js +222 -0
- package/dist/esm/drawers/WorkspaceSidePaneRoot.js +90 -0
- package/dist/esm/drawers/drawerAppearance.js +7 -0
- package/dist/esm/drawers/index.js +8 -0
- package/dist/esm/drawers/useVisualViewportBottomInset.js +29 -0
- package/dist/esm/drawers/workspaceSidePaneGeometry.js +11 -0
- package/dist/esm/feedback/StatusNotice.js +56 -0
- package/dist/esm/feedback/index.js +3 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/internal/DialogChoiceTile.js +54 -0
- package/dist/esm/links/LinkAddressPreview.js +91 -0
- package/dist/esm/links/index.js +4 -0
- package/dist/esm/links/useLinkAddressPreview.js +168 -0
- package/dist/esm/location/GeographicLocationField.js +43 -0
- package/dist/esm/location/GoogleMapsAttribution.js +9 -0
- package/dist/esm/location/MetadataFieldGroup.js +9 -0
- package/dist/esm/location/MetadataValueField.js +23 -0
- package/dist/esm/location/SearchInputAction.js +8 -0
- package/dist/esm/location/TemplateBadge.js +6 -0
- package/dist/esm/location/VenueSearchDialog.js +109 -0
- package/dist/esm/location/index.js +7 -0
- package/dist/esm/pending/PendingChangesDialogShell.js +10 -0
- package/dist/esm/pending/PendingChangesDialogView.js +134 -0
- package/dist/esm/pending/PendingChangesIndicatorView.js +21 -0
- package/dist/esm/pending/index.js +4 -0
- package/dist/esm/pending/types.js +1 -0
- package/dist/esm/pricing/PlanUpgradeDialog.js +19 -0
- package/dist/esm/pricing/PricingTable.js +54 -0
- package/dist/esm/pricing/index.js +3 -0
- package/dist/esm/providers/BayonThemeProvider.js +123 -0
- package/dist/esm/sections/ExpandableSectionToggle.js +26 -0
- package/dist/esm/sections/index.js +3 -0
- package/dist/esm/styles/pageStyles.js +100 -0
- package/dist/esm/swipe/SwipeActionRow.js +116 -0
- package/dist/esm/swipe/index.js +3 -0
- package/dist/esm/theme/components.js +120 -0
- package/dist/esm/theme/createBayonTheme.js +41 -0
- package/dist/esm/theme/palette.js +106 -0
- package/dist/esm/theme/shadows.js +18 -0
- package/dist/esm/theme/types.js +1 -0
- package/dist/esm/theme/typography.js +55 -0
- package/dist/esm/toasts/ActionToast.js +9 -0
- package/dist/esm/toasts/Toast.js +52 -0
- package/dist/esm/toasts/index.js +5 -0
- package/dist/esm/toasts/useUpwardToastDismiss.js +69 -0
- package/dist/esm/uploads/CameraCaptureDialog.js +181 -0
- package/dist/esm/uploads/FileRow.js +17 -0
- package/dist/esm/uploads/FileSwipeActionRow.js +7 -0
- package/dist/esm/uploads/FileThumbnail.js +98 -0
- package/dist/esm/uploads/FileUpload.js +92 -0
- package/dist/esm/uploads/FileViewer.js +167 -0
- package/dist/esm/uploads/ImageCropDialog.js +212 -0
- package/dist/esm/uploads/ImageInfoPanel.js +35 -0
- package/dist/esm/uploads/ImageUploadQualityDialog.js +51 -0
- package/dist/esm/uploads/UploadProgressRing.js +29 -0
- package/dist/esm/uploads/cameraCropPresentation.js +5 -0
- package/dist/esm/uploads/index.js +11 -0
- package/dist/esm/utils/createBayonEmotionCache.js +15 -0
- package/dist/types/actions/ActionMenu.d.ts +24 -0
- package/dist/types/actions/DialogActionButtons.d.ts +23 -0
- package/dist/types/actions/LoadingIconButton.d.ts +11 -0
- package/dist/types/actions/StickyActionFooter.d.ts +14 -0
- package/dist/types/actions/StickySubmitButton.d.ts +10 -0
- package/dist/types/actions/index.d.ts +5 -0
- package/dist/types/client.d.ts +4 -0
- package/dist/types/components/BayonFlowVisual.d.ts +12 -0
- package/dist/types/components/BayonThemeModeToggle.d.ts +6 -0
- package/dist/types/components/IconTooltipButton.d.ts +10 -0
- package/dist/types/components/panels.d.ts +37 -0
- package/dist/types/drawers/BottomDrawer.d.ts +16 -0
- package/dist/types/drawers/MobileBottomDrawer.d.ts +20 -0
- package/dist/types/drawers/MobileBottomDrawerHeader.d.ts +11 -0
- package/dist/types/drawers/ResponsiveDrawer.d.ts +25 -0
- package/dist/types/drawers/WorkspaceSidePane.d.ts +31 -0
- package/dist/types/drawers/WorkspaceSidePaneRoot.d.ts +1 -0
- package/dist/types/drawers/drawerAppearance.d.ts +8 -0
- package/dist/types/drawers/index.d.ts +7 -0
- package/dist/types/drawers/useVisualViewportBottomInset.d.ts +6 -0
- package/dist/types/drawers/workspaceSidePaneGeometry.d.ts +11 -0
- package/dist/types/feedback/StatusNotice.d.ts +13 -0
- package/dist/types/feedback/index.d.ts +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/internal/DialogChoiceTile.d.ts +20 -0
- package/dist/types/links/LinkAddressPreview.d.ts +21 -0
- package/dist/types/links/index.d.ts +3 -0
- package/dist/types/links/useLinkAddressPreview.d.ts +26 -0
- package/dist/types/location/GeographicLocationField.d.ts +26 -0
- package/dist/types/location/GoogleMapsAttribution.d.ts +1 -0
- package/dist/types/location/MetadataFieldGroup.d.ts +5 -0
- package/dist/types/location/MetadataValueField.d.ts +23 -0
- package/dist/types/location/SearchInputAction.d.ts +9 -0
- package/dist/types/location/TemplateBadge.d.ts +5 -0
- package/dist/types/location/VenueSearchDialog.d.ts +33 -0
- package/dist/types/location/index.d.ts +6 -0
- package/dist/types/pending/PendingChangesDialogShell.d.ts +2 -0
- package/dist/types/pending/PendingChangesDialogView.d.ts +2 -0
- package/dist/types/pending/PendingChangesIndicatorView.d.ts +10 -0
- package/dist/types/pending/index.d.ts +3 -0
- package/dist/types/pending/types.d.ts +55 -0
- package/dist/types/pricing/PlanUpgradeDialog.d.ts +17 -0
- package/dist/types/pricing/PricingTable.d.ts +28 -0
- package/dist/types/pricing/index.d.ts +3 -0
- package/dist/types/providers/BayonThemeProvider.d.ts +20 -0
- package/dist/types/sections/ExpandableSectionToggle.d.ts +12 -0
- package/dist/types/sections/index.d.ts +2 -0
- package/dist/types/styles/pageStyles.d.ts +15 -0
- package/dist/types/swipe/SwipeActionRow.d.ts +8 -0
- package/dist/types/swipe/index.d.ts +1 -0
- package/dist/types/theme/components.d.ts +2 -0
- package/dist/types/theme/createBayonTheme.d.ts +4 -0
- package/dist/types/theme/palette.d.ts +146 -0
- package/dist/types/theme/shadows.d.ts +2 -0
- package/dist/types/theme/types.d.ts +47 -0
- package/dist/types/theme/typography.d.ts +2 -0
- package/dist/types/toasts/ActionToast.d.ts +11 -0
- package/dist/types/toasts/Toast.d.ts +16 -0
- package/dist/types/toasts/index.d.ts +5 -0
- package/dist/types/toasts/useUpwardToastDismiss.d.ts +15 -0
- package/dist/types/uploads/CameraCaptureDialog.d.ts +22 -0
- package/dist/types/uploads/FileRow.d.ts +10 -0
- package/dist/types/uploads/FileSwipeActionRow.d.ts +1 -0
- package/dist/types/uploads/FileThumbnail.d.ts +5 -0
- package/dist/types/uploads/FileUpload.d.ts +26 -0
- package/dist/types/uploads/FileViewer.d.ts +9 -0
- package/dist/types/uploads/ImageCropDialog.d.ts +26 -0
- package/dist/types/uploads/ImageInfoPanel.d.ts +24 -0
- package/dist/types/uploads/ImageUploadQualityDialog.d.ts +13 -0
- package/dist/types/uploads/UploadProgressRing.d.ts +24 -0
- package/dist/types/uploads/cameraCropPresentation.d.ts +2 -0
- package/dist/types/uploads/index.d.ts +12 -0
- package/dist/types/utils/createBayonEmotionCache.d.ts +1 -0
- package/docs/uploads-contract.md +15 -0
- package/package.json +2 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { UploadFile } from "@bayonai/file-uploads";
|
|
3
|
+
export declare function FileRow<T extends UploadFile>({ attachment, canDelete, onDelete, onPreview, thumbnail, sizeLabel, }: {
|
|
4
|
+
attachment: T;
|
|
5
|
+
canDelete: boolean;
|
|
6
|
+
onDelete: (file: T) => void;
|
|
7
|
+
onPreview: (file: T) => void;
|
|
8
|
+
thumbnail: ReactNode;
|
|
9
|
+
sizeLabel: string;
|
|
10
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.FileRow = FileRow;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const DeleteOutlineRounded_1 = __importDefault(require("@mui/icons-material/DeleteOutlineRounded"));
|
|
10
|
+
const material_1 = require("@mui/material");
|
|
11
|
+
const FileSwipeActionRow_js_1 = require("./FileSwipeActionRow.js");
|
|
12
|
+
function FileRow({ attachment, canDelete, onDelete, onPreview, thumbnail, sizeLabel, }) {
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(FileSwipeActionRow_js_1.SwipeActionRow, { canDelete: canDelete, onDelete: () => onDelete(attachment), dataComponent: "attachment-row-swipe-container", children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", sx: { alignItems: "center", gap: 1, minHeight: 56, px: 1.5 }, children: [(0, jsx_runtime_1.jsxs)(material_1.ButtonBase, { "aria-label": `Preview attachment ${attachment.fileName}`, "data-component": "attachment-preview-target", onClick: () => onPreview(attachment), sx: {
|
|
14
|
+
alignItems: "center",
|
|
15
|
+
borderRadius: 1,
|
|
16
|
+
flex: 1,
|
|
17
|
+
gap: 1,
|
|
18
|
+
justifyContent: "flex-start",
|
|
19
|
+
minWidth: 0,
|
|
20
|
+
p: 0.5,
|
|
21
|
+
textAlign: "left",
|
|
22
|
+
}, children: [thumbnail, (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { flex: 1, minWidth: 0 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, sx: { color: "text.primary", fontSize: 14 }, children: attachment.fileName }), (0, jsx_runtime_1.jsx)(material_1.Typography, { color: "text.secondary", sx: { fontSize: 12 }, children: sizeLabel })] })] }), canDelete ? ((0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": `Delete attachment ${attachment.fileName}`, onClick: () => onDelete(attachment), size: "small", children: (0, jsx_runtime_1.jsx)(DeleteOutlineRounded_1.default, { fontSize: "small" }) })) : null] }) }));
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SwipeActionRow } from "../swipe/SwipeActionRow.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SwipeActionRow = void 0;
|
|
5
|
+
// The shared MUI row preserves the file adapter's error.main/common.white delete
|
|
6
|
+
// surface, background.paper content, spacing(2), Delete label, 160ms easing and
|
|
7
|
+
// reduced-motion behavior. Its gesture contract is the same: 12px direction lock,
|
|
8
|
+
// 72px delete threshold, 104px cap, pan-y, cancellation and click suppression.
|
|
9
|
+
// Keep one gesture implementation and the host's existing MUI theme context.
|
|
10
|
+
var SwipeActionRow_js_1 = require("../swipe/SwipeActionRow.js");
|
|
11
|
+
Object.defineProperty(exports, "SwipeActionRow", { enumerable: true, get: function () { return SwipeActionRow_js_1.SwipeActionRow; } });
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.FileThumbnail = FileThumbnail;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const InsertDriveFileRounded_1 = __importDefault(require("@mui/icons-material/InsertDriveFileRounded"));
|
|
10
|
+
const material_1 = require("@mui/material");
|
|
11
|
+
const react_1 = require("react");
|
|
12
|
+
const rasterTypes = new Set([
|
|
13
|
+
"image/jpeg",
|
|
14
|
+
"image/png",
|
|
15
|
+
"image/gif",
|
|
16
|
+
"image/webp",
|
|
17
|
+
]);
|
|
18
|
+
function FileThumbnail({ attachment, loadFile, }) {
|
|
19
|
+
var _a;
|
|
20
|
+
const { blobUrl, contentType, id } = attachment;
|
|
21
|
+
const [preview, setPreview] = (0, react_1.useState)(null);
|
|
22
|
+
const [failedSource, setFailedSource] = (0, react_1.useState)(null);
|
|
23
|
+
const source = `${id}/${blobUrl}`;
|
|
24
|
+
const isRaster = rasterTypes.has(contentType);
|
|
25
|
+
const url = failedSource !== source && isRaster
|
|
26
|
+
? blobUrl.startsWith("blob:")
|
|
27
|
+
? blobUrl
|
|
28
|
+
: (preview === null || preview === void 0 ? void 0 : preview.source) === source
|
|
29
|
+
? preview.url
|
|
30
|
+
: null
|
|
31
|
+
: null;
|
|
32
|
+
const loadingPreview = isRaster &&
|
|
33
|
+
!blobUrl.startsWith("blob:") &&
|
|
34
|
+
failedSource !== source &&
|
|
35
|
+
(preview === null || preview === void 0 ? void 0 : preview.source) !== source;
|
|
36
|
+
(0, react_1.useEffect)(() => {
|
|
37
|
+
if (!rasterTypes.has(contentType) || blobUrl.startsWith("blob:"))
|
|
38
|
+
return;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
let objectUrl;
|
|
41
|
+
// Only raster decoders receive authenticated bytes; never embed documents or SVG.
|
|
42
|
+
// Host loaders may fail before returning a promise; both failures use the fallback.
|
|
43
|
+
void (async () => {
|
|
44
|
+
try {
|
|
45
|
+
const blob = await loadFile(attachment, controller.signal);
|
|
46
|
+
if (controller.signal.aborted)
|
|
47
|
+
return;
|
|
48
|
+
objectUrl = URL.createObjectURL(new Blob([blob], { type: contentType }));
|
|
49
|
+
// A successful current attempt supersedes an earlier failure for this source.
|
|
50
|
+
setFailedSource(null);
|
|
51
|
+
setPreview({ source, url: objectUrl });
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
if (!controller.signal.aborted) {
|
|
55
|
+
console.error("[AttachmentPreview] Unable to load image thumbnail.", {
|
|
56
|
+
attachmentId: id,
|
|
57
|
+
error,
|
|
58
|
+
});
|
|
59
|
+
setFailedSource(source);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
})();
|
|
63
|
+
return () => {
|
|
64
|
+
controller.abort();
|
|
65
|
+
if (objectUrl)
|
|
66
|
+
URL.revokeObjectURL(objectUrl);
|
|
67
|
+
};
|
|
68
|
+
}, [attachment, blobUrl, contentType, id, source, loadFile]);
|
|
69
|
+
return url ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: url, alt: "", onError: () => {
|
|
70
|
+
console.error("[AttachmentPreview] Unable to decode image thumbnail.", {
|
|
71
|
+
attachmentId: id,
|
|
72
|
+
});
|
|
73
|
+
setFailedSource(source);
|
|
74
|
+
}, sx: {
|
|
75
|
+
width: 40,
|
|
76
|
+
height: 40,
|
|
77
|
+
flexShrink: 0,
|
|
78
|
+
objectFit: "cover",
|
|
79
|
+
borderRadius: 1,
|
|
80
|
+
outline: "1px solid",
|
|
81
|
+
outlineColor: (theme) => theme.palette.mode === "dark"
|
|
82
|
+
? "rgba(255,255,255,0.1)"
|
|
83
|
+
: "rgba(0,0,0,0.1)",
|
|
84
|
+
} })) : loadingPreview ? ((0, jsx_runtime_1.jsx)(material_1.Stack, { "aria-label": "Loading attachment preview", sx: {
|
|
85
|
+
alignItems: "center",
|
|
86
|
+
bgcolor: "action.hover",
|
|
87
|
+
borderRadius: 1,
|
|
88
|
+
flexShrink: 0,
|
|
89
|
+
height: 40,
|
|
90
|
+
justifyContent: "center",
|
|
91
|
+
width: 40,
|
|
92
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 18 }) })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { "aria-hidden": true, sx: {
|
|
93
|
+
width: 40,
|
|
94
|
+
height: 40,
|
|
95
|
+
flexShrink: 0,
|
|
96
|
+
alignItems: "center",
|
|
97
|
+
justifyContent: "center",
|
|
98
|
+
bgcolor: "action.hover",
|
|
99
|
+
borderRadius: 1,
|
|
100
|
+
color: "text.secondary",
|
|
101
|
+
}, children: [(0, jsx_runtime_1.jsx)(InsertDriveFileRounded_1.default, { sx: { fontSize: 20 } }), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: { fontSize: 9, fontWeight: 600, maxWidth: 36 }, noWrap: true, children: attachment.fileName.includes(".")
|
|
102
|
+
? (_a = attachment.fileName.split(".").pop()) === null || _a === void 0 ? void 0 : _a.slice(0, 5).toUpperCase()
|
|
103
|
+
: "FILE" })] }));
|
|
104
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ReactNode, type ComponentType } from "react";
|
|
2
|
+
import type { UploadFile } from "@bayonai/file-uploads";
|
|
3
|
+
export declare function FileUpload<T extends UploadFile>({ attachments, canUpload, onUploadAttachment, label, accept, errorMessage, renderFile, renderViewer, RowShell, FieldIcon, colors, }: {
|
|
4
|
+
attachments: T[];
|
|
5
|
+
canUpload?: boolean;
|
|
6
|
+
onUploadAttachment: (file: File) => Promise<void> | void;
|
|
7
|
+
label: string;
|
|
8
|
+
accept: string;
|
|
9
|
+
errorMessage: (error: unknown) => string | null;
|
|
10
|
+
renderFile: (file: T, onPreview: (file: T) => void) => ReactNode;
|
|
11
|
+
renderViewer: (file: T | null, onClose: () => void) => ReactNode;
|
|
12
|
+
RowShell: ComponentType<{
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
hasBottomBorder?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
FieldIcon: ComponentType<{
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
ariaLabel?: string;
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
}>;
|
|
21
|
+
colors: {
|
|
22
|
+
text: string;
|
|
23
|
+
divider: string;
|
|
24
|
+
transition: string;
|
|
25
|
+
};
|
|
26
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.FileUpload = FileUpload;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const hooks_1 = require("@bayonai/file-uploads/hooks");
|
|
10
|
+
const AddRounded_1 = __importDefault(require("@mui/icons-material/AddRounded"));
|
|
11
|
+
const AttachFileRounded_1 = __importDefault(require("@mui/icons-material/AttachFileRounded"));
|
|
12
|
+
const material_1 = require("@mui/material");
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
function FileUpload({ attachments, canUpload = true, onUploadAttachment, label, accept, errorMessage, renderFile, renderViewer, RowShell, FieldIcon, colors, }) {
|
|
15
|
+
const inputRef = (0, react_1.useRef)(null);
|
|
16
|
+
const [previewAttachment, setPreviewAttachment] = (0, react_1.useState)(null);
|
|
17
|
+
const [uploadError, setUploadError] = (0, react_1.useState)(null);
|
|
18
|
+
const { busy: uploading, tryStart, finish } = (0, hooks_1.useUploadLock)();
|
|
19
|
+
const countLabel = attachments.length
|
|
20
|
+
? `${attachments.length} attached file${attachments.length === 1 ? "" : "s"}`
|
|
21
|
+
: canUpload
|
|
22
|
+
? "Add a file"
|
|
23
|
+
: "No files";
|
|
24
|
+
if (!canUpload && attachments.length === 0) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
async function handleFileChange(fileList) {
|
|
28
|
+
if (!canUpload)
|
|
29
|
+
return;
|
|
30
|
+
const file = fileList === null || fileList === void 0 ? void 0 : fileList[0];
|
|
31
|
+
if (!file) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (!tryStart())
|
|
35
|
+
return;
|
|
36
|
+
setUploadError(null);
|
|
37
|
+
try {
|
|
38
|
+
await onUploadAttachment(file);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error("[AttachmentSection] Attachment upload failed.", {
|
|
42
|
+
error,
|
|
43
|
+
fileName: file.name,
|
|
44
|
+
});
|
|
45
|
+
setUploadError(errorMessage(error));
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
finish();
|
|
49
|
+
if (inputRef.current) {
|
|
50
|
+
inputRef.current.value = "";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function openFilePicker() {
|
|
55
|
+
var _a;
|
|
56
|
+
if (!canUpload || uploading)
|
|
57
|
+
return;
|
|
58
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
59
|
+
}
|
|
60
|
+
function handlePreviewAttachment(attachment) {
|
|
61
|
+
setUploadError(null);
|
|
62
|
+
setPreviewAttachment(attachment);
|
|
63
|
+
}
|
|
64
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { position: "relative" }, children: [(0, jsx_runtime_1.jsxs)(RowShell, { hasBottomBorder: attachments.length === 0, children: [(0, jsx_runtime_1.jsx)(FieldIcon, { ariaLabel: `Add a file to ${label}`, onClick: canUpload && !uploading ? openFilePicker : undefined, children: (0, jsx_runtime_1.jsx)(AttachFileRounded_1.default, {}) }), canUpload && uploading ? ((0, jsx_runtime_1.jsx)(material_1.CircularProgress, { "aria-label": "Uploading attachment", size: 16, sx: { color: "primary.main" } })) : null, canUpload ? ((0, jsx_runtime_1.jsx)(material_1.ButtonBase, { "aria-label": `Add a file to ${label}`, component: "button", disabled: uploading, onClick: openFilePicker, sx: {
|
|
65
|
+
color: colors.text,
|
|
66
|
+
display: "block",
|
|
67
|
+
flex: 1,
|
|
68
|
+
fontSize: 13,
|
|
69
|
+
minWidth: 0,
|
|
70
|
+
overflow: "hidden",
|
|
71
|
+
textAlign: "left",
|
|
72
|
+
textOverflow: "ellipsis",
|
|
73
|
+
transition: `color ${colors.transition}`,
|
|
74
|
+
whiteSpace: "nowrap",
|
|
75
|
+
"&:hover": { color: "text.primary" },
|
|
76
|
+
"&.Mui-disabled": {
|
|
77
|
+
color: colors.text,
|
|
78
|
+
},
|
|
79
|
+
}, children: uploading ? "Uploading file..." : countLabel })) : ((0, jsx_runtime_1.jsx)(material_1.Typography, { noWrap: true, sx: {
|
|
80
|
+
color: colors.text,
|
|
81
|
+
flex: 1,
|
|
82
|
+
fontSize: 13,
|
|
83
|
+
}, children: countLabel })), canUpload ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": `Upload attachment to ${label}`, disabled: uploading, onClick: openFilePicker, size: "small", sx: { color: colors.text }, children: (0, jsx_runtime_1.jsx)(AddRounded_1.default, { fontSize: "small" }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { accept: accept, component: "input", onChange: (event) => void handleFileChange(event.target.files), ref: inputRef, sx: { display: "none" }, type: "file" })] })) : null] }), canUpload && uploading ? ((0, jsx_runtime_1.jsx)(material_1.LinearProgress, { "aria-label": "Attachment upload progress", "data-component": "attachment-upload-progress", sx: {
|
|
84
|
+
bottom: 0,
|
|
85
|
+
height: 2,
|
|
86
|
+
left: 0,
|
|
87
|
+
position: "absolute",
|
|
88
|
+
right: 0,
|
|
89
|
+
} })) : null] }), attachments.length ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { "aria-hidden": true, sx: {
|
|
90
|
+
borderTop: 1,
|
|
91
|
+
borderColor: colors.divider,
|
|
92
|
+
mx: "10%",
|
|
93
|
+
} }), (0, jsx_runtime_1.jsx)(material_1.Stack, { sx: {
|
|
94
|
+
borderBottom: 1,
|
|
95
|
+
borderColor: colors.divider,
|
|
96
|
+
py: 0.5,
|
|
97
|
+
}, children: attachments.map((attachment) => ((0, jsx_runtime_1.jsx)(material_1.Box, { children: renderFile(attachment, handlePreviewAttachment) }, attachment.id))) })] })) : null, uploadError ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", sx: { fontSize: 12, px: 1.5, py: 0.75 }, children: uploadError })) : null, renderViewer(previewAttachment, () => setPreviewAttachment(null))] }));
|
|
98
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { LoadFile, UploadFile } from "@bayonai/file-uploads";
|
|
2
|
+
type FileViewerProps<T extends UploadFile> = {
|
|
3
|
+
attachment: T | null;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
loadFile: LoadFile<T>;
|
|
6
|
+
onDownload: (file: T) => Promise<void>;
|
|
7
|
+
};
|
|
8
|
+
export declare function FileViewer<T extends UploadFile>(props: FileViewerProps<T>): import("react").JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.FileViewer = FileViewer;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const CloseRounded_1 = __importDefault(require("@mui/icons-material/CloseRounded"));
|
|
11
|
+
const DownloadRounded_1 = __importDefault(require("@mui/icons-material/DownloadRounded"));
|
|
12
|
+
const material_1 = require("@mui/material");
|
|
13
|
+
const react_2 = require("react");
|
|
14
|
+
const headerActionSx = { width: 44, height: 44, flexShrink: 0 };
|
|
15
|
+
const rasterImageTypes = new Set([
|
|
16
|
+
"image/jpeg",
|
|
17
|
+
"image/png",
|
|
18
|
+
"image/gif",
|
|
19
|
+
"image/webp",
|
|
20
|
+
]);
|
|
21
|
+
function getPreviewKind(contentType) {
|
|
22
|
+
if (rasterImageTypes.has(contentType))
|
|
23
|
+
return "image";
|
|
24
|
+
if (contentType === "application/pdf")
|
|
25
|
+
return "pdf";
|
|
26
|
+
if (contentType.startsWith("text/") || contentType === "application/json") {
|
|
27
|
+
return "text";
|
|
28
|
+
}
|
|
29
|
+
if (contentType.startsWith("audio/"))
|
|
30
|
+
return "audio";
|
|
31
|
+
if (contentType.startsWith("video/"))
|
|
32
|
+
return "video";
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function FileViewer(props) {
|
|
36
|
+
const { attachment } = props;
|
|
37
|
+
const fileKey = attachment
|
|
38
|
+
? `${attachment.id}/${attachment.blobUrl}`
|
|
39
|
+
: "closed";
|
|
40
|
+
// Product decision: file-specific loading and error state belongs to the
|
|
41
|
+
// viewer. Consumers may replace the selected file without coordinating a
|
|
42
|
+
// React key or clearing state from the previous selection.
|
|
43
|
+
return (0, react_1.createElement)(FileViewerState, { ...props, key: fileKey });
|
|
44
|
+
}
|
|
45
|
+
function FileViewerState({ attachment, onClose, loadFile, onDownload, }) {
|
|
46
|
+
const titleId = (0, react_2.useId)();
|
|
47
|
+
const [downloadError, setDownloadError] = (0, react_2.useState)(null);
|
|
48
|
+
const [downloading, setDownloading] = (0, react_2.useState)(false);
|
|
49
|
+
async function download() {
|
|
50
|
+
if (!attachment || downloading)
|
|
51
|
+
return;
|
|
52
|
+
setDownloading(true);
|
|
53
|
+
setDownloadError(null);
|
|
54
|
+
try {
|
|
55
|
+
await onDownload(attachment);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error("[FileViewer] Download failed.", {
|
|
59
|
+
fileId: attachment.id,
|
|
60
|
+
error,
|
|
61
|
+
});
|
|
62
|
+
setDownloadError("Could not download this file. Check your connection and try downloading again.");
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
setDownloading(false);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const previewKind = attachment
|
|
69
|
+
? getPreviewKind(attachment.contentType)
|
|
70
|
+
: null;
|
|
71
|
+
// Product decision: give previews more width while retaining the existing
|
|
72
|
+
// media height limits. Keep Download and Close in reading order above the file.
|
|
73
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Dialog, { "aria-labelledby": titleId, fullWidth: true, maxWidth: "xl", onClose: onClose, open: Boolean(attachment), slotProps: {
|
|
74
|
+
paper: {
|
|
75
|
+
sx: {
|
|
76
|
+
width: { xs: "calc(100% - 16px)", sm: "calc(100% - 64px)" },
|
|
77
|
+
mx: { xs: 1, sm: 4 },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
}, children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, { component: "div", id: `${titleId}-header`, sx: {
|
|
81
|
+
alignItems: "center",
|
|
82
|
+
display: "flex",
|
|
83
|
+
gap: 0.5,
|
|
84
|
+
py: 1,
|
|
85
|
+
pl: { xs: 2, sm: 3 },
|
|
86
|
+
pr: 1,
|
|
87
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", dir: "auto", id: titleId, noWrap: true, sx: { flex: 1, minWidth: 0, textAlign: "start" }, variant: "h6", children: attachment === null || attachment === void 0 ? void 0 : attachment.fileName }), attachment ? ((0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": "Download attachment", disabled: downloading, onClick: () => void download(), sx: headerActionSx, children: (0, jsx_runtime_1.jsx)(DownloadRounded_1.default, {}) })) : null, (0, jsx_runtime_1.jsx)(material_1.IconButton, { "aria-label": "Close attachment preview", onClick: onClose, sx: headerActionSx, children: (0, jsx_runtime_1.jsx)(CloseRounded_1.default, {}) })] }), (0, jsx_runtime_1.jsxs)(material_1.DialogContent, { dividers: true, sx: { borderBottom: 0, minHeight: 240, px: { xs: 1, sm: 2 }, pb: 1.5 }, children: [attachment ? ((0, jsx_runtime_1.jsx)(AttachmentViewerContent, { attachment: attachment, loadFile: loadFile, previewKind: previewKind })) : null, downloadError ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { role: "alert", color: "error", sx: { mt: 1 }, children: downloadError })) : null] })] }));
|
|
88
|
+
}
|
|
89
|
+
function AttachmentViewerContent({ attachment, previewKind, loadFile, }) {
|
|
90
|
+
if (!previewKind) {
|
|
91
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "text.secondary", children: "This file type can\u2019t be displayed here. Download it to open it in a compatible app." }));
|
|
92
|
+
}
|
|
93
|
+
return ((0, jsx_runtime_1.jsx)(LoadableAttachmentPreview, { attachment: attachment, previewKind: previewKind, loadFile: loadFile }));
|
|
94
|
+
}
|
|
95
|
+
function LoadableAttachmentPreview({ attachment, previewKind, loadFile, }) {
|
|
96
|
+
const [attempt, setAttempt] = (0, react_2.useState)();
|
|
97
|
+
// A replacement loader starts a fresh attempt even for the same attachment.
|
|
98
|
+
const preview = (attempt === null || attempt === void 0 ? void 0 : attempt.attachment) === attachment && attempt.loadFile === loadFile
|
|
99
|
+
? attempt.result
|
|
100
|
+
: undefined;
|
|
101
|
+
const previewUrl = (preview === null || preview === void 0 ? void 0 : preview.kind) === "url" ? preview.value : undefined;
|
|
102
|
+
function handleMediaDecodeError() {
|
|
103
|
+
console.error("[FileViewer] Browser could not decode the file preview.", {
|
|
104
|
+
contentType: attachment.contentType,
|
|
105
|
+
fileId: attachment.id,
|
|
106
|
+
previewKind,
|
|
107
|
+
});
|
|
108
|
+
setAttempt({ attachment, loadFile, result: { kind: "error" } });
|
|
109
|
+
}
|
|
110
|
+
(0, react_2.useEffect)(() => {
|
|
111
|
+
let objectUrl = null;
|
|
112
|
+
const controller = new AbortController();
|
|
113
|
+
const { signal } = controller;
|
|
114
|
+
const publish = (result) => {
|
|
115
|
+
if (!signal.aborted)
|
|
116
|
+
setAttempt({ attachment, loadFile, result });
|
|
117
|
+
};
|
|
118
|
+
void (async () => {
|
|
119
|
+
try {
|
|
120
|
+
const blob = attachment.blobUrl.startsWith("blob:")
|
|
121
|
+
? await fetch(attachment.blobUrl, { signal }).then((response) => {
|
|
122
|
+
if (!response.ok)
|
|
123
|
+
throw new Error("Local attachment blob is unavailable.");
|
|
124
|
+
return response.blob();
|
|
125
|
+
})
|
|
126
|
+
: await loadFile(attachment, signal);
|
|
127
|
+
if (signal.aborted)
|
|
128
|
+
return;
|
|
129
|
+
if (previewKind === "text") {
|
|
130
|
+
const content = await blob.text();
|
|
131
|
+
publish({ kind: "text", value: content });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
objectUrl = attachment.blobUrl.startsWith("blob:")
|
|
135
|
+
? attachment.blobUrl
|
|
136
|
+
: URL.createObjectURL(new Blob([blob], { type: attachment.contentType }));
|
|
137
|
+
publish({ kind: "url", value: objectUrl });
|
|
138
|
+
}
|
|
139
|
+
catch (caughtError) {
|
|
140
|
+
if (!signal.aborted) {
|
|
141
|
+
console.error("[FileViewer] Unable to load the file preview.", {
|
|
142
|
+
contentType: attachment.contentType,
|
|
143
|
+
error: caughtError,
|
|
144
|
+
fileId: attachment.id,
|
|
145
|
+
});
|
|
146
|
+
publish({ kind: "error" });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
})();
|
|
150
|
+
return () => {
|
|
151
|
+
controller.abort();
|
|
152
|
+
if (objectUrl && !attachment.blobUrl.startsWith("blob:")) {
|
|
153
|
+
URL.revokeObjectURL(objectUrl);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}, [attachment, previewKind, loadFile]);
|
|
157
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !preview ? ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { display: "grid", minHeight: 200, placeItems: "center" }, children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { "aria-label": "Loading attachment preview" }) })) : preview.kind === "error" ? ((0, jsx_runtime_1.jsx)(material_1.Typography, { color: "error", role: "alert", children: "Unable to display this file. You can download it instead." })) : previewKind === "image" ? ((0, jsx_runtime_1.jsx)(material_1.Box, { alt: attachment.fileName, component: "img", onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: {
|
|
158
|
+
display: "block",
|
|
159
|
+
maxHeight: "65vh",
|
|
160
|
+
maxWidth: "100%",
|
|
161
|
+
mx: "auto",
|
|
162
|
+
} })) : previewKind === "pdf" ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "iframe", referrerPolicy: "no-referrer",
|
|
163
|
+
// Product decision: PDFs are collaborator-controlled active-format
|
|
164
|
+
// documents. Keep their browsing context opaque and block scripts,
|
|
165
|
+
// forms, popups and top-level navigation while retaining preview.
|
|
166
|
+
sandbox: "", src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, title: "Attachment preview", sx: { border: 0, height: "65vh", width: "100%" } })) : previewKind === "text" ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "pre", sx: {
|
|
167
|
+
fontFamily: "monospace",
|
|
168
|
+
fontSize: 13,
|
|
169
|
+
m: 0,
|
|
170
|
+
overflow: "auto",
|
|
171
|
+
whiteSpace: "pre-wrap",
|
|
172
|
+
}, children: preview.kind === "text" ? preview.value : undefined })) : previewKind === "audio" ? ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "audio", controls: true, onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: { width: "100%" } })) : ((0, jsx_runtime_1.jsx)(material_1.Box, { component: "video", controls: true, onError: handleMediaDecodeError, src: previewUrl !== null && previewUrl !== void 0 ? previewUrl : undefined, sx: { maxHeight: "65vh", maxWidth: "100%", width: "100%" } })) }));
|
|
173
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ImageCrop } from "@bayonai/file-uploads";
|
|
2
|
+
export type ImageCropLabels = {
|
|
3
|
+
title: string;
|
|
4
|
+
close: string;
|
|
5
|
+
preview: string;
|
|
6
|
+
confirm: string;
|
|
7
|
+
opening: string;
|
|
8
|
+
instruction: string;
|
|
9
|
+
zoom: string;
|
|
10
|
+
horizontal: string;
|
|
11
|
+
vertical: string;
|
|
12
|
+
decodeError: string;
|
|
13
|
+
previewError: string;
|
|
14
|
+
};
|
|
15
|
+
export type ImageCropDialogProps = {
|
|
16
|
+
file: File;
|
|
17
|
+
busy: boolean;
|
|
18
|
+
error: string | null;
|
|
19
|
+
onClose: () => void;
|
|
20
|
+
onConfirm: (crop: ImageCrop) => Promise<void>;
|
|
21
|
+
labels?: Partial<ImageCropLabels>;
|
|
22
|
+
previewShape?: "circle" | "square";
|
|
23
|
+
previewWidth?: string | number;
|
|
24
|
+
};
|
|
25
|
+
/** Emits orientation-correct decoded-pixel coordinates; the host persists them. */
|
|
26
|
+
export declare function ImageCropDialog({ file, busy, error, onClose, onConfirm, labels, previewShape, previewWidth, }: ImageCropDialogProps): import("react").JSX.Element;
|