rsuite 5.0.3 → 5.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/MaskedInput/package.json +7 -0
  3. package/README.md +1 -1
  4. package/Toggle/styles/index.less +20 -0
  5. package/Toggle/styles/mixin.less +12 -0
  6. package/cjs/DOMHelper/index.d.ts +1 -1
  7. package/cjs/DatePicker/DatePicker.js +3 -2
  8. package/cjs/DateRangePicker/DateRangePicker.js +3 -2
  9. package/cjs/Dropdown/DropdownItem.js +23 -16
  10. package/cjs/MaskedInput/MaskedInput.d.ts +43 -0
  11. package/cjs/MaskedInput/MaskedInput.js +80 -0
  12. package/cjs/MaskedInput/adjustCaretPosition.d.ts +11 -0
  13. package/cjs/MaskedInput/adjustCaretPosition.js +218 -0
  14. package/cjs/MaskedInput/conformToMask.d.ts +8 -0
  15. package/cjs/MaskedInput/conformToMask.js +247 -0
  16. package/cjs/MaskedInput/createTextMaskInputElement.d.ts +7 -0
  17. package/cjs/MaskedInput/createTextMaskInputElement.js +226 -0
  18. package/cjs/MaskedInput/index.d.ts +3 -0
  19. package/cjs/MaskedInput/index.js +11 -0
  20. package/cjs/MaskedInput/types.d.ts +10 -0
  21. package/cjs/{@types/icons.js → MaskedInput/types.js} +0 -0
  22. package/cjs/MaskedInput/utilities.d.ts +7 -0
  23. package/cjs/MaskedInput/utilities.js +47 -0
  24. package/cjs/Overlay/positionUtils.js +1 -1
  25. package/cjs/Picker/PickerToggle.js +3 -3
  26. package/cjs/Toggle/Toggle.d.ts +2 -0
  27. package/cjs/Toggle/Toggle.js +23 -5
  28. package/cjs/index.d.ts +2 -0
  29. package/cjs/index.js +5 -1
  30. package/cjs/locales/fa_IR.d.ts +105 -0
  31. package/cjs/locales/fa_IR.js +84 -0
  32. package/cjs/locales/index.d.ts +1 -0
  33. package/cjs/locales/index.js +6 -2
  34. package/dist/rsuite-rtl.css +58 -0
  35. package/dist/rsuite-rtl.min.css +1 -1
  36. package/dist/rsuite-rtl.min.css.map +1 -1
  37. package/dist/rsuite.css +58 -0
  38. package/dist/rsuite.js +79 -23
  39. package/dist/rsuite.js.map +1 -1
  40. package/dist/rsuite.min.css +1 -1
  41. package/dist/rsuite.min.css.map +1 -1
  42. package/dist/rsuite.min.js +1 -1
  43. package/dist/rsuite.min.js.map +1 -1
  44. package/esm/DOMHelper/index.d.ts +1 -1
  45. package/esm/DatePicker/DatePicker.js +3 -2
  46. package/esm/DateRangePicker/DateRangePicker.js +3 -2
  47. package/esm/Dropdown/DropdownItem.js +23 -16
  48. package/esm/MaskedInput/MaskedInput.d.ts +43 -0
  49. package/esm/MaskedInput/MaskedInput.js +67 -0
  50. package/esm/MaskedInput/adjustCaretPosition.d.ts +11 -0
  51. package/esm/MaskedInput/adjustCaretPosition.js +213 -0
  52. package/esm/MaskedInput/conformToMask.d.ts +8 -0
  53. package/esm/MaskedInput/conformToMask.js +239 -0
  54. package/esm/MaskedInput/createTextMaskInputElement.d.ts +7 -0
  55. package/esm/MaskedInput/createTextMaskInputElement.js +212 -0
  56. package/esm/MaskedInput/index.d.ts +3 -0
  57. package/esm/MaskedInput/index.js +2 -0
  58. package/esm/MaskedInput/types.d.ts +10 -0
  59. package/esm/{@types/icons.js → MaskedInput/types.js} +0 -0
  60. package/esm/MaskedInput/utilities.d.ts +7 -0
  61. package/esm/MaskedInput/utilities.js +38 -0
  62. package/esm/Overlay/positionUtils.js +1 -1
  63. package/esm/Picker/PickerToggle.js +1 -1
  64. package/esm/Toggle/Toggle.d.ts +2 -0
  65. package/esm/Toggle/Toggle.js +22 -5
  66. package/esm/index.d.ts +2 -0
  67. package/esm/index.js +1 -0
  68. package/esm/locales/fa_IR.d.ts +105 -0
  69. package/esm/locales/fa_IR.js +74 -0
  70. package/esm/locales/index.d.ts +1 -0
  71. package/esm/locales/index.js +2 -1
  72. package/locales/fa_IR/package.json +7 -0
  73. package/package.json +3 -4
  74. package/styles/color-modes/light.less +2 -0
  75. package/cjs/@types/icons.d.ts +0 -1
  76. package/esm/@types/icons.d.ts +0 -1
@@ -0,0 +1,239 @@
1
+ import { convertMaskToPlaceholder, processCaretTraps, defaultPlaceholderChar } from './utilities';
2
+ export function isArray(value) {
3
+ return Array.isArray && Array.isArray(value) || value instanceof Array;
4
+ }
5
+ export default function conformToMask(rawValue, mask, config) {
6
+ if (rawValue === void 0) {
7
+ rawValue = '';
8
+ }
9
+
10
+ if (mask === void 0) {
11
+ mask = [];
12
+ }
13
+
14
+ if (config === void 0) {
15
+ config = {};
16
+ }
17
+
18
+ if (!isArray(mask)) {
19
+ // If someone passes a function as the mask property, we should call the
20
+ // function to get the mask array - Normally this is handled by the
21
+ // `createTextMaskInputElement:update` function - this allows mask functions
22
+ // to be used directly with `conformToMask`
23
+ if (typeof mask === 'function') {
24
+ // call the mask function to get the mask array
25
+ mask = mask(rawValue, config); // mask functions can setup caret traps to have some control over how the caret moves. We need to process
26
+ // the mask for any caret traps. `processCaretTraps` will remove the caret traps from the mask
27
+
28
+ mask = processCaretTraps(mask).maskWithoutCaretTraps;
29
+ } else {
30
+ throw new Error('Text-mask:conformToMask; The mask property must be an array.');
31
+ }
32
+ } // These configurations tell us how to conform the mask
33
+
34
+
35
+ var _config = config,
36
+ _config$guide = _config.guide,
37
+ guide = _config$guide === void 0 ? true : _config$guide,
38
+ _config$previousConfo = _config.previousConformedValue,
39
+ previousConformedValue = _config$previousConfo === void 0 ? '' : _config$previousConfo,
40
+ _config$placeholderCh = _config.placeholderChar,
41
+ placeholderChar = _config$placeholderCh === void 0 ? defaultPlaceholderChar : _config$placeholderCh,
42
+ _config$placeholder = _config.placeholder,
43
+ placeholder = _config$placeholder === void 0 ? convertMaskToPlaceholder(mask, placeholderChar) : _config$placeholder,
44
+ currentCaretPosition = _config.currentCaretPosition,
45
+ keepCharPositions = _config.keepCharPositions; // The configs below indicate that the user wants the algorithm to work in *no guide* mode
46
+
47
+ var suppressGuide = guide === false && previousConformedValue !== undefined; // Calculate lengths once for performance
48
+
49
+ var rawValueLength = rawValue.length;
50
+ var previousConformedValueLength = previousConformedValue.length;
51
+ var placeholderLength = placeholder.length;
52
+ var maskLength = mask.length; // This tells us the number of edited characters and the direction in which they were edited (+/-)
53
+
54
+ var editDistance = rawValueLength - previousConformedValueLength; // In *no guide* mode, we need to know if the user is trying to add a character or not
55
+
56
+ var isAddition = editDistance > 0; // Tells us the index of the first change. For (438) 394-4938 to (38) 394-4938, that would be 1
57
+
58
+ var indexOfFirstChange = currentCaretPosition + (isAddition ? -editDistance : 0); // We're also gonna need the index of last change, which we can derive as follows...
59
+
60
+ var indexOfLastChange = indexOfFirstChange + Math.abs(editDistance); // If `conformToMask` is configured to keep character positions, that is, for mask 111, previous value
61
+ // _2_ and raw value 3_2_, the new conformed value should be 32_, not 3_2 (default behavior). That's in the case of
62
+ // addition. And in the case of deletion, previous value _23, raw value _3, the new conformed string should be
63
+ // __3, not _3_ (default behavior)
64
+ //
65
+ // The next block of logic handles keeping character positions for the case of deletion. (Keeping
66
+ // character positions for the case of addition is further down since it is handled differently.)
67
+ // To do this, we want to compensate for all characters that were deleted
68
+
69
+ if (keepCharPositions === true && !isAddition) {
70
+ // We will be storing the new placeholder characters in this variable.
71
+ var compensatingPlaceholderChars = ''; // For every character that was deleted from a placeholder position, we add a placeholder char
72
+
73
+ for (var i = indexOfFirstChange; i < indexOfLastChange; i++) {
74
+ if (placeholder[i] === placeholderChar) {
75
+ compensatingPlaceholderChars += placeholderChar;
76
+ }
77
+ } // Now we trick our algorithm by modifying the raw value to make it contain additional placeholder characters
78
+ // That way when the we start laying the characters again on the mask, it will keep the non-deleted characters
79
+ // in their positions.
80
+
81
+
82
+ rawValue = rawValue.slice(0, indexOfFirstChange) + compensatingPlaceholderChars + rawValue.slice(indexOfFirstChange, rawValueLength);
83
+ } // Convert `rawValue` string to an array, and mark characters based on whether they are newly added or have
84
+ // existed in the previous conformed value. Identifying new and old characters is needed for `conformToMask`
85
+ // to work if it is configured to keep character positions.
86
+
87
+
88
+ var rawValueArr = rawValue.split('').map(function (char, i) {
89
+ return {
90
+ char: char,
91
+ isNew: i >= indexOfFirstChange && i < indexOfLastChange
92
+ };
93
+ }); // The loop below removes masking characters from user input. For example, for mask
94
+ // `00 (111)`, the placeholder would be `00 (___)`. If user input is `00 (234)`, the loop below
95
+ // would remove all characters but `234` from the `rawValueArr`. The rest of the algorithm
96
+ // then would lay `234` on top of the available placeholder positions in the mask.
97
+
98
+ for (var _i = rawValueLength - 1; _i >= 0; _i--) {
99
+ var char = rawValueArr[_i].char;
100
+
101
+ if (char !== placeholderChar) {
102
+ var shouldOffset = _i >= indexOfFirstChange && previousConformedValueLength === maskLength;
103
+
104
+ if (char === placeholder[shouldOffset ? _i - editDistance : _i]) {
105
+ rawValueArr.splice(_i, 1);
106
+ }
107
+ }
108
+ } // This is the variable that we will be filling with characters as we figure them out
109
+ // in the algorithm below
110
+
111
+
112
+ var conformedValue = '';
113
+ var someCharsRejected = false; // Ok, so first we loop through the placeholder looking for placeholder characters to fill up.
114
+
115
+ placeholderLoop: for (var _i2 = 0; _i2 < placeholderLength; _i2++) {
116
+ var charInPlaceholder = placeholder[_i2]; // We see one. Let's find out what we can put in it.
117
+
118
+ if (charInPlaceholder === placeholderChar) {
119
+ // But before that, do we actually have any user characters that need a place?
120
+ if (rawValueArr.length > 0) {
121
+ // We will keep chipping away at user input until either we run out of characters
122
+ // or we find at least one character that we can map.
123
+ while (rawValueArr.length > 0) {
124
+ // Let's retrieve the first user character in the queue of characters we have left
125
+ var _rawValueArr$shift = rawValueArr.shift(),
126
+ rawValueChar = _rawValueArr$shift.char,
127
+ isNew = _rawValueArr$shift.isNew; // If the character we got from the user input is a placeholder character (which happens
128
+ // regularly because user input could be something like (540) 90_-____, which includes
129
+ // a bunch of `_` which are placeholder characters) and we are not in *no guide* mode,
130
+ // then we map this placeholder character to the current spot in the placeholder
131
+
132
+
133
+ if (rawValueChar === placeholderChar && suppressGuide !== true) {
134
+ conformedValue += placeholderChar; // And we go to find the next placeholder character that needs filling
135
+
136
+ continue placeholderLoop; // Else if, the character we got from the user input is not a placeholder, let's see
137
+ // if the current position in the mask can accept it.
138
+ } else if (mask[_i2].test(rawValueChar)) {
139
+ // we map the character differently based on whether we are keeping character positions or not.
140
+ // If any of the conditions below are met, we simply map the raw value character to the
141
+ // placeholder position.
142
+ if (keepCharPositions !== true || isNew === false || previousConformedValue === '' || guide === false || !isAddition) {
143
+ conformedValue += rawValueChar;
144
+ } else {
145
+ // We enter this block of code if we are trying to keep character positions and none of the conditions
146
+ // above is met. In this case, we need to see if there's an available spot for the raw value character
147
+ // to be mapped to. If we couldn't find a spot, we will discard the character.
148
+ //
149
+ // For example, for mask `1111`, previous conformed value `_2__`, raw value `942_2__`. We can map the
150
+ // `9`, to the first available placeholder position, but then, there are no more spots available for the
151
+ // `4` and `2`. So, we discard them and end up with a conformed value of `92__`.
152
+ var rawValueArrLength = rawValueArr.length;
153
+ var indexOfNextAvailablePlaceholderChar = null; // Let's loop through the remaining raw value characters. We are looking for either a suitable spot, ie,
154
+ // a placeholder character or a non-suitable spot, ie, a non-placeholder character that is not new.
155
+ // If we see a suitable spot first, we store its position and exit the loop. If we see a non-suitable
156
+ // spot first, we exit the loop and our `indexOfNextAvailablePlaceholderChar` will stay as `null`.
157
+
158
+ for (var _i3 = 0; _i3 < rawValueArrLength; _i3++) {
159
+ var charData = rawValueArr[_i3];
160
+
161
+ if (charData.char !== placeholderChar && charData.isNew === false) {
162
+ break;
163
+ }
164
+
165
+ if (charData.char === placeholderChar) {
166
+ indexOfNextAvailablePlaceholderChar = _i3;
167
+ break;
168
+ }
169
+ } // If `indexOfNextAvailablePlaceholderChar` is not `null`, that means the character is not blocked.
170
+ // We can map it. And to keep the character positions, we remove the placeholder character
171
+ // from the remaining characters
172
+
173
+
174
+ if (indexOfNextAvailablePlaceholderChar !== null) {
175
+ conformedValue += rawValueChar;
176
+ rawValueArr.splice(indexOfNextAvailablePlaceholderChar, 1); // If `indexOfNextAvailablePlaceholderChar` is `null`, that means the character is blocked. We have to
177
+ // discard it.
178
+ } else {
179
+ _i2--;
180
+ }
181
+ } // Since we've mapped this placeholder position. We move on to the next one.
182
+
183
+
184
+ continue placeholderLoop;
185
+ } else {
186
+ someCharsRejected = true;
187
+ }
188
+ }
189
+ } // We reach this point when we've mapped all the user input characters to placeholder
190
+ // positions in the mask. In *guide* mode, we append the left over characters in the
191
+ // placeholder to the `conformedString`, but in *no guide* mode, we don't wanna do that.
192
+ //
193
+ // That is, for mask `(111)` and user input `2`, we want to return `(2`, not `(2__)`.
194
+
195
+
196
+ if (suppressGuide === false) {
197
+ conformedValue += placeholder.substr(_i2, placeholderLength);
198
+ } // And we break
199
+
200
+
201
+ break; // Else, the charInPlaceholder is not a placeholderChar. That is, we cannot fill it
202
+ // with user input. So we just map it to the final output
203
+ } else {
204
+ conformedValue += charInPlaceholder;
205
+ }
206
+ } // The following logic is needed to deal with the case of deletion in *no guide* mode.
207
+ //
208
+ // Consider the silly mask `(111) /// 1`. What if user tries to delete the last placeholder
209
+ // position? Something like `(589) /// `. We want to conform that to `(589`. Not `(589) /// `.
210
+ // That's why the logic below finds the last filled placeholder character, and removes everything
211
+ // from that point on.
212
+
213
+
214
+ if (suppressGuide && isAddition === false) {
215
+ var indexOfLastFilledPlaceholderChar = null; // Find the last filled placeholder position and substring from there
216
+
217
+ for (var _i4 = 0; _i4 < conformedValue.length; _i4++) {
218
+ if (placeholder[_i4] === placeholderChar) {
219
+ indexOfLastFilledPlaceholderChar = _i4;
220
+ }
221
+ }
222
+
223
+ if (indexOfLastFilledPlaceholderChar !== null) {
224
+ // We substring from the beginning until the position after the last filled placeholder char.
225
+ conformedValue = conformedValue.substr(0, indexOfLastFilledPlaceholderChar + 1);
226
+ } else {
227
+ // If we couldn't find `indexOfLastFilledPlaceholderChar` that means the user deleted
228
+ // the first character in the mask. So we return an empty string.
229
+ conformedValue = '';
230
+ }
231
+ }
232
+
233
+ return {
234
+ conformedValue: conformedValue,
235
+ meta: {
236
+ someCharsRejected: someCharsRejected
237
+ }
238
+ };
239
+ }
@@ -0,0 +1,7 @@
1
+ export default function createTextMaskInputElement(config: any): {
2
+ state: {
3
+ previousConformedValue: any;
4
+ previousPlaceholder: any;
5
+ };
6
+ update(rawValue: any, { inputElement, mask: providedMask, guide, pipe, placeholderChar, keepCharPositions, showMask }?: any): void;
7
+ };
@@ -0,0 +1,212 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import isString from 'lodash/isString';
3
+ import isNumber from 'lodash/isNumber';
4
+ import adjustCaretPosition from './adjustCaretPosition';
5
+ import conformToMask from './conformToMask';
6
+ import { convertMaskToPlaceholder, processCaretTraps, defaultPlaceholderChar } from './utilities';
7
+ var emptyString = '';
8
+ var strNone = 'none';
9
+ var strObject = 'object';
10
+ var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
11
+ var defer = typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame : setTimeout;
12
+ export default function createTextMaskInputElement(config) {
13
+ // Anything that we will need to keep between `update` calls, we will store in this `state` object.
14
+ var state = {
15
+ previousConformedValue: undefined,
16
+ previousPlaceholder: undefined
17
+ };
18
+ return {
19
+ state: state,
20
+ // `update` is called by framework components whenever they want to update the `value` of the input element.
21
+ // The caller can send a `rawValue` to be conformed and set on the input element. However, the default use-case
22
+ // is for this to be read from the `inputElement` directly.
23
+ update: function update(rawValue, _temp) {
24
+ var _pipeResults, _pipeResults2;
25
+
26
+ var _ref = _temp === void 0 ? config : _temp,
27
+ inputElement = _ref.inputElement,
28
+ providedMask = _ref.mask,
29
+ guide = _ref.guide,
30
+ pipe = _ref.pipe,
31
+ _ref$placeholderChar = _ref.placeholderChar,
32
+ placeholderChar = _ref$placeholderChar === void 0 ? defaultPlaceholderChar : _ref$placeholderChar,
33
+ _ref$keepCharPosition = _ref.keepCharPositions,
34
+ keepCharPositions = _ref$keepCharPosition === void 0 ? false : _ref$keepCharPosition,
35
+ _ref$showMask = _ref.showMask,
36
+ showMask = _ref$showMask === void 0 ? false : _ref$showMask;
37
+
38
+ // if `rawValue` is `undefined`, read from the `inputElement`
39
+ if (typeof rawValue === 'undefined') {
40
+ rawValue = inputElement.value;
41
+ } // If `rawValue` equals `state.previousConformedValue`, we don't need to change anything. So, we return.
42
+ // This check is here to handle controlled framework components that repeat the `update` call on every render.
43
+
44
+
45
+ if (rawValue === state.previousConformedValue) {
46
+ return;
47
+ } // Text Mask accepts masks that are a combination of a `mask` and a `pipe` that work together. If such a `mask` is
48
+ // passed, we destructure it below, so the rest of the code can work normally as if a separate `mask` and a `pipe`
49
+ // were passed.
50
+
51
+
52
+ if (typeof providedMask === strObject && providedMask.pipe !== undefined && providedMask.mask !== undefined) {
53
+ pipe = providedMask.pipe;
54
+ providedMask = providedMask.mask;
55
+ } // The `placeholder` is an essential piece of how Text Mask works. For a mask like `(111)`, the placeholder would
56
+ // be `(___)` if the `placeholderChar` is set to `_`.
57
+
58
+
59
+ var placeholder; // We don't know what the mask would be yet. If it is an array, we take it as is, but if it's a function, we will
60
+ // have to call that function to get the mask array.
61
+
62
+ var mask; // If the provided mask is an array, we can call `convertMaskToPlaceholder` here once and we'll always have the
63
+ // correct `placeholder`.
64
+
65
+ if (providedMask instanceof Array) {
66
+ placeholder = convertMaskToPlaceholder(providedMask, placeholderChar);
67
+ } // In framework components that support reactivity, it's possible to turn off masking by passing
68
+ // `false` for `mask` after initialization. See https://github.com/text-mask/text-mask/pull/359
69
+
70
+
71
+ if (providedMask === false) {
72
+ return;
73
+ } // We check the provided `rawValue` before moving further.
74
+ // If it's something we can't work with `getSafeRawValue` will throw.
75
+
76
+
77
+ var safeRawValue = getSafeRawValue(rawValue); // `selectionEnd` indicates to us where the caret position is after the user has typed into the input
78
+
79
+ var currentCaretPosition = inputElement.selectionEnd; // We need to know what the `previousConformedValue` and `previousPlaceholder` is from the previous `update` call
80
+
81
+ var previousConformedValue = state.previousConformedValue,
82
+ previousPlaceholder = state.previousPlaceholder;
83
+ var caretTrapIndexes; // If the `providedMask` is a function. We need to call it at every `update` to get the `mask` array.
84
+ // Then we also need to get the `placeholder`
85
+
86
+ if (typeof providedMask === 'function') {
87
+ mask = providedMask(safeRawValue, {
88
+ currentCaretPosition: currentCaretPosition,
89
+ previousConformedValue: previousConformedValue,
90
+ placeholderChar: placeholderChar
91
+ }); // disable masking if `mask` is `false`
92
+
93
+ if (mask === false) {
94
+ return;
95
+ } // mask functions can setup caret traps to have some control over how the caret moves. We need to process
96
+ // the mask for any caret traps. `processCaretTraps` will remove the caret traps from the mask and return
97
+ // the indexes of the caret traps.
98
+
99
+
100
+ var _processCaretTraps = processCaretTraps(mask),
101
+ maskWithoutCaretTraps = _processCaretTraps.maskWithoutCaretTraps,
102
+ indexes = _processCaretTraps.indexes;
103
+
104
+ mask = maskWithoutCaretTraps; // The processed mask is what we're interested in
105
+
106
+ caretTrapIndexes = indexes; // And we need to store these indexes because they're needed by `adjustCaretPosition`
107
+
108
+ placeholder = convertMaskToPlaceholder(mask, placeholderChar); // If the `providedMask` is not a function, we just use it as-is.
109
+ } else {
110
+ mask = providedMask;
111
+ } // The following object will be passed to `conformToMask` to determine how the `rawValue` will be conformed
112
+
113
+
114
+ var conformToMaskConfig = {
115
+ previousConformedValue: previousConformedValue,
116
+ guide: guide,
117
+ placeholderChar: placeholderChar,
118
+ pipe: pipe,
119
+ placeholder: placeholder,
120
+ currentCaretPosition: currentCaretPosition,
121
+ keepCharPositions: keepCharPositions
122
+ }; // `conformToMask` returns `conformedValue` as part of an object for future API flexibility
123
+
124
+ var _conformToMask = conformToMask(safeRawValue, mask, conformToMaskConfig),
125
+ conformedValue = _conformToMask.conformedValue; // The following few lines are to support the `pipe` feature.
126
+
127
+
128
+ var piped = typeof pipe === 'function';
129
+ var pipeResults = {}; // If `pipe` is a function, we call it.
130
+
131
+ if (piped) {
132
+ // `pipe` receives the `conformedValue` and the configurations with which `conformToMask` was called.
133
+ pipeResults = pipe(conformedValue, _extends({
134
+ rawValue: safeRawValue
135
+ }, conformToMaskConfig)); // `pipeResults` should be an object. But as a convenience, we allow the pipe author to just return `false` to
136
+ // indicate rejection. Or return just a string when there are no piped characters.
137
+ // If the `pipe` returns `false` or a string, the block below turns it into an object that the rest
138
+ // of the code can work with.
139
+
140
+ if (pipeResults === false) {
141
+ // If the `pipe` rejects `conformedValue`, we use the `previousConformedValue`, and set `rejected` to `true`.
142
+ pipeResults = {
143
+ value: previousConformedValue,
144
+ rejected: true
145
+ };
146
+ } else if (isString(pipeResults)) {
147
+ pipeResults = {
148
+ value: pipeResults
149
+ };
150
+ }
151
+ } // Before we proceed, we need to know which conformed value to use, the one returned by the pipe or the one
152
+ // returned by `conformToMask`.
153
+
154
+
155
+ var finalConformedValue = piped ? (_pipeResults = pipeResults) === null || _pipeResults === void 0 ? void 0 : _pipeResults.value : conformedValue; // After determining the conformed value, we will need to know where to set
156
+ // the caret position. `adjustCaretPosition` will tell us.
157
+
158
+ var adjustedCaretPosition = adjustCaretPosition({
159
+ previousConformedValue: previousConformedValue,
160
+ previousPlaceholder: previousPlaceholder,
161
+ conformedValue: finalConformedValue,
162
+ placeholder: placeholder,
163
+ rawValue: safeRawValue,
164
+ currentCaretPosition: currentCaretPosition,
165
+ placeholderChar: placeholderChar,
166
+ indexesOfPipedChars: (_pipeResults2 = pipeResults) === null || _pipeResults2 === void 0 ? void 0 : _pipeResults2.indexesOfPipedChars,
167
+ caretTrapIndexes: caretTrapIndexes
168
+ }); // Text Mask sets the input value to an empty string when the condition below is set. It provides a better UX.
169
+
170
+ var inputValueShouldBeEmpty = finalConformedValue === placeholder && adjustedCaretPosition === 0;
171
+ var emptyValue = showMask ? placeholder : emptyString;
172
+ var inputElementValue = inputValueShouldBeEmpty ? emptyValue : finalConformedValue;
173
+ state.previousConformedValue = inputElementValue; // store value for access for next time
174
+
175
+ state.previousPlaceholder = placeholder; // In some cases, this `update` method will be repeatedly called with a raw value that has already been conformed
176
+ // and set to `inputElement.value`. The below check guards against needlessly readjusting the input state.
177
+ // See https://github.com/text-mask/text-mask/issues/231
178
+
179
+ if (inputElement.value === inputElementValue) {
180
+ return;
181
+ }
182
+
183
+ inputElement.value = inputElementValue; // set the input value
184
+
185
+ safeSetSelection(inputElement, adjustedCaretPosition); // adjust caret position
186
+ }
187
+ };
188
+ }
189
+
190
+ function safeSetSelection(element, selectionPosition) {
191
+ if (document.activeElement === element) {
192
+ if (isAndroid) {
193
+ defer(function () {
194
+ return element.setSelectionRange(selectionPosition, selectionPosition, strNone);
195
+ }, 0);
196
+ } else {
197
+ element.setSelectionRange(selectionPosition, selectionPosition, strNone);
198
+ }
199
+ }
200
+ }
201
+
202
+ function getSafeRawValue(inputValue) {
203
+ if (isString(inputValue)) {
204
+ return inputValue;
205
+ } else if (isNumber(inputValue)) {
206
+ return String(inputValue);
207
+ } else if (inputValue === undefined || inputValue === null) {
208
+ return emptyString;
209
+ } else {
210
+ throw new Error("The 'value' provided to Text Mask needs to be a string or a number. The value received was:\n\n " + JSON.stringify(inputValue));
211
+ }
212
+ }
@@ -0,0 +1,3 @@
1
+ import MaskedInput from './MaskedInput';
2
+ export type { MaskedInputProps } from './MaskedInput';
3
+ export default MaskedInput;
@@ -0,0 +1,2 @@
1
+ import MaskedInput from './MaskedInput';
2
+ export default MaskedInput;
@@ -0,0 +1,10 @@
1
+ export interface ConfigType {
2
+ guide?: boolean;
3
+ previousConformedValue?: string;
4
+ placeholderChar?: string;
5
+ placeholder?: string;
6
+ currentCaretPosition?: number;
7
+ keepCharPositions?: boolean;
8
+ }
9
+ export declare type MaskType = string | (string | RegExp)[];
10
+ export declare type MaskFunctionType = (rawValue: string, config: ConfigType) => MaskType;
File without changes
@@ -0,0 +1,7 @@
1
+ import { MaskType, MaskFunctionType } from './types';
2
+ export declare const defaultPlaceholderChar = "_";
3
+ export declare function convertMaskToPlaceholder(mask?: MaskType | MaskFunctionType, placeholderChar?: string): string;
4
+ export declare function processCaretTraps(mask: any): {
5
+ maskWithoutCaretTraps: any;
6
+ indexes: any[];
7
+ };
@@ -0,0 +1,38 @@
1
+ var emptyArray = [];
2
+ var strCaretTrap = '[]';
3
+ export var defaultPlaceholderChar = '_';
4
+ export function convertMaskToPlaceholder(mask, placeholderChar) {
5
+ if (mask === void 0) {
6
+ mask = emptyArray;
7
+ }
8
+
9
+ if (placeholderChar === void 0) {
10
+ placeholderChar = defaultPlaceholderChar;
11
+ }
12
+
13
+ if (!Array.isArray(mask)) {
14
+ throw new Error('Text-mask:convertMaskToPlaceholder; The mask property must be an array.');
15
+ }
16
+
17
+ if (mask.indexOf(placeholderChar) !== -1) {
18
+ throw new Error('Placeholder character must not be used as part of the mask. Please specify a character ' + 'that is not present in your mask as your placeholder character.\n\n' + ("The placeholder character that was received is: " + JSON.stringify(placeholderChar) + "\n\n") + ("The mask that was received is: " + JSON.stringify(mask)));
19
+ }
20
+
21
+ return mask.map(function (char) {
22
+ return char instanceof RegExp ? placeholderChar : char;
23
+ }).join('');
24
+ }
25
+ export function processCaretTraps(mask) {
26
+ var indexes = [];
27
+ var indexOfCaretTrap;
28
+
29
+ while (indexOfCaretTrap = mask.indexOf(strCaretTrap), indexOfCaretTrap !== -1) {
30
+ indexes.push(indexOfCaretTrap);
31
+ mask.splice(indexOfCaretTrap, 1);
32
+ }
33
+
34
+ return {
35
+ maskWithoutCaretTraps: mask,
36
+ indexes: indexes
37
+ };
38
+ }
@@ -123,7 +123,7 @@ export default (function (props) {
123
123
 
124
124
  return {
125
125
  getPosition: function getPosition(target, container) {
126
- var offset = container.tagName === 'BODY' ? getOffset(target) : _getPosition(target, container);
126
+ var offset = container.tagName === 'BODY' ? getOffset(target) : _getPosition(target, container, false);
127
127
  return offset;
128
128
  },
129
129
  calcAutoPlacement: function calcAutoPlacement(targetOffset, container, overlay) {
@@ -7,12 +7,12 @@ var _templateObject, _templateObject2;
7
7
  import React, { useState, useCallback, useEffect, useRef } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import debounce from 'lodash/debounce';
10
- import MaskedInput from 'react-text-mask';
11
10
  import ToggleButton from './ToggleButton';
12
11
  import CloseButton from '../CloseButton';
13
12
  import { useClassNames, KEY_VALUES, mergeRefs } from '../utils';
14
13
  import Plaintext from '../Plaintext';
15
14
  import useToggleCaret from '../utils/useToggleCaret';
15
+ import MaskedInput from '../MaskedInput';
16
16
  var defaultInputMask = [];
17
17
  var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
18
18
  var activeProp = props.active,
@@ -8,6 +8,8 @@ export interface ToggleProps extends WithAsProps {
8
8
  plaintext?: boolean;
9
9
  /** Make the control readonly */
10
10
  readOnly?: boolean;
11
+ /** Whether the checked state is being updated */
12
+ loading?: boolean;
11
13
  /** Checked(Controlled) */
12
14
  checked?: boolean;
13
15
  /** Default checked */
@@ -4,6 +4,7 @@ import React, { useCallback } from 'react';
4
4
  import PropTypes from 'prop-types';
5
5
  import { useClassNames, useControlled, useCustom } from '../utils';
6
6
  import Plaintext from '../Plaintext';
7
+ import Loader from '../Loader';
7
8
 
8
9
  /**
9
10
  * fixme: Should contain an input[type=checkbox]
@@ -13,6 +14,8 @@ var Toggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
13
14
  Component = _props$as === void 0 ? 'span' : _props$as,
14
15
  disabled = props.disabled,
15
16
  readOnly = props.readOnly,
17
+ _props$loading = props.loading,
18
+ loading = _props$loading === void 0 ? false : _props$loading,
16
19
  plaintext = props.plaintext,
17
20
  className = props.className,
18
21
  checkedChildren = props.checkedChildren,
@@ -24,7 +27,7 @@ var Toggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
24
27
  size = props.size,
25
28
  localeProp = props.locale,
26
29
  onChange = props.onChange,
27
- rest = _objectWithoutPropertiesLoose(props, ["as", "disabled", "readOnly", "plaintext", "className", "checkedChildren", "unCheckedChildren", "classPrefix", "checked", "defaultChecked", "size", "locale", "onChange"]);
30
+ rest = _objectWithoutPropertiesLoose(props, ["as", "disabled", "readOnly", "loading", "plaintext", "className", "checkedChildren", "unCheckedChildren", "classPrefix", "checked", "defaultChecked", "size", "locale", "onChange"]);
28
31
 
29
32
  var _useControlled = useControlled(checkedProp, defaultChecked),
30
33
  checked = _useControlled[0],
@@ -40,7 +43,8 @@ var Toggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
40
43
 
41
44
  var classes = merge(className, withClassPrefix(size, {
42
45
  checked: checked,
43
- disabled: disabled
46
+ disabled: disabled,
47
+ loading: loading
44
48
  }));
45
49
  var inner = checked ? checkedChildren : unCheckedChildren;
46
50
  var label = checked ? locale.on : locale.off;
@@ -52,6 +56,14 @@ var Toggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
52
56
  setChecked(!checked);
53
57
  onChange === null || onChange === void 0 ? void 0 : onChange(!checked, event);
54
58
  }, [checked, disabled, onChange, readOnly, setChecked]);
59
+ var handleKeyDown = useCallback(function (event) {
60
+ if (event.key !== ' ') {
61
+ return;
62
+ }
63
+
64
+ handleChange(event);
65
+ event.preventDefault();
66
+ }, [handleChange]);
55
67
 
56
68
  if (plaintext) {
57
69
  return /*#__PURE__*/React.createElement(Plaintext, null, inner || label);
@@ -62,14 +74,18 @@ var Toggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
62
74
  "aria-checked": checked,
63
75
  "aria-disabled": disabled,
64
76
  "aria-label": typeof inner === 'string' ? inner : label,
65
- tabIndex: -1
77
+ "aria-busy": loading || undefined,
78
+ tabIndex: 0
66
79
  }, rest, {
67
80
  ref: ref,
68
81
  className: classes,
69
- onClick: handleChange
82
+ onClick: handleChange,
83
+ onKeyDown: handleKeyDown
70
84
  }), /*#__PURE__*/React.createElement("span", {
71
85
  className: prefix('inner')
72
- }, inner));
86
+ }, inner), loading && /*#__PURE__*/React.createElement(Loader, {
87
+ className: prefix('loader')
88
+ }));
73
89
  });
74
90
  Toggle.displayName = 'Toggle';
75
91
  Toggle.propTypes = {
@@ -78,6 +94,7 @@ Toggle.propTypes = {
78
94
  defaultChecked: PropTypes.bool,
79
95
  checkedChildren: PropTypes.node,
80
96
  unCheckedChildren: PropTypes.node,
97
+ loading: PropTypes.bool,
81
98
  classPrefix: PropTypes.string,
82
99
  className: PropTypes.string,
83
100
  onChange: PropTypes.func
package/esm/index.d.ts CHANGED
@@ -54,6 +54,8 @@ export { default as Form } from './Form';
54
54
  export type { FormProps, FormGroupProps, FormErrorMessageProps, FormControlLabelProps, FormHelpTextProps, FormControlProps } from './Form';
55
55
  export { default as Input } from './Input';
56
56
  export type { InputProps } from './Input';
57
+ export { default as MaskedInput } from './MaskedInput';
58
+ export type { MaskedInputProps } from './MaskedInput';
57
59
  export { default as InputNumber } from './InputNumber';
58
60
  export type { InputNumberProps } from './InputNumber';
59
61
  export { default as InputGroup } from './InputGroup';
package/esm/index.js CHANGED
@@ -29,6 +29,7 @@ export { default as Steps } from './Steps';
29
29
  export { default as Toggle } from './Toggle';
30
30
  export { default as Form } from './Form';
31
31
  export { default as Input } from './Input';
32
+ export { default as MaskedInput } from './MaskedInput';
32
33
  export { default as InputNumber } from './InputNumber';
33
34
  export { default as InputGroup } from './InputGroup';
34
35
  export { default as Checkbox } from './Checkbox';