Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cmdk

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cmdk - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

2

dist/index.js

@@ -1,1 +0,1 @@

function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("react"),r=e(t),n=e(require("clsx")),a=require("@reach/auto-id"),l=e(require("react-merge-refs")),o=require("use-descendants"),i=e(require("match-sorter"));function c(){return(c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var d=["select","button","textarea"];function s(e,t){var r=Object.values(e.current);return r.length?i(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var m,f,p=t.createContext({}),v=function(){return t.useContext(p)},h=t.forwardRef(function(e,n){var l=e.label,o=e.className,i=e.children,d=u(e,["label","className","children"]),s=a.useId(),m=a.useId(),f=t.useMemo(function(){return c({listId:s,inputId:m},d)},[s,m,d]);return r.createElement(p.Provider,{value:f},r.createElement("div",{"data-command":"",className:o,ref:n},l&&r.createElement("label",{htmlFor:m,style:w},l),i))});h.displayName="Command";var b=o.createDescendants(),g=t.forwardRef(function(e,n){var a=e.children,o=u(e,["children"]),i=v(),d=i.listId,s=i.ordering,m=i.listRef,f=i.map,p=i.list,h=i.force;x(function(){if(s&&m.current){var e=new Map;Array.from(m.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===m.current)return;if(e.has(r))return;m.current.appendChild(r),e.set(r,!0)}})}});var g=t.useMemo(function(){return{list:p,map:f,force:h}},[p,f,h]);return r.createElement(t.Fragment,null,r.createElement("ul",c({ref:l([m,n]),role:"listbox",id:d,"data-command-list":"","data-command-list-empty":0===p.current.length?"":void 0},o),r.createElement(b.Provider,{value:g},a)),p.current.length>0&&r.createElement("div",{"aria-live":"polite",role:"status",style:w},p.current.length," result",p.current.length>1?"s":""," ","available."))});g.displayName="CommandList";var E=t.forwardRef(function(e,a){var i,d,s,m=e.children,f=u(e,["children"]),p=v(),h=p.selected,g=p.setSelected,E=p.filterList,y=p.search,C=p.ordering,w=p.map,x=p.itemClass,k=p.selectedItemClass,I=o.useDescendant(b,c({value:"string"==typeof m?m:void 0},f)),S=I.index,q=I.ref,N=I.id,A=!!w.current[N],D=h===S,L=t.useCallback((d=function(){requestAnimationFrame(function(){g(S)})},s=!1,function(){s||(s=!0,d.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return s=!1},50))}),[g,S]);t.useEffect(function(){D&&q.current&&q.current.scrollIntoView({block:"nearest"})},[D]);var O=E&&A?E.findIndex(function(e){return e._internalId===N}):void 0;return t.useEffect(function(){0===O&&g(S)},[y,S,O,g]),C&&-1===O?null:r.createElement("li",{ref:l([q,a]),onClick:f.callback,"data-order":O,className:n(x,(i={},i[k]=D,i)),onMouseMove:L,"aria-selected":D||void 0,role:"option","data-command-item":"","data-command-selected":D?"":void 0},m)});E.displayName="CommandItem";var y=t.forwardRef(function(e,t){var n=c({},e),a=v();return r.createElement("input",c({ref:t,value:a.search,onChange:a.setSearch},n,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":a.listId,id:a.inputId,"data-command-input":""}))});y.displayName="CommandInput";var C=function(){return r.createElement("li",{"data-command-separator":"",role:"separator"})},w={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},x="undefined"!=typeof window&&(null==(m=window)||null==(f=m.document)?void 0:f.createElement)?t.useLayoutEffect:t.useEffect;exports.Command=h,exports.CommandGroup=function(e){var n=e.children,l=e.heading,o=e.separator,i=u(e,["children","heading","separator"]),d=a.useId(),s=t.useRef(),m=t.useState(!0),f=m[0],p=m[1];return x(function(){s.current&&p(0!==s.current.children.length)}),r.createElement(t.Fragment,null,o&&r.createElement(C,null),r.createElement("li",c({"data-command-group":"",role:"presentation"},i,{style:f?void 0:{display:"none"}}),r.createElement("div",{"aria-hidden":!0,id:d},l),r.createElement("ul",{role:"group","aria-labelledby":d,ref:s},n)))},exports.CommandInput=y,exports.CommandItem=E,exports.CommandList=g,exports.useCommand=function(e){var r=void 0===e?{}:e,n=r.search,a=void 0===n?"":n,l=r.selected,i=void 0===l?0:l,m=r.ordering,f=void 0===m||m,p=r.filter,v=void 0===p?s:p,h=r.loop,b=void 0!==h&&h,g=r.element,E=u(r,["search","selected","ordering","filter","loop","element"]),y=o.useDescendants(),C=y.ref,w=u(y,["ref"]),x=t.useState(i),k=x[0],I=x[1],S=t.useState(a),q=S[0],N=S[1],A=v(w.map,q);return function(e){var r=e.setSelected,n=e.descendants,a=e.selected,l=e.loop,o=e.element,i=t.useCallback(function(){r(n.length-1)},[r,n]),c=t.useCallback(function(){r(0)},[r]),u=t.useCallback(function(){a===n.length-1?l&&r((a+1)%n.length):r(a+1)},[a,l,n,r]),s=t.useCallback(function(){0===a?l&&i():r(a-1)},[r,a,i,l]);t.useEffect(function(){function e(e){switch(e.key){case"Home":e.preventDefault(),c();break;case"End":e.preventDefault(),i();break;case"ArrowDown":e.preventDefault(),u();break;case"ArrowUp":e.preventDefault(),s();break;case"Enter":var t,r=null==(t=n[a])?void 0:t.callback;if(!r)return;if(document.activeElement){if(-1!==d.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}r()}}var t=o||window;return t.addEventListener("keydown",e),function(){return t.removeEventListener("keydown",e)}},[a,n,r,c,i,u,s,o])}({setSelected:I,selected:k,descendants:w.list.current,loop:b,element:g}),c({search:q,selected:k,setSelected:I,setSearch:t.useCallback(function(e){N(e?e.target.value:e)},[]),filterList:A,ordering:f,listRef:C},w,E)},exports.usePages=function(e,r){var n=e.setSearch,a=t.useState([r]),l=a[0],o=a[1];return t.useEffect(function(){n("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[l,n]),[l,o]};
function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var t=require("react"),r=e(t),n=e(require("clsx")),a=require("@reach/auto-id"),l=e(require("react-merge-refs")),o=require("use-descendants"),c=e(require("match-sorter"));function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var s=["select","button","textarea"];function d(e,t){var r=Object.values(e.current);return r.length?c(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var f,m,p=t.createContext({}),v=function(){return t.useContext(p)},h=t.forwardRef(function(e,n){var o=e.label,c=e.className,s=e.children,d=e.commandRef,f=u(e,["label","className","children","commandRef"]),m=a.useId(),v=a.useId(),h=t.useMemo(function(){return i({listId:m,inputId:v},f)},[m,v,f]);return r.createElement(p.Provider,{value:h},r.createElement("div",{"data-command":"",className:c,ref:l([n,d])},o&&r.createElement("label",{htmlFor:v,style:w},o),s))});h.displayName="Command";var b=o.createDescendants(),g=t.forwardRef(function(e,n){var a=e.children,o=u(e,["children"]),c=v(),s=c.listId,d=c.ordering,f=c.listRef,m=c.map,p=c.list,h=c.force;x(function(){if(d&&f.current){var e=new Map;Array.from(f.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===f.current)return;if(e.has(r))return;f.current.appendChild(r),e.set(r,!0)}})}});var g=t.useMemo(function(){return{list:p,map:m,force:h}},[p,m,h]);return r.createElement(t.Fragment,null,r.createElement("ul",i({ref:l([f,n]),role:"listbox",id:s,"data-command-list":"","data-command-list-empty":0===p.current.length?"":void 0},o),r.createElement(b.Provider,{value:g},a)),p.current.length>0&&r.createElement("div",{"aria-live":"polite",role:"status",style:w},p.current.length," result",p.current.length>1?"s":""," ","available."))});g.displayName="CommandList";var E=t.forwardRef(function(e,a){var c,s,d,f=e.children,m=u(e,["children"]),p=v(),h=p.selected,g=p.setSelected,E=p.filterList,y=p.search,C=p.ordering,w=p.map,x=p.itemClass,k=p.selectedItemClass,I=o.useDescendant(b,i({value:"string"==typeof f?f:void 0},m)),R=I.index,S=I.ref,q=I.id,N=!!w.current[q],A=h===R,D=t.useCallback((s=function(){requestAnimationFrame(function(){g(R)})},d=!1,function(){d||(d=!0,s.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return d=!1},50))}),[g,R]);t.useEffect(function(){A&&S.current&&S.current.scrollIntoView({block:"nearest"})},[A]);var L=E&&N?E.findIndex(function(e){return e._internalId===q}):void 0;return t.useEffect(function(){0===L&&g(R)},[y,R,L,g]),C&&-1===L?null:r.createElement("li",{ref:l([S,a]),onClick:m.callback,"data-order":L,className:n(x,(c={},c[k]=A,c)),onMouseMove:D,"aria-selected":A||void 0,role:"option","data-command-item":"","data-command-selected":A?"":void 0},f)});E.displayName="CommandItem";var y=t.forwardRef(function(e,t){var n=i({},e),a=v();return r.createElement("input",i({ref:t,value:a.search,onChange:a.setSearch},n,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":a.listId,id:a.inputId,"data-command-input":""}))});y.displayName="CommandInput";var C=function(){return r.createElement("li",{"data-command-separator":"",role:"separator"})},w={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},x="undefined"!=typeof window&&(null==(f=window)||null==(m=f.document)?void 0:m.createElement)?t.useLayoutEffect:t.useEffect;exports.Command=h,exports.CommandGroup=function(e){var n=e.children,l=e.heading,o=e.separator,c=u(e,["children","heading","separator"]),s=a.useId(),d=t.useRef(),f=t.useState(!0),m=f[0],p=f[1];return x(function(){d.current&&p(0!==d.current.children.length)}),r.createElement(t.Fragment,null,o&&r.createElement(C,null),r.createElement("li",i({"data-command-group":"",role:"presentation"},c,{style:m?void 0:{display:"none"}}),r.createElement("div",{"aria-hidden":!0,id:s},l),r.createElement("ul",{role:"group","aria-labelledby":s,ref:d},n)))},exports.CommandInput=y,exports.CommandItem=E,exports.CommandList=g,exports.useCommand=function(e){var r=void 0===e?{}:e,n=r.search,a=void 0===n?"":n,l=r.selected,c=void 0===l?0:l,f=r.ordering,m=void 0===f||f,p=r.filter,v=void 0===p?d:p,h=r.loop,b=void 0!==h&&h,g=r.element,E=u(r,["search","selected","ordering","filter","loop","element"]),y=o.useDescendants(),C=y.ref,w=u(y,["ref"]),x=t.useState(c),k=x[0],I=x[1],R=t.useState(a),S=R[0],q=R[1],N=t.useRef(),A=t.useRef(k);A.current=k;var D=v(w.map,S);return function(e){var r=e.setSelected,n=e.selectedRef,a=e.listProps,l=e.loop,o=e.element,c=t.useCallback(function(){r(a.list.current.length-1)},[]),i=t.useCallback(function(){r(0)},[]),u=t.useCallback(function(){r(function(e){return e===a.list.current.length-1?l?(e+1)%a.list.current.length:e:e+1})},[]),d=t.useCallback(function(){r(function(e){return 0===e?l?a.list.current.length-1:e:e-1})},[]),f=t.useCallback(function(e){switch(e.key){case"Home":e.preventDefault(),i();break;case"End":e.preventDefault(),c();break;case"ArrowDown":e.preventDefault(),u();break;case"ArrowUp":e.preventDefault(),d();break;case"Enter":var t,r=null==(t=a.list.current[n.current])?void 0:t.callback;if(console.log("enter pressed with selected",n.current,a.list.current,r),!r)return;if(document.activeElement){if(-1!==s.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}r()}},[]);t.useEffect(function(){return o&&o.addEventListener("keydown",f),function(){return null==o?void 0:o.removeEventListener("keydown",f)}},[o,f])}({setSelected:I,listProps:w,selectedRef:A,loop:b,element:g||N.current}),i({search:S,selected:k,setSelected:I,setSearch:t.useCallback(function(e){q(e?e.target.value:e)},[]),filterList:D,ordering:m,listRef:C,commandRef:N},w,E)},exports.usePages=function(e,r){var n=e.setSearch,a=t.useState([r]),l=a[0],o=a[1];return t.useEffect(function(){n("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[l,n]),[l,o]};

@@ -1,1 +0,1 @@

import e,{useState as t,useCallback as r,useEffect as n,createContext as a,forwardRef as l,useMemo as i,useContext as o,Fragment as c,useRef as d,useLayoutEffect as u}from"react";import s from"clsx";import{useId as m}from"@reach/auto-id";import f from"react-merge-refs";import{useDescendants as p,createDescendants as v,useDescendant as h}from"use-descendants";import g from"match-sorter";function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var y=["select","button","textarea"],w=function(e){var n=void 0===e?{}:e,a=n.search,l=void 0===a?"":a,i=n.selected,o=void 0===i?0:i,c=n.ordering,d=void 0===c||c,u=n.filter,s=void 0===u?x:u,m=n.loop,f=void 0!==m&&m,v=n.element,h=E(n,["search","selected","ordering","filter","loop","element"]),g=p(),y=g.ref,w=E(g,["ref"]),k=t(o),C=k[0],S=k[1],N=t(l),A=N[0],O=N[1],L=s(w.map,A);return I({setSelected:S,selected:C,descendants:w.list.current,loop:f,element:v}),b({search:A,selected:C,setSelected:S,setSearch:r(function(e){O(e?e.target.value:e)},[]),filterList:L,ordering:d,listRef:y},w,h)};function x(e,t){var r=Object.values(e.current);return r.length?g(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var k,C,I=function(e){var t=e.setSelected,a=e.descendants,l=e.selected,i=e.loop,o=e.element,c=r(function(){t(a.length-1)},[t,a]),d=r(function(){t(0)},[t]),u=r(function(){l===a.length-1?i&&t((l+1)%a.length):t(l+1)},[l,i,a,t]),s=r(function(){0===l?i&&c():t(l-1)},[t,l,c,i]);n(function(){function e(e){switch(e.key){case"Home":e.preventDefault(),d();break;case"End":e.preventDefault(),c();break;case"ArrowDown":e.preventDefault(),u();break;case"ArrowUp":e.preventDefault(),s();break;case"Enter":var t,r=null==(t=a[l])?void 0:t.callback;if(!r)return;if(document.activeElement){if(-1!==y.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}r()}}var t=o||window;return t.addEventListener("keydown",e),function(){return t.removeEventListener("keydown",e)}},[l,a,t,d,c,u,s,o])},S=function(e,r){var a=e.setSearch,l=t([r]),i=l[0],o=l[1];return n(function(){a("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[i,a]),[i,o]},N=a({}),A=function(){return o(N)},O=l(function(t,r){var n=t.label,a=t.className,l=t.children,o=E(t,["label","className","children"]),c=m(),d=m(),u=i(function(){return b({listId:c,inputId:d},o)},[c,d,o]);return e.createElement(N.Provider,{value:u},e.createElement("div",{"data-command":"",className:a,ref:r},n&&e.createElement("label",{htmlFor:d,style:F},n),l))});O.displayName="Command";var L=v(),D=l(function(t,r){var n=t.children,a=E(t,["children"]),l=A(),o=l.listId,d=l.ordering,u=l.listRef,s=l.map,m=l.list,p=l.force;R(function(){if(d&&u.current){var e=new Map;Array.from(u.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===u.current)return;if(e.has(r))return;u.current.appendChild(r),e.set(r,!0)}})}});var v=i(function(){return{list:m,map:s,force:p}},[m,s,p]);return e.createElement(c,null,e.createElement("ul",b({ref:f([u,r]),role:"listbox",id:o,"data-command-list":"","data-command-list-empty":0===m.current.length?"":void 0},a),e.createElement(L.Provider,{value:v},n)),m.current.length>0&&e.createElement("div",{"aria-live":"polite",role:"status",style:F},m.current.length," result",m.current.length>1?"s":""," ","available."))});D.displayName="CommandList";var j=l(function(t,a){var l,i,o,c=t.children,d=E(t,["children"]),u=A(),m=u.selected,p=u.setSelected,v=u.filterList,g=u.search,y=u.ordering,w=u.map,x=u.itemClass,k=u.selectedItemClass,C=h(L,b({value:"string"==typeof c?c:void 0},d)),I=C.index,S=C.ref,N=C.id,O=!!w.current[N],D=m===I,j=r((i=function(){requestAnimationFrame(function(){p(I)})},o=!1,function(){o||(o=!0,i.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return o=!1},50))}),[p,I]);n(function(){D&&S.current&&S.current.scrollIntoView({block:"nearest"})},[D]);var q=v&&O?v.findIndex(function(e){return e._internalId===N}):void 0;return n(function(){0===q&&p(I)},[g,I,q,p]),y&&-1===q?null:e.createElement("li",{ref:f([S,a]),onClick:d.callback,"data-order":q,className:s(x,(l={},l[k]=D,l)),onMouseMove:j,"aria-selected":D||void 0,role:"option","data-command-item":"","data-command-selected":D?"":void 0},c)});j.displayName="CommandItem";var q=l(function(t,r){var n=b({},t),a=A();return e.createElement("input",b({ref:r,value:a.search,onChange:a.setSearch},n,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":a.listId,id:a.inputId,"data-command-input":""}))});q.displayName="CommandInput";var M=function(r){var n=r.children,a=r.heading,l=r.separator,i=E(r,["children","heading","separator"]),o=m(),u=d(),s=t(!0),f=s[0],p=s[1];return R(function(){u.current&&p(0!==u.current.children.length)}),e.createElement(c,null,l&&e.createElement(P,null),e.createElement("li",b({"data-command-group":"",role:"presentation"},i,{style:f?void 0:{display:"none"}}),e.createElement("div",{"aria-hidden":!0,id:o},a),e.createElement("ul",{role:"group","aria-labelledby":o,ref:u},n)))},P=function(){return e.createElement("li",{"data-command-separator":"",role:"separator"})},F={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},R="undefined"!=typeof window&&(null==(k=window)||null==(C=k.document)?void 0:C.createElement)?u:n;export{O as Command,M as CommandGroup,q as CommandInput,j as CommandItem,D as CommandList,w as useCommand,S as usePages};
import e,{useState as t,useRef as r,useCallback as n,useEffect as a,createContext as l,forwardRef as i,useMemo as o,useContext as c,Fragment as u,useLayoutEffect as d}from"react";import s from"clsx";import{useId as m}from"@reach/auto-id";import f from"react-merge-refs";import{useDescendants as p,createDescendants as v,useDescendant as h}from"use-descendants";import g from"match-sorter";function b(){return(b=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var y=["select","button","textarea"],w=function(e){var a=void 0===e?{}:e,l=a.search,i=void 0===l?"":l,o=a.selected,c=void 0===o?0:o,u=a.ordering,d=void 0===u||u,s=a.filter,m=void 0===s?x:s,f=a.loop,v=void 0!==f&&f,h=a.element,g=E(a,["search","selected","ordering","filter","loop","element"]),y=p(),w=y.ref,k=E(y,["ref"]),C=t(c),S=C[0],N=C[1],A=t(i),O=A[0],R=A[1],L=r(),D=r(S);D.current=S;var P=m(k.map,O);return I({setSelected:N,listProps:k,selectedRef:D,loop:v,element:h||L.current}),b({search:O,selected:S,setSelected:N,setSearch:n(function(e){R(e?e.target.value:e)},[]),filterList:P,ordering:d,listRef:w,commandRef:L},k,g)};function x(e,t){var r=Object.values(e.current);return r.length?g(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var k,C,I=function(e){var t=e.setSelected,r=e.selectedRef,l=e.listProps,i=e.loop,o=e.element,c=n(function(){t(l.list.current.length-1)},[]),u=n(function(){t(0)},[]),d=n(function(){t(function(e){return e===l.list.current.length-1?i?(e+1)%l.list.current.length:e:e+1})},[]),s=n(function(){t(function(e){return 0===e?i?l.list.current.length-1:e:e-1})},[]),m=n(function(e){switch(e.key){case"Home":e.preventDefault(),u();break;case"End":e.preventDefault(),c();break;case"ArrowDown":e.preventDefault(),d();break;case"ArrowUp":e.preventDefault(),s();break;case"Enter":var t,n=null==(t=l.list.current[r.current])?void 0:t.callback;if(console.log("enter pressed with selected",r.current,l.list.current,n),!n)return;if(document.activeElement){if(-1!==y.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}n()}},[]);a(function(){return o&&o.addEventListener("keydown",m),function(){return null==o?void 0:o.removeEventListener("keydown",m)}},[o,m])},S=function(e,r){var n=e.setSearch,l=t([r]),i=l[0],o=l[1];return a(function(){n("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[i,n]),[i,o]},N=l({}),A=function(){return c(N)},O=i(function(t,r){var n=t.label,a=t.className,l=t.children,i=t.commandRef,c=E(t,["label","className","children","commandRef"]),u=m(),d=m(),s=o(function(){return b({listId:u,inputId:d},c)},[u,d,c]);return e.createElement(N.Provider,{value:s},e.createElement("div",{"data-command":"",className:a,ref:f([r,i])},n&&e.createElement("label",{htmlFor:d,style:M},n),l))});O.displayName="Command";var R=v(),L=i(function(t,r){var n=t.children,a=E(t,["children"]),l=A(),i=l.listId,c=l.ordering,d=l.listRef,s=l.map,m=l.list,p=l.force;F(function(){if(c&&d.current){var e=new Map;Array.from(d.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===d.current)return;if(e.has(r))return;d.current.appendChild(r),e.set(r,!0)}})}});var v=o(function(){return{list:m,map:s,force:p}},[m,s,p]);return e.createElement(u,null,e.createElement("ul",b({ref:f([d,r]),role:"listbox",id:i,"data-command-list":"","data-command-list-empty":0===m.current.length?"":void 0},a),e.createElement(R.Provider,{value:v},n)),m.current.length>0&&e.createElement("div",{"aria-live":"polite",role:"status",style:M},m.current.length," result",m.current.length>1?"s":""," ","available."))});L.displayName="CommandList";var D=i(function(t,r){var l,i,o,c=t.children,u=E(t,["children"]),d=A(),m=d.selected,p=d.setSelected,v=d.filterList,g=d.search,y=d.ordering,w=d.map,x=d.itemClass,k=d.selectedItemClass,C=h(R,b({value:"string"==typeof c?c:void 0},u)),I=C.index,S=C.ref,N=C.id,O=!!w.current[N],L=m===I,D=n((i=function(){requestAnimationFrame(function(){p(I)})},o=!1,function(){o||(o=!0,i.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return o=!1},50))}),[p,I]);a(function(){L&&S.current&&S.current.scrollIntoView({block:"nearest"})},[L]);var P=v&&O?v.findIndex(function(e){return e._internalId===N}):void 0;return a(function(){0===P&&p(I)},[g,I,P,p]),y&&-1===P?null:e.createElement("li",{ref:f([S,r]),onClick:u.callback,"data-order":P,className:s(x,(l={},l[k]=L,l)),onMouseMove:D,"aria-selected":L||void 0,role:"option","data-command-item":"","data-command-selected":L?"":void 0},c)});D.displayName="CommandItem";var P=i(function(t,r){var n=b({},t),a=A();return e.createElement("input",b({ref:r,value:a.search,onChange:a.setSearch},n,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":a.listId,id:a.inputId,"data-command-input":""}))});P.displayName="CommandInput";var j=function(n){var a=n.children,l=n.heading,i=n.separator,o=E(n,["children","heading","separator"]),c=m(),d=r(),s=t(!0),f=s[0],p=s[1];return F(function(){d.current&&p(0!==d.current.children.length)}),e.createElement(u,null,i&&e.createElement(q,null),e.createElement("li",b({"data-command-group":"",role:"presentation"},o,{style:f?void 0:{display:"none"}}),e.createElement("div",{"aria-hidden":!0,id:c},l),e.createElement("ul",{role:"group","aria-labelledby":c,ref:d},a)))},q=function(){return e.createElement("li",{"data-command-separator":"",role:"separator"})},M={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},F="undefined"!=typeof window&&(null==(k=window)||null==(C=k.document)?void 0:C.createElement)?d:a;export{O as Command,j as CommandGroup,P as CommandInput,D as CommandItem,L as CommandList,w as useCommand,S as usePages};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("clsx"),require("@reach/auto-id"),require("react-merge-refs"),require("use-descendants"),require("match-sorter")):"function"==typeof define&&define.amd?define(["exports","react","clsx","@reach/auto-id","react-merge-refs","use-descendants","match-sorter"],t):t((e=e||self).cmdk={},e.react,e.clsx,e.autoId,e.reactMergeRefs,e.useDescendants,e.matchSorter)}(this,function(e,t,r,n,a,l,o){var c="default"in t?t.default:t;function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var d=["select","button","textarea"];function s(e,t){var r=Object.values(e.current);return r.length?o(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var f,m,p=t.createContext({}),v=function(){return t.useContext(p)},h=t.forwardRef(function(e,r){var a=e.label,l=e.className,o=e.children,d=u(e,["label","className","children"]),s=n.useId(),f=n.useId(),m=t.useMemo(function(){return i({listId:s,inputId:f},d)},[s,f,d]);return c.createElement(p.Provider,{value:m},c.createElement("div",{"data-command":"",className:l,ref:r},a&&c.createElement("label",{htmlFor:f,style:C},a),o))});h.displayName="Command";var b=l.createDescendants(),g=t.forwardRef(function(e,r){var n=e.children,l=u(e,["children"]),o=v(),d=o.listId,s=o.ordering,f=o.listRef,m=o.map,p=o.list,h=o.force;x(function(){if(s&&f.current){var e=new Map;Array.from(f.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===f.current)return;if(e.has(r))return;f.current.appendChild(r),e.set(r,!0)}})}});var g=t.useMemo(function(){return{list:p,map:m,force:h}},[p,m,h]);return c.createElement(t.Fragment,null,c.createElement("ul",i({ref:a([f,r]),role:"listbox",id:d,"data-command-list":"","data-command-list-empty":0===p.current.length?"":void 0},l),c.createElement(b.Provider,{value:g},n)),p.current.length>0&&c.createElement("div",{"aria-live":"polite",role:"status",style:C},p.current.length," result",p.current.length>1?"s":""," ","available."))});g.displayName="CommandList";var y=t.forwardRef(function(e,n){var o,d,s,f=e.children,m=u(e,["children"]),p=v(),h=p.selected,g=p.setSelected,y=p.filterList,E=p.search,w=p.ordering,C=p.map,x=p.itemClass,k=p.selectedItemClass,I=l.useDescendant(b,i({value:"string"==typeof f?f:void 0},m)),S=I.index,O=I.ref,q=I.id,D=!!C.current[q],N=h===S,j=t.useCallback((d=function(){requestAnimationFrame(function(){g(S)})},s=!1,function(){s||(s=!0,d.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return s=!1},50))}),[g,S]);t.useEffect(function(){N&&O.current&&O.current.scrollIntoView({block:"nearest"})},[N]);var A=y&&D?y.findIndex(function(e){return e._internalId===q}):void 0;return t.useEffect(function(){0===A&&g(S)},[E,S,A,g]),w&&-1===A?null:c.createElement("li",{ref:a([O,n]),onClick:m.callback,"data-order":A,className:r(x,(o={},o[k]=N,o)),onMouseMove:j,"aria-selected":N||void 0,role:"option","data-command-item":"","data-command-selected":N?"":void 0},f)});y.displayName="CommandItem";var E=t.forwardRef(function(e,t){var r=i({},e),n=v();return c.createElement("input",i({ref:t,value:n.search,onChange:n.setSearch},r,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":n.listId,id:n.inputId,"data-command-input":""}))});E.displayName="CommandInput";var w=function(){return c.createElement("li",{"data-command-separator":"",role:"separator"})},C={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},x="undefined"!=typeof window&&(null==(f=window)||null==(m=f.document)?void 0:m.createElement)?t.useLayoutEffect:t.useEffect;e.Command=h,e.CommandGroup=function(e){var r=e.children,a=e.heading,l=e.separator,o=u(e,["children","heading","separator"]),d=n.useId(),s=t.useRef(),f=t.useState(!0),m=f[0],p=f[1];return x(function(){s.current&&p(0!==s.current.children.length)}),c.createElement(t.Fragment,null,l&&c.createElement(w,null),c.createElement("li",i({"data-command-group":"",role:"presentation"},o,{style:m?void 0:{display:"none"}}),c.createElement("div",{"aria-hidden":!0,id:d},a),c.createElement("ul",{role:"group","aria-labelledby":d,ref:s},r)))},e.CommandInput=E,e.CommandItem=y,e.CommandList=g,e.useCommand=function(e){var r=void 0===e?{}:e,n=r.search,a=void 0===n?"":n,o=r.selected,c=void 0===o?0:o,f=r.ordering,m=void 0===f||f,p=r.filter,v=void 0===p?s:p,h=r.loop,b=void 0!==h&&h,g=r.element,y=u(r,["search","selected","ordering","filter","loop","element"]),E=l.useDescendants(),w=E.ref,C=u(E,["ref"]),x=t.useState(c),k=x[0],I=x[1],S=t.useState(a),O=S[0],q=S[1],D=v(C.map,O);return function(e){var r=e.setSelected,n=e.descendants,a=e.selected,l=e.loop,o=e.element,c=t.useCallback(function(){r(n.length-1)},[r,n]),i=t.useCallback(function(){r(0)},[r]),u=t.useCallback(function(){a===n.length-1?l&&r((a+1)%n.length):r(a+1)},[a,l,n,r]),s=t.useCallback(function(){0===a?l&&c():r(a-1)},[r,a,c,l]);t.useEffect(function(){function e(e){switch(e.key){case"Home":e.preventDefault(),i();break;case"End":e.preventDefault(),c();break;case"ArrowDown":e.preventDefault(),u();break;case"ArrowUp":e.preventDefault(),s();break;case"Enter":var t,r=null==(t=n[a])?void 0:t.callback;if(!r)return;if(document.activeElement){if(-1!==d.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}r()}}var t=o||window;return t.addEventListener("keydown",e),function(){return t.removeEventListener("keydown",e)}},[a,n,r,i,c,u,s,o])}({setSelected:I,selected:k,descendants:C.list.current,loop:b,element:g}),i({search:O,selected:k,setSelected:I,setSearch:t.useCallback(function(e){q(e?e.target.value:e)},[]),filterList:D,ordering:m,listRef:w},C,y)},e.usePages=function(e,r){var n=e.setSearch,a=t.useState([r]),l=a[0],o=a[1];return t.useEffect(function(){n("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[l,n]),[l,o]}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("clsx"),require("@reach/auto-id"),require("react-merge-refs"),require("use-descendants"),require("match-sorter")):"function"==typeof define&&define.amd?define(["exports","react","clsx","@reach/auto-id","react-merge-refs","use-descendants","match-sorter"],t):t((e=e||self).cmdk={},e.react,e.clsx,e.autoId,e.reactMergeRefs,e.useDescendants,e.matchSorter)}(this,function(e,t,r,n,a,l,o){var c="default"in t?t.default:t;function u(){return(u=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}r=r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r,a=a&&Object.prototype.hasOwnProperty.call(a,"default")?a.default:a,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var d=["select","button","textarea"];function s(e,t){var r=Object.values(e.current);return r.length?o(r,t,{keys:[function(e){return(null==e?void 0:e.value)||null}]}):null}var f,m,p=t.createContext({}),v=function(){return t.useContext(p)},h=t.forwardRef(function(e,r){var l=e.label,o=e.className,d=e.children,s=e.commandRef,f=i(e,["label","className","children","commandRef"]),m=n.useId(),v=n.useId(),h=t.useMemo(function(){return u({listId:m,inputId:v},f)},[m,v,f]);return c.createElement(p.Provider,{value:h},c.createElement("div",{"data-command":"",className:o,ref:a([r,s])},l&&c.createElement("label",{htmlFor:v,style:C},l),d))});h.displayName="Command";var b=l.createDescendants(),g=t.forwardRef(function(e,r){var n=e.children,l=i(e,["children"]),o=v(),d=o.listId,s=o.ordering,f=o.listRef,m=o.map,p=o.list,h=o.force;k(function(){if(s&&f.current){var e=new Map;Array.from(f.current.querySelectorAll("[data-descendant]")).sort(function(e,t){return e.getAttribute("data-order")-t.getAttribute("data-order")}).forEach(function(t){if(t.parentElement){t.parentElement.appendChild(t);var r=t.closest("[data-command-list] > *");if(!r||r===t||r===f.current)return;if(e.has(r))return;f.current.appendChild(r),e.set(r,!0)}})}});var g=t.useMemo(function(){return{list:p,map:m,force:h}},[p,m,h]);return c.createElement(t.Fragment,null,c.createElement("ul",u({ref:a([f,r]),role:"listbox",id:d,"data-command-list":"","data-command-list-empty":0===p.current.length?"":void 0},l),c.createElement(b.Provider,{value:g},n)),p.current.length>0&&c.createElement("div",{"aria-live":"polite",role:"status",style:C},p.current.length," result",p.current.length>1?"s":""," ","available."))});g.displayName="CommandList";var y=t.forwardRef(function(e,n){var o,d,s,f=e.children,m=i(e,["children"]),p=v(),h=p.selected,g=p.setSelected,y=p.filterList,E=p.search,w=p.ordering,C=p.map,k=p.itemClass,x=p.selectedItemClass,I=l.useDescendant(b,u({value:"string"==typeof f?f:void 0},m)),R=I.index,S=I.ref,O=I.id,q=!!C.current[O],D=h===R,N=t.useCallback((d=function(){requestAnimationFrame(function(){g(R)})},s=!1,function(){s||(s=!0,d.apply(void 0,[].slice.call(arguments)),setTimeout(function(){return s=!1},50))}),[g,R]);t.useEffect(function(){D&&S.current&&S.current.scrollIntoView({block:"nearest"})},[D]);var P=y&&q?y.findIndex(function(e){return e._internalId===O}):void 0;return t.useEffect(function(){0===P&&g(R)},[E,R,P,g]),w&&-1===P?null:c.createElement("li",{ref:a([S,n]),onClick:m.callback,"data-order":P,className:r(k,(o={},o[x]=D,o)),onMouseMove:N,"aria-selected":D||void 0,role:"option","data-command-item":"","data-command-selected":D?"":void 0},f)});y.displayName="CommandItem";var E=t.forwardRef(function(e,t){var r=u({},e),n=v();return c.createElement("input",u({ref:t,value:n.search,onChange:n.setSearch},r,{type:"text","aria-expanded":!0,"aria-autocomplete":"list","aria-haspopup":"listbox",autoComplete:"off",role:"combobox","aria-owns":n.listId,id:n.inputId,"data-command-input":""}))});E.displayName="CommandInput";var w=function(){return c.createElement("li",{"data-command-separator":"",role:"separator"})},C={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"},k="undefined"!=typeof window&&(null==(f=window)||null==(m=f.document)?void 0:m.createElement)?t.useLayoutEffect:t.useEffect;e.Command=h,e.CommandGroup=function(e){var r=e.children,a=e.heading,l=e.separator,o=i(e,["children","heading","separator"]),d=n.useId(),s=t.useRef(),f=t.useState(!0),m=f[0],p=f[1];return k(function(){s.current&&p(0!==s.current.children.length)}),c.createElement(t.Fragment,null,l&&c.createElement(w,null),c.createElement("li",u({"data-command-group":"",role:"presentation"},o,{style:m?void 0:{display:"none"}}),c.createElement("div",{"aria-hidden":!0,id:d},a),c.createElement("ul",{role:"group","aria-labelledby":d,ref:s},r)))},e.CommandInput=E,e.CommandItem=y,e.CommandList=g,e.useCommand=function(e){var r=void 0===e?{}:e,n=r.search,a=void 0===n?"":n,o=r.selected,c=void 0===o?0:o,f=r.ordering,m=void 0===f||f,p=r.filter,v=void 0===p?s:p,h=r.loop,b=void 0!==h&&h,g=r.element,y=i(r,["search","selected","ordering","filter","loop","element"]),E=l.useDescendants(),w=E.ref,C=i(E,["ref"]),k=t.useState(c),x=k[0],I=k[1],R=t.useState(a),S=R[0],O=R[1],q=t.useRef(),D=t.useRef(x);D.current=x;var N=v(C.map,S);return function(e){var r=e.setSelected,n=e.selectedRef,a=e.listProps,l=e.loop,o=e.element,c=t.useCallback(function(){r(a.list.current.length-1)},[]),u=t.useCallback(function(){r(0)},[]),i=t.useCallback(function(){r(function(e){return e===a.list.current.length-1?l?(e+1)%a.list.current.length:e:e+1})},[]),s=t.useCallback(function(){r(function(e){return 0===e?l?a.list.current.length-1:e:e-1})},[]),f=t.useCallback(function(e){switch(e.key){case"Home":e.preventDefault(),u();break;case"End":e.preventDefault(),c();break;case"ArrowDown":e.preventDefault(),i();break;case"ArrowUp":e.preventDefault(),s();break;case"Enter":var t,r=null==(t=a.list.current[n.current])?void 0:t.callback;if(console.log("enter pressed with selected",n.current,a.list.current,r),!r)return;if(document.activeElement){if(-1!==d.indexOf(document.activeElement.tagName.toLowerCase())||"true"===document.activeElement.contentEditable)return;if(!document.activeElement.hasAttribute("data-command-input"))return}r()}},[]);t.useEffect(function(){return o&&o.addEventListener("keydown",f),function(){return null==o?void 0:o.removeEventListener("keydown",f)}},[o,f])}({setSelected:I,listProps:C,selectedRef:D,loop:b,element:g||q.current}),u({search:S,selected:x,setSelected:I,setSearch:t.useCallback(function(e){O(e?e.target.value:e)},[]),filterList:N,ordering:m,listRef:w,commandRef:q},C,y)},e.usePages=function(e,r){var n=e.setSearch,a=t.useState([r]),l=a[0],o=a[1];return t.useEffect(function(){n("");var e=document.querySelector("[data-command-input]");null==e||e.focus()},[l,n]),[l,o]}});
{
"name": "cmdk",
"version": "0.0.2",
"version": "0.0.3",
"main": "./dist/index.js",

@@ -5,0 +5,0 @@ "module": "./dist/index.modern.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc