@ws-ui/code-editor 0.1.24 → 0.1.25
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 +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -0
- package/dist/index.es.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs.js
CHANGED
|
@@ -48,5 +48,5 @@ Check the top-level render call using <`+a+">.")}return o}}function qe(e,o){{if(
|
|
|
48
48
|
cursor: not-allowed;
|
|
49
49
|
z-index: 1;
|
|
50
50
|
}
|
|
51
|
-
`;if(j){const m="monaco-read-only";on(m)||rn(j,m),j=null}const M=()=>{d(E),E()},I=()=>{l(E),L=r.deltaDecorations(L,[])},E=()=>{const m=r.getModel();m&&(L=r.deltaDecorations(L,i.map(R(m))))},R=m=>p=>{const q=m.getPositionAt(p[0]),F=m.getPositionAt(p[1]);return{range:new c.Range(q.lineNumber,q.column,F.lineNumber,F.column),options:{className:"idoc-readonly-mark"}}};return{get buffer(){return i},exclude:u,attach:d,detach:l,dispose:N,show:M,hide:I}}function sn(r,n,t){let i=!1;const s=I=>I[1]<I[0]?(i=!0,[[I[1],I[0]]]):[[...I]],u=I=>i?I.map(E=>E[1]>E[0]?l(E):E).reverse():I;let d;const l=I=>(d=I[1],I[1]=I[0],I[0]=d,I),f=s(r);let h,b,S,v,N,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],N=S[0],L=S[1],N<j)L<j?h=[S]:L<=M?h=[[N,j-1]]:h=[[N,j-1],[M+1,L]];else if(N<=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 ln(r,n){if(r.length<2)return r;const t=[];let i=null,s,u;r=r.map(d=>(d[1]<d[0]&&(s=d[1],d[1]=d[0],d[1]=s),d)).sort((d,l)=>d[0]-l[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 un{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 s=this.getSelections(),u=this.intervals.buffer;let d;if(t===i.Delete)d=l=>l[0]===l[1]&&u.find(f=>l[1]+1===f[0])!=null;else if(t===i.Backspace)d=l=>l[0]===l[1]&&u.find(f=>f[1]+1===l[0])!=null;else return;s.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=an(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,s){arguments.length===1?this.intervals.exclude(n,0,n,Number.MAX_SAFE_INTEGER):this.intervals.exclude(n,t,i,s)}getApprovedSelections(){const n=this.editor.getModel();return this.getSelections().map(i=>sn(i,this.intervals.buffer,this.prefer)).flat().map(i=>{const s=n.getPositionAt(i[0]),u=n.getPositionAt(i[1]);return new c.Selection(s.lineNumber,s.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 cn=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"})]})})}),dn=({path:r,initialValue:n,theme:t="fd-dark",type:i,language:s,onChange:u,options:d={},extra:l={},showAlerts:f=!1,lspProps:h,...b})=>{const{initialLineInfo:S,initialSelectionInfo:v}=l,{editor:N,setEditor:L}=rt(),{inited:j}=h;function M(E){s==="css"&&E.languages.registerCompletionItemProvider("css",Qt),s==="json"&&E.languages.json&&E.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:"condition-schema.json",fileMatch:["*.condition.json"],schema:nn}]})}function I(E,R){L(E);const m=E.getModel();if(m&&(m.updateOptions({insertSpaces:!1}),E.onKeyUp(()=>{var q;const p=(q=E.getPosition())==null?void 0:q.lineNumber;if(p){const F=m.getLineFirstNonWhitespaceColumn(p),k=m.getLineLength(p),U=m.getLineContent(p);cn.test(U)&&E.executeEdits("edit-handler",[{range:new R.Range(p,0,p,k),text:U.substr(F-1,k-F)}])}})),i===B.FileFolderType.METHOD&&B.hasAttributesString(n)){const p=new un(E,!0);p.exclude(1,1,1,Number.POSITIVE_INFINITY),p.enable()}}return w.useEffect(()=>{if(!N)return;const{line:E,offset:R}=S||{};E&&et(N,E,R)},[S,N]),w.useEffect(()=>{if(!N)return;const{selection:E}=v||{};E&&Qe(N,E)},[v,N]),j?A.jsxs(A.Fragment,{children:[f?A.jsx(st,{lspProps:h}):null,A.jsx(ye.Editor,{options:{readOnly:!0,fontSize:12,"semanticHighlighting.enabled":!0,...d},path:z(r),value:n,theme:"fd-dark",onChange:E=>u&&u(E||""),language:s,beforeMount:M,onMount:I,loading:A.jsx(He,{}),...b})]}):A.jsx(He,{})};exports.Alerts=st;exports.CodeEditor=dn;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";on(m)||rn(j,m),j=null}const M=()=>{d(E),E()},I=()=>{l(E),L=r.deltaDecorations(L,[])},E=()=>{const m=r.getModel();m&&(L=r.deltaDecorations(L,i.map(R(m))))},R=m=>p=>{const q=m.getPositionAt(p[0]),F=m.getPositionAt(p[1]);return{range:new c.Range(q.lineNumber,q.column,F.lineNumber,F.column),options:{className:"idoc-readonly-mark"}}};return{get buffer(){return i},exclude:u,attach:d,detach:l,dispose:N,show:M,hide:I}}function sn(r,n,t){let i=!1;const s=I=>I[1]<I[0]?(i=!0,[[I[1],I[0]]]):[[...I]],u=I=>i?I.map(E=>E[1]>E[0]?l(E):E).reverse():I;let d;const l=I=>(d=I[1],I[1]=I[0],I[0]=d,I),f=s(r);let h,b,S,v,N,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],N=S[0],L=S[1],N<j)L<j?h=[S]:L<=M?h=[[N,j-1]]:h=[[N,j-1],[M+1,L]];else if(N<=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 ln(r,n){if(r.length<2)return r;const t=[];let i=null,s,u;r=r.map(d=>(d[1]<d[0]&&(s=d[1],d[1]=d[0],d[1]=s),d)).sort((d,l)=>d[0]-l[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 un{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 s=this.getSelections(),u=this.intervals.buffer;let d;if(t===i.Delete)d=l=>l[0]===l[1]&&u.find(f=>l[1]+1===f[0])!=null;else if(t===i.Backspace)d=l=>l[0]===l[1]&&u.find(f=>f[1]+1===l[0])!=null;else return;s.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=an(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,s){arguments.length===1?this.intervals.exclude(n,0,n,Number.MAX_SAFE_INTEGER):this.intervals.exclude(n,t,i,s)}getApprovedSelections(){const n=this.editor.getModel();return this.getSelections().map(i=>sn(i,this.intervals.buffer,this.prefer)).flat().map(i=>{const s=n.getPositionAt(i[0]),u=n.getPositionAt(i[1]);return new c.Selection(s.lineNumber,s.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 cn=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"})]})})}),dn=({path:r,initialValue:n,theme:t="fd-dark",type:i,language:s,onChange:u,options:d={},extra:l={},showAlerts:f=!1,lspProps:h,...b})=>{const{initialLineInfo:S,initialSelectionInfo:v}=l,{editor:N,setEditor:L}=rt(),{inited:j}=h;function M(E){s==="css"&&E.languages.registerCompletionItemProvider("css",Qt),s==="json"&&E.languages.json&&E.languages.json.jsonDefaults.setDiagnosticsOptions({validate:!0,schemas:[{uri:"condition-schema.json",fileMatch:["*.condition.json"],schema:nn}]})}function I(E,R){L(E);const m=E.getModel();if(m&&(m.updateOptions({insertSpaces:!1}),E.onKeyUp(()=>{var q;const p=(q=E.getPosition())==null?void 0:q.lineNumber;if(p){const F=m.getLineFirstNonWhitespaceColumn(p),k=m.getLineLength(p),U=m.getLineContent(p);cn.test(U)&&E.executeEdits("edit-handler",[{range:new R.Range(p,0,p,k),text:U.substr(F-1,k-F)}])}})),i===B.FileFolderType.METHOD&&B.hasAttributesString(n)){const p=new un(E,!0);p.exclude(1,1,1,Number.POSITIVE_INFINITY),p.enable()}}return w.useEffect(()=>{if(!N)return;const{line:E,offset:R}=S||{};E&&et(N,E,R)},[S,N]),w.useEffect(()=>{if(!N)return;const{selection:E}=v||{};E&&Qe(N,E)},[v,N]),j?A.jsxs(A.Fragment,{children:[f?A.jsx(st,{lspProps:h}):null,A.jsx(ye.Editor,{options:{readOnly:!0,fontSize:12,"semanticHighlighting.enabled":!0,padding:{top:10},...d},path:z(r),value:n,theme:"fd-dark",onChange:E=>u&&u(E||""),language:s,beforeMount:M,onMount:I,loading:A.jsx(He,{}),...b})]}):A.jsx(He,{})};exports.Alerts=st;exports.CodeEditor=dn;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
|