/*! * Tiny Comments plugin * * Copyright (c) 2023 Ephox Corporation DBA Tiny Technologies, Inc. * Licensed under the Tiny commercial license. See https://www.tiny.cloud/legal/ * * Version: 3.3.3-117 */ !function(){"use strict";const e=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},t=Object.getPrototypeOf,o=(e,t,o)=>{var n;return!!o(e,t.prototype)||(null===(n=e.constructor)||void 0===n?void 0:n.name)===t.name},n=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&o(e,String,((e,t)=>t.isPrototypeOf(e)))?"string":t})(t)===e,r=e=>t=>typeof t===e,s=e=>t=>e===t,a=n("string"),i=n("object"),c=e=>((e,n)=>i(e)&&o(e,n,((e,o)=>t(e)===o)))(e,Object),l=s(null),d=r("boolean"),m=s(void 0),u=e=>!(e=>null==e)(e),h=r("function"),_=r("number");class v{constructor(e,t){this.tag=e,this.value=t}static some(e){return new v(!0,e)}static none(){return v.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?v.some(e(this.value)):v.none()}bind(e){return this.tag?e(this.value):v.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:v.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 u(e)?v.some(e):v.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()"}}v.singletonNone=new v(!1);const p=e=>parseInt(e,10),g=(e,t)=>{const o=e-t;return 0===o?0:o>0?1:-1},y=(e,t,o)=>({major:e,minor:t,patch:o}),f=e=>{const t=/([0-9]+)\.([0-9]+)\.([0-9]+)(?:(\-.+)?)/.exec(e);return t?y(p(t[1]),p(t[2]),p(t[3])):y(0,0,0)};let b=0;const w=e=>{const t=(new Date).getTime(),o=Math.floor(1e9*Math.random());return b++,e+"_"+o+b+String(t)},S=()=>{},C=e=>()=>e,x=e=>e,O=e=>e(),A=C(!1),E=C(!0),R=Array.prototype.indexOf,D=(e,t)=>{const o=e.length,n=new Array(o);for(let r=0;r{for(let o=0,n=e.length;o{const o=[];for(let n=0,r=e.length;n((e,t,o)=>{for(let n=0,r=e.length;n{const o=L(e);for(let n=0,r=o.length;nP(e,((e,o)=>({k:o,v:t(e,o)}))),P=(e,t)=>{const o={};return U(e,((e,n)=>{const r=t(e,n);o[r.k]=r.v})),o},$=(e,t)=>N.call(e,t);"undefined"!=typeof window?window:Function("return this;")();const I=e=>t=>(e=>e.dom.nodeType)(t)===e,F=I(1),H=I(9),B=e=>t=>F(t)&&t.dom.nodeName.toLowerCase()===e,V=(e,t,o)=>{if(!(a(o)||d(o)||_(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+"")},Y=(e,t,o)=>{V(e.dom,t,o)},W=(e,t)=>{const o=e.dom.getAttribute(t);return null===o?void 0:o},G=(e,t)=>v.from(W(e,t)),q=(e,t)=>{e.dom.removeAttribute(t)},z=(e,t,o=0,n)=>{const r=e.indexOf(t,o);return-1!==r&&(!!m(n)||r+t.length<=n)},J=e=>t=>t.replace(e,""),K=J(/^\s+|\s+$/g),Q=J(/^\s+/g),X=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},Z=(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 X(o.childNodes[0])},ee=(e,t)=>{const o=(t||document).createElement(e);return X(o)},te=X,oe=e=>1!==e.nodeType&&9!==e.nodeType&&11!==e.nodeType||0===e.childElementCount,ne=e=>te(e.dom.ownerDocument),re=e=>v.from(e.dom.parentNode).map(te),se=e=>D(e.dom.childNodes,te),ae=h(Element.prototype.attachShadow)&&h(Node.prototype.getRootNode)?e=>te(e.dom.getRootNode()):e=>H(e)?e:ne(e),ie=()=>ce(te(document)),ce=e=>{const t=e.dom.body;if(null==t)throw new Error("Body is not available yet");return te(t)},le=(e,t)=>{e.dom.appendChild(t.dom)},de=e=>{e.dom.textContent="",k(se(e),(e=>{me(e)}))},me=e=>{const t=e.dom;null!==t.parentNode&&t.parentNode.removeChild(t)},ue=e=>{const t=se(e);var o,n;t.length>0&&(o=e,k(n=t,((e,t)=>{((e,t)=>{const o=(e=>v.from(e.dom.nextSibling).map(te))(e);o.fold((()=>{re(e).each((e=>{le(e,t)}))}),(e=>{((e,t)=>{re(e).each((o=>{o.dom.insertBefore(t.dom,e.dom)}))})(e,t)}))})(0===t?o:n[t-1],e)}))),me(e)},he=(e,t)=>{const o=ne(e).dom,n=te(o.createDocumentFragment());((e,t)=>{k(t,(t=>{le(e,t)}))})(n,((e,t)=>{const o=(t||document).createElement("div");return o.innerHTML=e,se(te(o))})(t,o)),de(e),le(e,n)},_e=()=>ve(0,0),ve=(e,t)=>({major:e,minor:t}),pe={nu:ve,detect:(e,t)=>{const o=String(t).toLowerCase();return 0===e.length?_e():((e,t)=>{const o=((e,t)=>{for(let o=0;oNumber(t.replace(o,"$"+e));return ve(n(1),n(2))})(e,o)},unknown:_e},ge=(e,t)=>{const o=String(t).toLowerCase();return M(e,(e=>e.search(o)))},ye=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,fe=e=>t=>z(t,e),be=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:e=>z(e,"edge/")&&z(e,"chrome")&&z(e,"safari")&&z(e,"applewebkit")},{name:"Chromium",brand:"Chromium",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,ye],search:e=>z(e,"chrome")&&!z(e,"chromeframe")},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:e=>z(e,"msie")||z(e,"trident")},{name:"Opera",versionRegexes:[ye,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:fe("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:fe("firefox")},{name:"Safari",versionRegexes:[ye,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:e=>(z(e,"safari")||z(e,"mobile/"))&&z(e,"applewebkit")}],we=[{name:"Windows",search:fe("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:e=>z(e,"iphone")||z(e,"ipad"),versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:fe("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"macOS",search:fe("mac os x"),versionRegexes:[/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:fe("linux"),versionRegexes:[]},{name:"Solaris",search:fe("sunos"),versionRegexes:[]},{name:"FreeBSD",search:fe("freebsd"),versionRegexes:[]},{name:"ChromeOS",search:fe("cros"),versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/]}],Se={browsers:C(be),oses:C(we)},Ce="Edge",xe="Chromium",Oe="Opera",Ae="Firefox",Ee="Safari",Re=e=>{const t=e.current,o=e.version,n=e=>()=>t===e;return{current:t,version:o,isEdge:n(Ce),isChromium:n(xe),isIE:n("IE"),isOpera:n(Oe),isFirefox:n(Ae),isSafari:n(Ee)}},De=()=>Re({current:void 0,version:pe.unknown()}),ke=Re,Te=(C(Ce),C(xe),C("IE"),C(Oe),C(Ae),C(Ee),"Windows"),Me="Android",Le="Linux",Ne="macOS",Ue="Solaris",je="FreeBSD",Pe="ChromeOS",$e=e=>{const t=e.current,o=e.version,n=e=>()=>t===e;return{current:t,version:o,isWindows:n(Te),isiOS:n("iOS"),isAndroid:n(Me),isMacOS:n(Ne),isLinux:n(Le),isSolaris:n(Ue),isFreeBSD:n(je),isChromeOS:n(Pe)}},Ie=()=>$e({current:void 0,version:pe.unknown()}),Fe=$e,He=(C(Te),C("iOS"),C(Me),C(Le),C(Ne),C(Ue),C(je),C(Pe),(e,t,o)=>{const n=Se.browsers(),r=Se.oses(),s=t.bind((e=>((e,t)=>((e,t)=>{for(let o=0;o{const o=t.brand.toLowerCase();return M(e,(e=>{var t;return o===(null===(t=e.brand)||void 0===t?void 0:t.toLowerCase())})).map((e=>({current:e.name,version:pe.nu(parseInt(t.version,10),0)})))})))(n,e))).orThunk((()=>((e,t)=>ge(e,t).map((e=>{const o=pe.detect(e.versionRegexes,t);return{current:e.name,version:o}})))(n,e))).fold(De,ke),a=((e,t)=>ge(e,t).map((e=>{const o=pe.detect(e.versionRegexes,t);return{current:e.name,version:o}})))(r,e).fold(Ie,Fe),i=((e,t,o,n)=>{const r=e.isiOS()&&!0===/ipad/i.test(o),s=e.isiOS()&&!r,a=e.isiOS()||e.isAndroid(),i=a||n("(pointer:coarse)"),c=r||!s&&a&&n("(min-device-width:768px)"),l=s||a&&!c,d=t.isSafari()&&e.isiOS()&&!1===/safari/i.test(o),m=!l&&!c&&!d;return{isiPad:C(r),isiPhone:C(s),isTablet:C(c),isPhone:C(l),isTouch:C(i),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:C(d),isDesktop:C(m)}})(a,s,e,o);return{browser:s,os:a,deviceType:i}}),Be=e=>window.matchMedia(e).matches,Ve=(e=>{let t,o=!1;return(...n)=>(o||(o=!0,t=e.apply(null,n)),t)})((()=>He(navigator.userAgent,v.from(navigator.userAgentData),Be)))().os.isMacOS()?"\u2318":"Ctrl",Ye=j({tc_menu_name:"TinyComments",tc_conversations_title:"Comments",tc_announce_sidebar_available:`Comment. Sidebar available. Press ${Ve} + Alt + M to switch to sidebar`,tc_items_addcomment:"Add comment",tc_items_showcomments:"Show comments",tc_items_deleteall:"Delete all conversations",tc_edit_buttons_save:"Save",tc_edit_buttons_cancel:"Cancel",tc_reply_buttons_comment:"Comment",tc_reply_buttons_clear:"Clear",tc_reply_placeholders:"Add comment...",tc_kebab_delete_conversation:"Delete conversation",tc_kebab_resolve_conversation:"Resolve conversation",tc_kebab_delete:"Delete",tc_kebab_edit:"Edit",tc_edit_problem_comment:"An error occurred editing this comment. See the console for details.",tc_edit_unauthorised_comment:"You are not allowed to edit this comment",tc_delete_buttons_cancel:"Cancel",tc_delete_buttons_proceed:"Delete",tc_resolve_buttons_proceed:"Resolve",tc_create_problem:"An error occurred while creating a comment. See the console for details",tc_reply_problem:"An error occurred while replying to a comment. See the console for details",tc_delete_prompts_conversation:"Delete this conversation?",tc_delete_prompts_conversation_detail_sing:"1 comment will be deleted. You can't undo this action.",tc_delete_prompts_conversation_detail_pl:"{0} comments will be deleted. You can't undo this action.",tc_delete_prompts_all:"Delete all conversations in the content? This cannot be undone.",tc_delete_prompts_comment:"Are you sure you want to delete this comment?",tc_resolve_prompts_conversation:"Resolve this conversation?",tc_resolve_prompts_conversation_detail_sing:"1 comment will be resolved. You can't undo this action.",tc_resolve_prompts_conversation_detail_pl:"{0} comments will be resolved. You can't undo this action.",tc_delete_problem_all:"An error occurred deleting all the conversations. See the console for details.",tc_delete_problem_conversation:"An error occurred deleting the conversation. See the console for details.",tc_delete_problem_comment:"An error occurred deleting the comment. See the console for details.",tc_delete_unauthorised_all:"You are not allowed to delete all the conversations",tc_delete_unauthorised_conversation:"You are not allowed to delete this conversation",tc_delete_unauthorised_comment:"You are not allowed to delete this comment",tc_resolve_unauthorised_conversation:"You are not allowed to resolve this conversation",tc_resolve_problem_conversation:"An error occurred resolving the conversation. See the console for details.",tc_date_less_than_a_minute_ago:"a moment ago",tc_date_1_minute_ago:"1 minute ago",tc_date_x_minutes_ago:"{0} minutes ago",tc_date_1_hour_ago:"1 hour ago",tc_date_x_hours_ago:"{0} hours ago",tc_date_1_day_ago:"1 day ago",tc_date_x_days_ago:"{0} days ago",tc_date_1_week_ago:"1 week ago",tc_date_x_weeks_ago:"{0} weeks ago",tc_date_1_month_ago:"1 month ago",tc_date_x_months_ago:"{0} months ago",tc_date_1_year_ago:"1 year ago",tc_date_x_years_ago:"{0} years ago",tc_date_comment_edited:" (edited)",tc_comment_buttons_showmore:"SHOW MORE",tc_comment_buttons_showless:"SHOW LESS"},x),We=w("aria-comment-description");let Ge=0;const qe=e=>{const t=(o=ie(),n=`#${We}`,((e,t)=>{const o=void 0===t?document:t.dom;return oe(o)?v.none():v.from(o.querySelector(e)).map(te)})(n,o)).getOrThunk((()=>{const e=ee("span");return((e,t)=>{const o=e.dom;U(t,((e,t)=>{V(o,t,e)}))})(e,{id:We,"aria-live":"polite","aria-atomic":"true",role:"alert"}),((e,t)=>{const o=e.dom;U({position:"absolute",left:"-10000px",top:"-1000px"},((e,t)=>{((e,t,o)=>{if(!a(o))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",o,":: Element ",e),new Error("CSS value must be a string: "+o);(e=>void 0!==e.style&&h(e.style.getPropertyValue))(e)&&e.style.setProperty(t,o)})(o,t,e)}))})(e),le(ie(),e),e}));var o,n;return Ge++,((e,t)=>({onComment:()=>{he(t,e.translate(Ye.tc_announce_sidebar_available))},notOnComment:()=>{he(t,"")},getMarker:()=>t,release:()=>{Ge--,0===Ge&&me(t)}}))(e,t)},ze=()=>(new Date).toISOString();var Je;!function(e){e[e.LessThanMinute=0]="LessThanMinute",e[e.Minute=1]="Minute",e[e.Hour=2]="Hour",e[e.Day=3]="Day",e[e.Week=4]="Week",e[e.Month=5]="Month",e[e.Year=6]="Year"}(Je||(Je={}));const Ke=e=>{e.dispatch("mce-tinycomments-update",{})},Qe=(e,t="")=>{const o=e.get(),n=""===t?0:Date.parse(t);return{timestamp:ze(),events:n>0?T(o,(e=>Date.parse(e.timestamp)>n)):o}},Xe=e=>(t={})=>a(t.after)?Qe(e,t.after):Qe(e),Ze=B("hr"),et=e=>{const t=te(e.selection.getNode()),o=te(e.selection.getStart());return(e=>{let t=e.selection.getRng().commonAncestorContainer;return 3===t.nodeType&&(t=t.parentNode),!!u(t)&&e.dom.isEmpty(t)})(e)||Ze(t)||Ze(o)},tt=(e,t)=>{const o=W(e,t);return void 0===o||""===o?[]:o.split(" ")},ot=e=>void 0!==e.dom.classList,nt=(e,t)=>{ot(e)?e.dom.classList.remove(t):((e,t)=>{((e,t,o)=>{const n=T(tt(e,t),(e=>e!==o));n.length>0?Y(e,t,n.join(" ")):q(e,t)})(e,"class",t)})(e,t),(e=>{const t=ot(e)?e.dom.classList:(e=>tt(e,"class"))(e);0===t.length&&q(e,"class")})(e)},rt=C("tox-comment"),st=C("tinycomments"),at=C("mce-annotation"),it=C("data-mce-annotation"),ct=C("data-mce-annotation-uid"),lt=C("data-mce-annotation-active"),dt=C("data-mce-annotation-classes"),mt=C("data-mce-annotation-attrs"),ut=C("tox-comments-visible"),ht=B("span"),_t=e=>{ht(e)?ue(e):(e=>{nt(e,at()),q(e,`${ct()}`),q(e,`${it()}`),q(e,`${lt()}`);const t=G(e,`${mt()}`).map((e=>e.split(","))).getOr([]),o=G(e,`${dt()}`).map((e=>e.split(","))).getOr([]);var n;k(t,(t=>q(e,t))),n=e,k(o,(e=>{nt(n,e)})),q(e,`${dt()}`),q(e,`${mt()}`)})(e)},vt=(e,t,o,n)=>(he(e,t),k(((e,t)=>((e,t)=>{const o=void 0===t?document:t.dom;return oe(o)?[]:D(o.querySelectorAll(e),te)})(t,e))(e,o),n),e.dom.innerHTML),pt=(e,t,o)=>{const n=ee("div");k(e,(e=>{if(e.content=vt(n,e.content,t,o),u(e.fragments))for(let r=0;r{e.on("init",(()=>{((e,t,o)=>{e.addCommand(gt,((e,n)=>{const r=o.get();t.refreshSidebar(r,n.grabFocus?1:0)}))})(e,t,r),((e,t)=>{e.addCommand("tc-delete-conversation-at-cursor",((o,n)=>{var r,s;et(e)||(e.undoManager.transact((()=>e.annotator.remove(st()))),r=e.undoManager.data,s=n.conversationUid,pt(r,(e=>`[${ct()}="${e}"]`)(s),_t),t.refreshSidebar(v.none(),2),e.focus())}))})(e,t),((e,t,o,n)=>{e.addCommand(yt,(()=>{et(e)||e.windowManager.confirm(Ye.tc_delete_prompts_all,(r=>{if(r)return o.deleteAllConversations({}).get((o=>{o.fold((e=>t.showError(Ye.tc_delete_problem_all,e)),(o=>{var r;o.canDelete?(n({type:"delete-all-conversations",timestamp:ze()}),e.annotator.removeAll(st()),r=e.undoManager.data,pt(r,`[${it()}="${st()}"]`,_t),e.undoManager.dispatchChange(),t.refreshSidebar(v.none(),2),e.focus()):t.showError(Ye.tc_delete_unauthorised_all)}))}))}))}))})(e,t,o,n)}))},bt=(e,t)=>{e.execCommand(gt,!1,{grabFocus:t},{skip_focus:!t})},wt=e=>{e.execCommand("ToggleSidebar",!1,"showcomments")},St=e=>{let t=v.none(),o=[];const n=e=>{r()?s(e):o.push(e)},r=()=>t.isSome(),s=e=>{t.each((t=>{setTimeout((()=>{e(t)}),0)}))};return e((e=>{r()||(t=v.some(e),k(o,s),o=[])})),{get:n,map:e=>St((t=>{n((o=>{t(e(o))}))})),isReady:r}},Ct={nu:St,pure:e=>St((t=>{t(e)}))},xt=e=>{setTimeout((()=>{throw e}),0)},Ot=e=>{const t=t=>{e().then(t,xt)};return{map:t=>Ot((()=>e().then(t))),bind:t=>Ot((()=>e().then((e=>t(e).toPromise())))),anonBind:t=>Ot((()=>e().then((()=>t.toPromise())))),toLazy:()=>Ct.nu(t),toCached:()=>{let t=null;return Ot((()=>(null===t&&(t=e()),t)))},toPromise:e,get:t}},At=e=>Ot((()=>new Promise(e))),Et=e=>Ot((()=>Promise.resolve(e))),Rt=e=>{const t=t=>t(e),o=C(e),n=()=>r,r={tag:!0,inner:e,fold:(t,o)=>o(e),isValue:E,isError:A,map:t=>kt.value(t(e)),mapError:n,bind:t,exists:t,forall:t,getOr:o,or:n,getOrThunk:o,orThunk:n,getOrDie:o,each:t=>{t(e)},toOptional:()=>v.some(e)};return r},Dt=e=>{const t=()=>o,o={tag:!1,inner:e,fold:(t,o)=>t(e),isValue:A,isError:E,map:t,mapError:t=>kt.error(t(e)),bind:t,exists:A,forall:E,getOr:x,or:x,getOrThunk:O,orThunk:O,getOrDie:(n=String(e),()=>{throw new Error(n)}),each:S,toOptional:v.none};var n;return o},kt={value:Rt,error:Dt,fromOption:(e,t)=>e.fold((()=>Dt(t)),Rt)},Tt=e=>({...e,toCached:()=>Tt(e.toCached()),bindFuture:t=>Tt(e.bind((e=>e.fold((e=>Et(kt.error(e))),(e=>t(e)))))),bindResult:t=>Tt(e.map((e=>e.bind(t)))),mapResult:t=>Tt(e.map((e=>e.map(t)))),mapError:t=>Tt(e.map((e=>e.mapError(t)))),foldResult:(t,o)=>e.map((e=>e.fold(t,o))),withTimeout:(t,o)=>Tt(At((n=>{let r=!1;const s=setTimeout((()=>{r=!0,n(kt.error(o()))}),t);e.get((e=>{r||(clearTimeout(s),n(e))}))})))}),Mt=e=>Tt(At(e)),Lt=e=>Tt(Et(kt.value(e))),Nt=e=>Tt(Et(kt.error(e))),Ut=e=>t=>Mt((o=>e(t,(e=>{o(kt.value(e))}),(e=>{o(kt.error(e))})))),jt=e=>t=>t.options.get(e),Pt=e=>t=>v.from(jt(e)(t)).filter(h),$t=e=>t=>Pt(e)(t).getOrDie(e+" has not been implemented."),It=(e,t)=>o=>{var n;return null!==(n=o.options.get(e))&&void 0!==n?n:t(o)},Ft=(e,t)=>o=>{const n=It(e,(()=>t(Jt(o))))(o);return Ut(n)},Ht=$t("tinycomments_create"),Bt=$t("tinycomments_reply"),Vt=$t("tinycomments_delete"),Yt=Pt("tinycomments_resolve"),Wt=$t("tinycomments_delete_all"),Gt=$t("tinycomments_delete_comment"),qt=$t("tinycomments_edit_comment"),zt=$t("tinycomments_lookup"),Jt=jt("tinycomments_author"),Kt=It("tinycomments_author_name",Jt),Qt=jt("tinycomments_author_avatar"),Xt=Ft("tinycomments_can_delete",(e=>(t,o,n)=>{o({canDelete:t.comments.length>0&&t.comments[0].author===e&&!0})})),Zt=Pt("tinycomments_can_resolve"),eo=Ft("tinycomments_can_delete_comment",(e=>(t,o,n)=>{o({canDelete:t.comment.author===e&&!0})})),to=Ft("tinycomments_can_edit_comment",(e=>(t,o,n)=>{o({canEdit:t.comment.author===e&&!0})})),oo=jt("tinycomments_mode"),no=jt("tinycomments_css_url"),ro=jt("tinycomments_js_url"),so=(ao=(e,t)=>c(e)&&c(t)?so(e,t):t,(...e)=>{if(0===e.length)throw new Error("Can't merge zero objects");const t={};for(let o=0;o{const t=Ht(e),o=Bt(e),n=zt(e),r=Vt(e),s=Yt(e),a=Wt(e),i=Gt(e),c=qt(e);return{create:Ut(t),reply:Ut(o),lookup:Ut((l=n,(e,t,o)=>{l(e,(e=>{const o=D(e.conversation.comments,(e=>({authorName:e.author,...e})));t(so(e,{conversation:{comments:o}}))}),o)})),deleteConversation:Ut(r),resolveConversation:s.map((e=>Ut(e))),deleteAllConversations:Ut(a),editComment:Ut(c),deleteComment:Ut(i),lifecycleHooks:{onPreInit:S,onGetContent:v.none}};var l},co={base64:{versions:["2.0","2.1"],encryptor:{encryptText:e=>{const t=new Blob([e],{type:"application/json"}),o=new FileReader;return Mt((e=>{o.addEventListener("loadend",(()=>e(kt.value({encrypted:[o.result]})))),o.addEventListener("error",(()=>e(kt.error(o.error||new Error("error decoding text"))))),o.readAsDataURL(t)}))},decryptText:e=>{return(t=e[0],(e=>{const t=e.split(","),o=/data:([^;]+)/.exec(t[0]);if(!o)return v.none();const n=o[1],r=t[1],s=1024,a=atob(r),i=a.length,c=Math.ceil(i/s),l=new Array(c);for(let e=0;eNt("Could not decode URI")),(e=>{const t=new FileReader;return Mt((o=>{t.addEventListener("loadend",(()=>o(kt.value({decrypted:t.result})))),t.addEventListener("error",(()=>{var e;return o(kt.error((null===(e=t.error)||void 0===e?void 0:e.message)||"error decoding text"))})),t.readAsText(e)}))}));var t}}}};co.current=co.base64;const lo=e=>((e,t)=>{const o=L(e);for(let n=0,r=o.length;n{return o=t.versions,n=o,r=e,R.call(n,r)>-1;var o,n,r})).map((e=>e.encryptor)),mo=(e,t,o)=>t===e?o:"2.0"===e?mo("2.1",t,(e=>({...e,authorName:e.author}))(o)):o,uo="tinycomments",ho="2.1",_o=e=>{return t=Q(e),""===(o=uo)||t.length>=o.length&&t.substr(0,0+o.length)===o;var t,o},vo=e=>{const t=K(e).split("|");return t.length>2?kt.value({version:t[1],rest:t.slice(2)}):kt.error("Embedded comments not in expected format.")},po=(e,t,o)=>((e,t)=>{const o=(e=>{try{const t=JSON.parse(e);return kt.value(t)}catch(e){return kt.error("Could not JSON parse conversations.")}})(t);return e!==ho?o.map((t=>j(t,(t=>({...t,comments:D(t.comments,(t=>mo(e,ho,t)))}))))):o})(e,o).map((e=>({conversations:e,encrypted:{encrypted:t}}))),go=e=>{const t=Jt(e),o=Kt(e),n=Qt(e),r=(()=>{let e={},t=v.none();const o=t=>Object.prototype.hasOwnProperty.call(e,t)?v.some(e[t]):v.none();return{get:()=>so(e,{}),clear:()=>{e={},t=v.none()},addData:(t,o)=>{e[t]=o},setData:(o,n)=>{e=o,t=v.some(n)},setEncryptedData:e=>{t=v.some(e)},getEncryptedData:()=>t,lookupData:o,removeData:t=>{delete e[t]},updateData:(t,n)=>o(t).map((o=>{const r=n(o);return e[t]=r,r}))}})(),s=Xt(e),a=eo(e),i=to(e),c=Zt(e).map((e=>Ut(e))),l={author:t,authorName:o},d=((e,t)=>{const o={};var n;return((e,t,o,n)=>{U(e,((e,r)=>{(t(e,r)?o:n)(e,r)}))})(e,t,(n=o,(e,t)=>{n[t]=e}),S),o})({authorAvatar:n},(e=>!m(e))),u=co.current.encryptor,h=()=>u.encryptText(JSON.stringify(r.get())).mapResult((e=>r.setEncryptedData(e))),_=c.map((e=>t=>r.lookupData(t.conversationUid).fold((()=>Nt("Could not find conversation to resolve")),(o=>e({conversationUid:o.uid,comments:o.comments}).bindFuture((e=>e.canResolve?(r.removeData(t.conversationUid),h().mapResult((()=>({canResolve:!0})))):Lt({canResolve:!1}))))))),p=(e,t,o,n)=>(e=>r.lookupData(e.conversationUid).fold((()=>kt.error(`Could not find conversation with uid ${e.conversationUid}`)),(t=>M(t.comments,(t=>t.uid===e.commentUid)).fold((()=>kt.error(`Could not find comment with uid ${e.commentUid} in conversation ${e.conversationUid}`)),(e=>kt.value({conversationUid:t.uid,comment:e}))))))(e).fold((e=>Nt(e)),(s=>o(s).bindFuture((o=>!0===o[t]?r.updateData(e.conversationUid,n(s)).fold((()=>Nt("Could not operate on comment ("+t+")")),(e=>h().mapResult((()=>({[t]:!0}))))):Lt({[t]:!1})))));return{create:e=>{const t=w("mce-conversation");return r.addData(t,{uid:t,comments:[{uid:t,...l,...d,content:e.content,createdAt:e.createdAt,modifiedAt:e.createdAt}]}),h().mapResult((()=>({conversationUid:t})))},reply:e=>{const t=w("mce-reply"),o={uid:t,...l,...d,content:e.content,createdAt:e.createdAt,modifiedAt:e.createdAt};return r.updateData(e.conversationUid,(e=>({...e,comments:e.comments.concat([o])}))).fold((()=>Nt("Could not reply to uid: "+e.conversationUid)),(()=>h().mapResult((()=>({commentUid:t})))))},lookup:e=>r.lookupData(e.conversationUid).fold((()=>Nt("Could not find uid: "+e.conversationUid)),(e=>Lt({conversation:e}))),deleteConversation:e=>r.lookupData(e.conversationUid).fold((()=>Nt("Could not find conversation to delete")),(t=>s({conversationUid:t.uid,comments:t.comments}).bindFuture((t=>t.canDelete?(r.removeData(e.conversationUid),h().mapResult((()=>({canDelete:!0})))):Lt({canDelete:!1}))))),resolveConversation:_,deleteAllConversations:()=>{const e=L(r.get()),t=D(e,(e=>r.lookupData(e).fold((()=>Nt("Could not find conversation")),(e=>s({conversationUid:e.uid,comments:e.comments})))));return Mt((e=>{var o;(o=t,((e,t)=>t((t=>{const o=[];let n=0;0===e.length?t([]):k(e,((r,s)=>{r.get((r=>s=>{o[r]=s,n++,n>=e.length&&t(o)})(s))}))})))(o,At)).get((t=>{const o=((e,t)=>{for(let t=0,o=e.length;te.canDelete)))return!1;return!0})(t);o&&r.clear(),e(kt.value({canDelete:o}))}))}))},deleteComment:e=>p(e,"canDelete",a,(e=>{return t=e.comment.uid,e=>({uid:e.uid,comments:T(e.comments,(e=>e.uid!==t))});var t})),editComment:e=>p(e,"canEdit",(t=>i({...t,edit:{modifiedAt:e.modifiedAt,content:e.content}})),(()=>{return t=e.commentUid,o=e.content,n=e.modifiedAt,e=>({uid:e.uid,comments:D(e.comments,(e=>e.uid===t?{...e,content:o,modifiedAt:n}:e))});var t,o,n})),lifecycleHooks:{onPreInit:t=>{e.parser.addNodeFilter("#comment",((e,t,o)=>{o.isRootContent&&(r.clear(),k(e,(e=>{const t=e.value;var o;t&&_o(t)&&(e.remove(),vo(t).each((e=>r.setEncryptedData({encrypted:e.rest}))),(o=t,_o(o)?vo(o).fold((e=>Nt(e)),(({version:e,rest:t})=>((e,t)=>lo(e).fold((()=>Nt(`No Encryptor for version: ${e}`)),(e=>e.decryptText(t))))(e,t).bindResult((({decrypted:o})=>po(e,t,o))))):Lt({conversations:{},encrypted:{encrypted:[]}})).get((e=>e.fold((e=>console.error("Error extracting embedded conversations: "+e)),(e=>{r.setData(e.conversations,e.encrypted)})))))})))}))},onGetContent:(e,t)=>r.getEncryptedData().map((e=>t+(e=>{const t=te(document.createComment((e=>[uo,ho,...e.encrypted].join("|"))(e)));return(e=>{const t=ee("div"),o=te(e.dom.cloneNode(!0));return le(t,o),(e=>e.dom.innerHTML)(t)})(t)})(e)))}}},yo=(e,t,o)=>{e.on("init",(()=>{e.annotator.register(st(),{decorate:()=>({classes:[rt()],attributes:{}})}),e.annotator.annotationChanged(st(),((e,n,r)=>{if(e){if(o.onComment(),r){const{uid:e,nodes:o}=r;t.refreshView(v.some({uid:e,nodes:D(o,te)}))}}else o.notOnComment(),t.refreshView(v.none())}));const n=((e,t)=>{let o=null;const n=()=>{l(o)||(clearTimeout(o),o=null)};return{cancel:n,throttle:(...t)=>{n(),o=setTimeout((()=>{o=null,e.apply(null,t)}),50)}}})((()=>{t.refreshReadonly()}));e.on("SelectionChange AfterSetSelectionRange",n.throttle),e.on("remove",n.cancel)}))},fo="mce-tinycomments-uistate-updated";var bo;!function(e){e[e.Open=0]="Open",e[e.Closed=1]="Closed",e[e.Closing=2]="Closing"}(bo||(bo={}));const wo=(e,t)=>()=>{var o,n;t.set(bo.Open),o=te(e.getBody()),n=ut(),ot(o)?o.dom.classList.add(n):((e,t)=>{((e,t,o)=>{const n=tt(e,t).concat([o]);Y(e,t,n.join(" "))})(e,"class",t)})(o,n),Ke(e),bt(e,!1)},So=(e,t)=>o=>{var n;(n=te(o.element()),((e=(()=>te(document))())=>v.from(e.dom.activeElement).map(te))(ae(n)).filter((e=>n.dom.contains(e.dom)))).each((t=>{e.focus()})),t.set(bo.Closed),nt(te(e.getBody()),ut()),Ke(e)},Co=(e,t,o)=>{t.isReadonly()||(o.get()!==bo.Closed&&o.get()!==bo.Closing||wt(e),bt(e,!0))},xo=(t,o)=>{const n=e(!1),r=e(v.none()),s=e([]);((e,t)=>{const o=e.options.register;o("tinycomments_css_url",{processor:"string",default:t+"/css"}),o("tinycomments_js_url",{processor:"string",default:t+"/js"}),o("tinycomments_mode",{processor:"string",default:"callback"}),o("tinycomments_author",{processor:"string",default:"Anon"}),o("tinycomments_author_name",{processor:"string"}),o("tinycomments_author_avatar",{processor:"string"}),k(["tinycomments_create","tinycomments_reply","tinycomments_lookup","tinycomments_delete","tinycomments_delete_all","tinycomments_delete_comment","tinycomments_can_delete","tinycomments_can_delete_comment","tinycomments_resolve","tinycomments_can_resolve","tinycomments_edit_comment","tinycomments_can_edit_comment"],(e=>o(e,{processor:"function"})))})(t,o);const i=(e=>("embedded"===oo(e)?go:io)(e))(t),c=(()=>{const t=e(v.none()),o=e(v.none());return{rememberSidebar:e=>{o.set(v.some(e)),t.get().fold((()=>{const t=Z('
\n
\n
\n
\n

Comments are loading

\n
\n
\n
\n
\n
\n
\n
');le(e,t)}),(t=>{t.attachTo(e)}))},setUi:e=>{t.set(v.some(e)),o.get().each((t=>{de(t),e.attachTo(t),e.controller.refreshReadonly()}))},refreshView:e=>{t.get().fold(S,(t=>{t.controller.refreshView(e)}))},refreshSidebar:(e,o)=>{t.get().fold(S,(t=>{t.controller.refreshSidebar(e,o)}))},setReadonly:e=>{t.get().each((t=>t.controller.setReadonly(e)))},setSaving:e=>{t.get().each((t=>t.controller.setSaving(e)))},showError:(e,o)=>{t.get().each((t=>t.controller.showError(e,o)))},isReadonly:()=>t.get().map((e=>e.controller.isReadonly())).getOr(!1),refreshReadonly:()=>t.get().map((e=>e.controller.refreshReadonly())).getOr(!1)}})(),l={translate:e=>tinymce.translate(e),getIcon:e=>{var o;return null!==(o=t.ui.registry.getAll().icons[e])&&void 0!==o?o:"temporary-placeholder"}};((e,t)=>tinymce.Resource.load("tinymce.plugins.tinycomments.sidebar",t))(0,(e=>ro(e)+"/")(t)+"tinycomments-sidebar.min.js").then((e=>e(t,i,r,s,(e=>{c.setUi(e),c.refreshSidebar(r.get(),5),n.set(!0)}),l)));const d=qe(l);return t.on("remove",d.release),ft(t,c,i,((e,t)=>o=>{const n=Xe(t);t.set(t.get().concat([o])),((e,t)=>{const o={getEventLog:t};e.dispatch("CommentChange",o)})(e,n)})(t,s),r),yo(t,c,d),((t,o)=>{const n=e(bo.Closed);t.shortcuts.add("meta+alt+m","TinyComments addComment",(()=>{Co(t,o,n)})),((e,t,o)=>{const n="comment-add",r=(o,n)=>{n(!t.isReadonly());const r=()=>{n(!t.isReadonly())};return e.on(fo,r),()=>e.off(fo,r)};e.ui.registry.addButton("addcomment",{tooltip:Ye.tc_items_addcomment,icon:n,onSetup:e=>r(e.isEnabled,e.setEnabled),onAction:()=>{e.selection.expand(),Co(e,t,o)}}),e.ui.registry.addMenuItem("addcomment",{text:Ye.tc_items_addcomment,shortcut:"meta+Alt+M",icon:n,onSetup:e=>r(e.isEnabled,e.setEnabled),onAction:()=>{e.selection.expand(),Co(e,t,o)}}),e.ui.registry.addMenuItem("deleteallconversations",{text:Ye.tc_items_deleteall,onAction:()=>{(e=>{e.execCommand(yt,!1,{})})(e)},onSetup:t=>{const o=e.annotator.getAll(st());return t.setEnabled(!(e=>{for(const t in e)if(N.call(e,t))return!1;return!0})(o)),S}}),e.ui.registry.addToggleMenuItem("showcomments",{text:Ye.tc_items_showcomments,icon:"comment",onAction:()=>wt(e),onSetup:t=>{const n=()=>{t.setActive(o.get()===bo.Open)};return e.on("mce-tinycomments-update",n),n(),()=>{e.off("mce-tinycomments-update",n)}}}),e.ui.registry.addSidebar("showcomments",{tooltip:Ye.tc_items_showcomments,icon:"comment",onSetup:e=>(t.rememberSidebar(te(e.element())),S),onShow:wo(e,o),onHide:So(e,o)})})(t,o,n)})(t,c),t.on("PostRender",(()=>{(e=>{var t,o,n;o=no(e)+"/tinycomments.css",(null!=(n=v.from(null===(t=e.ui)||void 0===t?void 0:t.styleSheetLoader).getOr(tinymce.DOM.styleSheetLoader))?n:tinymce.DOM.styleSheetLoader).load(o)})(t)})),t.on("init",(()=>{c.refreshSidebar(v.none(),5)})),t.on("PreInit",(()=>{i.lifecycleHooks.onPreInit(t)})),t.on("setContent",(e=>{e.selection||c.refreshView(v.none())})),t.on("SwitchMode",(()=>{c.setReadonly(t.readonly)})),t.on("GetContent",(e=>{if(a(e.content)){const o=!0===e.source_view,n=!0===e.contextual,r=!0===e.selection,s=o||n||r?v.none():i.lifecycleHooks.onGetContent(t,e.content);e.content=s.getOr(e.content)}})),((e,t)=>({getEventLog:Xe(t),hasLoadedUi:e.get}))(n,s)};tinymce.PluginManager.requireLangPack("tinycomments","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_PT,pt_BR,ro,ru,sk,sl_SI,sv_SE,th_TH,tr,uk,vi,zh_CN,zh_TW"),tinymce.PluginManager.add("tinycomments",((e,t)=>((e,t)=>!!e&&-1===((e,t)=>{const o=g(e.major,t.major);if(0!==o)return o;const n=g(e.minor,t.minor);if(0!==n)return n;const r=g(e.patch,t.patch);return 0!==r?r:0})((e=>f((e=>[e.majorVersion,e.minorVersion].join(".").split(".").slice(0,3).join("."))(e)))(e),f(t)))(tinymce,"6.1.0")?(console.error("The tinycomments plugin requires at least version 6.1.0 of TinyMCE."),{}):xo(e,t)))}();