/*! * 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.3.0-38 */ !function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const n=e-t;return 0===n?0:n>0?1:-1},n=(e,t,n)=>({major:e,minor:t,patch:n}),a=t=>{const a=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return a?n(e(a[1]),e(a[2]),e(a[3])):n(0,0,0)},r=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(n=a=e,(r=String).prototype.isPrototypeOf(n)||(null===(o=a.constructor)||void 0===o?void 0:o.name)===r.name)?"string":t;var n,a,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=()=>{},v=e=>()=>e,h=e=>e,f=e=>e(),_=v(!1),b=v(!0);class w{constructor(e,t){this.tag=e,this.value=t}static some(e){return new w(!0,e)}static none(){return w.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?w.some(e(this.value)):w.none()}bind(e){return this.tag?e(this.value):w.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:w.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)?w.some(e):w.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()"}}w.singletonNone=new w(!1);const x=Array.prototype.slice,C=Array.prototype.indexOf,S=Array.prototype.push,A=(e,t)=>((e,t)=>C.call(e,t))(e,t)>-1,T=(e,t)=>{const n=e.length,a=new Array(n);for(let r=0;r{for(let n=0,a=e.length;n(e=>{const t=[];for(let n=0,a=e.length;n{for(let n=0,a=e.length;n((e,t)=>0{const t=t=>t(e),n=v(e),a=()=>r,r={tag:!0,inner:e,fold:(t,n)=>n(e),isValue:b,isError:_,map:t=>j.value(t(e)),mapError:a,bind:t,exists:t,forall:t,getOr:n,or:a,getOrThunk:n,orThunk:a,getOrDie:n,each:t=>{t(e)},toOptional:()=>w.some(e)};return r},N=e=>{const t=()=>n,n={tag:!1,inner:e,fold:(t,n)=>t(e),isValue:_,isError:b,map:t,mapError:t=>j.error(t(e)),bind:t,exists:_,forall:b,getOr:h,or:h,getOrThunk:f,orThunk:f,getOrDie:(a=String(e),()=>{throw new Error(a)}),each:y,toOptional:w.none};var a;return n},j={value:I,error:N,fromOption:(e,t)=>e.fold((()=>N(t)),I)},k=Object.keys,$=Object.hasOwnProperty,R=(e,t)=>$.call(e,t),B=e=>i(e)&&e.length>0,L=e=>B(e),z=e=>R(e,"id")&&L(e.id),U=e=>R(e,"title")&&B(e.title),V=e=>R(e,"content")&&B(e.content),K=e=>l(e)&&z(e)&&U(e)&&R(e,"items")&&F(e.items),q=e=>l(e)&&z(e)&&U(e)&&(e=>!R(e,"items")||F(e.items))(e),F=e=>s(e)&&O(e,q),H=e=>R(e,"items")&&W(e.items),G=e=>l(e)&&U(e)&&((e=>V(e))(e)||H(e)),W=e=>s(e)&&O(e,G),Y=(e,t)=>n=>e(n)?j.value(n):j.error(t),J=Y((e=>l(e)&&(e=>{for(const t in e)if($.call(e,t))return!1;return!0})(e)),"response should contain empty object"),Q=Y((e=>l(e)&&z(e)),"response should contain id"),X=Y((e=>l(e)&&z(e)&&U(e)&&V(e)),"response contains invalid template data"),Z=e=>F(e)?(e=>{const t=e=>D(e,(e=>K(e)?[e.id,...t(e.items)]:[e.id])),n=t(e);return n.length===[...new Set(n)].length})(e)?j.value(e):j.error("response contains duplicated ids"):j.error("response contains invalid data"),ee=e=>t=>t.options.get(e),te=e=>{const t=(t,n)=>{var a,r;a=t,r=(e,t)=>(...a)=>((e,t,n)=>{return l(a=n)&&u(a.then)&&u(a.catch)?n.then((n=>t(n).fold((t=>Promise.reject(new P(`${e} ${t}`))),(e=>Promise.resolve(e))))):Promise.reject(new P(`${e} should return a Promise`));var a})(e,n,t(...a)),e.options.register(a,{processor:e=>u(e)?{valid:!0,value:r(a,e)}:{valid:!1,message:"Must be a function returning promise"},default:()=>Promise.reject(new P(`${a} option is not configured`))})};t("advtemplate_create_category",Q),t("advtemplate_rename_category",J),t("advtemplate_move_category_items",J),t("advtemplate_delete_category",J),t("advtemplate_create_template",Q),t("advtemplate_rename_template",J),t("advtemplate_update_template",J),t("advtemplate_move_template",J),t("advtemplate_get_template",X),t("advtemplate_delete_template",J),t("advtemplate_delete_all",J),t("advtemplate_list",Z),e.options.register("advtemplate_templates",{processor:W})},ne=ee("advtemplate_create_category"),ae=ee("advtemplate_rename_category"),re=ee("advtemplate_move_category_items"),oe=ee("advtemplate_delete_category"),ie=ee("advtemplate_create_template"),le=ee("advtemplate_rename_template"),se=ee("advtemplate_move_template"),ce=ee("advtemplate_get_template"),me=ee("advtemplate_delete_template"),de=ee("advtemplate_list"),pe=ee("advtemplate_templates"),ue=ee("content_style"),ge=ee("body_class"),ye=ee("content_css_cors"),ve=(e,t)=>e?w.some(t):w.none();let he=0;const fe=()=>{const e=(e=>{const t=(e=>{let t=e;return{get:()=>t,set:e=>{t=e}}})(w.none()),n=()=>t.get().each(e);return{clear:()=>{n(),t.set(w.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{n(),t.set(w.some(e))}}})(y);return{...e,on:t=>e.get().each(t)}},_e=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},be=(e,t)=>{const n=(t||document).createElement(e);return _e(n)},we=_e;"undefined"!=typeof window?window:Function("return this;")();const xe="{{mce-cursor}}",Ce=(e,t)=>{((e,t)=>ve(-1!==t.indexOf(xe),t).bind((t=>{const n=tinymce.html.DomParser(void 0,e.schema),a=fe();var r;n.addNodeFilter("#text",(r=a,e=>{((e,t)=>{for(let n=0;nw.from(e.value).map((t=>({node:e,textContent:t,index:t.indexOf(xe)}))).filter((({index:e})=>-1!==e)))).each((({node:e,textContent:t,index:n})=>{const a=tinymce.html.Node.create("span");if(n>0){const e=tinymce.html.Node.create("#text");e.value=t.substring(0,n),a.append(e)}const o=(e=>{const t=(new Date).getTime(),n=Math.floor(1e9*Math.random());return he++,"advtemplate-cursor-marker_"+n+he+String(t)})();r.set(o);const i=tinymce.html.Node.create("span",{"data-mce-id":o,"data-mce-cursor-marker":"true"}),l=tinymce.html.Node.create("#text");if(l.value="\ufeff",i.append(l),a.append(i),t.length>n+14){const e=tinymce.html.Node.create("#text");e.value=t.substring(n+14,t.length),a.append(e)}e.replace(a),a.unwrap()}))}));const o=n.parse(t,{insert:!0});return ve(a.isSet(),{content:tinymce.html.Serializer({validate:!0},e.schema).serialize(o),cursorMarkerId:a.get().getOrDie()})})))(e,t).fold((()=>e.insertContent(t)),(({cursorMarkerId:t,content:n})=>{e.undoManager.transact((()=>{e.insertContent(n),((e,t)=>{const n=we(e.getBody());var a,r;(a=n,r=`span[data-mce-id="${t}"]`,((e,t)=>{const n=void 0===t?document:t.dom;return 1!==(a=n).nodeType&&9!==a.nodeType&&11!==a.nodeType||0===a.childElementCount?w.none():w.from(n.querySelector(e)).map(we);var a})(r,a)).each((t=>{const n=e.dom.createRng();n.setStartAfter(t.dom),n.setEndAfter(t.dom),e.selection.setRng(n),e.selection.scrollIntoView(),(e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)})(t)}))})(e,t)}))}))},Se=(e,t)=>ce(e)(t).then((t=>{Ce(e,t.content)})),Ae={text:"Uncategorized",value:""},Te=(e,t)=>{const n=((e,n)=>{const a=[];for(let n=0,o=e.length;n({text:t,value:e})))]},Ee=(e,t)=>{return(n=t,a=t=>K(t)&&A(T(t.items,(({id:e})=>e)),e),((e,t,n)=>{for(let a=0,r=e.length;ae.id)).getOr(Ae.value);var n,a},De=e=>ve(e!==Ae.value,e).getOrUndefined(),Oe=(e,t,n)=>e.options.isSet(t)?[n]:[],Me=(e,t,n)=>{const a=e=>{const a=[...Oe(n,"advtemplate_rename_category",{type:"menuitem",text:"Rename...",onAction:t.renameCategory(e)}),...Oe(n,"advtemplate_move_category_items",{type:"menuitem",text:"Move all items...",enabled:e.items.length>0,onAction:t.moveCategoryItems(e.id)}),...Oe(n,"advtemplate_delete_category",{type:"separator"}),...Oe(n,"advtemplate_delete_category",{type:"menuitem",icon:"remove",text:"Delete all",onAction:t.deleteCategory(e.id)})];return a.length>0?{menu:{type:"menubutton",icon:"image-options",fetch:e=>e(a)}}:{}},r=e=>{const a=[...Oe(n,"advtemplate_rename_template",{type:"menuitem",text:"Rename...",onAction:t.renameTemplate(e)}),...Oe(n,"advtemplate_move_template",{type:"menuitem",text:"Move to...",onAction:t.moveTemplate(e.id)}),...Oe(n,"advtemplate_delete_template",{type:"separator"}),...Oe(n,"advtemplate_delete_template",{type:"menuitem",icon:"remove",text:"Delete",onAction:t.deleteTemplate(e.id)})];return a.length>0?{menu:{type:"menubutton",icon:"image-options",fetch:e=>e(a)}}:{}};return T(e,(e=>K(e)?(e=>({type:"directory",id:e.id,title:e.title,children:Me(e.items,t,n),...a(e)}))(e):(e=>({type:"leaf",id:e.id,title:e.title,...r(e)}))(e)))},Pe=e=>t=>{w.from(t.message).bind((e=>(console.error(e),ve(!(e=>e instanceof P)(t),e)))).or(w.some("Operation failed")).each(e.windowManager.alert)},Ie=(e,t)=>((e,t,n)=>{const a=((e,t)=>{const n=((e,t)=>{const n=e.dom.getAttribute(t);return null===n?void 0:n})(e,t);return void 0===n||""===n?[]:n.split(" ")})(e,t);return((e,t,n)=>{((e,t,n)=>{if(!(i(n)||c(n)||g(n)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",n,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,n+"")})(e.dom,t,n)})(e,t,a.concat([n]).join(" ")),!0})(e,"class",t),Ne=(e=>{let t,n=!1;return(...a)=>(n||(n=!0,t=e.apply(null,a)),t)})((()=>{const e=tinymce.Env.os.isMacOS()||tinymce.Env.os.isiOS()?e=>e.metaKey:e=>e.ctrlKey&&!e.altKey;return`