@uiw/react-json-view 2.0.0-alpha.10 → 2.0.0-alpha.11

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
@@ -363,7 +363,7 @@ export default function Demo() {
363
363
  }
364
364
  ```
365
365
 
366
- Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`
366
+ Supports certain partial customizations such as: `<Copied />`, `<CountInfo />`, `<CountInfoExtra />`, `<Ellipsis />`, `<KeyName />`, `<Row />`
367
367
 
368
368
  ```tsx mdx:preview
369
369
  import React, { Fragment } from 'react';
@@ -580,6 +580,52 @@ Passing **as="tagName"** will automatically infer the type.
580
580
  />
581
581
  ```
582
582
 
583
+ Add a click event on the data row
584
+
585
+ ```tsx mdx:preview
586
+ import React from 'react';
587
+ import JsonView from '@uiw/react-json-view';
588
+
589
+ export default function Demo() {
590
+ return (
591
+ <JsonView
592
+ style={{
593
+ '--w-rjv-background-color': '#ffffff',
594
+ }}
595
+ value={{
596
+ name: 'John',
597
+ age: 30,
598
+ hobbies: ['reading', 'coding', 'swimming'],
599
+ address: {
600
+ street: '123 Main St',
601
+ city: 'New York',
602
+ country: {
603
+ name: 'Main ',
604
+ codex: '123'
605
+ }
606
+ }
607
+ }}
608
+ >
609
+ <JsonView.Row
610
+ as="div"
611
+ render={(props, { keyName, value, parentValue }) => {
612
+ return (
613
+ <div
614
+ {...props}
615
+ onClick={() => {
616
+ console.log("keyName", keyName)
617
+ console.log("value", value)
618
+ console.log("parentValue", parentValue)
619
+ }}
620
+ />
621
+ )
622
+ }}
623
+ />
624
+ </JsonView>
625
+ )
626
+ }
627
+ ```
628
+
583
629
  ## Highlight Updates
584
630
 
585
631
  ```tsx mdx:preview
@@ -777,6 +823,7 @@ import { Arrow } from './symbol/Arrow';
777
823
  import { Colon } from './symbol/Colon';
778
824
  import { Quote } from './symbol/Quote';
779
825
  import { ValueQuote } from './symbol/ValueQuote';
826
+
780
827
  import { Bigint } from './types/Bigint';
781
828
  import { Date } from './types/Date';
782
829
  import { False } from './types/False';
@@ -790,13 +837,24 @@ import { StringText } from './types/String';
790
837
  import { True } from './types/True';
791
838
  import { Undefined } from './types/Undefined';
792
839
  import { Url } from './types/Url';
840
+
793
841
  import { Copied } from './section/Copied';
794
842
  import { CountInfo } from './section/CountInfo';
795
843
  import { CountInfoExtra } from './section/CountInfoExtra';
796
844
  import { Ellipsis } from './section/Ellipsis';
797
845
  import { KeyName } from './section/KeyName';
846
+ import { Row } from './section/Row';
798
847
 
799
848
  type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
849
+ BraceLeft: typeof BraceLeft;
850
+ BraceRight: typeof BraceRight;
851
+ BracketsLeft: typeof BracketsLeft;
852
+ BracketsRight: typeof BracketsRight;
853
+ Arrow: typeof Arrow;
854
+ Colon: typeof Colon;
855
+ Quote: typeof Quote;
856
+ ValueQuote: typeof ValueQuote;
857
+
800
858
  Bigint: typeof Bigint;
801
859
  Date: typeof Date;
802
860
  False: typeof False;
@@ -810,19 +868,13 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
810
868
  True: typeof True;
811
869
  Undefined: typeof Undefined;
812
870
  Url: typeof Url;
813
- BraceLeft: typeof BraceLeft;
814
- BraceRight: typeof BraceRight;
815
- BracketsLeft: typeof BracketsLeft;
816
- BracketsRight: typeof BracketsRight;
817
- Colon: typeof Colon;
818
- Ellipsis: typeof Ellipsis;
819
- Quote: typeof Quote;
820
- ValueQuote: typeof ValueQuote;
821
- Arrow: typeof Arrow;
871
+
822
872
  Copied: typeof Copied;
823
873
  CountInfo: typeof CountInfo;
824
874
  CountInfoExtra: typeof CountInfoExtra;
875
+ Ellipsis: typeof Ellipsis;
825
876
  KeyName: typeof KeyName;
877
+ Row: typeof Row;
826
878
  };
827
879
  declare const JsonView: JsonViewComponent;
828
880
  export default JsonView;
@@ -15,6 +15,7 @@ var _Expands = require("../store/Expands");
15
15
  var _ShowTools = require("../store/ShowTools");
16
16
  var _Value = require("./Value");
17
17
  var _KeyName = require("../section/KeyName");
18
+ var _Row = require("../section/Row");
18
19
  var _Container = require("../Container");
19
20
  var _symbol = require("../symbol");
20
21
  var _useHighlight = require("../utils/useHighlight");
@@ -143,8 +144,11 @@ var KeyValuesItem = exports.KeyValuesItem = function KeyValuesItem(props) {
143
144
  return dispatch((0, _defineProperty2["default"])({}, subkeyid, false));
144
145
  }
145
146
  };
146
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
147
- className: "w-rjv-line"
147
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Row.RowComp, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
148
+ className: "w-rjv-line",
149
+ value: value,
150
+ keyName: keyName,
151
+ parentValue: parentValue
148
152
  }, reset), {}, {
149
153
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(KayName, {
150
154
  keyName: keyName,
package/cjs/index.d.ts CHANGED
@@ -25,6 +25,7 @@ import { CountInfo } from './section/CountInfo';
25
25
  import { CountInfoExtra } from './section/CountInfoExtra';
26
26
  import { Ellipsis } from './section/Ellipsis';
27
27
  import { KeyName } from './section/KeyName';
28
+ import { Row } from './section/Row';
28
29
  export * from './store';
29
30
  export * from './store/Expands';
30
31
  export * from './store/ShowTools';
@@ -89,6 +90,7 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
89
90
  CountInfo: typeof CountInfo;
90
91
  CountInfoExtra: typeof CountInfoExtra;
91
92
  KeyName: typeof KeyName;
93
+ Row: typeof Row;
92
94
  };
93
95
  declare const JsonView: JsonViewComponent;
94
96
  export default JsonView;
package/cjs/index.js CHANGED
@@ -48,6 +48,7 @@ var _CountInfo = require("./section/CountInfo");
48
48
  var _CountInfoExtra = require("./section/CountInfoExtra");
49
49
  var _Ellipsis = require("./section/Ellipsis");
50
50
  var _KeyName = require("./section/KeyName");
51
+ var _Row = require("./section/Row");
51
52
  var _jsxRuntime = require("react/jsx-runtime");
52
53
  var _Expands = require("./store/Expands");
53
54
  Object.keys(_Expands).forEach(function (key) {
@@ -191,5 +192,6 @@ JsonView.Copied = _Copied.Copied;
191
192
  JsonView.CountInfo = _CountInfo.CountInfo;
192
193
  JsonView.CountInfoExtra = _CountInfoExtra.CountInfoExtra;
193
194
  JsonView.KeyName = _KeyName.KeyName;
195
+ JsonView.Row = _Row.Row;
194
196
  JsonView.displayName = 'JVR.JsonView';
195
197
  var _default = exports["default"] = JsonView;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { type TagType } from '../store/Types';
3
+ import { type SectionElement } from '../store/Section';
4
+ export declare const Row: {
5
+ <K extends TagType>(props: SectionElement<K>): null;
6
+ displayName: string;
7
+ };
8
+ export interface RowCompProps<T extends object> extends React.HTMLAttributes<HTMLDivElement> {
9
+ value?: T;
10
+ keyName?: string | number;
11
+ parentValue?: unknown;
12
+ }
13
+ export declare const RowComp: {
14
+ <T extends object>({ children, value, keyName, parentValue, ...other }: import("react").PropsWithChildren<RowCompProps<T>>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.RowComp = exports.Row = void 0;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
+ var _Section = require("../store/Section");
11
+ var _useRender = require("../utils/useRender");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ var _excluded = ["children", "value", "keyName", "parentValue"],
14
+ _excluded2 = ["as", "render", "children"];
15
+ var Row = exports.Row = function Row(props) {
16
+ var _useSectionStore = (0, _Section.useSectionStore)(),
17
+ _useSectionStore$Row = _useSectionStore.Row,
18
+ Comp = _useSectionStore$Row === void 0 ? {} : _useSectionStore$Row;
19
+ (0, _useRender.useSectionRender)(Comp, props, 'Row');
20
+ return null;
21
+ };
22
+ Row.displayName = 'JVR.Row';
23
+ var RowComp = exports.RowComp = function RowComp(_ref) {
24
+ var children = _ref.children,
25
+ value = _ref.value,
26
+ _ref$keyName = _ref.keyName,
27
+ keyName = _ref$keyName === void 0 ? '' : _ref$keyName,
28
+ parentValue = _ref.parentValue,
29
+ other = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
30
+ var _useSectionStore2 = (0, _Section.useSectionStore)(),
31
+ _useSectionStore2$Row = _useSectionStore2.Row,
32
+ Comp = _useSectionStore2$Row === void 0 ? {} : _useSectionStore2$Row;
33
+ var as = Comp.as,
34
+ render = Comp.render,
35
+ _ = Comp.children,
36
+ reset = (0, _objectWithoutProperties2["default"])(Comp, _excluded2);
37
+ var Elm = as || 'div';
38
+ var child = render && typeof render === 'function' && render((0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), reset), {}, {
39
+ children: children
40
+ }), {
41
+ value: value,
42
+ keyName: keyName,
43
+ parentValue: parentValue
44
+ });
45
+ if (child) return child;
46
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(Elm, (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, other), reset), {}, {
47
+ children: children
48
+ }));
49
+ };
50
+ RowComp.displayName = 'JVR.RowComp';
@@ -14,6 +14,7 @@ type InitialState<T extends TagType> = {
14
14
  CountInfo?: SectionElement<T>;
15
15
  CountInfoExtra?: SectionElement<T>;
16
16
  Ellipsis?: SectionElement<T>;
17
+ Row?: SectionElement<T>;
17
18
  KeyName?: SectionElement<T>;
18
19
  };
19
20
  type Dispatch = React.Dispatch<InitialState<TagType>>;
@@ -23,6 +24,7 @@ export declare function useSection(): [{
23
24
  CountInfo?: SectionElement<TagType> | undefined;
24
25
  CountInfoExtra?: SectionElement<TagType> | undefined;
25
26
  Ellipsis?: SectionElement<TagType> | undefined;
27
+ Row?: SectionElement<TagType> | undefined;
26
28
  KeyName?: SectionElement<TagType> | undefined;
27
29
  }, React.Dispatch<InitialState<TagType>>];
28
30
  export declare function useSectionDispatch(): Dispatch;
@@ -49,6 +49,10 @@ var initialState = {
49
49
  className: 'w-rjv-ellipsis',
50
50
  children: '...'
51
51
  },
52
+ Row: {
53
+ as: 'div',
54
+ className: 'w-rjv-line'
55
+ },
52
56
  KeyName: {
53
57
  as: 'span',
54
58
  className: 'w-rjv-object-key'
@@ -5,6 +5,7 @@ import { useExpandsStore } from '../store/Expands';
5
5
  import { useShowToolsDispatch } from '../store/ShowTools';
6
6
  import { Value } from './Value';
7
7
  import { KeyNameComp } from '../section/KeyName';
8
+ import { RowComp } from '../section/Row';
8
9
  import { Container } from '../Container';
9
10
  import { Quote, Colon } from '../symbol';
10
11
  import { useHighlight } from '../utils/useHighlight';
@@ -130,8 +131,11 @@ export var KeyValuesItem = props => {
130
131
  [subkeyid]: false
131
132
  })
132
133
  };
133
- return /*#__PURE__*/_jsxs("div", _extends({
134
- className: "w-rjv-line"
134
+ return /*#__PURE__*/_jsxs(RowComp, _extends({
135
+ className: "w-rjv-line",
136
+ value: value,
137
+ keyName: keyName,
138
+ parentValue: parentValue
135
139
  }, reset, {
136
140
  children: [/*#__PURE__*/_jsx(KayName, {
137
141
  keyName: keyName,
package/esm/index.d.ts CHANGED
@@ -25,6 +25,7 @@ import { CountInfo } from './section/CountInfo';
25
25
  import { CountInfoExtra } from './section/CountInfoExtra';
26
26
  import { Ellipsis } from './section/Ellipsis';
27
27
  import { KeyName } from './section/KeyName';
28
+ import { Row } from './section/Row';
28
29
  export * from './store';
29
30
  export * from './store/Expands';
30
31
  export * from './store/ShowTools';
@@ -89,6 +90,7 @@ type JsonViewComponent = React.FC<React.PropsWithRef<JsonViewProps<object>>> & {
89
90
  CountInfo: typeof CountInfo;
90
91
  CountInfoExtra: typeof CountInfoExtra;
91
92
  KeyName: typeof KeyName;
93
+ Row: typeof Row;
92
94
  };
93
95
  declare const JsonView: JsonViewComponent;
94
96
  export default JsonView;
package/esm/index.js CHANGED
@@ -30,6 +30,7 @@ import { CountInfo } from './section/CountInfo';
30
30
  import { CountInfoExtra } from './section/CountInfoExtra';
31
31
  import { Ellipsis } from './section/Ellipsis';
32
32
  import { KeyName } from './section/KeyName';
33
+ import { Row } from './section/Row';
33
34
  import { jsx as _jsx } from "react/jsx-runtime";
34
35
  import { jsxs as _jsxs } from "react/jsx-runtime";
35
36
  export * from './store';
@@ -113,5 +114,6 @@ JsonView.Copied = Copied;
113
114
  JsonView.CountInfo = CountInfo;
114
115
  JsonView.CountInfoExtra = CountInfoExtra;
115
116
  JsonView.KeyName = KeyName;
117
+ JsonView.Row = Row;
116
118
  JsonView.displayName = 'JVR.JsonView';
117
119
  export default JsonView;
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { type TagType } from '../store/Types';
3
+ import { type SectionElement } from '../store/Section';
4
+ export declare const Row: {
5
+ <K extends TagType>(props: SectionElement<K>): null;
6
+ displayName: string;
7
+ };
8
+ export interface RowCompProps<T extends object> extends React.HTMLAttributes<HTMLDivElement> {
9
+ value?: T;
10
+ keyName?: string | number;
11
+ parentValue?: unknown;
12
+ }
13
+ export declare const RowComp: {
14
+ <T extends object>({ children, value, keyName, parentValue, ...other }: import("react").PropsWithChildren<RowCompProps<T>>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
@@ -0,0 +1,45 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["children", "value", "keyName", "parentValue"],
4
+ _excluded2 = ["as", "render", "children"];
5
+ import { useSectionStore } from '../store/Section';
6
+ import { useSectionRender } from '../utils/useRender';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export var Row = props => {
9
+ var {
10
+ Row: Comp = {}
11
+ } = useSectionStore();
12
+ useSectionRender(Comp, props, 'Row');
13
+ return null;
14
+ };
15
+ Row.displayName = 'JVR.Row';
16
+ export var RowComp = _ref => {
17
+ var {
18
+ children,
19
+ value,
20
+ keyName = '',
21
+ parentValue
22
+ } = _ref,
23
+ other = _objectWithoutPropertiesLoose(_ref, _excluded);
24
+ var {
25
+ Row: Comp = {}
26
+ } = useSectionStore();
27
+ var {
28
+ as,
29
+ render
30
+ } = Comp,
31
+ reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
32
+ var Elm = as || 'div';
33
+ var child = render && typeof render === 'function' && render(_extends({}, other, reset, {
34
+ children
35
+ }), {
36
+ value,
37
+ keyName,
38
+ parentValue
39
+ });
40
+ if (child) return child;
41
+ return /*#__PURE__*/_jsx(Elm, _extends({}, other, reset, {
42
+ children: children
43
+ }));
44
+ };
45
+ RowComp.displayName = 'JVR.RowComp';
@@ -14,6 +14,7 @@ type InitialState<T extends TagType> = {
14
14
  CountInfo?: SectionElement<T>;
15
15
  CountInfoExtra?: SectionElement<T>;
16
16
  Ellipsis?: SectionElement<T>;
17
+ Row?: SectionElement<T>;
17
18
  KeyName?: SectionElement<T>;
18
19
  };
19
20
  type Dispatch = React.Dispatch<InitialState<TagType>>;
@@ -23,6 +24,7 @@ export declare function useSection(): [{
23
24
  CountInfo?: SectionElement<TagType> | undefined;
24
25
  CountInfoExtra?: SectionElement<TagType> | undefined;
25
26
  Ellipsis?: SectionElement<TagType> | undefined;
27
+ Row?: SectionElement<TagType> | undefined;
26
28
  KeyName?: SectionElement<TagType> | undefined;
27
29
  }, React.Dispatch<InitialState<TagType>>];
28
30
  export declare function useSectionDispatch(): Dispatch;
@@ -38,6 +38,10 @@ var initialState = {
38
38
  className: 'w-rjv-ellipsis',
39
39
  children: '...'
40
40
  },
41
+ Row: {
42
+ as: 'div',
43
+ className: 'w-rjv-line'
44
+ },
41
45
  KeyName: {
42
46
  as: 'span',
43
47
  className: 'w-rjv-object-key'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "2.0.0-alpha.10",
3
+ "version": "2.0.0-alpha.11",
4
4
  "description": "JSON viewer for react.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",