UNPKG

tinymce

Version:

Web based JavaScript HTML WYSIWYG editor control.

1 lines 6.57 kB
!function(){"use strict";var t=tinymce.util.Tools.resolve("tinymce.PluginManager");const e=t=>e=>t===e,o=e(null),n=e(void 0),s=t=>"function"==typeof t;const r=()=>{};class a{tag;value;static singletonNone=new a(!1);constructor(t,e){this.tag=t,this.value=e}static some(t){return new a(!0,t)}static none(){return a.singletonNone}fold(t,e){return this.tag?e(this.value):t()}isSome(){return this.tag}isNone(){return!this.tag}map(t){return this.tag?a.some(t(this.value)):a.none()}bind(t){return this.tag?t(this.value):a.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:a.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(t??"Called getOrDie on None")}static from(t){return null==t?a.none():a.some(t)}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()"}}Array.prototype.slice;const i=(t,e)=>{const o=t.length,n=new Array(o);for(let s=0;s<o;s++){const o=t[s];n[s]=e(o,s)}return n};s(Array.from)&&Array.from;const l=Object.keys,c=Object.hasOwnProperty,u=(t,e)=>{const o=l(t);for(let n=0,s=o.length;n<s;n++){const s=o[n];e(t[s],s)}},g=(t,e)=>c.call(t,e),m=t=>{let e=t;return{get:()=>e,set:t=>{e=t}}},d=(h=(t,e)=>e,(...t)=>{if(0===t.length)throw new Error("Can't merge zero objects");const e={};for(let o=0;o<t.length;o++){const n=t[o];for(const t in n)g(n,t)&&(e[t]=h(e[t],n[t]))}return e});var h;const p=()=>{const t=(t=>{const e=m(a.none()),o=()=>e.get().each(t);return{clear:()=>{o(),e.set(a.none())},isSet:()=>e.get().isSome(),get:()=>e.get(),set:t=>{o(),e.set(a.some(t))}}})(r);return{...t,on:e=>t.get().each(e)}},y=(t,e,o=0,s)=>{const r=t.indexOf(e,o);return-1!==r&&(!!n(s)||r+e.length<=s)};var f=tinymce.util.Tools.resolve("tinymce.Resource");const v=t=>e=>e.options.get(t),b=v("emoticons_database"),w=v("emoticons_database_url"),j=v("emoticons_database_id"),C=v("emoticons_append"),_=v("emoticons_images_url"),A="All",k={symbols:"Symbols",people:"People",animals_and_nature:"Animals and Nature",food_and_drink:"Food and Drink",activity:"Activity",travel_and_places:"Travel and Places",objects:"Objects",flags:"Flags",user:"User Defined"},O=(t,e)=>g(t,e)?t[e]:e,x=t=>{const e=C(t);return o=t=>({keywords:[],category:"user",...t}),((t,e)=>{const o={};return u(t,(t,n)=>{const s=e(t,n);o[s.k]=s.v}),o})(e,(t,e)=>({k:e,v:o(t)}));var o},E=(t,e)=>y(t.title.toLowerCase(),e)||((t,e)=>{for(let o=0,n=t.length;o<n;o++)if(e(t[o]))return!0;return!1})(t.keywords,t=>y(t.toLowerCase(),e)),L=(t,e,o)=>{const n=[],s=e.toLowerCase();for(let r=0;r<t.length&&(0!==e.length&&!E(t[r],s)||(n.push({value:t[r].char,text:t[r].title,icon:t[r].char}),!o.exists(t=>n.length>=t)));r++);return n},S="pattern",N=(t,e)=>{const n={pattern:"",results:L(e.listAll(),"",a.none())},s=m(A),r=(t=>{let e=null;const n=()=>{o(e)||(clearTimeout(e),e=null)};return{cancel:n,throttle:(...o)=>{n(),e=setTimeout(()=>{e=null,t.apply(null,o)},200)}}})(t=>{(t=>{const o=t.getData(),n=s.get(),r=e.listCategory(n),i=L(r,o[S],a.none());t.setData({results:i})})(t)}),l={label:"Search",type:"input",name:S},c={type:"collection",name:"results"},u=()=>({title:"Emojis",size:"normal",body:{type:"tabpanel",dynamicHeight:!0,tabs:i(e.listCategories(),t=>({title:t,name:t,items:[l,c]}))},initialData:n,onTabChange:(t,e)=>{s.set(e.newTabName),r.throttle(t)},onChange:r.throttle,onAction:(e,o)=>{"results"===o.name&&(((t,e)=>{t.insertContent(e)})(t,o.value),e.close())},buttons:[{type:"cancel",text:"Close",primary:!0}]}),g=t.windowManager.open(u());g.focus(S),e.hasLoaded()||(g.block("Loading emojis..."),e.waitForLoad().then(()=>{g.redial(u()),r.throttle(g),g.focus(S),g.unblock()}).catch(t=>{g.redial({title:"Emojis",body:{type:"panel",items:[{type:"alertbanner",level:"error",icon:"warning",text:"Could not load emojis"}]},buttons:[{type:"cancel",text:"Close",primary:!0}],initialData:{pattern:"",results:[]}}),g.focus(S),g.unblock()}))},T=t=>e=>{const o=()=>{e.setEnabled(t.selection.isEditable())};return t.on("NodeChange",o),o(),()=>{t.off("NodeChange",o)}};t.add("emoticons",(t,e)=>{((t,e)=>{const o=t.options.register;o("emoticons_database",{processor:"string",default:"emojis"}),o("emoticons_database_url",{processor:"string",default:`${e}/js/${b(t)}${t.suffix}.js`}),o("emoticons_database_id",{processor:"string",default:"tinymce.plugins.emoticons"}),o("emoticons_append",{processor:"object",default:{}}),o("emoticons_images_url",{processor:"string",default:"https://cdnjs.cloudflare.com/ajax/libs/twemoji/15.1.0/72x72/"})})(t,e);const o=((t,e,o)=>{const n=p(),s=p(),r=_(t),i=t=>{return o="<img",(e=t.char).length>=4&&e.substr(0,4)===o?t.char.replace(/src="([^"]+)"/,(t,e)=>`src="${r}${e}"`):t.char;var e,o};t.on("init",()=>{f.load(o,e).then(e=>{const o=x(t);(t=>{const e={},o=[];u(t,(t,n)=>{const s={title:n,keywords:t.keywords,char:i(t),category:O(k,t.category)},r=void 0!==e[s.category]?e[s.category]:[];e[s.category]=r.concat([s]),o.push(s)}),n.set(e),s.set(o)})(d(e,o))},t=>{console.log(`Failed to load emojis: ${t}`),n.set({}),s.set([])})});const c=()=>s.get().getOr([]),g=()=>n.isSet()&&s.isSet();return{listCategories:()=>[A].concat(l(n.get().getOr({}))),hasLoaded:g,waitForLoad:()=>g()?Promise.resolve(!0):new Promise((t,o)=>{let n=15;const s=setInterval(()=>{g()?(clearInterval(s),t(!0)):(n--,n<0&&(console.log("Could not load emojis from url: "+e),clearInterval(s),o(!1)))},100)}),listAll:c,listCategory:t=>t===A?c():n.get().bind(e=>a.from(e[t])).getOr([])}})(t,w(t),j(t));return((t,e)=>{t.addCommand("mceEmoticons",()=>N(t,e))})(t,o),(t=>{const e=()=>t.execCommand("mceEmoticons");t.ui.registry.addButton("emoticons",{tooltip:"Emojis",icon:"emoji",onAction:e,onSetup:T(t)}),t.ui.registry.addMenuItem("emoticons",{text:"Emojis...",icon:"emoji",onAction:e,onSetup:T(t)})})(t),((t,e)=>{t.ui.registry.addAutocompleter("emoticons",{trigger:":",columns:"auto",minChars:2,fetch:(t,o)=>e.waitForLoad().then(()=>{const n=e.listAll();return L(n,t,a.some(o))}),onAction:(e,o,n)=>{t.selection.setRng(o),t.insertContent(n),e.hide()}})})(t,o),(t=>{t.on("PreInit",()=>{t.parser.addAttributeFilter("data-emoticon",t=>{((t,e)=>{for(let o=0,n=t.length;o<n;o++)e(t[o])})(t,t=>{t.attr("data-mce-resize","false"),t.attr("data-mce-placeholder","1")})})})})(t),{getAllEmojis:()=>o.waitForLoad().then(()=>o.listAll())}})}();