@ws-ui/code-editor 0.0.15 → 0.0.17

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/dist/index.cjs.js CHANGED
@@ -48,5 +48,5 @@ Check the top-level render call using <`+s+">.")}return o}}function Ke(e,o){{if(
48
48
  cursor: not-allowed;
49
49
  z-index: 1;
50
50
  }
51
- `;if(j){const m="monaco-read-only";tn(m)||en(j,m),j=null}const M=()=>{d(R),R()},I=()=>{a(R),L=r.deltaDecorations(L,[])},R=()=>{const m=r.getModel();m&&(L=r.deltaDecorations(L,i.map(y(m))))},y=m=>p=>{const K=m.getPositionAt(p[0]),F=m.getPositionAt(p[1]);return{range:new c.Range(K.lineNumber,K.column,F.lineNumber,F.column),options:{className:"idoc-readonly-mark"}}};return{get buffer(){return i},exclude:u,attach:d,detach:a,dispose:P,show:M,hide:I}}function rn(r,n,t){let i=!1;const l=I=>I[1]<I[0]?(i=!0,[[I[1],I[0]]]):[[...I]],u=I=>i?I.map(R=>R[1]>R[0]?a(R):R).reverse():I;let d;const a=I=>(d=I[1],I[1]=I[0],I[0]=d,I),f=l(r);let h,b,S,v,P,L,j,M;S=f[0];for(b of n)for(j=b[0],M=b[1],v=0;v<f.length;v++){if(S=f[v],P=S[0],L=S[1],P<j)L<j?h=[S]:L<=M?h=[[P,j-1]]:h=[[P,j-1],[M+1,L]];else if(P<=M)if(j===Number.NEGATIVE_INFINITY){const I=M+1;h=t===0?[]:[[I,L>I?L:I]]}else M===Number.POSITIVE_INFINITY?h=t===0?[]:[[j-1,j-1]]:L<=M?h=t<0?[[j-1,j-1]]:t>0?[[M+1,M+1]]:[]:h=[[M+1,L]];else h=[S];if(f.splice(v,1,...h),f.length===1&&f[0][1]<j)return u(f)}return u(f)}function on(r,n){if(r.length<2)return r;const t=[];let i=null,l,u;r=r.map(d=>(d[1]<d[0]&&(l=d[1],d[1]=d[0],d[1]=l),d)).sort((d,a)=>d[0]-a[0]),t.push(r[0]);for(let d=1;d<r.length;d++)i=t[t.length-1],u=r[d],i[1]===u[0]&&!n?t.push(u):i[1]===u[0]-1&&n?(i[1]=u[1],t.splice(t.length-1,1,i)):i[1]<u[0]?t.push(u):i[1]<u[1]&&(i[1]=u[1],t.splice(t.length-1,1,i));return t}function ie(r,n){return n.bind(r)}class sn{constructor(n,t){V(this,"editor");V(this,"intervals");V(this,"disposables",[]);V(this,"prefer",1);V(this,"lastPrefer",1);V(this,"onCursor",ie(this,function(n){if(n.source==="api")return;const t=this.getApprovedSelections();t.length!==0&&this.editor.setSelections(t)}));V(this,"onRectangleSelectionStart",ie(this,function({event:n}){n.middleButton&&(this.lastPrefer=this.prefer,this.prefer=0,window.addEventListener("pointerup",this.onRectangleSelectionStop))}));V(this,"onRectangleSelectionStop",ie(this,function(){this.prefer=this.lastPrefer,window.removeEventListener("pointerup",this.onRectangleSelectionStop)}));V(this,"onKey",ie(this,function(n){const t=n.keyCode,i=c.KeyCode;if(n.altKey||i.F1<=t&&t<=i.F19||n.ctrlKey&&t!==i.Backspace)return;if(t===i.UpArrow||t===i.LeftArrow||t===i.Home||t===i.PageUp){this.prefer=-1;return}if(t===i.DownArrow||t===i.RightArrow||t===i.End||t===i.PageDown){this.prefer=1;return}const l=this.getSelections(),u=this.intervals.buffer;let d;if(t===i.Delete)d=a=>a[0]===a[1]&&u.find(f=>a[1]+1===f[0])!=null;else if(t===i.Backspace)d=a=>a[0]===a[1]&&u.find(f=>f[1]+1===a[0])!=null;else return;l.findIndex(d)!==-1&&(n.stopPropagation(),n.preventDefault())}));V(this,"getOffsetAt",ie(this,function(n){let t;for(let i=0;i<this.intervals.buffer.length;i++)if(t=this.intervals.buffer[i],n<=t[1])return t[0]-n<n-t[1]?t[0]:t[1]}));var i;this.editor=n,this.intervals=nn(n,t),(i=this.editor.getModel())==null||i.setEOL(c.editor.EndOfLineSequence.LF)}enable(){this.disposables.push(this.editor.onDidChangeCursorPosition(this.onCursor),this.editor.onKeyDown(this.onKey),this.editor.onMouseDown(this.onRectangleSelectionStart)),this.intervals.show()}dispose(){for(const n of this.disposables)n.dispose();this.disposables.splice(0)}exclude(n,t,i,l){arguments.length===1?this.intervals.exclude(n,0,n,Number.MAX_SAFE_INTEGER):this.intervals.exclude(n,t,i,l)}getApprovedSelections(){const n=this.editor.getModel();return this.getSelections().map(i=>rn(i,this.intervals.buffer,this.prefer)).flat().map(i=>{const l=n.getPositionAt(i[0]),u=n.getPositionAt(i[1]);return new c.Selection(l.lineNumber,l.column,u.lineNumber,u.column)})}getSelections(){const n=this.editor.getModel();return(this.editor.getSelections()||[]).map(t=>[n.getOffsetAt({lineNumber:t.selectionStartLineNumber,column:t.selectionStartColumn}),n.getOffsetAt({lineNumber:t.positionLineNumber,column:t.positionColumn})])}}const an=new RegExp("^[ s]+(exposed|Function)","i"),He=()=>A.jsx("div",{className:"absolute inset-0 animate-pulse",children:A.jsx("div",{className:"w-full space-y-4 px-4 py-1",children:A.jsxs("div",{className:"space-y-2",children:[A.jsx("div",{className:"h-3 w-3/4 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 w-5/6 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"})]})})}),ln=({path:r,initialValue:n,theme:t="fd-dark",type:i,language:l,onChange:u,options:d={},extra:a={},showAlerts:f=!1,lspProps:h,...b})=>{const{initialLineInfo:S,initialSelectionInfo:v}=a,{editor:P,setEditor:L}=rt(),{inited:j}=h;function M(R){l==="css"&&R.languages.registerCompletionItemProvider("css",Qt)}function I(R,y){L(R);const m=R.getModel();if(m&&(m.updateOptions({insertSpaces:!1}),R.onKeyUp(()=>{var K;const p=(K=R.getPosition())==null?void 0:K.lineNumber;if(p){const F=m.getLineFirstNonWhitespaceColumn(p),k=m.getLineLength(p),U=m.getLineContent(p);an.test(U)&&R.executeEdits("edit-handler",[{range:new y.Range(p,0,p,k),text:U.substr(F-1,k-F)}])}})),i===B.FileFolderType.METHOD&&B.hasAttributesString(n)){const p=new sn(R,!0);p.exclude(1,1,1,Number.POSITIVE_INFINITY),p.enable()}}return w.useEffect(()=>{if(!P)return;const{line:R,offset:y}=S||{};R&&et(P,R,y)},[S]),w.useEffect(()=>{if(!P)return;const{selection:R}=v||{};R&&Qe(P,R)},[v]),j?A.jsxs(A.Fragment,{children:[f?A.jsx(at,{lspProps:h}):null,A.jsx(Re.Editor,{options:{readOnly:!0,fontSize:12,"semanticHighlighting.enabled":!0,...d},path:z(r),value:n,theme:"fd-dark",onChange:R=>u&&u(R||""),language:l,beforeMount:M,onMount:I,loading:A.jsx(He,{}),...b})]}):A.jsx(He,{})};exports.Alerts=at;exports.CodeEditor=ln;exports.CodeEditorProvider=Gt;exports.LSPProvider=Bt;exports._await=Se;exports.getFileSystemPath=z;exports.getFunctionOffset=$t;exports.jumpToLine=et;exports.jumpToSelection=Qe;exports.useCodeEditor=rt;exports.useLSP=zt;
51
+ `;if(j){const m="monaco-read-only";tn(m)||en(j,m),j=null}const M=()=>{d(R),R()},I=()=>{a(R),L=r.deltaDecorations(L,[])},R=()=>{const m=r.getModel();m&&(L=r.deltaDecorations(L,i.map(y(m))))},y=m=>p=>{const K=m.getPositionAt(p[0]),F=m.getPositionAt(p[1]);return{range:new c.Range(K.lineNumber,K.column,F.lineNumber,F.column),options:{className:"idoc-readonly-mark"}}};return{get buffer(){return i},exclude:u,attach:d,detach:a,dispose:P,show:M,hide:I}}function rn(r,n,t){let i=!1;const l=I=>I[1]<I[0]?(i=!0,[[I[1],I[0]]]):[[...I]],u=I=>i?I.map(R=>R[1]>R[0]?a(R):R).reverse():I;let d;const a=I=>(d=I[1],I[1]=I[0],I[0]=d,I),f=l(r);let h,b,S,v,P,L,j,M;S=f[0];for(b of n)for(j=b[0],M=b[1],v=0;v<f.length;v++){if(S=f[v],P=S[0],L=S[1],P<j)L<j?h=[S]:L<=M?h=[[P,j-1]]:h=[[P,j-1],[M+1,L]];else if(P<=M)if(j===Number.NEGATIVE_INFINITY){const I=M+1;h=t===0?[]:[[I,L>I?L:I]]}else M===Number.POSITIVE_INFINITY?h=t===0?[]:[[j-1,j-1]]:L<=M?h=t<0?[[j-1,j-1]]:t>0?[[M+1,M+1]]:[]:h=[[M+1,L]];else h=[S];if(f.splice(v,1,...h),f.length===1&&f[0][1]<j)return u(f)}return u(f)}function on(r,n){if(r.length<2)return r;const t=[];let i=null,l,u;r=r.map(d=>(d[1]<d[0]&&(l=d[1],d[1]=d[0],d[1]=l),d)).sort((d,a)=>d[0]-a[0]),t.push(r[0]);for(let d=1;d<r.length;d++)i=t[t.length-1],u=r[d],i[1]===u[0]&&!n?t.push(u):i[1]===u[0]-1&&n?(i[1]=u[1],t.splice(t.length-1,1,i)):i[1]<u[0]?t.push(u):i[1]<u[1]&&(i[1]=u[1],t.splice(t.length-1,1,i));return t}function ie(r,n){return n.bind(r)}class sn{constructor(n,t){V(this,"editor");V(this,"intervals");V(this,"disposables",[]);V(this,"prefer",1);V(this,"lastPrefer",1);V(this,"onCursor",ie(this,function(n){if(n.source==="api")return;const t=this.getApprovedSelections();t.length!==0&&this.editor.setSelections(t)}));V(this,"onRectangleSelectionStart",ie(this,function({event:n}){n.middleButton&&(this.lastPrefer=this.prefer,this.prefer=0,window.addEventListener("pointerup",this.onRectangleSelectionStop))}));V(this,"onRectangleSelectionStop",ie(this,function(){this.prefer=this.lastPrefer,window.removeEventListener("pointerup",this.onRectangleSelectionStop)}));V(this,"onKey",ie(this,function(n){const t=n.keyCode,i=c.KeyCode;if(n.altKey||i.F1<=t&&t<=i.F19||n.ctrlKey&&t!==i.Backspace)return;if(t===i.UpArrow||t===i.LeftArrow||t===i.Home||t===i.PageUp){this.prefer=-1;return}if(t===i.DownArrow||t===i.RightArrow||t===i.End||t===i.PageDown){this.prefer=1;return}const l=this.getSelections(),u=this.intervals.buffer;let d;if(t===i.Delete)d=a=>a[0]===a[1]&&u.find(f=>a[1]+1===f[0])!=null;else if(t===i.Backspace)d=a=>a[0]===a[1]&&u.find(f=>f[1]+1===a[0])!=null;else return;l.findIndex(d)!==-1&&(n.stopPropagation(),n.preventDefault())}));V(this,"getOffsetAt",ie(this,function(n){let t;for(let i=0;i<this.intervals.buffer.length;i++)if(t=this.intervals.buffer[i],n<=t[1])return t[0]-n<n-t[1]?t[0]:t[1]}));var i;this.editor=n,this.intervals=nn(n,t),(i=this.editor.getModel())==null||i.setEOL(c.editor.EndOfLineSequence.LF)}enable(){this.disposables.push(this.editor.onDidChangeCursorPosition(this.onCursor),this.editor.onKeyDown(this.onKey),this.editor.onMouseDown(this.onRectangleSelectionStart)),this.intervals.show()}dispose(){for(const n of this.disposables)n.dispose();this.disposables.splice(0)}exclude(n,t,i,l){arguments.length===1?this.intervals.exclude(n,0,n,Number.MAX_SAFE_INTEGER):this.intervals.exclude(n,t,i,l)}getApprovedSelections(){const n=this.editor.getModel();return this.getSelections().map(i=>rn(i,this.intervals.buffer,this.prefer)).flat().map(i=>{const l=n.getPositionAt(i[0]),u=n.getPositionAt(i[1]);return new c.Selection(l.lineNumber,l.column,u.lineNumber,u.column)})}getSelections(){const n=this.editor.getModel();return(this.editor.getSelections()||[]).map(t=>[n.getOffsetAt({lineNumber:t.selectionStartLineNumber,column:t.selectionStartColumn}),n.getOffsetAt({lineNumber:t.positionLineNumber,column:t.positionColumn})])}}const an=new RegExp("^[ s]+(exposed|Function)","i"),He=()=>A.jsx("div",{className:"absolute inset-0 animate-pulse",children:A.jsx("div",{className:"w-full space-y-4 px-4 py-1",children:A.jsxs("div",{className:"space-y-2",children:[A.jsx("div",{className:"h-3 w-3/4 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 w-5/6 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"}),A.jsx("div",{className:"h-3 rounded bg-grey-200"})]})})}),ln=({path:r,initialValue:n,theme:t="fd-dark",type:i,language:l,onChange:u,options:d={},extra:a={},showAlerts:f=!1,lspProps:h,...b})=>{const{initialLineInfo:S,initialSelectionInfo:v}=a,{editor:P,setEditor:L}=rt(),{inited:j}=h;function M(R){l==="css"&&R.languages.registerCompletionItemProvider("css",Qt)}function I(R,y){L(R);const m=R.getModel();if(m&&(m.updateOptions({insertSpaces:!1}),R.onKeyUp(()=>{var K;const p=(K=R.getPosition())==null?void 0:K.lineNumber;if(p){const F=m.getLineFirstNonWhitespaceColumn(p),k=m.getLineLength(p),U=m.getLineContent(p);an.test(U)&&R.executeEdits("edit-handler",[{range:new y.Range(p,0,p,k),text:U.substr(F-1,k-F)}])}})),i===B.FileFolderType.METHOD&&B.hasAttributesString(n)){const p=new sn(R,!0);p.exclude(1,1,1,Number.POSITIVE_INFINITY),p.enable()}}return w.useEffect(()=>{if(!P)return;const{line:R,offset:y}=S||{};R&&et(P,R,y)},[S,P]),w.useEffect(()=>{if(!P)return;const{selection:R}=v||{};R&&Qe(P,R)},[v,P]),j?A.jsxs(A.Fragment,{children:[f?A.jsx(at,{lspProps:h}):null,A.jsx(Re.Editor,{options:{readOnly:!0,fontSize:12,"semanticHighlighting.enabled":!0,...d},path:z(r),value:n,theme:"fd-dark",onChange:R=>u&&u(R||""),language:l,beforeMount:M,onMount:I,loading:A.jsx(He,{}),...b})]}):A.jsx(He,{})};exports.Alerts=at;exports.CodeEditor=ln;exports.CodeEditorProvider=Gt;exports.LSPProvider=Bt;exports._await=Se;exports.getFileSystemPath=z;exports.getFunctionOffset=$t;exports.jumpToLine=et;exports.jumpToSelection=Qe;exports.useCodeEditor=rt;exports.useLSP=zt;
52
52
  //# sourceMappingURL=index.cjs.js.map