@smilodon/vue 1.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/README.md +413 -0
- package/dist/index.cjs +309 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +288 -0
- package/dist/index.js.map +1 -0
- package/dist/style.css +2 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
# @smilodon/vue
|
|
2
|
+
|
|
3
|
+
Production-ready, accessible select component for Vue 3 applications.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ⨠**Single & Multi-Select** - Flexible selection modes
|
|
8
|
+
- đ **Searchable** - Built-in search with client or server-side filtering
|
|
9
|
+
- âŋ **Fully Accessible** - WCAG 2.1 AAA compliant with complete keyboard navigation
|
|
10
|
+
- đ **Virtual Scrolling** - Handle thousands of items efficiently
|
|
11
|
+
- â **Infinite Scroll** - Load more items on demand
|
|
12
|
+
- đĻ **Grouped Options** - Organize items with group headers
|
|
13
|
+
- đ¨ **Themeable** - Multiple built-in themes or custom styles
|
|
14
|
+
- đĒ **TypeScript** - Full type safety and intellisense
|
|
15
|
+
- đĒļ **Lightweight** - Only 2.0KB gzipped
|
|
16
|
+
- đ¯ **Vue 3 Composition API** - Modern Vue patterns with v-model support
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @smilodon/vue @smilodon/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
```vue
|
|
27
|
+
<script setup>
|
|
28
|
+
import { ref } from 'vue';
|
|
29
|
+
import { Select } from '@smilodon/vue';
|
|
30
|
+
|
|
31
|
+
const selectedValue = ref('');
|
|
32
|
+
const items = [
|
|
33
|
+
{ value: 'apple', label: 'Apple' },
|
|
34
|
+
{ value: 'banana', label: 'Banana' },
|
|
35
|
+
{ value: 'cherry', label: 'Cherry' },
|
|
36
|
+
];
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<Select
|
|
41
|
+
:items="items"
|
|
42
|
+
v-model="selectedValue"
|
|
43
|
+
placeholder="Select a fruit..."
|
|
44
|
+
searchable
|
|
45
|
+
/>
|
|
46
|
+
</template>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Examples
|
|
50
|
+
|
|
51
|
+
### Basic Single Select
|
|
52
|
+
|
|
53
|
+
```vue
|
|
54
|
+
<script setup>
|
|
55
|
+
import { ref } from 'vue';
|
|
56
|
+
import { Select } from '@smilodon/vue';
|
|
57
|
+
|
|
58
|
+
const value = ref('');
|
|
59
|
+
const items = [
|
|
60
|
+
{ value: '1', label: 'Option 1' },
|
|
61
|
+
{ value: '2', label: 'Option 2' },
|
|
62
|
+
{ value: '3', label: 'Option 3' },
|
|
63
|
+
];
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<div>
|
|
68
|
+
<Select
|
|
69
|
+
:items="items"
|
|
70
|
+
v-model="value"
|
|
71
|
+
placeholder="Choose an option..."
|
|
72
|
+
/>
|
|
73
|
+
<p>Selected: {{ value }}</p>
|
|
74
|
+
</div>
|
|
75
|
+
</template>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Multi-Select
|
|
79
|
+
|
|
80
|
+
```vue
|
|
81
|
+
<script setup>
|
|
82
|
+
import { ref } from 'vue';
|
|
83
|
+
import { Select } from '@smilodon/vue';
|
|
84
|
+
|
|
85
|
+
const selectedValues = ref([]);
|
|
86
|
+
const colors = [
|
|
87
|
+
{ value: 'red', label: 'Red' },
|
|
88
|
+
{ value: 'green', label: 'Green' },
|
|
89
|
+
{ value: 'blue', label: 'Blue' },
|
|
90
|
+
{ value: 'yellow', label: 'Yellow' },
|
|
91
|
+
];
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<Select
|
|
96
|
+
:items="colors"
|
|
97
|
+
v-model="selectedValues"
|
|
98
|
+
placeholder="Select colors..."
|
|
99
|
+
multiple
|
|
100
|
+
searchable
|
|
101
|
+
/>
|
|
102
|
+
</template>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Searchable with Server-Side Filtering
|
|
106
|
+
|
|
107
|
+
```vue
|
|
108
|
+
<script setup>
|
|
109
|
+
import { ref } from 'vue';
|
|
110
|
+
import { Select } from '@smilodon/vue';
|
|
111
|
+
|
|
112
|
+
const value = ref('');
|
|
113
|
+
const items = ref([]);
|
|
114
|
+
const isLoading = ref(false);
|
|
115
|
+
|
|
116
|
+
async function handleSearch(query) {
|
|
117
|
+
if (!query) {
|
|
118
|
+
items.value = [];
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
isLoading.value = true;
|
|
123
|
+
try {
|
|
124
|
+
const response = await fetch(`/api/search?q=${query}`);
|
|
125
|
+
const data = await response.json();
|
|
126
|
+
items.value = data.results;
|
|
127
|
+
} finally {
|
|
128
|
+
isLoading.value = false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<template>
|
|
134
|
+
<Select
|
|
135
|
+
:items="items"
|
|
136
|
+
v-model="value"
|
|
137
|
+
searchable
|
|
138
|
+
placeholder="Search..."
|
|
139
|
+
@search="handleSearch"
|
|
140
|
+
/>
|
|
141
|
+
</template>
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Grouped Options
|
|
145
|
+
|
|
146
|
+
```vue
|
|
147
|
+
<script setup>
|
|
148
|
+
import { ref } from 'vue';
|
|
149
|
+
import { Select } from '@smilodon/vue';
|
|
150
|
+
|
|
151
|
+
const value = ref('');
|
|
152
|
+
const groupedItems = [
|
|
153
|
+
{
|
|
154
|
+
groupLabel: 'Fruits',
|
|
155
|
+
items: [
|
|
156
|
+
{ value: 'apple', label: 'Apple' },
|
|
157
|
+
{ value: 'banana', label: 'Banana' },
|
|
158
|
+
]
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
groupLabel: 'Vegetables',
|
|
162
|
+
items: [
|
|
163
|
+
{ value: 'carrot', label: 'Carrot' },
|
|
164
|
+
{ value: 'potato', label: 'Potato' },
|
|
165
|
+
]
|
|
166
|
+
}
|
|
167
|
+
];
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
<template>
|
|
171
|
+
<Select
|
|
172
|
+
:groupedItems="groupedItems"
|
|
173
|
+
v-model="value"
|
|
174
|
+
searchable
|
|
175
|
+
/>
|
|
176
|
+
</template>
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Infinite Scroll
|
|
180
|
+
|
|
181
|
+
```vue
|
|
182
|
+
<script setup>
|
|
183
|
+
import { ref } from 'vue';
|
|
184
|
+
import { Select } from '@smilodon/vue';
|
|
185
|
+
|
|
186
|
+
const value = ref('');
|
|
187
|
+
const items = ref([]);
|
|
188
|
+
const currentPage = ref(1);
|
|
189
|
+
|
|
190
|
+
async function loadMore(page) {
|
|
191
|
+
const response = await fetch(`/api/items?page=${page}`);
|
|
192
|
+
const newItems = await response.json();
|
|
193
|
+
items.value = [...items.value, ...newItems];
|
|
194
|
+
currentPage.value = page;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Load initial page
|
|
198
|
+
onMounted(() => loadMore(1));
|
|
199
|
+
</script>
|
|
200
|
+
|
|
201
|
+
<template>
|
|
202
|
+
<Select
|
|
203
|
+
:items="items"
|
|
204
|
+
v-model="value"
|
|
205
|
+
infiniteScroll
|
|
206
|
+
:pageSize="50"
|
|
207
|
+
@loadMore="loadMore"
|
|
208
|
+
/>
|
|
209
|
+
</template>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Form Validation
|
|
213
|
+
|
|
214
|
+
```vue
|
|
215
|
+
<script setup>
|
|
216
|
+
import { ref } from 'vue';
|
|
217
|
+
import { Select } from '@smilodon/vue';
|
|
218
|
+
|
|
219
|
+
const value = ref('');
|
|
220
|
+
const error = ref(false);
|
|
221
|
+
const items = [
|
|
222
|
+
{ value: 'small', label: 'Small' },
|
|
223
|
+
{ value: 'medium', label: 'Medium' },
|
|
224
|
+
{ value: 'large', label: 'Large' },
|
|
225
|
+
];
|
|
226
|
+
|
|
227
|
+
function handleSubmit() {
|
|
228
|
+
if (!value.value) {
|
|
229
|
+
error.value = true;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
error.value = false;
|
|
233
|
+
// Submit form...
|
|
234
|
+
}
|
|
235
|
+
</script>
|
|
236
|
+
|
|
237
|
+
<template>
|
|
238
|
+
<form @submit.prevent="handleSubmit">
|
|
239
|
+
<Select
|
|
240
|
+
:items="items"
|
|
241
|
+
v-model="value"
|
|
242
|
+
placeholder="Select size..."
|
|
243
|
+
required
|
|
244
|
+
:error="error"
|
|
245
|
+
/>
|
|
246
|
+
<p v-if="error" class="error">Please select a size</p>
|
|
247
|
+
<button type="submit">Submit</button>
|
|
248
|
+
</form>
|
|
249
|
+
</template>
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Using Template Ref
|
|
253
|
+
|
|
254
|
+
```vue
|
|
255
|
+
<script setup>
|
|
256
|
+
import { ref } from 'vue';
|
|
257
|
+
import { Select } from '@smilodon/vue';
|
|
258
|
+
|
|
259
|
+
const selectRef = ref(null);
|
|
260
|
+
const value = ref('');
|
|
261
|
+
const items = [
|
|
262
|
+
{ value: '1', label: 'Option 1' },
|
|
263
|
+
{ value: '2', label: 'Option 2' },
|
|
264
|
+
];
|
|
265
|
+
|
|
266
|
+
function openSelect() {
|
|
267
|
+
selectRef.value?.open();
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function clearSelection() {
|
|
271
|
+
selectRef.value?.clear();
|
|
272
|
+
}
|
|
273
|
+
</script>
|
|
274
|
+
|
|
275
|
+
<template>
|
|
276
|
+
<div>
|
|
277
|
+
<Select
|
|
278
|
+
ref="selectRef"
|
|
279
|
+
:items="items"
|
|
280
|
+
v-model="value"
|
|
281
|
+
/>
|
|
282
|
+
<button @click="openSelect">Open</button>
|
|
283
|
+
<button @click="clearSelection">Clear</button>
|
|
284
|
+
</div>
|
|
285
|
+
</template>
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## API Reference
|
|
289
|
+
|
|
290
|
+
### Props
|
|
291
|
+
|
|
292
|
+
| Prop | Type | Default | Description |
|
|
293
|
+
|------|------|---------|-------------|
|
|
294
|
+
| `items` | `SelectItem[]` | `[]` | Array of items to display |
|
|
295
|
+
| `groupedItems` | `GroupedItem[]` | - | Grouped items (alternative to items) |
|
|
296
|
+
| `modelValue` | `string \| number \| (string \| number)[]` | - | Selected value(s) for v-model |
|
|
297
|
+
| `defaultValue` | `string \| number \| (string \| number)[]` | - | Default value for uncontrolled mode |
|
|
298
|
+
| `multiple` | `boolean` | `false` | Enable multi-select mode |
|
|
299
|
+
| `searchable` | `boolean` | `false` | Enable search functionality |
|
|
300
|
+
| `placeholder` | `string` | - | Placeholder text |
|
|
301
|
+
| `disabled` | `boolean` | `false` | Disable the select |
|
|
302
|
+
| `required` | `boolean` | `false` | Mark as required |
|
|
303
|
+
| `error` | `boolean` | `false` | Show error state |
|
|
304
|
+
| `infiniteScroll` | `boolean` | `false` | Enable infinite scroll |
|
|
305
|
+
| `pageSize` | `number` | `50` | Items per page (for infinite scroll) |
|
|
306
|
+
| `virtualized` | `boolean` | `true` | Enable virtual scrolling |
|
|
307
|
+
| `maxSelections` | `number` | - | Maximum selections (for multi-select) |
|
|
308
|
+
| `placement` | `'bottom' \| 'top' \| 'auto'` | `'auto'` | Dropdown placement |
|
|
309
|
+
| `className` | `string` | - | Custom CSS class |
|
|
310
|
+
| `style` | `object` | - | Custom inline styles |
|
|
311
|
+
|
|
312
|
+
### Events
|
|
313
|
+
|
|
314
|
+
| Event | Payload | Description |
|
|
315
|
+
|-------|---------|-------------|
|
|
316
|
+
| `update:modelValue` | `value: string \| number \| (string \| number)[]` | Emitted when selection changes (v-model) |
|
|
317
|
+
| `change` | `value, selectedItems: SelectItem[]` | Emitted with full selection details |
|
|
318
|
+
| `select` | `item: SelectItem, index: number` | Emitted when an item is selected |
|
|
319
|
+
| `open` | - | Emitted when dropdown opens |
|
|
320
|
+
| `close` | - | Emitted when dropdown closes |
|
|
321
|
+
| `search` | `query: string` | Emitted when search query changes |
|
|
322
|
+
| `loadMore` | `page: number` | Emitted when more items requested |
|
|
323
|
+
| `create` | `value: string` | Emitted when user creates new item |
|
|
324
|
+
|
|
325
|
+
### Exposed Methods (Template Ref)
|
|
326
|
+
|
|
327
|
+
| Method | Description |
|
|
328
|
+
|--------|-------------|
|
|
329
|
+
| `open()` | Open the dropdown |
|
|
330
|
+
| `close()` | Close the dropdown |
|
|
331
|
+
| `focus()` | Focus the select |
|
|
332
|
+
| `setItems(items)` | Set items programmatically |
|
|
333
|
+
| `setGroupedItems(groups)` | Set grouped items programmatically |
|
|
334
|
+
| `clear()` | Clear selection |
|
|
335
|
+
|
|
336
|
+
### Types
|
|
337
|
+
|
|
338
|
+
```typescript
|
|
339
|
+
interface SelectItem {
|
|
340
|
+
value: string | number;
|
|
341
|
+
label: string;
|
|
342
|
+
disabled?: boolean;
|
|
343
|
+
group?: string;
|
|
344
|
+
[key: string]: any;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
interface GroupedItem {
|
|
348
|
+
groupLabel: string;
|
|
349
|
+
items: SelectItem[];
|
|
350
|
+
}
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
## Styling
|
|
354
|
+
|
|
355
|
+
The component uses web components from `@smilodon/core` and comes with built-in themes.
|
|
356
|
+
|
|
357
|
+
### Built-in Themes
|
|
358
|
+
|
|
359
|
+
- Apple/macOS style
|
|
360
|
+
- Windows style
|
|
361
|
+
- Material Design
|
|
362
|
+
- Default
|
|
363
|
+
|
|
364
|
+
### Custom Styling
|
|
365
|
+
|
|
366
|
+
```vue
|
|
367
|
+
<template>
|
|
368
|
+
<Select
|
|
369
|
+
:items="items"
|
|
370
|
+
v-model="value"
|
|
371
|
+
className="my-custom-select"
|
|
372
|
+
:style="{ '--border-radius': '8px' }"
|
|
373
|
+
/>
|
|
374
|
+
</template>
|
|
375
|
+
|
|
376
|
+
<style>
|
|
377
|
+
.my-custom-select {
|
|
378
|
+
--primary-color: #007bff;
|
|
379
|
+
--border-color: #ced4da;
|
|
380
|
+
--focus-color: #80bdff;
|
|
381
|
+
}
|
|
382
|
+
</style>
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
## Accessibility
|
|
386
|
+
|
|
387
|
+
- â
Full keyboard navigation (Arrow keys, Enter, Escape, Tab)
|
|
388
|
+
- â
Screen reader support with ARIA labels
|
|
389
|
+
- â
Focus management and trap
|
|
390
|
+
- â
High contrast mode support
|
|
391
|
+
- â
WCAG 2.1 AAA compliant
|
|
392
|
+
|
|
393
|
+
## Performance
|
|
394
|
+
|
|
395
|
+
- Virtual scrolling handles 100,000+ items smoothly
|
|
396
|
+
- Efficient DOM updates with Vue's reactivity
|
|
397
|
+
- Lazy loading with infinite scroll
|
|
398
|
+
- Optimized re-renders with computed values
|
|
399
|
+
|
|
400
|
+
## Browser Support
|
|
401
|
+
|
|
402
|
+
- Chrome/Edge (latest)
|
|
403
|
+
- Firefox (latest)
|
|
404
|
+
- Safari (latest)
|
|
405
|
+
- Mobile browsers (iOS Safari, Chrome Android)
|
|
406
|
+
|
|
407
|
+
## License
|
|
408
|
+
|
|
409
|
+
MIT
|
|
410
|
+
|
|
411
|
+
## Contributing
|
|
412
|
+
|
|
413
|
+
See the main [repository](https://github.com/yourusername/smilodon) for contribution guidelines.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const core = require("@smilodon/core");
|
|
5
|
+
const _sfc_main = /* @__PURE__ */ vue.defineComponent({
|
|
6
|
+
__name: "Select",
|
|
7
|
+
props: {
|
|
8
|
+
items: { default: () => [] },
|
|
9
|
+
groupedItems: {},
|
|
10
|
+
modelValue: {},
|
|
11
|
+
defaultValue: {},
|
|
12
|
+
multiple: { type: Boolean, default: false },
|
|
13
|
+
searchable: { type: Boolean, default: false },
|
|
14
|
+
placeholder: {},
|
|
15
|
+
disabled: { type: Boolean, default: false },
|
|
16
|
+
required: { type: Boolean, default: false },
|
|
17
|
+
error: { type: Boolean, default: false },
|
|
18
|
+
infiniteScroll: { type: Boolean, default: false },
|
|
19
|
+
pageSize: { default: 50 },
|
|
20
|
+
virtualized: { type: Boolean, default: true },
|
|
21
|
+
maxSelections: {},
|
|
22
|
+
placement: { default: "auto" },
|
|
23
|
+
className: {},
|
|
24
|
+
style: {}
|
|
25
|
+
},
|
|
26
|
+
emits: ["update:modelValue", "change", "select", "open", "close", "search", "loadMore", "create"],
|
|
27
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
28
|
+
const props = __props;
|
|
29
|
+
const emit = __emit;
|
|
30
|
+
const selectRef = vue.ref(null);
|
|
31
|
+
const internalValue = vue.ref(
|
|
32
|
+
props.defaultValue
|
|
33
|
+
);
|
|
34
|
+
const isControlled = vue.computed(() => props.modelValue !== void 0);
|
|
35
|
+
const currentValue = vue.computed(
|
|
36
|
+
() => isControlled.value ? props.modelValue : internalValue.value
|
|
37
|
+
);
|
|
38
|
+
vue.watch(
|
|
39
|
+
() => props.items,
|
|
40
|
+
(newItems) => {
|
|
41
|
+
if (selectRef.value && newItems) {
|
|
42
|
+
selectRef.value.setItems(newItems);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{ deep: true }
|
|
46
|
+
);
|
|
47
|
+
vue.watch(
|
|
48
|
+
() => props.groupedItems,
|
|
49
|
+
(newGroups) => {
|
|
50
|
+
if (selectRef.value && newGroups) {
|
|
51
|
+
selectRef.value.setGroupedItems(newGroups);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{ deep: true }
|
|
55
|
+
);
|
|
56
|
+
vue.watch(
|
|
57
|
+
currentValue,
|
|
58
|
+
(newValue) => {
|
|
59
|
+
if (selectRef.value && newValue !== void 0) {
|
|
60
|
+
const values = Array.isArray(newValue) ? newValue : [newValue];
|
|
61
|
+
selectRef.value.setSelectedValues(values);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{ immediate: true }
|
|
65
|
+
);
|
|
66
|
+
vue.watch(
|
|
67
|
+
() => props.placeholder,
|
|
68
|
+
(newPlaceholder) => {
|
|
69
|
+
if (selectRef.value && newPlaceholder) {
|
|
70
|
+
selectRef.value.setAttribute("placeholder", newPlaceholder);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
vue.watch(
|
|
75
|
+
() => props.disabled,
|
|
76
|
+
(newDisabled) => {
|
|
77
|
+
if (selectRef.value) {
|
|
78
|
+
if (newDisabled) {
|
|
79
|
+
selectRef.value.setAttribute("disabled", "");
|
|
80
|
+
} else {
|
|
81
|
+
selectRef.value.removeAttribute("disabled");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
vue.watch(
|
|
87
|
+
() => props.searchable,
|
|
88
|
+
(newSearchable) => {
|
|
89
|
+
if (selectRef.value) {
|
|
90
|
+
if (newSearchable) {
|
|
91
|
+
selectRef.value.setAttribute("searchable", "");
|
|
92
|
+
} else {
|
|
93
|
+
selectRef.value.removeAttribute("searchable");
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
98
|
+
vue.watch(
|
|
99
|
+
() => props.multiple,
|
|
100
|
+
(newMultiple) => {
|
|
101
|
+
if (selectRef.value) {
|
|
102
|
+
if (newMultiple) {
|
|
103
|
+
selectRef.value.setAttribute("multiple", "");
|
|
104
|
+
} else {
|
|
105
|
+
selectRef.value.removeAttribute("multiple");
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
vue.watch(
|
|
111
|
+
() => props.virtualized,
|
|
112
|
+
(newVirtualized) => {
|
|
113
|
+
if (selectRef.value) {
|
|
114
|
+
if (newVirtualized) {
|
|
115
|
+
selectRef.value.setAttribute("virtualized", "");
|
|
116
|
+
} else {
|
|
117
|
+
selectRef.value.removeAttribute("virtualized");
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
const handleSelect = (e) => {
|
|
123
|
+
const customEvent = e;
|
|
124
|
+
const { item, index } = customEvent.detail;
|
|
125
|
+
emit("select", item, index);
|
|
126
|
+
};
|
|
127
|
+
const handleChange = (e) => {
|
|
128
|
+
const customEvent = e;
|
|
129
|
+
const { selectedItems, selectedValues } = customEvent.detail;
|
|
130
|
+
const values = selectedValues;
|
|
131
|
+
if (!isControlled.value) {
|
|
132
|
+
internalValue.value = props.multiple ? values : values[0];
|
|
133
|
+
}
|
|
134
|
+
const value = props.multiple ? values : values[0];
|
|
135
|
+
emit("update:modelValue", value);
|
|
136
|
+
emit("change", value, selectedItems);
|
|
137
|
+
};
|
|
138
|
+
const handleOpen = () => {
|
|
139
|
+
emit("open");
|
|
140
|
+
};
|
|
141
|
+
const handleClose = () => {
|
|
142
|
+
emit("close");
|
|
143
|
+
};
|
|
144
|
+
const handleSearch = (e) => {
|
|
145
|
+
const customEvent = e;
|
|
146
|
+
emit("search", customEvent.detail.query);
|
|
147
|
+
};
|
|
148
|
+
const handleLoadMore = (e) => {
|
|
149
|
+
const customEvent = e;
|
|
150
|
+
emit("loadMore", customEvent.detail.page);
|
|
151
|
+
};
|
|
152
|
+
const handleCreate = (e) => {
|
|
153
|
+
const customEvent = e;
|
|
154
|
+
emit("create", customEvent.detail.value);
|
|
155
|
+
};
|
|
156
|
+
vue.onMounted(() => {
|
|
157
|
+
var _a, _b;
|
|
158
|
+
if (!selectRef.value) return;
|
|
159
|
+
const element = selectRef.value;
|
|
160
|
+
if (props.placeholder) {
|
|
161
|
+
element.setAttribute("placeholder", props.placeholder);
|
|
162
|
+
}
|
|
163
|
+
if (props.disabled) {
|
|
164
|
+
element.setAttribute("disabled", "");
|
|
165
|
+
}
|
|
166
|
+
if (props.required) {
|
|
167
|
+
element.setAttribute("required", "");
|
|
168
|
+
}
|
|
169
|
+
if (props.error) {
|
|
170
|
+
element.setAttribute("error", "");
|
|
171
|
+
}
|
|
172
|
+
if (props.searchable) {
|
|
173
|
+
element.setAttribute("searchable", "");
|
|
174
|
+
}
|
|
175
|
+
if (props.multiple) {
|
|
176
|
+
element.setAttribute("multiple", "");
|
|
177
|
+
}
|
|
178
|
+
if (props.virtualized) {
|
|
179
|
+
element.setAttribute("virtualized", "");
|
|
180
|
+
}
|
|
181
|
+
if (props.infiniteScroll) {
|
|
182
|
+
element.setAttribute("infinite-scroll", "");
|
|
183
|
+
}
|
|
184
|
+
if (props.pageSize) {
|
|
185
|
+
element.setAttribute("page-size", String(props.pageSize));
|
|
186
|
+
}
|
|
187
|
+
if (props.maxSelections) {
|
|
188
|
+
element.setAttribute("max-selections", String(props.maxSelections));
|
|
189
|
+
}
|
|
190
|
+
if (props.placement) {
|
|
191
|
+
element.setAttribute("placement", props.placement);
|
|
192
|
+
}
|
|
193
|
+
if ((_a = props.items) == null ? void 0 : _a.length) {
|
|
194
|
+
element.setItems(props.items);
|
|
195
|
+
}
|
|
196
|
+
if ((_b = props.groupedItems) == null ? void 0 : _b.length) {
|
|
197
|
+
element.setGroupedItems(props.groupedItems);
|
|
198
|
+
}
|
|
199
|
+
if (currentValue.value !== void 0) {
|
|
200
|
+
const values = Array.isArray(currentValue.value) ? currentValue.value : [currentValue.value];
|
|
201
|
+
element.setSelectedValues(values);
|
|
202
|
+
}
|
|
203
|
+
element.addEventListener("select", handleSelect);
|
|
204
|
+
element.addEventListener("change", handleChange);
|
|
205
|
+
element.addEventListener("open", handleOpen);
|
|
206
|
+
element.addEventListener("close", handleClose);
|
|
207
|
+
element.addEventListener("search", handleSearch);
|
|
208
|
+
element.addEventListener("loadMore", handleLoadMore);
|
|
209
|
+
element.addEventListener("create", handleCreate);
|
|
210
|
+
});
|
|
211
|
+
vue.onBeforeUnmount(() => {
|
|
212
|
+
if (!selectRef.value) return;
|
|
213
|
+
const element = selectRef.value;
|
|
214
|
+
element.removeEventListener("select", handleSelect);
|
|
215
|
+
element.removeEventListener("change", handleChange);
|
|
216
|
+
element.removeEventListener("open", handleOpen);
|
|
217
|
+
element.removeEventListener("close", handleClose);
|
|
218
|
+
element.removeEventListener("search", handleSearch);
|
|
219
|
+
element.removeEventListener("loadMore", handleLoadMore);
|
|
220
|
+
element.removeEventListener("create", handleCreate);
|
|
221
|
+
});
|
|
222
|
+
__expose({
|
|
223
|
+
/** Open the dropdown */
|
|
224
|
+
open: () => {
|
|
225
|
+
var _a;
|
|
226
|
+
(_a = selectRef.value) == null ? void 0 : _a.open();
|
|
227
|
+
},
|
|
228
|
+
/** Close the dropdown */
|
|
229
|
+
close: () => {
|
|
230
|
+
var _a;
|
|
231
|
+
(_a = selectRef.value) == null ? void 0 : _a.close();
|
|
232
|
+
},
|
|
233
|
+
/** Focus the select */
|
|
234
|
+
focus: () => {
|
|
235
|
+
var _a;
|
|
236
|
+
(_a = selectRef.value) == null ? void 0 : _a.focus();
|
|
237
|
+
},
|
|
238
|
+
/** Set items programmatically */
|
|
239
|
+
setItems: (items) => {
|
|
240
|
+
var _a;
|
|
241
|
+
(_a = selectRef.value) == null ? void 0 : _a.setItems(items);
|
|
242
|
+
},
|
|
243
|
+
/** Set grouped items programmatically */
|
|
244
|
+
setGroupedItems: (groups) => {
|
|
245
|
+
var _a;
|
|
246
|
+
(_a = selectRef.value) == null ? void 0 : _a.setGroupedItems(groups);
|
|
247
|
+
},
|
|
248
|
+
/** Clear selection */
|
|
249
|
+
clear: () => {
|
|
250
|
+
var _a;
|
|
251
|
+
(_a = selectRef.value) == null ? void 0 : _a.setSelectedValues([]);
|
|
252
|
+
if (!isControlled.value) {
|
|
253
|
+
internalValue.value = props.multiple ? [] : void 0;
|
|
254
|
+
}
|
|
255
|
+
const value = props.multiple ? [] : "";
|
|
256
|
+
emit("update:modelValue", value);
|
|
257
|
+
emit("change", value, []);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return (_ctx, _cache) => {
|
|
261
|
+
const _component_enhanced_select = vue.resolveComponent("enhanced-select");
|
|
262
|
+
return vue.openBlock(), vue.createBlock(_component_enhanced_select, {
|
|
263
|
+
ref_key: "selectRef",
|
|
264
|
+
ref: selectRef,
|
|
265
|
+
class: vue.normalizeClass(__props.className),
|
|
266
|
+
style: vue.normalizeStyle(__props.style)
|
|
267
|
+
}, null, 8, ["class", "style"]);
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
const _export_sfc = (sfc, props) => {
|
|
272
|
+
const target = sfc.__vccOpts || sfc;
|
|
273
|
+
for (const [key, val] of props) {
|
|
274
|
+
target[key] = val;
|
|
275
|
+
}
|
|
276
|
+
return target;
|
|
277
|
+
};
|
|
278
|
+
const Select = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a2f90b1e"]]);
|
|
279
|
+
Object.defineProperty(exports, "ChangeEventDetail", {
|
|
280
|
+
enumerable: true,
|
|
281
|
+
get: () => core.ChangeEventDetail
|
|
282
|
+
});
|
|
283
|
+
Object.defineProperty(exports, "CloseEventDetail", {
|
|
284
|
+
enumerable: true,
|
|
285
|
+
get: () => core.CloseEventDetail
|
|
286
|
+
});
|
|
287
|
+
Object.defineProperty(exports, "GroupedItem", {
|
|
288
|
+
enumerable: true,
|
|
289
|
+
get: () => core.GroupedItem
|
|
290
|
+
});
|
|
291
|
+
Object.defineProperty(exports, "LoadMoreEventDetail", {
|
|
292
|
+
enumerable: true,
|
|
293
|
+
get: () => core.LoadMoreEventDetail
|
|
294
|
+
});
|
|
295
|
+
Object.defineProperty(exports, "OpenEventDetail", {
|
|
296
|
+
enumerable: true,
|
|
297
|
+
get: () => core.OpenEventDetail
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(exports, "SearchEventDetail", {
|
|
300
|
+
enumerable: true,
|
|
301
|
+
get: () => core.SearchEventDetail
|
|
302
|
+
});
|
|
303
|
+
Object.defineProperty(exports, "SelectEventDetail", {
|
|
304
|
+
enumerable: true,
|
|
305
|
+
get: () => core.SelectEventDetail
|
|
306
|
+
});
|
|
307
|
+
exports.Select = Select;
|
|
308
|
+
exports.default = Select;
|
|
309
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/Select.vue"],"sourcesContent":["<!--\n Smilodon Select Component for Vue 3\n \n A production-ready, accessible select component with advanced features:\n - Single and multi-select modes\n - Searchable with client or server-side filtering\n - Infinite scroll and virtual scrolling for large datasets\n - Grouped options\n - Custom rendering\n - Full keyboard navigation\n - WCAG 2.1 AAA compliant\n \n @example\n <Select\n :items=\"items\"\n v-model=\"selectedValue\"\n searchable\n placeholder=\"Select an option...\"\n />\n-->\n\n<template>\n <enhanced-select\n ref=\"selectRef\"\n :class=\"className\"\n :style=\"style\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue';\nimport {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n} from '@smilodon/core';\n\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n group?: string;\n [key: string]: any;\n}\n\nexport interface SelectProps {\n /** Array of items to display in the select */\n items?: SelectItem[];\n /** Grouped items (alternative to items) */\n groupedItems?: GroupedItem[];\n /** Selected value(s) - for v-model binding */\n modelValue?: string | number | (string | number)[];\n /** Default value for uncontrolled mode */\n defaultValue?: string | number | (string | number)[];\n /** Enable multi-select mode */\n multiple?: boolean;\n /** Enable search functionality */\n searchable?: boolean;\n /** Placeholder text */\n placeholder?: string;\n /** Disable the select */\n disabled?: boolean;\n /** Mark as required */\n required?: boolean;\n /** Show error state */\n error?: boolean;\n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n /** Number of items per page (for infinite scroll) */\n pageSize?: number;\n /** Enable virtual scrolling */\n virtualized?: boolean;\n /** Maximum number of selections (for multi-select) */\n maxSelections?: number;\n /** Dropdown placement */\n placement?: 'bottom' | 'top' | 'auto';\n /** Custom CSS class */\n className?: string;\n /** Custom inline styles */\n style?: Record<string, string>;\n}\n\nexport interface SelectEmits {\n /** Emitted when selection changes - for v-model */\n (e: 'update:modelValue', value: string | number | (string | number)[]): void;\n /** Emitted when selection changes with full details */\n (e: 'change', value: string | number | (string | number)[], selectedItems: SelectItem[]): void;\n /** Emitted when an item is selected */\n (e: 'select', item: SelectItem, index: number): void;\n /** Emitted when dropdown opens */\n (e: 'open'): void;\n /** Emitted when dropdown closes */\n (e: 'close'): void;\n /** Emitted when search query changes */\n (e: 'search', query: string): void;\n /** Emitted when more items are requested (infinite scroll) */\n (e: 'loadMore', page: number): void;\n /** Emitted when user creates a new item (if enabled) */\n (e: 'create', value: string): void;\n}\n\nconst props = withDefaults(defineProps<SelectProps>(), {\n items: () => [],\n multiple: false,\n searchable: false,\n disabled: false,\n required: false,\n error: false,\n infiniteScroll: false,\n pageSize: 50,\n virtualized: true,\n placement: 'auto',\n});\n\nconst emit = defineEmits<SelectEmits>();\n\nconst selectRef = ref<HTMLElement | null>(null);\nconst internalValue = ref<string | number | (string | number)[] | undefined>(\n props.defaultValue\n);\n\n// Check if component is controlled\nconst isControlled = computed(() => props.modelValue !== undefined);\n\n// Get current value\nconst currentValue = computed(() =>\n isControlled.value ? props.modelValue : internalValue.value\n);\n\n// Sync items to web component\nwatch(\n () => props.items,\n (newItems) => {\n if (selectRef.value && newItems) {\n (selectRef.value as any).setItems(newItems);\n }\n },\n { deep: true }\n);\n\n// Sync grouped items to web component\nwatch(\n () => props.groupedItems,\n (newGroups) => {\n if (selectRef.value && newGroups) {\n (selectRef.value as any).setGroupedItems(newGroups);\n }\n },\n { deep: true }\n);\n\n// Sync value to web component\nwatch(\n currentValue,\n (newValue) => {\n if (selectRef.value && newValue !== undefined) {\n const values = Array.isArray(newValue) ? newValue : [newValue];\n (selectRef.value as any).setSelectedValues(values);\n }\n },\n { immediate: true }\n);\n\n// Sync other props\nwatch(\n () => props.placeholder,\n (newPlaceholder) => {\n if (selectRef.value && newPlaceholder) {\n selectRef.value.setAttribute('placeholder', newPlaceholder);\n }\n }\n);\n\nwatch(\n () => props.disabled,\n (newDisabled) => {\n if (selectRef.value) {\n if (newDisabled) {\n selectRef.value.setAttribute('disabled', '');\n } else {\n selectRef.value.removeAttribute('disabled');\n }\n }\n }\n);\n\nwatch(\n () => props.searchable,\n (newSearchable) => {\n if (selectRef.value) {\n if (newSearchable) {\n selectRef.value.setAttribute('searchable', '');\n } else {\n selectRef.value.removeAttribute('searchable');\n }\n }\n }\n);\n\nwatch(\n () => props.multiple,\n (newMultiple) => {\n if (selectRef.value) {\n if (newMultiple) {\n selectRef.value.setAttribute('multiple', '');\n } else {\n selectRef.value.removeAttribute('multiple');\n }\n }\n }\n);\n\nwatch(\n () => props.virtualized,\n (newVirtualized) => {\n if (selectRef.value) {\n if (newVirtualized) {\n selectRef.value.setAttribute('virtualized', '');\n } else {\n selectRef.value.removeAttribute('virtualized');\n }\n }\n }\n);\n\n// Event handlers\nconst handleSelect = (e: Event) => {\n const customEvent = e as CustomEvent<SelectEventDetail>;\n const { item, index } = customEvent.detail;\n emit('select', item as SelectItem, index);\n};\n\nconst handleChange = (e: Event) => {\n const customEvent = e as CustomEvent<ChangeEventDetail>;\n const { selectedItems, selectedValues } = customEvent.detail;\n\n const values = selectedValues as (string | number)[];\n\n // Update internal value in uncontrolled mode\n if (!isControlled.value) {\n internalValue.value = props.multiple ? values : values[0];\n }\n\n // Emit events\n const value = props.multiple ? values : values[0];\n emit('update:modelValue', value);\n emit('change', value, selectedItems as SelectItem[]);\n};\n\nconst handleOpen = () => {\n emit('open');\n};\n\nconst handleClose = () => {\n emit('close');\n};\n\nconst handleSearch = (e: Event) => {\n const customEvent = e as CustomEvent<SearchEventDetail>;\n emit('search', customEvent.detail.query);\n};\n\nconst handleLoadMore = (e: Event) => {\n const customEvent = e as CustomEvent<LoadMoreEventDetail>;\n emit('loadMore', customEvent.detail.page);\n};\n\nconst handleCreate = (e: Event) => {\n const customEvent = e as CustomEvent<{ value: string }>;\n emit('create', customEvent.detail.value);\n};\n\n// Setup event listeners\nonMounted(() => {\n if (!selectRef.value) return;\n\n const element = selectRef.value;\n\n // Set initial attributes\n if (props.placeholder) {\n element.setAttribute('placeholder', props.placeholder);\n }\n if (props.disabled) {\n element.setAttribute('disabled', '');\n }\n if (props.required) {\n element.setAttribute('required', '');\n }\n if (props.error) {\n element.setAttribute('error', '');\n }\n if (props.searchable) {\n element.setAttribute('searchable', '');\n }\n if (props.multiple) {\n element.setAttribute('multiple', '');\n }\n if (props.virtualized) {\n element.setAttribute('virtualized', '');\n }\n if (props.infiniteScroll) {\n element.setAttribute('infinite-scroll', '');\n }\n if (props.pageSize) {\n element.setAttribute('page-size', String(props.pageSize));\n }\n if (props.maxSelections) {\n element.setAttribute('max-selections', String(props.maxSelections));\n }\n if (props.placement) {\n element.setAttribute('placement', props.placement);\n }\n\n // Set initial items\n if (props.items?.length) {\n (element as any).setItems(props.items);\n }\n if (props.groupedItems?.length) {\n (element as any).setGroupedItems(props.groupedItems);\n }\n\n // Set initial value\n if (currentValue.value !== undefined) {\n const values = Array.isArray(currentValue.value)\n ? currentValue.value\n : [currentValue.value];\n (element as any).setSelectedValues(values);\n }\n\n // Add event listeners\n element.addEventListener('select', handleSelect as EventListener);\n element.addEventListener('change', handleChange as EventListener);\n element.addEventListener('open', handleOpen as EventListener);\n element.addEventListener('close', handleClose as EventListener);\n element.addEventListener('search', handleSearch as EventListener);\n element.addEventListener('loadMore', handleLoadMore as EventListener);\n element.addEventListener('create', handleCreate as EventListener);\n});\n\nonBeforeUnmount(() => {\n if (!selectRef.value) return;\n\n const element = selectRef.value;\n\n // Remove event listeners\n element.removeEventListener('select', handleSelect as EventListener);\n element.removeEventListener('change', handleChange as EventListener);\n element.removeEventListener('open', handleOpen as EventListener);\n element.removeEventListener('close', handleClose as EventListener);\n element.removeEventListener('search', handleSearch as EventListener);\n element.removeEventListener('loadMore', handleLoadMore as EventListener);\n element.removeEventListener('create', handleCreate as EventListener);\n});\n\n// Expose imperative API\ndefineExpose({\n /** Open the dropdown */\n open: () => {\n (selectRef.value as any)?.open();\n },\n /** Close the dropdown */\n close: () => {\n (selectRef.value as any)?.close();\n },\n /** Focus the select */\n focus: () => {\n selectRef.value?.focus();\n },\n /** Set items programmatically */\n setItems: (items: SelectItem[]) => {\n (selectRef.value as any)?.setItems(items);\n },\n /** Set grouped items programmatically */\n setGroupedItems: (groups: GroupedItem[]) => {\n (selectRef.value as any)?.setGroupedItems(groups);\n },\n /** Clear selection */\n clear: () => {\n (selectRef.value as any)?.setSelectedValues([]);\n if (!isControlled.value) {\n internalValue.value = props.multiple ? [] : undefined;\n }\n const value = props.multiple ? [] : '';\n emit('update:modelValue', value);\n emit('change', value, []);\n },\n});\n</script>\n\n<style scoped>\n/* Component uses web component styling from @smilodon/core */\n</style>\n"],"names":["ref","computed","watch","onMounted","onBeforeUnmount","_createBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,UAAM,QAAQ;AAad,UAAM,OAAO;AAEb,UAAM,YAAYA,IAAAA,IAAwB,IAAI;AAC9C,UAAM,gBAAgBA,IAAAA;AAAAA,MACpB,MAAM;AAAA,IAAA;AAIR,UAAM,eAAeC,IAAAA,SAAS,MAAM,MAAM,eAAe,MAAS;AAGlE,UAAM,eAAeA,IAAAA;AAAAA,MAAS,MAC5B,aAAa,QAAQ,MAAM,aAAa,cAAc;AAAA,IAAA;AAIxDC,QAAAA;AAAAA,MACE,MAAM,MAAM;AAAA,MACZ,CAAC,aAAa;AACZ,YAAI,UAAU,SAA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AM,QAAQ,MAAM,WAAW,CAAA,IAAK;AACpC,aAAK,qBAAqB,KAAK;AAC/B,aAAK,UAAU,OAAO,EAAE;AAAA,MAC1B;AAAA,IAAA,CACD;;;8BAhXCC,IAAAA,YAIE,4BAAA;AAAA,iBAHI;AAAA,QAAJ,KAAI;AAAA,QACH,0BAAO,QAAA,SAAS;AAAA,QAChB,0BAAO,QAAA,KAAK;AAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, watch, onMounted, onBeforeUnmount, resolveComponent, createBlock, openBlock, normalizeStyle, normalizeClass } from "vue";
|
|
2
|
+
import { ChangeEventDetail, CloseEventDetail, GroupedItem, LoadMoreEventDetail, OpenEventDetail, SearchEventDetail, SelectEventDetail } from "@smilodon/core";
|
|
3
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
4
|
+
__name: "Select",
|
|
5
|
+
props: {
|
|
6
|
+
items: { default: () => [] },
|
|
7
|
+
groupedItems: {},
|
|
8
|
+
modelValue: {},
|
|
9
|
+
defaultValue: {},
|
|
10
|
+
multiple: { type: Boolean, default: false },
|
|
11
|
+
searchable: { type: Boolean, default: false },
|
|
12
|
+
placeholder: {},
|
|
13
|
+
disabled: { type: Boolean, default: false },
|
|
14
|
+
required: { type: Boolean, default: false },
|
|
15
|
+
error: { type: Boolean, default: false },
|
|
16
|
+
infiniteScroll: { type: Boolean, default: false },
|
|
17
|
+
pageSize: { default: 50 },
|
|
18
|
+
virtualized: { type: Boolean, default: true },
|
|
19
|
+
maxSelections: {},
|
|
20
|
+
placement: { default: "auto" },
|
|
21
|
+
className: {},
|
|
22
|
+
style: {}
|
|
23
|
+
},
|
|
24
|
+
emits: ["update:modelValue", "change", "select", "open", "close", "search", "loadMore", "create"],
|
|
25
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
26
|
+
const props = __props;
|
|
27
|
+
const emit = __emit;
|
|
28
|
+
const selectRef = ref(null);
|
|
29
|
+
const internalValue = ref(
|
|
30
|
+
props.defaultValue
|
|
31
|
+
);
|
|
32
|
+
const isControlled = computed(() => props.modelValue !== void 0);
|
|
33
|
+
const currentValue = computed(
|
|
34
|
+
() => isControlled.value ? props.modelValue : internalValue.value
|
|
35
|
+
);
|
|
36
|
+
watch(
|
|
37
|
+
() => props.items,
|
|
38
|
+
(newItems) => {
|
|
39
|
+
if (selectRef.value && newItems) {
|
|
40
|
+
selectRef.value.setItems(newItems);
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
{ deep: true }
|
|
44
|
+
);
|
|
45
|
+
watch(
|
|
46
|
+
() => props.groupedItems,
|
|
47
|
+
(newGroups) => {
|
|
48
|
+
if (selectRef.value && newGroups) {
|
|
49
|
+
selectRef.value.setGroupedItems(newGroups);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{ deep: true }
|
|
53
|
+
);
|
|
54
|
+
watch(
|
|
55
|
+
currentValue,
|
|
56
|
+
(newValue) => {
|
|
57
|
+
if (selectRef.value && newValue !== void 0) {
|
|
58
|
+
const values = Array.isArray(newValue) ? newValue : [newValue];
|
|
59
|
+
selectRef.value.setSelectedValues(values);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{ immediate: true }
|
|
63
|
+
);
|
|
64
|
+
watch(
|
|
65
|
+
() => props.placeholder,
|
|
66
|
+
(newPlaceholder) => {
|
|
67
|
+
if (selectRef.value && newPlaceholder) {
|
|
68
|
+
selectRef.value.setAttribute("placeholder", newPlaceholder);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
watch(
|
|
73
|
+
() => props.disabled,
|
|
74
|
+
(newDisabled) => {
|
|
75
|
+
if (selectRef.value) {
|
|
76
|
+
if (newDisabled) {
|
|
77
|
+
selectRef.value.setAttribute("disabled", "");
|
|
78
|
+
} else {
|
|
79
|
+
selectRef.value.removeAttribute("disabled");
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
watch(
|
|
85
|
+
() => props.searchable,
|
|
86
|
+
(newSearchable) => {
|
|
87
|
+
if (selectRef.value) {
|
|
88
|
+
if (newSearchable) {
|
|
89
|
+
selectRef.value.setAttribute("searchable", "");
|
|
90
|
+
} else {
|
|
91
|
+
selectRef.value.removeAttribute("searchable");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
watch(
|
|
97
|
+
() => props.multiple,
|
|
98
|
+
(newMultiple) => {
|
|
99
|
+
if (selectRef.value) {
|
|
100
|
+
if (newMultiple) {
|
|
101
|
+
selectRef.value.setAttribute("multiple", "");
|
|
102
|
+
} else {
|
|
103
|
+
selectRef.value.removeAttribute("multiple");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
watch(
|
|
109
|
+
() => props.virtualized,
|
|
110
|
+
(newVirtualized) => {
|
|
111
|
+
if (selectRef.value) {
|
|
112
|
+
if (newVirtualized) {
|
|
113
|
+
selectRef.value.setAttribute("virtualized", "");
|
|
114
|
+
} else {
|
|
115
|
+
selectRef.value.removeAttribute("virtualized");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
);
|
|
120
|
+
const handleSelect = (e) => {
|
|
121
|
+
const customEvent = e;
|
|
122
|
+
const { item, index } = customEvent.detail;
|
|
123
|
+
emit("select", item, index);
|
|
124
|
+
};
|
|
125
|
+
const handleChange = (e) => {
|
|
126
|
+
const customEvent = e;
|
|
127
|
+
const { selectedItems, selectedValues } = customEvent.detail;
|
|
128
|
+
const values = selectedValues;
|
|
129
|
+
if (!isControlled.value) {
|
|
130
|
+
internalValue.value = props.multiple ? values : values[0];
|
|
131
|
+
}
|
|
132
|
+
const value = props.multiple ? values : values[0];
|
|
133
|
+
emit("update:modelValue", value);
|
|
134
|
+
emit("change", value, selectedItems);
|
|
135
|
+
};
|
|
136
|
+
const handleOpen = () => {
|
|
137
|
+
emit("open");
|
|
138
|
+
};
|
|
139
|
+
const handleClose = () => {
|
|
140
|
+
emit("close");
|
|
141
|
+
};
|
|
142
|
+
const handleSearch = (e) => {
|
|
143
|
+
const customEvent = e;
|
|
144
|
+
emit("search", customEvent.detail.query);
|
|
145
|
+
};
|
|
146
|
+
const handleLoadMore = (e) => {
|
|
147
|
+
const customEvent = e;
|
|
148
|
+
emit("loadMore", customEvent.detail.page);
|
|
149
|
+
};
|
|
150
|
+
const handleCreate = (e) => {
|
|
151
|
+
const customEvent = e;
|
|
152
|
+
emit("create", customEvent.detail.value);
|
|
153
|
+
};
|
|
154
|
+
onMounted(() => {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
if (!selectRef.value) return;
|
|
157
|
+
const element = selectRef.value;
|
|
158
|
+
if (props.placeholder) {
|
|
159
|
+
element.setAttribute("placeholder", props.placeholder);
|
|
160
|
+
}
|
|
161
|
+
if (props.disabled) {
|
|
162
|
+
element.setAttribute("disabled", "");
|
|
163
|
+
}
|
|
164
|
+
if (props.required) {
|
|
165
|
+
element.setAttribute("required", "");
|
|
166
|
+
}
|
|
167
|
+
if (props.error) {
|
|
168
|
+
element.setAttribute("error", "");
|
|
169
|
+
}
|
|
170
|
+
if (props.searchable) {
|
|
171
|
+
element.setAttribute("searchable", "");
|
|
172
|
+
}
|
|
173
|
+
if (props.multiple) {
|
|
174
|
+
element.setAttribute("multiple", "");
|
|
175
|
+
}
|
|
176
|
+
if (props.virtualized) {
|
|
177
|
+
element.setAttribute("virtualized", "");
|
|
178
|
+
}
|
|
179
|
+
if (props.infiniteScroll) {
|
|
180
|
+
element.setAttribute("infinite-scroll", "");
|
|
181
|
+
}
|
|
182
|
+
if (props.pageSize) {
|
|
183
|
+
element.setAttribute("page-size", String(props.pageSize));
|
|
184
|
+
}
|
|
185
|
+
if (props.maxSelections) {
|
|
186
|
+
element.setAttribute("max-selections", String(props.maxSelections));
|
|
187
|
+
}
|
|
188
|
+
if (props.placement) {
|
|
189
|
+
element.setAttribute("placement", props.placement);
|
|
190
|
+
}
|
|
191
|
+
if ((_a = props.items) == null ? void 0 : _a.length) {
|
|
192
|
+
element.setItems(props.items);
|
|
193
|
+
}
|
|
194
|
+
if ((_b = props.groupedItems) == null ? void 0 : _b.length) {
|
|
195
|
+
element.setGroupedItems(props.groupedItems);
|
|
196
|
+
}
|
|
197
|
+
if (currentValue.value !== void 0) {
|
|
198
|
+
const values = Array.isArray(currentValue.value) ? currentValue.value : [currentValue.value];
|
|
199
|
+
element.setSelectedValues(values);
|
|
200
|
+
}
|
|
201
|
+
element.addEventListener("select", handleSelect);
|
|
202
|
+
element.addEventListener("change", handleChange);
|
|
203
|
+
element.addEventListener("open", handleOpen);
|
|
204
|
+
element.addEventListener("close", handleClose);
|
|
205
|
+
element.addEventListener("search", handleSearch);
|
|
206
|
+
element.addEventListener("loadMore", handleLoadMore);
|
|
207
|
+
element.addEventListener("create", handleCreate);
|
|
208
|
+
});
|
|
209
|
+
onBeforeUnmount(() => {
|
|
210
|
+
if (!selectRef.value) return;
|
|
211
|
+
const element = selectRef.value;
|
|
212
|
+
element.removeEventListener("select", handleSelect);
|
|
213
|
+
element.removeEventListener("change", handleChange);
|
|
214
|
+
element.removeEventListener("open", handleOpen);
|
|
215
|
+
element.removeEventListener("close", handleClose);
|
|
216
|
+
element.removeEventListener("search", handleSearch);
|
|
217
|
+
element.removeEventListener("loadMore", handleLoadMore);
|
|
218
|
+
element.removeEventListener("create", handleCreate);
|
|
219
|
+
});
|
|
220
|
+
__expose({
|
|
221
|
+
/** Open the dropdown */
|
|
222
|
+
open: () => {
|
|
223
|
+
var _a;
|
|
224
|
+
(_a = selectRef.value) == null ? void 0 : _a.open();
|
|
225
|
+
},
|
|
226
|
+
/** Close the dropdown */
|
|
227
|
+
close: () => {
|
|
228
|
+
var _a;
|
|
229
|
+
(_a = selectRef.value) == null ? void 0 : _a.close();
|
|
230
|
+
},
|
|
231
|
+
/** Focus the select */
|
|
232
|
+
focus: () => {
|
|
233
|
+
var _a;
|
|
234
|
+
(_a = selectRef.value) == null ? void 0 : _a.focus();
|
|
235
|
+
},
|
|
236
|
+
/** Set items programmatically */
|
|
237
|
+
setItems: (items) => {
|
|
238
|
+
var _a;
|
|
239
|
+
(_a = selectRef.value) == null ? void 0 : _a.setItems(items);
|
|
240
|
+
},
|
|
241
|
+
/** Set grouped items programmatically */
|
|
242
|
+
setGroupedItems: (groups) => {
|
|
243
|
+
var _a;
|
|
244
|
+
(_a = selectRef.value) == null ? void 0 : _a.setGroupedItems(groups);
|
|
245
|
+
},
|
|
246
|
+
/** Clear selection */
|
|
247
|
+
clear: () => {
|
|
248
|
+
var _a;
|
|
249
|
+
(_a = selectRef.value) == null ? void 0 : _a.setSelectedValues([]);
|
|
250
|
+
if (!isControlled.value) {
|
|
251
|
+
internalValue.value = props.multiple ? [] : void 0;
|
|
252
|
+
}
|
|
253
|
+
const value = props.multiple ? [] : "";
|
|
254
|
+
emit("update:modelValue", value);
|
|
255
|
+
emit("change", value, []);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return (_ctx, _cache) => {
|
|
259
|
+
const _component_enhanced_select = resolveComponent("enhanced-select");
|
|
260
|
+
return openBlock(), createBlock(_component_enhanced_select, {
|
|
261
|
+
ref_key: "selectRef",
|
|
262
|
+
ref: selectRef,
|
|
263
|
+
class: normalizeClass(__props.className),
|
|
264
|
+
style: normalizeStyle(__props.style)
|
|
265
|
+
}, null, 8, ["class", "style"]);
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
const _export_sfc = (sfc, props) => {
|
|
270
|
+
const target = sfc.__vccOpts || sfc;
|
|
271
|
+
for (const [key, val] of props) {
|
|
272
|
+
target[key] = val;
|
|
273
|
+
}
|
|
274
|
+
return target;
|
|
275
|
+
};
|
|
276
|
+
const Select = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a2f90b1e"]]);
|
|
277
|
+
export {
|
|
278
|
+
ChangeEventDetail,
|
|
279
|
+
CloseEventDetail,
|
|
280
|
+
GroupedItem,
|
|
281
|
+
LoadMoreEventDetail,
|
|
282
|
+
OpenEventDetail,
|
|
283
|
+
SearchEventDetail,
|
|
284
|
+
Select,
|
|
285
|
+
SelectEventDetail,
|
|
286
|
+
Select as default
|
|
287
|
+
};
|
|
288
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/Select.vue"],"sourcesContent":["<!--\n Smilodon Select Component for Vue 3\n \n A production-ready, accessible select component with advanced features:\n - Single and multi-select modes\n - Searchable with client or server-side filtering\n - Infinite scroll and virtual scrolling for large datasets\n - Grouped options\n - Custom rendering\n - Full keyboard navigation\n - WCAG 2.1 AAA compliant\n \n @example\n <Select\n :items=\"items\"\n v-model=\"selectedValue\"\n searchable\n placeholder=\"Select an option...\"\n />\n-->\n\n<template>\n <enhanced-select\n ref=\"selectRef\"\n :class=\"className\"\n :style=\"style\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, watch, onMounted, onBeforeUnmount, computed } from 'vue';\nimport {\n SelectEventDetail,\n OpenEventDetail,\n CloseEventDetail,\n SearchEventDetail,\n ChangeEventDetail,\n LoadMoreEventDetail,\n GroupedItem,\n} from '@smilodon/core';\n\nexport interface SelectItem {\n value: string | number;\n label: string;\n disabled?: boolean;\n group?: string;\n [key: string]: any;\n}\n\nexport interface SelectProps {\n /** Array of items to display in the select */\n items?: SelectItem[];\n /** Grouped items (alternative to items) */\n groupedItems?: GroupedItem[];\n /** Selected value(s) - for v-model binding */\n modelValue?: string | number | (string | number)[];\n /** Default value for uncontrolled mode */\n defaultValue?: string | number | (string | number)[];\n /** Enable multi-select mode */\n multiple?: boolean;\n /** Enable search functionality */\n searchable?: boolean;\n /** Placeholder text */\n placeholder?: string;\n /** Disable the select */\n disabled?: boolean;\n /** Mark as required */\n required?: boolean;\n /** Show error state */\n error?: boolean;\n /** Enable infinite scroll */\n infiniteScroll?: boolean;\n /** Number of items per page (for infinite scroll) */\n pageSize?: number;\n /** Enable virtual scrolling */\n virtualized?: boolean;\n /** Maximum number of selections (for multi-select) */\n maxSelections?: number;\n /** Dropdown placement */\n placement?: 'bottom' | 'top' | 'auto';\n /** Custom CSS class */\n className?: string;\n /** Custom inline styles */\n style?: Record<string, string>;\n}\n\nexport interface SelectEmits {\n /** Emitted when selection changes - for v-model */\n (e: 'update:modelValue', value: string | number | (string | number)[]): void;\n /** Emitted when selection changes with full details */\n (e: 'change', value: string | number | (string | number)[], selectedItems: SelectItem[]): void;\n /** Emitted when an item is selected */\n (e: 'select', item: SelectItem, index: number): void;\n /** Emitted when dropdown opens */\n (e: 'open'): void;\n /** Emitted when dropdown closes */\n (e: 'close'): void;\n /** Emitted when search query changes */\n (e: 'search', query: string): void;\n /** Emitted when more items are requested (infinite scroll) */\n (e: 'loadMore', page: number): void;\n /** Emitted when user creates a new item (if enabled) */\n (e: 'create', value: string): void;\n}\n\nconst props = withDefaults(defineProps<SelectProps>(), {\n items: () => [],\n multiple: false,\n searchable: false,\n disabled: false,\n required: false,\n error: false,\n infiniteScroll: false,\n pageSize: 50,\n virtualized: true,\n placement: 'auto',\n});\n\nconst emit = defineEmits<SelectEmits>();\n\nconst selectRef = ref<HTMLElement | null>(null);\nconst internalValue = ref<string | number | (string | number)[] | undefined>(\n props.defaultValue\n);\n\n// Check if component is controlled\nconst isControlled = computed(() => props.modelValue !== undefined);\n\n// Get current value\nconst currentValue = computed(() =>\n isControlled.value ? props.modelValue : internalValue.value\n);\n\n// Sync items to web component\nwatch(\n () => props.items,\n (newItems) => {\n if (selectRef.value && newItems) {\n (selectRef.value as any).setItems(newItems);\n }\n },\n { deep: true }\n);\n\n// Sync grouped items to web component\nwatch(\n () => props.groupedItems,\n (newGroups) => {\n if (selectRef.value && newGroups) {\n (selectRef.value as any).setGroupedItems(newGroups);\n }\n },\n { deep: true }\n);\n\n// Sync value to web component\nwatch(\n currentValue,\n (newValue) => {\n if (selectRef.value && newValue !== undefined) {\n const values = Array.isArray(newValue) ? newValue : [newValue];\n (selectRef.value as any).setSelectedValues(values);\n }\n },\n { immediate: true }\n);\n\n// Sync other props\nwatch(\n () => props.placeholder,\n (newPlaceholder) => {\n if (selectRef.value && newPlaceholder) {\n selectRef.value.setAttribute('placeholder', newPlaceholder);\n }\n }\n);\n\nwatch(\n () => props.disabled,\n (newDisabled) => {\n if (selectRef.value) {\n if (newDisabled) {\n selectRef.value.setAttribute('disabled', '');\n } else {\n selectRef.value.removeAttribute('disabled');\n }\n }\n }\n);\n\nwatch(\n () => props.searchable,\n (newSearchable) => {\n if (selectRef.value) {\n if (newSearchable) {\n selectRef.value.setAttribute('searchable', '');\n } else {\n selectRef.value.removeAttribute('searchable');\n }\n }\n }\n);\n\nwatch(\n () => props.multiple,\n (newMultiple) => {\n if (selectRef.value) {\n if (newMultiple) {\n selectRef.value.setAttribute('multiple', '');\n } else {\n selectRef.value.removeAttribute('multiple');\n }\n }\n }\n);\n\nwatch(\n () => props.virtualized,\n (newVirtualized) => {\n if (selectRef.value) {\n if (newVirtualized) {\n selectRef.value.setAttribute('virtualized', '');\n } else {\n selectRef.value.removeAttribute('virtualized');\n }\n }\n }\n);\n\n// Event handlers\nconst handleSelect = (e: Event) => {\n const customEvent = e as CustomEvent<SelectEventDetail>;\n const { item, index } = customEvent.detail;\n emit('select', item as SelectItem, index);\n};\n\nconst handleChange = (e: Event) => {\n const customEvent = e as CustomEvent<ChangeEventDetail>;\n const { selectedItems, selectedValues } = customEvent.detail;\n\n const values = selectedValues as (string | number)[];\n\n // Update internal value in uncontrolled mode\n if (!isControlled.value) {\n internalValue.value = props.multiple ? values : values[0];\n }\n\n // Emit events\n const value = props.multiple ? values : values[0];\n emit('update:modelValue', value);\n emit('change', value, selectedItems as SelectItem[]);\n};\n\nconst handleOpen = () => {\n emit('open');\n};\n\nconst handleClose = () => {\n emit('close');\n};\n\nconst handleSearch = (e: Event) => {\n const customEvent = e as CustomEvent<SearchEventDetail>;\n emit('search', customEvent.detail.query);\n};\n\nconst handleLoadMore = (e: Event) => {\n const customEvent = e as CustomEvent<LoadMoreEventDetail>;\n emit('loadMore', customEvent.detail.page);\n};\n\nconst handleCreate = (e: Event) => {\n const customEvent = e as CustomEvent<{ value: string }>;\n emit('create', customEvent.detail.value);\n};\n\n// Setup event listeners\nonMounted(() => {\n if (!selectRef.value) return;\n\n const element = selectRef.value;\n\n // Set initial attributes\n if (props.placeholder) {\n element.setAttribute('placeholder', props.placeholder);\n }\n if (props.disabled) {\n element.setAttribute('disabled', '');\n }\n if (props.required) {\n element.setAttribute('required', '');\n }\n if (props.error) {\n element.setAttribute('error', '');\n }\n if (props.searchable) {\n element.setAttribute('searchable', '');\n }\n if (props.multiple) {\n element.setAttribute('multiple', '');\n }\n if (props.virtualized) {\n element.setAttribute('virtualized', '');\n }\n if (props.infiniteScroll) {\n element.setAttribute('infinite-scroll', '');\n }\n if (props.pageSize) {\n element.setAttribute('page-size', String(props.pageSize));\n }\n if (props.maxSelections) {\n element.setAttribute('max-selections', String(props.maxSelections));\n }\n if (props.placement) {\n element.setAttribute('placement', props.placement);\n }\n\n // Set initial items\n if (props.items?.length) {\n (element as any).setItems(props.items);\n }\n if (props.groupedItems?.length) {\n (element as any).setGroupedItems(props.groupedItems);\n }\n\n // Set initial value\n if (currentValue.value !== undefined) {\n const values = Array.isArray(currentValue.value)\n ? currentValue.value\n : [currentValue.value];\n (element as any).setSelectedValues(values);\n }\n\n // Add event listeners\n element.addEventListener('select', handleSelect as EventListener);\n element.addEventListener('change', handleChange as EventListener);\n element.addEventListener('open', handleOpen as EventListener);\n element.addEventListener('close', handleClose as EventListener);\n element.addEventListener('search', handleSearch as EventListener);\n element.addEventListener('loadMore', handleLoadMore as EventListener);\n element.addEventListener('create', handleCreate as EventListener);\n});\n\nonBeforeUnmount(() => {\n if (!selectRef.value) return;\n\n const element = selectRef.value;\n\n // Remove event listeners\n element.removeEventListener('select', handleSelect as EventListener);\n element.removeEventListener('change', handleChange as EventListener);\n element.removeEventListener('open', handleOpen as EventListener);\n element.removeEventListener('close', handleClose as EventListener);\n element.removeEventListener('search', handleSearch as EventListener);\n element.removeEventListener('loadMore', handleLoadMore as EventListener);\n element.removeEventListener('create', handleCreate as EventListener);\n});\n\n// Expose imperative API\ndefineExpose({\n /** Open the dropdown */\n open: () => {\n (selectRef.value as any)?.open();\n },\n /** Close the dropdown */\n close: () => {\n (selectRef.value as any)?.close();\n },\n /** Focus the select */\n focus: () => {\n selectRef.value?.focus();\n },\n /** Set items programmatically */\n setItems: (items: SelectItem[]) => {\n (selectRef.value as any)?.setItems(items);\n },\n /** Set grouped items programmatically */\n setGroupedItems: (groups: GroupedItem[]) => {\n (selectRef.value as any)?.setGroupedItems(groups);\n },\n /** Clear selection */\n clear: () => {\n (selectRef.value as any)?.setSelectedValues([]);\n if (!isControlled.value) {\n internalValue.value = props.multiple ? [] : undefined;\n }\n const value = props.multiple ? [] : '';\n emit('update:modelValue', value);\n emit('change', value, []);\n },\n});\n</script>\n\n<style scoped>\n/* Component uses web component styling from @smilodon/core */\n</style>\n"],"names":["_createBlock"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,UAAM,QAAQ;AAad,UAAM,OAAO;AAEb,UAAM,YAAY,IAAwB,IAAI;AAC9C,UAAM,gBAAgB;AAAA,MACpB,MAAM;AAAA,IAAA;AAIR,UAAM,eAAe,SAAS,MAAM,MAAM,eAAe,MAAS;AAGlE,UAAM,eAAe;AAAA,MAAS,MAC5B,aAAa,QAAQ,MAAM,aAAa,cAAc;AAAA,IAAA;AAIxD;AAAA,MACE,MAAM,MAAM;AAAA,MACZ,CAAC,aAAa;AACZ,YAAI,UAAU,SAAS,UAAU;AAC9B,oBAAU,MAAc,SAAS,QAAQ;AAAA,QAC5C;AAAA,MACF;AAAA,MACA,EAAE,MAAM,KAAA;AAAA,IAAK;AAIf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,QAAA,SAAS;AAAA,QAChB,sBAAO,QAAA,KAAK;AAAA,MAAA;;;;;;;;;;;;"}
|
package/dist/style.css
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smilodon/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue 3 adapter for @smilodon/core - Production-ready accessible select component",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/types/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"types": "./dist/types/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "vue-tsc --declaration --emitDeclarationOnly --outDir dist/types && vite build && node scripts/cleanup-types.js",
|
|
22
|
+
"size": "gzip -c dist/index.js | wc -c",
|
|
23
|
+
"prepublishOnly": "npm run build"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@smilodon/core": "^1.0.0",
|
|
27
|
+
"vue": "^3.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@vitejs/plugin-vue": "^5.0.0",
|
|
31
|
+
"typescript": "^5.6.2",
|
|
32
|
+
"vite": "^5.4.21",
|
|
33
|
+
"vue": "^3.4.0",
|
|
34
|
+
"vue-tsc": "^2.2.12"
|
|
35
|
+
},
|
|
36
|
+
"keywords": [
|
|
37
|
+
"vue",
|
|
38
|
+
"vue3",
|
|
39
|
+
"select",
|
|
40
|
+
"dropdown",
|
|
41
|
+
"combobox",
|
|
42
|
+
"autocomplete",
|
|
43
|
+
"searchable",
|
|
44
|
+
"multi-select",
|
|
45
|
+
"virtualization",
|
|
46
|
+
"infinite-scroll",
|
|
47
|
+
"accessible",
|
|
48
|
+
"wcag",
|
|
49
|
+
"aria",
|
|
50
|
+
"typescript",
|
|
51
|
+
"web-components",
|
|
52
|
+
"composition-api"
|
|
53
|
+
],
|
|
54
|
+
"license": "MIT",
|
|
55
|
+
"author": "Navid Rezadoost <navidrezadoost07@gmail.com>",
|
|
56
|
+
"sideEffects": false,
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "git+https://github.com/navidrezadoost/smilodon.git",
|
|
60
|
+
"directory": "packages/vue"
|
|
61
|
+
},
|
|
62
|
+
"bugs": {
|
|
63
|
+
"url": "https://github.com/navidrezadoost/smilodon/issues"
|
|
64
|
+
},
|
|
65
|
+
"homepage": "https://github.com/navidrezadoost/smilodon#readme",
|
|
66
|
+
"engines": {
|
|
67
|
+
"node": ">=18",
|
|
68
|
+
"npm": ">=9"
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public",
|
|
72
|
+
"registry": "https://registry.npmjs.org/"
|
|
73
|
+
}
|
|
74
|
+
}
|