@editora/light-code-editor 1.0.2 → 1.0.3
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.es.js +827 -485
- package/dist/index.umd.js +35 -50
- package/dist/light-code-editor.css +1 -1
- package/package.json +25 -7
- package/LICENSE +0 -21
package/dist/index.umd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`)}setText(
|
|
3
|
-
`),this._version++}getTextInRange(
|
|
4
|
-
`)}replaceRange(e
|
|
5
|
-
`);r[0]=o+r[0],r[r.length-1]=r[r.length-1]+h,this._lines.splice(
|
|
1
|
+
(function(m,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(m=typeof globalThis<"u"?globalThis:m||self,b(m.LightCodeEditor={}))})(this,(function(m){"use strict";class b{constructor(t=""){this._lines=[],this._version=0,this.setText(t)}getLine(t){return this._lines[t]||""}getLines(){return[...this._lines]}getLineCount(){return this._lines.length}getText(){return this._lines.join(`
|
|
2
|
+
`)}setText(t){this._lines=t.split(`
|
|
3
|
+
`),this._version++}getTextInRange(t){if(t.start.line===t.end.line)return this.getLine(t.start.line).substring(t.start.column,t.end.column);const e=[];e.push(this.getLine(t.start.line).substring(t.start.column));for(let s=t.start.line+1;s<t.end.line;s++)e.push(this.getLine(s));return t.end.line<this.getLineCount()&&e.push(this.getLine(t.end.line).substring(0,t.end.column)),e.join(`
|
|
4
|
+
`)}replaceRange(t,e){const s=this.getTextInRange(t);if(t.start.line===t.end.line){const i=this.getLine(t.start.line),n=i.substring(0,t.start.column)+e+i.substring(t.end.column);this._lines[t.start.line]=n}else{const i=this.getLine(t.start.line),n=this.getLine(t.end.line),o=i.substring(0,t.start.column)+e,h=n.substring(t.end.column),r=e.split(`
|
|
5
|
+
`);r[0]=o+r[0],r[r.length-1]=r[r.length-1]+h,this._lines.splice(t.start.line,t.end.line-t.start.line+1,...r)}return this._version++,{range:t,text:e,oldText:s}}insertText(t,e){const s={start:t,end:t};return this.replaceRange(s,e)}deleteRange(t){return this.replaceRange(t,"")}positionToOffset(t){let e=0;for(let s=0;s<t.line;s++)e+=this.getLine(s).length+1;return e+=t.column,e}offsetToPosition(t){let e=t;for(let s=0;s<this.getLineCount();s++){const i=this.getLine(s).length;if(e<=i)return{line:s,column:e};e-=i+1}return{line:this.getLineCount()-1,column:this.getLine(this.getLineCount()-1).length}}isValidPosition(t){return!(t.line<0||t.line>=this.getLineCount()||t.column<0||t.column>this.getLine(t.line).length)}isValidRange(t){return this.isValidPosition(t.start)&&this.isValidPosition(t.end)}getVersion(){return this._version}clone(){const t=new b;return t._lines=[...this._lines],t._version=this._version,t}}class O{constructor(t){this.gutterWidth=50,this.lineHeight=21,this.container=t,this.createDOM()}createDOM(){this.container.innerHTML="";const t=document.createElement("div");this.editorContainer=t,t.style.cssText=`
|
|
6
6
|
position: relative;
|
|
7
7
|
display: flex;
|
|
8
8
|
width: 100%;
|
|
@@ -12,29 +12,29 @@
|
|
|
12
12
|
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
13
13
|
font-size: 14px;
|
|
14
14
|
line-height: ${this.lineHeight}px;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
/* make the outer container the single scrollable element so gutter and content scroll together */
|
|
16
|
+
overflow: auto;
|
|
17
|
+
`,this.lineNumbersElement=document.createElement("div"),this.lineNumbersElement.setAttribute("data-editor-gutter","true"),this.lineNumbersElement.style.cssText=`
|
|
18
|
+
display: table-cell;
|
|
19
|
+
vertical-align: top;
|
|
20
20
|
width: ${this.gutterWidth}px;
|
|
21
21
|
background: var(--editor-gutter-background, #252526);
|
|
22
22
|
color: var(--editor-gutter-foreground, #858585);
|
|
23
|
-
padding: 0;
|
|
23
|
+
padding: 0 8px 0 0;
|
|
24
24
|
text-align: right;
|
|
25
25
|
border-right: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
26
26
|
user-select: none;
|
|
27
|
-
overflow: hidden;
|
|
28
27
|
z-index: 1;
|
|
29
28
|
`,this.contentElement=document.createElement("div"),this.contentElement.style.cssText=`
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
display: table-cell;
|
|
30
|
+
vertical-align: top;
|
|
31
|
+
padding: 0 12px;
|
|
32
32
|
background: transparent;
|
|
33
33
|
border: none;
|
|
34
34
|
outline: none;
|
|
35
35
|
white-space: pre;
|
|
36
36
|
overflow-x: auto;
|
|
37
|
-
overflow-y:
|
|
37
|
+
overflow-y: visible;
|
|
38
38
|
min-height: 400px;
|
|
39
39
|
font-family: inherit;
|
|
40
40
|
font-size: inherit;
|
|
@@ -42,32 +42,17 @@
|
|
|
42
42
|
color: inherit;
|
|
43
43
|
tab-size: 2;
|
|
44
44
|
-moz-tab-size: 2;
|
|
45
|
-
`,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1,e.appendChild(this.lineNumbersElement),e.appendChild(this.contentElement),this.container.appendChild(
|
|
46
|
-
`).length;this.updateLineNumbers(
|
|
47
|
-
`);return{line:
|
|
48
|
-
`)
|
|
49
|
-
`),
|
|
50
|
-
`)
|
|
51
|
-
`);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
width: 50px;
|
|
57
|
-
background: var(--editor-gutter-background, #252526);
|
|
58
|
-
color: var(--editor-gutter-foreground, #858585);
|
|
59
|
-
font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
|
|
60
|
-
font-size: 14px;
|
|
61
|
-
line-height: 21px;
|
|
62
|
-
padding: 0;
|
|
63
|
-
text-align: right;
|
|
64
|
-
border-right: 1px solid var(--editor-gutter-border, #3e3e42);
|
|
65
|
-
user-select: none;
|
|
66
|
-
overflow: hidden;
|
|
67
|
-
z-index: 1;
|
|
68
|
-
pointer-events: none;
|
|
69
|
-
`;const n=e.getContentElement();n&&n.parentNode&&(n.parentNode.insertBefore(this.lineNumbersElement,n),n.style.marginLeft="60px")}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const e=this.editor.getValue().split(`
|
|
70
|
-
`).length,t=Array.from({length:Math.max(e,20)},(n,i)=>i+1);this.lineNumbersElement.innerHTML=t.map(n=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${n}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const e=this.editor.getView().getContentElement();e&&(e.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement&&this.lineNumbersElement.parentNode&&this.lineNumbersElement.parentNode.removeChild(this.lineNumbersElement),this.lineNumbersElement=null,this.editor=null}}class E{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(e){this.editor=e,e.registerCommand("setTheme",t=>{this.setTheme(t)}),e.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(e){this.editor&&(this.currentTheme=e,this.editor.setTheme(e))}toggleTheme(){const e=this.currentTheme==="dark"?"light":"dark";this.setTheme(e)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class w{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(e){this.editor=e,e.registerCommand("setReadOnly",t=>{this.setReadOnly(t)}),e.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),e.on("keydown",t=>{if(t.ctrlKey&&t.key==="r")return t.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(e){this.editor&&(this.isReadOnly=e,this.editor.setReadOnly(e))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class k{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(e){this.editor=e,e.registerCommand("find",()=>{this.showSearch()}),e.registerCommand("findNext",()=>{this.findNext()}),e.registerCommand("findPrev",()=>{this.findPrev()}),e.registerCommand("replace",()=>{this.showReplace()}),e.registerCommand("replaceAll",(t,n)=>{this.replaceAll(t,n)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const e=this.searchUI.querySelector("input");e&&(e.focus(),e.select())}}showReplace(){this.showSearch();const e=this.searchUI?.querySelector(".search-replace-input");e&&(e.style.display="block",e.focus());const t=this.searchUI?.querySelector(".search-status");t&&(t.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const e=document.querySelector(".rte-source-editor-modal");if(!e)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
|
|
45
|
+
`,this.contentElement.contentEditable="true",this.contentElement.spellcheck=!1;const e=document.createElement("div");e.setAttribute("data-editora-editor","true"),e.style.cssText="display: table; table-layout: fixed; width: 100%; height: 100%;",e.appendChild(this.lineNumbersElement),e.appendChild(this.contentElement),t.appendChild(e),this.container.appendChild(t),this.updateLineNumbers(1)}updateLineNumbers(t){const e=Math.max(t,20),s=Array.from({length:e},(i,n)=>n+1);this.lineNumbersElement.innerHTML=s.map(i=>`<div style="height: ${this.lineHeight}px; line-height: ${this.lineHeight}px; padding-right: 12px;">${i}</div>`).join("")}getContentElement(){return this.contentElement}getLineNumbersElement(){return this.lineNumbersElement}getText(){return this.contentElement.textContent||""}setText(t){this.contentElement.textContent=t;const e=t.split(`
|
|
46
|
+
`).length;this.updateLineNumbers(e)}setHTML(t){const e=/<|>/.test(t),s=/<span\b/i.test(t),i=/<[^>]+>/.test(t);e&&s?this.contentElement.innerHTML=t:i&&!e?this.contentElement.textContent=t:this.contentElement.innerHTML=t;const o=(this.contentElement.textContent||"").split(`
|
|
47
|
+
`).length;this.updateLineNumbers(o)}getCursorPosition(){const t=window.getSelection();if(!t||t.rangeCount===0)return{line:0,column:0};const e=t.getRangeAt(0),s=e.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(e.endContainer,e.endOffset);const n=s.toString().split(`
|
|
48
|
+
`);return{line:n.length-1,column:n[n.length-1].length}}setCursorPosition(t){const s=this.getText().split(`
|
|
49
|
+
`),i=Math.min(t.line,s.length-1),n=Math.min(t.column,s[i]?.length||0);let o=0;for(let a=0;a<i;a++)o+=s[a].length+1;o+=n;const h=document.createRange(),r=window.getSelection();let l=0,c=null,d=0;const f=document.createTreeWalker(this.contentElement,NodeFilter.SHOW_TEXT,null);let g;for(;g=f.nextNode();){const a=g.textContent?.length||0;if(l+a>=o){c=g,d=o-l;break}l+=a}if(c)try{h.setStart(c,d),h.setEnd(c,d),r?.removeAllRanges(),r?.addRange(h)}catch(a){console.warn("Could not set cursor position:",a)}}getSelectionRange(){const t=window.getSelection();if(!t||t.rangeCount===0||t.isCollapsed)return;const e=t.getRangeAt(0),s=e.cloneRange();s.selectNodeContents(this.contentElement),s.setEnd(e.startContainer,e.startOffset);const n=s.toString().split(`
|
|
50
|
+
`),o=e.cloneRange();o.selectNodeContents(this.contentElement),o.setEnd(e.endContainer,e.endOffset);const r=o.toString().split(`
|
|
51
|
+
`);return{start:{line:n.length-1,column:n[n.length-1].length},end:{line:r.length-1,column:r[r.length-1].length}}}setSelectionRange(t){this.setCursorPosition(t.start)}focus(){this.contentElement.focus()}blur(){this.contentElement.blur()}setReadOnly(t){this.contentElement.contentEditable=t?"false":"true"}applyTheme(t){Object.entries(t).forEach(([e,s])=>{this.container.style.setProperty(`--${e}`,s)})}scrollToPosition(t){const e=this.lineNumbersElement.children[t.line];e&&e.scrollIntoView({block:"center",behavior:"smooth"})}getScrollTop(){return this.editorContainer.scrollTop}setScrollTop(t){this.editorContainer.scrollTop=t}destroy(){this.container&&this.container.parentNode&&this.container.parentNode.removeChild(this.container),this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=void 0)}}class k{constructor(t,e={}){this.extensions=new Map,this.commands=new Map,this.eventListeners=new Map,this.folds=[],this.currentTheme="default",this.isDestroyed=!1,this.undoStack=[],this.redoStack=[],this.suppressHistory=!1,this.expectingProgrammaticCursor=!1,this.config={value:"",theme:"default",readOnly:!1,tabSize:2,lineWrapping:!1,lineNumbers:!0,...e},this.textModel=new b(this.config.value),this.view=new O(t),this.setupEventHandlers(),this.config.extensions&&this.config.extensions.forEach(s=>this.addExtension(s)),this.setTheme(this.config.theme),this.view.setReadOnly(this.config.readOnly||!1),this.renderTextWithHighlight(this.textModel.getText()),this.registerBuiltInCommands()}getTextModel(){return this.textModel}getView(){return this.view}getConfig(){return{...this.config}}registerBuiltInCommands(){this.registerCommand("undo",()=>this.undo()),this.registerCommand("redo",()=>this.redo()),this.registerCommand("insertTab",()=>this.insertTab()),this.registerCommand("save",()=>{this.emit("save")})}getKeymapExtension(){return this.extensions.get("keymap")}setupEventHandlers(){const t=this.view.getContentElement();t.addEventListener("input",()=>{const e=this.view.getText(),s=this.textModel.getText();if(e!==s){if(!this.suppressHistory){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:s,cursorOffset:n,anchorOffset:h,focusOffset:r}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}this.textModel.setText(e),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:e,oldText:s}])}}),t.addEventListener("selectionchange",()=>{const e=this.getCursor(),s=this.getSelection();this.emit("cursor",e),s&&this.emit("selection",s)}),t.addEventListener("keydown",e=>{if(this.emit("keydown",e),e.key==="Tab"){this.config.readOnly||this.insertTab(),e.preventDefault(),e.stopPropagation();return}if(e.key==="Enter"){if(!this.config.readOnly){const s=window.getSelection();if(s&&s.rangeCount>0){const i=this.getCursor().position,n=this.textModel.positionToOffset(i),o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.suppressHistory||(this.undoStack.push({text:this.textModel.getText(),cursorOffset:n,anchorOffset:h,focusOffset:r}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0);const l=s.getRangeAt(0);l.deleteContents();const c=document.createTextNode(`
|
|
52
|
+
`);l.insertNode(c),l.setStartAfter(c),l.collapse(!0),s.removeAllRanges(),s.addRange(l);const d=this.getCursor().position,f=this.textModel.positionToOffset(d),g=this.getSelection();let a,u;g&&(a=this.textModel.positionToOffset(g.start),u=this.textModel.positionToOffset(g.end));const p=this.view.getText();this.textModel.setText(p),this.highlightTimeout&&clearTimeout(this.highlightTimeout),this.highlightTimeout=setTimeout(()=>{this.renderTextWithHighlight(this.textModel.getText(),!1),requestAnimationFrame(()=>{try{if(g&&(a!==void 0||u!==void 0)){const x=a!==void 0?a:f,w=u!==void 0?u:f,T=Math.min(x,w),L=Math.max(x,w),S=this.textModel.offsetToPosition(T),C=this.textModel.offsetToPosition(L);this.setSelection({start:S,end:C})}else{const x=this.textModel.offsetToPosition(f);this.setCursor(x)}}catch{}}),this.highlightTimeout=null},300),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:this.getValue(),oldText:""}])}}e.preventDefault(),e.stopPropagation();return}for(const s of this.extensions.values())if(s.onKeyDown&&s.onKeyDown(e)===!1){e.preventDefault(),e.stopPropagation();return}}),t.addEventListener("mousedown",e=>{this.emit("mousedown",e);for(const s of this.extensions.values())if(s.onMouseDown&&s.onMouseDown(e)===!1){e.preventDefault(),e.stopPropagation();return}}),t.addEventListener("focus",()=>{this.emit("focus")}),t.addEventListener("blur",()=>{this.emit("blur")})}updateLineNumbers(){const t=this.textModel.getLineCount();this.view.updateLineNumbers(t)}getFullRange(){return{start:{line:0,column:0},end:{line:this.textModel.getLineCount()-1,column:this.textModel.getLine(this.textModel.getLineCount()-1).length}}}emit(t,...e){const s=this.eventListeners.get(t);s&&s.forEach(i=>i(...e))}getValue(){return this.textModel.getText()}setValue(t){const e=this.textModel.getText();this.textModel.setText(t),this.renderTextWithHighlight(t,!1),this.updateLineNumbers(),this.emit("change",[{range:this.getFullRange(),text:t,oldText:e}])}getState(){return{text:this.getValue(),cursor:this.getCursor(),selection:this.getSelection(),readOnly:this.config.readOnly||!1,theme:this.currentTheme}}getCursor(){const t=this.view.getCursorPosition();return{position:t,anchor:t}}setCursor(t){this.view.setCursorPosition(t),this.emit("cursor",this.getCursor())}getSelection(){return this.view.getSelectionRange()}setSelection(t){this.view.setSelectionRange(t),this.emit("selection",t)}setTheme(t){this.currentTheme=t;const e={"editor-background":t==="dark"?"#1e1e1e":"#ffffff","editor-foreground":t==="dark"?"#f8f9fa":"#1a1a1a","editor-gutter-background":t==="dark"?"#252526":"#f8f9fa","editor-gutter-foreground":t==="dark"?"#858585":"#666666","editor-gutter-border":t==="dark"?"#3e3e42":"#e1e5e9"};this.view.applyTheme(e);const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.setTheme=="function")try{s.setTheme(t==="dark"?"dark":"light"),this.renderTextWithHighlight(this.textModel.getText())}catch(i){console.warn("Error applying theme to syntax-highlighting extension",i)}}setReadOnly(t){this.config.readOnly=t,this.view.setReadOnly(t)}addExtension(t){if(this.extensions.has(t.name))throw new Error(`Extension '${t.name}' already exists`);this.extensions.set(t.name,t),t.setup(this),t.name==="syntax-highlighting"&&typeof t.highlightHTML=="function"&&this.renderTextWithHighlight(this.textModel.getText())}removeExtension(t){const e=this.extensions.get(t);e&&e.destroy&&e.destroy(),this.extensions.delete(t)}executeCommand(t,...e){const s=this.commands.get(t);s?s(this,...e):console.warn(`Command '${t}' not found`)}registerCommand(t,e){this.commands.set(t,e)}search(t,e={}){const s={caseSensitive:!1,regex:!1,...e},i=[],n=this.getValue();n.split(`
|
|
53
|
+
`);let o=s.caseSensitive?n:n.toLowerCase(),h=s.caseSensitive?t:t.toLowerCase();if(s.regex){const r=new RegExp(h,s.caseSensitive?"g":"gi");let l;for(;(l=r.exec(o))!==null;){const c=this.textModel.offsetToPosition(l.index),d=this.textModel.offsetToPosition(l.index+l[0].length);i.push({range:{start:c,end:d},match:l[0]})}}else{let r=0,l=o.indexOf(h,r);for(;l!==-1;){const c=l+t.length,d=this.textModel.offsetToPosition(l),f=this.textModel.offsetToPosition(c);i.push({range:{start:d,end:f},match:n.substring(l,c)}),r=c,l=o.indexOf(h,r)}}return i}replace(t,e){const s=this.getValue();if(!this.suppressHistory){const n=this.getCursor().position,o=this.textModel.positionToOffset(n),h=this.getSelection();let r,l;h&&(r=this.textModel.positionToOffset(h.start),l=this.textModel.positionToOffset(h.end)),this.undoStack.push({text:s,cursorOffset:o,anchorOffset:r,focusOffset:l}),this.undoStack.length>100&&this.undoStack.shift(),this.redoStack.length=0}const i=this.textModel.replaceRange(t,e);this.renderTextWithHighlight(this.getValue(),!1),this.emit("change",[i])}replaceAll(t,e,s={}){const i=this.search(t,s);let n=0;for(let o=i.length-1;o>=0;o--)this.replace(i[o].range,e),n++;return n}fold(t){const e={start:t.start,end:t.end,collapsed:!0,level:0};this.folds.push(e)}unfold(t){this.folds=this.folds.filter(e=>!(e.start.line===t.start.line&&e.end.line===t.end.line))}getFolds(){return[...this.folds]}focus(){this.view.focus()}blur(){this.view.blur()}renderTextWithHighlight(t,e=!0){const s=this.extensions.get("syntax-highlighting");if(s&&typeof s.highlightHTML=="function")try{const i=!e&&!this.expectingProgrammaticCursor;let n,o,h,r;if(e||i){n=this.getSelection();const c=this.getCursor().position;o=this.textModel.positionToOffset(c),n&&(h=this.textModel.positionToOffset(n.start),r=this.textModel.positionToOffset(n.end))}const l=s.highlightHTML(t);typeof this.view.setHighlightHTML=="function"?this.view.setHighlightHTML(l):this.view.setHTML(l),(e||i)&&requestAnimationFrame(()=>{try{if(n&&(h!==void 0||r!==void 0)){const c=h!==void 0?h:o,d=r!==void 0?r:o,f=Math.min(c,d),g=Math.max(c,d),a=this.textModel.offsetToPosition(f),u=this.textModel.offsetToPosition(g);this.view.setSelectionRange({start:a,end:u})}else if(o!==void 0){const c=this.textModel.offsetToPosition(o);this.view.setCursorPosition(c)}}catch{}});return}catch(i){console.warn("Syntax highlighting failed, falling back to plain text",i)}this.view.setText(t)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;for(const t of this.extensions.values())t.destroy&&t.destroy();this.extensions.clear(),this.view.destroy(),this.commands.clear(),this.eventListeners.clear()}}undo(){if(this.undoStack.length===0)return;const t=this.undoStack.pop(),e={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.redoStack.push(e);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof t=="string"?s=t:(s=t.text,i=t.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof t!="string"&&(t.anchorOffset!==void 0||t.focusOffset!==void 0)){const n=t.anchorOffset!==void 0?t.anchorOffset:i,o=t.focusOffset!==void 0?t.focusOffset:i,h=Math.min(n,o),r=Math.max(n,o),l=this.textModel.offsetToPosition(h),c=this.textModel.offsetToPosition(r);this.setSelection({start:l,end:c})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}redo(){if(this.redoStack.length===0)return;const t=this.redoStack.pop(),e={text:this.getValue(),cursorOffset:this.textModel.positionToOffset(this.getCursor().position)};this.undoStack.push(e);try{this.suppressHistory=!0,this.expectingProgrammaticCursor=!0;let s,i;typeof t=="string"?s=t:(s=t.text,i=t.cursorOffset),this.setValue(s),requestAnimationFrame(()=>{try{if(i!=null)if(typeof t!="string"&&(t.anchorOffset!==void 0||t.focusOffset!==void 0)){const n=t.anchorOffset!==void 0?t.anchorOffset:i,o=t.focusOffset!==void 0?t.focusOffset:i,h=Math.min(n,o),r=Math.max(n,o),l=this.textModel.offsetToPosition(h),c=this.textModel.offsetToPosition(r);this.setSelection({start:l,end:c})}else{const n=this.textModel.offsetToPosition(i);this.setCursor(n)}}catch{}}),setTimeout(()=>{this.expectingProgrammaticCursor=!1},30)}finally{this.suppressHistory=!1}}insertTab(){if(this.config.readOnly)return;const t=this.getCursor().position,e=this.textModel.positionToOffset(t),s=" ".repeat(this.config.tabSize||2),i=this.textModel.insertText(t,s),n=this.textModel.offsetToPosition(this.textModel.positionToOffset(t)+s.length);if(!this.suppressHistory){const o=this.getSelection();let h,r;o&&(h=this.textModel.positionToOffset(o.start),r=this.textModel.positionToOffset(o.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:h,focusOffset:r}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(n),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[i])}insertNewLine(){if(this.config.readOnly)return;const t=this.getCursor().position,e=this.textModel.positionToOffset(t),s=this.textModel.insertText(t,`
|
|
54
|
+
`),i=this.textModel.offsetToPosition(this.textModel.positionToOffset(t)+1);if(!this.suppressHistory){const n=this.getSelection();let o,h;n&&(o=this.textModel.positionToOffset(n.start),h=this.textModel.positionToOffset(n.end)),this.undoStack.push({text:this.getValue(),cursorOffset:e,anchorOffset:o,focusOffset:h}),this.redoStack.length=0}this.expectingProgrammaticCursor=!0,this.renderTextWithHighlight(this.getValue(),!1),this.setCursor(i),setTimeout(()=>{this.expectingProgrammaticCursor=!1},20),this.emit("change",[s])}on(t,e){this.eventListeners.has(t)||this.eventListeners.set(t,[]),this.eventListeners.get(t).push(e)}off(t,e){if(!this.eventListeners.has(t))return;const s=this.eventListeners.get(t);if(e){const i=s.indexOf(e);i!==-1&&s.splice(i,1)}else s.length=0}}class E{constructor(t){this.name="keymap",this.editor=null,this.keymap={},this.isMac=navigator.platform.toUpperCase().indexOf("MAC")>=0,this.keymap=t||this.getDefaultKeymap()}setup(t){this.editor=t}handleKeyDown(t){if(!this.editor)return;const e=this.findMatchingBinding(t);if(e)return this.editor.executeCommand(e.command),t.preventDefault(),t.stopPropagation(),!1}findMatchingBinding(t){const{key:e,ctrlKey:s,altKey:i,shiftKey:n,metaKey:o}=t,h=String(e).toLowerCase(),r=this.keymap[h];if(!r)return null;for(const l of r){const c=l.ctrlKey===void 0||l.ctrlKey===s,d=l.altKey===void 0||l.altKey===i,f=l.shiftKey===void 0||l.shiftKey===n,g=l.metaKey===void 0||l.metaKey===o;if(c&&d&&f&&g)return l}return null}onKeyDown(t){return this.handleKeyDown(t)}getDefaultKeymap(){const t={};return this.addBinding(t,"f",{ctrlKey:!this.isMac,metaKey:this.isMac},"find"),this.addBinding(t,"h",{ctrlKey:!this.isMac,metaKey:this.isMac},"replace"),this.addBinding(t,"f3",{},"findNext"),this.addBinding(t,"f3",{shiftKey:!0},"findPrev"),this.addBinding(t,"g",{ctrlKey:!this.isMac,metaKey:this.isMac},"findNext"),this.addBinding(t,"[",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"fold"),this.addBinding(t,"]",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"unfold"),this.addBinding(t,"s",{ctrlKey:!0},"save"),this.addBinding(t,"s",{metaKey:!0},"save"),this.addBinding(t,"z",{ctrlKey:!0},"undo"),this.addBinding(t,"z",{metaKey:!0},"undo"),this.addBinding(t,"y",{ctrlKey:!0},"redo"),this.addBinding(t,"y",{metaKey:!0},"redo"),this.addBinding(t,"z",{ctrlKey:!0,shiftKey:!0},"redo"),this.addBinding(t,"z",{metaKey:!0,shiftKey:!0},"redo"),this.addBinding(t,"tab",{},"insertTab"),this.addBinding(t,"t",{ctrlKey:!this.isMac,metaKey:this.isMac,shiftKey:!0},"toggleTheme"),t}addBinding(t,e,s,i){const n=e.toLowerCase();t[n]||(t[n]=[]),t[n].push({key:n,command:i,...s})}setKeymap(t){this.keymap={...t}}addKeyBinding(t){const e=t.key.toLowerCase();this.keymap[e]||(this.keymap[e]=[]),this.keymap[e]=this.keymap[e].filter(s=>s.command!==t.command),this.keymap[e].push({...t,key:e})}removeKeyBinding(t,e){const s=t.toLowerCase();e?this.keymap[s]&&(this.keymap[s]=this.keymap[s].filter(i=>i.command!==e),this.keymap[s].length===0&&delete this.keymap[s]):delete this.keymap[s]}getKeymap(){return{...this.keymap}}getBindingsForCommand(t){const e=[];for(const s in this.keymap)for(const i of this.keymap[s])i.command===t&&e.push({...i});return e}getPlatformInfo(){return{isMac:this.isMac,platform:navigator.platform}}destroy(){this.keymap={},this.editor=null}}class ${constructor(){this.name="transaction",this.transactions=[]}setup(t){t.on("change",e=>{const s={changes:[e],selection:t.getSelection(),effects:[],annotations:[]};this.transactions.push(s)})}getTransactions(){return this.transactions}destroy(){this.transactions=[]}}class H{constructor(){this.name="line-numbers",this.editor=null,this.lineNumbersElement=null,this.isEnabled=!0}setup(t){this.editor=t,this.createLineNumbers(),t.registerCommand("toggleLineNumbers",()=>{this.toggle()}),t.on("change",()=>{this.updateLineNumbers()}),this.updateLineNumbers()}createLineNumbers(){if(!this.editor)return;const e=this.editor.getView().getLineNumbersElement();e&&(this.lineNumbersElement=e)}updateLineNumbers(){if(!this.lineNumbersElement||!this.editor||!this.isEnabled)return;const t=this.editor.getValue().split(`
|
|
55
|
+
`).length,e=Array.from({length:Math.max(t,20)},(s,i)=>i+1);this.lineNumbersElement.innerHTML=e.map(s=>`<div style="height: 21px; line-height: 21px; padding-right: 12px;">${s}</div>`).join("")}toggle(){this.isEnabled=!this.isEnabled,this.lineNumbersElement&&(this.lineNumbersElement.style.display=this.isEnabled?"block":"none");const t=this.editor.getView().getContentElement();t&&(t.style.marginLeft=this.isEnabled?"60px":"0"),this.updateLineNumbers()}destroy(){this.lineNumbersElement=null,this.editor=null}}class R{constructor(){this.name="theme",this.editor=null,this.currentTheme="dark"}setup(t){this.editor=t,t.registerCommand("setTheme",e=>{this.setTheme(e)}),t.registerCommand("toggleTheme",()=>{this.toggleTheme()}),this.setTheme(this.currentTheme)}setTheme(t){this.editor&&(this.currentTheme=t,this.editor.setTheme(t))}toggleTheme(){const t=this.currentTheme==="dark"?"light":"dark";this.setTheme(t)}getCurrentTheme(){return this.currentTheme}destroy(){this.editor=null}}class I{constructor(){this.name="read-only",this.editor=null,this.isReadOnly=!1}setup(t){this.editor=t,t.registerCommand("setReadOnly",e=>{this.setReadOnly(e)}),t.registerCommand("toggleReadOnly",()=>{this.toggleReadOnly()}),t.on("keydown",e=>{if(e.ctrlKey&&e.key==="r")return e.preventDefault(),this.toggleReadOnly(),!1})}setReadOnly(t){this.editor&&(this.isReadOnly=t,this.editor.setReadOnly(t))}toggleReadOnly(){this.setReadOnly(!this.isReadOnly)}isCurrentlyReadOnly(){return this.isReadOnly}destroy(){this.editor=null}}class N{constructor(){this.name="search",this.editor=null,this.searchUI=null,this.isVisible=!1,this.currentResults=[],this.currentIndex=-1}setup(t){this.editor=t,t.registerCommand("find",()=>{this.showSearch()}),t.registerCommand("findNext",()=>{this.findNext()}),t.registerCommand("findPrev",()=>{this.findPrev()}),t.registerCommand("replace",()=>{this.showReplace()}),t.registerCommand("replaceAll",(e,s)=>{this.replaceAll(e,s)})}showSearch(){if(this.editor&&(this.searchUI||this.createSearchUI(),this.isVisible=!0,this.searchUI)){this.searchUI.style.display="block";const t=this.searchUI.querySelector("input");t&&(t.focus(),t.select())}}showReplace(){this.showSearch();const t=this.searchUI?.querySelector(".search-replace-input");t&&(t.style.display="block",t.focus());const e=this.searchUI?.querySelector(".search-status");e&&(e.textContent="Replace mode - Enter to replace, Shift+Enter to replace all")}hideSearch(){this.isVisible=!1,this.searchUI&&(this.searchUI.style.display="none"),this.clearHighlights()}createSearchUI(){if(!this.editor)return;const t=document.querySelector(".rte-source-editor-modal");if(!t)return;this.searchUI=document.createElement("div"),this.searchUI.style.cssText=`
|
|
71
56
|
position: absolute;
|
|
72
57
|
top: 10px;
|
|
73
58
|
right: 10px;
|
|
@@ -136,11 +121,11 @@
|
|
|
136
121
|
display: none;
|
|
137
122
|
margin-top: 4px;
|
|
138
123
|
" />
|
|
139
|
-
`;const
|
|
140
|
-
`),i=
|
|
141
|
-
`);let i=0;for(let
|
|
142
|
-
`);if(
|
|
143
|
-
`),i=
|
|
124
|
+
`;const e=this.searchUI.querySelector("input"),s=this.searchUI.querySelector(".search-replace-input"),i=this.searchUI.querySelector(".search-prev"),n=this.searchUI.querySelector(".search-next"),o=this.searchUI.querySelector(".search-close");e.addEventListener("input",()=>{this.performSearch(e.value)}),e.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.findPrev():this.findNext())}),s.addEventListener("keydown",h=>{h.key==="Enter"&&(h.preventDefault(),h.shiftKey?this.replaceAll(e.value,s.value):this.replaceCurrent(e.value,s.value))}),i.addEventListener("click",()=>this.findPrev()),n.addEventListener("click",()=>this.findNext()),o.addEventListener("click",()=>this.hideSearch()),t.appendChild(this.searchUI)}performSearch(t){if(!this.editor||!t.trim()){this.clearHighlights(),this.updateStatus("");return}const e=this.editor.getValue(),s=[];let i=e.toLowerCase().indexOf(t.toLowerCase());for(;i!==-1;){const n=this.getPositionFromOffset(e,i),o=this.getPositionFromOffset(e,i+t.length);s.push({range:{start:n,end:o},match:e.substring(i,i+t.length)}),i=e.toLowerCase().indexOf(t.toLowerCase(),i+1)}this.currentResults=s,this.currentIndex=this.currentResults.length>0?0:-1,this.updateHighlights(),this.updateStatus(`${this.currentResults.length} matches`)}getPositionFromOffset(t,e){const s=t.substring(0,e).split(`
|
|
125
|
+
`),i=s.length-1,n=s[s.length-1].length;return{line:i,column:n}}findNext(){this.currentResults.length!==0&&(this.currentIndex=(this.currentIndex+1)%this.currentResults.length,this.updateHighlights())}findPrev(){this.currentResults.length!==0&&(this.currentIndex=this.currentIndex<=0?this.currentResults.length-1:this.currentIndex-1,this.updateHighlights())}replaceCurrent(t,e){if(!this.editor||!t.trim()||this.currentIndex===-1)return;const s=this.currentResults[this.currentIndex];if(!s)return;const i=this.editor.getValue(),n=this.getOffsetFromPosition(i,s.range.start),o=i.substring(0,n),h=i.substring(n+t.length),r=o+e+h;this.editor.setValue(r),this.performSearch(t),this.updateStatus("Replaced current occurrence")}replaceAll(t,e){if(!this.editor||!t.trim())return;let s=this.editor.getValue(),i=0,n=s.toLowerCase().indexOf(t.toLowerCase());for(;n!==-1;)s=s.substring(0,n)+e+s.substring(n+t.length),i++,n=s.toLowerCase().indexOf(t.toLowerCase(),n+e.length);i>0&&(this.editor.setValue(s),this.updateStatus(`Replaced ${i} occurrences`))}getOffsetFromPosition(t,e){const s=t.split(`
|
|
126
|
+
`);let i=0;for(let n=0;n<e.line;n++)i+=s[n].length+1;return i+=e.column,i}updateHighlights(){this.clearHighlights(),!(this.currentResults.length===0||this.currentIndex===-1)&&(this.currentResults[this.currentIndex],this.updateStatus(`${this.currentResults.length} matches (showing ${this.currentIndex+1}/${this.currentResults.length})`))}clearHighlights(){}updateStatus(t){const e=this.searchUI?.querySelector(".search-status");e&&(e.textContent=t)}destroy(){this.searchUI&&this.searchUI.parentNode&&this.searchUI.parentNode.removeChild(this.searchUI),this.searchUI=null,this.editor=null}}class K{constructor(){this.name="bracket-matching",this.editor=null,this.bracketPairs={"(":")","[":"]","{":"}","<":">"},this.reverseBracketPairs={")":"(","]":"[","}":"{",">":"<"},this.currentMatch=null}setup(t){this.editor=t,t.on("cursor",()=>{this.updateBracketMatching()}),t.on("change",()=>{this.updateBracketMatching()})}updateBracketMatching(){if(!this.editor)return;const t=this.editor.getCursor(),e=this.editor.getValue();this.clearBracketHighlighting();const s=this.getBracketAtPosition(e,t.position);if(!s)return;const i=this.findMatchingBracket(e,s);i&&(this.currentMatch=i,this.highlightBrackets(i))}getBracketAtPosition(t,e){const s=t.split(`
|
|
127
|
+
`);if(e.line>=s.length)return null;const i=s[e.line];if(e.column>=i.length)return null;const n=i[e.column];return this.bracketPairs[n]||this.reverseBracketPairs[n]?{char:n,position:e}:null}findMatchingBracket(t,e){const s=t.split(`
|
|
128
|
+
`),i=e.position.line,n=e.position.column,o=e.char;return this.bracketPairs[o]?this.findClosingBracket(t,s,i,n,o):this.reverseBracketPairs[o]?this.findOpeningBracket(t,s,i,n,o):null}findClosingBracket(t,e,s,i,n){const o=this.bracketPairs[n];let h=0;for(let r=s;r<e.length;r++){const l=e[r],c=r===s?i:0;for(let d=c;d<l.length;d++){const f=l[d];if(f===n)h++;else if(f===o&&(h--,h===0))return{open:{start:{line:s,column:i},end:{line:s,column:i+1}},close:{start:{line:r,column:d},end:{line:r,column:d+1}},type:n}}}return null}findOpeningBracket(t,e,s,i,n){const o=this.reverseBracketPairs[n];let h=0;for(let r=s;r>=0;r--){const l=e[r],c=r===s?i:l.length-1;for(let d=c;d>=0;d--){const f=l[d];if(f===n)h++;else if(f===o&&(h--,h===0))return{open:{start:{line:r,column:d},end:{line:r,column:d+1}},close:{start:{line:s,column:i},end:{line:s,column:i+1}},type:o}}}return null}highlightBrackets(t){}clearBracketHighlighting(){this.currentMatch=null}getCurrentMatch(){return this.currentMatch}destroy(){this.clearBracketHighlighting(),this.editor=null}}class B{constructor(){this.name="code-folding",this.editor=null,this.foldIndicators=[],this.foldingUI=null}setup(t){this.editor=t,t.registerCommand("fold",()=>{this.foldAtCursor()}),t.registerCommand("unfold",()=>{this.unfoldAtCursor()}),t.registerCommand("foldAll",()=>{this.foldAll()}),t.registerCommand("unfoldAll",()=>{this.unfoldAll()}),t.on("change",()=>{this.updateFoldIndicators()}),this.createFoldingUI(),this.updateFoldIndicators()}createFoldingUI(){if(!this.editor)return;const t=document.querySelector(".rte-source-editor-modal");t&&(this.foldingUI=document.createElement("div"),this.foldingUI.style.cssText=`
|
|
144
129
|
position: absolute;
|
|
145
130
|
left: 40px;
|
|
146
131
|
top: 0;
|
|
@@ -148,11 +133,11 @@
|
|
|
148
133
|
width: 20px;
|
|
149
134
|
pointer-events: none;
|
|
150
135
|
z-index: 2;
|
|
151
|
-
`,
|
|
152
|
-
`);this.findFoldableLines(
|
|
136
|
+
`,t.appendChild(this.foldingUI))}updateFoldIndicators(){if(!this.editor||!this.foldingUI)return;this.foldingUI.innerHTML="",this.foldIndicators=[];const e=this.editor.getValue().split(`
|
|
137
|
+
`);this.findFoldableLines(e).forEach(i=>{this.createFoldIndicator(i)})}findFoldableLines(t){const e=[];for(let s=0;s<t.length;s++){const i=t[s].trim();(i.startsWith("{")||i.startsWith("function")||i.startsWith("class")||i.startsWith("if")||i.includes("=>")||i.startsWith("for")||i.startsWith("while")||i.startsWith("try"))&&e.push(s)}return e}createFoldIndicator(t){if(!this.foldingUI)return;const e=document.createElement("div");e.style.cssText=`
|
|
153
138
|
position: absolute;
|
|
154
139
|
left: 0;
|
|
155
|
-
top: ${
|
|
140
|
+
top: ${t*21}px;
|
|
156
141
|
width: 20px;
|
|
157
142
|
height: 21px;
|
|
158
143
|
display: flex;
|
|
@@ -163,4 +148,4 @@
|
|
|
163
148
|
color: var(--editor-gutter-foreground, #858585);
|
|
164
149
|
font-size: 10px;
|
|
165
150
|
user-select: none;
|
|
166
|
-
`,
|
|
151
|
+
`,e.innerHTML="▶",e.title="Code folding not yet implemented - click shows fold indicators",e.addEventListener("click",()=>{}),this.foldingUI.appendChild(e),this.foldIndicators.push(e)}foldAtCursor(){}unfoldAtCursor(){}foldAll(){}unfoldAll(){}destroy(){this.foldingUI&&this.foldingUI.parentNode&&this.foldingUI.parentNode.removeChild(this.foldingUI),this.foldingUI=null,this.foldIndicators=[],this.editor=null}}class V{constructor(){this.name="syntax-highlighting",this.editor=null,this.currentTheme="dark",this.currentLanguage=null,this.modes=new Map}setup(t){this.editor=t,this.registerMode("html",{name:"html",highlight:(e,s)=>this._highlightHTML(e,s)}),this.registerMode("javascript",{name:"javascript",highlight:(e,s)=>this._highlightJS(e,s)}),this.registerMode("typescript",{name:"typescript",highlight:(e,s)=>this._highlightJS(e,s)}),this.registerMode("php",{name:"php",highlight:(e,s)=>this._highlightPHP(e,s)})}setTheme(t){this.currentTheme=t}setLanguage(t){this.currentLanguage=t}registerMode(t,e){this.modes.set(t.toLowerCase(),e)}getSyntaxColors(){return this.currentTheme==="dark"?{tag:"#569cd6",comment:"#6a9955",attrName:"#9cdcfe",attrValue:"#ce9178",styleProp:"#c586c0",styleVal:"#dcdcaa",doctype:"#808080",text:"#d4d4d4",keyword:"#c586c0",string:"#ce9178",number:"#b5cea8",variable:"#9cdcfe"}:{tag:"#0000ff",comment:"#008000",attrName:"#001080",attrValue:"#a31515",styleProp:"#6a00a8",styleVal:"#804000",doctype:"#444444",text:"#000000",keyword:"#000080",string:"#a31515",number:"#0086b3",variable:"#001080"}}highlight(t,e){const s=this.getSyntaxColors(),i=(e||this.currentLanguage||"html").toLowerCase();return(this.modes.get(i)||this.modes.get("html")).highlight(t,s)}highlightHTML(t){return this.highlight(t,"html")}escapeHTML(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\"/g,""").replace(/'/g,"'")}unescapeEntitiesRepeated(t){let e=t||"";for(let s=0;s<5;s++){const i=e;if(e=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,'"').replace(/'/g,"'"),e===i)break}return e}_highlightHTML(t,e){const s=e,i=l=>this.escapeHTML(l);let n=i(t);const o=l=>{let c=l.replace(/"/g,'"').replace(/'/g,"'");return c=c.replace(/(\/\*[\s\S]*?\*\/)/g,`<span style="color: ${s.comment};">$1</span>`),c=c.replace(/([a-zA-Z-]+)(\s*:\s*)([^;{]+)(;?)/g,(d,f,g,a,u)=>{const p=String(a).trim(),x=i(p);return`<span style="color: ${s.styleProp};">${f}</span>${g}<span style="color: ${s.styleVal};">${x}</span>${u}`}),c},h=[];try{t.replace(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi,(l,c,d)=>(h.push({attrs:String(c||""),inner:String(d||"")}),l))}catch{}let r=0;return n=n.replace(/(<script\b([^&>]*)>)([\s\S]*?)(<\/script>)/gi,(l,c,d,f,g)=>{const a=h[r++]?.inner??this.unescapeEntitiesRepeated(f||"");(h[r-1]?.attrs||d||"").toLowerCase();const u=this._highlightJS(a,s);return`${c}${u}${g}`}),n=n.replace(/(<style\b[^&]*>)([\s\S]*?)(<\/style>)/gi,(l,c,d,f)=>{const g=o(d);return`${c}${g}${f}`}),n=n.replace(/(<!--[\s\S]*?-->)/g,`<span style="color: ${s.comment};">$1</span>`),n=n.replace(/(<!DOCTYPE[\s\S]*?>)/i,`<span style="color: ${s.doctype};">$1</span>`),n=n.replace(/(<\/?\s*)([^\s&>\/]+)([\s\S]*?)(\/?>)/g,(l,c,d,f,g)=>{const a=`<span style="color: ${s.tag};">${d}</span>`;let u=f;return u=u.replace(/([\w:-]+)(\s*=\s*)(("[\s\S]*?"|'[\s\S]*?'|[^\s&>]+))/g,(p,x,w,T)=>{const L=String(x).toLowerCase(),S=`<span style="color: ${s.attrName};">${x}</span>`;let C=T,v="";T.startsWith(""")&&T.endsWith(""")?(C=T.slice(6,-6),v="""):T.startsWith("'")&&T.endsWith("'")&&(C=T.slice(5,-5),v="'");let M=T;if(L==="style"){const P=C.replace(/([\w-]+)\s*:\s*([^;]+)(;?)/g,(z,U,F,_)=>`<span style="color: ${s.styleProp};">${U}</span>:<span style="color: ${s.styleVal};">${F.trim()}</span>${_}`);v?M=`${v}${P}${v}`:M=P,M=`<span style="color: ${s.attrValue};">${M}</span>`}else v&&(M=`${v}${C}${v}`),M=`<span style="color: ${s.attrValue};">${M}</span>`;return`${S}${w}${M}`}),`${c}${a}${u}${g}`}),n}_highlightJS(t,e){const s=this.unescapeEntitiesRepeated(t);this.escapeHTML(s);const i=[],n=g=>{let a="",u=g;do a=String.fromCharCode(97+u%26)+a,u=Math.floor(u/26)-1;while(u>=0);return a||"a"},o=g=>`\0${n(g)}\0`,h=g=>{const a=i.length;return i.push(g),o(a)};let r;const l=/(\/\*[\s\S]*?\*\/)|(\/\/[^\n\r]*)|("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|`(?:\\.|[^`\\])*`)/g;let c=0,d="";for(;r=l.exec(s);){const g=r.index;c<g&&(d+=this.escapeHTML(s.slice(c,g)));const a=r[0];/^\/\*/.test(a)||/^\/\//.test(a)?d+=h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`):d+=h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`),c=l.lastIndex}return c<s.length&&(d+=this.escapeHTML(s.slice(c))),d=d.replace(/\b(0x[0-9a-fA-F]+|\d+\.?\d*|\d*\.\d+)\b/g,(g,a,u)=>{const p=d[u-1]||"",x=d[u+g.length]||"";return p==="&"||p==="#"||x===";"||x==="#"?g:`<span style="color: ${e.number};">${g}</span>`}),d=d.replace(/\b(const|let|var|function|class|if|else|return|for|while|switch|case|break|import|from|export|extends|new|try|catch|finally|throw|await|async|interface|type)\b/g,`<span style="color: ${e.keyword};">$1</span>`),d.replace(/\u0000([a-z]+)\u0000/g,(g,a)=>{let u=0;for(let p=0;p<a.length;p++)u=u*26+(a.charCodeAt(p)-97+1);return u=u-1,i[u]||""})}_highlightPHP(t,e){const s=this.unescapeEntitiesRepeated(t);let i=this.escapeHTML(s);const n=[],o=a=>{let u="",p=a;do u=String.fromCharCode(97+p%26)+u,p=Math.floor(p/26)-1;while(p>=0);return u||"a"},h=a=>{const u=n.length;return n.push(a),`\0${o(u)}\0`},r=(a,u)=>{const p=i.indexOf(a);return p===-1?!1:(i=i.slice(0,p)+u+i.slice(p+a.length),!0)};let l;const c=/\/\*[\s\S]*?\*\//g,d=/\/\/[^\n\r]*/g,f=/\#([^\n\r]*)/g,g=/("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*')/g;for(;l=c.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=d.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=f.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.comment};">${this.escapeHTML(a)}</span>`))}for(;l=g.exec(s);){const a=l[0];r(this.escapeHTML(a),h(`<span style="color: ${e.string};">${this.escapeHTML(a)}</span>`))}return i=i.replace(/(\$[a-zA-Z_\x80-\xff][a-zA-Z0-9_\x80-\xff]*)/g,`<span style="color: ${e.variable};">$1</span>`),i=i.replace(/\b(echo|print|function|class|if|else|elseif|foreach|as|return|namespace|use|new|extends|public|protected|private|static)\b/g,`<span style="color: ${e.keyword};">$1</span>`),i=i.replace(/\u0000([a-z]+)\u0000/g,(a,u)=>{let p=0;for(let x=0;x<u.length;x++)p=p*26+(u.charCodeAt(x)-97+1);return p=p-1,n[p]||""}),i}shouldHighlight(t){return/<\/?[\w:-]+|<!--/.test(t)}destroy(){this.editor=null,this.modes.clear()}}function A(y,t){const e={...t};return e.extensions||(e.extensions=[]),e.extensions.some(n=>n.name==="keymap")||e.extensions.unshift(new E(e.keymap)),e.extensions.some(n=>n.name==="transaction")||e.extensions.unshift(new $),new k(y,e)}m.BracketMatchingExtension=K,m.CodeFoldingExtension=B,m.EditorCore=k,m.KeymapExtension=E,m.LineNumbersExtension=H,m.ReadOnlyExtension=I,m.SearchExtension=N,m.SyntaxHighlightingExtension=V,m.TextModel=b,m.ThemeExtension=R,m.View=O,m.createEditor=A,m.default=k,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}
|
|
1
|
+
.rte-light-editor{position:relative;width:100%;height:400px;border:1px solid #ccc;border-radius:4px;overflow:hidden;font-family:Monaco,Menlo,Ubuntu Mono,monospace;font-size:14px;line-height:21px}.rte-light-editor-content{position:relative;width:100%;height:100%;padding:8px;margin:0;border:none;outline:none;resize:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:auto;background:transparent}.rte-light-editor-gutter{position:absolute;left:0;top:0;bottom:0;width:50px;padding:8px 0;text-align:right;border-right:1px solid #e0e0e0;background:#f8f8f8;color:#999;font-size:12px;line-height:21px;-webkit-user-select:none;user-select:none;overflow:hidden}.rte-light-editor-gutter.dark{border-right-color:#3e3e3e;background:#1e1e1e;color:#666}.rte-syntax-highlight-overlay{position:absolute;inset:0 0 0 50px;pointer-events:none;font-family:inherit;font-size:inherit;line-height:inherit;white-space:pre-wrap;word-wrap:break-word;overflow:hidden;z-index:5;background:transparent;color:transparent}.syntax-html-tag{color:#569cd6!important}.syntax-html-comment{color:#6a9955!important}.syntax-html-attr-value{color:#ce9178!important}.dark .syntax-html-tag{color:#569cd6!important}.dark .syntax-html-comment{color:#6a9955!important}.dark .syntax-html-attr-value{color:#ce9178!important}.light .syntax-html-tag{color:#00f!important}.light .syntax-html-comment{color:green!important}.light .syntax-html-attr-value{color:#a31515!important}.rte-light-editor.dark{background:#1e1e1e;color:#d4d4d4;border-color:#3e3e3e}.rte-light-editor.dark .rte-light-editor-content{background:#1e1e1e;color:#d4d4d4}.rte-light-editor.light{background:#fff;color:#000;border-color:#e0e0e0}.rte-light-editor.light .rte-light-editor-content{background:#fff;color:#000}.rte-light-editor.readonly .rte-light-editor-content{cursor:not-allowed;opacity:.7}.rte-light-editor.readonly .rte-light-editor-content:after{content:"";position:absolute;inset:0;background:#ffffff1a;pointer-events:none}.rte-light-editor.focused{border-color:#007acc;box-shadow:0 0 0 2px #007acc33}.rte-light-editor-content::selection{background:#007acc33}.rte-light-editor.dark .rte-light-editor-content::selection{background:#007acc4d}.rte-light-editor-content::-webkit-scrollbar{width:12px;height:12px}.rte-light-editor-content::-webkit-scrollbar-track{background:#f1f1f1}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-track{background:#2d2d2d}.rte-light-editor-content::-webkit-scrollbar-thumb{background:#c1c1c1;border-radius:6px}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb{background:#555}.rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#a8a8a8}.rte-light-editor.dark .rte-light-editor-content::-webkit-scrollbar-thumb:hover{background:#666}.bracket-match{background:#007acc1a;border-radius:2px}.dark .bracket-match{background:#007acc33}.search-match{background:#ffff004d;border-radius:2px}.search-match.current{background:#ff09;border:1px solid #ffcc00}.fold-indicator{position:absolute;left:35px;width:12px;height:12px;cursor:pointer;opacity:.5;transition:opacity .2s}.fold-indicator:hover{opacity:1}.fold-indicator.expanded:before{content:"▼";font-size:10px;color:#666}.fold-indicator.collapsed:before{content:"▶";font-size:10px;color:#666}.dark .fold-indicator.expanded:before,.dark .fold-indicator.collapsed:before{color:#999}.editor-container{font-family:monospace;background-color:#1e1e1e;color:#d4d4d4;padding:10px;border:1px solid #333;border-radius:4px;overflow:auto}.editor-line{white-space:pre}.editor-line-number{display:inline-block;width:30px;text-align:right;margin-right:10px;color:#858585}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@editora/light-code-editor",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Lightweight, extensible code editor
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "Lightweight, extensible code editor for the web — syntax highlighting, line numbers, code folding, and a plugin-friendly API. Ideal for embedding in docs, demos, and web apps.",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Ajay Kumar <ajaykr089@gmail.com>"
|
|
7
7
|
],
|
|
@@ -25,11 +25,29 @@
|
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
27
27
|
"code-editor",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"typescript"
|
|
28
|
+
"lightweight-editor",
|
|
29
|
+
"syntax-highlighting",
|
|
30
|
+
"javascript-editor",
|
|
31
|
+
"typescript-editor",
|
|
32
|
+
"web-editor",
|
|
33
|
+
"code-playground",
|
|
34
|
+
"line-numbers",
|
|
35
|
+
"code-folding",
|
|
36
|
+
"plugin-friendly"
|
|
32
37
|
],
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/ajaykr089/Editora.git",
|
|
41
|
+
"directory": "packages/light-code-editor"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://github.com/ajaykr089/Editora#readme",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/ajaykr089/Editora/issues"
|
|
46
|
+
},
|
|
47
|
+
"style": "dist/light-code-editor.css",
|
|
48
|
+
"publishConfig": {
|
|
49
|
+
"access": "public"
|
|
50
|
+
},
|
|
33
51
|
"author": "Ajay Kumar <ajaykr089@gmail.com>",
|
|
34
52
|
"license": "MIT",
|
|
35
53
|
"devDependencies": {
|
|
@@ -37,5 +55,5 @@
|
|
|
37
55
|
"typescript": "^5.0.0",
|
|
38
56
|
"vite": "^7.3.1"
|
|
39
57
|
},
|
|
40
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "694494db58b809f0dcf24501696284faa1ab68a5"
|
|
41
59
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ajay Kumar
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|