@redocly/theme 0.45.2-rc.0 → 0.45.2
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/lib/components/CodeBlock/CodeBlock.js +5 -11
- package/lib/components/CodeBlock/CodeBlockContainer.d.ts +1 -1
- package/lib/components/CodeBlock/CodeBlockContainer.js +13 -227
- package/lib/components/CodeBlock/variables.js +0 -30
- package/lib/components/Filter/FilterContent.js +4 -1
- package/lib/components/Footer/FooterColumn.js +1 -1
- package/lib/components/Markdown/variables.js +1 -1
- package/lib/components/Search/SearchFilterField.js +2 -2
- package/lib/components/UserMenu/LogoutMenuItem.js +1 -1
- package/lib/components/UserMenu/UserMenu.js +2 -2
- package/lib/core/types/hooks.d.ts +0 -6
- package/lib/core/utils/highlight.d.ts +35 -0
- package/lib/core/utils/highlight.js +129 -0
- package/lib/core/utils/index.d.ts +1 -1
- package/lib/core/utils/index.js +1 -1
- package/lib/core/utils/type-guards.d.ts +6 -0
- package/lib/core/utils/type-guards.js +9 -1
- package/package.json +3 -1
- package/src/components/CodeBlock/CodeBlock.tsx +7 -13
- package/src/components/CodeBlock/CodeBlockContainer.tsx +14 -228
- package/src/components/CodeBlock/variables.ts +0 -30
- package/src/components/Filter/FilterContent.tsx +6 -1
- package/src/components/Footer/FooterColumn.tsx +2 -2
- package/src/components/Markdown/variables.ts +1 -1
- package/src/components/Search/SearchFilterField.tsx +1 -1
- package/src/components/UserMenu/LogoutMenuItem.tsx +1 -2
- package/src/components/UserMenu/UserMenu.tsx +1 -1
- package/src/core/types/hooks.ts +0 -7
- package/src/core/utils/highlight.ts +125 -0
- package/src/core/utils/index.ts +1 -1
- package/src/core/utils/type-guards.ts +12 -0
- package/lib/core/utils/add-line-numbers.d.ts +0 -6
- package/lib/core/utils/add-line-numbers.js +0 -19
- package/src/core/utils/add-line-numbers.ts +0 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@redocly/theme",
|
|
3
|
-
"version": "0.45.2
|
|
3
|
+
"version": "0.45.2",
|
|
4
4
|
"description": "Shared UI components lib",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"theme",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"@markdoc/markdoc": "0.4.0",
|
|
29
29
|
"lodash.throttle": "^4.1.1",
|
|
30
|
+
"prismjs": "^1.28.0",
|
|
30
31
|
"react": "^17.0.0 || ^18.0.0",
|
|
31
32
|
"react-dom": "^17.0.0 || ^18.0.0",
|
|
32
33
|
"react-router-dom": "^6.21.1",
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
"@types/jest-when": "3.5.5",
|
|
44
45
|
"@types/lodash.throttle": "4.1.9",
|
|
45
46
|
"@types/node": "18.19.3",
|
|
47
|
+
"@types/prismjs": "1.26.4",
|
|
46
48
|
"@types/react": "18.3.9",
|
|
47
49
|
"@types/react-dom": "18.2.25",
|
|
48
50
|
"@types/styled-components": "5.1.34",
|
|
@@ -4,8 +4,8 @@ import styled from 'styled-components';
|
|
|
4
4
|
import type { CodeBlockControlsProps } from '@redocly/theme/components/CodeBlock/CodeBlockControls';
|
|
5
5
|
import type { ReportDialogProps } from '@redocly/theme/components/Feedback/ReportDialog';
|
|
6
6
|
|
|
7
|
-
import { addLineNumbers } from '@redocly/theme/core/utils';
|
|
8
|
-
import { useModalScrollLock, useReportDialog
|
|
7
|
+
import { highlight, addLineNumbers } from '@redocly/theme/core/utils';
|
|
8
|
+
import { useModalScrollLock, useReportDialog } from '@redocly/theme/core/hooks';
|
|
9
9
|
import { ReportDialog } from '@redocly/theme/components/Feedback/ReportDialog';
|
|
10
10
|
import { CodeBlockContainer } from '@redocly/theme/components/CodeBlock/CodeBlockContainer';
|
|
11
11
|
import { CodeBlockControls } from '@redocly/theme/components/CodeBlock/CodeBlockControls';
|
|
@@ -68,16 +68,8 @@ export function CodeBlock({
|
|
|
68
68
|
const [sourceCode, setSourceCode] = useState<string>(
|
|
69
69
|
(source || externalSource?.sample?.get?.(externalSource)) ?? '',
|
|
70
70
|
);
|
|
71
|
-
const { useCodeHighlight } = useThemeHooks();
|
|
72
|
-
const { highlight } = useCodeHighlight() || {};
|
|
73
71
|
|
|
74
|
-
const highlightedCode = highlightedHtml
|
|
75
|
-
? withLineNumbers
|
|
76
|
-
? addLineNumbers(highlightedHtml, startLineNumber)
|
|
77
|
-
: highlightedHtml
|
|
78
|
-
: children
|
|
79
|
-
? null
|
|
80
|
-
: highlight?.(sourceCode, lang, { withLineNumbers, startLineNumber });
|
|
72
|
+
const highlightedCode = highlightedHtml || (children ? null : highlight(sourceCode, lang));
|
|
81
73
|
|
|
82
74
|
// The same initial value should be returned for ssr and frontend to avoid issues
|
|
83
75
|
// Because we don't have session storage in ssr and can't get the security details there
|
|
@@ -110,11 +102,13 @@ export function CodeBlock({
|
|
|
110
102
|
/>
|
|
111
103
|
<CodeBlockContainer
|
|
112
104
|
ref={codeBlockRef}
|
|
113
|
-
|
|
105
|
+
className={withLineNumbers ? 'line-numbers' : ''}
|
|
114
106
|
dangerouslySetInnerHTML={
|
|
115
107
|
highlightedCode
|
|
116
108
|
? {
|
|
117
|
-
__html:
|
|
109
|
+
__html: withLineNumbers
|
|
110
|
+
? addLineNumbers(highlightedCode, startLineNumber)
|
|
111
|
+
: highlightedCode,
|
|
118
112
|
}
|
|
119
113
|
: undefined
|
|
120
114
|
}
|
|
@@ -8,7 +8,7 @@ export type CodeBlockContainerProps = PropsWithChildren<{
|
|
|
8
8
|
maxHeight?: string;
|
|
9
9
|
wrapContents?: boolean;
|
|
10
10
|
ref?: (instance: HTMLPreElement | null) => void;
|
|
11
|
-
|
|
11
|
+
className?: string;
|
|
12
12
|
dangerouslySetInnerHTML?: {
|
|
13
13
|
__html: string;
|
|
14
14
|
};
|
|
@@ -117,244 +117,30 @@ const CodeBlockContainerComponent = styled.pre<CodeBlockContainerProps>`
|
|
|
117
117
|
cursor: help;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
.line
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
.code-line {
|
|
121
|
+
&:before {
|
|
122
|
+
content: attr(data-line-number);
|
|
123
|
+
display: inline-block;
|
|
124
|
+
min-width: 2em;
|
|
125
|
+
padding-right: 0.8em;
|
|
126
|
+
text-align: right;
|
|
127
|
+
pointer-events: none;
|
|
128
|
+
user-select: none;
|
|
129
|
+
}
|
|
127
130
|
}
|
|
128
131
|
|
|
129
132
|
.highlighted {
|
|
130
133
|
background: var(--tag-basic-bg-color);
|
|
131
134
|
}
|
|
132
135
|
|
|
133
|
-
/*
|
|
134
|
-
* Shiki styles
|
|
135
|
-
*/
|
|
136
|
-
|
|
137
|
-
.line {
|
|
138
|
-
display: block;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
.has-diff {
|
|
142
|
-
> .line {
|
|
143
|
-
&:before {
|
|
144
|
-
content: ' ';
|
|
145
|
-
display: inline-block;
|
|
146
|
-
min-width: 1em;
|
|
147
|
-
padding-right: 0.4em;
|
|
148
|
-
text-align: right;
|
|
149
|
-
pointer-events: none;
|
|
150
|
-
user-select: none;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.diff {
|
|
156
|
-
&.add {
|
|
157
|
-
background: var(--color-grass-2);
|
|
158
|
-
&:before {
|
|
159
|
-
content: '+';
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
&.remove {
|
|
163
|
-
background: var(--color-red-2);
|
|
164
|
-
|
|
165
|
-
&:before {
|
|
166
|
-
content: '-';
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
.highlighted-word {
|
|
172
|
-
background: var(--color-carrot-2);
|
|
173
|
-
border: 1px solid var(--color-carrot-5);
|
|
174
|
-
border-radius: 4px;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.has-focused {
|
|
178
|
-
.line {
|
|
179
|
-
opacity: 0.7;
|
|
180
|
-
filter: blur(0.095rem);
|
|
181
|
-
transition:
|
|
182
|
-
filter 0.35s,
|
|
183
|
-
opacity 0.35s;
|
|
184
|
-
&.focused {
|
|
185
|
-
opacity: 1;
|
|
186
|
-
filter: blur(0);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
&:hover {
|
|
191
|
-
.line {
|
|
192
|
-
opacity: 1;
|
|
193
|
-
filter: blur(0);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/*
|
|
199
|
-
* Tree view styles
|
|
200
|
-
*/
|
|
201
|
-
|
|
202
|
-
.tree-view-line {
|
|
203
|
-
display: flex;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
.tree-view-branch {
|
|
207
|
-
color: var(--code-block-tree-view-lines-color);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
.tree-view-file {
|
|
211
|
-
display: inline-flex;
|
|
212
|
-
&::before {
|
|
213
|
-
content: '\\ea01';
|
|
214
|
-
margin-right: 0.5rem;
|
|
215
|
-
font-family: 'TreeViewIcons';
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
&.no-file {
|
|
219
|
-
&::before {
|
|
220
|
-
content: '';
|
|
221
|
-
margin-right: 0;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
&.ext-folder {
|
|
226
|
-
&::before {
|
|
227
|
-
content: '\\ea02';
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
&.ext-img,
|
|
232
|
-
&.ext-png,
|
|
233
|
-
&.ext-jpg,
|
|
234
|
-
&.ext-jpeg,
|
|
235
|
-
&.ext-gif,
|
|
236
|
-
&.ext-svg {
|
|
237
|
-
&::before {
|
|
238
|
-
content: '\\ea03';
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
&.ext-mp2,
|
|
243
|
-
&.ext-mp3,
|
|
244
|
-
&.ext-wav,
|
|
245
|
-
&.ext-ogg,
|
|
246
|
-
&.ext-flac {
|
|
247
|
-
&::before {
|
|
248
|
-
content: '\\ea04';
|
|
249
|
-
margin-right: 0.5rem;
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
&.ext-mp4,
|
|
254
|
-
&.ext-mkv,
|
|
255
|
-
&.ext-avi,
|
|
256
|
-
&.ext-mov,
|
|
257
|
-
&.ext-wmv,
|
|
258
|
-
&.ext-flv {
|
|
259
|
-
&::before {
|
|
260
|
-
content: '\\ea05';
|
|
261
|
-
margin-right: 0.5rem;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
&.ext-txt,
|
|
266
|
-
&.ext-text,
|
|
267
|
-
&.ext-md,
|
|
268
|
-
&.ext-markdown {
|
|
269
|
-
&::before {
|
|
270
|
-
content: '\\ea06';
|
|
271
|
-
margin-right: 0.5rem;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
&.ext-js,
|
|
276
|
-
&.ext-ts,
|
|
277
|
-
&.ext-jsx,
|
|
278
|
-
&.ext-tsx,
|
|
279
|
-
&.ext-json,
|
|
280
|
-
&.ext-yaml,
|
|
281
|
-
&.ext-yml,
|
|
282
|
-
&.ext-xml,
|
|
283
|
-
&.ext-html,
|
|
284
|
-
&.ext-css,
|
|
285
|
-
&.ext-scss,
|
|
286
|
-
&.ext-less,
|
|
287
|
-
&.ext-sass,
|
|
288
|
-
&.ext-java,
|
|
289
|
-
&.ext-c,
|
|
290
|
-
&.ext-cpp,
|
|
291
|
-
&.ext-cs,
|
|
292
|
-
&.ext-php,
|
|
293
|
-
&.ext-py,
|
|
294
|
-
&.ext-rb,
|
|
295
|
-
&.ext-go,
|
|
296
|
-
&.ext-swift,
|
|
297
|
-
&.ext-sql,
|
|
298
|
-
&.ext-perl,
|
|
299
|
-
&.ext-lua,
|
|
300
|
-
&.ext-scala,
|
|
301
|
-
&.ext-sh {
|
|
302
|
-
&::before {
|
|
303
|
-
content: '\\ea07';
|
|
304
|
-
margin-right: 0.5rem;
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
&.ext-zip,
|
|
309
|
-
&.ext-rar,
|
|
310
|
-
&.ext-tar,
|
|
311
|
-
&.ext-gz,
|
|
312
|
-
&.ext-iso {
|
|
313
|
-
&::before {
|
|
314
|
-
content: '\\ea08';
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
&.ext-pdf,
|
|
319
|
-
&.ext-PDF {
|
|
320
|
-
&::before {
|
|
321
|
-
content: '\\ea09';
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
&.ext-excel,
|
|
326
|
-
&.ext-xls,
|
|
327
|
-
&.ext-xlsx {
|
|
328
|
-
&::before {
|
|
329
|
-
content: '\\ea0a';
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
&.ext-powerpoint,
|
|
334
|
-
&.ext-ppt,
|
|
335
|
-
&.ext-pptx {
|
|
336
|
-
&::before {
|
|
337
|
-
content: '\\ea0b';
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
&.ext-doc,
|
|
342
|
-
&.ext-docx,
|
|
343
|
-
&.ext-rtf {
|
|
344
|
-
&::before {
|
|
345
|
-
content: '\\ea0c';
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
136
|
${generateCodeBlockTokens()}
|
|
351
137
|
|
|
352
138
|
${({ hideCodeColors }) =>
|
|
353
139
|
hideCodeColors &&
|
|
354
140
|
css`
|
|
355
|
-
.line
|
|
356
|
-
.line
|
|
357
|
-
.line
|
|
141
|
+
.code-line:not(.highlighted),
|
|
142
|
+
.code-line:not(.highlighted) > span,
|
|
143
|
+
.code-line:not(.highlighted) > span > span {
|
|
358
144
|
color: grey;
|
|
359
145
|
}
|
|
360
146
|
`}
|
|
@@ -1,30 +1,6 @@
|
|
|
1
1
|
import { css } from 'styled-components';
|
|
2
2
|
|
|
3
3
|
export const code = css`
|
|
4
|
-
/**
|
|
5
|
-
* Tree view icons font
|
|
6
|
-
*/
|
|
7
|
-
@font-face {
|
|
8
|
-
font-family: 'TreeViewIcons';
|
|
9
|
-
/**
|
|
10
|
-
* Use the following escape sequences to refer to a specific icon:
|
|
11
|
-
*
|
|
12
|
-
* - \\ea01 file
|
|
13
|
-
* - \\ea02 folder
|
|
14
|
-
* - \\ea03 image
|
|
15
|
-
* - \\ea04 audio
|
|
16
|
-
* - \\ea05 video
|
|
17
|
-
* - \\ea06 text
|
|
18
|
-
* - \\ea07 code
|
|
19
|
-
* - \\ea08 archive
|
|
20
|
-
* - \\ea09 pdf
|
|
21
|
-
* - \\ea0a excel
|
|
22
|
-
* - \\ea0b powerpoint
|
|
23
|
-
* - \\ea0c word
|
|
24
|
-
*/
|
|
25
|
-
src: url('data:application/font-woff;base64,d09GRgABAAAAAAgYAAsAAAAAEGAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADsAAABUIIslek9TLzIAAAFEAAAAPwAAAFY1UkH9Y21hcAAAAYQAAAB/AAACCtvO7yxnbHlmAAACBAAAA+MAAAlACm1VqmhlYWQAAAXoAAAAKgAAADZfxj5jaGhlYQAABhQAAAAYAAAAJAFbAMFobXR4AAAGLAAAAA4AAAA0CGQAAGxvY2EAAAY8AAAAHAAAABwM9A9CbWF4cAAABlgAAAAfAAAAIAEgAHZuYW1lAAAGeAAAATcAAAJSfUrk+HBvc3QAAAewAAAAZgAAAIka0DSfeJxjYGRgYOBiMGCwY2BycfMJYeDLSSzJY5BiYGGAAJA8MpsxJzM9kYEDxgPKsYBpDiBmg4gCACY7BUgAeJxjYGRYyjiBgZWBgaGQoRZISkLpUAYOBj0GBiYGVmYGrCAgzTWFweEV4ysehs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GDAigDFhxgVXLLjhjhUPCtmKTtmLaGN7x6dy/Io5bybqoevRQ3LRObb0sk3HKpn1SFqW6ru26vbpYfcmRCccJhqsAAA=') format('woff');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
4
|
/**
|
|
29
5
|
* @tokens Code base styles
|
|
30
6
|
*/
|
|
@@ -112,11 +88,5 @@ export const code = css`
|
|
|
112
88
|
--code-block-tokens-class-name-color: var(--color-carrot-7); // @presenter Color
|
|
113
89
|
--code-block-tokens-function-color: var(--color-carrot-7); // @presenter Color
|
|
114
90
|
|
|
115
|
-
/**
|
|
116
|
-
* @tokens Code Block tree view
|
|
117
|
-
*/
|
|
118
|
-
--code-block-tree-view-icon-font-family: 'TreeViewIcons'; // @presenter FontFamily
|
|
119
|
-
--code-block-tree-view-lines-color: var(--border-color-primary); // @presenter Color
|
|
120
|
-
|
|
121
91
|
// @tokens End
|
|
122
92
|
`;
|
|
@@ -8,6 +8,7 @@ import { FilterInput } from '@redocly/theme/components/Filter/FilterInput';
|
|
|
8
8
|
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
9
9
|
import { Button } from '@redocly/theme/components/Button/Button';
|
|
10
10
|
import { Filter } from '@redocly/theme/components/Filter/Filter';
|
|
11
|
+
import { isFromToSelectedOptions } from '@redocly/theme/core/utils';
|
|
11
12
|
|
|
12
13
|
export type FilterContentProps = {
|
|
13
14
|
setFilterTerm: (value: string) => void;
|
|
@@ -29,7 +30,11 @@ export function FilterContent({
|
|
|
29
30
|
if (filterTerm) return true;
|
|
30
31
|
if (filter.selectedOptions && filter.selectedOptions instanceof Set) {
|
|
31
32
|
return filter.selectedOptions.size;
|
|
32
|
-
} else if (
|
|
33
|
+
} else if (
|
|
34
|
+
isFromToSelectedOptions(filter.selectedOptions) &&
|
|
35
|
+
filter.selectedOptions.from &&
|
|
36
|
+
filter.selectedOptions.to
|
|
37
|
+
) {
|
|
33
38
|
return true;
|
|
34
39
|
}
|
|
35
40
|
});
|
|
@@ -4,7 +4,7 @@ import styled from 'styled-components';
|
|
|
4
4
|
import type { ResolvedNavItem } from '@redocly/config';
|
|
5
5
|
|
|
6
6
|
import { FooterItem } from '@redocly/theme/components/Footer/FooterItem';
|
|
7
|
-
import { breakpoints } from '@redocly/theme/core/utils';
|
|
7
|
+
import { breakpoints, isNavLinkItem } from '@redocly/theme/core/utils';
|
|
8
8
|
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
9
9
|
import { Link } from '@redocly/theme/components/Link/Link';
|
|
10
10
|
|
|
@@ -24,7 +24,7 @@ export function FooterColumn({ column, className }: FooterColumnProps): JSX.Elem
|
|
|
24
24
|
return (
|
|
25
25
|
<FooterColumnWrapper data-component-name="Footer/FooterColumn" className={className}>
|
|
26
26
|
<FooterColumnTitle>
|
|
27
|
-
{column
|
|
27
|
+
{isNavLinkItem(column) ? (
|
|
28
28
|
<Link to={column.link} external={column.external} target={column.target}>
|
|
29
29
|
{label}
|
|
30
30
|
</Link>
|
|
@@ -5,7 +5,7 @@ export const markdown = css`
|
|
|
5
5
|
* @tokens Markdown Content
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
--md-content-max-width:
|
|
8
|
+
--md-content-max-width: 688px;
|
|
9
9
|
--md-content-padding: 25px 0px 25px 0px; // @presenter Spacing
|
|
10
10
|
--md-content-font-size: var(--font-size-base); // @presenter FontSize
|
|
11
11
|
--md-content-font-family: var(--font-family-base); // @presenter FontFamily
|
|
@@ -5,7 +5,7 @@ import type { SearchFacet, SearchFilterItem } from '@redocly/theme/core/types';
|
|
|
5
5
|
|
|
6
6
|
import { Button } from '@redocly/theme/components/Button/Button';
|
|
7
7
|
import { ResetIcon } from '@redocly/theme/icons/ResetIcon/ResetIcon';
|
|
8
|
-
import { useThemeHooks } from '@redocly/theme/core';
|
|
8
|
+
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
9
9
|
import { SearchFilterFieldSelect } from '@redocly/theme/components/Search/FilterFields/SearchFilterFieldSelect';
|
|
10
10
|
import { SearchFilterFieldTags } from '@redocly/theme/components/Search/FilterFields/SearchFilterFieldTags';
|
|
11
11
|
|
|
@@ -2,8 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { useThemeHooks } from '@redocly/theme/core/hooks';
|
|
4
4
|
import { LogoutIcon } from '@redocly/theme/icons/LogoutIcon/LogoutIcon';
|
|
5
|
-
|
|
6
|
-
import { DropdownMenuItem } from '../Dropdown/DropdownMenuItem';
|
|
5
|
+
import { DropdownMenuItem } from '@redocly/theme/components/Dropdown/DropdownMenuItem';
|
|
7
6
|
|
|
8
7
|
export type LogoutMenuItemProps = {
|
|
9
8
|
iconOnly?: boolean;
|
|
@@ -12,7 +12,7 @@ import { UserAvatar } from '@redocly/theme/components/UserMenu/UserAvatar';
|
|
|
12
12
|
import { UserInfoMenuItem } from '@redocly/theme/components/UserMenu/UserInfoMenuItem';
|
|
13
13
|
import { Dropdown } from '@redocly/theme/components/Dropdown/Dropdown';
|
|
14
14
|
import { LogoutMenuItem } from '@redocly/theme/components/UserMenu/LogoutMenuItem';
|
|
15
|
-
import { breakpoints } from '@redocly/theme/core';
|
|
15
|
+
import { breakpoints } from '@redocly/theme/core/utils';
|
|
16
16
|
|
|
17
17
|
export type UserMenuProps = {
|
|
18
18
|
className?: string;
|
package/src/core/types/hooks.ts
CHANGED
|
@@ -109,13 +109,6 @@ export type ThemeHooks = {
|
|
|
109
109
|
useTelemetry: () => { send(action: TelemetryEvent, data: unknown): void };
|
|
110
110
|
useUserTeams: () => string[];
|
|
111
111
|
usePageProps: <T extends Record<string, unknown>>() => PageProps & T;
|
|
112
|
-
useCodeHighlight: () => {
|
|
113
|
-
highlight: (
|
|
114
|
-
code: string,
|
|
115
|
-
language: string | undefined,
|
|
116
|
-
{ withLineNumbers, startLineNumber }: { withLineNumbers?: boolean; startLineNumber?: number },
|
|
117
|
-
) => string;
|
|
118
|
-
};
|
|
119
112
|
};
|
|
120
113
|
|
|
121
114
|
export type L10nConfig = {
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as Prism from 'prismjs';
|
|
2
|
+
import 'prismjs/components/prism-bash.js';
|
|
3
|
+
import 'prismjs/components/prism-c.js';
|
|
4
|
+
import 'prismjs/components/prism-clike.js';
|
|
5
|
+
import 'prismjs/components/prism-coffeescript.js';
|
|
6
|
+
import 'prismjs/components/prism-cpp.js';
|
|
7
|
+
import 'prismjs/components/prism-csharp.js';
|
|
8
|
+
import 'prismjs/components/prism-go.js';
|
|
9
|
+
import 'prismjs/components/prism-http.js';
|
|
10
|
+
import 'prismjs/components/prism-java.js';
|
|
11
|
+
import 'prismjs/components/prism-lua.js';
|
|
12
|
+
import 'prismjs/components/prism-markdown.js';
|
|
13
|
+
import 'prismjs/components/prism-markup-templating.js'; // dep of php
|
|
14
|
+
import 'prismjs/components/prism-markup.js'; // xml
|
|
15
|
+
import 'prismjs/components/prism-objectivec.js';
|
|
16
|
+
import 'prismjs/components/prism-perl.js';
|
|
17
|
+
import 'prismjs/components/prism-php.js';
|
|
18
|
+
import 'prismjs/components/prism-python.js';
|
|
19
|
+
import 'prismjs/components/prism-ruby.js';
|
|
20
|
+
import 'prismjs/components/prism-scala.js';
|
|
21
|
+
import 'prismjs/components/prism-sql.js';
|
|
22
|
+
import 'prismjs/components/prism-swift.js';
|
|
23
|
+
import 'prismjs/components/prism-graphql.js';
|
|
24
|
+
import 'prismjs/plugins/treeview/prism-treeview.js';
|
|
25
|
+
|
|
26
|
+
const DEFAULT_LANG = 'clike';
|
|
27
|
+
const NEW_LINE_EXP = /\n(?!$)/g;
|
|
28
|
+
|
|
29
|
+
Prism.languages.insertBefore(
|
|
30
|
+
'javascript',
|
|
31
|
+
'string',
|
|
32
|
+
{
|
|
33
|
+
'property string': {
|
|
34
|
+
pattern: /([{,]\s*)"(?:\\.|[^\\"\r\n])*"(?=\s*:)/i,
|
|
35
|
+
lookbehind: true,
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
undefined,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
Prism.languages.insertBefore(
|
|
42
|
+
'javascript',
|
|
43
|
+
'punctuation',
|
|
44
|
+
{
|
|
45
|
+
property: {
|
|
46
|
+
pattern: /([{,]\s*)[a-z]\w*(?=\s*:)/i,
|
|
47
|
+
lookbehind: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
undefined,
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
Prism.languages.markdoc = {
|
|
54
|
+
...Prism.languages.markdown,
|
|
55
|
+
tag: {
|
|
56
|
+
pattern: /{%(.|\n)*?%}/i,
|
|
57
|
+
inside: {
|
|
58
|
+
keyword: {
|
|
59
|
+
pattern: /^({%\s*\/?)(\w*|-)*\b/i,
|
|
60
|
+
lookbehind: true,
|
|
61
|
+
},
|
|
62
|
+
id: /#(\w|-)*\b/,
|
|
63
|
+
string: /".*?"/,
|
|
64
|
+
equals: /=/,
|
|
65
|
+
number: /\b\d+\b/i,
|
|
66
|
+
variable: {
|
|
67
|
+
pattern: /\$[\w.]+/i,
|
|
68
|
+
inside: {
|
|
69
|
+
punctuation: /\./i,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
function: /\b\w+(?=\()/,
|
|
73
|
+
punctuation: /({%|\/?%})/i,
|
|
74
|
+
boolean: /false|true/,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
variable: {
|
|
78
|
+
pattern: /\$\w+/i,
|
|
79
|
+
},
|
|
80
|
+
function: {
|
|
81
|
+
pattern: /\b\w+(?=\()/i,
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* map language names to Prism.js names
|
|
87
|
+
*/
|
|
88
|
+
export function mapLang(lang: string): string {
|
|
89
|
+
return (
|
|
90
|
+
{
|
|
91
|
+
json: 'js',
|
|
92
|
+
'c++': 'cpp',
|
|
93
|
+
'c#': 'csharp',
|
|
94
|
+
'c#+newtonsoft': 'csharp',
|
|
95
|
+
'java8+apache': 'java',
|
|
96
|
+
'objective-c': 'objectivec',
|
|
97
|
+
shell: 'bash',
|
|
98
|
+
viml: 'vim',
|
|
99
|
+
curl: 'bash',
|
|
100
|
+
'node.js': 'js',
|
|
101
|
+
}[lang] || DEFAULT_LANG
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Highlight source code string using Prism.js
|
|
107
|
+
* @param source source code to highlight
|
|
108
|
+
* @param lang highlight language
|
|
109
|
+
* @return highlighted source code as **html string**
|
|
110
|
+
*/
|
|
111
|
+
export function highlight(source: string | number | boolean, lang: string = DEFAULT_LANG): string {
|
|
112
|
+
lang = lang.toLowerCase();
|
|
113
|
+
const grammar = Prism.languages[lang] || Prism.languages[mapLang(lang)];
|
|
114
|
+
return Prism.highlight(source.toString(), grammar, lang);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function addLineNumbers(highlightedCode: string, start = 1): string {
|
|
118
|
+
const codeLines = highlightedCode.split(NEW_LINE_EXP);
|
|
119
|
+
|
|
120
|
+
return codeLines
|
|
121
|
+
.map((line, i) => {
|
|
122
|
+
return `<span class="code-line" data-line-number=${start + i}>${line}</span>`;
|
|
123
|
+
})
|
|
124
|
+
.join('\n');
|
|
125
|
+
}
|
package/src/core/utils/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '@redocly/theme/core/utils/clipboard-service';
|
|
2
2
|
export * from '@redocly/theme/core/utils/css-variables';
|
|
3
|
-
export * from '@redocly/theme/core/utils/
|
|
3
|
+
export * from '@redocly/theme/core/utils/highlight';
|
|
4
4
|
export * from '@redocly/theme/core/utils/media-css';
|
|
5
5
|
export * from '@redocly/theme/core/utils/theme-helpers';
|
|
6
6
|
export * from '@redocly/theme/core/utils/class-names';
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ResolvedNavItem, ResolvedNavLinkItem } from '@redocly/config';
|
|
2
|
+
|
|
1
3
|
export function isUndefined<T>(value: T | undefined): value is undefined {
|
|
2
4
|
return value === undefined;
|
|
3
5
|
}
|
|
@@ -17,3 +19,13 @@ export function isNotNull<T>(value: T): value is NonNullable<T> {
|
|
|
17
19
|
export const isObject = (item: unknown): item is object => {
|
|
18
20
|
return isNotNull(item) && typeof item === 'object';
|
|
19
21
|
};
|
|
22
|
+
|
|
23
|
+
export const isNavLinkItem = (item: ResolvedNavItem): item is ResolvedNavLinkItem => {
|
|
24
|
+
return item.link !== undefined;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const isFromToSelectedOptions = (
|
|
28
|
+
options: unknown,
|
|
29
|
+
): options is { from: string; to: string } => {
|
|
30
|
+
return isObject(options) && 'from' in options && 'to' in options;
|
|
31
|
+
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @param highlightedCode - A string with new line breaks; the line numbers will be added before each line.
|
|
3
|
-
* @param start - The number to start the line numbering from; default is 1
|
|
4
|
-
* @returns A string with line numbers added before each line
|
|
5
|
-
*/
|
|
6
|
-
export declare function addLineNumbers(highlightedCode: string, start?: number): string;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addLineNumbers = addLineNumbers;
|
|
4
|
-
const NEW_LINE_EXP = /\n(?!$)/g;
|
|
5
|
-
/**
|
|
6
|
-
* @param highlightedCode - A string with new line breaks; the line numbers will be added before each line.
|
|
7
|
-
* @param start - The number to start the line numbering from; default is 1
|
|
8
|
-
* @returns A string with line numbers added before each line
|
|
9
|
-
*/
|
|
10
|
-
function addLineNumbers(highlightedCode, start = 1) {
|
|
11
|
-
console.log('from addLineNumbers ---> ', highlightedCode);
|
|
12
|
-
const codeLines = highlightedCode.split(NEW_LINE_EXP);
|
|
13
|
-
return codeLines
|
|
14
|
-
.map((line, i) => {
|
|
15
|
-
return `<span class='line-number'>${start + i}</span>${line}`;
|
|
16
|
-
})
|
|
17
|
-
.join('\n');
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=add-line-numbers.js.map
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
const NEW_LINE_EXP = /\n(?!$)/g;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param highlightedCode - A string with new line breaks; the line numbers will be added before each line.
|
|
5
|
-
* @param start - The number to start the line numbering from; default is 1
|
|
6
|
-
* @returns A string with line numbers added before each line
|
|
7
|
-
*/
|
|
8
|
-
export function addLineNumbers(highlightedCode: string, start = 1): string {
|
|
9
|
-
console.log('from addLineNumbers ---> ', highlightedCode);
|
|
10
|
-
const codeLines = highlightedCode.split(NEW_LINE_EXP);
|
|
11
|
-
|
|
12
|
-
return codeLines
|
|
13
|
-
.map((line, i) => {
|
|
14
|
-
return `<span class='line-number'>${start + i}</span>${line}`;
|
|
15
|
-
})
|
|
16
|
-
.join('\n');
|
|
17
|
-
}
|