@inkeep/cxkit-primitives 0.5.33 → 0.5.35
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.
- package/dist/atoms/cmdk/index.cjs +1 -1
- package/dist/atoms/cmdk/index.js +96 -95
- package/dist/components/embedded-search/transform-results.cjs +1 -1
- package/dist/components/embedded-search/transform-results.js +14 -15
- package/dist/components/embedded-search/use-inkeep-search.cjs +1 -1
- package/dist/components/embedded-search/use-inkeep-search.js +41 -41
- package/dist/components/embedded-search.cjs +1 -1
- package/dist/components/embedded-search.js +293 -289
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),Re=require("@radix-ui/react-dialog"),ke=require("react"),je=require("./command-score.cjs"),I=require("@radix-ui/react-primitive"),D=require("@radix-ui/react-id"),_e=require("../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.cjs"),Pe=require("../../components/embedded-search.cjs"),Ae=require("../shadow/context.cjs");function ue(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const l=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,l.get?l:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const q=ue(Re),c=ue(ke),O='[cmdk-group=""]',Q='[cmdk-group-items=""]',Le='[cmdk-group-heading=""]',le='[cmdk-item=""]',ie=`${le}:not([aria-disabled="true"])`,X="cmdk-item-select",P="data-value",ae=(t,n,r)=>je.commandScore(t,n,r??[]),de=c.createContext(void 0),V=()=>c.useContext(de),fe=c.createContext(void 0),Y=()=>c.useContext(fe),me=c.createContext(void 0),Z=c.forwardRef((t,n)=>{const r=A(()=>({search:"",value:t.value??t.defaultValue??"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),l=A(()=>new Set),s=A(()=>new Map),d=A(()=>new Map),f=A(()=>new Set),m=Ee(t),{label:a,children:y,value:b,onValueChange:E,filter:w,shouldFilter:x,loop:_,disablePointerSelection:Ce=!1,vimBindings:G=!0,...K}=t,ee=D.useId(),N=D.useId(),p=D.useId(),L=c.useRef(null),C=Ve();k(()=>{if(b!==void 0){const e=b.trim();r.current.value=e,S.emit()}},[b]),k(()=>{C(6,re)},[]);const Ie=Ae.useShadow(),S=c.useMemo(()=>({subscribe:e=>(f.current.add(e),()=>f.current.delete(e)),snapshot:()=>r.current,setState:(e,i,o)=>{if(!Object.is(r.current[e],i)){if(r.current[e]=i,e==="search")z(),$(),C(1,U);else if(e==="value"&&(Ie?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input")||C(1,()=>{R()?.focus()}),C(7,()=>{r.current.selectedItemId=R()?.id,S.emit()}),o||C(5,re),m.current?.value!==void 0)){const g=i??"";m.current.onValueChange?.(g);return}S.emit()}},emit:()=>{f.current.forEach(e=>e())}}),[]),B=c.useMemo(()=>({value:(e,i,o)=>{i!==d.current.get(e)?.value&&(d.current.set(e,{value:i,keywords:o}),r.current.filtered.items.set(e,te(i,o)),C(2,()=>{$(),S.emit()}))},item:(e,i)=>(l.current.add(e),i&&(s.current.has(i)?s.current?.get(i)?.add(e):s.current.set(i,new Set([e]))),C(3,()=>{z(),$(),r.current.value||U(),S.emit()}),()=>{d.current.delete(e),l.current.delete(e),r.current.filtered.items.delete(e);const o=R();C(4,()=>{z(),o?.getAttribute("id")===e&&U(),S.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{d.current.delete(e),s.current.delete(e)}),filter:()=>!!m.current.shouldFilter,label:a||t["aria-label"]||"",getDisablePointerSelection:()=>!!m.current.disablePointerSelection,listId:ee,inputId:p,labelId:N,listInnerRef:L}),[]);function te(e,i){const o=m.current?.filter??ae;return e?o?.(e,r.current.search,i):0}function $(){if(!r.current.search||m.current.shouldFilter===!1)return;const e=r.current.filtered.items,i=[];r.current.filtered.groups.forEach(u=>{const v=s.current.get(u);let g=0;v.forEach(J=>{const ye=e.get(J);g=Math.max(ye,g)}),i.push([u,g])});const o=L.current;M().sort((u,v)=>{const g=u.getAttribute("id"),J=v.getAttribute("id");return(e.get(J)??0)-(e.get(g)??0)}).forEach(u=>{const v=u.closest(Q);if(v){const g=u.parentElement===v?u:u.closest(`${Q} > *`);g&&v.appendChild(g)}else{const g=u.parentElement===o?u:u.closest(`${Q} > *`);g&&o?.appendChild(g)}}),i.sort((u,v)=>v[1]-u[1]).forEach(u=>{const v=L.current?.querySelector(`${O}[${P}="${encodeURIComponent(u[0])}"]`);v?.parentElement?.appendChild(v)})}function U(){const i=M().find(o=>o.getAttribute("aria-disabled")!=="true"&&o.getAttribute("data-value")!==Pe.ASK_AI_TRIGGER_VALUE)?.getAttribute(P);S.setState("value",i||void 0)}function z(){if(!r.current.search||m.current.shouldFilter===!1){r.current.filtered.count=l.current.size;return}r.current.filtered.groups=new Set;let e=0;for(const i of l.current){const o=d.current.get(i)?.value??"",u=d.current.get(i)?.keywords??[],v=te(o,u);r.current.filtered.items.set(i,v),v>0&&e++}for(const[i,o]of s.current)for(const u of o){const v=r.current.filtered.items.get(u);if(v&&v>0){r.current.filtered.groups.add(i);break}}r.current.filtered.count=e}function re(){const e=R();e&&(e.parentElement?.firstChild===e&&e.closest(O)?.querySelector(Le)?.scrollIntoView({block:"nearest"}),e.scrollIntoView({block:"nearest"}))}function R(){return L.current?.querySelector(`${le}[aria-selected="true"]`)}function M(){return Array.from(L.current?.querySelectorAll(ie)||[])}function H(e){const o=M()[e];o&&S.setState("value",o.getAttribute(P))}function W(e){const i=R(),o=M(),u=o.findIndex(g=>g===i);let v=o[u+e];m.current?.loop&&(v=u+e<0?o[o.length-1]:u+e===o.length?o[0]:o[u+e]),v&&S.setState("value",v.getAttribute(P))}function ne(e){let o=R()?.closest(O),u;for(;o&&!u;)o=e>0?De(o,O):Te(o,O),u=o?.querySelector(ie);u?S.setState("value",u.getAttribute(P)):W(e)}const oe=()=>H(M().length-1),ce=e=>{e.preventDefault(),e.metaKey?oe():e.altKey?ne(1):W(1)},se=e=>{e.preventDefault(),e.metaKey?H(0):e.altKey?ne(-1):W(-1)};return h.jsxs(I.Primitive.div,{ref:n,tabIndex:-1,...K,"cmdk-root":"",onKeyDown:e=>{if(K.onKeyDown?.(e),!e.defaultPrevented)switch(e.key){case"n":case"j":{G&&e.ctrlKey&&ce(e);break}case"ArrowDown":{ce(e);break}case"p":case"k":{G&&e.ctrlKey&&se(e);break}case"ArrowUp":{se(e);break}case"Home":{e.preventDefault(),H(0);break}case"End":{e.preventDefault(),oe();break}case"Enter":if(!e.nativeEvent.isComposing&&e.keyCode!==229){e.preventDefault();const i=R();if(i){const o=new Event(X);i.dispatchEvent(o)}}}},children:[h.jsx("label",{"cmdk-label":"",htmlFor:B.inputId,id:B.labelId,style:Fe,children:a}),F(t,e=>h.jsx(fe.Provider,{value:S,children:h.jsx(de.Provider,{value:B,children:e})}))]})}),ve=c.forwardRef((t,n)=>{const{id:r}=t,l=c.useRef(null),s=c.useContext(me),d=V(),f=Ee(t),m=f.current?.forceMount??s?.forceMount;k(()=>{if(!m)return d.item(r,s?.id)},[m]);const a=we(r,l,[t.value,t.children,l],t.keywords),y=Y(),b=j(p=>p.value&&p.value===a.current),E=j(p=>m||d.filter()===!1?!0:p.search?p.filtered.items.get(r)>0:!0);c.useEffect(()=>{const p=l.current;if(!(!p||t.disabled))return p.addEventListener(X,w),()=>p.removeEventListener(X,w)},[E,t.onSelect,t.disabled]);function w(){x(),f.current.onSelect?.(a.current)}function x(){y.setState("value",a.current,!0)}if(!E)return null;const{disabled:_,value:Ce,onSelect:G,forceMount:K,keywords:ee,...N}=t;return h.jsx(I.Primitive.div,{ref:T([l,n]),...N,id:r,"cmdk-item":"",role:"option","aria-disabled":!!_,"aria-selected":!!b,"data-disabled":!!_,"data-selected":!!b,onPointerMove:_||d.getDisablePointerSelection()?void 0:x,onClick:_?void 0:w,onFocus:_?void 0:x,children:t.children})}),Me=c.forwardRef((t,n)=>{const{heading:r,children:l,forceMount:s,...d}=t,f=D.useId(),m=c.useRef(null),a=c.useRef(null),y=D.useId(),b=V(),E=j(x=>s||b.filter()===!1?!0:x.search?x.filtered.groups.has(f):!0);k(()=>b.group(f),[]),we(f,m,[t.value,t.heading,a]);const w=c.useMemo(()=>({id:f,forceMount:s}),[s]);return h.jsxs(I.Primitive.div,{ref:T([m,n]),...d,"cmdk-group":"",role:"presentation",hidden:E?void 0:!0,children:[r&&h.jsx("div",{ref:a,"cmdk-group-heading":"","aria-hidden":!0,id:y,children:r}),F(t,x=>h.jsx("div",{"cmdk-group-items":"",role:"group","aria-labelledby":r?y:void 0,children:h.jsx(me.Provider,{value:w,children:x})}))]})}),he=c.forwardRef((t,n)=>{const{alwaysRender:r,...l}=t,s=c.useRef(null),d=j(f=>!f.search);return!r&&!d?null:h.jsx(I.Primitive.div,{ref:T([s,n]),...l,"cmdk-separator":"",role:"separator"})}),ge=c.forwardRef((t,n)=>{const{onValueChange:r,...l}=t,s=t.value!=null,d=Y(),f=j(a=>a.search),m=V();return c.useEffect(()=>{t.value!=null&&d.setState("search",t.value)},[t.value]),h.jsx(I.Primitive.input,{ref:n,...l,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":m.listId,"aria-labelledby":m.labelId,id:m.inputId,type:"text",value:s?t.value:f,onChange:a=>{s||d.setState("search",a.target.value),r?.(a.target.value)}})}),be=c.forwardRef((t,n)=>{const{children:r,label:l="Suggestions",...s}=t,d=c.useRef(null),f=c.useRef(null),m=V();return c.useEffect(()=>{if(f.current&&d.current){const a=f.current,y=d.current;let b;const E=new ResizeObserver(()=>{b=requestAnimationFrame(()=>{const w=a.offsetHeight;y.style.setProperty("--cmdk-list-height",w.toFixed(1)+"px")})});return E.observe(a),()=>{cancelAnimationFrame(b),E.unobserve(a)}}},[]),h.jsx(I.Primitive.div,{ref:T([d,n]),...s,"cmdk-list":"",tabIndex:-1,"aria-label":l,id:m.listId,children:F(t,a=>h.jsx("div",{ref:T([f,m.listInnerRef]),"cmdk-list-sizer":"",children:a}))})}),pe=c.forwardRef((t,n)=>{const{open:r,onOpenChange:l,overlayClassName:s,contentClassName:d,container:f,...m}=t;return h.jsx(q.Root,{open:r,onOpenChange:l,children:h.jsxs(q.Portal,{container:f,children:[h.jsx(q.Overlay,{"cmdk-overlay":"",className:s}),h.jsx(q.Content,{"aria-label":t.label,"cmdk-dialog":"",className:d,children:h.jsx(Z,{ref:n,...m})})]})})}),Se=c.forwardRef((t,n)=>j(l=>l.filtered.count===0)?h.jsx(I.Primitive.div,{ref:n,...t,"cmdk-empty":"",role:"presentation"}):null),xe=c.forwardRef((t,n)=>{const{progress:r,children:l,label:s="Loading...",...d}=t;return h.jsx(I.Primitive.div,{ref:n,...d,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s,children:F(t,f=>h.jsx("div",{"aria-hidden":!0,children:f}))})}),Oe=Object.assign(Z,{List:be,Item:ve,Input:ge,Group:Me,Separator:he,Dialog:pe,Empty:Se,Loading:xe});function De(t,n){let r=t.nextElementSibling;for(;r;){if(r.matches(n))return r;r=r.nextElementSibling}}function Te(t,n){let r=t.previousElementSibling;for(;r;){if(r.matches(n))return r;r=r.previousElementSibling}}function Ee(t){const n=c.useRef(t);return k(()=>{n.current=t}),n}const k=typeof window>"u"?c.useEffect:c.useLayoutEffect;function A(t){const n=c.useRef(void 0);return n.current===void 0&&(n.current=t()),n}function T(t){return n=>{t.forEach(r=>{typeof r=="function"?r(n):r!=null&&(r.current=n)})}}function j(t){const n=Y(),r=()=>t(n.snapshot());return _e.shimExports.useSyncExternalStore(n.subscribe,r,r)}function we(t,n,r,l=[]){const s=c.useRef(void 0),d=V();return k(()=>{const f=(()=>{for(const a of r){if(typeof a=="string")return a.trim();if(typeof a=="object"&&"current"in a)return a.current?a.current.textContent?.trim():s.current}})(),m=l.map(a=>a.trim());d.value(t,f,m),n.current?.setAttribute(P,f),s.current=f}),s}const Ve=()=>{const[t,n]=c.useState(),r=A(()=>new Map);return k(()=>{r.current.forEach(l=>l()),r.current=new Map},[t]),(l,s)=>{r.current.set(l,s),n({})}};function qe(t){const n=t.type;return typeof n=="function"?n(t.props):"render"in n?n.render(t.props):t}function F({asChild:t,children:n},r){return t&&c.isValidElement(n)?c.cloneElement(qe(n),{ref:n.ref},r(n.props.children)):r(n)}const Fe={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};exports.Command=Oe;exports.CommandDialog=pe;exports.CommandEmpty=Se;exports.CommandInput=ge;exports.CommandItem=ve;exports.CommandList=be;exports.CommandLoading=xe;exports.CommandRoot=Z;exports.CommandSeparator=he;exports.defaultFilter=ae;exports.useCommandState=j;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),Re=require("@radix-ui/react-dialog"),ke=require("react"),je=require("./command-score.cjs"),y=require("@radix-ui/react-primitive"),D=require("@radix-ui/react-id"),_e=require("../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.cjs"),Pe=require("../../components/embedded-search.cjs"),Ae=require("../shadow/context.cjs");function le(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const u=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,u.get?u:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const q=le(Re),c=le(ke),O='[cmdk-group=""]',Q='[cmdk-group-items=""]',Le='[cmdk-group-heading=""]',ue='[cmdk-item=""]',ie=`${ue}:not([aria-disabled="true"])`,X="cmdk-item-select",A="data-value",ae=(t,n,r)=>je.commandScore(t,n,r??[]),de=c.createContext(void 0),V=()=>c.useContext(de),fe=c.createContext(void 0),Y=()=>c.useContext(fe),me=c.createContext(void 0),Z=c.forwardRef((t,n)=>{const r=L(()=>({search:"",value:t.value??t.defaultValue??"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),u=L(()=>new Set),s=L(()=>new Map),d=L(()=>new Map),f=L(()=>new Set),m=Ee(t),{label:a,children:I,value:p,onValueChange:E,filter:R,shouldFilter:x,loop:P,disablePointerSelection:Ce=!1,vimBindings:G=!0,...K}=t,ee=D.useId(),N=D.useId(),b=D.useId(),w=c.useRef(null),C=Ve();j(()=>{if(p!==void 0){const e=p.trim();r.current.value=e,S.emit()}},[p]),j(()=>{C(6,re)},[]);const ye=Ae.useShadow(),S=c.useMemo(()=>({subscribe:e=>(f.current.add(e),()=>f.current.delete(e)),snapshot:()=>r.current,setState:(e,i,o)=>{if(!Object.is(r.current[e],i)){if(r.current[e]=i,e==="search")z(),$(),C(1,U);else if(e==="value"&&(ye?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input")||C(1,()=>{k()?.focus()}),C(7,()=>{r.current.selectedItemId=k()?.id,S.emit()}),o||C(5,re),m.current?.value!==void 0)){const g=i??"";m.current.onValueChange?.(g);return}S.emit()}},emit:()=>{f.current.forEach(e=>e())}}),[]),B=c.useMemo(()=>({value:(e,i,o)=>{i!==d.current.get(e)?.value&&(d.current.set(e,{value:i,keywords:o}),r.current.filtered.items.set(e,te(i,o)),C(2,()=>{$(),S.emit()}))},item:(e,i)=>(u.current.add(e),i&&(s.current.has(i)?s.current?.get(i)?.add(e):s.current.set(i,new Set([e]))),C(3,()=>{z(),$(),r.current.value||U(),S.emit()}),()=>{d.current.delete(e),u.current.delete(e),r.current.filtered.items.delete(e);const o=k();C(4,()=>{z(),o?.getAttribute("id")===e&&U(),S.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{d.current.delete(e),s.current.delete(e)}),filter:()=>!!m.current.shouldFilter,label:a||t["aria-label"]||"",getDisablePointerSelection:()=>!!m.current.disablePointerSelection,listId:ee,inputId:b,labelId:N,listInnerRef:w}),[]);function te(e,i){const o=m.current?.filter??ae;return e?o?.(e,r.current.search,i):0}function $(){if(!r.current.search||m.current.shouldFilter===!1)return;const e=r.current.filtered.items,i=[];r.current.filtered.groups.forEach(l=>{const v=s.current.get(l);let g=0;v.forEach(J=>{const Ie=e.get(J);g=Math.max(Ie,g)}),i.push([l,g])});const o=w.current;M().sort((l,v)=>{const g=l.getAttribute("id"),J=v.getAttribute("id");return(e.get(J)??0)-(e.get(g)??0)}).forEach(l=>{const v=l.closest(Q);if(v){const g=l.parentElement===v?l:l.closest(`${Q} > *`);g&&v.appendChild(g)}else{const g=l.parentElement===o?l:l.closest(`${Q} > *`);g&&o?.appendChild(g)}}),i.sort((l,v)=>v[1]-l[1]).forEach(l=>{const v=w.current?.querySelector(`${O}[${A}="${encodeURIComponent(l[0])}"]`);v?.parentElement?.appendChild(v)})}function U(){const i=M().find(o=>o.getAttribute("aria-disabled")!=="true"&&o.getAttribute("data-value")!==Pe.ASK_AI_TRIGGER_VALUE)?.getAttribute(A);S.setState("value",i||void 0)}function z(){if(!r.current.search||m.current.shouldFilter===!1){r.current.filtered.count=u.current.size;return}r.current.filtered.groups=new Set;let e=0;for(const i of u.current){const o=d.current.get(i)?.value??"",l=d.current.get(i)?.keywords??[],v=te(o,l);r.current.filtered.items.set(i,v),v>0&&e++}for(const[i,o]of s.current)for(const l of o){const v=r.current.filtered.items.get(l);if(v&&v>0){r.current.filtered.groups.add(i);break}}r.current.filtered.count=e}function re(){const e=k();e&&(e.parentElement?.firstChild===e&&e.closest(O)?.querySelector(Le)?.scrollIntoView({block:"nearest"}),e.scrollIntoView({block:"nearest"}))}function k(){return w.current?.querySelector(`${ue}[aria-selected="true"]`)}function M(){return Array.from(w.current?.querySelectorAll(ie)||[])}function H(e){const o=M()[e];o&&S.setState("value",o.getAttribute(A))}function W(e){const i=k(),o=M(),l=o.findIndex(g=>g===i);let v=o[l+e];m.current?.loop&&(v=l+e<0?o[o.length-1]:l+e===o.length?o[0]:o[l+e]),v&&S.setState("value",v.getAttribute(A))}function ne(e){let o=k()?.closest(O),l;for(;o&&!l;)o=e>0?De(o,O):Te(o,O),l=o?.querySelector(ie);l?S.setState("value",l.getAttribute(A)):W(e)}const oe=()=>H(M().length-1),ce=e=>{e.preventDefault(),e.metaKey?oe():e.altKey?ne(1):W(1)},se=e=>{e.preventDefault(),e.metaKey?H(0):e.altKey?ne(-1):W(-1)};return h.jsxs(y.Primitive.div,{ref:n,tabIndex:-1,...K,"cmdk-root":"",onKeyDown:e=>{if(K.onKeyDown?.(e),!e.defaultPrevented)switch(e.key){case"n":case"j":{G&&e.ctrlKey&&ce(e);break}case"ArrowDown":{ce(e);break}case"p":case"k":{G&&e.ctrlKey&&se(e);break}case"ArrowUp":{se(e);break}case"Home":{e.preventDefault(),H(0);break}case"End":{e.preventDefault(),oe();break}case"Enter":if(!e.nativeEvent.isComposing&&e.keyCode!==229){e.preventDefault();const i=k();if(i){const o=new Event(X);i.dispatchEvent(o)}}}},children:[h.jsx("label",{"cmdk-label":"",htmlFor:B.inputId,id:B.labelId,style:Fe,children:a}),F(t,e=>h.jsx(fe.Provider,{value:S,children:h.jsx(de.Provider,{value:B,children:e})}))]})}),ve=c.forwardRef((t,n)=>{const{id:r}=t,u=c.useRef(null),s=c.useContext(me),d=V(),f=Ee(t),m=f.current?.forceMount??s?.forceMount;j(()=>{if(!m)return d.item(r,s?.id)},[m]);const a=we(r,u,[t.value,t.children,u],t.keywords),I=Y(),p=_(b=>b.value&&b.value===a.current),E=_(b=>m||d.filter()===!1?!0:b.search?b.filtered.items.get(r)>0:!0);c.useEffect(()=>{const b=u.current;if(!b||t.disabled)return;const w=()=>R("keyboard");return b.addEventListener(X,w),()=>b.removeEventListener(X,w)},[E,t.onSelect,t.disabled]);function R(b="click"){x(),f.current.onSelect?.({value:a.current,trigger:b})}function x(){I.setState("value",a.current,!0)}if(!E)return null;const{disabled:P,value:Ce,onSelect:G,forceMount:K,keywords:ee,...N}=t;return h.jsx(y.Primitive.div,{ref:T([u,n]),...N,id:r,"cmdk-item":"",role:"option","aria-disabled":!!P,"aria-selected":!!p,"data-disabled":!!P,"data-selected":!!p,onPointerMove:P||d.getDisablePointerSelection()?void 0:x,onClick:P?void 0:()=>R(),onFocus:P?void 0:x,children:t.children})}),Me=c.forwardRef((t,n)=>{const{heading:r,children:u,forceMount:s,...d}=t,f=D.useId(),m=c.useRef(null),a=c.useRef(null),I=D.useId(),p=V(),E=_(x=>s||p.filter()===!1?!0:x.search?x.filtered.groups.has(f):!0);j(()=>p.group(f),[]),we(f,m,[t.value,t.heading,a]);const R=c.useMemo(()=>({id:f,forceMount:s}),[s]);return h.jsxs(y.Primitive.div,{ref:T([m,n]),...d,"cmdk-group":"",role:"presentation",hidden:E?void 0:!0,children:[r&&h.jsx("div",{ref:a,"cmdk-group-heading":"","aria-hidden":!0,id:I,children:r}),F(t,x=>h.jsx("div",{"cmdk-group-items":"",role:"group","aria-labelledby":r?I:void 0,children:h.jsx(me.Provider,{value:R,children:x})}))]})}),he=c.forwardRef((t,n)=>{const{alwaysRender:r,...u}=t,s=c.useRef(null),d=_(f=>!f.search);return!r&&!d?null:h.jsx(y.Primitive.div,{ref:T([s,n]),...u,"cmdk-separator":"",role:"separator"})}),ge=c.forwardRef((t,n)=>{const{onValueChange:r,...u}=t,s=t.value!=null,d=Y(),f=_(a=>a.search),m=V();return c.useEffect(()=>{t.value!=null&&d.setState("search",t.value)},[t.value]),h.jsx(y.Primitive.input,{ref:n,...u,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":m.listId,"aria-labelledby":m.labelId,id:m.inputId,type:"text",value:s?t.value:f,onChange:a=>{s||d.setState("search",a.target.value),r?.(a.target.value)}})}),be=c.forwardRef((t,n)=>{const{children:r,label:u="Suggestions",...s}=t,d=c.useRef(null),f=c.useRef(null),m=V();return c.useEffect(()=>{if(f.current&&d.current){const a=f.current,I=d.current;let p;const E=new ResizeObserver(()=>{p=requestAnimationFrame(()=>{const R=a.offsetHeight;I.style.setProperty("--cmdk-list-height",R.toFixed(1)+"px")})});return E.observe(a),()=>{cancelAnimationFrame(p),E.unobserve(a)}}},[]),h.jsx(y.Primitive.div,{ref:T([d,n]),...s,"cmdk-list":"",tabIndex:-1,"aria-label":u,id:m.listId,children:F(t,a=>h.jsx("div",{ref:T([f,m.listInnerRef]),"cmdk-list-sizer":"",children:a}))})}),pe=c.forwardRef((t,n)=>{const{open:r,onOpenChange:u,overlayClassName:s,contentClassName:d,container:f,...m}=t;return h.jsx(q.Root,{open:r,onOpenChange:u,children:h.jsxs(q.Portal,{container:f,children:[h.jsx(q.Overlay,{"cmdk-overlay":"",className:s}),h.jsx(q.Content,{"aria-label":t.label,"cmdk-dialog":"",className:d,children:h.jsx(Z,{ref:n,...m})})]})})}),Se=c.forwardRef((t,n)=>_(u=>u.filtered.count===0)?h.jsx(y.Primitive.div,{ref:n,...t,"cmdk-empty":"",role:"presentation"}):null),xe=c.forwardRef((t,n)=>{const{progress:r,children:u,label:s="Loading...",...d}=t;return h.jsx(y.Primitive.div,{ref:n,...d,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":s,children:F(t,f=>h.jsx("div",{"aria-hidden":!0,children:f}))})}),Oe=Object.assign(Z,{List:be,Item:ve,Input:ge,Group:Me,Separator:he,Dialog:pe,Empty:Se,Loading:xe});function De(t,n){let r=t.nextElementSibling;for(;r;){if(r.matches(n))return r;r=r.nextElementSibling}}function Te(t,n){let r=t.previousElementSibling;for(;r;){if(r.matches(n))return r;r=r.previousElementSibling}}function Ee(t){const n=c.useRef(t);return j(()=>{n.current=t}),n}const j=typeof window>"u"?c.useEffect:c.useLayoutEffect;function L(t){const n=c.useRef(void 0);return n.current===void 0&&(n.current=t()),n}function T(t){return n=>{t.forEach(r=>{typeof r=="function"?r(n):r!=null&&(r.current=n)})}}function _(t){const n=Y(),r=()=>t(n.snapshot());return _e.shimExports.useSyncExternalStore(n.subscribe,r,r)}function we(t,n,r,u=[]){const s=c.useRef(void 0),d=V();return j(()=>{const f=(()=>{for(const a of r){if(typeof a=="string")return a.trim();if(typeof a=="object"&&"current"in a)return a.current?a.current.textContent?.trim():s.current}})(),m=u.map(a=>a.trim());d.value(t,f,m),n.current?.setAttribute(A,f),s.current=f}),s}const Ve=()=>{const[t,n]=c.useState(),r=L(()=>new Map);return j(()=>{r.current.forEach(u=>u()),r.current=new Map},[t]),(u,s)=>{r.current.set(u,s),n({})}};function qe(t){const n=t.type;return typeof n=="function"?n(t.props):"render"in n?n.render(t.props):t}function F({asChild:t,children:n},r){return t&&c.isValidElement(n)?c.cloneElement(qe(n),{ref:n.ref},r(n.props.children)):r(n)}const Fe={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};exports.Command=Oe;exports.CommandDialog=pe;exports.CommandEmpty=Se;exports.CommandInput=ge;exports.CommandItem=ve;exports.CommandList=be;exports.CommandLoading=xe;exports.CommandRoot=Z;exports.CommandSeparator=he;exports.defaultFilter=ae;exports.useCommandState=_;
|
package/dist/atoms/cmdk/index.js
CHANGED
|
@@ -2,13 +2,13 @@ import { jsxs as Y, jsx as h } from "react/jsx-runtime";
|
|
|
2
2
|
import * as G from "@radix-ui/react-dialog";
|
|
3
3
|
import * as c from "react";
|
|
4
4
|
import { commandScore as be } from "./command-score.js";
|
|
5
|
-
import { Primitive as
|
|
5
|
+
import { Primitive as R } from "@radix-ui/react-primitive";
|
|
6
6
|
import { useId as T } from "@radix-ui/react-id";
|
|
7
7
|
import { s as Se } from "../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.js";
|
|
8
8
|
import { ASK_AI_TRIGGER_VALUE as Ee } from "../../components/embedded-search.js";
|
|
9
9
|
import { useShadow as Ce } from "../shadow/context.js";
|
|
10
|
-
const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-heading=""]', le = '[cmdk-item=""]', ie = `${le}:not([aria-disabled="true"])`, X = "cmdk-item-select",
|
|
11
|
-
const t =
|
|
10
|
+
const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-heading=""]', le = '[cmdk-item=""]', ie = `${le}:not([aria-disabled="true"])`, X = "cmdk-item-select", L = "data-value", ye = (r, n, t) => be(r, n, t ?? []), ue = c.createContext(void 0), O = () => c.useContext(ue), ae = c.createContext(void 0), Z = () => c.useContext(ae), de = c.createContext(void 0), fe = c.forwardRef((r, n) => {
|
|
11
|
+
const t = M(() => ({
|
|
12
12
|
/** Value of the search query. */
|
|
13
13
|
search: "",
|
|
14
14
|
/** Currently selected item value. */
|
|
@@ -23,25 +23,25 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
23
23
|
/** Set of groups with at least one visible item. */
|
|
24
24
|
groups: /* @__PURE__ */ new Set()
|
|
25
25
|
}
|
|
26
|
-
})), a =
|
|
26
|
+
})), a = M(() => /* @__PURE__ */ new Set()), s = M(() => /* @__PURE__ */ new Map()), d = M(() => /* @__PURE__ */ new Map()), f = M(() => /* @__PURE__ */ new Set()), m = me(r), {
|
|
27
27
|
label: u,
|
|
28
|
-
children:
|
|
29
|
-
value:
|
|
28
|
+
children: I,
|
|
29
|
+
value: b,
|
|
30
30
|
onValueChange: C,
|
|
31
|
-
filter:
|
|
31
|
+
filter: x,
|
|
32
32
|
shouldFilter: E,
|
|
33
|
-
loop:
|
|
33
|
+
loop: _,
|
|
34
34
|
disablePointerSelection: he = !1,
|
|
35
35
|
vimBindings: B = !0,
|
|
36
36
|
...N
|
|
37
|
-
} = r, ee = T(), U = T(),
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
const e =
|
|
37
|
+
} = r, ee = T(), U = T(), p = T(), w = c.useRef(null), y = De();
|
|
38
|
+
A(() => {
|
|
39
|
+
if (b !== void 0) {
|
|
40
|
+
const e = b.trim();
|
|
41
41
|
t.current.value = e, S.emit();
|
|
42
42
|
}
|
|
43
|
-
}, [
|
|
44
|
-
|
|
43
|
+
}, [b]), A(() => {
|
|
44
|
+
y(6, re);
|
|
45
45
|
}, []);
|
|
46
46
|
const ge = Ce(), S = c.useMemo(() => ({
|
|
47
47
|
subscribe: (e) => (f.current.add(e), () => f.current.delete(e)),
|
|
@@ -49,12 +49,12 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
49
49
|
setState: (e, i, o) => {
|
|
50
50
|
if (!Object.is(t.current[e], i)) {
|
|
51
51
|
if (t.current[e] = i, e === "search")
|
|
52
|
-
z(), j(),
|
|
53
|
-
else if (e === "value" && (ge?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input") ||
|
|
54
|
-
|
|
55
|
-
}),
|
|
56
|
-
t.current.selectedItemId =
|
|
57
|
-
}), o ||
|
|
52
|
+
z(), j(), y(1, q);
|
|
53
|
+
else if (e === "value" && (ge?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input") || y(1, () => {
|
|
54
|
+
k()?.focus();
|
|
55
|
+
}), y(7, () => {
|
|
56
|
+
t.current.selectedItemId = k()?.id, S.emit();
|
|
57
|
+
}), o || y(5, re), m.current?.value !== void 0)) {
|
|
58
58
|
const g = i ?? "";
|
|
59
59
|
m.current.onValueChange?.(g);
|
|
60
60
|
return;
|
|
@@ -69,17 +69,17 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
69
69
|
() => ({
|
|
70
70
|
// Keep id → {value, keywords} mapping up-to-date
|
|
71
71
|
value: (e, i, o) => {
|
|
72
|
-
i !== d.current.get(e)?.value && (d.current.set(e, { value: i, keywords: o }), t.current.filtered.items.set(e, te(i, o)),
|
|
72
|
+
i !== d.current.get(e)?.value && (d.current.set(e, { value: i, keywords: o }), t.current.filtered.items.set(e, te(i, o)), y(2, () => {
|
|
73
73
|
j(), S.emit();
|
|
74
74
|
}));
|
|
75
75
|
},
|
|
76
76
|
// Track item lifecycle (mount, unmount)
|
|
77
|
-
item: (e, i) => (a.current.add(e), i && (s.current.has(i) ? s.current?.get(i)?.add(e) : s.current.set(i, /* @__PURE__ */ new Set([e]))),
|
|
77
|
+
item: (e, i) => (a.current.add(e), i && (s.current.has(i) ? s.current?.get(i)?.add(e) : s.current.set(i, /* @__PURE__ */ new Set([e]))), y(3, () => {
|
|
78
78
|
z(), j(), t.current.value || q(), S.emit();
|
|
79
79
|
}), () => {
|
|
80
80
|
d.current.delete(e), a.current.delete(e), t.current.filtered.items.delete(e);
|
|
81
|
-
const o =
|
|
82
|
-
|
|
81
|
+
const o = k();
|
|
82
|
+
y(4, () => {
|
|
83
83
|
z(), o?.getAttribute("id") === e && q(), S.emit();
|
|
84
84
|
});
|
|
85
85
|
}),
|
|
@@ -91,14 +91,14 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
91
91
|
label: u || r["aria-label"] || "",
|
|
92
92
|
getDisablePointerSelection: () => !!m.current.disablePointerSelection,
|
|
93
93
|
listId: ee,
|
|
94
|
-
inputId:
|
|
94
|
+
inputId: p,
|
|
95
95
|
labelId: U,
|
|
96
|
-
listInnerRef:
|
|
96
|
+
listInnerRef: w
|
|
97
97
|
}),
|
|
98
98
|
[]
|
|
99
99
|
);
|
|
100
100
|
function te(e, i) {
|
|
101
|
-
const o = m.current?.filter ??
|
|
101
|
+
const o = m.current?.filter ?? ye;
|
|
102
102
|
return e ? o?.(e, t.current.search, i) : 0;
|
|
103
103
|
}
|
|
104
104
|
function j() {
|
|
@@ -114,7 +114,7 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
114
114
|
g = Math.max(pe, g);
|
|
115
115
|
}), i.push([l, g]);
|
|
116
116
|
});
|
|
117
|
-
const o =
|
|
117
|
+
const o = w.current;
|
|
118
118
|
V().sort((l, v) => {
|
|
119
119
|
const g = l.getAttribute("id"), J = v.getAttribute("id");
|
|
120
120
|
return (e.get(J) ?? 0) - (e.get(g) ?? 0);
|
|
@@ -128,8 +128,8 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
128
128
|
g && o?.appendChild(g);
|
|
129
129
|
}
|
|
130
130
|
}), i.sort((l, v) => v[1] - l[1]).forEach((l) => {
|
|
131
|
-
const v =
|
|
132
|
-
`${D}[${
|
|
131
|
+
const v = w.current?.querySelector(
|
|
132
|
+
`${D}[${L}="${encodeURIComponent(l[0])}"]`
|
|
133
133
|
);
|
|
134
134
|
v?.parentElement?.appendChild(v);
|
|
135
135
|
});
|
|
@@ -137,7 +137,7 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
137
137
|
function q() {
|
|
138
138
|
const i = V().find(
|
|
139
139
|
(o) => o.getAttribute("aria-disabled") !== "true" && o.getAttribute("data-value") !== Ee
|
|
140
|
-
)?.getAttribute(
|
|
140
|
+
)?.getAttribute(L);
|
|
141
141
|
S.setState("value", i || void 0);
|
|
142
142
|
}
|
|
143
143
|
function z() {
|
|
@@ -163,29 +163,29 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
163
163
|
t.current.filtered.count = e;
|
|
164
164
|
}
|
|
165
165
|
function re() {
|
|
166
|
-
const e =
|
|
166
|
+
const e = k();
|
|
167
167
|
e && (e.parentElement?.firstChild === e && e.closest(D)?.querySelector(we)?.scrollIntoView({ block: "nearest" }), e.scrollIntoView({ block: "nearest" }));
|
|
168
168
|
}
|
|
169
|
-
function
|
|
170
|
-
return
|
|
169
|
+
function k() {
|
|
170
|
+
return w.current?.querySelector(`${le}[aria-selected="true"]`);
|
|
171
171
|
}
|
|
172
172
|
function V() {
|
|
173
|
-
return Array.from(
|
|
173
|
+
return Array.from(w.current?.querySelectorAll(ie) || []);
|
|
174
174
|
}
|
|
175
175
|
function H(e) {
|
|
176
176
|
const o = V()[e];
|
|
177
|
-
o && S.setState("value", o.getAttribute(
|
|
177
|
+
o && S.setState("value", o.getAttribute(L));
|
|
178
178
|
}
|
|
179
179
|
function W(e) {
|
|
180
|
-
const i =
|
|
180
|
+
const i = k(), o = V(), l = o.findIndex((g) => g === i);
|
|
181
181
|
let v = o[l + e];
|
|
182
|
-
m.current?.loop && (v = l + e < 0 ? o[o.length - 1] : l + e === o.length ? o[0] : o[l + e]), v && S.setState("value", v.getAttribute(
|
|
182
|
+
m.current?.loop && (v = l + e < 0 ? o[o.length - 1] : l + e === o.length ? o[0] : o[l + e]), v && S.setState("value", v.getAttribute(L));
|
|
183
183
|
}
|
|
184
184
|
function ne(e) {
|
|
185
|
-
let o =
|
|
185
|
+
let o = k()?.closest(D), l;
|
|
186
186
|
for (; o && !l; )
|
|
187
187
|
o = e > 0 ? Pe(o, D) : Ve(o, D), l = o?.querySelector(ie);
|
|
188
|
-
l ? S.setState("value", l.getAttribute(
|
|
188
|
+
l ? S.setState("value", l.getAttribute(L)) : W(e);
|
|
189
189
|
}
|
|
190
190
|
const oe = () => H(V().length - 1), ce = (e) => {
|
|
191
191
|
e.preventDefault(), e.metaKey ? oe() : e.altKey ? ne(1) : W(1);
|
|
@@ -193,7 +193,7 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
193
193
|
e.preventDefault(), e.metaKey ? H(0) : e.altKey ? ne(-1) : W(-1);
|
|
194
194
|
};
|
|
195
195
|
return /* @__PURE__ */ Y(
|
|
196
|
-
|
|
196
|
+
R.div,
|
|
197
197
|
{
|
|
198
198
|
ref: n,
|
|
199
199
|
tabIndex: -1,
|
|
@@ -231,7 +231,7 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
231
231
|
case "Enter":
|
|
232
232
|
if (!e.nativeEvent.isComposing && e.keyCode !== 229) {
|
|
233
233
|
e.preventDefault();
|
|
234
|
-
const i =
|
|
234
|
+
const i = k();
|
|
235
235
|
if (i) {
|
|
236
236
|
const o = new Event(X);
|
|
237
237
|
i.dispatchEvent(o);
|
|
@@ -254,54 +254,55 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
254
254
|
]
|
|
255
255
|
}
|
|
256
256
|
);
|
|
257
|
-
}),
|
|
257
|
+
}), Re = c.forwardRef((r, n) => {
|
|
258
258
|
const { id: t } = r, a = c.useRef(null), s = c.useContext(de), d = O(), f = me(r), m = f.current?.forceMount ?? s?.forceMount;
|
|
259
|
-
|
|
259
|
+
A(() => {
|
|
260
260
|
if (!m)
|
|
261
261
|
return d.item(t, s?.id);
|
|
262
262
|
}, [m]);
|
|
263
|
-
const u = ve(t, a, [r.value, r.children, a], r.keywords),
|
|
264
|
-
(
|
|
263
|
+
const u = ve(t, a, [r.value, r.children, a], r.keywords), I = Z(), b = P((p) => p.value && p.value === u.current), C = P(
|
|
264
|
+
(p) => m || d.filter() === !1 ? !0 : p.search ? p.filtered.items.get(t) > 0 : !0
|
|
265
265
|
);
|
|
266
266
|
c.useEffect(() => {
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
|
|
267
|
+
const p = a.current;
|
|
268
|
+
if (!p || r.disabled) return;
|
|
269
|
+
const w = () => x("keyboard");
|
|
270
|
+
return p.addEventListener(X, w), () => p.removeEventListener(X, w);
|
|
270
271
|
}, [C, r.onSelect, r.disabled]);
|
|
271
|
-
function
|
|
272
|
-
E(), f.current.onSelect?.(u.current);
|
|
272
|
+
function x(p = "click") {
|
|
273
|
+
E(), f.current.onSelect?.({ value: u.current, trigger: p });
|
|
273
274
|
}
|
|
274
275
|
function E() {
|
|
275
|
-
|
|
276
|
+
I.setState("value", u.current, !0);
|
|
276
277
|
}
|
|
277
278
|
if (!C) return null;
|
|
278
|
-
const { disabled:
|
|
279
|
+
const { disabled: _, value: he, onSelect: B, forceMount: N, keywords: ee, ...U } = r;
|
|
279
280
|
return /* @__PURE__ */ h(
|
|
280
|
-
|
|
281
|
+
R.div,
|
|
281
282
|
{
|
|
282
283
|
ref: F([a, n]),
|
|
283
284
|
...U,
|
|
284
285
|
id: t,
|
|
285
286
|
"cmdk-item": "",
|
|
286
287
|
role: "option",
|
|
287
|
-
"aria-disabled": !!
|
|
288
|
-
"aria-selected": !!
|
|
289
|
-
"data-disabled": !!
|
|
290
|
-
"data-selected": !!
|
|
291
|
-
onPointerMove:
|
|
292
|
-
onClick:
|
|
293
|
-
onFocus:
|
|
288
|
+
"aria-disabled": !!_,
|
|
289
|
+
"aria-selected": !!b,
|
|
290
|
+
"data-disabled": !!_,
|
|
291
|
+
"data-selected": !!b,
|
|
292
|
+
onPointerMove: _ || d.getDisablePointerSelection() ? void 0 : E,
|
|
293
|
+
onClick: _ ? void 0 : () => x(),
|
|
294
|
+
onFocus: _ ? void 0 : E,
|
|
294
295
|
children: r.children
|
|
295
296
|
}
|
|
296
297
|
);
|
|
297
|
-
}),
|
|
298
|
-
const { heading: t, children: a, forceMount: s, ...d } = r, f = T(), m = c.useRef(null), u = c.useRef(null),
|
|
299
|
-
(E) => s ||
|
|
298
|
+
}), Ie = c.forwardRef((r, n) => {
|
|
299
|
+
const { heading: t, children: a, forceMount: s, ...d } = r, f = T(), m = c.useRef(null), u = c.useRef(null), I = T(), b = O(), C = P(
|
|
300
|
+
(E) => s || b.filter() === !1 ? !0 : E.search ? E.filtered.groups.has(f) : !0
|
|
300
301
|
);
|
|
301
|
-
|
|
302
|
-
const
|
|
302
|
+
A(() => b.group(f), []), ve(f, m, [r.value, r.heading, u]);
|
|
303
|
+
const x = c.useMemo(() => ({ id: f, forceMount: s }), [s]);
|
|
303
304
|
return /* @__PURE__ */ Y(
|
|
304
|
-
|
|
305
|
+
R.div,
|
|
305
306
|
{
|
|
306
307
|
ref: F([m, n]),
|
|
307
308
|
...d,
|
|
@@ -309,18 +310,18 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
309
310
|
role: "presentation",
|
|
310
311
|
hidden: C ? void 0 : !0,
|
|
311
312
|
children: [
|
|
312
|
-
t && /* @__PURE__ */ h("div", { ref: u, "cmdk-group-heading": "", "aria-hidden": !0, id:
|
|
313
|
+
t && /* @__PURE__ */ h("div", { ref: u, "cmdk-group-heading": "", "aria-hidden": !0, id: I, children: t }),
|
|
313
314
|
K(r, (E) => (
|
|
314
315
|
// biome-ignore lint/a11y/useSemanticElements: <explanation>
|
|
315
|
-
/* @__PURE__ */ h("div", { "cmdk-group-items": "", role: "group", "aria-labelledby": t ?
|
|
316
|
+
/* @__PURE__ */ h("div", { "cmdk-group-items": "", role: "group", "aria-labelledby": t ? I : void 0, children: /* @__PURE__ */ h(de.Provider, { value: x, children: E }) })
|
|
316
317
|
))
|
|
317
318
|
]
|
|
318
319
|
}
|
|
319
320
|
);
|
|
320
321
|
}), xe = c.forwardRef((r, n) => {
|
|
321
|
-
const { alwaysRender: t, ...a } = r, s = c.useRef(null), d =
|
|
322
|
+
const { alwaysRender: t, ...a } = r, s = c.useRef(null), d = P((f) => !f.search);
|
|
322
323
|
return !t && !d ? null : /* @__PURE__ */ h(
|
|
323
|
-
|
|
324
|
+
R.div,
|
|
324
325
|
{
|
|
325
326
|
ref: F([s, n]),
|
|
326
327
|
...a,
|
|
@@ -329,11 +330,11 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
329
330
|
}
|
|
330
331
|
);
|
|
331
332
|
}), ke = c.forwardRef((r, n) => {
|
|
332
|
-
const { onValueChange: t, ...a } = r, s = r.value != null, d = Z(), f =
|
|
333
|
+
const { onValueChange: t, ...a } = r, s = r.value != null, d = Z(), f = P((u) => u.search), m = O();
|
|
333
334
|
return c.useEffect(() => {
|
|
334
335
|
r.value != null && d.setState("search", r.value);
|
|
335
336
|
}, [r.value]), /* @__PURE__ */ h(
|
|
336
|
-
|
|
337
|
+
R.input,
|
|
337
338
|
{
|
|
338
339
|
ref: n,
|
|
339
340
|
...a,
|
|
@@ -358,20 +359,20 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
358
359
|
const { children: t, label: a = "Suggestions", ...s } = r, d = c.useRef(null), f = c.useRef(null), m = O();
|
|
359
360
|
return c.useEffect(() => {
|
|
360
361
|
if (f.current && d.current) {
|
|
361
|
-
const u = f.current,
|
|
362
|
-
let
|
|
362
|
+
const u = f.current, I = d.current;
|
|
363
|
+
let b;
|
|
363
364
|
const C = new ResizeObserver(() => {
|
|
364
|
-
|
|
365
|
-
const
|
|
366
|
-
|
|
365
|
+
b = requestAnimationFrame(() => {
|
|
366
|
+
const x = u.offsetHeight;
|
|
367
|
+
I.style.setProperty("--cmdk-list-height", x.toFixed(1) + "px");
|
|
367
368
|
});
|
|
368
369
|
});
|
|
369
370
|
return C.observe(u), () => {
|
|
370
|
-
cancelAnimationFrame(
|
|
371
|
+
cancelAnimationFrame(b), C.unobserve(u);
|
|
371
372
|
};
|
|
372
373
|
}
|
|
373
374
|
}, []), /* @__PURE__ */ h(
|
|
374
|
-
|
|
375
|
+
R.div,
|
|
375
376
|
{
|
|
376
377
|
ref: F([d, n]),
|
|
377
378
|
...s,
|
|
@@ -388,10 +389,10 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
388
389
|
/* @__PURE__ */ h(G.Overlay, { "cmdk-overlay": "", className: s }),
|
|
389
390
|
/* @__PURE__ */ h(G.Content, { "aria-label": r.label, "cmdk-dialog": "", className: d, children: /* @__PURE__ */ h(fe, { ref: n, ...m }) })
|
|
390
391
|
] }) });
|
|
391
|
-
}), Le = c.forwardRef((r, n) =>
|
|
392
|
+
}), Le = c.forwardRef((r, n) => P((a) => a.filtered.count === 0) ? /* @__PURE__ */ h(R.div, { ref: n, ...r, "cmdk-empty": "", role: "presentation" }) : null), Me = c.forwardRef((r, n) => {
|
|
392
393
|
const { progress: t, children: a, label: s = "Loading...", ...d } = r;
|
|
393
394
|
return /* @__PURE__ */ h(
|
|
394
|
-
|
|
395
|
+
R.div,
|
|
395
396
|
{
|
|
396
397
|
ref: n,
|
|
397
398
|
...d,
|
|
@@ -406,9 +407,9 @@ const D = '[cmdk-group=""]', Q = '[cmdk-group-items=""]', we = '[cmdk-group-head
|
|
|
406
407
|
);
|
|
407
408
|
}), je = Object.assign(fe, {
|
|
408
409
|
List: Ae,
|
|
409
|
-
Item:
|
|
410
|
+
Item: Re,
|
|
410
411
|
Input: ke,
|
|
411
|
-
Group:
|
|
412
|
+
Group: Ie,
|
|
412
413
|
Separator: xe,
|
|
413
414
|
Dialog: _e,
|
|
414
415
|
Empty: Le,
|
|
@@ -430,12 +431,12 @@ function Ve(r, n) {
|
|
|
430
431
|
}
|
|
431
432
|
function me(r) {
|
|
432
433
|
const n = c.useRef(r);
|
|
433
|
-
return
|
|
434
|
+
return A(() => {
|
|
434
435
|
n.current = r;
|
|
435
436
|
}), n;
|
|
436
437
|
}
|
|
437
|
-
const
|
|
438
|
-
function
|
|
438
|
+
const A = typeof window > "u" ? c.useEffect : c.useLayoutEffect;
|
|
439
|
+
function M(r) {
|
|
439
440
|
const n = c.useRef(void 0);
|
|
440
441
|
return n.current === void 0 && (n.current = r()), n;
|
|
441
442
|
}
|
|
@@ -446,13 +447,13 @@ function F(r) {
|
|
|
446
447
|
});
|
|
447
448
|
};
|
|
448
449
|
}
|
|
449
|
-
function
|
|
450
|
+
function P(r) {
|
|
450
451
|
const n = Z(), t = () => r(n.snapshot());
|
|
451
452
|
return Se.useSyncExternalStore(n.subscribe, t, t);
|
|
452
453
|
}
|
|
453
454
|
function ve(r, n, t, a = []) {
|
|
454
455
|
const s = c.useRef(void 0), d = O();
|
|
455
|
-
return
|
|
456
|
+
return A(() => {
|
|
456
457
|
const f = (() => {
|
|
457
458
|
for (const u of t) {
|
|
458
459
|
if (typeof u == "string")
|
|
@@ -461,12 +462,12 @@ function ve(r, n, t, a = []) {
|
|
|
461
462
|
return u.current ? u.current.textContent?.trim() : s.current;
|
|
462
463
|
}
|
|
463
464
|
})(), m = a.map((u) => u.trim());
|
|
464
|
-
d.value(r, f, m), n.current?.setAttribute(
|
|
465
|
+
d.value(r, f, m), n.current?.setAttribute(L, f), s.current = f;
|
|
465
466
|
}), s;
|
|
466
467
|
}
|
|
467
468
|
const De = () => {
|
|
468
|
-
const [r, n] = c.useState(), t =
|
|
469
|
-
return
|
|
469
|
+
const [r, n] = c.useState(), t = M(() => /* @__PURE__ */ new Map());
|
|
470
|
+
return A(() => {
|
|
470
471
|
t.current.forEach((a) => a()), t.current = /* @__PURE__ */ new Map();
|
|
471
472
|
}, [r]), (a, s) => {
|
|
472
473
|
t.current.set(a, s), n({});
|
|
@@ -500,11 +501,11 @@ export {
|
|
|
500
501
|
_e as CommandDialog,
|
|
501
502
|
Le as CommandEmpty,
|
|
502
503
|
ke as CommandInput,
|
|
503
|
-
|
|
504
|
+
Re as CommandItem,
|
|
504
505
|
Ae as CommandList,
|
|
505
506
|
Me as CommandLoading,
|
|
506
507
|
fe as CommandRoot,
|
|
507
508
|
xe as CommandSeparator,
|
|
508
|
-
|
|
509
|
-
|
|
509
|
+
ye as defaultFilter,
|
|
510
|
+
P as useCommandState
|
|
510
511
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react"),S=require("../../providers/config-provider.cjs"),T=require("../../utils/transform-source/index.cjs"),v=(e,
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react"),S=require("../../providers/config-provider.cjs"),T=require("../../utils/transform-source/index.cjs"),v=(e,s)=>{const{baseSettings:{transformSource:r,organizationDisplayName:o},searchSettings:{tabs:u,searchQueryParamKey:i,shouldOpenLinksInNewTab:g}}=S.useInkeepConfig();return w.useMemo(()=>{const R=u.length>0?u:["All"],n={},y=new Set,d=R.map(t=>typeof t=="string"?t:t[0]);for(const t of d)n[t]=[];for(const t of e){const c=t.url||"";if(y.has(c))continue;y.add(c);const l=i?I(c,s,i):c,a=T.transformInkeepSource({title:t.title,url:l,description:k(t),type:O(t.rootRecord.__typename),tag:D(t),breadcrumbs:t.rootRecord.pathBreadcrumbs??[],contentType:t.rootRecord.contentType},"searchResultItem",{organizationDisplayName:o,tabs:u,transformSource:r}),f={...a,id:t.id,isExternal:a.shouldOpenInNewTab!==void 0?a.shouldOpenInNewTab:g},m=f.tabs||[];for(const b of m){const p=typeof b=="string"?b:b[0];if(!d.includes(p)){console.warn(`Tab "${p}" found in item but not configured in tabs`);continue}n[p].push(f)}d.includes("All")&&n.All.push(f)}for(const t of Object.keys(n)){const c=R.find(a=>typeof a=="string"?a===t:a[0]===t),l=typeof c=="object"?c[1]?.isAlwaysVisible===!0:!1;n[t].length===0&&!l&&delete n[t]}return n},[e,r,o,u,i,g])};function I(e,s,r){try{const o=new URL(e);return o.searchParams.set(r,s),o.toString()}catch{return e}}const k=e=>{switch(e.rootRecord.__typename){case"DocumentationRecord":{const s=h(e.pathHeadings?.at(-1)?.content||""),r=h(e.content?.content||"");return e.preview||r||s}case"GitHubIssueRecord":case"StackOverflowRecord":case"DiscourseRecord":return e.rootRecord.body;default:return e.preview}},D=e=>{switch(e.rootRecord.__typename){case"StackOverflowRecord":return e.rootRecord.markedAsCorrectAnswer?"Resolved":void 0;case"GitHubIssueRecord":return e.rootRecord.state==="CLOSED"?"Closed":void 0}},h=e=>{const s=/(https?:\/\/\S+)/g;return e.replace(s,r=>{const o=r.split("/");return o.length>3?`...${o.slice(-2).join("/")}`:r})},O=e=>{switch(e){case"DocumentationRecord":return"documentation";case"GitHubIssueRecord":return"github_issue";case"DiscourseRecord":return"discourse";case"DiscordRecord":return"discord";case"StackOverflowRecord":return"stackoverflow";case"SlackEntry":return"slack_message";default:return"site"}};exports.useTransformResults=v;
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { useMemo as w } from "react";
|
|
3
3
|
import { useInkeepConfig as S } from "../../providers/config-provider.js";
|
|
4
4
|
import { transformInkeepSource as I } from "../../utils/transform-source/index.js";
|
|
5
|
-
const N = (e,
|
|
5
|
+
const N = (e, s) => {
|
|
6
6
|
const {
|
|
7
|
-
baseSettings: { transformSource: o, organizationDisplayName:
|
|
7
|
+
baseSettings: { transformSource: o, organizationDisplayName: r },
|
|
8
8
|
searchSettings: { tabs: u, searchQueryParamKey: i, shouldOpenLinksInNewTab: g }
|
|
9
9
|
} = S();
|
|
10
10
|
return w(() => {
|
|
@@ -15,7 +15,7 @@ const N = (e, r) => {
|
|
|
15
15
|
const c = t.url || "";
|
|
16
16
|
if (R.has(c)) continue;
|
|
17
17
|
R.add(c);
|
|
18
|
-
const l = i ? T(c,
|
|
18
|
+
const l = i ? T(c, s, i) : c, a = I(
|
|
19
19
|
{
|
|
20
20
|
title: t.title,
|
|
21
21
|
url: l,
|
|
@@ -26,7 +26,7 @@ const N = (e, r) => {
|
|
|
26
26
|
contentType: t.rootRecord.contentType
|
|
27
27
|
},
|
|
28
28
|
"searchResultItem",
|
|
29
|
-
{ organizationDisplayName:
|
|
29
|
+
{ organizationDisplayName: r, tabs: u, transformSource: o }
|
|
30
30
|
), f = {
|
|
31
31
|
...a,
|
|
32
32
|
id: t.id,
|
|
@@ -50,17 +50,16 @@ const N = (e, r) => {
|
|
|
50
50
|
}, [
|
|
51
51
|
e,
|
|
52
52
|
o,
|
|
53
|
-
s,
|
|
54
|
-
u,
|
|
55
53
|
r,
|
|
54
|
+
u,
|
|
56
55
|
i,
|
|
57
56
|
g
|
|
58
57
|
]);
|
|
59
58
|
};
|
|
60
|
-
function T(e,
|
|
59
|
+
function T(e, s, o) {
|
|
61
60
|
try {
|
|
62
|
-
const
|
|
63
|
-
return
|
|
61
|
+
const r = new URL(e);
|
|
62
|
+
return r.searchParams.set(o, s), r.toString();
|
|
64
63
|
} catch {
|
|
65
64
|
return e;
|
|
66
65
|
}
|
|
@@ -68,8 +67,8 @@ function T(e, r, o) {
|
|
|
68
67
|
const k = (e) => {
|
|
69
68
|
switch (e.rootRecord.__typename) {
|
|
70
69
|
case "DocumentationRecord": {
|
|
71
|
-
const
|
|
72
|
-
return e.preview || o ||
|
|
70
|
+
const s = h(e.pathHeadings?.at(-1)?.content || ""), o = h(e.content?.content || "");
|
|
71
|
+
return e.preview || o || s;
|
|
73
72
|
}
|
|
74
73
|
case "GitHubIssueRecord":
|
|
75
74
|
case "StackOverflowRecord":
|
|
@@ -86,10 +85,10 @@ const k = (e) => {
|
|
|
86
85
|
return e.rootRecord.state === "CLOSED" ? "Closed" : void 0;
|
|
87
86
|
}
|
|
88
87
|
}, h = (e) => {
|
|
89
|
-
const
|
|
90
|
-
return e.replace(
|
|
91
|
-
const
|
|
92
|
-
return
|
|
88
|
+
const s = /(https?:\/\/\S+)/g;
|
|
89
|
+
return e.replace(s, (o) => {
|
|
90
|
+
const r = o.split("/");
|
|
91
|
+
return r.length > 3 ? `...${r.slice(-2).join("/")}` : o;
|
|
93
92
|
});
|
|
94
93
|
}, D = (e) => {
|
|
95
94
|
switch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),te=require("../../providers/config-provider.cjs"),se=require("../../hooks/use-media-query.cjs"),re=require("./search-query.graphql.cjs"),ne=require("./transform-results.cjs"),ce=require("../../providers/search-events-provider.cjs"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),te=require("../../providers/config-provider.cjs"),se=require("../../hooks/use-media-query.cjs"),re=require("./search-query.graphql.cjs"),ne=require("./transform-results.cjs"),ce=require("../../providers/search-events-provider.cjs"),ue=require("../../hooks/use-instant-update.cjs"),ae=require("../../utils/graphql-client.cjs"),oe=()=>{const{baseSettings:B,searchSettings:H}=te.useInkeepConfig(),{apiKey:Q,aiApiBaseUrl:$,userAuthToken:h,filters:T}=B,{maxResults:q,placeholder:w,defaultQuery:z,debounceTimeMs:C,onQueryChange:D,searchFunctionsRef:K,tabs:a,filters:k}=H,{logEvent:v}=ce.useSearchEvents(),[n,E]=t.useState(z),M=t.useRef(null),[I,f]=t.useState(!1),[W,d]=t.useState(null),[G,o]=t.useState("NONE"),J=t.useCallback(e=>{o(e)},[]),[y,b]=t.useState([]),s=ne.useTransformResults(y,n),A=a?.length?typeof a[0]=="string"?a[0]:a[0][0]:"All",[m,P]=t.useState(A),{disableTransition:U,disabled:V}=ue.useInstantUpdate(),X=t.useCallback(e=>{U(),P(e);const r=s[e][0]?s[e][0]?.id:void 0;o(r)},[s,U]);t.useEffect(()=>{let e=m in s?m:Object.keys(s)[0];if(!s[e]?.length){const u=Object.keys(s).find(i=>s[i]?.length);u?e=u:e=A}if(!e)return;P(e);const r=s[e]?.[0];r&&o(r.id)},[s]);const g=se.useMediaQuery("(max-width: 768px)"),l=t.useRef({}),S=t.useRef(null),p=t.useRef(null);t.useImperativeHandle(K,()=>({updateQuery(e){E(e)},focusInput:()=>{M.current?.focus()}}));const _=`${$}/graphql`,j=t.useMemo(()=>({Authorization:`Bearer ${Q}`,"Content-Type":"application/json",...h?{"User-Token":h}:{}}),[Q,h]),F=t.useCallback(async e=>{const r=new AbortController;S.current=r;try{d(null);const i=(await ae.graphqlRequest(_,re.default,{searchInput:e},j,r.signal))?.search.searchHits;l.current[e.searchQuery]=i,b(i)}catch(u){if(u.name==="AbortError")return;d("Failed to fetch search results. Please try again.")}finally{f(!1)}},[_,j]),L=t.useCallback(e=>{const r=l.current[e.searchQuery];v({eventName:"search_query_response_received",properties:{searchQuery:e.searchQuery,totalResults:r?.length}})},[]),N=()=>{S.current&&(S.current.abort(),f(!1))},O=t.useCallback(e=>{if(p.current&&window.clearTimeout(p.current),!e.searchQuery){N(),b([]),d(null);return}p.current=window.setTimeout(()=>{N(),v({eventName:"search_query_submitted",properties:{searchQuery:e.searchQuery}}),l.current[e.searchQuery]?(b(l.current[e.searchQuery]),L(e)):(f(!0),F(e).then(()=>{L(e)}))},C)},[C,F]),R=t.useMemo(()=>({searchQuery:n,filters:{...T,...k,limit:q}}),[n,q,T,k]);t.useEffect(()=>{D?.(R.searchQuery),O(R)},[O,R]);const c=t.useRef(null),[Y,x]=t.useState(!1);t.useEffect(()=>(c.current!==null&&window.clearTimeout(c.current),n?c.current=window.setTimeout(()=>{x(!0)},400):x(!1),()=>{c.current!==null&&window.clearTimeout(c.current)}),[n]);const Z=t.useCallback(e=>E(e.target.value),[]),ee=t.useMemo(()=>w||(g?"Search...":"Search for anything..."),[w,g]);return{results:s,resultsList:y,hasContent:Y&&(y.length>0||I),loading:I,error:W,query:n,onInput:Z,placeholder:ee,tab:m,onTabChange:X,selectedItem:G,setSelectedItem:o,onSelectedItemChange:J,transitionsDisabled:V,inputRef:M,isMobile:g}};exports.useInkeepSearch=oe;
|