@contentful/field-editor-dropdown 0.14.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 CHANGED
@@ -3,178 +3,118 @@
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.14.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.3...@contentful/field-editor-dropdown@0.14.4) (2021-09-17)
6
+ # [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.16.0...@contentful/field-editor-dropdown@1.0.0) (2021-11-04)
7
7
 
8
8
  **Note:** Version bump only for package @contentful/field-editor-dropdown
9
9
 
10
+ # [0.16.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.15.1...@contentful/field-editor-dropdown@0.16.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
- ## [0.14.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.2...@contentful/field-editor-dropdown@0.14.3) (2021-09-16)
18
+ - adopts a new Forma v4 beta
15
19
 
16
- **Note:** Version bump only for package @contentful/field-editor-dropdown
20
+ ## [0.15.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.15.0...@contentful/field-editor-dropdown@0.15.1) (2021-10-14)
17
21
 
22
+ **Note:** Version bump only for package @contentful/field-editor-dropdown
18
23
 
24
+ # [0.15.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.4...@contentful/field-editor-dropdown@0.15.0) (2021-10-06)
19
25
 
26
+ ### Features
20
27
 
28
+ - [EXT-3161] bump app sdk to v4 ([#881](https://github.com/contentful/field-editors/issues/881)) ([9c4a2af](https://github.com/contentful/field-editors/commit/9c4a2af07da203d59fb5f15c3a5188ecc64b1d44))
21
29
 
22
- ## [0.14.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.1...@contentful/field-editor-dropdown@0.14.2) (2021-08-19)
30
+ ## [0.14.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.3...@contentful/field-editor-dropdown@0.14.4) (2021-09-17)
23
31
 
24
32
  **Note:** Version bump only for package @contentful/field-editor-dropdown
25
33
 
34
+ ## [0.14.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.2...@contentful/field-editor-dropdown@0.14.3) (2021-09-16)
26
35
 
36
+ **Note:** Version bump only for package @contentful/field-editor-dropdown
27
37
 
38
+ ## [0.14.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.1...@contentful/field-editor-dropdown@0.14.2) (2021-08-19)
28
39
 
40
+ **Note:** Version bump only for package @contentful/field-editor-dropdown
29
41
 
30
42
  ## [0.14.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.14.0...@contentful/field-editor-dropdown@0.14.1) (2021-07-29)
31
43
 
32
44
  **Note:** Version bump only for package @contentful/field-editor-dropdown
33
45
 
34
-
35
-
36
-
37
-
38
46
  # [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.6...@contentful/field-editor-dropdown@0.14.0) (2021-07-23)
39
47
 
40
-
41
48
  ### Features
42
49
 
43
- * 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
44
-
45
-
46
-
47
-
50
+ - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
48
51
 
49
52
  ## [0.13.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.3...@contentful/field-editor-dropdown@0.13.6) (2021-07-06)
50
53
 
51
54
  **Note:** Version bump only for package @contentful/field-editor-dropdown
52
55
 
53
-
54
-
55
-
56
-
57
56
  ## [0.13.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.3...@contentful/field-editor-dropdown@0.13.5) (2021-07-06)
58
57
 
59
58
  **Note:** Version bump only for package @contentful/field-editor-dropdown
60
59
 
61
-
62
-
63
-
64
-
65
60
  ## [0.13.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.3...@contentful/field-editor-dropdown@0.13.4) (2021-06-23)
66
61
 
67
62
  **Note:** Version bump only for package @contentful/field-editor-dropdown
68
63
 
69
-
70
-
71
-
72
-
73
64
  ## [0.13.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.2...@contentful/field-editor-dropdown@0.13.3) (2021-06-23)
74
65
 
75
66
  **Note:** Version bump only for package @contentful/field-editor-dropdown
76
67
 
77
-
78
-
79
-
80
-
81
68
  ## [0.13.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.1...@contentful/field-editor-dropdown@0.13.2) (2021-06-22)
82
69
 
83
70
  **Note:** Version bump only for package @contentful/field-editor-dropdown
84
71
 
85
-
86
-
87
-
88
-
89
72
  ## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.13.0...@contentful/field-editor-dropdown@0.13.1) (2021-03-05)
90
73
 
91
74
  **Note:** Version bump only for package @contentful/field-editor-dropdown
92
75
 
93
-
94
-
95
-
96
-
97
76
  # [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.12.2...@contentful/field-editor-dropdown@0.13.0) (2021-02-19)
98
77
 
99
-
100
78
  ### Features
101
79
 
102
- * bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
103
-
104
-
105
-
106
-
80
+ - 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
81
 
108
82
  ## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.12.1...@contentful/field-editor-dropdown@0.12.2) (2021-02-09)
109
83
 
110
84
  **Note:** Version bump only for package @contentful/field-editor-dropdown
111
85
 
112
-
113
-
114
-
115
-
116
86
  ## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.12.0...@contentful/field-editor-dropdown@0.12.1) (2021-02-01)
117
87
 
118
88
  **Note:** Version bump only for package @contentful/field-editor-dropdown
119
89
 
120
-
121
-
122
-
123
-
124
90
  # [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.11.0...@contentful/field-editor-dropdown@0.12.0) (2021-01-20)
125
91
 
126
-
127
92
  ### Features
128
93
 
129
- * 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))
130
-
131
-
132
-
133
-
94
+ - 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
95
 
135
96
  # [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.5...@contentful/field-editor-dropdown@0.11.0) (2021-01-12)
136
97
 
137
-
138
98
  ### Features
139
99
 
140
- * 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))
141
-
142
-
143
-
144
-
100
+ - 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
101
 
146
102
  ## [0.10.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.4...@contentful/field-editor-dropdown@0.10.5) (2020-12-16)
147
103
 
148
104
  **Note:** Version bump only for package @contentful/field-editor-dropdown
149
105
 
150
-
151
-
152
-
153
-
154
106
  ## [0.10.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.3...@contentful/field-editor-dropdown@0.10.4) (2020-11-06)
155
107
 
156
108
  **Note:** Version bump only for package @contentful/field-editor-dropdown
157
109
 
158
-
159
-
160
-
161
-
162
110
  ## [0.10.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.2...@contentful/field-editor-dropdown@0.10.3) (2020-11-06)
163
111
 
164
112
  **Note:** Version bump only for package @contentful/field-editor-dropdown
165
113
 
166
-
167
-
168
-
169
-
170
114
  ## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.1...@contentful/field-editor-dropdown@0.10.2) (2020-10-28)
171
115
 
172
116
  **Note:** Version bump only for package @contentful/field-editor-dropdown
173
117
 
174
-
175
-
176
-
177
-
178
118
  ## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-dropdown@0.10.0...@contentful/field-editor-dropdown@0.10.1) (2020-08-24)
179
119
 
180
120
  **Note:** Version bump only for package @contentful/field-editor-dropdown
package/README.md CHANGED
@@ -7,6 +7,5 @@ npm install @contentful/field-editor-dropdown
7
7
  This package contains a React `DropdownEditor` component that is used for the `Text`,`Symbol`,`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 { DropdownEditor } from '@contentful/field-editor-dropdown';
12
11
  ```
@@ -3,10 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
- var forma36ReactComponents = require('@contentful/forma-36-react-components');
7
6
  var fieldEditorShared = require('@contentful/field-editor-shared');
8
7
  var nanoid = require('nanoid');
9
8
  var emotion = require('emotion');
9
+ var f36Components = require('@contentful/f36-components');
10
10
 
11
11
  function parseValue(value, fieldType) {
12
12
  if (value === '') {
@@ -64,21 +64,21 @@ function DropdownEditor(props) {
64
64
  errors = _ref.errors,
65
65
  disabled = _ref.disabled,
66
66
  setValue = _ref.setValue;
67
- return React.createElement(forma36ReactComponents.Select, {
67
+ return React.createElement(f36Components.Select, {
68
68
  testId: "dropdown-editor",
69
- hasError: errors.length > 0,
69
+ isInvalid: errors.length > 0,
70
70
  isDisabled: disabled,
71
71
  className: direction === 'rtl' ? rightToLeft : '',
72
- required: field.required,
72
+ isRequired: field.required,
73
73
  value: value === undefined ? '' : String(value),
74
74
  onChange: function onChange(e) {
75
75
  var value = e.target.value;
76
76
  setValue(parseValue(value, field.type));
77
77
  }
78
- }, React.createElement(forma36ReactComponents.Option, {
78
+ }, React.createElement(f36Components.Select.Option, {
79
79
  value: ""
80
80
  }, "Choose a value"), options.map(function (option) {
81
- return React.createElement(forma36ReactComponents.Option, {
81
+ return React.createElement(f36Components.Select.Option, {
82
82
  key: option.value,
83
83
  value: String(option.value)
84
84
  }, option.label);
@@ -1 +1 @@
1
- {"version":3,"file":"field-editor-dropdown.cjs.development.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter(validation => (validation as any).in)\n .map(validation => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value)\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl'\n});\n","import * as React from 'react';\nimport { Select, Option } from '@contentful/forma-36-react-components';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n hasError={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n required={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Option value=\"\">Choose a value</Option>\n {options.map((option) => (\n <Option key={option.value} value={String(option.value)}>\n {option.label}\n </Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","undefined","asNumber","Number","isNaN","getOptions","field","validations","predefinedValues","filter","validation","map","firstPredefinedValues","length","id","nanoid","type","label","String","item","rightToLeft","css","direction","DropdownEditor","props","locales","options","misconfigured","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","errors","disabled","setValue","Select","testId","hasError","isDisabled","className","styles","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":";;;;;;;;;;SASgBA,WAAWC,OAAeC;AACxC,MAAID,KAAK,KAAK,EAAd,EAAkB;AAChB,WAAOE,SAAP;AACD;;AACD,MAAID,SAAS,KAAK,SAAd,IAA2BA,SAAS,KAAK,QAA7C,EAAuD;AACrD,QAAME,QAAQ,GAAGC,MAAM,CAACJ,KAAD,CAAvB;AACA,WAAOK,KAAK,CAACF,QAAD,CAAL,GAAkBD,SAAlB,GAA8BC,QAArC;AACD;;AACD,SAAOH,KAAP;AACD;SAEeM,WAAWC;AACzB;AACA,MAAMC,WAAW,GAAGD,KAAK,CAACC,WAAN,IAAqB,EAAzC;AACA,MAAMC,gBAAgB,GAAGD,WAAW,CACjCE,MADsB,CACf,UAAAC,UAAU;AAAA,WAAKA,UAAkB,MAAvB;AAAA,GADK,EAEtBC,GAFsB,CAElB,UAAAD,UAAU;AAAA,WAAKA,UAAkB,MAAvB;AAAA,GAFQ,CAAzB;AAIA,MAAME,qBAAqB,GAAGJ,gBAAgB,CAACK,MAAjB,GAA0B,CAA1B,GAA8BL,gBAAgB,CAAC,CAAD,CAA9C,GAAoD,EAAlF;AAEA,SAAOI,qBAAqB,CACzBD,GADI,CACA,UAACZ,KAAD;AAAA,WAAoB;AACvBe,MAAAA,EAAE,EAAEC,aAAM,CAAC,CAAD,CADa;AAEvBhB,MAAAA,KAAK,EAAED,UAAU,CAACC,KAAD,EAAQO,KAAK,CAACU,IAAd,CAFM;AAGvBC,MAAAA,KAAK,EAAEC,MAAM,CAACnB,KAAD;AAHU,KAApB;AAAA,GADA,EAMJU,MANI,CAMG,UAACU,IAAD;AACN,WAAOA,IAAI,CAACpB,KAAL,KAAeE,SAAtB;AACD,GARI,CAAP;AASD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A,QAAQ,CAACtC,UAAU,CAACC,KAAD,EAAQO,KAAK,CAACU,IAAd,CAAX,CAAR;AACD;KAVH,EAWEY,mBAAA,CAACmB,6BAAD;AAAQhD,MAAAA,KAAK,EAAC;KAAd,kBAAA,CAXF,EAYG2B,OAAO,CAACf,GAAR,CAAY,UAACqC,MAAD;AAAA,aACXpB,mBAAA,CAACmB,6BAAD;AAAQE,QAAAA,GAAG,EAAED,MAAM,CAACjD;AAAOA,QAAAA,KAAK,EAAEmB,MAAM,CAAC8B,MAAM,CAACjD,KAAR;OAAxC,EACGiD,MAAM,CAAC/B,KADV,CADW;AAAA,KAAZ,CAZH,CADD;AAAA,GAJH,CADF;AA2BD;AAEDM,cAAc,CAAC2B,YAAf,GAA8B;AAC5BjB,EAAAA,mBAAmB,EAAE;AADO,CAA9B;;;;;;"}
1
+ {"version":3,"file":"field-editor-dropdown.cjs.development.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter((validation) => (validation as any).in)\n .map((validation) => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value),\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nimport { Select } from '@contentful/f36-components';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Select.Option value=\"\">Choose a value</Select.Option>\n {options.map((option) => (\n <Select.Option key={option.value} value={String(option.value)}>\n {option.label}\n </Select.Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","undefined","asNumber","Number","isNaN","getOptions","field","validations","predefinedValues","filter","validation","map","firstPredefinedValues","length","id","nanoid","type","label","String","item","rightToLeft","css","direction","DropdownEditor","props","locales","options","misconfigured","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","errors","disabled","setValue","Select","testId","isInvalid","isDisabled","className","styles","isRequired","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":";;;;;;;;;;SASgBA,WAAWC,OAAeC;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ACXrB,mBAAA,CAACS,oBAAM,CAACW,MAAR;AAAeE,QAAAA,GAAG,EAAED,MAAM,CAAClD;AAAOA,QAAAA,KAAK,EAAEmB,MAAM,CAAC+B,MAAM,CAAClD,KAAR;OAA/C,EACGkD,MAAM,CAAChC,KADV,CADW;AAAA,KAAZ,CAZH,CADD;AAAA,GAJH,CADF;AA2BD;AAEDM,cAAc,CAAC4B,YAAf,GAA8B;AAC5BlB,EAAAA,mBAAmB,EAAE;AADO,CAA9B;;;;;;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@contentful/forma-36-react-components"),t=require("@contentful/field-editor-shared"),n=require("nanoid");function i(e,r){if(""!==e){if("Integer"===r||"Number"===r){var t=Number(e);return isNaN(t)?void 0:t}return e}}function l(e){var r=(e.validations||[]).filter((function(e){return e.in})).map((function(e){return e.in}));return(r.length>0?r[0]:[]).map((function(r){return{id:n.nanoid(6),value:i(r,e.type),label:String(r)}})).filter((function(e){return void 0!==e.value}))}var a=require("emotion").css({direction:"rtl"});function o(n){var o=n.field,u=n.locales,d=l(o);if(0===d.length)return e.createElement(t.PredefinedValuesError,null);var s=u.direction[o.locale]||"ltr";return e.createElement(t.FieldConnector,{throttle:0,field:o,isInitiallyDisabled:n.isInitiallyDisabled},(function(t){var n=t.value,l=t.setValue;return e.createElement(r.Select,{testId:"dropdown-editor",hasError:t.errors.length>0,isDisabled:t.disabled,className:"rtl"===s?a:"",required:o.required,value:void 0===n?"":String(n),onChange:function(e){l(i(e.target.value,o.type))}},e.createElement(r.Option,{value:""},"Choose a value"),d.map((function(t){return e.createElement(r.Option,{key:t.value,value:String(t.value)},t.label)})))}))}o.defaultProps={isInitiallyDisabled:!0},exports.DropdownEditor=o,exports.getOptions=l,exports.parseValue=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),r=require("@contentful/field-editor-shared"),t=require("nanoid"),n=require("emotion"),i=require("@contentful/f36-components");function l(e,r){if(""!==e){if("Integer"===r||"Number"===r){var t=Number(e);return isNaN(t)?void 0:t}return e}}function a(e){var r=(e.validations||[]).filter((function(e){return e.in})).map((function(e){return e.in}));return(r.length>0?r[0]:[]).map((function(r){return{id:t.nanoid(6),value:l(r,e.type),label:String(r)}})).filter((function(e){return void 0!==e.value}))}var o=n.css({direction:"rtl"});function u(t){var n=t.field,u=t.locales,d=a(n);if(0===d.length)return e.createElement(r.PredefinedValuesError,null);var s=u.direction[n.locale]||"ltr";return e.createElement(r.FieldConnector,{throttle:0,field:n,isInitiallyDisabled:t.isInitiallyDisabled},(function(r){var t=r.value,a=r.setValue;return e.createElement(i.Select,{testId:"dropdown-editor",isInvalid:r.errors.length>0,isDisabled:r.disabled,className:"rtl"===s?o:"",isRequired:n.required,value:void 0===t?"":String(t),onChange:function(e){a(l(e.target.value,n.type))}},e.createElement(i.Select.Option,{value:""},"Choose a value"),d.map((function(r){return e.createElement(i.Select.Option,{key:r.value,value:String(r.value)},r.label)})))}))}u.defaultProps={isInitiallyDisabled:!0},exports.DropdownEditor=u,exports.getOptions=a,exports.parseValue=l;
2
2
  //# sourceMappingURL=field-editor-dropdown.cjs.production.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"field-editor-dropdown.cjs.production.min.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter(validation => (validation as any).in)\n .map(validation => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value)\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl'\n});\n","import * as React from 'react';\nimport { Select, Option } from '@contentful/forma-36-react-components';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n hasError={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n required={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Option value=\"\">Choose a value</Option>\n {options.map((option) => (\n <Option key={option.value} value={String(option.value)}>\n {option.label}\n </Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","asNumber","Number","isNaN","undefined","getOptions","field","predefinedValues","validations","filter","validation","map","length","id","nanoid","type","label","String","item","rightToLeft","direction","DropdownEditor","props","locales","options","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","setValue","Select","testId","hasError","errors","isDisabled","disabled","className","styles","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":"wNASgBA,EAAWC,EAAeC,MAC1B,KAAVD,MAGc,YAAdC,GAAyC,WAAdA,EAAwB,KAC/CC,EAAWC,OAAOH,UACjBI,MAAMF,QAAYG,EAAYH,SAEhCF,YAGOM,EAAWC,OAGnBC,GADcD,EAAME,aAAe,IAEtCC,QAAO,SAAAC,UAAeA,QACtBC,KAAI,SAAAD,UAAeA,eAEQH,EAAiBK,OAAS,EAAIL,EAAiB,GAAK,IAG/EI,KAAI,SAACZ,SAAmB,CACvBc,GAAIC,SAAO,GACXf,MAAOD,EAAWC,EAAOO,EAAMS,MAC/BC,MAAOC,OAAOlB,OAEfU,QAAO,SAACS,eACed,IAAfc,EAAKnB,SClCX,IAAMoB,yBAAkB,CAC7BC,UAAW,iBCwBGC,EAAeC,OACrBhB,EAAmBgB,EAAnBhB,MAAOiB,EAAYD,EAAZC,QAETC,EAAUnB,EAAWC,MACc,IAAnBkB,EAAQZ,cAGrBa,gBAACC,kCAGJN,EAAYG,EAAQH,UAAUd,EAAMqB,SAAW,aAGnDF,gBAACG,kBACCC,SAAU,EACVvB,MAAOA,EACPwB,oBAAqBR,EAAMQ,sBAC1B,gBAAG/B,IAAAA,MAAyBgC,IAAAA,gBAC3BN,gBAACO,UACCC,OAAO,kBACPC,WAHOC,OAGUvB,OAAS,EAC1BwB,aAJeC,SAKfC,UAAyB,QAAdlB,EAAsBmB,EAAqB,GACtDC,SAAUlC,EAAMkC,SAChBzC,WAAiBK,IAAVL,EAAsB,GAAKkB,OAAOlB,GACzC0C,SAAU,SAACC,GAETX,EAASjC,EADK4C,EAAEC,OAAO5C,MACIO,EAAMS,SAEnCU,gBAACmB,UAAO7C,MAAM,sBACbyB,EAAQb,KAAI,SAACkC,UACZpB,gBAACmB,UAAOE,IAAKD,EAAO9C,MAAOA,MAAOkB,OAAO4B,EAAO9C,QAC7C8C,EAAO7B,cAStBK,EAAe0B,aAAe,CAC5BjB,qBAAqB"}
1
+ {"version":3,"file":"field-editor-dropdown.cjs.production.min.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter((validation) => (validation as any).in)\n .map((validation) => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value),\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nimport { Select } from '@contentful/f36-components';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Select.Option value=\"\">Choose a value</Select.Option>\n {options.map((option) => (\n <Select.Option key={option.value} value={String(option.value)}>\n {option.label}\n </Select.Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","asNumber","Number","isNaN","undefined","getOptions","field","predefinedValues","validations","filter","validation","map","length","id","nanoid","type","label","String","item","rightToLeft","css","direction","DropdownEditor","props","locales","options","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","setValue","Select","testId","isInvalid","errors","isDisabled","disabled","className","styles","isRequired","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":"kOASgBA,EAAWC,EAAeC,MAC1B,KAAVD,MAGc,YAAdC,GAAyC,WAAdA,EAAwB,KAC/CC,EAAWC,OAAOH,UACjBI,MAAMF,QAAYG,EAAYH,SAEhCF,YAGOM,EAAWC,OAGnBC,GADcD,EAAME,aAAe,IAEtCC,QAAO,SAACC,UAAgBA,QACxBC,KAAI,SAACD,UAAgBA,eAEMH,EAAiBK,OAAS,EAAIL,EAAiB,GAAK,IAG/EI,KAAI,SAACZ,SAAmB,CACvBc,GAAIC,SAAO,GACXf,MAAOD,EAAWC,EAAOO,EAAMS,MAC/BC,MAAOC,OAAOlB,OAEfU,QAAO,SAACS,eACed,IAAfc,EAAKnB,SClCX,IAAMoB,EAAcC,MAAI,CAC7BC,UAAW,iBCyBGC,EAAeC,OACrBjB,EAAmBiB,EAAnBjB,MAAOkB,EAAYD,EAAZC,QAETC,EAAUpB,EAAWC,MACc,IAAnBmB,EAAQb,cAGrBc,gBAACC,kCAGJN,EAAYG,EAAQH,UAAUf,EAAMsB,SAAW,aAGnDF,gBAACG,kBACCC,SAAU,EACVxB,MAAOA,EACPyB,oBAAqBR,EAAMQ,sBAC1B,gBAAGhC,IAAAA,MAAyBiC,IAAAA,gBAC3BN,gBAACO,UACCC,OAAO,kBACPC,YAHOC,OAGWxB,OAAS,EAC3ByB,aAJeC,SAKfC,UAAyB,QAAdlB,EAAsBmB,EAAqB,GACtDC,WAAYnC,EAAMoC,SAClB3C,WAAiBK,IAAVL,EAAsB,GAAKkB,OAAOlB,GACzC4C,SAAU,SAACC,GAETZ,EAASlC,EADK8C,EAAEC,OAAO9C,MACIO,EAAMS,SAEnCW,gBAACO,SAAOa,QAAO/C,MAAM,sBACpB0B,EAAQd,KAAI,SAACoC,UACZrB,gBAACO,SAAOa,QAAOE,IAAKD,EAAOhD,MAAOA,MAAOkB,OAAO8B,EAAOhD,QACpDgD,EAAO/B,cAStBM,EAAe2B,aAAe,CAC5BlB,qBAAqB"}
@@ -1,8 +1,8 @@
1
1
  import { createElement } from 'react';
2
- import { Select, Option } from '@contentful/forma-36-react-components';
3
2
  import { PredefinedValuesError, FieldConnector } from '@contentful/field-editor-shared';
4
3
  import { nanoid } from 'nanoid';
5
4
  import { css } from 'emotion';
5
+ import { Select } from '@contentful/f36-components';
6
6
 
7
7
  function parseValue(value, fieldType) {
8
8
  if (value === '') {
@@ -62,19 +62,19 @@ function DropdownEditor(props) {
62
62
  setValue = _ref.setValue;
63
63
  return createElement(Select, {
64
64
  testId: "dropdown-editor",
65
- hasError: errors.length > 0,
65
+ isInvalid: errors.length > 0,
66
66
  isDisabled: disabled,
67
67
  className: direction === 'rtl' ? rightToLeft : '',
68
- required: field.required,
68
+ isRequired: field.required,
69
69
  value: value === undefined ? '' : String(value),
70
70
  onChange: function onChange(e) {
71
71
  var value = e.target.value;
72
72
  setValue(parseValue(value, field.type));
73
73
  }
74
- }, createElement(Option, {
74
+ }, createElement(Select.Option, {
75
75
  value: ""
76
76
  }, "Choose a value"), options.map(function (option) {
77
- return createElement(Option, {
77
+ return createElement(Select.Option, {
78
78
  key: option.value,
79
79
  value: String(option.value)
80
80
  }, option.label);
@@ -1 +1 @@
1
- {"version":3,"file":"field-editor-dropdown.esm.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter(validation => (validation as any).in)\n .map(validation => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value)\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl'\n});\n","import * as React from 'react';\nimport { Select, Option } from '@contentful/forma-36-react-components';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n hasError={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n required={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Option value=\"\">Choose a value</Option>\n {options.map((option) => (\n <Option key={option.value} value={String(option.value)}>\n {option.label}\n </Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","undefined","asNumber","Number","isNaN","getOptions","field","validations","predefinedValues","filter","validation","map","firstPredefinedValues","length","id","nanoid","type","label","String","item","rightToLeft","css","direction","DropdownEditor","props","locales","options","misconfigured","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","errors","disabled","setValue","Select","testId","hasError","isDisabled","className","styles","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":";;;;;;SASgBA,WAAWC,OAAeC;AACxC,MAAID,KAAK,KAAK,EAAd,EAAkB;AAChB,WAAOE,SAAP;AACD;;AACD,MAAID,SAAS,KAAK,SAAd,IAA2BA,SAAS,KAAK,QAA7C,EAAuD;AACrD,QAAME,QAAQ,GAAGC,MAAM,CAACJ,KAAD,CAAvB;AACA,WAAOK,KAAK,CAACF,QAAD,CAAL,GAAkBD,SAAlB,GAA8BC,QAArC;AACD;;AACD,SAAOH,KAAP;AACD;SAEeM,WAAWC;AACz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version":3,"file":"field-editor-dropdown.esm.js","sources":["../src/dropdownUtils.ts","../src/styles.ts","../src/DropdownEditor.tsx"],"sourcesContent":["import { nanoid } from 'nanoid';\nimport { FieldAPI } from '@contentful/field-editor-shared';\n\ntype DropdownOption = {\n id: string;\n value: string | number | undefined;\n label: string;\n};\n\nexport function parseValue(value: string, fieldType: string): string | number | undefined {\n if (value === '') {\n return undefined;\n }\n if (fieldType === 'Integer' || fieldType === 'Number') {\n const asNumber = Number(value);\n return isNaN(asNumber) ? undefined : asNumber;\n }\n return value;\n}\n\nexport function getOptions(field: FieldAPI): DropdownOption[] {\n // Get first object that has a 'in' property\n const validations = field.validations || [];\n const predefinedValues = validations\n .filter((validation) => (validation as any).in)\n .map((validation) => (validation as any).in);\n\n const firstPredefinedValues = predefinedValues.length > 0 ? predefinedValues[0] : [];\n\n return firstPredefinedValues\n .map((value: string) => ({\n id: nanoid(6),\n value: parseValue(value, field.type),\n label: String(value),\n }))\n .filter((item: { value: string | number | undefined; label: string }) => {\n return item.value !== undefined;\n });\n}\n","import { css } from 'emotion';\n\nexport const rightToLeft = css({\n direction: 'rtl',\n});\n","import * as React from 'react';\nimport {\n FieldAPI,\n FieldConnector,\n PredefinedValuesError,\n LocalesAPI,\n} from '@contentful/field-editor-shared';\nimport { getOptions, parseValue } from './dropdownUtils';\nimport * as styles from './styles';\n\nimport { Select } from '@contentful/f36-components';\n\nexport interface DropdownEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n /**\n * sdk.field\n */\n field: FieldAPI;\n\n /**\n * sdk.locales\n */\n locales: LocalesAPI;\n}\n\nexport function DropdownEditor(props: DropdownEditorProps) {\n const { field, locales } = props;\n\n const options = getOptions(field);\n const misconfigured = options.length === 0;\n\n if (misconfigured) {\n return <PredefinedValuesError />;\n }\n\n const direction = locales.direction[field.locale] || 'ltr';\n\n return (\n <FieldConnector<string | number>\n throttle={0}\n field={field}\n isInitiallyDisabled={props.isInitiallyDisabled}>\n {({ value, errors, disabled, setValue }) => (\n <Select\n testId=\"dropdown-editor\"\n isInvalid={errors.length > 0}\n isDisabled={disabled}\n className={direction === 'rtl' ? styles.rightToLeft : ''}\n isRequired={field.required}\n value={value === undefined ? '' : String(value)}\n onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {\n const value = e.target.value;\n setValue(parseValue(value, field.type));\n }}>\n <Select.Option value=\"\">Choose a value</Select.Option>\n {options.map((option) => (\n <Select.Option key={option.value} value={String(option.value)}>\n {option.label}\n </Select.Option>\n ))}\n </Select>\n )}\n </FieldConnector>\n );\n}\n\nDropdownEditor.defaultProps = {\n isInitiallyDisabled: true,\n};\n"],"names":["parseValue","value","fieldType","undefined","asNumber","Number","isNaN","getOptions","field","validations","predefinedValues","filter","validation","map","firstPredefinedValues","length","id","nanoid","type","label","String","item","rightToLeft","css","direction","DropdownEditor","props","locales","options","misconfigured","React","PredefinedValuesError","locale","FieldConnector","throttle","isInitiallyDisabled","errors","disabled","setValue","Select","testId","isInvalid","isDisabled","className","styles","isRequired","required","onChange","e","target","Option","option","key","defaultProps"],"mappings":";;;;;;SASgBA,WAAWC,OAAeC;AACxC,MAAID,KAAK,KAAK,EAAd,EAAkB;AAChB,WAAOE,SAAP;AACD;;AACD,MAAID,SAAS,KAAK,SAAd,IAA2BA,SAAS,KAAK,QAA7C,EAAuD;AACrD,QAAME,QAAQ,GAAGC,MAAM,CAACJ,KAAD,CAAvB;AACA,WAAOK,KAAK,CAACF,QAAD,CAAL,GAAkBD,SAAlB,GAA8BC,QAArC;AACD;;AACD,SAAOH,KAAP;AACD;SAEeM,WAAWC;AACzB;AACA,MAAMC,WAAW,GAAGD,KAAK,CAACC,WAAN,IAAqB,EAAzC;AACA,MAAMC,gBAAgB,GAAGD,WAAW,CACjCE,MADsB,CACf,UAACC,UAAD;AAAA,WAAiBA,UAAkB,MAAnC;AAAA,GADe,EAEtBC,GAFsB,CAElB,UAACD,UAAD;AAAA,WAAiBA,UAAkB,MAAnC;AAAA,GAFkB,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B,QAA4BA,QAA5B;AAAA,WACCR,aAAA,CAACS,MAAD;AACEC,MAAAA,MAAM,EAAC;AACPC,MAAAA,SAAS,EAAEL,MAAM,CAACrB,MAAP,GAAgB;AAC3B2B,MAAAA,UAAU,EAAEL;AACZM,MAAAA,SAAS,EAAEnB,SAAS,KAAK,KAAd,GAAsBoB,WAAtB,GAA2C;AACtDC,MAAAA,UAAU,EAAErC,KAAK,CAACsC;AAClB7C,MAAAA,KAAK,EAAEA,KAAK,KAAKE,SAAV,GAAsB,EAAtB,GAA2BiB,MAAM,CAACnB,KAAD;AACxC8C,MAAAA,QAAQ,EAAE,kBAACC,CAAD;AACR,YAAM/C,KAAK,GAAG+C,CAAC,CAACC,MAAF,CAAShD,KAAvB;AACAqC,QAAAA,QAAQ,CAACtC,UAAU,CAACC,KAAD,EAAQO,KAAK,CAACU,IAAd,CAAX,CAAR;AACD;KAVH,EAWEY,aAAA,CAACS,MAAM,CAACW,MAAR;AAAejD,MAAAA,KAAK,EAAC;KAArB,kBAAA,CAXF,EAYG2B,OAAO,CAACf,GAAR,CAAY,UAACsC,MAAD;AAAA,aACXrB,aAAA,CAACS,MAAM,CAACW,MAAR;AAAeE,QAAAA,GAAG,EAAED,MAAM,CAAClD;AAAOA,QAAAA,KAAK,EAAEmB,MAAM,CAAC+B,MAAM,CAAClD,KAAR;OAA/C,EACGkD,MAAM,CAAChC,KADV,CADW;AAAA,KAAZ,CAZH,CADD;AAAA,GAJH,CADF;AA2BD;AAEDM,cAAc,CAAC4B,YAAf,GAA8B;AAC5BlB,EAAAA,mBAAmB,EAAE;AADO,CAA9B;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-dropdown",
3
- "version": "0.14.4",
3
+ "version": "1.0.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/field-editor-dropdown.esm.js",
6
6
  "typings": "dist/index.d.ts",
@@ -21,16 +21,17 @@
21
21
  "tsc": "tsc -p ./ --noEmit"
22
22
  },
23
23
  "dependencies": {
24
- "@contentful/field-editor-shared": "^0.24.0",
25
- "@contentful/forma-36-react-components": "^3.93.4",
26
- "@contentful/forma-36-tokens": "^0.11.0",
24
+ "@contentful/f36-components": "beta",
25
+ "@contentful/f36-tokens": "beta",
26
+ "@contentful/field-editor-shared": "^1.0.0",
27
27
  "emotion": "^10.0.0",
28
28
  "lodash": "^4.17.15",
29
29
  "lodash-es": "^4.17.15",
30
30
  "nanoid": "^3.1.3"
31
31
  },
32
32
  "devDependencies": {
33
- "@contentful/field-editor-test-utils": "^0.17.3"
33
+ "@contentful/field-editor-test-utils": "^1.0.0",
34
+ "contentful-management": "^7.42.1"
34
35
  },
35
36
  "peerDependencies": {
36
37
  "react": ">=16.8.0"
@@ -45,5 +46,5 @@
45
46
  }
46
47
  }
47
48
  },
48
- "gitHead": "f5450f62e92802984fb32a4dd28f266aabbdd5d7"
49
+ "gitHead": "538c2239a48991e4bb281d4d07d8ede3413492a5"
49
50
  }