@dxos/react-ui-syntax-highlighter 0.8.4-main.ead640a → 0.8.4-main.ef1bc66f44
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 +74 -125
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +74 -125
- 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 -1
- package/dist/types/src/Json/Json.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +21 -17
- package/src/Json/Json.stories.tsx +14 -1
- package/src/Json/Json.tsx +54 -104
- package/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +1 -1
- package/src/SyntaxHighlighter/SyntaxHighlighter.tsx +3 -3
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-syntax-highlighter",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.ef1bc66f44",
|
|
4
4
|
"description": "A syntax highlighter wrapper.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
|
-
"sideEffects":
|
|
13
|
+
"sideEffects": false,
|
|
10
14
|
"type": "module",
|
|
11
15
|
"exports": {
|
|
12
16
|
".": {
|
|
@@ -25,29 +29,29 @@
|
|
|
25
29
|
"src"
|
|
26
30
|
],
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"@preact-signals/safe-react": "^0.9.0",
|
|
29
32
|
"jsonpath": "^1.1.1",
|
|
30
|
-
"react-syntax-highlighter": "^15.6.1"
|
|
33
|
+
"react-syntax-highlighter": "^15.6.1",
|
|
34
|
+
"@dxos/util": "0.8.4-main.ef1bc66f44"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
33
37
|
"@types/jsonpath": "^0.2.4",
|
|
34
|
-
"@types/react": "~19.2.
|
|
35
|
-
"@types/react-dom": "~19.2.
|
|
38
|
+
"@types/react": "~19.2.7",
|
|
39
|
+
"@types/react-dom": "~19.2.3",
|
|
36
40
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
37
|
-
"react": "~19.2.
|
|
38
|
-
"react-dom": "~19.2.
|
|
41
|
+
"react": "~19.2.3",
|
|
42
|
+
"react-dom": "~19.2.3",
|
|
39
43
|
"vite": "7.1.9",
|
|
40
|
-
"@dxos/random": "0.8.4-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
44
|
+
"@dxos/random": "0.8.4-main.ef1bc66f44",
|
|
45
|
+
"@dxos/react-ui": "0.8.4-main.ef1bc66f44",
|
|
46
|
+
"@dxos/storybook-utils": "0.8.4-main.ef1bc66f44",
|
|
47
|
+
"@dxos/ui-theme": "0.8.4-main.ef1bc66f44",
|
|
48
|
+
"@dxos/util": "0.8.4-main.ef1bc66f44"
|
|
45
49
|
},
|
|
46
50
|
"peerDependencies": {
|
|
47
|
-
"react": "
|
|
48
|
-
"react-dom": "
|
|
49
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
50
|
-
"@dxos/
|
|
51
|
+
"react": "~19.2.3",
|
|
52
|
+
"react-dom": "~19.2.3",
|
|
53
|
+
"@dxos/react-ui": "0.8.4-main.ef1bc66f44",
|
|
54
|
+
"@dxos/ui-theme": "0.8.4-main.ef1bc66f44"
|
|
51
55
|
},
|
|
52
56
|
"publishConfig": {
|
|
53
57
|
"access": "public"
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { faker } from '@dxos/random';
|
|
8
9
|
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
@@ -55,7 +56,7 @@ const createData = ({ depth = 2, children = 3 } = {}): any => {
|
|
|
55
56
|
const meta = {
|
|
56
57
|
title: 'ui/react-ui-syntax-highlighter/Json',
|
|
57
58
|
component: Json,
|
|
58
|
-
decorators: [withTheme, withLayout({
|
|
59
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
59
60
|
} satisfies Meta<typeof Json>;
|
|
60
61
|
|
|
61
62
|
export default meta;
|
|
@@ -91,3 +92,15 @@ export const Large: Story = {
|
|
|
91
92
|
},
|
|
92
93
|
},
|
|
93
94
|
};
|
|
95
|
+
|
|
96
|
+
const cycle: any = {
|
|
97
|
+
a: 1,
|
|
98
|
+
b: [],
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
cycle.b.push(cycle);
|
|
102
|
+
|
|
103
|
+
// NOTE: Storybook args cannot be circular.
|
|
104
|
+
export const Cycle: Story = {
|
|
105
|
+
render: () => <Json data={cycle} />,
|
|
106
|
+
};
|
package/src/Json/Json.tsx
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
// TODO(burdon): Use to jsonpath-plus.
|
|
6
6
|
import jp from 'jsonpath';
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
7
|
+
import React, { forwardRef, useEffect, useState } from 'react';
|
|
8
8
|
|
|
9
9
|
import { Input, type ThemedClassName } from '@dxos/react-ui';
|
|
10
|
+
import { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';
|
|
10
11
|
|
|
11
12
|
import { SyntaxHighlighter } from '../SyntaxHighlighter';
|
|
12
13
|
|
|
13
|
-
const defaultClassNames = '!m-0 grow overflow-y-auto text-sm';
|
|
14
|
-
|
|
15
14
|
export type JsonProps = ThemedClassName<{
|
|
16
15
|
data?: any;
|
|
17
16
|
filter?: boolean;
|
|
@@ -19,112 +18,63 @@ export type JsonProps = ThemedClassName<{
|
|
|
19
18
|
testId?: string;
|
|
20
19
|
}>;
|
|
21
20
|
|
|
22
|
-
export const Json = (
|
|
23
|
-
if (filter) {
|
|
24
|
-
return <JsonFilter {...
|
|
21
|
+
export const Json = forwardRef<HTMLDivElement, JsonProps>((props, forwardedRef) => {
|
|
22
|
+
if (props.filter) {
|
|
23
|
+
return <JsonFilter {...props} />;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const { classNames, data, replacer, testId } =
|
|
26
|
+
const { classNames, data, replacer, testId } = props;
|
|
28
27
|
return (
|
|
29
|
-
<SyntaxHighlighter
|
|
30
|
-
|
|
28
|
+
<SyntaxHighlighter
|
|
29
|
+
language='json'
|
|
30
|
+
classNames={['is-full overflow-y-auto text-sm', classNames]}
|
|
31
|
+
data-testid={testId}
|
|
32
|
+
ref={forwardedRef}
|
|
33
|
+
>
|
|
34
|
+
{safeStringify(data, replacer && createReplacer(replacer), 2)}
|
|
31
35
|
</SyntaxHighlighter>
|
|
32
36
|
);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const JsonFilter = ({ classNames, data: initialData, replacer, testId }: JsonProps) => {
|
|
36
|
-
const [data, setData] = useState(initialData);
|
|
37
|
-
const [text, setText] = useState('');
|
|
38
|
-
const [error, setError] = useState<Error | null>(null);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (!initialData || !text.trim().length) {
|
|
41
|
-
setData(initialData);
|
|
42
|
-
} else {
|
|
43
|
-
try {
|
|
44
|
-
setData(jp.query(initialData, text));
|
|
45
|
-
setError(null);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
setData(initialData);
|
|
48
|
-
setError(err as Error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}, [initialData, text]); // TODO(burdon): Need structural diff.
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<div className='flex flex-col grow overflow-hidden'>
|
|
55
|
-
<Input.Root validationValence={error ? 'error' : 'success'}>
|
|
56
|
-
<Input.TextInput
|
|
57
|
-
classNames={['p-1 px-2 font-mono', error && 'border-red-500']}
|
|
58
|
-
variant='subdued'
|
|
59
|
-
value={text}
|
|
60
|
-
onChange={(event) => setText(event.target.value)}
|
|
61
|
-
placeholder='JSONPath (e.g., $.graph.nodes)'
|
|
62
|
-
/>
|
|
63
|
-
</Input.Root>
|
|
64
|
-
<SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
|
|
65
|
-
{JSON.stringify(data, replacer && createReplacer(replacer), 2)}
|
|
66
|
-
</SyntaxHighlighter>
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export type CreateReplacerProps = {
|
|
72
|
-
omit?: string[];
|
|
73
|
-
parse?: string[];
|
|
74
|
-
maxDepth?: number;
|
|
75
|
-
maxArrayLen?: number;
|
|
76
|
-
maxStringLen?: number;
|
|
77
|
-
};
|
|
37
|
+
});
|
|
78
38
|
|
|
79
|
-
export
|
|
39
|
+
export const JsonFilter = forwardRef<HTMLDivElement, JsonProps>(
|
|
40
|
+
({ classNames, data: initialData, replacer, testId }, forwardedRef) => {
|
|
41
|
+
const [data, setData] = useState(initialData);
|
|
42
|
+
const [text, setText] = useState('');
|
|
43
|
+
const [error, setError] = useState<Error | null>(null);
|
|
80
44
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Track depth.
|
|
93
|
-
if (key === '') {
|
|
94
|
-
currentDepth = 0;
|
|
95
|
-
} else if (this && typeof this === 'object') {
|
|
96
|
-
const parentDepth = depthMap.get(this) ?? 0;
|
|
97
|
-
currentDepth = parentDepth + 1;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// Store depth for this object.
|
|
101
|
-
if (value && typeof value === 'object') {
|
|
102
|
-
depthMap.set(value, currentDepth);
|
|
103
|
-
|
|
104
|
-
// Check max depth.
|
|
105
|
-
if (maxDepth != null && currentDepth >= maxDepth) {
|
|
106
|
-
return Array.isArray(value) ? `[{ length: ${value.length} }]` : `{ keys: ${Object.keys(value).length} }`;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Apply other filters.
|
|
111
|
-
if (omit?.includes(key)) {
|
|
112
|
-
return undefined;
|
|
113
|
-
}
|
|
114
|
-
if (parse?.includes(key) && typeof value === 'string') {
|
|
115
|
-
try {
|
|
116
|
-
return JSON.parse(value);
|
|
117
|
-
} catch {
|
|
118
|
-
return value;
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (!initialData || !text.trim().length) {
|
|
47
|
+
setData(initialData);
|
|
48
|
+
} else {
|
|
49
|
+
try {
|
|
50
|
+
setData(jp.query(initialData, text));
|
|
51
|
+
setError(null);
|
|
52
|
+
} catch (err) {
|
|
53
|
+
setData(initialData);
|
|
54
|
+
setError(err as Error);
|
|
55
|
+
}
|
|
119
56
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
57
|
+
}, [initialData, text]); // TODO(burdon): Need structural diff.
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<div className='flex flex-col bs-full overflow-hidden' ref={forwardedRef}>
|
|
61
|
+
<Input.Root validationValence={error ? 'error' : 'success'}>
|
|
62
|
+
<Input.TextInput
|
|
63
|
+
classNames={['p-1 pli-2 font-mono', error && 'border-rose-500']}
|
|
64
|
+
variant='subdued'
|
|
65
|
+
value={text}
|
|
66
|
+
placeholder='JSONPath (e.g., $.graph.nodes)'
|
|
67
|
+
onChange={(event) => setText(event.target.value)}
|
|
68
|
+
/>
|
|
69
|
+
</Input.Root>
|
|
70
|
+
<SyntaxHighlighter
|
|
71
|
+
language='json'
|
|
72
|
+
classNames={['is-full overflow-y-auto text-sm', classNames]}
|
|
73
|
+
data-testid={testId}
|
|
74
|
+
>
|
|
75
|
+
{safeStringify(data, replacer && createReplacer(replacer), 2)}
|
|
76
|
+
</SyntaxHighlighter>
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
},
|
|
80
|
+
);
|
|
@@ -12,7 +12,7 @@ import { SyntaxHighlighter } from './SyntaxHighlighter';
|
|
|
12
12
|
const meta = {
|
|
13
13
|
title: 'ui/react-ui-syntax-highlighter/SyntaxHighlighter',
|
|
14
14
|
component: SyntaxHighlighter,
|
|
15
|
-
decorators: [withTheme],
|
|
15
|
+
decorators: [withTheme()],
|
|
16
16
|
} satisfies Meta<typeof SyntaxHighlighter>;
|
|
17
17
|
|
|
18
18
|
export default meta;
|
|
@@ -8,7 +8,7 @@ import NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-asy
|
|
|
8
8
|
import { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
9
9
|
|
|
10
10
|
import { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
11
|
-
import { mx } from '@dxos/
|
|
11
|
+
import { mx } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
const zeroWidthSpace = '\u200b';
|
|
14
14
|
|
|
@@ -36,9 +36,9 @@ export const SyntaxHighlighter = ({
|
|
|
36
36
|
const { themeMode } = useThemeContext();
|
|
37
37
|
|
|
38
38
|
return (
|
|
39
|
-
<div className={mx('flex is-full p-1 overflow-hidden
|
|
39
|
+
<div className={mx('flex is-full p-1 overflow-hidden', classNames)}>
|
|
40
40
|
<NativeSyntaxHighlighter
|
|
41
|
-
className='is-full overflow-auto scrollbar-thin'
|
|
41
|
+
className='!m-0 is-full overflow-auto scrollbar-thin'
|
|
42
42
|
language={languages[language as keyof typeof languages] || language}
|
|
43
43
|
style={themeMode === 'dark' ? dark : light}
|
|
44
44
|
customStyle={{
|