{"version":3,"file":"edit_controller-C1hrs7Ye.js","sources":["../../../app/javascript/controllers/link/edit_controller.js"],"sourcesContent":["import { computePosition, autoUpdate, flip } from '@floating-ui/dom'\n\nimport ApplicationController from '../application_controller'\nimport { useURLValidations } from '../mixins/useURLValidations'\n\nexport default class extends ApplicationController {\n static values = {\n placement: String\n }\n\n static targets = ['input']\n\n initialize() {\n super.initialize()\n this.placementValue ||= 'top-start'\n }\n\n connect() {\n super.connect()\n useURLValidations(this)\n }\n\n show({ detail }) {\n this.clearFocusedElement()\n const { element, url, id } = detail\n\n this.focusedElement = element\n this.focusedElementId = id\n\n this.initialValue = url\n this.inputTarget.value = url\n\n this.setup()\n }\n\n setup() {\n this.floatingUICleanup = autoUpdate(this.focusedElement, this.element, () => {\n computePosition(this.focusedElement, this.element, {\n placement: this.placementValue,\n middleware: [\n flip()\n ]\n }).then(({x, y}) => {\n Object.assign(this.element.style, {\n left: `${x}px`,\n top: `${y}px`,\n });\n });\n })\n\n super.show()\n this.focus(this.inputTarget, { moveCursorToEnd: true })\n }\n\n async update() {\n if(this.invalidURL(this.inputTarget.value)) {\n return this.addClass(this.inputTarget, 'border-red-500')\n }\n\n if(this.unchanged) {\n return this.cancel()\n }\n\n this.removeClass(this.inputTarget, 'border-red-500')\n\n this.dispatch('updated', {\n detail: {\n id: this.focusedElementId,\n url: this.inputTarget.value,\n }\n })\n\n this.clearFocusedElement()\n this.hide()\n\n this.dispatch('canceled')\n }\n\n cancel() {\n this.element.classList.add('hidden')\n this.clearFocusedElement()\n\n this.dispatch('cancelled')\n }\n\n destroy() {\n this.element.classList.add('hidden')\n this.floatingUICleanup()\n\n this.dispatch('destroy', { detail: this.focusedElement.dataset.trixId })\n }\n\n clearAndHide({ target }) {\n if(this.isVisible() && !this.element.contains(target)) {\n this.element.classList.add('hidden')\n this.clearFocusedElement()\n }\n }\n\n clearFocusedElement() {\n if(this.floatingUICleanup) {\n this.floatingUICleanup()\n }\n\n if(this.focusedELementLink) {\n this.dispatch('finished', {\n target: this.focusedELementLink\n })\n }\n\n this.focusedElementId = null\n this.focusedElement = null\n }\n\n closeByEscape() {\n if(this.invisible) return\n\n this.cancel()\n }\n\n editLink({ detail }) {\n this.show({\n detail: {\n element: detail.figureElement,\n url: detail.clientUrl,\n id: detail.id\n }\n })\n\n this.dispatch('start', {\n target: this.focusedELementLink\n })\n }\n\n // private\n\n get unchanged() {\n return this.inputTarget.value.trim() === this.initialValue.trim()\n }\n}\n"],"names":["edit_controller","ApplicationController","useURLValidations","detail","element","url","id","autoUpdate","computePosition","flip","x","y","target","__publicField"],"mappings":"2UAKe,MAAKA,UAASC,CAAsB,CAOjD,YAAa,CACX,MAAM,WAAU,EAChB,KAAK,iBAAL,KAAK,eAAmB,YAC5B,CAEE,SAAU,CACR,MAAM,QAAO,EACbC,EAAkB,IAAI,CAC1B,CAEE,KAAK,CAAE,OAAAC,GAAU,CACf,KAAK,oBAAmB,EACxB,KAAM,CAAE,QAAAC,EAAS,IAAAC,EAAK,GAAAC,GAAOH,EAE7B,KAAK,eAAiBC,EACtB,KAAK,iBAAmBE,EAExB,KAAK,aAAeD,EACpB,KAAK,YAAY,MAAQA,EAEzB,KAAK,MAAK,CACd,CAEE,OAAQ,CACN,KAAK,kBAAoBE,EAAW,KAAK,eAAgB,KAAK,QAAS,IAAM,CAC3EC,EAAgB,KAAK,eAAgB,KAAK,QAAS,CACjD,UAAW,KAAK,eAChB,WAAY,CACVC,EAAI,CACd,CACO,CAAA,EAAE,KAAK,CAAC,CAAC,EAAAC,EAAG,EAAAC,CAAC,IAAM,CAClB,OAAO,OAAO,KAAK,QAAQ,MAAO,CAChC,KAAM,GAAGD,CAAC,KACV,IAAK,GAAGC,CAAC,IACnB,CAAS,CACT,CAAO,CACF,CAAA,EAED,MAAM,KAAI,EACV,KAAK,MAAM,KAAK,YAAa,CAAE,gBAAiB,EAAM,CAAA,CAC1D,CAEE,MAAM,QAAS,CACb,GAAG,KAAK,WAAW,KAAK,YAAY,KAAK,EACvC,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