{"version":3,"file":"number_input_controller-nJMxW59F.js","sources":["../../../app/javascript/controllers/util/number_input_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\nimport { KeyboardKey } from \"../compose/models\";\n\nexport default class extends ApplicationController {\n static values = {\n min: Number,\n max: Number,\n }\n\n initialize() {\n super.initialize()\n\n this.onKeydown = this.onKeydown.bind(this)\n this.onContentPaste = this.onContentPaste.bind(this)\n }\n\n connect() {\n super.connect()\n\n this.element.addEventListener('keydown', this.onKeydown)\n this.element.addEventListener('paste', this.onContentPaste)\n }\n\n disconnect() {\n super.disconnect()\n\n this.element.removeEventListener('keydown', this.onKeydown)\n this.element.removeEventListener('keydown', this.onContentPaste)\n }\n\n onKeydown(event) {\n const key = KeyboardKey.fromKeyboardEvent(event)\n\n if(key.isUpArrow) {\n event.preventDefault()\n\n if(!(this.maxValue && parseInt(this.element.value) >= this.maxValue)) {\n this.element.value = parseInt(this.element.value) + 1\n this.element.dispatchEvent(new Event('input'))\n }\n\n return\n }\n\n if(key.isDownArrow) {\n event.preventDefault()\n\n if(!(this.minValue && parseInt(this.element.value) <= this.minValue)) {\n this.element.value = parseInt(this.element.value) - 1\n this.element.dispatchEvent(new Event('input'))\n }\n\n return\n }\n\n if(\n key.isNumeric\n || key.isArrow\n || key.isBackspace\n || key.hasAnyModifier\n || key.isTab\n || key.isEnter\n ) {\n return\n }\n\n event.preventDefault()\n }\n\n onContentPaste(event) {\n const parsedClipboardData = parseInt(event.clipboardData.getData('text/plain'))\n\n if(isNaN(parsedClipboardData)) {\n event.preventDefault()\n }\n }\n}\n"],"names":["number_input_controller","ApplicationController","event","key","KeyboardKey","parsedClipboardData","__publicField"],"mappings":"mQAGe,MAAKA,UAASC,CAAsB,CAMjD,YAAa,CACX,MAAM,WAAU,EAEhB,KAAK,UAAY,KAAK,UAAU,KAAK,IAAI,EACzC,KAAK,eAAiB,KAAK,eAAe,KAAK,IAAI,CACvD,CAEE,SAAU,CACR,MAAM,QAAO,EAEb,KAAK,QAAQ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