@inkeep/cxkit-primitives 0.5.44 → 0.5.45
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 +193 -184
- package/dist/components/embedded-chat/use-chat-action.cjs +1 -1
- package/dist/components/embedded-chat/use-chat-action.js +5 -5
- package/dist/providers/base-events-provider.cjs +1 -1
- package/dist/providers/base-events-provider.js +22 -18
- package/dist/providers/chat-events-provider.cjs +1 -1
- package/dist/providers/chat-events-provider.js +46 -55
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),je=require("@radix-ui/react-dialog"),G=require("react"),_e=require("./command-score.cjs"),k=require("@radix-ui/react-primitive"),T=require("@radix-ui/react-id"),Pe=require("../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.cjs"),Ae=require("../../constants/search.cjs"),Me=require("../shadow/context.cjs");function de(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const F=de(je),c=de(G),D='[cmdk-group=""]',ee='[cmdk-group-items=""]',Le='[cmdk-group-heading=""]',fe='[cmdk-item=""]',ae=`${fe}:not([aria-disabled="true"])`,te="cmdk-item-select",M="data-value",me=(t,n,r)=>_e.commandScore(t,n,r??[]),ve=c.createContext(void 0),q=()=>c.useContext(ve),he=c.createContext(void 0),K=()=>c.useContext(he),ge=c.createContext(void 0),re=c.forwardRef((t,n)=>{const r=L(()=>new Set),s=L(()=>new Map),a=L(()=>new Map),f=L(()=>new Set),i=we(t),{label:h,children:d,value:S,onValueChange:E,filter:y,shouldFilter:C,loop:w,disablePointerSelection:A=!1,vimBindings:B=!0,defaultSearch:ne,...$}=t,g=L(()=>({search:ne??"",value:t.value??t.defaultValue??"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),U=T.useId(),z=T.useId(),p=T.useId(),I=c.useRef(null),R=qe();_(()=>{if(S!==void 0){const e=S.trim();g.current.value=e,x.emit()}},[S]),_(()=>{R(6,ce)},[]);const Re=Me.useShadow(),x=c.useMemo(()=>({subscribe:e=>(f.current.add(e),()=>f.current.delete(e)),snapshot:()=>g.current,setState:(e,l,o)=>{if(!Object.is(g.current[e],l)){if(g.current[e]=l,e==="search")Q(),W(),R(1,J);else if(e==="value"&&(Re?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input")||R(1,()=>{j()?.focus()}),R(7,()=>{g.current.selectedItemId=j()?.id,x.emit()}),o||R(5,ce),i.current?.value!==void 0)){const b=l??"";i.current.onValueChange?.(b);return}x.emit()}},emit:()=>{f.current.forEach(e=>e())}}),[]),H=c.useMemo(()=>({value:(e,l,o)=>{l!==a.current.get(e)?.value&&(a.current.set(e,{value:l,keywords:o}),g.current.filtered.items.set(e,oe(l,o)),R(2,()=>{W(),x.emit()}))},item:(e,l)=>(r.current.add(e),l&&(s.current.has(l)?s.current?.get(l)?.add(e):s.current.set(l,new Set([e]))),R(3,()=>{Q(),W(),g.current.value||J(),x.emit()}),()=>{a.current.delete(e),r.current.delete(e),g.current.filtered.items.delete(e);const o=j();R(4,()=>{Q(),o?.getAttribute("id")===e&&J(),x.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{a.current.delete(e),s.current.delete(e)}),filter:()=>!!i.current.shouldFilter,label:h||t["aria-label"]||"",getDisablePointerSelection:()=>!!i.current.disablePointerSelection,listId:U,inputId:p,labelId:z,listInnerRef:I}),[]);function oe(e,l){const o=i.current?.filter??me;return e?o?.(e,g.current.search,l):0}function W(){if(!g.current.search||i.current.shouldFilter===!1)return;const e=g.current.filtered.items,l=[];g.current.filtered.groups.forEach(u=>{const m=s.current.get(u);let b=0;m.forEach(Z=>{const ke=e.get(Z);b=Math.max(ke,b)}),l.push([u,b])});const o=I.current;O().sort((u,m)=>{const b=u.getAttribute("id"),Z=m.getAttribute("id");return(e.get(Z)??0)-(e.get(b)??0)}).forEach(u=>{const m=u.closest(ee);if(m){const b=u.parentElement===m?u:u.closest(`${ee} > *`);b&&m.appendChild(b)}else{const b=u.parentElement===o?u:u.closest(`${ee} > *`);b&&o?.appendChild(b)}}),l.sort((u,m)=>m[1]-u[1]).forEach(u=>{const m=I.current?.querySelector(`${D}[${M}="${encodeURIComponent(u[0])}"]`);m?.parentElement?.appendChild(m)})}function J(){const l=O().find(o=>o.getAttribute("aria-disabled")!=="true"&&o.getAttribute("data-value")!==Ae.ASK_AI_TRIGGER_VALUE)?.getAttribute(M);x.setState("value",l||void 0)}function Q(){if(!g.current.search||i.current.shouldFilter===!1){g.current.filtered.count=r.current.size;return}g.current.filtered.groups=new Set;let e=0;for(const l of r.current){const o=a.current.get(l)?.value??"",u=a.current.get(l)?.keywords??[],m=oe(o,u);g.current.filtered.items.set(l,m),m>0&&e++}for(const[l,o]of s.current)for(const u of o){const m=g.current.filtered.items.get(u);if(m&&m>0){g.current.filtered.groups.add(l);break}}g.current.filtered.count=e}function ce(){const e=j();e&&(e.parentElement?.firstChild===e&&e.closest(D)?.querySelector(Le)?.scrollIntoView({block:"nearest"}),e.scrollIntoView({block:"nearest"}))}function j(){return I.current?.querySelector(`${fe}[aria-selected="true"]`)}function O(){return Array.from(I.current?.querySelectorAll(ae)||[])}function X(e){const o=O()[e];o&&x.setState("value",o.getAttribute(M))}function Y(e){const l=j(),o=O(),u=o.findIndex(b=>b===l);let m=o[u+e];i.current?.loop&&(m=u+e<0?o[o.length-1]:u+e===o.length?o[0]:o[u+e]),m&&x.setState("value",m.getAttribute(M))}function se(e){let o=j()?.closest(D),u;for(;o&&!u;)o=e>0?Te(o,D):Ve(o,D),u=o?.querySelector(ae);u?x.setState("value",u.getAttribute(M)):Y(e)}const ie=()=>X(O().length-1),le=e=>{e.preventDefault(),e.metaKey?ie():e.altKey?se(1):Y(1)},ue=e=>{e.preventDefault(),e.metaKey?X(0):e.altKey?se(-1):Y(-1)};return v.jsxs(k.Primitive.div,{ref:n,tabIndex:-1,...$,"cmdk-root":"",onKeyDown:e=>{if($.onKeyDown?.(e),!e.defaultPrevented)switch(e.key){case"n":case"j":{B&&e.ctrlKey&&le(e);break}case"ArrowDown":{le(e);break}case"p":case"k":{B&&e.ctrlKey&&ue(e);break}case"ArrowUp":{ue(e);break}case"Home":{e.preventDefault(),X(0);break}case"End":{e.preventDefault(),ie();break}case"Enter":if(!e.nativeEvent.isComposing&&e.keyCode!==229){e.preventDefault();const l=j();if(l){const o=new Event(te);l.dispatchEvent(o)}}}},style:{display:"contents"},children:[v.jsx("label",{"cmdk-label":"",htmlFor:H.inputId,id:H.labelId,style:Ge,children:h}),N(t,e=>v.jsx(he.Provider,{value:x,children:v.jsx(ve.Provider,{value:H,children:e})}))]})}),be=c.forwardRef((t,n)=>{const{id:r}=t,s=c.useRef(null),a=c.useContext(ge),f=q(),i=we(t),h=i.current?.forceMount??a?.forceMount;_(()=>{if(!h)return f.item(r,a?.id)},[h]);const d=Ie(r,s,[t.value,t.children,s],t.keywords),S=K(),E=P(p=>p.value&&p.value===d.current),y=P(p=>h||f.filter()===!1?!0:p.search?p.filtered.items.get(r)>0:!0);c.useEffect(()=>{const p=s.current;if(!p||t.disabled)return;const I=()=>w("keyboard");return p.addEventListener(te,I),()=>p.removeEventListener(te,I)},[y,t.onSelect,t.disabled]);const C=G.useCallback(()=>{S.setState("value",d.current,!0)},[S,d]),w=G.useCallback((p="click")=>{C(),i.current.onSelect?.({value:d.current,trigger:p})},[C,i,d]);if(!y)return null;const{disabled:A,value:B,onSelect:ne,forceMount:$,keywords:g,...U}=t,z=G.useMemo(()=>V([s,n]),[s,n]);return v.jsx(k.Primitive.div,{ref:z,...U,id:r,"cmdk-item":"",role:"option","aria-disabled":!!A,"aria-selected":!!E,"data-disabled":!!A,"data-selected":!!E,onPointerMove:A||f.getDisablePointerSelection()?void 0:C,onClick:A?void 0:w,onFocus:A?void 0:C,children:t.children})}),Oe=c.forwardRef((t,n)=>{const{heading:r,children:s,forceMount:a,...f}=t,i=T.useId(),h=c.useRef(null),d=c.useRef(null),S=T.useId(),E=q(),y=P(w=>a||E.filter()===!1?!0:w.search?w.filtered.groups.has(i):!0);_(()=>E.group(i),[]),Ie(i,h,[t.value,t.heading,d]);const C=c.useMemo(()=>({id:i,forceMount:a}),[a]);return v.jsxs(k.Primitive.div,{ref:V([h,n]),...f,"cmdk-group":"",role:"presentation",hidden:y?void 0:!0,children:[r&&v.jsx("div",{ref:d,"cmdk-group-heading":"","aria-hidden":!0,id:S,children:r}),N(t,w=>v.jsx("div",{"cmdk-group-items":"",role:"group","aria-labelledby":r?S:void 0,children:v.jsx(ge.Provider,{value:C,children:w})}))]})}),pe=c.forwardRef((t,n)=>{const{alwaysRender:r,...s}=t,a=c.useRef(null),f=P(i=>!i.search);return!r&&!f?null:v.jsx(k.Primitive.div,{ref:V([a,n]),...s,"cmdk-separator":"",role:"separator"})}),Se=c.forwardRef((t,n)=>{const{onValueChange:r,...s}=t,a=t.value!=null,f=K(),i=P(d=>d.search),h=q();return c.useEffect(()=>{t.value!=null&&f.setState("search",t.value)},[t.value]),v.jsx(k.Primitive.input,{ref:n,...s,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":h.listId,"aria-labelledby":h.labelId,id:h.inputId,type:"text",value:a?t.value:i,onChange:d=>{a||f.setState("search",d.target.value),r?.(d.target.value)}})}),xe=c.forwardRef((t,n)=>{const{children:r,label:s="Suggestions",...a}=t,f=c.useRef(null),i=c.useRef(null),h=q();return c.useEffect(()=>{if(i.current&&f.current){const d=i.current,S=f.current;let E;const y=new ResizeObserver(()=>{E=requestAnimationFrame(()=>{const C=d.offsetHeight;S.style.setProperty("--cmdk-list-height",C.toFixed(1)+"px")})});return y.observe(d),()=>{cancelAnimationFrame(E),y.unobserve(d)}}},[]),v.jsx(k.Primitive.div,{ref:V([f,n]),...a,"cmdk-list":"",tabIndex:-1,"aria-label":s,id:h.listId,children:N(t,d=>v.jsx("div",{ref:V([i,h.listInnerRef]),"cmdk-list-sizer":"",children:d}))})}),Ee=c.forwardRef((t,n)=>{const{open:r,onOpenChange:s,overlayClassName:a,contentClassName:f,container:i,...h}=t;return v.jsx(F.Root,{open:r,onOpenChange:s,children:v.jsxs(F.Portal,{container:i,children:[v.jsx(F.Overlay,{"cmdk-overlay":"",className:a}),v.jsx(F.Content,{"aria-label":t.label,"cmdk-dialog":"",className:f,children:v.jsx(re,{ref:n,...h})})]})})}),Ce=c.forwardRef((t,n)=>P(s=>s.filtered.count===0)?v.jsx(k.Primitive.div,{ref:n,...t,"cmdk-empty":"",role:"presentation"}):null),ye=c.forwardRef((t,n)=>{const{progress:r,children:s,label:a="Loading...",...f}=t;return v.jsx(k.Primitive.div,{ref:n,...f,"cmdk-loading":"",role:"progressbar","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":100,"aria-label":a,children:N(t,i=>v.jsx("div",{"aria-hidden":!0,children:i}))})}),De=Object.assign(re,{List:xe,Item:be,Input:Se,Group:Oe,Separator:pe,Dialog:Ee,Empty:Ce,Loading:ye});function Te(t,n){let r=t.nextElementSibling;for(;r;){if(r.matches(n))return r;r=r.nextElementSibling}}function Ve(t,n){let r=t.previousElementSibling;for(;r;){if(r.matches(n))return r;r=r.previousElementSibling}}function we(t){const n=c.useRef(t);return _(()=>{n.current=t}),n}const _=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 V(t){return n=>{t.forEach(r=>{typeof r=="function"?r(n):r!=null&&(r.current=n)})}}function P(t){const n=K(),r=()=>t(n.snapshot());return Pe.shimExports.useSyncExternalStore(n.subscribe,r,r)}function Ie(t,n,r,s=[]){const a=c.useRef(void 0),f=q();return _(()=>{const i=(()=>{for(const d of r){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?d.current.textContent?.trim():a.current}})(),h=s.map(d=>d.trim());f.value(t,i,h),n.current?.setAttribute(M,i),a.current=i}),a}const qe=()=>{const[t,n]=c.useState(),r=L(()=>new Map);return _(()=>{r.current.forEach(s=>s()),r.current=new Map},[t]),(s,a)=>{r.current.set(s,a),n({})}};function Fe(t){const n=t.type;return typeof n=="function"?n(t.props):"render"in n?n.render(t.props):t}function N({asChild:t,children:n},r){return t&&c.isValidElement(n)?c.cloneElement(Fe(n),{ref:n.ref},r(n.props.children)):r(n)}const Ge={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};exports.Command=De;exports.CommandDialog=Ee;exports.CommandEmpty=Ce;exports.CommandInput=Se;exports.CommandItem=be;exports.CommandList=xe;exports.CommandLoading=ye;exports.CommandRoot=re;exports.CommandSeparator=pe;exports.defaultFilter=me;exports.useCommandState=P;exports.useCommandStore=K;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),je=require("@radix-ui/react-dialog"),G=require("react"),_e=require("./command-score.cjs"),I=require("@radix-ui/react-primitive"),D=require("@radix-ui/react-id"),Pe=require("../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.cjs"),Ae=require("../../constants/search.cjs"),Me=require("../../utils/compose-event-handlers.cjs"),Le=require("../shadow/context.cjs");function fe(t){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return r.default=t,Object.freeze(r)}const F=fe(je),c=fe(G),O='[cmdk-group=""]',te='[cmdk-group-items=""]',Oe='[cmdk-group-heading=""]',me='[cmdk-item=""]',de=`${me}:not([aria-disabled="true"])`,ne="cmdk-item-select",A="data-value",ve=(t,r,n)=>_e.commandScore(t,r,n??[]),he=c.createContext(void 0),q=()=>c.useContext(he),ge=c.createContext(void 0),K=()=>c.useContext(ge),be=c.createContext(void 0),re=c.forwardRef((t,r)=>{const n=M(()=>new Set),s=M(()=>new Map),a=M(()=>new Map),f=M(()=>new Set),i=Ie(t),{label:h,children:d,value:S,onValueChange:E,filter:y,shouldFilter:C,loop:w,disablePointerSelection:P=!1,vimBindings:B=!0,defaultSearch:oe,...$}=t,g=M(()=>({search:oe??"",value:t.value??t.defaultValue??"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}})),U=D.useId(),H=D.useId(),z=D.useId(),R=c.useRef(null),b=Fe();j(()=>{if(S!==void 0){const e=S.trim();g.current.value=e,x.emit()}},[S]),j(()=>{b(6,se)},[]);const V=Le.useShadow(),x=c.useMemo(()=>({subscribe:e=>(f.current.add(e),()=>f.current.delete(e)),snapshot:()=>g.current,setState:(e,l,o)=>{if(!Object.is(g.current[e],l)){if(g.current[e]=l,e==="search")X(),J(),b(1,Q);else if(e==="value"&&(V?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input")||b(1,()=>{k()?.focus()}),b(7,()=>{g.current.selectedItemId=k()?.id,x.emit()}),o||b(5,se),i.current?.value!==void 0)){const p=l??"";i.current.onValueChange?.(p);return}x.emit()}},emit:()=>{f.current.forEach(e=>e())}}),[]),W=c.useMemo(()=>({value:(e,l,o)=>{l!==a.current.get(e)?.value&&(a.current.set(e,{value:l,keywords:o}),g.current.filtered.items.set(e,ce(l,o)),b(2,()=>{J(),x.emit()}))},item:(e,l)=>(n.current.add(e),l&&(s.current.has(l)?s.current?.get(l)?.add(e):s.current.set(l,new Set([e]))),b(3,()=>{X(),J(),g.current.value||Q(),x.emit()}),()=>{a.current.delete(e),n.current.delete(e),g.current.filtered.items.delete(e);const o=k();b(4,()=>{X(),o?.getAttribute("id")===e&&Q(),x.emit()})}),group:e=>(s.current.has(e)||s.current.set(e,new Set),()=>{a.current.delete(e),s.current.delete(e)}),filter:()=>!!i.current.shouldFilter,label:h||t["aria-label"]||"",getDisablePointerSelection:()=>!!i.current.disablePointerSelection,listId:U,inputId:z,labelId:H,listInnerRef:R}),[]);function ce(e,l){const o=i.current?.filter??ve;return e?o?.(e,g.current.search,l):0}function J(){if(!g.current.search||i.current.shouldFilter===!1)return;const e=g.current.filtered.items,l=[];g.current.filtered.groups.forEach(u=>{const m=s.current.get(u);let p=0;m.forEach(ee=>{const ke=e.get(ee);p=Math.max(ke,p)}),l.push([u,p])});const o=R.current;L().sort((u,m)=>{const p=u.getAttribute("id"),ee=m.getAttribute("id");return(e.get(ee)??0)-(e.get(p)??0)}).forEach(u=>{const m=u.closest(te);if(m){const p=u.parentElement===m?u:u.closest(`${te} > *`);p&&m.appendChild(p)}else{const p=u.parentElement===o?u:u.closest(`${te} > *`);p&&o?.appendChild(p)}}),l.sort((u,m)=>m[1]-u[1]).forEach(u=>{const m=R.current?.querySelector(`${O}[${A}="${encodeURIComponent(u[0])}"]`);m?.parentElement?.appendChild(m)})}function Q(){const l=L().find(o=>o.getAttribute("aria-disabled")!=="true"&&o.getAttribute("data-value")!==Ae.ASK_AI_TRIGGER_VALUE)?.getAttribute(A);x.setState("value",l||void 0)}function X(){if(!g.current.search||i.current.shouldFilter===!1){g.current.filtered.count=n.current.size;return}g.current.filtered.groups=new Set;let e=0;for(const l of n.current){const o=a.current.get(l)?.value??"",u=a.current.get(l)?.keywords??[],m=ce(o,u);g.current.filtered.items.set(l,m),m>0&&e++}for(const[l,o]of s.current)for(const u of o){const m=g.current.filtered.items.get(u);if(m&&m>0){g.current.filtered.groups.add(l);break}}g.current.filtered.count=e}function se(){const e=k();e&&(e.parentElement?.firstChild===e&&e.closest(O)?.querySelector(Oe)?.scrollIntoView({block:"nearest"}),e.scrollIntoView({block:"nearest"}))}function k(){return R.current?.querySelector(`${me}[aria-selected="true"]`)}function L(){return Array.from(R.current?.querySelectorAll(de)||[])}function Y(e){const o=L()[e];o&&x.setState("value",o.getAttribute(A))}function Z(e){const l=k(),o=L(),u=o.findIndex(p=>p===l);let m=o[u+e];i.current?.loop&&(m=u+e<0?o[o.length-1]:u+e===o.length?o[0]:o[u+e]),m&&x.setState("value",m.getAttribute(A))}function ie(e){let o=k()?.closest(O),u;for(;o&&!u;)o=e>0?qe(o,O):Ve(o,O),u=o?.querySelector(de);u?x.setState("value",u.getAttribute(A)):Z(e)}const le=()=>Y(L().length-1),ue=e=>{e.preventDefault(),e.metaKey?le():e.altKey?ie(1):Z(1)},ae=e=>{e.preventDefault(),e.metaKey?Y(0):e.altKey?ie(-1):Z(-1)};return v.jsxs(I.Primitive.div,{ref:r,tabIndex:-1,...$,"cmdk-root":"",onKeyDown:e=>{if($.onKeyDown?.(e),!e.defaultPrevented)switch(e.key){case"n":case"j":{B&&e.ctrlKey&&ue(e);break}case"ArrowDown":{ue(e);break}case"p":case"k":{B&&e.ctrlKey&&ae(e);break}case"ArrowUp":{ae(e);break}case"Home":{e.preventDefault(),Y(0);break}case"End":{e.preventDefault(),le();break}case"Enter":if(!e.nativeEvent.isComposing&&e.keyCode!==229){e.preventDefault();const l=k();if(l){const o=new Event(ne);l.dispatchEvent(o)}}}},style:{display:"contents"},children:[v.jsx("label",{"cmdk-label":"",htmlFor:W.inputId,id:W.labelId,style:Ke,children:h}),N(t,e=>v.jsx(ge.Provider,{value:x,children:v.jsx(he.Provider,{value:W,children:e})}))]})}),pe=c.forwardRef((t,r)=>{const{id:n}=t,s=c.useRef(null),a=c.useContext(be),f=q(),i=Ie(t),h=i.current?.forceMount??a?.forceMount;j(()=>{if(!h)return f.item(n,a?.id)},[h]);const d=Re(n,s,[t.value,t.children,s],t.keywords),S=K(),E=_(b=>b.value&&b.value===d.current),y=_(b=>h||f.filter()===!1?!0:b.search?b.filtered.items.get(n)>0:!0);c.useEffect(()=>{const b=s.current;if(!b||t.disabled)return;const V=()=>w("keyboard");return b.addEventListener(ne,V),()=>b.removeEventListener(ne,V)},[y,t.onSelect,t.disabled]);const C=G.useCallback(()=>{S.setState("value",d.current,!0)},[S,d]),w=G.useCallback((b="click")=>{C(),i.current.onSelect?.({value:d.current,trigger:b})},[C,i,d]);if(!y)return null;const{disabled:P,value:B,onSelect:oe,forceMount:$,keywords:g,onClick:U,...H}=t,z=G.useMemo(()=>T([s,r]),[s,r]),R=Me.composeEventHandlers(U,w);return v.jsx(I.Primitive.div,{ref:z,...H,id:n,"cmdk-item":"",role:"option","aria-disabled":!!P,"aria-selected":!!E,"data-disabled":!!P,"data-selected":!!E,onPointerMove:P||f.getDisablePointerSelection()?void 0:C,onClick:P?void 0:R,onFocus:P?void 0:C,children:t.children})}),De=c.forwardRef((t,r)=>{const{heading:n,children:s,forceMount:a,...f}=t,i=D.useId(),h=c.useRef(null),d=c.useRef(null),S=D.useId(),E=q(),y=_(w=>a||E.filter()===!1?!0:w.search?w.filtered.groups.has(i):!0);j(()=>E.group(i),[]),Re(i,h,[t.value,t.heading,d]);const C=c.useMemo(()=>({id:i,forceMount:a}),[a]);return v.jsxs(I.Primitive.div,{ref:T([h,r]),...f,"cmdk-group":"",role:"presentation",hidden:y?void 0:!0,children:[n&&v.jsx("div",{ref:d,"cmdk-group-heading":"","aria-hidden":!0,id:S,children:n}),N(t,w=>v.jsx("div",{"cmdk-group-items":"",role:"group","aria-labelledby":n?S:void 0,children:v.jsx(be.Provider,{value:C,children:w})}))]})}),Se=c.forwardRef((t,r)=>{const{alwaysRender:n,...s}=t,a=c.useRef(null),f=_(i=>!i.search);return!n&&!f?null:v.jsx(I.Primitive.div,{ref:T([a,r]),...s,"cmdk-separator":"",role:"separator"})}),xe=c.forwardRef((t,r)=>{const{onValueChange:n,...s}=t,a=t.value!=null,f=K(),i=_(d=>d.search),h=q();return c.useEffect(()=>{t.value!=null&&f.setState("search",t.value)},[t.value]),v.jsx(I.Primitive.input,{ref:r,...s,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":h.listId,"aria-labelledby":h.labelId,id:h.inputId,type:"text",value:a?t.value:i,onChange:d=>{a||f.setState("search",d.target.value),n?.(d.target.value)}})}),Ee=c.forwardRef((t,r)=>{const{children:n,label:s="Suggestions",...a}=t,f=c.useRef(null),i=c.useRef(null),h=q();return c.useEffect(()=>{if(i.current&&f.current){const d=i.current,S=f.current;let E;const y=new ResizeObserver(()=>{E=requestAnimationFrame(()=>{const C=d.offsetHeight;S.style.setProperty("--cmdk-list-height",C.toFixed(1)+"px")})});return y.observe(d),()=>{cancelAnimationFrame(E),y.unobserve(d)}}},[]),v.jsx(I.Primitive.div,{ref:T([f,r]),...a,"cmdk-list":"",tabIndex:-1,"aria-label":s,id:h.listId,children:N(t,d=>v.jsx("div",{ref:T([i,h.listInnerRef]),"cmdk-list-sizer":"",children:d}))})}),Ce=c.forwardRef((t,r)=>{const{open:n,onOpenChange:s,overlayClassName:a,contentClassName:f,container:i,...h}=t;return v.jsx(F.Root,{open:n,onOpenChange:s,children:v.jsxs(F.Portal,{container:i,children:[v.jsx(F.Overlay,{"cmdk-overlay":"",className:a}),v.jsx(F.Content,{"aria-label":t.label,"cmdk-dialog":"",className:f,children:v.jsx(re,{ref:r,...h})})]})})}),ye=c.forwardRef((t,r)=>_(s=>s.filtered.count===0)?v.jsx(I.Primitive.div,{ref:r,...t,"cmdk-empty":"",role:"presentation"}):null),we=c.forwardRef((t,r)=>{const{progress:n,children:s,label:a="Loading...",...f}=t;return v.jsx(I.Primitive.div,{ref:r,...f,"cmdk-loading":"",role:"progressbar","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":100,"aria-label":a,children:N(t,i=>v.jsx("div",{"aria-hidden":!0,children:i}))})}),Te=Object.assign(re,{List:Ee,Item:pe,Input:xe,Group:De,Separator:Se,Dialog:Ce,Empty:ye,Loading:we});function qe(t,r){let n=t.nextElementSibling;for(;n;){if(n.matches(r))return n;n=n.nextElementSibling}}function Ve(t,r){let n=t.previousElementSibling;for(;n;){if(n.matches(r))return n;n=n.previousElementSibling}}function Ie(t){const r=c.useRef(t);return j(()=>{r.current=t}),r}const j=typeof window>"u"?c.useEffect:c.useLayoutEffect;function M(t){const r=c.useRef(void 0);return r.current===void 0&&(r.current=t()),r}function T(t){return r=>{t.forEach(n=>{typeof n=="function"?n(r):n!=null&&(n.current=r)})}}function _(t){const r=K(),n=()=>t(r.snapshot());return Pe.shimExports.useSyncExternalStore(r.subscribe,n,n)}function Re(t,r,n,s=[]){const a=c.useRef(void 0),f=q();return j(()=>{const i=(()=>{for(const d of n){if(typeof d=="string")return d.trim();if(typeof d=="object"&&"current"in d)return d.current?d.current.textContent?.trim():a.current}})(),h=s.map(d=>d.trim());f.value(t,i,h),r.current?.setAttribute(A,i),a.current=i}),a}const Fe=()=>{const[t,r]=c.useState(),n=M(()=>new Map);return j(()=>{n.current.forEach(s=>s()),n.current=new Map},[t]),(s,a)=>{n.current.set(s,a),r({})}};function Ge(t){const r=t.type;return typeof r=="function"?r(t.props):"render"in r?r.render(t.props):t}function N({asChild:t,children:r},n){return t&&c.isValidElement(r)?c.cloneElement(Ge(r),{ref:r.ref},n(r.props.children)):n(r)}const Ke={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};exports.Command=Te;exports.CommandDialog=Ce;exports.CommandEmpty=ye;exports.CommandInput=xe;exports.CommandItem=pe;exports.CommandList=Ee;exports.CommandLoading=we;exports.CommandRoot=re;exports.CommandSeparator=Se;exports.defaultFilter=ve;exports.useCommandState=_;exports.useCommandStore=K;
|
package/dist/atoms/cmdk/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as te, jsx as p } from "react/jsx-runtime";
|
|
2
2
|
import * as K from "@radix-ui/react-dialog";
|
|
3
3
|
import * as c from "react";
|
|
4
|
-
import { useCallback as
|
|
4
|
+
import { useCallback as ue, useMemo as Ee } from "react";
|
|
5
5
|
import { commandScore as Ce } from "./command-score.js";
|
|
6
|
-
import { Primitive as
|
|
7
|
-
import { useId as
|
|
6
|
+
import { Primitive as I } from "@radix-ui/react-primitive";
|
|
7
|
+
import { useId as T } from "@radix-ui/react-id";
|
|
8
8
|
import { s as we } from "../../node_modules/.pnpm/use-sync-external-store@1.4.0_react@19.0.0/node_modules/use-sync-external-store/shim/index.js";
|
|
9
9
|
import { ASK_AI_TRIGGER_VALUE as ye } from "../../constants/search.js";
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import { composeEventHandlers as Re } from "../../utils/compose-event-handlers.js";
|
|
11
|
+
import { useShadow as Ie } from "../shadow/context.js";
|
|
12
|
+
const D = '[cmdk-group=""]', Z = '[cmdk-group-items=""]', ke = '[cmdk-group-heading=""]', fe = '[cmdk-item=""]', de = `${fe}:not([aria-disabled="true"])`, ee = "cmdk-item-select", L = "data-value", xe = (t, n, r) => Ce(t, n, r ?? []), me = c.createContext(void 0), O = () => c.useContext(me), ve = c.createContext(void 0), re = () => c.useContext(ve), he = c.createContext(void 0), ge = c.forwardRef((t, n) => {
|
|
13
|
+
const r = M(() => /* @__PURE__ */ new Set()), i = M(() => /* @__PURE__ */ new Map()), u = M(() => /* @__PURE__ */ new Map()), f = M(() => /* @__PURE__ */ new Set()), s = pe(t), {
|
|
13
14
|
label: v,
|
|
14
15
|
children: d,
|
|
15
16
|
value: S,
|
|
@@ -17,13 +18,13 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
17
18
|
filter: y,
|
|
18
19
|
shouldFilter: w,
|
|
19
20
|
loop: R,
|
|
20
|
-
disablePointerSelection:
|
|
21
|
+
disablePointerSelection: _ = !1,
|
|
21
22
|
vimBindings: N = !0,
|
|
22
|
-
defaultSearch:
|
|
23
|
+
defaultSearch: ne,
|
|
23
24
|
...U
|
|
24
|
-
} = t, h =
|
|
25
|
+
} = t, h = M(() => ({
|
|
25
26
|
/** Value of the search query. */
|
|
26
|
-
search:
|
|
27
|
+
search: ne ?? "",
|
|
27
28
|
/** Currently selected item value. */
|
|
28
29
|
value: t.value ?? t.defaultValue ?? "",
|
|
29
30
|
/** Currently selected item id. */
|
|
@@ -36,29 +37,29 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
36
37
|
/** Set of groups with at least one visible item. */
|
|
37
38
|
groups: /* @__PURE__ */ new Set()
|
|
38
39
|
}
|
|
39
|
-
})), $ =
|
|
40
|
-
|
|
40
|
+
})), $ = T(), j = T(), q = T(), k = c.useRef(null), g = Ge();
|
|
41
|
+
A(() => {
|
|
41
42
|
if (S !== void 0) {
|
|
42
43
|
const e = S.trim();
|
|
43
44
|
h.current.value = e, E.emit();
|
|
44
45
|
}
|
|
45
|
-
}, [S]),
|
|
46
|
-
|
|
46
|
+
}, [S]), A(() => {
|
|
47
|
+
g(6, ce);
|
|
47
48
|
}, []);
|
|
48
|
-
const
|
|
49
|
+
const G = Ie(), E = c.useMemo(() => ({
|
|
49
50
|
subscribe: (e) => (f.current.add(e), () => f.current.delete(e)),
|
|
50
51
|
snapshot: () => h.current,
|
|
51
52
|
setState: (e, l, o) => {
|
|
52
53
|
if (!Object.is(h.current[e], l)) {
|
|
53
54
|
if (h.current[e] = l, e === "search")
|
|
54
|
-
|
|
55
|
-
else if (e === "value" && (
|
|
56
|
-
|
|
57
|
-
}),
|
|
58
|
-
h.current.selectedItemId =
|
|
59
|
-
}), o ||
|
|
60
|
-
const
|
|
61
|
-
s.current.onValueChange?.(
|
|
55
|
+
J(), z(), g(1, W);
|
|
56
|
+
else if (e === "value" && (G?.shadowHost?.shadowRoot?.activeElement?.hasAttribute("cmdk-input") || g(1, () => {
|
|
57
|
+
x()?.focus();
|
|
58
|
+
}), g(7, () => {
|
|
59
|
+
h.current.selectedItemId = x()?.id, E.emit();
|
|
60
|
+
}), o || g(5, ce), s.current?.value !== void 0)) {
|
|
61
|
+
const b = l ?? "";
|
|
62
|
+
s.current.onValueChange?.(b);
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
65
|
E.emit();
|
|
@@ -67,22 +68,22 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
67
68
|
emit: () => {
|
|
68
69
|
f.current.forEach((e) => e());
|
|
69
70
|
}
|
|
70
|
-
}), []),
|
|
71
|
+
}), []), H = c.useMemo(
|
|
71
72
|
() => ({
|
|
72
73
|
// Keep id → {value, keywords} mapping up-to-date
|
|
73
74
|
value: (e, l, o) => {
|
|
74
|
-
l !== u.current.get(e)?.value && (u.current.set(e, { value: l, keywords: o }), h.current.filtered.items.set(e,
|
|
75
|
+
l !== u.current.get(e)?.value && (u.current.set(e, { value: l, keywords: o }), h.current.filtered.items.set(e, oe(l, o)), g(2, () => {
|
|
75
76
|
z(), E.emit();
|
|
76
77
|
}));
|
|
77
78
|
},
|
|
78
79
|
// Track item lifecycle (mount, unmount)
|
|
79
|
-
item: (e, l) => (r.current.add(e), l && (i.current.has(l) ? i.current?.get(l)?.add(e) : i.current.set(l, /* @__PURE__ */ new Set([e]))),
|
|
80
|
-
|
|
80
|
+
item: (e, l) => (r.current.add(e), l && (i.current.has(l) ? i.current?.get(l)?.add(e) : i.current.set(l, /* @__PURE__ */ new Set([e]))), g(3, () => {
|
|
81
|
+
J(), z(), h.current.value || W(), E.emit();
|
|
81
82
|
}), () => {
|
|
82
83
|
u.current.delete(e), r.current.delete(e), h.current.filtered.items.delete(e);
|
|
83
|
-
const o =
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
const o = x();
|
|
85
|
+
g(4, () => {
|
|
86
|
+
J(), o?.getAttribute("id") === e && W(), E.emit();
|
|
86
87
|
});
|
|
87
88
|
}),
|
|
88
89
|
// Track group lifecycle (mount, unmount)
|
|
@@ -93,13 +94,13 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
93
94
|
label: v || t["aria-label"] || "",
|
|
94
95
|
getDisablePointerSelection: () => !!s.current.disablePointerSelection,
|
|
95
96
|
listId: $,
|
|
96
|
-
inputId:
|
|
97
|
+
inputId: q,
|
|
97
98
|
labelId: j,
|
|
98
|
-
listInnerRef:
|
|
99
|
+
listInnerRef: k
|
|
99
100
|
}),
|
|
100
101
|
[]
|
|
101
102
|
);
|
|
102
|
-
function
|
|
103
|
+
function oe(e, l) {
|
|
103
104
|
const o = s.current?.filter ?? xe;
|
|
104
105
|
return e ? o?.(e, h.current.search, l) : 0;
|
|
105
106
|
}
|
|
@@ -110,39 +111,39 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
110
111
|
const e = h.current.filtered.items, l = [];
|
|
111
112
|
h.current.filtered.groups.forEach((a) => {
|
|
112
113
|
const m = i.current.get(a);
|
|
113
|
-
let
|
|
114
|
-
m.forEach((
|
|
115
|
-
const Se = e.get(
|
|
116
|
-
|
|
117
|
-
}), l.push([a,
|
|
114
|
+
let b = 0;
|
|
115
|
+
m.forEach((Y) => {
|
|
116
|
+
const Se = e.get(Y);
|
|
117
|
+
b = Math.max(Se, b);
|
|
118
|
+
}), l.push([a, b]);
|
|
118
119
|
});
|
|
119
|
-
const o =
|
|
120
|
-
|
|
121
|
-
const
|
|
122
|
-
return (e.get(
|
|
120
|
+
const o = k.current;
|
|
121
|
+
V().sort((a, m) => {
|
|
122
|
+
const b = a.getAttribute("id"), Y = m.getAttribute("id");
|
|
123
|
+
return (e.get(Y) ?? 0) - (e.get(b) ?? 0);
|
|
123
124
|
}).forEach((a) => {
|
|
124
|
-
const m = a.closest(
|
|
125
|
+
const m = a.closest(Z);
|
|
125
126
|
if (m) {
|
|
126
|
-
const
|
|
127
|
-
|
|
127
|
+
const b = a.parentElement === m ? a : a.closest(`${Z} > *`);
|
|
128
|
+
b && m.appendChild(b);
|
|
128
129
|
} else {
|
|
129
|
-
const
|
|
130
|
-
|
|
130
|
+
const b = a.parentElement === o ? a : a.closest(`${Z} > *`);
|
|
131
|
+
b && o?.appendChild(b);
|
|
131
132
|
}
|
|
132
133
|
}), l.sort((a, m) => m[1] - a[1]).forEach((a) => {
|
|
133
|
-
const m =
|
|
134
|
-
`${
|
|
134
|
+
const m = k.current?.querySelector(
|
|
135
|
+
`${D}[${L}="${encodeURIComponent(a[0])}"]`
|
|
135
136
|
);
|
|
136
137
|
m?.parentElement?.appendChild(m);
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
|
-
function
|
|
140
|
-
const l =
|
|
140
|
+
function W() {
|
|
141
|
+
const l = V().find(
|
|
141
142
|
(o) => o.getAttribute("aria-disabled") !== "true" && o.getAttribute("data-value") !== ye
|
|
142
|
-
)?.getAttribute(
|
|
143
|
+
)?.getAttribute(L);
|
|
143
144
|
E.setState("value", l || void 0);
|
|
144
145
|
}
|
|
145
|
-
function
|
|
146
|
+
function J() {
|
|
146
147
|
if (!h.current.search || // Explicitly false, because true | undefined is the default
|
|
147
148
|
s.current.shouldFilter === !1) {
|
|
148
149
|
h.current.filtered.count = r.current.size;
|
|
@@ -151,7 +152,7 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
151
152
|
h.current.filtered.groups = /* @__PURE__ */ new Set();
|
|
152
153
|
let e = 0;
|
|
153
154
|
for (const l of r.current) {
|
|
154
|
-
const o = u.current.get(l)?.value ?? "", a = u.current.get(l)?.keywords ?? [], m =
|
|
155
|
+
const o = u.current.get(l)?.value ?? "", a = u.current.get(l)?.keywords ?? [], m = oe(o, a);
|
|
155
156
|
h.current.filtered.items.set(l, m), m > 0 && e++;
|
|
156
157
|
}
|
|
157
158
|
for (const [l, o] of i.current)
|
|
@@ -164,38 +165,38 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
164
165
|
}
|
|
165
166
|
h.current.filtered.count = e;
|
|
166
167
|
}
|
|
167
|
-
function
|
|
168
|
-
const e =
|
|
169
|
-
e && (e.parentElement?.firstChild === e && e.closest(
|
|
170
|
-
}
|
|
171
|
-
function A() {
|
|
172
|
-
return I.current?.querySelector(`${de}[aria-selected="true"]`);
|
|
168
|
+
function ce() {
|
|
169
|
+
const e = x();
|
|
170
|
+
e && (e.parentElement?.firstChild === e && e.closest(D)?.querySelector(ke)?.scrollIntoView({ block: "nearest" }), e.scrollIntoView({ block: "nearest" }));
|
|
173
171
|
}
|
|
174
|
-
function
|
|
175
|
-
return
|
|
172
|
+
function x() {
|
|
173
|
+
return k.current?.querySelector(`${fe}[aria-selected="true"]`);
|
|
176
174
|
}
|
|
177
|
-
function
|
|
178
|
-
|
|
179
|
-
o && E.setState("value", o.getAttribute(M));
|
|
175
|
+
function V() {
|
|
176
|
+
return Array.from(k.current?.querySelectorAll(de) || []);
|
|
180
177
|
}
|
|
181
178
|
function Q(e) {
|
|
182
|
-
const
|
|
179
|
+
const o = V()[e];
|
|
180
|
+
o && E.setState("value", o.getAttribute(L));
|
|
181
|
+
}
|
|
182
|
+
function X(e) {
|
|
183
|
+
const l = x(), o = V(), a = o.findIndex((b) => b === l);
|
|
183
184
|
let m = o[a + e];
|
|
184
|
-
s.current?.loop && (m = a + e < 0 ? o[o.length - 1] : a + e === o.length ? o[0] : o[a + e]), m && E.setState("value", m.getAttribute(
|
|
185
|
+
s.current?.loop && (m = a + e < 0 ? o[o.length - 1] : a + e === o.length ? o[0] : o[a + e]), m && E.setState("value", m.getAttribute(L));
|
|
185
186
|
}
|
|
186
|
-
function
|
|
187
|
-
let o =
|
|
187
|
+
function se(e) {
|
|
188
|
+
let o = x()?.closest(D), a;
|
|
188
189
|
for (; o && !a; )
|
|
189
|
-
o = e > 0 ?
|
|
190
|
-
a ? E.setState("value", a.getAttribute(
|
|
190
|
+
o = e > 0 ? Fe(o, D) : Oe(o, D), a = o?.querySelector(de);
|
|
191
|
+
a ? E.setState("value", a.getAttribute(L)) : X(e);
|
|
191
192
|
}
|
|
192
|
-
const
|
|
193
|
-
e.preventDefault(), e.metaKey ?
|
|
194
|
-
},
|
|
195
|
-
e.preventDefault(), e.metaKey ?
|
|
193
|
+
const ie = () => Q(V().length - 1), le = (e) => {
|
|
194
|
+
e.preventDefault(), e.metaKey ? ie() : e.altKey ? se(1) : X(1);
|
|
195
|
+
}, ae = (e) => {
|
|
196
|
+
e.preventDefault(), e.metaKey ? Q(0) : e.altKey ? se(-1) : X(-1);
|
|
196
197
|
};
|
|
197
|
-
return /* @__PURE__ */
|
|
198
|
-
|
|
198
|
+
return /* @__PURE__ */ te(
|
|
199
|
+
I.div,
|
|
199
200
|
{
|
|
200
201
|
ref: n,
|
|
201
202
|
tabIndex: -1,
|
|
@@ -206,36 +207,36 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
206
207
|
switch (e.key) {
|
|
207
208
|
case "n":
|
|
208
209
|
case "j": {
|
|
209
|
-
N && e.ctrlKey &&
|
|
210
|
+
N && e.ctrlKey && le(e);
|
|
210
211
|
break;
|
|
211
212
|
}
|
|
212
213
|
case "ArrowDown": {
|
|
213
|
-
|
|
214
|
+
le(e);
|
|
214
215
|
break;
|
|
215
216
|
}
|
|
216
217
|
case "p":
|
|
217
218
|
case "k": {
|
|
218
|
-
N && e.ctrlKey &&
|
|
219
|
+
N && e.ctrlKey && ae(e);
|
|
219
220
|
break;
|
|
220
221
|
}
|
|
221
222
|
case "ArrowUp": {
|
|
222
|
-
|
|
223
|
+
ae(e);
|
|
223
224
|
break;
|
|
224
225
|
}
|
|
225
226
|
case "Home": {
|
|
226
|
-
e.preventDefault(),
|
|
227
|
+
e.preventDefault(), Q(0);
|
|
227
228
|
break;
|
|
228
229
|
}
|
|
229
230
|
case "End": {
|
|
230
|
-
e.preventDefault(),
|
|
231
|
+
e.preventDefault(), ie();
|
|
231
232
|
break;
|
|
232
233
|
}
|
|
233
234
|
case "Enter":
|
|
234
235
|
if (!e.nativeEvent.isComposing && e.keyCode !== 229) {
|
|
235
236
|
e.preventDefault();
|
|
236
|
-
const l =
|
|
237
|
+
const l = x();
|
|
237
238
|
if (l) {
|
|
238
|
-
const o = new Event(
|
|
239
|
+
const o = new Event(ee);
|
|
239
240
|
l.dispatchEvent(o);
|
|
240
241
|
}
|
|
241
242
|
}
|
|
@@ -245,103 +246,111 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
245
246
|
display: "contents"
|
|
246
247
|
},
|
|
247
248
|
children: [
|
|
248
|
-
/* @__PURE__ */
|
|
249
|
+
/* @__PURE__ */ p(
|
|
249
250
|
"label",
|
|
250
251
|
{
|
|
251
252
|
"cmdk-label": "",
|
|
252
|
-
htmlFor:
|
|
253
|
-
id:
|
|
254
|
-
style:
|
|
253
|
+
htmlFor: H.inputId,
|
|
254
|
+
id: H.labelId,
|
|
255
|
+
style: Be,
|
|
255
256
|
children: v
|
|
256
257
|
}
|
|
257
258
|
),
|
|
258
|
-
B(t, (e) => /* @__PURE__ */
|
|
259
|
+
B(t, (e) => /* @__PURE__ */ p(ve.Provider, { value: E, children: /* @__PURE__ */ p(me.Provider, { value: H, children: e }) }))
|
|
259
260
|
]
|
|
260
261
|
}
|
|
261
262
|
);
|
|
262
|
-
}),
|
|
263
|
-
const { id: r } = t, i = c.useRef(null), u = c.useContext(
|
|
264
|
-
|
|
263
|
+
}), Ae = c.forwardRef((t, n) => {
|
|
264
|
+
const { id: r } = t, i = c.useRef(null), u = c.useContext(he), f = O(), s = pe(t), v = s.current?.forceMount ?? u?.forceMount;
|
|
265
|
+
A(() => {
|
|
265
266
|
if (!v)
|
|
266
267
|
return f.item(r, u?.id);
|
|
267
268
|
}, [v]);
|
|
268
|
-
const d =
|
|
269
|
-
(
|
|
269
|
+
const d = be(r, i, [t.value, t.children, i], t.keywords), S = re(), C = P((g) => g.value && g.value === d.current), y = P(
|
|
270
|
+
(g) => v || f.filter() === !1 ? !0 : g.search ? g.filtered.items.get(r) > 0 : !0
|
|
270
271
|
);
|
|
271
272
|
c.useEffect(() => {
|
|
272
|
-
const
|
|
273
|
-
if (!
|
|
274
|
-
const
|
|
275
|
-
return
|
|
273
|
+
const g = i.current;
|
|
274
|
+
if (!g || t.disabled) return;
|
|
275
|
+
const G = () => R("keyboard");
|
|
276
|
+
return g.addEventListener(ee, G), () => g.removeEventListener(ee, G);
|
|
276
277
|
}, [y, t.onSelect, t.disabled]);
|
|
277
|
-
const w =
|
|
278
|
+
const w = ue(() => {
|
|
278
279
|
S.setState("value", d.current, !0);
|
|
279
|
-
}, [S, d]), R =
|
|
280
|
-
(
|
|
281
|
-
w(), s.current.onSelect?.({ value: d.current, trigger:
|
|
280
|
+
}, [S, d]), R = ue(
|
|
281
|
+
(g = "click") => {
|
|
282
|
+
w(), s.current.onSelect?.({ value: d.current, trigger: g });
|
|
282
283
|
},
|
|
283
284
|
[w, s, d]
|
|
284
285
|
);
|
|
285
286
|
if (!y) return null;
|
|
286
|
-
const {
|
|
287
|
-
|
|
288
|
-
|
|
287
|
+
const {
|
|
288
|
+
disabled: _,
|
|
289
|
+
value: N,
|
|
290
|
+
onSelect: ne,
|
|
291
|
+
forceMount: U,
|
|
292
|
+
keywords: h,
|
|
293
|
+
onClick: $,
|
|
294
|
+
...j
|
|
295
|
+
} = t, q = Ee(() => F([i, n]), [i, n]), k = Re($, R);
|
|
296
|
+
return /* @__PURE__ */ p(
|
|
297
|
+
I.div,
|
|
289
298
|
{
|
|
290
|
-
ref:
|
|
291
|
-
|
|
299
|
+
ref: q,
|
|
300
|
+
...j,
|
|
292
301
|
id: r,
|
|
293
302
|
"cmdk-item": "",
|
|
294
303
|
role: "option",
|
|
295
|
-
"aria-disabled": !!
|
|
304
|
+
"aria-disabled": !!_,
|
|
296
305
|
"aria-selected": !!C,
|
|
297
|
-
"data-disabled": !!
|
|
306
|
+
"data-disabled": !!_,
|
|
298
307
|
"data-selected": !!C,
|
|
299
|
-
onPointerMove:
|
|
300
|
-
onClick:
|
|
301
|
-
onFocus:
|
|
308
|
+
onPointerMove: _ || f.getDisablePointerSelection() ? void 0 : w,
|
|
309
|
+
onClick: _ ? void 0 : k,
|
|
310
|
+
onFocus: _ ? void 0 : w,
|
|
302
311
|
children: t.children
|
|
303
312
|
}
|
|
304
313
|
);
|
|
305
|
-
}),
|
|
306
|
-
const { heading: r, children: i, forceMount: u, ...f } = t, s =
|
|
314
|
+
}), _e = c.forwardRef((t, n) => {
|
|
315
|
+
const { heading: r, children: i, forceMount: u, ...f } = t, s = T(), v = c.useRef(null), d = c.useRef(null), S = T(), C = O(), y = P(
|
|
307
316
|
(R) => u || C.filter() === !1 ? !0 : R.search ? R.filtered.groups.has(s) : !0
|
|
308
317
|
);
|
|
309
|
-
|
|
318
|
+
A(() => C.group(s), []), be(s, v, [t.value, t.heading, d]);
|
|
310
319
|
const w = c.useMemo(() => ({ id: s, forceMount: u }), [u]);
|
|
311
|
-
return /* @__PURE__ */
|
|
312
|
-
|
|
320
|
+
return /* @__PURE__ */ te(
|
|
321
|
+
I.div,
|
|
313
322
|
{
|
|
314
|
-
ref:
|
|
323
|
+
ref: F([v, n]),
|
|
315
324
|
...f,
|
|
316
325
|
"cmdk-group": "",
|
|
317
326
|
role: "presentation",
|
|
318
327
|
hidden: y ? void 0 : !0,
|
|
319
328
|
children: [
|
|
320
|
-
r && /* @__PURE__ */
|
|
329
|
+
r && /* @__PURE__ */ p("div", { ref: d, "cmdk-group-heading": "", "aria-hidden": !0, id: S, children: r }),
|
|
321
330
|
B(t, (R) => (
|
|
322
331
|
// biome-ignore lint/a11y/useSemanticElements: <explanation>
|
|
323
|
-
/* @__PURE__ */
|
|
332
|
+
/* @__PURE__ */ p("div", { "cmdk-group-items": "", role: "group", "aria-labelledby": r ? S : void 0, children: /* @__PURE__ */ p(he.Provider, { value: w, children: R }) })
|
|
324
333
|
))
|
|
325
334
|
]
|
|
326
335
|
}
|
|
327
336
|
);
|
|
328
|
-
}),
|
|
329
|
-
const { alwaysRender: r, ...i } = t, u = c.useRef(null), f =
|
|
330
|
-
return !r && !f ? null : /* @__PURE__ */
|
|
331
|
-
|
|
337
|
+
}), Le = c.forwardRef((t, n) => {
|
|
338
|
+
const { alwaysRender: r, ...i } = t, u = c.useRef(null), f = P((s) => !s.search);
|
|
339
|
+
return !r && !f ? null : /* @__PURE__ */ p(
|
|
340
|
+
I.div,
|
|
332
341
|
{
|
|
333
|
-
ref:
|
|
342
|
+
ref: F([u, n]),
|
|
334
343
|
...i,
|
|
335
344
|
"cmdk-separator": "",
|
|
336
345
|
role: "separator"
|
|
337
346
|
}
|
|
338
347
|
);
|
|
339
|
-
}),
|
|
340
|
-
const { onValueChange: r, ...i } = t, u = t.value != null, f =
|
|
348
|
+
}), Me = c.forwardRef((t, n) => {
|
|
349
|
+
const { onValueChange: r, ...i } = t, u = t.value != null, f = re(), s = P((d) => d.search), v = O();
|
|
341
350
|
return c.useEffect(() => {
|
|
342
351
|
t.value != null && f.setState("search", t.value);
|
|
343
|
-
}, [t.value]), /* @__PURE__ */
|
|
344
|
-
|
|
352
|
+
}, [t.value]), /* @__PURE__ */ p(
|
|
353
|
+
I.input,
|
|
345
354
|
{
|
|
346
355
|
ref: n,
|
|
347
356
|
...i,
|
|
@@ -362,8 +371,8 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
362
371
|
}
|
|
363
372
|
}
|
|
364
373
|
);
|
|
365
|
-
}),
|
|
366
|
-
const { children: r, label: i = "Suggestions", ...u } = t, f = c.useRef(null), s = c.useRef(null), v =
|
|
374
|
+
}), Pe = c.forwardRef((t, n) => {
|
|
375
|
+
const { children: r, label: i = "Suggestions", ...u } = t, f = c.useRef(null), s = c.useRef(null), v = O();
|
|
367
376
|
return c.useEffect(() => {
|
|
368
377
|
if (s.current && f.current) {
|
|
369
378
|
const d = s.current, S = f.current;
|
|
@@ -378,28 +387,28 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
378
387
|
cancelAnimationFrame(C), y.unobserve(d);
|
|
379
388
|
};
|
|
380
389
|
}
|
|
381
|
-
}, []), /* @__PURE__ */
|
|
382
|
-
|
|
390
|
+
}, []), /* @__PURE__ */ p(
|
|
391
|
+
I.div,
|
|
383
392
|
{
|
|
384
|
-
ref:
|
|
393
|
+
ref: F([f, n]),
|
|
385
394
|
...u,
|
|
386
395
|
"cmdk-list": "",
|
|
387
396
|
tabIndex: -1,
|
|
388
397
|
"aria-label": i,
|
|
389
398
|
id: v.listId,
|
|
390
|
-
children: B(t, (d) => /* @__PURE__ */
|
|
399
|
+
children: B(t, (d) => /* @__PURE__ */ p("div", { ref: F([s, v.listInnerRef]), "cmdk-list-sizer": "", children: d }))
|
|
391
400
|
}
|
|
392
401
|
);
|
|
393
|
-
}),
|
|
402
|
+
}), Ve = c.forwardRef((t, n) => {
|
|
394
403
|
const { open: r, onOpenChange: i, overlayClassName: u, contentClassName: f, container: s, ...v } = t;
|
|
395
|
-
return /* @__PURE__ */
|
|
396
|
-
/* @__PURE__ */
|
|
397
|
-
/* @__PURE__ */
|
|
404
|
+
return /* @__PURE__ */ p(K.Root, { open: r, onOpenChange: i, children: /* @__PURE__ */ te(K.Portal, { container: s, children: [
|
|
405
|
+
/* @__PURE__ */ p(K.Overlay, { "cmdk-overlay": "", className: u }),
|
|
406
|
+
/* @__PURE__ */ p(K.Content, { "aria-label": t.label, "cmdk-dialog": "", className: f, children: /* @__PURE__ */ p(ge, { ref: n, ...v }) })
|
|
398
407
|
] }) });
|
|
399
|
-
}),
|
|
408
|
+
}), De = c.forwardRef((t, n) => P((i) => i.filtered.count === 0) ? /* @__PURE__ */ p(I.div, { ref: n, ...t, "cmdk-empty": "", role: "presentation" }) : null), Te = c.forwardRef((t, n) => {
|
|
400
409
|
const { progress: r, children: i, label: u = "Loading...", ...f } = t;
|
|
401
|
-
return /* @__PURE__ */
|
|
402
|
-
|
|
410
|
+
return /* @__PURE__ */ p(
|
|
411
|
+
I.div,
|
|
403
412
|
{
|
|
404
413
|
ref: n,
|
|
405
414
|
...f,
|
|
@@ -409,58 +418,58 @@ const T = '[cmdk-group=""]', Y = '[cmdk-group-items=""]', Ie = '[cmdk-group-head
|
|
|
409
418
|
"aria-valuemin": 0,
|
|
410
419
|
"aria-valuemax": 100,
|
|
411
420
|
"aria-label": u,
|
|
412
|
-
children: B(t, (s) => /* @__PURE__ */
|
|
421
|
+
children: B(t, (s) => /* @__PURE__ */ p("div", { "aria-hidden": !0, children: s }))
|
|
413
422
|
}
|
|
414
423
|
);
|
|
415
|
-
}),
|
|
416
|
-
List:
|
|
417
|
-
Item:
|
|
418
|
-
Input:
|
|
419
|
-
Group:
|
|
420
|
-
Separator:
|
|
421
|
-
Dialog:
|
|
422
|
-
Empty:
|
|
423
|
-
Loading:
|
|
424
|
+
}), Qe = Object.assign(ge, {
|
|
425
|
+
List: Pe,
|
|
426
|
+
Item: Ae,
|
|
427
|
+
Input: Me,
|
|
428
|
+
Group: _e,
|
|
429
|
+
Separator: Le,
|
|
430
|
+
Dialog: Ve,
|
|
431
|
+
Empty: De,
|
|
432
|
+
Loading: Te
|
|
424
433
|
});
|
|
425
|
-
function
|
|
434
|
+
function Fe(t, n) {
|
|
426
435
|
let r = t.nextElementSibling;
|
|
427
436
|
for (; r; ) {
|
|
428
437
|
if (r.matches(n)) return r;
|
|
429
438
|
r = r.nextElementSibling;
|
|
430
439
|
}
|
|
431
440
|
}
|
|
432
|
-
function
|
|
441
|
+
function Oe(t, n) {
|
|
433
442
|
let r = t.previousElementSibling;
|
|
434
443
|
for (; r; ) {
|
|
435
444
|
if (r.matches(n)) return r;
|
|
436
445
|
r = r.previousElementSibling;
|
|
437
446
|
}
|
|
438
447
|
}
|
|
439
|
-
function
|
|
448
|
+
function pe(t) {
|
|
440
449
|
const n = c.useRef(t);
|
|
441
|
-
return
|
|
450
|
+
return A(() => {
|
|
442
451
|
n.current = t;
|
|
443
452
|
}), n;
|
|
444
453
|
}
|
|
445
|
-
const
|
|
446
|
-
function
|
|
454
|
+
const A = typeof window > "u" ? c.useEffect : c.useLayoutEffect;
|
|
455
|
+
function M(t) {
|
|
447
456
|
const n = c.useRef(void 0);
|
|
448
457
|
return n.current === void 0 && (n.current = t()), n;
|
|
449
458
|
}
|
|
450
|
-
function
|
|
459
|
+
function F(t) {
|
|
451
460
|
return (n) => {
|
|
452
461
|
t.forEach((r) => {
|
|
453
462
|
typeof r == "function" ? r(n) : r != null && (r.current = n);
|
|
454
463
|
});
|
|
455
464
|
};
|
|
456
465
|
}
|
|
457
|
-
function
|
|
458
|
-
const n =
|
|
466
|
+
function P(t) {
|
|
467
|
+
const n = re(), r = () => t(n.snapshot());
|
|
459
468
|
return we.useSyncExternalStore(n.subscribe, r, r);
|
|
460
469
|
}
|
|
461
|
-
function
|
|
462
|
-
const u = c.useRef(void 0), f =
|
|
463
|
-
return
|
|
470
|
+
function be(t, n, r, i = []) {
|
|
471
|
+
const u = c.useRef(void 0), f = O();
|
|
472
|
+
return A(() => {
|
|
464
473
|
const s = (() => {
|
|
465
474
|
for (const d of r) {
|
|
466
475
|
if (typeof d == "string")
|
|
@@ -469,30 +478,30 @@ function pe(t, n, r, i = []) {
|
|
|
469
478
|
return d.current ? d.current.textContent?.trim() : u.current;
|
|
470
479
|
}
|
|
471
480
|
})(), v = i.map((d) => d.trim());
|
|
472
|
-
f.value(t, s, v), n.current?.setAttribute(
|
|
481
|
+
f.value(t, s, v), n.current?.setAttribute(L, s), u.current = s;
|
|
473
482
|
}), u;
|
|
474
483
|
}
|
|
475
|
-
const
|
|
476
|
-
const [t, n] = c.useState(), r =
|
|
477
|
-
return
|
|
484
|
+
const Ge = () => {
|
|
485
|
+
const [t, n] = c.useState(), r = M(() => /* @__PURE__ */ new Map());
|
|
486
|
+
return A(() => {
|
|
478
487
|
r.current.forEach((i) => i()), r.current = /* @__PURE__ */ new Map();
|
|
479
488
|
}, [t]), (i, u) => {
|
|
480
489
|
r.current.set(i, u), n({});
|
|
481
490
|
};
|
|
482
491
|
};
|
|
483
|
-
function
|
|
492
|
+
function Ke(t) {
|
|
484
493
|
const n = t.type;
|
|
485
494
|
return typeof n == "function" ? n(t.props) : "render" in n ? n.render(t.props) : t;
|
|
486
495
|
}
|
|
487
496
|
function B({ asChild: t, children: n }, r) {
|
|
488
497
|
return t && c.isValidElement(n) ? c.cloneElement(
|
|
489
|
-
|
|
498
|
+
Ke(n),
|
|
490
499
|
{ ref: n.ref },
|
|
491
500
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
492
501
|
r(n.props.children)
|
|
493
502
|
) : r(n);
|
|
494
503
|
}
|
|
495
|
-
const
|
|
504
|
+
const Be = {
|
|
496
505
|
position: "absolute",
|
|
497
506
|
width: "1px",
|
|
498
507
|
height: "1px",
|
|
@@ -504,16 +513,16 @@ const Ke = {
|
|
|
504
513
|
borderWidth: "0"
|
|
505
514
|
};
|
|
506
515
|
export {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
+
Qe as Command,
|
|
517
|
+
Ve as CommandDialog,
|
|
518
|
+
De as CommandEmpty,
|
|
519
|
+
Me as CommandInput,
|
|
520
|
+
Ae as CommandItem,
|
|
521
|
+
Pe as CommandList,
|
|
522
|
+
Te as CommandLoading,
|
|
523
|
+
ge as CommandRoot,
|
|
524
|
+
Le as CommandSeparator,
|
|
516
525
|
xe as defaultFilter,
|
|
517
|
-
|
|
518
|
-
|
|
526
|
+
P as useCommandState,
|
|
527
|
+
re as useCommandStore
|
|
519
528
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../../providers/conversation-provider.cjs"),l=require("../../providers/chat-events-provider.cjs"),a=require("../../providers/chat-form-provider.cjs"),c=require("../modal/modal-provider.cjs"),u=e=>{const{logEvent:n}=l.useChatEvents(),{conversation:o}=i.useInkeepConversation(),{openForm:t}=a.useChatForm(),r=c.useModal();return{handleAction:s=>{e.action.type==="open_form"?(s?.onOpenForm?.(),t?.(e.action.formSettings)):e.action.type==="invoke_callback"&&(e.action.callback({conversation:o}),e.action.shouldCloseModal&&r?.setOpen(!1))},logHelpAction:()=>{"name"in e&&n({eventName:"get_help_option_clicked",properties:{getHelpOption:e,conversation:o}})}}};exports.useChatAction=u;
|
|
@@ -4,13 +4,13 @@ import { useChatEvents as r } from "../../providers/chat-events-provider.js";
|
|
|
4
4
|
import { useChatForm as p } from "../../providers/chat-form-provider.js";
|
|
5
5
|
import { useModal as a } from "../modal/modal-provider.js";
|
|
6
6
|
const v = (o) => {
|
|
7
|
-
const { logEvent: n } = r(), { conversation: e } = l(), { openForm: t } = p(),
|
|
8
|
-
return { handleAction: (
|
|
9
|
-
o.action.type === "open_form" ? (
|
|
7
|
+
const { logEvent: n } = r(), { conversation: e } = l(), { openForm: t } = p(), s = a();
|
|
8
|
+
return { handleAction: (i) => {
|
|
9
|
+
o.action.type === "open_form" ? (i?.onOpenForm?.(), t?.(o.action.formSettings)) : o.action.type === "invoke_callback" && (o.action.callback({
|
|
10
10
|
conversation: e
|
|
11
|
-
}), o.action.shouldCloseModal &&
|
|
11
|
+
}), o.action.shouldCloseModal && s?.setOpen(!1));
|
|
12
12
|
}, logHelpAction: () => {
|
|
13
|
-
|
|
13
|
+
"name" in o && n({
|
|
14
14
|
eventName: "get_help_option_clicked",
|
|
15
15
|
properties: {
|
|
16
16
|
getHelpOption: o,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("react/jsx-runtime"),t=require("react"),y=require("../atoms/api/analytics/events.cjs"),B=require("./config-provider.cjs"),f=require("./user-provider.cjs"),d=t.createContext(void 0),b=({children:e})=>{const{baseSettings:n,componentType:o}=B.useInkeepConfig(),{apiKey:r,analyticsApiBaseUrl:i,tags:c,privacyPreferences:E,env:g}=n,{userProperties:a}=f.useUser(),v=t.useMemo(()=>({widgetLibraryVersion:"0.5.45",componentType:o,tags:c}),[o,c]),u=!E.optOutAllAnalytics&&g!=="development",m={logEvent:t.useCallback(async l=>{const s={...v,...l.properties},p={eventName:l.eventName,properties:s,userProperties:a};if(u){if("conversation"in s&&!s.conversation?.id)return;y.logEvent(p,r,i)}n.onEvent?.(p)},[u,n,r,i,a,v])};return P.jsx(d.Provider,{value:m,children:e})},x=()=>{const e=t.useContext(d);if(!e)throw new Error("useBaseEvents must be used within a BaseEventsProvider");return e};exports.BaseEventsProvider=b;exports.useBaseEvents=x;
|
|
@@ -1,34 +1,38 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useMemo as
|
|
2
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo as g, useCallback as y, createContext as x, useContext as B } from "react";
|
|
4
4
|
import { logEvent as P } from "../atoms/api/analytics/events.js";
|
|
5
5
|
import { useInkeepConfig as C } from "./config-provider.js";
|
|
6
6
|
import { useUser as b } from "./user-provider.js";
|
|
7
|
-
const
|
|
8
|
-
const { baseSettings: t, componentType:
|
|
7
|
+
const u = x(void 0), U = ({ children: e }) => {
|
|
8
|
+
const { baseSettings: t, componentType: n } = C(), { apiKey: s, analyticsApiBaseUrl: r, tags: i, privacyPreferences: l, env: E } = t, { userProperties: a } = b(), c = g(
|
|
9
9
|
() => ({
|
|
10
|
-
widgetLibraryVersion: "0.5.
|
|
11
|
-
componentType:
|
|
12
|
-
tags:
|
|
10
|
+
widgetLibraryVersion: "0.5.45",
|
|
11
|
+
componentType: n,
|
|
12
|
+
tags: i
|
|
13
13
|
}),
|
|
14
|
-
[
|
|
15
|
-
),
|
|
14
|
+
[n, i]
|
|
15
|
+
), v = !l.optOutAllAnalytics && E !== "development", f = { logEvent: y(
|
|
16
16
|
async (p) => {
|
|
17
|
-
const
|
|
18
|
-
...
|
|
17
|
+
const o = {
|
|
18
|
+
...c,
|
|
19
19
|
...p.properties
|
|
20
|
-
},
|
|
20
|
+
}, m = {
|
|
21
21
|
eventName: p.eventName,
|
|
22
|
-
properties:
|
|
23
|
-
userProperties:
|
|
22
|
+
properties: o,
|
|
23
|
+
userProperties: a
|
|
24
24
|
};
|
|
25
|
-
|
|
25
|
+
if (v) {
|
|
26
|
+
if ("conversation" in o && !o.conversation?.id) return;
|
|
27
|
+
P(m, s, r);
|
|
28
|
+
}
|
|
29
|
+
t.onEvent?.(m);
|
|
26
30
|
},
|
|
27
|
-
[
|
|
31
|
+
[v, t, s, r, a, c]
|
|
28
32
|
) };
|
|
29
|
-
return /* @__PURE__ */
|
|
33
|
+
return /* @__PURE__ */ d(u.Provider, { value: f, children: e });
|
|
30
34
|
}, $ = () => {
|
|
31
|
-
const e = B(
|
|
35
|
+
const e = B(u);
|
|
32
36
|
if (!e)
|
|
33
37
|
throw new Error("useBaseEvents must be used within a BaseEventsProvider");
|
|
34
38
|
return e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),n=require("react"),j=require("../atoms/api/analytics/conversation.cjs"),w=require("./config-provider.cjs"),B=require("./conversation-provider.cjs"),k=require("./user-provider.cjs"),f=require("./base-events-provider.cjs"),g=n.createContext(void 0),b=({children:e})=>{const{baseSettings:x}=w.useInkeepConfig(),{apiKey:l,analyticsApiBaseUrl:C,tags:d,privacyPreferences:{optOutAllAnalytics:o},env:i}=x,{userProperties:E}=k.useUser(),{logEvent:h}=f.useBaseEvents(),{conversation:a,setConversation:y}=B.useInkeepConversation(),c=n.useRef(a);n.useEffect(()=>{c.current=a},[a]);const v=n.useCallback(async r=>{const s=c.current;return!o&&i!=="development"?await j.logConversation(s.id,{messages:r,tags:d,userProperties:E},l,C):void 0},[C,l,d,E,o,i]),q={logEvent:n.useCallback(async(r,s)=>{let t=c.current;if(s){const P=await v(s);P?t=P:t=Object.assign({},t,{messages:s}),y(t)}const p={...r,properties:{conversation:t,...r.properties}};h(p)},[h,v,o,i]),logConversation:v};return u.jsx(g.Provider,{value:q,children:e})},A=({children:e})=>u.jsx(f.BaseEventsProvider,{children:u.jsx(b,{children:e})}),O=()=>{const e=n.useContext(g);if(!e)throw new Error("useChatEvents must be used within a ChatEventsProvider");return e};exports.ChatEventsProvider=b;exports.ChatEventsProviderWithBase=A;exports.useChatEvents=O;
|
|
@@ -1,76 +1,67 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useRef as
|
|
2
|
+
import { jsx as v } from "react/jsx-runtime";
|
|
3
|
+
import { useRef as y, useEffect as w, useCallback as m, createContext as b, useContext as B } from "react";
|
|
4
4
|
import { logConversation as k } from "../atoms/api/analytics/conversation.js";
|
|
5
5
|
import { useInkeepConfig as A } from "./config-provider.js";
|
|
6
|
-
import { useInkeepConversation as
|
|
7
|
-
import { useUser as
|
|
8
|
-
import { useBaseEvents as
|
|
9
|
-
const d =
|
|
6
|
+
import { useInkeepConversation as j } from "./conversation-provider.js";
|
|
7
|
+
import { useUser as I } from "./user-provider.js";
|
|
8
|
+
import { useBaseEvents as L, BaseEventsProvider as O } from "./base-events-provider.js";
|
|
9
|
+
const d = b(void 0), U = ({ children: t }) => {
|
|
10
10
|
const { baseSettings: g } = A(), {
|
|
11
|
-
apiKey:
|
|
12
|
-
analyticsApiBaseUrl:
|
|
13
|
-
tags:
|
|
14
|
-
privacyPreferences: { optOutAllAnalytics:
|
|
15
|
-
env:
|
|
16
|
-
} = g, { userProperties:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}, [
|
|
20
|
-
const
|
|
21
|
-
async (
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
e.id,
|
|
11
|
+
apiKey: u,
|
|
12
|
+
analyticsApiBaseUrl: p,
|
|
13
|
+
tags: l,
|
|
14
|
+
privacyPreferences: { optOutAllAnalytics: r },
|
|
15
|
+
env: s
|
|
16
|
+
} = g, { userProperties: C } = I(), { logEvent: f } = L(), { conversation: i, setConversation: P } = j(), a = y(i);
|
|
17
|
+
w(() => {
|
|
18
|
+
a.current = i;
|
|
19
|
+
}, [i]);
|
|
20
|
+
const c = m(
|
|
21
|
+
async (o) => {
|
|
22
|
+
const n = a.current;
|
|
23
|
+
return !r && s !== "development" ? await k(
|
|
24
|
+
n.id,
|
|
26
25
|
{
|
|
27
|
-
messages:
|
|
28
|
-
tags:
|
|
29
|
-
userProperties:
|
|
26
|
+
messages: o,
|
|
27
|
+
tags: l,
|
|
28
|
+
userProperties: C
|
|
30
29
|
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
34
|
-
return n && c(n), n;
|
|
30
|
+
u,
|
|
31
|
+
p
|
|
32
|
+
) : void 0;
|
|
35
33
|
},
|
|
36
|
-
[
|
|
37
|
-
),
|
|
34
|
+
[p, u, l, C, r, s]
|
|
35
|
+
), x = {
|
|
38
36
|
logEvent: m(
|
|
39
|
-
async (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}));
|
|
45
|
-
return;
|
|
37
|
+
async (o, n) => {
|
|
38
|
+
let e = a.current;
|
|
39
|
+
if (n) {
|
|
40
|
+
const h = await c(n);
|
|
41
|
+
h ? e = h : e = Object.assign({}, e, { messages: n }), P(e);
|
|
46
42
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const i = await u(e);
|
|
50
|
-
i && (n = i);
|
|
51
|
-
}
|
|
52
|
-
const y = {
|
|
53
|
-
...s,
|
|
43
|
+
const E = {
|
|
44
|
+
...o,
|
|
54
45
|
properties: {
|
|
55
|
-
conversation:
|
|
56
|
-
...
|
|
46
|
+
conversation: e,
|
|
47
|
+
...o.properties
|
|
57
48
|
}
|
|
58
49
|
};
|
|
59
|
-
|
|
50
|
+
f(E);
|
|
60
51
|
},
|
|
61
|
-
[
|
|
52
|
+
[f, c, r, s]
|
|
62
53
|
),
|
|
63
|
-
logConversation:
|
|
54
|
+
logConversation: c
|
|
64
55
|
};
|
|
65
|
-
return /* @__PURE__ */
|
|
66
|
-
},
|
|
67
|
-
const t =
|
|
56
|
+
return /* @__PURE__ */ v(d.Provider, { value: x, children: t });
|
|
57
|
+
}, F = ({ children: t }) => /* @__PURE__ */ v(O, { children: /* @__PURE__ */ v(U, { children: t }) }), G = () => {
|
|
58
|
+
const t = B(d);
|
|
68
59
|
if (!t)
|
|
69
60
|
throw new Error("useChatEvents must be used within a ChatEventsProvider");
|
|
70
61
|
return t;
|
|
71
62
|
};
|
|
72
63
|
export {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
U as ChatEventsProvider,
|
|
65
|
+
F as ChatEventsProviderWithBase,
|
|
66
|
+
G as useChatEvents
|
|
76
67
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/cxkit-primitives",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.45",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Inkeep, Inc. Customer License (IICL) v1.1",
|
|
6
6
|
"homepage": "",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"remark-gfm": "^4.0.1",
|
|
60
60
|
"unist-util-visit": "^5.0.0",
|
|
61
61
|
"use-sync-external-store": "^1.4.0",
|
|
62
|
-
"@inkeep/cxkit-color-mode": "0.5.
|
|
63
|
-
"@inkeep/cxkit-theme": "0.5.
|
|
64
|
-
"@inkeep/cxkit-types": "0.5.
|
|
62
|
+
"@inkeep/cxkit-color-mode": "0.5.45",
|
|
63
|
+
"@inkeep/cxkit-theme": "0.5.45",
|
|
64
|
+
"@inkeep/cxkit-types": "0.5.45"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@biomejs/biome": "1.9.4",
|