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

10 lines
21 KiB
JavaScript
Raw Normal View History

2023-11-01 22:54:59 -04:00
/*!
* 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
2023-11-01 22:54:59 -04:00
*/
!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<a;r++){const a=e[r];n[r]=t(a,r)}return n},D=(e,t)=>{for(let a=0,n=e.length;a<n;a++)t(e[a],a)},O=(e,t)=>{for(let a=0,n=e.length;a<n;a++)if(t(e[a],a))return x.some(a);return x.none()},P=(e,t)=>(e=>{const t=[];for(let a=0,n=e.length;a<n;++a){if(!s(e[a]))throw new Error("Arr.flatten item "+a+" was not an array, input: "+e);A.apply(t,e[a])}return t})(T(e,t)),I=(e,t)=>{for(let a=0,n=e.length;a<n;++a)if(!0!==t(e[a],a))return!1;return!0},M=e=>((e,t)=>0<e.length?x.some(e[0]):x.none())(e);class $ extends Error{constructor(e){super(e),this.name="AdvTemplateError"}}const N=e=>{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(ne