{"version":3,"file":"tinymce-public-B33nb2ZW.js","sources":["../../../app/frontend/entrypoints/tinymce-public.js"],"sourcesContent":["import \"tinymce\";\nimport 'tinymce/themes/silver/theme';\nimport 'tinymce/models/dom';\nimport 'tinymce/plugins/wordcount';\nimport 'tinymce/plugins/autoresize';\nimport 'tinymce/icons/default';\nimport 'tinymce/skins/content/default/content';\n\nwindow.addEventListener('turbo:load', () => {\n initializeTinymce();\n});\n\nfunction initializeTinymce() {\n // remove old editors (from previous page visit, preserved by Turbo)\n if (tinymce) tinymce.remove();\n\n // Initialize on all textareas\n const textareas = document.querySelectorAll(\"textarea[data-tinymce]\");\n textareas.forEach((el) => initializeEditor(el, \"textarea\"));\n\n // Initialize on all textfields\n const textfields = document.querySelectorAll(\"input[data-tinymce]\");\n textfields.forEach((el) => initializeEditor(el, \"textfield\"));\n}\n\nfunction initializeEditor(el, type) {\n const id = el.getAttribute('id');\n const maxChars = Number(el.getAttribute('maxlength'));\n const hasMaxChars = !!maxChars;\n const font = window.getComputedStyle(el).fontFamily;\n const focusColor = window.getComputedStyle(el).getPropertyValue('--color-focus-outline')\n const placeholderCss = '.mce-content-body[data-mce-placeholder] {position: relative;} .mce-content-body[data-mce-placeholder]:not(.mce-visualblocks)::before {color: rgba(34, 47, 62, 0.7); content: attr(data-mce-placeholder); position: absolute; left: 1px;}'\n // We will only handle maxChars if this was enabled for this form field\n\n const css = `body { font-family: ${font}; font-size: 16px; line-height: 1.5; margin: 12px;}` + 'p { margin: 0 0 4px 0; }' + placeholderCss;\n const height = type === 'textarea' ? 160 : 50;\n const plugins = type === 'textarea' ? ['autoresize', 'wordcount'] : ['wordcount'];\n\n tinymce.init({\n selector: `#${id}`,\n // We don't need a skin, since we load our own styling.\n licence_key: 'gpl',\n skin: false,\n height: height,\n width: '100%',\n min_height: height,\n menubar: false,\n statusbar: false,\n branding: false,\n elementpath: false,\n entity_encoding: 'raw',\n toolbar: false,\n autoresize_bottom_margin: 0,\n plugins: plugins,\n content_style: css,\n smart_paste: false,\n paste_block_drop: true,\n paste_data_images: false,\n paste_as_text: true,\n text_patterns: false,\n setup: function (editor) {\n var charsCount = 0;\n\n // handle input event\n // we only load the rhetoric feedback when needed\n if (el.dataset.nudgingActive) {\n editor.on('input', () => {\n // we let input trigger a custom event on the textarea that contains the content,\n // so that Alpine.js can react to it\n const content = editor.getContent({ format: 'text' });\n const event = new CustomEvent('commentInput', { detail: content });\n el.dispatchEvent(event);\n });\n };\n\n if (hasMaxChars) {\n editor.on('input', (e) => {\n // we delay the truncate to let the content be updated if maxChars counter is present\n if (hasMaxChars) { charsCount = asyncTruncate(editor, maxChars) };\n });\n };\n\n // update counter on backspace and delete (= not an input event)\n editor.on('keyup', function (event) {\n if (hasMaxChars && [8, 46].includes(event.keyCode)) {\n charsCount = updateCharsCounter(editor, maxChars);\n }\n });\n\n editor.on('focusin', function (e) {\n el.parentNode.querySelector('.tox-tinymce').style.outline = `2px solid ${focusColor}`;\n });\n\n editor.on('focusout', function (e) {\n el.parentNode.querySelector('.tox-tinymce').style.outline = '';\n });\n\n // text fields should not allow enter (= keycode 13) to insert newlines\n if (type === 'textfield') {\n editor.on('keydown', function (e) {\n if (e.keyCode == 13) {\n e.preventDefault();\n }\n });\n };\n\n editor.on('init', function (e) {\n editor.addShortcut(\"meta+b\", \"\", \"\");\n editor.addShortcut(\"meta+i\", \"\", \"\");\n editor.addShortcut(\"meta+u\", \"\", \"\");\n editor.addShortcut(\"ctrl+b\", \"\", \"\");\n editor.addShortcut(\"ctrl+i\", \"\", \"\");\n editor.addShortcut(\"ctrl+u\", \"\", \"\");\n });\n }\n });\n}\n\nfunction updateCharsCounter(editor, maxChars) {\n const charsCount = editor.plugins.wordcount.body.getCharacterCount();\n editor.targetElm.parentNode.querySelector('.remaining-chars').innerHTML = maxChars - charsCount;\n return charsCount;\n}\n\nfunction truncateContent(editor, maxChars) {\n var content = editor.getContent({ format: 'text' });\n if (content.length > maxChars) {\n\n const bookmark = editor.selection.getBookmark(2, true);\n editor.setContent(content.substring(0, maxChars));\n editor.selection.moveToBookmark(bookmark);\n }\n}\n\nasync function asyncTruncate(editor, maxChars) {\n await truncateContent(editor, maxChars);\n\n return updateCharsCounter(editor, maxChars);\n}\n\n"],"names":["initializeTinymce","el","initializeEditor","type","id","maxChars","hasMaxChars","font","focusColor","css","height","plugins","editor","content","event","e","asyncTruncate","updateCharsCounter","charsCount","truncateContent","bookmark"],"mappings":"oEAQA,OAAO,iBAAiB,aAAc,IAAM,CAC1CA,EAAmB,CACrB,CAAC,EAED,SAASA,GAAoB,CAEvB,SAAS,QAAQ,OAAQ,EAGX,SAAS,iBAAiB,wBAAwB,EAC1D,QAASC,GAAOC,EAAiBD,EAAI,UAAU,CAAC,EAGvC,SAAS,iBAAiB,qBAAqB,EACvD,QAASA,GAAOC,EAAiBD,EAAI,WAAW,CAAC,CAC9D,CAEA,SAASC,EAAiBD,EAAIE,EAAM,CAClC,MAAMC,EAAKH,EAAG,aAAa,IAAI,EACzBI,EAAW,OAAOJ,EAAG,aAAa,WAAW,CAAC,EAC9CK,EAAc,CAAC,CAACD,EAChBE,EAAO,OAAO,iBAAiBN,CAAE,EAAE,WACnCO,EAAa,OAAO,iBAAiBP,CAAE,EAAE,iBAAiB,uBAAuB,EAIjFQ,EAAM,uBAAuBF,CAAI,8EAHhB,2OAIjBG,EAASP,IAAS,WAAa,IAAM,GACrCQ,EAAUR,IAAS,WAAa,CAAC,aAAc,WAAW,EAAI,CAAC,WAAW,EAEhF,QAAQ,KAAK,CACX,SAAU,IAAIC,CAAE,GAEhB,YAAa,MACb,KAAM,GACN,OAAQM,EACR,MAAO,OACP,WAAYA,EACZ,QAAS,GACT,UAAW,GACX,SAAU,GACV,YAAa,GACb,gBAAiB,MACjB,QAAS,GACT,yBAA0B,EAC1B,QAASC,EACT,cAAeF,EACf,YAAa,GACb,iBAAkB,GAClB,kBAAmB,GACnB,cAAe,GACf,cAAe,GACf,MAAO,SAAUG,EAAQ,CAKnBX,EAAG,QAAQ,eAC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