rsuite 5.0.1 → 5.2.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/Button/styles/index.less +1 -1
- package/CHANGELOG.md +50 -0
- package/MaskedInput/package.json +7 -0
- package/Navbar/styles/index.less +8 -0
- package/Picker/styles/index.less +1 -1
- package/Picker/styles/mixin.less +1 -1
- package/README.md +1 -2
- package/Sidenav/styles/index.less +13 -16
- package/Slider/styles/index.less +20 -14
- package/Toggle/styles/index.less +53 -12
- package/Toggle/styles/mixin.less +25 -11
- package/Uploader/styles/index.less +10 -1
- package/cjs/@types/common.d.ts +8 -2
- package/cjs/Affix/Affix.js +3 -3
- package/cjs/Animation/Collapse.js +9 -7
- package/cjs/Animation/Transition.js +4 -2
- package/cjs/AutoComplete/AutoComplete.d.ts +2 -2
- package/cjs/AutoComplete/AutoComplete.js +7 -4
- package/cjs/Calendar/TimeDropdown.js +5 -3
- package/cjs/Cascader/Cascader.d.ts +1 -1
- package/cjs/Cascader/Cascader.js +3 -1
- package/cjs/Cascader/DropdownMenu.js +6 -5
- package/cjs/CheckTreePicker/CheckTreeNode.d.ts +1 -1
- package/cjs/CheckTreePicker/CheckTreePicker.d.ts +1 -1
- package/cjs/Checkbox/Checkbox.d.ts +3 -3
- package/cjs/CheckboxGroup/CheckboxGroupContext.d.ts +1 -1
- package/cjs/DOMHelper/index.d.ts +13 -28
- package/cjs/DOMHelper/index.js +4 -3
- package/cjs/DOMHelper/isElement.d.ts +2 -0
- package/cjs/DOMHelper/isElement.js +11 -0
- package/cjs/DatePicker/DatePicker.d.ts +3 -3
- package/cjs/DatePicker/DatePicker.js +6 -3
- package/cjs/DateRangePicker/Calendar.d.ts +1 -1
- package/cjs/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/cjs/DateRangePicker/DateRangePicker.js +15 -7
- package/cjs/Disclosure/Disclosure.d.ts +1 -1
- package/cjs/Disclosure/DisclosureContext.d.ts +1 -1
- package/cjs/Dropdown/DropdownItem.d.ts +1 -1
- package/cjs/Dropdown/DropdownItem.js +23 -16
- package/cjs/Dropdown/DropdownMenu.d.ts +2 -2
- package/cjs/Form/Form.d.ts +1 -1
- package/cjs/FormControl/FormControl.d.ts +9 -3
- package/cjs/FormControl/FormControl.js +6 -2
- package/cjs/Input/Input.d.ts +2 -1
- package/cjs/InputNumber/InputNumber.js +2 -2
- package/cjs/InputPicker/InputPicker.js +4 -3
- package/cjs/List/helper/useSortHelper.js +11 -6
- package/cjs/MaskedInput/MaskedInput.d.ts +43 -0
- package/cjs/MaskedInput/MaskedInput.js +80 -0
- package/cjs/MaskedInput/adjustCaretPosition.d.ts +11 -0
- package/cjs/MaskedInput/adjustCaretPosition.js +218 -0
- package/cjs/MaskedInput/conformToMask.d.ts +8 -0
- package/cjs/MaskedInput/conformToMask.js +247 -0
- package/cjs/MaskedInput/createTextMaskInputElement.d.ts +7 -0
- package/cjs/MaskedInput/createTextMaskInputElement.js +226 -0
- package/cjs/MaskedInput/index.d.ts +3 -0
- package/cjs/MaskedInput/index.js +11 -0
- package/cjs/MaskedInput/types.d.ts +10 -0
- package/cjs/{@types/icons.js → MaskedInput/types.js} +0 -0
- package/cjs/MaskedInput/utilities.d.ts +7 -0
- package/cjs/MaskedInput/utilities.js +47 -0
- package/cjs/Menu/MenuItem.d.ts +1 -1
- package/cjs/Menu/Menubar.d.ts +1 -1
- package/cjs/Message/Message.js +13 -11
- package/cjs/Modal/Modal.js +5 -3
- package/cjs/Modal/utils.js +7 -5
- package/cjs/MultiCascader/MultiCascader.js +3 -1
- package/cjs/Notification/Notification.js +6 -3
- package/cjs/Overlay/Modal.js +14 -11
- package/cjs/Overlay/ModalManager.js +19 -7
- package/cjs/Overlay/OverlayTrigger.js +2 -2
- package/cjs/Overlay/Position.js +20 -13
- package/cjs/Overlay/positionUtils.js +16 -8
- package/cjs/Panel/Panel.d.ts +1 -1
- package/cjs/Picker/DropdownMenu.js +10 -6
- package/cjs/Picker/DropdownMenuCheckItem.d.ts +3 -3
- package/cjs/Picker/PickerOverlay.js +5 -3
- package/cjs/Picker/PickerToggle.d.ts +6 -0
- package/cjs/Picker/PickerToggle.js +17 -8
- package/cjs/Picker/SearchBar.d.ts +1 -1
- package/cjs/Picker/utils.d.ts +2 -2
- package/cjs/Picker/utils.js +1 -1
- package/cjs/Radio/Radio.d.ts +1 -1
- package/cjs/RadioGroup/RadioGroup.d.ts +1 -1
- package/cjs/RangeSlider/RangeSlider.js +9 -5
- package/cjs/Rate/Character.js +2 -2
- package/cjs/Ripple/Ripple.js +6 -7
- package/cjs/SelectPicker/SelectPicker.js +2 -1
- package/cjs/Sidenav/SidenavDropdownItem.d.ts +1 -1
- package/cjs/Sidenav/SidenavDropdownMenu.d.ts +1 -1
- package/cjs/Slider/Graduated.js +1 -1
- package/cjs/Slider/Handle.js +10 -5
- package/cjs/Slider/ProgressBar.js +1 -1
- package/cjs/Slider/Slider.js +9 -5
- package/cjs/Table/Table.d.ts +7 -7
- package/cjs/TagPicker/index.d.ts +1 -1
- package/cjs/Toggle/Toggle.d.ts +5 -6
- package/cjs/Toggle/Toggle.js +42 -19
- package/cjs/Tree/Tree.d.ts +3 -3
- package/cjs/TreePicker/TreeNode.d.ts +1 -1
- package/cjs/TreePicker/TreeNode.js +2 -2
- package/cjs/TreePicker/TreePicker.d.ts +1 -1
- package/cjs/TreePicker/TreePicker.js +2 -1
- package/cjs/Uploader/UploadFileItem.d.ts +1 -0
- package/cjs/Uploader/UploadFileItem.js +30 -17
- package/cjs/Uploader/Uploader.d.ts +6 -4
- package/cjs/Uploader/Uploader.js +4 -1
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -1
- package/cjs/locales/fa_IR.d.ts +105 -0
- package/cjs/locales/fa_IR.js +84 -0
- package/cjs/locales/index.d.ts +1 -0
- package/cjs/locales/index.js +6 -2
- package/cjs/utils/BrowserDetection.js +1 -1
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.js +7 -2
- package/cjs/utils/previewFile.d.ts +1 -0
- package/cjs/utils/previewFile.js +11 -0
- package/cjs/utils/scrollTopAnimation.js +5 -5
- package/cjs/utils/treeUtils.d.ts +2 -2
- package/cjs/utils/useEventListener.js +4 -2
- package/cjs/utils/useIsMounted.d.ts +2 -0
- package/cjs/utils/useIsMounted.js +22 -0
- package/cjs/utils/usePortal.js +2 -2
- package/cjs/utils/useRootClose.js +10 -10
- package/dist/rsuite-rtl.css +225 -124
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +225 -124
- package/dist/rsuite.js +773 -508
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/@types/common.d.ts +8 -2
- package/esm/Affix/Affix.js +1 -1
- package/esm/Animation/Collapse.js +2 -1
- package/esm/Animation/Transition.js +3 -2
- package/esm/AutoComplete/AutoComplete.d.ts +2 -2
- package/esm/AutoComplete/AutoComplete.js +8 -5
- package/esm/Calendar/TimeDropdown.js +2 -1
- package/esm/Cascader/Cascader.d.ts +1 -1
- package/esm/Cascader/Cascader.js +3 -1
- package/esm/Cascader/DropdownMenu.js +4 -3
- package/esm/CheckTreePicker/CheckTreeNode.d.ts +1 -1
- package/esm/CheckTreePicker/CheckTreePicker.d.ts +1 -1
- package/esm/Checkbox/Checkbox.d.ts +3 -3
- package/esm/CheckboxGroup/CheckboxGroupContext.d.ts +1 -1
- package/esm/DOMHelper/index.d.ts +13 -28
- package/esm/DOMHelper/index.js +2 -3
- package/esm/DOMHelper/isElement.d.ts +2 -0
- package/esm/DOMHelper/isElement.js +5 -0
- package/esm/DatePicker/DatePicker.d.ts +3 -3
- package/esm/DatePicker/DatePicker.js +6 -3
- package/esm/DateRangePicker/Calendar.d.ts +1 -1
- package/esm/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/esm/DateRangePicker/DateRangePicker.js +15 -7
- package/esm/Disclosure/Disclosure.d.ts +1 -1
- package/esm/Disclosure/DisclosureContext.d.ts +1 -1
- package/esm/Dropdown/DropdownItem.d.ts +1 -1
- package/esm/Dropdown/DropdownItem.js +23 -16
- package/esm/Dropdown/DropdownMenu.d.ts +2 -2
- package/esm/Form/Form.d.ts +1 -1
- package/esm/FormControl/FormControl.d.ts +9 -3
- package/esm/FormControl/FormControl.js +6 -2
- package/esm/Input/Input.d.ts +2 -1
- package/esm/InputNumber/InputNumber.js +2 -2
- package/esm/InputPicker/InputPicker.js +3 -2
- package/esm/List/helper/useSortHelper.js +8 -4
- package/esm/MaskedInput/MaskedInput.d.ts +43 -0
- package/esm/MaskedInput/MaskedInput.js +67 -0
- package/esm/MaskedInput/adjustCaretPosition.d.ts +11 -0
- package/esm/MaskedInput/adjustCaretPosition.js +213 -0
- package/esm/MaskedInput/conformToMask.d.ts +8 -0
- package/esm/MaskedInput/conformToMask.js +239 -0
- package/esm/MaskedInput/createTextMaskInputElement.d.ts +7 -0
- package/esm/MaskedInput/createTextMaskInputElement.js +212 -0
- package/esm/MaskedInput/index.d.ts +3 -0
- package/esm/MaskedInput/index.js +2 -0
- package/esm/MaskedInput/types.d.ts +10 -0
- package/esm/{@types/icons.js → MaskedInput/types.js} +0 -0
- package/esm/MaskedInput/utilities.d.ts +7 -0
- package/esm/MaskedInput/utilities.js +38 -0
- package/esm/Menu/MenuItem.d.ts +1 -1
- package/esm/Menu/Menubar.d.ts +1 -1
- package/esm/Message/Message.js +15 -13
- package/esm/Modal/Modal.js +3 -2
- package/esm/Modal/utils.js +6 -5
- package/esm/MultiCascader/MultiCascader.js +3 -1
- package/esm/Notification/Notification.js +7 -4
- package/esm/Overlay/Modal.js +11 -8
- package/esm/Overlay/ModalManager.js +6 -1
- package/esm/Overlay/OverlayTrigger.js +1 -1
- package/esm/Overlay/Position.js +14 -8
- package/esm/Overlay/positionUtils.js +6 -2
- package/esm/Panel/Panel.d.ts +1 -1
- package/esm/Picker/DropdownMenu.js +3 -1
- package/esm/Picker/DropdownMenuCheckItem.d.ts +3 -3
- package/esm/Picker/PickerOverlay.js +2 -1
- package/esm/Picker/PickerToggle.d.ts +6 -0
- package/esm/Picker/PickerToggle.js +14 -6
- package/esm/Picker/SearchBar.d.ts +1 -1
- package/esm/Picker/utils.d.ts +2 -2
- package/esm/Picker/utils.js +1 -1
- package/esm/Radio/Radio.d.ts +1 -1
- package/esm/RadioGroup/RadioGroup.d.ts +1 -1
- package/esm/RangeSlider/RangeSlider.js +4 -2
- package/esm/Rate/Character.js +2 -2
- package/esm/Ripple/Ripple.js +4 -3
- package/esm/SelectPicker/SelectPicker.js +2 -1
- package/esm/Sidenav/SidenavDropdownItem.d.ts +1 -1
- package/esm/Sidenav/SidenavDropdownMenu.d.ts +1 -1
- package/esm/Slider/Graduated.js +1 -1
- package/esm/Slider/Handle.js +5 -2
- package/esm/Slider/ProgressBar.js +1 -1
- package/esm/Slider/Slider.js +4 -2
- package/esm/Table/Table.d.ts +7 -7
- package/esm/TagPicker/index.d.ts +1 -1
- package/esm/Toggle/Toggle.d.ts +5 -6
- package/esm/Toggle/Toggle.js +43 -21
- package/esm/Tree/Tree.d.ts +3 -3
- package/esm/TreePicker/TreeNode.d.ts +1 -1
- package/esm/TreePicker/TreeNode.js +1 -1
- package/esm/TreePicker/TreePicker.d.ts +1 -1
- package/esm/TreePicker/TreePicker.js +2 -1
- package/esm/Uploader/UploadFileItem.d.ts +1 -0
- package/esm/Uploader/UploadFileItem.js +30 -17
- package/esm/Uploader/Uploader.d.ts +6 -4
- package/esm/Uploader/Uploader.js +4 -1
- package/esm/index.d.ts +2 -0
- package/esm/index.js +1 -0
- package/esm/locales/fa_IR.d.ts +105 -0
- package/esm/locales/fa_IR.js +74 -0
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.js +2 -1
- package/esm/utils/BrowserDetection.js +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +2 -1
- package/esm/utils/previewFile.d.ts +1 -0
- package/esm/utils/previewFile.js +9 -0
- package/esm/utils/scrollTopAnimation.js +2 -2
- package/esm/utils/treeUtils.d.ts +2 -2
- package/esm/utils/useEventListener.js +1 -1
- package/esm/utils/useIsMounted.d.ts +2 -0
- package/esm/utils/useIsMounted.js +16 -0
- package/esm/utils/usePortal.js +2 -2
- package/esm/utils/useRootClose.js +8 -6
- package/locales/fa_IR/package.json +7 -0
- package/package.json +6 -8
- package/styles/color-modes/dark.less +1 -0
- package/styles/color-modes/high-contrast.less +1 -0
- package/styles/color-modes/light.less +3 -0
- package/styles/plugins/palette.js +10 -1
- package/styles/variables.less +3 -1
- package/cjs/@types/icons.d.ts +0 -1
- package/esm/@types/icons.d.ts +0 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.isArray = isArray;
|
|
5
|
+
exports.default = conformToMask;
|
|
6
|
+
|
|
7
|
+
var _utilities = require("./utilities");
|
|
8
|
+
|
|
9
|
+
function isArray(value) {
|
|
10
|
+
return Array.isArray && Array.isArray(value) || value instanceof Array;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function conformToMask(rawValue, mask, config) {
|
|
14
|
+
if (rawValue === void 0) {
|
|
15
|
+
rawValue = '';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (mask === void 0) {
|
|
19
|
+
mask = [];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (config === void 0) {
|
|
23
|
+
config = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (!isArray(mask)) {
|
|
27
|
+
// If someone passes a function as the mask property, we should call the
|
|
28
|
+
// function to get the mask array - Normally this is handled by the
|
|
29
|
+
// `createTextMaskInputElement:update` function - this allows mask functions
|
|
30
|
+
// to be used directly with `conformToMask`
|
|
31
|
+
if (typeof mask === 'function') {
|
|
32
|
+
// call the mask function to get the mask array
|
|
33
|
+
mask = mask(rawValue, config); // mask functions can setup caret traps to have some control over how the caret moves. We need to process
|
|
34
|
+
// the mask for any caret traps. `processCaretTraps` will remove the caret traps from the mask
|
|
35
|
+
|
|
36
|
+
mask = (0, _utilities.processCaretTraps)(mask).maskWithoutCaretTraps;
|
|
37
|
+
} else {
|
|
38
|
+
throw new Error('Text-mask:conformToMask; The mask property must be an array.');
|
|
39
|
+
}
|
|
40
|
+
} // These configurations tell us how to conform the mask
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
var _config = config,
|
|
44
|
+
_config$guide = _config.guide,
|
|
45
|
+
guide = _config$guide === void 0 ? true : _config$guide,
|
|
46
|
+
_config$previousConfo = _config.previousConformedValue,
|
|
47
|
+
previousConformedValue = _config$previousConfo === void 0 ? '' : _config$previousConfo,
|
|
48
|
+
_config$placeholderCh = _config.placeholderChar,
|
|
49
|
+
placeholderChar = _config$placeholderCh === void 0 ? _utilities.defaultPlaceholderChar : _config$placeholderCh,
|
|
50
|
+
_config$placeholder = _config.placeholder,
|
|
51
|
+
placeholder = _config$placeholder === void 0 ? (0, _utilities.convertMaskToPlaceholder)(mask, placeholderChar) : _config$placeholder,
|
|
52
|
+
currentCaretPosition = _config.currentCaretPosition,
|
|
53
|
+
keepCharPositions = _config.keepCharPositions; // The configs below indicate that the user wants the algorithm to work in *no guide* mode
|
|
54
|
+
|
|
55
|
+
var suppressGuide = guide === false && previousConformedValue !== undefined; // Calculate lengths once for performance
|
|
56
|
+
|
|
57
|
+
var rawValueLength = rawValue.length;
|
|
58
|
+
var previousConformedValueLength = previousConformedValue.length;
|
|
59
|
+
var placeholderLength = placeholder.length;
|
|
60
|
+
var maskLength = mask.length; // This tells us the number of edited characters and the direction in which they were edited (+/-)
|
|
61
|
+
|
|
62
|
+
var editDistance = rawValueLength - previousConformedValueLength; // In *no guide* mode, we need to know if the user is trying to add a character or not
|
|
63
|
+
|
|
64
|
+
var isAddition = editDistance > 0; // Tells us the index of the first change. For (438) 394-4938 to (38) 394-4938, that would be 1
|
|
65
|
+
|
|
66
|
+
var indexOfFirstChange = currentCaretPosition + (isAddition ? -editDistance : 0); // We're also gonna need the index of last change, which we can derive as follows...
|
|
67
|
+
|
|
68
|
+
var indexOfLastChange = indexOfFirstChange + Math.abs(editDistance); // If `conformToMask` is configured to keep character positions, that is, for mask 111, previous value
|
|
69
|
+
// _2_ and raw value 3_2_, the new conformed value should be 32_, not 3_2 (default behavior). That's in the case of
|
|
70
|
+
// addition. And in the case of deletion, previous value _23, raw value _3, the new conformed string should be
|
|
71
|
+
// __3, not _3_ (default behavior)
|
|
72
|
+
//
|
|
73
|
+
// The next block of logic handles keeping character positions for the case of deletion. (Keeping
|
|
74
|
+
// character positions for the case of addition is further down since it is handled differently.)
|
|
75
|
+
// To do this, we want to compensate for all characters that were deleted
|
|
76
|
+
|
|
77
|
+
if (keepCharPositions === true && !isAddition) {
|
|
78
|
+
// We will be storing the new placeholder characters in this variable.
|
|
79
|
+
var compensatingPlaceholderChars = ''; // For every character that was deleted from a placeholder position, we add a placeholder char
|
|
80
|
+
|
|
81
|
+
for (var i = indexOfFirstChange; i < indexOfLastChange; i++) {
|
|
82
|
+
if (placeholder[i] === placeholderChar) {
|
|
83
|
+
compensatingPlaceholderChars += placeholderChar;
|
|
84
|
+
}
|
|
85
|
+
} // Now we trick our algorithm by modifying the raw value to make it contain additional placeholder characters
|
|
86
|
+
// That way when the we start laying the characters again on the mask, it will keep the non-deleted characters
|
|
87
|
+
// in their positions.
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
rawValue = rawValue.slice(0, indexOfFirstChange) + compensatingPlaceholderChars + rawValue.slice(indexOfFirstChange, rawValueLength);
|
|
91
|
+
} // Convert `rawValue` string to an array, and mark characters based on whether they are newly added or have
|
|
92
|
+
// existed in the previous conformed value. Identifying new and old characters is needed for `conformToMask`
|
|
93
|
+
// to work if it is configured to keep character positions.
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
var rawValueArr = rawValue.split('').map(function (char, i) {
|
|
97
|
+
return {
|
|
98
|
+
char: char,
|
|
99
|
+
isNew: i >= indexOfFirstChange && i < indexOfLastChange
|
|
100
|
+
};
|
|
101
|
+
}); // The loop below removes masking characters from user input. For example, for mask
|
|
102
|
+
// `00 (111)`, the placeholder would be `00 (___)`. If user input is `00 (234)`, the loop below
|
|
103
|
+
// would remove all characters but `234` from the `rawValueArr`. The rest of the algorithm
|
|
104
|
+
// then would lay `234` on top of the available placeholder positions in the mask.
|
|
105
|
+
|
|
106
|
+
for (var _i = rawValueLength - 1; _i >= 0; _i--) {
|
|
107
|
+
var char = rawValueArr[_i].char;
|
|
108
|
+
|
|
109
|
+
if (char !== placeholderChar) {
|
|
110
|
+
var shouldOffset = _i >= indexOfFirstChange && previousConformedValueLength === maskLength;
|
|
111
|
+
|
|
112
|
+
if (char === placeholder[shouldOffset ? _i - editDistance : _i]) {
|
|
113
|
+
rawValueArr.splice(_i, 1);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} // This is the variable that we will be filling with characters as we figure them out
|
|
117
|
+
// in the algorithm below
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
var conformedValue = '';
|
|
121
|
+
var someCharsRejected = false; // Ok, so first we loop through the placeholder looking for placeholder characters to fill up.
|
|
122
|
+
|
|
123
|
+
placeholderLoop: for (var _i2 = 0; _i2 < placeholderLength; _i2++) {
|
|
124
|
+
var charInPlaceholder = placeholder[_i2]; // We see one. Let's find out what we can put in it.
|
|
125
|
+
|
|
126
|
+
if (charInPlaceholder === placeholderChar) {
|
|
127
|
+
// But before that, do we actually have any user characters that need a place?
|
|
128
|
+
if (rawValueArr.length > 0) {
|
|
129
|
+
// We will keep chipping away at user input until either we run out of characters
|
|
130
|
+
// or we find at least one character that we can map.
|
|
131
|
+
while (rawValueArr.length > 0) {
|
|
132
|
+
// Let's retrieve the first user character in the queue of characters we have left
|
|
133
|
+
var _rawValueArr$shift = rawValueArr.shift(),
|
|
134
|
+
rawValueChar = _rawValueArr$shift.char,
|
|
135
|
+
isNew = _rawValueArr$shift.isNew; // If the character we got from the user input is a placeholder character (which happens
|
|
136
|
+
// regularly because user input could be something like (540) 90_-____, which includes
|
|
137
|
+
// a bunch of `_` which are placeholder characters) and we are not in *no guide* mode,
|
|
138
|
+
// then we map this placeholder character to the current spot in the placeholder
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if (rawValueChar === placeholderChar && suppressGuide !== true) {
|
|
142
|
+
conformedValue += placeholderChar; // And we go to find the next placeholder character that needs filling
|
|
143
|
+
|
|
144
|
+
continue placeholderLoop; // Else if, the character we got from the user input is not a placeholder, let's see
|
|
145
|
+
// if the current position in the mask can accept it.
|
|
146
|
+
} else if (mask[_i2].test(rawValueChar)) {
|
|
147
|
+
// we map the character differently based on whether we are keeping character positions or not.
|
|
148
|
+
// If any of the conditions below are met, we simply map the raw value character to the
|
|
149
|
+
// placeholder position.
|
|
150
|
+
if (keepCharPositions !== true || isNew === false || previousConformedValue === '' || guide === false || !isAddition) {
|
|
151
|
+
conformedValue += rawValueChar;
|
|
152
|
+
} else {
|
|
153
|
+
// We enter this block of code if we are trying to keep character positions and none of the conditions
|
|
154
|
+
// above is met. In this case, we need to see if there's an available spot for the raw value character
|
|
155
|
+
// to be mapped to. If we couldn't find a spot, we will discard the character.
|
|
156
|
+
//
|
|
157
|
+
// For example, for mask `1111`, previous conformed value `_2__`, raw value `942_2__`. We can map the
|
|
158
|
+
// `9`, to the first available placeholder position, but then, there are no more spots available for the
|
|
159
|
+
// `4` and `2`. So, we discard them and end up with a conformed value of `92__`.
|
|
160
|
+
var rawValueArrLength = rawValueArr.length;
|
|
161
|
+
var indexOfNextAvailablePlaceholderChar = null; // Let's loop through the remaining raw value characters. We are looking for either a suitable spot, ie,
|
|
162
|
+
// a placeholder character or a non-suitable spot, ie, a non-placeholder character that is not new.
|
|
163
|
+
// If we see a suitable spot first, we store its position and exit the loop. If we see a non-suitable
|
|
164
|
+
// spot first, we exit the loop and our `indexOfNextAvailablePlaceholderChar` will stay as `null`.
|
|
165
|
+
|
|
166
|
+
for (var _i3 = 0; _i3 < rawValueArrLength; _i3++) {
|
|
167
|
+
var charData = rawValueArr[_i3];
|
|
168
|
+
|
|
169
|
+
if (charData.char !== placeholderChar && charData.isNew === false) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (charData.char === placeholderChar) {
|
|
174
|
+
indexOfNextAvailablePlaceholderChar = _i3;
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
} // If `indexOfNextAvailablePlaceholderChar` is not `null`, that means the character is not blocked.
|
|
178
|
+
// We can map it. And to keep the character positions, we remove the placeholder character
|
|
179
|
+
// from the remaining characters
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
if (indexOfNextAvailablePlaceholderChar !== null) {
|
|
183
|
+
conformedValue += rawValueChar;
|
|
184
|
+
rawValueArr.splice(indexOfNextAvailablePlaceholderChar, 1); // If `indexOfNextAvailablePlaceholderChar` is `null`, that means the character is blocked. We have to
|
|
185
|
+
// discard it.
|
|
186
|
+
} else {
|
|
187
|
+
_i2--;
|
|
188
|
+
}
|
|
189
|
+
} // Since we've mapped this placeholder position. We move on to the next one.
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
continue placeholderLoop;
|
|
193
|
+
} else {
|
|
194
|
+
someCharsRejected = true;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
} // We reach this point when we've mapped all the user input characters to placeholder
|
|
198
|
+
// positions in the mask. In *guide* mode, we append the left over characters in the
|
|
199
|
+
// placeholder to the `conformedString`, but in *no guide* mode, we don't wanna do that.
|
|
200
|
+
//
|
|
201
|
+
// That is, for mask `(111)` and user input `2`, we want to return `(2`, not `(2__)`.
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if (suppressGuide === false) {
|
|
205
|
+
conformedValue += placeholder.substr(_i2, placeholderLength);
|
|
206
|
+
} // And we break
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
break; // Else, the charInPlaceholder is not a placeholderChar. That is, we cannot fill it
|
|
210
|
+
// with user input. So we just map it to the final output
|
|
211
|
+
} else {
|
|
212
|
+
conformedValue += charInPlaceholder;
|
|
213
|
+
}
|
|
214
|
+
} // The following logic is needed to deal with the case of deletion in *no guide* mode.
|
|
215
|
+
//
|
|
216
|
+
// Consider the silly mask `(111) /// 1`. What if user tries to delete the last placeholder
|
|
217
|
+
// position? Something like `(589) /// `. We want to conform that to `(589`. Not `(589) /// `.
|
|
218
|
+
// That's why the logic below finds the last filled placeholder character, and removes everything
|
|
219
|
+
// from that point on.
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
if (suppressGuide && isAddition === false) {
|
|
223
|
+
var indexOfLastFilledPlaceholderChar = null; // Find the last filled placeholder position and substring from there
|
|
224
|
+
|
|
225
|
+
for (var _i4 = 0; _i4 < conformedValue.length; _i4++) {
|
|
226
|
+
if (placeholder[_i4] === placeholderChar) {
|
|
227
|
+
indexOfLastFilledPlaceholderChar = _i4;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (indexOfLastFilledPlaceholderChar !== null) {
|
|
232
|
+
// We substring from the beginning until the position after the last filled placeholder char.
|
|
233
|
+
conformedValue = conformedValue.substr(0, indexOfLastFilledPlaceholderChar + 1);
|
|
234
|
+
} else {
|
|
235
|
+
// If we couldn't find `indexOfLastFilledPlaceholderChar` that means the user deleted
|
|
236
|
+
// the first character in the mask. So we return an empty string.
|
|
237
|
+
conformedValue = '';
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
conformedValue: conformedValue,
|
|
243
|
+
meta: {
|
|
244
|
+
someCharsRejected: someCharsRejected
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
@@ -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,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = createTextMaskInputElement;
|
|
7
|
+
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
|
|
10
|
+
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
11
|
+
|
|
12
|
+
var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
|
|
13
|
+
|
|
14
|
+
var _adjustCaretPosition = _interopRequireDefault(require("./adjustCaretPosition"));
|
|
15
|
+
|
|
16
|
+
var _conformToMask2 = _interopRequireDefault(require("./conformToMask"));
|
|
17
|
+
|
|
18
|
+
var _utilities = require("./utilities");
|
|
19
|
+
|
|
20
|
+
var emptyString = '';
|
|
21
|
+
var strNone = 'none';
|
|
22
|
+
var strObject = 'object';
|
|
23
|
+
var isAndroid = typeof navigator !== 'undefined' && /Android/i.test(navigator.userAgent);
|
|
24
|
+
var defer = typeof requestAnimationFrame !== 'undefined' ? requestAnimationFrame : setTimeout;
|
|
25
|
+
|
|
26
|
+
function createTextMaskInputElement(config) {
|
|
27
|
+
// Anything that we will need to keep between `update` calls, we will store in this `state` object.
|
|
28
|
+
var state = {
|
|
29
|
+
previousConformedValue: undefined,
|
|
30
|
+
previousPlaceholder: undefined
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
state: state,
|
|
34
|
+
// `update` is called by framework components whenever they want to update the `value` of the input element.
|
|
35
|
+
// The caller can send a `rawValue` to be conformed and set on the input element. However, the default use-case
|
|
36
|
+
// is for this to be read from the `inputElement` directly.
|
|
37
|
+
update: function update(rawValue, _temp) {
|
|
38
|
+
var _pipeResults, _pipeResults2;
|
|
39
|
+
|
|
40
|
+
var _ref = _temp === void 0 ? config : _temp,
|
|
41
|
+
inputElement = _ref.inputElement,
|
|
42
|
+
providedMask = _ref.mask,
|
|
43
|
+
guide = _ref.guide,
|
|
44
|
+
pipe = _ref.pipe,
|
|
45
|
+
_ref$placeholderChar = _ref.placeholderChar,
|
|
46
|
+
placeholderChar = _ref$placeholderChar === void 0 ? _utilities.defaultPlaceholderChar : _ref$placeholderChar,
|
|
47
|
+
_ref$keepCharPosition = _ref.keepCharPositions,
|
|
48
|
+
keepCharPositions = _ref$keepCharPosition === void 0 ? false : _ref$keepCharPosition,
|
|
49
|
+
_ref$showMask = _ref.showMask,
|
|
50
|
+
showMask = _ref$showMask === void 0 ? false : _ref$showMask;
|
|
51
|
+
|
|
52
|
+
// if `rawValue` is `undefined`, read from the `inputElement`
|
|
53
|
+
if (typeof rawValue === 'undefined') {
|
|
54
|
+
rawValue = inputElement.value;
|
|
55
|
+
} // If `rawValue` equals `state.previousConformedValue`, we don't need to change anything. So, we return.
|
|
56
|
+
// This check is here to handle controlled framework components that repeat the `update` call on every render.
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (rawValue === state.previousConformedValue) {
|
|
60
|
+
return;
|
|
61
|
+
} // Text Mask accepts masks that are a combination of a `mask` and a `pipe` that work together. If such a `mask` is
|
|
62
|
+
// passed, we destructure it below, so the rest of the code can work normally as if a separate `mask` and a `pipe`
|
|
63
|
+
// were passed.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if (typeof providedMask === strObject && providedMask.pipe !== undefined && providedMask.mask !== undefined) {
|
|
67
|
+
pipe = providedMask.pipe;
|
|
68
|
+
providedMask = providedMask.mask;
|
|
69
|
+
} // The `placeholder` is an essential piece of how Text Mask works. For a mask like `(111)`, the placeholder would
|
|
70
|
+
// be `(___)` if the `placeholderChar` is set to `_`.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
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
|
|
74
|
+
// have to call that function to get the mask array.
|
|
75
|
+
|
|
76
|
+
var mask; // If the provided mask is an array, we can call `convertMaskToPlaceholder` here once and we'll always have the
|
|
77
|
+
// correct `placeholder`.
|
|
78
|
+
|
|
79
|
+
if (providedMask instanceof Array) {
|
|
80
|
+
placeholder = (0, _utilities.convertMaskToPlaceholder)(providedMask, placeholderChar);
|
|
81
|
+
} // In framework components that support reactivity, it's possible to turn off masking by passing
|
|
82
|
+
// `false` for `mask` after initialization. See https://github.com/text-mask/text-mask/pull/359
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
if (providedMask === false) {
|
|
86
|
+
return;
|
|
87
|
+
} // We check the provided `rawValue` before moving further.
|
|
88
|
+
// If it's something we can't work with `getSafeRawValue` will throw.
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
var safeRawValue = getSafeRawValue(rawValue); // `selectionEnd` indicates to us where the caret position is after the user has typed into the input
|
|
92
|
+
|
|
93
|
+
var currentCaretPosition = inputElement.selectionEnd; // We need to know what the `previousConformedValue` and `previousPlaceholder` is from the previous `update` call
|
|
94
|
+
|
|
95
|
+
var previousConformedValue = state.previousConformedValue,
|
|
96
|
+
previousPlaceholder = state.previousPlaceholder;
|
|
97
|
+
var caretTrapIndexes; // If the `providedMask` is a function. We need to call it at every `update` to get the `mask` array.
|
|
98
|
+
// Then we also need to get the `placeholder`
|
|
99
|
+
|
|
100
|
+
if (typeof providedMask === 'function') {
|
|
101
|
+
mask = providedMask(safeRawValue, {
|
|
102
|
+
currentCaretPosition: currentCaretPosition,
|
|
103
|
+
previousConformedValue: previousConformedValue,
|
|
104
|
+
placeholderChar: placeholderChar
|
|
105
|
+
}); // disable masking if `mask` is `false`
|
|
106
|
+
|
|
107
|
+
if (mask === false) {
|
|
108
|
+
return;
|
|
109
|
+
} // mask functions can setup caret traps to have some control over how the caret moves. We need to process
|
|
110
|
+
// the mask for any caret traps. `processCaretTraps` will remove the caret traps from the mask and return
|
|
111
|
+
// the indexes of the caret traps.
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
var _processCaretTraps = (0, _utilities.processCaretTraps)(mask),
|
|
115
|
+
maskWithoutCaretTraps = _processCaretTraps.maskWithoutCaretTraps,
|
|
116
|
+
indexes = _processCaretTraps.indexes;
|
|
117
|
+
|
|
118
|
+
mask = maskWithoutCaretTraps; // The processed mask is what we're interested in
|
|
119
|
+
|
|
120
|
+
caretTrapIndexes = indexes; // And we need to store these indexes because they're needed by `adjustCaretPosition`
|
|
121
|
+
|
|
122
|
+
placeholder = (0, _utilities.convertMaskToPlaceholder)(mask, placeholderChar); // If the `providedMask` is not a function, we just use it as-is.
|
|
123
|
+
} else {
|
|
124
|
+
mask = providedMask;
|
|
125
|
+
} // The following object will be passed to `conformToMask` to determine how the `rawValue` will be conformed
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
var conformToMaskConfig = {
|
|
129
|
+
previousConformedValue: previousConformedValue,
|
|
130
|
+
guide: guide,
|
|
131
|
+
placeholderChar: placeholderChar,
|
|
132
|
+
pipe: pipe,
|
|
133
|
+
placeholder: placeholder,
|
|
134
|
+
currentCaretPosition: currentCaretPosition,
|
|
135
|
+
keepCharPositions: keepCharPositions
|
|
136
|
+
}; // `conformToMask` returns `conformedValue` as part of an object for future API flexibility
|
|
137
|
+
|
|
138
|
+
var _conformToMask = (0, _conformToMask2.default)(safeRawValue, mask, conformToMaskConfig),
|
|
139
|
+
conformedValue = _conformToMask.conformedValue; // The following few lines are to support the `pipe` feature.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
var piped = typeof pipe === 'function';
|
|
143
|
+
var pipeResults = {}; // If `pipe` is a function, we call it.
|
|
144
|
+
|
|
145
|
+
if (piped) {
|
|
146
|
+
// `pipe` receives the `conformedValue` and the configurations with which `conformToMask` was called.
|
|
147
|
+
pipeResults = pipe(conformedValue, (0, _extends2.default)({
|
|
148
|
+
rawValue: safeRawValue
|
|
149
|
+
}, conformToMaskConfig)); // `pipeResults` should be an object. But as a convenience, we allow the pipe author to just return `false` to
|
|
150
|
+
// indicate rejection. Or return just a string when there are no piped characters.
|
|
151
|
+
// If the `pipe` returns `false` or a string, the block below turns it into an object that the rest
|
|
152
|
+
// of the code can work with.
|
|
153
|
+
|
|
154
|
+
if (pipeResults === false) {
|
|
155
|
+
// If the `pipe` rejects `conformedValue`, we use the `previousConformedValue`, and set `rejected` to `true`.
|
|
156
|
+
pipeResults = {
|
|
157
|
+
value: previousConformedValue,
|
|
158
|
+
rejected: true
|
|
159
|
+
};
|
|
160
|
+
} else if ((0, _isString.default)(pipeResults)) {
|
|
161
|
+
pipeResults = {
|
|
162
|
+
value: pipeResults
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
} // Before we proceed, we need to know which conformed value to use, the one returned by the pipe or the one
|
|
166
|
+
// returned by `conformToMask`.
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
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
|
|
170
|
+
// the caret position. `adjustCaretPosition` will tell us.
|
|
171
|
+
|
|
172
|
+
var adjustedCaretPosition = (0, _adjustCaretPosition.default)({
|
|
173
|
+
previousConformedValue: previousConformedValue,
|
|
174
|
+
previousPlaceholder: previousPlaceholder,
|
|
175
|
+
conformedValue: finalConformedValue,
|
|
176
|
+
placeholder: placeholder,
|
|
177
|
+
rawValue: safeRawValue,
|
|
178
|
+
currentCaretPosition: currentCaretPosition,
|
|
179
|
+
placeholderChar: placeholderChar,
|
|
180
|
+
indexesOfPipedChars: (_pipeResults2 = pipeResults) === null || _pipeResults2 === void 0 ? void 0 : _pipeResults2.indexesOfPipedChars,
|
|
181
|
+
caretTrapIndexes: caretTrapIndexes
|
|
182
|
+
}); // Text Mask sets the input value to an empty string when the condition below is set. It provides a better UX.
|
|
183
|
+
|
|
184
|
+
var inputValueShouldBeEmpty = finalConformedValue === placeholder && adjustedCaretPosition === 0;
|
|
185
|
+
var emptyValue = showMask ? placeholder : emptyString;
|
|
186
|
+
var inputElementValue = inputValueShouldBeEmpty ? emptyValue : finalConformedValue;
|
|
187
|
+
state.previousConformedValue = inputElementValue; // store value for access for next time
|
|
188
|
+
|
|
189
|
+
state.previousPlaceholder = placeholder; // In some cases, this `update` method will be repeatedly called with a raw value that has already been conformed
|
|
190
|
+
// and set to `inputElement.value`. The below check guards against needlessly readjusting the input state.
|
|
191
|
+
// See https://github.com/text-mask/text-mask/issues/231
|
|
192
|
+
|
|
193
|
+
if (inputElement.value === inputElementValue) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
inputElement.value = inputElementValue; // set the input value
|
|
198
|
+
|
|
199
|
+
safeSetSelection(inputElement, adjustedCaretPosition); // adjust caret position
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function safeSetSelection(element, selectionPosition) {
|
|
205
|
+
if (document.activeElement === element) {
|
|
206
|
+
if (isAndroid) {
|
|
207
|
+
defer(function () {
|
|
208
|
+
return element.setSelectionRange(selectionPosition, selectionPosition, strNone);
|
|
209
|
+
}, 0);
|
|
210
|
+
} else {
|
|
211
|
+
element.setSelectionRange(selectionPosition, selectionPosition, strNone);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function getSafeRawValue(inputValue) {
|
|
217
|
+
if ((0, _isString.default)(inputValue)) {
|
|
218
|
+
return inputValue;
|
|
219
|
+
} else if ((0, _isNumber.default)(inputValue)) {
|
|
220
|
+
return String(inputValue);
|
|
221
|
+
} else if (inputValue === undefined || inputValue === null) {
|
|
222
|
+
return emptyString;
|
|
223
|
+
} else {
|
|
224
|
+
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));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _MaskedInput = _interopRequireDefault(require("./MaskedInput"));
|
|
9
|
+
|
|
10
|
+
var _default = _MaskedInput.default;
|
|
11
|
+
exports.default = _default;
|
|
@@ -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,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.convertMaskToPlaceholder = convertMaskToPlaceholder;
|
|
5
|
+
exports.processCaretTraps = processCaretTraps;
|
|
6
|
+
exports.defaultPlaceholderChar = void 0;
|
|
7
|
+
var emptyArray = [];
|
|
8
|
+
var strCaretTrap = '[]';
|
|
9
|
+
var defaultPlaceholderChar = '_';
|
|
10
|
+
exports.defaultPlaceholderChar = defaultPlaceholderChar;
|
|
11
|
+
|
|
12
|
+
function convertMaskToPlaceholder(mask, placeholderChar) {
|
|
13
|
+
if (mask === void 0) {
|
|
14
|
+
mask = emptyArray;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (placeholderChar === void 0) {
|
|
18
|
+
placeholderChar = defaultPlaceholderChar;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!Array.isArray(mask)) {
|
|
22
|
+
throw new Error('Text-mask:convertMaskToPlaceholder; The mask property must be an array.');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (mask.indexOf(placeholderChar) !== -1) {
|
|
26
|
+
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)));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return mask.map(function (char) {
|
|
30
|
+
return char instanceof RegExp ? placeholderChar : char;
|
|
31
|
+
}).join('');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function processCaretTraps(mask) {
|
|
35
|
+
var indexes = [];
|
|
36
|
+
var indexOfCaretTrap;
|
|
37
|
+
|
|
38
|
+
while (indexOfCaretTrap = mask.indexOf(strCaretTrap), indexOfCaretTrap !== -1) {
|
|
39
|
+
indexes.push(indexOfCaretTrap);
|
|
40
|
+
mask.splice(indexOfCaretTrap, 1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
maskWithoutCaretTraps: mask,
|
|
45
|
+
indexes: indexes
|
|
46
|
+
};
|
|
47
|
+
}
|
package/cjs/Menu/MenuItem.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface MenuItemProps {
|
|
|
8
8
|
/** Render prop */
|
|
9
9
|
children: (menuitem: React.LiHTMLAttributes<HTMLLIElement> & MenuitemRenderProps, ref: React.Ref<HTMLLIElement>) => React.ReactElement;
|
|
10
10
|
/** Callback when menuitem is being activated */
|
|
11
|
-
onActivate?: (event: React.SyntheticEvent
|
|
11
|
+
onActivate?: (event: React.SyntheticEvent) => void;
|
|
12
12
|
}
|
|
13
13
|
export interface MenuitemRenderProps {
|
|
14
14
|
selected: boolean;
|
package/cjs/Menu/Menubar.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export interface MenubarProps {
|
|
|
5
5
|
/** Render prop */
|
|
6
6
|
children: (menubar: React.HTMLAttributes<HTMLUListElement>, ref: React.Ref<HTMLUListElement>) => React.ReactElement;
|
|
7
7
|
/** Callback triggered when an item is being activated */
|
|
8
|
-
onActivateItem?: (event: React.SyntheticEvent
|
|
8
|
+
onActivateItem?: (event: React.SyntheticEvent) => void;
|
|
9
9
|
}
|
|
10
10
|
export default function Menubar({ vertical, children, onActivateItem }: MenubarProps): JSX.Element;
|
package/cjs/Message/Message.js
CHANGED
|
@@ -50,12 +50,24 @@ var Message = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
50
50
|
var _useClassNames = (0, _utils.useClassNames)(classPrefix),
|
|
51
51
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
52
52
|
merge = _useClassNames.merge,
|
|
53
|
-
prefix = _useClassNames.prefix;
|
|
53
|
+
prefix = _useClassNames.prefix;
|
|
54
54
|
|
|
55
|
+
var isMounted = (0, _utils.useIsMounted)(); // Timed close message
|
|
55
56
|
|
|
56
57
|
var _useTimeout = (0, _utils.useTimeout)(onClose, duration, duration > 0),
|
|
57
58
|
clear = _useTimeout.clear;
|
|
58
59
|
|
|
60
|
+
var handleClose = (0, _react.useCallback)(function (event) {
|
|
61
|
+
setDisplay('hiding');
|
|
62
|
+
onClose === null || onClose === void 0 ? void 0 : onClose(event);
|
|
63
|
+
clear();
|
|
64
|
+
setTimeout(function () {
|
|
65
|
+
if (isMounted()) {
|
|
66
|
+
setDisplay('hide');
|
|
67
|
+
}
|
|
68
|
+
}, 1000);
|
|
69
|
+
}, [clear, isMounted, onClose]);
|
|
70
|
+
|
|
59
71
|
if (display === 'hide') {
|
|
60
72
|
return null;
|
|
61
73
|
}
|
|
@@ -63,16 +75,6 @@ var Message = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
63
75
|
var classes = merge(className, withClassPrefix(type, display, (_withClassPrefix = {
|
|
64
76
|
full: full
|
|
65
77
|
}, _withClassPrefix['has-title'] = header, _withClassPrefix['has-icon'] = showIcon, _withClassPrefix)));
|
|
66
|
-
|
|
67
|
-
var handleClose = function handleClose(event) {
|
|
68
|
-
setDisplay('hiding');
|
|
69
|
-
onClose === null || onClose === void 0 ? void 0 : onClose(event);
|
|
70
|
-
clear();
|
|
71
|
-
setTimeout(function () {
|
|
72
|
-
setDisplay('hide');
|
|
73
|
-
}, 1000);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
78
|
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({
|
|
77
79
|
role: "alert"
|
|
78
80
|
}, rest, {
|
package/cjs/Modal/Modal.js
CHANGED
|
@@ -19,6 +19,10 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
19
19
|
|
|
20
20
|
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
21
21
|
|
|
22
|
+
var _on = _interopRequireDefault(require("dom-lib/on"));
|
|
23
|
+
|
|
24
|
+
var _getTransitionEnd = _interopRequireDefault(require("dom-lib/getTransitionEnd"));
|
|
25
|
+
|
|
22
26
|
var _Modal = _interopRequireWildcard(require("../Overlay/Modal"));
|
|
23
27
|
|
|
24
28
|
var _Bounce = _interopRequireDefault(require("../Animation/Bounce"));
|
|
@@ -37,8 +41,6 @@ var _ModalTitle = _interopRequireDefault(require("./ModalTitle"));
|
|
|
37
41
|
|
|
38
42
|
var _ModalFooter = _interopRequireDefault(require("./ModalFooter"));
|
|
39
43
|
|
|
40
|
-
var _DOMHelper = _interopRequireDefault(require("../DOMHelper"));
|
|
41
|
-
|
|
42
44
|
var _utils2 = require("./utils");
|
|
43
45
|
|
|
44
46
|
var _useUniqueId = _interopRequireDefault(require("../utils/useUniqueId"));
|
|
@@ -122,7 +124,7 @@ var Modal = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
|
|
|
122
124
|
// When the value of `backdrop` is `static`, a jitter animation will be added to the dialog when clicked.
|
|
123
125
|
if (backdrop === 'static') {
|
|
124
126
|
setShake(true);
|
|
125
|
-
transitionEndListener.current =
|
|
127
|
+
transitionEndListener.current = (0, _on.default)(dialogRef.current, (0, _getTransitionEnd.default)(), function () {
|
|
126
128
|
setShake(false);
|
|
127
129
|
});
|
|
128
130
|
}
|