@zhin.js/adapter-sandbox 1.0.59 → 1.0.61

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @zhin.js/adapter-process
2
2
 
3
+ ## 1.0.61
4
+
5
+ ### Patch Changes
6
+
7
+ - zhin.js@1.0.51
8
+ - @zhin.js/console@1.0.50
9
+ - @zhin.js/http@1.0.45
10
+ - @zhin.js/core@1.0.51
11
+
12
+ ## 1.0.60
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [353de3d]
17
+ - @zhin.js/client@1.0.12
18
+ - @zhin.js/console@1.0.49
19
+
3
20
  ## 1.0.59
4
21
 
5
22
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1,7 +1 @@
1
- import{jsx as t,jsxs as i}from"react/jsx-runtime";import{cn as C,addPage as be}from"@zhin.js/client";import{MessageSquare as B,Wifi as Ne,WifiOff as ve,Trash2 as we,Bot as Ce,User as G,Smile as Se,Image as ke,X as Re,Search as ie,Check as Ee,Send as Ae,Info as Ie,Hash as ze,Users as Te,Terminal as $e}from"lucide-react";import ce,{forwardRef as Le,useRef as _,useImperativeHandle as je,useState as f,useEffect as H}from"react";const oe=Le(({placeholder:O="输入消息...",onSend:S,onChange:N,onAtTrigger:x,minHeight:W="44px",maxHeight:K="200px"},h)=>{const m=_(null),g=_(null),v=()=>{if(!m.current)return{text:"",segments:[]};let a="";const r=[],c=Array.from(m.current.childNodes);for(const d of c)if(d.nodeType===Node.TEXT_NODE){const o=d.textContent||"";o&&(a+=o,r.push({type:"text",data:{text:o}}))}else if(d.nodeType===Node.ELEMENT_NODE){const o=d;if(o.classList.contains("editor-face")){const u=o.dataset.id;a+=`[face:${u}]`,r.push({type:"face",data:{id:Number(u)}})}else if(o.classList.contains("editor-image")){const u=o.dataset.url;a+=`[image:${u}]`,r.push({type:"image",data:{url:u}})}else if(o.classList.contains("editor-at")){const u=o.dataset.name,y=o.dataset.id;a+=`[@${u}]`,r.push({type:"at",data:{name:u,qq:y}})}else o.tagName==="BR"&&(a+=`
2
- `)}return{text:a,segments:r}},k=a=>{if(!m.current)return;const r=document.createElement("img");r.src=`https://face.viki.moe/apng/${a}.png`,r.alt=`[face:${a}]`,r.dataset.type="face",r.dataset.id=String(a),r.className="editor-face",E(r),A()},Q=a=>{if(!m.current||!a.trim())return;const r=document.createElement("img");r.src=a.trim(),r.alt=`[image:${a.trim()}]`,r.dataset.type="image",r.dataset.url=a.trim(),r.className="editor-image",E(r),A()},R=(a,r)=>{if(!m.current||!a.trim())return;const c=document.createElement("span");c.dataset.type="at",c.dataset.name=a,r&&(c.dataset.id=r),c.className="editor-at",c.contentEditable="false";const d=document.createElement("span");d.textContent="@",d.className="editor-at-symbol";const o=document.createElement("span");o.textContent=a,o.className="editor-at-name",c.appendChild(d),c.appendChild(o),E(c),A()},E=a=>{if(!m.current)return;m.current.focus();const r=window.getSelection();if(r&&r.rangeCount>0){const c=r.getRangeAt(0);if(m.current.contains(c.commonAncestorContainer))c.deleteContents(),c.insertNode(a),c.collapse(false),r.removeAllRanges(),r.addRange(c);else{m.current.appendChild(a);const o=document.createRange();o.setStartAfter(a),o.collapse(true),r.removeAllRanges(),r.addRange(o)}}else{m.current.appendChild(a);const c=window.getSelection();if(c){const d=document.createRange();d.setStartAfter(a),d.collapse(true),c.removeAllRanges(),c.addRange(d)}}},$=()=>{m.current&&(m.current.innerHTML="",A())},L=()=>{m.current?.focus()},j=()=>v(),D=()=>{if(!m.current||!x)return;const a=window.getSelection();if(!a||a.rangeCount===0){x(false,""),g.current=null;return}const r=a.getRangeAt(0);if(!m.current.contains(r.commonAncestorContainer)){x(false,""),g.current=null;return}const c=r.startContainer;if(c.nodeType!==Node.TEXT_NODE){x(false,""),g.current=null;return}const d=c,o=d.textContent?.substring(0,r.startOffset)||"",u=o.lastIndexOf("@");if(u!==-1){const y=o.substring(u+1);if(y.includes(" ")||y.includes(`
3
- `)){x(false,""),g.current=null;return}g.current=d;const I=document.createRange();I.setStart(d,u),I.setEnd(d,u+1);const U=I.getBoundingClientRect(),b=m.current.getBoundingClientRect();x(true,y,{top:U.bottom-b.top,left:U.left-b.left})}else x(false,""),g.current=null},A=()=>{if(D(),N){const{text:a,segments:r}=v();N(a,r)}},Z=(a,r)=>{if(!g.current)return;const c=g.current,d=c.textContent||"",o=d.lastIndexOf("@");if(o!==-1){const u=d.substring(o+1),y=o+1+u.split(/[\s\n]/)[0].length,I=d.substring(0,o),U=d.substring(y);c.textContent=I+U;const b=window.getSelection();if(b){const M=document.createRange();M.setStart(c,o),M.collapse(true),b.removeAllRanges(),b.addRange(M)}}g.current=null,R(a,r)},F=a=>{if(a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),S)){const{text:r,segments:c}=v();S(r,c)}};return je(h,()=>({focus:L,clear:$,insertFace:k,insertImage:Q,insertAt:R,replaceAtTrigger:Z,getContent:j})),t("div",{ref:m,contentEditable:true,suppressContentEditableWarning:true,onInput:A,onKeyDown:F,"data-placeholder":O,className:"rich-text-editor",style:{width:"100%",minHeight:W,maxHeight:K,padding:"0.5rem 0.75rem",border:"1px solid var(--gray-6)",borderRadius:"6px",backgroundColor:"var(--gray-1)",fontSize:"var(--font-size-2)",outline:"none",overflowY:"auto",lineHeight:"1.5",wordWrap:"break-word",color:"var(--gray-12)"}})});oe.displayName="RichTextEditor";function De(){const[O,S]=f([]),[N,x]=f([{id:"user_1001",name:"测试用户",type:"private",unread:0},{id:"group_2001",name:"测试群组",type:"group",unread:0},{id:"channel_3001",name:"测试频道",type:"channel",unread:0}]),[W,K]=f([]),[h,m]=f(N[0]),[g,v]=f(""),[k,Q]=f("ProcessBot"),[R,E]=f(false),[$,L]=f(false),[j,D]=f(false),[A,Z]=f(false),[F,a]=f(null),[r,c]=f(""),[d,o]=f(""),[u,y]=f(""),[I,U]=f(""),[b]=f([{id:"10001",name:"张三"},{id:"10002",name:"李四"},{id:"10003",name:"王五"},{id:"10004",name:"赵六"},{id:"10005",name:"测试用户"},{id:"10086",name:"Admin"},{id:"10010",name:"Test User"}]),[M,q]=f([]),[X,J]=f(false),ee=_(null),z=_(null),T=_(null),de=async()=>{try{const e=await fetch("https://face.viki.moe/metadata.json");K(await e.json())}catch(e){console.error("[Sandbox] Failed to fetch face list:",e)}};H(()=>{de()},[]),H(()=>{const e=window.location.protocol==="https:"?"wss:":"ws:";return z.current=new WebSocket(`${e}//${window.location.host}/sandbox`),z.current.onopen=()=>E(true),z.current.onmessage=s=>{try{const n=JSON.parse(s.data);let p=typeof n.content=="string"?V(n.content):Array.isArray(n.content)?n.content:V(String(n.content)),l=N.find(P=>P.id===n.id);if(!l){const P=n.type==="private"?`私聊-${n.bot||k}`:n.type==="group"?`群组-${n.id}`:`频道-${n.id}`;l={id:n.id,name:P,type:n.type,unread:0},x(ye=>[...ye,l]),m(l)}const w={id:`bot_${n.timestamp}`,type:"received",channelType:n.type,channelId:n.id,channelName:l.name,senderId:"bot",senderName:n.bot||k,content:p,timestamp:n.timestamp};S(P=>[...P,w])}catch(n){console.error("[Sandbox] Failed to parse message:",n)}},z.current.onclose=()=>E(false),()=>{z.current?.close()}},[k,N]),H(()=>{ee.current?.scrollIntoView({behavior:"smooth"})},[O]),H(()=>{q(g.trim()?V(g):[])},[g]);const V=e=>{const s=[],n=/\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]/g;let p=0,l;for(;(l=n.exec(e))!==null;){if(l.index>p){const w=e.substring(p,l.index);w&&s.push({type:"text",data:{text:w}})}l[1]?s.push({type:"at",data:{qq:l[1],name:l[1]}}):l[2]?s.push({type:"face",data:{id:parseInt(l[2])}}):l[3]&&s.push({type:"image",data:{url:l[3]}}),p=n.lastIndex}if(p<e.length){const w=e.substring(p);w&&s.push({type:"text",data:{text:w}})}return s.length>0?s:[{type:"text",data:{text:e}}]},le=e=>e.map((s,n)=>{if(typeof s=="string")return t("span",{children:s.split(`
4
- `).map((p,l)=>i(ce.Fragment,{children:[p,l<s.split(`
5
- `).length-1&&t("br",{})]},l))},n);switch(s.type){case"text":return t("span",{children:s.data.text.split(`
6
- `).map((p,l)=>i(ce.Fragment,{children:[p,l<s.data.text.split(`
7
- `).length-1&&t("br",{})]},l))},n);case"at":return i("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-accent text-accent-foreground text-xs mx-0.5",children:["@",s.data.name||s.data.qq]},n);case"face":return t("img",{src:`https://face.viki.moe/apng/${s.data.id}.png`,alt:`face${s.data.id}`,className:"w-6 h-6 inline-block align-middle mx-0.5"},n);case"image":return t("img",{src:s.data.url,alt:"image",className:"max-w-[300px] rounded-lg my-1 block",onError:p=>{p.currentTarget.style.display="none"}},n);case"video":return t("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:"📹 视频"},n);case"audio":return t("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:"🎵 语音"},n);case"file":return i("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:["📎 ",s.data.name||"文件"]},n);default:return t("span",{children:"[未知消息类型]"},n)}}),te=(e,s)=>{if(!e.trim()||s.length===0)return;const n={id:`msg_${Date.now()}`,type:"sent",channelType:h.type,channelId:h.id,channelName:h.name,senderId:"test_user",senderName:"测试用户",content:s,timestamp:Date.now()};S(p=>[...p,n]),v(""),q([]),T.current?.clear(),z.current?.send(JSON.stringify({type:h.type,id:h.id,content:s,timestamp:Date.now()}))},me=()=>{confirm("确定清空所有消息记录?")&&S([])},ue=e=>{m(e),x(s=>s.map(n=>n.id===e.id?{...n,unread:0}:n)),window.innerWidth<768&&J(false)},pe=()=>{const e=["private","group","channel"],s=e[Math.floor(Math.random()*e.length)],n=prompt("请输入频道名称:");if(n){const p={id:`${s}_${Date.now()}`,name:n,type:s,unread:0};x(l=>[...l,p]),m(p)}},ne=e=>{switch(e){case"private":return t(G,{size:16});case"group":return t(Te,{size:16});case"channel":return t(ze,{size:16});default:return t(B,{size:16})}},fe=e=>{T.current?.insertFace(e),L(false)},re=()=>{u.trim()&&(T.current?.insertImage(u.trim()),y(""),D(false))},he=e=>{T.current?.replaceAtTrigger(e.name,e.id),a(null),c("")},ge=(e,s,n)=>{if(h.type==="private"){a(null),c("");return}e&&n?(a(n),c(s)):(a(null),c(""))},ae=b.filter(e=>{if(!r.trim())return true;const s=r.toLowerCase();return e.name.toLowerCase().includes(s)||e.id.toLowerCase().includes(s)}),xe=(e,s)=>{v(e),q(s)},se=W.filter(e=>e.name.toLowerCase().includes(d.toLowerCase())||e.describe.toLowerCase().includes(d.toLowerCase())),Y=O.filter(e=>e.channelId===h.id);return i("div",{className:"sandbox-container",children:[i("button",{className:"mobile-channel-toggle md:hidden",onClick:()=>J(!X),children:[t(B,{size:20})," 频道列表"]}),i("div",{className:C("channel-sidebar rounded-lg border bg-card",X&&"show"),children:[t("div",{className:"p-3 border-b",children:i("div",{className:"flex justify-between items-center",children:[i("div",{className:"flex items-center gap-2",children:[t("div",{className:"p-1 rounded-md bg-secondary",children:t(B,{size:16,className:"text-muted-foreground"})}),t("h3",{className:"font-semibold",children:"频道列表"})]}),i("span",{className:C("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border",R?"bg-emerald-100 text-emerald-800 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-muted text-muted-foreground"),children:[R?t(Ne,{size:12}):t(ve,{size:12}),R?"已连接":"未连接"]})]})}),t("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:N.map(e=>{const s=h.id===e.id;return i("div",{className:C("menu-item",s&&"active"),onClick:()=>ue(e),children:[t("span",{className:"shrink-0",children:ne(e.type)}),i("div",{className:"flex-1 min-w-0",children:[t("div",{className:"text-sm font-medium truncate",children:e.name}),t("div",{className:"text-xs text-muted-foreground",children:e.type==="private"?"私聊":e.type==="group"?"群聊":"频道"})]}),e.unread>0&&t("span",{className:"inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1",children:e.unread})]},e.id)})}),t("div",{className:"p-2 border-t",children:t("button",{className:"w-full py-2 px-3 rounded-md border border-dashed text-sm text-muted-foreground hover:bg-accent transition-colors",onClick:pe,children:"+ 添加频道"})})]}),X&&t("div",{className:"channel-overlay md:hidden",onClick:()=>J(false)}),i("div",{className:"chat-area",children:[t("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0",children:i("div",{className:"flex justify-between items-center flex-wrap gap-2",children:[i("div",{className:"flex items-center gap-3",children:[t("div",{className:"p-2 rounded-lg bg-secondary",children:ne(h.type)}),i("div",{children:[t("h2",{className:"text-lg font-bold",children:h.name}),i("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t("span",{children:h.id}),t("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-[10px]",children:Y.length}),t("span",{children:"条消息"})]})]}),t("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-secondary text-secondary-foreground",children:h.type==="private"?"私聊":h.type==="group"?"群聊":"频道"})]}),i("div",{className:"flex items-center gap-2",children:[t("input",{value:k,onChange:e=>Q(e.target.value),placeholder:"机器人名称",className:"h-8 w-28 rounded-md border bg-transparent px-2 text-sm"}),i("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-secondary text-secondary-foreground text-sm hover:bg-secondary/80",onClick:me,children:[t(we,{size:14})," 清空"]})]})]})}),t("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0",children:t("div",{className:"flex-1 overflow-y-auto p-4",children:Y.length===0?i("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[t(B,{size:64,className:"text-muted-foreground/20"}),t("span",{className:"text-muted-foreground",children:"暂无消息,开始对话吧!"})]}):i("div",{className:"space-y-2",children:[Y.map(e=>t("div",{className:C("flex",e.type==="sent"?"justify-end":"justify-start"),children:i("div",{className:C("max-w-[70%] p-3 rounded-2xl",e.type==="sent"?"bg-primary text-primary-foreground":"bg-muted"),children:[i("div",{className:"flex items-center gap-2 mb-1",children:[e.type==="received"&&t(Ce,{size:14}),e.type==="sent"&&t(G,{size:14}),t("span",{className:"text-xs font-medium opacity-90",children:e.senderName}),t("span",{className:"text-xs opacity-70",children:new Date(e.timestamp).toLocaleTimeString()})]}),t("div",{className:"text-sm",children:le(e.content)})]})},e.id)),t("div",{ref:ee})]})})}),i("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0 space-y-3",children:[i("div",{className:"flex gap-2 items-center",children:[t("button",{className:C("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",$?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{L(!$),D(false)},title:"插入表情",children:t(Se,{size:16})}),t("button",{className:C("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",j?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{D(!j),L(false)},title:"插入图片",children:t(ke,{size:16})}),t("div",{className:"flex-1"}),g&&t("button",{className:"h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors",onClick:()=>{v(""),q([])},children:t(Re,{size:16})})]}),$&&i("div",{className:"p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2",children:[t("input",{value:d,onChange:e=>o(e.target.value),placeholder:"搜索表情...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm"}),t("div",{className:"grid grid-cols-8 gap-1",children:se.slice(0,80).map(e=>t("button",{onClick:()=>fe(e.id),title:e.name,className:"w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors",children:t("img",{src:`https://face.viki.moe/apng/${e.id}.png`,alt:e.name,className:"w-8 h-8"})},e.id))}),se.length===0&&i("div",{className:"flex flex-col items-center gap-2 py-4",children:[t(ie,{size:32,className:"text-muted-foreground/30"}),t("span",{className:"text-sm text-muted-foreground",children:"未找到匹配的表情"})]})]}),j&&i("div",{className:"p-3 rounded-md border bg-muted/30 space-y-2",children:[t("input",{value:u,onChange:e=>y(e.target.value),placeholder:"输入图片 URL...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm",onKeyDown:e=>{e.key==="Enter"&&(e.preventDefault(),re())}}),i("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50",onClick:re,disabled:!u.trim(),children:[t(Ee,{size:14})," 插入"]})]}),i("div",{className:"flex gap-2 items-start",children:[i("div",{className:"flex-1 relative",children:[t(oe,{ref:T,placeholder:`向 ${h.name} 发送消息...`,onSend:te,onChange:xe,onAtTrigger:ge,minHeight:"44px",maxHeight:"200px"}),F&&t("div",{className:"absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1",style:{top:`${F.top}px`,left:`${F.left}px`},children:ae.length>0?ae.map(e=>i("div",{className:"flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors",onClick:()=>he(e),children:[t(G,{size:16,className:"text-muted-foreground"}),i("div",{className:"flex-1",children:[t("div",{className:"text-sm font-medium",children:e.name}),i("div",{className:"text-xs text-muted-foreground",children:["ID: ",e.id]})]})]},e.id)):i("div",{className:"flex flex-col items-center gap-2 p-4",children:[t(ie,{size:20,className:"text-muted-foreground/50"}),t("span",{className:"text-xs text-muted-foreground",children:"未找到匹配的用户"})]})})]}),i("button",{className:"inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90",onClick:()=>{const e=T.current?.getContent();e&&te(e.text,e.segments)},disabled:!g.trim()||M.length===0,children:[t(Ae,{size:16})," 发送"]})]}),i("div",{className:"flex items-center gap-2 flex-wrap text-xs text-muted-foreground",children:[t(Ie,{size:12})," 快捷操作:",t("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Enter"})," 发送",t("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Shift+Enter"})," 换行",t("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[@名称]"})," @某人"]})]})]})]})}be({key:"process-sandbox",path:"/sandbox",title:"沙盒",icon:t($e,{className:"w-5 h-5"}),element:t(De,{})});
1
+ import{addPage as e,cn as t}from"@zhin.js/client";import{Bot as n,Check as r,Hash as i,Image as a,Info as o,MessageSquare as s,Search as c,Send as l,Smile as u,Terminal as d,Trash2 as f,User as p,Users as m,Wifi as ee,WifiOff as te,X as h}from"lucide-react";import g,{forwardRef as _,useEffect as v,useImperativeHandle as y,useRef as b,useState as x}from"react";import{jsx as S,jsxs as C}from"react/jsx-runtime";var w=_(({placeholder:e2="输入消息...",onSend:t2,onChange:n2,onAtTrigger:r2,minHeight:i2="44px",maxHeight:a2="200px"},o2)=>{let s2=b(null),c2=b(null),l2=()=>{if(!s2.current)return{text:"",segments:[]};let e3="",t3=[],n3=Array.from(s2.current.childNodes);for(let r3 of n3)if(r3.nodeType===Node.TEXT_NODE){let n4=r3.textContent||"";n4&&(e3+=n4,t3.push({type:"text",data:{text:n4}}))}else if(r3.nodeType===Node.ELEMENT_NODE){let n4=r3;if(n4.classList.contains("editor-face")){let r4=n4.dataset.id;e3+=`[face:${r4}]`,t3.push({type:"face",data:{id:Number(r4)}})}else if(n4.classList.contains("editor-image")){let r4=n4.dataset.url;e3+=`[image:${r4}]`,t3.push({type:"image",data:{url:r4}})}else if(n4.classList.contains("editor-at")){let r4=n4.dataset.name,i3=n4.dataset.id;e3+=`[@${r4}]`,t3.push({type:"at",data:{name:r4,qq:i3}})}else n4.tagName==="BR"&&(e3+="\n")}return{text:e3,segments:t3}},u2=e3=>{if(!s2.current)return;let t3=document.createElement("img");t3.src=`https://face.viki.moe/apng/${e3}.png`,t3.alt=`[face:${e3}]`,t3.dataset.type="face",t3.dataset.id=String(e3),t3.className="editor-face",p2(t3),g2()},d2=e3=>{if(!s2.current||!e3.trim())return;let t3=document.createElement("img");t3.src=e3.trim(),t3.alt=`[image:${e3.trim()}]`,t3.dataset.type="image",t3.dataset.url=e3.trim(),t3.className="editor-image",p2(t3),g2()},f2=(e3,t3)=>{if(!s2.current||!e3.trim())return;let n3=document.createElement("span");n3.dataset.type="at",n3.dataset.name=e3,t3&&(n3.dataset.id=t3),n3.className="editor-at",n3.contentEditable="false";let r3=document.createElement("span");r3.textContent="@",r3.className="editor-at-symbol";let i3=document.createElement("span");i3.textContent=e3,i3.className="editor-at-name",n3.appendChild(r3),n3.appendChild(i3),p2(n3),g2()},p2=e3=>{if(!s2.current)return;s2.current.focus();let t3=window.getSelection();if(t3&&t3.rangeCount>0){let n3=t3.getRangeAt(0);if(s2.current.contains(n3.commonAncestorContainer))n3.deleteContents(),n3.insertNode(e3),n3.collapse(false),t3.removeAllRanges(),t3.addRange(n3);else{s2.current.appendChild(e3);let n4=document.createRange();n4.setStartAfter(e3),n4.collapse(true),t3.removeAllRanges(),t3.addRange(n4)}}else{s2.current.appendChild(e3);let t4=window.getSelection();if(t4){let n3=document.createRange();n3.setStartAfter(e3),n3.collapse(true),t4.removeAllRanges(),t4.addRange(n3)}}},m2=()=>{s2.current&&(s2.current.innerHTML="",g2())},ee2=()=>{s2.current?.focus()},te2=()=>l2(),h2=()=>{if(!s2.current||!r2)return;let e3=window.getSelection();if(!e3||e3.rangeCount===0){r2(false,""),c2.current=null;return}let t3=e3.getRangeAt(0);if(!s2.current.contains(t3.commonAncestorContainer)){r2(false,""),c2.current=null;return}let n3=t3.startContainer;if(n3.nodeType!==Node.TEXT_NODE){r2(false,""),c2.current=null;return}let i3=n3,a3=i3.textContent?.substring(0,t3.startOffset)||"",o3=a3.lastIndexOf("@");if(o3!==-1){let e4=a3.substring(o3+1);if(e4.includes(" ")||e4.includes("\n")){r2(false,""),c2.current=null;return}c2.current=i3;let t4=document.createRange();t4.setStart(i3,o3),t4.setEnd(i3,o3+1);let n4=t4.getBoundingClientRect(),l3=s2.current.getBoundingClientRect();r2(true,e4,{top:n4.bottom-l3.top,left:n4.left-l3.left})}else r2(false,""),c2.current=null},g2=()=>{if(h2(),n2){let{text:e3,segments:t3}=l2();n2(e3,t3)}},_2=(e3,t3)=>{if(!c2.current)return;let n3=c2.current,r3=n3.textContent||"",i3=r3.lastIndexOf("@");if(i3!==-1){let e4=r3.substring(i3+1),t4=i3+1+e4.split(/[\s\n]/)[0].length;n3.textContent=r3.substring(0,i3)+r3.substring(t4);let a3=window.getSelection();if(a3){let e5=document.createRange();e5.setStart(n3,i3),e5.collapse(true),a3.removeAllRanges(),a3.addRange(e5)}}c2.current=null,f2(e3,t3)};return y(o2,()=>({focus:ee2,clear:m2,insertFace:u2,insertImage:d2,insertAt:f2,replaceAtTrigger:_2,getContent:te2})),S("div",{ref:s2,contentEditable:true,suppressContentEditableWarning:true,onInput:g2,onKeyDown:e3=>{if(e3.key==="Enter"&&!e3.shiftKey&&(e3.preventDefault(),t2)){let{text:e4,segments:n3}=l2();t2(e4,n3)}},"data-placeholder":e2,className:"rich-text-editor",style:{width:"100%",minHeight:i2,maxHeight:a2,padding:"0.5rem 0.75rem",border:"1px solid var(--gray-6)",borderRadius:"6px",backgroundColor:"var(--gray-1)",fontSize:"var(--font-size-2)",outline:"none",overflowY:"auto",lineHeight:"1.5",wordWrap:"break-word",color:"var(--gray-12)"}})});w.displayName="RichTextEditor";function T(){let[e2,d2]=x([]),[_2,y2]=x([{id:"user_1001",name:"测试用户",type:"private",unread:0},{id:"group_2001",name:"测试群组",type:"group",unread:0},{id:"channel_3001",name:"测试频道",type:"channel",unread:0}]),[T2,ne]=x([]),[E,D]=x(_2[0]),[O,k]=x(""),[A,re]=x("ProcessBot"),[j,M]=x(false),[N,P]=x(false),[F,I]=x(false),[ie,ae]=x(false),[L,R]=x(null),[z,B]=x(""),[V,oe]=x(""),[H,U]=x(""),[se,ce]=x(""),[le]=x([{id:"10001",name:"张三"},{id:"10002",name:"李四"},{id:"10003",name:"王五"},{id:"10004",name:"赵六"},{id:"10005",name:"测试用户"},{id:"10086",name:"Admin"},{id:"10010",name:"Test User"}]),[ue,W]=x([]),[G,K]=x(false),q=b(null),J=b(null),Y=b(null),de=async()=>{try{ne(await(await fetch("https://face.viki.moe/metadata.json")).json())}catch(e3){console.error("[Sandbox] Failed to fetch face list:",e3)}};v(()=>{de()},[]),v(()=>{let e3=window.location.protocol==="https:"?"wss:":"ws:";return J.current=new WebSocket(`${e3}//${window.location.host}/sandbox`),J.current.onopen=()=>M(true),J.current.onmessage=e4=>{try{let t2=JSON.parse(e4.data),n2=typeof t2.content=="string"?X(t2.content):Array.isArray(t2.content)?t2.content:X(String(t2.content)),r2=_2.find(e5=>e5.id===t2.id);if(!r2){let e5=t2.type==="private"?`私聊-${t2.bot||A}`:t2.type==="group"?`群组-${t2.id}`:`频道-${t2.id}`;r2={id:t2.id,name:e5,type:t2.type,unread:0},y2(e6=>[...e6,r2]),D(r2)}let i2={id:`bot_${t2.timestamp}`,type:"received",channelType:t2.type,channelId:t2.id,channelName:r2.name,senderId:"bot",senderName:t2.bot||A,content:n2,timestamp:t2.timestamp};d2(e5=>[...e5,i2])}catch(e5){console.error("[Sandbox] Failed to parse message:",e5)}},J.current.onclose=()=>M(false),()=>{J.current?.close()}},[A,_2]),v(()=>{q.current?.scrollIntoView({behavior:"smooth"})},[e2]),v(()=>{W(O.trim()?X(O):[])},[O]);let X=e3=>{let t2=[],n2=/\[@([^\]]+)\]|\[face:(\d+)\]|\[image:([^\]]+)\]/g,r2=0,i2;for(;(i2=n2.exec(e3))!==null;){if(i2.index>r2){let n3=e3.substring(r2,i2.index);n3&&t2.push({type:"text",data:{text:n3}})}i2[1]?t2.push({type:"at",data:{qq:i2[1],name:i2[1]}}):i2[2]?t2.push({type:"face",data:{id:parseInt(i2[2])}}):i2[3]&&t2.push({type:"image",data:{url:i2[3]}}),r2=n2.lastIndex}if(r2<e3.length){let n3=e3.substring(r2);n3&&t2.push({type:"text",data:{text:n3}})}return t2.length>0?t2:[{type:"text",data:{text:e3}}]},fe=e3=>e3.map((e4,t2)=>{if(typeof e4=="string")return S("span",{children:e4.split("\n").map((t3,n2)=>C(g.Fragment,{children:[t3,n2<e4.split("\n").length-1&&S("br",{})]},n2))},t2);switch(e4.type){case"text":return S("span",{children:e4.data.text.split("\n").map((t3,n2)=>C(g.Fragment,{children:[t3,n2<e4.data.text.split("\n").length-1&&S("br",{})]},n2))},t2);case"at":return C("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded bg-accent text-accent-foreground text-xs mx-0.5",children:["@",e4.data.name||e4.data.qq]},t2);case"face":return S("img",{src:`https://face.viki.moe/apng/${e4.data.id}.png`,alt:`face${e4.data.id}`,className:"w-6 h-6 inline-block align-middle mx-0.5"},t2);case"image":return S("img",{src:e4.data.url,alt:"image",className:"max-w-[300px] rounded-lg my-1 block",onError:e5=>{e5.currentTarget.style.display="none"}},t2);case"video":return S("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:"📹 视频"},t2);case"audio":return S("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:"🎵 语音"},t2);case"file":return C("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-xs mx-0.5",children:["📎 ",e4.data.name||"文件"]},t2);default:return S("span",{children:"[未知消息类型]"},t2)}}),Z=(e3,t2)=>{if(!e3.trim()||t2.length===0)return;let n2={id:`msg_${Date.now()}`,type:"sent",channelType:E.type,channelId:E.id,channelName:E.name,senderId:"test_user",senderName:"测试用户",content:t2,timestamp:Date.now()};d2(e4=>[...e4,n2]),k(""),W([]),Y.current?.clear(),J.current?.send(JSON.stringify({type:E.type,id:E.id,content:t2,timestamp:Date.now()}))},pe=()=>{confirm("确定清空所有消息记录?")&&d2([])},me=e3=>{D(e3),y2(t2=>t2.map(t3=>t3.id===e3.id?{...t3,unread:0}:t3)),window.innerWidth<768&&K(false)},he=()=>{let e3=["private","group","channel"],t2=e3[Math.floor(Math.random()*e3.length)],n2=prompt("请输入频道名称:");if(n2){let e4={id:`${t2}_${Date.now()}`,name:n2,type:t2,unread:0};y2(t3=>[...t3,e4]),D(e4)}},Q=e3=>{switch(e3){case"private":return S(p,{size:16});case"group":return S(m,{size:16});case"channel":return S(i,{size:16});default:return S(s,{size:16})}},ge=e3=>{Y.current?.insertFace(e3),P(false)},_e=()=>{H.trim()&&(Y.current?.insertImage(H.trim()),U(""),I(false))},ve=e3=>{Y.current?.replaceAtTrigger(e3.name,e3.id),R(null),B("")},ye=(e3,t2,n2)=>{if(E.type==="private"){R(null),B("");return}e3&&n2?(R(n2),B(t2)):(R(null),B(""))},be=le.filter(e3=>{if(!z.trim())return true;let t2=z.toLowerCase();return e3.name.toLowerCase().includes(t2)||e3.id.toLowerCase().includes(t2)}),xe=(e3,t2)=>{k(e3),W(t2)},Se=T2.filter(e3=>e3.name.toLowerCase().includes(V.toLowerCase())||e3.describe.toLowerCase().includes(V.toLowerCase())),$=e2.filter(e3=>e3.channelId===E.id);return C("div",{className:"sandbox-container",children:[C("button",{className:"mobile-channel-toggle md:hidden",onClick:()=>K(!G),children:[S(s,{size:20})," 频道列表"]}),C("div",{className:t("channel-sidebar rounded-lg border bg-card",G&&"show"),children:[S("div",{className:"p-3 border-b",children:C("div",{className:"flex justify-between items-center",children:[C("div",{className:"flex items-center gap-2",children:[S("div",{className:"p-1 rounded-md bg-secondary",children:S(s,{size:16,className:"text-muted-foreground"})}),S("h3",{className:"font-semibold",children:"频道列表"})]}),C("span",{className:t("inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium border",j?"bg-emerald-100 text-emerald-800 border-emerald-200 dark:bg-emerald-900/30 dark:text-emerald-400 dark:border-emerald-800":"bg-muted text-muted-foreground"),children:[S(j?ee:te,{size:12}),j?"已连接":"未连接"]})]})}),S("div",{className:"flex-1 overflow-y-auto p-2 space-y-1",children:_2.map(e3=>C("div",{className:t("menu-item",E.id===e3.id&&"active"),onClick:()=>me(e3),children:[S("span",{className:"shrink-0",children:Q(e3.type)}),C("div",{className:"flex-1 min-w-0",children:[S("div",{className:"text-sm font-medium truncate",children:e3.name}),S("div",{className:"text-xs text-muted-foreground",children:e3.type==="private"?"私聊":e3.type==="group"?"群聊":"频道"})]}),e3.unread>0&&S("span",{className:"inline-flex items-center justify-center h-5 min-w-5 rounded-full bg-destructive text-destructive-foreground text-[10px] font-medium px-1",children:e3.unread})]},e3.id))}),S("div",{className:"p-2 border-t",children:S("button",{className:"w-full py-2 px-3 rounded-md border border-dashed text-sm text-muted-foreground hover:bg-accent transition-colors",onClick:he,children:"+ 添加频道"})})]}),G&&S("div",{className:"channel-overlay md:hidden",onClick:()=>K(false)}),C("div",{className:"chat-area",children:[S("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0",children:C("div",{className:"flex justify-between items-center flex-wrap gap-2",children:[C("div",{className:"flex items-center gap-3",children:[S("div",{className:"p-2 rounded-lg bg-secondary",children:Q(E.type)}),C("div",{children:[S("h2",{className:"text-lg font-bold",children:E.name}),C("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[S("span",{children:E.id}),S("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded border text-[10px]",children:$.length}),S("span",{children:"条消息"})]})]}),S("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-secondary text-secondary-foreground",children:E.type==="private"?"私聊":E.type==="group"?"群聊":"频道"})]}),C("div",{className:"flex items-center gap-2",children:[S("input",{value:A,onChange:e3=>re(e3.target.value),placeholder:"机器人名称",className:"h-8 w-28 rounded-md border bg-transparent px-2 text-sm"}),C("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-secondary text-secondary-foreground text-sm hover:bg-secondary/80",onClick:pe,children:[S(f,{size:14})," 清空"]})]})]})}),S("div",{className:"rounded-lg border bg-card flex-1 flex flex-col min-h-0",children:S("div",{className:"flex-1 overflow-y-auto p-4",children:$.length===0?C("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[S(s,{size:64,className:"text-muted-foreground/20"}),S("span",{className:"text-muted-foreground",children:"暂无消息,开始对话吧!"})]}):C("div",{className:"space-y-2",children:[$.map(e3=>S("div",{className:t("flex",e3.type==="sent"?"justify-end":"justify-start"),children:C("div",{className:t("max-w-[70%] p-3 rounded-2xl",e3.type==="sent"?"bg-primary text-primary-foreground":"bg-muted"),children:[C("div",{className:"flex items-center gap-2 mb-1",children:[e3.type==="received"&&S(n,{size:14}),e3.type==="sent"&&S(p,{size:14}),S("span",{className:"text-xs font-medium opacity-90",children:e3.senderName}),S("span",{className:"text-xs opacity-70",children:new Date(e3.timestamp).toLocaleTimeString()})]}),S("div",{className:"text-sm",children:fe(e3.content)})]})},e3.id)),S("div",{ref:q})]})})}),C("div",{className:"rounded-lg border bg-card p-3 flex-shrink-0 space-y-3",children:[C("div",{className:"flex gap-2 items-center",children:[S("button",{className:t("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",N?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{P(!N),I(false)},title:"插入表情",children:S(u,{size:16})}),S("button",{className:t("h-8 w-8 rounded-md flex items-center justify-center border transition-colors",F?"bg-primary text-primary-foreground":"hover:bg-accent"),onClick:()=>{I(!F),P(false)},title:"插入图片",children:S(a,{size:16})}),S("div",{className:"flex-1"}),O&&S("button",{className:"h-8 w-8 rounded-md flex items-center justify-center hover:bg-accent transition-colors",onClick:()=>{k(""),W([])},children:S(h,{size:16})})]}),N&&C("div",{className:"p-3 rounded-md border bg-muted/30 max-h-64 overflow-y-auto space-y-2",children:[S("input",{value:V,onChange:e3=>oe(e3.target.value),placeholder:"搜索表情...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm"}),S("div",{className:"grid grid-cols-8 gap-1",children:Se.slice(0,80).map(e3=>S("button",{onClick:()=>ge(e3.id),title:e3.name,className:"w-10 h-10 rounded-md border flex items-center justify-center hover:bg-accent transition-colors",children:S("img",{src:`https://face.viki.moe/apng/${e3.id}.png`,alt:e3.name,className:"w-8 h-8"})},e3.id))}),Se.length===0&&C("div",{className:"flex flex-col items-center gap-2 py-4",children:[S(c,{size:32,className:"text-muted-foreground/30"}),S("span",{className:"text-sm text-muted-foreground",children:"未找到匹配的表情"})]})]}),F&&C("div",{className:"p-3 rounded-md border bg-muted/30 space-y-2",children:[S("input",{value:H,onChange:e3=>U(e3.target.value),placeholder:"输入图片 URL...",className:"w-full h-8 rounded-md border bg-transparent px-2 text-sm",onKeyDown:e3=>{e3.key==="Enter"&&(e3.preventDefault(),_e())}}),C("button",{className:"inline-flex items-center gap-1 h-8 px-3 rounded-md bg-primary text-primary-foreground text-sm disabled:opacity-50",onClick:_e,disabled:!H.trim(),children:[S(r,{size:14})," 插入"]})]}),C("div",{className:"flex gap-2 items-start",children:[C("div",{className:"flex-1 relative",children:[S(w,{ref:Y,placeholder:`向 ${E.name} 发送消息...`,onSend:Z,onChange:xe,onAtTrigger:ye,minHeight:"44px",maxHeight:"200px"}),L&&S("div",{className:"absolute z-50 rounded-lg border bg-popover shadow-md min-w-60 max-h-72 overflow-y-auto p-1",style:{top:`${L.top}px`,left:`${L.left}px`},children:be.length>0?be.map(e3=>C("div",{className:"flex items-center gap-2 p-2 rounded-md cursor-pointer hover:bg-accent transition-colors",onClick:()=>ve(e3),children:[S(p,{size:16,className:"text-muted-foreground"}),C("div",{className:"flex-1",children:[S("div",{className:"text-sm font-medium",children:e3.name}),C("div",{className:"text-xs text-muted-foreground",children:["ID: ",e3.id]})]})]},e3.id)):C("div",{className:"flex flex-col items-center gap-2 p-4",children:[S(c,{size:20,className:"text-muted-foreground/50"}),S("span",{className:"text-xs text-muted-foreground",children:"未找到匹配的用户"})]})})]}),C("button",{className:"inline-flex items-center gap-1.5 h-10 px-4 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 transition-colors hover:bg-primary/90",onClick:()=>{let e3=Y.current?.getContent();e3&&Z(e3.text,e3.segments)},disabled:!O.trim()||ue.length===0,children:[S(l,{size:16})," 发送"]})]}),C("div",{className:"flex items-center gap-2 flex-wrap text-xs text-muted-foreground",children:[S(o,{size:12})," 快捷操作:",S("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Enter"})," 发送",S("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"Shift+Enter"})," 换行",S("span",{className:"px-1 py-0.5 rounded border text-[10px]",children:"[@名称]"})," @某人"]})]})]})]})}e({key:"process-sandbox",path:"/sandbox",title:"沙盒",icon:S(d,{className:"w-5 h-5"}),element:S(T,{})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-sandbox",
3
- "version": "1.0.59",
3
+ "version": "1.0.61",
4
4
  "description": "Zhin.js adapter for local testing and development",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -46,14 +46,14 @@
46
46
  "radix-ui": "^1.4.3",
47
47
  "lucide-react": "^0.469.0",
48
48
  "typescript": "^5.3.0",
49
- "zhin.js": "1.0.50"
49
+ "zhin.js": "1.0.51"
50
50
  },
51
51
  "peerDependencies": {
52
- "@zhin.js/core": "1.0.50",
53
- "@zhin.js/client": "1.0.11",
54
- "@zhin.js/http": "1.0.44",
55
- "@zhin.js/console": "1.0.48",
56
- "zhin.js": "1.0.50"
52
+ "@zhin.js/core": "1.0.51",
53
+ "@zhin.js/client": "1.0.12",
54
+ "@zhin.js/console": "1.0.50",
55
+ "zhin.js": "1.0.51",
56
+ "@zhin.js/http": "1.0.45"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@zhin.js/http": {