rsuite 5.0.3 → 5.2.2
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 +7 -1
- package/CHANGELOG.md +50 -0
- package/MaskedInput/package.json +7 -0
- package/PanelGroup/styles/index.less +12 -12
- package/README.md +4 -46
- package/Sidenav/styles/index.less +4 -0
- package/Slider/styles/index.less +20 -14
- package/Toggle/styles/index.less +53 -12
- package/Toggle/styles/mixin.less +25 -11
- 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/DropdownMenu.js +6 -5
- package/cjs/CheckTreePicker/CheckTreeNode.d.ts +1 -1
- package/cjs/CheckTreePicker/CheckTreePicker.d.ts +1 -1
- package/cjs/CheckTreePicker/utils.d.ts +1 -1
- package/cjs/CheckTreePicker/utils.js +7 -6
- 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 +3 -2
- package/cjs/DateRangePicker/Calendar.d.ts +1 -1
- package/cjs/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/cjs/DateRangePicker/DateRangePicker.js +3 -2
- 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 -19
- package/cjs/Dropdown/DropdownMenu.d.ts +2 -2
- package/cjs/Dropdown/useRenderDropdownItem.d.ts +2 -0
- package/cjs/Dropdown/useRenderDropdownItem.js +26 -0
- package/cjs/Form/Form.d.ts +1 -1
- package/cjs/FormControl/FormControl.d.ts +9 -3
- package/cjs/Input/Input.d.ts +2 -1
- package/cjs/InputNumber/InputNumber.js +2 -2
- package/cjs/InputPicker/InputPicker.js +2 -2
- package/cjs/List/helper/useSortHelper.js +11 -6
- package/cjs/MaskedInput/MaskedInput.d.ts +6 -0
- package/cjs/MaskedInput/MaskedInput.js +26 -0
- package/cjs/MaskedInput/TextMask.d.ts +43 -0
- package/cjs/MaskedInput/TextMask.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 +15 -14
- 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 +27 -17
- 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 +12 -6
- package/cjs/Picker/SearchBar.d.ts +1 -1
- package/cjs/Picker/utils.d.ts +2 -2
- 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/Sidenav/SidenavDropdownItem.d.ts +1 -1
- package/cjs/Sidenav/SidenavDropdownItem.js +17 -10
- 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/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/Uploader/Uploader.d.ts +4 -4
- 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/scrollTopAnimation.js +5 -5
- package/cjs/utils/treeUtils.d.ts +2 -2
- package/cjs/utils/useElementResize.d.ts +1 -1
- package/cjs/utils/useElementResize.js +7 -5
- 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 +217 -84
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +217 -84
- package/dist/rsuite.js +769 -536
- 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/DropdownMenu.js +4 -3
- package/esm/CheckTreePicker/CheckTreeNode.d.ts +1 -1
- package/esm/CheckTreePicker/CheckTreePicker.d.ts +1 -1
- package/esm/CheckTreePicker/utils.d.ts +1 -1
- package/esm/CheckTreePicker/utils.js +7 -6
- 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 +3 -2
- package/esm/DateRangePicker/Calendar.d.ts +1 -1
- package/esm/DateRangePicker/DateRangePicker.d.ts +2 -2
- package/esm/DateRangePicker/DateRangePicker.js +3 -2
- 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 +22 -19
- package/esm/Dropdown/DropdownMenu.d.ts +2 -2
- package/esm/Dropdown/useRenderDropdownItem.d.ts +2 -0
- package/esm/Dropdown/useRenderDropdownItem.js +18 -0
- package/esm/Form/Form.d.ts +1 -1
- package/esm/FormControl/FormControl.d.ts +9 -3
- package/esm/Input/Input.d.ts +2 -1
- package/esm/InputNumber/InputNumber.js +2 -2
- package/esm/InputPicker/InputPicker.js +1 -1
- package/esm/List/helper/useSortHelper.js +8 -4
- package/esm/MaskedInput/MaskedInput.d.ts +6 -0
- package/esm/MaskedInput/MaskedInput.js +13 -0
- package/esm/MaskedInput/TextMask.d.ts +43 -0
- package/esm/MaskedInput/TextMask.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 +14 -12
- 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 +20 -11
- 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 +10 -5
- package/esm/Picker/SearchBar.d.ts +1 -1
- package/esm/Picker/utils.d.ts +2 -2
- 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/Sidenav/SidenavDropdownItem.d.ts +1 -1
- package/esm/Sidenav/SidenavDropdownItem.js +16 -10
- 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/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/Uploader/Uploader.d.ts +4 -4
- 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/scrollTopAnimation.js +2 -2
- package/esm/utils/treeUtils.d.ts +2 -2
- package/esm/utils/useElementResize.d.ts +1 -1
- package/esm/utils/useElementResize.js +8 -4
- 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 +5 -6
- package/styles/color-modes/light.less +2 -0
- package/styles/plugins/palette.js +10 -1
- package/cjs/@types/icons.d.ts +0 -1
- package/esm/@types/icons.d.ts +0 -1
package/esm/Input/Input.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { WithAsProps, RsRefForwardingComponent, TypeAttributes, FormControlBaseP
|
|
|
3
3
|
export interface LocaleType {
|
|
4
4
|
unfilled: string;
|
|
5
5
|
}
|
|
6
|
-
export interface InputProps extends WithAsProps, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'size'>, FormControlBaseProps
|
|
6
|
+
export interface InputProps extends WithAsProps, Omit<React.InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'size'>, FormControlBaseProps {
|
|
7
7
|
/** The HTML input type */
|
|
8
8
|
type?: string;
|
|
9
9
|
/** The HTML input id */
|
|
@@ -12,6 +12,7 @@ export interface InputProps extends WithAsProps, Omit<React.InputHTMLAttributes<
|
|
|
12
12
|
size?: TypeAttributes.Size;
|
|
13
13
|
/** Ref of input element */
|
|
14
14
|
inputRef?: React.Ref<any>;
|
|
15
|
+
onChange?: (value: string, event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
15
16
|
/** Called on press enter */
|
|
16
17
|
onPressEnter?: React.KeyboardEventHandler<HTMLInputElement>;
|
|
17
18
|
}
|
|
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
|
|
|
5
5
|
import isNil from 'lodash/isNil';
|
|
6
6
|
import AngleUpIcon from '@rsuite/icons/legacy/AngleUp';
|
|
7
7
|
import AngleDownIcon from '@rsuite/icons/legacy/AngleDown';
|
|
8
|
-
import
|
|
8
|
+
import on from 'dom-lib/on';
|
|
9
9
|
import InputGroup from '../InputGroup/InputGroup';
|
|
10
10
|
import InputGroupAddon from '../InputGroup/InputGroupAddon';
|
|
11
11
|
import Input from '../Input';
|
|
@@ -195,7 +195,7 @@ var InputNumber = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
195
195
|
var wheelListener;
|
|
196
196
|
|
|
197
197
|
if (inputRef.current && scrollable) {
|
|
198
|
-
wheelListener =
|
|
198
|
+
wheelListener = on(inputRef.current, 'wheel', handleWheel, {
|
|
199
199
|
passive: false
|
|
200
200
|
});
|
|
201
201
|
}
|
|
@@ -14,7 +14,7 @@ import clone from 'lodash/clone';
|
|
|
14
14
|
import isArray from 'lodash/isArray';
|
|
15
15
|
import omit from 'lodash/omit';
|
|
16
16
|
import pick from 'lodash/pick';
|
|
17
|
-
import
|
|
17
|
+
import getWidth from 'dom-lib/getWidth';
|
|
18
18
|
import shallowEqual from '../utils/shallowEqual';
|
|
19
19
|
import { filterNodesOfTree } from '../utils/treeUtils';
|
|
20
20
|
import Plaintext from '../Plaintext';
|
|
@@ -4,10 +4,11 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
|
|
5
5
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import on from 'dom-lib/on';
|
|
8
8
|
import { useCallback, useRef, useState } from 'react';
|
|
9
9
|
import AutoScroller from './AutoScroller';
|
|
10
10
|
import { closestNode, getEdgeOffset, getScrollingParent, isContainInteractiveElement, setInlineStyles, setTransitionDuration, setTranslate3d } from './utils';
|
|
11
|
+
import { useIsMounted } from '../../utils';
|
|
11
12
|
import useManager from './useManager';
|
|
12
13
|
|
|
13
14
|
var useSortHelper = function useSortHelper(config) {
|
|
@@ -30,14 +31,16 @@ var useSortHelper = function useSortHelper(config) {
|
|
|
30
31
|
listItemRegister = _useManager.listItemRegister,
|
|
31
32
|
getManagedItem = _useManager.getManagedItem,
|
|
32
33
|
getOrderedItems = _useManager.getOrderedItems;
|
|
34
|
+
|
|
35
|
+
var isMounted = useIsMounted();
|
|
33
36
|
/**
|
|
34
37
|
* start dragging
|
|
35
38
|
* */
|
|
36
39
|
|
|
37
|
-
|
|
38
40
|
var handlePress = useCallback(function (mouseDownEvent, targetNode, curManagedItem) {
|
|
39
41
|
var _activeNodeHelper;
|
|
40
42
|
|
|
43
|
+
if (!isMounted()) return;
|
|
41
44
|
var listItemBaseClassName = targetNode.classList[0]; // get list item base className
|
|
42
45
|
|
|
43
46
|
var helperElementClass = listItemBaseClassName + "-helper";
|
|
@@ -217,7 +220,8 @@ var useSortHelper = function useSortHelper(config) {
|
|
|
217
220
|
setTimeout(function () {
|
|
218
221
|
var _activeNodeHelper2, _activeNodeHelper2$pa;
|
|
219
222
|
|
|
220
|
-
// Remove the helper from the DOM
|
|
223
|
+
if (!isMounted()) return; // Remove the helper from the DOM
|
|
224
|
+
|
|
221
225
|
(_activeNodeHelper2 = activeNodeHelper) === null || _activeNodeHelper2 === void 0 ? void 0 : (_activeNodeHelper2$pa = _activeNodeHelper2.parentNode) === null || _activeNodeHelper2$pa === void 0 ? void 0 : _activeNodeHelper2$pa.removeChild(activeNodeHelper);
|
|
222
226
|
activeNodeHelper = null; // Remove redundant styles
|
|
223
227
|
|
|
@@ -260,7 +264,7 @@ var useSortHelper = function useSortHelper(config) {
|
|
|
260
264
|
oldIndex: activeNodeOldIndex,
|
|
261
265
|
newIndex: activeNodeNextIndex
|
|
262
266
|
}, mouseDownEvent.nativeEvent);
|
|
263
|
-
}, [autoScroll, getOrderedItems, onSort, onSortEnd, onSortMove, onSortStart, transitionDuration]);
|
|
267
|
+
}, [autoScroll, getOrderedItems, isMounted, onSort, onSortEnd, onSortMove, onSortStart, transitionDuration]);
|
|
264
268
|
/**
|
|
265
269
|
* Determine whether to start dragging
|
|
266
270
|
* */
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { InputProps } from '../Input';
|
|
2
|
+
import type { TextMaskProps } from './TextMask';
|
|
3
|
+
import { RsRefForwardingComponent } from '../@types/common';
|
|
4
|
+
export declare type MaskedInputProps = Omit<TextMaskProps, 'onChange'> & Omit<InputProps, 'type'>;
|
|
5
|
+
declare const MaskedInput: RsRefForwardingComponent<'input', MaskedInputProps>;
|
|
6
|
+
export default MaskedInput;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import TextMask from './TextMask';
|
|
4
|
+
import Input from '../Input';
|
|
5
|
+
var MaskedInput = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
6
|
+
var _props$as = props.as,
|
|
7
|
+
inputAs = _props$as === void 0 ? TextMask : _props$as;
|
|
8
|
+
return /*#__PURE__*/React.createElement(Input, _extends({}, props, {
|
|
9
|
+
as: inputAs,
|
|
10
|
+
ref: ref
|
|
11
|
+
}));
|
|
12
|
+
});
|
|
13
|
+
export default MaskedInput;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { MaskType, MaskFunctionType, ConfigType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#guide
|
|
5
|
+
*/
|
|
6
|
+
interface TextMaskBaseProps {
|
|
7
|
+
/**
|
|
8
|
+
* `guide` is a boolean that tells the component whether to be in guide or no guide mode.
|
|
9
|
+
*/
|
|
10
|
+
guide?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* `mask` is an array or a function that defines how the user input is going to be masked.
|
|
13
|
+
*/
|
|
14
|
+
mask?: MaskType | MaskFunctionType | boolean;
|
|
15
|
+
/**
|
|
16
|
+
* `showMask` is a boolean that tells the Text Mask component to display the mask as a placeholder
|
|
17
|
+
* in place of the regular placeholder when the input element value is empty.
|
|
18
|
+
*/
|
|
19
|
+
showMask?: boolean;
|
|
20
|
+
/** The placeholder character represents the fillable spot in the mask. The default placeholder character is underscore, _. */
|
|
21
|
+
placeholderChar?: string;
|
|
22
|
+
/** `keepCharPositions` changes the general behavior of the Text Mask component. */
|
|
23
|
+
keepCharPositions?: boolean;
|
|
24
|
+
/** You can provide a `pipe` function that will give you the opportunity to modify the conformed value before it is displayed on the screen. */
|
|
25
|
+
pipe?: (conformedValue: string, config: ConfigType) => string;
|
|
26
|
+
}
|
|
27
|
+
export declare type TextMaskProps = TextMaskBaseProps & React.HTMLAttributes<HTMLInputElement> & {
|
|
28
|
+
/** Custom rendering DOM */
|
|
29
|
+
render?: (ref: React.Ref<HTMLInputElement>, props: React.HTMLAttributes<HTMLInputElement>) => any;
|
|
30
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
31
|
+
value?: string | number;
|
|
32
|
+
readOnly?: boolean;
|
|
33
|
+
disabled?: boolean;
|
|
34
|
+
};
|
|
35
|
+
declare const TextMask: React.ForwardRefExoticComponent<TextMaskBaseProps & React.HTMLAttributes<HTMLInputElement> & {
|
|
36
|
+
/** Custom rendering DOM */
|
|
37
|
+
render?: (ref: React.Ref<HTMLInputElement>, props: React.HTMLAttributes<HTMLInputElement>) => any;
|
|
38
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
39
|
+
value?: string | number;
|
|
40
|
+
readOnly?: boolean;
|
|
41
|
+
disabled?: boolean;
|
|
42
|
+
} & React.RefAttributes<HTMLInputElement>>;
|
|
43
|
+
export default TextMask;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import React, { useCallback, useEffect, useRef } from 'react';
|
|
4
|
+
import omit from 'lodash/omit';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import createTextMaskInputElement from './createTextMaskInputElement';
|
|
7
|
+
import { mergeRefs } from '../utils';
|
|
8
|
+
/**
|
|
9
|
+
* https://github.com/text-mask/text-mask/blob/master/componentDocumentation.md#guide
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
var defaultRender = function defaultRender(ref, props) {
|
|
13
|
+
return /*#__PURE__*/React.createElement("input", _extends({
|
|
14
|
+
ref: ref
|
|
15
|
+
}, props));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var TextMask = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
19
|
+
var mask = props.mask,
|
|
20
|
+
_props$guide = props.guide,
|
|
21
|
+
guide = _props$guide === void 0 ? true : _props$guide,
|
|
22
|
+
placeholderChar = props.placeholderChar,
|
|
23
|
+
value = props.value,
|
|
24
|
+
showMask = props.showMask,
|
|
25
|
+
pipe = props.pipe,
|
|
26
|
+
_props$render = props.render,
|
|
27
|
+
render = _props$render === void 0 ? defaultRender : _props$render,
|
|
28
|
+
onChange = props.onChange,
|
|
29
|
+
rest = _objectWithoutPropertiesLoose(props, ["mask", "guide", "placeholderChar", "value", "showMask", "pipe", "render", "onChange"]);
|
|
30
|
+
|
|
31
|
+
var inputRef = useRef(null);
|
|
32
|
+
var textMaskInputElement = useRef();
|
|
33
|
+
var initTextMask = useCallback(function () {
|
|
34
|
+
var _textMaskInputElement;
|
|
35
|
+
|
|
36
|
+
textMaskInputElement.current = createTextMaskInputElement(_extends({
|
|
37
|
+
inputElement: inputRef.current
|
|
38
|
+
}, props));
|
|
39
|
+
(_textMaskInputElement = textMaskInputElement.current) === null || _textMaskInputElement === void 0 ? void 0 : _textMaskInputElement.update(value);
|
|
40
|
+
}, [props, value]);
|
|
41
|
+
var handleChange = useCallback(function (event) {
|
|
42
|
+
var _textMaskInputElement2;
|
|
43
|
+
|
|
44
|
+
(_textMaskInputElement2 = textMaskInputElement.current) === null || _textMaskInputElement2 === void 0 ? void 0 : _textMaskInputElement2.update();
|
|
45
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
46
|
+
}, [onChange]);
|
|
47
|
+
useEffect(function () {
|
|
48
|
+
initTextMask();
|
|
49
|
+
}, [guide, placeholderChar, showMask, pipe, mask, value, initTextMask]);
|
|
50
|
+
return render(mergeRefs(inputRef, ref), _extends({
|
|
51
|
+
onChange: handleChange,
|
|
52
|
+
defaultValue: value
|
|
53
|
+
}, omit(rest, ['keepCharPositions'])));
|
|
54
|
+
});
|
|
55
|
+
TextMask.displayName = 'TextMask';
|
|
56
|
+
TextMask.propTypes = {
|
|
57
|
+
render: PropTypes.func,
|
|
58
|
+
onChange: PropTypes.func,
|
|
59
|
+
mask: PropTypes.oneOfType([PropTypes.array, PropTypes.func, PropTypes.bool]).isRequired,
|
|
60
|
+
guide: PropTypes.bool,
|
|
61
|
+
value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
62
|
+
pipe: PropTypes.func,
|
|
63
|
+
placeholderChar: PropTypes.string,
|
|
64
|
+
keepCharPositions: PropTypes.bool,
|
|
65
|
+
showMask: PropTypes.bool
|
|
66
|
+
};
|
|
67
|
+
export default TextMask;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function adjustCaretPosition({ previousConformedValue, previousPlaceholder, currentCaretPosition, conformedValue, rawValue, placeholderChar, placeholder, indexesOfPipedChars, caretTrapIndexes }: {
|
|
2
|
+
previousConformedValue?: string;
|
|
3
|
+
previousPlaceholder?: string;
|
|
4
|
+
currentCaretPosition?: number;
|
|
5
|
+
conformedValue: any;
|
|
6
|
+
rawValue: any;
|
|
7
|
+
placeholderChar: any;
|
|
8
|
+
placeholder: any;
|
|
9
|
+
indexesOfPipedChars?: any[];
|
|
10
|
+
caretTrapIndexes?: any[];
|
|
11
|
+
}): number;
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
var defaultArray = [];
|
|
2
|
+
var emptyString = '';
|
|
3
|
+
export default function adjustCaretPosition(_ref) {
|
|
4
|
+
var _ref$previousConforme = _ref.previousConformedValue,
|
|
5
|
+
previousConformedValue = _ref$previousConforme === void 0 ? emptyString : _ref$previousConforme,
|
|
6
|
+
_ref$previousPlacehol = _ref.previousPlaceholder,
|
|
7
|
+
previousPlaceholder = _ref$previousPlacehol === void 0 ? emptyString : _ref$previousPlacehol,
|
|
8
|
+
_ref$currentCaretPosi = _ref.currentCaretPosition,
|
|
9
|
+
currentCaretPosition = _ref$currentCaretPosi === void 0 ? 0 : _ref$currentCaretPosi,
|
|
10
|
+
conformedValue = _ref.conformedValue,
|
|
11
|
+
rawValue = _ref.rawValue,
|
|
12
|
+
placeholderChar = _ref.placeholderChar,
|
|
13
|
+
placeholder = _ref.placeholder,
|
|
14
|
+
_ref$indexesOfPipedCh = _ref.indexesOfPipedChars,
|
|
15
|
+
indexesOfPipedChars = _ref$indexesOfPipedCh === void 0 ? defaultArray : _ref$indexesOfPipedCh,
|
|
16
|
+
_ref$caretTrapIndexes = _ref.caretTrapIndexes,
|
|
17
|
+
caretTrapIndexes = _ref$caretTrapIndexes === void 0 ? defaultArray : _ref$caretTrapIndexes;
|
|
18
|
+
|
|
19
|
+
if (currentCaretPosition === 0 || !rawValue.length) {
|
|
20
|
+
return 0;
|
|
21
|
+
} // Store lengths for faster performance?
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var rawValueLength = rawValue.length;
|
|
25
|
+
var previousConformedValueLength = previousConformedValue.length;
|
|
26
|
+
var placeholderLength = placeholder.length;
|
|
27
|
+
var conformedValueLength = conformedValue.length; // This tells us how long the edit is. If user modified input from `(2__)` to `(243__)`,
|
|
28
|
+
// we know the user in this instance pasted two characters
|
|
29
|
+
|
|
30
|
+
var editLength = rawValueLength - previousConformedValueLength; // If the edit length is positive, that means the user is adding characters, not deleting.
|
|
31
|
+
|
|
32
|
+
var isAddition = editLength > 0; // This is the first raw value the user entered that needs to be conformed to mask
|
|
33
|
+
|
|
34
|
+
var isFirstRawValue = previousConformedValueLength === 0; // A partial multi-character edit happens when the user makes a partial selection in their
|
|
35
|
+
// input and edits that selection. That is going from `(123) 432-4348` to `() 432-4348` by
|
|
36
|
+
// selecting the first 3 digits and pressing backspace.
|
|
37
|
+
//
|
|
38
|
+
// Such cases can also happen when the user presses the backspace while holding down the ALT
|
|
39
|
+
// key.
|
|
40
|
+
|
|
41
|
+
var isPartialMultiCharEdit = editLength > 1 && !isFirstRawValue; // This algorithm doesn't support all cases of multi-character edits, so we just return
|
|
42
|
+
// the current caret position.
|
|
43
|
+
//
|
|
44
|
+
// This works fine for most cases.
|
|
45
|
+
|
|
46
|
+
if (isPartialMultiCharEdit) {
|
|
47
|
+
return currentCaretPosition;
|
|
48
|
+
} // For a mask like (111), if the `previousConformedValue` is (1__) and user attempts to enter
|
|
49
|
+
// `f` so the `rawValue` becomes (1f__), the new `conformedValue` would be (1__), which is the
|
|
50
|
+
// same as the original `previousConformedValue`. We handle this case differently for caret
|
|
51
|
+
// positioning.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
var possiblyHasRejectedChar = isAddition && (previousConformedValue === conformedValue || conformedValue === placeholder);
|
|
55
|
+
var startingSearchIndex = 0;
|
|
56
|
+
var trackRightCharacter;
|
|
57
|
+
var targetChar;
|
|
58
|
+
|
|
59
|
+
if (possiblyHasRejectedChar) {
|
|
60
|
+
startingSearchIndex = currentCaretPosition - editLength;
|
|
61
|
+
} else {
|
|
62
|
+
// At this point in the algorithm, we want to know where the caret is right before the raw input
|
|
63
|
+
// has been conformed, and then see if we can find that same spot in the conformed input.
|
|
64
|
+
//
|
|
65
|
+
// We do that by seeing what character lies immediately before the caret, and then look for that
|
|
66
|
+
// same character in the conformed input and place the caret there.
|
|
67
|
+
// First, we need to normalize the inputs so that letter capitalization between raw input and
|
|
68
|
+
// conformed input wouldn't matter.
|
|
69
|
+
var normalizedConformedValue = conformedValue.toLowerCase();
|
|
70
|
+
var normalizedRawValue = rawValue.toLowerCase(); // Then we take all characters that come before where the caret currently is.
|
|
71
|
+
|
|
72
|
+
var leftHalfChars = normalizedRawValue.substr(0, currentCaretPosition).split(emptyString); // Now we find all the characters in the left half that exist in the conformed input
|
|
73
|
+
// This step ensures that we don't look for a character that was filtered out or rejected by `conformToMask`.
|
|
74
|
+
|
|
75
|
+
var intersection = leftHalfChars.filter(function (char) {
|
|
76
|
+
return normalizedConformedValue.indexOf(char) !== -1;
|
|
77
|
+
}); // The last character in the intersection is the character we want to look for in the conformed
|
|
78
|
+
// value and the one we want to adjust the caret close to
|
|
79
|
+
|
|
80
|
+
targetChar = intersection[intersection.length - 1]; // Calculate the number of mask characters in the previous placeholder
|
|
81
|
+
// from the start of the string up to the place where the caret is
|
|
82
|
+
|
|
83
|
+
var previousLeftMaskChars = previousPlaceholder.substr(0, intersection.length).split(emptyString).filter(function (char) {
|
|
84
|
+
return char !== placeholderChar;
|
|
85
|
+
}).length; // Calculate the number of mask characters in the current placeholder
|
|
86
|
+
// from the start of the string up to the place where the caret is
|
|
87
|
+
|
|
88
|
+
var leftMaskChars = placeholder.substr(0, intersection.length).split(emptyString).filter(function (char) {
|
|
89
|
+
return char !== placeholderChar;
|
|
90
|
+
}).length; // Has the number of mask characters up to the caret changed?
|
|
91
|
+
|
|
92
|
+
var masklengthChanged = leftMaskChars !== previousLeftMaskChars; // Detect if `targetChar` is a mask character and has moved to the left
|
|
93
|
+
|
|
94
|
+
var targetIsMaskMovingLeft = previousPlaceholder[intersection.length - 1] !== undefined && placeholder[intersection.length - 2] !== undefined && previousPlaceholder[intersection.length - 1] !== placeholderChar && previousPlaceholder[intersection.length - 1] !== placeholder[intersection.length - 1] && previousPlaceholder[intersection.length - 1] === placeholder[intersection.length - 2]; // If deleting and the `targetChar` `is a mask character and `masklengthChanged` is true
|
|
95
|
+
// or the mask is moving to the left, we can't use the selected `targetChar` any longer
|
|
96
|
+
// if we are not at the end of the string.
|
|
97
|
+
// In this case, change tracking strategy and track the character to the right of the caret.
|
|
98
|
+
|
|
99
|
+
if (!isAddition && (masklengthChanged || targetIsMaskMovingLeft) && previousLeftMaskChars > 0 && placeholder.indexOf(targetChar) > -1 && rawValue[currentCaretPosition] !== undefined) {
|
|
100
|
+
trackRightCharacter = true;
|
|
101
|
+
targetChar = rawValue[currentCaretPosition];
|
|
102
|
+
} // It is possible that `targetChar` will appear multiple times in the conformed value.
|
|
103
|
+
// We need to know not to select a character that looks like our target character from the placeholder or
|
|
104
|
+
// the piped characters, so we inspect the piped characters and the placeholder to see if they contain
|
|
105
|
+
// characters that match our target character.
|
|
106
|
+
// If the `conformedValue` got piped, we need to know which characters were piped in so that when we look for
|
|
107
|
+
// our `targetChar`, we don't select a piped char by mistake
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
var pipedChars = indexesOfPipedChars.map(function (index) {
|
|
111
|
+
return normalizedConformedValue[index];
|
|
112
|
+
}); // We need to know how many times the `targetChar` occurs in the piped characters.
|
|
113
|
+
|
|
114
|
+
var countTargetCharInPipedChars = pipedChars.filter(function (char) {
|
|
115
|
+
return char === targetChar;
|
|
116
|
+
}).length; // We need to know how many times it occurs in the intersection
|
|
117
|
+
|
|
118
|
+
var countTargetCharInIntersection = intersection.filter(function (char) {
|
|
119
|
+
return char === targetChar;
|
|
120
|
+
}).length; // We need to know if the placeholder contains characters that look like
|
|
121
|
+
// our `targetChar`, so we don't select one of those by mistake.
|
|
122
|
+
|
|
123
|
+
var countTargetCharInPlaceholder = placeholder.substr(0, placeholder.indexOf(placeholderChar)).split(emptyString).filter(function (char, index) {
|
|
124
|
+
return (// Check if `char` is the same as our `targetChar`, so we account for it
|
|
125
|
+
char === targetChar && // but also make sure that both the `rawValue` and placeholder don't have the same character at the same
|
|
126
|
+
// index because if they are equal, that means we are already counting those characters in
|
|
127
|
+
// `countTargetCharInIntersection`
|
|
128
|
+
rawValue[index] !== char
|
|
129
|
+
);
|
|
130
|
+
}).length; // The number of times we need to see occurrences of the `targetChar` before we know it is the one we're looking
|
|
131
|
+
// for is:
|
|
132
|
+
|
|
133
|
+
var requiredNumberOfMatches = countTargetCharInPlaceholder + countTargetCharInIntersection + countTargetCharInPipedChars + ( // The character to the right of the caret isn't included in `intersection`
|
|
134
|
+
// so add one if we are tracking the character to the right
|
|
135
|
+
trackRightCharacter ? 1 : 0); // Now we start looking for the location of the `targetChar`.
|
|
136
|
+
// We keep looping forward and store the index in every iteration. Once we have encountered
|
|
137
|
+
// enough occurrences of the target character, we break out of the loop
|
|
138
|
+
// If are searching for the second `1` in `1214`, `startingSearchIndex` will point at `4`.
|
|
139
|
+
|
|
140
|
+
var numberOfEncounteredMatches = 0;
|
|
141
|
+
|
|
142
|
+
for (var i = 0; i < conformedValueLength; i++) {
|
|
143
|
+
var conformedValueChar = normalizedConformedValue[i];
|
|
144
|
+
startingSearchIndex = i + 1;
|
|
145
|
+
|
|
146
|
+
if (conformedValueChar === targetChar) {
|
|
147
|
+
numberOfEncounteredMatches++;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (numberOfEncounteredMatches >= requiredNumberOfMatches) {
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} // At this point, if we simply return `startingSearchIndex` as the adjusted caret position,
|
|
155
|
+
// most cases would be handled. However, we want to fast forward or rewind the caret to the
|
|
156
|
+
// closest placeholder character if it happens to be in a non-editable spot. That's what the next
|
|
157
|
+
// logic is for.
|
|
158
|
+
// In case of addition, we fast forward.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if (isAddition) {
|
|
162
|
+
// We want to remember the last placeholder character encountered so that if the mask
|
|
163
|
+
// contains more characters after the last placeholder character, we don't forward the caret
|
|
164
|
+
// that far to the right. Instead, we stop it at the last encountered placeholder character.
|
|
165
|
+
var lastPlaceholderChar = startingSearchIndex;
|
|
166
|
+
|
|
167
|
+
for (var _i = startingSearchIndex; _i <= placeholderLength; _i++) {
|
|
168
|
+
if (placeholder[_i] === placeholderChar) {
|
|
169
|
+
lastPlaceholderChar = _i;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if ( // If we're adding, we can position the caret at the next placeholder character.
|
|
173
|
+
placeholder[_i] === placeholderChar || // If a caret trap was set by a mask function, we need to stop at the trap.
|
|
174
|
+
caretTrapIndexes.indexOf(_i) !== -1 || // This is the end of the placeholder. We cannot move any further. Let's put the caret there.
|
|
175
|
+
_i === placeholderLength) {
|
|
176
|
+
return lastPlaceholderChar;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
// In case of deletion, we rewind.
|
|
181
|
+
if (trackRightCharacter) {
|
|
182
|
+
// Searching for the character that was to the right of the caret
|
|
183
|
+
// We start at `startingSearchIndex` - 1 because it includes one character extra to the right
|
|
184
|
+
for (var _i2 = startingSearchIndex - 1; _i2 >= 0; _i2--) {
|
|
185
|
+
// If tracking the character to the right of the cursor, we move to the left until
|
|
186
|
+
// we found the character and then place the caret right before it
|
|
187
|
+
if ( // `targetChar` should be in `conformedValue`, since it was in `rawValue`, just
|
|
188
|
+
// to the right of the caret
|
|
189
|
+
conformedValue[_i2] === targetChar || // If a caret trap was set by a mask function, we need to stop at the trap.
|
|
190
|
+
caretTrapIndexes.indexOf(_i2) !== -1 || // This is the beginning of the placeholder. We cannot move any further.
|
|
191
|
+
// Let's put the caret there.
|
|
192
|
+
_i2 === 0) {
|
|
193
|
+
return _i2;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
// Searching for the first placeholder or caret trap to the left
|
|
198
|
+
for (var _i3 = startingSearchIndex; _i3 >= 0; _i3--) {
|
|
199
|
+
// If we're deleting, we stop the caret right before the placeholder character.
|
|
200
|
+
// For example, for mask `(111) 11`, current conformed input `(456) 86`. If user
|
|
201
|
+
// modifies input to `(456 86`. That is, they deleted the `)`, we place the caret
|
|
202
|
+
// right after the first `6`
|
|
203
|
+
if ( // If we're deleting, we can position the caret right before the placeholder character
|
|
204
|
+
placeholder[_i3 - 1] === placeholderChar || // If a caret trap was set by a mask function, we need to stop at the trap.
|
|
205
|
+
caretTrapIndexes.indexOf(_i3) !== -1 || // This is the beginning of the placeholder. We cannot move any further.
|
|
206
|
+
// Let's put the caret there.
|
|
207
|
+
_i3 === 0) {
|
|
208
|
+
return _i3;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MaskType, ConfigType, MaskFunctionType } from './types';
|
|
2
|
+
export declare function isArray(value: any): boolean;
|
|
3
|
+
export default function conformToMask(rawValue?: string, mask?: MaskType | MaskFunctionType, config?: ConfigType): {
|
|
4
|
+
conformedValue: string;
|
|
5
|
+
meta: {
|
|
6
|
+
someCharsRejected: boolean;
|
|
7
|
+
};
|
|
8
|
+
};
|