ngx-digits-only 1.0.3 → 1.1.0
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.
- package/README.md +382 -52
- package/fesm2022/ngx-digits-only.mjs +105 -56
- package/fesm2022/ngx-digits-only.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-digits-only.d.ts +43 -13
package/package.json
CHANGED
|
@@ -85,8 +85,16 @@ declare class DigitsOnlyDirective implements ControlValueAccessor, Validator, On
|
|
|
85
85
|
private el;
|
|
86
86
|
private renderer;
|
|
87
87
|
private document;
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* How many decimal places are allowed. Ignored when pattern is set.
|
|
90
|
+
*
|
|
91
|
+
* 0 (default) — integers only, decimal point blocked
|
|
92
|
+
* N — exactly N decimal places allowed (e.g. 2 for currency)
|
|
93
|
+
* null — unlimited decimal places allowed
|
|
94
|
+
*
|
|
95
|
+
* Matches the same null = "no limit" convention used by maxLength, min, and max.
|
|
96
|
+
*/
|
|
97
|
+
decimalPlaces: number | null;
|
|
90
98
|
/** Visual grouping character inserted between digit groups. Ignored when pattern is set. */
|
|
91
99
|
thousandSeparator: '' | ',' | '.' | ' ' | '_';
|
|
92
100
|
/** Visual text prepended to the displayed value (e.g. '$'). Never reaches the model. */
|
|
@@ -205,12 +213,6 @@ declare class DigitsOnlyDirective implements ControlValueAccessor, Validator, On
|
|
|
205
213
|
* number portion start" — cursor clamping, minus-key position check, etc.
|
|
206
214
|
*/
|
|
207
215
|
private get editableStartOffset();
|
|
208
|
-
/**
|
|
209
|
-
* The number of characters at the RIGHT end of the display string that
|
|
210
|
-
* belong to the suffix (LTR) or prefix (RTL) — i.e. characters the cursor
|
|
211
|
-
* must never move past on the right side.
|
|
212
|
-
*/
|
|
213
|
-
private get editableEndPadding();
|
|
214
216
|
constructor(el: ElementRef<HTMLInputElement>, renderer: Renderer2, document: Document);
|
|
215
217
|
ngOnInit(): void;
|
|
216
218
|
ngOnChanges(changes: SimpleChanges): void;
|
|
@@ -270,11 +272,11 @@ declare class DigitsOnlyDirective implements ControlValueAccessor, Validator, On
|
|
|
270
272
|
*/
|
|
271
273
|
private buildModelValue;
|
|
272
274
|
/**
|
|
273
|
-
* Write the formatted display string back to the <input> DOM element
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
275
|
+
* Write the formatted display string back to the <input> DOM element.
|
|
276
|
+
* Cursor placement is left entirely to the browser — we never call
|
|
277
|
+
* setSelectionRange here. The browser naturally keeps the cursor where
|
|
278
|
+
* the user last interacted, which is the correct behaviour for both
|
|
279
|
+
* LTR and RTL inputs.
|
|
278
280
|
*/
|
|
279
281
|
private refreshDisplay;
|
|
280
282
|
/**
|
|
@@ -373,6 +375,34 @@ declare class DigitsOnlyDirective implements ControlValueAccessor, Validator, On
|
|
|
373
375
|
* '0' pos 7 → digit (raw index 4) digit consumed → raw index 5
|
|
374
376
|
* We reached position 8, so raw index = 5 ✔
|
|
375
377
|
*/
|
|
378
|
+
/**
|
|
379
|
+
* Convert a DOM cursor position (selectionStart) to an index inside the
|
|
380
|
+
* raw digit string.
|
|
381
|
+
*
|
|
382
|
+
* Works correctly in both LTR and RTL:
|
|
383
|
+
*
|
|
384
|
+
* LTR: display = [prefix][formattedNumber][suffix]
|
|
385
|
+
* number starts at prefix.length
|
|
386
|
+
*
|
|
387
|
+
* RTL: display = [LRM][suffix][formattedNumber][prefix]
|
|
388
|
+
* number starts at LRM.length + suffix.length
|
|
389
|
+
*
|
|
390
|
+
* In both cases we subtract editableStartOffset to get a position
|
|
391
|
+
* relative to the start of the formatted number, then walk the pattern
|
|
392
|
+
* (if any) to count how many raw digits precede that position.
|
|
393
|
+
*
|
|
394
|
+
* Non-pattern mode:
|
|
395
|
+
* The cursor position inside the number portion equals the raw digit
|
|
396
|
+
* index directly (no separators injected in string/integer mode, and
|
|
397
|
+
* thousands separators shift characters but the raw index is what we
|
|
398
|
+
* need for splice operations).
|
|
399
|
+
*
|
|
400
|
+
* Example (RTL, pattern='(000) 000-0000', prefix='﷼', suffix=''):
|
|
401
|
+
* editableStartOffset = LRM.length (1) + suffix.length (0) = 1
|
|
402
|
+
* displayCursorPos = 5 → positionInPattern = 5 - 1 = 4
|
|
403
|
+
* Walk: '(' pos0, '5' pos1 (raw 1), '5' pos2 (raw 2), '5' pos3 (raw 3), ')' pos4
|
|
404
|
+
* → rawDigitIndex = 3 ✔
|
|
405
|
+
*/
|
|
376
406
|
private mapDisplayCursorToRawIndex;
|
|
377
407
|
/**
|
|
378
408
|
* Decide whether a keyboard event is a "control" key that should always
|