@contentful/field-editor-number 1.3.6 → 1.3.7
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/dist/cjs/NumberEditor.js
CHANGED
|
@@ -36,7 +36,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
36
36
|
if (cache && cache.has(obj)) {
|
|
37
37
|
return cache.get(obj);
|
|
38
38
|
}
|
|
39
|
-
var newObj = {
|
|
39
|
+
var newObj = {
|
|
40
|
+
__proto__: null
|
|
41
|
+
};
|
|
40
42
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
41
43
|
for(var key in obj){
|
|
42
44
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -56,11 +58,11 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
56
58
|
}
|
|
57
59
|
var StepChangeType;
|
|
58
60
|
(function(StepChangeType) {
|
|
59
|
-
StepChangeType["Increment"] =
|
|
60
|
-
StepChangeType["Decrement"] =
|
|
61
|
+
StepChangeType["Increment"] = "increment";
|
|
62
|
+
StepChangeType["Decrement"] = "decrement";
|
|
61
63
|
})(StepChangeType || (StepChangeType = {}));
|
|
62
64
|
const NUMBER_STEP = 1;
|
|
63
|
-
function InnerNumberEditor({ disabled
|
|
65
|
+
function InnerNumberEditor({ disabled, errors, field, setValue, value: sdkValue }) {
|
|
64
66
|
const [inputValue, setInputValue] = _react.useState((0, _utils.valueToString)(sdkValue));
|
|
65
67
|
const range = (0, _utils.getRangeFromField)(field);
|
|
66
68
|
const inputRef = _react.useRef(null);
|
|
@@ -79,7 +81,7 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
79
81
|
};
|
|
80
82
|
const changeValueByStep = (type)=>{
|
|
81
83
|
const currentValue = Number.isNaN(+inputValue) ? 0 : +inputValue;
|
|
82
|
-
let nextValue = type ===
|
|
84
|
+
let nextValue = type === "increment" ? currentValue + NUMBER_STEP : currentValue - NUMBER_STEP;
|
|
83
85
|
nextValue = +nextValue.toFixed((0, _utils.countDecimals)(currentValue));
|
|
84
86
|
setInputValue((0, _utils.valueToString)(nextValue));
|
|
85
87
|
setValue(nextValue);
|
|
@@ -90,8 +92,8 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
90
92
|
};
|
|
91
93
|
const handleKeyDown = (event)=>{
|
|
92
94
|
const keyToFnMap = {
|
|
93
|
-
ArrowUp: ()=>changeValueByStep(
|
|
94
|
-
ArrowDown: ()=>changeValueByStep(
|
|
95
|
+
ArrowUp: ()=>changeValueByStep("increment"),
|
|
96
|
+
ArrowDown: ()=>changeValueByStep("decrement")
|
|
95
97
|
};
|
|
96
98
|
const fn = keyToFnMap[event.key];
|
|
97
99
|
if (fn) {
|
|
@@ -143,25 +145,25 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
143
145
|
}, _react.createElement("button", {
|
|
144
146
|
tabIndex: -1,
|
|
145
147
|
className: _NumberEditorstyles.styles.control,
|
|
146
|
-
onClick: ()=>changeValueByStep(
|
|
148
|
+
onClick: ()=>changeValueByStep("increment"),
|
|
147
149
|
onPointerDown: handleControlPointerDown
|
|
148
150
|
}, _react.createElement(_f36icons.ArrowUpTrimmedIcon, {
|
|
149
151
|
size: "medium"
|
|
150
152
|
})), _react.createElement("button", {
|
|
151
153
|
tabIndex: -1,
|
|
152
154
|
className: _NumberEditorstyles.styles.control,
|
|
153
|
-
onClick: ()=>changeValueByStep(
|
|
155
|
+
onClick: ()=>changeValueByStep("decrement"),
|
|
154
156
|
onPointerDown: handleControlPointerDown
|
|
155
157
|
}, _react.createElement(_f36icons.ArrowDownTrimmedIcon, {
|
|
156
158
|
size: "medium"
|
|
157
159
|
}))));
|
|
158
160
|
}
|
|
159
161
|
function NumberEditor(props) {
|
|
160
|
-
const { field
|
|
162
|
+
const { field } = props;
|
|
161
163
|
return _react.createElement(_fieldeditorshared.FieldConnector, {
|
|
162
164
|
field: field,
|
|
163
165
|
isInitiallyDisabled: props.isInitiallyDisabled
|
|
164
|
-
}, ({ value
|
|
166
|
+
}, ({ value, errors, disabled, setValue })=>_react.createElement(InnerNumberEditor, {
|
|
165
167
|
disabled: disabled,
|
|
166
168
|
errors: errors,
|
|
167
169
|
field: field,
|
|
@@ -34,7 +34,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
34
34
|
if (cache && cache.has(obj)) {
|
|
35
35
|
return cache.get(obj);
|
|
36
36
|
}
|
|
37
|
-
var newObj = {
|
|
37
|
+
var newObj = {
|
|
38
|
+
__proto__: null
|
|
39
|
+
};
|
|
38
40
|
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
39
41
|
for(var key in obj){
|
|
40
42
|
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
@@ -55,7 +57,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
55
57
|
(0, _react1.configure)({
|
|
56
58
|
testIdAttribute: 'data-test-id'
|
|
57
59
|
});
|
|
58
|
-
function createField({ initialValue
|
|
60
|
+
function createField({ initialValue, type = 'Integer' }) {
|
|
59
61
|
const [field] = (0, _fieldeditortestutils.createFakeFieldAPI)((field)=>{
|
|
60
62
|
jest.spyOn(field, 'setValue');
|
|
61
63
|
jest.spyOn(field, 'removeValue');
|
package/dist/cjs/parseNumber.js
CHANGED
|
@@ -9,11 +9,11 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
parseNumber: function() {
|
|
13
|
-
return parseNumber;
|
|
14
|
-
},
|
|
15
12
|
isNumberInputValueValid: function() {
|
|
16
13
|
return isNumberInputValueValid;
|
|
14
|
+
},
|
|
15
|
+
parseNumber: function() {
|
|
16
|
+
return parseNumber;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
function parseNumber(value, type) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -9,14 +9,14 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
+
countDecimals: function() {
|
|
13
|
+
return countDecimals;
|
|
14
|
+
},
|
|
12
15
|
getRangeFromField: function() {
|
|
13
16
|
return getRangeFromField;
|
|
14
17
|
},
|
|
15
18
|
valueToString: function() {
|
|
16
19
|
return valueToString;
|
|
17
|
-
},
|
|
18
|
-
countDecimals: function() {
|
|
19
|
-
return countDecimals;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
const getRangeFromField = (field)=>{
|
package/dist/esm/NumberEditor.js
CHANGED
|
@@ -7,11 +7,11 @@ import { isNumberInputValueValid, parseNumber } from './parseNumber';
|
|
|
7
7
|
import { getRangeFromField, valueToString, countDecimals } from './utils';
|
|
8
8
|
var StepChangeType;
|
|
9
9
|
(function(StepChangeType) {
|
|
10
|
-
StepChangeType["Increment"] =
|
|
11
|
-
StepChangeType["Decrement"] =
|
|
10
|
+
StepChangeType["Increment"] = "increment";
|
|
11
|
+
StepChangeType["Decrement"] = "decrement";
|
|
12
12
|
})(StepChangeType || (StepChangeType = {}));
|
|
13
13
|
const NUMBER_STEP = 1;
|
|
14
|
-
function InnerNumberEditor({ disabled
|
|
14
|
+
function InnerNumberEditor({ disabled, errors, field, setValue, value: sdkValue }) {
|
|
15
15
|
const [inputValue, setInputValue] = React.useState(valueToString(sdkValue));
|
|
16
16
|
const range = getRangeFromField(field);
|
|
17
17
|
const inputRef = React.useRef(null);
|
|
@@ -30,7 +30,7 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
30
30
|
};
|
|
31
31
|
const changeValueByStep = (type)=>{
|
|
32
32
|
const currentValue = Number.isNaN(+inputValue) ? 0 : +inputValue;
|
|
33
|
-
let nextValue = type ===
|
|
33
|
+
let nextValue = type === "increment" ? currentValue + NUMBER_STEP : currentValue - NUMBER_STEP;
|
|
34
34
|
nextValue = +nextValue.toFixed(countDecimals(currentValue));
|
|
35
35
|
setInputValue(valueToString(nextValue));
|
|
36
36
|
setValue(nextValue);
|
|
@@ -41,8 +41,8 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
41
41
|
};
|
|
42
42
|
const handleKeyDown = (event)=>{
|
|
43
43
|
const keyToFnMap = {
|
|
44
|
-
ArrowUp: ()=>changeValueByStep(
|
|
45
|
-
ArrowDown: ()=>changeValueByStep(
|
|
44
|
+
ArrowUp: ()=>changeValueByStep("increment"),
|
|
45
|
+
ArrowDown: ()=>changeValueByStep("decrement")
|
|
46
46
|
};
|
|
47
47
|
const fn = keyToFnMap[event.key];
|
|
48
48
|
if (fn) {
|
|
@@ -94,25 +94,25 @@ function InnerNumberEditor({ disabled , errors , field , setValue , value: sdkVa
|
|
|
94
94
|
}, React.createElement("button", {
|
|
95
95
|
tabIndex: -1,
|
|
96
96
|
className: styles.control,
|
|
97
|
-
onClick: ()=>changeValueByStep(
|
|
97
|
+
onClick: ()=>changeValueByStep("increment"),
|
|
98
98
|
onPointerDown: handleControlPointerDown
|
|
99
99
|
}, React.createElement(ArrowUpTrimmedIcon, {
|
|
100
100
|
size: "medium"
|
|
101
101
|
})), React.createElement("button", {
|
|
102
102
|
tabIndex: -1,
|
|
103
103
|
className: styles.control,
|
|
104
|
-
onClick: ()=>changeValueByStep(
|
|
104
|
+
onClick: ()=>changeValueByStep("decrement"),
|
|
105
105
|
onPointerDown: handleControlPointerDown
|
|
106
106
|
}, React.createElement(ArrowDownTrimmedIcon, {
|
|
107
107
|
size: "medium"
|
|
108
108
|
}))));
|
|
109
109
|
}
|
|
110
110
|
export function NumberEditor(props) {
|
|
111
|
-
const { field
|
|
111
|
+
const { field } = props;
|
|
112
112
|
return React.createElement(FieldConnector, {
|
|
113
113
|
field: field,
|
|
114
114
|
isInitiallyDisabled: props.isInitiallyDisabled
|
|
115
|
-
}, ({ value
|
|
115
|
+
}, ({ value, errors, disabled, setValue })=>React.createElement(InnerNumberEditor, {
|
|
116
116
|
disabled: disabled,
|
|
117
117
|
errors: errors,
|
|
118
118
|
field: field,
|
|
@@ -7,7 +7,7 @@ import { NumberEditor } from './NumberEditor';
|
|
|
7
7
|
configure({
|
|
8
8
|
testIdAttribute: 'data-test-id'
|
|
9
9
|
});
|
|
10
|
-
function createField({ initialValue
|
|
10
|
+
function createField({ initialValue, type = 'Integer' }) {
|
|
11
11
|
const [field] = createFakeFieldAPI((field)=>{
|
|
12
12
|
jest.spyOn(field, 'setValue');
|
|
13
13
|
jest.spyOn(field, 'removeValue');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-number",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.7",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@contentful/f36-components": "^4.0.27",
|
|
39
39
|
"@contentful/f36-tokens": "^4.0.0",
|
|
40
|
-
"@contentful/field-editor-shared": "^1.4.
|
|
40
|
+
"@contentful/field-editor-shared": "^1.4.5",
|
|
41
41
|
"emotion": "^10.0.17"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@contentful/field-editor-test-utils": "^1.4.
|
|
44
|
+
"@contentful/field-editor-test-utils": "^1.4.6",
|
|
45
45
|
"@testing-library/jest-dom": "^5.12.0",
|
|
46
46
|
"@testing-library/react": "^11.2.6",
|
|
47
47
|
"@testing-library/user-event": "^13.1.9"
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"registry": "https://npm.pkg.github.com/"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "142d2039f023bf4ced956aae1dd08b27c35fdbaa"
|
|
56
56
|
}
|