UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

3 lines • 25.6 kB
import{n as e}from"./rolldown-runtime-8BhlS34s.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 te,V as g,W as ne,Z as _,_ as v,b as y,et as b,g as x,it as re,nt as S,pt as ie,q as ae,rt as C,st as w,t as oe,tt as se,x as ce,y as T,z as le}from"./dist-BwVqDVly.js";import{n as ue,t as de}from"./code-language-DtOh6Vp4.js";function E(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 fe(e,t){let n=e.languageDataAt(`commentTokens`,t,1);return n.length?n[0]:{}}function pe(e,{open:t,close:n},r,i){let a=e.sliceDoc(r-H,r),o=e.sliceDoc(i,i+H),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+H),d=e.sliceDoc(i-H,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 me(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 he(e,t,n=t.selection.ranges){let r=n.map(e=>fe(t,e.from).block);if(!r.every(e=>e))return null;let i=n.map((e,n)=>pe(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 ge(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=fe(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 _e(e={}){return[G,W.of(e),o.domEventHandlers({beforeinput(e,t){let n=e.inputType==`historyUndo`?K:e.inputType==`historyRedo`?q:null;return n?(e.preventDefault(),n(t)):!1}})]}function D(e,t){return function({state:n,dispatch:r}){if(!t&&n.readOnly)return!1;let i=n.field(G,!1);if(!i)return!1;let a=i.pop(e,n,t);return a?(r(a),!0):!1}}function O(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 ve(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 ye(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((e,n)=>e.empty!=t.ranges[n].empty).length===0}function be(e,t){return e.length?t.length?e.concat(t):e:t}function xe(e,t){if(e.length){let n=e[e.length-1],r=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Je));return r.length&&r[r.length-1].eq(t)?e:(r.push(t),O(e,e.length-1,1e9,n.setSelAfter(r)))}return[J.selection([t])]}function Se(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 k(e,t){if(!e.length)return e;let n=e.length,r=Y;for(;n;){let i=Ce(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 Ce(e,t,n){let r=be(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,_.mapEffects(e.effects,t),o,e.startSelection.map(a),r)}function A(e,t){return s.create(e.ranges.map(t),e.mainIndex)}function j(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:`select`})}function M({state:e,dispatch:t},n){let r=A(e.selection,n);return!r.eq(e.selection,!0)&&(t(j(e,r)),!0)}function N(e,t){return s.cursor(t?e.to:e.from)}function we(e,t){return M(e,n=>n.empty?e.moveByChar(n,t):N(n,t))}function P(e){return e.textDirectionAt(e.state.selection.main.head)==p.LTR}function Te(e,t){return M(e,n=>n.empty?e.moveByGroup(n,t):N(n,t))}function Ee(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 F(e,t,n){let r=a(e).resolveInner(t.head),o=n?w.closedBy:w.openedBy;for(let i=t.head;;){let t=n?r.childAfter(i):r.childBefore(i);if(!t)break;Ee(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 De(e,t){return M(e,n=>{if(!n.empty)return N(n,t);let r=e.moveVertically(n,t);return r.head==n.head?e.moveToLineBoundary(n,t):r})}function Oe(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 ke(e,t){let n=Oe(e),{state:r}=e,i=A(r.selection,r=>r.empty?e.moveVertically(r,t,n.height):N(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(j(r,i),{effects:a}),!0}function I(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 Ae(e,t,n){let r=!1,a=A(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(j(e,a)),!0):!1}function L(e,t,n){let r=A(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(j(e.state,r)),!0)}function je(e,t){return L(e,t,n=>e.moveByChar(n,t))}function Me(e,t){return L(e,t,n=>e.moveByGroup(n,t))}function Ne(e,t){return L(e,t,n=>e.moveVertically(n,t))}function Pe(e,t){return L(e,t,n=>e.moveVertically(n,t,Oe(e).height))}function Fe(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(j(n,s.create(i,i.length-1))),!0)}function R(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=z(e,o,!1)):o>i&&(n=`delete.forward`,o=z(e,o,!0)),i=Math.min(i,o),a=Math.max(a,o)}else i=z(e,i,!1),a=z(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 z(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 B(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 Ie(e,t,n){if(e.readOnly)return!1;let r=[],i=[];for(let t of B(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 Le(e,t,n){if(e.readOnly)return!1;let r=[];for(let t of B(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 Re(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(w.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 ze(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&&Re(n,i);e&&(i=a=(a<=o.to?o:n.doc.lineAt(a)).to);let l=new oe(n,{simulateBreak:i,simulateDoubleBreak:!!c}),u=v(l,i);for(u??=S(/^\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=[``,T(n,u)];return c&&d.push(T(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 V(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 Be,Ve,He,Ue,H,U,We,Ge,W,G,K,q,Ke,qe,J,Y,Je,Ye,X,Xe,Z,Ze,Qe,$e,et,tt,nt,rt,it,Q,at,ot,st,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,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt,Zt,Qt,$t,en,tn,nn,rn,an,on,sn,cn;function ln(){return(ln=e((()=>{re(),h(),ce(),ie(),Be=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),r=fe(e.state,n.from);return r.line?Ve(e):r.block?Ue(e):!1},Ve=E(ge,0),He=E(he,0),Ue=E((e,t)=>he(e,t,me(t)),0),H=50,U=g.define(),We=g.define(),Ge=ae.define(),W=ae.define({combine(e){return se(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)})}}),G=m.define({create(){return X.empty},update(e,t){let n=t.state.facet(W),r=t.annotation(U);if(r){let i=J.fromTransaction(t,r.selection),a=r.side,o=a==0?e.undone:e.done;return o=i?O(o,o.length,n.minDepth,i):xe(o,t.startState.selection),new X(a==0?r.rest:o,a==0?o:r.rest)}let i=t.annotation(We);if((i==`full`||i==`before`)&&(e=e.isolate()),t.annotation(b.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let a=J.fromTransaction(t),o=t.annotation(b.time),s=t.annotation(b.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))}}),K=D(0,!1),q=D(1,!1),Ke=D(0,!0),qe=D(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&&te.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(Ge)){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=[],Je=200,Ye=/^(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||Ye.test(r))&&(!s.selectionsAfter.length&&n-this.prevTime<i.newGroupDelay&&i.joinToEvent(a,ve(s.changes,t.changes))||r==`input.type.compose`)?O(o,o.length-1,i.minDepth,new J(t.changes.compose(s.changes),be(_.mapEffects(t.effects,s.changes),s.effects),s.mapped,s.startSelection,Y)):O(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)&&ye(a[a.length-1],t)?this:new e(xe(this.done,t),this.undone,n,r)}addMapping(t){return new e(k(this.done,t),k(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:U.of({side:e,rest:Se(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=k(n,i.mapped)),t.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:U.of({side:e,rest:n,selection:a}),filter:!1,userEvent:e==0?`undo`:`redo`,scrollIntoView:!0})}return null}},X.empty=new X(Y,Y),Xe=[{key:`Mod-z`,run:K,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:Ke,preventDefault:!0},{key:`Alt-u`,mac:`Mod-Shift-u`,run:qe,preventDefault:!0}],Z=e=>we(e,!P(e)),Ze=e=>we(e,P(e)),Qe=e=>Te(e,!P(e)),$e=e=>Te(e,P(e)),typeof Intl<`u`&&Intl.Segmenter,et=e=>M(e,t=>F(e.state,t,!P(e))),tt=e=>M(e,t=>F(e.state,t,P(e))),nt=e=>De(e,!1),rt=e=>De(e,!0),it=e=>ke(e,!1),Q=e=>ke(e,!0),at=e=>M(e,t=>I(e,t,!0)),ot=e=>M(e,t=>I(e,t,!1)),st=e=>M(e,t=>I(e,t,!P(e))),ct=e=>M(e,t=>I(e,t,P(e))),lt=e=>M(e,t=>e.moveToLineBoundary(t,!1,!1)),ut=e=>M(e,t=>e.moveToLineBoundary(t,!0,!1)),dt=({state:e,dispatch:t})=>Ae(e,t,!1),ft=e=>je(e,!P(e)),pt=e=>je(e,P(e)),mt=e=>Me(e,!P(e)),ht=e=>Me(e,P(e)),gt=e=>{let t=!P(e);return L(e,t,n=>F(e.state,n,t))},_t=e=>{let t=P(e);return L(e,t,n=>F(e.state,n,t))},vt=e=>Ne(e,!1),yt=e=>Ne(e,!0),bt=e=>Pe(e,!1),xt=e=>Pe(e,!0),St=e=>L(e,!0,t=>I(e,t,!0)),Ct=e=>L(e,!1,t=>I(e,t,!1)),wt=e=>{let t=!P(e);return L(e,t,n=>I(e,n,t))},Tt=e=>{let t=P(e);return L(e,t,n=>I(e,n,t))},Et=e=>L(e,!1,t=>s.cursor(e.lineBlockAt(t.head).from)),Dt=e=>L(e,!0,t=>s.cursor(e.lineBlockAt(t.head).to)),Ot=({state:e,dispatch:t})=>(t(j(e,{anchor:0})),!0),kt=({state:e,dispatch:t})=>(t(j(e,{anchor:e.doc.length})),!0),At=({state:e,dispatch:t})=>(t(j(e,{anchor:e.selection.main.anchor,head:0})),!0),jt=({state:e,dispatch:t})=>(t(j(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),Mt=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:`select`})),!0),Nt=({state:e,dispatch:t})=>{let n=B(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},Pt=({state:e,dispatch:t})=>{let n=A(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(j(e,n)),!0)},Ft=e=>Fe(e,!1),It=e=>Fe(e,!0),Lt=({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(j(e,r)),!0):!1},Rt=(e,t,n)=>R(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=S(s,a.tabSize)%x(a)||x(a);for(let t=0;t<e&&s[s.length-1-t]==` `;t++)i--;c=i}else c=C(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=C(o.text,c-o.from,!1,!1)+o.from);return c}),$=e=>Rt(e,!1,!0),zt=e=>Rt(e,!0,!1),Bt=(e,t)=>R(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=C(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}),Vt=e=>Bt(e,!1),Ht=e=>Bt(e,!0),Ut=e=>R(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Wt=e=>R(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),Gt=e=>R(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)}),Kt=({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},qt=({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:C(r.text,n-r.from,!1)+r.from,a=n==r.to?n+1:C(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)},Jt=({state:e,dispatch:t})=>Ie(e,t,!1),Yt=({state:e,dispatch:t})=>Ie(e,t,!0),Xt=({state:e,dispatch:t})=>Le(e,t,!1),Zt=({state:e,dispatch:t})=>Le(e,t,!0),Qt=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(B(t).map(({from:e,to:n})=>(e>0?e--:n<t.doc.length&&n++,{from:e,to:n}))),r=A(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},$t=ze(!1),en=ze(!0),tn=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),r=new oe(e,{overrideIndentation:e=>n[e]??-1}),i=V(e,(t,i,a)=>{let o=v(r,t.from);if(o==null)return;/\S/.test(t.text)||(o=0);let s=/^\s*/.exec(t.text)[0],c=T(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},nn=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(V(e,(t,n)=>{n.push({from:t.from,insert:e.facet(y)})}),{userEvent:`input.indent`})),!0),rn=({state:e,dispatch:t})=>!e.readOnly&&(t(e.update(V(e,(t,n)=>{let r=/^\s*/.exec(t.text)[0];if(!r)return;let i=S(r,e.tabSize),a=0,o=T(e,Math.max(0,i-x(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),an=e=>(e.setTabFocusMode(),!0),on=[{key:`Ctrl-b`,run:Z,shift:ft,preventDefault:!0},{key:`Ctrl-f`,run:Ze,shift:pt},{key:`Ctrl-p`,run:nt,shift:vt},{key:`Ctrl-n`,run:rt,shift:yt},{key:`Ctrl-a`,run:lt,shift:Et},{key:`Ctrl-e`,run:ut,shift:Dt},{key:`Ctrl-d`,run:zt},{key:`Ctrl-h`,run:$},{key:`Ctrl-k`,run:Ut},{key:`Ctrl-Alt-h`,run:Vt},{key:`Ctrl-o`,run:Kt},{key:`Ctrl-t`,run:qt},{key:`Ctrl-v`,run:Q}],sn=[{key:`ArrowLeft`,run:Z,shift:ft,preventDefault:!0},{key:`Mod-ArrowLeft`,mac:`Alt-ArrowLeft`,run:Qe,shift:mt,preventDefault:!0},{mac:`Cmd-ArrowLeft`,run:st,shift:wt,preventDefault:!0},{key:`ArrowRight`,run:Ze,shift:pt,preventDefault:!0},{key:`Mod-ArrowRight`,mac:`Alt-ArrowRight`,run:$e,shift:ht,preventDefault:!0},{mac:`Cmd-ArrowRight`,run:ct,shift:Tt,preventDefault:!0},{key:`ArrowUp`,run:nt,shift:vt,preventDefault:!0},{mac:`Cmd-ArrowUp`,run:Ot,shift:At},{mac:`Ctrl-ArrowUp`,run:it,shift:bt},{key:`ArrowDown`,run:rt,shift:yt,preventDefault:!0},{mac:`Cmd-ArrowDown`,run:kt,shift:jt},{mac:`Ctrl-ArrowDown`,run:Q,shift:xt},{key:`PageUp`,run:it,shift:bt},{key:`PageDown`,run:Q,shift:xt},{key:`Home`,run:ot,shift:Ct,preventDefault:!0},{key:`Mod-Home`,run:Ot,shift:At},{key:`End`,run:at,shift:St,preventDefault:!0},{key:`Mod-End`,run:kt,shift:jt},{key:`Enter`,run:$t,shift:$t},{key:`Mod-a`,run:Mt},{key:`Backspace`,run:$,shift:$,preventDefault:!0},{key:`Delete`,run:zt,preventDefault:!0},{key:`Mod-Backspace`,mac:`Alt-Backspace`,run:Vt,preventDefault:!0},{key:`Mod-Delete`,mac:`Alt-Delete`,run:Ht,preventDefault:!0},{mac:`Mod-Backspace`,run:Wt,preventDefault:!0},{mac:`Mod-Delete`,run:Gt,preventDefault:!0}].concat(on.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),cn=[{key:`Alt-ArrowLeft`,mac:`Ctrl-ArrowLeft`,run:et,shift:gt},{key:`Alt-ArrowRight`,mac:`Ctrl-ArrowRight`,run:tt,shift:_t},{key:`Alt-ArrowUp`,run:Jt},{key:`Shift-Alt-ArrowUp`,run:Xt},{key:`Alt-ArrowDown`,run:Yt},{key:`Shift-Alt-ArrowDown`,run:Zt},{key:`Mod-Alt-ArrowUp`,run:Ft},{key:`Mod-Alt-ArrowDown`,run:It},{key:`Escape`,run:Lt},{key:`Mod-Enter`,run:en},{key:`Alt-l`,mac:`Ctrl-l`,run:Nt},{key:`Mod-i`,run:Pt,preventDefault:!0},{key:`Mod-[`,run:rn},{key:`Mod-]`,run:nn},{key:`Mod-Alt-\\`,run:tn},{key:`Shift-Mod-k`,run:Qt},{key:`Shift-Mod-\\`,run:dt},{key:`Mod-/`,run:Be},{key:`Alt-A`,mac:`Ctrl-A`,run:He},{key:`Ctrl-m`,mac:`Shift-Alt-m`,run:an}].concat(sn)})))()}function un(e){let t=e.match(/\r\n|\r|\n/);return t&&t[0]!==` `?t[0]:void 0}async function dn(e){let t=new ne,n=new ne,i=await ue(e.name),a=null,s=!1,c=e.editable===!0,p=e.wrap===!0,m=un(e.content),h=e.content,te=e=>e.doc.eq(v)?h:e.doc.sliceString(0,e.doc.length,m??` `),g=s=>l.create({doc:s,extensions:[r(),u(),_e(),le.of([...cn,...Xe,{key:`Mod-s`,preventDefault:!0,run:()=>(e.onSave(),!0)}]),ee(f),...i?[i]:[],o.contentAttributes.of({"aria-label":e.name,tabindex:`0`}),t.of([l.readOnly.of(!c),o.editable.of(c)]),n.of(p?o.lineWrapping:[]),pn,o.updateListener.of(e=>{e.docChanged&&a?.(te(e.state))})]}),_=g(e.content),v=_.doc;e.parent.replaceChildren();let y=new o({parent:e.parent,root:document,state:_}),b=e=>Math.max(1,Math.min(Math.floor(e),y.state.doc.lines));return{destroy:()=>{s||(s=!0,y.destroy())},setContent:e=>{if(s)return;let t=un(e);if(h=e,v=y.state.toText(e),t!==m){m=t,y.setState(g(e));return}y.state.doc.eq(v)||y.dispatch({changes:{from:0,to:y.state.doc.length,insert:e}})},contentEquals:e=>y.state.toText(e).eq(y.state.doc),setEditable:e=>{s||(c=e,y.dispatch({effects:t.reconfigure([l.readOnly.of(!e),o.editable.of(e)])}))},setLineWrapping:e=>{s||e===p||(p=e,y.dispatch({effects:n.reconfigure(e?o.lineWrapping:[])}))},setDecorations:({targetLine:e,matches:t=[],currentMatch:n})=>{if(s)return;let r=new Set(t),i=new Set(t);e!=null&&i.add(e),n!=null&&i.add(n);let a=[...i].filter(e=>Number.isInteger(e)&&e>=1&&e<=y.state.doc.lines).toSorted((e,t)=>e-t).map(t=>{let i=[];return t===e&&i.push(`file-view__line--target`),r.has(t)&&i.push(`file-view__line--match`),t===n&&i.push(`file-view__line--current`),d.line({class:i.join(` `),...t===e?{attributes:{"data-line":String(t)}}:{}}).range(y.state.doc.line(t).from)});y.dispatch({effects:fn.of(d.set(a))})},scrollToLine:(e,t)=>{s||y.dispatch({effects:o.scrollIntoView(y.state.doc.line(b(e)).from,{y:t?`center`:`nearest`})})},getContent:()=>te(y.state),onDocChanged:e=>{a=e},focus:()=>y.focus()}}var fn,pn;function mn(){return(mn=e((()=>{ln(),ce(),re(),h(),n(),de(),fn=_.define(),pn=m.define({create:()=>d.none,update:(e,t)=>{for(let e of t.effects)if(e.is(fn))return e.value;return e.map(t.changes)},provide:e=>o.decorations.from(e)})})))()}mn();export{dn as createFileEditorView};