openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 3.53 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$ as t,A as n,B as r,F as i,J as a,K as o,N as s,O as c,R as l,T as u,V as d,et as f,ot as p,x as m,z as h}from"./dist-Bqm7i9hf.js";import{r as g,t as _}from"./chat-file-scroll-CqTm7TBq.js";import{n as v,t as y}from"./code-language-DNKLVSzs.js";import{i as b,n as x,r as S,t as C}from"./dist-CpyheiAI.js";function w(e){let t=e.match(/\r\n|\r|\n/);return t&&t[0]!==`
`?t[0]:void 0}async function T(e){let t=new o,n=new o,f=new o,p=await v(e.name,e.language);if(e.isCurrent&&!e.isCurrent())throw new DOMException(`Editor selection changed`,`AbortError`);let m=null,h=!1,_=e.editable===!0,y=e.wrap===!0,b=e.highlight!==!1,T=w(e.content),O=e.content,k=e=>e.doc.eq(M)?O:e.doc.sliceString(0,e.doc.length,T??`
`),A=o=>a.create({doc:o,extensions:[d(),l(),x(),r.of([...C,...S,{key:`Mod-s`,preventDefault:!0,run:()=>(e.onSave(),!0)}]),f.of(b?u(c):[]),...p?[p]:[],i.contentAttributes.of({"aria-label":e.name,tabindex:`0`}),t.of([a.readOnly.of(!_),i.editable.of(_)]),n.of(y?i.lineWrapping:[]),D,i.updateListener.of(t=>{t.selectionSet&&!t.state.selection.main.empty&&e.onSelectContent?.(),t.docChanged&&m?.(k(t.state))})]}),j=A(e.content),M=j.doc;e.parent.replaceChildren();let N=new i({parent:e.parent,root:document,state:j}),P=e.onScrollPortRef?.(N.scrollDOM),F=g(N.scrollDOM,N.contentDOM,e.scrollFades===!0),I;return{destroy:()=>{h||(h=!0,F.destroy(),P?.(),N.destroy())},setScrollFades:e=>F.setEnabled(e),setContent:e=>{if(h)return;let t=w(e);O=e,M=N.state.toText(e),t===T?N.state.doc.eq(M)||N.dispatch({changes:{from:0,to:N.state.doc.length,insert:e}}):(T=t,N.setState(A(e)))},contentEquals:e=>N.state.toText(e).eq(N.state.doc),setEditable:e=>{h||e===_||(_=e,N.dispatch({effects:t.reconfigure([a.readOnly.of(!e),i.editable.of(e)])}))},setLineWrapping:e=>{h||e===y||(y=e,N.dispatch({effects:n.reconfigure(e?i.lineWrapping:[])}))},setSyntaxHighlighting:e=>{if(h||e===b)return;let t=N.dom.ownerDocument.getSelection(),n=!_&&!N.hasFocus&&t?.anchorNode!=null&&t.focusNode!=null&&N.contentDOM.contains(t.anchorNode)&&N.contentDOM.contains(t.focusNode);if(b=e,N.dispatch({effects:f.reconfigure(e?u(c):[])}),n&&t){let{anchor:e,head:n}=N.state.selection.main,r=N.domAtPos(e),i=N.domAtPos(n);t.setBaseAndExtent(r.node,r.offset,i.node,i.offset)}},setDecorations:({targetLine:e,matches:t=[],currentMatch:n})=>{if(h)return;let r=I;if(r?.document===N.state.doc&&r.targetLine===e&&r.currentMatch===n&&r.matches.length===t.length&&t.every((e,t)=>e===r.matches[t]))return;I={document:N.state.doc,targetLine:e,matches:t,currentMatch:n};let i=new Set(t),a=[...new Set([...t,e,n])].filter(e=>e!=null&&Number.isInteger(e)&&e>=1&&e<=N.state.doc.lines).toSorted((e,t)=>e-t).map(t=>{let r=[];return t===e&&r.push(`file-view__line--target`),i.has(t)&&r.push(`file-view__line--match`),t===n&&r.push(`file-view__line--current`),s.line({class:r.join(` `),...t===e?{attributes:{"data-line":String(t)}}:{}}).range(N.state.doc.line(t).from)});N.dispatch({effects:E.of(s.set(a))})},scrollToLine:(e,t)=>{if(h)return;let n=Math.max(1,Math.min(Math.floor(e),N.state.doc.lines));N.dispatch({effects:i.scrollIntoView(N.state.doc.line(n).from,{y:t?`center`:`nearest`})})},getContent:()=>k(N.state),onDocChanged:e=>{m=e},focus:()=>N.focus()}}var E,D;function O(){return(O=e((()=>{b(),m(),p(),h(),n(),y(),_(),E=t.define(),D=f.define({create:()=>s.none,update:(e,t)=>{for(let e of t.effects)if(e.is(E))return e.value;return e.map(t.changes)},provide:e=>i.decorations.from(e)})})))()}O();export{T as createFileEditorView};