@uiw/react-json-view 1.3.0 → 1.5.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.
Files changed (55) hide show
  1. package/README.md +155 -13
  2. package/cjs/comps/ellipsis.d.ts +5 -0
  3. package/cjs/comps/ellipsis.js +32 -0
  4. package/cjs/comps/meta.d.ts +8 -0
  5. package/cjs/comps/meta.js +38 -0
  6. package/cjs/copied.js +5 -4
  7. package/cjs/editor/icon/edit.d.ts +4 -0
  8. package/cjs/editor/icon/edit.js +30 -0
  9. package/cjs/editor/index.d.ts +16 -0
  10. package/cjs/editor/index.js +48 -0
  11. package/cjs/editor/objectKey.d.ts +11 -0
  12. package/cjs/editor/objectKey.js +138 -0
  13. package/cjs/editor/value.d.ts +14 -0
  14. package/cjs/editor/value.js +165 -0
  15. package/cjs/index.d.ts +5 -1
  16. package/cjs/node.d.ts +0 -19
  17. package/cjs/node.js +68 -168
  18. package/cjs/semicolon.d.ts +21 -0
  19. package/cjs/semicolon.js +113 -0
  20. package/cjs/theme/dark.d.ts +2 -0
  21. package/cjs/theme/dark.js +2 -0
  22. package/cjs/theme/light.d.ts +2 -0
  23. package/cjs/theme/light.js +2 -0
  24. package/cjs/tools.d.ts +10 -0
  25. package/cjs/tools.js +24 -0
  26. package/cjs/value.d.ts +20 -5
  27. package/cjs/value.js +67 -28
  28. package/editor.d.ts +16 -0
  29. package/esm/comps/ellipsis.d.ts +5 -0
  30. package/esm/comps/ellipsis.js +26 -0
  31. package/esm/comps/meta.d.ts +8 -0
  32. package/esm/comps/meta.js +31 -0
  33. package/esm/copied.js +5 -4
  34. package/esm/editor/icon/edit.d.ts +4 -0
  35. package/esm/editor/icon/edit.js +24 -0
  36. package/esm/editor/index.d.ts +16 -0
  37. package/esm/editor/index.js +37 -0
  38. package/esm/editor/objectKey.d.ts +11 -0
  39. package/esm/editor/objectKey.js +122 -0
  40. package/esm/editor/value.d.ts +14 -0
  41. package/esm/editor/value.js +150 -0
  42. package/esm/index.d.ts +5 -1
  43. package/esm/node.d.ts +0 -19
  44. package/esm/node.js +49 -156
  45. package/esm/semicolon.d.ts +21 -0
  46. package/esm/semicolon.js +104 -0
  47. package/esm/theme/dark.d.ts +2 -0
  48. package/esm/theme/dark.js +2 -0
  49. package/esm/theme/light.d.ts +2 -0
  50. package/esm/theme/light.js +2 -0
  51. package/esm/tools.d.ts +10 -0
  52. package/esm/tools.js +20 -0
  53. package/esm/value.d.ts +20 -5
  54. package/esm/value.js +67 -28
  55. package/package.json +7 -1
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { TypeProps } from '../value';
3
+ import { JsonViewEditorProps } from './';
4
+ export interface ReValueProps<T extends object> extends React.HTMLAttributes<HTMLSpanElement> {
5
+ onEdit?: JsonViewEditorProps<T>['onEdit'];
6
+ quotes?: JsonViewEditorProps<T>['quotes'];
7
+ keyName?: JsonViewEditorProps<T>['keyName'];
8
+ type: TypeProps['type'];
9
+ value?: unknown;
10
+ visible?: boolean;
11
+ editableValue?: boolean;
12
+ displayDataTypes?: boolean;
13
+ }
14
+ export declare function ReValue<T extends object>(props: ReValueProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ReValue = ReValue;
8
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
9
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
+ var _react = require("react");
12
+ var _value = require("../value");
13
+ var _edit = require("./icon/edit");
14
+ var _jsxRuntime = require("react/jsx-runtime");
15
+ var _excluded = ["type", "value", "keyName", "visible", "quotes", "style", "content", "children", "displayDataTypes", "editableValue", "onEdit"];
16
+ var Quotes = function Quotes(_ref) {
17
+ var show = _ref.show,
18
+ style = _ref.style,
19
+ quotes = _ref.quotes;
20
+ if (!quotes || !show) return;
21
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
22
+ style: style,
23
+ children: quotes
24
+ });
25
+ };
26
+ function ReValue(props) {
27
+ var _typeMap$typeStr;
28
+ var type = props.type,
29
+ value = props.value,
30
+ keyName = props.keyName,
31
+ visible = props.visible,
32
+ quotes = props.quotes,
33
+ style = props.style,
34
+ content = props.content,
35
+ children = props.children,
36
+ displayDataTypes = props.displayDataTypes,
37
+ editableValue = props.editableValue,
38
+ onEdit = props.onEdit,
39
+ reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
40
+ var _useState = (0, _react.useState)(false),
41
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
42
+ editable = _useState2[0],
43
+ setEditable = _useState2[1];
44
+ var $edit = (0, _react.useRef)(null);
45
+ var _useState3 = (0, _react.useState)(type),
46
+ _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
47
+ curentType = _useState4[0],
48
+ setCurentType = _useState4[1];
49
+ var _useState5 = (0, _react.useState)(value),
50
+ _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
51
+ curentChild = _useState6[0],
52
+ setCurentChild = _useState6[1];
53
+ (0, _react.useEffect)(function () {
54
+ return setCurentChild(value);
55
+ }, [value]);
56
+ var click = function click(evn) {
57
+ evn.stopPropagation();
58
+ if (!editableValue) return;
59
+ if ($edit.current) {
60
+ var _$edit$current;
61
+ setEditable(true);
62
+ $edit.current.contentEditable = 'true';
63
+ (_$edit$current = $edit.current) === null || _$edit$current === void 0 ? void 0 : _$edit$current.focus();
64
+ }
65
+ };
66
+ var keyDown = function keyDown(evn) {
67
+ if (!editableValue) return;
68
+ if (evn.key === 'Enter') {
69
+ evn.stopPropagation();
70
+ evn.preventDefault();
71
+ setEditable(false);
72
+ $edit.current.contentEditable = 'false';
73
+ }
74
+ };
75
+ var blur = function blur() {
76
+ if (!editableValue) return;
77
+ setEditable(false);
78
+ if ($edit.current) {
79
+ $edit.current.contentEditable = 'false';
80
+ var text = $edit.current.innerText;
81
+ if (curentType === 'number' || curentType === 'float') {
82
+ text = Number(text);
83
+ setCurentType((0, _value.isFloat)(text) ? 'float' : 'number');
84
+ }
85
+ if (curentType === 'url' && typeof text === 'string') {
86
+ text = new URL(text);
87
+ }
88
+ if (Number.isNaN(text)) {
89
+ setCurentType('number');
90
+ }
91
+ if (typeof text === 'string' && /^(true|false)$/ig.test(text)) {
92
+ text = /^(true)$/ig.test(text) ? true : false;
93
+ setCurentType('boolean');
94
+ } else if (typeof text === 'string' && /^[\d]+n$/ig.test(text)) {
95
+ text = BigInt(text.replace(/n$/ig, ''));
96
+ setCurentType('bigint');
97
+ } else if (typeof text === 'string' && /^(null)$/ig.test(text)) {
98
+ text = null;
99
+ setCurentType('null');
100
+ } else if (typeof text === 'string' && /^(undefined)$/ig.test(text)) {
101
+ text = undefined;
102
+ setCurentType('undefined');
103
+ } else if (typeof text === 'string') {
104
+ try {
105
+ var dt = new Date(text);
106
+ if (dt.toString() !== 'Invalid Date') {
107
+ text = dt;
108
+ setCurentType('date');
109
+ }
110
+ } catch (error) {}
111
+ }
112
+ setCurentChild(text);
113
+ onEdit && onEdit({
114
+ type: 'value',
115
+ value: text,
116
+ oldValue: curentChild
117
+ });
118
+ }
119
+ };
120
+ var defaultStyle = {
121
+ minWidth: 34,
122
+ minHeight: 18,
123
+ paddingInline: 3,
124
+ display: 'inline-block'
125
+ };
126
+ var _getValueString = (0, _value.getValueString)(curentChild),
127
+ typeStr = _getValueString.type,
128
+ childStr = _getValueString.content;
129
+ var color = ((_typeMap$typeStr = _value.typeMap[typeStr]) === null || _typeMap$typeStr === void 0 ? void 0 : _typeMap$typeStr.color) || '';
130
+ var spanProps = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
131
+ onBlur: blur,
132
+ onKeyDown: keyDown,
133
+ spellCheck: false,
134
+ style: editable ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), defaultStyle), {}, {
135
+ color: color
136
+ }) : (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, style), {}, {
137
+ color: color
138
+ })
139
+ });
140
+ var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Type, {
141
+ type: typeStr
142
+ });
143
+ if (typeStr === 'null' || typeStr === 'undefined') {
144
+ typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
145
+ }
146
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
147
+ children: [displayDataTypes && typeView, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
148
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
149
+ style: style,
150
+ quotes: quotes,
151
+ show: typeStr === 'string'
152
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, spanProps), {}, {
153
+ ref: $edit,
154
+ "data-value": content,
155
+ children: typeof curentChild === 'string' ? curentChild : childStr
156
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(Quotes, {
157
+ style: style,
158
+ quotes: quotes,
159
+ show: typeStr === 'string'
160
+ })]
161
+ }), visible && editableValue && /*#__PURE__*/(0, _jsxRuntime.jsx)(_edit.EditIcon, {
162
+ onClick: click
163
+ })]
164
+ });
165
+ }
package/cjs/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import React from 'react';
2
- import { MetaProps, SemicolonProps, EllipsisProps } from './node';
2
+ import { SemicolonProps } from './semicolon';
3
3
  import { ValueViewProps } from './value';
4
4
  import { CopiedProps } from './copied';
5
+ import { EllipsisProps } from './comps/ellipsis';
6
+ import { MetaProps } from './comps/meta';
5
7
  export * from './node';
6
8
  export * from './value';
7
9
  export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> {
@@ -19,6 +21,8 @@ export interface JsonViewProps<T extends object> extends React.DetailedHTMLProps
19
21
  enableClipboard?: boolean;
20
22
  /** Whether to highlight updates. @default true */
21
23
  highlightUpdates?: boolean;
24
+ /** Whether sort keys through `String.prototype.localeCompare()` @default false */
25
+ objectSortKeys?: boolean | ((a: string, b: string) => number);
22
26
  /** Display for quotes in object-key @default " */
23
27
  quotes?: "'" | '"' | '';
24
28
  /** When set to true, all nodes will be collapsed by default. Use an integer value to collapse at a particular depth. @default false */
package/cjs/node.d.ts CHANGED
@@ -1,25 +1,6 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
2
  import { LabelProps } from './value';
3
3
  import { JsonViewProps } from './';
4
- export interface MetaProps extends LabelProps {
5
- isArray?: boolean;
6
- start?: boolean;
7
- render?: (props: Pick<MetaProps, 'start' | 'isArray' | 'className' | 'children'>) => JSX.Element;
8
- }
9
- export declare function usePrevious<T>(value: T): T | undefined;
10
- export declare function Meta(props: MetaProps): JSX.Element;
11
- export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
12
- render?: (props: EllipsisProps) => JSX.Element;
13
- }
14
- export declare const Ellipsis: FC<PropsWithChildren<EllipsisProps>>;
15
- export interface SemicolonProps extends LabelProps {
16
- show?: boolean;
17
- highlightUpdates?: boolean;
18
- quotes?: JsonViewProps<object>['quotes'];
19
- value?: object;
20
- render?: (props: Omit<SemicolonProps, 'show'> & {}) => JSX.Element;
21
- }
22
- export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
23
4
  export declare const CountInfo: FC<PropsWithChildren<LabelProps>>;
24
5
  export interface RooNodeProps<T extends object> extends JsonViewProps<T> {
25
6
  keyName?: string | number;
package/cjs/node.js CHANGED
@@ -4,152 +4,24 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.Ellipsis = exports.CountInfo = void 0;
8
- exports.Meta = Meta;
7
+ exports.CountInfo = void 0;
9
8
  exports.RooNode = RooNode;
10
- exports.Semicolon = void 0;
11
- exports.usePrevious = usePrevious;
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
14
9
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
12
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
16
13
  var _react = require("react");
17
14
  var _value = require("./value");
18
15
  var _TriangleArrow = require("./arrow/TriangleArrow");
19
16
  var _store = require("./store");
20
- var _copied = require("./copied");
17
+ var _semicolon = require("./semicolon");
18
+ var _tools = require("./tools");
19
+ var _ellipsis = require("./comps/ellipsis");
20
+ var _meta = require("./comps/meta");
21
21
  var _jsxRuntime = require("react/jsx-runtime");
22
- var _excluded = ["isArray", "start", "className", "render"],
23
- _excluded2 = ["style", "render"],
24
- _excluded3 = ["children", "render", "color", "value", "className", "show", "highlightUpdates", "quotes"],
25
- _excluded4 = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
26
- function usePrevious(value) {
27
- var ref = (0, _react.useRef)();
28
- (0, _react.useEffect)(function () {
29
- ref.current = value;
30
- });
31
- return ref.current;
32
- }
33
- function Meta(props) {
34
- var _props$isArray = props.isArray,
35
- isArray = _props$isArray === void 0 ? false : _props$isArray,
36
- _props$start = props.start,
37
- start = _props$start === void 0 ? false : _props$start,
38
- className = props.className,
39
- render = props.render,
40
- reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
41
- var mark = isArray ? '[]' : '{}';
42
- var cls = "w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-").concat(start ? 'start' : 'end', " ").concat(className || '');
43
- var color = "var(--w-rjv-".concat(isArray ? 'brackets' : 'curlybraces', "-color, #236a7c)");
44
- if (render) return render((0, _objectSpread2["default"])({
45
- isArray: isArray,
46
- className: cls,
47
- style: {
48
- color: color
49
- },
50
- children: start ? mark.charAt(0) : mark.charAt(1)
51
- }, reset));
52
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
53
- color: color,
54
- className: cls
55
- }, reset), {}, {
56
- children: start ? mark.charAt(0) : mark.charAt(1)
57
- }));
58
- }
59
- var Ellipsis = function Ellipsis(_ref) {
60
- var style = _ref.style,
61
- render = _ref.render,
62
- props = (0, _objectWithoutProperties2["default"])(_ref, _excluded2);
63
- var styl = (0, _objectSpread2["default"])({
64
- cursor: 'pointer'
65
- }, style);
66
- var className = "w-rjv-ellipsis ".concat(props.className || '');
67
- if (render) return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
68
- style: styl
69
- }, props), {}, {
70
- className: className
71
- }));
72
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("span", (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
73
- className: className,
74
- style: styl
75
- }, props), {}, {
76
- children: "..."
77
- }));
78
- };
79
- exports.Ellipsis = Ellipsis;
80
- var Semicolon = function Semicolon(_ref2) {
81
- var children = _ref2.children,
82
- render = _ref2.render,
83
- color = _ref2.color,
84
- value = _ref2.value,
85
- _ref2$className = _ref2.className,
86
- className = _ref2$className === void 0 ? 'w-rjv-object-key' : _ref2$className,
87
- show = _ref2.show,
88
- highlightUpdates = _ref2.highlightUpdates,
89
- quotes = _ref2.quotes,
90
- props = (0, _objectWithoutProperties2["default"])(_ref2, _excluded3);
91
- var prevValue = usePrevious(value);
92
- var highlightContainer = (0, _react.useRef)(null);
93
- var isHighlight = (0, _react.useMemo)(function () {
94
- if (!highlightUpdates || prevValue === undefined) return false;
95
- // highlight if value type changed
96
- if ((0, _typeof2["default"])(value) !== (0, _typeof2["default"])(prevValue)) {
97
- return true;
98
- }
99
- if (typeof value === 'number') {
100
- // notice: NaN !== NaN
101
- if (isNaN(value) && isNaN(prevValue)) return false;
102
- return value !== prevValue;
103
- }
104
- // highlight if isArray changed
105
- if (Array.isArray(value) !== Array.isArray(prevValue)) {
106
- return true;
107
- }
108
- // not highlight object/function
109
- // deep compare they will be slow
110
- if ((0, _typeof2["default"])(value) === 'object' || typeof value === 'function') {
111
- return false;
112
- }
113
-
114
- // highlight if not equal
115
- if (value !== prevValue) {
116
- return true;
117
- }
118
- return false;
119
- }, [highlightUpdates, value]);
120
- (0, _react.useEffect)(function () {
121
- if (highlightContainer.current && isHighlight && 'animate' in highlightContainer.current) {
122
- highlightContainer.current.animate([{
123
- backgroundColor: 'var(--w-rjv-update-color, #ebcb8b)'
124
- }, {
125
- backgroundColor: ''
126
- }], {
127
- duration: 1000,
128
- easing: 'ease-in'
129
- });
130
- }
131
- }, [isHighlight, value]);
132
- var content = show ? "".concat(quotes).concat(children).concat(quotes) : children;
133
- if (render) return render((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
134
- className: className
135
- }, props), {}, {
136
- value: value,
137
- style: {
138
- color: color
139
- },
140
- children: content
141
- }));
142
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({
143
- className: className,
144
- color: color
145
- }, props), {}, {
146
- ref: highlightContainer,
147
- children: content
148
- }));
149
- };
150
- exports.Semicolon = Semicolon;
151
- var CountInfo = function CountInfo(_ref3) {
152
- var children = _ref3.children;
22
+ var _excluded = ["value", "keyName", "className", "displayDataTypes", "components", "displayObjectSize", "enableClipboard", "highlightUpdates", "objectSortKeys", "indentWidth", "collapsed", "level", "keyid", "quotes", "onCopied", "onExpand"];
23
+ var CountInfo = function CountInfo(_ref) {
24
+ var children = _ref.children;
153
25
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Label, {
154
26
  style: {
155
27
  paddingLeft: 4,
@@ -177,6 +49,8 @@ function RooNode(props) {
177
49
  enableClipboard = _props$enableClipboar === void 0 ? true : _props$enableClipboar,
178
50
  _props$highlightUpdat = props.highlightUpdates,
179
51
  highlightUpdates = _props$highlightUpdat === void 0 ? true : _props$highlightUpdat,
52
+ _props$objectSortKeys = props.objectSortKeys,
53
+ objectSortKeys = _props$objectSortKeys === void 0 ? false : _props$objectSortKeys,
180
54
  _props$indentWidth = props.indentWidth,
181
55
  indentWidth = _props$indentWidth === void 0 ? 15 : _props$indentWidth,
182
56
  collapsed = props.collapsed,
@@ -188,11 +62,8 @@ function RooNode(props) {
188
62
  quotes = _props$quotes === void 0 ? '"' : _props$quotes,
189
63
  onCopied = props.onCopied,
190
64
  onExpand = props.onExpand,
191
- reset = (0, _objectWithoutProperties2["default"])(props, _excluded4);
65
+ reset = (0, _objectWithoutProperties2["default"])(props, _excluded);
192
66
  var isArray = Array.isArray(value);
193
- var nameKeys = isArray ? Object.keys(value).map(function (m) {
194
- return Number(m);
195
- }) : Object.keys(value);
196
67
  var subkeyid = (0, _react.useId)();
197
68
  var expands = (0, _store.useExpandsStatus)();
198
69
  var expand = (_expands$keyid = expands[keyid]) !== null && _expands$keyid !== void 0 ? _expands$keyid : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level <= collapsed : true;
@@ -230,6 +101,7 @@ function RooNode(props) {
230
101
  displayObjectSize: displayObjectSize,
231
102
  enableClipboard: enableClipboard,
232
103
  indentWidth: indentWidth,
104
+ quotes: quotes,
233
105
  renderBraces: components.braces,
234
106
  renderValue: components.value
235
107
  };
@@ -245,12 +117,6 @@ function RooNode(props) {
245
117
  _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
246
118
  showTools = _useState2[0],
247
119
  setShowTools = _useState2[1];
248
- var tools = enableClipboard ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_copied.Copied, {
249
- show: showTools,
250
- text: value,
251
- onCopied: onCopied,
252
- render: components.copied
253
- }) : undefined;
254
120
  var eventProps = {};
255
121
  if (enableClipboard) {
256
122
  eventProps.onMouseEnter = function () {
@@ -260,6 +126,29 @@ function RooNode(props) {
260
126
  return setShowTools(false);
261
127
  };
262
128
  }
129
+ var nameKeys = isArray ? Object.keys(value).map(function (m) {
130
+ return Number(m);
131
+ }) : Object.keys(value);
132
+
133
+ // object
134
+ var entries = isArray ? Object.entries(value).map(function (m) {
135
+ return [Number(m[0]), m[1]];
136
+ }) : Object.entries(value);
137
+ if (objectSortKeys) {
138
+ entries = objectSortKeys === true ? entries.sort(function (_ref2, _ref3) {
139
+ var _ref4 = (0, _slicedToArray2["default"])(_ref2, 1),
140
+ a = _ref4[0];
141
+ var _ref5 = (0, _slicedToArray2["default"])(_ref3, 1),
142
+ b = _ref5[0];
143
+ return typeof a === 'string' && typeof b === 'string' ? a.localeCompare(b) : 0;
144
+ }) : entries.sort(function (_ref6, _ref7) {
145
+ var _ref8 = (0, _slicedToArray2["default"])(_ref6, 1),
146
+ a = _ref8[0];
147
+ var _ref9 = (0, _slicedToArray2["default"])(_ref7, 1),
148
+ b = _ref9[0];
149
+ return typeof a === 'string' && typeof b === 'string' ? objectSortKeys(a, b) : 0;
150
+ });
151
+ }
263
152
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
264
153
  className: "".concat(className, " w-rjv-inner")
265
154
  }, eventProps), {}, {
@@ -270,42 +159,53 @@ function RooNode(props) {
270
159
  },
271
160
  onClick: handle,
272
161
  children: [arrowView, (typeof keyName === 'string' || typeof keyName === 'number') && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
273
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Semicolon, {
162
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
274
163
  value: value,
275
164
  quotes: quotes,
165
+ "data-keys": keyid,
276
166
  render: components.objectKey,
277
- color: typeof keyName === 'number' ? _value.typeMap['number'].color : '',
278
- show: typeof keyName === 'string',
279
- children: keyName
167
+ keyName: keyName,
168
+ parentName: keyName,
169
+ color: typeof keyName === 'number' ? _value.typeMap['number'].color : ''
280
170
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Colon, {})]
281
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
171
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
282
172
  start: true,
283
173
  isArray: isArray,
284
174
  render: components.braces
285
- }), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Ellipsis, {
175
+ }), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ellipsis.Ellipsis, {
286
176
  render: components.ellipsis
287
- }), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
177
+ }), !expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
288
178
  isArray: isArray,
289
179
  render: components.braces
290
180
  }), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(CountInfo, {
291
181
  children: [nameKeys.length, " items"]
292
- }), tools]
182
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_tools.Tools, {
183
+ value: value,
184
+ enableClipboard: enableClipboard,
185
+ onCopied: onCopied,
186
+ components: components,
187
+ showTools: showTools
188
+ })]
293
189
  }), expand && /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
294
190
  className: "w-rjv-content",
295
191
  style: {
296
- borderLeft: 'var(--w-rjv-border-left-width, 1px) solid var(--w-rjv-line-color, #ebebeb)',
192
+ borderLeft: 'var(--w-rjv-border-left-width, 1px) var(--w-rjv-line-style, solid) var(--w-rjv-line-color, #ebebeb)',
297
193
  marginLeft: 6
298
194
  },
299
- children: nameKeys.length > 0 && nameKeys.map(function (key, idx) {
300
- var item = value[key];
301
- var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(Semicolon, {
195
+ children: entries.length > 0 && entries.map(function (_ref10, idx) {
196
+ var _ref11 = (0, _slicedToArray2["default"])(_ref10, 2),
197
+ key = _ref11[0],
198
+ itemVal = _ref11[1];
199
+ var item = itemVal;
200
+ var renderKey = /*#__PURE__*/(0, _jsxRuntime.jsx)(_semicolon.Semicolon, {
302
201
  value: item,
202
+ "data-keys": keyid,
303
203
  quotes: quotes,
204
+ parentName: keyName,
304
205
  highlightUpdates: highlightUpdates,
305
206
  render: components.objectKey,
306
207
  color: typeof key === 'number' ? _value.typeMap['number'].color : '',
307
- show: typeof key === 'string',
308
- children: key
208
+ keyName: key
309
209
  });
310
210
  var isEmpty = Array.isArray(item) && item.length === 0 || (0, _typeof2["default"])(item) === 'object' && item && !(item instanceof Date) && Object.keys(item).length === 0;
311
211
  if (Array.isArray(item) && !isEmpty) {
@@ -314,8 +214,8 @@ function RooNode(props) {
314
214
  className: "w-rjv-wrap",
315
215
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
316
216
  value: item,
317
- keyid: keyid + subkeyid + label,
318
- keyName: label
217
+ keyName: label,
218
+ keyid: keyid + subkeyid + label
319
219
  }, subNodeProps))
320
220
  }, label + idx);
321
221
  }
@@ -323,11 +223,11 @@ function RooNode(props) {
323
223
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_value.Line, {
324
224
  className: "w-rjv-wrap",
325
225
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(RooNode, (0, _objectSpread2["default"])({
326
- keyid: keyid + subkeyid + key,
327
226
  value: item,
328
- keyName: key
227
+ keyName: key,
228
+ keyid: keyid + subkeyid + key
329
229
  }, subNodeProps))
330
- }, key + idx);
230
+ }, key + '' + idx);
331
231
  }
332
232
  if (typeof item === 'function') {
333
233
  return;
@@ -342,7 +242,7 @@ function RooNode(props) {
342
242
  style: {
343
243
  paddingLeft: 2
344
244
  },
345
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Meta, {
245
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
346
246
  render: components.braces,
347
247
  isArray: isArray,
348
248
  style: {
@@ -0,0 +1,21 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ import { LabelProps } from './value';
3
+ import { JsonViewProps } from './';
4
+ export declare function usePrevious<T>(value: T): T | undefined;
5
+ interface UseHighlight {
6
+ value: any;
7
+ highlightUpdates?: boolean;
8
+ highlightContainer: React.MutableRefObject<HTMLSpanElement | null>;
9
+ }
10
+ export declare function useHighlight({ value, highlightUpdates, highlightContainer }: UseHighlight): void;
11
+ export interface SemicolonProps extends LabelProps {
12
+ highlightUpdates?: boolean;
13
+ keyName?: string | number;
14
+ parentName?: string | number;
15
+ quotes?: JsonViewProps<object>['quotes'];
16
+ value?: object;
17
+ label?: string;
18
+ render?: (props: SemicolonProps) => React.ReactNode;
19
+ }
20
+ export declare const Semicolon: FC<PropsWithChildren<SemicolonProps>>;
21
+ export {};