@pdanpdan/headless-combobox-vue 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 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,331 @@
1
- # Temporary Holding Version
1
+ # @pdanpdan/headless-combobox-vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Accessible, **renderless** (headless) combobox for Vue 3. It ships **zero styles**; you own the markup and styling (for example with daisyUI or Tailwind). The component exposes state, actions, and ARIA prop bags through its default scoped slot. You can also drive the same state machine directly with the [`useHeadlessCombobox`](#composable) composable.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @pdanpdan/headless-combobox-vue
9
+ ```
10
+
11
+ `vue@^3` is a peer dependency.
12
+
13
+ ## Usage
14
+
15
+ The component renders nothing on its own. You build the markup and bind the slot scope to it. The markup follows the ARIA combobox pattern: a **trigger** that opens a **popup** listing the **options**, optionally with a search input:
16
+
17
+ **Trigger + popup**: a button opens a list below it. The example below uses this layout:
18
+
19
+ ```text
20
+ HeadlessCombobox (default slot scope)
21
+ └─ div :ref="setContainerRef" widget boundary (optional)
22
+ ├─ button :ref="setTriggerRef" the trigger
23
+ │ │ v-bind="triggerProps"
24
+ │ └─ selected label
25
+ ├─ ul :ref="setDropdownRef" the popup
26
+ │ │ v-bind="listboxProps" :style="popupStyle"
27
+ │ │ popover="manual" optional: native Popover API
28
+ │ └─ li v-for="(option, i) in filteredOptions"
29
+ │ └─ button :ref="setOptionRef(option, el)" one option
30
+ │ v-bind="getOptionProps(option, i)"
31
+ └─ input :ref="setInputRef" search input (optional)
32
+ v-bind="inputProps"
33
+ ```
34
+
35
+ **Typeahead**: the text input itself is the combobox. Typing reopens the popup and filters (see `examples/TextTypeahead.vue`):
36
+
37
+ ```text
38
+ HeadlessCombobox (default slot scope)
39
+ └─ div :ref="setContainerRef" widget boundary (optional)
40
+ ├─ input :ref="setTriggerRef" the combobox input
41
+ │ │ v-bind="comboboxInputProps"
42
+ └─ ul :ref="setDropdownRef" the popup
43
+ │ v-bind="listboxProps" :style="popupStyle"
44
+ │ popover="manual" optional: native Popover API
45
+ └─ li v-for="(option, i) in filteredOptions"
46
+ └─ button :ref="setOptionRef(option, el)" one option
47
+ v-bind="getOptionProps(option, i)"
48
+ ```
49
+
50
+ This is where each slot prop is designed to be used:
51
+
52
+ | Markup | Slot props to bind | What they do |
53
+ |---|---|---|
54
+ | wrapper element | `setContainerRef` | Widget boundary for click-outside and focus. Optional, recommended. |
55
+ | trigger button | `triggerProps`, `setTriggerRef` | `role="combobox"`. Toggles the popup and handles keyboard navigation. |
56
+ | typeahead input | `comboboxInputProps`, `setTriggerRef`, `setInputRef` | The input *is* the combobox: typing reopens and filters. |
57
+ | search input in the popup | `inputProps`, `setInputRef` | `role="searchbox"`. Filters while the popup stays open. |
58
+ | popup element | `popupStyle`, `setDropdownRef` | Positioning; add `popover="manual"` to use the native Popover API. |
59
+ | list element | `listboxProps`, `setListRef` | `role="listbox"`. The options container. |
60
+ | each option element | `getOptionProps(option, index)`, `setOptionRef(option, el)` | Option semantics + select/highlight handlers. |
61
+
62
+ Ref setters are wired with `:ref="..."` and are optional. Bind only the elements your markup uses. `setOptionRef` enables `alignSelected` and scroll-into-view; `setContainerRef` extends the click-outside boundary (e.g. to external chips).
63
+
64
+ ```vue
65
+ <script setup lang="ts">
66
+ import { HeadlessCombobox } from '@pdanpdan/headless-combobox-vue';
67
+ import { ref } from 'vue';
68
+
69
+ interface User { id: number; name: string; }
70
+
71
+ const users = ref<User[]>([
72
+ { id: 1, name: 'Wade Cooper' },
73
+ { id: 2, name: 'Arlene Mccoy' },
74
+ ]);
75
+ const selected = ref<User | null>(null);
76
+ </script>
77
+
78
+ <template>
79
+ <HeadlessCombobox
80
+ v-slot="{ isOpen, filteredOptions, toggle, select, triggerProps, setContainerRef, setTriggerRef, getOptionProps }"
81
+ v-model="selected"
82
+ :options="users"
83
+ :option-label="(u) => u.name"
84
+ >
85
+ <div :ref="setContainerRef">
86
+ <button :ref="setTriggerRef" v-bind="triggerProps" type="button" @click="toggle">
87
+ {{ selected?.name ?? 'Select…' }}
88
+ </button>
89
+ <ul v-if="isOpen">
90
+ <li v-for="(u, i) in filteredOptions" :key="u.id">
91
+ <button type="button" v-bind="getOptionProps(u, i)" @click="select(u)">
92
+ {{ u.name }}
93
+ </button>
94
+ </li>
95
+ </ul>
96
+ </div>
97
+ </HeadlessCombobox>
98
+ </template>
99
+ ```
100
+
101
+ See the [`examples/`](./examples) folder for full daisyUI-styled demos: `TextTypeahead.vue` (editable combobox), `NiceSelect.vue` (selected-option alignment), and `ComposableSingle.vue` / `ComposableProgrammatic.vue` (composable API).
102
+
103
+ Prefer to skip the slot indirection? The same state machine is available as the [`useHeadlessCombobox`](#composable) composable.
104
+
105
+ ## Composable
106
+
107
+ Two APIs, one state machine. `HeadlessCombobox` renders its default slot with the scope above, and the `useHeadlessCombobox` composable exposes the same state, ARIA prop bags, actions, and ref setters directly. The component is a thin wrapper around it. Use the component for slot-driven templates; use the composable for programmatic control (actions are plain functions callable from anywhere), wrapper components, or non-slot layouts. Call it from `setup()`. It registers document-level listeners and uses `useId()` for default ids.
108
+
109
+ ```vue
110
+ <script setup lang="ts">
111
+ import { useHeadlessCombobox } from '@pdanpdan/headless-combobox-vue';
112
+ import { ref, useId } from 'vue';
113
+
114
+ interface User {
115
+ id: number;
116
+ name: string;
117
+ }
118
+
119
+ const users: User[] = [
120
+ { id: 1, name: 'Wade Cooper' },
121
+ { id: 2, name: 'Arlene Mccoy' },
122
+ ];
123
+ const selected = ref<User | null>(null);
124
+ const labelId = useId();
125
+
126
+ const {
127
+ isOpen,
128
+ filteredOptions,
129
+ comboboxInputProps,
130
+ listboxProps,
131
+ getOptionProps,
132
+ select,
133
+ setContainerRef,
134
+ setTriggerRef,
135
+ setInputRef,
136
+ setDropdownRef,
137
+ setListRef,
138
+ setOptionRef,
139
+ } = useHeadlessCombobox<User>(
140
+ {
141
+ modelValue: selected,
142
+ options: users,
143
+ optionLabel: (u) => u.name,
144
+ },
145
+ (value) => {
146
+ selected.value = value as User | null;
147
+ },
148
+ );
149
+ </script>
150
+
151
+ <template>
152
+ <fieldset :ref="setContainerRef">
153
+ <legend :id="labelId">Pick a user</legend>
154
+ <input
155
+ :ref="(el) => { setTriggerRef(el); setInputRef(el); }"
156
+ v-bind="comboboxInputProps"
157
+ :aria-labelledby="labelId"
158
+ type="text"
159
+ />
160
+ <ul
161
+ v-if="isOpen"
162
+ :ref="(el) => { setDropdownRef(el); setListRef(el); }"
163
+ v-bind="listboxProps"
164
+ >
165
+ <li v-for="(user, index) in filteredOptions" :key="user.id">
166
+ <button
167
+ :ref="(el) => setOptionRef(user, el)"
168
+ type="button"
169
+ v-bind="getOptionProps(user, index)"
170
+ @click="select(user)"
171
+ >
172
+ {{ user.name }}
173
+ </button>
174
+ </li>
175
+ </ul>
176
+ </fieldset>
177
+ </template>
178
+ ```
179
+
180
+ - **`props` accept plain values, refs, or a getter**. Every field is unwrapped and tracked internally, so you can pass your `modelValue` ref directly without a `reactive()` wrapper.
181
+ - The second argument receives every `update:modelValue` payload. Write it back to your state. Note that a ref deep-converts object values (`selected.value` is a reactive proxy of the option); use `isSelected(option)` for identity-based checks, as with the component.
182
+ - Returns a `HeadlessComboboxScope<T, Q>`: `Ref`s for state, plain functions for actions and ref setters. Destructure like any composable; refs unwrap in templates.
183
+
184
+ ## Props
185
+
186
+ | Prop | Type | Default | Description |
187
+ |-----------------|-------------------------------------------|--------------------|-----------------------------------------------------------------------------|
188
+ | `modelValue` | `V \| V[] \| null` | internal state | Selected value(s) (`v-model`). Optional: without `v-model` the component keeps the selection internally. |
189
+ | `options` | `O[]` | n/a | List of options. |
190
+ | `multiple` | `boolean` | `false` | Enable multiple selection. |
191
+ | `minLength` | `number` | n/a | Multiple: minimum number of selected options (validation). |
192
+ | `maxLength` | `number` | n/a | Multiple: maximum selected. Blocks adding beyond it. |
193
+ | `required` | `boolean` | `false` | Require a selection (single: a value; multiple: at least one). |
194
+ | `disabled` | `boolean` | `false` | Disable the control: not focusable, cannot open or change. |
195
+ | `readonly` | `boolean` | `false` | Read-only: focusable and shows the value, but cannot open or change. |
196
+ | `closeOnSelect` | `boolean \| null` | `!multiple` | Close the dropdown after selecting. |
197
+ | `closeOnClickOutside` | `boolean` | `true` | Close when clicking outside the widget boundary. |
198
+ | `clickOutsideFilter` | `(target: EventTarget \| null) => boolean` | n/a | Return `false` to keep the dropdown open for a specific outside target. |
199
+ | `selectOnTab` | `boolean` | `false` | On `Tab`, when focus leaves the widget: select the highlighted option and close. |
200
+ | `optionValue` | `(option: O) => V` | the option itself | Maps an option to the value stored in `modelValue` / emitted on select. |
201
+ | `optionLabel` | `(option: O) => string` | `String(option)` | Maps an option to a string for default filtering / rendering. |
202
+ | `optionFilter` | `(option: O, query: Q) => boolean` | case-insensitive substring | Custom filter function. `Q` defaults to `string`. |
203
+ | `id` | `string` | auto (`useId()`) | Base id for accessibility attributes. |
204
+ | `alignSelected` | `boolean` | `false` | Align the dropdown so the selected option covers the trigger. |
205
+ | `inputOnOpen` | `'select' \| 'keep' \| 'clear'` | `'select'` | Typeahead input when the popup opens: `select` keeps showing the current value and selects it (typing replaces it); `keep` shows it without selecting; `clear` opens with an empty input. |
206
+ | `errorMessages` | `Partial<Record<HeadlessComboboxErrorCode, string>>` | n/a | Override default validation messages. |
207
+
208
+ ## Emits
209
+
210
+ | Event | Payload | Description |
211
+ |---------------------|---------------------|------------------------------------|
212
+ | `update:modelValue` | `V \| V[] \| null` | Fired when the selection changes. |
213
+
214
+ ## Selection & validation
215
+
216
+ - Set `multiple` to make `modelValue` an array. `select(option)` toggles membership and keeps the dropdown open; at `max`, adding is blocked (removing still works). `canSelectMore` reflects this.
217
+ - Validation is reactive and headless. You render it. `errors` is an array of `HeadlessComboboxErrorCode` (`'required' | 'minlength' | 'maxlength'`), `valid` is a boolean, and `validationMessage` is a ready-to-show message for the first error (override via `errorMessages`).
218
+
219
+ ## Slot props
220
+
221
+ State: `isOpen`, `multiple`, `disabled`, `readonly`, `searchQuery` (`Q | undefined`, defaults to `string`), `filteredOptions`, `highlightedIndex`, `alignmentOffset`, `cssAnchorName`, `popupStyle` (`HeadlessComboboxPopupStyle`), `selectedCount`, `selectedList`, `canSelectMore`, `isSelected(option)`, `valid`, `errors`, `validationMessage`.
222
+
223
+ ARIA prop bags (spread with `v-bind`). Each bag also carries its interaction handlers, so options, triggers, and inputs need no hand-written event wiring:
224
+ - `triggerProps`: `HeadlessComboboxTriggerProps` (trigger as `role="combobox"`, plus `onClick` → toggle and `onKeydown` → `handleKeydown`)
225
+ - `inputProps`: `HeadlessComboboxInputProps` (in-popup filter input as `role="searchbox"`, plus `onInput` → `setSearchQuery` and `onKeydown` → `handleKeydown`)
226
+ - `comboboxInputProps`: `HeadlessComboboxComboboxInputProps` (typeahead input as `role="combobox"`, plus `onClick`/`onFocus` → open and `onInput` → `setSearchQuery`)
227
+ - `listboxProps`: `HeadlessComboboxListboxProps`
228
+ - `getOptionProps(option, index)` → `HeadlessComboboxOptionProps` (option semantics, plus `onClick` → select, `onMousedown` → `preventDefault` to keep the filter focused, and `onMousemove`/`onFocus` → `setHighlightedIndex`; blocked options are skipped)
229
+
230
+ Each ARIA interface is exported for precise typing. The `disabled`/`readonly` flags and all `aria-*` attributes are included.
231
+
232
+ Actions: `toggle`, `open`, `close(returnFocus?)`, `select(option)`, `clear()`, `setSearchQuery(value: Q | undefined)`, `setHighlightedIndex(index)`, `focusInput()`, `handleKeydown(event)`.
233
+
234
+ Ref setters (assign with `:ref`): `setContainerRef`, `setTriggerRef`, `setDropdownRef`, `setInputRef`, `setListRef`, `setOptionRef(option, el)`.
235
+
236
+ > The example components render options, triggers, and search inputs with nothing more than `v-bind` on the bags. See `examples/` for the recommended usage.
237
+
238
+ ## Popup positioning & the Popover API
239
+
240
+ Positioning the popup needs two styles: the **trigger** exposes an anchor via `cssAnchorName`, and the **popup** applies the ready-made `popupStyle` (position, anchor position, and width) plus `popover="manual"` so the browser renders it in the top layer:
241
+
242
+ ```vue
243
+ <button
244
+ :ref="setTriggerRef"
245
+ v-bind="triggerProps"
246
+ :style="{ anchorName: cssAnchorName }"
247
+ >
248
+ …
249
+ </button>
250
+
251
+ <ul
252
+ :ref="setDropdownRef"
253
+ v-bind="listboxProps"
254
+ popover="manual"
255
+ :style="popupStyle"
256
+ >
257
+ …
258
+ </ul>
259
+ ```
260
+
261
+ `popupStyle` (`HeadlessComboboxPopupStyle`) is a ready-to-apply style object. No `position` is set: a popover gets `position: fixed` from the UA stylesheet, and a regular element keeps the position you give it:
262
+
263
+ ```
264
+ { positionAnchor: cssAnchorName, top: 'anchor(bottom)', left: 'anchor(left)', width: 'anchor-size(width)' }
265
+ ```
266
+
267
+ Merge overrides with an array (`:style="[popupStyle, { top: '…' }]"`). A simple popup style hides the element unless it is open and slides/fades it in (the `@starting-style` block plays the entry; the `overlay`/`display` transitions make the top-layer appearance and the `display: none` switch animatable). The popover UA pins the element with `inset: 0`, so flippable popups reset it (`inset: auto`) and `position-try: flip-block` flips the anchored base position to the other side when there is no space. The transition is applied only when the user has not requested reduced motion. Under `prefers-reduced-motion: reduce` the popup still opens, but appears instantly:
268
+
269
+ ```css
270
+ /* A simple popup: slide + fade via the Popover API. */
271
+ .cbx-popup {
272
+ inset: auto;
273
+ position-try: flip-block;
274
+ opacity: 0;
275
+ margin-block-start: 0;
276
+
277
+ @media (prefers-reduced-motion: no-preference) {
278
+ transition:
279
+ opacity 0.15s ease,
280
+ margin-block-start 0.15s ease,
281
+ overlay 0.15s ease allow-discrete,
282
+ display 0.15s ease allow-discrete;
283
+ }
284
+
285
+ &:not(:popover-open) {
286
+ display: none;
287
+ }
288
+
289
+ &:popover-open {
290
+ opacity: 1;
291
+ margin-block-start: 0.5rem;
292
+
293
+ @starting-style {
294
+ opacity: 0;
295
+ margin-block-start: 0;
296
+ }
297
+ }
298
+ }
299
+ ```
300
+
301
+ If the dropdown element is a popover (`popover="manual"`), the component drives it with the native **Popover API** (`showPopover()` / `hidePopover()`), so no `v-if` is needed. Otherwise, toggle the element yourself with `v-if="isOpen"` (the `popupStyle` still positions it).
302
+
303
+ ## Keyboard
304
+
305
+ | Key | Behavior |
306
+ |-------------------------|-------------------------------------------|
307
+ | `Enter` / `Space` / `ArrowDown` / `ArrowUp` (closed) | Open the dropdown. |
308
+ | `Backspace` / `Delete` (closed, or open without a filter input, or open on an empty typeahead input) | Remove the last (or only) selected option. Keys aimed at a text input that still holds text (the selection label or a query) keep their native behavior. |
309
+ | `ArrowDown` / `ArrowUp` (open) | Move the highlight. |
310
+ | `PageDown` / `PageUp` | Move the highlight a full page (visible options), clamped at the ends. |
311
+ | `Home` / `End` | Jump to the first/last selectable option (native caret behavior in inputs). |
312
+ | `Enter` (open) | Select the highlighted option. |
313
+ | `Space` (open) | Does nothing on the trigger (the native click that would toggle the popup closed is suppressed); options and text entries keep their native behavior. |
314
+ | `Tab` / `Shift+Tab` | Skip the options list to the next focusable element; closes when focus leaves the widget (`selectOnTab` selects the highlighted option first). |
315
+ | `Escape` | Close and return focus to the trigger. |
316
+
317
+ Clicking outside the container (or tabbing focus out of it) closes the dropdown.
318
+
319
+ Keys pressed on elements outside the combobox's own controls, for example chip remove buttons or popup clear buttons, are never intercepted. They keep their native activation.
320
+
321
+ ## Distribution
322
+
323
+ This package ships both compiled output and raw source:
324
+
325
+ - `@pdanpdan/headless-combobox-vue` → compiled ESM/CJS + types (`dist/`).
326
+ - `@pdanpdan/headless-combobox-vue/source` → raw `src/index.ts`.
327
+ - `@pdanpdan/headless-combobox-vue/HeadlessCombobox.vue` → the raw SFC.
328
+
329
+ ## License
330
+
331
+ MIT
@@ -0,0 +1,27 @@
1
+ import { HeadlessComboboxProps, HeadlessComboboxSlotProps } from './useHeadlessCombobox';
2
+ export type { HeadlessComboboxComboboxInputProps, HeadlessComboboxErrorCode, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxPopupStyle, HeadlessComboboxProps, HeadlessComboboxPropsSource, HeadlessComboboxScope, HeadlessComboboxSlotProps, HeadlessComboboxTriggerProps, } from './useHeadlessCombobox';
3
+ declare const __VLS_export: <O, V = O, Q = string>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_exposed?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
4
+ props: import('vue').PublicProps & __VLS_PrettifyLocal<(Omit<HeadlessComboboxProps<O, V, Q>, "modelValue"> & {
5
+ modelValue?: V | V[] | null;
6
+ }) & {
7
+ "onUpdate:modelValue"?: (value: V | V[] | null) => any;
8
+ }> & (typeof globalThis extends {
9
+ __VLS_PROPS_FALLBACK: infer P;
10
+ } ? P : {});
11
+ expose: (exposed: {}) => void;
12
+ attrs: any;
13
+ slots: {
14
+ default: (props: HeadlessComboboxSlotProps<O, V, Q>) => unknown;
15
+ };
16
+ emit: (event: "update:modelValue", value: V | V[] | null) => void;
17
+ }>) => import('vue').VNode & {
18
+ __ctx?: NonNullable<Awaited<typeof __VLS_setup>>;
19
+ };
20
+ declare const _default: typeof __VLS_export;
21
+ export default _default;
22
+ type __VLS_PrettifyLocal<T> = (T extends any ? {
23
+ [K in keyof T]: T[K];
24
+ } : {
25
+ [K in keyof T as K]: T[K];
26
+ }) & {};
27
+ //# sourceMappingURL=HeadlessCombobox.vue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HeadlessCombobox.vue.d.ts","sourceRoot":"","sources":["../src/HeadlessCombobox.vue"],"names":[],"mappings":"AA+HA,OAAO,KAAK,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAI9F,YAAY,EACV,kCAAkC,EAClC,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAI/B,QAAA,MAAM,YAAY,GAAK,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAC1C,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,gBAAgB,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EAClE;WAwJO,OAAO,KAAK,EAAE,WAAW,GAAG,mBAAmB,CAAC;qBAhFzC,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI;;;KAgF8D,CAAC,GAAG,CAAC,OAAO,UAAU,SAAS;QAAE,oBAAoB,EAAE,MAAM,CAAC,CAAA;KAAE,GAAG,CAAC,GAAG,EAAE,CAAC;YAC5J,CAAC,OAAO,EAAE,EAAE,KAAK,IAAI;WACtB,GAAG;;iBA/IA,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,OAAO;;;EAmJ7D,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAA;CAAI,CAAC;wBACpE,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,mBAAmB,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,GAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,CAAC,GAAG,EAAE,CAAC"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("vue"),t=require("@pdanpdan/headless-combobox-core");var n=[`modelValue`,`options`,`multiple`,`minLength`,`maxLength`,`required`,`disabled`,`readonly`,`closeOnSelect`,`closeOnClickOutside`,`clickOutsideFilter`,`selectOnTab`,`optionValue`,`optionLabel`,`optionFilter`,`id`,`alignSelected`,`inputOnOpen`,`errorMessages`];function r(t){let r=(0,e.isRef)(t)?t.value:typeof t==`function`?t():t,i={};for(let t of n){let n=r[t];i[t]=(0,e.isRef)(n)?n.value:n}return i}function i(n,i){let a=(0,e.computed)(()=>r(n)),o=(0,e.getCurrentInstance)(),s=o?(0,e.useId)():void 0,c=(0,t.createCombobox)({props:a.value,onChange:i,runtime:{nextTick:()=>(0,e.nextTick)(),unwrap:t=>(0,e.toRaw)(t),getDocument:()=>typeof document>`u`?null:document,...s==null?{}:{createId:()=>s}}}),l=(0,e.shallowRef)(c.getSnapshot()),u=c.subscribe(()=>{l.value=c.getSnapshot()});return(0,e.watch)(a,e=>c.setProps(e),{immediate:!0}),o?((0,e.onMounted)(()=>c.mount()),(0,e.onUnmounted)(()=>{u(),c.destroy()})):c.mount(),{isOpen:(0,e.computed)({get:()=>l.value.isOpen,set:e=>c.setState({isOpen:e})}),multiple:(0,e.computed)(()=>l.value.multiple),disabled:(0,e.computed)(()=>l.value.disabled),readonly:(0,e.computed)(()=>l.value.readonly),searchQuery:(0,e.computed)({get:()=>l.value.searchQuery,set:e=>c.getSnapshot().setSearchQuery(e)}),filteredOptions:(0,e.computed)(()=>l.value.filteredOptions),highlightedIndex:(0,e.computed)({get:()=>l.value.highlightedIndex,set:e=>c.setState({highlightedIndex:e})}),alignmentOffset:(0,e.computed)({get:()=>l.value.alignmentOffset,set:e=>c.setState({alignmentOffset:e})}),cssAnchorName:l.value.cssAnchorName,popupStyle:(0,e.computed)(()=>l.value.popupStyle),selectedCount:(0,e.computed)(()=>l.value.selectedCount),selectedList:(0,e.computed)(()=>l.value.selectedList),canSelectMore:(0,e.computed)(()=>l.value.canSelectMore),isSelected:e=>c.getSnapshot().isSelected(e),valid:(0,e.computed)(()=>l.value.valid),errors:(0,e.computed)(()=>l.value.errors),validationMessage:(0,e.computed)(()=>l.value.validationMessage),triggerProps:(0,e.computed)(()=>l.value.triggerProps),inputProps:(0,e.computed)(()=>l.value.inputProps),comboboxInputProps:(0,e.computed)(()=>l.value.comboboxInputProps),listboxProps:(0,e.computed)(()=>l.value.listboxProps),getOptionProps:(e,t)=>c.getSnapshot().getOptionProps(e,t),setSearchQuery:e=>c.getSnapshot().setSearchQuery(e),setHighlightedIndex:e=>c.getSnapshot().setHighlightedIndex(e),toggle:()=>c.getSnapshot().toggle(),open:()=>c.getSnapshot().open(),close:e=>c.getSnapshot().close(e),select:e=>c.getSnapshot().select(e),clear:()=>c.getSnapshot().clear(),focusInput:()=>c.getSnapshot().focusInput(),handleKeydown:e=>c.getSnapshot().handleKeydown(e),setContainerRef:e=>c.getSnapshot().setContainerRef(e),setTriggerRef:e=>c.getSnapshot().setTriggerRef(e),setDropdownRef:e=>c.getSnapshot().setDropdownRef(e),setInputRef:e=>c.getSnapshot().setInputRef(e),setListRef:e=>c.getSnapshot().setListRef(e),setOptionRef:(e,t)=>c.getSnapshot().setOptionRef(e,t)}}var a=(0,e.defineComponent)({__name:`HeadlessCombobox`,props:(0,e.mergeModels)({options:{},multiple:{type:Boolean},minLength:{},maxLength:{},required:{type:Boolean},disabled:{type:Boolean},readonly:{type:Boolean},closeOnSelect:{type:[Boolean,null],default:null},closeOnClickOutside:{type:Boolean,default:!0},clickOutsideFilter:{},selectOnTab:{type:Boolean},optionValue:{},optionLabel:{},optionFilter:{},id:{},alignSelected:{type:Boolean},inputOnOpen:{default:`select`},errorMessages:{}},{modelValue:{default:null},modelModifiers:{}}),emits:[`update:modelValue`],setup(t){let n=t,r=(0,e.useModel)(t,`modelValue`),{isOpen:a,multiple:o,disabled:s,readonly:c,searchQuery:l,filteredOptions:u,highlightedIndex:d,alignmentOffset:f,cssAnchorName:p,popupStyle:m,selectedCount:h,selectedList:g,canSelectMore:_,isSelected:v,valid:y,errors:b,validationMessage:x,triggerProps:S,inputProps:C,comboboxInputProps:w,listboxProps:T,getOptionProps:E,setSearchQuery:D,setHighlightedIndex:O,toggle:k,open:A,close:j,select:M,clear:N,focusInput:P,handleKeydown:F,setContainerRef:I,setTriggerRef:L,setDropdownRef:R,setInputRef:z,setListRef:B,setOptionRef:V}=i(()=>({...n,modelValue:r.value}),e=>{r.value=e});return(t,n)=>(0,e.renderSlot)(t.$slots,`default`,{isOpen:(0,e.unref)(a),multiple:(0,e.unref)(o)===!0,disabled:(0,e.unref)(s)===!0,readonly:(0,e.unref)(c)===!0,searchQuery:(0,e.unref)(l),filteredOptions:(0,e.unref)(u),highlightedIndex:(0,e.unref)(d),alignmentOffset:(0,e.unref)(f),cssAnchorName:(0,e.unref)(p),popupStyle:(0,e.unref)(m),selectedCount:(0,e.unref)(h),selectedList:(0,e.unref)(g),canSelectMore:(0,e.unref)(_),isSelected:(0,e.unref)(v),valid:(0,e.unref)(y),errors:(0,e.unref)(b),validationMessage:(0,e.unref)(x),triggerProps:(0,e.unref)(S),inputProps:(0,e.unref)(C),comboboxInputProps:(0,e.unref)(w),listboxProps:(0,e.unref)(T),getOptionProps:(0,e.unref)(E),setSearchQuery:(0,e.unref)(D),setHighlightedIndex:(0,e.unref)(O),toggle:(0,e.unref)(k),open:(0,e.unref)(A),close:(0,e.unref)(j),select:(0,e.unref)(M),clear:(0,e.unref)(N),focusInput:(0,e.unref)(P),handleKeydown:(0,e.unref)(F),setContainerRef:(0,e.unref)(I),setTriggerRef:(0,e.unref)(L),setDropdownRef:(0,e.unref)(R),setInputRef:(0,e.unref)(z),setListRef:(0,e.unref)(B),setOptionRef:(0,e.unref)(V)})}});exports.HeadlessCombobox=a,exports.useHeadlessCombobox=i;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["isRef","computed","getCurrentInstance","useId","createCombobox","nextTick","toRaw","shallowRef","_useModel","_renderSlot","_unref","vue","_pdanpdan_headless_combobox_core","PROP_KEYS","resolveProps","base","source","resolved","key","value","useHeadlessCombobox","resolvedProps","propsSource","instance","generatedId","store","emit","snapshot","unsubscribe","next","option","index","returnFocus","event","el","HeadlessCombobox_default","\"modelValue\"","\"modelModifiers\"","props","__props","model","_ctx","isOpen","multiple","disabled","readonly","searchQuery","filteredOptions","highlightedIndex","alignmentOffset","cssAnchorName","popupStyle","selectedCount","selectedList","canSelectMore","isSelected","valid","errors","validationMessage","triggerProps","inputProps","comboboxInputProps","listboxProps","getOptionProps","setSearchQuery","setHighlightedIndex","toggle","open","close","select","clear","focusInput","handleKeydown","setContainerRef","setTriggerRef","setDropdownRef","setInputRef","setListRef","setOptionRef"],"sources":["../src/useHeadlessCombobox.ts","../src/HeadlessCombobox.vue"],"sourcesContent":["import type {\n HeadlessComboboxProps,\n HeadlessComboboxSnapshot,\n} from '@pdanpdan/headless-combobox-core';\nimport type { ComputedRef, Ref } from 'vue';\n\nimport { createCombobox } from '@pdanpdan/headless-combobox-core';\nimport {\n computed,\n getCurrentInstance,\n isRef,\n nextTick,\n onMounted,\n onUnmounted,\n shallowRef,\n toRaw,\n useId,\n watch,\n} from 'vue';\n\nexport type {\n HeadlessComboboxComboboxInputProps,\n HeadlessComboboxErrorCode,\n HeadlessComboboxInputProps,\n HeadlessComboboxListboxProps,\n HeadlessComboboxOptionProps,\n HeadlessComboboxPopupStyle,\n HeadlessComboboxProps,\n HeadlessComboboxTriggerProps,\n} from '@pdanpdan/headless-combobox-core';\n\n/** Scope exposed by the default slot: plain values, no refs. */\nexport type HeadlessComboboxSlotProps<O, V, Q = string> = HeadlessComboboxSnapshot<O, V, Q>;\n\n/**\n * Accepted forms for `useHeadlessCombobox` props: a plain props object (fields\n * may be refs, which are unwrapped and tracked), a ref to a props object, or a\n * getter. Normalized internally, so no `reactive()` wrapper needed by callers.\n */\nexport type HeadlessComboboxPropsSource<O, V = O, Q = string>\n = | HeadlessComboboxProps<O, V, Q>\n | Ref<HeadlessComboboxProps<O, V, Q>>\n | (() => HeadlessComboboxProps<O, V, Q>)\n | { [K in keyof HeadlessComboboxProps<O, V, Q>]: HeadlessComboboxProps<O, V, Q>[ K ] | Ref<HeadlessComboboxProps<O, V, Q>[ K ]> };\n\n/** Return value of `useHeadlessCombobox`: Vue refs for state, stable actions. */\nexport interface HeadlessComboboxScope<O, V, Q = string> {\n // State\n isOpen: Ref<boolean>;\n multiple: ComputedRef<boolean>;\n disabled: ComputedRef<boolean>;\n readonly: ComputedRef<boolean>;\n searchQuery: Ref<Q | undefined>;\n filteredOptions: ComputedRef<O[]>;\n highlightedIndex: Ref<number>;\n alignmentOffset: Ref<number>;\n cssAnchorName: string;\n popupStyle: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'popupStyle' ]>;\n selectedCount: ComputedRef<number>;\n selectedList: ComputedRef<V[]>;\n canSelectMore: ComputedRef<boolean>;\n isSelected: (option: O) => boolean;\n valid: ComputedRef<boolean>;\n errors: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'errors' ]>;\n validationMessage: ComputedRef<string>;\n // ARIA prop bags (spread with v-bind)\n triggerProps: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'triggerProps' ]>;\n inputProps: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'inputProps' ]>;\n comboboxInputProps: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'comboboxInputProps' ]>;\n listboxProps: ComputedRef<HeadlessComboboxSnapshot<O, V, Q>[ 'listboxProps' ]>;\n getOptionProps: (option: O, index: number) => HeadlessComboboxSnapshot<O, V, Q>[ 'getOptionProps' ] extends (option: O, index: number) => infer R\n ? R\n : never;\n // Actions\n setSearchQuery: (value: Q | undefined) => void;\n setHighlightedIndex: (index: number) => void;\n toggle: () => void;\n open: () => Promise<void>;\n close: (returnFocus?: boolean) => void;\n select: (option: O) => void;\n clear: () => void;\n focusInput: () => void;\n handleKeydown: (event: Event) => void;\n // Element wiring\n setContainerRef: (el: unknown) => void;\n setTriggerRef: (el: unknown) => void;\n setDropdownRef: (el: unknown) => void;\n setInputRef: (el: unknown) => void;\n setListRef: (el: unknown) => void;\n setOptionRef: (option: O, el: unknown) => void;\n}\n\n/** The props fields read from a props source; a fixed list keeps tracking deterministic. */\nconst PROP_KEYS = [\n 'modelValue',\n 'options',\n 'multiple',\n 'minLength',\n 'maxLength',\n 'required',\n 'disabled',\n 'readonly',\n 'closeOnSelect',\n 'closeOnClickOutside',\n 'clickOutsideFilter',\n 'selectOnTab',\n 'optionValue',\n 'optionLabel',\n 'optionFilter',\n 'id',\n 'alignSelected',\n 'inputOnOpen',\n 'errorMessages',\n] as const;\n\nfunction resolveProps<O, V, Q>(source: HeadlessComboboxPropsSource<O, V, Q>): HeadlessComboboxProps<O, V, Q> {\n const base = isRef(source)\n ? source.value\n : typeof source === 'function'\n ? source()\n : source;\n const resolved: Record<string, unknown> = {};\n for (const key of PROP_KEYS) {\n const value = (base as Record<string, unknown>)[ key ];\n resolved[ key ] = isRef(value)\n ? value.value\n : value;\n }\n return resolved as unknown as HeadlessComboboxProps<O, V, Q>;\n}\n\n/**\n * Vue adapter for the framework-independent combobox core.\n *\n * Returns Vue refs backed by the core snapshot. Call it from `setup()`; it\n * mounts the document listeners and uses Vue's `useId()` for default ids.\n */\nexport function useHeadlessCombobox<O, V = O, Q = string>(\n propsSource: HeadlessComboboxPropsSource<O, V, Q>,\n emit: (value: V | V[] | null) => void,\n): HeadlessComboboxScope<O, V, Q> {\n const resolvedProps = computed(() => resolveProps(propsSource));\n const instance = getCurrentInstance();\n const generatedId = instance\n ? useId()\n : undefined;\n\n const store = createCombobox<O, V, Q>({\n props: resolvedProps.value,\n onChange: emit,\n runtime: {\n nextTick: () => nextTick(),\n unwrap: (value) => toRaw(value),\n getDocument: () => (typeof document === 'undefined'\n ? null\n : document),\n ...(generatedId != null\n ? {\n createId: () => generatedId,\n }\n : {}),\n },\n });\n\n const snapshot = shallowRef(store.getSnapshot());\n const unsubscribe = store.subscribe(() => {\n snapshot.value = store.getSnapshot();\n });\n\n // Props may be Vue-reactive (component props) or contain refs (composable\n // callers). The computed tracks both; push each change into the core.\n watch(resolvedProps, (next) => store.setProps(next), { immediate: true });\n\n if (instance) {\n onMounted(() => store.mount());\n onUnmounted(() => {\n unsubscribe();\n store.destroy();\n });\n } else {\n store.mount();\n }\n\n const isSelected = (option: O) => store.getSnapshot().isSelected(option);\n const getOptionProps = (option: O, index: number) =>\n store.getSnapshot().getOptionProps(option, index);\n\n return {\n isOpen: computed({\n get: () => snapshot.value.isOpen,\n set: (value) => store.setState({ isOpen: value }),\n }),\n multiple: computed(() => snapshot.value.multiple),\n disabled: computed(() => snapshot.value.disabled),\n readonly: computed(() => snapshot.value.readonly),\n searchQuery: computed({\n get: () => snapshot.value.searchQuery,\n set: (value) => store.getSnapshot().setSearchQuery(value),\n }),\n filteredOptions: computed(() => snapshot.value.filteredOptions),\n highlightedIndex: computed({\n get: () => snapshot.value.highlightedIndex,\n set: (value) => store.setState({ highlightedIndex: value }),\n }),\n alignmentOffset: computed({\n get: () => snapshot.value.alignmentOffset,\n set: (value) => store.setState({ alignmentOffset: value }),\n }),\n cssAnchorName: snapshot.value.cssAnchorName,\n popupStyle: computed(() => snapshot.value.popupStyle),\n selectedCount: computed(() => snapshot.value.selectedCount),\n selectedList: computed(() => snapshot.value.selectedList),\n canSelectMore: computed(() => snapshot.value.canSelectMore),\n isSelected,\n valid: computed(() => snapshot.value.valid),\n errors: computed(() => snapshot.value.errors),\n validationMessage: computed(() => snapshot.value.validationMessage),\n triggerProps: computed(() => snapshot.value.triggerProps),\n inputProps: computed(() => snapshot.value.inputProps),\n comboboxInputProps: computed(() => snapshot.value.comboboxInputProps),\n listboxProps: computed(() => snapshot.value.listboxProps),\n getOptionProps,\n setSearchQuery: (value) => store.getSnapshot().setSearchQuery(value),\n setHighlightedIndex: (index) => store.getSnapshot().setHighlightedIndex(index),\n toggle: () => store.getSnapshot().toggle(),\n open: () => store.getSnapshot().open(),\n close: (returnFocus) => store.getSnapshot().close(returnFocus),\n select: (option) => store.getSnapshot().select(option),\n clear: () => store.getSnapshot().clear(),\n focusInput: () => store.getSnapshot().focusInput(),\n handleKeydown: (event) => store.getSnapshot().handleKeydown(event),\n setContainerRef: (el) => store.getSnapshot().setContainerRef(el),\n setTriggerRef: (el) => store.getSnapshot().setTriggerRef(el),\n setDropdownRef: (el) => store.getSnapshot().setDropdownRef(el),\n setInputRef: (el) => store.getSnapshot().setInputRef(el),\n setListRef: (el) => store.getSnapshot().setListRef(el),\n setOptionRef: (option, el) => store.getSnapshot().setOptionRef(option, el),\n };\n}\n","<script setup lang=\"ts\" generic=\"O, V = O, Q = string\">\nimport type { HeadlessComboboxProps, HeadlessComboboxSlotProps } from './useHeadlessCombobox';\n\nimport { useHeadlessCombobox } from './useHeadlessCombobox';\n\nexport type {\n HeadlessComboboxComboboxInputProps,\n HeadlessComboboxErrorCode,\n HeadlessComboboxInputProps,\n HeadlessComboboxListboxProps,\n HeadlessComboboxOptionProps,\n HeadlessComboboxPopupStyle,\n HeadlessComboboxProps,\n HeadlessComboboxPropsSource,\n HeadlessComboboxScope,\n HeadlessComboboxSlotProps,\n HeadlessComboboxTriggerProps,\n} from './useHeadlessCombobox';\n\nconst props = withDefaults(defineProps<Omit<HeadlessComboboxProps<O, V, Q>, 'modelValue'>>(), {\n // defaults to auto based on `multiple`.\n closeOnSelect: null,\n // Vue casts absent boolean props to `false`; the default must be explicit.\n closeOnClickOutside: true,\n inputOnOpen: 'select',\n});\n\ndefineSlots<{\n default: (props: HeadlessComboboxSlotProps<O, V, Q>) => unknown;\n}>();\n\n// No parent `v-model`? The model falls back to local state (`defineModel`\n// keeps the last set value internally) so the component still works.\nconst model = defineModel<V | V[] | null>('modelValue', { default: null });\n\nconst {\n isOpen,\n multiple,\n disabled,\n readonly,\n searchQuery,\n filteredOptions,\n highlightedIndex,\n alignmentOffset,\n cssAnchorName,\n popupStyle,\n selectedCount,\n selectedList,\n canSelectMore,\n isSelected,\n valid,\n errors,\n validationMessage,\n triggerProps,\n inputProps,\n comboboxInputProps,\n listboxProps,\n getOptionProps,\n setSearchQuery,\n setHighlightedIndex,\n toggle,\n open,\n close,\n select,\n clear,\n focusInput,\n handleKeydown,\n setContainerRef,\n setTriggerRef,\n setDropdownRef,\n setInputRef,\n setListRef,\n setOptionRef,\n} = useHeadlessCombobox<O, V, Q>(\n // The getter keeps the props reactive: reading `props` inside it tracks\n // every field, and the model ref is read on each access too.\n () => ({ ...props, modelValue: model.value }) as unknown as HeadlessComboboxProps<O, V, Q>,\n (value) => {\n model.value = value;\n },\n);\n</script>\n\n<template>\n <slot\n :is-open=\"isOpen\"\n :multiple=\"multiple === true\"\n :disabled=\"disabled === true\"\n :readonly=\"readonly === true\"\n :search-query=\"(searchQuery as Q | undefined)\"\n :filtered-options=\"filteredOptions\"\n :highlighted-index=\"highlightedIndex\"\n :alignment-offset=\"alignmentOffset\"\n :css-anchor-name=\"cssAnchorName\"\n :popup-style=\"popupStyle\"\n :selected-count=\"selectedCount\"\n :selected-list=\"selectedList\"\n :can-select-more=\"canSelectMore\"\n :is-selected=\"isSelected\"\n :valid=\"valid\"\n :errors=\"errors\"\n :validation-message=\"validationMessage\"\n :trigger-props=\"triggerProps\"\n :input-props=\"inputProps\"\n :combobox-input-props=\"comboboxInputProps\"\n :listbox-props=\"listboxProps\"\n :get-option-props=\"getOptionProps\"\n :set-search-query=\"setSearchQuery\"\n :set-highlighted-index=\"setHighlightedIndex\"\n :toggle=\"toggle\"\n :open=\"open\"\n :close=\"close\"\n :select=\"select\"\n :clear=\"clear\"\n :focus-input=\"focusInput\"\n :handle-keydown=\"handleKeydown\"\n :set-container-ref=\"setContainerRef\"\n :set-trigger-ref=\"setTriggerRef\"\n :set-dropdown-ref=\"setDropdownRef\"\n :set-input-ref=\"setInputRef\"\n :set-list-ref=\"setListRef\"\n :set-option-ref=\"setOptionRef\"\n />\n</template>\n"],"mappings":"A,sIA6FA,IAAMa,EAAY,CAChB,aACA,UACA,WACA,YACA,YACA,WACA,WACA,WACA,gBACA,sBACA,qBACA,cACA,cACA,cACA,eACA,KACA,gBACA,cACA,eACF,EAEA,SAASC,EAAsB,EAA8E,CAC3G,IAAMC,GAAA,EAAOf,EAAAA,MAAAA,CAAMgB,CAAM,EACrBA,EAAO,MACP,OAAOA,GAAW,WAChBA,EAAO,EACPA,EACAC,EAAoC,CAAC,EAC3C,IAAK,IAAMC,KAAOL,EAAW,CAC3B,IAAMM,EAASJ,EAAkCG,GACjD,EAA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EAAAA,MAAAA,CAAAmD,CAAA,EACtB,cAAA,EAAenD,EAAAA,MAAAA,CAAAoD,CAAA,EACf,gBAAA,EAAkBpD,EAAAA,MAAAA,CAAAqD,CAAA,EAClB,gBAAA,EAAkBrD,EAAAA,MAAAA,CAAAsD,CAAA,EAClB,qBAAA,EAAuBtD,EAAAA,MAAAA,CAAAuD,CAAA,EACvB,QAAA,EAAQvD,EAAAA,MAAAA,CAAAwD,CAAA,EACR,MAAA,EAAMxD,EAAAA,MAAAA,CAAAyD,CAAA,EACN,OAAA,EAAOzD,EAAAA,MAAAA,CAAA0D,CAAA,EACP,QAAA,EAAQ1D,EAAAA,MAAAA,CAAA2D,CAAA,EACR,OAAA,EAAO3D,EAAAA,MAAAA,CAAA4D,CAAA,EACP,YAAA,EAAa5D,EAAAA,MAAAA,CAAA6D,CAAA,EACb,eAAA,EAAgB7D,EAAAA,MAAAA,CAAA8D,CAAA,EAChB,iBAAA,EAAmB9D,EAAAA,MAAAA,CAAA+D,CAAA,EACnB,eAAA,EAAiB/D,EAAAA,MAAAA,CAAAgE,CAAA,EACjB,gBAAA,EAAkBhE,EAAAA,MAAAA,CAAAiE,CAAA,EAClB,aAAA,EAAejE,EAAAA,MAAAA,CAAAkE,CAAA,EACf,YAAA,EAAclE,EAAAA,MAAAA,CAAAmE,CAAA,EACd,cAAA,EAAgBnE,EAAAA,MAAAA,CAAAoE,CAAA,C"}
@@ -0,0 +1,4 @@
1
+ export { default as HeadlessCombobox } from './HeadlessCombobox.vue';
2
+ export { useHeadlessCombobox } from './useHeadlessCombobox';
3
+ export type { HeadlessComboboxComboboxInputProps, HeadlessComboboxErrorCode, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxPopupStyle, HeadlessComboboxProps, HeadlessComboboxPropsSource, HeadlessComboboxScope, HeadlessComboboxSlotProps, HeadlessComboboxTriggerProps, } from './useHeadlessCombobox';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EACV,kCAAkC,EAClC,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,2BAA2B,EAC3B,qBAAqB,EACrB,yBAAyB,EACzB,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,183 @@
1
+ import { computed as e, defineComponent as t, getCurrentInstance as n, isRef as r, mergeModels as i, nextTick as a, onMounted as o, onUnmounted as s, renderSlot as c, shallowRef as l, toRaw as u, unref as d, useId as f, useModel as p, watch as m } from "vue";
2
+ import { createCombobox as h } from "@pdanpdan/headless-combobox-core";
3
+ // src/useHeadlessCombobox.ts
4
+ var g = [
5
+ "modelValue",
6
+ "options",
7
+ "multiple",
8
+ "minLength",
9
+ "maxLength",
10
+ "required",
11
+ "disabled",
12
+ "readonly",
13
+ "closeOnSelect",
14
+ "closeOnClickOutside",
15
+ "clickOutsideFilter",
16
+ "selectOnTab",
17
+ "optionValue",
18
+ "optionLabel",
19
+ "optionFilter",
20
+ "id",
21
+ "alignSelected",
22
+ "inputOnOpen",
23
+ "errorMessages"
24
+ ];
25
+ function _(e) {
26
+ let t = r(e) ? e.value : typeof e == "function" ? e() : e, n = {};
27
+ for (let e of g) {
28
+ let i = t[e];
29
+ n[e] = r(i) ? i.value : i;
30
+ }
31
+ return n;
32
+ }
33
+ function v(t, r) {
34
+ let i = e(() => _(t)), c = n(), d = c ? f() : void 0, p = h({
35
+ props: i.value,
36
+ onChange: r,
37
+ runtime: {
38
+ nextTick: () => a(),
39
+ unwrap: (e) => u(e),
40
+ getDocument: () => typeof document > "u" ? null : document,
41
+ ...d == null ? {} : { createId: () => d }
42
+ }
43
+ }), g = l(p.getSnapshot()), v = p.subscribe(() => {
44
+ g.value = p.getSnapshot();
45
+ });
46
+ return m(i, (e) => p.setProps(e), { immediate: !0 }), c ? (o(() => p.mount()), s(() => {
47
+ v(), p.destroy();
48
+ })) : p.mount(), {
49
+ isOpen: e({
50
+ get: () => g.value.isOpen,
51
+ set: (e) => p.setState({ isOpen: e })
52
+ }),
53
+ multiple: e(() => g.value.multiple),
54
+ disabled: e(() => g.value.disabled),
55
+ readonly: e(() => g.value.readonly),
56
+ searchQuery: e({
57
+ get: () => g.value.searchQuery,
58
+ set: (e) => p.getSnapshot().setSearchQuery(e)
59
+ }),
60
+ filteredOptions: e(() => g.value.filteredOptions),
61
+ highlightedIndex: e({
62
+ get: () => g.value.highlightedIndex,
63
+ set: (e) => p.setState({ highlightedIndex: e })
64
+ }),
65
+ alignmentOffset: e({
66
+ get: () => g.value.alignmentOffset,
67
+ set: (e) => p.setState({ alignmentOffset: e })
68
+ }),
69
+ cssAnchorName: g.value.cssAnchorName,
70
+ popupStyle: e(() => g.value.popupStyle),
71
+ selectedCount: e(() => g.value.selectedCount),
72
+ selectedList: e(() => g.value.selectedList),
73
+ canSelectMore: e(() => g.value.canSelectMore),
74
+ isSelected: (e) => p.getSnapshot().isSelected(e),
75
+ valid: e(() => g.value.valid),
76
+ errors: e(() => g.value.errors),
77
+ validationMessage: e(() => g.value.validationMessage),
78
+ triggerProps: e(() => g.value.triggerProps),
79
+ inputProps: e(() => g.value.inputProps),
80
+ comboboxInputProps: e(() => g.value.comboboxInputProps),
81
+ listboxProps: e(() => g.value.listboxProps),
82
+ getOptionProps: (e, t) => p.getSnapshot().getOptionProps(e, t),
83
+ setSearchQuery: (e) => p.getSnapshot().setSearchQuery(e),
84
+ setHighlightedIndex: (e) => p.getSnapshot().setHighlightedIndex(e),
85
+ toggle: () => p.getSnapshot().toggle(),
86
+ open: () => p.getSnapshot().open(),
87
+ close: (e) => p.getSnapshot().close(e),
88
+ select: (e) => p.getSnapshot().select(e),
89
+ clear: () => p.getSnapshot().clear(),
90
+ focusInput: () => p.getSnapshot().focusInput(),
91
+ handleKeydown: (e) => p.getSnapshot().handleKeydown(e),
92
+ setContainerRef: (e) => p.getSnapshot().setContainerRef(e),
93
+ setTriggerRef: (e) => p.getSnapshot().setTriggerRef(e),
94
+ setDropdownRef: (e) => p.getSnapshot().setDropdownRef(e),
95
+ setInputRef: (e) => p.getSnapshot().setInputRef(e),
96
+ setListRef: (e) => p.getSnapshot().setListRef(e),
97
+ setOptionRef: (e, t) => p.getSnapshot().setOptionRef(e, t)
98
+ };
99
+ }
100
+ // src/HeadlessCombobox.vue
101
+ var y = /* @__PURE__ */ t({
102
+ __name: "HeadlessCombobox",
103
+ props: /*@__PURE__*/ i({
104
+ options: {},
105
+ multiple: { type: Boolean },
106
+ minLength: {},
107
+ maxLength: {},
108
+ required: { type: Boolean },
109
+ disabled: { type: Boolean },
110
+ readonly: { type: Boolean },
111
+ closeOnSelect: {
112
+ type: [Boolean, null],
113
+ default: null
114
+ },
115
+ closeOnClickOutside: {
116
+ type: Boolean,
117
+ default: !0
118
+ },
119
+ clickOutsideFilter: {},
120
+ selectOnTab: { type: Boolean },
121
+ optionValue: {},
122
+ optionLabel: {},
123
+ optionFilter: {},
124
+ id: {},
125
+ alignSelected: { type: Boolean },
126
+ inputOnOpen: { default: "select" },
127
+ errorMessages: {}
128
+ }, {
129
+ modelValue: { default: null },
130
+ modelModifiers: {}
131
+ }),
132
+ emits: ["update:modelValue"],
133
+ setup(e) {
134
+ let t = e, n = p(e, "modelValue"), { isOpen: r, multiple: i, disabled: a, readonly: o, searchQuery: s, filteredOptions: l, highlightedIndex: u, alignmentOffset: f, cssAnchorName: m, popupStyle: h, selectedCount: g, selectedList: _, canSelectMore: y, isSelected: b, valid: x, errors: S, validationMessage: C, triggerProps: w, inputProps: T, comboboxInputProps: E, listboxProps: D, getOptionProps: O, setSearchQuery: k, setHighlightedIndex: A, toggle: j, open: M, close: N, select: P, clear: F, focusInput: I, handleKeydown: L, setContainerRef: R, setTriggerRef: z, setDropdownRef: B, setInputRef: V, setListRef: H, setOptionRef: U } = v(() => ({
135
+ ...t,
136
+ modelValue: n.value
137
+ }), (e) => {
138
+ n.value = e;
139
+ });
140
+ return (e, t) => c(e.$slots, "default", {
141
+ isOpen: d(r),
142
+ multiple: d(i) === !0,
143
+ disabled: d(a) === !0,
144
+ readonly: d(o) === !0,
145
+ searchQuery: d(s),
146
+ filteredOptions: d(l),
147
+ highlightedIndex: d(u),
148
+ alignmentOffset: d(f),
149
+ cssAnchorName: d(m),
150
+ popupStyle: d(h),
151
+ selectedCount: d(g),
152
+ selectedList: d(_),
153
+ canSelectMore: d(y),
154
+ isSelected: d(b),
155
+ valid: d(x),
156
+ errors: d(S),
157
+ validationMessage: d(C),
158
+ triggerProps: d(w),
159
+ inputProps: d(T),
160
+ comboboxInputProps: d(E),
161
+ listboxProps: d(D),
162
+ getOptionProps: d(O),
163
+ setSearchQuery: d(k),
164
+ setHighlightedIndex: d(A),
165
+ toggle: d(j),
166
+ open: d(M),
167
+ close: d(N),
168
+ select: d(P),
169
+ clear: d(F),
170
+ focusInput: d(I),
171
+ handleKeydown: d(L),
172
+ setContainerRef: d(R),
173
+ setTriggerRef: d(z),
174
+ setDropdownRef: d(B),
175
+ setInputRef: d(V),
176
+ setListRef: d(H),
177
+ setOptionRef: d(U)
178
+ });
179
+ }
180
+ });
181
+ export { y as HeadlessCombobox, v as useHeadlessCombobox };
182
+
183
+ //# sourceMappingURL=index.mjs.map