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

10 lines
20 KiB
JavaScript

/*!
* Tiny Footnotes plugin
*
* Copyright (c) 2022 Ephox Corporation DBA Tiny Technologies, Inc.
* Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/
*
* Version: 7.0.0-22
*/
!function(){"use strict";const e=e=>parseInt(e,10),t=(e,t)=>{const o=e-t;return 0===o?0:o>0?1:-1},o=(e,t,o)=>({major:e,minor:t,patch:o}),n=t=>{const n=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(t);return n?o(e(n[1]),e(n[2]),e(n[3])):o(0,0,0)},r=e=>t=>typeof t===e,i=e=>"string"===(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(o=n=e,(r=String).prototype.isPrototypeOf(o)||(null===(i=n.constructor)||void 0===i?void 0:i.name)===r.name)?"string":t;var o,n,r,i})(e),s=r("boolean"),a=e=>!(e=>null==e)(e),d=r("function"),l=r("number"),c=()=>{},m=e=>()=>e,u=(e,t)=>e===t,f=m(!1);class h{constructor(e,t){this.tag=e,this.value=t}static some(e){return new h(!0,e)}static none(){return h.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?h.some(e(this.value)):h.none()}bind(e){return this.tag?e(this.value):h.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:h.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 a(e)?h.some(e):h.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()"}}h.singletonNone=new h(!1);const g=Array.prototype.indexOf,p=(e,t)=>{return o=e,n=t,g.call(o,n)>-1;var o,n},y=(e,t)=>{for(let o=0,n=e.length;o<n;o++)if(t(e[o],o))return!0;return!1},v=(e,t)=>{const o=e.length,n=new Array(o);for(let r=0;r<o;r++){const o=e[r];n[r]=t(o,r)}return n},b=(e,t)=>{for(let o=0,n=e.length;o<n;o++)t(e[o],o)},x=(e,t)=>{const o=[];for(let n=0,r=e.length;n<r;n++){const r=e[n];t(r,n)&&o.push(r)}return o},w=(e,t,o)=>(b(e,((e,n)=>{o=t(o,e,n)})),o),T=e=>{const t=[],o=e=>{t.push(e)};for(let t=0;t<e.length;t++)e[t].each(o);return t},I=(e,t)=>k(e,t)?((e,t)=>e.substring(t))(e,t.length):e,k=(e,t)=>((e,t,o)=>""===t||e.length>=t.length&&e.substr(0,0+t.length)===t)(e,t),P=(D=/^\s+|\s+$/g,e=>e.replace(D,""));var D;const S="\xa0",C=Object.keys,N=Object.hasOwnProperty,E=(e,t)=>N.call(e,t);"undefined"!=typeof window?window:Function("return this;")();const $=e=>e.dom.nodeName.toLowerCase(),W=e=>e.dom.nodeType,A=e=>t=>W(t)===e,B=A(1),F=A(3),M=A(9),_=A(11),O=(e,t,o)=>{if(!(i(o)||s(o)||l(o)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",o,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,o+"")},U=(e,t,o)=>{O(e.dom,t,o)},j=(e,t)=>{const o=e.dom;((e,t)=>{const o=C(e);for(let n=0,r=o.length;n<r;n++){const r=o[n];t(e[r],r)}})(t,((e,t)=>{O(o,t,e)}))},L=(e,t)=>{const o=e.dom.getAttribute(t);return null===o?void 0:o},V=(e,t)=>h.from(L(e,t)),R=(e,t)=>{e.dom.removeAttribute(t)},q=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},H={fromHtml:(e,t)=>{const o=(t||document).createElement("div");if(o.innerHTML=e,!o.hasChildNodes()||o.childNodes.length>1){const t="HTML does not have a single root node";throw console.error(t,e),new Error(t)}return q(o.childNodes[0])},fromTag:(e,t)=>{const o=(t||document).createElement(e);return q(o)},fromText:(e,t)=>{const o=(t||document).createTextNode(e);return q(o)},fromDom:q,fromPoint:(e,t,o)=>h.from(e.dom.elementFromPoint(t,o)).map(q)},z=(e,t)=>{const o=e.dom;if(1!==o.nodeType)return!1;{const e=o;if(void 0!==e.matches)return e.matches(t);if(void 0!==e.msMatchesSelector)return e.msMatchesSelector(t);if(void 0!==e.webkitMatchesSelector)return e.webkitMatchesSelector(t);if(void 0!==e.mozMatchesSelector)return e.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")}},K=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,G=(e,t)=>e.dom===t.dom,J=z,Q=e=>void 0!==e.style&&d(e.style.getPropertyValue),X=e=>H.fromDom(e.dom.ownerDocument),Y=e=>M(e)?e:X(e),Z=e=>h.from(e.dom.parentNode).map(H.fromDom),ee=e=>h.from(e.dom.nextSibling).map(H.fromDom),te=e=>v(e.dom.childNodes,H.fromDom),oe=d(Element.prototype.attachShadow)&&d(Node.prototype.getRootNode)?e=>H.fromDom(e.dom.getRootNode()):Y,ne=e=>H.fromDom(e.dom.host),re=e=>{const t=F(e)?e.dom.parentNode:e.dom;if(null==t||null===t.ownerDocument)return!1;const o=t.ownerDocument;return(e=>{const t=oe(e);return _(o=t)&&a(o.dom.host)?h.some(t):h.none();var o})(H.fromDom(t)).fold((()=>o.body.contains(t)),(n=re,r=ne,e=>n(r(e))));var n,r},ie=(e,t)=>Q(e)?e.style.getPropertyValue(t):"",se=(e,t)=>{Z(e).each((o=>{o.dom.insertBefore(t.dom,e.dom)}))},ae=(e,t)=>{ee(e).fold((()=>{Z(e).each((e=>{de(e,t)}))}),(e=>{se(e,t)}))},de=(e,t)=>{e.dom.appendChild(t.dom)},le=(e,t)=>{b(t,((o,n)=>{const r=0===n?e:t[n-1];ae(r,o)}))},ce=(e,t)=>{b(t,(t=>{de(e,t)}))},me=(e,t)=>{let o=[];return b(te(e),(e=>{t(e)&&(o=o.concat([e])),o=o.concat(me(e,t))})),o},ue=(e,t,o)=>{let n=e.dom;const r=d(o)?o:f;for(;n.parentNode;){n=n.parentNode;const e=H.fromDom(n);if(t(e))return h.some(e);if(r(e))break}return h.none()},fe=e=>{e.dom.textContent="",b(te(e),(e=>{he(e)}))},he=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},ge=(e,t)=>((e,o)=>x(te(e),(e=>z(e,t))))(e),pe=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return K(o)?[]:v(o.querySelectorAll(e),H.fromDom)})(t,e),ye=(e,t,o)=>ue(e,(e=>z(e,t)),o),ve=(e,t)=>((e,o)=>{return(n=e.dom.childNodes,r=e=>{return o=H.fromDom(e),z(o,t);var o},((e,t,o)=>{for(let n=0,r=e.length;n<r;n++){const r=e[n];if(t(r,n))return h.some(r);if(o(r,n))break}return h.none()})(n,r,f)).map(H.fromDom);var n,r})(e),be=(e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return K(o)?h.none():h.from(o.querySelector(e)).map(H.fromDom)})(t,e),xe=((e,t)=>{const o=t=>e(t)?h.from(t.dom.nodeValue):h.none();return{get:t=>{if(!e(t))throw new Error("Can only get text value of a text node");return o(t).getOr("")},getOption:o,set:(t,o)=>{if(!e(t))throw new Error("Can only set raw text value of a text node");t.dom.nodeValue=o}}})(F);var we=["body","p","div","article","aside","figcaption","figure","footer","header","nav","section","ol","ul","li","table","thead","tbody","tfoot","caption","tr","td","th","h1","h2","h3","h4","h5","h6","blockquote","pre","address"];const Te=(e,t)=>({element:e,offset:t}),Ie=(e,t,o)=>e.property().isText(t)&&0===e.property().getText(t).trim().length||e.property().isComment(t)?o(t).bind((t=>Ie(e,t,o).orThunk((()=>h.some(t))))):h.none(),ke=(e,t)=>e.property().isText(t)?e.property().getText(t).length:e.property().children(t).length,Pe=(e,t)=>{const o=Ie(e,t,e.query().prevSibling).getOr(t);if(e.property().isText(o))return Te(o,ke(e,o));const n=e.property().children(o);return n.length>0?Pe(e,n[n.length-1]):Te(o,ke(e,o))},De=Pe,Se={up:m({selector:ye,closest:(e,t,o)=>((e,t,o,n,r)=>((e,t)=>z(e,t))(o,n)?h.some(o):d(r)&&r(o)?h.none():t(o,n,r))(0,ye,e,t,o),predicate:ue,all:(e,t)=>{const o=d(t)?t:f;let n=e.dom;const r=[];for(;null!==n.parentNode&&void 0!==n.parentNode;){const e=n.parentNode,t=H.fromDom(e);if(r.push(t),!0===o(t))break;n=e}return r}}),down:m({selector:pe,predicate:me}),styles:m({get:(e,t)=>{const o=e.dom,n=window.getComputedStyle(o).getPropertyValue(t);return""!==n||re(e)?n:ie(o,t)},getRaw:(e,t)=>{const o=e.dom,n=ie(o,t);return h.from(n).filter((e=>e.length>0))},set:(e,t,o)=>{((e,t,o)=>{if(!i(o))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",o,":: Element ",e),new Error("CSS value must be a string: "+o);Q(e)&&e.style.setProperty(t,o)})(e.dom,t,o)},remove:(e,t)=>{((e,t)=>{Q(e)&&e.style.removeProperty(t)})(e.dom,t),((e,t,o=u)=>e.exists((e=>o(e,t))))(V(e,"style").map(P),"")&&R(e,"style")}}),attrs:m({get:L,set:U,remove:R,copyTo:(e,t)=>{const o=w(e.dom.attributes,((e,t)=>(e[t.name]=t.value,e)),{});j(t,o)}}),insert:m({before:se,after:ae,afterAll:le,append:de,appendAll:ce,prepend:(e,t)=>{(e=>((e,t)=>{const o=e.dom.childNodes;return h.from(o[0]).map(H.fromDom)})(e))(e).fold((()=>{de(e,t)}),(o=>{e.dom.insertBefore(t.dom,o.dom)}))},wrap:(e,t)=>{se(e,t),de(t,e)}}),remove:m({unwrap:e=>{const t=te(e);t.length>0&&le(e,t),he(e)},remove:he}),create:m({nu:H.fromTag,clone:e=>H.fromDom(e.dom.cloneNode(!1)),text:H.fromText}),query:m({comparePosition:(e,t)=>e.dom.compareDocumentPosition(t.dom),prevSibling:e=>h.from(e.dom.previousSibling).map(H.fromDom),nextSibling:ee}),property:m({children:te,name:$,parent:Z,document:e=>Y(e).dom,isText:F,isComment:e=>8===W(e)||"#comment"===$(e),isElement:B,isSpecial:e=>{const t=$(e);return p(["script","noscript","iframe","noframes","noembed","title","style","textarea","xmp"],t)},getLanguage:e=>B(e)?V(e,"lang"):h.none(),getText:e=>xe.get(e),setText:(e,t)=>xe.set(e,t),isBoundary:e=>!!B(e)&&("body"===$(e)||p(we,$(e))),isEmptyTag:e=>!!B(e)&&p(["br","img","hr","input"],$(e)),isNonEditable:e=>B(e)&&"false"===L(e,"contenteditable")}),eq:G,is:J},Ce=(e,t)=>{(e=>void 0!==e.dom.classList)(e)?e.dom.classList.add(t):((e,t)=>{((e,t,o)=>{const n=((e,t)=>{const o=L(e,t);return void 0===o||""===o?[]:o.split(" ")})(e,t),r=n.concat([o]);U(e,t,r.join(" "))})(e,"class",t)})(e,t)},Ne=e=>e.dom.innerHTML,Ee=(e,t,o)=>ye(e,t,o).isSome(),$e=(e,t)=>{e.dom.textContent=t},We="footnote",Ae="mce-footnote",Be="mce-footnotes",Fe="footnotes_entry",Me="mce-footnotes-backlink",_e="mce-footnotes-note",Oe="sup",Ue="div",je="li",Le="span",Ve='[contenteditable="false"]',Re=e=>`${Oe}.${Ae}${i(e)?`#${e}`:""}${Ve}`,qe=`${Ue}.${Be}${Ve}`,He=e=>`${je}#${e}`,ze=`a.${Me}`,Ke=`${Le}.${_e}[contenteditable="true"]`,Ge=e=>`${We}_${e}`,Je=e=>`${Fe}_${e}`,Qe=e=>t=>I(t,e+"_"),Xe=Qe(We),Ye=Qe(Fe),Ze=e=>e.startsWith(We+"_"),et=e=>e.startsWith(Fe+"_"),tt=e=>{const t=e.getBody(),o=e.selection.getStart(),n=`${qe} ${je}`;return h.from(e.dom.getParent(o,n,t)).bind((o=>h.from(e.dom.getParent(o,qe,t)).map((e=>({section:H.fromDom(e),entry:H.fromDom(o)})))))},ot=(nt=e=>a(e.dom.getParent(e.selection.getStart(),qe,e.getBody())),e=>!nt(e));var nt;const rt=e=>H.fromDom(e.getBody()),it=(st=je,e=>B(e)&&$(e)===st);var st;const at=e=>be(e,qe),dt=e=>ve(e,"ol"),lt=e=>ve(e,Ke),ct=e=>V(e,"id").filter(et),mt=e=>it(e)&&ct(e).isSome()&&Ee(e,qe),ut=(e,t)=>at(rt(e)).bind(dt).bind((e=>((e,t)=>ve(e,He(t)))(e,t))).bind(lt).each((t=>{ft(e,t),e.selection.scrollIntoView(void 0,!0)})),ft=(e,t)=>{const o=e.dom.createRng(),n=De(Se,t);o.setStart(n.element.dom,n.offset),o.setEnd(n.element.dom,n.offset),e.selection.setRng(o)},ht=e=>ct(e).bind((t=>lt(e).map(Ne).bind((o=>{return(n=e,ve(n,ze)).bind((e=>V(e,"href"))).map((e=>({entryIdWithPrefix:t,note:o,backlinkIdWithPrefix:e})));var n})))),gt=e=>{const t=H.fromTag(je),o=H.fromTag("a");Ce(o,Me),$e(o,`^${S}`);const n=H.fromTag(Le);Ce(n,_e),U(n,"contenteditable",!0);return((e,t)=>{const o=X(e).dom,n=H.fromDom(o.createDocumentFragment()),r=((e,t)=>{const o=(t||document).createElement("div");return o.innerHTML=e,te(H.fromDom(o))})(t,o);ce(n,r),fe(e),de(e,n)})(n,e.note.length>0?e.note:'<br data-mce-bogus="1">'),de(t,o),de(t,n),U(t,"id",e.entryIdWithPrefix),U(o,"href",e.backlinkIdWithPrefix),t};let pt=0;const yt=e=>{const t=pe(e,Re());return x(t,(t=>{return n=e,!(((e,t)=>{const o=e.dom;return!(!o||!o.hasAttribute)&&o.hasAttribute("data-mce-bogus")})(o=t)||Ee(o,'[data-mce-bogus="all"]',(e=>t=>G(t,e))(n)));var o,n}))},vt=e=>be(e,"a"),bt=()=>(e=>{const t=(new Date).getTime(),o=Math.floor(1e9*Math.random());return pt++,e+"_"+o+pt+String(t)})(We),xt=e=>{return(t=e,V(t,"id").filter(Ze)).bind((t=>vt(e).bind((e=>(e=>V(e,"data-mce-href").orThunk((()=>V(e,"href"))).bind((e=>{return t=e,k(e,"#")?h.some(t):h.none();var t})))(e).map((o=>{var n,r;return{footnoteIdWithPrefix:t,symbol:null!==(r=e,n=r.dom.textContent)&&void 0!==n?n:"",forwardlinkIdWithPrefix:o}}))))));var t},wt=(e,t,o)=>{U(e,"id",o.footnoteIdWithPrefix),$e(t,o.symbol),U(t,"href",o.forwardlinkIdWithPrefix),U(t,"data-mce-href",o.forwardlinkIdWithPrefix)},Tt=(e,t)=>{const o=yt(e),n=x(o,(e=>xt(e).isSome()));b(n,((e,o)=>{var n,r;n=e,r=t[o],vt(n).each((e=>{wt(n,e,r)}))}))},It=(e,t,o)=>{const n=w(t,((e,t)=>({...e,[Ye(t.entryIdWithPrefix)]:t})),{}),r=w(e,((e,t,r)=>{const i=Xe(t.footnoteIdWithPrefix),s={newBaseId:E(e.existingIds,i)?Xe(o(i)):i,note:(a=n,d=i,E(a,d)?h.from(a[d]):h.none()).map((e=>e.note)).getOr(""),symbol:String(r+1)};var a,d;return{intexts:e.intexts.concat([s]),existingIds:{...e.existingIds,[i]:!0}}}),{existingIds:{},intexts:[]}),i=v(r.intexts,(e=>({note:e.note,entryIdWithPrefix:Je(e.newBaseId),backlinkIdWithPrefix:`#${Ge(e.newBaseId)}`})));return{intext:v(r.intexts,(e=>({footnoteIdWithPrefix:Ge(e.newBaseId),forwardlinkIdWithPrefix:`#${Je(e.newBaseId)}`,symbol:e.symbol}))),entries:i}},kt=(e,t)=>{(e=>{b(yt(e),he)})(t);const o=(e=>{const t=e.getBody();return at(H.fromDom(t)).bind((t=>{if("1"===L(t,"data-mce-selected")||((e,t)=>tt(e).filter((({section:e})=>G(t,e))).isSome())(e,t)){const o=e.dom.createRng();return o.setStartBefore(t.dom),o.setEndBefore(t.dom),he(t),h.some(o)}return he(t),h.none()}))})(e);e.dom.isEmpty(e.getBody())?(e.setContent(""),e.selection.setCursorLocation()):o.each(e.selection.setRng)},Pt=(e,t)=>{const o=rt(e),{addUndo:n,isDeleteTrigger:r}=t,i=(e=>{const t=yt(e);return T(v(t,xt))})(o),s=(e=>{const t=at(e),o=(e=>at(e).bind(dt).map((e=>ge(e,je))).getOr([]))(e);return t.map((e=>({entries:T(v(o,ht))})))})(o),a=((e,t,o)=>e.section.fold((()=>e.intext.length>0?o?{kind:"remove-footnotes"}:((e,t)=>{const{intext:o,entries:n}=It(e,[],t);return{kind:"insert-footnotes",newFootnotes:{intext:o,entries:n}}})(e.intext,t):{kind:"noop-footnotes"}),(o=>e.intext.length>0?((e,t,o)=>{const{intext:n,entries:r}=It(e,t,o);return n.length!==e.length||y(n,((t,o)=>t.footnoteIdWithPrefix!==e[o].footnoteIdWithPrefix||t.symbol!==e[o].symbol||t.forwardlinkIdWithPrefix!==e[o].forwardlinkIdWithPrefix))||r.length!==t.length||y(r,((e,o)=>e.entryIdWithPrefix!==t[o].entryIdWithPrefix||e.backlinkIdWithPrefix!==t[o].backlinkIdWithPrefix||e.note!==t[o].note))?{kind:"update-footnotes",newFootnotes:{intext:n,entries:r}}:{kind:"noop-footnotes"}})(e.intext,o.entries,t):{kind:"remove-footnotes"})))({intext:i,section:s},bt,r),d=n?e.undoManager.transact:e.undoManager.ignore;switch(a.kind){case"noop-footnotes":return;case"remove-footnotes":return void d((()=>{kt(e,o)}));case"insert-footnotes":return void d((()=>{Tt(o,a.newFootnotes.intext),((e,t)=>{const o=(e=>{const t=(()=>{const e=H.fromTag(Ue);return j(e,{contentEditable:!1}),Ce(e,Be),e})(),o=H.fromTag("hr"),n=H.fromTag("ol");return ce(n,e),de(t,o),de(t,n),t})(v(t,gt));de(e,o)})(o,a.newFootnotes.entries)}));case"update-footnotes":return void d((()=>{Tt(o,a.newFootnotes.intext),((e,t)=>{tt(e).bind((({entry:e,section:t})=>ct(e).map((e=>({entryId:e,section:t}))))).filter((({section:t})=>at(rt(e)).exists((e=>G(e,t))))).fold((()=>t()),(o=>{const n=t(),r=`${He(o.entryId)} ${Ke}`;return be(o.section,r).orThunk((()=>{const e=`${je} ${Ke}`;return be(o.section,e)})).each((t=>ft(e,t))),n}))})(e,(()=>{((e,t)=>{const o=v(t,gt);at(e).bind(dt).each((e=>{fe(e),ce(e,o)}))})(o,a.newFootnotes.entries)}))}))}},Dt=e=>{e.addCommand("mceInsertFootnote",((t,o)=>{e.selection.isEditable()&&(e=>{ot(e)&&e.undoManager.transact((()=>{const t=(e=>{const t=bt(),o=Xe(t);return e.undoManager.ignore((()=>{const o=((e,t)=>{const o=H.fromTag(Oe);U(o,"contenteditable","false"),Ce(o,Ae);const n=H.fromTag("a");return de(o,n),wt(o,n,{footnoteIdWithPrefix:e,symbol:t,forwardlinkIdWithPrefix:`#${Je(Xe(e))}`}),o})(t,S),n=(e=>{const t=H.fromTag("div"),o=H.fromDom(e.dom.cloneNode(!0));return de(t,o),Ne(t)})(o);e.selection.collapse(!1),e.insertContent(n,{no_events:!0})})),o})(e);Pt(e,{addUndo:!1,isDeleteTrigger:!1}),ut(e,Je(t))}))})(e)})),e.addCommand("mceUpdateFootnotes",((t,o)=>{e.selection.isEditable()&&Pt(e,{addUndo:!0,isDeleteTrigger:!1})}))},St=tinymce.util.VK,Ct=e=>l(null==e?void 0:e.nodeType),Nt=e=>{e.on("init",(()=>{e.on("click",(t=>{h.from(t.target).filter(Ct).bind((t=>((e,t)=>h.from(e.dom.getParent(t,"a[href]")).map(H.fromDom))(e,t))).each((o=>{const n=((e,t,o)=>V(t,"href").filter((e=>/^#/.test(e))).map((e=>I(e,"#"))).exists((t=>Ze(t)?(((e,t)=>{((e,t)=>be(e,Re(t)))(rt(e),t).each((t=>e.selection.scrollIntoView(t.dom,!0)))})(e,t),!0):!(!et(t)||!o||(ut(e,t),0)))))(e,o,St.metaKeyPressed(t));n&&t.preventDefault()}))}))}))},Et=tinymce.html.Node,$t=e=>{var t,o;return null!==(o=null===(t=e.attr("class"))||void 0===t?void 0:t.split(" "))&&void 0!==o?o:[]},Wt=(e,t)=>{const o=$t(e).concat(t);e.attr("class",o.join(" "))},At=e=>{const t=new Et("br",1);t.attr("data-mce-bogus","1"),e.empty(),e.append(t)},Bt=e=>{const t=new Et("#text",3);t.value=S,e.empty(),e.append(t)},Ft=e=>e.name===Ue&&p($t(e),Be),Mt=e=>{const t=e.attr("id");return e.name===je&&a(t)&&et(t)},_t=e=>{const t=e.attr("id");return e.name===Oe&&a(t)&&Ze(t)},Ot=e=>{let t=e.parent;for(;a(t);){if(Ft(t))return t;t=t.parent}},Ut=e=>{const t=e.children();for(let e=t.length-1;e>=0;e--){const n=t[e];if((o=n).name===Le&&p($t(o),_e))return n}var o},jt=e=>{const t=[],o=[];for(let n=0;n<e.length;n++){const r=e[n];if(Mt(r)){const e=Ot(r);if(a(e)){const t=o.find((t=>t.node===e));a(t)?t.entries.push(r):o.push({node:e,entries:[r]})}}else _t(r)&&t.push(r)}return{intextFootnotes:t,footnotesSections:o}},Lt=e=>l(null==e?void 0:e.nodeType);tinymce.PluginManager.requireLangPack("footnotes","ar,bg_BG,ca,cs,da,de,el,es,eu,fa,fi,fr_FR,he_IL,hi,hr,hu_HU,id,it,ja,kk,ko_KR,ms,nb_NO,nl,pl,pt_BR,pt_PT,ro,ru,sk,sl_SI,sv_SE,th_TH,tr,uk,vi,zh_CN,zh_TW"),tinymce.PluginManager.add("footnotes",(e=>{((e,o)=>!!e&&-1===((e,o)=>{const n=t(e.major,o.major);if(0!==n)return n;const r=t(e.minor,o.minor);if(0!==r)return r;const i=t(e.patch,o.patch);return 0!==i?i:0})((e=>n((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),n(o)))(tinymce,"6.4.0")?console.error("The footnotes plugin requires at least version 6.4.0 of TinyMCE."):(Dt(e),(e=>{const t=()=>e.execCommand("mceInsertFootnote"),o=()=>e.execCommand("mceUpdateFootnotes"),n=t=>{const o=()=>t.setEnabled(e.selection.isEditable()&&ot(e));return o(),e.on("NodeChange",o),()=>e.off("NodeChange",o)};e.ui.registry.addButton("footnotes",{icon:"footnote",tooltip:"Insert footnote",onAction:t,onSetup:n}),e.ui.registry.addMenuItem("footnotes",{icon:"footnote",text:"Insert footnote",onAction:t,onSetup:n}),e.ui.registry.addButton("footnotesupdate",{icon:"reload",tooltip:"Update footnotes",onAction:o}),e.ui.registry.addMenuItem("footnotesupdate",{icon:"reload",text:"Update footnotes",onAction:o})})(e),(e=>{e.on("PreInit",(()=>{e.serializer.addAttributeFilter("id",(e=>{const t=jt(e);for(const e of t.intextFootnotes)e.attr("contenteditable",null);for(const e of t.footnotesSections){const t=e.node,o=e.entries;t.attr("contenteditable",null);for(const e of o){const t=Ut(e);if(a(t))t.attr("contenteditable",null);else{const t=new Et(Le,1);Wt(t,[_e]),Bt(t),e.append(t)}}}})),e.parser.addAttributeFilter("id",(e=>{var t;const o=jt(e);for(const e of o.intextFootnotes)e.attr("contenteditable","false");for(const e of o.footnotesSections){const o=e.node,n=e.entries;o.attr("contenteditable","false");for(const e of n){const o=Ut(e);a(o)&&(o.firstChild===o.lastChild&&(null===(t=o.firstChild)||void 0===t?void 0:t.value)===S&&At(o),o.attr("contenteditable","true"))}}}))}))})(e),Nt(e),(e=>{e.on("PreInit",(()=>{e.on("mousedown tap",(t=>{h.from(t.target).filter(Lt).map(H.fromDom).filter(mt).filter((t=>lt(t).exists((t=>e.dom.isEmpty(t.dom))))).bind(ct).each((o=>{t.preventDefault(),ut(e,o)}))}))}))})(e),(e=>{const t=(()=>{const e=(e=>{const t=(e=>{let t=e;return{get:()=>t,set:e=>{t=e}}})(h.none()),o=()=>t.get().each(e);return{clear:()=>{o(),t.set(h.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{o(),t.set(h.some(e))}}})(c);return{...e,on:t=>e.get().each(t)}})();e.on("ExecCommand",(t=>{const o=t.command.toLowerCase();"delete"!==o&&"forwarddelete"!==o||Pt(e,{addUndo:!1,isDeleteTrigger:!0})}),!0),e.on("input",(o=>{var n;("insertParagraph"===(n=o.inputType)||"insertLineBreak"===n||"insertFromPaste"===n||"insertFromDrop"===n||"insertReplacementText"===n)&&(Pt(e,{addUndo:!1,isDeleteTrigger:!0}),t.clear())})),e.on("keydown",(()=>{t.set(!e.selection.isCollapsed())}),!0),e.on("keyup",(o=>{const n=o.keyCode,r=8===n||46===n;(t.get().getOr(!1)||r)&&Pt(e,{addUndo:!1,isDeleteTrigger:!0}),t.clear()})),e.on("dragend",(()=>{Pt(e,{addUndo:!1,isDeleteTrigger:!1})})),e.on("SetContent",(t=>{"raw"!==t.format&&Pt(e,{addUndo:!1,isDeleteTrigger:!t.set})}))})(e))}))}();