docusaurus-theme-openapi-docs 0.0.0-beta.644 → 0.0.0-beta.645
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/theme/ApiDemoPanel/ApiCodeBlock/Container/_Container.scss +6 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Container/index.js +29 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/Element.js +30 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/String.js +131 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +88 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/_CopyButton.scss +44 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/index.js +74 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/_ExitButton.scss +16 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/index.js +47 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/_ExpandButton.scss +42 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +180 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Line/_Line.scss +46 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/Line/index.js +47 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/_WordWrapButton.scss +10 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/index.js +44 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/index.js +40 -0
- package/lib/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +19 -1
- package/lib/theme/ApiDemoPanel/CodeTabs/index.js +1 -1
- package/lib/theme/ApiDemoPanel/Curl/index.js +5 -2
- package/lib/theme/ParamsItem/index.js +1 -1
- package/lib/theme/SchemaItem/index.js +1 -1
- package/lib/theme/styles.scss +10 -0
- package/package.json +5 -3
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Container/_Container.scss +6 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Container/index.js +29 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/Element.js +30 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/String.js +131 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Content/_Content.scss +88 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/_CopyButton.scss +44 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/CopyButton/index.js +74 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/_ExitButton.scss +16 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExitButton/index.js +47 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/_ExpandButton.scss +42 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +180 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Line/_Line.scss +46 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/Line/index.js +47 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/_WordWrapButton.scss +10 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/WordWrapButton/index.js +44 -0
- package/src/theme/ApiDemoPanel/ApiCodeBlock/index.js +40 -0
- package/src/theme/ApiDemoPanel/CodeTabs/_CodeTabs.scss +19 -1
- package/src/theme/ApiDemoPanel/CodeTabs/index.js +1 -1
- package/src/theme/ApiDemoPanel/Curl/index.tsx +5 -3
- package/src/theme/ParamsItem/index.js +1 -1
- package/src/theme/SchemaItem/index.js +1 -1
- package/src/theme/styles.scss +10 -0
- package/src/theme-openapi.d.ts +4 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { useCallback, useState, useRef, useEffect } from "react";
|
|
9
|
+
|
|
10
|
+
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
// @ts-expect-error: TODO, we need to make theme-classic have type: module
|
|
13
|
+
import copy from "copy-text-to-clipboard";
|
|
14
|
+
|
|
15
|
+
export default function CopyButton({ code, className }) {
|
|
16
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
17
|
+
const copyTimeout = useRef(undefined);
|
|
18
|
+
const handleCopyCode = useCallback(() => {
|
|
19
|
+
copy(code);
|
|
20
|
+
setIsCopied(true);
|
|
21
|
+
copyTimeout.current = window.setTimeout(() => {
|
|
22
|
+
setIsCopied(false);
|
|
23
|
+
}, 1000);
|
|
24
|
+
}, [code]);
|
|
25
|
+
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
|
|
26
|
+
return (
|
|
27
|
+
<button
|
|
28
|
+
type="button"
|
|
29
|
+
aria-label={
|
|
30
|
+
isCopied
|
|
31
|
+
? translate({
|
|
32
|
+
id: "theme.CodeBlock.copied",
|
|
33
|
+
message: "Copied",
|
|
34
|
+
description: "The copied button label on code blocks",
|
|
35
|
+
})
|
|
36
|
+
: translate({
|
|
37
|
+
id: "theme.CodeBlock.copyButtonAriaLabel",
|
|
38
|
+
message: "Copy code to clipboard",
|
|
39
|
+
description: "The ARIA label for copy code blocks button",
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
title={translate({
|
|
43
|
+
id: "theme.CodeBlock.copy",
|
|
44
|
+
message: "Copy",
|
|
45
|
+
description: "The copy button label on code blocks",
|
|
46
|
+
})}
|
|
47
|
+
className={clsx(
|
|
48
|
+
"clean-btn",
|
|
49
|
+
className,
|
|
50
|
+
"openapi-demo__code-block-copy-btn",
|
|
51
|
+
isCopied && "openapi-demo__code-block-copy-btn--copied"
|
|
52
|
+
)}
|
|
53
|
+
onClick={handleCopyCode}
|
|
54
|
+
>
|
|
55
|
+
<span
|
|
56
|
+
className="openapi-demo__code-block-copy-btn-icons"
|
|
57
|
+
aria-hidden="true"
|
|
58
|
+
>
|
|
59
|
+
<svg
|
|
60
|
+
className="openapi-demo__code-block-copy-btn-icon"
|
|
61
|
+
viewBox="0 0 24 24"
|
|
62
|
+
>
|
|
63
|
+
<path d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" />
|
|
64
|
+
</svg>
|
|
65
|
+
<svg
|
|
66
|
+
className="openapi-demo__code-block-copy-btn-icon--success"
|
|
67
|
+
viewBox="0 0 24 24"
|
|
68
|
+
>
|
|
69
|
+
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
|
|
70
|
+
</svg>
|
|
71
|
+
</span>
|
|
72
|
+
</button>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.openapi-demo__code-block-exit-btn-icons {
|
|
2
|
+
position: relative;
|
|
3
|
+
width: 1.125rem;
|
|
4
|
+
height: 1.125rem;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.openapi-demo__code-block-exit-btn-icon {
|
|
8
|
+
position: absolute;
|
|
9
|
+
top: 0;
|
|
10
|
+
left: 0;
|
|
11
|
+
fill: currentColor;
|
|
12
|
+
opacity: inherit;
|
|
13
|
+
width: inherit;
|
|
14
|
+
height: inherit;
|
|
15
|
+
transition: all 0.15s ease;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
|
|
13
|
+
export default function ExitButton({ className, handler }) {
|
|
14
|
+
return (
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
aria-label={translate({
|
|
18
|
+
id: "theme.CodeBlock.exitButtonAriaLabel",
|
|
19
|
+
message: "Exit expanded view",
|
|
20
|
+
description: "The ARIA label for exit expanded view button",
|
|
21
|
+
})}
|
|
22
|
+
title={translate({
|
|
23
|
+
id: "theme.CodeBlock.copy",
|
|
24
|
+
message: "Copy",
|
|
25
|
+
description: "The exit button label on code blocks",
|
|
26
|
+
})}
|
|
27
|
+
className={clsx(
|
|
28
|
+
"clean-btn",
|
|
29
|
+
"openapi-demo__code-block-exit-btn",
|
|
30
|
+
className
|
|
31
|
+
)}
|
|
32
|
+
onClick={handler}
|
|
33
|
+
>
|
|
34
|
+
<span
|
|
35
|
+
className="openapi-demo__code-block-exit-btn-icons"
|
|
36
|
+
aria-hidden="true"
|
|
37
|
+
>
|
|
38
|
+
<svg
|
|
39
|
+
className="openapi-demo__code-block-exit-btn-icon"
|
|
40
|
+
viewBox="0 0 384 512"
|
|
41
|
+
>
|
|
42
|
+
<path d="M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L237.3 256 342.6 150.6z" />
|
|
43
|
+
</svg>
|
|
44
|
+
</span>
|
|
45
|
+
</button>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
.theme-code-block:hover .openapi-demo__code-block-expand-btn--copied {
|
|
2
|
+
opacity: 1 !important;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.openapi-demo__code-block-expand-btn-icons {
|
|
6
|
+
position: relative;
|
|
7
|
+
width: 1.125rem;
|
|
8
|
+
height: 1.125rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.openapi-demo__code-block-expand-btn-icon,
|
|
12
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
13
|
+
position: absolute;
|
|
14
|
+
top: 0;
|
|
15
|
+
left: 0;
|
|
16
|
+
fill: currentColor;
|
|
17
|
+
opacity: inherit;
|
|
18
|
+
width: inherit;
|
|
19
|
+
height: inherit;
|
|
20
|
+
transition: all 0.15s ease;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
24
|
+
top: 50%;
|
|
25
|
+
left: 50%;
|
|
26
|
+
transform: translate(-50%, -50%) scale(0.33);
|
|
27
|
+
opacity: 0;
|
|
28
|
+
color: #00d600;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.openapi-demo__code-block-expand-btn--copied
|
|
32
|
+
.openapi-demo__code-block-expand-btn-icon {
|
|
33
|
+
transform: scale(0.33);
|
|
34
|
+
opacity: 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.openapi-demo__code-block-expand-btn--copied
|
|
38
|
+
.openapi-demo__code-block-expand-btn-icon--success {
|
|
39
|
+
transform: translate(-50%, -50%) scale(1);
|
|
40
|
+
opacity: 1;
|
|
41
|
+
transition-delay: 0.075s;
|
|
42
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { useEffect } from "react";
|
|
9
|
+
|
|
10
|
+
import { usePrismTheme } from "@docusaurus/theme-common";
|
|
11
|
+
import { translate } from "@docusaurus/Translate";
|
|
12
|
+
import Container from "@theme/ApiDemoPanel/ApiCodeBlock/Container";
|
|
13
|
+
import CopyButton from "@theme/ApiDemoPanel/ApiCodeBlock/CopyButton";
|
|
14
|
+
import ExitButton from "@theme/ApiDemoPanel/ApiCodeBlock/ExitButton";
|
|
15
|
+
import Line from "@theme/ApiDemoPanel/ApiCodeBlock/Line";
|
|
16
|
+
import clsx from "clsx";
|
|
17
|
+
import Highlight, { defaultProps } from "prism-react-renderer";
|
|
18
|
+
import Modal from "react-modal";
|
|
19
|
+
|
|
20
|
+
export default function ExpandButton({
|
|
21
|
+
code,
|
|
22
|
+
className,
|
|
23
|
+
language,
|
|
24
|
+
showLineNumbers,
|
|
25
|
+
blockClassName,
|
|
26
|
+
title,
|
|
27
|
+
lineClassNames,
|
|
28
|
+
}) {
|
|
29
|
+
const prismTheme = usePrismTheme();
|
|
30
|
+
|
|
31
|
+
function openModal() {
|
|
32
|
+
setIsOpen(true);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closeModal() {
|
|
36
|
+
setIsOpen(false);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const [modalIsOpen, setIsOpen] = React.useState(false);
|
|
40
|
+
|
|
41
|
+
const customStyles = {
|
|
42
|
+
overlay: { backgroundColor: "rgba(0, 0, 0, 0.9)", zIndex: "201" },
|
|
43
|
+
content: {
|
|
44
|
+
top: "50%",
|
|
45
|
+
left: "50%",
|
|
46
|
+
right: "auto",
|
|
47
|
+
bottom: "auto",
|
|
48
|
+
padding: "none",
|
|
49
|
+
border: "thin solid var(--ifm-toc-border-color)",
|
|
50
|
+
borderRadius: "var(--ifm-global-radius)",
|
|
51
|
+
transform: "translate(-50%, -50%)",
|
|
52
|
+
maxWidth: "95%",
|
|
53
|
+
width: "min-content",
|
|
54
|
+
overflow: "auto",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
Modal.setAppElement("body");
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<>
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
aria-label={
|
|
66
|
+
modalIsOpen
|
|
67
|
+
? translate({
|
|
68
|
+
id: "theme.CodeBlock.expanded",
|
|
69
|
+
message: "Expanded",
|
|
70
|
+
description: "The expanded button label on code blocks",
|
|
71
|
+
})
|
|
72
|
+
: translate({
|
|
73
|
+
id: "theme.CodeBlock.expandButtonAriaLabel",
|
|
74
|
+
message: "Expand code to fullscreen",
|
|
75
|
+
description: "The ARIA label for expand code blocks button",
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
title={translate({
|
|
79
|
+
id: "theme.CodeBlock.expand",
|
|
80
|
+
message: "Expand",
|
|
81
|
+
description: "The expand button label on code blocks",
|
|
82
|
+
})}
|
|
83
|
+
className={clsx(
|
|
84
|
+
"clean-btn",
|
|
85
|
+
className,
|
|
86
|
+
"openapi-demo__code-block-expand-btn",
|
|
87
|
+
modalIsOpen && "openapi-demo__code-block-expand-btn--copied"
|
|
88
|
+
)}
|
|
89
|
+
onClick={openModal}
|
|
90
|
+
>
|
|
91
|
+
<span
|
|
92
|
+
className="openapi-demo__code-block-expand-btn-icons"
|
|
93
|
+
aria-hidden="true"
|
|
94
|
+
>
|
|
95
|
+
<svg
|
|
96
|
+
className="openapi-demo__code-block-expand-btn-icon"
|
|
97
|
+
viewBox="0 0 448 512"
|
|
98
|
+
>
|
|
99
|
+
<path d="M32 32C14.3 32 0 46.3 0 64v96c0 17.7 14.3 32 32 32s32-14.3 32-32V96h64c17.7 0 32-14.3 32-32s-14.3-32-32-32H32zM64 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v96c0 17.7 14.3 32 32 32h96c17.7 0 32-14.3 32-32s-14.3-32-32-32H64V352zM320 32c-17.7 0-32 14.3-32 32s14.3 32 32 32h64v64c0 17.7 14.3 32 32 32s32-14.3 32-32V64c0-17.7-14.3-32-32-32H320zM448 352c0-17.7-14.3-32-32-32s-32 14.3-32 32v64H320c-17.7 0-32 14.3-32 32s14.3 32 32 32h96c17.7 0 32-14.3 32-32V352z" />
|
|
100
|
+
</svg>
|
|
101
|
+
<svg
|
|
102
|
+
className="openapi-demo__code-block-expand-btn-icon--success"
|
|
103
|
+
viewBox="0 0 24 24"
|
|
104
|
+
>
|
|
105
|
+
<path d="M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" />
|
|
106
|
+
</svg>
|
|
107
|
+
</span>
|
|
108
|
+
</button>
|
|
109
|
+
<Modal
|
|
110
|
+
isOpen={modalIsOpen}
|
|
111
|
+
onRequestClose={closeModal}
|
|
112
|
+
style={customStyles}
|
|
113
|
+
contentLabel="Code Snippet"
|
|
114
|
+
>
|
|
115
|
+
<Container
|
|
116
|
+
as="div"
|
|
117
|
+
className={clsx(
|
|
118
|
+
"openapi-demo__code-block-container",
|
|
119
|
+
language &&
|
|
120
|
+
!blockClassName.includes(`language-${language}`) &&
|
|
121
|
+
`language-${language}`
|
|
122
|
+
)}
|
|
123
|
+
>
|
|
124
|
+
{title && (
|
|
125
|
+
<div className="openapi-demo__code-block-title">{title}</div>
|
|
126
|
+
)}
|
|
127
|
+
<div className="openapi-demo__code-block-content">
|
|
128
|
+
<Highlight
|
|
129
|
+
{...defaultProps}
|
|
130
|
+
theme={prismTheme}
|
|
131
|
+
code={code}
|
|
132
|
+
language={language ?? "text"}
|
|
133
|
+
>
|
|
134
|
+
{({ className, tokens, getLineProps, getTokenProps }) => (
|
|
135
|
+
<pre
|
|
136
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
137
|
+
tabIndex={0}
|
|
138
|
+
className={clsx(
|
|
139
|
+
className,
|
|
140
|
+
"openapi-demo__code-block",
|
|
141
|
+
"thin-scrollbar"
|
|
142
|
+
)}
|
|
143
|
+
>
|
|
144
|
+
<code
|
|
145
|
+
className={clsx(
|
|
146
|
+
"openapi-demo__code-block-lines",
|
|
147
|
+
showLineNumbers &&
|
|
148
|
+
"openapi-demo__code-block-lines-numbers"
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{tokens.map((line, i) => (
|
|
152
|
+
<Line
|
|
153
|
+
key={i}
|
|
154
|
+
line={line}
|
|
155
|
+
getLineProps={getLineProps}
|
|
156
|
+
getTokenProps={getTokenProps}
|
|
157
|
+
classNames={lineClassNames[i]}
|
|
158
|
+
showLineNumbers={showLineNumbers}
|
|
159
|
+
/>
|
|
160
|
+
))}
|
|
161
|
+
</code>
|
|
162
|
+
</pre>
|
|
163
|
+
)}
|
|
164
|
+
</Highlight>
|
|
165
|
+
<div className="openapi-demo__code-block-btn-group">
|
|
166
|
+
<CopyButton
|
|
167
|
+
className="openapi-demo__code-block-code-btn"
|
|
168
|
+
code={code}
|
|
169
|
+
/>
|
|
170
|
+
<ExitButton
|
|
171
|
+
className="openapi-dmeo__code-block-code-btn"
|
|
172
|
+
handler={closeModal}
|
|
173
|
+
/>
|
|
174
|
+
</div>
|
|
175
|
+
</div>
|
|
176
|
+
</Container>
|
|
177
|
+
</Modal>
|
|
178
|
+
</>
|
|
179
|
+
);
|
|
180
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* Intentionally has zero specificity, so that to be able to override
|
|
2
|
+
the background in custom CSS file due bug https://github.com/facebook/docusaurus/issues/3678 */
|
|
3
|
+
:where(:root) {
|
|
4
|
+
--docusaurus-highlighted-code-line-bg: rgb(72 77 91);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
:where([data-theme="dark"]) {
|
|
8
|
+
--docusaurus-highlighted-code-line-bg: rgb(100 100 100);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.theme-code-block-highlighted-line {
|
|
12
|
+
background-color: var(--docusaurus-highlighted-code-line-bg);
|
|
13
|
+
display: block;
|
|
14
|
+
margin: 0 calc(-1 * var(--ifm-pre-padding));
|
|
15
|
+
padding: 0 var(--ifm-pre-padding);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.openapi-demo__code-block-code-line {
|
|
19
|
+
display: table-row;
|
|
20
|
+
counter-increment: line-count;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.openapi-demo__code-block-code-line-number {
|
|
24
|
+
display: table-cell;
|
|
25
|
+
text-align: right;
|
|
26
|
+
width: 1%;
|
|
27
|
+
position: sticky;
|
|
28
|
+
left: 0;
|
|
29
|
+
padding: 0 var(--ifm-pre-padding);
|
|
30
|
+
background: var(--ifm-pre-background);
|
|
31
|
+
overflow-wrap: normal;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.openapi-demo__code-block-code-line-number::before {
|
|
35
|
+
content: counter(line-count);
|
|
36
|
+
opacity: 0.4;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
:global(.theme-code-block-highlighted-line)
|
|
40
|
+
.openapi-demo__code-block-code-line-number::before {
|
|
41
|
+
opacity: 0.8;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.openapi-demo__code-block-code-line-number {
|
|
45
|
+
padding-right: var(--ifm-pre-padding);
|
|
46
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import clsx from "clsx";
|
|
11
|
+
|
|
12
|
+
export default function CodeBlockLine({
|
|
13
|
+
line,
|
|
14
|
+
classNames,
|
|
15
|
+
showLineNumbers,
|
|
16
|
+
getLineProps,
|
|
17
|
+
getTokenProps,
|
|
18
|
+
}) {
|
|
19
|
+
if (line.length === 1 && line[0].content === "\n") {
|
|
20
|
+
line[0].content = "";
|
|
21
|
+
}
|
|
22
|
+
const lineProps = getLineProps({
|
|
23
|
+
line,
|
|
24
|
+
className: clsx(
|
|
25
|
+
classNames,
|
|
26
|
+
showLineNumbers && "openapi-demo__code-block-code-line"
|
|
27
|
+
),
|
|
28
|
+
});
|
|
29
|
+
const lineTokens = line.map((token, key) => (
|
|
30
|
+
<span key={key} {...getTokenProps({ token, key })} />
|
|
31
|
+
));
|
|
32
|
+
return (
|
|
33
|
+
<span {...lineProps}>
|
|
34
|
+
{showLineNumbers ? (
|
|
35
|
+
<>
|
|
36
|
+
<span className="openapi-demo__code-block-code-line-number" />
|
|
37
|
+
<span className="openapi-demo__code-block-code-line-content">
|
|
38
|
+
{lineTokens}
|
|
39
|
+
</span>
|
|
40
|
+
</>
|
|
41
|
+
) : (
|
|
42
|
+
lineTokens
|
|
43
|
+
)}
|
|
44
|
+
<br />
|
|
45
|
+
</span>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
import { translate } from "@docusaurus/Translate";
|
|
11
|
+
import clsx from "clsx";
|
|
12
|
+
|
|
13
|
+
export default function WordWrapButton({ className, onClick, isEnabled }) {
|
|
14
|
+
const title = translate({
|
|
15
|
+
id: "theme.CodeBlock.wordWrapToggle",
|
|
16
|
+
message: "Toggle word wrap",
|
|
17
|
+
description:
|
|
18
|
+
"The title attribute for toggle word wrapping button of code block lines",
|
|
19
|
+
});
|
|
20
|
+
return (
|
|
21
|
+
<button
|
|
22
|
+
type="button"
|
|
23
|
+
onClick={onClick}
|
|
24
|
+
className={clsx(
|
|
25
|
+
"clean-btn",
|
|
26
|
+
className,
|
|
27
|
+
isEnabled && "openapi-demo__code-block-word-wrap-btn--enabled"
|
|
28
|
+
)}
|
|
29
|
+
aria-label={title}
|
|
30
|
+
title={title}
|
|
31
|
+
>
|
|
32
|
+
<svg
|
|
33
|
+
className="openapi-demo__code-block-word-wrap-btn-icon"
|
|
34
|
+
viewBox="0 0 24 24"
|
|
35
|
+
aria-hidden="true"
|
|
36
|
+
>
|
|
37
|
+
<path
|
|
38
|
+
fill="currentColor"
|
|
39
|
+
d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3l3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"
|
|
40
|
+
/>
|
|
41
|
+
</svg>
|
|
42
|
+
</button>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Copyright (c) Palo Alto Networks
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
* ========================================================================== */
|
|
7
|
+
|
|
8
|
+
import React, { isValidElement } from "react";
|
|
9
|
+
|
|
10
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
11
|
+
import ElementContent from "@theme/ApiDemoPanel/ApiCodeBlock/Content/Element";
|
|
12
|
+
import StringContent from "@theme/ApiDemoPanel/ApiCodeBlock/Content/String";
|
|
13
|
+
/**
|
|
14
|
+
* Best attempt to make the children a plain string so it is copyable. If there
|
|
15
|
+
* are react elements, we will not be able to copy the content, and it will
|
|
16
|
+
* return `children` as-is; otherwise, it concatenates the string children
|
|
17
|
+
* together.
|
|
18
|
+
*/
|
|
19
|
+
function maybeStringifyChildren(children) {
|
|
20
|
+
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
21
|
+
return children;
|
|
22
|
+
}
|
|
23
|
+
// The children is now guaranteed to be one/more plain strings
|
|
24
|
+
return Array.isArray(children) ? children.join("") : children;
|
|
25
|
+
}
|
|
26
|
+
export default function ApiCodeBlock({ children: rawChildren, ...props }) {
|
|
27
|
+
// The Prism theme on SSR is always the default theme but the site theme can
|
|
28
|
+
// be in a different mode. React hydration doesn't update DOM styles that come
|
|
29
|
+
// from SSR. Hence force a re-render after mounting to apply the current
|
|
30
|
+
// relevant styles.
|
|
31
|
+
const isBrowser = useIsBrowser();
|
|
32
|
+
const children = maybeStringifyChildren(rawChildren);
|
|
33
|
+
const CodeBlockComp =
|
|
34
|
+
typeof children === "string" ? StringContent : ElementContent;
|
|
35
|
+
return (
|
|
36
|
+
<CodeBlockComp key={String(isBrowser)} {...props}>
|
|
37
|
+
{children}
|
|
38
|
+
</CodeBlockComp>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
--bash-border-radius: 20px;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
.openapi-tabs__code-container {
|
|
14
|
+
margin-bottom: 1rem;
|
|
15
|
+
}
|
|
16
|
+
|
|
13
17
|
.openapi-tabs__code-list-container {
|
|
14
18
|
display: flex;
|
|
15
19
|
justify-content: flex-start;
|
|
@@ -21,7 +25,13 @@
|
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
.openapi-demo__code-block code {
|
|
24
|
-
max-height:
|
|
28
|
+
max-height: 200px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
body[class="ReactModal__Body--open"] {
|
|
32
|
+
.openapi-demo__code-block code {
|
|
33
|
+
max-height: 600px;
|
|
34
|
+
}
|
|
25
35
|
}
|
|
26
36
|
|
|
27
37
|
.openapi-tabs__code-item {
|
|
@@ -215,3 +225,11 @@
|
|
|
215
225
|
justify-content: space-around;
|
|
216
226
|
}
|
|
217
227
|
}
|
|
228
|
+
|
|
229
|
+
.ReactModal__Body--open {
|
|
230
|
+
overflow: hidden !important;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.openapi-modal--open {
|
|
234
|
+
background-color: rgba(0, 0, 0, 0.7) !important;
|
|
235
|
+
}
|
|
@@ -136,7 +136,7 @@ function TabContent({ lazy, children, selectedValue }) {
|
|
|
136
136
|
function TabsComponent(props) {
|
|
137
137
|
const tabs = useTabs(props);
|
|
138
138
|
return (
|
|
139
|
-
<div className="tabs-container">
|
|
139
|
+
<div className="tabs-container openapi-tabs__code-container">
|
|
140
140
|
<TabList {...props} {...tabs} />
|
|
141
141
|
<TabContent {...props} {...tabs} />
|
|
142
142
|
</div>
|
|
@@ -10,10 +10,10 @@ import React, { useState, useEffect } from "react";
|
|
|
10
10
|
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
|
|
11
11
|
import codegen from "@paloaltonetworks/postman-code-generators";
|
|
12
12
|
import sdk from "@paloaltonetworks/postman-collection";
|
|
13
|
+
import ApiCodeBlock from "@theme/ApiDemoPanel/ApiCodeBlock";
|
|
13
14
|
import buildPostmanRequest from "@theme/ApiDemoPanel/buildPostmanRequest";
|
|
14
15
|
import CodeTabs from "@theme/ApiDemoPanel/CodeTabs";
|
|
15
16
|
import { useTypedSelector } from "@theme/ApiItem/hooks";
|
|
16
|
-
import CodeBlock from "@theme/CodeBlock";
|
|
17
17
|
import merge from "lodash/merge";
|
|
18
18
|
|
|
19
19
|
export interface Language {
|
|
@@ -285,13 +285,15 @@ function Curl({ postman, codeSamples }: Props) {
|
|
|
285
285
|
className: `openapi-tabs__code-item--${lang.logoClass}`,
|
|
286
286
|
}}
|
|
287
287
|
>
|
|
288
|
-
|
|
288
|
+
{/* @ts-ignore */}
|
|
289
|
+
<ApiCodeBlock
|
|
289
290
|
language={lang.highlight}
|
|
290
291
|
className="openapi-demo__code-block"
|
|
291
292
|
title={`${lang.language} / ${lang.variant}`}
|
|
293
|
+
showLineNumbers={true}
|
|
292
294
|
>
|
|
293
295
|
{codeText}
|
|
294
|
-
</
|
|
296
|
+
</ApiCodeBlock>
|
|
295
297
|
</CodeTab>
|
|
296
298
|
);
|
|
297
299
|
})}
|
|
@@ -123,7 +123,7 @@ function ParamsItem({
|
|
|
123
123
|
<span className="openapi-schema__container">
|
|
124
124
|
<strong>{name}</strong>
|
|
125
125
|
{renderSchemaName}
|
|
126
|
-
{required && <span
|
|
126
|
+
{required && <span className="openapi-schema__divider"></span>}
|
|
127
127
|
{renderSchemaRequired}
|
|
128
128
|
</span>
|
|
129
129
|
{renderSchema}
|
|
@@ -101,7 +101,7 @@ function SchemaItem({
|
|
|
101
101
|
</strong>
|
|
102
102
|
<span className="openapi-schema__name"> {schemaName}</span>
|
|
103
103
|
{(nullable || required || deprecated) && (
|
|
104
|
-
<span
|
|
104
|
+
<span className="openapi-schema__divider"></span>
|
|
105
105
|
)}
|
|
106
106
|
{renderNullable}
|
|
107
107
|
{!deprecated && renderRequired}
|
package/src/theme/styles.scss
CHANGED
|
@@ -18,6 +18,16 @@
|
|
|
18
18
|
@use "./ApiDemoPanel/Request/Request";
|
|
19
19
|
@use "./ApiDemoPanel/Response/Response";
|
|
20
20
|
@use "./ApiDemoPanel/Server/Server";
|
|
21
|
+
|
|
22
|
+
/* Api Demo Panel / ApiCodeBlock */
|
|
23
|
+
@use "./ApiDemoPanel/ApiCodeBlock/Container/Container";
|
|
24
|
+
@use "./ApiDemoPanel/ApiCodeBlock/Content/Content";
|
|
25
|
+
@use "./ApiDemoPanel/ApiCodeBlock/CopyButton/CopyButton";
|
|
26
|
+
@use "./ApiDemoPanel/ApiCodeBlock/ExitButton/ExitButton";
|
|
27
|
+
@use "./ApiDemoPanel/ApiCodeBlock/ExpandButton/ExpandButton";
|
|
28
|
+
@use "./ApiDemoPanel/ApiCodeBlock/Line/Line";
|
|
29
|
+
@use "./ApiDemoPanel/ApiCodeBlock/WordWrapButton/WordWrapButton";
|
|
30
|
+
|
|
21
31
|
/* Schema Styling */
|
|
22
32
|
@use "./ParamsItem/ParamsItem";
|
|
23
33
|
@use "./SchemaItem/SchemaItem";
|
package/src/theme-openapi.d.ts
CHANGED
|
@@ -225,6 +225,10 @@ declare module "@theme/ApiDemoPanel/Server" {
|
|
|
225
225
|
export default function Server(): JSX.Element;
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
+
declare module "@theme/ApiDemoPanel/ApiCodeBlock" {
|
|
229
|
+
export default function ApiCodeBlock(): JSX.Element;
|
|
230
|
+
}
|
|
231
|
+
|
|
228
232
|
declare module "@theme/ApiDemoPanel/Server/slice" {
|
|
229
233
|
export default server as Reducer<State, AnyAction>;
|
|
230
234
|
}
|