@dxos/react-ui-syntax-highlighter 0.8.1 → 0.8.2-main.10c050d

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.
@@ -4,32 +4,38 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
+ import { type Meta, type StoryObj } from '@storybook/react';
8
+
7
9
  import { withTheme } from '@dxos/storybook-utils';
8
10
 
9
11
  import { SyntaxHighlighter } from './SyntaxHighlighter';
10
12
 
11
- export default {
13
+ const meta: Meta<typeof SyntaxHighlighter> = {
12
14
  title: 'ui/react-ui-syntax-highlighter/SyntaxHighlighter',
13
15
  component: SyntaxHighlighter,
14
16
  decorators: [withTheme],
15
17
  };
16
18
 
17
- export const Default = {
19
+ export default meta;
20
+
21
+ type Story = StoryObj<typeof SyntaxHighlighter>;
22
+
23
+ export const Default: Story = {
18
24
  args: {
19
25
  language: 'json',
20
- className: 'text-sm',
26
+ classNames: 'text-sm',
21
27
  children: JSON.stringify({ message: 'DXOS', initialized: true }, null, 2),
22
28
  },
23
29
  };
24
30
 
25
- export const Typescript = {
31
+ export const Typescript: Story = {
26
32
  args: {
27
33
  language: 'ts',
28
34
  children: 'const x = 100;',
29
35
  },
30
36
  };
31
37
 
32
- export const Empty = {
38
+ export const Empty: Story = {
33
39
  args: {
34
40
  children: false,
35
41
  },
@@ -4,16 +4,16 @@
4
4
 
5
5
  import React from 'react';
6
6
  import { type SyntaxHighlighterProps as NativeSyntaxHighlighterProps } from 'react-syntax-highlighter';
7
- // Lightweight version will load specific language parsers asynchronously.
8
7
  // Using `light-async` version directly from dist to avoid any chance of the heavy one being loaded.
8
+ // Lightweight version will load specific language parsers asynchronously.
9
9
  // eslint-disable-next-line no-restricted-imports
10
10
  import NativeSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/light-async';
11
+ // eslint-disable-next-line no-restricted-imports
12
+ import { github as light, a11yDark as dark } from 'react-syntax-highlighter/dist/esm/styles/hljs';
11
13
 
12
14
  import { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
13
15
  import { mx } from '@dxos/react-ui-theme';
14
16
 
15
- import { alabasterDark, githubLight } from './styles';
16
-
17
17
  const zeroWidthSpace = '\u200b';
18
18
 
19
19
  export type SyntaxHighlighterProps = ThemedClassName<
@@ -22,21 +22,24 @@ export type SyntaxHighlighterProps = ThemedClassName<
22
22
  }
23
23
  >;
24
24
 
25
+ light.hljs.background = '';
26
+ dark.hljs.background = '';
27
+
25
28
  /**
26
29
  * https://github.com/react-syntax-highlighter/react-syntax-highlighter
27
30
  */
28
31
  export const SyntaxHighlighter = ({
29
32
  classNames,
30
- fallback = zeroWidthSpace,
31
33
  children,
34
+ fallback = zeroWidthSpace,
32
35
  ...props
33
36
  }: SyntaxHighlighterProps) => {
34
37
  const { themeMode } = useThemeContext();
35
38
 
36
39
  return (
37
40
  <NativeSyntaxHighlighter
38
- className={mx('w-full p-0', classNames)}
39
- style={themeMode === 'dark' ? alabasterDark : githubLight}
41
+ className={mx('w-full p-0 bg-baseSurface font-thin', classNames)}
42
+ style={themeMode === 'dark' ? dark : light}
40
43
  {...props}
41
44
  >
42
45
  {/* Non-empty fallback prevents collapse. */}
package/src/shims.d.ts CHANGED
@@ -3,5 +3,6 @@
3
3
  //
4
4
 
5
5
  declare module 'react-syntax-highlighter/dist/esm/light-async';
6
+
6
7
  declare module 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-dark';
7
8
  declare module 'react-syntax-highlighter/dist/esm/styles/hljs/a11y-light';
@@ -1,10 +0,0 @@
1
- import { type CSSProperties } from 'react';
2
- /**
3
- * https://github.com/findrakecil/hljs-alabaster-dark/blob/master/readme.md
4
- */
5
- export declare const alabasterDark: Record<string, CSSProperties>;
6
- /**
7
- * https://github.com/highlightjs/highlight.js/blob/main/src/styles/github.css
8
- */
9
- export declare const githubLight: Record<string, CSSProperties>;
10
- //# sourceMappingURL=styles.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/SyntaxHighlighter/styles.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;AAM3C;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAoCvD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CA8FrD,CAAC"}
@@ -1,149 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import { type CSSProperties } from 'react';
6
-
7
- // https://highlightjs.org/examples
8
- // https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo
9
- // https://github.com/react-syntax-highlighter/react-syntax-highlighter/blob/master/AVAILABLE_STYLES_HLJS.MD
10
-
11
- /**
12
- * https://github.com/findrakecil/hljs-alabaster-dark/blob/master/readme.md
13
- */
14
- export const alabasterDark: Record<string, CSSProperties> = {
15
- hljs: {
16
- display: 'block',
17
- overflowX: 'auto',
18
- color: '#CECECE',
19
- padding: '0.5em',
20
- },
21
- 'hljs-comment': {
22
- color: '#DFDF8E',
23
- },
24
- 'hljs-string': {
25
- color: '#95CB82',
26
- },
27
- 'hljs-meta-string': {
28
- color: '#95CB82',
29
- },
30
- 'hljs-regexp': {
31
- color: '#95CB82',
32
- },
33
- 'hljs-number': {
34
- color: '#CC8BC9',
35
- },
36
- 'hljs-literal': {
37
- color: '#CC8BC9',
38
- },
39
- 'hljs-title': {
40
- color: '#71ADE7',
41
- },
42
- 'hljs-deletion': {
43
- backgroundColor: '#ffdddd',
44
- color: '#434343',
45
- },
46
- 'hljs-addition': {
47
- backgroundColor: '#ddffdd',
48
- color: '#434343',
49
- },
50
- };
51
-
52
- /**
53
- * https://github.com/highlightjs/highlight.js/blob/main/src/styles/github.css
54
- */
55
- export const githubLight: Record<string, CSSProperties> = {
56
- hljs: {
57
- display: 'block',
58
- overflowX: 'auto',
59
- color: '#545454',
60
- padding: '0.5em',
61
- },
62
- 'hljs-comment': {
63
- color: '#696969',
64
- },
65
- 'hljs-quote': {
66
- color: '#696969',
67
- },
68
- 'hljs-variable': {
69
- color: '#d91e18',
70
- },
71
- 'hljs-template-variable': {
72
- color: '#d91e18',
73
- },
74
- 'hljs-tag': {
75
- color: '#d91e18',
76
- },
77
- 'hljs-name': {
78
- color: '#d91e18',
79
- },
80
- 'hljs-selector-id': {
81
- color: '#d91e18',
82
- },
83
- 'hljs-selector-class': {
84
- color: '#d91e18',
85
- },
86
- 'hljs-regexp': {
87
- color: '#d91e18',
88
- },
89
- 'hljs-deletion': {
90
- color: '#d91e18',
91
- },
92
- 'hljs-number': {
93
- color: '#aa5d00',
94
- },
95
- 'hljs-built_in': {
96
- color: '#aa5d00',
97
- },
98
- 'hljs-builtin-name': {
99
- color: '#aa5d00',
100
- },
101
- 'hljs-literal': {
102
- color: '#aa5d00',
103
- },
104
- 'hljs-type': {
105
- color: '#aa5d00',
106
- },
107
- 'hljs-params': {
108
- color: '#aa5d00',
109
- },
110
- 'hljs-meta': {
111
- color: '#aa5d00',
112
- },
113
- 'hljs-link': {
114
- color: '#aa5d00',
115
- },
116
- 'hljs-attribute': {
117
- color: '#aa5d00',
118
- },
119
- 'hljs-string': {
120
- color: '#008000',
121
- },
122
- 'hljs-symbol': {
123
- color: '#008000',
124
- },
125
- 'hljs-bullet': {
126
- color: '#008000',
127
- },
128
- 'hljs-addition': {
129
- color: '#008000',
130
- },
131
- 'hljs-title': {
132
- color: '#007faa',
133
- },
134
- 'hljs-section': {
135
- color: '#007faa',
136
- },
137
- 'hljs-keyword': {
138
- color: '#7928a1',
139
- },
140
- 'hljs-selector-tag': {
141
- color: '#7928a1',
142
- },
143
- 'hljs-emphasis': {
144
- fontStyle: 'italic',
145
- },
146
- 'hljs-strong': {
147
- fontWeight: 'bold',
148
- },
149
- };