@microlink/react-json-view 1.23.3 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,114 +1,167 @@
1
- ![alt text](https://raw.githubusercontent.com/microlinkhq/react-json-view/master/doc/rjv-icon-alt.png)
2
1
 
3
- [![npm](https://img.shields.io/npm/v/%40microlink%2Freact-json-view.svg)](https://www.npmjs.com/package/@microlink/react-json-view) [![npm](https://img.shields.io/npm/l/%40microlink%2Freact-json-view.svg
4
- )](https://github.com/microlinkhq/react-json-view/blob/master/LICENSE) [![Build Status](https://github.com/microlinkhq/react-json-view/workflows/test/badge.svg)](https://github.com/microlinkhq/react-json-view/actions/workflows/main.yml?query=branch%3Amaster)
5
-
6
- # react-json-view
7
- RJV is a React component for displaying and editing javascript **arrays** and **JSON objects**.
2
+ <h1 align="center">
3
+ <a href="https://react-json-view.microlink.io/">
4
+ <img src="https://raw.githubusercontent.com/microlinkhq/react-json-view/master/docs/assets/rjv-icon-alt.png" alt="react-json-view" width="200"></a>
5
+ <br>
6
+ react-json-view
7
+ <br>
8
+ <a href="https://www.npmjs.com/package/@microlink/react-json-view"><img src="https://img.shields.io/npm/v/%40microlink%2Freact-json-view.svg" alt="npm version"></a>
9
+ <a href="https://github.com/microlinkhq/react-json-view/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/%40microlink%2Freact-json-view.svg" alt="npm license"></a>
10
+ <a href="https://github.com/microlinkhq/react-json-view/actions/workflows/main.yml?query=branch%3Amaster"><img src="https://github.com/microlinkhq/react-json-view/workflows/test/badge.svg" alt="Build Status"></a>
11
+ <br>
12
+ </h1>
13
+
14
+ **react-json-view** (rjv) is a React component for displaying and editing javascript **arrays** and **JSON objects**.
15
+
16
+ ![](https://raw.githubusercontent.com/microlinkhq/react-json-view/docs/docs/assets/banner.png)
17
+
18
+ ### Highlights
19
+
20
+ * `onEdit`, `onAdd` and `onDelete` props allow users to edit the `src` variable.
21
+ * Object, array, string and function values can be collapsed and expanded.
22
+ * Object and array nodes display length.
23
+ * Object and array nodes support a "Copy to Clipboard" feature.
24
+ * String values can be truncated after a specified length.
25
+ * Arrays can be subgrouped after a specified length.
26
+ * Base-16 Theme Support.
27
+ * When `onEdit` is enabled:
28
+ * `Ctrl/Cmd+Click` Edit Mode
29
+ * `Ctrl/Cmd+Enter` Submit
8
30
 
9
- This component provides a responsive interface for displaying arrays or JSON in a web browser. NPM offers a distribution of the source that's transpiled to ES5; so you can include this component with *any web-based javascript application*.
31
+ ### Installation
10
32
 
11
- [Check out the Interactive Demo](https://react-json-view.microlink.io/)
33
+ ```shell
34
+ npm install @microlink/react-json-view --save
35
+ ```
12
36
 
37
+ ### Usage
13
38
 
14
- ### Implementation Example
15
39
  ```js
16
- // import the react-json-view component
17
- import ReactJson from '@microlink/react-json-view'
18
-
19
- // use the component in your app!
20
- <ReactJson src={my_json_object} />
40
+ import ReactJsonView from '@microlink/react-json-view'
41
+
42
+ <ReactJsonView src={{
43
+ string: 'this is a test string',
44
+ integer: 42,
45
+ array: [1, 2, 3, 'test', NaN],
46
+ float: 3.14159,
47
+ undefined: undefined,
48
+ object: {
49
+ 'first-child': true,
50
+ 'second-child': false,
51
+ 'last-child': null
52
+ },
53
+ string_number: '1234',
54
+ date: new Date()
55
+ }} />
21
56
  ```
22
57
 
23
- ### Output Examples
24
- #### Default Theme
25
- ![alt text](https://raw.githubusercontent.com/microlinkhq/react-json-view/master/doc/output-example-15.png "Output Example 1")
26
- #### Hopscotch Theme, with Triangle Icons:
27
- ![alt text](https://raw.githubusercontent.com/microlinkhq/react-json-view/master/doc/output-example-14.png "Output Example 2")
58
+ ### API
59
+
60
+ | Name | Type | Default | Description |
61
+ |:-----------------------------|:-------------------------------------------------|:-------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
62
+ | `src` | `JSON Object` | None | This property contains your input JSON. |
63
+ | `name` | `string` or `JSX.Element` | `false` | "root" - Contains the name of your root node. Use `null` or `false` for no name. |
64
+ | `theme` | `string` | `'rjv-default'` | RJV supports base-16 themes. Check out the list of supported themes [in the demo](https://react-json-view.microlink.io/). A custom "rjv-default" theme applies by default. |
65
+ | `style` | `object` | `{}` | Style attributes for react-json-view container. Explicit style attributes will override attributes provided by a theme. |
66
+ | `iconStyle` | `string` | `'circle'` | Style of expand/collapse icons. Accepted values are "circle", "triangle" or "square". |
67
+ | `indentWidth` | `integer` | 4 | Set the indent-width for nested objects. |
68
+ | `collapsed` | `boolean` or `integer` | `false` | When set to `true`, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. |
69
+ | `collapseStringsAfterLength` | `integer` | `false` | When an integer value is assigned, strings will be cut off at that length. Collapsed strings are followed by an ellipsis. String content can be expanded and collapsed by clicking on the string value. |
70
+ | `shouldCollapse` | `(field)=>{}` | `false` | Callback function to provide control over what objects and arrays should be collapsed by default. An object is passed to the callback containing `name`, `src`, `type` ("array" or "object") and `namespace`. |
71
+ | `groupArraysAfterLength` | `integer` | 100 | When an integer value is assigned, arrays will be displayed in groups by count of the value. Groups are displayed with bracket notation and can be expanded and collapsed by clicking on the brackets. |
72
+ | `enableClipboard` | `boolean` or `(copy)=>{}` | `true` | When prop is not `false`, the user can copy objects and arrays to clipboard by clicking on the clipboard icon. Copy callbacks are supported. |
73
+ | `displayObjectSize` | `boolean` | `true` | When set to `true`, objects and arrays are labeled with size. |
74
+ | `displayDataTypes` | `boolean` | `true` | When set to `true`, data type labels prefix values. |
75
+ | `onEdit` | `(edit)=>{}` | `false` | When a callback function is passed in, `edit` functionality is enabled. The callback is invoked before edits are completed. Returning `false` from `onEdit` will prevent the change from being made. [see: onEdit docs](#onedit-onadd-and-ondelete-interaction) |
76
+ | `onAdd` | `(add)=>{}` | `false` | When a callback function is passed in, `add` functionality is enabled. The callback is invoked before additions are completed. Returning `false` from `onAdd` will prevent the change from being made. [see: onAdd docs](#onedit-onadd-and-ondelete-interaction) |
77
+ | `defaultValue` | `string \| number \| boolean \| array \| object` | `null` | Sets the default value to be used when adding an item to JSON. |
78
+ | `onDelete` | `(delete)=>{}` | `false` | When a callback function is passed in, `delete` functionality is enabled. The callback is invoked before deletions are completed. Returning `false` from `onDelete` will prevent the change from being made. [see: onDelete docs](#onedit-onadd-and-ondelete-interaction) |
79
+ | `onSelect` | `(select)=>{}` | `false` | When a function is passed in, clicking a value triggers the `onSelect` method to be called. |
80
+ | `sortKeys` | `boolean` | `false` | Set to `true` to sort object keys. |
81
+ | `quotesOnKeys` | `boolean` | `true` | Set to `false` to remove quotes from keys (e.g., `"name":` vs. `name:`). |
82
+ | `validationMessage` | `string` | "Validation Error" | Custom message for validation failures to `onEdit`, `onAdd`, or `onDelete` callbacks. |
83
+ | `displayArrayKey` | `boolean` | `true` | When set to `true`, the index of the elements prefix values. |
84
+ | `escapeStrings` | `boolean` | `true` | When set to `true`, strings sequences such as \n, \t, \r, \f will be escaped. |
85
+
86
+ #### Callbacks
87
+
88
+ You can pass callback methods to `onEdit`, `onAdd` and `onDelete` props.
89
+
90
+ Your method will be invoked when a user attempts to update your `src` object.
28
91
 
29
- ### Installation Instructions
30
- Install this component with [NPM](https://www.npmjs.com/package/@microlink/react-json-view).
31
- ```shell
32
- npm install --save @microlink/react-json-view
33
- ```
34
- Or add to your package.json config file:
35
- ```json
36
- "dependencies": {
37
- "@microlink/react-json-view": "latest"
92
+ The following object will be passed to your method:
93
+ ```js
94
+ {
95
+ updated_src: src, //new src value
96
+ name: name, //new var name
97
+ namespace: namespace, //list, namespace indicating var location
98
+ new_value: new_value, //new variable value
99
+ existing_value: existing_value, //existing variable value
38
100
  }
39
101
  ```
40
102
 
41
- ### Props
42
- Name|Type|Default|Description
43
- |:---|:---|:---|:---
44
- `src`|`JSON Object`|None|This property contains your input JSON
45
- `name`|`string`|`JSX.Element` or `false`|"root"|Contains the name of your root node. Use `null` or `false` for no name.
46
- `theme`|`string`|"rjv-default"|RJV supports base-16 themes. Check out the list of supported themes [in the demo](https://react-json-view.microlink.io/). A custom "rjv-default" theme applies by default.
47
- `style`|`object`|`{}`|Style attributes for react-json-view container. Explicit style attributes will override attributes provided by a theme.
48
- `iconStyle`|`string`|"circle"| Style of expand/collapse icons. Accepted values are "circle", triangle" or "square".
49
- `indentWidth`|`integer`|4|Set the indent-width for nested objects
50
- `collapsed`|`boolean` or `integer`|`false`|When set to `true`, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth.
51
- `collapseStringsAfterLength`|`integer`|`false`|When an integer value is assigned, strings will be cut off at that length. Collapsed strings are followed by an ellipsis. String content can be expanded and collapsed by clicking on the string value.
52
- `shouldCollapse`|`(field)=>{}`|`false`|Callback function to provide control over what objects and arrays should be collapsed by default. An object is passed to the callback containing `name`, `src`, `type` ("array" or "object") and `namespace`.
53
- `groupArraysAfterLength`|`integer`|`100`|When an integer value is assigned, arrays will be displayed in groups by count of the value. Groups are displayed with bracket notation and can be expanded and collapsed by clicking on the brackets.
54
- `enableClipboard`|`boolean` or `(copy)=>{}`|`true`|When prop is not `false`, the user can copy objects and arrays to clipboard by clicking on the clipboard icon. Copy callbacks are supported.
55
- `displayObjectSize`|`boolean`|`true`|When set to `true`, objects and arrays are labeled with size
56
- `displayDataTypes`|`boolean`|`true`|When set to `true`, data type labels prefix values
57
- `onEdit`|`(edit)=>{}`|`false`|When a callback function is passed in, `edit` functionality is enabled. The callback is invoked before edits are completed. Returning `false` from `onEdit` will prevent the change from being made. [see: onEdit docs](#onedit-onadd-and-ondelete-interaction)
58
- `onAdd`|`(add)=>{}`|`false`|When a callback function is passed in, `add` functionality is enabled. The callback is invoked before additions are completed. Returning `false` from `onAdd` will prevent the change from being made. [see: onAdd docs](#onedit-onadd-and-ondelete-interaction)
59
- `defaultValue`|`string \|number \|boolean \|array \|object`|`null`|Sets the default value to be used when adding an item to json
60
- `onDelete`|`(delete)=>{}`|`false`|When a callback function is passed in, `delete` functionality is enabled. The callback is invoked before deletions are completed. Returning `false` from `onDelete` will prevent the change from being made. [see: onDelete docs](#onedit-onadd-and-ondelete-interaction)
61
- `onSelect`|`(select)=>{}`|`false`|When a function is passed in, clicking a value triggers the `onSelect` method to be called.
62
- `sortKeys`|`boolean`|`false`|set to true to sort object keys
63
- `quotesOnKeys`|`boolean`|`true`|set to false to remove quotes from keys (eg. `"name":` vs. `name:`)
64
- `validationMessage`|`string`|"Validation Error"|Custom message for validation failures to `onEdit`, `onAdd`, or `onDelete` callbacks
65
- `displayArrayKey`|`boolean`|`true`|When set to `true`, the index of the elements prefix values
66
-
67
- ### Features
68
- * `onEdit`, `onAdd` and `onDelete` props allow users to edit the `src` variable
69
- * Object, array, string and function values can be collapsed and expanded
70
- * Object and array nodes display length
71
- * Object and array nodes support a "Copy to Clipboard" feature
72
- * String values can be truncated after a specified length
73
- * Arrays can be subgrouped after a specified length
74
- * Base-16 Theme Support
75
- * When `onEdit` is enabled:
76
- * `Ctrl/Cmd+Click` Edit Mode
77
- * `Ctrl/Cmd+Enter` Submit
103
+ Returning `false` from a callback method will prevent the src from being affected.
78
104
 
79
- ### Customizing Style
80
- #### Stock Themes
81
- RJV now supports base-16 themes!
105
+ ### Theming
106
+
107
+ #### Builtin theme
82
108
 
83
109
  You can specify a `theme` name or object when you instantiate your rjv component.
110
+
84
111
  ```jsx
85
- <ReactJson src={my_important_json} theme="monokai" />
112
+ <ReactJsonView src={my_important_json} theme="monokai" />
86
113
  ```
87
- Check out the list of supported themes [in the component demo](https://react-json-view.microlink.io/).
88
114
 
89
- #### Monokai theme example
90
- ![alt text](https://raw.githubusercontent.com/microlinkhq/react-json-view/master/doc/output-example-monokai-2.png "Base-16 Theme Example")
91
-
92
- #### Solarized theme example
93
- ![alt text](https://raw.githubusercontent.com/microlinkhq/react-json-view/master/doc/output-example-solarized-2.png "Base-16 Theme Example")
94
-
95
- #### Use Your Own Theme
96
- You can supply your own base-16 theme object.
115
+ The following themes are builtin with the library:
116
+
117
+ - `'apathy'`
118
+ - `'ashes'`
119
+ - `'atelierDune'`
120
+ - `'atelierForest'`
121
+ - `'atelierHeath'`
122
+ - `'atelierLakeside'`
123
+ - `'atelierSeaside'`
124
+ - `'bespin'`
125
+ - `'brewer'`
126
+ - `'bright'`
127
+ - `'chalk'`
128
+ - `'codeschool'`
129
+ - `'colors'`
130
+ - `'eighties'`
131
+ - `'embers'`
132
+ - `'flat'`
133
+ - `'google'`
134
+ - `'grayscale'`
135
+ - `'greenscreen'`
136
+ - `'harmonic'`
137
+ - `'hopscotch'`
138
+ - `'isotope'`
139
+ - `'marrakesh'`
140
+ - `'mocha'`
141
+ - `'monokai'`
142
+ - `'ocean'`
143
+ - `'paraiso'`
144
+ - `'pop'`
145
+ - `'railscasts'`
146
+ - `'shapeshifter'`
147
+ - `'solarized'`
148
+ - `'summerfruit'`
149
+ - `'threezerotwofour'`
150
+ - `'tomorrow'`
151
+ - `'tube'`
152
+ - `'twilight'`
153
+
154
+ Check [react-json-view.microlink.io](https://react-json-view.microlink.io/) to see how they look like.
155
+
156
+ #### Custom theme
157
+
158
+ **rjv** supports any base-16 theme. You can supply your own base-16 theme object.
97
159
 
98
160
  To better understand custom themes, take a look at [my example implementation](https://github.com/microlinkhq/react-json-view/blob/7c154b9a7d83ea89dce2c171ebdf4d163ff49233/dev-server/src/index.js#L135) and the [base-16 theme styling guidelines](https://github.com/chriskempson/base16/blob/master/styling.md).
99
161
 
100
- ### onEdit, onAdd and onDelete Interaction
101
- Pass callback methods to `onEdit`, `onAdd` and `onDelete` props. Your method will be invoked when a user attempts to update your `src` object.
162
+ ## License
102
163
 
103
- The following object will be passed to your method:
104
- ```js
105
- {
106
- updated_src: src, //new src value
107
- name: name, //new var name
108
- namespace: namespace, //list, namespace indicating var location
109
- new_value: new_value, //new variable value
110
- existing_value: existing_value, //existing variable value
111
- }
112
- ```
164
+ **react-json-view** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/cards/blob/master/LICENSE.md) License.<br>
165
+ Authored by [Mac Gainor](https://github.com/mac-s-g) and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/cards/contributors).
113
166
 
114
- Returning `false` from a callback method will prevent the src from being affected.
167
+ > [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)