@steroidsjs/core 3.0.89 → 3.0.90
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/docs-autogen-result.json +167 -0
- package/en.json +2 -0
- package/hooks/useSaveCursorPosition.d.ts +16 -3
- package/hooks/useSaveCursorPosition.js +50 -15
- package/package.json +1 -1
- package/ui/form/EmailField/EmailField.js +3 -1
- package/ui/form/InputField/InputField.d.ts +5 -0
- package/ui/form/InputField/InputField.js +8 -6
- package/ui/form/NumberField/NumberField.d.ts +5 -0
- package/ui/form/NumberField/NumberField.js +8 -6
- package/ui/form/PasswordField/PasswordField.js +1 -1
- package/ui/form/TextField/TextField.js +3 -1
- package/ui/modal/Modal/Modal.d.ts +4 -0
- package/ui/modal/Modal/Modal.js +3 -3
package/docs-autogen-result.json
CHANGED
|
@@ -4365,6 +4365,81 @@
|
|
|
4365
4365
|
],
|
|
4366
4366
|
"methods": []
|
|
4367
4367
|
},
|
|
4368
|
+
"ISaveCursorPositionConfig": {
|
|
4369
|
+
"name": "ISaveCursorPositionConfig",
|
|
4370
|
+
"moduleName": "hooks/useSaveCursorPosition",
|
|
4371
|
+
"title": "",
|
|
4372
|
+
"description": "",
|
|
4373
|
+
"tags": {},
|
|
4374
|
+
"defaultProps": null,
|
|
4375
|
+
"extends": [],
|
|
4376
|
+
"properties": [
|
|
4377
|
+
{
|
|
4378
|
+
"name": "debounce",
|
|
4379
|
+
"decorators": [],
|
|
4380
|
+
"description": "",
|
|
4381
|
+
"required": false,
|
|
4382
|
+
"type": "ISaveCursorPositionDebounceConfig",
|
|
4383
|
+
"example": null
|
|
4384
|
+
},
|
|
4385
|
+
{
|
|
4386
|
+
"name": "inputParams",
|
|
4387
|
+
"decorators": [],
|
|
4388
|
+
"description": "",
|
|
4389
|
+
"required": true,
|
|
4390
|
+
"type": "IInputParams",
|
|
4391
|
+
"example": null
|
|
4392
|
+
}
|
|
4393
|
+
],
|
|
4394
|
+
"methods": [
|
|
4395
|
+
{
|
|
4396
|
+
"name": "onChangeCallback",
|
|
4397
|
+
"decorators": [],
|
|
4398
|
+
"description": "",
|
|
4399
|
+
"required": false,
|
|
4400
|
+
"type": "void",
|
|
4401
|
+
"example": null,
|
|
4402
|
+
"parameters": [
|
|
4403
|
+
{
|
|
4404
|
+
"name": "value",
|
|
4405
|
+
"decorators": [],
|
|
4406
|
+
"description": "",
|
|
4407
|
+
"required": true,
|
|
4408
|
+
"type": "any",
|
|
4409
|
+
"example": null
|
|
4410
|
+
}
|
|
4411
|
+
]
|
|
4412
|
+
}
|
|
4413
|
+
]
|
|
4414
|
+
},
|
|
4415
|
+
"ISaveCursorPositionDebounceConfig": {
|
|
4416
|
+
"name": "ISaveCursorPositionDebounceConfig",
|
|
4417
|
+
"moduleName": "hooks/useSaveCursorPosition",
|
|
4418
|
+
"title": "",
|
|
4419
|
+
"description": "",
|
|
4420
|
+
"tags": {},
|
|
4421
|
+
"defaultProps": null,
|
|
4422
|
+
"extends": [],
|
|
4423
|
+
"properties": [
|
|
4424
|
+
{
|
|
4425
|
+
"name": "delayMs",
|
|
4426
|
+
"decorators": [],
|
|
4427
|
+
"description": "Задержка в мс",
|
|
4428
|
+
"required": false,
|
|
4429
|
+
"type": "number",
|
|
4430
|
+
"example": null
|
|
4431
|
+
},
|
|
4432
|
+
{
|
|
4433
|
+
"name": "enabled",
|
|
4434
|
+
"decorators": [],
|
|
4435
|
+
"description": "",
|
|
4436
|
+
"required": true,
|
|
4437
|
+
"type": "boolean",
|
|
4438
|
+
"example": null
|
|
4439
|
+
}
|
|
4440
|
+
],
|
|
4441
|
+
"methods": []
|
|
4442
|
+
},
|
|
4368
4443
|
"IPreparedTreeItem": {
|
|
4369
4444
|
"name": "IPreparedTreeItem",
|
|
4370
4445
|
"moduleName": "hooks/useTree",
|
|
@@ -7496,6 +7571,14 @@
|
|
|
7496
7571
|
"required": false,
|
|
7497
7572
|
"type": "React.ReactNode | {}",
|
|
7498
7573
|
"example": "MyCustomView"
|
|
7574
|
+
},
|
|
7575
|
+
{
|
|
7576
|
+
"name": "viewProps",
|
|
7577
|
+
"decorators": [],
|
|
7578
|
+
"description": "Свойства для view компонента",
|
|
7579
|
+
"required": false,
|
|
7580
|
+
"type": "any",
|
|
7581
|
+
"example": null
|
|
7499
7582
|
}
|
|
7500
7583
|
],
|
|
7501
7584
|
"methods": [
|
|
@@ -7709,6 +7792,14 @@
|
|
|
7709
7792
|
"required": false,
|
|
7710
7793
|
"type": "React.ReactNode | {}",
|
|
7711
7794
|
"example": "MyCustomView"
|
|
7795
|
+
},
|
|
7796
|
+
{
|
|
7797
|
+
"name": "viewProps",
|
|
7798
|
+
"decorators": [],
|
|
7799
|
+
"description": "Свойства для view компонента",
|
|
7800
|
+
"required": false,
|
|
7801
|
+
"type": "any",
|
|
7802
|
+
"example": null
|
|
7712
7803
|
}
|
|
7713
7804
|
],
|
|
7714
7805
|
"methods": [
|
|
@@ -11243,6 +11334,14 @@
|
|
|
11243
11334
|
"required": false,
|
|
11244
11335
|
"type": "React.ReactNode | {}",
|
|
11245
11336
|
"example": "MyCustomView"
|
|
11337
|
+
},
|
|
11338
|
+
{
|
|
11339
|
+
"name": "viewProps",
|
|
11340
|
+
"decorators": [],
|
|
11341
|
+
"description": "Свойства для view компонента",
|
|
11342
|
+
"required": false,
|
|
11343
|
+
"type": "any",
|
|
11344
|
+
"example": null
|
|
11246
11345
|
}
|
|
11247
11346
|
],
|
|
11248
11347
|
"methods": [
|
|
@@ -11743,6 +11842,14 @@
|
|
|
11743
11842
|
"required": false,
|
|
11744
11843
|
"type": "React.ReactNode | {}",
|
|
11745
11844
|
"example": "MyCustomView"
|
|
11845
|
+
},
|
|
11846
|
+
{
|
|
11847
|
+
"name": "viewProps",
|
|
11848
|
+
"decorators": [],
|
|
11849
|
+
"description": "Свойства для view компонента",
|
|
11850
|
+
"required": false,
|
|
11851
|
+
"type": "any",
|
|
11852
|
+
"example": null
|
|
11746
11853
|
}
|
|
11747
11854
|
],
|
|
11748
11855
|
"methods": [
|
|
@@ -24544,6 +24651,14 @@
|
|
|
24544
24651
|
"required": false,
|
|
24545
24652
|
"type": "React.ReactNode | {}",
|
|
24546
24653
|
"example": "MyCustomView"
|
|
24654
|
+
},
|
|
24655
|
+
{
|
|
24656
|
+
"name": "viewProps",
|
|
24657
|
+
"decorators": [],
|
|
24658
|
+
"description": "Свойства для view компонента",
|
|
24659
|
+
"required": false,
|
|
24660
|
+
"type": "any",
|
|
24661
|
+
"example": null
|
|
24547
24662
|
}
|
|
24548
24663
|
],
|
|
24549
24664
|
"methods": [
|
|
@@ -25512,6 +25627,15 @@
|
|
|
25512
25627
|
"example": null,
|
|
25513
25628
|
"defaultValue": null
|
|
25514
25629
|
},
|
|
25630
|
+
{
|
|
25631
|
+
"name": "debounce",
|
|
25632
|
+
"decorators": [],
|
|
25633
|
+
"description": "Задержка применения введённого значения",
|
|
25634
|
+
"required": false,
|
|
25635
|
+
"type": "boolean | ISaveCursorPositionDebounceConfig",
|
|
25636
|
+
"example": null,
|
|
25637
|
+
"defaultValue": null
|
|
25638
|
+
},
|
|
25515
25639
|
{
|
|
25516
25640
|
"name": "disabled",
|
|
25517
25641
|
"decorators": [],
|
|
@@ -25819,6 +25943,14 @@
|
|
|
25819
25943
|
"type": "any",
|
|
25820
25944
|
"example": null
|
|
25821
25945
|
},
|
|
25946
|
+
{
|
|
25947
|
+
"name": "debounce",
|
|
25948
|
+
"decorators": [],
|
|
25949
|
+
"description": "Задержка применения введённого значения",
|
|
25950
|
+
"required": false,
|
|
25951
|
+
"type": "boolean | ISaveCursorPositionDebounceConfig",
|
|
25952
|
+
"example": null
|
|
25953
|
+
},
|
|
25822
25954
|
{
|
|
25823
25955
|
"name": "defaultValue",
|
|
25824
25956
|
"decorators": [],
|
|
@@ -26168,6 +26300,15 @@
|
|
|
26168
26300
|
"example": null,
|
|
26169
26301
|
"defaultValue": null
|
|
26170
26302
|
},
|
|
26303
|
+
{
|
|
26304
|
+
"name": "debounce",
|
|
26305
|
+
"decorators": [],
|
|
26306
|
+
"description": "Задержка применения введённого значения",
|
|
26307
|
+
"required": false,
|
|
26308
|
+
"type": "boolean | ISaveCursorPositionDebounceConfig",
|
|
26309
|
+
"example": null,
|
|
26310
|
+
"defaultValue": null
|
|
26311
|
+
},
|
|
26171
26312
|
{
|
|
26172
26313
|
"name": "disabled",
|
|
26173
26314
|
"decorators": [],
|
|
@@ -26751,6 +26892,15 @@
|
|
|
26751
26892
|
"example": null,
|
|
26752
26893
|
"defaultValue": null
|
|
26753
26894
|
},
|
|
26895
|
+
{
|
|
26896
|
+
"name": "debounce",
|
|
26897
|
+
"decorators": [],
|
|
26898
|
+
"description": "Задержка применения введённого значения",
|
|
26899
|
+
"required": false,
|
|
26900
|
+
"type": "boolean | ISaveCursorPositionDebounceConfig",
|
|
26901
|
+
"example": null,
|
|
26902
|
+
"defaultValue": null
|
|
26903
|
+
},
|
|
26754
26904
|
{
|
|
26755
26905
|
"name": "decimal",
|
|
26756
26906
|
"decorators": [],
|
|
@@ -27042,6 +27192,14 @@
|
|
|
27042
27192
|
"type": "any",
|
|
27043
27193
|
"example": null
|
|
27044
27194
|
},
|
|
27195
|
+
{
|
|
27196
|
+
"name": "debounce",
|
|
27197
|
+
"decorators": [],
|
|
27198
|
+
"description": "Задержка применения введённого значения",
|
|
27199
|
+
"required": false,
|
|
27200
|
+
"type": "boolean | ISaveCursorPositionDebounceConfig",
|
|
27201
|
+
"example": null
|
|
27202
|
+
},
|
|
27045
27203
|
{
|
|
27046
27204
|
"name": "decimal",
|
|
27047
27205
|
"decorators": [],
|
|
@@ -37957,6 +38115,15 @@
|
|
|
37957
38115
|
"type": "React.ReactNode | {}",
|
|
37958
38116
|
"example": "MyCustomView",
|
|
37959
38117
|
"defaultValue": null
|
|
38118
|
+
},
|
|
38119
|
+
{
|
|
38120
|
+
"name": "viewProps",
|
|
38121
|
+
"decorators": [],
|
|
38122
|
+
"description": "Свойства для view компонента",
|
|
38123
|
+
"required": false,
|
|
38124
|
+
"type": "any",
|
|
38125
|
+
"example": null,
|
|
38126
|
+
"defaultValue": null
|
|
37960
38127
|
}
|
|
37961
38128
|
],
|
|
37962
38129
|
"methods": [
|
package/en.json
CHANGED
|
@@ -1047,5 +1047,7 @@
|
|
|
1047
1047
|
"Логическое значение, указывающее, есть ли еще элементы в списке с бесконечным скроллом": "",
|
|
1048
1048
|
"Кастомный домен для куки": "",
|
|
1049
1049
|
" Автоматически устанавливает куку для всех поддоменов текущего домена,\n но только если параметр domain не указан явно": "",
|
|
1050
|
+
"Задержка в мс": "",
|
|
1051
|
+
"Задержка применения введённого значения": "",
|
|
1050
1052
|
"Флаг, который указывает, что высота поля должна быть равна высоте контента": ""
|
|
1051
1053
|
}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
2
|
import { IInputParams } from '../ui/form/Field/fieldWrapper';
|
|
3
|
-
export
|
|
4
|
-
|
|
3
|
+
export interface ISaveCursorPositionDebounceConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Задержка в мс
|
|
6
|
+
*/
|
|
7
|
+
delayMs?: number;
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface ISaveCursorPositionConfig {
|
|
11
|
+
inputParams: IInputParams;
|
|
12
|
+
onChangeCallback?: (value: any) => void;
|
|
13
|
+
debounce?: ISaveCursorPositionDebounceConfig;
|
|
14
|
+
}
|
|
15
|
+
export default function useSaveCursorPosition(config: ISaveCursorPositionConfig): {
|
|
16
|
+
inputRef: import("react").MutableRefObject<any>;
|
|
5
17
|
onChange: (event: ChangeEvent<HTMLInputElement>, value?: any) => void;
|
|
18
|
+
value: any;
|
|
6
19
|
};
|
|
@@ -3,17 +3,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
-
/* eslint-disable max-len */
|
|
7
|
-
/* eslint-disable no-unneeded-ternary */
|
|
8
6
|
/* eslint-disable consistent-return */
|
|
9
7
|
/* eslint-disable no-return-assign */
|
|
10
8
|
/* eslint-disable no-unused-expressions */
|
|
11
|
-
var react_1 =
|
|
9
|
+
var react_1 = require("react");
|
|
10
|
+
var debounce_1 = __importDefault(require("lodash-es/debounce"));
|
|
12
11
|
var isNull_1 = __importDefault(require("lodash-es/isNull"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
react_1
|
|
12
|
+
var DEFAULT_DEBOUNCE_DELAY_MS = 300;
|
|
13
|
+
function useSaveCursorPosition(config) {
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
var _d = (0, react_1.useState)(null), cursor = _d[0], setCursor = _d[1];
|
|
16
|
+
var inputRef = (0, react_1.useRef)(null);
|
|
17
|
+
var _e = (0, react_1.useState)((_a = config.inputParams.value) !== null && _a !== void 0 ? _a : ''), localValue = _e[0], setLocalValue = _e[1];
|
|
18
|
+
(0, react_1.useEffect)(function () {
|
|
17
19
|
var el = inputRef.current;
|
|
18
20
|
if (!el || (0, isNull_1["default"])(cursor)) {
|
|
19
21
|
return;
|
|
@@ -25,19 +27,52 @@ function useSaveCursorPosition(inputParams, onChangeCallback) {
|
|
|
25
27
|
catch (e) {
|
|
26
28
|
console.error(e);
|
|
27
29
|
}
|
|
28
|
-
}, [cursor,
|
|
29
|
-
|
|
30
|
+
}, [cursor, localValue]);
|
|
31
|
+
/**
|
|
32
|
+
* Синхронизация ТОЛЬКО при внешнем reset (например, очистка формы)
|
|
33
|
+
*/
|
|
34
|
+
(0, react_1.useEffect)(function () {
|
|
35
|
+
var _a;
|
|
36
|
+
if (config.inputParams.value !== localValue) {
|
|
37
|
+
setLocalValue((_a = config.inputParams.value) !== null && _a !== void 0 ? _a : '');
|
|
38
|
+
}
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [config.inputParams.value]);
|
|
41
|
+
/**
|
|
42
|
+
* Создаём debounce только при смене delay или enabled.
|
|
43
|
+
* onChange и onChangeCallback не добавляем в зависимости,
|
|
44
|
+
* чтобы debounce не пересоздавался каждый рендер.
|
|
45
|
+
*/
|
|
46
|
+
var debouncedCommit = (0, react_1.useMemo)(function () {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (!((_a = config.debounce) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
return (0, debounce_1["default"])(function (value) {
|
|
52
|
+
var _a;
|
|
53
|
+
config.inputParams.onChange(value);
|
|
54
|
+
(_a = config.onChangeCallback) === null || _a === void 0 ? void 0 : _a.call(config, value);
|
|
55
|
+
}, (_b = config.debounce.delayMs) !== null && _b !== void 0 ? _b : DEFAULT_DEBOUNCE_DELAY_MS);
|
|
56
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
57
|
+
}, [(_b = config.debounce) === null || _b === void 0 ? void 0 : _b.enabled, (_c = config.debounce) === null || _c === void 0 ? void 0 : _c.delayMs]);
|
|
58
|
+
var onChange = (0, react_1.useCallback)(function (event, value) {
|
|
30
59
|
var _a, _b, _c;
|
|
31
60
|
if (value === void 0) { value = null; }
|
|
32
|
-
|
|
33
|
-
|
|
61
|
+
var val = value !== null && value !== void 0 ? value : event.target.value;
|
|
62
|
+
setCursor((_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.selectionStart);
|
|
63
|
+
setLocalValue(val);
|
|
64
|
+
if ((_b = config.debounce) === null || _b === void 0 ? void 0 : _b.enabled) {
|
|
65
|
+
debouncedCommit(val);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
config.inputParams.onChange(val);
|
|
69
|
+
(_c = config.onChangeCallback) === null || _c === void 0 ? void 0 : _c.call(config, val);
|
|
34
70
|
}
|
|
35
|
-
|
|
36
|
-
inputParams.onChange(value || ((_c = event.target) === null || _c === void 0 ? void 0 : _c.value));
|
|
37
|
-
}, [inputParams, onChangeCallback]);
|
|
71
|
+
}, [config, debouncedCommit]);
|
|
38
72
|
return {
|
|
39
73
|
inputRef: inputRef,
|
|
40
|
-
onChange: onChange
|
|
74
|
+
onChange: onChange,
|
|
75
|
+
value: localValue
|
|
41
76
|
};
|
|
42
77
|
}
|
|
43
78
|
exports["default"] = useSaveCursorPosition;
|
package/package.json
CHANGED
|
@@ -44,7 +44,9 @@ var useInputTypeEmail_1 = __importDefault(require("./hooks/useInputTypeEmail"));
|
|
|
44
44
|
var enums_1 = require("../../../enums");
|
|
45
45
|
function EmailField(props) {
|
|
46
46
|
var components = (0, hooks_1.useComponents)();
|
|
47
|
-
var _a = (0, hooks_1.useSaveCursorPosition)(
|
|
47
|
+
var _a = (0, hooks_1.useSaveCursorPosition)({
|
|
48
|
+
inputParams: props.input
|
|
49
|
+
}), currentInputRef = _a.inputRef, onChange = _a.onChange;
|
|
48
50
|
var onInputChange = (0, useInputTypeEmail_1["default"])(currentInputRef, onChange, props.input.value, props.required).onInputChange;
|
|
49
51
|
var onClear = react_1["default"].useCallback(function () { return props.input.onChange(''); }, [props.input]);
|
|
50
52
|
var inputProps = react_1["default"].useMemo(function () {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InputHTMLAttributes, ReactNode } from 'react';
|
|
3
3
|
import { MaskitoOptions } from '@maskito/core';
|
|
4
|
+
import { ISaveCursorPositionDebounceConfig } from '@steroidsjs/core/hooks/useSaveCursorPosition';
|
|
4
5
|
import { IFieldWrapperInputProps, IFieldWrapperOutputProps } from '../Field/fieldWrapper';
|
|
5
6
|
export declare const MASK_PRESETS: {
|
|
6
7
|
date: Required<MaskitoOptions>;
|
|
@@ -87,6 +88,10 @@ export interface IInputFieldProps extends IBaseFieldProps {
|
|
|
87
88
|
* Пользовательская иконка svg или название иконки
|
|
88
89
|
*/
|
|
89
90
|
leadIcon?: React.ReactElement | string;
|
|
91
|
+
/**
|
|
92
|
+
* Задержка применения введённого значения
|
|
93
|
+
*/
|
|
94
|
+
debounce?: boolean | ISaveCursorPositionDebounceConfig;
|
|
90
95
|
}
|
|
91
96
|
export interface IInputFieldViewProps extends IInputFieldProps, IFieldWrapperOutputProps {
|
|
92
97
|
inputProps: {
|
|
@@ -87,11 +87,16 @@ exports.MASK_PRESETS = {
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
function InputField(props) {
|
|
90
|
+
var _a;
|
|
90
91
|
var components = (0, hooks_1.useComponents)();
|
|
91
92
|
var maskedInputRef = (0, react_2.useMaskito)({
|
|
92
93
|
options: props.maskOptions
|
|
93
94
|
});
|
|
94
|
-
var
|
|
95
|
+
var _b = (0, hooks_1.useSaveCursorPosition)({
|
|
96
|
+
inputParams: props.input,
|
|
97
|
+
onChangeCallback: props.onChange,
|
|
98
|
+
debounce: __assign({ enabled: !!props.debounce }, (typeof props.debounce === 'boolean' ? { enabled: props.debounce } : ((_a = props.debounce) !== null && _a !== void 0 ? _a : {})))
|
|
99
|
+
}), inputRef = _b.inputRef, onChange = _b.onChange, value = _b.value;
|
|
95
100
|
React.useEffect(function () {
|
|
96
101
|
if (inputRef.current) {
|
|
97
102
|
maskedInputRef(inputRef.current);
|
|
@@ -103,11 +108,8 @@ function InputField(props) {
|
|
|
103
108
|
props.onClear('');
|
|
104
109
|
}
|
|
105
110
|
props.input.onChange('');
|
|
106
|
-
}, [props
|
|
107
|
-
var inputProps = (0, react_1.useMemo)(function () {
|
|
108
|
-
var _a;
|
|
109
|
-
return (__assign({ type: props.type, name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : '', onInput: onChange, placeholder: props.placeholder }, props.inputProps));
|
|
110
|
-
}, [onChange, props.input.name, props.input.value, props.inputProps, props.placeholder, props.type]);
|
|
111
|
+
}, [props]);
|
|
112
|
+
var inputProps = (0, react_1.useMemo)(function () { return (__assign({ type: props.type, name: props.input.name, value: value, onInput: onChange, placeholder: props.placeholder }, props.inputProps)); }, [value, onChange, props.input.name, props.inputProps, props.placeholder, props.type]);
|
|
111
113
|
var viewProps = (0, react_1.useMemo)(function () { return ({
|
|
112
114
|
inputRef: useInputFieldWarningByType_1.INPUT_TYPES_SUPPORTED_SELECTION.includes(props.type) ? inputRef : null,
|
|
113
115
|
onClear: onClear,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { ChangeEvent } from 'react';
|
|
2
|
+
import { ISaveCursorPositionDebounceConfig } from '@steroidsjs/core/hooks/useSaveCursorPosition';
|
|
2
3
|
import { IBaseFieldProps } from '../InputField/InputField';
|
|
3
4
|
import { IFieldWrapperInputProps, IFieldWrapperOutputProps } from '../Field/fieldWrapper';
|
|
4
5
|
/**
|
|
@@ -30,6 +31,10 @@ export interface INumberFieldProps extends IFieldWrapperInputProps, IBaseFieldPr
|
|
|
30
31
|
* Может ли число быть отрицательным
|
|
31
32
|
*/
|
|
32
33
|
isCanBeNegative?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Задержка применения введённого значения
|
|
36
|
+
*/
|
|
37
|
+
debounce?: boolean | ISaveCursorPositionDebounceConfig;
|
|
33
38
|
}
|
|
34
39
|
export interface INumberFieldViewProps extends INumberFieldProps, IFieldWrapperOutputProps {
|
|
35
40
|
inputProps: {
|
|
@@ -45,8 +45,13 @@ var useInputTypeNumber_1 = __importDefault(require("./hooks/useInputTypeNumber")
|
|
|
45
45
|
var enums_1 = require("../../../enums");
|
|
46
46
|
var DEFAULT_STEP = 1;
|
|
47
47
|
function NumberField(props) {
|
|
48
|
+
var _a;
|
|
48
49
|
var components = (0, hooks_1.useComponents)();
|
|
49
|
-
var
|
|
50
|
+
var _b = (0, hooks_1.useSaveCursorPosition)({
|
|
51
|
+
inputParams: props.input,
|
|
52
|
+
onChangeCallback: props.onChange,
|
|
53
|
+
debounce: __assign({ enabled: !!props.debounce }, (typeof props.debounce === 'boolean' ? { enabled: props.debounce } : ((_a = props.debounce) !== null && _a !== void 0 ? _a : {})))
|
|
54
|
+
}), currentInputRef = _b.inputRef, onChange = _b.onChange, value = _b.value;
|
|
50
55
|
var step = react_1["default"].useMemo(function () { var _a; return (_a = props.step) !== null && _a !== void 0 ? _a : DEFAULT_STEP; }, [props.step]);
|
|
51
56
|
var onInputChange = (0, useInputTypeNumber_1["default"])(currentInputRef, {
|
|
52
57
|
max: props.max,
|
|
@@ -58,7 +63,7 @@ function NumberField(props) {
|
|
|
58
63
|
var _a;
|
|
59
64
|
var currentValue = Number((_a = currentInputRef === null || currentInputRef === void 0 ? void 0 : currentInputRef.current) === null || _a === void 0 ? void 0 : _a.value);
|
|
60
65
|
var newValue;
|
|
61
|
-
var fixToDecimal = function (
|
|
66
|
+
var fixToDecimal = function (rawValue) { return props.decimal ? rawValue.toFixed(props.decimal) : rawValue; };
|
|
62
67
|
if (isIncrement) {
|
|
63
68
|
newValue = fixToDecimal(currentValue + step);
|
|
64
69
|
}
|
|
@@ -75,10 +80,7 @@ function NumberField(props) {
|
|
|
75
80
|
onStep(false);
|
|
76
81
|
}
|
|
77
82
|
}, [onStep]);
|
|
78
|
-
var inputProps = (0, react_1.useMemo)(function () {
|
|
79
|
-
var _a;
|
|
80
|
-
return (__assign(__assign({}, props.inputProps), { name: props.input.name, value: (_a = props.input.value) !== null && _a !== void 0 ? _a : '', onChange: onInputChange, type: 'text', min: props.min, max: props.max, step: props.step, placeholder: props.placeholder, disabled: props.disabled, required: props.required, autoComplete: 'off', onKeyDown: onKeyDown }));
|
|
81
|
-
}, [props.inputProps, props.input.name, props.input.value, props.min, props.max, props.step, props.placeholder, props.disabled, props.required, onInputChange, onKeyDown]);
|
|
83
|
+
var inputProps = (0, react_1.useMemo)(function () { return (__assign(__assign({}, props.inputProps), { name: props.input.name, value: value, onChange: onInputChange, type: 'text', min: props.min, max: props.max, step: props.step, placeholder: props.placeholder, disabled: props.disabled, required: props.required, autoComplete: 'off', onKeyDown: onKeyDown })); }, [props.inputProps, props.input.name, props.min, props.max, props.step, props.placeholder, props.disabled, props.required, value, onInputChange, onKeyDown]);
|
|
82
84
|
var viewProps = (0, react_1.useMemo)(function () { return ({
|
|
83
85
|
viewProps: props.viewProps,
|
|
84
86
|
inputProps: inputProps,
|
|
@@ -56,7 +56,7 @@ exports.checkPassword = checkPassword;
|
|
|
56
56
|
function PasswordField(props) {
|
|
57
57
|
var _a = (0, react_1.useState)(InputType.PASSWORD), type = _a[0], setType = _a[1];
|
|
58
58
|
var components = (0, hooks_1.useComponents)();
|
|
59
|
-
var _b = (0, hooks_1.useSaveCursorPosition)(props.input), inputRef = _b.inputRef, onChange = _b.onChange;
|
|
59
|
+
var _b = (0, hooks_1.useSaveCursorPosition)({ inputParams: props.input }), inputRef = _b.inputRef, onChange = _b.onChange;
|
|
60
60
|
var onClear = (0, react_1.useCallback)(function () { return props.input.onChange(''); }, [props.input]);
|
|
61
61
|
var onShowButtonClick = (0, react_1.useCallback)(function () {
|
|
62
62
|
type === InputType.PASSWORD ? setType(InputType.TEXT) : setType(InputType.PASSWORD);
|
|
@@ -21,7 +21,9 @@ var enums_1 = require("../../../enums");
|
|
|
21
21
|
function TextField(props) {
|
|
22
22
|
// const dispatch = useDispatch();
|
|
23
23
|
var components = (0, hooks_1.useComponents)();
|
|
24
|
-
var _a = (0, hooks_1.useSaveCursorPosition)(
|
|
24
|
+
var _a = (0, hooks_1.useSaveCursorPosition)({
|
|
25
|
+
inputParams: props.input
|
|
26
|
+
}), inputRef = _a.inputRef, onChange = _a.onChange;
|
|
25
27
|
var onKeyUp = (0, react_1.useCallback)(function (e) {
|
|
26
28
|
if (props.submitOnEnter
|
|
27
29
|
&& props.formId
|
package/ui/modal/Modal/Modal.js
CHANGED
|
@@ -56,9 +56,9 @@ function Modal(props) {
|
|
|
56
56
|
shouldCloseOnOverlayClick: props.shouldCloseOnOverlayClick,
|
|
57
57
|
title: props.title,
|
|
58
58
|
children: props.children,
|
|
59
|
-
buttons: props.buttons
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
buttons: props.buttons,
|
|
60
|
+
viewProps: props.viewProps
|
|
61
|
+
}); }, [props.buttons, props.children, props.className, props.closeTimeoutMs, props.isClosing, props.onClose, props.shouldCloseOnEsc, props.shouldCloseOnOverlayClick, props.size, props.title, props.viewProps]);
|
|
62
62
|
return (react_1["default"].createElement(ModalView, __assign({}, viewProps), (ContentComponent && (react_1["default"].createElement(ContentComponent, __assign({}, props, props.componentProps)))) || (props.children)));
|
|
63
63
|
}
|
|
64
64
|
Modal.defaultProps = {
|