@dxos/react-ui-syntax-highlighter 0.8.4-main.e8ec1fe → 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/package.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-syntax-highlighter",
3
- "version": "0.8.4-main.e8ec1fe",
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": true,
13
+ "sideEffects": false,
10
14
  "type": "module",
11
15
  "exports": {
12
16
  ".": {
@@ -25,30 +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
33
  "react-syntax-highlighter": "^15.6.1",
31
- "@dxos/util": "0.8.4-main.e8ec1fe"
34
+ "@dxos/util": "0.8.4-main.ef1bc66f44"
32
35
  },
33
36
  "devDependencies": {
34
37
  "@types/jsonpath": "^0.2.4",
35
- "@types/react": "~19.2.2",
36
- "@types/react-dom": "~19.2.2",
38
+ "@types/react": "~19.2.7",
39
+ "@types/react-dom": "~19.2.3",
37
40
  "@types/react-syntax-highlighter": "^15.5.13",
38
- "react": "~19.2.0",
39
- "react-dom": "~19.2.0",
41
+ "react": "~19.2.3",
42
+ "react-dom": "~19.2.3",
40
43
  "vite": "7.1.9",
41
- "@dxos/random": "0.8.4-main.e8ec1fe",
42
- "@dxos/react-ui-theme": "0.8.4-main.e8ec1fe",
43
- "@dxos/util": "0.8.4-main.e8ec1fe",
44
- "@dxos/react-ui": "0.8.4-main.e8ec1fe",
45
- "@dxos/storybook-utils": "0.8.4-main.e8ec1fe"
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"
46
49
  },
47
50
  "peerDependencies": {
48
- "react": "^19.0.0",
49
- "react-dom": "^19.0.0",
50
- "@dxos/react-ui": "0.8.4-main.e8ec1fe",
51
- "@dxos/react-ui-theme": "0.8.4-main.e8ec1fe"
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"
52
55
  },
53
56
  "publishConfig": {
54
57
  "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
@@ -4,15 +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
10
  import { type CreateReplacerProps, createReplacer, safeStringify } from '@dxos/util';
11
11
 
12
12
  import { SyntaxHighlighter } from '../SyntaxHighlighter';
13
13
 
14
- const defaultClassNames = 'grow overflow-y-auto text-sm';
15
-
16
14
  export type JsonProps = ThemedClassName<{
17
15
  data?: any;
18
16
  filter?: boolean;
@@ -20,51 +18,63 @@ export type JsonProps = ThemedClassName<{
20
18
  testId?: string;
21
19
  }>;
22
20
 
23
- export const Json = ({ filter, ...params }: JsonProps) => {
24
- if (filter) {
25
- return <JsonFilter {...params} />;
21
+ export const Json = forwardRef<HTMLDivElement, JsonProps>((props, forwardedRef) => {
22
+ if (props.filter) {
23
+ return <JsonFilter {...props} />;
26
24
  }
27
25
 
28
- const { classNames, data, replacer, testId } = params;
26
+ const { classNames, data, replacer, testId } = props;
29
27
  return (
30
- <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
28
+ <SyntaxHighlighter
29
+ language='json'
30
+ classNames={['is-full overflow-y-auto text-sm', classNames]}
31
+ data-testid={testId}
32
+ ref={forwardedRef}
33
+ >
31
34
  {safeStringify(data, replacer && createReplacer(replacer), 2)}
32
35
  </SyntaxHighlighter>
33
36
  );
34
- };
37
+ });
38
+
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);
35
44
 
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) {
45
+ useEffect(() => {
46
+ if (!initialData || !text.trim().length) {
48
47
  setData(initialData);
49
- setError(err as Error);
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
+ }
50
56
  }
51
- }
52
- }, [initialData, text]); // TODO(burdon): Need structural diff.
57
+ }, [initialData, text]); // TODO(burdon): Need structural diff.
53
58
 
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
- };
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/react-ui-theme';
11
+ import { mx } from '@dxos/ui-theme';
12
12
 
13
13
  const zeroWidthSpace = '\u200b';
14
14