UNPKG

solid-command-palette

Version:

Add a command palette to your Solid.js App

2 lines (1 loc) 27.2 kB
"use strict";var Ze=Object.defineProperty,et=Object.defineProperties;var tt=Object.getOwnPropertyDescriptors;var ge=Object.getOwnPropertySymbols;var nt=Object.prototype.hasOwnProperty,ot=Object.prototype.propertyIsEnumerable;var $e=(e,t,n)=>t in e?Ze(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ye=(e,t)=>{for(var n in t||(t={}))nt.call(t,n)&&$e(e,n,t[n]);if(ge)for(var n of ge(t))ot.call(t,n)&&$e(e,n,t[n]);return e},Ae=(e,t)=>et(e,tt(t));Object.defineProperty(exports,"__esModule",{value:!0});exports[Symbol.toStringTag]="Module";var a=require("solid-js"),Ce=require("tinykeys"),it=require("fuse.js");function be(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var we=be(Ce),st=be(it);const rt=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected"],ct=new Set(["className","value","readOnly","formNoValidate","isMap","noModule","playsInline",...rt]),lt=new Set(["innerHTML","textContent","innerText","children"]),at={className:"class",htmlFor:"for"},Se={class:"className",formnovalidate:"formNoValidate",ismap:"isMap",nomodule:"noModule",playsinline:"playsInline",readonly:"readOnly"},dt=new Set(["beforeinput","click","dblclick","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),ut={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"};function xe(e,t,n){let o=n.length,r=t.length,i=o,c=0,s=0,l=t[r-1].nextSibling,d=null;for(;c<r||s<i;){if(t[c]===n[s]){c++,s++;continue}for(;t[r-1]===n[i-1];)r--,i--;if(r===c){const m=i<o?s?n[s-1].nextSibling:n[i-s]:l;for(;s<i;)e.insertBefore(n[s++],m)}else if(i===s)for(;c<r;)(!d||!d.has(t[c]))&&t[c].remove(),c++;else if(t[c]===n[i-1]&&n[s]===t[r-1]){const m=t[--r].nextSibling;e.insertBefore(n[s++],t[c++].nextSibling),e.insertBefore(n[--i],m),t[r]=n[i]}else{if(!d){d=new Map;let v=s;for(;v<i;)d.set(n[v],v++)}const m=d.get(t[c]);if(m!=null)if(s<m&&m<i){let v=c,f=1,A;for(;++v<r&&v<i&&!((A=d.get(t[v]))==null||A!==m+f);)f++;if(f>m-s){const w=t[c];for(;s<m;)e.insertBefore(n[s++],w)}else e.replaceChild(n[s++],t[c++])}else c++;else t[c++].remove()}}}const Ee="_$DX_DELEGATE";function E(e,t,n){const o=document.createElement("template");o.innerHTML=e;let r=o.content.firstChild;return n&&(r=r.firstChild),r}function U(e,t=window.document){const n=t[Ee]||(t[Ee]=new Set);for(let o=0,r=e.length;o<r;o++){const i=e[o];n.has(i)||(n.add(i),t.addEventListener(i,$t))}}function b(e,t,n){n==null?e.removeAttribute(t):e.setAttribute(t,n)}function ft(e,t,n,o){o==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,o)}function ht(e,t,n,o){o?Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n:Array.isArray(n)?e.addEventListener(t,r=>n[0](n[1],r)):e.addEventListener(t,n)}function Le(e,t,n={}){const o=Object.keys(t||{}),r=Object.keys(n);let i,c;for(i=0,c=r.length;i<c;i++){const s=r[i];!s||s==="undefined"||t[s]||(Ie(e,s,!1),delete n[s])}for(i=0,c=o.length;i<c;i++){const s=o[i],l=!!t[s];!s||s==="undefined"||n[s]===l||!l||(Ie(e,s,!0),n[s]=l)}return n}function mt(e,t,n={}){const o=e.style;if(t==null||typeof t=="string")return o.cssText=t;typeof n=="string"&&(n={});let r,i;for(i in n)t[i]==null&&o.removeProperty(i),delete n[i];for(i in t)r=t[i],r!==n[i]&&(o.setProperty(i,r),n[i]=r);return n}function vt(e,t,n,o){typeof t=="function"?a.createRenderEffect(r=>Pe(e,t(),r,n,o)):Pe(e,t,void 0,n,o)}function y(e,t,n,o){if(n!==void 0&&!o&&(o=[]),typeof t!="function")return K(e,t,o,n);a.createRenderEffect(r=>K(e,t(),r,n),o)}function _t(e,t,n,o,r={}){for(const i in r)if(!(i in t)){if(i==="children")continue;Ne(e,i,null,r[i],n)}for(const i in t){if(i==="children"){o||K(e,t.children);continue}const c=t[i];r[i]=Ne(e,i,c,r[i],n)}}function gt(e){return e.toLowerCase().replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function Ie(e,t,n){const o=t.trim().split(/\s+/);for(let r=0,i=o.length;r<i;r++)e.classList.toggle(o[r],n)}function Ne(e,t,n,o,r){let i,c,s;if(t==="style")return mt(e,n,o);if(t==="classList")return Le(e,n,o);if(n===o)return o;if(t==="ref")n(e);else if(t.slice(0,3)==="on:")e.addEventListener(t.slice(3),n);else if(t.slice(0,10)==="oncapture:")e.addEventListener(t.slice(10),n,!0);else if(t.slice(0,2)==="on"){const l=t.slice(2).toLowerCase(),d=dt.has(l);ht(e,l,n,d),d&&U([l])}else if((s=lt.has(t))||!r&&(Se[t]||(c=ct.has(t)))||(i=e.nodeName.includes("-")))i&&!c&&!s?e[gt(t)]=n:e[Se[t]||t]=n;else{const l=r&&t.indexOf(":")>-1&&ut[t.split(":")[0]];l?ft(e,l,t,n):b(e,at[t]||t,n)}return n}function $t(e){const t=`$$${e.type}`;let n=e.composedPath&&e.composedPath()[0]||e.target;for(e.target!==n&&Object.defineProperty(e,"target",{configurable:!0,value:n}),Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return n||document}});n!==null;){const o=n[t];if(o&&!n.disabled){const r=n[`${t}Data`];if(r!==void 0?o(r,e):o(e),e.cancelBubble)return}n=n.host&&n.host!==n&&n.host instanceof Node?n.host:n.parentNode}}function Pe(e,t,n={},o,r){return!r&&"children"in t&&a.createRenderEffect(()=>n.children=K(e,t.children,n.children)),a.createRenderEffect(()=>_t(e,t,o,!0,n)),n}function K(e,t,n,o,r){for(a.sharedConfig.context&&!n&&(n=[...e.childNodes]);typeof n=="function";)n=n();if(t===n)return n;const i=typeof t,c=o!==void 0;if(e=c&&n[0]&&n[0].parentNode||e,i==="string"||i==="number")if(i==="number"&&(t=t.toString()),c){let s=n[0];s&&s.nodeType===3?s.data=t:s=document.createTextNode(t),n=H(e,n,o,s)}else n!==""&&typeof n=="string"?n=e.firstChild.data=t:n=e.textContent=t;else if(t==null||i==="boolean"){if(a.sharedConfig.context)return n;n=H(e,n,o)}else{if(i==="function")return a.createRenderEffect(()=>{let s=t();for(;typeof s=="function";)s=s();n=K(e,s,n,o)}),()=>n;if(Array.isArray(t)){const s=[];if(W(s,t,r))return a.createRenderEffect(()=>n=K(e,s,n,o,!0)),()=>n;if(a.sharedConfig.context&&n&&n.length){for(let l=0;l<s.length;l++)if(s[l].parentNode)return n=s;return n}if(s.length===0){if(n=H(e,n,o),c)return n}else Array.isArray(n)?n.length===0?ke(e,s,o):xe(e,n,s):n==null||n===""?ke(e,s):xe(e,c&&n||[e.firstChild],s);n=s}else if(t instanceof Node){if(a.sharedConfig.context)return n=t.parentNode?c?[t]:t:n;if(Array.isArray(n)){if(c)return n=H(e,n,o,t);H(e,n,null,t)}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}}return n}function W(e,t,n){let o=!1;for(let r=0,i=t.length;r<i;r++){let c=t[r],s;if(c instanceof Node)e.push(c);else if(!(c==null||c===!0||c===!1))if(Array.isArray(c))o=W(e,c)||o;else if((s=typeof c)==="string")e.push(document.createTextNode(c));else if(s==="function")if(n){for(;typeof c=="function";)c=c();o=W(e,Array.isArray(c)?c:[c])||o}else e.push(c),o=!0;else e.push(document.createTextNode(c.toString()))}return o}function ke(e,t,n){for(let o=0,r=t.length;o<r;o++)e.insertBefore(t[o],n)}function H(e,t,n,o){if(n===void 0)return e.textContent="";const r=o||document.createTextNode("");if(t.length){let i=!1;for(let c=t.length-1;c>=0;c--){const s=t[c];if(r!==s){const l=s.parentNode===e;!i&&!c?l?e.replaceChild(r,s):e.insertBefore(r,n):l&&s.remove()}else i=!0}}else e.insertBefore(r,n);return[r]}const yt="http://www.w3.org/2000/svg";function At(e,t=!1){return t?document.createElementNS(yt,e):document.createElement(e)}function Ct(e){const{useShadow:t}=e,n=document.createTextNode(""),o=e.mount||document.body;function r(){if(a.sharedConfig.context){const[i,c]=a.createSignal(!1);return queueMicrotask(()=>c(!0)),()=>i()&&e.children}else return()=>e.children}if(o instanceof HTMLHeadElement){const[i,c]=a.createSignal(!1),s=()=>c(!0);a.createRoot(l=>y(o,()=>i()?l():r()(),null)),a.onCleanup(()=>{a.sharedConfig.context?queueMicrotask(s):s()})}else{const i=At(e.isSVG?"g":"div",e.isSVG),c=t&&i.attachShadow?i.attachShadow({mode:"open"}):i;Object.defineProperty(i,"host",{get(){return n.parentNode}}),y(c,r()),o.appendChild(i),e.ref&&e.ref(i),a.onCleanup(()=>o.removeChild(i))}return n}const J=Symbol("store-raw"),X=Symbol("store-node"),bt=Symbol("store-name");function pe(e,t){let n=e[a.$PROXY];if(!n){Object.defineProperty(e,a.$PROXY,{value:n=new Proxy(e,xt)});const o=Object.keys(e),r=Object.getOwnPropertyDescriptors(e);for(let i=0,c=o.length;i<c;i++){const s=o[i];if(r[s].get){const l=r[s].get.bind(n);Object.defineProperty(e,s,{get:l})}}}return n}function F(e){return e!=null&&typeof e=="object"&&(e[a.$PROXY]||!e.__proto__||e.__proto__===Object.prototype||Array.isArray(e))}function q(e,t=new Set){let n,o,r,i;if(n=e!=null&&e[J])return n;if(!F(e)||t.has(e))return e;if(Array.isArray(e)){Object.isFrozen(e)?e=e.slice(0):t.add(e);for(let c=0,s=e.length;c<s;c++)r=e[c],(o=q(r,t))!==r&&(e[c]=o)}else{Object.isFrozen(e)?e=Object.assign({},e):t.add(e);const c=Object.keys(e),s=Object.getOwnPropertyDescriptors(e);for(let l=0,d=c.length;l<d;l++)i=c[l],!s[i].get&&(r=e[i],(o=q(r,t))!==r&&(e[i]=o))}return e}function Y(e){let t=e[X];return t||Object.defineProperty(e,X,{value:t={}}),t}function wt(e,t){const n=Reflect.getOwnPropertyDescriptor(e,t);return!n||n.get||!n.configurable||t===a.$PROXY||t===X||t===bt||(delete n.value,delete n.writable,n.get=()=>e[a.$PROXY][t]),n}function St(e){if(a.getListener()){const t=Y(e);(t._||(t._=Q()))()}return Reflect.ownKeys(e)}function Q(){const[e,t]=a.createSignal(void 0,{equals:!1,internal:!0});return e.$=t,e}const xt={get(e,t,n){if(t===J)return e;if(t===a.$PROXY)return n;const o=e[t];if(t===X||t==="__proto__")return o;const r=F(o);if(a.getListener()&&(typeof o!="function"||e.hasOwnProperty(t))){let i,c;r&&(i=Y(o))&&(c=i._||(i._=Q()),c()),i=Y(e),c=i[t]||(i[t]=Q()),c()}return r?pe(o):o},set(){return!0},deleteProperty(){return!0},ownKeys:St,getOwnPropertyDescriptor:wt};function z(e,t,n){if(e[t]===n)return;const o=Array.isArray(e),r=e.length,i=n===void 0,c=o||i===t in e;i?delete e[t]:e[t]=n;let s=Y(e),l;(l=s[t])&&l.$(),o&&e.length!==r&&(l=s.length)&&l.$(),c&&(l=s._)&&l.$()}function Et(e,t){const n=Object.keys(t);for(let o=0;o<n.length;o+=1){const r=n[o];z(e,r,t[r])}}function G(e,t,n=[]){let o,r=e;if(t.length>1){o=t.shift();const c=typeof o,s=Array.isArray(e);if(Array.isArray(o)){for(let l=0;l<o.length;l++)G(e,[o[l]].concat(t),[o[l]].concat(n));return}else if(s&&c==="function"){for(let l=0;l<e.length;l++)o(e[l],l)&&G(e,[l].concat(t),[l].concat(n));return}else if(s&&c==="object"){const{from:l=0,to:d=e.length-1,by:m=1}=o;for(let v=l;v<=d;v+=m)G(e,[v].concat(t),[v].concat(n));return}else if(t.length>1){G(e[o],t,[o].concat(n));return}r=e[o],n=[o].concat(n)}let i=t[0];typeof i=="function"&&(i=i(r,n),i===r)||o===void 0&&i==null||(i=q(i),o===void 0||F(r)&&F(i)&&!Array.isArray(i)?Et(r,i):z(e,o,i))}function Lt(e,t){const n=q(e||{}),o=pe(n);function r(...i){a.batch(()=>G(n,i))}return[o,r]}const Re={get(e,t){if(t===J)return e;const n=e[t];return F(n)?new Proxy(n,Re):n},set(e,t,n){return z(e,t,q(n)),!0},deleteProperty(e,t){return z(e,t,void 0),!0}};function It(e){return t=>(F(t)&&e(new Proxy(t,Re)),t)}const Te=a.createContext(),Nt=Te.Provider;function O(){const e=a.useContext(Te);if(!e)throw new Error("Please use it inside Root component");return e}const V="__ROOT__";function Me(e,t){const n=t.root,o=t.dynamic[e.id]||{};return{rootContext:n,dynamicContext:o}}function Oe(e,t){if(!e.cond)return!0;const{rootContext:n,dynamicContext:o}=Me(e,t);return e.cond({actionId:e.id,rootContext:n,dynamicContext:o})}function De(e,t,n){const{id:o,run:r}=e;if(!r){n.selectParentAction(o);return}const{rootContext:i,dynamicContext:c}=Me(e,t);r({actionId:o,rootContext:i,dynamicContext:c}),n.closePalette()}function Pt(e,t,n){const o={};return e.forEach(r=>{const i=s=>{s.target.dataset.cpKbdShortcuts==="disabled"||!Oe(r,t)||(s.preventDefault(),De(r,t,n))},c=r.shortcut;c&&(o[c]=i)}),o}function je(e){const t=e.at(-1);return{activeId:t,isRoot:t===V}}function Ke(){const[e]=O();return a.createMemo(()=>Object.values(e.actions))}function kt(){const e=Ke(),[t]=O();function n(r){const{activeId:i,isRoot:c}=je(t.activeParentActionIdList);return c||r.parentActionId===i}return a.createMemo(()=>e().filter(n))}function pt(){const[e]=O(),t=kt();function n(r){return Oe(r,e.actionsContext)}return a.createMemo(()=>t().filter(n))}function Rt(){const[e]=O(),t=pt(),n=new st.default(t(),{keys:[{name:"title",weight:1},{name:"subtitle",weight:.7},{name:"keywords",weight:.5}]}),o=a.createMemo(()=>e.searchText.length===0?t():n.search(e.searchText).map(c=>c.item));return a.createEffect(()=>{n.setCollection(t())}),o}function Tt(){const[e,t]=O(),{togglePalette:n}=t,o=Ke();let r=null;a.onMount(()=>{const i=Pt(o(),e.actionsContext,t),c=s=>{s.preventDefault(),n()};r=we.default(window,Ae(ye({},i),{"$mod+k":c}))}),a.onCleanup(()=>{r&&r()})}const Mt=E("<div></div>"),Ot=()=>(Tt(),null),Dt=e=>{const t=e.actions||{},n=e.actionsContext||{},[o,r]=Lt({visibility:"closed",searchText:"",activeParentActionIdList:[V],actions:t,actionsContext:{root:n,dynamic:{}}}),i={setSearchText(s){r("searchText",s)},setActionsContext(s,l){r("actionsContext","dynamic",s,l)},resetActionsContext(s){r("actionsContext","dynamic",It(l=>{delete l[s]}))},openPalette(){r("visibility","opened")},closePalette(){r("visibility","closed"),o.activeParentActionIdList.length>1&&(i.setSearchText(""),i.resetParentAction())},togglePalette(){r("visibility",s=>s==="opened"?"closed":"opened")},selectParentAction(s){s!==V&&(r("activeParentActionIdList",l=>[...l,s]),i.setSearchText(""))},revertParentAction(){r("activeParentActionIdList",s=>{const{isRoot:l}=je(s);if(l)return s;const d=[...s];return d.pop(),d})},resetParentAction(){r("activeParentActionIdList",[V])}},c=[o,i];return a.createComponent(Nt,{value:c,get children(){const s=Mt.cloneNode(!0);return y(s,a.createComponent(Ot,{}),null),y(s,()=>e.children,null),s}})},jt=e=>{let t,n=!0;const[o,r]=a.createSignal(),[i,c]=a.createSignal(),s=a.children(()=>e.children),l=e.name||"s";e=a.mergeProps({name:l,enterActiveClass:l+"-enter-active",enterClass:l+"-enter",enterToClass:l+"-enter-to",exitActiveClass:l+"-exit-active",exitClass:l+"-exit",exitToClass:l+"-exit-to"},e);const{onBeforeEnter:d,onEnter:m,onAfterEnter:v,onBeforeExit:f,onExit:A,onAfterExit:w}=e;function p(h,$){if(!n||e.appear){let N=function(){h&&(h.classList.remove(...D),h.classList.remove(...j),a.batch(()=>{o()!==h&&r(h),i()===h&&c(void 0)}),v&&v(h),e.mode==="inout"&&I(h,$))};const T=e.enterClass.split(" "),D=e.enterActiveClass.split(" "),j=e.enterToClass.split(" ");d&&d(h),h.classList.add(...T),h.classList.add(...D),requestAnimationFrame(()=>{h.classList.remove(...T),h.classList.add(...j),m&&m(h,N),(!m||m.length<2)&&(h.addEventListener("transitionend",N,{once:!0}),h.addEventListener("animationend",N,{once:!0}))})}$&&!e.mode?c(h):r(h)}function I(h,$){const T=e.exitClass.split(" "),D=e.exitActiveClass.split(" "),j=e.exitToClass.split(" ");if(!$.parentNode)return N();f&&f($),$.classList.add(...T),$.classList.add(...D),requestAnimationFrame(()=>{$.classList.remove(...T),$.classList.add(...j)}),A&&A($,N),(!A||A.length<2)&&($.addEventListener("transitionend",N,{once:!0}),$.addEventListener("animationend",N,{once:!0}));function N(){$.classList.remove(...D),$.classList.remove(...j),o()===$&&r(void 0),w&&w($),e.mode==="outin"&&p(h,$)}}return a.createComputed(h=>{for(t=s();typeof t=="function";)t=t();return a.untrack(()=>(t&&t!==h&&(e.mode!=="outin"?p(t,h):n&&r(t)),h&&h!==t&&e.mode!=="inout"&&I(t,h),n=!1,t))}),[o,i]},Kt=e=>{let t;return a.createRenderEffect(()=>{if(t)return;const n=document.body,o=document.createElement("div");o.classList.add("command-palette-portal"),n.appendChild(o),t=o}),a.onCleanup(()=>{t&&(t.remove(),t=void 0)}),a.createComponent(Ct,{mount:t,get children(){return e.children}})};function Ft(e){return e==="Meta"?"\u2318":e==="Control"?"Ctrl":e==="Escape"?"Esc":e}const Bt=e=>Ce.parseKeybinding(e).map(o=>o.flat().map(Ft)),Ht="_kbdShortcut_v1zud_1",qt="_kbdGroup_v1zud_6",Gt="_kbdKey_v1zud_11";var Z={kbdShortcut:Ht,kbdGroup:qt,kbdKey:Gt};const ee=E("<kbd></kbd>"),te=e=>{const[t,n]=a.splitProps(e,["shortcut","class"]),o=Bt(t.shortcut),r=[Z.kbdKey,t.class].join(" ");return(()=>{const i=ee.cloneNode(!0);return vt(i,n,!1,!0),y(i,a.createComponent(a.For,{each:o,children:c=>(()=>{const s=ee.cloneNode(!0);return y(s,a.createComponent(a.For,{each:c,children:l=>(()=>{const d=ee.cloneNode(!0);return d.className=r,y(d,l),d})()})),a.createRenderEffect(()=>s.className=Z.kbdGroup),s})()})),a.createRenderEffect(()=>i.className=Z.kbdShortcut),i})()},Ut="_scrollShape_1199m_1";var Xt={scrollShape:Ut};const Yt=E("<div></div>"),Fe=e=>{let t=null;function n(){e.onNavigate()}function o(){n(),t=setInterval(()=>{e.status==="running"&&n()},500)}function r(){t&&clearInterval(t),t=null}function i(){e.status==="available"&&o()}function c(l){if(e.status!=="running")return;let d=!1;e.direction==="up"&&l.movementY>0&&(d=!0),e.direction==="down"&&l.movementY<0&&(d=!0),d&&e.onStop()}function s(){e.onStop()}return a.createEffect(()=>{e.status==="stopped"&&r()}),(()=>{const l=Yt.cloneNode(!0);return l.addEventListener("mouseleave",s),l.$$mousemove=c,l.addEventListener("mouseenter",i),a.createRenderEffect(d=>{const m=Xt.scrollShape,v=e.direction,f=e.status;return m!==d._v$&&(l.className=d._v$=m),v!==d._v$2&&b(l,"data-direction",d._v$2=v),f!==d._v$3&&b(l,"data-status",d._v$3=f),d},{_v$:void 0,_v$2:void 0,_v$3:void 0}),l})()};U(["mousemove"]);const zt="_visuallyHidden_1rdqz_1",Vt="_stripSpace_1rdqz_14";var B={visuallyHidden:zt,stripSpace:Vt};const Wt="_resultWrapper_m81ar_1",Jt="_resultList_m81ar_7",Qt="_resultItem_m81ar_11",Zt="_activeItem_m81ar_21",en="_resultTitle_m81ar_25",tn="_resultSubtitle_m81ar_30",nn="_resultShortcut_m81ar_37";var R={resultWrapper:Wt,resultList:Jt,resultItem:Qt,activeItem:Zt,resultTitle:en,resultSubtitle:tn,resultShortcut:nn};const on=E("<p></p>"),sn=E('<li role="option"><div><h4></h4></div><div></div></li>'),rn=E('<div><ul role="listbox"></ul></div>'),cn=E("<div><h4>Couldn't find any matching actions</h4></div>"),ln=e=>{let t,n=!1;function o(){return e.action.id===e.activeItemId}function r(s){n||(n=!0,e.onActionItemHover(s))}function i(){n=!1}function c(s){s.preventDefault()}return a.createEffect(()=>{o()&&t&&t.scrollIntoView({behavior:"smooth",block:"nearest"})}),(()=>{const s=sn.cloneNode(!0),l=s.firstChild,d=l.firstChild,m=l.nextSibling;s.$$mousedown=c,s.addEventListener("mouseleave",i),s.$$mousemove=r,s.$$mousemoveData=e.action,s.$$click=e.onActionItemSelect,s.$$clickData=e.action;const v=t;return typeof v=="function"?v(s):t=s,y(d,()=>e.action.title),y(l,a.createComponent(a.Show,{get when(){return e.action.subtitle},get children(){const f=on.cloneNode(!0);return y(f,()=>e.action.subtitle),a.createRenderEffect(()=>f.className=`${R.resultSubtitle} ${B.stripSpace}`),f}}),null),y(m,a.createComponent(a.Show,{get when(){return e.action.shortcut},children:f=>a.createComponent(te,{get class(){return R.resultShortcut},shortcut:f})})),a.createRenderEffect(f=>{const A=`scp-result-item-${e.action.id}`,w=R.resultItem,p={[R.activeItem]:o()},I=o(),h=`${R.resultTitle} ${B.stripSpace}`;return A!==f._v$&&b(s,"id",f._v$=A),w!==f._v$2&&(s.className=f._v$2=w),f._v$3=Le(s,p,f._v$3),I!==f._v$4&&b(s,"aria-selected",f._v$4=I),h!==f._v$5&&(d.className=f._v$5=h),f},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0,_v$5:void 0}),s})()},an=e=>(()=>{const t=rn.cloneNode(!0),n=t.firstChild;return y(n,a.createComponent(a.For,{get each(){return e.resultsList},get fallback(){return(()=>{const o=cn.cloneNode(!0),r=o.firstChild;return a.createRenderEffect(i=>{const c=R.resultItem,s=`${R.resultTitle} ${B.stripSpace}`;return c!==i._v$10&&(o.className=i._v$10=c),s!==i._v$11&&(r.className=i._v$11=s),i},{_v$10:void 0,_v$11:void 0}),o})()},children:o=>a.createComponent(ln,{action:o,get activeItemId(){return e.activeItemId},get onActionItemHover(){return e.onActionItemHover},get onActionItemSelect(){return e.onActionItemSelect}})})),a.createRenderEffect(o=>{const r=R.resultWrapper,i=e.resultListId,c=e.searchLabelId,s=`${R.resultList} ${B.stripSpace}`;return r!==o._v$6&&(t.className=o._v$6=r),i!==o._v$7&&b(n,"id",o._v$7=i),c!==o._v$8&&b(n,"aria-labelledby",o._v$8=c),s!==o._v$9&&(n.className=o._v$9=s),o},{_v$6:void 0,_v$7:void 0,_v$8:void 0,_v$9:void 0}),t})();U(["click","mousemove","mousedown"]);const dn="_footer_14oge_1",un="_group_14oge_11",fn="_shortcut_14oge_17",hn="_runShortcut_14oge_27",mn="_icon_14oge_31",vn="_iconArrow_14oge_36",_n="_iconReturn_14oge_40";var L={footer:dn,group:un,shortcut:fn,runShortcut:hn,icon:mn,iconArrow:vn,iconReturn:_n};const gn=E('<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M8 7l4-4m0 0l4 4m-4-4v18"></path></svg>'),$n=E('<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1" d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"></path></svg>'),yn=E("<div><div>Navigate with <kbd></kbd><kbd></kbd></div><div>Select using <kbd></kbd></div></div>"),Be=e=>(()=>{const t=gn.cloneNode(!0);return a.createRenderEffect(n=>{const o=`${L.icon} ${L.iconArrow}`,r=e.direction||"up";return o!==n._v$&&b(t,"class",n._v$=o),r!==n._v$2&&b(t,"data-arrow-direction",n._v$2=r),n},{_v$:void 0,_v$2:void 0}),t})(),An=()=>(()=>{const e=$n.cloneNode(!0);return a.createRenderEffect(()=>b(e,"class",`${L.icon} ${L.iconReturn}`)),e})(),Cn=()=>(()=>{const e=yn.cloneNode(!0),t=e.firstChild,n=t.firstChild,o=n.nextSibling,r=o.nextSibling,i=t.nextSibling,c=i.firstChild,s=c.nextSibling;return y(o,a.createComponent(Be,{})),y(r,a.createComponent(Be,{direction:"down"})),y(s,a.createComponent(An,{})),a.createRenderEffect(l=>{const d=L.footer,m=L.group,v=L.shortcut,f=L.shortcut,A=L.group,w=`${L.shortcut} ${L.runShortcut}`;return d!==l._v$3&&(e.className=l._v$3=d),m!==l._v$4&&(t.className=l._v$4=m),v!==l._v$5&&(o.className=l._v$5=v),f!==l._v$6&&(r.className=l._v$6=f),A!==l._v$7&&(i.className=l._v$7=A),w!==l._v$8&&(s.className=l._v$8=w),l},{_v$3:void 0,_v$4:void 0,_v$5:void 0,_v$6:void 0,_v$7:void 0,_v$8:void 0}),e})(),bn="_wrapper_1lhwr_1",wn="_palette_1lhwr_12",Sn="_panel_1lhwr_18",xn="_animEnter_1lhwr_36",En="_animEnterActive_1lhwr_47",Ln="_animExit_1lhwr_52",In="_animExitActive_1lhwr_56",Nn="_searchForm_1lhwr_68",Pn="_searchInput_1lhwr_75",kn="_closeBtn_1lhwr_96";var k={wrapper:bn,palette:wn,panel:Sn,animEnter:xn,animEnterActive:En,animExit:Ln,animExitActive:In,searchForm:Nn,searchInput:Pn,closeBtn:kn};const pn=E('<div><div><div role="combobox" aria-haspopup="listbox"><form role="search" novalidate><label>Search for an action and then select one of the option.</label><input type="search" aria-autocomplete="list" autocomplete="off" autocapitalize="off" placeholder="Type a command or search..." data-cp-kbd-shortcuts="disabled"><button type="button"><span>Close the Command Palette</span></button></form></div></div></div>'),Rn=()=>{const[e,t]=O(),{closePalette:n,setSearchText:o,revertParentAction:r}=t,i=Rt(),[c,s]=a.createSignal(null),[l,d]=a.createSignal("idle"),m=a.createUniqueId(),v=a.createUniqueId(),f=a.createUniqueId();let A,w,p,I;function h(u){De(u,e.actionsContext,t)}function $(){const u=i(),C=u.length,_=c(),x=u.findIndex(P=>P.id===_);if(x<0)return;const M=(C+x-1)%C,S=u[M].id;s(S)}function T(){const u=i(),C=u.length,_=c(),x=u.findIndex(P=>P.id===_);if(x<0)return;const M=(x+1)%C,S=u[M].id;s(S)}function D(){n()}function j(u){u.stopPropagation()}const N=u=>{const C=u.currentTarget.value;d("search"),o(C)};function He(u){h(u)}function qe(u){d("navigate-mouse"),s(u.id)}function Ge(u){const C=u.target;if(p&&p.contains(C))return;u.preventDefault();const _=c();if(!_)return null;const x=e.actions[_];h(x)}function Ue(u){u.preventDefault(),d("navigate-kbd"),$()}function Xe(u){u.preventDefault(),d("navigate-kbd"),T()}function Ye(u){u.preventDefault();const _=i()[0];_&&(d("navigate-kbd"),s(_.id))}function ze(u){u.preventDefault();const _=i().at(-1);_&&(d("navigate-kbd"),s(_.id))}function Ve(){e.searchText.length<=0&&r()}function We(){d("navigate-scroll-assist"),$()}function Je(){d("navigate-scroll-assist"),T()}function ne(){d("idle")}function oe(){return l()==="navigate-mouse"?"available":l()==="navigate-scroll-assist"?"running":"stopped"}return a.onMount(()=>{I=document.activeElement,w&&w.select(),A&&we.default(A,{Escape:u=>{u.preventDefault(),n()},Enter:Ge,ArrowUp:Ue,ArrowDown:Xe,PageUp:Ye,PageDown:ze,Backspace:Ve})}),a.onCleanup(()=>{I&&I.focus(),I=null}),a.createEffect(()=>{var _;const C=(_=i()[0])==null?void 0:_.id;s(C||null)}),(()=>{const u=pn.cloneNode(!0),C=u.firstChild,_=C.firstChild,x=_.firstChild,M=x.firstChild,S=M.nextSibling,P=S.nextSibling,Qe=P.firstChild;u.$$click=D;const ie=A;typeof ie=="function"?ie(u):A=u,y(C,a.createComponent(Fe,{direction:"up",get status(){return oe()},onNavigate:We,onStop:ne}),_),y(C,a.createComponent(Fe,{direction:"down",get status(){return oe()},onNavigate:Je,onStop:ne}),_),_.$$click=j,b(_,"aria-expanded",!0),b(_,"aria-controls",f),b(_,"aria-labelledby",m),x.addEventListener("submit",g=>{g.preventDefault()}),b(M,"for",v),b(M,"id",m),S.$$input=N;const se=w;typeof se=="function"?se(S):w=S,b(S,"id",v),b(S,"spellcheck",!1),P.$$click=()=>{n()};const re=p;return typeof re=="function"?re(P):p=P,y(P,a.createComponent(te,{shortcut:"Escape","aria-hidden":!0}),null),y(_,a.createComponent(an,{get activeItemId(){return c()},get resultsList(){return i()},resultListId:f,searchLabelId:m,onActionItemHover:qe,onActionItemSelect:He}),null),y(_,a.createComponent(Cn,{}),null),a.createRenderEffect(g=>{const ce=k.wrapper,le=k.palette,ae=`scp-result-item-${c()}`,de=k.panel,ue=k.searchForm,fe=B.visuallyHidden,he=k.searchInput,me=e.searchText,ve=k.closeBtn,_e=B.visuallyHidden;return ce!==g._v$&&(u.className=g._v$=ce),le!==g._v$2&&(C.className=g._v$2=le),ae!==g._v$3&&b(_,"aria-activedescendant",g._v$3=ae),de!==g._v$4&&(_.className=g._v$4=de),ue!==g._v$5&&(x.className=g._v$5=ue),fe!==g._v$6&&(M.className=g._v$6=fe),he!==g._v$7&&(S.className=g._v$7=he),me!==g._v$8&&(S.value=g._v$8=me),ve!==g._v$9&&(P.className=g._v$9=ve),_e!==g._v$10&&(Qe.className=g._v$10=_e),g},{_v$:void 0,_v$2:void 0,_v$3:void 0,_v$4:void 0,_v$5:void 0,_v$6:void 0,_v$7:void 0,_v$8:void 0,_v$9:void 0,_v$10:void 0}),u})()},Tn=()=>{const[e]=O();return a.createComponent(Kt,{get children(){return a.createComponent(jt,{get enterClass(){return k.animEnter},get enterActiveClass(){return k.animEnterActive},get exitClass(){return k.animExit},get exitActiveClass(){return k.animExitActive},get children(){return a.createComponent(a.Show,{get when(){return e.visibility==="opened"},get children(){return a.createComponent(Rn,{})}})}})}})};U(["click","input"]);const Mn=(e,t)=>{const[n,{setActionsContext:o,resetActionsContext:r}]=O();a.createEffect(()=>{const i=t();o(e,i)}),a.onCleanup(()=>{r(e)})},On=e=>{const t=e.id||Math.random().toString(),n=e.parentActionId||null,o=e.title,r=e.subtitle||null,i=e.keywords||[],c=e.shortcut||null,s=e.run;return{id:t,parentActionId:n,title:o,subtitle:r,keywords:i,shortcut:c,cond:e.cond,run:s}};exports.CommandPalette=Tn;exports.KbdShortcut=te;exports.Root=Dt;exports.createSyncActionsContext=Mn;exports.defineAction=On;