{"version":3,"file":"base_controller-D00ohnAk.js","sources":["../../../app/javascript/controllers/editor/link/base_controller.js"],"sourcesContent":["import { useDispatch } from \"stimulus-use\"\n\nimport ApplicationController from '../../application_controller'\n\nexport default class extends ApplicationController {\n static targets = [\"input\", \"cancelButton\", \"form\"]\n\n static values = {\n url: String,\n clientUrl: String,\n turbo: Boolean,\n initial: String,\n }\n\n static classes = [\"default\", \"error\"]\n\n initialize() {\n this.submitListener = this.submitListener.bind(this)\n }\n\n connect() {\n super.connect()\n this.inputTarget?.addEventListener(\"keydown\", this.submitListener)\n this.sync()\n\n useDispatch(this, {\n eventPrefix: false,\n })\n }\n\n disconnect() {\n if (this.hasInputTarget) {\n this.inputTarget?.removeEventListener(\"keydown\", this.submitListener)\n }\n\n super.disconnect()\n }\n\n sync(e = null) {\n const url = this.inputTarget.value\n this.url = url\n this.inputTarget.value = this.url\n this.inputTarget.classList.replace(this.errorClass, this.defaultClass)\n\n if (e) {\n e.preventDefault()\n e.stopImmediatePropagation()\n }\n }\n\n submitListener(e) {\n if (e.key === \"Enter\") {\n e.stopPropagation()\n e.preventDefault()\n\n this.onEnterPress()\n }\n if ((e.ctrlKey || e.metaKey) && e.key === \"v\") {\n e.stopPropagation()\n e.stopImmediatePropagation()\n }\n }\n\n clear() {\n this.inputTarget.value = \"https://www.\"\n }\n\n cancel(e) {\n this._cancel(true)\n }\n\n _cancel(dispatchEvent = false) {\n if(this.hasFormTarget) {\n this.formTarget.classList.remove(\"border-tiger\", \"ring-1\", \"ring-tiger\")\n this.formTarget.classList.add(\"hidden\")\n }\n\n if (dispatchEvent) {\n this.dispatch(\"link:hide\")\n }\n\n this.inputTarget.value = this.initialValue\n }\n\n focus() {\n this.inputTarget.focus()\n this.inputTarget.selectionStart = this.inputTarget.selectionEnd = 10000\n }\n\n onDropdownOpen() {\n setTimeout(() => this.focus(), 1)\n\n this.dispatch(\"link:shown\")\n }\n\n onDropdownHide() {\n this.dispatch('link:hidden')\n }\n\n isValidURL() {\n const res = this.inputTarget.value.match(\n /(http(s)?:\\/\\/.)?(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)/g\n )\n return res !== null\n }\n}\n"],"names":["LinkController","ApplicationController","_a","useDispatch","e","url","dispatchEvent","__publicField"],"mappings":"+PAIe,MAAKA,UAASC,CAAsB,CAYjD,YAAa,CACX,KAAK,eAAiB,KAAK,eAAe,KAAK,IAAI,CACvD,CAEE,SAAU,OACR,MAAM,QAAO,GACbC,EAAA,KAAK,cAAL,MAAAA,EAAkB,iBAAiB,UAAW,KAAK,gBACnD,KAAK,KAAI,EAETC,EAAY,KAAM,CAChB,YAAa,EACd,CAAA,CACL,CAEE,YAAa,OACP,KAAK,kBACPD,EAAA,KAAK,cAAL,MAAAA,EAAkB,oBAAoB,UAAW,KAAK,iBAGxD,MAAM,WAAU,CACpB,CAEE,KAAKE,EAAI,KAAM,CACb,MAAMC,EAAM,KAAK,YAAY,MAC7B,KAAK,IAAMA,EACX,KAAK,YAAY,MAAQ,KAAK,IAC9B,KAAK,YAAY,UAAU,QAAQ,KAAK,WAAY,KAAK,YAAY,EAEjED,IACFA,EAAE,eAAc,EAChBA,EAAE,yBAAwB,EAEhC,CAEE,eAAeA,EAAG,CACZA,EAAE,MAAQ,UACZA,EAAE,gBAAe,EACjBA,EAAE,eAAc,EAEhB,KAAK,aAAY,IAEdA,EAAE,SAAWA,EAAE,UAAYA,EAAE,MAAQ,MACxCA,EAAE,gBAAe,EACjBA,EAAE,yBAAwB,EAEhC,CAEE,OAAQ,CACN,KAAK,YAAY,MAAQ,cAC7B,CAEE,OAAOA,EAAG,CACR,KAAK,QAAQ,EAAI,CACrB,CAEE,QAAQE,EAAgB,GAAO,CAC1B,KAAK,gBACN,KAAK,WAAW,UAAU,OAAO,eAAgB,SAAU,YAAY,EACvE,KAAK,WAAW,UAAU,IAAI,QAAQ,GAGpCA,GACF,KAAK,SAAS,WAAW,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