json-edit-react 1.1.0 → 1.1.1

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 e=require("react/jsx-runtime"),n=require("react"),t=require("object-property-assigner"),r=require("object-property-extractor"),o=require("just-clone"),i=require("react-icons/hi"),a=require("react-icons/bi"),l=require("react-icons/md"),s=require("react-icons/fi"),c=require("react-icons/ti"),d=require("react-icons/fa");function u(e,n,t,r){return new(t||(t=Promise))((function(o,i){function a(e){try{s(r.next(e))}catch(e){i(e)}}function l(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(a,l)}s((r=r.apply(e,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;var p=[],m=[];!function(e,n){if(e&&"undefined"!=typeof document){var t,r=!0===n.prepend?"prepend":"append",o=!0===n.singleTag,i="string"==typeof n.container?document.querySelector(n.container):document.getElementsByTagName("head")[0];if(o){var a=p.indexOf(i);-1===a&&(a=p.push(i)-1,m[a]={}),t=m[a]&&m[a][r]?m[a][r]:m[a][r]=l()}else t=l();65279===e.charCodeAt(0)&&(e=e.substring(1)),t.styleSheet?t.styleSheet.cssText+=e:t.appendChild(document.createTextNode(e))}function l(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),n.attributes)for(var t=Object.keys(n.attributes),o=0;o<t.length;o++)e.setAttribute(t[o],n.attributes[t[o]]);var a="prepend"===r?"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 h={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"}}},y={container:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},j=h.default,b={styles:y,setTheme:e=>{},icons:{},setIcons:()=>{}},g=n.createContext(b),f=({children:t})=>{const[r,o]=n.useState(y),[i,a]=n.useState({});return e.jsx(g.Provider,{value:{styles:r,setTheme:e=>o(x(e)),icons:i,setIcons:a},children:t})},v=()=>n.useContext(g),x=e=>{if("string"==typeof e)return E(h[e]);if(Array.isArray(e)){const[n,t]=e;return E(h[n],k(t)?{styles:t}:t)}return E(j,k(e)?{styles:e}:e)},E=(e,n={styles:y})=>{var t,r,o,i;const[a,l,s]=[j,e,n].map((e=>{const{fragments:n,styles:t}=e,r={};return Object.entries(t).forEach((([e,t])=>{const o=(Array.isArray(t)?t:[t]).reduce(((t,r)=>{var o;if("string"==typeof r){const i=null!==(o=null==n?void 0:n[r])&&void 0!==o?o:r;return"string"==typeof i?Object.assign(Object.assign({},t),{[C[e]]:i}):Object.assign(Object.assign({},t),i)}return Object.assign(Object.assign({},t),r)}),{});r[e]=o})),r})),c={};return Object.keys(j.styles).forEach((e=>{c[e]=Object.assign(Object.assign(Object.assign({},a[e]),l[e]),s[e])})),(null===(t=null==c?void 0:c.inputHighlight)||void 0===t?void 0:t.backgroundColor)&&document.documentElement.style.setProperty("--jer-highlight-color",null===(r=null==c?void 0:c.inputHighlight)||void 0===r?void 0:r.backgroundColor),(null===(o=null==c?void 0:c.iconCopy)||void 0===o?void 0:o.color)&&document.documentElement.style.setProperty("--jer-icon-copy-color",null===(i=null==c?void 0:c.iconCopy)||void 0===i?void 0:i.color),c},k=e=>!("styles"in e),C={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"},w=({className:n,name:t,value:r,setValue:o,handleKeyPress:i})=>{const{styles:a}=v(),l="\n"===r.slice(-1)?r+".":r;return e.jsxs("div",{style:{display:"grid"},children:[e.jsx("textarea",{style:Object.assign({height:"auto",gridArea:"1 / 1 / 2 / 2",overflowY:"auto"},a.input),rows:1,className:n,name:t,value:r,onChange:e=>o(e.target.value),autoFocus:!0,onFocus:e=>{r.length<40&&e.target.select()},onKeyDown:i}),e.jsx("span",{className:n,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"},a.input),children:l})]})},D="**INVALID_FUNCTION**",N=(e,n=200)=>e.length<n?e:`${e.slice(0,n-2).trim()}...`,O=({value:n,setValue:t,isEditing:r,path:o,setIsEditing:i,handleEdit:a,handleCancel:l,stringTruncate:s})=>{const{styles:c}=v();return r?e.jsx(w,{className:"jer-input-text",name:o.join("."),value:n,setValue:t,isEditing:r,handleKeyPress:e=>{"Enter"!==e.key||e.shiftKey?"Escape"===e.key&&l():a()}}):e.jsxs("div",{onDoubleClick:()=>i(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&i(!0)},className:"jer-value-string",style:c.string,children:['"',(d=N(n,s),d.split("\n").map(((n,t,r)=>e.jsxs("span",{children:[n,t<r.length-1?e.jsx("br",{}):null]},t)))),'"']});var d},S=({value:n,setValue:t,isEditing:r,path:o,setIsEditing:i,handleEdit:a,handleCancel:l})=>{const{styles:s}=v();return r?e.jsx("input",{className:"jer-input-number",type:"text",name:o.join("."),value:n,onChange:e=>t(e.target.value.replace(/[^0-9.-]/g,"")),autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?a():"Escape"===e.key&&l()},style:{width:String(n).length/1.5+2+"em"}}):e.jsx("span",{onDoubleClick:()=>i(!0),className:"jer-value-number",style:s.number,children:n})},A=({value:t,setValue:r,isEditing:o,path:i,setIsEditing:a,handleEdit:l,handleCancel:s})=>{const{styles:c}=v();n.useEffect((()=>(o&&document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d))),[o]);const d=e=>{"Enter"===e.key?l():"Escape"===e.key&&s()};return o?e.jsx("input",{className:"jer-input-boolean",type:"checkbox",name:i.join("."),checked:t,onChange:()=>r(!t)}):e.jsx("span",{onDoubleClick:()=>a(!0),className:"jer-value-boolean",style:c.boolean,children:String(t)})},F=({value:t,isEditing:r,setIsEditing:o,handleEdit:i,handleCancel:a})=>{const{styles:l}=v();n.useEffect((()=>(r&&document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s))),[r]);const s=e=>{"Enter"===e.key?i():"Escape"===e.key&&a()};return r?e.jsx("div",{className:"jer-input-null",children:"null"}):e.jsx("div",{onDoubleClick:()=>o(!0),className:"jer-value-null",style:l.null,children:String(t)})},T=({value:t,translate:r,isEditing:o,handleEdit:i,handleCancel:a})=>{n.useEffect((()=>(o&&document.addEventListener("keydown",l),()=>document.removeEventListener("keydown",l))),[]);const l=e=>{"Enter"===e.key?i():"Escape"===e.key&&a()};return e.jsx("span",{className:"jer-value-object",children:`{${r("DEFAULT_NEW_KEY")}: "${t}" }`})},V=({value:t,isEditing:r,handleEdit:o,handleCancel:i})=>{n.useEffect((()=>(r&&document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a))),[]);const a=e=>{"Enter"===e.key?o():"Escape"===e.key&&i()};return e.jsx("span",{className:"jer-value-array",children:`[${null===t?"":t}]`})},I=({value:n})=>{let t="Error!";switch(typeof n){case"string":n===D&&(t="Function");break;case"undefined":t="Undefined";break;case"symbol":t="Symbol"}return e.jsx("span",{className:"jer-value-invalid",children:t})},L=({name:n,rotate:t})=>{var r,o,u,p,m,h,y;const{styles:j,icons:b}=v(),g={size:"1.4em",className:"jer-icon"};switch(n){case"add":return null!==(r=null==b?void 0:b.add)&&void 0!==r?r:e.jsx(a.BiPlusCircle,Object.assign({},g,{style:j.iconAdd}));case"edit":return null!==(o=null==b?void 0:b.edit)&&void 0!==o?o:e.jsx(a.BiEdit,Object.assign({},g,{style:j.iconEdit}));case"delete":return null!==(u=null==b?void 0:b.delete)&&void 0!==u?u:e.jsx(l.MdDeleteForever,Object.assign({},g,{style:j.iconDelete,size:"1.5em"}));case"copy":return null!==(p=null==b?void 0:b.copy)&&void 0!==p?p:e.jsx(i.HiOutlineClipboardCopy,Object.assign({},g,{style:j.iconCopy}));case"ok":return null!==(m=null==b?void 0:b.ok)&&void 0!==m?m:e.jsx(s.FiCheckCircle,Object.assign({},g,{style:Object.assign({fontSize:"90%"},j.iconOk)}));case"cancel":return null!==(h=null==b?void 0:b.cancel)&&void 0!==h?h:e.jsx(c.TiCancel,Object.assign({},g,{style:Object.assign({fontSize:"130%"},j.iconCancel)}));case"chevron":return null!==(y=null==b?void 0:b.chevron)&&void 0!==y?y:e.jsx(d.FaChevronDown,{className:"jer-accordion-icon"+(t?" jer-rotate-90":""),style:j.iconCollection});default:return e.jsx(e.Fragment,{})}},R=({startEdit:t,handleDelete:r,handleAdd:o,enableClipboard:i,type:a,data:l,path:s,name:c,translate:d})=>{const{styles:u}=v(),p=d("KEY_NEW"),[m,h]=n.useState(!1),[y,j]=n.useState(p);n.useEffect((()=>{m||j(p)}),[m]);return e.jsxs("div",{className:"jer-edit-buttons",style:m?{opacity:1}:void 0,children:[i&&e.jsx("div",{onClick:e=>{let n,t="value",r="";if(i){if(!0===(e.ctrlKey||e.metaKey))n=_(s),r=n,t="path";else n=l,r=a?JSON.stringify(l,null,2):String(n);navigator.clipboard.writeText(r)}"function"==typeof i&&i({value:n,stringValue:r,path:s,key:c,type:t})},className:"jer-copy-pulse",children:e.jsx(L,{name:"copy"})}),t&&e.jsx("div",{onClick:t,children:e.jsx(L,{name:"edit"})}),r&&e.jsx("div",{onClick:r,children:e.jsx(L,{name:"delete"})}),o&&e.jsx("div",{onClick:()=>{"object"===a?h(!0):o("")},children:e.jsx(L,{name:"add"})}),m&&o&&"object"===a&&e.jsxs(e.Fragment,{children:[e.jsx("input",{className:"jer-input-new-key",type:"text",name:"new-object-key",value:y,onChange:e=>j(e.target.value),autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key&&o?(h(!1),o(y)):"Escape"===e.key&&h(!1)},style:Object.assign({},u.input)}),e.jsx(K,{onOk:()=>{y&&(h(!1),o(y))},onCancel:()=>{h(!1)}})]})]})},K=({onOk:n,onCancel:t})=>e.jsxs("div",{className:"jer-confirm-buttons",children:[e.jsx("div",{onClick:n,children:e.jsx(L,{name:"ok"})}),e.jsx("div",{onClick:t,children:e.jsx(L,{name:"cancel"})})]}),_=e=>e.reduce(((e,n)=>"number"==typeof n?`${e}[${n}]`:""===e?n:`${e}.${n}`),""),W=2500,z=["string","number","boolean","null","object","array"],G=(e=[],n)=>{const t=e.filter((({condition:e})=>e(n)));if(0===t.length)return{};const{element:r,props:o,hideKey:i=!1}=t[0];return{CustomNode:r,customNodeProps:o,hideKey:i}},P=({name:n,hideKey:t,children:r,indent:o})=>{const{styles:i}=v(),a=o?{marginLeft:o/2+"em"}:{};return e.jsx("div",{className:"jer-component jer-value-component",style:a,children:e.jsxs("div",{className:"jer-value-main-row",style:{flexWrap:n.length>10?"wrap":"nowrap"},children:[!t&&e.jsxs("label",{htmlFor:n,className:"jer-object-key",style:Object.assign(Object.assign({},i.property),{minWidth:`${Math.min(String(n).length+1,5)}ch`,flexShrink:n.length>10?1:0}),children:[n,":"," "]}),e.jsx("div",{className:"jer-value-and-buttons",style:{paddingLeft:t?0:void 0},children:r})]})})},M=t=>{const{data:r,parentData:o,name:i,path:a,onEdit:l,onDelete:s,enableClipboard:c,restrictEditFilter:d,restrictDeleteFilter:u,restrictTypeSelection:p,showLabel:m,stringTruncate:h,indent:y,translate:j,customNodeDefinitions:b}=t,{styles:g}=v(),[f,x]=n.useState(!1),[E,k]=n.useState(!1),[C,w]=n.useState("function"==typeof r?D:r),[N,O]=n.useState(null),[S,A]=n.useState(B(r));n.useEffect((()=>{w("function"==typeof r?D:r),A(B(r))}),[r,N]);const F=e=>{O(e),setTimeout((()=>O(null)),W),console.log("Error",e)},T=()=>{let e;switch(x(!1),S){case"object":e={[j("DEFAULT_NEW_KEY")]:C};break;case"array":e=null!==C?C:[];break;case"number":const n=Number(C);e=isNaN(n)?0:n;break;default:e=C}l(e,a).then((e=>{e&&F(e)}))},V=()=>{x(!1),k(!1),w(r),A(B(r))},I={key:i,path:a,level:a.length,value:r,size:null},L=n.useMemo((()=>!d(I)),[I]),_=n.useMemo((()=>!u(I)),[I]),M=!("number"==typeof a.slice(-1)[0])&&L&&_,U={value:C,parentData:o,setValue:w,isEditing:f,setIsEditing:L?()=>x(!0):()=>{},handleEdit:T,handleCancel:V,path:a,stringTruncate:h,translate:j},{CustomNode:Y,customNodeProps:J,hideKey:H}=G(b,{key:i,path:a,level:a.length,value:r,size:0}),X=[...b.filter((({showInTypesSelector:e=!1})=>e)).map((({name:e})=>e)),...z],Q=n.useMemo((()=>{if("boolean"==typeof p)return p?[]:X;if(Array.isArray(p))return p;const e=p(I);return"boolean"==typeof e?e?[]:X:e}),[I,p]);return Y?e.jsx(P,{name:i,hideKey:H,indent:y,children:e.jsx(Y,Object.assign({customProps:J},t))}):e.jsx("div",{className:"jer-component jer-value-component",style:{marginLeft:y/2+"em"},children:e.jsxs("div",{className:"jer-value-main-row",style:{flexWrap:i.length>10?"wrap":"nowrap"},children:[m&&!E&&e.jsxs("label",{htmlFor:a.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},g.property),{minWidth:`${Math.min(String(i).length+1,5)}ch`,flexShrink:i.length>10?1:0}),onDoubleClick:()=>M&&k(!0),children:[i,":"," "]}),m&&E&&e.jsx("input",{className:"jer-object-key",type:"text",name:a.join("."),defaultValue:i,autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?(e=>{if(k(!1),!o)return;const n=a.slice(0,-1);if(!e)return;const t=Object.fromEntries(Object.entries(o).map((([n,t])=>n===i?[e,t]:[n,t])));l(t,n)})(e.target.value):"Escape"===e.key&&V()},style:{width:String(i).length/1.5+.5+"em"}}),e.jsxs("div",{className:"jer-value-and-buttons",children:[e.jsx("div",{className:"jer-input-component",children:$(S,U)}),f?e.jsx(K,{onOk:T,onCancel:V}):"invalid"!==S&&!N&&e.jsx(R,{startEdit:L?()=>x(!0):void 0,handleDelete:_?()=>{s(C,a).then((e=>{e&&F(e)}))}:void 0,data:r,enableClipboard:c,name:i,path:a,translate:j}),f&&Q.length>0&&e.jsxs("div",{className:"jer-select",children:[e.jsx("select",{name:`${i}-type-select`,className:"jer-type-select",onChange:e=>(e=>{const n=b.find((n=>n.name===e));n?l(n.defaultValue,a):(w(q(C,e)),A(e))})(e.target.value),value:S,children:Q.map((n=>e.jsx("option",{value:n,children:n},n)))}),e.jsx("span",{className:"focus"})]}),!f&&N&&e.jsx("span",{className:"jer-error-slug",style:g.error,children:N})]})]})})},B=e=>"string"==typeof e?"string":"number"==typeof e?"number":"boolean"==typeof e?"boolean":null===e?"null":"invalid",$=(n,t)=>{const r=t.value;switch(n){case"string":return e.jsx(O,Object.assign({},t,{value:r}));case"number":return e.jsx(S,Object.assign({},t,{value:r}));case"boolean":return e.jsx(A,Object.assign({},t,{value:r}));case"null":return e.jsx(F,Object.assign({},t));case"object":return e.jsx(T,Object.assign({},t,{value:r}));case"array":return e.jsx(V,Object.assign({},t));default:return e.jsx(I,Object.assign({},t))}},q=(e,n)=>{switch(n){case"string":default:return String(e);case"number":const n=Number(e);return isNaN(n)?0:n;case"boolean":return!!e;case"null":return null;case"object":return e;case"array":return[e]}},U=e=>null!==e&&"object"==typeof e,Y=t=>{var{data:r,path:o,name:i,parentData:a,showCollectionCount:l}=t,s=function(e,n){var t={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&n.indexOf(r)<0&&(t[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)n.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(t[r[o]]=e[r[o]])}return t}(t,["data","path","name","parentData","showCollectionCount"]);const{styles:c}=v(),{onEdit:d,onAdd:u,onDelete:p,restrictEditFilter:m,restrictDeleteFilter:h,restrictAddFilter:y,collapseFilter:j,enableClipboard:b,indent:g,keySort:f,showArrayIndices:x,defaultValue:E,translate:k,customNodeDefinitions:C}=s,[D,N]=n.useState(!1),[O,S]=n.useState(!1),[A,F]=n.useState(JSON.stringify(r,null,2)),[T,V]=n.useState(null),I=Object.keys(r).length,_={key:i,path:o,level:o.length,value:r,size:I},z=j(_),[B,$]=n.useState(z),q=n.useRef(!z),[J,H]=n.useState(!1);n.useEffect((()=>{F(JSON.stringify(r,null,2))}),[r]),n.useEffect((()=>{$(j(_))}),[j]);const X=Array.isArray(r)?"array":"object",Q="array"===X?{open:"[",close:"]"}:{open:"{",close:"}"},Z=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),ee=e=>{V(e),setTimeout((()=>V(null)),W),console.log("Error",e)},ne=()=>{try{const e=JSON.parse(A);N(!1),V(null),d(e,o).then((e=>{e&&ee(e)}))}catch(e){return V(k("ERROR_INVALID_JSON")),setTimeout((()=>V(null)),W),void console.log("Invalid JSON")}},te=o.length>0?()=>{p(r,o).then((e=>{e&&ee(e)}))}:void 0,re=()=>{N(!1),S(!1),V(null),F(JSON.stringify(r,null,2))},oe=n.useMemo((()=>!m(_)),[_]),ie=n.useMemo((()=>!h(_)),[_]),ae=n.useMemo((()=>!y(_)),[_]),le=null!==a&&oe&&ae&&ie,se="number"==typeof o.slice(-1)[0],ce=x||!se,de="when-closed"===l?B:l,ue=Object.entries(r).map((([e,n])=>["array"===X?Number(e):e,n]));f&&"object"===X&&ue.sort("function"==typeof f?(e,n)=>f(e[0],n[0]):void 0);const pe=JSON.stringify(r,null,2).split("\n").length,{CustomNode:me,customNodeProps:he,hideKey:ye}=G(C,{key:i,path:o,level:o.length,value:r,size:Object.keys(r).length});return e.jsx("div",{className:"jer-component jer-collection-component",style:{marginLeft:(0===o.length?0:g/2)+"em"},children:me?e.jsx(P,{name:i,hideKey:ye,children:e.jsx(me,Object.assign({data:r,path:o,name:i,parentData:a,customProps:he},s))}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"jer-collection-header-row",children:[e.jsx("div",{onClick:()=>{D||(H(!0),q.current=!0,$(!B),setTimeout((()=>H(!1)),500))},children:e.jsx(L,{name:"chevron",rotate:B})}),e.jsxs("div",{className:"jer-collection-name",children:[!O&&e.jsx("span",{style:c.property,onDoubleClick:()=>le&&S(!0),children:ce&&""!==i&&void 0!==i?`${i}:`:null}),O&&e.jsx("input",{className:"jer-collection-name",type:"text",name:o.join("."),defaultValue:i,autoFocus:!0,onFocus:e=>e.target.select(),onKeyDown:e=>{"Enter"===e.key?(e=>{if(S(!1),!a)return;const n=o.slice(0,-1);if(!e)return;const t=Object.fromEntries(Object.entries(a).map((([n,t])=>n===i?[e,t]:[n,t])));d(t,n)})(e.target.value):"Escape"===e.key&&re()},style:{width:String(i).length/1.5+.5+"em"}}),!D&&e.jsx("span",{className:"jer-brackets",style:c.bracket,children:Q.open})]}),!D&&l&&e.jsx("div",{className:"jer-collection-item-count"+(de?" jer-visible":" jer-hidden"),style:c.itemCount,children:1===I?k("ITEM_SINGLE",1):k("ITEMS_MULTIPLE",I)}),e.jsx("div",{className:"jer-brackets"+(B?" jer-visible":" jer-hidden"),style:c.bracket,children:Q.close}),!D&&e.jsx(R,{startEdit:oe?()=>{N(!0),$(!1)}:void 0,handleAdd:ae?e=>{if($(!1),"array"===X)u(E,[...o,r.length]).then((e=>{e&&ee(e)}));else{if(e in r)return void ee(k("ERROR_KEY_EXISTS"));u(E,[...o,e]).then((e=>{e&&ee(e)}))}}:void 0,handleDelete:ie?te:void 0,enableClipboard:b,type:X,data:r,name:i,path:o,translate:k})]}),e.jsxs("div",{className:"jer-collection-inner",style:{maxHeight:B?0:D?void 0:3*pe+"em",overflowY:B||J?"hidden":"visible",transition:`max-height ${Z}`},children:[D?e.jsx("div",{className:"jer-collection-text-edit",children:e.jsxs("div",{children:[e.jsx(w,{className:"jer-collection-text-area",name:o.join("."),value:A,setValue:F,isEditing:D,handleKeyPress:e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?ne():"Escape"===e.key&&re()}}),e.jsx("div",{className:"jer-collection-input-button-row",children:e.jsx(K,{onOk:ne,onCancel:re,isCollection:!0})})]})}):e.jsx(e.Fragment,{children:q.current?ue.map((([n,t])=>e.jsx("div",{className:"jer-collection-element",children:U(t)?e.jsx(Y,Object.assign({data:t,parentData:r,path:[...o,n],name:n,showCollectionCount:l},s),n):e.jsx(M,Object.assign({data:t,parentData:r,path:[...o,n],name:n},s,{showLabel:"object"===X||x}),n)},n))):null}),e.jsx("div",{className:D?"jer-collection-error-row":"jer-collection-error-row-edit",children:T&&e.jsx("span",{className:"jer-error-slug",style:c.error,children:T})}),e.jsx("div",{className:"jer-brackets",style:c.bracket,children:Q.close})]})]})})},J={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"},H=e=>(n,t)=>((e,n,t)=>{const r=n in e?e[n]:J[n];return void 0===t?r:null==r?void 0:r.replace("{{count}}",String(t))})(e,n,t),X=({data:t,rootName:r="root",onUpdate:o,onEdit:i=o,onDelete:a=o,onAdd:l=o,enableClipboard:s=!0,theme:c="default",icons:d,indent:p=4,collapse:m=!1,showCollectionCount:h=!0,restrictEdit:y=!1,restrictDelete:j=!1,restrictAdd:b=!1,restrictTypeSelection:g=!1,keySort:f=!1,showArrayIndices:x=!0,defaultValue:E=null,minWidth:k=250,maxWidth:C="min(600px, 90vw)",stringTruncate:w=250,translations:D={},className:N,customNodeDefinitions:O=[]})=>{const{styles:S,setTheme:A,setIcons:F}=v(),T=n.useCallback(Z(m),[m]),V=n.useCallback(H(D),[D]);n.useEffect((()=>{c&&A(c),d&&F(d)}),[c,d]);const I={name:r,onEdit:(e,n)=>u(void 0,void 0,void 0,(function*(){const{currentData:r,newData:o,currentValue:a,newValue:l}=Q(t,n,e,"update");if(i){const e=yield i({currentData:r,newData:o,currentValue:a,newValue:l,name:n.slice(-1)[0],path:n});return!1===e?V("ERROR_UPDATE"):e}})),onDelete:(e,n)=>u(void 0,void 0,void 0,(function*(){const{currentData:r,newData:o,currentValue:i,newValue:l}=Q(t,n,e,"delete");if(a){const e=yield a({currentData:r,newData:o,currentValue:i,newValue:l,name:n.slice(-1)[0],path:n});return!1===e?V("ERROR_DELETE"):e}})),onAdd:(e,n)=>u(void 0,void 0,void 0,(function*(){const{currentData:r,newData:o,currentValue:i,newValue:a}=Q(t,n,e,"add");if(l){const e=yield l({currentData:r,newData:o,currentValue:i,newValue:a,name:n.slice(-1)[0],path:n});return!1===e?V("ERROR_ADD"):e}})),showCollectionCount:h,collapseFilter:T,restrictEditFilter:Z(y),restrictDeleteFilter:Z(j),restrictAddFilter:Z(b),restrictTypeSelection:g,enableClipboard:s,keySort:f,showArrayIndices:x,indent:p,defaultValue:E,stringTruncate:w,translate:V,customNodeDefinitions:O,parentData:null};return S?e.jsx("div",{className:"jer-editor-container "+N,style:Object.assign(Object.assign({},S.container),{minWidth:k,maxWidth:C}),children:U(t)?e.jsx(Y,Object.assign({data:t,path:[]},I)):e.jsx(M,Object.assign({data:t,path:[],showLabel:!0},I))}):null},Q=(e,n,i,a)=>{if(0===n.length)return{currentData:e,newData:i,currentValue:e,newValue:i};const l="add"!==a?r(e,n):void 0;return{currentData:e,newData:t(o(e),n,i,{remove:"delete"===a}),currentValue:l,newValue:"update"===a?i:void 0}},Z=e=>"boolean"==typeof e?()=>e:"number"==typeof e?({level:n})=>n>=e:e;exports.JsonEditor=n=>e.jsx(f,{children:e.jsx(X,Object.assign({},n))}),exports.themes=h;