@namroodinc/liquid-editorial 0.4.1 → 0.6.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/README.md +17 -7
- package/UPGRADING.md +217 -0
- package/dist/chunks/{Board-BaQ04nWg.cjs → Board-BPA6mVhf.cjs} +2 -2
- package/dist/chunks/{Board-BaQ04nWg.cjs.map → Board-BPA6mVhf.cjs.map} +1 -1
- package/dist/chunks/{Board-CUhF8pTX.js → Board-CcIF7jS0.js} +2 -2
- package/dist/chunks/{Board-CUhF8pTX.js.map → Board-CcIF7jS0.js.map} +1 -1
- package/dist/chunks/{ColourField-CJicr3OT.cjs → ColourField-BQ4a5tAV.cjs} +2 -2
- package/dist/chunks/{ColourField-CJicr3OT.cjs.map → ColourField-BQ4a5tAV.cjs.map} +1 -1
- package/dist/chunks/{ColourField-DjHRiFDU.js → ColourField-Doew1hLw.js} +3 -3
- package/dist/chunks/{ColourField-DjHRiFDU.js.map → ColourField-Doew1hLw.js.map} +1 -1
- package/dist/chunks/{DatePicker-aSlYLjtW.cjs → DatePicker-C0-609Zx.cjs} +2 -2
- package/dist/chunks/{DatePicker-aSlYLjtW.cjs.map → DatePicker-C0-609Zx.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-D_6CQpUd.js → DatePicker-DmeWUsOS.js} +2 -2
- package/dist/chunks/{DatePicker-D_6CQpUd.js.map → DatePicker-DmeWUsOS.js.map} +1 -1
- package/dist/chunks/{FormEditor-CaskinQ1.js → FormEditor-DTnFO4oS.js} +170 -154
- package/dist/chunks/FormEditor-DTnFO4oS.js.map +1 -0
- package/dist/chunks/FormEditor-DfQLJnsO.cjs +2 -0
- package/dist/chunks/FormEditor-DfQLJnsO.cjs.map +1 -0
- package/dist/chunks/Icon-D1kx7-1c.js +81 -0
- package/dist/chunks/Icon-D1kx7-1c.js.map +1 -0
- package/dist/chunks/Icon-D38lQXNe.cjs +2 -0
- package/dist/chunks/Icon-D38lQXNe.cjs.map +1 -0
- package/dist/chunks/RichTextEditor-DEJ-u-ZR.js +483 -0
- package/dist/chunks/RichTextEditor-DEJ-u-ZR.js.map +1 -0
- package/dist/chunks/RichTextEditor-Ddk7qaqg.cjs +2 -0
- package/dist/chunks/RichTextEditor-Ddk7qaqg.cjs.map +1 -0
- package/dist/chunks/movableHost-CajG9_5Z.cjs +2 -0
- package/dist/chunks/movableHost-CajG9_5Z.cjs.map +1 -0
- package/dist/chunks/movableHost-NJj_FsAu.js +23 -0
- package/dist/chunks/movableHost-NJj_FsAu.js.map +1 -0
- package/dist/chunks/portalScope-AzzPM54i.js +105 -0
- package/dist/chunks/portalScope-AzzPM54i.js.map +1 -0
- package/dist/chunks/portalScope-BVA1-Ypu.cjs +2 -0
- package/dist/chunks/portalScope-BVA1-Ypu.cjs.map +1 -0
- package/dist/chunks/useModalDialog-BVaG--b3.js +87 -0
- package/dist/chunks/useModalDialog-BVaG--b3.js.map +1 -0
- package/dist/chunks/useModalDialog-Ctu270Dp.cjs +2 -0
- package/dist/chunks/useModalDialog-Ctu270Dp.cjs.map +1 -0
- package/dist/components/AssetCard/index.cjs +1 -1
- package/dist/components/AssetCard/index.js +1 -1
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.cjs.map +1 -1
- package/dist/components/Button/index.d.cts +5 -0
- package/dist/components/Button/index.d.cts.map +1 -1
- package/dist/components/Button/index.d.ts +5 -0
- package/dist/components/Button/index.d.ts.map +1 -1
- package/dist/components/Button/index.js +14 -12
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Button/style.css +43 -11
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.cjs.map +1 -1
- package/dist/components/Drawer/index.d.cts.map +1 -1
- package/dist/components/Drawer/index.d.ts.map +1 -1
- package/dist/components/Drawer/index.js +59 -75
- package/dist/components/Drawer/index.js.map +1 -1
- package/dist/components/Drawer/style.css +3 -0
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.cjs.map +1 -1
- package/dist/components/EditLayout/index.d.cts.map +1 -1
- package/dist/components/EditLayout/index.d.ts.map +1 -1
- package/dist/components/EditLayout/index.js +107 -121
- package/dist/components/EditLayout/index.js.map +1 -1
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.cjs.map +1 -1
- package/dist/components/EntryPicker/index.d.cts.map +1 -1
- package/dist/components/EntryPicker/index.d.ts.map +1 -1
- package/dist/components/EntryPicker/index.js +3 -9
- package/dist/components/EntryPicker/index.js.map +1 -1
- package/dist/components/FormEditor/README.md +79 -3
- package/dist/components/FormEditor/control.d.cts.map +1 -1
- package/dist/components/FormEditor/control.d.ts.map +1 -1
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.d.cts.map +1 -1
- package/dist/components/FormEditor/index.d.ts.map +1 -1
- package/dist/components/FormEditor/index.js +2 -1
- package/dist/components/FormEditor/model.d.cts +6 -0
- package/dist/components/FormEditor/model.d.cts.map +1 -1
- package/dist/components/FormEditor/model.d.ts +6 -0
- package/dist/components/FormEditor/model.d.ts.map +1 -1
- package/dist/components/FormEditor/style.css +7 -0
- package/dist/components/Icon/icons.d.cts +2 -0
- package/dist/components/Icon/icons.d.cts.map +1 -1
- package/dist/components/Icon/icons.d.ts +2 -0
- package/dist/components/Icon/icons.d.ts.map +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +1 -1
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.cjs.map +1 -1
- package/dist/components/Modal/index.d.cts +9 -1
- package/dist/components/Modal/index.d.cts.map +1 -1
- package/dist/components/Modal/index.d.ts +9 -1
- package/dist/components/Modal/index.d.ts.map +1 -1
- package/dist/components/Modal/index.js +37 -45
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/style.css +8 -1
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.cjs.map +1 -1
- package/dist/components/Popover/index.d.cts.map +1 -1
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +44 -37
- package/dist/components/Popover/index.js.map +1 -1
- package/dist/components/Popover/style.css +3 -0
- package/dist/components/RichTextEditor/expanded-width.d.cts +4 -0
- package/dist/components/RichTextEditor/expanded-width.d.cts.map +1 -0
- package/dist/components/RichTextEditor/expanded-width.d.ts +4 -0
- package/dist/components/RichTextEditor/expanded-width.d.ts.map +1 -0
- package/dist/components/RichTextEditor/expansion.d.cts +28 -0
- package/dist/components/RichTextEditor/expansion.d.cts.map +1 -0
- package/dist/components/RichTextEditor/expansion.d.ts +28 -0
- package/dist/components/RichTextEditor/expansion.d.ts.map +1 -0
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts +4 -4
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts +4 -4
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RichTextEditor/style.css +85 -4
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +1 -1
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.cjs.map +1 -1
- package/dist/components/SortableList/index.d.cts +12 -2
- package/dist/components/SortableList/index.d.cts.map +1 -1
- package/dist/components/SortableList/index.d.ts +12 -2
- package/dist/components/SortableList/index.d.ts.map +1 -1
- package/dist/components/SortableList/index.js +126 -66
- package/dist/components/SortableList/index.js.map +1 -1
- package/dist/components/SortableList/style.css +19 -5
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SubNav/index.cjs +1 -1
- package/dist/components/SubNav/index.js +1 -1
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -30
- package/dist/internal/dialogFocus.d.cts +8 -0
- package/dist/internal/dialogFocus.d.cts.map +1 -1
- package/dist/internal/dialogFocus.d.ts +8 -0
- package/dist/internal/dialogFocus.d.ts.map +1 -1
- package/dist/internal/movableHost.d.cts +20 -0
- package/dist/internal/movableHost.d.cts.map +1 -0
- package/dist/internal/movableHost.d.ts +20 -0
- package/dist/internal/movableHost.d.ts.map +1 -0
- package/dist/internal/portalScope.d.cts +23 -0
- package/dist/internal/portalScope.d.cts.map +1 -0
- package/dist/internal/portalScope.d.ts +23 -0
- package/dist/internal/portalScope.d.ts.map +1 -0
- package/dist/internal/useModalDialog.d.cts +22 -0
- package/dist/internal/useModalDialog.d.cts.map +1 -0
- package/dist/internal/useModalDialog.d.ts +22 -0
- package/dist/internal/useModalDialog.d.ts.map +1 -0
- package/package.json +1 -1
- package/dist/chunks/FormEditor-CaskinQ1.js.map +0 -1
- package/dist/chunks/FormEditor-DDylpJ9O.cjs +0 -2
- package/dist/chunks/FormEditor-DDylpJ9O.cjs.map +0 -1
- package/dist/chunks/Icon-BBoWP_Y6.cjs +0 -2
- package/dist/chunks/Icon-BBoWP_Y6.cjs.map +0 -1
- package/dist/chunks/Icon-XNismJDm.js +0 -79
- package/dist/chunks/Icon-XNismJDm.js.map +0 -1
- package/dist/chunks/RichTextEditor-C7nMfDmE.cjs +0 -2
- package/dist/chunks/RichTextEditor-C7nMfDmE.cjs.map +0 -1
- package/dist/chunks/RichTextEditor-DjR10XJ-.js +0 -370
- package/dist/chunks/RichTextEditor-DjR10XJ-.js.map +0 -1
- package/dist/chunks/dialogFocus-B9iqKl3I.cjs +0 -2
- package/dist/chunks/dialogFocus-B9iqKl3I.cjs.map +0 -1
- package/dist/chunks/dialogFocus-BFoyeTpA.js +0 -48
- package/dist/chunks/dialogFocus-BFoyeTpA.js.map +0 -1
- package/dist/chunks/dialogStack-6yv3NXFD.js +0 -43
- package/dist/chunks/dialogStack-6yv3NXFD.js.map +0 -1
- package/dist/chunks/dialogStack-C9SLVu6Q.cjs +0 -2
- package/dist/chunks/dialogStack-C9SLVu6Q.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Icon","_Fragment","useRef","Button","forwardRef","useMemo","mergeRefs","useState","useId","observeElementWidth","flushSync","Drawer","createPortal","require_Icon","require_components_Button_index","require_mergeRefs","require_components_Drawer_index","require_observeElementWidth","react","react_dom","react_jsx_runtime","TIGHT_WIDTH","COMPACT_WIDTH","WIDE_WIDTH","layoutMode","width","statusLabels","statusIcons","cannotHoldFocus","element","createRailHost","host","SaveStatus","icon","saveState","savedAgo","LeaveConfirmation","keepRef","origin","frame","text","onKeepEditing","bodyRef","EditActionBar","compact","backLabel","onBack","confirmLeave","confirmation","status","onLeave","actions","detailsToggle","DetailsRail","label","expanded","toggleRef","sheetOpen","detailsId","opensSheet","onToggle","contentRef","collapsed","EditLayout","rest","rootRef","mergedRef","ref","railSlotRef","sheetSlotRef","lastFocus","railHost","mode","setMode","localOpen","setLocalOpen","defaultRailOpen","sheet","setSheet","animate","setAnimate","narrow","railOpen","current","next","slot","focused","refocus","last","toggle","onRailToggle","railContent","rail","className","event","onFocus","confirmText","railLabel","railCollapsed"],"sources":["../../../src/components/EditLayout/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n} from \"react\";\nimport { createPortal, flushSync } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport { Drawer } from \"../Drawer\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { observeElementWidth } from \"../../internal/observeElementWidth\";\nimport \"./style.css\";\n\nexport type EditSaveState = \"clean\" | \"dirty\" | \"saving\" | \"saved\" | \"error\" | \"offline\";\n\nexport interface EditLayoutProps extends HTMLAttributes<HTMLDivElement> {\n backLabel: string;\n onBack: () => void;\n saveState?: EditSaveState;\n savedAgo?: ReactNode;\n actions?: ReactNode;\n /** A render slot can close the Details sheet before opening another dialog. */\n rail: ReactNode | ((closeDetails: () => void) => ReactNode);\n /** Custom collapsed controls receive the accessible expand action. */\n railCollapsed?: (expand: () => void) => ReactNode;\n railLabel?: string;\n railOpen?: boolean;\n defaultRailOpen?: boolean;\n onRailToggle?: (open: boolean) => void;\n confirmLeave?: boolean;\n confirmText?: string;\n onKeepEditing?: () => void;\n onLeave?: () => void;\n children?: ReactNode;\n}\n\n/** Below this width, the action bar's gaps and padding contract. */\nconst TIGHT_WIDTH = 360;\n/** Below this width, Details opens from the action bar. */\nconst COMPACT_WIDTH = 600;\n/** From this width, the rail follows the open/closed preference. */\nconst WIDE_WIDTH = 900;\n\ntype LayoutMode = \"tight\" | \"compact\" | \"narrow\" | \"wide\";\n\nfunction layoutMode(width: number): LayoutMode {\n if (width < TIGHT_WIDTH) {\n return \"tight\";\n }\n if (width < COMPACT_WIDTH) {\n return \"compact\";\n }\n if (width < WIDE_WIDTH) {\n return \"narrow\";\n }\n return \"wide\";\n}\n\nconst statusLabels: Record<EditSaveState, string> = {\n clean: \"No changes\",\n dirty: \"Unsaved changes\",\n saving: \"Saving…\",\n saved: \"Saved\",\n error: \"Couldn't save\",\n offline: \"Offline · kept in this tab\",\n};\n\nconst statusIcons: Record<EditSaveState, IconName | undefined> = {\n clean: undefined,\n dirty: undefined,\n saving: \"spinner\",\n saved: \"check\",\n error: \"alert-triangle\",\n offline: \"clock\",\n};\n\n/** Removed, hidden and inert elements can't keep focus, and neither can the page. */\nfunction cannotHoldFocus(element: Element | null) {\n return (\n !element ||\n element === document.body ||\n !element.isConnected ||\n element.closest(\"[aria-hidden='true'], [inert]\") !== null\n );\n}\n\nfunction createRailHost() {\n if (typeof document === \"undefined\") {\n return null;\n }\n const host = document.createElement(\"div\");\n host.className = \"ds-edit-layout__rail-host\";\n return host;\n}\n\ninterface SaveStatusProps {\n saveState: EditSaveState;\n savedAgo?: ReactNode;\n}\n\nfunction SaveStatus({ saveState, savedAgo }: SaveStatusProps) {\n const icon = statusIcons[saveState];\n return (\n <div\n className=\"ds-edit-layout__status\"\n data-state={saveState}\n role=\"status\"\n aria-live=\"polite\"\n >\n {icon && (\n <Icon\n name={icon}\n className={saveState === \"saving\" ? \"ds-icon--spin\" : undefined}\n />\n )}\n {saveState === \"dirty\" && (\n <span\n className=\"ds-edit-layout__dirty\"\n aria-hidden=\"true\"\n />\n )}\n <span>\n {statusLabels[saveState]}\n {saveState === \"saved\" && savedAgo ? <> {savedAgo}</> : null}\n </span>\n </div>\n );\n}\n\ninterface LeaveConfirmationProps {\n text: string;\n /** Keep editing falls back to the first control here when its origin is gone. */\n bodyRef: RefObject<HTMLDivElement | null>;\n onKeepEditing?: () => void;\n}\n\n/** Takes focus while shown; Keep editing returns it to where the user was. */\nfunction LeaveConfirmation({ text, bodyRef, onKeepEditing }: LeaveConfirmationProps) {\n const keepRef = useRef<HTMLButtonElement>(null);\n const origin = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n origin.current = document.activeElement as HTMLElement | null;\n const frame = requestAnimationFrame(() => keepRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, []);\n\n const keepEditing = () => {\n onKeepEditing?.();\n requestAnimationFrame(() => {\n const destination = origin.current?.isConnected\n ? origin.current\n : bodyRef.current?.querySelector<HTMLElement>(\n \"input, textarea, button, [contenteditable='true']\",\n );\n destination?.focus({ preventScroll: true });\n });\n };\n\n return (\n <div className=\"ds-edit-layout__confirmation\">\n <strong>{text}</strong>\n <Button\n ref={keepRef}\n size=\"xs\"\n onClick={keepEditing}\n >\n Keep editing\n </Button>\n </div>\n );\n}\n\ninterface EditActionBarProps {\n backLabel: string;\n onBack: () => void;\n compact: boolean;\n status: ReactNode;\n actions?: ReactNode;\n /** Replaces the status and actions while set. */\n confirmLeave: boolean;\n confirmation: ReactNode;\n onLeave?: () => void;\n /** Shown only in compact layouts, where Details opens as a sheet. */\n detailsToggle: ReactNode;\n}\n\nfunction EditActionBar({\n backLabel,\n onBack,\n compact,\n status,\n actions,\n confirmLeave,\n confirmation,\n onLeave,\n detailsToggle,\n}: EditActionBarProps) {\n return (\n <header className=\"ds-edit-layout__bar\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n iconStart=\"arrow-left\"\n isIconOnly={compact}\n aria-label={`Back to ${backLabel}`}\n onClick={onBack}\n >\n {backLabel}\n </Button>\n {confirmLeave ? confirmation : status}\n <div className=\"ds-edit-layout__actions\">\n {confirmLeave ? (\n <Button\n variant=\"danger\"\n size=\"sm\"\n onClick={onLeave}\n >\n Leave anyway\n </Button>\n ) : (\n actions\n )}\n {compact && detailsToggle}\n </div>\n </header>\n );\n}\n\ninterface DetailsRailProps {\n label: string;\n detailsId: string;\n expanded: boolean;\n /** Below the wide breakpoint, the toggle opens the Details sheet instead. */\n opensSheet: boolean;\n sheetOpen: boolean;\n toggleRef: RefObject<HTMLButtonElement | null>;\n /** Receives the rail content while the rail is expanded. */\n contentRef: RefObject<HTMLDivElement | null>;\n collapsed?: (expand: () => void) => ReactNode;\n onToggle: () => void;\n}\n\nfunction DetailsRail({\n label,\n detailsId,\n expanded,\n opensSheet,\n sheetOpen,\n toggleRef,\n contentRef,\n collapsed,\n onToggle,\n}: DetailsRailProps) {\n return (\n <aside\n className=\"ds-edit-layout__rail\"\n aria-label={label}\n >\n <header className=\"ds-edit-layout__rail-head\">\n {expanded && <span>{label}</span>}\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart={expanded ? \"chevrons-right\" : \"chevrons-left\"}\n className=\"ds-edit-layout__toggle\"\n aria-label={`${expanded ? \"Collapse\" : \"Expand\"} ${label}`}\n aria-expanded={expanded || sheetOpen}\n aria-controls={detailsId}\n aria-haspopup={opensSheet ? \"dialog\" : undefined}\n onClick={onToggle}\n />\n </header>\n {expanded ? (\n <div\n id={detailsId}\n ref={contentRef}\n className=\"ds-edit-layout__rail-content\"\n />\n ) : (\n <div className=\"ds-edit-layout__rail-icons\">\n {collapsed ? (\n collapsed(onToggle)\n ) : (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={`Show ${label}`}\n onClick={onToggle}\n />\n )}\n </div>\n )}\n </aside>\n );\n}\n\n/** Presentation only: the consumer owns saving, routing and persisted preferences. */\nexport const EditLayout = forwardRef<HTMLDivElement, EditLayoutProps>(function EditLayout(\n {\n backLabel,\n onBack,\n saveState = \"clean\",\n savedAgo,\n actions,\n rail,\n railCollapsed,\n railLabel = \"Details\",\n railOpen,\n defaultRailOpen = true,\n onRailToggle,\n confirmLeave = false,\n confirmText = \"Leave without saving?\",\n onKeepEditing,\n onLeave,\n children,\n className,\n onFocus,\n ...rest\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMemo(() => mergeRefs(rootRef, ref), [ref]);\n const bodyRef = useRef<HTMLDivElement>(null);\n const toggleRef = useRef<HTMLButtonElement>(null);\n const railSlotRef = useRef<HTMLDivElement>(null);\n const sheetSlotRef = useRef<HTMLDivElement>(null);\n const lastFocus = useRef<Element | null>(null);\n // Rail content renders once, into a node that moves between the rail and\n // the sheet, so uncontrolled fields keep their values across modes.\n const [railHost] = useState(createRailHost);\n const [mode, setMode] = useState<LayoutMode>(\"wide\");\n const [localOpen, setLocalOpen] = useState(defaultRailOpen);\n const [sheet, setSheet] = useState(false);\n const [animate, setAnimate] = useState(false);\n const detailsId = useId();\n const compact = mode === \"tight\" || mode === \"compact\";\n const narrow = mode !== \"wide\";\n const expanded = !narrow && (railOpen ?? localOpen);\n\n // Leave confirmation and the wide rail both replace the Details sheet.\n if (sheet && (confirmLeave || !narrow)) {\n setSheet(false);\n }\n\n // Measure before the first paint, then re-render only when a breakpoint is crossed.\n useLayoutEffect(() => {\n let current: LayoutMode | undefined;\n return observeElementWidth(rootRef.current!, (width) => {\n const next = layoutMode(width);\n if (next === current) {\n return;\n }\n current = next;\n // Crossing a breakpoint is not a deliberate toggle, so it doesn't animate.\n setAnimate(false);\n setMode(next);\n });\n }, []);\n\n useLayoutEffect(() => {\n if (!railHost) {\n return;\n }\n const slot = railSlotRef.current ?? sheetSlotRef.current;\n if (!slot) {\n railHost.remove();\n return;\n }\n if (railHost.parentNode === slot) {\n return;\n }\n // Moving a node drops its focus; keep the user in the field they were in.\n const focused = lastFocus.current;\n const refocus =\n focused instanceof HTMLElement &&\n railHost.contains(focused) &&\n cannotHoldFocus(document.activeElement);\n slot.append(railHost);\n if (refocus) {\n focused.focus({ preventScroll: true });\n }\n });\n\n // A breakpoint, a collapse or a closing sheet can remove the focused control.\n // Hand focus to the Details toggle that replaced it.\n useEffect(() => {\n const last = lastFocus.current;\n if (last && cannotHoldFocus(last) && cannotHoldFocus(document.activeElement)) {\n toggleRef.current?.focus({ preventScroll: true });\n }\n }, [mode, expanded, sheet]);\n\n const toggle = () => {\n if (narrow) {\n setSheet(true);\n return;\n }\n setAnimate(true);\n setLocalOpen(!expanded);\n onRailToggle?.(!expanded);\n };\n const closeDetails = () => flushSync(() => setSheet(false));\n const railContent = typeof rail === \"function\" ? rail(closeDetails) : rail;\n\n return (\n <div\n {...rest}\n ref={mergedRef}\n className={[\"ds-edit-layout\", className].filter(Boolean).join(\" \")}\n data-compact={compact || undefined}\n data-tight={mode === \"tight\" || undefined}\n data-expanded={expanded || undefined}\n data-animate={animate || undefined}\n onFocus={(event) => {\n lastFocus.current = event.target;\n onFocus?.(event);\n }}\n >\n <div className=\"ds-edit-layout__main\">\n <EditActionBar\n backLabel={backLabel}\n onBack={onBack}\n compact={compact}\n status={\n <SaveStatus\n saveState={saveState}\n savedAgo={savedAgo}\n />\n }\n actions={actions}\n confirmLeave={confirmLeave}\n confirmation={\n <LeaveConfirmation\n text={confirmText}\n bodyRef={bodyRef}\n onKeepEditing={onKeepEditing}\n />\n }\n onLeave={onLeave}\n detailsToggle={\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={railLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={sheet}\n aria-controls={detailsId}\n onClick={toggle}\n />\n }\n />\n <div\n ref={bodyRef}\n className=\"ds-edit-layout__body\"\n >\n <div className=\"ds-edit-layout__content\">{children}</div>\n </div>\n </div>\n {!compact && (\n <DetailsRail\n label={railLabel}\n detailsId={detailsId}\n expanded={expanded}\n opensSheet={narrow}\n sheetOpen={sheet}\n toggleRef={toggleRef}\n contentRef={railSlotRef}\n collapsed={railCollapsed}\n onToggle={toggle}\n />\n )}\n <Drawer\n id={narrow ? detailsId : undefined}\n dir={rest.dir}\n isOpen={sheet}\n onClose={() => setSheet(false)}\n side=\"end\"\n size=\"md\"\n title={railLabel}\n closeLabel={`Close ${railLabel}`}\n className=\"ds-edit-layout__sheet\"\n >\n {narrow && (\n <div\n ref={sheetSlotRef}\n className=\"ds-edit-layout__rail-content\"\n />\n )}\n </Drawer>\n {railHost && createPortal(railContent, railHost)}\n </div>\n );\n});\n"],"mappings":"A,gXA6CA,IAAMqB,EAAc,IAEdC,EAAgB,IAEhBC,EAAa,IAInB,SAASC,EAAW,EAA2B,CAU7C,OATIC,EAAQJ,EACH,QAELI,E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AAYyC,EACZ,gBAAc,SACd,gBAAepB,EACf,gBAAenB,EACf,QAAS+B,CACV,CAAA,CAEJ,CAAA,GACD,EAAArE,EAAA,IAAA,CAAC,MAAD,CACE,IAAKsB,EACL,UAAU,uBAEV,UAAA,EAAAtB,EAAA,IAAA,CAAC,MAAD,CAAK,UAAU,0BAA2B,UAAc,CAAA,CACrD,CAAA,CACF,C,GACJ,CAACwB,IACA,EAAAxB,EAAA,IAAA,CAACiC,EAAD,CACE,MAAO4C,EACI,YACD,WACV,WAAYhB,EACZ,UAAWJ,EACA,YACX,WAAYT,EACZ,UAAW8B,EACX,SAAUT,CACX,CAAA,GAEH,EAAArE,EAAA,IAAA,CAACT,EAAAA,OAAD,CACE,GAAIsE,EAASvB,EAAY,IAAA,GACzB,IAAKM,EAAK,IACV,OAAQa,EACR,YAAeC,EAAS,EAAK,EAC7B,KAAK,MACL,KAAK,KACL,MAAOmB,EACP,WAAY,SAASA,IACrB,UAAU,wBAET,SAAAhB,IACC,EAAA7D,EAAA,IAAA,CAAC,MAAD,CACE,IAAKiD,EACL,UAAU,8BACX,CAAA,CAEG,CAAA,EACPE,IAAA,EAAY3D,EAAAA,aAAAA,CAAa+E,GAAapB,CAAQ,CAC5C,C,EAET,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Icon","_Fragment","useRef","Button","forwardRef","useMemo","mergeRefs","useState","createMovableHost","useId","observeElementWidth","cannotHoldFocus","flushSync","Drawer","createPortal","require_Icon","require_components_Button_index","require_mergeRefs","require_portalScope","require_components_Drawer_index","require_observeElementWidth","require_movableHost","react","react_dom","react_jsx_runtime","TIGHT_WIDTH","COMPACT_WIDTH","WIDE_WIDTH","layoutMode","width","statusLabels","statusIcons","SaveStatus","icon","saveState","savedAgo","LeaveConfirmation","keepRef","origin","frame","text","onKeepEditing","bodyRef","EditActionBar","compact","backLabel","onBack","confirmLeave","confirmation","status","onLeave","actions","detailsToggle","DetailsRail","label","expanded","toggleRef","sheetOpen","detailsId","opensSheet","onToggle","contentRef","collapsed","EditLayout","rest","rootRef","mergedRef","ref","railSlotRef","sheetSlotRef","lastFocus","railHost","mode","setMode","localOpen","setLocalOpen","defaultRailOpen","sheet","setSheet","animate","setAnimate","narrow","railOpen","current","next","last","toggle","onRailToggle","railContent","rail","className","event","onFocus","confirmText","railLabel","railCollapsed"],"sources":["../../../src/components/EditLayout/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n} from \"react\";\nimport { createPortal, flushSync } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport { Drawer } from \"../Drawer\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { observeElementWidth } from \"../../internal/observeElementWidth\";\nimport { cannotHoldFocus } from \"../../internal/dialogFocus\";\nimport { createMovableHost, moveHost } from \"../../internal/movableHost\";\nimport \"./style.css\";\n\nexport type EditSaveState = \"clean\" | \"dirty\" | \"saving\" | \"saved\" | \"error\" | \"offline\";\n\nexport interface EditLayoutProps extends HTMLAttributes<HTMLDivElement> {\n backLabel: string;\n onBack: () => void;\n saveState?: EditSaveState;\n savedAgo?: ReactNode;\n actions?: ReactNode;\n /** A render slot can close the Details sheet before opening another dialog. */\n rail: ReactNode | ((closeDetails: () => void) => ReactNode);\n /** Custom collapsed controls receive the accessible expand action. */\n railCollapsed?: (expand: () => void) => ReactNode;\n railLabel?: string;\n railOpen?: boolean;\n defaultRailOpen?: boolean;\n onRailToggle?: (open: boolean) => void;\n confirmLeave?: boolean;\n confirmText?: string;\n onKeepEditing?: () => void;\n onLeave?: () => void;\n children?: ReactNode;\n}\n\n/** Below this width, the action bar's gaps and padding contract. */\nconst TIGHT_WIDTH = 360;\n/** Below this width, Details opens from the action bar. */\nconst COMPACT_WIDTH = 600;\n/** From this width, the rail follows the open/closed preference. */\nconst WIDE_WIDTH = 900;\n\ntype LayoutMode = \"tight\" | \"compact\" | \"narrow\" | \"wide\";\n\nfunction layoutMode(width: number): LayoutMode {\n if (width < TIGHT_WIDTH) {\n return \"tight\";\n }\n if (width < COMPACT_WIDTH) {\n return \"compact\";\n }\n if (width < WIDE_WIDTH) {\n return \"narrow\";\n }\n return \"wide\";\n}\n\nconst statusLabels: Record<EditSaveState, string> = {\n clean: \"No changes\",\n dirty: \"Unsaved changes\",\n saving: \"Saving…\",\n saved: \"Saved\",\n error: \"Couldn't save\",\n offline: \"Offline · kept in this tab\",\n};\n\nconst statusIcons: Record<EditSaveState, IconName | undefined> = {\n clean: undefined,\n dirty: undefined,\n saving: \"spinner\",\n saved: \"check\",\n error: \"alert-triangle\",\n offline: \"clock\",\n};\n\ninterface SaveStatusProps {\n saveState: EditSaveState;\n savedAgo?: ReactNode;\n}\n\nfunction SaveStatus({ saveState, savedAgo }: SaveStatusProps) {\n const icon = statusIcons[saveState];\n return (\n <div\n className=\"ds-edit-layout__status\"\n data-state={saveState}\n role=\"status\"\n aria-live=\"polite\"\n >\n {icon && (\n <Icon\n name={icon}\n className={saveState === \"saving\" ? \"ds-icon--spin\" : undefined}\n />\n )}\n {saveState === \"dirty\" && (\n <span\n className=\"ds-edit-layout__dirty\"\n aria-hidden=\"true\"\n />\n )}\n <span>\n {statusLabels[saveState]}\n {saveState === \"saved\" && savedAgo ? <> {savedAgo}</> : null}\n </span>\n </div>\n );\n}\n\ninterface LeaveConfirmationProps {\n text: string;\n /** Keep editing falls back to the first control here when its origin is gone. */\n bodyRef: RefObject<HTMLDivElement | null>;\n onKeepEditing?: () => void;\n}\n\n/** Takes focus while shown; Keep editing returns it to where the user was. */\nfunction LeaveConfirmation({ text, bodyRef, onKeepEditing }: LeaveConfirmationProps) {\n const keepRef = useRef<HTMLButtonElement>(null);\n const origin = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n origin.current = document.activeElement as HTMLElement | null;\n const frame = requestAnimationFrame(() => keepRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, []);\n\n const keepEditing = () => {\n onKeepEditing?.();\n requestAnimationFrame(() => {\n const destination = origin.current?.isConnected\n ? origin.current\n : bodyRef.current?.querySelector<HTMLElement>(\n \"input, textarea, button, [contenteditable='true']\",\n );\n destination?.focus({ preventScroll: true });\n });\n };\n\n return (\n <div className=\"ds-edit-layout__confirmation\">\n <strong>{text}</strong>\n <Button\n ref={keepRef}\n size=\"xs\"\n onClick={keepEditing}\n >\n Keep editing\n </Button>\n </div>\n );\n}\n\ninterface EditActionBarProps {\n backLabel: string;\n onBack: () => void;\n compact: boolean;\n status: ReactNode;\n actions?: ReactNode;\n /** Replaces the status and actions while set. */\n confirmLeave: boolean;\n confirmation: ReactNode;\n onLeave?: () => void;\n /** Shown only in compact layouts, where Details opens as a sheet. */\n detailsToggle: ReactNode;\n}\n\nfunction EditActionBar({\n backLabel,\n onBack,\n compact,\n status,\n actions,\n confirmLeave,\n confirmation,\n onLeave,\n detailsToggle,\n}: EditActionBarProps) {\n return (\n <header className=\"ds-edit-layout__bar\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n iconStart=\"arrow-left\"\n isIconOnly={compact}\n aria-label={`Back to ${backLabel}`}\n onClick={onBack}\n >\n {backLabel}\n </Button>\n {confirmLeave ? confirmation : status}\n <div className=\"ds-edit-layout__actions\">\n {confirmLeave ? (\n <Button\n variant=\"danger\"\n size=\"sm\"\n onClick={onLeave}\n >\n Leave anyway\n </Button>\n ) : (\n actions\n )}\n {compact && detailsToggle}\n </div>\n </header>\n );\n}\n\ninterface DetailsRailProps {\n label: string;\n detailsId: string;\n expanded: boolean;\n /** Below the wide breakpoint, the toggle opens the Details sheet instead. */\n opensSheet: boolean;\n sheetOpen: boolean;\n toggleRef: RefObject<HTMLButtonElement | null>;\n /** Receives the rail content while the rail is expanded. */\n contentRef: RefObject<HTMLDivElement | null>;\n collapsed?: (expand: () => void) => ReactNode;\n onToggle: () => void;\n}\n\nfunction DetailsRail({\n label,\n detailsId,\n expanded,\n opensSheet,\n sheetOpen,\n toggleRef,\n contentRef,\n collapsed,\n onToggle,\n}: DetailsRailProps) {\n return (\n <aside\n className=\"ds-edit-layout__rail\"\n aria-label={label}\n >\n <header className=\"ds-edit-layout__rail-head\">\n {expanded && <span>{label}</span>}\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart={expanded ? \"chevrons-right\" : \"chevrons-left\"}\n className=\"ds-edit-layout__toggle\"\n aria-label={`${expanded ? \"Collapse\" : \"Expand\"} ${label}`}\n aria-expanded={expanded || sheetOpen}\n aria-controls={detailsId}\n aria-haspopup={opensSheet ? \"dialog\" : undefined}\n onClick={onToggle}\n />\n </header>\n {expanded ? (\n <div\n id={detailsId}\n ref={contentRef}\n className=\"ds-edit-layout__rail-content\"\n />\n ) : (\n <div className=\"ds-edit-layout__rail-icons\">\n {collapsed ? (\n collapsed(onToggle)\n ) : (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={`Show ${label}`}\n onClick={onToggle}\n />\n )}\n </div>\n )}\n </aside>\n );\n}\n\n/** Presentation only: the consumer owns saving, routing and persisted preferences. */\nexport const EditLayout = forwardRef<HTMLDivElement, EditLayoutProps>(function EditLayout(\n {\n backLabel,\n onBack,\n saveState = \"clean\",\n savedAgo,\n actions,\n rail,\n railCollapsed,\n railLabel = \"Details\",\n railOpen,\n defaultRailOpen = true,\n onRailToggle,\n confirmLeave = false,\n confirmText = \"Leave without saving?\",\n onKeepEditing,\n onLeave,\n children,\n className,\n onFocus,\n ...rest\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMemo(() => mergeRefs(rootRef, ref), [ref]);\n const bodyRef = useRef<HTMLDivElement>(null);\n const toggleRef = useRef<HTMLButtonElement>(null);\n const railSlotRef = useRef<HTMLDivElement>(null);\n const sheetSlotRef = useRef<HTMLDivElement>(null);\n const lastFocus = useRef<Element | null>(null);\n // Rail content renders once, into a node that moves between the rail and\n // the sheet, so uncontrolled fields keep their values across modes.\n const [railHost] = useState(() => createMovableHost(\"ds-edit-layout__rail-host\"));\n const [mode, setMode] = useState<LayoutMode>(\"wide\");\n const [localOpen, setLocalOpen] = useState(defaultRailOpen);\n const [sheet, setSheet] = useState(false);\n const [animate, setAnimate] = useState(false);\n const detailsId = useId();\n const compact = mode === \"tight\" || mode === \"compact\";\n const narrow = mode !== \"wide\";\n const expanded = !narrow && (railOpen ?? localOpen);\n\n // Leave confirmation and the wide rail both replace the Details sheet.\n if (sheet && (confirmLeave || !narrow)) {\n setSheet(false);\n }\n\n // Measure before the first paint, then re-render only when a breakpoint is crossed.\n useLayoutEffect(() => {\n let current: LayoutMode | undefined;\n return observeElementWidth(rootRef.current!, (width) => {\n const next = layoutMode(width);\n if (next === current) {\n return;\n }\n current = next;\n // Crossing a breakpoint is not a deliberate toggle, so it doesn't animate.\n setAnimate(false);\n setMode(next);\n });\n }, []);\n\n // Moving a node drops its focus; keep the user in the field they were in.\n useLayoutEffect(() => {\n if (railHost) {\n moveHost(railHost, railSlotRef.current ?? sheetSlotRef.current, lastFocus.current);\n }\n });\n\n // A breakpoint, a collapse or a closing sheet can remove the focused control.\n // Hand focus to the Details toggle that replaced it.\n useEffect(() => {\n const last = lastFocus.current;\n if (last && cannotHoldFocus(last) && cannotHoldFocus(document.activeElement)) {\n toggleRef.current?.focus({ preventScroll: true });\n }\n }, [mode, expanded, sheet]);\n\n const toggle = () => {\n if (narrow) {\n setSheet(true);\n return;\n }\n setAnimate(true);\n setLocalOpen(!expanded);\n onRailToggle?.(!expanded);\n };\n const closeDetails = () => flushSync(() => setSheet(false));\n const railContent = typeof rail === \"function\" ? rail(closeDetails) : rail;\n\n return (\n <div\n {...rest}\n ref={mergedRef}\n className={[\"ds-edit-layout\", className].filter(Boolean).join(\" \")}\n data-compact={compact || undefined}\n data-tight={mode === \"tight\" || undefined}\n data-expanded={expanded || undefined}\n data-animate={animate || undefined}\n onFocus={(event) => {\n lastFocus.current = event.target;\n onFocus?.(event);\n }}\n >\n <div className=\"ds-edit-layout__main\">\n <EditActionBar\n backLabel={backLabel}\n onBack={onBack}\n compact={compact}\n status={\n <SaveStatus\n saveState={saveState}\n savedAgo={savedAgo}\n />\n }\n actions={actions}\n confirmLeave={confirmLeave}\n confirmation={\n <LeaveConfirmation\n text={confirmText}\n bodyRef={bodyRef}\n onKeepEditing={onKeepEditing}\n />\n }\n onLeave={onLeave}\n detailsToggle={\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={railLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={sheet}\n aria-controls={detailsId}\n onClick={toggle}\n />\n }\n />\n <div\n ref={bodyRef}\n className=\"ds-edit-layout__body\"\n >\n <div className=\"ds-edit-layout__content\">{children}</div>\n </div>\n </div>\n {!compact && (\n <DetailsRail\n label={railLabel}\n detailsId={detailsId}\n expanded={expanded}\n opensSheet={narrow}\n sheetOpen={sheet}\n toggleRef={toggleRef}\n contentRef={railSlotRef}\n collapsed={railCollapsed}\n onToggle={toggle}\n />\n )}\n <Drawer\n id={narrow ? detailsId : undefined}\n dir={rest.dir}\n isOpen={sheet}\n onClose={() => setSheet(false)}\n side=\"end\"\n size=\"md\"\n title={railLabel}\n closeLabel={`Close ${railLabel}`}\n className=\"ds-edit-layout__sheet\"\n >\n {narrow && (\n <div\n ref={sheetSlotRef}\n className=\"ds-edit-layout__rail-content\"\n />\n )}\n </Drawer>\n {railHost && createPortal(railContent, railHost)}\n </div>\n );\n});\n"],"mappings":"A,sdA+CA,IAAMyB,EAAc,IAEdC,EAAgB,IAEhBC,EAAa,IAInB,SAASC,EAAW,EAA2B,CAU7C,OATIC,EAAQJ,EACH,QAELI,EAAQH,EACH,UAELG,EAAQF,EACH,SAEF,MACT,CAEA,IAAMG,EAA8C,CAClD,MAAO,aACP,MAAO,kBACP,OAAQ,UACR,MAAO,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rB,UAAU,wBAET,SAAAb,IACC,EAAAzD,EAAA,IAAA,CAAC,MAAD,CACE,IAAK6C,EACL,UAAU,8BACX,CAAA,CAEG,CAAA,EACPE,IAAA,EAAYzD,EAAAA,aAAAA,CAAa0E,GAAajB,CAAQ,CAC5C,C,EAET,CAAC,E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/EditLayout/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/components/EditLayout/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAUf,OAAO,aAAa,CAAC;AAErB,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAEzF,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,+EAA+E;IAC/E,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,YAAY,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC,CAAC;IAC5D,sEAAsE;IACtE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAwPD,sFAAsF;AACtF,eAAO,MAAM,UAAU,4GAsLrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/EditLayout/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/EditLayout/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAUf,OAAO,aAAa,CAAC;AAErB,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAEzF,MAAM,WAAW,eAAgB,SAAQ,cAAc,CAAC,cAAc,CAAC;IACrE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,SAAS,CAAC,EAAE,aAAa,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,+EAA+E;IAC/E,IAAI,EAAE,SAAS,GAAG,CAAC,CAAC,YAAY,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC,CAAC;IAC5D,sEAAsE;IACtE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,IAAI,KAAK,SAAS,CAAC;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACvC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;IAC3B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAwPD,sFAAsF;AACtF,eAAO,MAAM,UAAU,4GAsLrB,CAAC"}
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { t as e } from "../../chunks/Icon-
|
|
1
|
+
import { t as e } from "../../chunks/Icon-D1kx7-1c.js";
|
|
2
2
|
import { Button as t } from "../Button/index.js";
|
|
3
3
|
import { t as n } from "../../chunks/mergeRefs-DGM402mE.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
4
|
+
import { i as r } from "../../chunks/portalScope-AzzPM54i.js";
|
|
5
|
+
import { Drawer as i } from "../Drawer/index.js";
|
|
6
|
+
import { t as a } from "../../chunks/observeElementWidth-BlQOlW2t.js";
|
|
7
|
+
import { n as o, t as s } from "../../chunks/movableHost-NJj_FsAu.js";
|
|
8
|
+
import { forwardRef as c, useEffect as l, useId as u, useLayoutEffect as d, useMemo as ee, useRef as f, useState as p } from "react";
|
|
9
|
+
import { createPortal as te, flushSync as m } from "react-dom";
|
|
10
|
+
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
9
11
|
//#region src/components/EditLayout/index.tsx
|
|
10
|
-
var
|
|
11
|
-
function
|
|
12
|
-
return e <
|
|
12
|
+
var v = 360, y = 600, b = 900;
|
|
13
|
+
function ne(e) {
|
|
14
|
+
return e < v ? "tight" : e < y ? "compact" : e < b ? "narrow" : "wide";
|
|
13
15
|
}
|
|
14
|
-
var
|
|
16
|
+
var x = {
|
|
15
17
|
clean: "No changes",
|
|
16
18
|
dirty: "Unsaved changes",
|
|
17
19
|
saving: "Saving…",
|
|
18
20
|
saved: "Saved",
|
|
19
21
|
error: "Couldn't save",
|
|
20
22
|
offline: "Offline · kept in this tab"
|
|
21
|
-
},
|
|
23
|
+
}, S = {
|
|
22
24
|
clean: void 0,
|
|
23
25
|
dirty: void 0,
|
|
24
26
|
saving: "spinner",
|
|
@@ -26,43 +28,35 @@ var b = {
|
|
|
26
28
|
error: "alert-triangle",
|
|
27
29
|
offline: "clock"
|
|
28
30
|
};
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
function C() {
|
|
33
|
-
if (typeof document > "u") return null;
|
|
34
|
-
let e = document.createElement("div");
|
|
35
|
-
return e.className = "ds-edit-layout__rail-host", e;
|
|
36
|
-
}
|
|
37
|
-
function te({ saveState: t, savedAgo: n }) {
|
|
38
|
-
let r = x[t];
|
|
39
|
-
return /* @__PURE__ */ h("div", {
|
|
31
|
+
function C({ saveState: t, savedAgo: n }) {
|
|
32
|
+
let r = S[t];
|
|
33
|
+
return /* @__PURE__ */ _("div", {
|
|
40
34
|
className: "ds-edit-layout__status",
|
|
41
35
|
"data-state": t,
|
|
42
36
|
role: "status",
|
|
43
37
|
"aria-live": "polite",
|
|
44
38
|
children: [
|
|
45
|
-
r && /* @__PURE__ */
|
|
39
|
+
r && /* @__PURE__ */ g(e, {
|
|
46
40
|
name: r,
|
|
47
41
|
className: t === "saving" ? "ds-icon--spin" : void 0
|
|
48
42
|
}),
|
|
49
|
-
t === "dirty" && /* @__PURE__ */
|
|
43
|
+
t === "dirty" && /* @__PURE__ */ g("span", {
|
|
50
44
|
className: "ds-edit-layout__dirty",
|
|
51
45
|
"aria-hidden": "true"
|
|
52
46
|
}),
|
|
53
|
-
/* @__PURE__ */
|
|
47
|
+
/* @__PURE__ */ _("span", { children: [x[t], t === "saved" && n ? /* @__PURE__ */ _(h, { children: [" ", n] }) : null] })
|
|
54
48
|
]
|
|
55
49
|
});
|
|
56
50
|
}
|
|
57
|
-
function
|
|
58
|
-
let i =
|
|
59
|
-
return
|
|
51
|
+
function w({ text: e, bodyRef: n, onKeepEditing: r }) {
|
|
52
|
+
let i = f(null), a = f(null);
|
|
53
|
+
return l(() => {
|
|
60
54
|
a.current = document.activeElement;
|
|
61
55
|
let e = requestAnimationFrame(() => i.current?.focus({ preventScroll: !0 }));
|
|
62
56
|
return () => cancelAnimationFrame(e);
|
|
63
|
-
}, []), /* @__PURE__ */
|
|
57
|
+
}, []), /* @__PURE__ */ _("div", {
|
|
64
58
|
className: "ds-edit-layout__confirmation",
|
|
65
|
-
children: [/* @__PURE__ */
|
|
59
|
+
children: [/* @__PURE__ */ g("strong", { children: e }), /* @__PURE__ */ g(t, {
|
|
66
60
|
ref: i,
|
|
67
61
|
size: "xs",
|
|
68
62
|
onClick: () => {
|
|
@@ -74,11 +68,11 @@ function ne({ text: e, bodyRef: n, onKeepEditing: r }) {
|
|
|
74
68
|
})]
|
|
75
69
|
});
|
|
76
70
|
}
|
|
77
|
-
function
|
|
78
|
-
return /* @__PURE__ */
|
|
71
|
+
function T({ backLabel: e, onBack: n, compact: r, status: i, actions: a, confirmLeave: o, confirmation: s, onLeave: c, detailsToggle: l }) {
|
|
72
|
+
return /* @__PURE__ */ _("header", {
|
|
79
73
|
className: "ds-edit-layout__bar",
|
|
80
74
|
children: [
|
|
81
|
-
/* @__PURE__ */
|
|
75
|
+
/* @__PURE__ */ g(t, {
|
|
82
76
|
variant: "simple",
|
|
83
77
|
size: "sm",
|
|
84
78
|
iconStart: "arrow-left",
|
|
@@ -88,9 +82,9 @@ function re({ backLabel: e, onBack: n, compact: r, status: i, actions: a, confir
|
|
|
88
82
|
children: e
|
|
89
83
|
}),
|
|
90
84
|
o ? s : i,
|
|
91
|
-
/* @__PURE__ */
|
|
85
|
+
/* @__PURE__ */ _("div", {
|
|
92
86
|
className: "ds-edit-layout__actions",
|
|
93
|
-
children: [o ? /* @__PURE__ */
|
|
87
|
+
children: [o ? /* @__PURE__ */ g(t, {
|
|
94
88
|
variant: "danger",
|
|
95
89
|
size: "sm",
|
|
96
90
|
onClick: c,
|
|
@@ -100,13 +94,13 @@ function re({ backLabel: e, onBack: n, compact: r, status: i, actions: a, confir
|
|
|
100
94
|
]
|
|
101
95
|
});
|
|
102
96
|
}
|
|
103
|
-
function
|
|
104
|
-
return /* @__PURE__ */
|
|
97
|
+
function E({ label: e, detailsId: n, expanded: r, opensSheet: i, sheetOpen: a, toggleRef: o, contentRef: s, collapsed: c, onToggle: l }) {
|
|
98
|
+
return /* @__PURE__ */ _("aside", {
|
|
105
99
|
className: "ds-edit-layout__rail",
|
|
106
100
|
"aria-label": e,
|
|
107
|
-
children: [/* @__PURE__ */
|
|
101
|
+
children: [/* @__PURE__ */ _("header", {
|
|
108
102
|
className: "ds-edit-layout__rail-head",
|
|
109
|
-
children: [r && /* @__PURE__ */
|
|
103
|
+
children: [r && /* @__PURE__ */ g("span", { children: e }), /* @__PURE__ */ g(t, {
|
|
110
104
|
ref: o,
|
|
111
105
|
variant: "simple",
|
|
112
106
|
size: "sm",
|
|
@@ -119,13 +113,13 @@ function ie({ label: e, detailsId: n, expanded: r, opensSheet: i, sheetOpen: a,
|
|
|
119
113
|
"aria-haspopup": i ? "dialog" : void 0,
|
|
120
114
|
onClick: l
|
|
121
115
|
})]
|
|
122
|
-
}), r ? /* @__PURE__ */
|
|
116
|
+
}), r ? /* @__PURE__ */ g("div", {
|
|
123
117
|
id: n,
|
|
124
118
|
ref: s,
|
|
125
119
|
className: "ds-edit-layout__rail-content"
|
|
126
|
-
}) : /* @__PURE__ */
|
|
120
|
+
}) : /* @__PURE__ */ g("div", {
|
|
127
121
|
className: "ds-edit-layout__rail-icons",
|
|
128
|
-
children: c ? c(l) : /* @__PURE__ */
|
|
122
|
+
children: c ? c(l) : /* @__PURE__ */ g(t, {
|
|
129
123
|
variant: "simple",
|
|
130
124
|
size: "sm",
|
|
131
125
|
isIconOnly: !0,
|
|
@@ -136,117 +130,109 @@ function ie({ label: e, detailsId: n, expanded: r, opensSheet: i, sheetOpen: a,
|
|
|
136
130
|
})]
|
|
137
131
|
});
|
|
138
132
|
}
|
|
139
|
-
var
|
|
140
|
-
let
|
|
141
|
-
|
|
133
|
+
var D = c(function({ backLabel: e, onBack: c, saveState: h = "clean", savedAgo: v, actions: y, rail: b, railCollapsed: x, railLabel: S = "Details", railOpen: D, defaultRailOpen: O = !0, onRailToggle: k, confirmLeave: A = !1, confirmText: re = "Leave without saving?", onKeepEditing: ie, onLeave: ae, children: oe, className: se, onFocus: ce, ...j }, M) {
|
|
134
|
+
let N = f(null), P = ee(() => n(N, M), [M]), F = f(null), I = f(null), L = f(null), R = f(null), z = f(null), [B] = p(() => s("ds-edit-layout__rail-host")), [V, H] = p("wide"), [U, W] = p(O), [G, K] = p(!1), [le, q] = p(!1), J = u(), Y = V === "tight" || V === "compact", X = V !== "wide", Z = !X && (D ?? U);
|
|
135
|
+
G && (A || !X) && K(!1), d(() => {
|
|
142
136
|
let e;
|
|
143
|
-
return
|
|
144
|
-
let n =
|
|
145
|
-
n !== e && (e = n,
|
|
137
|
+
return a(N.current, (t) => {
|
|
138
|
+
let n = ne(t);
|
|
139
|
+
n !== e && (e = n, q(!1), H(n));
|
|
146
140
|
});
|
|
147
|
-
}, []),
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (V.parentNode === e) return;
|
|
155
|
-
let t = B.current, n = t instanceof HTMLElement && V.contains(t) && S(document.activeElement);
|
|
156
|
-
e.append(V), n && t.focus({ preventScroll: !0 });
|
|
157
|
-
}), o(() => {
|
|
158
|
-
let e = B.current;
|
|
159
|
-
e && S(e) && S(document.activeElement) && L.current?.focus({ preventScroll: !0 });
|
|
141
|
+
}, []), d(() => {
|
|
142
|
+
B && o(B, L.current ?? R.current, z.current);
|
|
143
|
+
}), l(() => {
|
|
144
|
+
let e = z.current;
|
|
145
|
+
e && r(e) && r(document.activeElement) && I.current?.focus({ preventScroll: !0 });
|
|
160
146
|
}, [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
147
|
+
V,
|
|
148
|
+
Z,
|
|
149
|
+
G
|
|
164
150
|
]);
|
|
165
|
-
let
|
|
166
|
-
|
|
167
|
-
},
|
|
168
|
-
return /* @__PURE__ */
|
|
169
|
-
...
|
|
170
|
-
ref:
|
|
171
|
-
className: ["ds-edit-layout",
|
|
172
|
-
"data-compact":
|
|
173
|
-
"data-tight":
|
|
174
|
-
"data-expanded":
|
|
175
|
-
"data-animate":
|
|
151
|
+
let Q = () => {
|
|
152
|
+
X ? K(!0) : (q(!0), W(!Z), k?.(!Z));
|
|
153
|
+
}, $ = typeof b == "function" ? b(() => m(() => K(!1))) : b;
|
|
154
|
+
return /* @__PURE__ */ _("div", {
|
|
155
|
+
...j,
|
|
156
|
+
ref: P,
|
|
157
|
+
className: ["ds-edit-layout", se].filter(Boolean).join(" "),
|
|
158
|
+
"data-compact": Y || void 0,
|
|
159
|
+
"data-tight": V === "tight" || void 0,
|
|
160
|
+
"data-expanded": Z || void 0,
|
|
161
|
+
"data-animate": le || void 0,
|
|
176
162
|
onFocus: (e) => {
|
|
177
|
-
|
|
163
|
+
z.current = e.target, ce?.(e);
|
|
178
164
|
},
|
|
179
165
|
children: [
|
|
180
|
-
/* @__PURE__ */
|
|
166
|
+
/* @__PURE__ */ _("div", {
|
|
181
167
|
className: "ds-edit-layout__main",
|
|
182
|
-
children: [/* @__PURE__ */
|
|
168
|
+
children: [/* @__PURE__ */ g(T, {
|
|
183
169
|
backLabel: e,
|
|
184
|
-
onBack:
|
|
185
|
-
compact:
|
|
186
|
-
status: /* @__PURE__ */
|
|
187
|
-
saveState:
|
|
188
|
-
savedAgo:
|
|
170
|
+
onBack: c,
|
|
171
|
+
compact: Y,
|
|
172
|
+
status: /* @__PURE__ */ g(C, {
|
|
173
|
+
saveState: h,
|
|
174
|
+
savedAgo: v
|
|
189
175
|
}),
|
|
190
|
-
actions:
|
|
191
|
-
confirmLeave:
|
|
192
|
-
confirmation: /* @__PURE__ */
|
|
193
|
-
text:
|
|
194
|
-
bodyRef:
|
|
195
|
-
onKeepEditing:
|
|
176
|
+
actions: y,
|
|
177
|
+
confirmLeave: A,
|
|
178
|
+
confirmation: /* @__PURE__ */ g(w, {
|
|
179
|
+
text: re,
|
|
180
|
+
bodyRef: F,
|
|
181
|
+
onKeepEditing: ie
|
|
196
182
|
}),
|
|
197
|
-
onLeave:
|
|
198
|
-
detailsToggle: /* @__PURE__ */
|
|
199
|
-
ref:
|
|
183
|
+
onLeave: ae,
|
|
184
|
+
detailsToggle: /* @__PURE__ */ g(t, {
|
|
185
|
+
ref: I,
|
|
200
186
|
variant: "simple",
|
|
201
187
|
size: "sm",
|
|
202
188
|
isIconOnly: !0,
|
|
203
189
|
iconStart: "info",
|
|
204
|
-
"aria-label":
|
|
190
|
+
"aria-label": S,
|
|
205
191
|
"aria-haspopup": "dialog",
|
|
206
|
-
"aria-expanded":
|
|
207
|
-
"aria-controls":
|
|
208
|
-
onClick:
|
|
192
|
+
"aria-expanded": G,
|
|
193
|
+
"aria-controls": J,
|
|
194
|
+
onClick: Q
|
|
209
195
|
})
|
|
210
|
-
}), /* @__PURE__ */
|
|
211
|
-
ref:
|
|
196
|
+
}), /* @__PURE__ */ g("div", {
|
|
197
|
+
ref: F,
|
|
212
198
|
className: "ds-edit-layout__body",
|
|
213
|
-
children: /* @__PURE__ */
|
|
199
|
+
children: /* @__PURE__ */ g("div", {
|
|
214
200
|
className: "ds-edit-layout__content",
|
|
215
|
-
children:
|
|
201
|
+
children: oe
|
|
216
202
|
})
|
|
217
203
|
})]
|
|
218
204
|
}),
|
|
219
|
-
!
|
|
220
|
-
label:
|
|
221
|
-
detailsId:
|
|
222
|
-
expanded:
|
|
223
|
-
opensSheet:
|
|
224
|
-
sheetOpen:
|
|
225
|
-
toggleRef:
|
|
226
|
-
contentRef:
|
|
227
|
-
collapsed:
|
|
228
|
-
onToggle:
|
|
205
|
+
!Y && /* @__PURE__ */ g(E, {
|
|
206
|
+
label: S,
|
|
207
|
+
detailsId: J,
|
|
208
|
+
expanded: Z,
|
|
209
|
+
opensSheet: X,
|
|
210
|
+
sheetOpen: G,
|
|
211
|
+
toggleRef: I,
|
|
212
|
+
contentRef: L,
|
|
213
|
+
collapsed: x,
|
|
214
|
+
onToggle: Q
|
|
229
215
|
}),
|
|
230
|
-
/* @__PURE__ */
|
|
231
|
-
id:
|
|
232
|
-
dir:
|
|
233
|
-
isOpen:
|
|
234
|
-
onClose: () =>
|
|
216
|
+
/* @__PURE__ */ g(i, {
|
|
217
|
+
id: X ? J : void 0,
|
|
218
|
+
dir: j.dir,
|
|
219
|
+
isOpen: G,
|
|
220
|
+
onClose: () => K(!1),
|
|
235
221
|
side: "end",
|
|
236
222
|
size: "md",
|
|
237
|
-
title:
|
|
238
|
-
closeLabel: `Close ${
|
|
223
|
+
title: S,
|
|
224
|
+
closeLabel: `Close ${S}`,
|
|
239
225
|
className: "ds-edit-layout__sheet",
|
|
240
|
-
children:
|
|
241
|
-
ref:
|
|
226
|
+
children: X && /* @__PURE__ */ g("div", {
|
|
227
|
+
ref: R,
|
|
242
228
|
className: "ds-edit-layout__rail-content"
|
|
243
229
|
})
|
|
244
230
|
}),
|
|
245
|
-
|
|
231
|
+
B && te($, B)
|
|
246
232
|
]
|
|
247
233
|
});
|
|
248
234
|
});
|
|
249
235
|
//#endregion
|
|
250
|
-
export {
|
|
236
|
+
export { D as EditLayout };
|
|
251
237
|
|
|
252
238
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_Fragment","Icon","mergeRefs","observeElementWidth","Fragment$1","TIGHT_WIDTH","COMPACT_WIDTH","WIDE_WIDTH","layoutMode","width","statusLabels","statusIcons","cannotHoldFocus","element","createRailHost","host","SaveStatus","icon","saveState","savedAgo","LeaveConfirmation","keepRef","useRef","origin","useEffect","frame","text","Button","onKeepEditing","bodyRef","EditActionBar","compact","backLabel","onBack","confirmLeave","confirmation","status","onLeave","actions","detailsToggle","DetailsRail","label","expanded","toggleRef","sheetOpen","detailsId","opensSheet","onToggle","contentRef","collapsed","EditLayout","forwardRef","rest","rootRef","mergedRef","useMemo","ref","railSlotRef","sheetSlotRef","lastFocus","railHost","useState","mode","setMode","localOpen","setLocalOpen","defaultRailOpen","sheet","setSheet","animate","setAnimate","useId","narrow","railOpen","useLayoutEffect","current","next","slot","focused","refocus","last","toggle","onRailToggle","railContent","rail","flushSync","className","event","onFocus","confirmText","railLabel","railCollapsed","Drawer","createPortal"],"sources":["../../../src/components/EditLayout/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n} from \"react\";\nimport { createPortal, flushSync } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport { Drawer } from \"../Drawer\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { observeElementWidth } from \"../../internal/observeElementWidth\";\nimport \"./style.css\";\n\nexport type EditSaveState = \"clean\" | \"dirty\" | \"saving\" | \"saved\" | \"error\" | \"offline\";\n\nexport interface EditLayoutProps extends HTMLAttributes<HTMLDivElement> {\n backLabel: string;\n onBack: () => void;\n saveState?: EditSaveState;\n savedAgo?: ReactNode;\n actions?: ReactNode;\n /** A render slot can close the Details sheet before opening another dialog. */\n rail: ReactNode | ((closeDetails: () => void) => ReactNode);\n /** Custom collapsed controls receive the accessible expand action. */\n railCollapsed?: (expand: () => void) => ReactNode;\n railLabel?: string;\n railOpen?: boolean;\n defaultRailOpen?: boolean;\n onRailToggle?: (open: boolean) => void;\n confirmLeave?: boolean;\n confirmText?: string;\n onKeepEditing?: () => void;\n onLeave?: () => void;\n children?: ReactNode;\n}\n\n/** Below this width, the action bar's gaps and padding contract. */\nconst TIGHT_WIDTH = 360;\n/** Below this width, Details opens from the action bar. */\nconst COMPACT_WIDTH = 600;\n/** From this width, the rail follows the open/closed preference. */\nconst WIDE_WIDTH = 900;\n\ntype LayoutMode = \"tight\" | \"compact\" | \"narrow\" | \"wide\";\n\nfunction layoutMode(width: number): LayoutMode {\n if (width < TIGHT_WIDTH) {\n return \"tight\";\n }\n if (width < COMPACT_WIDTH) {\n return \"compact\";\n }\n if (width < WIDE_WIDTH) {\n return \"narrow\";\n }\n return \"wide\";\n}\n\nconst statusLabels: Record<EditSaveState, string> = {\n clean: \"No changes\",\n dirty: \"Unsaved changes\",\n saving: \"Saving…\",\n saved: \"Saved\",\n error: \"Couldn't save\",\n offline: \"Offline · kept in this tab\",\n};\n\nconst statusIcons: Record<EditSaveState, IconName | undefined> = {\n clean: undefined,\n dirty: undefined,\n saving: \"spinner\",\n saved: \"check\",\n error: \"alert-triangle\",\n offline: \"clock\",\n};\n\n/** Removed, hidden and inert elements can't keep focus, and neither can the page. */\nfunction cannotHoldFocus(element: Element | null) {\n return (\n !element ||\n element === document.body ||\n !element.isConnected ||\n element.closest(\"[aria-hidden='true'], [inert]\") !== null\n );\n}\n\nfunction createRailHost() {\n if (typeof document === \"undefined\") {\n return null;\n }\n const host = document.createElement(\"div\");\n host.className = \"ds-edit-layout__rail-host\";\n return host;\n}\n\ninterface SaveStatusProps {\n saveState: EditSaveState;\n savedAgo?: ReactNode;\n}\n\nfunction SaveStatus({ saveState, savedAgo }: SaveStatusProps) {\n const icon = statusIcons[saveState];\n return (\n <div\n className=\"ds-edit-layout__status\"\n data-state={saveState}\n role=\"status\"\n aria-live=\"polite\"\n >\n {icon && (\n <Icon\n name={icon}\n className={saveState === \"saving\" ? \"ds-icon--spin\" : undefined}\n />\n )}\n {saveState === \"dirty\" && (\n <span\n className=\"ds-edit-layout__dirty\"\n aria-hidden=\"true\"\n />\n )}\n <span>\n {statusLabels[saveState]}\n {saveState === \"saved\" && savedAgo ? <> {savedAgo}</> : null}\n </span>\n </div>\n );\n}\n\ninterface LeaveConfirmationProps {\n text: string;\n /** Keep editing falls back to the first control here when its origin is gone. */\n bodyRef: RefObject<HTMLDivElement | null>;\n onKeepEditing?: () => void;\n}\n\n/** Takes focus while shown; Keep editing returns it to where the user was. */\nfunction LeaveConfirmation({ text, bodyRef, onKeepEditing }: LeaveConfirmationProps) {\n const keepRef = useRef<HTMLButtonElement>(null);\n const origin = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n origin.current = document.activeElement as HTMLElement | null;\n const frame = requestAnimationFrame(() => keepRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, []);\n\n const keepEditing = () => {\n onKeepEditing?.();\n requestAnimationFrame(() => {\n const destination = origin.current?.isConnected\n ? origin.current\n : bodyRef.current?.querySelector<HTMLElement>(\n \"input, textarea, button, [contenteditable='true']\",\n );\n destination?.focus({ preventScroll: true });\n });\n };\n\n return (\n <div className=\"ds-edit-layout__confirmation\">\n <strong>{text}</strong>\n <Button\n ref={keepRef}\n size=\"xs\"\n onClick={keepEditing}\n >\n Keep editing\n </Button>\n </div>\n );\n}\n\ninterface EditActionBarProps {\n backLabel: string;\n onBack: () => void;\n compact: boolean;\n status: ReactNode;\n actions?: ReactNode;\n /** Replaces the status and actions while set. */\n confirmLeave: boolean;\n confirmation: ReactNode;\n onLeave?: () => void;\n /** Shown only in compact layouts, where Details opens as a sheet. */\n detailsToggle: ReactNode;\n}\n\nfunction EditActionBar({\n backLabel,\n onBack,\n compact,\n status,\n actions,\n confirmLeave,\n confirmation,\n onLeave,\n detailsToggle,\n}: EditActionBarProps) {\n return (\n <header className=\"ds-edit-layout__bar\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n iconStart=\"arrow-left\"\n isIconOnly={compact}\n aria-label={`Back to ${backLabel}`}\n onClick={onBack}\n >\n {backLabel}\n </Button>\n {confirmLeave ? confirmation : status}\n <div className=\"ds-edit-layout__actions\">\n {confirmLeave ? (\n <Button\n variant=\"danger\"\n size=\"sm\"\n onClick={onLeave}\n >\n Leave anyway\n </Button>\n ) : (\n actions\n )}\n {compact && detailsToggle}\n </div>\n </header>\n );\n}\n\ninterface DetailsRailProps {\n label: string;\n detailsId: string;\n expanded: boolean;\n /** Below the wide breakpoint, the toggle opens the Details sheet instead. */\n opensSheet: boolean;\n sheetOpen: boolean;\n toggleRef: RefObject<HTMLButtonElement | null>;\n /** Receives the rail content while the rail is expanded. */\n contentRef: RefObject<HTMLDivElement | null>;\n collapsed?: (expand: () => void) => ReactNode;\n onToggle: () => void;\n}\n\nfunction DetailsRail({\n label,\n detailsId,\n expanded,\n opensSheet,\n sheetOpen,\n toggleRef,\n contentRef,\n collapsed,\n onToggle,\n}: DetailsRailProps) {\n return (\n <aside\n className=\"ds-edit-layout__rail\"\n aria-label={label}\n >\n <header className=\"ds-edit-layout__rail-head\">\n {expanded && <span>{label}</span>}\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart={expanded ? \"chevrons-right\" : \"chevrons-left\"}\n className=\"ds-edit-layout__toggle\"\n aria-label={`${expanded ? \"Collapse\" : \"Expand\"} ${label}`}\n aria-expanded={expanded || sheetOpen}\n aria-controls={detailsId}\n aria-haspopup={opensSheet ? \"dialog\" : undefined}\n onClick={onToggle}\n />\n </header>\n {expanded ? (\n <div\n id={detailsId}\n ref={contentRef}\n className=\"ds-edit-layout__rail-content\"\n />\n ) : (\n <div className=\"ds-edit-layout__rail-icons\">\n {collapsed ? (\n collapsed(onToggle)\n ) : (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={`Show ${label}`}\n onClick={onToggle}\n />\n )}\n </div>\n )}\n </aside>\n );\n}\n\n/** Presentation only: the consumer owns saving, routing and persisted preferences. */\nexport const EditLayout = forwardRef<HTMLDivElement, EditLayoutProps>(function EditLayout(\n {\n backLabel,\n onBack,\n saveState = \"clean\",\n savedAgo,\n actions,\n rail,\n railCollapsed,\n railLabel = \"Details\",\n railOpen,\n defaultRailOpen = true,\n onRailToggle,\n confirmLeave = false,\n confirmText = \"Leave without saving?\",\n onKeepEditing,\n onLeave,\n children,\n className,\n onFocus,\n ...rest\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMemo(() => mergeRefs(rootRef, ref), [ref]);\n const bodyRef = useRef<HTMLDivElement>(null);\n const toggleRef = useRef<HTMLButtonElement>(null);\n const railSlotRef = useRef<HTMLDivElement>(null);\n const sheetSlotRef = useRef<HTMLDivElement>(null);\n const lastFocus = useRef<Element | null>(null);\n // Rail content renders once, into a node that moves between the rail and\n // the sheet, so uncontrolled fields keep their values across modes.\n const [railHost] = useState(createRailHost);\n const [mode, setMode] = useState<LayoutMode>(\"wide\");\n const [localOpen, setLocalOpen] = useState(defaultRailOpen);\n const [sheet, setSheet] = useState(false);\n const [animate, setAnimate] = useState(false);\n const detailsId = useId();\n const compact = mode === \"tight\" || mode === \"compact\";\n const narrow = mode !== \"wide\";\n const expanded = !narrow && (railOpen ?? localOpen);\n\n // Leave confirmation and the wide rail both replace the Details sheet.\n if (sheet && (confirmLeave || !narrow)) {\n setSheet(false);\n }\n\n // Measure before the first paint, then re-render only when a breakpoint is crossed.\n useLayoutEffect(() => {\n let current: LayoutMode | undefined;\n return observeElementWidth(rootRef.current!, (width) => {\n const next = layoutMode(width);\n if (next === current) {\n return;\n }\n current = next;\n // Crossing a breakpoint is not a deliberate toggle, so it doesn't animate.\n setAnimate(false);\n setMode(next);\n });\n }, []);\n\n useLayoutEffect(() => {\n if (!railHost) {\n return;\n }\n const slot = railSlotRef.current ?? sheetSlotRef.current;\n if (!slot) {\n railHost.remove();\n return;\n }\n if (railHost.parentNode === slot) {\n return;\n }\n // Moving a node drops its focus; keep the user in the field they were in.\n const focused = lastFocus.current;\n const refocus =\n focused instanceof HTMLElement &&\n railHost.contains(focused) &&\n cannotHoldFocus(document.activeElement);\n slot.append(railHost);\n if (refocus) {\n focused.focus({ preventScroll: true });\n }\n });\n\n // A breakpoint, a collapse or a closing sheet can remove the focused control.\n // Hand focus to the Details toggle that replaced it.\n useEffect(() => {\n const last = lastFocus.current;\n if (last && cannotHoldFocus(last) && cannotHoldFocus(document.activeElement)) {\n toggleRef.current?.focus({ preventScroll: true });\n }\n }, [mode, expanded, sheet]);\n\n const toggle = () => {\n if (narrow) {\n setSheet(true);\n return;\n }\n setAnimate(true);\n setLocalOpen(!expanded);\n onRailToggle?.(!expanded);\n };\n const closeDetails = () => flushSync(() => setSheet(false));\n const railContent = typeof rail === \"function\" ? rail(closeDetails) : rail;\n\n return (\n <div\n {...rest}\n ref={mergedRef}\n className={[\"ds-edit-layout\", className].filter(Boolean).join(\" \")}\n data-compact={compact || undefined}\n data-tight={mode === \"tight\" || undefined}\n data-expanded={expanded || undefined}\n data-animate={animate || undefined}\n onFocus={(event) => {\n lastFocus.current = event.target;\n onFocus?.(event);\n }}\n >\n <div className=\"ds-edit-layout__main\">\n <EditActionBar\n backLabel={backLabel}\n onBack={onBack}\n compact={compact}\n status={\n <SaveStatus\n saveState={saveState}\n savedAgo={savedAgo}\n />\n }\n actions={actions}\n confirmLeave={confirmLeave}\n confirmation={\n <LeaveConfirmation\n text={confirmText}\n bodyRef={bodyRef}\n onKeepEditing={onKeepEditing}\n />\n }\n onLeave={onLeave}\n detailsToggle={\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={railLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={sheet}\n aria-controls={detailsId}\n onClick={toggle}\n />\n }\n />\n <div\n ref={bodyRef}\n className=\"ds-edit-layout__body\"\n >\n <div className=\"ds-edit-layout__content\">{children}</div>\n </div>\n </div>\n {!compact && (\n <DetailsRail\n label={railLabel}\n detailsId={detailsId}\n expanded={expanded}\n opensSheet={narrow}\n sheetOpen={sheet}\n toggleRef={toggleRef}\n contentRef={railSlotRef}\n collapsed={railCollapsed}\n onToggle={toggle}\n />\n )}\n <Drawer\n id={narrow ? detailsId : undefined}\n dir={rest.dir}\n isOpen={sheet}\n onClose={() => setSheet(false)}\n side=\"end\"\n size=\"md\"\n title={railLabel}\n closeLabel={`Close ${railLabel}`}\n className=\"ds-edit-layout__sheet\"\n >\n {narrow && (\n <div\n ref={sheetSlotRef}\n className=\"ds-edit-layout__rail-content\"\n />\n )}\n </Drawer>\n {railHost && createPortal(railContent, railHost)}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;AA6CA,IAAMK,IAAc,KAEdC,IAAgB,KAEhBC,IAAa;AAInB,SAASC,EAAW,GAA2B;CAU7C,OATIC,IAAQJ,IACH,UAELI,IAAQH,IACH,YAELG,IAAQF,IACH,WAEF;AACT;AAEA,IAAMG,IAA8C;CAClD,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,SAAS;AACX,GAEMC,IAA2D;CAC/D,OAAO,KAAA;CACP,OAAO,KAAA;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,SAAS;AACX;AAGA,SAASC,EAAgB,GAAyB;CAChD,OACE,CAACC,KACDA,MAAY,SAAS,QACrB,CAACA,EAAQ,eACTA,EAAQ,QAAQ,+BAA+B,MAAM;AAEzD;AAEA,SAASC,IAAiB;CACxB,IAAI,OAAO,WAAa,KACtB,OAAO;CAET,IAAMC,IAAO,SAAS,cAAc,KAAK;CAEzC,OADA,EAAK,YAAY,6BACVA;AACT;AAOA,SAASC,GAAW,EAAE,cAAW,eAA6B;CAC5D,IAAMC,IAAON,EAAYO;CACzB,OACE,kBAAC,OAAD;EACE,WAAU;EACV,cAAYA;EACZ,MAAK;EACL,aAAU;EAJZ,UAAA;GAMGD,KACC,kBAAChB,GAAD;IACE,MAAMgB;IACN,WAAWC,MAAc,WAAW,kBAAkB,KAAA;GACvD,CAAA;GAEFA,MAAc,WACb,kBAAC,QAAD;IACE,WAAU;IACV,eAAY;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U;IAET,UAAAlB,KACC,kBAAC,OAAD;KACE,KAAKd;KACL,WAAU;IACX,CAAA;GAEG,CAAA;GACPE,KAAYiC,GAAaV,IAAavB,CAAQ;EAC5C;;AAET,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_Fragment","Icon","mergeRefs","cannotHoldFocus","observeElementWidth","moveHost","createMovableHost","Fragment$1","TIGHT_WIDTH","COMPACT_WIDTH","WIDE_WIDTH","layoutMode","width","statusLabels","statusIcons","SaveStatus","icon","saveState","savedAgo","LeaveConfirmation","keepRef","useRef","origin","useEffect","frame","text","Button","onKeepEditing","bodyRef","EditActionBar","compact","backLabel","onBack","confirmLeave","confirmation","status","onLeave","actions","detailsToggle","DetailsRail","label","expanded","toggleRef","sheetOpen","detailsId","opensSheet","onToggle","contentRef","collapsed","EditLayout","forwardRef","rest","rootRef","mergedRef","useMemo","ref","railSlotRef","sheetSlotRef","lastFocus","railHost","useState","mode","setMode","localOpen","setLocalOpen","defaultRailOpen","sheet","setSheet","animate","setAnimate","useId","narrow","railOpen","useLayoutEffect","current","next","last","toggle","onRailToggle","railContent","rail","flushSync","className","event","onFocus","confirmText","railLabel","railCollapsed","Drawer","createPortal"],"sources":["../../../src/components/EditLayout/index.tsx"],"sourcesContent":["import {\n forwardRef,\n useEffect,\n useId,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n} from \"react\";\nimport { createPortal, flushSync } from \"react-dom\";\nimport { Button } from \"../Button\";\nimport { Drawer } from \"../Drawer\";\nimport { Icon } from \"../Icon\";\nimport type { IconName } from \"../Icon/icons\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { observeElementWidth } from \"../../internal/observeElementWidth\";\nimport { cannotHoldFocus } from \"../../internal/dialogFocus\";\nimport { createMovableHost, moveHost } from \"../../internal/movableHost\";\nimport \"./style.css\";\n\nexport type EditSaveState = \"clean\" | \"dirty\" | \"saving\" | \"saved\" | \"error\" | \"offline\";\n\nexport interface EditLayoutProps extends HTMLAttributes<HTMLDivElement> {\n backLabel: string;\n onBack: () => void;\n saveState?: EditSaveState;\n savedAgo?: ReactNode;\n actions?: ReactNode;\n /** A render slot can close the Details sheet before opening another dialog. */\n rail: ReactNode | ((closeDetails: () => void) => ReactNode);\n /** Custom collapsed controls receive the accessible expand action. */\n railCollapsed?: (expand: () => void) => ReactNode;\n railLabel?: string;\n railOpen?: boolean;\n defaultRailOpen?: boolean;\n onRailToggle?: (open: boolean) => void;\n confirmLeave?: boolean;\n confirmText?: string;\n onKeepEditing?: () => void;\n onLeave?: () => void;\n children?: ReactNode;\n}\n\n/** Below this width, the action bar's gaps and padding contract. */\nconst TIGHT_WIDTH = 360;\n/** Below this width, Details opens from the action bar. */\nconst COMPACT_WIDTH = 600;\n/** From this width, the rail follows the open/closed preference. */\nconst WIDE_WIDTH = 900;\n\ntype LayoutMode = \"tight\" | \"compact\" | \"narrow\" | \"wide\";\n\nfunction layoutMode(width: number): LayoutMode {\n if (width < TIGHT_WIDTH) {\n return \"tight\";\n }\n if (width < COMPACT_WIDTH) {\n return \"compact\";\n }\n if (width < WIDE_WIDTH) {\n return \"narrow\";\n }\n return \"wide\";\n}\n\nconst statusLabels: Record<EditSaveState, string> = {\n clean: \"No changes\",\n dirty: \"Unsaved changes\",\n saving: \"Saving…\",\n saved: \"Saved\",\n error: \"Couldn't save\",\n offline: \"Offline · kept in this tab\",\n};\n\nconst statusIcons: Record<EditSaveState, IconName | undefined> = {\n clean: undefined,\n dirty: undefined,\n saving: \"spinner\",\n saved: \"check\",\n error: \"alert-triangle\",\n offline: \"clock\",\n};\n\ninterface SaveStatusProps {\n saveState: EditSaveState;\n savedAgo?: ReactNode;\n}\n\nfunction SaveStatus({ saveState, savedAgo }: SaveStatusProps) {\n const icon = statusIcons[saveState];\n return (\n <div\n className=\"ds-edit-layout__status\"\n data-state={saveState}\n role=\"status\"\n aria-live=\"polite\"\n >\n {icon && (\n <Icon\n name={icon}\n className={saveState === \"saving\" ? \"ds-icon--spin\" : undefined}\n />\n )}\n {saveState === \"dirty\" && (\n <span\n className=\"ds-edit-layout__dirty\"\n aria-hidden=\"true\"\n />\n )}\n <span>\n {statusLabels[saveState]}\n {saveState === \"saved\" && savedAgo ? <> {savedAgo}</> : null}\n </span>\n </div>\n );\n}\n\ninterface LeaveConfirmationProps {\n text: string;\n /** Keep editing falls back to the first control here when its origin is gone. */\n bodyRef: RefObject<HTMLDivElement | null>;\n onKeepEditing?: () => void;\n}\n\n/** Takes focus while shown; Keep editing returns it to where the user was. */\nfunction LeaveConfirmation({ text, bodyRef, onKeepEditing }: LeaveConfirmationProps) {\n const keepRef = useRef<HTMLButtonElement>(null);\n const origin = useRef<HTMLElement | null>(null);\n\n useEffect(() => {\n origin.current = document.activeElement as HTMLElement | null;\n const frame = requestAnimationFrame(() => keepRef.current?.focus({ preventScroll: true }));\n return () => cancelAnimationFrame(frame);\n }, []);\n\n const keepEditing = () => {\n onKeepEditing?.();\n requestAnimationFrame(() => {\n const destination = origin.current?.isConnected\n ? origin.current\n : bodyRef.current?.querySelector<HTMLElement>(\n \"input, textarea, button, [contenteditable='true']\",\n );\n destination?.focus({ preventScroll: true });\n });\n };\n\n return (\n <div className=\"ds-edit-layout__confirmation\">\n <strong>{text}</strong>\n <Button\n ref={keepRef}\n size=\"xs\"\n onClick={keepEditing}\n >\n Keep editing\n </Button>\n </div>\n );\n}\n\ninterface EditActionBarProps {\n backLabel: string;\n onBack: () => void;\n compact: boolean;\n status: ReactNode;\n actions?: ReactNode;\n /** Replaces the status and actions while set. */\n confirmLeave: boolean;\n confirmation: ReactNode;\n onLeave?: () => void;\n /** Shown only in compact layouts, where Details opens as a sheet. */\n detailsToggle: ReactNode;\n}\n\nfunction EditActionBar({\n backLabel,\n onBack,\n compact,\n status,\n actions,\n confirmLeave,\n confirmation,\n onLeave,\n detailsToggle,\n}: EditActionBarProps) {\n return (\n <header className=\"ds-edit-layout__bar\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n iconStart=\"arrow-left\"\n isIconOnly={compact}\n aria-label={`Back to ${backLabel}`}\n onClick={onBack}\n >\n {backLabel}\n </Button>\n {confirmLeave ? confirmation : status}\n <div className=\"ds-edit-layout__actions\">\n {confirmLeave ? (\n <Button\n variant=\"danger\"\n size=\"sm\"\n onClick={onLeave}\n >\n Leave anyway\n </Button>\n ) : (\n actions\n )}\n {compact && detailsToggle}\n </div>\n </header>\n );\n}\n\ninterface DetailsRailProps {\n label: string;\n detailsId: string;\n expanded: boolean;\n /** Below the wide breakpoint, the toggle opens the Details sheet instead. */\n opensSheet: boolean;\n sheetOpen: boolean;\n toggleRef: RefObject<HTMLButtonElement | null>;\n /** Receives the rail content while the rail is expanded. */\n contentRef: RefObject<HTMLDivElement | null>;\n collapsed?: (expand: () => void) => ReactNode;\n onToggle: () => void;\n}\n\nfunction DetailsRail({\n label,\n detailsId,\n expanded,\n opensSheet,\n sheetOpen,\n toggleRef,\n contentRef,\n collapsed,\n onToggle,\n}: DetailsRailProps) {\n return (\n <aside\n className=\"ds-edit-layout__rail\"\n aria-label={label}\n >\n <header className=\"ds-edit-layout__rail-head\">\n {expanded && <span>{label}</span>}\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart={expanded ? \"chevrons-right\" : \"chevrons-left\"}\n className=\"ds-edit-layout__toggle\"\n aria-label={`${expanded ? \"Collapse\" : \"Expand\"} ${label}`}\n aria-expanded={expanded || sheetOpen}\n aria-controls={detailsId}\n aria-haspopup={opensSheet ? \"dialog\" : undefined}\n onClick={onToggle}\n />\n </header>\n {expanded ? (\n <div\n id={detailsId}\n ref={contentRef}\n className=\"ds-edit-layout__rail-content\"\n />\n ) : (\n <div className=\"ds-edit-layout__rail-icons\">\n {collapsed ? (\n collapsed(onToggle)\n ) : (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={`Show ${label}`}\n onClick={onToggle}\n />\n )}\n </div>\n )}\n </aside>\n );\n}\n\n/** Presentation only: the consumer owns saving, routing and persisted preferences. */\nexport const EditLayout = forwardRef<HTMLDivElement, EditLayoutProps>(function EditLayout(\n {\n backLabel,\n onBack,\n saveState = \"clean\",\n savedAgo,\n actions,\n rail,\n railCollapsed,\n railLabel = \"Details\",\n railOpen,\n defaultRailOpen = true,\n onRailToggle,\n confirmLeave = false,\n confirmText = \"Leave without saving?\",\n onKeepEditing,\n onLeave,\n children,\n className,\n onFocus,\n ...rest\n },\n ref,\n) {\n const rootRef = useRef<HTMLDivElement>(null);\n const mergedRef = useMemo(() => mergeRefs(rootRef, ref), [ref]);\n const bodyRef = useRef<HTMLDivElement>(null);\n const toggleRef = useRef<HTMLButtonElement>(null);\n const railSlotRef = useRef<HTMLDivElement>(null);\n const sheetSlotRef = useRef<HTMLDivElement>(null);\n const lastFocus = useRef<Element | null>(null);\n // Rail content renders once, into a node that moves between the rail and\n // the sheet, so uncontrolled fields keep their values across modes.\n const [railHost] = useState(() => createMovableHost(\"ds-edit-layout__rail-host\"));\n const [mode, setMode] = useState<LayoutMode>(\"wide\");\n const [localOpen, setLocalOpen] = useState(defaultRailOpen);\n const [sheet, setSheet] = useState(false);\n const [animate, setAnimate] = useState(false);\n const detailsId = useId();\n const compact = mode === \"tight\" || mode === \"compact\";\n const narrow = mode !== \"wide\";\n const expanded = !narrow && (railOpen ?? localOpen);\n\n // Leave confirmation and the wide rail both replace the Details sheet.\n if (sheet && (confirmLeave || !narrow)) {\n setSheet(false);\n }\n\n // Measure before the first paint, then re-render only when a breakpoint is crossed.\n useLayoutEffect(() => {\n let current: LayoutMode | undefined;\n return observeElementWidth(rootRef.current!, (width) => {\n const next = layoutMode(width);\n if (next === current) {\n return;\n }\n current = next;\n // Crossing a breakpoint is not a deliberate toggle, so it doesn't animate.\n setAnimate(false);\n setMode(next);\n });\n }, []);\n\n // Moving a node drops its focus; keep the user in the field they were in.\n useLayoutEffect(() => {\n if (railHost) {\n moveHost(railHost, railSlotRef.current ?? sheetSlotRef.current, lastFocus.current);\n }\n });\n\n // A breakpoint, a collapse or a closing sheet can remove the focused control.\n // Hand focus to the Details toggle that replaced it.\n useEffect(() => {\n const last = lastFocus.current;\n if (last && cannotHoldFocus(last) && cannotHoldFocus(document.activeElement)) {\n toggleRef.current?.focus({ preventScroll: true });\n }\n }, [mode, expanded, sheet]);\n\n const toggle = () => {\n if (narrow) {\n setSheet(true);\n return;\n }\n setAnimate(true);\n setLocalOpen(!expanded);\n onRailToggle?.(!expanded);\n };\n const closeDetails = () => flushSync(() => setSheet(false));\n const railContent = typeof rail === \"function\" ? rail(closeDetails) : rail;\n\n return (\n <div\n {...rest}\n ref={mergedRef}\n className={[\"ds-edit-layout\", className].filter(Boolean).join(\" \")}\n data-compact={compact || undefined}\n data-tight={mode === \"tight\" || undefined}\n data-expanded={expanded || undefined}\n data-animate={animate || undefined}\n onFocus={(event) => {\n lastFocus.current = event.target;\n onFocus?.(event);\n }}\n >\n <div className=\"ds-edit-layout__main\">\n <EditActionBar\n backLabel={backLabel}\n onBack={onBack}\n compact={compact}\n status={\n <SaveStatus\n saveState={saveState}\n savedAgo={savedAgo}\n />\n }\n actions={actions}\n confirmLeave={confirmLeave}\n confirmation={\n <LeaveConfirmation\n text={confirmText}\n bodyRef={bodyRef}\n onKeepEditing={onKeepEditing}\n />\n }\n onLeave={onLeave}\n detailsToggle={\n <Button\n ref={toggleRef}\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"info\"\n aria-label={railLabel}\n aria-haspopup=\"dialog\"\n aria-expanded={sheet}\n aria-controls={detailsId}\n onClick={toggle}\n />\n }\n />\n <div\n ref={bodyRef}\n className=\"ds-edit-layout__body\"\n >\n <div className=\"ds-edit-layout__content\">{children}</div>\n </div>\n </div>\n {!compact && (\n <DetailsRail\n label={railLabel}\n detailsId={detailsId}\n expanded={expanded}\n opensSheet={narrow}\n sheetOpen={sheet}\n toggleRef={toggleRef}\n contentRef={railSlotRef}\n collapsed={railCollapsed}\n onToggle={toggle}\n />\n )}\n <Drawer\n id={narrow ? detailsId : undefined}\n dir={rest.dir}\n isOpen={sheet}\n onClose={() => setSheet(false)}\n side=\"end\"\n size=\"md\"\n title={railLabel}\n closeLabel={`Close ${railLabel}`}\n className=\"ds-edit-layout__sheet\"\n >\n {narrow && (\n <div\n ref={sheetSlotRef}\n className=\"ds-edit-layout__rail-content\"\n />\n )}\n </Drawer>\n {railHost && createPortal(railContent, railHost)}\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;AA+CA,IAAMQ,IAAc,KAEdC,IAAgB,KAEhBC,IAAa;AAInB,SAASC,GAAW,GAA2B;CAU7C,OATIC,IAAQJ,IACH,UAELI,IAAQH,IACH,YAELG,IAAQF,IACH,WAEF;AACT;AAEA,IAAMG,IAA8C;CAClD,OAAO;CACP,OAAO;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,SAAS;AACX,GAEMC,IAA2D;CAC/D,OAAO,KAAA;CACP,OAAO,KAAA;CACP,QAAQ;CACR,OAAO;CACP,OAAO;CACP,SAAS;AACX;AAOA,SAASC,EAAW,EAAE,cAAW,eAA6B;CAC5D,IAAMC,IAAOF,EAAYG;CACzB,OACE,kBAAC,OAAD;EACE,WAAU;EACV,cAAYA;EACZ,MAAK;EACL,aAAU;EAJZ,UAAA;GAMGD,KACC,kBAACf,GAAD;IACE,MAAMe;IACN,WAAWC,MAAc,WAAW,kBAAkB,KAAA;GACvD,CAAA;GAEFA,MAAc,WACb,kBAAC,QAAD;IACE,WAAU;IACV,eAAY;GACb,CAAA;GAEH,kBAAC,QAAD,EAAA,UAAA,CACGJ,EAAaI,IACbA,MAAc,WAAWC,IAAW,kBAAAlB,GAAA,EAAA,UAAA,CAAE,KAAEkB,CAAW,EAAA,CAAA,IAAI,IACpD,EAAA,CAAA;EACH;;AAET;AAUA,SAASC,EAAkB,EAAE,SAAM,YAAS,oBAAyC;CACnF,IAAMC,IAAUC,EAA0B,IAAI,GACxCC,IAASD,EAA2B,IAAI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MACa;MACD;KACX,CAAA;KAEM;KACK;KACd,cACE,kBAACI,GAAD;MACE,MAAMkE;MACG;MACM;KAChB,CAAA;KAEM;KACT,eACE,kBAAC3D,GAAD;MACE,KAAKgB;MACL,SAAQ;MACR,MAAK;MACL,YAAA;MACA,WAAU;MACV,cAAY4C;MACZ,iBAAc;MACd,iBAAepB;MACf,iBAAetB;MACf,SAASiC;KACV,CAAA;IAEJ,CAAA,GACD,kBAAC,OAAD;KACE,KAAKjD;KACL,WAAU;KAEV,UAAA,kBAAC,OAAD;MAAK,WAAU;MAA2B;KAAc,CAAA;IACrD,CAAA,CACF;;GACJ,CAACE,KACA,kBAACS,GAAD;IACE,OAAO+C;IACI;IACD;IACV,YAAYf;IACZ,WAAWL;IACA;IACX,YAAYV;IACZ,WAAW+B;IACX,UAAUV;GACX,CAAA;GAEH,kBAACW,GAAD;IACE,IAAIjB,IAAS3B,IAAY,KAAA;IACzB,KAAKO,EAAK;IACV,QAAQe;IACR,eAAeC,EAAS,EAAK;IAC7B,MAAK;IACL,MAAK;IACL,OAAOmB;IACP,YAAY,SAASA;IACrB,WAAU;IAET,UAAAf,KACC,kBAAC,OAAD;KACE,KAAKd;KACL,WAAU;IACX,CAAA;GAEG,CAAA;GACPE,KAAY8B,GAAaV,GAAapB,CAAQ;EAC5C;;AAET,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../../chunks/Icon-D38lQXNe.cjs"),t=require("../Button/index.cjs"),n=require("../Modal/index.cjs"),r=require("../../chunks/group-pKDQtq-9.cjs"),i=require("../SearchField/index.cjs"),a=require("../SortableList/index.cjs");let o=require("react"),s=require("react/jsx-runtime");function c(...e){return e.filter(Boolean).join(` `)}function l(e,t){return!t||[e.title,e.subtitle,...e.keywords??[]].filter(Boolean).join(` `).toLowerCase().includes(t.toLowerCase())}function u({item:t}){return(0,s.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,s.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,s.jsx)(e.t,{name:`file-text`,size:20})})}function d({items:d,value:f,defaultValue:p=[],onValueChange:m,mode:h=`multiple`,max:g,label:_=`Entries`,emptyLabel:v=`Nothing selected yet.`,addLabel:y=`Choose entries`,itemLabel:b=`entry`,itemsLabel:x=`entries`,isReorderable:S=!0,isDisabled:C=!1,className:w,...T}){let[E,D]=(0,o.useState)(p),O=f??E,[k,A]=(0,o.useState)(!1),[j,M]=(0,o.useState)(``),N=(0,o.useMemo)(()=>new Map(d.map(e=>[e.id,e])),[d]),P=(0,o.useMemo)(()=>d.filter(e=>l(e,j)),[d,j]),F=h===`multiple`&&g!==void 0&&O.length>=g,I=e=>{C||(f===void 0&&D(e),m?.(e))},L=e=>{h===`single`?(I(O[0]===e?[]:[e]),A(!1)):O.includes(e)?I(O.filter(t=>t!==e)):F||I([...O,e])},R=O.map(e=>N.get(e)??{id:e,title:e}),z=S&&h===`multiple`&&R.length>1,B=e=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(u,{item:e}),(0,s.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,s.jsx)(`span`,{className:`ds-entry__title`,children:e.title}),e.subtitle&&(0,s.jsx)(`span`,{className:`ds-entry__subtitle`,children:e.subtitle})]})]});return(0,s.jsxs)(r.t,{...T,className:c(`ds-entry-picker`,w),label:_,count:O.length,children:[R.length===0?(0,s.jsx)(`p`,{className:`ds-entry-picker__empty`,children:v}):z?(0,s.jsx)(a.SortableList,{items:O,onReorder:I,isDisabled:C,children:R.map(e=>(0,s.jsx)(a.SortableListItem,{id:e.id,label:e.title,action:(0,s.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${e.title}`,isDisabled:C,onClick:()=>I(O.filter(t=>t!==e.id))}),children:(0,s.jsx)(`div`,{className:`ds-entry`,children:B(e)})},e.id))}):(0,s.jsx)(`ul`,{className:`ds-entry-picker__list`,children:R.map(e=>(0,s.jsxs)(`li`,{className:`ds-entry-picker__row`,children:[(0,s.jsx)(`div`,{className:`ds-entry`,children:B(e)}),(0,s.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${e.title}`,isDisabled:C,onClick:()=>I(O.filter(t=>t!==e.id))})]},e.id))}),(0,s.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,s.jsx)(t.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:C,onClick:()=>A(!0),children:y}),O.length>0&&(0,s.jsx)(t.Button,{variant:`simple`,size:`sm`,isDisabled:C,onClick:()=>I([]),children:`Clear`})]}),(0,s.jsxs)(n.Modal,{isOpen:k,onClose:()=>A(!1),title:y,description:h===`single`?`Choose one ${b}.`:g===void 0?`Choose as many ${x} as you need.`:`Choose up to ${g} ${x}.`,footer:(0,s.jsx)(t.Button,{variant:`primary`,onClick:()=>A(!1),children:`Done`}),children:[(0,s.jsx)(`div`,{className:`ds-entry-picker__search`,children:(0,s.jsx)(i.SearchField,{value:j,placeholder:`Search ${x}`,onChange:e=>M(e.target.value),onClear:()=>M(``)})}),(0,s.jsxs)(`ul`,{className:`ds-entry-picker__results`,children:[P.map(n=>{let r=O.includes(n.id),i=C||n.isDisabled||!r&&F;return(0,s.jsx)(`li`,{children:(0,s.jsxs)(t.Button,{variant:r?`active`:`simple`,size:`lg`,className:`ds-entry-picker__result`,"aria-pressed":r,isDisabled:!!i,onClick:()=>L(n.id),children:[(0,s.jsx)(`span`,{className:`ds-entry`,children:B(n)}),r&&(0,s.jsx)(e.t,{name:`check`,size:20})]})},n.id)}),P.length===0&&(0,s.jsxs)(`li`,{className:`ds-entry-picker__no-results`,children:[`No `,x,` match “`,j,`”.`]})]})]})]})}exports.EntryPicker=d;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|