docusaurus-theme-openapi-docs 3.0.0-beta.3 → 3.0.0-beta.5
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/markdown/utils.d.ts +2 -1
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.d.ts +13 -0
- package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +199 -124
- package/lib/theme/ApiExplorer/Accept/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +115 -96
- package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +200 -120
- package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
- package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
- package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
- package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
- package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Body/index.js +8 -1
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
- package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
- package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +4 -14
- package/lib/theme/ApiExplorer/CodeSnippets/index.js +87 -8
- package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +2 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +32 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
- package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +14 -0
- package/lib/theme/ApiExplorer/CodeTabs/index.js +130 -78
- package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
- package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/index.js +1 -1
- package/lib/theme/ApiItem/index.d.ts +2 -2
- package/lib/theme/ApiItem/index.js +4 -3
- package/lib/theme/ApiItem/store.d.ts +4 -4
- package/lib/theme/ApiLogo/index.d.ts +2 -2
- package/lib/theme/ApiTabs/index.d.ts +7 -0
- package/lib/theme/ApiTabs/index.js +155 -97
- package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
- package/lib/theme/DiscriminatorTabs/index.js +146 -94
- package/lib/theme/Markdown/index.js +37 -0
- package/lib/theme/MimeTabs/index.d.ts +6 -0
- package/lib/theme/MimeTabs/index.js +163 -114
- package/lib/theme/OperationTabs/_OperationTabs.scss +68 -0
- package/lib/theme/OperationTabs/index.d.ts +3 -0
- package/lib/theme/OperationTabs/index.js +232 -0
- package/lib/theme/ParamsItem/index.d.ts +22 -0
- package/lib/theme/ParamsItem/index.js +154 -109
- package/lib/theme/ResponseSamples/index.d.ts +8 -0
- package/lib/theme/ResponseSamples/index.js +18 -13
- package/lib/theme/SchemaItem/index.d.ts +12 -0
- package/lib/theme/SchemaItem/index.js +123 -89
- package/lib/theme/SchemaTabs/index.d.ts +3 -0
- package/lib/theme/SchemaTabs/index.js +142 -91
- package/lib/theme/styles.scss +1 -0
- package/package.json +4 -4
- package/src/markdown/utils.ts +4 -2
- package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
- package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
- package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +4 -4
- package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
- package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +12 -2
- package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
- package/src/theme/ApiExplorer/Body/index.tsx +3 -1
- package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
- package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
- package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +37 -0
- package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
- package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +57 -25
- package/src/theme/ApiExplorer/index.tsx +1 -1
- package/src/theme/ApiItem/index.tsx +3 -4
- package/src/theme/ApiLogo/index.tsx +1 -1
- package/src/theme/ApiTabs/{index.js → index.tsx} +63 -25
- package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
- package/src/theme/Markdown/index.js +37 -0
- package/src/theme/MimeTabs/{index.js → index.tsx} +58 -26
- package/src/theme/OperationTabs/_OperationTabs.scss +68 -0
- package/src/theme/OperationTabs/index.tsx +216 -0
- package/src/theme/ParamsItem/{index.js → index.tsx} +28 -13
- package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
- package/src/theme/SchemaItem/{index.js → index.tsx} +18 -9
- package/src/theme/SchemaTabs/{index.js → index.tsx} +56 -25
- package/src/theme/styles.scss +1 -0
- package/src/theme-classic.d.ts +69 -2
- package/src/theme-openapi.d.ts +4 -0
- package/tsconfig.json +4 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
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
|
+
.openapi-tabs__operation-container {
|
|
9
|
+
display: flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
margin-top: 1rem;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.openapi-tabs__operation-item {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
padding: 0.35rem 0.7rem;
|
|
20
|
+
border: 1px solid transparent;
|
|
21
|
+
margin-top: 0 !important;
|
|
22
|
+
margin-right: 0.5rem;
|
|
23
|
+
font-weight: var(--ifm-font-weight-bold);
|
|
24
|
+
font-size: 12px;
|
|
25
|
+
white-space: nowrap;
|
|
26
|
+
transition: 300ms;
|
|
27
|
+
|
|
28
|
+
&:hover {
|
|
29
|
+
background-color: transparent;
|
|
30
|
+
border: 1px solid var(--ifm-toc-border-color);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.active {
|
|
34
|
+
border: 1px solid var(--ifm-tabs-color-active-border);
|
|
35
|
+
color: var(--ifm-tabs-color-active);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&:last-child {
|
|
39
|
+
margin-right: 0 !important;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.openapi-tabs__operation-list-container {
|
|
44
|
+
overflow-y: hidden;
|
|
45
|
+
overflow-x: scroll;
|
|
46
|
+
scroll-behavior: smooth;
|
|
47
|
+
|
|
48
|
+
&::-webkit-scrollbar {
|
|
49
|
+
display: none;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.openapi-tabs__operation-schema-container {
|
|
54
|
+
max-width: 600px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media screen and (max-width: 500px) {
|
|
58
|
+
.operationTabsTopSection {
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
align-items: flex-start;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.operationTabsContainer {
|
|
64
|
+
width: 100%;
|
|
65
|
+
margin-top: var(--ifm-spacing-vertical);
|
|
66
|
+
padding: 0;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
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, {
|
|
9
|
+
cloneElement,
|
|
10
|
+
useEffect,
|
|
11
|
+
useState,
|
|
12
|
+
useRef,
|
|
13
|
+
ReactElement,
|
|
14
|
+
} from "react";
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
sanitizeTabsChildren,
|
|
18
|
+
TabProps,
|
|
19
|
+
useScrollPositionBlocker,
|
|
20
|
+
useTabs,
|
|
21
|
+
} from "@docusaurus/theme-common/internal";
|
|
22
|
+
import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
|
|
23
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
24
|
+
import clsx from "clsx";
|
|
25
|
+
|
|
26
|
+
function TabList({
|
|
27
|
+
className,
|
|
28
|
+
block,
|
|
29
|
+
selectedValue,
|
|
30
|
+
selectValue,
|
|
31
|
+
tabValues,
|
|
32
|
+
}: TabProps & ReturnType<typeof useTabs>) {
|
|
33
|
+
const tabRefs: (HTMLLIElement | null)[] = [];
|
|
34
|
+
const { blockElementScrollPositionUntilNextRender } =
|
|
35
|
+
useScrollPositionBlocker();
|
|
36
|
+
|
|
37
|
+
const handleTabChange = (
|
|
38
|
+
event:
|
|
39
|
+
| React.FocusEvent<HTMLLIElement>
|
|
40
|
+
| React.MouseEvent<HTMLLIElement>
|
|
41
|
+
| React.KeyboardEvent<HTMLLIElement>
|
|
42
|
+
) => {
|
|
43
|
+
const newTab = event.currentTarget;
|
|
44
|
+
const newTabIndex = tabRefs.indexOf(newTab);
|
|
45
|
+
const newTabValue = tabValues[newTabIndex].value;
|
|
46
|
+
|
|
47
|
+
if (newTabValue !== selectedValue) {
|
|
48
|
+
blockElementScrollPositionUntilNextRender(newTab);
|
|
49
|
+
selectValue(newTabValue);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
|
|
54
|
+
let focusElement: HTMLLIElement | null = null;
|
|
55
|
+
|
|
56
|
+
switch (event.key) {
|
|
57
|
+
case "Enter": {
|
|
58
|
+
handleTabChange(event);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "ArrowRight": {
|
|
62
|
+
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
63
|
+
focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case "ArrowLeft": {
|
|
67
|
+
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
68
|
+
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
default:
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
focusElement?.focus();
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const tabItemListContainerRef = useRef<HTMLUListElement>(null);
|
|
79
|
+
const [showTabArrows, setShowTabArrows] = useState<boolean>(false);
|
|
80
|
+
|
|
81
|
+
useEffect(() => {
|
|
82
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
83
|
+
for (let entry of entries) {
|
|
84
|
+
if (entry.target.clientWidth < entry.target.scrollWidth) {
|
|
85
|
+
setShowTabArrows(true);
|
|
86
|
+
} else {
|
|
87
|
+
setShowTabArrows(false);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
resizeObserver.observe(tabItemListContainerRef.current!);
|
|
93
|
+
|
|
94
|
+
return () => {
|
|
95
|
+
resizeObserver.disconnect();
|
|
96
|
+
};
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
const handleRightClick = () => {
|
|
100
|
+
tabItemListContainerRef.current!.scrollLeft += 90;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const handleLeftClick = () => {
|
|
104
|
+
tabItemListContainerRef.current!.scrollLeft -= 90;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div className="tabs__container">
|
|
109
|
+
<div className="openapi-tabs__operation-container">
|
|
110
|
+
{showTabArrows && (
|
|
111
|
+
<button
|
|
112
|
+
className={clsx("openapi-tabs__arrow", "left")}
|
|
113
|
+
onClick={handleLeftClick}
|
|
114
|
+
/>
|
|
115
|
+
)}
|
|
116
|
+
<ul
|
|
117
|
+
ref={tabItemListContainerRef}
|
|
118
|
+
role="tablist"
|
|
119
|
+
aria-orientation="horizontal"
|
|
120
|
+
className={clsx(
|
|
121
|
+
"openapi-tabs__operation-list-container",
|
|
122
|
+
"tabs",
|
|
123
|
+
{
|
|
124
|
+
"tabs--block": block,
|
|
125
|
+
},
|
|
126
|
+
className
|
|
127
|
+
)}
|
|
128
|
+
>
|
|
129
|
+
{tabValues.map(({ value, label, attributes }) => {
|
|
130
|
+
return (
|
|
131
|
+
<li
|
|
132
|
+
// TODO extract TabListItem
|
|
133
|
+
role="tab"
|
|
134
|
+
tabIndex={selectedValue === value ? 0 : -1}
|
|
135
|
+
aria-selected={selectedValue === value}
|
|
136
|
+
key={value}
|
|
137
|
+
ref={(tabControl) => tabRefs.push(tabControl)}
|
|
138
|
+
onKeyDown={handleKeydown}
|
|
139
|
+
onFocus={handleTabChange}
|
|
140
|
+
onClick={(e) => handleTabChange(e)}
|
|
141
|
+
{...attributes}
|
|
142
|
+
className={clsx(
|
|
143
|
+
"tabs__item",
|
|
144
|
+
"openapi-tabs__operation-item",
|
|
145
|
+
attributes?.className as string,
|
|
146
|
+
{
|
|
147
|
+
active: selectedValue === value,
|
|
148
|
+
}
|
|
149
|
+
)}
|
|
150
|
+
>
|
|
151
|
+
{label ?? value}
|
|
152
|
+
</li>
|
|
153
|
+
);
|
|
154
|
+
})}
|
|
155
|
+
</ul>
|
|
156
|
+
{showTabArrows && (
|
|
157
|
+
<button
|
|
158
|
+
className={clsx("openapi-tabs__arrow", "right")}
|
|
159
|
+
onClick={handleRightClick}
|
|
160
|
+
/>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
function TabContent({
|
|
167
|
+
lazy,
|
|
168
|
+
children,
|
|
169
|
+
selectedValue,
|
|
170
|
+
}: TabProps & ReturnType<typeof useTabs>): React.JSX.Element | null {
|
|
171
|
+
const childTabs = (Array.isArray(children) ? children : [children]).filter(
|
|
172
|
+
Boolean
|
|
173
|
+
) as ReactElement<TabItemProps>[];
|
|
174
|
+
if (lazy) {
|
|
175
|
+
const selectedTabItem = childTabs.find(
|
|
176
|
+
(tabItem) => tabItem.props.value === selectedValue
|
|
177
|
+
);
|
|
178
|
+
if (!selectedTabItem) {
|
|
179
|
+
// fail-safe or fail-fast? not sure what's best here
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
return cloneElement(selectedTabItem, { className: "margin-top--md" });
|
|
183
|
+
}
|
|
184
|
+
return (
|
|
185
|
+
<div className="margin-top--md">
|
|
186
|
+
{childTabs.map((tabItem, i) =>
|
|
187
|
+
cloneElement(tabItem, {
|
|
188
|
+
key: i,
|
|
189
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
190
|
+
})
|
|
191
|
+
)}
|
|
192
|
+
</div>
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
function TabsComponent(props: TabProps): React.JSX.Element {
|
|
196
|
+
const tabs = useTabs(props);
|
|
197
|
+
return (
|
|
198
|
+
<div className="tabs-container">
|
|
199
|
+
<TabList {...props} {...tabs} />
|
|
200
|
+
<TabContent {...props} {...tabs} />
|
|
201
|
+
</div>
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
export default function OperationTabs(props: TabProps): React.JSX.Element {
|
|
205
|
+
const isBrowser = useIsBrowser();
|
|
206
|
+
return (
|
|
207
|
+
<TabsComponent
|
|
208
|
+
// Remount tabs after hydration
|
|
209
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
210
|
+
key={String(isBrowser)}
|
|
211
|
+
{...props}
|
|
212
|
+
>
|
|
213
|
+
{sanitizeTabsChildren(props.children)}
|
|
214
|
+
</TabsComponent>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
@@ -10,24 +10,38 @@ import React from "react";
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
11
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
12
12
|
import TabItem from "@theme/TabItem";
|
|
13
|
-
/* eslint-disable import/no-extraneous-dependencies*/
|
|
14
|
-
import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
|
|
15
|
-
/* eslint-disable import/no-extraneous-dependencies*/
|
|
16
|
-
import {
|
|
17
|
-
getQualifierMessage,
|
|
18
|
-
getSchemaName,
|
|
19
|
-
} from "docusaurus-theme-openapi-docs/lib/markdown/schema";
|
|
20
|
-
/* eslint-disable import/no-extraneous-dependencies*/
|
|
21
|
-
import {
|
|
22
|
-
guard,
|
|
23
|
-
toString,
|
|
24
|
-
} from "docusaurus-theme-openapi-docs/lib/markdown/utils";
|
|
25
13
|
import ReactMarkdown from "react-markdown";
|
|
26
14
|
import rehypeRaw from "rehype-raw";
|
|
27
15
|
|
|
16
|
+
import { createDescription } from "../../markdown/createDescription";
|
|
17
|
+
import { getQualifierMessage, getSchemaName } from "../../markdown/schema";
|
|
18
|
+
import { guard, toString } from "../../markdown/utils";
|
|
19
|
+
|
|
20
|
+
interface Map<T> {
|
|
21
|
+
[key: string]: T;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface ExampleObject {
|
|
25
|
+
summary?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
value?: any;
|
|
28
|
+
externalValue?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Props {
|
|
32
|
+
param: {
|
|
33
|
+
description: string;
|
|
34
|
+
example: any;
|
|
35
|
+
examples: Map<ExampleObject>;
|
|
36
|
+
name: string;
|
|
37
|
+
required: boolean;
|
|
38
|
+
schema: any;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
28
42
|
function ParamsItem({
|
|
29
43
|
param: { description, example, examples, name, required, schema },
|
|
30
|
-
}) {
|
|
44
|
+
}: Props) {
|
|
31
45
|
if (!schema || !schema?.type) {
|
|
32
46
|
schema = { type: "any" };
|
|
33
47
|
}
|
|
@@ -97,6 +111,7 @@ function ParamsItem({
|
|
|
97
111
|
<strong>Examples:</strong>
|
|
98
112
|
<SchemaTabs>
|
|
99
113
|
{exampleEntries.map(([exampleName, exampleProperties]) => (
|
|
114
|
+
// @ts-ignore
|
|
100
115
|
<TabItem value={exampleName} label={exampleName}>
|
|
101
116
|
{exampleProperties.summary && <p>{exampleProperties.summary}</p>}
|
|
102
117
|
{exampleProperties.description && (
|
|
@@ -8,8 +8,17 @@
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
|
+
import { Language } from "prism-react-renderer";
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
export interface Props {
|
|
14
|
+
readonly responseExample: string;
|
|
15
|
+
readonly language: Language;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ResponseSamples({
|
|
19
|
+
responseExample,
|
|
20
|
+
language,
|
|
21
|
+
}: Props): React.JSX.Element {
|
|
13
22
|
return (
|
|
14
23
|
<div className="openapi-code__response-samples-container">
|
|
15
24
|
<CodeBlock language={language ? language : "json"}>
|
|
@@ -5,18 +5,29 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React from "react";
|
|
8
|
+
import React, { ReactNode } from "react";
|
|
9
9
|
|
|
10
10
|
import CodeBlock from "@theme/CodeBlock";
|
|
11
|
-
/* eslint-disable import/no-extraneous-dependencies*/
|
|
12
11
|
import clsx from "clsx";
|
|
13
|
-
import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
|
|
14
|
-
/* eslint-disable import/no-extraneous-dependencies*/
|
|
15
|
-
import { guard } from "docusaurus-theme-openapi-docs/lib/markdown/utils";
|
|
16
12
|
import ReactMarkdown from "react-markdown";
|
|
17
13
|
import rehypeRaw from "rehype-raw";
|
|
18
14
|
|
|
19
|
-
|
|
15
|
+
import { createDescription } from "../../markdown/createDescription";
|
|
16
|
+
import { guard } from "../../markdown/utils";
|
|
17
|
+
|
|
18
|
+
export interface Props {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
collapsible: boolean;
|
|
21
|
+
name: string;
|
|
22
|
+
qualifierMessage: string | undefined;
|
|
23
|
+
required: boolean;
|
|
24
|
+
schemaName: string;
|
|
25
|
+
// TODO should probably be typed
|
|
26
|
+
schema: any;
|
|
27
|
+
discriminator: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default function SchemaItem({
|
|
20
31
|
children: collapsibleSchemaContent,
|
|
21
32
|
collapsible,
|
|
22
33
|
name,
|
|
@@ -24,7 +35,7 @@ function SchemaItem({
|
|
|
24
35
|
required,
|
|
25
36
|
schemaName,
|
|
26
37
|
schema,
|
|
27
|
-
}) {
|
|
38
|
+
}: Props) {
|
|
28
39
|
let deprecated;
|
|
29
40
|
let schemaDescription;
|
|
30
41
|
let defaultValue;
|
|
@@ -119,5 +130,3 @@ function SchemaItem({
|
|
|
119
130
|
</div>
|
|
120
131
|
);
|
|
121
132
|
}
|
|
122
|
-
|
|
123
|
-
export default SchemaItem;
|
|
@@ -5,31 +5,55 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React, {
|
|
8
|
+
import React, {
|
|
9
|
+
cloneElement,
|
|
10
|
+
useRef,
|
|
11
|
+
useEffect,
|
|
12
|
+
useState,
|
|
13
|
+
ReactElement,
|
|
14
|
+
} from "react";
|
|
9
15
|
|
|
10
16
|
import {
|
|
17
|
+
sanitizeTabsChildren,
|
|
18
|
+
TabProps,
|
|
11
19
|
useScrollPositionBlocker,
|
|
12
20
|
useTabs,
|
|
13
21
|
} from "@docusaurus/theme-common/internal";
|
|
22
|
+
import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
|
|
14
23
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
15
24
|
import clsx from "clsx";
|
|
16
25
|
import flatten from "lodash/flatten";
|
|
17
26
|
|
|
18
|
-
function TabList({
|
|
19
|
-
|
|
27
|
+
function TabList({
|
|
28
|
+
className,
|
|
29
|
+
block,
|
|
30
|
+
selectedValue,
|
|
31
|
+
selectValue,
|
|
32
|
+
tabValues,
|
|
33
|
+
}: TabProps & ReturnType<typeof useTabs>) {
|
|
34
|
+
const tabRefs: (HTMLLIElement | null)[] = [];
|
|
20
35
|
const { blockElementScrollPositionUntilNextRender } =
|
|
21
36
|
useScrollPositionBlocker();
|
|
22
|
-
|
|
37
|
+
|
|
38
|
+
const handleTabChange = (
|
|
39
|
+
event:
|
|
40
|
+
| React.FocusEvent<HTMLLIElement>
|
|
41
|
+
| React.MouseEvent<HTMLLIElement>
|
|
42
|
+
| React.KeyboardEvent<HTMLLIElement>
|
|
43
|
+
) => {
|
|
23
44
|
const newTab = event.currentTarget;
|
|
24
45
|
const newTabIndex = tabRefs.indexOf(newTab);
|
|
25
46
|
const newTabValue = tabValues[newTabIndex].value;
|
|
47
|
+
|
|
26
48
|
if (newTabValue !== selectedValue) {
|
|
27
49
|
blockElementScrollPositionUntilNextRender(newTab);
|
|
28
50
|
selectValue(newTabValue);
|
|
29
51
|
}
|
|
30
52
|
};
|
|
31
|
-
|
|
32
|
-
|
|
53
|
+
|
|
54
|
+
const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
|
|
55
|
+
let focusElement: HTMLLIElement | null = null;
|
|
56
|
+
|
|
33
57
|
switch (event.key) {
|
|
34
58
|
case "Enter": {
|
|
35
59
|
handleTabChange(event);
|
|
@@ -37,27 +61,28 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
37
61
|
}
|
|
38
62
|
case "ArrowRight": {
|
|
39
63
|
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
40
|
-
focusElement = tabRefs[nextTab] ?? tabRefs[0]
|
|
64
|
+
focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
|
|
41
65
|
break;
|
|
42
66
|
}
|
|
43
67
|
case "ArrowLeft": {
|
|
44
68
|
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
45
|
-
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]
|
|
69
|
+
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
|
|
46
70
|
break;
|
|
47
71
|
}
|
|
48
72
|
default:
|
|
49
73
|
break;
|
|
50
74
|
}
|
|
75
|
+
|
|
51
76
|
focusElement?.focus();
|
|
52
77
|
};
|
|
53
78
|
|
|
54
|
-
const tabItemListContainerRef = useRef(null);
|
|
55
|
-
const [showTabArrows, setShowTabArrows] = useState(false);
|
|
79
|
+
const tabItemListContainerRef = useRef<HTMLUListElement>(null);
|
|
80
|
+
const [showTabArrows, setShowTabArrows] = useState<boolean>(false);
|
|
56
81
|
|
|
57
82
|
useEffect(() => {
|
|
58
83
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
59
84
|
for (let entry of entries) {
|
|
60
|
-
if (entry.target.
|
|
85
|
+
if (entry.target.clientWidth < entry.target.scrollWidth) {
|
|
61
86
|
setShowTabArrows(true);
|
|
62
87
|
} else {
|
|
63
88
|
setShowTabArrows(false);
|
|
@@ -65,7 +90,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
65
90
|
}
|
|
66
91
|
});
|
|
67
92
|
|
|
68
|
-
resizeObserver.observe(tabItemListContainerRef.current);
|
|
93
|
+
resizeObserver.observe(tabItemListContainerRef.current!);
|
|
69
94
|
|
|
70
95
|
return () => {
|
|
71
96
|
resizeObserver.disconnect();
|
|
@@ -73,11 +98,11 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
73
98
|
}, []);
|
|
74
99
|
|
|
75
100
|
const handleRightClick = () => {
|
|
76
|
-
tabItemListContainerRef.current
|
|
101
|
+
tabItemListContainerRef.current!.scrollLeft += 90;
|
|
77
102
|
};
|
|
78
103
|
|
|
79
104
|
const handleLeftClick = () => {
|
|
80
|
-
tabItemListContainerRef.current
|
|
105
|
+
tabItemListContainerRef.current!.scrollLeft -= 90;
|
|
81
106
|
};
|
|
82
107
|
|
|
83
108
|
return (
|
|
@@ -115,7 +140,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
115
140
|
className={clsx(
|
|
116
141
|
"tabs__item",
|
|
117
142
|
"openapi-tabs__schema-item",
|
|
118
|
-
attributes?.className,
|
|
143
|
+
attributes?.className as string,
|
|
119
144
|
{
|
|
120
145
|
active: selectedValue === value,
|
|
121
146
|
}
|
|
@@ -134,13 +159,17 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
134
159
|
</div>
|
|
135
160
|
);
|
|
136
161
|
}
|
|
137
|
-
function TabContent({
|
|
138
|
-
|
|
139
|
-
children
|
|
140
|
-
|
|
141
|
-
|
|
162
|
+
function TabContent({
|
|
163
|
+
lazy,
|
|
164
|
+
children,
|
|
165
|
+
selectedValue,
|
|
166
|
+
}: TabProps & ReturnType<typeof useTabs>) {
|
|
167
|
+
const childTabs = (Array.isArray(children) ? children : [children]).filter(
|
|
168
|
+
Boolean
|
|
169
|
+
) as ReactElement<TabItemProps>[];
|
|
170
|
+
const flattenedChildTabs = flatten(childTabs);
|
|
142
171
|
if (lazy) {
|
|
143
|
-
const selectedTabItem =
|
|
172
|
+
const selectedTabItem = flattenedChildTabs.find(
|
|
144
173
|
(tabItem) => tabItem.props.value === selectedValue
|
|
145
174
|
);
|
|
146
175
|
if (!selectedTabItem) {
|
|
@@ -151,7 +180,7 @@ function TabContent({ lazy, children, selectedValue }) {
|
|
|
151
180
|
}
|
|
152
181
|
return (
|
|
153
182
|
<div className="margin-top--md">
|
|
154
|
-
{
|
|
183
|
+
{childTabs.map((tabItem, i) =>
|
|
155
184
|
cloneElement(tabItem, {
|
|
156
185
|
key: i,
|
|
157
186
|
hidden: tabItem.props.value !== selectedValue,
|
|
@@ -160,7 +189,7 @@ function TabContent({ lazy, children, selectedValue }) {
|
|
|
160
189
|
</div>
|
|
161
190
|
);
|
|
162
191
|
}
|
|
163
|
-
function TabsComponent(props) {
|
|
192
|
+
function TabsComponent(props: TabProps): React.JSX.Element {
|
|
164
193
|
const tabs = useTabs(props);
|
|
165
194
|
return (
|
|
166
195
|
<div className="openapi-tabs__schema-container">
|
|
@@ -169,7 +198,7 @@ function TabsComponent(props) {
|
|
|
169
198
|
</div>
|
|
170
199
|
);
|
|
171
200
|
}
|
|
172
|
-
export default function SchemaTabs(props) {
|
|
201
|
+
export default function SchemaTabs(props: TabProps): React.JSX.Element {
|
|
173
202
|
const isBrowser = useIsBrowser();
|
|
174
203
|
return (
|
|
175
204
|
<TabsComponent
|
|
@@ -177,6 +206,8 @@ export default function SchemaTabs(props) {
|
|
|
177
206
|
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
178
207
|
key={String(isBrowser)}
|
|
179
208
|
{...props}
|
|
180
|
-
|
|
209
|
+
>
|
|
210
|
+
{sanitizeTabsChildren(props.children)}
|
|
211
|
+
</TabsComponent>
|
|
181
212
|
);
|
|
182
213
|
}
|
package/src/theme/styles.scss
CHANGED
package/src/theme-classic.d.ts
CHANGED
|
@@ -8,6 +8,73 @@
|
|
|
8
8
|
/// <reference types="@docusaurus/theme-classic" />
|
|
9
9
|
|
|
10
10
|
declare module "@docusaurus/theme-common/internal" {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import { CSSProperties, ReactNode, RefObject } from "react";
|
|
12
|
+
|
|
13
|
+
import type { PropDocContent } from "@docusaurus/plugin-content-docs";
|
|
14
|
+
import { MagicCommentConfig } from "@docusaurus/theme-common/lib/utils/codeBlockUtils";
|
|
15
|
+
import {
|
|
16
|
+
TabsProps as ITabsProps,
|
|
17
|
+
TabValue,
|
|
18
|
+
} from "@docusaurus/theme-common/lib/utils/tabsUtils";
|
|
19
|
+
import { Props as ICodeBlockProps } from "@theme/CodeBlock";
|
|
20
|
+
import { Props as ICopyButtonProps } from "@theme/CodeBlock/CopyButton";
|
|
21
|
+
import { Props as ILineProps } from "@theme/CodeBlock/Line";
|
|
22
|
+
import { PrismTheme } from "prism-react-renderer";
|
|
23
|
+
|
|
24
|
+
export interface TabProps extends ITabsProps {}
|
|
25
|
+
|
|
26
|
+
export interface CopyButtonProps extends ICopyButtonProps {}
|
|
27
|
+
export interface LineProps extends ILineProps {}
|
|
28
|
+
export interface CodeBlockProps extends ICodeBlockProps {}
|
|
29
|
+
|
|
30
|
+
export function useDoc();
|
|
31
|
+
|
|
32
|
+
export function usePrismTheme(): PrismTheme;
|
|
33
|
+
|
|
34
|
+
export function sanitizeTabsChildren(children: TabProps["children"]);
|
|
35
|
+
|
|
36
|
+
export function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties;
|
|
37
|
+
|
|
38
|
+
export function parseCodeBlockTitle(metastring?: string): string;
|
|
39
|
+
|
|
40
|
+
export function parseLanguage(className: string): string | undefined;
|
|
41
|
+
|
|
42
|
+
export function containsLineNumbers(metastring?: string): boolean;
|
|
43
|
+
|
|
44
|
+
export function useScrollPositionBlocker(): {
|
|
45
|
+
blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export function DocProvider({
|
|
49
|
+
children,
|
|
50
|
+
content,
|
|
51
|
+
}: {
|
|
52
|
+
children: ReactNode;
|
|
53
|
+
content: PropDocContent;
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
export function useTabs(props: TabProps): {
|
|
57
|
+
selectedValue: string;
|
|
58
|
+
selectValue: (value: string) => void;
|
|
59
|
+
tabValues: readonly TabValue[];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export function parseLines(
|
|
63
|
+
content: string,
|
|
64
|
+
options: {
|
|
65
|
+
metastring: string | undefined;
|
|
66
|
+
language: string | undefined;
|
|
67
|
+
magicComments: MagicCommentConfig[];
|
|
68
|
+
}
|
|
69
|
+
): {
|
|
70
|
+
lineClassNames: { [lineIndex: number]: string[] };
|
|
71
|
+
code: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export function useCodeWordWrap(): {
|
|
75
|
+
readonly codeBlockRef: RefObject<HTMLPreElement>;
|
|
76
|
+
readonly isEnabled: boolean;
|
|
77
|
+
readonly isCodeScrollable: boolean;
|
|
78
|
+
readonly toggle: () => void;
|
|
79
|
+
};
|
|
13
80
|
}
|
package/src/theme-openapi.d.ts
CHANGED
|
@@ -65,6 +65,10 @@ declare module "@theme/SchemaTabs" {
|
|
|
65
65
|
export default function SchemaTabs(props: any): JSX.Element;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
declare module "@theme/Markdown" {
|
|
69
|
+
export default function Markdown(props: any): JSX.Element;
|
|
70
|
+
}
|
|
71
|
+
|
|
68
72
|
declare module "@theme/ApiExplorer/Accept" {
|
|
69
73
|
export default function Accept(): JSX.Element;
|
|
70
74
|
}
|