@contentful/field-editor-number 0.13.4 → 1.0.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.
- package/CHANGELOG.md +19 -81
- 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,178 +3,116 @@
|
|
|
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
|
-
|
|
6
|
+
# [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)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
9
9
|
|
|
10
|
+
# [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)
|
|
10
11
|
|
|
12
|
+
### Features
|
|
11
13
|
|
|
14
|
+
- Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
|
|
12
15
|
|
|
16
|
+
### BREAKING CHANGES
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @contentful/field-editor-number
|
|
18
|
+
- adopts a new Forma v4 beta
|
|
17
19
|
|
|
20
|
+
## [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)
|
|
18
21
|
|
|
22
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
19
23
|
|
|
24
|
+
## [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)
|
|
20
25
|
|
|
26
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
21
27
|
|
|
22
|
-
## [0.13.
|
|
28
|
+
## [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)
|
|
23
29
|
|
|
24
30
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
25
31
|
|
|
32
|
+
## [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)
|
|
26
33
|
|
|
34
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
27
35
|
|
|
36
|
+
## [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)
|
|
28
37
|
|
|
38
|
+
**Note:** Version bump only for package @contentful/field-editor-number
|
|
29
39
|
|
|
30
40
|
## [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)
|
|
31
41
|
|
|
32
42
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
33
43
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
44
|
# [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)
|
|
39
45
|
|
|
40
|
-
|
|
41
46
|
### Features
|
|
42
47
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
- 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
|
|
48
49
|
|
|
49
50
|
## [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)
|
|
50
51
|
|
|
51
52
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
54
|
## [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)
|
|
58
55
|
|
|
59
56
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
58
|
## [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)
|
|
66
59
|
|
|
67
60
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
62
|
## [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)
|
|
74
63
|
|
|
75
64
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
76
65
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
66
|
## [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)
|
|
82
67
|
|
|
83
68
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
84
69
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
70
|
## [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)
|
|
90
71
|
|
|
91
72
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
92
73
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
74
|
# [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)
|
|
98
75
|
|
|
99
|
-
|
|
100
76
|
### Features
|
|
101
77
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
78
|
+
- bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
|
|
107
79
|
|
|
108
80
|
## [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)
|
|
109
81
|
|
|
110
82
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
111
83
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
84
|
## [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)
|
|
117
85
|
|
|
118
86
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
119
87
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
88
|
# [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)
|
|
125
89
|
|
|
126
|
-
|
|
127
90
|
### Features
|
|
128
91
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
92
|
+
- 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))
|
|
134
93
|
|
|
135
94
|
# [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)
|
|
136
95
|
|
|
137
|
-
|
|
138
96
|
### Features
|
|
139
97
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
98
|
+
- 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))
|
|
145
99
|
|
|
146
100
|
## [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)
|
|
147
101
|
|
|
148
102
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
149
103
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
104
|
## [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)
|
|
155
105
|
|
|
156
106
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
157
107
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
108
|
## [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)
|
|
163
109
|
|
|
164
110
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
165
111
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
112
|
## [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)
|
|
171
113
|
|
|
172
114
|
**Note:** Version bump only for package @contentful/field-editor-number
|
|
173
115
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
116
|
## [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)
|
|
179
117
|
|
|
180
118
|
**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,C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AAEX,KAAK,CAACW,GAAN,KAAcrB,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;;;;"}
|
|
@@ -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","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|
|
@@ -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,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,IA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E,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.0",
|
|
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": "beta",
|
|
25
|
+
"@contentful/f36-tokens": "beta",
|
|
26
|
+
"@contentful/field-editor-shared": "^1.0.0",
|
|
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.0"
|
|
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": "538c2239a48991e4bb281d4d07d8ede3413492a5"
|
|
48
48
|
}
|