cmd-bar
Version:
Versatile Vue 3 command-bar component
2 lines (1 loc) • 33.5 kB
JavaScript
(function($,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],r):($=typeof globalThis<"u"?globalThis:$||self,r($.CmdBar={},$.Vue))})(this,function($,r){"use strict";function we(s){return r.getCurrentScope()?(r.onScopeDispose(s),!0):!1}function L(s){return typeof s=="function"?s():r.unref(s)}const Ce=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const Me=Object.prototype.toString,be=s=>Me.call(s)==="[object Object]",z=()=>{};function xe(s,e){function t(...n){return new Promise((o,i)=>{Promise.resolve(s(()=>e.apply(this,n),{fn:e,thisArg:this,args:n})).then(o).catch(i)})}return t}function $e(s,e={}){let t,n,o=z;const i=a=>{clearTimeout(a),o(),o=z};return a=>{const d=L(s),h=L(e.maxWait);return t&&i(t),d<=0||h!==void 0&&h<=0?(n&&(i(n),n=null),Promise.resolve(a())):new Promise((u,l)=>{o=e.rejectOnCancel?l:u,h&&!n&&(n=setTimeout(()=>{t&&i(t),n=null,u(a())},h)),t=setTimeout(()=>{n&&i(n),n=null,u(a())},d)})}}function Le(s,e=200,t={}){return xe($e(e,t),s)}function Be(s,e,t){return r.watch(s,(o,i,c)=>{o&&e(o,i,c)},{...t,once:!1})}function Ie(s){var e;const t=L(s);return(e=t==null?void 0:t.$el)!=null?e:t}const re=Ce?window:void 0;function W(...s){let e,t,n,o;if(typeof s[0]=="string"||Array.isArray(s[0])?([t,n,o]=s,e=re):[e,t,n,o]=s,!e)return z;Array.isArray(t)||(t=[t]),Array.isArray(n)||(n=[n]);const i=[],c=()=>{i.forEach(u=>u()),i.length=0},a=(u,l,m,f)=>(u.addEventListener(l,m,f),()=>u.removeEventListener(l,m,f)),d=r.watch(()=>[Ie(e),L(o)],([u,l])=>{if(c(),!u)return;const m=be(l)?{...l}:l;i.push(...t.flatMap(f=>n.map(p=>a(u,f,p,m))))},{immediate:!0,flush:"post"}),h=()=>{d(),c()};return we(h),h}const Ae={ctrl:"control",command:"meta",cmd:"meta",option:"alt",up:"arrowup",down:"arrowdown",left:"arrowleft",right:"arrowright"};function Oe(s={}){const{reactive:e=!1,target:t=re,aliasMap:n=Ae,passive:o=!0,onEventFired:i=z}=s,c=r.reactive(new Set),a={toJSON(){return{}},current:c},d=e?r.reactive(a):a,h=new Set,u=new Set;function l(y,E){y in d&&(e?d[y]=E:d[y].value=E)}function m(){c.clear();for(const y of u)l(y,!1)}function f(y,E){var w,b;const x=(w=y.key)==null?void 0:w.toLowerCase(),g=[(b=y.code)==null?void 0:b.toLowerCase(),x].filter(Boolean);x&&(E?c.add(x):c.delete(x));for(const S of g)u.add(S),l(S,E);x==="meta"&&!E?(h.forEach(S=>{c.delete(S),l(S,!1)}),h.clear()):typeof y.getModifierState=="function"&&y.getModifierState("Meta")&&E&&[...c,...g].forEach(S=>h.add(S))}W(t,"keydown",y=>(f(y,!0),i(y)),{passive:o}),W(t,"keyup",y=>(f(y,!1),i(y)),{passive:o}),W("blur",m,{passive:!0}),W("focus",m,{passive:!0});const p=new Proxy(d,{get(y,E,w){if(typeof E!="string")return Reflect.get(y,E,w);if(E=E.toLowerCase(),E in n&&(E=n[E]),!(E in d))if(/[+_-]/.test(E)){const x=E.split(/[+_-]/g).map(I=>I.trim());d[E]=r.computed(()=>x.every(I=>L(p[I])))}else d[E]=r.ref(!1);const b=Reflect.get(y,E,w);return e?L(b):b}});return p}function K(s){return Array.isArray?Array.isArray(s):ce(s)==="[object Array]"}const Re=1/0;function Ne(s){if(typeof s=="string")return s;let e=s+"";return e=="0"&&1/s==-Re?"-0":e}function Ke(s){return s==null?"":Ne(s)}function O(s){return typeof s=="string"}function oe(s){return typeof s=="number"}function Te(s){return s===!0||s===!1||Fe(s)&&ce(s)=="[object Boolean]"}function ie(s){return typeof s=="object"}function Fe(s){return ie(s)&&s!==null}function B(s){return s!=null}function X(s){return!s.trim().length}function ce(s){return s==null?s===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(s)}const Xt="Extended search is not available",Ge="Incorrect 'index' type",Ve=s=>`Invalid value for key ${s}`,je=s=>`Pattern length exceeds max of ${s}.`,Pe=s=>`Missing ${s} property in key`,De=s=>`Property 'weight' in key '${s}' must be a positive integer`,ae=Object.prototype.hasOwnProperty;class ze{constructor(e){this._keys=[],this._keyMap={};let t=0;e.forEach(n=>{let o=le(n);t+=o.weight,this._keys.push(o),this._keyMap[o.id]=o,t+=o.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 le(s){let e=null,t=null,n=null,o=1,i=null;if(O(s)||K(s))n=s,e=de(s),t=J(s);else{if(!ae.call(s,"name"))throw new Error(Pe("name"));const c=s.name;if(n=c,ae.call(s,"weight")&&(o=s.weight,o<=0))throw new Error(De(c));e=de(c),t=J(c),i=s.getFn}return{path:e,id:t,weight:o,src:n,getFn:i}}function de(s){return K(s)?s:s.split(".")}function J(s){return K(s)?s.join("."):s}function We(s,e){let t=[],n=!1;const o=(i,c,a)=>{if(B(i))if(!c[a])t.push(i);else{let d=c[a];const h=i[d];if(!B(h))return;if(a===c.length-1&&(O(h)||oe(h)||Te(h)))t.push(Ke(h));else if(K(h)){n=!0;for(let u=0,l=h.length;u<l;u+=1)o(h[u],c,a+1)}else c.length&&o(h,c,a+1)}};return o(s,O(e)?e.split("."):e,0),n?t:t[0]}var k={...{isCaseSensitive:!1,includeScore:!1,keys:[],shouldSort:!0,sortFn:(s,e)=>s.score===e.score?s.idx<e.idx?-1:1:s.score<e.score?-1:1},...{includeMatches:!1,findAllMatches:!1,minMatchCharLength:1},...{location:0,threshold:.6,distance:100},...{useExtendedSearch:!1,getFn:We,ignoreLocation:!1,ignoreFieldNorm:!1,fieldNormWeight:1}};const ve=/[^ ]+/g;function He(s=1,e=3){const t=new Map,n=Math.pow(10,e);return{get(o){const i=o.match(ve).length;if(t.has(i))return t.get(i);const c=1/Math.pow(i,.5*s),a=parseFloat(Math.round(c*n)/n);return t.set(i,a),a},clear(){t.clear()}}}class q{constructor({getFn:e=k.getFn,fieldNormWeight:t=k.fieldNormWeight}={}){this.norm=He(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,O(this.docs[0])?this.docs.forEach((e,t)=>{this._addString(e,t)}):this.docs.forEach((e,t)=>{this._addObject(e,t)}),this.norm.clear())}add(e){const t=this.size();O(e)?this._addString(e,t):this._addObject(e,t)}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(!B(e)||X(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((o,i)=>{let c=o.getFn?o.getFn(e):this.getFn(e,o.path);if(B(c)){if(K(c)){let a=[];const d=[{nestedArrIndex:-1,value:c}];for(;d.length;){const{nestedArrIndex:h,value:u}=d.pop();if(B(u))if(O(u)&&!X(u)){let l={v:u,i:h,n:this.norm.get(u)};a.push(l)}else K(u)&&u.forEach((l,m)=>{d.push({nestedArrIndex:m,value:l})})}n.$[i]=a}else if(O(c)&&!X(c)){let a={v:c,n:this.norm.get(c)};n.$[i]=a}}}),this.records.push(n)}toJSON(){return{keys:this.keys,records:this.records}}}function ue(s,e,{getFn:t=k.getFn,fieldNormWeight:n=k.fieldNormWeight}={}){const o=new q({getFn:t,fieldNormWeight:n});return o.setKeys(s.map(le)),o.setSources(e),o.create(),o}function Qe(s,{getFn:e=k.getFn,fieldNormWeight:t=k.fieldNormWeight}={}){const{keys:n,records:o}=s,i=new q({getFn:e,fieldNormWeight:t});return i.setKeys(n),i.setIndexRecords(o),i}function v(s,{errors:e=0,currentLocation:t=0,expectedLocation:n=0,distance:o=k.distance,ignoreLocation:i=k.ignoreLocation}={}){const c=e/s.length;if(i)return c;const a=Math.abs(n-t);return o?c+a/o:a?1:c}function Ue(s=[],e=k.minMatchCharLength){let t=[],n=-1,o=-1,i=0;for(let c=s.length;i<c;i+=1){let a=s[i];a&&n===-1?n=i:!a&&n!==-1&&(o=i-1,o-n+1>=e&&t.push([n,o]),n=-1)}return s[i-1]&&i-n>=e&&t.push([n,i-1]),t}const j=32;function Ye(s,e,t,{location:n=k.location,distance:o=k.distance,threshold:i=k.threshold,findAllMatches:c=k.findAllMatches,minMatchCharLength:a=k.minMatchCharLength,includeMatches:d=k.includeMatches,ignoreLocation:h=k.ignoreLocation}={}){if(e.length>j)throw new Error(je(j));const u=e.length,l=s.length,m=Math.max(0,Math.min(n,l));let f=i,p=m;const y=a>1||d,E=y?Array(l):[];let w;for(;(w=s.indexOf(e,p))>-1;){let C=v(e,{currentLocation:w,expectedLocation:m,distance:o,ignoreLocation:h});if(f=Math.min(C,f),p=w+u,y){let M=0;for(;M<u;)E[w+M]=1,M+=1}}p=-1;let b=[],x=1,I=u+l;const g=1<<u-1;for(let C=0;C<u;C+=1){let M=0,R=I;for(;M<R;)v(e,{errors:C,currentLocation:m+R,expectedLocation:m,distance:o,ignoreLocation:h})<=f?M=R:I=R,R=Math.floor((I-M)/2+M);I=R;let G=Math.max(1,m-R+1),N=c?l:Math.min(m+R,l)+u,V=Array(N+2);V[N+1]=(1<<C)-1;for(let A=N;A>=G;A-=1){let Y=A-1,Se=t[s.charAt(Y)];if(y&&(E[Y]=+!!Se),V[A]=(V[A+1]<<1|1)&Se,C&&(V[A]|=(b[A+1]|b[A])<<1|1|b[A+1]),V[A]&g&&(x=v(e,{errors:C,currentLocation:Y,expectedLocation:m,distance:o,ignoreLocation:h}),x<=f)){if(f=x,p=Y,p<=m)break;G=Math.max(1,2*m-p)}}if(v(e,{errors:C+1,currentLocation:m,expectedLocation:m,distance:o,ignoreLocation:h})>f)break;b=V}const S={isMatch:p>=0,score:Math.max(.001,x)};if(y){const C=Ue(E,a);C.length?d&&(S.indices=C):S.isMatch=!1}return S}function Xe(s){let e={};for(let t=0,n=s.length;t<n;t+=1){const o=s.charAt(t);e[o]=(e[o]||0)|1<<n-t-1}return e}class he{constructor(e,{location:t=k.location,threshold:n=k.threshold,distance:o=k.distance,includeMatches:i=k.includeMatches,findAllMatches:c=k.findAllMatches,minMatchCharLength:a=k.minMatchCharLength,isCaseSensitive:d=k.isCaseSensitive,ignoreLocation:h=k.ignoreLocation}={}){if(this.options={location:t,threshold:n,distance:o,includeMatches:i,findAllMatches:c,minMatchCharLength:a,isCaseSensitive:d,ignoreLocation:h},this.pattern=d?e:e.toLowerCase(),this.chunks=[],!this.pattern.length)return;const u=(m,f)=>{this.chunks.push({pattern:m,alphabet:Xe(m),startIndex:f})},l=this.pattern.length;if(l>j){let m=0;const f=l%j,p=l-f;for(;m<p;)u(this.pattern.substr(m,j),m),m+=j;if(f){const y=l-j;u(this.pattern.substr(y),y)}}else u(this.pattern,0)}searchIn(e){const{isCaseSensitive:t,includeMatches:n}=this.options;if(t||(e=e.toLowerCase()),this.pattern===e){let p={isMatch:!0,score:0};return n&&(p.indices=[[0,e.length-1]]),p}const{location:o,distance:i,threshold:c,findAllMatches:a,minMatchCharLength:d,ignoreLocation:h}=this.options;let u=[],l=0,m=!1;this.chunks.forEach(({pattern:p,alphabet:y,startIndex:E})=>{const{isMatch:w,score:b,indices:x}=Ye(e,p,y,{location:o+E,distance:i,threshold:c,findAllMatches:a,minMatchCharLength:d,includeMatches:n,ignoreLocation:h});w&&(m=!0),l+=b,w&&x&&(u=[...u,...x])});let f={isMatch:m,score:m?l/this.chunks.length:1};return m&&n&&(f.indices=u),f}}class F{constructor(e){this.pattern=e}static isMultiMatch(e){return fe(e,this.multiRegex)}static isSingleMatch(e){return fe(e,this.singleRegex)}search(){}}function fe(s,e){const t=s.match(e);return t?t[1]:null}class Je extends F{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 qe extends F{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 Ze extends F{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 et extends F{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 tt extends F{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 st extends F{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 me extends F{constructor(e,{location:t=k.location,threshold:n=k.threshold,distance:o=k.distance,includeMatches:i=k.includeMatches,findAllMatches:c=k.findAllMatches,minMatchCharLength:a=k.minMatchCharLength,isCaseSensitive:d=k.isCaseSensitive,ignoreLocation:h=k.ignoreLocation}={}){super(e),this._bitapSearch=new he(e,{location:t,threshold:n,distance:o,includeMatches:i,findAllMatches:c,minMatchCharLength:a,isCaseSensitive:d,ignoreLocation:h})}static get type(){return"fuzzy"}static get multiRegex(){return/^"(.*)"$/}static get singleRegex(){return/^(.*)$/}search(e){return this._bitapSearch.searchIn(e)}}class pe extends F{constructor(e){super(e)}static get type(){return"include"}static get multiRegex(){return/^'"(.*)"$/}static get singleRegex(){return/^'(.*)$/}search(e){let t=0,n;const o=[],i=this.pattern.length;for(;(n=e.indexOf(this.pattern,t))>-1;)t=n+i,o.push([n,t-1]);const c=!!o.length;return{isMatch:c,score:c?0:1,indices:o}}}const Z=[Je,pe,Ze,et,st,tt,qe,me],ge=Z.length,nt=/ +(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)/,rt="|";function ot(s,e={}){return s.split(rt).map(t=>{let n=t.trim().split(nt).filter(i=>i&&!!i.trim()),o=[];for(let i=0,c=n.length;i<c;i+=1){const a=n[i];let d=!1,h=-1;for(;!d&&++h<ge;){const u=Z[h];let l=u.isMultiMatch(a);l&&(o.push(new u(l,e)),d=!0)}if(!d)for(h=-1;++h<ge;){const u=Z[h];let l=u.isSingleMatch(a);if(l){o.push(new u(l,e));break}}}return o})}const it=new Set([me.type,pe.type]);class ct{constructor(e,{isCaseSensitive:t=k.isCaseSensitive,includeMatches:n=k.includeMatches,minMatchCharLength:o=k.minMatchCharLength,ignoreLocation:i=k.ignoreLocation,findAllMatches:c=k.findAllMatches,location:a=k.location,threshold:d=k.threshold,distance:h=k.distance}={}){this.query=null,this.options={isCaseSensitive:t,includeMatches:n,minMatchCharLength:o,findAllMatches:c,ignoreLocation:i,location:a,threshold:d,distance:h},this.pattern=t?e:e.toLowerCase(),this.query=ot(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:o}=this.options;e=o?e:e.toLowerCase();let i=0,c=[],a=0;for(let d=0,h=t.length;d<h;d+=1){const u=t[d];c.length=0,i=0;for(let l=0,m=u.length;l<m;l+=1){const f=u[l],{isMatch:p,indices:y,score:E}=f.search(e);if(p){if(i+=1,a+=E,n){const w=f.constructor.type;it.has(w)?c=[...c,...y]:c.push(y)}}else{a=0,i=0,c.length=0;break}}if(i){let l={isMatch:!0,score:a/i};return n&&(l.indices=c),l}}return{isMatch:!1,score:1}}}const ee=[];function at(...s){ee.push(...s)}function te(s,e){for(let t=0,n=ee.length;t<n;t+=1){let o=ee[t];if(o.condition(s,e))return new o(s,e)}return new he(s,e)}const H={AND:"$and",OR:"$or"},se={PATH:"$path",PATTERN:"$val"},ne=s=>!!(s[H.AND]||s[H.OR]),lt=s=>!!s[se.PATH],dt=s=>!K(s)&&ie(s)&&!ne(s),ye=s=>({[H.AND]:Object.keys(s).map(e=>({[e]:s[e]}))});function _e(s,e,{auto:t=!0}={}){const n=o=>{let i=Object.keys(o);const c=lt(o);if(!c&&i.length>1&&!ne(o))return n(ye(o));if(dt(o)){const d=c?o[se.PATH]:i[0],h=c?o[se.PATTERN]:o[d];if(!O(h))throw new Error(Ve(d));const u={keyId:J(d),pattern:h};return t&&(u.searcher=te(h,e)),u}let a={children:[],operator:i[0]};return i.forEach(d=>{const h=o[d];K(h)&&h.forEach(u=>{a.children.push(n(u))})}),a};return ne(s)||(s=ye(s)),n(s)}function ut(s,{ignoreFieldNorm:e=k.ignoreFieldNorm}){s.forEach(t=>{let n=1;t.matches.forEach(({key:o,norm:i,score:c})=>{const a=o?o.weight:null;n*=Math.pow(c===0&&a?Number.EPSILON:c,(a||1)*(e?1:i))}),t.score=n})}function ht(s,e){const t=s.matches;e.matches=[],B(t)&&t.forEach(n=>{if(!B(n.indices)||!n.indices.length)return;const{indices:o,value:i}=n;let c={indices:o,value:i};n.key&&(c.key=n.key.src),n.idx>-1&&(c.refIndex=n.idx),e.matches.push(c)})}function ft(s,e){e.score=s.score}function mt(s,e,{includeMatches:t=k.includeMatches,includeScore:n=k.includeScore}={}){const o=[];return t&&o.push(ht),n&&o.push(ft),s.map(i=>{const{idx:c}=i,a={item:e[c],refIndex:c};return o.length&&o.forEach(d=>{d(i,a)}),a})}class D{constructor(e,t={},n){this.options={...k,...t},this.options.useExtendedSearch,this._keyStore=new ze(this.options.keys),this.setCollection(e,n)}setCollection(e,t){if(this._docs=e,t&&!(t instanceof q))throw new Error(Ge);this._myIndex=t||ue(this.options.keys,this._docs,{getFn:this.options.getFn,fieldNormWeight:this.options.fieldNormWeight})}add(e){B(e)&&(this._docs.push(e),this._myIndex.add(e))}remove(e=()=>!1){const t=[];for(let n=0,o=this._docs.length;n<o;n+=1){const i=this._docs[n];e(i,n)&&(this.removeAt(n),n-=1,o-=1,t.push(i))}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:o,shouldSort:i,sortFn:c,ignoreFieldNorm:a}=this.options;let d=O(e)?O(this._docs[0])?this._searchStringList(e):this._searchObjectList(e):this._searchLogical(e);return ut(d,{ignoreFieldNorm:a}),i&&d.sort(c),oe(t)&&t>-1&&(d=d.slice(0,t)),mt(d,this._docs,{includeMatches:n,includeScore:o})}_searchStringList(e){const t=te(e,this.options),{records:n}=this._myIndex,o=[];return n.forEach(({v:i,i:c,n:a})=>{if(!B(i))return;const{isMatch:d,score:h,indices:u}=t.searchIn(i);d&&o.push({item:i,idx:c,matches:[{score:h,value:i,norm:a,indices:u}]})}),o}_searchLogical(e){const t=_e(e,this.options),n=(a,d,h)=>{if(!a.children){const{keyId:l,searcher:m}=a,f=this._findMatches({key:this._keyStore.get(l),value:this._myIndex.getValueForItemAtKeyId(d,l),searcher:m});return f&&f.length?[{idx:h,item:d,matches:f}]:[]}const u=[];for(let l=0,m=a.children.length;l<m;l+=1){const f=a.children[l],p=n(f,d,h);if(p.length)u.push(...p);else if(a.operator===H.AND)return[]}return u},o=this._myIndex.records,i={},c=[];return o.forEach(({$:a,i:d})=>{if(B(a)){let h=n(t,a,d);h.length&&(i[d]||(i[d]={idx:d,item:a,matches:[]},c.push(i[d])),h.forEach(({matches:u})=>{i[d].matches.push(...u)}))}}),c}_searchObjectList(e){const t=te(e,this.options),{keys:n,records:o}=this._myIndex,i=[];return o.forEach(({$:c,i:a})=>{if(!B(c))return;let d=[];n.forEach((h,u)=>{d.push(...this._findMatches({key:h,value:c[u],searcher:t}))}),d.length&&i.push({idx:a,item:c,matches:d})}),i}_findMatches({key:e,value:t,searcher:n}){if(!B(t))return[];let o=[];if(K(t))t.forEach(({v:i,i:c,n:a})=>{if(!B(i))return;const{isMatch:d,score:h,indices:u}=n.searchIn(i);d&&o.push({score:h,key:e,value:i,idx:c,norm:a,indices:u})});else{const{v:i,n:c}=t,{isMatch:a,score:d,indices:h}=n.searchIn(i);a&&o.push({score:d,key:e,value:i,norm:c,indices:h})}return o}}D.version="6.6.2",D.createIndex=ue,D.parseIndex=Qe,D.config=k,D.parseQuery=_e,at(ct);function pt(s,e,t){const n=()=>{var c,a;return new D((c=L(e))!=null?c:[],(a=L(t))==null?void 0:a.fuseOptions)},o=r.ref(n());r.watch(()=>{var c;return(c=L(t))==null?void 0:c.fuseOptions},()=>{o.value=n()},{deep:!0}),r.watch(()=>L(e),c=>{o.value.setCollection(c)},{deep:!0});const i=r.computed(()=>{const c=L(t);if(c!=null&&c.matchAllWhenSearchEmpty&&!L(s))return L(e).map((d,h)=>({item:d,refIndex:h}));const a=c==null?void 0:c.resultLimit;return o.value.search(L(s),a?{limit:a}:void 0)});return{fuse:o,results:i}}function gt(s,e){return s.find(t=>t.key===e)}function yt(s){return{all:s=s||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(o){o(t)}),(n=s.get("*"))&&n.slice().map(function(o){o(e,t)})}}}const _t=yt(),Q=()=>({emitter:_t}),_=r.reactive({commands:[],groups:[],query:"",isLoading:!1,results:[],fuseOptions:null,selectedCommandKey:null,selectedGroups:new Set,loop:!1});function T(){const{emitter:s}=Q();function e(g){_.groups=g.filter(S=>S.visible!==!1),_.commands=_.groups.flatMap(S=>{var C;return((C=S.commands)==null?void 0:C.map(M=>({...M,group:S.key})))??[]}),m()}function t(){_.query="",_.isLoading=!1,_.results=[],_.selectedCommandKey=null,_.selectedGroups.clear(),m()}function n(g){_.loop=g}async function o(g,S){_.selectedGroups.has(g)?_.selectedGroups.delete(g):(S||_.selectedGroups.clear(),_.selectedGroups.add(g)),s.emit("filterChange",Array.from(_.selectedGroups)),_.query!==""?await p(_.query):_.results=[],m()}const i=r.computed(()=>_.query!==""&&_.results.length===0),c=r.computed(()=>_.query!==""&&_.results.length>0),a=r.computed(()=>c.value?_.results.filter(g=>_.selectedGroups.size===0||_.selectedGroups.has(null)||_.selectedGroups.has(g.group??null)):i.value?[]:_.selectedGroups.size===0||_.selectedGroups.has(null)?_.commands:_.commands.filter(g=>_.selectedGroups.has(g.group??null))),d=r.computed(()=>a.value.findIndex(g=>g.key===_.selectedCommandKey));function h(g){const C=a.value.find(M=>M.key===g);C?(_.selectedCommandKey=g,s.emit("selected",C)):(console.warn(`Command with key ${g} not found in displayed commands`),m())}function u(){const g=a.value;if(g.length===0){m();return}const S=d.value+1;S<g.length?h(g[S].key):_.loop&&h(g[0].key)}function l(){const g=a.value;if(g.length===0){m();return}const S=d.value-1;S>=0?h(g[S].key):_.loop&&h(g[g.length-1].key)}function m(){const g=a.value;g.length>0?h(g[0].key):(_.selectedCommandKey=null,s.emit("selected",null))}function f(){var S;const g=gt(_.commands,_.selectedCommandKey);g&&(s.emit("executed",g),(S=g.action)==null||S.call(g))}async function p(g,S){await E(g,S)}function y(){_.query="",_.results=[],m()}const E=Le(async(g,S)=>{if(_.isLoading=!0,S&&(_.fuseOptions=S),_.query=g,g===""){_.results=[],m();return}_.results=await w(g),m(),_.isLoading=!1},200);async function w(g){const S=I(_.groups),C=S.filter(N=>!!N.search),M=await x(g,C);let G=S.filter(N=>!N.search).flatMap(N=>(N.commands??[]).map(V=>({...V,group:N.key})));return Array.isArray(M)&&M.length>0&&(G=G.concat(M)),b(g,G)}function b(g,S){const{results:C}=pt(g,r.ref(S),_.fuseOptions??{});return C.value.map(M=>M.item)}async function x(g,S){return S.length?(await Promise.all(S.map(async M=>(await M.search(g)).map(G=>({...G,group:M.key}))))).flat():[]}function I(g){return _.selectedGroups.has(null)?g:g.filter(S=>_.selectedGroups.has(S.key))}return{state:r.readonly(_),initState:e,resetState:t,setLoop:n,toggleGroup:o,selectCommand:h,nextCommand:u,prevCommand:l,executeCommand:f,updateQuery:p,clearQuery:y,displayedCommands:a,resultsEmpty:i}}const kt=r.defineComponent({__name:"CmdBar",props:{commands:{}},setup(s,{expose:e}){const{initState:t,resetState:n}=T();return r.watch(()=>s.commands,()=>{t(s.commands)},{deep:!0,immediate:!0}),e({resetState:n}),(o,i)=>r.renderSlot(o.$slots,"default")}}),Et={class:"input-container"},St={class:"input__leading","aria-hidden":"true"},wt=["value","placeholder","aria-label"],Ct={class:"input__clear"},Mt=r.defineComponent({__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:o,updateQuery:i,clearQuery:c}=T(),a=r.ref(t.modelValue??o.query),d=r.computed({get:()=>t.modelValue??a.value,set:f=>{a.value=f,t.modelValue!==void 0&&n("update:modelValue",f)}});r.watch(()=>t.modelValue,f=>{f!==void 0&&f!==a.value&&(a.value=f,f.length>=t.threshold?i(f,h.value):c())});const h=r.computed(()=>{var f,p,y,E,w,b;return{fuseOptions:{...(f=t.fuse)==null?void 0:f.fuseOptions,keys:((y=(p=t.fuse)==null?void 0:p.fuseOptions)==null?void 0:y.keys)??["label"],minMatchCharLength:((w=(E=t.fuse)==null?void 0:E.fuseOptions)==null?void 0:w.minMatchCharLength)??0},resultLimit:((b=t.fuse)==null?void 0:b.resultLimit)??12}}),{emitter:u}=Q();function l(f){var y,E;const p=(y=f.target)==null?void 0:y.value;if((E=t.nonTriggerKeys)!=null&&E.includes(p)){u.emit("input",p);return}p!=null&&(d.value=p,p.length>=t.threshold?i(p,h.value):c()),u.emit("input",p)}function m(){c(),d.value="",n("update:modelValue","")}return(f,p)=>(r.openBlock(),r.createElementBlock("div",Et,[r.createElementVNode("span",St,[r.renderSlot(f.$slots,"leading")]),r.createElementVNode("input",{"data-cmd-bar-input":"",class:"input",autofocus:"",autocomplete:"off","aria-autocomplete":"list",role:"combobox",value:d.value,placeholder:f.placeholder,"aria-label":f.placeholder,onInput:l},null,40,wt),r.createElementVNode("div",Ct,[r.createElementVNode("button",{"aria-label":"Close",tabindex:"-1",onClick:m},[r.renderSlot(f.$slots,"clear")])])]))}}),bt=["data-id","aria-selected","onMouseenter"],ke=r.defineComponent({__name:"CmdBarItems",props:{commands:{}},setup(s){const{state:e,selectCommand:t,executeCommand:n}=T(),o=i=>e.selectedCommandKey===i.key;return(i,c)=>(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(i.commands,(a,d)=>(r.openBlock(),r.createElementBlock("li",{key:`${a.key}-${d}`,"data-id":a.key,role:"option",class:"item","aria-selected":o(a),onMouseenter:h=>r.unref(t)(a.key),onClick:c[0]||(c[0]=h=>r.unref(n)())},[r.renderSlot(i.$slots,"default",{command:a})],40,bt))),128))}}),xt={class:"group-container"},$t={key:0,"data-cmd-bar-items":"",class:"items"},Lt=r.defineComponent({__name:"CmdBarGroup",props:{group:{}},emits:["selected","clicked"],setup(s){return(e,t)=>(r.openBlock(),r.createElementBlock("div",xt,[e.group.commands?(r.openBlock(),r.createElementBlock("ul",$t,[r.createVNode(ke,r.mergeProps(e.$attrs,{commands:e.group.commands}),{default:r.withCtx(({command:n})=>[r.renderSlot(e.$slots,"default",{command:n})]),_:3},16,["commands"])])):r.createCommentVNode("",!0)]))}}),Bt={key:0,class:"no-results"},It={key:1,"data-cmd-bar-items":"",class:"results"},At={key:0},Ot={key:1,class:"group"},Rt={key:0,class:"group__label"},Nt={"data-cmd-bar-items":"",class:"items"},Kt=r.defineComponent({__name:"CmdBarResults",props:{resultsHeader:{}},setup(s){const{state:e,resultsEmpty:t}=T(),n=r.computed(()=>e.results),o=r.computed(()=>e.isLoading),i=r.computed(()=>t.value&&!o.value);return(c,a)=>i.value?(r.openBlock(),r.createElementBlock("div",Bt,[r.renderSlot(c.$slots,"no-results")])):(r.openBlock(),r.createElementBlock("ul",It,[o.value?(r.openBlock(),r.createElementBlock("li",At,[r.renderSlot(c.$slots,"loading")])):(r.openBlock(),r.createElementBlock("li",Ot,[c.resultsHeader?(r.openBlock(),r.createElementBlock("h2",Rt,r.toDisplayString(c.resultsHeader),1)):r.createCommentVNode("",!0),r.createElementVNode("ul",Nt,[r.createVNode(ke,{commands:n.value},{default:r.withCtx(({command:d})=>[r.renderSlot(c.$slots,"default",{command:d})]),_:3},8,["commands"])])]))]))}}),Tt={key:1,"data-cmd-bar-items":"",class:"list-items"},Ft={key:0,class:"group__label"},Gt=r.defineComponent({__name:"CmdBarList",props:{loop:{type:Boolean,default:!1},resultsHeader:{default:"Results"}},setup(s){const{state:e,setLoop:t,resultsEmpty:n}=T();t(s.loop??!1);const o=r.ref(null),i=r.ref(null),c=r.computed(()=>{const u=e.selectedGroups,l=e.groups;return u.has(null)?l:l.filter(m=>u.has(m.key))}),a=r.computed(()=>e.query.length>0),d=()=>{var m,f,p,y;const u=e.selectedCommandKey,l=(m=i.value)==null?void 0:m.querySelector(`[data-id="${u}"]`);if(((f=l==null?void 0:l.parentElement)==null?void 0:f.firstElementChild)===l){(y=(p=l==null?void 0:l.closest(".group"))==null?void 0:p.querySelector(".group__label"))==null||y.scrollIntoView({block:"nearest"});return}l==null||l.scrollIntoView({block:"nearest"})},{emitter:h}=Q();return h.on("selected",u=>{o.value=u}),r.watch(()=>e.selectedCommandKey,u=>{u&&r.nextTick(d)}),(u,l)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.createElementVNode("div",{ref_key:"listRef",ref:i,class:"grouped-list",tabindex:"-1"},[a.value?(r.openBlock(),r.createBlock(Kt,{key:0,"results-header":u.resultsHeader},{loading:r.withCtx(()=>[r.renderSlot(u.$slots,"loading",{},()=>[l[0]||(l[0]=r.createElementVNode("div",{class:"loading-animation"},"Loading...",-1))])]),"no-results":r.withCtx(()=>[r.renderSlot(u.$slots,"no-results",{},()=>[l[1]||(l[1]=r.createElementVNode("div",null,"Nothing found",-1))])]),default:r.withCtx(({command:m})=>[r.renderSlot(u.$slots,"results",{command:m},()=>[r.renderSlot(u.$slots,"default",{command:m})])]),_:3},8,["results-header"])):(r.openBlock(),r.createElementBlock("ul",Tt,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(c.value,m=>{var f;return r.openBlock(),r.createElementBlock("li",{key:m.key,class:"group"},[m.label&&((f=m.commands)!=null&&f.length)?(r.openBlock(),r.createElementBlock("h2",Ft,r.toDisplayString(m.label),1)):r.createCommentVNode("",!0),r.createVNode(Lt,{group:m},{default:r.withCtx(({command:p})=>[r.renderSlot(u.$slots,"default",{command:p})]),_:2},1032,["group"])])}),128))]))],512),r.renderSlot(u.$slots,"preview",{activeCommand:o.value})],64))}}),Vt={class:"filter"},jt={class:"filter-list",role:"tablist"},Pt=["data-id","aria-selected","onClick"],Dt=r.defineComponent({__name:"CmdBarFilter",props:{filterOptions:{},asCheckbox:{type:Boolean,default:!1}},setup(s){const{lineStyle:e,setLineStyle:t}=m(),{state:n,toggleGroup:o}=T(),i=r.computed(()=>n.selectedGroups),c=r.ref(new Set),a=r.ref([]),d=r.ref(null);function h(){s.filterOptions.forEach((f,p)=>{if(!f.visible){a.value.push(f);return}c.value.add(f),p===0&&(d.value=f)})}h(),r.watchEffect(()=>{d.value&&i.value.size===0&&l(d.value.groupKey)});function u(f){var p;return!i.value.size&&((p=d.value)==null?void 0:p.groupKey)===f?!0:i.value.has(f)}function l(f){o(f,s.asCheckbox),t()}function m(){const f=r.ref({transform:"translateX(0)",width:"0"});async function p(){await r.nextTick(()=>{const E=document.querySelector('.filter-chip[aria-selected="true"]');if(!E)return;const w=E.clientWidth,b=E.offsetLeft;f.value={transform:`translateX(${b}px)`,width:`${w}px`}})}function y(){const E=new ResizeObserver(()=>{p()});r.nextTick(()=>{const w=document.querySelector(".filter");w&&E.observe(w)})}return r.onMounted(()=>{y()}),{lineStyle:f,setLineStyle:p}}return(f,p)=>(r.openBlock(),r.createElementBlock("div",Vt,[r.createElementVNode("div",jt,[(r.openBlock(!0),r.createElementBlock(r.Fragment,null,r.renderList(Array.from(c.value),y=>(r.openBlock(),r.createElementBlock("button",{key:y.groupKey??"default","data-id":y.groupKey,class:"filter-chip","aria-selected":u(y.groupKey),role:"tab",tabindex:"0",onKeydown:p[0]||(p[0]=r.withKeys(r.withModifiers(()=>{},["prevent"]),["enter"])),onClick:E=>l(y.groupKey)},[r.renderSlot(f.$slots,"default",{group:y,isSelected:u(y.groupKey)},()=>[r.createTextVNode(r.toDisplayString(y.label),1)])],40,Pt))),128)),r.renderSlot(f.$slots,"option",{hiddenOptions:a.value})]),r.createElementVNode("div",{style:r.normalizeStyle(r.unref(e)),class:"filter-line"},null,4)]))}}),P=r.ref([]),U=r.ref(!1);function zt(){const s=Oe();return{registerKeyBinding:o=>{const{key:i,action:c,autoRepeat:a=!1}=o;if(i.includes("+")){const d=s[i];d&&!P.value.some(h=>h.key===i)&&Be(d,()=>{U.value&&c()})}else P.value.some(d=>d.key===i)||P.value.push({key:i,action:c,autoRepeat:a})},handleKeydown:o=>{const i=P.value.find(c=>c.key===o.key);if(i&&U.value&&i.action){if(!i.autoRepeat&&o.repeat)return;i.action()}},removeKeyBinding:o=>{const i=P.value.findIndex(c=>c.key===o);i!==-1&&P.value.splice(i,1)},singleKeyShortcuts:P}}function Ee(s){const{nextCommand:e,prevCommand:t,executeCommand:n}=T(),o={next:()=>e(),prev:()=>t(),execute:()=>n()},{registerKeyBinding:i,handleKeydown:c}=zt();s(o).forEach(m=>{m.key&&i(m)});const{state:d}=T(),h=()=>{d.commands.forEach(m=>{if(m.shortcut){const f=m.action,p={key:m.shortcut,action:f};i(p)}})},u=()=>{U.value=!0,window.addEventListener("keydown",c)},l=()=>{U.value=!1,window.removeEventListener("keydown",c)};return h(),{addEventListener:u,removeEventListener:l}}const Wt={"data-cmd-bar-wrapper":"",class:"cmd-bar__wrapper"},vt={"data-cmd-bar-header":"",class:"cmd-bar__header"},Ht={"data-cmd-bar-content":"",class:"cmd-bar__body"},Qt={"data-cmd-bar-footer":"",class:"cmd-bar__footer"},Ut=r.defineComponent({__name:"CmdBarDialog",props:{visible:{type:Boolean,default:!1}},emits:["update:visible"],setup(s,{emit:e}){const t=e,n=r.ref(null),{addEventListener:o,removeEventListener:i}=Ee(l=>[{key:"ArrowUp",action:()=>l.prev(),autoRepeat:!0},{key:"ArrowDown",action:()=>l.next(),autoRepeat:!0},{key:"Enter",action:()=>l.execute(),autoRepeat:!0}]);function c(){var l;(l=n.value)==null||l.close()}const a={mounted(l,m){l.__ClickOutsideHandler__=f=>{l===f.target||l.contains(f.target)||m.value(f,l)},document.body.addEventListener("click",l.__ClickOutsideHandler__)},unmounted(l){document.body.removeEventListener("click",l.__ClickOutsideHandler__)}},{resetState:d}=T();function h(){t("update:visible",!0),o()}function u(){t("update:visible",!1),i(),d()}return r.watch(n,l=>{l&&(l.addEventListener("close",u),l.addEventListener("show",h))}),r.watch(()=>s.visible,l=>{var m,f;l?(o(),(m=n.value)==null||m.showModal()):((f=n.value)==null||f.close(),i())}),(l,m)=>(r.openBlock(),r.createElementBlock("dialog",{ref_key:"dialogRef",ref:n,"data-cmd-bar":"",class:"cmd-bar",tabindex:"-1"},[r.withDirectives((r.openBlock(),r.createElementBlock("div",Wt,[r.createElementVNode("div",vt,[r.renderSlot(l.$slots,"header")]),r.createElementVNode("div",Ht,[r.renderSlot(l.$slots,"content")]),r.createElementVNode("div",Qt,[r.renderSlot(l.$slots,"footer")])])),[[a,c]])],512))}});function Yt(s){return s}$.CmdBar=kt,$.CmdBarDialog=Ut,$.CmdBarFilter=Dt,$.CmdBarInput=Mt,$.CmdBarList=Gt,$.defineCommand=Yt,$.useCmdBarEvent=Q,$.useKeymap=Ee,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});