fuck-tiny-cloud/plugins/advcode/plugin.min.js

10 lines
11 KiB
JavaScript
Raw Normal View History

2023-10-09 16:11:16 -04:00
/*!
2024-03-21 17:16:22 -04:00
* Tiny Enhanced Code Editor plugin
2023-10-09 16:11:16 -04:00
*
* Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc.
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
*
2024-03-21 17:16:22 -04:00
* Version: 7.0.0-22
2023-10-09 16:11:16 -04:00
*/
2024-03-21 17:16:22 -04:00
!function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const o=e-t;return 0===o?0:o>0?1:-1},o=(e,t,o)=>({major:e,minor:t,patch:o}),n=t=>{const n=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return n?o(e(n[1]),e(n[2]),e(n[3])):o(0,0,0)},r=e=>t=>typeof t===e,s=("string",e=>"string"===(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(o=n=e,(r=String).prototype.isPrototypeOf(o)||(null===(s=n.constructor)||void 0===s?void 0:s.name)===r.name)?"string":t;var o,n,r,s})(e));const i=r("boolean"),c=r("function"),a=r("number");class d{constructor(e,t){this.tag=e,this.value=t}static some(e){return new d(!0,e)}static none(){return d.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?d.some(e(this.value)):d.none()}bind(e){return this.tag?e(this.value):d.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:d.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(null!=e?e:"Called getOrDie on None")}static from(e){return null==e?d.none():d.some(e)}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}d.singletonNone=new d(!1);let l=0;const u=e=>{const t=(new Date).getTime(),o=Math.floor(1e9*Math.random());return l++,e+"_"+o+l+String(t)},m=e=>t=>t.options.get(e),g=m("codemirror_script"),h=m("codemirror_linewrapping"),p=m("codemirror_linenumbers"),f=m("codemirror_foldgutter"),v=m("codemirror_gutter"),y=m("advcode_headless"),b=m("advcode_inline"),_=(e,t,o)=>({customEditorScriptUrl:t+"/customeditor.min.js",codeMirrorScriptUrl:g(e),lineWrapping:h(e),lineNumbers:p(e),foldGutter:f(e),gutter:v(e),editorId:e.id,advcodeInstanceId:u("advcode_instance"),currentAdvStatus:o}),S=()=>{},w=()=>!1,C=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},k=(e,t)=>{const o=(t||document).createElement("div");if(o.innerHTML=e,!o.hasChildNodes()||o.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return C(o.childNodes[0])},x=(e,t)=>{const o=(t||document).createElement(e);return C(o)},z=C;"undefined"!=typeof window?window:Function("return this;")();const A=(e,t,o)=>{let n=e.dom;const r=c(o)?o:w;for(;n.parentNode;){n=n.parentNode;const e=z(n);if(t(e))return d.some(e);if(r(e))break}return d.none()},I=Object.hasOwnProperty,N=(e,t)=>I.call(e,t),T=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},F="\x3c!--mce_cursor--\x3e",M=(e,t)=>{const o=e.dom,n=e.selection,r=n.getBookmark(),s=(e=>N(e,"name"))(r)?o.select(r.name)[r.index]:o.select(`#${r.id}_start`)[0],i=d.from(s).map((t=>{const o=z(e.getBody());return((e,t)=>{const n=k(F),r=z(e),s=((e,t,o)=>((e,t,o,n,r)=>n(o)?d.some(o):c(r)&&r(o)?d.none():t(o,n,r))(0,A,e,t,o))(r,(e=>((e,t)=>{const o=e.dom;return!(!o||!o.hasAttribute)&&o.hasAttribute("data-mce-bogus")})(e)),(e=>{return t=o,e.dom===t.dom;var t})).getOr(r);return((e,t)=>{const o=(e=>d.from(e.dom.parentNode).map(z))(e);o.each((o=>{o.dom.insertBefore(t.dom,e.dom)}))})(s,n),n})(t)})),a=t();return i.each(T),n.moveToBookmark(r),a},E=e=>{const t=(e=>{const t=e.indexOf(F);return-1===t?0:t})(M(e,(()=>e.getContent({source_view:!0}))));return{content:e.getContent({source_view:!0}),cursor:t}},j=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},D=()=>{const e=(e=>{const t=j(d.none()),o=()=>t.get().each(e);return{clear:()=>{o(),t.set(d.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{o(),t.set(d.some(e))}}})(S);return{...e,on:t=>e.get().each(t)}},O=(e,t)=>{e.focus(),e.undoManager.transact((()=>{e.setContent(t)})),e.selection.setCursorLocation(),e.nodeChanged()},V=e=>{return(t=tinymce,"get",N(t,"get")?d.from(t.get):d.none()).bind((t=>d.from(t.c