@alwith/module-chat 0.1.0 → 0.1.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as
|
|
1
|
+
import{jsx as f,jsxs as ne}from"react/jsx-runtime";import{useCallback as re,useEffect as y,useMemo as B,useRef as g,useState as P}from"react";import{NavigationPreview as ie}from"./navigation-preview.js";import"./navigation-rail.css";var se=4,ae=10;function X(v,I){if(v.size!==I.size)return!1;for(let d of v)if(!I.has(d))return!1;return!0}function fe({audio:v,beforeReveal:I,ensureItemMounted:d,items:s,scrollRoot:o,targetTopMarginPx:R=16}){let[U,Z]=P(()=>new Set(s.length===0?[]:[s[s.length-1].id])),[h,b]=P(null),[_,O]=P(null),[z,S]=P(!1),[M,ee]=P(()=>new Set),{installUnlock:H,preload:L,playSequence:G}=v,E=g(null),x=g(null),C=g(!1),w=g(null),N=g(0),k=B(()=>s.map((e)=>e.id).join("\x00"),[s]),V=g(s);V.current=s;let K=g(M),D=g(U),F=g({itemIdsKey:k,scrollRoot:o}),J=F.current;if(J.itemIdsKey!==k||J.scrollRoot!==o)N.current+=1,F.current={itemIdsKey:k,scrollRoot:o};let m=B(()=>d===void 0?s.filter((e)=>M.has(e.id)):s,[d,s,M]),W=B(()=>m.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[m]);y(()=>H(),[H]),y(()=>()=>{N.current+=1},[]),y(()=>{b(null),S(!1),O(null),x.current=null,C.current=!1,w.current=null},[k,o]),y(()=>{L()},[L]),y(()=>{if(o===null)return;let e=new Set,t=new Map,u=()=>{let r=new Set(t.values()),i=V.current.filter((l)=>r.has(l.id)).map((l)=>l.id),n=i.findIndex((l)=>e.has(l));if(n===-1)return;let p=n;for(let l=n+1;l<i.length;l++)if(e.has(i[l]))p=l;let A=new Set(i.slice(n,p+1));if(X(D.current,A))return;D.current=A,Z(A)},c=new IntersectionObserver((r)=>{for(let i of r){let n=t.get(i.target);if(i.isIntersecting)e.add(n);else e.delete(n)}u()},{root:o,rootMargin:`-${R}px 0px 0px 0px`}),T=()=>{let r=new Set,i=new Set;for(let n of V.current){let p=o.querySelector(`[data-content-search-unit-key="${CSS.escape(n.id)}"]`);if(p===null)continue;if(r.add(n.id),i.add(p),t.has(p))continue;t.set(p,n.id),c.observe(p)}for(let n of t.keys()){if(i.has(n))continue;c.unobserve(n),e.delete(t.get(n)),t.delete(n)}if(X(K.current,r))return;K.current=r,ee(r)};T();let a=new MutationObserver(T);return a.observe(o,{childList:!0,subtree:!0}),()=>{a.disconnect(),c.disconnect()}},[k,o,R]);let Y=re(async(e)=>{if(o===null)throw Error("Thread user-message navigation scroll root is missing");let t=N.current+1;if(N.current=t,I(),d!==void 0){await d(e);return}let u=o.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`);if(u===null)throw Error(`Thread user-message navigation target is missing: ${e.id}`);if(N.current!==t)return;u.scrollIntoView({behavior:"instant",block:"start"})},[I,d,o]);if(m.length<se)return null;let q=E.current,te=h===null||q===null||!q.contains(h.button)?0:oe(q,h.button),Q=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),u=E.current;if(t===void 0||t===null||!u.contains(t))return null;let c=t.dataset.threadUserMessageNavigationItemId,T=m.findIndex((a)=>a.id===c);return{button:t,item:m[T],index:T}},j=(e)=>{let t=x.current;if(t===null||t.pointerId!==e.pointerId)return;if(x.current=null,O(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return f("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:f(ie,{open:z,onOpenChange:S,side:"inline-end",sideOffset:0,align:"center",alignOffset:te,trigger:f("div",{ref:E,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":_===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{w.current=null},onPointerDown:(e)=>{if(e.button!==0)return;let t=Q(e.target instanceof Element?e.target:null);if(t===null)return;C.current=!1,x.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),O(t.item.id),b(t),S(!0)},onPointerMove:(e)=>{let t=x.current;if(t===null){let r=Q(e.target instanceof Element?e.target:null);if(r!==null){let i=w.current;if(i!==null&&i!==r.index)G(i,r.index,W);w.current=r.index,b(r)}return}if(t.pointerId!==e.pointerId)return;let u=e.currentTarget.getBoundingClientRect(),c=Math.max(0,Math.min(m.length-1,Math.floor((e.clientY-u.top+e.currentTarget.scrollTop)/ae))),a={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[c],item:m[c],index:c};if(a.item.id===t.itemId)return;G(t.itemIndex,a.index,W),w.current=a.index,x.current={...t,itemId:a.item.id,itemIndex:a.index},C.current=!0,O(a.item.id),b(a),Y(a.item)},onPointerUp:j,onPointerCancel:j,onLostPointerCapture:j,onPointerLeave:()=>{if(w.current=null,x.current===null&&!z)b(null)},children:f("div",{className:"flex flex-col",children:m.map((e,t)=>f("button",{type:"button","data-thread-user-message-navigation-item-id":e.id,"data-scrub-target":_===e.id?"":void 0,"aria-current":U.has(e.id)?"true":void 0,"aria-label":`Jump to user message ${t+1}`,className:"thread-user-message-navigation-row",onClick:(u)=>{if(C.current){C.current=!1;return}let c={button:u.currentTarget,item:e,index:t};b(c),S(!0),Y(e)},onFocus:(u)=>{b({button:u.currentTarget,item:e,index:t}),S(!0)},children:f("span",{className:"flex h-0.5 w-[30px] items-center",children:f("span",{className:"thread-user-message-navigation-marker"})})},e.id))})}),children:h!==null&&ne("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:[f("div",{className:"min-w-0 truncate font-medium",children:h.item.label}),h.item.response.length>0&&f("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:h.item.response})]})})})}function oe(v,I){let d=v.getBoundingClientRect(),s=I.getBoundingClientRect();return s.top+s.height/2-(d.top+d.height/2)}export{fe as ThreadUserMessageNavigationRail};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alwith/module-chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -282,9 +282,14 @@
|
|
|
282
282
|
"prepack": "bun run build"
|
|
283
283
|
},
|
|
284
284
|
"devDependencies": {
|
|
285
|
+
"@happy-dom/global-registrator": "^20.14.3",
|
|
286
|
+
"@testing-library/dom": "^10.4.1",
|
|
287
|
+
"@testing-library/react": "^16.3.3",
|
|
285
288
|
"@types/react": "^19.3.0",
|
|
286
|
-
"
|
|
287
|
-
"
|
|
289
|
+
"@types/react-dom": "^19.3.0",
|
|
290
|
+
"react": "^19.3.0",
|
|
291
|
+
"react-dom": "^19.3.0",
|
|
292
|
+
"typescript": "^7.0.2"
|
|
288
293
|
},
|
|
289
294
|
"dependencies": {
|
|
290
295
|
"entities": "^8.1.0",
|