@dxos/react-ui-syntax-highlighter 0.8.4-main.72ec0f3 → 0.8.4-main.7996785055
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 +87 -93
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +87 -93
- 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 +16 -2
- package/dist/types/src/Json/Json.d.ts.map +1 -1
- package/dist/types/src/Json/Json.stories.d.ts +8 -1
- package/dist/types/src/Json/Json.stories.d.ts.map +1 -1
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts +9 -4
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.d.ts.map +1 -1
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts +10 -1
- package/dist/types/src/SyntaxHighlighter/SyntaxHighlighter.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -20
- package/src/Json/Json.stories.tsx +1 -1
- package/src/Json/Json.tsx +52 -43
- package/src/SyntaxHighlighter/SyntaxHighlighter.stories.tsx +11 -9
- package/src/SyntaxHighlighter/SyntaxHighlighter.tsx +40 -38
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.7996785055",
|
|
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,30 +29,28 @@
|
|
|
25
29
|
"src"
|
|
26
30
|
],
|
|
27
31
|
"dependencies": {
|
|
28
|
-
"
|
|
29
|
-
"jsonpath": "^1.1.1",
|
|
32
|
+
"jsonpath-plus": "^10.3.0",
|
|
30
33
|
"react-syntax-highlighter": "^15.6.1",
|
|
31
|
-
"@dxos/util": "0.8.4-main.
|
|
34
|
+
"@dxos/util": "0.8.4-main.7996785055"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/react": "~19.2.
|
|
36
|
-
"@types/react-dom": "~19.2.2",
|
|
37
|
+
"@types/react": "~19.2.7",
|
|
38
|
+
"@types/react-dom": "~19.2.3",
|
|
37
39
|
"@types/react-syntax-highlighter": "^15.5.13",
|
|
38
|
-
"react": "~19.2.
|
|
39
|
-
"react-dom": "~19.2.
|
|
40
|
-
"vite": "7.1.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/util": "0.8.4-main.
|
|
45
|
-
"@dxos/
|
|
40
|
+
"react": "~19.2.3",
|
|
41
|
+
"react-dom": "~19.2.3",
|
|
42
|
+
"vite": "^7.1.11",
|
|
43
|
+
"@dxos/react-ui": "0.8.4-main.7996785055",
|
|
44
|
+
"@dxos/random": "0.8.4-main.7996785055",
|
|
45
|
+
"@dxos/ui-theme": "0.8.4-main.7996785055",
|
|
46
|
+
"@dxos/util": "0.8.4-main.7996785055",
|
|
47
|
+
"@dxos/storybook-utils": "0.8.4-main.7996785055"
|
|
46
48
|
},
|
|
47
49
|
"peerDependencies": {
|
|
48
|
-
"react": "
|
|
49
|
-
"react-dom": "
|
|
50
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
51
|
-
"@dxos/
|
|
50
|
+
"react": "~19.2.3",
|
|
51
|
+
"react-dom": "~19.2.3",
|
|
52
|
+
"@dxos/react-ui": "0.8.4-main.7996785055",
|
|
53
|
+
"@dxos/ui-theme": "0.8.4-main.7996785055"
|
|
52
54
|
},
|
|
53
55
|
"publishConfig": {
|
|
54
56
|
"access": "public"
|
|
@@ -56,7 +56,7 @@ const createData = ({ depth = 2, children = 3 } = {}): any => {
|
|
|
56
56
|
const meta = {
|
|
57
57
|
title: 'ui/react-ui-syntax-highlighter/Json',
|
|
58
58
|
component: Json,
|
|
59
|
-
decorators: [withTheme, withLayout({
|
|
59
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
60
60
|
} satisfies Meta<typeof Json>;
|
|
61
61
|
|
|
62
62
|
export default meta;
|
package/src/Json/Json.tsx
CHANGED
|
@@ -2,17 +2,14 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
5
|
+
import { JSONPath } from 'jsonpath-plus';
|
|
6
|
+
import React, { forwardRef, useEffect, useState } from 'react';
|
|
8
7
|
|
|
9
8
|
import { Input, type ThemedClassName } from '@dxos/react-ui';
|
|
10
9
|
import { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';
|
|
11
10
|
|
|
12
11
|
import { SyntaxHighlighter } from '../SyntaxHighlighter';
|
|
13
12
|
|
|
14
|
-
const defaultClassNames = 'grow overflow-y-auto text-sm';
|
|
15
|
-
|
|
16
13
|
export type JsonProps = ThemedClassName<{
|
|
17
14
|
data?: any;
|
|
18
15
|
filter?: boolean;
|
|
@@ -20,51 +17,63 @@ export type JsonProps = ThemedClassName<{
|
|
|
20
17
|
testId?: string;
|
|
21
18
|
}>;
|
|
22
19
|
|
|
23
|
-
export const Json = (
|
|
24
|
-
if (filter) {
|
|
25
|
-
return <JsonFilter {...
|
|
20
|
+
export const Json = forwardRef<HTMLDivElement, JsonProps>((props, forwardedRef) => {
|
|
21
|
+
if (props.filter) {
|
|
22
|
+
return <JsonFilter {...props} />;
|
|
26
23
|
}
|
|
27
24
|
|
|
28
|
-
const { classNames, data, replacer, testId } =
|
|
25
|
+
const { classNames, data, replacer, testId } = props;
|
|
29
26
|
return (
|
|
30
|
-
<SyntaxHighlighter
|
|
27
|
+
<SyntaxHighlighter
|
|
28
|
+
language='json'
|
|
29
|
+
classNames={['w-full py-1 px-2 overflow-y-auto text-sm', classNames]}
|
|
30
|
+
data-testid={testId}
|
|
31
|
+
ref={forwardedRef}
|
|
32
|
+
>
|
|
31
33
|
{safeStringify(data, replacer && createReplacer(replacer), 2)}
|
|
32
34
|
</SyntaxHighlighter>
|
|
33
35
|
);
|
|
34
|
-
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const JsonFilter = forwardRef<HTMLDivElement, JsonProps>(
|
|
39
|
+
({ classNames, data: initialData, replacer, testId }, forwardedRef) => {
|
|
40
|
+
const [data, setData] = useState(initialData);
|
|
41
|
+
const [text, setText] = useState('');
|
|
42
|
+
const [error, setError] = useState<Error | null>(null);
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const [text, setText] = useState('');
|
|
39
|
-
const [error, setError] = useState<Error | null>(null);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (!initialData || !text.trim().length) {
|
|
42
|
-
setData(initialData);
|
|
43
|
-
} else {
|
|
44
|
-
try {
|
|
45
|
-
setData(jp.query(initialData, text));
|
|
46
|
-
setError(null);
|
|
47
|
-
} catch (err) {
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!initialData || !text.trim().length) {
|
|
48
46
|
setData(initialData);
|
|
49
|
-
|
|
47
|
+
} else {
|
|
48
|
+
try {
|
|
49
|
+
setData(JSONPath({ path: text, json: initialData }));
|
|
50
|
+
setError(null);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
setData(initialData);
|
|
53
|
+
setError(err as Error);
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
|
-
}
|
|
52
|
-
}, [initialData, text]); // TODO(burdon): Need structural diff.
|
|
56
|
+
}, [initialData, text]); // TODO(burdon): Need structural diff.
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
58
|
+
return (
|
|
59
|
+
<div className='flex flex-col h-full overflow-hidden' ref={forwardedRef}>
|
|
60
|
+
<Input.Root validationValence={error ? 'error' : 'success'}>
|
|
61
|
+
<Input.TextInput
|
|
62
|
+
classNames={['p-1 px-2 font-mono', error && 'border-rose-500']}
|
|
63
|
+
variant='subdued'
|
|
64
|
+
value={text}
|
|
65
|
+
placeholder='JSONPath (e.g., $.graph.nodes)'
|
|
66
|
+
onChange={(event) => setText(event.target.value)}
|
|
67
|
+
/>
|
|
68
|
+
</Input.Root>
|
|
69
|
+
<SyntaxHighlighter
|
|
70
|
+
language='json'
|
|
71
|
+
classNames={['w-full overflow-y-auto text-sm', classNames]}
|
|
72
|
+
data-testid={testId}
|
|
73
|
+
>
|
|
74
|
+
{safeStringify(data, replacer && createReplacer(replacer), 2)}
|
|
75
|
+
</SyntaxHighlighter>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
);
|
|
@@ -4,15 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
6
|
|
|
7
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
7
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
8
8
|
import { trim } from '@dxos/util';
|
|
9
9
|
|
|
10
|
+
// @ts-ignore - Vite raw import.
|
|
11
|
+
import TEXT from '../../package.json?raw';
|
|
12
|
+
|
|
10
13
|
import { SyntaxHighlighter } from './SyntaxHighlighter';
|
|
11
14
|
|
|
12
15
|
const meta = {
|
|
13
16
|
title: 'ui/react-ui-syntax-highlighter/SyntaxHighlighter',
|
|
14
17
|
component: SyntaxHighlighter,
|
|
15
|
-
decorators: [withTheme],
|
|
18
|
+
decorators: [withTheme(), withLayout({ layout: 'fullscreen' })],
|
|
19
|
+
parameters: {
|
|
20
|
+
layout: 'fullscreen',
|
|
21
|
+
},
|
|
16
22
|
} satisfies Meta<typeof SyntaxHighlighter>;
|
|
17
23
|
|
|
18
24
|
export default meta;
|
|
@@ -23,7 +29,7 @@ export const Default: Story = {
|
|
|
23
29
|
args: {
|
|
24
30
|
language: 'json',
|
|
25
31
|
classNames: 'text-sm',
|
|
26
|
-
children:
|
|
32
|
+
children: TEXT,
|
|
27
33
|
},
|
|
28
34
|
};
|
|
29
35
|
|
|
@@ -32,7 +38,7 @@ export const Typescript: Story = {
|
|
|
32
38
|
language: 'tsx',
|
|
33
39
|
children: trim`
|
|
34
40
|
import React from 'react'
|
|
35
|
-
|
|
41
|
+
|
|
36
42
|
const Test = () => {
|
|
37
43
|
return <div>Test</div>
|
|
38
44
|
}
|
|
@@ -40,8 +46,4 @@ export const Typescript: Story = {
|
|
|
40
46
|
},
|
|
41
47
|
};
|
|
42
48
|
|
|
43
|
-
export const Empty: Story = {
|
|
44
|
-
args: {
|
|
45
|
-
children: false,
|
|
46
|
-
},
|
|
47
|
-
};
|
|
49
|
+
export const Empty: Story = {};
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import React from 'react';
|
|
5
|
+
import React, { CSSProperties } from 'react';
|
|
6
6
|
import { type SyntaxHighlighterProps as NaturalSyntaxHighlighterProps } from 'react-syntax-highlighter';
|
|
7
7
|
import NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-async-light';
|
|
8
8
|
import { coldarkDark as dark, coldarkCold as light } from 'react-syntax-highlighter/dist/esm/styles/prism';
|
|
9
9
|
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { ScrollArea, useThemeContext } from '@dxos/react-ui';
|
|
11
|
+
import { composable, composableProps } from '@dxos/ui-theme';
|
|
12
12
|
|
|
13
13
|
const zeroWidthSpace = '\u200b';
|
|
14
14
|
|
|
15
|
-
export type SyntaxHighlighterProps =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
>;
|
|
15
|
+
export type SyntaxHighlighterProps = NaturalSyntaxHighlighterProps & {
|
|
16
|
+
fallback?: string;
|
|
17
|
+
};
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* NOTE: Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.
|
|
@@ -26,36 +24,40 @@ export type SyntaxHighlighterProps = ThemedClassName<
|
|
|
26
24
|
* https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html
|
|
27
25
|
*/
|
|
28
26
|
// TODO(burdon): Replace with react-ui-editor (and reuse styles).
|
|
29
|
-
export const SyntaxHighlighter = (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
27
|
+
export const SyntaxHighlighter = composable<HTMLDivElement, SyntaxHighlighterProps>(
|
|
28
|
+
(
|
|
29
|
+
{ children, language = 'text', fallback = zeroWidthSpace, classNames, className, style, ...nativeProps },
|
|
30
|
+
forwardedRef,
|
|
31
|
+
) => {
|
|
32
|
+
const { themeMode } = useThemeContext();
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<ScrollArea.Root {...composableProps({ classNames, className })} thin ref={forwardedRef}>
|
|
36
|
+
<ScrollArea.Viewport>
|
|
37
|
+
<div role='none'>
|
|
38
|
+
<NativeSyntaxHighlighter
|
|
39
|
+
language={languages[language as keyof typeof languages] || language}
|
|
40
|
+
style={(style as { [key: string]: CSSProperties }) ?? (themeMode === 'dark' ? dark : light)}
|
|
41
|
+
customStyle={{
|
|
42
|
+
background: 'unset',
|
|
43
|
+
border: 'none',
|
|
44
|
+
boxShadow: 'none',
|
|
45
|
+
padding: 0,
|
|
46
|
+
margin: 0,
|
|
47
|
+
}}
|
|
48
|
+
{...nativeProps}
|
|
49
|
+
>
|
|
50
|
+
{/* Non-empty fallback prevents collapse. */}
|
|
51
|
+
{children || fallback}
|
|
52
|
+
</NativeSyntaxHighlighter>
|
|
53
|
+
</div>
|
|
54
|
+
</ScrollArea.Viewport>
|
|
55
|
+
</ScrollArea.Root>
|
|
56
|
+
);
|
|
57
|
+
},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
SyntaxHighlighter.displayName = 'SyntaxHighlighter';
|
|
59
61
|
|
|
60
62
|
const languages = {
|
|
61
63
|
js: 'javascript',
|