docusaurus-theme-openapi-docs 0.0.0-845 → 0.0.0-852
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.
|
@@ -72,18 +72,29 @@ function TabList({
|
|
|
72
72
|
tabValues,
|
|
73
73
|
}) {
|
|
74
74
|
const tabRefs = (0, react_1.useRef)([]);
|
|
75
|
+
const tabsScrollContainerRef = (0, react_1.useRef)();
|
|
75
76
|
const { blockElementScrollPositionUntilNextRender } = (0,
|
|
76
77
|
internal_1.useScrollPositionBlocker)();
|
|
77
78
|
(0, react_1.useEffect)(() => {
|
|
78
79
|
const activeTab = tabRefs.current.find(
|
|
79
80
|
(tab) => tab?.getAttribute("aria-selected") === "true"
|
|
80
81
|
);
|
|
81
|
-
if (activeTab) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
if (activeTab && tabsScrollContainerRef.current) {
|
|
83
|
+
const container = tabsScrollContainerRef.current;
|
|
84
|
+
const containerRect = container.getBoundingClientRect();
|
|
85
|
+
const activeTabRect = activeTab.getBoundingClientRect();
|
|
86
|
+
// Calculate the distance to scroll to align active tab to the left
|
|
87
|
+
const glowOffset = 3;
|
|
88
|
+
const scrollOffset =
|
|
89
|
+
activeTabRect.left -
|
|
90
|
+
containerRect.left +
|
|
91
|
+
container.scrollLeft -
|
|
92
|
+
glowOffset;
|
|
93
|
+
// Check if the active tab is not already at the left position
|
|
94
|
+
if (Math.abs(scrollOffset - container.scrollLeft) > 4) {
|
|
95
|
+
// Adjust the scroll of the container
|
|
96
|
+
container.scrollLeft = scrollOffset;
|
|
97
|
+
}
|
|
87
98
|
}
|
|
88
99
|
}, []);
|
|
89
100
|
const handleTabChange = (event) => {
|
|
@@ -155,6 +166,7 @@ function TabList({
|
|
|
155
166
|
},
|
|
156
167
|
className
|
|
157
168
|
),
|
|
169
|
+
ref: tabsScrollContainerRef,
|
|
158
170
|
},
|
|
159
171
|
tabValues.map(({ value, label, attributes }) =>
|
|
160
172
|
react_1.default.createElement(
|
|
@@ -51,6 +51,7 @@ function SchemaItem(props) {
|
|
|
51
51
|
let deprecated;
|
|
52
52
|
let schemaDescription;
|
|
53
53
|
let defaultValue;
|
|
54
|
+
let example;
|
|
54
55
|
let nullable;
|
|
55
56
|
let enumDescriptions = [];
|
|
56
57
|
if (schema) {
|
|
@@ -58,6 +59,7 @@ function SchemaItem(props) {
|
|
|
58
59
|
schemaDescription = schema.description;
|
|
59
60
|
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
60
61
|
defaultValue = schema.default;
|
|
62
|
+
example = schema.example;
|
|
61
63
|
nullable = schema.nullable;
|
|
62
64
|
}
|
|
63
65
|
const renderRequired = (0, utils_1.guard)(
|
|
@@ -167,6 +169,33 @@ function SchemaItem(props) {
|
|
|
167
169
|
}
|
|
168
170
|
return undefined;
|
|
169
171
|
}
|
|
172
|
+
function renderExample() {
|
|
173
|
+
if (example !== undefined) {
|
|
174
|
+
if (typeof example === "string") {
|
|
175
|
+
return react_1.default.createElement(
|
|
176
|
+
"div",
|
|
177
|
+
null,
|
|
178
|
+
react_1.default.createElement("strong", null, "Example: "),
|
|
179
|
+
react_1.default.createElement(
|
|
180
|
+
"span",
|
|
181
|
+
null,
|
|
182
|
+
react_1.default.createElement("code", null, example)
|
|
183
|
+
)
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
return react_1.default.createElement(
|
|
187
|
+
"div",
|
|
188
|
+
null,
|
|
189
|
+
react_1.default.createElement("strong", null, "Example: "),
|
|
190
|
+
react_1.default.createElement(
|
|
191
|
+
"span",
|
|
192
|
+
null,
|
|
193
|
+
react_1.default.createElement("code", null, JSON.stringify(example))
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
170
199
|
const schemaContent = react_1.default.createElement(
|
|
171
200
|
"div",
|
|
172
201
|
null,
|
|
@@ -200,6 +229,7 @@ function SchemaItem(props) {
|
|
|
200
229
|
renderEnumDescriptions,
|
|
201
230
|
renderQualifierMessage,
|
|
202
231
|
renderDefaultValue(),
|
|
232
|
+
renderExample(),
|
|
203
233
|
collapsibleSchemaContent ?? collapsibleSchemaContent
|
|
204
234
|
);
|
|
205
235
|
return react_1.default.createElement(
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "docusaurus-theme-openapi-docs",
|
|
3
3
|
"description": "OpenAPI theme for Docusaurus.",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-852",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"clsx": "^1.1.1",
|
|
43
43
|
"copy-text-to-clipboard": "^3.1.0",
|
|
44
44
|
"crypto-js": "^4.1.1",
|
|
45
|
-
"docusaurus-plugin-openapi-docs": "0.0.0-
|
|
45
|
+
"docusaurus-plugin-openapi-docs": "0.0.0-852",
|
|
46
46
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
47
47
|
"file-saver": "^2.0.5",
|
|
48
48
|
"lodash": "^4.17.20",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"engines": {
|
|
71
71
|
"node": ">=14"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "a352f9c4ce4e9fb46044d7cba30c132aaa81518f"
|
|
74
74
|
}
|
|
@@ -44,6 +44,7 @@ function TabList({
|
|
|
44
44
|
tabValues,
|
|
45
45
|
}: CodeTabsProps & ReturnType<typeof useTabs>) {
|
|
46
46
|
const tabRefs = useRef<(HTMLLIElement | null)[]>([]);
|
|
47
|
+
const tabsScrollContainerRef = useRef<any>();
|
|
47
48
|
const { blockElementScrollPositionUntilNextRender } =
|
|
48
49
|
useScrollPositionBlocker();
|
|
49
50
|
|
|
@@ -51,12 +52,26 @@ function TabList({
|
|
|
51
52
|
const activeTab = tabRefs.current.find(
|
|
52
53
|
(tab) => tab?.getAttribute("aria-selected") === "true"
|
|
53
54
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
|
|
56
|
+
if (activeTab && tabsScrollContainerRef.current) {
|
|
57
|
+
const container = tabsScrollContainerRef.current;
|
|
58
|
+
const containerRect = container.getBoundingClientRect();
|
|
59
|
+
const activeTabRect = activeTab.getBoundingClientRect();
|
|
60
|
+
|
|
61
|
+
// Calculate the distance to scroll to align active tab to the left
|
|
62
|
+
const glowOffset = 3;
|
|
63
|
+
const scrollOffset =
|
|
64
|
+
activeTabRect.left -
|
|
65
|
+
containerRect.left +
|
|
66
|
+
container.scrollLeft -
|
|
67
|
+
glowOffset;
|
|
68
|
+
|
|
69
|
+
// Check if the active tab is not already at the left position
|
|
70
|
+
|
|
71
|
+
if (Math.abs(scrollOffset - container.scrollLeft) > 4) {
|
|
72
|
+
// Adjust the scroll of the container
|
|
73
|
+
container.scrollLeft = scrollOffset;
|
|
74
|
+
}
|
|
60
75
|
}
|
|
61
76
|
}, []);
|
|
62
77
|
|
|
@@ -139,6 +154,7 @@ function TabList({
|
|
|
139
154
|
},
|
|
140
155
|
className
|
|
141
156
|
)}
|
|
157
|
+
ref={tabsScrollContainerRef}
|
|
142
158
|
>
|
|
143
159
|
{tabValues.map(({ value, label, attributes }) => (
|
|
144
160
|
<li
|
|
@@ -66,6 +66,7 @@ export default function SchemaItem(props: Props) {
|
|
|
66
66
|
let deprecated;
|
|
67
67
|
let schemaDescription;
|
|
68
68
|
let defaultValue: string | undefined;
|
|
69
|
+
let example: string | undefined;
|
|
69
70
|
let nullable;
|
|
70
71
|
let enumDescriptions: [string, string][] = [];
|
|
71
72
|
|
|
@@ -74,6 +75,7 @@ export default function SchemaItem(props: Props) {
|
|
|
74
75
|
schemaDescription = schema.description;
|
|
75
76
|
enumDescriptions = transformEnumDescriptions(schema["x-enumDescriptions"]);
|
|
76
77
|
defaultValue = schema.default;
|
|
78
|
+
example = schema.example;
|
|
77
79
|
nullable = schema.nullable;
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -157,6 +159,30 @@ export default function SchemaItem(props: Props) {
|
|
|
157
159
|
return undefined;
|
|
158
160
|
}
|
|
159
161
|
|
|
162
|
+
function renderExample() {
|
|
163
|
+
if (example !== undefined) {
|
|
164
|
+
if (typeof example === "string") {
|
|
165
|
+
return (
|
|
166
|
+
<div>
|
|
167
|
+
<strong>Example: </strong>
|
|
168
|
+
<span>
|
|
169
|
+
<code>{example}</code>
|
|
170
|
+
</span>
|
|
171
|
+
</div>
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
return (
|
|
175
|
+
<div>
|
|
176
|
+
<strong>Example: </strong>
|
|
177
|
+
<span>
|
|
178
|
+
<code>{JSON.stringify(example)}</code>
|
|
179
|
+
</span>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
160
186
|
const schemaContent = (
|
|
161
187
|
<div>
|
|
162
188
|
<span className="openapi-schema__container">
|
|
@@ -179,6 +205,7 @@ export default function SchemaItem(props: Props) {
|
|
|
179
205
|
{renderEnumDescriptions}
|
|
180
206
|
{renderQualifierMessage}
|
|
181
207
|
{renderDefaultValue()}
|
|
208
|
+
{renderExample()}
|
|
182
209
|
{collapsibleSchemaContent ?? collapsibleSchemaContent}
|
|
183
210
|
</div>
|
|
184
211
|
);
|