@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.
- package/dist/lib/browser/index.mjs +81 -127
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +81 -127
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Json/Json.d.ts +17 -11
- package/dist/types/src/Json/Json.d.ts.map +1 -1
- package/dist/types/src/Json/Json.stories.d.ts +10 -4
- package/dist/types/src/Json/Json.stories.d.ts.map +1 -1
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts.map +1 -1
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts +3 -0
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -20
- package/src/Json/Json.stories.tsx +15 -5
- package/src/Json/Json.tsx +55 -106
- package/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +11 -9
- package/src/SyntaxHighlighter/SyntaxHighlighter.tsx +23 -20
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
// src/Json/Json.tsx
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
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/
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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\
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
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,oBAAoB,CAAC,EAChCC,YACAC,UACAC,WAAW,QACXC,WAAWL,gBACX,GAAGM,MAAAA,MACoB;AACvB,QAAM,EAAEC,UAAS,IAAKC,gBAAAA;AAEtB,SACE,sBAAA,cAACC,WAAWC,MAAI;IAACC,MAAAA;IAAKT,YAAYU,GAAG,MAAMV,UAAAA;KACzC,sBAAA,cAACO,WAAWI,UAAQ,MAClB,sBAAA,cAACC,OAAAA;IAAIC,MAAK;KACR,sBAAA,cAACC,yBAAAA;IACCZ,UAAUa,UAAUb,QAAAA,KAAuCA;IAC3Dc,OAAOX,cAAc,SAASY,OAAOC;IACrCC,aAAa;MACXC,YAAY;MACZC,QAAQ;MACRC,WAAW;MACXC,SAAS;MACTC,QAAQ;IACV;IACC,GAAGpB;KAGHH,YAAYE,QAAAA,CAAAA,CAAAA,CAAAA;AAMzB;AAEA,IAAMY,YAAY;EAChBU,IAAI;EACJC,IAAI;AACN;;;AF9CO,IAAMC,OAAOC,2BAAsC,CAACC,OAAOC,iBAAAA;AAChE,MAAID,MAAME,QAAQ;AAChB,WAAO,gBAAAC,OAAA,cAACC,YAAeJ,KAAAA;EACzB;AAEA,QAAM,EAAEK,YAAYC,MAAMC,UAAUC,OAAM,IAAKR;AAC/C,SACE,gBAAAG,OAAA,cAACM,mBAAAA;IACCC,UAAS;IACTL,YAAY;MAAC;MAAkCA;;IAC/CM,eAAaH;IACbI,KAAKX;KAEJY,cAAcP,MAAMC,YAAYO,eAAeP,QAAAA,GAAW,CAAA,CAAA;AAGjE,CAAA;AAEO,IAAMH,aAAaL,2BACxB,CAAC,EAAEM,YAAYC,MAAMS,aAAaR,UAAUC,OAAM,GAAIP,iBAAAA;AACpD,QAAM,CAACK,MAAMU,OAAAA,IAAWC,SAASF,WAAAA;AACjC,QAAM,CAACG,MAAMC,OAAAA,IAAWF,SAAS,EAAA;AACjC,QAAM,CAACG,OAAOC,QAAAA,IAAYJ,SAAuB,IAAA;AAEjDK,YAAU,MAAA;AACR,QAAI,CAACP,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":
|
|
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 {
|
|
5
|
-
import
|
|
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/
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|