{"version":3,"file":"images_controller-BaIK4IO-.js","sources":["../../../app/javascript/controllers/artifact/entity/images_controller.js"],"sourcesContent":["import ApplicationController from '@/controllers/application_controller'\n\nexport default class extends ApplicationController {\n static targets = [\n 'fileInput',\n 'template',\n 'container',\n 'attachment',\n 'placeholderButton',\n ]\n\n openFilePicker() {\n this.fileInputTarget.click()\n }\n\n previewSelectedImages() {\n this.files = Array.from(this.fileInputTarget.files)\n\n this.files.forEach(file => {\n const element = this.attachmentElement()\n\n const thumbnail = document.createElement(\"img\")\n\n thumbnail.src = URL.createObjectURL(file)\n this.addClass(thumbnail,'w-full', \"h-32\", \"rounded-md\", \"object-cover\")\n\n element.appendChild(thumbnail)\n\n this.containerTarget.appendChild(element)\n })\n\n this.show(this.containerTarget)\n }\n\n removeAttachment({ currentTarget }) {\n const image = this.attachmentTargets.find(attachment => attachment.contains(currentTarget))\n const index = this.attachmentTargets.indexOf(image)\n\n this.files = this.files.filter((_, i) => i !== index)\n\n const dataTransfer = new DataTransfer()\n this.files.forEach(file => dataTransfer.items.add(file))\n\n this.fileInputTarget.files = dataTransfer.files\n\n image.remove()\n }\n\n attachmentElement() {\n const element = this.templateTarget.cloneNode(true)\n element.removeAttribute(\"hidden\")\n element.classList.remove(\"hidden\")\n\n element.setAttribute(\"data-artifact--entity--images-target\", \"attachment\")\n\n return element\n }\n\n attachmentTargetDisconnected() {\n if(this.containerTarget.children.length === 0) {\n this.show(this.placeholderButtonTarget)\n this.hide(this.containerTarget)\n }\n }\n}\n"],"names":["images_controller","ApplicationController","file","element","thumbnail","currentTarget","image","attachment","index","_","i","dataTransfer","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CASjD,gBAAiB,CACf,KAAK,gBAAgB,MAAK,CAC9B,CAEE,uBAAwB,CACtB,KAAK,MAAQ,MAAM,KAAK,KAAK,gBAAgB,KAAK,EAElD,KAAK,MAAM,QAAQC,GAAQ,CACzB,MAAMC,EAAU,KAAK,kBAAiB,EAEhCC,EAAY,SAAS,cAAc,KAAK,EAE9CA,EAAU,IAAM,IAAI,gBAAgBF,CAAI,EACxC,KAAK,SAASE,EAAU,SAAU,OAAQ,aAAc,cAAc,EAEtED,EAAQ,YAAYC,CAAS,EAE7B,KAAK,gBAAgB,YAAYD,CAAO,CACzC,CAAA,EAED,KAAK,KAAK,KAAK,eAAe,CAClC,CAEE,iBAAiB,CAAE,cAAAE,GAAiB,CAClC,MAAMC,EAAQ,KAAK,kBAAkB,KAAKC,GAAcA,EAAW,SAASF,CAAa,CAAC,EACpFG,EAAQ,KAAK,kBAAkB,QAAQF,CAAK,EAElD,KAAK,MAAQ,KAAK,MAAM,OAAO,CAACG,EAAGC,IAAMA,IAAMF,CAAK,EAEpD,MAAMG,EAAe,IAAI,aACzB,KAAK,MAAM,QAAQT,GAAQS,EAAa,MAAM,IAAIT,CAAI,CAAC,EAEvD,KAAK,gBAAgB,MAAQS,EAAa,MAE1CL,EAAM,OAAM,CAChB,CAEE,mBAAoB,CAClB,MAAMH,EAAU,KAAK,eAAe,UAAU,EAAI,EAClD,OAAAA,EAAQ,gBAAgB,QAAQ,EAChCA,EAAQ,UAAU,OAAO,QAAQ,EAEjCA,EAAQ,aAAa,uCAAwC,YAAY,EAElEA,CACX,CAEE,8BAA+B,CAC1B,KAAK,gBAAgB,SAAS,SAAW,IAC1C,KAAK,KAAK,KAAK,uBAAuB,EACtC,KAAK,KAAK,KAAK,eAAe,EAEpC,CACA,CA7DES,EADkBZ,EACX,UAAU,CACf,YACA,WACA,YACA,aACA,mBACJ"}