openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
1 lines • 3.23 kB
JavaScript
import{n as e,r as t}from"./rolldown-runtime-CNOWq4Kh.js";import{Wo as n,li as r,oi as i}from"./_4____________________________.js";import{C_ as a,iP as o,nP as s,rP as c,w_ as l}from"./_2_____________________________.js";import{d as u,f as d,g as f,h as p,j as m,l as h,m as g,n as _,s as v,u as y,x as b}from"./_6____________________.js";import{Ft as x,Lt as S,Rt as C}from"./control-ui-boot-chat-styles-DMRbEm40.js";var w=t({mountChatSelectionPopup:()=>D,positionChatSelectionPopup:()=>E,showChatSelectionToolbar:()=>T});function T(e,t,i,a){let o=t.commonAncestorContainer,s=(o instanceof Element?o:o.parentElement)?.closest(`.chat-bubble`);if(!s||!e.contains(s))return;let c=t.cloneRange();c.selectNodeContents(s),c.setEnd(t.startContainer,t.startOffset);let l=c.toString().length;c.setEnd(t.endContainer,t.endOffset);let v={text:i,start:l,end:c.toString().length,...s.dataset.messageId?{messageId:s.dataset.messageId}:{},...s.dataset.entryId?{entryId:s.dataset.entryId}:{}},y=t.getBoundingClientRect(),b,x=e=>{C(),window.getSelection()?.removeAllRanges(),e()},S=p(()=>m(_,{get mount(){return document.body},get children(){var e=O(),t=e.firstChild,n=t.nextSibling;return e._$$pointerdown=e=>e.preventDefault(),g(()=>e=>{b=e},e),u(e,(()=>{var e=d(()=>!!a.onAddToChat);return()=>e()?(()=>{var e=k();return e._$$click=()=>x(()=>a.onAddToChat?.(v,y)),u(e,()=>r(`chat.messages.addToChat`)),h(()=>r(`chat.messages.addToChat`),t=>{f(e,`aria-label`,t)}),e})():void 0})(),t),t._$$click=()=>x(()=>a.onAskSideChat(v,y)),u(t,()=>r(`chat.messages.askInSideChat`)),n._$$click=()=>x(()=>a.onAskNewSession(v)),u(n,()=>r(`chat.messages.newSessionOption`)),h(()=>({e:r(`chat.messages.selectionActions`),t:r(`chat.messages.askInNewSession`)}),({e:t,t:r},i)=>{t!==i?.e&&f(e,`aria-label`,t),r!==i?.t&&f(n,`aria-label`,r)}),e}}),document.createElement(`div`)),w=D(b,()=>E(b,y),a.paneId,S);n(document,`selectionchange`,()=>{let e=window.getSelection();(!e||e.isCollapsed)&&C()},{signal:w})}function E(e,t){let n=window.visualViewport,r=(n?.offsetLeft??0)+8,i=(n?.offsetTop??0)+8,a=r+(n?.width??window.innerWidth)-16,o=i+(n?.height??window.innerHeight)-16;e.style.maxWidth=`${a-r}px`,e.style.maxHeight=`${o-i}px`;let s=e.getBoundingClientRect(),c=t.left+t.width/2-s.width/2,l=t.top-s.height-8,u=t.bottom+8,d=e.classList.contains(`chat-annotation-editor`)&&u+s.height<=o||l<i?u:l;e.style.left=`${Math.max(r,Math.min(c,a-s.width))}px`,e.style.top=`${Math.max(i,Math.min(d,o-s.height))}px`}function D(e,t,r,i,a,c=()=>!0){let l=S(e,r,i);return t(),n(document,`pointerdown`,t=>{(!(t.target instanceof Node)||!e.contains(t.target))&&C()},{capture:!0,signal:l}),n(document,`keydown`,e=>{o(s.escape,e)&&(e.preventDefault(),e.stopPropagation(),C(),a?.())},{signal:l}),n(document,`scroll`,t=>{(!(t.target instanceof Node)||!e.contains(t.target))&&c()&&C()},{capture:!0,passive:!0,signal:l}),n(window,`resize`,t,{signal:l}),window.visualViewport&&n(window.visualViewport,`resize`,t,{signal:l}),l}var O,k;function A(){return(A=e((()=>{y(),i(),a(),c(),x(),O=b(`<div class=chat-selection-popup role=toolbar><button type=button></button><button type=button>`),k=b(`<button type=button>`),l(),v([`pointerdown`,`click`])})))()}export{E as i,A as n,D as r,w as t};