json-edit-react 1.1.0 → 1.1.3

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.
@@ -1,1081 +1 @@
1
- 'use strict';
2
-
3
- var jsxRuntime = require('react/jsx-runtime');
4
- var react = require('react');
5
- var assign = require('object-property-assigner');
6
- var extract = require('object-property-extractor');
7
- var clone = require('just-clone');
8
- var hi = require('react-icons/hi');
9
- var bi = require('react-icons/bi');
10
- var md = require('react-icons/md');
11
- var fi = require('react-icons/fi');
12
- var ti = require('react-icons/ti');
13
- var fa = require('react-icons/fa');
14
-
15
- /******************************************************************************
16
- Copyright (c) Microsoft Corporation.
17
-
18
- Permission to use, copy, modify, and/or distribute this software for any
19
- purpose with or without fee is hereby granted.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
22
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
23
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
24
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
25
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
27
- PERFORMANCE OF THIS SOFTWARE.
28
- ***************************************************************************** */
29
- /* global Reflect, Promise, SuppressedError, Symbol */
30
-
31
-
32
- function __rest(s, e) {
33
- var t = {};
34
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
- t[p] = s[p];
36
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
- t[p[i]] = s[p[i]];
40
- }
41
- return t;
42
- }
43
-
44
- function __awaiter(thisArg, _arguments, P, generator) {
45
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
46
- return new (P || (P = Promise))(function (resolve, reject) {
47
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
48
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
49
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
50
- step((generator = generator.apply(thisArg, _arguments || [])).next());
51
- });
52
- }
53
-
54
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
55
- var e = new Error(message);
56
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
57
- };
58
-
59
- var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
60
-
61
- var css = ":root {\n --jer-select-border: #b6b6b6;\n --jer-select-focus: #777;\n --jer-select-arrow: #777;\n --jer-form-border: 1px solid #ededf0;\n --jer-form-border-focus: 1px solid #e2e2e2;\n --jer-expand-transition-time: 0.5s;\n --jer-highlight-color: #b3d8ff;\n}\n\n.jer-visible {\n opacity: 1;\n transition: var(--jer-expand-transition-time);\n}\n\n.jer-hidden {\n opacity: 0;\n transition: var(--jer-expand-transition-time);\n}\n\n/* Select styled as per:\nhttps://moderncss.dev/custom-select-styles-with-pure-css/\n*/\n\n.jer-select select {\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n background-color: transparent;\n border: none;\n padding: 0 1em 0 0;\n margin: 0;\n /* width: 100%; */\n font-family: inherit;\n font-size: inherit;\n color: black;\n cursor: inherit;\n line-height: inherit;\n z-index: 1;\n outline: none;\n}\nselect::-ms-expand {\n display: none;\n}\n\n.jer-select {\n display: grid;\n grid-template-areas: 'select';\n align-items: center;\n position: relative;\n min-width: 12ch;\n max-width: 15ch;\n border: 1px solid var(--jer-select-border);\n border-radius: 0.25em;\n padding: 0.25em 0.5em;\n font-size: 1em;\n cursor: pointer;\n line-height: 1.1;\n background-color: #fff;\n background-image: linear-gradient(to top, #f9f9f9, #fff 33%);\n}\n.jer-select select,\n.jer-select::after {\n grid-area: select;\n}\n.jer-select:not(.jer-select--multiple)::after {\n content: '';\n justify-self: end;\n width: 0.8em;\n height: 0.5em;\n background-color: var(--jer-select-arrow);\n -webkit-clip-path: polygon(100% 0%, 0 0%, 50% 100%);\n clip-path: polygon(100% 0%, 0 0%, 50% 100%);\n}\n\nselect:focus + .focus {\n position: absolute;\n top: -1px;\n left: -1px;\n right: -1px;\n bottom: -1px;\n border: 1px solid var(--jer-select-focus);\n border-radius: inherit;\n}\n\n.jer-editor-container {\n font-size: 1.1em;\n /* font-size: 20px; */\n padding: 1em;\n margin-top: 1em;\n margin-bottom: 1em;\n border-radius: 0.5em;\n}\n\n.jer-editor-container textarea {\n /* width: 90%; */\n color: var(--jer-input-color);\n border: var(--jer-form-border);\n border-radius: 0.3em;\n outline: none;\n}\n\n.jer-editor-container textarea:focus {\n border: var(--jer-form-border-focus);\n}\n\n.jer-editor-container input {\n border: var(--jer-form-border);\n border-radius: 0.3em;\n outline: none;\n}\n\n.jer-editor-container input:focus {\n border: var(--jer-form-border-focus);\n}\n\n/* Input highlighted text */\n.jer-editor-container ::selection {\n background-color: var(--jer-highlight-color);\n}\n\n.jer-editor-container select {\n /* color: red; */\n}\n\n.jer-component {\n}\n\n.jer-collection-header-row,\n.jer-value-main-row {\n display: flex;\n min-height: 1.7em;\n gap: 0.3em;\n align-items: center;\n}\n\n.jer-collection-header-row {\n display: flex;\n flex-wrap: wrap;\n}\n\n.jer-brackets {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collection-inner {\n position: relative;\n}\n\n.jer-collection-text-edit {\n display: flex;\n flex-direction: column;\n gap: 0.3em;\n align-items: flex-start;\n}\n\n.jer-collection-text-area {\n resize: both;\n padding-top: 0.2em;\n padding-left: 0.5em;\n padding-right: 0.5em;\n padding-bottom: 0;\n overflow: hidden;\n max-height: 40em;\n}\n\n.jer-collection-input-button-row {\n display: flex;\n justify-content: flex-end;\n font-size: 150%;\n}\n\n.jer-collection-element {\n}\n\n.jer-collection-error-row {\n position: absolute;\n bottom: 0;\n}\n\n.jer-collection-error-row-edit {\n}\n\n.jer-error-slug {\n margin-left: 1em;\n}\n\n.jer-value-component {\n position: relative;\n}\n\n.jer-value-main-row {\n display: flex;\n gap: 0;\n}\n\n.jer-value-and-buttons {\n display: flex;\n justify-content: flex-start;\n align-items: center;\n padding-left: 0.5em;\n}\n\n.jer-value-error-row {\n position: absolute;\n}\n\n.jer-value-string {\n line-height: 1.3em;\n}\n\n.jer-input-text {\n resize: none;\n margin: 0;\n height: 1.4em;\n padding-left: 0.5em;\n padding-right: 0.5em;\n padding-bottom: 0;\n min-width: 6em;\n overflow: hidden;\n max-height: 30em;\n}\n\n.jer-value-number {\n}\n\n.jer-value-boolean {\n}\n\n.jer-input-boolean {\n transform: scale(1.5);\n margin-left: 0.3em;\n margin-right: 0.3em;\n}\n\n.jer-value-null {\n}\n\n.jer-value-object {\n}\n\n.jer-object-key {\n word-break: break-word;\n line-height: 1.1em;\n}\n\n.jer-value-array {\n}\n\n.jer-value-invalid {\n opacity: 0.5;\n font-style: italic;\n}\n\n/* .jer-input-text, */\n.jer-input-number {\n height: 1.6em;\n}\n\n.jer-input-number {\n min-width: 3em;\n}\n\n.jer-input-component {\n}\n\n.jer-edit-buttons,\n.jer-confirm-buttons {\n display: flex;\n align-items: center;\n cursor: pointer;\n}\n\n.jer-input-buttons {\n gap: 0.4em;\n}\n\n.jer-edit-buttons {\n gap: 0.4em;\n margin-left: 0.5em;\n opacity: 0;\n}\n\n.jer-confirm-buttons {\n gap: 0.2em;\n margin-left: 0.4em;\n}\n\n.jer-edit-buttons:hover {\n opacity: 1;\n position: relative;\n}\n\n.jer-collection-header-row:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-value-main-row:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-value-and-buttons:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-input-buttons {\n}\n\n.jer-copy-pulse {\n position: relative;\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-copy-pulse:hover {\n opacity: 0.85;\n transition: 0.3s;\n transform: scale(1.2);\n}\n\n.jer-copy-pulse:after {\n content: '';\n display: block;\n position: absolute;\n border-radius: 50%;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n opacity: 0;\n transition: all 0.5s;\n box-shadow: 0 0 15px 5px var(--jer-icon-copy-color);\n}\n\n.jer-copy-pulse:active:after {\n box-shadow: 0 0 0 0 var(--jer-icon-copy-color);\n position: absolute;\n border-radius: 4em;\n left: 0;\n top: 0;\n opacity: 1;\n transition: 0s;\n}\n\n.jer-copy-pulse:active {\n top: 0.07em;\n}\n\n.jer-rotate-90 {\n transform: rotate(-90deg);\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-accordion-icon {\n /* font-size: '2em'; */\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-icon:hover {\n opacity: 0.85;\n transition: 0.3s;\n transform: scale(1.2);\n}\n";
62
- n(css,{});
63
-
64
- const defaultTheme$1 = {
65
- displayName: 'Default',
66
- fragments: { edit: 'rgb(42, 161, 152)' },
67
- styles: {
68
- container: {
69
- backgroundColor: '#f6f6f6',
70
- fontFamily: 'monospace',
71
- },
72
- property: '#292929',
73
- bracket: { color: 'rgb(0, 43, 54)', fontWeight: 'bold' },
74
- itemCount: { color: 'rgba(0, 0, 0, 0.3)', fontStyle: 'italic' },
75
- string: 'rgb(203, 75, 22)',
76
- number: 'rgb(38, 139, 210)',
77
- boolean: 'green',
78
- null: { color: 'rgb(220, 50, 47)', fontVariant: 'small-caps', fontWeight: 'bold' },
79
- input: ['#292929', { fontSize: '90%' }],
80
- inputHighlight: '#b3d8ff',
81
- error: { fontSize: '0.8em', color: 'red', fontWeight: 'bold' },
82
- iconCollection: 'rgb(0, 43, 54)',
83
- iconEdit: 'edit',
84
- iconDelete: 'rgb(203, 75, 22)',
85
- iconAdd: 'edit',
86
- iconCopy: 'rgb(38, 139, 210)',
87
- iconOk: 'green',
88
- iconCancel: 'rgb(203, 75, 22)',
89
- },
90
- };
91
- const themes = {
92
- default: defaultTheme$1,
93
- githubDark: {
94
- displayName: 'Github Dark',
95
- styles: {
96
- container: {
97
- backgroundColor: '#0d1117',
98
- color: 'white',
99
- },
100
- property: '#E6EDF3',
101
- bracket: '#56d364',
102
- itemCount: '#8B949E',
103
- string: '#A5D6FF',
104
- number: '#D2A8FF',
105
- boolean: { color: '#FF7B72', fontSize: '90%', fontWeight: 'bold' },
106
- null: 'green',
107
- iconCollection: '#D2A8FF',
108
- iconEdit: '#D2A8FF',
109
- iconDelete: 'rgb(203, 75, 22)',
110
- iconAdd: 'rgb(203, 75, 22)',
111
- iconCopy: '#A5D6FF',
112
- iconOk: '#56d364',
113
- iconCancel: 'rgb(203, 75, 22)',
114
- },
115
- },
116
- githubLight: {
117
- displayName: 'Github Light',
118
- styles: {
119
- container: 'white',
120
- property: '#1F2328',
121
- bracket: '#00802e',
122
- itemCount: '#8B949E',
123
- string: '#0A3069',
124
- number: '#953800',
125
- boolean: { color: '#CF222E', fontSize: '90%', fontWeight: 'bold' },
126
- null: '#FF7B72',
127
- iconCollection: '#8250DF',
128
- iconEdit: '#8250DF',
129
- iconDelete: 'rgb(203, 75, 22)',
130
- iconAdd: '#8250DF',
131
- iconCopy: '#57606A',
132
- },
133
- },
134
- monoDark: {
135
- displayName: 'Black & White',
136
- fragments: {
137
- lightText: { color: 'white' },
138
- midGrey: '#5c5c5c',
139
- },
140
- styles: {
141
- container: ['lightText', { backgroundColor: 'black' }],
142
- property: 'lightText',
143
- bracket: 'midGrey',
144
- itemCount: '#4a4a4a',
145
- string: '#a8a8a8',
146
- number: '#666666',
147
- boolean: { color: '#848484', fontStyle: 'italic' },
148
- null: '#333333',
149
- iconCollection: 'midGrey',
150
- iconEdit: 'midGrey',
151
- iconDelete: 'midGrey',
152
- iconAdd: 'midGrey',
153
- iconCopy: 'midGrey',
154
- iconOk: 'midGrey',
155
- iconCancel: 'midGrey',
156
- },
157
- },
158
- monoLight: {
159
- fragments: { midGrey: '#a3a3a3' },
160
- displayName: 'White & Black',
161
- styles: {
162
- container: 'white',
163
- property: 'black',
164
- bracket: 'midGrey',
165
- itemCount: '#b5b5b5',
166
- string: '#575757',
167
- number: '#999999',
168
- boolean: { color: '#7b7b7b', fontStyle: 'italic' },
169
- null: '#cccccc',
170
- iconCollection: 'midGrey',
171
- iconEdit: 'midGrey',
172
- iconDelete: 'midGrey',
173
- iconAdd: 'midGrey',
174
- iconCopy: 'midGrey',
175
- iconOk: 'midGrey',
176
- iconCancel: 'midGrey',
177
- },
178
- },
179
- candyWrapper: {
180
- displayName: 'Candy Wrapper',
181
- fragments: {
182
- minty: { backgroundColor: '#F1FAEE' },
183
- pale: { color: '#A8DADC' },
184
- mid: { color: '#457B9D' },
185
- dark: { color: '#1D3557' },
186
- pop: { color: '#E63946' },
187
- darkBlue: { color: '#2B2D42' },
188
- },
189
- styles: {
190
- container: 'minty',
191
- property: 'pop',
192
- bracket: 'dark',
193
- itemCount: 'pale',
194
- string: 'mid',
195
- number: ['darkBlue', { fontSize: '85%' }],
196
- boolean: ['mid', { fontStyle: 'italic', fontWeight: 'bold', fontSize: '80%' }],
197
- null: ['#cccccc', { fontWeight: 'bold' }],
198
- iconCollection: '#1D3557',
199
- iconEdit: '#457B9D',
200
- iconDelete: '#E63946',
201
- iconAdd: '#2B2D42',
202
- iconCopy: '#1D3557',
203
- iconCancel: '#E63946',
204
- },
205
- },
206
- psychedelic: {
207
- displayName: 'Psychedelic',
208
- fragments: {
209
- minty: {
210
- backgroundColor: '#F1FAEE',
211
- },
212
- pale: {
213
- color: '#A8DADC',
214
- },
215
- mid: {
216
- color: '#457B9D',
217
- },
218
- dark: {
219
- color: '#1D3557',
220
- },
221
- pop: {
222
- color: '#E63946',
223
- },
224
- fluroYellow: 'rgb(242, 228, 21)',
225
- fluroGreen: 'rgb(68, 255, 62)',
226
- hotPink: '#f7379a',
227
- },
228
- styles: {
229
- container: {
230
- backgroundColor: 'unset',
231
- background: 'linear-gradient(90deg, hsla(333, 100%, 53%, 1) 0%, hsla(33, 94%, 57%, 1) 100%)',
232
- color: 'black',
233
- },
234
- property: 'black',
235
- bracket: 'fluroYellow',
236
- itemCount: [
237
- 'pale',
238
- {
239
- opacity: 0.7,
240
- },
241
- ],
242
- string: 'white',
243
- number: [
244
- '#33d9ff',
245
- {
246
- fontSize: '90%',
247
- fontWeight: 'bold',
248
- },
249
- ],
250
- boolean: [
251
- 'fluroGreen',
252
- {
253
- fontWeight: 'bold',
254
- fontSize: '80%',
255
- },
256
- ],
257
- null: [
258
- 'black',
259
- {
260
- fontWeight: 'bold',
261
- opacity: 0.3,
262
- backgroundColor: 'rgb(255, 255, 255, 0.5)',
263
- padding: '0 0.4em',
264
- borderRadius: '0.4em',
265
- },
266
- ],
267
- iconCollection: 'fluroYellow',
268
- iconEdit: ['black'],
269
- iconDelete: [
270
- 'white',
271
- {
272
- opacity: 0.5,
273
- },
274
- ],
275
- iconAdd: [
276
- 'white',
277
- {
278
- opacity: 0.5,
279
- },
280
- ],
281
- iconCopy: 'rgb(32, 84, 242)',
282
- iconOk: 'fluroGreen',
283
- iconCancel: 'hotPink',
284
- },
285
- },
286
- };
287
- const emptyStyleObject = {
288
- container: {},
289
- property: {},
290
- bracket: {},
291
- itemCount: {},
292
- string: {},
293
- number: {},
294
- boolean: {},
295
- null: {},
296
- input: {},
297
- inputHighlight: {},
298
- error: {},
299
- iconCollection: {},
300
- iconEdit: {},
301
- iconDelete: {},
302
- iconAdd: {},
303
- iconCopy: {},
304
- iconOk: {},
305
- iconCancel: {},
306
- };
307
-
308
- const defaultTheme = themes.default;
309
- const initialContext = {
310
- styles: emptyStyleObject,
311
- setTheme: (_) => { },
312
- icons: {},
313
- setIcons: () => { },
314
- };
315
- const ThemeProviderContext = react.createContext(initialContext);
316
- const ThemeProvider = ({ children }) => {
317
- const [styles, setStyles] = react.useState(emptyStyleObject);
318
- const [icons, setIcons] = react.useState({});
319
- const setTheme = (theme) => setStyles(compileStyles(theme));
320
- return (jsxRuntime.jsx(ThemeProviderContext.Provider, { value: { styles, setTheme, icons, setIcons }, children: children }));
321
- };
322
- const useTheme = () => react.useContext(ThemeProviderContext);
323
- const compileStyles = (themeInput) => {
324
- if (typeof themeInput === 'string')
325
- return buildStyleObject(themes[themeInput]);
326
- if (Array.isArray(themeInput)) {
327
- const [name, overrides] = themeInput;
328
- return buildStyleObject(themes[name], isStyleObject(overrides) ? { styles: overrides } : overrides);
329
- }
330
- return buildStyleObject(defaultTheme, isStyleObject(themeInput) ? { styles: themeInput } : themeInput);
331
- };
332
- const buildStyleObject = (baseTheme, overrides = { styles: emptyStyleObject }) => {
333
- var _a, _b, _c, _d;
334
- const [defaultStyles, baseStyles, overrideStyles] = [defaultTheme, baseTheme, overrides].map((theme) => {
335
- const { fragments, styles } = theme;
336
- const compiledStyles = {};
337
- Object.entries(styles).forEach(([key, value]) => {
338
- const elements = Array.isArray(value) ? value : [value];
339
- const cssStyles = elements.reduce((acc, curr) => {
340
- var _a;
341
- if (typeof curr === 'string') {
342
- const style = (_a = fragments === null || fragments === void 0 ? void 0 : fragments[curr]) !== null && _a !== void 0 ? _a : curr;
343
- switch (typeof style) {
344
- case 'string':
345
- return Object.assign(Object.assign({}, acc), { [defaultStyleProperties[key]]: style });
346
- default:
347
- return Object.assign(Object.assign({}, acc), style);
348
- }
349
- }
350
- else
351
- return Object.assign(Object.assign({}, acc), curr);
352
- }, {});
353
- compiledStyles[key] = cssStyles;
354
- });
355
- return compiledStyles;
356
- });
357
- const finalStyles = {};
358
- Object.keys(defaultTheme.styles).forEach((key) => {
359
- finalStyles[key] = Object.assign(Object.assign(Object.assign({}, defaultStyles[key]), baseStyles[key]), overrideStyles[key]);
360
- });
361
- if ((_a = finalStyles === null || finalStyles === void 0 ? void 0 : finalStyles.inputHighlight) === null || _a === void 0 ? void 0 : _a.backgroundColor)
362
- document.documentElement.style.setProperty('--jer-highlight-color', (_b = finalStyles === null || finalStyles === void 0 ? void 0 : finalStyles.inputHighlight) === null || _b === void 0 ? void 0 : _b.backgroundColor);
363
- if ((_c = finalStyles === null || finalStyles === void 0 ? void 0 : finalStyles.iconCopy) === null || _c === void 0 ? void 0 : _c.color)
364
- document.documentElement.style.setProperty('--jer-icon-copy-color', (_d = finalStyles === null || finalStyles === void 0 ? void 0 : finalStyles.iconCopy) === null || _d === void 0 ? void 0 : _d.color);
365
- return finalStyles;
366
- };
367
- const isStyleObject = (overrideObject) => {
368
- return !('styles' in overrideObject);
369
- };
370
- const defaultStyleProperties = {
371
- container: 'backgroundColor',
372
- property: 'color',
373
- bracket: 'color',
374
- itemCount: 'color',
375
- string: 'color',
376
- number: 'color',
377
- boolean: 'color',
378
- null: 'color',
379
- input: 'color',
380
- inputHighlight: 'backgroundColor',
381
- error: 'color',
382
- iconCollection: 'color',
383
- iconEdit: 'color',
384
- iconDelete: 'color',
385
- iconAdd: 'color',
386
- iconCopy: 'color',
387
- iconOk: 'color',
388
- iconCancel: 'color',
389
- };
390
-
391
- const AutogrowTextArea = ({ className, name, value, setValue, handleKeyPress, }) => {
392
- const { styles } = useTheme();
393
- const dummyValue = value.slice(-1) === '\n' ? value + '.' : value;
394
- return (jsxRuntime.jsxs("div", { style: { display: 'grid' }, children: [jsxRuntime.jsx("textarea", { style: Object.assign({ height: 'auto', gridArea: '1 / 1 / 2 / 2', overflowY: 'auto' }, styles.input), rows: 1, className: className, name: name, value: value, onChange: (e) => setValue(e.target.value), autoFocus: true, onFocus: (e) => {
395
- if (value.length < 40)
396
- e.target.select();
397
- }, onKeyDown: handleKeyPress }), jsxRuntime.jsx("span", { className: className, style: Object.assign({ visibility: 'hidden', height: 'auto', gridArea: '1 / 1 / 2 / 2', color: 'red', opacity: 0.9, whiteSpace: 'pre-wrap', overflow: 'clip', border: '1px solid transparent' }, styles.input), children: dummyValue })] }));
398
- };
399
-
400
- const INVALID_FUNCTION_STRING = '**INVALID_FUNCTION**';
401
- const truncate = (string, length = 200) => string.length < length ? string : `${string.slice(0, length - 2).trim()}...`;
402
- const StringValue = ({ value, setValue, isEditing, path, setIsEditing, handleEdit, handleCancel, stringTruncate, }) => {
403
- const { styles } = useTheme();
404
- const handleKeyPress = (e) => {
405
- if (e.key === 'Enter' && !e.shiftKey)
406
- handleEdit();
407
- else if (e.key === 'Escape')
408
- handleCancel();
409
- };
410
- const breakString = (text) => text.split('\n').map((line, index, arr) => (jsxRuntime.jsxs("span", { children: [line, index < arr.length - 1 ? jsxRuntime.jsx("br", {}) : null] }, index)));
411
- return isEditing ? (jsxRuntime.jsx(AutogrowTextArea, { className: "jer-input-text", name: path.join('.'), value: value, setValue: setValue, isEditing: isEditing, handleKeyPress: handleKeyPress })) : (jsxRuntime.jsxs("div", { onDoubleClick: () => setIsEditing(true), onClick: (e) => {
412
- if (e.getModifierState('Control') || e.getModifierState('Meta'))
413
- setIsEditing(true);
414
- }, className: "jer-value-string", style: styles.string, children: ["\"", breakString(truncate(value, stringTruncate)), "\""] }));
415
- };
416
- const NumberValue = ({ value, setValue, isEditing, path, setIsEditing, handleEdit, handleCancel, }) => {
417
- const { styles } = useTheme();
418
- const handleKeyPress = (e) => {
419
- if (e.key === 'Enter')
420
- handleEdit();
421
- else if (e.key === 'Escape')
422
- handleCancel();
423
- };
424
- const validateNumber = (input) => {
425
- return input.replace(/[^0-9.-]/g, '');
426
- };
427
- return isEditing ? (jsxRuntime.jsx("input", { className: "jer-input-number", type: "text", name: path.join('.'), value: value, onChange: (e) => setValue(validateNumber(e.target.value)), autoFocus: true, onFocus: (e) => e.target.select(), onKeyDown: handleKeyPress, style: { width: `${String(value).length / 1.5 + 2}em` } })) : (jsxRuntime.jsx("span", { onDoubleClick: () => setIsEditing(true), className: "jer-value-number", style: styles.number, children: value }));
428
- };
429
- const BooleanValue = ({ value, setValue, isEditing, path, setIsEditing, handleEdit, handleCancel, }) => {
430
- const { styles } = useTheme();
431
- react.useEffect(() => {
432
- if (isEditing)
433
- document.addEventListener('keydown', listenForSubmit);
434
- return () => document.removeEventListener('keydown', listenForSubmit);
435
- }, [isEditing]);
436
- const listenForSubmit = (event) => {
437
- if (event.key === 'Enter') {
438
- handleEdit();
439
- }
440
- else if (event.key === 'Escape')
441
- handleCancel();
442
- };
443
- return isEditing ? (jsxRuntime.jsx("input", { className: "jer-input-boolean", type: "checkbox", name: path.join('.'), checked: value, onChange: () => setValue(!value) })) : (jsxRuntime.jsx("span", { onDoubleClick: () => setIsEditing(true), className: "jer-value-boolean", style: styles.boolean, children: String(value) }));
444
- };
445
- const NullValue = ({ value, isEditing, setIsEditing, handleEdit, handleCancel, }) => {
446
- const { styles } = useTheme();
447
- react.useEffect(() => {
448
- if (isEditing)
449
- document.addEventListener('keydown', listenForSubmit);
450
- return () => document.removeEventListener('keydown', listenForSubmit);
451
- }, [isEditing]);
452
- const listenForSubmit = (event) => {
453
- if (event.key === 'Enter') {
454
- handleEdit();
455
- }
456
- else if (event.key === 'Escape')
457
- handleCancel();
458
- };
459
- return isEditing ? (jsxRuntime.jsx("div", { className: "jer-input-null", children: "null" })) : (jsxRuntime.jsx("div", { onDoubleClick: () => setIsEditing(true), className: "jer-value-null", style: styles.null, children: String(value) }));
460
- };
461
- const ObjectValue = ({ value, translate, isEditing, handleEdit, handleCancel, }) => {
462
- react.useEffect(() => {
463
- if (isEditing)
464
- document.addEventListener('keydown', listenForSubmit);
465
- return () => document.removeEventListener('keydown', listenForSubmit);
466
- }, []);
467
- const listenForSubmit = (event) => {
468
- if (event.key === 'Enter') {
469
- handleEdit();
470
- }
471
- else if (event.key === 'Escape')
472
- handleCancel();
473
- };
474
- return (jsxRuntime.jsx("span", { className: "jer-value-object", children: `{${translate('DEFAULT_NEW_KEY')}: "${value}" }` }));
475
- };
476
- const ArrayValue = ({ value, isEditing, handleEdit, handleCancel, }) => {
477
- react.useEffect(() => {
478
- if (isEditing)
479
- document.addEventListener('keydown', listenForSubmit);
480
- return () => document.removeEventListener('keydown', listenForSubmit);
481
- }, []);
482
- const listenForSubmit = (event) => {
483
- if (event.key === 'Enter') {
484
- handleEdit();
485
- }
486
- else if (event.key === 'Escape')
487
- handleCancel();
488
- };
489
- return jsxRuntime.jsx("span", { className: "jer-value-array", children: `[${value === null ? '' : value}]` });
490
- };
491
- const InvalidValue = ({ value }) => {
492
- let message = 'Error!';
493
- switch (typeof value) {
494
- case 'string':
495
- if (value === INVALID_FUNCTION_STRING)
496
- message = 'Function';
497
- break;
498
- case 'undefined':
499
- message = 'Undefined';
500
- break;
501
- case 'symbol':
502
- message = 'Symbol';
503
- break;
504
- }
505
- return jsxRuntime.jsx("span", { className: "jer-value-invalid", children: message });
506
- };
507
-
508
- const Icon = ({ name, rotate }) => {
509
- var _a, _b, _c, _d, _e, _f, _g;
510
- const { styles, icons } = useTheme();
511
- const commonProps = { size: '1.4em', className: 'jer-icon' };
512
- switch (name) {
513
- case 'add':
514
- return (_a = icons === null || icons === void 0 ? void 0 : icons.add) !== null && _a !== void 0 ? _a : jsxRuntime.jsx(bi.BiPlusCircle, Object.assign({}, commonProps, { style: styles.iconAdd }));
515
- case 'edit':
516
- return (_b = icons === null || icons === void 0 ? void 0 : icons.edit) !== null && _b !== void 0 ? _b : jsxRuntime.jsx(bi.BiEdit, Object.assign({}, commonProps, { style: styles.iconEdit }));
517
- case 'delete':
518
- return ((_c = icons === null || icons === void 0 ? void 0 : icons.delete) !== null && _c !== void 0 ? _c : jsxRuntime.jsx(md.MdDeleteForever, Object.assign({}, commonProps, { style: styles.iconDelete, size: "1.5em" })));
519
- case 'copy':
520
- return (_d = icons === null || icons === void 0 ? void 0 : icons.copy) !== null && _d !== void 0 ? _d : jsxRuntime.jsx(hi.HiOutlineClipboardCopy, Object.assign({}, commonProps, { style: styles.iconCopy }));
521
- case 'ok':
522
- return ((_e = icons === null || icons === void 0 ? void 0 : icons.ok) !== null && _e !== void 0 ? _e : (jsxRuntime.jsx(fi.FiCheckCircle, Object.assign({}, commonProps, { style: Object.assign({ fontSize: '90%' }, styles.iconOk) }))));
523
- case 'cancel':
524
- return ((_f = icons === null || icons === void 0 ? void 0 : icons.cancel) !== null && _f !== void 0 ? _f : (jsxRuntime.jsx(ti.TiCancel, Object.assign({}, commonProps, { style: Object.assign({ fontSize: '130%' }, styles.iconCancel) }))));
525
- case 'chevron':
526
- return ((_g = icons === null || icons === void 0 ? void 0 : icons.chevron) !== null && _g !== void 0 ? _g : (jsxRuntime.jsx(fa.FaChevronDown, { className: `jer-accordion-icon${rotate ? ' jer-rotate-90' : ''}`, style: styles.iconCollection })));
527
- default:
528
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
529
- }
530
- };
531
-
532
- const EditButtons = ({ startEdit, handleDelete, handleAdd, enableClipboard, type, data, path, name, translate, }) => {
533
- const { styles } = useTheme();
534
- const NEW_KEY_PROMPT = translate('KEY_NEW');
535
- const [isAdding, setIsAdding] = react.useState(false);
536
- const [newKey, setNewKey] = react.useState(NEW_KEY_PROMPT);
537
- react.useEffect(() => {
538
- if (!isAdding)
539
- setNewKey(NEW_KEY_PROMPT);
540
- }, [isAdding]);
541
- const handleKeyPress = (e) => {
542
- if (e.key === 'Enter' && handleAdd) {
543
- setIsAdding(false);
544
- handleAdd(newKey);
545
- }
546
- else if (e.key === 'Escape')
547
- setIsAdding(false);
548
- };
549
- const handleCopy = (e) => {
550
- let copyType = 'value';
551
- let value;
552
- let stringValue = '';
553
- if (enableClipboard) {
554
- switch (e.ctrlKey || e.metaKey) {
555
- case true:
556
- value = stringifyPath(path);
557
- stringValue = value;
558
- copyType = 'path';
559
- break;
560
- default:
561
- value = data;
562
- stringValue = type ? JSON.stringify(data, null, 2) : String(value);
563
- }
564
- navigator.clipboard.writeText(stringValue);
565
- }
566
- if (typeof enableClipboard === 'function')
567
- enableClipboard({ value, stringValue, path, key: name, type: copyType });
568
- };
569
- return (jsxRuntime.jsxs("div", { className: "jer-edit-buttons", style: isAdding ? { opacity: 1 } : undefined, children: [enableClipboard && (jsxRuntime.jsx("div", { onClick: handleCopy, className: "jer-copy-pulse", children: jsxRuntime.jsx(Icon, { name: "copy" }) })), startEdit && (jsxRuntime.jsx("div", { onClick: startEdit, children: jsxRuntime.jsx(Icon, { name: "edit" }) })), handleDelete && (jsxRuntime.jsx("div", { onClick: handleDelete, children: jsxRuntime.jsx(Icon, { name: "delete" }) })), handleAdd && (jsxRuntime.jsx("div", { onClick: () => {
570
- if (type === 'object')
571
- setIsAdding(true);
572
- else
573
- handleAdd('');
574
- }, children: jsxRuntime.jsx(Icon, { name: "add" }) })), isAdding && handleAdd && type === 'object' && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("input", { className: "jer-input-new-key", type: "text", name: "new-object-key", value: newKey, onChange: (e) => setNewKey(e.target.value), autoFocus: true, onFocus: (e) => e.target.select(), onKeyDown: handleKeyPress, style: Object.assign({}, styles.input) }), jsxRuntime.jsx(InputButtons, { onOk: () => {
575
- if (!!newKey) {
576
- setIsAdding(false);
577
- handleAdd(newKey);
578
- }
579
- }, onCancel: () => {
580
- setIsAdding(false);
581
- } })] }))] }));
582
- };
583
- const InputButtons = ({ onOk, onCancel }) => {
584
- return (jsxRuntime.jsxs("div", { className: "jer-confirm-buttons", children: [jsxRuntime.jsx("div", { onClick: onOk, children: jsxRuntime.jsx(Icon, { name: "ok" }) }), jsxRuntime.jsx("div", { onClick: onCancel, children: jsxRuntime.jsx(Icon, { name: "cancel" }) })] }));
585
- };
586
- const stringifyPath = (path) => path.reduce((str, part) => {
587
- if (typeof part === 'number')
588
- return `${str}[${part}]`;
589
- else
590
- return str === '' ? part : `${str}.${part}`;
591
- }, '');
592
-
593
- const ERROR_DISPLAY_TIME = 2500;
594
- const ValueDataTypes = ['string', 'number', 'boolean', 'null'];
595
- const CollectionDataTypes = ['object', 'array'];
596
- const DataTypes = [...ValueDataTypes, ...CollectionDataTypes];
597
-
598
- const getCustomNode = (customNodeDefinitions = [], filterProps) => {
599
- const matchingDefinitions = customNodeDefinitions.filter(({ condition }) => condition(filterProps));
600
- if (matchingDefinitions.length === 0)
601
- return {};
602
- const { element, props, hideKey = false } = matchingDefinitions[0];
603
- return { CustomNode: element, customNodeProps: props, hideKey };
604
- };
605
-
606
- const CustomNodeWrapper = ({ name, hideKey, children, indent, }) => {
607
- const { styles } = useTheme();
608
- const indentStyle = indent ? { marginLeft: `${indent / 2}em` } : {};
609
- return (jsxRuntime.jsx("div", { className: "jer-component jer-value-component", style: indentStyle, children: jsxRuntime.jsxs("div", { className: "jer-value-main-row", style: {
610
- flexWrap: name.length > 10 ? 'wrap' : 'nowrap',
611
- }, children: [!hideKey && (jsxRuntime.jsxs("label", { htmlFor: name, className: "jer-object-key", style: Object.assign(Object.assign({}, styles.property), { minWidth: `${Math.min(String(name).length + 1, 5)}ch`, flexShrink: name.length > 10 ? 1 : 0 }), children: [name, ":", ' '] })), jsxRuntime.jsx("div", { className: "jer-value-and-buttons", style: { paddingLeft: hideKey ? 0 : undefined }, children: children })] }) }));
612
- };
613
-
614
- const ValueNodeWrapper = (props) => {
615
- const { data, parentData, name, path, onEdit, onDelete, enableClipboard, restrictEditFilter, restrictDeleteFilter, restrictTypeSelection, showLabel, stringTruncate, indent, translate, customNodeDefinitions, } = props;
616
- const { styles } = useTheme();
617
- const [isEditing, setIsEditing] = react.useState(false);
618
- const [isEditingKey, setIsEditingKey] = react.useState(false);
619
- const [value, setValue] = react.useState(typeof data === 'function' ? INVALID_FUNCTION_STRING : data);
620
- const [error, setError] = react.useState(null);
621
- const [dataType, setDataType] = react.useState(getDataType(data));
622
- react.useEffect(() => {
623
- setValue(typeof data === 'function' ? INVALID_FUNCTION_STRING : data);
624
- setDataType(getDataType(data));
625
- }, [data, error]);
626
- const handleChangeDataType = (type) => {
627
- const customNode = customNodeDefinitions.find((customNode) => customNode.name === type);
628
- if (customNode) {
629
- onEdit(customNode.defaultValue, path);
630
- }
631
- else {
632
- setValue(convertValue(value, type));
633
- setDataType(type);
634
- }
635
- };
636
- const logError = (errorString) => {
637
- setError(errorString);
638
- setTimeout(() => setError(null), ERROR_DISPLAY_TIME);
639
- console.log('Error', errorString);
640
- };
641
- const handleEdit = () => {
642
- setIsEditing(false);
643
- let newValue;
644
- switch (dataType) {
645
- case 'object':
646
- newValue = { [translate('DEFAULT_NEW_KEY')]: value };
647
- break;
648
- case 'array':
649
- newValue = value !== null ? value : [];
650
- break;
651
- case 'number':
652
- const n = Number(value);
653
- if (isNaN(n))
654
- newValue = 0;
655
- else
656
- newValue = n;
657
- break;
658
- default:
659
- newValue = value;
660
- }
661
- onEdit(newValue, path).then((error) => {
662
- if (error)
663
- logError(error);
664
- });
665
- };
666
- const handleEditKey = (newKey) => {
667
- setIsEditingKey(false);
668
- if (!parentData)
669
- return;
670
- const parentPath = path.slice(0, -1);
671
- if (!newKey)
672
- return;
673
- const newData = Object.fromEntries(Object.entries(parentData).map(([key, val]) => (key === name ? [newKey, val] : [key, val])));
674
- onEdit(newData, parentPath);
675
- };
676
- const handleKeyPress = (e) => {
677
- if (e.key === 'Enter')
678
- handleEditKey(e.target.value);
679
- else if (e.key === 'Escape')
680
- handleCancel();
681
- };
682
- const handleCancel = () => {
683
- setIsEditing(false);
684
- setIsEditingKey(false);
685
- setValue(data);
686
- setDataType(getDataType(data));
687
- };
688
- const handleDelete = () => {
689
- onDelete(value, path).then((error) => {
690
- if (error)
691
- logError(error);
692
- });
693
- };
694
- const filterProps = { key: name, path, level: path.length, value: data, size: null };
695
- const canEdit = react.useMemo(() => !restrictEditFilter(filterProps), [filterProps]);
696
- const canDelete = react.useMemo(() => !restrictDeleteFilter(filterProps), [filterProps]);
697
- const isArray = typeof path.slice(-1)[0] === 'number';
698
- const canEditKey = !isArray && canEdit && canDelete;
699
- const inputProps = {
700
- value,
701
- parentData,
702
- setValue,
703
- isEditing,
704
- setIsEditing: canEdit ? () => setIsEditing(true) : () => { },
705
- handleEdit,
706
- handleCancel,
707
- path,
708
- stringTruncate,
709
- translate,
710
- };
711
- const { CustomNode, customNodeProps, hideKey } = getCustomNode(customNodeDefinitions, {
712
- key: name,
713
- path,
714
- level: path.length,
715
- value: data,
716
- size: 0,
717
- });
718
- const allDataTypes = [
719
- ...customNodeDefinitions
720
- .filter(({ showInTypesSelector = false }) => showInTypesSelector)
721
- .map(({ name }) => name),
722
- ...DataTypes,
723
- ];
724
- const allowedDataTypes = react.useMemo(() => {
725
- if (typeof restrictTypeSelection === 'boolean')
726
- return restrictTypeSelection ? [] : allDataTypes;
727
- if (Array.isArray(restrictTypeSelection))
728
- return restrictTypeSelection;
729
- const result = restrictTypeSelection(filterProps);
730
- if (typeof result === 'boolean')
731
- return result ? [] : allDataTypes;
732
- return result;
733
- }, [filterProps, restrictTypeSelection]);
734
- return CustomNode ? (jsxRuntime.jsx(CustomNodeWrapper, { name: name, hideKey: hideKey, indent: indent, children: jsxRuntime.jsx(CustomNode, Object.assign({ customProps: customNodeProps }, props)) })) : (jsxRuntime.jsx("div", { className: "jer-component jer-value-component", style: { marginLeft: `${indent / 2}em` }, children: jsxRuntime.jsxs("div", { className: "jer-value-main-row", style: {
735
- flexWrap: name.length > 10 ? 'wrap' : 'nowrap',
736
- }, children: [showLabel && !isEditingKey && (jsxRuntime.jsxs("label", { htmlFor: path.join('.'), className: "jer-object-key", style: Object.assign(Object.assign({}, styles.property), { minWidth: `${Math.min(String(name).length + 1, 5)}ch`, flexShrink: name.length > 10 ? 1 : 0 }), onDoubleClick: () => canEditKey && setIsEditingKey(true), children: [name, ":", ' '] })), showLabel && isEditingKey && (jsxRuntime.jsx("input", { className: "jer-object-key", type: "text", name: path.join('.'), defaultValue: name, autoFocus: true, onFocus: (e) => e.target.select(), onKeyDown: handleKeyPress, style: { width: `${String(name).length / 1.5 + 0.5}em` } })), jsxRuntime.jsxs("div", { className: "jer-value-and-buttons", children: [jsxRuntime.jsx("div", { className: "jer-input-component", children: getInputComponent(dataType, inputProps) }), isEditing ? (jsxRuntime.jsx(InputButtons, { onOk: handleEdit, onCancel: handleCancel })) : (dataType !== 'invalid' &&
737
- !error && (jsxRuntime.jsx(EditButtons, { startEdit: canEdit ? () => setIsEditing(true) : undefined, handleDelete: canDelete ? handleDelete : undefined, data: data, enableClipboard: enableClipboard, name: name, path: path, translate: translate }))), isEditing && allowedDataTypes.length > 0 && (jsxRuntime.jsxs("div", { className: "jer-select", children: [jsxRuntime.jsx("select", { name: `${name}-type-select`, className: "jer-type-select", onChange: (e) => handleChangeDataType(e.target.value), value: dataType, children: allowedDataTypes.map((type) => (jsxRuntime.jsx("option", { value: type, children: type }, type))) }), jsxRuntime.jsx("span", { className: "focus" })] })), !isEditing && error && (jsxRuntime.jsx("span", { className: "jer-error-slug", style: styles.error, children: error }))] })] }) }));
738
- };
739
- const getDataType = (value) => {
740
- if (typeof value === 'string')
741
- return 'string';
742
- if (typeof value === 'number')
743
- return 'number';
744
- if (typeof value === 'boolean')
745
- return 'boolean';
746
- if (value === null)
747
- return 'null';
748
- return 'invalid';
749
- };
750
- const getInputComponent = (dataType, inputProps) => {
751
- const value = inputProps.value;
752
- switch (dataType) {
753
- case 'string':
754
- return jsxRuntime.jsx(StringValue, Object.assign({}, inputProps, { value: value }));
755
- case 'number':
756
- return jsxRuntime.jsx(NumberValue, Object.assign({}, inputProps, { value: value }));
757
- case 'boolean':
758
- return jsxRuntime.jsx(BooleanValue, Object.assign({}, inputProps, { value: value }));
759
- case 'null':
760
- return jsxRuntime.jsx(NullValue, Object.assign({}, inputProps));
761
- case 'object':
762
- return jsxRuntime.jsx(ObjectValue, Object.assign({}, inputProps, { value: value }));
763
- case 'array':
764
- return jsxRuntime.jsx(ArrayValue, Object.assign({}, inputProps));
765
- default:
766
- return jsxRuntime.jsx(InvalidValue, Object.assign({}, inputProps));
767
- }
768
- };
769
- const convertValue = (value, type) => {
770
- switch (type) {
771
- case 'string':
772
- return String(value);
773
- case 'number':
774
- const n = Number(value);
775
- return isNaN(n) ? 0 : n;
776
- case 'boolean':
777
- return !!value;
778
- case 'null':
779
- return null;
780
- case 'object':
781
- return value;
782
- case 'array':
783
- return [value];
784
- default:
785
- return String(value);
786
- }
787
- };
788
-
789
- const isCollection = (value) => value !== null && typeof value == 'object';
790
- const CollectionNode = (_a) => {
791
- var { data, path, name, parentData, showCollectionCount } = _a, props = __rest(_a, ["data", "path", "name", "parentData", "showCollectionCount"]);
792
- const { styles } = useTheme();
793
- const { onEdit, onAdd, onDelete, restrictEditFilter, restrictDeleteFilter, restrictAddFilter, collapseFilter, enableClipboard, indent, keySort, showArrayIndices, defaultValue, translate, customNodeDefinitions, } = props;
794
- const [isEditing, setIsEditing] = react.useState(false);
795
- const [isEditingKey, setIsEditingKey] = react.useState(false);
796
- const [stringifiedValue, setStringifiedValue] = react.useState(JSON.stringify(data, null, 2));
797
- const [error, setError] = react.useState(null);
798
- const collectionSize = Object.keys(data).length;
799
- const filterProps = { key: name, path, level: path.length, value: data, size: collectionSize };
800
- const startCollapsed = collapseFilter(filterProps);
801
- const [collapsed, setCollapsed] = react.useState(startCollapsed);
802
- const hasBeenOpened = react.useRef(!startCollapsed);
803
- const [isAnimating, setIsAnimating] = react.useState(false);
804
- react.useEffect(() => {
805
- setStringifiedValue(JSON.stringify(data, null, 2));
806
- }, [data]);
807
- react.useEffect(() => {
808
- setCollapsed(collapseFilter(filterProps));
809
- }, [collapseFilter]);
810
- const collectionType = Array.isArray(data) ? 'array' : 'object';
811
- const brackets = collectionType === 'array' ? { open: '[', close: ']' } : { open: '{', close: '}' };
812
- const transitionTime = getComputedStyle(document.documentElement).getPropertyValue('--jer-expand-transition-time');
813
- const handleKeyPress = (e) => {
814
- if (e.key === 'Enter' && (e.metaKey || e.shiftKey || e.ctrlKey))
815
- handleEdit();
816
- else if (e.key === 'Escape')
817
- handleCancel();
818
- };
819
- const handleCollapse = () => {
820
- if (!isEditing) {
821
- setIsAnimating(true);
822
- hasBeenOpened.current = true;
823
- setCollapsed(!collapsed);
824
- setTimeout(() => setIsAnimating(false), 500);
825
- }
826
- };
827
- const showError = (errorString) => {
828
- setError(errorString);
829
- setTimeout(() => setError(null), ERROR_DISPLAY_TIME);
830
- console.log('Error', errorString);
831
- };
832
- const handleEdit = () => {
833
- try {
834
- const value = JSON.parse(stringifiedValue);
835
- setIsEditing(false);
836
- setError(null);
837
- onEdit(value, path).then((error) => {
838
- if (error)
839
- showError(error);
840
- });
841
- }
842
- catch (_a) {
843
- setError(translate('ERROR_INVALID_JSON'));
844
- setTimeout(() => setError(null), ERROR_DISPLAY_TIME);
845
- console.log('Invalid JSON');
846
- return;
847
- }
848
- };
849
- const handleEditKey = (newKey) => {
850
- setIsEditingKey(false);
851
- if (!parentData)
852
- return;
853
- const parentPath = path.slice(0, -1);
854
- if (!newKey)
855
- return;
856
- const newData = Object.fromEntries(Object.entries(parentData).map(([key, val]) => (key === name ? [newKey, val] : [key, val])));
857
- onEdit(newData, parentPath);
858
- };
859
- const handleKeyPressKeyEdit = (e) => {
860
- if (e.key === 'Enter')
861
- handleEditKey(e.target.value);
862
- else if (e.key === 'Escape')
863
- handleCancel();
864
- };
865
- const handleAdd = (key) => {
866
- setCollapsed(false);
867
- if (collectionType === 'array') {
868
- onAdd(defaultValue, [...path, data.length]).then((error) => {
869
- if (error)
870
- showError(error);
871
- });
872
- }
873
- else if (key in data) {
874
- showError(translate('ERROR_KEY_EXISTS'));
875
- return;
876
- }
877
- else
878
- onAdd(defaultValue, [...path, key]).then((error) => {
879
- if (error)
880
- showError(error);
881
- });
882
- };
883
- const handleDelete = path.length > 0
884
- ? () => {
885
- onDelete(data, path).then((result) => {
886
- if (result)
887
- showError(result);
888
- });
889
- }
890
- : undefined;
891
- const handleCancel = () => {
892
- setIsEditing(false);
893
- setError(null);
894
- setStringifiedValue(JSON.stringify(data, null, 2));
895
- };
896
- const canEdit = react.useMemo(() => !restrictEditFilter(filterProps), [filterProps]);
897
- const canDelete = react.useMemo(() => !restrictDeleteFilter(filterProps), [filterProps]);
898
- const canAdd = react.useMemo(() => !restrictAddFilter(filterProps), [filterProps]);
899
- const canEditKey = parentData !== null && canEdit && canAdd && canDelete;
900
- const isArray = typeof path.slice(-1)[0] === 'number';
901
- const showLabel = showArrayIndices || !isArray;
902
- const showCount = showCollectionCount === 'when-closed' ? collapsed : showCollectionCount;
903
- const keyValueArray = Object.entries(data).map(([key, value]) => [
904
- collectionType === 'array' ? Number(key) : key,
905
- value,
906
- ]);
907
- if (keySort && collectionType === 'object')
908
- keyValueArray.sort(typeof keySort === 'function' ? (a, b) => keySort(a[0], b[0]) : undefined);
909
- const numOfLines = JSON.stringify(data, null, 2).split('\n').length;
910
- const { CustomNode, customNodeProps, hideKey } = getCustomNode(customNodeDefinitions, {
911
- key: name,
912
- path,
913
- level: path.length,
914
- value: data,
915
- size: Object.keys(data).length,
916
- });
917
- return (jsxRuntime.jsx("div", { className: "jer-component fb-collection-component", style: { marginLeft: `${path.length === 0 ? 0 : indent / 2}em` }, children: CustomNode ? (jsxRuntime.jsx(CustomNodeWrapper, { name: name, hideKey: hideKey, children: jsxRuntime.jsx(CustomNode, Object.assign({ data: data, path: path, name: name, parentData: parentData, customProps: customNodeProps }, props)) })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: "jer-collection-header-row", children: [jsxRuntime.jsx("div", { onClick: handleCollapse, children: jsxRuntime.jsx(Icon, { name: "chevron", rotate: collapsed }) }), jsxRuntime.jsxs("div", { className: "jer-collection-name", children: [!isEditingKey && (jsxRuntime.jsx("span", { style: styles.property, onDoubleClick: () => canEditKey && setIsEditingKey(true), children: showLabel && name !== '' && name !== undefined ? `${name}:` : null })), isEditingKey && (jsxRuntime.jsx("input", { className: "jer-collection-name", type: "text", name: path.join('.'), defaultValue: name, autoFocus: true, onFocus: (e) => e.target.select(), onKeyDown: handleKeyPressKeyEdit, style: { width: `${String(name).length / 1.5 + 0.5}em` } })), !isEditing && (jsxRuntime.jsx("span", { className: "jer-brackets", style: styles.bracket, children: brackets.open }))] }), !isEditing && showCollectionCount && (jsxRuntime.jsx("div", { className: `jer-collection-item-count${showCount ? ' jer-visible' : ' jer-hidden'}`, style: styles.itemCount, children: collectionSize === 1
918
- ? translate('ITEM_SINGLE', 1)
919
- : translate('ITEMS_MULTIPLE', collectionSize) })), jsxRuntime.jsx("div", { className: `jer-brackets${collapsed ? ' jer-visible' : ' jer-hidden'}`, style: styles.bracket, children: brackets.close }), !isEditing && (jsxRuntime.jsx(EditButtons, { startEdit: canEdit
920
- ? () => {
921
- setIsEditing(true);
922
- setCollapsed(false);
923
- }
924
- : undefined, handleAdd: canAdd ? handleAdd : undefined, handleDelete: canDelete ? handleDelete : undefined, enableClipboard: enableClipboard, type: collectionType, data: data, name: name, path: path, translate: translate }))] }), jsxRuntime.jsxs("div", { className: 'jer-collection-inner', style: {
925
- maxHeight: collapsed ? 0 : !isEditing ? `${numOfLines * 3}em` : undefined,
926
- overflowY: collapsed || isAnimating ? 'hidden' : 'visible',
927
- transition: `max-height ${transitionTime}`,
928
- }, children: [isEditing ? (jsxRuntime.jsx("div", { className: "jer-collection-text-edit", children: jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(AutogrowTextArea, { className: "jer-collection-text-area", name: path.join('.'), value: stringifiedValue, setValue: setStringifiedValue, isEditing: isEditing, handleKeyPress: handleKeyPress }), jsxRuntime.jsx("div", { className: "jer-collection-input-button-row", children: jsxRuntime.jsx(InputButtons, { onOk: handleEdit, onCancel: handleCancel, isCollection: true }) })] }) })) : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: !hasBeenOpened.current
929
- ? null
930
- : keyValueArray.map(([key, value]) => (jsxRuntime.jsx("div", { className: "jer-collection-element", children: isCollection(value) ? (jsxRuntime.jsx(CollectionNode, Object.assign({ data: value, parentData: data, path: [...path, key], name: key, showCollectionCount: showCollectionCount }, props), key)) : (jsxRuntime.jsx(ValueNodeWrapper, Object.assign({ data: value, parentData: data, path: [...path, key], name: key }, props, { showLabel: collectionType === 'object' ? true : showArrayIndices }), key)) }, key))) })), jsxRuntime.jsx("div", { className: isEditing ? 'jer-collection-error-row' : 'jer-collection-error-row-edit', children: error && (jsxRuntime.jsx("span", { className: "jer-error-slug", style: styles.error, children: error })) }), jsxRuntime.jsx("div", { className: "jer-brackets", style: styles.bracket, children: brackets.close })] })] })) }));
931
- };
932
-
933
- const localisedStrings = {
934
- ITEM_SINGLE: '{{count}} item',
935
- ITEMS_MULTIPLE: '{{count}} items',
936
- KEY_NEW: 'Enter new key',
937
- ERROR_KEY_EXISTS: 'Key already exists',
938
- ERROR_INVALID_JSON: 'Invalid JSON',
939
- ERROR_UPDATE: 'Update unsuccessful',
940
- ERROR_DELETE: 'Delete unsuccessful',
941
- ERROR_ADD: 'Adding node unsuccessful',
942
- DEFAULT_STRING: 'New data!',
943
- DEFAULT_NEW_KEY: 'key',
944
- };
945
- const translate = (translations, key, count) => {
946
- const string = key in translations ? translations[key] : localisedStrings[key];
947
- return count === undefined ? string : string === null || string === void 0 ? void 0 : string.replace('{{count}}', String(count));
948
- };
949
- const getTranslateFunction = (translations) => (key, count) => translate(translations, key, count);
950
-
951
- const Editor = ({ data: srcData, rootName = 'root', onUpdate, onEdit: srcEdit = onUpdate, onDelete: srcDelete = onUpdate, onAdd: srcAdd = onUpdate, enableClipboard = true, theme = 'default', icons, indent = 4, collapse = false, showCollectionCount = true, restrictEdit = false, restrictDelete = false, restrictAdd = false, restrictTypeSelection = false, keySort = false, showArrayIndices = true, defaultValue = null, minWidth = 250, maxWidth = 'min(600px, 90vw)', stringTruncate = 250, translations = {}, className, customNodeDefinitions = [], }) => {
952
- const [data, setData] = react.useState(srcData);
953
- const { styles, setTheme, setIcons } = useTheme();
954
- const collapseFilter = react.useCallback(getFilterFunction(collapse), [collapse]);
955
- const translate = react.useCallback(getTranslateFunction(translations), [translations]);
956
- react.useEffect(() => {
957
- setData(srcData);
958
- }, [srcData]);
959
- react.useEffect(() => {
960
- if (theme)
961
- setTheme(theme);
962
- if (icons)
963
- setIcons(icons);
964
- }, [theme, icons]);
965
- const onEdit = (value, path) => __awaiter(void 0, void 0, void 0, function* () {
966
- const { currentData, newData, currentValue, newValue } = updateDataObject(data, path, value, 'update');
967
- if (srcEdit) {
968
- const result = yield srcEdit({
969
- currentData,
970
- newData,
971
- currentValue,
972
- newValue,
973
- name: path.slice(-1)[0],
974
- path,
975
- });
976
- if (result === undefined)
977
- setData(newData);
978
- if (result === false)
979
- return translate('ERROR_UPDATE');
980
- return result;
981
- }
982
- else
983
- setData(newData);
984
- });
985
- const onDelete = (value, path) => __awaiter(void 0, void 0, void 0, function* () {
986
- const { currentData, newData, currentValue, newValue } = updateDataObject(data, path, value, 'delete');
987
- if (srcDelete) {
988
- const result = yield srcDelete({
989
- currentData,
990
- newData,
991
- currentValue,
992
- newValue,
993
- name: path.slice(-1)[0],
994
- path,
995
- });
996
- if (result === undefined)
997
- setData(newData);
998
- if (result === false)
999
- return translate('ERROR_DELETE');
1000
- return result;
1001
- }
1002
- else
1003
- setData(newData);
1004
- });
1005
- const onAdd = (value, path) => __awaiter(void 0, void 0, void 0, function* () {
1006
- const { currentData, newData, currentValue, newValue } = updateDataObject(data, path, value, 'add');
1007
- if (srcAdd) {
1008
- const result = yield srcAdd({
1009
- currentData,
1010
- newData,
1011
- currentValue,
1012
- newValue,
1013
- name: path.slice(-1)[0],
1014
- path,
1015
- });
1016
- if (result === undefined)
1017
- setData(newData);
1018
- if (result === false)
1019
- return translate('ERROR_ADD');
1020
- return result;
1021
- }
1022
- else
1023
- setData(newData);
1024
- });
1025
- const restrictEditFilter = getFilterFunction(restrictEdit);
1026
- const restrictDeleteFilter = getFilterFunction(restrictDelete);
1027
- const restrictAddFilter = getFilterFunction(restrictAdd);
1028
- const otherProps = {
1029
- name: rootName,
1030
- onEdit,
1031
- onDelete,
1032
- onAdd,
1033
- showCollectionCount,
1034
- collapseFilter,
1035
- restrictEditFilter,
1036
- restrictDeleteFilter,
1037
- restrictAddFilter,
1038
- restrictTypeSelection,
1039
- enableClipboard,
1040
- keySort,
1041
- showArrayIndices,
1042
- indent,
1043
- defaultValue,
1044
- stringTruncate,
1045
- translate,
1046
- customNodeDefinitions,
1047
- parentData: null,
1048
- };
1049
- if (!styles)
1050
- return null;
1051
- return (jsxRuntime.jsx("div", { className: 'jer-editor-container ' + className, style: Object.assign(Object.assign({}, styles.container), { minWidth, maxWidth }), children: isCollection(data) ? (jsxRuntime.jsx(CollectionNode, Object.assign({ data: data, path: [] }, otherProps))) : (jsxRuntime.jsx(ValueNodeWrapper, Object.assign({ data: data, path: [], showLabel: true }, otherProps))) }));
1052
- };
1053
- const JsonEditor = (props) => (jsxRuntime.jsx(ThemeProvider, { children: jsxRuntime.jsx(Editor, Object.assign({}, props)) }));
1054
- const updateDataObject = (data, path, newValue, action) => {
1055
- if (path.length === 0) {
1056
- return {
1057
- currentData: data,
1058
- newData: newValue,
1059
- currentValue: data,
1060
- newValue: newValue,
1061
- };
1062
- }
1063
- const currentValue = action !== 'add' ? extract(data, path) : undefined;
1064
- const newData = assign(clone(data), path, newValue, { remove: action === 'delete' });
1065
- return {
1066
- currentData: data,
1067
- newData,
1068
- currentValue,
1069
- newValue: action === 'update' ? newValue : undefined,
1070
- };
1071
- };
1072
- const getFilterFunction = (propValue) => {
1073
- if (typeof propValue === 'boolean')
1074
- return () => propValue;
1075
- if (typeof propValue === 'number')
1076
- return ({ level }) => level >= propValue;
1077
- return propValue;
1078
- };
1079
-
1080
- exports.JsonEditor = JsonEditor;
1081
- exports.themes = themes;
1
+ "use strict";var jsxRuntime=require("react/jsx-runtime"),react=require("react"),assign=require("object-property-assigner"),extract=require("object-property-extractor"),clone=require("just-clone"),hi=require("react-icons/hi"),bi=require("react-icons/bi"),md=require("react-icons/md"),fi=require("react-icons/fi"),ti=require("react-icons/ti"),fa=require("react-icons/fa");function __awaiter(thisArg,_arguments,P,generator){return new(P||(P=Promise))((function(resolve,reject){function fulfilled(value){try{step(generator.next(value))}catch(e){reject(e)}}function rejected(value){try{step(generator.throw(value))}catch(e){reject(e)}}function step(result){var value;result.done?resolve(result.value):(value=result.value,value instanceof P?value:new P((function(resolve){resolve(value)}))).then(fulfilled,rejected)}step((generator=generator.apply(thisArg,_arguments||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var e=[],t=[];!function(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c()}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n))}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}(":root {\n --jer-select-border: #b6b6b6;\n --jer-select-focus: #777;\n --jer-select-arrow: #777;\n --jer-form-border: 1px solid #ededf0;\n --jer-form-border-focus: 1px solid #e2e2e2;\n --jer-expand-transition-time: 0.5s;\n --jer-highlight-color: #b3d8ff;\n}\n\n.jer-visible {\n opacity: 1;\n transition: var(--jer-expand-transition-time);\n}\n\n.jer-hidden {\n opacity: 0;\n transition: var(--jer-expand-transition-time);\n}\n\n/* Select styled as per:\nhttps://moderncss.dev/custom-select-styles-with-pure-css/\n*/\n\n.jer-select select {\n -webkit-appearance: none;\n -moz-appearance: none;\n appearance: none;\n background-color: transparent;\n border: none;\n padding: 0 1em 0 0;\n margin: 0;\n /* width: 100%; */\n font-family: inherit;\n font-size: inherit;\n color: black;\n cursor: inherit;\n line-height: inherit;\n z-index: 1;\n outline: none;\n}\nselect::-ms-expand {\n display: none;\n}\n\n.jer-select {\n display: grid;\n grid-template-areas: 'select';\n align-items: center;\n position: relative;\n min-width: 12ch;\n max-width: 15ch;\n border: 1px solid var(--jer-select-border);\n border-radius: 0.25em;\n padding: 0.25em 0.5em;\n font-size: 1em;\n cursor: pointer;\n line-height: 1.1;\n background-color: #fff;\n background-image: linear-gradient(to top, #f9f9f9, #fff 33%);\n}\n.jer-select select,\n.jer-select::after {\n grid-area: select;\n}\n.jer-select:not(.jer-select--multiple)::after {\n content: '';\n justify-self: end;\n width: 0.8em;\n height: 0.5em;\n background-color: var(--jer-select-arrow);\n -webkit-clip-path: polygon(100% 0%, 0 0%, 50% 100%);\n clip-path: polygon(100% 0%, 0 0%, 50% 100%);\n}\n\nselect:focus + .focus {\n position: absolute;\n top: -1px;\n left: -1px;\n right: -1px;\n bottom: -1px;\n border: 1px solid var(--jer-select-focus);\n border-radius: inherit;\n}\n\n.jer-editor-container {\n font-size: 1.1em;\n /* font-size: 20px; */\n padding: 1em;\n margin-top: 1em;\n margin-bottom: 1em;\n border-radius: 0.5em;\n}\n\n.jer-editor-container textarea {\n /* width: 90%; */\n color: var(--jer-input-color);\n border: var(--jer-form-border);\n border-radius: 0.3em;\n outline: none;\n}\n\n.jer-editor-container textarea:focus {\n border: var(--jer-form-border-focus);\n}\n\n.jer-editor-container input {\n border: var(--jer-form-border);\n border-radius: 0.3em;\n outline: none;\n}\n\n.jer-editor-container input:focus {\n border: var(--jer-form-border-focus);\n}\n\n/* Input highlighted text */\n.jer-editor-container ::selection {\n background-color: var(--jer-highlight-color);\n}\n\n.jer-editor-container select {\n /* color: red; */\n}\n\n.jer-component {\n}\n\n.jer-collection-header-row,\n.jer-value-main-row {\n display: flex;\n min-height: 1.7em;\n gap: 0.3em;\n align-items: center;\n}\n\n.jer-collection-header-row {\n display: flex;\n flex-wrap: wrap;\n}\n\n.jer-brackets {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collection-inner {\n position: relative;\n}\n\n.jer-collection-text-edit {\n display: flex;\n flex-direction: column;\n gap: 0.3em;\n align-items: flex-start;\n}\n\n.jer-collection-text-area {\n resize: both;\n padding-top: 0.2em;\n padding-left: 0.5em;\n padding-right: 0.5em;\n padding-bottom: 0;\n overflow: hidden;\n max-height: 40em;\n}\n\n.jer-collection-input-button-row {\n display: flex;\n justify-content: flex-end;\n font-size: 150%;\n}\n\n.jer-collection-element {\n}\n\n.jer-collection-error-row {\n position: absolute;\n bottom: 0;\n}\n\n.jer-collection-error-row-edit {\n}\n\n.jer-error-slug {\n margin-left: 1em;\n}\n\n.jer-value-component {\n position: relative;\n}\n\n.jer-value-main-row {\n display: flex;\n gap: 0;\n}\n\n.jer-value-and-buttons {\n display: flex;\n justify-content: flex-start;\n align-items: center;\n padding-left: 0.5em;\n}\n\n.jer-value-error-row {\n position: absolute;\n}\n\n.jer-value-string {\n line-height: 1.3em;\n}\n\n.jer-input-text {\n resize: none;\n margin: 0;\n height: 1.4em;\n padding-left: 0.5em;\n padding-right: 0.5em;\n padding-bottom: 0;\n min-width: 6em;\n overflow: hidden;\n max-height: 30em;\n}\n\n.jer-value-number {\n}\n\n.jer-value-boolean {\n}\n\n.jer-input-boolean {\n transform: scale(1.5);\n margin-left: 0.3em;\n margin-right: 0.3em;\n}\n\n.jer-value-null {\n}\n\n.jer-value-object {\n}\n\n.jer-object-key {\n word-break: break-word;\n line-height: 1.1em;\n}\n\n.jer-value-array {\n}\n\n.jer-value-invalid {\n opacity: 0.5;\n font-style: italic;\n}\n\n/* .jer-input-text, */\n.jer-input-number {\n height: 1.6em;\n}\n\n.jer-input-number {\n min-width: 3em;\n}\n\n.jer-input-component {\n}\n\n.jer-edit-buttons,\n.jer-confirm-buttons {\n display: flex;\n align-items: center;\n cursor: pointer;\n}\n\n.jer-input-buttons {\n gap: 0.4em;\n}\n\n.jer-edit-buttons {\n gap: 0.4em;\n margin-left: 0.5em;\n opacity: 0;\n}\n\n.jer-confirm-buttons {\n gap: 0.2em;\n margin-left: 0.4em;\n}\n\n.jer-edit-buttons:hover {\n opacity: 1;\n position: relative;\n}\n\n.jer-collection-header-row:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-value-main-row:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-value-and-buttons:hover > .jer-edit-buttons {\n opacity: 1;\n}\n\n.jer-input-buttons {\n}\n\n.jer-copy-pulse {\n position: relative;\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-copy-pulse:hover {\n opacity: 0.85;\n transition: 0.3s;\n transform: scale(1.2);\n}\n\n.jer-copy-pulse:after {\n content: '';\n display: block;\n position: absolute;\n border-radius: 50%;\n left: 0;\n top: 0;\n width: 100%;\n height: 100%;\n opacity: 0;\n transition: all 0.5s;\n box-shadow: 0 0 15px 5px var(--jer-icon-copy-color);\n}\n\n.jer-copy-pulse:active:after {\n box-shadow: 0 0 0 0 var(--jer-icon-copy-color);\n position: absolute;\n border-radius: 4em;\n left: 0;\n top: 0;\n opacity: 1;\n transition: 0s;\n}\n\n.jer-copy-pulse:active {\n top: 0.07em;\n}\n\n.jer-rotate-90 {\n transform: rotate(-90deg);\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-accordion-icon {\n /* font-size: '2em'; */\n transition: transform var(--jer-expand-transition-time);\n}\n\n.jer-icon:hover {\n opacity: 0.85;\n transition: 0.3s;\n transform: scale(1.2);\n}\n",{});const themes={default:{displayName:"Default",fragments:{edit:"rgb(42, 161, 152)"},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},property:"#292929",bracket:{color:"rgb(0, 43, 54)",fontWeight:"bold"},itemCount:{color:"rgba(0, 0, 0, 0.3)",fontStyle:"italic"},string:"rgb(203, 75, 22)",number:"rgb(38, 139, 210)",boolean:"green",null:{color:"rgb(220, 50, 47)",fontVariant:"small-caps",fontWeight:"bold"},input:["#292929",{fontSize:"90%"}],inputHighlight:"#b3d8ff",error:{fontSize:"0.8em",color:"red",fontWeight:"bold"},iconCollection:"rgb(0, 43, 54)",iconEdit:"edit",iconDelete:"rgb(203, 75, 22)",iconAdd:"edit",iconCopy:"rgb(38, 139, 210)",iconOk:"green",iconCancel:"rgb(203, 75, 22)"}},githubDark:{displayName:"Github Dark",styles:{container:{backgroundColor:"#0d1117",color:"white"},property:"#E6EDF3",bracket:"#56d364",itemCount:"#8B949E",string:"#A5D6FF",number:"#D2A8FF",boolean:{color:"#FF7B72",fontSize:"90%",fontWeight:"bold"},null:"green",iconCollection:"#D2A8FF",iconEdit:"#D2A8FF",iconDelete:"rgb(203, 75, 22)",iconAdd:"rgb(203, 75, 22)",iconCopy:"#A5D6FF",iconOk:"#56d364",iconCancel:"rgb(203, 75, 22)"}},githubLight:{displayName:"Github Light",styles:{container:"white",property:"#1F2328",bracket:"#00802e",itemCount:"#8B949E",string:"#0A3069",number:"#953800",boolean:{color:"#CF222E",fontSize:"90%",fontWeight:"bold"},null:"#FF7B72",iconCollection:"#8250DF",iconEdit:"#8250DF",iconDelete:"rgb(203, 75, 22)",iconAdd:"#8250DF",iconCopy:"#57606A"}},monoDark:{displayName:"Black & White",fragments:{lightText:{color:"white"},midGrey:"#5c5c5c"},styles:{container:["lightText",{backgroundColor:"black"}],property:"lightText",bracket:"midGrey",itemCount:"#4a4a4a",string:"#a8a8a8",number:"#666666",boolean:{color:"#848484",fontStyle:"italic"},null:"#333333",iconCollection:"midGrey",iconEdit:"midGrey",iconDelete:"midGrey",iconAdd:"midGrey",iconCopy:"midGrey",iconOk:"midGrey",iconCancel:"midGrey"}},monoLight:{fragments:{midGrey:"#a3a3a3"},displayName:"White & Black",styles:{container:"white",property:"black",bracket:"midGrey",itemCount:"#b5b5b5",string:"#575757",number:"#999999",boolean:{color:"#7b7b7b",fontStyle:"italic"},null:"#cccccc",iconCollection:"midGrey",iconEdit:"midGrey",iconDelete:"midGrey",iconAdd:"midGrey",iconCopy:"midGrey",iconOk:"midGrey",iconCancel:"midGrey"}},candyWrapper:{displayName:"Candy Wrapper",fragments:{minty:{backgroundColor:"#F1FAEE"},pale:{color:"#A8DADC"},mid:{color:"#457B9D"},dark:{color:"#1D3557"},pop:{color:"#E63946"},darkBlue:{color:"#2B2D42"}},styles:{container:"minty",property:"pop",bracket:"dark",itemCount:"pale",string:"mid",number:["darkBlue",{fontSize:"85%"}],boolean:["mid",{fontStyle:"italic",fontWeight:"bold",fontSize:"80%"}],null:["#cccccc",{fontWeight:"bold"}],iconCollection:"#1D3557",iconEdit:"#457B9D",iconDelete:"#E63946",iconAdd:"#2B2D42",iconCopy:"#1D3557",iconCancel:"#E63946"}},psychedelic:{displayName:"Psychedelic",fragments:{minty:{backgroundColor:"#F1FAEE"},pale:{color:"#A8DADC"},mid:{color:"#457B9D"},dark:{color:"#1D3557"},pop:{color:"#E63946"},fluroYellow:"rgb(242, 228, 21)",fluroGreen:"rgb(68, 255, 62)",hotPink:"#f7379a"},styles:{container:{backgroundColor:"unset",background:"linear-gradient(90deg, hsla(333, 100%, 53%, 1) 0%, hsla(33, 94%, 57%, 1) 100%)",color:"black"},property:"black",bracket:"fluroYellow",itemCount:["pale",{opacity:.7}],string:"white",number:["#33d9ff",{fontSize:"90%",fontWeight:"bold"}],boolean:["fluroGreen",{fontWeight:"bold",fontSize:"80%"}],null:["black",{fontWeight:"bold",opacity:.3,backgroundColor:"rgb(255, 255, 255, 0.5)",padding:"0 0.4em",borderRadius:"0.4em"}],iconCollection:"fluroYellow",iconEdit:["black"],iconDelete:["white",{opacity:.5}],iconAdd:["white",{opacity:.5}],iconCopy:"rgb(32, 84, 242)",iconOk:"fluroGreen",iconCancel:"hotPink"}}},emptyStyleObject={container:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},defaultTheme=themes.default,initialContext={styles:emptyStyleObject,setTheme:_=>{},icons:{},setIcons:()=>{}},ThemeProviderContext=react.createContext(initialContext),ThemeProvider=({children:children})=>{const[styles,setStyles]=react.useState(emptyStyleObject),[icons,setIcons]=react.useState({});return jsxRuntime.jsx(ThemeProviderContext.Provider,{value:{styles:styles,setTheme:theme=>setStyles(compileStyles(theme)),icons:icons,setIcons:setIcons},children:children})},useTheme=()=>react.useContext(ThemeProviderContext),compileStyles=themeInput=>{if("string"==typeof themeInput)return buildStyleObject(themes[themeInput]);if(Array.isArray(themeInput)){const[name,overrides]=themeInput;return buildStyleObject(themes[name],isStyleObject(overrides)?{styles:overrides}:overrides)}return buildStyleObject(defaultTheme,isStyleObject(themeInput)?{styles:themeInput}:themeInput)},buildStyleObject=(baseTheme,overrides={styles:emptyStyleObject})=>{var _a,_b,_c,_d;const[defaultStyles,baseStyles,overrideStyles]=[defaultTheme,baseTheme,overrides].map((theme=>{const{fragments:fragments,styles:styles}=theme,compiledStyles={};return Object.entries(styles).forEach((([key,value])=>{const cssStyles=(Array.isArray(value)?value:[value]).reduce(((acc,curr)=>{var _a;if("string"==typeof curr){const style=null!==(_a=null==fragments?void 0:fragments[curr])&&void 0!==_a?_a:curr;return"string"==typeof style?Object.assign(Object.assign({},acc),{[defaultStyleProperties[key]]:style}):Object.assign(Object.assign({},acc),style)}return Object.assign(Object.assign({},acc),curr)}),{});compiledStyles[key]=cssStyles})),compiledStyles})),finalStyles={};return Object.keys(defaultTheme.styles).forEach((key=>{finalStyles[key]=Object.assign(Object.assign(Object.assign({},defaultStyles[key]),baseStyles[key]),overrideStyles[key])})),(null===(_a=null==finalStyles?void 0:finalStyles.inputHighlight)||void 0===_a?void 0:_a.backgroundColor)&&document.documentElement.style.setProperty("--jer-highlight-color",null===(_b=null==finalStyles?void 0:finalStyles.inputHighlight)||void 0===_b?void 0:_b.backgroundColor),(null===(_c=null==finalStyles?void 0:finalStyles.iconCopy)||void 0===_c?void 0:_c.color)&&document.documentElement.style.setProperty("--jer-icon-copy-color",null===(_d=null==finalStyles?void 0:finalStyles.iconCopy)||void 0===_d?void 0:_d.color),finalStyles},isStyleObject=overrideObject=>!("styles"in overrideObject),defaultStyleProperties={container:"backgroundColor",property:"color",bracket:"color",itemCount:"color",string:"color",number:"color",boolean:"color",null:"color",input:"color",inputHighlight:"backgroundColor",error:"color",iconCollection:"color",iconEdit:"color",iconDelete:"color",iconAdd:"color",iconCopy:"color",iconOk:"color",iconCancel:"color"},AutogrowTextArea=({className:className,name:name,value:value,setValue:setValue,handleKeyPress:handleKeyPress})=>{const{styles:styles}=useTheme(),dummyValue="\n"===value.slice(-1)?value+".":value;return jsxRuntime.jsxs("div",{style:{display:"grid"},children:[jsxRuntime.jsx("textarea",{style:Object.assign({height:"auto",gridArea:"1 / 1 / 2 / 2",overflowY:"auto"},styles.input),rows:1,className:className,name:name,value:value,onChange:e=>setValue(e.target.value),autoFocus:!0,onFocus:e=>{value.length<40&&e.target.select()},onKeyDown:handleKeyPress}),jsxRuntime.jsx("span",{className:className,style:Object.assign({visibility:"hidden",height:"auto",gridArea:"1 / 1 / 2 / 2",color:"red",opacity:.9,whiteSpace:"pre-wrap",overflow:"clip",border:"1px solid transparent"},styles.input),children:dummyValue})]})},truncate=(string,length=200)=>string.length<length?string:`${string.slice(0,length-2).trim()}...`,StringValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,stringTruncate:stringTruncate})=>{const{styles:styles}=useTheme();return isEditing?jsxRuntime.jsx(AutogrowTextArea,{className:"jer-input-text",name:path.join("."),value:value,setValue:setValue,isEditing:isEditing,handleKeyPress:e=>{"Enter"!==e.key||e.shiftKey?"Escape"===e.key&&handleCancel():handleEdit()}}):jsxRuntime.jsxs("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string",style:styles.string,children:['"',(text=truncate(value,stringTruncate),text.split("\n").map(((line,index,arr)=>jsxRuntime.jsxs("span",{children:[line,index<arr.length-1?jsxRuntime.jsx("br",{}):null]},index)))),'"']});var text},NumberValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{const{styles:styles}=useTheme();return isEditing?jsxRuntime.jsx("input",{className:"jer-input-number",type:"text",name:path.join("."),value:value,onChange:e=>setValue(e.target.value.replace(/[^0-9.-]/g,"")),autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?handleEdit():"Escape"===e.key&&handleCancel()},style:{width:String(value).length/1.5+2+"em"}}):jsxRuntime.jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-number",style:styles.number,children:value})},BooleanValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{const{styles:styles}=useTheme();react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return isEditing?jsxRuntime.jsx("input",{className:"jer-input-boolean",type:"checkbox",name:path.join("."),checked:value,onChange:()=>setValue(!value)}):jsxRuntime.jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-boolean",style:styles.boolean,children:String(value)})},NullValue=({value:value,isEditing:isEditing,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{const{styles:styles}=useTheme();react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return isEditing?jsxRuntime.jsx("div",{className:"jer-input-null",children:"null"}):jsxRuntime.jsx("div",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-null",style:styles.null,children:String(value)})},ObjectValue=({value:value,translate:translate,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsxRuntime.jsx("span",{className:"jer-value-object",children:`{${translate("DEFAULT_NEW_KEY")}: "${value}" }`})},ArrayValue=({value:value,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsxRuntime.jsx("span",{className:"jer-value-array",children:`[${null===value?"":value}]`})},InvalidValue=({value:value})=>{let message="Error!";switch(typeof value){case"string":"**INVALID_FUNCTION**"===value&&(message="Function");break;case"undefined":message="Undefined";break;case"symbol":message="Symbol"}return jsxRuntime.jsx("span",{className:"jer-value-invalid",children:message})},Icon=({name:name,rotate:rotate})=>{var _a,_b,_c,_d,_e,_f,_g;const{styles:styles,icons:icons}=useTheme(),commonProps={size:"1.4em",className:"jer-icon"};switch(name){case"add":return null!==(_a=null==icons?void 0:icons.add)&&void 0!==_a?_a:jsxRuntime.jsx(bi.BiPlusCircle,Object.assign({},commonProps,{style:styles.iconAdd}));case"edit":return null!==(_b=null==icons?void 0:icons.edit)&&void 0!==_b?_b:jsxRuntime.jsx(bi.BiEdit,Object.assign({},commonProps,{style:styles.iconEdit}));case"delete":return null!==(_c=null==icons?void 0:icons.delete)&&void 0!==_c?_c:jsxRuntime.jsx(md.MdDeleteForever,Object.assign({},commonProps,{style:styles.iconDelete,size:"1.5em"}));case"copy":return null!==(_d=null==icons?void 0:icons.copy)&&void 0!==_d?_d:jsxRuntime.jsx(hi.HiOutlineClipboardCopy,Object.assign({},commonProps,{style:styles.iconCopy}));case"ok":return null!==(_e=null==icons?void 0:icons.ok)&&void 0!==_e?_e:jsxRuntime.jsx(fi.FiCheckCircle,Object.assign({},commonProps,{style:Object.assign({fontSize:"90%"},styles.iconOk)}));case"cancel":return null!==(_f=null==icons?void 0:icons.cancel)&&void 0!==_f?_f:jsxRuntime.jsx(ti.TiCancel,Object.assign({},commonProps,{style:Object.assign({fontSize:"130%"},styles.iconCancel)}));case"chevron":return null!==(_g=null==icons?void 0:icons.chevron)&&void 0!==_g?_g:jsxRuntime.jsx(fa.FaChevronDown,{className:"jer-accordion-icon"+(rotate?" jer-rotate-90":""),style:styles.iconCollection});default:return jsxRuntime.jsx(jsxRuntime.Fragment,{})}},EditButtons=({startEdit:startEdit,handleDelete:handleDelete,handleAdd:handleAdd,enableClipboard:enableClipboard,type:type,data:data,path:path,name:name,translate:translate})=>{const{styles:styles}=useTheme(),NEW_KEY_PROMPT=translate("KEY_NEW"),[isAdding,setIsAdding]=react.useState(!1),[newKey,setNewKey]=react.useState(NEW_KEY_PROMPT);react.useEffect((()=>{isAdding||setNewKey(NEW_KEY_PROMPT)}),[isAdding]);return jsxRuntime.jsxs("div",{className:"jer-edit-buttons",style:isAdding?{opacity:1}:void 0,children:[enableClipboard&&jsxRuntime.jsx("div",{onClick:e=>{let value,copyType="value",stringValue="";if(enableClipboard){if(!0===(e.ctrlKey||e.metaKey))value=stringifyPath(path),stringValue=value,copyType="path";else value=data,stringValue=type?JSON.stringify(data,null,2):String(value);navigator.clipboard.writeText(stringValue)}"function"==typeof enableClipboard&&enableClipboard({value:value,stringValue:stringValue,path:path,key:name,type:copyType})},className:"jer-copy-pulse",children:jsxRuntime.jsx(Icon,{name:"copy"})}),startEdit&&jsxRuntime.jsx("div",{onClick:startEdit,children:jsxRuntime.jsx(Icon,{name:"edit"})}),handleDelete&&jsxRuntime.jsx("div",{onClick:handleDelete,children:jsxRuntime.jsx(Icon,{name:"delete"})}),handleAdd&&jsxRuntime.jsx("div",{onClick:()=>{"object"===type?setIsAdding(!0):handleAdd("")},children:jsxRuntime.jsx(Icon,{name:"add"})}),isAdding&&handleAdd&&"object"===type&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("input",{className:"jer-input-new-key",type:"text",name:"new-object-key",value:newKey,onChange:e=>setNewKey(e.target.value),autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key&&handleAdd?(setIsAdding(!1),handleAdd(newKey)):"Escape"===e.key&&setIsAdding(!1)},style:Object.assign({},styles.input)}),jsxRuntime.jsx(InputButtons,{onOk:()=>{newKey&&(setIsAdding(!1),handleAdd(newKey))},onCancel:()=>{setIsAdding(!1)}})]})]})},InputButtons=({onOk:onOk,onCancel:onCancel})=>jsxRuntime.jsxs("div",{className:"jer-confirm-buttons",children:[jsxRuntime.jsx("div",{onClick:onOk,children:jsxRuntime.jsx(Icon,{name:"ok"})}),jsxRuntime.jsx("div",{onClick:onCancel,children:jsxRuntime.jsx(Icon,{name:"cancel"})})]}),stringifyPath=path=>path.reduce(((str,part)=>"number"==typeof part?`${str}[${part}]`:""===str?part:`${str}.${part}`),""),DataTypes=["string","number","boolean","null","object","array"],getCustomNode=(customNodeDefinitions=[],filterProps)=>{const matchingDefinitions=customNodeDefinitions.filter((({condition:condition})=>condition(filterProps)));if(0===matchingDefinitions.length)return{};const{element:element,props:props,hideKey:hideKey=!1}=matchingDefinitions[0];return{CustomNode:element,customNodeProps:props,hideKey:hideKey}},CustomNodeWrapper=({name:name,hideKey:hideKey,children:children,indent:indent})=>{const{styles:styles}=useTheme(),indentStyle=indent?{marginLeft:indent/2+"em"}:{};return jsxRuntime.jsx("div",{className:"jer-component jer-value-component",style:indentStyle,children:jsxRuntime.jsxs("div",{className:"jer-value-main-row",style:{flexWrap:name.length>10?"wrap":"nowrap"},children:[!hideKey&&jsxRuntime.jsxs("label",{htmlFor:name,className:"jer-object-key",style:Object.assign(Object.assign({},styles.property),{minWidth:`${Math.min(String(name).length+1,5)}ch`,flexShrink:name.length>10?1:0}),children:[name,":"," "]}),jsxRuntime.jsx("div",{className:"jer-value-and-buttons",style:{paddingLeft:hideKey?0:void 0},children:children})]})})},ValueNodeWrapper=props=>{const{data:data,parentData:parentData,name:name,path:path,onEdit:onEdit,onDelete:onDelete,enableClipboard:enableClipboard,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictTypeSelection:restrictTypeSelection,showLabel:showLabel,stringTruncate:stringTruncate,indent:indent,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,{styles:styles}=useTheme(),[isEditing,setIsEditing]=react.useState(!1),[isEditingKey,setIsEditingKey]=react.useState(!1),[value,setValue]=react.useState("function"==typeof data?"**INVALID_FUNCTION**":data),[error,setError]=react.useState(null),[dataType,setDataType]=react.useState(getDataType(data));react.useEffect((()=>{setValue("function"==typeof data?"**INVALID_FUNCTION**":data),setDataType(getDataType(data))}),[data,error]);const logError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{let newValue;switch(setIsEditing(!1),dataType){case"object":newValue={[translate("DEFAULT_NEW_KEY")]:value};break;case"array":newValue=null!==value?value:[];break;case"number":const n=Number(value);newValue=isNaN(n)?0:n;break;default:newValue=value}onEdit(newValue,path).then((error=>{error&&logError(error)}))},handleCancel=()=>{setIsEditing(!1),setIsEditingKey(!1),setValue(data),setDataType(getDataType(data))},filterProps={key:name,path:path,level:path.length,value:data,size:null},canEdit=react.useMemo((()=>!restrictEditFilter(filterProps)),[filterProps]),canDelete=react.useMemo((()=>!restrictDeleteFilter(filterProps)),[filterProps]),canEditKey=!("number"==typeof path.slice(-1)[0])&&canEdit&&canDelete,inputProps={value:value,parentData:parentData,setValue:setValue,isEditing:isEditing,setIsEditing:canEdit?()=>setIsEditing(!0):()=>{},handleEdit:handleEdit,handleCancel:handleCancel,path:path,stringTruncate:stringTruncate,translate:translate},{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey}=getCustomNode(customNodeDefinitions,{key:name,path:path,level:path.length,value:data,size:0}),allDataTypes=[...customNodeDefinitions.filter((({showInTypesSelector:showInTypesSelector=!1})=>showInTypesSelector)).map((({name:name})=>name)),...DataTypes],allowedDataTypes=react.useMemo((()=>{if("boolean"==typeof restrictTypeSelection)return restrictTypeSelection?[]:allDataTypes;if(Array.isArray(restrictTypeSelection))return restrictTypeSelection;const result=restrictTypeSelection(filterProps);return"boolean"==typeof result?result?[]:allDataTypes:result}),[filterProps,restrictTypeSelection]);return CustomNode?jsxRuntime.jsx(CustomNodeWrapper,{name:name,hideKey:hideKey,indent:indent,children:jsxRuntime.jsx(CustomNode,Object.assign({customProps:customNodeProps},props))}):jsxRuntime.jsx("div",{className:"jer-component jer-value-component",style:{marginLeft:indent/2+"em"},children:jsxRuntime.jsxs("div",{className:"jer-value-main-row",style:{flexWrap:name.length>10?"wrap":"nowrap"},children:[showLabel&&!isEditingKey&&jsxRuntime.jsxs("label",{htmlFor:path.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},styles.property),{minWidth:`${Math.min(String(name).length+1,5)}ch`,flexShrink:name.length>10?1:0}),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:[name,":"," "]}),showLabel&&isEditingKey&&jsxRuntime.jsx("input",{className:"jer-object-key",type:"text",name:path.join("."),defaultValue:name,autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?(newKey=>{if(setIsEditingKey(!1),!parentData)return;const parentPath=path.slice(0,-1);if(!newKey)return;const newData=Object.fromEntries(Object.entries(parentData).map((([key,val])=>key===name?[newKey,val]:[key,val])));onEdit(newData,parentPath)})(e.target.value):"Escape"===e.key&&handleCancel()},style:{width:String(name).length/1.5+.5+"em"}}),jsxRuntime.jsxs("div",{className:"jer-value-and-buttons",children:[jsxRuntime.jsx("div",{className:"jer-input-component",children:getInputComponent(dataType,inputProps)}),isEditing?jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel}):"invalid"!==dataType&&!error&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>setIsEditing(!0):void 0,handleDelete:canDelete?()=>{onDelete(value,path).then((error=>{error&&logError(error)}))}:void 0,data:data,enableClipboard:enableClipboard,name:name,path:path,translate:translate}),isEditing&&allowedDataTypes.length>0&&jsxRuntime.jsxs("div",{className:"jer-select",children:[jsxRuntime.jsx("select",{name:`${name}-type-select`,className:"jer-type-select",onChange:e=>(type=>{const customNode=customNodeDefinitions.find((customNode=>customNode.name===type));customNode?onEdit(customNode.defaultValue,path):(setValue(convertValue(value,type)),setDataType(type))})(e.target.value),value:dataType,children:allowedDataTypes.map((type=>jsxRuntime.jsx("option",{value:type,children:type},type)))}),jsxRuntime.jsx("span",{className:"focus"})]}),!isEditing&&error&&jsxRuntime.jsx("span",{className:"jer-error-slug",style:styles.error,children:error})]})]})})},getDataType=value=>"string"==typeof value?"string":"number"==typeof value?"number":"boolean"==typeof value?"boolean":null===value?"null":"invalid",getInputComponent=(dataType,inputProps)=>{const value=inputProps.value;switch(dataType){case"string":return jsxRuntime.jsx(StringValue,Object.assign({},inputProps,{value:value}));case"number":return jsxRuntime.jsx(NumberValue,Object.assign({},inputProps,{value:value}));case"boolean":return jsxRuntime.jsx(BooleanValue,Object.assign({},inputProps,{value:value}));case"null":return jsxRuntime.jsx(NullValue,Object.assign({},inputProps));case"object":return jsxRuntime.jsx(ObjectValue,Object.assign({},inputProps,{value:value}));case"array":return jsxRuntime.jsx(ArrayValue,Object.assign({},inputProps));default:return jsxRuntime.jsx(InvalidValue,Object.assign({},inputProps))}},convertValue=(value,type)=>{switch(type){case"string":default:return String(value);case"number":const n=Number(value);return isNaN(n)?0:n;case"boolean":return!!value;case"null":return null;case"object":return value;case"array":return[value]}},isCollection=value=>null!==value&&"object"==typeof value,CollectionNode=_a=>{var{data:data,path:path,name:name,parentData:parentData,showCollectionCount:showCollectionCount}=_a,props=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(null!=s&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]])}return t}(_a,["data","path","name","parentData","showCollectionCount"]);const{styles:styles}=useTheme(),{onEdit:onEdit,onAdd:onAdd,onDelete:onDelete,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,collapseFilter:collapseFilter,enableClipboard:enableClipboard,indent:indent,keySort:keySort,showArrayIndices:showArrayIndices,defaultValue:defaultValue,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,[isEditing,setIsEditing]=react.useState(!1),[isEditingKey,setIsEditingKey]=react.useState(!1),[stringifiedValue,setStringifiedValue]=react.useState(JSON.stringify(data,null,2)),[error,setError]=react.useState(null),collectionSize=Object.keys(data).length,filterProps={key:name,path:path,level:path.length,value:data,size:collectionSize},startCollapsed=collapseFilter(filterProps),[collapsed,setCollapsed]=react.useState(startCollapsed),hasBeenOpened=react.useRef(!startCollapsed),[isAnimating,setIsAnimating]=react.useState(!1);react.useEffect((()=>{setStringifiedValue(JSON.stringify(data,null,2))}),[data]),react.useEffect((()=>{setCollapsed(collapseFilter(filterProps))}),[collapseFilter]);const collectionType=Array.isArray(data)?"array":"object",brackets="array"===collectionType?{open:"[",close:"]"}:{open:"{",close:"}"},transitionTime=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),showError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{try{const value=JSON.parse(stringifiedValue);setIsEditing(!1),setError(null),onEdit(value,path).then((error=>{error&&showError(error)}))}catch(_a){return setError(translate("ERROR_INVALID_JSON")),setTimeout((()=>setError(null)),2500),void console.log("Invalid JSON")}},handleDelete=path.length>0?()=>{onDelete(data,path).then((result=>{result&&showError(result)}))}:void 0,handleCancel=()=>{setIsEditing(!1),setIsEditingKey(!1),setError(null),setStringifiedValue(JSON.stringify(data,null,2))},canEdit=react.useMemo((()=>!restrictEditFilter(filterProps)),[filterProps]),canDelete=react.useMemo((()=>!restrictDeleteFilter(filterProps)),[filterProps]),canAdd=react.useMemo((()=>!restrictAddFilter(filterProps)),[filterProps]),canEditKey=null!==parentData&&canEdit&&canAdd&&canDelete,isArray="number"==typeof path.slice(-1)[0],showLabel=showArrayIndices||!isArray,showCount="when-closed"===showCollectionCount?collapsed:showCollectionCount,keyValueArray=Object.entries(data).map((([key,value])=>["array"===collectionType?Number(key):key,value]));keySort&&"object"===collectionType&&keyValueArray.sort("function"==typeof keySort?(a,b)=>keySort(a[0],b[0]):void 0);const numOfLines=JSON.stringify(data,null,2).split("\n").length,{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey}=getCustomNode(customNodeDefinitions,{key:name,path:path,level:path.length,value:data,size:Object.keys(data).length});return jsxRuntime.jsx("div",{className:"jer-component jer-collection-component",style:{marginLeft:(0===path.length?0:indent/2)+"em"},children:CustomNode?jsxRuntime.jsx(CustomNodeWrapper,{name:name,hideKey:hideKey,children:jsxRuntime.jsx(CustomNode,Object.assign({data:data,path:path,name:name,parentData:parentData,customProps:customNodeProps},props))}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"jer-collection-header-row",children:[jsxRuntime.jsx("div",{onClick:()=>{isEditing||(setIsAnimating(!0),hasBeenOpened.current=!0,setCollapsed(!collapsed),setTimeout((()=>setIsAnimating(!1)),500))},children:jsxRuntime.jsx(Icon,{name:"chevron",rotate:collapsed})}),jsxRuntime.jsxs("div",{className:"jer-collection-name",children:[!isEditingKey&&jsxRuntime.jsx("span",{style:styles.property,onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:showLabel&&""!==name&&void 0!==name?`${name}:`:null}),isEditingKey&&jsxRuntime.jsx("input",{className:"jer-collection-name",type:"text",name:path.join("."),defaultValue:name,autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?(newKey=>{if(setIsEditingKey(!1),!parentData)return;const parentPath=path.slice(0,-1);if(!newKey)return;const newData=Object.fromEntries(Object.entries(parentData).map((([key,val])=>key===name?[newKey,val]:[key,val])));onEdit(newData,parentPath)})(e.target.value):"Escape"===e.key&&handleCancel()},style:{width:String(name).length/1.5+.5+"em"}}),!isEditing&&jsxRuntime.jsx("span",{className:"jer-brackets",style:styles.bracket,children:brackets.open})]}),!isEditing&&showCollectionCount&&jsxRuntime.jsx("div",{className:"jer-collection-item-count"+(showCount?" jer-visible":" jer-hidden"),style:styles.itemCount,children:1===collectionSize?translate("ITEM_SINGLE",1):translate("ITEMS_MULTIPLE",collectionSize)}),jsxRuntime.jsx("div",{className:"jer-brackets"+(collapsed?" jer-visible":" jer-hidden"),style:styles.bracket,children:brackets.close}),!isEditing&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>{setIsEditing(!0),setCollapsed(!1)}:void 0,handleAdd:canAdd?key=>{if(setCollapsed(!1),"array"===collectionType)onAdd(defaultValue,[...path,data.length]).then((error=>{error&&showError(error)}));else{if(key in data)return void showError(translate("ERROR_KEY_EXISTS"));onAdd(defaultValue,[...path,key]).then((error=>{error&&showError(error)}))}}:void 0,handleDelete:canDelete?handleDelete:void 0,enableClipboard:enableClipboard,type:collectionType,data:data,name:name,path:path,translate:translate})]}),jsxRuntime.jsxs("div",{className:"jer-collection-inner",style:{maxHeight:collapsed?0:isEditing?void 0:3*numOfLines+"em",overflowY:collapsed||isAnimating?"hidden":"visible",transition:`max-height ${transitionTime}`},children:[isEditing?jsxRuntime.jsx("div",{className:"jer-collection-text-edit",children:jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx(AutogrowTextArea,{className:"jer-collection-text-area",name:path.join("."),value:stringifiedValue,setValue:setStringifiedValue,isEditing:isEditing,handleKeyPress:e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?handleEdit():"Escape"===e.key&&handleCancel()}}),jsxRuntime.jsx("div",{className:"jer-collection-input-button-row",children:jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,isCollection:!0})})]})}):jsxRuntime.jsx(jsxRuntime.Fragment,{children:hasBeenOpened.current?keyValueArray.map((([key,value])=>jsxRuntime.jsx("div",{className:"jer-collection-element",children:isCollection(value)?jsxRuntime.jsx(CollectionNode,Object.assign({data:value,parentData:data,path:[...path,key],name:key,showCollectionCount:showCollectionCount},props),key):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:value,parentData:data,path:[...path,key],name:key},props,{showLabel:"object"===collectionType||showArrayIndices}),key)},key))):null}),jsxRuntime.jsx("div",{className:isEditing?"jer-collection-error-row":"jer-collection-error-row-edit",children:error&&jsxRuntime.jsx("span",{className:"jer-error-slug",style:styles.error,children:error})}),jsxRuntime.jsx("div",{className:"jer-brackets",style:styles.bracket,children:brackets.close})]})]})})},localisedStrings={ITEM_SINGLE:"{{count}} item",ITEMS_MULTIPLE:"{{count}} items",KEY_NEW:"Enter new key",ERROR_KEY_EXISTS:"Key already exists",ERROR_INVALID_JSON:"Invalid JSON",ERROR_UPDATE:"Update unsuccessful",ERROR_DELETE:"Delete unsuccessful",ERROR_ADD:"Adding node unsuccessful",DEFAULT_STRING:"New data!",DEFAULT_NEW_KEY:"key"},getTranslateFunction=translations=>(key,count)=>((translations,key,count)=>{const string=key in translations?translations[key]:localisedStrings[key];return void 0===count?string:null==string?void 0:string.replace("{{count}}",String(count))})(translations,key,count),Editor=({data:data,rootName:rootName="root",onUpdate:onUpdate,onEdit:srcEdit=onUpdate,onDelete:srcDelete=onUpdate,onAdd:srcAdd=onUpdate,enableClipboard:enableClipboard=!0,theme:theme="default",icons:icons,indent:indent=4,collapse:collapse=!1,showCollectionCount:showCollectionCount=!0,restrictEdit:restrictEdit=!1,restrictDelete:restrictDelete=!1,restrictAdd:restrictAdd=!1,restrictTypeSelection:restrictTypeSelection=!1,keySort:keySort=!1,showArrayIndices:showArrayIndices=!0,defaultValue:defaultValue=null,minWidth:minWidth=250,maxWidth:maxWidth="min(600px, 90vw)",stringTruncate:stringTruncate=250,translations:translations={},className:className,customNodeDefinitions:customNodeDefinitions=[]})=>{const{styles:styles,setTheme:setTheme,setIcons:setIcons}=useTheme(),collapseFilter=react.useCallback(getFilterFunction(collapse),[collapse]),translate=react.useCallback(getTranslateFunction(translations),[translations]);react.useEffect((()=>{theme&&setTheme(theme),icons&&setIcons(icons)}),[theme,icons]);const otherProps={name:rootName,onEdit:(value,path)=>__awaiter(void 0,void 0,void 0,(function*(){const{currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue}=updateDataObject(data,path,value,"update");if(srcEdit){const result=yield srcEdit({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});return!1===result?translate("ERROR_UPDATE"):result}})),onDelete:(value,path)=>__awaiter(void 0,void 0,void 0,(function*(){const{currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue}=updateDataObject(data,path,value,"delete");if(srcDelete){const result=yield srcDelete({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});return!1===result?translate("ERROR_DELETE"):result}})),onAdd:(value,path)=>__awaiter(void 0,void 0,void 0,(function*(){const{currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue}=updateDataObject(data,path,value,"add");if(srcAdd){const result=yield srcAdd({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});return!1===result?translate("ERROR_ADD"):result}})),showCollectionCount:showCollectionCount,collapseFilter:collapseFilter,restrictEditFilter:getFilterFunction(restrictEdit),restrictDeleteFilter:getFilterFunction(restrictDelete),restrictAddFilter:getFilterFunction(restrictAdd),restrictTypeSelection:restrictTypeSelection,enableClipboard:enableClipboard,keySort:keySort,showArrayIndices:showArrayIndices,indent:indent,defaultValue:defaultValue,stringTruncate:stringTruncate,translate:translate,customNodeDefinitions:customNodeDefinitions,parentData:null};return styles?jsxRuntime.jsx("div",{className:"jer-editor-container "+className,style:Object.assign(Object.assign({},styles.container),{minWidth:minWidth,maxWidth:maxWidth}),children:isCollection(data)?jsxRuntime.jsx(CollectionNode,Object.assign({data:data,path:[]},otherProps)):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:data,path:[],showLabel:!0},otherProps))}):null},updateDataObject=(data,path,newValue,action)=>{if(0===path.length)return{currentData:data,newData:newValue,currentValue:data,newValue:newValue};const currentValue="add"!==action?extract(data,path):void 0;return{currentData:data,newData:assign(clone(data),path,newValue,{remove:"delete"===action}),currentValue:currentValue,newValue:"update"===action?newValue:void 0}},getFilterFunction=propValue=>"boolean"==typeof propValue?()=>propValue:"number"==typeof propValue?({level:level})=>level>=propValue:propValue;exports.JsonEditor=props=>jsxRuntime.jsx(ThemeProvider,{children:jsxRuntime.jsx(Editor,Object.assign({},props))}),exports.themes=themes;