@pdanpdan/headless-combobox-core 0.0.0-stage → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +70 -2
- package/dist/accessibility.d.ts +24 -0
- package/dist/accessibility.d.ts.map +1 -0
- package/dist/context.d.ts +38 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/filtering.d.ts +16 -0
- package/dist/filtering.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +674 -0
- package/dist/index.mjs.map +1 -0
- package/dist/navigation.d.ts +26 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/popover.d.ts +24 -0
- package/dist/popover.d.ts.map +1 -0
- package/dist/positioning.d.ts +17 -0
- package/dist/positioning.d.ts.map +1 -0
- package/dist/runtime.d.ts +19 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/selection.d.ts +24 -0
- package/dist/selection.d.ts.map +1 -0
- package/dist/store.d.ts +36 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/types.d.ts +158 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/validation.d.ts +9 -0
- package/dist/validation.d.ts.map +1 -0
- package/package.json +65 -3
- package/src/accessibility.ts +130 -0
- package/src/context.ts +52 -0
- package/src/filtering.ts +70 -0
- package/src/index.ts +18 -0
- package/src/navigation.ts +286 -0
- package/src/popover.ts +206 -0
- package/src/positioning.ts +112 -0
- package/src/runtime.ts +31 -0
- package/src/selection.ts +144 -0
- package/src/store.ts +420 -0
- package/src/types.ts +170 -0
- package/src/validation.ts +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pdanpdan/headless-combobox-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The framework-independent combobox state machine behind every adapter. Zero dependencies, no framework imports. It owns selection, filtering, validation, keyboard navigation, popup lifecycle, CSS-anchor positioning, and focus management; adapters only translate its snapshot into their reactive primitive and supply DOM refs.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @pdanpdan/headless-combobox-core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createCombobox } from '@pdanpdan/headless-combobox-core';
|
|
15
|
+
|
|
16
|
+
const store = createCombobox<string>({
|
|
17
|
+
props: {
|
|
18
|
+
modelValue: null,
|
|
19
|
+
options: [ 'JavaScript', 'TypeScript', 'Rust' ],
|
|
20
|
+
},
|
|
21
|
+
onChange: (value) => {
|
|
22
|
+
console.log('selected', value);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Lazy, revision-keyed snapshot: state + actions + ARIA prop bags.
|
|
27
|
+
const subscribe = store.subscribe(() => {
|
|
28
|
+
render(store.getSnapshot());
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const triggerElement = document.createElement('button');
|
|
32
|
+
const dropdownElement = document.createElement('div');
|
|
33
|
+
store.getSnapshot().setTriggerRef(triggerElement);
|
|
34
|
+
store.getSnapshot().setDropdownRef(dropdownElement);
|
|
35
|
+
store.mount(); // document-level click-outside / Escape listeners
|
|
36
|
+
|
|
37
|
+
render(store.getSnapshot());
|
|
38
|
+
|
|
39
|
+
function render(scope) {
|
|
40
|
+
// bind scope.triggerProps, scope.listboxProps, scope.getOptionProps(...)
|
|
41
|
+
console.log(scope.triggerProps.id, scope.filteredOptions.length);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// teardown
|
|
45
|
+
subscribe();
|
|
46
|
+
store.destroy();
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Adapters pass a runtime for the three framework-specific concerns:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { createCombobox } from '@pdanpdan/headless-combobox-core';
|
|
53
|
+
|
|
54
|
+
const props = {
|
|
55
|
+
modelValue: null,
|
|
56
|
+
options: [ 'One', 'Two' ],
|
|
57
|
+
};
|
|
58
|
+
const onChange = (value) => console.log(value);
|
|
59
|
+
|
|
60
|
+
createCombobox({
|
|
61
|
+
props,
|
|
62
|
+
onChange,
|
|
63
|
+
runtime: {
|
|
64
|
+
nextTick: () => Promise.resolve(), // resolve after the framework commits the DOM
|
|
65
|
+
unwrap: (value) => value, // Vue passes toRaw; others keep identity
|
|
66
|
+
createId: () => 'combobox', // optional stable id source
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The store is a plain object: `getSnapshot()`, `subscribe()`, `setProps()`, `setState()`, `mount()`, `destroy()`. The snapshot's identity changes only when state or props change, so it plugs directly into React's `useSyncExternalStore`, Svelte stores, Solid signals, and Angular signals.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ComboboxContext } from './context';
|
|
2
|
+
import { HeadlessComboboxComboboxInputProps, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxTriggerProps } from './types';
|
|
3
|
+
/** Late-bound actions the ARIA prop bags need (wired by the store). */
|
|
4
|
+
export interface AccessibilityDeps<O> {
|
|
5
|
+
select: (option: O) => void;
|
|
6
|
+
setHighlightedIndex: (index: number) => void;
|
|
7
|
+
toggle: () => void;
|
|
8
|
+
handleKeydown: (event: Event) => void;
|
|
9
|
+
open: () => Promise<void>;
|
|
10
|
+
setQueryFromEvent: (event: Event) => void;
|
|
11
|
+
openAndSetQueryFromEvent: (event: Event) => void;
|
|
12
|
+
isSelected: (option: O) => boolean;
|
|
13
|
+
isOptionDisabled: (option: O) => boolean;
|
|
14
|
+
}
|
|
15
|
+
/** Ids, the anchor name, and the ARIA prop bags spread onto consumer markup. */
|
|
16
|
+
export declare function createAccessibility<O, V, Q>(ctx: ComboboxContext<O, V, Q>, instanceId: string, deps: AccessibilityDeps<O>): {
|
|
17
|
+
cssAnchorName: string;
|
|
18
|
+
getTriggerProps: () => HeadlessComboboxTriggerProps;
|
|
19
|
+
getInputProps: () => HeadlessComboboxInputProps;
|
|
20
|
+
getComboboxInputProps: () => HeadlessComboboxComboboxInputProps;
|
|
21
|
+
getListboxProps: () => HeadlessComboboxListboxProps;
|
|
22
|
+
getOptionProps: (option: O, index: number) => HeadlessComboboxOptionProps;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=accessibility.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accessibility.d.ts","sourceRoot":"","sources":["../src/accessibility.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,kCAAkC,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AAIvL,uEAAuE;AACvE,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;IAC5B,mBAAmB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC1C,wBAAwB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjD,UAAU,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;IACnC,gBAAgB,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;CAC1C;AAED,gFAAgF;AAChF,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACzC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC7B,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;;;;;;6BAmEM,CAAC,SAAS,MAAM,KAAG,2BAA2B;EAwC/E"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ComboboxRuntime } from './runtime';
|
|
2
|
+
import { HeadlessComboboxDomRefs, HeadlessComboboxProps } from './types';
|
|
3
|
+
export interface ComboboxState<Q> {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
searchQuery: Q | undefined;
|
|
6
|
+
highlightedIndex: number;
|
|
7
|
+
alignmentOffset: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Shared mutable context. Feature modules receive it instead of Vue refs and
|
|
11
|
+
* computed values; every mutation goes through `mutate`, which bumps `version`
|
|
12
|
+
* so lazily computed values know they are stale.
|
|
13
|
+
*/
|
|
14
|
+
export interface ComboboxContext<O, V, Q> {
|
|
15
|
+
props: HeadlessComboboxProps<O, V, Q>;
|
|
16
|
+
state: ComboboxState<Q>;
|
|
17
|
+
refs: HeadlessComboboxDomRefs<O>;
|
|
18
|
+
runtime: ComboboxRuntime;
|
|
19
|
+
/** Monotonic revision; changes whenever props or state change. */
|
|
20
|
+
version: number;
|
|
21
|
+
/** Batch state changes and notify subscribers once at the end. */
|
|
22
|
+
mutate: <T>(fn: () => T) => T;
|
|
23
|
+
/** Mark state as changed (invalidates memoized values immediately). */
|
|
24
|
+
bump: () => void;
|
|
25
|
+
/** The model value, including any change emitted but not yet round-tripped through props. */
|
|
26
|
+
getModelValue: () => V | V[] | null;
|
|
27
|
+
/** Record and publish a model change. Call inside `mutate`. */
|
|
28
|
+
emitModel: (value: V | V[] | null) => void;
|
|
29
|
+
nextTick: () => Promise<void>;
|
|
30
|
+
unwrap: <T>(value: T) => T;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Lazy memoization keyed by the context revision. A state change bumps the
|
|
34
|
+
* version, so values read later in the same mutation are recomputed, while
|
|
35
|
+
* repeated reads in one revision stay cached.
|
|
36
|
+
*/
|
|
37
|
+
export declare function createMemo<T>(ctx: Pick<ComboboxContext<never, never, never>, 'version'>): (compute: () => T) => () => T;
|
|
38
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/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K,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,MAAM,CAAC,CAYvH"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ComboboxContext } from './context';
|
|
2
|
+
/** Late-bound popup action the filtering needs (wired by the store). */
|
|
3
|
+
export interface FilteringHooks {
|
|
4
|
+
/** `selectText: false` when the popup reopens by typing, so the input text must not be selected then. */
|
|
5
|
+
open: (selectText?: boolean) => Promise<void>;
|
|
6
|
+
/** Reset the highlight after a query change (wired by the store). */
|
|
7
|
+
onQueryChange?: () => void;
|
|
8
|
+
}
|
|
9
|
+
/** Search query, filtering, and the resulting options list. */
|
|
10
|
+
export declare function createFiltering<O, V, Q>(ctx: ComboboxContext<O, V, Q>, hooks: FilteringHooks): {
|
|
11
|
+
getFilteredOptions: () => O[];
|
|
12
|
+
setSearchQuery: (val: Q | undefined) => void;
|
|
13
|
+
setQueryFromEvent: (event: Event) => void;
|
|
14
|
+
openAndSetQueryFromEvent: (event: Event) => void;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=filtering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filtering.d.ts","sourceRoot":"","sources":["../src/filtering.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAIjD,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,yGAAyG;IACzG,IAAI,EAAE,CAAC,UAAU,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,qEAAqE;IACrE,aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAED,+DAA+D;AAC/D,wBAAgB,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACrC,GAAG,EAAE,eAAe,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC7B,KAAK,EAAE,cAAc;;0BAuBQ,CAAC,GAAG,SAAS;+BAaR,KAAK;sCAOE,KAAK;EAW/C"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return t=>{let n=-1,r;return()=>(n!==e.version&&(r=t(),n=e.version),r)}}function t(t,n,r){let i=n.replace(/[^\w-]/g,`-`),a=`${i}-listbox`,o=`${i}-trigger`,s=`${i}-input`,c=e=>`${i}-opt-${e}`,l=`--anchor-${i}`,u=e(t)(()=>{if(t.state.isOpen&&t.state.highlightedIndex!==-1)return c(t.state.highlightedIndex)}),d=e(t)(()=>({id:o,role:`combobox`,"aria-controls":a,"aria-expanded":t.state.isOpen,"aria-haspopup":`listbox`,"aria-activedescendant":u(),disabled:t.props.disabled?!0:void 0,"aria-disabled":t.props.disabled?!0:void 0,"aria-readonly":t.props.readonly?!0:void 0,onClick:r.toggle,onKeydown:r.handleKeydown})),f=e(t)(()=>({id:s,role:`searchbox`,"aria-autocomplete":`list`,"aria-controls":a,"aria-activedescendant":u(),onInput:r.setQueryFromEvent,onKeydown:r.handleKeydown})),p=e(t)(()=>({id:s,role:`combobox`,"aria-autocomplete":`list`,"aria-controls":a,"aria-expanded":t.state.isOpen,"aria-haspopup":`listbox`,"aria-activedescendant":u(),"aria-disabled":t.props.disabled?!0:void 0,"aria-readonly":t.props.readonly?!0:void 0,disabled:t.props.disabled?!0:void 0,readonly:t.props.readonly?!0:void 0,onClick:r.open,onFocus:r.open,onInput:r.openAndSetQueryFromEvent})),m=e(t)(()=>({id:a,role:`listbox`,"aria-multiselectable":t.props.multiple?!0:void 0}));function h(e,n){let i=()=>!r.isOptionDisabled(e);return{id:c(n),role:`option`,"aria-selected":r.isSelected(e),"aria-disabled":r.isOptionDisabled(e)?!0:void 0,"data-highlighted":n===t.state.highlightedIndex||void 0,onClick:()=>r.select(e),onMousedown:e=>e.preventDefault(),onMousemove:()=>{i()&&r.setHighlightedIndex(n)},onFocus:()=>{i()&&r.setHighlightedIndex(n)},onKeydown:r.handleKeydown}}return{cssAnchorName:l,getTriggerProps:d,getInputProps:f,getComboboxInputProps:p,getListboxProps:m,getOptionProps:h}}function n(t,n){function r(e){return t.props.optionLabel?t.props.optionLabel(e):String(e)}function i(e,n){return t.props.optionFilter?t.props.optionFilter(e,n):r(e).toLowerCase().includes(String(n).toLowerCase())}let a=e(t)(()=>{let e=t.state.searchQuery;return e==null||typeof e==`string`&&e===``?t.props.options:t.props.options.filter(t=>i(t,e))});function o(e){Object.is(t.state.searchQuery,e)||t.mutate(()=>{t.state.searchQuery=e,t.bump(),n.onQueryChange?.()})}function s(e){o(e.target.value)}function c(e){n.open(!1),s(e)}return{getFilteredOptions:a,setSearchQuery:o,setQueryFromEvent:s,openAndSetQueryFromEvent:c}}function r(e){return e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement?e.value.length>0:e instanceof HTMLElement&&e.isContentEditable&&(e.textContent?.length??0)>0}function i(e,t,n){function i(){let t=e.runtime.getDocument();return t?[...t.querySelectorAll(`a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]`)].filter(e=>e.tabIndex>=0&&e.getClientRects().length>0):[]}function a(t){e.state.highlightedIndex!==t&&t>=0&&t<n.getFilteredOptions().length&&e.mutate(()=>{e.state.highlightedIndex=t,e.bump()})}function o(){return n.getFilteredOptions().findIndex(e=>!n.isOptionDisabled(e))}function s(){let e=n.getFilteredOptions();for(let t=e.length-1;t>=0;t--)if(e[t]!=null&&!n.isOptionDisabled(e[t]))return t;return-1}function c(t,r=1,i=!0){let a=n.getFilteredOptions().length;if(a===0){e.mutate(()=>{e.state.highlightedIndex=-1,e.bump()});return}let o=e.state.highlightedIndex+t*r;i||(o=Math.max(0,Math.min(a-1,o)));for(let r=0;r<a;r++){o<0?o=a-1:o>=a&&(o=0);let r=n.getFilteredOptions()[o];if(r!=null&&!n.isOptionDisabled(r)){e.state.highlightedIndex!==o&&e.mutate(()=>{e.state.highlightedIndex=o,e.bump()});return}o+=t}e.mutate(()=>{e.state.highlightedIndex=-1,e.bump()})}function l(){let e=t.listRef,n=t.optionRefs.values().next().value;return e!=null&&n!=null&&e.clientHeight>0&&n.offsetHeight>0?Math.max(1,Math.floor(e.clientHeight/n.offsetHeight)):10}function u(n){let r=i();if(r.length===0)return;let a=e.runtime.getDocument()?.activeElement,o=a==null?-1:r.indexOf(a),s=n?-1:1;for(let e=1;e<=r.length;e++){let n=r[(o+e*s+r.length)%r.length];if(t.listRef==null||!t.listRef.contains(n)){n.focus();return}}}function d(i){let a=i;if(!a.defaultPrevented&&!n.isLocked()&&(a.currentTarget===a.target||a.key===`Tab`)){if(!e.state.isOpen)[`Enter`,` `,`ArrowDown`,`ArrowUp`].includes(a.key)?(a.preventDefault(),n.open()):[`Backspace`,`Delete`].includes(a.key)&&!r(a.target)&&(a.preventDefault(),n.removeLastSelected());else switch(a.key){case`ArrowDown`:a.preventDefault(),c(1),n.scrollToHighlight();break;case`ArrowUp`:a.preventDefault(),c(-1),n.scrollToHighlight();break;case`Enter`:{a.preventDefault();let t=n.getFilteredOptions()[e.state.highlightedIndex];e.state.highlightedIndex>=0&&t!=null&&n.select(t);break}case` `:if(a.target!==t.triggerRef)break;a.preventDefault();break;case`Backspace`:case`Delete`:{let e=a.target===t.triggerRef&&t.triggerRef===t.inputRef;(t.inputRef==null||e)&&!r(a.target)&&(a.preventDefault(),n.removeLastSelected());break}case`PageDown`:case`PageUp`:a.preventDefault(),c(a.key===`PageDown`?1:-1,l(),!1),n.scrollToHighlight();break;case`Home`:case`End`:if(a.target instanceof HTMLInputElement||a.target instanceof HTMLTextAreaElement)break;a.preventDefault(),e.mutate(()=>{e.state.highlightedIndex=a.key===`Home`?o():s(),e.bump()}),n.scrollToHighlight();break;case`Tab`:{a.preventDefault();let t=n.getFilteredOptions()[e.state.highlightedIndex];if(e.props.selectOnTab&&e.state.highlightedIndex>=0&&t!=null){n.select(t),e.state.isOpen&&n.close(!1),u(a.shiftKey);break}u(a.shiftKey),n.isInsideWidget(e.runtime.getDocument()?.activeElement??null)||n.close(!1);break}case`Escape`:a.preventDefault(),n.close(!0)}}}return{setHighlightedIndex:a,firstActionableIndex:o,lastActionableIndex:s,stepHighlight:c,pageSize:l,getFocusableElements:i,focusNextOutside:u,handleKeydown:d}}function a(e){return e instanceof HTMLTextAreaElement||e instanceof HTMLElement&&e.isContentEditable?!0:e instanceof HTMLInputElement&&![`button`,`submit`,`reset`,`checkbox`,`radio`,`range`,`color`,`file`,`hidden`,`image`].includes(e.type)}function o(e,t,n){function r(){return t.dropdownRef!=null&&t.dropdownRef.hasAttribute(`popover`)&&typeof t.dropdownRef.showPopover==`function`?t.dropdownRef:null}function i(){let e=r();e!=null&&!e.matches(`:popover-open`)&&e.showPopover()}function o(){let e=r();e!=null&&e.matches(`:popover-open`)&&e.hidePopover()}async function s(r=!0){e.state.isOpen||n.isLocked()||(e.mutate(()=>{e.state.isOpen=!0;let t=e.props.inputOnOpen??`select`;e.state.searchQuery=t===`clear`?``:void 0;let r=n.getSelectedList()[0],i=r==null?-1:n.getFilteredOptions().findIndex(t=>e.unwrap(n.valueOf(t))===e.unwrap(r));e.state.highlightedIndex=i>=0?i:n.firstActionableIndex(),e.bump()}),await e.nextTick(),i(),n.calculateAlignment(),e.props.alignSelected||n.scrollToHighlight(),t.inputRef?.focus({preventScroll:!0}),r&&(e.props.inputOnOpen??`select`)===`select`&&t.inputRef?.select())}function c(n=!0){e.state.isOpen&&(e.mutate(()=>{o(),e.state.isOpen=!1,e.state.highlightedIndex=-1,e.state.searchQuery=void 0,e.bump()}),n&&t.triggerRef?.focus())}function l(){n.isLocked()||(e.state.isOpen?c():s())}function u(){t.inputRef?.focus({preventScroll:!0})}function d(e){return e!=null&&[t.containerRef,t.triggerRef,t.dropdownRef].some(t=>t!=null&&t.contains(e))}function f(){let n=t.inputRef;if(n==null)return;let r=e.runtime.getDocument(),i=r?.activeElement??null;i==null||i===n||i===r?.body||i===r?.documentElement?n.focus({preventScroll:!0}):a(i)||d(i)&&n.focus({preventScroll:!0})}function p(t){e.state.isOpen&&e.props.closeOnClickOutside!==!1&&e.props.clickOutsideFilter?.(t.target)!==!1&&(d(t.target)||c(!1))}function m(t){t.key===`Escape`&&e.state.isOpen&&(t.preventDefault(),c(!0))}return{open:s,close:c,toggle:l,focusInput:u,isInsideWidget:d,maybeRefocusInput:f,handleClickOutside:p,handleDocumentKeydown:m}}function s(e,t){if(!t)return;let n=t.getBoundingClientRect(),r=e.getBoundingClientRect(),i=(t.offsetWidth>0?n.width/t.offsetWidth:1)||1;r.top<n.top?t.scrollTop-=(n.top-r.top)/i:r.bottom>n.bottom&&(t.scrollTop+=(r.bottom-n.bottom)/i)}function c(t,n,r,i){let a=e(t)(()=>{let e={positionAnchor:n,left:`anchor(left)`,width:`anchor-size(width)`,top:t.props.alignSelected?`anchor(top)`:`anchor(bottom)`};return t.props.alignSelected&&(e.translate=`0 -${t.state.alignmentOffset}px`),e});function o(){let e=i.getSelectedList()[0];if(!r.dropdownRef||!t.props.alignSelected||e==null){t.mutate(()=>{t.state.alignmentOffset=0,t.bump()});return}let n=r.dropdownRef,a=i.findOptionByValue(e),o=a==null?void 0:r.optionRefs.get(t.unwrap(a));if(o&&r.listRef){s(o,r.listRef);let e=n.getBoundingClientRect(),i=o.getBoundingClientRect(),a=n.offsetWidth>0?e.width/n.offsetWidth:1;t.mutate(()=>{t.state.alignmentOffset=(i.top-e.top)/(a||1),t.bump()})}else t.mutate(()=>{t.state.alignmentOffset=0,t.bump()})}async function c(){await t.nextTick();let e=i.getFilteredOptions()[t.state.highlightedIndex];if(!e)return;let n=r.optionRefs.get(t.unwrap(e));n&&s(n,r.listRef)}return{getPopupStyle:a,scrollElementIntoContainer:s,calculateAlignment:o,scrollToHighlight:c}}var l=0;function u(e={}){return{nextTick:e.nextTick??(()=>Promise.resolve()),unwrap:e.unwrap??(e=>e),createId:e.createId??(()=>`headless-combobox-${++l}`),getDocument:e.getDocument??(()=>typeof document>`u`?null:document)}}function d(t,n){function r(e){return t.props.optionValue?t.props.optionValue(e):e}function i(e){return t.props.options.find(n=>t.unwrap(r(n))===t.unwrap(e))}let a=e(t)(()=>{let e=t.getModelValue();return t.props.multiple?Array.isArray(e)?e:[]:e==null?[]:[e]}),o=e(t)(()=>a().length),s=e(t)(()=>!t.props.multiple||t.props.maxLength==null||o()<t.props.maxLength),c=e(t)(()=>t.props.disabled===!0||t.props.readonly===!0);function l(e){let n=t.unwrap(r(e));return a().some(e=>t.unwrap(e)===n)}function u(e){return!l(e)&&!s()}function d(e){if(c())return;let i=r(e);t.mutate(()=>{if(t.props.multiple){let e=a(),n=t.unwrap(i);e.some(e=>t.unwrap(e)===n)?t.emitModel(e.filter(e=>t.unwrap(e)!==n)):s()&&t.emitModel([...e,i])}else t.emitModel(i);t.props.closeOnSelect??!t.props.multiple?n.close(!0):t.state.isOpen&&t.nextTick().then(n.maybeRefocusInput)})}function f(){c()||t.mutate(()=>{t.emitModel(t.props.multiple?[]:null),t.state.isOpen&&t.nextTick().then(n.maybeRefocusInput)})}function p(){if(c())return;let e=a();e.length!==0&&t.mutate(()=>{t.emitModel(t.props.multiple?e.slice(0,-1):null),t.state.isOpen&&t.nextTick().then(n.maybeRefocusInput)})}return{valueOf:r,findOptionByValue:i,getSelectedList:a,getSelectedCount:o,getCanSelectMore:s,isSelected:l,isOptionDisabled:u,isLocked:c,select:d,clear:f,removeLastSelected:p}}function f(t,n){let r=e(t)(()=>{let e=[],r=n();return t.props.required&&r===0&&e.push(`required`),t.props.multiple&&(t.props.minLength!=null&&r<t.props.minLength&&e.push(`minlength`),t.props.maxLength!=null&&r>t.props.maxLength&&e.push(`maxlength`)),e});return{getErrors:r,getValid:e(t)(()=>r().length===0),getValidationMessage:e(t)(()=>{let e=r()[0];if(!e)return``;let n=t.props.errorMessages?.[e];if(n!=null)return n;switch(e){case`required`:return`Selection is required.`;case`minlength`:return`Select at least ${t.props.minLength} option${t.props.minLength===1?``:`s`}.`;case`maxlength`:return`Select at most ${t.props.maxLength} option${t.props.maxLength===1?``:`s`}.`}return``})}}var p=Symbol(`unset`);function m(e){let r=u(e.runtime),a={isOpen:!1,searchQuery:void 0,highlightedIndex:-1,alignmentOffset:0},s={containerRef:null,triggerRef:null,dropdownRef:null,inputRef:null,listRef:null,optionRefs:new Map},l=e.props,m=p,h=0,g=0,_=!1,v=!1,y=new Set;function b(){for(let e of[...y])e()}function x(){h++,g>0?_=!0:b()}function S(e){g++;try{return e()}finally{g--,g===0&&_&&(_=!1,b())}}function C(){return m===p?l.modelValue:m}function w(t){m=t,x(),e.onChange?.(t)}let T={get props(){return l},state:a,refs:s,runtime:r,get version(){return h},mutate:S,bump:x,getModelValue:C,emitModel:w,nextTick:()=>r.nextTick(),unwrap:r.unwrap},E={close:()=>{},maybeRefocusInput:()=>{}},D=d(T,E),O={open:async()=>{}},k=n(T,O),A=f(T,D.getSelectedCount),j={select:()=>{},setHighlightedIndex:()=>{},toggle:()=>{},handleKeydown:()=>{},open:async()=>{},setQueryFromEvent:()=>{},openAndSetQueryFromEvent:()=>{},isSelected:()=>!1,isOptionDisabled:()=>!1},M=t(T,l.id||r.createId(),j),N=c(T,M.cssAnchorName,s,{getSelectedList:D.getSelectedList,getFilteredOptions:k.getFilteredOptions,findOptionByValue:D.findOptionByValue}),P={getFilteredOptions:k.getFilteredOptions,isOptionDisabled:D.isOptionDisabled,isLocked:D.isLocked,open:async()=>{},select:D.select,close:()=>{},isInsideWidget:()=>!1,scrollToHighlight:N.scrollToHighlight,removeLastSelected:()=>{}},F=i(T,s,P),I=o(T,s,{isLocked:D.isLocked,getSelectedList:D.getSelectedList,getFilteredOptions:k.getFilteredOptions,valueOf:D.valueOf,firstActionableIndex:F.firstActionableIndex,calculateAlignment:N.calculateAlignment,scrollToHighlight:N.scrollToHighlight});E.close=I.close,E.maybeRefocusInput=I.maybeRefocusInput,O.open=I.open,O.onQueryChange=()=>{T.mutate(()=>{T.state.highlightedIndex=F.firstActionableIndex(),T.bump()})},P.open=I.open,P.close=I.close,P.isInsideWidget=I.isInsideWidget,P.removeLastSelected=D.removeLastSelected,j.select=D.select,j.setHighlightedIndex=F.setHighlightedIndex,j.toggle=I.toggle,j.handleKeydown=F.handleKeydown,j.open=I.open,j.setQueryFromEvent=k.setQueryFromEvent,j.openAndSetQueryFromEvent=k.openAndSetQueryFromEvent,j.isSelected=D.isSelected,j.isOptionDisabled=D.isOptionDisabled;let L=e=>F.handleKeydown(e);function R(e){s.containerRef!=null&&s.containerRef.removeEventListener(`keydown`,L),s.containerRef=e,s.containerRef!=null&&s.containerRef.addEventListener(`keydown`,L)}function z(e){s.triggerRef=e}function B(e){s.dropdownRef!=null&&s.dropdownRef.removeEventListener(`keydown`,L),s.dropdownRef=e,s.dropdownRef!=null&&s.dropdownRef.addEventListener(`keydown`,L)}function V(e){s.inputRef=e}function H(e){s.listRef=e}function U(e,t){let n=r.unwrap(e);t?s.optionRefs.set(n,t):s.optionRefs.delete(n)}let W,G=-1;function K(){if(W!==void 0&&G===h)return W;let e=D.getSelectedList();return W={isOpen:a.isOpen,multiple:l.multiple===!0,disabled:l.disabled===!0,readonly:l.readonly===!0,searchQuery:a.searchQuery,filteredOptions:k.getFilteredOptions(),highlightedIndex:a.highlightedIndex,alignmentOffset:a.alignmentOffset,cssAnchorName:M.cssAnchorName,popupStyle:N.getPopupStyle(),selectedCount:e.length,selectedList:e,canSelectMore:D.getCanSelectMore(),isSelected:D.isSelected,valid:A.getValid(),errors:A.getErrors(),validationMessage:A.getValidationMessage(),triggerProps:M.getTriggerProps(),inputProps:M.getInputProps(),comboboxInputProps:M.getComboboxInputProps(),listboxProps:M.getListboxProps(),getOptionProps:M.getOptionProps,setSearchQuery:k.setSearchQuery,setHighlightedIndex:F.setHighlightedIndex,toggle:I.toggle,open:I.open,close:I.close,select:D.select,clear:D.clear,focusInput:I.focusInput,handleKeydown:F.handleKeydown,setContainerRef:R,setTriggerRef:z,setDropdownRef:B,setInputRef:V,setListRef:H,setOptionRef:U},G=h,W}function q(e){let t=l,n=e,r=!1;for(let e of new Set([...Object.keys(t),...Object.keys(n)]))if(!Object.is(t[e],n[e])){r=!0;break}l=e,m!==p&&(m=p,r=!0),r&&x()}function J(e){let t=!1;for(let n of Object.keys(e))Object.is(a[n],e[n])||(a[n]=e[n],t=!0);t&&x()}function Y(e){return y.add(e),()=>{y.delete(e)}}function X(){if(v)return;let e=r.getDocument();e&&(v=!0,e.addEventListener(`mousedown`,I.handleClickOutside),e.addEventListener(`keydown`,I.handleDocumentKeydown))}function Z(){let e=r.getDocument();e&&v&&(e.removeEventListener(`mousedown`,I.handleClickOutside),e.removeEventListener(`keydown`,I.handleDocumentKeydown)),v=!1,s.containerRef?.removeEventListener(`keydown`,L),s.dropdownRef?.removeEventListener(`keydown`,L),y.clear()}return{getSnapshot:K,subscribe:Y,setProps:q,setState:J,mount:X,destroy:Z}}exports.createCombobox=m,exports.createRuntime=u;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createMemo","version","value","ctx","compute","createAccessibility","safeInstanceId","instanceId","listboxId","triggerId","inputId","getOptionId","index","cssAnchorName","getActiveDescendant","getTriggerProps","deps","getInputProps","getComboboxInputProps","getListboxProps","getOptionProps","actionable","option","event","createFiltering","getOptionLabel","applyFilter","query","getFilteredOptions","q","o","setSearchQuery","val","hooks","setQueryFromEvent","openAndSetQueryFromEvent","hasTextValue","target","createNavigation","getFocusableElements","doc","el","setHighlightedIndex","firstActionableIndex","lastActionableIndex","options","i","stepHighlight","len","next","direction","steps","wrap","pageSize","list","refs","firstOption","focusNextOutside","focusables","active","step","backward","handleKeydown","e","typeahead","isTextEntryElement","createPopover","popoverEl","showPopoverIfAny","hidePopoverIfAny","open","inputOnOpen","firstSelected","selectedIndex","selectText","close","returnFocus","toggle","focusInput","isInsideWidget","r","maybeRefocusInput","input","handleClickOutside","handleDocumentKeydown","scrollElementIntoContainer","container","containerRect","elRect","s","createPositioning","getPopupStyle","style","calculateAlignment","dropdownEl","selectedOption","selectedEl","dropdownRect","selectedRect","scale","scrollToHighlight","idCounter","createRuntime","overrides","createSelection","valueOf","findOptionByValue","getSelectedList","model","getSelectedCount","getCanSelectMore","isLocked","isSelected","v","isOptionDisabled","select","current","raw","clear","removeLastSelected","createValidation","getErrors","count","code","custom","UNSET","createCombobox","runtime","state","props","pendingModel","batchDepth","dirty","mounted","subscribers","notify","listener","bump","mutate","fn","getModelValue","emitModel","selectionHooks","selection","filteringHooks","filtering","validation","accessibilityDeps","accessibility","positioning","navigationDeps","navigation","popover","keydownHandler","setContainerRef","setTriggerRef","setDropdownRef","setInputRef","setListRef","setOptionRef","key","cachedSnapshot","cachedVersion","getSnapshot","selectedList","setProps","previous","incoming","changed","setState","patch","subscribe","mount","destroy"],"sources":["../src/context.ts","../src/accessibility.ts","../src/filtering.ts","../src/navigation.ts","../src/popover.ts","../src/positioning.ts","../src/runtime.ts","../src/selection.ts","../src/validation.ts","../src/store.ts"],"sourcesContent":["import type { ComboboxRuntime } from './runtime';\nimport type { HeadlessComboboxDomRefs, HeadlessComboboxProps } from './types';\n\nexport interface ComboboxState<Q> {\n isOpen: boolean;\n searchQuery: Q | undefined;\n highlightedIndex: number;\n alignmentOffset: number;\n}\n\n/**\n * Shared mutable context. Feature modules receive it instead of Vue refs and\n * computed values; every mutation goes through `mutate`, which bumps `version`\n * so lazily computed values know they are stale.\n */\nexport interface ComboboxContext<O, V, Q> {\n props: HeadlessComboboxProps<O, V, Q>;\n state: ComboboxState<Q>;\n refs: HeadlessComboboxDomRefs<O>;\n runtime: ComboboxRuntime;\n /** Monotonic revision; changes whenever props or state change. */\n version: number;\n /** Batch state changes and notify subscribers once at the end. */\n mutate: <T>(fn: () => T) => T;\n /** Mark state as changed (invalidates memoized values immediately). */\n bump: () => void;\n /** The model value, including any change emitted but not yet round-tripped through props. */\n getModelValue: () => V | V[] | null;\n /** Record and publish a model change. Call inside `mutate`. */\n emitModel: (value: V | V[] | null) => void;\n nextTick: () => Promise<void>;\n unwrap: <T>(value: T) => T;\n}\n\n/**\n * Lazy memoization keyed by the context revision. A state change bumps the\n * version, so values read later in the same mutation are recomputed, while\n * repeated reads in one revision stay cached.\n */\nexport function createMemo<T>(ctx: Pick<ComboboxContext<never, never, never>, 'version'>): (compute: () => T) => () => T {\n return (compute) => {\n let version = -1;\n let value!: T;\n return () => {\n if (version !== ctx.version) {\n value = compute();\n version = ctx.version;\n }\n return value;\n };\n };\n}\n","import type { ComboboxContext } from './context';\nimport type { HeadlessComboboxComboboxInputProps, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxTriggerProps } from './types';\n\nimport { createMemo } from './context';\n\n/** Late-bound actions the ARIA prop bags need (wired by the store). */\nexport interface AccessibilityDeps<O> {\n select: (option: O) => void;\n setHighlightedIndex: (index: number) => void;\n toggle: () => void;\n handleKeydown: (event: Event) => void;\n open: () => Promise<void>;\n setQueryFromEvent: (event: Event) => void;\n openAndSetQueryFromEvent: (event: Event) => void;\n isSelected: (option: O) => boolean;\n isOptionDisabled: (option: O) => boolean;\n}\n\n/** Ids, the anchor name, and the ARIA prop bags spread onto consumer markup. */\nexport function createAccessibility<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n instanceId: string,\n deps: AccessibilityDeps<O>,\n) {\n // Vue's default useId contains a colon; React's contains «». Strip anything\n // that is not valid in an id or a CSS custom property.\n const safeInstanceId = instanceId.replace(/[^\\w-]/g, '-');\n\n const listboxId = `${ safeInstanceId }-listbox`;\n const triggerId = `${ safeInstanceId }-trigger`;\n const inputId = `${ safeInstanceId }-input`;\n const getOptionId = (index: number) => `${ safeInstanceId }-opt-${ index }`;\n const cssAnchorName = `--anchor-${ safeInstanceId }`;\n\n const getActiveDescendant = createMemo<string | undefined>(ctx)(() => {\n if (!ctx.state.isOpen || ctx.state.highlightedIndex === -1) {\n return undefined;\n }\n return getOptionId(ctx.state.highlightedIndex);\n });\n\n const getTriggerProps = createMemo<HeadlessComboboxTriggerProps>(ctx)(() => ({\n id: triggerId,\n role: 'combobox',\n 'aria-controls': listboxId,\n 'aria-expanded': ctx.state.isOpen,\n 'aria-haspopup': 'listbox',\n 'aria-activedescendant': getActiveDescendant(),\n disabled: ctx.props.disabled ? true : undefined,\n 'aria-disabled': ctx.props.disabled ? true : undefined,\n 'aria-readonly': ctx.props.readonly ? true : undefined,\n onClick: deps.toggle,\n onKeydown: deps.handleKeydown,\n }));\n\n const getInputProps = createMemo<HeadlessComboboxInputProps>(ctx)(() => ({\n id: inputId,\n role: 'searchbox',\n 'aria-autocomplete': 'list',\n 'aria-controls': listboxId,\n 'aria-activedescendant': getActiveDescendant(),\n onInput: deps.setQueryFromEvent,\n onKeydown: deps.handleKeydown,\n }));\n\n // For the canonical editable (typeahead) pattern where the text input *is* the combobox.\n const getComboboxInputProps = createMemo<HeadlessComboboxComboboxInputProps>(ctx)(() => ({\n id: inputId,\n role: 'combobox',\n 'aria-autocomplete': 'list',\n 'aria-controls': listboxId,\n 'aria-expanded': ctx.state.isOpen,\n 'aria-haspopup': 'listbox',\n 'aria-activedescendant': getActiveDescendant(),\n 'aria-disabled': ctx.props.disabled ? true : undefined,\n 'aria-readonly': ctx.props.readonly ? true : undefined,\n disabled: ctx.props.disabled ? true : undefined,\n readonly: ctx.props.readonly ? true : undefined,\n onClick: deps.open,\n onFocus: deps.open,\n onInput: deps.openAndSetQueryFromEvent,\n }));\n\n const getListboxProps = createMemo<HeadlessComboboxListboxProps>(ctx)(() => ({\n id: listboxId,\n role: 'listbox',\n 'aria-multiselectable': ctx.props.multiple ? true : undefined,\n }));\n\n function getOptionProps(option: O, index: number): HeadlessComboboxOptionProps {\n const actionable = () => !deps.isOptionDisabled(option);\n return {\n id: getOptionId(index),\n role: 'option',\n 'aria-selected': deps.isSelected(option),\n 'aria-disabled': deps.isOptionDisabled(option)\n ? true\n : undefined,\n 'data-highlighted': index === ctx.state.highlightedIndex\n ? true\n : undefined,\n onClick: () => deps.select(option),\n // Keep the filter input focused when the option is clicked.\n onMousedown: (event: Event) => (event as MouseEvent).preventDefault(),\n // Hover and focus drive the highlight; blocked options never get it.\n onMousemove: () => {\n if (actionable()) {\n deps.setHighlightedIndex(index);\n }\n },\n onFocus: () => {\n if (actionable()) {\n deps.setHighlightedIndex(index);\n }\n },\n // Keep the popup's keyboard navigation (and Tab skipping) working from\n // inside the options list.\n onKeydown: deps.handleKeydown,\n };\n }\n\n return {\n cssAnchorName,\n getTriggerProps,\n getInputProps,\n getComboboxInputProps,\n getListboxProps,\n getOptionProps,\n };\n}\n","import type { ComboboxContext } from './context';\n\nimport { createMemo } from './context';\n\n/** Late-bound popup action the filtering needs (wired by the store). */\nexport interface FilteringHooks {\n /** `selectText: false` when the popup reopens by typing, so the input text must not be selected then. */\n open: (selectText?: boolean) => Promise<void>;\n /** Reset the highlight after a query change (wired by the store). */\n onQueryChange?: () => void;\n}\n\n/** Search query, filtering, and the resulting options list. */\nexport function createFiltering<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n hooks: FilteringHooks,\n) {\n function getOptionLabel(option: O): string {\n return ctx.props.optionLabel\n ? ctx.props.optionLabel(option)\n : String(option);\n }\n\n function applyFilter(option: O, query: Q): boolean {\n if (ctx.props.optionFilter) {\n return ctx.props.optionFilter(option, query);\n }\n return getOptionLabel(option).toLowerCase().includes(String(query).toLowerCase());\n }\n\n const getFilteredOptions = createMemo<O[]>(ctx)(() => {\n const q = ctx.state.searchQuery;\n if (q == null || (typeof q === 'string' && q === '')) {\n return ctx.props.options;\n }\n return ctx.props.options.filter((o) => applyFilter(o, q));\n });\n\n function setSearchQuery(val: Q | undefined) {\n if (Object.is(ctx.state.searchQuery, val)) {\n return;\n }\n ctx.mutate(() => {\n ctx.state.searchQuery = val;\n ctx.bump();\n // The store wires this to `setHighlightedIndex(firstActionableIndex())`\n // after construction; the hook keeps the two modules decoupled.\n hooks.onQueryChange?.();\n });\n }\n\n function setQueryFromEvent(event: Event) {\n setSearchQuery((event.target as HTMLInputElement).value as Q);\n }\n\n // Typing in the typeahead input reopens the popup (open() resets the query\n // first, so the order matters) and filters the options. The text being typed\n // must not be selected by the open, so it opens with selectText disabled.\n function openAndSetQueryFromEvent(event: Event) {\n hooks.open(false);\n setQueryFromEvent(event);\n }\n\n return {\n getFilteredOptions,\n setSearchQuery,\n setQueryFromEvent,\n openAndSetQueryFromEvent,\n };\n}\n","import type { ComboboxContext } from './context';\nimport type { HeadlessComboboxDomRefs } from './types';\n\n/** The selection/popover pieces the keyboard navigation needs. */\nexport interface NavigationDeps<O> {\n getFilteredOptions: () => O[];\n isOptionDisabled: (option: O) => boolean;\n isLocked: () => boolean;\n open: () => Promise<void>;\n select: (option: O) => void;\n close: (returnFocus?: boolean) => void;\n isInsideWidget: (target: Node | null) => boolean;\n scrollToHighlight: () => Promise<void>;\n removeLastSelected: () => void;\n}\n\n// Backspace/Delete fall through to native behavior when the key is meant to\n// edit text (e.g. the typeahead input still holds a query).\nfunction hasTextValue(target: EventTarget | null): boolean {\n if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) {\n return target.value.length > 0;\n }\n /* v8 ignore next 1 -- element.textContent is never null ('' when empty) */\n return target instanceof HTMLElement && target.isContentEditable && (target.textContent?.length ?? 0) > 0;\n}\n\n/** The highlight state and the keyboard navigation (arrows, paging, Home/End, Tab). */\nexport function createNavigation<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n refs: HeadlessComboboxDomRefs<O>,\n deps: NavigationDeps<O>,\n) {\n function getFocusableElements(): HTMLElement[] {\n const doc = ctx.runtime.getDocument();\n if (!doc) {\n return [];\n }\n return [\n ...doc.querySelectorAll<HTMLElement>(\n 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]',\n ),\n ].filter((el) => el.tabIndex >= 0 && el.getClientRects().length > 0);\n }\n\n function setHighlightedIndex(index: number) {\n if (ctx.state.highlightedIndex !== index && index >= 0 && index < deps.getFilteredOptions().length) {\n ctx.mutate(() => {\n ctx.state.highlightedIndex = index;\n ctx.bump();\n });\n }\n }\n\n function firstActionableIndex(): number {\n return deps.getFilteredOptions().findIndex((o) => !deps.isOptionDisabled(o));\n }\n\n function lastActionableIndex(): number {\n const options = deps.getFilteredOptions();\n for (let i = options.length - 1; i >= 0; i--) {\n // The null guard mirrors the filtering contract; filtered options are never null.\n /* v8 ignore next 3 */\n if (options[ i ] != null && !deps.isOptionDisabled(options[ i ]!)) {\n return i;\n }\n }\n return -1;\n }\n\n // Move the highlight by `direction` (1 or -1, scaled by `steps`), skipping\n // options that cannot be selected (at `maxLength`). Wraps around unless\n // `wrap` is false, in which case the move clamps at the ends; clears the\n // highlight when nothing is actionable.\n function stepHighlight(direction: 1 | -1, steps = 1, wrap = true) {\n const len = deps.getFilteredOptions().length;\n if (len === 0) {\n ctx.mutate(() => {\n ctx.state.highlightedIndex = -1;\n ctx.bump();\n });\n return;\n }\n let next = ctx.state.highlightedIndex + direction * steps;\n if (!wrap) {\n next = Math.max(0, Math.min(len - 1, next));\n }\n for (let i = 0; i < len; i++) {\n if (next < 0) {\n next = len - 1;\n } else if (next >= len) {\n next = 0;\n }\n const option = deps.getFilteredOptions()[ next ];\n if (option != null && !deps.isOptionDisabled(option)) {\n if (ctx.state.highlightedIndex !== next) {\n ctx.mutate(() => {\n ctx.state.highlightedIndex = next;\n ctx.bump();\n });\n }\n return;\n }\n next += direction;\n }\n ctx.mutate(() => {\n ctx.state.highlightedIndex = -1;\n ctx.bump();\n });\n }\n\n /** Jump per page: the number of fully visible options. */\n function pageSize(): number {\n const list = refs.listRef;\n const firstOption = refs.optionRefs.values().next().value;\n if (list != null && firstOption != null && list.clientHeight > 0 && firstOption.offsetHeight > 0) {\n return Math.max(1, Math.floor(list.clientHeight / firstOption.offsetHeight));\n }\n return 10;\n }\n\n // The next (or previous) focusable element in the document that is not inside\n // the options list, wrapping around when the end is reached.\n function focusNextOutside(backward: boolean) {\n const focusables = getFocusableElements();\n if (focusables.length === 0) {\n return;\n }\n const doc = ctx.runtime.getDocument();\n const active = doc?.activeElement as HTMLElement | null;\n // document.activeElement is never null per the DOM spec.\n /* v8 ignore next 3 */\n const index = active == null\n ? -1\n : focusables.indexOf(active);\n const step = backward\n ? -1\n : 1;\n for (let i = 1; i <= focusables.length; i++) {\n const el = focusables[ (index + i * step + focusables.length) % focusables.length ]!;\n // The list ref is always set while the popup is open.\n /* v8 ignore next 2 */\n if (refs.listRef == null || !refs.listRef.contains(el)) {\n el.focus();\n return;\n }\n }\n }\n\n function handleKeydown(event: Event) {\n const e = event as KeyboardEvent;\n // The same event bubbles from the trigger/input/option handlers to the\n // container/dropdown listeners; only the first (target) handler processes it.\n if (e.defaultPrevented) {\n return;\n }\n if (deps.isLocked()) {\n return;\n }\n // The container/dropdown listeners exist to catch Tab (so it skips the\n // options list) from elements around the trigger. Keys aimed at non-wired\n // elements (chip remove buttons, popup clear buttons) must fall through\n // to their native activation instead of driving the combobox.\n if (e.currentTarget !== e.target && e.key !== 'Tab') {\n return;\n }\n if (!ctx.state.isOpen) {\n if ([ 'Enter', ' ', 'ArrowDown', 'ArrowUp' ].includes(e.key)) {\n e.preventDefault();\n deps.open();\n } else if ([ 'Backspace', 'Delete' ].includes(e.key) && !hasTextValue(e.target)) {\n e.preventDefault();\n deps.removeLastSelected();\n }\n return;\n }\n\n switch (e.key) {\n case 'ArrowDown': {\n e.preventDefault();\n stepHighlight(1);\n deps.scrollToHighlight();\n break;\n }\n case 'ArrowUp': {\n e.preventDefault();\n stepHighlight(-1);\n deps.scrollToHighlight();\n break;\n }\n case 'Enter': {\n e.preventDefault();\n const option = deps.getFilteredOptions()[ ctx.state.highlightedIndex ];\n if (ctx.state.highlightedIndex >= 0 && option != null) {\n deps.select(option);\n }\n break;\n }\n case ' ': {\n // Space types in text entries and natively activates option buttons\n // (click → select). On the trigger its native click would toggle the\n // popup closed; suppress that, because Space does nothing there.\n if (e.target !== refs.triggerRef) {\n break;\n }\n e.preventDefault();\n break;\n }\n case 'Backspace':\n case 'Delete': {\n // Without a filter input there is no text to delete, so Backspace/\n // Delete drop the last (or only) selected option instead. The typeahead\n // trigger doubles as the filter input: while it holds the selection\n // label or a query, Backspace edits/deletes the text natively; only an\n // empty input removes the selection.\n const typeahead = e.target === refs.triggerRef && refs.triggerRef === refs.inputRef;\n if ((refs.inputRef == null || typeahead) && !hasTextValue(e.target)) {\n e.preventDefault();\n deps.removeLastSelected();\n }\n break;\n }\n case 'PageDown':\n case 'PageUp': {\n e.preventDefault();\n stepHighlight(e.key === 'PageDown'\n ? 1\n : -1, pageSize(), false);\n deps.scrollToHighlight();\n break;\n }\n case 'Home':\n case 'End': {\n // In inputs these keep their native caret behavior.\n if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {\n break;\n }\n e.preventDefault();\n ctx.mutate(() => {\n ctx.state.highlightedIndex = e.key === 'Home'\n ? firstActionableIndex()\n : lastActionableIndex();\n ctx.bump();\n });\n deps.scrollToHighlight();\n break;\n }\n case 'Tab': {\n // Skip the options list: focus the next focusable element outside it.\n e.preventDefault();\n const option = deps.getFilteredOptions()[ ctx.state.highlightedIndex ];\n const willSelect = ctx.props.selectOnTab && ctx.state.highlightedIndex >= 0 && option != null;\n if (willSelect) {\n deps.select(option);\n if (ctx.state.isOpen) {\n deps.close(false);\n }\n // The selection's close may return focus to the trigger; move on to\n // the next focusable element as a normal Tab would.\n focusNextOutside(e.shiftKey);\n break;\n }\n focusNextOutside(e.shiftKey);\n // Focus leaving the widget closes the popup, like a click outside.\n if (!deps.isInsideWidget(ctx.runtime.getDocument()?.activeElement ?? null)) {\n deps.close(false);\n }\n break;\n }\n case 'Escape':\n e.preventDefault();\n deps.close(true);\n break;\n }\n }\n\n return {\n setHighlightedIndex,\n firstActionableIndex,\n lastActionableIndex,\n stepHighlight,\n pageSize,\n getFocusableElements,\n focusNextOutside,\n handleKeydown,\n };\n}\n","import type { ComboboxContext } from './context';\nimport type { HeadlessComboboxDomRefs } from './types';\n\n/** The state and actions the popup lifecycle needs. */\nexport interface PopoverDeps<O, V> {\n isLocked: () => boolean;\n getSelectedList: () => V[];\n getFilteredOptions: () => O[];\n valueOf: (option: O) => V;\n firstActionableIndex: () => number;\n calculateAlignment: () => void;\n scrollToHighlight: () => Promise<void>;\n}\n\n// Elements the user types into. We must never steal focus from these.\nfunction isTextEntryElement(el: Element | null): boolean {\n if (el instanceof HTMLTextAreaElement) {\n return true;\n }\n if (el instanceof HTMLElement && el.isContentEditable) {\n return true;\n }\n if (el instanceof HTMLInputElement) {\n return ![\n 'button',\n 'submit',\n 'reset',\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'hidden',\n 'image',\n ].includes(el.type);\n }\n return false;\n}\n\n/** The open/close lifecycle, the Popover API, focus management, and the outside-close guards. */\nexport function createPopover<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n refs: HeadlessComboboxDomRefs<O>,\n deps: PopoverDeps<O, V>,\n) {\n // If the consumer marked the dropdown as a popover, drive it with the Popover API\n // (top-layer rendering) instead of relying on conditional rendering.\n function popoverEl(): HTMLElement | null {\n return refs.dropdownRef != null && refs.dropdownRef.hasAttribute('popover') && typeof refs.dropdownRef.showPopover === 'function'\n ? refs.dropdownRef\n : null;\n }\n\n function showPopoverIfAny() {\n const el = popoverEl();\n if (el != null && !el.matches(':popover-open')) {\n el.showPopover();\n }\n }\n\n function hidePopoverIfAny() {\n const el = popoverEl();\n if (el != null && el.matches(':popover-open')) {\n el.hidePopover();\n }\n }\n\n async function open(selectText = true) {\n if (ctx.state.isOpen || deps.isLocked()) {\n return;\n }\n ctx.mutate(() => {\n ctx.state.isOpen = true;\n // `clear` opens with an empty input; otherwise the query stays empty and\n // the input keeps showing the current value (typeahead examples fall back\n // to the selection), or has its text selected, per `inputOnOpen`.\n const inputOnOpen = ctx.props.inputOnOpen ?? 'select';\n ctx.state.searchQuery = inputOnOpen === 'clear'\n ? ('' as Q)\n : undefined;\n\n const firstSelected = deps.getSelectedList()[ 0 ];\n const selectedIndex = firstSelected == null\n ? -1\n : deps.getFilteredOptions().findIndex((o) => ctx.unwrap(deps.valueOf(o)) === ctx.unwrap(firstSelected));\n // A selected option is always actionable; otherwise start on the first one that can be selected.\n ctx.state.highlightedIndex = selectedIndex >= 0\n ? selectedIndex\n : deps.firstActionableIndex();\n ctx.bump();\n });\n\n await ctx.nextTick();\n showPopoverIfAny();\n deps.calculateAlignment();\n if (!ctx.props.alignSelected) {\n // Bring the first selected option (or the top) into view.\n deps.scrollToHighlight();\n }\n refs.inputRef?.focus({ preventScroll: true });\n // Select the visible text so typing replaces it (not when the popup\n // reopens by typing, and not in `keep`/`clear` modes).\n if (selectText && (ctx.props.inputOnOpen ?? 'select') === 'select') {\n refs.inputRef?.select();\n }\n }\n\n function close(returnFocus = true) {\n if (!ctx.state.isOpen) {\n return;\n }\n ctx.mutate(() => {\n hidePopoverIfAny();\n ctx.state.isOpen = false;\n ctx.state.highlightedIndex = -1;\n ctx.state.searchQuery = undefined;\n ctx.bump();\n });\n if (returnFocus) {\n refs.triggerRef?.focus();\n }\n }\n\n function toggle() {\n if (deps.isLocked()) {\n return;\n }\n if (ctx.state.isOpen) {\n close();\n } else {\n open();\n }\n }\n\n // Return focus to the filter input (used when the popup stays open after an interaction).\n function focusInput() {\n refs.inputRef?.focus({ preventScroll: true });\n }\n\n // Refocus the filter only when it is safe to do so, i.e. don't yank focus away\n // from another text field (e.g. an \"add option\" input) or a control the user\n // intentionally moved to outside the combobox.\n // The widget boundary = any of the wired parts (control container, trigger, dropdown).\n // `setContainerRef` is optional; wire it only to extend the boundary (e.g. external chips).\n function isInsideWidget(target: Node | null): boolean {\n // Unreachable in normal use: callers always pass a DOM node (an event target\n // or document.activeElement, which is never null per the DOM spec).\n /* v8 ignore next 2 */\n if (target == null) {\n return false;\n }\n return [ refs.containerRef, refs.triggerRef, refs.dropdownRef ].some((r) => r != null && r.contains(target));\n }\n\n function maybeRefocusInput() {\n const input = refs.inputRef;\n if (input == null) {\n return;\n }\n const doc = ctx.runtime.getDocument();\n const active = doc?.activeElement ?? null;\n if (active == null || active === input || active === doc?.body || active === doc?.documentElement) {\n input.focus({ preventScroll: true });\n return;\n }\n if (isTextEntryElement(active)) {\n return;\n }\n if (!isInsideWidget(active)) {\n return;\n }\n input.focus({ preventScroll: true });\n }\n\n function handleClickOutside(e: MouseEvent) {\n if (!ctx.state.isOpen || ctx.props.closeOnClickOutside === false) {\n return;\n }\n if (ctx.props.clickOutsideFilter?.(e.target) === false) {\n return;\n }\n if (!isInsideWidget(e.target as Node)) {\n close(false);\n }\n }\n\n // ESC closes the popup no matter which control inside the widget has focus\n // (clear button, option buttons, …). This follows the WAI-ARIA combobox pattern.\n function handleDocumentKeydown(e: KeyboardEvent) {\n if (e.key === 'Escape' && ctx.state.isOpen) {\n e.preventDefault();\n close(true);\n }\n }\n\n return {\n open,\n close,\n toggle,\n focusInput,\n isInsideWidget,\n maybeRefocusInput,\n handleClickOutside,\n handleDocumentKeydown,\n };\n}\n","import type { ComboboxContext } from './context';\nimport type { HeadlessComboboxDomRefs, HeadlessComboboxPopupStyle } from './types';\n\nimport { createMemo } from './context';\n\n/** The selection pieces the popup positioning needs. */\nexport interface PositioningDeps<O, V> {\n getSelectedList: () => V[];\n getFilteredOptions: () => O[];\n findOptionByValue: (value: V) => O | undefined;\n}\n\nexport function scrollElementIntoContainer(el: HTMLElement, container: HTMLElement | null) {\n if (!container) {\n return;\n }\n const containerRect = container.getBoundingClientRect();\n const elRect = el.getBoundingClientRect();\n // Compensate for any CSS scale applied by the open animation: getBoundingClientRect\n // is scaled, but scrollTop is in unscaled content units.\n const scale = container.offsetWidth > 0\n ? containerRect.width / container.offsetWidth\n : 1;\n const s = scale || 1;\n\n if (elRect.top < containerRect.top) {\n container.scrollTop -= (containerRect.top - elRect.top) / s;\n } else if (elRect.bottom > containerRect.bottom) {\n container.scrollTop += (elRect.bottom - containerRect.bottom) / s;\n }\n}\n\n/** The anchor style and the popup alignment (alignSelected) machinery. */\nexport function createPositioning<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n cssAnchorName: string,\n refs: HeadlessComboboxDomRefs<O>,\n deps: PositioningDeps<O, V>,\n) {\n // Default popup positioning: spread (or merge) onto the dropdown element's style.\n // No `position` is set: a popover gets `position: fixed` from the UA stylesheet,\n // and a regular element keeps the position you give it.\n const getPopupStyle = createMemo<HeadlessComboboxPopupStyle>(ctx)(() => {\n const style: HeadlessComboboxPopupStyle = {\n positionAnchor: cssAnchorName,\n left: 'anchor(left)',\n width: 'anchor-size(width)',\n top: ctx.props.alignSelected ? 'anchor(top)' : 'anchor(bottom)',\n };\n if (ctx.props.alignSelected) {\n style.translate = `0 -${ ctx.state.alignmentOffset }px`;\n }\n return style;\n });\n\n function calculateAlignment() {\n const firstSelected = deps.getSelectedList()[ 0 ];\n if (!refs.dropdownRef || !ctx.props.alignSelected || firstSelected == null) {\n ctx.mutate(() => {\n ctx.state.alignmentOffset = 0;\n ctx.bump();\n });\n return;\n }\n\n const dropdownEl = refs.dropdownRef;\n const selectedOption = deps.findOptionByValue(firstSelected);\n const selectedEl = selectedOption == null\n ? undefined\n : refs.optionRefs.get(ctx.unwrap(selectedOption));\n if (selectedEl && refs.listRef) {\n scrollElementIntoContainer(selectedEl, refs.listRef);\n\n const dropdownRect = dropdownEl.getBoundingClientRect();\n const selectedRect = selectedEl.getBoundingClientRect();\n // The popup settles at scale 1, so divide out the current scale to get the\n // final (unscaled) offset. Both rects share the popup's scale, so the vector\n // difference scales by the same factor regardless of transform-origin.\n const scale = dropdownEl.offsetWidth > 0\n ? dropdownRect.width / dropdownEl.offsetWidth\n : 1;\n ctx.mutate(() => {\n ctx.state.alignmentOffset = (selectedRect.top - dropdownRect.top) / (scale || 1);\n ctx.bump();\n });\n } else {\n ctx.mutate(() => {\n ctx.state.alignmentOffset = 0;\n ctx.bump();\n });\n }\n }\n\n async function scrollToHighlight() {\n await ctx.nextTick();\n const option = deps.getFilteredOptions()[ ctx.state.highlightedIndex ];\n if (!option) {\n return;\n }\n const el = refs.optionRefs.get(ctx.unwrap(option));\n if (el) {\n scrollElementIntoContainer(el, refs.listRef);\n }\n }\n\n return {\n getPopupStyle,\n scrollElementIntoContainer,\n calculateAlignment,\n scrollToHighlight,\n };\n}\n","let idCounter = 0;\n\n/**\n * The three host capabilities the core needs. Adapters override them with\n * framework-specific implementations:\n *\n * - `nextTick`: resolves after the framework has committed the DOM, so the\n * popup can be measured/focused;\n * - `unwrap`: strips framework proxies before identity comparisons (Vue\n * passes `toRaw`, every other adapter keeps the identity default);\n * - `createId`: stable id source (React/Vue pass their own `useId`).\n */\nexport interface ComboboxRuntime {\n nextTick: () => Promise<void>;\n unwrap: <T>(value: T) => T;\n createId: () => string;\n getDocument: () => Document | null;\n}\n\nexport type ComboboxRuntimeOverrides = Partial<ComboboxRuntime>;\n\nexport function createRuntime(overrides: ComboboxRuntimeOverrides = {}): ComboboxRuntime {\n return {\n nextTick: overrides.nextTick ?? (() => Promise.resolve()),\n unwrap: overrides.unwrap ?? (<T>(value: T): T => value),\n createId: overrides.createId ?? (() => `headless-combobox-${ ++idCounter }`),\n getDocument: overrides.getDocument ?? (() => typeof document === 'undefined'\n ? null\n : document),\n };\n}\n","import type { ComboboxContext } from './context';\n\nimport { createMemo } from './context';\n\n/** Late-bound popup actions the selection needs (wired by the store). */\nexport interface SelectionHooks {\n close: (returnFocus?: boolean) => void;\n maybeRefocusInput: () => void;\n}\n\n/**\n * Selection state: the model values, membership by resolved option value, and\n * the select/clear actions. Equality is by the resolved option value.\n */\nexport function createSelection<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n hooks: SelectionHooks,\n) {\n /** The value stored / emitted for an option; defaults to the option itself. */\n function valueOf(option: O): V {\n return ctx.props.optionValue\n ? ctx.props.optionValue(option)\n : option as unknown as V;\n }\n\n /** The option whose value equals `value` (used to resolve the model back to an option). */\n function findOptionByValue(value: V): O | undefined {\n return ctx.props.options.find((option) => ctx.unwrap(valueOf(option)) === ctx.unwrap(value));\n }\n\n const getSelectedList = createMemo<V[]>(ctx)(() => {\n const model = ctx.getModelValue();\n if (ctx.props.multiple) {\n return Array.isArray(model)\n ? model as V[]\n : [];\n }\n return model == null\n ? []\n : [ model as V ];\n });\n\n const getSelectedCount = createMemo<number>(ctx)(() => getSelectedList().length);\n\n const getCanSelectMore = createMemo<boolean>(ctx)(() => {\n if (!ctx.props.multiple) {\n return true;\n }\n return ctx.props.maxLength == null || getSelectedCount() < ctx.props.maxLength;\n });\n\n const isLocked = createMemo<boolean>(ctx)(() => ctx.props.disabled === true || ctx.props.readonly === true);\n\n function isSelected(option: O): boolean {\n const value = ctx.unwrap(valueOf(option));\n return getSelectedList().some((v) => ctx.unwrap(v) === value);\n }\n\n // Options that cannot be selected: only when at `maxLength` (multiple).\n function isOptionDisabled(option: O): boolean {\n return !isSelected(option) && !getCanSelectMore();\n }\n\n function select(option: O) {\n if (isLocked()) {\n return;\n }\n\n const value = valueOf(option);\n ctx.mutate(() => {\n if (ctx.props.multiple) {\n const current = getSelectedList();\n const raw = ctx.unwrap(value);\n const has = current.some((v) => ctx.unwrap(v) === raw);\n if (has) {\n ctx.emitModel(current.filter((v) => ctx.unwrap(v) !== raw));\n } else if (getCanSelectMore()) {\n ctx.emitModel([ ...current, value ]);\n }\n // else: blocked at `max`: no change, but still fall through to keep the filter focused.\n } else {\n ctx.emitModel(value);\n }\n\n const shouldClose = ctx.props.closeOnSelect ?? !ctx.props.multiple;\n if (shouldClose) {\n hooks.close(true);\n } else if (ctx.state.isOpen) {\n // Popup stays open (e.g. multiple): keep the filter focused for continued typing,\n // unless the user is focused on another text field / control.\n ctx.nextTick().then(hooks.maybeRefocusInput);\n }\n });\n }\n\n function clear() {\n if (isLocked()) {\n return;\n }\n ctx.mutate(() => {\n ctx.emitModel(ctx.props.multiple\n ? []\n : null);\n if (ctx.state.isOpen) {\n ctx.nextTick().then(hooks.maybeRefocusInput);\n }\n });\n }\n\n // Backspace/Delete: drop the trailing selection (multiple) or the sole value\n // (single). Same focus handling as `clear`.\n function removeLastSelected() {\n /* v8 ignore next 3 -- handleKeydown guards isLocked; removeLastSelected is not exposed */\n if (isLocked()) {\n return;\n }\n const current = getSelectedList();\n if (current.length === 0) {\n return;\n }\n ctx.mutate(() => {\n ctx.emitModel(ctx.props.multiple\n ? current.slice(0, -1)\n : null);\n if (ctx.state.isOpen) {\n ctx.nextTick().then(hooks.maybeRefocusInput);\n }\n });\n }\n\n return {\n valueOf,\n findOptionByValue,\n getSelectedList,\n getSelectedCount,\n getCanSelectMore,\n isSelected,\n isOptionDisabled,\n isLocked,\n select,\n clear,\n removeLastSelected,\n };\n}\n","import type { ComboboxContext } from './context';\nimport type { HeadlessComboboxErrorCode } from './types';\n\nimport { createMemo } from './context';\n\n/** Validation derived from the selection count. */\nexport function createValidation<O, V, Q>(\n ctx: ComboboxContext<O, V, Q>,\n getSelectedCount: () => number,\n) {\n const getErrors = createMemo<HeadlessComboboxErrorCode[]>(ctx)(() => {\n const list: HeadlessComboboxErrorCode[] = [];\n const count = getSelectedCount();\n\n if (ctx.props.required && count === 0) {\n list.push('required');\n }\n if (ctx.props.multiple) {\n if (ctx.props.minLength != null && count < ctx.props.minLength) {\n list.push('minlength');\n }\n if (ctx.props.maxLength != null && count > ctx.props.maxLength) {\n list.push('maxlength');\n }\n }\n return list;\n });\n\n const getValid = createMemo<boolean>(ctx)(() => getErrors().length === 0);\n\n const getValidationMessage = createMemo<string>(ctx)(() => {\n const code = getErrors()[ 0 ];\n if (!code) {\n return '';\n }\n const custom = ctx.props.errorMessages?.[ code ];\n if (custom != null) {\n return custom;\n }\n switch (code) {\n case 'required':\n return 'Selection is required.';\n case 'minlength':\n return `Select at least ${ ctx.props.minLength } option${ ctx.props.minLength === 1\n ? ''\n : 's' }.`;\n case 'maxlength':\n return `Select at most ${ ctx.props.maxLength } option${ ctx.props.maxLength === 1\n ? ''\n : 's' }.`;\n }\n // Unreachable: the switch above is exhaustive over HeadlessComboboxErrorCode.\n /* v8 ignore next 1 */\n return '';\n });\n\n return {\n getErrors,\n getValid,\n getValidationMessage,\n };\n}\n","import type { AccessibilityDeps } from './accessibility';\nimport type { ComboboxContext, ComboboxState } from './context';\nimport type { FilteringHooks } from './filtering';\nimport type { NavigationDeps } from './navigation';\nimport type { PopoverDeps } from './popover';\nimport type { ComboboxRuntimeOverrides } from './runtime';\nimport type { SelectionHooks } from './selection';\nimport type { HeadlessComboboxDomRefs, HeadlessComboboxProps, HeadlessComboboxSnapshot } from './types';\n\nimport { createAccessibility } from './accessibility';\nimport { createFiltering } from './filtering';\nimport { createNavigation } from './navigation';\nimport { createPopover } from './popover';\nimport { createPositioning } from './positioning';\nimport { createRuntime } from './runtime';\nimport { createSelection } from './selection';\nimport { createValidation } from './validation';\n\n/** Store surface the adapters drive. All UI state lives in `getSnapshot()`. */\nexport interface ComboboxStore<O, V, Q = string> {\n /** Current flat state + actions. Stable identity until something changes. */\n getSnapshot: () => HeadlessComboboxSnapshot<O, V, Q>;\n /** Subscribe to state/props changes. Returns the unsubscribe function. */\n subscribe: (listener: () => void) => () => void;\n /** Push new props (from the adapter's reactive layer). No-op when shallow-equal. */\n setProps: (props: HeadlessComboboxProps<O, V, Q>) => void;\n /** Override individual state fields (adapter-backed writable refs). */\n setState: (patch: Partial<ComboboxState<Q>>) => void;\n /** Attach document-level listeners. Idempotent; safe on the server. */\n mount: () => void;\n /** Remove listeners and drop subscribers. */\n destroy: () => void;\n}\n\nexport interface CreateComboboxOptions<O, V, Q = string> {\n props: HeadlessComboboxProps<O, V, Q>;\n /** Receives every model change (`select`, `clear`, backspace removal). */\n onChange?: (value: V | V[] | null) => void;\n /** Framework hooks: tick, unwrap, id generation, document lookup. */\n runtime?: ComboboxRuntimeOverrides;\n}\n\nconst UNSET = Symbol('unset');\ntype PendingModel<V> = V | V[] | null | typeof UNSET;\n\n/**\n * Framework-independent combobox state machine.\n *\n * The store owns every piece of behavior: selection, filtering, validation,\n * keyboard navigation, popup lifecycle, anchoring, and focus management. It\n * touches the DOM only after `mount()` and only through the element refs the\n * adapter wires up. Framework adapters translate its snapshot into their own\n * reactive primitive and implement `nextTick`/`unwrap`/`createId`.\n */\nexport function createCombobox<O, V, Q = string>(\n options: CreateComboboxOptions<O, V, Q>,\n): ComboboxStore<O, V, Q> {\n const runtime = createRuntime(options.runtime);\n\n const state: ComboboxState<Q> = {\n isOpen: false,\n searchQuery: undefined,\n highlightedIndex: -1,\n alignmentOffset: 0,\n };\n\n const refs: HeadlessComboboxDomRefs<O> = {\n containerRef: null,\n triggerRef: null,\n dropdownRef: null,\n inputRef: null,\n listRef: null,\n optionRefs: new Map(),\n };\n\n let props = options.props;\n let pendingModel: PendingModel<V> = UNSET;\n let version = 0;\n let batchDepth = 0;\n let dirty = false;\n let mounted = false;\n\n const subscribers = new Set<() => void>();\n\n function notify() {\n for (const listener of [ ...subscribers ]) {\n listener();\n }\n }\n\n function bump() {\n version++;\n if (batchDepth > 0) {\n dirty = true;\n return;\n }\n notify();\n }\n\n function mutate<T>(fn: () => T): T {\n batchDepth++;\n try {\n return fn();\n } finally {\n batchDepth--;\n if (batchDepth === 0 && dirty) {\n dirty = false;\n notify();\n }\n }\n }\n\n function getModelValue(): V | V[] | null {\n return pendingModel === UNSET\n ? props.modelValue\n : pendingModel;\n }\n\n function emitModel(value: V | V[] | null) {\n pendingModel = value;\n bump();\n options.onChange?.(value);\n }\n\n const ctx: ComboboxContext<O, V, Q> = {\n get props() {\n return props;\n },\n state,\n refs,\n runtime,\n get version() {\n return version;\n },\n mutate,\n bump,\n getModelValue,\n emitModel,\n nextTick: () => runtime.nextTick(),\n unwrap: runtime.unwrap,\n };\n\n // --- Feature modules (dependency cycle broken with late-bound hooks) ---\n const selectionHooks: SelectionHooks = {\n /* v8 ignore next 1 */\n close: () => {},\n /* v8 ignore next 1 */\n maybeRefocusInput: () => {},\n };\n const selection = createSelection(ctx, selectionHooks);\n\n const filteringHooks: FilteringHooks = {\n /* v8 ignore next 1 */\n open: async () => {},\n };\n const filtering = createFiltering(ctx, filteringHooks);\n\n const validation = createValidation(ctx, selection.getSelectedCount);\n\n const accessibilityDeps: AccessibilityDeps<O> = {\n /* v8 ignore next 1 */\n select: () => {},\n /* v8 ignore next 1 */\n setHighlightedIndex: () => {},\n /* v8 ignore next 1 */\n toggle: () => {},\n /* v8 ignore next 1 */\n handleKeydown: () => {},\n /* v8 ignore next 1 */\n open: async () => {},\n /* v8 ignore next 1 */\n setQueryFromEvent: () => {},\n /* v8 ignore next 1 */\n openAndSetQueryFromEvent: () => {},\n /* v8 ignore next 1 */\n isSelected: () => false,\n /* v8 ignore next 1 */\n isOptionDisabled: () => false,\n };\n const accessibility = createAccessibility(\n ctx,\n props.id || runtime.createId(),\n accessibilityDeps,\n );\n\n const positioning = createPositioning(ctx, accessibility.cssAnchorName, refs, {\n getSelectedList: selection.getSelectedList,\n getFilteredOptions: filtering.getFilteredOptions,\n findOptionByValue: selection.findOptionByValue,\n });\n\n const navigationDeps: NavigationDeps<O> = {\n getFilteredOptions: filtering.getFilteredOptions,\n isOptionDisabled: selection.isOptionDisabled,\n isLocked: selection.isLocked,\n /* v8 ignore next 1 */\n open: async () => {},\n select: selection.select,\n /* v8 ignore next 1 */\n close: () => {},\n /* v8 ignore next 1 */\n isInsideWidget: () => false,\n scrollToHighlight: positioning.scrollToHighlight,\n /* v8 ignore next 1 */\n removeLastSelected: () => {},\n };\n const navigation = createNavigation(ctx, refs, navigationDeps);\n\n const popoverDeps: PopoverDeps<O, V> = {\n isLocked: selection.isLocked,\n getSelectedList: selection.getSelectedList,\n getFilteredOptions: filtering.getFilteredOptions,\n valueOf: selection.valueOf,\n firstActionableIndex: navigation.firstActionableIndex,\n calculateAlignment: positioning.calculateAlignment,\n scrollToHighlight: positioning.scrollToHighlight,\n };\n const popover = createPopover(ctx, refs, popoverDeps);\n\n // --- Late-bound cross-links ---\n selectionHooks.close = popover.close;\n selectionHooks.maybeRefocusInput = popover.maybeRefocusInput;\n filteringHooks.open = popover.open;\n filteringHooks.onQueryChange = () => {\n ctx.mutate(() => {\n ctx.state.highlightedIndex = navigation.firstActionableIndex();\n ctx.bump();\n });\n };\n navigationDeps.open = popover.open;\n navigationDeps.close = popover.close;\n navigationDeps.isInsideWidget = popover.isInsideWidget;\n navigationDeps.removeLastSelected = selection.removeLastSelected;\n accessibilityDeps.select = selection.select;\n accessibilityDeps.setHighlightedIndex = navigation.setHighlightedIndex;\n accessibilityDeps.toggle = popover.toggle;\n accessibilityDeps.handleKeydown = navigation.handleKeydown;\n accessibilityDeps.open = popover.open;\n accessibilityDeps.setQueryFromEvent = filtering.setQueryFromEvent;\n accessibilityDeps.openAndSetQueryFromEvent = filtering.openAndSetQueryFromEvent;\n accessibilityDeps.isSelected = selection.isSelected;\n accessibilityDeps.isOptionDisabled = selection.isOptionDisabled;\n\n // --- Element refs ---\n // The handler is late-bound because navigation is created after the refs.\n const keydownHandler = (event: Event) => navigation.handleKeydown(event);\n\n function setContainerRef(el: unknown) {\n if (refs.containerRef != null) {\n refs.containerRef.removeEventListener('keydown', keydownHandler);\n }\n refs.containerRef = el as HTMLElement | null;\n // Catch keys from elements around the trigger so Tab always skips the\n // options list instead of entering it.\n if (refs.containerRef != null) {\n refs.containerRef.addEventListener('keydown', keydownHandler);\n }\n }\n function setTriggerRef(el: unknown) {\n refs.triggerRef = el as HTMLElement | null;\n }\n function setDropdownRef(el: unknown) {\n if (refs.dropdownRef != null) {\n refs.dropdownRef.removeEventListener('keydown', keydownHandler);\n }\n refs.dropdownRef = el as HTMLElement | null;\n // The popup is usually a sibling of the container, so also catch keys\n // from elements inside it (clear buttons, custom controls).\n if (refs.dropdownRef != null) {\n refs.dropdownRef.addEventListener('keydown', keydownHandler);\n }\n }\n function setInputRef(el: unknown) {\n refs.inputRef = el as HTMLInputElement | null;\n }\n function setListRef(el: unknown) {\n refs.listRef = el as HTMLElement | null;\n }\n function setOptionRef(option: O, el: unknown) {\n const key = runtime.unwrap(option);\n if (el) {\n refs.optionRefs.set(key, el as HTMLElement);\n } else { refs.optionRefs.delete(key); }\n }\n\n // --- Snapshot ---\n let cachedSnapshot: HeadlessComboboxSnapshot<O, V, Q> | undefined;\n let cachedVersion = -1;\n\n function getSnapshot(): HeadlessComboboxSnapshot<O, V, Q> {\n if (cachedSnapshot !== undefined && cachedVersion === version) {\n return cachedSnapshot;\n }\n\n const selectedList = selection.getSelectedList();\n cachedSnapshot = {\n isOpen: state.isOpen,\n multiple: props.multiple === true,\n disabled: props.disabled === true,\n readonly: props.readonly === true,\n searchQuery: state.searchQuery,\n filteredOptions: filtering.getFilteredOptions(),\n highlightedIndex: state.highlightedIndex,\n alignmentOffset: state.alignmentOffset,\n cssAnchorName: accessibility.cssAnchorName,\n popupStyle: positioning.getPopupStyle(),\n selectedCount: selectedList.length,\n selectedList,\n canSelectMore: selection.getCanSelectMore(),\n isSelected: selection.isSelected,\n valid: validation.getValid(),\n errors: validation.getErrors(),\n validationMessage: validation.getValidationMessage(),\n triggerProps: accessibility.getTriggerProps(),\n inputProps: accessibility.getInputProps(),\n comboboxInputProps: accessibility.getComboboxInputProps(),\n listboxProps: accessibility.getListboxProps(),\n getOptionProps: accessibility.getOptionProps,\n setSearchQuery: filtering.setSearchQuery,\n setHighlightedIndex: navigation.setHighlightedIndex,\n toggle: popover.toggle,\n open: popover.open,\n close: popover.close,\n select: selection.select,\n clear: selection.clear,\n focusInput: popover.focusInput,\n handleKeydown: navigation.handleKeydown,\n setContainerRef,\n setTriggerRef,\n setDropdownRef,\n setInputRef,\n setListRef,\n setOptionRef,\n };\n cachedVersion = version;\n return cachedSnapshot;\n }\n\n function setProps(next: HeadlessComboboxProps<O, V, Q>) {\n const previous = props as unknown as Record<string, unknown>;\n const incoming = next as unknown as Record<string, unknown>;\n let changed = false;\n\n for (const key of new Set([\n ...Object.keys(previous),\n ...Object.keys(incoming),\n ])) {\n if (!Object.is(previous[ key ], incoming[ key ])) {\n changed = true;\n break;\n }\n }\n\n props = next;\n // Any props round-trip is authoritative: once the adapter has pushed the\n // new model back, the local mirror is no longer needed.\n if (pendingModel !== UNSET) {\n pendingModel = UNSET;\n changed = true;\n }\n\n if (changed) {\n bump();\n }\n }\n\n function setState(patch: Partial<ComboboxState<Q>>) {\n let changed = false;\n for (const key of Object.keys(patch) as Array<keyof ComboboxState<Q>>) {\n if (!Object.is(state[ key ], patch[ key ])) {\n state[ key ] = patch[ key ] as never;\n changed = true;\n }\n }\n if (changed) {\n bump();\n }\n }\n\n function subscribe(listener: () => void) {\n subscribers.add(listener);\n return () => {\n subscribers.delete(listener);\n };\n }\n\n function mount() {\n if (mounted) {\n return;\n }\n const doc = runtime.getDocument();\n if (!doc) {\n return;\n }\n mounted = true;\n doc.addEventListener('mousedown', popover.handleClickOutside);\n doc.addEventListener('keydown', popover.handleDocumentKeydown);\n }\n\n function destroy() {\n const doc = runtime.getDocument();\n if (doc && mounted) {\n doc.removeEventListener('mousedown', popover.handleClickOutside);\n doc.removeEventListener('keydown', popover.handleDocumentKeydown);\n }\n mounted = false;\n refs.containerRef?.removeEventListener('keydown', keydownHandler);\n refs.dropdownRef?.removeEventListener('keydown', keydownHandler);\n subscribers.clear();\n }\n\n return {\n getSnapshot,\n subscribe,\n setProps,\n setState,\n mount,\n destroy,\n };\n}\n"],"mappings":"A,mEAuCA,SAAgBA,EAAc,EAA2F,CACvH,MAAQ,IAAY,CAClB,IAAIC,EAAU,GACVC,EACJ,WACMD,IAAYE,EAAI,UAClB,EAAQC,EAAQ,EAChB,EAAUD,EAAI,SAETD,EAEX,CACF,CChCA,SAAgBG,EACd,EACA,EACA,EACA,CAGA,IAAMC,EAAiBC,EAAW,QAAQ,UAAW,GAAG,EAElDC,EAAY,GAAIF,EAAgB,UAChCG,EAAY,GAAIH,EAAgB,UAChCI,EAAU,GAAIJ,EAAgB,QAC9BK,EAAe,GAAkB,GAAIL,EAAgB,OAAQM,IAC7DC,EAAgB,YAAaP,IAE7BQ,EAAsBd,EAA+BG,CAAG,CAAC,KAAO,CACpE,GAAKA,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B,OAAO,GAAG1C,EAAOgC,GAAOU,EAAOV,EAAK,IACvC,EAAOA,GAAQU,EAAOV,GACtB,EAAU,IAGVQ,GACF/B,EAAK,CAET,CAEA,SAASkC,EAAU,EAAsB,CAEvC,OADArC,EAAY,IAAIE,CAAQ,MACX,CACXF,EAAY,OAAOE,CAAQ,CAC7B,CACF,CAEA,SAASoC,GAAQ,CACf,GAAIvC,EACF,OAEF,IAAM7F,EAAMuF,EAAQ,YAAY,EAC3BvF,IAGL,EAAU,GACVA,EAAI,iBAAiB,YAAagH,EAAQ,kBAAkB,EAC5DhH,EAAI,iBAAiB,UAAWgH,EAAQ,qBAAqB,EAC/D,CAEA,SAASqB,GAAU,CACjB,IAAMrI,EAAMuF,EAAQ,YAAY,EAC5BvF,GAAO6F,IACT7F,EAAI,oBAAoB,YAAagH,EAAQ,kBAAkB,EAC/DhH,EAAI,oBAAoB,UAAWgH,EAAQ,qBAAqB,GAElE,EAAU,GACVjG,EAAK,cAAc,oBAAoB,UAAWkG,CAAc,EAChElG,EAAK,aAAa,oBAAoB,UAAWkG,CAAc,EAC/DnB,EAAY,MAAM,CACpB,CAEA,MAAO,CACL,cACA,YACA,WACA,WACA,QACA,SACF,CACF,C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { HeadlessComboboxComboboxInputProps, HeadlessComboboxDomRefs, HeadlessComboboxErrorCode, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxPopupStyle, HeadlessComboboxProps, HeadlessComboboxSnapshot, HeadlessComboboxTriggerProps, } from './types';
|
|
2
|
+
export type { ComboboxState } from './context';
|
|
3
|
+
export type { ComboboxRuntime, ComboboxRuntimeOverrides } from './runtime';
|
|
4
|
+
export type { ComboboxStore, CreateComboboxOptions } from './store';
|
|
5
|
+
export { createCombobox } from './store';
|
|
6
|
+
export { createRuntime } from './runtime';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kCAAkC,EAClC,uBAAuB,EACvB,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,SAAS,CAAC;AACjB,YAAY,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAC3E,YAAY,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEpE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|