@dxos/react-ui-syntax-highlighter 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-syntax-highlighter",
3
- "version": "0.8.4-main.dedc0f3",
3
+ "version": "0.8.4-main.e8ec1fe",
4
4
  "description": "A syntax highlighter wrapper.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -27,27 +27,28 @@
27
27
  "dependencies": {
28
28
  "@preact-signals/safe-react": "^0.9.0",
29
29
  "jsonpath": "^1.1.1",
30
- "react-syntax-highlighter": "^15.6.1"
30
+ "react-syntax-highlighter": "^15.6.1",
31
+ "@dxos/util": "0.8.4-main.e8ec1fe"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/jsonpath": "^0.2.4",
34
- "@types/react": "~18.2.0",
35
- "@types/react-dom": "~18.2.0",
35
+ "@types/react": "~19.2.2",
36
+ "@types/react-dom": "~19.2.2",
36
37
  "@types/react-syntax-highlighter": "^15.5.13",
37
- "react": "~18.2.0",
38
- "react-dom": "~18.2.0",
39
- "vite": "7.1.1",
40
- "@dxos/random": "0.8.4-main.dedc0f3",
41
- "@dxos/react-ui": "0.8.4-main.dedc0f3",
42
- "@dxos/react-ui-theme": "0.8.4-main.dedc0f3",
43
- "@dxos/storybook-utils": "0.8.4-main.dedc0f3",
44
- "@dxos/util": "0.8.4-main.dedc0f3"
38
+ "react": "~19.2.0",
39
+ "react-dom": "~19.2.0",
40
+ "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"
45
46
  },
46
47
  "peerDependencies": {
47
- "react": "~18.2.0",
48
- "react-dom": "~18.2.0",
49
- "@dxos/react-ui": "0.8.4-main.dedc0f3",
50
- "@dxos/react-ui-theme": "0.8.4-main.dedc0f3"
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
52
  },
52
53
  "publishConfig": {
53
54
  "access": "public"
@@ -2,12 +2,11 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
6
+ import React from 'react';
8
7
 
9
8
  import { faker } from '@dxos/random';
10
- import { ColumnContainer, withLayout, withTheme } from '@dxos/storybook-utils';
9
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
11
10
 
12
11
  import { Json } from './Json';
13
12
 
@@ -57,7 +56,7 @@ const createData = ({ depth = 2, children = 3 } = {}): any => {
57
56
  const meta = {
58
57
  title: 'ui/react-ui-syntax-highlighter/Json',
59
58
  component: Json,
60
- decorators: [withTheme, withLayout({ fullscreen: true, Container: ColumnContainer })],
59
+ decorators: [withTheme, withLayout({ container: 'column' })],
61
60
  } satisfies Meta<typeof Json>;
62
61
 
63
62
  export default meta;
@@ -93,3 +92,15 @@ export const Large: Story = {
93
92
  },
94
93
  },
95
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
@@ -7,10 +7,11 @@ import jp from 'jsonpath';
7
7
  import React, { 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';
14
+ const defaultClassNames = 'grow overflow-y-auto text-sm';
14
15
 
15
16
  export type JsonProps = ThemedClassName<{
16
17
  data?: any;
@@ -27,7 +28,7 @@ export const Json = ({ filter, ...params }: JsonProps) => {
27
28
  const { classNames, data, replacer, testId } = params;
28
29
  return (
29
30
  <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
30
- {JSON.stringify(data, replacer && createReplacer(replacer), 2)}
31
+ {safeStringify(data, replacer && createReplacer(replacer), 2)}
31
32
  </SyntaxHighlighter>
32
33
  );
33
34
  };
@@ -54,7 +55,7 @@ export const JsonFilter = ({ classNames, data: initialData, replacer, testId }:
54
55
  <div className='flex flex-col grow overflow-hidden'>
55
56
  <Input.Root validationValence={error ? 'error' : 'success'}>
56
57
  <Input.TextInput
57
- classNames={['p-1 px-2 font-mono', error && 'border-red-500']}
58
+ classNames={['p-1 pli-2 font-mono', error && 'border-red-500']}
58
59
  variant='subdued'
59
60
  value={text}
60
61
  onChange={(event) => setText(event.target.value)}
@@ -62,69 +63,8 @@ export const JsonFilter = ({ classNames, data: initialData, replacer, testId }:
62
63
  />
63
64
  </Input.Root>
64
65
  <SyntaxHighlighter language='json' classNames={[defaultClassNames, classNames]} data-testid={testId}>
65
- {JSON.stringify(data, replacer && createReplacer(replacer), 2)}
66
+ {safeStringify(data, replacer && createReplacer(replacer), 2)}
66
67
  </SyntaxHighlighter>
67
68
  </div>
68
69
  );
69
70
  };
70
-
71
- export type CreateReplacerProps = {
72
- omit?: string[];
73
- parse?: string[];
74
- maxDepth?: number;
75
- maxArrayLen?: number;
76
- maxStringLen?: number;
77
- };
78
-
79
- export type JsonReplacer = (this: any, key: string, value: any) => any;
80
-
81
- export const createReplacer = ({
82
- omit,
83
- parse,
84
- maxDepth,
85
- maxArrayLen,
86
- maxStringLen,
87
- }: CreateReplacerProps): JsonReplacer => {
88
- let currentDepth = 0;
89
- const depthMap = new WeakMap<object, number>();
90
-
91
- return function (this: any, key: string, value: any) {
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;
119
- }
120
- }
121
- if (maxArrayLen != null && Array.isArray(value) && value.length > maxArrayLen) {
122
- return `[length: ${value.length}]`;
123
- }
124
- if (maxStringLen != null && typeof value === 'string' && value.length > maxStringLen) {
125
- return value.slice(0, maxStringLen) + '...';
126
- }
127
-
128
- return value;
129
- };
130
- };
@@ -2,11 +2,9 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import '@dxos-theme';
6
-
7
5
  import { type Meta, type StoryObj } from '@storybook/react-vite';
8
6
 
9
- import { withTheme } from '@dxos/storybook-utils';
7
+ import { withTheme } from '@dxos/react-ui/testing';
10
8
  import { trim } from '@dxos/util';
11
9
 
12
10
  import { SyntaxHighlighter } from './SyntaxHighlighter';
@@ -25,6 +25,7 @@ export type SyntaxHighlighterProps = ThemedClassName<
25
25
  * https://github.com/react-syntax-highlighter/react-syntax-highlighter
26
26
  * https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html
27
27
  */
28
+ // TODO(burdon): Replace with react-ui-editor (and reuse styles).
28
29
  export const SyntaxHighlighter = ({
29
30
  classNames,
30
31
  children,
@@ -35,9 +36,9 @@ export const SyntaxHighlighter = ({
35
36
  const { themeMode } = useThemeContext();
36
37
 
37
38
  return (
38
- <div className={mx('is-full p-1 overflow-hidden font-thin text-baseText', classNames)}>
39
+ <div className={mx('flex is-full p-1 overflow-hidden', classNames)}>
39
40
  <NativeSyntaxHighlighter
40
- className='is-full overflow-auto scrollbar-thin'
41
+ className='!m-0 is-full overflow-auto scrollbar-thin'
41
42
  language={languages[language as keyof typeof languages] || language}
42
43
  style={themeMode === 'dark' ? dark : light}
43
44
  customStyle={{