{"version":3,"file":"popover_controller-e87AxWLl.js","sources":["../../../app/javascript/controllers/ui/popover_controller.js"],"sourcesContent":["import {computePosition, autoUpdate, shift, flip, offset, autoPlacement} from \"@floating-ui/dom\"\n\nimport ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static values = {\n placement: { type: String, default: \"bottom-start\" },\n shiftPadding: { type: Number, default: 24 },\n open: { type: Boolean, default: false },\n alignWidth: { type: Boolean, default: false },\n autoPlacement: { type: Boolean, default: false },\n disabled: { type: Boolean, default: false },\n offset: { type: Number, default: 5 },\n behaviour: { type: String, default: 'popover' }\n }\n\n static targets = ['trigger', 'popover']\n\n connect() {\n this.floatingUICleanup = autoUpdate(this.triggerTarget, this.popoverTarget, () => {\n computePosition(this.triggerTarget, this.popoverTarget, {\n placement: this.placementValue,\n middleware: this.middlewares,\n }).then(({x, y}) => {\n const newStyle = {\n left: `${x}px`,\n top: `${y}px`\n }\n\n if(this.alignWidthValue) {\n newStyle.width = `${this.triggerTarget.offsetWidth}px`\n }\n\n Object.assign(this.popoverTarget.style, newStyle);\n });\n })\n }\n\n show() {\n console.log('showing')\n this.openValue = true\n }\n\n another() {\n console.log('another')\n }\n\n hide() {\n this.openValue = false\n }\n\n toggle() {\n this.openValue = !this.openValue\n }\n\n onClickOutside(event) {\n if(this.behaviourValue === 'modal' || event.target.closest('dialog') || event.target.tagName === 'DIALOG' || !this.openValue) return\n\n if (event.target.nodeType && this.element.contains(event.target) === false) {\n this.openValue = false\n setTimeout(() => this.dispatch(\"aborted\"), 400)\n }\n }\n\n enable() {\n this.disabledValue = false\n }\n\n disable() {\n this.disabledValue = true\n this.openValue = false\n }\n\n openValueChanged() {\n if(this.disabledValue) return\n\n this.dispatch(\"toggle\", {\n detail: this.openValue\n })\n\n if(this.openValue) {\n this.popoverTarget.showPopover()\n this.popoverTarget.setAttribute(\"aria-expanded\", \"true\")\n\n this.dispatch(\"opened\")\n this.dispatch(\"opened\", { target: this.element })\n } else {\n this.popoverTarget.hidePopover()\n this.popoverTarget.removeAttribute(\"aria-expanded\")\n\n this.dispatch(\"hidden\")\n this.dispatch(\"hidden\", { target: this.element })\n }\n }\n\n get middlewares() {\n const flipMechanism = this.autoPlacementValue ? autoPlacement({ allowedPlacements: ['top', 'bottom' ]}) : flip()\n\n return [\n offset(this.offsetValue),\n shift({ padding: this.shiftPaddingValue }),\n flipMechanism,\n ]\n }\n}\n"],"names":["PopoverController","ApplicationController","autoUpdate","computePosition","x","y","newStyle","event","flipMechanism","autoPlacement","flip","offset","shift","__publicField"],"mappings":"4SAIe,MAAKA,UAASC,CAAsB,CAcjD,SAAU,CACR,KAAK,kBAAoBC,EAAW,KAAK,cAAe,KAAK,cAAe,IAAM,CAChFC,EAAgB,KAAK,cAAe,KAAK,cAAe,CACtD,UAAW,KAAK,eAChB,WAAY,KAAK,WAClB,CAAA,EAAE,KAAK,CAAC,CAAC,EAAAC,EAAG,EAAAC,CAAC,IAAM,CAClB,MAAMC,EAAW,CACf,KAAM,GAAGF,CAAC,KACV,IAAK,GAAGC,CAAC,IACnB,EAEW,KAAK,kBACNC,EAAS,MAAQ,GAAG,KAAK,cAAc,WAAW,MAGpD,OAAO,OAAO,KAAK,cAAc,MAAOA,CAAQ,CACxD,CAAO,CACF,CAAA,CACL,CAEE,MAAO,CACL,QAAQ,IAAI,SAAS,EACrB,KAAK,UAAY,EACrB,CAEE,SAAU,CACR,QAAQ,IAAI,SAAS,CACzB,CAEE,MAAO,CACL,KAAK,UAAY,EACrB,CAEE,QAAS,CACP,KAAK,UAAY,CAAC,KAAK,SAC3B,CAEE,eAAeC,EAAO,CACjB,KAAK,iBAAmB,SAAWA,EAAM,OAAO,QAAQ,QAAQ,GAAKA,EAAM,OAAO,UAAY,UAAY,CAAC,KAAK,WAE/GA,EAAM,OAAO,UAAY,KAAK,QAAQ,SAASA,EAAM,MAAM,IAAM,KACnE,KAAK,UAAY,GACjB,WAAW,IAAM,KAAK,SAAS,SAAS,EAAG,GAAG,EAEpD,CAEE,QA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