@pongrass/utils 1.1.8-v20 → 1.1.9-v20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -664,7 +664,7 @@ class CheckboxCellRendererComponent {
664
664
  }
665
665
  // Return Cell Value
666
666
  refresh(params) {
667
- this.value = params.value === 'Y' || params.value === 1 ? true : false;
667
+ this.value = params.value === 'Y' || params.value === 1 || params.value === '1' ? true : false;
668
668
  return true;
669
669
  }
670
670
  onChangeCheckBox(event) {
@@ -1686,72 +1686,72 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
1686
1686
  args: ['keydown', ['$event']]
1687
1687
  }] } });
1688
1688
 
1689
- /* eslint-disable @typescript-eslint/no-explicit-any */
1690
1689
  class DecimalInputDirective {
1691
1690
  el = inject((ElementRef));
1692
- control = inject(NgControl);
1693
- sub;
1691
+ control = inject(NgControl, { optional: true });
1694
1692
  wsDecimalInput = 4;
1695
1693
  wsAcceptStringInput = true;
1696
- specialKeys = ['Backspace', 'Tab', 'End', 'Home', 'ArrowLeft', 'ArrowRight', 'Delete'];
1697
- ngOnInit() {
1698
- // Only format when value comes from patchValue / setValue (not typing)
1699
- this.sub = this.control.valueChanges?.subscribe(value => {
1700
- const inputEl = this.el.nativeElement;
1701
- // Skip if input element is focused (user typing)
1702
- if (document.activeElement === inputEl)
1703
- return;
1704
- this.formatValue(value);
1705
- });
1706
- }
1707
- ngOnDestroy() {
1708
- this.sub?.unsubscribe();
1694
+ get decimalPlaces() {
1695
+ return this.wsDecimalInput;
1709
1696
  }
1710
- onKeyDown(event) {
1697
+ onInput(e) {
1711
1698
  const input = this.el.nativeElement;
1712
- const value = input.value;
1713
- if (this.specialKeys.includes(event.key))
1714
- return;
1715
- if (event.key === '.' && value.includes('.')) {
1716
- event.preventDefault();
1717
- return;
1699
+ const before = input.value;
1700
+ let cleaned = before.replace(/[^0-9.]/g, '');
1701
+ const parts = cleaned.split('.');
1702
+ if (parts.length > 2) {
1703
+ cleaned = parts[0] + '.' + parts.slice(1).join('');
1718
1704
  }
1719
- const cursorPos = input.selectionStart ?? value.length;
1720
- const nextValue = this.getNextValue(value, event.key, cursorPos);
1721
- if (!this.isValidInput(nextValue)) {
1722
- event.preventDefault();
1705
+ if (parts.length === 2 && parts[1].length > this.decimalPlaces) {
1706
+ cleaned = parts[0] + '.' + parts[1].slice(0, this.decimalPlaces);
1707
+ }
1708
+ if (cleaned !== before) {
1709
+ const cursorPos = input.selectionStart ?? 0;
1710
+ input.value = cleaned;
1711
+ const newPos = cursorPos + (cleaned.length - before.length);
1712
+ input.setSelectionRange(newPos, newPos);
1713
+ this.control?.control?.setValue(this.wsAcceptStringInput ? cleaned : Number(cleaned) || null, { emitEvent: false, onlySelf: true });
1723
1714
  }
1724
1715
  }
1725
- onBlur() {
1726
- this.formatValue(this.el.nativeElement.value);
1716
+ onPaste(e) {
1717
+ const text = e.clipboardData?.getData('text') ?? '';
1718
+ if (!/^\d*\.?\d*$/.test(text)) {
1719
+ e.preventDefault();
1720
+ }
1727
1721
  }
1728
- formatValue(value) {
1729
- if (value === null || value === undefined || value === '')
1722
+ onBlur() {
1723
+ const val = this.el.nativeElement.value.trim();
1724
+ if (!val)
1730
1725
  return;
1731
- if (isNaN(Number(value)))
1726
+ const num = Number(val);
1727
+ if (isNaN(num))
1732
1728
  return;
1733
- const [integerPart, decimalPart = ''] = value.toString().split('.');
1734
- let formatted = integerPart + '.' + decimalPart.padEnd(this.wsDecimalInput, '0');
1735
- if (decimalPart.length > this.wsDecimalInput) {
1736
- formatted = integerPart + '.' + decimalPart.slice(0, this.wsDecimalInput);
1737
- }
1738
- if (this.wsAcceptStringInput) {
1739
- this.control.control?.setValue(formatted, { emitEvent: false });
1729
+ let str = num.toFixed(this.decimalPlaces);
1730
+ if (!this.wsAcceptStringInput) {
1731
+ this.control?.control?.setValue(num, { emitEvent: false });
1740
1732
  }
1741
1733
  else {
1742
- this.control.control?.setValue(Number(formatted), { emitEvent: false });
1734
+ this.control?.control?.setValue(str, { emitEvent: false });
1743
1735
  }
1744
- this.el.nativeElement.value = formatted;
1736
+ this.el.nativeElement.value = str;
1745
1737
  }
1746
- isValidInput(value) {
1747
- const regex = new RegExp(`^\\d*\\.?\\d{0,${this.wsDecimalInput}}$`);
1748
- return regex.test(value);
1738
+ constructor() {
1739
+ this.control?.valueChanges?.subscribe(v => {
1740
+ if (document.activeElement !== this.el.nativeElement) {
1741
+ this.formatProgrammatic(v);
1742
+ }
1743
+ });
1749
1744
  }
1750
- getNextValue(currentValue, key, cursorPos) {
1751
- return currentValue.slice(0, cursorPos) + key + currentValue.slice(cursorPos);
1745
+ formatProgrammatic(value) {
1746
+ if (value == null || value === '') {
1747
+ this.el.nativeElement.value = '';
1748
+ return;
1749
+ }
1750
+ const str = Number(value).toFixed(this.decimalPlaces);
1751
+ this.el.nativeElement.value = str;
1752
1752
  }
1753
1753
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: DecimalInputDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1754
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: DecimalInputDirective, isStandalone: true, selector: "[wsDecimalInput]", inputs: { wsDecimalInput: "wsDecimalInput", wsAcceptStringInput: "wsAcceptStringInput" }, host: { listeners: { "keydown": "onKeyDown($event)", "blur": "onBlur()" } }, ngImport: i0 });
1754
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.9", type: DecimalInputDirective, isStandalone: true, selector: "[wsDecimalInput]", inputs: { wsDecimalInput: "wsDecimalInput", wsAcceptStringInput: "wsAcceptStringInput" }, host: { listeners: { "input": "onInput($event)", "paste": "onPaste($event)", "blur": "onBlur()" } }, ngImport: i0 });
1755
1755
  }
1756
1756
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImport: i0, type: DecimalInputDirective, decorators: [{
1757
1757
  type: Directive,
@@ -1759,13 +1759,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.9", ngImpor
1759
1759
  selector: '[wsDecimalInput]',
1760
1760
  standalone: true
1761
1761
  }]
1762
- }], propDecorators: { wsDecimalInput: [{
1762
+ }], ctorParameters: () => [], propDecorators: { wsDecimalInput: [{
1763
1763
  type: Input
1764
1764
  }], wsAcceptStringInput: [{
1765
1765
  type: Input
1766
- }], onKeyDown: [{
1766
+ }], onInput: [{
1767
1767
  type: HostListener,
1768
- args: ['keydown', ['$event']]
1768
+ args: ['input', ['$event']]
1769
+ }], onPaste: [{
1770
+ type: HostListener,
1771
+ args: ['paste', ['$event']]
1769
1772
  }], onBlur: [{
1770
1773
  type: HostListener,
1771
1774
  args: ['blur']
@@ -2217,7 +2220,7 @@ class MultiFormComponent {
2217
2220
  this.multiForm.markAsPristine();
2218
2221
  }
2219
2222
  getTruthyOrFalsy(value) {
2220
- return value === '1' ? true : false;
2223
+ return value === '1' || value === 1 ? true : false;
2221
2224
  }
2222
2225
  getValidators(validations) {
2223
2226
  const validators = [];