{"version":3,"file":"js/app_packs_src_decidim_decidim_awesome_editors_editor_js.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AACA;AAEA;AACA;AAEA;AAAA;AAAA;AAAA;AAGA;AAAA;AAAA;AAAA;AACA;AAAA;AAGA;AAEA;AACA;AACA;AAAA;AAIA;AACA;AAIA;AAGA;AACA;;AAEA;AACA;AACA;AAAA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AACA;AACA;AAEA;AACA;AAEA;AACA;AACA;;AAEA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;;AAEA;AACA;AACA;AAEA;AACA;AACA;AACA;;AAGA;AACA;AACA;AAEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AAEA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;;AAEA;AACA;AAEA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;AC9TA","sources":["webpack://decidim-app/./app/packs/src/decidim/decidim_awesome/editors/editor.js","webpack://decidim-app/ignored|/code/node_modules/typo-js|fs"],"sourcesContent":["/* eslint-disable require-jsdoc, func-style */\n\n/*\n* Since version 0.25 we follow a different strategy and opt to destroy and override completely the original editor\n* That's because editors are instantiated directly instead of creating a global function to instantiate them\n*/\n\nimport lineBreakButtonHandler from \"src/decidim/editor/linebreak_module\"\nimport InscrybMDE from \"inscrybmde\"\nimport Europa from \"europa\"\nimport \"inline-attachment/src/inline-attachment\";\nimport \"inline-attachment/src/codemirror-4.inline-attachment\";\nimport \"inline-attachment/src/jquery.inline-attachment\";\nimport hljs from \"highlight.js\";\nimport \"highlight.js/styles/github.css\";\nimport \"src/decidim/editor/clipboard_override\"\nimport \"src/decidim/vendor/image-resize.min\"\nimport \"src/decidim/vendor/image-upload.min\"\nimport { marked } from \"marked\";\n\nconst DecidimAwesome = window.DecidimAwesome || {};\nconst quillFormats = [\"bold\", \"italic\", \"link\", \"underline\", \"header\", \"list\", \"video\", \"image\", \"alt\", \"break\", \"width\", \"style\", \"code\", \"blockquote\", \"indent\"];\n\n// A tricky way to destroy the quill editor\nexport function destroyQuillEditor(container) {\n if (container) {\n const content = $(container).find(\".ql-editor\").html();\n $(container).html(content);\n $(container).siblings(\".ql-toolbar\").remove();\n $(container).find(\"*[class*='ql-']\").removeClass((index, className) => (className.match(/(^|\\s)ql-\\S+/g) || []).join(\" \"));\n $(container).removeClass((index, className) => (className.match(/(^|\\s)ql-\\S+/g) || []).join(\" \"));\n if ($(container).next().is(\"p.help-text\")) {\n $(container).next().remove();\n }\n }\n else {\n console.error(`editor [${container}] not exists`);\n }\n}\n\nexport function createQuillEditor(container) {\n const toolbar = $(container).data(\"toolbar\");\n const disabled = $(container).data(\"disabled\");\n \n const allowedEmptyContentSelector = \"iframe\";\n let quillToolbar = [\n [\"bold\", \"italic\", \"underline\", \"linebreak\",],\n [{ list: \"ordered\" }, { list: \"bullet\" }],\n [\"link\", \"clean\"],\n [\"code\", \"blockquote\"],\n [{ \"indent\": \"-1\" }, { \"indent\": \"+1\" }],\n [{ 'savedDataset': \"openModal\" }]\n ]\n \n let addImage = $(container).data(\"editorImages\");\n \n if (toolbar === \"full\") {\n quillToolbar = [\n [{ header: [2, 3, 4, 5, 6, false] }],\n ...quillToolbar,\n [\"video\"]\n ];\n } else if (toolbar === \"basic\") {\n quillToolbar = [\n ...quillToolbar,\n [\"video\"]\n ];\n }\n \n \n let modalData = [];\n let hasFetched = false; // Add this flag\n \n // Function to fetch data\n function fetchData() {\n if (!hasFetched) { // Check if fetch hasn't been performed yet\n fetch('/idra_update', {\n method: 'GET'\n })\n .then(response => {\n if (response.ok) {\n return response.text(); // Assuming the response is HTML\n } else {\n throw new Error('Failed to fetch the updated content');\n }\n })\n .then(data => {\n const parser = new DOMParser();\n const doc = parser.parseFromString(data, 'text/html');\n const datasetElements = doc.querySelectorAll('#datasets-list a');\n const urlElements = doc.querySelectorAll('#datasets-list #url');\n \n datasetElements.forEach((dataset, index) => {\n const title = dataset.textContent;\n const url = urlElements[index].textContent;\n modalData.push({ title, url });\n });\n })\n .catch(error => {\n console.error('Error updating partial view:', error);\n });\n \n hasFetched = true; // Set the flag to indicate that fetch has been performed\n }\n }\n \n // Call the fetchData function\n fetchData();\n \n \n // Function to create and display the modal\n function openModal() {\n // Create a modal container\n var modalContainer = document.createElement('div');\n modalContainer.classList.add('modal-container');\n \n // Create a modal element\n var modal = document.createElement('div');\n modal.classList.add('modal');\n \n // Modal content\n var modalContent = document.createElement('div');\n modalContent.classList.add('modal-content');\n modalContent.id = 'modalContent';\n \n // Create an unordered list to display the elements as a list\n // Create a div for the links\n var linksDiv = document.createElement('div');\n linksDiv.classList.add('links-column');\n \n var titleElement = document.createElement('h1');\n titleElement.textContent = \"Saved Dataset\";\n linksDiv.appendChild(titleElement);\n titleElement.className = \"text-center\"\n \n var descriptionElement = document.createElement(\"h5\")\n descriptionElement.textContent = \"Select a dataset to insert in text editor:\"\n descriptionElement.style.color = \"gray\"\n linksDiv.appendChild(descriptionElement)\n \n // Loop through modalData array and create links with click event listeners\n modalData.forEach(function (element) {\n var link = document.createElement('a');\n link.href = element.url; // URL as the href attribute of the link\n link.textContent = element.title; // Title as the visible text of the link\n linksDiv.appendChild(link);\n \n link.addEventListener('click', function (event) {\n event.preventDefault(); // Prevent default navigation behavior\n \n copyAndPasteText(element.title, element.url);\n modalContainer.style.display = 'none'; // Close the modal\n });\n \n if (element !== modalData[modalData.length - 1]) {\n linksDiv.appendChild(document.createElement('br'));\n }\n });\n \n \n // Function to copy and paste the text into the Quill editor\n function copyAndPasteText(title, url) {\n const range = quill.getSelection();\n \n const linkFormat = {\n link: url,\n target: '_blank',\n };\n \n quill.insertText(range.index, title, linkFormat);\n quill.setSelection(range.index, title.length, 'user');\n }\n modalContent.appendChild(linksDiv);\n modal.appendChild(modalContent);\n modalContainer.appendChild(modal);\n document.body.appendChild(modalContainer);\n \n // Open the modal\n modalContainer.style.display = 'block';\n \n // Close modal when clicking outside the modal\n window.addEventListener('click', function (event) {\n if (event.target == modalContainer) {\n modalContainer.style.display = 'none';\n }\n });\n }\n \n \n let modules = {\n linebreak: {},\n toolbar: {\n container: quillToolbar,\n handlers: {\n \"linebreak\": lineBreakButtonHandler,\n \"savedDataset\": openModal,\n }\n }\n };\n \n \n \n \n const $input = $(container).siblings('input[type=\"hidden\"]');\n container.innerHTML = $input.val() || \"\";\n const token = $('meta[name=\"csrf-token\"]').attr(\"content\");\n if (addImage) {\n modules.imageResize = {\n modules: [\"Resize\", \"DisplaySize\"]\n }\n modules.imageUpload = {\n url: $(container).data(\"uploadImagesPath\"),\n method: \"POST\",\n name: \"image\",\n withCredentials: false,\n headers: { \"X-CSRF-Token\": token },\n callbackOK: (serverResponse, next) => {\n $(\"div.ql-toolbar\").last().removeClass(\"editor-loading\")\n next(serverResponse.url);\n },\n callbackKO: (serverError) => {\n $(\"div.ql-toolbar\").last().removeClass(\"editor-loading\")\n console.log(`Image upload error: ${serverError.message}`);\n },\n checkBeforeSend: (file, next) => {\n $(\"div.ql-toolbar\").last().addClass(\"editor-loading\")\n next(file);\n }\n }\n }\n const quill = new Quill(container, {\n modules: modules,\n formats: quillFormats,\n theme: \"snow\"\n });\n \n \n \n if (disabled) {\n quill.disable();\n }\n \n quill.on(\"text-change\", () => {\n const text = quill.getText();\n \n // Triggers CustomEvent with the cursor position\n // It is required in input_mentions.js\n let event = new CustomEvent(\"quill-position\", {\n detail: quill.getSelection()\n });\n container.dispatchEvent(event);\n \n if ((text === \"\\n\" || text === \"\\n\\n\") && quill.root.querySelectorAll(allowedEmptyContentSelector).length === 0) {\n $input.val(\"\");\n } else {\n const emptyParagraph = \"
${text}
`);\n }\n \n // After editor is ready, linebreak_module deletes two extraneous new lines\n quill.emitter.emit(\"editor-ready\");\n \n return quill;\n}\n\nexport function createMarkdownEditor(container) {\n const text = DecidimAwesome.texts.drag_and_drop_image;\n const token = $('meta[name=\"csrf-token\"]').attr(\"content\");\n const $input = $(container).siblings('input[type=\"hidden\"]');\n const $faker = $('