@molecule/app-search-autocomplete-vue 0.0.0-stage → 1.1.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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,235 @@
1
- # Temporary Holding Version
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-21T12:47:13.298Z
7
+ -->
2
8
 
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.
9
+ # @molecule/app-search-autocomplete-vue
10
+
11
+ Search input with a typeahead suggestion popover.
12
+
13
+ Exports `<SearchAutocomplete>` and the `SuggestionItem<T>` type
14
+ (`{ id, label, meta?, data? }`). Two data modes — pass ONE of:
15
+ `onSearch(query)` (async fetch, debounced; default 200 ms) or
16
+ `suggestions` (caller-controlled list). Other props: `value` / `onChange`
17
+ (controlled input), `onSelect(item)`, `placeholder?` (defaults to the
18
+ translated `search.placeholder`), `debounceMs?`, `minChars?` (default 1),
19
+ `className?`.
20
+
21
+ Vue counterpart of `@molecule/app-search-autocomplete-react`: the same
22
+ exports, the same props (React names), the same ClassMap tokens and the same
23
+ DOM for the same input.
24
+
25
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
26
+ > It is written to be read by coding agents as much as by people, and is generated from this
27
+ > package's source — edit `src/index.ts` JSDoc, not this file.
28
+
29
+ ## Quick Start
30
+
31
+ ```ts
32
+ import { createApp, defineComponent, h, ref } from 'vue'
33
+ import { moleculePlugin } from '@molecule/app-vue'
34
+ import { SearchAutocomplete } from '@molecule/app-search-autocomplete-vue'
35
+ import type { SuggestionItem } from '@molecule/app-search-autocomplete-vue'
36
+
37
+ const UserSearch = defineComponent({
38
+ setup() {
39
+ const query = ref('')
40
+ const fetchUsers = (q: string): Promise<SuggestionItem<{ id: string }>[]> =>
41
+ fetch(`/api/users?q=${encodeURIComponent(q)}`).then((r) => r.json())
42
+
43
+ return () =>
44
+ h(SearchAutocomplete, {
45
+ value: query.value,
46
+ onChange: (next: string) => {
47
+ query.value = next
48
+ },
49
+ onSearch: fetchUsers,
50
+ onSelect: (item) => console.log(item.data?.id),
51
+ placeholder: 'Search users…',
52
+ })
53
+ },
54
+ })
55
+
56
+ const app = createApp(UserSearch)
57
+ app.use(moleculePlugin, { i18n: i18nProvider })
58
+ app.mount('#app')
59
+ ```
60
+
61
+ ## Type
62
+
63
+ `feature`
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ npm install @molecule/app-search-autocomplete-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
69
+ ```
70
+
71
+ ## API
72
+
73
+ ### Interfaces
74
+
75
+ #### `SuggestionItem`
76
+
77
+ A single suggestion entry returned by `onSearch` or passed via `suggestions`.
78
+
79
+ ```typescript
80
+ interface SuggestionItem<T = unknown> {
81
+ id: string
82
+ label: VNodeChild
83
+ /** Optional secondary line / category. */
84
+ meta?: VNodeChild
85
+ /** Original payload for the selection callback. */
86
+ data?: T
87
+ }
88
+ ```
89
+
90
+ #### `SearchAutocompleteProps`
91
+
92
+ Props accepted by the {@link SearchAutocomplete} component.
93
+
94
+ ```typescript
95
+ interface SearchAutocompleteProps<T = unknown> {
96
+ /** Current input value. */
97
+ value: string
98
+ /** Called whenever the input changes. */
99
+ onChange: (value: string) => void
100
+ /** Async search function — receives the query, returns suggestions. */
101
+ onSearch?: (query: string) => Promise<SuggestionItem<T>[]> | SuggestionItem<T>[]
102
+ /** Optional pre-computed suggestion list (when caller controls fetching). */
103
+ suggestions?: SuggestionItem<T>[]
104
+ /** Called when the user picks a suggestion. */
105
+ onSelect: (item: SuggestionItem<T>) => void
106
+ /** Placeholder. */
107
+ placeholder?: string
108
+ /**
109
+ * Accessible name for the input, rendered as `aria-label`. Defaults to the
110
+ * translated `search.aria.label`: a placeholder is not a label, so an input
111
+ * named only by its placeholder (let alone an empty one) is nameless for
112
+ * assistive technology.
113
+ */
114
+ ariaLabel?: string
115
+ /** Debounce ms for `onSearch`. Defaults to 200. */
116
+ debounceMs?: number
117
+ /** Min chars before suggestions appear. Defaults to 1. */
118
+ minChars?: number
119
+ /** Extra classes on the wrapper. */
120
+ className?: string
121
+ }
122
+ ```
123
+
124
+ ### Constants
125
+
126
+ #### `SearchAutocomplete`
127
+
128
+ Search input with a typeahead suggestions popover. Pass either
129
+ `onSearch` (async fetch with debounce) or `suggestions` (controlled).
130
+
131
+ Vue counterpart of `@molecule/app-search-autocomplete-react`'s
132
+ `SearchAutocomplete` — the same props (React names), the same ClassMap
133
+ tokens, the same DOM for the same input, and the same callback calls.
134
+
135
+ ```typescript
136
+ const SearchAutocomplete: DefineComponent<
137
+ ExtractPropTypes<{
138
+ value: { type: StringConstructor; required: true }
139
+ onChange: { type: PropType<(value: string) => void>; default: undefined }
140
+ onSearch: {
141
+ type: PropType<(query: string) => Promise<SuggestionItem[]> | SuggestionItem[]>
142
+ default: undefined
143
+ }
144
+ suggestions: { type: PropType<SuggestionInput[]>; default: undefined }
145
+ onSelect: { type: PropType<(item: SuggestionItem<unknown>) => void>; default: undefined }
146
+ placeholder: StringConstructor
147
+ ariaLabel: StringConstructor
148
+ debounceMs: { type: NumberConstructor; default: number }
149
+ minChars: { type: NumberConstructor; default: number }
150
+ className: StringConstructor
151
+ }>,
152
+ () => VNode,
153
+ {},
154
+ {},
155
+ {},
156
+ ComponentOptionsMixin,
157
+ ComponentOptionsMixin,
158
+ {},
159
+ string,
160
+ PublicProps,
161
+ Readonly<
162
+ ExtractPropTypes<{
163
+ value: { type: StringConstructor; required: true }
164
+ onChange: { type: PropType<(value: string) => void>; default: undefined }
165
+ onSearch: {
166
+ type: PropType<(query: string) => Promise<SuggestionItem[]> | SuggestionItem[]>
167
+ default: undefined
168
+ }
169
+ suggestions: { type: PropType<SuggestionInput[]>; default: undefined }
170
+ onSelect: { type: PropType<(item: SuggestionItem<unknown>) => void>; default: undefined }
171
+ placeholder: StringConstructor
172
+ ariaLabel: StringConstructor
173
+ debounceMs: { type: NumberConstructor; default: number }
174
+ minChars: { type: NumberConstructor; default: number }
175
+ className: StringConstructor
176
+ }>
177
+ > &
178
+ Readonly<{}>,
179
+ {
180
+ onChange: (value: string) => void
181
+ onSearch: (query: string) => Promise<SuggestionItem[]> | SuggestionItem[]
182
+ suggestions: SuggestionInput[]
183
+ onSelect: (item: SuggestionItem<unknown>) => void
184
+ debounceMs: number
185
+ minChars: number
186
+ },
187
+ {},
188
+ {},
189
+ {},
190
+ string,
191
+ ComponentProvideOptions,
192
+ true,
193
+ {},
194
+ any
195
+ >
196
+ ```
197
+
198
+ - `props` — Component props (see {@link SearchAutocompleteProps}).
199
+
200
+ **Returns:** The search-autocomplete component.
201
+
202
+ ## Injection Notes
203
+
204
+ ### Requirements
205
+
206
+ Peer dependencies:
207
+
208
+ - `@molecule/app-ui` ^1.0.1
209
+ - `@molecule/app-ui-vue` ^1.1.0
210
+ - `@molecule/app-vue` ^3.5.0
211
+ - `vue` ^3.4.0
212
+
213
+ ### Runtime Dependencies
214
+
215
+ - `@molecule/app-ui`
216
+ - `@molecule/app-ui-vue`
217
+ - `@molecule/app-vue`
218
+ - `vue`
219
+
220
+ - Throws unless mounted under `moleculePlugin` (from `@molecule/app-vue`)
221
+ with a bonded ClassMap.
222
+ - Full keyboard support: it's an ARIA combobox — ArrowDown/ArrowUp move the
223
+ highlight (opening the popover), Enter selects the highlighted option, and
224
+ Escape closes. `aria-activedescendant` tracks the active `role="option"`.
225
+ - Stale-response safe: out-of-order `onSearch` responses are dropped (each
226
+ request carries a token; only the latest applies), so a slow earlier fetch
227
+ can't overwrite fresher results. `onSearch` needs no cancellation of its own.
228
+ - The popover surface uses `var(--color-surface)` with a WHITE fallback
229
+ and black-alpha borders — define `--color-surface` (dark themes) or the
230
+ dropdown stays light.
231
+ - Default placeholder translations: `@molecule/app-locales-search-autocomplete`.
232
+
233
+ ## Translations
234
+
235
+ Translation strings are provided by `@molecule/app-locales-search-autocomplete`.
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Vue search input with a typeahead suggestion popover.
3
+ *
4
+ * @module
5
+ */
6
+ import { type PropType, type VNode } from 'vue';
7
+ import type { SuggestionItem } from './types.js';
8
+ /**
9
+ * A suggestion as it arrives in props: node-valued fields are whatever the
10
+ * caller (or the conformance node builder) put there, narrowed at render time.
11
+ */
12
+ interface SuggestionInput {
13
+ id: string;
14
+ label: unknown;
15
+ meta?: unknown;
16
+ data?: unknown;
17
+ }
18
+ /**
19
+ * Search input with a typeahead suggestions popover. Pass either
20
+ * `onSearch` (async fetch with debounce) or `suggestions` (controlled).
21
+ *
22
+ * Vue counterpart of `@molecule/app-search-autocomplete-react`'s
23
+ * `SearchAutocomplete` — the same props (React names), the same ClassMap
24
+ * tokens, the same DOM for the same input, and the same callback calls.
25
+ *
26
+ * @param props - Component props (see {@link SearchAutocompleteProps}).
27
+ * @returns The search-autocomplete component.
28
+ */
29
+ export declare const SearchAutocomplete: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
30
+ value: {
31
+ type: StringConstructor;
32
+ required: true;
33
+ };
34
+ onChange: {
35
+ type: PropType<(value: string) => void>;
36
+ default: undefined;
37
+ };
38
+ onSearch: {
39
+ type: PropType<(query: string) => Promise<SuggestionItem[]> | SuggestionItem[]>;
40
+ default: undefined;
41
+ };
42
+ suggestions: {
43
+ type: PropType<SuggestionInput[]>;
44
+ default: undefined;
45
+ };
46
+ onSelect: {
47
+ type: PropType<(item: SuggestionItem<unknown>) => void>;
48
+ default: undefined;
49
+ };
50
+ placeholder: StringConstructor;
51
+ ariaLabel: StringConstructor;
52
+ debounceMs: {
53
+ type: NumberConstructor;
54
+ default: number;
55
+ };
56
+ minChars: {
57
+ type: NumberConstructor;
58
+ default: number;
59
+ };
60
+ className: StringConstructor;
61
+ }>, () => VNode, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
62
+ value: {
63
+ type: StringConstructor;
64
+ required: true;
65
+ };
66
+ onChange: {
67
+ type: PropType<(value: string) => void>;
68
+ default: undefined;
69
+ };
70
+ onSearch: {
71
+ type: PropType<(query: string) => Promise<SuggestionItem[]> | SuggestionItem[]>;
72
+ default: undefined;
73
+ };
74
+ suggestions: {
75
+ type: PropType<SuggestionInput[]>;
76
+ default: undefined;
77
+ };
78
+ onSelect: {
79
+ type: PropType<(item: SuggestionItem<unknown>) => void>;
80
+ default: undefined;
81
+ };
82
+ placeholder: StringConstructor;
83
+ ariaLabel: StringConstructor;
84
+ debounceMs: {
85
+ type: NumberConstructor;
86
+ default: number;
87
+ };
88
+ minChars: {
89
+ type: NumberConstructor;
90
+ default: number;
91
+ };
92
+ className: StringConstructor;
93
+ }>> & Readonly<{}>, {
94
+ onChange: (value: string) => void;
95
+ onSearch: (query: string) => Promise<SuggestionItem[]> | SuggestionItem[];
96
+ suggestions: SuggestionInput[];
97
+ onSelect: (item: SuggestionItem<unknown>) => void;
98
+ debounceMs: number;
99
+ minChars: number;
100
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
101
+ export {};
102
+ //# sourceMappingURL=SearchAutocomplete.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchAutocomplete.d.ts","sourceRoot":"","sources":["../src/SearchAutocomplete.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAGL,KAAK,QAAQ,EAGb,KAAK,KAAK,EAGX,MAAM,KAAK,CAAA;AAMZ,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhD;;;GAGG;AACH,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAkBD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB;;;;;;cAWP,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;;;;cAIjC,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC;;;;cAI5E,QAAQ,CAAC,eAAe,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;;;;;;;;;;;;;;UA6J1D,KAAK;;;;;;cAzKI,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;;;;cAIjC,QAAQ,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,GAAG,cAAc,EAAE,CAAC;;;;cAI5E,QAAQ,CAAC,eAAe,EAAE,CAAC;;;;cAIxB,QAAQ,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;;;;;;;;;;;;;;;sBAZhC,MAAM,KAAK,IAAI;sBAIf,MAAM,KAAK,OAAO,CAAC,cAAc,EAAE,CAAC,GAAG,cAAc,EAAE;;qBAQxD,cAAc,CAAC,OAAO,CAAC,KAAK,IAAI;;;4EAkQtE,CAAA"}
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Vue search input with a typeahead suggestion popover.
3
+ *
4
+ * @module
5
+ */
6
+ import { defineComponent, h, ref, shallowRef, watch, } from 'vue';
7
+ import { getClassMap } from '@molecule/app-ui';
8
+ import { Input } from '@molecule/app-ui-vue';
9
+ import { useTranslation } from '@molecule/app-vue';
10
+ /** Counter backing the per-instance ids (React's `useId()`). */
11
+ let nextGeneratedId = 0;
12
+ /**
13
+ * The children a node value contributes: an array stays a list of siblings, a
14
+ * single node is one child, and an absent value contributes nothing — the way
15
+ * React renders `{node}`.
16
+ *
17
+ * @param value - A node value.
18
+ * @returns The child nodes.
19
+ */
20
+ const childrenOf = (value) => {
21
+ if (value === null || value === undefined || value === false)
22
+ return [];
23
+ return Array.isArray(value) ? value : [value];
24
+ };
25
+ /**
26
+ * Search input with a typeahead suggestions popover. Pass either
27
+ * `onSearch` (async fetch with debounce) or `suggestions` (controlled).
28
+ *
29
+ * Vue counterpart of `@molecule/app-search-autocomplete-react`'s
30
+ * `SearchAutocomplete` — the same props (React names), the same ClassMap
31
+ * tokens, the same DOM for the same input, and the same callback calls.
32
+ *
33
+ * @param props - Component props (see {@link SearchAutocompleteProps}).
34
+ * @returns The search-autocomplete component.
35
+ */
36
+ export const SearchAutocomplete = defineComponent({
37
+ name: 'SearchAutocomplete',
38
+ // As in React (which never spreads unknown props onto an element): a prop
39
+ // this component does not declare must not leak onto the wrapper.
40
+ inheritAttrs: false,
41
+ props: {
42
+ value: {
43
+ type: String,
44
+ required: true,
45
+ },
46
+ onChange: {
47
+ type: Function,
48
+ default: undefined,
49
+ },
50
+ onSearch: {
51
+ type: Function,
52
+ default: undefined,
53
+ },
54
+ suggestions: {
55
+ type: Array,
56
+ default: undefined,
57
+ },
58
+ onSelect: {
59
+ type: Function,
60
+ default: undefined,
61
+ },
62
+ placeholder: String,
63
+ ariaLabel: String,
64
+ debounceMs: {
65
+ type: Number,
66
+ default: 200,
67
+ },
68
+ minChars: {
69
+ type: Number,
70
+ default: 1,
71
+ },
72
+ className: String,
73
+ },
74
+ setup(props) {
75
+ const cm = getClassMap();
76
+ const { t } = useTranslation();
77
+ const internal = shallowRef([]);
78
+ const open = ref(false);
79
+ const activeIndex = ref(-1);
80
+ const wrapper = ref(null);
81
+ // Monotonic id of the latest in-flight `onSearch`. A response only applies
82
+ // if its token still equals the latest — the stale-response race guard.
83
+ let request = 0;
84
+ const baseId = `mol-search-autocomplete-${nextGeneratedId++}`;
85
+ const listId = `${baseId}-listbox`;
86
+ /**
87
+ * Stable DOM id for the option at `index` (referenced by aria-activedescendant).
88
+ * @param index - Option position.
89
+ * @returns The option id.
90
+ */
91
+ const optionId = (index) => `${baseId}-option-${index}`;
92
+ /** The suggestion list: the caller's controlled list wins over fetched results. */
93
+ const list = () => props.suggestions ?? internal.value;
94
+ /** The popover is only visible with open + at least one suggestion. */
95
+ const isExpanded = () => open.value && list().length > 0;
96
+ /**
97
+ * The highlight clamped to the current list: a list that shrinks below the
98
+ * highlighted index leaves the old option id pointing at nothing, so every
99
+ * read of the index (activedescendant, the highlighted option, Enter) sees
100
+ * -1 — nothing highlighted — instead of naming an option that is gone.
101
+ *
102
+ * @returns The active index, or -1 when nothing is highlighted.
103
+ */
104
+ const active = () => {
105
+ const index = activeIndex.value;
106
+ return index < list().length ? index : -1;
107
+ };
108
+ // React's debounced `onSearch` effect: a new value/search/debounce/minChars
109
+ // restarts the timer; a query shorter than minChars clears the results.
110
+ watch(() => [props.value, props.onSearch, props.debounceMs, props.minChars], ([value, onSearch, debounceMs, minChars], _previous, onCleanup) => {
111
+ if (!onSearch || value.length < minChars) {
112
+ internal.value = [];
113
+ return;
114
+ }
115
+ const timer = setTimeout(() => {
116
+ const token = ++request;
117
+ Promise.resolve(onSearch(value))
118
+ .then((result) => {
119
+ // Drop a response that lost the race: only the LATEST request may
120
+ // apply, so a slow earlier fetch can't clobber fresher results.
121
+ if (token === request)
122
+ internal.value = result;
123
+ })
124
+ .catch((_error) => {
125
+ // Typeahead is best-effort — a failed suggestion fetch simply
126
+ // yields no suggestions for THIS query. Guard on the token so an
127
+ // out-of-order failure can't wipe a fresher successful result.
128
+ if (token === request)
129
+ internal.value = [];
130
+ });
131
+ }, debounceMs);
132
+ onCleanup(() => clearTimeout(timer));
133
+ }, { immediate: true });
134
+ // A new query resets the keyboard highlight (works for both the internal
135
+ // and the controlled `suggestions` data modes).
136
+ watch(() => props.value, () => {
137
+ activeIndex.value = -1;
138
+ });
139
+ // React's outside-mousedown effect: the listener exists only while open.
140
+ watch(open, (isOpen, _previous, onCleanup) => {
141
+ if (!isOpen)
142
+ return;
143
+ /**
144
+ * Closes the dropdown when a click occurs outside the wrapper element.
145
+ * @param event - The document mousedown.
146
+ */
147
+ const onDoc = (event) => {
148
+ if (!wrapper.value?.contains(event.target)) {
149
+ open.value = false;
150
+ activeIndex.value = -1;
151
+ }
152
+ };
153
+ document.addEventListener('mousedown', onDoc);
154
+ onCleanup(() => document.removeEventListener('mousedown', onDoc));
155
+ });
156
+ /**
157
+ * Commits a suggestion selection and closes the popover.
158
+ * @param item - The chosen suggestion.
159
+ */
160
+ function select(item) {
161
+ props.onSelect?.(item);
162
+ open.value = false;
163
+ activeIndex.value = -1;
164
+ }
165
+ /**
166
+ * Full keyboard support for the combobox: ArrowDown/ArrowUp move the
167
+ * highlight (opening the popover if needed), Enter selects the highlighted
168
+ * option, Escape closes.
169
+ * @param event - The keyboard event from the input.
170
+ */
171
+ function onKeyDown(event) {
172
+ const current = list();
173
+ if (event.key === 'ArrowDown') {
174
+ event.preventDefault();
175
+ if (!open.value) {
176
+ if (current.length > 0)
177
+ open.value = true;
178
+ return;
179
+ }
180
+ if (current.length === 0)
181
+ return;
182
+ activeIndex.value = (activeIndex.value + 1) % current.length;
183
+ }
184
+ else if (event.key === 'ArrowUp') {
185
+ event.preventDefault();
186
+ if (!open.value) {
187
+ if (current.length > 0)
188
+ open.value = true;
189
+ return;
190
+ }
191
+ if (current.length === 0)
192
+ return;
193
+ activeIndex.value = activeIndex.value <= 0 ? current.length - 1 : activeIndex.value - 1;
194
+ }
195
+ else if (event.key === 'Enter') {
196
+ if (isExpanded() && active() >= 0) {
197
+ event.preventDefault();
198
+ select(current[active()]);
199
+ }
200
+ }
201
+ else if (event.key === 'Escape') {
202
+ if (open.value) {
203
+ event.preventDefault();
204
+ open.value = false;
205
+ activeIndex.value = -1;
206
+ }
207
+ }
208
+ }
209
+ return () => {
210
+ const current = list();
211
+ const expanded = isExpanded();
212
+ return h('div', {
213
+ ref: wrapper,
214
+ class: cm.cn(cm.position('relative'), props.className),
215
+ }, [
216
+ h(Input, {
217
+ type: 'search',
218
+ value: props.value,
219
+ onChange: (event) => {
220
+ props.onChange?.(event.target.value);
221
+ open.value = true;
222
+ },
223
+ onFocus: () => {
224
+ if (props.value.length >= props.minChars)
225
+ open.value = true;
226
+ },
227
+ onKeyDown: onKeyDown,
228
+ placeholder: props.placeholder ?? t('search.placeholder', {}, { defaultValue: 'Search…' }),
229
+ role: 'combobox',
230
+ 'aria-label': props.ariaLabel ?? t('search.aria.label', undefined, { defaultValue: 'Search' }),
231
+ 'aria-autocomplete': 'list',
232
+ 'aria-expanded': expanded ? 'true' : 'false',
233
+ 'aria-controls': listId,
234
+ 'aria-activedescendant': expanded && active() >= 0 ? optionId(active()) : undefined,
235
+ }),
236
+ expanded
237
+ ? h('ul', {
238
+ role: 'listbox',
239
+ id: listId,
240
+ class: cm.cn(cm.stack(0), cm.sp('p', 1)),
241
+ style: {
242
+ position: 'absolute',
243
+ top: '100%',
244
+ left: '0',
245
+ right: '0',
246
+ zIndex: '50',
247
+ background: 'var(--color-surface, #fff)',
248
+ border: '1px solid rgba(0,0,0,0.1)',
249
+ borderRadius: '8px',
250
+ boxShadow: '0 8px 24px rgba(0,0,0,0.12)',
251
+ maxHeight: '320px',
252
+ overflowY: 'auto',
253
+ },
254
+ }, current.map((suggestion, index) => h('li', {
255
+ key: suggestion.id,
256
+ id: optionId(index),
257
+ role: 'option',
258
+ 'aria-selected': index === active() ? 'true' : 'false',
259
+ tabindex: -1,
260
+ 'data-mol-id': 'search-autocomplete-option',
261
+ onMouseenter: () => {
262
+ activeIndex.value = index;
263
+ },
264
+ // Pointer selection happens on press: preventDefault keeps
265
+ // DOM focus on the input, which owns the combobox.
266
+ onMousedown: (event) => {
267
+ event.preventDefault();
268
+ select(suggestion);
269
+ },
270
+ class: cm.cn(cm.sp('px', 2), cm.sp('py', 2), cm.textSize('sm'), cm.cursorPointer, index === active() && cm.surfaceSecondary),
271
+ }, [
272
+ h('div', { class: cm.fontWeight('medium') }, childrenOf(suggestion.label)),
273
+ suggestion.meta
274
+ ? h('div', { class: cm.textSize('xs') }, childrenOf(suggestion.meta))
275
+ : null,
276
+ ])))
277
+ : null,
278
+ ]);
279
+ };
280
+ },
281
+ });
282
+ //# sourceMappingURL=SearchAutocomplete.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchAutocomplete.js","sourceRoot":"","sources":["../src/SearchAutocomplete.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,eAAe,EACf,CAAC,EAED,GAAG,EACH,UAAU,EAGV,KAAK,GACN,MAAM,KAAK,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAelD,gEAAgE;AAChE,IAAI,eAAe,GAAG,CAAC,CAAA;AAEvB;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,KAAiB,EAAgB,EAAE;IACrD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,KAAK;QAAE,OAAO,EAAE,CAAA;IACvE,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,eAAe,CAAC;IAChD,IAAI,EAAE,oBAAoB;IAC1B,0EAA0E;IAC1E,kEAAkE;IAClE,YAAY,EAAE,KAAK;IACnB,KAAK,EAAE;QACL,KAAK,EAAE;YACL,IAAI,EAAE,MAAM;YACZ,QAAQ,EAA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,GAAG,EAAE;4BACjB,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;wBAC3B,CAAC;wBACD,2DAA2D;wBAC3D,mDAAmD;wBACnD,WAAW,EAAE,CAAC,KAAiB,EAAE,EAAE;4BACjC,KAAK,CAAC,cAAc,EAAE,CAAA;4BACtB,MAAM,CAAC,UAAU,CAAC,CAAA;wBACpB,CAAC;wBACD,KAAK,EAAE,EAAE,CAAC,EAAE,CACV,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,EACd,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,EACd,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EACjB,EAAE,CAAC,aAAa,EAChB,KAAK,KAAK,MAAM,EAAE,IAAI,EAAE,CAAC,gBAAgB,CAC1C;qBACF,EACD;wBACE,CAAC,CACC,KAAK,EACL,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAClC,UAAU,CAAC,UAAU,CAAC,KAAmB,CAAC,CAC3C;wBACD,UAAU,CAAC,IAAI;4BACb,CAAC,CAAC,CAAC,CACC,KAAK,EACL,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,EAC5B,UAAU,CAAC,UAAU,CAAC,IAAkB,CAAC,CAC1C;4BACH,CAAC,CAAC,IAAI;qBACT,CACF,CACF,CACF;oBACH,CAAC,CAAC,IAAI;aACT,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Search input with a typeahead suggestion popover.
3
+ *
4
+ * Exports `<SearchAutocomplete>` and the `SuggestionItem<T>` type
5
+ * (`{ id, label, meta?, data? }`). Two data modes — pass ONE of:
6
+ * `onSearch(query)` (async fetch, debounced; default 200 ms) or
7
+ * `suggestions` (caller-controlled list). Other props: `value` / `onChange`
8
+ * (controlled input), `onSelect(item)`, `placeholder?` (defaults to the
9
+ * translated `search.placeholder`), `debounceMs?`, `minChars?` (default 1),
10
+ * `className?`.
11
+ *
12
+ * Vue counterpart of `@molecule/app-search-autocomplete-react`: the same
13
+ * exports, the same props (React names), the same ClassMap tokens and the same
14
+ * DOM for the same input.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createApp, defineComponent, h, ref } from 'vue'
19
+ * import { moleculePlugin } from '@molecule/app-vue'
20
+ * import { SearchAutocomplete } from '@molecule/app-search-autocomplete-vue'
21
+ * import type { SuggestionItem } from '@molecule/app-search-autocomplete-vue'
22
+ *
23
+ * const UserSearch = defineComponent({
24
+ * setup() {
25
+ * const query = ref('')
26
+ * const fetchUsers = (q: string): Promise<SuggestionItem<{ id: string }>[]> =>
27
+ * fetch(`/api/users?q=${encodeURIComponent(q)}`).then((r) => r.json())
28
+ *
29
+ * return () =>
30
+ * h(SearchAutocomplete, {
31
+ * value: query.value,
32
+ * onChange: (next: string) => {
33
+ * query.value = next
34
+ * },
35
+ * onSearch: fetchUsers,
36
+ * onSelect: (item) => console.log(item.data?.id),
37
+ * placeholder: 'Search users…',
38
+ * })
39
+ * },
40
+ * })
41
+ *
42
+ * const app = createApp(UserSearch)
43
+ * app.use(moleculePlugin, { i18n: i18nProvider })
44
+ * app.mount('#app')
45
+ * ```
46
+ *
47
+ * @remarks
48
+ * - Throws unless mounted under `moleculePlugin` (from `@molecule/app-vue`)
49
+ * with a bonded ClassMap.
50
+ * - Full keyboard support: it's an ARIA combobox — ArrowDown/ArrowUp move the
51
+ * highlight (opening the popover), Enter selects the highlighted option, and
52
+ * Escape closes. `aria-activedescendant` tracks the active `role="option"`.
53
+ * - Stale-response safe: out-of-order `onSearch` responses are dropped (each
54
+ * request carries a token; only the latest applies), so a slow earlier fetch
55
+ * can't overwrite fresher results. `onSearch` needs no cancellation of its own.
56
+ * - The popover surface uses `var(--color-surface)` with a WHITE fallback
57
+ * and black-alpha borders — define `--color-surface` (dark themes) or the
58
+ * dropdown stays light.
59
+ * - Default placeholder translations: `@molecule/app-locales-search-autocomplete`.
60
+ *
61
+ * @module
62
+ */
63
+ export * from './SearchAutocomplete.js';
64
+ export * from './types.js';
65
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Search input with a typeahead suggestion popover.
3
+ *
4
+ * Exports `<SearchAutocomplete>` and the `SuggestionItem<T>` type
5
+ * (`{ id, label, meta?, data? }`). Two data modes — pass ONE of:
6
+ * `onSearch(query)` (async fetch, debounced; default 200 ms) or
7
+ * `suggestions` (caller-controlled list). Other props: `value` / `onChange`
8
+ * (controlled input), `onSelect(item)`, `placeholder?` (defaults to the
9
+ * translated `search.placeholder`), `debounceMs?`, `minChars?` (default 1),
10
+ * `className?`.
11
+ *
12
+ * Vue counterpart of `@molecule/app-search-autocomplete-react`: the same
13
+ * exports, the same props (React names), the same ClassMap tokens and the same
14
+ * DOM for the same input.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createApp, defineComponent, h, ref } from 'vue'
19
+ * import { moleculePlugin } from '@molecule/app-vue'
20
+ * import { SearchAutocomplete } from '@molecule/app-search-autocomplete-vue'
21
+ * import type { SuggestionItem } from '@molecule/app-search-autocomplete-vue'
22
+ *
23
+ * const UserSearch = defineComponent({
24
+ * setup() {
25
+ * const query = ref('')
26
+ * const fetchUsers = (q: string): Promise<SuggestionItem<{ id: string }>[]> =>
27
+ * fetch(`/api/users?q=${encodeURIComponent(q)}`).then((r) => r.json())
28
+ *
29
+ * return () =>
30
+ * h(SearchAutocomplete, {
31
+ * value: query.value,
32
+ * onChange: (next: string) => {
33
+ * query.value = next
34
+ * },
35
+ * onSearch: fetchUsers,
36
+ * onSelect: (item) => console.log(item.data?.id),
37
+ * placeholder: 'Search users…',
38
+ * })
39
+ * },
40
+ * })
41
+ *
42
+ * const app = createApp(UserSearch)
43
+ * app.use(moleculePlugin, { i18n: i18nProvider })
44
+ * app.mount('#app')
45
+ * ```
46
+ *
47
+ * @remarks
48
+ * - Throws unless mounted under `moleculePlugin` (from `@molecule/app-vue`)
49
+ * with a bonded ClassMap.
50
+ * - Full keyboard support: it's an ARIA combobox — ArrowDown/ArrowUp move the
51
+ * highlight (opening the popover), Enter selects the highlighted option, and
52
+ * Escape closes. `aria-activedescendant` tracks the active `role="option"`.
53
+ * - Stale-response safe: out-of-order `onSearch` responses are dropped (each
54
+ * request carries a token; only the latest applies), so a slow earlier fetch
55
+ * can't overwrite fresher results. `onSearch` needs no cancellation of its own.
56
+ * - The popover surface uses `var(--color-surface)` with a WHITE fallback
57
+ * and black-alpha borders — define `--color-surface` (dark themes) or the
58
+ * dropdown stays light.
59
+ * - Default placeholder translations: `@molecule/app-locales-search-autocomplete`.
60
+ *
61
+ * @module
62
+ */
63
+ export * from './SearchAutocomplete.js';
64
+ export * from './types.js';
65
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,cAAc,yBAAyB,CAAA;AACvC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Types for the Vue search-autocomplete component.
3
+ *
4
+ * Vue counterparts of `@molecule/app-search-autocomplete-react`'s props — the
5
+ * same prop names, with node-valued suggestions accepted as VNodes (or, as in
6
+ * Vue, through a same-named slot).
7
+ *
8
+ * @module
9
+ */
10
+ import type { VNodeChild } from 'vue';
11
+ /**
12
+ * A single suggestion entry returned by `onSearch` or passed via `suggestions`.
13
+ */
14
+ export interface SuggestionItem<T = unknown> {
15
+ id: string;
16
+ label: VNodeChild;
17
+ /** Optional secondary line / category. */
18
+ meta?: VNodeChild;
19
+ /** Original payload for the selection callback. */
20
+ data?: T;
21
+ }
22
+ /** Props accepted by the {@link SearchAutocomplete} component. */
23
+ export interface SearchAutocompleteProps<T = unknown> {
24
+ /** Current input value. */
25
+ value: string;
26
+ /** Called whenever the input changes. */
27
+ onChange: (value: string) => void;
28
+ /** Async search function — receives the query, returns suggestions. */
29
+ onSearch?: (query: string) => Promise<SuggestionItem<T>[]> | SuggestionItem<T>[];
30
+ /** Optional pre-computed suggestion list (when caller controls fetching). */
31
+ suggestions?: SuggestionItem<T>[];
32
+ /** Called when the user picks a suggestion. */
33
+ onSelect: (item: SuggestionItem<T>) => void;
34
+ /** Placeholder. */
35
+ placeholder?: string;
36
+ /**
37
+ * Accessible name for the input, rendered as `aria-label`. Defaults to the
38
+ * translated `search.aria.label`: a placeholder is not a label, so an input
39
+ * named only by its placeholder (let alone an empty one) is nameless for
40
+ * assistive technology.
41
+ */
42
+ ariaLabel?: string;
43
+ /** Debounce ms for `onSearch`. Defaults to 200. */
44
+ debounceMs?: number;
45
+ /** Min chars before suggestions appear. Defaults to 1. */
46
+ minChars?: number;
47
+ /** Extra classes on the wrapper. */
48
+ className?: string;
49
+ }
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAErC;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,OAAO;IACzC,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,UAAU,CAAA;IACjB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,UAAU,CAAA;IACjB,mDAAmD;IACnD,IAAI,CAAC,EAAE,CAAC,CAAA;CACT;AAED,kEAAkE;AAClE,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO;IAClD,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,yCAAyC;IACzC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,uEAAuE;IACvE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA;IAChF,6EAA6E;IAC7E,WAAW,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAA;IACjC,+CAA+C;IAC/C,QAAQ,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC3C,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Types for the Vue search-autocomplete component.
3
+ *
4
+ * Vue counterparts of `@molecule/app-search-autocomplete-react`'s props — the
5
+ * same prop names, with node-valued suggestions accepted as VNodes (or, as in
6
+ * Vue, through a same-named slot).
7
+ *
8
+ * @module
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@molecule/app-search-autocomplete-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "Search input with typeahead suggestion popover",
5
+ "homepage": "https://www.molecule.dev/packages/app-search-autocomplete-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "search-autocomplete",
28
+ "vue"
29
+ ],
30
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
31
+ "license": "Apache-2.0",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/molecule-dev/molecule.git",
35
+ "directory": "packages/app/features/search-autocomplete-vue"
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "peerDependencies": {
45
+ "@molecule/app-ui": "^1.0.1",
46
+ "@molecule/app-ui-vue": "^1.1.0",
47
+ "@molecule/app-vue": "^3.5.0",
48
+ "vue": "^3.4.0"
49
+ },
50
+ "devDependencies": {
51
+ "@molecule/app-framework-conformance": "0.0.0",
52
+ "@molecule/app-i18n": "1.2.2",
53
+ "@molecule/app-icons": "1.0.4",
54
+ "@molecule/app-ui": "1.5.0",
55
+ "@molecule/app-ui-vue": "1.2.1",
56
+ "@molecule/app-vue": "3.9.0",
57
+ "@types/node": "26.6.5",
58
+ "jsdom": "30.1.3",
59
+ "typescript": "6.0.3",
60
+ "vite": "8.3.5",
61
+ "vitest": "4.1.12",
62
+ "vue": "3.5.44",
63
+ "vue-tsc": "3.3.13"
64
+ }
65
+ }