vue-command-kit 0.1.0 → 0.1.1
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 +140 -19
- package/dist/index.d.ts +9 -9
- package/dist/injectionKeys.d.ts +1 -0
- package/dist/types.d.ts +5 -0
- package/dist/useCommandRoot.d.ts +19 -0
- package/dist/utils/injectStrict.d.ts +8 -0
- package/dist/vue-cmdk.js +327 -295
- package/dist/vue-cmdk.umd.cjs +1 -1
- package/package.json +20 -10
package/README.md
CHANGED
|
@@ -11,7 +11,9 @@
|
|
|
11
11
|
Press <kbd>⌘K</kbd> and take control.
|
|
12
12
|
</p>
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
<p align="center">
|
|
15
|
+
<img src="./demo.gif" alt="vue-cmdk demo" width="720">
|
|
16
|
+
</p>
|
|
15
17
|
|
|
16
18
|
## 🧠 Inspiration
|
|
17
19
|
|
|
@@ -171,26 +173,92 @@ npm install vue-command-kit
|
|
|
171
173
|
</template>
|
|
172
174
|
```
|
|
173
175
|
|
|
176
|
+
### With v-model:searchQuery
|
|
177
|
+
|
|
178
|
+
```vue
|
|
179
|
+
<script setup lang="ts">
|
|
180
|
+
import { ref } from 'vue'
|
|
181
|
+
import { Command } from 'vue-command-kit'
|
|
182
|
+
import type { CommandItemData } from 'vue-command-kit'
|
|
183
|
+
|
|
184
|
+
const visible = ref(false)
|
|
185
|
+
const query = ref('')
|
|
186
|
+
|
|
187
|
+
const items: CommandItemData[] = [
|
|
188
|
+
{ value: 'home', label: 'Home', keywords: ['dashboard'] },
|
|
189
|
+
{ value: 'settings', label: 'Settings' },
|
|
190
|
+
]
|
|
191
|
+
</script>
|
|
192
|
+
|
|
193
|
+
<template>
|
|
194
|
+
<Command.Dialog
|
|
195
|
+
:visible="visible"
|
|
196
|
+
:items="items"
|
|
197
|
+
v-model:searchQuery="query"
|
|
198
|
+
@update:visible="visible = $event"
|
|
199
|
+
/>
|
|
200
|
+
</template>
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Async data + loading
|
|
204
|
+
|
|
205
|
+
```vue
|
|
206
|
+
<script setup lang="ts">
|
|
207
|
+
import { ref, watch } from 'vue'
|
|
208
|
+
import { Command } from 'vue-command-kit'
|
|
209
|
+
import type { CommandItemData } from 'vue-command-kit'
|
|
210
|
+
|
|
211
|
+
const visible = ref(false)
|
|
212
|
+
const loading = ref(false)
|
|
213
|
+
const items = ref<CommandItemData[]>([])
|
|
214
|
+
|
|
215
|
+
watch(visible, async (v) => {
|
|
216
|
+
if (v) {
|
|
217
|
+
loading.value = true
|
|
218
|
+
const data = await fetch('/api/commands').then((r) => r.json())
|
|
219
|
+
items.value = data.map((d: any) => ({
|
|
220
|
+
value: d.id,
|
|
221
|
+
label: d.name,
|
|
222
|
+
group: d.category,
|
|
223
|
+
}))
|
|
224
|
+
loading.value = false
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
</script>
|
|
228
|
+
|
|
229
|
+
<template>
|
|
230
|
+
<Command.Dialog
|
|
231
|
+
:visible="visible"
|
|
232
|
+
:items="items"
|
|
233
|
+
:loading="loading"
|
|
234
|
+
@update:visible="visible = $event"
|
|
235
|
+
@select="console.log('selected', $event)"
|
|
236
|
+
/>
|
|
237
|
+
</template>
|
|
238
|
+
```
|
|
239
|
+
|
|
174
240
|
## 📖 API
|
|
175
241
|
|
|
176
242
|
### `<Command.Dialog>` Props
|
|
177
243
|
|
|
178
|
-
| Prop | Type | Default | Description
|
|
179
|
-
| --------------- | ------------------- | --------------------- |
|
|
180
|
-
| `visible` | `boolean` | `false` | Controlled open state
|
|
181
|
-
| `items` | `CommandItemData[]` | `[]` | Items to display
|
|
182
|
-
| `
|
|
183
|
-
| `
|
|
184
|
-
| `
|
|
185
|
-
| `
|
|
186
|
-
| `
|
|
244
|
+
| Prop | Type | Default | Description |
|
|
245
|
+
| --------------- | ------------------- | --------------------- | ------------------------------------ |
|
|
246
|
+
| `visible` | `boolean` | `false` | Controlled open state |
|
|
247
|
+
| `items` | `CommandItemData[]` | `[]` | Items to display |
|
|
248
|
+
| `searchQuery` | `string` | `''` | Search query (`v-model:searchQuery`) |
|
|
249
|
+
| `placeholder` | `string` | `'Type a command...'` | Input placeholder |
|
|
250
|
+
| `filter` | `FilterFn` | — | Custom filter function |
|
|
251
|
+
| `loading` | `boolean` | `false` | Show loading state |
|
|
252
|
+
| `autoFocus` | `boolean` | `true` | Auto-focus input on open |
|
|
253
|
+
| `closeOnSelect` | `boolean` | `true` | Close dialog after selection |
|
|
187
254
|
|
|
188
255
|
### `<Command.Dialog>` Events
|
|
189
256
|
|
|
190
|
-
| Event
|
|
191
|
-
|
|
|
192
|
-
| `update:visible`
|
|
193
|
-
| `
|
|
257
|
+
| Event | Payload | Description |
|
|
258
|
+
| -------------------- | ----------------- | --------------------------------- |
|
|
259
|
+
| `update:visible` | `boolean` | Emitted when visibility changes |
|
|
260
|
+
| `update:searchQuery` | `string` | Emitted when search query changes |
|
|
261
|
+
| `select` | `CommandItemData` | Emitted when an item is selected |
|
|
194
262
|
|
|
195
263
|
### Components
|
|
196
264
|
|
|
@@ -245,16 +313,69 @@ menu.toggle()
|
|
|
245
313
|
|
|
246
314
|
## 🤝 Contributing
|
|
247
315
|
|
|
316
|
+
### Prerequisites
|
|
317
|
+
|
|
318
|
+
- **Node.js** >= 22.13
|
|
319
|
+
- **pnpm** >= 11.x
|
|
320
|
+
|
|
321
|
+
### Setup
|
|
322
|
+
|
|
248
323
|
```bash
|
|
249
|
-
#
|
|
324
|
+
# Clone the repo
|
|
325
|
+
git clone https://github.com/yvng-jie/vue-cmdk.git
|
|
326
|
+
cd vue-cmdk
|
|
327
|
+
|
|
328
|
+
# Install dependencies
|
|
329
|
+
pnpm install
|
|
330
|
+
|
|
331
|
+
# Start demo dev server
|
|
250
332
|
pnpm dev
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### Scripts
|
|
336
|
+
|
|
337
|
+
| Command | Description |
|
|
338
|
+
| ----------------- | ----------------------------------------- |
|
|
339
|
+
| `pnpm dev` | Start demo dev server at `localhost:5173` |
|
|
340
|
+
| `pnpm build` | Build the library + type declarations |
|
|
341
|
+
| `pnpm typecheck` | Run TypeScript type checking |
|
|
342
|
+
| `pnpm preview` | Preview production build |
|
|
343
|
+
| `pnpm build:demo` | Build demo site to `dist-demo/` |
|
|
251
344
|
|
|
252
|
-
|
|
253
|
-
pnpm typecheck
|
|
345
|
+
### Project Structure
|
|
254
346
|
|
|
255
|
-
# build
|
|
256
|
-
pnpm build
|
|
257
347
|
```
|
|
348
|
+
src/
|
|
349
|
+
├── useCommandMenu.ts # core composable (state, filter, shortcuts)
|
|
350
|
+
├── useCommandRoot.ts # shared composable (provide/inject wiring)
|
|
351
|
+
├── types.ts # TypeScript type definitions
|
|
352
|
+
├── injectionKeys.ts # provide/inject keys
|
|
353
|
+
├── utils/
|
|
354
|
+
│ └── injectStrict.ts # type-safe inject helper
|
|
355
|
+
├── CommandMenu.vue # inline command menu
|
|
356
|
+
├── CommandDialog.vue # modal dialog command palette
|
|
357
|
+
├── CommandInput.vue # search input
|
|
358
|
+
├── CommandList.vue # scrollable filtered list
|
|
359
|
+
├── CommandGroup.vue # group with heading
|
|
360
|
+
├── CommandItem.vue # single selectable item
|
|
361
|
+
├── CommandEmpty.vue # empty state
|
|
362
|
+
├── CommandSeparator.vue # visual separator
|
|
363
|
+
├── CommandLoading.vue # loading indicator
|
|
364
|
+
├── index.ts # barrel exports
|
|
365
|
+
└── env.d.ts # type shims
|
|
366
|
+
demo/
|
|
367
|
+
├── App.vue # demo application
|
|
368
|
+
├── main.ts # demo entry
|
|
369
|
+
└── style.css # demo styles
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Pull Request Process
|
|
373
|
+
|
|
374
|
+
1. Fork the repo and create a feature branch from `main`
|
|
375
|
+
2. Make your changes and run `pnpm typecheck && pnpm build`
|
|
376
|
+
3. Test your changes with `pnpm dev` (demo app)
|
|
377
|
+
4. Update `CHANGELOG.md` with a description of your changes
|
|
378
|
+
5. Submit a PR with a clear description of what and why
|
|
258
379
|
|
|
259
380
|
PRs and issues are welcome!
|
|
260
381
|
|
package/dist/index.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ export type * from './types'
|
|
|
6
6
|
import type { Component } from 'vue'
|
|
7
7
|
|
|
8
8
|
export const Command: {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
CommandMenu: Component
|
|
10
|
+
CommandDialog: Component
|
|
11
|
+
CommandInput: Component
|
|
12
|
+
CommandList: Component
|
|
13
|
+
CommandGroup: Component
|
|
14
|
+
CommandItem: Component
|
|
15
|
+
CommandEmpty: Component
|
|
16
|
+
CommandSeparator: Component
|
|
17
|
+
CommandLoading: Component
|
|
18
18
|
}
|
|
19
19
|
export const CommandMenu: Component
|
|
20
20
|
export const CommandDialog: Component
|
package/dist/injectionKeys.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export declare const CMDK_STATE: InjectionKey<UseCommandMenuReturn>;
|
|
|
5
5
|
export declare const CMDK_LOADING: InjectionKey<() => boolean>;
|
|
6
6
|
export declare const CMDK_CLOSE_ON_SELECT: InjectionKey<() => boolean>;
|
|
7
7
|
export declare const CMDK_SELECT_HANDLER: InjectionKey<(item: CommandItemData) => void>;
|
|
8
|
+
export declare const CMDK_ITEM_INDEX_MAP: InjectionKey<() => Map<string, number>>;
|
package/dist/types.d.ts
CHANGED
|
@@ -41,6 +41,11 @@ export interface CommandRootEmits {
|
|
|
41
41
|
(e: 'update:searchQuery', value: string): void;
|
|
42
42
|
(e: 'select', item: CommandItemData): void;
|
|
43
43
|
}
|
|
44
|
+
/** Props for CommandDialog — extends shared root props with items array */
|
|
45
|
+
export interface CommandDialogProps extends CommandRootProps {
|
|
46
|
+
/** Command items to display */
|
|
47
|
+
items?: CommandItemData[];
|
|
48
|
+
}
|
|
44
49
|
/** Group definition */
|
|
45
50
|
export interface CommandGroupData {
|
|
46
51
|
heading: string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CommandItemData, CommandRootEmits } from './types';
|
|
2
|
+
import { useCommandMenu, FilterFn } from './useCommandMenu';
|
|
3
|
+
export interface UseCommandRootOptions {
|
|
4
|
+
filter?: FilterFn;
|
|
5
|
+
loading?: boolean;
|
|
6
|
+
closeOnSelect?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface UseCommandRootReturn {
|
|
9
|
+
state: ReturnType<typeof useCommandMenu>;
|
|
10
|
+
handleSelect: (item: CommandItemData) => void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Shared composable for root command components (Menu, Dialog).
|
|
14
|
+
*
|
|
15
|
+
* - Creates the command menu state
|
|
16
|
+
* - Provides all injection keys so child components can consume them
|
|
17
|
+
* - Returns the state and a select handler
|
|
18
|
+
*/
|
|
19
|
+
export declare function useCommandRoot(options: UseCommandRootOptions, emit: CommandRootEmits, onItemSelect?: (item: CommandItemData) => void): UseCommandRootReturn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionKey } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* Type-safe inject that throws a clear error when a required value is missing.
|
|
4
|
+
*
|
|
5
|
+
* Use this instead of `inject(key)!` to get early feedback when a child
|
|
6
|
+
* component is used outside of `<CommandMenu>` or `<CommandDialog>`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function injectStrict<T>(key: InjectionKey<T>, componentName: string): T;
|
package/dist/vue-cmdk.js
CHANGED
|
@@ -1,118 +1,133 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
const
|
|
1
|
+
import { ref as E, computed as Q, watch as g, onUnmounted as ne, provide as x, defineComponent as I, openBlock as d, createElementBlock as m, renderSlot as C, unref as v, inject as D, createElementVNode as k, createCommentVNode as S, toDisplayString as T, normalizeClass as le, createBlock as N, resolveDynamicComponent as se, Fragment as $, createTextVNode as B, createVNode as L, renderList as F, withCtx as G, nextTick as re, Teleport as ue, Transition as ce } from "vue";
|
|
2
|
+
const ie = {
|
|
3
3
|
"⌘": "metaKey",
|
|
4
4
|
"⌃": "ctrlKey",
|
|
5
5
|
"⌥": "altKey",
|
|
6
6
|
"⇧": "shiftKey"
|
|
7
|
-
}
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
s[t] = !0, e = e.slice(r.length), n = !0;
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
7
|
+
}, de = /^([⌘⌃⌥⇧]+)(.+)$/;
|
|
8
|
+
function me(t) {
|
|
9
|
+
if (!t) return null;
|
|
10
|
+
const e = de.exec(t);
|
|
11
|
+
if (!e) return { key: t.toLowerCase() };
|
|
12
|
+
const [, o, r] = e, s = {};
|
|
13
|
+
for (const a of o) {
|
|
14
|
+
const i = ie[a];
|
|
15
|
+
i && (s[i] = !0);
|
|
19
16
|
}
|
|
20
|
-
return
|
|
17
|
+
return { ...s, key: r.toLowerCase() };
|
|
21
18
|
}
|
|
22
|
-
function
|
|
23
|
-
return e ?
|
|
19
|
+
function fe(t, e) {
|
|
20
|
+
return e ? t.key.toLowerCase() === e.key && !!t.metaKey == !!e.metaKey && !!t.ctrlKey == !!e.ctrlKey && !!t.altKey == !!e.altKey && !!t.shiftKey == !!e.shiftKey : !1;
|
|
24
21
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
}, a = () => {
|
|
29
|
-
s.value = !0, r.value = 0;
|
|
22
|
+
function ve(t, e) {
|
|
23
|
+
const o = E(!1), r = E(""), s = E(0), a = E([]), i = () => {
|
|
24
|
+
o.value = !o.value;
|
|
30
25
|
}, l = () => {
|
|
31
|
-
|
|
26
|
+
o.value = !0, s.value = 0;
|
|
27
|
+
}, n = () => {
|
|
28
|
+
o.value = !1, r.value = "";
|
|
32
29
|
};
|
|
33
|
-
function
|
|
34
|
-
if (!
|
|
35
|
-
const
|
|
30
|
+
function u(c, p) {
|
|
31
|
+
if (!p.trim()) return c;
|
|
32
|
+
const f = p.toLowerCase();
|
|
36
33
|
return c.filter((_) => {
|
|
37
|
-
var b,
|
|
38
|
-
return !!(_.value.toLowerCase().includes(
|
|
34
|
+
var b, P;
|
|
35
|
+
return !!(_.value.toLowerCase().includes(f) || (b = _.label) != null && b.toLowerCase().includes(f) || (P = _.keywords) != null && P.some((ae) => ae.toLowerCase().includes(f)));
|
|
39
36
|
});
|
|
40
37
|
}
|
|
41
|
-
function
|
|
42
|
-
const
|
|
38
|
+
function h(c) {
|
|
39
|
+
const p = /* @__PURE__ */ new Map();
|
|
43
40
|
for (const _ of c) {
|
|
44
41
|
const b = _.group || "__ungrouped__";
|
|
45
|
-
|
|
42
|
+
p.has(b) || p.set(b, []), p.get(b).push(_);
|
|
46
43
|
}
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
for (const [_, b] of
|
|
50
|
-
|
|
51
|
-
return
|
|
44
|
+
const f = [];
|
|
45
|
+
p.has("__ungrouped__") && (f.push({ heading: "", items: p.get("__ungrouped__") }), p.delete("__ungrouped__"));
|
|
46
|
+
for (const [_, b] of p)
|
|
47
|
+
f.push({ heading: _, items: b });
|
|
48
|
+
return f;
|
|
52
49
|
}
|
|
53
|
-
const y =
|
|
54
|
-
if (
|
|
55
|
-
const c =
|
|
50
|
+
const y = Q(() => {
|
|
51
|
+
if (t) {
|
|
52
|
+
const c = t(a.value, r.value);
|
|
56
53
|
if (c !== null) return c;
|
|
57
54
|
}
|
|
58
|
-
return
|
|
59
|
-
}),
|
|
60
|
-
function
|
|
55
|
+
return u(a.value, r.value);
|
|
56
|
+
}), K = Q(() => h(y.value));
|
|
57
|
+
function ee() {
|
|
61
58
|
const c = y.value.length;
|
|
62
|
-
c !== 0 && (
|
|
59
|
+
c !== 0 && (s.value = (s.value + 1) % c);
|
|
63
60
|
}
|
|
64
|
-
function
|
|
61
|
+
function te() {
|
|
65
62
|
const c = y.value.length;
|
|
66
|
-
c !== 0 && (
|
|
63
|
+
c !== 0 && (s.value = (s.value - 1 + c) % c);
|
|
67
64
|
}
|
|
68
|
-
function
|
|
69
|
-
var
|
|
70
|
-
const c = y.value[
|
|
71
|
-
c && !c.disabled && ((
|
|
65
|
+
function oe() {
|
|
66
|
+
var p;
|
|
67
|
+
const c = y.value[s.value];
|
|
68
|
+
c && !c.disabled && ((p = c.onSelect) == null || p.call(c, c), n());
|
|
72
69
|
}
|
|
73
|
-
function
|
|
74
|
-
var
|
|
75
|
-
for (const
|
|
76
|
-
if (
|
|
77
|
-
const _ =
|
|
78
|
-
if (
|
|
79
|
-
c.preventDefault(), c.stopPropagation(), (
|
|
70
|
+
function R(c) {
|
|
71
|
+
var p;
|
|
72
|
+
for (const f of a.value) {
|
|
73
|
+
if (f.disabled || !f.shortcut) continue;
|
|
74
|
+
const _ = me(f.shortcut);
|
|
75
|
+
if (fe(c, _)) {
|
|
76
|
+
c.preventDefault(), c.stopPropagation(), (p = f.onSelect) == null || p.call(f, f), e == null || e(f), n();
|
|
80
77
|
return;
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
80
|
}
|
|
84
|
-
let
|
|
85
|
-
return
|
|
86
|
-
|
|
81
|
+
let w = null;
|
|
82
|
+
return g(
|
|
83
|
+
a,
|
|
87
84
|
(c) => {
|
|
88
|
-
|
|
85
|
+
w && (w(), w = null), c.some((f) => f.shortcut) && typeof window < "u" && (window.addEventListener("keydown", R), w = () => window.removeEventListener("keydown", R));
|
|
89
86
|
},
|
|
90
|
-
{ immediate: !0, flush: "
|
|
91
|
-
),
|
|
92
|
-
|
|
87
|
+
{ immediate: !0, flush: "post" }
|
|
88
|
+
), ne(() => {
|
|
89
|
+
w && w();
|
|
93
90
|
}), {
|
|
94
|
-
visible:
|
|
95
|
-
searchQuery:
|
|
96
|
-
activeIndex:
|
|
97
|
-
items:
|
|
98
|
-
toggle:
|
|
99
|
-
open:
|
|
100
|
-
close:
|
|
101
|
-
defaultFilter:
|
|
102
|
-
groupItems:
|
|
91
|
+
visible: o,
|
|
92
|
+
searchQuery: r,
|
|
93
|
+
activeIndex: s,
|
|
94
|
+
items: a,
|
|
95
|
+
toggle: i,
|
|
96
|
+
open: l,
|
|
97
|
+
close: n,
|
|
98
|
+
defaultFilter: u,
|
|
99
|
+
groupItems: h,
|
|
103
100
|
filteredItems: y,
|
|
104
|
-
groupedItems:
|
|
105
|
-
selectNext:
|
|
106
|
-
selectPrev:
|
|
107
|
-
selectCurrent:
|
|
101
|
+
groupedItems: K,
|
|
102
|
+
selectNext: ee,
|
|
103
|
+
selectPrev: te,
|
|
104
|
+
selectCurrent: oe
|
|
108
105
|
};
|
|
109
106
|
}
|
|
110
|
-
const
|
|
107
|
+
const M = Symbol("cmdk-state"), V = Symbol("cmdk-loading"), j = Symbol("cmdk-close-on-select"), A = Symbol("cmdk-select-handler"), U = Symbol("cmdk-item-index-map");
|
|
108
|
+
function q(t, e, o) {
|
|
109
|
+
const { filter: r, loading: s = !1, closeOnSelect: a = !0 } = t, i = ve(r, (u) => {
|
|
110
|
+
e("select", u), a && i.close();
|
|
111
|
+
});
|
|
112
|
+
x(M, i), x(V, () => s), x(j, () => a), x(A, (u) => {
|
|
113
|
+
e("select", u), a && i.close();
|
|
114
|
+
});
|
|
115
|
+
const l = Q(() => {
|
|
116
|
+
const u = /* @__PURE__ */ new Map();
|
|
117
|
+
return i.filteredItems.value.forEach((h, y) => u.set(h.value, y)), u;
|
|
118
|
+
});
|
|
119
|
+
x(U, () => l.value);
|
|
120
|
+
function n(u) {
|
|
121
|
+
e("select", u), a && i.close();
|
|
122
|
+
}
|
|
123
|
+
return { state: i, handleSelect: n };
|
|
124
|
+
}
|
|
125
|
+
const pe = {
|
|
111
126
|
"data-cmdk-root": "",
|
|
112
127
|
role: "combobox",
|
|
113
128
|
"aria-expanded": "true",
|
|
114
129
|
"aria-haspopup": "listbox"
|
|
115
|
-
},
|
|
130
|
+
}, he = /* @__PURE__ */ I({
|
|
116
131
|
__name: "CommandMenu",
|
|
117
132
|
props: {
|
|
118
133
|
visible: { type: Boolean },
|
|
@@ -124,137 +139,146 @@ const K = Symbol("cmdk-state"), A = Symbol("cmdk-loading"), F = Symbol("cmdk-clo
|
|
|
124
139
|
loading: { type: Boolean }
|
|
125
140
|
},
|
|
126
141
|
emits: ["update:visible", "update:searchQuery", "select"],
|
|
127
|
-
setup(
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
142
|
+
setup(t, { expose: e, emit: o }) {
|
|
143
|
+
const r = t, s = o, { state: a, handleSelect: i } = q(
|
|
144
|
+
{
|
|
145
|
+
filter: r.filter,
|
|
146
|
+
loading: r.loading,
|
|
147
|
+
closeOnSelect: r.closeOnSelect
|
|
148
|
+
},
|
|
149
|
+
s
|
|
150
|
+
);
|
|
151
|
+
return a.visible.value = r.visible ?? !0, a.searchQuery.value = r.searchQuery ?? "", x("cmdk-filter", r.filter), g(
|
|
152
|
+
() => r.visible,
|
|
153
|
+
(l) => {
|
|
154
|
+
l !== void 0 && (a.visible.value = l);
|
|
137
155
|
}
|
|
138
|
-
),
|
|
139
|
-
() =>
|
|
140
|
-
(
|
|
141
|
-
|
|
156
|
+
), g(a.visible, (l) => s("update:visible", l)), g(
|
|
157
|
+
() => r.searchQuery,
|
|
158
|
+
(l) => {
|
|
159
|
+
l !== void 0 && (a.searchQuery.value = l);
|
|
142
160
|
}
|
|
143
|
-
),
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
selectNext: m(t).selectNext,
|
|
160
|
-
selectPrev: m(t).selectPrev,
|
|
161
|
-
selectCurrent: m(t).selectCurrent,
|
|
162
|
-
handleSelect: v
|
|
161
|
+
), g(a.searchQuery, (l) => s("update:searchQuery", l)), e({
|
|
162
|
+
open: a.open,
|
|
163
|
+
close: a.close,
|
|
164
|
+
toggle: a.toggle,
|
|
165
|
+
searchQuery: a.searchQuery,
|
|
166
|
+
items: a.items,
|
|
167
|
+
filteredItems: a.filteredItems
|
|
168
|
+
}), (l, n) => (d(), m("div", pe, [
|
|
169
|
+
C(l.$slots, "default", {
|
|
170
|
+
items: v(a).items,
|
|
171
|
+
filteredItems: v(a).filteredItems,
|
|
172
|
+
searchQuery: v(a).searchQuery,
|
|
173
|
+
selectNext: v(a).selectNext,
|
|
174
|
+
selectPrev: v(a).selectPrev,
|
|
175
|
+
selectCurrent: v(a).selectCurrent,
|
|
176
|
+
handleSelect: v(i)
|
|
163
177
|
})
|
|
164
178
|
]));
|
|
165
179
|
}
|
|
166
|
-
})
|
|
180
|
+
});
|
|
181
|
+
function O(t, e) {
|
|
182
|
+
const o = D(t);
|
|
183
|
+
if (!o)
|
|
184
|
+
throw new Error(`[vue-cmdk] <${e}> must be used inside <CommandMenu> or <CommandDialog>.`);
|
|
185
|
+
return o;
|
|
186
|
+
}
|
|
187
|
+
const ye = ["value", "placeholder", "autofocus"], z = /* @__PURE__ */ I({
|
|
167
188
|
__name: "CommandInput",
|
|
168
189
|
props: {
|
|
169
190
|
placeholder: { default: "Type a command or search..." },
|
|
170
191
|
autoFocus: { type: Boolean, default: !0 }
|
|
171
192
|
},
|
|
172
|
-
setup(
|
|
173
|
-
const
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
|
|
193
|
+
setup(t, { expose: e }) {
|
|
194
|
+
const o = O(M, "CommandInput"), r = D(A, () => {
|
|
195
|
+
}), s = E(null);
|
|
196
|
+
e({ inputRef: s });
|
|
197
|
+
function a(l) {
|
|
198
|
+
o.searchQuery.value = l.target.value, o.activeIndex.value = 0;
|
|
177
199
|
}
|
|
178
|
-
function
|
|
179
|
-
var
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
else if (
|
|
183
|
-
|
|
184
|
-
else if (
|
|
185
|
-
|
|
186
|
-
const
|
|
187
|
-
|
|
200
|
+
function i(l) {
|
|
201
|
+
var n;
|
|
202
|
+
if (l.key === "ArrowDown")
|
|
203
|
+
l.preventDefault(), o.selectNext();
|
|
204
|
+
else if (l.key === "ArrowUp")
|
|
205
|
+
l.preventDefault(), o.selectPrev();
|
|
206
|
+
else if (l.key === "Enter") {
|
|
207
|
+
l.preventDefault();
|
|
208
|
+
const u = o.filteredItems.value[o.activeIndex.value];
|
|
209
|
+
u && !u.disabled && ((n = u.onSelect) == null || n.call(u, u), r(u));
|
|
188
210
|
}
|
|
189
211
|
}
|
|
190
|
-
return (
|
|
212
|
+
return (l, n) => (d(), m("input", {
|
|
213
|
+
ref_key: "inputRef",
|
|
214
|
+
ref: s,
|
|
191
215
|
"data-cmdk-input": "",
|
|
192
|
-
value:
|
|
193
|
-
placeholder:
|
|
216
|
+
value: v(o).searchQuery.value,
|
|
217
|
+
placeholder: t.placeholder,
|
|
194
218
|
role: "searchbox",
|
|
195
219
|
autocomplete: "off",
|
|
196
220
|
autocorrect: "off",
|
|
197
221
|
spellcheck: "false",
|
|
198
|
-
autofocus:
|
|
199
|
-
onInput:
|
|
200
|
-
onKeydown:
|
|
201
|
-
}, null, 40,
|
|
222
|
+
autofocus: t.autoFocus,
|
|
223
|
+
onInput: a,
|
|
224
|
+
onKeydown: i
|
|
225
|
+
}, null, 40, ye));
|
|
202
226
|
}
|
|
203
|
-
}),
|
|
227
|
+
}), _e = {
|
|
204
228
|
key: 0,
|
|
205
229
|
"data-cmdk-empty": ""
|
|
206
|
-
},
|
|
230
|
+
}, H = /* @__PURE__ */ I({
|
|
207
231
|
__name: "CommandEmpty",
|
|
208
|
-
setup(
|
|
209
|
-
const e =
|
|
210
|
-
return (
|
|
211
|
-
|
|
212
|
-
|
|
232
|
+
setup(t) {
|
|
233
|
+
const e = O(M, "CommandEmpty");
|
|
234
|
+
return (o, r) => v(e).searchQuery.value && v(e).filteredItems.value.length === 0 ? (d(), m("div", _e, [
|
|
235
|
+
C(o.$slots, "default", {}, () => [
|
|
236
|
+
r[0] || (r[0] = k("span", null, "No results found.", -1))
|
|
213
237
|
])
|
|
214
|
-
])) :
|
|
238
|
+
])) : S("", !0);
|
|
215
239
|
}
|
|
216
|
-
}),
|
|
240
|
+
}), ge = {
|
|
217
241
|
key: 0,
|
|
218
242
|
"data-cmdk-loading": ""
|
|
219
|
-
},
|
|
243
|
+
}, X = /* @__PURE__ */ I({
|
|
220
244
|
__name: "CommandLoading",
|
|
221
245
|
props: {
|
|
222
246
|
loading: { type: Boolean, default: !1 }
|
|
223
247
|
},
|
|
224
|
-
setup(
|
|
225
|
-
return (e,
|
|
226
|
-
|
|
227
|
-
|
|
248
|
+
setup(t) {
|
|
249
|
+
return (e, o) => t.loading ? (d(), m("div", ge, [
|
|
250
|
+
C(e.$slots, "default", {}, () => [
|
|
251
|
+
o[0] || (o[0] = k("span", null, "Loading...", -1))
|
|
228
252
|
])
|
|
229
|
-
])) :
|
|
253
|
+
])) : S("", !0);
|
|
230
254
|
}
|
|
231
|
-
}),
|
|
255
|
+
}), ke = {
|
|
232
256
|
"data-cmdk-group": "",
|
|
233
257
|
role: "group"
|
|
234
|
-
},
|
|
258
|
+
}, be = {
|
|
235
259
|
key: 0,
|
|
236
260
|
"data-cmdk-group-heading": "",
|
|
237
261
|
role: "presentation"
|
|
238
|
-
},
|
|
262
|
+
}, Ce = {
|
|
239
263
|
"data-cmdk-group-items": "",
|
|
240
264
|
role: "group"
|
|
241
|
-
},
|
|
265
|
+
}, J = /* @__PURE__ */ I({
|
|
242
266
|
__name: "CommandGroup",
|
|
243
267
|
props: {
|
|
244
268
|
heading: {}
|
|
245
269
|
},
|
|
246
|
-
setup(
|
|
247
|
-
return (e,
|
|
248
|
-
|
|
249
|
-
k("div",
|
|
250
|
-
|
|
270
|
+
setup(t) {
|
|
271
|
+
return (e, o) => (d(), m("div", ke, [
|
|
272
|
+
t.heading ? (d(), m("div", be, T(t.heading), 1)) : S("", !0),
|
|
273
|
+
k("div", Ce, [
|
|
274
|
+
C(e.$slots, "default")
|
|
251
275
|
])
|
|
252
276
|
]));
|
|
253
277
|
}
|
|
254
|
-
}),
|
|
278
|
+
}), Se = ["aria-selected", "aria-disabled", "data-value"], Ie = {
|
|
255
279
|
key: 0,
|
|
256
280
|
"data-cmdk-item-icon": ""
|
|
257
|
-
},
|
|
281
|
+
}, we = { "data-cmdk-item-label": "" }, $e = {
|
|
258
282
|
key: 1,
|
|
259
283
|
"data-cmdk-item-shortcut": ""
|
|
260
284
|
}, W = /* @__PURE__ */ I({
|
|
@@ -268,8 +292,8 @@ const K = Symbol("cmdk-state"), A = Symbol("cmdk-loading"), F = Symbol("cmdk-clo
|
|
|
268
292
|
icon: {},
|
|
269
293
|
onSelect: {}
|
|
270
294
|
},
|
|
271
|
-
setup(
|
|
272
|
-
const e = o,
|
|
295
|
+
setup(t) {
|
|
296
|
+
const e = t, o = O(M, "CommandItem"), r = D(U, () => /* @__PURE__ */ new Map()), s = Q(() => ({
|
|
273
297
|
value: e.value,
|
|
274
298
|
label: e.label,
|
|
275
299
|
keywords: e.keywords,
|
|
@@ -277,210 +301,218 @@ const K = Symbol("cmdk-state"), A = Symbol("cmdk-loading"), F = Symbol("cmdk-clo
|
|
|
277
301
|
disabled: e.disabled,
|
|
278
302
|
icon: e.icon,
|
|
279
303
|
onSelect: e.onSelect
|
|
280
|
-
})),
|
|
281
|
-
const
|
|
282
|
-
return (
|
|
283
|
-
}),
|
|
304
|
+
})), a = Q(() => {
|
|
305
|
+
const u = o.filteredItems.value[o.activeIndex.value];
|
|
306
|
+
return (u == null ? void 0 : u.value) === e.value;
|
|
307
|
+
}), i = D(j, () => !0), l = D(A, () => {
|
|
284
308
|
});
|
|
285
|
-
function
|
|
286
|
-
var
|
|
287
|
-
e.disabled || ((
|
|
309
|
+
function n() {
|
|
310
|
+
var u;
|
|
311
|
+
e.disabled || ((u = e.onSelect) == null || u.call(e, s.value), l(s.value), i() && o.close());
|
|
288
312
|
}
|
|
289
|
-
return (
|
|
313
|
+
return (u, h) => (d(), m("div", {
|
|
290
314
|
"data-cmdk-item": "",
|
|
291
315
|
role: "option",
|
|
292
|
-
"aria-selected":
|
|
293
|
-
"aria-disabled":
|
|
294
|
-
"data-value":
|
|
295
|
-
class:
|
|
296
|
-
onClick:
|
|
316
|
+
"aria-selected": a.value,
|
|
317
|
+
"aria-disabled": t.disabled,
|
|
318
|
+
"data-value": t.value,
|
|
319
|
+
class: le({ active: a.value, disabled: t.disabled }),
|
|
320
|
+
onClick: n,
|
|
297
321
|
onPointerenter: h[0] || (h[0] = () => {
|
|
298
|
-
const
|
|
299
|
-
|
|
322
|
+
const y = v(r)().get(t.value);
|
|
323
|
+
y !== void 0 && (v(o).activeIndex.value = y);
|
|
300
324
|
})
|
|
301
325
|
}, [
|
|
302
|
-
|
|
303
|
-
item:
|
|
304
|
-
active:
|
|
326
|
+
C(u.$slots, "default", {
|
|
327
|
+
item: s.value,
|
|
328
|
+
active: a.value
|
|
305
329
|
}, () => [
|
|
306
|
-
|
|
307
|
-
(
|
|
308
|
-
])) :
|
|
309
|
-
k("span",
|
|
310
|
-
|
|
330
|
+
t.icon ? (d(), m("span", Ie, [
|
|
331
|
+
(d(), N(se(t.icon)))
|
|
332
|
+
])) : S("", !0),
|
|
333
|
+
k("span", we, T(t.label || t.value), 1),
|
|
334
|
+
t.shortcut ? (d(), m("span", $e, T(t.shortcut), 1)) : S("", !0)
|
|
311
335
|
])
|
|
312
|
-
], 42,
|
|
336
|
+
], 42, Se));
|
|
313
337
|
}
|
|
314
|
-
}),
|
|
315
|
-
const
|
|
316
|
-
for (const [
|
|
317
|
-
|
|
318
|
-
return
|
|
319
|
-
},
|
|
338
|
+
}), xe = (t, e) => {
|
|
339
|
+
const o = t.__vccOpts || t;
|
|
340
|
+
for (const [r, s] of e)
|
|
341
|
+
o[r] = s;
|
|
342
|
+
return o;
|
|
343
|
+
}, Ee = {}, De = {
|
|
320
344
|
"data-cmdk-separator": "",
|
|
321
345
|
role: "separator"
|
|
322
346
|
};
|
|
323
|
-
function
|
|
324
|
-
return
|
|
347
|
+
function Le(t, e) {
|
|
348
|
+
return d(), m("div", De);
|
|
325
349
|
}
|
|
326
|
-
const
|
|
350
|
+
const Y = /* @__PURE__ */ xe(Ee, [["render", Le]]), Qe = {
|
|
327
351
|
"data-cmdk-list": "",
|
|
328
352
|
role: "listbox"
|
|
329
|
-
},
|
|
353
|
+
}, Me = {
|
|
330
354
|
"aria-live": "polite",
|
|
331
355
|
"aria-atomic": "true",
|
|
332
356
|
class: "sr-only"
|
|
333
|
-
},
|
|
357
|
+
}, Z = /* @__PURE__ */ I({
|
|
334
358
|
__name: "CommandList",
|
|
335
|
-
setup(
|
|
336
|
-
const e =
|
|
337
|
-
return (
|
|
338
|
-
k("div",
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
], 64)) :
|
|
342
|
-
|
|
343
|
-
], 64)) : (
|
|
344
|
-
|
|
359
|
+
setup(t) {
|
|
360
|
+
const e = O(M, "CommandList"), o = D(V, () => !1), r = Q(() => e.groupedItems.value);
|
|
361
|
+
return (s, a) => (d(), m("div", Qe, [
|
|
362
|
+
k("div", Me, [
|
|
363
|
+
v(e).searchQuery.value && v(e).filteredItems.value.length === 0 ? (d(), m($, { key: 0 }, [
|
|
364
|
+
B("No results found")
|
|
365
|
+
], 64)) : v(o)() ? (d(), m($, { key: 1 }, [
|
|
366
|
+
B("Loading")
|
|
367
|
+
], 64)) : (d(), m($, { key: 2 }, [
|
|
368
|
+
B(T(v(e).filteredItems.value.length) + " items", 1)
|
|
345
369
|
], 64))
|
|
346
370
|
]),
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
loading:
|
|
371
|
+
L(H),
|
|
372
|
+
L(X, {
|
|
373
|
+
loading: v(o)()
|
|
350
374
|
}, null, 8, ["loading"]),
|
|
351
|
-
(
|
|
352
|
-
key:
|
|
375
|
+
(d(!0), m($, null, F(r.value, (i) => (d(), m($, {
|
|
376
|
+
key: i.heading || "__ungrouped__"
|
|
353
377
|
}, [
|
|
354
|
-
|
|
355
|
-
heading:
|
|
378
|
+
L(J, {
|
|
379
|
+
heading: i.heading
|
|
356
380
|
}, {
|
|
357
|
-
default:
|
|
358
|
-
(
|
|
359
|
-
key:
|
|
360
|
-
value:
|
|
361
|
-
label:
|
|
362
|
-
shortcut:
|
|
363
|
-
disabled:
|
|
364
|
-
icon:
|
|
365
|
-
"on-select":
|
|
381
|
+
default: G(() => [
|
|
382
|
+
(d(!0), m($, null, F(i.items, (l) => (d(), N(W, {
|
|
383
|
+
key: l.value,
|
|
384
|
+
value: l.value,
|
|
385
|
+
label: l.label,
|
|
386
|
+
shortcut: l.shortcut,
|
|
387
|
+
disabled: l.disabled,
|
|
388
|
+
icon: l.icon,
|
|
389
|
+
"on-select": l.onSelect
|
|
366
390
|
}, null, 8, ["value", "label", "shortcut", "disabled", "icon", "on-select"]))), 128))
|
|
367
391
|
]),
|
|
368
392
|
_: 2
|
|
369
393
|
}, 1032, ["heading"]),
|
|
370
|
-
|
|
394
|
+
i !== r.value[r.value.length - 1] ? (d(), N(Y, { key: 0 })) : S("", !0)
|
|
371
395
|
], 64))), 128))
|
|
372
396
|
]));
|
|
373
397
|
}
|
|
374
|
-
}),
|
|
398
|
+
}), Ke = { "data-cmdk-dialog-wrapper": "" }, Te = { "data-cmdk-dialog-header": "" }, Ne = { "data-cmdk-dialog-body": "" }, Oe = {
|
|
375
399
|
key: 0,
|
|
376
400
|
"data-cmdk-dialog-footer": ""
|
|
377
|
-
},
|
|
401
|
+
}, Be = /* @__PURE__ */ I({
|
|
378
402
|
__name: "CommandDialog",
|
|
379
403
|
props: {
|
|
404
|
+
items: { default: () => [] },
|
|
380
405
|
visible: { type: Boolean, default: !1 },
|
|
406
|
+
searchQuery: {},
|
|
381
407
|
placeholder: { default: "Type a command or search..." },
|
|
408
|
+
filter: {},
|
|
382
409
|
autoFocus: { type: Boolean, default: !0 },
|
|
383
410
|
closeOnSelect: { type: Boolean, default: !0 },
|
|
384
|
-
items: { default: () => [] },
|
|
385
|
-
filter: {},
|
|
386
411
|
loading: { type: Boolean, default: !1 }
|
|
387
412
|
},
|
|
388
|
-
emits: ["update:visible", "select"],
|
|
389
|
-
setup(
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
413
|
+
emits: ["update:visible", "update:searchQuery", "select"],
|
|
414
|
+
setup(t, { emit: e }) {
|
|
415
|
+
const o = t, r = e, { state: s } = q(
|
|
416
|
+
{
|
|
417
|
+
filter: o.filter,
|
|
418
|
+
loading: o.loading,
|
|
419
|
+
closeOnSelect: o.closeOnSelect
|
|
420
|
+
},
|
|
421
|
+
r
|
|
422
|
+
), a = E(null);
|
|
423
|
+
g(
|
|
424
|
+
() => o.items,
|
|
425
|
+
(n) => {
|
|
426
|
+
s.items.value = n;
|
|
395
427
|
},
|
|
396
428
|
{ immediate: !0 }
|
|
397
|
-
),
|
|
398
|
-
() =>
|
|
399
|
-
(
|
|
400
|
-
|
|
429
|
+
), g(
|
|
430
|
+
() => o.visible,
|
|
431
|
+
(n) => {
|
|
432
|
+
s.visible.value = n;
|
|
401
433
|
},
|
|
402
434
|
{ immediate: !0 }
|
|
403
|
-
),
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
h == null || h.focus();
|
|
435
|
+
), g(
|
|
436
|
+
() => o.searchQuery,
|
|
437
|
+
(n) => {
|
|
438
|
+
n !== void 0 && (s.searchQuery.value = n);
|
|
408
439
|
}
|
|
440
|
+
), g(s.searchQuery, (n) => r("update:searchQuery", n)), g(s.visible, async (n) => {
|
|
441
|
+
var u, h;
|
|
442
|
+
r("update:visible", n), n && (await re(), (h = (u = a.value) == null ? void 0 : u.inputRef) == null || h.focus());
|
|
409
443
|
});
|
|
410
|
-
function
|
|
411
|
-
n
|
|
412
|
-
}
|
|
413
|
-
g(M, t);
|
|
414
|
-
function v(l) {
|
|
415
|
-
l.target === l.currentTarget && r.close();
|
|
444
|
+
function i(n) {
|
|
445
|
+
n.target === n.currentTarget && s.close();
|
|
416
446
|
}
|
|
417
|
-
function
|
|
418
|
-
if (
|
|
419
|
-
const
|
|
447
|
+
function l(n) {
|
|
448
|
+
if (n.key === "Escape" && (n.preventDefault(), s.close()), n.key === "Tab") {
|
|
449
|
+
const h = n.currentTarget.querySelectorAll(
|
|
420
450
|
'input, button, [href], select, textarea, [tabindex]:not([tabindex="-1"])'
|
|
421
451
|
);
|
|
422
|
-
if (
|
|
423
|
-
const y =
|
|
424
|
-
|
|
452
|
+
if (h.length === 0) return;
|
|
453
|
+
const y = h[0], K = h[h.length - 1];
|
|
454
|
+
n.shiftKey ? document.activeElement === y && (n.preventDefault(), K.focus()) : document.activeElement === K && (n.preventDefault(), y.focus());
|
|
425
455
|
}
|
|
426
456
|
}
|
|
427
|
-
return (
|
|
428
|
-
|
|
429
|
-
default:
|
|
430
|
-
|
|
457
|
+
return (n, u) => (d(), N(ue, { to: "body" }, [
|
|
458
|
+
L(ce, { name: "cmdk-dialog" }, {
|
|
459
|
+
default: G(() => [
|
|
460
|
+
v(s).visible.value ? (d(), m("div", {
|
|
431
461
|
key: 0,
|
|
432
462
|
"data-cmdk-dialog": "",
|
|
433
|
-
onKeydown:
|
|
463
|
+
onKeydown: l
|
|
434
464
|
}, [
|
|
435
465
|
k("div", {
|
|
436
466
|
"data-cmdk-dialog-mask": "",
|
|
437
|
-
onClick:
|
|
467
|
+
onClick: i
|
|
438
468
|
}),
|
|
439
|
-
k("div",
|
|
440
|
-
k("div",
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
469
|
+
k("div", Ke, [
|
|
470
|
+
k("div", Te, [
|
|
471
|
+
C(n.$slots, "header", {}, () => [
|
|
472
|
+
L(z, {
|
|
473
|
+
ref_key: "commandInputRef",
|
|
474
|
+
ref: a,
|
|
475
|
+
placeholder: t.placeholder,
|
|
476
|
+
"auto-focus": t.autoFocus
|
|
445
477
|
}, null, 8, ["placeholder", "auto-focus"])
|
|
446
478
|
])
|
|
447
479
|
]),
|
|
448
|
-
k("div",
|
|
449
|
-
|
|
450
|
-
|
|
480
|
+
k("div", Ne, [
|
|
481
|
+
C(n.$slots, "body", {}, () => [
|
|
482
|
+
L(Z)
|
|
451
483
|
])
|
|
452
484
|
]),
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
])) :
|
|
485
|
+
n.$slots.footer ? (d(), m("div", Oe, [
|
|
486
|
+
C(n.$slots, "footer")
|
|
487
|
+
])) : S("", !0)
|
|
456
488
|
])
|
|
457
|
-
], 32)) :
|
|
489
|
+
], 32)) : S("", !0)
|
|
458
490
|
]),
|
|
459
491
|
_: 3
|
|
460
492
|
})
|
|
461
493
|
]));
|
|
462
494
|
}
|
|
463
|
-
}),
|
|
464
|
-
Menu:
|
|
465
|
-
Dialog:
|
|
466
|
-
Input:
|
|
467
|
-
List:
|
|
468
|
-
Group:
|
|
495
|
+
}), Re = {
|
|
496
|
+
Menu: he,
|
|
497
|
+
Dialog: Be,
|
|
498
|
+
Input: z,
|
|
499
|
+
List: Z,
|
|
500
|
+
Group: J,
|
|
469
501
|
Item: W,
|
|
470
|
-
Empty:
|
|
471
|
-
Separator:
|
|
472
|
-
Loading:
|
|
502
|
+
Empty: H,
|
|
503
|
+
Separator: Y,
|
|
504
|
+
Loading: X
|
|
473
505
|
};
|
|
474
506
|
export {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
507
|
+
Re as Command,
|
|
508
|
+
Be as CommandDialog,
|
|
509
|
+
H as CommandEmpty,
|
|
510
|
+
J as CommandGroup,
|
|
511
|
+
z as CommandInput,
|
|
480
512
|
W as CommandItem,
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
513
|
+
Z as CommandList,
|
|
514
|
+
X as CommandLoading,
|
|
515
|
+
he as CommandMenu,
|
|
516
|
+
Y as CommandSeparator,
|
|
517
|
+
ve as useCommandMenu
|
|
486
518
|
};
|
package/dist/vue-cmdk.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(m,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(m=typeof globalThis<"u"?globalThis:m||self,e(m.VueCmdk={},m.Vue))})(this,(function(m,e){"use strict";const M={"⌘":"metaKey","⌃":"ctrlKey","⌥":"altKey","⇧":"shiftKey"};function F(n){let t=n;const r={};let l=!0;for(;l&&t.length>0;){l=!1;for(const[s,o]of Object.entries(M))if(t.startsWith(s)){r[o]=!0,t=t.slice(s.length),l=!0;break}}return t?{...r,key:t.toLowerCase()}:null}function j(n,t){return t?n.key.toLowerCase()===t.key&&!!n.metaKey==!!t.metaKey&&!!n.ctrlKey==!!t.ctrlKey&&!!n.altKey==!!t.altKey&&!!n.shiftKey==!!t.shiftKey:!1}function S(n,t){const r=e.ref(!1),l=e.ref(""),s=e.ref(0),o=e.ref([]),f=()=>{r.value=!r.value},a=()=>{r.value=!0,s.value=0},c=()=>{r.value=!1,l.value=""};function p(i,u){if(!u.trim())return i;const d=u.toLowerCase();return i.filter(y=>{var g,Q;return!!(y.value.toLowerCase().includes(d)||(g=y.label)!=null&&g.toLowerCase().includes(d)||(Q=y.keywords)!=null&&Q.some(me=>me.toLowerCase().includes(d)))})}function h(i){const u=new Map;for(const y of i){const g=y.group||"__ungrouped__";u.has(g)||u.set(g,[]),u.get(g).push(y)}const d=[];u.has("__ungrouped__")&&(d.push({heading:"",items:u.get("__ungrouped__")}),u.delete("__ungrouped__"));for(const[y,g]of u)d.push({heading:y,items:g});return d}const k=e.computed(()=>{if(n){const i=n(o.value,l.value);if(i!==null)return i}return p(o.value,l.value)}),B=e.computed(()=>h(k.value));function se(){const i=k.value.length;i!==0&&(s.value=(s.value+1)%i)}function ie(){const i=k.value.length;i!==0&&(s.value=(s.value-1+i)%i)}function de(){var u;const i=k.value[s.value];i&&!i.disabled&&((u=i.onSelect)==null||u.call(i,i),c())}function O(i){var u;for(const d of o.value){if(d.disabled||!d.shortcut)continue;const y=F(d.shortcut);if(j(i,y)){i.preventDefault(),i.stopPropagation(),(u=d.onSelect)==null||u.call(d,d),t==null||t(d),c();return}}}let C=null;return e.watch(o,i=>{C&&(C(),C=null),i.some(d=>d.shortcut)&&typeof window<"u"&&(window.addEventListener("keydown",O),C=()=>window.removeEventListener("keydown",O))},{immediate:!0,flush:"sync"}),e.onUnmounted(()=>{C&&C()}),{visible:r,searchQuery:l,activeIndex:s,items:o,toggle:f,open:a,close:c,defaultFilter:p,groupItems:h,filteredItems:k,groupedItems:B,selectNext:se,selectPrev:ie,selectCurrent:de}}const _=Symbol("cmdk-state"),E=Symbol("cmdk-loading"),w=Symbol("cmdk-close-on-select"),b=Symbol("cmdk-select-handler"),A={"data-cmdk-root":"",role:"combobox","aria-expanded":"true","aria-haspopup":"listbox"},x=e.defineComponent({__name:"CommandMenu",props:{visible:{type:Boolean},searchQuery:{},placeholder:{default:"Type a command or search..."},filter:{},autoFocus:{type:Boolean,default:!0},closeOnSelect:{type:Boolean,default:!0},loading:{type:Boolean}},emits:["update:visible","update:searchQuery","select"],setup(n,{expose:t,emit:r}){const l=n,s=r,o=S(l.filter,a=>{s("select",a),l.closeOnSelect&&o.close()});o.visible.value=l.visible??!0,o.searchQuery.value=l.searchQuery??"",e.provide(_,o),e.provide("cmdk-filter",l.filter),e.provide(E,()=>l.loading??!1),e.provide(w,()=>l.closeOnSelect),e.provide(b,a=>{s("select",a),l.closeOnSelect&&o.close()}),e.watch(()=>l.visible,a=>{a!==void 0&&(o.visible.value=a)}),e.watch(o.visible,a=>s("update:visible",a)),e.watch(()=>l.searchQuery,a=>{a!==void 0&&(o.searchQuery.value=a)}),e.watch(o.searchQuery,a=>s("update:searchQuery",a));function f(a){s("select",a),l.closeOnSelect&&o.close()}return t({open:o.open,close:o.close,toggle:o.toggle,searchQuery:o.searchQuery,items:o.items,filteredItems:o.filteredItems}),(a,c)=>(e.openBlock(),e.createElementBlock("div",A,[e.renderSlot(a.$slots,"default",{items:e.unref(o).items,filteredItems:e.unref(o).filteredItems,searchQuery:e.unref(o).searchQuery,selectNext:e.unref(o).selectNext,selectPrev:e.unref(o).selectPrev,selectCurrent:e.unref(o).selectCurrent,handleSelect:f})]))}}),P=["value","placeholder","autofocus"],N=e.defineComponent({__name:"CommandInput",props:{placeholder:{default:"Type a command or search..."},autoFocus:{type:Boolean,default:!0}},setup(n){const t=e.inject(_),r=e.inject(b,()=>{});function l(o){t.searchQuery.value=o.target.value,t.activeIndex.value=0}function s(o){var f;if(o.key==="ArrowDown")o.preventDefault(),t.selectNext();else if(o.key==="ArrowUp")o.preventDefault(),t.selectPrev();else if(o.key==="Enter"){o.preventDefault();const a=t.filteredItems.value[t.activeIndex.value];a&&!a.disabled&&((f=a.onSelect)==null||f.call(a,a),r(a))}}return(o,f)=>(e.openBlock(),e.createElementBlock("input",{"data-cmdk-input":"",value:e.unref(t).searchQuery.value,placeholder:n.placeholder,role:"searchbox",autocomplete:"off",autocorrect:"off",spellcheck:"false",autofocus:n.autoFocus,onInput:l,onKeydown:s},null,40,P))}}),G={key:0,"data-cmdk-empty":""},$=e.defineComponent({__name:"CommandEmpty",setup(n){const t=e.inject(_);return(r,l)=>e.unref(t).searchQuery.value&&e.unref(t).filteredItems.value.length===0?(e.openBlock(),e.createElementBlock("div",G,[e.renderSlot(r.$slots,"default",{},()=>[l[0]||(l[0]=e.createElementVNode("span",null,"No results found.",-1))])])):e.createCommentVNode("",!0)}}),q={key:0,"data-cmdk-loading":""},I=e.defineComponent({__name:"CommandLoading",props:{loading:{type:Boolean,default:!1}},setup(n){return(t,r)=>n.loading?(e.openBlock(),e.createElementBlock("div",q,[e.renderSlot(t.$slots,"default",{},()=>[r[0]||(r[0]=e.createElementVNode("span",null,"Loading...",-1))])])):e.createCommentVNode("",!0)}}),R={"data-cmdk-group":"",role:"group"},U={key:0,"data-cmdk-group-heading":"",role:"presentation"},z={"data-cmdk-group-items":"",role:"group"},V=e.defineComponent({__name:"CommandGroup",props:{heading:{}},setup(n){return(t,r)=>(e.openBlock(),e.createElementBlock("div",R,[n.heading?(e.openBlock(),e.createElementBlock("div",U,e.toDisplayString(n.heading),1)):e.createCommentVNode("",!0),e.createElementVNode("div",z,[e.renderSlot(t.$slots,"default")])]))}}),H=["aria-selected","aria-disabled","data-value"],W={key:0,"data-cmdk-item-icon":""},J={"data-cmdk-item-label":""},X={key:1,"data-cmdk-item-shortcut":""},D=e.defineComponent({__name:"CommandItem",props:{value:{},label:{},keywords:{},shortcut:{},disabled:{type:Boolean,default:!1},icon:{},onSelect:{}},setup(n){const t=n,r=e.inject(_),l=e.computed(()=>({value:t.value,label:t.label,keywords:t.keywords,shortcut:t.shortcut,disabled:t.disabled,icon:t.icon,onSelect:t.onSelect})),s=e.computed(()=>{const c=r.filteredItems.value[r.activeIndex.value];return(c==null?void 0:c.value)===t.value}),o=e.inject(w,()=>!0),f=e.inject(b,()=>{});function a(){var c;t.disabled||((c=t.onSelect)==null||c.call(t,l.value),f(l.value),o()&&r.close())}return(c,p)=>(e.openBlock(),e.createElementBlock("div",{"data-cmdk-item":"",role:"option","aria-selected":s.value,"aria-disabled":n.disabled,"data-value":n.value,class:e.normalizeClass({active:s.value,disabled:n.disabled}),onClick:a,onPointerenter:p[0]||(p[0]=()=>{const h=e.unref(r).filteredItems.value.findIndex(k=>k.value===n.value);h>=0&&(e.unref(r).activeIndex.value=h)})},[e.renderSlot(c.$slots,"default",{item:l.value,active:s.value},()=>[n.icon?(e.openBlock(),e.createElementBlock("span",W,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(n.icon)))])):e.createCommentVNode("",!0),e.createElementVNode("span",J,e.toDisplayString(n.label||n.value),1),n.shortcut?(e.openBlock(),e.createElementBlock("span",X,e.toDisplayString(n.shortcut),1)):e.createCommentVNode("",!0)])],42,H))}}),Y=(n,t)=>{const r=n.__vccOpts||n;for(const[l,s]of t)r[l]=s;return r},Z={},v={"data-cmdk-separator":"",role:"separator"};function ee(n,t){return e.openBlock(),e.createElementBlock("div",v)}const L=Y(Z,[["render",ee]]),te={"data-cmdk-list":"",role:"listbox"},oe={"aria-live":"polite","aria-atomic":"true",class:"sr-only"},K=e.defineComponent({__name:"CommandList",setup(n){const t=e.inject(_),r=e.inject(E,()=>!1),l=e.computed(()=>t.groupedItems.value);return(s,o)=>(e.openBlock(),e.createElementBlock("div",te,[e.createElementVNode("div",oe,[e.unref(t).searchQuery.value&&e.unref(t).filteredItems.value.length===0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode("No results found")],64)):e.unref(r)()?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode("Loading")],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createTextVNode(e.toDisplayString(e.unref(t).filteredItems.value.length)+" items",1)],64))]),e.createVNode($),e.createVNode(I,{loading:e.unref(r)()},null,8,["loading"]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.value,f=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:f.heading||"__ungrouped__"},[e.createVNode(V,{heading:f.heading},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(f.items,a=>(e.openBlock(),e.createBlock(D,{key:a.value,value:a.value,label:a.label,shortcut:a.shortcut,disabled:a.disabled,icon:a.icon,"on-select":a.onSelect},null,8,["value","label","shortcut","disabled","icon","on-select"]))),128))]),_:2},1032,["heading"]),f!==l.value[l.value.length-1]?(e.openBlock(),e.createBlock(L,{key:0})):e.createCommentVNode("",!0)],64))),128))]))}}),ne={"data-cmdk-dialog-wrapper":""},ae={"data-cmdk-dialog-header":""},le={"data-cmdk-dialog-body":""},ce={key:0,"data-cmdk-dialog-footer":""},T=e.defineComponent({__name:"CommandDialog",props:{visible:{type:Boolean,default:!1},placeholder:{default:"Type a command or search..."},autoFocus:{type:Boolean,default:!0},closeOnSelect:{type:Boolean,default:!0},items:{default:()=>[]},filter:{},loading:{type:Boolean,default:!1}},emits:["update:visible","select"],setup(n,{emit:t}){const r=n,l=t,s=S(r.filter,o);e.provide(_,s),e.provide(E,()=>r.loading),e.provide(w,()=>r.closeOnSelect),e.watch(()=>r.items,c=>{s.items.value=c},{immediate:!0}),e.watch(()=>r.visible,c=>{s.visible.value=c},{immediate:!0}),e.watch(s.visible,async c=>{if(l("update:visible",c),c){await e.nextTick();const p=document.querySelector("[data-cmdk-input]");p==null||p.focus()}});function o(c){l("select",c),r.closeOnSelect&&s.close()}e.provide(b,o);function f(c){c.target===c.currentTarget&&s.close()}function a(c){if(c.key==="Escape"&&(c.preventDefault(),s.close()),c.key==="Tab"){const h=c.currentTarget.querySelectorAll('input, button, [href], select, textarea, [tabindex]:not([tabindex="-1"])');if(h.length===0)return;const k=h[0],B=h[h.length-1];c.shiftKey?document.activeElement===k&&(c.preventDefault(),B.focus()):document.activeElement===B&&(c.preventDefault(),k.focus())}}return(c,p)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.createVNode(e.Transition,{name:"cmdk-dialog"},{default:e.withCtx(()=>[e.unref(s).visible.value?(e.openBlock(),e.createElementBlock("div",{key:0,"data-cmdk-dialog":"",onKeydown:a},[e.createElementVNode("div",{"data-cmdk-dialog-mask":"",onClick:f}),e.createElementVNode("div",ne,[e.createElementVNode("div",ae,[e.renderSlot(c.$slots,"header",{},()=>[e.createVNode(N,{placeholder:n.placeholder,"auto-focus":n.autoFocus},null,8,["placeholder","auto-focus"])])]),e.createElementVNode("div",le,[e.renderSlot(c.$slots,"body",{},()=>[e.createVNode(K)])]),c.$slots.footer?(e.openBlock(),e.createElementBlock("div",ce,[e.renderSlot(c.$slots,"footer")])):e.createCommentVNode("",!0)])],32)):e.createCommentVNode("",!0)]),_:3})]))}}),re={Menu:x,Dialog:T,Input:N,List:K,Group:V,Item:D,Empty:$,Separator:L,Loading:I};m.Command=re,m.CommandDialog=T,m.CommandEmpty=$,m.CommandGroup=V,m.CommandInput=N,m.CommandItem=D,m.CommandList=K,m.CommandLoading=I,m.CommandMenu=x,m.CommandSeparator=L,m.useCommandMenu=S,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(f,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(f=typeof globalThis<"u"?globalThis:f||self,e(f.VueCmdk={},f.Vue))})(this,(function(f,e){"use strict";const P={"⌘":"metaKey","⌃":"ctrlKey","⌥":"altKey","⇧":"shiftKey"},R=/^([⌘⌃⌥⇧]+)(.+)$/;function j(o){if(!o)return null;const t=R.exec(o);if(!t)return{key:o.toLowerCase()};const[,n,s]=t,r={};for(const a of n){const m=P[a];m&&(r[m]=!0)}return{...r,key:s.toLowerCase()}}function G(o,t){return t?o.key.toLowerCase()===t.key&&!!o.metaKey==!!t.metaKey&&!!o.ctrlKey==!!t.ctrlKey&&!!o.altKey==!!t.altKey&&!!o.shiftKey==!!t.shiftKey:!1}function L(o,t){const n=e.ref(!1),s=e.ref(""),r=e.ref(0),a=e.ref([]),m=()=>{n.value=!n.value},c=()=>{n.value=!0,r.value=0},l=()=>{n.value=!1,s.value=""};function d(i,p){if(!p.trim())return i;const u=p.toLowerCase();return i.filter(y=>{var g,A;return!!(y.value.toLowerCase().includes(u)||(g=y.label)!=null&&g.toLowerCase().includes(u)||(A=y.keywords)!=null&&A.some(he=>he.toLowerCase().includes(u)))})}function h(i){const p=new Map;for(const y of i){const g=y.group||"__ungrouped__";p.has(g)||p.set(g,[]),p.get(g).push(y)}const u=[];p.has("__ungrouped__")&&(u.push({heading:"",items:p.get("__ungrouped__")}),p.delete("__ungrouped__"));for(const[y,g]of p)u.push({heading:y,items:g});return u}const k=e.computed(()=>{if(o){const i=o(a.value,s.value);if(i!==null)return i}return d(a.value,s.value)}),B=e.computed(()=>h(k.value));function ue(){const i=k.value.length;i!==0&&(r.value=(r.value+1)%i)}function fe(){const i=k.value.length;i!==0&&(r.value=(r.value-1+i)%i)}function pe(){var p;const i=k.value[r.value];i&&!i.disabled&&((p=i.onSelect)==null||p.call(i,i),l())}function F(i){var p;for(const u of a.value){if(u.disabled||!u.shortcut)continue;const y=j(u.shortcut);if(G(i,y)){i.preventDefault(),i.stopPropagation(),(p=u.onSelect)==null||p.call(u,u),t==null||t(u),l();return}}}let _=null;return e.watch(a,i=>{_&&(_(),_=null),i.some(u=>u.shortcut)&&typeof window<"u"&&(window.addEventListener("keydown",F),_=()=>window.removeEventListener("keydown",F))},{immediate:!0,flush:"post"}),e.onUnmounted(()=>{_&&_()}),{visible:n,searchQuery:s,activeIndex:r,items:a,toggle:m,open:c,close:l,defaultFilter:d,groupItems:h,filteredItems:k,groupedItems:B,selectNext:ue,selectPrev:fe,selectCurrent:pe}}const C=Symbol("cmdk-state"),M=Symbol("cmdk-loading"),x=Symbol("cmdk-close-on-select"),S=Symbol("cmdk-select-handler"),Q=Symbol("cmdk-item-index-map");function T(o,t,n){const{filter:s,loading:r=!1,closeOnSelect:a=!0}=o,m=L(s,d=>{t("select",d),a&&m.close()});e.provide(C,m),e.provide(M,()=>r),e.provide(x,()=>a),e.provide(S,d=>{t("select",d),a&&m.close()});const c=e.computed(()=>{const d=new Map;return m.filteredItems.value.forEach((h,k)=>d.set(h.value,k)),d});e.provide(Q,()=>c.value);function l(d){t("select",d),a&&m.close()}return{state:m,handleSelect:l}}const q={"data-cmdk-root":"",role:"combobox","aria-expanded":"true","aria-haspopup":"listbox"},K=e.defineComponent({__name:"CommandMenu",props:{visible:{type:Boolean},searchQuery:{},placeholder:{default:"Type a command or search..."},filter:{},autoFocus:{type:Boolean,default:!0},closeOnSelect:{type:Boolean,default:!0},loading:{type:Boolean}},emits:["update:visible","update:searchQuery","select"],setup(o,{expose:t,emit:n}){const s=o,r=n,{state:a,handleSelect:m}=T({filter:s.filter,loading:s.loading,closeOnSelect:s.closeOnSelect},r);return a.visible.value=s.visible??!0,a.searchQuery.value=s.searchQuery??"",e.provide("cmdk-filter",s.filter),e.watch(()=>s.visible,c=>{c!==void 0&&(a.visible.value=c)}),e.watch(a.visible,c=>r("update:visible",c)),e.watch(()=>s.searchQuery,c=>{c!==void 0&&(a.searchQuery.value=c)}),e.watch(a.searchQuery,c=>r("update:searchQuery",c)),t({open:a.open,close:a.close,toggle:a.toggle,searchQuery:a.searchQuery,items:a.items,filteredItems:a.filteredItems}),(c,l)=>(e.openBlock(),e.createElementBlock("div",q,[e.renderSlot(c.$slots,"default",{items:e.unref(a).items,filteredItems:e.unref(a).filteredItems,searchQuery:e.unref(a).searchQuery,selectNext:e.unref(a).selectNext,selectPrev:e.unref(a).selectPrev,selectCurrent:e.unref(a).selectCurrent,handleSelect:e.unref(m)})]))}});function b(o,t){const n=e.inject(o);if(!n)throw new Error(`[vue-cmdk] <${t}> must be used inside <CommandMenu> or <CommandDialog>.`);return n}const U=["value","placeholder","autofocus"],E=e.defineComponent({__name:"CommandInput",props:{placeholder:{default:"Type a command or search..."},autoFocus:{type:Boolean,default:!0}},setup(o,{expose:t}){const n=b(C,"CommandInput"),s=e.inject(S,()=>{}),r=e.ref(null);t({inputRef:r});function a(c){n.searchQuery.value=c.target.value,n.activeIndex.value=0}function m(c){var l;if(c.key==="ArrowDown")c.preventDefault(),n.selectNext();else if(c.key==="ArrowUp")c.preventDefault(),n.selectPrev();else if(c.key==="Enter"){c.preventDefault();const d=n.filteredItems.value[n.activeIndex.value];d&&!d.disabled&&((l=d.onSelect)==null||l.call(d,d),s(d))}}return(c,l)=>(e.openBlock(),e.createElementBlock("input",{ref_key:"inputRef",ref:r,"data-cmdk-input":"",value:e.unref(n).searchQuery.value,placeholder:o.placeholder,role:"searchbox",autocomplete:"off",autocorrect:"off",spellcheck:"false",autofocus:o.autoFocus,onInput:a,onKeydown:m},null,40,U))}}),z={key:0,"data-cmdk-empty":""},w=e.defineComponent({__name:"CommandEmpty",setup(o){const t=b(C,"CommandEmpty");return(n,s)=>e.unref(t).searchQuery.value&&e.unref(t).filteredItems.value.length===0?(e.openBlock(),e.createElementBlock("div",z,[e.renderSlot(n.$slots,"default",{},()=>[s[0]||(s[0]=e.createElementVNode("span",null,"No results found.",-1))])])):e.createCommentVNode("",!0)}}),H={key:0,"data-cmdk-loading":""},I=e.defineComponent({__name:"CommandLoading",props:{loading:{type:Boolean,default:!1}},setup(o){return(t,n)=>o.loading?(e.openBlock(),e.createElementBlock("div",H,[e.renderSlot(t.$slots,"default",{},()=>[n[0]||(n[0]=e.createElementVNode("span",null,"Loading...",-1))])])):e.createCommentVNode("",!0)}}),X={"data-cmdk-group":"",role:"group"},J={key:0,"data-cmdk-group-heading":"",role:"presentation"},W={"data-cmdk-group-items":"",role:"group"},N=e.defineComponent({__name:"CommandGroup",props:{heading:{}},setup(o){return(t,n)=>(e.openBlock(),e.createElementBlock("div",X,[o.heading?(e.openBlock(),e.createElementBlock("div",J,e.toDisplayString(o.heading),1)):e.createCommentVNode("",!0),e.createElementVNode("div",W,[e.renderSlot(t.$slots,"default")])]))}}),Y=["aria-selected","aria-disabled","data-value"],Z={key:0,"data-cmdk-item-icon":""},v={"data-cmdk-item-label":""},ee={key:1,"data-cmdk-item-shortcut":""},$=e.defineComponent({__name:"CommandItem",props:{value:{},label:{},keywords:{},shortcut:{},disabled:{type:Boolean,default:!1},icon:{},onSelect:{}},setup(o){const t=o,n=b(C,"CommandItem"),s=e.inject(Q,()=>new Map),r=e.computed(()=>({value:t.value,label:t.label,keywords:t.keywords,shortcut:t.shortcut,disabled:t.disabled,icon:t.icon,onSelect:t.onSelect})),a=e.computed(()=>{const d=n.filteredItems.value[n.activeIndex.value];return(d==null?void 0:d.value)===t.value}),m=e.inject(x,()=>!0),c=e.inject(S,()=>{});function l(){var d;t.disabled||((d=t.onSelect)==null||d.call(t,r.value),c(r.value),m()&&n.close())}return(d,h)=>(e.openBlock(),e.createElementBlock("div",{"data-cmdk-item":"",role:"option","aria-selected":a.value,"aria-disabled":o.disabled,"data-value":o.value,class:e.normalizeClass({active:a.value,disabled:o.disabled}),onClick:l,onPointerenter:h[0]||(h[0]=()=>{const k=e.unref(s)().get(o.value);k!==void 0&&(e.unref(n).activeIndex.value=k)})},[e.renderSlot(d.$slots,"default",{item:r.value,active:a.value},()=>[o.icon?(e.openBlock(),e.createElementBlock("span",Z,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(o.icon)))])):e.createCommentVNode("",!0),e.createElementVNode("span",v,e.toDisplayString(o.label||o.value),1),o.shortcut?(e.openBlock(),e.createElementBlock("span",ee,e.toDisplayString(o.shortcut),1)):e.createCommentVNode("",!0)])],42,Y))}}),te=(o,t)=>{const n=o.__vccOpts||o;for(const[s,r]of t)n[s]=r;return n},oe={},ne={"data-cmdk-separator":"",role:"separator"};function ae(o,t){return e.openBlock(),e.createElementBlock("div",ne)}const D=te(oe,[["render",ae]]),le={"data-cmdk-list":"",role:"listbox"},ce={"aria-live":"polite","aria-atomic":"true",class:"sr-only"},V=e.defineComponent({__name:"CommandList",setup(o){const t=b(C,"CommandList"),n=e.inject(M,()=>!1),s=e.computed(()=>t.groupedItems.value);return(r,a)=>(e.openBlock(),e.createElementBlock("div",le,[e.createElementVNode("div",ce,[e.unref(t).searchQuery.value&&e.unref(t).filteredItems.value.length===0?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[e.createTextVNode("No results found")],64)):e.unref(n)()?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[e.createTextVNode("Loading")],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.createTextVNode(e.toDisplayString(e.unref(t).filteredItems.value.length)+" items",1)],64))]),e.createVNode(w),e.createVNode(I,{loading:e.unref(n)()},null,8,["loading"]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s.value,m=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:m.heading||"__ungrouped__"},[e.createVNode(N,{heading:m.heading},{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(m.items,c=>(e.openBlock(),e.createBlock($,{key:c.value,value:c.value,label:c.label,shortcut:c.shortcut,disabled:c.disabled,icon:c.icon,"on-select":c.onSelect},null,8,["value","label","shortcut","disabled","icon","on-select"]))),128))]),_:2},1032,["heading"]),m!==s.value[s.value.length-1]?(e.openBlock(),e.createBlock(D,{key:0})):e.createCommentVNode("",!0)],64))),128))]))}}),re={"data-cmdk-dialog-wrapper":""},se={"data-cmdk-dialog-header":""},de={"data-cmdk-dialog-body":""},ie={key:0,"data-cmdk-dialog-footer":""},O=e.defineComponent({__name:"CommandDialog",props:{items:{default:()=>[]},visible:{type:Boolean,default:!1},searchQuery:{},placeholder:{default:"Type a command or search..."},filter:{},autoFocus:{type:Boolean,default:!0},closeOnSelect:{type:Boolean,default:!0},loading:{type:Boolean,default:!1}},emits:["update:visible","update:searchQuery","select"],setup(o,{emit:t}){const n=o,s=t,{state:r}=T({filter:n.filter,loading:n.loading,closeOnSelect:n.closeOnSelect},s),a=e.ref(null);e.watch(()=>n.items,l=>{r.items.value=l},{immediate:!0}),e.watch(()=>n.visible,l=>{r.visible.value=l},{immediate:!0}),e.watch(()=>n.searchQuery,l=>{l!==void 0&&(r.searchQuery.value=l)}),e.watch(r.searchQuery,l=>s("update:searchQuery",l)),e.watch(r.visible,async l=>{var d,h;s("update:visible",l),l&&(await e.nextTick(),(h=(d=a.value)==null?void 0:d.inputRef)==null||h.focus())});function m(l){l.target===l.currentTarget&&r.close()}function c(l){if(l.key==="Escape"&&(l.preventDefault(),r.close()),l.key==="Tab"){const h=l.currentTarget.querySelectorAll('input, button, [href], select, textarea, [tabindex]:not([tabindex="-1"])');if(h.length===0)return;const k=h[0],B=h[h.length-1];l.shiftKey?document.activeElement===k&&(l.preventDefault(),B.focus()):document.activeElement===B&&(l.preventDefault(),k.focus())}}return(l,d)=>(e.openBlock(),e.createBlock(e.Teleport,{to:"body"},[e.createVNode(e.Transition,{name:"cmdk-dialog"},{default:e.withCtx(()=>[e.unref(r).visible.value?(e.openBlock(),e.createElementBlock("div",{key:0,"data-cmdk-dialog":"",onKeydown:c},[e.createElementVNode("div",{"data-cmdk-dialog-mask":"",onClick:m}),e.createElementVNode("div",re,[e.createElementVNode("div",se,[e.renderSlot(l.$slots,"header",{},()=>[e.createVNode(E,{ref_key:"commandInputRef",ref:a,placeholder:o.placeholder,"auto-focus":o.autoFocus},null,8,["placeholder","auto-focus"])])]),e.createElementVNode("div",de,[e.renderSlot(l.$slots,"body",{},()=>[e.createVNode(V)])]),l.$slots.footer?(e.openBlock(),e.createElementBlock("div",ie,[e.renderSlot(l.$slots,"footer")])):e.createCommentVNode("",!0)])],32)):e.createCommentVNode("",!0)]),_:3})]))}}),me={Menu:K,Dialog:O,Input:E,List:V,Group:N,Item:$,Empty:w,Separator:D,Loading:I};f.Command=me,f.CommandDialog=O,f.CommandEmpty=w,f.CommandGroup=N,f.CommandInput=E,f.CommandItem=$,f.CommandList=V,f.CommandLoading=I,f.CommandMenu=K,f.CommandSeparator=D,f.useCommandMenu=L,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-command-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "⌘K — Fast, composable, unstyled command menu for Vue 3",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"packageManager": "pnpm@11.1.2",
|
|
6
7
|
"main": "./dist/vue-cmdk.umd.cjs",
|
|
7
8
|
"module": "./dist/vue-cmdk.js",
|
|
8
9
|
"exports": {
|
|
@@ -10,14 +11,30 @@
|
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"import": "./dist/vue-cmdk.js",
|
|
12
13
|
"require": "./dist/vue-cmdk.umd.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./composables": {
|
|
16
|
+
"types": "./dist/useCommandMenu.d.ts",
|
|
17
|
+
"import": "./dist/vue-cmdk.js"
|
|
18
|
+
},
|
|
19
|
+
"./types": {
|
|
20
|
+
"types": "./dist/types.d.ts",
|
|
21
|
+
"import": "./dist/vue-cmdk.js"
|
|
13
22
|
}
|
|
14
23
|
},
|
|
15
24
|
"files": [
|
|
16
25
|
"dist/vue-cmdk.js",
|
|
17
26
|
"dist/vue-cmdk.umd.cjs",
|
|
18
|
-
"dist
|
|
27
|
+
"dist/**/*.d.ts"
|
|
19
28
|
],
|
|
20
29
|
"sideEffects": false,
|
|
30
|
+
"scripts": {
|
|
31
|
+
"dev": "vite",
|
|
32
|
+
"build": "vite build && node scripts/postbuild.mjs",
|
|
33
|
+
"preview": "vite preview",
|
|
34
|
+
"build:demo": "vite build --config vite.demo.config.ts",
|
|
35
|
+
"typecheck": "vue-tsc --noEmit",
|
|
36
|
+
"prepublishOnly": "pnpm run build"
|
|
37
|
+
},
|
|
21
38
|
"keywords": [
|
|
22
39
|
"vue",
|
|
23
40
|
"command",
|
|
@@ -60,12 +77,5 @@
|
|
|
60
77
|
"vite-plugin-dts": "^4.0.0",
|
|
61
78
|
"vue": "^3.5.0",
|
|
62
79
|
"vue-tsc": "^2.0.0"
|
|
63
|
-
},
|
|
64
|
-
"scripts": {
|
|
65
|
-
"dev": "vite",
|
|
66
|
-
"build": "vite build && node scripts/postbuild.mjs",
|
|
67
|
-
"preview": "vite preview",
|
|
68
|
-
"build:demo": "vite build --config vite.demo.config.ts",
|
|
69
|
-
"typecheck": "vue-tsc --noEmit"
|
|
70
80
|
}
|
|
71
|
-
}
|
|
81
|
+
}
|