From 4c2688bd76b4666db05017c8ddebed6d501cb0c0 Mon Sep 17 00:00:00 2001 From: moisseev Date: Fri, 27 Oct 2023 16:57:15 +0300 Subject: [WebUI] Update map editor CodeJar 3.7.0 -> 4.2.0 --- interface/js/app/config.js | 4 +++- interface/js/lib/codejar-linenumbers.min.js | 6 ++++++ interface/js/lib/codejar.min.js | 4 ++-- interface/js/lib/linenumbers.min.js | 5 ----- interface/js/main.js | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 interface/js/lib/codejar-linenumbers.min.js delete mode 100644 interface/js/lib/linenumbers.min.js (limited to 'interface/js') diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 8d979f1f2..b3f4e5661 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -181,7 +181,6 @@ define(["jquery", "codejar", "linenumbers", "prism"], mode = (new Blob([data[0].data]).size > 5120) ? "basic" : $("input[name=editorMode]:checked").val(); $("<" + editor[mode].elt + ' id="editor" class="' + editor[mode].class + '" data-id="' + item.map + '">' + - rspamd.escapeHTML(data[0].data) + "").appendTo("#modalBody"); if (editor[mode].codejar) { @@ -189,6 +188,9 @@ define(["jquery", "codejar", "linenumbers", "prism"], document.querySelector("#editor"), withLineNumbers((el) => Prism.highlightElement(el)) ); + jar.updateCode(data[0].data); + } else { + document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data); } var icon = "fa-edit"; diff --git a/interface/js/lib/codejar-linenumbers.min.js b/interface/js/lib/codejar-linenumbers.min.js new file mode 100644 index 000000000..e3ca168ce --- /dev/null +++ b/interface/js/lib/codejar-linenumbers.min.js @@ -0,0 +1,6 @@ +/*! + * codejar-linenumbers v1.0.0 (https://github.com/julianpoemp/codejar-linenumbers) + * Copyright (c) 2023, Julian Poemp, MIT + */ +function withLineNumbers(r,e={}){const d={class:"codejar-linenumbers",wrapClass:"codejar-wrap",width:"35px",backgroundColor:"rgba(128, 128, 128, 0.15)",color:"",...e};let l;return function(e){r(e),l||(l=init(e,d),e.addEventListener("scroll",()=>l.style.top=`-${e.scrollTop}px`));var t=(e.textContent||"").replace(/\n\n$/g,"\n").split("\n").length;let o="";for(let e=0;e{var e=T();n(u,e),b(e)},30);let C=!1;const N=e=>!O(e)&&!M(e)&&"Meta"!==e.key&&"Control"!==e.key&&"Alt"!==e.key&&!e.key.startsWith("Arrow"),a=d(e=>{N(e)&&(w(),C=!1)},300);e=(e,t)=>{r.push([e,t]),u.addEventListener(e,t)};function T(){var e=H();const t={start:0,end:0,dir:void 0};let{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:i}=e;if(n&&o)return n===u&&o===u?(t.start=0=r?"->":"<-"):(n.nodeType===Node.ELEMENT_NODE&&(e=p.createTextNode(""),n.insertBefore(e,n.childNodes[r]),n=e,r=0),o.nodeType===Node.ELEMENT_NODE&&(e=p.createTextNode(""),o.insertBefore(e,o.childNodes[i]),o=e,i=0),l(u,e=>{if(e===n&&e===o)return t.start+=r,t.end+=i,t.dir=r<=i?"->":"<-","stop";if(e===n){if(t.start+=r,t.dir)return"stop";t.dir="->"}else if(e===o){if(t.end+=i,t.dir)return"stop";t.dir="<-"}e.nodeType===Node.TEXT_NODE&&("->"!=t.dir&&(t.start+=e.nodeValue.length),"<-"!=t.dir)&&(t.end+=e.nodeValue.length)}),u.normalize()),t;throw"error1"}function b(n){var e,t,r=H();let o,i=0,s,a=0,d=(n.dir||(n.dir="->"),n.start<0&&(n.start=0),n.end<0&&(n.end=0),"<-"==n.dir&&({start:e,end:t}=n,n.start=t,n.end=e),0);l(u,e=>{var t;if(e.nodeType===Node.TEXT_NODE)return t=(e.nodeValue||"").length,d+t>n.start&&(o||(o=e,i=n.start-d),d+t>n.end)?(s=e,a=n.end-d,"stop"):void(d+=t)}),o||(o=u,i=u.childNodes.length),s||(s=u,a=u.childNodes.length),"<-"==n.dir&&([o,i,s,a]=[s,a,o,i]),r.setBaseAndExtent(o,i,s,a)}function E(){var e=H().getRangeAt(0),t=p.createRange();return t.selectNodeContents(u),t.setEnd(e.startContainer,e.startOffset),t.toString()}function m(){var e=H().getRangeAt(0),t=p.createRange();return t.selectNodeContents(u),t.setStart(e.endContainer,e.endOffset),t.toString()}function k(e){v&&"Enter"===e.key&&(_(e),e.stopPropagation(),""==m()?(S("\n "),(e=T()).start=--e.end,b(e)):S("\n"))}function w(){var e,t,n;i&&(e=u.innerHTML,t=T(),(n=h[g])&&n.html===e&&n.pos.start===t.start&&n.pos.end===t.end||(g++,h[g]={html:e,pos:t},h.splice(g+1),300/g,">").replace(/"/g,""").replace(/'/g,"'"),p.execCommand("insertHTML",!1,e)}function d(t,n){let r=0;return(...e)=>{clearTimeout(r),r=o.setTimeout(()=>t(...e),n)}}function A(e){let t=e.length-1;for(;0<=t&&"\n"!==e[t];)t--;let n=++t;for(;n{if(!e.defaultPrevented){if(y=D(),f.preserveIdent){var t=e;if("Enter"===t.key){var n=E(),r=m(),[o]=A(n);let e=o;f.indentOn.test(n)&&(e+=f.tab),0=h.length)&&g--,N(e))&&!C&&(w(),C=!0),v&&(!x(l=e)||"C"!==L(l))&&b(T())}}),e("keyup",e=>{e.defaultPrevented||e.isComposing||(y!==D()&&t(),a(e),s&&s(D()))}),e("focus",e=>{i=!0}),e("blur",e=>{i=!1}),e("paste",e=>{var t;w(),_(e=e),e=(e.originalEvent||e).clipboardData.getData("text/plain").replace(/\r/g,""),t=T(),S(e),n(u),b({start:Math.min(t.start,t.end)+e.length,end:Math.min(t.start,t.end)+e.length,dir:"<-"}),w(),s&&s(D())}),{updateOptions(e){Object.assign(f,e)},updateCode(e){u.textContent=e,n(u)},onUpdate(e){s=e},toString:D,save:T,restore:b,recordHistory:w,destroy(){for(var[e,t]of r)u.removeEventListener(e,t)}}} \ No newline at end of file +const globalWindow=window;function CodeJar(l,n,e={}){const c={tab:"\t",indentOn:/[({\[]$/,moveToNewLine:/^[)}\]]/,spellcheck:!1,catchTab:!0,preserveIdent:!0,addClosing:!0,history:!0,window:globalWindow,...e},o=c.window,f=o.document,r=[],u=[];let p=-1,a=!1,i=()=>{},h;l.setAttribute("contenteditable","plaintext-only"),l.setAttribute("spellcheck",c.spellcheck?"true":"false"),l.style.outline="none",l.style.overflowWrap="break-word",l.style.overflowY="auto",l.style.whiteSpace="pre-wrap";const d=(e,t)=>{n(e,t)};let g=!1;(g="plaintext-only"!==l.contentEditable?!0:g)&&l.setAttribute("contenteditable","true");const t=S(()=>{var e=v();d(l,e),T(e)},30);let y=!1;const N=e=>!O(e)&&!M(e)&&"Meta"!==e.key&&"Control"!==e.key&&"Alt"!==e.key&&!e.key.startsWith("Arrow"),s=S(e=>{N(e)&&(x(),y=!1)},300);e=(e,t)=>{r.push([e,t]),l.addEventListener(e,t)};function v(){var e=H();const t={start:0,end:0,dir:void 0};let{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:a}=e;if(n&&o)return n===l&&o===l?(t.start=0=r?"->":"<-"):(n.nodeType===Node.ELEMENT_NODE&&(e=f.createTextNode(""),n.insertBefore(e,n.childNodes[r]),n=e,r=0),o.nodeType===Node.ELEMENT_NODE&&(e=f.createTextNode(""),o.insertBefore(e,o.childNodes[a]),o=e,a=0),w(l,e=>{if(e===n&&e===o)return t.start+=r,t.end+=a,t.dir=r<=a?"->":"<-","stop";if(e===n){if(t.start+=r,t.dir)return"stop";t.dir="->"}else if(e===o){if(t.end+=a,t.dir)return"stop";t.dir="<-"}e.nodeType===Node.TEXT_NODE&&("->"!=t.dir&&(t.start+=e.nodeValue.length),"<-"!=t.dir)&&(t.end+=e.nodeValue.length)}),l.normalize()),t;throw"error1"}function T(n){var e=H();let r,o=0,a,i=0,d=(n.dir||(n.dir="->"),n.start<0&&(n.start=0),n.end<0&&(n.end=0),"<-"==n.dir&&({start:t,end:s}=n,n.start=s,n.end=t),0);w(l,e=>{var t;if(e.nodeType===Node.TEXT_NODE)return t=(e.nodeValue||"").length,d+t>n.start&&(r||(r=e,o=n.start-d),d+t>n.end)?(a=e,i=n.end-d,"stop"):void(d+=t)}),r||(r=l,o=l.childNodes.length),a||(a=l,i=l.childNodes.length),"<-"==n.dir&&([r,o,a,i]=[a,i,r,o]);var t,s=C(r),s=(s&&(t=f.createTextNode(""),s.parentNode?.insertBefore(t,s),r=t,o=0),C(a));s&&(t=f.createTextNode(""),s.parentNode?.insertBefore(t,s),a=t,i=0),e.setBaseAndExtent(r,o,a,i),l.normalize()}function C(e){for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE){var t=e;if("false"==t.getAttribute("contenteditable"))return t}e=e.parentNode}}function E(){var e=H().getRangeAt(0),t=f.createRange();return t.selectNodeContents(l),t.setEnd(e.startContainer,e.startOffset),t.toString()}function m(){var e=H().getRangeAt(0),t=f.createRange();return t.selectNodeContents(l),t.setStart(e.endContainer,e.endOffset),t.toString()}function b(e){g&&"Enter"===e.key&&(B(e),e.stopPropagation(),""==m()?(L("\n "),(e=v()).start=--e.end,T(e)):L("\n"))}function x(){var e,t,n;a&&(e=l.innerHTML,t=v(),(n=u[p])&&n.html===e&&n.pos.start===t.start&&n.pos.end===t.end||(p++,u[p]={html:e,pos:t},u.splice(p+1),300/g,">").replace(/"/g,""").replace(/'/g,"'"),f.execCommand("insertHTML",!1,e)}function S(t,n){let r=0;return(...e)=>{clearTimeout(r),r=o.setTimeout(()=>t(...e),n)}}function A(e){let t=e.length-1;for(;0<=t&&"\n"!==e[t];)t--;let n=++t;for(;n{if(!e.defaultPrevented){if(h=_(),c.preserveIdent){var t=e;if("Enter"===t.key){var n=E(),r=m(),[o]=A(n);let e=o;c.indentOn.test(n)&&(e+=c.tab),0=u.length)&&p--,N(e))&&!y&&(x(),y=!0),g&&(!k(i=e)||"C"!==D(i))&&T(v())}}),e("keyup",e=>{e.defaultPrevented||e.isComposing||(h!==_()&&t(),s(e),i(_()))}),e("focus",e=>{a=!0}),e("blur",e=>{a=!1}),e("paste",e=>{var t;x(),(e=e).defaultPrevented||(B(e),e=(e.originalEvent??e).clipboardData.getData("text/plain").replace(/\r\n?/g,"\n"),t=v(),L(e),d(l),T({start:Math.min(t.start,t.end)+e.length,end:Math.min(t.start,t.end)+e.length,dir:"<-"})),x(),i(_())}),e("cut",e=>{var t,n;x(),e=e,t=v(),n=H(),(e.originalEvent??e).clipboardData.setData("text/plain",n.toString()),f.execCommand("delete"),d(l),T({start:Math.min(t.start,t.end),end:Math.min(t.start,t.end),dir:"<-"}),B(e),x(),i(_())}),{updateOptions(e){Object.assign(c,e)},updateCode(e){l.textContent=e,d(l),i(e)},onUpdate(e){i=e},toString:_,save:v,restore:T,recordHistory:x,destroy(){for(var[e,t]of r)l.removeEventListener(e,t)}}} \ No newline at end of file diff --git a/interface/js/lib/linenumbers.min.js b/interface/js/lib/linenumbers.min.js deleted file mode 100644 index 0dd83d0d0..000000000 --- a/interface/js/lib/linenumbers.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/*! - * CodeJar 3.2.2 helper: lineNumbers (https://github.com/antonmedv/codejar) - * Copyright (c) 2020, Anton Medvedev, MIT - */ -function withLineNumbers(e,t={}){const o=Object.assign({class:"codejar-linenumbers",wrapClass:"codejar-wrap",width:"35px",backgroundColor:"rgba(128, 128, 128, 0.15)",color:""},t);let l;return function(t){e(t),l||(l=init(t,o),t.addEventListener("scroll",()=>l.style.top=`-${t.scrollTop}px`));const n=(t.textContent||"").replace(/\n+$/,"\n").split("\n").length+1;let s="";for(let e=1;e