@redocly/theme 0.17.0 → 0.17.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 +29 -1
- package/lib/components/CodeBlock/CodeBlock.js +56 -94
- package/lib/components/CodeBlock/CodeBlockContainer.d.ts +3 -0
- package/lib/components/CodeBlock/CodeBlockContainer.js +120 -0
- package/lib/components/CodeBlock/CodeBlockControlButton.d.ts +5 -0
- package/lib/components/CodeBlock/CodeBlockControlButton.js +63 -0
- package/lib/components/CodeBlock/CodeBlockControls.d.ts +33 -0
- package/lib/components/CodeBlock/CodeBlockControls.js +56 -0
- package/lib/components/CodeBlock/index.d.ts +3 -0
- package/lib/components/CodeBlock/index.js +3 -0
- package/lib/components/CopyButton/CopyButton.d.ts +12 -3
- package/lib/components/CopyButton/CopyButton.js +30 -26
- package/lib/components/CopyButton/index.d.ts +0 -1
- package/lib/components/CopyButton/index.js +0 -1
- package/lib/components/Feedback/useReportDialog.d.ts +12 -6
- package/lib/components/Feedback/useReportDialog.js +13 -5
- package/lib/components/JsonViewer/JsonViewer.d.ts +0 -1
- package/lib/components/JsonViewer/JsonViewer.js +100 -119
- package/lib/components/Markdown/MarkdownWrapper.d.ts +5 -1
- package/lib/components/Markdown/MarkdownWrapper.js +59 -53
- package/lib/components/Menu/MobileMenu.js +2 -2
- package/lib/components/Menu/MobileMenuGroup.js +1 -1
- package/lib/components/Panel/PanelHeader.js +0 -1
- package/lib/components/Tooltip/Tooltip.js +2 -0
- package/lib/components/index.d.ts +0 -3
- package/lib/components/index.js +0 -3
- package/lib/config.d.ts +30 -23
- package/lib/config.js +16 -3
- package/lib/globalStyle.js +50 -7
- package/lib/icons/ArrowIcon/ArrowIcon.d.ts +3 -3
- package/lib/icons/ArrowIcon/ArrowIcon.js +33 -6
- package/lib/icons/CollapseIcon/CollapseIcon.d.ts +7 -0
- package/lib/icons/CollapseIcon/CollapseIcon.js +22 -0
- package/lib/icons/CollapseIcon/index.d.ts +1 -0
- package/lib/{components/SourceCode → icons/CollapseIcon}/index.js +1 -1
- package/lib/icons/CopyIcon/CopyIcon.d.ts +7 -0
- package/lib/icons/CopyIcon/CopyIcon.js +17 -0
- package/lib/icons/CopyIcon/index.d.ts +1 -0
- package/lib/{components/CodeSample → icons/CopyIcon}/index.js +1 -1
- package/lib/icons/DeselectIcon/DeselectIcon.d.ts +7 -0
- package/lib/icons/DeselectIcon/DeselectIcon.js +19 -0
- package/lib/icons/DeselectIcon/index.d.ts +1 -0
- package/lib/{components/SamplesPanelControls → icons/DeselectIcon}/index.js +1 -1
- package/lib/icons/ExpandIcon/ExpandIcon.d.ts +5 -6
- package/lib/icons/ExpandIcon/ExpandIcon.js +10 -19
- package/lib/icons/FileIcon/FileIcon.d.ts +7 -0
- package/lib/icons/FileIcon/FileIcon.js +17 -0
- package/lib/icons/FileIcon/index.d.ts +1 -0
- package/lib/icons/FileIcon/index.js +18 -0
- package/lib/icons/ReportIcon/ReportIcon.d.ts +7 -0
- package/lib/icons/ReportIcon/ReportIcon.js +19 -0
- package/lib/icons/ReportIcon/index.d.ts +1 -0
- package/lib/icons/ReportIcon/index.js +18 -0
- package/lib/icons/SelectIcon/SelectIcon.d.ts +7 -0
- package/lib/icons/SelectIcon/SelectIcon.js +19 -0
- package/lib/icons/SelectIcon/index.d.ts +1 -0
- package/lib/icons/SelectIcon/index.js +18 -0
- package/lib/icons/index.d.ts +7 -1
- package/lib/icons/index.js +7 -1
- package/lib/layouts/Forbidden.js +2 -2
- package/lib/utils/highlight.d.ts +1 -0
- package/lib/utils/highlight.js +1 -0
- package/package.json +1 -1
- package/src/components/CodeBlock/CodeBlock.tsx +100 -0
- package/src/components/CodeBlock/{CodeBlock.ts → CodeBlockContainer.tsx} +23 -6
- package/src/components/CodeBlock/CodeBlockControlButton.tsx +38 -0
- package/src/components/CodeBlock/CodeBlockControls.tsx +182 -0
- package/src/components/CodeBlock/index.ts +3 -0
- package/src/components/CopyButton/CopyButton.tsx +71 -19
- package/src/components/CopyButton/index.ts +0 -1
- package/src/components/Feedback/useReportDialog.ts +24 -14
- package/src/components/JsonViewer/JsonViewer.tsx +112 -142
- package/src/components/Markdown/MarkdownWrapper.tsx +65 -54
- package/src/components/Menu/MobileMenu.tsx +3 -3
- package/src/components/Menu/MobileMenuGroup.tsx +4 -2
- package/src/components/Panel/PanelHeader.ts +0 -1
- package/src/components/Tooltip/Tooltip.tsx +2 -0
- package/src/components/index.ts +0 -3
- package/src/config.ts +18 -7
- package/src/globalStyle.ts +50 -7
- package/src/icons/ArrowIcon/ArrowIcon.tsx +37 -14
- package/src/icons/CollapseIcon/CollapseIcon.tsx +40 -0
- package/src/icons/CollapseIcon/index.tsx +1 -0
- package/src/icons/CopyIcon/CopyIcon.tsx +26 -0
- package/src/icons/CopyIcon/index.ts +1 -0
- package/src/icons/DeselectIcon/DeselectIcon.tsx +28 -0
- package/src/icons/DeselectIcon/index.ts +1 -0
- package/src/icons/ExpandIcon/ExpandIcon.tsx +28 -34
- package/src/icons/FileIcon/FileIcon.tsx +29 -0
- package/src/icons/FileIcon/index.ts +1 -0
- package/src/icons/ReportIcon/ReportIcon.tsx +36 -0
- package/src/icons/ReportIcon/index.ts +1 -0
- package/src/icons/SelectIcon/SelectIcon.tsx +31 -0
- package/src/icons/SelectIcon/index.ts +1 -0
- package/src/icons/index.ts +7 -1
- package/src/layouts/Forbidden.tsx +1 -1
- package/src/utils/highlight.ts +1 -0
- package/lib/components/CodeSample/CodeSample.d.ts +0 -10
- package/lib/components/CodeSample/CodeSample.js +0 -226
- package/lib/components/CodeSample/index.d.ts +0 -1
- package/lib/components/CopyButton/CopyButtonWrapper.d.ts +0 -11
- package/lib/components/CopyButton/CopyButtonWrapper.js +0 -53
- package/lib/components/SamplesPanelControls/SamplesPanelControls.d.ts +0 -4
- package/lib/components/SamplesPanelControls/SamplesPanelControls.js +0 -76
- package/lib/components/SamplesPanelControls/index.d.ts +0 -1
- package/lib/components/SourceCode/SourceCode.d.ts +0 -33
- package/lib/components/SourceCode/SourceCode.js +0 -60
- package/lib/components/SourceCode/index.d.ts +0 -1
- package/src/components/CodeSample/CodeSample.tsx +0 -257
- package/src/components/CodeSample/index.ts +0 -1
- package/src/components/CopyButton/CopyButtonWrapper.tsx +0 -55
- package/src/components/SamplesPanelControls/SamplesPanelControls.ts +0 -76
- package/src/components/SamplesPanelControls/index.ts +0 -1
- package/src/components/SourceCode/SourceCode.tsx +0 -128
- package/src/components/SourceCode/index.ts +0 -1
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { CodeBlockControlsProps } from '../../components/CodeBlock';
|
|
3
|
+
export interface CodeBlockProps {
|
|
4
|
+
lang?: string;
|
|
5
|
+
source?: string;
|
|
6
|
+
externalSource?: ExternalSource;
|
|
7
|
+
header?: CodeBlockControlsProps;
|
|
8
|
+
dataTestId?: string;
|
|
9
|
+
className?: string;
|
|
10
|
+
withLineNumbers?: boolean;
|
|
11
|
+
startLineNumber?: number;
|
|
12
|
+
highlightedHtml?: string;
|
|
13
|
+
codeBlockRef?: (instance: HTMLPreElement | null) => void;
|
|
14
|
+
}
|
|
15
|
+
export interface Sample {
|
|
16
|
+
lang: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
}
|
|
19
|
+
export type UnstableExternalCodeSample = Sample & {
|
|
20
|
+
get: (source: ExternalSource) => string;
|
|
21
|
+
};
|
|
22
|
+
export interface ExternalSource {
|
|
23
|
+
sample: UnstableExternalCodeSample;
|
|
24
|
+
exampleName?: string;
|
|
25
|
+
pathParams?: any;
|
|
26
|
+
properties?: any;
|
|
27
|
+
operation?: any;
|
|
28
|
+
}
|
|
29
|
+
export declare function CodeBlock({ lang, source, externalSource, header, dataTestId, codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, }: CodeBlockProps): JSX.Element;
|
|
@@ -1,104 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.CodeBlock = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
7
31
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
32
|
const utils_1 = require("../../utils");
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
tab-size: 4;
|
|
31
|
-
|
|
32
|
-
-webkit-hyphens: none;
|
|
33
|
-
-moz-hyphens: none;
|
|
34
|
-
-ms-hyphens: none;
|
|
35
|
-
hyphens: none;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@media print {
|
|
39
|
-
code[class*='language-'],
|
|
40
|
-
pre[class*='language-'] {
|
|
41
|
-
text-shadow: none;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/* Code blocks */
|
|
46
|
-
pre[class*='language-'] {
|
|
47
|
-
padding: 1em;
|
|
48
|
-
margin: 0.5em 0;
|
|
49
|
-
overflow: auto;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.token.punctuation {
|
|
53
|
-
opacity: 1;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
.namespace {
|
|
57
|
-
opacity: 0.7;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.token.selector,
|
|
61
|
-
.token.attr-name,
|
|
62
|
-
.token.string,
|
|
63
|
-
.token.char,
|
|
64
|
-
.token.builtin,
|
|
65
|
-
.token.inserted {
|
|
66
|
-
& + a,
|
|
67
|
-
& + a:visited {
|
|
68
|
-
color: var(--code-block-tokens-link-color);
|
|
69
|
-
text-decoration: underline;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.token.property.string {
|
|
74
|
-
color: var(--code-block-tokens-property-string-color);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.token.important,
|
|
78
|
-
.token.bold {
|
|
79
|
-
font-weight: bold;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
.token.italic {
|
|
83
|
-
font-style: italic;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
.token.entity {
|
|
87
|
-
cursor: help;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
.code-line {
|
|
91
|
-
&:before {
|
|
92
|
-
content: attr(data-line-number);
|
|
93
|
-
display: inline-block;
|
|
94
|
-
min-width: 2em;
|
|
95
|
-
padding-right: 0.8em;
|
|
96
|
-
text-align: right;
|
|
97
|
-
pointer-events: none;
|
|
98
|
-
user-select: none;
|
|
33
|
+
const Feedback_1 = require("../../components/Feedback");
|
|
34
|
+
const CodeBlock_1 = require("../../components/CodeBlock");
|
|
35
|
+
function CodeBlock({ lang, source, externalSource, header, dataTestId = 'source-code', codeBlockRef, highlightedHtml, withLineNumbers, startLineNumber, className, }) {
|
|
36
|
+
var _a;
|
|
37
|
+
const [sourceCode, setSourceCode] = (0, react_1.useState)(source !== null && source !== void 0 ? source : '');
|
|
38
|
+
const highlightedCode = highlightedHtml || (0, utils_1.highlight)(sourceCode, lang);
|
|
39
|
+
// The same initial value should be returned for ssr and frontend to avoid issues
|
|
40
|
+
// Because we don't have session storage in ssr and can't get the security details there
|
|
41
|
+
// Issue for more details https://github.com/Redocly/reference-docs/issues/888
|
|
42
|
+
(0, react_1.useEffect)(() => {
|
|
43
|
+
var _a, _b;
|
|
44
|
+
const _source = source || ((_b = (_a = externalSource === null || externalSource === void 0 ? void 0 : externalSource.sample) === null || _a === void 0 ? void 0 : _a.get) === null || _b === void 0 ? void 0 : _b.call(_a, externalSource));
|
|
45
|
+
if (_source) {
|
|
46
|
+
setSourceCode(_source);
|
|
47
|
+
}
|
|
48
|
+
}, [source, externalSource]);
|
|
49
|
+
const { reportDialog, reportButton } = (0, Feedback_1.useReportDialog)();
|
|
50
|
+
const controls = Object.assign(Object.assign({}, header === null || header === void 0 ? void 0 : header.controls), { report: ((_a = header === null || header === void 0 ? void 0 : header.controls) === null || _a === void 0 ? void 0 : _a.report)
|
|
51
|
+
? Object.assign(Object.assign({}, header.controls.report), { props: reportButton.props }) : { props: reportButton.props } });
|
|
52
|
+
if (controls.copy && !controls.copy.handleOutside) {
|
|
53
|
+
controls.copy.data = sourceCode;
|
|
99
54
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
55
|
+
return (react_1.default.createElement(Wrapper, { "data-component-name": "CodeBlock/CodeBlock", className: className },
|
|
56
|
+
react_1.default.createElement(CodeBlock_1.CodeBlockControls, { 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(CodeBlock_1.CodeBlockContainer, { ref: codeBlockRef, className: withLineNumbers ? 'line-numbers' : '', dangerouslySetInnerHTML: {
|
|
58
|
+
__html: withLineNumbers
|
|
59
|
+
? (0, utils_1.addLineNumbers)(highlightedCode, startLineNumber)
|
|
60
|
+
: highlightedCode,
|
|
61
|
+
}, "data-cy": dataTestId, withControls: true }),
|
|
62
|
+
reportDialog.visible && (react_1.default.createElement(Feedback_1.ReportDialog, Object.assign({}, reportDialog.props, { location: sourceCode })))));
|
|
63
|
+
}
|
|
64
|
+
exports.CodeBlock = CodeBlock;
|
|
65
|
+
const Wrapper = styled_components_1.default.div ``;
|
|
104
66
|
//# sourceMappingURL=CodeBlock.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CodeBlockContainer = void 0;
|
|
7
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
exports.CodeBlockContainer = styled_components_1.default.pre.attrs(({ className }) => ({
|
|
10
|
+
'data-component-name': 'CodeBlock/CodeBlockContainer',
|
|
11
|
+
className,
|
|
12
|
+
})) `
|
|
13
|
+
&& {
|
|
14
|
+
overflow-x: auto;
|
|
15
|
+
max-height: var(--code-block-max-height);
|
|
16
|
+
font-family: var(--code-block-font-family);
|
|
17
|
+
line-height: var(--code-line-height);
|
|
18
|
+
padding: var(--code-block-padding);
|
|
19
|
+
margin: var(--code-block-margin);
|
|
20
|
+
border-radius: ${(withControls) => withControls
|
|
21
|
+
? '0 0 var(--code-block-border-radius) var(--code-block-border-radius)'
|
|
22
|
+
: 'var(--code-block-border-radius)'};
|
|
23
|
+
background-color: var(--code-block-background-color);
|
|
24
|
+
color: var(--code-block-text-color);
|
|
25
|
+
font-size: var(--code-font-size);
|
|
26
|
+
white-space: var(--code-wrap, pre);
|
|
27
|
+
max-height: var(--code-block-max-height, 600px);
|
|
28
|
+
word-break: var(--code-block-word-break, initial);
|
|
29
|
+
border: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Based on prism-dark.css
|
|
34
|
+
*/
|
|
35
|
+
code[class*='language-'],
|
|
36
|
+
pre[class*='language-'] {
|
|
37
|
+
text-shadow: 0 -0.1em 0.2em black;
|
|
38
|
+
text-align: left;
|
|
39
|
+
word-spacing: normal;
|
|
40
|
+
word-break: normal;
|
|
41
|
+
word-wrap: normal;
|
|
42
|
+
line-height: 1.5;
|
|
43
|
+
|
|
44
|
+
-moz-tab-size: 4;
|
|
45
|
+
-o-tab-size: 4;
|
|
46
|
+
tab-size: 4;
|
|
47
|
+
|
|
48
|
+
-webkit-hyphens: none;
|
|
49
|
+
-moz-hyphens: none;
|
|
50
|
+
-ms-hyphens: none;
|
|
51
|
+
hyphens: none;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@media print {
|
|
55
|
+
code[class*='language-'],
|
|
56
|
+
pre[class*='language-'] {
|
|
57
|
+
text-shadow: none;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* Code blocks */
|
|
62
|
+
pre[class*='language-'] {
|
|
63
|
+
padding: 1em;
|
|
64
|
+
margin: 0.5em 0;
|
|
65
|
+
overflow: auto;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.token.punctuation {
|
|
69
|
+
opacity: 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.namespace {
|
|
73
|
+
opacity: 0.7;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.token.selector,
|
|
77
|
+
.token.attr-name,
|
|
78
|
+
.token.string,
|
|
79
|
+
.token.char,
|
|
80
|
+
.token.builtin,
|
|
81
|
+
.token.inserted {
|
|
82
|
+
& + a,
|
|
83
|
+
& + a:visited {
|
|
84
|
+
color: var(--code-block-tokens-link-color);
|
|
85
|
+
text-decoration: underline;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.token.property.string {
|
|
90
|
+
color: var(--code-block-tokens-property-string-color);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.token.important,
|
|
94
|
+
.token.bold {
|
|
95
|
+
font-weight: bold;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.token.italic {
|
|
99
|
+
font-style: italic;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.token.entity {
|
|
103
|
+
cursor: help;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.code-line {
|
|
107
|
+
&:before {
|
|
108
|
+
content: attr(data-line-number);
|
|
109
|
+
display: inline-block;
|
|
110
|
+
min-width: 2em;
|
|
111
|
+
padding-right: 0.8em;
|
|
112
|
+
text-align: right;
|
|
113
|
+
pointer-events: none;
|
|
114
|
+
user-select: none;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
${(0, utils_1.generateCodeBlockTokens)()}
|
|
119
|
+
`;
|
|
120
|
+
//# sourceMappingURL=CodeBlockContainer.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CodeBlockControlButton = void 0;
|
|
27
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
28
|
+
exports.CodeBlockControlButton = styled_components_1.default.button.attrs(() => ({
|
|
29
|
+
'data-component-name': 'CodeBlockControls/CodeBlockControlButton',
|
|
30
|
+
})) `
|
|
31
|
+
border: 0;
|
|
32
|
+
outline: 0;
|
|
33
|
+
border-radius: var(--border-radius);
|
|
34
|
+
height: 20px;
|
|
35
|
+
font-size: 12px;
|
|
36
|
+
line-height: 12px;
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
padding: 1px 6px;
|
|
39
|
+
color: var(--panel-samples-controls-text-color);
|
|
40
|
+
|
|
41
|
+
${({ asIcon }) => asIcon
|
|
42
|
+
? (0, styled_components_1.css) `
|
|
43
|
+
background-color: var(--panel-samples-icon-controls-background-color);
|
|
44
|
+
`
|
|
45
|
+
: (0, styled_components_1.css) `
|
|
46
|
+
min-width: 90px;
|
|
47
|
+
background-color: var(--panel-samples-text-controls-background-color);
|
|
48
|
+
`}
|
|
49
|
+
|
|
50
|
+
${({ theme }) => { var _a; return (_a = theme.mediaQueries) === null || _a === void 0 ? void 0 : _a.small; }} {
|
|
51
|
+
padding: ${({ asIcon }) => (asIcon ? '2px 10px' : '2px 20px')};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
:not(:first-child) {
|
|
55
|
+
margin-left: 5px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
:hover,
|
|
59
|
+
:focus {
|
|
60
|
+
background-color: var(--panel-samples-controls-hover-background-color);
|
|
61
|
+
}
|
|
62
|
+
`;
|
|
63
|
+
//# sourceMappingURL=CodeBlockControlButton.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface CodeBlockControlsProps {
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
className?: string;
|
|
5
|
+
title?: React.ReactNode | string;
|
|
6
|
+
controls?: ControlItems;
|
|
7
|
+
}
|
|
8
|
+
interface ControlItems {
|
|
9
|
+
copy?: CopyControlProps;
|
|
10
|
+
expand?: ControlProps;
|
|
11
|
+
collapse?: ControlProps;
|
|
12
|
+
report?: ControlProps;
|
|
13
|
+
select?: ControlProps;
|
|
14
|
+
deselect?: ControlProps;
|
|
15
|
+
}
|
|
16
|
+
interface ControlProps {
|
|
17
|
+
label?: string;
|
|
18
|
+
tooltipText?: string;
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
props?: Record<string, any>;
|
|
21
|
+
}
|
|
22
|
+
interface CopyControlProps extends ControlProps {
|
|
23
|
+
data?: string;
|
|
24
|
+
dataSource?: string;
|
|
25
|
+
dataHash?: string;
|
|
26
|
+
toasterPlacement?: 'left' | 'right' | 'top' | 'bottom';
|
|
27
|
+
toasterText?: string;
|
|
28
|
+
toasterDuration?: number;
|
|
29
|
+
handleOutside?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export type ControlItemType = 'text' | 'icon';
|
|
32
|
+
export declare function CodeBlockControls({ children, className, title, controls, }: CodeBlockControlsProps): JSX.Element | null;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CodeBlockControls = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
const CodeBlock_1 = require("../../components/CodeBlock");
|
|
10
|
+
const icons_1 = require("../../icons");
|
|
11
|
+
const hooks_1 = require("../../hooks");
|
|
12
|
+
const CopyButton_1 = require("../CopyButton");
|
|
13
|
+
function CodeBlockControls({ children, className, title, controls, }) {
|
|
14
|
+
var _a, _b, _c, _d, _e;
|
|
15
|
+
const { codeSnippet } = (0, hooks_1.useThemeConfig)();
|
|
16
|
+
const controlsType = (codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.controlsStyle) || 'icon';
|
|
17
|
+
const { copy, expand, collapse, select, deselect, report } = controls
|
|
18
|
+
? controls
|
|
19
|
+
: { copy: null, expand: null, collapse: null, select: null, deselect: null, report: null };
|
|
20
|
+
const defaultControls = controls ? (react_1.default.createElement(react_1.default.Fragment, null,
|
|
21
|
+
react_1.default.createElement(Title, null, title),
|
|
22
|
+
react_1.default.createElement(ControlsWrapper, null,
|
|
23
|
+
copy && !((_a = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.copy) === null || _a === void 0 ? void 0 : _a.hide) ? (react_1.default.createElement(CopyButton_1.CopyButton, { data: copy.data, "data-source": copy.dataSource, "data-hash": copy.dataHash, type: controlsType, toasterPlacement: copy.toasterPlacement, toasterDuration: copy.toasterDuration, buttonText: copy.label, tooltipText: copy.tooltipText, onCopyClick: copy === null || copy === void 0 ? void 0 : copy.onClick })) : null,
|
|
24
|
+
expand && !((_b = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.expand) === null || _b === void 0 ? void 0 : _b.hide) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "expand-all", "data-testid": "expand-all", asIcon: controlsType === 'icon', onClick: expand === null || expand === void 0 ? void 0 : expand.onClick, title: (expand === null || expand === void 0 ? void 0 : expand.tooltipText) || 'Expand all' }, controlsType === 'icon' ? react_1.default.createElement(icons_1.ExpandIcon, null) : (expand === null || expand === void 0 ? void 0 : expand.label) ? expand.label : 'Expand all')) : null,
|
|
25
|
+
collapse && !((_c = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.collapse) === null || _c === void 0 ? void 0 : _c.hide) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "collapse-all", "data-testid": "collapse-all", asIcon: controlsType === 'icon', onClick: collapse === null || collapse === void 0 ? void 0 : collapse.onClick, title: (collapse === null || collapse === void 0 ? void 0 : collapse.tooltipText) || 'Collapse all' }, controlsType === 'icon' ? (react_1.default.createElement(icons_1.CollapseIcon, null)) : (collapse === null || collapse === void 0 ? void 0 : collapse.label) ? (collapse.label) : ('Collapse all'))) : null,
|
|
26
|
+
select ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "select-all", "data-testid": "select-all", asIcon: controlsType === 'icon', onClick: select === null || select === void 0 ? void 0 : select.onClick, title: select === null || select === void 0 ? void 0 : select.tooltipText }, controlsType === 'icon' ? react_1.default.createElement(icons_1.SelectIcon, null) : (select === null || select === void 0 ? void 0 : select.label) ? select.label : 'Select all')) : null,
|
|
27
|
+
deselect ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "clear-all", "data-testid": "clear-all", asIcon: controlsType === 'icon', onClick: deselect === null || deselect === void 0 ? void 0 : deselect.onClick, title: deselect === null || deselect === void 0 ? void 0 : deselect.tooltipText }, controlsType === 'icon' ? (react_1.default.createElement(icons_1.DeselectIcon, null)) : (deselect === null || deselect === void 0 ? void 0 : deselect.label) ? (deselect.label) : ('Clear all'))) : null,
|
|
28
|
+
report && ((_d = report === null || report === void 0 ? void 0 : report.props) === null || _d === void 0 ? void 0 : _d.visible) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, Object.assign({ "data-cy": "report-button", "data-testid": "report-button", asIcon: controlsType === 'icon', title: report.tooltipText }, report.props), controlsType === 'icon' ? react_1.default.createElement(icons_1.ReportIcon, null) : ((_e = report.props) === null || _e === void 0 ? void 0 : _e.buttonText) || 'Report')) : null))) : null;
|
|
29
|
+
return children || controls ? (react_1.default.createElement(ContainerWraper, { "data-component-name": "CodeBlock/CodeBlockControls", className: className }, children ? children : defaultControls)) : null;
|
|
30
|
+
}
|
|
31
|
+
exports.CodeBlockControls = CodeBlockControls;
|
|
32
|
+
const ContainerWraper = styled_components_1.default.div `
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: space-between;
|
|
35
|
+
padding: 5px 10px;
|
|
36
|
+
min-height: 30px;
|
|
37
|
+
background-color: var(--panel-samples-controls-background-color);
|
|
38
|
+
border-bottom: var(--panel-samples-controls-border);
|
|
39
|
+
border-radius: var(--border-radius) var(--border-radius) 0 0;
|
|
40
|
+
margin-top: 10px;
|
|
41
|
+
`;
|
|
42
|
+
const Title = styled_components_1.default.span `
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
color: var(--panel-samples-controls-text-color);
|
|
46
|
+
`;
|
|
47
|
+
const ControlsWrapper = styled_components_1.default.div `
|
|
48
|
+
opacity: 0.7;
|
|
49
|
+
transition: opacity 0.3s ease;
|
|
50
|
+
text-align: right;
|
|
51
|
+
|
|
52
|
+
&:focus-within {
|
|
53
|
+
opacity: 1;
|
|
54
|
+
}
|
|
55
|
+
`;
|
|
56
|
+
//# sourceMappingURL=CodeBlockControls.js.map
|
|
@@ -15,4 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("../../components/CodeBlock/CodeBlock"), exports);
|
|
18
|
+
__exportStar(require("../../components/CodeBlock/CodeBlockContainer"), exports);
|
|
19
|
+
__exportStar(require("../../components/CodeBlock/CodeBlockControls"), exports);
|
|
20
|
+
__exportStar(require("../../components/CodeBlock/CodeBlockControlButton"), exports);
|
|
18
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ControlItemType } from '../../components/CodeBlock';
|
|
3
|
+
import type { TooltipProps } from '../../components/Tooltip';
|
|
2
4
|
export interface CopyButtonProps {
|
|
3
|
-
|
|
5
|
+
data: unknown;
|
|
6
|
+
type?: ControlItemType;
|
|
7
|
+
toasterPlacement?: TooltipProps['placement'];
|
|
8
|
+
toasterText?: TooltipProps['tip'];
|
|
9
|
+
toasterDuration?: number;
|
|
10
|
+
buttonText?: string;
|
|
11
|
+
tooltipText?: string;
|
|
12
|
+
onCopyClick?: () => void;
|
|
4
13
|
dataTestId?: string;
|
|
5
14
|
}
|
|
6
|
-
export declare const CopyButton:
|
|
15
|
+
export declare const CopyButton: React.NamedExoticComponent<CopyButtonProps>;
|
|
@@ -22,33 +22,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
26
|
exports.CopyButton = void 0;
|
|
39
27
|
const react_1 = __importStar(require("react"));
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
28
|
+
const CodeBlock_1 = require("../../components/CodeBlock");
|
|
29
|
+
const Tooltip_1 = require("../../components/Tooltip");
|
|
30
|
+
const hooks_1 = require("../../hooks");
|
|
31
|
+
const utils_1 = require("../../utils");
|
|
32
|
+
const icons_1 = require("../../icons");
|
|
33
|
+
const hooks_2 = require("../../mocks/hooks");
|
|
34
|
+
function CopyButtonComponent({ data, type = 'icon', toasterPlacement = 'top', toasterText, toasterDuration, buttonText, tooltipText, onCopyClick, dataTestId = 'copy-button', }) {
|
|
35
|
+
const tooltip = (0, hooks_1.useControl)();
|
|
36
|
+
const { translate } = (0, hooks_2.useTranslate)();
|
|
37
|
+
const translationKeys = {
|
|
38
|
+
buttonText: 'theme.codeSnippet.copy.buttonText',
|
|
39
|
+
tooltipText: 'theme.codeSnippet.copy.tooltipText',
|
|
40
|
+
toasterText: 'theme.codeSnippet.copy.toasterText',
|
|
41
|
+
};
|
|
42
|
+
const showTooltip = (duration = 1500) => {
|
|
43
|
+
tooltip.handleOpen();
|
|
44
|
+
setTimeout(() => {
|
|
45
|
+
tooltip.handleClose();
|
|
46
|
+
}, duration);
|
|
47
|
+
};
|
|
48
|
+
const copy = (duration) => {
|
|
49
|
+
const content = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
50
|
+
utils_1.ClipboardService.copyCustom(content);
|
|
51
|
+
showTooltip(duration);
|
|
52
|
+
onCopyClick === null || onCopyClick === void 0 ? void 0 : onCopyClick();
|
|
53
|
+
};
|
|
54
|
+
return (react_1.default.createElement(Tooltip_1.Tooltip, { className: "copy-button", tip: translate(translationKeys.toasterText, toasterText || 'Copied!'), isOpen: tooltip.isOpened, placement: toasterPlacement },
|
|
55
|
+
react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { onClick: () => copy(toasterDuration), "data-cy": dataTestId, asIcon: type === 'icon', title: translate(translationKeys.tooltipText, tooltipText || 'Copy to clipboard'), "data-testid": dataTestId }, type === 'icon' ? (react_1.default.createElement(icons_1.CopyIcon, null)) : (translate(translationKeys.buttonText, buttonText || 'Copy')))));
|
|
56
|
+
}
|
|
57
|
+
exports.CopyButton = (0, react_1.memo)(CopyButtonComponent);
|
|
54
58
|
//# sourceMappingURL=CopyButton.js.map
|
|
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../../components/CopyButton/CopyButtonWrapper"), exports);
|
|
18
17
|
__exportStar(require("../../components/CopyButton/CopyButton"), exports);
|
|
19
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type { ReportDialogProps } from '../../components/Feedback/types';
|
|
2
|
+
export interface ReportButtonProps {
|
|
3
|
+
onClick: () => void;
|
|
4
|
+
buttonText: string;
|
|
5
|
+
tooltip: string;
|
|
6
|
+
visible: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface ReportComponentsProps {
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
props: Partial<ReportDialogProps> | ReportButtonProps;
|
|
11
|
+
}
|
|
12
|
+
export declare function useReportDialog(): Record<string, ReportComponentsProps>;
|
|
7
13
|
export {};
|
|
@@ -3,11 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useReportDialog = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const hooks_1 = require("../../mocks/hooks");
|
|
6
|
-
|
|
6
|
+
const hooks_2 = require("../../hooks");
|
|
7
|
+
function useReportDialog() {
|
|
8
|
+
const { codeSnippet: { report = {} } = {} } = (0, hooks_2.useThemeConfig)();
|
|
7
9
|
const [isReportDialogShown, setIsReportDialogShown] = (0, react_1.useState)(false);
|
|
8
|
-
const isReportButtonShown =
|
|
10
|
+
const isReportButtonShown = (report === null || report === void 0 ? void 0 : report.hide) === false; // TODO: report temporary disabled by default
|
|
9
11
|
const { translate } = (0, hooks_1.useTranslate)();
|
|
10
12
|
const translationKeys = {
|
|
13
|
+
buttonText: 'theme.codeSnippet.report.buttonText',
|
|
11
14
|
tooltipText: 'theme.codeSnippet.report.tooltipText',
|
|
12
15
|
label: 'theme.codeSnippet.report.label',
|
|
13
16
|
};
|
|
@@ -19,16 +22,21 @@ function useReportDialog(reportSettings) {
|
|
|
19
22
|
};
|
|
20
23
|
const reportButtonProps = {
|
|
21
24
|
onClick: showReportDialog,
|
|
22
|
-
|
|
25
|
+
buttonText: translate(translationKeys.buttonText, 'Report'),
|
|
26
|
+
tooltip: translate(translationKeys.tooltipText, 'Report a problem'),
|
|
27
|
+
visible: isReportButtonShown,
|
|
23
28
|
};
|
|
24
29
|
const reportDialogProps = {
|
|
25
30
|
settings: {
|
|
26
|
-
label: translate(translationKeys.label,
|
|
31
|
+
label: translate(translationKeys.label, 'What is wrong with this code?'),
|
|
27
32
|
},
|
|
28
33
|
onSubmit: hideReportDialog,
|
|
29
34
|
onCancel: hideReportDialog,
|
|
30
35
|
};
|
|
31
|
-
return {
|
|
36
|
+
return {
|
|
37
|
+
reportDialog: { visible: isReportDialogShown, props: reportDialogProps },
|
|
38
|
+
reportButton: { props: reportButtonProps },
|
|
39
|
+
};
|
|
32
40
|
}
|
|
33
41
|
exports.useReportDialog = useReportDialog;
|
|
34
42
|
//# sourceMappingURL=useReportDialog.js.map
|