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
@@ -46,7 +46,7 @@ declare const DOMHelper: {
46
46
  } | DOMRect;
47
47
  nodeName: (node: Element) => string;
48
48
  getOffsetParent: (node: Element) => Element;
49
- getPosition: (node: Element, offsetParent?: Element) => DOMRect | {
49
+ getPosition: (node: Element, offsetParent?: Element, calcMargin?: boolean) => DOMRect | {
50
50
  top: number;
51
51
  left: number;
52
52
  height: number;
@@ -301,7 +301,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
301
301
  * The callback after the enter key is triggered on the input
302
302
  */
303
303
 
304
- var handleInputBlur = useCallback(function (event) {
304
+ var handleInputPressEnd = useCallback(function (event) {
305
305
  if (inputState === 'Typing') {
306
306
  updateValue(event, calendarDate);
307
307
  }
@@ -430,7 +430,8 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
430
430
  inputPlaceholder: typeof placeholder === 'string' && placeholder ? placeholder : formatStr,
431
431
  inputMask: DateUtils.getDateMask(formatStr),
432
432
  onInputChange: handleInputChange,
433
- onInputBlur: handleInputBlur,
433
+ onInputBlur: handleInputPressEnd,
434
+ onInputPressEnter: handleInputPressEnd,
434
435
  onKeyDown: onPickerKeyDown,
435
436
  onClean: createChainedFunction(handleClean, onClean),
436
437
  cleanable: cleanable && !disabled,
@@ -400,7 +400,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
400
400
  * The callback after the enter key is triggered on the input
401
401
  */
402
402
 
403
- var handleInputBlur = useCallback(function (event) {
403
+ var handleInputPressEnd = useCallback(function (event) {
404
404
  if (inputState === 'Typing') {
405
405
  handleValueUpdate(event, selectValue);
406
406
  }
@@ -578,7 +578,8 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
578
578
  inputValue: value ? getDisplayString(value, true) : '',
579
579
  inputPlaceholder: typeof placeholder === 'string' && placeholder ? placeholder : rangeFormatStr,
580
580
  onInputChange: handleInputChange,
581
- onInputBlur: handleInputBlur,
581
+ onInputBlur: handleInputPressEnd,
582
+ onInputPressEnter: handleInputPressEnd,
582
583
  onKeyDown: onPickerKeyDown,
583
584
  onClean: createChainedFunction(handleClean, onClean),
584
585
  cleanable: cleanable && !disabled,
@@ -29,7 +29,13 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
29
29
  eventKey = props.eventKey,
30
30
  onSelect = props.onSelect,
31
31
  icon = props.icon,
32
- rest = _objectWithoutPropertiesLoose(props, ["classPrefix", "className", "active", "eventKey", "onSelect", "icon"]);
32
+ _props$as = props.as,
33
+ Component = _props$as === void 0 ? 'li' : _props$as,
34
+ divider = props.divider,
35
+ panel = props.panel,
36
+ children = props.children,
37
+ disabled = props.disabled,
38
+ restProps = _objectWithoutPropertiesLoose(props, ["classPrefix", "className", "active", "eventKey", "onSelect", "icon", "as", "divider", "panel", "children", "disabled"]);
33
39
 
34
40
  var internalId = useInternalId('DropdownItem');
35
41
  var nav = useContext(NavContext);
@@ -82,6 +88,15 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
82
88
  };
83
89
  }
84
90
  }, [internalId, selected, dispatch]);
91
+ var renderDropdownItem = useCallback(function (ui) {
92
+ if (Component === 'li') {
93
+ return ui;
94
+ }
95
+
96
+ return /*#__PURE__*/React.createElement("li", {
97
+ role: "none presentation"
98
+ }, ui);
99
+ }, [Component]);
85
100
 
86
101
  if (sidenav !== null && sidenav !== void 0 && sidenav.expanded) {
87
102
  return /*#__PURE__*/React.createElement(SidenavDropdownItem, _extends({
@@ -89,28 +104,19 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
89
104
  }, props));
90
105
  }
91
106
 
92
- var _rest$as = rest.as,
93
- Component = _rest$as === void 0 ? 'li' : _rest$as,
94
- divider = rest.divider,
95
- panel = rest.panel,
96
- children = rest.children,
97
- disabled = rest.disabled,
98
- restProps = _objectWithoutPropertiesLoose(rest, ["as", "divider", "panel", "children", "disabled"]);
99
-
100
107
  if (divider) {
101
- return /*#__PURE__*/React.createElement(Component, _extends({
108
+ return renderDropdownItem( /*#__PURE__*/React.createElement(Component, _extends({
102
109
  ref: ref,
103
110
  role: "separator",
104
111
  className: merge(prefix('divider'), className)
105
- }, restProps));
112
+ }, restProps)));
106
113
  }
107
114
 
108
115
  if (panel) {
109
- return /*#__PURE__*/React.createElement(Component, _extends({
116
+ return renderDropdownItem( /*#__PURE__*/React.createElement(Component, _extends({
110
117
  ref: ref,
111
- role: "none presentation",
112
118
  className: merge(prefix('panel'), className)
113
- }, restProps), children);
119
+ }, restProps), children));
114
120
  }
115
121
 
116
122
  if (navbar) {
@@ -134,6 +140,7 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
134
140
  className: classes,
135
141
  "aria-current": selected || undefined
136
142
  }, dataAttributes, restProps, {
143
+ as: Component,
137
144
  onClick: createChainedFunction(handleClickNavbarDropdownItem, restProps.onClick)
138
145
  }), icon && /*#__PURE__*/React.cloneElement(icon, {
139
146
  className: prefix('menu-icon')
@@ -165,12 +172,12 @@ var DropdownItem = /*#__PURE__*/React.forwardRef(function (props, ref) {
165
172
  dataAttributes['data-event-key-type'] = typeof eventKey;
166
173
  }
167
174
 
168
- return /*#__PURE__*/React.createElement(Component, _extends({
175
+ return renderDropdownItem( /*#__PURE__*/React.createElement(Component, _extends({
169
176
  ref: mergeRefs(ref, menuitemRef),
170
177
  className: classes
171
178
  }, menuitem, dataAttributes, restProps), icon && /*#__PURE__*/React.cloneElement(icon, {
172
179
  className: prefix('menu-icon')
173
- }), children);
180
+ }), children));
174
181
  });
175
182
  });
176
183
  DropdownItem.displayName = 'Dropdown.Item';
@@ -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 TextMaskProps {
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 MaskedInputProps = TextMaskProps & 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 MaskedInput: React.ForwardRefExoticComponent<TextMaskProps & 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 MaskedInput;
@@ -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 MaskedInput = /*#__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
+ MaskedInput.displayName = 'MaskedInput';
56
+ MaskedInput.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 MaskedInput;
@@ -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
+ };