aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js/lib/codejar.min.js
diff options
context:
space:
mode:
Diffstat (limited to 'interface/js/lib/codejar.min.js')
-rw-r--r--interface/js/lib/codejar.min.js6
1 files changed, 3 insertions, 3 deletions
diff --git a/interface/js/lib/codejar.min.js b/interface/js/lib/codejar.min.js
index 272e6ae72..a3bc42534 100644
--- a/interface/js/lib/codejar.min.js
+++ b/interface/js/lib/codejar.min.js
@@ -1,5 +1,5 @@
/*!
- * CodeJar 3.5.0 (https://github.com/antonmedv/codejar)
- * Copyright (c) 2020, Anton Medvedev, MIT
+ * CodeJar 3.6.0 (https://github.com/antonmedv/codejar)
+ * Copyright (c) 2020-2022, Anton Medvedev, MIT
*/
-const globalWindow=window;function CodeJar(t,e,n={}){const o=Object.assign({tab:"\t",indentOn:/{$/,spellcheck:!1,catchTab:!0,preserveIdent:!0,addClosing:!0,history:!0,window:globalWindow},n),r=o.window,s=r.document;let i,d,l=[],a=[],c=-1,f=!1;t.setAttribute("contenteditable","plaintext-only"),t.setAttribute("spellcheck",o.spellcheck?"true":"false"),t.style.outline="none",t.style.overflowWrap="break-word",t.style.overflowY="auto",t.style.whiteSpace="pre-wrap";let u=!1;e(t),"plaintext-only"!==t.contentEditable&&(u=!0),u&&t.setAttribute("contenteditable","true");const p=S(()=>{const n=b();e(t,n),T(n)},30);let g=!1;const h=t=>!O(t)&&!x(t)&&"Meta"!==t.key&&"Control"!==t.key&&"Alt"!==t.key&&!t.key.startsWith("Arrow"),y=S(t=>{h(t)&&(m(),g=!1)},300),N=(e,n)=>{l.push([e,n]),t.addEventListener(e,n)};function b(){const e=K(),n={start:0,end:0,dir:void 0};let{anchorNode:o,anchorOffset:r,focusNode:i,focusOffset:d}=e;if(!o||!i)throw"error1";if(o.nodeType===Node.ELEMENT_NODE){const t=s.createTextNode("");o.insertBefore(t,o.childNodes[r]),o=t,r=0}if(i.nodeType===Node.ELEMENT_NODE){const t=s.createTextNode("");i.insertBefore(t,i.childNodes[d]),i=t,d=0}return v(t,t=>{if(t===o&&t===i)return n.start+=r,n.end+=d,n.dir=r<=d?"->":"<-","stop";if(t===o){if(n.start+=r,n.dir)return"stop";n.dir="->"}else if(t===i){if(n.end+=d,n.dir)return"stop";n.dir="<-"}t.nodeType===Node.TEXT_NODE&&("->"!=n.dir&&(n.start+=t.nodeValue.length),"<-"!=n.dir&&(n.end+=t.nodeValue.length))}),t.normalize(),n}function T(e){const n=K();let o,r,s=0,i=0;if(e.dir||(e.dir="->"),e.start<0&&(e.start=0),e.end<0&&(e.end=0),"<-"==e.dir){const{start:t,end:n}=e;e.start=n,e.end=t}let d=0;v(t,t=>{if(t.nodeType!==Node.TEXT_NODE)return;const n=(t.nodeValue||"").length;if(d+n>e.start&&(o||(o=t,s=e.start-d),d+n>e.end))return r=t,i=e.end-d,"stop";d+=n}),o||(o=t,s=t.childNodes.length),r||(r=t,i=t.childNodes.length),"<-"==e.dir&&([o,s,r,i]=[r,i,o,s]),n.setBaseAndExtent(o,s,r,i)}function E(){const e=K().getRangeAt(0),n=s.createRange();return n.selectNodeContents(t),n.setEnd(e.startContainer,e.startOffset),n.toString()}function k(){const e=K().getRangeAt(0),n=s.createRange();return n.selectNodeContents(t),n.setStart(e.endContainer,e.endOffset),n.toString()}function C(t){if(u&&"Enter"===t.key)if(L(t),t.stopPropagation(),""==k()){M("\n ");const t=b();t.start=--t.end,T(t)}else M("\n")}function m(){if(!f)return;const e=t.innerHTML,n=b(),o=a[c];if(o&&o.html===e&&o.pos.start===n.start&&o.pos.end===n.end)return;a[++c]={html:e,pos:n},a.splice(c+1);c>300&&(c=300,a.splice(0,1))}function v(t,e){const n=[];t.firstChild&&n.push(t.firstChild);let o=n.pop();for(;o&&"stop"!==e(o);)o.nextSibling&&n.push(o.nextSibling),o.firstChild&&n.push(o.firstChild),o=n.pop()}function w(t){return t.metaKey||t.ctrlKey}function O(t){return w(t)&&!t.shiftKey&&"KeyZ"===t.code}function x(t){return w(t)&&t.shiftKey&&"KeyZ"===t.code}function M(t){t=t.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"),s.execCommand("insertHTML",!1,t)}function S(t,e){let n=0;return(...o)=>{clearTimeout(n),n=r.setTimeout(()=>t(...o),e)}}function A(t){let e=t.length-1;for(;e>=0&&"\n"!==t[e];)e--;let n=++e;for(;n<t.length&&/[ \t]/.test(t[n]);)n++;return[t.substring(e,n)||"",e,n]}function D(){return t.textContent||""}function L(t){t.preventDefault()}function K(){var e;return(null===(e=t.parentNode)||void 0===e?void 0:e.nodeType)==Node.DOCUMENT_FRAGMENT_NODE?t.parentNode.getSelection():r.getSelection()}return N("keydown",e=>{e.defaultPrevented||(d=D(),o.preserveIdent?function(t){if("Enter"===t.key){const e=E(),n=k();let[r]=A(e),s=r;if(o.indentOn.test(e)&&(s+=o.tab),s.length>0?(L(t),t.stopPropagation(),M("\n"+s)):C(t),s!==r&&"}"===n[0]){const t=b();M("\n"+r),T(t)}}}(e):C(e),o.catchTab&&function(t){if("Tab"===t.key)if(L(t),t.shiftKey){const t=E();let[e,n]=A(t);if(e.length>0){const t=b(),r=Math.min(o.tab.length,e.length);T({start:n,end:n+r}),s.execCommand("delete"),t.start-=r,t.end-=r,T(t)}}else M(o.tab)}(e),o.addClosing&&function(t){const e="([{'\"",n=")]}'\"",o=k(),r=E(),s="\\"===r.substr(r.length-1),i=o.substr(0,1);if(n.includes(t.key)&&!s&&i===t.key){const e=b();L(t),e.start=++e.end,T(e)}else if(e.includes(t.key)&&!s&&("\"'".includes(t.key)||[""," ","\n"].includes(i))){L(t);const o=b(),r=o.start==o.end?"":K().toString(),s=t.key+r+n[e.indexOf(t.key)];M(s),o.start++,o.end++,T(o)}}(e),o.history&&(!function(e){if(O(e)){L(e);const n=a[--c];n&&(t.innerHTML=n.html,T(n.pos)),c<0&&(c=0)}if(x(e)){L(e);const n=a[++c];n&&(t.innerHTML=n.html,T(n.pos)),c>=a.length&&c--}}(e),h(e)&&!g&&(m(),g=!0)),u&&T(b()))}),N("keyup",t=>{t.defaultPrevented||t.isComposing||(d!==D()&&p(),y(t),i&&i(D()))}),N("focus",t=>{f=!0}),N("blur",t=>{f=!1}),N("paste",n=>{m(),function(n){L(n);const o=(n.originalEvent||n).clipboardData.getData("text/plain").replace(/\r/g,""),r=b();M(o),e(t),T({start:r.start+o.length,end:r.start+o.length})}(n),m(),i&&i(D())}),{updateOptions(t){Object.assign(o,t)},updateCode(n){t.textContent=n,e(t)},onUpdate(t){i=t},toString:D,save:b,restore:T,recordHistory:m,destroy(){for(let[e,n]of l)t.removeEventListener(e,n)}}} \ No newline at end of file
+const globalWindow=window;function CodeJar(y,n,e={}){const v=Object.assign({tab:"\t",indentOn:/[({\[]$/,moveToNewLine:/^[)}\]]/,spellcheck:!1,catchTab:!0,preserveIdent:!0,addClosing:!0,history:!0,window:globalWindow},e),o=v.window,N=o.document;let r=[],T=[],b=-1,s=!1,i,E,m=(y.setAttribute("contenteditable","plaintext-only"),y.setAttribute("spellcheck",v.spellcheck?"true":"false"),y.style.outline="none",y.style.overflowWrap="break-word",y.style.overflowY="auto",!(y.style.whiteSpace="pre-wrap"));n(y),(m="plaintext-only"!==y.contentEditable?!0:m)&&y.setAttribute("contenteditable","true");const t=c(()=>{var e=w();n(y,e),O(e)},30);let k=!1;const C=e=>!D(e)&&!S(e)&&"Meta"!==e.key&&"Control"!==e.key&&"Alt"!==e.key&&!e.key.startsWith("Arrow"),a=c(e=>{C(e)&&(A(),k=!1)},300);e=(e,t)=>{r.push([e,t]),y.addEventListener(e,t)};function w(){var e=P();const t={start:0,end:0,dir:void 0};let{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:s}=e;if(n&&o)return n.nodeType===Node.ELEMENT_NODE&&(e=N.createTextNode(""),n.insertBefore(e,n.childNodes[r]),n=e,r=0),o.nodeType===Node.ELEMENT_NODE&&(e=N.createTextNode(""),o.insertBefore(e,o.childNodes[s]),o=e,s=0),l(y,e=>{if(e===n&&e===o)return t.start+=r,t.end+=s,t.dir=r<=s?"->":"<-","stop";if(e===n){if(t.start+=r,t.dir)return"stop";t.dir="->"}else if(e===o){if(t.end+=s,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))}),y.normalize(),t;throw"error1"}function O(n){const e=P();let r,o=0,s,i=0;var t,a;n.dir||(n.dir="->"),n.start<0&&(n.start=0),n.end<0&&(n.end=0),"<-"==n.dir&&({start:t,end:a}=n,n.start=a,n.end=t);let d=0;l(y,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)?(s=e,i=n.end-d,"stop"):void(d+=t)}),r||(r=y,o=y.childNodes.length),s||(s=y,i=y.childNodes.length),"<-"==n.dir&&([r,o,s,i]=[s,i,r,o]),e.setBaseAndExtent(r,o,s,i)}function x(){const e=P();var t=e.getRangeAt(0);const n=N.createRange();return n.selectNodeContents(y),n.setEnd(t.startContainer,t.startOffset),n.toString()}function M(){const e=P();var t=e.getRangeAt(0);const n=N.createRange();return n.selectNodeContents(y),n.setStart(t.endContainer,t.endOffset),n.toString()}function L(e){if(m&&"Enter"===e.key)if(R(e),e.stopPropagation(),""==M()){K("\n ");const t=w();t.start=--t.end,O(t)}else K("\n")}function A(){var e,t,n;s&&(e=y.innerHTML,t=w(),(n=T[b])&&n.html===e&&n.pos.start===t.start&&n.pos.end===t.end||(b++,T[b]={html:e,pos:t},T.splice(b+1),300<b&&(b=300,T.splice(0,1))))}function l(e,t){const n=[];e.firstChild&&n.push(e.firstChild);let r=n.pop();for(;r&&"stop"!==t(r);)r.nextSibling&&n.push(r.nextSibling),r.firstChild&&n.push(r.firstChild),r=n.pop()}function d(e){return e.metaKey||e.ctrlKey}function D(e){return d(e)&&!e.shiftKey&&"KeyZ"===e.code}function S(e){return d(e)&&e.shiftKey&&"KeyZ"===e.code}function K(e){e=e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;"),N.execCommand("insertHTML",!1,e)}function c(t,n){let r=0;return(...e)=>{clearTimeout(r),r=o.setTimeout(()=>t(...e),n)}}function _(e){let t=e.length-1;for(;0<=t&&"\n"!==e[t];)t--;let n=++t;for(;n<e.length&&/[ \t]/.test(e[n]);)n++;return[e.substring(t,n)||"",t,n]}function H(){return y.textContent||""}function R(e){e.preventDefault()}function P(){var e;return((null==(e=y.parentNode)?void 0:e.nodeType)==Node.DOCUMENT_FRAGMENT_NODE?y.parentNode:o).getSelection()}return e("keydown",e=>{if(!e.defaultPrevented){if(E=H(),v.preserveIdent){var t=e;if("Enter"===t.key){var n=x(),r=M(),[o]=_(n);let e=o;v.indentOn.test(n)&&(e+=v.tab),0<e.length?(R(t),t.stopPropagation(),K("\n"+e)):L(t),e!==o&&v.moveToNewLine.test(r)&&(n=w(),K("\n"+o),O(n))}}else L(e);var s,i;if(v.catchTab)if("Tab"===(t=e).key)if(R(t),t.shiftKey){var[t,r]=_(x());if(0<t.length){const a=w();t=Math.min(v.tab.length,t.length);O({start:r,end:r+t}),N.execCommand("delete"),a.start-=t,a.end-=t,O(a)}}else K(v.tab);if(v.addClosing){o=e;const d=`([{'"`,l=`)]}'"`,c=M(),f=x(),u="\\"===f.substr(f.length-1),p=c.substr(0,1);if(l.includes(o.key)&&!u&&p===o.key){const h=w();R(o),h.start=++h.end,O(h)}else if(d.includes(o.key)&&!u&&(`"'`.includes(o.key)||[""," ","\n"].includes(p))){R(o);const g=w();n=g.start==g.end?"":P().toString();K(o.key+n+l[d.indexOf(o.key)]),g.start++,g.end++,O(g)}}v.history&&(D(s=e)&&(R(s),b--,(i=T[b])&&(y.innerHTML=i.html,O(i.pos)),b<0&&(b=0)),S(s)&&(R(s),b++,(i=T[b])&&(y.innerHTML=i.html,O(i.pos)),b>=T.length&&b--),C(e)&&!k&&(A(),k=!0)),m&&O(w())}}),e("keyup",e=>{e.defaultPrevented||e.isComposing||(E!==H()&&t(),a(e),i&&i(H()))}),e("focus",e=>{s=!0}),e("blur",e=>{s=!1}),e("paste",e=>{var t;A(),R(e=e),e=(e.originalEvent||e).clipboardData.getData("text/plain").replace(/\r/g,""),t=w(),K(e),n(y),O({start:Math.min(t.start,t.end)+e.length,end:Math.min(t.start,t.end)+e.length,dir:"<-"}),A(),i&&i(H())}),{updateOptions(e){Object.assign(v,e)},updateCode(e){y.textContent=e,n(y)},onUpdate(e){i=e},toString:H,save:w,restore:O,recordHistory:A,destroy(){for(var[e,t]of r)y.removeEventListener(e,t)}}} \ No newline at end of file