@contentful/field-editor-number 0.13.6 → 1.0.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/CHANGELOG.md +20 -88
- package/README.md +0 -1
- package/dist/field-editor-number.cjs.development.js +5 -5
- package/dist/field-editor-number.cjs.development.js.map +1 -1
- package/dist/field-editor-number.cjs.production.min.js +1 -1
- package/dist/field-editor-number.cjs.production.min.js.map +1 -1
- package/dist/field-editor-number.esm.js +4 -4
- package/dist/field-editor-number.esm.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -3,194 +3,126 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [0.
|
|
6
|
+
## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@1.0.1...@contentful/field-editor-number@1.0.2) (2021-12-20)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
9
9
|
|
|
10
|
+
## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@1.0.0...@contentful/field-editor-number@1.0.1) (2021-11-17)
|
|
10
11
|
|
|
12
|
+
### Bug Fixes
|
|
11
13
|
|
|
14
|
+
- **card-actions:** update forma 36 to fix card actions click issue ([#927](https://github.com/contentful/field-editors/issues/927)) ([3dfdef2](https://github.com/contentful/field-editors/commit/3dfdef2c2b0045f12ea94ddafca89a8e9f25e7d0))
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
## [0.13.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.4...@contentful/field-editor-number@0.13.5) (2021-10-06)
|
|
16
|
+
# [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.14.0...@contentful/field-editor-number@1.0.0) (2021-11-04)
|
|
15
17
|
|
|
16
18
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
17
19
|
|
|
20
|
+
# [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.6...@contentful/field-editor-number@0.14.0) (2021-11-04)
|
|
18
21
|
|
|
22
|
+
### Features
|
|
19
23
|
|
|
24
|
+
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
20
25
|
|
|
26
|
+
### BREAKING CHANGES
|
|
21
27
|
|
|
22
|
-
|
|
28
|
+
- adopts a new Forma v4 beta
|
|
29
|
+
|
|
30
|
+
## [0.13.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.5...@contentful/field-editor-number@0.13.6) (2021-10-14)
|
|
23
31
|
|
|
24
32
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
25
33
|
|
|
34
|
+
## [0.13.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.4...@contentful/field-editor-number@0.13.5) (2021-10-06)
|
|
26
35
|
|
|
36
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
27
37
|
|
|
38
|
+
## [0.13.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.3...@contentful/field-editor-number@0.13.4) (2021-09-17)
|
|
28
39
|
|
|
40
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
29
41
|
|
|
30
42
|
## [0.13.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.2...@contentful/field-editor-number@0.13.3) (2021-09-16)
|
|
31
43
|
|
|
32
44
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
33
45
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
46
|
## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.1...@contentful/field-editor-number@0.13.2) (2021-08-19)
|
|
39
47
|
|
|
40
48
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
41
49
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
50
|
## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.13.0...@contentful/field-editor-number@0.13.1) (2021-07-29)
|
|
47
51
|
|
|
48
52
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
54
|
# [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.6...@contentful/field-editor-number@0.13.0) (2021-07-23)
|
|
55
55
|
|
|
56
|
-
|
|
57
56
|
### Features
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
58
|
+
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
64
59
|
|
|
65
60
|
## [0.12.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.3...@contentful/field-editor-number@0.12.6) (2021-07-06)
|
|
66
61
|
|
|
67
62
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
68
63
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
64
|
## [0.12.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.3...@contentful/field-editor-number@0.12.5) (2021-07-06)
|
|
74
65
|
|
|
75
66
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
76
67
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
68
|
## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.3...@contentful/field-editor-number@0.12.4) (2021-06-23)
|
|
82
69
|
|
|
83
70
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
84
71
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
72
|
## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.2...@contentful/field-editor-number@0.12.3) (2021-06-23)
|
|
90
73
|
|
|
91
74
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
92
75
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
76
|
## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.1...@contentful/field-editor-number@0.12.2) (2021-06-22)
|
|
98
77
|
|
|
99
78
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
100
79
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
80
|
## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.12.0...@contentful/field-editor-number@0.12.1) (2021-03-05)
|
|
106
81
|
|
|
107
82
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
108
83
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
84
|
# [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.11.2...@contentful/field-editor-number@0.12.0) (2021-02-19)
|
|
114
85
|
|
|
115
|
-
|
|
116
86
|
### Features
|
|
117
87
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
88
|
+
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
123
89
|
|
|
124
90
|
## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.11.1...@contentful/field-editor-number@0.11.2) (2021-02-09)
|
|
125
91
|
|
|
126
92
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
127
93
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
94
|
## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.11.0...@contentful/field-editor-number@0.11.1) (2021-02-01)
|
|
133
95
|
|
|
134
96
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
135
97
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
98
|
# [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.10.0...@contentful/field-editor-number@0.11.0) (2021-01-20)
|
|
141
99
|
|
|
142
|
-
|
|
143
100
|
### Features
|
|
144
101
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
102
|
+
- update minimal forma-36 versions to use updated design ([#565](https://github.com/contentful/field-editors/issues/565)) ([332c734](https://github.com/contentful/field-editors/commit/332c734bfaf54f0e9773fcbb460d743b1f5459ec))
|
|
150
103
|
|
|
151
104
|
# [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.5...@contentful/field-editor-number@0.10.0) (2021-01-12)
|
|
152
105
|
|
|
153
|
-
|
|
154
106
|
### Features
|
|
155
107
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
108
|
+
- update minimal required Forma version to the 3.73.12 ([#552](https://github.com/contentful/field-editors/issues/552)) ([2816fd9](https://github.com/contentful/field-editors/commit/2816fd960c28815faebf49a9ef8f4c4c0d91fc36))
|
|
161
109
|
|
|
162
110
|
## [0.9.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.4...@contentful/field-editor-number@0.9.5) (2020-12-16)
|
|
163
111
|
|
|
164
112
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
165
113
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
114
|
## [0.9.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.3...@contentful/field-editor-number@0.9.4) (2020-11-06)
|
|
171
115
|
|
|
172
116
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
173
117
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
118
|
## [0.9.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.2...@contentful/field-editor-number@0.9.3) (2020-11-06)
|
|
179
119
|
|
|
180
120
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
181
121
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
122
|
## [0.9.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.1...@contentful/field-editor-number@0.9.2) (2020-10-28)
|
|
187
123
|
|
|
188
124
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
189
125
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
126
|
## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-number@0.9.0...@contentful/field-editor-number@0.9.1) (2020-08-24)
|
|
195
127
|
|
|
196
128
|
**Note:** Version bump only for package @contentful/field-editor-number
|
package/README.md
CHANGED
|
@@ -7,6 +7,5 @@ npm install @contentful/field-editor-number
|
|
|
7
7
|
This package contains a React `NumberEditor` component that is used as a default for the `Integer` and `Number` field types in the Contentful web application.
|
|
8
8
|
|
|
9
9
|
```js
|
|
10
|
-
import '@contentful/forma-36-react-components/dist/styles.css';
|
|
11
10
|
import { NumberEditor } from '@contentful/field-editor-number';
|
|
12
11
|
```
|
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var React = require('react');
|
|
8
|
-
var forma36ReactComponents = require('@contentful/forma-36-react-components');
|
|
9
8
|
var fieldEditorShared = require('@contentful/field-editor-shared');
|
|
10
9
|
var isEmpty = _interopDefault(require('lodash/isEmpty'));
|
|
10
|
+
var f36Components = require('@contentful/f36-components');
|
|
11
11
|
|
|
12
12
|
function parseNumber(value, type) {
|
|
13
13
|
// This has saner semantics than parseFloat.
|
|
@@ -73,15 +73,15 @@ function NumberEditor(props) {
|
|
|
73
73
|
setValue = _ref.setValue;
|
|
74
74
|
return React.createElement("div", {
|
|
75
75
|
"data-test-id": "number-editor"
|
|
76
|
-
}, React.createElement(
|
|
76
|
+
}, React.createElement(f36Components.TextInput, {
|
|
77
77
|
testId: "number-editor-input",
|
|
78
78
|
min: range.min !== undefined ? String(range.min) : '',
|
|
79
79
|
max: range.max !== undefined ? String(range.max) : '',
|
|
80
80
|
step: field.type === 'Integer' ? '1' : '',
|
|
81
81
|
type: "number",
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
isRequired: field.required,
|
|
83
|
+
isInvalid: errors.length > 0,
|
|
84
|
+
isDisabled: disabled,
|
|
85
85
|
value: value === undefined ? '' : String(value),
|
|
86
86
|
onChange: function onChange(e) {
|
|
87
87
|
var parseResult = parseNumber(e.target.value, field.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-number.cjs.development.js","sources":["../src/parseNumber.ts","../src/NumberEditor.tsx"],"sourcesContent":["import isEmpty from 'lodash/isEmpty';\n\nexport function parseNumber(\n value: string,\n type: string\n): {\n isValid: boolean;\n value: number | undefined;\n} {\n // This has saner semantics than parseFloat.\n // For values with chars in 'em, it gives\n // us NaN unlike parseFloat\n const floatVal = +value;\n const hasDot = /\\./g.test(value);\n const hasFractional = /\\.\\d+/g.test(value);\n\n if (isEmpty(value)) {\n return {\n isValid: true,\n value: undefined
|
|
1
|
+
{"version":3,"file":"field-editor-number.cjs.development.js","sources":["../src/parseNumber.ts","../src/NumberEditor.tsx"],"sourcesContent":["import isEmpty from 'lodash/isEmpty';\n\nexport function parseNumber(\n value: string,\n type: string\n): {\n isValid: boolean;\n value: number | undefined;\n} {\n // This has saner semantics than parseFloat.\n // For values with chars in 'em, it gives\n // us NaN unlike parseFloat\n const floatVal = +value;\n const hasDot = /\\./g.test(value);\n const hasFractional = /\\.\\d+/g.test(value);\n\n if (isEmpty(value)) {\n return {\n isValid: true,\n value: undefined,\n };\n }\n\n if (isNaN(floatVal)) {\n return {\n isValid: false,\n value: undefined,\n };\n }\n\n if (type === 'Integer' && hasDot) {\n const intVal = parseInt(value, 10);\n\n return {\n isValid: false,\n value: intVal,\n };\n }\n\n if (hasDot && !hasFractional) {\n return {\n isValid: false,\n value: floatVal,\n };\n }\n\n return {\n isValid: true,\n value: floatVal,\n };\n}\n","import * as React from 'react';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { parseNumber } from './parseNumber';\n\nimport { TextInput } from '@contentful/f36-components';\n\nexport interface NumberEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype RangeValidation = { min?: number; max?: number };\n\nfunction getRangeFromField(field: FieldAPI): RangeValidation {\n const validations = field.validations || [];\n const result = validations.find((validation) => (validation as any).range) as\n | { range: RangeValidation }\n | undefined;\n return result ? result.range : {};\n}\n\nexport function NumberEditor(props: NumberEditorProps) {\n const { field } = props;\n\n const range = getRangeFromField(field);\n\n return (\n <FieldConnector<number> field={field} isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"number-editor\">\n <TextInput\n testId=\"number-editor-input\"\n min={range.min !== undefined ? String(range.min) : ''}\n max={range.max !== undefined ? String(range.max) : ''}\n step={field.type === 'Integer' ? '1' : ''}\n type=\"number\"\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n const parseResult = parseNumber(e.target.value, field.type);\n field.setInvalid(!parseResult.isValid);\n if (parseResult.isValid) {\n setValue(parseResult.value);\n }\n }}\n />\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nNumberEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseNumber","value","type","floatVal","hasDot","test","hasFractional","isEmpty","isValid","undefined","isNaN","intVal","parseInt","getRangeFromField","field","validations","result","find","validation","range","NumberEditor","props","React","FieldConnector","isInitiallyDisabled","errors","disabled","setValue","TextInput","testId","min","String","max","step","isRequired","required","isInvalid","length","isDisabled","onChange","e","parseResult","target","setInvalid","defaultProps"],"mappings":";;;;;;;;;;;SAEgBA,YACdC,OACAC;AAKA;AACA;AACA;AACA,MAAMC,QAAQ,GAAG,CAACF,KAAlB;AACA,MAAMG,MAAM,GAAG,MAAMC,IAAN,CAAWJ,KAAX,CAAf;AACA,MAAMK,aAAa,GAAG,SAASD,IAAT,CAAcJ,KAAd,CAAtB;;AAEA,MAAIM,OAAO,CAACN,KAAD,CAAX,EAAoB;AAClB,WAAO;AACLO,MAAAA,OAAO,EAAE,IADJ;AAELP,MAAAA,KAAK,EAAEQ;AAFF,KAAP;AAID;;AAED,MAAIC,KAAK,CAACP,QAAD,CAAT,EAAqB;AACnB,WAAO;AACLK,MAAAA,OAAO,EAAE,KADJ;AAELP,MAAAA,KAAK,EAAEQ;AAFF,KAAP;AAID;;AAED,MAAIP,IAAI,KAAK,SAAT,IAAsBE,MAA1B,EAAkC;AAChC,QAAMO,MAAM,GAAGC,QAAQ,CAACX,KAAD,EAAQ,EAAR,CAAvB;AAEA,WAAO;AACLO,MAAAA,OAAO,EAAE,KADJ;AAELP,MAAAA,KAAK,EAAEU;AAFF,KAAP;AAID;;AAED,MAAIP,MAAM,IAAI,CAACE,aAAf,EAA8B;AAC5B,WAAO;AACLE,MAAAA,OAAO,EAAE,KADJ;AAELP,MAAAA,KAAK,EAAEE;AAFF,KAAP;AAID;;AAED,SAAO;AACLK,IAAAA,OAAO,EAAE,IADJ;AAELP,IAAAA,KAAK,EAAEE;AAFF,GAAP;AAID;;AC9BD,SAASU,iBAAT,CAA2BC,KAA3B;AACE,MAAMC,WAAW,GAAGD,KAAK,CAACC,WAAN,IAAqB,EAAzC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AF,CAASzC,KAAV,EAAiBa,KAAK,CAACZ,IAAvB,CAA/B;AACAY,QAAAA,KAAK,CAAC6B,UAAN,CAAiB,CAACF,WAAW,CAACjC,OAA9B;;AACA,YAAIiC,WAAW,CAACjC,OAAhB,EAAyB;AACvBmB,UAAAA,QAAQ,CAACc,WAAW,CAACxC,KAAb,CAAR;AACD;AACF;KAhBH,CADF,CADF;AAsBD,GAxBH,CADF;AA4BD;AAEDmB,YAAY,CAACwB,YAAb,GAA4B;AAC1BpB,EAAAA,mBAAmB,EAAE;AADK,CAA5B;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,i=require("react"),t=require("@contentful/field-editor-shared"),r=(e=require("lodash/isEmpty"))&&"object"==typeof e&&"default"in e?e.default:e,a=require("@contentful/f36-components");function n(e){var n=e.field,l=function(e){var i=(e.validations||[]).find((function(e){return e.range}));return i?i.range:{}}(n);return i.createElement(t.FieldConnector,{field:n,isInitiallyDisabled:e.isInitiallyDisabled},(function(e){var t=e.value,d=e.errors,u=e.disabled,s=e.setValue;return i.createElement("div",{"data-test-id":"number-editor"},i.createElement(a.TextInput,{testId:"number-editor-input",min:void 0!==l.min?String(l.min):"",max:void 0!==l.max?String(l.max):"",step:"Integer"===n.type?"1":"",type:"number",isRequired:n.required,isInvalid:d.length>0,isDisabled:u,value:void 0===t?"":String(t),onChange:function(e){var i=function(e,i){var t=+e,a=/\./g.test(e),n=/\.\d+/g.test(e);return r(e)?{isValid:!0,value:void 0}:isNaN(t)?{isValid:!1,value:void 0}:"Integer"===i&&a?{isValid:!1,value:parseInt(e,10)}:a&&!n?{isValid:!1,value:t}:{isValid:!0,value:t}}(e.target.value,n.type);n.setInvalid(!i.isValid),i.isValid&&s(i.value)}}))}))}n.defaultProps={isInitiallyDisabled:!0},exports.NumberEditor=n;
|
|
2
2
|
//# sourceMappingURL=field-editor-number.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-number.cjs.production.min.js","sources":["../src/NumberEditor.tsx","../src/parseNumber.ts"],"sourcesContent":["import * as React from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"field-editor-number.cjs.production.min.js","sources":["../src/NumberEditor.tsx","../src/parseNumber.ts"],"sourcesContent":["import * as React from 'react';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { parseNumber } from './parseNumber';\n\nimport { TextInput } from '@contentful/f36-components';\n\nexport interface NumberEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype RangeValidation = { min?: number; max?: number };\n\nfunction getRangeFromField(field: FieldAPI): RangeValidation {\n const validations = field.validations || [];\n const result = validations.find((validation) => (validation as any).range) as\n | { range: RangeValidation }\n | undefined;\n return result ? result.range : {};\n}\n\nexport function NumberEditor(props: NumberEditorProps) {\n const { field } = props;\n\n const range = getRangeFromField(field);\n\n return (\n <FieldConnector<number> field={field} isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"number-editor\">\n <TextInput\n testId=\"number-editor-input\"\n min={range.min !== undefined ? String(range.min) : ''}\n max={range.max !== undefined ? String(range.max) : ''}\n step={field.type === 'Integer' ? '1' : ''}\n type=\"number\"\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n const parseResult = parseNumber(e.target.value, field.type);\n field.setInvalid(!parseResult.isValid);\n if (parseResult.isValid) {\n setValue(parseResult.value);\n }\n }}\n />\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nNumberEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n","import isEmpty from 'lodash/isEmpty';\n\nexport function parseNumber(\n value: string,\n type: string\n): {\n isValid: boolean;\n value: number | undefined;\n} {\n // This has saner semantics than parseFloat.\n // For values with chars in 'em, it gives\n // us NaN unlike parseFloat\n const floatVal = +value;\n const hasDot = /\\./g.test(value);\n const hasFractional = /\\.\\d+/g.test(value);\n\n if (isEmpty(value)) {\n return {\n isValid: true,\n value: undefined,\n };\n }\n\n if (isNaN(floatVal)) {\n return {\n isValid: false,\n value: undefined,\n };\n }\n\n if (type === 'Integer' && hasDot) {\n const intVal = parseInt(value, 10);\n\n return {\n isValid: false,\n value: intVal,\n };\n }\n\n if (hasDot && !hasFractional) {\n return {\n isValid: false,\n value: floatVal,\n };\n }\n\n return {\n isValid: true,\n value: floatVal,\n };\n}\n"],"names":["NumberEditor","props","field","range","result","validations","find","validation","getRangeFromField","React","FieldConnector","isInitiallyDisabled","value","errors","disabled","setValue","TextInput","testId","min","undefined","String","max","step","type","isRequired","required","isInvalid","length","isDisabled","onChange","e","parseResult","floatVal","hasDot","test","hasFractional","isEmpty","isValid","isNaN","parseInt","parseNumber","target","setInvalid","defaultProps"],"mappings":"0QA4BgBA,EAAaC,OACnBC,EAAUD,EAAVC,MAEFC,EAXR,SAA2BD,OAEnBE,GADcF,EAAMG,aAAe,IACdC,MAAK,SAACC,UAAgBA,EAAmBJ,gBAG7DC,EAASA,EAAOD,MAAQ,GAMjBK,CAAkBN,UAG9BO,gBAACC,kBAAuBR,MAAOA,EAAOS,oBAAqBV,EAAMU,sBAC9D,gBAAGC,IAAAA,MAAOC,IAAAA,OAAQC,IAAAA,SAAUC,IAAAA,gBAEzBN,sCAAkB,iBAChBA,gBAACO,aACCC,OAAO,sBACPC,SAAmBC,IAAdhB,EAAMe,IAAoBE,OAAOjB,EAAMe,KAAO,GACnDG,SAAmBF,IAAdhB,EAAMkB,IAAoBD,OAAOjB,EAAMkB,KAAO,GACnDC,KAAqB,YAAfpB,EAAMqB,KAAqB,IAAM,GACvCA,KAAK,SACLC,WAAYtB,EAAMuB,SAClBC,UAAWb,EAAOc,OAAS,EAC3BC,WAAYd,EACZF,WAAiBO,IAAVP,EAAsB,GAAKQ,OAAOR,GACzCiB,SAAU,SAACC,OACHC,WC9CpBnB,EACAW,OAQMS,GAAYpB,EACZqB,EAAS,MAAMC,KAAKtB,GACpBuB,EAAgB,SAASD,KAAKtB,UAEhCwB,EAAQxB,GACH,CACLyB,SAAS,EACTzB,WAAOO,GAIPmB,MAAMN,GACD,CACLK,SAAS,EACTzB,WAAOO,GAIE,YAATI,GAAsBU,EAGjB,CACLI,SAAS,EACTzB,MAJa2B,SAAS3B,EAAO,KAQ7BqB,IAAWE,EACN,CACLE,SAAS,EACTzB,MAAOoB,GAIJ,CACLK,SAAS,EACTzB,MAAOoB,GDCyBQ,CAAYV,EAAEW,OAAO7B,MAAOV,EAAMqB,MACtDrB,EAAMwC,YAAYX,EAAYM,SAC1BN,EAAYM,SACdtB,EAASgB,EAAYnB,cAWvCZ,EAAa2C,aAAe,CAC1BhC,qBAAqB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
|
-
import { TextInput } from '@contentful/forma-36-react-components';
|
|
3
2
|
import { FieldConnector } from '@contentful/field-editor-shared';
|
|
4
3
|
import isEmpty from 'lodash-es/isEmpty';
|
|
4
|
+
import { TextInput } from '@contentful/f36-components';
|
|
5
5
|
|
|
6
6
|
function parseNumber(value, type) {
|
|
7
7
|
// This has saner semantics than parseFloat.
|
|
@@ -73,9 +73,9 @@ function NumberEditor(props) {
|
|
|
73
73
|
max: range.max !== undefined ? String(range.max) : '',
|
|
74
74
|
step: field.type === 'Integer' ? '1' : '',
|
|
75
75
|
type: "number",
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
isRequired: field.required,
|
|
77
|
+
isInvalid: errors.length > 0,
|
|
78
|
+
isDisabled: disabled,
|
|
79
79
|
value: value === undefined ? '' : String(value),
|
|
80
80
|
onChange: function onChange(e) {
|
|
81
81
|
var parseResult = parseNumber(e.target.value, field.type);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-editor-number.esm.js","sources":["../src/parseNumber.ts","../src/NumberEditor.tsx"],"sourcesContent":["import isEmpty from 'lodash/isEmpty';\n\nexport function parseNumber(\n value: string,\n type: string\n): {\n isValid: boolean;\n value: number | undefined;\n} {\n // This has saner semantics than parseFloat.\n // For values with chars in 'em, it gives\n // us NaN unlike parseFloat\n const floatVal = +value;\n const hasDot = /\\./g.test(value);\n const hasFractional = /\\.\\d+/g.test(value);\n\n if (isEmpty(value)) {\n return {\n isValid: true,\n value: undefined
|
|
1
|
+
{"version":3,"file":"field-editor-number.esm.js","sources":["../src/parseNumber.ts","../src/NumberEditor.tsx"],"sourcesContent":["import isEmpty from 'lodash/isEmpty';\n\nexport function parseNumber(\n value: string,\n type: string\n): {\n isValid: boolean;\n value: number | undefined;\n} {\n // This has saner semantics than parseFloat.\n // For values with chars in 'em, it gives\n // us NaN unlike parseFloat\n const floatVal = +value;\n const hasDot = /\\./g.test(value);\n const hasFractional = /\\.\\d+/g.test(value);\n\n if (isEmpty(value)) {\n return {\n isValid: true,\n value: undefined,\n };\n }\n\n if (isNaN(floatVal)) {\n return {\n isValid: false,\n value: undefined,\n };\n }\n\n if (type === 'Integer' && hasDot) {\n const intVal = parseInt(value, 10);\n\n return {\n isValid: false,\n value: intVal,\n };\n }\n\n if (hasDot && !hasFractional) {\n return {\n isValid: false,\n value: floatVal,\n };\n }\n\n return {\n isValid: true,\n value: floatVal,\n };\n}\n","import * as React from 'react';\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport { parseNumber } from './parseNumber';\n\nimport { TextInput } from '@contentful/f36-components';\n\nexport interface NumberEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype RangeValidation = { min?: number; max?: number };\n\nfunction getRangeFromField(field: FieldAPI): RangeValidation {\n const validations = field.validations || [];\n const result = validations.find((validation) => (validation as any).range) as\n | { range: RangeValidation }\n | undefined;\n return result ? result.range : {};\n}\n\nexport function NumberEditor(props: NumberEditorProps) {\n const { field } = props;\n\n const range = getRangeFromField(field);\n\n return (\n <FieldConnector<number> field={field} isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => {\n return (\n <div data-test-id=\"number-editor\">\n <TextInput\n testId=\"number-editor-input\"\n min={range.min !== undefined ? String(range.min) : ''}\n max={range.max !== undefined ? String(range.max) : ''}\n step={field.type === 'Integer' ? '1' : ''}\n type=\"number\"\n isRequired={field.required}\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLInputElement>) => {\n const parseResult = parseNumber(e.target.value, field.type);\n field.setInvalid(!parseResult.isValid);\n if (parseResult.isValid) {\n setValue(parseResult.value);\n }\n }}\n />\n </div>\n );\n }}\n </FieldConnector>\n );\n}\n\nNumberEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseNumber","value","type","floatVal","hasDot","test","hasFractional","isEmpty","isValid","undefined","isNaN","intVal","parseInt","getRangeFromField","field","validations","result","find","validation","range","NumberEditor","props","React","FieldConnector","isInitiallyDisabled","errors","disabled","setValue","TextInput","testId","min","String","max","step","isRequired","required","isInvalid","length","isDisabled","onChange","e","parseResult","target","setInvalid","defaultProps"],"mappings":";;;;;SAEgBA,YACdC,OACAC;AAKA;AACA;AACA;AACA,MAAMC,QAAQ,GAAG,CAACF,KAAlB;AACA,MAAMG,MAAM,GAAG,MAAMC,IAAN,CAAWJ,KAAX,CAAf;AACA,MAAMK,aAAa,GAAG,SAASD,IAAT,CAAcJ,KAAd,CAAtB;;AAEA,MAAIM,OAAO,CAACN,KAAD,CAAX,EAAoB;AAClB,WAAO;AACLO,MAAAA,OAAO,EAAE,IADJ;AAELP,MAAAA,KAAK,EAAEQ;AAFF,KAAP;AAID;;AAED,MAAIC,KAAK,CAACP,QAAD,CAAT,EAA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AcrB,SAAd,GAA0BsB,MAAM,CAACZ,KAAK,CAACW,GAAP,CAAhC,GAA8C;AACnDE,MAAAA,GAAG,EAAEb,KAAK,CAACa,GAAN,KAAcvB,SAAd,GAA0BsB,MAAM,CAACZ,KAAK,CAACa,GAAP,CAAhC,GAA8C;AACnDC,MAAAA,IAAI,EAAEnB,KAAK,CAACZ,IAAN,KAAe,SAAf,GAA2B,GAA3B,GAAiC;AACvCA,MAAAA,IAAI,EAAC;AACLgC,MAAAA,UAAU,EAAEpB,KAAK,CAACqB;AAClBC,MAAAA,SAAS,EAAEX,MAAM,CAACY,MAAP,GAAgB;AAC3BC,MAAAA,UAAU,EAAEZ;AACZzB,MAAAA,KAAK,EAAEA,KAAK,KAAKQ,SAAV,GAAsB,EAAtB,GAA2BsB,MAAM,CAAC9B,KAAD;AACxCsC,MAAAA,QAAQ,EAAE,kBAACC,CAAD;AACR,YAAMC,WAAW,GAAGzC,WAAW,CAACwC,CAAC,CAACE,MAAF,CAASzC,KAAV,EAAiBa,KAAK,CAACZ,IAAvB,CAA/B;AACAY,QAAAA,KAAK,CAAC6B,UAAN,CAAiB,CAACF,WAAW,CAACjC,OAA9B;;AACA,YAAIiC,WAAW,CAACjC,OAAhB,EAAyB;AACvBmB,UAAAA,QAAQ,CAACc,WAAW,CAACxC,KAAb,CAAR;AACD;AACF;KAhBH,CADF,CADF;AAsBD,GAxBH,CADF;AA4BD;AAEDmB,YAAY,CAACwB,YAAb,GAA4B;AAC1BpB,EAAAA,mBAAmB,EAAE;AADK,CAA5B;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-number",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/field-editor-number.esm.js",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"tsc": "tsc -p ./ --noEmit"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@contentful/
|
|
25
|
-
"@contentful/
|
|
26
|
-
"@contentful/
|
|
24
|
+
"@contentful/f36-components": "^4.0.1-beta.2696",
|
|
25
|
+
"@contentful/f36-tokens": "^4.0.1-beta.2696",
|
|
26
|
+
"@contentful/field-editor-shared": "^1.0.2",
|
|
27
27
|
"emotion": "^10.0.17",
|
|
28
28
|
"lodash": "^4.17.15",
|
|
29
29
|
"lodash-es": "^4.17.15"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@contentful/field-editor-test-utils": "^0.
|
|
32
|
+
"@contentful/field-editor-test-utils": "^1.0.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"react": ">=16.8.0"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "7813114ba59222371e5b3f2c4d90464b75cb8d0d"
|
|
48
48
|
}
|