openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 26.6 kB
JavaScript
import{n as e}from"./rolldown-runtime-CNOWq4Kh.js";import{$ as t,A as n,B as r,C as i,E as a,F as o,G as s,H as c,K as l,L as u,N as d,O as f,P as p,Q as m,R as h,T as ee,U as g,V as _,W as v,Z as y,_ as b,b as x,et as S,g as C,it as te,nt as w,pt as T,q as ne,rt as E,st as D,t as re,tt as ie,x as ae,y as O,z as oe}from"./dist-CKGuiyqz.js";import{r as se,t as ce}from"./chat-file-scroll-BYjNc13x.js";import{n as le,t as ue}from"./code-language-DiXU7oGo.js";function k(e,t){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=e(t,n);return i?(r(n.update(i)),!0):!1}}function A(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}function de(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-G,r),o=e.sliceDoc(i,i+G),s=/\s*$/.exec(a)[0].length,c=/^\s*/.exec(o)[0].length,l=a.length-s;if(a.slice(l-t.length,l)==t&&o.slice(c,c+n.length)==n)return{open:{pos:r-s,margin:s&&1},close:{pos:i+c,margin:c&&1}};let u,d;i-r<=100?u=d=e.sliceDoc(r,i):(u=e.sliceDoc(r,r+G),d=e.sliceDoc(i-G,i));let f=/^\s*/.exec(u)[0].length,p=/\s*$/.exec(d)[0].length,m=d.length-p-n.length;return u.slice(f,f+t.length)==t&&d.slice(m,m+n.length)==n?{open:{pos:r+f+t.length,margin:+!!/\s/.test(u.charAt(f+t.length))},close:{pos:i-p-n.length,margin:+!!/\s/.test(d.charAt(m-1))}}:null}function fe(e){let t=[];for(let n of e.selection.ranges){let r=e.doc.lineAt(n.from),i=n.to<=r.to?r:e.doc.lineAt(n.to);i.from>r.from&&i.from==n.to&&(i=n.to==r.to+1?r:e.doc.lineAt(n.to-1));let a=t.length-1;a>=0&&t[a].to>r.from?t[a].to=i.to:t.push({from:r.from+/^\s*/.exec(r.text)[0].length,to:i.to})}return t}function pe(e,t,n=t.selection.ranges){let r=n.map(e=>A(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>de(t,r[n],e.from,e.to));if(e!=2&&!i.every(e=>e))return{changes:t.changes(n.map((e,t)=>i[t]?[]:[{from:e.from,insert:r[t].open+` `},{from:e.to,insert:` `+r[t].close}]))};if(e!=1&&i.some(e=>e)){let e=[];for(let t=0,n;t<i.length;t++)if(n=i[t]){let i=r[t],{open:a,close:o}=n;e.push({from:a.pos-i.open.length,to:a.pos+a.margin},{from:o.pos-o.margin,to:o.pos+i.close.length})}return{changes:e}}return null}function me(e,t,n=t.selection.ranges){let r=[],i=-1;ranges:for(let{from:e,to:a}of n){let n=r.length,o=1e9,s;for(let n=e;n<=a;){let c=t.doc.lineAt(n);if(s==null&&(s=A(t,c.from).line,!s))continue ranges;if(c.from>i&&(e==a||a>c.from)){i=c.from;let e=/^\s*/.exec(c.text)[0].length,t=e==c.length,n=c.text.slice(e,e+s.length)==s?e:-1;e<c.text.length&&e<o&&(o=e),r.push({line:c,comment:n,token:s,indent:e,empty:t,single:!1})}n=c.to+1}if(o<1e9)for(let e=n;e<r.length;e++)r[e].indent<r[e].line.text.length&&(r[e].indent=o);r.length==n+1&&(r[n].single=!0)}if(e!=2&&r.some(e=>e.comment<0&&(!e.empty||e.single))){let e=[];for(let{line:t,token:n,indent:i,empty:a,single:o}of r)(o||!a)&&e.push({from:t.from+i,insert:n+` `});let n=t.changes(e);return{changes:n,selection:t.selection.map(n,1)}}if(e!=1&&r.some(e=>e.comment>=0)){let e=[];for(let{line:t,comment:n,token:i}of r)if(n>=0){let r=t.from+n,a=r+i.length;t.text[a-t.from]==` `&&a++,e.push({from:r,to:a})}return{changes:e}}return null}function he(e={}){return[Ke,Ge.of(e),o.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?qe:e.inputType==`historyRedo`?q:null;return n?(e.preventDefault(),n(t)):!1}})]}function j(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(Ke,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}function M(e,t,n,r){let i=t+1>n+20?t-n-1:0,a=e.slice(i,t);return a.push(r),a}function ge(e,t){let n=[],r=!1;return e.iterChangedRanges((e,t)=>n.push(e,t)),t.iterChangedRanges((e,t,i,a)=>{for(let e=0;e<n.length;){let t=n[e++],o=n[e++];a>=t&&i<=o&&(r=!0)}}),r}function _e(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function ve(e,t){return e.length?t.length?e.concat(t):e:t}function ye(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Xe));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),M(e,e.length-1,1e9,n.setSelAfter(r)))}return[J.selection([t])]}function be(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function N(e,t){if(!e.length)return e;let n=e.length,r=Y;for(;n;){let i=xe(e[n-1],t,r);if(i.changes&&!i.changes.empty||i.effects.length){let t=e.slice(0,n);return t[n-1]=i,t}t=i.mapped,n--,r=i.selectionsAfter}return r.length?[J.selection(r)]:Y}function xe(e,t,n){let r=ve(e.selectionsAfter.length?e.selectionsAfter.map(e=>e.map(t)):Y,n);if(!e.changes)return J.selection(r);let i=e.changes.map(t),a=t.mapDesc(e.changes,!0),o=e.mapped?e.mapped.composeDesc(a):a;return new J(i,y.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}function P(e,t){return s.create(e.ranges.map(t),e.mainIndex)}function F(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function I({state:e,dispatch:t},n){let r=P(e.selection,n);return!r.eq(e.selection,!0)&&(t(F(e,r)),!0)}function L(e,t){return s.cursor(t?e.to:e.from)}function Se(e,t){return I(e,n=>n.empty?e.moveByChar(n,t):L(n,t))}function R(e){return e.textDirectionAt(e.state.selection.main.head)==p.LTR}function Ce(e,t){return I(e,n=>n.empty?e.moveByGroup(n,t):L(n,t))}function we(e,t,n){if(t.type.prop(n))return!0;let r=t.to-t.from;return r&&(r>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function z(e,t,n){let r=a(e).resolveInner(t.head),o=n?D.closedBy:D.openedBy;for(let i=t.head;;){let t=n?r.childAfter(i):r.childBefore(i);if(!t)break;we(e,t,o)?r=t:i=n?t.to:t.from}let c=r.type.prop(o),l,u;return u=c&&(l=n?i(e,r.from,1):i(e,r.to,-1))&&l.matched?n?l.end.to:l.end.from:n?r.to:r.from,s.cursor(u,n?-1:1)}function Te(e,t){return I(e,n=>{if(!n.empty)return L(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}function Ee(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,r=0,i;if(t){for(let t of e.state.facet(o.scrollMargins)){let i=t(e);i?.top&&(n=Math.max(i?.top,n)),i?.bottom&&(r=Math.max(i?.bottom,r))}i=e.scrollDOM.clientHeight-n-r}else i=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:r,selfScroll:t,height:Math.max(e.defaultLineHeight,i-5)}}function De(e,t){let n=Ee(e),{state:r}=e,i=P(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):L(r,t));if(i.eq(r.selection))return!1;let a;if(n.selfScroll){let t=e.coordsAtPos(r.selection.main.head),s=e.scrollDOM.getBoundingClientRect(),c=s.top+n.marginTop,l=s.bottom-n.marginBottom;t&&t.top>c&&t.bottom<l&&(a=o.scrollIntoView(i.main.head,{y:`start`,yMargin:t.top-c}))}return e.dispatch(F(r,i),{effects:a}),!0}function B(e,t,n){let r=e.lineBlockAt(t.head),i=e.moveToLineBoundary(t,n);if(i.head==t.head&&i.head!=(n?r.to:r.from)&&(i=e.moveToLineBoundary(t,n,!1)),!n&&i.head==r.from&&r.length){let n=/^\s*/.exec(e.state.sliceDoc(r.from,Math.min(r.from+100,r.to)))[0].length;n&&t.head!=r.from+n&&(i=s.cursor(r.from+n))}return i}function Oe(e,t,n){let r=!1,a=P(e.selection,t=>{let a=i(e,t.head,-1)||i(e,t.head,1)||t.head>0&&i(e,t.head-1,1)||t.head<e.doc.length&&i(e,t.head+1,-1);if(!a||!a.end)return t;r=!0;let o=a.start.from==t.head?a.end.to:a.end.from;return n?s.range(t.anchor,o):s.cursor(o)});return r?(t(F(e,a)),!0):!1}function V(e,t,n){let r=P(e.state.selection,e=>{e.undirectional&&e.head>=e.anchor!=t&&(e=s.range(e.head,e.anchor));let r=n(e);return s.range(e.anchor,r.head,r.goalColumn,r.bidiLevel||void 0,r.assoc)});return!r.eq(e.state.selection)&&(e.dispatch(F(e.state,r)),!0)}function ke(e,t){return V(e,t,n=>e.moveByChar(n,t))}function Ae(e,t){return V(e,t,n=>e.moveByGroup(n,t))}function je(e,t){return V(e,t,n=>e.moveVertically(n,t))}function Me(e,t){return V(e,t,n=>e.moveVertically(n,t,Ee(e).height))}function Ne(e,t){let{state:n}=e,r=n.selection,i=n.selection.ranges.slice();for(let r of n.selection.ranges){let a=n.doc.lineAt(r.head);if(t?a.to<e.state.doc.length:a.from>0)for(let n=r;;){let r=e.moveVertically(n,t);if(r.head<a.from||r.head>a.to){i.some(e=>e.head==r.head)||i.push(r);break}if(r.head==n.head)break;n=r}}return i.length!=r.ranges.length&&(e.dispatch(F(n,s.create(i,i.length-1))),!0)}function H(e,t){if(e.state.readOnly)return!1;let n=`delete.selection`,{state:r}=e,i=r.changeByRange(r=>{let{from:i,to:a}=r;if(i==a){let o=t(r);o<i?(n=`delete.backward`,o=U(e,o,!1)):o>i&&(n=`delete.forward`,o=U(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=U(e,i,!1),a=U(e,a,!0);return i==a?{range:r}:{changes:{from:i,to:a},range:s.cursor(i,i<r.head?-1:1)}});return!i.changes.empty&&(e.dispatch(r.update(i,{scrollIntoView:!0,userEvent:n,effects:n==`delete.selection`?o.announce.of(r.phrase(`Selection deleted`)):void 0})),!0)}function U(e,t,n){if(e instanceof o)for(let r of e.state.facet(o.atomicRanges).map(t=>t(e)))r.between(t,t,(e,r)=>{e<t&&r>t&&(t=n?r:e)});return t}function W(e){let t=[],n=-1;for(let r of e.selection.ranges){let i=e.doc.lineAt(r.from),a=e.doc.lineAt(r.to);if(!r.empty&&r.to==a.from&&(a=e.doc.lineAt(r.to-1)),n>=i.number){let e=t[t.length-1];e.to=a.to,e.ranges.push(r)}else t.push({from:i.from,to:a.to,ranges:[r]});n=a.number+1}return t}function Pe(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of W(e)){if(n?t.to==e.doc.length:t.from==0)continue;let a=e.doc.lineAt(n?t.to+1:t.from-1),o=a.length+1;if(n){r.push({from:t.to,to:a.to},{from:t.from,insert:a.text+e.lineBreak});for(let n of t.ranges)i.push(s.range(Math.min(e.doc.length,n.anchor+o),Math.min(e.doc.length,n.head+o)))}else{r.push({from:a.from,to:t.from},{from:t.to,insert:e.lineBreak+a.text});for(let e of t.ranges)i.push(s.range(e.anchor-o,e.head-o))}}return r.length?(t(e.update({changes:r,scrollIntoView:!0,selection:s.create(i,e.selection.mainIndex),userEvent:`move.line`})),!0):!1}function Fe(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of W(e))n?r.push({from:t.from,insert:e.doc.slice(t.from,t.to)+e.lineBreak}):r.push({from:t.to,insert:e.lineBreak+e.doc.slice(t.from,t.to)});let i=e.changes(r);return t(e.update({changes:i,selection:e.selection.map(i,n?1:-1),scrollIntoView:!0,userEvent:`input.copyline`})),!0}function Ie(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=a(e).resolveInner(t),r=n.childBefore(t),i=n.childAfter(t),o;return r&&i&&r.to<=t&&i.from>=t&&(o=r.type.prop(D.closedBy))&&o.indexOf(i.name)>-1&&e.doc.lineAt(r.to).from==e.doc.lineAt(i.from).from&&!/\S/.test(e.sliceDoc(r.to,i.from))?{from:r.to,to:i.from}:null}function Le(e){return({state:n,dispatch:r})=>{if(n.readOnly)return!1;let i=n.changeByRange(r=>{let{from:i,to:a}=r,o=n.doc.lineAt(i),c=!e&&i==a&&Ie(n,i);e&&(i=a=(a<=o.to?o:n.doc.lineAt(a)).to);let l=new re(n,{simulateBreak:i,simulateDoubleBreak:!!c}),u=b(l,i);for(u??=w(/^\s*/.exec(n.doc.lineAt(i).text)[0],n.tabSize);a<o.to&&/\s/.test(o.text[a-o.from]);)a++;c?{from:i,to:a}=c:i>o.from&&i<o.from+100&&!/\S/.test(o.text.slice(0,i))&&(i=o.from);let d=[``,O(n,u)];return c&&d.push(O(n,l.lineIndent(o.from,-1))),{changes:{from:i,to:a,insert:t.of(d)},range:s.cursor(i+1+d[1].length)}});return r(n.update(i,{scrollIntoView:!0,userEvent:`input`})),!0}}function Re(e,t){let n=-1;return e.changeByRange(r=>{let i=[];for(let a=r.from;a<=r.to;){let o=e.doc.lineAt(a);o.number>n&&(r.empty||r.to>o.from)&&(t(o,i,r),n=o.number),a=o.to+1}let a=e.changes(i);return{changes:i,range:s.range(a.mapPos(r.anchor,1),a.mapPos(r.head,1))}})}var ze,Be,Ve,He,G,K,Ue,We,Ge,Ke,qe,q,Je,Ye,J,Y,Xe,Ze,X,Qe,$e,et,tt,nt,rt,it,at,ot,st,Z,ct,lt,ut,dt,ft,pt,mt,ht,gt,_t,vt,yt,bt,xt,St,Ct,wt,Tt,Et,Dt,Ot,kt,At,jt,Mt,Nt,Pt,Ft,It,Lt,Rt,zt,Bt,Vt,Q,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt,Zt,Qt,$t,en,tn,nn,rn,an,on,sn,cn,ln,un,dn;function fn(){return(fn=e((()=>{te(),h(),ae(),T(),ze=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=A(e.state,n.from);return r.line?Be(e):r.block?He(e):!1},Be=k(me,0),Ve=k(pe,0),He=k((e,t)=>pe(e,t,fe(t)),0),G=50,K=_.define(),Ue=_.define(),We=ne.define(),Ge=ne.define({combine(e){return ie(e,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(n,r)=>e(n,r)||t(n,r)})}}),Ke=m.define({create(){return X.empty},update(e,t){let n=t.state.facet(Ge),r=t.annotation(K);if(r){let i=J.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?M(o,o.length,n.minDepth,i):ye(o,t.startState.selection),new X(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(Ue);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(S.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=J.fromTransaction(t),o=t.annotation(S.time),s=t.annotation(S.userEvent);return a?e=e.addChanges(a,o,s,n,t):t.selection&&(e=e.addSelection(t.startState.selection,o,s,n.newGroupDelay)),(i==`full`||i==`after`)&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(e=>e.toJSON()),undone:e.undone.map(e=>e.toJSON())}},fromJSON(e){return new X(e.done.map(J.fromJSON),e.undone.map(J.fromJSON))}}),qe=j(0,!1),q=j(1,!1),Je=j(0,!0),Ye=j(1,!0),J=class e{constructor(e,t,n,r,i){this.changes=e,this.effects=t,this.mapped=n,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){return{changes:this.changes?.toJSON(),mapped:this.mapped?.toJSON(),startSelection:this.startSelection?.toJSON(),selectionsAfter:this.selectionsAfter.map(e=>e.toJSON())}}static fromJSON(t){return new e(t.changes&&g.fromJSON(t.changes),[],t.mapped&&c.fromJSON(t.mapped),t.startSelection&&s.fromJSON(t.startSelection),t.selectionsAfter.map(s.fromJSON))}static fromTransaction(t,n){let r=Y;for(let e of t.startState.facet(We)){let n=e(t);n.length&&(r=r.concat(n))}return!r.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),r,void 0,n||t.startState.selection,Y)}static selection(t){return new e(void 0,Y,void 0,void 0,t)}},Y=[],Xe=200,Ze=/^(input\.type|delete)($|\.)/,X=class e{constructor(e,t,n=0,r=void 0){this.done=e,this.undone=t,this.prevTime=n,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,r,i,a){let o=this.done,s=o[o.length-1];return o=s&&s.changes&&!s.changes.empty&&t.changes&&(!r||Ze.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,ge(s.changes,t.changes))||r==`input.type.compose`)?M(o,o.length-1,i.minDepth,new J(t.changes.compose(s.changes),ve(y.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,Y)):M(o,o.length,i.minDepth,t),new e(o,Y,n,r)}addSelection(t,n,r,i){let a=this.done.length?this.done[this.done.length-1].selectionsAfter:Y;return a.length>0&&n-this.prevTime<i&&r==this.prevUserEvent&&r&&/^select($|\.)/.test(r)&&_e(a[a.length-1],t)?this:new e(ye(this.done,t),this.undone,n,r)}addMapping(t){return new e(N(this.done,t),N(this.undone,t),this.prevTime,this.prevUserEvent)}pop(e,t,n){let r=e==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],a=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):t.selection);if(n&&i.selectionsAfter.length)return t.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:K.of({side:e,rest:be(r),selection:a}),userEvent:e==0?`select.undo`:`select.redo`,scrollIntoView:!0});if(i.changes){let n=r.length==1?Y:r.slice(0,r.length-1);return i.mapped&&(n=N(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:K.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}},X.empty=new X(Y,Y),Qe=[{key:`Mod-z`,run:qe,preventDefault:!0},{key:`Mod-y`,mac:`Mod-Shift-z`,run:q,preventDefault:!0},{linux:`Ctrl-Shift-z`,run:q,preventDefault:!0},{key:`Mod-u`,run:Je,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:Ye,preventDefault:!0}],$e=e=>Se(e,!R(e)),et=e=>Se(e,R(e)),tt=e=>Ce(e,!R(e)),nt=e=>Ce(e,R(e)),typeof Intl<`u`&&Intl.Segmenter,rt=e=>I(e,t=>z(e.state,t,!R(e))),it=e=>I(e,t=>z(e.state,t,R(e))),at=e=>Te(e,!1),ot=e=>Te(e,!0),st=e=>De(e,!1),Z=e=>De(e,!0),ct=e=>I(e,t=>B(e,t,!0)),lt=e=>I(e,t=>B(e,t,!1)),ut=e=>I(e,t=>B(e,t,!R(e))),dt=e=>I(e,t=>B(e,t,R(e))),ft=e=>I(e,t=>e.moveToLineBoundary(t,!1,!1)),pt=e=>I(e,t=>e.moveToLineBoundary(t,!0,!1)),mt=({state:e,dispatch:t})=>Oe(e,t,!1),ht=e=>ke(e,!R(e)),gt=e=>ke(e,R(e)),_t=e=>Ae(e,!R(e)),vt=e=>Ae(e,R(e)),yt=e=>{let t=!R(e);return V(e,t,n=>z(e.state,n,t))},bt=e=>{let t=R(e);return V(e,t,n=>z(e.state,n,t))},xt=e=>je(e,!1),St=e=>je(e,!0),Ct=e=>Me(e,!1),wt=e=>Me(e,!0),Tt=e=>V(e,!0,t=>B(e,t,!0)),Et=e=>V(e,!1,t=>B(e,t,!1)),Dt=e=>{let t=!R(e);return V(e,t,n=>B(e,n,t))},Ot=e=>{let t=R(e);return V(e,t,n=>B(e,n,t))},kt=e=>V(e,!1,t=>s.cursor(e.lineBlockAt(t.head).from)),At=e=>V(e,!0,t=>s.cursor(e.lineBlockAt(t.head).to)),jt=({state:e,dispatch:t})=>(t(F(e,{anchor:0})),!0),Mt=({state:e,dispatch:t})=>(t(F(e,{anchor:e.doc.length})),!0),Nt=({state:e,dispatch:t})=>(t(F(e,{anchor:e.selection.main.anchor,head:0})),!0),Pt=({state:e,dispatch:t})=>(t(F(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Ft=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),It=({state:e,dispatch:t})=>{let n=W(e).map(({from:t,to:n})=>s.undirectionalRange(t,Math.min(n+1,e.doc.length)));return t(e.update({selection:s.create(n),userEvent:`select`})),!0},Lt=({state:e,dispatch:t})=>{let n=P(e.selection,t=>{let n=a(e),r=n.resolveStack(t.from,1);if(t.empty){let e=n.resolveStack(t.from,-1);e.node.from>=r.node.from&&e.node.to<=r.node.to&&(r=e)}for(let e=r;e;e=e.next){let{node:n}=e;if((n.from<t.from&&n.to>=t.to||n.to>t.to&&n.from<=t.from)&&e.next)return s.undirectionalRange(n.from,n.to)}return t});return!n.eq(e.selection)&&(t(F(e,n)),!0)},Rt=e=>Ne(e,!1),zt=e=>Ne(e,!0),Bt=({state:e,dispatch:t})=>{let n=e.selection,r=null;return n.ranges.length>1?r=s.create([n.main]):n.main.empty||(r=s.create([s.cursor(n.main.head)])),r?(t(F(e,r)),!0):!1},Vt=(e,t,n)=>H(e,r=>{let i=r.from,{state:a}=e,o=a.doc.lineAt(i),s,c;if(n&&!t&&i>o.from&&i<o.from+200&&!/[^ \t]/.test(s=o.text.slice(0,i-o.from))){if(s[s.length-1]==` `)return i-1;let e=w(s,a.tabSize)%C(a)||C(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=E(o.text,i-o.from,t,t)+o.from,c==i&&o.number!=(t?a.doc.lines:1)?c+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(o.text.slice(c-o.from,i-o.from))&&(c=E(o.text,c-o.from,!1,!1)+o.from);return c}),Q=e=>Vt(e,!1,!0),Ht=e=>Vt(e,!0,!1),Ut=(e,t)=>H(e,n=>{let r=n.head,{state:i}=e,a=i.doc.lineAt(r),o=i.charCategorizer(r);for(let e=null;;){if(r==(t?a.to:a.from)){r==n.head&&a.number!=(t?i.doc.lines:1)&&(r+=t?1:-1);break}let s=E(a.text,r-a.from,t)+a.from,c=a.text.slice(Math.min(r,s)-a.from,Math.max(r,s)-a.from),l=o(c);if(e!=null&&l!=e)break;(c!=` `||r!=n.head)&&(e=l),r=s}return r}),Wt=e=>Ut(e,!1),Gt=e=>Ut(e,!0),Kt=e=>H(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),qt=e=>H(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Jt=e=>H(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Yt=({state:e,dispatch:n})=>{if(e.readOnly)return!1;let r=e.changeByRange(e=>({changes:{from:e.from,to:e.to,insert:t.of([``,``])},range:s.cursor(e.from)}));return n(e.update(r,{scrollIntoView:!0,userEvent:`input`})),!0},Xt=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(t=>{if(!t.empty||t.from==0||t.from==e.doc.length)return{range:t};let n=t.from,r=e.doc.lineAt(n),i=n==r.from?n-1:E(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:E(r.text,n-r.from,!0)+r.from;return{changes:{from:i,to:a,insert:e.doc.slice(n,a).append(e.doc.slice(i,n))},range:s.cursor(a)}});return!n.changes.empty&&(t(e.update(n,{scrollIntoView:!0,userEvent:`move.character`})),!0)},Zt=({state:e,dispatch:t})=>Pe(e,t,!1),Qt=({state:e,dispatch:t})=>Pe(e,t,!0),$t=({state:e,dispatch:t})=>Fe(e,t,!1),en=({state:e,dispatch:t})=>Fe(e,t,!0),tn=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(W(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=P(t.selection,t=>{let n;if(e.lineWrapping){let r=e.lineBlockAt(t.head),i=e.coordsAtPos(t.head,t.assoc||1);i&&(n=r.bottom+e.documentTop-i.bottom+e.defaultLineHeight/2)}return e.moveVertically(t,!0,n)}).map(n);return e.dispatch({changes:n,selection:r,scrollIntoView:!0,userEvent:`delete.line`}),!0},nn=Le(!1),rn=Le(!0),an=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new re(e,{overrideIndentation:e=>n[e]??-1}),i=Re(e,(t,i,a)=>{let o=b(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=O(e,o);(s!=c||a.from<t.from+s.length)&&(n[t.from]=o,i.push({from:t.from,to:t.from+s.length,insert:c}))});return i.changes.empty||t(e.update(i,{userEvent:`indent`})),!0},on=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Re(e,(t,n)=>{n.push({from:t.from,insert:e.facet(x)})}),{userEvent:`input.indent`})),!0),sn=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(Re(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=w(r,e.tabSize),a=0,o=O(e,Math.max(0,i-C(e)));for(;a<r.length&&a<o.length&&r.charCodeAt(a)==o.charCodeAt(a);)a++;n.push({from:t.from+a,to:t.from+r.length,insert:o.slice(a)})}),{userEvent:`delete.dedent`})),!0),cn=e=>(e.setTabFocusMode(),!0),ln=[{key:`Ctrl-b`,run:$e,shift:ht,preventDefault:!0},{key:`Ctrl-f`,run:et,shift:gt},{key:`Ctrl-p`,run:at,shift:xt},{key:`Ctrl-n`,run:ot,shift:St},{key:`Ctrl-a`,run:ft,shift:kt},{key:`Ctrl-e`,run:pt,shift:At},{key:`Ctrl-d`,run:Ht},{key:`Ctrl-h`,run:Q},{key:`Ctrl-k`,run:Kt},{key:`Ctrl-Alt-h`,run:Wt},{key:`Ctrl-o`,run:Yt},{key:`Ctrl-t`,run:Xt},{key:`Ctrl-v`,run:Z}],un=[{key:`ArrowLeft`,run:$e,shift:ht,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:tt,shift:_t,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:ut,shift:Dt,preventDefault:!0},{key:`ArrowRight`,run:et,shift:gt,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:nt,shift:vt,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:dt,shift:Ot,preventDefault:!0},{key:`ArrowUp`,run:at,shift:xt,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:jt,shift:Nt},{mac:`Ctrl-ArrowUp`,run:st,shift:Ct},{key:`ArrowDown`,run:ot,shift:St,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:Mt,shift:Pt},{mac:`Ctrl-ArrowDown`,run:Z,shift:wt},{key:`PageUp`,run:st,shift:Ct},{key:`PageDown`,run:Z,shift:wt},{key:`Home`,run:lt,shift:Et,preventDefault:!0},{key:`Mod-Home`,run:jt,shift:Nt},{key:`End`,run:ct,shift:Tt,preventDefault:!0},{key:`Mod-End`,run:Mt,shift:Pt},{key:`Enter`,run:nn,shift:nn},{key:`Mod-a`,run:Ft},{key:`Backspace`,run:Q,shift:Q,preventDefault:!0},{key:`Delete`,run:Ht,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Wt,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:Gt,preventDefault:!0},{mac:`Mod-Backspace`,run:qt,preventDefault:!0},{mac:`Mod-Delete`,run:Jt,preventDefault:!0}].concat(ln.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),dn=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:rt,shift:yt},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:it,shift:bt},{key:`Alt-ArrowUp`,run:Zt},{key:`Shift-Alt-ArrowUp`,run:$t},{key:`Alt-ArrowDown`,run:Qt},{key:`Shift-Alt-ArrowDown`,run:en},{key:`Mod-Alt-ArrowUp`,run:Rt},{key:`Mod-Alt-ArrowDown`,run:zt},{key:`Escape`,run:Bt},{key:`Mod-Enter`,run:rn},{key:`Alt-l`,mac:`Ctrl-l`,run:It},{key:`Mod-i`,run:Lt,preventDefault:!0},{key:`Mod-[`,run:sn},{key:`Mod-]`,run:on},{key:`Mod-Alt-\\`,run:an},{key:`Shift-Mod-k`,run:tn},{key:`Shift-Mod-\\`,run:mt},{key:`Mod-/`,run:ze},{key:`Alt-A`,mac:`Ctrl-A`,run:Ve},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:cn}].concat(un)})))()}function pn(e){let t=e.match(/\r\n|\r|\n/);return t&&t[0]!==`
`?t[0]:void 0}async function mn(e){let t=new v,n=new v,i=new v,a=await le(e.name,e.language);if(e.isCurrent&&!e.isCurrent())throw new DOMException(`Editor selection changed`,`AbortError`);let s=null,c=!1,p=e.editable===!0,m=e.wrap===!0,h=e.highlight!==!1,g=pn(e.content),_=e.content,y=e=>e.doc.eq(S)?_:e.doc.sliceString(0,e.doc.length,g??`
`),b=c=>l.create({doc:c,extensions:[r(),u(),he(),oe.of([...dn,...Qe,{key:`Mod-s`,preventDefault:!0,run:()=>(e.onSave(),!0)}]),i.of(h?ee(f):[]),...a?[a]:[],o.contentAttributes.of({"aria-label":e.name,tabindex:`0`}),t.of([l.readOnly.of(!p),o.editable.of(p)]),n.of(m?o.lineWrapping:[]),hn,o.updateListener.of(t=>{t.selectionSet&&!t.state.selection.main.empty&&e.onSelectContent?.(),t.docChanged&&s?.(y(t.state))})]}),x=b(e.content),S=x.doc;e.parent.replaceChildren();let C=new o({parent:e.parent,root:document,state:x}),te=e.onScrollPortRef?.(C.scrollDOM),w=se(C.scrollDOM,C.contentDOM,e.scrollFades===!0),T;return{destroy:()=>{c||(c=!0,w.destroy(),te?.(),C.destroy())},setScrollFades:e=>w.setEnabled(e),setContent:e=>{if(c)return;let t=pn(e);_=e,S=C.state.toText(e),t===g?C.state.doc.eq(S)||C.dispatch({changes:{from:0,to:C.state.doc.length,insert:e}}):(g=t,C.setState(b(e)))},contentEquals:e=>C.state.toText(e).eq(C.state.doc),setEditable:e=>{c||e===p||(p=e,C.dispatch({effects:t.reconfigure([l.readOnly.of(!e),o.editable.of(e)])}))},setLineWrapping:e=>{c||e===m||(m=e,C.dispatch({effects:n.reconfigure(e?o.lineWrapping:[])}))},setSyntaxHighlighting:e=>{if(c||e===h)return;let t=C.dom.ownerDocument.getSelection(),n=!p&&!C.hasFocus&&t?.anchorNode!=null&&t.focusNode!=null&&C.contentDOM.contains(t.anchorNode)&&C.contentDOM.contains(t.focusNode);if(h=e,C.dispatch({effects:i.reconfigure(e?ee(f):[])}),n&&t){let{anchor:e,head:n}=C.state.selection.main,r=C.domAtPos(e),i=C.domAtPos(n);t.setBaseAndExtent(r.node,r.offset,i.node,i.offset)}},setDecorations:({targetLine:e,matches:t=[],currentMatch:n})=>{if(c)return;let r=T;if(r?.document===C.state.doc&&r.targetLine===e&&r.currentMatch===n&&r.matches.length===t.length&&t.every((e,t)=>e===r.matches[t]))return;T={document:C.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<=C.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`),d.line({class:r.join(` `),...t===e?{attributes:{"data-line":String(t)}}:{}}).range(C.state.doc.line(t).from)});C.dispatch({effects:$.of(d.set(a))})},scrollToLine:(e,t)=>{if(c)return;let n=Math.max(1,Math.min(Math.floor(e),C.state.doc.lines));C.dispatch({effects:o.scrollIntoView(C.state.doc.line(n).from,{y:t?`center`:`nearest`})})},getContent:()=>y(C.state),onDocChanged:e=>{s=e},focus:()=>C.focus()}}var $,hn;function gn(){return(gn=e((()=>{fn(),ae(),te(),h(),n(),ue(),ce(),$=y.define(),hn=m.define({create:()=>d.none,update:(e,t)=>{for(let e of t.effects)if(e.is($))return e.value;return e.map(t.changes)},provide:e=>o.decorations.from(e)})})))()}gn();export{mn as createFileEditorView};