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

10 lines
9.4 KiB
JavaScript

/*!
* Tiny Checklist plugin
*
* Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc.
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
*
* Version: 2.0.6-56
*/
!function(){"use strict";const t=t=>parseInt(t,10),e=(t,e)=>{const o=t-e;return 0===o?0:o>0?1:-1},o=(t,e,o)=>({major:t,minor:e,patch:o}),n=e=>{const n=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return n?o(t(n[1]),t(n[2]),t(n[3])):o(0,0,0)},r=t=>e=>typeof e===t,s=t=>"string"===(t=>{const e=typeof t;return null===t?"null":"object"===e&&Array.isArray(t)?"array":"object"===e&&(o=n=t,(r=String).prototype.isPrototypeOf(o)||(null===(s=n.constructor)||void 0===s?void 0:s.name)===r.name)?"string":e;var o,n,r,s})(t),i=r("boolean"),l=t=>!(t=>null==t)(t),c=r("function"),a=r("number");class u{constructor(t,e){this.tag=t,this.value=e}static some(t){return new u(!0,t)}static none(){return u.singletonNone}fold(t,e){return this.tag?e(this.value):t()}isSome(){return this.tag}isNone(){return!this.tag}map(t){return this.tag?u.some(t(this.value)):u.none()}bind(t){return this.tag?t(this.value):u.none()}exists(t){return this.tag&&t(this.value)}forall(t){return!this.tag||t(this.value)}filter(t){return!this.tag||t(this.value)?this:u.none()}getOr(t){return this.tag?this.value:t}or(t){return this.tag?this:t}getOrThunk(t){return this.tag?this.value:t()}orThunk(t){return this.tag?this:t()}getOrDie(t){if(this.tag)return this.value;throw new Error(null!=t?t:"Called getOrDie on None")}static from(t){return l(t)?u.some(t):u.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(t){this.tag&&t(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}u.singletonNone=new u(!1);const d=(!1,()=>false);const m=Array.prototype.indexOf,h=(t,e)=>{return o=t,n=e,m.call(o,n)>-1;var o,n},g=(t,e)=>{const o=t.length,n=new Array(o);for(let r=0;r<o;r++){const o=t[r];n[r]=e(o,r)}return n},f=(t,e)=>{for(let o=0,n=t.length;o<n;o++)e(t[o],o)},p=(t,e)=>{const o=[];for(let n=0,r=t.length;n<r;n++){const r=t[n];e(r,n)&&o.push(r)}return o},v=Object.keys;"undefined"!=typeof window?window:Function("return this;")();const k=t=>t.dom.nodeName.toLowerCase(),y=t=>e=>(t=>t.dom.nodeType)(e)===t,w=y(1),L=y(3),b=y(9),N=y(11),S=t=>e=>w(e)&&k(e)===t,x=(t,e,o)=>{if(!(s(o)||i(o)||a(o)))throw console.error("Invalid call to Attribute.set. Key ",e,":: Value ",o,":: Element ",t),new Error("Attribute value was not simple");t.setAttribute(e,o+"")},T=(t,e,o)=>{x(t.dom,e,o)},C=(t,e)=>{t.dom.removeAttribute(e)},O=(t,e)=>{const o=((t,e)=>{const o=t.dom.getAttribute(e);return null===o?void 0:o})(t,e);return void 0===o||""===o?[]:o.split(" ")},A=t=>void 0!==t.dom.classList,E=t=>O(t,"class"),D=(t,e)=>((t,e,o)=>{const n=O(t,e).concat([o]);return T(t,e,n.join(" ")),!0})(t,"class",e),M=(t,e)=>((t,e,o)=>{const n=p(O(t,e),(t=>t!==o));return n.length>0?T(t,e,n.join(" ")):C(t,e),!1})(t,"class",e),j=(t,e)=>{A(t)?t.dom.classList.add(e):D(t,e)},B=t=>{0===(A(t)?t.dom.classList:E(t)).length&&C(t,"class")},P=(t,e)=>{A(t)?t.dom.classList.remove(e):M(t,e),B(t)},I=(t,e)=>A(t)&&t.dom.classList.contains(e),U=t=>{if(null==t)throw new Error("Node cannot be null or undefined");return{dom:t}},V=(t,e)=>{const o=(e||document).createElement(t);return U(o)},R=U,q=(t,e)=>{const o=t.dom;if(1!==o.nodeType)return!1;{const t=o;if(void 0!==t.matches)return t.matches(e);if(void 0!==t.msMatchesSelector)return t.msMatchesSelector(e);if(void 0!==t.webkitMatchesSelector)return t.webkitMatchesSelector(e);if(void 0!==t.mozMatchesSelector)return t.mozMatchesSelector(e);throw new Error("Browser lacks native selectors")}},X=t=>u.from(t.dom.parentNode).map(R),$=t=>g(t.dom.childNodes,R),z=t=>((t,e)=>{const o=t.dom.childNodes;return u.from(o[0]).map(R)})(t),F=c(Element.prototype.attachShadow)&&c(Node.prototype.getRootNode)?t=>R(t.dom.getRootNode()):t=>b(t)?t:R(t.dom.ownerDocument),K=t=>R(t.dom.host),Y=t=>{const e=L(t)?t.dom.parentNode:t.dom;if(null==e||null===e.ownerDocument)return!1;const o=e.ownerDocument;return(t=>{const e=F(t);return N(o=e)&&l(o.dom.host)?u.some(e):u.none();var o})(R(e)).fold((()=>o.body.contains(e)),(n=Y,r=K,t=>n(r(t))));var n,r},G=(t,e)=>({left:t,top:e,translate:(o,n)=>G(t+o,e+n)}),H=G,J=(t,e)=>void 0!==t?t:void 0!==e?e:0,Q=t=>S("li")(t)&&X(t).filter((t=>"ul"===k(t)&&I(t,"tox-checklist"))).isSome(),W=(t,e)=>e<(t=>{const e=t.dom.ownerDocument,o=e.body,n=e.defaultView,r=e.documentElement;if(o===t.dom)return H(o.offsetLeft,o.offsetTop);const s=J(null==n?void 0:n.pageYOffset,r.scrollTop),i=J(null==n?void 0:n.pageXOffset,r.scrollLeft),l=J(r.clientTop,o.clientTop),c=J(r.clientLeft,o.clientLeft);return(t=>{const e=t.dom,o=e.ownerDocument.body;return o===e?H(o.offsetLeft,o.offsetTop):Y(t)?(t=>{const e=t.getBoundingClientRect();return H(e.left,e.top)})(e):H(0,0)})(t).translate(i-c,s-l)})(t).left,Z=t=>((t,e)=>{const o=A(t)?t.dom.classList.toggle(e):((t,e)=>h(E(t),e)?M(t,e):D(t,e))(t,e);return B(t),o})(t,"tox-checklist--checked"),_=t=>h(["ul","ol","dl"],k(t)),tt=t=>(u.from(t).filter((t=>I(t,"tox-checklist"))).bind(z).map((t=>{S("li")(t)&&z(t).exists(S("ul"))&&j(t,"tox-checklist--hidden")})),t);var et=(t,e,o,n,r)=>t(o,n)?u.some(o):c(r)&&r(o)?u.none():e(o,n,r);const ot=(t,e,o)=>{let n=t.dom;const r=c(o)?o:d;for(;n.parentNode;){n=n.parentNode;const t=R(n);if(e(t))return u.some(t);if(r(t))break}return u.none()},nt=(t,e)=>{t.dom.appendChild(e.dom)},rt=(t,e)=>{const o=((t,e)=>{const o=V(e),n=(r=t.dom.attributes,s=(t,e)=>(t[e.name]=e.value,t),i={},f(r,((t,e)=>{i=s(i,t)})),i);var r,s,i;return((t,e)=>{const o=t.dom;((t,e)=>{const o=v(t);for(let n=0,r=o.length;n<r;n++){const r=o[n];e(t[r],r)}})(e,((t,e)=>{x(o,e,t)}))})(o,n),o})(t,e);var n,r;return r=o,(t=>u.from(t.dom.nextSibling).map(R))(n=t).fold((()=>{X(n).each((t=>{nt(t,r)}))}),(t=>{((t,e)=>{X(t).each((o=>{o.dom.insertBefore(e.dom,t.dom)}))})(t,r)})),((t,e)=>{f(e,(e=>{nt(t,e)}))})(o,$(t)),(t=>{const e=t.dom;null!==e.parentNode&&e.parentNode.removeChild(e)})(t),o},st=(t,e,o)=>ot(t,(t=>q(t,e)),o),it=t=>e=>l(e)&&t.test(e.nodeName),lt=it(/^(OL|UL|DL)$/),ct=it(/^(LI|DT|DD)$/),at=["OL","UL","DL"],ut=at.join(","),dt=(t,e)=>{const o=t.dom.getParents(e,t.dom.isBlock);return(n=o,r=e=>{return o=t.schema,!lt(n=e)&&!ct(n)&&((t,e)=>{for(let e=0,s=t.length;e<s;e++)if(r=t[e],o.isValidChild(n.nodeName,r))return!0;var r;return!1})(at);var o,n},((t,e,o)=>{for(let n=0,r=t.length;n<r;n++){const r=t[n];if(e(r,n))return u.some(r);if(o(r,n))break}return u.none()})(n,r,d)).getOr(t.getBody());var n,r},mt=t=>{const e=t=>"ol"===k(t)||"ul"===k(t),o=()=>{const o=R(t.selection.getNode());var n,r;t.selection.isEditable()&&(n=o,r=e,et(((t,e)=>e(t)),ot,n,r,undefined)).fold((()=>{t.undoManager.transact((()=>{t.execCommand("InsertUnorderedList",!1,{"list-attributes":{class:"tox-checklist"}}),f(p(g(t.selection.getSelectedBlocks(),R),e),(t=>j(t,"tox-checklist")))}))}),(e=>{t.undoManager.transact((()=>{if(I(e,"tox-checklist"))t.execCommand("RemoveList");else{const o=t.selection.getBookmark(),n=(t=>{const e=((t,e)=>{const o=t.selection.getStart(!0);return t.dom.getParent(o,ut,dt(t,o))})(t),o=t.selection.getSelectedBlocks();return((t,e)=>l(t)&&1===e.length&&e[0]===t)(e,o)?(t=>p(t.querySelectorAll(ut),lt))(e):p(o,(t=>lt(t)&&e!==t))})(t).map(R);f([e,...n],(t=>{const e=rt(t,"ul");j(e,"tox-checklist")})),t.selection.moveToBookmark(o)}}))}))};t.ui.registry.addToggleButton("checklist",{icon:"checklist",tooltip:"Insert Checklist",onAction:o,onSetup:o=>{const n=R(t.getBody()),r=t=>{return o=n,t.dom===o.dom||e(t);var o},s=e=>o.setActive(!t.readonly&&((t,e,o)=>et(((t,e)=>q(t,e)),st,t,".tox-checklist",o))(R(e),0,r).isSome()),i=()=>{const e=t.selection.isEditable();o.setEnabled(!t.readonly&&e)},l=t=>{s(t.element),i()};return t.on("NodeChange",l),s(t.selection.getNode()),i(),()=>t.off("NodeChange",l)}}),t.ui.registry.addMenuItem("checklist",{icon:"checklist",text:"Checklist",onAction:o,onSetup:e=>{const o=()=>{const o=t.selection.isEditable();e.setEnabled(!t.readonly&&o)};return t.on("NodeChange",o),o(),()=>t.off("NodeChange",o)}})};tinymce.PluginManager.add("checklist",(t=>{((t,o)=>!!t&&-1===((t,o)=>{const n=e(t.major,o.major);if(0!==n)return n;const r=e(t.minor,o.minor);if(0!==r)return r;const s=e(t.patch,o.patch);return 0!==s?s:0})((t=>n((t=>[t.majorVersion,t.minorVersion].join(".").split(".").slice(0,3).join("."))(t)))(t),n(o)))(tinymce,"6.0.0")?console.error("The Checklist Plugin requires at least version 6.0.0 of TinyMCE"):(t.on("init",(()=>{t.hasPlugin("lists",!0)||t.windowManager.alert("Please use the Checklist Plugin together with the Lists plugin.")})),(t=>{t.on("ListMutation",(t=>{const e=u.from(t.element).map(R);"IndentList"===t.action||"OutdentList"===t.action?e.map(tt).map((t=>f(((t,e)=>{const o=void 0===e?document:e.dom;return 1!==(n=o).nodeType&&9!==n.nodeType&&11!==n.nodeType||0===n.childElementCount?[]:g(o.querySelectorAll(t),R);var n})("ul",t),(t=>tt(t))))):"ToggleUlList"!==t.action&&"ToggleOlList"!==t.action&&"ToggleDLList"!==t.action||e.filter(_).map((t=>{P(t,"tox-checklist"),f($(t),(t=>P(t,"tox-checklist--checked")))}))}))})(t),mt(t),(t=>{t.shortcuts.add("meta+13","Check checklist item",(()=>{const e=t.selection.getSelectedBlocks();f(e,(t=>{const e=R(t);Q(e)&&Z(e)}))}))})(t),(t=>{const e=(t=>{let e=t;return{get:()=>e,set:t=>{e=t}}})(u.none());t.on("mousedown touchstart",(o=>{const n=R(o.target);!((t,e)=>e.exists((e=>"touchstart"===e.type&&"mousedown"===t.type&&t.timeStamp-e.timeStamp<250)))(o,e.get())&&Q(n)&&W(n,(t=>(t=>"touchstart"===t.type)(t)?t.touches[0].clientX:t.clientX)(o))&&(e.set(u.some(o)),t.undoManager.transact((()=>{o.preventDefault(),Z(n)})))}))})(t))}))}();