@bayonai/mui-design 1.0.0 → 1.2.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.
- package/CHANGELOG.md +55 -0
- package/README.md +124 -7
- package/dist/cjs/actions/ActionMenu.js +36 -0
- package/dist/cjs/actions/DialogActionButtons.js +33 -0
- package/dist/cjs/actions/LoadingIconButton.js +10 -0
- package/dist/cjs/actions/StickyActionFooter.js +27 -0
- package/dist/cjs/actions/StickySubmitButton.js +10 -0
- package/dist/cjs/actions/index.js +18 -0
- package/dist/cjs/drawers/BottomDrawer.js +43 -0
- package/dist/cjs/drawers/MobileBottomDrawer.js +102 -0
- package/dist/cjs/drawers/MobileBottomDrawerHeader.js +36 -0
- package/dist/cjs/drawers/ResponsiveDrawer.js +22 -0
- package/dist/cjs/drawers/drawerAppearance.js +10 -0
- package/dist/cjs/drawers/index.js +17 -0
- package/dist/cjs/drawers/useVisualViewportBottomInset.js +33 -0
- package/dist/cjs/feedback/StatusNotice.js +62 -0
- package/dist/cjs/feedback/index.js +7 -0
- package/dist/cjs/links/LinkAddressPreview.js +80 -0
- package/dist/cjs/links/index.js +9 -0
- package/dist/cjs/links/useLinkAddressPreview.js +152 -0
- package/dist/cjs/pending/PendingChangesDialogShell.js +16 -0
- package/dist/cjs/pending/PendingChangesDialogView.js +130 -0
- package/dist/cjs/pending/PendingChangesIndicatorView.js +27 -0
- package/dist/cjs/pending/index.js +9 -0
- package/dist/cjs/pending/types.js +2 -0
- package/dist/cjs/pricing/PricingTable.js +58 -0
- package/dist/cjs/pricing/index.js +6 -0
- package/dist/cjs/providers/BayonThemeProvider.js +51 -11
- package/dist/cjs/sections/ExpandableSectionToggle.js +32 -0
- package/dist/cjs/sections/index.js +7 -0
- package/dist/cjs/swipe/SwipeActionRow.js +123 -0
- package/dist/cjs/swipe/index.js +8 -0
- package/dist/cjs/toasts/ActionToast.js +12 -0
- package/dist/cjs/toasts/Toast.js +55 -0
- package/dist/cjs/toasts/index.js +12 -0
- package/dist/cjs/toasts/useUpwardToastDismiss.js +73 -0
- package/dist/cjs/uploads/CameraCaptureDialog.js +187 -0
- package/dist/cjs/uploads/FileRow.js +23 -0
- package/dist/cjs/uploads/FileSwipeActionRow.js +11 -0
- package/dist/cjs/uploads/FileThumbnail.js +104 -0
- package/dist/cjs/uploads/FileUpload.js +98 -0
- package/dist/cjs/uploads/FileViewer.js +151 -0
- package/dist/cjs/uploads/ImageCropDialog.js +215 -0
- package/dist/cjs/uploads/UploadProgressRing.js +32 -0
- package/dist/cjs/uploads/cameraCropPresentation.js +12 -0
- package/dist/cjs/uploads/index.js +20 -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/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/drawerAppearance.js +7 -0
- package/dist/esm/drawers/index.js +7 -0
- package/dist/esm/drawers/useVisualViewportBottomInset.js +29 -0
- package/dist/esm/feedback/StatusNotice.js +56 -0
- package/dist/esm/feedback/index.js +3 -0
- package/dist/esm/links/LinkAddressPreview.js +74 -0
- package/dist/esm/links/index.js +4 -0
- package/dist/esm/links/useLinkAddressPreview.js +149 -0
- package/dist/esm/pending/PendingChangesDialogShell.js +10 -0
- package/dist/esm/pending/PendingChangesDialogView.js +124 -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/PricingTable.js +52 -0
- package/dist/esm/pricing/index.js +2 -0
- package/dist/esm/providers/BayonThemeProvider.js +51 -11
- package/dist/esm/sections/ExpandableSectionToggle.js +26 -0
- package/dist/esm/sections/index.js +3 -0
- package/dist/esm/swipe/SwipeActionRow.js +116 -0
- package/dist/esm/swipe/index.js +3 -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 +145 -0
- package/dist/esm/uploads/ImageCropDialog.js +212 -0
- package/dist/esm/uploads/UploadProgressRing.js +29 -0
- package/dist/esm/uploads/cameraCropPresentation.js +5 -0
- package/dist/esm/uploads/index.js +9 -0
- package/dist/types/actions/ActionMenu.d.ts +24 -0
- package/dist/types/actions/DialogActionButtons.d.ts +22 -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/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/drawerAppearance.d.ts +8 -0
- package/dist/types/drawers/index.d.ts +6 -0
- package/dist/types/drawers/useVisualViewportBottomInset.d.ts +6 -0
- package/dist/types/feedback/StatusNotice.d.ts +13 -0
- package/dist/types/feedback/index.d.ts +1 -0
- package/dist/types/links/LinkAddressPreview.d.ts +19 -0
- package/dist/types/links/index.d.ts +3 -0
- package/dist/types/links/useLinkAddressPreview.d.ts +24 -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 +53 -0
- package/dist/types/pricing/PricingTable.d.ts +25 -0
- package/dist/types/pricing/index.d.ts +2 -0
- package/dist/types/sections/ExpandableSectionToggle.d.ts +12 -0
- package/dist/types/sections/index.d.ts +2 -0
- package/dist/types/swipe/SwipeActionRow.d.ts +8 -0
- package/dist/types/swipe/index.d.ts +1 -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/UploadProgressRing.d.ts +24 -0
- package/dist/types/uploads/cameraCropPresentation.d.ts +2 -0
- package/dist/types/uploads/index.d.ts +10 -0
- package/docs/camera-crop-contract.md +50 -0
- package/docs/pending-contract.md +11 -0
- package/docs/uploads-contract.md +40 -0
- package/package.json +115 -48
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import MoreHorizIcon from "@mui/icons-material/MoreHoriz";
|
|
4
|
+
import { Box, ListItemIcon, ListSubheader, Menu, MenuItem, Tooltip, } from "@mui/material";
|
|
5
|
+
import { Fragment, useId, useState } from "react";
|
|
6
|
+
import { LoadingIconButton } from "./LoadingIconButton.js";
|
|
7
|
+
/** A compact, grouped action menu with an optional in-flight trigger state. */
|
|
8
|
+
export function ActionMenu({ actionColorSx, actions, buttonSx, containerSx, disabled = false, label = "Actions", loading = false, loadingLabel = `${label} loading`, size = "small", }) {
|
|
9
|
+
const menuId = useId();
|
|
10
|
+
const [anchorElement, setAnchorElement] = useState(null);
|
|
11
|
+
const open = Boolean(anchorElement);
|
|
12
|
+
function handleAction(action) {
|
|
13
|
+
setAnchorElement(null);
|
|
14
|
+
action.onClick();
|
|
15
|
+
}
|
|
16
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: loading ? loadingLabel : label, children: _jsx(Box, { component: "span", sx: containerSx, children: _jsx(LoadingIconButton, { "aria-controls": open ? menuId : undefined, "aria-expanded": open ? "true" : undefined, "aria-haspopup": "menu", "aria-label": label, disabled: disabled, loading: loading, loadingLabel: loadingLabel, onClick: (event) => setAnchorElement(event.currentTarget), size: size, sx: buttonSx, children: _jsx(MoreHorizIcon, { fontSize: size === "large" ? "medium" : "small" }) }) }) }), _jsx(Menu, { anchorEl: anchorElement, anchorOrigin: { horizontal: "right", vertical: "bottom" }, disableScrollLock: true, id: menuId, onClose: () => setAnchorElement(null), open: open, transformOrigin: { horizontal: "right", vertical: "top" }, children: actions.map((action, index) => {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
return (_jsxs(Fragment, { children: [action.section &&
|
|
19
|
+
action.section !== ((_a = actions[index - 1]) === null || _a === void 0 ? void 0 : _a.section) ? (_jsx(ListSubheader, { children: action.section })) : null, _jsxs(MenuItem, { disabled: action.disabled, onClick: () => handleAction(action), sx: (_c = actionColorSx === null || actionColorSx === void 0 ? void 0 : actionColorSx[(_b = action.color) !== null && _b !== void 0 ? _b : "default"]) !== null && _c !== void 0 ? _c : getDefaultActionColorSx(action.color), children: [action.icon ? _jsx(ListItemIcon, { children: action.icon }) : null, action.label] })] }, `${(_d = action.section) !== null && _d !== void 0 ? _d : "default"}:${action.label}`));
|
|
20
|
+
}) })] }));
|
|
21
|
+
}
|
|
22
|
+
function getDefaultActionColorSx(color) {
|
|
23
|
+
if (color === "primary")
|
|
24
|
+
return { color: "primary.main" };
|
|
25
|
+
if (color === "secondary")
|
|
26
|
+
return { color: "secondary.main" };
|
|
27
|
+
if (color === "error")
|
|
28
|
+
return { color: "error.main" };
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import CheckIcon from "@mui/icons-material/Check";
|
|
4
|
+
import CloseIcon from "@mui/icons-material/Close";
|
|
5
|
+
import { CircularProgress, DialogActions, IconButton, Stack, Tooltip, } from "@mui/material";
|
|
6
|
+
// Product decision: concise decisions/info fit content above a readable 320px floor.
|
|
7
|
+
// Keep MUI's readable maxWidth/viewport cap; forms and previews own their sizing.
|
|
8
|
+
export const compactDialogPaperSx = {
|
|
9
|
+
width: "fit-content",
|
|
10
|
+
// Preserve MUI's 32px margins even when the viewport is narrower than the floor.
|
|
11
|
+
minWidth: "min(320px, calc(100% - 64px))",
|
|
12
|
+
overflowWrap: "anywhere",
|
|
13
|
+
};
|
|
14
|
+
/** Keeps the modal's primary decision compact and explicitly labelled. */
|
|
15
|
+
export function DialogActionButtons({ confirmColor = "success", confirmDisabled = false, confirmIcon, confirmLabel, confirmType = "button", onConfirm, sx, }) {
|
|
16
|
+
return (_jsx(DialogActions, { sx: sx, children: _jsx(Stack, { direction: "row", spacing: 1, children: _jsx(Tooltip, { title: confirmLabel, children: _jsx("span", { children: _jsx(IconButton, { "aria-label": confirmLabel, color: confirmColor, disabled: confirmDisabled, onClick: confirmType === "submit" ? undefined : onConfirm, type: confirmType, children: confirmIcon !== null && confirmIcon !== void 0 ? confirmIcon : _jsx(CheckIcon, {}) }) }) }) }) }));
|
|
17
|
+
}
|
|
18
|
+
export function DialogActionProgress() {
|
|
19
|
+
return _jsx(CircularProgress, { color: "inherit", size: 20 });
|
|
20
|
+
}
|
|
21
|
+
export function DialogCloseButton({ disabled = false, label = "Close", onClose, sx, }) {
|
|
22
|
+
// Product decision: dismissible dialogs have one close action in the title's top-right corner.
|
|
23
|
+
return (_jsx(Stack, { sx: { position: "absolute", right: 16, top: 16, ...sx }, children: _jsx(Tooltip, { title: label, children: _jsx("span", { children: _jsx(IconButton, { "aria-label": label, disabled: disabled, onClick: onClose, size: "small", type: "button", children: _jsx(CloseIcon, { fontSize: "small" }) }) }) }) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { CircularProgress, IconButton, } from "@mui/material";
|
|
4
|
+
/** Keeps an icon action's footprint while making an in-flight request visible. */
|
|
5
|
+
export function LoadingIconButton({ "aria-label": ariaLabel, children, disabled, loading = false, loadingLabel, spinnerSize = 20, ...props }) {
|
|
6
|
+
return (_jsx(IconButton, { ...props, "aria-busy": loading || undefined, "aria-label": loading ? loadingLabel : ariaLabel, disabled: disabled || loading, children: loading ? (_jsx(CircularProgress, { "aria-label": loadingLabel, color: "inherit", size: spinnerSize })) : (children) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Box } from "@mui/material";
|
|
4
|
+
/**
|
|
5
|
+
* Keeps the final actions of a long, scrollable form in view.
|
|
6
|
+
*
|
|
7
|
+
* Product decision: this component owns local sticky positioning and neutral
|
|
8
|
+
* footer chrome only. The host owns its scroll container, any edge-to-edge
|
|
9
|
+
* bleed required by a padded surface, action layout, and form submission.
|
|
10
|
+
*/
|
|
11
|
+
export function StickyActionFooter({ children, sx }) {
|
|
12
|
+
return (_jsx(Box, { component: "footer", "data-component": "sticky-action-footer", sx: {
|
|
13
|
+
backgroundColor: "background.paper",
|
|
14
|
+
borderColor: "divider",
|
|
15
|
+
borderTop: 1,
|
|
16
|
+
bottom: 0,
|
|
17
|
+
mt: 1,
|
|
18
|
+
p: 2,
|
|
19
|
+
position: "sticky",
|
|
20
|
+
// Local stacking keeps the footer above fields without escaping its form.
|
|
21
|
+
zIndex: 1,
|
|
22
|
+
...sx,
|
|
23
|
+
}, children: children }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Button, } from "@mui/material";
|
|
4
|
+
import { StickyActionFooter } from "./StickyActionFooter.js";
|
|
5
|
+
export function StickySubmitButton({ buttonSx, disabled = false, footerSx, label = "Save", loading = false, variant = "contained", }) {
|
|
6
|
+
return (_jsx(StickyActionFooter, { sx: footerSx, children: _jsx(Button, { color: "secondary", disabled: disabled, fullWidth: true, loading: loading, sx: { minHeight: 44, ...buttonSx }, type: "submit", variant: variant, children: label }) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// TL-M249: preserve the established MUI presentation under its owning package.
|
|
3
|
+
export { ActionMenu, } from "./ActionMenu.js";
|
|
4
|
+
export { LoadingIconButton, } from "./LoadingIconButton.js";
|
|
5
|
+
export { StickyActionFooter, } from "./StickyActionFooter.js";
|
|
6
|
+
export { StickySubmitButton, } from "./StickySubmitButton.js";
|
|
7
|
+
export { compactDialogPaperSx, DialogActionButtons, DialogActionProgress, DialogCloseButton, } from "./DialogActionButtons.js";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import CloseRoundedIcon from "@mui/icons-material/CloseRounded";
|
|
4
|
+
import { Box, Drawer, IconButton, Tooltip, Typography, } from "@mui/material";
|
|
5
|
+
import { defaultDrawerAppearance, } from "./drawerAppearance.js";
|
|
6
|
+
export function BottomDrawer({ children, appearance = defaultDrawerAppearance, closeTooltip, closeLabel, contentSx, dataComponent, disablePortal = false, headerActions, onClose, open, title, }) {
|
|
7
|
+
const paperSlotProps = {
|
|
8
|
+
"data-component": dataComponent,
|
|
9
|
+
sx: {
|
|
10
|
+
bgcolor: appearance.background,
|
|
11
|
+
borderRadius: "16px 16px 0 0",
|
|
12
|
+
boxShadow: appearance.shadow,
|
|
13
|
+
maxHeight: "calc(100dvh - 24px)",
|
|
14
|
+
width: "100%",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return (_jsxs(Drawer, { anchor: "bottom",
|
|
18
|
+
// Portal ownership belongs to the host because route slots and stacking
|
|
19
|
+
// containers are application concerns rather than drawer presentation.
|
|
20
|
+
ModalProps: { disablePortal }, onClose: onClose, open: open, slotProps: { paper: paperSlotProps }, children: [_jsxs(Box, { sx: {
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
borderBottom: 1,
|
|
23
|
+
borderColor: "divider",
|
|
24
|
+
display: "flex",
|
|
25
|
+
flex: "0 0 auto",
|
|
26
|
+
gap: 1,
|
|
27
|
+
minHeight: 64,
|
|
28
|
+
px: 2.5,
|
|
29
|
+
}, children: [_jsx(Typography, { component: "h1", sx: { flex: 1, fontWeight: 760 }, children: title }), headerActions ? (_jsx(Box, { sx: { alignItems: "center", display: "flex" }, children: headerActions })) : null, _jsx(Tooltip, { title: closeTooltip !== null && closeTooltip !== void 0 ? closeTooltip : "", children: _jsx(IconButton, { "aria-label": closeLabel, onClick: onClose, sx: {
|
|
30
|
+
minHeight: 40,
|
|
31
|
+
minWidth: 40,
|
|
32
|
+
"& > .MuiSvgIcon-root": { fontSize: 28 },
|
|
33
|
+
}, children: _jsx(CloseRoundedIcon, {}) }) })] }), _jsx(Box, { sx: [
|
|
34
|
+
{ flex: 1, minHeight: 0, overflowY: "auto" },
|
|
35
|
+
...(Array.isArray(contentSx) ? contentSx : [contentSx]),
|
|
36
|
+
], children: children })] }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Box } from "@mui/material";
|
|
4
|
+
import SwipeableDrawer from "@mui/material/SwipeableDrawer";
|
|
5
|
+
import { useCallback, useEffect, useRef, useState, } from "react";
|
|
6
|
+
import { defaultDrawerAppearance, } from "./drawerAppearance.js";
|
|
7
|
+
import { MobileBottomDrawerHeader } from "./MobileBottomDrawerHeader.js";
|
|
8
|
+
export const mobileBottomDrawerDismissDuration = 220;
|
|
9
|
+
export function MobileBottomDrawer({ ariaLabel, appearance = defaultDrawerAppearance, closeTooltip, children, contentScrollMode = "container", dataComponent, dismiss = false, handleBackground = "default", handlePlacement = "above-content", headerLeft, headerRight, maxHeight = "calc(100dvh - 24px)", onClose, }) {
|
|
10
|
+
const dismissTimer = useRef(null);
|
|
11
|
+
const [open, setOpen] = useState(true);
|
|
12
|
+
useEffect(() => () => {
|
|
13
|
+
if (dismissTimer.current) {
|
|
14
|
+
clearTimeout(dismissTimer.current);
|
|
15
|
+
}
|
|
16
|
+
}, []);
|
|
17
|
+
const requestClose = useCallback(() => {
|
|
18
|
+
if (!open || dismissTimer.current) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
setOpen(false);
|
|
22
|
+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
23
|
+
dismissTimer.current = setTimeout(onClose, prefersReducedMotion ? 0 : mobileBottomDrawerDismissDuration);
|
|
24
|
+
}, [onClose, open]);
|
|
25
|
+
// Product decision: nested dialogs may layer over a retained drawer; the host
|
|
26
|
+
// decides whether closing that dialog also closes its underlying context.
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (!dismiss || !open) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
32
|
+
dismissTimer.current = setTimeout(onClose, prefersReducedMotion ? 0 : mobileBottomDrawerDismissDuration);
|
|
33
|
+
return () => {
|
|
34
|
+
if (dismissTimer.current) {
|
|
35
|
+
clearTimeout(dismissTimer.current);
|
|
36
|
+
dismissTimer.current = null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}, [dismiss, onClose, open]);
|
|
40
|
+
const paperSlotProps = {
|
|
41
|
+
"aria-label": ariaLabel,
|
|
42
|
+
"data-component": dataComponent !== null && dataComponent !== void 0 ? dataComponent : "mobile-bottom-drawer",
|
|
43
|
+
sx: {
|
|
44
|
+
backgroundColor: appearance.background,
|
|
45
|
+
borderRadius: "16px 16px 0 0",
|
|
46
|
+
bottom: 0,
|
|
47
|
+
boxShadow: appearance.shadow,
|
|
48
|
+
display: "flex",
|
|
49
|
+
flexDirection: "column",
|
|
50
|
+
height: maxHeight,
|
|
51
|
+
maxHeight,
|
|
52
|
+
overflow: "hidden",
|
|
53
|
+
overscrollBehaviorY: "contain",
|
|
54
|
+
width: "100%",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
const drawerHandle = (_jsx(Box, { "aria-hidden": true, "data-component": "mobile-bottom-drawer-handle", "data-placement": handlePlacement, "data-swipe-surface": "drawer", sx: {
|
|
58
|
+
alignItems: "center",
|
|
59
|
+
bgcolor: handleBackground === "detailChrome"
|
|
60
|
+
? appearance.chrome
|
|
61
|
+
: "transparent",
|
|
62
|
+
display: "flex",
|
|
63
|
+
flex: "0 0 auto",
|
|
64
|
+
justifyContent: "center",
|
|
65
|
+
minHeight: 44,
|
|
66
|
+
// Product decision: header actions sit above this visual handle while
|
|
67
|
+
// MUI SwipeableDrawer owns a natural pull-down gesture across the
|
|
68
|
+
// entire sheet, including its scroll-aware cancellation behavior.
|
|
69
|
+
pointerEvents: handlePlacement === "overlay" ? "none" : "auto",
|
|
70
|
+
position: handlePlacement === "overlay" ? "absolute" : "relative",
|
|
71
|
+
top: handlePlacement === "overlay" ? 0 : "auto",
|
|
72
|
+
width: "100%",
|
|
73
|
+
zIndex: 0,
|
|
74
|
+
}, children: _jsx(Box, { sx: {
|
|
75
|
+
bgcolor: appearance.handle,
|
|
76
|
+
borderRadius: 999,
|
|
77
|
+
height: 4,
|
|
78
|
+
width: 36,
|
|
79
|
+
} }) }));
|
|
80
|
+
return (_jsxs(SwipeableDrawer, { anchor: "bottom", disableBackdropTransition: true, disableDiscovery: true, disableSwipeToOpen: true, hysteresis: 0.16, onClose: requestClose, onOpen: () => undefined, open: dismiss ? false : open, slotProps: {
|
|
81
|
+
backdrop: {
|
|
82
|
+
sx: { backgroundColor: "transparent" },
|
|
83
|
+
},
|
|
84
|
+
paper: paperSlotProps,
|
|
85
|
+
}, transitionDuration: mobileBottomDrawerDismissDuration, children: [headerLeft ? (_jsx(MobileBottomDrawerHeader, { closeLabel: `Close ${ariaLabel}`, closeTooltip: closeTooltip, dragHandle: drawerHandle, left: headerLeft, onClose: requestClose, right: headerRight })) : handlePlacement === "above-content" ? (drawerHandle) : null, _jsxs(Box, { "data-component": "mobile-bottom-drawer-scroll", sx: {
|
|
86
|
+
display: contentScrollMode === "child" ? "flex" : "block",
|
|
87
|
+
flex: 1,
|
|
88
|
+
minHeight: 0,
|
|
89
|
+
overflowY: contentScrollMode === "child" ? "hidden" : "auto",
|
|
90
|
+
overscrollBehaviorY: "contain",
|
|
91
|
+
pb: appearance.safeAreaBottom,
|
|
92
|
+
position: "relative",
|
|
93
|
+
zIndex: handlePlacement === "overlay" ? 1 : "auto",
|
|
94
|
+
}, children: [handlePlacement === "overlay" ? drawerHandle : null, children] })] }));
|
|
95
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import CloseRoundedIcon from "@mui/icons-material/CloseRounded";
|
|
4
|
+
import { Box, IconButton, Tooltip } from "@mui/material";
|
|
5
|
+
export function MobileBottomDrawerHeader({ closeLabel, closeTooltip, dragHandle, left, onClose, right, }) {
|
|
6
|
+
return (_jsxs(Box, { component: "header", "data-component": "mobile-bottom-drawer-header", sx: {
|
|
7
|
+
flex: "0 0 auto",
|
|
8
|
+
minHeight: 56,
|
|
9
|
+
position: "relative",
|
|
10
|
+
}, children: [_jsx(Box, { sx: {
|
|
11
|
+
inset: 0,
|
|
12
|
+
position: "absolute",
|
|
13
|
+
zIndex: 0,
|
|
14
|
+
}, children: dragHandle }), _jsxs(Box, { sx: {
|
|
15
|
+
alignItems: "center",
|
|
16
|
+
display: "flex",
|
|
17
|
+
gap: 1,
|
|
18
|
+
minHeight: 56,
|
|
19
|
+
px: 2,
|
|
20
|
+
// Product decision: title and actions occupy the same compact row as
|
|
21
|
+
// the drag affordance, avoiding a second band that pushes context
|
|
22
|
+
// away from the top edge of the drawer.
|
|
23
|
+
position: "relative",
|
|
24
|
+
zIndex: 1,
|
|
25
|
+
}, children: [_jsx(Box, { sx: { flex: 1, minWidth: 0 }, children: left }), _jsxs(Box, { sx: { alignItems: "center", display: "flex", gap: 0.5 }, children: [right, _jsx(Tooltip, { title: closeTooltip !== null && closeTooltip !== void 0 ? closeTooltip : "", children: _jsx(IconButton, { "aria-label": closeLabel, onClick: onClose, sx: {
|
|
26
|
+
minHeight: 48,
|
|
27
|
+
minWidth: 48,
|
|
28
|
+
"& > .MuiSvgIcon-root": { fontSize: 32 },
|
|
29
|
+
}, children: _jsx(CloseRoundedIcon, {}) }) })] })] })] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { Typography, useMediaQuery } from "@mui/material";
|
|
4
|
+
import { MobileBottomDrawer } from "./MobileBottomDrawer.js";
|
|
5
|
+
import { BottomDrawer } from "./BottomDrawer.js";
|
|
6
|
+
// Product decision: consumers share responsive drawer chrome but keep
|
|
7
|
+
// navigation and dismissal policies in their owning feature.
|
|
8
|
+
export function ResponsiveDrawer({ ariaLabel, appearance, closeTooltip, children, desktopContentSx, desktopCloseLabel, desktopDataComponent, desktopDisablePortal = false, desktopOpen = true, headerActions, mobileContentScrollMode, mobileDataComponent, mobileDismiss = false, mobileOpen = true, onDesktopClose, onMobileClose, title, }) {
|
|
9
|
+
const isMobileDrawer = useMediaQuery("(max-width:899.95px)", {
|
|
10
|
+
noSsr: true,
|
|
11
|
+
});
|
|
12
|
+
if (isMobileDrawer) {
|
|
13
|
+
if (!mobileOpen) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return (_jsx(MobileBottomDrawer, { appearance: appearance, closeTooltip: closeTooltip, ariaLabel: ariaLabel, contentScrollMode: mobileContentScrollMode, dataComponent: mobileDataComponent, dismiss: mobileDismiss, headerLeft: _jsx(Typography, { component: "h1", sx: { fontWeight: 760 }, children: title }), headerRight: headerActions, onClose: onMobileClose, children: children("mobile") }));
|
|
17
|
+
}
|
|
18
|
+
return (_jsx(BottomDrawer, { appearance: appearance, closeTooltip: closeTooltip, closeLabel: desktopCloseLabel !== null && desktopCloseLabel !== void 0 ? desktopCloseLabel : `Close ${ariaLabel}`, contentSx: desktopContentSx, dataComponent: desktopDataComponent, disablePortal: desktopDisablePortal, headerActions: headerActions, onClose: onDesktopClose, open: desktopOpen, title: title, children: children("desktop") }));
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
// TL-M249: preserve the established MUI presentation under its owning package.
|
|
3
|
+
export { MobileBottomDrawer, mobileBottomDrawerDismissDuration, } from "./MobileBottomDrawer.js";
|
|
4
|
+
export { MobileBottomDrawerHeader } from "./MobileBottomDrawerHeader.js";
|
|
5
|
+
export { BottomDrawer } from "./BottomDrawer.js";
|
|
6
|
+
export { ResponsiveDrawer } from "./ResponsiveDrawer.js";
|
|
7
|
+
export { useVisualViewportBottomInset, getVisualViewportBottomInset, } from "./useVisualViewportBottomInset.js";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
export function getVisualViewportBottomInset({ layoutViewportHeight, visualViewportHeight, visualViewportOffsetTop, }) {
|
|
4
|
+
return Math.max(0, Math.round(layoutViewportHeight - visualViewportHeight - visualViewportOffsetTop));
|
|
5
|
+
}
|
|
6
|
+
export function useVisualViewportBottomInset() {
|
|
7
|
+
const [bottomInset, setBottomInset] = useState(0);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const visualViewport = window.visualViewport;
|
|
10
|
+
if (!visualViewport) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const updateBottomInset = () => {
|
|
14
|
+
setBottomInset(getVisualViewportBottomInset({
|
|
15
|
+
layoutViewportHeight: window.innerHeight,
|
|
16
|
+
visualViewportHeight: visualViewport.height,
|
|
17
|
+
visualViewportOffsetTop: visualViewport.offsetTop,
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
updateBottomInset();
|
|
21
|
+
visualViewport.addEventListener("resize", updateBottomInset);
|
|
22
|
+
visualViewport.addEventListener("scroll", updateBottomInset);
|
|
23
|
+
return () => {
|
|
24
|
+
visualViewport.removeEventListener("resize", updateBottomInset);
|
|
25
|
+
visualViewport.removeEventListener("scroll", updateBottomInset);
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return bottomInset;
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined";
|
|
4
|
+
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
|
5
|
+
import TaskAltOutlinedIcon from "@mui/icons-material/TaskAltOutlined";
|
|
6
|
+
import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined";
|
|
7
|
+
import { Box, Stack, Typography, } from "@mui/material";
|
|
8
|
+
export function StatusNotice({ action, compact = false, dataComponent, message, role, sx, tone = "info", }) {
|
|
9
|
+
const toneConfig = getStatusNoticeTone(tone);
|
|
10
|
+
const Icon = toneConfig.Icon;
|
|
11
|
+
return (_jsxs(Stack, { "data-component": dataComponent, component: compact ? "span" : "div", direction: "row", role: role !== null && role !== void 0 ? role : (tone === "error" ? "status" : undefined), spacing: compact ? 2 : 1.25, sx: [
|
|
12
|
+
{
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
alignSelf: "flex-start",
|
|
15
|
+
borderRadius: 1,
|
|
16
|
+
boxShadow: "0 10px 28px rgba(0, 0, 0, 0.12)",
|
|
17
|
+
maxWidth: "100%",
|
|
18
|
+
minWidth: 0,
|
|
19
|
+
px: compact ? 0 : 1.25,
|
|
20
|
+
py: compact ? 0 : 0.875,
|
|
21
|
+
},
|
|
22
|
+
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
|
|
23
|
+
], children: [_jsx(Box, { "data-status-notice-part": "icon", component: compact ? "span" : "div", sx: {
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
borderRadius: 999,
|
|
26
|
+
color: toneConfig.iconColor,
|
|
27
|
+
display: "flex",
|
|
28
|
+
flex: "0 0 auto",
|
|
29
|
+
height: compact ? 20 : 26,
|
|
30
|
+
justifyContent: "center",
|
|
31
|
+
width: compact ? 20 : 26,
|
|
32
|
+
}, children: _jsx(Icon, { fontSize: compact ? "inherit" : "small" }) }), typeof message === "string" ? (_jsx(Typography, { color: "text.secondary", ...(compact ? { component: "span" } : {}), "data-status-notice-part": "message", sx: {
|
|
33
|
+
fontSize: compact ? "0.75rem" : undefined,
|
|
34
|
+
lineHeight: compact ? 1.35 : 1.55,
|
|
35
|
+
minWidth: 0,
|
|
36
|
+
overflowWrap: "anywhere",
|
|
37
|
+
}, variant: "body2", children: message })) : (_jsx(Box, { "data-status-notice-part": "message", component: compact ? "span" : "div", sx: {
|
|
38
|
+
color: "text.secondary",
|
|
39
|
+
fontSize: compact ? "0.75rem" : undefined,
|
|
40
|
+
lineHeight: compact ? 1.35 : 1.55,
|
|
41
|
+
minWidth: 0,
|
|
42
|
+
overflowWrap: "anywhere",
|
|
43
|
+
}, children: message })), action ? (_jsx(Box, { "data-status-notice-part": "action", sx: { alignItems: "center", display: "flex", flex: "0 0 auto" }, children: action })) : null] }));
|
|
44
|
+
}
|
|
45
|
+
function getStatusNoticeTone(tone) {
|
|
46
|
+
if (tone === "error") {
|
|
47
|
+
return { Icon: ErrorOutlineOutlinedIcon, iconColor: "error.main" };
|
|
48
|
+
}
|
|
49
|
+
if (tone === "warning") {
|
|
50
|
+
return { Icon: WarningAmberOutlinedIcon, iconColor: "warning.main" };
|
|
51
|
+
}
|
|
52
|
+
if (tone === "success") {
|
|
53
|
+
return { Icon: TaskAltOutlinedIcon, iconColor: "success.main" };
|
|
54
|
+
}
|
|
55
|
+
return { Icon: InfoOutlinedIcon, iconColor: "text.secondary" };
|
|
56
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import LinkRoundedIcon from "@mui/icons-material/LinkRounded";
|
|
4
|
+
import OpenInNewRoundedIcon from "@mui/icons-material/OpenInNewRounded";
|
|
5
|
+
import { Box, Tooltip } from "@mui/material";
|
|
6
|
+
/**
|
|
7
|
+
* Shared presentation of the editor's destination card. Hosts own validated
|
|
8
|
+
* URLs, placement, portal/lifecycle and navigation policy; no metadata is fetched.
|
|
9
|
+
*/
|
|
10
|
+
export function LinkAddressPreview({ link, ariaLabel = "Link destination", openLabel = `Open ${link.href} in a new tab`, sx, ...events }) {
|
|
11
|
+
return (_jsxs(Box, { component: "a", href: link.href, target: "_blank", rel: "noopener noreferrer", title: openLabel, "aria-label": ariaLabel, "data-link-address-preview": "true", ...events, sx: [
|
|
12
|
+
{
|
|
13
|
+
alignItems: "center",
|
|
14
|
+
bgcolor: "background.paper",
|
|
15
|
+
border: 1,
|
|
16
|
+
borderColor: "divider",
|
|
17
|
+
borderRadius: "10px",
|
|
18
|
+
boxShadow: 8,
|
|
19
|
+
color: "text.primary",
|
|
20
|
+
display: "flex",
|
|
21
|
+
textDecoration: "none",
|
|
22
|
+
cursor: "pointer",
|
|
23
|
+
"&:focus-visible": {
|
|
24
|
+
outline: "2px solid",
|
|
25
|
+
outlineColor: "primary.main",
|
|
26
|
+
outlineOffset: 2,
|
|
27
|
+
},
|
|
28
|
+
gap: "10px",
|
|
29
|
+
left: link.left,
|
|
30
|
+
maxWidth: "calc(100vw - 24px)",
|
|
31
|
+
minHeight: 64,
|
|
32
|
+
p: "8px 10px",
|
|
33
|
+
position: "fixed",
|
|
34
|
+
top: link.top,
|
|
35
|
+
width: 360,
|
|
36
|
+
boxSizing: "border-box",
|
|
37
|
+
zIndex: (theme) => theme.zIndex.tooltip + 100,
|
|
38
|
+
},
|
|
39
|
+
...(Array.isArray(sx) ? sx : sx ? [sx] : []),
|
|
40
|
+
], children: [_jsx(Box, { "aria-hidden": "true", "data-link-preview-part": "icon", sx: {
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
bgcolor: "action.selected",
|
|
43
|
+
borderRadius: "8px",
|
|
44
|
+
color: "primary.main",
|
|
45
|
+
display: "flex",
|
|
46
|
+
flex: "0 0 36px",
|
|
47
|
+
height: 36,
|
|
48
|
+
justifyContent: "center",
|
|
49
|
+
}, children: _jsx(LinkRoundedIcon, { sx: { fontSize: 16 } }) }), _jsxs(Box, { sx: { flex: 1, minWidth: 0 }, "data-link-preview-part": "text", children: [_jsx(Box, { component: "div", dir: "auto", sx: {
|
|
50
|
+
fontSize: "0.92rem",
|
|
51
|
+
fontWeight: 600,
|
|
52
|
+
lineHeight: 1.35,
|
|
53
|
+
overflow: "hidden",
|
|
54
|
+
textOverflow: "ellipsis",
|
|
55
|
+
whiteSpace: "nowrap",
|
|
56
|
+
}, children: link.label }), _jsx(Box, { component: "div", dir: "ltr", title: link.href, sx: {
|
|
57
|
+
color: "text.secondary",
|
|
58
|
+
fontSize: "0.8rem",
|
|
59
|
+
lineHeight: 1.4,
|
|
60
|
+
overflow: "hidden",
|
|
61
|
+
textAlign: "start",
|
|
62
|
+
textOverflow: "ellipsis",
|
|
63
|
+
whiteSpace: "nowrap",
|
|
64
|
+
}, children: link.href })] }), _jsx(Tooltip, { title: openLabel, children: _jsx(Box, { component: "span", "aria-hidden": "true", "data-link-preview-part": "open", sx: {
|
|
65
|
+
display: "inline-flex",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
justifyContent: "center",
|
|
68
|
+
color: "text.primary",
|
|
69
|
+
flex: "0 0 44px",
|
|
70
|
+
height: 44,
|
|
71
|
+
width: 44,
|
|
72
|
+
borderRadius: "6px",
|
|
73
|
+
}, children: _jsx(OpenInNewRoundedIcon, { sx: { fontSize: 18 } }) }) })] }));
|
|
74
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { LinkAddressPreview, } from "./LinkAddressPreview.js";
|
|
4
|
+
import { useEffect, useId, useRef, useState, } from "react";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
/** Product decision: hosts own link interaction; the shared UI card only displays
|
|
7
|
+
* a validated destination. The source previews/edits; the card navigates. */
|
|
8
|
+
export function useLinkAddressPreview(enabled = true, onEdit) {
|
|
9
|
+
const id = useId();
|
|
10
|
+
const activated = useRef(null);
|
|
11
|
+
const [preview, setPreview] = useState(null);
|
|
12
|
+
const closeTimer = useRef(null);
|
|
13
|
+
const focusFrame = useRef(null);
|
|
14
|
+
function cancelClose() {
|
|
15
|
+
if (closeTimer.current !== null)
|
|
16
|
+
clearTimeout(closeTimer.current);
|
|
17
|
+
closeTimer.current = null;
|
|
18
|
+
}
|
|
19
|
+
function close() {
|
|
20
|
+
cancelClose();
|
|
21
|
+
setPreview(null);
|
|
22
|
+
activated.current = null;
|
|
23
|
+
}
|
|
24
|
+
function contains(target) {
|
|
25
|
+
var _a;
|
|
26
|
+
return (target instanceof Node &&
|
|
27
|
+
((preview === null || preview === void 0 ? void 0 : preview.anchor.contains(target)) ||
|
|
28
|
+
((_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.contains(target))));
|
|
29
|
+
}
|
|
30
|
+
function show(anchor, href, label) {
|
|
31
|
+
if (!enabled)
|
|
32
|
+
return;
|
|
33
|
+
cancelClose();
|
|
34
|
+
const rect = anchor.getBoundingClientRect();
|
|
35
|
+
const width = Math.min(360, window.innerWidth - 24);
|
|
36
|
+
setPreview({
|
|
37
|
+
anchor,
|
|
38
|
+
href,
|
|
39
|
+
label,
|
|
40
|
+
left: Math.max(12, Math.min(rect.left, window.innerWidth - width - 12)),
|
|
41
|
+
top: Math.max(12, Math.min(rect.bottom + 8, window.innerHeight - 88)),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
function scheduleClose() {
|
|
45
|
+
cancelClose();
|
|
46
|
+
// Allow pointer travel between the inline link and its portal card.
|
|
47
|
+
closeTimer.current = setTimeout(() => {
|
|
48
|
+
if (!contains(document.activeElement))
|
|
49
|
+
setPreview(null);
|
|
50
|
+
}, 180);
|
|
51
|
+
}
|
|
52
|
+
function blur(event) {
|
|
53
|
+
if (!contains(event.relatedTarget))
|
|
54
|
+
close();
|
|
55
|
+
}
|
|
56
|
+
function escape(event) {
|
|
57
|
+
if (event.key !== "Escape")
|
|
58
|
+
return;
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
preview === null || preview === void 0 ? void 0 : preview.anchor.focus({ preventScroll: true });
|
|
62
|
+
close();
|
|
63
|
+
}
|
|
64
|
+
useEffect(() => () => {
|
|
65
|
+
if (closeTimer.current !== null)
|
|
66
|
+
clearTimeout(closeTimer.current);
|
|
67
|
+
if (focusFrame.current !== null)
|
|
68
|
+
cancelAnimationFrame(focusFrame.current);
|
|
69
|
+
}, []);
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (!preview)
|
|
72
|
+
return;
|
|
73
|
+
const dismiss = () => setPreview(null);
|
|
74
|
+
const outside = (event) => {
|
|
75
|
+
var _a;
|
|
76
|
+
const target = event.target;
|
|
77
|
+
if (target instanceof Node &&
|
|
78
|
+
!preview.anchor.contains(target) &&
|
|
79
|
+
!((_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.contains(target)))
|
|
80
|
+
dismiss();
|
|
81
|
+
};
|
|
82
|
+
window.addEventListener("resize", dismiss);
|
|
83
|
+
window.addEventListener("scroll", dismiss, true);
|
|
84
|
+
document.addEventListener("pointerdown", outside);
|
|
85
|
+
return () => {
|
|
86
|
+
window.removeEventListener("resize", dismiss);
|
|
87
|
+
window.removeEventListener("scroll", dismiss, true);
|
|
88
|
+
document.removeEventListener("pointerdown", outside);
|
|
89
|
+
};
|
|
90
|
+
}, [preview, id]);
|
|
91
|
+
return {
|
|
92
|
+
linkProps(href, label) {
|
|
93
|
+
return enabled
|
|
94
|
+
? {
|
|
95
|
+
"aria-controls": (preview === null || preview === void 0 ? void 0 : preview.href) === href ? id : undefined,
|
|
96
|
+
"aria-keyshortcuts": "ArrowDown",
|
|
97
|
+
onMouseEnter: (event) => show(event.currentTarget, href, label),
|
|
98
|
+
onMouseLeave: scheduleClose,
|
|
99
|
+
onFocus: (event) => show(event.currentTarget, href, label),
|
|
100
|
+
onBlur: blur,
|
|
101
|
+
onKeyDown: (event) => {
|
|
102
|
+
// Links inside editable titles must not trigger the parent's Enter handler.
|
|
103
|
+
event.stopPropagation();
|
|
104
|
+
if (event.key === "ArrowDown") {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
show(event.currentTarget, href, label);
|
|
107
|
+
if (focusFrame.current !== null)
|
|
108
|
+
cancelAnimationFrame(focusFrame.current);
|
|
109
|
+
focusFrame.current = requestAnimationFrame(() => {
|
|
110
|
+
var _a;
|
|
111
|
+
(_a = document.getElementById(id)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else
|
|
115
|
+
escape(event);
|
|
116
|
+
},
|
|
117
|
+
}
|
|
118
|
+
: {};
|
|
119
|
+
},
|
|
120
|
+
onClick(event, href, label) {
|
|
121
|
+
event.stopPropagation();
|
|
122
|
+
if (!enabled ||
|
|
123
|
+
event.metaKey ||
|
|
124
|
+
event.ctrlKey ||
|
|
125
|
+
event.shiftKey ||
|
|
126
|
+
event.altKey ||
|
|
127
|
+
event.button !== 0)
|
|
128
|
+
return;
|
|
129
|
+
// The source is an editing affordance after preview; the card owns navigation.
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
if ((preview === null || preview === void 0 ? void 0 : preview.anchor) === event.currentTarget &&
|
|
132
|
+
activated.current === event.currentTarget &&
|
|
133
|
+
onEdit) {
|
|
134
|
+
close();
|
|
135
|
+
onEdit();
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
activated.current = event.currentTarget;
|
|
139
|
+
show(event.currentTarget, href, label);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
card: preview
|
|
143
|
+
? createPortal(_jsx(LinkAddressPreview, { id: id, link: preview, onMouseEnter: cancelClose, onMouseLeave: scheduleClose, onFocusCapture: cancelClose, onBlurCapture: blur, onKeyDown: (event) => {
|
|
144
|
+
event.stopPropagation();
|
|
145
|
+
escape(event);
|
|
146
|
+
}, onClick: (event) => event.stopPropagation() }), document.body)
|
|
147
|
+
: null,
|
|
148
|
+
};
|
|
149
|
+
}
|