@namroodinc/liquid-editorial 0.12.0 → 0.13.1
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 +90 -0
- package/dist/chunks/{Avatar-DPnrvkwd.cjs → Avatar-BY0dAItT.cjs} +2 -2
- package/dist/chunks/{Avatar-DPnrvkwd.cjs.map → Avatar-BY0dAItT.cjs.map} +1 -1
- package/dist/chunks/{Avatar-BK8IdL5W.js → Avatar-UjhjcHh5.js} +2 -2
- package/dist/chunks/{Avatar-BK8IdL5W.js.map → Avatar-UjhjcHh5.js.map} +1 -1
- package/dist/chunks/{Board-BCS7sDXg.js → Board-6fXt1YFp.js} +2 -2
- package/dist/chunks/{Board-BCS7sDXg.js.map → Board-6fXt1YFp.js.map} +1 -1
- package/dist/chunks/{Board-CNVy8gHI.cjs → Board-DfVQSb_L.cjs} +2 -2
- package/dist/chunks/{Board-CNVy8gHI.cjs.map → Board-DfVQSb_L.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-DrszOUOt.cjs → CollectionView-CIJdNwcq.cjs} +2 -2
- package/dist/chunks/{CollectionView-DrszOUOt.cjs.map → CollectionView-CIJdNwcq.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-B0ZJxkNK.js → CollectionView-JRNdXHti.js} +2 -2
- package/dist/chunks/{CollectionView-B0ZJxkNK.js.map → CollectionView-JRNdXHti.js.map} +1 -1
- package/dist/chunks/{ColourField-C39pcjkG.js → ColourField-YaCEWiPA.js} +147 -153
- package/dist/chunks/ColourField-YaCEWiPA.js.map +1 -0
- package/dist/chunks/ColourField-bgi6TLOM.cjs +2 -0
- package/dist/chunks/ColourField-bgi6TLOM.cjs.map +1 -0
- package/dist/chunks/{DatePicker-Dpvfomrm.cjs → DatePicker-CCygKPuy.cjs} +2 -2
- package/dist/chunks/{DatePicker-Dpvfomrm.cjs.map → DatePicker-CCygKPuy.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-DDc1nDTb.js → DatePicker-CHJYSaLU.js} +22 -22
- package/dist/chunks/{DatePicker-DDc1nDTb.js.map → DatePicker-CHJYSaLU.js.map} +1 -1
- package/dist/chunks/{Drawer-C3mWT9Kh.js → Drawer-Ck5XKT_V.js} +3 -3
- package/dist/chunks/{Drawer-C3mWT9Kh.js.map → Drawer-Ck5XKT_V.js.map} +1 -1
- package/dist/chunks/{Drawer-DTKZptua.cjs → Drawer-DdIH9jpe.cjs} +2 -2
- package/dist/chunks/{Drawer-DTKZptua.cjs.map → Drawer-DdIH9jpe.cjs.map} +1 -1
- package/dist/chunks/{EntryPicker-CgWbgWnc.cjs → EntryPicker-DmiAnu9l.cjs} +2 -2
- package/dist/chunks/{EntryPicker-CgWbgWnc.cjs.map → EntryPicker-DmiAnu9l.cjs.map} +1 -1
- package/dist/chunks/{EntryPicker-DlEsVCvA.js → EntryPicker-WERMwe0h.js} +3 -3
- package/dist/chunks/{EntryPicker-DlEsVCvA.js.map → EntryPicker-WERMwe0h.js.map} +1 -1
- package/dist/chunks/{FormEditor-iACd0El-.cjs → FormEditor-B8USzAky.cjs} +2 -2
- package/dist/chunks/{FormEditor-iACd0El-.cjs.map → FormEditor-B8USzAky.cjs.map} +1 -1
- package/dist/chunks/{FormEditor-CLLOHKiO.js → FormEditor-BG2RhC71.js} +16 -16
- package/dist/chunks/{FormEditor-CLLOHKiO.js.map → FormEditor-BG2RhC71.js.map} +1 -1
- package/dist/chunks/{Icon-CD3oeiNA.cjs → Icon-C12r4frL.cjs} +2 -2
- package/dist/chunks/Icon-C12r4frL.cjs.map +1 -0
- package/dist/chunks/{Icon-CYXOo0Kt.js → Icon-Peb0houB.js} +38 -36
- package/dist/chunks/Icon-Peb0houB.js.map +1 -0
- package/dist/chunks/{Message-CyLq9ef-.js → Message-CMoH7jcg.js} +5 -9
- package/dist/chunks/{Message-CyLq9ef-.js.map → Message-CMoH7jcg.js.map} +1 -1
- package/dist/chunks/{Message-D3b8HDhm.cjs → Message-qguX0uZk.cjs} +2 -2
- package/dist/chunks/{Message-D3b8HDhm.cjs.map → Message-qguX0uZk.cjs.map} +1 -1
- package/dist/chunks/RichTextEditor-BSA4uzKm.cjs +2 -0
- package/dist/chunks/RichTextEditor-BSA4uzKm.cjs.map +1 -0
- package/dist/chunks/{RichTextEditor-B0P53GFt.js → RichTextEditor-D8VQAM5h.js} +396 -375
- package/dist/chunks/RichTextEditor-D8VQAM5h.js.map +1 -0
- package/dist/chunks/{dialogLabel-D18maX-p.js → dialogLabel-DT7rCr3_.js} +19 -19
- package/dist/chunks/{dialogLabel-D18maX-p.js.map → dialogLabel-DT7rCr3_.js.map} +1 -1
- package/dist/chunks/{dialogLabel-2HRYMHbF.cjs → dialogLabel-_-MTckE_.cjs} +2 -2
- package/dist/chunks/{dialogLabel-2HRYMHbF.cjs.map → dialogLabel-_-MTckE_.cjs.map} +1 -1
- package/dist/chunks/overlayLayer-iGhuAByk.cjs +2 -0
- package/dist/chunks/overlayLayer-iGhuAByk.cjs.map +1 -0
- package/dist/chunks/{overlayLayer-IuoPVwTO.js → overlayLayer-lU4iWSjO.js} +32 -28
- package/dist/chunks/overlayLayer-lU4iWSjO.js.map +1 -0
- package/dist/chunks/{group-7Z_xRlQx.js → style-7Z_xRlQx.js} +1 -1
- package/dist/chunks/{group-7Z_xRlQx.js.map → style-7Z_xRlQx.js.map} +1 -1
- package/dist/chunks/{group-nulIa2_8.cjs → style-nulIa2_8.cjs} +1 -1
- package/dist/chunks/{group-nulIa2_8.cjs.map → style-nulIa2_8.cjs.map} +1 -1
- package/dist/chunks/{use-picker-session-DbfOJstX.cjs → use-picker-session-CM0zcEbf.cjs} +2 -2
- package/dist/chunks/{use-picker-session-DbfOJstX.cjs.map → use-picker-session-CM0zcEbf.cjs.map} +1 -1
- package/dist/chunks/{use-picker-session-BnMxbGAZ.js → use-picker-session-GCDShVBy.js} +3 -3
- package/dist/chunks/{use-picker-session-BnMxbGAZ.js.map → use-picker-session-GCDShVBy.js.map} +1 -1
- package/dist/chunks/{useTooltip-BXAvQwt4.cjs → useTooltip-C7ON4nkV.cjs} +2 -2
- package/dist/chunks/{useTooltip-BXAvQwt4.cjs.map → useTooltip-C7ON4nkV.cjs.map} +1 -1
- package/dist/chunks/{useTooltip-BrC7FdeH.js → useTooltip-DnJEFBLg.js} +2 -2
- package/dist/chunks/{useTooltip-BrC7FdeH.js.map → useTooltip-DnJEFBLg.js.map} +1 -1
- package/dist/components/AppShell/index.cjs +1 -1
- package/dist/components/AppShell/index.js +1 -1
- 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/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Badge/style.css +9 -9
- package/dist/components/Banner/index.cjs +1 -1
- package/dist/components/Banner/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Board/style.css +3 -3
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Button/style.css +4 -8
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.js +3 -3
- package/dist/components/Choice/index.js.map +1 -1
- package/dist/components/Choice/style.css +29 -18
- package/dist/components/CollectionView/index.cjs +1 -1
- package/dist/components/CollectionView/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.d.cts.map +1 -1
- package/dist/components/ColourField/index.d.ts.map +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/ColourField/style.css +4 -4
- 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.js +1 -1
- package/dist/components/Drawer/style.css +2 -4
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.js +4 -4
- package/dist/components/EditLayout/style.css +1 -7
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/EntryPicker/style.css +3 -1
- package/dist/components/Field/style.css +1 -1
- package/dist/components/FormEditor/README.md +28 -33
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/FormEditor/style.css +1 -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/LimitReading/style.css +1 -1
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.js +1 -1
- package/dist/components/Menu/style.css +3 -2
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +2 -2
- package/dist/components/Modal/style.css +1 -3
- 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 +58 -55
- package/dist/components/Popover/index.js.map +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RichTextEditor/storyblock-view.d.cts.map +1 -1
- package/dist/components/RichTextEditor/storyblock-view.d.ts.map +1 -1
- package/dist/components/RichTextEditor/style.css +141 -61
- 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 +2 -2
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.d.cts.map +1 -1
- package/dist/components/SelectionCard/index.d.ts.map +1 -1
- package/dist/components/SelectionCard/index.js +2 -2
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SelectionCard/style.css +20 -65
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/Skeleton/style.css +1 -1
- package/dist/components/Slider/style.css +12 -23
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- 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/Switch/index.cjs +1 -1
- package/dist/components/Switch/index.cjs.map +1 -1
- package/dist/components/Switch/index.d.cts.map +1 -1
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Switch/index.js +2 -1
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Switch/style.css +14 -2
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/TagsInput/style.css +3 -21
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/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/elements.css +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +30 -30
- package/dist/internal/dialogFocus.d.cts +2 -0
- package/dist/internal/dialogFocus.d.cts.map +1 -1
- package/dist/internal/dialogFocus.d.ts +2 -0
- package/dist/internal/dialogFocus.d.ts.map +1 -1
- package/dist/message.css +5 -3
- package/dist/tokens.css +83 -309
- package/package.json +1 -1
- package/dist/chunks/ColourField-BdobU76j.cjs +0 -2
- package/dist/chunks/ColourField-BdobU76j.cjs.map +0 -1
- package/dist/chunks/ColourField-C39pcjkG.js.map +0 -1
- package/dist/chunks/Icon-CD3oeiNA.cjs.map +0 -1
- package/dist/chunks/Icon-CYXOo0Kt.js.map +0 -1
- package/dist/chunks/RichTextEditor-B0P53GFt.js.map +0 -1
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs +0 -2
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs.map +0 -1
- package/dist/chunks/overlayLayer-IuoPVwTO.js.map +0 -1
- package/dist/chunks/overlayLayer-seJG-EFn.cjs +0 -2
- package/dist/chunks/overlayLayer-seJG-EFn.cjs.map +0 -1
- package/dist/components/ColourField/focus.d.cts +0 -3
- package/dist/components/ColourField/focus.d.cts.map +0 -1
- package/dist/components/ColourField/focus.d.ts +0 -3
- package/dist/components/ColourField/focus.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker-DDc1nDTb.js","names":["Icon","useOverlayOpen","omitRequired","useGroupBinding","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","forwardRef","rest","focused","setFocused","useState","setMonth","gridRef","useRef","shouldFocus","useEffect","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","Button","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","useId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","Popover","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAGA,SAAgBI,EAAM,GAAqB;CACzC,IAAMC,IAAQ,GAAGC,EAAK,SAAS,IAAI,IAAI,SAAS,GAAG,GAAG,GAChDC,IAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,GAAG,GAAG;CAC/C,OAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE;AAC3C;AAEA,SAAgBC,EAAQ,GAAwC;CAC9D,IAAI,CAACC,KAAS,CAAC,sBAAsB,KAAKA,CAAK,GAC7C,OAAO;CAET,IAAM,CAACC,GAAML,GAAOE,KAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CACtD,IAAI,CAACC,KAAQ,CAACL,KAAS,CAACE,GACtB,OAAO;CAET,IAAMD,IAAO,IAAI,KAAKI,GAAML,IAAQ,GAAGE,CAAG;CAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CAAC,KAAKF,EAAME,CAAI,MAAMG,IAAQ,OAAOH;AACxE;AAGA,SAAgBK,EAAU,GAAe;CACvC,OAAOH,EAAQC,CAAK,MAAM;AAC5B;AAGA,SAAgBG,EAAc,GAAmC;CAC/D,IAAMN,IAAOE,EAAQC,CAAK;CAI1B,OAHKH,IAGEA,EAAK,mBAAmB,SAAS;EAAE,KAAK;EAAW,OAAO;EAAQ,MAAM;CAAU,CAAC,IAFjF;AAGX;;;ACnBA,SAASO,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAEA,IAAMC,IAAW;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAK;AAGjE,SAASC,EAAa,GAA2B,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HAC;AAYX;AAGA,SAAgBE,EAAe,EAC7B,UACA,kBAAe;CAAE,OAAO;CAAI,KAAK;AAAG,GACpC,kBACA,UAAO,MACP,QACA,QACA,gBAAa,IACb,iBAAc,IACd,gBAAa,cACb,cAAW,YACX,cACA,cACA,GAAGC,KACmB;CACtB,IAAM,CAAC5B,GAAUC,KAAe7B,EAAyB8B,CAAY,GAC/DC,IAAUtD,KAASmD,GAEnB6B,KAAU,MAAyB;EAIvC,AAHIhF,MAAU,KAAA,KACZoD,EAAYvB,CAAI,GAElB2C,IAAgB3C,CAAI;CACtB,GACM,EAAE,kBAAenC,EAAgBqF,CAAO;CAE9C,OACE,kBAAC,OAAD;EACE,GAAIE;EACJ,WAAW7E,EAAG,gBAAgBqC,CAAS;EAFzC,UAAA;GAIE,kBAACQ,GAAD;IACE,gBAAc8B,EAAQ;IACtB,cAAYG;IACD;IACL;IACN,OAAO5B,EAAQ;IACV;IACL,KAAKoB,EAAWpB,EAAQ,KAAK7C,GAAK,KAAK;IAC3B;IACC;IACb,YAAY,SAASyE;IACrB,aAAaA;IACb,gBAAgB,MAASF,EAAO;KAAE,GAAG1B;KAAS,OAAOzB;IAAK,CAAC;GAC5D,CAAA;GACD,kBAAC,QAAD;IACE,WAAU;IACV,eAAY;IACb,UAAA;GAEK,CAAA;GACN,kBAACoB,GAAD;IACE,gBAAc8B,EAAQ;IACtB,cAAYI;IACD;IACL;IACN,OAAO7B,EAAQ;IACf,KAAKoB,EAAWpB,EAAQ,OAAO9C,GAAK,KAAK;IACpC;IACO;IACC;IACb,YAAY,SAAS2E;IACrB,aAAaA;IACb,gBAAgB,MAASH,EAAO;KAAE,GAAG1B;KAAS,KAAKzB;IAAK,CAAC;GAC1D,CAAA;EACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"DatePicker-CHJYSaLU.js","names":["Icon","useOverlayOpen","omitRequired","useGroupBinding","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","forwardRef","rest","focused","setFocused","useState","setMonth","gridRef","useRef","shouldFocus","useEffect","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","Button","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","useId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","Popover","rangeBound","endpoint","bound","kind","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../src/components/DatePicker/date.ts","../../src/components/DatePicker/index.tsx"],"sourcesContent":["/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nexport function toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nexport function fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** A real calendar day in \"YYYY-MM-DD\" form, checked without locale formatting. */\nexport function isIsoDate(value: string) {\n return fromIso(value) !== null;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport { formatIsoDate, fromIso, toIso, type IsoDate } from \"./date\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nexport { formatIsoDate } from \"./date\";\nexport type { IsoDate } from \"./date\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\n/** The selected day, or today when none is valid, moved inside the bounds so it can take focus. */\nfunction focusableDay(value: string | undefined, min?: IsoDate, max?: IsoDate): IsoDate {\n const day = fromIso(value) ? (value as IsoDate) : toIso(new Date());\n if (min && day < min) {\n return min;\n }\n return max && day > max ? max : day;\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const [focused, setFocused] = useState<IsoDate>(() => focusableDay(value, min, max));\n const [month, setMonth] = useState(() => fromIso(focused) ?? new Date());\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n if (!fromIso(value)) {\n return;\n }\n const day = focusableDay(value, min, max);\n const next = fromIso(day) ?? new Date();\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(day);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value, min, max]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", \"ds-field-surface\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head ds-field-surface\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n /** Show a separate clear action when populated. Defaults to false. */\n isClearable?: boolean;\n clearLabel?: string;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n isClearable = false,\n clearLabel = \"Clear date\",\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n if (isOpen && isDisabled) {\n setOpen(false);\n }\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n // The roving day is always in bounds; the panel takes focus only if bounds exclude every day.\n const panel = panelRef.current;\n (panel?.querySelector<HTMLButtonElement>(\"[data-focused]:not(:disabled)\") ?? panel)?.focus();\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n return () => document.removeEventListener(\"mousedown\", onPointerDown);\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n onKeyDown={(event) => {\n if (isOpen && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n triggerRef.current?.focus();\n }\n }}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n {isClearable && current && (\n <Button\n variant=\"simple\"\n size={size}\n isIconOnly\n iconStart=\"x\"\n aria-label={clearLabel}\n isDisabled={isDisabled}\n onClick={() => {\n if (value === undefined) {\n setInternal(\"\");\n }\n onValueChange?.(\"\");\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n )}\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n align=\"start\"\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n // A click on the heading or padding focuses the dialog rather than the page,\n // so the field's own Escape handler still runs before an enclosing Modal's.\n tabIndex={-1}\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isClearable?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\nfunction rangeBound(endpoint: string, bound: string | undefined, kind: \"min\" | \"max\") {\n if (!fromIso(endpoint)) {\n return bound;\n }\n if (!bound) {\n return endpoint;\n }\n return kind === \"min\"\n ? endpoint > bound\n ? endpoint\n : bound\n : endpoint < bound\n ? endpoint\n : bound;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n isClearable = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={rangeBound(current.end, max, \"max\")}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${startLabel}`}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={rangeBound(current.start, min, \"min\")}\n max={max}\n isDisabled={isDisabled}\n isClearable={isClearable}\n clearLabel={`Clear ${endLabel}`}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;;AAGA,SAAgBI,EAAM,GAAqB;CACzC,IAAMC,IAAQ,GAAGC,EAAK,SAAS,IAAI,IAAI,SAAS,GAAG,GAAG,GAChDC,IAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,GAAG,GAAG;CAC/C,OAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE;AAC3C;AAEA,SAAgBC,EAAQ,GAAwC;CAC9D,IAAI,CAACC,KAAS,CAAC,sBAAsB,KAAKA,CAAK,GAC7C,OAAO;CAET,IAAM,CAACC,GAAML,GAAOE,KAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CACtD,IAAI,CAACC,KAAQ,CAACL,KAAS,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,YAAY,SAASyE;IACrB,aAAaA;IACb,gBAAgB,MAASF,EAAO;KAAE,GAAG1B;KAAS,OAAOzB;IAAK,CAAC;GAC5D,CAAA;GACD,kBAAC,QAAD;IACE,WAAU;IACV,eAAY;IACb,UAAA;GAEK,CAAA;GACN,kBAACoB,GAAD;IACE,gBAAc8B,EAAQ;IACtB,cAAYI;IACD;IACL;IACN,OAAO7B,EAAQ;IACf,KAAKoB,EAAWpB,EAAQ,OAAO9C,GAAK,KAAK;IACpC;IACO;IACC;IACb,YAAY,SAAS2E;IACrB,aAAaA;IACb,gBAAgB,MAASH,EAAO;KAAE,GAAG1B;KAAS,KAAKzB;IAAK,CAAC;GAC1D,CAAA;EACE;;AAET"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Button as e } from "../components/Button/index.js";
|
|
2
2
|
import { t } from "./transitionDuration-BIBA3V7G.js";
|
|
3
3
|
import { t as n } from "./mergeRefs-C6_5pADN.js";
|
|
4
|
-
import { c as r, r as i, t as a } from "./overlayLayer-
|
|
5
|
-
import { n as o, r as s, t as c } from "./dialogLabel-
|
|
4
|
+
import { c as r, r as i, t as a } from "./overlayLayer-lU4iWSjO.js";
|
|
5
|
+
import { n as o, r as s, t as c } from "./dialogLabel-DT7rCr3_.js";
|
|
6
6
|
import { forwardRef as l, useEffect as u, useId as d, useRef as f, useState as p } from "react";
|
|
7
7
|
import { createPortal as m } from "react-dom";
|
|
8
8
|
import { Fragment as h, jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
@@ -169,4 +169,4 @@ var S = l(function({ isOpen: e, isHidden: t = !1, onClose: l, title: u, descript
|
|
|
169
169
|
//#endregion
|
|
170
170
|
export { S as t };
|
|
171
171
|
|
|
172
|
-
//# sourceMappingURL=Drawer-
|
|
172
|
+
//# sourceMappingURL=Drawer-Ck5XKT_V.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer-C3mWT9Kh.js","names":["_Fragment","mergeRefs","useInheritedPortalScope","useDialogPresence","DialogContent","useModalDialog","useDialogPortal","dialogAttributes","Fragment$1","DrawerHead","hasHeader","titleId","title","description","descriptionId","Button","closeRef","variant","closeLabel","onClose","drawerInteraction","active","isActive","isVisible","isInert","isOpen","canPress","onInactivePress","ariaHidden","DrawerContent","head","node","footer","inactivePressLabel","event","useDrawerExit","previousOpen","setPreviousOpen","useState","exiting","setExiting","useEffect","duration","transitionDurationMs","scrimRef","timeout","Drawer","forwardRef","rest","isHidden","overlayLayer","panelRef","useRef","useId","onTransitionEnd","portalContainer","portal","order","createPortal","frameInert","hasScrim","isResumed","layer","side","onScrimMouseDown","ref","panelAttributes","size","className"],"sources":["../../src/components/Drawer/head.tsx","../../src/components/Drawer/content.tsx","../../src/components/Drawer/index.tsx"],"sourcesContent":["import type { RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport type { DrawerProps } from \".\";\ntype HeadProps = Pick<\n DrawerProps,\n \"title\" | \"description\" | \"onClose\" | \"hasHeader\" | \"variant\" | \"closeLabel\"\n> & { titleId: string; descriptionId: string; closeRef: RefObject<HTMLButtonElement | null> };\nexport function DrawerHead({\n title,\n description,\n onClose,\n hasHeader,\n variant,\n closeLabel,\n titleId,\n descriptionId,\n closeRef,\n}: HeadProps) {\n return (\n <header\n className=\"ds-drawer__head\"\n hidden={!hasHeader}\n >\n <div className=\"ds-drawer__titles\">\n <h2\n id={titleId}\n className=\"ds-drawer__title\"\n >\n {title}\n </h2>\n {description && (\n <p\n id={descriptionId}\n className=\"ds-drawer__description\"\n >\n {description}\n </p>\n )}\n </div>\n <Button\n ref={closeRef}\n variant=\"simple\"\n size={variant === \"navigation\" ? \"lg\" : \"sm\"}\n isIconOnly\n iconStart=\"x\"\n className={variant === \"navigation\" ? \"ds-drawer__close\" : undefined}\n aria-label={closeLabel}\n onClick={onClose}\n />\n </header>\n );\n}\n","import type { ComponentProps } from \"react\";\nimport { Button } from \"../Button\";\nimport { DrawerHead } from \"./head\";\nimport type { DrawerProps } from \".\";\n\ntype ContentProps = ComponentProps<typeof DrawerHead> &\n Pick<DrawerProps, \"children\" | \"footer\" | \"onInactivePress\" | \"inactivePressLabel\"> & {\n isInert: boolean;\n };\n\n/** Distinguish modal participation from an application's inactive-panel action. */\nexport function drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden,\n}: {\n isOpen: boolean;\n isVisible: boolean;\n isActive: boolean;\n onInactivePress?: () => void;\n ariaHidden?: DrawerProps[\"aria-hidden\"];\n}) {\n const active = isActive && isVisible;\n const isInert = !isOpen || !active;\n const canPress = isOpen && isVisible && !isActive && Boolean(onInactivePress);\n return {\n active,\n isInert,\n canPress,\n frameInert: isInert && !canPress,\n panelAttributes: {\n \"aria-hidden\": canPress ? ariaHidden : isInert || ariaHidden,\n tabIndex: canPress ? undefined : -1,\n },\n };\n}\n\n/** Keep editors mounted inside an inert boundary, with activation outside it. */\nexport function DrawerContent({\n isInert,\n children,\n footer,\n onInactivePress,\n inactivePressLabel,\n ...head\n}: ContentProps) {\n return (\n <>\n <div\n className=\"ds-drawer__content\"\n ref={(node) => {\n if (node) {\n node.inert = isInert;\n node.toggleAttribute(\"inert\", isInert);\n }\n }}\n aria-hidden={isInert || undefined}\n >\n <DrawerHead {...head} />\n <div className=\"ds-drawer__body\">{children}</div>\n {footer && <footer className=\"ds-drawer__footer ds-field-surface\">{footer}</footer>}\n </div>\n {onInactivePress && (\n <Button\n variant=\"simple\"\n className=\"ds-drawer__inactive-press\"\n aria-label={\n inactivePressLabel ??\n (typeof head.title === \"string\" ? `Return to ${head.title}` : \"Activate drawer\")\n }\n tabIndex={-1}\n onPointerDown={(event) => event.preventDefault()}\n onClick={(event) => {\n event.stopPropagation();\n onInactivePress();\n }}\n />\n )}\n </>\n );\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n type TransitionEvent,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DrawerContent, drawerInteraction } from \"./content\";\nimport { transitionDurationMs } from \"../../internal/transitionDuration\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { useDialogPortal } from \"../../internal/useDialogPortal\";\nimport { useModalDialog } from \"../../internal/useModalDialog\";\nimport { dialogAttributes } from \"../../internal/dialogLabel\";\nimport { useInheritedPortalScope } from \"../../internal/portalScope\";\nimport { DialogContent, useDialogPresence } from \"../../internal/overlayLayer\";\nimport \"./style.css\";\n\nexport type DrawerSide = \"end\" | \"start\" | \"bottom\";\nexport type DrawerSize = \"md\" | \"wide\";\n\nexport interface DrawerProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /**\n * Visually suspend an open dialog while retaining its mounted children. It\n * stays laid out but invisible and inert, so scroll positions are kept.\n */\n isHidden?: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: ReactNode;\n description?: string;\n /** Which edge the panel is anchored to. */\n side?: DrawerSide;\n size?: DrawerSize;\n /** Without it the title still names the dialog; give people another way to close it. */\n hasHeader?: boolean;\n /**\n * Only the active panel traps focus and handles Escape. An inactive open\n * panel stays visible and mounted as an inert background panel.\n */\n isActive?: boolean;\n /** Activate an exposed inactive panel. Its editor stays inert; the app decides whether to activate it. */\n onInactivePress?: () => void;\n /** Accessible name for the inactive-panel action; defaults to Return to {title} for string titles. */\n inactivePressLabel?: string;\n /** Without a scrim, presses outside the panel reach the page beneath. */\n hasScrim?: boolean;\n /**\n * z-index for this panel and the dialogs and popovers opened from it.\n * Defaults to an enclosing `OverlayLayer`, then the stylesheet. Keep it below\n * the toast layer (80).\n */\n overlayLayer?: number;\n /** Navigation uses a compact panel, header and footer. Both variants slide in and out. */\n variant?: \"default\" | \"navigation\";\n /** Accessible name of the dismiss button. */\n closeLabel?: string;\n /**\n * Defaults to document.body, covering the viewport. A navigation drawer\n * portaled into a positioned element, such as an app shell, stays inside it.\n */\n portalContainer?: HTMLElement | null;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\nfunction useDrawerExit(isOpen: boolean, scrimRef: RefObject<HTMLDivElement | null>) {\n const [previousOpen, setPreviousOpen] = useState(isOpen);\n const [exiting, setExiting] = useState(false);\n\n if (previousOpen !== isOpen) {\n setPreviousOpen(isOpen);\n setExiting(!isOpen);\n }\n\n useEffect(() => {\n if (!exiting || isOpen) {\n return;\n }\n // Read the actual transition, including token overrides and reduced motion.\n const duration = transitionDurationMs(scrimRef.current!);\n const timeout = window.setTimeout(() => setExiting(false), duration);\n return () => window.clearTimeout(timeout);\n }, [exiting, isOpen, scrimRef]);\n\n const onTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget && event.propertyName === \"opacity\" && !isOpen) {\n setExiting(false);\n }\n };\n return [exiting, onTransitionEnd] as const;\n}\n\n/**\n * A side panel for work that belongs beside the page rather than on top of it\n * — editing one record, a filter set, a revision history. Same frame, rules\n * and footer band as `Modal`, with square corners and a full slide through\n * its anchored edge. Focus is trapped while open.\n */\nexport const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(\n {\n isOpen,\n isHidden = false,\n onClose,\n title,\n description,\n side = \"end\",\n size = \"md\",\n hasHeader = true,\n isActive = true,\n onInactivePress,\n inactivePressLabel,\n hasScrim = true,\n overlayLayer,\n variant = \"default\",\n closeLabel = \"Close\",\n portalContainer,\n footer,\n className,\n children,\n ...rest\n },\n ref,\n) {\n const { layer, isVisible, isResumed } = useDialogPresence(isOpen, isHidden, overlayLayer);\n const { active, isInert, canPress, frameInert, panelAttributes } = drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden: rest[\"aria-hidden\"],\n });\n const panelRef = useRef<HTMLDivElement | null>(null);\n const scrimRef = useRef<HTMLDivElement | null>(null);\n const closeRef = useRef<HTMLButtonElement | null>(null);\n const titleId = useId();\n const descriptionId = useId();\n const [exiting, onTransitionEnd] = useDrawerExit(isOpen, scrimRef);\n const { onScrimMouseDown, order } = useModalDialog({\n isOpen,\n isActive: active,\n layer,\n panelRef,\n onClose,\n // A hidden header's close button can't take focus.\n initialFocus: variant === \"navigation\" && hasHeader ? () => closeRef.current : undefined,\n // Panels start off-screen; focusing them must not scroll the page with them.\n preventScroll: true,\n container: portalContainer,\n });\n const portal = useDialogPortal(order, isOpen || exiting, portalContainer);\n useInheritedPortalScope(scrimRef, isOpen, { keepDir: rest.dir !== undefined });\n\n if ((!isOpen && !exiting) || !portal) {\n return null;\n }\n\n return createPortal(\n <DialogContent\n layer={layer}\n isSuspended={isInert}\n >\n <div\n ref={(node) => {\n scrimRef.current = node;\n if (node) {\n node.inert = frameInert;\n }\n }}\n className=\"ds-drawer-scrim\"\n hidden={!isVisible}\n data-scrim={hasScrim ? undefined : \"none\"}\n data-inactive-press={canPress || undefined}\n data-resumed={isResumed || undefined}\n style={{ zIndex: layer }}\n dir={rest.dir}\n data-side={side}\n data-variant={variant}\n data-contained={portalContainer ? \"\" : undefined}\n data-state={isOpen ? \"open\" : \"closed\"}\n aria-hidden={frameInert || undefined}\n onTransitionEnd={onTransitionEnd}\n onMouseDown={onScrimMouseDown}\n >\n <div\n {...rest}\n ref={mergeRefs(panelRef, ref)}\n {...dialogAttributes(rest, titleId, descriptionId, Boolean(description), active)}\n {...panelAttributes}\n data-side={side}\n data-size={size}\n data-header={hasHeader ? undefined : \"none\"}\n data-variant={variant}\n className={[\"ds-drawer\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n >\n <DrawerContent\n isInert={isInert}\n title={title}\n description={description}\n onClose={onClose}\n hasHeader={hasHeader}\n variant={variant}\n closeLabel={closeLabel}\n titleId={titleId}\n descriptionId={descriptionId}\n closeRef={closeRef}\n footer={footer}\n onInactivePress={canPress ? onInactivePress : undefined}\n inactivePressLabel={inactivePressLabel}\n >\n {children}\n </DrawerContent>\n </div>\n </div>\n </DialogContent>,\n portal,\n );\n});\n"],"mappings":";;;;;;;;;AAOA,SAAgBS,EAAW,EACzB,UAC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AC,CAAC,KAAK,GAAG;IAEhF,UAAA,kBAACvC,GAAD;KACW;KACF;KACM;KACJ;KACE;KACF;KACG;KACH;KACM;KACL;KACF;KACR,iBAAiBH,IAAWC,IAAkB,KAAA;KAC1B;KAEnB;IACY,CAAA;GACZ,CAAA;EACF,CAAA;CACQ,CAAA,GACf6B,CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"Drawer-Ck5XKT_V.js","names":["_Fragment","mergeRefs","useInheritedPortalScope","useDialogPresence","DialogContent","useModalDialog","useDialogPortal","dialogAttributes","Fragment$1","DrawerHead","hasHeader","titleId","title","description","descriptionId","Button","closeRef","variant","closeLabel","onClose","drawerInteraction","active","isActive","isVisible","isInert","isOpen","canPress","onInactivePress","ariaHidden","DrawerContent","head","node","footer","inactivePressLabel","event","useDrawerExit","previousOpen","setPreviousOpen","useState","exiting","setExiting","useEffect","duration","transitionDurationMs","scrimRef","timeout","Drawer","forwardRef","rest","isHidden","overlayLayer","panelRef","useRef","useId","onTransitionEnd","portalContainer","portal","order","createPortal","frameInert","hasScrim","isResumed","layer","side","onScrimMouseDown","ref","panelAttributes","size","className"],"sources":["../../src/components/Drawer/head.tsx","../../src/components/Drawer/content.tsx","../../src/components/Drawer/index.tsx"],"sourcesContent":["import type { RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport type { DrawerProps } from \".\";\ntype HeadProps = Pick<\n DrawerProps,\n \"title\" | \"description\" | \"onClose\" | \"hasHeader\" | \"variant\" | \"closeLabel\"\n> & { titleId: string; descriptionId: string; closeRef: RefObject<HTMLButtonElement | null> };\nexport function DrawerHead({\n title,\n description,\n onClose,\n hasHeader,\n variant,\n closeLabel,\n titleId,\n descriptionId,\n closeRef,\n}: HeadProps) {\n return (\n <header\n className=\"ds-drawer__head\"\n hidden={!hasHeader}\n >\n <div className=\"ds-drawer__titles\">\n <h2\n id={titleId}\n className=\"ds-drawer__title\"\n >\n {title}\n </h2>\n {description && (\n <p\n id={descriptionId}\n className=\"ds-drawer__description\"\n >\n {description}\n </p>\n )}\n </div>\n <Button\n ref={closeRef}\n variant=\"simple\"\n size={variant === \"navigation\" ? \"lg\" : \"sm\"}\n isIconOnly\n iconStart=\"x\"\n className={variant === \"navigation\" ? \"ds-drawer__close\" : undefined}\n aria-label={closeLabel}\n onClick={onClose}\n />\n </header>\n );\n}\n","import type { ComponentProps } from \"react\";\nimport { Button } from \"../Button\";\nimport { DrawerHead } from \"./head\";\nimport type { DrawerProps } from \".\";\n\ntype ContentProps = ComponentProps<typeof DrawerHead> &\n Pick<DrawerProps, \"children\" | \"footer\" | \"onInactivePress\" | \"inactivePressLabel\"> & {\n isInert: boolean;\n };\n\n/** Distinguish modal participation from an application's inactive-panel action. */\nexport function drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden,\n}: {\n isOpen: boolean;\n isVisible: boolean;\n isActive: boolean;\n onInactivePress?: () => void;\n ariaHidden?: DrawerProps[\"aria-hidden\"];\n}) {\n const active = isActive && isVisible;\n const isInert = !isOpen || !active;\n const canPress = isOpen && isVisible && !isActive && Boolean(onInactivePress);\n return {\n active,\n isInert,\n canPress,\n frameInert: isInert && !canPress,\n panelAttributes: {\n \"aria-hidden\": canPress ? ariaHidden : isInert || ariaHidden,\n tabIndex: canPress ? undefined : -1,\n },\n };\n}\n\n/** Keep editors mounted inside an inert boundary, with activation outside it. */\nexport function DrawerContent({\n isInert,\n children,\n footer,\n onInactivePress,\n inactivePressLabel,\n ...head\n}: ContentProps) {\n return (\n <>\n <div\n className=\"ds-drawer__content\"\n ref={(node) => {\n if (node) {\n node.inert = isInert;\n node.toggleAttribute(\"inert\", isInert);\n }\n }}\n aria-hidden={isInert || undefined}\n >\n <DrawerHead {...head} />\n <div className=\"ds-drawer__body\">{children}</div>\n {footer && <footer className=\"ds-drawer__footer ds-field-surface\">{footer}</footer>}\n </div>\n {onInactivePress && (\n <Button\n variant=\"simple\"\n className=\"ds-drawer__inactive-press\"\n aria-label={\n inactivePressLabel ??\n (typeof head.title === \"string\" ? `Return to ${head.title}` : \"Activate drawer\")\n }\n tabIndex={-1}\n onPointerDown={(event) => event.preventDefault()}\n onClick={(event) => {\n event.stopPropagation();\n onInactivePress();\n }}\n />\n )}\n </>\n );\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n type TransitionEvent,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DrawerContent, drawerInteraction } from \"./content\";\nimport { transitionDurationMs } from \"../../internal/transitionDuration\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { useDialogPortal } from \"../../internal/useDialogPortal\";\nimport { useModalDialog } from \"../../internal/useModalDialog\";\nimport { dialogAttributes } from \"../../internal/dialogLabel\";\nimport { useInheritedPortalScope } from \"../../internal/portalScope\";\nimport { DialogContent, useDialogPresence } from \"../../internal/overlayLayer\";\nimport \"./style.css\";\n\nexport type DrawerSide = \"end\" | \"start\" | \"bottom\";\nexport type DrawerSize = \"md\" | \"wide\";\n\nexport interface DrawerProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /**\n * Visually suspend an open dialog while retaining its mounted children. It\n * stays laid out but invisible and inert, so scroll positions are kept.\n */\n isHidden?: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: ReactNode;\n description?: string;\n /** Which edge the panel is anchored to. */\n side?: DrawerSide;\n size?: DrawerSize;\n /** Without it the title still names the dialog; give people another way to close it. */\n hasHeader?: boolean;\n /**\n * Only the active panel traps focus and handles Escape. An inactive open\n * panel stays visible and mounted as an inert background panel.\n */\n isActive?: boolean;\n /** Activate an exposed inactive panel. Its editor stays inert; the app decides whether to activate it. */\n onInactivePress?: () => void;\n /** Accessible name for the inactive-panel action; defaults to Return to {title} for string titles. */\n inactivePressLabel?: string;\n /** Without a scrim, presses outside the panel reach the page beneath. */\n hasScrim?: boolean;\n /**\n * z-index for this panel and the dialogs and popovers opened from it.\n * Defaults to an enclosing `OverlayLayer`, then the stylesheet. Keep it below\n * the toast layer (80).\n */\n overlayLayer?: number;\n /** Navigation uses a compact panel, header and footer. Both variants slide in and out. */\n variant?: \"default\" | \"navigation\";\n /** Accessible name of the dismiss button. */\n closeLabel?: string;\n /**\n * Defaults to document.body, covering the viewport. A navigation drawer\n * portaled into a positioned element, such as an app shell, stays inside it.\n */\n portalContainer?: HTMLElement | null;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\nfunction useDrawerExit(isOpen: boolean, scrimRef: RefObject<HTMLDivElement | null>) {\n const [previousOpen, setPreviousOpen] = useState(isOpen);\n const [exiting, setExiting] = useState(false);\n\n if (previousOpen !== isOpen) {\n setPreviousOpen(isOpen);\n setExiting(!isOpen);\n }\n\n useEffect(() => {\n if (!exiting || isOpen) {\n return;\n }\n // Read the actual transition, including token overrides and reduced motion.\n const duration = transitionDurationMs(scrimRef.current!);\n const timeout = window.setTimeout(() => setExiting(false), duration);\n return () => window.clearTimeout(timeout);\n }, [exiting, isOpen, scrimRef]);\n\n const onTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget && event.propertyName === \"opacity\" && !isOpen) {\n setExiting(false);\n }\n };\n return [exiting, onTransitionEnd] as const;\n}\n\n/**\n * A side panel for work that belongs beside the page rather than on top of it\n * — editing one record, a filter set, a revision history. Same frame, rules\n * and footer band as `Modal`, with square corners and a full slide through\n * its anchored edge. Focus is trapped while open.\n */\nexport const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(\n {\n isOpen,\n isHidden = false,\n onClose,\n title,\n description,\n side = \"end\",\n size = \"md\",\n hasHeader = true,\n isActive = true,\n onInactivePress,\n inactivePressLabel,\n hasScrim = true,\n overlayLayer,\n variant = \"default\",\n closeLabel = \"Close\",\n portalContainer,\n footer,\n className,\n children,\n ...rest\n },\n ref,\n) {\n const { layer, isVisible, isResumed } = useDialogPresence(isOpen, isHidden, overlayLayer);\n const { active, isInert, canPress, frameInert, panelAttributes } = drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden: rest[\"aria-hidden\"],\n });\n const panelRef = useRef<HTMLDivElement | null>(null);\n const scrimRef = useRef<HTMLDivElement | null>(null);\n const closeRef = useRef<HTMLButtonElement | null>(null);\n const titleId = useId();\n const descriptionId = useId();\n const [exiting, onTransitionEnd] = useDrawerExit(isOpen, scrimRef);\n const { onScrimMouseDown, order } = useModalDialog({\n isOpen,\n isActive: active,\n layer,\n panelRef,\n onClose,\n // A hidden header's close button can't take focus.\n initialFocus: variant === \"navigation\" && hasHeader ? () => closeRef.current : undefined,\n // Panels start off-screen; focusing them must not scroll the page with them.\n preventScroll: true,\n container: portalContainer,\n });\n const portal = useDialogPortal(order, isOpen || exiting, portalContainer);\n useInheritedPortalScope(scrimRef, isOpen, { keepDir: rest.dir !== undefined });\n\n if ((!isOpen && !exiting) || !portal) {\n return null;\n }\n\n return createPortal(\n <DialogContent\n layer={layer}\n isSuspended={isInert}\n >\n <div\n ref={(node) => {\n scrimRef.current = node;\n if (node) {\n node.inert = frameInert;\n }\n }}\n className=\"ds-drawer-scrim\"\n hidden={!isVisible}\n data-scrim={hasScrim ? undefined : \"none\"}\n data-inactive-press={canPress || undefined}\n data-resumed={isResumed || undefined}\n style={{ zIndex: layer }}\n dir={rest.dir}\n data-side={side}\n data-variant={variant}\n data-contained={portalContainer ? \"\" : undefined}\n data-state={isOpen ? \"open\" : \"closed\"}\n aria-hidden={frameInert || undefined}\n onTransitionEnd={onTransitionEnd}\n onMouseDown={onScrimMouseDown}\n >\n <div\n {...rest}\n ref={mergeRefs(panelRef, ref)}\n {...dialogAttributes(rest, titleId, descriptionId, Boolean(description), active)}\n {...panelAttributes}\n data-side={side}\n data-size={size}\n data-header={hasHeader ? undefined : \"none\"}\n data-variant={variant}\n className={[\"ds-drawer\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n >\n <DrawerContent\n isInert={isInert}\n title={title}\n description={description}\n onClose={onClose}\n hasHeader={hasHeader}\n variant={variant}\n closeLabel={closeLabel}\n titleId={titleId}\n descriptionId={descriptionId}\n closeRef={closeRef}\n footer={footer}\n onInactivePress={canPress ? onInactivePress : undefined}\n inactivePressLabel={inactivePressLabel}\n >\n {children}\n </DrawerContent>\n </div>\n </div>\n </DialogContent>,\n portal,\n );\n});\n"],"mappings":";;;;;;;;;AAOA,SAAgBS,EAAW,EACzB,UACA,gBACA,YACA,cACA,YACA,eACA,YACA,kBACA,eACY;CACZ,OACE,kBAAC,UAAD;EACE,WAAU;EACV,QAAQ,CAACC;EAFX,UAAA,CAIE,kBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,kBAAC,MAAD;IACE,IAAIC;IACJ,WAAU;IAET,UAAAC;GACC,CAAA,GACHC,KACC,kBAAC,KAAD;IACE,IAAIC;IACJ,WAAU;IAET,UAAAD;GACA,CAAA,CAEF;EACL,CAAA,GAAA,kBAACE,GAAD;GACE,KAAKC;GACL,SAAQ;GACR,MAAMC,MAAY,eAAe,OAAO;GACxC,YAAA;GACA,WAAU;GACV,WAAWA,MAAY,eAAe,qBAAqB,KAAA;GAC3D,cAAYC;GACZ,SAASC;EACV,CAAA,CACK;;AAEZ;;;ACxCA,SAAgBC,EAAkB,EAChC,WACA,cACA,aACA,oBACA,iBAOC;CACD,IAAMC,IAASC,KAAYC,GACrBC,IAAU,CAACC,KAAU,CAACJ,GACtBK,IAAWD,KAAUF,KAAa,CAACD,KAAY,EAAQK;CAC7D,OAAO;EACL;EACA;EACA;EACA,YAAYH,KAAW,CAACE;EACxB,iBAAiB;GACf,eAAeA,IAAWE,IAAaJ,KAAWI;GAClD,UAAUF,IAAW,KAAA,IAAY;EACnC;CACF;AACF;AAGA,SAAgBG,EAAc,EAC5B,YACA,aACA,WACA,oBACA,uBACA,GAAGC,KACY;CACf,OACE,kBAAA9B,GAAA,EAAA,UAAA,CACE,kBAAC,OAAD;EACE,WAAU;EACV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aK;GAEb,UAAA,kBAAC,OAAD;IACE,GAAIhB;IACJ,KAAK/C,EAAUkD,GAAUc,CAAG;IAC5B,GAAI1D,EAAiByC,GAAMrC,GAASG,GAAe,EAAQD,GAAcQ,CAAM;IAC/E,GAAI6C;IACJ,aAAWH;IACX,aAAWI;IACX,eAAazD,IAAY,KAAA,IAAY;IACrC,gBAAcO;IACd,WAAW;KAAC;KAAa;KAAoBmD;IAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;IAEhF,UAAA,kBAACvC,GAAD;KACW;KACF;KACM;KACJ;KACE;KACF;KACG;KACH;KACM;KACL;KACF;KACR,iBAAiBH,IAAWC,IAAkB,KAAA;KAC1B;KAEnB;IACY,CAAA;GACZ,CAAA;EACF,CAAA;CACQ,CAAA,GACf6B,CACF;AACF,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../components/Button/index.cjs"),t=require("./transitionDuration-B4UnScFc.cjs"),n=require("./mergeRefs-CZ-SArlE.cjs"),r=require("./overlayLayer-
|
|
2
|
-
//# sourceMappingURL=Drawer-
|
|
1
|
+
const e=require("../components/Button/index.cjs"),t=require("./transitionDuration-B4UnScFc.cjs"),n=require("./mergeRefs-CZ-SArlE.cjs"),r=require("./overlayLayer-iGhuAByk.cjs"),i=require("./dialogLabel-_-MTckE_.cjs");let a=require("react"),o=require("react-dom"),s=require("react/jsx-runtime");function c({title:t,description:n,onClose:r,hasHeader:i,variant:a,closeLabel:o,titleId:c,descriptionId:l,closeRef:u}){return(0,s.jsxs)(`header`,{className:`ds-drawer__head`,hidden:!i,children:[(0,s.jsxs)(`div`,{className:`ds-drawer__titles`,children:[(0,s.jsx)(`h2`,{id:c,className:`ds-drawer__title`,children:t}),n&&(0,s.jsx)(`p`,{id:l,className:`ds-drawer__description`,children:n})]}),(0,s.jsx)(e.Button,{ref:u,variant:`simple`,size:a===`navigation`?`lg`:`sm`,isIconOnly:!0,iconStart:`x`,className:a===`navigation`?`ds-drawer__close`:void 0,"aria-label":o,onClick:r})]})}function l({isOpen:e,isVisible:t,isActive:n,onInactivePress:r,ariaHidden:i}){let a=n&&t,o=!e||!a,s=e&&t&&!n&&!!r;return{active:a,isInert:o,canPress:s,frameInert:o&&!s,panelAttributes:{"aria-hidden":s?i:o||i,tabIndex:s?void 0:-1}}}function u({isInert:t,children:n,footer:r,onInactivePress:i,inactivePressLabel:a,...o}){return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`div`,{className:`ds-drawer__content`,ref:e=>{e&&(e.inert=t,e.toggleAttribute(`inert`,t))},"aria-hidden":t||void 0,children:[(0,s.jsx)(c,{...o}),(0,s.jsx)(`div`,{className:`ds-drawer__body`,children:n}),r&&(0,s.jsx)(`footer`,{className:`ds-drawer__footer ds-field-surface`,children:r})]}),i&&(0,s.jsx)(e.Button,{variant:`simple`,className:`ds-drawer__inactive-press`,"aria-label":a??(typeof o.title==`string`?`Return to ${o.title}`:`Activate drawer`),tabIndex:-1,onPointerDown:e=>e.preventDefault(),onClick:e=>{e.stopPropagation(),i()}})]})}function d(e,n){let[r,i]=(0,a.useState)(e),[o,s]=(0,a.useState)(!1);return r!==e&&(i(e),s(!e)),(0,a.useEffect)(()=>{if(!o||e)return;let r=t.t(n.current),i=window.setTimeout(()=>s(!1),r);return()=>window.clearTimeout(i)},[o,e,n]),[o,t=>{t.target===t.currentTarget&&t.propertyName===`opacity`&&!e&&s(!1)}]}var f=(0,a.forwardRef)(function({isOpen:e,isHidden:t=!1,onClose:c,title:f,description:p,side:m=`end`,size:h=`md`,hasHeader:g=!0,isActive:_=!0,onInactivePress:v,inactivePressLabel:y,hasScrim:b=!0,overlayLayer:x,variant:S=`default`,closeLabel:C=`Close`,portalContainer:w,footer:T,className:E,children:D,...O},k){let{layer:A,isVisible:j,isResumed:M}=r.r(e,t,x),{active:N,isInert:P,canPress:F,frameInert:I,panelAttributes:L}=l({isOpen:e,isVisible:j,isActive:_,onInactivePress:v,ariaHidden:O[`aria-hidden`]}),R=(0,a.useRef)(null),z=(0,a.useRef)(null),B=(0,a.useRef)(null),V=(0,a.useId)(),H=(0,a.useId)(),[U,W]=d(e,z),{onScrimMouseDown:G,order:K}=i.n({isOpen:e,isActive:N,layer:A,panelRef:R,onClose:c,initialFocus:S===`navigation`&&g?()=>B.current:void 0,preventScroll:!0,container:w}),q=i.r(K,e||U,w);return r.c(z,e,{keepDir:O.dir!==void 0}),!e&&!U||!q?null:(0,o.createPortal)((0,s.jsx)(r.t,{layer:A,isSuspended:P,children:(0,s.jsx)(`div`,{ref:e=>{z.current=e,e&&(e.inert=I)},className:`ds-drawer-scrim`,hidden:!j,"data-scrim":b?void 0:`none`,"data-inactive-press":F||void 0,"data-resumed":M||void 0,style:{zIndex:A},dir:O.dir,"data-side":m,"data-variant":S,"data-contained":w?``:void 0,"data-state":e?`open`:`closed`,"aria-hidden":I||void 0,onTransitionEnd:W,onMouseDown:G,children:(0,s.jsx)(`div`,{...O,ref:n.t(R,k),...i.t(O,V,H,!!p,N),...L,"data-side":m,"data-size":h,"data-header":g?void 0:`none`,"data-variant":S,className:[`ds-drawer`,`ds-field-surface`,E].filter(Boolean).join(` `),children:(0,s.jsx)(u,{isInert:P,title:f,description:p,onClose:c,hasHeader:g,variant:S,closeLabel:C,titleId:V,descriptionId:H,closeRef:B,footer:T,onInactivePress:F?v:void 0,inactivePressLabel:y,children:D})})})}),q)});Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return f}});
|
|
2
|
+
//# sourceMappingURL=Drawer-DdIH9jpe.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer-DTKZptua.cjs","names":["Button","_Fragment","Button","useState","transitionDurationMs","forwardRef","useDialogPresence","useRef","useId","useModalDialog","useDialogPortal","createPortal","DialogContent","mergeRefs","dialogAttributes","require_components_Button_index","require_transitionDuration","require_mergeRefs","require_overlayLayer","require_dialogLabel","react","react_dom","react_jsx_runtime","DrawerHead","hasHeader","titleId","title","description","descriptionId","closeRef","variant","closeLabel","onClose","drawerInteraction","active","isActive","isVisible","isInert","isOpen","canPress","onInactivePress","ariaHidden","DrawerContent","head","node","footer","inactivePressLabel","event","useDrawerExit","previousOpen","setPreviousOpen","exiting","setExiting","duration","scrimRef","timeout","Drawer","rest","isHidden","overlayLayer","panelRef","onTransitionEnd","portalContainer","portal","order","frameInert","hasScrim","isResumed","layer","side","onScrimMouseDown","ref","panelAttributes","size","className"],"sources":["../../src/components/Drawer/head.tsx","../../src/components/Drawer/content.tsx","../../src/components/Drawer/index.tsx"],"sourcesContent":["import type { RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport type { DrawerProps } from \".\";\ntype HeadProps = Pick<\n DrawerProps,\n \"title\" | \"description\" | \"onClose\" | \"hasHeader\" | \"variant\" | \"closeLabel\"\n> & { titleId: string; descriptionId: string; closeRef: RefObject<HTMLButtonElement | null> };\nexport function DrawerHead({\n title,\n description,\n onClose,\n hasHeader,\n variant,\n closeLabel,\n titleId,\n descriptionId,\n closeRef,\n}: HeadProps) {\n return (\n <header\n className=\"ds-drawer__head\"\n hidden={!hasHeader}\n >\n <div className=\"ds-drawer__titles\">\n <h2\n id={titleId}\n className=\"ds-drawer__title\"\n >\n {title}\n </h2>\n {description && (\n <p\n id={descriptionId}\n className=\"ds-drawer__description\"\n >\n {description}\n </p>\n )}\n </div>\n <Button\n ref={closeRef}\n variant=\"simple\"\n size={variant === \"navigation\" ? \"lg\" : \"sm\"}\n isIconOnly\n iconStart=\"x\"\n className={variant === \"navigation\" ? \"ds-drawer__close\" : undefined}\n aria-label={closeLabel}\n onClick={onClose}\n />\n </header>\n );\n}\n","import type { ComponentProps } from \"react\";\nimport { Button } from \"../Button\";\nimport { DrawerHead } from \"./head\";\nimport type { DrawerProps } from \".\";\n\ntype ContentProps = ComponentProps<typeof DrawerHead> &\n Pick<DrawerProps, \"children\" | \"footer\" | \"onInactivePress\" | \"inactivePressLabel\"> & {\n isInert: boolean;\n };\n\n/** Distinguish modal participation from an application's inactive-panel action. */\nexport function drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden,\n}: {\n isOpen: boolean;\n isVisible: boolean;\n isActive: boolean;\n onInactivePress?: () => void;\n ariaHidden?: DrawerProps[\"aria-hidden\"];\n}) {\n const active = isActive && isVisible;\n const isInert = !isOpen || !active;\n const canPress = isOpen && isVisible && !isActive && Boolean(onInactivePress);\n return {\n active,\n isInert,\n canPress,\n frameInert: isInert && !canPress,\n panelAttributes: {\n \"aria-hidden\": canPress ? ariaHidden : isInert || ariaHidden,\n tabIndex: canPress ? undefined : -1,\n },\n };\n}\n\n/** Keep editors mounted inside an inert boundary, with activation outside it. */\nexport function DrawerContent({\n isInert,\n children,\n footer,\n onInactivePress,\n inactivePressLabel,\n ...head\n}: ContentProps) {\n return (\n <>\n <div\n className=\"ds-drawer__content\"\n ref={(node) => {\n if (node) {\n node.inert = isInert;\n node.toggleAttribute(\"inert\", isInert);\n }\n }}\n aria-hidden={isInert || undefined}\n >\n <DrawerHead {...head} />\n <div className=\"ds-drawer__body\">{children}</div>\n {footer && <footer className=\"ds-drawer__footer ds-field-surface\">{footer}</footer>}\n </div>\n {onInactivePress && (\n <Button\n variant=\"simple\"\n className=\"ds-drawer__inactive-press\"\n aria-label={\n inactivePressLabel ??\n (typeof head.title === \"string\" ? `Return to ${head.title}` : \"Activate drawer\")\n }\n tabIndex={-1}\n onPointerDown={(event) => event.preventDefault()}\n onClick={(event) => {\n event.stopPropagation();\n onInactivePress();\n }}\n />\n )}\n </>\n );\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n type TransitionEvent,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DrawerContent, drawerInteraction } from \"./content\";\nimport { transitionDurationMs } from \"../../internal/transitionDuration\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { useDialogPortal } from \"../../internal/useDialogPortal\";\nimport { useModalDialog } from \"../../internal/useModalDialog\";\nimport { dialogAttributes } from \"../../internal/dialogLabel\";\nimport { useInheritedPortalScope } from \"../../internal/portalScope\";\nimport { DialogContent, useDialogPresence } from \"../../internal/overlayLayer\";\nimport \"./style.css\";\n\nexport type DrawerSide = \"end\" | \"start\" | \"bottom\";\nexport type DrawerSize = \"md\" | \"wide\";\n\nexport interface DrawerProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /**\n * Visually suspend an open dialog while retaining its mounted children. It\n * stays laid out but invisible and inert, so scroll positions are kept.\n */\n isHidden?: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: ReactNode;\n description?: string;\n /** Which edge the panel is anchored to. */\n side?: DrawerSide;\n size?: DrawerSize;\n /** Without it the title still names the dialog; give people another way to close it. */\n hasHeader?: boolean;\n /**\n * Only the active panel traps focus and handles Escape. An inactive open\n * panel stays visible and mounted as an inert background panel.\n */\n isActive?: boolean;\n /** Activate an exposed inactive panel. Its editor stays inert; the app decides whether to activate it. */\n onInactivePress?: () => void;\n /** Accessible name for the inactive-panel action; defaults to Return to {title} for string titles. */\n inactivePressLabel?: string;\n /** Without a scrim, presses outside the panel reach the page beneath. */\n hasScrim?: boolean;\n /**\n * z-index for this panel and the dialogs and popovers opened from it.\n * Defaults to an enclosing `OverlayLayer`, then the stylesheet. Keep it below\n * the toast layer (80).\n */\n overlayLayer?: number;\n /** Navigation uses a compact panel, header and footer. Both variants slide in and out. */\n variant?: \"default\" | \"navigation\";\n /** Accessible name of the dismiss button. */\n closeLabel?: string;\n /**\n * Defaults to document.body, covering the viewport. A navigation drawer\n * portaled into a positioned element, such as an app shell, stays inside it.\n */\n portalContainer?: HTMLElement | null;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\nfunction useDrawerExit(isOpen: boolean, scrimRef: RefObject<HTMLDivElement | null>) {\n const [previousOpen, setPreviousOpen] = useState(isOpen);\n const [exiting, setExiting] = useState(false);\n\n if (previousOpen !== isOpen) {\n setPreviousOpen(isOpen);\n setExiting(!isOpen);\n }\n\n useEffect(() => {\n if (!exiting || isOpen) {\n return;\n }\n // Read the actual transition, including token overrides and reduced motion.\n const duration = transitionDurationMs(scrimRef.current!);\n const timeout = window.setTimeout(() => setExiting(false), duration);\n return () => window.clearTimeout(timeout);\n }, [exiting, isOpen, scrimRef]);\n\n const onTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget && event.propertyName === \"opacity\" && !isOpen) {\n setExiting(false);\n }\n };\n return [exiting, onTransitionEnd] as const;\n}\n\n/**\n * A side panel for work that belongs beside the page rather than on top of it\n * — editing one record, a filter set, a revision history. Same frame, rules\n * and footer band as `Modal`, with square corners and a full slide through\n * its anchored edge. Focus is trapped while open.\n */\nexport const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(\n {\n isOpen,\n isHidden = false,\n onClose,\n title,\n description,\n side = \"end\",\n size = \"md\",\n hasHeader = true,\n isActive = true,\n onInactivePress,\n inactivePressLabel,\n hasScrim = true,\n overlayLayer,\n variant = \"default\",\n closeLabel = \"Close\",\n portalContainer,\n footer,\n className,\n children,\n ...rest\n },\n ref,\n) {\n const { layer, isVisible, isResumed } = useDialogPresence(isOpen, isHidden, overlayLayer);\n const { active, isInert, canPress, frameInert, panelAttributes } = drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden: rest[\"aria-hidden\"],\n });\n const panelRef = useRef<HTMLDivElement | null>(null);\n const scrimRef = useRef<HTMLDivElement | null>(null);\n const closeRef = useRef<HTMLButtonElement | null>(null);\n const titleId = useId();\n const descriptionId = useId();\n const [exiting, onTransitionEnd] = useDrawerExit(isOpen, scrimRef);\n const { onScrimMouseDown, order } = useModalDialog({\n isOpen,\n isActive: active,\n layer,\n panelRef,\n onClose,\n // A hidden header's close button can't take focus.\n initialFocus: variant === \"navigation\" && hasHeader ? () => closeRef.current : undefined,\n // Panels start off-screen; focusing them must not scroll the page with them.\n preventScroll: true,\n container: portalContainer,\n });\n const portal = useDialogPortal(order, isOpen || exiting, portalContainer);\n useInheritedPortalScope(scrimRef, isOpen, { keepDir: rest.dir !== undefined });\n\n if ((!isOpen && !exiting) || !portal) {\n return null;\n }\n\n return createPortal(\n <DialogContent\n layer={layer}\n isSuspended={isInert}\n >\n <div\n ref={(node) => {\n scrimRef.current = node;\n if (node) {\n node.inert = frameInert;\n }\n }}\n className=\"ds-drawer-scrim\"\n hidden={!isVisible}\n data-scrim={hasScrim ? undefined : \"none\"}\n data-inactive-press={canPress || undefined}\n data-resumed={isResumed || undefined}\n style={{ zIndex: layer }}\n dir={rest.dir}\n data-side={side}\n data-variant={variant}\n data-contained={portalContainer ? \"\" : undefined}\n data-state={isOpen ? \"open\" : \"closed\"}\n aria-hidden={frameInert || undefined}\n onTransitionEnd={onTransitionEnd}\n onMouseDown={onScrimMouseDown}\n >\n <div\n {...rest}\n ref={mergeRefs(panelRef, ref)}\n {...dialogAttributes(rest, titleId, descriptionId, Boolean(description), active)}\n {...panelAttributes}\n data-side={side}\n data-size={size}\n data-header={hasHeader ? undefined : \"none\"}\n data-variant={variant}\n className={[\"ds-drawer\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n >\n <DrawerContent\n isInert={isInert}\n title={title}\n description={description}\n onClose={onClose}\n hasHeader={hasHeader}\n variant={variant}\n closeLabel={closeLabel}\n titleId={titleId}\n descriptionId={descriptionId}\n closeRef={closeRef}\n footer={footer}\n onInactivePress={canPress ? onInactivePress : undefined}\n inactivePressLabel={inactivePressLabel}\n >\n {children}\n </DrawerContent>\n </div>\n </div>\n </DialogContent>,\n portal,\n );\n});\n"],"mappings":"A,qSAOA,SAAgBuB,EAAW,CACzB,QACA,cACA,UACA,YACA,UACA,aACA,UACA,gBACA,YACY,CACZ,OACE,EAAAD,EAAA,KAAA,CAAC,SAAD,CACE,UAAU,kBACV,OAAQ,CAACE,EAFX,SAAA,EAIE,EAAA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C,aAAYxB,EAAS,OAAS,SAC9B,cAAa2B,GAAc,IAAA,GACV,kBACjB,YAAaK,EAEb,UAAA,EAAAhD,EAAA,IAAA,CAAC,MAAD,CACE,GAAImC,EACJ,IAAK5C,EAAAA,EAAU+C,EAAUW,CAAG,EAC5B,GAAIzD,EAAAA,EAAiB2C,EAAMhC,EAASG,EAAe,EAAQD,EAAcO,CAAM,EAC/E,GAAIsC,EACJ,YAAWH,EACX,YAAWI,EACX,cAAajD,EAAY,IAAA,GAAY,OACrC,eAAcM,EACd,UAAW,CAAC,YAAa,mBAAoB4C,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAEhF,UAAA,EAAApD,EAAA,IAAA,CAACoB,EAAD,CACW,UACF,QACM,cACJ,UACE,YACF,UACG,aACH,UACM,gBACL,WACF,SACR,gBAAiBH,EAAWC,EAAkB,IAAA,GAC1B,qBAEnB,UACY,CAAA,CACZ,CAAA,CACF,CAAA,CACQ,CAAA,EACfuB,CACF,CACF,CAAC,E"}
|
|
1
|
+
{"version":3,"file":"Drawer-DdIH9jpe.cjs","names":["Button","_Fragment","Button","useState","transitionDurationMs","forwardRef","useDialogPresence","useRef","useId","useModalDialog","useDialogPortal","createPortal","DialogContent","mergeRefs","dialogAttributes","require_components_Button_index","require_transitionDuration","require_mergeRefs","require_overlayLayer","require_dialogLabel","react","react_dom","react_jsx_runtime","DrawerHead","hasHeader","titleId","title","description","descriptionId","closeRef","variant","closeLabel","onClose","drawerInteraction","active","isActive","isVisible","isInert","isOpen","canPress","onInactivePress","ariaHidden","DrawerContent","head","node","footer","inactivePressLabel","event","useDrawerExit","previousOpen","setPreviousOpen","exiting","setExiting","duration","scrimRef","timeout","Drawer","rest","isHidden","overlayLayer","panelRef","onTransitionEnd","portalContainer","portal","order","frameInert","hasScrim","isResumed","layer","side","onScrimMouseDown","ref","panelAttributes","size","className"],"sources":["../../src/components/Drawer/head.tsx","../../src/components/Drawer/content.tsx","../../src/components/Drawer/index.tsx"],"sourcesContent":["import type { RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport type { DrawerProps } from \".\";\ntype HeadProps = Pick<\n DrawerProps,\n \"title\" | \"description\" | \"onClose\" | \"hasHeader\" | \"variant\" | \"closeLabel\"\n> & { titleId: string; descriptionId: string; closeRef: RefObject<HTMLButtonElement | null> };\nexport function DrawerHead({\n title,\n description,\n onClose,\n hasHeader,\n variant,\n closeLabel,\n titleId,\n descriptionId,\n closeRef,\n}: HeadProps) {\n return (\n <header\n className=\"ds-drawer__head\"\n hidden={!hasHeader}\n >\n <div className=\"ds-drawer__titles\">\n <h2\n id={titleId}\n className=\"ds-drawer__title\"\n >\n {title}\n </h2>\n {description && (\n <p\n id={descriptionId}\n className=\"ds-drawer__description\"\n >\n {description}\n </p>\n )}\n </div>\n <Button\n ref={closeRef}\n variant=\"simple\"\n size={variant === \"navigation\" ? \"lg\" : \"sm\"}\n isIconOnly\n iconStart=\"x\"\n className={variant === \"navigation\" ? \"ds-drawer__close\" : undefined}\n aria-label={closeLabel}\n onClick={onClose}\n />\n </header>\n );\n}\n","import type { ComponentProps } from \"react\";\nimport { Button } from \"../Button\";\nimport { DrawerHead } from \"./head\";\nimport type { DrawerProps } from \".\";\n\ntype ContentProps = ComponentProps<typeof DrawerHead> &\n Pick<DrawerProps, \"children\" | \"footer\" | \"onInactivePress\" | \"inactivePressLabel\"> & {\n isInert: boolean;\n };\n\n/** Distinguish modal participation from an application's inactive-panel action. */\nexport function drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden,\n}: {\n isOpen: boolean;\n isVisible: boolean;\n isActive: boolean;\n onInactivePress?: () => void;\n ariaHidden?: DrawerProps[\"aria-hidden\"];\n}) {\n const active = isActive && isVisible;\n const isInert = !isOpen || !active;\n const canPress = isOpen && isVisible && !isActive && Boolean(onInactivePress);\n return {\n active,\n isInert,\n canPress,\n frameInert: isInert && !canPress,\n panelAttributes: {\n \"aria-hidden\": canPress ? ariaHidden : isInert || ariaHidden,\n tabIndex: canPress ? undefined : -1,\n },\n };\n}\n\n/** Keep editors mounted inside an inert boundary, with activation outside it. */\nexport function DrawerContent({\n isInert,\n children,\n footer,\n onInactivePress,\n inactivePressLabel,\n ...head\n}: ContentProps) {\n return (\n <>\n <div\n className=\"ds-drawer__content\"\n ref={(node) => {\n if (node) {\n node.inert = isInert;\n node.toggleAttribute(\"inert\", isInert);\n }\n }}\n aria-hidden={isInert || undefined}\n >\n <DrawerHead {...head} />\n <div className=\"ds-drawer__body\">{children}</div>\n {footer && <footer className=\"ds-drawer__footer ds-field-surface\">{footer}</footer>}\n </div>\n {onInactivePress && (\n <Button\n variant=\"simple\"\n className=\"ds-drawer__inactive-press\"\n aria-label={\n inactivePressLabel ??\n (typeof head.title === \"string\" ? `Return to ${head.title}` : \"Activate drawer\")\n }\n tabIndex={-1}\n onPointerDown={(event) => event.preventDefault()}\n onClick={(event) => {\n event.stopPropagation();\n onInactivePress();\n }}\n />\n )}\n </>\n );\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useRef,\n useState,\n type HTMLAttributes,\n type ReactNode,\n type RefObject,\n type TransitionEvent,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { DrawerContent, drawerInteraction } from \"./content\";\nimport { transitionDurationMs } from \"../../internal/transitionDuration\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { useDialogPortal } from \"../../internal/useDialogPortal\";\nimport { useModalDialog } from \"../../internal/useModalDialog\";\nimport { dialogAttributes } from \"../../internal/dialogLabel\";\nimport { useInheritedPortalScope } from \"../../internal/portalScope\";\nimport { DialogContent, useDialogPresence } from \"../../internal/overlayLayer\";\nimport \"./style.css\";\n\nexport type DrawerSide = \"end\" | \"start\" | \"bottom\";\nexport type DrawerSize = \"md\" | \"wide\";\n\nexport interface DrawerProps extends Omit<HTMLAttributes<HTMLDivElement>, \"title\"> {\n isOpen: boolean;\n /**\n * Visually suspend an open dialog while retaining its mounted children. It\n * stays laid out but invisible and inert, so scroll positions are kept.\n */\n isHidden?: boolean;\n /** Escape, the scrim and the close button all call this. */\n onClose: () => void;\n title: ReactNode;\n description?: string;\n /** Which edge the panel is anchored to. */\n side?: DrawerSide;\n size?: DrawerSize;\n /** Without it the title still names the dialog; give people another way to close it. */\n hasHeader?: boolean;\n /**\n * Only the active panel traps focus and handles Escape. An inactive open\n * panel stays visible and mounted as an inert background panel.\n */\n isActive?: boolean;\n /** Activate an exposed inactive panel. Its editor stays inert; the app decides whether to activate it. */\n onInactivePress?: () => void;\n /** Accessible name for the inactive-panel action; defaults to Return to {title} for string titles. */\n inactivePressLabel?: string;\n /** Without a scrim, presses outside the panel reach the page beneath. */\n hasScrim?: boolean;\n /**\n * z-index for this panel and the dialogs and popovers opened from it.\n * Defaults to an enclosing `OverlayLayer`, then the stylesheet. Keep it below\n * the toast layer (80).\n */\n overlayLayer?: number;\n /** Navigation uses a compact panel, header and footer. Both variants slide in and out. */\n variant?: \"default\" | \"navigation\";\n /** Accessible name of the dismiss button. */\n closeLabel?: string;\n /**\n * Defaults to document.body, covering the viewport. A navigation drawer\n * portaled into a positioned element, such as an app shell, stays inside it.\n */\n portalContainer?: HTMLElement | null;\n /** Actions, right-aligned. The confirming action goes last. */\n footer?: ReactNode;\n children?: ReactNode;\n}\n\nfunction useDrawerExit(isOpen: boolean, scrimRef: RefObject<HTMLDivElement | null>) {\n const [previousOpen, setPreviousOpen] = useState(isOpen);\n const [exiting, setExiting] = useState(false);\n\n if (previousOpen !== isOpen) {\n setPreviousOpen(isOpen);\n setExiting(!isOpen);\n }\n\n useEffect(() => {\n if (!exiting || isOpen) {\n return;\n }\n // Read the actual transition, including token overrides and reduced motion.\n const duration = transitionDurationMs(scrimRef.current!);\n const timeout = window.setTimeout(() => setExiting(false), duration);\n return () => window.clearTimeout(timeout);\n }, [exiting, isOpen, scrimRef]);\n\n const onTransitionEnd = (event: TransitionEvent<HTMLDivElement>) => {\n if (event.target === event.currentTarget && event.propertyName === \"opacity\" && !isOpen) {\n setExiting(false);\n }\n };\n return [exiting, onTransitionEnd] as const;\n}\n\n/**\n * A side panel for work that belongs beside the page rather than on top of it\n * — editing one record, a filter set, a revision history. Same frame, rules\n * and footer band as `Modal`, with square corners and a full slide through\n * its anchored edge. Focus is trapped while open.\n */\nexport const Drawer = forwardRef<HTMLDivElement, DrawerProps>(function Drawer(\n {\n isOpen,\n isHidden = false,\n onClose,\n title,\n description,\n side = \"end\",\n size = \"md\",\n hasHeader = true,\n isActive = true,\n onInactivePress,\n inactivePressLabel,\n hasScrim = true,\n overlayLayer,\n variant = \"default\",\n closeLabel = \"Close\",\n portalContainer,\n footer,\n className,\n children,\n ...rest\n },\n ref,\n) {\n const { layer, isVisible, isResumed } = useDialogPresence(isOpen, isHidden, overlayLayer);\n const { active, isInert, canPress, frameInert, panelAttributes } = drawerInteraction({\n isOpen,\n isVisible,\n isActive,\n onInactivePress,\n ariaHidden: rest[\"aria-hidden\"],\n });\n const panelRef = useRef<HTMLDivElement | null>(null);\n const scrimRef = useRef<HTMLDivElement | null>(null);\n const closeRef = useRef<HTMLButtonElement | null>(null);\n const titleId = useId();\n const descriptionId = useId();\n const [exiting, onTransitionEnd] = useDrawerExit(isOpen, scrimRef);\n const { onScrimMouseDown, order } = useModalDialog({\n isOpen,\n isActive: active,\n layer,\n panelRef,\n onClose,\n // A hidden header's close button can't take focus.\n initialFocus: variant === \"navigation\" && hasHeader ? () => closeRef.current : undefined,\n // Panels start off-screen; focusing them must not scroll the page with them.\n preventScroll: true,\n container: portalContainer,\n });\n const portal = useDialogPortal(order, isOpen || exiting, portalContainer);\n useInheritedPortalScope(scrimRef, isOpen, { keepDir: rest.dir !== undefined });\n\n if ((!isOpen && !exiting) || !portal) {\n return null;\n }\n\n return createPortal(\n <DialogContent\n layer={layer}\n isSuspended={isInert}\n >\n <div\n ref={(node) => {\n scrimRef.current = node;\n if (node) {\n node.inert = frameInert;\n }\n }}\n className=\"ds-drawer-scrim\"\n hidden={!isVisible}\n data-scrim={hasScrim ? undefined : \"none\"}\n data-inactive-press={canPress || undefined}\n data-resumed={isResumed || undefined}\n style={{ zIndex: layer }}\n dir={rest.dir}\n data-side={side}\n data-variant={variant}\n data-contained={portalContainer ? \"\" : undefined}\n data-state={isOpen ? \"open\" : \"closed\"}\n aria-hidden={frameInert || undefined}\n onTransitionEnd={onTransitionEnd}\n onMouseDown={onScrimMouseDown}\n >\n <div\n {...rest}\n ref={mergeRefs(panelRef, ref)}\n {...dialogAttributes(rest, titleId, descriptionId, Boolean(description), active)}\n {...panelAttributes}\n data-side={side}\n data-size={size}\n data-header={hasHeader ? undefined : \"none\"}\n data-variant={variant}\n className={[\"ds-drawer\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n >\n <DrawerContent\n isInert={isInert}\n title={title}\n description={description}\n onClose={onClose}\n hasHeader={hasHeader}\n variant={variant}\n closeLabel={closeLabel}\n titleId={titleId}\n descriptionId={descriptionId}\n closeRef={closeRef}\n footer={footer}\n onInactivePress={canPress ? onInactivePress : undefined}\n inactivePressLabel={inactivePressLabel}\n >\n {children}\n </DrawerContent>\n </div>\n </div>\n </DialogContent>,\n portal,\n );\n});\n"],"mappings":"A,qSAOA,SAAgBuB,EAAW,CACzB,QACA,cACA,UACA,YACA,UACA,aACA,UACA,gBACA,YACY,CACZ,OACE,EAAAD,EAAA,KAAA,CAAC,SAAD,CACE,UAAU,kBACV,OAAQ,CAACE,EAFX,SAAA,EAIE,EAAAF,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,oBAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,KAAD,CACE,GAAIG,EACJ,UAAU,mBAET,SAAAC,CACC,CAAA,EACHC,IACC,EAAAL,EAAA,IAAA,CAAC,IAAD,CACE,GAAIM,EACJ,UAAU,yBAET,SAAAD,CACA,CAAA,CAEF,CACL,CAAA,GAAA,EAAAL,EAAA,IAAA,CAACtB,EAAAA,OAAD,CACE,IAAK6B,EACL,QAAQ,SACR,KAAMC,IAAY,aAAe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,CAAC,YAAa,mBAAoB4C,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,EAEhF,UAAA,EAAApD,EAAA,IAAA,CAACoB,EAAD,CACW,UACF,QACM,cACJ,UACE,YACF,UACG,aACH,UACM,gBACL,WACF,SACR,gBAAiBH,EAAWC,EAAkB,IAAA,GAC1B,qBAEnB,UACY,CAAA,CACZ,CAAA,CACF,CAAA,CACQ,CAAA,EACfuB,CACF,CACF,CAAC,E"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("../components/Button/index.cjs"),t=require("./use-picker-session-
|
|
2
|
-
//# sourceMappingURL=EntryPicker-
|
|
1
|
+
const e=require("../components/Button/index.cjs"),t=require("./use-picker-session-CM0zcEbf.cjs"),n=require("./style-nulIa2_8.cjs"),r=require("../components/SortableList/index.cjs");let i=require("react"),a=require("react/jsx-runtime");function o({items:n,selected:o,onChange:s,onEdit:c,isDisabled:l,canReorder:u,emptyLabel:d}){let f=(0,i.useId)(),p=(e,n)=>t.f(e)?`${f}-reason-${n}`:void 0,m=(n,r)=>(0,a.jsxs)(`span`,{className:`ds-entry-picker__item-actions`,children:[(0,a.jsx)(t.u,{item:n}),(0,a.jsx)(t.c,{item:n,onEdit:n.tone===`removed`?void 0:c,isDisabled:l}),(0,a.jsx)(e.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${n.title}`,"aria-describedby":r,isDisabled:l,onClick:()=>s(o.filter(e=>e!==n.id))})]});return n.length===0?(0,a.jsx)(`p`,{className:`ds-entry-picker__empty`,children:d}):u?(0,a.jsx)(r.SortableList,{items:o,onReorder:s,isDisabled:l,children:n.map((e,n)=>(0,a.jsx)(r.SortableListItem,{id:e.id,label:e.title,"data-tone":e.tone,handleDescribedBy:p(e,n),action:m(e,p(e,n)),children:(0,a.jsx)(`div`,{className:`ds-entry`,children:(0,a.jsx)(t.d,{item:e,reasonId:p(e,n)})})},e.id))}):(0,a.jsx)(`ul`,{className:`ds-entry-picker__list`,children:n.map((e,n)=>(0,a.jsxs)(`li`,{className:`ds-entry-picker__row ds-field-surface`,"data-tone":e.tone,children:[(0,a.jsx)(`div`,{className:`ds-entry`,children:(0,a.jsx)(t.d,{item:e,reasonId:p(e,n)})}),m(e,p(e,n))]},e.id))})}var s=[];function c({items:r=s,value:c,defaultValue:l=[],onValueChange:u,mode:d=`multiple`,max:f,label:p=`Entries`,emptyLabel:m=`Nothing selected yet.`,addLabel:h=`Choose entries`,itemLabel:g=`entry`,itemsLabel:_=`entries`,isReorderable:v=!0,isDisabled:y=!1,loadPage:b,pageSize:x=10,resolveItem:S,onEditItem:C,onCreate:w,isCreating:T=!1,refreshKey:E,dialogTitle:D,dialogDescription:O,isDialogHidden:k=!1,className:A,...j}){let[M,N]=(0,i.useState)(l),P=c??M,[F,I]=(0,i.useState)(!1),L=t.t(P,r,{resolveItem:S,refreshKey:E,loadPage:b,pageSize:x,mode:d,max:f,onEditItem:C},{isOpen:F,isDisabled:y,itemLabel:g,itemsLabel:_,close:()=>I(!1)}),{selection:R,remote:z,cap:B,editItem:V}=L,H=t.a(`Couldn't load selected ${_}`,R.status,R.error,R.retry),U=e=>{y||(c===void 0&&N(e),u?.(e))},W=(e,t)=>{R.remember([t],L.revision,e),U(e)},G=e=>{let t=L.choice(e);t&&(d===`single`?(W(P[0]===e?[]:[e],t),I(!1)):P.includes(e)?U(P.filter(t=>t!==e)):W([...P,e],t))},{known:K,failures:q}=R,J=!!S,Y=(0,i.useMemo)(()=>t.s({selected:P,items:r,pageItems:z.items,known:K,failures:q,hasResolver:J,itemLabel:g}),[P,r,z.items,K,q,J,g]);return(0,a.jsxs)(n.t,{...j,className:[`ds-entry-picker`,A].filter(Boolean).join(` `),label:p,count:t.n(d,P.length,f),limit:j.limit===void 0?B.limit:j.limit,children:[(0,a.jsx)(o,{items:Y,selected:P,onChange:U,onEdit:V,isDisabled:y,canReorder:v&&d===`multiple`&&Y.length>1,emptyLabel:m}),H,(0,a.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,a.jsx)(e.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:y,onClick:()=>I(!0),children:h}),P.length>0&&(0,a.jsx)(e.Button,{variant:`simple`,size:`sm`,isDisabled:y,onClick:()=>U([]),children:`Clear`})]}),(0,a.jsx)(t.i,{...L.dialog,isOpen:F,onClose:()=>I(!1),onToggle:G,addLabel:h,onCreate:w,isCreating:T,dialogTitle:D,dialogDescription:O,isDialogHidden:k})]})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return c}});
|
|
2
|
+
//# sourceMappingURL=EntryPicker-DmiAnu9l.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntryPicker-CgWbgWnc.cjs","names":["useId","selectedReason","RemovedLabel","EditItemButton","Button","SortableList","SortableListItem","SelectedEntry","useState","usePickerSession","useLoadError","useMemo","chosenItems","FieldGroup","selectionCount","Button","PickerDialog","require_components_Button_index","require_use_picker_session","require_group","require_components_SortableList_index","react","react_jsx_runtime","SelectedItems","id","reasonId","item","index","actions","onEdit","describedBy","onChange","selected","items","emptyLabel","canReorder","emptyItems","EntryPicker","fieldProps","internal","setInternal","defaultValue","value","isOpen","setOpen","session","resolutionError","itemsLabel","selection","commit","isDisabled","next","onValueChange","pick","toggle","mode","selectedId","hasResolver","resolveItem","chosen","remote","known","failures","itemLabel","className","max","cap","editItem","isReorderable","addLabel"],"sources":["../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row ds-field-surface\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { selectionCount } from \"./limit\";\nimport { usePickerSession } from \"./use-picker-session\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const session = usePickerSession(\n selected,\n items,\n { resolveItem, refreshKey, loadPage, pageSize, mode, max, onEditItem },\n { isOpen, isDisabled, itemLabel, itemsLabel, close: () => setOpen(false) },\n );\n const { selection, remote, cap, editItem } = session;\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n selection.remember([item], session.revision, next);\n commit(next);\n };\n // The session's choice enforces the selection rules, whichever control asked.\n const toggle = (id: string) => {\n const item = session.choice(id);\n if (!item) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n {...session.dialog}\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n onToggle={toggle}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":"A,2OAKA,SAAgBuB,EAAc,CAC5B,QACA,WACA,WACA,SACA,aACA,aACA,cASC,CACD,IAAMC,GAAA,EAAKxB,EAAAA,MAAAA,CAAM,EAEXyB,GAAY,EAAiB,IACjCxB,EAAAA,EAAeyB,CAAI,EAAI,GAAGF,EAAG,UAAUG,IAAU,IAAA,GAC7CC,GAAW,EAAiB,KAChC,EAAAN,EAAA,KAAA,CAAC,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O,aACZ,YAAekC,EAAO,CAAC,CAAC,EACzB,SAAA,OAEO,CAAA,CAEP,C,IACL,EAAA3B,EAAA,IAAA,CAACN,EAAAA,EAAD,CACE,GAAI6B,EAAQ,OACJ,SACR,YAAeD,EAAQ,EAAK,EAC5B,SAAUU,EACA,WACA,WACE,aACC,cACM,oBACH,gBACjB,CAAA,CACS,C,EAEhB,C"}
|
|
1
|
+
{"version":3,"file":"EntryPicker-DmiAnu9l.cjs","names":["useId","selectedReason","RemovedLabel","EditItemButton","Button","SortableList","SortableListItem","SelectedEntry","useState","usePickerSession","useLoadError","useMemo","chosenItems","FieldGroup","selectionCount","Button","PickerDialog","require_components_Button_index","require_use_picker_session","require_style","require_components_SortableList_index","react","react_jsx_runtime","SelectedItems","id","reasonId","item","index","actions","onEdit","describedBy","onChange","selected","items","emptyLabel","canReorder","emptyItems","EntryPicker","fieldProps","internal","setInternal","defaultValue","value","isOpen","setOpen","session","resolutionError","itemsLabel","selection","commit","isDisabled","next","onValueChange","pick","toggle","mode","selectedId","hasResolver","resolveItem","chosen","remote","known","failures","itemLabel","className","max","cap","editItem","isReorderable","addLabel"],"sources":["../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row ds-field-surface\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { selectionCount } from \"./limit\";\nimport { usePickerSession } from \"./use-picker-session\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const session = usePickerSession(\n selected,\n items,\n { resolveItem, refreshKey, loadPage, pageSize, mode, max, onEditItem },\n { isOpen, isDisabled, itemLabel, itemsLabel, close: () => setOpen(false) },\n );\n const { selection, remote, cap, editItem } = session;\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n selection.remember([item], session.revision, next);\n commit(next);\n };\n // The session's choice enforces the selection rules, whichever control asked.\n const toggle = (id: string) => {\n const item = session.choice(id);\n if (!item) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n {...session.dialog}\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n onToggle={toggle}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":"A,2OAKA,SAAgBuB,EAAc,CAC5B,QACA,WACA,WACA,SACA,aACA,aACA,cASC,CACD,IAAMC,GAAA,EAAKxB,EAAAA,MAAAA,CAAM,EAEXyB,GAAY,EAAiB,IACjCxB,EAAAA,EAAeyB,CAAI,EAAI,GAAGF,EAAG,UAAUG,IAAU,IAAA,GAC7CC,GAAW,EAAiB,KAChC,EAAAN,EAAA,KAAA,CAAC,OAAD,CAAM,UAAU,gCAAhB,SAAA,EACE,EAAAA,EAAA,IAAA,CAACpB,EAAAA,EAAD,CAAoB,MAAO,CAAA,GAE3B,EAAAoB,EAAA,IAAA,CAACnB,EAAAA,EAAD,CACQ,OACN,OAAQuB,EAAK,OAAS,UAAY,IAAA,GAAYG,EAClC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,oBACH,gBACjB,CAAA,CACS,C,EAEhB,C"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Button as e } from "../components/Button/index.js";
|
|
2
|
-
import { a as t, c as n, d as r, f as i, i as a, n as o, s, t as c, u as l } from "./use-picker-session-
|
|
3
|
-
import { t as u } from "./
|
|
2
|
+
import { a as t, c as n, d as r, f as i, i as a, n as o, s, t as c, u as l } from "./use-picker-session-GCDShVBy.js";
|
|
3
|
+
import { t as u } from "./style-7Z_xRlQx.js";
|
|
4
4
|
import { SortableList as d, SortableListItem as f } from "../components/SortableList/index.js";
|
|
5
5
|
import { useId as p, useMemo as m, useState as h } from "react";
|
|
6
6
|
import { jsx as g, jsxs as _ } from "react/jsx-runtime";
|
|
@@ -157,4 +157,4 @@ function b({ items: n = y, value: r, defaultValue: i = [], onValueChange: l, mod
|
|
|
157
157
|
//#endregion
|
|
158
158
|
export { b as t };
|
|
159
159
|
|
|
160
|
-
//# sourceMappingURL=EntryPicker-
|
|
160
|
+
//# sourceMappingURL=EntryPicker-WERMwe0h.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntryPicker-DlEsVCvA.js","names":["useLoadError","EditItemButton","SelectedEntry","selectedReason","PickerDialog","selectionCount","usePickerSession","RemovedLabel","FieldGroup","SelectedItems","id","useId","reasonId","item","index","actions","onEdit","Button","describedBy","onChange","selected","items","emptyLabel","canReorder","SortableList","SortableListItem","emptyItems","EntryPicker","fieldProps","internal","setInternal","useState","defaultValue","value","isOpen","setOpen","session","resolutionError","itemsLabel","selection","commit","isDisabled","next","onValueChange","pick","toggle","mode","selectedId","hasResolver","resolveItem","chosen","useMemo","chosenItems","remote","known","failures","itemLabel","className","max","cap","editItem","isReorderable","addLabel"],"sources":["../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row ds-field-surface\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { selectionCount } from \"./limit\";\nimport { usePickerSession } from \"./use-picker-session\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const session = usePickerSession(\n selected,\n items,\n { resolveItem, refreshKey, loadPage, pageSize, mode, max, onEditItem },\n { isOpen, isDisabled, itemLabel, itemsLabel, close: () => setOpen(false) },\n );\n const { selection, remote, cap, editItem } = session;\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n selection.remember([item], session.revision, next);\n commit(next);\n };\n // The session's choice enforces the selection rules, whichever control asked.\n const toggle = (id: string) => {\n const item = session.choice(id);\n if (!item) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n {...session.dialog}\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n onToggle={toggle}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":";;;;;;;AAKA,SAAgBS,EAAc,EAC5B,UACA,aACA,aACA,WACA,eACA,eACA,iBASC;CACD,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MAAe2B,MAAerC,CAAE,CAAC,IAEzDkC,EAAK,CAAC,GAAGxB,GAAUV,CAAE,GAAGG,CAAI;CAEhC,GACM,EAAE,UAAO,gBAAa0B,GACtBS,IAAc,EAAQC,GACtBC,IAASC,QAEXC,EAAY;EACV;EACA;EACA,WAAWC,EAAO;EAClB;EACA;EACA;EACA;CACF,CAAC,GACH;EAACjC;EAAUC;EAAOgC,EAAO;EAAOC;EAAOC;EAAUP;EAAaQ;CAAS,CACzE;CACA,OACE,kBAAChD,GAAD;EACE,GAAIoB;EACJ,WAAW,CAAC,mBAAmB6B,CAAS,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;EAC3D;EACP,OAAOpD,EAAeyC,GAAM1B,EAAS,QAAQsC,CAAG;EAChD,OAAO9B,EAAW,UAAU,KAAA,IAAY+B,EAAI,QAAQ/B,EAAW;EALjE,UAAA;GAOE,kBAACnB,GAAD;IACE,OAAOyC;IACG;IACV,UAAUV;IACV,QAAQoB;IACI;IACZ,YAAYC,KAAiBf,MAAS,cAAcI,EAAO,SAAS;IACxD;GACb,CAAA;GACAb;GACD,kBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACE,kBAACpB,GAAD;KACE,SAAQ;KACR,MAAK;KACL,WAAU;KACE;KACZ,eAAekB,EAAQ,EAAI;KAE1B,UAAA2B;IACK,CAAA,GACP1C,EAAS,SAAS,KACjB,kBAACH,GAAD;KACE,SAAQ;KACR,MAAK;KACO;KACZ,eAAeuB,EAAO,CAAC,CAAC;KACzB,UAAA;IAEO,CAAA,CAEP;;GACL,kBAACpC,GAAD;IACE,GAAIgC,EAAQ;IACJ;IACR,eAAeD,EAAQ,EAAK;IAC5B,UAAUU;IACA;IACA;IACE;IACC;IACM;IACH;GACjB,CAAA;EACS;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"EntryPicker-WERMwe0h.js","names":["useLoadError","EditItemButton","SelectedEntry","selectedReason","PickerDialog","selectionCount","usePickerSession","RemovedLabel","FieldGroup","SelectedItems","id","useId","reasonId","item","index","actions","onEdit","Button","describedBy","onChange","selected","items","emptyLabel","canReorder","SortableList","SortableListItem","emptyItems","EntryPicker","fieldProps","internal","setInternal","useState","defaultValue","value","isOpen","setOpen","session","resolutionError","itemsLabel","selection","commit","isDisabled","next","onValueChange","pick","toggle","mode","selectedId","hasResolver","resolveItem","chosen","useMemo","chosenItems","remote","known","failures","itemLabel","className","max","cap","editItem","isReorderable","addLabel"],"sources":["../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row ds-field-surface\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { selectionCount } from \"./limit\";\nimport { usePickerSession } from \"./use-picker-session\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const session = usePickerSession(\n selected,\n items,\n { resolveItem, refreshKey, loadPage, pageSize, mode, max, onEditItem },\n { isOpen, isDisabled, itemLabel, itemsLabel, close: () => setOpen(false) },\n );\n const { selection, remote, cap, editItem } = session;\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n selection.remember([item], session.revision, next);\n commit(next);\n };\n // The session's choice enforces the selection rules, whichever control asked.\n const toggle = (id: string) => {\n const item = session.choice(id);\n if (!item) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n {...session.dialog}\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n onToggle={toggle}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":";;;;;;;AAKA,SAAgBS,EAAc,EAC5B,UACA,aACA,aACA,WACA,eACA,eACA,iBASC;CACD,IAAMC,IAAKC,EAAM,GAEXC,KAAY,GAAiB,MACjCT,EAAeU,CAAI,IAAI,GAAGH,EAAG,UAAUI,MAAU,KAAA,GAC7CC,KAAW,GAAiB,MAChC,kBAAC,QAAD;EAAM,WAAU;EAAhB,UAAA;GACE,kBAACR,GAAD,EAAoB,QAAO,CAAA;GAE3B,kBAACN,GAAD;IACQ;IACN,QAAQY,EAAK,SAAS,YAAY,KAAA,IAAYG;IAClC;GACb,CAAA;GACD,kBAACC,GAAD;IACE,SAAQ;IACR,MAAK;IACL,YAAA;IACA,WAAU;IACV,cAAY,UAAUJ,EAAK;IAC3B,oBAAkBK;IACN;IACZ,eAAeC,EAASC,EAAS,QAAQ,MAAOV,MAAOG,EAAK,EAAE,CAAC;GAChE,CAAA;EACG;;CAgCR,OA9BIQ,EAAM,WAAW,IACZ,kBAAC,KAAD;EAAG,WAAU;EAA0B,UAAAC;CAAc,CAAA,IAE1DC,IAEA,kBAACC,GAAD;EACE,OAAOJ;EACP,WAAWD;EACC;EAEX,UAAAE,EAAM,KAAK,GAAM,MAChB,kBAACI,GAAD;GAEE,IAAIZ,EAAK;GACT,OAAOA,EAAK;GACZ,aAAWA,EAAK;GAChB,mBAAmBD,EAASC,GAAMC,CAAK;GACvC,QAAQC,EAAQF,GAAMD,E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