@open-mercato/ui 0.11.1-develop.8305.1.6a9c271838 → 0.11.1-develop.8325.1.5d93cbd8bf
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/charts/KpiCard.js +1 -1
- package/dist/backend/charts/KpiCard.js.map +2 -2
- package/dist/backend/inputs/ComboboxInput.js +4 -5
- package/dist/backend/inputs/ComboboxInput.js.map +2 -2
- package/dist/backend/inputs/LookupSelect.js +2 -2
- package/dist/backend/inputs/LookupSelect.js.map +2 -2
- package/package.json +3 -3
- package/src/backend/charts/KpiCard.tsx +1 -1
- package/src/backend/charts/__tests__/KpiCard.test.tsx +19 -0
- package/src/backend/inputs/ComboboxInput.tsx +4 -5
- package/src/backend/inputs/LookupSelect.tsx +2 -2
- package/src/backend/inputs/__tests__/ComboboxInput.test.tsx +49 -0
- package/src/backend/inputs/__tests__/LookupSelect.hints.test.tsx +73 -0
|
@@ -92,7 +92,7 @@ function KpiCard({
|
|
|
92
92
|
] }),
|
|
93
93
|
trend && /* @__PURE__ */ jsx(BadgeDelta, { direction: trend.direction, value: trend.value })
|
|
94
94
|
] }),
|
|
95
|
-
|
|
95
|
+
comparisonLabel && /* @__PURE__ */ jsx("p", { className: "mt-1 text-xs text-muted-foreground", children: comparisonLabel }),
|
|
96
96
|
footer != null && /* @__PURE__ */ jsx("div", { className: "mt-3", children: footer })
|
|
97
97
|
] });
|
|
98
98
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/charts/KpiCard.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type KpiTrend = {\n value: number\n direction: 'up' | 'down' | 'unchanged'\n}\n\nexport type KpiCardProps = {\n title?: string\n value: number | null\n trend?: KpiTrend\n comparisonLabel?: string\n loading?: boolean\n error?: string | null\n formatValue?: (value: number) => string\n prefix?: string\n suffix?: string\n className?: string\n headerAction?: React.ReactNode\n footer?: React.ReactNode\n titleClassName?: string\n}\n\nfunction defaultFormatValue(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nfunction formatPercentageChange(value: number, unit: string = '%'): string {\n const abs = Math.abs(value)\n const formatted = Number.isInteger(abs) ? String(abs) : abs.toFixed(1)\n return `${formatted}${unit}`\n}\n\ntype BadgeDeltaProps = {\n direction: 'up' | 'down' | 'unchanged'\n value: number\n unit?: string\n className?: string\n title?: string\n}\n\nfunction BadgeDelta({ direction, value, unit = '%', className = '', title = 'Compared to previous period' }: BadgeDeltaProps) {\n const baseClasses = 'inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium'\n\n const directionClasses = {\n up: 'bg-status-success-bg text-status-success-text',\n down: 'bg-status-error-bg text-status-error-text',\n unchanged: 'bg-status-neutral-bg text-status-neutral-text',\n }\n\n const icons = {\n up: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M5 10l7-7m0 0l7 7m-7-7v18\" />\n </svg>\n ),\n down: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M19 14l-7 7m0 0l-7-7m7 7V3\" />\n </svg>\n ),\n unchanged: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M5 12h14\" />\n </svg>\n ),\n }\n\n return (\n <span\n className={`${baseClasses} ${directionClasses[direction]}${className ? ` ${className}` : ''}`}\n title={title}\n >\n {icons[direction]}\n {formatPercentageChange(value, unit)}\n </span>\n )\n}\n\nexport const DeltaBadge = BadgeDelta\n\nexport function KpiCard({\n title,\n value,\n trend,\n comparisonLabel,\n loading,\n error,\n formatValue = defaultFormatValue,\n prefix = '',\n suffix = '',\n className = '',\n headerAction,\n footer,\n titleClassName,\n}: KpiCardProps) {\n const hasWrapper = !!title\n const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className\n\n const headerRow = (title || headerAction) ? (\n <div className=\"flex items-center justify-between gap-2 mb-2\">\n {title && <p className={titleClassName ?? 'text-sm font-medium text-muted-foreground'}>{title}</p>}\n {headerAction}\n </div>\n ) : null\n\n if (error) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <p className=\"text-sm text-destructive\">{error}</p>\n </div>\n )\n }\n\n if (loading) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <div className=\"flex items-center justify-center py-4\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n </div>\n )\n }\n\n if (value === null) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <p className=\"text-2xl sm:text-3xl font-semibold tracking-tight text-card-foreground\">--</p>\n {footer != null && <div className=\"mt-3\">{footer}</div>}\n </div>\n )\n }\n\n return (\n <div className={wrapperClass}>\n {headerRow}\n <div className=\"flex items-baseline gap-3\">\n <p className=\"flex items-baseline gap-1.5 text-2xl sm:text-3xl font-semibold tracking-tight text-card-foreground\">\n <span>{prefix}{formatValue(value)}</span>\n {suffix ? <span className=\"text-sm font-medium text-muted-foreground\">{suffix}</span> : null}\n </p>\n {trend && (\n <BadgeDelta direction={trend.direction} value={trend.value} />\n )}\n </div>\n {
|
|
5
|
-
"mappings": ";AA8DQ,cAgBJ,YAhBI;AA3DR,SAAS,eAAe;AAuBxB,SAAS,mBAAmB,OAAuB;AACjD,MAAI,KAAK,IAAI,KAAK,KAAK,KAA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A6C,kBAAO,IAAU;AAAA,SAC1F;AAAA,MACC,SACC,oBAAC,cAAW,WAAW,MAAM,WAAW,OAAO,MAAM,OAAO;AAAA,OAEhE;AAAA,IACC,
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { Spinner } from '@open-mercato/ui/primitives/spinner'\n\nexport type KpiTrend = {\n value: number\n direction: 'up' | 'down' | 'unchanged'\n}\n\nexport type KpiCardProps = {\n title?: string\n value: number | null\n trend?: KpiTrend\n comparisonLabel?: string\n loading?: boolean\n error?: string | null\n formatValue?: (value: number) => string\n prefix?: string\n suffix?: string\n className?: string\n headerAction?: React.ReactNode\n footer?: React.ReactNode\n titleClassName?: string\n}\n\nfunction defaultFormatValue(value: number): string {\n if (Math.abs(value) >= 1_000_000) {\n return `${(value / 1_000_000).toFixed(1)}M`\n }\n if (Math.abs(value) >= 1_000) {\n return `${(value / 1_000).toFixed(1)}K`\n }\n return value.toLocaleString(undefined, { maximumFractionDigits: 2 })\n}\n\nfunction formatPercentageChange(value: number, unit: string = '%'): string {\n const abs = Math.abs(value)\n const formatted = Number.isInteger(abs) ? String(abs) : abs.toFixed(1)\n return `${formatted}${unit}`\n}\n\ntype BadgeDeltaProps = {\n direction: 'up' | 'down' | 'unchanged'\n value: number\n unit?: string\n className?: string\n title?: string\n}\n\nfunction BadgeDelta({ direction, value, unit = '%', className = '', title = 'Compared to previous period' }: BadgeDeltaProps) {\n const baseClasses = 'inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-medium'\n\n const directionClasses = {\n up: 'bg-status-success-bg text-status-success-text',\n down: 'bg-status-error-bg text-status-error-text',\n unchanged: 'bg-status-neutral-bg text-status-neutral-text',\n }\n\n const icons = {\n up: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M5 10l7-7m0 0l7 7m-7-7v18\" />\n </svg>\n ),\n down: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M19 14l-7 7m0 0l-7-7m7 7V3\" />\n </svg>\n ),\n unchanged: (\n <svg className=\"h-3 w-3\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" strokeWidth={2}>\n <path strokeLinecap=\"round\" strokeLinejoin=\"round\" d=\"M5 12h14\" />\n </svg>\n ),\n }\n\n return (\n <span\n className={`${baseClasses} ${directionClasses[direction]}${className ? ` ${className}` : ''}`}\n title={title}\n >\n {icons[direction]}\n {formatPercentageChange(value, unit)}\n </span>\n )\n}\n\nexport const DeltaBadge = BadgeDelta\n\nexport function KpiCard({\n title,\n value,\n trend,\n comparisonLabel,\n loading,\n error,\n formatValue = defaultFormatValue,\n prefix = '',\n suffix = '',\n className = '',\n headerAction,\n footer,\n titleClassName,\n}: KpiCardProps) {\n const hasWrapper = !!title\n const wrapperClass = hasWrapper ? `rounded-lg border bg-card p-4 ${className}` : className\n\n const headerRow = (title || headerAction) ? (\n <div className=\"flex items-center justify-between gap-2 mb-2\">\n {title && <p className={titleClassName ?? 'text-sm font-medium text-muted-foreground'}>{title}</p>}\n {headerAction}\n </div>\n ) : null\n\n if (error) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <p className=\"text-sm text-destructive\">{error}</p>\n </div>\n )\n }\n\n if (loading) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <div className=\"flex items-center justify-center py-4\">\n <Spinner className=\"h-6 w-6 text-muted-foreground\" />\n </div>\n </div>\n )\n }\n\n if (value === null) {\n return (\n <div className={wrapperClass}>\n {headerRow}\n <p className=\"text-2xl sm:text-3xl font-semibold tracking-tight text-card-foreground\">--</p>\n {footer != null && <div className=\"mt-3\">{footer}</div>}\n </div>\n )\n }\n\n return (\n <div className={wrapperClass}>\n {headerRow}\n <div className=\"flex items-baseline gap-3\">\n <p className=\"flex items-baseline gap-1.5 text-2xl sm:text-3xl font-semibold tracking-tight text-card-foreground\">\n <span>{prefix}{formatValue(value)}</span>\n {suffix ? <span className=\"text-sm font-medium text-muted-foreground\">{suffix}</span> : null}\n </p>\n {trend && (\n <BadgeDelta direction={trend.direction} value={trend.value} />\n )}\n </div>\n {comparisonLabel && (\n <p className=\"mt-1 text-xs text-muted-foreground\">{comparisonLabel}</p>\n )}\n {footer != null && <div className=\"mt-3\">{footer}</div>}\n </div>\n )\n}\n\nexport default KpiCard\n"],
|
|
5
|
+
"mappings": ";AA8DQ,cAgBJ,YAhBI;AA3DR,SAAS,eAAe;AAuBxB,SAAS,mBAAmB,OAAuB;AACjD,MAAI,KAAK,IAAI,KAAK,KAAK,KAAW;AAChC,WAAO,IAAI,QAAQ,KAAW,QAAQ,CAAC,CAAC;AAAA,EAC1C;AACA,MAAI,KAAK,IAAI,KAAK,KAAK,KAAO;AAC5B,WAAO,IAAI,QAAQ,KAAO,QAAQ,CAAC,CAAC;AAAA,EACtC;AACA,SAAO,MAAM,eAAe,QAAW,EAAE,uBAAuB,EAAE,CAAC;AACrE;AAEA,SAAS,uBAAuB,OAAe,OAAe,KAAa;AACzE,QAAM,MAAM,KAAK,IAAI,KAAK;AAC1B,QAAM,YAAY,OAAO,UAAU,GAAG,IAAI,OAAO,GAAG,IAAI,IAAI,QAAQ,CAAC;AACrE,SAAO,GAAG,SAAS,GAAG,IAAI;AAC5B;AAUA,SAAS,WAAW,EAAE,WAAW,OAAO,OAAO,KAAK,YAAY,IAAI,QAAQ,8BAA8B,GAAoB;AAC5H,QAAM,cAAc;AAEpB,QAAM,mBAAmB;AAAA,IACvB,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,WAAW;AAAA,EACb;AAEA,QAAM,QAAQ;AAAA,IACZ,IACE,oBAAC,SAAI,WAAU,WAAU,MAAK,QAAO,SAAQ,aAAY,QAAO,gBAAe,aAAa,GAC1F,8BAAC,UAAK,eAAc,SAAQ,gBAAe,S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8BAAC,WAAQ,WAAU,iCAAgC,GACrD;AAAA,OACF;AAAA,EAEJ;AAEA,MAAI,UAAU,MAAM;AAClB,WACE,qBAAC,SAAI,WAAW,cACb;AAAA;AAAA,MACD,oBAAC,OAAE,WAAU,0EAAyE,gBAAE;AAAA,MACvF,UAAU,QAAQ,oBAAC,SAAI,WAAU,QAAQ,kBAAO;AAAA,OACnD;AAAA,EAEJ;AAEA,SACE,qBAAC,SAAI,WAAW,cACb;AAAA;AAAA,IACD,qBAAC,SAAI,WAAU,6BACb;AAAA,2BAAC,OAAE,WAAU,sGACX;AAAA,6BAAC,UAAM;AAAA;AAAA,UAAQ,YAAY,KAAK;AAAA,WAAE;AAAA,QACjC,SAAS,oBAAC,UAAK,WAAU,6CAA6C,kBAAO,IAAU;AAAA,SAC1F;AAAA,MACC,SACC,oBAAC,cAAW,WAAW,MAAM,WAAW,OAAO,MAAM,OAAO;AAAA,OAEhE;AAAA,IACC,mBACC,oBAAC,OAAE,WAAU,sCAAsC,2BAAgB;AAAA,IAEpE,UAAU,QAAQ,oBAAC,SAAI,WAAU,QAAQ,kBAAO;AAAA,KACnD;AAEJ;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -193,10 +193,9 @@ function ComboboxInput({
|
|
|
193
193
|
}, [value, knownLabelValues, coveredOptionValues, eagerResolveLabel, loadSuggestions]);
|
|
194
194
|
React.useEffect(() => {
|
|
195
195
|
const option = optionMap.get(value);
|
|
196
|
-
|
|
197
|
-
if (document.activeElement === inputRef.current && (userTypedRef.current || !hasRealLabel)) return;
|
|
196
|
+
if (document.activeElement === inputRef.current && (userTypedRef.current || !coveredOptionValues.has(value))) return;
|
|
198
197
|
setInput(option?.label ?? value ?? "");
|
|
199
|
-
}, [value, optionMap]);
|
|
198
|
+
}, [value, optionMap, coveredOptionValues]);
|
|
200
199
|
const selectValue = React.useCallback(
|
|
201
200
|
(nextValue) => {
|
|
202
201
|
if (disabled) return;
|
|
@@ -238,7 +237,7 @@ function ComboboxInput({
|
|
|
238
237
|
if (!allowCustomValues) {
|
|
239
238
|
setShowSuggestions(false);
|
|
240
239
|
const currentOption = optionMap.get(value);
|
|
241
|
-
if (currentOption &&
|
|
240
|
+
if (currentOption && coveredOptionValues.has(value)) {
|
|
242
241
|
setInput(currentOption.label);
|
|
243
242
|
} else if (!value) {
|
|
244
243
|
setInput("");
|
|
@@ -247,7 +246,7 @@ function ComboboxInput({
|
|
|
247
246
|
}
|
|
248
247
|
selectValue(raw);
|
|
249
248
|
},
|
|
250
|
-
[allowCustomValues, clearable, disabled, findOptionForInput, optionMap, selectValue, value]
|
|
249
|
+
[allowCustomValues, clearable, coveredOptionValues, disabled, findOptionForInput, optionMap, selectValue, value]
|
|
251
250
|
);
|
|
252
251
|
const handleClear = React.useCallback(() => {
|
|
253
252
|
if (disabled) return;
|
|
@@ -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 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,QAAS,QAAO;AACrB,aAAO,EAAE,OAAO,SAAS,OAAO,QAAQ;AAAA,IAC1C;AACA,UAAM,QAAQ,OAAO,OAAO,UAAU,WAAW,OAAO,MAAM,KAAK,IAAI;AACvE,QAAI,CAAC,MAAO,QAAO;AACnB,WAAO;AAAA,MACL;AAAA,MACA,OAAO,OAAO,OAAO,KAAK,KAAK;AAAA,MAC/B,aAAa,OAAO,eAAe;AAAA,IACrC;AAAA,EACF,CAAC,EACA,OAAO,CAAC,WAAqC,CAAC,CAAC,MAAM;AAC1D;AAEA,SAAS,gBAAgB,GAAqB,GAA8B;AAC1E,MAAI,EAAE,WAAW,EAAE,OAAQ,QA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BAAoB,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 if (document.activeElement === inputRef.current && (userTypedRef.current || !coveredOptionValues.has(value))) return\n setInput(option?.label ?? value ?? '')\n }, [value, optionMap, coveredOptionValues])\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 && coveredOptionValues.has(value)) {\n setInput(currentOption.label)\n } else if (!value) {\n setInput('')\n }\n return\n }\n selectValue(raw)\n },\n [allowCustomValues, clearable, coveredOptionValues, 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": ";AA6aQ,SAKE,KALF;AA3aR,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,CAAC,MAAO,QAAO;AACnB,WAAO;AAAA,MACL;AAAA,MACA,OAAO,OAAO,OAAO,KAAK,KAAK;AAAA,MAC/B,aAAa,OAAO,eAAe;AAAA,IACrC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AAU,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;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -47,7 +47,7 @@ function LookupSelect({
|
|
|
47
47
|
const resolvedStartTypingLabel = startTypingLabel ?? t("ui.lookupSelect.startTyping", "Start typing to search.");
|
|
48
48
|
const resolvedMinQueryHintLabel = minQueryHintLabel ?? t(
|
|
49
49
|
"ui.lookupSelect.minQueryHint",
|
|
50
|
-
"
|
|
50
|
+
"Minimum characters to search: {minQuery}. You can also paste an id.",
|
|
51
51
|
{ minQuery: String(minQuery) }
|
|
52
52
|
);
|
|
53
53
|
const [query, setQuery] = React.useState("");
|
|
@@ -427,7 +427,7 @@ function LookupSelect({
|
|
|
427
427
|
]
|
|
428
428
|
}
|
|
429
429
|
)
|
|
430
|
-
) : hasTyped ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: resolvedMinQueryHintLabel }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: resolvedStartTypingLabel }),
|
|
430
|
+
) : hasTyped && minQuery > 0 ? /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: resolvedMinQueryHintLabel }) : /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: resolvedStartTypingLabel }),
|
|
431
431
|
error ? /* @__PURE__ */ jsx("p", { className: "text-xs text-status-error-text", role: "alert", children: resolvedEmptyLabel }) : null
|
|
432
432
|
] });
|
|
433
433
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/backend/inputs/LookupSelect.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { Check, Loader2, Search, 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 { cn } from '@open-mercato/shared/lib/utils'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('ui').child({ component: 'LookupSelect' })\n\nexport type LookupSelectItem = {\n id: string\n title: string\n subtitle?: string | null\n badge?: string | null\n icon?: React.ReactNode\n disabled?: boolean\n rightLabel?: string | null\n description?: string | null\n}\n\ntype LookupSelectProps = {\n value: string | null\n onChange: (next: string | null) => void\n fetchItems?: (query: string) => Promise<LookupSelectItem[]>\n fetchOptions?: (query?: string) => Promise<LookupSelectItem[]>\n options?: LookupSelectItem[]\n minQuery?: number\n actionSlot?: React.ReactNode\n onReady?: (controls: { setQuery: (value: string) => void }) => void\n searchPlaceholder?: string\n placeholder?: string\n clearLabel?: string\n emptyLabel?: string\n loadingLabel?: string\n selectLabel?: string\n selectedLabel?: string\n minQueryHintLabel?: string\n startTypingLabel?: string\n selectedHintLabel?: (id: string) => string\n disabled?: boolean\n loading?: boolean\n defaultOpen?: boolean\n}\n\nfunction keepSelectedItem(\n result: LookupSelectItem[],\n selected: LookupSelectItem | null,\n value: string | null,\n): LookupSelectItem[] {\n if (!value || !selected || selected.id !== value) return result\n if (result.some((item) => item.id === value)) return result\n return [selected, ...result]\n}\n\nexport function LookupSelect({\n value,\n onChange,\n fetchItems,\n fetchOptions,\n options,\n minQuery = 2,\n actionSlot,\n onReady,\n placeholder,\n searchPlaceholder,\n clearLabel,\n emptyLabel,\n loadingLabel,\n selectLabel,\n selectedLabel,\n minQueryHintLabel,\n startTypingLabel,\n selectedHintLabel,\n disabled = false,\n loading: loadingProp = false,\n defaultOpen = false,\n}: LookupSelectProps) {\n const t = useT()\n const resolvedSearchPlaceholder = searchPlaceholder ?? placeholder ?? t('ui.lookupSelect.searchPlaceholder', 'Search\u2026')\n const resolvedClearLabel = clearLabel ?? t('ui.lookupSelect.clearSelection', 'Clear selection')\n const resolvedEmptyLabel = emptyLabel ?? t('ui.lookupSelect.noResults', 'No results')\n const resolvedLoadingLabel = loadingLabel ?? t('ui.lookupSelect.searching', 'Searching\u2026')\n const resolvedSelectLabel = selectLabel ?? t('ui.lookupSelect.select', 'Select')\n const resolvedSelectedLabel = selectedLabel ?? t('ui.lookupSelect.selected', 'Selected')\n const resolvedChangeLabel = t('ui.lookupSelect.change', 'Change')\n const resolvedStartTypingLabel = startTypingLabel ?? t('ui.lookupSelect.startTyping', 'Start typing to search.')\n const resolvedMinQueryHintLabel = minQueryHintLabel ?? t(\n 'ui.lookupSelect.minQueryHint',\n 'Type at least {minQuery} characters or paste an id to search.',\n { minQuery: String(minQuery) }\n )\n const [query, setQuery] = React.useState('')\n const [items, setItems] = React.useState<LookupSelectItem[]>(options ?? [])\n const [loading, setLoading] = React.useState(false)\n // Escape collapses the list without clearing the selection. Derived state is not\n // enough here: Escape empties the query but the fetched `items` linger, so the\n // list would stay open and the collapsed summary \u2014 the branch that keeps a raw\n // record id out of the DOM (TC-EUDR-013) \u2014 would never render.\n // A value that is already there when the lookup mounts (hydrated, or seeded by the host,\n // e.g. the deal owner defaulting to the current user) is a finished selection: it starts\n // collapsed on the summary instead of an open list with one row checked (#5109).\n // `defaultOpen` keeps the list on screen regardless (pickers that browse a short list).\n const [collapsed, setCollapsed] = React.useState(() => Boolean(value) && !defaultOpen)\n const [hasTyped, setHasTyped] = React.useState(defaultOpen)\n const [error, setError] = React.useState<string | null>(null)\n const [fetchKey, setFetchKey] = React.useState(0)\n const [activeIndex, setActiveIndex] = React.useState(-1)\n const [selectedItem, setSelectedItem] = React.useState<LookupSelectItem | null>(null)\n const listboxId = React.useId()\n const fetchItemsRef = React.useRef(fetchItems ?? fetchOptions)\n const setQueryRef = React.useRef(setQuery)\n const onReadyRef = React.useRef(onReady)\n const optionsWasArrayRef = React.useRef(Array.isArray(options))\n const valueRef = React.useRef(value)\n const selectedItemRef = React.useRef<LookupSelectItem | null>(null)\n const inputRef = React.useRef<HTMLInputElement>(null)\n const pendingCommitRef = React.useRef<string | null>(null)\n const changeButtonRef = React.useRef<HTMLButtonElement>(null)\n const focusSummaryRef = React.useRef(false)\n\n React.useEffect(() => {\n fetchItemsRef.current = fetchItems ?? fetchOptions\n }, [fetchItems, fetchOptions])\n\n React.useEffect(() => {\n valueRef.current = value\n }, [value])\n\n React.useEffect(() => {\n onReadyRef.current = onReady\n }, [onReady])\n\n React.useEffect(() => {\n if (Array.isArray(options)) {\n optionsWasArrayRef.current = true\n setItems(options)\n } else if (optionsWasArrayRef.current) {\n optionsWasArrayRef.current = false\n setFetchKey((k) => k + 1)\n }\n }, [options])\n\n React.useEffect(() => {\n setQueryRef.current = setQuery\n if (onReadyRef.current) onReadyRef.current({ setQuery })\n }, [setQuery])\n\n // A set `value` keeps the lookup live: the list (or, once collapsed after a\n // pick, the summary) is where the selection, its checkmark and the clear control\n // render, so a selection is never invisible. This used to also require an\n // `options` prop, which left every caller that resolves its selection through\n // `fetchItems` blind whenever minQuery kept the list shut.\n const shouldSearch = defaultOpen || query.trim().length >= minQuery || Boolean(value)\n\n React.useEffect(() => {\n setActiveIndex(-1)\n }, [items])\n\n const optionDomId = React.useCallback(\n (index: number) => `${listboxId}-option-${index}`,\n [listboxId],\n )\n\n const isInteractiveItem = React.useCallback(\n (item: LookupSelectItem) => !disabled && (!item.disabled || value === item.id),\n [disabled, value],\n )\n\n const moveActiveIndex = React.useCallback((direction: 1 | -1) => {\n setActiveIndex((current) => {\n if (!items.length) return -1\n let next = current\n for (let step = 0; step < items.length; step += 1) {\n next = (next + direction + items.length) % items.length\n if (isInteractiveItem(items[next])) return next\n }\n return current\n })\n }, [isInteractiveItem, items])\n\n React.useEffect(() => {\n if (activeIndex < 0) return\n const activeElement = typeof document !== 'undefined'\n ? document.getElementById(optionDomId(activeIndex))\n : null\n if (typeof activeElement?.scrollIntoView === 'function') {\n activeElement.scrollIntoView({ block: 'nearest' })\n }\n }, [activeIndex, optionDomId])\n\n const listboxVisible = shouldSearch && !disabled && !collapsed\n\n const finishSelection = React.useCallback(() => {\n pendingCommitRef.current = null\n focusSummaryRef.current = true\n setCollapsed(true)\n setQuery('')\n setHasTyped(false)\n setActiveIndex(-1)\n }, [])\n\n // Picking a result ends the interaction (#6196): the list closes and the collapsed\n // summary takes over, but only once the parent has adopted the id. A host that keeps\n // `value` at null and collects picks itself (multi-add pickers) keeps browsing.\n const commitSelection = React.useCallback((item: LookupSelectItem) => {\n selectedItemRef.current = item\n setSelectedItem(item)\n if (valueRef.current === item.id) {\n finishSelection()\n return\n }\n pendingCommitRef.current = item.id\n onChange(item.id)\n }, [finishSelection, onChange])\n\n React.useEffect(() => {\n if (pendingCommitRef.current) {\n if (value === pendingCommitRef.current) finishSelection()\n else if (value) pendingCommitRef.current = null\n return\n }\n // The host adopted a value the user never picked here (seeded after mount): treat it\n // like a finished pick as long as the user is not mid-search.\n if (value && !hasTyped && query.length === 0) setCollapsed(true)\n }, [finishSelection, hasTyped, query, value])\n\n // The search box is not in the DOM while the summary row stands in for it, so the focus\n // moves once the box has mounted again.\n const focusAfterReopenRef = React.useRef(false)\n const reopenList = React.useCallback(() => {\n focusAfterReopenRef.current = true\n focusSummaryRef.current = false\n setCollapsed(false)\n }, [])\n const clearSelection = React.useCallback(() => {\n focusAfterReopenRef.current = true\n focusSummaryRef.current = false\n onChange(null)\n }, [onChange])\n\n // With nothing selected there is no summary to collapse onto, so the browse list comes back.\n React.useEffect(() => {\n if (!value) setCollapsed(false)\n }, [value])\n\n const handleInputKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!listboxVisible) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n moveActiveIndex(1)\n return\n }\n if (event.key === 'ArrowUp') {\n event.preventDefault()\n moveActiveIndex(-1)\n return\n }\n if (event.key === 'Enter') {\n if (activeIndex < 0 || activeIndex >= items.length) return\n const item = items[activeIndex]\n if (!isInteractiveItem(item)) return\n event.preventDefault()\n commitSelection(item)\n return\n }\n if (event.key === 'Escape') {\n if (query.length === 0 && activeIndex < 0) return\n event.preventDefault()\n event.stopPropagation()\n setQuery('')\n setActiveIndex(-1)\n focusSummaryRef.current = Boolean(value)\n setCollapsed(true)\n }\n }, [activeIndex, commitSelection, items, isInteractiveItem, listboxVisible, moveActiveIndex, query, value])\n React.useEffect(() => {\n if (disabled) {\n setItems(options ?? [])\n setLoading(false)\n return\n }\n let cancelled = false\n let timer: ReturnType<typeof setTimeout> | null = null\n if (!shouldSearch) {\n setItems(options ?? [])\n setLoading(false)\n setError(null)\n return () => { cancelled = true }\n }\n setLoading(true)\n setError(null)\n timer = setTimeout(() => {\n const requestId = Date.now()\n const fetcher = fetchItemsRef.current\n const loader = fetcher ?? (() => Promise.resolve(options ?? []))\n const trimmedQuery = query.trim()\n loader(trimmedQuery)\n .then((result) => {\n if (cancelled) return\n // A set `value` opens the list with an empty query, and that browse\n // fetch returns an arbitrary first page. Without this the stored\n // selection vanished from the list whenever it fell outside that page,\n // while the form still held its id. A typed query stays a pure search.\n setItems(\n trimmedQuery\n ? result\n : keepSelectedItem(result, selectedItemRef.current, valueRef.current),\n )\n })\n .catch((err) => {\n if (cancelled) return\n logger.error('Failed to fetch lookup items', { err })\n setError('error')\n })\n .finally(() => {\n if (!cancelled) setLoading(false)\n })\n return requestId\n }, 220)\n return () => {\n cancelled = true\n if (timer) clearTimeout(timer)\n }\n }, [query, shouldSearch, fetchKey])\n\n React.useEffect(() => {\n if (!value) {\n selectedItemRef.current = null\n setSelectedItem(null)\n return\n }\n const match = items.find((item) => item.id === value)\n if (match) {\n selectedItemRef.current = match\n setSelectedItem(match)\n }\n }, [items, value])\n\n /*\n * The collapsed summary needs a label it can trust: the consumer's\n * `selectedHintLabel` when it resolves to a name, otherwise the title of the\n * item that was actually fetched or picked. A resolver that falls back to the\n * id (`known.get(id) ?? id`) or embeds it (\"Selected customer: <id>\") is\n * treated as unresolved \u2014 a record id must never reach the DOM as a label.\n * With neither (a hydrated value whose lookup returned nothing) there is no\n * summary, so consumers rendering their own label never get a second one.\n */\n const collapsedSelectionLabel = React.useMemo(() => {\n if (!value) return null\n const hinted = selectedHintLabel?.(value)\n if (hinted && hinted !== value && !hinted.includes(value)) return hinted\n const fetchedTitle = selectedItem && selectedItem.id === value ? selectedItem.title : null\n return fetchedTitle && fetchedTitle !== value ? fetchedTitle : null\n }, [selectedHintLabel, selectedItem, value])\n const collapsedSelectionSubtitle = selectedItem && selectedItem.id === value ? selectedItem.subtitle ?? null : null\n // Once collapsed on a resolved selection the summary row IS the control: the search box\n // comes back only when the user asks to change the pick, so the field stays one row tall\n // and fits a narrow column (#5109).\n const showSummaryOnly = collapsed && Boolean(collapsedSelectionLabel)\n\n // The search box and the summary row replace each other, so whichever held the focus is\n // gone from the DOM: keyboard users continue on the control that took its place.\n React.useEffect(() => {\n if (showSummaryOnly) {\n if (!focusSummaryRef.current) return\n focusSummaryRef.current = false\n changeButtonRef.current?.focus()\n return\n }\n if (!focusAfterReopenRef.current) return\n focusAfterReopenRef.current = false\n inputRef.current?.focus()\n }, [showSummaryOnly])\n\n return (\n <div className=\"space-y-3\">\n {showSummaryOnly ? null : (\n <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3\">\n <div className=\"relative flex-1\">\n <Search className=\"pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n 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\"\n value={query}\n onChange={(event) => {\n setQuery(event.target.value)\n setHasTyped(true)\n setCollapsed(false)\n }}\n onKeyDown={handleInputKeyDown}\n placeholder={resolvedSearchPlaceholder}\n disabled={disabled}\n role=\"combobox\"\n aria-expanded={listboxVisible}\n aria-controls={listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant={activeIndex >= 0 ? optionDomId(activeIndex) : undefined}\n />\n </div>\n {actionSlot && !disabled ? <div className=\"sm:self-start\">{actionSlot}</div> : null}\n </div>\n )}\n {/*\n * `shouldSearch` decides whether to FETCH; this decides whether to RENDER a\n * list. They differ for a set value whose lookup comes back empty: develop's\n * #5248 work needs the list (and its selected option) whenever items exist,\n * while the collapsed summary \u2014 which keeps a selection visible after the\n * search box reverts to its placeholder, and keeps a raw record id out of the\n * DOM (TC-EUDR-013) \u2014 is only reachable when they do not. Falling through on\n * an empty result satisfies both. A non-empty query still renders the list so\n * its spinner and empty-state are reachable while the user is searching.\n */}\n {shouldSearch && !collapsed && (items.length > 0 || query.trim().length > 0) ? (\n <div className=\"space-y-2\">\n {loading || loadingProp ? (\n <div className=\"flex items-center gap-2 text-sm text-muted-foreground\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n {resolvedLoadingLabel}\n </div>\n ) : null}\n {!loading && !loadingProp && !items.length ? (\n <p className=\"text-xs text-muted-foreground\">{resolvedEmptyLabel}</p>\n ) : null}\n <div\n id={listboxId}\n role=\"listbox\"\n className=\"flex flex-col gap-1.5 max-h-80 overflow-y-auto -mx-0.5 px-0.5 py-0.5\"\n >\n {items.map((item, index) => {\n const isSelected = value === item.id\n const isInteractive = isInteractiveItem(item)\n const isActive = index === activeIndex\n return (\n <div\n key={item.id}\n id={optionDomId(index)}\n className={cn(\n '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',\n isInteractive ? 'cursor-pointer' : 'cursor-not-allowed opacity-60',\n isSelected\n ? 'border-accent-indigo bg-accent-indigo/5'\n : 'border-input bg-card hover:border-foreground/20 hover:bg-muted/30',\n isActive && !isSelected ? 'border-foreground/20 bg-muted/30 shadow-sm' : null\n )}\n role=\"option\"\n tabIndex={isInteractive ? 0 : -1}\n onClick={() => {\n if (!isInteractive) return\n commitSelection(item)\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n if (!isInteractive) return\n commitSelection(item)\n }\n }}\n aria-selected={isSelected}\n aria-disabled={isInteractive ? undefined : true}\n title={isSelected ? resolvedSelectedLabel : isInteractive ? resolvedSelectLabel : undefined}\n >\n {item.icon ? (\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden [&>svg]:size-5 [&_svg]:text-muted-foreground\">\n {item.icon}\n </div>\n ) : (\n <div className={cn(\n 'flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md border transition-colors',\n isSelected\n ? 'border-accent-indigo/40 bg-accent-indigo/10 text-accent-indigo'\n : 'border-input bg-muted text-muted-foreground group-hover:border-foreground/20'\n )}>\n <span className=\"text-sm font-medium uppercase\">{item.title.slice(0, 1)}</span>\n </div>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"truncate text-sm font-medium text-foreground\">{item.title}</div>\n {item.rightLabel ? (\n <div className=\"shrink-0 text-overline font-medium uppercase tracking-wider text-muted-foreground\">\n {item.rightLabel}\n </div>\n ) : null}\n </div>\n {item.subtitle ? (\n <div className=\"text-xs text-muted-foreground truncate\">{item.subtitle}</div>\n ) : null}\n {item.description ? (\n <div className=\"text-xs text-muted-foreground/70 truncate\">{item.description}</div>\n ) : null}\n </div>\n <div className=\"flex shrink-0 items-center justify-center gap-1.5\">\n {isSelected ? (\n <>\n <span className=\"text-xs font-medium text-foreground\">{resolvedSelectedLabel}</span>\n <Check className=\"size-4 text-accent-indigo\" aria-hidden=\"true\" />\n </>\n ) : (\n <div className=\"size-5\" aria-hidden=\"true\" />\n )}\n </div>\n </div>\n )\n })}\n </div>\n {value && !disabled ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"w-fit gap-1 text-sm font-normal\"\n onClick={() => onChange(null)}\n >\n <X className=\"h-4 w-4\" />\n {resolvedClearLabel}\n </Button>\n ) : null}\n </div>\n ) : collapsedSelectionLabel ? (\n /*\n * The selection as a single row: the name is the control that reopens the\n * search (Change), the icon clears. No second search box above it.\n */\n <div\n className={cn(\n 'flex h-9 items-center gap-1 rounded-lg border border-accent-indigo bg-accent-indigo/5 pl-1 pr-1',\n disabled && 'border-border-disabled bg-bg-disabled',\n )}\n data-testid=\"lookup-select-selected\"\n >\n {disabled ? (\n <span className=\"flex h-7 min-w-0 flex-1 items-center gap-2 px-2 text-muted-foreground\">\n <Check className=\"size-4 shrink-0\" aria-hidden=\"true\" />\n <span className=\"truncate text-sm\">{collapsedSelectionLabel}</span>\n {collapsedSelectionSubtitle ? (\n <span className=\"hidden truncate text-xs sm:inline\">{collapsedSelectionSubtitle}</span>\n ) : null}\n </span>\n ) : (\n <Button\n ref={changeButtonRef}\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n 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\"\n onClick={reopenList}\n aria-label={resolvedChangeLabel}\n title={resolvedChangeLabel}\n >\n <Check className=\"size-4 shrink-0 text-accent-indigo\" aria-hidden=\"true\" />\n <span className=\"truncate text-sm text-foreground\">{collapsedSelectionLabel}</span>\n {collapsedSelectionSubtitle ? (\n <span className=\"hidden truncate text-xs text-muted-foreground sm:inline\">{collapsedSelectionSubtitle}</span>\n ) : null}\n </Button>\n )}\n {disabled ? null : (\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"shrink-0 text-muted-foreground hover:bg-accent-indigo/10 hover:text-accent-indigo\"\n onClick={clearSelection}\n aria-label={resolvedClearLabel}\n title={resolvedClearLabel}\n >\n <X className=\"size-4\" aria-hidden=\"true\" />\n </IconButton>\n )}\n </div>\n ) : hasTyped ? (\n <p className=\"text-xs text-muted-foreground\">\n {resolvedMinQueryHintLabel}\n </p>\n ) : (\n <p className=\"text-xs text-muted-foreground\">{resolvedStartTypingLabel}</p>\n )}\n {error ? <p className=\"text-xs text-status-error-text\" role=\"alert\">{resolvedEmptyLabel}</p> : null}\n </div>\n )\n}\n"],
|
|
5
|
-
"mappings": ";AA6XQ,SAmHc,UAlHZ,KADF;AA3XR,YAAY,WAAW;AACvB,SAAS,OAAO,SAAS,QAAQ,SAAS;AAC1C,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,IAAI,EAAE,MAAM,EAAE,WAAW,eAAe,CAAC;AAqCrE,SAAS,iBACP,QACA,UACA,OACoB;AACpB,MAAI,CAAC,SAAS,CAAC,YAAY,SAAS,OAAO,MAAO,QAAO;AACzD,MAAI,OAAO,KAAK,CAAC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AU;AAAA,gBACV,SAAS;AAAA,gBACT,cAAY;AAAA,gBACZ,OAAO;AAAA,gBAEP,8BAAC,KAAE,WAAU,UAAS,eAAY,QAAO;AAAA;AAAA,YAC3C;AAAA;AAAA;AAAA,MAEJ;AAAA,QACE,WACF,oBAAC,OAAE,WAAU,iCACV,qCACH,IAEA,oBAAC,OAAE,WAAU,iCAAiC,oCAAyB;AAAA,IAExE,QAAQ,oBAAC,OAAE,WAAU,kCAAiC,MAAK,SAAS,8BAAmB,IAAO;AAAA,KACjG;AAEJ;",
|
|
4
|
+
"sourcesContent": ["\"use client\"\n\nimport * as React from 'react'\nimport { Check, Loader2, Search, 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 { cn } from '@open-mercato/shared/lib/utils'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\n\nconst logger = createLogger('ui').child({ component: 'LookupSelect' })\n\nexport type LookupSelectItem = {\n id: string\n title: string\n subtitle?: string | null\n badge?: string | null\n icon?: React.ReactNode\n disabled?: boolean\n rightLabel?: string | null\n description?: string | null\n}\n\ntype LookupSelectProps = {\n value: string | null\n onChange: (next: string | null) => void\n fetchItems?: (query: string) => Promise<LookupSelectItem[]>\n fetchOptions?: (query?: string) => Promise<LookupSelectItem[]>\n options?: LookupSelectItem[]\n minQuery?: number\n actionSlot?: React.ReactNode\n onReady?: (controls: { setQuery: (value: string) => void }) => void\n searchPlaceholder?: string\n placeholder?: string\n clearLabel?: string\n emptyLabel?: string\n loadingLabel?: string\n selectLabel?: string\n selectedLabel?: string\n minQueryHintLabel?: string\n startTypingLabel?: string\n selectedHintLabel?: (id: string) => string\n disabled?: boolean\n loading?: boolean\n defaultOpen?: boolean\n}\n\nfunction keepSelectedItem(\n result: LookupSelectItem[],\n selected: LookupSelectItem | null,\n value: string | null,\n): LookupSelectItem[] {\n if (!value || !selected || selected.id !== value) return result\n if (result.some((item) => item.id === value)) return result\n return [selected, ...result]\n}\n\nexport function LookupSelect({\n value,\n onChange,\n fetchItems,\n fetchOptions,\n options,\n minQuery = 2,\n actionSlot,\n onReady,\n placeholder,\n searchPlaceholder,\n clearLabel,\n emptyLabel,\n loadingLabel,\n selectLabel,\n selectedLabel,\n minQueryHintLabel,\n startTypingLabel,\n selectedHintLabel,\n disabled = false,\n loading: loadingProp = false,\n defaultOpen = false,\n}: LookupSelectProps) {\n const t = useT()\n const resolvedSearchPlaceholder = searchPlaceholder ?? placeholder ?? t('ui.lookupSelect.searchPlaceholder', 'Search\u2026')\n const resolvedClearLabel = clearLabel ?? t('ui.lookupSelect.clearSelection', 'Clear selection')\n const resolvedEmptyLabel = emptyLabel ?? t('ui.lookupSelect.noResults', 'No results')\n const resolvedLoadingLabel = loadingLabel ?? t('ui.lookupSelect.searching', 'Searching\u2026')\n const resolvedSelectLabel = selectLabel ?? t('ui.lookupSelect.select', 'Select')\n const resolvedSelectedLabel = selectedLabel ?? t('ui.lookupSelect.selected', 'Selected')\n const resolvedChangeLabel = t('ui.lookupSelect.change', 'Change')\n const resolvedStartTypingLabel = startTypingLabel ?? t('ui.lookupSelect.startTyping', 'Start typing to search.')\n const resolvedMinQueryHintLabel = minQueryHintLabel ?? t(\n 'ui.lookupSelect.minQueryHint',\n 'Minimum characters to search: {minQuery}. You can also paste an id.',\n { minQuery: String(minQuery) }\n )\n const [query, setQuery] = React.useState('')\n const [items, setItems] = React.useState<LookupSelectItem[]>(options ?? [])\n const [loading, setLoading] = React.useState(false)\n // Escape collapses the list without clearing the selection. Derived state is not\n // enough here: Escape empties the query but the fetched `items` linger, so the\n // list would stay open and the collapsed summary \u2014 the branch that keeps a raw\n // record id out of the DOM (TC-EUDR-013) \u2014 would never render.\n // A value that is already there when the lookup mounts (hydrated, or seeded by the host,\n // e.g. the deal owner defaulting to the current user) is a finished selection: it starts\n // collapsed on the summary instead of an open list with one row checked (#5109).\n // `defaultOpen` keeps the list on screen regardless (pickers that browse a short list).\n const [collapsed, setCollapsed] = React.useState(() => Boolean(value) && !defaultOpen)\n const [hasTyped, setHasTyped] = React.useState(defaultOpen)\n const [error, setError] = React.useState<string | null>(null)\n const [fetchKey, setFetchKey] = React.useState(0)\n const [activeIndex, setActiveIndex] = React.useState(-1)\n const [selectedItem, setSelectedItem] = React.useState<LookupSelectItem | null>(null)\n const listboxId = React.useId()\n const fetchItemsRef = React.useRef(fetchItems ?? fetchOptions)\n const setQueryRef = React.useRef(setQuery)\n const onReadyRef = React.useRef(onReady)\n const optionsWasArrayRef = React.useRef(Array.isArray(options))\n const valueRef = React.useRef(value)\n const selectedItemRef = React.useRef<LookupSelectItem | null>(null)\n const inputRef = React.useRef<HTMLInputElement>(null)\n const pendingCommitRef = React.useRef<string | null>(null)\n const changeButtonRef = React.useRef<HTMLButtonElement>(null)\n const focusSummaryRef = React.useRef(false)\n\n React.useEffect(() => {\n fetchItemsRef.current = fetchItems ?? fetchOptions\n }, [fetchItems, fetchOptions])\n\n React.useEffect(() => {\n valueRef.current = value\n }, [value])\n\n React.useEffect(() => {\n onReadyRef.current = onReady\n }, [onReady])\n\n React.useEffect(() => {\n if (Array.isArray(options)) {\n optionsWasArrayRef.current = true\n setItems(options)\n } else if (optionsWasArrayRef.current) {\n optionsWasArrayRef.current = false\n setFetchKey((k) => k + 1)\n }\n }, [options])\n\n React.useEffect(() => {\n setQueryRef.current = setQuery\n if (onReadyRef.current) onReadyRef.current({ setQuery })\n }, [setQuery])\n\n // A set `value` keeps the lookup live: the list (or, once collapsed after a\n // pick, the summary) is where the selection, its checkmark and the clear control\n // render, so a selection is never invisible. This used to also require an\n // `options` prop, which left every caller that resolves its selection through\n // `fetchItems` blind whenever minQuery kept the list shut.\n const shouldSearch = defaultOpen || query.trim().length >= minQuery || Boolean(value)\n\n React.useEffect(() => {\n setActiveIndex(-1)\n }, [items])\n\n const optionDomId = React.useCallback(\n (index: number) => `${listboxId}-option-${index}`,\n [listboxId],\n )\n\n const isInteractiveItem = React.useCallback(\n (item: LookupSelectItem) => !disabled && (!item.disabled || value === item.id),\n [disabled, value],\n )\n\n const moveActiveIndex = React.useCallback((direction: 1 | -1) => {\n setActiveIndex((current) => {\n if (!items.length) return -1\n let next = current\n for (let step = 0; step < items.length; step += 1) {\n next = (next + direction + items.length) % items.length\n if (isInteractiveItem(items[next])) return next\n }\n return current\n })\n }, [isInteractiveItem, items])\n\n React.useEffect(() => {\n if (activeIndex < 0) return\n const activeElement = typeof document !== 'undefined'\n ? document.getElementById(optionDomId(activeIndex))\n : null\n if (typeof activeElement?.scrollIntoView === 'function') {\n activeElement.scrollIntoView({ block: 'nearest' })\n }\n }, [activeIndex, optionDomId])\n\n const listboxVisible = shouldSearch && !disabled && !collapsed\n\n const finishSelection = React.useCallback(() => {\n pendingCommitRef.current = null\n focusSummaryRef.current = true\n setCollapsed(true)\n setQuery('')\n setHasTyped(false)\n setActiveIndex(-1)\n }, [])\n\n // Picking a result ends the interaction (#6196): the list closes and the collapsed\n // summary takes over, but only once the parent has adopted the id. A host that keeps\n // `value` at null and collects picks itself (multi-add pickers) keeps browsing.\n const commitSelection = React.useCallback((item: LookupSelectItem) => {\n selectedItemRef.current = item\n setSelectedItem(item)\n if (valueRef.current === item.id) {\n finishSelection()\n return\n }\n pendingCommitRef.current = item.id\n onChange(item.id)\n }, [finishSelection, onChange])\n\n React.useEffect(() => {\n if (pendingCommitRef.current) {\n if (value === pendingCommitRef.current) finishSelection()\n else if (value) pendingCommitRef.current = null\n return\n }\n // The host adopted a value the user never picked here (seeded after mount): treat it\n // like a finished pick as long as the user is not mid-search.\n if (value && !hasTyped && query.length === 0) setCollapsed(true)\n }, [finishSelection, hasTyped, query, value])\n\n // The search box is not in the DOM while the summary row stands in for it, so the focus\n // moves once the box has mounted again.\n const focusAfterReopenRef = React.useRef(false)\n const reopenList = React.useCallback(() => {\n focusAfterReopenRef.current = true\n focusSummaryRef.current = false\n setCollapsed(false)\n }, [])\n const clearSelection = React.useCallback(() => {\n focusAfterReopenRef.current = true\n focusSummaryRef.current = false\n onChange(null)\n }, [onChange])\n\n // With nothing selected there is no summary to collapse onto, so the browse list comes back.\n React.useEffect(() => {\n if (!value) setCollapsed(false)\n }, [value])\n\n const handleInputKeyDown = React.useCallback((event: React.KeyboardEvent<HTMLInputElement>) => {\n if (!listboxVisible) return\n if (event.key === 'ArrowDown') {\n event.preventDefault()\n moveActiveIndex(1)\n return\n }\n if (event.key === 'ArrowUp') {\n event.preventDefault()\n moveActiveIndex(-1)\n return\n }\n if (event.key === 'Enter') {\n if (activeIndex < 0 || activeIndex >= items.length) return\n const item = items[activeIndex]\n if (!isInteractiveItem(item)) return\n event.preventDefault()\n commitSelection(item)\n return\n }\n if (event.key === 'Escape') {\n if (query.length === 0 && activeIndex < 0) return\n event.preventDefault()\n event.stopPropagation()\n setQuery('')\n setActiveIndex(-1)\n focusSummaryRef.current = Boolean(value)\n setCollapsed(true)\n }\n }, [activeIndex, commitSelection, items, isInteractiveItem, listboxVisible, moveActiveIndex, query, value])\n React.useEffect(() => {\n if (disabled) {\n setItems(options ?? [])\n setLoading(false)\n return\n }\n let cancelled = false\n let timer: ReturnType<typeof setTimeout> | null = null\n if (!shouldSearch) {\n setItems(options ?? [])\n setLoading(false)\n setError(null)\n return () => { cancelled = true }\n }\n setLoading(true)\n setError(null)\n timer = setTimeout(() => {\n const requestId = Date.now()\n const fetcher = fetchItemsRef.current\n const loader = fetcher ?? (() => Promise.resolve(options ?? []))\n const trimmedQuery = query.trim()\n loader(trimmedQuery)\n .then((result) => {\n if (cancelled) return\n // A set `value` opens the list with an empty query, and that browse\n // fetch returns an arbitrary first page. Without this the stored\n // selection vanished from the list whenever it fell outside that page,\n // while the form still held its id. A typed query stays a pure search.\n setItems(\n trimmedQuery\n ? result\n : keepSelectedItem(result, selectedItemRef.current, valueRef.current),\n )\n })\n .catch((err) => {\n if (cancelled) return\n logger.error('Failed to fetch lookup items', { err })\n setError('error')\n })\n .finally(() => {\n if (!cancelled) setLoading(false)\n })\n return requestId\n }, 220)\n return () => {\n cancelled = true\n if (timer) clearTimeout(timer)\n }\n }, [query, shouldSearch, fetchKey])\n\n React.useEffect(() => {\n if (!value) {\n selectedItemRef.current = null\n setSelectedItem(null)\n return\n }\n const match = items.find((item) => item.id === value)\n if (match) {\n selectedItemRef.current = match\n setSelectedItem(match)\n }\n }, [items, value])\n\n /*\n * The collapsed summary needs a label it can trust: the consumer's\n * `selectedHintLabel` when it resolves to a name, otherwise the title of the\n * item that was actually fetched or picked. A resolver that falls back to the\n * id (`known.get(id) ?? id`) or embeds it (\"Selected customer: <id>\") is\n * treated as unresolved \u2014 a record id must never reach the DOM as a label.\n * With neither (a hydrated value whose lookup returned nothing) there is no\n * summary, so consumers rendering their own label never get a second one.\n */\n const collapsedSelectionLabel = React.useMemo(() => {\n if (!value) return null\n const hinted = selectedHintLabel?.(value)\n if (hinted && hinted !== value && !hinted.includes(value)) return hinted\n const fetchedTitle = selectedItem && selectedItem.id === value ? selectedItem.title : null\n return fetchedTitle && fetchedTitle !== value ? fetchedTitle : null\n }, [selectedHintLabel, selectedItem, value])\n const collapsedSelectionSubtitle = selectedItem && selectedItem.id === value ? selectedItem.subtitle ?? null : null\n // Once collapsed on a resolved selection the summary row IS the control: the search box\n // comes back only when the user asks to change the pick, so the field stays one row tall\n // and fits a narrow column (#5109).\n const showSummaryOnly = collapsed && Boolean(collapsedSelectionLabel)\n\n // The search box and the summary row replace each other, so whichever held the focus is\n // gone from the DOM: keyboard users continue on the control that took its place.\n React.useEffect(() => {\n if (showSummaryOnly) {\n if (!focusSummaryRef.current) return\n focusSummaryRef.current = false\n changeButtonRef.current?.focus()\n return\n }\n if (!focusAfterReopenRef.current) return\n focusAfterReopenRef.current = false\n inputRef.current?.focus()\n }, [showSummaryOnly])\n\n return (\n <div className=\"space-y-3\">\n {showSummaryOnly ? null : (\n <div className=\"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3\">\n <div className=\"relative flex-1\">\n <Search className=\"pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground\" />\n <input\n ref={inputRef}\n 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\"\n value={query}\n onChange={(event) => {\n setQuery(event.target.value)\n setHasTyped(true)\n setCollapsed(false)\n }}\n onKeyDown={handleInputKeyDown}\n placeholder={resolvedSearchPlaceholder}\n disabled={disabled}\n role=\"combobox\"\n aria-expanded={listboxVisible}\n aria-controls={listboxId}\n aria-autocomplete=\"list\"\n aria-activedescendant={activeIndex >= 0 ? optionDomId(activeIndex) : undefined}\n />\n </div>\n {actionSlot && !disabled ? <div className=\"sm:self-start\">{actionSlot}</div> : null}\n </div>\n )}\n {/*\n * `shouldSearch` decides whether to FETCH; this decides whether to RENDER a\n * list. They differ for a set value whose lookup comes back empty: develop's\n * #5248 work needs the list (and its selected option) whenever items exist,\n * while the collapsed summary \u2014 which keeps a selection visible after the\n * search box reverts to its placeholder, and keeps a raw record id out of the\n * DOM (TC-EUDR-013) \u2014 is only reachable when they do not. Falling through on\n * an empty result satisfies both. A non-empty query still renders the list so\n * its spinner and empty-state are reachable while the user is searching.\n */}\n {shouldSearch && !collapsed && (items.length > 0 || query.trim().length > 0) ? (\n <div className=\"space-y-2\">\n {loading || loadingProp ? (\n <div className=\"flex items-center gap-2 text-sm text-muted-foreground\">\n <Loader2 className=\"h-4 w-4 animate-spin\" />\n {resolvedLoadingLabel}\n </div>\n ) : null}\n {!loading && !loadingProp && !items.length ? (\n <p className=\"text-xs text-muted-foreground\">{resolvedEmptyLabel}</p>\n ) : null}\n <div\n id={listboxId}\n role=\"listbox\"\n className=\"flex flex-col gap-1.5 max-h-80 overflow-y-auto -mx-0.5 px-0.5 py-0.5\"\n >\n {items.map((item, index) => {\n const isSelected = value === item.id\n const isInteractive = isInteractiveItem(item)\n const isActive = index === activeIndex\n return (\n <div\n key={item.id}\n id={optionDomId(index)}\n className={cn(\n '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',\n isInteractive ? 'cursor-pointer' : 'cursor-not-allowed opacity-60',\n isSelected\n ? 'border-accent-indigo bg-accent-indigo/5'\n : 'border-input bg-card hover:border-foreground/20 hover:bg-muted/30',\n isActive && !isSelected ? 'border-foreground/20 bg-muted/30 shadow-sm' : null\n )}\n role=\"option\"\n tabIndex={isInteractive ? 0 : -1}\n onClick={() => {\n if (!isInteractive) return\n commitSelection(item)\n }}\n onKeyDown={(event) => {\n if (event.key === 'Enter' || event.key === ' ') {\n event.preventDefault()\n if (!isInteractive) return\n commitSelection(item)\n }\n }}\n aria-selected={isSelected}\n aria-disabled={isInteractive ? undefined : true}\n title={isSelected ? resolvedSelectedLabel : isInteractive ? resolvedSelectLabel : undefined}\n >\n {item.icon ? (\n <div className=\"flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden [&>svg]:size-5 [&_svg]:text-muted-foreground\">\n {item.icon}\n </div>\n ) : (\n <div className={cn(\n 'flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-md border transition-colors',\n isSelected\n ? 'border-accent-indigo/40 bg-accent-indigo/10 text-accent-indigo'\n : 'border-input bg-muted text-muted-foreground group-hover:border-foreground/20'\n )}>\n <span className=\"text-sm font-medium uppercase\">{item.title.slice(0, 1)}</span>\n </div>\n )}\n <div className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n <div className=\"flex items-center justify-between gap-3\">\n <div className=\"truncate text-sm font-medium text-foreground\">{item.title}</div>\n {item.rightLabel ? (\n <div className=\"shrink-0 text-overline font-medium uppercase tracking-wider text-muted-foreground\">\n {item.rightLabel}\n </div>\n ) : null}\n </div>\n {item.subtitle ? (\n <div className=\"text-xs text-muted-foreground truncate\">{item.subtitle}</div>\n ) : null}\n {item.description ? (\n <div className=\"text-xs text-muted-foreground/70 truncate\">{item.description}</div>\n ) : null}\n </div>\n <div className=\"flex shrink-0 items-center justify-center gap-1.5\">\n {isSelected ? (\n <>\n <span className=\"text-xs font-medium text-foreground\">{resolvedSelectedLabel}</span>\n <Check className=\"size-4 text-accent-indigo\" aria-hidden=\"true\" />\n </>\n ) : (\n <div className=\"size-5\" aria-hidden=\"true\" />\n )}\n </div>\n </div>\n )\n })}\n </div>\n {value && !disabled ? (\n <Button\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"w-fit gap-1 text-sm font-normal\"\n onClick={() => onChange(null)}\n >\n <X className=\"h-4 w-4\" />\n {resolvedClearLabel}\n </Button>\n ) : null}\n </div>\n ) : collapsedSelectionLabel ? (\n /*\n * The selection as a single row: the name is the control that reopens the\n * search (Change), the icon clears. No second search box above it.\n */\n <div\n className={cn(\n 'flex h-9 items-center gap-1 rounded-lg border border-accent-indigo bg-accent-indigo/5 pl-1 pr-1',\n disabled && 'border-border-disabled bg-bg-disabled',\n )}\n data-testid=\"lookup-select-selected\"\n >\n {disabled ? (\n <span className=\"flex h-7 min-w-0 flex-1 items-center gap-2 px-2 text-muted-foreground\">\n <Check className=\"size-4 shrink-0\" aria-hidden=\"true\" />\n <span className=\"truncate text-sm\">{collapsedSelectionLabel}</span>\n {collapsedSelectionSubtitle ? (\n <span className=\"hidden truncate text-xs sm:inline\">{collapsedSelectionSubtitle}</span>\n ) : null}\n </span>\n ) : (\n <Button\n ref={changeButtonRef}\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n 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\"\n onClick={reopenList}\n aria-label={resolvedChangeLabel}\n title={resolvedChangeLabel}\n >\n <Check className=\"size-4 shrink-0 text-accent-indigo\" aria-hidden=\"true\" />\n <span className=\"truncate text-sm text-foreground\">{collapsedSelectionLabel}</span>\n {collapsedSelectionSubtitle ? (\n <span className=\"hidden truncate text-xs text-muted-foreground sm:inline\">{collapsedSelectionSubtitle}</span>\n ) : null}\n </Button>\n )}\n {disabled ? null : (\n <IconButton\n type=\"button\"\n variant=\"ghost\"\n size=\"sm\"\n className=\"shrink-0 text-muted-foreground hover:bg-accent-indigo/10 hover:text-accent-indigo\"\n onClick={clearSelection}\n aria-label={resolvedClearLabel}\n title={resolvedClearLabel}\n >\n <X className=\"size-4\" aria-hidden=\"true\" />\n </IconButton>\n )}\n </div>\n ) : hasTyped && minQuery > 0 ? (\n <p className=\"text-xs text-muted-foreground\">\n {resolvedMinQueryHintLabel}\n </p>\n ) : (\n <p className=\"text-xs text-muted-foreground\">{resolvedStartTypingLabel}</p>\n )}\n {error ? <p className=\"text-xs text-status-error-text\" role=\"alert\">{resolvedEmptyLabel}</p> : null}\n </div>\n )\n}\n"],
|
|
5
|
+
"mappings": ";AA6XQ,SAmHc,UAlHZ,KADF;AA3XR,YAAY,WAAW;AACvB,SAAS,OAAO,SAAS,QAAQ,SAAS;AAC1C,SAAS,YAAY;AACrB,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAC3B,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAE7B,MAAM,SAAS,aAAa,IAAI,EAAE,MAAM,EAAE,WAAW,eAAe,CAAC;AAqCrE,SAAS,iBACP,QACA,UACA,OACoB;AACpB,MAAI,CAAC,SAAS,CAAC,YAAY,SAAS,OAAO,MAAO,QAAO;AACzD,MAAI,OAAO,KAAK,CAAC,SAAS,KAAK,OAAO,KAAK,EAAG,QAAO;AACrD,SAAO,CAAC,UAAU,GAAG,MAAM;AAC7B;AAEO,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,W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,8BAAmB,IAAO;AAAA,KACjG;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-mercato/ui",
|
|
3
|
-
"version": "0.11.1-develop.
|
|
3
|
+
"version": "0.11.1-develop.8325.1.5d93cbd8bf",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -156,14 +156,14 @@
|
|
|
156
156
|
"remark-gfm": "^4.0.1"
|
|
157
157
|
},
|
|
158
158
|
"peerDependencies": {
|
|
159
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
159
|
+
"@open-mercato/shared": "0.11.1-develop.8325.1.5d93cbd8bf",
|
|
160
160
|
"react": ">=18.0.0",
|
|
161
161
|
"react-dom": ">=18.0.0",
|
|
162
162
|
"react-is": ">=18.0.0"
|
|
163
163
|
},
|
|
164
164
|
"devDependencies": {
|
|
165
165
|
"@figma/code-connect": "^1.3.4",
|
|
166
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
166
|
+
"@open-mercato/shared": "0.11.1-develop.8325.1.5d93cbd8bf",
|
|
167
167
|
"@testing-library/dom": "^10.4.1",
|
|
168
168
|
"@testing-library/jest-dom": "^7.0.1",
|
|
169
169
|
"@testing-library/react": "^16.3.3",
|
|
@@ -155,7 +155,7 @@ export function KpiCard({
|
|
|
155
155
|
<BadgeDelta direction={trend.direction} value={trend.value} />
|
|
156
156
|
)}
|
|
157
157
|
</div>
|
|
158
|
-
{
|
|
158
|
+
{comparisonLabel && (
|
|
159
159
|
<p className="mt-1 text-xs text-muted-foreground">{comparisonLabel}</p>
|
|
160
160
|
)}
|
|
161
161
|
{footer != null && <div className="mt-3">{footer}</div>}
|
|
@@ -7,6 +7,25 @@ import { render, screen } from '@testing-library/react'
|
|
|
7
7
|
import { KpiCard } from '../KpiCard'
|
|
8
8
|
|
|
9
9
|
describe('KpiCard', () => {
|
|
10
|
+
it.each([
|
|
11
|
+
'target 8:00 — 6:00 to go',
|
|
12
|
+
'of 40:00',
|
|
13
|
+
'21 working days',
|
|
14
|
+
'16.7% of the month',
|
|
15
|
+
])('shows the comparison caption without a trend: %s', (comparisonLabel) => {
|
|
16
|
+
render(<KpiCard title="Today" value={120} comparisonLabel={comparisonLabel} />)
|
|
17
|
+
|
|
18
|
+
expect(screen.getByText(comparisonLabel)).toBeVisible()
|
|
19
|
+
expect(screen.queryByTitle('Compared to previous period')).toBeNull()
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('shows the comparison caption alongside a supplied trend', () => {
|
|
23
|
+
render(<KpiCard title="Orders" value={3} comparisonLabel="last month" trend={{ value: 10, direction: 'up' }} />)
|
|
24
|
+
|
|
25
|
+
expect(screen.getByText('last month')).toBeVisible()
|
|
26
|
+
expect(screen.getByText('10%')).toBeVisible()
|
|
27
|
+
})
|
|
28
|
+
|
|
10
29
|
it('keeps the footer when there is no value, because the footer is what explains the dash', () => {
|
|
11
30
|
render(<KpiCard title="Latest NPS" value={null} footer={<span>Never answered a survey</span>} />)
|
|
12
31
|
expect(screen.getByText('--')).toBeTruthy()
|
|
@@ -272,10 +272,9 @@ export function ComboboxInput({
|
|
|
272
272
|
// the route's `?search=` cannot match — drops it back to the placeholder).
|
|
273
273
|
React.useEffect(() => {
|
|
274
274
|
const option = optionMap.get(value)
|
|
275
|
-
|
|
276
|
-
if (document.activeElement === inputRef.current && (userTypedRef.current || !hasRealLabel)) return
|
|
275
|
+
if (document.activeElement === inputRef.current && (userTypedRef.current || !coveredOptionValues.has(value))) return
|
|
277
276
|
setInput(option?.label ?? value ?? '')
|
|
278
|
-
}, [value, optionMap])
|
|
277
|
+
}, [value, optionMap, coveredOptionValues])
|
|
279
278
|
|
|
280
279
|
const selectValue = React.useCallback(
|
|
281
280
|
(nextValue: string) => {
|
|
@@ -323,7 +322,7 @@ export function ComboboxInput({
|
|
|
323
322
|
// would freeze a placeholder (e.g. a UUID) into the visible input.
|
|
324
323
|
setShowSuggestions(false)
|
|
325
324
|
const currentOption = optionMap.get(value)
|
|
326
|
-
if (currentOption &&
|
|
325
|
+
if (currentOption && coveredOptionValues.has(value)) {
|
|
327
326
|
setInput(currentOption.label)
|
|
328
327
|
} else if (!value) {
|
|
329
328
|
setInput('')
|
|
@@ -332,7 +331,7 @@ export function ComboboxInput({
|
|
|
332
331
|
}
|
|
333
332
|
selectValue(raw)
|
|
334
333
|
},
|
|
335
|
-
[allowCustomValues, clearable, disabled, findOptionForInput, optionMap, selectValue, value]
|
|
334
|
+
[allowCustomValues, clearable, coveredOptionValues, disabled, findOptionForInput, optionMap, selectValue, value]
|
|
336
335
|
)
|
|
337
336
|
|
|
338
337
|
const handleClear = React.useCallback(() => {
|
|
@@ -89,7 +89,7 @@ export function LookupSelect({
|
|
|
89
89
|
const resolvedStartTypingLabel = startTypingLabel ?? t('ui.lookupSelect.startTyping', 'Start typing to search.')
|
|
90
90
|
const resolvedMinQueryHintLabel = minQueryHintLabel ?? t(
|
|
91
91
|
'ui.lookupSelect.minQueryHint',
|
|
92
|
-
'
|
|
92
|
+
'Minimum characters to search: {minQuery}. You can also paste an id.',
|
|
93
93
|
{ minQuery: String(minQuery) }
|
|
94
94
|
)
|
|
95
95
|
const [query, setQuery] = React.useState('')
|
|
@@ -571,7 +571,7 @@ export function LookupSelect({
|
|
|
571
571
|
</IconButton>
|
|
572
572
|
)}
|
|
573
573
|
</div>
|
|
574
|
-
) : hasTyped ? (
|
|
574
|
+
) : hasTyped && minQuery > 0 ? (
|
|
575
575
|
<p className="text-xs text-muted-foreground">
|
|
576
576
|
{resolvedMinQueryHintLabel}
|
|
577
577
|
</p>
|
|
@@ -474,6 +474,55 @@ describe('ComboboxInput — eager label resolution', () => {
|
|
|
474
474
|
await waitFor(() => expect(getInput(container).value).toBe('Central warehouse'))
|
|
475
475
|
})
|
|
476
476
|
|
|
477
|
+
it.each(['suggestions', 'seedOptions'] as const)('shows a saved currency under autofocus with self-labeled %s', (source) => {
|
|
478
|
+
const onChange = jest.fn()
|
|
479
|
+
const { container } = render(
|
|
480
|
+
<ComboboxInput
|
|
481
|
+
value="USD"
|
|
482
|
+
onChange={onChange}
|
|
483
|
+
autoFocus
|
|
484
|
+
allowCustomValues={false}
|
|
485
|
+
{...{ [source]: [{ value: 'USD', label: 'USD' }] }}
|
|
486
|
+
/>,
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
expect(document.activeElement).toBe(getInput(container))
|
|
490
|
+
expect(getInput(container).value).toBe('USD')
|
|
491
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
492
|
+
})
|
|
493
|
+
|
|
494
|
+
it('shows a saved currency when its options arrive after autofocus without changing the stored value', async () => {
|
|
495
|
+
const onChange = jest.fn()
|
|
496
|
+
const loadSuggestions = jest.fn(async () => [{ value: 'USD', label: 'USD' }])
|
|
497
|
+
const { container } = render(
|
|
498
|
+
<ComboboxInput value="USD" onChange={onChange} autoFocus allowCustomValues={false} loadSuggestions={loadSuggestions} />,
|
|
499
|
+
)
|
|
500
|
+
|
|
501
|
+
await waitFor(() => expect(getInput(container).value).toBe('USD'))
|
|
502
|
+
expect(document.activeElement).toBe(getInput(container))
|
|
503
|
+
expect(loadSuggestions).toHaveBeenCalledTimes(1)
|
|
504
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
505
|
+
})
|
|
506
|
+
|
|
507
|
+
it('reverts an invalid query to the saved self-labeled currency on blur', async () => {
|
|
508
|
+
const onChange = jest.fn()
|
|
509
|
+
const { container } = render(
|
|
510
|
+
<ComboboxInput
|
|
511
|
+
value="USD"
|
|
512
|
+
onChange={onChange}
|
|
513
|
+
suggestions={[{ value: 'USD', label: 'USD' }]}
|
|
514
|
+
allowCustomValues={false}
|
|
515
|
+
/>,
|
|
516
|
+
)
|
|
517
|
+
const input = getInput(container)
|
|
518
|
+
act(() => input.focus())
|
|
519
|
+
fireEvent.change(input, { target: { value: 'missing' } })
|
|
520
|
+
fireEvent.blur(input)
|
|
521
|
+
|
|
522
|
+
await waitFor(() => expect(input.value).toBe('USD'))
|
|
523
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
524
|
+
})
|
|
525
|
+
|
|
477
526
|
// Guards the opposite direction of the case above: it passes on both the old
|
|
478
527
|
// focus-based guard and the current typing-based one, so it is a behavior pin
|
|
479
528
|
// rather than a regression test for any specific bug.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as React from 'react'
|
|
4
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
5
|
+
import { I18nProvider } from '@open-mercato/shared/lib/i18n/context'
|
|
6
|
+
import en from '../../../../../../apps/mercato/src/i18n/en.json'
|
|
7
|
+
import pl from '../../../../../../apps/mercato/src/i18n/pl.json'
|
|
8
|
+
import es from '../../../../../../apps/mercato/src/i18n/es.json'
|
|
9
|
+
import { LookupSelect } from '../LookupSelect'
|
|
10
|
+
|
|
11
|
+
describe('LookupSelect minimum-query guidance', () => {
|
|
12
|
+
it('shows generic guidance instead of a zero-character minimum when opened or cleared', () => {
|
|
13
|
+
render(
|
|
14
|
+
<I18nProvider locale="en" dict={en}>
|
|
15
|
+
<LookupSelect value={null} onChange={jest.fn()} minQuery={0} defaultOpen options={[]} />
|
|
16
|
+
</I18nProvider>,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
expect(screen.getByText('Start typing to search.')).toBeInTheDocument()
|
|
20
|
+
expect(screen.queryByText(/Minimum characters/)).not.toBeInTheDocument()
|
|
21
|
+
|
|
22
|
+
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'missing' } })
|
|
23
|
+
fireEvent.change(screen.getByRole('combobox'), { target: { value: '' } })
|
|
24
|
+
|
|
25
|
+
expect(screen.getByText('Start typing to search.')).toBeInTheDocument()
|
|
26
|
+
expect(screen.queryByText(/Minimum characters/)).not.toBeInTheDocument()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it.each([
|
|
30
|
+
['en', en, 'Minimum characters to search: 1. You can also paste an id.'],
|
|
31
|
+
['pl', pl, 'Minimalna liczba znaków do wyszukiwania: 1. Możesz też wkleić identyfikator.'],
|
|
32
|
+
['es', es, 'Caracteres mínimos para buscar: 1. También puedes pegar un id.'],
|
|
33
|
+
] as const)('uses grammatical one-character guidance in %s', (locale, dict, hint) => {
|
|
34
|
+
render(
|
|
35
|
+
<I18nProvider locale={locale} dict={dict}>
|
|
36
|
+
<LookupSelect value={null} onChange={jest.fn()} minQuery={1} defaultOpen options={[]} />
|
|
37
|
+
</I18nProvider>,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
expect(screen.getByText(hint)).toBeInTheDocument()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('keeps positive-minimum guidance and custom hint overrides', () => {
|
|
44
|
+
const { rerender } = render(
|
|
45
|
+
<I18nProvider locale="en" dict={en}>
|
|
46
|
+
<LookupSelect value={null} onChange={jest.fn()} minQuery={2} options={[]} />
|
|
47
|
+
</I18nProvider>,
|
|
48
|
+
)
|
|
49
|
+
fireEvent.change(screen.getByRole('combobox'), { target: { value: 'a' } })
|
|
50
|
+
expect(screen.getByText('Minimum characters to search: 2. You can also paste an id.')).toBeInTheDocument()
|
|
51
|
+
|
|
52
|
+
rerender(
|
|
53
|
+
<I18nProvider locale="en" dict={en}>
|
|
54
|
+
<LookupSelect value={null} onChange={jest.fn()} minQuery={2} options={[]} minQueryHintLabel="Custom guidance" />
|
|
55
|
+
</I18nProvider>,
|
|
56
|
+
)
|
|
57
|
+
expect(screen.getByText('Custom guidance')).toBeInTheDocument()
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('still loads and selects results without a minimum query', async () => {
|
|
61
|
+
const fetchItems = jest.fn(async () => [{ id: 'variant', title: 'Available variant' }])
|
|
62
|
+
const onChange = jest.fn()
|
|
63
|
+
render(
|
|
64
|
+
<I18nProvider locale="en" dict={en}>
|
|
65
|
+
<LookupSelect value={null} onChange={onChange} minQuery={0} defaultOpen fetchItems={fetchItems} />
|
|
66
|
+
</I18nProvider>,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
fireEvent.click(await screen.findByRole('option', { name: /Available variant/ }))
|
|
70
|
+
expect(fetchItems).toHaveBeenCalledWith('')
|
|
71
|
+
expect(onChange).toHaveBeenCalledWith('variant')
|
|
72
|
+
})
|
|
73
|
+
})
|