Since TinyMCE seems to require you to use a selector and will not allow you to simply pass an instance of the element (and the developer does not seem to understand the usefulness of this use case based on its answers in the forum), your best thing would be to do something like this:
View
<template> <textarea id.one-time="uniqueId" ...other bindings go here...></textarea> </template>
ViewModel
export class TinyMceCustomElement { constructor() { this.uniqueId = generateUUID(); } attached() { tinymce.init({ selector: `#${this.uniqueId}`, inline: true, menubar: false, toolbar: 'undo redo' }); } } function generateUUID() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); }); }
My UUID function comes from here: Create GUID / UUID in JavaScript?
source share