@contentful/field-editor-json 3.1.7 → 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,284 +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.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)
7
-
8
- **Note:** Version bump only for package @contentful/field-editor-json
9
-
10
- ## [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)
11
-
12
- **Note:** Version bump only for package @contentful/field-editor-json
13
-
14
- ## [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)
15
-
16
- **Note:** Version bump only for package @contentful/field-editor-json
17
-
18
- ## [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)
19
-
20
- **Note:** Version bump only for package @contentful/field-editor-json
21
-
22
- ## [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)
23
-
24
- **Note:** Version bump only for package @contentful/field-editor-json
25
-
26
- ## [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)
27
-
28
- ### Bug Fixes
29
-
30
- - 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))
31
-
32
- ## [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)
33
-
34
- **Note:** Version bump only for package @contentful/field-editor-json
35
-
36
- # [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)
37
-
38
- ### Features
39
-
40
- - 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))
41
-
42
- ## [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)
43
-
44
- **Note:** Version bump only for package @contentful/field-editor-json
45
-
46
- # [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)
47
-
48
- ### chore
49
-
50
- - 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))
51
-
52
- ### BREAKING CHANGES
53
-
54
- - update codemirror from 5 to 6
55
-
56
- - fix: make release BREAKING CHANGE
57
-
58
- - fix!: make release BREAKING CHANGE
59
-
60
- - fix!: make release breaking change
61
-
62
- - fix!: make release breaking change
63
-
64
- - feat!: make release BREAKING CHANGE
65
-
66
- - fix: make major release due to breaking change
67
-
68
- - chore: remove unnecessary codemirror import in json editor
69
-
70
- ## [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)
71
-
72
- **Note:** Version bump only for package @contentful/field-editor-json
73
-
74
- ## [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)
75
-
76
- ### Bug Fixes
77
-
78
- - remove custom theme from jsonEditor ([#1201](https://github.com/contentful/field-editors/issues/1201)) ([6eefb13](https://github.com/contentful/field-editors/commit/6eefb13d58fee12e0bc50e456c06f160f26dfebe))
79
-
80
- ## [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)
81
-
82
- ### Bug Fixes
83
-
84
- - add white background to json editor ([#1200](https://github.com/contentful/field-editors/issues/1200)) ([56437c0](https://github.com/contentful/field-editors/commit/56437c0dd0183bf4219ada812f8045bc15f0028b))
85
-
86
- ## [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)
87
-
88
- ### Bug Fixes
89
-
90
- - 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))
91
-
92
- # [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)
93
-
94
- ### Features
95
-
96
- - 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))
97
-
98
- ## [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)
99
-
100
- **Note:** Version bump only for package @contentful/field-editor-json
101
-
102
- ## [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)
103
-
104
- **Note:** Version bump only for package @contentful/field-editor-json
105
-
106
- ## [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)
107
-
108
- ### Bug Fixes
109
-
110
- - reflect disabled state on fields ([#1125](https://github.com/contentful/field-editors/issues/1125)) ([01502b9](https://github.com/contentful/field-editors/commit/01502b9d785c5f782b0e5de782d092c439cb690f))
111
-
112
- ## [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)
113
-
114
- ### Bug Fixes
115
-
116
- - bump f36 packages ([#1025](https://github.com/contentful/field-editors/issues/1025)) ([ec37a40](https://github.com/contentful/field-editors/commit/ec37a4000db7cd75c66dd9621136b2272c9feeea))
117
-
118
- ## [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)
119
-
120
- **Note:** Version bump only for package @contentful/field-editor-json
121
-
122
- # [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)
123
-
124
- ### Features
125
-
126
- - 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))
127
-
128
- ## [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)
129
-
130
- ### Bug Fixes
131
-
132
- - markdown buttons ([#968](https://github.com/contentful/field-editors/issues/968)) ([9803b98](https://github.com/contentful/field-editors/commit/9803b98c25d92df6148686ffe2749a77f7efdbb9))
133
-
134
- ## [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)
135
-
136
- **Note:** Version bump only for package @contentful/field-editor-json
137
-
138
- ## [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)
139
-
140
- ### Bug Fixes
141
-
142
- - **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))
143
-
144
- # [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)
145
-
146
- **Note:** Version bump only for package @contentful/field-editor-json
147
-
148
- # [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)
149
-
150
- ### Features
151
-
152
- - Forma v4 components adoption ([#805](https://github.com/contentful/field-editors/issues/805)) ([526bde6](https://github.com/contentful/field-editors/commit/526bde6e10e0ee3789705ec10fb31489af7ca59e))
153
-
154
- ### BREAKING CHANGES
155
-
156
- - adopts a new Forma v4 beta
157
-
158
- ## [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)
159
-
160
- **Note:** Version bump only for package @contentful/field-editor-json
161
-
162
- # [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)
163
-
164
- ### Features
165
-
166
- - [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))
167
-
168
- ## [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)
169
-
170
- **Note:** Version bump only for package @contentful/field-editor-json
171
-
172
- ## [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)
173
-
174
- **Note:** Version bump only for package @contentful/field-editor-json
175
-
176
- ## [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)
177
-
178
- **Note:** Version bump only for package @contentful/field-editor-json
179
-
180
- ## [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)
181
-
182
- **Note:** Version bump only for package @contentful/field-editor-json
183
-
184
- # [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)
185
-
186
- ### Features
187
-
188
- - 💡 new color tokens ([#778](https://github.com/contentful/field-editors/issues/778)) ([fba548d](https://github.com/contentful/field-editors/commit/fba548de32305016df7f2685634eefb14294828f))
189
-
190
- ## [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)
191
-
192
- **Note:** Version bump only for package @contentful/field-editor-json
193
-
194
- ## [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)
195
-
196
- **Note:** Version bump only for package @contentful/field-editor-json
197
-
198
- ## [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)
199
-
200
- **Note:** Version bump only for package @contentful/field-editor-json
201
-
202
- ## [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)
203
-
204
- **Note:** Version bump only for package @contentful/field-editor-json
205
-
206
- ## [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)
207
-
208
- **Note:** Version bump only for package @contentful/field-editor-json
209
-
210
- ## [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)
211
-
212
- ### Bug Fixes
213
-
214
- - [] 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))
215
-
216
- ## [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)
217
-
218
- **Note:** Version bump only for package @contentful/field-editor-json
219
-
220
- # [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)
221
-
222
- ### Features
223
-
224
- - bump min version of forma-36 ([#606](https://github.com/contentful/field-editors/issues/606)) ([fd57c7a](https://github.com/contentful/field-editors/commit/fd57c7a4312766af38c01507f17706ab22992617))
225
-
226
- ## [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)
227
-
228
- **Note:** Version bump only for package @contentful/field-editor-json
229
-
230
- ## [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)
231
-
232
- **Note:** Version bump only for package @contentful/field-editor-json
233
-
234
- ## [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)
235
-
236
- **Note:** Version bump only for package @contentful/field-editor-json
237
-
238
- # [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)
239
-
240
- ### Features
241
-
242
- - 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))
243
-
244
- ## [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)
245
-
246
- ### Bug Fixes
247
-
248
- - 🐛 use tokens for border-radius ([ec56c06](https://github.com/contentful/field-editors/commit/ec56c06ddd01718086a96c4cb2bc2877071644a9))
249
-
250
- # [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)
251
-
252
- ### Features
253
-
254
- - 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))
255
-
256
- ## [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)
257
-
258
- **Note:** Version bump only for package @contentful/field-editor-json
259
-
260
- ## [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)
261
-
262
- **Note:** Version bump only for package @contentful/field-editor-json
263
-
264
- ## [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)
265
-
266
- **Note:** Version bump only for package @contentful/field-editor-json
267
-
268
- ## [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)
269
-
270
- **Note:** Version bump only for package @contentful/field-editor-json
271
-
272
- ## [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)
273
-
274
- **Note:** Version bump only for package @contentful/field-editor-json
275
-
276
- ## [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)
277
-
278
- **Note:** Version bump only for package @contentful/field-editor-json
279
-
280
- # [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)
281
-
282
- ### Features
283
-
284
- - 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,364 +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
- function _extends() {
20
- _extends = Object.assign || function (target) {
21
- for (var i = 1; i < arguments.length; i++) {
22
- var source = arguments[i];
23
-
24
- for (var key in source) {
25
- if (Object.prototype.hasOwnProperty.call(source, key)) {
26
- target[key] = source[key];
27
- }
28
- }
29
- }
30
-
31
- return target;
32
- };
33
-
34
- return _extends.apply(this, arguments);
35
- }
36
-
37
- function _inheritsLoose(subClass, superClass) {
38
- subClass.prototype = Object.create(superClass.prototype);
39
- subClass.prototype.constructor = subClass;
40
-
41
- _setPrototypeOf(subClass, superClass);
42
- }
43
-
44
- function _setPrototypeOf(o, p) {
45
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
46
- o.__proto__ = p;
47
- return o;
48
- };
49
-
50
- return _setPrototypeOf(o, p);
51
- }
52
-
53
- var styles = {
54
- root: /*#__PURE__*/emotion.css({
55
- cursor: 'text',
56
- padding: tokens.spacingS,
57
- border: "1px solid " + tokens.gray200,
58
- borderTop: 'none',
59
- borderBottomLeftRadius: tokens.borderRadiusSmall,
60
- borderBottomRightRadius: tokens.borderRadiusSmall,
61
- fontSize: tokens.fontSizeM,
62
- '.cm-editor': {
63
- color: tokens.gray900,
64
- '&.cm-focused': {
65
- outline: 'none'
66
- }
67
- },
68
- '.cm-scroller': {
69
- fontFamily: tokens.fontStackMonospace,
70
- minHeight: '6rem'
71
- },
72
- '&.disabled': {
73
- cursor: 'auto',
74
- '.cm-scroller ': {
75
- minHeight: '6rem',
76
- backgroundColor: tokens.gray100,
77
- cursor: 'not-allowed'
78
- },
79
- '.cm-editor': {
80
- border: "1px solid " + tokens.gray200
81
- },
82
- '.cm-line': {
83
- cursor: 'not-allowed'
84
- },
85
- '.cm-lines': {
86
- cursor: 'not-allowed'
87
- }
88
- }
89
- })
90
- };
91
- function JsonEditorField(props) {
92
- return React__default.createElement("div", {
93
- className: emotion.cx(styles.root, {
94
- disabled: props.isDisabled
95
- }),
96
- "data-test-id": "json-editor-code-mirror"
97
- }, React__default.createElement(CodeMirror, {
98
- value: props.value,
99
- onChange: props.onChange,
100
- theme: "light",
101
- extensions: [langJson.json(), view.EditorView.lineWrapping],
102
- basicSetup: {
103
- closeBrackets: false,
104
- lineNumbers: false,
105
- highlightActiveLineGutter: false,
106
- searchKeymap: false,
107
- highlightActiveLine: false,
108
- foldGutter: false,
109
- bracketMatching: false,
110
- syntaxHighlighting: false
111
- },
112
- width: "100%",
113
- editable: !props.isDisabled,
114
- indentWithTab: true
115
- }));
116
- }
117
-
118
- var styles$1 = {
119
- toolbar: /*#__PURE__*/emotion.css({
120
- display: 'flex',
121
- alignItems: 'center',
122
- padding: tokens.spacingXs,
123
- justifyContent: 'space-between',
124
- backgroundColor: tokens.gray100,
125
- border: "1px solid " + tokens.gray200,
126
- borderTopLeftRadius: tokens.borderRadiusSmall,
127
- borderTopRightRadius: tokens.borderRadiusSmall,
128
- borderBottom: 'none'
129
- }),
130
- title: /*#__PURE__*/emotion.css({
131
- fontFamily: tokens.fontStackPrimary,
132
- fontSize: tokens.fontSizeM,
133
- color: tokens.gray600
134
- }),
135
- actions: /*#__PURE__*/emotion.css({
136
- button: {
137
- marginLeft: tokens.spacingS
138
- }
139
- })
140
- };
141
- function JsonEditorToolbar(props) {
142
- return React__default.createElement("div", {
143
- className: styles$1.toolbar
144
- }, React__default.createElement("div", {
145
- className: styles$1.title
146
- }, "JSON Editor"), React__default.createElement("div", {
147
- className: styles$1.actions
148
- }, React__default.createElement(f36Components.Button, {
149
- variant: "secondary",
150
- size: "small",
151
- isDisabled: props.isUndoDisabled,
152
- testId: "json-editor-undo",
153
- onClick: function onClick() {
154
- props.onUndo();
155
- }
156
- }, "Undo"), React__default.createElement(f36Components.Button, {
157
- variant: "secondary",
158
- size: "small",
159
- isDisabled: props.isRedoDisabled,
160
- testId: "json-editor-redo",
161
- onClick: function onClick() {
162
- props.onRedo();
163
- }
164
- }, "Redo")));
165
- }
166
-
167
- function JsonInvalidStatus() {
168
- return React__default.createElement("div", {
169
- role: "status",
170
- "data-test-id": "json-editor.invalid-json",
171
- className: emotion.css({
172
- marginTop: tokens.spacingS
173
- })
174
- }, React__default.createElement(f36Components.ValidationMessage, null, "This is not valid JSON"));
175
- }
176
-
177
- function stringifyJSON(obj) {
178
- if (obj === null || obj === undefined) {
179
- return '';
180
- } else {
181
- return JSON.stringify(obj, null, 4);
182
- }
183
- }
184
- function isValidJson(str) {
185
- var parsed;
186
-
187
- try {
188
- parsed = JSON.parse(str);
189
- } catch (e) {
190
- return false;
191
- } // An object or array is valid JSON
192
-
193
-
194
- if (typeof parsed !== 'object') {
195
- return false;
196
- }
197
-
198
- return true;
199
- }
200
- function parseJSON(str) {
201
- if (str === '') {
202
- return {
203
- value: undefined,
204
- valid: true
205
- };
206
- } else if (isValidJson(str)) {
207
- return {
208
- value: JSON.parse(str),
209
- valid: true
210
- };
211
- } else {
212
- return {
213
- value: undefined,
214
- valid: false
215
- };
216
- }
217
- }
218
-
219
- var ConnectedJsonEditor = /*#__PURE__*/function (_React$Component) {
220
- _inheritsLoose(ConnectedJsonEditor, _React$Component);
221
-
222
- function ConnectedJsonEditor(props) {
223
- var _this;
224
-
225
- _this = _React$Component.call(this, props) || this;
226
-
227
- _this.setValidJson = function (value) {
228
- _this.setState({
229
- isValidJson: value
230
- });
231
- };
232
-
233
- _this.pushUndo = throttle(function (value) {
234
- _this.setState(function (state) {
235
- return {
236
- undoStack: [].concat(state.undoStack, [value])
237
- };
238
- });
239
- }, 400);
240
-
241
- _this.onChange = function (value) {
242
- var parsed = parseJSON(value);
243
-
244
- if (value !== _this.state.lastUndo) {
245
- _this.pushUndo(_this.state.value);
246
- }
247
-
248
- _this.setState({
249
- value: value,
250
- isValidJson: parsed.valid
251
- });
252
-
253
- if (parsed.valid) {
254
- _this.props.setValue(parsed.value);
255
- }
256
- };
257
-
258
- _this.onUndo = function () {
259
- var undoStack = _this.state.undoStack;
260
-
261
- if (undoStack.length === 0) {
262
- return;
263
- }
264
-
265
- var value = undoStack.pop() || '';
266
- var parsedValue = parseJSON(value);
267
-
268
- _this.setState(function (state) {
269
- return _extends({}, state, {
270
- value: value,
271
- isValidJson: parsedValue.valid,
272
- undoStack: undoStack,
273
- redoStack: [].concat(state.redoStack, [state.value]),
274
- lastUndo: value
275
- });
276
- }, function () {
277
- if (parsedValue.valid) {
278
- _this.props.setValue(parsedValue.value);
279
- }
280
- });
281
- };
282
-
283
- _this.onRedo = function () {
284
- var redoStack = [].concat(_this.state.redoStack);
285
-
286
- if (redoStack.length === 0) {
287
- return;
288
- }
289
-
290
- var value = redoStack.pop() || '';
291
- var parsedValue = parseJSON(value);
292
-
293
- _this.setState(function (state) {
294
- return _extends({}, state, {
295
- value: value,
296
- isValidJson: parsedValue.valid,
297
- redoStack: redoStack,
298
- undoStack: [].concat(state.undoStack, [state.value])
299
- });
300
- }, function () {
301
- if (parsedValue.valid) {
302
- _this.props.setValue(parsedValue.value);
303
- }
304
- });
305
- };
306
-
307
- _this.state = {
308
- value: stringifyJSON(props.initialValue),
309
- isValidJson: true,
310
- undoStack: [],
311
- redoStack: [],
312
- lastUndo: ''
313
- };
314
- return _this;
315
- }
316
-
317
- var _proto = ConnectedJsonEditor.prototype;
318
-
319
- _proto.render = function render() {
320
- return React.createElement("div", {
321
- "data-test-id": "json-editor"
322
- }, React.createElement(JsonEditorToolbar, {
323
- isRedoDisabled: this.props.disabled || this.state.redoStack.length === 0,
324
- isUndoDisabled: this.props.disabled || this.state.undoStack.length === 0,
325
- onUndo: this.onUndo,
326
- onRedo: this.onRedo
327
- }), React.createElement(JsonEditorField, {
328
- value: this.state.value,
329
- onChange: this.onChange,
330
- isDisabled: this.props.disabled
331
- }), !this.state.isValidJson && React.createElement(JsonInvalidStatus, null));
332
- };
333
-
334
- return ConnectedJsonEditor;
335
- }(React.Component);
336
-
337
- ConnectedJsonEditor.defaultProps = {
338
- isInitiallyDisabled: true
339
- };
340
- function JsonEditor(props) {
341
- return React.createElement(fieldEditorShared.FieldConnector, {
342
- field: props.field,
343
- isInitiallyDisabled: props.isInitiallyDisabled,
344
- isEqualValues: function isEqualValues(value1, value2) {
345
- return deepEqual(value1, value2);
346
- }
347
- }, function (_ref) {
348
- var value = _ref.value,
349
- disabled = _ref.disabled,
350
- setValue = _ref.setValue,
351
- externalReset = _ref.externalReset;
352
- return React.createElement(ConnectedJsonEditor // on external change reset component completely and init with initial value again
353
- , {
354
- // on external change reset component completely and init with initial value again
355
- key: "json-editor-" + externalReset,
356
- initialValue: value,
357
- disabled: disabled,
358
- setValue: setValue
359
- });
360
- });
361
- }
362
-
363
- exports.JsonEditor = JsonEditor;
364
- //# sourceMappingURL=field-editor-json.cjs.development.js.map