blowfish/node_modules/@headlessui/react/dist/components/combobox/combobox.js

2 lines
14 KiB
JavaScript
Raw Normal View History

2023-01-29 22:30:24 +00:00
import q,{Fragment as ce,createContext as le,createRef as fe,useCallback as me,useContext as ie,useMemo as D,useReducer as Te,useRef as E,useEffect as xe}from"react";import{useComputed as z}from'../../hooks/use-computed.js';import{useDisposables as ee}from'../../hooks/use-disposables.js';import{useEvent as g}from'../../hooks/use-event.js';import{useId as W}from'../../hooks/use-id.js';import{useIsoMorphicEffect as F}from'../../hooks/use-iso-morphic-effect.js';import{useLatestValue as ge}from'../../hooks/use-latest-value.js';import{useOutsideClick as Oe}from'../../hooks/use-outside-click.js';import{useResolveButtonType as Ce}from'../../hooks/use-resolve-button-type.js';import{useSyncRefs as X}from'../../hooks/use-sync-refs.js';import{useTreeWalker as Re}from'../../hooks/use-tree-walker.js';import{calculateActiveIndex as ve,Focus as y}from'../../utils/calculate-active-index.js';import{disposables as ue}from'../../utils/disposables.js';import{forwardRefWithAs as w,render as B,compact as ye,Features as pe}from'../../utils/render.js';import{isDisabledReactIssue7711 as Se}from'../../utils/bugs.js';import{match as U}from'../../utils/match.js';import{objectToFormEntries as Ae}from'../../utils/form.js';import{sortByDomNode as Pe}from'../../utils/focus-management.js';import{Hidden as Ee,Features as Ie}from'../../internal/hidden.js';import{useOpenClosed as Le,State as oe,OpenClosedProvider as De}from'../../internal/open-closed.js';import{Keys as S}from'../keyboard.js';import{useControllable as Ve}from'../../hooks/use-controllable.js';import{useWatch as Me}from'../../hooks/use-watch.js';import{useTrackedPointer as he}from'../../hooks/use-tracked-pointer.js';var Fe=(n=>(n[n.Open=0]="Open",n[n.Closed=1]="Closed",n))(Fe||{}),_e=(n=>(n[n.Single=0]="Single",n[n.Multi=1]="Multi",n))(_e||{}),ke=(n=>(n[n.Pointer=0]="Pointer",n[n.Other=1]="Other",n))(ke||{}),we=(l=>(l[l.OpenCombobox=0]="OpenCombobox",l[l.CloseCombobox=1]="CloseCombobox",l[l.GoToOption=2]="GoToOption",l[l.RegisterOption=3]="RegisterOption",l[l.UnregisterOption=4]="UnregisterOption",l[l.RegisterLabel=5]="RegisterLabel",l))(we||{});function te(t,r=n=>n){let n=t.activeOptionIndex!==null?t.options[t.activeOptionIndex]:null,o=Pe(r(t.options.slice()),i=>i.dataRef.current.domRef.current),a=n?o.indexOf(n):null;return a===-1&&(a=null),{options:o,activeOptionIndex:a}}let Be={[1](t){return t.dataRef.current.disabled||t.comboboxState===1?t:{...t,activeOptionIndex:null,comboboxState:1}},[0](t){if(t.dataRef.current.disabled||t.comboboxState===0)return t;let r=t.activeOptionIndex,{isSelected:n}=t.dataRef.current,o=t.options.findIndex(a=>n(a.dataRef.current.value));return o!==-1&&(r=o),{...t,comboboxState:0,activeOptionIndex:r}},[2](t,r){var a;if(t.dataRef.current.disabled||t.dataRef.current.optionsRef.current&&!t.dataRef.current.optionsPropsRef.current.static&&t.comboboxState===1)return t;let n=te(t);if(n.activeOptionIndex===null){let i=n.options.findIndex(l=>!l.dataRef.current.disabled);i!==-1&&(n.activeOptionIndex=i)}let o=ve(r,{resolveItems:()=>n.options,resolveActiveIndex:()=>n.activeOptionIndex,resolveId:i=>i.id,resolveDisabled:i=>i.dataRef.current.disabled});return{...t,...n,activeOptionIndex:o,activationTrigger:(a=r.trigger)!=null?a:1}},[3]:(t,r)=>{let n={id:r.id,dataRef:r.dataRef},o=te(t,i=>[...i,n]);t.activeOptionIndex===null&&t.dataRef.current.isSelected(r.dataRef.current.value)&&(o.activeOptionIndex=o.options.indexOf(n));let a={...t,...o,activationTrigger:1};return t.dataRef.current.__demoMode&&t.dataRef.current.value===void 0&&(a.activeOptionIndex=0),a},[4]:(t,r)=>{let n=te(t,o=>{let a=o.findIndex(i=>i.id===r.id);return a!==-1&&o.splice(a,1),o});return{...t,...n,activationTrigger:1}},[5]:(t,r)=>({...t,labelId:r.id})},ne=le(null);ne.displayName="ComboboxActionsContext";function $(t){let r=ie(ne);if(r===null){let n=new Error(`<${t} /> is missing a parent <Combobox /> component.`);throw Error.captureStackTrace&&Error.captureStackTrace(n,$),n}return r}let re=le(null);re.displayName="ComboboxDataContext";function G(t){let r=ie(re);if(r===null){let n=new Error(`<${t} /> is missing a p