json-edit-react 1.6.1 → 1.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -10,6 +10,7 @@ Features include:
10
10
  - fine-grained control over which elements can be edited, deleted, or added to
11
11
  - customisable UI, through simple, pre-defined [themes](#themes--styles), specific CSS overrides for UI components, or by targeting CSS classes
12
12
  - self-contained — rendered with plain HTML/CSS, so no dependance on external UI libraries
13
+ - search/filter data by key, value or custom function
13
14
  - provide your own [custom component](#custom-nodes) to integrate specialised UI for certain data.
14
15
 
15
16
  **[Explore the Demo](https://carlosnz.github.io/json-edit-react/)**
@@ -24,12 +25,14 @@ Features include:
24
25
  - [Copy function](#copy-function)
25
26
  - [Filter functions](#filter-functions)
26
27
  - [Examples](#examples)
28
+ - [Search/Filtering](#searchfiltering)
27
29
  - [Themes \& Styles](#themes--styles)
28
30
  - [Fragments](#fragments)
29
31
  - [A note about sizing and scaling](#a-note-about-sizing-and-scaling)
30
32
  - [Icons](#icons)
31
33
  - [Localisation](#localisation)
32
34
  - [Custom Nodes](#custom-nodes)
35
+ - [Custom Collection nodes](#custom-collection-nodes)
33
36
  - [Active hyperlinks](#active-hyperlinks)
34
37
  - [Custom Text](#custom-text)
35
38
  - [Undo functionality](#undo-functionality)
@@ -82,34 +85,37 @@ It's pretty self explanatory (click the "edit" icon to edit, etc.), but there ar
82
85
 
83
86
  The only *required* value is `data`.
84
87
 
85
- | prop | type | default | description |
86
- | ----------------------- | -------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
87
- | `data` | `object\|array` | | The data to be displayed / edited |
88
- | `rootName` | `string` | `"data"` | A name to display in the editor as the root of the data object. |
89
- | `onUpdate` | `UpdateFunction` | | A function to run whenever a value is **updated** (edit, delete *or* add) in the editor. See [Update functions](#update-functions). |
90
- | `onEdit` | `UpdateFunction` | | A function to run whenever a value is **edited**. |
91
- | `onDelete` | `UpdateFunction` | | A function to run whenever a value is **deleted**. |
92
- | `onAdd` | `UpdateFunction` | | A function to run whenever a new property is **added**. |
93
- | `enableClipboard` | `boolean\|CopyFunction` | `true` | Whether or not to enable the "Copy to clipboard" button in the UI. If a function is provided, `true` is assumed and this function will be run whenever an item is copied. |
94
- | `indent` | `number` | `3` | Specify the amount of indentation for each level of nesting in the displayed data. |
95
- | `collapse` | `boolean\|number\|FilterFunction` | `false` | Defines which nodes of the JSON tree will be displayed "opened" in the UI on load. If `boolean`, it'll be either all or none. A `number` specifies a nesting depth after which nodes will be closed. For more fine control a function can be provided — see [Filter functions](#filter-functions). |
96
- | `restrictEdit` | `boolean\|FilterFunction` | `false` | If `false`, no editing is permitted. A function can be provided for more specificity — see [Filter functions](#filter-functions) |
97
- | `restrictDelete` | `boolean\|FilterFunction` | `false` | As with `restrictEdit` but for deletion |
98
- | `restrictAdd` | `boolean\|FilterFunction` | `false` | As with `restrictEdit` but for adding new properties |
99
- | `restrictTypeSelection` | `boolean\|DataType[]\|TypeFilterFunction` | `false` | For restricting the data types the user can select. Can be a list of data types (e.g. `[ 'string', 'number', 'boolean', 'array', 'object', 'null' ]`) or a boolean. A function can be provided -- it should take the same input as the above `FilterFunction`s, but output should be `boolean \| DataType[]`. |
100
- | `keySort` | `boolean\|CompareFunction` | `false` | If `true`, object keys will be ordered (using default JS `.sort()`). A [compare function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) can also be provided to define sorting behaviour. |
101
- | `showArrayIndices` | `boolean` | `true` | Whether or not to display the index (as a property key) for array elements. |
102
- | `showCollectionCount` | `boolean\|"when-closed"` | `true` | Whether or not to display the number of items in each collection (object or array). |
103
- | `defaultValue` | `any\|DefaultValueFilterFunction` | `null` | When a new property is added, it is initialised with this value. A function can be provided with the same input as the `FilterFunction`s, but should output a value. This allows a different default value to be used depending on the data state (e.g. default for top level is an object, but a string elsewhere.) |
104
- | `stringTruncate` | `number` | `250` | String values longer than this many characters will be displayed truncated (with `...`). The full string will always be visible when editing. |
105
- | `translations` | `LocalisedStrings` object | `{ }` | UI strings (such as error messages) can be translated by passing an object containing localised string values (there are only a few). See [Localisation](#localisation) |
106
- | `theme` | `string\|ThemeObject\|[string, ThemeObject]` | `"default"` | Either the name of one of the built-in themes, or an object specifying some or all theme properties. See [Themes](#themes--styles). |
107
- | `className` | `string` | | Name of a CSS class to apply to the component. In most cases, specifying `theme` properties will be more straightforward. |
108
- | `icons` | `{[iconName]: JSX.Element, ... }` | `{ }` | Replace the built-in icons by specifying them here. See [Themes](#themes--styles). | |
109
- | `minWidth` | `number\|string` (CSS value) | `250` | Minimum width for the editor container. |
110
- | `maxWidth` | `number\|string` (CSS value) | `600` | Maximum width for the editor container. |
111
- | `customNodeDefinitions` | `CustomNodeDefinition[]` | | You can provide customised components to override specific nodes in the data tree, according to a condition function. See see [Custom nodes](#custom-nodes) for more detail. (A simple custom component to turn url strings into active links is provided in the main package -- see [here](#active-hyperlinks)) |
112
- | `customText` | `CustomTextDefinitions` | | In addition to [localising the component](#localisation) text strings, you can also *dynamically* alter it, depending on the data. See [Custom Text](#custom-text) for more detail. |
88
+ | prop | type | default | description |
89
+ | ----------------------- | --------------------------------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
90
+ | `data` | `object\|array` | | The data to be displayed / edited |
91
+ | `rootName` | `string` | `"data"` | A name to display in the editor as the root of the data object. |
92
+ | `onUpdate` | `UpdateFunction` | | A function to run whenever a value is **updated** (edit, delete *or* add) in the editor. See [Update functions](#update-functions). |
93
+ | `onEdit` | `UpdateFunction` | | A function to run whenever a value is **edited**. |
94
+ | `onDelete` | `UpdateFunction` | | A function to run whenever a value is **deleted**. |
95
+ | `onAdd` | `UpdateFunction` | | A function to run whenever a new property is **added**. |
96
+ | `enableClipboard` | `boolean\|CopyFunction` | `true` | Whether or not to enable the "Copy to clipboard" button in the UI. If a function is provided, `true` is assumed and this function will be run whenever an item is copied. |
97
+ | `indent` | `number` | `3` | Specify the amount of indentation for each level of nesting in the displayed data. |
98
+ | `collapse` | `boolean\|number\|FilterFunction` | `false` | Defines which nodes of the JSON tree will be displayed "opened" in the UI on load. If `boolean`, it'll be either all or none. A `number` specifies a nesting depth after which nodes will be closed. For more fine control a function can be provided — see [Filter functions](#filter-functions). |
99
+ | `restrictEdit` | `boolean\|FilterFunction` | `false` | If `false`, no editing is permitted. A function can be provided for more specificity — see [Filter functions](#filter-functions) |
100
+ | `restrictDelete` | `boolean\|FilterFunction` | `false` | As with `restrictEdit` but for deletion |
101
+ | `restrictAdd` | `boolean\|FilterFunction` | `false` | As with `restrictEdit` but for adding new properties |
102
+ | `restrictTypeSelection` | `boolean\|DataType[]\|TypeFilterFunction` | `false` | For restricting the data types the user can select. Can be a list of data types (e.g. `[ 'string', 'number', 'boolean', 'array', 'object', 'null' ]`) or a boolean. A function can be provided -- it should take the same input as the above `FilterFunction`s, but output should be `boolean \| DataType[]`. |
103
+ | `searchText` | `string` | `undefined` | Data visibility will be filtered by matching against value, using the method defined below in `searchFilter` |
104
+ | `searchFilter` | `"key"\|"value"\|"all"\|SearchFilterFunction` | `undefined` | Define how `searchText` should be matched to filter the visible items. See [Search/Filtering](#searchfiltering) |
105
+ | `searchDebounceTime` | `number` | `350` | Debounce time when `searchText` changes |
106
+ | `keySort` | `boolean\|CompareFunction` | `false` | If `true`, object keys will be ordered (using default JS `.sort()`). A [compare function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) can also be provided to define sorting behaviour. |
107
+ | `showArrayIndices` | `boolean` | `true` | Whether or not to display the index (as a property key) for array elements. |
108
+ | `showCollectionCount` | `boolean\|"when-closed"` | `true` | Whether or not to display the number of items in each collection (object or array). |
109
+ | `defaultValue` | `any\|DefaultValueFilterFunction` | `null` | When a new property is added, it is initialised with this value. A function can be provided with the same input as the `FilterFunction`s, but should output a value. This allows a different default value to be used depending on the data state (e.g. default for top level is an object, but a string elsewhere.) |
110
+ | `stringTruncate` | `number` | `250` | String values longer than this many characters will be displayed truncated (with `...`). The full string will always be visible when editing. |
111
+ | `translations` | `LocalisedStrings` object | `{ }` | UI strings (such as error messages) can be translated by passing an object containing localised string values (there are only a few). See [Localisation](#localisation) |
112
+ | `theme` | `string\|ThemeObject\|[string, ThemeObject]` | `"default"` | Either the name of one of the built-in themes, or an object specifying some or all theme properties. See [Themes](#themes--styles). |
113
+ | `className` | `string` | | Name of a CSS class to apply to the component. In most cases, specifying `theme` properties will be more straightforward. |
114
+ | `icons` | `{[iconName]: JSX.Element, ... }` | `{ }` | Replace the built-in icons by specifying them here. See [Themes](#themes--styles). | |
115
+ | `minWidth` | `number\|string` (CSS value) | `250` | Minimum width for the editor container. |
116
+ | `maxWidth` | `number\|string` (CSS value) | `600` | Maximum width for the editor container. |
117
+ | `customNodeDefinitions` | `CustomNodeDefinition[]` | | You can provide customised components to override specific nodes in the data tree, according to a condition function. See see [Custom nodes](#custom-nodes) for more detail. (A simple custom component to turn url strings into active links is provided in the main package -- see [here](#active-hyperlinks)) |
118
+ | `customText` | `CustomTextDefinitions` | | In addition to [localising the component](#localisation) text strings, you can also *dynamically* alter it, depending on the data. See [Custom Text](#custom-text) for more detail. |
113
119
 
114
120
  ## Update functions
115
121
 
@@ -156,9 +162,11 @@ The function receives the following object:
156
162
  key, // name of the property
157
163
  path, // path to the property (as an array of property keys)
158
164
  level, // depth of the property (with 0 being the root)
165
+ index, // index of the node within its collection (based on display order)
159
166
  value, // value of the property
160
167
  size , // if a collection (object, array), the number of items (null for non-collections)
161
168
  parentData, // parent object containing the current node
169
+ fullData // the full (overall) data object
162
170
  collapsed // whether or not the current node is in a
163
171
  // "collapsed" state (only for Collection nodes)
164
172
  }
@@ -220,6 +228,33 @@ restrictTypeSelection = { ({ path, value }) => {
220
228
  } }
221
229
  ```
222
230
 
231
+ ## Search/Filtering
232
+
233
+ The displayed data can be filtered based on search input from a user. The user input should be captured independently (we don't provide a UI here) and passed in with the `searchText` prop. This input is debounced internally (time can be set with the `searchDebounceTime` prop), so no need for that as well. The values that the `searchText` are tested against is specified with the `searchFilter` prop. By default (no `searchFilter` defined), it will match against the data *values* (with case-insensitive partial matching -- i.e. input "Ilb", will match value "Bilbo").
234
+
235
+ You can specify what should be matched by setting `searchFilter` to either `"key"` (match property names), `"value"` (the default described above), or `"all"` (match both properties and values). This should be enough for the majority of use cases, but you can specify your own `SearchFilterFunction`. The search function is the same signature as the above [FilterFunctions](#filter-functions) but takes one additional argument for the `searchText`, i.e.
236
+
237
+ ```ts
238
+ ( { key, path, level, value, ...etc }:FilterFunctionInput, searchText:string ) => boolean
239
+ ```
240
+
241
+ There are two helper functions (`matchNode()` and `matchNodeKey()`) exported with the package that might make creating your search function easier (these are the functions used internally for the `"key"` and `"value"` matches described above). You can see what they do [here](https://github.com/CarlosNZ/json-edit-react/blob/574f2c1ba3e724c93ce8ab9cdba2fe8ebbbbf806/src/filterHelpers.ts#L64-L95).
242
+
243
+ An example custom search function can be seen in the [Demo](#https://carlosnz.github.io/json-edit-react/) with the "Client list" data set -- the search function matches by name and username, and makes the entire "Client" object visible when one of those matches, so it can be used to find a particular person and edit their specific details:
244
+
245
+ ```js
246
+ ({ path, fullData }, searchText) => {
247
+ // Matches *any* node that shares a path (i.e. a descendent) with a matching name/username
248
+ if (path?.length >= 2) {
249
+ const index = path?.[0]
250
+ return (
251
+ matchNode({ value: fullData[index].name }, searchText) ||
252
+ matchNode({ value: fullData[index].username }, searchText)
253
+ )
254
+ } else return false
255
+ }
256
+ ```
257
+
223
258
  ## Themes & Styles
224
259
 
225
260
  There is a small selection of built-in themes (as seen in the [Demo app](https://carlosnz.github.io/json-edit-react/)). In order to use one of these, just pass the name into the `theme` prop (although realistically, these exist more to showcase the capabilities — I'm open to better built-in themes, so feel free to [create an issue](https://github.com/CarlosNZ/json-edit-react/issues) with suggestions). The available themes are:
@@ -390,10 +425,12 @@ Custom nodes are provided in the `customNodeDefinitions` prop, as an array of ob
390
425
  showEditTools // boolean, default true
391
426
  name // string (appears in Types selector)
392
427
  showInTypesSelector, // boolean (optional), default false
428
+ // Only affects Collection nodes:
429
+ showCollectionWrapper // boolean (optional), default true
393
430
  }
394
431
  ```
395
432
 
396
- The `condition` is just a [Filter function](#filter-functions), with the same input parameters (`key`, `path`, `level`, `value`, `size`), and `element` is a React component. Every node in the data structure will be run through each condition function, and any that match will be replaced by your custom component. Note that if a node matches more than one custom definition conditions (from multiple components), the *first* one will be used, so place them in the array in priority order.
433
+ The `condition` is just a [Filter function](#filter-functions), with the same input parameters (`key`, `path`, `value`, etc.), and `element` is a React component. Every node in the data structure will be run through each condition function, and any that match will be replaced by your custom component. Note that if a node matches more than one custom definition conditions (from multiple components), the *first* one will be used, so place them in the array in priority order.
397
434
 
398
435
  The component will receive *all* the same props as a standard node component (see codebase), but you can pass additional props to your component if required through the `customNodeProps` object. A thorough example of a custom Date picker is used in the demo (along with a couple of other more basic presentational ones), which you can inspect to see how to utilise the standard props and a couple of custom props. View the source code [here](https://github.com/CarlosNZ/json-edit-react/blob/main/demo/src/customComponents/DateTimePicker.tsx)
399
436
 
@@ -403,6 +440,12 @@ Also, by default, your component will be treated as a "display" element, i.e. it
403
440
 
404
441
  You can allow users to create new instances of your special nodes by selecting them as a "Type" in the types selector when editing/adding values. Set `showInTypesSelector: true` to enable this. However, if this is enabled you need to also provide a `name` (which is what the user will see in the selector) and a `defaultValue` which is the data that is inserted when the user selects this "type". (The `defaultValue` must return `true` if passed through the `condition` function in order for it to be immediately displayed using your custom component.)
405
442
 
443
+ ### Custom Collection nodes
444
+
445
+ In most cases it will be preferable to create custom nodes to match *value* nodes (i.e. not `array` or `object` *collection* nodes). However, if you do wish to replace a whole collection, there are a couple of other things to know:
446
+ - The descendants of this node can still be displayed using the [React `children`](https://react.dev/learn/passing-props-to-a-component#passing-jsx-as-children) property, it just becomes your component's responsibility to handle it.
447
+ - There is one additional prop, `showCollectionWrapper` (default `true`), which, when set to `false`, hides the surrounding "wrapper", namely the hide/show chevron and the brackets. In this case, you would have to provide your own hide/show mechanism in your component.
448
+
406
449
  ### Active hyperlinks
407
450
 
408
451
  A simple custom component and definition to turn url strings into clickable links is provided with the main package for you to use out of the box. Just import and use like so:
@@ -466,6 +509,7 @@ A few helper functions, components and types that might be useful in your own im
466
509
  - `LinkCustomComponent`: the component used to render [hyperlinks](#active-hyperlinks)
467
510
  - `LinkCustomNodeDefinition`: custom node definition for [hyperlinks](#active-hyperlinks)
468
511
  - `IconAdd`, `IconEdit`, `IconDelete`, `IconCopy`, `IconOk`, `IconCancel`, `IconChevron`: all the built-in [icon](#icons) components
512
+ - `matchNode`, `matchNodeKey`: helpers for defining custom [Search](#searchfiltering) functions
469
513
  - `truncate`: function to truncate a string to a specified length. See [here](https://github.com/CarlosNZ/json-edit-react/blob/d5fdbdfed6da7152f5802c67fbb3577810d13adc/src/ValueNodes.tsx#L9-L13)
470
514
  - `breakString`: function to turn a string into HTML, preserving line breaks and white space. See [here](https://github.com/CarlosNZ/json-edit-react/blob/d5fdbdfed6da7152f5802c67fbb3577810d13adc/src/ValueNodes.tsx#L15-L29)
471
515
  - `extract`: function to extract a deeply nested object value from a string path. See [here](https://github.com/CarlosNZ/object-property-extractor)
@@ -477,7 +521,7 @@ A few helper functions, components and types that might be useful in your own im
477
521
  - `Theme`: a full [Theme](#themes--styles) object
478
522
  - `ThemeInput`: input type for the `theme` prop
479
523
  - `JsonEditorProps`: all input props for the Json Editor component
480
- - [`UpdateFunction`](#update-functions), [`FilterFunction`](#filter-functions), [`CopyFunction`](#copy-function), [`CompareFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort), [`LocalisedString`](#localisation), [`CustomNodeDefinition`](#custom-nodes), [`CustomTextDefinitions`](#custom-text)
524
+ - [`UpdateFunction`](#update-functions), [`FilterFunction`](#filter-functions), [`CopyFunction`](#copy-function), [`SearchFilterFunction`](#searchfiltering), [`CompareFunction`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort), [`LocalisedString`](#localisation), [`CustomNodeDefinition`](#custom-nodes), [`CustomTextDefinitions`](#custom-text)
481
525
  - `TranslateFunction`: function that takes a [localisation](#localisation) key and returns a translated string
482
526
  - `IconReplacements`: input type for the `icons` prop
483
527
  - `CollectionNodeProps`: all props passed internally to "collection" nodes (i.e. objects/arrays)
@@ -494,7 +538,7 @@ The main features I'd like to introduce are:
494
538
 
495
539
  1. **JSON Schema validation**. We can currently specify a reasonable degree of control over what can be edited using [Filter functions](#filter-functions) with the restriction props, but I'd like to go a step further and be able to pass in a [JSON Schema](https://json-schema.org/) and have the data be automatically validated against it, with the results reflected in the UI. This would allow control over data types and prevent missing properties, something that is not currently possible.
496
540
  2. **Visibility filter function** — *hide* properties from the UI completely based on a Filter function. This should arguably be done outside the component though (filter the data upstream), so would be less of a priority (though it would be fairly simple to implement, so 🤷‍♂️)
497
- 3. **Search** — allow the user to narrow the list of visible keys with a simple search input. This would be useful for very large data objects, but is possibly getting a bit too much in terms of opinionated UI, so would need to ensure it can be styled easily. Perhaps it would be better if the "Search" input was handled outside this package, and we just accepted a "search" string prop?
541
+ 3. ~~**Search** — allow the user to narrow the list of visible keys with a simple search input. This would be useful for very large data objects, but is possibly getting a bit too much in terms of opinionated UI, so would need to ensure it can be styled easily. Perhaps it would be better if the "Search" input was handled outside this package, and we just accepted a "search" string prop?~~ 👍 [Done](#searchfiltering)
498
542
 
499
543
  ## Inspiration
500
544
 
@@ -502,6 +546,10 @@ This component is heavily inspired by [react-json-view](https://github.com/mac-s
502
546
 
503
547
  ## Changelog
504
548
 
549
+ - **1.7.2**:
550
+ - Fix and improve Custom nodes in *collections*
551
+ - Include `index` in Filter (and other) function input
552
+ - **1.7.0**: Implement [Search/filtering](#searchfiltering) of data visibility
505
553
  - **1.6.1**: Revert data state on Update Function error
506
554
  - **1.6.0**: Allow a function for `defaultValue` prop
507
555
  - **1.5.0**:
@@ -1 +1 @@
1
- "use strict";var jsxRuntime=require("react/jsx-runtime"),react=require("react"),assign=require("object-property-assigner"),extract=require("object-property-extractor"),JSON5=require("json5"),clone=require("just-clone");function __rest(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}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 line-height: 1;\n padding: 1em;\n padding-left: 2em;\n /* margin-top: 1em; */\n /* margin-bottom: 1em; */\n border-radius: 0.5em;\n text-align: left;\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-bracket-outside {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collapse-icon {\n position: absolute;\n left: -1.2em;\n top: 0.35em;\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-hyperlink {\n text-decoration: underline;\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 AutogrowTextArea=({className:className,name:name,value:value,setValue:setValue,handleKeyPress:handleKeyPress,styles:styles})=>{const 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),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),children:dummyValue})]})},themes={default:{displayName:"Default",fragments:{edit:"rgb(42, 161, 152)"},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},collection:{},collectionInner:{},collectionElement:{},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:{},collection:{},collectionInner:{},collectionElement:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},defaultTheme=themes.default,ThemeProviderContext=react.createContext({getStyles:()=>({}),setTheme:_=>{},icons:{},setIcons:()=>{}}),ThemeProvider=({children:children})=>{const[styles,setStyles]=react.useState(emptyStyleObject),[icons,setIcons]=react.useState({});return jsxRuntime.jsx(ThemeProviderContext.Provider,{value:{getStyles:(element,nodeData)=>"function"==typeof styles[element]?styles[element](nodeData):styles[element],setTheme:theme=>{const styles=compileStyles(theme);setStyles(styles)},icons:icons,setIcons:setIcons},children:children})},useTheme=()=>react.useContext(ThemeProviderContext),compileStyles=themeInput=>{var _a,_b,_c,_d;const collectedFunctions={},stylesArray=(Array.isArray(themeInput)?themeInput:[themeInput]).map((theme=>"default"===themeInput?{}:"string"==typeof theme?buildStyleObject(themes[theme],collectedFunctions):isStyleObject(theme)?buildStyleObject({fragments:{},styles:theme},collectedFunctions):buildStyleObject(theme,collectedFunctions))),mergedStyleObject=buildStyleObject(defaultTheme,{});Object.keys(mergedStyleObject).forEach((k=>{const key=k;stylesArray.forEach((styleObj=>{styleObj[key]&&(mergedStyleObject[key]=Object.assign(Object.assign({},mergedStyleObject[key]),styleObj[key]))}))}));const finalStyles=Object.assign({},mergedStyleObject);return Object.entries(collectedFunctions).forEach((([key,func])=>{const element=key;finalStyles[element]=nodeData=>{const funcResult=func(nodeData)||{};return Object.assign(Object.assign({},mergedStyleObject[element]),funcResult)}})),"function"!=typeof(null==finalStyles?void 0:finalStyles.inputHighlight)&&(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),"function"!=typeof(null==finalStyles?void 0:finalStyles.iconCopy)&&(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},buildStyleObject=(theme,collectedFunctions)=>{const{fragments:fragments,styles:styles}=theme,styleObject={};return Object.entries(styles).forEach((([key,value])=>{const cssStyles=(Array.isArray(value)?value:[value]).reduce(((acc,curr)=>{var _a;if("function"==typeof curr)return collectedFunctions[key]=curr,Object.assign({},acc);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)}),{});styleObject[key]=cssStyles})),styleObject},isStyleObject=overrideObject=>!("styles"in overrideObject),defaultStyleProperties={container:"backgroundColor",collection:"backgroundColor",collectionInner:"backgroundColor",collectionElement:"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"},truncate=(string,length=200)=>string.length<length?string:`${string.slice(0,length-2).trim()}...`,breakString=text=>text.split("\n").map(((line,index,arr)=>{const match=/^( +)/.exec(line);return jsxRuntime.jsxs("span",{children:[match?match[0].split("").map((()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:" "}))):null,line,index<arr.length-1?jsxRuntime.jsx("br",{}):null]},index)})),StringValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,stringTruncate:stringTruncate,nodeData:nodeData})=>{const{getStyles:getStyles}=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()},styles:getStyles("input",nodeData)}):jsxRuntime.jsxs("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string",style:getStyles("string",nodeData),children:['"',breakString(truncate(value,stringTruncate)),'"']})},NumberValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=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:getStyles("number",nodeData),children:value})},BooleanValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing,handleEdit]);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:getStyles("boolean",nodeData),children:String(value)})},NullValue=({value:value,isEditing:isEditing,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=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:getStyles("null",nodeData),children:String(value)})},ObjectValue=({value:value,translate:translate,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{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",nodeData)}: "${String(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?"":String(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})},IconAdd=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4z"}),jsxRuntime.jsx("path",{d:"M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"})]}),IconEdit=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M7 17.013l4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z"}),jsxRuntime.jsx("path",{d:"M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z"})]}),IconDelete=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M6 19a2 2 0 002 2h8a2 2 0 002-2V7H6v12m2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12M15.5 4l-1-1h-5l-1 1H5v2h14V4h-3.5z"})}),IconCopy=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M9 2 H15 A1 1 0 0 1 16 3 V5 A1 1 0 0 1 15 6 H9 A1 1 0 0 1 8 5 V3 A1 1 0 0 1 9 2 z"}),jsxRuntime.jsx("path",{d:"M8 4H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2v-2M16 4h2a2 2 0 012 2v4M21 14H11"}),jsxRuntime.jsx("path",{d:"M15 10l-4 4 4 4"})]}),IconOk=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M22 11.08V12a10 10 0 11-5.93-9.14"}),jsxRuntime.jsx("path",{d:"M22 4L12 14.01l-3-3"})]}),IconCancel=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{baseProfile:"tiny",viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M12 4c-4.411 0-8 3.589-8 8s3.589 8 8 8 8-3.589 8-8-3.589-8-8-8zm-5 8c0-.832.224-1.604.584-2.295l6.711 6.711A4.943 4.943 0 0112 17c-2.757 0-5-2.243-5-5zm9.416 2.295L9.705 7.584A4.943 4.943 0 0112 7c2.757 0 5 2.243 5 5 0 .832-.224 1.604-.584 2.295z"})}),IconChevron=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{viewBox:"0 0 512 512",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})}),Icon=({name:name,nodeData:nodeData,rotate:rotate})=>{var _a,_b,_c,_d,_e,_f,_g;const{getStyles:getStyles,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(IconAdd,Object.assign({},commonProps,{style:getStyles("iconAdd",nodeData)}));case"edit":return null!==(_b=null==icons?void 0:icons.edit)&&void 0!==_b?_b:jsxRuntime.jsx(IconEdit,Object.assign({},commonProps,{style:getStyles("iconEdit",nodeData)}));case"delete":return null!==(_c=null==icons?void 0:icons.delete)&&void 0!==_c?_c:jsxRuntime.jsx(IconDelete,Object.assign({},commonProps,{style:getStyles("iconDelete",nodeData),size:"1.5em"}));case"copy":return null!==(_d=null==icons?void 0:icons.copy)&&void 0!==_d?_d:jsxRuntime.jsx(IconCopy,Object.assign({},commonProps,{style:getStyles("iconCopy",nodeData),size:"1.2em"}));case"ok":return null!==(_e=null==icons?void 0:icons.ok)&&void 0!==_e?_e:jsxRuntime.jsx(IconOk,Object.assign({},commonProps,{style:Object.assign({fontSize:"90%"},getStyles("iconOk",nodeData))}));case"cancel":return null!==(_f=null==icons?void 0:icons.cancel)&&void 0!==_f?_f:jsxRuntime.jsx(IconCancel,Object.assign({},commonProps,{style:Object.assign({fontSize:"130%"},getStyles("iconCancel",nodeData))}));case"chevron":return null!==(_g=null==icons?void 0:icons.chevron)&&void 0!==_g?_g:jsxRuntime.jsx(IconChevron,{className:"jer-accordion-icon"+(rotate?" jer-rotate-90":""),size:"1em",style:getStyles("iconCollection",nodeData)});default:return jsxRuntime.jsx(jsxRuntime.Fragment,{})}},EditButtons=({startEdit:startEdit,handleDelete:handleDelete,handleAdd:handleAdd,enableClipboard:enableClipboard,type:type,nodeData:nodeData,translate:translate})=>{const{getStyles:getStyles}=useTheme(),NEW_KEY_PROMPT=translate("KEY_NEW",nodeData),[isAdding,setIsAdding]=react.useState(!1),[newKey,setNewKey]=react.useState(NEW_KEY_PROMPT),{key:key,path:path,value:data}=nodeData;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:key,type:copyType})},className:"jer-copy-pulse",children:jsxRuntime.jsx(Icon,{name:"copy",nodeData:nodeData})}),startEdit&&jsxRuntime.jsx("div",{onClick:startEdit,children:jsxRuntime.jsx(Icon,{name:"edit",nodeData:nodeData})}),handleDelete&&jsxRuntime.jsx("div",{onClick:handleDelete,children:jsxRuntime.jsx(Icon,{name:"delete",nodeData:nodeData})}),handleAdd&&jsxRuntime.jsx("div",{onClick:()=>{"object"===type?setIsAdding(!0):handleAdd("")},children:jsxRuntime.jsx(Icon,{name:"add",nodeData:nodeData})}),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:getStyles("input",nodeData)}),jsxRuntime.jsx(InputButtons,{onOk:()=>{newKey&&(setIsAdding(!1),handleAdd(newKey))},onCancel:()=>{setIsAdding(!1)},nodeData:nodeData})]})]})},InputButtons=({onOk:onOk,onCancel:onCancel,nodeData:nodeData})=>jsxRuntime.jsxs("div",{className:"jer-confirm-buttons",children:[jsxRuntime.jsx("div",{onClick:onOk,children:jsxRuntime.jsx(Icon,{name:"ok",nodeData:nodeData})}),jsxRuntime.jsx("div",{onClick:onCancel,children:jsxRuntime.jsx(Icon,{name:"cancel",nodeData:nodeData})})]}),stringifyPath=path=>path.reduce(((str,part)=>"number"==typeof part?`${str}[${part}]`:""===str?part:`${str}.${part}`),""),DataTypes=["string","number","boolean","null","object","array"],getCustomNode=(customNodeDefinitions=[],nodeData)=>{const matchingDefinitions=customNodeDefinitions.filter((({condition:condition})=>condition(nodeData)));if(0===matchingDefinitions.length)return{};const _a=matchingDefinitions[0],{element:element,customNodeProps:customNodeProps,hideKey:hideKey=!1,showEditTools:showEditTools=!0,showOnEdit:showOnEdit=!1,showOnView:showOnView=!0}=_a,rest=__rest(_a,["element","customNodeProps","hideKey","showEditTools","showOnEdit","showOnView"]);return Object.assign({CustomNode:element,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools,showOnEdit:showOnEdit,showOnView:showOnView},rest)},ValueNodeWrapper=props=>{const{data:data,parentData:parentData,nodeData:nodeData,onEdit:onEdit,onDelete:onDelete,enableClipboard:enableClipboard,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictTypeSelection:restrictTypeSelection,showLabel:showLabel,stringTruncate:stringTruncate,indent:indent,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,{getStyles:getStyles}=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),{key:name,path:path}=nodeData,customNodeData=getCustomNode(customNodeDefinitions,nodeData),[dataType,setDataType]=react.useState(getDataType(data,customNodeData));react.useEffect((()=>{setValue("function"==typeof data?"**INVALID_FUNCTION**":data),setDataType(getDataType(data,customNodeData))}),[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",nodeData)]: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,customNodeData))},canEdit=react.useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=react.useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),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,nodeData:nodeData,translate:translate},{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=customNodeData,allDataTypes=[...DataTypes,...customNodeDefinitions.filter((({showInTypesSelector:showInTypesSelector=!1,name:name})=>showInTypesSelector&&!!name)).map((({name:name})=>name))],allowedDataTypes=react.useMemo((()=>{if("boolean"==typeof restrictTypeSelection)return restrictTypeSelection?[]:allDataTypes;if(Array.isArray(restrictTypeSelection))return restrictTypeSelection;const result=restrictTypeSelection(nodeData);return"boolean"==typeof result?result?[]:allDataTypes:result}),[nodeData,restrictTypeSelection]),ValueComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsxRuntime.jsx(CustomNode,Object.assign({},props,{value:value,customNodeProps:customNodeProps,setValue:setValue,handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:e=>{"Enter"===e.key?handleEdit():"Escape"===e.key&&handleCancel()},isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):getInputComponent(getDataType(data),inputProps);return 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&&!hideKey&&jsxRuntime.jsxs("label",{htmlFor:path.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},getStyles("property",nodeData)),{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:ValueComponent}),isEditing?jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData}):"invalid"!==dataType&&!error&&showEditTools&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>setIsEditing(!0):void 0,handleDelete:canDelete?()=>{onDelete(value,path).then((error=>{error&&logError(error)}))}:void 0,enableClipboard:enableClipboard,translate:translate,nodeData:nodeData}),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));if(customNode)onEdit(customNode.defaultValue,path),setDataType(type);else{const newValue=convertValue(value,type,translate("DEFAULT_NEW_KEY",nodeData),(null==customNodeData?void 0:customNodeData.CustomNode)?translate("DEFAULT_STRING",nodeData):void 0);setValue(newValue),onEdit(newValue,path),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:getStyles("error",nodeData),children:error})]})]})})},getDataType=(value,customNodeData)=>(null==customNodeData?void 0:customNodeData.CustomNode)&&(null==customNodeData?void 0:customNodeData.name)&&customNodeData.showInTypesSelector?customNodeData.name:"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,defaultNewKey,defaultString)=>{switch(type){case"string":return null!=defaultString?defaultString:String(value);case"number":{const n=Number(value);return isNaN(n)?0:n}case"boolean":return!!value;case"null":return null;case"object":return{[defaultNewKey]:value};case"array":return[value];default:return String(value)}},CollapseProviderContext=react.createContext({collapseState:null,setCollapseState:()=>{},doesPathMatch:()=>!1}),CollapseProvider=({children:children})=>{const[collapseState,setCollapseState]=react.useState(null);return jsxRuntime.jsx(CollapseProviderContext.Provider,{value:{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:path=>{if(null===collapseState)return!1;for(const[index,value]of collapseState.path.entries())if(value!==path[index])return!1;return!0}},children:children})},useCollapseAll=()=>react.useContext(CollapseProviderContext),isCollection=value=>null!==value&&"object"==typeof value,CollectionNode=_a=>{var{data:data,nodeData:incomingNodeData,parentData:parentData,showCollectionCount:showCollectionCount}=_a,props=__rest(_a,["data","nodeData","parentData","showCollectionCount"]);const{getStyles:getStyles}=useTheme(),{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:doesPathMatch}=useCollapseAll(),{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),startCollapsed=collapseFilter(incomingNodeData),[collapsed,setCollapsed]=react.useState(startCollapsed),nodeData=Object.assign(Object.assign({},incomingNodeData),{collapsed:collapsed}),{path:path,key:name,size:size}=nodeData,hasBeenOpened=react.useRef(!startCollapsed),[isAnimating,setIsAnimating]=react.useState(!1);react.useEffect((()=>{setStringifiedValue(JSON.stringify(data,null,2))}),[data]),react.useEffect((()=>{setCollapsed(collapseFilter(nodeData))}),[collapseFilter]),react.useEffect((()=>{null!==collapseState&&doesPathMatch(path)&&(hasBeenOpened.current=!0,setCollapsed(collapseState.open))}),[collapseState]);const collectionType=Array.isArray(data)?"array":"object",brackets="array"===collectionType?{open:"[",close:"]"}:{open:"{",close:"}"},transitionTime=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),getDefaultNewValue=react.useMemo((()=>nodeData=>"function"!=typeof defaultValue?defaultValue:defaultValue(nodeData)),[defaultValue]),handleKeyPress=e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?handleEdit():"Escape"===e.key&&handleCancel()},showError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{try{const value=JSON5.parse(stringifiedValue);setIsEditing(!1),setError(null),onEdit(value,path).then((error=>{error&&showError(error)}))}catch(_a){setError(translate("ERROR_INVALID_JSON",nodeData)),setTimeout((()=>setError(null)),2500),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(nodeData)),[nodeData]),canDelete=react.useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),canAdd=react.useMemo((()=>!restrictAddFilter(nodeData)),[nodeData]),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,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=getCustomNode(customNodeDefinitions,nodeData),CollectionComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsxRuntime.jsx(CustomNode,Object.assign({},props,{data:data,value:data,parentData:parentData,nodeData:nodeData,customNodeProps:customNodeProps,setValue:value=>onEdit(value,path),handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:handleKeyPress,isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):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,styles:getStyles("input",nodeData)}),jsxRuntime.jsx("div",{className:"jer-collection-input-button-row",children:jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData})})]})}):hasBeenOpened.current?keyValueArray.map((([key,value])=>jsxRuntime.jsx("div",{className:"jer-collection-element",style:getStyles("collectionElement",nodeData),children:isCollection(value)?jsxRuntime.jsx(CollectionNode,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,parentData:data,size:Object.keys(value).length},showCollectionCount:showCollectionCount},props),key):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,size:1,parentData:data}},props,{showLabel:"object"===collectionType||showArrayIndices}),key)},key))):null;return jsxRuntime.jsxs("div",{className:"jer-component jer-collection-component",style:Object.assign({marginLeft:(0===path.length?0:indent/2)+"em"},getStyles("collection",nodeData)),children:[jsxRuntime.jsxs("div",{className:"jer-collection-header-row",style:{position:"relative"},children:[jsxRuntime.jsxs("div",{className:"jer-collection-name",children:[jsxRuntime.jsx("div",{className:"jer-collapse-icon",onClick:e=>(e=>{if(e.getModifierState("Alt"))return hasBeenOpened.current=!0,void setCollapseState({open:!collapsed,path:path});isEditing||(setIsAnimating(!0),hasBeenOpened.current=!0,setCollapsed(!collapsed),setTimeout((()=>setIsAnimating(!1)),500))})(e),children:jsxRuntime.jsx(Icon,{name:"chevron",rotate:collapsed,nodeData:nodeData})}),!isEditingKey&&jsxRuntime.jsx("span",{style:getStyles("property",nodeData),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:showLabel&&!hideKey&&""!==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 jer-bracket-open",style:getStyles("bracket",nodeData),children:brackets.open})]}),!isEditing&&showCount&&jsxRuntime.jsx("div",{className:"jer-collection-item-count"+(showCount?" jer-visible":" jer-hidden"),style:getStyles("itemCount",nodeData),children:1===size?translate("ITEM_SINGLE",Object.assign(Object.assign({},nodeData),{size:1}),1):translate("ITEMS_MULTIPLE",nodeData,size)}),jsxRuntime.jsx("div",{className:"jer-brackets"+(collapsed?" jer-visible":" jer-hidden"),style:getStyles("bracket",nodeData),children:brackets.close}),!isEditing&&showEditTools&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>{setIsEditing(!0),setCollapsed(!1)}:void 0,handleAdd:canAdd?key=>{setCollapsed(!1);const newValue=getDefaultNewValue(nodeData);"array"===collectionType?onAdd(newValue,[...path,data.length]).then((error=>{error&&showError(error)})):key in data?showError(translate("ERROR_KEY_EXISTS",nodeData)):onAdd(newValue,[...path,key]).then((error=>{error&&showError(error)}))}:void 0,handleDelete:canDelete?handleDelete:void 0,enableClipboard:enableClipboard,type:collectionType,nodeData:nodeData,translate:translate})]}),jsxRuntime.jsxs("div",{className:"jer-collection-inner",style:Object.assign({maxHeight:collapsed?0:isEditing?void 0:3*numOfLines+"em",overflowY:collapsed||isAnimating?"hidden":"visible",transition:`max-height ${transitionTime}`},getStyles("collectionInner",nodeData)),children:[CollectionComponent,jsxRuntime.jsx("div",{className:isEditing?"jer-collection-error-row":"jer-collection-error-row-edit",children:error&&jsxRuntime.jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})}),!isEditing&&jsxRuntime.jsx("div",{className:"jer-brackets jer-bracket-outside",style:getStyles("bracket",nodeData),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,customText)=>(key,customTextData,count)=>((translations,customText,customTextData,key,count)=>{if(customText[key]){const output=customText[key](customTextData);if(null!==output)return output}const string=key in translations?translations[key]:localisedStrings[key];return void 0===count?string:null==string?void 0:string.replace("{{count}}",String(count))})(translations,customText,customTextData,key,count),Editor=({data:srcData,rootName:rootName="root",onUpdate:onUpdate=(()=>{}),onEdit:srcEdit=onUpdate,onDelete:srcDelete=onUpdate,onAdd:srcAdd=onUpdate,enableClipboard:enableClipboard=!0,theme:theme="default",icons:icons,indent:indent=3,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,customText:customText={},customNodeDefinitions:customNodeDefinitions=[]})=>{const{getStyles:getStyles,setTheme:setTheme,setIcons:setIcons}=useTheme(),{setCollapseState:setCollapseState}=useCollapseAll(),collapseFilter=react.useCallback(getFilterFunction(collapse),[collapse]),translate=react.useCallback(getTranslateFunction(translations,customText),[translations,customText]),[data,setData]=react.useState(srcData);react.useEffect((()=>{theme&&setTheme(theme),icons&&setIcons(icons)}),[theme,icons]),react.useEffect((()=>{setCollapseState(null),setData(srcData)}),[srcData]);const nodeData={key:rootName,path:[],level:0,value:data,size:Object.keys(data).length,parentData:null},restrictEditFilter=getFilterFunction(restrictEdit),restrictDeleteFilter=getFilterFunction(restrictDelete),restrictAddFilter=getFilterFunction(restrictAdd),otherProps={name:rootName,nodeData:nodeData,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");setData(newData);const result=yield srcEdit({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcDelete({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcAdd({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):result})),showCollectionCount:showCollectionCount,collapseFilter:collapseFilter,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,restrictTypeSelection:restrictTypeSelection,enableClipboard:enableClipboard,keySort:keySort,showArrayIndices:showArrayIndices,indent:indent,defaultValue:defaultValue,stringTruncate:stringTruncate,translate:translate,customNodeDefinitions:customNodeDefinitions,parentData:null};return jsxRuntime.jsx("div",{className:"jer-editor-container "+className,style:Object.assign(Object.assign({},getStyles("container",nodeData)),{minWidth:minWidth,maxWidth:maxWidth}),children:isCollection(data)?jsxRuntime.jsx(CollectionNode,Object.assign({data:data},otherProps)):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:data,showLabel:!0},otherProps))})},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:"delete"!==action?newValue:void 0}},getFilterFunction=propValue=>"boolean"==typeof propValue?()=>propValue:"number"==typeof propValue?({level:level})=>level>=propValue:propValue,LinkCustomComponent=({value:value,setIsEditing:setIsEditing,getStyles:getStyles,customNodeProps:customNodeProps,nodeData:nodeData})=>{var _a,_b;const stringTruncateLength=null!==(_a=null==customNodeProps?void 0:customNodeProps.stringTruncate)&&void 0!==_a?_a:100,styles=getStyles("string",nodeData);return jsxRuntime.jsx("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string jer-hyperlink",style:styles,children:jsxRuntime.jsxs("a",{href:value,target:"_blank",rel:"noreferrer",style:{color:null!==(_b=styles.color)&&void 0!==_b?_b:void 0},children:['"',truncate(value,stringTruncateLength),'"']})})},LinkCustomNodeDefinition={condition:({value:value})=>"string"==typeof value&&/^https?:\/\/.+\..+$/.test(value),element:LinkCustomComponent,showOnView:!0,showOnEdit:!1};exports.assign=assign,exports.extract=extract,exports.IconAdd=IconAdd,exports.IconCancel=IconCancel,exports.IconChevron=IconChevron,exports.IconCopy=IconCopy,exports.IconDelete=IconDelete,exports.IconEdit=IconEdit,exports.IconOk=IconOk,exports.JsonEditor=props=>jsxRuntime.jsx(ThemeProvider,{children:jsxRuntime.jsx(CollapseProvider,{children:jsxRuntime.jsx(Editor,Object.assign({},props))})}),exports.LinkCustomComponent=LinkCustomComponent,exports.LinkCustomNodeDefinition=LinkCustomNodeDefinition,exports.breakString=breakString,exports.themes=themes,exports.truncate=truncate;
1
+ "use strict";var jsxRuntime=require("react/jsx-runtime"),react=require("react"),assign=require("object-property-assigner"),extract=require("object-property-extractor"),JSON5=require("json5"),clone=require("just-clone");function __rest(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}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 line-height: 1;\n padding: 1em;\n padding-left: 2em;\n /* margin-top: 1em; */\n /* margin-bottom: 1em; */\n border-radius: 0.5em;\n text-align: left;\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-bracket-outside {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collapse-icon {\n position: absolute;\n left: -1.2em;\n top: 0.35em;\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-hyperlink {\n text-decoration: underline;\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 AutogrowTextArea=({className:className,name:name,value:value,setValue:setValue,handleKeyPress:handleKeyPress,styles:styles})=>{const 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),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),children:dummyValue})]})},themes={default:{displayName:"Default",fragments:{edit:"rgb(42, 161, 152)"},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},collection:{},collectionInner:{},collectionElement:{},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:{},collection:{},collectionInner:{},collectionElement:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},defaultTheme=themes.default,ThemeProviderContext=react.createContext({getStyles:()=>({}),setTheme:_=>{},icons:{},setIcons:()=>{}}),ThemeProvider=({children:children})=>{const[styles,setStyles]=react.useState(emptyStyleObject),[icons,setIcons]=react.useState({});return jsxRuntime.jsx(ThemeProviderContext.Provider,{value:{getStyles:(element,nodeData)=>"function"==typeof styles[element]?styles[element](nodeData):styles[element],setTheme:theme=>{const styles=compileStyles(theme);setStyles(styles)},icons:icons,setIcons:setIcons},children:children})},useTheme=()=>react.useContext(ThemeProviderContext),compileStyles=themeInput=>{var _a,_b,_c,_d;const collectedFunctions={},stylesArray=(Array.isArray(themeInput)?themeInput:[themeInput]).map((theme=>"default"===themeInput?{}:"string"==typeof theme?buildStyleObject(themes[theme],collectedFunctions):isStyleObject(theme)?buildStyleObject({fragments:{},styles:theme},collectedFunctions):buildStyleObject(theme,collectedFunctions))),mergedStyleObject=buildStyleObject(defaultTheme,{});Object.keys(mergedStyleObject).forEach((k=>{const key=k;stylesArray.forEach((styleObj=>{styleObj[key]&&(mergedStyleObject[key]=Object.assign(Object.assign({},mergedStyleObject[key]),styleObj[key]))}))}));const finalStyles=Object.assign({},mergedStyleObject);return Object.entries(collectedFunctions).forEach((([key,func])=>{const element=key;finalStyles[element]=nodeData=>{const funcResult=func(nodeData)||{};return Object.assign(Object.assign({},mergedStyleObject[element]),funcResult)}})),"function"!=typeof(null==finalStyles?void 0:finalStyles.inputHighlight)&&(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),"function"!=typeof(null==finalStyles?void 0:finalStyles.iconCopy)&&(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},buildStyleObject=(theme,collectedFunctions)=>{const{fragments:fragments,styles:styles}=theme,styleObject={};return Object.entries(styles).forEach((([key,value])=>{const cssStyles=(Array.isArray(value)?value:[value]).reduce(((acc,curr)=>{var _a;if("function"==typeof curr)return collectedFunctions[key]=curr,Object.assign({},acc);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)}),{});styleObject[key]=cssStyles})),styleObject},isStyleObject=overrideObject=>!("styles"in overrideObject),defaultStyleProperties={container:"backgroundColor",collection:"backgroundColor",collectionInner:"backgroundColor",collectionElement:"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"},truncate=(string,length=200)=>string.length<length?string:`${string.slice(0,length-2).trim()}...`,breakString=text=>text.split("\n").map(((line,index,arr)=>{const match=/^( +)/.exec(line);return jsxRuntime.jsxs("span",{children:[match?match[0].split("").map((()=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:" "}))):null,line,index<arr.length-1?jsxRuntime.jsx("br",{}):null]},index)})),StringValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,stringTruncate:stringTruncate,nodeData:nodeData})=>{const{getStyles:getStyles}=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()},styles:getStyles("input",nodeData)}):jsxRuntime.jsxs("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string",style:getStyles("string",nodeData),children:['"',breakString(truncate(value,stringTruncate)),'"']})},NumberValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=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:getStyles("number",nodeData),children:value})},BooleanValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();react.useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing,handleEdit]);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:getStyles("boolean",nodeData),children:String(value)})},NullValue=({value:value,isEditing:isEditing,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=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:getStyles("null",nodeData),children:String(value)})},ObjectValue=({value:value,translate:translate,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{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",nodeData)}: "${String(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?"":String(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})},IconAdd=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4z"}),jsxRuntime.jsx("path",{d:"M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"})]}),IconEdit=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,transform:"translate(0, 0.5)",children:[jsxRuntime.jsx("path",{d:"M7 17.013l4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z"}),jsxRuntime.jsx("path",{d:"M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z"})]}),IconDelete=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M6 19a2 2 0 002 2h8a2 2 0 002-2V7H6v12m2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12M15.5 4l-1-1h-5l-1 1H5v2h14V4h-3.5z"})}),IconCopy=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M9 2 H15 A1 1 0 0 1 16 3 V5 A1 1 0 0 1 15 6 H9 A1 1 0 0 1 8 5 V3 A1 1 0 0 1 9 2 z"}),jsxRuntime.jsx("path",{d:"M8 4H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2v-2M16 4h2a2 2 0 012 2v4M21 14H11"}),jsxRuntime.jsx("path",{d:"M15 10l-4 4 4 4"})]}),IconOk=({size:size,style:style,className:className})=>jsxRuntime.jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsxRuntime.jsx("path",{d:"M22 11.08V12a10 10 0 11-5.93-9.14"}),jsxRuntime.jsx("path",{d:"M22 4L12 14.01l-3-3"})]}),IconCancel=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{baseProfile:"tiny",viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M12 4c-4.411 0-8 3.589-8 8s3.589 8 8 8 8-3.589 8-8-3.589-8-8-8zm-5 8c0-.832.224-1.604.584-2.295l6.711 6.711A4.943 4.943 0 0112 17c-2.757 0-5-2.243-5-5zm9.416 2.295L9.705 7.584A4.943 4.943 0 0112 7c2.757 0 5 2.243 5 5 0 .832-.224 1.604-.584 2.295z"})}),IconChevron=({size:size,style:style,className:className})=>jsxRuntime.jsx("svg",{viewBox:"0 0 512 512",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsxRuntime.jsx("path",{d:"M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})}),Icon=({name:name,nodeData:nodeData,rotate:rotate})=>{var _a,_b,_c,_d,_e,_f,_g;const{getStyles:getStyles,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(IconAdd,Object.assign({},commonProps,{style:getStyles("iconAdd",nodeData)}));case"edit":return null!==(_b=null==icons?void 0:icons.edit)&&void 0!==_b?_b:jsxRuntime.jsx(IconEdit,Object.assign({},commonProps,{style:getStyles("iconEdit",nodeData)}));case"delete":return null!==(_c=null==icons?void 0:icons.delete)&&void 0!==_c?_c:jsxRuntime.jsx(IconDelete,Object.assign({},commonProps,{style:getStyles("iconDelete",nodeData),size:"1.45em"}));case"copy":return null!==(_d=null==icons?void 0:icons.copy)&&void 0!==_d?_d:jsxRuntime.jsx(IconCopy,Object.assign({},commonProps,{style:getStyles("iconCopy",nodeData),size:"1.2em"}));case"ok":return null!==(_e=null==icons?void 0:icons.ok)&&void 0!==_e?_e:jsxRuntime.jsx(IconOk,Object.assign({},commonProps,{style:Object.assign({fontSize:"90%"},getStyles("iconOk",nodeData))}));case"cancel":return null!==(_f=null==icons?void 0:icons.cancel)&&void 0!==_f?_f:jsxRuntime.jsx(IconCancel,Object.assign({},commonProps,{style:Object.assign({fontSize:"130%"},getStyles("iconCancel",nodeData))}));case"chevron":return null!==(_g=null==icons?void 0:icons.chevron)&&void 0!==_g?_g:jsxRuntime.jsx(IconChevron,{className:"jer-accordion-icon"+(rotate?" jer-rotate-90":""),size:"1em",style:getStyles("iconCollection",nodeData)});default:return jsxRuntime.jsx(jsxRuntime.Fragment,{})}},EditButtons=({startEdit:startEdit,handleDelete:handleDelete,handleAdd:handleAdd,enableClipboard:enableClipboard,type:type,nodeData:nodeData,translate:translate})=>{const{getStyles:getStyles}=useTheme(),NEW_KEY_PROMPT=translate("KEY_NEW",nodeData),[isAdding,setIsAdding]=react.useState(!1),[newKey,setNewKey]=react.useState(NEW_KEY_PROMPT),{key:key,path:path,value:data}=nodeData;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:key,type:copyType})},className:"jer-copy-pulse",children:jsxRuntime.jsx(Icon,{name:"copy",nodeData:nodeData})}),startEdit&&jsxRuntime.jsx("div",{onClick:startEdit,children:jsxRuntime.jsx(Icon,{name:"edit",nodeData:nodeData})}),handleDelete&&jsxRuntime.jsx("div",{onClick:handleDelete,children:jsxRuntime.jsx(Icon,{name:"delete",nodeData:nodeData})}),handleAdd&&jsxRuntime.jsx("div",{onClick:()=>{"object"===type?setIsAdding(!0):handleAdd("")},children:jsxRuntime.jsx(Icon,{name:"add",nodeData:nodeData})}),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:getStyles("input",nodeData)}),jsxRuntime.jsx(InputButtons,{onOk:()=>{newKey&&(setIsAdding(!1),handleAdd(newKey))},onCancel:()=>{setIsAdding(!1)},nodeData:nodeData})]})]})},InputButtons=({onOk:onOk,onCancel:onCancel,nodeData:nodeData})=>jsxRuntime.jsxs("div",{className:"jer-confirm-buttons",children:[jsxRuntime.jsx("div",{onClick:onOk,children:jsxRuntime.jsx(Icon,{name:"ok",nodeData:nodeData})}),jsxRuntime.jsx("div",{onClick:onCancel,children:jsxRuntime.jsx(Icon,{name:"cancel",nodeData:nodeData})})]}),stringifyPath=path=>path.reduce(((str,part)=>"number"==typeof part?`${str}[${part}]`:""===str?part:`${str}.${part}`),""),DataTypes=["string","number","boolean","null","object","array"],getCustomNode=(customNodeDefinitions=[],nodeData)=>{const matchingDefinitions=customNodeDefinitions.filter((({condition:condition})=>condition(nodeData)));if(0===matchingDefinitions.length)return{};const _a=matchingDefinitions[0],{element:element,customNodeProps:customNodeProps,hideKey:hideKey=!1,showEditTools:showEditTools=!0,showOnEdit:showOnEdit=!1,showOnView:showOnView=!0,showCollectionWrapper:showCollectionWrapper=!0}=_a,rest=__rest(_a,["element","customNodeProps","hideKey","showEditTools","showOnEdit","showOnView","showCollectionWrapper"]);return Object.assign({CustomNode:element,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools,showOnEdit:showOnEdit,showOnView:showOnView,showCollectionWrapper:showCollectionWrapper},rest)},isCollection=value=>null!==value&&"object"==typeof value,filterNode=(type,nodeData,searchFilter,searchText="")=>{if(!searchFilter&&!searchText)return!0;switch(type){case"collection":if(searchFilter){if(searchFilter(nodeData,searchText))return!0;if(!filterCollection(searchText,nodeData,searchFilter))return!1}if(!searchFilter&&searchText&&!filterCollection(searchText,nodeData))return!1;break;case"value":if(searchFilter&&!searchFilter(nodeData,searchText))return!1;if(!searchFilter&&searchText&&!matchNode(nodeData,searchText))return!1}return!0},filterCollection=(searchText="",nodeData,matcher=matchNode)=>{const collection=nodeData.value;return Object.entries(collection).some((([key,value])=>{const childPath=[...nodeData.path,key],childNodeData=Object.assign(Object.assign({},nodeData),{key:key,path:childPath,level:nodeData.level+1,value:value,size:childPath.length,parentData:collection});return isCollection(value)?filterCollection(searchText,childNodeData,matcher):matcher(childNodeData,searchText)}))},matchNode=(nodeData,searchText="")=>{const{value:value}=nodeData;if(null===value&&"null".includes(searchText.toLowerCase()))return!0;switch(typeof value){case"string":return value.toLowerCase().includes(searchText.toLowerCase());case"number":return!!String(value).includes(searchText);case"boolean":return value?"true".includes(searchText.toLowerCase())||"1"===searchText:"false".includes(searchText.toLowerCase())||"0"===searchText;default:return!1}},matchNodeKey=({key:key,path:path},searchText="")=>!!matchNode({value:key},searchText)||!!path.some((field=>matchNode({value:field},searchText))),ValueNodeWrapper=props=>{const{data:data,parentData:parentData,nodeData:nodeData,onEdit:onEdit,onDelete:onDelete,enableClipboard:enableClipboard,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictTypeSelection:restrictTypeSelection,searchFilter:searchFilter,searchText:searchText,showLabel:showLabel,stringTruncate:stringTruncate,indent:indent,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,{getStyles:getStyles}=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),{key:name,path:path}=nodeData,customNodeData=getCustomNode(customNodeDefinitions,nodeData),[dataType,setDataType]=react.useState(getDataType(data,customNodeData));react.useEffect((()=>{setValue("function"==typeof data?"**INVALID_FUNCTION**":data),setDataType(getDataType(data,customNodeData))}),[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",nodeData)]: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,customNodeData))},canEdit=react.useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=react.useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),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,nodeData:nodeData,translate:translate},{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=customNodeData,allDataTypes=[...DataTypes,...customNodeDefinitions.filter((({showInTypesSelector:showInTypesSelector=!1,name:name})=>showInTypesSelector&&!!name)).map((({name:name})=>name))],allowedDataTypes=react.useMemo((()=>{if("boolean"==typeof restrictTypeSelection)return restrictTypeSelection?[]:allDataTypes;if(Array.isArray(restrictTypeSelection))return restrictTypeSelection;const result=restrictTypeSelection(nodeData);return"boolean"==typeof result?result?[]:allDataTypes:result}),[nodeData,restrictTypeSelection]);if(!filterNode("value",nodeData,searchFilter,searchText))return null;const ValueComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsxRuntime.jsx(CustomNode,Object.assign({},props,{value:value,customNodeProps:customNodeProps,setValue:setValue,handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:e=>{"Enter"===e.key?handleEdit():"Escape"===e.key&&handleCancel()},isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):getInputComponent(getDataType(data),inputProps);return 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&&!hideKey&&jsxRuntime.jsxs("label",{htmlFor:path.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},getStyles("property",nodeData)),{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:ValueComponent}),isEditing?jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData}):"invalid"!==dataType&&!error&&showEditTools&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>setIsEditing(!0):void 0,handleDelete:canDelete?()=>{onDelete(value,path).then((error=>{error&&logError(error)}))}:void 0,enableClipboard:enableClipboard,translate:translate,nodeData:nodeData}),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));if(customNode)onEdit(customNode.defaultValue,path),setDataType(type);else{const newValue=convertValue(value,type,translate("DEFAULT_NEW_KEY",nodeData),(null==customNodeData?void 0:customNodeData.CustomNode)?translate("DEFAULT_STRING",nodeData):void 0);setValue(newValue),onEdit(newValue,path),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:getStyles("error",nodeData),children:error})]})]})})},getDataType=(value,customNodeData)=>(null==customNodeData?void 0:customNodeData.CustomNode)&&(null==customNodeData?void 0:customNodeData.name)&&customNodeData.showInTypesSelector?customNodeData.name:"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,defaultNewKey,defaultString)=>{switch(type){case"string":return null!=defaultString?defaultString:String(value);case"number":{const n=Number(value);return isNaN(n)?0:n}case"boolean":return!!value;case"null":return null;case"object":return{[defaultNewKey]:value};case"array":return[value];default:return String(value)}},CollapseProviderContext=react.createContext({collapseState:null,setCollapseState:()=>{},doesPathMatch:()=>!1}),CollapseProvider=({children:children})=>{const[collapseState,setCollapseState]=react.useState(null);return jsxRuntime.jsx(CollapseProviderContext.Provider,{value:{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:path=>{if(null===collapseState)return!1;for(const[index,value]of collapseState.path.entries())if(value!==path[index])return!1;return!0}},children:children})},useCollapseAll=()=>react.useContext(CollapseProviderContext),CollectionNode=_a=>{var{data:data,nodeData:incomingNodeData,parentData:parentData,showCollectionCount:showCollectionCount}=_a,props=__rest(_a,["data","nodeData","parentData","showCollectionCount"]);const{getStyles:getStyles}=useTheme(),{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:doesPathMatch}=useCollapseAll(),{onEdit:onEdit,onAdd:onAdd,onDelete:onDelete,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,collapseFilter:collapseFilter,enableClipboard:enableClipboard,searchFilter:searchFilter,searchText:searchText,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),startCollapsed=collapseFilter(incomingNodeData),[collapsed,setCollapsed]=react.useState(startCollapsed),nodeData=Object.assign(Object.assign({},incomingNodeData),{collapsed:collapsed}),{path:path,key:name,size:size}=nodeData,hasBeenOpened=react.useRef(!startCollapsed),[isAnimating,setIsAnimating]=react.useState(!1);react.useEffect((()=>{setStringifiedValue(JSON.stringify(data,null,2))}),[data]),react.useEffect((()=>{setCollapsed(collapseFilter(nodeData))}),[collapseFilter]),react.useEffect((()=>{null!==collapseState&&doesPathMatch(path)&&(hasBeenOpened.current=!0,setCollapsed(collapseState.open))}),[collapseState]);const collectionType=Array.isArray(data)?"array":"object",brackets="array"===collectionType?{open:"[",close:"]"}:{open:"{",close:"}"},transitionTime=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),getDefaultNewValue=react.useMemo((()=>nodeData=>"function"!=typeof defaultValue?defaultValue:defaultValue(nodeData)),[defaultValue]),handleKeyPress=e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?handleEdit():"Escape"===e.key&&handleCancel()},showError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{try{const value=JSON5.parse(stringifiedValue);setIsEditing(!1),setError(null),onEdit(value,path).then((error=>{error&&showError(error)}))}catch(_a){setError(translate("ERROR_INVALID_JSON",nodeData)),setTimeout((()=>setError(null)),2500),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(nodeData)),[nodeData]),canDelete=react.useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),canAdd=react.useMemo((()=>!restrictAddFilter(nodeData)),[nodeData]),canEditKey=null!==parentData&&canEdit&&canAdd&&canDelete;if(!filterNode("collection",nodeData,searchFilter,searchText)&&nodeData.level>0)return null;const 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,CollectionChildren=hasBeenOpened.current?keyValueArray.map((([key,value],index)=>jsxRuntime.jsx("div",{className:"jer-collection-element",style:getStyles("collectionElement",nodeData),children:isCollection(value)?jsxRuntime.jsx(CollectionNode,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,index:index,parentData:data,size:Object.keys(value).length,fullData:nodeData.fullData},showCollectionCount:showCollectionCount},props),key):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,index:index,size:1,parentData:data,fullData:nodeData.fullData}},props,{showLabel:"object"===collectionType||showArrayIndices}),key)},key))):null,{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView,showCollectionWrapper:showCollectionWrapper=!0}=getCustomNode(customNodeDefinitions,nodeData),isCollapsed=!!showCollectionWrapper&&collapsed,CollectionContents=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsxRuntime.jsx(CustomNode,Object.assign({},props,{data:data,value:data,parentData:parentData,nodeData:nodeData,customNodeProps:customNodeProps,setValue:value=>onEdit(value,path),handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:handleKeyPress,isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles,children:CollectionChildren})):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,styles:getStyles("input",nodeData)}),jsxRuntime.jsx("div",{className:"jer-collection-input-button-row",children:jsxRuntime.jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData})})]})}):CollectionChildren,KeyDisplay=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"}}):jsxRuntime.jsx("span",{style:getStyles("property",nodeData),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:showLabel&&!hideKey&&""!==name&&void 0!==name?`${name}:`:null});return jsxRuntime.jsxs("div",{className:"jer-component jer-collection-component",style:Object.assign({marginLeft:(0===path.length?0:indent/2)+"em"},getStyles("collection",nodeData)),children:[showCollectionWrapper?jsxRuntime.jsxs("div",{className:"jer-collection-header-row",style:{position:"relative"},children:[jsxRuntime.jsxs("div",{className:"jer-collection-name",children:[jsxRuntime.jsx("div",{className:"jer-collapse-icon",onClick:e=>(e=>{if(e.getModifierState("Alt"))return hasBeenOpened.current=!0,void setCollapseState({open:!collapsed,path:path});isEditing||(setIsAnimating(!0),hasBeenOpened.current=!0,setCollapsed(!collapsed),setTimeout((()=>setIsAnimating(!1)),500))})(e),children:jsxRuntime.jsx(Icon,{name:"chevron",rotate:collapsed,nodeData:nodeData})}),KeyDisplay,!isEditing&&jsxRuntime.jsx("span",{className:"jer-brackets jer-bracket-open",style:getStyles("bracket",nodeData),children:brackets.open})]}),!isEditing&&showCount&&jsxRuntime.jsx("div",{className:"jer-collection-item-count"+(showCount?" jer-visible":" jer-hidden"),style:getStyles("itemCount",nodeData),children:1===size?translate("ITEM_SINGLE",Object.assign(Object.assign({},nodeData),{size:1}),1):translate("ITEMS_MULTIPLE",nodeData,size)}),jsxRuntime.jsx("div",{className:"jer-brackets"+(isCollapsed?" jer-visible":" jer-hidden"),style:getStyles("bracket",nodeData),children:brackets.close}),!isEditing&&showEditTools&&jsxRuntime.jsx(EditButtons,{startEdit:canEdit?()=>{setIsEditing(!0),setCollapsed(!1)}:void 0,handleAdd:canAdd?key=>{setCollapsed(!1);const newValue=getDefaultNewValue(nodeData);"array"===collectionType?onAdd(newValue,[...path,data.length]).then((error=>{error&&showError(error)})):key in data?showError(translate("ERROR_KEY_EXISTS",nodeData)):onAdd(newValue,[...path,key]).then((error=>{error&&showError(error)}))}:void 0,handleDelete:canDelete?handleDelete:void 0,enableClipboard:enableClipboard,type:collectionType,nodeData:nodeData,translate:translate})]}):hideKey?null:jsxRuntime.jsx("div",{className:"jer-collection-header-row",style:{position:"relative"},children:KeyDisplay}),jsxRuntime.jsxs("div",{className:"jer-collection-inner",style:Object.assign({maxHeight:isCollapsed?0:isEditing?void 0:3*numOfLines+"em",overflowY:isCollapsed||isAnimating?"hidden":"visible",transition:`max-height ${transitionTime}`},getStyles("collectionInner",nodeData)),children:[CollectionContents,jsxRuntime.jsx("div",{className:isEditing?"jer-collection-error-row":"jer-collection-error-row-edit",children:error&&jsxRuntime.jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})}),!isEditing&&showCollectionWrapper&&jsxRuntime.jsx("div",{className:"jer-brackets jer-bracket-outside",style:getStyles("bracket",nodeData),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,customText)=>(key,customTextData,count)=>((translations,customText,customTextData,key,count)=>{if(customText[key]){const output=customText[key](customTextData);if(null!==output)return output}const string=key in translations?translations[key]:localisedStrings[key];return void 0===count?string:null==string?void 0:string.replace("{{count}}",String(count))})(translations,customText,customTextData,key,count),Editor=({data:srcData,rootName:rootName="root",onUpdate:onUpdate=(()=>{}),onEdit:srcEdit=onUpdate,onDelete:srcDelete=onUpdate,onAdd:srcAdd=onUpdate,enableClipboard:enableClipboard=!0,theme:theme="default",icons:icons,indent:indent=3,collapse:collapse=!1,showCollectionCount:showCollectionCount=!0,restrictEdit:restrictEdit=!1,restrictDelete:restrictDelete=!1,restrictAdd:restrictAdd=!1,restrictTypeSelection:restrictTypeSelection=!1,searchFilter:searchFilterInput,searchText:searchText,searchDebounceTime:searchDebounceTime=350,keySort:keySort=!1,showArrayIndices:showArrayIndices=!0,defaultValue:defaultValue=null,minWidth:minWidth=250,maxWidth:maxWidth="min(600px, 90vw)",stringTruncate:stringTruncate=250,translations:translations={},className:className,customText:customText={},customNodeDefinitions:customNodeDefinitions=[]})=>{const{getStyles:getStyles,setTheme:setTheme,setIcons:setIcons}=useTheme(),{setCollapseState:setCollapseState}=useCollapseAll(),collapseFilter=react.useCallback(getFilterFunction(collapse),[collapse]),translate=react.useCallback(getTranslateFunction(translations,customText),[translations,customText]),[debouncedSearchText,setDebouncedSearchText]=react.useState(searchText),[data,setData]=react.useState(srcData);react.useEffect((()=>{theme&&setTheme(theme),icons&&setIcons(icons)}),[theme,icons]),react.useEffect((()=>{setCollapseState(null),setData(srcData)}),[srcData]),react.useEffect((()=>{const debounce=setTimeout((()=>setDebouncedSearchText(searchText)),searchDebounceTime);return()=>clearTimeout(debounce)}),[searchText,searchDebounceTime]);const nodeData={key:rootName,path:[],level:0,index:0,value:data,size:Object.keys(data).length,parentData:null,fullData:data},restrictEditFilter=getFilterFunction(restrictEdit),restrictDeleteFilter=getFilterFunction(restrictDelete),restrictAddFilter=getFilterFunction(restrictAdd),searchFilter=getSearchFilter(searchFilterInput),otherProps={name:rootName,nodeData:nodeData,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");setData(newData);const result=yield srcEdit({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcDelete({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcAdd({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):result})),showCollectionCount:showCollectionCount,collapseFilter:collapseFilter,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,restrictTypeSelection:restrictTypeSelection,searchFilter:searchFilter,searchText:debouncedSearchText,enableClipboard:enableClipboard,keySort:keySort,showArrayIndices:showArrayIndices,indent:indent,defaultValue:defaultValue,stringTruncate:stringTruncate,translate:translate,customNodeDefinitions:customNodeDefinitions,parentData:null};return jsxRuntime.jsx("div",{className:"jer-editor-container "+className,style:Object.assign(Object.assign({},getStyles("container",nodeData)),{minWidth:minWidth,maxWidth:maxWidth}),children:isCollection(data)?jsxRuntime.jsx(CollectionNode,Object.assign({data:data},otherProps)):jsxRuntime.jsx(ValueNodeWrapper,Object.assign({data:data,showLabel:!0},otherProps))})},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:"delete"!==action?newValue:void 0}},getFilterFunction=propValue=>"boolean"==typeof propValue?()=>propValue:"number"==typeof propValue?({level:level})=>level>=propValue:propValue,getSearchFilter=searchFilterInput=>{if(void 0!==searchFilterInput)return"value"===searchFilterInput?matchNode:"key"===searchFilterInput?matchNodeKey:"all"===searchFilterInput?(inputData,searchText)=>matchNode(inputData,searchText)||matchNodeKey(inputData,searchText):searchFilterInput},LinkCustomComponent=({value:value,setIsEditing:setIsEditing,getStyles:getStyles,customNodeProps:customNodeProps,nodeData:nodeData})=>{var _a,_b;const stringTruncateLength=null!==(_a=null==customNodeProps?void 0:customNodeProps.stringTruncate)&&void 0!==_a?_a:100,styles=getStyles("string",nodeData);return jsxRuntime.jsx("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string jer-hyperlink",style:styles,children:jsxRuntime.jsxs("a",{href:value,target:"_blank",rel:"noreferrer",style:{color:null!==(_b=styles.color)&&void 0!==_b?_b:void 0},children:['"',truncate(value,stringTruncateLength),'"']})})},LinkCustomNodeDefinition={condition:({value:value})=>"string"==typeof value&&/^https?:\/\/.+\..+$/.test(value),element:LinkCustomComponent,showOnView:!0,showOnEdit:!1};exports.assign=assign,exports.extract=extract,exports.IconAdd=IconAdd,exports.IconCancel=IconCancel,exports.IconChevron=IconChevron,exports.IconCopy=IconCopy,exports.IconDelete=IconDelete,exports.IconEdit=IconEdit,exports.IconOk=IconOk,exports.JsonEditor=props=>jsxRuntime.jsx(ThemeProvider,{children:jsxRuntime.jsx(CollapseProvider,{children:jsxRuntime.jsx(Editor,Object.assign({},props))})}),exports.LinkCustomComponent=LinkCustomComponent,exports.LinkCustomNodeDefinition=LinkCustomNodeDefinition,exports.breakString=breakString,exports.matchNode=matchNode,exports.matchNodeKey=matchNodeKey,exports.themes=themes,exports.truncate=truncate;
package/build/index.d.ts CHANGED
@@ -36,6 +36,9 @@ interface JsonEditorProps {
36
36
  restrictDelete?: boolean | FilterFunction;
37
37
  restrictAdd?: boolean | FilterFunction;
38
38
  restrictTypeSelection?: boolean | DataType[] | TypeFilterFunction;
39
+ searchText?: string;
40
+ searchFilter?: 'key' | 'value' | 'all' | SearchFilterFunction;
41
+ searchDebounceTime?: number;
39
42
  keySort?: boolean | CompareFunction;
40
43
  showArrayIndices?: boolean;
41
44
  defaultValue?: unknown;
@@ -71,6 +74,7 @@ type UpdateFunction = (props: {
71
74
  type FilterFunction = (input: NodeData) => boolean;
72
75
  type TypeFilterFunction = (input: NodeData) => boolean | DataType[];
73
76
  type CustomTextFunction = (input: NodeData) => string | null;
77
+ type SearchFilterFunction = (inputData: NodeData, searchText: string) => boolean;
74
78
  type CopyType = 'path' | 'value';
75
79
  type CopyFunction = (input: {
76
80
  key: CollectionKey;
@@ -85,9 +89,11 @@ interface NodeData {
85
89
  key: CollectionKey;
86
90
  path: CollectionKey[];
87
91
  level: number;
92
+ index: number;
88
93
  value: unknown;
89
94
  size: number | null;
90
95
  parentData: object | null;
96
+ fullData: object;
91
97
  collapsed?: boolean;
92
98
  }
93
99
  interface BaseNodeProps {
@@ -100,6 +106,8 @@ interface BaseNodeProps {
100
106
  restrictEditFilter: FilterFunction;
101
107
  restrictDeleteFilter: FilterFunction;
102
108
  restrictAddFilter: FilterFunction;
109
+ searchFilter?: SearchFilterFunction;
110
+ searchText?: string;
103
111
  restrictTypeSelection: boolean | DataType[] | TypeFilterFunction;
104
112
  stringTruncate: number;
105
113
  indent: number;
@@ -131,6 +139,7 @@ interface CustomNodeProps<T = Record<string, unknown>> extends BaseNodeProps {
131
139
  isEditing: boolean;
132
140
  setIsEditing: React.Dispatch<React.SetStateAction<boolean>>;
133
141
  getStyles: (element: ThemeableElement, nodeData: NodeData) => React.CSSProperties;
142
+ children?: JSX.Element[] | null;
134
143
  }
135
144
  interface CustomNodeDefinition<T = Record<string, unknown>> {
136
145
  condition: FilterFunction;
@@ -143,6 +152,7 @@ interface CustomNodeDefinition<T = Record<string, unknown>> {
143
152
  showOnEdit?: boolean;
144
153
  showOnView?: boolean;
145
154
  showEditTools?: boolean;
155
+ showCollectionWrapper?: boolean;
146
156
  }
147
157
  type CustomTextDefinitions = Partial<{
148
158
  [key in keyof LocalisedStrings]: CustomTextFunction;
@@ -186,4 +196,7 @@ declare const LinkCustomNodeDefinition: CustomNodeDefinition;
186
196
  declare const truncate: (string: string, length?: number) => string;
187
197
  declare const breakString: (text: string) => React$1.ReactElement[];
188
198
 
189
- export { CollectionNodeProps, CompareFunction, CopyFunction, CustomNodeDefinition, CustomNodeProps, CustomTextDefinitions, FilterFunction, IconAdd, IconCancel, IconChevron, IconCopy, IconDelete, IconEdit, IconOk, IconReplacements, JsonEditor, JsonEditorProps, LinkCustomComponent, LinkCustomNodeDefinition, LocalisedStrings, Theme, ThemeInput, ThemeName, TranslateFunction, UpdateFunction, ValueNodeProps, breakString, themes, truncate };
199
+ declare const matchNode: (input: Partial<NodeData>, searchText: string) => boolean;
200
+ declare const matchNodeKey: SearchFilterFunction;
201
+
202
+ export { CollectionNodeProps, CompareFunction, CopyFunction, CustomNodeDefinition, CustomNodeProps, CustomTextDefinitions, FilterFunction, IconAdd, IconCancel, IconChevron, IconCopy, IconDelete, IconEdit, IconOk, IconReplacements, JsonEditor, JsonEditorProps, LinkCustomComponent, LinkCustomNodeDefinition, LocalisedStrings, SearchFilterFunction, Theme, ThemeInput, ThemeName, TranslateFunction, UpdateFunction, ValueNodeProps, breakString, matchNode, matchNodeKey, themes, truncate };
@@ -1 +1 @@
1
- import{jsxs,jsx,Fragment}from"react/jsx-runtime";import{createContext,useState,useContext,useEffect,useMemo,useRef,useCallback}from"react";import assign from"object-property-assigner";export{default as assign}from"object-property-assigner";import extract from"object-property-extractor";export{default as extract}from"object-property-extractor";import JSON5 from"json5";import clone from"just-clone";function __rest(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}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 line-height: 1;\n padding: 1em;\n padding-left: 2em;\n /* margin-top: 1em; */\n /* margin-bottom: 1em; */\n border-radius: 0.5em;\n text-align: left;\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-bracket-outside {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collapse-icon {\n position: absolute;\n left: -1.2em;\n top: 0.35em;\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-hyperlink {\n text-decoration: underline;\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 AutogrowTextArea=({className:className,name:name,value:value,setValue:setValue,handleKeyPress:handleKeyPress,styles:styles})=>{const dummyValue="\n"===value.slice(-1)?value+".":value;return jsxs("div",{style:{display:"grid"},children:[jsx("textarea",{style:Object.assign({height:"auto",gridArea:"1 / 1 / 2 / 2",overflowY:"auto"},styles),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}),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),children:dummyValue})]})},themes={default:{displayName:"Default",fragments:{edit:"rgb(42, 161, 152)"},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},collection:{},collectionInner:{},collectionElement:{},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:{},collection:{},collectionInner:{},collectionElement:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},defaultTheme=themes.default,ThemeProviderContext=createContext({getStyles:()=>({}),setTheme:_=>{},icons:{},setIcons:()=>{}}),ThemeProvider=({children:children})=>{const[styles,setStyles]=useState(emptyStyleObject),[icons,setIcons]=useState({});return jsx(ThemeProviderContext.Provider,{value:{getStyles:(element,nodeData)=>"function"==typeof styles[element]?styles[element](nodeData):styles[element],setTheme:theme=>{const styles=compileStyles(theme);setStyles(styles)},icons:icons,setIcons:setIcons},children:children})},useTheme=()=>useContext(ThemeProviderContext),compileStyles=themeInput=>{var _a,_b,_c,_d;const collectedFunctions={},stylesArray=(Array.isArray(themeInput)?themeInput:[themeInput]).map((theme=>"default"===themeInput?{}:"string"==typeof theme?buildStyleObject(themes[theme],collectedFunctions):isStyleObject(theme)?buildStyleObject({fragments:{},styles:theme},collectedFunctions):buildStyleObject(theme,collectedFunctions))),mergedStyleObject=buildStyleObject(defaultTheme,{});Object.keys(mergedStyleObject).forEach((k=>{const key=k;stylesArray.forEach((styleObj=>{styleObj[key]&&(mergedStyleObject[key]=Object.assign(Object.assign({},mergedStyleObject[key]),styleObj[key]))}))}));const finalStyles=Object.assign({},mergedStyleObject);return Object.entries(collectedFunctions).forEach((([key,func])=>{const element=key;finalStyles[element]=nodeData=>{const funcResult=func(nodeData)||{};return Object.assign(Object.assign({},mergedStyleObject[element]),funcResult)}})),"function"!=typeof(null==finalStyles?void 0:finalStyles.inputHighlight)&&(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),"function"!=typeof(null==finalStyles?void 0:finalStyles.iconCopy)&&(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},buildStyleObject=(theme,collectedFunctions)=>{const{fragments:fragments,styles:styles}=theme,styleObject={};return Object.entries(styles).forEach((([key,value])=>{const cssStyles=(Array.isArray(value)?value:[value]).reduce(((acc,curr)=>{var _a;if("function"==typeof curr)return collectedFunctions[key]=curr,Object.assign({},acc);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)}),{});styleObject[key]=cssStyles})),styleObject},isStyleObject=overrideObject=>!("styles"in overrideObject),defaultStyleProperties={container:"backgroundColor",collection:"backgroundColor",collectionInner:"backgroundColor",collectionElement:"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"},truncate=(string,length=200)=>string.length<length?string:`${string.slice(0,length-2).trim()}...`,breakString=text=>text.split("\n").map(((line,index,arr)=>{const match=/^( +)/.exec(line);return jsxs("span",{children:[match?match[0].split("").map((()=>jsx(Fragment,{children:" "}))):null,line,index<arr.length-1?jsx("br",{}):null]},index)})),StringValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,stringTruncate:stringTruncate,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();return isEditing?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()},styles:getStyles("input",nodeData)}):jsxs("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string",style:getStyles("string",nodeData),children:['"',breakString(truncate(value,stringTruncate)),'"']})},NumberValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();return isEditing?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"}}):jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-number",style:getStyles("number",nodeData),children:value})},BooleanValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing,handleEdit]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return isEditing?jsx("input",{className:"jer-input-boolean",type:"checkbox",name:path.join("."),checked:value,onChange:()=>setValue(!value)}):jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-boolean",style:getStyles("boolean",nodeData),children:String(value)})},NullValue=({value:value,isEditing:isEditing,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("div",isEditing?{className:"jer-input-null",children:"null"}:{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-null",style:getStyles("null",nodeData),children:String(value)})},ObjectValue=({value:value,translate:translate,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("span",{className:"jer-value-object",children:`{${translate("DEFAULT_NEW_KEY",nodeData)}: "${String(value)}" }`})},ArrayValue=({value:value,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("span",{className:"jer-value-array",children:`[${null===value?"":String(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 jsx("span",{className:"jer-value-invalid",children:message})},IconAdd=({size:size,style:style,className:className})=>jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4z"}),jsx("path",{d:"M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"})]}),IconEdit=({size:size,style:style,className:className})=>jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M7 17.013l4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z"}),jsx("path",{d:"M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z"})]}),IconDelete=({size:size,style:style,className:className})=>jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M6 19a2 2 0 002 2h8a2 2 0 002-2V7H6v12m2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12M15.5 4l-1-1h-5l-1 1H5v2h14V4h-3.5z"})}),IconCopy=({size:size,style:style,className:className})=>jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M9 2 H15 A1 1 0 0 1 16 3 V5 A1 1 0 0 1 15 6 H9 A1 1 0 0 1 8 5 V3 A1 1 0 0 1 9 2 z"}),jsx("path",{d:"M8 4H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2v-2M16 4h2a2 2 0 012 2v4M21 14H11"}),jsx("path",{d:"M15 10l-4 4 4 4"})]}),IconOk=({size:size,style:style,className:className})=>jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M22 11.08V12a10 10 0 11-5.93-9.14"}),jsx("path",{d:"M22 4L12 14.01l-3-3"})]}),IconCancel=({size:size,style:style,className:className})=>jsx("svg",{baseProfile:"tiny",viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M12 4c-4.411 0-8 3.589-8 8s3.589 8 8 8 8-3.589 8-8-3.589-8-8-8zm-5 8c0-.832.224-1.604.584-2.295l6.711 6.711A4.943 4.943 0 0112 17c-2.757 0-5-2.243-5-5zm9.416 2.295L9.705 7.584A4.943 4.943 0 0112 7c2.757 0 5 2.243 5 5 0 .832-.224 1.604-.584 2.295z"})}),IconChevron=({size:size,style:style,className:className})=>jsx("svg",{viewBox:"0 0 512 512",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})}),Icon=({name:name,nodeData:nodeData,rotate:rotate})=>{var _a,_b,_c,_d,_e,_f,_g;const{getStyles:getStyles,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:jsx(IconAdd,Object.assign({},commonProps,{style:getStyles("iconAdd",nodeData)}));case"edit":return null!==(_b=null==icons?void 0:icons.edit)&&void 0!==_b?_b:jsx(IconEdit,Object.assign({},commonProps,{style:getStyles("iconEdit",nodeData)}));case"delete":return null!==(_c=null==icons?void 0:icons.delete)&&void 0!==_c?_c:jsx(IconDelete,Object.assign({},commonProps,{style:getStyles("iconDelete",nodeData),size:"1.5em"}));case"copy":return null!==(_d=null==icons?void 0:icons.copy)&&void 0!==_d?_d:jsx(IconCopy,Object.assign({},commonProps,{style:getStyles("iconCopy",nodeData),size:"1.2em"}));case"ok":return null!==(_e=null==icons?void 0:icons.ok)&&void 0!==_e?_e:jsx(IconOk,Object.assign({},commonProps,{style:Object.assign({fontSize:"90%"},getStyles("iconOk",nodeData))}));case"cancel":return null!==(_f=null==icons?void 0:icons.cancel)&&void 0!==_f?_f:jsx(IconCancel,Object.assign({},commonProps,{style:Object.assign({fontSize:"130%"},getStyles("iconCancel",nodeData))}));case"chevron":return null!==(_g=null==icons?void 0:icons.chevron)&&void 0!==_g?_g:jsx(IconChevron,{className:"jer-accordion-icon"+(rotate?" jer-rotate-90":""),size:"1em",style:getStyles("iconCollection",nodeData)});default:return jsx(Fragment,{})}},EditButtons=({startEdit:startEdit,handleDelete:handleDelete,handleAdd:handleAdd,enableClipboard:enableClipboard,type:type,nodeData:nodeData,translate:translate})=>{const{getStyles:getStyles}=useTheme(),NEW_KEY_PROMPT=translate("KEY_NEW",nodeData),[isAdding,setIsAdding]=useState(!1),[newKey,setNewKey]=useState(NEW_KEY_PROMPT),{key:key,path:path,value:data}=nodeData;useEffect((()=>{isAdding||setNewKey(NEW_KEY_PROMPT)}),[isAdding]);return jsxs("div",{className:"jer-edit-buttons",style:isAdding?{opacity:1}:void 0,children:[enableClipboard&&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:key,type:copyType})},className:"jer-copy-pulse",children:jsx(Icon,{name:"copy",nodeData:nodeData})}),startEdit&&jsx("div",{onClick:startEdit,children:jsx(Icon,{name:"edit",nodeData:nodeData})}),handleDelete&&jsx("div",{onClick:handleDelete,children:jsx(Icon,{name:"delete",nodeData:nodeData})}),handleAdd&&jsx("div",{onClick:()=>{"object"===type?setIsAdding(!0):handleAdd("")},children:jsx(Icon,{name:"add",nodeData:nodeData})}),isAdding&&handleAdd&&"object"===type&&jsxs(Fragment,{children:[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:getStyles("input",nodeData)}),jsx(InputButtons,{onOk:()=>{newKey&&(setIsAdding(!1),handleAdd(newKey))},onCancel:()=>{setIsAdding(!1)},nodeData:nodeData})]})]})},InputButtons=({onOk:onOk,onCancel:onCancel,nodeData:nodeData})=>jsxs("div",{className:"jer-confirm-buttons",children:[jsx("div",{onClick:onOk,children:jsx(Icon,{name:"ok",nodeData:nodeData})}),jsx("div",{onClick:onCancel,children:jsx(Icon,{name:"cancel",nodeData:nodeData})})]}),stringifyPath=path=>path.reduce(((str,part)=>"number"==typeof part?`${str}[${part}]`:""===str?part:`${str}.${part}`),""),DataTypes=["string","number","boolean","null","object","array"],getCustomNode=(customNodeDefinitions=[],nodeData)=>{const matchingDefinitions=customNodeDefinitions.filter((({condition:condition})=>condition(nodeData)));if(0===matchingDefinitions.length)return{};const _a=matchingDefinitions[0],{element:element,customNodeProps:customNodeProps,hideKey:hideKey=!1,showEditTools:showEditTools=!0,showOnEdit:showOnEdit=!1,showOnView:showOnView=!0}=_a,rest=__rest(_a,["element","customNodeProps","hideKey","showEditTools","showOnEdit","showOnView"]);return Object.assign({CustomNode:element,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools,showOnEdit:showOnEdit,showOnView:showOnView},rest)},ValueNodeWrapper=props=>{const{data:data,parentData:parentData,nodeData:nodeData,onEdit:onEdit,onDelete:onDelete,enableClipboard:enableClipboard,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictTypeSelection:restrictTypeSelection,showLabel:showLabel,stringTruncate:stringTruncate,indent:indent,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,{getStyles:getStyles}=useTheme(),[isEditing,setIsEditing]=useState(!1),[isEditingKey,setIsEditingKey]=useState(!1),[value,setValue]=useState("function"==typeof data?"**INVALID_FUNCTION**":data),[error,setError]=useState(null),{key:name,path:path}=nodeData,customNodeData=getCustomNode(customNodeDefinitions,nodeData),[dataType,setDataType]=useState(getDataType(data,customNodeData));useEffect((()=>{setValue("function"==typeof data?"**INVALID_FUNCTION**":data),setDataType(getDataType(data,customNodeData))}),[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",nodeData)]: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,customNodeData))},canEdit=useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),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,nodeData:nodeData,translate:translate},{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=customNodeData,allDataTypes=[...DataTypes,...customNodeDefinitions.filter((({showInTypesSelector:showInTypesSelector=!1,name:name})=>showInTypesSelector&&!!name)).map((({name:name})=>name))],allowedDataTypes=useMemo((()=>{if("boolean"==typeof restrictTypeSelection)return restrictTypeSelection?[]:allDataTypes;if(Array.isArray(restrictTypeSelection))return restrictTypeSelection;const result=restrictTypeSelection(nodeData);return"boolean"==typeof result?result?[]:allDataTypes:result}),[nodeData,restrictTypeSelection]),ValueComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsx(CustomNode,Object.assign({},props,{value:value,customNodeProps:customNodeProps,setValue:setValue,handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:e=>{"Enter"===e.key?handleEdit():"Escape"===e.key&&handleCancel()},isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):getInputComponent(getDataType(data),inputProps);return jsx("div",{className:"jer-component jer-value-component",style:{marginLeft:indent/2+"em"},children:jsxs("div",{className:"jer-value-main-row",style:{flexWrap:name.length>10?"wrap":"nowrap"},children:[showLabel&&!isEditingKey&&!hideKey&&jsxs("label",{htmlFor:path.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},getStyles("property",nodeData)),{minWidth:`${Math.min(String(name).length+1,5)}ch`,flexShrink:name.length>10?1:0}),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:[name,":"," "]}),showLabel&&isEditingKey&&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"}}),jsxs("div",{className:"jer-value-and-buttons",children:[jsx("div",{className:"jer-input-component",children:ValueComponent}),isEditing?jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData}):"invalid"!==dataType&&!error&&showEditTools&&jsx(EditButtons,{startEdit:canEdit?()=>setIsEditing(!0):void 0,handleDelete:canDelete?()=>{onDelete(value,path).then((error=>{error&&logError(error)}))}:void 0,enableClipboard:enableClipboard,translate:translate,nodeData:nodeData}),isEditing&&allowedDataTypes.length>0&&jsxs("div",{className:"jer-select",children:[jsx("select",{name:`${name}-type-select`,className:"jer-type-select",onChange:e=>(type=>{const customNode=customNodeDefinitions.find((customNode=>customNode.name===type));if(customNode)onEdit(customNode.defaultValue,path),setDataType(type);else{const newValue=convertValue(value,type,translate("DEFAULT_NEW_KEY",nodeData),(null==customNodeData?void 0:customNodeData.CustomNode)?translate("DEFAULT_STRING",nodeData):void 0);setValue(newValue),onEdit(newValue,path),setDataType(type)}})(e.target.value),value:dataType,children:allowedDataTypes.map((type=>jsx("option",{value:type,children:type},type)))}),jsx("span",{className:"focus"})]}),!isEditing&&error&&jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})]})]})})},getDataType=(value,customNodeData)=>(null==customNodeData?void 0:customNodeData.CustomNode)&&(null==customNodeData?void 0:customNodeData.name)&&customNodeData.showInTypesSelector?customNodeData.name:"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 jsx(StringValue,Object.assign({},inputProps,{value:value}));case"number":return jsx(NumberValue,Object.assign({},inputProps,{value:value}));case"boolean":return jsx(BooleanValue,Object.assign({},inputProps,{value:value}));case"null":return jsx(NullValue,Object.assign({},inputProps));case"object":return jsx(ObjectValue,Object.assign({},inputProps,{value:value}));case"array":return jsx(ArrayValue,Object.assign({},inputProps));default:return jsx(InvalidValue,Object.assign({},inputProps))}},convertValue=(value,type,defaultNewKey,defaultString)=>{switch(type){case"string":return null!=defaultString?defaultString:String(value);case"number":{const n=Number(value);return isNaN(n)?0:n}case"boolean":return!!value;case"null":return null;case"object":return{[defaultNewKey]:value};case"array":return[value];default:return String(value)}},CollapseProviderContext=createContext({collapseState:null,setCollapseState:()=>{},doesPathMatch:()=>!1}),CollapseProvider=({children:children})=>{const[collapseState,setCollapseState]=useState(null);return jsx(CollapseProviderContext.Provider,{value:{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:path=>{if(null===collapseState)return!1;for(const[index,value]of collapseState.path.entries())if(value!==path[index])return!1;return!0}},children:children})},useCollapseAll=()=>useContext(CollapseProviderContext),isCollection=value=>null!==value&&"object"==typeof value,CollectionNode=_a=>{var{data:data,nodeData:incomingNodeData,parentData:parentData,showCollectionCount:showCollectionCount}=_a,props=__rest(_a,["data","nodeData","parentData","showCollectionCount"]);const{getStyles:getStyles}=useTheme(),{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:doesPathMatch}=useCollapseAll(),{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]=useState(!1),[isEditingKey,setIsEditingKey]=useState(!1),[stringifiedValue,setStringifiedValue]=useState(JSON.stringify(data,null,2)),[error,setError]=useState(null),startCollapsed=collapseFilter(incomingNodeData),[collapsed,setCollapsed]=useState(startCollapsed),nodeData=Object.assign(Object.assign({},incomingNodeData),{collapsed:collapsed}),{path:path,key:name,size:size}=nodeData,hasBeenOpened=useRef(!startCollapsed),[isAnimating,setIsAnimating]=useState(!1);useEffect((()=>{setStringifiedValue(JSON.stringify(data,null,2))}),[data]),useEffect((()=>{setCollapsed(collapseFilter(nodeData))}),[collapseFilter]),useEffect((()=>{null!==collapseState&&doesPathMatch(path)&&(hasBeenOpened.current=!0,setCollapsed(collapseState.open))}),[collapseState]);const collectionType=Array.isArray(data)?"array":"object",brackets="array"===collectionType?{open:"[",close:"]"}:{open:"{",close:"}"},transitionTime=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),getDefaultNewValue=useMemo((()=>nodeData=>"function"!=typeof defaultValue?defaultValue:defaultValue(nodeData)),[defaultValue]),handleKeyPress=e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?handleEdit():"Escape"===e.key&&handleCancel()},showError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{try{const value=JSON5.parse(stringifiedValue);setIsEditing(!1),setError(null),onEdit(value,path).then((error=>{error&&showError(error)}))}catch(_a){setError(translate("ERROR_INVALID_JSON",nodeData)),setTimeout((()=>setError(null)),2500),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=useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),canAdd=useMemo((()=>!restrictAddFilter(nodeData)),[nodeData]),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,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=getCustomNode(customNodeDefinitions,nodeData),CollectionComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsx(CustomNode,Object.assign({},props,{data:data,value:data,parentData:parentData,nodeData:nodeData,customNodeProps:customNodeProps,setValue:value=>onEdit(value,path),handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:handleKeyPress,isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):isEditing?jsx("div",{className:"jer-collection-text-edit",children:jsxs("div",{children:[jsx(AutogrowTextArea,{className:"jer-collection-text-area",name:path.join("."),value:stringifiedValue,setValue:setStringifiedValue,isEditing:isEditing,handleKeyPress:handleKeyPress,styles:getStyles("input",nodeData)}),jsx("div",{className:"jer-collection-input-button-row",children:jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData})})]})}):hasBeenOpened.current?keyValueArray.map((([key,value])=>jsx("div",{className:"jer-collection-element",style:getStyles("collectionElement",nodeData),children:isCollection(value)?jsx(CollectionNode,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,parentData:data,size:Object.keys(value).length},showCollectionCount:showCollectionCount},props),key):jsx(ValueNodeWrapper,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,size:1,parentData:data}},props,{showLabel:"object"===collectionType||showArrayIndices}),key)},key))):null;return jsxs("div",{className:"jer-component jer-collection-component",style:Object.assign({marginLeft:(0===path.length?0:indent/2)+"em"},getStyles("collection",nodeData)),children:[jsxs("div",{className:"jer-collection-header-row",style:{position:"relative"},children:[jsxs("div",{className:"jer-collection-name",children:[jsx("div",{className:"jer-collapse-icon",onClick:e=>(e=>{if(e.getModifierState("Alt"))return hasBeenOpened.current=!0,void setCollapseState({open:!collapsed,path:path});isEditing||(setIsAnimating(!0),hasBeenOpened.current=!0,setCollapsed(!collapsed),setTimeout((()=>setIsAnimating(!1)),500))})(e),children:jsx(Icon,{name:"chevron",rotate:collapsed,nodeData:nodeData})}),!isEditingKey&&jsx("span",{style:getStyles("property",nodeData),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:showLabel&&!hideKey&&""!==name&&void 0!==name?`${name}:`:null}),isEditingKey&&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&&jsx("span",{className:"jer-brackets jer-bracket-open",style:getStyles("bracket",nodeData),children:brackets.open})]}),!isEditing&&showCount&&jsx("div",{className:"jer-collection-item-count"+(showCount?" jer-visible":" jer-hidden"),style:getStyles("itemCount",nodeData),children:1===size?translate("ITEM_SINGLE",Object.assign(Object.assign({},nodeData),{size:1}),1):translate("ITEMS_MULTIPLE",nodeData,size)}),jsx("div",{className:"jer-brackets"+(collapsed?" jer-visible":" jer-hidden"),style:getStyles("bracket",nodeData),children:brackets.close}),!isEditing&&showEditTools&&jsx(EditButtons,{startEdit:canEdit?()=>{setIsEditing(!0),setCollapsed(!1)}:void 0,handleAdd:canAdd?key=>{setCollapsed(!1);const newValue=getDefaultNewValue(nodeData);"array"===collectionType?onAdd(newValue,[...path,data.length]).then((error=>{error&&showError(error)})):key in data?showError(translate("ERROR_KEY_EXISTS",nodeData)):onAdd(newValue,[...path,key]).then((error=>{error&&showError(error)}))}:void 0,handleDelete:canDelete?handleDelete:void 0,enableClipboard:enableClipboard,type:collectionType,nodeData:nodeData,translate:translate})]}),jsxs("div",{className:"jer-collection-inner",style:Object.assign({maxHeight:collapsed?0:isEditing?void 0:3*numOfLines+"em",overflowY:collapsed||isAnimating?"hidden":"visible",transition:`max-height ${transitionTime}`},getStyles("collectionInner",nodeData)),children:[CollectionComponent,jsx("div",{className:isEditing?"jer-collection-error-row":"jer-collection-error-row-edit",children:error&&jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})}),!isEditing&&jsx("div",{className:"jer-brackets jer-bracket-outside",style:getStyles("bracket",nodeData),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,customText)=>(key,customTextData,count)=>((translations,customText,customTextData,key,count)=>{if(customText[key]){const output=customText[key](customTextData);if(null!==output)return output}const string=key in translations?translations[key]:localisedStrings[key];return void 0===count?string:null==string?void 0:string.replace("{{count}}",String(count))})(translations,customText,customTextData,key,count),Editor=({data:srcData,rootName:rootName="root",onUpdate:onUpdate=(()=>{}),onEdit:srcEdit=onUpdate,onDelete:srcDelete=onUpdate,onAdd:srcAdd=onUpdate,enableClipboard:enableClipboard=!0,theme:theme="default",icons:icons,indent:indent=3,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,customText:customText={},customNodeDefinitions:customNodeDefinitions=[]})=>{const{getStyles:getStyles,setTheme:setTheme,setIcons:setIcons}=useTheme(),{setCollapseState:setCollapseState}=useCollapseAll(),collapseFilter=useCallback(getFilterFunction(collapse),[collapse]),translate=useCallback(getTranslateFunction(translations,customText),[translations,customText]),[data,setData]=useState(srcData);useEffect((()=>{theme&&setTheme(theme),icons&&setIcons(icons)}),[theme,icons]),useEffect((()=>{setCollapseState(null),setData(srcData)}),[srcData]);const nodeData={key:rootName,path:[],level:0,value:data,size:Object.keys(data).length,parentData:null},restrictEditFilter=getFilterFunction(restrictEdit),restrictDeleteFilter=getFilterFunction(restrictDelete),restrictAddFilter=getFilterFunction(restrictAdd),otherProps={name:rootName,nodeData:nodeData,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");setData(newData);const result=yield srcEdit({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcDelete({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcAdd({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):result})),showCollectionCount:showCollectionCount,collapseFilter:collapseFilter,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,restrictTypeSelection:restrictTypeSelection,enableClipboard:enableClipboard,keySort:keySort,showArrayIndices:showArrayIndices,indent:indent,defaultValue:defaultValue,stringTruncate:stringTruncate,translate:translate,customNodeDefinitions:customNodeDefinitions,parentData:null};return jsx("div",{className:"jer-editor-container "+className,style:Object.assign(Object.assign({},getStyles("container",nodeData)),{minWidth:minWidth,maxWidth:maxWidth}),children:isCollection(data)?jsx(CollectionNode,Object.assign({data:data},otherProps)):jsx(ValueNodeWrapper,Object.assign({data:data,showLabel:!0},otherProps))})},JsonEditor=props=>jsx(ThemeProvider,{children:jsx(CollapseProvider,{children:jsx(Editor,Object.assign({},props))})}),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:"delete"!==action?newValue:void 0}},getFilterFunction=propValue=>"boolean"==typeof propValue?()=>propValue:"number"==typeof propValue?({level:level})=>level>=propValue:propValue,LinkCustomComponent=({value:value,setIsEditing:setIsEditing,getStyles:getStyles,customNodeProps:customNodeProps,nodeData:nodeData})=>{var _a,_b;const stringTruncateLength=null!==(_a=null==customNodeProps?void 0:customNodeProps.stringTruncate)&&void 0!==_a?_a:100,styles=getStyles("string",nodeData);return jsx("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string jer-hyperlink",style:styles,children:jsxs("a",{href:value,target:"_blank",rel:"noreferrer",style:{color:null!==(_b=styles.color)&&void 0!==_b?_b:void 0},children:['"',truncate(value,stringTruncateLength),'"']})})},LinkCustomNodeDefinition={condition:({value:value})=>"string"==typeof value&&/^https?:\/\/.+\..+$/.test(value),element:LinkCustomComponent,showOnView:!0,showOnEdit:!1};export{IconAdd,IconCancel,IconChevron,IconCopy,IconDelete,IconEdit,IconOk,JsonEditor,LinkCustomComponent,LinkCustomNodeDefinition,breakString,themes,truncate};
1
+ import{jsxs,jsx,Fragment}from"react/jsx-runtime";import{createContext,useState,useContext,useEffect,useMemo,useRef,useCallback}from"react";import assign from"object-property-assigner";export{default as assign}from"object-property-assigner";import extract from"object-property-extractor";export{default as extract}from"object-property-extractor";import JSON5 from"json5";import clone from"just-clone";function __rest(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}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 line-height: 1;\n padding: 1em;\n padding-left: 2em;\n /* margin-top: 1em; */\n /* margin-bottom: 1em; */\n border-radius: 0.5em;\n text-align: left;\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-bracket-outside {\n}\n\n.jer-collection-item-count {\n}\n\n.jer-collapse-icon {\n position: absolute;\n left: -1.2em;\n top: 0.35em;\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-hyperlink {\n text-decoration: underline;\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 AutogrowTextArea=({className:className,name:name,value:value,setValue:setValue,handleKeyPress:handleKeyPress,styles:styles})=>{const dummyValue="\n"===value.slice(-1)?value+".":value;return jsxs("div",{style:{display:"grid"},children:[jsx("textarea",{style:Object.assign({height:"auto",gridArea:"1 / 1 / 2 / 2",overflowY:"auto"},styles),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}),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),children:dummyValue})]})},themes={default:{displayName:"Default",fragments:{edit:"rgb(42, 161, 152)"},styles:{container:{backgroundColor:"#f6f6f6",fontFamily:"monospace"},collection:{},collectionInner:{},collectionElement:{},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:{},collection:{},collectionInner:{},collectionElement:{},property:{},bracket:{},itemCount:{},string:{},number:{},boolean:{},null:{},input:{},inputHighlight:{},error:{},iconCollection:{},iconEdit:{},iconDelete:{},iconAdd:{},iconCopy:{},iconOk:{},iconCancel:{}},defaultTheme=themes.default,ThemeProviderContext=createContext({getStyles:()=>({}),setTheme:_=>{},icons:{},setIcons:()=>{}}),ThemeProvider=({children:children})=>{const[styles,setStyles]=useState(emptyStyleObject),[icons,setIcons]=useState({});return jsx(ThemeProviderContext.Provider,{value:{getStyles:(element,nodeData)=>"function"==typeof styles[element]?styles[element](nodeData):styles[element],setTheme:theme=>{const styles=compileStyles(theme);setStyles(styles)},icons:icons,setIcons:setIcons},children:children})},useTheme=()=>useContext(ThemeProviderContext),compileStyles=themeInput=>{var _a,_b,_c,_d;const collectedFunctions={},stylesArray=(Array.isArray(themeInput)?themeInput:[themeInput]).map((theme=>"default"===themeInput?{}:"string"==typeof theme?buildStyleObject(themes[theme],collectedFunctions):isStyleObject(theme)?buildStyleObject({fragments:{},styles:theme},collectedFunctions):buildStyleObject(theme,collectedFunctions))),mergedStyleObject=buildStyleObject(defaultTheme,{});Object.keys(mergedStyleObject).forEach((k=>{const key=k;stylesArray.forEach((styleObj=>{styleObj[key]&&(mergedStyleObject[key]=Object.assign(Object.assign({},mergedStyleObject[key]),styleObj[key]))}))}));const finalStyles=Object.assign({},mergedStyleObject);return Object.entries(collectedFunctions).forEach((([key,func])=>{const element=key;finalStyles[element]=nodeData=>{const funcResult=func(nodeData)||{};return Object.assign(Object.assign({},mergedStyleObject[element]),funcResult)}})),"function"!=typeof(null==finalStyles?void 0:finalStyles.inputHighlight)&&(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),"function"!=typeof(null==finalStyles?void 0:finalStyles.iconCopy)&&(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},buildStyleObject=(theme,collectedFunctions)=>{const{fragments:fragments,styles:styles}=theme,styleObject={};return Object.entries(styles).forEach((([key,value])=>{const cssStyles=(Array.isArray(value)?value:[value]).reduce(((acc,curr)=>{var _a;if("function"==typeof curr)return collectedFunctions[key]=curr,Object.assign({},acc);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)}),{});styleObject[key]=cssStyles})),styleObject},isStyleObject=overrideObject=>!("styles"in overrideObject),defaultStyleProperties={container:"backgroundColor",collection:"backgroundColor",collectionInner:"backgroundColor",collectionElement:"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"},truncate=(string,length=200)=>string.length<length?string:`${string.slice(0,length-2).trim()}...`,breakString=text=>text.split("\n").map(((line,index,arr)=>{const match=/^( +)/.exec(line);return jsxs("span",{children:[match?match[0].split("").map((()=>jsx(Fragment,{children:" "}))):null,line,index<arr.length-1?jsx("br",{}):null]},index)})),StringValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,stringTruncate:stringTruncate,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();return isEditing?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()},styles:getStyles("input",nodeData)}):jsxs("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string",style:getStyles("string",nodeData),children:['"',breakString(truncate(value,stringTruncate)),'"']})},NumberValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();return isEditing?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"}}):jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-number",style:getStyles("number",nodeData),children:value})},BooleanValue=({value:value,setValue:setValue,isEditing:isEditing,path:path,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing,handleEdit]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return isEditing?jsx("input",{className:"jer-input-boolean",type:"checkbox",name:path.join("."),checked:value,onChange:()=>setValue(!value)}):jsx("span",{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-boolean",style:getStyles("boolean",nodeData),children:String(value)})},NullValue=({value:value,isEditing:isEditing,setIsEditing:setIsEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{const{getStyles:getStyles}=useTheme();useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[isEditing]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("div",isEditing?{className:"jer-input-null",children:"null"}:{onDoubleClick:()=>setIsEditing(!0),className:"jer-value-null",style:getStyles("null",nodeData),children:String(value)})},ObjectValue=({value:value,translate:translate,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel,nodeData:nodeData})=>{useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("span",{className:"jer-value-object",children:`{${translate("DEFAULT_NEW_KEY",nodeData)}: "${String(value)}" }`})},ArrayValue=({value:value,isEditing:isEditing,handleEdit:handleEdit,handleCancel:handleCancel})=>{useEffect((()=>(isEditing&&document.addEventListener("keydown",listenForSubmit),()=>document.removeEventListener("keydown",listenForSubmit))),[]);const listenForSubmit=event=>{"Enter"===event.key?handleEdit():"Escape"===event.key&&handleCancel()};return jsx("span",{className:"jer-value-array",children:`[${null===value?"":String(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 jsx("span",{className:"jer-value-invalid",children:message})},IconAdd=({size:size,style:style,className:className})=>jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M13 7h-2v4H7v2h4v4h2v-4h4v-2h-4z"}),jsx("path",{d:"M12 2C6.486 2 2 6.486 2 12s4.486 10 10 10 10-4.486 10-10S17.514 2 12 2zm0 18c-4.411 0-8-3.589-8-8s3.589-8 8-8 8 3.589 8 8-3.589 8-8 8z"})]}),IconEdit=({size:size,style:style,className:className})=>jsxs("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,transform:"translate(0, 0.5)",children:[jsx("path",{d:"M7 17.013l4.413-.015 9.632-9.54c.378-.378.586-.88.586-1.414s-.208-1.036-.586-1.414l-1.586-1.586c-.756-.756-2.075-.752-2.825-.003L7 12.583v4.43zM18.045 4.458l1.589 1.583-1.597 1.582-1.586-1.585 1.594-1.58zM9 13.417l6.03-5.973 1.586 1.586-6.029 5.971L9 15.006v-1.589z"}),jsx("path",{d:"M5 21h14c1.103 0 2-.897 2-2v-8.668l-2 2V19H8.158c-.026 0-.053.01-.079.01-.033 0-.066-.009-.1-.01H5V5h6.847l2-2H5c-1.103 0-2 .897-2 2v14c0 1.103.897 2 2 2z"})]}),IconDelete=({size:size,style:style,className:className})=>jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M6 19a2 2 0 002 2h8a2 2 0 002-2V7H6v12m2.46-7.12l1.41-1.41L12 12.59l2.12-2.12 1.41 1.41L13.41 14l2.12 2.12-1.41 1.41L12 15.41l-2.12 2.12-1.41-1.41L10.59 14l-2.13-2.12M15.5 4l-1-1h-5l-1 1H5v2h14V4h-3.5z"})}),IconCopy=({size:size,style:style,className:className})=>jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M9 2 H15 A1 1 0 0 1 16 3 V5 A1 1 0 0 1 15 6 H9 A1 1 0 0 1 8 5 V3 A1 1 0 0 1 9 2 z"}),jsx("path",{d:"M8 4H6a2 2 0 00-2 2v14a2 2 0 002 2h12a2 2 0 002-2v-2M16 4h2a2 2 0 012 2v4M21 14H11"}),jsx("path",{d:"M15 10l-4 4 4 4"})]}),IconOk=({size:size,style:style,className:className})=>jsxs("svg",{fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,viewBox:"0 0 24 24",width:size,height:size,className:className,style:style,children:[jsx("path",{d:"M22 11.08V12a10 10 0 11-5.93-9.14"}),jsx("path",{d:"M22 4L12 14.01l-3-3"})]}),IconCancel=({size:size,style:style,className:className})=>jsx("svg",{baseProfile:"tiny",viewBox:"0 0 24 24",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M12 4c-4.411 0-8 3.589-8 8s3.589 8 8 8 8-3.589 8-8-3.589-8-8-8zm-5 8c0-.832.224-1.604.584-2.295l6.711 6.711A4.943 4.943 0 0112 17c-2.757 0-5-2.243-5-5zm9.416 2.295L9.705 7.584A4.943 4.943 0 0112 7c2.757 0 5 2.243 5 5 0 .832-.224 1.604-.584 2.295z"})}),IconChevron=({size:size,style:style,className:className})=>jsx("svg",{viewBox:"0 0 512 512",fill:"currentColor",width:size,height:size,className:className,style:style,children:jsx("path",{d:"M233.4 406.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 338.7 86.6 169.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})}),Icon=({name:name,nodeData:nodeData,rotate:rotate})=>{var _a,_b,_c,_d,_e,_f,_g;const{getStyles:getStyles,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:jsx(IconAdd,Object.assign({},commonProps,{style:getStyles("iconAdd",nodeData)}));case"edit":return null!==(_b=null==icons?void 0:icons.edit)&&void 0!==_b?_b:jsx(IconEdit,Object.assign({},commonProps,{style:getStyles("iconEdit",nodeData)}));case"delete":return null!==(_c=null==icons?void 0:icons.delete)&&void 0!==_c?_c:jsx(IconDelete,Object.assign({},commonProps,{style:getStyles("iconDelete",nodeData),size:"1.45em"}));case"copy":return null!==(_d=null==icons?void 0:icons.copy)&&void 0!==_d?_d:jsx(IconCopy,Object.assign({},commonProps,{style:getStyles("iconCopy",nodeData),size:"1.2em"}));case"ok":return null!==(_e=null==icons?void 0:icons.ok)&&void 0!==_e?_e:jsx(IconOk,Object.assign({},commonProps,{style:Object.assign({fontSize:"90%"},getStyles("iconOk",nodeData))}));case"cancel":return null!==(_f=null==icons?void 0:icons.cancel)&&void 0!==_f?_f:jsx(IconCancel,Object.assign({},commonProps,{style:Object.assign({fontSize:"130%"},getStyles("iconCancel",nodeData))}));case"chevron":return null!==(_g=null==icons?void 0:icons.chevron)&&void 0!==_g?_g:jsx(IconChevron,{className:"jer-accordion-icon"+(rotate?" jer-rotate-90":""),size:"1em",style:getStyles("iconCollection",nodeData)});default:return jsx(Fragment,{})}},EditButtons=({startEdit:startEdit,handleDelete:handleDelete,handleAdd:handleAdd,enableClipboard:enableClipboard,type:type,nodeData:nodeData,translate:translate})=>{const{getStyles:getStyles}=useTheme(),NEW_KEY_PROMPT=translate("KEY_NEW",nodeData),[isAdding,setIsAdding]=useState(!1),[newKey,setNewKey]=useState(NEW_KEY_PROMPT),{key:key,path:path,value:data}=nodeData;useEffect((()=>{isAdding||setNewKey(NEW_KEY_PROMPT)}),[isAdding]);return jsxs("div",{className:"jer-edit-buttons",style:isAdding?{opacity:1}:void 0,children:[enableClipboard&&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:key,type:copyType})},className:"jer-copy-pulse",children:jsx(Icon,{name:"copy",nodeData:nodeData})}),startEdit&&jsx("div",{onClick:startEdit,children:jsx(Icon,{name:"edit",nodeData:nodeData})}),handleDelete&&jsx("div",{onClick:handleDelete,children:jsx(Icon,{name:"delete",nodeData:nodeData})}),handleAdd&&jsx("div",{onClick:()=>{"object"===type?setIsAdding(!0):handleAdd("")},children:jsx(Icon,{name:"add",nodeData:nodeData})}),isAdding&&handleAdd&&"object"===type&&jsxs(Fragment,{children:[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:getStyles("input",nodeData)}),jsx(InputButtons,{onOk:()=>{newKey&&(setIsAdding(!1),handleAdd(newKey))},onCancel:()=>{setIsAdding(!1)},nodeData:nodeData})]})]})},InputButtons=({onOk:onOk,onCancel:onCancel,nodeData:nodeData})=>jsxs("div",{className:"jer-confirm-buttons",children:[jsx("div",{onClick:onOk,children:jsx(Icon,{name:"ok",nodeData:nodeData})}),jsx("div",{onClick:onCancel,children:jsx(Icon,{name:"cancel",nodeData:nodeData})})]}),stringifyPath=path=>path.reduce(((str,part)=>"number"==typeof part?`${str}[${part}]`:""===str?part:`${str}.${part}`),""),DataTypes=["string","number","boolean","null","object","array"],getCustomNode=(customNodeDefinitions=[],nodeData)=>{const matchingDefinitions=customNodeDefinitions.filter((({condition:condition})=>condition(nodeData)));if(0===matchingDefinitions.length)return{};const _a=matchingDefinitions[0],{element:element,customNodeProps:customNodeProps,hideKey:hideKey=!1,showEditTools:showEditTools=!0,showOnEdit:showOnEdit=!1,showOnView:showOnView=!0,showCollectionWrapper:showCollectionWrapper=!0}=_a,rest=__rest(_a,["element","customNodeProps","hideKey","showEditTools","showOnEdit","showOnView","showCollectionWrapper"]);return Object.assign({CustomNode:element,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools,showOnEdit:showOnEdit,showOnView:showOnView,showCollectionWrapper:showCollectionWrapper},rest)},isCollection=value=>null!==value&&"object"==typeof value,filterNode=(type,nodeData,searchFilter,searchText="")=>{if(!searchFilter&&!searchText)return!0;switch(type){case"collection":if(searchFilter){if(searchFilter(nodeData,searchText))return!0;if(!filterCollection(searchText,nodeData,searchFilter))return!1}if(!searchFilter&&searchText&&!filterCollection(searchText,nodeData))return!1;break;case"value":if(searchFilter&&!searchFilter(nodeData,searchText))return!1;if(!searchFilter&&searchText&&!matchNode(nodeData,searchText))return!1}return!0},filterCollection=(searchText="",nodeData,matcher=matchNode)=>{const collection=nodeData.value;return Object.entries(collection).some((([key,value])=>{const childPath=[...nodeData.path,key],childNodeData=Object.assign(Object.assign({},nodeData),{key:key,path:childPath,level:nodeData.level+1,value:value,size:childPath.length,parentData:collection});return isCollection(value)?filterCollection(searchText,childNodeData,matcher):matcher(childNodeData,searchText)}))},matchNode=(nodeData,searchText="")=>{const{value:value}=nodeData;if(null===value&&"null".includes(searchText.toLowerCase()))return!0;switch(typeof value){case"string":return value.toLowerCase().includes(searchText.toLowerCase());case"number":return!!String(value).includes(searchText);case"boolean":return value?"true".includes(searchText.toLowerCase())||"1"===searchText:"false".includes(searchText.toLowerCase())||"0"===searchText;default:return!1}},matchNodeKey=({key:key,path:path},searchText="")=>!!matchNode({value:key},searchText)||!!path.some((field=>matchNode({value:field},searchText))),ValueNodeWrapper=props=>{const{data:data,parentData:parentData,nodeData:nodeData,onEdit:onEdit,onDelete:onDelete,enableClipboard:enableClipboard,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictTypeSelection:restrictTypeSelection,searchFilter:searchFilter,searchText:searchText,showLabel:showLabel,stringTruncate:stringTruncate,indent:indent,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,{getStyles:getStyles}=useTheme(),[isEditing,setIsEditing]=useState(!1),[isEditingKey,setIsEditingKey]=useState(!1),[value,setValue]=useState("function"==typeof data?"**INVALID_FUNCTION**":data),[error,setError]=useState(null),{key:name,path:path}=nodeData,customNodeData=getCustomNode(customNodeDefinitions,nodeData),[dataType,setDataType]=useState(getDataType(data,customNodeData));useEffect((()=>{setValue("function"==typeof data?"**INVALID_FUNCTION**":data),setDataType(getDataType(data,customNodeData))}),[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",nodeData)]: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,customNodeData))},canEdit=useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),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,nodeData:nodeData,translate:translate},{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView}=customNodeData,allDataTypes=[...DataTypes,...customNodeDefinitions.filter((({showInTypesSelector:showInTypesSelector=!1,name:name})=>showInTypesSelector&&!!name)).map((({name:name})=>name))],allowedDataTypes=useMemo((()=>{if("boolean"==typeof restrictTypeSelection)return restrictTypeSelection?[]:allDataTypes;if(Array.isArray(restrictTypeSelection))return restrictTypeSelection;const result=restrictTypeSelection(nodeData);return"boolean"==typeof result?result?[]:allDataTypes:result}),[nodeData,restrictTypeSelection]);if(!filterNode("value",nodeData,searchFilter,searchText))return null;const ValueComponent=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsx(CustomNode,Object.assign({},props,{value:value,customNodeProps:customNodeProps,setValue:setValue,handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:e=>{"Enter"===e.key?handleEdit():"Escape"===e.key&&handleCancel()},isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles})):getInputComponent(getDataType(data),inputProps);return jsx("div",{className:"jer-component jer-value-component",style:{marginLeft:indent/2+"em"},children:jsxs("div",{className:"jer-value-main-row",style:{flexWrap:name.length>10?"wrap":"nowrap"},children:[showLabel&&!isEditingKey&&!hideKey&&jsxs("label",{htmlFor:path.join("."),className:"jer-object-key",style:Object.assign(Object.assign({},getStyles("property",nodeData)),{minWidth:`${Math.min(String(name).length+1,5)}ch`,flexShrink:name.length>10?1:0}),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:[name,":"," "]}),showLabel&&isEditingKey&&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"}}),jsxs("div",{className:"jer-value-and-buttons",children:[jsx("div",{className:"jer-input-component",children:ValueComponent}),isEditing?jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData}):"invalid"!==dataType&&!error&&showEditTools&&jsx(EditButtons,{startEdit:canEdit?()=>setIsEditing(!0):void 0,handleDelete:canDelete?()=>{onDelete(value,path).then((error=>{error&&logError(error)}))}:void 0,enableClipboard:enableClipboard,translate:translate,nodeData:nodeData}),isEditing&&allowedDataTypes.length>0&&jsxs("div",{className:"jer-select",children:[jsx("select",{name:`${name}-type-select`,className:"jer-type-select",onChange:e=>(type=>{const customNode=customNodeDefinitions.find((customNode=>customNode.name===type));if(customNode)onEdit(customNode.defaultValue,path),setDataType(type);else{const newValue=convertValue(value,type,translate("DEFAULT_NEW_KEY",nodeData),(null==customNodeData?void 0:customNodeData.CustomNode)?translate("DEFAULT_STRING",nodeData):void 0);setValue(newValue),onEdit(newValue,path),setDataType(type)}})(e.target.value),value:dataType,children:allowedDataTypes.map((type=>jsx("option",{value:type,children:type},type)))}),jsx("span",{className:"focus"})]}),!isEditing&&error&&jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})]})]})})},getDataType=(value,customNodeData)=>(null==customNodeData?void 0:customNodeData.CustomNode)&&(null==customNodeData?void 0:customNodeData.name)&&customNodeData.showInTypesSelector?customNodeData.name:"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 jsx(StringValue,Object.assign({},inputProps,{value:value}));case"number":return jsx(NumberValue,Object.assign({},inputProps,{value:value}));case"boolean":return jsx(BooleanValue,Object.assign({},inputProps,{value:value}));case"null":return jsx(NullValue,Object.assign({},inputProps));case"object":return jsx(ObjectValue,Object.assign({},inputProps,{value:value}));case"array":return jsx(ArrayValue,Object.assign({},inputProps));default:return jsx(InvalidValue,Object.assign({},inputProps))}},convertValue=(value,type,defaultNewKey,defaultString)=>{switch(type){case"string":return null!=defaultString?defaultString:String(value);case"number":{const n=Number(value);return isNaN(n)?0:n}case"boolean":return!!value;case"null":return null;case"object":return{[defaultNewKey]:value};case"array":return[value];default:return String(value)}},CollapseProviderContext=createContext({collapseState:null,setCollapseState:()=>{},doesPathMatch:()=>!1}),CollapseProvider=({children:children})=>{const[collapseState,setCollapseState]=useState(null);return jsx(CollapseProviderContext.Provider,{value:{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:path=>{if(null===collapseState)return!1;for(const[index,value]of collapseState.path.entries())if(value!==path[index])return!1;return!0}},children:children})},useCollapseAll=()=>useContext(CollapseProviderContext),CollectionNode=_a=>{var{data:data,nodeData:incomingNodeData,parentData:parentData,showCollectionCount:showCollectionCount}=_a,props=__rest(_a,["data","nodeData","parentData","showCollectionCount"]);const{getStyles:getStyles}=useTheme(),{collapseState:collapseState,setCollapseState:setCollapseState,doesPathMatch:doesPathMatch}=useCollapseAll(),{onEdit:onEdit,onAdd:onAdd,onDelete:onDelete,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,collapseFilter:collapseFilter,enableClipboard:enableClipboard,searchFilter:searchFilter,searchText:searchText,indent:indent,keySort:keySort,showArrayIndices:showArrayIndices,defaultValue:defaultValue,translate:translate,customNodeDefinitions:customNodeDefinitions}=props,[isEditing,setIsEditing]=useState(!1),[isEditingKey,setIsEditingKey]=useState(!1),[stringifiedValue,setStringifiedValue]=useState(JSON.stringify(data,null,2)),[error,setError]=useState(null),startCollapsed=collapseFilter(incomingNodeData),[collapsed,setCollapsed]=useState(startCollapsed),nodeData=Object.assign(Object.assign({},incomingNodeData),{collapsed:collapsed}),{path:path,key:name,size:size}=nodeData,hasBeenOpened=useRef(!startCollapsed),[isAnimating,setIsAnimating]=useState(!1);useEffect((()=>{setStringifiedValue(JSON.stringify(data,null,2))}),[data]),useEffect((()=>{setCollapsed(collapseFilter(nodeData))}),[collapseFilter]),useEffect((()=>{null!==collapseState&&doesPathMatch(path)&&(hasBeenOpened.current=!0,setCollapsed(collapseState.open))}),[collapseState]);const collectionType=Array.isArray(data)?"array":"object",brackets="array"===collectionType?{open:"[",close:"]"}:{open:"{",close:"}"},transitionTime=getComputedStyle(document.documentElement).getPropertyValue("--jer-expand-transition-time"),getDefaultNewValue=useMemo((()=>nodeData=>"function"!=typeof defaultValue?defaultValue:defaultValue(nodeData)),[defaultValue]),handleKeyPress=e=>{"Enter"===e.key&&(e.metaKey||e.shiftKey||e.ctrlKey)?handleEdit():"Escape"===e.key&&handleCancel()},showError=errorString=>{setError(errorString),setTimeout((()=>setError(null)),2500),console.log("Error",errorString)},handleEdit=()=>{try{const value=JSON5.parse(stringifiedValue);setIsEditing(!1),setError(null),onEdit(value,path).then((error=>{error&&showError(error)}))}catch(_a){setError(translate("ERROR_INVALID_JSON",nodeData)),setTimeout((()=>setError(null)),2500),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=useMemo((()=>!restrictEditFilter(nodeData)),[nodeData]),canDelete=useMemo((()=>!restrictDeleteFilter(nodeData)),[nodeData]),canAdd=useMemo((()=>!restrictAddFilter(nodeData)),[nodeData]),canEditKey=null!==parentData&&canEdit&&canAdd&&canDelete;if(!filterNode("collection",nodeData,searchFilter,searchText)&&nodeData.level>0)return null;const 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,CollectionChildren=hasBeenOpened.current?keyValueArray.map((([key,value],index)=>jsx("div",{className:"jer-collection-element",style:getStyles("collectionElement",nodeData),children:isCollection(value)?jsx(CollectionNode,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,index:index,parentData:data,size:Object.keys(value).length,fullData:nodeData.fullData},showCollectionCount:showCollectionCount},props),key):jsx(ValueNodeWrapper,Object.assign({data:value,parentData:data,nodeData:{key:key,value:value,path:[...path,key],level:path.length+1,index:index,size:1,parentData:data,fullData:nodeData.fullData}},props,{showLabel:"object"===collectionType||showArrayIndices}),key)},key))):null,{CustomNode:CustomNode,customNodeProps:customNodeProps,hideKey:hideKey,showEditTools:showEditTools=!0,showOnEdit:showOnEdit,showOnView:showOnView,showCollectionWrapper:showCollectionWrapper=!0}=getCustomNode(customNodeDefinitions,nodeData),isCollapsed=!!showCollectionWrapper&&collapsed,CollectionContents=CustomNode&&(isEditing&&showOnEdit||!isEditing&&showOnView)?jsx(CustomNode,Object.assign({},props,{data:data,value:data,parentData:parentData,nodeData:nodeData,customNodeProps:customNodeProps,setValue:value=>onEdit(value,path),handleEdit:handleEdit,handleCancel:handleCancel,handleKeyPress:handleKeyPress,isEditing:isEditing,setIsEditing:setIsEditing,getStyles:getStyles,children:CollectionChildren})):isEditing?jsx("div",{className:"jer-collection-text-edit",children:jsxs("div",{children:[jsx(AutogrowTextArea,{className:"jer-collection-text-area",name:path.join("."),value:stringifiedValue,setValue:setStringifiedValue,isEditing:isEditing,handleKeyPress:handleKeyPress,styles:getStyles("input",nodeData)}),jsx("div",{className:"jer-collection-input-button-row",children:jsx(InputButtons,{onOk:handleEdit,onCancel:handleCancel,nodeData:nodeData})})]})}):CollectionChildren,KeyDisplay=isEditingKey?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"}}):jsx("span",{style:getStyles("property",nodeData),onDoubleClick:()=>canEditKey&&setIsEditingKey(!0),children:showLabel&&!hideKey&&""!==name&&void 0!==name?`${name}:`:null});return jsxs("div",{className:"jer-component jer-collection-component",style:Object.assign({marginLeft:(0===path.length?0:indent/2)+"em"},getStyles("collection",nodeData)),children:[showCollectionWrapper?jsxs("div",{className:"jer-collection-header-row",style:{position:"relative"},children:[jsxs("div",{className:"jer-collection-name",children:[jsx("div",{className:"jer-collapse-icon",onClick:e=>(e=>{if(e.getModifierState("Alt"))return hasBeenOpened.current=!0,void setCollapseState({open:!collapsed,path:path});isEditing||(setIsAnimating(!0),hasBeenOpened.current=!0,setCollapsed(!collapsed),setTimeout((()=>setIsAnimating(!1)),500))})(e),children:jsx(Icon,{name:"chevron",rotate:collapsed,nodeData:nodeData})}),KeyDisplay,!isEditing&&jsx("span",{className:"jer-brackets jer-bracket-open",style:getStyles("bracket",nodeData),children:brackets.open})]}),!isEditing&&showCount&&jsx("div",{className:"jer-collection-item-count"+(showCount?" jer-visible":" jer-hidden"),style:getStyles("itemCount",nodeData),children:1===size?translate("ITEM_SINGLE",Object.assign(Object.assign({},nodeData),{size:1}),1):translate("ITEMS_MULTIPLE",nodeData,size)}),jsx("div",{className:"jer-brackets"+(isCollapsed?" jer-visible":" jer-hidden"),style:getStyles("bracket",nodeData),children:brackets.close}),!isEditing&&showEditTools&&jsx(EditButtons,{startEdit:canEdit?()=>{setIsEditing(!0),setCollapsed(!1)}:void 0,handleAdd:canAdd?key=>{setCollapsed(!1);const newValue=getDefaultNewValue(nodeData);"array"===collectionType?onAdd(newValue,[...path,data.length]).then((error=>{error&&showError(error)})):key in data?showError(translate("ERROR_KEY_EXISTS",nodeData)):onAdd(newValue,[...path,key]).then((error=>{error&&showError(error)}))}:void 0,handleDelete:canDelete?handleDelete:void 0,enableClipboard:enableClipboard,type:collectionType,nodeData:nodeData,translate:translate})]}):hideKey?null:jsx("div",{className:"jer-collection-header-row",style:{position:"relative"},children:KeyDisplay}),jsxs("div",{className:"jer-collection-inner",style:Object.assign({maxHeight:isCollapsed?0:isEditing?void 0:3*numOfLines+"em",overflowY:isCollapsed||isAnimating?"hidden":"visible",transition:`max-height ${transitionTime}`},getStyles("collectionInner",nodeData)),children:[CollectionContents,jsx("div",{className:isEditing?"jer-collection-error-row":"jer-collection-error-row-edit",children:error&&jsx("span",{className:"jer-error-slug",style:getStyles("error",nodeData),children:error})}),!isEditing&&showCollectionWrapper&&jsx("div",{className:"jer-brackets jer-bracket-outside",style:getStyles("bracket",nodeData),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,customText)=>(key,customTextData,count)=>((translations,customText,customTextData,key,count)=>{if(customText[key]){const output=customText[key](customTextData);if(null!==output)return output}const string=key in translations?translations[key]:localisedStrings[key];return void 0===count?string:null==string?void 0:string.replace("{{count}}",String(count))})(translations,customText,customTextData,key,count),Editor=({data:srcData,rootName:rootName="root",onUpdate:onUpdate=(()=>{}),onEdit:srcEdit=onUpdate,onDelete:srcDelete=onUpdate,onAdd:srcAdd=onUpdate,enableClipboard:enableClipboard=!0,theme:theme="default",icons:icons,indent:indent=3,collapse:collapse=!1,showCollectionCount:showCollectionCount=!0,restrictEdit:restrictEdit=!1,restrictDelete:restrictDelete=!1,restrictAdd:restrictAdd=!1,restrictTypeSelection:restrictTypeSelection=!1,searchFilter:searchFilterInput,searchText:searchText,searchDebounceTime:searchDebounceTime=350,keySort:keySort=!1,showArrayIndices:showArrayIndices=!0,defaultValue:defaultValue=null,minWidth:minWidth=250,maxWidth:maxWidth="min(600px, 90vw)",stringTruncate:stringTruncate=250,translations:translations={},className:className,customText:customText={},customNodeDefinitions:customNodeDefinitions=[]})=>{const{getStyles:getStyles,setTheme:setTheme,setIcons:setIcons}=useTheme(),{setCollapseState:setCollapseState}=useCollapseAll(),collapseFilter=useCallback(getFilterFunction(collapse),[collapse]),translate=useCallback(getTranslateFunction(translations,customText),[translations,customText]),[debouncedSearchText,setDebouncedSearchText]=useState(searchText),[data,setData]=useState(srcData);useEffect((()=>{theme&&setTheme(theme),icons&&setIcons(icons)}),[theme,icons]),useEffect((()=>{setCollapseState(null),setData(srcData)}),[srcData]),useEffect((()=>{const debounce=setTimeout((()=>setDebouncedSearchText(searchText)),searchDebounceTime);return()=>clearTimeout(debounce)}),[searchText,searchDebounceTime]);const nodeData={key:rootName,path:[],level:0,index:0,value:data,size:Object.keys(data).length,parentData:null,fullData:data},restrictEditFilter=getFilterFunction(restrictEdit),restrictDeleteFilter=getFilterFunction(restrictDelete),restrictAddFilter=getFilterFunction(restrictAdd),searchFilter=getSearchFilter(searchFilterInput),otherProps={name:rootName,nodeData:nodeData,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");setData(newData);const result=yield srcEdit({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcDelete({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):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");setData(newData);const result=yield srcAdd({currentData:currentData,newData:newData,currentValue:currentValue,newValue:newValue,name:path.slice(-1)[0],path:path});if(void 0!==result)return setData(currentData),!1===result?translate("ERROR_UPDATE",nodeData):result})),showCollectionCount:showCollectionCount,collapseFilter:collapseFilter,restrictEditFilter:restrictEditFilter,restrictDeleteFilter:restrictDeleteFilter,restrictAddFilter:restrictAddFilter,restrictTypeSelection:restrictTypeSelection,searchFilter:searchFilter,searchText:debouncedSearchText,enableClipboard:enableClipboard,keySort:keySort,showArrayIndices:showArrayIndices,indent:indent,defaultValue:defaultValue,stringTruncate:stringTruncate,translate:translate,customNodeDefinitions:customNodeDefinitions,parentData:null};return jsx("div",{className:"jer-editor-container "+className,style:Object.assign(Object.assign({},getStyles("container",nodeData)),{minWidth:minWidth,maxWidth:maxWidth}),children:isCollection(data)?jsx(CollectionNode,Object.assign({data:data},otherProps)):jsx(ValueNodeWrapper,Object.assign({data:data,showLabel:!0},otherProps))})},JsonEditor=props=>jsx(ThemeProvider,{children:jsx(CollapseProvider,{children:jsx(Editor,Object.assign({},props))})}),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:"delete"!==action?newValue:void 0}},getFilterFunction=propValue=>"boolean"==typeof propValue?()=>propValue:"number"==typeof propValue?({level:level})=>level>=propValue:propValue,getSearchFilter=searchFilterInput=>{if(void 0!==searchFilterInput)return"value"===searchFilterInput?matchNode:"key"===searchFilterInput?matchNodeKey:"all"===searchFilterInput?(inputData,searchText)=>matchNode(inputData,searchText)||matchNodeKey(inputData,searchText):searchFilterInput},LinkCustomComponent=({value:value,setIsEditing:setIsEditing,getStyles:getStyles,customNodeProps:customNodeProps,nodeData:nodeData})=>{var _a,_b;const stringTruncateLength=null!==(_a=null==customNodeProps?void 0:customNodeProps.stringTruncate)&&void 0!==_a?_a:100,styles=getStyles("string",nodeData);return jsx("div",{onDoubleClick:()=>setIsEditing(!0),onClick:e=>{(e.getModifierState("Control")||e.getModifierState("Meta"))&&setIsEditing(!0)},className:"jer-value-string jer-hyperlink",style:styles,children:jsxs("a",{href:value,target:"_blank",rel:"noreferrer",style:{color:null!==(_b=styles.color)&&void 0!==_b?_b:void 0},children:['"',truncate(value,stringTruncateLength),'"']})})},LinkCustomNodeDefinition={condition:({value:value})=>"string"==typeof value&&/^https?:\/\/.+\..+$/.test(value),element:LinkCustomComponent,showOnView:!0,showOnEdit:!1};export{IconAdd,IconCancel,IconChevron,IconCopy,IconDelete,IconEdit,IconOk,JsonEditor,LinkCustomComponent,LinkCustomNodeDefinition,breakString,matchNode,matchNodeKey,themes,truncate};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-edit-react",
3
- "version": "1.6.1",
3
+ "version": "1.7.2",
4
4
  "description": "React component for editing or viewing JSON/object data",
5
5
  "main": "build/index.cjs.js",
6
6
  "module": "build/index.esm.js",
@@ -34,7 +34,7 @@
34
34
  "dependencies": {
35
35
  "json5": "^2.2.3",
36
36
  "just-clone": "^6.2.0",
37
- "object-property-assigner": "^1.2.1",
37
+ "object-property-assigner": "^1.2.2",
38
38
  "object-property-extractor": "^1.0.10"
39
39
  },
40
40
  "devDependencies": {
@@ -60,6 +60,6 @@
60
60
  "rollup-plugin-styles": "^4.0.0",
61
61
  "ts-node": "^10.9.2",
62
62
  "tslib": "^2.6.2",
63
- "typescript": "*"
63
+ "typescript": "^5.3.3"
64
64
  }
65
65
  }