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BA,GAD6B,IAEhCnC,SAAU,GAAF,OAAK,EAAKD,GAAV,aAAiBoC,EAAcnC,eAGnCoC,GAAcC,EAAAA,EAAAA,GAAO,oBAAqBR,KAAKzB,SAASC,MAN5C,WAQTiC,GACP,IAAMC,EAAaH,EAAYE,GAMxBH,E,k1BAAP,CALgCF,EAAeO,QAC7C,SAACC,GAAD,OACEF,EAAW1C,aAAa,qBAAuB4C,EAAazC,YAGhE,MAEImC,SAC6C,IAApC,EAAK/B,SAAS+B,EAAcpC,IACrC,EAAKK,SAAS+B,EAAcpC,IAAMwC,QAEkB,IAAzC,EAAKnC,SAAS+B,EAAcpC,IAAI2C,OACzC,EAAKtC,SAAS+B,EAAcpC,IAAM,CAAC,EAAKK,SAAS+B,EAAcpC,MAEjE,EAAKK,SAAS+B,EAAcpC,IAAI2C,KAAKH,MAhBlCD,EAAI,EAAGA,EAAIF,EAAYO,OAAQL,GAAK,EAAG,EAAvCA,GA4BTM,OAAOC,OAAOhB,KAAKzB,UAAU0C,SAAQ,SAACC,GACpCA,EAAIC,OAFS,SAACD,GAAD,YAA8B,IAAbA,EAAIL,KAAuB,CAACK,GAAOA,EAEpDC,CAAOD,W,mBAlEpBxB","sources":["webpack:///./components/textarea-richtext/javascripts/textarea-richtext.js","webpack:///./javascripts/dom/select.js","webpack:///./javascripts/helpers/baseModule.js"],"sourcesContent":["import Quill from 'quill';\nimport BaseModule from '../../../javascripts/helpers/baseModule';\n\nexport default class TextareaRichtext extends BaseModule {\n constructor(element) {\n super(element, element.getAttribute('data-js-module'));\n\n this.getElements([\n { id: 'editor', selector: 'editor' },\n { id: 'textarea', selector: 'textarea' }\n ]);\n const config = JSON.parse(this.elements.self.dataset.jsModuleConfig);\n\n const editor = new Quill(this.elements.editor, {\n modules: { toolbar: config.toolbar },\n theme: 'snow'\n });\n\n if (this.elements.textarea.value) {\n editor.root.innerHTML = this.elements.textarea.value;\n }\n\n editor.on('text-change', () => {\n const content = editor.root.innerHTML;\n this.elements.textarea.value = content;\n this.elements.textarea.innerHTML = content;\n });\n\n editor.on('editor-change', () => {\n if (editor.hasFocus()) {\n this.elements.self.classList.add('textarea-richtext--has-focus');\n } else {\n this.elements.self.classList.remove('textarea-richtext--has-focus');\n }\n });\n }\n}\n","/**\n * This methods selects Elements from a specific context by a selector\n * @param {string} selector Selector of the element to find\n * @param {Element|HTMLDocument} [element] Context of the selectable\n * @returns {Array} Am array with selected Elements\n */\nexport default (selector, element = window.document) =>\n [].slice.call(element.querySelectorAll(selector));\n","import select from '../dom/select';\n\nclass BaseModule {\n constructor(element, id) {\n this.id = id;\n this.elements = {\n self: element\n };\n\n this.setInitialized();\n }\n\n setInitialized() {\n if (this.elements.self) {\n this.elements.self.setAttribute('data-js-module-initialized', true);\n }\n }\n\n setUnInitialized() {\n if (this.elements.self) {\n this.elements.self.removeAttribute('data-js-module-initialized');\n }\n }\n\n /**\n * Selects DOMElements of a module with a specific data attribute (`data-js-element=\"${module}__${selector}\"`)\n * Receives an object where the id param is the key in the elements cache\n * The selector param of the config is the selector part in the query-selector described above\n * @param {Object} config Configuration object in a key value format\n * @returns {void}\n */\n getElements(config) {\n const elementsConfig = config.map((elementConfig) => ({\n ...elementConfig,\n selector: `${this.id}__${elementConfig.selector}`\n }));\n\n const domElements = select('[data-js-element]', this.elements.self);\n\n for (let i = 0; i < domElements.length; i += 1) {\n const domElement = domElements[i];\n const elementConfigCandidates = elementsConfig.filter(\n (singleConfig) =>\n domElement.getAttribute('data-js-element') === singleConfig.selector\n );\n\n const [elementConfig] = elementConfigCandidates;\n\n if (elementConfig) {\n if (typeof this.elements[elementConfig.id] === 'undefined') {\n this.elements[elementConfig.id] = domElement;\n } else {\n if (typeof this.elements[elementConfig.id].push === 'undefined') {\n this.elements[elementConfig.id] = [this.elements[elementConfig.id]];\n }\n this.elements[elementConfig.id].push(domElement);\n }\n }\n }\n\n /*\n * Append a attribute \"asList\" to each element/s in this.elements\n * which is always an array no matter if element/s is an array\n * or a single HTMLElement\n */\n\n const asList = (obj) => (typeof obj.push === 'undefined' ? [obj] : obj);\n Object.values(this.elements).forEach((obj) => {\n obj.asList = asList(obj); // eslint-disable-line no-param-reassign\n });\n }\n}\n\nexport default BaseModule;\n"],"names":["TextareaRichtext","element","getAttribute","getElements","id","selector","config","JSON","parse","elements","self","dataset","jsModuleConfig","editor","Quill","modules","toolbar","theme","textarea","value","root","innerHTML","on","content","hasFocus","classList","add","remove","BaseModule","window","document","slice","call","querySelectorAll","this","setInitialized","setAttribute","removeAttribute","elementsConfig","map","elementConfig","domElements","select","i","domElement","filter","singleConfig","push","length","Object","values","forEach","obj","asList"],"sourceRoot":""}