@dxos/react-ui-syntax-highlighter 0.8.4-main.406dc2a → 0.8.4-main.40e3dcdf1b

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.
@@ -1,42 +1,38 @@
1
1
  // src/Json/Json.tsx
2
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
3
- import jp from "jsonpath";
4
- import React2, { useEffect, useState } from "react";
2
+ import { JSONPath } from "jsonpath-plus";
3
+ import React2, { forwardRef, useEffect, useState } from "react";
5
4
  import { Input } from "@dxos/react-ui";
5
+ import { createReplacer, safeStringify } from "@dxos/util";
6
6
 
7
7
  // src/SyntaxHighlighter/index.ts
8
8
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
9
9
 
10
10
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
11
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
12
11
  import React from "react";
13
12
  import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
14
13
  import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
15
- import { useThemeContext } from "@dxos/react-ui";
16
- import { mx } from "@dxos/react-ui-theme";
14
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
15
+ import { mx } from "@dxos/ui-theme";
17
16
  var zeroWidthSpace = "\u200B";
18
17
  var SyntaxHighlighter = ({ classNames, children, language = "text", fallback = zeroWidthSpace, ...props }) => {
19
- var _effect = _useSignals();
20
- try {
21
- const { themeMode } = useThemeContext();
22
- return /* @__PURE__ */ React.createElement("div", {
23
- className: mx("flex is-full p-1 overflow-hidden text-baseText", classNames)
24
- }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
25
- className: "is-full overflow-auto scrollbar-thin",
26
- language: languages[language] || language,
27
- style: themeMode === "dark" ? dark : light,
28
- customStyle: {
29
- background: "unset",
30
- border: "none",
31
- boxShadow: "none",
32
- padding: 0,
33
- margin: 0
34
- },
35
- ...props
36
- }, children || fallback));
37
- } finally {
38
- _effect.f();
39
- }
18
+ const { themeMode } = useThemeContext();
19
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
20
+ thin: true,
21
+ classNames: mx("p1", classNames)
22
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React.createElement("div", {
23
+ role: "none"
24
+ }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
25
+ language: languages[language] || language,
26
+ style: themeMode === "dark" ? dark : light,
27
+ customStyle: {
28
+ background: "unset",
29
+ border: "none",
30
+ boxShadow: "none",
31
+ padding: 0,
32
+ margin: 0
33
+ },
34
+ ...props
35
+ }, children || fallback))));
40
36
  };
41
37
  var languages = {
42
38
  js: "javascript",
@@ -44,113 +40,71 @@ var languages = {
44
40
  };
45
41
 
46
42
  // src/Json/Json.tsx
47
- var defaultClassNames = "!m-0 grow overflow-y-auto text-sm";
48
- var Json = ({ filter, ...params }) => {
49
- var _effect = _useSignals2();
50
- try {
51
- if (filter) {
52
- return /* @__PURE__ */ React2.createElement(JsonFilter, params);
53
- }
54
- const { classNames, data, replacer, testId } = params;
55
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
56
- language: "json",
57
- classNames: [
58
- defaultClassNames,
59
- classNames
60
- ],
61
- "data-testid": testId
62
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2));
63
- } finally {
64
- _effect.f();
65
- }
66
- };
67
- var JsonFilter = ({ classNames, data: initialData, replacer, testId }) => {
68
- var _effect = _useSignals2();
69
- try {
70
- const [data, setData] = useState(initialData);
71
- const [text, setText] = useState("");
72
- const [error, setError] = useState(null);
73
- useEffect(() => {
74
- if (!initialData || !text.trim().length) {
75
- setData(initialData);
76
- } else {
77
- try {
78
- setData(jp.query(initialData, text));
79
- setError(null);
80
- } catch (err) {
81
- setData(initialData);
82
- setError(err);
83
- }
84
- }
85
- }, [
86
- initialData,
87
- text
88
- ]);
89
- return /* @__PURE__ */ React2.createElement("div", {
90
- className: "flex flex-col grow overflow-hidden"
91
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
92
- validationValence: error ? "error" : "success"
93
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
94
- classNames: [
95
- "p-1 px-2 font-mono",
96
- error && "border-red-500"
97
- ],
98
- variant: "subdued",
99
- value: text,
100
- onChange: (event) => setText(event.target.value),
101
- placeholder: "JSONPath (e.g., $.graph.nodes)"
102
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
103
- language: "json",
104
- classNames: [
105
- defaultClassNames,
106
- classNames
107
- ],
108
- "data-testid": testId
109
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2)));
110
- } finally {
111
- _effect.f();
43
+ var Json = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
44
+ if (props.filter) {
45
+ return /* @__PURE__ */ React2.createElement(JsonFilter, props);
112
46
  }
113
- };
114
- var createReplacer = ({ omit, parse, maxDepth, maxArrayLen, maxStringLen }) => {
115
- let currentDepth = 0;
116
- const depthMap = /* @__PURE__ */ new WeakMap();
117
- return function(key, value) {
118
- if (key === "") {
119
- currentDepth = 0;
120
- } else if (this && typeof this === "object") {
121
- const parentDepth = depthMap.get(this) ?? 0;
122
- currentDepth = parentDepth + 1;
123
- }
124
- if (value && typeof value === "object") {
125
- depthMap.set(value, currentDepth);
126
- if (maxDepth != null && currentDepth >= maxDepth) {
127
- return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
128
- }
129
- }
130
- if (omit?.includes(key)) {
131
- return void 0;
132
- }
133
- if (parse?.includes(key) && typeof value === "string") {
47
+ const { classNames, data, replacer, testId } = props;
48
+ return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
49
+ language: "json",
50
+ classNames: [
51
+ "w-full overflow-y-auto text-sm",
52
+ classNames
53
+ ],
54
+ "data-testid": testId,
55
+ ref: forwardedRef
56
+ }, safeStringify(data, replacer && createReplacer(replacer), 2));
57
+ });
58
+ var JsonFilter = /* @__PURE__ */ forwardRef(({ classNames, data: initialData, replacer, testId }, forwardedRef) => {
59
+ const [data, setData] = useState(initialData);
60
+ const [text, setText] = useState("");
61
+ const [error, setError] = useState(null);
62
+ useEffect(() => {
63
+ if (!initialData || !text.trim().length) {
64
+ setData(initialData);
65
+ } else {
134
66
  try {
135
- return JSON.parse(value);
136
- } catch {
137
- return value;
67
+ setData(JSONPath({
68
+ path: text,
69
+ json: initialData
70
+ }));
71
+ setError(null);
72
+ } catch (err) {
73
+ setData(initialData);
74
+ setError(err);
138
75
  }
139
76
  }
140
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
141
- return `[length: ${value.length}]`;
142
- }
143
- if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
144
- return value.slice(0, maxStringLen) + "...";
145
- }
146
- return value;
147
- };
148
- };
77
+ }, [
78
+ initialData,
79
+ text
80
+ ]);
81
+ return /* @__PURE__ */ React2.createElement("div", {
82
+ className: "flex flex-col h-full overflow-hidden",
83
+ ref: forwardedRef
84
+ }, /* @__PURE__ */ React2.createElement(Input.Root, {
85
+ validationValence: error ? "error" : "success"
86
+ }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
87
+ classNames: [
88
+ "p-1 px-2 font-mono",
89
+ error && "border-rose-500"
90
+ ],
91
+ variant: "subdued",
92
+ value: text,
93
+ placeholder: "JSONPath (e.g., $.graph.nodes)",
94
+ onChange: (event) => setText(event.target.value)
95
+ })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
96
+ language: "json",
97
+ classNames: [
98
+ "w-full overflow-y-auto text-sm",
99
+ classNames
100
+ ],
101
+ "data-testid": testId
102
+ }, safeStringify(data, replacer && createReplacer(replacer), 2)));
103
+ });
149
104
  export {
150
105
  Json,
151
106
  JsonFilter,
152
107
  SyntaxHighlighter,
153
- createElement,
154
- createReplacer
108
+ createElement
155
109
  };
156
110
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/Json/Json.tsx", "../../../src/SyntaxHighlighter/index.ts", "../../../src/SyntaxHighlighter/SyntaxHighlighter.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// TODO(burdon): Use to jsonpath-plus.\nimport jp from 'jsonpath';\nimport React, { useEffect, useState } from 'react';\n\nimport { Input, type ThemedClassName } from '@dxos/react-ui';\n\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\n\nconst defaultClassNames = '!m-0 grow overflow-y-auto text-sm';\n\nexport type JsonProps = ThemedClassName<{\n data?: any;\n filter?: boolean;\n replacer?: CreateReplacerProps;\n testId?: string;\n}>;\n\nexport const Json = ({ filter, ...params }: JsonProps) => {\n if (filter) {\n return <JsonFilter {...params} />;\n }\n\n const { classNames, data, replacer, testId } = params;\n return (\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {JSON.stringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n );\n};\n\nexport const JsonFilter = ({ classNames, data: initialData, replacer, testId }: JsonProps) => {\n const [data, setData] = useState(initialData);\n const [text, setText] = useState('');\n const [error, setError] = useState<Error | null>(null);\n useEffect(() => {\n if (!initialData || !text.trim().length) {\n setData(initialData);\n } else {\n try {\n setData(jp.query(initialData, text));\n setError(null);\n } catch (err) {\n setData(initialData);\n setError(err as Error);\n }\n }\n }, [initialData, text]); // TODO(burdon): Need structural diff.\n\n return (\n <div className='flex flex-col grow overflow-hidden'>\n <Input.Root validationValence={error ? 'error' : 'success'}>\n <Input.TextInput\n classNames={['p-1 px-2 font-mono', error && 'border-red-500']}\n variant='subdued'\n value={text}\n onChange={(event) => setText(event.target.value)}\n placeholder='JSONPath (e.g., $.graph.nodes)'\n />\n </Input.Root>\n <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>\n {JSON.stringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n </div>\n );\n};\n\nexport type CreateReplacerProps = {\n omit?: string[];\n parse?: string[];\n maxDepth?: number;\n maxArrayLen?: number;\n maxStringLen?: number;\n};\n\nexport type JsonReplacer = (this: any, key: string, value: any) => any;\n\nexport const createReplacer = ({\n omit,\n parse,\n maxDepth,\n maxArrayLen,\n maxStringLen,\n}: CreateReplacerProps): JsonReplacer => {\n let currentDepth = 0;\n const depthMap = new WeakMap<object, number>();\n\n return function (this: any, key: string, value: any) {\n // Track depth.\n if (key === '') {\n currentDepth = 0;\n } else if (this && typeof this === 'object') {\n const parentDepth = depthMap.get(this) ?? 0;\n currentDepth = parentDepth + 1;\n }\n\n // Store depth for this object.\n if (value && typeof value === 'object') {\n depthMap.set(value, currentDepth);\n\n // Check max depth.\n if (maxDepth != null && currentDepth >= maxDepth) {\n return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;\n }\n }\n\n // Apply other filters.\n if (omit?.includes(key)) {\n return undefined;\n }\n if (parse?.includes(key) && typeof value === 'string') {\n try {\n return JSON.parse(value);\n } catch {\n return value;\n }\n }\n if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {\n return `[length: ${value.length}]`;\n }\n if (maxStringLen != null && typeof value === 'string' && value.length > maxStringLen) {\n return value.slice(0, maxStringLen) + '...';\n }\n\n return value;\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// eslint-disable-next-line no-restricted-imports\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element';\n\nexport { createElement };\n\nexport * from './SyntaxHighlighter';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\nimport { type SyntaxHighlighterProps as NaturalSyntaxHighlighterProps } from 'react-syntax-highlighter';\nimport NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-async-light';\nimport { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nexport type SyntaxHighlighterProps = ThemedClassName<\n NaturalSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\n/**\n * NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.\n * The lightweight version will load specific language parsers asynchronously.\n *\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html\n */\n// TODO(burdon): Replace with react-ui-editor (and reuse styles).\nexport const SyntaxHighlighter = ({\n classNames,\n children,\n language = 'text',\n fallback = zeroWidthSpace,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n\n return (\n <div className={mx('flex is-full p-1 overflow-hidden text-baseText', classNames)}>\n <NativeSyntaxHighlighter\n className='is-full overflow-auto scrollbar-thin'\n language={languages[language as keyof typeof languages] || language}\n style={themeMode === 'dark' ? dark : light}\n customStyle={{\n background: 'unset',\n border: 'none',\n boxShadow: 'none',\n padding: 0,\n margin: 0,\n }}\n {...props}\n >\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n );\n};\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n"],
5
- "mappings": ";;AAKA,OAAOA,QAAQ;AACf,OAAOC,UAASC,WAAWC,gBAAgB;AAE3C,SAASC,aAAmC;;;ACH5C,OAAOC,mBAAmB;;;;ACD1B,OAAOC,WAAW;AAElB,OAAOC,6BAA6B;AACpC,SAASC,eAAeC,MAAMC,eAAeC,aAAa;AAE1D,SAA+BC,uBAAuB;AACtD,SAASC,UAAU;AAEnB,IAAMC,iBAAiB;AAgBhB,IAAMC,oBAAoB,CAAC,EAChCC,YACAC,UACAC,WAAW,QACXC,WAAWL,gBACX,GAAGM,MAAAA,MACoB;;;AACvB,UAAM,EAAEC,UAAS,IAAKC,gBAAAA;AAEtB,WACE,sBAAA,cAACC,OAAAA;MAAI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pB,QAAQ;AACN,eAAOA;MACT;IACF;AACA,QAAIQ,eAAe,QAAQS,MAAMC,QAAQlB,KAAAA,KAAUA,MAAMX,SAASmB,aAAa;AAC7E,aAAO,YAAYR,MAAMX,MAAM;IACjC;AACA,QAAIoB,gBAAgB,QAAQ,OAAOT,UAAU,YAAYA,MAAMX,SAASoB,cAAc;AACpF,aAAOT,MAAMuB,MAAM,GAAGd,YAAAA,IAAgB;IACxC;AAEA,WAAOT;EACT;AACF;",
6
- "names": ["jp", "React", "useEffect", "useState", "Input", "createElement", "React", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "useThemeContext", "mx", "zeroWidthSpace", "SyntaxHighlighter", "classNames", "children", "language", "fallback", "props", "themeMode", "useThemeContext", "div", "className", "mx", "NativeSyntaxHighlighter", "languages", "style", "dark", "light", "customStyle", "background", "border", "boxShadow", "padding", "margin", "js", "ts", "defaultClassNames", "Json", "filter", "params", "React", "JsonFilter", "classNames", "data", "replacer", "testId", "SyntaxHighlighter", "language", "data-testid", "JSON", "stringify", "createReplacer", "initialData", "setData", "useState", "text", "setText", "error", "setError", "useEffect", "trim", "length", "jp", "query", "err", "div", "className", "Input", "Root", "validationValence", "TextInput", "variant", "value", "onChange", "event", "target", "placeholder", "omit", "parse", "maxDepth", "maxArrayLen", "maxStringLen", "currentDepth", "depthMap", "WeakMap", "key", "parentDepth", "get", "set", "Array", "isArray", "Object", "keys", "includes", "undefined", "slice"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { JSONPath } from 'jsonpath-plus';\nimport React, { forwardRef, useEffect, useState } from 'react';\n\nimport { Input, type ThemedClassName } from '@dxos/react-ui';\nimport { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';\n\nimport { SyntaxHighlighter } from '../SyntaxHighlighter';\n\nexport type JsonProps = ThemedClassName<{\n data?: any;\n filter?: boolean;\n replacer?: CreateReplacerProps;\n testId?: string;\n}>;\n\nexport const Json = forwardRef<HTMLDivElement, JsonProps>((props, forwardedRef) => {\n if (props.filter) {\n return <JsonFilter {...props} />;\n }\n\n const { classNames, data, replacer, testId } = props;\n return (\n <SyntaxHighlighter\n language='json'\n classNames={['w-full overflow-y-auto text-sm', classNames]}\n data-testid={testId}\n ref={forwardedRef}\n >\n {safeStringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n );\n});\n\nexport const JsonFilter = forwardRef<HTMLDivElement, JsonProps>(\n ({ classNames, data: initialData, replacer, testId }, forwardedRef) => {\n const [data, setData] = useState(initialData);\n const [text, setText] = useState('');\n const [error, setError] = useState<Error | null>(null);\n\n useEffect(() => {\n if (!initialData || !text.trim().length) {\n setData(initialData);\n } else {\n try {\n setData(JSONPath({ path: text, json: initialData }));\n setError(null);\n } catch (err) {\n setData(initialData);\n setError(err as Error);\n }\n }\n }, [initialData, text]); // TODO(burdon): Need structural diff.\n\n return (\n <div className='flex flex-col h-full overflow-hidden' ref={forwardedRef}>\n <Input.Root validationValence={error ? 'error' : 'success'}>\n <Input.TextInput\n classNames={['p-1 px-2 font-mono', error && 'border-rose-500']}\n variant='subdued'\n value={text}\n placeholder='JSONPath (e.g., $.graph.nodes)'\n onChange={(event) => setText(event.target.value)}\n />\n </Input.Root>\n <SyntaxHighlighter\n language='json'\n classNames={['w-full overflow-y-auto text-sm', classNames]}\n data-testid={testId}\n >\n {safeStringify(data, replacer && createReplacer(replacer), 2)}\n </SyntaxHighlighter>\n </div>\n );\n },\n);\n", "//\n// Copyright 2024 DXOS.org\n//\n\n// eslint-disable-next-line no-restricted-imports\nimport createElement from 'react-syntax-highlighter/dist/esm/create-element';\n\nexport { createElement };\n\nexport * from './SyntaxHighlighter';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\nimport { type SyntaxHighlighterProps as NaturalSyntaxHighlighterProps } from 'react-syntax-highlighter';\nimport NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-async-light';\nimport { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';\n\nimport { ScrollArea, type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nconst zeroWidthSpace = '\\u200b';\n\nexport type SyntaxHighlighterProps = ThemedClassName<\n NaturalSyntaxHighlighterProps & {\n fallback?: string;\n }\n>;\n\n/**\n * NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.\n * The lightweight version will load specific language parsers asynchronously.\n *\n * https://github.com/react-syntax-highlighter/react-syntax-highlighter\n * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html\n */\n// TODO(burdon): Replace with react-ui-editor (and reuse styles).\nexport const SyntaxHighlighter = ({\n classNames,\n children,\n language = 'text',\n fallback = zeroWidthSpace,\n ...props\n}: SyntaxHighlighterProps) => {\n const { themeMode } = useThemeContext();\n\n return (\n <ScrollArea.Root thin classNames={mx('p1', classNames)}>\n <ScrollArea.Viewport>\n <div role='none'>\n <NativeSyntaxHighlighter\n language={languages[language as keyof typeof languages] || language}\n style={themeMode === 'dark' ? dark : light}\n customStyle={{\n background: 'unset',\n border: 'none',\n boxShadow: 'none',\n padding: 0,\n margin: 0,\n }}\n {...props}\n >\n {/* Non-empty fallback prevents collapse. */}\n {children || fallback}\n </NativeSyntaxHighlighter>\n </div>\n </ScrollArea.Viewport>\n </ScrollArea.Root>\n );\n};\n\nconst languages = {\n js: 'javascript',\n ts: 'typescript',\n};\n"],
5
+ "mappings": ";AAIA,SAASA,gBAAgB;AACzB,OAAOC,UAASC,YAAYC,WAAWC,gBAAgB;AAEvD,SAASC,aAAmC;AAC5C,SAAmCC,gBAAgBC,qBAAqB;;;ACHxE,OAAOC,mBAAmB;;;ACD1B,OAAOC,WAAW;AAElB,OAAOC,6BAA6B;AACpC,SAASC,eAAeC,MAAMC,eAAeC,aAAa;AAE1D,SAASC,YAAkCC,uBAAuB;AAClE,SAASC,UAAU;AAEnB,IAAMC,iBAAiB;AAgBhB,IAAMC,o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eAAe,CAACG,KAAKK,KAAI,EAAGC,QAAQ;AACvCR,cAAQD,WAAAA;IACV,OAAO;AACL,UAAI;AACFC,gBAAQS,SAAS;UAAEC,MAAMR;UAAMS,MAAMZ;QAAY,CAAA,CAAA;AACjDM,iBAAS,IAAA;MACX,SAASO,KAAK;AACZZ,gBAAQD,WAAAA;AACRM,iBAASO,GAAAA;MACX;IACF;EACF,GAAG;IAACb;IAAaG;GAAK;AAEtB,SACE,gBAAAf,OAAA,cAAC0B,OAAAA;IAAIC,WAAU;IAAuClB,KAAKX;KACzD,gBAAAE,OAAA,cAAC4B,MAAMC,MAAI;IAACC,mBAAmBb,QAAQ,UAAU;KAC/C,gBAAAjB,OAAA,cAAC4B,MAAMG,WAAS;IACd7B,YAAY;MAAC;MAAsBe,SAAS;;IAC5Ce,SAAQ;IACRC,OAAOlB;IACPmB,aAAY;IACZC,UAAU,CAACC,UAAUpB,QAAQoB,MAAMC,OAAOJ,KAAK;OAGnD,gBAAAjC,OAAA,cAACM,mBAAAA;IACCC,UAAS;IACTL,YAAY;MAAC;MAAkCA;;IAC/CM,eAAaH;KAEZK,cAAcP,MAAMC,YAAYO,eAAeP,QAAAA,GAAW,CAAA,CAAA,CAAA;AAInE,CAAA;",
6
+ "names": ["JSONPath", "React", "forwardRef", "useEffect", "useState", "Input", "createReplacer", "safeStringify", "createElement", "React", "NativeSyntaxHighlighter", "coldarkDark", "dark", "coldarkCold", "light", "ScrollArea", "useThemeContext", "mx", "zeroWidthSpace", "SyntaxHighlighter", "classNames", "children", "language", "fallback", "props", "themeMode", "useThemeContext", "ScrollArea", "Root", "thin", "mx", "Viewport", "div", "role", "NativeSyntaxHighlighter", "languages", "style", "dark", "light", "customStyle", "background", "border", "boxShadow", "padding", "margin", "js", "ts", "Json", "forwardRef", "props", "forwardedRef", "filter", "React", "JsonFilter", "classNames", "data", "replacer", "testId", "SyntaxHighlighter", "language", "data-testid", "ref", "safeStringify", "createReplacer", "initialData", "setData", "useState", "text", "setText", "error", "setError", "useEffect", "trim", "length", "JSONPath", "path", "json", "err", "div", "className", "Input", "Root", "validationValence", "TextInput", "variant", "value", "placeholder", "onChange", "event", "target"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytes":6186,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/SyntaxHighlighter/index.ts":{"bytes":979,"imports":[{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"},"src/Json/Json.tsx":{"bytes":13573,"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"jsonpath","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"../SyntaxHighlighter"}],"format":"esm"},"src/Json/index.ts":{"bytes":463,"imports":[{"path":"src/Json/Json.tsx","kind":"import-statement","original":"./Json"}],"format":"esm"},"src/index.ts":{"bytes":571,"imports":[{"path":"src/Json/index.ts","kind":"import-statement","original":"./Json"},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":10249},"dist/lib/browser/index.mjs":{"imports":[{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"jsonpath","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"@preact-signals/safe-react/tracking","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-theme","kind":"import-statement","external":true}],"exports":["Json","JsonFilter","SyntaxHighlighter","createElement","createReplacer"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":3419},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1283},"src/Json/index.ts":{"bytesInOutput":0},"src/index.ts":{"bytesInOutput":0}},"bytes":5030}}}
1
+ {"inputs":{"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytes":6276,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/SyntaxHighlighter/index.ts":{"bytes":979,"imports":[{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/SyntaxHighlighter.tsx","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"},"src/Json/Json.tsx":{"bytes":8496,"imports":[{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"../SyntaxHighlighter"}],"format":"esm"},"src/Json/index.ts":{"bytes":463,"imports":[{"path":"src/Json/Json.tsx","kind":"import-statement","original":"./Json"}],"format":"esm"},"src/index.ts":{"bytes":571,"imports":[{"path":"src/Json/index.ts","kind":"import-statement","original":"./Json"},{"path":"src/SyntaxHighlighter/index.ts","kind":"import-statement","original":"./SyntaxHighlighter"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":8179},"dist/lib/browser/index.mjs":{"imports":[{"path":"jsonpath-plus","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/create-element","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/prism-async-light","kind":"import-statement","external":true},{"path":"react-syntax-highlighter/dist/esm/styles/prism","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["Json","JsonFilter","SyntaxHighlighter","createElement"],"entryPoint":"src/index.ts","inputs":{"src/Json/Json.tsx":{"bytesInOutput":2125},"src/SyntaxHighlighter/index.ts":{"bytesInOutput":78},"src/SyntaxHighlighter/SyntaxHighlighter.tsx":{"bytesInOutput":1162},"src/index.ts":{"bytesInOutput":0}},"bytes":3597}}}
@@ -1,44 +1,40 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
2
 
3
3
  // src/Json/Json.tsx
4
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
5
- import jp from "jsonpath";
6
- import React2, { useEffect, useState } from "react";
4
+ import { JSONPath } from "jsonpath-plus";
5
+ import React2, { forwardRef, useEffect, useState } from "react";
7
6
  import { Input } from "@dxos/react-ui";
7
+ import { createReplacer, safeStringify } from "@dxos/util";
8
8
 
9
9
  // src/SyntaxHighlighter/index.ts
10
10
  import createElement from "react-syntax-highlighter/dist/esm/create-element";
11
11
 
12
12
  // src/SyntaxHighlighter/SyntaxHighlighter.tsx
13
- import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
14
13
  import React from "react";
15
14
  import NativeSyntaxHighlighter from "react-syntax-highlighter/dist/esm/prism-async-light";
16
15
  import { coldarkDark as dark, coldarkCold as light } from "react-syntax-highlighter/dist/esm/styles/prism";
17
- import { useThemeContext } from "@dxos/react-ui";
18
- import { mx } from "@dxos/react-ui-theme";
16
+ import { ScrollArea, useThemeContext } from "@dxos/react-ui";
17
+ import { mx } from "@dxos/ui-theme";
19
18
  var zeroWidthSpace = "\u200B";
20
19
  var SyntaxHighlighter = ({ classNames, children, language = "text", fallback = zeroWidthSpace, ...props }) => {
21
- var _effect = _useSignals();
22
- try {
23
- const { themeMode } = useThemeContext();
24
- return /* @__PURE__ */ React.createElement("div", {
25
- className: mx("flex is-full p-1 overflow-hidden text-baseText", classNames)
26
- }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
27
- className: "is-full overflow-auto scrollbar-thin",
28
- language: languages[language] || language,
29
- style: themeMode === "dark" ? dark : light,
30
- customStyle: {
31
- background: "unset",
32
- border: "none",
33
- boxShadow: "none",
34
- padding: 0,
35
- margin: 0
36
- },
37
- ...props
38
- }, children || fallback));
39
- } finally {
40
- _effect.f();
41
- }
20
+ const { themeMode } = useThemeContext();
21
+ return /* @__PURE__ */ React.createElement(ScrollArea.Root, {
22
+ thin: true,
23
+ classNames: mx("p1", classNames)
24
+ }, /* @__PURE__ */ React.createElement(ScrollArea.Viewport, null, /* @__PURE__ */ React.createElement("div", {
25
+ role: "none"
26
+ }, /* @__PURE__ */ React.createElement(NativeSyntaxHighlighter, {
27
+ language: languages[language] || language,
28
+ style: themeMode === "dark" ? dark : light,
29
+ customStyle: {
30
+ background: "unset",
31
+ border: "none",
32
+ boxShadow: "none",
33
+ padding: 0,
34
+ margin: 0
35
+ },
36
+ ...props
37
+ }, children || fallback))));
42
38
  };
43
39
  var languages = {
44
40
  js: "javascript",
@@ -46,113 +42,71 @@ var languages = {
46
42
  };
47
43
 
48
44
  // src/Json/Json.tsx
49
- var defaultClassNames = "!m-0 grow overflow-y-auto text-sm";
50
- var Json = ({ filter, ...params }) => {
51
- var _effect = _useSignals2();
52
- try {
53
- if (filter) {
54
- return /* @__PURE__ */ React2.createElement(JsonFilter, params);
55
- }
56
- const { classNames, data, replacer, testId } = params;
57
- return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
58
- language: "json",
59
- classNames: [
60
- defaultClassNames,
61
- classNames
62
- ],
63
- "data-testid": testId
64
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2));
65
- } finally {
66
- _effect.f();
67
- }
68
- };
69
- var JsonFilter = ({ classNames, data: initialData, replacer, testId }) => {
70
- var _effect = _useSignals2();
71
- try {
72
- const [data, setData] = useState(initialData);
73
- const [text, setText] = useState("");
74
- const [error, setError] = useState(null);
75
- useEffect(() => {
76
- if (!initialData || !text.trim().length) {
77
- setData(initialData);
78
- } else {
79
- try {
80
- setData(jp.query(initialData, text));
81
- setError(null);
82
- } catch (err) {
83
- setData(initialData);
84
- setError(err);
85
- }
86
- }
87
- }, [
88
- initialData,
89
- text
90
- ]);
91
- return /* @__PURE__ */ React2.createElement("div", {
92
- className: "flex flex-col grow overflow-hidden"
93
- }, /* @__PURE__ */ React2.createElement(Input.Root, {
94
- validationValence: error ? "error" : "success"
95
- }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
96
- classNames: [
97
- "p-1 px-2 font-mono",
98
- error && "border-red-500"
99
- ],
100
- variant: "subdued",
101
- value: text,
102
- onChange: (event) => setText(event.target.value),
103
- placeholder: "JSONPath (e.g., $.graph.nodes)"
104
- })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
105
- language: "json",
106
- classNames: [
107
- defaultClassNames,
108
- classNames
109
- ],
110
- "data-testid": testId
111
- }, JSON.stringify(data, replacer && createReplacer(replacer), 2)));
112
- } finally {
113
- _effect.f();
45
+ var Json = /* @__PURE__ */ forwardRef((props, forwardedRef) => {
46
+ if (props.filter) {
47
+ return /* @__PURE__ */ React2.createElement(JsonFilter, props);
114
48
  }
115
- };
116
- var createReplacer = ({ omit, parse, maxDepth, maxArrayLen, maxStringLen }) => {
117
- let currentDepth = 0;
118
- const depthMap = /* @__PURE__ */ new WeakMap();
119
- return function(key, value) {
120
- if (key === "") {
121
- currentDepth = 0;
122
- } else if (this && typeof this === "object") {
123
- const parentDepth = depthMap.get(this) ?? 0;
124
- currentDepth = parentDepth + 1;
125
- }
126
- if (value && typeof value === "object") {
127
- depthMap.set(value, currentDepth);
128
- if (maxDepth != null && currentDepth >= maxDepth) {
129
- return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
130
- }
131
- }
132
- if (omit?.includes(key)) {
133
- return void 0;
134
- }
135
- if (parse?.includes(key) && typeof value === "string") {
49
+ const { classNames, data, replacer, testId } = props;
50
+ return /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
51
+ language: "json",
52
+ classNames: [
53
+ "w-full overflow-y-auto text-sm",
54
+ classNames
55
+ ],
56
+ "data-testid": testId,
57
+ ref: forwardedRef
58
+ }, safeStringify(data, replacer && createReplacer(replacer), 2));
59
+ });
60
+ var JsonFilter = /* @__PURE__ */ forwardRef(({ classNames, data: initialData, replacer, testId }, forwardedRef) => {
61
+ const [data, setData] = useState(initialData);
62
+ const [text, setText] = useState("");
63
+ const [error, setError] = useState(null);
64
+ useEffect(() => {
65
+ if (!initialData || !text.trim().length) {
66
+ setData(initialData);
67
+ } else {
136
68
  try {
137
- return JSON.parse(value);
138
- } catch {
139
- return value;
69
+ setData(JSONPath({
70
+ path: text,
71
+ json: initialData
72
+ }));
73
+ setError(null);
74
+ } catch (err) {
75
+ setData(initialData);
76
+ setError(err);
140
77
  }
141
78
  }
142
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
143
- return `[length: ${value.length}]`;
144
- }
145
- if (maxStringLen != null && typeof value === "string" && value.length > maxStringLen) {
146
- return value.slice(0, maxStringLen) + "...";
147
- }
148
- return value;
149
- };
150
- };
79
+ }, [
80
+ initialData,
81
+ text
82
+ ]);
83
+ return /* @__PURE__ */ React2.createElement("div", {
84
+ className: "flex flex-col h-full overflow-hidden",
85
+ ref: forwardedRef
86
+ }, /* @__PURE__ */ React2.createElement(Input.Root, {
87
+ validationValence: error ? "error" : "success"
88
+ }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
89
+ classNames: [
90
+ "p-1 px-2 font-mono",
91
+ error && "border-rose-500"
92
+ ],
93
+ variant: "subdued",
94
+ value: text,
95
+ placeholder: "JSONPath (e.g., $.graph.nodes)",
96
+ onChange: (event) => setText(event.target.value)
97
+ })), /* @__PURE__ */ React2.createElement(SyntaxHighlighter, {
98
+ language: "json",
99
+ classNames: [
100
+ "w-full overflow-y-auto text-sm",
101
+ classNames
102
+ ],
103
+ "data-testid": testId
104
+ }, safeStringify(data, replacer && createReplacer(replacer), 2)));
105
+ });
151
106
  export {
152
107
  Json,
153
108
  JsonFilter,
154
109
  SyntaxHighlighter,
155
- createElement,
156
- createReplacer
110
+ createElement
157
111
  };
158
112
  //# sourceMappingURL=index.mjs.map