@namroodinc/liquid-editorial 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -18
- package/UPGRADING.md +252 -0
- package/dist/chunks/{Board-Cnyqrc-R.js → Board-BCS7sDXg.js} +13 -5
- package/dist/chunks/{Board-Cnyqrc-R.js.map → Board-BCS7sDXg.js.map} +1 -1
- package/dist/chunks/{Board-DFuJt2Oh.cjs → Board-CNVy8gHI.cjs} +2 -2
- package/dist/chunks/Board-CNVy8gHI.cjs.map +1 -0
- package/dist/chunks/{CollectionView-Vj84E26b.js → CollectionView-B0ZJxkNK.js} +4 -4
- package/dist/chunks/CollectionView-B0ZJxkNK.js.map +1 -0
- package/dist/chunks/CollectionView-DrszOUOt.cjs +2 -0
- package/dist/chunks/CollectionView-DrszOUOt.cjs.map +1 -0
- package/dist/chunks/ColourField-BdobU76j.cjs +2 -0
- package/dist/chunks/ColourField-BdobU76j.cjs.map +1 -0
- package/dist/chunks/{ColourField-DkO8tjeB.js → ColourField-C39pcjkG.js} +2 -2
- package/dist/chunks/ColourField-C39pcjkG.js.map +1 -0
- package/dist/chunks/{DatePicker-B8tllGYy.js → DatePicker-DDc1nDTb.js} +2 -2
- package/dist/chunks/DatePicker-DDc1nDTb.js.map +1 -0
- package/dist/chunks/DatePicker-Dpvfomrm.cjs +2 -0
- package/dist/chunks/DatePicker-Dpvfomrm.cjs.map +1 -0
- package/dist/chunks/{Drawer-DTtgAZO2.js → Drawer-C3mWT9Kh.js} +2 -2
- package/dist/chunks/Drawer-C3mWT9Kh.js.map +1 -0
- package/dist/chunks/Drawer-DTKZptua.cjs +2 -0
- package/dist/chunks/Drawer-DTKZptua.cjs.map +1 -0
- package/dist/chunks/EntryPicker-CgWbgWnc.cjs +2 -0
- package/dist/chunks/EntryPicker-CgWbgWnc.cjs.map +1 -0
- package/dist/chunks/{EntryPicker-KxHZzZsh.js → EntryPicker-DlEsVCvA.js} +3 -3
- package/dist/chunks/EntryPicker-DlEsVCvA.js.map +1 -0
- package/dist/chunks/{FormEditor-CdLqPaKK.js → FormEditor-CLLOHKiO.js} +6 -6
- package/dist/chunks/{FormEditor-CdLqPaKK.js.map → FormEditor-CLLOHKiO.js.map} +1 -1
- package/dist/chunks/{FormEditor-BJcAIVcL.cjs → FormEditor-iACd0El-.cjs} +2 -2
- package/dist/chunks/{FormEditor-BJcAIVcL.cjs.map → FormEditor-iACd0El-.cjs.map} +1 -1
- package/dist/chunks/{RichTextEditor-DmNM63Wg.js → RichTextEditor-B0P53GFt.js} +9 -9
- package/dist/chunks/RichTextEditor-B0P53GFt.js.map +1 -0
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs +2 -0
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs.map +1 -0
- package/dist/chunks/{use-picker-session-BDEWL2jK.js → use-picker-session-BnMxbGAZ.js} +3 -3
- package/dist/chunks/use-picker-session-BnMxbGAZ.js.map +1 -0
- package/dist/chunks/use-picker-session-DbfOJstX.cjs +2 -0
- package/dist/chunks/use-picker-session-DbfOJstX.cjs.map +1 -0
- 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.cjs.map +1 -1
- package/dist/components/AssetCard/index.d.cts.map +1 -1
- package/dist/components/AssetCard/index.d.ts.map +1 -1
- package/dist/components/AssetCard/index.js +16 -16
- package/dist/components/AssetCard/index.js.map +1 -1
- package/dist/components/AssetCard/style.css +47 -46
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.cjs.map +1 -1
- package/dist/components/AssetGrid/index.d.cts +0 -2
- package/dist/components/AssetGrid/index.d.cts.map +1 -1
- package/dist/components/AssetGrid/index.d.ts +0 -2
- package/dist/components/AssetGrid/index.d.ts.map +1 -1
- package/dist/components/AssetGrid/index.js +15 -15
- package/dist/components/AssetGrid/index.js.map +1 -1
- package/dist/components/Avatar/style.css +26 -5
- package/dist/components/Badge/index.cjs +1 -1
- package/dist/components/Badge/index.cjs.map +1 -1
- package/dist/components/Badge/index.d.cts +2 -3
- package/dist/components/Badge/index.d.cts.map +1 -1
- package/dist/components/Badge/index.d.ts +2 -3
- package/dist/components/Badge/index.d.ts.map +1 -1
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Badge/index.js.map +1 -1
- package/dist/components/Badge/style.css +20 -26
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Board/style.css +36 -15
- package/dist/components/Button/style.css +19 -10
- package/dist/components/ButtonGroup/index.cjs.map +1 -1
- package/dist/components/ButtonGroup/index.d.cts +1 -1
- package/dist/components/ButtonGroup/index.d.ts +1 -1
- package/dist/components/ButtonGroup/index.js.map +1 -1
- package/dist/components/ButtonGroup/style.css +4 -20
- package/dist/components/Choice/style.css +10 -9
- package/dist/components/CollectionView/index.cjs +1 -1
- package/dist/components/CollectionView/index.js +1 -1
- package/dist/components/CollectionView/style.css +8 -11
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/ColourField/style.css +28 -17
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/DatePicker/style.css +10 -3
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.js +1 -1
- package/dist/components/Drawer/style.css +11 -22
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.cjs.map +1 -1
- package/dist/components/EditLayout/index.js +2 -2
- package/dist/components/EditLayout/index.js.map +1 -1
- package/dist/components/EditLayout/style.css +10 -5
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/EntryPicker/style.css +43 -19
- package/dist/components/Field/style.css +6 -5
- package/dist/components/FormEditor/README.md +21 -5
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/ImageCropper/style.css +20 -20
- package/dist/components/Menu/style.css +2 -3
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.cjs.map +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/Modal/style.css +7 -5
- package/dist/components/Popover/style.css +2 -2
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RichTextEditor/style.css +59 -42
- 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 +5 -1
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SelectionCard/style.css +39 -12
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.cjs.map +1 -1
- package/dist/components/SideNav/index.d.cts +3 -3
- package/dist/components/SideNav/index.d.ts +3 -3
- package/dist/components/SideNav/index.js +15 -3
- package/dist/components/SideNav/index.js.map +1 -1
- package/dist/components/SideNav/style.css +19 -13
- package/dist/components/Slider/style.css +12 -14
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.cjs.map +1 -1
- package/dist/components/SortableList/index.js +6 -2
- package/dist/components/SortableList/index.js.map +1 -1
- package/dist/components/SortableList/style.css +20 -5
- package/dist/components/Stepper/style.css +8 -9
- package/dist/components/SubNav/index.cjs.map +1 -1
- package/dist/components/SubNav/index.d.cts +2 -2
- package/dist/components/SubNav/index.d.ts +2 -2
- package/dist/components/SubNav/index.js.map +1 -1
- package/dist/components/SubNav/style.css +3 -8
- 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 -2
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Switch/style.css +14 -6
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.cjs.map +1 -1
- package/dist/components/Table/index.js +2 -2
- package/dist/components/Table/index.js.map +1 -1
- package/dist/components/Table/style.css +34 -22
- package/dist/components/TagsInput/index.cjs +1 -1
- package/dist/components/TagsInput/index.cjs.map +1 -1
- package/dist/components/TagsInput/index.js +1 -1
- package/dist/components/TagsInput/index.js.map +1 -1
- package/dist/components/TagsInput/style.css +31 -6
- package/dist/components/Time/style.css +1 -1
- package/dist/components/Toast/style.css +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.cjs.map +1 -1
- package/dist/components/TopNav/index.d.cts +4 -4
- package/dist/components/TopNav/index.d.ts +4 -4
- package/dist/components/TopNav/index.js +5 -1
- package/dist/components/TopNav/index.js.map +1 -1
- package/dist/components/TopNav/style.css +6 -9
- package/dist/elements.css +0 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -44
- package/dist/message.css +8 -14
- package/dist/tokens.css +101 -43
- package/package.json +1 -1
- package/dist/chunks/Board-DFuJt2Oh.cjs.map +0 -1
- package/dist/chunks/CollectionView-BNYx29b1.cjs +0 -2
- package/dist/chunks/CollectionView-BNYx29b1.cjs.map +0 -1
- package/dist/chunks/CollectionView-Vj84E26b.js.map +0 -1
- package/dist/chunks/ColourField--rS9KDpq.cjs +0 -2
- package/dist/chunks/ColourField--rS9KDpq.cjs.map +0 -1
- package/dist/chunks/ColourField-DkO8tjeB.js.map +0 -1
- package/dist/chunks/DatePicker-B8tllGYy.js.map +0 -1
- package/dist/chunks/DatePicker-OiqjoO-f.cjs +0 -2
- package/dist/chunks/DatePicker-OiqjoO-f.cjs.map +0 -1
- package/dist/chunks/Drawer-BDX9_qHA.cjs +0 -2
- package/dist/chunks/Drawer-BDX9_qHA.cjs.map +0 -1
- package/dist/chunks/Drawer-DTtgAZO2.js.map +0 -1
- package/dist/chunks/EntryPicker-BI_7g2Wg.cjs +0 -2
- package/dist/chunks/EntryPicker-BI_7g2Wg.cjs.map +0 -1
- package/dist/chunks/EntryPicker-KxHZzZsh.js.map +0 -1
- package/dist/chunks/RichTextEditor-BXyhSeJd.cjs +0 -2
- package/dist/chunks/RichTextEditor-BXyhSeJd.cjs.map +0 -1
- package/dist/chunks/RichTextEditor-DmNM63Wg.js.map +0 -1
- package/dist/chunks/use-picker-session-BDEWL2jK.js.map +0 -1
- package/dist/chunks/use-picker-session-C4FGinLN.cjs +0 -2
- package/dist/chunks/use-picker-session-C4FGinLN.cjs.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ColourField-DkO8tjeB.js","names":["_Fragment","Icon","mergeRefs","tabbableControls","useOverlayOpen","parseColour","colourState","normaliseColour","colourHex","Slider","Fragment$1","focusAfterField","boundary","root","controls","element","clamp","value","ColourSquare","dragging","useRef","update","rect","event","onChange","colour","isDisabled","step","change","useColourValue","internal","setInternal","useState","defaultValue","current","selection","setSelection","hex","next","onValueChange","useColourDraft","draft","setDraft","isValid","eyeDropperConstructor","subscribe","noPresets","presetColumns","presetTarget","column","index","lastInColumn","count","key","ColourPanel","forwardRef","rest","ColourPanelContent","commit","inputRef","active","disabledRef","isPicking","setPicking","pickerError","setPickerError","hasEyeDropper","useSyncExternalStore","presetsId","useId","rgb","swatches","useMemo","unique","preset","presets","normalised","selectedIndex","swatch","useEffect","pickFromScreen","EyeDropper","result","onColourChange","error","className","style","picker","Button","delta","input","a","showPresets","radios","selected","ColourField","ariaInvalid","open","setOpen","isOpen","rootRef","openerRef","panelRef","panelId","fieldId","id","invalid","text","effectiveDisabled","disabled","readOnly","visible","onValidityChange","outside","target","toggle","opener","close","triggerProps","FieldAffix","TextField","ref","isInvalid","valid","type","discard","onBlur","onKeyDown","Popover"],"sources":["../../src/components/ColourField/focus.ts","../../src/components/ColourField/square.tsx","../../src/components/ColourField/value.ts","../../src/components/ColourField/panel.tsx","../../src/components/ColourField/index.tsx"],"sourcesContent":["import { tabbableControls } from \"../../internal/dialogFocus\";\n\n/** Continue after the composed field, respecting an enclosing modal's focus boundary. */\nexport function focusAfterField(root: HTMLElement) {\n const boundary = root.closest<HTMLElement>(\"[aria-modal='true']\") ?? document.body;\n const controls = tabbableControls(boundary).filter((element) => !element.closest(\".ds-popover\"));\n const last = controls.map((element) => root.contains(element)).lastIndexOf(true);\n const next = controls[last + 1] ?? controls[0];\n next?.focus({ preventScroll: true });\n}\n","import { useRef, type KeyboardEvent, type PointerEvent } from \"react\";\nimport type { Colour } from \"./colour\";\n\ninterface ColourSquareProps {\n colour: Colour;\n isDisabled: boolean;\n onChange: (colour: Colour) => void;\n}\n\nfunction clamp(value: number) {\n return Math.max(0, Math.min(100, value));\n}\n\nexport function ColourSquare({ colour, isDisabled, onChange }: ColourSquareProps) {\n const dragging = useRef<number | null>(null);\n const update = (event: PointerEvent<HTMLDivElement>) => {\n const rect = event.currentTarget.getBoundingClientRect();\n if (!rect.width || !rect.height) {\n return;\n }\n onChange({\n ...colour,\n s: clamp(((event.clientX - rect.left) / rect.width) * 100),\n v: clamp((1 - (event.clientY - rect.top) / rect.height) * 100),\n });\n };\n const handleKey = (event: KeyboardEvent) => {\n if (isDisabled) {\n return;\n }\n const step = event.shiftKey ? 10 : 1;\n const changes: Record<string, Partial<Colour>> = {\n ArrowLeft: { s: clamp(colour.s - step) },\n ArrowRight: { s: clamp(colour.s + step) },\n ArrowDown: { v: clamp(colour.v - step) },\n ArrowUp: { v: clamp(colour.v + step) },\n Home: { s: 0 },\n End: { s: 100 },\n };\n const change = changes[event.key];\n if (!change) {\n return;\n }\n event.preventDefault();\n onChange({ ...colour, ...change });\n };\n return (\n <div\n className=\"ds-colour-panel__square\"\n role=\"slider\"\n tabIndex={isDisabled ? -1 : 0}\n aria-label=\"Saturation and brightness\"\n aria-valuemin={0}\n aria-valuemax={100}\n aria-valuenow={Math.round(colour.s)}\n aria-valuetext={`Saturation ${Math.round(colour.s)}%, brightness ${Math.round(colour.v)}%`}\n aria-disabled={isDisabled || undefined}\n onKeyDown={handleKey}\n onPointerDown={(event) => {\n if (isDisabled || event.button !== 0) {\n return;\n }\n event.preventDefault();\n event.currentTarget.focus();\n dragging.current = event.pointerId;\n event.currentTarget.setPointerCapture(event.pointerId);\n update(event);\n }}\n onPointerMove={(event) => {\n if (!isDisabled && dragging.current === event.pointerId) {\n update(event);\n }\n }}\n onPointerUp={(event) => {\n if (dragging.current !== event.pointerId) {\n return;\n }\n dragging.current = null;\n event.currentTarget.releasePointerCapture(event.pointerId);\n }}\n onPointerCancel={() => {\n dragging.current = null;\n }}\n onLostPointerCapture={() => {\n dragging.current = null;\n }}\n >\n <span\n className=\"ds-colour-panel__thumb\"\n style={{ left: `${colour.s}%`, top: `${100 - colour.v}%` }}\n />\n </div>\n );\n}\n","import { useState } from \"react\";\nimport { colourHex, colourState, normaliseColour, type Colour } from \"./colour\";\n\nexport interface ColourValueProps {\n value?: string;\n defaultValue?: string;\n /** Uppercase hex (including alpha when needed), or an empty string when cleared. */\n onValueChange?: (value: string) => void;\n}\n\nexport function useColourValue({ value, defaultValue = \"\", onValueChange }: ColourValueProps) {\n const [internal, setInternal] = useState(defaultValue);\n const current = value ?? internal;\n const [selection, setSelection] = useState(() => ({\n source: current,\n colour: colourState(current),\n }));\n let colour = selection.colour;\n if (selection.source !== current) {\n colour = colourState(current, colour);\n setSelection({ source: current, colour });\n }\n\n const commit = (next: string | Colour) => {\n const hex = typeof next === \"string\" ? normaliseColour(next) : colourHex(next);\n setSelection({\n source: hex,\n colour: typeof next === \"string\" ? colourState(next, colour) : next,\n });\n if (value === undefined) {\n setInternal(hex);\n }\n onValueChange?.(hex);\n };\n\n return { current, colour, commit };\n}\n\n/** Typed text the field shows until it is committed, blurred, or replaced. */\nexport function useColourDraft(current: string, hex: string) {\n const [draft, setDraft] = useState<{ source: string; text: string } | null>(null);\n // A draft belongs to the value it was typed over. A parent that stores the invalid\n // text (FormEditor does) takes it over, so restoring the earlier value then wins.\n if (draft && draft.source !== current && draft.text === current) {\n setDraft({ source: current, text: current });\n }\n const text = draft?.source === current ? draft.text : hex || current;\n /** Valid text becomes the committed hex; invalid text stays over the current value. */\n const type = (next: string, isValid: boolean) =>\n setDraft({ source: isValid ? normaliseColour(next) : current, text: next });\n return { text, type, discard: () => setDraft(null) };\n}\n","import {\n forwardRef,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n type CSSProperties,\n type HTMLAttributes,\n} from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Slider } from \"../Slider\";\nimport { colourHex, colourState, normaliseColour, parseColour, type Colour } from \"./colour\";\nimport { ColourSquare } from \"./square\";\nimport { useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport interface ColourPickerOptions {\n presets?: string[];\n showPresets?: boolean;\n picker?: \"custom\" | \"native\";\n isDisabled?: boolean;\n}\n\nexport interface ColourPanelProps\n extends\n Omit<HTMLAttributes<HTMLDivElement>, \"defaultValue\" | \"onChange\">,\n ColourValueProps,\n ColourPickerOptions {}\n\ninterface EyeDropperInstance {\n open: () => Promise<{ sRGBHex: string }>;\n}\nfunction eyeDropperConstructor() {\n return (window as Window & { EyeDropper?: new () => EyeDropperInstance }).EyeDropper;\n}\nconst subscribe = () => () => {};\nconst noPresets: string[] = [];\nconst presetColumns = 8;\n\n/** Where a key moves within the preset grid; rows wrap within their column. */\nfunction presetTarget(key: string, index: number, count: number) {\n const column = index % presetColumns;\n const lastInColumn = column + Math.floor((count - 1 - column) / presetColumns) * presetColumns;\n switch (key) {\n case \"Home\":\n return 0;\n case \"End\":\n return count - 1;\n case \"ArrowRight\":\n return (index + 1) % count;\n case \"ArrowLeft\":\n return (index - 1 + count) % count;\n case \"ArrowDown\":\n return index + presetColumns < count ? index + presetColumns : column;\n case \"ArrowUp\":\n return index >= presetColumns ? index - presetColumns : lastInColumn;\n default:\n return undefined;\n }\n}\n\n/** A standalone colour selection surface, also composed by ColourField. */\nexport const ColourPanel = forwardRef<HTMLDivElement, ColourPanelProps>(function ColourPanel(\n { value, defaultValue, onValueChange, ...rest },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n return (\n <ColourPanelContent\n {...rest}\n ref={ref}\n colour={colour}\n current={current}\n onColourChange={commit}\n />\n );\n});\n\ninterface ColourPanelContentProps extends Omit<\n ColourPanelProps,\n \"value\" | \"defaultValue\" | \"onValueChange\"\n> {\n colour: Colour;\n current: string;\n onColourChange: (colour: Colour | string) => void;\n}\n\nexport const ColourPanelContent = forwardRef<HTMLDivElement, ColourPanelContentProps>(\n function ColourPanelContent(\n {\n colour,\n current,\n onColourChange,\n presets = noPresets,\n showPresets = true,\n picker = \"custom\",\n isDisabled = false,\n className,\n style,\n ...rest\n },\n ref,\n ) {\n const inputRef = useRef<HTMLInputElement>(null);\n const active = useRef(true);\n const disabledRef = useRef(isDisabled);\n const [isPicking, setPicking] = useState(false);\n const [pickerError, setPickerError] = useState(\"\");\n const hasEyeDropper = useSyncExternalStore(\n subscribe,\n () => Boolean(eyeDropperConstructor()),\n () => false,\n );\n const presetsId = useId();\n const hex = normaliseColour(current);\n const rgb = colourHex({ ...colour, a: 1 });\n // Equivalent spellings collapse onto the first; each preset is parsed once.\n const swatches = useMemo(() => {\n const unique = new Map<string, string>();\n for (const preset of presets) {\n const normalised = normaliseColour(preset);\n if (normalised && !unique.has(normalised)) {\n unique.set(normalised, preset);\n }\n }\n return [...unique].map(([normalised, preset]) => ({ normalised, preset }));\n }, [presets]);\n const selectedIndex = swatches.findIndex((swatch) => swatch.normalised === hex);\n useEffect(() => {\n disabledRef.current = isDisabled;\n }, [isDisabled]);\n useEffect(() => {\n active.current = true;\n return () => {\n active.current = false;\n };\n }, []);\n\n const pickFromScreen = async () => {\n const EyeDropper = eyeDropperConstructor();\n if (!EyeDropper || isDisabled || isPicking) {\n return;\n }\n setPicking(true);\n setPickerError(\"\");\n try {\n const result = await new EyeDropper().open();\n if (active.current && !disabledRef.current) {\n if (parseColour(result.sRGBHex)) {\n onColourChange({ ...colourState(result.sRGBHex, colour), a: colour.a });\n }\n }\n } catch (error) {\n if (active.current && !(error instanceof DOMException && error.name === \"AbortError\")) {\n setPickerError(\"Unable to pick a colour from the screen. Try again.\");\n }\n } finally {\n if (active.current) {\n setPicking(false);\n }\n }\n };\n\n return (\n <div\n {...rest}\n ref={ref}\n className={[\"ds-colour-panel\", \"ds-field-surface\", className].filter(Boolean).join(\" \")}\n data-disabled={isDisabled || undefined}\n style={\n {\n ...style,\n \"--colour-hue\": `hsl(${colour.h} 100% 50%)`,\n \"--colour-rgb\": rgb,\n \"--colour-rgba\": colourHex(colour),\n } as CSSProperties\n }\n >\n <div className=\"ds-colour-panel__head\">\n <span>Colour</span>\n <span className=\"ds-colour-panel__value\">{hex || \"No colour\"}</span>\n </div>\n {picker === \"custom\" ? (\n <>\n <ColourSquare\n colour={colour}\n isDisabled={isDisabled}\n onChange={onColourChange}\n />\n <div className=\"ds-colour-panel__hue-row\">\n {hasEyeDropper && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"pipette\"\n aria-label=\"Pick from screen\"\n isDisabled={isDisabled}\n // Busy, not pending: a pending Button disables itself and drops focus.\n aria-busy={isPicking || undefined}\n onClick={() => void pickFromScreen()}\n />\n )}\n <Slider\n className=\"ds-colour-panel__hue\"\n value={colour.h}\n min={0}\n max={360}\n step={1}\n hasValueLabel={false}\n aria-label=\"Hue\"\n aria-valuetext={`${Math.round(colour.h)} degrees`}\n isDisabled={isDisabled}\n onValueChange={(h) => onColourChange({ ...colour, h })}\n onKeyDown={(event) => {\n if (\n !event.shiftKey ||\n ![\"ArrowLeft\", \"ArrowRight\", \"ArrowUp\", \"ArrowDown\"].includes(event.key)\n ) {\n return;\n }\n event.preventDefault();\n const delta = event.key === \"ArrowRight\" || event.key === \"ArrowUp\" ? 15 : -15;\n onColourChange({ ...colour, h: Math.max(0, Math.min(360, colour.h + delta)) });\n }}\n />\n </div>\n </>\n ) : (\n <div className=\"ds-colour-panel__native\">\n <input\n ref={inputRef}\n type=\"color\"\n value={rgb}\n tabIndex={-1}\n aria-hidden=\"true\"\n disabled={isDisabled}\n onChange={(event) => {\n if (parseColour(event.target.value)) {\n onColourChange({ ...colourState(event.target.value, colour), a: colour.a });\n }\n }}\n />\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"pipette\"\n isDisabled={isDisabled}\n onClick={() => {\n const input = inputRef.current;\n if (!input) {\n return;\n }\n try {\n if (input.showPicker) {\n input.showPicker();\n } else {\n input.click();\n }\n } catch {\n input.click();\n }\n }}\n >\n Custom colour…\n </Button>\n </div>\n )}\n <div className=\"ds-colour-panel__opacity\">\n <label htmlFor={`${presetsId}-opacity`}>Opacity</label>\n <Slider\n id={`${presetsId}-opacity`}\n className=\"ds-colour-panel__alpha\"\n value={Math.round(colour.a * 100)}\n min={0}\n max={100}\n step={1}\n suffix=\"%\"\n isDisabled={isDisabled}\n onValueChange={(a) => onColourChange({ ...colour, a: a / 100 })}\n />\n </div>\n {showPresets && swatches.length > 0 && (\n <div className=\"ds-colour-panel__presets\">\n <span\n id={presetsId}\n className=\"ds-colour-panel__presets-label\"\n >\n Presets\n </span>\n <div\n className=\"ds-colour-panel__grid\"\n role=\"radiogroup\"\n aria-labelledby={presetsId}\n style={{ \"--colour-preset-columns\": presetColumns } as CSSProperties}\n onKeyDown={(event) => {\n const radios = Array.from(\n event.currentTarget.querySelectorAll<HTMLButtonElement>(\"[role='radio']\"),\n );\n const index = radios.indexOf(event.target as HTMLButtonElement);\n const next = index < 0 ? undefined : presetTarget(event.key, index, radios.length);\n if (next === undefined) {\n return;\n }\n event.preventDefault();\n radios[next]?.focus();\n radios[next]?.click();\n }}\n >\n {swatches.map(({ normalised, preset }, index) => {\n const selected = index === selectedIndex;\n return (\n <Button\n key={normalised}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n role=\"radio\"\n aria-checked={selected}\n aria-label={preset}\n title={preset}\n tabIndex={index === Math.max(0, selectedIndex) ? 0 : -1}\n isDisabled={isDisabled}\n className=\"ds-colour-panel__preset\"\n onClick={() => onColourChange(preset)}\n >\n <span\n className=\"ds-colour-swatch\"\n style={{ \"--colour-swatch\": normalised } as CSSProperties}\n >\n {selected && (\n <Icon\n name=\"check\"\n size={16}\n strokeWidth={3}\n />\n )}\n </span>\n </Button>\n );\n })}\n </div>\n </div>\n )}\n {pickerError && (\n <span\n className=\"ds-colour-panel__error\"\n role=\"status\"\n >\n {pickerError}\n </span>\n )}\n </div>\n );\n },\n);\n","import { useOverlayOpen } from \"../../internal/overlayLayer\";\nimport { forwardRef, useEffect, useId, useRef, useState, type CSSProperties } from \"react\";\nimport { Button } from \"../Button\";\nimport { FieldAffix } from \"../FieldAffix\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { TextField, type TextFieldProps } from \"../TextField\";\nimport { mergeRefs } from \"../../internal/mergeRefs\";\nimport { normaliseColour, parseColour } from \"./colour\";\nimport { tabbableControls } from \"../../internal/dialogFocus\";\nimport { focusAfterField } from \"./focus\";\nimport { ColourPanelContent, type ColourPickerOptions } from \"./panel\";\nimport { useColourDraft, useColourValue, type ColourValueProps } from \"./value\";\nimport \"./style.css\";\n\nexport { ColourPanel } from \"./panel\";\nexport type { ColourPanelProps } from \"./panel\";\n\nexport interface ColourFieldProps\n extends\n Omit<TextFieldProps, \"value\" | \"defaultValue\" | \"onChange\" | \"type\" | \"children\">,\n ColourValueProps,\n ColourPickerOptions {\n isInvalid?: boolean;\n placement?: PopoverPlacement;\n /** Parsing validity; an empty value is valid and native required validation remains separate. */\n onValidityChange?: (isValid: boolean) => void;\n}\n\n/** A typed colour value and a visual picker, bound to the shared Field frame. */\nexport const ColourField = forwardRef<HTMLInputElement, ColourFieldProps>(function ColourField(\n {\n value,\n defaultValue,\n onValueChange,\n onValidityChange,\n presets,\n showPresets,\n picker,\n placement,\n isDisabled = false,\n disabled,\n readOnly,\n isInvalid,\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n onBlur,\n onKeyDown,\n ...rest\n },\n ref,\n) {\n const { current, colour, commit } = useColourValue({ value, defaultValue, onValueChange });\n const [open, setOpen] = useState(false);\n const isOpen = useOverlayOpen(open);\n const rootRef = useRef<HTMLDivElement>(null);\n const inputRef = useRef<HTMLInputElement>(null);\n const openerRef = useRef<HTMLElement | null>(null);\n const panelRef = useRef<HTMLDivElement>(null);\n const panelId = useId();\n const fieldId = id ?? `${panelId}-input`;\n const hex = normaliseColour(current);\n const { text, type, discard } = useColourDraft(current, hex);\n const invalid = Boolean(text.trim() && !parseColour(text));\n const effectiveDisabled = isDisabled || disabled;\n if (isOpen && (effectiveDisabled || readOnly)) {\n setOpen(false);\n }\n const visible = isOpen && !effectiveDisabled && !readOnly;\n\n useEffect(() => {\n onValidityChange?.(!invalid);\n inputRef.current?.setCustomValidity(\n invalid ? \"Enter a colour, such as #0052CC or rebeccapurple.\" : \"\",\n );\n }, [invalid, onValidityChange]);\n\n useEffect(() => {\n if (!visible) {\n return;\n }\n if (panelRef.current) {\n tabbableControls(panelRef.current)[0]?.focus({ preventScroll: true });\n }\n const outside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", outside);\n return () => document.removeEventListener(\"mousedown\", outside);\n }, [visible]);\n\n const toggle = (opener: HTMLElement) => {\n openerRef.current = opener;\n setOpen(!visible);\n };\n const close = () => {\n setOpen(false);\n openerRef.current?.focus({ preventScroll: true });\n };\n const triggerProps = {\n \"aria-label\": visible ? \"Close colour picker\" : \"Open colour picker\",\n \"aria-haspopup\": \"dialog\" as const,\n \"aria-expanded\": visible,\n \"aria-controls\": visible ? panelId : undefined,\n isDisabled: effectiveDisabled || readOnly,\n };\n\n return (\n <div\n className=\"ds-colour-field\"\n ref={rootRef}\n onBlur={(event) => {\n const target = event.relatedTarget as Node | null;\n if (target && !rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n }}\n onKeyDown={(event) => {\n if (visible && event.key === \"Escape\") {\n event.preventDefault();\n event.stopPropagation();\n close();\n }\n if (!visible || event.key !== \"Tab\" || !panelRef.current?.contains(event.target as Node)) {\n return;\n }\n const controls = tabbableControls(panelRef.current);\n const atBoundary = event.shiftKey\n ? event.target === controls[0]\n : event.target === controls.at(-1);\n if (!atBoundary) {\n return;\n }\n event.preventDefault();\n event.stopPropagation();\n setOpen(false);\n if (event.shiftKey) {\n openerRef.current?.focus({ preventScroll: true });\n } else if (rootRef.current) {\n focusAfterField(rootRef.current);\n }\n }}\n >\n <FieldAffix\n isLeadInteractive\n isTrailInteractive\n lead={\n // A pointer shortcut only: the chevron is the one keyboard and screen\n // reader trigger. The swatch never takes focus; the input gets it back.\n <Button\n aria-hidden=\"true\"\n tabIndex={-1}\n isDisabled={triggerProps.isDisabled}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n openerRef.current = inputRef.current;\n if (visible) {\n close();\n } else {\n setOpen(true);\n }\n }}\n >\n <span\n className=\"ds-colour-swatch ds-colour-field__swatch\"\n style={{ \"--colour-swatch\": hex || \"transparent\" } as CSSProperties}\n />\n </Button>\n }\n trail={\n <Button\n {...triggerProps}\n variant=\"simple\"\n size=\"xs\"\n isIconOnly\n iconStart=\"chevron-down\"\n onClick={(event) => toggle(event.currentTarget)}\n />\n }\n >\n <TextField\n {...rest}\n ref={mergeRefs(inputRef, ref)}\n id={fieldId}\n disabled={effectiveDisabled}\n readOnly={readOnly}\n spellCheck={false}\n autoComplete=\"off\"\n value={text}\n aria-invalid={invalid || isInvalid || ariaInvalid || undefined}\n aria-haspopup=\"dialog\"\n aria-controls={visible ? panelId : undefined}\n className={[\"ds-colour-field__input\", className].filter(Boolean).join(\" \")}\n onChange={(event) => {\n const next = event.target.value;\n const valid = !next.trim() || Boolean(parseColour(next));\n type(next, valid);\n if (valid) {\n commit(next);\n }\n }}\n onBlur={(event) => {\n if (!invalid) {\n discard();\n }\n onBlur?.(event);\n }}\n onKeyDown={(event) => {\n onKeyDown?.(event);\n if (event.defaultPrevented) {\n return;\n }\n if (event.key === \"Enter\" && !invalid) {\n event.preventDefault();\n discard();\n }\n if (event.key === \"ArrowDown\" && !effectiveDisabled && !readOnly) {\n event.preventDefault();\n openerRef.current = event.currentTarget;\n setOpen(true);\n }\n }}\n />\n </FieldAffix>\n <Popover\n anchorRef={inputRef}\n anchorId={fieldId}\n isOpen={visible}\n align=\"start\"\n placement={placement}\n panelRef={panelRef}\n id={panelId}\n role=\"dialog\"\n aria-label=\"Choose a colour\"\n // A click on the padding or a label 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 className=\"ds-colour-field__popover\"\n >\n <ColourPanelContent\n colour={colour}\n current={hex}\n presets={presets}\n showPresets={showPresets}\n picker={picker}\n onColourChange={(next) => {\n discard();\n commit(next);\n }}\n />\n </Popover>\n </div>\n );\n});\n"],"mappings":";;;;;;;;;;;;AAGA,SAAgBW,EAAgB,GAAmB;CACjD,IAAMC,IAAWC,EAAK,QAAqB,qBAAqB,KAAK,SAAS,MACxEC,IAAWX,EAAiBS,CAAQ,CAAC,CAAC,QAAQ,MAAY,CAACG,EAAQ,QAAQ,aAAa,CAAC;CAG/F,CADaD,EADAA,EAAS,KAAK,MAAYD,EAAK,SAASE,CAAO,CAAC,CAAC,CAAC,YAAY,EACrD,IAAO,MAAMD,EAAS,GAAA,EACtC,MAAM,EAAE,eAAe,GAAK,CAAC;AACrC;;;ACAA,SAASE,EAAM,GAAe;CAC5B,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,KAAKC,CAAK,CAAC;AACzC;AAEA,SAAgBC,EA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AW;GAGX,UAAU;GACV,WAAU;GAEV,UAAA,kBAAC9C,GAAD;IACU;IACR,SAASpB;IACA;IACI;IACL;IACR,iBAAiB,MAAS;KAExB,AADAwF,EAAQ,GACRnE,EAAOpB,CAAI;IACb;GACD,CAAA;EACM,CAAA,CACN;;AAET,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker-B8tllGYy.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\">\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,IAA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AIvC,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,2 +0,0 @@
|
|
|
1
|
-
const e=require("./Icon-CD3oeiNA.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-seJG-EFn.cjs");;/* empty css */const r=require("./binding-tMjrUzkU.cjs"),i=require("../components/Popover/index.cjs");let a=require("react"),o=require("react/jsx-runtime");function s(e){let t=`${e.getMonth()+1}`.padStart(2,`0`),n=`${e.getDate()}`.padStart(2,`0`);return`${e.getFullYear()}-${t}-${n}`}function c(e){if(!e||!/^\d{4}-\d{2}-\d{2}$/.test(e))return null;let[t,n,r]=e.split(`-`).map(Number);if(!t||!n||!r)return null;let i=new Date(t,n-1,r);return Number.isNaN(i.getTime())||s(i)!==e?null:i}function l(e){return c(e)!==null}function u(e){let t=c(e);return t?t.toLocaleDateString(`en-GB`,{day:`numeric`,month:`long`,year:`numeric`}):``}function d(...e){return e.filter(Boolean).join(` `)}var f=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`];function p(e,t,n){let r=c(e)?e:s(new Date);return t&&r<t?t:n&&r>n?n:r}function m(e){return e.toLocaleDateString(`en-GB`,{month:`long`,year:`numeric`})}function h(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7;return new Date(t.getFullYear(),t.getMonth(),1-n)}function g(e,t,n){return e?`primary`:t?`active`:n?`neutral`:`simple`}var _=(0,a.forwardRef)(function({value:e,endValue:n,onSelect:i,min:l,max:_,className:v,...y},b){let[x,S]=(0,a.useState)(()=>p(e,l,_)),[C,w]=(0,a.useState)(()=>c(x)??new Date),T=(0,a.useRef)(null),E=(0,a.useRef)(!1);(0,a.useEffect)(()=>{if(!c(e))return;let t=p(e,l,_),n=c(t)??new Date;S(t),w(new Date(n.getFullYear(),n.getMonth(),1))},[e,l,_]),(0,a.useEffect)(()=>{E.current&&(E.current=!1,T.current?.querySelector(`[data-focused]`)?.focus())},[x]);let D=Array.from({length:42},(e,t)=>{let n=h(C);return new Date(n.getFullYear(),n.getMonth(),n.getDate()+t)}),O=s(new Date),k=e=>{let t=new Date(C.getFullYear(),C.getMonth()+e,1);w(t),S(s(t))},A=e=>{let t=c(x)??new Date,n=new Date(t.getFullYear(),t.getMonth(),t.getDate()+e);E.current=!0,S(s(n)),w(new Date(n.getFullYear(),n.getMonth(),1))},j=e=>{let t={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7,PageUp:-28,PageDown:28}[e.key];t!==void 0&&(e.preventDefault(),A(t))};return(0,o.jsxs)(`div`,{ref:b,className:d(`ds-calendar`,`ds-field-surface`,v),...r.n(y),children:[(0,o.jsxs)(`div`,{className:`ds-calendar__head`,children:[(0,o.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`chevron-left`,"aria-label":`Previous month`,onClick:()=>k(-1)}),(0,o.jsx)(`span`,{className:`ds-calendar__month`,children:m(C)}),(0,o.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`chevron-right`,"aria-label":`Next month`,onClick:()=>k(1)})]}),(0,o.jsx)(`div`,{className:`ds-calendar__weekdays`,"aria-hidden":`true`,children:f.map(e=>(0,o.jsx)(`span`,{children:e.slice(0,2)},e))}),(0,o.jsx)(`div`,{ref:T,className:`ds-calendar__grid`,role:`grid`,onKeyDown:j,children:Array.from({length:6},(r,a)=>(0,o.jsx)(`div`,{role:`row`,className:`ds-calendar__row`,children:D.slice(a*7,a*7+7).map(r=>{let a=s(r),c=r.getMonth()!==C.getMonth(),d=l&&a<l||_&&a>_,f=!!(e&&n&&a>e&&a<n),p=a===e||a===n;return(0,o.jsx)(t.Button,{variant:g(p,f,a===O),size:`sm`,isIconOnly:!0,role:`gridcell`,"aria-label":u(a),tabIndex:a===x?0:-1,isDisabled:!!d,"aria-selected":p||void 0,"data-outside":c||void 0,"data-today":a===O||void 0,"data-in-range":f||void 0,"data-focused":a===x||void 0,className:`ds-calendar__day`,onClick:()=>{S(a),i?.(a)},children:r.getDate()},a)})},a))})]})});function v({value:s,defaultValue:c=``,onValueChange:l,size:f=`md`,placeholder:p=`Pick a date`,placement:m,min:h,max:g,isDisabled:v=!1,isInvalid:y=!1,isClearable:b=!1,clearLabel:x=`Clear date`,"aria-invalid":S,id:C,className:w,...T}){let[E,D]=(0,a.useState)(c),O=s??E,[k,A]=(0,a.useState)(!1),j=n.o(k),M=(0,a.useRef)(null),N=(0,a.useRef)(null),P=(0,a.useRef)(null),F=(0,a.useId)(),I=C??F;return j&&v&&A(!1),(0,a.useEffect)(()=>{if(!j)return;let e=P.current;(e?.querySelector(`[data-focused]:not(:disabled)`)??e)?.focus();let t=e=>{let t=e.target;!M.current?.contains(t)&&!P.current?.contains(t)&&A(!1)};return document.addEventListener(`mousedown`,t),()=>document.removeEventListener(`mousedown`,t)},[j]),(0,o.jsxs)(`div`,{className:d(`ds-datefield`,w),ref:M,onKeyDown:e=>{j&&e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),A(!1),N.current?.focus())},children:[(0,o.jsxs)(t.Button,{...r.n(T),ref:N,id:I,size:f,"aria-haspopup":`dialog`,"aria-expanded":j,"aria-invalid":y||S||void 0,isDisabled:v,"data-placeholder":O?void 0:``,className:`ds-field-skin ds-datefield__control`,onClick:()=>A(e=>!e),children:[(0,o.jsx)(`span`,{className:`ds-datefield__value`,children:O?u(O):p}),(0,o.jsx)(e.t,{name:`calendar`,size:16,className:`ds-datefield__glyph`})]}),b&&O&&(0,o.jsx)(t.Button,{variant:`simple`,size:f,isIconOnly:!0,iconStart:`x`,"aria-label":x,isDisabled:v,onClick:()=>{s===void 0&&D(``),l?.(``),A(!1),N.current?.focus()}}),(0,o.jsx)(i.Popover,{anchorRef:N,placement:m,anchorId:I,isOpen:j,align:`start`,panelRef:P,className:`ds-datefield__popover`,role:`dialog`,"aria-label":`Choose a date`,tabIndex:-1,children:(0,o.jsx)(_,{value:O,min:h,max:g,onSelect:e=>{s===void 0&&D(e),l?.(e),A(!1),N.current?.focus()}})})]})}function y(e,t,n){return c(e)?t?n===`min`?e>t?e:t:e<t?e:t:e:t}function b({value:e,defaultValue:t={start:``,end:``},onValueChange:n,size:i=`md`,min:s,max:c,isDisabled:l=!1,isClearable:u=!1,startLabel:f=`Start date`,endLabel:p=`End date`,placement:m,className:h,...g}){let[_,b]=(0,a.useState)(t),x=e??_,S=t=>{e===void 0&&b(t),n?.(t)},{attributes:C}=r.r(g);return(0,o.jsxs)(`div`,{...C,className:d(`ds-daterange`,h),children:[(0,o.jsx)(v,{"aria-invalid":g[`aria-invalid`],"aria-label":f,placement:m,size:i,value:x.start,min:s,max:y(x.end,c,`max`),isDisabled:l,isClearable:u,clearLabel:`Clear ${f}`,placeholder:f,onValueChange:e=>S({...x,start:e})}),(0,o.jsx)(`span`,{className:`ds-daterange__dash`,"aria-hidden":`true`,children:`–`}),(0,o.jsx)(v,{"aria-invalid":g[`aria-invalid`],"aria-label":p,placement:m,size:i,value:x.end,min:y(x.start,s,`min`),max:c,isDisabled:l,isClearable:u,clearLabel:`Clear ${p}`,placeholder:p,onValueChange:e=>S({...x,end:e})})]})}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return _}});
|
|
2
|
-
//# sourceMappingURL=DatePicker-OiqjoO-f.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker-OiqjoO-f.cjs","names":["forwardRef","useState","useRef","omitRequired","Button","useOverlayOpen","useId","Icon","Popover","useGroupBinding","require_Icon","require_components_Button_index","require_overlayLayer","require_binding","require_components_Popover_index","react","react_jsx_runtime","toIso","month","date","day","fromIso","value","year","isIsoDate","formatIsoDate","cx","parts","WEEKDAYS","focusableDay","min","max","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","rest","focused","setFocused","setMonth","gridRef","shouldFocus","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","rowIndex","iso","isOutside","isDisabled","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","open","setOpen","isOpen","rootRef","triggerRef","panelRef","generatedId","triggerId","id","panel","onPointerDown","target","isInvalid","placeholder","isClearable","clearLabel","onValueChange","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\">\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":"A,ySAGA,SAAgBiB,EAAM,EAAqB,CACzC,IAAMC,EAAQ,GAAGC,EAAK,SAAS,EAAI,IAAI,SAAS,EAAG,GAAG,EAChDC,EAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,EAAG,GAAG,EAC/C,MAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE,GAC3C,CAEA,SAAgBC,EAAQ,EAAwC,CAC9D,GAAI,CAACC,GAAS,CAAC,sBAAsB,KAAKA,CAAK,EAC7C,OAAO,KAET,GAAM,CAACC,EAAML,EAAOE,GAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,EACtD,GAAI,CAACC,GAAQ,CAACL,GAAS,CAACE,EACtB,OAAO,KAET,IAAMD,EAAO,IAAI,KAAKI,EAAML,EAAQ,EAAGE,CAAG,EAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CAAC,GAAKF,EAAME,CAAI,IAAMG,EAAQ,KAAOH,CACxE,CAGA,SAAgBK,EAAU,EAAe,CACvC,OAAOH,EAAQC,CAAK,IAAM,IAC5B,CAGA,SAAgBG,EAAc,EAAmC,CAC/D,IAAMN,EAAOE,EAAQC,CAAK,EAI1B,OAHKH,EAGEA,EAAK,mBAAmB,QAAS,CAAE,IAAK,UAAW,MAAO,OAAQ,KAAM,SAAU,CAAC,EAFjF,EAGX,CCnBA,SAASO,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAEA,IAAMC,EAAW,CAAC,MAAO,MAAO,MAA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EAAQ,MACV,MACL,IAAKkB,EAAWlB,EAAQ,IAAKxC,EAAK,KAAK,EAC3B,aACC,cACb,WAAY,SAASkE,IACrB,YAAaA,EACb,cAAgB,GAASF,EAAO,CAAE,GAAGxB,EAAS,MAAOxB,CAAK,CAAC,CAC5D,CAAA,GACD,EAAA/B,EAAA,IAAA,CAAC,OAAD,CACE,UAAU,qBACV,cAAY,OACb,SAAA,GAEK,CAAA,GACN,EAAAA,EAAA,IAAA,CAACkD,EAAD,CACE,eAAc4B,EAAQ,gBACtB,aAAYI,EACD,YACL,OACN,MAAO3B,EAAQ,IACf,IAAKkB,EAAWlB,EAAQ,MAAOzC,EAAK,KAAK,EACpC,MACO,aACC,cACb,WAAY,SAASoE,IACrB,YAAaA,EACb,cAAgB,GAASH,EAAO,CAAE,GAAGxB,EAAS,IAAKxB,CAAK,CAAC,CAC1D,CAAA,CACE,C,EAET,C"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const e=require("../components/Button/index.cjs"),t=require("./transitionDuration-B4UnScFc.cjs"),n=require("./mergeRefs-CZ-SArlE.cjs"),r=require("./overlayLayer-seJG-EFn.cjs"),i=require("./dialogLabel-2HRYMHbF.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`,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-BDX9_qHA.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer-BDX9_qHA.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\">{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,m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,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Drawer-DTtgAZO2.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\">{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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K,QAAQ4B;GAEjB;GACA,WAAU;GACV,QAAQ,CAACpC;GACT,cAAYqC,IAAW,KAAA,IAAY;GACnC,uBAAqBlC,KAAY,KAAA;GACjC,gBAAcmC,KAAa,KAAA;GAC3B,OAAO,EAAE,QAAQC,EAAM;GACvB,KAAKd,EAAK;GACV,aAAWe;GACX,gBAAc9C;GACd,kBAAgBsC,IAAkB,KAAK,KAAA;GACvC,cAAY9B,IAAS,SAAS;GAC9B,eAAakC,KAAc,KAAA;GACV;GACjB,aAAaK;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 +0,0 @@
|
|
|
1
|
-
const e=require("../components/Button/index.cjs"),t=require("./use-picker-session-C4FGinLN.cjs"),n=require("./group-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`,"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-BI_7g2Wg.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntryPicker-BI_7g2Wg.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\"\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,YACb,CAAA,GACD,EAAAP,EAAA,IAAA,CAAClB,EAAAA,OAAD,CACE,QAAQ,SACR,KAAK,KACL,WAAA,GACA,UAAU,IACV,aAAY,UAAUsB,EAAK,QAC3B,mBAAkBI,EACN,aACZ,YAAeC,EAASC,EAAS,OAAQ,GAAOR,IAAOE,EAAK,EAAE,CAAC,CAChE,CAAA,CACG,C,GAgCR,OA9BIO,EAAM,SAAW,GACZ,EAAAX,EAAA,IAAA,CAAC,IAAD,CAAG,UAAU,yBAA0B,SAAAY,CAAc,CAAA,EAE1DC,GAEA,EAAAb,EAAA,IAAA,CAACjB,EAAAA,aAAD,CACE,MAAO2B,EACP,UAAWD,EACC,aAEX,SAAAE,EAAM,KAAK,EAAM,KAChB,EAAAX,EAAA,IAAA,CAAChB,EAAAA,iBAAD,CAEE,GAAIoB,EAAK,GACT,MAAOA,EAAK,MACZ,YAAWA,EAAK,KAChB,kBAAmBD,EAASC,EAAMC,CAAK,EACvC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AAhB,EAAA,IAAA,CAACC,EAAD,CACE,MAAOoC,EACG,WACV,SAAUV,EACV,OAAQkB,EACI,aACZ,WAAYC,GAAiBb,IAAS,YAAcI,EAAO,OAAS,EACxD,YACb,CAAA,EACAb,GACD,EAAAxB,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,2BAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAACP,EAAAA,OAAD,CACE,QAAQ,UACR,KAAK,KACL,UAAU,OACE,aACZ,YAAe6B,EAAQ,EAAI,EAE1B,SAAAyB,CACK,CAAA,EACPrC,EAAS,OAAS,IACjB,EAAAV,EAAA,IAAA,CAACP,EAAAA,OAAD,CACE,QAAQ,SACR,KAAK,KACO,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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EntryPicker-KxHZzZsh.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\"\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,i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S,QAAQ,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,2 +0,0 @@
|
|
|
1
|
-
const e=require("./Icon-CD3oeiNA.cjs"),t=require("../components/Button/index.cjs"),n=require("./mergeRefs-CZ-SArlE.cjs"),r=require("./overlayLayer-seJG-EFn.cjs"),i=require("./dialogLabel-2HRYMHbF.cjs"),a=require("./useIsomorphicLayoutEffect-XM4Ot6x5.cjs"),o=require("../components/ButtonGroup/index.cjs"),s=require("../components/Badge/index.cjs");;/* empty css */const c=require("../components/Field/index.cjs"),l=require("../components/Modal/index.cjs"),u=require("../components/TextField/index.cjs"),d=require("./use-picker-session-C4FGinLN.cjs");let f=require("react"),p=require("react-dom"),m=require("react/jsx-runtime"),h=require("@tiptap/react"),g=require("@tiptap/extension-placeholder"),_=require("@tiptap/starter-kit"),v=require("@tiptap/extension-link");function y(e,t){let n=t.querySelector(`.ds-rte__content`);if(!n)return;let r=e.view.coordsAtPos(e.state.selection.head),i=n.getBoundingClientRect();(r.top<i.top||r.bottom>i.bottom)&&(n.scrollTop+=r.top-i.top-i.height/2)}function b({editor:e,disabled:n,isHeld:o=!1,invalid:s,label:c,labelledBy:u,expandedWidth:d,frameRef:h}){let g=i.o(`ds-rte__host`),[_,v]=(0,f.useState)(!1),[b,x]=(0,f.useState)(0),S=(0,f.useRef)(null),C=(0,f.useRef)(null),w=(0,f.useRef)(null),T=(0,f.useRef)(!1),E=(0,f.useRef)(!1),D=(0,f.useId)();_&&n&&!o&&v(!1);let O=(0,f.useCallback)(()=>{T.current=document.activeElement===w.current,v(!1)},[]);a.t(()=>{g&&(i.a(g,_?C.current:S.current),E.current!==_&&(E.current=_,n||!e?r.d(document.activeElement)&&r.f(h.current,{preventScroll:!0}):(y(e,g),!_&&T.current?w.current?.focus():(e.view.focus(),e.commands.scrollIntoView()),T.current=!1)))},[g,_,e,n,h]);let k=_?`Collapse editor`:`Expand editor`;return{expanded:_,toggle:(0,m.jsx)(t.Button,{ref:w,size:`sm`,isIconOnly:!0,iconStart:_?`minimize-2`:`maximize-2`,className:`ds-rte__expand`,"aria-label":k,title:k,"aria-expanded":_,"aria-controls":_?D:void 0,isDisabled:n||!e||!g,onMouseDown:e=>e.preventDefault(),onClick:()=>{_?O():(x(h.current.getBoundingClientRect().height),v(!0))}}),surfaceSlot:e=>(0,m.jsx)(`div`,{ref:S,className:`ds-rte__slot`,children:g?(0,p.createPortal)(e,g):e}),dialog:(0,m.jsx)(l.Modal,{id:D,isOpen:_,onClose:O,title:c,hasHeader:!1,size:d===`full`?`full`:`wide`,className:`ds-rte__modal`,"data-invalid":s||void 0,"aria-labelledby":u,children:(0,m.jsx)(`div`,{ref:C,className:`ds-rte__expanded-slot`})}),frameStyle:_?{minBlockSize:b}:void 0}}function x(e){let t=e=>typeof e==`string`&&e.trim().length>0;return[`left`,`full`,`right`].includes(e.align==null?`full`:e.align)&&(e.type===`entry`?t(e.id)&&t(e.entryId)&&e.assetId==null:e.type===`asset`&&t(e.assetId)&&e.id==null&&e.entryId==null)}function S(e){return{...e,...e.type===`storyblock`&&e.attrs?{attrs:{type:e.attrs.type,...e.attrs.type===`entry`?{id:e.attrs.id,entryId:e.attrs.entryId}:{assetId:e.attrs.assetId},align:e.attrs.align??`full`}}:{},...e.content?{content:e.content.map(S)}:{}}}var C=h.Node.create({name:`storyblock`,group:`block`,atom:!0,draggable:!0,selectable:!0,marks:``,addAttributes(){return Object.fromEntries([`type`,`id`,`entryId`,`assetId`,`align`].map(e=>[e,{default:e===`align`?`full`:null,parseHTML:t=>t.getAttribute(`data-storyblock-${e.toLowerCase()}`),renderHTML:()=>({})}]))},parseHTML(){return[{tag:`div[data-storyblock]`,getAttrs:e=>x(Object.fromEntries([`type`,`id`,`entryId`,`assetId`,`align`].map(t=>[t,e.getAttribute(`data-storyblock-${t.toLowerCase()}`)])))?null:!1}]},renderHTML({node:e,HTMLAttributes:t}){let n=S({type:`storyblock`,attrs:e.attrs}).attrs;return[`div`,(0,h.mergeAttributes)(t,{"data-storyblock":``,...Object.fromEntries(Object.entries(n).map(([e,t])=>[`data-storyblock-${e.toLowerCase()}`,t]))})]}}),w={type:`doc`,content:[{type:`paragraph`}]},T=[_.StarterKit.configure({link:!1,trailingNode:{notAfter:[`paragraph`,`storyblock`]}}),v.Link.configure({openOnClick:!1,autolink:!0})];function E(e=C){return[e,...T]}var D=(0,h.getSchema)(E());function O(e){return e.content?.length?e:{...e,content:w.content}}function k(e){try{if(!e||typeof e!=`object`||!(`type`in e)||e.type!==`doc`)throw Error();let t=e=>{let n=D.nodes[e.type??``];if(!n||Object.keys(e).some(e=>![`type`,`attrs`,`content`,`marks`,`text`].includes(e))||e.text!==void 0&&e.type!==`text`||e.attrs&&Object.keys(e.attrs).some(e=>!Object.hasOwn(n.spec.attrs??{},e))||e.type===`storyblock`&&(!x(e.attrs??{})||e.marks?.length))throw Error();for(let t of e.marks??[]){let e=D.marks[t.type];if(!e||Object.keys(t).some(e=>![`type`,`attrs`].includes(e))||Object.keys(t.attrs??{}).some(t=>!Object.hasOwn(e.spec.attrs??{},t)))throw Error()}e.content?.forEach(t)},n=e;t(n),D.nodeFromJSON(O(n)).check()}catch{return`Unsupported or invalid rich-text document.`}}function A(e){return!!(e&&(e.loadPage||e.items?.length||e.onCreate))}var j=(0,f.createContext)({views:{},disabled:!1,busy:!1,pickCount:0,replace:()=>{},seed:()=>void 0,forgetSeed:()=>{}}),M=[],N=[{align:`left`,icon:`align-left`,label:`Align left`},{align:`full`,icon:`align-justify`,label:`Full width`},{align:`right`,icon:`align-right`,label:`Align right`}],P=[`left`,`full`,`right`,`replace`,`edit`,`remove`],F=new Map([[`ArrowLeft`,-1],[`ArrowRight`,1],[`Home`,-1/0],[`End`,1/0]]);function I(e){let t=F.get(e.key);if(t===void 0||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let n=Array.from(e.currentTarget.querySelectorAll(`button:not(:disabled)`)),r=n.indexOf(e.target);if(r===-1)return;e.preventDefault();let i=r+t;n[Number.isFinite(i)?(i+n.length)%n.length:Math.max(0,Math.min(i,n.length-1))].focus()}function L(e,t){let[n,r]=(0,f.useState)(),[i,a]=(0,f.useState)(!1),o=e||i,s=n&&t.includes(n)?n:t[0];return{control:e=>({isDisabled:!t.includes(e),tabIndex:o&&e===s?0:-1,onFocus:()=>r(e)}),barProps:{onKeyDown:I,onFocus:()=>a(!0),onBlur:e=>{e.currentTarget.contains(e.relatedTarget)||a(!1)}}}}function R(e,t){let{views:n,seed:r,forgetSeed:i}=(0,f.useContext)(j),a=n[e],o=a?.items??M,s=(0,f.useMemo)(()=>[t],[t]),c=(0,f.useCallback)(t=>r(e,t),[r,e]),l=d.o(s,o,a?.resolveItem,a?.refreshKey,c),u=r(e,t);(0,f.useEffect)(()=>{u&&i(e,t,u)},[i,e,t,u]);let{known:p,failures:m}=l,h=!!a?.resolveItem,g=(0,f.useMemo)(()=>d.s({selected:s,items:o,pageItems:M,known:p,failures:m,hasResolver:h,itemLabel:e})[0],[s,o,p,m,h,e]),_=d.a(`Couldn't load ${e}`,l.status,l.error,l.retry),v=o.some(e=>e.id===t);return{view:a,item:g,missing:g.tone===`removed`||!v&&p.has(t)&&!p.get(t),failure:_}}function z({kind:t,isMovable:n,onSelect:r}){return(0,m.jsxs)(`span`,{className:`ds-storyblock__kind`,"data-drag-handle":n?``:void 0,draggable:n||void 0,title:n?`Drag to move`:void 0,onClick:n?r:void 0,children:[n&&(0,m.jsx)(`span`,{className:`ds-storyblock__grip`,"aria-hidden":`true`,children:(0,m.jsx)(e.t,{name:`grip-vertical`,size:16})}),(0,m.jsx)(s.Badge,{className:`ds-storyblock__kind-label`,shape:`tag`,size:`sm`,children:t})]})}function B({kind:e,name:n,align:r,isSelected:i,isLocked:a,canReplace:s,onEdit:c,onSelect:l,onAlign:u,onReplace:d,onRemove:f}){let p={left:!0,full:!0,right:!0,replace:s.isEnabled,edit:!!c,remove:!0},{control:h,barProps:g}=L(i,a?[]:P.filter(e=>p[e]));return(0,m.jsxs)(`div`,{className:`ds-storyblock__bar`,role:`toolbar`,"aria-label":`Block actions for ${n}`,...g,children:[(0,m.jsx)(z,{kind:e,isMovable:!a,onSelect:l}),(0,m.jsx)(o.ButtonGroup,{className:`ds-storyblock__alignment`,"aria-label":`Alignment`,children:N.map(e=>(0,m.jsx)(t.Button,{...h(e.align),size:`sm`,isIconOnly:!0,iconStart:e.icon,"aria-label":`${e.label}: ${n}`,title:e.label,"aria-pressed":r===e.align,variant:r===e.align?`active`:`neutral`,onClick:()=>u(e.align)},e.align))}),(0,m.jsxs)(`div`,{className:`ds-storyblock__actions`,children:[s.isShown&&(0,m.jsx)(t.Button,{...h(`replace`),variant:`simple`,size:`sm`,"aria-label":`Replace ${n}`,onClick:d,children:`Replace`}),c&&(0,m.jsx)(t.Button,{...h(`edit`),variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${n}`,title:`Edit ${e}`,onClick:c}),(0,m.jsx)(t.Button,{...h(`remove`),variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`trash`,"aria-label":`Remove ${n}`,title:`Remove block from this field`,onClick:f})]})]})}function V({kind:e,id:t,item:n,missing:r}){return(0,m.jsx)(`div`,{className:`ds-entry ds-storyblock__body`,children:r?(0,m.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,m.jsx)(`em`,{className:`ds-entry__title`,children:`Unavailable ${e}`}),(0,m.jsxs)(`span`,{className:`ds-entry__meta`,children:[(0,m.jsx)(`span`,{children:`This ${e} was deleted. Replace or remove it.`}),(0,m.jsx)(`code`,{children:t})]})]}):(0,m.jsx)(d.l,{item:n})})}function H({node:e,selected:t,editor:n,getPos:r,updateAttributes:i}){let{disabled:a,busy:o,replace:s}=(0,f.useContext)(j),c=e.attrs.type,l=String(c===`entry`?e.attrs.entryId:e.attrs.assetId),{view:u,item:d,missing:p,failure:g}=R(c,l),_=e.attrs.align??`full`,v=!p&&!d.isUnavailable&&!d.isDisabled&&u?.onEditItem,y=t&&!a,b=()=>{let e=r();e!==void 0&&n.chain().focus().setNodeSelection(e).run()};return(0,m.jsxs)(h.NodeViewWrapper,{className:`ds-storyblock`,"data-align":_,"data-selected":y||void 0,"data-missing":p||void 0,"data-tone":p?`removed`:d.tone,contentEditable:!1,onMouseDown:e=>{let t=e.target instanceof Element?e.target:null;t?.closest(`button`)?e.preventDefault():!a&&!t?.closest(`[data-drag-handle]`)&&(e.preventDefault(),b())},children:[a?(0,m.jsx)(`div`,{className:`ds-storyblock__bar`,children:(0,m.jsx)(z,{kind:c,isMovable:!1})}):(0,m.jsx)(B,{kind:c,name:p?`Unavailable ${c}`:d.title,align:_,isSelected:y,isLocked:!!u?.isDialogHidden,canReplace:{isShown:!!u?.canEmbed,isEnabled:!!u?.canEmbed&&!o},onEdit:v?()=>v(d):void 0,onSelect:b,onAlign:e=>i({align:e}),onReplace:()=>{let e=r();e!==void 0&&s(c,e)},onRemove:()=>{let t=r();t!==void 0&&n.chain().focus().setNodeSelection(t).deleteRange({from:t,to:t+e.nodeSize}).run()}}),(0,m.jsx)(V,{kind:c,id:l,item:d,missing:p}),g&&(0,m.jsx)(`div`,{className:`ds-storyblock__failure`,children:g})]})}var U=`ds-rte-embed-commit`,W=[`entry`,`asset`],G={entry:{itemLabel:`entry`,itemsLabel:`entries`},asset:{itemLabel:`asset`,itemsLabel:`assets`}},K={},q=[];function J(e,t,n){return{type:e,align:t,...e===`entry`?{id:n.modelId,entryId:n.id}:{assetId:n.id}}}function Y(e,t){if(t.tone===`removed`)return{label:t.removedLabel??`Removed`,description:`This ${e} was removed.`};if(!x(J(e,`full`,t)))return{label:`Can't embed`,description:`This ${e} has no ${e===`entry`&&!t.modelId?.trim()?`model API ID`:`ID`}.`}}var X={entry:e=>Y(`entry`,e),asset:e=>Y(`asset`,e)};function Z(e,t){return e?.type.name===`storyblock`&&e.attrs.type===t.kind&&String(t.kind===`entry`?e.attrs.entryId:e.attrs.assetId)===t.replaceId}function Q(e){return e.flatMap(e=>e.mapping.maps)}function ee(e,t){let n=t;for(let t of Q(e)){let e=n,r;if(t.forEach((t,n,i,a)=>{r===void 0&&t<=e&&e<n&&n-t===a-i&&(r=i+(e-t))}),r!==void 0){n=r;continue}let i=t.mapResult(e,1);if(i.deletedAfter)return null;n=i.pos}return n}function te(e,t,n){let r=t,i=n;for(let t of Q(e)){if(r===i){r=i=t.map(i,-1);continue}let e=!1;if(t.forEach((t,n,a,o)=>{let s=i-r===1&&t===r&&n===i&&o-a===1;e||=t<=r&&i<=n&&!s}),r=t.map(r,1),i=t.map(i,-1),e||i<=r)return null}return{from:r,to:i}}function ne(e,t){let n=e.resolve(Math.min(t,e.content.size));return n.depth?n.after(1):n.pos}function $(e,t,n){let r=e!==void 0,i=!!e?.resolveItem,a=!!e?.onEditItem,o=e?.refreshKey,s=e?.items,c=!!e?.isDialogHidden,l=A(e);return(0,f.useMemo)(()=>r?{resolveItem:i?t:void 0,refreshKey:o,items:s,isDialogHidden:c,canEmbed:l,onEditItem:a?n:void 0}:void 0,[r,i,a,o,s,c,l,t,n])}function re({session:e,source:t,disabled:n,label:r,close:i,target:a,pick:o}){let{itemLabel:s,itemsLabel:c}=G[e.kind],l=(0,f.useMemo)(()=>e.replaceId?[e.replaceId]:[],[e]),u=d.t(l,t.items??q,{...t,resolveItem:void 0,mode:`single`},{isOpen:!0,isDisabled:n,itemLabel:s,itemsLabel:c,close:i,restrict:X[e.kind]}),p=e.replaceId?`Replace`:`Embed`;return(0,m.jsx)(d.i,{...u.dialog,isOpen:!0,onClose:i,onToggle:e=>{let t=u.choice(e);t&&o(t,u.revision)},addLabel:`${p} ${s}`,onCreate:t.onCreate?()=>t.onCreate?.(a):void 0,isCreating:t.isCreating,dialogTitle:t.dialogTitle,dialogDescription:`Choose one ${s} to embed in ${r}. ${t.dialogDescription??``}`.trim(),isDialogHidden:t.isDialogHidden})}function ie(e,n=K,i,a){let[s,c]=(0,f.useState)(null),l=(0,f.useRef)(0),u=(0,f.useRef)({session:null,from:0,to:0,alive:!1}),d=(0,f.useRef)(new Map),[p,h]=(0,f.useState)(0),g=(0,f.useCallback)(()=>{u.current.alive=!1,c(null)},[]),_=s?n[s.kind]:void 0,v=s&&A(_)&&(!i||_?.isCreating)?s:null;s&&!v&&c(null);let y=!!(v&&(_?.isDialogHidden||_?.isCreating)),b=r.u({editor:e,sources:n,disabled:i,busy:y});(0,f.useEffect)(()=>{if(!e||!s)return;u.current.alive=!0;let t=({editor:e,transaction:t,appendedTransactions:n})=>{let r=[t,...n];if(!u.current.alive||!r.some(e=>e.docChanged))return;let{from:i,to:a}=u.current;if(s.replaceId===void 0){let e=te(r,i,a);e?Object.assign(u.current,e):g();return}let o=ee(r,i);o===null||!Z(e.state.doc.nodeAt(o),s)?g():Object.assign(u.current,{from:o,to:o+1})};return e.on(`transaction`,t),()=>{e.off(`transaction`,t),u.current.session===s&&(u.current.alive=!1)}},[e,s,g]);let S=e=>{let{editor:t,sources:n,disabled:r}=b.current,i=n[e.kind];return!(!t||t.isDestroyed||u.current.session!==e||!u.current.alive||!A(i)||r&&!i?.isCreating)},C=(e,t,n)=>{let r=b.current.editor;if(!r||!S(e)||t.isDisabled||t.tone===`removed`)return!1;let{doc:i}=r.state,a=e.replaceId!==void 0,o=a?i.nodeAt(u.current.from):null;if(a&&!Z(o,e))return!1;let s=J(e.kind,o?.attrs.align??`full`,t);if(!x(s))return!1;let c=a?u.current.from:ne(i,u.current.to),l=`${e.kind}:${t.id}`;u.current.alive=!1,d.current=new Map([[l,{item:t,revision:n}]]);let f=!1;try{let e=r.chain().focus().setMeta(U,!0);f=a?e.setNodeSelection(c).updateAttributes(`storyblock`,s).run():e.insertContentAt(c,{type:`storyblock`,attrs:s}).setNodeSelection(c).run()}catch{f=!1}finally{g()}return f?h(e=>e+1):d.current.delete(l),f},w=(e,t)=>{let{editor:n,sources:r,disabled:i,busy:a}=b.current;if(!n||i||a||!A(r[e]))return;let o=t===void 0?null:n.state.doc.nodeAt(t);if(t!==void 0&&(o?.type.name!==`storyblock`||o.attrs.type!==e))return;let{$from:s,from:d,to:f}=n.state.selection,p={id:l.current+=1,kind:e,replaceId:o?String(e===`entry`?o.attrs.entryId:o.attrs.assetId):void 0},m=t===void 0?s.depth?{from:s.before(1),to:s.after(1)}:{from:d,to:f}:{from:t,to:t+1};u.current={session:p,...m,alive:!0},c(p)},T=r.u({open:w}),[E]=(0,f.useState)(()=>({replace:(e,t)=>T.current.open(e,t),seed:(e,t)=>d.current.get(`${e}:${t}`),forgetSeed:(e,t,n)=>{d.current.get(`${e}:${t}`)===n&&d.current.delete(`${e}:${t}`)},resolve:{entry:e=>b.current.sources.entry?.resolveItem?.(e)??null,asset:e=>b.current.sources.asset?.resolveItem?.(e)??null},edit:{entry:e=>{b.current.sources.entry?.onEditItem?.(e)},asset:e=>{b.current.sources.asset?.onEditItem?.(e)}}})),D=$(n.entry,E.resolve.entry,E.edit.entry),O=$(n.asset,E.resolve.asset,E.edit.asset),k=(0,f.useMemo)(()=>({views:{entry:D,asset:O},disabled:i,busy:y,pickCount:p,replace:E.replace,seed:E.seed,forgetSeed:E.forgetSeed}),[D,O,i,y,p,E]),j=W.filter(e=>A(n[e]));return{context:k,isCreating:W.some(e=>n[e]?.isCreating),toolbar:j.length>0&&(0,m.jsx)(o.ButtonGroup,{"aria-label":`Embed`,children:j.map(n=>(0,m.jsx)(t.Button,{size:`sm`,isIconOnly:!0,iconStart:n===`entry`?`file-text`:`image`,"aria-label":`Embed ${n}`,title:`Embed ${n}`,"aria-pressed":v?.kind===n,variant:v?.kind===n?`active`:`neutral`,isDisabled:i||y||!e,onClick:()=>w(n)},n))}),dialog:e&&v&&_&&(0,m.jsx)(re,{session:v,source:_,disabled:i,label:a,close:g,target:{available:()=>S(v),commit:e=>C(v,e,b.current.sources[v.kind]?.refreshKey)},pick:(e,t)=>C(v,e,t)},v.id)}}function ae({editor:e,selection:n,onClose:r}){let[i,a]=(0,f.useState)(n.href),[o,s]=(0,f.useState)(),d=(0,f.useId)();(0,f.useEffect)(()=>{let t=()=>{e.state.doc.eq(n.document)||r()};return e.on(`transaction`,t),()=>{e.off(`transaction`,t)}},[e,n,r]);let p=()=>!e.isDestroyed&&e.isEditable&&e.state.doc.eq(n.document),h=()=>{if(!p()){r();return}let t=i.trim();if(!t||!e.can().setLink({href:t})){s(t?`Enter a valid link URL.`:`Enter a link URL.`);return}let a=e.chain().focus().setTextSelection({from:n.from,to:n.to});n.from===n.to&&!n.isEditing?a.setLink({href:t}).insertContent({type:`text`,text:t,marks:[{type:`link`,attrs:{href:t}}]}).run():a.setLink({href:t}).run(),r()};return(0,m.jsx)(l.Modal,{isOpen:!0,title:n.isEditing?`Edit link`:`Add link`,size:`dialog`,onClose:r,footer:(0,m.jsxs)(m.Fragment,{children:[n.isEditing&&(0,m.jsx)(t.Button,{variant:`danger`,onClick:()=>{p()&&e.chain().focus().setTextSelection({from:n.from,to:n.to}).unsetLink().run(),r()},children:`Remove link`}),(0,m.jsx)(t.Button,{onClick:r,children:`Cancel`}),(0,m.jsx)(t.Button,{variant:`primary`,type:`submit`,form:d,children:`Save`})]}),children:(0,m.jsx)(`form`,{id:d,noValidate:!0,onSubmit:e=>{e.preventDefault(),e.stopPropagation(),h()},children:(0,m.jsx)(c.Field,{label:`URL`,isRequired:!0,error:o,children:e=>(0,m.jsx)(u.TextField,{...e,value:i,inputMode:`url`,autoComplete:`url`,placeholder:`https://example.com`,onChange:e=>{a(e.target.value),s(void 0)}})})})})}var oe=[[{id:`bold`,icon:`bold`,label:`Bold`,run:e=>e.chain().focus().toggleBold().run(),active:e=>e.isActive(`bold`)},{id:`italic`,icon:`italic`,label:`Italic`,run:e=>e.chain().focus().toggleItalic().run(),active:e=>e.isActive(`italic`)},{id:`strike`,icon:`strikethrough`,label:`Strikethrough`,run:e=>e.chain().focus().toggleStrike().run(),active:e=>e.isActive(`strike`)},{id:`code`,icon:`code`,label:`Inline code`,run:e=>e.chain().focus().toggleCode().run(),active:e=>e.isActive(`code`)}],[{id:`h2`,icon:`heading-2`,label:`Heading`,run:e=>e.chain().focus().toggleHeading({level:2}).run(),active:e=>e.isActive(`heading`,{level:2})},{id:`h3`,icon:`heading-3`,label:`Subheading`,run:e=>e.chain().focus().toggleHeading({level:3}).run(),active:e=>e.isActive(`heading`,{level:3})},{id:`quote`,icon:`quote`,label:`Quote`,run:e=>e.chain().focus().toggleBlockquote().run(),active:e=>e.isActive(`blockquote`)}],[{id:`ul`,icon:`list`,label:`Bulleted list`,run:e=>e.chain().focus().toggleBulletList().run(),active:e=>e.isActive(`bulletList`)},{id:`ol`,icon:`list-ordered`,label:`Numbered list`,run:e=>e.chain().focus().toggleOrderedList().run(),active:e=>e.isActive(`orderedList`)}],[{id:`undo`,icon:`undo`,label:`Undo`,run:e=>e.chain().focus().undo().run()},{id:`redo`,icon:`redo`,label:`Redo`,run:e=>e.chain().focus().redo().run()}]];function se({editor:e,state:n,disabled:r,label:i,toolbarExtra:a,openLink:s,expandControl:c,embedControl:l}){return(0,m.jsxs)(`div`,{className:`ds-rte__toolbar`,role:`toolbar`,"aria-label":`${i} formatting`,children:[oe.map((i,a)=>(0,m.jsx)(o.ButtonGroup,{"aria-label":`Formatting ${a+1}`,children:i.map(i=>(0,m.jsx)(t.Button,{size:`sm`,isIconOnly:!0,iconStart:i.icon,"aria-label":i.label,title:i.label,"aria-pressed":i.active?n?.active[i.id]:void 0,variant:n?.active[i.id]?`active`:`neutral`,isDisabled:r||!e,onClick:()=>e&&i.run(e)},i.id))},a)),(0,m.jsx)(o.ButtonGroup,{"aria-label":`Link`,children:(0,m.jsx)(t.Button,{size:`sm`,isIconOnly:!0,iconStart:`link`,"aria-label":n?.linkActive?`Edit link`:`Add link`,title:n?.linkActive?`Edit link`:`Add link`,variant:n?.linkActive?`active`:`neutral`,isDisabled:r||!e,onClick:()=>e&&s(e.state,e.isActive(`link`)?e.state.selection.from:void 0)})}),l,a,c]})}var ce=(0,f.forwardRef)(function({scopeRef:e,className:t,expansion:n,isFocused:i,disabled:a,invalid:o,contentError:s,errorId:c,surface:l,children:u},d){return(0,m.jsx)(r.s.Provider,{value:e,children:(0,m.jsxs)(`div`,{ref:d,className:[`ds-rte`,t].filter(Boolean).join(` `),style:n.frameStyle,"data-expanded":n.expanded||void 0,"data-focused":i&&!n.expanded||void 0,"data-disabled":a||void 0,"aria-invalid":o||void 0,children:[s&&(0,m.jsx)(`p`,{id:c,role:`alert`,className:`ds-field__error`,children:s}),n.expanded&&(0,m.jsx)(`p`,{className:`ds-rte__placeholder`,children:`Editing in expanded view. Press Esc to return.`}),n.surfaceSlot((0,m.jsx)(`div`,{className:`ds-rte__surface`,hidden:!!s,"data-invalid":o||void 0,children:l})),n.dialog,u]})})}),le=C.extend({addNodeView(){return(0,h.ReactNodeViewRenderer)(H,{update:({oldNode:e,newNode:t,updateProps:n})=>e.attrs.type===t.attrs.type&&(e!==t&&n(),!0)})}});function ue(e,t){return t.key!==`Escape`||t.isComposing?!1:(e.someProp(`handleKeyDown`,n=>n(e,t))&&t.preventDefault(),!0)}var de=(0,f.forwardRef)(function(e,t){let{placeholder:r=`Write something…`,size:i=`md`,expandedWidth:a=`wide`,isDisabled:o=!1,isInvalid:s=!1,label:c=`Rich text editor`,className:l,toolbarExtra:u,id:d,isRequired:p,required:_,"aria-label":v,"aria-labelledby":y,"aria-describedby":x,"aria-invalid":C}=e,T=(0,f.useRef)(null),D=(0,f.useMemo)(()=>n.t(T,t),[t]),[A,M]=(0,f.useState)(!1),[N,P]=(0,f.useState)(null),F=(0,f.useCallback)(()=>P(null),[]),[I]=(0,f.useState)(()=>e.defaultValue??(e.format===`json`?w:``)),L=e.value===void 0?I:e.value,R=(0,f.useMemo)(()=>e.format===`json`?k(L):void 0,[e.format,L]),z=(0,f.useId)(),B=s||!!R||C,V=o||!!R;V&&N&&P(null);let H=(0,f.useCallback)((e,t)=>{if(V)return;let n=t===void 0?void 0:(0,h.getMarkRange)(e.doc.resolve(t),e.schema.marks.link),r=n&&e.doc.nodeAt(n.from)?.marks.find(t=>t.type===e.schema.marks.link);P({from:n?.from??e.selection.from,to:n?.to??e.selection.to,href:r?.attrs.href??``,isEditing:!!r,document:e.doc})},[V]),U=(0,f.useMemo)(()=>({role:`textbox`,...y?{}:{"aria-label":v??c},"aria-multiline":`true`,...d?{id:d}:{},...y?{"aria-labelledby":y}:{},...x?{"aria-describedby":x}:{},...B?{"aria-invalid":String(B)}:{},...p||_?{"aria-required":`true`}:{}}),[c,v,d,y,x,B,p,_]),W=(0,f.useMemo)(()=>({attributes:U,handleDOMEvents:{keydown:ue,click:(e,t)=>{let n=t.target instanceof Element?t.target.closest(`a`):null;return!n||!e.dom.contains(n)?!1:(t.preventDefault(),e.editable&&H(e.state,e.posAtDOM(n,0)),!0)}}}),[U,H]),G=(0,f.useMemo)(()=>[...E(le),g.Placeholder.configure({placeholder:r})],[r]),K=(0,f.useMemo)(()=>R?w:typeof L==`string`?L:O(L),[L,R]),q=(0,h.useEditor)({immediatelyRender:!1,editable:!V,content:K,extensions:G,editorProps:W,onFocus:()=>M(!0),onBlur:()=>M(!1),onUpdate:({editor:t,transaction:n})=>{(!V||n.getMeta(`ds-rte-embed-commit`))&&(e.format===`json`?e.onChange?.(S(t.getJSON())):e.onChange?.(t.getHTML()))}});(0,f.useEffect)(()=>{q&&(q.setEditable(!V,!1),q.setOptions({editorProps:W}))},[q,V,W]),(0,f.useEffect)(()=>{if(!q||e.value===void 0||R)return;let t=typeof e.value==`string`?(0,h.createDocument)(e.value,q.schema):q.schema.nodeFromJSON(O(e.value));t.eq(q.state.doc)||q.commands.setContent(t,{emitUpdate:!1})},[q,e.value,R]);let J=(0,h.useEditorState)({editor:q,selector:({editor:e})=>e?{active:Object.fromEntries(oe.flat().map(t=>[t.id,t.active?.(e)??!1])),linkActive:e.isActive(`link`)}:null}),Y=ie(q,R?void 0:e.embeds,V,c),X=b({editor:q,disabled:V,isHeld:Y.isCreating,invalid:!!B,label:v??c,labelledBy:y,expandedWidth:a,frameRef:T});return(0,m.jsx)(j.Provider,{value:Y.context,children:(0,m.jsxs)(ce,{ref:D,scopeRef:T,className:l,expansion:X,isFocused:A,disabled:V,invalid:!!B,contentError:R,errorId:z,surface:(0,m.jsxs)(m.Fragment,{children:[(0,m.jsx)(se,{editor:q,state:J,disabled:V,label:c,toolbarExtra:u,openLink:H,expandControl:X.toggle,embedControl:Y.toolbar}),(0,m.jsx)(`div`,{className:`ds-rte__content`,"data-size":i,children:(0,m.jsx)(h.EditorContent,{editor:q})})]}),children:[Y.dialog,q&&N&&!V&&(0,m.jsx)(ae,{editor:q,selection:N,onClose:F})]})})});Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return de}});
|
|
2
|
-
//# sourceMappingURL=RichTextEditor-BXyhSeJd.cjs.map
|