primevue
Version:
PrimeVue is an open source UI library for Vue featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBloc
1 lines • 10.5 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["../../src/keyfilter/BaseKeyFilter.js","../../src/keyfilter/KeyFilter.js"],"sourcesContent":["import BaseDirective from '@primevue/core/basedirective';\nimport KeyFilterStyle from 'primevue/keyfilter/style';\n\nconst BaseKeyFilter = BaseDirective.extend({\n style: KeyFilterStyle\n});\n\nexport default BaseKeyFilter;\n","import { isAttributeEquals } from '@primeuix/utils/dom';\nimport BaseKeyFilter from './BaseKeyFilter';\n\nconst KeyFilter = BaseKeyFilter.extend('keyfilter', {\n beforeMount(el, options) {\n let target = this.getTarget(el);\n\n if (!target) return;\n\n target.$_pkeyfilterModifier = this.getModifiers(options);\n\n if (options.value !== undefined) {\n target.$_pkeyfilterPattern = options.value?.pattern || options.value;\n target.$_pkeyfilterValidateOnly = options.value?.validateOnly || false;\n }\n\n this.bindEvents(target);\n\n target.setAttribute('data-pd-keyfilter', true);\n },\n updated(el, options) {\n let target = this.getTarget(el);\n\n if (!target) return;\n\n target.$_pkeyfilterModifier = this.getModifiers(options);\n this.unbindEvents(el, options);\n\n if (options.value !== undefined) {\n target.$_pkeyfilterPattern = options.value?.pattern || options.value;\n target.$_pkeyfilterValidateOnly = options.value?.validateOnly || false;\n }\n\n this.bindEvents(target);\n },\n unmounted(el, options) {\n this.unbindEvents(el, options);\n },\n DEFAULT_PATTERNS: {\n pint: /[\\d]/,\n int: /[\\d-]/,\n pnum: /[\\d.]/,\n money: /[\\d.\\s,]/,\n num: /[\\d-.]/,\n hex: /[0-9a-f]/i,\n email: /[a-z0-9_.-@]/i,\n alpha: /[a-z_]/i,\n alphanum: /[a-z0-9_]/\n },\n methods: {\n getTarget(el) {\n return isAttributeEquals(el, 'data-pc-name', 'inputtext') || isAttributeEquals(el, 'data-pc-name', 'textarea') ? el : null;\n },\n getModifiers(options) {\n if (options.modifiers && Object.keys(options.modifiers).length) {\n return Object.keys(options.modifiers)[Object.keys.length - 1];\n }\n\n return '';\n },\n getRegex(target) {\n return target.$_pkeyfilterPattern ? target.$_pkeyfilterPattern : target.$_pkeyfilterModifier ? this.DEFAULT_PATTERNS[target.$_pkeyfilterModifier] : /./;\n },\n bindEvents(el) {\n el.$_keyfilterKeydownEvent = (event) => this.onKeydown(event, el);\n el.$_keyfilterPasteEvent = (event) => this.onPaste(event, el);\n\n el.addEventListener('keypress', el.$_keyfilterKeydownEvent);\n el.addEventListener('paste', el.$_keyfilterPasteEvent);\n },\n unbindEvents(el) {\n el.removeEventListener('keypress', el.$_keyfilterKeydownEvent);\n el.removeEventListener('paste', el.$_keyfilterPasteEvent);\n\n el.$_keyfilterKeydownEvent = null;\n el.$_keyfilterPasteEvent = null;\n },\n onKeydown(event, target) {\n if (event.ctrlKey || event.altKey || event.metaKey || event.key === 'Tab') {\n return;\n }\n\n let regex = this.getRegex(target);\n\n if (regex === '') {\n return;\n }\n\n let testKey = `${event.key}`;\n\n if (target.$_pkeyfilterValidateOnly) {\n testKey = `${target.value.substring(0, target.selectionStart)}${event.key}${target.value.substring(target.selectionEnd)}`;\n }\n\n if (!regex.test(testKey)) {\n // runs before @update:modelValue emit\n event.preventDefault();\n }\n },\n onPaste(event, target) {\n let regex = this.getRegex(target);\n\n if (regex === '') {\n return;\n }\n\n const clipboard = event.clipboardData.getData('text');\n\n if (target.$_pkeyfilterValidateOnly) {\n const newValue = `${target.value.substring(0, target.selectionStart)}${clipboard}${target.value.substring(target.selectionEnd)}`;\n\n if (!regex.test(newValue)) {\n event.preventDefault();\n }\n } else {\n for (let i = 0; i < clipboard.length; i++) {\n if (!regex.test(clipboard[i])) {\n event.preventDefault();\n\n return;\n }\n }\n }\n }\n }\n});\n\nexport default KeyFilter;\n"],"names":["BaseKeyFilter","BaseDirective","extend","style","KeyFilterStyle","KeyFilter","beforeMount","el","options","target","getTarget","$_pkeyfilterModifier","getModifiers","value","undefined","_options$value","_options$value2","$_pkeyfilterPattern","pattern","$_pkeyfilterValidateOnly","validateOnly","bindEvents","setAttribute","updated","unbindEvents","_options$value3","_options$value4","unmounted","DEFAULT_PATTERNS","pint","pnum","money","num","hex","email","alpha","alphanum","methods","isAttributeEquals","modifiers","Object","keys","length","getRegex","_this","$_keyfilterKeydownEvent","event","onKeydown","$_keyfilterPasteEvent","onPaste","addEventListener","removeEventListener","ctrlKey","altKey","metaKey","key","regex","testKey","concat","substring","selectionStart","selectionEnd","test","preventDefault","clipboard","clipboardData","getData","newValue","i"],"mappings":";;;;AAGA,IAAMA,aAAa,GAAGC,aAAa,CAACC,MAAM,CAAC;AACvCC,EAAAA,KAAK,EAAEC;AACX,CAAC,CAAC;;ACFF,IAAMC,SAAS,GAAGL,aAAa,CAACE,MAAM,CAAC,WAAW,EAAE;AAChDI,EAAAA,WAAW,WAAXA,WAAWA,CAACC,EAAE,EAAEC,OAAO,EAAE;AACrB,IAAA,IAAIC,MAAM,GAAG,IAAI,CAACC,SAAS,CAACH,EAAE,CAAC;IAE/B,IAAI,CAACE,MAAM,EAAE;IAEbA,MAAM,CAACE,oBAAoB,GAAG,IAAI,CAACC,YAAY,CAACJ,OAAO,CAAC;AAExD,IAAA,IAAIA,OAAO,CAACK,KAAK,KAAKC,SAAS,EAAE;MAAA,IAAAC,cAAA,EAAAC,eAAA;AAC7BP,MAAAA,MAAM,CAACQ,mBAAmB,GAAG,EAAAF,cAAA,GAAAP,OAAO,CAACK,KAAK,MAAAE,IAAAA,IAAAA,cAAA,uBAAbA,cAAA,CAAeG,OAAO,KAAIV,OAAO,CAACK,KAAK;AACpEJ,MAAAA,MAAM,CAACU,wBAAwB,GAAG,CAAAH,CAAAA,eAAA,GAAAR,OAAO,CAACK,KAAK,MAAA,IAAA,IAAAG,eAAA,KAAbA,MAAAA,GAAAA,MAAAA,GAAAA,eAAA,CAAeI,YAAY,KAAI,KAAK;AAC1E;AAEA,IAAA,IA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