@uiw/react-json-view 1.4.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 +150 -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 +2 -1
  16. package/cjs/node.d.ts +0 -10
  17. package/cjs/node.js +45 -90
  18. package/cjs/semicolon.d.ts +11 -2
  19. package/cjs/semicolon.js +44 -25
  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 +19 -4
  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 +2 -1
  43. package/esm/node.d.ts +0 -10
  44. package/esm/node.js +35 -80
  45. package/esm/semicolon.d.ts +11 -2
  46. package/esm/semicolon.js +44 -25
  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 +19 -4
  54. package/esm/value.js +67 -28
  55. package/package.json +7 -1
package/cjs/value.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { FC, PropsWithChildren } from 'react';
2
- import { MetaProps } from './node';
2
+ import { MetaProps } from './comps/meta';
3
+ import { JsonViewProps } from './';
3
4
  export declare const Line: FC<PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>>;
5
+ export declare const isFloat: (n: number) => boolean;
4
6
  export declare const typeMap: {
5
7
  string: {
6
8
  color: string;
@@ -26,6 +28,10 @@ export declare const typeMap: {
26
28
  color: string;
27
29
  label: string;
28
30
  };
31
+ url: {
32
+ color: string;
33
+ label: string;
34
+ };
29
35
  null: {
30
36
  color: string;
31
37
  label: string;
@@ -40,20 +46,29 @@ export declare const typeMap: {
40
46
  };
41
47
  };
42
48
  export declare const Colon: FC<PropsWithChildren<React.HTMLAttributes<HTMLSpanElement>>>;
43
- export interface ValueViewProps<T> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
49
+ export interface ValueViewProps<T extends object> extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement> {
44
50
  keyName?: string | number;
45
- value?: T;
51
+ value?: unknown;
46
52
  displayDataTypes: boolean;
47
53
  displayObjectSize: boolean;
48
54
  enableClipboard: boolean;
49
55
  indentWidth: number;
56
+ quotes?: JsonViewProps<T>['quotes'];
50
57
  renderKey?: JSX.Element;
51
58
  renderBraces?: MetaProps['render'];
52
59
  renderValue?: (props: React.HTMLAttributes<HTMLSpanElement> & {
53
60
  type: TypeProps['type'];
61
+ value?: unknown;
62
+ visible?: boolean;
63
+ quotes?: JsonViewProps<T>['quotes'];
64
+ keyName?: ValueViewProps<T>['keyName'];
54
65
  }) => JSX.Element;
55
66
  }
56
- export declare function ValueView<T = object>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
67
+ export declare function getValueString<T>(value: T): {
68
+ type: "string" | "number" | "bigint" | "boolean" | "undefined" | "date" | "url" | "float" | "null" | "NaN";
69
+ content: string;
70
+ };
71
+ export declare function ValueView<T extends object>(props: ValueViewProps<T>): import("react/jsx-runtime").JSX.Element;
57
72
  export interface LabelProps extends React.HTMLAttributes<HTMLSpanElement> {
58
73
  color?: string;
59
74
  fontSize?: number;
package/cjs/value.js CHANGED
@@ -6,17 +6,19 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.Type = exports.Line = exports.Label = exports.Colon = void 0;
8
8
  exports.ValueView = ValueView;
9
- exports.typeMap = void 0;
9
+ exports.getValueString = getValueString;
10
+ exports.typeMap = exports.isFloat = void 0;
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
12
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
12
13
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
14
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
14
15
  var _react = require("react");
15
16
  var _node = require("./node");
17
+ var _meta = require("./comps/meta");
16
18
  var _copied = require("./copied");
17
19
  var _jsxRuntime = require("react/jsx-runtime");
18
20
  var _excluded = ["children", "style"],
19
- _excluded2 = ["value", "keyName", "indentWidth", "renderKey", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
21
+ _excluded2 = ["value", "keyName", "indentWidth", "renderKey", "quotes", "renderValue", "renderBraces", "enableClipboard", "displayObjectSize", "displayDataTypes"],
20
22
  _excluded3 = ["children", "color", "fontSize", "opacity", "paddingRight", "style"];
21
23
  var Line = function Line(props) {
22
24
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", (0, _objectSpread2["default"])({}, props));
@@ -25,6 +27,7 @@ exports.Line = Line;
25
27
  var isFloat = function isFloat(n) {
26
28
  return Number(n) === n && n % 1 !== 0 || isNaN(n);
27
29
  };
30
+ exports.isFloat = isFloat;
28
31
  var typeMap = {
29
32
  string: {
30
33
  color: 'var(--w-rjv-type-string-color, #cb4b16)',
@@ -50,6 +53,10 @@ var typeMap = {
50
53
  color: 'var(--w-rjv-type-date-color, #586e75)',
51
54
  label: 'date'
52
55
  },
56
+ url: {
57
+ color: 'var(--w-rjv-type-url-color, #0969da)',
58
+ label: 'URL'
59
+ },
53
60
  "null": {
54
61
  color: 'var(--w-rjv-type-null-color, #d33682)',
55
62
  label: 'null'
@@ -79,22 +86,9 @@ var Colon = function Colon(_ref) {
79
86
  }));
80
87
  };
81
88
  exports.Colon = Colon;
82
- function ValueView(props) {
83
- var _typeMap$type;
84
- var value = props.value,
85
- keyName = props.keyName,
86
- indentWidth = props.indentWidth,
87
- renderKey = props.renderKey,
88
- renderValue = props.renderValue,
89
- renderBraces = props.renderBraces,
90
- enableClipboard = props.enableClipboard,
91
- displayObjectSize = props.displayObjectSize,
92
- displayDataTypes = props.displayDataTypes,
93
- reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
89
+ function getValueString(value) {
94
90
  var type = (0, _typeof2["default"])(value);
95
91
  var content = '';
96
- var color = '';
97
- var style = {};
98
92
  if (typeof value === 'number') {
99
93
  type = isFloat(value) ? 'float' : 'number';
100
94
  content = value.toString();
@@ -107,29 +101,62 @@ function ValueView(props) {
107
101
  type = 'date';
108
102
  content = value.toString();
109
103
  }
110
- var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
111
- type: type
112
- });
113
104
  if (value === null) {
114
105
  type = 'null';
115
106
  content = "".concat(value).toLocaleUpperCase();
116
- typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
117
- style = {
118
- fontWeight: 'bold'
119
- };
120
107
  }
121
108
  if (value === undefined) {
122
109
  type = 'undefined';
123
110
  content = String(value);
124
- typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
125
111
  }
126
112
  if (typeof value === 'bigint') {
127
113
  type = 'bigint';
128
114
  content = "".concat(value, "n");
129
115
  }
116
+ var isURL = value instanceof URL;
117
+ if (isURL) {
118
+ type = 'url';
119
+ content = "\"".concat(value.href, "\"");
120
+ }
130
121
  if (typeof value === 'string') {
131
122
  content = "\"".concat(value, "\"");
132
123
  }
124
+ return {
125
+ type: type,
126
+ content: content
127
+ };
128
+ }
129
+ function ValueView(props) {
130
+ var _typeMap$type;
131
+ var value = props.value,
132
+ keyName = props.keyName,
133
+ indentWidth = props.indentWidth,
134
+ renderKey = props.renderKey,
135
+ quotes = props.quotes,
136
+ renderValue = props.renderValue,
137
+ renderBraces = props.renderBraces,
138
+ enableClipboard = props.enableClipboard,
139
+ displayObjectSize = props.displayObjectSize,
140
+ displayDataTypes = props.displayDataTypes,
141
+ reset = (0, _objectWithoutProperties2["default"])(props, _excluded2);
142
+ var color = '';
143
+ var style = {};
144
+ var _getValueString = getValueString(value),
145
+ type = _getValueString.type,
146
+ content = _getValueString.content;
147
+ var typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(Type, {
148
+ type: type
149
+ });
150
+ if (value === null) {
151
+ typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
152
+ style = {
153
+ fontWeight: 'bold'
154
+ };
155
+ }
156
+ if (value === undefined) {
157
+ typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
158
+ }
159
+ var isURL = value instanceof URL;
133
160
  if (!displayDataTypes) {
134
161
  typeView = /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.Fragment, {});
135
162
  }
@@ -163,14 +190,26 @@ function ValueView(props) {
163
190
  color: color
164
191
  }, style),
165
192
  type: type,
193
+ value: value,
194
+ quotes: quotes,
195
+ keyName: keyName,
196
+ visible: showTools,
166
197
  content: content,
167
- children: value
198
+ children: content
168
199
  });
169
200
  var valueView = reView ? reView : /*#__PURE__*/(0, _jsxRuntime.jsx)(Label, {
170
201
  color: color,
171
202
  style: style,
172
203
  className: "w-rjv-value",
173
- children: content
204
+ children: isURL ? /*#__PURE__*/(0, _jsxRuntime.jsx)("a", {
205
+ href: value.href,
206
+ style: {
207
+ color: color
208
+ },
209
+ target: "_blank",
210
+ rel: "noopener noreferrer",
211
+ children: content
212
+ }) : content
174
213
  });
175
214
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(Line, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, eventProps), {}, {
176
215
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(Label, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, reset), {}, {
@@ -181,11 +220,11 @@ function ValueView(props) {
181
220
  }
182
221
  var length = Array.isArray(value) ? value.length : Object.keys(value).length;
183
222
  var empty = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_react.Fragment, {
184
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_node.Meta, {
223
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
185
224
  render: renderBraces,
186
225
  start: true,
187
226
  isArray: Array.isArray(value)
188
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_node.Meta, {
227
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_meta.Meta, {
189
228
  render: renderBraces,
190
229
  isArray: Array.isArray(value)
191
230
  }), displayObjectSize && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_node.CountInfo, {
package/editor.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+
3
+ declare module '@uiw/react-json-view/editor' {
4
+ import { JsonViewProps } from '@uiw/react-json-view';
5
+ type Option = {
6
+ value: string;
7
+ prevValue: string;
8
+ keyName: string | number;
9
+ };
10
+
11
+ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
12
+ onEdit?: (option: Option) => void;
13
+ }
14
+ const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
15
+ export default JsonViewEditor;
16
+ }
@@ -0,0 +1,5 @@
1
+ import { FC, PropsWithChildren } from 'react';
2
+ export interface EllipsisProps extends React.HTMLAttributes<HTMLSpanElement> {
3
+ render?: (props: EllipsisProps) => JSX.Element;
4
+ }
5
+ export declare const Ellipsis: FC<PropsWithChildren<EllipsisProps>>;
@@ -0,0 +1,26 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["style", "render"];
4
+ import { jsx as _jsx } from "react/jsx-runtime";
5
+ export var Ellipsis = _ref => {
6
+ var {
7
+ style,
8
+ render
9
+ } = _ref,
10
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
11
+ var styl = _extends({
12
+ cursor: 'pointer'
13
+ }, style);
14
+ var className = "w-rjv-ellipsis " + (props.className || '');
15
+ if (render) return render(_extends({
16
+ style: styl
17
+ }, props, {
18
+ className
19
+ }));
20
+ return /*#__PURE__*/_jsx("span", _extends({
21
+ className: className,
22
+ style: styl
23
+ }, props, {
24
+ children: "..."
25
+ }));
26
+ };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { LabelProps } from '../value';
3
+ export interface MetaProps extends LabelProps {
4
+ isArray?: boolean;
5
+ start?: boolean;
6
+ render?: (props: Pick<MetaProps, 'start' | 'isArray' | 'className' | 'children'>) => JSX.Element;
7
+ }
8
+ export declare function Meta(props: MetaProps): JSX.Element;
@@ -0,0 +1,31 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["isArray", "start", "className", "render"];
4
+ import { Label } from '../value';
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export function Meta(props) {
7
+ var {
8
+ isArray = false,
9
+ start = false,
10
+ className,
11
+ render
12
+ } = props,
13
+ reset = _objectWithoutPropertiesLoose(props, _excluded);
14
+ var mark = isArray ? '[]' : '{}';
15
+ var cls = "w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-" + (start ? 'start' : 'end') + " " + (className || '');
16
+ var color = "var(--w-rjv-" + (isArray ? 'brackets' : 'curlybraces') + "-color, #236a7c)";
17
+ if (render) return render(_extends({
18
+ isArray,
19
+ className: cls,
20
+ style: {
21
+ color
22
+ },
23
+ children: start ? mark.charAt(0) : mark.charAt(1)
24
+ }, reset));
25
+ return /*#__PURE__*/_jsx(Label, _extends({
26
+ color: color,
27
+ className: cls
28
+ }, reset, {
29
+ children: start ? mark.charAt(0) : mark.charAt(1)
30
+ }));
31
+ }
package/esm/copied.js CHANGED
@@ -34,6 +34,7 @@ export function Copied(props) {
34
34
  };
35
35
  var defalutStyle = _extends({}, style, {
36
36
  cursor: 'pointer',
37
+ verticalAlign: 'middle',
37
38
  marginLeft: 5
38
39
  });
39
40
  var svgProps = _extends({
@@ -47,19 +48,19 @@ export function Copied(props) {
47
48
  if (render) return render(_extends({}, props, svgProps));
48
49
  if (copied) {
49
50
  return /*#__PURE__*/_jsx("svg", _extends({
50
- viewBox: "0 0 38 38"
51
+ viewBox: "0 0 32 36"
51
52
  }, svgProps, {
52
53
  fill: "var(--w-rjv-copied-success-color, #28a745)",
53
54
  children: /*#__PURE__*/_jsx("path", {
54
- d: "M27.5,35 L2.5,35 L2.5,12.5 L27.5,12.5 L27.5,15.2249049 C29.1403264,13.8627542 29.9736597,13.1778155 30,13.1700887 C30,11.9705278 30,10.0804982 30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,35 C0,36.4 1.1,37.5 2.5,37.5 L27.5,37.5 C28.9,37.5 30,36.4 30,35 L30,30 L27.5,30 L27.5,35 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M31.5589286,15 L35.1589286,18.6 L21.0160714,33 L12.5303571,24.2571429 L16.1303571,20.6571429 L21.0160714,25.5428571 L31.5589286,15 Z M12.5,30 L12.5,32.5 L5,32.5 L5,30 L12.5,30 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
55
+ d: "M27.5,33 L2.5,33 L2.5,12.5 L27.5,12.5 L27.5,15.2249049 C29.1403264,13.8627542 29.9736597,13.1778155 30,13.1700887 C30,11.9705278 30,10.0804982 30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,33 C0,34.4 1.1,36 2.5,36 L27.5,36 C28.9,36 30,34.4 30,33 L30,26.1114493 L27.5,28.4926435 L27.5,33 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M28.5589286,16 L32,19.6 L21.0160714,30.5382252 L13.5303571,24.2571429 L17.1303571,20.6571429 L21.0160714,24.5428571 L28.5589286,16 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
55
56
  })
56
57
  }));
57
58
  }
58
59
  return /*#__PURE__*/_jsx("svg", _extends({
59
- viewBox: "0 0 38 38"
60
+ viewBox: "0 0 32 36"
60
61
  }, svgProps, {
61
62
  children: /*#__PURE__*/_jsx("path", {
62
- d: "M27.5,35 L2.5,35 L2.5,12.5 L27.5,12.5 L27.5,20 L30,20 L30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,35 C0,36.4 1.1,37.5 2.5,37.5 L27.5,37.5 C28.9,37.5 30,36.4 30,35 L30,30 L27.5,30 L27.5,35 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M22.5,22.5 L22.5,17.5 L12.5,25 L22.5,32.5 L22.5,27.5 L35,27.5 L35,22.5 L22.5,22.5 Z M5,32.5 L12.5,32.5 L12.5,30 L5,30 L5,32.5 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
63
+ d: "M27.5,33 L2.5,33 L2.5,12.5 L27.5,12.5 L27.5,20 L30,20 L30,7.5 C30,6.1 28.9,5 27.5,5 L20,5 C20,2.2 17.8,0 15,0 C12.2,0 10,2.2 10,5 L2.5,5 C1.1,5 0,6.1 0,7.5 L0,33 C0,34.4 1.1,36 2.5,36 L27.5,36 C28.9,36 30,34.4 30,33 L30,29 L27.5,29 L27.5,33 Z M7.5,7.5 L10,7.5 C10,7.5 12.5,6.4 12.5,5 C12.5,3.6 13.6,2.5 15,2.5 C16.4,2.5 17.5,3.6 17.5,5 C17.5,6.4 18.8,7.5 20,7.5 L22.5,7.5 C22.5,7.5 25,8.6 25,10 L5,10 C5,8.5 6.1,7.5 7.5,7.5 Z M5,27.5 L10,27.5 L10,25 L5,25 L5,27.5 Z M22.5,21.5 L22.5,16.5 L12.5,24 L22.5,31.5 L22.5,26.5 L32,26.5 L32,21.5 L22.5,21.5 Z M17.5,15 L5,15 L5,17.5 L17.5,17.5 L17.5,15 Z M10,20 L5,20 L5,22.5 L10,22.5 L10,20 Z"
63
64
  })
64
65
  }));
65
66
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ export interface EditIconProps extends React.SVGAttributes<SVGElement> {
3
+ }
4
+ export declare const EditIcon: (props: EditIconProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var EditIcon = props => {
4
+ var {
5
+ style
6
+ } = props;
7
+ var defaultStyle = {
8
+ verticalAlign: 'middle',
9
+ display: 'inline-block',
10
+ cursor: 'pointer',
11
+ marginLeft: 5,
12
+ height: '1em',
13
+ width: '1em'
14
+ };
15
+ return /*#__PURE__*/_jsx("svg", _extends({
16
+ viewBox: "0 0 26 26",
17
+ fill: "var(--w-rjv-edit-color, currentColor)"
18
+ }, props, {
19
+ style: _extends({}, style, defaultStyle),
20
+ children: /*#__PURE__*/_jsx("path", {
21
+ d: "M18,0 L7.74666667,0 C2.89333333,0 0,2.89333333 0,7.74666667 L0,17.9066667 C0,22.7733333 2.89333333,26 7.74666667,26 L18,26 C22.8533333,26 26.0001422,22.7733333 26.0001422,17.92 L26.0001422,7.74666667 C26.0133333,2.89333333 22.8533333,0 18,0 Z M11.9333333,20.68 C11.5466667,21.0666667 10.8133333,21.44 10.28,21.52 L7,21.9866667 C6.88,22 6.76,22.0133333 6.64,22.0133333 C6.09333333,22.0133333 5.58666667,21.8266667 5.22666667,21.4666667 C4.78666667,21.0266667 4.6,20.3866667 4.70666667,19.68 L5.17333333,16.4 C5.25333333,15.8533333 5.61333333,15.1333333 6.01333333,14.7466667 L11.96,8.8 C12.1719034,9.3972484 12.4397602,9.97314063 12.76,10.52 C12.8933333,10.7466667 13.04,10.96 13.16,11.12 C13.3066667,11.3466667 13.48,11.56 13.5866667,11.68 C13.6533333,11.7733333 13.7066667,11.84 13.7333333,11.8666667 C14.0666667,12.2666667 14.4533333,12.64 14.7866667,12.92 C14.88,13.0133333 14.9333333,13.0666667 14.96,13.08 C15.16,13.24 15.36,13.4 15.5333333,13.52 C15.7466667,13.68 15.96,13.8266667 16.1866667,13.9466667 C16.4533333,14.1066667 16.7466667,14.2533333 17.04,14.4 C17.3466667,14.5333333 17.6266667,14.6533333 17.9066667,14.7466667 L11.9333333,20.68 L11.9333333,20.68 Z M20.4933333,12.12 L19.2666667,13.36 C19.1887174,13.4373865 19.0831716,13.4805643 18.9733333,13.4800055 C18.9333333,13.4800055 18.88,13.4800055 18.8533333,13.4666667 C16.1309823,12.6775025 14.0024975,10.5490177 13.2133333,7.82666667 C13.1733333,7.68 13.2133333,7.52 13.32,7.42666667 L14.56,6.18666667 C16.5866667,4.16 18.52,4.2 20.5066667,6.18666667 C21.52,7.2 22.0133333,8.17333333 22.0133333,9.18666667 C22,10.1466667 21.5066667,11.1066667 20.4933333,12.12 L20.4933333,12.12 Z"
22
+ })
23
+ }));
24
+ };
@@ -0,0 +1,16 @@
1
+ /// <reference types="react" />
2
+ import { JsonViewProps } from '../';
3
+ export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
4
+ /** Callback when value edit functionality */
5
+ onEdit?: (option: {
6
+ value: unknown;
7
+ oldValue: unknown;
8
+ keyName?: string | number;
9
+ parentName?: string | number;
10
+ type?: 'value' | 'key';
11
+ }) => void;
12
+ /** Whether enable edit feature. @default true */
13
+ editable?: boolean;
14
+ }
15
+ declare const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
16
+ export default JsonViewEditor;
@@ -0,0 +1,37 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["onEdit", "components", "editable", "displayDataTypes"];
4
+ import { forwardRef } from 'react';
5
+ import JsonView from '../';
6
+ import { ObjectKey } from './objectKey';
7
+ import { ReValue } from './value';
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ var JsonViewEditor = /*#__PURE__*/forwardRef((props, ref) => {
10
+ var {
11
+ onEdit,
12
+ components,
13
+ editable = true,
14
+ displayDataTypes = true
15
+ } = props,
16
+ reset = _objectWithoutPropertiesLoose(props, _excluded);
17
+ var comps = _extends({}, components, {
18
+ objectKey: reprops => /*#__PURE__*/_jsx(ObjectKey, _extends({}, reprops, {
19
+ editableValue: editable,
20
+ onEdit: onEdit,
21
+ render: components == null ? void 0 : components.objectKey
22
+ })),
23
+ value: reprops => {
24
+ return /*#__PURE__*/_jsx(ReValue, _extends({}, reprops, {
25
+ editableValue: editable,
26
+ displayDataTypes: displayDataTypes,
27
+ onEdit: onEdit
28
+ }));
29
+ }
30
+ });
31
+ return /*#__PURE__*/_jsx(JsonView, _extends({}, reset, {
32
+ displayDataTypes: false,
33
+ components: comps,
34
+ ref: ref
35
+ }));
36
+ });
37
+ export default JsonViewEditor;
@@ -0,0 +1,11 @@
1
+ import { FC } from 'react';
2
+ import { SemicolonProps } from '../semicolon';
3
+ import { JsonViewEditorProps } from './';
4
+ export interface ObjectKeyProps<T extends object> extends SemicolonProps {
5
+ onEdit?: JsonViewEditorProps<T>['onEdit'];
6
+ render?: (props: SemicolonProps & {
7
+ ref?: React.RefObject<HTMLElement>;
8
+ }) => React.ReactNode;
9
+ editableValue?: boolean;
10
+ }
11
+ export declare const ObjectKey: FC<ObjectKeyProps<object>>;
@@ -0,0 +1,122 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
+ var _excluded = ["className", "value", "keyName", "parentName", "quotes", "label", "editableValue", "onEdit", "highlightUpdates", "render"];
4
+ import { useEffect, useRef, useState } from 'react';
5
+ import { useHighlight } from '../semicolon';
6
+ import { Label } from '../value';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export var ObjectKey = props => {
9
+ var {
10
+ className,
11
+ value,
12
+ keyName,
13
+ parentName,
14
+ quotes,
15
+ label,
16
+ editableValue,
17
+ onEdit,
18
+ highlightUpdates = true,
19
+ render
20
+ } = props,
21
+ reset = _objectWithoutPropertiesLoose(props, _excluded);
22
+ var [editable, setEditable] = useState(false);
23
+ var [curentLabel, setCurentLabel] = useState(label);
24
+ useEffect(() => setCurentLabel(label), [label]);
25
+ var $edit = useRef(null);
26
+ useHighlight({
27
+ value,
28
+ highlightUpdates: highlightUpdates,
29
+ highlightContainer: $edit
30
+ });
31
+ var click = evn => {
32
+ evn.stopPropagation();
33
+ if (!editableValue) return;
34
+ if (typeof keyName !== 'string') return;
35
+ if (editable) return;
36
+ setEditable(true);
37
+ if ($edit.current) {
38
+ var _$edit$current;
39
+ $edit.current.contentEditable = 'true';
40
+ (_$edit$current = $edit.current) == null ? void 0 : _$edit$current.focus();
41
+ }
42
+ };
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
+ };
59
+ var focus = () => {
60
+ if ($edit.current) {
61
+ var _$edit$current3;
62
+ $edit.current.contentEditable = 'true';
63
+ (_$edit$current3 = $edit.current) == null ? void 0 : _$edit$current3.focus();
64
+ }
65
+ };
66
+ var keyDown = evn => {
67
+ if (evn.key === 'Enter') {
68
+ evn.stopPropagation();
69
+ evn.preventDefault();
70
+ $edit.current.contentEditable = 'false';
71
+ }
72
+ };
73
+ useEffect(() => {
74
+ if ($edit.current) {
75
+ $edit.current.addEventListener("paste", e => {
76
+ e.preventDefault();
77
+ // @ts-ignore
78
+ var text = e.clipboardData.getData("text/plain");
79
+ document.execCommand("insertHTML", false, text);
80
+ });
81
+ }
82
+ }, [$edit]);
83
+ var style = {
84
+ minWidth: 34,
85
+ minHeight: 18,
86
+ paddingInline: 3,
87
+ display: 'inline-block'
88
+ };
89
+ var content = typeof keyName === 'string' ? "" + quotes + curentLabel + quotes : curentLabel;
90
+ var spanProps = {
91
+ onClick: click,
92
+ onFocus: focus,
93
+ onBlur: blur,
94
+ onKeyDown: keyDown,
95
+ style: editable ? style : {},
96
+ contentEditable: editable,
97
+ spellCheck: false,
98
+ autoFocus: editable,
99
+ suppressContentEditableWarning: true,
100
+ children: editable ? curentLabel : content
101
+ };
102
+ if (render) {
103
+ spanProps.value = value;
104
+ spanProps.keyName = keyName;
105
+ spanProps.parentName = parentName;
106
+ return render(_extends({
107
+ className
108
+ }, reset, spanProps, {
109
+ parentName,
110
+ label: curentLabel,
111
+ children: editable ? curentLabel : content,
112
+ ref: $edit
113
+ }));
114
+ }
115
+ return /*#__PURE__*/_jsx(Label, _extends({
116
+ className: className
117
+ }, reset, {
118
+ autoFocus: editable
119
+ }, spanProps, {
120
+ ref: $edit
121
+ }));
122
+ };
@@ -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;