@macrulez/vue-command-palette 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ (function($,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):($=typeof globalThis<"u"?globalThis:$||self,e($.VueCommandPalette={},$.Vue))})(this,function($,e){"use strict";function q(o){return o.normalize("NFD").replace(/\p{Diacritic}/gu,"").toLowerCase()}function M(o,l){const r=q(o),s=q(l);if(!r)return{score:0,matches:[]};if(s===r)return{score:100,matches:[[0,l.length-1]]};if(s.startsWith(r))return{score:80,matches:[[0,r.length-1]]};const d=s.indexOf(r);if(d!==-1)return{score:60,matches:[[d,d+r.length-1]]};const m=[];let a=0,p=0,f=-1;for(let k=0;k<s.length&&a<r.length;k++)s[k]===r[a]&&(m.push(k),f!==-1&&(p+=k-f-1),f=k,a++);if(a<r.length)return{score:-1,matches:[]};const y=[];let C=m[0],g=m[0];for(let k=1;k<m.length;k++)m[k]===g+1||(y.push([C,g]),C=m[k]),g=m[k];y.push([C,g]);const B=p/(l.length||1);return{score:Math.max(1,40-B*20),matches:y}}function oe(o){return!(o.disabled||o.enabled&&!o.enabled())}function _(o,l){if(!o.trim())return[];const r=[];for(const s of l){if(!oe(s))continue;let d=M(o,s.label);for(const m of s.keywords??[]){const a=M(o,m);a.score>d.score&&(d={score:a.score,matches:[]})}for(const m of s.aliases??[]){const a=M(o,m);a.score>d.score&&(d={score:a.score,matches:[]})}d.score>0&&r.push({command:s,score:d.score,matches:d.matches})}return r.sort((s,d)=>d.score-s.score)}function U(o,l){if(!l.length)return e.h("span",o);const r=[];let s=0;for(const[d,m]of l)s<d&&r.push(e.h("span",o.slice(s,d))),r.push(e.h("mark",{class:"vcp-match"},o.slice(d,m+1))),s=m+1;return s<o.length&&r.push(e.h("span",o.slice(s))),e.h("span",r)}function j(){const o=e.reactive({groups:new Map,commands:new Map});function l(a,p){for(const f of a)if(o.commands.set(f.id,f),p&&o.groups.has(p)){const y=o.groups.get(p);y.commands.find(C=>C.id===f.id)||y.commands.push(f)}return()=>{for(const f of a)if(o.commands.delete(f.id),p&&o.groups.has(p)){const y=o.groups.get(p),C=y.commands.findIndex(g=>g.id===f.id);C!==-1&&y.commands.splice(C,1)}}}function r(a){o.groups.set(a.id,e.reactive(a));for(const p of a.commands)o.commands.set(p.id,p);return()=>{const p=o.groups.get(a.id);if(p)for(const f of p.commands)o.commands.delete(f.id);o.groups.delete(a.id)}}function s(){return Array.from(o.commands.values())}function d(a){const p=s();if(!a.trim())return[];const f=_(a,p);for(const y of f)for(const[C,g]of o.groups)if(g.commands.find(B=>B.id===y.command.id)){y.groupId=C;break}return f}function m(){return Array.from(o.groups.values()).sort((a,p)=>(p.priority??0)-(a.priority??0))}return{state:o,registerCommands:l,registerGroup:r,search:d,getAllCommands:s,getSortedGroups:m}}const ne=new Set(["shift","ctrl","meta","alt","$mod"]);function re(o){return ne.has(o)}function Y(o){return o.length>=2&&o.every(l=>!re(l))}function ae(o,l){return o==="$mod"?l.metaKey||l.ctrlKey:o==="shift"?l.shiftKey:o==="alt"?l.altKey:o==="ctrl"?l.ctrlKey:o==="meta"?l.metaKey:l.key.toLowerCase()===o.toLowerCase()}function le(o,l){const r=o.slice(0,-1),s=o[o.length-1];for(const d of r)if(!ae(d,l))return!1;return!r.includes("$mod")&&!r.includes("ctrl")&&!r.includes("meta")&&(l.ctrlKey||l.metaKey)||!r.includes("shift")&&l.shiftKey||!r.includes("alt")&&l.altKey?!1:l.key.toLowerCase()===s.toLowerCase()}function J(){const o=[];let l=[],r=null,s=!1;function d(f){for(const{keys:g,handler:B}of o)if(!Y(g)&&le(g,f)){f.preventDefault(),B();return}const y=o.filter(g=>Y(g.keys));if(!y.length||f.metaKey||f.ctrlKey||f.altKey)return;l.push(f.key.toLowerCase()),r&&clearTimeout(r),r=setTimeout(()=>{l=[]},500);const C=l;for(const{keys:g,handler:B}of y){const k=g.map(w=>w.toLowerCase());if(C.length>=k.length&&C.slice(-k.length).every((V,P)=>V===k[P])){f.preventDefault(),l=[],B();return}}}function m(f,y){const C={keys:f,handler:y};return o.push(C),()=>{const g=o.indexOf(C);g!==-1&&o.splice(g,1)}}function a(){s||typeof document>"u"||(s=!0,document.addEventListener("keydown",d))}function p(){typeof document>"u"||(s=!1,document.removeEventListener("keydown",d))}return{registerShortcut:m,start:a,stop:p}}const G=Symbol("@macrulez/vue-command-palette"),ie={install(o,l={}){const{hotkey:r=["$mod","k"],persistRecent:s=!0,maxRecent:d=5,maxRecentPerGroup:m=0,localStorageKey:a="vcp:recent",colorTheme:p="system",onOpen:f,onClose:y,onError:C}=l,g=j(),B=J(),k=e.ref(!1),w=e.ref(""),V=e.ref(0),P=e.ref([]),E=e.ref(null);let S=[];if(s&&typeof localStorage<"u")try{S=JSON.parse(localStorage.getItem(a)??"[]")}catch{}const I=e.ref(S),x=e.computed(()=>g.search(w.value)),T=e.ref(p),K={store:g,keyboard:B,isOpen:k,query:w,activeIndex:V,history:P,recentIds:I,loadingCommandId:E,results:x,colorTheme:T,persistRecent:s,maxRecent:d,maxRecentPerGroup:m??0,localStorageKey:a,onOpen:f,onClose:y,onError:C};o.provide(G,K),B.registerShortcut(r,()=>{k.value=!k.value,k.value?(w.value="",V.value=0,f?.()):y?.()}),B.start();const L=o.unmount.bind(o);o.unmount=()=>{B.stop(),L()}}};function se(o,l){if(!(typeof localStorage>"u"))try{localStorage.setItem(l,JSON.stringify(o))}catch{}}function W(){const o=e.inject(G);if(!o)throw new Error("[@macrulez/vue-command-palette] Plugin not installed. Use app.use(VCommandPalettePlugin).");const{store:l,isOpen:r,query:s,activeIndex:d,history:m,recentIds:a,loadingCommandId:p,results:f,colorTheme:y,persistRecent:C,maxRecent:g,localStorageKey:B,onOpen:k,onClose:w,onError:V}=o;function P(h){h&&r.value?(m.value.push({paletteId:h,query:s.value,activeIndex:d.value}),s.value="",d.value=0):(r.value=!0,s.value="",d.value=0,k?.())}function E(){r.value=!1,s.value="",d.value=0,m.value=[],w?.()}function S(){r.value?E():P()}function I(){if(!m.value.length){E();return}const h=m.value.pop();s.value=h.query,d.value=h.activeIndex}function x(h){if(!C)return;const b=a.value.filter(A=>A!==h);b.unshift(h),a.value=b.slice(0,g),se(a.value,B)}async function T(h){if(!(h.disabled||h.enabled&&!h.enabled())){if(h.subCommands?.length){P(h.id);return}x(h.id),E(),p.value=h.id;try{await h.perform()}catch(b){V?V(b,h):console.error("[@macrulez/vue-command-palette] Command error:",b)}finally{p.value=null}}}async function K(){const h=f.value[d.value];h&&await T(h.command)}function L(){const h=l.getAllCommands();return a.value.map(b=>h.find(A=>A.id===b)).filter(b=>!!b)}function z(h){return l.registerCommands(h)}function O(h){return l.registerGroup(h)}return{isOpen:e.readonly(r),query:s,results:f,activeIndex:d,history:e.readonly(m),loadingCommandId:e.readonly(p),colorTheme:y,open:P,close:E,toggle:S,goBack:I,executeActive:K,executeCommand:T,getRecentCommands:L,registerCommands:z,registerGroup:O,addRecent:x}}function ce(o){const l=e.inject(G);if(!l)throw new Error("[@macrulez/vue-command-palette] Plugin not installed.");const r=l.store.registerCommands(o);e.onUnmounted(r)}function me(o){const l=e.inject(G);if(!l)throw new Error("[@macrulez/vue-command-palette] Plugin not installed.");const r=l.store.registerGroup(o);e.onUnmounted(r)}const de=["id","aria-selected","aria-disabled"],fe={key:0,class:"vcp-item__icon"},ue={class:"vcp-item__body"},pe={class:"vcp-item__label"},he={key:0,class:"vcp-item__description"},ge={key:0,class:"vcp-item__spinner","aria-label":"Loading"},ke={key:1,class:"vcp-item__shortcut"},R=e.defineComponent({__name:"CommandItem",props:{command:{},active:{type:Boolean},matches:{},itemId:{},loadingCommandId:{}},emits:["execute","activate"],setup(o){const l=o,r=e.computed(()=>l.command.disabled||l.command.enabled!=null&&!l.command.enabled()),s=e.computed(()=>l.loadingCommandId===l.command.id),d=e.computed(()=>U(l.command.label,l.matches));function m(a){return a==="$mod"?typeof navigator<"u"&&navigator.platform.includes("Mac")?"⌘":"Ctrl":a==="shift"?"⇧":a==="alt"?typeof navigator<"u"&&navigator.platform.includes("Mac")?"⌥":"Alt":a.toUpperCase()}return(a,p)=>(e.openBlock(),e.createElementBlock("div",{id:o.itemId,class:e.normalizeClass(["vcp-item",{"vcp-item--active":o.active,"vcp-item--disabled":r.value,"vcp-item--loading":s.value}]),role:"option","aria-selected":o.active,"aria-disabled":r.value,onClick:p[0]||(p[0]=f=>!r.value&&!s.value&&a.$emit("execute")),onMouseenter:p[1]||(p[1]=f=>!r.value&&a.$emit("activate"))},[e.renderSlot(a.$slots,"default",{command:o.command,active:o.active,matches:o.matches},()=>[e.renderSlot(a.$slots,"item-icon",{command:o.command},()=>[o.command.icon?(e.openBlock(),e.createElementBlock("span",fe,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(typeof o.command.icon=="string"?"span":o.command.icon),null,{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(typeof o.command.icon=="string"?o.command.icon:""),1)]),_:1}))])):e.createCommentVNode("",!0)]),e.createElementVNode("span",ue,[e.createElementVNode("span",pe,[(e.openBlock(),e.createBlock(e.resolveDynamicComponent(d.value)))]),o.command.description?(e.openBlock(),e.createElementBlock("span",he,e.toDisplayString(o.command.description),1)):e.createCommentVNode("",!0)]),e.renderSlot(a.$slots,"item-shortcut",{command:o.command},()=>[s.value?(e.openBlock(),e.createElementBlock("span",ge)):o.command.shortcut?.length?(e.openBlock(),e.createElementBlock("span",ke,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.command.shortcut,f=>(e.openBlock(),e.createElementBlock("kbd",{key:f,class:"vcp-kbd"},e.toDisplayString(m(f)),1))),128))])):e.createCommentVNode("",!0)])])],42,de))}}),ye={key:0,class:"vcp-group"},Ce={class:"vcp-group__header","aria-hidden":"true"},F=e.defineComponent({__name:"CommandGroup",props:{group:{},items:{},activeIndex:{},globalOffset:{},loadingCommandId:{}},emits:["execute","activate"],setup(o){return(l,r)=>o.items.length?(e.openBlock(),e.createElementBlock("div",ye,[e.renderSlot(l.$slots,"group-header",{group:o.group},()=>[e.createElementVNode("div",Ce,e.toDisplayString(o.group.label),1)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(o.items,(s,d)=>(e.openBlock(),e.createBlock(R,{key:s.command.id,command:s.command,active:o.globalOffset+d===o.activeIndex,matches:s.matches,"item-id":`vcp-item-${s.command.id}`,"loading-command-id":o.loadingCommandId,onExecute:m=>l.$emit("execute",s.command),onActivate:m=>l.$emit("activate",o.globalOffset+d)},e.createSlots({_:2},[l.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(m=>[e.renderSlot(l.$slots,"item-icon",e.mergeProps({ref_for:!0},m))]),key:"0"}:void 0,l.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(m=>[e.renderSlot(l.$slots,"item-shortcut",e.mergeProps({ref_for:!0},m))]),key:"1"}:void 0,l.$slots.item?{name:"default",fn:e.withCtx(m=>[e.renderSlot(l.$slots,"item",e.mergeProps({ref_for:!0},m))]),key:"2"}:void 0]),1032,["command","active","matches","item-id","loading-command-id","onExecute","onActivate"]))),128))])):e.createCommentVNode("",!0)}}),Q=e.defineComponent({__name:"VirtualList",props:{items:{},itemHeight:{},containerHeight:{},overscan:{default:3}},setup(o,{expose:l}){const r=o,s=e.ref(),d=e.ref(0),m=e.computed(()=>r.items.length*r.itemHeight),a=e.computed(()=>Math.max(0,Math.floor(d.value/r.itemHeight)-r.overscan)),p=e.computed(()=>{const g=Math.ceil(r.containerHeight/r.itemHeight);return Math.min(r.items.length-1,a.value+g+r.overscan*2)}),f=e.computed(()=>a.value*r.itemHeight),y=e.computed(()=>r.items.slice(a.value,p.value+1).map((g,B)=>({data:g,index:a.value+B})));function C(g){d.value=g.target.scrollTop}return e.watch(()=>r.items,()=>{d.value=0,s.value&&(s.value.scrollTop=0)}),l({containerEl:s}),(g,B)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"containerEl",ref:s,class:"vcp-virtual",style:e.normalizeStyle({height:o.containerHeight+"px",overflowY:"auto"}),onScrollPassive:C},[e.createElementVNode("div",{style:e.normalizeStyle({height:m.value+"px",position:"relative"})},[e.createElementVNode("div",{style:e.normalizeStyle({transform:`translateY(${f.value}px)`})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(y.value,k=>e.renderSlot(g.$slots,"default",{key:k.index,item:k.data,index:k.index})),128))],4)],4)],36))}}),Be={key:0,class:"vcp-breadcrumb","aria-live":"polite"},$e={key:0,class:"vcp-breadcrumb__sep","aria-hidden":"true"},Ee={key:1,class:"vcp-confirm"},be={class:"vcp-confirm__text"},Se={class:"vcp-confirm__actions"},we={class:"vcp-input-wrap"},Pe=["placeholder","aria-activedescendant"],Ie={class:"vcp-theme-switcher","aria-label":"Color theme"},Ve=["title","onClick"],xe=["aria-label"],Te={key:0,class:"vcp-state vcp-state--loading"},Ne={key:0,class:"vcp-section","aria-hidden":"true"},Le={key:0,class:"vcp-section","aria-hidden":"true"},De={key:0,class:"vcp-group__header","aria-hidden":"true"},Re={key:1,class:"vcp-section","aria-hidden":"true"},Ae={key:0,class:"vcp-section","aria-hidden":"true"},Ge={key:4,class:"vcp-state vcp-state--empty"},Ke=50,ze=40,Me=360,Fe="vcp-input",X="vcp-listbox",Oe=e.defineComponent({__name:"CommandPalette",props:{placeholder:{default:"Search commands…"},maxResults:{default:10},emptyText:{default:"No commands found."},loadingText:{default:"Loading…"},teleportTo:{default:"body"},theme:{default:"default"},animationDuration:{default:150}},setup(o){const l=o,r=e.inject(G),s=W(),{isOpen:d,query:m,activeIndex:a,history:p,loadingCommandId:f,close:y,toggle:C,open:g,executeCommand:B,getRecentCommands:k}=s,w=e.ref(),V=e.ref(),P=e.ref(!1),E=e.ref(null),S=e.computed(()=>{const t=k();if(!r.maxRecentPerGroup)return t;const c={};return t.filter(n=>{const i=n.group??"__none__";return c[i]=(c[i]??0)+1,c[i]<=r.maxRecentPerGroup})}),I=e.computed(()=>{if(!p.value.length)return null;const t=p.value[p.value.length-1].paletteId,c=r.store.getAllCommands().find(n=>n.id===t);return c?.subCommands?.length?c.subCommands.filter(n=>!n.disabled&&(n.enabled==null||n.enabled())):null}),x=e.computed(()=>r.store.getSortedGroups().map(t=>({group:t,items:t.commands.filter(c=>!c.disabled&&(c.enabled==null||c.enabled())).map(c=>({command:c,score:0,matches:[],groupId:t.id}))})).filter(t=>t.items.length>0)),T=e.computed(()=>x.value.flatMap(t=>t.items));function K(t){return x.value.slice(0,t).reduce((c,n)=>c+n.items.length,0)}const L=e.ref([]);let z=null;e.watch(m,async t=>{z&&clearTimeout(z);const c=r.store.getSortedGroups().filter(n=>n.onSearch);if(!c.length||!t.trim()){L.value=[];return}z=setTimeout(async()=>{P.value=!0;try{const n=await Promise.all(c.map(i=>i.onSearch(t).then(u=>u.map(D=>({command:D,score:50,matches:[],groupId:i.id})))));L.value=n.flat()}finally{P.value=!1}},200)});const O=e.computed(()=>r.store.search(m.value)),h=e.computed(()=>{const t=I.value;if(t!==null&&m.value.trim()){const n=m.value.toLowerCase();return t.filter(i=>i.label.toLowerCase().includes(n)||i.description?.toLowerCase().includes(n)||i.keywords?.some(u=>u.toLowerCase().includes(n))).map(i=>({command:i,score:50,matches:[],groupId:void 0}))}const c=[...O.value];for(const n of L.value)c.find(i=>i.command.id===n.command.id)||c.push(n);return c.sort((n,i)=>i.score-n.score).slice(0,l.maxResults)}),b=e.computed(()=>{const t=r.store.getSortedGroups(),c=[];let n=0;for(let i=0;i<t.length;i++){const u=t[i],D=h.value.filter(H=>H.groupId===u.id);D.length&&(c.push({group:u,items:D,offset:n,section:i>0&&c.length>0}),n+=D.length)}return c}),A=e.computed(()=>b.value.reduce((t,c)=>t+c.items.length,0)),Z=e.computed(()=>h.value.filter(t=>!t.groupId)),He=e.computed(()=>{const t=[];let c=0;for(let n=0;n<b.value.length;n++){const{group:i,items:u,section:D}=b.value[n];D&&t.push({type:"section"}),t.push({type:"group-header",label:i.label});for(const H of u)t.push({type:"command",result:H,index:c++})}for(const n of Z.value)t.push({type:"command",result:n,index:c++});return t}),qe=e.computed(()=>{const t=h.value[a.value];return t?`vcp-item-${t.command.id}`:void 0});function _e(t){return r.store.getAllCommands().find(c=>c.id===t)?.label??t}function v(){a.value=0}async function N(t){if(t.confirm){E.value=t;return}await B(t)}async function ee(){if(!E.value)return;const t=E.value;E.value=null,await B(t)}function te(){e.nextTick(()=>{V.value?.querySelector('[aria-selected="true"]')?.scrollIntoView({block:"nearest"})})}function Ue(t){if(E.value){t.key==="Escape"&&(t.preventDefault(),E.value=null),t.key==="Enter"&&(t.preventDefault(),ee());return}const c=h.value.length||(m.value.trim()?0:I.value?I.value.length:S.value.length+T.value.length);if(t.key==="ArrowDown")t.preventDefault(),c&&(a.value=(a.value+1)%c),te();else if(t.key==="ArrowUp")t.preventDefault(),c&&(a.value=(a.value-1+c)%c),te();else if(t.key==="Enter")if(t.preventDefault(),m.value.trim()){const n=h.value[a.value];n?.command&&N(n.command)}else{const n=a.value;let i;I.value?i=I.value[n]:i=n<S.value.length?S.value[n]:T.value[n-S.value.length]?.command,i&&N(i)}else t.key==="Escape"?(t.preventDefault(),p.value.length?s.goBack():y()):t.key==="Backspace"&&!m.value?(t.preventDefault(),s.goBack()):t.key==="Tab"&&(t.preventDefault(),w.value?.focus())}return e.watch(d,async t=>{typeof document>"u"||(t?(a.value=0,document.body.style.overflow="hidden",await e.nextTick(),w.value?.focus()):(document.body.style.overflow="",E.value=null))}),(t,c)=>(e.openBlock(),e.createElementBlock(e.Fragment,null,[e.renderSlot(t.$slots,"trigger",{open:e.unref(g),toggle:e.unref(C)}),(e.openBlock(),e.createBlock(e.Teleport,{to:o.teleportTo},[e.createVNode(e.Transition,{name:"vcp-fade"},{default:e.withCtx(()=>[e.unref(d)?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass(["vcp-overlay",e.unref(r).colorTheme.value!=="system"?`vcp-theme-${e.unref(r).colorTheme.value}`:""]),role:"presentation",onClick:c[6]||(c[6]=e.withModifiers((...n)=>e.unref(y)&&e.unref(y)(...n),["self"]))},[e.createElementVNode("div",{class:e.normalizeClass(["vcp-dialog",`vcp-dialog--${o.theme}`]),role:"dialog","aria-modal":"true","aria-label":"Command palette",onKeydown:Ue},[e.unref(p).length?(e.openBlock(),e.createElementBlock("div",Be,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p),(n,i)=>(e.openBlock(),e.createElementBlock("span",{key:n.paletteId,class:"vcp-breadcrumb__item"},[i>0?(e.openBlock(),e.createElementBlock("span",$e,"›")):e.createCommentVNode("",!0),e.createTextVNode(" "+e.toDisplayString(_e(n.paletteId)),1)]))),128)),c[7]||(c[7]=e.createElementVNode("span",{class:"vcp-breadcrumb__sep","aria-hidden":"true"},"›",-1))])):e.createCommentVNode("",!0),E.value?(e.openBlock(),e.createElementBlock("div",Ee,[e.createElementVNode("p",be,e.toDisplayString(E.value.confirm),1),e.createElementVNode("div",Se,[e.createElementVNode("button",{class:"vcp-confirm__btn vcp-confirm__btn--yes",onClick:ee}," Yes, proceed "),e.createElementVNode("button",{class:"vcp-confirm__btn vcp-confirm__btn--no",onClick:c[0]||(c[0]=n=>E.value=null)}," Cancel ")])])):(e.openBlock(),e.createElementBlock(e.Fragment,{key:2},[e.renderSlot(t.$slots,"header"),e.createElementVNode("div",we,[e.renderSlot(t.$slots,"input",{query:e.unref(m),onInput:v},()=>[e.withDirectives(e.createElementVNode("input",{id:Fe,ref_key:"inputEl",ref:w,"onUpdate:modelValue":c[1]||(c[1]=n=>e.isRef(m)?m.value=n:null),class:"vcp-input",type:"text",autocomplete:"off",spellcheck:"false",placeholder:o.placeholder,role:"combobox","aria-expanded":"true","aria-controls":X,"aria-activedescendant":qe.value,onInput:v},null,40,Pe),[[e.vModelText,e.unref(m)]])]),e.createElementVNode("div",Ie,[(e.openBlock(),e.createElementBlock(e.Fragment,null,e.renderList(["light","system","dark"],n=>e.createElementVNode("button",{key:n,class:e.normalizeClass(["vcp-theme-btn",{"vcp-theme-btn--active":e.unref(r).colorTheme.value===n}]),title:n==="light"?"Light theme":n==="dark"?"Dark theme":"System theme",type:"button",onClick:i=>e.unref(r).colorTheme.value=n},[e.createElementVNode("span",{class:e.normalizeClass(["vcp-theme-icon",`vcp-theme-icon--${n}`]),"aria-hidden":"true"},null,2)],10,Ve)),64))])]),e.withDirectives(e.createElementVNode("div",{id:X,ref_key:"listEl",ref:V,class:"vcp-list",role:"listbox","aria-label":o.placeholder},[P.value?(e.openBlock(),e.createElementBlock("div",Te,e.toDisplayString(o.loadingText),1)):e.unref(m).trim()?h.value.length>Ke?(e.openBlock(),e.createBlock(Q,{key:2,items:He.value,"item-height":ze,"container-height":Me},{default:e.withCtx(({item:n})=>[n.type==="group-header"?(e.openBlock(),e.createElementBlock("div",De,e.toDisplayString(n.label),1)):n.type==="section"?(e.openBlock(),e.createElementBlock("div",Re)):(e.openBlock(),e.createBlock(R,{key:2,command:n.result.command,active:n.index===e.unref(a),matches:n.result.matches,"item-id":`vcp-item-${n.result.command.id}`,"loading-command-id":e.unref(f),onExecute:i=>N(n.result.command),onActivate:i=>a.value=n.index},e.createSlots({_:2},[t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item-icon",e.normalizeProps(e.guardReactiveProps(i)))]),key:"0"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item-shortcut",e.normalizeProps(e.guardReactiveProps(i)))]),key:"1"}:void 0,t.$slots.item?{name:"default",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item",e.normalizeProps(e.guardReactiveProps(i)))]),key:"2"}:void 0]),1032,["command","active","matches","item-id","loading-command-id","onExecute","onActivate"]))]),_:3},8,["items"])):h.value.length?(e.openBlock(),e.createElementBlock(e.Fragment,{key:3},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(b.value,n=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:n.group.id},[n.section?(e.openBlock(),e.createElementBlock("div",Ae)):e.createCommentVNode("",!0),e.createVNode(F,{group:n.group,items:n.items,"active-index":e.unref(a),"global-offset":n.offset,"loading-command-id":e.unref(f),onExecute:c[4]||(c[4]=i=>N(i)),onActivate:c[5]||(c[5]=i=>a.value=i)},e.createSlots({_:2},[t.$slots["group-header"]?{name:"group-header",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"group-header",e.mergeProps({ref_for:!0},i))]),key:"0"}:void 0,t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item-icon",e.mergeProps({ref_for:!0},i))]),key:"1"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item-shortcut",e.mergeProps({ref_for:!0},i))]),key:"2"}:void 0,t.$slots.item?{name:"item",fn:e.withCtx(i=>[e.renderSlot(t.$slots,"item",e.mergeProps({ref_for:!0},i))]),key:"3"}:void 0]),1032,["group","items","active-index","global-offset","loading-command-id"])],64))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(Z.value,(n,i)=>(e.openBlock(),e.createBlock(R,{key:n.command.id,command:n.command,active:A.value+i===e.unref(a),matches:n.matches,"item-id":`vcp-item-${n.command.id}`,"loading-command-id":e.unref(f),onExecute:u=>N(n.command),onActivate:u=>a.value=A.value+i},e.createSlots({_:2},[t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-icon",e.mergeProps({ref_for:!0},u))]),key:"0"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-shortcut",e.mergeProps({ref_for:!0},u))]),key:"1"}:void 0,t.$slots.item?{name:"default",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item",e.mergeProps({ref_for:!0},u))]),key:"2"}:void 0]),1032,["command","active","matches","item-id","loading-command-id","onExecute","onActivate"]))),128))],64)):e.unref(m).trim()?(e.openBlock(),e.createElementBlock("div",Ge,[e.renderSlot(t.$slots,"empty",{query:e.unref(m)},()=>[e.createTextVNode(e.toDisplayString(o.emptyText),1)])])):e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[I.value?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(I.value,(n,i)=>(e.openBlock(),e.createBlock(R,{key:n.id,command:n,active:i===e.unref(a),matches:[],"item-id":`vcp-item-sub-${n.id}`,"loading-command-id":e.unref(f),onExecute:u=>N(n),onActivate:u=>a.value=i},e.createSlots({_:2},[t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-icon",e.mergeProps({ref_for:!0},u))]),key:"0"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-shortcut",e.mergeProps({ref_for:!0},u))]),key:"1"}:void 0,t.$slots.item?{name:"default",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item",e.mergeProps({ref_for:!0},u))]),key:"2"}:void 0]),1032,["command","active","item-id","loading-command-id","onExecute","onActivate"]))),128)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[S.value.length?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[c[8]||(c[8]=e.createElementVNode("div",{class:"vcp-group__header","aria-hidden":"true"},"Recent",-1)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(S.value,(n,i)=>(e.openBlock(),e.createBlock(R,{key:n.id,command:n,active:i===e.unref(a),matches:[],"item-id":`vcp-item-recent-${n.id}`,"loading-command-id":e.unref(f),onExecute:u=>N(n),onActivate:u=>a.value=i},e.createSlots({_:2},[t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-icon",e.mergeProps({ref_for:!0},u))]),key:"0"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-shortcut",e.mergeProps({ref_for:!0},u))]),key:"1"}:void 0,t.$slots.item?{name:"default",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item",e.mergeProps({ref_for:!0},u))]),key:"2"}:void 0]),1032,["command","active","item-id","loading-command-id","onExecute","onActivate"]))),128)),x.value.length?(e.openBlock(),e.createElementBlock("div",Ne)):e.createCommentVNode("",!0)],64)):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(x.value,(n,i)=>(e.openBlock(),e.createElementBlock(e.Fragment,{key:n.group.id},[i>0?(e.openBlock(),e.createElementBlock("div",Le)):e.createCommentVNode("",!0),e.createVNode(F,{group:n.group,items:n.items,"active-index":e.unref(a),"global-offset":S.value.length+K(i),"loading-command-id":e.unref(f),onExecute:c[2]||(c[2]=u=>N(u)),onActivate:c[3]||(c[3]=u=>a.value=u)},e.createSlots({_:2},[t.$slots["group-header"]?{name:"group-header",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"group-header",e.mergeProps({ref_for:!0},u))]),key:"0"}:void 0,t.$slots["item-icon"]?{name:"item-icon",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-icon",e.mergeProps({ref_for:!0},u))]),key:"1"}:void 0,t.$slots["item-shortcut"]?{name:"item-shortcut",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item-shortcut",e.mergeProps({ref_for:!0},u))]),key:"2"}:void 0,t.$slots.item?{name:"item",fn:e.withCtx(u=>[e.renderSlot(t.$slots,"item",e.mergeProps({ref_for:!0},u))]),key:"3"}:void 0]),1032,["group","items","active-index","global-offset","loading-command-id"])],64))),128))],64))],64))],8,xe),[[e.vShow,P.value||I.value!=null||S.value.length||e.unref(m).trim()||T.value.length]]),e.renderSlot(t.$slots,"footer")],64))],34)],2)):e.createCommentVNode("",!0)]),_:3})],8,["to"]))],64))}});$.CommandGroup=F,$.CommandItem=R,$.CommandPalette=Oe,$.VCommandPalettePlugin=ie,$.VirtualList=Q,$.createCommandStore=j,$.createKeyboardManager=J,$.fuzzySearch=_,$.highlightMatches=U,$.useCommandPalette=W,$.useRegisterCommands=ce,$.useRegisterGroup=me,Object.defineProperty($,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@macrulez/vue-command-palette",
3
+ "version": "0.1.0",
4
+ "description": "Command+K palette for Vue 3 — headless, fuzzy search, keyboard navigation, nested palettes",
5
+ "type": "module",
6
+ "main": "./dist/vue-command-palette.cjs",
7
+ "module": "./dist/vue-command-palette.js",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/vue-command-palette.js",
11
+ "require": "./dist/vue-command-palette.cjs",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "scripts": {
20
+ "build": "vite build",
21
+ "dev": "vite build --watch",
22
+ "typecheck": "tsc --noEmit",
23
+ "test": "vitest run",
24
+ "test:watch": "vitest",
25
+ "coverage": "vitest run --coverage",
26
+ "demo": "cd demo && npm run dev"
27
+ },
28
+ "lint-staged": {
29
+ "src/**/*.{ts,vue}": [
30
+ "eslint --fix",
31
+ "prettier --write"
32
+ ],
33
+ "src/**/*.{css,vue}": [
34
+ "stylelint --fix",
35
+ "prettier --write"
36
+ ],
37
+ "*.{json,md}": [
38
+ "prettier --write"
39
+ ]
40
+ },
41
+ "peerDependencies": {
42
+ "vue": "^3.3.0"
43
+ },
44
+ "devDependencies": {
45
+ "@eslint/js": "^10.0.1",
46
+ "@vitejs/plugin-vue": "^5.0.0",
47
+ "@vitest/coverage-v8": "^4.1.7",
48
+ "eslint": "^10.4.0",
49
+ "eslint-config-prettier": "^10.1.8",
50
+ "eslint-plugin-vue": "^10.9.1",
51
+ "jsdom": "^29.1.1",
52
+ "lint-staged": "^17.0.5",
53
+ "postcss-html": "^1.8.1",
54
+ "prettier": "^3.8.3",
55
+ "stylelint": "^17.12.0",
56
+ "stylelint-config-standard": "^40.0.0",
57
+ "typescript": "^5.0.0",
58
+ "vite": "^5.0.0",
59
+ "vite-plugin-dts": "^3.0.0",
60
+ "vitest": "^4.1.7",
61
+ "vue": "^3.4.0"
62
+ },
63
+ "keywords": [
64
+ "vue",
65
+ "vue3",
66
+ "command-palette",
67
+ "command-k",
68
+ "fuzzy-search",
69
+ "headless"
70
+ ],
71
+ "license": "MIT",
72
+ "publishConfig": {
73
+ "access": "public"
74
+ }
75
+ }