minerva-design 1.19.0 → 1.19.2
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/CHANGELOG.md +18 -0
- package/dist/angular/fesm2022/minerva-angular.mjs +10 -14
- package/dist/angular/fesm2022/minerva-angular.mjs.map +1 -1
- package/dist/angular/types/minerva-angular.d.ts +8 -2
- package/dist/core/decimal-places.d.cts +6 -0
- package/dist/core/decimal-places.d.ts +6 -0
- package/dist/core/index.cjs +21 -21
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +590 -580
- package/dist/core/index.js.map +1 -1
- package/dist/core/keyboard-navigation.d.cts +14 -0
- package/dist/core/keyboard-navigation.d.ts +14 -0
- package/dist/core/number-input.d.cts +4 -1
- package/dist/core/number-input.d.ts +4 -1
- package/dist/core/slider.d.cts +1 -1
- package/dist/core/slider.d.ts +1 -1
- package/dist/react/components/AutoComplete/AutoComplete.cjs +1 -1
- package/dist/react/components/AutoComplete/AutoComplete.cjs.map +1 -1
- package/dist/react/components/AutoComplete/AutoComplete.js +91 -90
- package/dist/react/components/AutoComplete/AutoComplete.js.map +1 -1
- package/dist/react/components/DatePicker/DatePicker.cjs +1 -1
- package/dist/react/components/DatePicker/DatePicker.cjs.map +1 -1
- package/dist/react/components/DatePicker/DatePicker.js +3 -2
- package/dist/react/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/vue/components/AutoComplete/AutoComplete.vue.js.map +1 -1
- package/dist/vue/components/AutoComplete/AutoComplete.vue_vue_type_script_setup_true_lang.js +58 -57
- package/dist/vue/components/AutoComplete/AutoComplete.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/weapp/controls.js +24 -12
- package/dist/web-components/cdn/minerva.js +532 -532
- package/dist/web-components/cdn/minerva.js.map +1 -1
- package/dist/web-components/components/autocomplete/autocomplete.d.ts +7 -1
- package/dist/web-components/components/autocomplete/autocomplete.js +29 -24
- package/dist/web-components/components/autocomplete/autocomplete.js.map +1 -1
- package/dist/web-components/components/date-picker/date-picker.js +11 -5
- package/dist/web-components/components/date-picker/date-picker.js.map +1 -1
- package/package.json +1 -1
|
@@ -31,3 +31,17 @@ export interface GetNextIndexOptions {
|
|
|
31
31
|
* - PageUp / PageDown: only with `pageSize` (clamped, never wraps).
|
|
32
32
|
*/
|
|
33
33
|
export declare function getNextIndex({ currentIndex, count, key, orientation, dir, loop, isDisabled, pageSize, }: GetNextIndexOptions): number | null;
|
|
34
|
+
/** An option of a combobox list (identified by its `value`). */
|
|
35
|
+
export interface ActiveOptionItem {
|
|
36
|
+
value: string | number;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Index of the active (aria-activedescendant) option of a combobox list.
|
|
41
|
+
* The highlight follows the option's identity (`focusedValue`), not its
|
|
42
|
+
* index, so it survives async option updates and is dropped when that option
|
|
43
|
+
* is gone or disabled. Without a valid highlight, `autoHighlight` falls back
|
|
44
|
+
* to the first enabled option; `-1` otherwise. Pass `[]` while the options
|
|
45
|
+
* are hidden (loading) so nothing unseen can be active or selected.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveActiveOptionIndex(options: readonly ActiveOptionItem[], focusedValue: string | number | null, autoHighlight: boolean): number;
|
|
@@ -31,3 +31,17 @@ export interface GetNextIndexOptions {
|
|
|
31
31
|
* - PageUp / PageDown: only with `pageSize` (clamped, never wraps).
|
|
32
32
|
*/
|
|
33
33
|
export declare function getNextIndex({ currentIndex, count, key, orientation, dir, loop, isDisabled, pageSize, }: GetNextIndexOptions): number | null;
|
|
34
|
+
/** An option of a combobox list (identified by its `value`). */
|
|
35
|
+
export interface ActiveOptionItem {
|
|
36
|
+
value: string | number;
|
|
37
|
+
disabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Index of the active (aria-activedescendant) option of a combobox list.
|
|
41
|
+
* The highlight follows the option's identity (`focusedValue`), not its
|
|
42
|
+
* index, so it survives async option updates and is dropped when that option
|
|
43
|
+
* is gone or disabled. Without a valid highlight, `autoHighlight` falls back
|
|
44
|
+
* to the first enabled option; `-1` otherwise. Pass `[]` while the options
|
|
45
|
+
* are hidden (loading) so nothing unseen can be active or selected.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveActiveOptionIndex(options: readonly ActiveOptionItem[], focusedValue: string | number | null, autoHighlight: boolean): number;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Decimal places of `step` (`0.05` -> 2, `1.25` -> 2, `1e-7` -> 7);
|
|
3
|
+
* `0` for whole or missing steps.
|
|
4
|
+
*/
|
|
2
5
|
export declare function inferStepPrecision(step?: number): number;
|
|
3
6
|
/** `n` limited to `[min, max]`; a missing bound does not limit. */
|
|
4
7
|
export declare function clampNumber(n: number, min?: number, max?: number): number;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Decimal places of `step` (`0.05` -> 2, `1.25` -> 2, `1e-7` -> 7);
|
|
3
|
+
* `0` for whole or missing steps.
|
|
4
|
+
*/
|
|
2
5
|
export declare function inferStepPrecision(step?: number): number;
|
|
3
6
|
/** `n` limited to `[min, max]`; a missing bound does not limit. */
|
|
4
7
|
export declare function clampNumber(n: number, min?: number, max?: number): number;
|
package/dist/core/slider.d.cts
CHANGED
|
@@ -20,7 +20,7 @@ export interface SliderScale {
|
|
|
20
20
|
}
|
|
21
21
|
/** Most step ticks drawn by `marks: true` (denser scales draw none). */
|
|
22
22
|
export declare const SLIDER_MAX_STEP_MARKS = 101;
|
|
23
|
-
/** Decimal places of a step (`0.05` -> 2). */
|
|
23
|
+
/** Decimal places of a step (`0.05` -> 2, `1.5e-7` -> 8). */
|
|
24
24
|
export declare function sliderPrecision(step?: number | null): number;
|
|
25
25
|
/** `v` limited to `[min, max]`. */
|
|
26
26
|
export declare function clampSliderValue(v: number, min: number, max: number): number;
|
package/dist/core/slider.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface SliderScale {
|
|
|
20
20
|
}
|
|
21
21
|
/** Most step ticks drawn by `marks: true` (denser scales draw none). */
|
|
22
22
|
export declare const SLIDER_MAX_STEP_MARKS = 101;
|
|
23
|
-
/** Decimal places of a step (`0.05` -> 2). */
|
|
23
|
+
/** Decimal places of a step (`0.05` -> 2, `1.5e-7` -> 8). */
|
|
24
24
|
export declare function sliderPrecision(step?: number | null): number;
|
|
25
25
|
/** `v` limited to `[min, max]`. */
|
|
26
26
|
export declare function clampSliderValue(v: number, min: number, max: number): number;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs");require("../../utils/cn.cjs");const t=require("../../internal/stylingHooks.cjs"),n=require("../../internal/devWarnings.cjs"),r=require("../ProgressIndicator/ProgressIndicator.cjs");require("../ProgressIndicator/index.cjs");const i=require("../../internal/mergeRefs.cjs"),a=require("../../internal/useControllableState.cjs"),ee=require("../FormControl/context.cjs"),te=require("../../internal/FloatingPanel.cjs"),ne=require("../Input/Input.cjs");require("../Input/index.cjs");const re=require("../Empty/Empty.cjs");require("../Empty/index.cjs");const o=require("./autoComplete.module.scss.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("
|
|
1
|
+
"use client";const e=require("../../_virtual/_rolldown/runtime.cjs");require("../../utils/cn.cjs");const t=require("../../internal/stylingHooks.cjs"),n=require("../../internal/devWarnings.cjs"),r=require("../ProgressIndicator/ProgressIndicator.cjs");require("../ProgressIndicator/index.cjs");const i=require("../../internal/mergeRefs.cjs"),a=require("../../internal/useControllableState.cjs"),ee=require("../FormControl/context.cjs"),te=require("../../internal/FloatingPanel.cjs"),ne=require("../Input/Input.cjs");require("../Input/index.cjs");const re=require("../Empty/Empty.cjs");require("../Empty/index.cjs");const o=require("./autoComplete.module.scss.cjs");let s=require("react");s=e.__toESM(s,1);let c=require("../../../core/index.cjs"),l=require("react/jsx-runtime"),u=require("../../../dom/index.cjs");var ie=Object.freeze({x:0,y:4}),d=[],ae={top:`top-start`,bottom:`bottom-start`,left:`left-start`,right:`right-start`},f=({ref:e,name:f,label:p,mode:oe=`basic`,value:m,onChange:h,options:g=d,defaultValue:_,onSelect:se,filterOption:v,groupBy:y,renderOption:ce,renderEmpty:le,loading:b=!1,inputProps:x,emptyProps:ue,placement:S=`bottom`,offset:C=ie,animation:de=!0,sortOption:w,onOptionClick:fe,onDropdownVisibleChange:pe,dropdownClassName:me,onSubmit:T,autoHighlight:he=!1,fillOnSelect:ge=!0,className:_e,groupMode:E=`first`})=>{let[D,O]=a.useControllableState({value:m,defaultValue:_??``,onChange:h,name:`AutoComplete`}),[k,A]=a.useControllableState({defaultValue:!1,onChange:pe,name:`AutoComplete`,prop:`open`}),[ve,j]=(0,s.useState)(null),[ye,M]=(0,s.useState)(-1),[N,be]=(0,s.useState)(null),[P,xe]=(0,s.useState)(null),Se=i.useMergedRefs(xe,e),[Ce,we]=(0,s.useState)(null),F=S===`top`||S===`bottom`,I=(0,s.useId)(),L=`${I}-listbox`,R=(0,s.useRef)(!1),z=ee.useFormControlProps({id:x?.id,disabled:x?.disabled,readOnly:x?.readOnly}),B=z.id??`${I}-input`,V=!!z.disabled||!!z.readOnly;process.env.NODE_ENV!==`production`&&n.warnControlledProps(`AutoComplete`,{prop:`value`,value:m,defaultProp:`defaultValue`,defaultValue:_,handlerProp:`onChange`,handler:h,locked:V,lockHint:"set `inputProps.disabled` / `inputProps.readOnly`"});let H=k&&!V,U=()=>{V||A(!0)},W=()=>{A(!1),j(null)},G=(0,s.useMemo)(()=>{let e=D.toLowerCase(),t=g.filter(t=>v?v(D,t):t.label.toLowerCase().includes(e));return w?[...t].sort(w):t},[g,D,v,w]),K=(0,s.useMemo)(()=>{if(!y)return null;if(E===`adjacent`){let e=[];return G.forEach(t=>{let n=y(t),r=e[e.length-1];r&&r[0]===n?r[1].push(t):e.push([n,[t]])}),e}let e=new Map;return G.forEach(t=>{let n=y(t),r=e.get(n);r?r.push(t):e.set(n,[t])}),Array.from(e.entries())},[G,y,E]),q=(0,s.useMemo)(()=>K?K.flatMap(([,e])=>e):G,[K,G]),J=b?d:q,Y=(0,c.resolveActiveOptionIndex)(J,ve,he&&H),X=e=>{let t=J.length;if(t===0)return;let n=Y>=0?Y:e===1?-1:t;for(let r=0;r<t;r+=1)if(n=(n+e+t)%t,!J[n].disabled){j(J[n].value);return}},Z=e=>{e.disabled||(ge&&O(e.label),W(),se?.(e))},Te=e=>{if(!(V||R.current||e.nativeEvent.isComposing||e.keyCode===229))switch(e.key){case`ArrowDown`:e.preventDefault(),k||U(),X(1);break;case`ArrowUp`:e.preventDefault(),k||U(),X(-1);break;case`Enter`:{let t=H?J[Y]:void 0;t?(e.preventDefault(),Z(t)):T&&D.trim()&&(e.preventDefault(),T(D.trim()),W());break}case`Escape`:!H&&D!==``&&(e.preventDefault(),O(``),j(null))}},Ee=e=>{O(e),j(null),U()},De=e=>{let t=e.relatedTarget;t&&(Ce?.contains(t)||N?.contains(t))||W()},Oe=e=>{e.disabled||R.current||(Z(e),fe?.(e),P?.focus())},Q=H&&Y>=0?`${L}-option-${Y}`:void 0;(0,s.useEffect)(()=>{P&&(P.setAttribute(`role`,`combobox`),P.setAttribute(`aria-autocomplete`,`list`),P.setAttribute(`aria-expanded`,String(H)),!H&&D!==``?P.setAttribute(u.ESCAPE_CONSUMER_ATTRIBUTE,``):P.removeAttribute(u.ESCAPE_CONSUMER_ATTRIBUTE),H?P.setAttribute(`aria-controls`,L):P.removeAttribute(`aria-controls`),Q?P.setAttribute(`aria-activedescendant`,Q):P.removeAttribute(`aria-activedescendant`))},[P,H,L,Q,D]);let ke=(0,s.useRef)(()=>{});(0,s.useEffect)(()=>{ke.current=()=>{k||U()}}),(0,s.useEffect)(()=>{if(!P)return;let e=()=>ke.current();return P.addEventListener(`click`,e),()=>P.removeEventListener(`click`,e)},[P]),(0,s.useEffect)(()=>{Q&&document.getElementById(Q)?.scrollIntoView?.({block:`nearest`})},[Q]);let Ae=e=>(0,l.jsxs)(`div`,{className:o.default.basicOption,children:[e.icon&&(0,l.jsx)(`span`,{className:o.default.icon,children:e.icon}),(0,l.jsxs)(`div`,{className:o.default.content,children:[(0,l.jsx)(`div`,{className:o.default.label,children:e.label}),e.description&&(0,l.jsx)(`div`,{className:o.default.description,children:e.description})]})]}),$=(e,n)=>{let r=Y===n,i=ye===n||r;return(0,l.jsx)(`div`,{className:(0,c.cn)(o.default.optionItem,{[o.default.disabled]:e.disabled,[o.default.highlight]:e.highlight,[o.default.active]:i}),style:e.style,role:`option`,tabIndex:-1,id:`${L}-option-${n}`,"aria-selected":r,"aria-disabled":e.disabled||void 0,onMouseDown:e=>e.preventDefault(),onClick:()=>Oe(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),Oe(e))},onMouseEnter:()=>M(n),onMouseLeave:()=>M(-1),...t.hooks(`autocomplete`,`item`,{highlighted:i,disabled:e.disabled}),children:oe===`custom`&&ce?ce(e):Ae(e)},e.value)};return(0,l.jsxs)(`div`,{ref:be,className:(0,c.cn)(o.default.autoComplete,_e),onCompositionStart:()=>{R.current=!0},onCompositionEnd:()=>{R.current=!1},...t.hooks(`autocomplete`,`root`,{state:H?`open`:`closed`,disabled:!!z.disabled,readonly:!!z.readOnly,loading:b}),children:[p&&(0,l.jsx)(`label`,{htmlFor:B,className:o.default.label,...t.hooks(`autocomplete`,`label`),children:p}),(0,l.jsx)(ne.Input,{...x,id:B,disabled:z.disabled,readOnly:z.readOnly,name:f,ref:Se,value:D,onChange:e=>Ee(e.target.value),onFocus:e=>{U(),x?.onFocus?.(e)},onBlur:e=>{De(e),x?.onBlur?.(e)},onKeyDown:e=>{Te(e),x?.onKeyDown?.(e)}}),(0,l.jsx)(te.FloatingPanel,{ref:we,open:H,anchor:N,placement:ae[S],offset:{mainAxis:F?C.y:C.x,crossAxis:F?C.x:C.y},matchAnchorWidth:`min`,branches:()=>[N],onEscapeKeyDown:e=>{(R.current||e.isComposing)&&e.preventDefault()},onDismiss:W,returnFocusOnEscape:()=>P,className:(0,c.cn)(o.default.popup,me),...t.hooks(`autocomplete`,`content`,{state:`open`}),children:(0,l.jsx)(`div`,{className:(0,c.cn)(o.default.dropdown,de&&o.default.animated),children:(0,l.jsx)(`div`,{className:o.default.optionList,role:`listbox`,id:L,"aria-label":p,"aria-busy":b||void 0,...t.hooks(`autocomplete`,`list`),children:b?(0,l.jsx)(`div`,{role:`presentation`,className:o.default.loading,...t.hooks(`autocomplete`,`loading`),children:(0,l.jsx)(r.default,{})}):G.length>0?(0,l.jsx)(l.Fragment,{children:K?K.map(([e,n],r)=>e===``?(0,l.jsx)(s.default.Fragment,{children:n.map(e=>$(e,q.indexOf(e)))},`${r}-`):(0,l.jsxs)(`div`,{className:o.default.optionGroup,role:`group`,"aria-label":e,children:[(0,l.jsx)(`div`,{className:o.default.groupLabel,"aria-hidden":`true`,...t.hooks(`autocomplete`,`group-label`),children:e}),n.map(e=>$(e,q.indexOf(e)))]},`${r}-${e}`)):G.map((e,t)=>$(e,t))}):(0,l.jsx)(`div`,{role:`presentation`,className:o.default.empty,...t.hooks(`autocomplete`,`empty`),children:le?.()||(0,l.jsx)(re.default,{...ue})})})})})]})};exports.default=f;
|
|
2
2
|
//# sourceMappingURL=AutoComplete.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoComplete.cjs","names":["useControllableState","useState","useMergedRefs","useId","useRef","useFormControlProps","useMemo","ESCAPE_CONSUMER_ATTRIBUTE","styles","cn","hooks","Input","FloatingPanel","ProgressIndicator","_Fragment","React","Empty","require_runtime","require_stylingHooks","require_devWarnings","require_ProgressIndicator","require_mergeRefs","require_useControllableState","require_context","require_FloatingPanel","require_Input","require_Empty","require_autoComplete_module","react","react_jsx_runtime","_minerva_dom","_minerva_core","DEFAULT_OFFSET","EMPTY_OPTIONS","PLACEMENT","AutoComplete","defaultValueProp","inputValue","setInputValue","visible","setVisible","onDropdownVisibleChange","focusedIndex","setFocusedIndex","hoveredIndex","setHoveredIndex","container","setContainer","input","setInput","setInputRef","ref","dropdown","setDropdown","vertical","placement","baseId","listboxId","composing","field","inputProps","inputId","blocked","onChange","shown","open","close","processedOptions","search","result","options","filterOption","option","sortOption","groupedOptions","groupBy","groupMode","runs","group","last","groups","list","navigableOptions","activeIndex","autoHighlight","moveFocus","count","index","step","i","handleOptionSelect","fillOnSelect","onSelect","handleKeyDown","event","onSubmit","handleInputChange","next","handleBlur","handleOptionClick","onOptionClick","activeOptionId","reopenRef","onClick","renderBasicOption","renderOptionItem","active","highlighted","e","mode","renderOption","className","label","offset","dropdownClassName","animation","loading","groupOptions","groupIndex","renderEmpty","emptyProps"],"sources":["../../../../../react/src/components/AutoComplete/AutoComplete.tsx"],"sourcesContent":["import React, { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Input } from \"../Input\";\nimport { ProgressIndicator } from \"../ProgressIndicator\";\nimport { Empty } from \"../Empty\";\nimport type { AutoCompleteProps, AutoCompleteOption } from \"./types\";\nimport { FloatingPanel } from \"../../internal/FloatingPanel\";\nimport { useControllableState } from \"../../internal/useControllableState\";\nimport { warnControlledProps } from \"../../internal/devWarnings\";\nimport { useMergedRefs } from \"../../internal/mergeRefs\";\nimport { useFormControlProps } from \"../FormControl/context\";\nimport { hooks } from \"../../internal/stylingHooks\";\nimport styles from \"./autoComplete.module.scss\";\nimport { ESCAPE_CONSUMER_ATTRIBUTE } from \"@minerva/dom\";\n\nconst DEFAULT_OFFSET = Object.freeze({ x: 0, y: 4 });\nconst EMPTY_OPTIONS: AutoCompleteOption[] = [];\n\nconst PLACEMENT = {\n top: \"top-start\",\n bottom: \"bottom-start\",\n left: \"left-start\",\n right: \"right-start\",\n} as const;\n\n/**\n * AutoComplete: a text input (combobox) that suggests options from a list.\n * Supports grouping, custom rendering and async loading; the input text can\n * be controlled or not. Focus stays in the input (`aria-activedescendant`).\n * For picking several values use `TagInput`.\n */\nconst AutoComplete = ({\n ref,\n name,\n label,\n mode = \"basic\",\n value,\n onChange,\n options = EMPTY_OPTIONS,\n defaultValue: defaultValueProp,\n onSelect,\n filterOption,\n groupBy,\n renderOption,\n renderEmpty,\n loading = false,\n inputProps,\n emptyProps,\n placement = \"bottom\",\n offset = DEFAULT_OFFSET,\n animation = true,\n sortOption,\n onOptionClick,\n onDropdownVisibleChange,\n dropdownClassName,\n onSubmit,\n autoHighlight = false,\n fillOnSelect = true,\n className,\n groupMode = \"first\",\n}: AutoCompleteProps) => {\n const [inputValue, setInputValue] = useControllableState({\n value,\n defaultValue: defaultValueProp ?? \"\",\n onChange,\n name: \"AutoComplete\",\n });\n const [visible, setVisible] = useControllableState({\n defaultValue: false,\n onChange: onDropdownVisibleChange,\n name: \"AutoComplete\",\n prop: \"open\",\n });\n const [focusedIndex, setFocusedIndex] = useState(-1);\n const [hoveredIndex, setHoveredIndex] = useState(-1);\n const [container, setContainer] = useState<HTMLDivElement | null>(null);\n const [input, setInput] = useState<HTMLInputElement | null>(null);\n const setInputRef = useMergedRefs<HTMLInputElement>(setInput, ref);\n const [dropdown, setDropdown] = useState<HTMLDivElement | null>(null);\n const vertical = placement === \"top\" || placement === \"bottom\";\n\n const baseId = useId();\n const listboxId = `${baseId}-listbox`;\n // IME composition in progress: Enter / arrows belong to the IME.\n const composing = useRef(false);\n\n // FormControl wiring (id, disabled / read-only state, aria-*). The\n // input's own disabled / readOnly props still apply.\n const field = useFormControlProps({\n id: inputProps?.id,\n disabled: inputProps?.disabled,\n readOnly: inputProps?.readOnly,\n });\n const inputId = field.id ?? `${baseId}-input`;\n const blocked = !!field.disabled || !!field.readOnly;\n if (process.env.NODE_ENV !== \"production\") {\n warnControlledProps(\"AutoComplete\", {\n prop: \"value\",\n value,\n defaultProp: \"defaultValue\",\n defaultValue: defaultValueProp,\n handlerProp: \"onChange\",\n handler: onChange,\n locked: blocked,\n lockHint: \"set `inputProps.disabled` / `inputProps.readOnly`\",\n });\n }\n // A disabled / read-only field never shows (or keeps) the dropdown.\n const shown = visible && !blocked;\n\n const open = () => {\n if (!blocked) setVisible(true);\n };\n const close = () => {\n setVisible(false);\n setFocusedIndex(-1);\n };\n\n const processedOptions = useMemo(() => {\n const search = inputValue.toLowerCase();\n const result = options.filter((option) =>\n filterOption\n ? filterOption(inputValue, option)\n : option.label.toLowerCase().includes(search),\n );\n return sortOption ? [...result].sort(sortOption) : result;\n }, [options, inputValue, filterOption, sortOption]);\n\n /** Groups in order of first appearance, or runs of adjacent options */\n const groupedOptions = useMemo(() => {\n if (!groupBy) return null;\n if (groupMode === \"adjacent\") {\n const runs: [string, AutoCompleteOption[]][] = [];\n processedOptions.forEach((option) => {\n const group = groupBy(option);\n const last = runs[runs.length - 1];\n if (last && last[0] === group) last[1].push(option);\n else runs.push([group, [option]]);\n });\n return runs;\n }\n const groups = new Map<string, AutoCompleteOption[]>();\n processedOptions.forEach((option) => {\n const group = groupBy(option);\n const list = groups.get(group);\n if (list) list.push(option);\n else groups.set(group, [option]);\n });\n return Array.from(groups.entries());\n }, [processedOptions, groupBy, groupMode]);\n\n /** Options in display order; keyboard / hover indexes refer to this list */\n const navigableOptions = useMemo(\n () =>\n groupedOptions\n ? groupedOptions.flatMap(([, list]) => list)\n : processedOptions,\n [groupedOptions, processedOptions],\n );\n\n // With autoHighlight the first enabled option is active until the user\n // moves the highlight.\n const activeIndex =\n focusedIndex >= 0\n ? focusedIndex\n : autoHighlight && shown\n ? navigableOptions.findIndex((option) => !option.disabled)\n : -1;\n\n const moveFocus = (step: 1 | -1) => {\n const count = navigableOptions.length;\n if (count === 0) return;\n // from \"nothing focused\", ArrowDown starts at the first option and\n // ArrowUp at the last one\n let index = activeIndex >= 0 ? activeIndex : step === 1 ? -1 : count;\n for (let i = 0; i < count; i += 1) {\n index = (index + step + count) % count;\n if (!navigableOptions[index].disabled) {\n setFocusedIndex(index);\n return;\n }\n }\n };\n\n const handleOptionSelect = (option: AutoCompleteOption) => {\n if (option.disabled) return;\n if (fillOnSelect) setInputValue(option.label);\n close();\n onSelect?.(option);\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (\n blocked ||\n composing.current ||\n event.nativeEvent.isComposing ||\n event.keyCode === 229\n )\n return;\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (!visible) open();\n moveFocus(1);\n break;\n case \"ArrowUp\":\n event.preventDefault();\n if (!visible) open();\n moveFocus(-1);\n break;\n case \"Enter\": {\n const option = shown ? navigableOptions[activeIndex] : undefined;\n if (option) {\n event.preventDefault();\n handleOptionSelect(option);\n } else if (onSubmit && inputValue.trim()) {\n // No active option: submit the typed text (e.g. a search).\n event.preventDefault();\n onSubmit(inputValue.trim());\n close();\n }\n break;\n }\n case \"Escape\":\n // Open: the dropdown's dismissable layer closes it (topmost only).\n // Closed: clears the text (APG combobox), `onChange(\"\")`.\n if (!shown && inputValue !== \"\") {\n event.preventDefault();\n setInputValue(\"\");\n setFocusedIndex(-1);\n }\n break;\n default:\n break;\n }\n };\n\n const handleInputChange = (next: string) => {\n setInputValue(next);\n setFocusedIndex(-1);\n open();\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n const next = event.relatedTarget as Node | null;\n if (next && (dropdown?.contains(next) || container?.contains(next))) return;\n close();\n };\n\n const handleOptionClick = (option: AutoCompleteOption) => {\n if (option.disabled || composing.current) return;\n handleOptionSelect(option);\n onOptionClick?.(option);\n input?.focus();\n };\n\n // Expose combobox semantics on the inner <input>\n const activeOptionId =\n shown && activeIndex >= 0\n ? `${listboxId}-option-${activeIndex}`\n : undefined;\n useEffect(() => {\n if (!input) return;\n input.setAttribute(\"role\", \"combobox\");\n input.setAttribute(\"aria-autocomplete\", \"list\");\n input.setAttribute(\"aria-expanded\", String(shown));\n // Closed with text: Escape clears it instead of closing an enclosing\n // Modal / Drawer / Popover\n if (!shown && inputValue !== \"\") {\n input.setAttribute(ESCAPE_CONSUMER_ATTRIBUTE, \"\");\n } else input.removeAttribute(ESCAPE_CONSUMER_ATTRIBUTE);\n if (shown) input.setAttribute(\"aria-controls\", listboxId);\n else input.removeAttribute(\"aria-controls\");\n if (activeOptionId)\n input.setAttribute(\"aria-activedescendant\", activeOptionId);\n else input.removeAttribute(\"aria-activedescendant\");\n }, [input, shown, listboxId, activeOptionId, inputValue]);\n\n // Clicking the still-focused input (after a pick or Escape) reopens the\n // dropdown; focus alone does not fire again.\n const reopenRef = useRef(() => {});\n useEffect(() => {\n reopenRef.current = () => {\n if (!visible) open();\n };\n });\n useEffect(() => {\n if (!input) return;\n const onClick = () => reopenRef.current();\n input.addEventListener(\"click\", onClick);\n return () => input.removeEventListener(\"click\", onClick);\n }, [input]);\n\n // Keep the keyboard-focused option scrolled into view\n useEffect(() => {\n if (!activeOptionId) return;\n document\n .getElementById(activeOptionId)\n ?.scrollIntoView?.({ block: \"nearest\" });\n }, [activeOptionId]);\n\n const renderBasicOption = (option: AutoCompleteOption) => (\n <div className={styles.basicOption}>\n {option.icon && <span className={styles.icon}>{option.icon}</span>}\n <div className={styles.content}>\n <div className={styles.label}>{option.label}</div>\n {option.description && (\n <div className={styles.description}>{option.description}</div>\n )}\n </div>\n </div>\n );\n\n const renderOptionItem = (option: AutoCompleteOption, index: number) => {\n const active = activeIndex === index;\n const highlighted = hoveredIndex === index || active;\n return (\n <div\n key={option.value}\n className={cn(styles.optionItem, {\n [styles.disabled]: option.disabled,\n [styles.highlight]: option.highlight,\n [styles.active]: highlighted,\n })}\n style={option.style}\n role=\"option\"\n // Focus stays in the input (aria-activedescendant); -1 keeps the\n // option out of the tab order while making it programmatically\n // focusable.\n tabIndex={-1}\n id={`${listboxId}-option-${index}`}\n aria-selected={active}\n aria-disabled={option.disabled || undefined}\n // keep focus (and the open dropdown) in the input while clicking\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => handleOptionClick(option)}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n handleOptionClick(option);\n }}\n onMouseEnter={() => setHoveredIndex(index)}\n onMouseLeave={() => setHoveredIndex(-1)}\n {...hooks(\"autocomplete\", \"item\", {\n highlighted,\n disabled: option.disabled,\n })}\n >\n {mode === \"custom\" && renderOption\n ? renderOption(option)\n : renderBasicOption(option)}\n </div>\n );\n };\n\n return (\n <div\n ref={setContainer}\n className={cn(styles.autoComplete, className)}\n onCompositionStart={() => {\n composing.current = true;\n }}\n onCompositionEnd={() => {\n composing.current = false;\n }}\n {...hooks(\"autocomplete\", \"root\", {\n state: shown ? \"open\" : \"closed\",\n disabled: !!field.disabled,\n readonly: !!field.readOnly,\n loading,\n })}\n >\n {label && (\n <label\n htmlFor={inputId}\n className={styles.label}\n {...hooks(\"autocomplete\", \"label\")}\n >\n {label}\n </label>\n )}\n <Input\n {...inputProps}\n id={inputId}\n disabled={field.disabled}\n readOnly={field.readOnly}\n name={name}\n ref={setInputRef}\n value={inputValue}\n onChange={(e) => handleInputChange(e.target.value)}\n onFocus={(e) => {\n open();\n inputProps?.onFocus?.(e);\n }}\n onBlur={(e) => {\n handleBlur(e);\n inputProps?.onBlur?.(e);\n }}\n onKeyDown={(e) => {\n handleKeyDown(e);\n inputProps?.onKeyDown?.(e);\n }}\n />\n\n <FloatingPanel\n ref={setDropdown}\n open={shown}\n anchor={container}\n placement={PLACEMENT[placement]}\n offset={{\n mainAxis: vertical ? offset.y : offset.x,\n crossAxis: vertical ? offset.x : offset.y,\n }}\n matchAnchorWidth=\"min\"\n // the field (label, input, suffix) is part of the dropdown layer\n branches={() => [container]}\n onEscapeKeyDown={(event) => {\n // Escape during IME composition cancels the composition only\n if (composing.current || event.isComposing) event.preventDefault();\n }}\n onDismiss={close}\n returnFocusOnEscape={() => input}\n className={cn(styles.popup, dropdownClassName)}\n {...hooks(\"autocomplete\", \"content\", { state: \"open\" })}\n >\n <div className={cn(styles.dropdown, animation && styles.animated)}>\n {/* While open the listbox always exists (aria-controls target);\n loading / empty states are presentational rows inside it. */}\n <div\n className={styles.optionList}\n role=\"listbox\"\n id={listboxId}\n aria-label={label}\n aria-busy={loading || undefined}\n {...hooks(\"autocomplete\", \"list\")}\n >\n {loading ? (\n <div\n role=\"presentation\"\n className={styles.loading}\n {...hooks(\"autocomplete\", \"loading\")}\n >\n <ProgressIndicator />\n </div>\n ) : processedOptions.length > 0 ? (\n <>\n {groupedOptions\n ? groupedOptions.map(([group, groupOptions], groupIndex) =>\n group === \"\" ? (\n // ungrouped options: no heading\n <React.Fragment key={`${groupIndex}-`}>\n {groupOptions.map((option) =>\n renderOptionItem(\n option,\n navigableOptions.indexOf(option),\n ),\n )}\n </React.Fragment>\n ) : (\n <div\n key={`${groupIndex}-${group}`}\n className={styles.optionGroup}\n role=\"group\"\n aria-label={group}\n >\n <div\n className={styles.groupLabel}\n aria-hidden=\"true\"\n {...hooks(\"autocomplete\", \"group-label\")}\n >\n {group}\n </div>\n {groupOptions.map((option) =>\n renderOptionItem(\n option,\n navigableOptions.indexOf(option),\n ),\n )}\n </div>\n ),\n )\n : processedOptions.map((option, index) =>\n renderOptionItem(option, index),\n )}\n </>\n ) : (\n <div\n role=\"presentation\"\n className={styles.empty}\n {...hooks(\"autocomplete\", \"empty\")}\n >\n {renderEmpty?.() || <Empty {...emptyProps} />}\n </div>\n )}\n </div>\n </div>\n </FloatingPanel>\n </div>\n );\n};\n\nexport default AutoComplete;\n"],"mappings":"2yBAeA,IAAMgC,GAAiB,OAAO,OAAO,CAAE,EAAG,EAAG,EAAG,CAAE,CAAC,EAC7CC,GAAsC,CAAC,EAEvCC,GAAY,CAChB,IAAK,YACL,OAAQ,eACR,KAAM,aACN,MAAO,aACT,EAQMC,GAAgB,CACpB,MACA,OACA,QACA,QAAO,QACP,QACA,WACA,UAAUF,GACV,aAAcG,EACd,YACA,eACA,UACA,eACA,eACA,UAAU,GACV,aACA,cACA,YAAY,SACZ,SAASJ,GACT,aAAY,GACZ,aACA,iBACA,2BACA,qBACA,WACA,iBAAgB,GAChB,gBAAe,GACf,aACA,YAAY,WACW,CACvB,GAAM,CAACK,E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A,MAAM,eAAgB,aAAa,EAEtC,SAAAoE,CACE,CAAA,EACJuC,EAAa,IAAK,GACjBZ,EACEjC,EACAU,EAAiB,QAAQV,CAAM,CACjC,CACF,CACG,CAlBE,EAAA,GAAG8C,EAAW,GAAGxC,GAkBnB,CAET,EACAX,EAAiB,KAAK,EAAQ,IAC5BsC,EAAiBjC,EAAQe,CAAK,CAChC,CACJ,CAAA,GAEF,EAAA1D,EAAA,IAAA,CAAC,MAAD,CACE,KAAK,eACL,UAAWrB,EAAAA,QAAO,MAClB,GAAIE,EAAAA,MAAM,eAAgB,OAAO,EAEhC,SAAA6G,KAAc,IAAK,EAAA1F,EAAA,IAAA,CAACb,GAAAA,QAAD,CAAO,GAAIwG,EAAa,CAAA,CACzC,CAAA,CAEJ,CAAA,CACF,CAAA,CACQ,CAAA,CACZ,GAET"}
|
|
1
|
+
{"version":3,"file":"AutoComplete.cjs","names":["useControllableState","useState","useMergedRefs","useId","useRef","useFormControlProps","useMemo","resolveActiveOptionIndex","ESCAPE_CONSUMER_ATTRIBUTE","styles","cn","hooks","Input","FloatingPanel","ProgressIndicator","_Fragment","React","Empty","require_runtime","require_stylingHooks","require_devWarnings","require_ProgressIndicator","require_mergeRefs","require_useControllableState","require_context","require_FloatingPanel","require_Input","require_Empty","require_autoComplete_module","react","_minerva_core","react_jsx_runtime","_minerva_dom","DEFAULT_OFFSET","EMPTY_OPTIONS","PLACEMENT","AutoComplete","defaultValueProp","inputValue","setInputValue","visible","setVisible","onDropdownVisibleChange","focusedValue","setFocusedValue","hoveredIndex","setHoveredIndex","container","setContainer","input","setInput","setInputRef","ref","dropdown","setDropdown","vertical","placement","baseId","listboxId","composing","field","inputProps","inputId","blocked","onChange","shown","open","close","processedOptions","search","result","options","filterOption","option","sortOption","groupedOptions","groupBy","groupMode","runs","group","last","groups","list","navigableOptions","interactiveOptions","loading","activeIndex","autoHighlight","moveFocus","count","index","step","i","handleOptionSelect","fillOnSelect","onSelect","handleKeyDown","event","onSubmit","handleInputChange","next","handleBlur","handleOptionClick","onOptionClick","activeOptionId","reopenRef","onClick","renderBasicOption","renderOptionItem","active","highlighted","e","mode","renderOption","className","label","offset","dropdownClassName","animation","groupOptions","groupIndex","renderEmpty","emptyProps"],"sources":["../../../../../react/src/components/AutoComplete/AutoComplete.tsx"],"sourcesContent":["import React, { useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { Input } from \"../Input\";\nimport { ProgressIndicator } from \"../ProgressIndicator\";\nimport { Empty } from \"../Empty\";\nimport type { AutoCompleteProps, AutoCompleteOption } from \"./types\";\nimport { FloatingPanel } from \"../../internal/FloatingPanel\";\nimport { useControllableState } from \"../../internal/useControllableState\";\nimport { warnControlledProps } from \"../../internal/devWarnings\";\nimport { useMergedRefs } from \"../../internal/mergeRefs\";\nimport { useFormControlProps } from \"../FormControl/context\";\nimport { hooks } from \"../../internal/stylingHooks\";\nimport styles from \"./autoComplete.module.scss\";\nimport { ESCAPE_CONSUMER_ATTRIBUTE } from \"@minerva/dom\";\nimport { resolveActiveOptionIndex } from \"@minerva/core\";\n\nconst DEFAULT_OFFSET = Object.freeze({ x: 0, y: 4 });\nconst EMPTY_OPTIONS: AutoCompleteOption[] = [];\n\nconst PLACEMENT = {\n top: \"top-start\",\n bottom: \"bottom-start\",\n left: \"left-start\",\n right: \"right-start\",\n} as const;\n\n/**\n * AutoComplete: a text input (combobox) that suggests options from a list.\n * Supports grouping, custom rendering and async loading; the input text can\n * be controlled or not. Focus stays in the input (`aria-activedescendant`).\n * For picking several values use `TagInput`.\n */\nconst AutoComplete = ({\n ref,\n name,\n label,\n mode = \"basic\",\n value,\n onChange,\n options = EMPTY_OPTIONS,\n defaultValue: defaultValueProp,\n onSelect,\n filterOption,\n groupBy,\n renderOption,\n renderEmpty,\n loading = false,\n inputProps,\n emptyProps,\n placement = \"bottom\",\n offset = DEFAULT_OFFSET,\n animation = true,\n sortOption,\n onOptionClick,\n onDropdownVisibleChange,\n dropdownClassName,\n onSubmit,\n autoHighlight = false,\n fillOnSelect = true,\n className,\n groupMode = \"first\",\n}: AutoCompleteProps) => {\n const [inputValue, setInputValue] = useControllableState({\n value,\n defaultValue: defaultValueProp ?? \"\",\n onChange,\n name: \"AutoComplete\",\n });\n const [visible, setVisible] = useControllableState({\n defaultValue: false,\n onChange: onDropdownVisibleChange,\n name: \"AutoComplete\",\n prop: \"open\",\n });\n // Keyboard highlight, by option identity (survives async option updates)\n const [focusedValue, setFocusedValue] = useState<string | number | null>(\n null,\n );\n const [hoveredIndex, setHoveredIndex] = useState(-1);\n const [container, setContainer] = useState<HTMLDivElement | null>(null);\n const [input, setInput] = useState<HTMLInputElement | null>(null);\n const setInputRef = useMergedRefs<HTMLInputElement>(setInput, ref);\n const [dropdown, setDropdown] = useState<HTMLDivElement | null>(null);\n const vertical = placement === \"top\" || placement === \"bottom\";\n\n const baseId = useId();\n const listboxId = `${baseId}-listbox`;\n // IME composition in progress: Enter / arrows belong to the IME.\n const composing = useRef(false);\n\n // FormControl wiring (id, disabled / read-only state, aria-*). The\n // input's own disabled / readOnly props still apply.\n const field = useFormControlProps({\n id: inputProps?.id,\n disabled: inputProps?.disabled,\n readOnly: inputProps?.readOnly,\n });\n const inputId = field.id ?? `${baseId}-input`;\n const blocked = !!field.disabled || !!field.readOnly;\n if (process.env.NODE_ENV !== \"production\") {\n warnControlledProps(\"AutoComplete\", {\n prop: \"value\",\n value,\n defaultProp: \"defaultValue\",\n defaultValue: defaultValueProp,\n handlerProp: \"onChange\",\n handler: onChange,\n locked: blocked,\n lockHint: \"set `inputProps.disabled` / `inputProps.readOnly`\",\n });\n }\n // A disabled / read-only field never shows (or keeps) the dropdown.\n const shown = visible && !blocked;\n\n const open = () => {\n if (!blocked) setVisible(true);\n };\n const close = () => {\n setVisible(false);\n setFocusedValue(null);\n };\n\n const processedOptions = useMemo(() => {\n const search = inputValue.toLowerCase();\n const result = options.filter((option) =>\n filterOption\n ? filterOption(inputValue, option)\n : option.label.toLowerCase().includes(search),\n );\n return sortOption ? [...result].sort(sortOption) : result;\n }, [options, inputValue, filterOption, sortOption]);\n\n /** Groups in order of first appearance, or runs of adjacent options */\n const groupedOptions = useMemo(() => {\n if (!groupBy) return null;\n if (groupMode === \"adjacent\") {\n const runs: [string, AutoCompleteOption[]][] = [];\n processedOptions.forEach((option) => {\n const group = groupBy(option);\n const last = runs[runs.length - 1];\n if (last && last[0] === group) last[1].push(option);\n else runs.push([group, [option]]);\n });\n return runs;\n }\n const groups = new Map<string, AutoCompleteOption[]>();\n processedOptions.forEach((option) => {\n const group = groupBy(option);\n const list = groups.get(group);\n if (list) list.push(option);\n else groups.set(group, [option]);\n });\n return Array.from(groups.entries());\n }, [processedOptions, groupBy, groupMode]);\n\n /** Options in display order; keyboard / hover indexes refer to this list */\n const navigableOptions = useMemo(\n () =>\n groupedOptions\n ? groupedOptions.flatMap(([, list]) => list)\n : processedOptions,\n [groupedOptions, processedOptions],\n );\n\n // Options the keyboard can reach: none while loading (they are hidden).\n const interactiveOptions = loading ? EMPTY_OPTIONS : navigableOptions;\n\n // With autoHighlight the first enabled option is active until the user\n // moves the highlight; a highlight whose option is gone falls back.\n const activeIndex = resolveActiveOptionIndex(\n interactiveOptions,\n focusedValue,\n autoHighlight && shown,\n );\n\n const moveFocus = (step: 1 | -1) => {\n const count = interactiveOptions.length;\n if (count === 0) return;\n // from \"nothing focused\", ArrowDown starts at the first option and\n // ArrowUp at the last one\n let index = activeIndex >= 0 ? activeIndex : step === 1 ? -1 : count;\n for (let i = 0; i < count; i += 1) {\n index = (index + step + count) % count;\n if (!interactiveOptions[index].disabled) {\n setFocusedValue(interactiveOptions[index].value);\n return;\n }\n }\n };\n\n const handleOptionSelect = (option: AutoCompleteOption) => {\n if (option.disabled) return;\n if (fillOnSelect) setInputValue(option.label);\n close();\n onSelect?.(option);\n };\n\n const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n if (\n blocked ||\n composing.current ||\n event.nativeEvent.isComposing ||\n event.keyCode === 229\n )\n return;\n switch (event.key) {\n case \"ArrowDown\":\n event.preventDefault();\n if (!visible) open();\n moveFocus(1);\n break;\n case \"ArrowUp\":\n event.preventDefault();\n if (!visible) open();\n moveFocus(-1);\n break;\n case \"Enter\": {\n const option = shown ? interactiveOptions[activeIndex] : undefined;\n if (option) {\n event.preventDefault();\n handleOptionSelect(option);\n } else if (onSubmit && inputValue.trim()) {\n // No active option: submit the typed text (e.g. a search).\n event.preventDefault();\n onSubmit(inputValue.trim());\n close();\n }\n break;\n }\n case \"Escape\":\n // Open: the dropdown's dismissable layer closes it (topmost only).\n // Closed: clears the text (APG combobox), `onChange(\"\")`.\n if (!shown && inputValue !== \"\") {\n event.preventDefault();\n setInputValue(\"\");\n setFocusedValue(null);\n }\n break;\n default:\n break;\n }\n };\n\n const handleInputChange = (next: string) => {\n setInputValue(next);\n setFocusedValue(null);\n open();\n };\n\n const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n const next = event.relatedTarget as Node | null;\n if (next && (dropdown?.contains(next) || container?.contains(next))) return;\n close();\n };\n\n const handleOptionClick = (option: AutoCompleteOption) => {\n if (option.disabled || composing.current) return;\n handleOptionSelect(option);\n onOptionClick?.(option);\n input?.focus();\n };\n\n // Expose combobox semantics on the inner <input>\n const activeOptionId =\n shown && activeIndex >= 0\n ? `${listboxId}-option-${activeIndex}`\n : undefined;\n useEffect(() => {\n if (!input) return;\n input.setAttribute(\"role\", \"combobox\");\n input.setAttribute(\"aria-autocomplete\", \"list\");\n input.setAttribute(\"aria-expanded\", String(shown));\n // Closed with text: Escape clears it instead of closing an enclosing\n // Modal / Drawer / Popover\n if (!shown && inputValue !== \"\") {\n input.setAttribute(ESCAPE_CONSUMER_ATTRIBUTE, \"\");\n } else input.removeAttribute(ESCAPE_CONSUMER_ATTRIBUTE);\n if (shown) input.setAttribute(\"aria-controls\", listboxId);\n else input.removeAttribute(\"aria-controls\");\n if (activeOptionId)\n input.setAttribute(\"aria-activedescendant\", activeOptionId);\n else input.removeAttribute(\"aria-activedescendant\");\n }, [input, shown, listboxId, activeOptionId, inputValue]);\n\n // Clicking the still-focused input (after a pick or Escape) reopens the\n // dropdown; focus alone does not fire again.\n const reopenRef = useRef(() => {});\n useEffect(() => {\n reopenRef.current = () => {\n if (!visible) open();\n };\n });\n useEffect(() => {\n if (!input) return;\n const onClick = () => reopenRef.current();\n input.addEventListener(\"click\", onClick);\n return () => input.removeEventListener(\"click\", onClick);\n }, [input]);\n\n // Keep the keyboard-focused option scrolled into view\n useEffect(() => {\n if (!activeOptionId) return;\n document\n .getElementById(activeOptionId)\n ?.scrollIntoView?.({ block: \"nearest\" });\n }, [activeOptionId]);\n\n const renderBasicOption = (option: AutoCompleteOption) => (\n <div className={styles.basicOption}>\n {option.icon && <span className={styles.icon}>{option.icon}</span>}\n <div className={styles.content}>\n <div className={styles.label}>{option.label}</div>\n {option.description && (\n <div className={styles.description}>{option.description}</div>\n )}\n </div>\n </div>\n );\n\n const renderOptionItem = (option: AutoCompleteOption, index: number) => {\n const active = activeIndex === index;\n const highlighted = hoveredIndex === index || active;\n return (\n <div\n key={option.value}\n className={cn(styles.optionItem, {\n [styles.disabled]: option.disabled,\n [styles.highlight]: option.highlight,\n [styles.active]: highlighted,\n })}\n style={option.style}\n role=\"option\"\n // Focus stays in the input (aria-activedescendant); -1 keeps the\n // option out of the tab order while making it programmatically\n // focusable.\n tabIndex={-1}\n id={`${listboxId}-option-${index}`}\n aria-selected={active}\n aria-disabled={option.disabled || undefined}\n // keep focus (and the open dropdown) in the input while clicking\n onMouseDown={(e) => e.preventDefault()}\n onClick={() => handleOptionClick(option)}\n onKeyDown={(e) => {\n if (e.key !== \"Enter\" && e.key !== \" \") return;\n e.preventDefault();\n handleOptionClick(option);\n }}\n onMouseEnter={() => setHoveredIndex(index)}\n onMouseLeave={() => setHoveredIndex(-1)}\n {...hooks(\"autocomplete\", \"item\", {\n highlighted,\n disabled: option.disabled,\n })}\n >\n {mode === \"custom\" && renderOption\n ? renderOption(option)\n : renderBasicOption(option)}\n </div>\n );\n };\n\n return (\n <div\n ref={setContainer}\n className={cn(styles.autoComplete, className)}\n onCompositionStart={() => {\n composing.current = true;\n }}\n onCompositionEnd={() => {\n composing.current = false;\n }}\n {...hooks(\"autocomplete\", \"root\", {\n state: shown ? \"open\" : \"closed\",\n disabled: !!field.disabled,\n readonly: !!field.readOnly,\n loading,\n })}\n >\n {label && (\n <label\n htmlFor={inputId}\n className={styles.label}\n {...hooks(\"autocomplete\", \"label\")}\n >\n {label}\n </label>\n )}\n <Input\n {...inputProps}\n id={inputId}\n disabled={field.disabled}\n readOnly={field.readOnly}\n name={name}\n ref={setInputRef}\n value={inputValue}\n onChange={(e) => handleInputChange(e.target.value)}\n onFocus={(e) => {\n open();\n inputProps?.onFocus?.(e);\n }}\n onBlur={(e) => {\n handleBlur(e);\n inputProps?.onBlur?.(e);\n }}\n onKeyDown={(e) => {\n handleKeyDown(e);\n inputProps?.onKeyDown?.(e);\n }}\n />\n\n <FloatingPanel\n ref={setDropdown}\n open={shown}\n anchor={container}\n placement={PLACEMENT[placement]}\n offset={{\n mainAxis: vertical ? offset.y : offset.x,\n crossAxis: vertical ? offset.x : offset.y,\n }}\n matchAnchorWidth=\"min\"\n // the field (label, input, suffix) is part of the dropdown layer\n branches={() => [container]}\n onEscapeKeyDown={(event) => {\n // Escape during IME composition cancels the composition only\n if (composing.current || event.isComposing) event.preventDefault();\n }}\n onDismiss={close}\n returnFocusOnEscape={() => input}\n className={cn(styles.popup, dropdownClassName)}\n {...hooks(\"autocomplete\", \"content\", { state: \"open\" })}\n >\n <div className={cn(styles.dropdown, animation && styles.animated)}>\n {/* While open the listbox always exists (aria-controls target);\n loading / empty states are presentational rows inside it. */}\n <div\n className={styles.optionList}\n role=\"listbox\"\n id={listboxId}\n aria-label={label}\n aria-busy={loading || undefined}\n {...hooks(\"autocomplete\", \"list\")}\n >\n {loading ? (\n <div\n role=\"presentation\"\n className={styles.loading}\n {...hooks(\"autocomplete\", \"loading\")}\n >\n <ProgressIndicator />\n </div>\n ) : processedOptions.length > 0 ? (\n <>\n {groupedOptions\n ? groupedOptions.map(([group, groupOptions], groupIndex) =>\n group === \"\" ? (\n // ungrouped options: no heading\n <React.Fragment key={`${groupIndex}-`}>\n {groupOptions.map((option) =>\n renderOptionItem(\n option,\n navigableOptions.indexOf(option),\n ),\n )}\n </React.Fragment>\n ) : (\n <div\n key={`${groupIndex}-${group}`}\n className={styles.optionGroup}\n role=\"group\"\n aria-label={group}\n >\n <div\n className={styles.groupLabel}\n aria-hidden=\"true\"\n {...hooks(\"autocomplete\", \"group-label\")}\n >\n {group}\n </div>\n {groupOptions.map((option) =>\n renderOptionItem(\n option,\n navigableOptions.indexOf(option),\n ),\n )}\n </div>\n ),\n )\n : processedOptions.map((option, index) =>\n renderOptionItem(option, index),\n )}\n </>\n ) : (\n <div\n role=\"presentation\"\n className={styles.empty}\n {...hooks(\"autocomplete\", \"empty\")}\n >\n {renderEmpty?.() || <Empty {...emptyProps} />}\n </div>\n )}\n </div>\n </div>\n </FloatingPanel>\n </div>\n );\n};\n\nexport default AutoComplete;\n"],"mappings":"2yBAgBA,IAAMiC,GAAiB,OAAO,OAAO,CAAE,EAAG,EAAG,EAAG,CAAE,CAAC,EAC7CC,EAAsC,CAAC,EAEvCC,GAAY,CAChB,IAAK,YACL,OAAQ,eACR,KAAM,aACN,MAAO,aACT,EAQMC,GAAgB,CACpB,MACA,OACA,QACA,QAAO,QACP,QACA,WACA,UAAUF,EACV,aAAcG,EACd,YACA,eACA,UACA,gBACA,eACA,UAAU,GACV,aACA,cACA,YAAY,SACZ,SAASJ,GACT,aAAY,GACZ,aACA,iBACA,2BACA,qBACA,WACA,iBAAgB,GAChB,gBAAe,GACf,aACA,YAAY,WACW,CACvB,GAAM,CAACK,EAAYC,GAAiBvC,EAAAA,qBAAqB,CACvD,QACA,aAAcqC,GAAoB,GAClC,WACA,KAAM,cACR,CAAC,EACK,CAACG,EAASC,GAAczC,EAAAA,qB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AiB,QAAQV,CAAM,CACjC,CACF,CACG,CAlBE,EAAA,GAAG+C,EAAW,GAAGzC,GAkBnB,CAET,EACAX,EAAiB,KAAK,EAAQ,IAC5BwC,EAAiBnC,EAAQiB,CAAK,CAChC,CACJ,CAAA,GAEF,EAAA3D,EAAA,IAAA,CAAC,MAAD,CACE,KAAK,eACL,UAAWtB,EAAAA,QAAO,MAClB,GAAIE,EAAAA,MAAM,eAAgB,OAAO,EAEhC,SAAA8G,KAAc,IAAK,EAAA1F,EAAA,IAAA,CAACd,GAAAA,QAAD,CAAO,GAAIyG,EAAa,CAAA,CACzC,CAAA,CAEJ,CAAA,CACF,CAAA,CACQ,CAAA,CACZ,GAET"}
|
|
@@ -13,59 +13,60 @@ import "../Input/index.js";
|
|
|
13
13
|
import re from "../Empty/Empty.js";
|
|
14
14
|
import "../Empty/index.js";
|
|
15
15
|
import o from "./autoComplete.module.scss.js";
|
|
16
|
-
import ie, { useEffect as s, useId as ae, useMemo as c, useRef as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
16
|
+
import ie, { useEffect as s, useId as ae, useMemo as c, useRef as l, useState as u } from "react";
|
|
17
|
+
import { resolveActiveOptionIndex as oe } from "../../../core/index.js";
|
|
18
|
+
import { Fragment as se, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
19
|
+
import { ESCAPE_CONSUMER_ATTRIBUTE as p } from "../../../dom/index.js";
|
|
19
20
|
//#region src/components/AutoComplete/AutoComplete.tsx
|
|
20
21
|
var ce = Object.freeze({
|
|
21
22
|
x: 0,
|
|
22
23
|
y: 4
|
|
23
|
-
}),
|
|
24
|
+
}), m = [], le = {
|
|
24
25
|
top: "top-start",
|
|
25
26
|
bottom: "bottom-start",
|
|
26
27
|
left: "left-start",
|
|
27
28
|
right: "right-start"
|
|
28
|
-
},
|
|
29
|
-
let [
|
|
30
|
-
value:
|
|
31
|
-
defaultValue:
|
|
32
|
-
onChange:
|
|
29
|
+
}, h = ({ ref: h, name: ue, label: g, mode: de = "basic", value: fe, onChange: pe, options: _ = m, defaultValue: me, onSelect: he, filterOption: v, groupBy: y, renderOption: b, renderEmpty: ge, loading: x = !1, inputProps: S, emptyProps: _e, placement: C = "bottom", offset: w = ce, animation: ve = !0, sortOption: T, onOptionClick: ye, onDropdownVisibleChange: be, dropdownClassName: xe, onSubmit: E, autoHighlight: Se = !1, fillOnSelect: Ce = !0, className: we, groupMode: D = "first" }) => {
|
|
30
|
+
let [O, k] = a({
|
|
31
|
+
value: fe,
|
|
32
|
+
defaultValue: me ?? "",
|
|
33
|
+
onChange: pe,
|
|
33
34
|
name: "AutoComplete"
|
|
34
|
-
}), [
|
|
35
|
+
}), [A, j] = a({
|
|
35
36
|
defaultValue: !1,
|
|
36
37
|
onChange: be,
|
|
37
38
|
name: "AutoComplete",
|
|
38
39
|
prop: "open"
|
|
39
|
-
}), [
|
|
40
|
-
id:
|
|
41
|
-
disabled:
|
|
42
|
-
readOnly:
|
|
40
|
+
}), [Te, M] = u(null), [Ee, N] = u(-1), [P, De] = u(null), [F, Oe] = u(null), ke = i(Oe, h), [Ae, je] = u(null), I = C === "top" || C === "bottom", L = ae(), R = `${L}-listbox`, z = l(!1), B = ee({
|
|
41
|
+
id: S?.id,
|
|
42
|
+
disabled: S?.disabled,
|
|
43
|
+
readOnly: S?.readOnly
|
|
43
44
|
}), V = B.id ?? `${L}-input`, H = !!B.disabled || !!B.readOnly;
|
|
44
45
|
process.env.NODE_ENV !== "production" && n("AutoComplete", {
|
|
45
46
|
prop: "value",
|
|
46
|
-
value:
|
|
47
|
+
value: fe,
|
|
47
48
|
defaultProp: "defaultValue",
|
|
48
|
-
defaultValue:
|
|
49
|
+
defaultValue: me,
|
|
49
50
|
handlerProp: "onChange",
|
|
50
|
-
handler:
|
|
51
|
+
handler: pe,
|
|
51
52
|
locked: H,
|
|
52
53
|
lockHint: "set `inputProps.disabled` / `inputProps.readOnly`"
|
|
53
54
|
});
|
|
54
|
-
let U =
|
|
55
|
-
H ||
|
|
55
|
+
let U = A && !H, W = () => {
|
|
56
|
+
H || j(!0);
|
|
56
57
|
}, G = () => {
|
|
57
|
-
|
|
58
|
+
j(!1), M(null);
|
|
58
59
|
}, K = c(() => {
|
|
59
|
-
let e =
|
|
60
|
-
return
|
|
60
|
+
let e = O.toLowerCase(), t = _.filter((t) => v ? v(O, t) : t.label.toLowerCase().includes(e));
|
|
61
|
+
return T ? [...t].sort(T) : t;
|
|
61
62
|
}, [
|
|
62
63
|
_,
|
|
63
|
-
|
|
64
|
+
O,
|
|
64
65
|
v,
|
|
65
|
-
|
|
66
|
+
T
|
|
66
67
|
]), q = c(() => {
|
|
67
68
|
if (!y) return null;
|
|
68
|
-
if (
|
|
69
|
+
if (D === "adjacent") {
|
|
69
70
|
let e = [];
|
|
70
71
|
return K.forEach((t) => {
|
|
71
72
|
let n = y(t), r = e[e.length - 1];
|
|
@@ -80,53 +81,53 @@ var ce = Object.freeze({
|
|
|
80
81
|
}, [
|
|
81
82
|
K,
|
|
82
83
|
y,
|
|
83
|
-
|
|
84
|
-
]), J = c(() => q ? q.flatMap(([, e]) => e) : K, [q, K]), Y =
|
|
85
|
-
let t =
|
|
84
|
+
D
|
|
85
|
+
]), J = c(() => q ? q.flatMap(([, e]) => e) : K, [q, K]), Y = x ? m : J, X = oe(Y, Te, Se && U), Me = (e) => {
|
|
86
|
+
let t = Y.length;
|
|
86
87
|
if (t === 0) return;
|
|
87
|
-
let n =
|
|
88
|
-
for (let r = 0; r < t; r += 1) if (n = (n + e + t) % t, !
|
|
89
|
-
M(n);
|
|
88
|
+
let n = X >= 0 ? X : e === 1 ? -1 : t;
|
|
89
|
+
for (let r = 0; r < t; r += 1) if (n = (n + e + t) % t, !Y[n].disabled) {
|
|
90
|
+
M(Y[n].value);
|
|
90
91
|
return;
|
|
91
92
|
}
|
|
92
|
-
},
|
|
93
|
-
e.disabled || (Ce &&
|
|
94
|
-
},
|
|
93
|
+
}, Ne = (e) => {
|
|
94
|
+
e.disabled || (Ce && k(e.label), G(), he?.(e));
|
|
95
|
+
}, Pe = (e) => {
|
|
95
96
|
if (!(H || z.current || e.nativeEvent.isComposing || e.keyCode === 229)) switch (e.key) {
|
|
96
97
|
case "ArrowDown":
|
|
97
|
-
e.preventDefault(),
|
|
98
|
+
e.preventDefault(), A || W(), Me(1);
|
|
98
99
|
break;
|
|
99
100
|
case "ArrowUp":
|
|
100
|
-
e.preventDefault(),
|
|
101
|
+
e.preventDefault(), A || W(), Me(-1);
|
|
101
102
|
break;
|
|
102
103
|
case "Enter": {
|
|
103
|
-
let t = U ?
|
|
104
|
-
t ? (e.preventDefault(),
|
|
104
|
+
let t = U ? Y[X] : void 0;
|
|
105
|
+
t ? (e.preventDefault(), Ne(t)) : E && O.trim() && (e.preventDefault(), E(O.trim()), G());
|
|
105
106
|
break;
|
|
106
107
|
}
|
|
107
|
-
case "Escape": !U &&
|
|
108
|
+
case "Escape": !U && O !== "" && (e.preventDefault(), k(""), M(null));
|
|
108
109
|
}
|
|
109
|
-
}, Ne = (e) => {
|
|
110
|
-
O(e), M(-1), W();
|
|
111
|
-
}, Pe = (e) => {
|
|
112
|
-
let t = e.relatedTarget;
|
|
113
|
-
t && (ke?.contains(t) || P?.contains(t)) || G();
|
|
114
110
|
}, Fe = (e) => {
|
|
115
|
-
|
|
116
|
-
},
|
|
111
|
+
k(e), M(null), W();
|
|
112
|
+
}, Ie = (e) => {
|
|
113
|
+
let t = e.relatedTarget;
|
|
114
|
+
t && (Ae?.contains(t) || P?.contains(t)) || G();
|
|
115
|
+
}, Le = (e) => {
|
|
116
|
+
e.disabled || z.current || (Ne(e), ye?.(e), F?.focus());
|
|
117
|
+
}, Z = U && X >= 0 ? `${R}-option-${X}` : void 0;
|
|
117
118
|
s(() => {
|
|
118
|
-
F && (F.setAttribute("role", "combobox"), F.setAttribute("aria-autocomplete", "list"), F.setAttribute("aria-expanded", String(U)), !U &&
|
|
119
|
+
F && (F.setAttribute("role", "combobox"), F.setAttribute("aria-autocomplete", "list"), F.setAttribute("aria-expanded", String(U)), !U && O !== "" ? F.setAttribute(p, "") : F.removeAttribute(p), U ? F.setAttribute("aria-controls", R) : F.removeAttribute("aria-controls"), Z ? F.setAttribute("aria-activedescendant", Z) : F.removeAttribute("aria-activedescendant"));
|
|
119
120
|
}, [
|
|
120
121
|
F,
|
|
121
122
|
U,
|
|
122
123
|
R,
|
|
123
124
|
Z,
|
|
124
|
-
|
|
125
|
+
O
|
|
125
126
|
]);
|
|
126
|
-
let Q =
|
|
127
|
+
let Q = l(() => {});
|
|
127
128
|
s(() => {
|
|
128
129
|
Q.current = () => {
|
|
129
|
-
|
|
130
|
+
A || W();
|
|
130
131
|
};
|
|
131
132
|
}), s(() => {
|
|
132
133
|
if (!F) return;
|
|
@@ -135,24 +136,24 @@ var ce = Object.freeze({
|
|
|
135
136
|
}, [F]), s(() => {
|
|
136
137
|
Z && document.getElementById(Z)?.scrollIntoView?.({ block: "nearest" });
|
|
137
138
|
}, [Z]);
|
|
138
|
-
let
|
|
139
|
+
let Re = (e) => /* @__PURE__ */ f("div", {
|
|
139
140
|
className: o.basicOption,
|
|
140
|
-
children: [e.icon && /* @__PURE__ */
|
|
141
|
+
children: [e.icon && /* @__PURE__ */ d("span", {
|
|
141
142
|
className: o.icon,
|
|
142
143
|
children: e.icon
|
|
143
|
-
}), /* @__PURE__ */
|
|
144
|
+
}), /* @__PURE__ */ f("div", {
|
|
144
145
|
className: o.content,
|
|
145
|
-
children: [/* @__PURE__ */
|
|
146
|
+
children: [/* @__PURE__ */ d("div", {
|
|
146
147
|
className: o.label,
|
|
147
148
|
children: e.label
|
|
148
|
-
}), e.description && /* @__PURE__ */
|
|
149
|
+
}), e.description && /* @__PURE__ */ d("div", {
|
|
149
150
|
className: o.description,
|
|
150
151
|
children: e.description
|
|
151
152
|
})]
|
|
152
153
|
})]
|
|
153
154
|
}), $ = (n, r) => {
|
|
154
|
-
let i =
|
|
155
|
-
return /* @__PURE__ */
|
|
155
|
+
let i = X === r, a = Ee === r || i;
|
|
156
|
+
return /* @__PURE__ */ d("div", {
|
|
156
157
|
className: e(o.optionItem, {
|
|
157
158
|
[o.disabled]: n.disabled,
|
|
158
159
|
[o.highlight]: n.highlight,
|
|
@@ -165,9 +166,9 @@ var ce = Object.freeze({
|
|
|
165
166
|
"aria-selected": i,
|
|
166
167
|
"aria-disabled": n.disabled || void 0,
|
|
167
168
|
onMouseDown: (e) => e.preventDefault(),
|
|
168
|
-
onClick: () =>
|
|
169
|
+
onClick: () => Le(n),
|
|
169
170
|
onKeyDown: (e) => {
|
|
170
|
-
(e.key === "Enter" || e.key === " ") && (e.preventDefault(),
|
|
171
|
+
(e.key === "Enter" || e.key === " ") && (e.preventDefault(), Le(n));
|
|
171
172
|
},
|
|
172
173
|
onMouseEnter: () => N(r),
|
|
173
174
|
onMouseLeave: () => N(-1),
|
|
@@ -175,11 +176,11 @@ var ce = Object.freeze({
|
|
|
175
176
|
highlighted: a,
|
|
176
177
|
disabled: n.disabled
|
|
177
178
|
}),
|
|
178
|
-
children:
|
|
179
|
+
children: de === "custom" && b ? b(n) : Re(n)
|
|
179
180
|
}, n.value);
|
|
180
181
|
};
|
|
181
|
-
return /* @__PURE__ */
|
|
182
|
-
ref:
|
|
182
|
+
return /* @__PURE__ */ f("div", {
|
|
183
|
+
ref: De,
|
|
183
184
|
className: e(o.autoComplete, we),
|
|
184
185
|
onCompositionStart: () => {
|
|
185
186
|
z.current = !0;
|
|
@@ -191,42 +192,42 @@ var ce = Object.freeze({
|
|
|
191
192
|
state: U ? "open" : "closed",
|
|
192
193
|
disabled: !!B.disabled,
|
|
193
194
|
readonly: !!B.readOnly,
|
|
194
|
-
loading:
|
|
195
|
+
loading: x
|
|
195
196
|
}),
|
|
196
197
|
children: [
|
|
197
|
-
|
|
198
|
+
g && /* @__PURE__ */ d("label", {
|
|
198
199
|
htmlFor: V,
|
|
199
200
|
className: o.label,
|
|
200
201
|
...t("autocomplete", "label"),
|
|
201
|
-
children:
|
|
202
|
+
children: g
|
|
202
203
|
}),
|
|
203
|
-
/* @__PURE__ */
|
|
204
|
-
...
|
|
204
|
+
/* @__PURE__ */ d(ne, {
|
|
205
|
+
...S,
|
|
205
206
|
id: V,
|
|
206
207
|
disabled: B.disabled,
|
|
207
208
|
readOnly: B.readOnly,
|
|
208
|
-
name:
|
|
209
|
-
ref:
|
|
210
|
-
value:
|
|
211
|
-
onChange: (e) =>
|
|
209
|
+
name: ue,
|
|
210
|
+
ref: ke,
|
|
211
|
+
value: O,
|
|
212
|
+
onChange: (e) => Fe(e.target.value),
|
|
212
213
|
onFocus: (e) => {
|
|
213
|
-
W(),
|
|
214
|
+
W(), S?.onFocus?.(e);
|
|
214
215
|
},
|
|
215
216
|
onBlur: (e) => {
|
|
216
|
-
|
|
217
|
+
Ie(e), S?.onBlur?.(e);
|
|
217
218
|
},
|
|
218
219
|
onKeyDown: (e) => {
|
|
219
|
-
|
|
220
|
+
Pe(e), S?.onKeyDown?.(e);
|
|
220
221
|
}
|
|
221
222
|
}),
|
|
222
|
-
/* @__PURE__ */
|
|
223
|
-
ref:
|
|
223
|
+
/* @__PURE__ */ d(te, {
|
|
224
|
+
ref: je,
|
|
224
225
|
open: U,
|
|
225
226
|
anchor: P,
|
|
226
|
-
placement:
|
|
227
|
+
placement: le[C],
|
|
227
228
|
offset: {
|
|
228
|
-
mainAxis: I ?
|
|
229
|
-
crossAxis: I ?
|
|
229
|
+
mainAxis: I ? w.y : w.x,
|
|
230
|
+
crossAxis: I ? w.x : w.y
|
|
230
231
|
},
|
|
231
232
|
matchAnchorWidth: "min",
|
|
232
233
|
branches: () => [P],
|
|
@@ -237,35 +238,35 @@ var ce = Object.freeze({
|
|
|
237
238
|
returnFocusOnEscape: () => F,
|
|
238
239
|
className: e(o.popup, xe),
|
|
239
240
|
...t("autocomplete", "content", { state: "open" }),
|
|
240
|
-
children: /* @__PURE__ */
|
|
241
|
+
children: /* @__PURE__ */ d("div", {
|
|
241
242
|
className: e(o.dropdown, ve && o.animated),
|
|
242
|
-
children: /* @__PURE__ */
|
|
243
|
+
children: /* @__PURE__ */ d("div", {
|
|
243
244
|
className: o.optionList,
|
|
244
245
|
role: "listbox",
|
|
245
246
|
id: R,
|
|
246
|
-
"aria-label":
|
|
247
|
-
"aria-busy":
|
|
247
|
+
"aria-label": g,
|
|
248
|
+
"aria-busy": x || void 0,
|
|
248
249
|
...t("autocomplete", "list"),
|
|
249
|
-
children:
|
|
250
|
+
children: x ? /* @__PURE__ */ d("div", {
|
|
250
251
|
role: "presentation",
|
|
251
252
|
className: o.loading,
|
|
252
253
|
...t("autocomplete", "loading"),
|
|
253
|
-
children: /* @__PURE__ */
|
|
254
|
-
}) : K.length > 0 ? /* @__PURE__ */
|
|
254
|
+
children: /* @__PURE__ */ d(r, {})
|
|
255
|
+
}) : K.length > 0 ? /* @__PURE__ */ d(se, { children: q ? q.map(([e, n], r) => e === "" ? /* @__PURE__ */ d(ie.Fragment, { children: n.map((e) => $(e, J.indexOf(e))) }, `${r}-`) : /* @__PURE__ */ f("div", {
|
|
255
256
|
className: o.optionGroup,
|
|
256
257
|
role: "group",
|
|
257
258
|
"aria-label": e,
|
|
258
|
-
children: [/* @__PURE__ */
|
|
259
|
+
children: [/* @__PURE__ */ d("div", {
|
|
259
260
|
className: o.groupLabel,
|
|
260
261
|
"aria-hidden": "true",
|
|
261
262
|
...t("autocomplete", "group-label"),
|
|
262
263
|
children: e
|
|
263
264
|
}), n.map((e) => $(e, J.indexOf(e)))]
|
|
264
|
-
}, `${r}-${e}`)) : K.map((e, t) => $(e, t)) }) : /* @__PURE__ */
|
|
265
|
+
}, `${r}-${e}`)) : K.map((e, t) => $(e, t)) }) : /* @__PURE__ */ d("div", {
|
|
265
266
|
role: "presentation",
|
|
266
267
|
className: o.empty,
|
|
267
268
|
...t("autocomplete", "empty"),
|
|
268
|
-
children: ge?.() || /* @__PURE__ */
|
|
269
|
+
children: ge?.() || /* @__PURE__ */ d(re, { ..._e })
|
|
269
270
|
})
|
|
270
271
|
})
|
|
271
272
|
})
|
|
@@ -274,6 +275,6 @@ var ce = Object.freeze({
|
|
|
274
275
|
});
|
|
275
276
|
};
|
|
276
277
|
//#endregion
|
|
277
|
-
export {
|
|
278
|
+
export { h as default };
|
|
278
279
|
|
|
279
280
|
//# sourceMappingURL=AutoComplete.js.map
|