{"version":3,"file":"form_controller-BjcXf1BV.js","sources":["../../../app/javascript/controllers/editor/link/form_controller.js"],"sourcesContent":["import LinkController from \"./base_controller\"\nimport { post } from \"@rails/request.js\"\n\nexport default class extends LinkController {\n static targets = [\"button\", \"closeButton\"]\n\n toggleButton(event) {\n let button = this.targets.find(\"button\");\n\n if (button) {\n button.disabled = event.detail.shouldDisable;\n }\n }\n\n enable() {\n super.enable(this.buttonTarget)\n }\n\n disable() {\n super.disable(this.buttonTarget)\n }\n\n async create() {\n if (!this.isValidURL()) {\n this.inputTarget.classList.replace(this.defaultClass, this.errorClass)\n this.focus()\n return\n }\n\n const response = await post(this.urlValue, {\n body: JSON.stringify({ url: this.url })\n })\n\n if (response.ok) {\n const data = await response.json\n\n this.dispatch('create', {\n linkPartial: data.link_partial\n })\n\n this.clear()\n this.cancelButtonTarget.click()\n } else {\n this.inputTarget.classList.replace(this.defaultClass, this.errorClass)\n }\n }\n\n onEnterPress() {\n this.create()\n }\n\n cancel(e) {\n super.cancel(e)\n\n if (this.formTarget.classList.contains(\"hidden\")) {\n this.openButtonTarget.click()\n } else {\n this.closeButtonTarget.click()\n }\n }\n\n closeByEscape() {\n if(this.isInvisible(this.formTarget)) return;\n\n this.dispatch('link:hidden')\n this.cancelButtonTarget.click()\n }\n\n _cancel(dispatchEvent = false) {\n super._cancel(dispatchEvent)\n\n if (this.formTarget.classList.contains(\"hidden\")) {\n this.openButtonTarget.click()\n } else {\n this.closeButtonTarget.click()\n }\n }\n}\n"],"names":["form_controller","LinkController","event","button","response","post","data","e","dispatchEvent","__publicField"],"mappings":"8PAGe,MAAKA,UAASC,CAAe,CAG1C,aAAaC,EAAO,CAClB,IAAIC,EAAS,KAAK,QAAQ,KAAK,QAAQ,EAEnCA,IACFA,EAAO,SAAWD,EAAM,OAAO,cAErC,CAEE,QAAS,CACP,MAAM,OAAO,KAAK,YAAY,CAClC,CAEE,SAAU,CACR,MAAM,QAAQ,KAAK,YAAY,CACnC,CAEE,MAAM,QAAS,CACb,GAAI,CAAC,KAAK,aAAc,CACtB,KAAK,YAAY,UAAU,QAAQ,KAAK,aAAc,KAAK,UAAU,EACrE,KAAK,MAAK,EACV,MACN,CAEI,MAAME,EAAW,MAAMC,EAAK,KAAK,SAAU,CACzC,KAAM,KAAK,UAAU,CAAE,IAAK,KAAK,GAAK,CAAA,CACvC,CAAA,EAED,GAAID,EAAS,GAAI,CACf,MAAME,EAAO,MAAMF,EAAS,KAE5B,KAAK,SAAS,SAAU,CACtB,YAAaE,EAAK,YACnB,CAAA,EAED,KAAK,MAAK,EACV,KAAK,mBAAmB,MAAK,CACnC,MACM,KAAK,YAAY,UAAU,QAAQ,KAAK,aAAc,KAAK,UAAU,CAE3E,CAEE,cAAe,CACb,KAAK,OAAM,CACf,CAEE,OAAOC,EAAG,CACR,MAAM,OAAOA,CAAC,EAEV,KAAK,WAAW,UAAU,SAAS,QAAQ,EAC7C,KAAK,iBAAiB,MAAK,EAE3B,KAAK,kBAAkB,MAAK,CAElC,CAEE,eAAgB,CACX,KAAK,YAAY,KAAK,UAAU,IAEnC,KAAK,SAAS,aAAa,EAC3B,KAAK,mBAAmB,MAAK,EACjC,CAEE,QAAQC,EAAgB,GAAO,CAC7B,MAAM,QAAQA,CAAa,EAEvB,KAAK,WAAW,UAAU,SAAS,QAAQ,EAC7C,KAAK,iBAAiB,MAAK,EAE3B,KAAK,kBAAkB,MAAK,CAElC,CACA,CAzEEC,EADkBT,EACX,UAAU,CAAC,SAAU,aAAa"}