{"version":3,"file":"list_controller-DCkVM2xQ.js","sources":["../../../app/javascript/controllers/sortable/list_controller.js"],"sourcesContent":["import Sortable from 'sortablejs'\nimport ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static targets = ['item']\n\n static values = {\n group: { type: String, default: \"shared\" }\n }\n\n initialize() {\n super.initialize()\n\n this.childListObserver = new MutationObserver(this.childListCallback.bind(this))\n this.activateItem = this.activateItem.bind(this)\n this.deactivateItem = this.deactivateItem.bind(this)\n }\n\n connect() {\n this.sortable = Sortable.create(this.element, {\n group: this.groupValue,\n animation: 150,\n filter: \".not-draggable\",\n onEnd: this.end.bind(this),\n preventOnFilter: false\n })\n\n if(!this.isSortable) {\n this.nextTick(() => this.visibleItems.forEach(this.deactivateItem))\n }\n\n this.childListObserver.observe(this.element, { childList: true })\n }\n\n disconnect() {\n super.disconnect()\n this.childListObserver.disconnect()\n }\n\n end(event) {\n this.dispatch('end', {\n target: event.item,\n detail: {\n item: event.item\n }\n })\n\n this.dispatch('end', {\n detail: {\n item: event.item\n }\n })\n\n this.itemTargets.forEach((item) => {\n this.dispatch('reorder', {\n target: item,\n })\n })\n }\n\n childListCallback(mutations) {\n const mutation = mutations.find(mutation => mutation.type === 'childList')\n if(!mutation) return\n\n if(this.visibleItems.length > 1) {\n this.visibleItems.forEach(this.activateItem)\n } else {\n this.visibleItems.forEach(this.deactivateItem)\n }\n }\n\n itemTargetConnected() {\n if(this.visibleItems.length > 1) {\n this.visibleItems.forEach(this.activateItem)\n } else {\n this.visibleItems.forEach(this.deactivateItem)\n }\n }\n\n itemTargetDisconnected() {\n if(this.visibleItems.length > 1) {\n this.visibleItems.forEach(this.activateItem)\n } else {\n this.visibleItems.forEach(this.deactivateItem)\n }\n }\n\n activateItem(item) {\n this.dispatch('activate', {\n target: item\n })\n }\n\n deactivateItem(item) {\n this.dispatch('deactivate', {\n target: item\n })\n }\n\n get isSortable() {\n return this.visibleItems.length > 1\n }\n\n get visibleItems() {\n return this.itemTargets.filter(item => !item.classList.contains('hidden'))\n }\n}\n"],"names":["list_controller","ApplicationController","Sortable","event","item","mutations","mutation","__publicField"],"mappings":"sQAGe,MAAKA,UAASC,CAAsB,CAOjD,YAAa,CACX,MAAM,WAAU,EAEhB,KAAK,kBAAoB,IAAI,iBAAiB,KAAK,kBAAkB,KAAK,IAAI,CAAC,EAC/E,KAAK,aAAe,KAAK,aAAa,KAAK,IAAI,EAC/C,KAAK,eAAiB,KAAK,eAAe,KAAK,IAAI,CACvD,CAEE,SAAU,CACR,KAAK,SAAWC,EAAS,OAAO,KAAK,QAAS,CAC5C,MAAO,KAAK,WACZ,UAAW,IACX,OAAQ,iBACR,MAAO,KAAK,IAAI,KAAK,IAAI,EACzB,gBAAiB,EAClB,CAAA,EAEG,KAAK,YACP,KAAK,SAAS,IAAM,KAAK,aAAa,QAAQ,KAAK,cAAc,CAAC,EAGpE,KAAK,kBAAkB,QAAQ,KAAK,QAAS,CAAE,UAAW,EAAM,CAAA,CACpE,CAEE,YAAa,CACX,MAAM,WAAU,EAChB,KAAK,kBAAkB,WAAU,CACrC,CAEE,IAAIC,EAAO,CACT,KAAK,SAAS,MAAO,CACnB,OAAQA,EAAM,KACd,OAAQ,CACN,KAAMA,EAAM,IACpB,CACK,CAAA,EAED,KAAK,SAAS,MAAO,CACnB,OAAQ,CACN,KAAMA,EAAM,IACpB,CACK,CAAA,EAED,KAAK,YAAY,QAASC,GAAS,CACjC,KAAK,SAAS,UAAW,CACvB,OAAQA,CACT,CAAA,CACF,CAAA,CACL,CAEE,kBAAkBC,EAAW,CACVA,EAAU,KAAKC,GAAYA,EAAS,OAAS,WAAW,IAGtE,KAAK,aAAa,OAAS,EAC5B,KAAK,aAAa,QAAQ,KAAK,YAAY,EAE3C,KAAK,aAAa,QAAQ,KAAK,cAAc,EAEnD,CAEE,qBAAsB,CACjB,KAAK,aAAa,OAAS,EAC5B,KAAK,aAAa,QAAQ,KAAK,YAAY,EAE3C,KAAK,aAAa,QAAQ,KAAK,cAAc,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