10 lines
21 KiB
JavaScript
10 lines
21 KiB
JavaScript
|
/*!
|
||
|
* 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<n;r++){const n=e[r];a[r]=t(n,r)}return a},E=(e,t)=>{for(let n=0,a=e.length;n<a;n++)if(t(e[n],n))return w.some(n);return w.none()},D=(e,t)=>(e=>{const t=[];for(let n=0,a=e.length;n<a;++n){if(!s(e[n]))throw new Error("Arr.flatten item "+n+" was not an array, input: "+e);S.apply(t,e[n])}return t})(T(e,t)),O=(e,t)=>{for(let n=0,a=e.length;n<a;++n)if(!0!==t(e[n],n))return!1;return!0},M=e=>((e,t)=>0<e.length?w.some(e[0]):w.none())(e);class P extends Error{constructor(e){super(e),this.name="AdvTemplateError"}}const I=e=>{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`));
|