@redocly/theme 0.45.11 → 0.46.1
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.d.ts +2 -1
- package/lib/components/CodeBlock/CodeBlock.js +33 -9
- package/lib/components/CodeBlock/CodeBlockContainer.d.ts +1 -0
- package/lib/components/CodeBlock/CodeBlockContainer.js +242 -68
- package/lib/components/CodeBlock/variables.js +43 -0
- package/lib/components/Link/Link.js +1 -1
- package/lib/core/hooks/use-theme-config.js +1 -1
- package/lib/core/hooks/use-theme-hooks.js +1 -0
- package/lib/core/types/hooks.d.ts +7 -0
- package/lib/core/utils/add-line-numbers.d.ts +6 -0
- package/lib/core/utils/add-line-numbers.js +18 -0
- package/lib/core/utils/index.d.ts +1 -1
- package/lib/core/utils/index.js +1 -1
- package/lib/markdoc/components/Cards/Card.d.ts +2 -1
- package/lib/markdoc/components/Cards/Card.js +2 -2
- package/lib/markdoc/components/Cards/CardIcon.d.ts +2 -1
- package/lib/markdoc/components/Cards/CardIcon.js +3 -3
- package/lib/markdoc/tags/card.js +5 -0
- package/package.json +2 -4
- package/src/components/CodeBlock/CodeBlock.tsx +21 -7
- package/src/components/CodeBlock/CodeBlockContainer.tsx +243 -68
- package/src/components/CodeBlock/variables.ts +43 -0
- package/src/components/Link/Link.tsx +1 -1
- package/src/core/hooks/use-theme-config.ts +1 -1
- package/src/core/hooks/use-theme-hooks.ts +1 -0
- package/src/core/types/hooks.ts +11 -0
- package/src/core/utils/add-line-numbers.ts +16 -0
- package/src/core/utils/index.ts +1 -1
- package/src/markdoc/components/Cards/Card.tsx +10 -1
- package/src/markdoc/components/Cards/CardIcon.tsx +5 -4
- package/src/markdoc/tags/card.ts +5 -0
- package/lib/core/utils/highlight.d.ts +0 -35
- package/lib/core/utils/highlight.js +0 -129
- package/src/core/utils/highlight.ts +0 -125
|
@@ -16,6 +16,7 @@ export type CodeBlockProps = {
|
|
|
16
16
|
codeBlockMaxHeight?: string;
|
|
17
17
|
hideCodeColors?: boolean;
|
|
18
18
|
wrapContents?: boolean;
|
|
19
|
+
[key: string]: unknown;
|
|
19
20
|
};
|
|
20
21
|
type UnstableExternalCodeSample = {
|
|
21
22
|
lang: string;
|
|
@@ -36,5 +37,5 @@ type ExternalSource = {
|
|
|
36
37
|
properties?: any;
|
|
37
38
|
operation?: any;
|
|
38
39
|
};
|
|
39
|
-
export declare function CodeBlock({ lang, source, externalSource, header, dataTestId, codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, wrapContents, children, }: React.PropsWithChildren<CodeBlockProps>): JSX.Element;
|
|
40
|
+
export declare function CodeBlock({ lang, source, externalSource, header, dataTestId, codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, wrapContents, children, ...rest }: React.PropsWithChildren<CodeBlockProps>): JSX.Element;
|
|
40
41
|
export {};
|
|
@@ -22,6 +22,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
25
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
38
|
};
|
|
@@ -34,10 +45,23 @@ const hooks_1 = require("../../core/hooks");
|
|
|
34
45
|
const ReportDialog_1 = require("../../components/Feedback/ReportDialog");
|
|
35
46
|
const CodeBlockContainer_1 = require("../../components/CodeBlock/CodeBlockContainer");
|
|
36
47
|
const CodeBlockControls_1 = require("../../components/CodeBlock/CodeBlockControls");
|
|
37
|
-
function CodeBlock(
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
const
|
|
48
|
+
function CodeBlock(_a) {
|
|
49
|
+
var _b, _c, _d, _e, _f, _g;
|
|
50
|
+
var { lang, source, externalSource, header, dataTestId = 'source-code', codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, codeBlockMaxHeight, tabs, hideCodeColors, wrapContents = false, children } = _a, rest = __rest(_a, ["lang", "source", "externalSource", "header", "dataTestId", "codeBlockRef", "highlightedHtml", "withLineNumbers", "startLineNumber", "className", "codeBlockMaxHeight", "tabs", "hideCodeColors", "wrapContents", "children"]);
|
|
51
|
+
const [sourceCode, setSourceCode] = (0, react_1.useState)((_d = (source || ((_c = (_b = externalSource === null || externalSource === void 0 ? void 0 : externalSource.sample) === null || _b === void 0 ? void 0 : _b.get) === null || _c === void 0 ? void 0 : _c.call(_b, externalSource)))) !== null && _d !== void 0 ? _d : '');
|
|
52
|
+
const { useCodeHighlight } = (0, hooks_1.useThemeHooks)();
|
|
53
|
+
const { highlight } = useCodeHighlight() || {};
|
|
54
|
+
const highlightedCode = highlightedHtml
|
|
55
|
+
? withLineNumbers
|
|
56
|
+
? (0, utils_1.addLineNumbers)(highlightedHtml, startLineNumber)
|
|
57
|
+
: highlightedHtml
|
|
58
|
+
: children
|
|
59
|
+
? null
|
|
60
|
+
: highlight === null || highlight === void 0 ? void 0 : highlight(sourceCode, lang, {
|
|
61
|
+
withLineNumbers,
|
|
62
|
+
startLineNumber,
|
|
63
|
+
highlight: rest['data-highlight'],
|
|
64
|
+
});
|
|
41
65
|
// The same initial value should be returned for ssr and frontend to avoid issues
|
|
42
66
|
// Because we don't have session storage in ssr and can't get the security details there
|
|
43
67
|
// Issue for more details https://github.com/Redocly/reference-docs/issues/888
|
|
@@ -50,15 +74,13 @@ function CodeBlock({ lang, source, externalSource, header, dataTestId = 'source-
|
|
|
50
74
|
}, [source, externalSource]);
|
|
51
75
|
const { reportDialog, reportButton } = (0, hooks_1.useReportDialog)();
|
|
52
76
|
(0, hooks_1.useModalScrollLock)(Boolean(reportDialog.visible));
|
|
53
|
-
const controls = (header === null || header === void 0 ? void 0 : header.controls) && Object.assign(Object.assign({}, header === null || header === void 0 ? void 0 : header.controls), { report: Object.assign(Object.assign({}, (
|
|
77
|
+
const controls = (header === null || header === void 0 ? void 0 : header.controls) && Object.assign(Object.assign({}, header === null || header === void 0 ? void 0 : header.controls), { report: Object.assign(Object.assign({}, (_e = header === null || header === void 0 ? void 0 : header.controls) === null || _e === void 0 ? void 0 : _e.report), { props: reportButton.props }), copy: ((_f = header === null || header === void 0 ? void 0 : header.controls) === null || _f === void 0 ? void 0 : _f.copy) ? Object.assign(Object.assign({}, (_g = header === null || header === void 0 ? void 0 : header.controls) === null || _g === void 0 ? void 0 : _g.copy), { data: sourceCode }) : undefined });
|
|
54
78
|
return (react_1.default.createElement(CodeBlockWrapper, { "data-component-name": "CodeBlock/CodeBlock", className: className },
|
|
55
79
|
react_1.default.createElement(ContainerWrapper, null,
|
|
56
80
|
react_1.default.createElement(CodeBlockControls_1.CodeBlockControls, { tabs: tabs, className: header === null || header === void 0 ? void 0 : header.className, title: header === null || header === void 0 ? void 0 : header.title, controls: controls }),
|
|
57
|
-
react_1.default.createElement(CodeBlockContainer_1.CodeBlockContainer, { ref: codeBlockRef,
|
|
81
|
+
react_1.default.createElement(CodeBlockContainer_1.CodeBlockContainer, { ref: codeBlockRef, withLineNumbers: withLineNumbers, dangerouslySetInnerHTML: highlightedCode
|
|
58
82
|
? {
|
|
59
|
-
__html:
|
|
60
|
-
? (0, utils_1.addLineNumbers)(highlightedCode, startLineNumber)
|
|
61
|
-
: highlightedCode,
|
|
83
|
+
__html: highlightedCode,
|
|
62
84
|
}
|
|
63
85
|
: undefined, suppressHydrationWarning // TODO: investigate issue
|
|
64
86
|
: true, "data-testid": dataTestId, hideCodeColors: hideCodeColors, maxHeight: codeBlockMaxHeight, wrapContents: wrapContents, tabIndex: 0 }, children),
|
|
@@ -72,5 +94,7 @@ const CodeBlockWrapper = styled_components_1.default.div `
|
|
|
72
94
|
border-radius: var(--border-radius);
|
|
73
95
|
background-color: var(--code-block-bg-color);
|
|
74
96
|
margin: 0 0 var(--spacing-sm);
|
|
97
|
+
|
|
98
|
+
--md-pre-margin: 0;
|
|
75
99
|
`;
|
|
76
100
|
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -52,104 +52,278 @@ const CodeBlockContainerComponent = styled_components_1.default.pre `
|
|
|
52
52
|
font-family: var(--code-block-font-family);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Based on prism-dark.css
|
|
57
|
-
*/
|
|
58
|
-
code[class*='language-'],
|
|
59
|
-
pre[class*='language-'] {
|
|
60
|
-
text-shadow: 0 -0.1em 0.2em black;
|
|
61
|
-
text-align: left;
|
|
62
|
-
word-spacing: normal;
|
|
63
|
-
word-break: normal;
|
|
64
|
-
word-wrap: normal;
|
|
65
|
-
line-height: 1.5;
|
|
66
|
-
|
|
67
|
-
-moz-tab-size: 4;
|
|
68
|
-
-o-tab-size: 4;
|
|
69
|
-
tab-size: 4;
|
|
70
|
-
|
|
71
|
-
-webkit-hyphens: none;
|
|
72
|
-
-moz-hyphens: none;
|
|
73
|
-
-ms-hyphens: none;
|
|
74
|
-
hyphens: none;
|
|
75
|
-
}
|
|
76
55
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
56
|
+
.highlighted {
|
|
57
|
+
background: var(--layer-color-hover);
|
|
58
|
+
margin-left: calc(var(--spacing-sm) * -1);
|
|
59
|
+
padding-left: var(--spacing-sm);
|
|
60
|
+
width: calc(100% + var(--spacing-sm));
|
|
61
|
+
display: inline-block;
|
|
62
|
+
|
|
63
|
+
&.error {
|
|
64
|
+
background: var(--color-raspberry-2);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
&.warning {
|
|
68
|
+
background: var(--color-carrot-2);
|
|
81
69
|
}
|
|
82
70
|
}
|
|
83
71
|
|
|
84
|
-
|
|
72
|
+
[data-line-number] {
|
|
73
|
+
&::before {
|
|
74
|
+
content: attr(data-line-number);
|
|
75
|
+
display: inline-block;
|
|
76
|
+
min-width: 2em;
|
|
77
|
+
padding-right: 0.8em;
|
|
78
|
+
text-align: right;
|
|
79
|
+
pointer-events: none;
|
|
80
|
+
user-select: none;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
85
83
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
84
|
+
.has-diff {
|
|
85
|
+
> .line {
|
|
86
|
+
&::before {
|
|
87
|
+
content: attr(data-line-number) ' ';
|
|
88
|
+
display: inline-block;
|
|
89
|
+
padding-right: 0.4em;
|
|
90
|
+
text-align: right;
|
|
91
|
+
pointer-events: none;
|
|
92
|
+
user-select: none;
|
|
93
|
+
}
|
|
94
|
+
&[data-line-number]::before {
|
|
95
|
+
min-width: 3em;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
90
98
|
}
|
|
91
99
|
|
|
92
|
-
.
|
|
93
|
-
|
|
100
|
+
.diff {
|
|
101
|
+
margin-left: calc(var(--spacing-sm) * -1);
|
|
102
|
+
padding-left: var(--spacing-sm);
|
|
103
|
+
width: calc(100% + var(--spacing-sm));
|
|
104
|
+
display: inline-block;
|
|
105
|
+
|
|
106
|
+
&.add {
|
|
107
|
+
background: var(--color-grass-2);
|
|
108
|
+
&:before {
|
|
109
|
+
content: attr(data-line-number) ' +';
|
|
110
|
+
color: var(--color-grass-7);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
&.remove {
|
|
114
|
+
background: var(--color-raspberry-2);
|
|
115
|
+
|
|
116
|
+
&:before {
|
|
117
|
+
content: attr(data-line-number) ' -';
|
|
118
|
+
color: var(--color-raspberry-7);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
94
121
|
}
|
|
95
122
|
|
|
96
|
-
.
|
|
97
|
-
|
|
123
|
+
.highlighted-word {
|
|
124
|
+
background: var(--color-carrot-2);
|
|
125
|
+
border: 1px solid var(--color-carrot-5);
|
|
126
|
+
border-radius: 4px;
|
|
98
127
|
}
|
|
99
128
|
|
|
100
|
-
.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
129
|
+
.has-focused {
|
|
130
|
+
.line {
|
|
131
|
+
margin-left: calc(var(--spacing-sm) * -1);
|
|
132
|
+
padding-left: var(--spacing-sm);
|
|
133
|
+
width: calc(100% + var(--spacing-sm));
|
|
134
|
+
display: inline-block;
|
|
135
|
+
|
|
136
|
+
opacity: 0.7;
|
|
137
|
+
filter: blur(0.095rem);
|
|
138
|
+
transition:
|
|
139
|
+
filter 0.35s,
|
|
140
|
+
opacity 0.35s;
|
|
141
|
+
&.focused {
|
|
142
|
+
opacity: 1;
|
|
143
|
+
filter: blur(0);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
&:hover {
|
|
148
|
+
.line {
|
|
149
|
+
opacity: 1;
|
|
150
|
+
filter: blur(0);
|
|
151
|
+
}
|
|
110
152
|
}
|
|
111
153
|
}
|
|
112
154
|
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
/*
|
|
156
|
+
* Tree view styles
|
|
157
|
+
*/
|
|
158
|
+
|
|
159
|
+
.shiki {
|
|
160
|
+
&.theme {
|
|
161
|
+
display: inline-block;
|
|
162
|
+
width: 100%;
|
|
163
|
+
|
|
164
|
+
&.tree-view-root {
|
|
165
|
+
display: flex;
|
|
166
|
+
flex-direction: column;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
115
169
|
}
|
|
116
170
|
|
|
117
|
-
.
|
|
118
|
-
|
|
119
|
-
font-weight: bold;
|
|
171
|
+
. .line {
|
|
172
|
+
display: inline-block;
|
|
120
173
|
}
|
|
121
174
|
|
|
122
|
-
.
|
|
123
|
-
|
|
175
|
+
.tree-view-line {
|
|
176
|
+
display: flex;
|
|
124
177
|
}
|
|
125
178
|
|
|
126
|
-
.
|
|
127
|
-
|
|
179
|
+
.tree-view-branch {
|
|
180
|
+
color: var(--code-block-tree-view-lines-color);
|
|
128
181
|
}
|
|
129
182
|
|
|
130
|
-
.
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
pointer-events: none;
|
|
138
|
-
user-select: none;
|
|
183
|
+
.tree-view-file {
|
|
184
|
+
display: inline-flex;
|
|
185
|
+
&::before {
|
|
186
|
+
content: '\\ea01';
|
|
187
|
+
margin-left: 0.3rem;
|
|
188
|
+
margin-right: 0.5rem;
|
|
189
|
+
font-family: 'TreeViewIcons';
|
|
139
190
|
}
|
|
140
|
-
}
|
|
141
191
|
|
|
142
|
-
|
|
143
|
-
|
|
192
|
+
&.no-file {
|
|
193
|
+
&::before {
|
|
194
|
+
content: '';
|
|
195
|
+
margin-right: 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
&.ext-folder {
|
|
200
|
+
&::before {
|
|
201
|
+
content: '\\ea02';
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
&.ext-img,
|
|
206
|
+
&.ext-png,
|
|
207
|
+
&.ext-jpg,
|
|
208
|
+
&.ext-jpeg,
|
|
209
|
+
&.ext-gif,
|
|
210
|
+
&.ext-svg {
|
|
211
|
+
&::before {
|
|
212
|
+
content: '\\ea03';
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
&.ext-mp2,
|
|
217
|
+
&.ext-mp3,
|
|
218
|
+
&.ext-wav,
|
|
219
|
+
&.ext-ogg,
|
|
220
|
+
&.ext-flac {
|
|
221
|
+
&::before {
|
|
222
|
+
content: '\\ea04';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&.ext-mp4,
|
|
227
|
+
&.ext-mkv,
|
|
228
|
+
&.ext-avi,
|
|
229
|
+
&.ext-mov,
|
|
230
|
+
&.ext-wmv,
|
|
231
|
+
&.ext-flv {
|
|
232
|
+
&::before {
|
|
233
|
+
content: '\\ea05';
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
&.ext-txt,
|
|
238
|
+
&.ext-text,
|
|
239
|
+
&.ext-md,
|
|
240
|
+
&.ext-markdown {
|
|
241
|
+
&::before {
|
|
242
|
+
content: '\\ea06';
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
&.ext-js,
|
|
247
|
+
&.ext-ts,
|
|
248
|
+
&.ext-jsx,
|
|
249
|
+
&.ext-tsx,
|
|
250
|
+
&.ext-json,
|
|
251
|
+
&.ext-yaml,
|
|
252
|
+
&.ext-yml,
|
|
253
|
+
&.ext-xml,
|
|
254
|
+
&.ext-html,
|
|
255
|
+
&.ext-css,
|
|
256
|
+
&.ext-scss,
|
|
257
|
+
&.ext-less,
|
|
258
|
+
&.ext-sass,
|
|
259
|
+
&.ext-java,
|
|
260
|
+
&.ext-c,
|
|
261
|
+
&.ext-cpp,
|
|
262
|
+
&.ext-cs,
|
|
263
|
+
&.ext-php,
|
|
264
|
+
&.ext-py,
|
|
265
|
+
&.ext-rb,
|
|
266
|
+
&.ext-go,
|
|
267
|
+
&.ext-swift,
|
|
268
|
+
&.ext-sql,
|
|
269
|
+
&.ext-perl,
|
|
270
|
+
&.ext-lua,
|
|
271
|
+
&.ext-scala,
|
|
272
|
+
&.ext-sh {
|
|
273
|
+
&::before {
|
|
274
|
+
content: '\\ea07';
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
&.ext-zip,
|
|
279
|
+
&.ext-rar,
|
|
280
|
+
&.ext-tar,
|
|
281
|
+
&.ext-gz,
|
|
282
|
+
&.ext-iso {
|
|
283
|
+
&::before {
|
|
284
|
+
content: '\\ea08';
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
&.ext-pdf,
|
|
289
|
+
&.ext-PDF {
|
|
290
|
+
&::before {
|
|
291
|
+
content: '\\ea09';
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
&.ext-excel,
|
|
296
|
+
&.ext-xls,
|
|
297
|
+
&.ext-xlsx {
|
|
298
|
+
&::before {
|
|
299
|
+
content: '\\ea0a';
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
&.ext-powerpoint,
|
|
304
|
+
&.ext-ppt,
|
|
305
|
+
&.ext-pptx {
|
|
306
|
+
&::before {
|
|
307
|
+
content: '\\ea0b';
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
&.ext-doc,
|
|
312
|
+
&.ext-docx,
|
|
313
|
+
&.ext-rtf {
|
|
314
|
+
&::before {
|
|
315
|
+
content: '\\ea0c';
|
|
316
|
+
}
|
|
317
|
+
}
|
|
144
318
|
}
|
|
145
319
|
|
|
146
320
|
${(0, utils_1.generateCodeBlockTokens)()}
|
|
147
321
|
|
|
148
322
|
${({ hideCodeColors }) => hideCodeColors &&
|
|
149
323
|
(0, styled_components_1.css) `
|
|
150
|
-
.
|
|
151
|
-
.
|
|
152
|
-
.
|
|
324
|
+
.line-number:not(.highlighted),
|
|
325
|
+
.line-number:not(.highlighted) > span,
|
|
326
|
+
.line-number:not(.highlighted) > span > span {
|
|
153
327
|
color: grey;
|
|
154
328
|
}
|
|
155
329
|
`}
|
|
@@ -3,6 +3,30 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.code = void 0;
|
|
4
4
|
const styled_components_1 = require("styled-components");
|
|
5
5
|
exports.code = (0, styled_components_1.css) `
|
|
6
|
+
/**
|
|
7
|
+
* Tree view icons font
|
|
8
|
+
*/
|
|
9
|
+
@font-face {
|
|
10
|
+
font-family: 'TreeViewIcons';
|
|
11
|
+
/**
|
|
12
|
+
* Use the following escape sequences to refer to a specific icon:
|
|
13
|
+
*
|
|
14
|
+
* - \\ea01 file
|
|
15
|
+
* - \\ea02 folder
|
|
16
|
+
* - \\ea03 image
|
|
17
|
+
* - \\ea04 audio
|
|
18
|
+
* - \\ea05 video
|
|
19
|
+
* - \\ea06 text
|
|
20
|
+
* - \\ea07 code
|
|
21
|
+
* - \\ea08 archive
|
|
22
|
+
* - \\ea09 pdf
|
|
23
|
+
* - \\ea0a excel
|
|
24
|
+
* - \\ea0b powerpoint
|
|
25
|
+
* - \\ea0c word
|
|
26
|
+
*/
|
|
27
|
+
src: url('data:application/font-woff;base64,d09GRgABAAAAAAgYAAsAAAAAEGAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAADsAAABUIIslek9TLzIAAAFEAAAAPwAAAFY1UkH9Y21hcAAAAYQAAAB/AAACCtvO7yxnbHlmAAACBAAAA+MAAAlACm1VqmhlYWQAAAXoAAAAKgAAADZfxj5jaGhlYQAABhQAAAAYAAAAJAFbAMFobXR4AAAGLAAAAA4AAAA0CGQAAGxvY2EAAAY8AAAAHAAAABwM9A9CbWF4cAAABlgAAAAfAAAAIAEgAHZuYW1lAAAGeAAAATcAAAJSfUrk+HBvc3QAAAewAAAAZgAAAIka0DSfeJxjYGRgYOBiMGCwY2BycfMJYeDLSSzJY5BiYGGAAJA8MpsxJzM9kYEDxgPKsYBpDiBmg4gCACY7BUgAeJxjYGRYyjiBgZWBgaGQoRZISkLpUAYOBj0GBiYGVmYGrCAgzTWFweEV4ysehs1ArgDDFgZGIA3CDAB2tQjAAHic7ZHLEcMwCESfLCz/VEoKSEE5parURxMOC4c0Ec283WGFdABgBXrwCAzam4bOK9KWeefM3Hhmjyn3ed+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28
|
+
}
|
|
29
|
+
|
|
6
30
|
/**
|
|
7
31
|
* @tokens Code base styles
|
|
8
32
|
*/
|
|
@@ -85,10 +109,29 @@ exports.code = (0, styled_components_1.css) `
|
|
|
85
109
|
--code-block-tokens-atrule-color: var(--code-block-tokens-keyword-color); // @presenter Color
|
|
86
110
|
--code-block-tokens-attr-value-color: var(--code-block-tokens-keyword-color); // @presenter Color
|
|
87
111
|
--code-block-tokens-regex-color: var(--color-carrot-7); // @presenter Color
|
|
112
|
+
--code-block-tokens-regex-char-escape-color: var(--color-grass-8); // @presenter Color
|
|
88
113
|
--code-block-tokens-important-color: var(--code-block-tokens-regex-color); // @presenter Color
|
|
89
114
|
--code-block-tokens-deleted-color: var(--color-red-7); // @presenter Color
|
|
90
115
|
--code-block-tokens-class-name-color: var(--color-carrot-7); // @presenter Color
|
|
91
116
|
--code-block-tokens-function-color: var(--color-carrot-7); // @presenter Color
|
|
117
|
+
--code-block-tokens-invalid-color: var(--color-orange-8); // @presenter Color
|
|
118
|
+
--code-block-tokens-message-error-color: var(--code-block-tokens-invalid-color); // @presenter Color
|
|
119
|
+
--code-block-tokens-unmatched-color: var(--code-block-tokens-invalid-color); // @presenter Color
|
|
120
|
+
--code-block-tokens-markup-bg-color: var(--color-grass-1); // @presenter Color
|
|
121
|
+
--code-block-tokens-markup-foreground-color: var(--color-grass-8); // @presenter Color
|
|
122
|
+
--code-block-tokens-markup-changed-color: var(--color-carrot-1); // @presenter Color
|
|
123
|
+
--code-block-tokens-markup-deleted-color: var(--color-magenta-1); // @presenter Color
|
|
124
|
+
--code-block-tokens-markup-quote-color: var(--color-grass-8); // @presenter Color
|
|
125
|
+
--code-block-tokens-markup-ignored-color: var(--color-blue-1); // @presenter Color
|
|
126
|
+
--code-block-tokens-warm-bg-color: var(--color-warm-grey-2); // @presenter Color
|
|
127
|
+
--code-block-tokens-warm-foreground-color: var(--color-warm-grey-8); // @presenter Color
|
|
128
|
+
--code-block-tokens-meta-diff-range-color: var(--color-purple-8); // @presenter Color
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @tokens Code Block tree view
|
|
132
|
+
*/
|
|
133
|
+
--code-block-tree-view-icon-font-family: 'TreeViewIcons'; // @presenter FontFamily
|
|
134
|
+
--code-block-tree-view-lines-color: var(--border-color-primary); // @presenter Color
|
|
92
135
|
|
|
93
136
|
// @tokens End
|
|
94
137
|
`;
|
|
@@ -41,7 +41,7 @@ const react_router_dom_1 = require("react-router-dom");
|
|
|
41
41
|
const contexts_1 = require("../../core/contexts");
|
|
42
42
|
function Link(props) {
|
|
43
43
|
const context = (0, react_1.useContext)(contexts_1.ThemeDataContext);
|
|
44
|
-
if (context) {
|
|
44
|
+
if (context === null || context === void 0 ? void 0 : context.components) {
|
|
45
45
|
const { LinkComponent } = context.components;
|
|
46
46
|
return React.createElement(LinkComponent, Object.assign({}, props));
|
|
47
47
|
}
|
|
@@ -6,7 +6,7 @@ const contexts_1 = require("../../core/contexts");
|
|
|
6
6
|
// TODO: rename and additionally export as alias for backward compatibility
|
|
7
7
|
function useThemeConfig(useProductConfig = true) {
|
|
8
8
|
const context = (0, react_1.useContext)(contexts_1.ThemeDataContext);
|
|
9
|
-
if (!context) {
|
|
9
|
+
if (!(context === null || context === void 0 ? void 0 : context.config)) {
|
|
10
10
|
return {};
|
|
11
11
|
}
|
|
12
12
|
const { config, hooks } = context;
|
|
@@ -10,6 +10,7 @@ const fallbacks = {
|
|
|
10
10
|
useSubmitFeedback: () => ({ submitFeedback: () => { } }),
|
|
11
11
|
useTelemetry: () => ({ telemetry: () => { } }),
|
|
12
12
|
useBreadcrumbs: () => [],
|
|
13
|
+
useCodeHighlight: () => ({ highlight: (rawContent) => rawContent }),
|
|
13
14
|
};
|
|
14
15
|
const useThemeHooks = () => {
|
|
15
16
|
const context = (0, react_1.useContext)(contexts_1.ThemeDataContext);
|
|
@@ -98,6 +98,13 @@ export type ThemeHooks = {
|
|
|
98
98
|
};
|
|
99
99
|
useUserTeams: () => string[];
|
|
100
100
|
usePageProps: <T extends Record<string, unknown>>() => PageProps & T;
|
|
101
|
+
useCodeHighlight: () => {
|
|
102
|
+
highlight: (code: string, language?: string | undefined, highlightOptions?: {
|
|
103
|
+
withLineNumbers?: boolean;
|
|
104
|
+
startLineNumber?: number;
|
|
105
|
+
highlight?: string;
|
|
106
|
+
}) => string;
|
|
107
|
+
};
|
|
101
108
|
};
|
|
102
109
|
export type L10nConfig = {
|
|
103
110
|
currentLocale: string;
|
|
@@ -0,0 +1,6 @@
|
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
const codeLines = highlightedCode.split(NEW_LINE_EXP);
|
|
12
|
+
return codeLines
|
|
13
|
+
.map((line, i) => {
|
|
14
|
+
return `<span class='line' data-line-number='${start + i}'>${line}</span>`;
|
|
15
|
+
})
|
|
16
|
+
.join('\n');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=add-line-numbers.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from '../../core/utils/clipboard-service';
|
|
2
2
|
export * from '../../core/utils/css-variables';
|
|
3
|
-
export * from '../../core/utils/
|
|
3
|
+
export * from '../../core/utils/add-line-numbers';
|
|
4
4
|
export * from '../../core/utils/media-css';
|
|
5
5
|
export * from '../../core/utils/theme-helpers';
|
|
6
6
|
export * from '../../core/utils/class-names';
|
package/lib/core/utils/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("../../core/utils/clipboard-service"), exports);
|
|
18
18
|
__exportStar(require("../../core/utils/css-variables"), exports);
|
|
19
|
-
__exportStar(require("../../core/utils/
|
|
19
|
+
__exportStar(require("../../core/utils/add-line-numbers"), exports);
|
|
20
20
|
__exportStar(require("../../core/utils/media-css"), exports);
|
|
21
21
|
__exportStar(require("../../core/utils/theme-helpers"), exports);
|
|
22
22
|
__exportStar(require("../../core/utils/class-names"), exports);
|
|
@@ -5,6 +5,7 @@ export type CardProps = React.PropsWithChildren<{
|
|
|
5
5
|
icon?: string;
|
|
6
6
|
iconRawContent?: string;
|
|
7
7
|
imagePosition?: 'start' | 'end';
|
|
8
|
+
iconPosition?: 'auto' | 'start' | 'center' | 'end';
|
|
8
9
|
lineClamp?: number;
|
|
9
10
|
layout?: 'horizontal' | 'vertical' | 'combined';
|
|
10
11
|
variant?: 'filled' | 'outlined' | 'elevated' | 'ghost';
|
|
@@ -12,4 +13,4 @@ export type CardProps = React.PropsWithChildren<{
|
|
|
12
13
|
align?: 'start' | 'center' | 'end';
|
|
13
14
|
to?: string;
|
|
14
15
|
}>;
|
|
15
|
-
export declare function Card({ title, image, icon, iconRawContent, imagePosition, layout, variant, lineClamp, iconVariant, align, to, children, }: CardProps): React.JSX.Element;
|
|
16
|
+
export declare function Card({ title, image, icon, iconRawContent, imagePosition, iconPosition, layout, variant, lineClamp, iconVariant, align, to, children, }: CardProps): React.JSX.Element;
|
|
@@ -10,7 +10,7 @@ const ChevronRightIcon_1 = require("../../../icons/ChevronRightIcon/ChevronRight
|
|
|
10
10
|
const CardImage_1 = require("../../../markdoc/components/Cards/CardImage");
|
|
11
11
|
const CardIcon_1 = require("../../../markdoc/components/Cards/CardIcon");
|
|
12
12
|
const Link_1 = require("../../../components/Link/Link");
|
|
13
|
-
function Card({ title, image, icon, iconRawContent, imagePosition = 'start', layout = 'vertical', variant = 'filled', lineClamp, iconVariant, align = 'start', to, children, }) {
|
|
13
|
+
function Card({ title, image, icon, iconRawContent, imagePosition = 'start', iconPosition = 'auto', layout = 'vertical', variant = 'filled', lineClamp, iconVariant, align = 'start', to, children, }) {
|
|
14
14
|
const titleNoSpaces = title.replace(/\s+/g, '-').toLowerCase();
|
|
15
15
|
const cardTitleId = `card-title-${titleNoSpaces}`;
|
|
16
16
|
const justifyContent = align === 'center' ? 'center' : align === 'end' ? 'flex-end' : 'flex-start';
|
|
@@ -21,7 +21,7 @@ function Card({ title, image, icon, iconRawContent, imagePosition = 'start', lay
|
|
|
21
21
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
22
22
|
image ? react_1.default.createElement(CardImage_1.CardImage, { src: image, alt: title, position: imagePosition }) : null,
|
|
23
23
|
react_1.default.createElement(CardContentWrapper, { "$layout": layout, "$alignItems": alignItems, "$textAlign": textAlign, "$hasImage": image !== undefined },
|
|
24
|
-
icon && react_1.default.createElement(CardIcon_1.CardIcon, { variant: iconVariant, src: icon, rawContent: iconRawContent }),
|
|
24
|
+
icon && (react_1.default.createElement(CardIcon_1.CardIcon, { variant: iconVariant, src: icon, rawContent: iconRawContent, position: iconPosition })),
|
|
25
25
|
react_1.default.createElement(ContentWrapper, null,
|
|
26
26
|
react_1.default.createElement(Title, { id: cardTitleId, "$isCardLink": !!to, "$justifyContent": justifyContent },
|
|
27
27
|
title,
|
|
@@ -3,5 +3,6 @@ export type CardIconProps = {
|
|
|
3
3
|
variant?: string;
|
|
4
4
|
src: string;
|
|
5
5
|
rawContent?: string;
|
|
6
|
+
position?: 'auto' | 'start' | 'center' | 'end';
|
|
6
7
|
};
|
|
7
|
-
export declare function CardIcon({ variant, src, rawContent }: CardIconProps): React.JSX.Element;
|
|
8
|
+
export declare function CardIcon({ variant, src, rawContent, position }: CardIconProps): React.JSX.Element;
|