intelicoreact 0.1.30 → 0.1.31
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.
|
@@ -37,10 +37,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
37
37
|
|
|
38
38
|
var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
39
39
|
var isSelect = _ref.isSelect,
|
|
40
|
-
onChange = _ref.onChange,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
_ref$onChange = _ref.onChange,
|
|
41
|
+
onChange = _ref$onChange === void 0 ? function () {} : _ref$onChange,
|
|
42
|
+
_ref$onBlur = _ref.onBlur,
|
|
43
|
+
onBlur = _ref$onBlur === void 0 ? function () {} : _ref$onBlur,
|
|
44
|
+
_ref$onFocus = _ref.onFocus,
|
|
45
|
+
onFocus = _ref$onFocus === void 0 ? function () {} : _ref$onFocus,
|
|
46
|
+
_ref$onKeyUp = _ref.onKeyUp,
|
|
47
|
+
onKeyUp = _ref$onKeyUp === void 0 ? function () {} : _ref$onKeyUp,
|
|
48
|
+
_ref$onKeyDown = _ref.onKeyDown,
|
|
49
|
+
onKeyDown = _ref$onKeyDown === void 0 ? function () {} : _ref$onKeyDown,
|
|
44
50
|
isNotBlinkErrors = _ref.isNotBlinkErrors,
|
|
45
51
|
isPriceInput = _ref.isPriceInput,
|
|
46
52
|
onlyNumbers = _ref.onlyNumbers,
|
|
@@ -64,7 +70,9 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
64
70
|
_ref$isFocusDefault = _ref.isFocusDefault,
|
|
65
71
|
isFocusDefault = _ref$isFocusDefault === void 0 ? false : _ref$isFocusDefault,
|
|
66
72
|
_ref$isNotValidateASC = _ref.isNotValidateASCII,
|
|
67
|
-
isNotValidateASCII = _ref$isNotValidateASC === void 0 ? false : _ref$isNotValidateASC
|
|
73
|
+
isNotValidateASCII = _ref$isNotValidateASC === void 0 ? false : _ref$isNotValidateASC,
|
|
74
|
+
_ref$isNumericMobileK = _ref.isNumericMobileKeyboard,
|
|
75
|
+
isNumericMobileKeyboard = _ref$isNumericMobileK === void 0 ? false : _ref$isNumericMobileK;
|
|
68
76
|
var DEFAULT_BLINK_TIME = 100; // STATES
|
|
69
77
|
|
|
70
78
|
var _useState = (0, _react.useState)(false),
|
|
@@ -98,6 +106,11 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
98
106
|
onInputHover = _useState10[0],
|
|
99
107
|
setOnInputHover = _useState10[1];
|
|
100
108
|
|
|
109
|
+
var _useState11 = (0, _react.useState)(value),
|
|
110
|
+
_useState12 = (0, _slicedToArray2.default)(_useState11, 2),
|
|
111
|
+
prevValue = _useState12[0],
|
|
112
|
+
setPreviousValue = _useState12[1];
|
|
113
|
+
|
|
101
114
|
var isUseBitDepthPoints = !!onlyNumbers && isPriceInput;
|
|
102
115
|
var isUseErrorsBlink = !isNotBlinkErrors && !mask; // HANDLES
|
|
103
116
|
|
|
@@ -116,7 +129,7 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
116
129
|
focus: function focus(e) {
|
|
117
130
|
setIsFocused(true);
|
|
118
131
|
if (onlyNumbers) onChange((0, _fieldValueFormatters.formatToRemoveComa)(value));
|
|
119
|
-
|
|
132
|
+
onFocus(e);
|
|
120
133
|
},
|
|
121
134
|
blur: function blur(e) {
|
|
122
135
|
setIsFocused(false);
|
|
@@ -127,12 +140,17 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
127
140
|
if (onlyNumbers || isUseBitDepthPoints) onChange(value);
|
|
128
141
|
if (onBlur) onBlur(e);
|
|
129
142
|
},
|
|
143
|
+
keyDown: function keyDown(e) {
|
|
144
|
+
var _e$target;
|
|
145
|
+
|
|
146
|
+
setPreviousValue(e === null || e === void 0 ? void 0 : (_e$target = e.target) === null || _e$target === void 0 ? void 0 : _e$target.value);
|
|
147
|
+
onKeyDown(e.keyCode, e);
|
|
148
|
+
},
|
|
130
149
|
keyUp: function keyUp(e) {
|
|
131
150
|
if (isUseErrorsBlink) {
|
|
132
|
-
var
|
|
151
|
+
var changedValue = '' + (value !== null && value !== void 0 ? value : ''); // const previousValue = '' + (previousValueRef.current ?? '');
|
|
133
152
|
|
|
134
|
-
var
|
|
135
|
-
var previousValue = '' + ((_previousValueRef$cur = previousValueRef.current) !== null && _previousValueRef$cur !== void 0 ? _previousValueRef$cur : '');
|
|
153
|
+
var previousValue = '' + prevValue;
|
|
136
154
|
var short = previousValue.length <= changedValue.length ? previousValue : changedValue;
|
|
137
155
|
var long = previousValue.length > changedValue.length ? previousValue : changedValue;
|
|
138
156
|
var infoAboutDifferencesSameness = short.split('').reduce(function (acc, symbol, idx) {
|
|
@@ -148,32 +166,63 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
148
166
|
});
|
|
149
167
|
var samePart = infoAboutDifferencesSameness.same.join('');
|
|
150
168
|
var differencesLength = infoAboutDifferencesSameness.differences.length;
|
|
151
|
-
var currentSet = changedValue.replace(samePart, '');
|
|
169
|
+
var currentSet = changedValue.replace(samePart, ''); /// ????????????????
|
|
170
|
+
// const getNext = (inputPartToAdd, correctedSamePart) => {
|
|
171
|
+
// const partToAdd = inputPartToAdd || currentSet;
|
|
172
|
+
// const currentSamePart = correctedSamePart || samePart;
|
|
173
|
+
// return changedValue.includes(e.key) && e.key !== changedValue[changedValue.length - 1]
|
|
174
|
+
// ? currentSamePart + (partToAdd[0] || '')
|
|
175
|
+
// : changedValue;
|
|
176
|
+
// };
|
|
177
|
+
/// ????????????????
|
|
178
|
+
|
|
179
|
+
if (!_index.KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) {
|
|
180
|
+
setIsAttemptToChange(!(!differencesLength && e.key === currentSet));
|
|
181
|
+
} /// ????????????????
|
|
182
|
+
// if (!previousValueRef.current || KEYBOARD_SERVICE_KEYS.includes(e.key)) previousValueRef.current = getNext();
|
|
183
|
+
// else if (changedValue === samePart) previousValueRef.current = getNext(changedValue, changedValue.slice(0, -1));
|
|
184
|
+
// else previousValueRef.current = getNext();
|
|
185
|
+
/// ????????????????
|
|
152
186
|
|
|
153
|
-
var getNext = function getNext(inputPartToAdd, correctedSamePart) {
|
|
154
|
-
var partToAdd = inputPartToAdd || currentSet;
|
|
155
|
-
var currentSamePart = correctedSamePart || samePart;
|
|
156
|
-
return changedValue.includes(e.key) && e.key !== changedValue[changedValue.length - 1] ? currentSamePart + (partToAdd[0] || '') : changedValue;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
if (!_index.KEYBOARD_SERVICE_KEYS.includes(e.key) && changedValue === previousValue) setIsAttemptToChange(!(!differencesLength && e.key === changedValue[changedValue.length - 2]));
|
|
160
|
-
if (!previousValueRef.current || _index.KEYBOARD_SERVICE_KEYS.includes(e.key)) previousValueRef.current = getNext();else if (changedValue === samePart) previousValueRef.current = getNext(changedValue, changedValue.slice(0, -1));else previousValueRef.current = getNext();
|
|
161
187
|
}
|
|
162
188
|
|
|
163
|
-
|
|
189
|
+
onKeyUp(e.keyCode, e);
|
|
164
190
|
}
|
|
165
191
|
};
|
|
192
|
+
(0, _react.useEffect)(function () {
|
|
193
|
+
var _inputRef$current, _inputRef$current$foc;
|
|
194
|
+
|
|
195
|
+
if (isEditing) inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : (_inputRef$current$foc = _inputRef$current.focus) === null || _inputRef$current$foc === void 0 ? void 0 : _inputRef$current$foc.call(_inputRef$current);
|
|
196
|
+
}, [isEditing, isFocused]);
|
|
197
|
+
(0, _react.useEffect)(function () {
|
|
198
|
+
setEditing(isSelect !== null && isSelect !== void 0 ? isSelect : false);
|
|
199
|
+
}, [isSelect]);
|
|
200
|
+
(0, _react.useEffect)(function () {
|
|
201
|
+
if (isUseErrorsBlink && isAttemptToChange) {
|
|
202
|
+
setIsAttemptToChange(null);
|
|
203
|
+
setIsToHighlightError(true);
|
|
204
|
+
setTimeout(function () {
|
|
205
|
+
setIsToHighlightError(false);
|
|
206
|
+
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
207
|
+
}
|
|
208
|
+
}, [isAttemptToChange]);
|
|
209
|
+
(0, _react.useEffect)(function () {
|
|
210
|
+
if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
211
|
+
setEditing(isFocusDefault);
|
|
212
|
+
}, [inputRef, isFocusDefault]);
|
|
166
213
|
|
|
167
214
|
function renderInput() {
|
|
168
215
|
var uniProps = _objectSpread(_objectSpread({
|
|
169
216
|
className: "input ".concat(className),
|
|
170
217
|
placeholder: placeholder,
|
|
171
218
|
value: value || '',
|
|
219
|
+
inputmode: isNumericMobileKeyboard ? "numeric" : "none",
|
|
172
220
|
disabled: disabled,
|
|
173
221
|
onChange: handle.change,
|
|
174
222
|
onFocus: handle.focus,
|
|
175
223
|
onBlur: handle.blur,
|
|
176
|
-
onKeyUp: handle.keyUp
|
|
224
|
+
onKeyUp: handle.keyUp,
|
|
225
|
+
onKeyDown: handle.keyDown
|
|
177
226
|
}, maskChar ? {
|
|
178
227
|
maskChar: maskChar
|
|
179
228
|
} : {}), formatChars ? {
|
|
@@ -193,27 +242,6 @@ var Input = /*#__PURE__*/_react.default.forwardRef(function (_ref, ref) {
|
|
|
193
242
|
}));
|
|
194
243
|
}
|
|
195
244
|
|
|
196
|
-
(0, _react.useEffect)(function () {
|
|
197
|
-
var _inputRef$current, _inputRef$current$foc;
|
|
198
|
-
|
|
199
|
-
if (isEditing) inputRef === null || inputRef === void 0 ? void 0 : (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : (_inputRef$current$foc = _inputRef$current.focus) === null || _inputRef$current$foc === void 0 ? void 0 : _inputRef$current$foc.call(_inputRef$current);
|
|
200
|
-
}, [isEditing, isFocused]);
|
|
201
|
-
(0, _react.useEffect)(function () {
|
|
202
|
-
setEditing(isSelect !== null && isSelect !== void 0 ? isSelect : false);
|
|
203
|
-
}, [isSelect]);
|
|
204
|
-
(0, _react.useEffect)(function () {
|
|
205
|
-
if (isUseErrorsBlink && isAttemptToChange) {
|
|
206
|
-
setIsAttemptToChange(null);
|
|
207
|
-
setIsToHighlightError(true);
|
|
208
|
-
setTimeout(function () {
|
|
209
|
-
setIsToHighlightError(false);
|
|
210
|
-
}, blinkTime || DEFAULT_BLINK_TIME);
|
|
211
|
-
}
|
|
212
|
-
}, [isAttemptToChange]);
|
|
213
|
-
(0, _react.useEffect)(function () {
|
|
214
|
-
if (inputRef !== null && inputRef !== void 0 && inputRef.current && typeof isFocusDefault === 'boolean') setIsFocused(isFocusDefault);
|
|
215
|
-
setEditing(isFocusDefault);
|
|
216
|
-
}, [inputRef, isFocusDefault]);
|
|
217
245
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
218
246
|
className: (0, _classnames.default)("input__wrap", (0, _defineProperty2.default)({}, "input__wrap_focus", isFocused), (0, _defineProperty2.default)({}, "input__wrap_error", error || isToHighlightError), (0, _defineProperty2.default)({}, "input__wrap_disabled", disabled)),
|
|
219
247
|
onMouseEnter: function onMouseEnter() {
|
|
@@ -88,6 +88,11 @@ var _default = {
|
|
|
88
88
|
},
|
|
89
89
|
onKeyUp: {
|
|
90
90
|
description: 'custom callback on keyup, returns event keyCode'
|
|
91
|
+
},
|
|
92
|
+
isNumericMobileKeyboard: {
|
|
93
|
+
description: 'Enable Mobile Numeric Keyboard',
|
|
94
|
+
type: 'boolean',
|
|
95
|
+
default: false
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
};
|
|
@@ -129,5 +134,6 @@ InputTemplate.args = {
|
|
|
129
134
|
withDelete: true,
|
|
130
135
|
symbolsLimit: 255,
|
|
131
136
|
placeholder: 'Placeholder',
|
|
132
|
-
icon: /*#__PURE__*/_react.default.createElement(_reactFeather.User, null)
|
|
137
|
+
icon: /*#__PURE__*/_react.default.createElement(_reactFeather.User, null),
|
|
138
|
+
isNumericMobileKeyboard: false
|
|
133
139
|
};
|