docusaurus-theme-openapi-docs 3.0.0-beta.3 → 3.0.0-beta.4
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/CodeSnippets/index.d.ts +2 -2
- package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +11 -0
- package/lib/theme/ApiExplorer/CodeTabs/index.js +125 -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/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 +3 -0
- package/lib/theme/ApiTabs/index.js +146 -96
- package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
- package/lib/theme/DiscriminatorTabs/index.js +146 -94
- package/lib/theme/MimeTabs/index.d.ts +6 -0
- package/lib/theme/MimeTabs/index.js +163 -114
- 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/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/CodeTabs/{index.js → index.tsx} +48 -25
- package/src/theme/ApiItem/index.tsx +3 -4
- package/src/theme/ApiLogo/index.tsx +1 -1
- package/src/theme/ApiTabs/{index.js → index.tsx} +54 -23
- package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
- package/src/theme/MimeTabs/{index.js → index.tsx} +58 -26
- 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-classic.d.ts +69 -2
- package/tsconfig.json +4 -1
|
@@ -1,24 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/* ============================================================================
|
|
2
3
|
* Copyright (c) Palo Alto Networks
|
|
3
4
|
*
|
|
4
5
|
* This source code is licensed under the MIT license found in the
|
|
5
6
|
* LICENSE file in the root directory of this source tree.
|
|
6
7
|
* ========================================================================== */
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
var __createBinding =
|
|
9
|
+
(this && this.__createBinding) ||
|
|
10
|
+
(Object.create
|
|
11
|
+
? function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (
|
|
15
|
+
!desc ||
|
|
16
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
17
|
+
) {
|
|
18
|
+
desc = {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return m[k];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}
|
|
27
|
+
: function (o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
});
|
|
31
|
+
var __setModuleDefault =
|
|
32
|
+
(this && this.__setModuleDefault) ||
|
|
33
|
+
(Object.create
|
|
34
|
+
? function (o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}
|
|
37
|
+
: function (o, v) {
|
|
38
|
+
o["default"] = v;
|
|
39
|
+
});
|
|
40
|
+
var __importStar =
|
|
41
|
+
(this && this.__importStar) ||
|
|
42
|
+
function (mod) {
|
|
43
|
+
if (mod && mod.__esModule) return mod;
|
|
44
|
+
var result = {};
|
|
45
|
+
if (mod != null)
|
|
46
|
+
for (var k in mod)
|
|
47
|
+
if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
|
|
48
|
+
__createBinding(result, mod, k);
|
|
49
|
+
__setModuleDefault(result, mod);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
var __importDefault =
|
|
53
|
+
(this && this.__importDefault) ||
|
|
54
|
+
function (mod) {
|
|
55
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
+
const react_1 = __importStar(require("react"));
|
|
59
|
+
const internal_1 = require("@docusaurus/theme-common/internal");
|
|
60
|
+
const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
|
|
61
|
+
const clsx_1 = __importDefault(require("clsx"));
|
|
62
|
+
const flatten_1 = __importDefault(require("lodash/flatten"));
|
|
18
63
|
function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
19
64
|
const tabRefs = [];
|
|
20
|
-
const { blockElementScrollPositionUntilNextRender } =
|
|
21
|
-
|
|
65
|
+
const { blockElementScrollPositionUntilNextRender } = (0,
|
|
66
|
+
internal_1.useScrollPositionBlocker)();
|
|
22
67
|
const handleTabChange = (event) => {
|
|
23
68
|
const newTab = event.currentTarget;
|
|
24
69
|
const newTabIndex = tabRefs.indexOf(newTab);
|
|
@@ -50,133 +95,139 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
|
|
|
50
95
|
}
|
|
51
96
|
focusElement?.focus();
|
|
52
97
|
};
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
98
|
+
const tabItemListContainerRef = (0, react_1.useRef)(null);
|
|
99
|
+
const [showTabArrows, setShowTabArrows] = (0, react_1.useState)(false);
|
|
100
|
+
(0, react_1.useEffect)(() => {
|
|
58
101
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
59
102
|
for (let entry of entries) {
|
|
60
|
-
if (entry.target.
|
|
103
|
+
if (entry.target.clientWidth < entry.target.scrollWidth) {
|
|
61
104
|
setShowTabArrows(true);
|
|
62
105
|
} else {
|
|
63
106
|
setShowTabArrows(false);
|
|
64
107
|
}
|
|
65
108
|
}
|
|
66
109
|
});
|
|
67
|
-
|
|
68
110
|
resizeObserver.observe(tabItemListContainerRef.current);
|
|
69
|
-
|
|
70
111
|
return () => {
|
|
71
112
|
resizeObserver.disconnect();
|
|
72
113
|
};
|
|
73
114
|
}, []);
|
|
74
|
-
|
|
75
115
|
const handleRightClick = () => {
|
|
76
116
|
tabItemListContainerRef.current.scrollLeft += 90;
|
|
77
117
|
};
|
|
78
|
-
|
|
79
118
|
const handleLeftClick = () => {
|
|
80
119
|
tabItemListContainerRef.current.scrollLeft -= 90;
|
|
81
120
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
121
|
+
return react_1.default.createElement(
|
|
122
|
+
"div",
|
|
123
|
+
{ className: "openapi-tabs__schema-tabs-container" },
|
|
124
|
+
showTabArrows &&
|
|
125
|
+
react_1.default.createElement("button", {
|
|
126
|
+
className: "openapi-tabs__arrow left",
|
|
127
|
+
onClick: handleLeftClick,
|
|
128
|
+
}),
|
|
129
|
+
react_1.default.createElement(
|
|
130
|
+
"ul",
|
|
131
|
+
{
|
|
132
|
+
ref: tabItemListContainerRef,
|
|
133
|
+
role: "tablist",
|
|
134
|
+
"aria-orientation": "horizontal",
|
|
135
|
+
className: (0, clsx_1.default)(
|
|
96
136
|
"openapi-tabs__schema-list-container",
|
|
97
137
|
"tabs",
|
|
98
138
|
{
|
|
99
139
|
"tabs--block": block,
|
|
100
140
|
},
|
|
101
141
|
className
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
142
|
+
),
|
|
143
|
+
},
|
|
144
|
+
tabValues.map(({ value, label, attributes }) =>
|
|
145
|
+
react_1.default.createElement(
|
|
146
|
+
"li",
|
|
147
|
+
{
|
|
106
148
|
// TODO extract TabListItem
|
|
107
|
-
role
|
|
108
|
-
tabIndex
|
|
109
|
-
aria-selected
|
|
110
|
-
key
|
|
111
|
-
ref
|
|
112
|
-
onKeyDown
|
|
113
|
-
onClick
|
|
114
|
-
|
|
115
|
-
className
|
|
149
|
+
role: "tab",
|
|
150
|
+
tabIndex: selectedValue === value ? 0 : -1,
|
|
151
|
+
"aria-selected": selectedValue === value,
|
|
152
|
+
key: value,
|
|
153
|
+
ref: (tabControl) => tabRefs.push(tabControl),
|
|
154
|
+
onKeyDown: handleKeydown,
|
|
155
|
+
onClick: handleTabChange,
|
|
156
|
+
...attributes,
|
|
157
|
+
className: (0, clsx_1.default)(
|
|
116
158
|
"tabs__item",
|
|
117
159
|
"openapi-tabs__schema-item",
|
|
118
160
|
attributes?.className,
|
|
119
161
|
{
|
|
120
162
|
active: selectedValue === value,
|
|
121
163
|
}
|
|
122
|
-
)
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
),
|
|
165
|
+
},
|
|
166
|
+
react_1.default.createElement(
|
|
167
|
+
"span",
|
|
168
|
+
{ className: "openapi-tabs__schema-label" },
|
|
169
|
+
label ?? value
|
|
170
|
+
)
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
),
|
|
174
|
+
showTabArrows &&
|
|
175
|
+
react_1.default.createElement("button", {
|
|
176
|
+
className: "openapi-tabs__arrow right",
|
|
177
|
+
onClick: handleRightClick,
|
|
178
|
+
})
|
|
135
179
|
);
|
|
136
180
|
}
|
|
137
181
|
function TabContent({ lazy, children, selectedValue }) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
182
|
+
const childTabs = (Array.isArray(children) ? children : [children]).filter(
|
|
183
|
+
Boolean
|
|
184
|
+
);
|
|
185
|
+
const flattenedChildTabs = (0, flatten_1.default)(childTabs);
|
|
142
186
|
if (lazy) {
|
|
143
|
-
const selectedTabItem =
|
|
187
|
+
const selectedTabItem = flattenedChildTabs.find(
|
|
144
188
|
(tabItem) => tabItem.props.value === selectedValue
|
|
145
189
|
);
|
|
146
190
|
if (!selectedTabItem) {
|
|
147
191
|
// fail-safe or fail-fast? not sure what's best here
|
|
148
192
|
return null;
|
|
149
193
|
}
|
|
150
|
-
return cloneElement(selectedTabItem, {
|
|
194
|
+
return (0, react_1.cloneElement)(selectedTabItem, {
|
|
195
|
+
className: "margin-top--md",
|
|
196
|
+
});
|
|
151
197
|
}
|
|
152
|
-
return (
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
|
|
198
|
+
return react_1.default.createElement(
|
|
199
|
+
"div",
|
|
200
|
+
{ className: "margin-top--md" },
|
|
201
|
+
childTabs.map((tabItem, i) =>
|
|
202
|
+
(0, react_1.cloneElement)(tabItem, {
|
|
203
|
+
key: i,
|
|
204
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
205
|
+
})
|
|
206
|
+
)
|
|
161
207
|
);
|
|
162
208
|
}
|
|
163
209
|
function TabsComponent(props) {
|
|
164
|
-
const tabs = useTabs(props);
|
|
165
|
-
return (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
210
|
+
const tabs = (0, internal_1.useTabs)(props);
|
|
211
|
+
return react_1.default.createElement(
|
|
212
|
+
"div",
|
|
213
|
+
{ className: "openapi-tabs__schema-container" },
|
|
214
|
+
react_1.default.createElement(TabList, { ...props, ...tabs }),
|
|
215
|
+
react_1.default.createElement(TabContent, { ...props, ...tabs })
|
|
170
216
|
);
|
|
171
217
|
}
|
|
172
|
-
|
|
173
|
-
const isBrowser =
|
|
174
|
-
return (
|
|
175
|
-
|
|
218
|
+
function SchemaTabs(props) {
|
|
219
|
+
const isBrowser = (0, useIsBrowser_1.default)();
|
|
220
|
+
return react_1.default.createElement(
|
|
221
|
+
TabsComponent,
|
|
222
|
+
// Remount tabs after hydration
|
|
223
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
224
|
+
{
|
|
176
225
|
// Remount tabs after hydration
|
|
177
226
|
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
178
|
-
key
|
|
179
|
-
|
|
180
|
-
|
|
227
|
+
key: String(isBrowser),
|
|
228
|
+
...props,
|
|
229
|
+
},
|
|
230
|
+
(0, internal_1.sanitizeTabsChildren)(props.children)
|
|
181
231
|
);
|
|
182
232
|
}
|
|
233
|
+
exports.default = SchemaTabs;
|
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": "3.0.0-beta.
|
|
4
|
+
"version": "3.0.0-beta.4",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"openapi",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"clsx": "^1.1.1",
|
|
45
45
|
"copy-text-to-clipboard": "^3.1.0",
|
|
46
46
|
"crypto-js": "^4.1.1",
|
|
47
|
-
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.
|
|
47
|
+
"docusaurus-plugin-openapi-docs": "^3.0.0-beta.4",
|
|
48
48
|
"docusaurus-plugin-sass": "^0.2.3",
|
|
49
49
|
"file-saver": "^2.0.5",
|
|
50
50
|
"lodash": "^4.17.20",
|
|
51
51
|
"node-polyfill-webpack-plugin": "^2.0.1",
|
|
52
|
-
"prism-react-renderer": "^2.
|
|
52
|
+
"prism-react-renderer": "^2.3.0",
|
|
53
53
|
"react-hook-form": "^7.43.8",
|
|
54
54
|
"react-live": "^4.0.0",
|
|
55
55
|
"react-magic-dropzone": "^1.0.1",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": ">=14"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "1207af7a96b5d5a033f87e4a94b94f9b263c1f36"
|
|
73
73
|
}
|
package/src/markdown/utils.ts
CHANGED
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
import { ReactNode } from "react";
|
|
9
|
+
|
|
10
|
+
export type Children = ReactNode | string | undefined | (string | undefined)[];
|
|
9
11
|
|
|
10
12
|
export type Props = Record<string, any> & { children?: Children };
|
|
11
13
|
|
|
@@ -35,7 +37,7 @@ export function render(children: Children): string {
|
|
|
35
37
|
if (Array.isArray(children)) {
|
|
36
38
|
return children.filter((c) => c !== undefined).join("");
|
|
37
39
|
}
|
|
38
|
-
return children ?? "";
|
|
40
|
+
return (children as string) ?? "";
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
export function toString(value: any): string | undefined {
|
|
@@ -9,14 +9,28 @@ import React, { useEffect } from "react";
|
|
|
9
9
|
|
|
10
10
|
import { usePrismTheme } from "@docusaurus/theme-common";
|
|
11
11
|
import { translate } from "@docusaurus/Translate";
|
|
12
|
-
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
import
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import Container from "@theme/ApiExplorer/ApiCodeBlock/Container";
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
import ExitButton from "@theme/ApiExplorer/ApiCodeBlock/ExitButton";
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
|
|
16
20
|
import clsx from "clsx";
|
|
17
|
-
import Highlight,
|
|
21
|
+
import { Highlight, type Language } from "prism-react-renderer";
|
|
18
22
|
import Modal from "react-modal";
|
|
19
23
|
|
|
24
|
+
interface Props {
|
|
25
|
+
code: string;
|
|
26
|
+
className: string;
|
|
27
|
+
language: Language;
|
|
28
|
+
showLineNumbers: boolean;
|
|
29
|
+
blockClassName: string;
|
|
30
|
+
title: string;
|
|
31
|
+
lineClassNames: string[];
|
|
32
|
+
}
|
|
33
|
+
|
|
20
34
|
export default function ExpandButton({
|
|
21
35
|
code,
|
|
22
36
|
className,
|
|
@@ -25,7 +39,7 @@ export default function ExpandButton({
|
|
|
25
39
|
blockClassName,
|
|
26
40
|
title,
|
|
27
41
|
lineClassNames,
|
|
28
|
-
}) {
|
|
42
|
+
}: Props): React.JSX.Element {
|
|
29
43
|
const prismTheme = usePrismTheme();
|
|
30
44
|
|
|
31
45
|
function openModal() {
|
|
@@ -111,7 +125,6 @@ export default function ExpandButton({
|
|
|
111
125
|
)}
|
|
112
126
|
<div className="openapi-explorer__code-block-content">
|
|
113
127
|
<Highlight
|
|
114
|
-
{...defaultProps}
|
|
115
128
|
theme={prismTheme}
|
|
116
129
|
code={code}
|
|
117
130
|
language={language ?? "text"}
|
|
@@ -139,7 +152,7 @@ export default function ExpandButton({
|
|
|
139
152
|
line={line}
|
|
140
153
|
getLineProps={getLineProps}
|
|
141
154
|
getTokenProps={getTokenProps}
|
|
142
|
-
classNames={lineClassNames
|
|
155
|
+
classNames={lineClassNames}
|
|
143
156
|
showLineNumbers={showLineNumbers}
|
|
144
157
|
/>
|
|
145
158
|
))}
|
|
@@ -5,19 +5,22 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React from "react";
|
|
8
|
+
import React, { ComponentProps } from "react";
|
|
9
9
|
|
|
10
10
|
import { ThemeClassNames, usePrismTheme } from "@docusaurus/theme-common";
|
|
11
11
|
import { getPrismCssVariables } from "@docusaurus/theme-common/internal";
|
|
12
12
|
import clsx from "clsx";
|
|
13
13
|
|
|
14
|
-
export default function CodeBlockContainer
|
|
14
|
+
export default function CodeBlockContainer<T extends "div" | "pre">({
|
|
15
|
+
as: As,
|
|
16
|
+
...props
|
|
17
|
+
}: { as: T } & ComponentProps<T>): React.JSX.Element {
|
|
15
18
|
const prismTheme = usePrismTheme();
|
|
16
19
|
const prismCssVariables = getPrismCssVariables(prismTheme);
|
|
17
20
|
return (
|
|
18
21
|
<As
|
|
19
22
|
// Polymorphic components are hard to type, without `oneOf` generics
|
|
20
|
-
{...props}
|
|
23
|
+
{...(props as any)}
|
|
21
24
|
style={prismCssVariables}
|
|
22
25
|
className={clsx(
|
|
23
26
|
"openapi-explorer__code-block-container",
|
|
@@ -8,12 +8,16 @@
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
10
|
import Container from "@theme/ApiExplorer/ApiCodeBlock/Container";
|
|
11
|
+
import type { Props } from "@theme/CodeBlock/Content/Element";
|
|
11
12
|
import clsx from "clsx";
|
|
12
13
|
|
|
13
14
|
// <pre> tags in markdown map to CodeBlocks. They may contain JSX children. When
|
|
14
15
|
// the children is not a simple string, we just return a styled block without
|
|
15
16
|
// actually highlighting.
|
|
16
|
-
export default function CodeBlockJSX({
|
|
17
|
+
export default function CodeBlockJSX({
|
|
18
|
+
children,
|
|
19
|
+
className,
|
|
20
|
+
}: Props): React.JSX.Element {
|
|
17
21
|
return (
|
|
18
22
|
<Container
|
|
19
23
|
as="pre"
|
|
@@ -20,8 +20,9 @@ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
|
|
|
20
20
|
import ExpandButton from "@theme/ApiExplorer/ApiCodeBlock/ExpandButton";
|
|
21
21
|
import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
|
|
22
22
|
import WordWrapButton from "@theme/ApiExplorer/ApiCodeBlock/WordWrapButton";
|
|
23
|
+
import type { Props } from "@theme/CodeBlock/Content/String";
|
|
23
24
|
import clsx from "clsx";
|
|
24
|
-
import { Highlight } from "prism-react-renderer";
|
|
25
|
+
import { Highlight, Language } from "prism-react-renderer";
|
|
25
26
|
|
|
26
27
|
export default function CodeBlockString({
|
|
27
28
|
children,
|
|
@@ -30,7 +31,7 @@ export default function CodeBlockString({
|
|
|
30
31
|
title: titleProp,
|
|
31
32
|
showLineNumbers: showLineNumbersProp,
|
|
32
33
|
language: languageProp,
|
|
33
|
-
}) {
|
|
34
|
+
}: Props): React.JSX.Element {
|
|
34
35
|
const {
|
|
35
36
|
prism: { defaultLanguage, magicComments },
|
|
36
37
|
} = useThemeConfig();
|
|
@@ -120,12 +121,11 @@ export default function CodeBlockString({
|
|
|
120
121
|
"openapi-explorer__expand-btn"
|
|
121
122
|
)}
|
|
122
123
|
code={code}
|
|
123
|
-
language={language}
|
|
124
|
+
language={(language ?? "text") as Language}
|
|
124
125
|
showLineNumbers={showLineNumbers}
|
|
125
126
|
blockClassName={blockClassName}
|
|
126
127
|
title={title}
|
|
127
128
|
lineClassNames={lineClassNames}
|
|
128
|
-
wordWrap={wordWrap}
|
|
129
129
|
/>
|
|
130
130
|
</div>
|
|
131
131
|
</div>
|
|
@@ -7,14 +7,17 @@
|
|
|
7
7
|
|
|
8
8
|
import React, { useCallback, useState, useRef, useEffect } from "react";
|
|
9
9
|
|
|
10
|
+
import { CopyButtonProps } from "@docusaurus/theme-common/internal";
|
|
10
11
|
import { translate } from "@docusaurus/Translate";
|
|
11
12
|
import clsx from "clsx";
|
|
12
|
-
// @ts-expect-error: TODO, we need to make theme-classic have type: module
|
|
13
13
|
import copy from "copy-text-to-clipboard";
|
|
14
14
|
|
|
15
|
-
export default function CopyButton({
|
|
15
|
+
export default function CopyButton({
|
|
16
|
+
code,
|
|
17
|
+
className,
|
|
18
|
+
}: CopyButtonProps): React.JSX.Element {
|
|
16
19
|
const [isCopied, setIsCopied] = useState(false);
|
|
17
|
-
const copyTimeout = useRef(undefined);
|
|
20
|
+
const copyTimeout = useRef<number | undefined>(undefined);
|
|
18
21
|
const handleCopyCode = useCallback(() => {
|
|
19
22
|
copy(code);
|
|
20
23
|
setIsCopied(true);
|
|
@@ -22,7 +25,9 @@ export default function CopyButton({ code, className }) {
|
|
|
22
25
|
setIsCopied(false);
|
|
23
26
|
}, 1000);
|
|
24
27
|
}, [code]);
|
|
28
|
+
|
|
25
29
|
useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
|
|
30
|
+
|
|
26
31
|
return (
|
|
27
32
|
<button
|
|
28
33
|
type="button"
|
|
@@ -10,7 +10,15 @@ import React from "react";
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
11
|
import clsx from "clsx";
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface Props {
|
|
14
|
+
readonly className: string;
|
|
15
|
+
readonly handler: () => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function ExitButton({
|
|
19
|
+
className,
|
|
20
|
+
handler,
|
|
21
|
+
}: Props): React.JSX.Element {
|
|
14
22
|
return (
|
|
15
23
|
<button
|
|
16
24
|
type="button"
|
|
@@ -14,9 +14,19 @@ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
|
|
|
14
14
|
import ExitButton from "@theme/ApiExplorer/ApiCodeBlock/ExitButton";
|
|
15
15
|
import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
|
|
16
16
|
import clsx from "clsx";
|
|
17
|
-
import { Highlight } from "prism-react-renderer";
|
|
17
|
+
import { Highlight, Language } from "prism-react-renderer";
|
|
18
18
|
import Modal from "react-modal";
|
|
19
19
|
|
|
20
|
+
export interface Props {
|
|
21
|
+
readonly code: string;
|
|
22
|
+
readonly className: string;
|
|
23
|
+
readonly language: Language;
|
|
24
|
+
readonly showLineNumbers: boolean;
|
|
25
|
+
readonly blockClassName: string;
|
|
26
|
+
readonly title: string | undefined;
|
|
27
|
+
readonly lineClassNames: { [lineIndex: number]: string[] };
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
export default function ExpandButton({
|
|
21
31
|
code,
|
|
22
32
|
className,
|
|
@@ -25,7 +35,7 @@ export default function ExpandButton({
|
|
|
25
35
|
blockClassName,
|
|
26
36
|
title,
|
|
27
37
|
lineClassNames,
|
|
28
|
-
}) {
|
|
38
|
+
}: Props): React.JSX.Element {
|
|
29
39
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
|
30
40
|
const prismTheme = usePrismTheme();
|
|
31
41
|
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import React from "react";
|
|
9
9
|
|
|
10
|
+
import { LineProps } from "@docusaurus/theme-common/internal";
|
|
10
11
|
import clsx from "clsx";
|
|
11
12
|
|
|
12
13
|
export default function CodeBlockLine({
|
|
@@ -15,7 +16,7 @@ export default function CodeBlockLine({
|
|
|
15
16
|
showLineNumbers,
|
|
16
17
|
getLineProps,
|
|
17
18
|
getTokenProps,
|
|
18
|
-
}) {
|
|
19
|
+
}: LineProps): React.JSX.Element {
|
|
19
20
|
if (line.length === 1 && line[0].content === "\n") {
|
|
20
21
|
line[0].content = "";
|
|
21
22
|
}
|
|
@@ -10,7 +10,17 @@ import React from "react";
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
11
|
import clsx from "clsx";
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export interface Props {
|
|
14
|
+
readonly className?: string;
|
|
15
|
+
readonly onClick: React.MouseEventHandler;
|
|
16
|
+
readonly isEnabled: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default function WordWrapButton({
|
|
20
|
+
className,
|
|
21
|
+
onClick,
|
|
22
|
+
isEnabled,
|
|
23
|
+
}: Props): React.JSX.Element | null {
|
|
14
24
|
const title = translate({
|
|
15
25
|
id: "theme.CodeBlock.wordWrapToggle",
|
|
16
26
|
message: "Toggle word wrap",
|
|
@@ -5,25 +5,30 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
import React, { isValidElement } from "react";
|
|
8
|
+
import React, { isValidElement, ReactNode } from "react";
|
|
9
9
|
|
|
10
|
+
import { CodeBlockProps } from "@docusaurus/theme-common/internal";
|
|
10
11
|
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
11
12
|
import ElementContent from "@theme/ApiExplorer/ApiCodeBlock/Content/Element";
|
|
12
13
|
import StringContent from "@theme/ApiExplorer/ApiCodeBlock/Content/String";
|
|
14
|
+
|
|
13
15
|
/**
|
|
14
16
|
* Best attempt to make the children a plain string so it is copyable. If there
|
|
15
17
|
* are react elements, we will not be able to copy the content, and it will
|
|
16
18
|
* return `children` as-is; otherwise, it concatenates the string children
|
|
17
19
|
* together.
|
|
18
20
|
*/
|
|
19
|
-
function maybeStringifyChildren(children) {
|
|
21
|
+
function maybeStringifyChildren(children: ReactNode): ReactNode {
|
|
20
22
|
if (React.Children.toArray(children).some((el) => isValidElement(el))) {
|
|
21
23
|
return children;
|
|
22
24
|
}
|
|
23
25
|
// The children is now guaranteed to be one/more plain strings
|
|
24
|
-
return Array.isArray(children) ? children.join("") : children;
|
|
26
|
+
return Array.isArray(children) ? children.join("") : (children as string);
|
|
25
27
|
}
|
|
26
|
-
export default function ApiCodeBlock({
|
|
28
|
+
export default function ApiCodeBlock({
|
|
29
|
+
children: rawChildren,
|
|
30
|
+
...props
|
|
31
|
+
}: CodeBlockProps) {
|
|
27
32
|
// The Prism theme on SSR is always the default theme but the site theme can
|
|
28
33
|
// be in a different mode. React hydration doesn't update DOM styles that come
|
|
29
34
|
// from SSR. Hence force a re-render after mounting to apply the current
|
|
@@ -34,7 +39,7 @@ export default function ApiCodeBlock({ children: rawChildren, ...props }) {
|
|
|
34
39
|
typeof children === "string" ? StringContent : ElementContent;
|
|
35
40
|
return (
|
|
36
41
|
<CodeBlockComp key={String(isBrowser)} {...props}>
|
|
37
|
-
{children}
|
|
42
|
+
{children as string}
|
|
38
43
|
</CodeBlockComp>
|
|
39
44
|
);
|
|
40
45
|
}
|