vue-command-kit 0.1.0 → 0.1.2

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/dist/vue-cmdk.js CHANGED
@@ -1,275 +1,328 @@
1
- import { ref as O, computed as E, watch as C, onUnmounted as oe, defineComponent as I, provide as g, openBlock as u, createElementBlock as i, renderSlot as S, unref as m, inject as w, createElementVNode as k, createCommentVNode as $, toDisplayString as B, normalizeClass as ae, createBlock as T, resolveDynamicComponent as ne, Fragment as L, createTextVNode as N, createVNode as D, renderList as V, withCtx as j, nextTick as le, Teleport as se, Transition as re } from "vue";
2
- const ce = {
1
+ import { ref as x, computed as I, watch as k, onUnmounted as ie, provide as B, defineComponent as $, openBlock as d, createElementBlock as h, renderSlot as S, unref as v, inject as M, createElementVNode as b, createCommentVNode as w, toDisplayString as T, isVNode as de, normalizeClass as me, createBlock as R, resolveDynamicComponent as fe, Fragment as L, createTextVNode as P, createVNode as K, renderList as q, withCtx as z, nextTick as ve, Teleport as pe, Transition as he } from "vue";
2
+ const O = "__ungrouped__", ye = {
3
3
  "⌘": "metaKey",
4
4
  "⌃": "ctrlKey",
5
5
  "⌥": "altKey",
6
6
  "⇧": "shiftKey"
7
- };
8
- function ue(o) {
9
- let e = o;
10
- const s = {};
11
- let n = !0;
12
- for (; n && e.length > 0; ) {
13
- n = !1;
14
- for (const [r, t] of Object.entries(ce))
15
- if (e.startsWith(r)) {
16
- s[t] = !0, e = e.slice(r.length), n = !0;
17
- break;
18
- }
7
+ }, _e = /^([⌘⌃⌥⇧]+)(.+)$/;
8
+ function ge(o) {
9
+ if (!o) return null;
10
+ const e = _e.exec(o);
11
+ if (!e) return { key: o.toLowerCase() };
12
+ const [, a, s] = e, r = {};
13
+ for (const l of a) {
14
+ const m = ye[l];
15
+ m && (r[m] = !0);
19
16
  }
20
- return e ? { ...s, key: e.toLowerCase() } : null;
17
+ return { ...r, key: s.toLowerCase() };
21
18
  }
22
- function ie(o, e) {
19
+ function ke(o, e) {
23
20
  return e ? o.key.toLowerCase() === e.key && !!o.metaKey == !!e.metaKey && !!o.ctrlKey == !!e.ctrlKey && !!o.altKey == !!e.altKey && !!o.shiftKey == !!e.shiftKey : !1;
24
21
  }
25
- function q(o, e) {
26
- const s = O(!1), n = O(""), r = O(0), t = O([]), v = () => {
27
- s.value = !s.value;
28
- }, a = () => {
29
- s.value = !0, r.value = 0;
30
- }, l = () => {
31
- s.value = !1, n.value = "";
22
+ function be(o, e) {
23
+ const a = typeof o == "function" ? { filter: o } : o ?? {}, { filter: s, shouldFilter: r = !0, loop: l = !0 } = a, m = x(!1), n = x(""), t = x(0), i = x(), c = x([]), _ = () => {
24
+ m.value = !m.value;
25
+ }, f = () => {
26
+ m.value = !0, t.value = 0;
27
+ }, C = () => {
28
+ m.value = !1, n.value = "";
32
29
  };
33
- function h(c, f) {
34
- if (!f.trim()) return c;
35
- const d = f.toLowerCase();
36
- return c.filter((_) => {
37
- var b, G;
38
- return !!(_.value.toLowerCase().includes(d) || (b = _.label) != null && b.toLowerCase().includes(d) || (G = _.keywords) != null && G.some((te) => te.toLowerCase().includes(d)));
30
+ function N(u, y) {
31
+ if (!y.trim()) return u;
32
+ const p = y.toLowerCase();
33
+ return u.filter((g) => {
34
+ var D, j;
35
+ return !!(g.value.toLowerCase().includes(p) || (D = g.label) != null && D.toLowerCase().includes(p) || (j = g.keywords) != null && j.some((ce) => ce.toLowerCase().includes(p)));
39
36
  });
40
37
  }
41
- function p(c) {
42
- const f = /* @__PURE__ */ new Map();
43
- for (const _ of c) {
44
- const b = _.group || "__ungrouped__";
45
- f.has(b) || f.set(b, []), f.get(b).push(_);
38
+ function G(u) {
39
+ const y = /* @__PURE__ */ new Map();
40
+ for (const g of u) {
41
+ const D = g.group || O;
42
+ y.has(D) ? y.get(D).push(g) : y.set(D, [g]);
46
43
  }
47
- const d = [];
48
- f.has("__ungrouped__") && (d.push({ heading: "", items: f.get("__ungrouped__") }), f.delete("__ungrouped__"));
49
- for (const [_, b] of f)
50
- d.push({ heading: _, items: b });
51
- return d;
44
+ const p = [];
45
+ y.has(O) && (p.push({ heading: "", items: y.get(O) }), y.delete(O));
46
+ for (const g of [...y.keys()].sort())
47
+ p.push({ heading: g, items: y.get(g) });
48
+ return p;
52
49
  }
53
- const y = E(() => {
54
- if (o) {
55
- const c = o(t.value, n.value);
56
- if (c !== null) return c;
50
+ const Q = I(() => {
51
+ if (s) {
52
+ const u = s(c.value, n.value);
53
+ if (u !== null) return u;
57
54
  }
58
- return h(t.value, n.value);
59
- }), Q = E(() => p(y.value));
60
- function Y() {
61
- const c = y.value.length;
62
- c !== 0 && (r.value = (r.value + 1) % c);
55
+ return r ? N(c.value, n.value) : c.value;
56
+ }), ne = I(() => G(Q.value));
57
+ function se() {
58
+ const u = Q.value.length;
59
+ u !== 0 && (l ? t.value = (t.value + 1) % u : t.value = Math.min(t.value + 1, u - 1));
63
60
  }
64
- function Z() {
65
- const c = y.value.length;
66
- c !== 0 && (r.value = (r.value - 1 + c) % c);
61
+ function ue() {
62
+ const u = Q.value.length;
63
+ u !== 0 && (l ? t.value = (t.value - 1 + u) % u : t.value = Math.max(t.value - 1, 0));
67
64
  }
68
- function ee() {
69
- var f;
70
- const c = y.value[r.value];
71
- c && !c.disabled && ((f = c.onSelect) == null || f.call(c, c), l());
65
+ function re() {
66
+ var y;
67
+ const u = Q.value[t.value];
68
+ u && !u.disabled && (i.value = u.value, (y = u.onSelect) == null || y.call(u, u), C());
72
69
  }
73
- function P(c) {
74
- var f;
75
- for (const d of t.value) {
76
- if (d.disabled || !d.shortcut) continue;
77
- const _ = ue(d.shortcut);
78
- if (ie(c, _)) {
79
- c.preventDefault(), c.stopPropagation(), (f = d.onSelect) == null || f.call(d, d), e == null || e(d), l();
70
+ function U(u) {
71
+ var y;
72
+ for (const p of c.value) {
73
+ if (p.disabled || !p.shortcut) continue;
74
+ const g = ge(p.shortcut);
75
+ if (ke(u, g)) {
76
+ u.preventDefault(), u.stopPropagation(), i.value = p.value, (y = p.onSelect) == null || y.call(p, p), e == null || e(p), C();
80
77
  return;
81
78
  }
82
79
  }
83
80
  }
84
- let x = null;
85
- return C(
86
- t,
87
- (c) => {
88
- x && (x(), x = null), c.some((d) => d.shortcut) && typeof window < "u" && (window.addEventListener("keydown", P), x = () => window.removeEventListener("keydown", P));
81
+ let E = null;
82
+ return k(
83
+ c,
84
+ (u) => {
85
+ E && (E(), E = null), u.some((p) => p.shortcut) && typeof window < "u" && (window.addEventListener("keydown", U), E = () => window.removeEventListener("keydown", U));
89
86
  },
90
- { immediate: !0, flush: "sync" }
91
- ), oe(() => {
92
- x && x();
87
+ { immediate: !0, deep: !0, flush: "post" }
88
+ ), ie(() => {
89
+ E && E();
93
90
  }), {
94
- visible: s,
91
+ visible: m,
95
92
  searchQuery: n,
96
- activeIndex: r,
97
- items: t,
98
- toggle: v,
99
- open: a,
100
- close: l,
101
- defaultFilter: h,
102
- groupItems: p,
103
- filteredItems: y,
104
- groupedItems: Q,
105
- selectNext: Y,
106
- selectPrev: Z,
107
- selectCurrent: ee
93
+ activeIndex: t,
94
+ selectedValue: i,
95
+ items: c,
96
+ toggle: _,
97
+ open: f,
98
+ close: C,
99
+ defaultFilter: N,
100
+ groupItems: G,
101
+ filteredItems: Q,
102
+ groupedItems: ne,
103
+ selectNext: se,
104
+ selectPrev: ue,
105
+ selectCurrent: re
108
106
  };
109
107
  }
110
- const K = Symbol("cmdk-state"), A = Symbol("cmdk-loading"), F = Symbol("cmdk-close-on-select"), M = Symbol("cmdk-select-handler"), de = {
108
+ const F = Symbol("cmdk-state"), H = Symbol("cmdk-loading"), X = Symbol("cmdk-close-on-select"), V = Symbol("cmdk-select-handler"), Y = Symbol("cmdk-item-index-map");
109
+ function J(o, e, a) {
110
+ const {
111
+ filter: s,
112
+ loading: r = !1,
113
+ closeOnSelect: l = !0,
114
+ shouldFilter: m = !0,
115
+ loop: n = !0
116
+ } = o, i = be({ filter: s, shouldFilter: m, loop: n }, (f) => {
117
+ e("select", f), e("update:value", f.value), l && i.close();
118
+ });
119
+ k(
120
+ () => o.value,
121
+ (f) => {
122
+ f !== void 0 && (i.selectedValue.value = f);
123
+ },
124
+ { immediate: !0 }
125
+ ), B(F, i), B(H, () => r), B(X, () => l), B(V, (f) => {
126
+ e("select", f), l && i.close();
127
+ });
128
+ const c = I(() => {
129
+ const f = /* @__PURE__ */ new Map();
130
+ return i.filteredItems.value.forEach((C, N) => f.set(C.value, N)), f;
131
+ });
132
+ B(Y, () => c.value);
133
+ function _(f) {
134
+ e("select", f), l && i.close();
135
+ }
136
+ return { state: i, handleSelect: _ };
137
+ }
138
+ const Ce = {
111
139
  "data-cmdk-root": "",
112
140
  role: "combobox",
113
141
  "aria-expanded": "true",
114
142
  "aria-haspopup": "listbox"
115
- }, fe = /* @__PURE__ */ I({
143
+ }, Ie = /* @__PURE__ */ $({
116
144
  __name: "CommandMenu",
117
145
  props: {
118
- visible: { type: Boolean },
146
+ visible: { type: Boolean, default: !0 },
119
147
  searchQuery: {},
120
148
  placeholder: { default: "Type a command or search..." },
121
149
  filter: {},
122
150
  autoFocus: { type: Boolean, default: !0 },
123
151
  closeOnSelect: { type: Boolean, default: !0 },
124
- loading: { type: Boolean }
152
+ loading: { type: Boolean },
153
+ label: {},
154
+ shouldFilter: { type: Boolean, default: !0 },
155
+ loop: { type: Boolean, default: !0 },
156
+ value: {}
125
157
  },
126
- emits: ["update:visible", "update:searchQuery", "select"],
127
- setup(o, { expose: e, emit: s }) {
128
- const n = o, r = s, t = q(n.filter, (a) => {
129
- r("select", a), n.closeOnSelect && t.close();
130
- });
131
- t.visible.value = n.visible ?? !0, t.searchQuery.value = n.searchQuery ?? "", g(K, t), g("cmdk-filter", n.filter), g(A, () => n.loading ?? !1), g(F, () => n.closeOnSelect), g(M, (a) => {
132
- r("select", a), n.closeOnSelect && t.close();
133
- }), C(
134
- () => n.visible,
135
- (a) => {
136
- a !== void 0 && (t.visible.value = a);
137
- }
138
- ), C(t.visible, (a) => r("update:visible", a)), C(
139
- () => n.searchQuery,
140
- (a) => {
141
- a !== void 0 && (t.searchQuery.value = a);
158
+ emits: ["update:visible", "update:searchQuery", "update:value", "select"],
159
+ setup(o, { expose: e, emit: a }) {
160
+ const s = o, r = a, { state: l, handleSelect: m } = J(
161
+ {
162
+ filter: s.filter,
163
+ loading: s.loading,
164
+ closeOnSelect: s.closeOnSelect,
165
+ shouldFilter: s.shouldFilter,
166
+ loop: s.loop,
167
+ value: s.value
168
+ },
169
+ r
170
+ );
171
+ return k(
172
+ () => s.visible,
173
+ (n) => {
174
+ n !== void 0 && (l.visible.value = n);
175
+ },
176
+ { immediate: !0 }
177
+ ), k(l.visible, (n) => r("update:visible", n)), k(
178
+ () => s.searchQuery,
179
+ (n) => {
180
+ n !== void 0 && (l.searchQuery.value = n);
142
181
  }
143
- ), C(t.searchQuery, (a) => r("update:searchQuery", a));
144
- function v(a) {
145
- r("select", a), n.closeOnSelect && t.close();
146
- }
147
- return e({
148
- open: t.open,
149
- close: t.close,
150
- toggle: t.toggle,
151
- searchQuery: t.searchQuery,
152
- items: t.items,
153
- filteredItems: t.filteredItems
154
- }), (a, l) => (u(), i("div", de, [
155
- S(a.$slots, "default", {
156
- items: m(t).items,
157
- filteredItems: m(t).filteredItems,
158
- searchQuery: m(t).searchQuery,
159
- selectNext: m(t).selectNext,
160
- selectPrev: m(t).selectPrev,
161
- selectCurrent: m(t).selectCurrent,
162
- handleSelect: v
182
+ ), k(l.searchQuery, (n) => r("update:searchQuery", n)), e({
183
+ open: l.open,
184
+ close: l.close,
185
+ toggle: l.toggle,
186
+ searchQuery: l.searchQuery,
187
+ items: l.items,
188
+ filteredItems: l.filteredItems
189
+ }), (n, t) => (d(), h("div", Ce, [
190
+ S(n.$slots, "default", {
191
+ items: v(l).items,
192
+ filteredItems: v(l).filteredItems,
193
+ searchQuery: v(l).searchQuery,
194
+ selectNext: v(l).selectNext,
195
+ selectPrev: v(l).selectPrev,
196
+ selectCurrent: v(l).selectCurrent,
197
+ handleSelect: v(m)
163
198
  })
164
199
  ]));
165
200
  }
166
- }), me = ["value", "placeholder", "autofocus"], R = /* @__PURE__ */ I({
201
+ });
202
+ function A(o, e) {
203
+ const a = M(o);
204
+ if (a == null)
205
+ throw new Error(
206
+ `[vue-cmdk] <${e}> must be used inside <CommandMenu> or <CommandDialog>.`
207
+ );
208
+ return a;
209
+ }
210
+ const Se = ["value", "placeholder", "aria-activedescendant", "autofocus"], W = /* @__PURE__ */ $({
167
211
  __name: "CommandInput",
168
212
  props: {
169
213
  placeholder: { default: "Type a command or search..." },
170
214
  autoFocus: { type: Boolean, default: !0 }
171
215
  },
172
- setup(o) {
173
- const e = w(K), s = w(M, () => {
216
+ setup(o, { expose: e }) {
217
+ const a = A(F, "CommandInput"), s = M(V, () => {
218
+ }), r = x(null);
219
+ e({ inputRef: r });
220
+ const l = I(() => {
221
+ const t = a.filteredItems.value[a.activeIndex.value];
222
+ return t ? `cmdk-item-${t.value}` : void 0;
174
223
  });
175
- function n(t) {
176
- e.searchQuery.value = t.target.value, e.activeIndex.value = 0;
224
+ function m(t) {
225
+ const i = t.target;
226
+ i && (a.searchQuery.value = i.value, a.activeIndex.value = 0);
177
227
  }
178
- function r(t) {
179
- var v;
228
+ function n(t) {
229
+ var i;
180
230
  if (t.key === "ArrowDown")
181
- t.preventDefault(), e.selectNext();
231
+ t.preventDefault(), a.selectNext();
182
232
  else if (t.key === "ArrowUp")
183
- t.preventDefault(), e.selectPrev();
233
+ t.preventDefault(), a.selectPrev();
184
234
  else if (t.key === "Enter") {
185
235
  t.preventDefault();
186
- const a = e.filteredItems.value[e.activeIndex.value];
187
- a && !a.disabled && ((v = a.onSelect) == null || v.call(a, a), s(a));
236
+ const c = a.filteredItems.value[a.activeIndex.value];
237
+ c && !c.disabled && ((i = c.onSelect) == null || i.call(c, c), s(c));
188
238
  }
189
239
  }
190
- return (t, v) => (u(), i("input", {
240
+ return (t, i) => (d(), h("input", {
241
+ ref_key: "inputRef",
242
+ ref: r,
191
243
  "data-cmdk-input": "",
192
- value: m(e).searchQuery.value,
244
+ value: v(a).searchQuery.value,
193
245
  placeholder: o.placeholder,
194
246
  role: "searchbox",
247
+ "aria-activedescendant": l.value,
195
248
  autocomplete: "off",
196
249
  autocorrect: "off",
197
250
  spellcheck: "false",
198
251
  autofocus: o.autoFocus,
199
- onInput: n,
200
- onKeydown: r
201
- }, null, 40, me));
252
+ onInput: m,
253
+ onKeydown: n
254
+ }, null, 40, Se));
202
255
  }
203
- }), ve = {
256
+ }), we = {
204
257
  key: 0,
205
258
  "data-cmdk-empty": ""
206
- }, U = /* @__PURE__ */ I({
259
+ }, Z = /* @__PURE__ */ $({
207
260
  __name: "CommandEmpty",
208
261
  setup(o) {
209
- const e = w(K);
210
- return (s, n) => m(e).searchQuery.value && m(e).filteredItems.value.length === 0 ? (u(), i("div", ve, [
211
- S(s.$slots, "default", {}, () => [
212
- n[0] || (n[0] = k("span", null, "No results found.", -1))
262
+ const e = A(F, "CommandEmpty");
263
+ return (a, s) => v(e).searchQuery.value && v(e).filteredItems.value.length === 0 ? (d(), h("div", we, [
264
+ S(a.$slots, "default", {}, () => [
265
+ s[0] || (s[0] = b("span", null, "No results found.", -1))
213
266
  ])
214
- ])) : $("", !0);
267
+ ])) : w("", !0);
215
268
  }
216
- }), he = {
269
+ }), $e = {
217
270
  key: 0,
218
271
  "data-cmdk-loading": ""
219
- }, z = /* @__PURE__ */ I({
272
+ }, ee = /* @__PURE__ */ $({
220
273
  __name: "CommandLoading",
221
274
  props: {
222
- loading: { type: Boolean, default: !1 }
275
+ loading: { type: Boolean }
223
276
  },
224
277
  setup(o) {
225
- return (e, s) => o.loading ? (u(), i("div", he, [
278
+ return (e, a) => o.loading ? (d(), h("div", $e, [
226
279
  S(e.$slots, "default", {}, () => [
227
- s[0] || (s[0] = k("span", null, "Loading...", -1))
280
+ a[0] || (a[0] = b("span", null, "Loading...", -1))
228
281
  ])
229
- ])) : $("", !0);
282
+ ])) : w("", !0);
230
283
  }
231
- }), pe = {
284
+ }), xe = {
232
285
  "data-cmdk-group": "",
233
286
  role: "group"
234
- }, ye = {
287
+ }, Ee = {
235
288
  key: 0,
236
289
  "data-cmdk-group-heading": "",
237
290
  role: "presentation"
238
- }, _e = {
291
+ }, De = {
239
292
  "data-cmdk-group-items": "",
240
293
  role: "group"
241
- }, H = /* @__PURE__ */ I({
294
+ }, te = /* @__PURE__ */ $({
242
295
  __name: "CommandGroup",
243
296
  props: {
244
297
  heading: {}
245
298
  },
246
299
  setup(o) {
247
- return (e, s) => (u(), i("div", pe, [
248
- o.heading ? (u(), i("div", ye, B(o.heading), 1)) : $("", !0),
249
- k("div", _e, [
300
+ return (e, a) => (d(), h("div", xe, [
301
+ o.heading ? (d(), h("div", Ee, T(o.heading), 1)) : w("", !0),
302
+ b("div", De, [
250
303
  S(e.$slots, "default")
251
304
  ])
252
305
  ]));
253
306
  }
254
- }), ge = ["aria-selected", "aria-disabled", "data-value"], ke = {
307
+ }), Le = ["id", "aria-selected", "aria-disabled", "data-value"], Me = {
255
308
  key: 0,
256
309
  "data-cmdk-item-icon": ""
257
- }, be = { "data-cmdk-item-label": "" }, Ce = {
310
+ }, Ke = { "data-cmdk-item-label": "" }, Qe = {
258
311
  key: 1,
259
312
  "data-cmdk-item-shortcut": ""
260
- }, W = /* @__PURE__ */ I({
313
+ }, oe = /* @__PURE__ */ $({
261
314
  __name: "CommandItem",
262
315
  props: {
263
316
  value: {},
264
- label: {},
265
- keywords: {},
266
- shortcut: {},
317
+ label: { default: void 0 },
318
+ keywords: { default: void 0 },
319
+ shortcut: { default: void 0 },
267
320
  disabled: { type: Boolean, default: !1 },
268
- icon: {},
269
- onSelect: {}
321
+ icon: { type: [Object, Function], default: void 0 },
322
+ onSelect: { type: Function, default: void 0 }
270
323
  },
271
324
  setup(o) {
272
- const e = o, s = w(K), n = E(() => ({
325
+ const e = o, a = A(F, "CommandItem"), s = M(Y, () => /* @__PURE__ */ new Map()), r = I(() => `cmdk-item-${e.value}`), l = I(() => ({
273
326
  value: e.value,
274
327
  label: e.label,
275
328
  keywords: e.keywords,
@@ -277,210 +330,231 @@ const K = Symbol("cmdk-state"), A = Symbol("cmdk-loading"), F = Symbol("cmdk-clo
277
330
  disabled: e.disabled,
278
331
  icon: e.icon,
279
332
  onSelect: e.onSelect
280
- })), r = E(() => {
281
- const l = s.filteredItems.value[s.activeIndex.value];
282
- return (l == null ? void 0 : l.value) === e.value;
283
- }), t = w(F, () => !0), v = w(M, () => {
333
+ })), m = I(() => e.icon ? de(e.icon) ? () => e.icon : e.icon : null), n = I(() => {
334
+ const _ = a.filteredItems.value[a.activeIndex.value];
335
+ return (_ == null ? void 0 : _.value) === e.value;
336
+ }), t = M(X, () => !0), i = M(V, () => {
284
337
  });
285
- function a() {
286
- var l;
287
- e.disabled || ((l = e.onSelect) == null || l.call(e, n.value), v(n.value), t() && s.close());
338
+ function c() {
339
+ var _;
340
+ e.disabled || ((_ = e.onSelect) == null || _.call(e, l.value), i(l.value), t() && a.close());
288
341
  }
289
- return (l, h) => (u(), i("div", {
342
+ return (_, f) => (d(), h("div", {
343
+ id: r.value,
290
344
  "data-cmdk-item": "",
291
345
  role: "option",
292
- "aria-selected": r.value,
346
+ "aria-selected": n.value,
293
347
  "aria-disabled": o.disabled,
294
348
  "data-value": o.value,
295
- class: ae({ active: r.value, disabled: o.disabled }),
296
- onClick: a,
297
- onPointerenter: h[0] || (h[0] = () => {
298
- const p = m(s).filteredItems.value.findIndex((y) => y.value === o.value);
299
- p >= 0 && (m(s).activeIndex.value = p);
349
+ class: me({ active: n.value, disabled: o.disabled }),
350
+ onClick: c,
351
+ onPointerenter: f[0] || (f[0] = () => {
352
+ const C = v(s)().get(o.value);
353
+ C !== void 0 && (v(a).activeIndex.value = C);
300
354
  })
301
355
  }, [
302
- S(l.$slots, "default", {
303
- item: n.value,
304
- active: r.value
356
+ S(_.$slots, "default", {
357
+ item: l.value,
358
+ active: n.value
305
359
  }, () => [
306
- o.icon ? (u(), i("span", ke, [
307
- (u(), T(ne(o.icon)))
308
- ])) : $("", !0),
309
- k("span", be, B(o.label || o.value), 1),
310
- o.shortcut ? (u(), i("span", Ce, B(o.shortcut), 1)) : $("", !0)
360
+ m.value ? (d(), h("span", Me, [
361
+ (d(), R(fe(m.value)))
362
+ ])) : w("", !0),
363
+ b("span", Ke, T(o.label || o.value), 1),
364
+ o.shortcut ? (d(), h("span", Qe, T(o.shortcut), 1)) : w("", !0)
311
365
  ])
312
- ], 42, ge));
366
+ ], 42, Le));
313
367
  }
314
- }), Se = (o, e) => {
315
- const s = o.__vccOpts || o;
316
- for (const [n, r] of e)
317
- s[n] = r;
318
- return s;
319
- }, we = {}, $e = {
368
+ }), Be = (o, e) => {
369
+ const a = o.__vccOpts || o;
370
+ for (const [s, r] of e)
371
+ a[s] = r;
372
+ return a;
373
+ }, Fe = {}, Ne = {
320
374
  "data-cmdk-separator": "",
321
375
  role: "separator"
322
376
  };
323
- function Ie(o, e) {
324
- return u(), i("div", $e);
377
+ function Oe(o, e) {
378
+ return d(), h("div", Ne);
325
379
  }
326
- const J = /* @__PURE__ */ Se(we, [["render", Ie]]), xe = {
380
+ const ae = /* @__PURE__ */ Be(Fe, [["render", Oe]]), Te = {
327
381
  "data-cmdk-list": "",
328
382
  role: "listbox"
329
- }, Le = {
383
+ }, Re = {
330
384
  "aria-live": "polite",
331
385
  "aria-atomic": "true",
332
386
  class: "sr-only"
333
- }, X = /* @__PURE__ */ I({
387
+ }, le = /* @__PURE__ */ $({
334
388
  __name: "CommandList",
335
389
  setup(o) {
336
- const e = w(K), s = w(A, () => !1), n = E(() => e.groupedItems.value);
337
- return (r, t) => (u(), i("div", xe, [
338
- k("div", Le, [
339
- m(e).searchQuery.value && m(e).filteredItems.value.length === 0 ? (u(), i(L, { key: 0 }, [
340
- N("No results found")
341
- ], 64)) : m(s)() ? (u(), i(L, { key: 1 }, [
342
- N("Loading")
343
- ], 64)) : (u(), i(L, { key: 2 }, [
344
- N(B(m(e).filteredItems.value.length) + " items", 1)
390
+ const e = A(F, "CommandList"), a = M(H, () => !1);
391
+ return (s, r) => (d(), h("div", Te, [
392
+ b("div", Re, [
393
+ v(e).searchQuery.value && v(e).filteredItems.value.length === 0 ? (d(), h(L, { key: 0 }, [
394
+ P("No results found")
395
+ ], 64)) : v(a)() ? (d(), h(L, { key: 1 }, [
396
+ P("Loading")
397
+ ], 64)) : (d(), h(L, { key: 2 }, [
398
+ P(T(v(e).filteredItems.value.length) + " items", 1)
345
399
  ], 64))
346
400
  ]),
347
- D(U),
348
- D(z, {
349
- loading: m(s)()
401
+ K(Z),
402
+ K(ee, {
403
+ loading: v(a)()
350
404
  }, null, 8, ["loading"]),
351
- (u(!0), i(L, null, V(n.value, (v) => (u(), i(L, {
352
- key: v.heading || "__ungrouped__"
405
+ (d(!0), h(L, null, q(v(e).groupedItems.value, (l, m) => (d(), h(L, {
406
+ key: l.heading || "__ungrouped__"
353
407
  }, [
354
- D(H, {
355
- heading: v.heading
408
+ K(te, {
409
+ heading: l.heading
356
410
  }, {
357
- default: j(() => [
358
- (u(!0), i(L, null, V(v.items, (a) => (u(), T(W, {
359
- key: a.value,
360
- value: a.value,
361
- label: a.label,
362
- shortcut: a.shortcut,
363
- disabled: a.disabled,
364
- icon: a.icon,
365
- "on-select": a.onSelect
366
- }, null, 8, ["value", "label", "shortcut", "disabled", "icon", "on-select"]))), 128))
411
+ default: z(() => [
412
+ (d(!0), h(L, null, q(l.items, (n) => (d(), R(oe, {
413
+ key: n.value,
414
+ value: n.value,
415
+ label: n.label,
416
+ keywords: n.keywords,
417
+ shortcut: n.shortcut,
418
+ disabled: n.disabled,
419
+ icon: n.icon,
420
+ "on-select": n.onSelect
421
+ }, null, 8, ["value", "label", "keywords", "shortcut", "disabled", "icon", "on-select"]))), 128))
367
422
  ]),
368
423
  _: 2
369
424
  }, 1032, ["heading"]),
370
- v !== n.value[n.value.length - 1] ? (u(), T(J, { key: 0 })) : $("", !0)
425
+ m !== v(e).groupedItems.value.length - 1 ? (d(), R(ae, { key: 0 })) : w("", !0)
371
426
  ], 64))), 128))
372
427
  ]));
373
428
  }
374
- }), De = { "data-cmdk-dialog-wrapper": "" }, Ke = { "data-cmdk-dialog-header": "" }, Ee = { "data-cmdk-dialog-body": "" }, Qe = {
429
+ }), Ae = ["aria-label"], Pe = { "data-cmdk-dialog-wrapper": "" }, Ve = { "data-cmdk-dialog-header": "" }, Ge = { "data-cmdk-dialog-body": "" }, Ue = {
375
430
  key: 0,
376
431
  "data-cmdk-dialog-footer": ""
377
- }, Oe = /* @__PURE__ */ I({
432
+ }, je = /* @__PURE__ */ $({
378
433
  __name: "CommandDialog",
379
434
  props: {
435
+ items: { default: () => [] },
380
436
  visible: { type: Boolean, default: !1 },
437
+ searchQuery: {},
381
438
  placeholder: { default: "Type a command or search..." },
439
+ filter: {},
382
440
  autoFocus: { type: Boolean, default: !0 },
383
441
  closeOnSelect: { type: Boolean, default: !0 },
384
- items: { default: () => [] },
385
- filter: {},
386
- loading: { type: Boolean, default: !1 }
442
+ loading: { type: Boolean, default: !1 },
443
+ label: {},
444
+ shouldFilter: { type: Boolean, default: !0 },
445
+ loop: { type: Boolean, default: !0 },
446
+ value: {}
387
447
  },
388
- emits: ["update:visible", "select"],
448
+ emits: ["update:visible", "update:searchQuery", "update:value", "select"],
389
449
  setup(o, { emit: e }) {
390
- const s = o, n = e, r = q(s.filter, t);
391
- g(K, r), g(A, () => s.loading), g(F, () => s.closeOnSelect), C(
392
- () => s.items,
393
- (l) => {
394
- r.items.value = l;
450
+ const a = o, s = e, { state: r } = J(
451
+ {
452
+ filter: a.filter,
453
+ loading: a.loading,
454
+ closeOnSelect: a.closeOnSelect,
455
+ shouldFilter: a.shouldFilter,
456
+ loop: a.loop,
457
+ value: a.value
458
+ },
459
+ s
460
+ ), l = x(null);
461
+ k(
462
+ () => a.items,
463
+ (t) => {
464
+ r.items.value = t;
395
465
  },
396
466
  { immediate: !0 }
397
- ), C(
398
- () => s.visible,
399
- (l) => {
400
- r.visible.value = l;
467
+ ), k(
468
+ () => a.visible,
469
+ (t) => {
470
+ r.visible.value = t;
401
471
  },
402
472
  { immediate: !0 }
403
- ), C(r.visible, async (l) => {
404
- if (n("update:visible", l), l) {
405
- await le();
406
- const h = document.querySelector("[data-cmdk-input]");
407
- h == null || h.focus();
473
+ ), k(
474
+ () => a.searchQuery,
475
+ (t) => {
476
+ t !== void 0 && (r.searchQuery.value = t);
408
477
  }
478
+ ), k(r.searchQuery, (t) => s("update:searchQuery", t)), k(r.visible, async (t) => {
479
+ var i, c;
480
+ s("update:visible", t), t && (await ve(), (c = (i = l.value) == null ? void 0 : i.inputRef) == null || c.focus());
409
481
  });
410
- function t(l) {
411
- n("select", l), s.closeOnSelect && r.close();
482
+ function m(t) {
483
+ t.target === t.currentTarget && r.close();
412
484
  }
413
- g(M, t);
414
- function v(l) {
415
- l.target === l.currentTarget && r.close();
416
- }
417
- function a(l) {
418
- if (l.key === "Escape" && (l.preventDefault(), r.close()), l.key === "Tab") {
419
- const p = l.currentTarget.querySelectorAll(
485
+ function n(t) {
486
+ if (t.key === "Escape" && (t.preventDefault(), r.close()), t.key === "Tab") {
487
+ const c = t.currentTarget.querySelectorAll(
420
488
  'input, button, [href], select, textarea, [tabindex]:not([tabindex="-1"])'
421
489
  );
422
- if (p.length === 0) return;
423
- const y = p[0], Q = p[p.length - 1];
424
- l.shiftKey ? document.activeElement === y && (l.preventDefault(), Q.focus()) : document.activeElement === Q && (l.preventDefault(), y.focus());
490
+ if (c.length === 0) return;
491
+ const _ = c[0], f = c[c.length - 1];
492
+ t.shiftKey ? document.activeElement === _ && (t.preventDefault(), f.focus()) : document.activeElement === f && (t.preventDefault(), _.focus());
425
493
  }
426
494
  }
427
- return (l, h) => (u(), T(se, { to: "body" }, [
428
- D(re, { name: "cmdk-dialog" }, {
429
- default: j(() => [
430
- m(r).visible.value ? (u(), i("div", {
495
+ return (t, i) => (d(), R(pe, { to: "body" }, [
496
+ K(he, { name: "cmdk-dialog" }, {
497
+ default: z(() => [
498
+ v(r).visible.value ? (d(), h("div", {
431
499
  key: 0,
432
500
  "data-cmdk-dialog": "",
433
- onKeydown: a
501
+ role: "dialog",
502
+ "aria-modal": "true",
503
+ "aria-label": a.label ?? "Command menu",
504
+ onKeydown: n
434
505
  }, [
435
- k("div", {
506
+ b("div", {
436
507
  "data-cmdk-dialog-mask": "",
437
- onClick: v
508
+ "aria-hidden": "true",
509
+ onClick: m
438
510
  }),
439
- k("div", De, [
440
- k("div", Ke, [
441
- S(l.$slots, "header", {}, () => [
442
- D(R, {
511
+ b("div", Pe, [
512
+ b("div", Ve, [
513
+ S(t.$slots, "header", {}, () => [
514
+ K(W, {
515
+ ref_key: "commandInputRef",
516
+ ref: l,
443
517
  placeholder: o.placeholder,
444
518
  "auto-focus": o.autoFocus
445
519
  }, null, 8, ["placeholder", "auto-focus"])
446
520
  ])
447
521
  ]),
448
- k("div", Ee, [
449
- S(l.$slots, "body", {}, () => [
450
- D(X)
522
+ b("div", Ge, [
523
+ S(t.$slots, "body", {}, () => [
524
+ K(le)
451
525
  ])
452
526
  ]),
453
- l.$slots.footer ? (u(), i("div", Qe, [
454
- S(l.$slots, "footer")
455
- ])) : $("", !0)
527
+ t.$slots.footer ? (d(), h("div", Ue, [
528
+ S(t.$slots, "footer")
529
+ ])) : w("", !0)
456
530
  ])
457
- ], 32)) : $("", !0)
531
+ ], 40, Ae)) : w("", !0)
458
532
  ]),
459
533
  _: 3
460
534
  })
461
535
  ]));
462
536
  }
463
- }), Te = {
464
- Menu: fe,
465
- Dialog: Oe,
466
- Input: R,
467
- List: X,
468
- Group: H,
469
- Item: W,
470
- Empty: U,
471
- Separator: J,
472
- Loading: z
537
+ }), ze = {
538
+ Menu: Ie,
539
+ Dialog: je,
540
+ Input: W,
541
+ List: le,
542
+ Group: te,
543
+ Item: oe,
544
+ Empty: Z,
545
+ Separator: ae,
546
+ Loading: ee
473
547
  };
474
548
  export {
475
- Te as Command,
476
- Oe as CommandDialog,
477
- U as CommandEmpty,
478
- H as CommandGroup,
479
- R as CommandInput,
480
- W as CommandItem,
481
- X as CommandList,
482
- z as CommandLoading,
483
- fe as CommandMenu,
484
- J as CommandSeparator,
485
- q as useCommandMenu
549
+ ze as Command,
550
+ je as CommandDialog,
551
+ Z as CommandEmpty,
552
+ te as CommandGroup,
553
+ W as CommandInput,
554
+ oe as CommandItem,
555
+ le as CommandList,
556
+ ee as CommandLoading,
557
+ Ie as CommandMenu,
558
+ ae as CommandSeparator,
559
+ be as useCommandMenu
486
560
  };