{"version":3,"file":"arrow_navigation_controller-kOTKyTmR.js","sources":["../../../app/javascript/controllers/arrow_navigation_controller.js"],"sourcesContent":["import ApplicationController from './application_controller'\n\nexport default class extends ApplicationController {\n static values = {\n active: { type: Number, default: 0 },\n enabled: Boolean\n }\n\n static targets = ['panel', 'tab']\n static classes = ['active']\n\n initialize() {\n this.onArrowUp = this.onArrowUp.bind(this)\n this.onArrowDown = this.onArrowDown.bind(this)\n }\n\n onArrowUp(e) {\n if(this.isDisabled) return;\n\n this.activeValue = this.activeValue - 1\n this.updateHighlightedElement()\n }\n\n onArrowDown(e) {\n if(this.isDisabled) return;\n\n this.activeValue = this.activeValue + 1\n this.updateHighlightedElement()\n }\n\n updateHighlightedElement() {\n if(this.activeValue < 0) {\n this.activeValue = this.navigatableElements.length - 1\n } else if(this.activeValue >= this.navigatableElements.length) {\n this.activeValue = 0\n }\n\n this.navigatableElements.forEach((element, index) => {\n if(index === this.activeValue) {\n this.addClass(element, ...this.activeElementClasses)\n element.scrollIntoView(false)\n } else {\n this.removeClass(element, ...this.activeElementClasses)\n }\n })\n }\n\n clickActiveElement() {\n if(this.isDisabled) {\n return this.dispatch('enter')\n }\n\n if(this.activeElement) {\n this.activeElement.click()\n } else {\n this.dispatch('empty')\n }\n }\n\n navigateToElement({ detail: element }) {\n this.activeValue = this.navigatableElements.indexOf(element)\n this.updateHighlightedElement()\n }\n\n setActiveElement({ currentTarget }) {\n this.activeValue = this.navigatableElements.indexOf(currentTarget)\n this.updateHighlightedElement()\n }\n\n // private\n\n enabledValueChanged() {\n if(this.isDisabled) return;\n this.updateHighlightedElement()\n }\n\n get activeElement() {\n return this.navigatableElements[this.activeValue]\n }\n\n get activeElementClasses() {\n return this.hasActiveClass ? [...this.activeClasses] : ['bg-night-10']\n }\n\n get navigatableElements() {\n return Array.from(this.element.querySelectorAll('[data-arrow-navigatable]'))\n }\n\n get isDisabled() {\n return !this.enabledValue\n }\n}\n"],"names":["arrow_navigation_controller","ApplicationController","element","index","currentT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