@open-mercato/ui 0.10.1-develop.8129.1.149839452c → 0.10.1-develop.8143.1.bf633ea932
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/dist/backend/CrudForm.js +65 -35
- package/dist/backend/CrudForm.js.map +2 -2
- package/dist/backend/detail/NotesSection.js +3 -2
- package/dist/backend/detail/NotesSection.js.map +2 -2
- package/dist/backend/inputs/ComboboxInput.js +1 -1
- package/dist/backend/inputs/ComboboxInput.js.map +2 -2
- package/dist/backend/inputs/LookupSelect.js +117 -35
- package/dist/backend/inputs/LookupSelect.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/CrudForm.tsx +168 -100
- package/src/backend/__tests__/CrudForm.accessibleLabels.test.tsx +108 -0
- package/src/backend/__tests__/CrudForm.doubleSubmit.test.tsx +85 -1
- package/src/backend/__tests__/CrudForm.injectionLifecycle.test.tsx +5 -2
- package/src/backend/__tests__/NotesSection.test.tsx +48 -1
- package/src/backend/detail/NotesSection.tsx +3 -2
- package/src/backend/inputs/ComboboxInput.tsx +2 -2
- package/src/backend/inputs/LookupSelect.tsx +166 -53
- package/src/backend/inputs/__tests__/ComboboxInput.test.tsx +22 -0
- package/src/backend/inputs/__tests__/LookupSelect.test.tsx +209 -23
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/inputs/ComboboxInput.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { X } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Button } from '../../primitives/button'\nimport { IconButton } from '../../primitives/icon-button'\nimport { Popover, PopoverAnchor, PopoverContent } from '../../primitives/popover'\n\nexport type ComboboxOption = {\n value: string\n label: string\n description?: string | null\n}\n\nexport type ComboboxInputProps = {\n value: string\n onChange: (next: string) => void\n placeholder?: string\n suggestions?: Array<string | ComboboxOption>\n // Options to hydrate the option map up front (typically the linked entity's\n // display fields, already present in a record-detail payload). Merged with\n // `suggestions` so a pre-selected value renders its label without interaction.\n seedOptions?: ComboboxOption[]\n loadSuggestions?: (query?: string) => Promise<Array<string | ComboboxOption>>\n // Eagerly resolve a pre-selected `value` to a human label when it is not\n // covered by `suggestions`/`seedOptions`/`loadSuggestions` results. Runs once\n // per value, before any user interaction. May be sync or async.\n resolveLabel?: (value: string) => string | Promise<string>\n resolveDescription?: (value: string) => string | null | undefined\n autoFocus?: boolean\n disabled?: boolean\n allowCustomValues?: boolean\n clearable?: boolean\n clearLabel?: string\n id?: string\n 'aria-describedby'?: string\n 'aria-invalid'?: boolean\n 'aria-required'?: boolean\n}\n\nfunction normalizeOptions(input?: Array<string | ComboboxOption>): ComboboxOption[] {\n if (!Array.isArray(input)) return []\n return input\n .map((option) => {\n if (typeof option === 'string') {\n const trimmed = option.trim()\n if (!trimmed) return null\n return { value: trimmed, label: trimmed }\n }\n const value = typeof option.value === 'string' ? option.value.trim() : ''\n if (!value) return null\n return {\n value,\n label: option.label?.trim() || value,\n description: option.description ?? null,\n }\n })\n .filter((option): option is ComboboxOption => !!option)\n}\n\nfunction areOptionsEqual(a: ComboboxOption[], b: ComboboxOption[]): boolean {\n if (a.length !== b.length) return false\n return a.every((option, index) => {\n const next = b[index]\n return option.value === next.value\n && option.label === next.label\n && (option.description ?? null) === (next.description ?? null)\n })\n}\n\nexport function ComboboxInput({\n value,\n onChange,\n placeholder,\n suggestions,\n seedOptions,\n loadSuggestions,\n resolveLabel,\n resolveDescription,\n autoFocus,\n disabled = false,\n allowCustomValues = true,\n clearable = false,\n clearLabel,\n id,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n}: ComboboxInputProps) {\n const t = useT()\n const resolvedPlaceholder = placeholder ?? t('ui.inputs.comboboxInput.placeholder', 'Type to search...')\n const loadingLabel = t('ui.inputs.comboboxInput.loading', 'Loading suggestions\u2026')\n const noMatchesLabel = t('ui.inputs.comboboxInput.noMatches', 'No matches found')\n const resolvedClearLabel = clearLabel ?? t('ui.inputs.comboboxInput.clear', 'Clear value')\n const blurCloseDelayMs = 250\n const blurCloseMaxDelayMs = 1000\n const [input, setInput] = React.useState('')\n const [asyncOptions, setAsyncOptions] = React.useState<ComboboxOption[]>([])\n const [resolvedOptions, setResolvedOptions] = React.useState<ComboboxOption[]>([])\n const [loading, setLoading] = React.useState(false)\n const [touched, setTouched] = React.useState(false)\n const [showSuggestions, setShowSuggestions] = React.useState(false)\n const [selectedIndex, setSelectedIndex] = React.useState(-1)\n const listboxId = React.useId()\n const inputRef = React.useRef<HTMLInputElement>(null)\n const loadingRef = React.useRef(false)\n const blurCloseTimerRef = React.useRef<number | null>(null)\n const blurClosePendingRef = React.useRef(false)\n const suppressOpenOnFocusRef = React.useRef(Boolean(autoFocus && !disabled))\n const eagerFallbackLoadedValueRef = React.useRef<string | null>(null)\n // Tracks whether the user actually typed into the field during the current focus\n // session. `touched` cannot serve this purpose because it is set by `onFocus`,\n // which `autoFocus` triggers before the user does anything at all.\n const userTypedRef = React.useRef(false)\n\n const staticOptions = React.useMemo(\n () => normalizeOptions([...(seedOptions ?? []), ...(suggestions ?? [])]),\n [seedOptions, suggestions]\n )\n\n // Single pass over all option sources to build both coverage sets at once.\n // knownLabelValues: values with a genuine label (not a self-mapping placeholder) \u2014\n // used to decide whether eager resolution still needs to run.\n // coveredOptionValues: all values present in any source (even self-mapped).\n const { knownLabelValues, coveredOptionValues } = React.useMemo(() => {\n const known = new Set<string>()\n const covered = new Set<string>()\n for (const opt of [...staticOptions, ...asyncOptions, ...resolvedOptions]) {\n covered.add(opt.value)\n if (opt.label && opt.label !== opt.value) known.add(opt.value)\n }\n return { knownLabelValues: known, coveredOptionValues: covered }\n }, [staticOptions, asyncOptions, resolvedOptions])\n\n const optionMap = React.useMemo(() => {\n const map = new Map<string, ComboboxOption>()\n const register = (option: ComboboxOption) => {\n const existing = map.get(option.value)\n // Prefer an entry that carries a real label over a self-mapping placeholder.\n if (!existing || (existing.label === existing.value && option.label !== option.value)) {\n map.set(option.value, option)\n }\n }\n staticOptions.forEach(register)\n asyncOptions.forEach(register)\n resolvedOptions.forEach(register)\n if (value) {\n const existing = map.get(value)\n if (!existing) {\n map.set(value, {\n value,\n label: value,\n description: resolveDescription?.(value) ?? null,\n })\n }\n }\n return map\n }, [asyncOptions, resolvedOptions, resolveDescription, staticOptions, value])\n\n const availableOptions = React.useMemo(() => {\n return Array.from(optionMap.values())\n }, [optionMap])\n\n React.useEffect(() => {\n loadingRef.current = loading\n }, [loading])\n\n const clearBlurCloseTimer = React.useCallback(() => {\n if (blurCloseTimerRef.current === null) return\n window.clearTimeout(blurCloseTimerRef.current)\n blurCloseTimerRef.current = null\n }, [])\n\n const resetBlurCloseState = React.useCallback(() => {\n blurClosePendingRef.current = false\n clearBlurCloseTimer()\n }, [clearBlurCloseTimer])\n\n React.useEffect(() => resetBlurCloseState, [resetBlurCloseState])\n\n const filteredSuggestions = React.useMemo(() => {\n const query = input.toLowerCase().trim()\n if (!query) return availableOptions\n return availableOptions.filter((option) => {\n const labelMatch = option.label.toLowerCase().includes(query)\n const descMatch = option.description?.toLowerCase().includes(query)\n return labelMatch || Boolean(descMatch)\n })\n }, [availableOptions, input])\n\n React.useEffect(() => {\n if (!loadSuggestions || !touched || disabled) return\n const query = input.trim()\n let cancelled = false\n const handle = window.setTimeout(() => {\n setLoading(true)\n Promise.resolve()\n .then(() => loadSuggestions(query))\n .then((items) => {\n if (!cancelled) {\n const normalized = normalizeOptions(items)\n setAsyncOptions((prev) => areOptionsEqual(prev, normalized) ? prev : normalized)\n }\n })\n .catch(() => {})\n .finally(() => {\n if (!cancelled) setLoading(false)\n })\n }, 200)\n return () => {\n cancelled = true\n window.clearTimeout(handle)\n }\n }, [disabled, input, loadSuggestions, touched])\n\n // Eagerly resolve a pre-selected value to its label without requiring the user\n // to focus the field. Runs once per value when it is not already covered.\n const eagerResolveLabel = typeof resolveLabel === 'function' ? resolveLabel : undefined\n React.useEffect(() => {\n if (!value) return\n let cancelled = false\n const apply = (label?: string | null, description?: string | null) => {\n const clean = typeof label === 'string' ? label.trim() : ''\n if (cancelled || !clean || clean === value) return\n setResolvedOptions((prev) => {\n if (prev.some((option) => option.value === value && option.label === clean)) return prev\n return [...prev.filter((option) => option.value !== value), { value, label: clean, description: description ?? null }]\n })\n }\n if (eagerResolveLabel) {\n if (knownLabelValues.has(value)) return\n Promise.resolve()\n .then(() => eagerResolveLabel(value))\n .then((label) => apply(label, resolveDescription?.(value)))\n .catch(() => {})\n return () => { cancelled = true }\n }\n if (coveredOptionValues.has(value)) return\n if (eagerFallbackLoadedValueRef.current === value) return\n eagerFallbackLoadedValueRef.current = value\n // Fallback: pull the first page of async suggestions so a remount that lost\n // its option cache can still recover the label without user interaction.\n // Note: if the loader is paginated and the value falls outside the first page,\n // the fallback silently fails and the raw value remains visible.\n if (loadSuggestions) {\n setLoading(true)\n Promise.resolve()\n .then(() => loadSuggestions())\n .then((items) => {\n if (cancelled) return\n const normalized = normalizeOptions(items)\n setAsyncOptions((prev) => areOptionsEqual(prev, normalized) ? prev : normalized)\n })\n .catch(() => {})\n .finally(() => { if (!cancelled) setLoading(false) })\n }\n return () => { cancelled = true }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- resolveDescription intentionally excluded:\n // including it would re-run the effect on every render when the prop is an inline function\n }, [value, knownLabelValues, coveredOptionValues, eagerResolveLabel, loadSuggestions])\n\n // Sync input with a value that changed outside the component. A focused field is\n // synced too, because `autoFocus` can focus the control before an async default value\n // arrives and a focus-only guard then leaves the control rendering an empty label for\n // a value the form has already committed. Two conditions still block the sync:\n // - the user is typing, so their query is never clobbered mid-keystroke;\n // - `optionMap` only holds the self-mapping placeholder it synthesises for an\n // uncovered value, which would paint the raw record id over a label the user just\n // picked (`asyncOptions` is replaced on every load, so any follow-up load that\n // misses the picked entry \u2014 a failed request, a debounce race, a composite label\n // the route's `?search=` cannot match \u2014 drops it back to the placeholder).\n React.useEffect(() => {\n const option = optionMap.get(value)\n const hasRealLabel = Boolean(option && option.label !== option.value)\n if (document.activeElement === inputRef.current && (userTypedRef.current || !hasRealLabel)) return\n setInput(option?.label ?? value ?? '')\n }, [value, optionMap])\n\n const selectValue = React.useCallback(\n (nextValue: string) => {\n if (disabled) return\n resetBlurCloseState()\n const trimmed = nextValue.trim()\n onChange(trimmed)\n const option = optionMap.get(trimmed)\n setInput(option?.label ?? trimmed)\n setShowSuggestions(false)\n setSelectedIndex(-1)\n userTypedRef.current = false\n },\n [disabled, onChange, optionMap, resetBlurCloseState]\n )\n\n const findOptionForInput = React.useCallback(\n (raw: string): ComboboxOption | null => {\n const query = raw.trim().toLowerCase()\n if (!query) return null\n for (const option of optionMap.values()) {\n if (option.value === raw.trim()) return option\n if (option.label.toLowerCase() === query) return option\n }\n return null\n },\n [optionMap]\n )\n\n const confirmSelection = React.useCallback(\n (raw: string) => {\n if (disabled) return\n if (clearable && raw.trim() === '') {\n selectValue('')\n return\n }\n const option = findOptionForInput(raw)\n if (option) {\n selectValue(option.value)\n return\n }\n if (!allowCustomValues) {\n // Revert to the current value's label \u2014 but only if we actually know it.\n // Baking the raw value back in while eager resolution is still pending\n // would freeze a placeholder (e.g. a UUID) into the visible input.\n setShowSuggestions(false)\n const currentOption = optionMap.get(value)\n if (currentOption && currentOption.label !== currentOption.value) {\n setInput(currentOption.label)\n } else if (!value) {\n setInput('')\n }\n return\n }\n selectValue(raw)\n },\n [allowCustomValues, clearable, disabled, findOptionForInput, optionMap, selectValue, value]\n )\n\n const handleClear = React.useCallback(() => {\n if (disabled) return\n selectValue('')\n inputRef.current?.focus()\n }, [disabled, selectValue])\n\n const closeAfterBlur = React.useCallback(() => {\n blurCloseTimerRef.current = null\n if (disabled) return\n blurClosePendingRef.current = false\n confirmSelection(input)\n setShowSuggestions(false)\n setSelectedIndex(-1)\n }, [confirmSelection, disabled, input])\n\n const attemptBlurClose = React.useCallback(() => {\n blurCloseTimerRef.current = null\n if (disabled) return\n if (loadingRef.current) {\n blurCloseTimerRef.current = window.setTimeout(closeAfterBlur, blurCloseMaxDelayMs)\n return\n }\n closeAfterBlur()\n }, [blurCloseMaxDelayMs, closeAfterBlur, disabled])\n\n React.useEffect(() => {\n if (!blurClosePendingRef.current) return\n if (loading) return\n clearBlurCloseTimer()\n closeAfterBlur()\n }, [clearBlurCloseTimer, closeAfterBlur, loading])\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n if (!showSuggestions) {\n setShowSuggestions(true)\n setSelectedIndex(0)\n } else {\n setSelectedIndex((prev) => Math.min(prev + 1, filteredSuggestions.length - 1))\n }\n } else if (event.key === 'ArrowUp') {\n event.preventDefault()\n setSelectedIndex((prev) => Math.max(prev - 1, -1))\n } else if (event.key === 'Enter') {\n event.preventDefault()\n if (selectedIndex >= 0 && filteredSuggestions[selectedIndex]) {\n selectValue(filteredSuggestions[selectedIndex].value)\n } else {\n confirmSelection(input)\n }\n } else if (event.key === 'Escape') {\n if (!showSuggestions) return\n event.preventDefault()\n event.stopPropagation()\n setShowSuggestions(false)\n setSelectedIndex(-1)\n }\n },\n [confirmSelection, disabled, filteredSuggestions, input, selectValue, selectedIndex, showSuggestions]\n )\n\n const optionDomId = React.useCallback(\n (index: number) => `${listboxId}-option-${index}`,\n [listboxId],\n )\n\n React.useEffect(() => {\n if (selectedIndex < 0 || !showSuggestions) return\n const activeElement = typeof document !== 'undefined'\n ? document.getElementById(optionDomId(selectedIndex))\n : null\n if (typeof activeElement?.scrollIntoView === 'function') {\n activeElement.scrollIntoView({ block: 'nearest' })\n }\n }, [optionDomId, selectedIndex, showSuggestions])\n\n const showClearButton = clearable && !disabled && (value !== '' || input !== '')\n const listboxVisible = showSuggestions\n && !disabled\n && (loading || filteredSuggestions.length > 0 || (touched && input.trim().length > 0))\n\n return (\n // The suggestion list goes through the DS Popover so it is portaled out of any\n // scrolling ancestor. Rendered in place it was clipped by a Dialog's\n // `overflow-y-auto`, where z-index cannot help. `open` stays fully controlled\n // (no `onOpenChange`) so the blur timer, Escape and selection keep owning\n // dismissal exactly as before.\n <Popover open={listboxVisible}>\n <PopoverAnchor asChild>\n <div className=\"relative w-full\">\n {/* Use raw <input> here instead of the DS Input primitive: ComboboxInput's\n focus / suggestions-popup interplay relies on the trigger being a plain\n input element. The DS wrapper introduces a <div> that desyncs autocomplete\n on this specific surface. Keeps the rest of the form on Input primitive. */}\n <input\n ref={inputRef}\n id={id}\n type=\"text\"\n className={[\n 'w-full h-9 rounded-md border border-input bg-background px-3 text-sm shadow-xs transition-colors outline-none placeholder:text-muted-foreground focus-visible:shadow-focus focus-visible:border-foreground disabled:bg-bg-disabled disabled:border-border-disabled disabled:text-muted-foreground disabled:cursor-not-allowed',\n showClearButton ? 'pr-9' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n value={input}\n placeholder={resolvedPlaceholder}\n autoFocus={autoFocus}\n data-crud-focus-target=\"\"\n disabled={disabled}\n role=\"combobox\"\n aria-expanded={listboxVisible}\n aria-controls={listboxVisible && !loading && filteredSuggestions.length > 0 ? listboxId : undefined}\n // The listbox is portaled out of the input's subtree, so `aria-owns` is what\n // makes it a logical descendant and keeps `aria-activedescendant` below valid.\n aria-owns={listboxVisible && !loading && filteredSuggestions.length > 0 ? listboxId : undefined}\n aria-autocomplete=\"list\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n aria-required={ariaRequired}\n aria-activedescendant={listboxVisible && selectedIndex >= 0 ? optionDomId(selectedIndex) : undefined}\n onFocus={() => {\n setTouched(true)\n if (suppressOpenOnFocusRef.current) {\n suppressOpenOnFocusRef.current = false\n return\n }\n resetBlurCloseState()\n if (loadSuggestions && availableOptions.length === 0) {\n setLoading(true)\n }\n setShowSuggestions(true)\n }}\n onChange={(event) => {\n setTouched(true)\n userTypedRef.current = true\n setInput(event.target.value)\n setShowSuggestions(true)\n setSelectedIndex(-1)\n }}\n onKeyDown={handleKeyDown}\n onBlur={() => {\n // Delay closing so clicks on the popup can resolve first. If async\n // suggestions are still loading, keep the dropdown open instead of\n // closing before the first payload arrives.\n userTypedRef.current = false\n blurClosePendingRef.current = true\n clearBlurCloseTimer()\n if (loadingRef.current) {\n blurCloseTimerRef.current = window.setTimeout(closeAfterBlur, blurCloseMaxDelayMs)\n return\n }\n blurCloseTimerRef.current = window.setTimeout(attemptBlurClose, blurCloseDelayMs)\n }}\n />\n\n {showClearButton ? (\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n aria-label={resolvedClearLabel}\n className=\"absolute right-1 top-1/2 -translate-y-1/2\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n >\n <X className=\"size-3\" />\n </IconButton>\n ) : null}\n </div>\n </PopoverAnchor>\n\n {/* Unmount the content outright rather than leaning on Radix's exit animation:\n a closing-but-still-mounted layer keeps swallowing Escape, which would\n strand the popup's host (see AdvancedFilterPanel for that failure mode). */}\n {listboxVisible ? (\n <PopoverContent\n // Radix hardcodes `role=\"dialog\"` on popover content. This popup is a\n // positioning shell around the listbox below, and a second dialog node\n // would both misdescribe it and break `getByRole('dialog')` for anything\n // that queries while suggestions happen to be open.\n role=\"presentation\"\n // Focus must stay in the input: the blur-close timer and\n // aria-activedescendant model depend on it, and Radix would otherwise\n // move focus into the list on open and back to the trigger on close.\n onOpenAutoFocus={(event) => event.preventDefault()}\n onCloseAutoFocus={(event) => event.preventDefault()}\n // A modal Dialog locks scrolling through `react-remove-scroll`, which\n // cancels document-level `wheel` and `touchmove` outside its own content\n // node. The portaled list is not part of that exemption, so without these\n // a long list inside a dialog cannot be scrolled by wheel or by touch.\n // `overscroll-contain` stops the scroll chaining to the page at the ends.\n onWheel={(event) => event.stopPropagation()}\n onTouchMove={(event) => event.stopPropagation()}\n className=\"w-[var(--radix-popover-trigger-width)] min-w-0 max-h-48 sm:max-h-60 overflow-auto overscroll-contain border-input p-2\"\n >\n {loading && touched ? (\n <div className=\"px-2 py-1.5 text-xs text-muted-foreground\" role=\"status\">{loadingLabel}</div>\n ) : touched && !filteredSuggestions.length ? (\n <div className=\"px-2 py-1.5 text-xs text-muted-foreground\" role=\"status\">{noMatchesLabel}</div>\n ) : (\n <div id={listboxId} role=\"listbox\" className=\"flex flex-col gap-1\">\n {filteredSuggestions.map((option, index) => (\n <Button\n key={option.value}\n id={optionDomId(index)}\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n role=\"option\"\n aria-selected={index === selectedIndex}\n className={[\n 'w-full h-auto justify-start font-normal text-left flex flex-col items-start rounded-lg p-2',\n index === selectedIndex ? 'bg-muted' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n resetBlurCloseState()\n selectValue(option.value)\n }}\n onMouseEnter={() => setSelectedIndex(index)}\n >\n <span className=\"font-medium text-foreground\">{option.label}</span>\n {option.description ? (\n <span className=\"text-xs text-muted-foreground\">{option.description}</span>\n ) : null}\n </Button>\n ))}\n </div>\n )}\n </PopoverContent>\n ) : null}\n </Popover>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AA8aQ,SAKE,KALF;AA5aR,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,SAAS,eAAe,sBAAsB;AAkCvD,SAAS,iBAAiB,OAA0D;AAClF,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,SAAO,MACJ,IAAI,CAAC,WAAW;AACf,QAAI,OAAO,WAAW,UAAU;AAC9B,YAAM,UAAU,OAAO,KAAK;AAC5B,UAAI,CAAC,QAAS,QAAO;AACrB,aAAO,EAAE,OAAO,SAAS,OAAO,QAAQ;AAAA,IAC1C;AACA,UAAM,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,MAAM,KAAK,IAAI;AACvE,QAAI,CA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C,UAAU,MAAM,eAAe;AAAA,UACjD,kBAAkB,CAAC,UAAU,MAAM,eAAe;AAAA,UAMlD,SAAS,CAAC,UAAU,MAAM,gBAAgB;AAAA,UAC1C,aAAa,CAAC,UAAU,MAAM,gBAAgB;AAAA,UAC9C,WAAU;AAAA,UAET,qBAAW,UACV,oBAAC,SAAI,WAAU,6CAA4C,MAAK,UAAU,wBAAa,IACrF,WAAW,CAAC,oBAAoB,SAClC,oBAAC,SAAI,WAAU,6CAA4C,MAAK,UAAU,0BAAe,IAEzF,oBAAC,SAAI,IAAI,WAAW,MAAK,WAAU,WAAU,uBAC1C,8BAAoB,IAAI,CAAC,QAAQ,UAChC;AAAA,YAAC;AAAA;AAAA,cAEC,IAAI,YAAY,KAAK;AAAA,cACrB,MAAK;AAAA,cACL,SAAQ;AAAA,cACR,MAAK;AAAA,cACL,MAAK;AAAA,cACL,iBAAe,UAAU;AAAA,cACzB,WAAW;AAAA,gBACT;AAAA,gBACA,UAAU,gBAAgB,aAAa;AAAA,cACzC,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,cACX,aAAa,CAAC,UAAU,MAAM,eAAe;AAAA,cAC7C,SAAS,MAAM;AACb,oCAAoB;AACpB,4BAAY,OAAO,KAAK;AAAA,cAC1B;AAAA,cACA,cAAc,MAAM,iBAAiB,KAAK;AAAA,cAE1C;AAAA,oCAAC,UAAK,WAAU,+BAA+B,iBAAO,OAAM;AAAA,gBAC3D,OAAO,cACN,oBAAC,UAAK,WAAU,iCAAiC,iBAAO,aAAY,IAClE;AAAA;AAAA;AAAA,YAvBC,OAAO;AAAA,UAwBd,CACD,GACH;AAAA;AAAA,MAEJ,IACE;AAAA,OACN;AAAA;AAEJ;",
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { X } from 'lucide-react'\nimport { useT } from '@open-mercato/shared/lib/i18n/context'\nimport { Button } from '../../primitives/button'\nimport { IconButton } from '../../primitives/icon-button'\nimport { Popover, PopoverAnchor, PopoverContent } from '../../primitives/popover'\n\nexport type ComboboxOption = {\n value: string\n label: string\n description?: string | null\n}\n\nexport type ComboboxInputProps = {\n id?: string\n value: string\n onChange: (next: string) => void\n placeholder?: string\n suggestions?: Array<string | ComboboxOption>\n // Options to hydrate the option map up front (typically the linked entity's\n // display fields, already present in a record-detail payload). Merged with\n // `suggestions` so a pre-selected value renders its label without interaction.\n seedOptions?: ComboboxOption[]\n loadSuggestions?: (query?: string) => Promise<Array<string | ComboboxOption>>\n // Eagerly resolve a pre-selected `value` to a human label when it is not\n // covered by `suggestions`/`seedOptions`/`loadSuggestions` results. Runs once\n // per value, before any user interaction. May be sync or async.\n resolveLabel?: (value: string) => string | Promise<string>\n resolveDescription?: (value: string) => string | null | undefined\n autoFocus?: boolean\n disabled?: boolean\n allowCustomValues?: boolean\n clearable?: boolean\n clearLabel?: string\n 'aria-describedby'?: string\n 'aria-invalid'?: boolean\n 'aria-required'?: boolean\n}\n\nfunction normalizeOptions(input?: Array<string | ComboboxOption>): ComboboxOption[] {\n if (!Array.isArray(input)) return []\n return input\n .map((option) => {\n if (typeof option === 'string') {\n const trimmed = option.trim()\n if (!trimmed) return null\n return { value: trimmed, label: trimmed }\n }\n const value = typeof option.value === 'string' ? option.value.trim() : ''\n if (!value) return null\n return {\n value,\n label: option.label?.trim() || value,\n description: option.description ?? null,\n }\n })\n .filter((option): option is ComboboxOption => !!option)\n}\n\nfunction areOptionsEqual(a: ComboboxOption[], b: ComboboxOption[]): boolean {\n if (a.length !== b.length) return false\n return a.every((option, index) => {\n const next = b[index]\n return option.value === next.value\n && option.label === next.label\n && (option.description ?? null) === (next.description ?? null)\n })\n}\n\nexport function ComboboxInput({\n id,\n value,\n onChange,\n placeholder,\n suggestions,\n seedOptions,\n loadSuggestions,\n resolveLabel,\n resolveDescription,\n autoFocus,\n disabled = false,\n allowCustomValues = true,\n clearable = false,\n clearLabel,\n 'aria-describedby': ariaDescribedBy,\n 'aria-invalid': ariaInvalid,\n 'aria-required': ariaRequired,\n}: ComboboxInputProps) {\n const t = useT()\n const resolvedPlaceholder = placeholder ?? t('ui.inputs.comboboxInput.placeholder', 'Type to search...')\n const loadingLabel = t('ui.inputs.comboboxInput.loading', 'Loading suggestions\u2026')\n const noMatchesLabel = t('ui.inputs.comboboxInput.noMatches', 'No matches found')\n const resolvedClearLabel = clearLabel ?? t('ui.inputs.comboboxInput.clear', 'Clear value')\n const blurCloseDelayMs = 250\n const blurCloseMaxDelayMs = 1000\n const [input, setInput] = React.useState('')\n const [asyncOptions, setAsyncOptions] = React.useState<ComboboxOption[]>([])\n const [resolvedOptions, setResolvedOptions] = React.useState<ComboboxOption[]>([])\n const [loading, setLoading] = React.useState(false)\n const [touched, setTouched] = React.useState(false)\n const [showSuggestions, setShowSuggestions] = React.useState(false)\n const [selectedIndex, setSelectedIndex] = React.useState(-1)\n const listboxId = React.useId()\n const inputRef = React.useRef<HTMLInputElement>(null)\n const loadingRef = React.useRef(false)\n const blurCloseTimerRef = React.useRef<number | null>(null)\n const blurClosePendingRef = React.useRef(false)\n const suppressOpenOnFocusRef = React.useRef(Boolean(autoFocus && !disabled))\n const eagerFallbackLoadedValueRef = React.useRef<string | null>(null)\n // Tracks whether the user actually typed into the field during the current focus\n // session. `touched` cannot serve this purpose because it is set by `onFocus`,\n // which `autoFocus` triggers before the user does anything at all.\n const userTypedRef = React.useRef(false)\n\n const staticOptions = React.useMemo(\n () => normalizeOptions([...(seedOptions ?? []), ...(suggestions ?? [])]),\n [seedOptions, suggestions]\n )\n\n // Single pass over all option sources to build both coverage sets at once.\n // knownLabelValues: values with a genuine label (not a self-mapping placeholder) \u2014\n // used to decide whether eager resolution still needs to run.\n // coveredOptionValues: all values present in any source (even self-mapped).\n const { knownLabelValues, coveredOptionValues } = React.useMemo(() => {\n const known = new Set<string>()\n const covered = new Set<string>()\n for (const opt of [...staticOptions, ...asyncOptions, ...resolvedOptions]) {\n covered.add(opt.value)\n if (opt.label && opt.label !== opt.value) known.add(opt.value)\n }\n return { knownLabelValues: known, coveredOptionValues: covered }\n }, [staticOptions, asyncOptions, resolvedOptions])\n\n const optionMap = React.useMemo(() => {\n const map = new Map<string, ComboboxOption>()\n const register = (option: ComboboxOption) => {\n const existing = map.get(option.value)\n // Prefer an entry that carries a real label over a self-mapping placeholder.\n if (!existing || (existing.label === existing.value && option.label !== option.value)) {\n map.set(option.value, option)\n }\n }\n staticOptions.forEach(register)\n asyncOptions.forEach(register)\n resolvedOptions.forEach(register)\n if (value) {\n const existing = map.get(value)\n if (!existing) {\n map.set(value, {\n value,\n label: value,\n description: resolveDescription?.(value) ?? null,\n })\n }\n }\n return map\n }, [asyncOptions, resolvedOptions, resolveDescription, staticOptions, value])\n\n const availableOptions = React.useMemo(() => {\n return Array.from(optionMap.values())\n }, [optionMap])\n\n React.useEffect(() => {\n loadingRef.current = loading\n }, [loading])\n\n const clearBlurCloseTimer = React.useCallback(() => {\n if (blurCloseTimerRef.current === null) return\n window.clearTimeout(blurCloseTimerRef.current)\n blurCloseTimerRef.current = null\n }, [])\n\n const resetBlurCloseState = React.useCallback(() => {\n blurClosePendingRef.current = false\n clearBlurCloseTimer()\n }, [clearBlurCloseTimer])\n\n React.useEffect(() => resetBlurCloseState, [resetBlurCloseState])\n\n const filteredSuggestions = React.useMemo(() => {\n const query = input.toLowerCase().trim()\n if (!query) return availableOptions\n return availableOptions.filter((option) => {\n const labelMatch = option.label.toLowerCase().includes(query)\n const descMatch = option.description?.toLowerCase().includes(query)\n return labelMatch || Boolean(descMatch)\n })\n }, [availableOptions, input])\n\n React.useEffect(() => {\n if (!loadSuggestions || !touched || disabled) return\n const query = input.trim()\n let cancelled = false\n const handle = window.setTimeout(() => {\n setLoading(true)\n Promise.resolve()\n .then(() => loadSuggestions(query))\n .then((items) => {\n if (!cancelled) {\n const normalized = normalizeOptions(items)\n setAsyncOptions((prev) => areOptionsEqual(prev, normalized) ? prev : normalized)\n }\n })\n .catch(() => {})\n .finally(() => {\n if (!cancelled) setLoading(false)\n })\n }, 200)\n return () => {\n cancelled = true\n window.clearTimeout(handle)\n }\n }, [disabled, input, loadSuggestions, touched])\n\n // Eagerly resolve a pre-selected value to its label without requiring the user\n // to focus the field. Runs once per value when it is not already covered.\n const eagerResolveLabel = typeof resolveLabel === 'function' ? resolveLabel : undefined\n React.useEffect(() => {\n if (!value) return\n let cancelled = false\n const apply = (label?: string | null, description?: string | null) => {\n const clean = typeof label === 'string' ? label.trim() : ''\n if (cancelled || !clean || clean === value) return\n setResolvedOptions((prev) => {\n if (prev.some((option) => option.value === value && option.label === clean)) return prev\n return [...prev.filter((option) => option.value !== value), { value, label: clean, description: description ?? null }]\n })\n }\n if (eagerResolveLabel) {\n if (knownLabelValues.has(value)) return\n Promise.resolve()\n .then(() => eagerResolveLabel(value))\n .then((label) => apply(label, resolveDescription?.(value)))\n .catch(() => {})\n return () => { cancelled = true }\n }\n if (coveredOptionValues.has(value)) return\n if (eagerFallbackLoadedValueRef.current === value) return\n eagerFallbackLoadedValueRef.current = value\n // Fallback: pull the first page of async suggestions so a remount that lost\n // its option cache can still recover the label without user interaction.\n // Note: if the loader is paginated and the value falls outside the first page,\n // the fallback silently fails and the raw value remains visible.\n if (loadSuggestions) {\n setLoading(true)\n Promise.resolve()\n .then(() => loadSuggestions())\n .then((items) => {\n if (cancelled) return\n const normalized = normalizeOptions(items)\n setAsyncOptions((prev) => areOptionsEqual(prev, normalized) ? prev : normalized)\n })\n .catch(() => {})\n .finally(() => { if (!cancelled) setLoading(false) })\n }\n return () => { cancelled = true }\n // eslint-disable-next-line react-hooks/exhaustive-deps -- resolveDescription intentionally excluded:\n // including it would re-run the effect on every render when the prop is an inline function\n }, [value, knownLabelValues, coveredOptionValues, eagerResolveLabel, loadSuggestions])\n\n // Sync input with a value that changed outside the component. A focused field is\n // synced too, because `autoFocus` can focus the control before an async default value\n // arrives and a focus-only guard then leaves the control rendering an empty label for\n // a value the form has already committed. Two conditions still block the sync:\n // - the user is typing, so their query is never clobbered mid-keystroke;\n // - `optionMap` only holds the self-mapping placeholder it synthesises for an\n // uncovered value, which would paint the raw record id over a label the user just\n // picked (`asyncOptions` is replaced on every load, so any follow-up load that\n // misses the picked entry \u2014 a failed request, a debounce race, a composite label\n // the route's `?search=` cannot match \u2014 drops it back to the placeholder).\n React.useEffect(() => {\n const option = optionMap.get(value)\n const hasRealLabel = Boolean(option && option.label !== option.value)\n if (document.activeElement === inputRef.current && (userTypedRef.current || !hasRealLabel)) return\n setInput(option?.label ?? value ?? '')\n }, [value, optionMap])\n\n const selectValue = React.useCallback(\n (nextValue: string) => {\n if (disabled) return\n resetBlurCloseState()\n const trimmed = nextValue.trim()\n onChange(trimmed)\n const option = optionMap.get(trimmed)\n setInput(option?.label ?? trimmed)\n setShowSuggestions(false)\n setSelectedIndex(-1)\n userTypedRef.current = false\n },\n [disabled, onChange, optionMap, resetBlurCloseState]\n )\n\n const findOptionForInput = React.useCallback(\n (raw: string): ComboboxOption | null => {\n const query = raw.trim().toLowerCase()\n if (!query) return null\n for (const option of optionMap.values()) {\n if (option.value === raw.trim()) return option\n if (option.label.toLowerCase() === query) return option\n }\n return null\n },\n [optionMap]\n )\n\n const confirmSelection = React.useCallback(\n (raw: string) => {\n if (disabled) return\n if (clearable && raw.trim() === '') {\n selectValue('')\n return\n }\n const option = findOptionForInput(raw)\n if (option) {\n selectValue(option.value)\n return\n }\n if (!allowCustomValues) {\n // Revert to the current value's label \u2014 but only if we actually know it.\n // Baking the raw value back in while eager resolution is still pending\n // would freeze a placeholder (e.g. a UUID) into the visible input.\n setShowSuggestions(false)\n const currentOption = optionMap.get(value)\n if (currentOption && currentOption.label !== currentOption.value) {\n setInput(currentOption.label)\n } else if (!value) {\n setInput('')\n }\n return\n }\n selectValue(raw)\n },\n [allowCustomValues, clearable, disabled, findOptionForInput, optionMap, selectValue, value]\n )\n\n const handleClear = React.useCallback(() => {\n if (disabled) return\n selectValue('')\n inputRef.current?.focus()\n }, [disabled, selectValue])\n\n const closeAfterBlur = React.useCallback(() => {\n blurCloseTimerRef.current = null\n if (disabled) return\n blurClosePendingRef.current = false\n confirmSelection(input)\n setShowSuggestions(false)\n setSelectedIndex(-1)\n }, [confirmSelection, disabled, input])\n\n const attemptBlurClose = React.useCallback(() => {\n blurCloseTimerRef.current = null\n if (disabled) return\n if (loadingRef.current) {\n blurCloseTimerRef.current = window.setTimeout(closeAfterBlur, blurCloseMaxDelayMs)\n return\n }\n closeAfterBlur()\n }, [blurCloseMaxDelayMs, closeAfterBlur, disabled])\n\n React.useEffect(() => {\n if (!blurClosePendingRef.current) return\n if (loading) return\n clearBlurCloseTimer()\n closeAfterBlur()\n }, [clearBlurCloseTimer, closeAfterBlur, loading])\n\n const handleKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n if (!showSuggestions) {\n setShowSuggestions(true)\n setSelectedIndex(0)\n } else {\n setSelectedIndex((prev) => Math.min(prev + 1, filteredSuggestions.length - 1))\n }\n } else if (event.key === 'ArrowUp') {\n event.preventDefault()\n setSelectedIndex((prev) => Math.max(prev - 1, -1))\n } else if (event.key === 'Enter') {\n event.preventDefault()\n if (selectedIndex >= 0 && filteredSuggestions[selectedIndex]) {\n selectValue(filteredSuggestions[selectedIndex].value)\n } else {\n confirmSelection(input)\n }\n } else if (event.key === 'Escape') {\n if (!showSuggestions) return\n event.preventDefault()\n event.stopPropagation()\n setShowSuggestions(false)\n setSelectedIndex(-1)\n }\n },\n [confirmSelection, disabled, filteredSuggestions, input, selectValue, selectedIndex, showSuggestions]\n )\n\n const optionDomId = React.useCallback(\n (index: number) => `${listboxId}-option-${index}`,\n [listboxId],\n )\n\n React.useEffect(() => {\n if (selectedIndex < 0 || !showSuggestions) return\n const activeElement = typeof document !== 'undefined'\n ? document.getElementById(optionDomId(selectedIndex))\n : null\n if (typeof activeElement?.scrollIntoView === 'function') {\n activeElement.scrollIntoView({ block: 'nearest' })\n }\n }, [optionDomId, selectedIndex, showSuggestions])\n\n const showClearButton = clearable && !disabled && (value !== '' || input !== '')\n const listboxVisible = showSuggestions\n && !disabled\n && (loading || filteredSuggestions.length > 0 || (touched && input.trim().length > 0))\n\n return (\n // The suggestion list goes through the DS Popover so it is portaled out of any\n // scrolling ancestor. Rendered in place it was clipped by a Dialog's\n // `overflow-y-auto`, where z-index cannot help. `open` stays fully controlled\n // (no `onOpenChange`) so the blur timer, Escape and selection keep owning\n // dismissal exactly as before.\n <Popover open={listboxVisible}>\n <PopoverAnchor asChild>\n <div className=\"relative w-full\">\n {/* Use raw <input> here instead of the DS Input primitive: ComboboxInput's\n focus / suggestions-popup interplay relies on the trigger being a plain\n input element. The DS wrapper introduces a <div> that desyncs autocomplete\n on this specific surface. Keeps the rest of the form on Input primitive. */}\n <input\n ref={inputRef}\n id={id}\n type=\"text\"\n className={[\n 'w-full h-9 rounded-md border border-input bg-background px-3 text-sm shadow-xs transition-colors outline-none placeholder:text-muted-foreground focus-visible:shadow-focus focus-visible:border-foreground disabled:bg-bg-disabled disabled:border-border-disabled disabled:text-muted-foreground disabled:cursor-not-allowed',\n showClearButton ? 'pr-9' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n value={input}\n placeholder={resolvedPlaceholder}\n autoFocus={autoFocus}\n data-crud-focus-target=\"\"\n disabled={disabled}\n role=\"combobox\"\n aria-expanded={listboxVisible}\n aria-controls={listboxVisible && !loading && filteredSuggestions.length > 0 ? listboxId : undefined}\n // The listbox is portaled out of the input's subtree, so `aria-owns` is what\n // makes it a logical descendant and keeps `aria-activedescendant` below valid.\n aria-owns={listboxVisible && !loading && filteredSuggestions.length > 0 ? listboxId : undefined}\n aria-autocomplete=\"list\"\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n aria-required={ariaRequired}\n aria-activedescendant={listboxVisible && selectedIndex >= 0 ? optionDomId(selectedIndex) : undefined}\n onFocus={() => {\n setTouched(true)\n if (suppressOpenOnFocusRef.current) {\n suppressOpenOnFocusRef.current = false\n return\n }\n resetBlurCloseState()\n if (loadSuggestions && availableOptions.length === 0) {\n setLoading(true)\n }\n setShowSuggestions(true)\n }}\n onChange={(event) => {\n setTouched(true)\n userTypedRef.current = true\n setInput(event.target.value)\n setShowSuggestions(true)\n setSelectedIndex(-1)\n }}\n onKeyDown={handleKeyDown}\n onBlur={() => {\n // Delay closing so clicks on the popup can resolve first. If async\n // suggestions are still loading, keep the dropdown open instead of\n // closing before the first payload arrives.\n userTypedRef.current = false\n blurClosePendingRef.current = true\n clearBlurCloseTimer()\n if (loadingRef.current) {\n blurCloseTimerRef.current = window.setTimeout(closeAfterBlur, blurCloseMaxDelayMs)\n return\n }\n blurCloseTimerRef.current = window.setTimeout(attemptBlurClose, blurCloseDelayMs)\n }}\n />\n\n {showClearButton ? (\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"xs\"\n aria-label={resolvedClearLabel}\n className=\"absolute right-1 top-1/2 -translate-y-1/2\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={handleClear}\n >\n <X className=\"size-3\" />\n </IconButton>\n ) : null}\n </div>\n </PopoverAnchor>\n\n {/* Unmount the content outright rather than leaning on Radix's exit animation:\n a closing-but-still-mounted layer keeps swallowing Escape, which would\n strand the popup's host (see AdvancedFilterPanel for that failure mode). */}\n {listboxVisible ? (\n <PopoverContent\n // Radix hardcodes `role=\"dialog\"` on popover content. This popup is a\n // positioning shell around the listbox below, and a second dialog node\n // would both misdescribe it and break `getByRole('dialog')` for anything\n // that queries while suggestions happen to be open.\n role=\"presentation\"\n // Focus must stay in the input: the blur-close timer and\n // aria-activedescendant model depend on it, and Radix would otherwise\n // move focus into the list on open and back to the trigger on close.\n onOpenAutoFocus={(event) => event.preventDefault()}\n onCloseAutoFocus={(event) => event.preventDefault()}\n // A modal Dialog locks scrolling through `react-remove-scroll`, which\n // cancels document-level `wheel` and `touchmove` outside its own content\n // node. The portaled list is not part of that exemption, so without these\n // a long list inside a dialog cannot be scrolled by wheel or by touch.\n // `overscroll-contain` stops the scroll chaining to the page at the ends.\n onWheel={(event) => event.stopPropagation()}\n onTouchMove={(event) => event.stopPropagation()}\n className=\"w-[var(--radix-popover-trigger-width)] min-w-0 max-h-48 sm:max-h-60 overflow-auto overscroll-contain border-input p-2\"\n >\n {loading && touched ? (\n <div className=\"px-2 py-1.5 text-xs text-muted-foreground\" role=\"status\">{loadingLabel}</div>\n ) : touched && !filteredSuggestions.length ? (\n <div className=\"px-2 py-1.5 text-xs text-muted-foreground\" role=\"status\">{noMatchesLabel}</div>\n ) : (\n <div id={listboxId} role=\"listbox\" className=\"flex flex-col gap-1\">\n {filteredSuggestions.map((option, index) => (\n <Button\n key={option.value}\n id={optionDomId(index)}\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n role=\"option\"\n aria-selected={index === selectedIndex}\n className={[\n 'w-full h-auto justify-start font-normal text-left flex flex-col items-start rounded-lg p-2',\n index === selectedIndex ? 'bg-muted' : '',\n ]\n .filter(Boolean)\n .join(' ')}\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => {\n resetBlurCloseState()\n selectValue(option.value)\n }}\n onMouseEnter={() => setSelectedIndex(index)}\n >\n <span className=\"font-medium text-foreground\">{option.label}</span>\n {option.description ? (\n <span className=\"text-xs text-muted-foreground\">{option.description}</span>\n ) : null}\n </Button>\n ))}\n </div>\n )}\n </PopoverContent>\n ) : null}\n </Popover>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA8aQ,SAKE,KALF;AA5aR,YAAY,WAAW;AACvB,SAAS,SAAS;AAClB,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,SAAS,eAAe,sBAAsB;AAkCvD,SAAS,iBAAiB,OAA0D;AAClF,MAAI,CAAC,MAAM,QAAQ,KAAK,EAAG,QAAO,CAAC;AACnC,SAAO,MACJ,IAAI,CAAC,WAAW;AACf,QAAI,OAAO,WAAW,UAAU;AAC9B,YAAM,UAAU,OAAO,KAAK;AAC5B,UAAI,CAAC,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7
7
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import * as React from "react";
|
|
4
4
|
import { Check, Loader2, Search, X } from "lucide-react";
|
|
5
5
|
import { useT } from "@open-mercato/shared/lib/i18n/context";
|
|
6
6
|
import { Button } from "../../primitives/button.js";
|
|
7
|
+
import { IconButton } from "../../primitives/icon-button.js";
|
|
7
8
|
import { cn } from "@open-mercato/shared/lib/utils";
|
|
8
9
|
import { createLogger } from "@open-mercato/shared/lib/logger";
|
|
9
10
|
const logger = createLogger("ui").child({ component: "LookupSelect" });
|
|
@@ -42,6 +43,7 @@ function LookupSelect({
|
|
|
42
43
|
const resolvedLoadingLabel = loadingLabel ?? t("ui.lookupSelect.searching", "Searching\u2026");
|
|
43
44
|
const resolvedSelectLabel = selectLabel ?? t("ui.lookupSelect.select", "Select");
|
|
44
45
|
const resolvedSelectedLabel = selectedLabel ?? t("ui.lookupSelect.selected", "Selected");
|
|
46
|
+
const resolvedChangeLabel = t("ui.lookupSelect.change", "Change");
|
|
45
47
|
const resolvedStartTypingLabel = startTypingLabel ?? t("ui.lookupSelect.startTyping", "Start typing to search.");
|
|
46
48
|
const resolvedMinQueryHintLabel = minQueryHintLabel ?? t(
|
|
47
49
|
"ui.lookupSelect.minQueryHint",
|
|
@@ -51,11 +53,12 @@ function LookupSelect({
|
|
|
51
53
|
const [query, setQuery] = React.useState("");
|
|
52
54
|
const [items, setItems] = React.useState(options ?? []);
|
|
53
55
|
const [loading, setLoading] = React.useState(false);
|
|
54
|
-
const [collapsed, setCollapsed] = React.useState(
|
|
56
|
+
const [collapsed, setCollapsed] = React.useState(() => Boolean(value) && !defaultOpen);
|
|
55
57
|
const [hasTyped, setHasTyped] = React.useState(defaultOpen);
|
|
56
58
|
const [error, setError] = React.useState(null);
|
|
57
59
|
const [fetchKey, setFetchKey] = React.useState(0);
|
|
58
60
|
const [activeIndex, setActiveIndex] = React.useState(-1);
|
|
61
|
+
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
59
62
|
const listboxId = React.useId();
|
|
60
63
|
const fetchItemsRef = React.useRef(fetchItems ?? fetchOptions);
|
|
61
64
|
const setQueryRef = React.useRef(setQuery);
|
|
@@ -63,6 +66,10 @@ function LookupSelect({
|
|
|
63
66
|
const optionsWasArrayRef = React.useRef(Array.isArray(options));
|
|
64
67
|
const valueRef = React.useRef(value);
|
|
65
68
|
const selectedItemRef = React.useRef(null);
|
|
69
|
+
const inputRef = React.useRef(null);
|
|
70
|
+
const pendingCommitRef = React.useRef(null);
|
|
71
|
+
const changeButtonRef = React.useRef(null);
|
|
72
|
+
const focusSummaryRef = React.useRef(false);
|
|
66
73
|
React.useEffect(() => {
|
|
67
74
|
fetchItemsRef.current = fetchItems ?? fetchOptions;
|
|
68
75
|
}, [fetchItems, fetchOptions]);
|
|
@@ -115,7 +122,47 @@ function LookupSelect({
|
|
|
115
122
|
activeElement.scrollIntoView({ block: "nearest" });
|
|
116
123
|
}
|
|
117
124
|
}, [activeIndex, optionDomId]);
|
|
118
|
-
const listboxVisible = shouldSearch && !disabled;
|
|
125
|
+
const listboxVisible = shouldSearch && !disabled && !collapsed;
|
|
126
|
+
const finishSelection = React.useCallback(() => {
|
|
127
|
+
pendingCommitRef.current = null;
|
|
128
|
+
focusSummaryRef.current = true;
|
|
129
|
+
setCollapsed(true);
|
|
130
|
+
setQuery("");
|
|
131
|
+
setHasTyped(false);
|
|
132
|
+
setActiveIndex(-1);
|
|
133
|
+
}, []);
|
|
134
|
+
const commitSelection = React.useCallback((item) => {
|
|
135
|
+
selectedItemRef.current = item;
|
|
136
|
+
setSelectedItem(item);
|
|
137
|
+
if (valueRef.current === item.id) {
|
|
138
|
+
finishSelection();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
pendingCommitRef.current = item.id;
|
|
142
|
+
onChange(item.id);
|
|
143
|
+
}, [finishSelection, onChange]);
|
|
144
|
+
React.useEffect(() => {
|
|
145
|
+
if (pendingCommitRef.current) {
|
|
146
|
+
if (value === pendingCommitRef.current) finishSelection();
|
|
147
|
+
else if (value) pendingCommitRef.current = null;
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (value && !hasTyped && query.length === 0) setCollapsed(true);
|
|
151
|
+
}, [finishSelection, hasTyped, query, value]);
|
|
152
|
+
const focusAfterReopenRef = React.useRef(false);
|
|
153
|
+
const reopenList = React.useCallback(() => {
|
|
154
|
+
focusAfterReopenRef.current = true;
|
|
155
|
+
focusSummaryRef.current = false;
|
|
156
|
+
setCollapsed(false);
|
|
157
|
+
}, []);
|
|
158
|
+
const clearSelection = React.useCallback(() => {
|
|
159
|
+
focusAfterReopenRef.current = true;
|
|
160
|
+
focusSummaryRef.current = false;
|
|
161
|
+
onChange(null);
|
|
162
|
+
}, [onChange]);
|
|
163
|
+
React.useEffect(() => {
|
|
164
|
+
if (!value) setCollapsed(false);
|
|
165
|
+
}, [value]);
|
|
119
166
|
const handleInputKeyDown = React.useCallback((event) => {
|
|
120
167
|
if (!listboxVisible) return;
|
|
121
168
|
if (event.key === "ArrowDown") {
|
|
@@ -133,8 +180,7 @@ function LookupSelect({
|
|
|
133
180
|
const item = items[activeIndex];
|
|
134
181
|
if (!isInteractiveItem(item)) return;
|
|
135
182
|
event.preventDefault();
|
|
136
|
-
|
|
137
|
-
setActiveIndex(-1);
|
|
183
|
+
commitSelection(item);
|
|
138
184
|
return;
|
|
139
185
|
}
|
|
140
186
|
if (event.key === "Escape") {
|
|
@@ -143,9 +189,10 @@ function LookupSelect({
|
|
|
143
189
|
event.stopPropagation();
|
|
144
190
|
setQuery("");
|
|
145
191
|
setActiveIndex(-1);
|
|
192
|
+
focusSummaryRef.current = Boolean(value);
|
|
146
193
|
setCollapsed(true);
|
|
147
194
|
}
|
|
148
|
-
}, [activeIndex, items, isInteractiveItem, listboxVisible, moveActiveIndex,
|
|
195
|
+
}, [activeIndex, commitSelection, items, isInteractiveItem, listboxVisible, moveActiveIndex, query, value]);
|
|
149
196
|
React.useEffect(() => {
|
|
150
197
|
if (disabled) {
|
|
151
198
|
setItems(options ?? []);
|
|
@@ -188,7 +235,6 @@ function LookupSelect({
|
|
|
188
235
|
if (timer) clearTimeout(timer);
|
|
189
236
|
};
|
|
190
237
|
}, [query, shouldSearch, fetchKey]);
|
|
191
|
-
const [selectedItem, setSelectedItem] = React.useState(null);
|
|
192
238
|
React.useEffect(() => {
|
|
193
239
|
if (!value) {
|
|
194
240
|
selectedItemRef.current = null;
|
|
@@ -202,20 +248,34 @@ function LookupSelect({
|
|
|
202
248
|
}
|
|
203
249
|
}, [items, value]);
|
|
204
250
|
const collapsedSelectionLabel = React.useMemo(() => {
|
|
205
|
-
if (!value
|
|
206
|
-
const hinted = selectedHintLabel(value);
|
|
207
|
-
if (hinted && hinted !== value) return hinted;
|
|
251
|
+
if (!value) return null;
|
|
252
|
+
const hinted = selectedHintLabel?.(value);
|
|
253
|
+
if (hinted && hinted !== value && !hinted.includes(value)) return hinted;
|
|
208
254
|
const fetchedTitle = selectedItem && selectedItem.id === value ? selectedItem.title : null;
|
|
209
255
|
return fetchedTitle && fetchedTitle !== value ? fetchedTitle : null;
|
|
210
256
|
}, [selectedHintLabel, selectedItem, value]);
|
|
257
|
+
const collapsedSelectionSubtitle = selectedItem && selectedItem.id === value ? selectedItem.subtitle ?? null : null;
|
|
258
|
+
const showSummaryOnly = collapsed && Boolean(collapsedSelectionLabel);
|
|
259
|
+
React.useEffect(() => {
|
|
260
|
+
if (showSummaryOnly) {
|
|
261
|
+
if (!focusSummaryRef.current) return;
|
|
262
|
+
focusSummaryRef.current = false;
|
|
263
|
+
changeButtonRef.current?.focus();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (!focusAfterReopenRef.current) return;
|
|
267
|
+
focusAfterReopenRef.current = false;
|
|
268
|
+
inputRef.current?.focus();
|
|
269
|
+
}, [showSummaryOnly]);
|
|
211
270
|
return /* @__PURE__ */ jsxs("div", { className: "space-y-3", children: [
|
|
212
|
-
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3", children: [
|
|
271
|
+
showSummaryOnly ? null : /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3", children: [
|
|
213
272
|
/* @__PURE__ */ jsxs("div", { className: "relative flex-1", children: [
|
|
214
273
|
/* @__PURE__ */ jsx(Search, { className: "pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground" }),
|
|
215
274
|
/* @__PURE__ */ jsx(
|
|
216
275
|
"input",
|
|
217
276
|
{
|
|
218
|
-
|
|
277
|
+
ref: inputRef,
|
|
278
|
+
className: "w-full h-9 rounded-lg border border-input bg-background pl-10 pr-3 text-sm shadow-xs transition-colors outline-none placeholder:text-muted-foreground hover:border-foreground/20 focus-visible:shadow-focus focus-visible:border-foreground disabled:bg-bg-disabled disabled:border-border-disabled disabled:text-muted-foreground disabled:cursor-not-allowed",
|
|
219
279
|
value: query,
|
|
220
280
|
onChange: (event) => {
|
|
221
281
|
setQuery(event.target.value);
|
|
@@ -256,41 +316,44 @@ function LookupSelect({
|
|
|
256
316
|
{
|
|
257
317
|
id: optionDomId(index),
|
|
258
318
|
className: cn(
|
|
259
|
-
"group flex items-center gap-
|
|
319
|
+
"group flex items-center gap-3 rounded-lg border px-3 py-2 transition-all duration-150 focus-visible:outline-none focus-visible:shadow-focus",
|
|
260
320
|
isInteractive ? "cursor-pointer" : "cursor-not-allowed opacity-60",
|
|
261
|
-
isSelected ? "border-
|
|
321
|
+
isSelected ? "border-accent-indigo bg-accent-indigo/5" : "border-input bg-card hover:border-foreground/20 hover:bg-muted/30",
|
|
262
322
|
isActive && !isSelected ? "border-foreground/20 bg-muted/30 shadow-sm" : null
|
|
263
323
|
),
|
|
264
324
|
role: "option",
|
|
265
325
|
tabIndex: isInteractive ? 0 : -1,
|
|
266
326
|
onClick: () => {
|
|
267
327
|
if (!isInteractive) return;
|
|
268
|
-
|
|
328
|
+
commitSelection(item);
|
|
269
329
|
},
|
|
270
330
|
onKeyDown: (event) => {
|
|
271
331
|
if (event.key === "Enter" || event.key === " ") {
|
|
272
332
|
event.preventDefault();
|
|
273
333
|
if (!isInteractive) return;
|
|
274
|
-
|
|
334
|
+
commitSelection(item);
|
|
275
335
|
}
|
|
276
336
|
},
|
|
277
337
|
"aria-selected": isSelected,
|
|
278
338
|
"aria-disabled": isInteractive ? void 0 : true,
|
|
279
339
|
title: isSelected ? resolvedSelectedLabel : isInteractive ? resolvedSelectLabel : void 0,
|
|
280
340
|
children: [
|
|
281
|
-
item.icon ? /* @__PURE__ */ jsx("div", { className: "flex h-
|
|
282
|
-
"flex h-
|
|
283
|
-
isSelected ? "border-
|
|
284
|
-
), children: /* @__PURE__ */ jsx("span", { className: "text-
|
|
341
|
+
item.icon ? /* @__PURE__ */ jsx("div", { className: "flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden [&>svg]:size-5 [&_svg]:text-muted-foreground", children: item.icon }) : /* @__PURE__ */ jsx("div", { className: cn(
|
|
342
|
+
"flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md border transition-colors",
|
|
343
|
+
isSelected ? "border-accent-indigo/40 bg-accent-indigo/10 text-accent-indigo" : "border-input bg-muted text-muted-foreground group-hover:border-foreground/20"
|
|
344
|
+
), children: /* @__PURE__ */ jsx("span", { className: "text-sm font-medium uppercase", children: item.title.slice(0, 1) }) }),
|
|
285
345
|
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [
|
|
286
346
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3", children: [
|
|
287
|
-
/* @__PURE__ */ jsx("div", { className: "truncate text-sm font-
|
|
347
|
+
/* @__PURE__ */ jsx("div", { className: "truncate text-sm font-medium text-foreground", children: item.title }),
|
|
288
348
|
item.rightLabel ? /* @__PURE__ */ jsx("div", { className: "shrink-0 text-overline font-medium uppercase tracking-wider text-muted-foreground", children: item.rightLabel }) : null
|
|
289
349
|
] }),
|
|
290
350
|
item.subtitle ? /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground truncate", children: item.subtitle }) : null,
|
|
291
351
|
item.description ? /* @__PURE__ */ jsx("div", { className: "text-xs text-muted-foreground/70 truncate", children: item.description }) : null
|
|
292
352
|
] }),
|
|
293
|
-
/* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center justify-center", children: isSelected ? /* @__PURE__ */
|
|
353
|
+
/* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center justify-center gap-1.5", children: isSelected ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
354
|
+
/* @__PURE__ */ jsx("span", { className: "text-xs font-medium text-foreground", children: resolvedSelectedLabel }),
|
|
355
|
+
/* @__PURE__ */ jsx(Check, { className: "size-4 text-accent-indigo", "aria-hidden": "true" })
|
|
356
|
+
] }) : /* @__PURE__ */ jsx("div", { className: "size-5", "aria-hidden": "true" }) })
|
|
294
357
|
]
|
|
295
358
|
},
|
|
296
359
|
item.id
|
|
@@ -314,33 +377,52 @@ function LookupSelect({
|
|
|
314
377
|
) : null
|
|
315
378
|
] }) : collapsedSelectionLabel ? (
|
|
316
379
|
/*
|
|
317
|
-
* The
|
|
318
|
-
*
|
|
319
|
-
* then collapsed left the control looking empty even though the form
|
|
320
|
-
* held the id. `selectedHintLabel` existed for exactly this and was
|
|
321
|
-
* never rendered.
|
|
380
|
+
* The selection as a single row: the name is the control that reopens the
|
|
381
|
+
* search (Change), the icon clears. No second search box above it.
|
|
322
382
|
*/
|
|
323
383
|
/* @__PURE__ */ jsxs(
|
|
324
384
|
"div",
|
|
325
385
|
{
|
|
326
|
-
className:
|
|
386
|
+
className: cn(
|
|
387
|
+
"flex h-9 items-center gap-1 rounded-lg border border-accent-indigo bg-accent-indigo/5 pl-1 pr-1",
|
|
388
|
+
disabled && "border-border-disabled bg-bg-disabled"
|
|
389
|
+
),
|
|
327
390
|
"data-testid": "lookup-select-selected",
|
|
328
391
|
children: [
|
|
329
|
-
/* @__PURE__ */
|
|
330
|
-
|
|
392
|
+
disabled ? /* @__PURE__ */ jsxs("span", { className: "flex h-7 min-w-0 flex-1 items-center gap-2 px-2 text-muted-foreground", children: [
|
|
393
|
+
/* @__PURE__ */ jsx(Check, { className: "size-4 shrink-0", "aria-hidden": "true" }),
|
|
394
|
+
/* @__PURE__ */ jsx("span", { className: "truncate text-sm", children: collapsedSelectionLabel }),
|
|
395
|
+
collapsedSelectionSubtitle ? /* @__PURE__ */ jsx("span", { className: "hidden truncate text-xs sm:inline", children: collapsedSelectionSubtitle }) : null
|
|
396
|
+
] }) : /* @__PURE__ */ jsxs(
|
|
331
397
|
Button,
|
|
332
398
|
{
|
|
399
|
+
ref: changeButtonRef,
|
|
333
400
|
type: "button",
|
|
334
401
|
variant: "ghost",
|
|
335
402
|
size: "sm",
|
|
336
|
-
className: "
|
|
337
|
-
|
|
338
|
-
|
|
403
|
+
className: "h-7 min-w-0 flex-1 justify-start gap-2 px-2 text-left font-normal hover:bg-accent-indigo/10 hover:text-accent-indigo",
|
|
404
|
+
onClick: reopenList,
|
|
405
|
+
"aria-label": resolvedChangeLabel,
|
|
406
|
+
title: resolvedChangeLabel,
|
|
339
407
|
children: [
|
|
340
|
-
/* @__PURE__ */ jsx(
|
|
341
|
-
|
|
408
|
+
/* @__PURE__ */ jsx(Check, { className: "size-4 shrink-0 text-accent-indigo", "aria-hidden": "true" }),
|
|
409
|
+
/* @__PURE__ */ jsx("span", { className: "truncate text-sm text-foreground", children: collapsedSelectionLabel }),
|
|
410
|
+
collapsedSelectionSubtitle ? /* @__PURE__ */ jsx("span", { className: "hidden truncate text-xs text-muted-foreground sm:inline", children: collapsedSelectionSubtitle }) : null
|
|
342
411
|
]
|
|
343
412
|
}
|
|
413
|
+
),
|
|
414
|
+
disabled ? null : /* @__PURE__ */ jsx(
|
|
415
|
+
IconButton,
|
|
416
|
+
{
|
|
417
|
+
type: "button",
|
|
418
|
+
variant: "ghost",
|
|
419
|
+
size: "sm",
|
|
420
|
+
className: "shrink-0 text-muted-foreground hover:bg-accent-indigo/10 hover:text-accent-indigo",
|
|
421
|
+
onClick: clearSelection,
|
|
422
|
+
"aria-label": resolvedClearLabel,
|
|
423
|
+
title: resolvedClearLabel,
|
|
424
|
+
children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
|
|
425
|
+
}
|
|
344
426
|
)
|
|
345
427
|
]
|
|
346
428
|
}
|