@contentful/field-editor-json 3.2.0 → 3.3.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 DELETED
@@ -1,290 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
-
6
- # [3.2.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.7...@contentful/field-editor-json@3.2.0) (2023-04-19)
7
-
8
- ### Features
9
-
10
- - upgrade cypress [TOL-1036] ([#1391](https://github.com/contentful/field-editors/issues/1391)) ([9c1aec9](https://github.com/contentful/field-editors/commit/9c1aec98aabbe464cdc3f1236c3bb1cc29b8208d))
11
-
12
- ## [3.1.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.6...@contentful/field-editor-json@3.1.7) (2023-03-14)
13
-
14
- **Note:** Version bump only for package @contentful/field-editor-json
15
-
16
- ## [3.1.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.5...@contentful/field-editor-json@3.1.6) (2023-03-10)
17
-
18
- **Note:** Version bump only for package @contentful/field-editor-json
19
-
20
- ## [3.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.4...@contentful/field-editor-json@3.1.5) (2023-02-21)
21
-
22
- **Note:** Version bump only for package @contentful/field-editor-json
23
-
24
- ## [3.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.3...@contentful/field-editor-json@3.1.4) (2023-02-07)
25
-
26
- **Note:** Version bump only for package @contentful/field-editor-json
27
-
28
- ## [3.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.2...@contentful/field-editor-json@3.1.3) (2022-12-08)
29
-
30
- **Note:** Version bump only for package @contentful/field-editor-json
31
-
32
- ## [3.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.1...@contentful/field-editor-json@3.1.2) (2022-11-07)
33
-
34
- ### Bug Fixes
35
-
36
- - disable search keymap option to prevent breaking on search [ZEND-2879] ([#1277](https://github.com/contentful/field-editors/issues/1277)) ([0ce1426](https://github.com/contentful/field-editors/commit/0ce14261afd83b013344303254f9e97912911abd))
37
-
38
- ## [3.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.1.0...@contentful/field-editor-json@3.1.1) (2022-10-07)
39
-
40
- **Note:** Version bump only for package @contentful/field-editor-json
41
-
42
- # [3.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.0.1...@contentful/field-editor-json@3.1.0) (2022-08-25)
43
-
44
- ### Features
45
-
46
- - add line wrapping to the JSON editor ([#1221](https://github.com/contentful/field-editors/issues/1221)) ([9ab1e80](https://github.com/contentful/field-editors/commit/9ab1e802516b44b0e0cba5f3084e5481eb57c024))
47
-
48
- ## [3.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@3.0.0...@contentful/field-editor-json@3.0.1) (2022-07-29)
49
-
50
- **Note:** Version bump only for package @contentful/field-editor-json
51
-
52
- # [3.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@2.1.4...@contentful/field-editor-json@3.0.0) (2022-07-29)
53
-
54
- ### chore
55
-
56
- - remove unnecessary codemirror import from json-editor ([#1205](https://github.com/contentful/field-editors/issues/1205)) ([87d378b](https://github.com/contentful/field-editors/commit/87d378b006aa79f237e49ab945d0cb7696228bbb))
57
-
58
- ### BREAKING CHANGES
59
-
60
- - update codemirror from 5 to 6
61
-
62
- - fix: make release BREAKING CHANGE
63
-
64
- - fix!: make release BREAKING CHANGE
65
-
66
- - fix!: make release breaking change
67
-
68
- - fix!: make release breaking change
69
-
70
- - feat!: make release BREAKING CHANGE
71
-
72
- - fix: make major release due to breaking change
73
-
74
- - chore: remove unnecessary codemirror import in json editor
75
-
76
- ## [2.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@2.1.3...@contentful/field-editor-json@2.1.4) (2022-07-29)
77
-
78
- **Note:** Version bump only for package @contentful/field-editor-json
79
-
80
- ## [2.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@2.1.2...@contentful/field-editor-json@2.1.3) (2022-07-28)
81
-
82
- ### Bug Fixes
83
-
84
- - remove custom theme from jsonEditor ([#1201](https://github.com/contentful/field-editors/issues/1201)) ([6eefb13](https://github.com/contentful/field-editors/commit/6eefb13d58fee12e0bc50e456c06f160f26dfebe))
85
-
86
- ## [2.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@2.1.1...@contentful/field-editor-json@2.1.2) (2022-07-26)
87
-
88
- ### Bug Fixes
89
-
90
- - add white background to json editor ([#1200](https://github.com/contentful/field-editors/issues/1200)) ([56437c0](https://github.com/contentful/field-editors/commit/56437c0dd0183bf4219ada812f8045bc15f0028b))
91
-
92
- ## [2.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@2.1.0...@contentful/field-editor-json@2.1.1) (2022-07-25)
93
-
94
- ### Bug Fixes
95
-
96
- - remove old codemirror imports from json editor, cleanup ([#1199](https://github.com/contentful/field-editors/issues/1199)) ([9703eb2](https://github.com/contentful/field-editors/commit/9703eb277ccf76330c85cc21eaa28f55986f296b))
97
-
98
- # [2.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.5...@contentful/field-editor-json@2.1.0) (2022-07-22)
99
-
100
- ### Features
101
-
102
- - replace react-codemirror2 with @uiw/react-codemirror to allow codemirror 6 ([#1193](https://github.com/contentful/field-editors/issues/1193)) ([dbdb0ae](https://github.com/contentful/field-editors/commit/dbdb0ae3eaf2c63b00e87195210986b22c15987f))
103
-
104
- ## [1.1.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.4...@contentful/field-editor-json@1.1.5) (2022-07-11)
105
-
106
- **Note:** Version bump only for package @contentful/field-editor-json
107
-
108
- ## [1.1.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.3...@contentful/field-editor-json@1.1.4) (2022-06-22)
109
-
110
- **Note:** Version bump only for package @contentful/field-editor-json
111
-
112
- ## [1.1.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.2...@contentful/field-editor-json@1.1.3) (2022-05-04)
113
-
114
- ### Bug Fixes
115
-
116
- - reflect disabled state on fields ([#1125](https://github.com/contentful/field-editors/issues/1125)) ([01502b9](https://github.com/contentful/field-editors/commit/01502b9d785c5f782b0e5de782d092c439cb690f))
117
-
118
- ## [1.1.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.1...@contentful/field-editor-json@1.1.2) (2022-02-15)
119
-
120
- ### Bug Fixes
121
-
122
- - bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
123
-
124
- ## [1.1.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.1.0...@contentful/field-editor-json@1.1.1) (2022-02-14)
125
-
126
- **Note:** Version bump only for package @contentful/field-editor-json
127
-
128
- # [1.1.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.0.3...@contentful/field-editor-json@1.1.0) (2022-01-11)
129
-
130
- ### Features
131
-
132
- - bump f36 packages to stable v4 [BAU-521] ([#988](https://github.com/contentful/field-editors/issues/988)) ([419cf56](https://github.com/contentful/field-editors/commit/419cf56692179b074fcfa2743469d5265ed98429))
133
-
134
- ## [1.0.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.0.2...@contentful/field-editor-json@1.0.3) (2021-12-23)
135
-
136
- ### Bug Fixes
137
-
138
- - markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
139
-
140
- ## [1.0.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.0.1...@contentful/field-editor-json@1.0.2) (2021-12-20)
141
-
142
- **Note:** Version bump only for package @contentful/field-editor-json
143
-
144
- ## [1.0.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@1.0.0...@contentful/field-editor-json@1.0.1) (2021-11-17)
145
-
146
- ### Bug Fixes
147
-
148
- - **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))
149
-
150
- # [1.0.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.14.0...@contentful/field-editor-json@1.0.0) (2021-11-04)
151
-
152
- **Note:** Version bump only for package @contentful/field-editor-json
153
-
154
- # [0.14.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.13.1...@contentful/field-editor-json@0.14.0) (2021-11-04)
155
-
156
- ### Features
157
-
158
- - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
159
-
160
- ### BREAKING CHANGES
161
-
162
- - adopts a new Forma v4 beta
163
-
164
- ## [0.13.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.13.0...@contentful/field-editor-json@0.13.1) (2021-10-14)
165
-
166
- **Note:** Version bump only for package @contentful/field-editor-json
167
-
168
- # [0.13.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.12.4...@contentful/field-editor-json@0.13.0) (2021-10-06)
169
-
170
- ### Features
171
-
172
- - [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))
173
-
174
- ## [0.12.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.12.3...@contentful/field-editor-json@0.12.4) (2021-09-17)
175
-
176
- **Note:** Version bump only for package @contentful/field-editor-json
177
-
178
- ## [0.12.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.12.2...@contentful/field-editor-json@0.12.3) (2021-09-16)
179
-
180
- **Note:** Version bump only for package @contentful/field-editor-json
181
-
182
- ## [0.12.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.12.1...@contentful/field-editor-json@0.12.2) (2021-08-19)
183
-
184
- **Note:** Version bump only for package @contentful/field-editor-json
185
-
186
- ## [0.12.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.12.0...@contentful/field-editor-json@0.12.1) (2021-07-29)
187
-
188
- **Note:** Version bump only for package @contentful/field-editor-json
189
-
190
- # [0.12.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.7...@contentful/field-editor-json@0.12.0) (2021-07-23)
191
-
192
- ### Features
193
-
194
- - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
195
-
196
- ## [0.11.7](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.4...@contentful/field-editor-json@0.11.7) (2021-07-06)
197
-
198
- **Note:** Version bump only for package @contentful/field-editor-json
199
-
200
- ## [0.11.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.4...@contentful/field-editor-json@0.11.6) (2021-07-06)
201
-
202
- **Note:** Version bump only for package @contentful/field-editor-json
203
-
204
- ## [0.11.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.4...@contentful/field-editor-json@0.11.5) (2021-06-23)
205
-
206
- **Note:** Version bump only for package @contentful/field-editor-json
207
-
208
- ## [0.11.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.3...@contentful/field-editor-json@0.11.4) (2021-06-23)
209
-
210
- **Note:** Version bump only for package @contentful/field-editor-json
211
-
212
- ## [0.11.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.2...@contentful/field-editor-json@0.11.3) (2021-06-22)
213
-
214
- **Note:** Version bump only for package @contentful/field-editor-json
215
-
216
- ## [0.11.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.1...@contentful/field-editor-json@0.11.2) (2021-04-14)
217
-
218
- ### Bug Fixes
219
-
220
- - [] auto refresh json and markdown when rendered out of view ([#684](https://github.com/contentful/field-editors/issues/684)) ([faea939](https://github.com/contentful/field-editors/commit/faea93910c934f6ed74ebe4a949ee1d2eea7b28b))
221
-
222
- ## [0.11.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.11.0...@contentful/field-editor-json@0.11.1) (2021-03-05)
223
-
224
- **Note:** Version bump only for package @contentful/field-editor-json
225
-
226
- # [0.11.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.10.3...@contentful/field-editor-json@0.11.0) (2021-02-19)
227
-
228
- ### Features
229
-
230
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
231
-
232
- ## [0.10.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.10.2...@contentful/field-editor-json@0.10.3) (2021-02-09)
233
-
234
- **Note:** Version bump only for package @contentful/field-editor-json
235
-
236
- ## [0.10.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.10.1...@contentful/field-editor-json@0.10.2) (2021-02-01)
237
-
238
- **Note:** Version bump only for package @contentful/field-editor-json
239
-
240
- ## [0.10.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.10.0...@contentful/field-editor-json@0.10.1) (2021-01-25)
241
-
242
- **Note:** Version bump only for package @contentful/field-editor-json
243
-
244
- # [0.10.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.9.1...@contentful/field-editor-json@0.10.0) (2021-01-20)
245
-
246
- ### Features
247
-
248
- - 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))
249
-
250
- ## [0.9.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.9.0...@contentful/field-editor-json@0.9.1) (2021-01-14)
251
-
252
- ### Bug Fixes
253
-
254
- - 🐛 use tokens for border-radius ([ec56c06](https://github.com/contentful/field-editors/commit/ec56c06ddd01718086a96c4cb2bc2877071644a9))
255
-
256
- # [0.9.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.6...@contentful/field-editor-json@0.9.0) (2021-01-12)
257
-
258
- ### Features
259
-
260
- - 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))
261
-
262
- ## [0.8.6](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.5...@contentful/field-editor-json@0.8.6) (2020-12-16)
263
-
264
- **Note:** Version bump only for package @contentful/field-editor-json
265
-
266
- ## [0.8.5](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.4...@contentful/field-editor-json@0.8.5) (2020-11-23)
267
-
268
- **Note:** Version bump only for package @contentful/field-editor-json
269
-
270
- ## [0.8.4](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.3...@contentful/field-editor-json@0.8.4) (2020-11-06)
271
-
272
- **Note:** Version bump only for package @contentful/field-editor-json
273
-
274
- ## [0.8.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.2...@contentful/field-editor-json@0.8.3) (2020-11-06)
275
-
276
- **Note:** Version bump only for package @contentful/field-editor-json
277
-
278
- ## [0.8.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.1...@contentful/field-editor-json@0.8.2) (2020-10-28)
279
-
280
- **Note:** Version bump only for package @contentful/field-editor-json
281
-
282
- ## [0.8.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.8.0...@contentful/field-editor-json@0.8.1) (2020-08-27)
283
-
284
- **Note:** Version bump only for package @contentful/field-editor-json
285
-
286
- # [0.8.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-json@0.7.0...@contentful/field-editor-json@0.8.0) (2020-08-24)
287
-
288
- ### Features
289
-
290
- - extract field component to default-field-editors package ([#365](https://github.com/contentful/field-editors/issues/365)) ([eb78219](https://github.com/contentful/field-editors/commit/eb78219d52c3dcfb91824f3106f44312aaaf1f8e))
@@ -1,2 +0,0 @@
1
- /// <reference types="react" />
2
- export declare function JsonInvalidStatus(): JSX.Element;
@@ -1,315 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- var React = require('react');
8
- var React__default = _interopDefault(React);
9
- var fieldEditorShared = require('@contentful/field-editor-shared');
10
- var deepEqual = _interopDefault(require('deep-equal'));
11
- var throttle = _interopDefault(require('lodash/throttle'));
12
- var langJson = require('@codemirror/lang-json');
13
- var view = require('@codemirror/view');
14
- var tokens = _interopDefault(require('@contentful/f36-tokens'));
15
- var CodeMirror = _interopDefault(require('@uiw/react-codemirror'));
16
- var emotion = require('emotion');
17
- var f36Components = require('@contentful/f36-components');
18
-
19
- const styles = {
20
- root: /*#__PURE__*/emotion.css({
21
- cursor: 'text',
22
- padding: tokens.spacingS,
23
- border: `1px solid ${tokens.gray200}`,
24
- borderTop: 'none',
25
- borderBottomLeftRadius: tokens.borderRadiusSmall,
26
- borderBottomRightRadius: tokens.borderRadiusSmall,
27
- fontSize: tokens.fontSizeM,
28
- '.cm-editor': {
29
- color: tokens.gray900,
30
- '&.cm-focused': {
31
- outline: 'none'
32
- }
33
- },
34
- '.cm-scroller': {
35
- fontFamily: tokens.fontStackMonospace,
36
- minHeight: '6rem'
37
- },
38
- '&.disabled': {
39
- cursor: 'auto',
40
- '.cm-scroller ': {
41
- minHeight: '6rem',
42
- backgroundColor: tokens.gray100,
43
- cursor: 'not-allowed'
44
- },
45
- '.cm-editor': {
46
- border: `1px solid ${tokens.gray200}`
47
- },
48
- '.cm-line': {
49
- cursor: 'not-allowed'
50
- },
51
- '.cm-lines': {
52
- cursor: 'not-allowed'
53
- }
54
- }
55
- })
56
- };
57
- function JsonEditorField(props) {
58
- return React__default.createElement("div", {
59
- className: emotion.cx(styles.root, {
60
- disabled: props.isDisabled
61
- }),
62
- "data-test-id": "json-editor-code-mirror"
63
- }, React__default.createElement(CodeMirror, {
64
- value: props.value,
65
- onChange: props.onChange,
66
- theme: "light",
67
- extensions: [langJson.json(), view.EditorView.lineWrapping],
68
- basicSetup: {
69
- closeBrackets: false,
70
- lineNumbers: false,
71
- highlightActiveLineGutter: false,
72
- searchKeymap: false,
73
- highlightActiveLine: false,
74
- foldGutter: false,
75
- bracketMatching: false,
76
- syntaxHighlighting: false
77
- },
78
- width: "100%",
79
- editable: !props.isDisabled,
80
- indentWithTab: true
81
- }));
82
- }
83
-
84
- const styles$1 = {
85
- toolbar: /*#__PURE__*/emotion.css({
86
- display: 'flex',
87
- alignItems: 'center',
88
- padding: tokens.spacingXs,
89
- justifyContent: 'space-between',
90
- backgroundColor: tokens.gray100,
91
- border: `1px solid ${tokens.gray200}`,
92
- borderTopLeftRadius: tokens.borderRadiusSmall,
93
- borderTopRightRadius: tokens.borderRadiusSmall,
94
- borderBottom: 'none'
95
- }),
96
- title: /*#__PURE__*/emotion.css({
97
- fontFamily: tokens.fontStackPrimary,
98
- fontSize: tokens.fontSizeM,
99
- color: tokens.gray600
100
- }),
101
- actions: /*#__PURE__*/emotion.css({
102
- button: {
103
- marginLeft: tokens.spacingS
104
- }
105
- })
106
- };
107
- function JsonEditorToolbar(props) {
108
- return React__default.createElement("div", {
109
- className: styles$1.toolbar
110
- }, React__default.createElement("div", {
111
- className: styles$1.title
112
- }, "JSON Editor"), React__default.createElement("div", {
113
- className: styles$1.actions
114
- }, React__default.createElement(f36Components.Button, {
115
- variant: "secondary",
116
- size: "small",
117
- isDisabled: props.isUndoDisabled,
118
- testId: "json-editor-undo",
119
- onClick: () => {
120
- props.onUndo();
121
- }
122
- }, "Undo"), React__default.createElement(f36Components.Button, {
123
- variant: "secondary",
124
- size: "small",
125
- isDisabled: props.isRedoDisabled,
126
- testId: "json-editor-redo",
127
- onClick: () => {
128
- props.onRedo();
129
- }
130
- }, "Redo")));
131
- }
132
-
133
- function JsonInvalidStatus() {
134
- return React__default.createElement("div", {
135
- role: "status",
136
- "data-test-id": "json-editor.invalid-json",
137
- className: emotion.css({
138
- marginTop: tokens.spacingS
139
- })
140
- }, React__default.createElement(f36Components.ValidationMessage, null, "This is not valid JSON"));
141
- }
142
-
143
- function stringifyJSON(obj) {
144
- if (obj === null || obj === undefined) {
145
- return '';
146
- } else {
147
- return JSON.stringify(obj, null, 4);
148
- }
149
- }
150
- function isValidJson(str) {
151
- let parsed;
152
-
153
- try {
154
- parsed = JSON.parse(str);
155
- } catch (e) {
156
- return false;
157
- } // An object or array is valid JSON
158
-
159
-
160
- if (typeof parsed !== 'object') {
161
- return false;
162
- }
163
-
164
- return true;
165
- }
166
- function parseJSON(str) {
167
- if (str === '') {
168
- return {
169
- value: undefined,
170
- valid: true
171
- };
172
- } else if (isValidJson(str)) {
173
- return {
174
- value: JSON.parse(str),
175
- valid: true
176
- };
177
- } else {
178
- return {
179
- value: undefined,
180
- valid: false
181
- };
182
- }
183
- }
184
-
185
- class ConnectedJsonEditor extends React.Component {
186
- constructor(props) {
187
- super(props);
188
-
189
- this.setValidJson = value => {
190
- this.setState({
191
- isValidJson: value
192
- });
193
- };
194
-
195
- this.pushUndo = throttle(value => {
196
- this.setState(state => ({
197
- undoStack: [...state.undoStack, value]
198
- }));
199
- }, 400);
200
-
201
- this.onChange = value => {
202
- const parsed = parseJSON(value);
203
-
204
- if (value !== this.state.lastUndo) {
205
- this.pushUndo(this.state.value);
206
- }
207
-
208
- this.setState({
209
- value,
210
- isValidJson: parsed.valid
211
- });
212
-
213
- if (parsed.valid) {
214
- this.props.setValue(parsed.value);
215
- }
216
- };
217
-
218
- this.onUndo = () => {
219
- const undoStack = this.state.undoStack;
220
-
221
- if (undoStack.length === 0) {
222
- return;
223
- }
224
-
225
- const value = undoStack.pop() || '';
226
- const parsedValue = parseJSON(value);
227
- this.setState(state => ({ ...state,
228
- value,
229
- isValidJson: parsedValue.valid,
230
- undoStack,
231
- redoStack: [...state.redoStack, state.value],
232
- lastUndo: value
233
- }), () => {
234
- if (parsedValue.valid) {
235
- this.props.setValue(parsedValue.value);
236
- }
237
- });
238
- };
239
-
240
- this.onRedo = () => {
241
- const redoStack = [...this.state.redoStack];
242
-
243
- if (redoStack.length === 0) {
244
- return;
245
- }
246
-
247
- const value = redoStack.pop() || '';
248
- const parsedValue = parseJSON(value);
249
- this.setState(state => ({ ...state,
250
- value,
251
- isValidJson: parsedValue.valid,
252
- redoStack,
253
- undoStack: [...state.undoStack, state.value]
254
- }), () => {
255
- if (parsedValue.valid) {
256
- this.props.setValue(parsedValue.value);
257
- }
258
- });
259
- };
260
-
261
- this.state = {
262
- value: stringifyJSON(props.initialValue),
263
- isValidJson: true,
264
- undoStack: [],
265
- redoStack: [],
266
- lastUndo: ''
267
- };
268
- }
269
-
270
- render() {
271
- return React.createElement("div", {
272
- "data-test-id": "json-editor"
273
- }, React.createElement(JsonEditorToolbar, {
274
- isRedoDisabled: this.props.disabled || this.state.redoStack.length === 0,
275
- isUndoDisabled: this.props.disabled || this.state.undoStack.length === 0,
276
- onUndo: this.onUndo,
277
- onRedo: this.onRedo
278
- }), React.createElement(JsonEditorField, {
279
- value: this.state.value,
280
- onChange: this.onChange,
281
- isDisabled: this.props.disabled
282
- }), !this.state.isValidJson && React.createElement(JsonInvalidStatus, null));
283
- }
284
-
285
- }
286
-
287
- ConnectedJsonEditor.defaultProps = {
288
- isInitiallyDisabled: true
289
- };
290
- function JsonEditor(props) {
291
- return React.createElement(fieldEditorShared.FieldConnector, {
292
- field: props.field,
293
- isInitiallyDisabled: props.isInitiallyDisabled,
294
- isEqualValues: (value1, value2) => {
295
- return deepEqual(value1, value2);
296
- }
297
- }, ({
298
- value,
299
- disabled,
300
- setValue,
301
- externalReset
302
- }) => {
303
- return React.createElement(ConnectedJsonEditor // on external change reset component completely and init with initial value again
304
- , {
305
- // on external change reset component completely and init with initial value again
306
- key: `json-editor-${externalReset}`,
307
- initialValue: value,
308
- disabled: disabled,
309
- setValue: setValue
310
- });
311
- });
312
- }
313
-
314
- exports.JsonEditor = JsonEditor;
315
- //# sourceMappingURL=field-editor-json.cjs.development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"field-editor-json.cjs.development.js","sources":["../src/JsonEditorField.tsx","../src/JsonEditorToolbar.tsx","../src/JsonInvalidStatus.tsx","../src/utils.ts","../src/JsonEditor.tsx"],"sourcesContent":["import React from 'react';\n\nimport { json } from '@codemirror/lang-json';\nimport { EditorView } from '@codemirror/view';\nimport tokens from '@contentful/f36-tokens';\nimport CodeMirror from '@uiw/react-codemirror';\nimport { css, cx } from 'emotion';\n\ntype JsonEditorFieldProps = {\n isDisabled: boolean;\n value: string;\n onChange: (value: string) => void;\n};\n\nconst styles = {\n root: css({\n cursor: 'text',\n padding: tokens.spacingS,\n border: `1px solid ${tokens.gray200}`,\n borderTop: 'none',\n borderBottomLeftRadius: tokens.borderRadiusSmall,\n borderBottomRightRadius: tokens.borderRadiusSmall,\n fontSize: tokens.fontSizeM,\n '.cm-editor': {\n color: tokens.gray900,\n '&.cm-focused': {\n outline: 'none',\n },\n },\n '.cm-scroller': {\n fontFamily: tokens.fontStackMonospace,\n minHeight: '6rem',\n },\n '&.disabled': {\n cursor: 'auto',\n '.cm-scroller ': {\n minHeight: '6rem',\n backgroundColor: tokens.gray100,\n cursor: 'not-allowed',\n },\n '.cm-editor': {\n border: `1px solid ${tokens.gray200}`,\n },\n '.cm-line': {\n cursor: 'not-allowed',\n },\n '.cm-lines': {\n cursor: 'not-allowed',\n },\n },\n }),\n};\n\nexport function JsonEditorField(props: JsonEditorFieldProps) {\n return (\n <div\n className={cx(styles.root, { disabled: props.isDisabled })}\n data-test-id=\"json-editor-code-mirror\"\n >\n <CodeMirror\n value={props.value}\n onChange={props.onChange}\n theme=\"light\"\n extensions={[json(), EditorView.lineWrapping]}\n basicSetup={{\n closeBrackets: false,\n lineNumbers: false,\n highlightActiveLineGutter: false,\n searchKeymap: false,\n highlightActiveLine: false,\n foldGutter: false,\n bracketMatching: false,\n syntaxHighlighting: false,\n }}\n width=\"100%\"\n editable={!props.isDisabled}\n indentWithTab={true}\n />\n </div>\n );\n}\n","import React from 'react';\n\nimport { Button } from '@contentful/f36-components';\nimport tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nconst styles = {\n toolbar: css({\n display: 'flex',\n alignItems: 'center',\n padding: tokens.spacingXs,\n justifyContent: 'space-between',\n backgroundColor: tokens.gray100,\n border: `1px solid ${tokens.gray200}`,\n borderTopLeftRadius: tokens.borderRadiusSmall,\n borderTopRightRadius: tokens.borderRadiusSmall,\n borderBottom: 'none',\n }),\n title: css({\n fontFamily: tokens.fontStackPrimary,\n fontSize: tokens.fontSizeM,\n color: tokens.gray600,\n }),\n actions: css({\n button: {\n marginLeft: tokens.spacingS,\n },\n }),\n};\n\ntype JsonEditorToolbarProps = {\n isUndoDisabled: boolean;\n isRedoDisabled: boolean;\n onRedo: () => void;\n onUndo: () => void;\n};\n\nexport function JsonEditorToolbar(props: JsonEditorToolbarProps) {\n return (\n <div className={styles.toolbar}>\n <div className={styles.title}>JSON Editor</div>\n <div className={styles.actions}>\n <Button\n variant=\"secondary\"\n size=\"small\"\n isDisabled={props.isUndoDisabled}\n testId=\"json-editor-undo\"\n onClick={() => {\n props.onUndo();\n }}>\n Undo\n </Button>\n <Button\n variant=\"secondary\"\n size=\"small\"\n isDisabled={props.isRedoDisabled}\n testId=\"json-editor-redo\"\n onClick={() => {\n props.onRedo();\n }}>\n Redo\n </Button>\n </div>\n </div>\n );\n}\n","import React from 'react';\n\nimport { ValidationMessage } from '@contentful/f36-components';\nimport tokens from '@contentful/f36-tokens';\nimport { css } from 'emotion';\n\nexport function JsonInvalidStatus() {\n return (\n <div\n role=\"status\"\n data-test-id=\"json-editor.invalid-json\"\n className={css({ marginTop: tokens.spacingS })}>\n <ValidationMessage>This is not valid JSON</ValidationMessage>\n </div>\n );\n}\n","import { JSONObject } from './types';\n\nexport function stringifyJSON(obj: JSONObject | null | undefined): string {\n if (obj === null || obj === undefined) {\n return '';\n } else {\n return JSON.stringify(obj, null, 4);\n }\n}\n\nexport function isValidJson(str: string) {\n let parsed;\n try {\n parsed = JSON.parse(str);\n } catch (e) {\n return false;\n }\n // An object or array is valid JSON\n if (typeof parsed !== 'object') {\n return false;\n }\n return true;\n}\n\nexport function parseJSON(str: string): { valid: boolean; value?: JSONObject } {\n if (str === '') {\n return {\n value: undefined,\n valid: true,\n };\n } else if (isValidJson(str)) {\n return {\n value: JSON.parse(str),\n valid: true,\n };\n } else {\n return {\n value: undefined,\n valid: false,\n };\n }\n}\n","import * as React from 'react';\n\nimport { FieldAPI, FieldConnector } from '@contentful/field-editor-shared';\nimport deepEqual from 'deep-equal';\nimport throttle from 'lodash/throttle';\n\nimport { JsonEditorField } from './JsonEditorField';\nimport { JsonEditorToolbar } from './JsonEditorToolbar';\nimport { JsonInvalidStatus } from './JsonInvalidStatus';\nimport { JSONObject } from './types';\nimport { stringifyJSON, parseJSON } from './utils';\n\nexport interface JsonEditorProps {\n /**\n * is the field disabled initially\n */\n isInitiallyDisabled: boolean;\n\n /**\n * sdk.field\n */\n field: FieldAPI;\n}\n\ntype NullableJsonObject = JSONObject | null | undefined;\n\ntype ConnectedJsonEditorProps = {\n initialValue: NullableJsonObject;\n setValue: (value: NullableJsonObject) => void;\n disabled: boolean;\n};\n\ntype ConnectedJsonEditorState = {\n value: string;\n isValidJson: boolean;\n undoStack: string[];\n redoStack: string[];\n lastUndo: string;\n};\n\nclass ConnectedJsonEditor extends React.Component<\n ConnectedJsonEditorProps,\n ConnectedJsonEditorState\n> {\n static defaultProps = {\n isInitiallyDisabled: true,\n };\n\n constructor(props: ConnectedJsonEditorProps) {\n super(props);\n this.state = {\n value: stringifyJSON(props.initialValue),\n isValidJson: true,\n undoStack: [],\n redoStack: [],\n lastUndo: '',\n };\n }\n\n setValidJson = (value: boolean) => {\n this.setState({\n isValidJson: value,\n });\n };\n\n pushUndo = throttle((value: string) => {\n this.setState((state) => ({\n undoStack: [...state.undoStack, value],\n }));\n }, 400);\n\n onChange = (value: string) => {\n const parsed = parseJSON(value);\n\n if (value !== this.state.lastUndo) {\n this.pushUndo(this.state.value);\n }\n\n this.setState({\n value,\n isValidJson: parsed.valid,\n });\n\n if (parsed.valid) {\n this.props.setValue(parsed.value);\n }\n };\n\n onUndo = () => {\n const undoStack = this.state.undoStack;\n\n if (undoStack.length === 0) {\n return;\n }\n\n const value = undoStack.pop() || '';\n\n const parsedValue = parseJSON(value);\n\n this.setState(\n (state) => ({\n ...state,\n value,\n isValidJson: parsedValue.valid,\n undoStack,\n redoStack: [...state.redoStack, state.value],\n lastUndo: value,\n }),\n () => {\n if (parsedValue.valid) {\n this.props.setValue(parsedValue.value);\n }\n }\n );\n };\n\n onRedo = () => {\n const redoStack = [...this.state.redoStack];\n\n if (redoStack.length === 0) {\n return;\n }\n\n const value = redoStack.pop() || '';\n\n const parsedValue = parseJSON(value);\n\n this.setState(\n (state) => ({\n ...state,\n value,\n isValidJson: parsedValue.valid,\n redoStack,\n undoStack: [...state.undoStack, state.value],\n }),\n () => {\n if (parsedValue.valid) {\n this.props.setValue(parsedValue.value);\n }\n }\n );\n };\n\n render() {\n return (\n <div data-test-id=\"json-editor\">\n <JsonEditorToolbar\n isRedoDisabled={this.props.disabled || this.state.redoStack.length === 0}\n isUndoDisabled={this.props.disabled || this.state.undoStack.length === 0}\n onUndo={this.onUndo}\n onRedo={this.onRedo}\n />\n <JsonEditorField\n value={this.state.value}\n onChange={this.onChange}\n isDisabled={this.props.disabled}\n />\n {!this.state.isValidJson && <JsonInvalidStatus />}\n </div>\n );\n }\n}\n\nexport default function JsonEditor(props: JsonEditorProps) {\n return (\n <FieldConnector<JSONObject>\n field={props.field}\n isInitiallyDisabled={props.isInitiallyDisabled}\n isEqualValues={(value1, value2) => {\n return deepEqual(value1, value2);\n }}>\n {({ value, disabled, setValue, externalReset }) => {\n return (\n <ConnectedJsonEditor\n // on external change reset component completely and init with initial value again\n key={`json-editor-${externalReset}`}\n initialValue={value}\n disabled={disabled}\n setValue={setValue}\n />\n );\n }}\n </FieldConnector>\n );\n}\n"],"names":["styles","root","css","cursor","padding","tokens","spacingS","border","gray200","borderTop","borderBottomLeftRadius","borderRadiusSmall","borderBottomRightRadius","fontSize","fontSizeM","color","gray900","outline","fontFamily","fontStackMonospace","minHeight","backgroundColor","gray100","JsonEditorField","props","React","className","cx","disabled","isDisabled","CodeMirror","value","onChange","theme","extensions","json","EditorView","lineWrapping","basicSetup","closeBrackets","lineNumbers","highlightActiveLineGutter","searchKeymap","highlightActiveLine","foldGutter","bracketMatching","syntaxHighlighting","width","editable","indentWithTab","toolbar","display","alignItems","spacingXs","justifyContent","borderTopLeftRadius","borderTopRightRadius","borderBottom","title","fontStackPrimary","gray600","actions","button","marginLeft","JsonEditorToolbar","Button","variant","size","isUndoDisabled","testId","onClick","onUndo","isRedoDisabled","onRedo","JsonInvalidStatus","role","marginTop","ValidationMessage","stringifyJSON","obj","undefined","JSON","stringify","isValidJson","str","parsed","parse","e","parseJSON","valid","ConnectedJsonEditor","constructor","setValidJson","setState","pushUndo","throttle","state","undoStack","lastUndo","setValue","length","pop","parsedValue","redoStack","initialValue","render","defaultProps","isInitiallyDisabled","JsonEditor","FieldConnector","field","isEqualValues","value1","value2","deepEqual","externalReset","key"],"mappings":";;;;;;;;;;;;;;;;;;AAcA,MAAMA,MAAM,GAAG;AACbC,EAAAA,IAAI,eAAEC,WAAG,CAAC;AACRC,IAAAA,MAAM,EAAE,MADA;AAERC,IAAAA,OAAO,EAAEC,MAAM,CAACC,QAFR;AAGRC,IAAAA,MAAM,eAAeF,MAAM,CAACG,SAHpB;AAIRC,IAAAA,SAAS,EA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aAAa,EAAE,CAACC,MAAD,EAASC,MAAT;AACb,aAAOC,SAAS,CAACF,MAAD,EAASC,MAAT,CAAhB;AACD;GALH,EAMG,CAAC;AAAElF,IAAAA,KAAF;AAASH,IAAAA,QAAT;AAAmBuE,IAAAA,QAAnB;AAA6BgB,IAAAA;AAA7B,GAAD;AACC,WACE1F,mBAAA,CAACiE,mBAAD;AAAA;AACE;AACA0B,MAAAA,GAAG,iBAAiBD;AACpBX,MAAAA,YAAY,EAAEzE;AACdH,MAAAA,QAAQ,EAAEA;AACVuE,MAAAA,QAAQ,EAAEA;KALZ,CADF;AASD,GAhBH,CADF;AAoBD;;;;"}
@@ -1,2 +0,0 @@
1
- "use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),i=e(t),o=require("@contentful/field-editor-shared"),a=e(require("deep-equal")),s=e(require("lodash/throttle")),n=require("@codemirror/lang-json"),r=require("@codemirror/view"),l=e(require("@contentful/f36-tokens")),d=e(require("@uiw/react-codemirror")),c=require("emotion"),u=require("@contentful/f36-components");const h={root:c.css({cursor:"text",padding:l.spacingS,border:"1px solid "+l.gray200,borderTop:"none",borderBottomLeftRadius:l.borderRadiusSmall,borderBottomRightRadius:l.borderRadiusSmall,fontSize:l.fontSizeM,".cm-editor":{color:l.gray900,"&.cm-focused":{outline:"none"}},".cm-scroller":{fontFamily:l.fontStackMonospace,minHeight:"6rem"},"&.disabled":{cursor:"auto",".cm-scroller ":{minHeight:"6rem",backgroundColor:l.gray100,cursor:"not-allowed"},".cm-editor":{border:"1px solid "+l.gray200},".cm-line":{cursor:"not-allowed"},".cm-lines":{cursor:"not-allowed"}}})};function m(e){return i.createElement("div",{className:c.cx(h.root,{disabled:e.isDisabled}),"data-test-id":"json-editor-code-mirror"},i.createElement(d,{value:e.value,onChange:e.onChange,theme:"light",extensions:[n.json(),r.EditorView.lineWrapping],basicSetup:{closeBrackets:!1,lineNumbers:!1,highlightActiveLineGutter:!1,searchKeymap:!1,highlightActiveLine:!1,foldGutter:!1,bracketMatching:!1,syntaxHighlighting:!1},width:"100%",editable:!e.isDisabled,indentWithTab:!0}))}const p={toolbar:c.css({display:"flex",alignItems:"center",padding:l.spacingXs,justifyContent:"space-between",backgroundColor:l.gray100,border:"1px solid "+l.gray200,borderTopLeftRadius:l.borderRadiusSmall,borderTopRightRadius:l.borderRadiusSmall,borderBottom:"none"}),title:c.css({fontFamily:l.fontStackPrimary,fontSize:l.fontSizeM,color:l.gray600}),actions:c.css({button:{marginLeft:l.spacingS}})};function b(e){return i.createElement("div",{className:p.toolbar},i.createElement("div",{className:p.title},"JSON Editor"),i.createElement("div",{className:p.actions},i.createElement(u.Button,{variant:"secondary",size:"small",isDisabled:e.isUndoDisabled,testId:"json-editor-undo",onClick:()=>{e.onUndo()}},"Undo"),i.createElement(u.Button,{variant:"secondary",size:"small",isDisabled:e.isRedoDisabled,testId:"json-editor-redo",onClick:()=>{e.onRedo()}},"Redo")))}function v(){return i.createElement("div",{role:"status","data-test-id":"json-editor.invalid-json",className:c.css({marginTop:l.spacingS})},i.createElement(u.ValidationMessage,null,"This is not valid JSON"))}function g(e){return""===e?{value:void 0,valid:!0}:function(e){let t;try{t=JSON.parse(e)}catch(e){return!1}return"object"==typeof t}(e)?{value:JSON.parse(e),valid:!0}:{value:void 0,valid:!1}}class f extends t.Component{constructor(e){var t;super(e),this.setValidJson=e=>{this.setState({isValidJson:e})},this.pushUndo=s(e=>{this.setState(t=>({undoStack:[...t.undoStack,e]}))},400),this.onChange=e=>{const t=g(e);e!==this.state.lastUndo&&this.pushUndo(this.state.value),this.setState({value:e,isValidJson:t.valid}),t.valid&&this.props.setValue(t.value)},this.onUndo=()=>{const e=this.state.undoStack;if(0===e.length)return;const t=e.pop()||"",i=g(t);this.setState(o=>({...o,value:t,isValidJson:i.valid,undoStack:e,redoStack:[...o.redoStack,o.value],lastUndo:t}),()=>{i.valid&&this.props.setValue(i.value)})},this.onRedo=()=>{const e=[...this.state.redoStack];if(0===e.length)return;const t=e.pop()||"",i=g(t);this.setState(o=>({...o,value:t,isValidJson:i.valid,redoStack:e,undoStack:[...o.undoStack,o.value]}),()=>{i.valid&&this.props.setValue(i.value)})},this.state={value:(t=e.initialValue,null==t?"":JSON.stringify(t,null,4)),isValidJson:!0,undoStack:[],redoStack:[],lastUndo:""}}render(){return t.createElement("div",{"data-test-id":"json-editor"},t.createElement(b,{isRedoDisabled:this.props.disabled||0===this.state.redoStack.length,isUndoDisabled:this.props.disabled||0===this.state.undoStack.length,onUndo:this.onUndo,onRedo:this.onRedo}),t.createElement(m,{value:this.state.value,onChange:this.onChange,isDisabled:this.props.disabled}),!this.state.isValidJson&&t.createElement(v,null))}}f.defaultProps={isInitiallyDisabled:!0},exports.JsonEditor=function(e){return t.createElement(o.FieldConnector,{field:e.field,isInitiallyDisabled:e.isInitiallyDisabled,isEqualValues:(e,t)=>a(e,t)},({value:e,disabled:i,setValue:o,externalReset:a})=>t.createElement(f,{key:"json-editor-"+a,initialValue:e,disabled:i,setValue:o}))};
2
- //# sourceMappingURL=field-editor-json.cjs.production.min.js.map