@sixbell-telco/sdk
Version:
A collection of reusable components designed for use in Sixbell Telco Angular projects
1 lines • 4.57 kB
Source Map (JSON)
{"version":3,"file":"sixbell-telco-sdk-directives-only-numbers.mjs","sources":["../../../projects/sdk/directives/only-numbers/src/only-numbers.directive.ts","../../../projects/sdk/directives/only-numbers/public-api.ts","../../../projects/sdk/directives/only-numbers/sixbell-telco-sdk-directives-only-numbers.ts"],"sourcesContent":["import { Directive, HostListener, input } from '@angular/core';\n\n/**\n * Directive that restricts input to numeric characters only.\n *\n * Use the `stOnlyNumbers` selector to enable numeric-only input restriction.\n * For backward compatibility, the `stJustNumbers` selector is also supported but is deprecated.\n *\n * @example\n * ```html\n * <!-- Modern usage (recommended) -->\n * <input stOnlyNumbers />\n * <input [stOnlyNumbers]=\"true\" />\n * ```\n */\n@Directive({\n\tselector: '[stOnlyNumbers], [stJustNumbers]',\n\tstandalone: true,\n})\nexport class OnlyNumbersDirective {\n\t/**\n\t * Enable numeric-only input restriction.\n\t * @default false\n\t */\n\tstOnlyNumbers = input<boolean>(false);\n\n\t/**\n\t * @deprecated Use `stOnlyNumbers` input instead.\n\t * This input is maintained for backward compatibility and will be removed in a future major version.\n\t */\n\tjustNumbers = input<boolean>(false);\n\n\tconstructor() {}\n\n\t@HostListener('paste', ['$event'])\n\tblockPaste(event: ClipboardEvent) {\n\t\tif (!this.getEnabled()) return true;\n\n\t\tconst justNumbersReg = new RegExp('^[0-9]+$');\n\t\tconst clipboardData = event.clipboardData;\n\t\tif (!clipboardData) return true;\n\n\t\tconst pastedValue = clipboardData.getData('Text');\n\t\tif (!justNumbersReg.test(pastedValue)) {\n\t\t\tevent.preventDefault();\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n\n\t@HostListener('keypress', ['$event'])\n\tonKeyPress(event: KeyboardEvent) {\n\t\tif (!this.getEnabled()) return true;\n\n\t\tconst key = event.key;\n\t\tif (!/^[0-9]$/.test(key)) {\n\t\t\tevent.preventDefault();\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t}\n\n\t/**\n\t * Determines if the numeric-only restriction is enabled.\n\t * Checks both the new and deprecated inputs for backward compatibility.\n\t * @private\n\t */\n\tprivate getEnabled(): boolean {\n\t\t// Check new input first, fallback to deprecated input for backward compatibility\n\t\treturn this.stOnlyNumbers() || this.justNumbers();\n\t}\n}\n","// Export the new directive without deprecation\nexport { OnlyNumbersDirective } from './src/only-numbers.directive';\n\n/**\n * @deprecated Use `OnlyNumbersDirective` instead.\n * This alias is maintained for backward compatibility and will be removed in a future major version.\n */\nexport { OnlyNumbersDirective as JustNumbersDirective } from './src/only-numbers.directive';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;AAEA;;;;;;;;;;;;AAYG;MAKU,oBAAoB,CAAA;AAChC;;;AAGG;AACH,IAAA,aAAa,GAAG,KAAK,CAAU,KAAK,CAAC;AAErC;;;AAGG;AACH,IAAA,WAAW,GAAG,KAAK,CAAU,KAAK,CAAC;AAEnC,IAAA,WAAA,GAAA;AAGA,IAAA,UAAU,CAAC,KAAqB,EAAA;AAC/B,QAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AAAE,YAAA,OAAO,IAAI;AAEnC,QAAA,MAAM,cAAc,GAAG,IAAI,MAAM,CAAC,UAAU,CAAC;AAC7C,QAAA,MAAM,aAAa,GAAG,KAAK,CAAC,aAAa;AACzC,QAAA,IAAI,CAAC,aAAa;AAAE,YAAA,OAAO,IAAI;QAE/B,MAAM,WAAW,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;QACjD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;YACtC,KAAK,CAAC,cAAc,EAAE;AACtB,YAAA,OAAO,KAAK;;AAGb,QAAA,OAAO,IAAI;;AAIZ,IAAA,UAAU,CAAC,KAAoB,EAAA;AAC9B,QAAA,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;AAAE,YAAA,OAAO,I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