@apify/ui-library 0.65.3-featuresyntaxhighlighter-48cb44.38 → 0.65.3

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/src/components/code/code_block/code_block.d.ts.map +1 -1
  3. package/dist/src/components/code/code_block/code_block.js +20 -14
  4. package/dist/src/components/code/code_block/code_block.js.map +1 -1
  5. package/dist/src/components/code/code_block/code_block.styled.d.ts +2 -8
  6. package/dist/src/components/code/code_block/code_block.styled.d.ts.map +1 -1
  7. package/dist/src/components/code/code_block/code_block.styled.js +68 -14
  8. package/dist/src/components/code/code_block/code_block.styled.js.map +1 -1
  9. package/dist/src/components/code/code_block/utils.d.ts +1 -5
  10. package/dist/src/components/code/code_block/utils.d.ts.map +1 -1
  11. package/dist/src/components/code/code_block/utils.js +12 -23
  12. package/dist/src/components/code/code_block/utils.js.map +1 -1
  13. package/dist/src/components/code/index.d.ts +0 -1
  14. package/dist/src/components/code/index.d.ts.map +1 -1
  15. package/dist/src/components/code/index.js +0 -1
  16. package/dist/src/components/code/index.js.map +1 -1
  17. package/dist/src/components/code/one_line_code/one_line_code.d.ts.map +1 -1
  18. package/dist/src/components/code/one_line_code/one_line_code.js +23 -5
  19. package/dist/src/components/code/one_line_code/one_line_code.js.map +1 -1
  20. package/dist/src/components/code/syntax_highlighter.d.ts +15 -0
  21. package/dist/src/components/code/syntax_highlighter.d.ts.map +1 -0
  22. package/dist/src/components/code/syntax_highlighter.js +103 -0
  23. package/dist/src/components/code/syntax_highlighter.js.map +1 -0
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/package.json +5 -5
  26. package/src/components/code/code_block/code_block.styled.tsx +69 -21
  27. package/src/components/code/code_block/code_block.tsx +36 -25
  28. package/src/components/code/code_block/utils.ts +19 -0
  29. package/src/components/code/index.ts +0 -1
  30. package/src/components/code/one_line_code/one_line_code.tsx +28 -9
  31. package/src/components/code/syntax_highlighter.tsx +134 -0
  32. package/dist/src/components/code/prism_highlighter.d.ts +0 -15
  33. package/dist/src/components/code/prism_highlighter.d.ts.map +0 -1
  34. package/dist/src/components/code/prism_highlighter.js +0 -116
  35. package/dist/src/components/code/prism_highlighter.js.map +0 -1
  36. package/src/components/code/code_block/utils.tsx +0 -50
  37. package/src/components/code/prism_highlighter.tsx +0 -178
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apify/ui-library",
3
- "version": "0.65.3-featuresyntaxhighlighter-48cb44.38+b70ba94452a",
3
+ "version": "0.65.3",
4
4
  "description": "React UI library used by apify.com",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -26,17 +26,16 @@
26
26
  "It's not nice, but helps us to get around the problem of multiple react instances."
27
27
  ],
28
28
  "dependencies": {
29
- "@apify/ui-icons": "^0.9.0",
29
+ "@apify/ui-icons": "^0.10.0",
30
30
  "@floating-ui/react": "^0.26.2",
31
31
  "clsx": "^2.0.0",
32
32
  "dayjs": "1.11.9",
33
33
  "fast-average-color": "^9.4.0",
34
34
  "history": "^5.3.0",
35
35
  "lodash": "^4.17.21",
36
- "prism-react-renderer": "^2.4.1",
37
- "prismjs": "^1.30.0",
38
36
  "query-string": "^8.1.0",
39
37
  "react-markdown": "^8.0.5",
38
+ "react-syntax-highlighter": "^15.5.0",
40
39
  "rehype-raw": "^6.1.1",
41
40
  "rehype-sanitize": "^6.0.0",
42
41
  "remark-gfm": "^3.0.1",
@@ -55,6 +54,7 @@
55
54
  "@types/lodash": "^4.14.200",
56
55
  "@types/node": "^22.10.5",
57
56
  "@types/react": "^18.2.74",
57
+ "@types/react-syntax-highlighter": "^15.5.9",
58
58
  "@types/styled-components": "^5.1.34",
59
59
  "eslint": "^9.22.0",
60
60
  "eslint-plugin-import": "2.26.0",
@@ -65,5 +65,5 @@
65
65
  "typescript": "^5.1.6",
66
66
  "typescript-eslint": "^8.24.0"
67
67
  },
68
- "gitHead": "b70ba94452adee75cf6d7d6567ae43a7d5bf8bba"
68
+ "gitHead": "d28107308e89cc139489334a352f51de1ce3ff8f"
69
69
  }
@@ -1,28 +1,10 @@
1
1
  import styled, { css } from 'styled-components';
2
2
 
3
3
  import { theme } from '../../../design_system/theme.js';
4
- import { Box } from '../../box.js';
5
- import type { SharedTextProps, SharedTextSize } from '../../text/text_shared.js';
4
+ import type { SharedTextSize } from '../../text/text_shared.js';
5
+ import { SyntaxHighlighterBaseStylesWrapper } from '../syntax_highlighter.js';
6
6
 
7
- export type SyntaxHighlighterBaseStylesWrapperProps = SharedTextProps & {
8
- $fullWidth?: boolean;
9
- $fullHeight?: string;
10
- $showLineNumbers?: boolean;
11
- }
12
-
13
- export const SyntaxHighlighterBaseStylesWrapper = styled(Box)<SyntaxHighlighterBaseStylesWrapperProps>`
14
- background-color: ${theme.color.neutral.backgroundMuted} !important;
15
- border: 1px solid ${theme.color.neutral.border};
16
- border-radius: ${theme.radius.radius12};
17
- overflow: hidden;
18
-
19
- width: 100%;
20
- ${({ $fullWidth }) => !$fullWidth && css`max-width: 860px;`}
21
- ${({ $fullHeight }) => !$fullHeight && css`max-height: 600px;`}
22
-
23
- background-color: transparent;
24
- position: relative;
25
- `;
7
+ const HIGHLIGHT_BACKGROUND_COLOR = 'rgba(22, 114, 235, 0.05)';
26
8
 
27
9
  export const CodeBlockWrapper = styled(SyntaxHighlighterBaseStylesWrapper) <{
28
10
  $hasHeader: boolean;
@@ -123,6 +105,72 @@ export const CodeBlockWrapper = styled(SyntaxHighlighterBaseStylesWrapper) <{
123
105
  }
124
106
  }
125
107
 
108
+ .CodePre {
109
+ z-index: 2;
110
+ padding: ${theme.space.space16} 0 !important;
111
+
112
+ code {
113
+ & > span {
114
+ display: block;
115
+ padding-left: ${({ $showLineNumbers }) => ($showLineNumbers ? theme.space.space8 : theme.space.space16)};
116
+ padding-right: ${theme.space.space16};
117
+ &:hover {
118
+ background-color: ${HIGHLIGHT_BACKGROUND_COLOR} !important;
119
+ border-left: 6px solid ${theme.color.neutral.border} !important;
120
+ padding-left: ${({ $showLineNumbers }) => ($showLineNumbers ? '0.2' : '1')}rem;
121
+ }
122
+ }
123
+
124
+ // Common styles
125
+ [data*='bash']{
126
+ &::before {
127
+ color: ${theme.color.lavender.base};
128
+ padding-right: ${theme.space.space16};
129
+ min-width: ${theme.space.space24};
130
+ user-select: none;
131
+ -webkit-user-select: none;
132
+ font-size: 1em;
133
+ }
134
+ }
135
+
136
+ [data*='bashStartCommand'] {
137
+ &::before {
138
+ content: '$';
139
+ }
140
+ }
141
+
142
+ [data*='bashCommand'] {
143
+ &::before {
144
+ content: '>';
145
+ }
146
+ }
147
+
148
+ [data*='bashEmptyLine'] {
149
+ &::before {
150
+ content: ' ';
151
+ }
152
+ }
153
+
154
+ [data*='highlighted'] {
155
+ background-color: ${HIGHLIGHT_BACKGROUND_COLOR} !important;
156
+ border-left: 6px solid ${theme.color.neutral.border} !important;
157
+ padding-left: ${({ $showLineNumbers }) => ($showLineNumbers ? '0.2' : '1')}rem;
158
+ }
159
+
160
+
161
+ .linenumber {
162
+ color: ${theme.color.neutral.textSubtle} !important;
163
+ padding-right: ${theme.space.space16} !important;
164
+ min-width: ${theme.space.space24} !important;
165
+ box-sizing: unset !important;
166
+ user-select: none;
167
+ -webkit-user-select: none;
168
+
169
+ ${({ $showLineNumbers }) => (!$showLineNumbers && css`display: none !important;`)}
170
+
171
+ }
172
+ }
173
+ }
126
174
 
127
175
  .CodeBlock-TopRightActionsWrapper {
128
176
  position: absolute;
@@ -1,5 +1,5 @@
1
1
  import clsx from 'clsx';
2
- import React, { useMemo, useRef, useState } from 'react';
2
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
3
3
 
4
4
  import type { RegularBoxProps } from '../../box.js';
5
5
  import { ColorWheelGradient } from '../../color_wheel_gradient.js';
@@ -7,9 +7,9 @@ import { Link } from '../../link.js';
7
7
  import { Text } from '../../text/index.js';
8
8
  import type { SharedTextSize } from '../../text/text_shared.js';
9
9
  import { ActionButton, CopyButton } from '../action_button.js';
10
- import { PrismSyntaxHighlighter } from '../prism_highlighter.js';
10
+ import { SyntaxHighlighter } from '../syntax_highlighter.js';
11
11
  import { CodeBlockWrapper } from './code_block.styled.js';
12
- import { getBashLinePrefixes, getNumberLinePrefixes } from './utils.js';
12
+ import { mapPrefixToBashLine } from './utils.js';
13
13
 
14
14
  type CodeTab = {
15
15
  key: string;
@@ -149,7 +149,9 @@ export const CodeBlock = ({
149
149
 
150
150
  const isBash = currentLanguage === 'bash';
151
151
 
152
- const showLineNumbers = !hideLineNumbers && !LANGUAGES_WITHOUT_LINE_NUMBERS.includes(currentLanguage ?? '');
152
+ const showLineNumbers = !hideLineNumbers
153
+ && !LANGUAGES_WITHOUT_LINE_NUMBERS.includes(currentLanguage ?? '');
154
+ const showBashPrompt = isBash && !hideBashPromptPrefixes;
153
155
  const showBashHeader = isBash && !hideBashHeader && !isMultiTab;
154
156
 
155
157
  const showHeader = isMultiTab || !!title || showBashHeader;
@@ -162,20 +164,28 @@ export const CodeBlock = ({
162
164
  syntaxHighlighterRef.current?.scrollTo(0, 0);
163
165
  };
164
166
 
165
- const showBashPrompt = isBash && !hideBashPromptPrefixes;
166
- const effectiveBashCommandsStart = currentTab?.bashCommandsStart ?? bashCommandsStart;
167
-
168
- const linePrefixes = useMemo(() => {
169
- if (showBashPrompt) {
170
- return getBashLinePrefixes(currentCode, effectiveBashCommandsStart);
171
- }
172
-
173
- if (showLineNumbers) {
174
- return getNumberLinePrefixes(currentCode);
175
- }
176
-
177
- return {};
178
- }, [showLineNumbers, showBashPrompt, currentCode, effectiveBashCommandsStart]);
167
+ const currentBashLinesPrefixes = useMemo(() => {
168
+ if (!showBashPrompt) return [];
169
+ return mapPrefixToBashLine(
170
+ currentCode,
171
+ currentTab?.bashCommandsStart ?? bashCommandsStart,
172
+ );
173
+ }, [currentCode, bashCommandsStart, showBashPrompt, currentTab]);
174
+
175
+ const getLineProps = useCallback(
176
+ (lineNumber: number) => {
177
+ const data = [];
178
+ if (currentHighlightLines?.includes(lineNumber)) {
179
+ data.push('highlighted');
180
+ }
181
+ if (showBashPrompt) {
182
+ data.push(currentBashLinesPrefixes[lineNumber - 1]);
183
+ }
184
+
185
+ return { data: data.join(' ') };
186
+ },
187
+ [currentHighlightLines, showBashPrompt, currentBashLinesPrefixes],
188
+ );
179
189
 
180
190
  return (
181
191
  <CodeBlockWrapper
@@ -198,15 +208,16 @@ export const CodeBlock = ({
198
208
  />
199
209
  )}
200
210
 
201
- <PrismSyntaxHighlighter
202
- code={currentCode}
203
- linePrefixes={linePrefixes}
204
- highlightLines={currentHighlightLines}
205
- language={currentLanguage || 'text'}
211
+ <SyntaxHighlighter
212
+ showLineNumbers
213
+ wrapLines
214
+ language={currentLanguage}
206
215
  size={size}
216
+ lineProps={getLineProps}
207
217
  ref={syntaxHighlighterRef}
208
- isSingleLine={false}
209
- />
218
+ >
219
+ {currentCode}
220
+ </SyntaxHighlighter>
210
221
 
211
222
  <div className="CodeBlock-TopRightActionsWrapper">
212
223
  {showActionButton && <ActionButton successStyle onClick={onActionButtonClick}>{actionButtonLabel ?? 'Run on Apify'}</ActionButton>}
@@ -0,0 +1,19 @@
1
+ // input: [2, 4, 5, 6, 8, 10, 11, 12]
2
+ // returns string indicating what type of line it is (bashStartCommand, bashCommand, bashEmptyLine)
3
+ // commands start -> bashStartCommand
4
+ // every next line after command start until next command start or empty line -> bashCommand
5
+ // empty line or comment -> bashEmptyLine
6
+ export const mapPrefixToBashLine = (code: string, bashCommandsStart: number[] = []) => {
7
+ const lines = code.split('\n').map((line) => line.trim());
8
+
9
+ // by default each line that is not empty or comment is a command start
10
+ if (bashCommandsStart.length === 0) {
11
+ return lines.map((line) => ((line.startsWith('#') || !line) ? 'bashEmptyLine' : 'bashStartCommand'));
12
+ }
13
+
14
+ return lines.map((line, i) => {
15
+ if (bashCommandsStart.includes(i + 1)) return 'bashStartCommand';
16
+ if (line.startsWith('#') || !line) return 'bashEmptyLine';
17
+ return 'bashCommand';
18
+ });
19
+ };
@@ -2,4 +2,3 @@ export * from './code_block/code_block.js';
2
2
  export * from './code_block/code_block_with_tabs.js';
3
3
  export * from './one_line_code/one_line_code.js';
4
4
  export * from './inline_code/inline_code.js';
5
- export * from './prism_highlighter.js';
@@ -8,9 +8,8 @@ import type { BoxProps } from '../../box.js';
8
8
  import { Text } from '../../text/index.js';
9
9
  import type { SharedTextSize } from '../../text/text_shared.js';
10
10
  import { ActionButton, CopyButton } from '../action_button.js';
11
- import type { SyntaxHighlighterBaseStylesWrapperProps } from '../code_block/code_block.styled.js';
12
- import { SyntaxHighlighterBaseStylesWrapper } from '../code_block/code_block.styled.js';
13
- import { PrismSyntaxHighlighter } from '../prism_highlighter.js';
11
+ import type { SyntaxHighlighterBaseStylesWrapperProps } from '../syntax_highlighter.js';
12
+ import { SyntaxHighlighter, SyntaxHighlighterBaseStylesWrapper } from '../syntax_highlighter.js';
14
13
 
15
14
  export const oneLineCodeClassNames = {
16
15
  gradientWrapper: 'OneLineCode-GradientWrapper',
@@ -93,7 +92,6 @@ const OneLineCodeWrapper = styled(SyntaxHighlighterBaseStylesWrapper)<OneLineCod
93
92
  top: 0;
94
93
  bottom: 0;
95
94
  width: 4rem;
96
- z-index: 5;
97
95
  background: linear-gradient(
98
96
  to right,
99
97
  transparent,
@@ -116,12 +114,32 @@ const OneLineCodeWrapper = styled(SyntaxHighlighterBaseStylesWrapper)<OneLineCod
116
114
  scrollbar-color: ${theme.color.neutral.border} transparent;
117
115
 
118
116
 
119
- pre {
117
+ .CodePre {
120
118
  overflow: unset !important;
121
119
  display: flex;
122
120
  flex: 1;
123
121
  align-items: center;
124
122
  height: 2.8rem;
123
+
124
+ code {
125
+ & > span {
126
+ text-overflow: ellipsis;
127
+ overflow: hidden;
128
+ white-space: nowrap;
129
+ vertical-align: text-top;
130
+ ${({ $showBashPrefixes }) => $showBashPrefixes && css`
131
+ &::before {
132
+ color: ${theme.color.lavender.base};
133
+ padding-right: ${theme.space.space16};
134
+ min-width: ${theme.space.space24};
135
+ user-select: none;
136
+ -webkit-user-select: none;
137
+ content: "$";
138
+ font-size: 1em;
139
+ }
140
+ `}
141
+ }
142
+ }
125
143
  }
126
144
  }
127
145
  `;
@@ -179,12 +197,13 @@ export function OneLineCode({
179
197
  {httpMethod}
180
198
  </Text>
181
199
  )}
182
- <PrismSyntaxHighlighter
200
+ <SyntaxHighlighter
183
201
  language={language}
184
202
  size={size}
185
- code={code}
186
- isSingleLine={true}
187
- />
203
+ wrapLines
204
+ >
205
+ {code}
206
+ </SyntaxHighlighter>
188
207
  </div>
189
208
  <div className={oneLineCodeClassNames.gradient} />
190
209
  </div>
@@ -0,0 +1,134 @@
1
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
2
+ import { forwardRef } from 'react';
3
+ // https://github.com/react-syntax-highlighter/react-syntax-highlighter/issues/228
4
+ import type { SyntaxHighlighterProps as ReactSyntaxHighlighterProps } from 'react-syntax-highlighter';
5
+ // @ts-ignore The library is badly typed and does not export the type
6
+ import bash from 'react-syntax-highlighter/dist/esm/languages/prism/bash.js';
7
+ // @ts-ignore The library is badly typed and does not export the type
8
+ import dockerFile from 'react-syntax-highlighter/dist/esm/languages/prism/docker.js';
9
+ // @ts-ignore The library is badly typed and does not export the type
10
+ import http from 'react-syntax-highlighter/dist/esm/languages/prism/http.js';
11
+ // @ts-ignore The library is badly typed and does not export the type
12
+ import js from 'react-syntax-highlighter/dist/esm/languages/prism/javascript.js';
13
+ // @ts-ignore The library is badly typed and does not export the type
14
+ import json from 'react-syntax-highlighter/dist/esm/languages/prism/json.js';
15
+ // @ts-ignore The library is badly typed and does not export the type
16
+ import html from 'react-syntax-highlighter/dist/esm/languages/prism/markup.js';
17
+ // @ts-ignore The library is badly typed and does not export the type
18
+ import python from 'react-syntax-highlighter/dist/esm/languages/prism/python.js';
19
+ // @ts-ignore The library is badly typed and does not export the type
20
+ import ts from 'react-syntax-highlighter/dist/esm/languages/prism/typescript.js';
21
+ // @ts-ignore The library is badly typed and does not export the type
22
+ import xml from 'react-syntax-highlighter/dist/esm/languages/prism/xml-doc.js';
23
+ // @ts-ignore The library is badly typed and does not export the type
24
+ import yaml from 'react-syntax-highlighter/dist/esm/languages/prism/yaml.js';
25
+ // @ts-ignore The library is badly typed and does not export the type
26
+ import ReactSyntaxHighlighter from 'react-syntax-highlighter/dist/esm/prism-light.js';
27
+ // @ts-ignore The library is badly typed and does not export the type
28
+ import dark from 'react-syntax-highlighter/dist/esm/styles/prism/night-owl.js';
29
+ // @ts-ignore The library is badly typed and does not export the type
30
+ import light from 'react-syntax-highlighter/dist/esm/styles/prism/prism.js';
31
+ /* tslint:enable */
32
+ import styled, { css } from 'styled-components';
33
+
34
+ import { theme } from '../../design_system/theme.js';
35
+ import { useSharedUiDependencies } from '../../ui_dependency_provider.js';
36
+ import { Box } from '../box.js';
37
+ import { type SharedTextProps, Text } from '../text/index.js';
38
+ import type { SharedTextSize } from '../text/text_shared.js';
39
+
40
+ ReactSyntaxHighlighter.registerLanguage('typescript', ts);
41
+ ReactSyntaxHighlighter.registerLanguage('javascript', js);
42
+ ReactSyntaxHighlighter.registerLanguage('json', json);
43
+ ReactSyntaxHighlighter.registerLanguage('bash', bash);
44
+ ReactSyntaxHighlighter.registerLanguage('docker', dockerFile);
45
+ ReactSyntaxHighlighter.registerLanguage('html', html);
46
+ ReactSyntaxHighlighter.registerLanguage('xml', xml);
47
+ ReactSyntaxHighlighter.registerLanguage('yaml', yaml);
48
+ ReactSyntaxHighlighter.registerLanguage('python', python);
49
+ ReactSyntaxHighlighter.registerLanguage('http', http);
50
+ ReactSyntaxHighlighter.registerLanguage('jsonp', json);
51
+ ReactSyntaxHighlighter.registerLanguage('jsonl', json);
52
+ ReactSyntaxHighlighter.registerLanguage('rss', xml);
53
+
54
+ const StyledPre = styled(Text)`
55
+ width: 100%;
56
+ position: relative;
57
+
58
+ *,
59
+ *::before,
60
+ *::after {
61
+ text-shadow: none !important;
62
+ font-style: normal !important;
63
+ font-family: inherit !important;
64
+ font-size: inherit !important;
65
+ font-weight: inherit !important;
66
+ line-height: inherit !important;
67
+ background-color: transparent !important;
68
+ }
69
+
70
+ code {
71
+ min-width: 100%;
72
+ display: inline-block;
73
+ vertical-align: middle;
74
+ overflow: hidden;
75
+ }
76
+ `;
77
+
78
+ // Syntax highlighter uses inline style a lot which makes it hard to override them. To do so, we make the library not
79
+ // use styles that we wish to set on our own (font-based styles, spacing, background, ...),
80
+ const inlineCssReset = {
81
+ fontFamily: undefined,
82
+ fontSize: undefined,
83
+ fontWeight: undefined,
84
+ lineHeight: undefined,
85
+ background: undefined,
86
+ margin: undefined,
87
+ padding: undefined,
88
+ };
89
+
90
+ type SyntaxHighlighterProps = ReactSyntaxHighlighterProps & { size: SharedTextSize };
91
+
92
+ export const SyntaxHighlighter = forwardRef<HTMLPreElement, SyntaxHighlighterProps>(({
93
+ size,
94
+ children,
95
+ ...rest
96
+ }, ref) => {
97
+ const { uiTheme } = useSharedUiDependencies();
98
+
99
+ const PreTag = (preProps: ReactSyntaxHighlighterProps) => {
100
+ return <StyledPre {...preProps} size={size} forwardedAs='pre' type='code' ref={ref}/>;
101
+ };
102
+
103
+ return (
104
+ <ReactSyntaxHighlighter
105
+ PreTag={PreTag}
106
+ customStyle={inlineCssReset}
107
+ className="CodePre"
108
+ style={uiTheme === 'DARK' ? dark : light}
109
+ {...rest}
110
+ >
111
+ {children}
112
+ </ReactSyntaxHighlighter>
113
+ );
114
+ });
115
+
116
+ export type SyntaxHighlighterBaseStylesWrapperProps = SharedTextProps & {
117
+ $fullWidth?: boolean;
118
+ $fullHeight?: string;
119
+ $showLineNumbers?: boolean;
120
+ }
121
+
122
+ export const SyntaxHighlighterBaseStylesWrapper = styled(Box)<SyntaxHighlighterBaseStylesWrapperProps>`
123
+ background-color: ${theme.color.neutral.backgroundMuted} !important;
124
+ border: 1px solid ${theme.color.neutral.border};
125
+ border-radius: ${theme.radius.radius12};
126
+ overflow: hidden;
127
+
128
+ width: 100%;
129
+ ${({ $fullWidth }) => !$fullWidth && css`max-width: 860px;`}
130
+ ${({ $fullHeight }) => !$fullHeight && css`max-height: 600px;`}
131
+
132
+ background-color: transparent;
133
+ position: relative;
134
+ `;
@@ -1,15 +0,0 @@
1
- import type { HighlightProps } from 'prism-react-renderer';
2
- import type { ReactNode } from 'react';
3
- import type { SharedTextSize } from '../text/text_shared.js';
4
- export declare const CodeHighlighterLinePrefix: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("../text/text_shared.js").SharedTextProps & import("react").RefAttributes<HTMLElement | undefined>>, any, {
5
- as: "span";
6
- }, "as">;
7
- export declare const PrismSyntaxHighlighter: import("react").ForwardRefExoticComponent<Omit<HighlightProps, "children" | "language"> & {
8
- size?: SharedTextSize;
9
- linePrefixes?: Record<string, ReactNode>;
10
- highlightLines?: number[];
11
- language?: string;
12
- className?: string;
13
- isSingleLine: boolean;
14
- } & import("react").RefAttributes<HTMLPreElement>>;
15
- //# sourceMappingURL=prism_highlighter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prism_highlighter.d.ts","sourceRoot":"","sources":["../../../../src/components/code/prism_highlighter.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAuG7D,eAAO,MAAM,yBAAyB;;QAQrC,CAAC;AAWF,eAAO,MAAM,sBAAsB;WARxB,cAAc;mBACN,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC;qBACvB,MAAM,EAAE;eACd,MAAM;gBACL,MAAM;kBACJ,OAAO;kDA+CvB,CAAC"}
@@ -1,116 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import clsx from 'clsx';
3
- import _ from 'lodash';
4
- import { Highlight, Prism, themes } from 'prism-react-renderer';
5
- import { forwardRef, useRef } from 'react';
6
- import styled, { css } from 'styled-components';
7
- import { theme } from '../../design_system/theme.js';
8
- import { useSharedUiDependencies } from '../../ui_dependency_provider.js';
9
- import { Text } from '../text/index.js';
10
- (typeof global !== 'undefined' ? global : window).Prism = Prism;
11
- const HIGHLIGHT_BACKGROUND_COLOR = 'rgba(22, 114, 235, 0.05)';
12
- const loadLanguages = async () => {
13
- await Promise.all([
14
- // @ts-expect-error The library is badly typed and does not export the type
15
- import('prismjs/components/prism-bash.js'),
16
- // @ts-expect-error The library is badly typed and does not export the type
17
- import('prismjs/components/prism-rust.js'),
18
- // @ts-expect-error The library is badly typed and does not export the type
19
- import('prismjs/components/prism-bash.js'),
20
- // @ts-expect-error The library is badly typed and does not export the type
21
- import('prismjs/components/prism-docker.js'),
22
- // @ts-expect-error The library is badly typed and does not export the type
23
- import('prismjs/components/prism-http.js'),
24
- // @ts-expect-error The library is badly typed and does not export the type
25
- import('prismjs/components/prism-javascript.js'),
26
- // @ts-expect-error The library is badly typed and does not export the type
27
- import('prismjs/components/prism-json.js'),
28
- // @ts-expect-error The library is badly typed and does not export the type
29
- import('prismjs/components/prism-markup.js'),
30
- // @ts-expect-error The library is badly typed and does not export the type
31
- import('prismjs/components/prism-python.js'),
32
- // @ts-expect-error The library is badly typed and does not export the type
33
- import('prismjs/components/prism-typescript.js'),
34
- // @ts-expect-error The library is badly typed and does not export the type
35
- import('prismjs/components/prism-xml-doc.js'),
36
- // @ts-expect-error The library is badly typed and does not export the type
37
- import('prismjs/components/prism-yaml.js'),
38
- ]);
39
- };
40
- void loadLanguages();
41
- const StyledPre = styled.pre `
42
- width: 100%;
43
- position: relative;
44
- overflow: auto;
45
- z-index: 2;
46
- padding: ${({ $isSingleLine }) => ($isSingleLine ? 0 : `${theme.space.space16} 0`)};
47
- margin: 0;
48
-
49
- code {
50
- min-width: 100%;
51
- display: inline-block;
52
- vertical-align: middle;
53
-
54
- *,
55
- *::before,
56
- *::after {
57
- text-shadow: none !important;
58
- font-style: normal !important;
59
- font-family: inherit !important;
60
- font-size: inherit !important;
61
- font-weight: inherit !important;
62
- line-height: inherit !important;
63
- background-color: transparent !important;
64
- }
65
-
66
- & > div {
67
- display: block;
68
-
69
- &.highlighted {
70
- background-color: ${HIGHLIGHT_BACKGROUND_COLOR} !important;
71
- border-left: 6px solid ${theme.color.neutral.border} !important;
72
- padding-left: ${({ $hasLinePrefixes }) => ($hasLinePrefixes ? '0.2' : '1')}rem;
73
- }
74
-
75
- ${({ $isSingleLine }) => !$isSingleLine && css `
76
- &:hover {
77
- background-color: ${HIGHLIGHT_BACKGROUND_COLOR} !important;
78
- border-left: 6px solid ${theme.color.neutral.border} !important;
79
- padding-left: ${({ $hasLinePrefixes }) => ($hasLinePrefixes ? '0.2' : '1')}rem;
80
- }
81
- `}
82
-
83
- ${({ $isSingleLine }) => ($isSingleLine ? css `
84
- text-overflow: ellipsis;
85
- overflow: hidden;
86
- white-space: nowrap;
87
- vertical-align: text-top;
88
- ` : css `
89
- padding-left: ${({ $hasLinePrefixes }) => ($hasLinePrefixes ? theme.space.space8 : theme.space.space16)};
90
- padding-right: ${theme.space.space16};
91
-
92
- &:hover {
93
- background-color: ${HIGHLIGHT_BACKGROUND_COLOR} !important;
94
- border-left: 6px solid ${theme.color.neutral.border} !important;
95
- padding-left: ${({ $hasLinePrefixes }) => ($hasLinePrefixes ? '0.2' : '1')}rem;
96
- }
97
- `)}
98
- }
99
- }
100
- `;
101
- export const CodeHighlighterLinePrefix = styled(Text).attrs({ as: 'span' }) `
102
- display: inline-block;
103
- margin-right: ${theme.space.space16};
104
- text-align: right;
105
- min-width: ${theme.space.space24};
106
- color: ${({ color }) => color || theme.color.neutral.textSubtle};
107
- user-select: none;
108
- -webkit-user-select: none;
109
- `;
110
- export const PrismSyntaxHighlighter = forwardRef(({ size = 'regular', linePrefixes = {}, highlightLines = [], language = 'javascript', className, isSingleLine, ...rest }, ref) => {
111
- const { uiTheme } = useSharedUiDependencies();
112
- const hasLinePrefixes = !_.isEmpty(linePrefixes);
113
- const highlightedLinesObject = useRef(Object.fromEntries(highlightLines.map((e) => [e, true])));
114
- return (_jsx(Highlight, { theme: uiTheme === 'DARK' ? themes.nightOwl : themes.oneLight, language: language, ...rest, children: ({ className: prismClassName, tokens, getLineProps, getTokenProps }) => (_jsx(StyledPre, { className: clsx(className, prismClassName), "$hasLinePrefixes": hasLinePrefixes, "$isSingleLine": isSingleLine, ref: ref, children: _jsx(Text, { size: size, type: 'code', as: 'code', children: tokens.map((line, i) => (_jsxs("div", { ...getLineProps({ line, className: highlightedLinesObject.current[i + 1] ? 'highlighted' : '' }), children: [hasLinePrefixes && (linePrefixes[i + 1] || _jsx(CodeHighlighterLinePrefix, {})), line.map((token, key) => (_jsx("span", { ...getTokenProps({ token }) }, key)))] }, i))) }) })) }));
115
- });
116
- //# sourceMappingURL=prism_highlighter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prism_highlighter.js","sourceRoot":"","sources":["../../../../src/components/code/prism_highlighter.tsx"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAGxC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;AAEhE,MAAM,0BAA0B,GAAG,0BAA0B,CAAC;A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