{"version":3,"file":"sortable_controller-V2013kdi.js","sources":["../../../app/frontend/javascript/controllers/color_picker_controller.js","../../../app/frontend/javascript/controllers/sortable_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport Picker from \"vanilla-picker\";\n\n// Connects to data-controller=\"color-picker\"\nexport default class extends Controller {\n picker = null;\n\n connect() {\n this.picker = new Picker({ alpha: false });\n\n if (this.getPickerInputElement().value) {\n this.getPreviewElement().style.background = this.getPickerInputElement().value;\n } else {\n this.getPreviewElement().style.background = \"white\"\n }\n\n this.getPreviewElement().addEventListener(\"click\", (e) => this.onPickerClick(e));\n // Clicking on the input to trigger the picker disable the ability to type the hex color by hand\n // this.getPickerInputElement().addEventListener(\"click\", (e) => this.onPickerClick(e));\n\n this.picker.onChange = (color) => {\n this.getPreviewElement().style.background = color.hex.substring(0, 7);\n this.getPickerInputElement().value = color.hex.substring(0, 7);\n };\n\n this.picker.onClose = () => {\n this.picker.movePopup({ parent: null }, false);\n };\n }\n\n onPickerClick(e) {\n e.preventDefault();\n\n if (!(this.getPickerInputElement().disabled)) {\n this.picker.movePopup({ parent: this.getPreviewElement(), color: this.getPickerInputElement().value }, false);\n this.picker.openHandler(e);\n }\n }\n\n getPickerInputElement() {\n return this.element.querySelector('input[type=\"text\"]');\n }\n\n getPreviewElement() {\n return this.element.querySelector('.preview');\n }\n}\n","import { Controller } from \"@hotwired/stimulus\"\nimport Sortable from \"sortablejs\";\n\n// Connects to data-controller=\"sortable\"\nexport default class SortableController extends Controller {\n static values = {\n animation: {\n type: Number,\n default: 150\n },\n handle: String,\n paramName: {\n type: String,\n default: \"position\",\n },\n resourceName: String\n };\n\n connect() {\n this.options = {\n dataIdAttr: \"data-sortable-id\",\n animation: this.animationValue,\n handle: this.handleValue,\n onUpdate: this.onUpdate\n };\n\n this.sortable = new Sortable(this.element, this.options);\n }\n\n disconnect() {\n // FIXME: we don't destroy Sortable instances while dragging\n // because it causes things to break.\n //\n // See:\n // https://github.com/stimulus-components/stimulus-sortable/issues/10\n // https://github.com/stimulus-components/stimulus-sortable/issues/16\n if (!Sortable.active) {\n let el = Sortable.get(this.element);\n if (el) el.destroy();\n }\n }\n\n onUpdate = ({item, newIndex, oldIndex, from}) => {\n const itemAtOldIndex = Sortable.utils.getChild(this.element, oldIndex, this.options);\n\n let newPosition;\n if (newIndex > oldIndex && item.previousElementSibling && item.previousElementSibling.dataset.sortableId) {\n newPosition = JSON.stringify({ after: item.previousElementSibling.dataset.sortableId });\n }\n else if (item.nextElementSibling && item.nextElementSibling.dataset.sortableId) {\n newPosition = JSON.stringify({ before: item.nextElementSibling.dataset.sortableId });\n }\n else if (item.previousElementSibling && item.previousElementSibling.dataset.sortableId) {\n newPosition = JSON.stringify({ after: item.previousElementSibling.dataset.sortableId });\n }\n else {\n const currentPage = (new URL(document.location)).searchParams.get(\"page\") || 1;\n const perPage = (new URL(document.location)).searchParams.get(\"per_page\") || 12;\n newPosition = newIndex + ((currentPage - 1) * perPage) + 1;\n }\n\n return fetch(item.dataset.sortableUpdateUrl, {\n method: \"PUT\",\n headers: { 'X-CSRF-Token': document.querySelector(\"meta[name=csrf-token]\").content },\n body: this.positionFormData(newPosition)\n }).then((res) => {\n if (res.status < 200 || res.status > 299) {\n return Promise.reject(res);\n }\n }).catch((error) => {\n from.insertBefore(item, itemAtOldIndex);\n return Promise.reject(error);\n });\n }\n\n positionFormData(position) {\n const data = new FormData();\n data.append(\n this.resourceNameValue ? `${this.resourceNameValue}[${this.paramNameValue}]` : this.paramNameValue,\n position\n );\n return data;\n }\n}\n"],"names":["ColorPickerController","Controller","__publicField","Picker","color","SortableController","item","newIndex","oldIndex","from","itemAtOldIndex","Sortable","newPosition","currentPage","perPage","res","error","el","position","data"],"mappings":"+PAIe,MAAKA,UAASC,CAAW,CAAzB,kCACbC,EAAA,cAAS,MAET,SAAU,CACR,KAAK,OAAS,IAAIC,EAAO,CAAE,MAAO,EAAK,CAAE,EAErC,KAAK,sBAAuB,EAAC,MAC/B,KAAK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