{"version":3,"file":"time_controller-B42koXmu.js","sources":["../../../app/javascript/controllers/ui/select/time_controller.js"],"sourcesContent":["import ApplicationController from '@/controllers/application_controller'\nimport { KeyboardKey } from '@/controllers/compose/models'\n\n// Events dispatched\n// - `select` - whenever a time is selected, or restored via escape.\n\nexport default class extends ApplicationController {\n static values = {\n time: String,\n }\n\n static targets = [\n 'input',\n 'item',\n 'popover',\n 'popoverTrigger',\n ]\n\n static classes = ['disabled']\n\n select({ currentTarget }) {\n this.inputTarget.value = currentTarget.dataset.value\n this.timeValue = this.inputTarget.value\n\n this.dispatch('select', {\n detail: this.timeValue\n })\n }\n\n onKeydown(event) {\n const key = KeyboardKey.fromKeyboardEvent(event)\n\n if(!(key.isNumeric || key.isBackspace) || (this.inputTarget.value.length === 5 && !key.isBackspace)) {\n return event.preventDefault()\n }\n }\n\n onKeyup(event) {\n const key = KeyboardKey.fromKeyboardEvent(event)\n\n if(this.inputTarget.value.length === 2 && !key.isBackspace) {\n this.inputTarget.value = this.inputTarget.value + \":\"\n }\n }\n\n submit() {\n this.timeValue = this.inputTarget.value\n\n this.selected()\n this.hide()\n }\n\n escape() {\n this.hide()\n\n this.inputTarget.value = this.timeValue\n\n this.timeValueChanged()\n this.selected()\n }\n\n selected() {\n this.dispatch('select', {\n detail: this.timeValue\n })\n }\n\n hide() {\n this.dispatch('hide', {\n target: this.popoverTarget\n })\n }\n\n timeValueChanged() {\n this.itemTargets.forEach(item => {\n if(item.dataset.value === this.timeValue) {\n item.classList.add('bg-lavender-light')\n } else {\n item.classList.remove('bg-lavender-light')\n }\n })\n }\n\n focus() {\n super.focus(this.inputTarget, { moveCursorToEnd: true })\n }\n\n focusAndOpenPopover() {\n this.focus()\n\n this.dispatch('show', {\n target: this.popoverTarget\n })\n }\n\n disable() {\n super.disable(this.inputTarget)\n\n this.hide()\n\n this.dispatch('disable', {\n target: this.element,\n })\n\n this.popoverTriggerTarget.classList.add(...this.disabledClasses)\n }\n\n enable() {\n console.log('enabling')\n super.enable(this.inputTarget)\n\n this.dispatch('enable', {\n target: this.element,\n })\n\n this.popoverTriggerTarget.classList.remove(...this.disabledClasses)\n }\n}\n"],"names":["time_controller","ApplicationController","currentTarget","event","key","KeyboardKey","item","__publicField"],"mappings":"mQAMe,MAAKA,UAASC,CAAsB,CAcjD,OAAO,CAAE,cAAAC,GAAiB,CACxB,KAAK,YAAY,MAAQA,EAAc,QAAQ,MAC/C,KAAK,UAAY,KAAK,YAAY,MAElC,KAAK,SAAS,SAAU,CACtB,OAAQ,KAAK,SACd,CAAA,CACL,CAEE,UAAUC,EAAO,CACf,MAAMC,EAAMC,EAAY,kBAAkBF,CAAK,EAE/C,GAAG,EAAEC,EAAI,WAAaA,EAAI,cAAiB,KAAK,YAAY,MAAM,SAAW,GAAK,CAACA,EAAI,YACrF,OAAOD,EAAM,eAAc,CAEjC,CAEE,QAAQA,EAAO,CACb,MAAMC,EAAMC,EAAY,kBAAkBF,CAAK,EAE5C,KAAK,YAAY,MAAM,SAAW,GAAK,CAACC,EAAI,cAC7C,KAAK,YAAY,MAAQ,KAAK,YAAY,MAAQ,IAExD,CAEE,QAAS,CACP,KAAK,UAAY,KAAK,YAAY,MAElC,KAAK,SAAQ,EACb,KAAK,KAAI,CACb,CAEE,QAAS,CACP,KAAK,KAAI,EAET,KAAK,YAAY,MAAQ,KAAK,UAE9B,KAAK,iBAAgB,EACrB,KAAK,SAAQ,CACjB,CAEE,UAAW,CACT,KAAK,SAAS,SAAU,CACtB,OAAQ,KAAK,SACd,CAAA,CACL,CAEE,MAAO,CACL,KAAK,SAAS,OAAQ,CACpB,OAAQ,KAAK,aACd,CAAA,CACL,CAEE,kBAAmB,CACjB,KAAK,YAAY,QAAQE,GAAQ,CAC5BA,EAAK,QAAQ,QAAU,KAAK,UAC7BA,EAAK,UAAU,IAAI,mBAAmB,EAEtCA,EAAK,UAAU,OAAO,mBAAmB,CAE5C,CAAA,CACL,CAEE,OAAQ,CACN,MAAM,MAAM,KAAK,YAAa,CAAE,g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