use-mask-input 3.6.0 → 3.7.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +53 -76
  2. package/README.md +2 -251
  3. package/dist/antd/index.cjs +67 -0
  4. package/dist/antd/index.cjs.map +1 -0
  5. package/dist/antd/index.d.cts +37 -0
  6. package/dist/antd/index.d.ts +37 -0
  7. package/dist/antd/index.js +64 -0
  8. package/dist/antd/index.js.map +1 -0
  9. package/dist/chunk-4Y2DTPBL.cjs +3841 -0
  10. package/dist/chunk-4Y2DTPBL.cjs.map +1 -0
  11. package/dist/chunk-JGOZSJMW.js +3829 -0
  12. package/dist/chunk-JGOZSJMW.js.map +1 -0
  13. package/dist/index-F3rlTTTe.d.cts +583 -0
  14. package/dist/index-F3rlTTTe.d.ts +583 -0
  15. package/dist/index.cjs +72 -3870
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +48 -585
  18. package/dist/index.d.ts +48 -585
  19. package/dist/index.js +72 -3870
  20. package/dist/index.js.map +1 -1
  21. package/package.json +27 -21
  22. package/src/antd/index.ts +9 -0
  23. package/src/antd/useHookFormMaskAntd.spec.ts +142 -0
  24. package/src/antd/useHookFormMaskAntd.ts +57 -0
  25. package/src/antd/useMaskInputAntd-server.spec.tsx +36 -0
  26. package/src/antd/useMaskInputAntd.spec.tsx +108 -0
  27. package/src/antd/useMaskInputAntd.ts +77 -0
  28. package/src/api/index.ts +4 -0
  29. package/src/api/useHookFormMask.spec.ts +146 -0
  30. package/src/api/useHookFormMask.ts +56 -0
  31. package/src/api/useMaskInput-server.spec.tsx +30 -0
  32. package/src/api/useMaskInput.spec.tsx +220 -0
  33. package/src/api/useMaskInput.ts +73 -0
  34. package/src/api/withHookFormMask.spec.ts +155 -0
  35. package/src/api/withHookFormMask.ts +54 -0
  36. package/src/api/withMask.spec.ts +93 -0
  37. package/src/api/withMask.ts +25 -0
  38. package/src/core/elementResolver.spec.ts +175 -0
  39. package/src/core/elementResolver.ts +84 -0
  40. package/src/core/index.ts +3 -0
  41. package/src/core/maskConfig.spec.ts +183 -0
  42. package/src/core/maskConfig.ts +56 -0
  43. package/src/core/maskEngine.spec.ts +108 -0
  44. package/src/core/maskEngine.ts +47 -0
  45. package/src/index.tsx +12 -5
  46. package/src/{types.ts → types/index.ts} +13 -0
  47. package/src/utils/flow.spec.ts +27 -30
  48. package/src/utils/flow.ts +2 -2
  49. package/src/utils/index.ts +1 -1
  50. package/src/utils/isServer.spec.ts +15 -0
  51. package/src/utils/moduleInterop.spec.ts +37 -0
  52. package/src/useHookFormMask.ts +0 -47
  53. package/src/useMaskInput.ts +0 -41
  54. package/src/utils/getMaskOptions.spec.ts +0 -126
  55. package/src/utils/getMaskOptions.ts +0 -94
  56. package/src/withHookFormMask.ts +0 -34
  57. package/src/withMask.ts +0 -18
  58. /package/src/{inputmask.types.ts → types/inputmask.types.ts} +0 -0
package/dist/index.d.cts CHANGED
@@ -1,593 +1,56 @@
1
- import { UseFormRegisterReturn, FieldValues, RegisterOptions, UseFormRegister, Path } from 'react-hook-form';
1
+ import { M as Mask, O as Options, I as Input, U as UseHookFormMaskReturn } from './index-F3rlTTTe.cjs';
2
+ import { FieldValues, RegisterOptions, UseFormRegister, Path, UseFormRegisterReturn } from 'react-hook-form';
2
3
  export { UseFormRegister, UseFormRegisterReturn } from 'react-hook-form';
3
- import { RefObject } from 'react';
4
+ import 'react';
4
5
 
5
- type Range = {
6
- start: string;
7
- end: string;
8
- } | [string, string];
9
- type PositionCaretOnClick = 'none' | 'lvp' | 'radixFocus' | 'select' | 'ignore';
10
- type InputMode = 'verbatim' | 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url';
11
- type Casing = 'upper' | 'lower' | 'title';
12
- type DefinitionValidator = (chrs: string, maskset: any, pos: number, strict: boolean, opts: Options$1) => boolean | CommandObject;
13
- interface Options$1 {
14
- /**
15
- * Change the mask placeholder. Instead of "_", you can change the unfilled
16
- * characters mask as you like, simply by adding the placeholder option.
17
- * For example, placeholder: " " will change the default autofill with empty
18
- * values.
19
- *
20
- * @default "_"
21
- */
22
- placeholder?: string | undefined;
23
- /**
24
- * Definition of the symbols used to indicate an optional part in the mask.
25
- *
26
- * @default { start: "[", end: "]" }
27
- */
28
- optionalmarker?: Range | undefined;
29
- /**
30
- * Definition of the symbols used to indicate a quantifier in the mask.
31
- *
32
- * @default { start: "{", end: "}" }
33
- */
34
- quantifiermarker?: Range | undefined;
35
- /**
36
- * Definition of the symbols used to indicate a group in the mask.
37
- *
38
- * @default { start: "(", end: ")" }
39
- */
40
- groupmarker?: Range | undefined;
41
- /**
42
- * Definition of the symbols used to indicate an alternator part in the mask.
43
- *
44
- * @default "|"
45
- */
46
- alternatormarker?: string | undefined;
47
- /**
48
- * Definition of the symbols used to escape a part in the mask.
49
- *
50
- * @default "\\"
51
- */
52
- escapeChar?: string | undefined;
53
- /**
54
- * The mask to use.
55
- */
56
- mask?: string | string[] | ((opts: Options$1) => string | string[]) | undefined;
57
- /**
58
- * Use a regular expression as a mask. When using shorthands be aware that you need to double escape or use
59
- * String.raw with a string literal.
60
- */
61
- regex?: string | undefined;
62
- /**
63
- * Execute a function when the mask is completed.
64
- */
65
- oncomplete?: (() => void) | undefined;
66
- /**
67
- * Execute a function when the mask is cleared.
68
- */
69
- onincomplete?: (() => void) | undefined;
70
- /**
71
- * Execute a function when the mask is cleared.
72
- */
73
- oncleared?: (() => void) | undefined;
74
- /**
75
- * Mask repeat function. Repeat the mask definition x-times.
76
- * `*` ~ forever, otherwise specify an integer
77
- *
78
- * @default 0
79
- */
80
- repeat?: number | string | undefined;
81
- /**
82
- * Toggle to allocate as much possible or the opposite. Non-greedy repeat function. With the non-greedy option
83
- * set to `false`, you can specify `*` as repeat. This makes an endless repeat.
84
- *
85
- * @default false
86
- */
87
- greedy?: boolean | undefined;
88
- /**
89
- * Automatically unmask the value when retrieved.
90
- *
91
- * When setting this option to true the plugin also expects the initial value from the server to be unmasked.
92
- *
93
- * @default false
94
- */
95
- autoUnmask?: boolean | undefined;
96
- /**
97
- * Remove the mask before submitting the form.
98
- *
99
- * @default false
100
- */
101
- removeMaskOnSubmit?: boolean | undefined;
102
- /**
103
- * Remove the empty mask on blur or when not empty remove the optional trailing part.
104
- *
105
- * @default true
106
- */
107
- clearMaskOnLostFocus?: boolean | undefined;
108
- /**
109
- * Toggle to insert or overwrite input. This option can be altered by pressing the Insert key.
110
- *
111
- * @default true
112
- */
113
- insertMode?: boolean | undefined;
114
- /**
115
- * Show selected caret when `insertMode = false`.
116
- *
117
- * @default true
118
- */
119
- insertModeVisual?: boolean | undefined;
120
- /**
121
- * Clear the incomplete input on blur.
122
- *
123
- * @default false
124
- */
125
- clearIncomplete?: boolean | undefined;
126
- /**
127
- * The alias to use.
128
- *
129
- * @default null
130
- */
131
- alias?: string | undefined;
132
- /**
133
- * Callback to implement autocomplete on certain keys for example.
134
- */
135
- onKeyDown?: ((event: KeyboardEvent, buffer: string[], caretPos: {
136
- begin: number;
137
- end: number;
138
- }, opts: Options$1) => void) | undefined;
139
- /**
140
- * Executes before masking the initial value to allow preprocessing of the initial value.
141
- */
142
- onBeforeMask?: ((initialValue: string, opts: Options$1) => string) | undefined;
143
- /**
144
- * This callback allows for preprocessing the pasted value before actually handling the value for masking.
145
- * This can be useful for stripping away some characters before processing. You can also disable pasting
146
- * a value by returning false in the `onBeforePaste` call.
147
- */
148
- onBeforePaste?: ((pastedValue: string, opts: Options$1) => string) | undefined;
149
- /**
150
- * Executes before writing to the masked element. Use this to do some extra processing of the input. This can
151
- * be useful when implementing an alias, ex. decimal alias, autofill the digits when leaving the inputfield.
152
- */
153
- onBeforeWrite?: ((event: KeyboardEvent, buffer: string[], caretPos: number, opts: Options$1) => CommandObject) | undefined;
154
- /**
155
- * Executes after unmasking to allow post-processing of the unmaskedvalue.
156
- *
157
- * @returns New unmasked value
158
- */
159
- onUnMask?: ((maskedValue: string, unmaskedValue: string) => string) | undefined;
160
- /**
161
- * Shows the mask when the input gets focus.
162
- *
163
- * @default true
164
- */
165
- showMaskOnFocus?: boolean | undefined;
166
- /**
167
- * Shows the mask when the input is hevered by the mouse cursor.
168
- *
169
- * @default true
170
- */
171
- showMaskOnHover?: boolean | undefined;
172
- /**
173
- * Callback function is executed on every keyvalidation with the key, result as the parameter.
174
- */
175
- onKeyValidation?: ((key: number, result: boolean) => void) | undefined;
176
- /**
177
- * A character which can be used to skip an optional part of a mask.
178
- *
179
- * @default " "
180
- */
181
- skipOptionalPartCharacter?: string | undefined;
182
- /**
183
- * Numeric input direction. Keeps the caret at the end.
184
- *
185
- * @default false
186
- */
187
- numericInput?: boolean | undefined;
188
- /**
189
- * Align the input to the right
190
- *
191
- * By setting the rightAlign you can specify to right-align an inputmask. This is only applied in combination of
192
- * the `numericInput` option or the `dir-attribute`.
193
- *
194
- * @default true
195
- */
196
- rightAlign?: boolean | undefined;
197
- /**
198
- * Make escape behave like undo. (ctrl-Z) Pressing escape reverts the value to the value before focus.
199
- *
200
- * @default true
201
- */
202
- undoOnEscape?: boolean | undefined;
203
- /**
204
- * Define the radixpoint (decimal separator)
205
- *
206
- * @default ""
207
- */
208
- radixPoint?: string | undefined;
209
- /**
210
- * Define the groupseparator.
211
- *
212
- * @default ""
213
- */
214
- groupSeparator?: string | undefined;
215
- /**
216
- * Use in combination with the alternator syntax Try to keep the mask static while typing. Decisions to alter the
217
- * mask will be postponed if possible.
218
- *
219
- * ex. $(selector).inputmask({ mask: ["+55-99-9999-9999", "+55-99-99999-9999", ], keepStatic: true });
220
- *
221
- * typing 1212345123 => should result in +55-12-1234-5123 type extra 4 => switch to +55-12-12345-1234
222
- *
223
- * When the option is not set, it will default to `false`, except for multiple masks it will default to `true`!
224
- */
225
- keepStatic?: boolean | null | undefined;
226
- /**
227
- * When enabled the caret position is set after the latest valid position on TAB.
228
- *
229
- * @default true
230
- */
231
- positionCaretOnTab?: boolean | undefined;
232
- /**
233
- * Allows for tabbing through the different parts of the masked field.
234
- *
235
- * @default false
236
- */
237
- tabThrough?: boolean | undefined;
238
- /**
239
- * List with the supported input types
240
- *
241
- * @default ["text", "tel", "url", "password", "search"]
242
- */
243
- supportsInputType?: string[] | undefined;
244
- /**
245
- * Specify keyCodes which should not be considered in the keypress event, otherwise the `preventDefault` will
246
- * stop their default behavior especially in FF.
247
- */
248
- ignorables?: number[] | undefined;
249
- /**
250
- * With this call-in (hook) you can override the default implementation of the isComplete function.
251
- */
252
- isComplete?: ((buffer: string[], opts: Options$1) => boolean) | undefined;
253
- /**
254
- * Hook to postValidate the result from `isValid`. Useful for validating the entry as a whole.
255
- */
256
- postValidation?: ((buffer: string[], pos: number, char: string, currentResult: boolean, opts: Options$1, maskset: any, strict: boolean, fromCheckval: boolean) => boolean | CommandObject) | undefined;
257
- /**
258
- * Hook to preValidate the input. Useful for validating regardless of the definition.
259
- *
260
- * When returning `true`, the normal validation kicks in, otherwise, it is skipped.
261
- *
262
- * When returning a command object the actions are executed and further validation is stopped. If you want to
263
- * continue further validation, you need to add the `rewritePosition` action.
264
- */
265
- preValidation?: ((buffer: string[], pos: number, char: string, isSelection: boolean, opts: Options$1, maskset: any, caretPos: {
266
- begin: number;
267
- end: number;
268
- }, strict: boolean) => boolean | CommandObject) | undefined;
269
- /**
270
- * The `staticDefinitionSymbol` option is used to indicate that the static entries in the mask can match a
271
- * certain definition. Especially useful with alternators so that static element in the mask can match
272
- * another alternation.
273
- *
274
- * @default undefined
275
- */
276
- staticDefinitionSymbol?: string | undefined;
277
- /**
278
- * Just in time masking. With the `jitMasking` option you can enable jit masking. The mask will only be
279
- * visible for the user entered characters.
280
- *
281
- * @default false
282
- */
283
- jitMasking?: boolean | undefined;
284
- /**
285
- * Return nothing from the input `value` property when the user hasn't entered anything. If this is false,
286
- * the mask might be returned.
287
- *
288
- * @default true
289
- */
290
- nullable?: boolean | undefined;
291
- /**
292
- * Disable value property patching
293
- *
294
- * @default false
295
- */
296
- noValuePatching?: boolean | undefined;
297
- /**
298
- * Positioning of the caret on click.
299
- *
300
- * Options:
301
- *
302
- * * `none`
303
- * * `lvp` - based on the last valid position (default)
304
- * * `radixFocus` - position caret to radixpoint on initial click
305
- * * `select` - select the whole input
306
- * * `ignore` - ignore the click and continue the mask
307
- *
308
- * @default "lvp"
309
- */
310
- positionCaretOnClick?: PositionCaretOnClick | undefined;
311
- /**
312
- * Apply casing at the mask-level.
313
- *
314
- * @default undefined
315
- */
316
- casing?: Casing | undefined;
317
- /**
318
- * Specify the inputmode - already in place for when browsers start to support them
319
- * https://html.spec.whatwg.org/#input-modalities:-the-inputmode-attribute
320
- *
321
- * @default "verbatim"
322
- */
323
- inputmode?: InputMode | undefined;
324
- /**
325
- * Specify to use the `data-inputmask` attributes or to ignore them.
326
- *
327
- * If you don't use data attributes you can disable the import by specifying `importDataAttributes: false`.
328
- *
329
- * @default true
330
- */
331
- importDataAttributes?: boolean | undefined;
332
- /**
333
- * Alter the behavior of the char shifting on entry or deletion.
334
- *
335
- * In some cases shifting the mask entries or deletion should be more restrictive.
336
- *
337
- * Ex. date masks. Shifting month to day makes no sense
338
- *
339
- * @default true
340
- */
341
- shiftPositions?: boolean | undefined;
342
- /**
343
- * Use the default defined definitions from the prototype.
344
- *
345
- * @default true
346
- */
347
- usePrototypeDefinitions?: boolean | undefined;
348
- /**
349
- * Minimum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
350
- */
351
- min?: string | number | undefined;
352
- /**
353
- * Maximum value. This needs to be in the same format as the `inputFormat` when used with the datetime alias.
354
- */
355
- max?: string | number | undefined;
356
- /**
357
- * Number of fractionalDigits.
358
- *
359
- * Possible values:
360
- *
361
- * * A number describing the number of fractional digits.
362
- * * `*`
363
- * * Quantifier syntax like `2,4`. When the quantifier syntax is used, the `digitsOptional` option is ignored
364
- *
365
- * @default "*"
366
- */
367
- digits?: string | number | undefined;
368
- /**
369
- * Specify wheter the digits are optional.
370
- *
371
- * @default true
372
- */
373
- digitsOptional?: boolean | undefined;
374
- /**
375
- * Enforces the decimal part when leaving the input field.
376
- *
377
- * @default false
378
- */
379
- enforceDigitsOnBlur?: boolean | undefined;
380
- /**
381
- * Allow to enter -.
382
- *
383
- * @default true
384
- */
385
- allowMinus?: boolean | undefined;
386
- /**
387
- * Define your negationSymbol.
388
- *
389
- * @default { front: "-", back: "" }
390
- */
391
- negationSymbol?: {
392
- front: string;
393
- back: string;
394
- } | undefined;
395
- /**
396
- * Define a prefix.
397
- *
398
- * @default ""
399
- */
400
- prefix?: string | undefined;
401
- /**
402
- * Define a suffix.
403
- *
404
- * @default ""
405
- */
406
- suffix?: string | undefined;
407
- /**
408
- * Set the maximum value when the user types a number which is greater that the value of max.
409
- *
410
- * @default false
411
- */
412
- SetMaxOnOverflow?: boolean | undefined;
413
- /**
414
- * Define the step the ctrl-up & ctrl-down must take.
415
- *
416
- * @default 1
417
- */
418
- step?: number | undefined;
419
- /**
420
- * Make unmasking returning a number instead of a string.
421
- *
422
- * Be warned that using the unmaskAsNumber option together with jQuery.serialize will fail as serialize expects a string. (See issue #1288)
423
- *
424
- * @default false
425
- */
426
- unmaskAsNumber?: boolean | undefined;
427
- /**
428
- * Indicates whether the value passed for initialization is text or a number.
429
- *
430
- * * `text` - radixpoint should be the same as in the options
431
- * * `number` - radixpoint should be a . as the default for a number in js
432
- *
433
- * @default "text"
434
- */
435
- inputType?: 'text' | 'number' | undefined;
436
- /**
437
- * Set the function for rounding the values when set.
438
- *
439
- * Other examples:
440
- * * `Math.floor`
441
- * * `fn(x) { // do your own rounding logic // return x; }`
442
- *
443
- * @default Math.round
444
- */
445
- roundingFN?: ((input: number) => number) | undefined;
446
- /**
447
- * Define shortcuts. This will allow typing 1k => 1000, 2m => 2000000
448
- *
449
- * To disable just pass shortcuts: `null` as option
450
- *
451
- * @default {k: "000", m: "000000"}
452
- */
453
- shortcuts?: Record<string, string> | null | undefined;
454
- /**
455
- * Format used to input a date. This option is only effective for the datetime alias.
456
- *
457
- * Supported symbols
458
- *
459
- * * `d` - Day of the month as digits; no leading zero for single-digit days.
460
- * * `dd` - Day of the month as digits; leading zero for single-digit days.
461
- * * `ddd` - Day of the week as a three-letter abbreviation.
462
- * * `dddd` - Day of the week as its full name.
463
- * * `m` - Month as digits; no leading zero for single-digit months.
464
- * * `mm` - Month as digits; leading zero for single-digit months.
465
- * * `mmm` - Month as a three-letter abbreviation.
466
- * * `mmmm` - Month as its full name.
467
- * * `yy` - Year as last two digits; leading zero for years less than 10.
468
- * * `yyyy` - Year as 4 digits.
469
- * * `h` - Hours; no leading zero for single-digit hours (12-hour clock).
470
- * * `hh` - Hours; leading zero for single-digit hours (12-hour clock).
471
- * * `hx` - Hours; no limit; `x` = number of digits ~ use as h2, h3, ...
472
- * * `H` - Hours; no leading zero for single-digit hours (24-hour clock).
473
- * * `HH` - Hours; leading zero for single-digit hours (24-hour clock).
474
- * * `Hx` - Hours; no limit; `x` = number of digits ~ use as H2, H3, ...
475
- * * `M` - Minutes; no leading zero for single-digit minutes. Uppercase M unlike CF timeFormat's m to avoid
476
- * conflict with months.
477
- * * `MM` - Minutes; leading zero for single-digit minutes. Uppercase MM unlike CF timeFormat's mm to avoid
478
- * conflict with months.
479
- * * `s` - Seconds; no leading zero for single-digit seconds.
480
- * * `ss` - Seconds; leading zero for single-digit seconds.
481
- * * `l` - Milliseconds. 3 digits.
482
- * * `L` - Milliseconds. 2 digits.
483
- * * `t` - Lowercase, single-character time marker string: a or p.
484
- * * `tt` - Two-character time marker string: am or pm.
485
- * * `T` - Single-character time marker string: A or P.
486
- * * `TT` - Two-character time marker string: AM or PM.
487
- * * `Z` - US timezone abbreviation, e.g. EST or MDT. With non-US timezones or in the Opera browser, the
488
- * GMT/UTC offset is returned, e.g. GMT-0500
489
- * * `o` - GMT/UTC timezone offset, e.g. -0500 or +0230.
490
- * * `S` - The date's ordinal suffix (st, nd, rd, or th). Works well with d.
491
- *
492
- * @default "isoDateTime"
493
- */
494
- inputFormat?: string | undefined;
495
- /**
496
- * Format of the unmasked value. This is only effective when used with the datetime alias.
497
- */
498
- outputFormat?: string | undefined;
499
- /**
500
- * Visual format when the input looses focus
501
- */
502
- displayFormat?: string | undefined;
503
- /**
504
- * Add new definitions to this inputmask.
505
- */
506
- definitions?: Record<string, Definition> | undefined;
507
- /**
508
- * Enable/disable prefilling of the year.
509
- * Although you can just over type the proposed value without deleting, many seems to see a problem with the year prediction.
510
- * This options is to disable this feature.
511
- *
512
- * @default true
513
- */
514
- prefillYear?: boolean | undefined;
515
- }
516
- interface Definition {
517
- validator: string | DefinitionValidator;
518
- casing?: Casing | undefined;
519
- cardinality?: number | undefined;
520
- placeholder?: string | undefined;
521
- definitionSymbol?: string | undefined;
522
- }
523
- interface InsertPosition {
524
- /**
525
- * Position to insert.
526
- */
527
- pos: number;
528
- /**
529
- * Character to insert.
530
- */
531
- c: string;
532
- /**
533
- * @default true
534
- */
535
- fromIsValid?: boolean | undefined;
536
- /**
537
- * @default true
538
- */
539
- strict?: boolean | undefined;
540
- }
541
- interface CommandObject {
542
- /**
543
- * Position to insert.
544
- */
545
- pos?: number | undefined;
546
- /**
547
- * Character to insert.
548
- */
549
- c?: string | undefined;
550
- /**
551
- * Position of the caret.
552
- */
553
- caret?: number | undefined;
554
- /**
555
- * Position(s) to remove.
556
- */
557
- remove?: number | number[] | undefined;
558
- /**
559
- * Position(s) to add.
560
- */
561
- insert?: InsertPosition | InsertPosition[] | undefined;
562
- /**
563
- * * `true` => refresh validPositions from the complete buffer .
564
- * * `{ start: , end: }` => refresh from start to end.
565
- */
566
- refreshFromBuffer?: true | {
567
- start: number;
568
- end: number;
569
- } | undefined;
570
- /**
571
- * Rewrite the maskPos within the isvalid function.
572
- */
573
- rewritePosition?: number | undefined;
6
+ interface UseMaskInputOptions {
7
+ mask: Mask;
8
+ register?: (element: HTMLElement) => void;
9
+ options?: Options;
574
10
  }
11
+ /**
12
+ * React hook for applying input masks to form elements.
13
+ * Works with Ant Design and other wrapped components too.
14
+ *
15
+ * @param props - Configuration object
16
+ * @param props.mask - The mask pattern to apply
17
+ * @param props.register - Optional callback that receives the element
18
+ * @param props.options - Optional mask configuration options
19
+ * @returns A ref callback function to attach to the input element
20
+ */
21
+ declare function useMaskInput(props: UseMaskInputOptions): ((input: Input | null) => void);
575
22
 
576
- type Mask = 'datetime' | 'email' | 'numeric' | 'currency' | 'decimal' | 'integer' | 'percentage' | 'url' | 'ip' | 'mac' | 'ssn' | 'brl-currency' | 'cpf' | 'cnpj' | (string & {}) | (string[] & {}) | null;
577
- type Options = Options$1;
578
- type Input = HTMLInputElement | HTMLTextAreaElement | HTMLElement;
579
-
580
- declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseFormRegisterReturn;
23
+ /**
24
+ * Creates a masked version of React Hook Form's register function.
25
+ * Takes react-hook-form's register and adds automatic masking. Like an upgrade.
26
+ *
27
+ * @template T - The form data type
28
+ * @template D - The register options type
29
+ * @param registerFn - The register function from useForm hook
30
+ * @returns A function that registers a field with mask support
31
+ */
32
+ declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseHookFormMaskReturn<T>;
581
33
 
34
+ /**
35
+ * Higher-order function that creates a ref callback for applying input masks.
36
+ * Simple function to apply mask via ref. No hooks, no drama.
37
+ *
38
+ * @param mask - The mask pattern to apply
39
+ * @param options - Optional mask configuration options
40
+ * @returns A ref callback function that applies the mask
41
+ */
582
42
  declare function withMask(mask: Mask, options?: Options): (input: Input | null) => void;
583
43
 
584
- declare function useHookFormMask<T extends FieldValues, D extends RegisterOptions>(registerFn: UseFormRegister<T>): (fieldName: Path<T>, mask: Mask, options?: (D & Options) | Options | D) => UseFormRegisterReturn<Path<T>>;
585
-
586
- interface UseInputMaskOptions {
587
- mask: Mask;
588
- register?: (element: HTMLElement) => void;
589
- options?: Options;
590
- }
591
- declare function useInputMask(props: UseInputMaskOptions): RefObject<HTMLInputElement>;
44
+ /**
45
+ * Enhances a React Hook Form register return object with mask support.
46
+ * Takes an already registered field and adds mask to it.
47
+ * Useful when you registered the field before.
48
+ *
49
+ * @param register - The register return object from React Hook Form
50
+ * @param mask - The mask pattern to apply
51
+ * @param options - Optional mask configuration options
52
+ * @returns A new register return object with mask applied
53
+ */
54
+ declare function withHookFormMask(register: UseFormRegisterReturn, mask: Mask, options?: Options): UseHookFormMaskReturn<FieldValues>;
592
55
 
593
- export { type Mask, type Options, useHookFormMask, useInputMask as useMaskInput, withHookFormMask, withMask };
56
+ export { Input, Mask, Options, useHookFormMask, useMaskInput, withHookFormMask, withMask };