@dxos/react-ui-syntax-highlighter 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660

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/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-syntax-highlighter",
3
- "version": "0.8.4-main.7ace549",
3
+ "version": "0.8.4-main.8360d9e660",
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": true,
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
- "@preact-signals/safe-react": "^0.9.0",
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.7ace549"
34
+ "@dxos/util": "0.8.4-main.8360d9e660"
32
35
  },
33
36
  "devDependencies": {
34
- "@types/jsonpath": "^0.2.4",
35
- "@types/react": "~19.2.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.0",
39
- "react-dom": "~19.2.0",
40
- "vite": "7.1.9",
41
- "@dxos/react-ui": "0.8.4-main.7ace549",
42
- "@dxos/random": "0.8.4-main.7ace549",
43
- "@dxos/react-ui-theme": "0.8.4-main.7ace549",
44
- "@dxos/storybook-utils": "0.8.4-main.7ace549",
45
- "@dxos/util": "0.8.4-main.7ace549"
40
+ "react": "~19.2.3",
41
+ "react-dom": "~19.2.3",
42
+ "vite": "^7.1.11",
43
+ "@dxos/random": "0.8.4-main.8360d9e660",
44
+ "@dxos/react-ui": "0.8.4-main.8360d9e660",
45
+ "@dxos/storybook-utils": "0.8.4-main.8360d9e660",
46
+ "@dxos/ui-theme": "0.8.4-main.8360d9e660",
47
+ "@dxos/util": "0.8.4-main.8360d9e660"
46
48
  },
47
49
  "peerDependencies": {
48
- "react": "^19.0.0",
49
- "react-dom": "^19.0.0",
50
- "@dxos/react-ui": "0.8.4-main.7ace549",
51
- "@dxos/react-ui-theme": "0.8.4-main.7ace549"
50
+ "react": "~19.2.3",
51
+ "react-dom": "~19.2.3",
52
+ "@dxos/react-ui": "0.8.4-main.8360d9e660",
53
+ "@dxos/ui-theme": "0.8.4-main.8360d9e660"
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({ container: 'column' })],
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
- // TODO(burdon): Use to jsonpath-plus.
6
- import jp from 'jsonpath';
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 = ({ filter, ...params }: JsonProps) => {
24
- if (filter) {
25
- return <JsonFilter {...params} />;
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 } = params;
25
+ const { classNames, data, replacer, testId } = props;
29
26
  return (
30
- <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
27
+ <SyntaxHighlighter
28
+ language='json'
29
+ classNames={['w-full 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
- export const JsonFilter = ({ classNames, data: initialData, replacer, testId }: JsonProps) => {
37
- const [data, setData] = useState(initialData);
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
- setError(err as Error);
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
- return (
55
- <div className='flex flex-col grow overflow-hidden'>
56
- <Input.Root validationValence={error ? 'error' : 'success'}>
57
- <Input.TextInput
58
- classNames={['p-1 pli-2 font-mono', error && 'border-red-500']}
59
- variant='subdued'
60
- value={text}
61
- onChange={(event) => setText(event.target.value)}
62
- placeholder='JSONPath (e.g., $.graph.nodes)'
63
- />
64
- </Input.Root>
65
- <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
66
- {safeStringify(data, replacer && createReplacer(replacer), 2)}
67
- </SyntaxHighlighter>
68
- </div>
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: JSON.stringify({ message: 'DXOS', initialized: true }, null, 2),
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 = {};
@@ -7,8 +7,8 @@ import { type SyntaxHighlighterProps as NaturalSyntaxHighlighterProps } from 're
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 { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
11
- import { mx } from '@dxos/react-ui-theme';
10
+ import { ScrollArea, type ThemedClassName, useThemeContext } from '@dxos/react-ui';
11
+ import { mx } from '@dxos/ui-theme';
12
12
 
13
13
  const zeroWidthSpace = '\u200b';
14
14
 
@@ -36,24 +36,27 @@ export const SyntaxHighlighter = ({
36
36
  const { themeMode } = useThemeContext();
37
37
 
38
38
  return (
39
- <div className={mx('flex is-full p-1 overflow-hidden', classNames)}>
40
- <NativeSyntaxHighlighter
41
- className='!m-0 is-full overflow-auto scrollbar-thin'
42
- language={languages[language as keyof typeof languages] || language}
43
- style={themeMode === 'dark' ? dark : light}
44
- customStyle={{
45
- background: 'unset',
46
- border: 'none',
47
- boxShadow: 'none',
48
- padding: 0,
49
- margin: 0,
50
- }}
51
- {...props}
52
- >
53
- {/* Non-empty fallback prevents collapse. */}
54
- {children || fallback}
55
- </NativeSyntaxHighlighter>
56
- </div>
39
+ <ScrollArea.Root thin classNames={mx('p1', classNames)}>
40
+ <ScrollArea.Viewport>
41
+ <div role='none'>
42
+ <NativeSyntaxHighlighter
43
+ language={languages[language as keyof typeof languages] || language}
44
+ style={themeMode === 'dark' ? dark : light}
45
+ customStyle={{
46
+ background: 'unset',
47
+ border: 'none',
48
+ boxShadow: 'none',
49
+ padding: 0,
50
+ margin: 0,
51
+ }}
52
+ {...props}
53
+ >
54
+ {/* Non-empty fallback prevents collapse. */}
55
+ {children || fallback}
56
+ </NativeSyntaxHighlighter>
57
+ </div>
58
+ </ScrollArea.Viewport>
59
+ </ScrollArea.Root>
57
60
  );
58
61
  };
59
62