@uiw/react-json-view 1.8.0 → 1.8.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
@@ -530,6 +530,11 @@ export default function Demo() {
530
530
  }}
531
531
  onEdit={(opts) => {
532
532
  console.log('opts:', opts)
533
+ // opts.namespace: ['object', 'child', 'last']
534
+ // opts.oldValue: null
535
+ // opts.type: "value"
536
+ // opts.value: "NULL3"
537
+ return true;
533
538
  }}
534
539
  components={{
535
540
  objectKey: ObjectKey
@@ -756,6 +761,7 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
756
761
  oldValue: unknown;
757
762
  keyName?: string | number;
758
763
  parentName?: string | number;
764
+ namespace?: Array<string | number>;
759
765
  type?: 'value' | 'key';
760
766
  }) => boolean;
761
767
  /**
@@ -11,6 +11,7 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
11
11
  oldValue: unknown;
12
12
  keyName?: string | number;
13
13
  parentName?: string | number;
14
+ namespace?: Array<string | number>;
14
15
  type?: 'value' | 'key';
15
16
  }) => boolean;
16
17
  /**
@@ -6,13 +6,15 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.ObjectKey = void 0;
8
8
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _regeneratorRuntime2 = _interopRequireDefault(require("@babel/runtime/helpers/regeneratorRuntime"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
9
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
13
  var _react = require("react");
12
14
  var _semicolon = require("../semicolon");
13
15
  var _value = require("../value");
14
16
  var _jsxRuntime = require("react/jsx-runtime");
15
- var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
17
+ var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "namespace", "editableValue", "onEdit", "highlightUpdates", "render"];
16
18
  var ObjectKey = function ObjectKey(props) {
17
19
  var className = props.className,
18
20
  value = props.value,
@@ -20,6 +22,7 @@ var ObjectKey = function ObjectKey(props) {
20
22
  parentName = props.parentName,
21
23
  quotes = props.quotes,
22
24
  label = props.label,
25
+ namespace = props.namespace,
23
26
  editableValue = props.editableValue,
24
27
  onEdit = props.onEdit,
25
28
  _props$highlightUpdat = props.highlightUpdates,
@@ -55,22 +58,51 @@ var ObjectKey = function ObjectKey(props) {
55
58
  (_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
56
59
  }
57
60
  };
58
- var blur = function blur() {
59
- setEditable(false);
60
- if ($edit.current) {
61
- var _$edit$current2;
62
- $edit.current.contentEditable = 'false';
63
- (_$edit$current2 = $edit.current) === null || _$edit$current2 === void 0 ? void 0 : _$edit$current2.focus();
64
- setCurentLabel($edit.current.innerText);
65
- onEdit && onEdit({
66
- value: $edit.current.innerText,
67
- oldValue: curentLabel,
68
- keyName: keyName,
69
- parentName: parentName,
70
- type: 'key'
71
- });
72
- }
73
- };
61
+ var blur = /*#__PURE__*/function () {
62
+ var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/(0, _regeneratorRuntime2["default"])().mark(function _callee() {
63
+ var _$edit$current2, result;
64
+ return (0, _regeneratorRuntime2["default"])().wrap(function _callee$(_context) {
65
+ while (1) switch (_context.prev = _context.next) {
66
+ case 0:
67
+ if (!$edit.current) {
68
+ _context.next = 8;
69
+ break;
70
+ }
71
+ if (!onEdit) {
72
+ _context.next = 6;
73
+ break;
74
+ }
75
+ _context.next = 4;
76
+ return onEdit({
77
+ value: $edit.current.innerText,
78
+ oldValue: curentLabel,
79
+ namespace: namespace,
80
+ keyName: keyName,
81
+ parentName: parentName,
82
+ type: 'key'
83
+ });
84
+ case 4:
85
+ result = _context.sent;
86
+ if (result) {
87
+ setCurentLabel($edit.current.innerText);
88
+ } else {
89
+ $edit.current.innerText = curentLabel;
90
+ }
91
+ case 6:
92
+ $edit.current.contentEditable = 'false';
93
+ (_$edit$current2 = $edit.current) === null || _$edit$current2 === void 0 ? void 0 : _$edit$current2.focus();
94
+ case 8:
95
+ setEditable(false);
96
+ case 9:
97
+ case "end":
98
+ return _context.stop();
99
+ }
100
+ }, _callee);
101
+ }));
102
+ return function blur() {
103
+ return _ref.apply(this, arguments);
104
+ };
105
+ }();
74
106
  var focus = function focus() {
75
107
  if ($edit.current) {
76
108
  var _$edit$current3;
@@ -87,11 +119,11 @@ var ObjectKey = function ObjectKey(props) {
87
119
  };
88
120
  (0, _react.useEffect)(function () {
89
121
  if ($edit.current) {
90
- $edit.current.addEventListener("paste", function (e) {
122
+ $edit.current.addEventListener('paste', function (e) {
91
123
  e.preventDefault();
92
124
  // @ts-ignore
93
- var text = e.clipboardData.getData("text/plain");
94
- document.execCommand("insertHTML", false, text);
125
+ var text = e.clipboardData.getData('text/plain');
126
+ document.execCommand('insertHTML', false, text);
95
127
  });
96
128
  }
97
129
  }, [$edit]);
@@ -9,6 +9,7 @@ export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTM
9
9
  value?: unknown;
10
10
  data?: T;
11
11
  visible?: boolean;
12
+ namespace?: Array<string | number>;
12
13
  editableValue?: boolean;
13
14
  displayDataTypes?: boolean;
14
15
  setValue?: React.Dispatch<React.SetStateAction<T>>;
@@ -15,7 +15,7 @@ var _value = require("../value");
15
15
  var _edit = require("./icon/edit");
16
16
  var _delete = require("./icon/delete");
17
17
  var _jsxRuntime = require("react/jsx-runtime");
18
- var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
18
+ var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
19
19
  var Quotes = function Quotes(_ref) {
20
20
  var show = _ref.show,
21
21
  style = _ref.style,
@@ -37,6 +37,7 @@ function ReValue(props) {
37
37
  quotes = props.quotes,
38
38
  style = props.style,
39
39
  children = props.children,
40
+ namespace = props.namespace,
40
41
  displayDataTypes = props.displayDataTypes,
41
42
  editableValue = props.editableValue,
42
43
  onDelete = props.onDelete,
@@ -64,7 +65,7 @@ function ReValue(props) {
64
65
  if ($edit.current) {
65
66
  var _$edit$current;
66
67
  setEditable(true);
67
- $edit.current.contentEditable = 'true';
68
+ $edit.current.setAttribute('contentEditable', 'true');
68
69
  (_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
69
70
  }
70
71
  };
@@ -74,7 +75,9 @@ function ReValue(props) {
74
75
  evn.stopPropagation();
75
76
  evn.preventDefault();
76
77
  setEditable(false);
77
- $edit.current.contentEditable = 'false';
78
+ if ($edit.current) {
79
+ $edit.current.setAttribute('contentEditable', 'false');
80
+ }
78
81
  }
79
82
  };
80
83
  var blur = /*#__PURE__*/function () {
@@ -94,8 +97,8 @@ function ReValue(props) {
94
97
  _context.next = 16;
95
98
  break;
96
99
  }
97
- $edit.current.contentEditable = 'false';
98
- text = $edit.current.innerText;
100
+ $edit.current.setAttribute('contentEditable', 'false');
101
+ text = $edit.current.innerHTML;
99
102
  _typeStr = curentType;
100
103
  if (curentType === 'number' || curentType === 'float') {
101
104
  text = Number(text);
@@ -108,16 +111,16 @@ function ReValue(props) {
108
111
  if (Number.isNaN(text)) {
109
112
  _typeStr = 'number';
110
113
  }
111
- if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
112
- text = /^(true)$/ig.test(text) ? true : false;
114
+ if (typeof text === 'string' && /^(true|false)$/gi.test(text)) {
115
+ text = /^(true)$/gi.test(text) ? true : false;
113
116
  _typeStr = 'boolean';
114
- } else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
115
- text = BigInt(text.replace(/n$/ig, ''));
117
+ } else if (typeof text === 'string' && /^[\d]+n$/gi.test(text)) {
118
+ text = BigInt(text.replace(/n$/gi, ''));
116
119
  _typeStr = 'bigint';
117
- } else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
120
+ } else if (typeof text === 'string' && /^(null)$/gi.test(text)) {
118
121
  text = null;
119
122
  _typeStr = 'null';
120
- } else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
123
+ } else if (typeof text === 'string' && /^(undefined)$/gi.test(text)) {
121
124
  text = undefined;
122
125
  _typeStr = 'undefined';
123
126
  } else if (typeof text === 'string') {
@@ -137,7 +140,8 @@ function ReValue(props) {
137
140
  return onEdit({
138
141
  type: 'value',
139
142
  value: text,
140
- oldValue: curentChild
143
+ oldValue: curentChild,
144
+ namespace: namespace
141
145
  });
142
146
  case 14:
143
147
  result = _context.sent;
package/cjs/node.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
7
7
  keyid?: string;
8
8
  level?: number;
9
9
  parentValue?: T;
10
+ namespace?: Array<string | number>;
10
11
  setParentValue?: React.Dispatch<React.SetStateAction<T>>;
11
12
  }
12
13
  export declare function RooNode<T extends object>(props: RooNodeProps<T>): import("react/jsx-runtime").JSX.Element;
package/cjs/node.js CHANGED
@@ -20,7 +20,7 @@ var _copied = require("./copied");
20
20
  var _ellipsis = require("./comps/ellipsis");
21
21
  var _meta = require("./comps/meta");
22
22
  var _jsxRuntime = require("react/jsx-runtime");
23
- var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand", "parentValue", "setParentValue"];
23
+ var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
24
24
  var CountInfo = function CountInfo(_ref) {
25
25
  var children = _ref.children;
26
26
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, {
@@ -61,6 +61,8 @@ function RooNode(props) {
61
61
  keyid = _props$keyid === void 0 ? 'root' : _props$keyid,
62
62
  _props$quotes = props.quotes,
63
63
  quotes = _props$quotes === void 0 ? '"' : _props$quotes,
64
+ _props$namespace = props.namespace,
65
+ namespace = _props$namespace === void 0 ? [] : _props$namespace,
64
66
  onCopied = props.onCopied,
65
67
  onExpand = props.onExpand,
66
68
  parentValue = props.parentValue,
@@ -70,10 +72,6 @@ function RooNode(props) {
70
72
  var subkeyid = (0, _react.useId)();
71
73
  var expands = (0, _store.useExpandsStatus)();
72
74
  var expand = (_expands$keyid = expands[keyid]) !== null && _expands$keyid !== void 0 ? _expands$keyid : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level <= collapsed : true;
73
- var arrowStyle = {
74
- transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
75
- transition: 'all 0.3s'
76
- };
77
75
  var handle = function handle() {
78
76
  onExpand && typeof onExpand === 'function' && onExpand({
79
77
  expand: !expand,
@@ -116,10 +114,14 @@ function RooNode(props) {
116
114
  renderBraces: components.braces,
117
115
  renderValue: components.value
118
116
  };
117
+ var arrowStyle = {
118
+ transform: "rotate(".concat(expand ? '0' : '-90', "deg)"),
119
+ transition: 'all 0.3s'
120
+ };
119
121
  var arrowView = components.arrow ? /*#__PURE__*/(0, _react.cloneElement)(components.arrow, {
120
122
  style: arrowStyle,
121
123
  'data-expand': expand,
122
- className: "w-rjv-arrow"
124
+ className: 'w-rjv-arrow'
123
125
  }) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_TriangleArrow.TriangleArrow, {
124
126
  style: arrowStyle,
125
127
  className: "w-rjv-arrow"
@@ -187,6 +189,7 @@ function RooNode(props) {
187
189
  value: valueData,
188
190
  quotes: quotes,
189
191
  "data-keys": keyid,
192
+ namespace: (0, _toConsumableArray2["default"])(namespace),
190
193
  render: components.objectKey,
191
194
  keyName: keyName,
192
195
  parentName: keyName,
@@ -236,6 +239,7 @@ function RooNode(props) {
236
239
  value: item,
237
240
  "data-keys": keyid,
238
241
  quotes: quotes,
242
+ namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
239
243
  parentName: keyName,
240
244
  highlightUpdates: highlightUpdates,
241
245
  render: components.objectKey,
@@ -249,6 +253,7 @@ function RooNode(props) {
249
253
  className: "w-rjv-wrap",
250
254
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
251
255
  value: item,
256
+ namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [label]),
252
257
  keyName: label,
253
258
  keyid: keyid + subkeyid + label
254
259
  }, subNodeProps))
@@ -259,6 +264,7 @@ function RooNode(props) {
259
264
  className: "w-rjv-wrap",
260
265
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
261
266
  value: item,
267
+ namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key]),
262
268
  keyName: key,
263
269
  keyid: keyid + subkeyid + key
264
270
  }, subNodeProps))
@@ -267,7 +273,9 @@ function RooNode(props) {
267
273
  if (typeof item === 'function') {
268
274
  return;
269
275
  }
270
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, valueViewProps), {}, {
276
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.ValueView, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
277
+ namespace: [].concat((0, _toConsumableArray2["default"])(namespace), [key])
278
+ }, valueViewProps), {}, {
271
279
  renderKey: renderKey,
272
280
  keyName: key,
273
281
  value: item
@@ -15,6 +15,7 @@ export interface SemicolonProps extends LabelProps {
15
15
  quotes?: JsonViewProps<object>['quotes'];
16
16
  value?: object;
17
17
  label?: string;
18
+ namespace?: Array<string | number>;
18
19
  render?: (props: SemicolonProps) => React.ReactNode;
19
20
  }
20
21
  export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
package/cjs/semicolon.js CHANGED
@@ -13,7 +13,7 @@ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
13
  var _react = require("react");
14
14
  var _value = require("./value");
15
15
  var _jsxRuntime = require("react/jsx-runtime");
16
- var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "parentName"];
16
+ var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "namespace", "parentName"];
17
17
  function usePrevious(value) {
18
18
  var ref = (0, _react.useRef)();
19
19
  (0, _react.useEffect)(function () {
@@ -77,6 +77,7 @@ var Semicolon = function Semicolon(_ref2) {
77
77
  highlightUpdates = _ref2.highlightUpdates,
78
78
  quotes = _ref2.quotes,
79
79
  style = _ref2.style,
80
+ namespace = _ref2.namespace,
80
81
  parentName = _ref2.parentName,
81
82
  props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
82
83
  var highlightContainer = (0, _react.useRef)(null);
@@ -86,6 +87,7 @@ var Semicolon = function Semicolon(_ref2) {
86
87
  className: className
87
88
  }, props), {}, {
88
89
  value: value,
90
+ namespace: namespace,
89
91
  style: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
90
92
  color: color
91
93
  }),
@@ -96,7 +98,6 @@ var Semicolon = function Semicolon(_ref2) {
96
98
  children: content
97
99
  }));
98
100
  }
99
- ;
100
101
  useHighlight({
101
102
  value: value,
102
103
  highlightUpdates: highlightUpdates,
package/cjs/value.d.ts CHANGED
@@ -52,6 +52,7 @@ interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSp
52
52
  data?: T;
53
53
  visible?: boolean;
54
54
  quotes?: JsonViewProps<T>['quotes'];
55
+ namespace?: Array<string | number>;
55
56
  setValue?: React.Dispatch<React.SetStateAction<T>>;
56
57
  keyName?: ValueViewProps<T>['keyName'];
57
58
  }
@@ -64,6 +65,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
64
65
  enableClipboard: boolean;
65
66
  indentWidth: number;
66
67
  level?: number;
68
+ namespace?: Array<string | number>;
67
69
  quotes?: JsonViewProps<T>['quotes'];
68
70
  renderKey?: JSX.Element;
69
71
  renderBraces?: MetaProps['render'];
package/cjs/value.js CHANGED
@@ -18,7 +18,7 @@ var _meta = require("./comps/meta");
18
18
  var _copied = require("./copied");
19
19
  var _jsxRuntime = require("react/jsx-runtime");
20
20
  var _excluded = ["children", "style"],
21
- _excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
21
+ _excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "namespace", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
22
22
  _excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
23
23
  var Line = function Line(props) {
24
24
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
@@ -133,6 +133,7 @@ function ValueView(props) {
133
133
  data = props.data,
134
134
  keyName = props.keyName,
135
135
  indentWidth = props.indentWidth,
136
+ namespace = props.namespace,
136
137
  renderKey = props.renderKey,
137
138
  quotes = props.quotes,
138
139
  level = props.level,
@@ -198,6 +199,7 @@ function ValueView(props) {
198
199
  data: data,
199
200
  quotes: quotes,
200
201
  keyName: keyName,
202
+ namespace: namespace,
201
203
  visible: showTools,
202
204
  content: content,
203
205
  children: content
@@ -11,6 +11,7 @@ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T>
11
11
  oldValue: unknown;
12
12
  keyName?: string | number;
13
13
  parentName?: string | number;
14
+ namespace?: Array<string | number>;
14
15
  type?: 'value' | 'key';
15
16
  }) => boolean;
16
17
  /**
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
4
+ var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "namespace", "editableValue", "onEdit", "highlightUpdates", "render"];
4
5
  import { useEffect, useRef, useState } from 'react';
5
6
  import { useHighlight } from '../semicolon';
6
7
  import { Label } from '../value';
@@ -13,6 +14,7 @@ export var ObjectKey = props => {
13
14
  parentName,
14
15
  quotes,
15
16
  label,
17
+ namespace,
16
18
  editableValue,
17
19
  onEdit,
18
20
  highlightUpdates = true,
@@ -40,22 +42,34 @@ export var ObjectKey = props => {
40
42
  (_$edit$current = $edit.current) == null ? void 0 : _$edit$current.focus();
41
43
  }
42
44
  };
43
- var blur = () => {
44
- setEditable(false);
45
- if ($edit.current) {
46
- var _$edit$current2;
47
- $edit.current.contentEditable = 'false';
48
- (_$edit$current2 = $edit.current) == null ? void 0 : _$edit$current2.focus();
49
- setCurentLabel($edit.current.innerText);
50
- onEdit && onEdit({
51
- value: $edit.current.innerText,
52
- oldValue: curentLabel,
53
- keyName,
54
- parentName,
55
- type: 'key'
56
- });
57
- }
58
- };
45
+ var blur = /*#__PURE__*/function () {
46
+ var _ref = _asyncToGenerator(function* () {
47
+ if ($edit.current) {
48
+ var _$edit$current2;
49
+ if (onEdit) {
50
+ var result = yield onEdit({
51
+ value: $edit.current.innerText,
52
+ oldValue: curentLabel,
53
+ namespace,
54
+ keyName,
55
+ parentName,
56
+ type: 'key'
57
+ });
58
+ if (result) {
59
+ setCurentLabel($edit.current.innerText);
60
+ } else {
61
+ $edit.current.innerText = curentLabel;
62
+ }
63
+ }
64
+ $edit.current.contentEditable = 'false';
65
+ (_$edit$current2 = $edit.current) == null ? void 0 : _$edit$current2.focus();
66
+ }
67
+ setEditable(false);
68
+ });
69
+ return function blur() {
70
+ return _ref.apply(this, arguments);
71
+ };
72
+ }();
59
73
  var focus = () => {
60
74
  if ($edit.current) {
61
75
  var _$edit$current3;
@@ -72,11 +86,11 @@ export var ObjectKey = props => {
72
86
  };
73
87
  useEffect(() => {
74
88
  if ($edit.current) {
75
- $edit.current.addEventListener("paste", e => {
89
+ $edit.current.addEventListener('paste', e => {
76
90
  e.preventDefault();
77
91
  // @ts-ignore
78
- var text = e.clipboardData.getData("text/plain");
79
- document.execCommand("insertHTML", false, text);
92
+ var text = e.clipboardData.getData('text/plain');
93
+ document.execCommand('insertHTML', false, text);
80
94
  });
81
95
  }
82
96
  }, [$edit]);
@@ -9,6 +9,7 @@ export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTM
9
9
  value?: unknown;
10
10
  data?: T;
11
11
  visible?: boolean;
12
+ namespace?: Array<string | number>;
12
13
  editableValue?: boolean;
13
14
  displayDataTypes?: boolean;
14
15
  setValue?: React.Dispatch<React.SetStateAction<T>>;
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
4
- var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
4
+ var _excluded = ["type", "value", "setValue", "data", "keyName", "visible", "quotes", "style", "children", "namespace", "displayDataTypes", "editableValue", "onDelete", "onEdit"];
5
5
  import { Fragment, useEffect, useRef, useState } from 'react';
6
6
  import { getValueString, isFloat, Type, typeMap } from '../value';
7
7
  import { EditIcon } from './icon/edit';
@@ -31,6 +31,7 @@ export function ReValue(props) {
31
31
  visible,
32
32
  quotes,
33
33
  style,
34
+ namespace,
34
35
  displayDataTypes,
35
36
  editableValue,
36
37
  onDelete,
@@ -48,7 +49,7 @@ export function ReValue(props) {
48
49
  if ($edit.current) {
49
50
  var _$edit$current;
50
51
  setEditable(true);
51
- $edit.current.contentEditable = 'true';
52
+ $edit.current.setAttribute('contentEditable', 'true');
52
53
  (_$edit$current = $edit.current) == null ? void 0 : _$edit$current.focus();
53
54
  }
54
55
  };
@@ -58,7 +59,9 @@ export function ReValue(props) {
58
59
  evn.stopPropagation();
59
60
  evn.preventDefault();
60
61
  setEditable(false);
61
- $edit.current.contentEditable = 'false';
62
+ if ($edit.current) {
63
+ $edit.current.setAttribute('contentEditable', 'false');
64
+ }
62
65
  }
63
66
  };
64
67
  var blur = /*#__PURE__*/function () {
@@ -66,8 +69,8 @@ export function ReValue(props) {
66
69
  if (!editableValue) return;
67
70
  setEditable(false);
68
71
  if ($edit.current) {
69
- $edit.current.contentEditable = 'false';
70
- var text = $edit.current.innerText;
72
+ $edit.current.setAttribute('contentEditable', 'false');
73
+ var text = $edit.current.innerHTML;
71
74
  var _typeStr = curentType;
72
75
  if (curentType === 'number' || curentType === 'float') {
73
76
  text = Number(text);
@@ -80,16 +83,16 @@ export function ReValue(props) {
80
83
  if (Number.isNaN(text)) {
81
84
  _typeStr = 'number';
82
85
  }
83
- if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
84
- text = /^(true)$/ig.test(text) ? true : false;
86
+ if (typeof text === 'string' && /^(true|false)$/gi.test(text)) {
87
+ text = /^(true)$/gi.test(text) ? true : false;
85
88
  _typeStr = 'boolean';
86
- } else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
87
- text = BigInt(text.replace(/n$/ig, ''));
89
+ } else if (typeof text === 'string' && /^[\d]+n$/gi.test(text)) {
90
+ text = BigInt(text.replace(/n$/gi, ''));
88
91
  _typeStr = 'bigint';
89
- } else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
92
+ } else if (typeof text === 'string' && /^(null)$/gi.test(text)) {
90
93
  text = null;
91
94
  _typeStr = 'null';
92
- } else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
95
+ } else if (typeof text === 'string' && /^(undefined)$/gi.test(text)) {
93
96
  text = undefined;
94
97
  _typeStr = 'undefined';
95
98
  } else if (typeof text === 'string') {
@@ -105,7 +108,8 @@ export function ReValue(props) {
105
108
  var result = yield onEdit({
106
109
  type: 'value',
107
110
  value: text,
108
- oldValue: curentChild
111
+ oldValue: curentChild,
112
+ namespace
109
113
  });
110
114
  if (result) {
111
115
  setCurentType(_typeStr);
package/esm/node.d.ts CHANGED
@@ -7,6 +7,7 @@ export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
7
7
  keyid?: string;
8
8
  level?: number;
9
9
  parentValue?: T;
10
+ namespace?: Array<string | number>;
10
11
  setParentValue?: React.Dispatch<React.SetStateAction<T>>;
11
12
  }
12
13
  export declare function RooNode<T extends object>(props: RooNodeProps<T>): import("react/jsx-runtime").JSX.Element;
package/esm/node.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand", "parentValue", "setParentValue"];
3
+ var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "namespace", "onCopied", "onExpand", "parentValue", "setParentValue"];
4
4
  import { Fragment, useId, cloneElement, useState, useEffect } from 'react';
5
5
  import { ValueView, Colon, Label, Line, typeMap } from './value';
6
6
  import { TriangleArrow } from './arrow/TriangleArrow';
@@ -42,6 +42,7 @@ export function RooNode(props) {
42
42
  level = 1,
43
43
  keyid = 'root',
44
44
  quotes = '"',
45
+ namespace = [],
45
46
  onCopied,
46
47
  onExpand,
47
48
  parentValue,
@@ -52,10 +53,6 @@ export function RooNode(props) {
52
53
  var subkeyid = useId();
53
54
  var expands = useExpandsStatus();
54
55
  var expand = (_expands$keyid = expands[keyid]) != null ? _expands$keyid : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level <= collapsed : true;
55
- var arrowStyle = {
56
- transform: "rotate(" + (expand ? '0' : '-90') + "deg)",
57
- transition: 'all 0.3s'
58
- };
59
56
  var handle = () => {
60
57
  onExpand && typeof onExpand === 'function' && onExpand({
61
58
  expand: !expand,
@@ -95,10 +92,14 @@ export function RooNode(props) {
95
92
  renderBraces: components.braces,
96
93
  renderValue: components.value
97
94
  };
95
+ var arrowStyle = {
96
+ transform: "rotate(" + (expand ? '0' : '-90') + "deg)",
97
+ transition: 'all 0.3s'
98
+ };
98
99
  var arrowView = components.arrow ? /*#__PURE__*/cloneElement(components.arrow, {
99
100
  style: arrowStyle,
100
101
  'data-expand': expand,
101
- className: "w-rjv-arrow"
102
+ className: 'w-rjv-arrow'
102
103
  }) : /*#__PURE__*/_jsx(TriangleArrow, {
103
104
  style: arrowStyle,
104
105
  className: "w-rjv-arrow"
@@ -149,6 +150,7 @@ export function RooNode(props) {
149
150
  value: valueData,
150
151
  quotes: quotes,
151
152
  "data-keys": keyid,
153
+ namespace: [...namespace],
152
154
  render: components.objectKey,
153
155
  keyName: keyName,
154
156
  parentName: keyName,
@@ -196,6 +198,7 @@ export function RooNode(props) {
196
198
  value: item,
197
199
  "data-keys": keyid,
198
200
  quotes: quotes,
201
+ namespace: [...namespace, key],
199
202
  parentName: keyName,
200
203
  highlightUpdates: highlightUpdates,
201
204
  render: components.objectKey,
@@ -209,6 +212,7 @@ export function RooNode(props) {
209
212
  className: "w-rjv-wrap",
210
213
  children: /*#__PURE__*/_jsx(RooNode, _extends({
211
214
  value: item,
215
+ namespace: [...namespace, label],
212
216
  keyName: label,
213
217
  keyid: keyid + subkeyid + label
214
218
  }, subNodeProps))
@@ -219,6 +223,7 @@ export function RooNode(props) {
219
223
  className: "w-rjv-wrap",
220
224
  children: /*#__PURE__*/_jsx(RooNode, _extends({
221
225
  value: item,
226
+ namespace: [...namespace, key],
222
227
  keyName: key,
223
228
  keyid: keyid + subkeyid + key
224
229
  }, subNodeProps))
@@ -227,7 +232,9 @@ export function RooNode(props) {
227
232
  if (typeof item === 'function') {
228
233
  return;
229
234
  }
230
- return /*#__PURE__*/_jsx(ValueView, _extends({}, valueViewProps, {
235
+ return /*#__PURE__*/_jsx(ValueView, _extends({
236
+ namespace: [...namespace, key]
237
+ }, valueViewProps, {
231
238
  renderKey: renderKey,
232
239
  keyName: key,
233
240
  value: item
@@ -15,6 +15,7 @@ export interface SemicolonProps extends LabelProps {
15
15
  quotes?: JsonViewProps<object>['quotes'];
16
16
  value?: object;
17
17
  label?: string;
18
+ namespace?: Array<string | number>;
18
19
  render?: (props: SemicolonProps) => React.ReactNode;
19
20
  }
20
21
  export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
package/esm/semicolon.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "parentName"];
3
+ var _excluded = ["children", "render", "color", "value", "className", "keyName", "highlightUpdates", "quotes", "style", "namespace", "parentName"];
4
4
  import { useMemo, useRef, useEffect } from 'react';
5
5
  import { Label } from './value';
6
6
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -68,6 +68,7 @@ export var Semicolon = _ref2 => {
68
68
  highlightUpdates,
69
69
  quotes,
70
70
  style,
71
+ namespace,
71
72
  parentName
72
73
  } = _ref2,
73
74
  props = _objectWithoutPropertiesLoose(_ref2, _excluded);
@@ -78,6 +79,7 @@ export var Semicolon = _ref2 => {
78
79
  className
79
80
  }, props, {
80
81
  value,
82
+ namespace,
81
83
  style: _extends({}, style, {
82
84
  color
83
85
  }),
@@ -88,7 +90,6 @@ export var Semicolon = _ref2 => {
88
90
  children: content
89
91
  }));
90
92
  }
91
- ;
92
93
  useHighlight({
93
94
  value,
94
95
  highlightUpdates,
package/esm/value.d.ts CHANGED
@@ -52,6 +52,7 @@ interface RenderValueProps<T extends object> extends React.HTMLAttributes<HTMLSp
52
52
  data?: T;
53
53
  visible?: boolean;
54
54
  quotes?: JsonViewProps<T>['quotes'];
55
+ namespace?: Array<string | number>;
55
56
  setValue?: React.Dispatch<React.SetStateAction<T>>;
56
57
  keyName?: ValueViewProps<T>['keyName'];
57
58
  }
@@ -64,6 +65,7 @@ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProp
64
65
  enableClipboard: boolean;
65
66
  indentWidth: number;
66
67
  level?: number;
68
+ namespace?: Array<string | number>;
67
69
  quotes?: JsonViewProps<T>['quotes'];
68
70
  renderKey?: JSX.Element;
69
71
  renderBraces?: MetaProps['render'];
package/esm/value.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  var _excluded = ["children", "style"],
4
- _excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
4
+ _excluded2 = ["value", "setValue", "data", "keyName", "indentWidth", "namespace", "renderKey", "quotes", "level", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
5
5
  _excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
6
6
  import { Fragment, forwardRef, useState } from 'react';
7
7
  import { CountInfo } from './node';
@@ -116,6 +116,7 @@ export function ValueView(props) {
116
116
  data,
117
117
  keyName,
118
118
  indentWidth,
119
+ namespace,
119
120
  renderKey,
120
121
  quotes,
121
122
  renderValue,
@@ -175,6 +176,7 @@ export function ValueView(props) {
175
176
  data,
176
177
  quotes,
177
178
  keyName,
179
+ namespace,
178
180
  visible: showTools,
179
181
  content,
180
182
  children: content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uiw/react-json-view",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "JSON viewer for react.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -79,6 +79,9 @@
79
79
  "tree-view",
80
80
  "treeview"
81
81
  ],
82
+ "dependencies": {
83
+ "@babel/runtime": "^7.22.6"
84
+ },
82
85
  "devDependencies": {
83
86
  "@testing-library/react": "^14.0.0",
84
87
  "@types/react-test-renderer": "^18.0.0",