@pdanpdan/headless-combobox-svelte 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,77 @@
1
- # Temporary Holding Version
1
+ # @pdanpdan/headless-combobox-svelte
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 combobox for Svelte 5. Backed by [`@pdanpdan/headless-combobox-core`](../headless-combobox-core).
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @pdanpdan/headless-combobox-svelte
9
+ ```
10
+
11
+ `svelte@>=5` is a peer dependency.
12
+
13
+ ## Usage
14
+
15
+ ```svelte
16
+ <script lang="ts">
17
+ import HeadlessCombobox from '@pdanpdan/headless-combobox-svelte/HeadlessCombobox.svelte';
18
+ import { toSvelteProps } from '@pdanpdan/headless-combobox-svelte';
19
+
20
+ const users = [
21
+ { id: 1, name: 'Wade Cooper' },
22
+ { id: 2, name: 'Arlene Mccoy' },
23
+ ];
24
+ let value = $state<typeof users[number] | null>(null);
25
+ </script>
26
+
27
+ <HeadlessCombobox
28
+ options={users}
29
+ optionLabel={(user) => user.name}
30
+ modelValue={value}
31
+ onChange={(next) => (value = next as typeof users[number] | null)}
32
+ >
33
+ {#snippet children(scope)}
34
+ <div
35
+ {@attach (el) => {
36
+ scope.setContainerRef(el);
37
+ return () => scope.setContainerRef(null);
38
+ }}
39
+ >
40
+ <button
41
+ type="button"
42
+ {...toSvelteProps(scope.triggerProps)}
43
+ {@attach (el) => {
44
+ scope.setTriggerRef(el);
45
+ return () => scope.setTriggerRef(null);
46
+ }}
47
+ >
48
+ {value?.name ?? 'Select…'}
49
+ </button>
50
+
51
+ <ul
52
+ {...toSvelteProps(scope.listboxProps)}
53
+ {@attach (el) => {
54
+ scope.setDropdownRef(el);
55
+ return () => scope.setDropdownRef(null);
56
+ }}
57
+ >
58
+ {#each scope.filteredOptions as user, index (user.id)}
59
+ <li
60
+ {...toSvelteProps(scope.getOptionProps(user, index))}
61
+ {@attach (el) => {
62
+ scope.setOptionRef(user, el);
63
+ return () => scope.setOptionRef(user, null);
64
+ }}
65
+ >
66
+ {user.name}
67
+ </li>
68
+ {/each}
69
+ </ul>
70
+ </div>
71
+ {/snippet}
72
+ </HeadlessCombobox>
73
+ ```
74
+
75
+ ### Store API
76
+
77
+ `createComboboxStore({ props, onChange })` returns a Svelte store, so `$combobox` gives the live snapshot. Call `store.mount()` / `store.destroy()` yourself when using the store directly. `toSvelteProps` maps the core's handler keys to Svelte 5's lowercase event attributes.
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("@pdanpdan/headless-combobox-core"),t=require("svelte");var n=[`modelValue`,`options`,`multiple`,`minLength`,`maxLength`,`required`,`disabled`,`readonly`,`closeOnSelect`,`closeOnClickOutside`,`clickOutsideFilter`,`selectOnTab`,`optionValue`,`optionLabel`,`optionFilter`,`id`,`alignSelected`,`inputOnOpen`,`errorMessages`],r={onClick:`onclick`,onKeydown:`onkeydown`,onMousedown:`onmousedown`,onMousemove:`onmousemove`,onFocus:`onfocus`,onInput:`oninput`};function i(n){let r=(0,e.createCombobox)({props:typeof n.props==`function`?n.props():n.props,onChange:e=>n.onChange?.(e),runtime:{nextTick:()=>(0,t.tick)()}});return{subscribe:e=>(e(r.getSnapshot()),r.subscribe(()=>e(r.getSnapshot()))),getSnapshot:r.getSnapshot,setProps:r.setProps,mount:r.mount,destroy:r.destroy}}function a(e){let t={};for(let r of n)t[r]=e[r];return t}function o(e){let t={};for(let[n,i]of Object.entries(e))t[r[n]??n]=i;return t}exports.createComboboxStore=i,exports.toCoreProps=a,exports.toSvelteProps=o;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["createCombobox","tick","_pdanpdan_headless_combobox_core","svelte","CORE_PROP_KEYS","SVELTE_EVENT_NAMES","createComboboxStore","store","options","value","run","toCoreProps","resolved","key","props","toSvelteProps","adapted"],"sources":["../src/store.ts"],"sourcesContent":["import type {\n HeadlessComboboxProps,\n HeadlessComboboxSnapshot,\n} from '@pdanpdan/headless-combobox-core';\n\nimport { createCombobox } from '@pdanpdan/headless-combobox-core';\nimport { tick } from 'svelte';\n\n/** Props read from a Svelte component; a fixed list keeps tracking deterministic. */\nconst CORE_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\nconst SVELTE_EVENT_NAMES: Record<string, string> = {\n onClick: 'onclick',\n onKeydown: 'onkeydown',\n onMousedown: 'onmousedown',\n onMousemove: 'onmousemove',\n onFocus: 'onfocus',\n onInput: 'oninput',\n};\n\nexport interface CreateSvelteComboboxOptions<O, V = O, Q = string> {\n /** A plain props object or a reactive getter. */\n props: HeadlessComboboxProps<O, V, Q> | (() => HeadlessComboboxProps<O, V, Q>);\n onChange?: (value: V | V[] | null) => void;\n}\n\n/** Svelte store (`$store` / `get(store)`) plus the adapter wiring. */\nexport interface SvelteComboboxStore<O, V, Q = string> {\n subscribe: (run: (value: HeadlessComboboxSnapshot<O, V, Q>) => void) => () => void;\n getSnapshot: () => HeadlessComboboxSnapshot<O, V, Q>;\n setProps: (props: HeadlessComboboxProps<O, V, Q>) => void;\n mount: () => void;\n destroy: () => void;\n}\n\n/**\n * Svelte adapter for the framework-independent combobox core.\n *\n * `$combobox` in a component gives the live snapshot (state + actions):\n *\n * ```svelte\n * <script>\n * const combobox = createComboboxStore({ props: () => ({ modelValue, options }) });\n * </script>\n * <button {...toSvelteProps($combobox.triggerProps)} />\n * ```\n */\nexport function createComboboxStore<O, V = O, Q = string>(\n options: CreateSvelteComboboxOptions<O, V, Q>,\n): SvelteComboboxStore<O, V, Q> {\n const resolve = () => (typeof options.props === 'function'\n ? options.props()\n : options.props);\n\n const store = createCombobox<O, V, Q>({\n props: resolve(),\n onChange: (value) => options.onChange?.(value),\n runtime: {\n nextTick: () => tick(),\n },\n });\n\n return {\n subscribe: (run) => {\n run(store.getSnapshot());\n return store.subscribe(() => run(store.getSnapshot()));\n },\n getSnapshot: store.getSnapshot,\n setProps: store.setProps,\n mount: store.mount,\n destroy: store.destroy,\n };\n}\n\n/**\n * Pick the combobox props out of a Svelte `$props()` object and drop component\n * plumbing (`children`, `onChange`). Reading inside an `$effect` tracks them.\n */\nexport function toCoreProps<O, V, Q>(props: Record<string, unknown>): HeadlessComboboxProps<O, V, Q> {\n const resolved: Record<string, unknown> = {};\n for (const key of CORE_PROP_KEYS) {\n resolved[ key ] = props[ key ];\n }\n return resolved as unknown as HeadlessComboboxProps<O, V, Q>;\n}\n\n/**\n * Adapt a core ARIA prop bag to Svelte 5 event attribute names:\n *\n * ```svelte\n * <button {...toSvelteProps(scope.triggerProps)} />\n * ```\n */\nexport function toSvelteProps<T extends object>(props: T): Record<string, unknown> {\n const adapted: Record<string, unknown> = {};\n for (const [ key, value ] of Object.entries(props)) {\n adapted[ SVELTE_EVENT_NAMES[ key ] ?? key ] = value;\n }\n return adapted;\n}\n"],"mappings":"A,yIASA,IAAMI,EAAiB,CACrB,aACA,UACA,WACA,YACA,YACA,WACA,WACA,WACA,gBACA,sBACA,qBACA,cACA,cACA,cACA,eACA,KACA,gBACA,cACA,eACF,EAEMC,EAA6C,CACjD,QAAS,UACT,UAAW,YACX,YAAa,cACb,YAAa,cACb,QAAS,UACT,QAAS,SACX,EA6BA,SAAgBC,EACd,EAC8B,CAK9B,IAAMC,GAAA,EAAQP,EAAAA,eAAAA,CAAwB,CACpC,MALqB,OAAOQ,EAAQ,OAAU,WAC5CA,EAAQ,MAAM,EACdA,EAAQ,MAIV,SAAW,GAAUA,EAAQ,WAAWC,CAAK,EAC7C,QAAS,CACP,cAAA,EAAgBR,EAAAA,KAAAA,CAAK,CACvB,CACF,CAAC,EAED,MAAO,CACL,UAAY,IACVS,EAAIH,EAAM,YAAY,CAAC,EAChBA,EAAM,cAAgBG,EAAIH,EAAM,YAAY,CAAC,CAAC,GAEvD,YAAaA,EAAM,YACnB,SAAUA,EAAM,SAChB,MAAOA,EAAM,MACb,QAASA,EAAM,OACjB,CACF,CAMA,SAAgBI,EAAqB,EAAgE,CACnG,IAAMC,EAAoC,CAAC,EAC3C,IAAK,IAAMC,KAAOT,EAChB,EAAUS,GAAQC,EAAOD,GAE3B,OAAOD,CACT,CASA,SAAgBG,EAAgC,EAAmC,CACjF,IAAMC,EAAmC,CAAC,EAC1C,IAAK,GAAM,CAAEH,EAAKJ,KAAW,OAAO,QAAQK,CAAK,EAC/C,EAAST,EAAoBQ,IAASA,GAAQJ,EAEhD,OAAOO,CACT,C"}
@@ -0,0 +1,4 @@
1
+ export type { HeadlessComboboxComboboxInputProps, HeadlessComboboxErrorCode, HeadlessComboboxInputProps, HeadlessComboboxListboxProps, HeadlessComboboxOptionProps, HeadlessComboboxPopupStyle, HeadlessComboboxSnapshot, HeadlessComboboxTriggerProps, } from '../../headless-combobox-core/src/index.ts';
2
+ export type { CreateSvelteComboboxOptions, SvelteComboboxStore } from './store';
3
+ export { createComboboxStore, toCoreProps, toSvelteProps } from './store';
4
+ //# 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,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EAAE,2BAA2B,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEhF,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
package/dist/index.mjs ADDED
@@ -0,0 +1,58 @@
1
+ import { createCombobox as e } from "@pdanpdan/headless-combobox-core";
2
+ import { tick as t } from "svelte";
3
+ // src/store.ts
4
+ var n = [
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
+ ], r = {
25
+ onClick: "onclick",
26
+ onKeydown: "onkeydown",
27
+ onMousedown: "onmousedown",
28
+ onMousemove: "onmousemove",
29
+ onFocus: "onfocus",
30
+ onInput: "oninput"
31
+ };
32
+ function i(n) {
33
+ let r = e({
34
+ props: typeof n.props == "function" ? n.props() : n.props,
35
+ onChange: (e) => n.onChange?.(e),
36
+ runtime: { nextTick: () => t() }
37
+ });
38
+ return {
39
+ subscribe: (e) => (e(r.getSnapshot()), r.subscribe(() => e(r.getSnapshot()))),
40
+ getSnapshot: r.getSnapshot,
41
+ setProps: r.setProps,
42
+ mount: r.mount,
43
+ destroy: r.destroy
44
+ };
45
+ }
46
+ function a(e) {
47
+ let t = {};
48
+ for (let r of n) t[r] = e[r];
49
+ return t;
50
+ }
51
+ function o(e) {
52
+ let t = {};
53
+ for (let [n, i] of Object.entries(e)) t[r[n] ?? n] = i;
54
+ return t;
55
+ }
56
+ export { i as createComboboxStore, a as toCoreProps, o as toSvelteProps };
57
+
58
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["CORE_PROP_KEYS","SVELTE_EVENT_NAMES","createComboboxStore","store","createCombobox","options","value","tick","run","toCoreProps","resolved","key","props","toSvelteProps","adapted"],"sources":["../src/store.ts"],"sourcesContent":["import type {\n HeadlessComboboxProps,\n HeadlessComboboxSnapshot,\n} from '@pdanpdan/headless-combobox-core';\n\nimport { createCombobox } from '@pdanpdan/headless-combobox-core';\nimport { tick } from 'svelte';\n\n/** Props read from a Svelte component; a fixed list keeps tracking deterministic. */\nconst CORE_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\nconst SVELTE_EVENT_NAMES: Record<string, string> = {\n onClick: 'onclick',\n onKeydown: 'onkeydown',\n onMousedown: 'onmousedown',\n onMousemove: 'onmousemove',\n onFocus: 'onfocus',\n onInput: 'oninput',\n};\n\nexport interface CreateSvelteComboboxOptions<O, V = O, Q = string> {\n /** A plain props object or a reactive getter. */\n props: HeadlessComboboxProps<O, V, Q> | (() => HeadlessComboboxProps<O, V, Q>);\n onChange?: (value: V | V[] | null) => void;\n}\n\n/** Svelte store (`$store` / `get(store)`) plus the adapter wiring. */\nexport interface SvelteComboboxStore<O, V, Q = string> {\n subscribe: (run: (value: HeadlessComboboxSnapshot<O, V, Q>) => void) => () => void;\n getSnapshot: () => HeadlessComboboxSnapshot<O, V, Q>;\n setProps: (props: HeadlessComboboxProps<O, V, Q>) => void;\n mount: () => void;\n destroy: () => void;\n}\n\n/**\n * Svelte adapter for the framework-independent combobox core.\n *\n * `$combobox` in a component gives the live snapshot (state + actions):\n *\n * ```svelte\n * <script>\n * const combobox = createComboboxStore({ props: () => ({ modelValue, options }) });\n * </script>\n * <button {...toSvelteProps($combobox.triggerProps)} />\n * ```\n */\nexport function createComboboxStore<O, V = O, Q = string>(\n options: CreateSvelteComboboxOptions<O, V, Q>,\n): SvelteComboboxStore<O, V, Q> {\n const resolve = () => (typeof options.props === 'function'\n ? options.props()\n : options.props);\n\n const store = createCombobox<O, V, Q>({\n props: resolve(),\n onChange: (value) => options.onChange?.(value),\n runtime: {\n nextTick: () => tick(),\n },\n });\n\n return {\n subscribe: (run) => {\n run(store.getSnapshot());\n return store.subscribe(() => run(store.getSnapshot()));\n },\n getSnapshot: store.getSnapshot,\n setProps: store.setProps,\n mount: store.mount,\n destroy: store.destroy,\n };\n}\n\n/**\n * Pick the combobox props out of a Svelte `$props()` object and drop component\n * plumbing (`children`, `onChange`). Reading inside an `$effect` tracks them.\n */\nexport function toCoreProps<O, V, Q>(props: Record<string, unknown>): HeadlessComboboxProps<O, V, Q> {\n const resolved: Record<string, unknown> = {};\n for (const key of CORE_PROP_KEYS) {\n resolved[ key ] = props[ key ];\n }\n return resolved as unknown as HeadlessComboboxProps<O, V, Q>;\n}\n\n/**\n * Adapt a core ARIA prop bag to Svelte 5 event attribute names:\n *\n * ```svelte\n * <button {...toSvelteProps(scope.triggerProps)} />\n * ```\n */\nexport function toSvelteProps<T extends object>(props: T): Record<string, unknown> {\n const adapted: Record<string, unknown> = {};\n for (const [ key, value ] of Object.entries(props)) {\n adapted[ SVELTE_EVENT_NAMES[ key ] ?? key ] = value;\n }\n return adapted;\n}\n"],"mappings":";;;AASA,IAAMA,IAAiB;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEMC,IAA6C;CACjD,SAAS;CACT,WAAW;CACX,aAAa;CACb,aAAa;CACb,SAAS;CACT,SAAS;AACX;AA6BA,SAAgBC,EACd,GAC8B;CAK9B,IAAMC,IAAQC,EAAwB;EACpC,OALqB,OAAOC,EAAQ,SAAU,aAC5CA,EAAQ,MAAM,IACdA,EAAQ;EAIV,WAAW,MAAUA,EAAQ,WAAWC,CAAK;EAC7C,SAAS,EACP,gBAAgBC,EAAK,EACvB;CACF,CAAC;CAED,OAAO;EACL,YAAY,OACVC,EAAIL,EAAM,YAAY,CAAC,GAChBA,EAAM,gBAAgBK,EAAIL,EAAM,YAAY,CAAC,CAAC;EAEvD,aAAaA,EAAM;EACnB,UAAUA,EAAM;EAChB,OAAOA,EAAM;EACb,SAASA,EAAM;CACjB;AACF;AAMA,SAAgBM,EAAqB,GAAgE;CACnG,IAAMC,IAAoC,CAAC;CAC3C,KAAK,IAAMC,KAAOX,GAChB,EAAUW,KAAQC,EAAOD;CAE3B,OAAOD;AACT;AASA,SAAgBG,EAAgC,GAAmC;CACjF,IAAMC,IAAmC,CAAC;CAC1C,KAAK,IAAM,CAAEH,GAAKL,MAAW,OAAO,QAAQM,CAAK,GAC/C,EAASX,EAAoBU,MAASA,KAAQL;CAEhD,OAAOQ;AACT"}
@@ -0,0 +1,41 @@
1
+ import { HeadlessComboboxProps, HeadlessComboboxSnapshot } from '../../headless-combobox-core/src/index.ts';
2
+ export interface CreateSvelteComboboxOptions<O, V = O, Q = string> {
3
+ /** A plain props object or a reactive getter. */
4
+ props: HeadlessComboboxProps<O, V, Q> | (() => HeadlessComboboxProps<O, V, Q>);
5
+ onChange?: (value: V | V[] | null) => void;
6
+ }
7
+ /** Svelte store (`$store` / `get(store)`) plus the adapter wiring. */
8
+ export interface SvelteComboboxStore<O, V, Q = string> {
9
+ subscribe: (run: (value: HeadlessComboboxSnapshot<O, V, Q>) => void) => () => void;
10
+ getSnapshot: () => HeadlessComboboxSnapshot<O, V, Q>;
11
+ setProps: (props: HeadlessComboboxProps<O, V, Q>) => void;
12
+ mount: () => void;
13
+ destroy: () => void;
14
+ }
15
+ /**
16
+ * Svelte adapter for the framework-independent combobox core.
17
+ *
18
+ * `$combobox` in a component gives the live snapshot (state + actions):
19
+ *
20
+ * ```svelte
21
+ * <script>
22
+ * const combobox = createComboboxStore({ props: () => ({ modelValue, options }) });
23
+ * </script>
24
+ * <button {...toSvelteProps($combobox.triggerProps)} />
25
+ * ```
26
+ */
27
+ export declare function createComboboxStore<O, V = O, Q = string>(options: CreateSvelteComboboxOptions<O, V, Q>): SvelteComboboxStore<O, V, Q>;
28
+ /**
29
+ * Pick the combobox props out of a Svelte `$props()` object and drop component
30
+ * plumbing (`children`, `onChange`). Reading inside an `$effect` tracks them.
31
+ */
32
+ export declare function toCoreProps<O, V, Q>(props: Record<string, unknown>): HeadlessComboboxProps<O, V, Q>;
33
+ /**
34
+ * Adapt a core ARIA prop bag to Svelte 5 event attribute names:
35
+ *
36
+ * ```svelte
37
+ * <button {...toSvelteProps(scope.triggerProps)} />
38
+ * ```
39
+ */
40
+ export declare function toSvelteProps<T extends object>(props: T): Record<string, unknown>;
41
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,wBAAwB,EACzB,MAAM,kCAAkC,CAAC;AAqC1C,MAAM,WAAW,2BAA2B,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM;IAC/D,iDAAiD;IACjD,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,MAAM,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC/E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC;CAC5C;AAED,sEAAsE;AACtE,MAAM,WAAW,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM;IACnD,SAAS,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,EAAE,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;IACnF,WAAW,EAAE,MAAM,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACrD,QAAQ,EAAE,CAAC,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC;IAC1D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EACtD,OAAO,EAAE,2BAA2B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAC5C,mBAAmB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAuB9B;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,qBAAqB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAMnG;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAMjF"}
package/package.json CHANGED
@@ -1,6 +1,77 @@
1
1
  {
2
2
  "name": "@pdanpdan/headless-combobox-svelte",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "type": "module",
4
+ "version": "3.0.0",
5
+ "description": "Accessible renderless combobox for Svelte, built on the framework-independent core",
6
+ "author": "Dan Popescu",
7
+ "license": "MIT",
8
+ "homepage": "https://pdanpdan.github.io/headless-components",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/pdanpdan/headless-components.git",
12
+ "directory": "packages/headless-combobox-svelte"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/pdanpdan/headless-components/issues"
16
+ },
17
+ "keywords": [
18
+ "svelte",
19
+ "combobox",
20
+ "headless",
21
+ "renderless",
22
+ "select",
23
+ "autocomplete",
24
+ "accessibility",
25
+ "typescript"
26
+ ],
27
+ "sideEffects": false,
28
+ "exports": {
29
+ ".": {
30
+ "types": "./dist/index.d.ts",
31
+ "import": "./dist/index.mjs",
32
+ "require": "./dist/index.cjs"
33
+ },
34
+ "./HeadlessCombobox.svelte": "./src/HeadlessCombobox.svelte",
35
+ "./source": {
36
+ "types": "./src/index.ts",
37
+ "import": "./src/index.ts"
38
+ }
39
+ },
40
+ "main": "./dist/index.cjs",
41
+ "module": "./dist/index.mjs",
42
+ "types": "./dist/index.d.ts",
43
+ "files": [
44
+ "dist",
45
+ "src"
46
+ ],
47
+ "peerDependencies": {
48
+ "svelte": ">=5.0.0"
49
+ },
50
+ "dependencies": {
51
+ "@pdanpdan/headless-combobox-core": "3.0.0"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public",
55
+ "registry": "https://registry.npmjs.org/"
56
+ },
57
+ "devDependencies": {
58
+ "@sveltejs/vite-plugin-svelte": "^7.3.1",
59
+ "@vitest/coverage-v8": "^5.1.1",
60
+ "jsdom": "^31.0.1",
61
+ "svelte": "^5.59.1",
62
+ "typescript": "^6.0.3",
63
+ "vite": "^8.3.8",
64
+ "vite-plugin-dts": "^5.1.2",
65
+ "vitest": "^5.1.1"
66
+ },
67
+ "scripts": {
68
+ "build": "vite build",
69
+ "lint": "pnpm --dir ../.. lint",
70
+ "test": "vitest run",
71
+ "test:watch": "vitest",
72
+ "test:coverage": "vitest run --coverage",
73
+ "typecheck": "tsc -p tsconfig.app.json --noEmit && tsc -p tsconfig.vitest.json --noEmit",
74
+ "test:all": "pnpm lint && pnpm typecheck && pnpm test",
75
+ "release:npm": "pnpm publish"
76
+ }
6
77
  }
@@ -0,0 +1,33 @@
1
+ <script lang="ts">
2
+ import type { HeadlessComboboxSnapshot } from '@pdanpdan/headless-combobox-core';
3
+ import type { Snippet } from 'svelte';
4
+ import { onDestroy, onMount } from 'svelte';
5
+
6
+ import { createComboboxStore, toCoreProps } from './store';
7
+
8
+ let props: {
9
+ children: Snippet<[HeadlessComboboxSnapshot<unknown, unknown, string>]>;
10
+ onChange?: (value: unknown) => void;
11
+ [key: string]: unknown;
12
+ } = $props();
13
+
14
+ const store = createComboboxStore<unknown, unknown, string>({
15
+ props: () => toCoreProps(props),
16
+ onChange: (value) => props.onChange?.(value),
17
+ });
18
+
19
+ let snapshot = $state(store.getSnapshot());
20
+
21
+ $effect(() => store.subscribe((value) => {
22
+ snapshot = value;
23
+ }));
24
+
25
+ $effect(() => {
26
+ store.setProps(toCoreProps(props));
27
+ });
28
+
29
+ onMount(() => store.mount());
30
+ onDestroy(() => store.destroy());
31
+ </script>
32
+
33
+ {@render props.children(snapshot)}
package/src/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ export type {
2
+ HeadlessComboboxComboboxInputProps,
3
+ HeadlessComboboxErrorCode,
4
+ HeadlessComboboxInputProps,
5
+ HeadlessComboboxListboxProps,
6
+ HeadlessComboboxOptionProps,
7
+ HeadlessComboboxPopupStyle,
8
+ HeadlessComboboxSnapshot,
9
+ HeadlessComboboxTriggerProps,
10
+ } from '@pdanpdan/headless-combobox-core';
11
+ export type { CreateSvelteComboboxOptions, SvelteComboboxStore } from './store';
12
+
13
+ export { createComboboxStore, toCoreProps, toSvelteProps } from './store';
package/src/store.ts ADDED
@@ -0,0 +1,120 @@
1
+ import type {
2
+ HeadlessComboboxProps,
3
+ HeadlessComboboxSnapshot,
4
+ } from '@pdanpdan/headless-combobox-core';
5
+
6
+ import { createCombobox } from '@pdanpdan/headless-combobox-core';
7
+ import { tick } from 'svelte';
8
+
9
+ /** Props read from a Svelte component; a fixed list keeps tracking deterministic. */
10
+ const CORE_PROP_KEYS = [
11
+ 'modelValue',
12
+ 'options',
13
+ 'multiple',
14
+ 'minLength',
15
+ 'maxLength',
16
+ 'required',
17
+ 'disabled',
18
+ 'readonly',
19
+ 'closeOnSelect',
20
+ 'closeOnClickOutside',
21
+ 'clickOutsideFilter',
22
+ 'selectOnTab',
23
+ 'optionValue',
24
+ 'optionLabel',
25
+ 'optionFilter',
26
+ 'id',
27
+ 'alignSelected',
28
+ 'inputOnOpen',
29
+ 'errorMessages',
30
+ ] as const;
31
+
32
+ const SVELTE_EVENT_NAMES: Record<string, string> = {
33
+ onClick: 'onclick',
34
+ onKeydown: 'onkeydown',
35
+ onMousedown: 'onmousedown',
36
+ onMousemove: 'onmousemove',
37
+ onFocus: 'onfocus',
38
+ onInput: 'oninput',
39
+ };
40
+
41
+ export interface CreateSvelteComboboxOptions<O, V = O, Q = string> {
42
+ /** A plain props object or a reactive getter. */
43
+ props: HeadlessComboboxProps<O, V, Q> | (() => HeadlessComboboxProps<O, V, Q>);
44
+ onChange?: (value: V | V[] | null) => void;
45
+ }
46
+
47
+ /** Svelte store (`$store` / `get(store)`) plus the adapter wiring. */
48
+ export interface SvelteComboboxStore<O, V, Q = string> {
49
+ subscribe: (run: (value: HeadlessComboboxSnapshot<O, V, Q>) => void) => () => void;
50
+ getSnapshot: () => HeadlessComboboxSnapshot<O, V, Q>;
51
+ setProps: (props: HeadlessComboboxProps<O, V, Q>) => void;
52
+ mount: () => void;
53
+ destroy: () => void;
54
+ }
55
+
56
+ /**
57
+ * Svelte adapter for the framework-independent combobox core.
58
+ *
59
+ * `$combobox` in a component gives the live snapshot (state + actions):
60
+ *
61
+ * ```svelte
62
+ * <script>
63
+ * const combobox = createComboboxStore({ props: () => ({ modelValue, options }) });
64
+ * </script>
65
+ * <button {...toSvelteProps($combobox.triggerProps)} />
66
+ * ```
67
+ */
68
+ export function createComboboxStore<O, V = O, Q = string>(
69
+ options: CreateSvelteComboboxOptions<O, V, Q>,
70
+ ): SvelteComboboxStore<O, V, Q> {
71
+ const resolve = () => (typeof options.props === 'function'
72
+ ? options.props()
73
+ : options.props);
74
+
75
+ const store = createCombobox<O, V, Q>({
76
+ props: resolve(),
77
+ onChange: (value) => options.onChange?.(value),
78
+ runtime: {
79
+ nextTick: () => tick(),
80
+ },
81
+ });
82
+
83
+ return {
84
+ subscribe: (run) => {
85
+ run(store.getSnapshot());
86
+ return store.subscribe(() => run(store.getSnapshot()));
87
+ },
88
+ getSnapshot: store.getSnapshot,
89
+ setProps: store.setProps,
90
+ mount: store.mount,
91
+ destroy: store.destroy,
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Pick the combobox props out of a Svelte `$props()` object and drop component
97
+ * plumbing (`children`, `onChange`). Reading inside an `$effect` tracks them.
98
+ */
99
+ export function toCoreProps<O, V, Q>(props: Record<string, unknown>): HeadlessComboboxProps<O, V, Q> {
100
+ const resolved: Record<string, unknown> = {};
101
+ for (const key of CORE_PROP_KEYS) {
102
+ resolved[ key ] = props[ key ];
103
+ }
104
+ return resolved as unknown as HeadlessComboboxProps<O, V, Q>;
105
+ }
106
+
107
+ /**
108
+ * Adapt a core ARIA prop bag to Svelte 5 event attribute names:
109
+ *
110
+ * ```svelte
111
+ * <button {...toSvelteProps(scope.triggerProps)} />
112
+ * ```
113
+ */
114
+ export function toSvelteProps<T extends object>(props: T): Record<string, unknown> {
115
+ const adapted: Record<string, unknown> = {};
116
+ for (const [ key, value ] of Object.entries(props)) {
117
+ adapted[ SVELTE_EVENT_NAMES[ key ] ?? key ] = value;
118
+ }
119
+ return adapted;
120
+ }