UNPKG

cmd-bar

Version:

Versatile Vue 3 command-bar component

1,835 lines (1,834 loc) 49.7 kB
import { unref as Z, watch as T, getCurrentScope as Ge, onScopeDispose as Fe, reactive as oe, computed as I, ref as O, readonly as Te, defineComponent as D, renderSlot as x, openBlock as E, createElementBlock as S, createElementVNode as K, Fragment as ee, renderList as fe, createVNode as me, mergeProps as Pe, withCtx as U, createCommentVNode as pe, toDisplayString as ge, nextTick as ie, createBlock as je, watchEffect as De, onMounted as We, withKeys as ze, withModifiers as Ve, createTextVNode as He, normalizeStyle as Qe, withDirectives as Ue } from "vue"; function Ye(s) { return Ge() ? (Fe(s), !0) : !1; } function L(s) { return typeof s == "function" ? s() : Z(s); } const Xe = typeof window < "u" && typeof document < "u"; typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope; const Je = Object.prototype.toString, qe = (s) => Je.call(s) === "[object Object]", te = () => { }; function Ze(s, e) { function t(...n) { return new Promise((r, o) => { Promise.resolve(s(() => e.apply(this, n), { fn: e, thisArg: this, args: n })).then(r).catch(o); }); } return t; } function et(s, e = {}) { let t, n, r = te; const o = (c) => { clearTimeout(c), r(), r = te; }; return (c) => { const l = L(s), d = L(e.maxWait); return t && o(t), l <= 0 || d !== void 0 && d <= 0 ? (n && (o(n), n = null), Promise.resolve(c())) : new Promise((u, a) => { r = e.rejectOnCancel ? a : u, d && !n && (n = setTimeout(() => { t && o(t), n = null, u(c()); }, d)), t = setTimeout(() => { n && o(n), n = null, u(c()); }, l); }); }; } function tt(s, e = 200, t = {}) { return Ze( et(e, t), s ); } function st(s, e, t) { return T( s, (r, o, i) => { r && e(r, o, i); }, { ...t, once: !1 } ); } function nt(s) { var e; const t = L(s); return (e = t == null ? void 0 : t.$el) != null ? e : t; } const Ce = Xe ? window : void 0; function J(...s) { let e, t, n, r; if (typeof s[0] == "string" || Array.isArray(s[0]) ? ([t, n, r] = s, e = Ce) : [e, t, n, r] = s, !e) return te; Array.isArray(t) || (t = [t]), Array.isArray(n) || (n = [n]); const o = [], i = () => { o.forEach((u) => u()), o.length = 0; }, c = (u, a, f, h) => (u.addEventListener(a, f, h), () => u.removeEventListener(a, f, h)), l = T( () => [nt(e), L(r)], ([u, a]) => { if (i(), !u) return; const f = qe(a) ? { ...a } : a; o.push( ...t.flatMap((h) => n.map((m) => c(u, h, m, f))) ); }, { immediate: !0, flush: "post" } ), d = () => { l(), i(); }; return Ye(d), d; } const rt = { ctrl: "control", command: "meta", cmd: "meta", option: "alt", up: "arrowup", down: "arrowdown", left: "arrowleft", right: "arrowright" }; function ot(s = {}) { const { reactive: e = !1, target: t = Ce, aliasMap: n = rt, passive: r = !0, onEventFired: o = te } = s, i = oe(/* @__PURE__ */ new Set()), c = { toJSON() { return {}; }, current: i }, l = e ? oe(c) : c, d = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set(); function a(g, _) { g in l && (e ? l[g] = _ : l[g].value = _); } function f() { i.clear(); for (const g of u) a(g, !1); } function h(g, _) { var b, C; const $ = (b = g.key) == null ? void 0 : b.toLowerCase(), p = [(C = g.code) == null ? void 0 : C.toLowerCase(), $].filter(Boolean); $ && (_ ? i.add($) : i.delete($)); for (const M of p) u.add(M), a(M, _); $ === "meta" && !_ ? (d.forEach((M) => { i.delete(M), a(M, !1); }), d.clear()) : typeof g.getModifierState == "function" && g.getModifierState("Meta") && _ && [...i, ...p].forEach((M) => d.add(M)); } J(t, "keydown", (g) => (h(g, !0), o(g)), { passive: r }), J(t, "keyup", (g) => (h(g, !1), o(g)), { passive: r }), J("blur", f, { passive: !0 }), J("focus", f, { passive: !0 }); const m = new Proxy( l, { get(g, _, b) { if (typeof _ != "string") return Reflect.get(g, _, b); if (_ = _.toLowerCase(), _ in n && (_ = n[_]), !(_ in l)) if (/[+_-]/.test(_)) { const $ = _.split(/[+_-]/g).map((N) => N.trim()); l[_] = I(() => $.every((N) => L(m[N]))); } else l[_] = O(!1); const C = Reflect.get(g, _, b); return e ? L(C) : C; } } ); return m; } function P(s) { return Array.isArray ? Array.isArray(s) : Le(s) === "[object Array]"; } const it = 1 / 0; function ct(s) { if (typeof s == "string") return s; let e = s + ""; return e == "0" && 1 / s == -it ? "-0" : e; } function at(s) { return s == null ? "" : ct(s); } function F(s) { return typeof s == "string"; } function xe(s) { return typeof s == "number"; } function lt(s) { return s === !0 || s === !1 || ut(s) && Le(s) == "[object Boolean]"; } function $e(s) { return typeof s == "object"; } function ut(s) { return $e(s) && s !== null; } function R(s) { return s != null; } function re(s) { return !s.trim().length; } function Le(s) { return s == null ? s === void 0 ? "[object Undefined]" : "[object Null]" : Object.prototype.toString.call(s); } const dt = "Incorrect 'index' type", ht = (s) => `Invalid value for key ${s}`, ft = (s) => `Pattern length exceeds max of ${s}.`, mt = (s) => `Missing ${s} property in key`, pt = (s) => `Property 'weight' in key '${s}' must be a positive integer`, be = Object.prototype.hasOwnProperty; class gt { constructor(e) { this._keys = [], this._keyMap = {}; let t = 0; e.forEach((n) => { let r = Ie(n); t += r.weight, this._keys.push(r), this._keyMap[r.id] = r, t += r.weight; }), this._keys.forEach((n) => { n.weight /= t; }); } get(e) { return this._keyMap[e]; } keys() { return this._keys; } toJSON() { return JSON.stringify(this._keys); } } function Ie(s) { let e = null, t = null, n = null, r = 1, o = null; if (F(s) || P(s)) n = s, e = we(s), t = ce(s); else { if (!be.call(s, "name")) throw new Error(mt("name")); const i = s.name; if (n = i, be.call(s, "weight") && (r = s.weight, r <= 0)) throw new Error(pt(i)); e = we(i), t = ce(i), o = s.getFn; } return { path: e, id: t, weight: r, src: n, getFn: o }; } function we(s) { return P(s) ? s : s.split("."); } function ce(s) { return P(s) ? s.join(".") : s; } function yt(s, e) { let t = [], n = !1; const r = (o, i, c) => { if (R(o)) if (!i[c]) t.push(o); else { let l = i[c]; const d = o[l]; if (!R(d)) return; if (c === i.length - 1 && (F(d) || xe(d) || lt(d))) t.push(at(d)); else if (P(d)) { n = !0; for (let u = 0, a = d.length; u < a; u += 1) r(d[u], i, c + 1); } else i.length && r(d, i, c + 1); } }; return r(s, F(e) ? e.split(".") : e, 0), n ? t : t[0]; } const vt = { // Whether the matches should be included in the result set. When `true`, each record in the result // set will include the indices of the matched characters. // These can consequently be used for highlighting purposes. includeMatches: !1, // When `true`, the matching function will continue to the end of a search pattern even if // a perfect match has already been located in the string. findAllMatches: !1, // Minimum number of characters that must be matched before a result is considered a match minMatchCharLength: 1 }, _t = { // When `true`, the algorithm continues searching to the end of the input even if a perfect // match is found before the end of the same input. isCaseSensitive: !1, // When true, the matching function will continue to the end of a search pattern even if includeScore: !1, // List of properties that will be searched. This also supports nested properties. keys: [], // Whether to sort the result list, by score shouldSort: !0, // Default sort function: sort by ascending score, ascending index sortFn: (s, e) => s.score === e.score ? s.idx < e.idx ? -1 : 1 : s.score < e.score ? -1 : 1 }, Mt = { // Approximately where in the text is the pattern expected to be found? location: 0, // At what point does the match algorithm give up. A threshold of '0.0' requires a perfect match // (of both letters and location), a threshold of '1.0' would match anything. threshold: 0.6, // Determines how close the match must be to the fuzzy location (specified above). // An exact letter match which is 'distance' characters away from the fuzzy location // would score as a complete mismatch. A distance of '0' requires the match be at // the exact location specified, a threshold of '1000' would require a perfect match // to be within 800 characters of the fuzzy location to be found using a 0.8 threshold. distance: 100 }, bt = { // When `true`, it enables the use of unix-like search commands useExtendedSearch: !1, // The get function to use when fetching an object's properties. // The default will search nested paths *ie foo.bar.baz* getFn: yt, // When `true`, search will ignore `location` and `distance`, so it won't matter // where in the string the pattern appears. // More info: https://fusejs.io/concepts/scoring-theory.html#fuzziness-score ignoreLocation: !1, // When `true`, the calculation for the relevance score (used for sorting) will // ignore the field-length norm. // More info: https://fusejs.io/concepts/scoring-theory.html#field-length-norm ignoreFieldNorm: !1, // The weight to determine how much field length norm effects scoring. fieldNormWeight: 1 }; var v = { ..._t, ...vt, ...Mt, ...bt }; const wt = /[^ ]+/g; function kt(s = 1, e = 3) { const t = /* @__PURE__ */ new Map(), n = Math.pow(10, e); return { get(r) { const o = r.match(wt).length; if (t.has(o)) return t.get(o); const i = 1 / Math.pow(o, 0.5 * s), c = parseFloat(Math.round(i * n) / n); return t.set(o, c), c; }, clear() { t.clear(); } }; } class ye { constructor({ getFn: e = v.getFn, fieldNormWeight: t = v.fieldNormWeight } = {}) { this.norm = kt(t, 3), this.getFn = e, this.isCreated = !1, this.setIndexRecords(); } setSources(e = []) { this.docs = e; } setIndexRecords(e = []) { this.records = e; } setKeys(e = []) { this.keys = e, this._keysMap = {}, e.forEach((t, n) => { this._keysMap[t.id] = n; }); } create() { this.isCreated || !this.docs.length || (this.isCreated = !0, F(this.docs[0]) ? this.docs.forEach((e, t) => { this._addString(e, t); }) : this.docs.forEach((e, t) => { this._addObject(e, t); }), this.norm.clear()); } // Adds a doc to the end of the index add(e) { const t = this.size(); F(e) ? this._addString(e, t) : this._addObject(e, t); } // Removes the doc at the specified index of the index removeAt(e) { this.records.splice(e, 1); for (let t = e, n = this.size(); t < n; t += 1) this.records[t].i -= 1; } getValueForItemAtKeyId(e, t) { return e[this._keysMap[t]]; } size() { return this.records.length; } _addString(e, t) { if (!R(e) || re(e)) return; let n = { v: e, i: t, n: this.norm.get(e) }; this.records.push(n); } _addObject(e, t) { let n = { i: t, $: {} }; this.keys.forEach((r, o) => { let i = r.getFn ? r.getFn(e) : this.getFn(e, r.path); if (R(i)) { if (P(i)) { let c = []; const l = [{ nestedArrIndex: -1, value: i }]; for (; l.length; ) { const { nestedArrIndex: d, value: u } = l.pop(); if (R(u)) if (F(u) && !re(u)) { let a = { v: u, i: d, n: this.norm.get(u) }; c.push(a); } else P(u) && u.forEach((a, f) => { l.push({ nestedArrIndex: f, value: a }); }); } n.$[o] = c; } else if (F(i) && !re(i)) { let c = { v: i, n: this.norm.get(i) }; n.$[o] = c; } } }), this.records.push(n); } toJSON() { return { keys: this.keys, records: this.records }; } } function Ae(s, e, { getFn: t = v.getFn, fieldNormWeight: n = v.fieldNormWeight } = {}) { const r = new ye({ getFn: t, fieldNormWeight: n }); return r.setKeys(s.map(Ie)), r.setSources(e), r.create(), r; } function Et(s, { getFn: e = v.getFn, fieldNormWeight: t = v.fieldNormWeight } = {}) { const { keys: n, records: r } = s, o = new ye({ getFn: e, fieldNormWeight: t }); return o.setKeys(n), o.setIndexRecords(r), o; } function q(s, { errors: e = 0, currentLocation: t = 0, expectedLocation: n = 0, distance: r = v.distance, ignoreLocation: o = v.ignoreLocation } = {}) { const i = e / s.length; if (o) return i; const c = Math.abs(n - t); return r ? i + c / r : c ? 1 : i; } function St(s = [], e = v.minMatchCharLength) { let t = [], n = -1, r = -1, o = 0; for (let i = s.length; o < i; o += 1) { let c = s[o]; c && n === -1 ? n = o : !c && n !== -1 && (r = o - 1, r - n + 1 >= e && t.push([n, r]), n = -1); } return s[o - 1] && o - n >= e && t.push([n, o - 1]), t; } const V = 32; function Ct(s, e, t, { location: n = v.location, distance: r = v.distance, threshold: o = v.threshold, findAllMatches: i = v.findAllMatches, minMatchCharLength: c = v.minMatchCharLength, includeMatches: l = v.includeMatches, ignoreLocation: d = v.ignoreLocation } = {}) { if (e.length > V) throw new Error(ft(V)); const u = e.length, a = s.length, f = Math.max(0, Math.min(n, a)); let h = o, m = f; const g = c > 1 || l, _ = g ? Array(a) : []; let b; for (; (b = s.indexOf(e, m)) > -1; ) { let w = q(e, { currentLocation: b, expectedLocation: f, distance: r, ignoreLocation: d }); if (h = Math.min(w, h), m = b + u, g) { let k = 0; for (; k < u; ) _[b + k] = 1, k += 1; } } m = -1; let C = [], $ = 1, N = u + a; const p = 1 << u - 1; for (let w = 0; w < u; w += 1) { let k = 0, G = N; for (; k < G; ) q(e, { errors: w, currentLocation: f + G, expectedLocation: f, distance: r, ignoreLocation: d }) <= h ? k = G : N = G, G = Math.floor((N - k) / 2 + k); N = G; let H = Math.max(1, f - G + 1), Q = i ? a : Math.min(f + G, a) + u, A = Array(Q + 2); A[Q + 1] = (1 << w) - 1; for (let B = Q; B >= H; B -= 1) { let X = B - 1, Me = t[s.charAt(X)]; if (g && (_[X] = +!!Me), A[B] = (A[B + 1] << 1 | 1) & Me, w && (A[B] |= (C[B + 1] | C[B]) << 1 | 1 | C[B + 1]), A[B] & p && ($ = q(e, { errors: w, currentLocation: X, expectedLocation: f, distance: r, ignoreLocation: d }), $ <= h)) { if (h = $, m = X, m <= f) break; H = Math.max(1, 2 * f - m); } } if (q(e, { errors: w + 1, currentLocation: f, expectedLocation: f, distance: r, ignoreLocation: d }) > h) break; C = A; } const M = { isMatch: m >= 0, // Count exact matches (those with a score of 0) to be "almost" exact score: Math.max(1e-3, $) }; if (g) { const w = St(_, c); w.length ? l && (M.indices = w) : M.isMatch = !1; } return M; } function xt(s) { let e = {}; for (let t = 0, n = s.length; t < n; t += 1) { const r = s.charAt(t); e[r] = (e[r] || 0) | 1 << n - t - 1; } return e; } class Re { constructor(e, { location: t = v.location, threshold: n = v.threshold, distance: r = v.distance, includeMatches: o = v.includeMatches, findAllMatches: i = v.findAllMatches, minMatchCharLength: c = v.minMatchCharLength, isCaseSensitive: l = v.isCaseSensitive, ignoreLocation: d = v.ignoreLocation } = {}) { if (this.options = { location: t, threshold: n, distance: r, includeMatches: o, findAllMatches: i, minMatchCharLength: c, isCaseSensitive: l, ignoreLocation: d }, this.pattern = l ? e : e.toLowerCase(), this.chunks = [], !this.pattern.length) return; const u = (f, h) => { this.chunks.push({ pattern: f, alphabet: xt(f), startIndex: h }); }, a = this.pattern.length; if (a > V) { let f = 0; const h = a % V, m = a - h; for (; f < m; ) u(this.pattern.substr(f, V), f), f += V; if (h) { const g = a - V; u(this.pattern.substr(g), g); } } else u(this.pattern, 0); } searchIn(e) { const { isCaseSensitive: t, includeMatches: n } = this.options; if (t || (e = e.toLowerCase()), this.pattern === e) { let m = { isMatch: !0, score: 0 }; return n && (m.indices = [[0, e.length - 1]]), m; } const { location: r, distance: o, threshold: i, findAllMatches: c, minMatchCharLength: l, ignoreLocation: d } = this.options; let u = [], a = 0, f = !1; this.chunks.forEach(({ pattern: m, alphabet: g, startIndex: _ }) => { const { isMatch: b, score: C, indices: $ } = Ct(e, m, g, { location: r + _, distance: o, threshold: i, findAllMatches: c, minMatchCharLength: l, includeMatches: n, ignoreLocation: d }); b && (f = !0), a += C, b && $ && (u = [...u, ...$]); }); let h = { isMatch: f, score: f ? a / this.chunks.length : 1 }; return f && n && (h.indices = u), h; } } class W { constructor(e) { this.pattern = e; } static isMultiMatch(e) { return ke(e, this.multiRegex); } static isSingleMatch(e) { return ke(e, this.singleRegex); } search() { } } function ke(s, e) { const t = s.match(e); return t ? t[1] : null; } class $t extends W { constructor(e) { super(e); } static get type() { return "exact"; } static get multiRegex() { return /^="(.*)"$/; } static get singleRegex() { return /^=(.*)$/; } search(e) { const t = e === this.pattern; return { isMatch: t, score: t ? 0 : 1, indices: [0, this.pattern.length - 1] }; } } class Lt extends W { constructor(e) { super(e); } static get type() { return "inverse-exact"; } static get multiRegex() { return /^!"(.*)"$/; } static get singleRegex() { return /^!(.*)$/; } search(e) { const n = e.indexOf(this.pattern) === -1; return { isMatch: n, score: n ? 0 : 1, indices: [0, e.length - 1] }; } } class It extends W { constructor(e) { super(e); } static get type() { return "prefix-exact"; } static get multiRegex() { return /^\^"(.*)"$/; } static get singleRegex() { return /^\^(.*)$/; } search(e) { const t = e.startsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, this.pattern.length - 1] }; } } class At extends W { constructor(e) { super(e); } static get type() { return "inverse-prefix-exact"; } static get multiRegex() { return /^!\^"(.*)"$/; } static get singleRegex() { return /^!\^(.*)$/; } search(e) { const t = !e.startsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] }; } } class Rt extends W { constructor(e) { super(e); } static get type() { return "suffix-exact"; } static get multiRegex() { return /^"(.*)"\$$/; } static get singleRegex() { return /^(.*)\$$/; } search(e) { const t = e.endsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [e.length - this.pattern.length, e.length - 1] }; } } class Ot extends W { constructor(e) { super(e); } static get type() { return "inverse-suffix-exact"; } static get multiRegex() { return /^!"(.*)"\$$/; } static get singleRegex() { return /^!(.*)\$$/; } search(e) { const t = !e.endsWith(this.pattern); return { isMatch: t, score: t ? 0 : 1, indices: [0, e.length - 1] }; } } class Oe extends W { constructor(e, { location: t = v.location, threshold: n = v.threshold, distance: r = v.distance, includeMatches: o = v.includeMatches, findAllMatches: i = v.findAllMatches, minMatchCharLength: c = v.minMatchCharLength, isCaseSensitive: l = v.isCaseSensitive, ignoreLocation: d = v.ignoreLocation } = {}) { super(e), this._bitapSearch = new Re(e, { location: t, threshold: n, distance: r, includeMatches: o, findAllMatches: i, minMatchCharLength: c, isCaseSensitive: l, ignoreLocation: d }); } static get type() { return "fuzzy"; } static get multiRegex() { return /^"(.*)"$/; } static get singleRegex() { return /^(.*)$/; } search(e) { return this._bitapSearch.searchIn(e); } } class Ke extends W { constructor(e) { super(e); } static get type() { return "include"; } static get multiRegex() { return /^'"(.*)"$/; } static get singleRegex() { return /^'(.*)$/; } search(e) { let t = 0, n; const r = [], o = this.pattern.length; for (; (n = e.indexOf(this.pattern, t)) > -1; ) t = n + o, r.push([n, t - 1]); const i = !!r.length; return { isMatch: i, score: i ? 0 : 1, indices: r }; } } const ae = [ $t, Ke, It, At, Ot, Rt, Lt, Oe ], Ee = ae.length, Kt = / +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/, Nt = "|"; function Bt(s, e = {}) { return s.split(Nt).map((t) => { let n = t.trim().split(Kt).filter((o) => o && !!o.trim()), r = []; for (let o = 0, i = n.length; o < i; o += 1) { const c = n[o]; let l = !1, d = -1; for (; !l && ++d < Ee; ) { const u = ae[d]; let a = u.isMultiMatch(c); a && (r.push(new u(a, e)), l = !0); } if (!l) for (d = -1; ++d < Ee; ) { const u = ae[d]; let a = u.isSingleMatch(c); if (a) { r.push(new u(a, e)); break; } } } return r; }); } const Gt = /* @__PURE__ */ new Set([Oe.type, Ke.type]); class Ft { constructor(e, { isCaseSensitive: t = v.isCaseSensitive, includeMatches: n = v.includeMatches, minMatchCharLength: r = v.minMatchCharLength, ignoreLocation: o = v.ignoreLocation, findAllMatches: i = v.findAllMatches, location: c = v.location, threshold: l = v.threshold, distance: d = v.distance } = {}) { this.query = null, this.options = { isCaseSensitive: t, includeMatches: n, minMatchCharLength: r, findAllMatches: i, ignoreLocation: o, location: c, threshold: l, distance: d }, this.pattern = t ? e : e.toLowerCase(), this.query = Bt(this.pattern, this.options); } static condition(e, t) { return t.useExtendedSearch; } searchIn(e) { const t = this.query; if (!t) return { isMatch: !1, score: 1 }; const { includeMatches: n, isCaseSensitive: r } = this.options; e = r ? e : e.toLowerCase(); let o = 0, i = [], c = 0; for (let l = 0, d = t.length; l < d; l += 1) { const u = t[l]; i.length = 0, o = 0; for (let a = 0, f = u.length; a < f; a += 1) { const h = u[a], { isMatch: m, indices: g, score: _ } = h.search(e); if (m) { if (o += 1, c += _, n) { const b = h.constructor.type; Gt.has(b) ? i = [...i, ...g] : i.push(g); } } else { c = 0, o = 0, i.length = 0; break; } } if (o) { let a = { isMatch: !0, score: c / o }; return n && (a.indices = i), a; } } return { isMatch: !1, score: 1 }; } } const le = []; function Tt(...s) { le.push(...s); } function ue(s, e) { for (let t = 0, n = le.length; t < n; t += 1) { let r = le[t]; if (r.condition(s, e)) return new r(s, e); } return new Re(s, e); } const se = { AND: "$and", OR: "$or" }, de = { PATH: "$path", PATTERN: "$val" }, he = (s) => !!(s[se.AND] || s[se.OR]), Pt = (s) => !!s[de.PATH], jt = (s) => !P(s) && $e(s) && !he(s), Se = (s) => ({ [se.AND]: Object.keys(s).map((e) => ({ [e]: s[e] })) }); function Ne(s, e, { auto: t = !0 } = {}) { const n = (r) => { let o = Object.keys(r); const i = Pt(r); if (!i && o.length > 1 && !he(r)) return n(Se(r)); if (jt(r)) { const l = i ? r[de.PATH] : o[0], d = i ? r[de.PATTERN] : r[l]; if (!F(d)) throw new Error(ht(l)); const u = { keyId: ce(l), pattern: d }; return t && (u.searcher = ue(d, e)), u; } let c = { children: [], operator: o[0] }; return o.forEach((l) => { const d = r[l]; P(d) && d.forEach((u) => { c.children.push(n(u)); }); }), c; }; return he(s) || (s = Se(s)), n(s); } function Dt(s, { ignoreFieldNorm: e = v.ignoreFieldNorm }) { s.forEach((t) => { let n = 1; t.matches.forEach(({ key: r, norm: o, score: i }) => { const c = r ? r.weight : null; n *= Math.pow( i === 0 && c ? Number.EPSILON : i, (c || 1) * (e ? 1 : o) ); }), t.score = n; }); } function Wt(s, e) { const t = s.matches; e.matches = [], R(t) && t.forEach((n) => { if (!R(n.indices) || !n.indices.length) return; const { indices: r, value: o } = n; let i = { indices: r, value: o }; n.key && (i.key = n.key.src), n.idx > -1 && (i.refIndex = n.idx), e.matches.push(i); }); } function zt(s, e) { e.score = s.score; } function Vt(s, e, { includeMatches: t = v.includeMatches, includeScore: n = v.includeScore } = {}) { const r = []; return t && r.push(Wt), n && r.push(zt), s.map((o) => { const { idx: i } = o, c = { item: e[i], refIndex: i }; return r.length && r.forEach((l) => { l(o, c); }), c; }); } class Y { constructor(e, t = {}, n) { this.options = { ...v, ...t }, this.options.useExtendedSearch, this._keyStore = new gt(this.options.keys), this.setCollection(e, n); } setCollection(e, t) { if (this._docs = e, t && !(t instanceof ye)) throw new Error(dt); this._myIndex = t || Ae(this.options.keys, this._docs, { getFn: this.options.getFn, fieldNormWeight: this.options.fieldNormWeight }); } add(e) { R(e) && (this._docs.push(e), this._myIndex.add(e)); } remove(e = () => !1) { const t = []; for (let n = 0, r = this._docs.length; n < r; n += 1) { const o = this._docs[n]; e(o, n) && (this.removeAt(n), n -= 1, r -= 1, t.push(o)); } return t; } removeAt(e) { this._docs.splice(e, 1), this._myIndex.removeAt(e); } getIndex() { return this._myIndex; } search(e, { limit: t = -1 } = {}) { const { includeMatches: n, includeScore: r, shouldSort: o, sortFn: i, ignoreFieldNorm: c } = this.options; let l = F(e) ? F(this._docs[0]) ? this._searchStringList(e) : this._searchObjectList(e) : this._searchLogical(e); return Dt(l, { ignoreFieldNorm: c }), o && l.sort(i), xe(t) && t > -1 && (l = l.slice(0, t)), Vt(l, this._docs, { includeMatches: n, includeScore: r }); } _searchStringList(e) { const t = ue(e, this.options), { records: n } = this._myIndex, r = []; return n.forEach(({ v: o, i, n: c }) => { if (!R(o)) return; const { isMatch: l, score: d, indices: u } = t.searchIn(o); l && r.push({ item: o, idx: i, matches: [{ score: d, value: o, norm: c, indices: u }] }); }), r; } _searchLogical(e) { const t = Ne(e, this.options), n = (c, l, d) => { if (!c.children) { const { keyId: a, searcher: f } = c, h = this._findMatches({ key: this._keyStore.get(a), value: this._myIndex.getValueForItemAtKeyId(l, a), searcher: f }); return h && h.length ? [ { idx: d, item: l, matches: h } ] : []; } const u = []; for (let a = 0, f = c.children.length; a < f; a += 1) { const h = c.children[a], m = n(h, l, d); if (m.length) u.push(...m); else if (c.operator === se.AND) return []; } return u; }, r = this._myIndex.records, o = {}, i = []; return r.forEach(({ $: c, i: l }) => { if (R(c)) { let d = n(t, c, l); d.length && (o[l] || (o[l] = { idx: l, item: c, matches: [] }, i.push(o[l])), d.forEach(({ matches: u }) => { o[l].matches.push(...u); })); } }), i; } _searchObjectList(e) { const t = ue(e, this.options), { keys: n, records: r } = this._myIndex, o = []; return r.forEach(({ $: i, i: c }) => { if (!R(i)) return; let l = []; n.forEach((d, u) => { l.push( ...this._findMatches({ key: d, value: i[u], searcher: t }) ); }), l.length && o.push({ idx: c, item: i, matches: l }); }), o; } _findMatches({ key: e, value: t, searcher: n }) { if (!R(t)) return []; let r = []; if (P(t)) t.forEach(({ v: o, i, n: c }) => { if (!R(o)) return; const { isMatch: l, score: d, indices: u } = n.searchIn(o); l && r.push({ score: d, key: e, value: o, idx: i, norm: c, indices: u }); }); else { const { v: o, n: i } = t, { isMatch: c, score: l, indices: d } = n.searchIn(o); c && r.push({ score: l, key: e, value: o, norm: i, indices: d }); } return r; } } Y.version = "6.6.2"; Y.createIndex = Ae; Y.parseIndex = Et; Y.config = v; Y.parseQuery = Ne; Tt(Ft); function Ht(s, e, t) { const n = () => { var i, c; return new Y( (i = L(e)) != null ? i : [], (c = L(t)) == null ? void 0 : c.fuseOptions ); }, r = O(n()); T( () => { var i; return (i = L(t)) == null ? void 0 : i.fuseOptions; }, () => { r.value = n(); }, { deep: !0 } ), T( () => L(e), (i) => { r.value.setCollection(i); }, { deep: !0 } ); const o = I(() => { const i = L(t); if (i != null && i.matchAllWhenSearchEmpty && !L(s)) return L(e).map((l, d) => ({ item: l, refIndex: d })); const c = i == null ? void 0 : i.resultLimit; return r.value.search(L(s), c ? { limit: c } : void 0); }); return { fuse: r, results: o }; } function Qt(s, e) { return s.find((t) => t.key === e); } function Ut(s) { return { all: s = s || /* @__PURE__ */ new Map(), on: function(e, t) { var n = s.get(e); n ? n.push(t) : s.set(e, [t]); }, off: function(e, t) { var n = s.get(e); n && (t ? n.splice(n.indexOf(t) >>> 0, 1) : s.set(e, [])); }, emit: function(e, t) { var n = s.get(e); n && n.slice().map(function(r) { r(t); }), (n = s.get("*")) && n.slice().map(function(r) { r(e, t); }); } }; } const Yt = Ut(), ve = () => ({ emitter: Yt }), y = oe({ commands: [], groups: [], query: "", isLoading: !1, results: [], fuseOptions: null, selectedCommandKey: null, selectedGroups: /* @__PURE__ */ new Set(), loop: !1 }); function j() { const { emitter: s } = ve(); function e(p) { y.groups = p.filter((M) => M.visible !== !1), y.commands = y.groups.flatMap( (M) => { var w; return ((w = M.commands) == null ? void 0 : w.map((k) => ({ ...k, group: M.key }))) ?? []; } ), f(); } function t() { y.query = "", y.isLoading = !1, y.results = [], y.selectedCommandKey = null, y.selectedGroups.clear(), f(); } function n(p) { y.loop = p; } async function r(p, M) { y.selectedGroups.has(p) ? y.selectedGroups.delete(p) : (M || y.selectedGroups.clear(), y.selectedGroups.add(p)), s.emit("filterChange", Array.from(y.selectedGroups)), y.query !== "" ? await m(y.query) : y.results = [], f(); } const o = I(() => y.query !== "" && y.results.length === 0), i = I(() => y.query !== "" && y.results.length > 0), c = I(() => i.value ? y.results.filter( (p) => y.selectedGroups.size === 0 || y.selectedGroups.has(null) || y.selectedGroups.has(p.group ?? null) ) : o.value ? [] : y.selectedGroups.size === 0 || y.selectedGroups.has(null) ? y.commands : y.commands.filter((p) => y.selectedGroups.has(p.group ?? null))), l = I(() => c.value.findIndex((p) => p.key === y.selectedCommandKey)); function d(p) { const w = c.value.find((k) => k.key === p); w ? (y.selectedCommandKey = p, s.emit("selected", w)) : (console.warn(`Command with key ${p} not found in displayed commands`), f()); } function u() { const p = c.value; if (p.length === 0) { f(); return; } const M = l.value + 1; M < p.length ? d(p[M].key) : y.loop && d(p[0].key); } function a() { const p = c.value; if (p.length === 0) { f(); return; } const M = l.value - 1; M >= 0 ? d(p[M].key) : y.loop && d(p[p.length - 1].key); } function f() { const p = c.value; p.length > 0 ? d(p[0].key) : (y.selectedCommandKey = null, s.emit("selected", null)); } function h() { var M; const p = Qt(y.commands, y.selectedCommandKey); p && (s.emit("executed", p), (M = p.action) == null || M.call(p)); } async function m(p, M) { await _(p, M); } function g() { y.query = "", y.results = [], f(); } const _ = tt( async (p, M) => { if (y.isLoading = !0, M && (y.fuseOptions = M), y.query = p, p === "") { y.results = [], f(); return; } y.results = await b(p), f(), y.isLoading = !1; }, 200 ); async function b(p) { const M = N(y.groups), w = M.filter((A) => !!A.search), k = await $(p, w), H = M.filter((A) => !A.search).flatMap( (A) => (A.commands ?? []).map((_e) => ({ ..._e, group: A.key })) ), Q = C(p, H); return Array.isArray(k) && k.length > 0 ? Q.concat(k) : Q; } function C(p, M) { const { results: w } = Ht(p, O(M), y.fuseOptions ?? {}); return w.value.map((k) => k.item); } async function $(p, M) { return M.length ? (await Promise.all( M.map(async (k) => (await k.search(p)).map((H) => ({ ...H, group: k.key }))) )).flat() : []; } function N(p) { return y.selectedGroups.has(null) ? p : p.filter((M) => y.selectedGroups.has(M.key)); } return { state: Te(y), initState: e, resetState: t, setLoop: n, toggleGroup: r, selectCommand: d, nextCommand: u, prevCommand: a, executeCommand: h, updateQuery: m, clearQuery: g, displayedCommands: c, resultsEmpty: o }; } const ks = /* @__PURE__ */ D({ __name: "CmdBar", props: { commands: {} }, setup(s, { expose: e }) { const { initState: t, resetState: n } = j(); return T( () => s.commands, () => { t(s.commands); }, { deep: !0, immediate: !0 } ), e({ resetState: n }), (r, o) => x(r.$slots, "default"); } }), Xt = { class: "input-container" }, Jt = { class: "input__leading", "aria-hidden": "true" }, qt = ["value", "placeholder", "aria-label"], Zt = { class: "input__clear" }, Es = /* @__PURE__ */ D({ __name: "CmdBarInput", props: { modelValue: { default: void 0 }, placeholder: { default: "Search for anything" }, fuse: { default: () => ({}) }, nonTriggerKeys: { default: () => ["@", "/"] }, threshold: { default: 0 } }, emits: ["update:modelValue"], setup(s, { emit: e }) { const t = s, n = e, { state: r, updateQuery: o, clearQuery: i } = j(), c = O(t.modelValue ?? r.query), l = I({ get: () => t.modelValue ?? c.value, set: (h) => { c.value = h, t.modelValue !== void 0 && n("update:modelValue", h); } }); T( () => t.modelValue, (h) => { h !== void 0 && h !== c.value && (c.value = h, h.length >= t.threshold ? o(h, d.value) : i()); } ); const d = I(() => { var h, m, g, _, b, C; return { fuseOptions: { ...(h = t.fuse) == null ? void 0 : h.fuseOptions, keys: ((g = (m = t.fuse) == null ? void 0 : m.fuseOptions) == null ? void 0 : g.keys) ?? ["label"], minMatchCharLength: ((b = (_ = t.fuse) == null ? void 0 : _.fuseOptions) == null ? void 0 : b.minMatchCharLength) ?? 0 }, resultLimit: ((C = t.fuse) == null ? void 0 : C.resultLimit) ?? 12 }; }), { emitter: u } = ve(); function a(h) { var g, _; const m = (g = h.target) == null ? void 0 : g.value; if ((_ = t.nonTriggerKeys) != null && _.includes(m)) { u.emit("input", m); return; } m != null && (l.value = m, m.length >= t.threshold ? o(m, d.value) : i()), u.emit("input", m); } function f() { i(), l.value = "", n("update:modelValue", ""); } return (h, m) => (E(), S("div", Xt, [ K("span", Jt, [ x(h.$slots, "leading") ]), K("input", { "data-cmd-bar-input": "", class: "input", autofocus: "", autocomplete: "off", "aria-autocomplete": "list", role: "combobox", value: l.value, placeholder: h.placeholder, "aria-label": h.placeholder, onInput: a }, null, 40, qt), K("div", Zt, [ K("button", { "aria-label": "Close", tabindex: "-1", onClick: f }, [ x(h.$slots, "clear") ]) ]) ])); } }), es = ["data-id", "aria-selected", "onMouseenter"], Be = /* @__PURE__ */ D({ __name: "CmdBarItems", props: { commands: {} }, setup(s) { const { state: e, selectCommand: t, executeCommand: n } = j(), r = (o) => e.selectedCommandKey === o.key; return (o, i) => (E(!0), S(ee, null, fe(o.commands, (c, l) => (E(), S("li", { key: `${c.key}-${l}`, "data-id": c.key, role: "option", class: "item", "aria-selected": r(c), onMouseenter: (d) => Z(t)(c.key), onClick: i[0] || (i[0] = (d) => Z(n)()) }, [ x(o.$slots, "default", { command: c }) ], 40, es))), 128)); } }), ts = { class: "group-container" }, ss = { key: 0, "data-cmd-bar-items": "", class: "items" }, ns = /* @__PURE__ */ D({ __name: "CmdBarGroup", props: { group: {} }, emits: ["selected", "clicked"], setup(s) { return (e, t) => (E(), S("div", ts, [ e.group.commands ? (E(), S("ul", ss, [ me(Be, Pe(e.$attrs, { commands: e.group.commands }), { default: U(({ command: n }) => [ x(e.$slots, "default", { command: n }) ]), _: 3 }, 16, ["commands"]) ])) : pe("", !0) ])); } }), rs = { key: 0, class: "no-results" }, os = { key: 1, "data-cmd-bar-items": "", class: "results" }, is = { key: 0 }, cs = { key: 1, class: "group" }, as = { key: 0, class: "group__label" }, ls = { "data-cmd-bar-items": "", class: "items" }, us = /* @__PURE__ */ D({ __name: "CmdBarResults", props: { resultsHeader: {} }, setup(s) { const { state: e, resultsEmpty: t } = j(), n = I(() => e.results), r = I(() => e.isLoading), o = I(() => t.value && !r.value); return (i, c) => o.value ? (E(), S("div", rs, [ x(i.$slots, "no-results") ])) : (E(), S("ul", os, [ r.value ? (E(), S("li", is, [ x(i.$slots, "loading") ])) : (E(), S("li", cs, [ i.resultsHeader ? (E(), S("h2", as, ge(i.resultsHeader), 1)) : pe("", !0), K("ul", ls, [ me(Be, { commands: n.value }, { default: U(({ command: l }) => [ x(i.$slots, "default", { command: l }) ]), _: 3 }, 8, ["commands"]) ]) ])) ])); } }), ds = { key: 1, "data-cmd-bar-items": "", class: "list-items" }, hs = { key: 0, class: "group__label" }, Ss = /* @__PURE__ */ D({ __name: "CmdBarList", props: { loop: { type: Boolean, default: !1 }, resultsHeader: { default: "Results" } }, setup(s) { const { state: e, setLoop: t, resultsEmpty: n } = j(); t(s.loop ?? !1); const r = O(null), o = O(null), i = I(() => { const u = e.selectedGroups, a = e.groups; return u.has(null) ? a : a.filter((f) => u.has(f.key)); }), c = I(() => e.query.length > 0), l = () => { var f, h, m, g; const u = e.selectedCommandKey, a = (f = o.value) == null ? void 0 : f.querySelector(`[data-id="${u}"]`); if (((h = a == null ? void 0 : a.parentElement) == null ? void 0 : h.firstElementChild) === a) { (g = (m = a == null ? void 0 : a.closest(".group")) == null ? void 0 : m.querySelector(".group__label")) == null || g.scrollIntoView({ block: "nearest" }); return; } a == null || a.scrollIntoView({ block: "nearest" }); }, { emitter: d } = ve(); return d.on("selected", (u) => { r.value = u; }), T( () => e.selectedCommandKey, (u) => { u && ie(l); } ), (u, a) => (E(), S(ee, null, [ K("div", { ref_key: "listRef", ref: o, class: "grouped-list", tabindex: "-1" }, [ c.value ? (E(), je(us, { key: 0, "results-header": u.resultsHeader }, { loading: U(() => [ x(u.$slots, "loading", {}, () => [ a[0] || (a[0] = K("div", { class: "loading-animation" }, "Loading...", -1)) ]) ]), "no-results": U(() => [ x(u.$slots, "no-results", {}, () => [ a[1] || (a[1] = K("div", null, "Nothing found", -1)) ]) ]), default: U(({ command: f }) => [ x(u.$slots, "results", { command: f }, () => [ x(u.$slots, "default", { command: f }) ]) ]), _: 3 }, 8, ["results-header"])) : (E(), S("ul", ds, [ (E(!0), S(ee, null, fe(i.value, (f) => { var h; return E(), S("li", { key: f.key, class: "group" }, [ f.label && ((h = f.commands) != null && h.length) ? (E(), S("h2", hs, ge(f.label), 1)) : pe("", !0), me(ns, { group: f }, { default: U(({ command: m }) => [ x(u.$slots, "default", { command: m }) ]), _: 2 }, 1032, ["group"]) ]); }), 128)) ])) ], 512), x(u.$slots, "preview", { activeCommand: r.value }) ], 64)); } }), fs = { class: "filter" }, ms = { class: "filter-list", role: "tablist" }, ps = ["data-id", "aria-selected", "onClick"], Cs = /* @__PURE__ */ D({ __name: "CmdBarFilter", props: { filterOptions: {}, asCheckbox: { type: Boolean, default: !1 } }, setup(s) { const { lineStyle: e, setLineStyle: t } = f(), { state: n, toggleGroup: r } = j(), o = I(() => n.selectedGroups), i = O(/* @__PURE__ */ new Set()), c = O([]), l = O(null); function d() { s.filterOptions.forEach((h, m) => { if (!h.visible) { c.value.push(h); return; } i.value.add(h), m === 0 && (l.value = h); }); } d(), De(() => { l.value && o.value.size === 0 && a(l.value.groupKey); }); function u(h) { var m; return !o.value.size && ((m = l.value) == null ? void 0 : m.groupKey) === h ? !0 : o.value.has(h); } function a(h) { r(h, s.asCheckbox), t(); } function f() { const h = O({ transform: "translateX(0)", width: "0" }); async function m() { await ie(() => { const _ = document.querySelector('.filter-chip[aria-selected="true"]'); if (!_) return; const b = _.clientWidth, C = _.offsetLeft; h.value = { transform: `translateX(${C}px)`, width: `${b}px` }; }); } function g() { const _ = new ResizeObserver(() => { m(); }); ie(() => { const b = document.querySelector(".filter"); b && _.observe(b); }); } return We(() => { g(); }), { lineStyle: h, setLineStyle: m }; } return (h, m) => (E(), S("div", fs, [ K("div", ms, [ (E(!0), S(ee, null, fe(Array.from(i.value), (g) => (E(), S("button", { key: g.groupKey ?? "default", "data-id": g.groupKey, class: "filter-chip", "aria-selected": u(g.groupKey), role: "tab", tabindex: "0", onKeydown: m[0] || (m[0] = ze(Ve(() => { }, ["prevent"]), ["enter"])), onClick: (_) => a(g.groupKey) }, [ x(h.$slots, "default", { group: g, isSelected: u(g.groupKey) }, () => [ He(ge(g.label), 1) ]) ], 40, ps))), 128)), x(h.$slots, "option", { hiddenOptions: c.value }) ]), K("div", { style: Qe(Z(e)), class: "filter-line" }, null, 4) ])); } }), z = O([]), ne = O(!1); function gs() { const s = ot(); return { registerKeyBinding: (r) => { const { key: o, action: i, autoRepeat: c = !1 } = r; if (o.includes("+")) { const l = s[o]; l && !z.value.some((d) => d.key === o) && st(l, () => { ne.value && i(); }); } else z.value.some((l) => l.key === o) || z.value.push({ key: o, action: i, autoRepeat: c }); }, handleKeydown: (r) => { const o = z.value.find((i) => i.key === r.key); if (o && ne.value && o.action) { if (!o.autoRepeat && r.repeat) return; o.action(); } }, removeKeyBinding: (r) => { const o = z.value.findIndex((i) => i.key === r); o !== -1 && z.value.splice(o, 1); }, singleKeyShortcuts: z }; } function ys(s) { const { nextCommand: e, prevCommand: t, executeCommand: n } = j(), r = { next: () => e(), prev: () => t(), execute: () => n() }, { registerKeyBinding: o, handleKeydown: i } = gs(); s(r).forEach((f) => { f.key && o(f); }); const { state: l } = j(), d = () => { l.commands.forEach((f) => { if (f.shortcut) { const h = f.action, m = { key: f.shortcut, action: h }; o(m); } }); }, u = () => { ne.value = !0, window.addEventListener("keydown", i); }, a = () => { ne.value = !1, window.removeEventListener("keydown", i); }; return d(), { addEventListener: u, removeEventListener: a }; } const vs = { "data-cmd-bar-wrapper": "", class: "cmd-bar__wrapper" }, _s = { "data-cmd-bar-header": "", class: "cmd-bar__header" }, Ms = { "data-cmd-bar-content": "", class: "cmd-bar__body" }, bs = { "data-cmd-bar-footer": "", class: "cmd-bar__footer" }, xs = /* @__PURE__ */ D({ __name: "CmdBarDialog", props: { visible: { type: Boolean, default: !1 } }, emits: ["update:visible"], setup(s, { emit: e }) { const t = e, n = O(null), { addEventListener: r, removeEventListener: o } = ys((a) => [ { key: "ArrowUp", action: () => a.prev(), autoRepeat: !0 }, { key: "ArrowDown", action: () => a.next(), autoRepeat: !0 }, { key: "Enter", action: () => a.execute(), autoRepeat: !0 } ]); function i() { var a; (a = n.value) == null || a.close(); } const c = { mounted(a, f) { a.__ClickOutsideHandler__ = (h) => { a === h.target || a.contains(h.target) || f.value(h, a); }, document.body.addEventListener("click", a.__ClickOutsideHandler__); }, unmounted(a) { document.body.removeEventListener("click", a.__ClickOutsideHandler__); } }, { resetState: l } = j(); function d() { t("update:visible", !0), r(); } function u() { t("update:visible", !1), o(), l(); } return T(n, (a) => { a && (a.addEventListener("close", u), a.addEventListener("show", d)); }), T( () => s.visible, (a) => { var f, h; a ? (r(), (f = n.value) == null || f.showModal()) : ((h = n.value) == null || h.close(), o()); } ), (a, f) => (E(), S("dialog", { ref_key: "dialogRef", ref: n, "data-cmd-bar": "", class: "cmd-bar", tabindex: "-1" }, [ Ue((E(), S("div", vs, [ K("div", _s, [ x(a.$slots, "header") ]), K("div", Ms, [ x(a.$slots, "content") ]), K("div", bs, [ x(a.$slots, "footer") ]) ])), [ [c, i] ]) ], 512)); } }); function $s(s) { return s; } export { ks as CmdBar, xs as CmdBarDialog, Cs as CmdBarFilter, Es as CmdBarInput, Ss as CmdBarList, $s as defineCommand, ve as useCmdBarEvent, ys as useKeymap };