/*! * Tiny Advanced Template plugin * * Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc. * Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/ * * Version: 1.4.0-44 */ !function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const a=e-t;return 0===a?0:a>0?1:-1},a=(e,t,a)=>({major:e,minor:t,patch:a}),n=t=>{const n=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return n?a(e(n[1]),e(n[2]),e(n[3])):a(0,0,0)},r=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(a=n=e,(r=String).prototype.isPrototypeOf(a)||(null===(o=n.constructor)||void 0===o?void 0:o.name)===r.name)?"string":t;var a,n,r,o})(t)===e,o=e=>t=>typeof t===e,i=r("string"),l=r("object"),s=r("array"),c=o("boolean"),m=(void 0,e=>undefined===e);const d=e=>null==e,p=e=>!d(e),u=o("function"),g=o("number"),y=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},v=()=>{},h=e=>()=>e,f=e=>e,_=e=>e(),b=h(!1),w=h(!0);class x{constructor(e,t){this.tag=e,this.value=t}static some(e){return new x(!0,e)}static none(){return x.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?x.some(e(this.value)):x.none()}bind(e){return this.tag?e(this.value):x.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:x.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 p(e)?x.some(e):x.none()}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()"}}x.singletonNone=new x(!1);const C=Array.prototype.slice,S=Array.prototype.indexOf,A=Array.prototype.push,E=(e,t)=>((e,t)=>S.call(e,t))(e,t)>-1,T=(e,t)=>{const a=e.length,n=new Array(a);for(let r=0;r{for(let a=0,n=e.length;a{for(let a=0,n=e.length;a(e=>{const t=[];for(let a=0,n=e.length;a{for(let a=0,n=e.length;a((e,t)=>0{const t=t=>t(e),a=h(e),n=()=>r,r={tag:!0,inner:e,fold:(t,a)=>a(e),isValue:w,isError:b,map:t=>k.value(t(e)),mapError:n,bind:t,exists:t,forall:t,getOr:a,or:n,getOrThunk:a,orThunk:n,getOrDie:a,each:t=>{t(e)},toOptional:()=>x.some(e)};return r},j=e=>{const t=()=>a,a={tag:!1,inner:e,fold:(t,a)=>t(e),isValue:b,isError:w,map:t,mapError:t=>k.error(t(e)),bind:t,exists:b,forall:w,getOr:f,or:f,getOrThunk:_,orThunk:_,getOrDie:(n=String(e),()=>{throw new Error(n)}),each:v,toOptional:x.none};var n;return a},k={value:N,error:j,fromOption:(e,t)=>e.fold((()=>j(t)),N)},R=Object.keys,B=Object.hasOwnProperty,L=(e,t)=>B.call(e,t),z=e=>i(e)&&e.length>0,U=e=>z(e),V=e=>L(e,"id")&&U(e.id),K=e=>L(e,"title")&&z(e.title),q=e=>L(e,"content")&&z(e.content),F=e=>l(e)&&V(e)&&K(e)&&L(e,"items")&&G(e.items),H=e=>l(e)&&V(e)&&K(e)&&(e=>!L(e,"items")||G(e.items))(e),G=e=>s(e)&&I(e,H),W=e=>L(e,"items")&&J(e.items),Y=e=>l(e)&&K(e)&&((e=>q(e))(e)||W(e)),J=e=>s(e)&&I(e,Y),Q=(e,t)=>a=>e(a)?k.value(a):k.error(t),X=Q((e=>l(e)&&(e=>{for(const t in e)if(B.call(e,t))return!1;return!0})(e)),"response should contain empty object"),Z=Q((e=>l(e)&&V(e)),"response should contain id"),ee=Q((e=>l(e)&&V(e)&&K(e)&&q(e)),"response contains invalid template data"),te=e=>G(e)?(e=>{const t=e=>P(e,(e=>F(e)?[e.id,...t(e.items)]:[e.id])),a=t(e);return a.length===[...new Set(a)].length})(e)?k.value(e):k.error("response contains duplicated ids"):k.error("response contains invalid data"),ae=e=>t=>t.options.get(e),ne=e=>{const t=(t,a)=>{var n,r;n=t,r=(e,t)=>(...n)=>((e,t,a)=>{return l(n=a)&&u(n.then)&&u(n.catch)?a.then((a=>t(a).fold((t=>Promise.reject(new $(`${e} ${t}`))),(e=>Promise.resolve(e))))):Promise.reject(new $(`${e} should return a Promise`));var n})(e,a,t(...n)),e.options.register(n,{processor:e=>u(e)?{valid:!0,value:r(n,e)}:{valid:!1,message:"Must be a function returning promise"},default:()=>Promise.reject(new $(`${n} option is not configured`))})};t("advtemplate_create_category",Z),t("advtemplate_rename_category",X),t("advtemplate_move_category_items",X),t("advtemplate_delete_category",X),t("advtemplate_create_template",Z),t("advtemplate_rename_template",X),t("advtemplate_update_template",X),t("advtemplate_move_template",X),t("advtemplate_get_template",ee),t("advtemplate_delete_template",X),t("advtemplate_delete_all",X),t("advtemplate_list",te),e.options.register("advtemplate_templates",{processor:J})},re=ae("advtemplate_create_category"),oe=ae("advtemplate_rename_category"),ie=ae("advtemplate_move_category_items"),le=ae("advtemplate_delete_category"),se=ae("advtemplate_create_template"),ce=ae("advtemplate_rename_template"),me=ae("advtemplate_move_template"),de=ae("advtemplate_get_template"),pe=ae("advtemplate_delete_template"),ue=ae("advtemplate_list"),ge=ae("advtemplate_templates"),ye=ae("content_style"),ve=ae("body_class"),he=ae("content_css_cors"),fe=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},_e=(e,t)=>{const a=(t||document).createElement(e);return fe(a)},be=fe,we=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount;"undefined"!=typeof window?window:Function("return this;")();const xe=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},Ce='data-mce-advtemplate-marker="clipboard"',Se=e=>{const t=((e,t)=>((e,t)=>{const a=void 0===t?document:t.dom;return we(a)?[]:T(a.querySelectorAll(e),be)})(t,e))(be(e.getBody()),`span[${Ce}]`);return 0===t.length?Promise.resolve():(async()=>new Promise(((e,t)=>{var a;u(null===(a=null===navigator||void 0===navigator?void 0:navigator.clipboard)||void 0===a?void 0:a.readText)?navigator.clipboard.readText().then((t=>{e(t)})).catch((e=>{t(e)})):t(new Error("Clipboard API not supported in this browser."))})))().then((a=>{D(t,(t=>{const n=e.dom.createRng();n.setStartAfter(t.dom),n.setEndAfter(t.dom),e.selection.setRng(n),e.insertContent(a)}))})).catch((t=>{e.notificationManager.open({text:e.translate("Failed to read clipboard content"),type:"error",timeout:2e3}),console.error(t)})).finally((()=>{D(t,(e=>{xe(e)}))}))},Ae='data-mce-advtemplate-marker="cursor"',Ee="{{mce-cursor}}",Te=new RegExp(Ee),De=new RegExp("{{mce-clipboard}}","g"),Oe='data-mce-bookmark="1"',Pe=``,Ie=``,Me=async e=>{await Se(e),(e=>{((e,t)=>((e,t)=>{const a=void 0===t?document:t.dom;return we(a)?x.none():x.from(a.querySelector(e)).map(be)})(t,e))(be(e.getBody()),`span[${Ae}]`).each((t=>{const a=e.dom.createRng();a.setStartBefore(t.dom),a.setEndBefore(t.dom),e.selection.setRng(a),e.selection.scrollIntoView(),xe(t)}))})(e)},$e=(e,t)=>de(e)(t).then((t=>{(async(e,t)=>{const a=y(!1),n=((e,t,a)=>{const n=tinymce.html.DomParser(void 0,e.schema);n.addNodeFilter("#text",(e=>t=>{let a,n=!1;for(const e of t){let t=!1;x.from(e.value).each((r=>{let o=r;if(!n){const e=o.match(Te);p(e)&&(o=o.replace(Ee,Pe),n=!0,t=!0)}const i=o.match(De);if(p(i)&&(o=o.replace(De,Ie),t=!0),t){a=null!=a?a:tinymce.html.DomParser();const t=a.parse(o);e.replace(t),t.unwrap()}}))}e.set(p(a))})(a));const r=n.parse(t,{insert:!0});return a.get()?tinymce.html.Serializer({validate:!0},e.schema).serialize(r):t})(e,t,a);e.insertContent(n),a.get()&&await Me(e)})(e,t.content)})),Ne=(e,t)=>e?x.some(t):x.none(),je={text:"Uncategorized",value:""},ke=(e,t)=>{const a=((e,a)=>{const n=[];for(let a=0,o=e.length;a({text:t,value:e})))]},Re=(e,t)=>{return(a=t,n=t=>F(t)&&E(T(t.items,(({id:e})=>e)),e),((e,t,a)=>{for(let n=0,r=e.length;ne.id)).getOr(je.value);var a,n},Be=e=>Ne(e!==je.value,e).getOrUndefined(),Le=(e,t,a)=>e.options.isSet(t)?[a]:[],ze=(e,t,a)=>{const n=e=>{const n=[...Le(a,"advtemplate_rename_category",{type:"menuitem",text:"Rename...",onAction:t.renameCategory(e)}),...Le(a,"advtemplate_move_category_items",{type:"menuitem",text:"Move all items...",enabled:e.items.length>0,onAction:t.moveCategoryItems(e.id)}),...Le(a,"advtemplate_delete_category",{type:"separator"}),...Le(a,"advtemplate_delete_category",{type:"menuitem",icon:"remove",text:"Delete all",onAction:t.deleteCategory(e.id)})];return n.length>0?{menu:{type:"menubutton",icon:"image-options",fetch:e=>e(n)}}:{}},r=e=>{const n=[...Le(a,"advtemplate_rename_template",{type:"menuitem",text:"Rename...",onAction:t.renameTemplate(e)}),...Le(a,"advtemplate_move_template",{type:"menuitem",text:"Move to...",onAction:t.moveTemplate(e.id)}),...Le(a,"advtemplate_delete_template",{type:"separator"}),...Le(a,"advtemplate_delete_template",{type:"menuitem",icon:"remove",text:"Delete",onAction:t.deleteTemplate(e.id)})];return n.length>0?{menu:{type:"menubutton",icon:"image-options",fetch:e=>e(n)}}:{}};return T(e,(e=>F(e)?(e=>({type:"directory",id:e.id,title:e.title,children:ze(e.items,t,a),...n(e)}))(e):(e=>({type:"leaf",id:e.id,title:e.title,...r(e)}))(e)))},Ue=e=>{const t=(e,a)=>((e,a,n)=>(D(e,((e,a)=>{var r,o;r=n,n="directory"===(o=e).type?[o,...t(o.children,r)]:[...r,o]})),n))(e,0,a);return t(e,[])},Ve=e=>t=>{x.from(t.message).bind((e=>(console.error(e),Ne(!(e=>e instanceof $)(t),e)))).or(x.some("Operation failed")).each(e.windowManager.alert)},Ke=(e,t)=>((e,t,a)=>{const n=((e,t)=>{const a=((e,t)=>{const a=e.dom.getAttribute(t);return null===a?void 0:a})(e,t);return void 0===a||""===a?[]:a.split(" ")})(e,t);return((e,t,a)=>{((e,t,a)=>{if(!(i(a)||c(a)||g(a)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",a,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,a+"")})(e.dom,t,a)})(e,t,n.concat([a]).join(" ")),!0})(e,"class",t),qe=(e=>{let t,a=!1;return(...n)=>(a||(a=!0,t=e.apply(null,n)),t)})((()=>{const e=tinymce.Env.os.isMacOS()||tinymce.Env.os.isiOS()?e=>e.metaKey:e=>e.ctrlKey&&!e.altKey;return`