@uiw/react-json-view 2.0.0-alpha.4 → 2.0.0-alpha.40

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 (227) hide show
  1. package/README.md +279 -39
  2. package/basic.d.ts +4 -0
  3. package/cjs/Container.d.ts +2 -0
  4. package/cjs/Container.js +15 -6
  5. package/cjs/arrow/TriangleArrow.js +1 -1
  6. package/cjs/comps/Copied.d.ts +3 -4
  7. package/cjs/comps/Copied.js +61 -18
  8. package/cjs/comps/KeyValues.d.ts +2 -4
  9. package/cjs/comps/KeyValues.js +73 -28
  10. package/cjs/comps/NestedClose.d.ts +2 -2
  11. package/cjs/comps/NestedClose.js +42 -12
  12. package/cjs/comps/NestedOpen.d.ts +2 -3
  13. package/cjs/comps/NestedOpen.js +42 -20
  14. package/cjs/comps/Value.d.ts +2 -2
  15. package/cjs/comps/Value.js +5 -7
  16. package/cjs/comps/useIdCompat.d.ts +1 -0
  17. package/cjs/comps/useIdCompat.js +14 -0
  18. package/cjs/editor/KeyName.d.ts +2 -0
  19. package/cjs/editor/KeyName.js +82 -0
  20. package/cjs/editor/index.d.ts +18 -0
  21. package/cjs/editor/index.js +44 -0
  22. package/cjs/editor/store.d.ts +27 -0
  23. package/cjs/editor/store.js +23 -0
  24. package/cjs/index.d.ts +26 -4
  25. package/cjs/index.js +17 -7
  26. package/cjs/section/Copied.d.ts +4 -1
  27. package/cjs/section/Copied.js +1 -2
  28. package/cjs/section/CountInfo.d.ts +1 -2
  29. package/cjs/section/CountInfo.js +3 -5
  30. package/cjs/section/CountInfoExtra.d.ts +1 -2
  31. package/cjs/section/CountInfoExtra.js +2 -4
  32. package/cjs/section/Ellipsis.d.ts +0 -1
  33. package/cjs/section/Ellipsis.js +4 -5
  34. package/cjs/section/KeyName.d.ts +7 -6
  35. package/cjs/section/KeyName.js +8 -6
  36. package/cjs/section/Row.d.ts +13 -0
  37. package/cjs/section/Row.js +51 -0
  38. package/cjs/store/Expands.js +2 -4
  39. package/cjs/store/Section.d.ts +12 -6
  40. package/cjs/store/Section.js +6 -4
  41. package/cjs/store/ShowTools.js +2 -4
  42. package/cjs/store/Symbols.d.ts +10 -3
  43. package/cjs/store/Symbols.js +2 -4
  44. package/cjs/store/Types.d.ts +30 -25
  45. package/cjs/store/Types.js +8 -8
  46. package/cjs/store.d.ts +12 -6
  47. package/cjs/store.js +5 -10
  48. package/cjs/symbol/Arrow.d.ts +1 -1
  49. package/cjs/symbol/Arrow.js +1 -2
  50. package/cjs/symbol/BraceLeft.d.ts +1 -1
  51. package/cjs/symbol/BraceLeft.js +1 -2
  52. package/cjs/symbol/BraceRight.d.ts +1 -1
  53. package/cjs/symbol/BraceRight.js +1 -2
  54. package/cjs/symbol/BracketsLeft.d.ts +1 -1
  55. package/cjs/symbol/BracketsLeft.js +1 -2
  56. package/cjs/symbol/BracketsRight.d.ts +1 -1
  57. package/cjs/symbol/BracketsRight.js +1 -2
  58. package/cjs/symbol/Colon.d.ts +1 -1
  59. package/cjs/symbol/Colon.js +1 -2
  60. package/cjs/symbol/Quote.d.ts +1 -1
  61. package/cjs/symbol/Quote.js +1 -2
  62. package/cjs/symbol/ValueQuote.d.ts +1 -1
  63. package/cjs/symbol/ValueQuote.js +1 -2
  64. package/cjs/symbol/index.d.ts +12 -17
  65. package/cjs/symbol/index.js +75 -30
  66. package/cjs/theme/basic.d.ts +2 -2
  67. package/cjs/theme/basic.js +4 -3
  68. package/cjs/theme/dark.d.ts +2 -2
  69. package/cjs/theme/dark.js +2 -3
  70. package/cjs/theme/github.dark.d.ts +2 -2
  71. package/cjs/theme/github.dark.js +2 -3
  72. package/cjs/theme/github.light.d.ts +2 -2
  73. package/cjs/theme/github.light.js +2 -3
  74. package/cjs/theme/gruvbox.d.ts +2 -2
  75. package/cjs/theme/gruvbox.js +2 -3
  76. package/cjs/theme/light.d.ts +2 -2
  77. package/cjs/theme/light.js +2 -3
  78. package/cjs/theme/monokai.d.ts +2 -2
  79. package/cjs/theme/monokai.js +2 -3
  80. package/cjs/theme/nord.d.ts +2 -2
  81. package/cjs/theme/nord.js +2 -3
  82. package/cjs/theme/vscode.d.ts +2 -2
  83. package/cjs/theme/vscode.js +2 -3
  84. package/cjs/types/Bigint.d.ts +1 -1
  85. package/cjs/types/Bigint.js +1 -2
  86. package/cjs/types/Date.d.ts +1 -1
  87. package/cjs/types/Date.js +1 -2
  88. package/cjs/types/False.d.ts +1 -1
  89. package/cjs/types/False.js +1 -2
  90. package/cjs/types/Float.d.ts +1 -1
  91. package/cjs/types/Float.js +1 -2
  92. package/cjs/types/Int.d.ts +1 -1
  93. package/cjs/types/Int.js +1 -2
  94. package/cjs/types/Map.d.ts +1 -1
  95. package/cjs/types/Map.js +1 -2
  96. package/cjs/types/Nan.d.ts +1 -1
  97. package/cjs/types/Nan.js +1 -2
  98. package/cjs/types/Null.d.ts +1 -1
  99. package/cjs/types/Null.js +1 -2
  100. package/cjs/types/Set.d.ts +1 -1
  101. package/cjs/types/Set.js +1 -2
  102. package/cjs/types/String.d.ts +1 -1
  103. package/cjs/types/String.js +1 -2
  104. package/cjs/types/True.d.ts +1 -1
  105. package/cjs/types/True.js +1 -2
  106. package/cjs/types/Undefined.d.ts +1 -1
  107. package/cjs/types/Undefined.js +1 -2
  108. package/cjs/types/Url.d.ts +1 -1
  109. package/cjs/types/Url.js +1 -2
  110. package/cjs/types/index.d.ts +5 -2
  111. package/cjs/types/index.js +174 -166
  112. package/cjs/utils/useHighlight.d.ts +0 -1
  113. package/cjs/utils/useRender.d.ts +1 -1
  114. package/dark.d.ts +2 -1
  115. package/editor.d.ts +22 -20
  116. package/esm/Container.d.ts +2 -0
  117. package/esm/Container.js +21 -11
  118. package/esm/arrow/TriangleArrow.js +1 -1
  119. package/esm/comps/Copied.d.ts +3 -4
  120. package/esm/comps/Copied.js +61 -19
  121. package/esm/comps/KeyValues.d.ts +2 -4
  122. package/esm/comps/KeyValues.js +71 -27
  123. package/esm/comps/NestedClose.d.ts +2 -2
  124. package/esm/comps/NestedClose.js +40 -11
  125. package/esm/comps/NestedOpen.d.ts +2 -3
  126. package/esm/comps/NestedOpen.js +47 -26
  127. package/esm/comps/Value.d.ts +2 -2
  128. package/esm/comps/Value.js +3 -3
  129. package/esm/comps/useIdCompat.d.ts +1 -0
  130. package/esm/comps/useIdCompat.js +8 -0
  131. package/esm/editor/KeyName.d.ts +2 -0
  132. package/esm/editor/KeyName.js +77 -0
  133. package/esm/editor/index.d.ts +18 -0
  134. package/esm/editor/index.js +33 -0
  135. package/esm/editor/store.d.ts +27 -0
  136. package/esm/editor/store.js +13 -0
  137. package/esm/index.d.ts +26 -4
  138. package/esm/index.js +50 -41
  139. package/esm/section/Copied.d.ts +4 -1
  140. package/esm/section/Copied.js +2 -2
  141. package/esm/section/CountInfo.d.ts +1 -2
  142. package/esm/section/CountInfo.js +4 -4
  143. package/esm/section/CountInfoExtra.d.ts +1 -2
  144. package/esm/section/CountInfoExtra.js +2 -2
  145. package/esm/section/Ellipsis.d.ts +0 -1
  146. package/esm/section/Ellipsis.js +3 -3
  147. package/esm/section/KeyName.d.ts +7 -6
  148. package/esm/section/KeyName.js +8 -4
  149. package/esm/section/Row.d.ts +13 -0
  150. package/esm/section/Row.js +47 -0
  151. package/esm/store/Section.d.ts +12 -6
  152. package/esm/store/Section.js +4 -0
  153. package/esm/store/Symbols.d.ts +10 -3
  154. package/esm/store/Symbols.js +1 -1
  155. package/esm/store/Types.d.ts +30 -25
  156. package/esm/store/Types.js +6 -4
  157. package/esm/store.d.ts +12 -6
  158. package/esm/store.js +5 -5
  159. package/esm/symbol/Arrow.d.ts +1 -1
  160. package/esm/symbol/Arrow.js +2 -2
  161. package/esm/symbol/BraceLeft.d.ts +1 -1
  162. package/esm/symbol/BraceLeft.js +2 -2
  163. package/esm/symbol/BraceRight.d.ts +1 -1
  164. package/esm/symbol/BraceRight.js +2 -2
  165. package/esm/symbol/BracketsLeft.d.ts +1 -1
  166. package/esm/symbol/BracketsLeft.js +2 -2
  167. package/esm/symbol/BracketsRight.d.ts +1 -1
  168. package/esm/symbol/BracketsRight.js +2 -2
  169. package/esm/symbol/Colon.d.ts +1 -1
  170. package/esm/symbol/Colon.js +2 -2
  171. package/esm/symbol/Quote.d.ts +1 -1
  172. package/esm/symbol/Quote.js +2 -2
  173. package/esm/symbol/ValueQuote.d.ts +1 -1
  174. package/esm/symbol/ValueQuote.js +2 -2
  175. package/esm/symbol/index.d.ts +12 -17
  176. package/esm/symbol/index.js +78 -25
  177. package/esm/theme/basic.d.ts +2 -2
  178. package/esm/theme/basic.js +2 -0
  179. package/esm/theme/dark.d.ts +2 -2
  180. package/esm/theme/github.dark.d.ts +2 -2
  181. package/esm/theme/github.light.d.ts +2 -2
  182. package/esm/theme/gruvbox.d.ts +2 -2
  183. package/esm/theme/light.d.ts +2 -2
  184. package/esm/theme/monokai.d.ts +2 -2
  185. package/esm/theme/nord.d.ts +2 -2
  186. package/esm/theme/vscode.d.ts +2 -2
  187. package/esm/types/Bigint.d.ts +1 -1
  188. package/esm/types/Bigint.js +2 -2
  189. package/esm/types/Date.d.ts +1 -1
  190. package/esm/types/Date.js +2 -2
  191. package/esm/types/False.d.ts +1 -1
  192. package/esm/types/False.js +2 -2
  193. package/esm/types/Float.d.ts +1 -1
  194. package/esm/types/Float.js +2 -2
  195. package/esm/types/Int.d.ts +1 -1
  196. package/esm/types/Int.js +2 -2
  197. package/esm/types/Map.d.ts +1 -1
  198. package/esm/types/Map.js +2 -2
  199. package/esm/types/Nan.d.ts +1 -1
  200. package/esm/types/Nan.js +2 -2
  201. package/esm/types/Null.d.ts +1 -1
  202. package/esm/types/Null.js +2 -2
  203. package/esm/types/Set.d.ts +1 -1
  204. package/esm/types/Set.js +2 -2
  205. package/esm/types/String.d.ts +1 -1
  206. package/esm/types/String.js +2 -2
  207. package/esm/types/True.d.ts +1 -1
  208. package/esm/types/True.js +2 -2
  209. package/esm/types/Undefined.d.ts +1 -1
  210. package/esm/types/Undefined.js +2 -2
  211. package/esm/types/Url.d.ts +1 -1
  212. package/esm/types/Url.js +2 -2
  213. package/esm/types/index.d.ts +5 -2
  214. package/esm/types/index.js +148 -131
  215. package/esm/utils/useHighlight.d.ts +0 -1
  216. package/esm/utils/useRender.d.ts +1 -1
  217. package/esm/utils/useRender.js +3 -3
  218. package/githubDark.d.ts +4 -0
  219. package/githubLight.d.ts +4 -0
  220. package/gruvbox.d.ts +4 -0
  221. package/light.d.ts +2 -1
  222. package/monokai.d.ts +4 -0
  223. package/nord.d.ts +4 -0
  224. package/package.json +11 -5
  225. package/triangle-arrow.d.ts +2 -2
  226. package/triangle-solid-arrow.d.ts +2 -2
  227. package/vscode.d.ts +4 -0
package/dark.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  declare module '@uiw/react-json-view/dark' {
2
- export const darkTheme: import('react').CSSProperties;
2
+ import type * as CSS from 'csstype';
3
+ export const darkTheme: CSS.Properties<string | number>;
3
4
  }
package/editor.d.ts CHANGED
@@ -2,35 +2,37 @@
2
2
 
3
3
  declare module '@uiw/react-json-view/editor' {
4
4
  import { JsonViewProps } from '@uiw/react-json-view';
5
- import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
5
+ // import type { CountInfoExtraProps } from '@uiw/react-json-view/cjs/editor/countInfoExtra';
6
6
  type Option = {
7
- value: string;
8
- prevValue: string;
9
- keyName: string | number;
7
+ value: string;
8
+ prevValue: string;
9
+ keyName: string | number;
10
10
  };
11
11
 
12
12
  export interface JsonViewEditorProps<T extends object> extends JsonViewProps<T> {
13
13
  /** Callback when value edit functionality */
14
14
  onEdit?: (option: {
15
- value: unknown;
16
- oldValue: unknown;
17
- keyName?: string | number;
18
- parentName?: string | number;
19
- type?: 'value' | 'key';
15
+ value: unknown;
16
+ oldValue: unknown;
17
+ keyName?: string | number;
18
+ parentName?: string | number;
19
+ type?: 'value' | 'key';
20
20
  }) => void;
21
- /**
22
- * When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
23
- * @returns {boolean} Returning false from onAdd will prevent the change from being made.
24
- */
25
- onAdd?: CountInfoExtraProps<T>['onAdd'];
26
- /**
27
- * When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
28
- * @returns Returning false from onDelete will prevent the change from being made.
29
- */
30
- onDelete?: CountInfoExtraProps<T>['onDelete'];
21
+ // /**
22
+ // * When a callback function is passed in, add functionality is enabled. The callback is invoked before additions are completed.
23
+ // * @returns {boolean} Returning false from onAdd will prevent the change from being made.
24
+ // */
25
+ // onAdd?: CountInfoExtraProps<T>['onAdd'];
26
+ // /**
27
+ // * When a callback function is passed in, delete functionality is enabled. The callback is invoked before deletions are completed.
28
+ // * @returns Returning false from onDelete will prevent the change from being made.
29
+ // */
30
+ // onDelete?: CountInfoExtraProps<T>['onDelete'];
31
31
  /** Whether enable edit feature. @default true */
32
32
  editable?: boolean;
33
33
  }
34
- const JsonViewEditor: import("react").ForwardRefExoticComponent<Omit<JsonViewEditorProps<object>, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
34
+ const JsonViewEditor: import('react').ForwardRefExoticComponent<
35
+ Omit<JsonViewEditorProps<object>, 'ref'> & import('react').RefAttributes<HTMLDivElement>
36
+ >;
35
37
  export default JsonViewEditor;
36
38
  }
@@ -6,5 +6,7 @@ export interface ContainerProps<T extends object> extends React.HTMLAttributes<H
6
6
  level?: number;
7
7
  value?: T;
8
8
  initialValue?: T;
9
+ /** Index of the parent `keyName` */
10
+ keys?: (string | number)[];
9
11
  }
10
12
  export declare const Container: React.ForwardRefExoticComponent<ContainerProps<object> & React.RefAttributes<HTMLDivElement>>;
package/esm/Container.js CHANGED
@@ -1,24 +1,26 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keyName"];
4
- import React, { forwardRef, useId } from 'react';
5
- import { NestedClose } from './comps/NestedClose';
6
- import { NestedOpen } from './comps/NestedOpen';
7
- import { KeyValues } from './comps/KeyValues';
8
- import { useShowToolsDispatch } from './store/ShowTools';
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- import { jsxs as _jsxs } from "react/jsx-runtime";
3
+ var _excluded = ["className", "children", "parentValue", "keyid", "level", "value", "initialValue", "keys", "keyName"];
4
+ import React, { forwardRef } from 'react';
5
+ import { NestedClose } from "./comps/NestedClose.js";
6
+ import { NestedOpen } from "./comps/NestedOpen.js";
7
+ import { KeyValues } from "./comps/KeyValues.js";
8
+ import { useIdCompat } from "./comps/useIdCompat.js";
9
+ import { useShowToolsDispatch } from "./store/ShowTools.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
11
  export var Container = /*#__PURE__*/forwardRef((props, ref) => {
12
12
  var {
13
13
  className = '',
14
+ parentValue,
14
15
  level = 1,
15
16
  value,
16
17
  initialValue,
18
+ keys,
17
19
  keyName
18
20
  } = props,
19
21
  elmProps = _objectWithoutPropertiesLoose(props, _excluded);
20
22
  var dispatch = useShowToolsDispatch();
21
- var subkeyid = useId();
23
+ var subkeyid = useIdCompat();
22
24
  var defaultClassNames = [className, 'w-rjv-inner'].filter(Boolean).join(' ');
23
25
  var reset = {
24
26
  onMouseEnter: () => dispatch({
@@ -36,16 +38,24 @@ export var Container = /*#__PURE__*/forwardRef((props, ref) => {
36
38
  expandKey: subkeyid,
37
39
  value: value,
38
40
  level: level,
41
+ keys: keys,
42
+ parentValue: parentValue,
39
43
  keyName: keyName,
40
44
  initialValue: initialValue
41
45
  }), /*#__PURE__*/_jsx(KeyValues, {
42
46
  expandKey: subkeyid,
43
47
  value: value,
44
- level: level
48
+ level: level,
49
+ keys: keys,
50
+ parentValue: parentValue,
51
+ keyName: keyName
45
52
  }), /*#__PURE__*/_jsx(NestedClose, {
46
53
  expandKey: subkeyid,
47
54
  value: value,
48
- level: level
55
+ level: level,
56
+ keys: keys,
57
+ parentValue: parentValue,
58
+ keyName: keyName
49
59
  })]
50
60
  }));
51
61
  });
@@ -13,7 +13,7 @@ export function TriangleArrow(props) {
13
13
  height: '1em',
14
14
  width: '1em',
15
15
  userSelect: 'none',
16
- display: 'flex'
16
+ display: 'inline-flex'
17
17
  }, style);
18
18
  return /*#__PURE__*/_jsx("svg", _extends({
19
19
  viewBox: "0 0 24 24",
@@ -1,14 +1,13 @@
1
- /// <reference types="react" />
1
+ import { type SectionElementResult } from '../store/Section';
2
2
  import { type TagType } from '../store/Types';
3
3
  export type CopiedOption<T extends object> = {
4
4
  value?: T;
5
5
  copied: boolean;
6
6
  setCopied: React.Dispatch<React.SetStateAction<boolean>>;
7
7
  };
8
- export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement> {
9
- value?: T;
10
- keyName: string | number;
8
+ export interface CopiedProps<T extends object> extends React.SVGProps<SVGSVGElement>, SectionElementResult<T> {
11
9
  expandKey: string;
10
+ beforeCopy?: (copyText: string, keyName?: string | number, value?: T, parentValue?: T, expandKey?: string, keys?: (number | string)[]) => string;
12
11
  }
13
12
  export declare const Copied: {
14
13
  <T extends object, K extends TagType>(props: CopiedProps<T>): string | number | true | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null;
@@ -1,22 +1,27 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
3
- var _excluded = ["keyName", "value", "expandKey"],
3
+ var _excluded = ["keyName", "value", "parentValue", "expandKey", "keys", "beforeCopy"],
4
4
  _excluded2 = ["as", "render"];
5
5
  import { useState } from 'react';
6
- import { useStore } from '../store';
7
- import { useShowToolsStore } from '../store/ShowTools';
8
- import { useSectionStore } from '../store/Section';
6
+ import { useStore } from "../store.js";
7
+ import { useSectionStore } from "../store/Section.js";
8
+ import { useShowToolsStore } from "../store/ShowTools.js";
9
+ import { bigIntToString } from "../types/index.js";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  export var Copied = props => {
11
12
  var {
12
13
  keyName,
13
14
  value,
14
- expandKey
15
+ parentValue,
16
+ expandKey,
17
+ keys,
18
+ beforeCopy
15
19
  } = props,
16
20
  other = _objectWithoutPropertiesLoose(props, _excluded);
17
21
  var {
18
22
  onCopied,
19
- enableClipboard
23
+ enableClipboard,
24
+ beforeCopy: globalBeforeCopy
20
25
  } = useStore();
21
26
  var showTools = useShowToolsStore();
22
27
  var isShowTools = showTools[expandKey];
@@ -24,21 +29,51 @@ export var Copied = props => {
24
29
  var {
25
30
  Copied: Comp = {}
26
31
  } = useSectionStore();
32
+ var sectionBeforeCopy = Comp == null ? void 0 : Comp.beforeCopy;
27
33
  if (enableClipboard === false || !isShowTools) return null;
28
34
  var click = event => {
29
35
  event.stopPropagation();
30
- var copyText = JSON.stringify(value, (key, value) => {
31
- if (typeof value === 'bigint') {
32
- return value.toString();
36
+ var copyText = '';
37
+ if (typeof value === 'number' && value === Infinity) {
38
+ copyText = 'Infinity';
39
+ } else if (typeof value === 'number' && isNaN(value)) {
40
+ copyText = 'NaN';
41
+ } else if (typeof value === 'bigint') {
42
+ copyText = bigIntToString(value);
43
+ } else if (value instanceof Date) {
44
+ copyText = value.toLocaleString();
45
+ } else {
46
+ copyText = JSON.stringify(value, (_, v) => typeof v === 'bigint' ? bigIntToString(v) : v, 2);
47
+ }
48
+
49
+ // Apply beforeCopy transformation if provided
50
+ // Priority: component prop > section prop > global prop
51
+ var finalBeforeCopy = beforeCopy || sectionBeforeCopy || globalBeforeCopy;
52
+ if (finalBeforeCopy && typeof finalBeforeCopy === 'function') {
53
+ copyText = finalBeforeCopy(copyText, keyName, value, parentValue, expandKey, keys);
54
+ }
55
+ onCopied && onCopied(copyText, value);
56
+ setCopied(true);
57
+ var _clipboard = navigator.clipboard || {
58
+ writeText(text) {
59
+ return new Promise((reslove, reject) => {
60
+ var textarea = document.createElement('textarea');
61
+ textarea.style.position = 'absolute';
62
+ textarea.style.opacity = '0';
63
+ textarea.style.left = '-99999999px';
64
+ textarea.value = text;
65
+ document.body.appendChild(textarea);
66
+ textarea.select();
67
+ if (!document.execCommand('copy')) {
68
+ reject();
69
+ } else {
70
+ reslove();
71
+ }
72
+ textarea.remove();
73
+ });
33
74
  }
34
- return value;
35
- }, 2);
36
- if (typeof value === 'number' && value === Infinity) copyText = 'Infinity';
37
- if (typeof value === 'number' && isNaN(value)) copyText = 'NaN';
38
- if (typeof value === 'bigint') copyText = value + 'n';
39
- navigator.clipboard.writeText(copyText).then(() => {
40
- onCopied && onCopied(copyText, value);
41
- setCopied(true);
75
+ };
76
+ _clipboard.writeText(copyText).then(() => {
42
77
  var timer = setTimeout(() => {
43
78
  setCopied(false);
44
79
  clearTimeout(timer);
@@ -46,6 +81,9 @@ export var Copied = props => {
46
81
  }).catch(error => {});
47
82
  };
48
83
  var svgProps = {
84
+ style: {
85
+ display: 'inline-flex'
86
+ },
49
87
  fill: copied ? 'var(--w-rjv-copied-success-color, #28a745)' : 'var(--w-rjv-copied-color, currentColor)',
50
88
  onClick: click
51
89
  };
@@ -53,13 +91,17 @@ export var Copied = props => {
53
91
  render
54
92
  } = Comp,
55
93
  reset = _objectWithoutPropertiesLoose(Comp, _excluded2);
56
- var elmProps = _extends({}, reset, other, svgProps);
94
+ var elmProps = _extends({}, reset, other, svgProps, {
95
+ style: _extends({}, reset.style, other.style, svgProps.style)
96
+ });
57
97
  var isRender = render && typeof render === 'function';
58
98
  var child = isRender && render(_extends({}, elmProps, {
59
99
  'data-copied': copied
60
100
  }), {
61
101
  value,
62
- keyName
102
+ keyName,
103
+ keys,
104
+ parentValue
63
105
  });
64
106
  if (child) return child;
65
107
  if (copied) {
@@ -1,7 +1,5 @@
1
- interface KeyValuesProps<T extends object> {
2
- keyName?: string | number;
3
- value?: T;
4
- parentValue?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ interface KeyValuesProps<T extends object> extends SectionElementResult<T> {
5
3
  expandKey?: string;
6
4
  level: number;
7
5
  }
@@ -1,33 +1,56 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import { Fragment, useId, useRef } from 'react';
3
- import { useStore } from '../store';
4
- import { useExpandsStore } from '../store/Expands';
5
- import { useShowToolsDispatch } from '../store/ShowTools';
6
- import { Value } from './Value';
7
- import { KeyNameComp } from '../section/KeyName';
8
- import { Container } from '../Container';
9
- import { Quote, Colon } from '../symbol';
10
- import { useHighlight } from '../utils/useHighlight';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Fragment, useRef } from 'react';
3
+ import { useStore } from "../store.js";
4
+ import { useExpandsStore } from "../store/Expands.js";
5
+ import { useShowToolsDispatch } from "../store/ShowTools.js";
6
+ import { Value } from "./Value.js";
7
+ import { KeyNameComp } from "../section/KeyName.js";
8
+ import { RowComp } from "../section/Row.js";
9
+ import { Container } from "../Container.js";
10
+ import { Quote, Colon } from "../symbol/index.js";
11
+ import { useHighlight } from "../utils/useHighlight.js";
12
+ import { Copied } from "../comps/Copied.js";
13
+ import { useIdCompat } from "../comps/useIdCompat.js";
14
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
15
  export var KeyValues = props => {
14
16
  var _expands$expandKey;
15
17
  var {
18
+ keyName,
16
19
  value,
17
20
  expandKey = '',
18
- level
21
+ level,
22
+ keys = [],
23
+ parentValue
19
24
  } = props;
20
25
  var expands = useExpandsStore();
21
26
  var {
22
27
  objectSortKeys,
23
28
  indentWidth,
24
- collapsed
29
+ collapsed,
30
+ shouldExpandNodeInitially
25
31
  } = useStore();
26
- var isMyArray = Array.isArray(value);
27
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
32
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
33
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
34
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
35
+ value,
36
+ keys,
37
+ level,
38
+ keyName,
39
+ parentValue
40
+ });
41
+ if (shouldExpandNodeInitially && collapsed === false) {
42
+ if (expands[expandKey] === undefined && !shouldExpand) {
43
+ return null;
44
+ }
45
+ } else {
46
+ if (expands[expandKey] === undefined && shouldExpand) {
47
+ return null;
48
+ }
49
+ }
28
50
  if (isExpanded) {
29
51
  return null;
30
52
  }
53
+ var isMyArray = Array.isArray(value);
31
54
  // object
32
55
  var entries = isMyArray ? Object.entries(value).map(m => [Number(m[0]), m[1]]) : Object.entries(value);
33
56
  if (objectSortKeys) {
@@ -54,6 +77,7 @@ export var KeyValues = props => {
54
77
  return /*#__PURE__*/_jsx(KeyValuesItem, {
55
78
  parentValue: value,
56
79
  keyName: key,
80
+ keys: [...keys, key],
57
81
  value: val,
58
82
  level: level
59
83
  }, idx);
@@ -64,6 +88,8 @@ KeyValues.displayName = 'JVR.KeyValues';
64
88
  export var KayName = props => {
65
89
  var {
66
90
  keyName,
91
+ parentValue,
92
+ keys,
67
93
  value
68
94
  } = props;
69
95
  var {
@@ -76,21 +102,25 @@ export var KayName = props => {
76
102
  highlightUpdates,
77
103
  highlightContainer
78
104
  });
105
+ var compProps = {
106
+ keyName,
107
+ value,
108
+ keys,
109
+ parentValue
110
+ };
79
111
  return /*#__PURE__*/_jsxs(Fragment, {
80
112
  children: [/*#__PURE__*/_jsxs("span", {
81
113
  ref: highlightContainer,
82
- children: [/*#__PURE__*/_jsx(Quote, {
114
+ children: [/*#__PURE__*/_jsx(Quote, _extends({
83
115
  isNumber: isNumber,
84
116
  "data-placement": "left"
85
- }), /*#__PURE__*/_jsx(KeyNameComp, {
86
- keyName: keyName,
87
- value: value,
117
+ }, compProps)), /*#__PURE__*/_jsx(KeyNameComp, _extends({}, compProps, {
88
118
  children: keyName
89
- }), /*#__PURE__*/_jsx(Quote, {
119
+ })), /*#__PURE__*/_jsx(Quote, _extends({
90
120
  isNumber: isNumber,
91
121
  "data-placement": "right"
92
- })]
93
- }), /*#__PURE__*/_jsx(Colon, {})]
122
+ }, compProps))]
123
+ }), /*#__PURE__*/_jsx(Colon, _extends({}, compProps))]
94
124
  });
95
125
  };
96
126
  KayName.displayName = 'JVR.KayName';
@@ -99,10 +129,11 @@ export var KeyValuesItem = props => {
99
129
  keyName,
100
130
  value,
101
131
  parentValue,
102
- level = 0
132
+ level = 0,
133
+ keys = []
103
134
  } = props;
104
135
  var dispatch = useShowToolsDispatch();
105
- var subkeyid = useId();
136
+ var subkeyid = useIdCompat();
106
137
  var isMyArray = Array.isArray(value);
107
138
  var isMySet = value instanceof Set;
108
139
  var isMyMap = value instanceof Map;
@@ -117,6 +148,7 @@ export var KeyValuesItem = props => {
117
148
  value: myValue,
118
149
  parentValue: parentValue,
119
150
  initialValue: value,
151
+ keys: keys,
120
152
  level: level + 1
121
153
  });
122
154
  }
@@ -128,15 +160,27 @@ export var KeyValuesItem = props => {
128
160
  [subkeyid]: false
129
161
  })
130
162
  };
131
- return /*#__PURE__*/_jsxs("div", _extends({
132
- className: "w-rjv-line"
163
+ return /*#__PURE__*/_jsxs(RowComp, _extends({
164
+ className: "w-rjv-line",
165
+ value: value,
166
+ keyName: keyName,
167
+ keys: keys,
168
+ parentValue: parentValue
133
169
  }, reset, {
134
170
  children: [/*#__PURE__*/_jsx(KayName, {
135
171
  keyName: keyName,
136
- value: value
172
+ value: value,
173
+ keys: keys,
174
+ parentValue: parentValue
137
175
  }), /*#__PURE__*/_jsx(Value, {
138
176
  keyName: keyName,
139
177
  value: value,
178
+ keys: keys
179
+ }), /*#__PURE__*/_jsx(Copied, {
180
+ keyName: keyName,
181
+ value: value,
182
+ keys: keys,
183
+ parentValue: parentValue,
140
184
  expandKey: subkeyid
141
185
  })]
142
186
  }));
@@ -1,5 +1,5 @@
1
- interface NestedCloseProps<T extends object> {
2
- value?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ interface NestedCloseProps<T extends object> extends SectionElementResult<T> {
3
3
  expandKey: string;
4
4
  level: number;
5
5
  }
@@ -1,21 +1,41 @@
1
- import { useStore } from '../store';
2
- import { useExpandsStore } from '../store/Expands';
3
- import { BracketsClose } from '../symbol';
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import { useStore } from "../store.js";
3
+ import { useExpandsStore } from "../store/Expands.js";
4
+ import { BracketsClose } from "../symbol/index.js";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
6
  export var NestedClose = props => {
6
7
  var _expands$expandKey;
7
8
  var {
9
+ keyName,
8
10
  value,
9
11
  expandKey,
10
- level
12
+ parentValue,
13
+ level,
14
+ keys = []
11
15
  } = props;
12
16
  var expands = useExpandsStore();
13
- var isArray = Array.isArray(value);
14
17
  var {
15
- collapsed
18
+ collapsed,
19
+ shouldExpandNodeInitially
16
20
  } = useStore();
17
- var isMySet = value instanceof Set;
18
- var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
21
+ var defaultExpanded = typeof collapsed === 'boolean' ? collapsed : typeof collapsed === 'number' ? level > collapsed : false;
22
+ var isExpanded = (_expands$expandKey = expands[expandKey]) != null ? _expands$expandKey : shouldExpandNodeInitially ? false : defaultExpanded;
23
+ var shouldExpand = shouldExpandNodeInitially && shouldExpandNodeInitially(!isExpanded, {
24
+ value,
25
+ keys,
26
+ level,
27
+ keyName,
28
+ parentValue
29
+ });
30
+ if (shouldExpandNodeInitially && collapsed === false) {
31
+ if (expands[expandKey] === undefined && !shouldExpand) {
32
+ return null;
33
+ }
34
+ } else {
35
+ if (expands[expandKey] === undefined && shouldExpand) {
36
+ return null;
37
+ }
38
+ }
19
39
  var len = Object.keys(value).length;
20
40
  if (isExpanded || len === 0) {
21
41
  return null;
@@ -23,12 +43,21 @@ export var NestedClose = props => {
23
43
  var style = {
24
44
  paddingLeft: 4
25
45
  };
46
+ var compProps = {
47
+ keyName,
48
+ value,
49
+ keys,
50
+ parentValue
51
+ };
52
+ var isArray = Array.isArray(value);
53
+ var isMySet = value instanceof Set;
26
54
  return /*#__PURE__*/_jsx("div", {
27
55
  style: style,
28
- children: /*#__PURE__*/_jsx(BracketsClose, {
29
- isBrackets: isArray || isMySet,
56
+ children: /*#__PURE__*/_jsx(BracketsClose, _extends({
57
+ isBrackets: isArray || isMySet
58
+ }, compProps, {
30
59
  isVisiable: true
31
- })
60
+ }))
32
61
  });
33
62
  };
34
63
  NestedClose.displayName = 'JVR.NestedClose';
@@ -1,6 +1,5 @@
1
- export interface NestedOpenProps<T extends object> {
2
- keyName?: string | number;
3
- value?: T;
1
+ import { type SectionElementResult } from '../store/Section';
2
+ export interface NestedOpenProps<T extends object> extends SectionElementResult<T> {
4
3
  initialValue?: T;
5
4
  expandKey: string;
6
5
  level: number;