docusaurus-theme-openapi-docs 0.0.0-1294 → 0.0.0-1310
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/schema.js +4 -5
- package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +4 -2
- package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +9 -6
- package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/Authorization/index.js +9 -10
- package/lib/theme/ApiExplorer/Body/index.js +4 -5
- package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +1 -1
- package/lib/theme/ApiExplorer/CodeTabs/index.js +6 -5
- package/lib/theme/ApiExplorer/Export/index.js +9 -2
- package/lib/theme/ApiExplorer/FormFileUpload/index.js +1 -2
- package/lib/theme/ApiExplorer/FormLabel/index.js +1 -2
- package/lib/theme/ApiExplorer/FormTextInput/index.js +1 -2
- package/lib/theme/ApiExplorer/LiveEditor/index.js +1 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +5 -3
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +1 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +1 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +1 -2
- package/lib/theme/ApiExplorer/ParamOptions/index.js +2 -3
- package/lib/theme/ApiExplorer/Request/index.js +17 -18
- package/lib/theme/ApiExplorer/Response/index.js +7 -11
- package/lib/theme/ApiExplorer/SecuritySchemes/index.js +57 -50
- package/lib/theme/ApiExplorer/Server/index.js +2 -3
- package/lib/theme/ApiTabs/index.d.ts +1 -1
- package/lib/theme/ApiTabs/index.js +7 -7
- package/lib/theme/DiscriminatorTabs/index.d.ts +1 -1
- package/lib/theme/DiscriminatorTabs/index.js +6 -5
- package/lib/theme/Example/index.js +3 -4
- package/lib/theme/MimeTabs/index.d.ts +1 -1
- package/lib/theme/MimeTabs/index.js +6 -5
- package/lib/theme/OperationTabs/index.d.ts +1 -1
- package/lib/theme/OperationTabs/index.js +6 -5
- package/lib/theme/ParamsDetails/index.js +1 -2
- package/lib/theme/ParamsItem/index.js +7 -8
- package/lib/theme/RequestSchema/index.js +4 -6
- package/lib/theme/ResponseExamples/index.js +3 -4
- package/lib/theme/ResponseSchema/index.js +2 -3
- package/lib/theme/Schema/index.js +8 -9
- package/lib/theme/SchemaExpansion/index.js +4 -5
- package/lib/theme/SchemaItem/index.js +9 -10
- package/lib/theme/SchemaTabs/index.d.ts +1 -1
- package/lib/theme/SchemaTabs/index.js +6 -5
- package/lib/theme/StatusCodes/index.js +2 -4
- package/lib/theme/TabItem/index.d.ts +5 -0
- package/lib/theme/TabItem/index.js +51 -0
- package/lib/theme/TabItem/styles.module.css +3 -0
- package/lib/theme/Tabs/index.d.ts +5 -0
- package/lib/theme/Tabs/index.js +148 -0
- package/lib/theme/Tabs/styles.module.css +7 -0
- package/lib/theme/translationIds.d.ts +1 -99
- package/lib/theme/translationIds.js +0 -116
- package/lib/theme/utils/codeBlockUtils.d.ts +28 -0
- package/lib/theme/utils/codeBlockUtils.js +223 -0
- package/lib/theme/utils/reactUtils.d.ts +1 -0
- package/lib/theme/utils/reactUtils.js +23 -0
- package/lib/theme/utils/scrollUtils.d.ts +7 -0
- package/lib/theme/utils/scrollUtils.js +175 -0
- package/lib/theme/utils/tabsUtils.d.ts +47 -0
- package/lib/theme/utils/tabsUtils.js +299 -0
- package/lib/theme/utils/useCodeWordWrap.d.ts +8 -0
- package/lib/theme/utils/useCodeWordWrap.js +84 -0
- package/lib/theme/utils/useMutationObserver.d.ts +3 -0
- package/lib/theme/utils/useMutationObserver.js +34 -0
- package/package.json +4 -4
- package/src/markdown/schema.ts +4 -5
- package/src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx +2 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx +8 -7
- package/src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx +1 -1
- package/src/theme/ApiExplorer/ApiCodeBlock/index.tsx +1 -1
- package/src/theme/ApiExplorer/Authorization/index.tsx +9 -10
- package/src/theme/ApiExplorer/Body/index.tsx +7 -5
- package/src/theme/ApiExplorer/CodeTabs/index.tsx +5 -5
- package/src/theme/ApiExplorer/Export/index.tsx +6 -2
- package/src/theme/ApiExplorer/FormFileUpload/index.tsx +1 -2
- package/src/theme/ApiExplorer/FormLabel/index.tsx +1 -2
- package/src/theme/ApiExplorer/FormTextInput/index.tsx +1 -2
- package/src/theme/ApiExplorer/LiveEditor/index.tsx +1 -2
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +5 -3
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +1 -2
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +1 -2
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +1 -2
- package/src/theme/ApiExplorer/ParamOptions/index.tsx +2 -3
- package/src/theme/ApiExplorer/Request/index.tsx +23 -18
- package/src/theme/ApiExplorer/Response/index.tsx +10 -8
- package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +60 -52
- package/src/theme/ApiExplorer/Server/index.tsx +8 -3
- package/src/theme/ApiTabs/index.tsx +8 -8
- package/src/theme/DiscriminatorTabs/index.tsx +6 -5
- package/src/theme/Example/index.tsx +3 -4
- package/src/theme/MimeTabs/index.tsx +9 -8
- package/src/theme/OperationTabs/index.tsx +5 -4
- package/src/theme/ParamsDetails/index.tsx +1 -2
- package/src/theme/ParamsItem/index.tsx +13 -8
- package/src/theme/RequestSchema/index.tsx +4 -5
- package/src/theme/ResponseExamples/index.tsx +3 -4
- package/src/theme/ResponseSchema/index.tsx +2 -3
- package/src/theme/Schema/index.tsx +8 -9
- package/src/theme/SchemaExpansion/index.tsx +4 -5
- package/src/theme/SchemaItem/index.tsx +18 -10
- package/src/theme/SchemaTabs/index.tsx +6 -5
- package/src/theme/StatusCodes/index.tsx +2 -3
- package/src/theme/TabItem/index.tsx +61 -0
- package/src/theme/TabItem/styles.module.css +3 -0
- package/src/theme/Tabs/index.tsx +164 -0
- package/src/theme/Tabs/styles.module.css +7 -0
- package/src/theme/translationIds.ts +37 -113
- package/src/theme/utils/codeBlockUtils.ts +296 -0
- package/src/theme/utils/reactUtils.ts +22 -0
- package/src/theme/utils/scrollUtils.tsx +153 -0
- package/src/theme/utils/tabsUtils.tsx +329 -0
- package/src/theme/utils/useCodeWordWrap.ts +110 -0
- package/src/theme/utils/useMutationObserver.ts +43 -0
- package/src/theme-classic.d.ts +0 -96
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
import SchemaItem from "@theme/SchemaItem";
|
|
23
23
|
import SchemaTabs from "@theme/SchemaTabs";
|
|
24
24
|
import TabItem from "@theme/TabItem";
|
|
25
|
-
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
26
25
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
27
26
|
import { merge } from "allof-merge";
|
|
28
27
|
import clsx from "clsx";
|
|
@@ -261,7 +260,7 @@ const Summary: React.FC<SummaryProps> = ({
|
|
|
261
260
|
{nullable && (
|
|
262
261
|
<span className="openapi-schema__nullable">
|
|
263
262
|
{translate({
|
|
264
|
-
id:
|
|
263
|
+
id: "theme.openapi.schemaItem.nullable",
|
|
265
264
|
message: "nullable",
|
|
266
265
|
})}
|
|
267
266
|
</span>
|
|
@@ -269,7 +268,7 @@ const Summary: React.FC<SummaryProps> = ({
|
|
|
269
268
|
{isRequired && (
|
|
270
269
|
<span className="openapi-schema__required">
|
|
271
270
|
{translate({
|
|
272
|
-
id:
|
|
271
|
+
id: "theme.openapi.schemaItem.required",
|
|
273
272
|
message: "required",
|
|
274
273
|
})}
|
|
275
274
|
</span>
|
|
@@ -277,7 +276,7 @@ const Summary: React.FC<SummaryProps> = ({
|
|
|
277
276
|
{deprecated && (
|
|
278
277
|
<span className="openapi-schema__deprecated">
|
|
279
278
|
{translate({
|
|
280
|
-
id:
|
|
279
|
+
id: "theme.openapi.schemaItem.deprecated",
|
|
281
280
|
message: "deprecated",
|
|
282
281
|
})}
|
|
283
282
|
</span>
|
|
@@ -314,8 +313,8 @@ const AnyOneOf: React.FC<SchemaProps> = ({
|
|
|
314
313
|
}
|
|
315
314
|
|
|
316
315
|
const type = schema.oneOf
|
|
317
|
-
? translate({ id:
|
|
318
|
-
: translate({ id:
|
|
316
|
+
? translate({ id: "theme.openapi.schemaItem.oneOf", message: "oneOf" })
|
|
317
|
+
: translate({ id: "theme.openapi.schemaItem.anyOf", message: "anyOf" });
|
|
319
318
|
|
|
320
319
|
// Generate a unique ID for this anyOf/oneOf to prevent tab value collisions
|
|
321
320
|
const uniqueId = React.useMemo(
|
|
@@ -364,12 +363,12 @@ const AnyOneOf: React.FC<SchemaProps> = ({
|
|
|
364
363
|
if (!label) {
|
|
365
364
|
if (anyOneSchema.oneOf) {
|
|
366
365
|
label = translate({
|
|
367
|
-
id:
|
|
366
|
+
id: "theme.openapi.schemaItem.oneOf",
|
|
368
367
|
message: "oneOf",
|
|
369
368
|
});
|
|
370
369
|
} else if (anyOneSchema.anyOf) {
|
|
371
370
|
label = translate({
|
|
372
|
-
id:
|
|
371
|
+
id: "theme.openapi.schemaItem.anyOf",
|
|
373
372
|
message: "anyOf",
|
|
374
373
|
});
|
|
375
374
|
} else {
|
|
@@ -550,7 +549,7 @@ const PropertyDiscriminator: React.FC<SchemaEdgeProps> = ({
|
|
|
550
549
|
{required && (
|
|
551
550
|
<span className="openapi-schema__required">
|
|
552
551
|
{translate({
|
|
553
|
-
id:
|
|
552
|
+
id: "theme.openapi.schemaItem.required",
|
|
554
553
|
message: "required",
|
|
555
554
|
})}
|
|
556
555
|
</span>
|
|
@@ -16,7 +16,6 @@ import React, {
|
|
|
16
16
|
} from "react";
|
|
17
17
|
|
|
18
18
|
import { translate } from "@docusaurus/Translate";
|
|
19
|
-
import { OPENAPI_SCHEMA_EXPANSION } from "@theme/translationIds";
|
|
20
19
|
import clsx from "clsx";
|
|
21
20
|
|
|
22
21
|
import { useSchemaExpansion } from "./context";
|
|
@@ -146,17 +145,17 @@ const SchemaExpansionControl: React.FC = () => {
|
|
|
146
145
|
if (!config.enabled) return null;
|
|
147
146
|
|
|
148
147
|
const buttonLabel = translate({
|
|
149
|
-
id:
|
|
148
|
+
id: "theme.openapi.schema.expansion.button",
|
|
150
149
|
message: "Schema expansion depth",
|
|
151
150
|
description: "Aria/title tooltip for the schema expansion icon button",
|
|
152
151
|
});
|
|
153
152
|
const menuLabel = translate({
|
|
154
|
-
id:
|
|
153
|
+
id: "theme.openapi.schema.expansion.menu",
|
|
155
154
|
message: "Schema expansion depth options",
|
|
156
155
|
description: "Accessible label for the expansion options menu",
|
|
157
156
|
});
|
|
158
157
|
const allLabel = translate({
|
|
159
|
-
id:
|
|
158
|
+
id: "theme.openapi.schema.expansion.all",
|
|
160
159
|
message: "All",
|
|
161
160
|
description: "Label for the expand-all option",
|
|
162
161
|
});
|
|
@@ -201,7 +200,7 @@ const SchemaExpansionControl: React.FC = () => {
|
|
|
201
200
|
? allLabel
|
|
202
201
|
: translate(
|
|
203
202
|
{
|
|
204
|
-
id:
|
|
203
|
+
id: "theme.openapi.schema.expansion.depthOption",
|
|
205
204
|
message: "Expand to depth {depth}",
|
|
206
205
|
description: "Accessible label for a depth option",
|
|
207
206
|
},
|
|
@@ -10,7 +10,6 @@ import React, { ReactNode } from "react";
|
|
|
10
10
|
import { translate } from "@docusaurus/Translate";
|
|
11
11
|
import { Example } from "@theme/Example";
|
|
12
12
|
import Markdown from "@theme/Markdown";
|
|
13
|
-
import { OPENAPI_SCHEMA_ITEM } from "@theme/translationIds";
|
|
14
13
|
import clsx from "clsx";
|
|
15
14
|
|
|
16
15
|
import { getQualifierMessage } from "../../markdown/schema";
|
|
@@ -41,11 +40,11 @@ const transformEnumDescriptions = (
|
|
|
41
40
|
const getEnumDescriptionMarkdown = (enumDescriptions?: [string, string][]) => {
|
|
42
41
|
if (enumDescriptions?.length) {
|
|
43
42
|
const enumValue = translate({
|
|
44
|
-
id:
|
|
43
|
+
id: "theme.openapi.schemaItem.enumValue",
|
|
45
44
|
message: "Enum Value",
|
|
46
45
|
});
|
|
47
46
|
const description = translate({
|
|
48
|
-
id:
|
|
47
|
+
id: "theme.openapi.schemaItem.enumDescription",
|
|
49
48
|
message: "Description",
|
|
50
49
|
});
|
|
51
50
|
return `| ${enumValue} | ${description} |
|
|
@@ -97,20 +96,29 @@ export default function SchemaItem(props: Props) {
|
|
|
97
96
|
Array.isArray(required) ? required.includes(name) : required,
|
|
98
97
|
() => (
|
|
99
98
|
<span className="openapi-schema__required">
|
|
100
|
-
{translate({
|
|
99
|
+
{translate({
|
|
100
|
+
id: "theme.openapi.schemaItem.required",
|
|
101
|
+
message: "required",
|
|
102
|
+
})}
|
|
101
103
|
</span>
|
|
102
104
|
)
|
|
103
105
|
);
|
|
104
106
|
|
|
105
107
|
const renderDeprecated = guard(deprecated, () => (
|
|
106
108
|
<span className="openapi-schema__deprecated">
|
|
107
|
-
{translate({
|
|
109
|
+
{translate({
|
|
110
|
+
id: "theme.openapi.schemaItem.deprecated",
|
|
111
|
+
message: "deprecated",
|
|
112
|
+
})}
|
|
108
113
|
</span>
|
|
109
114
|
));
|
|
110
115
|
|
|
111
116
|
const renderNullable = guard(nullable, () => (
|
|
112
117
|
<span className="openapi-schema__nullable">
|
|
113
|
-
{translate({
|
|
118
|
+
{translate({
|
|
119
|
+
id: "theme.openapi.schemaItem.nullable",
|
|
120
|
+
message: "nullable",
|
|
121
|
+
})}
|
|
114
122
|
</span>
|
|
115
123
|
));
|
|
116
124
|
|
|
@@ -148,7 +156,7 @@ export default function SchemaItem(props: Props) {
|
|
|
148
156
|
<div>
|
|
149
157
|
<strong>
|
|
150
158
|
{translate({
|
|
151
|
-
id:
|
|
159
|
+
id: "theme.openapi.schemaItem.defaultValue",
|
|
152
160
|
message: "Default value:",
|
|
153
161
|
})}{" "}
|
|
154
162
|
</strong>
|
|
@@ -162,7 +170,7 @@ export default function SchemaItem(props: Props) {
|
|
|
162
170
|
<div>
|
|
163
171
|
<strong>
|
|
164
172
|
{translate({
|
|
165
|
-
id:
|
|
173
|
+
id: "theme.openapi.schemaItem.defaultValue",
|
|
166
174
|
message: "Default value:",
|
|
167
175
|
})}{" "}
|
|
168
176
|
</strong>
|
|
@@ -182,7 +190,7 @@ export default function SchemaItem(props: Props) {
|
|
|
182
190
|
<div>
|
|
183
191
|
<strong>
|
|
184
192
|
{translate({
|
|
185
|
-
id:
|
|
193
|
+
id: "theme.openapi.schemaItem.constantValue",
|
|
186
194
|
message: "Constant value:",
|
|
187
195
|
})}{" "}
|
|
188
196
|
</strong>
|
|
@@ -196,7 +204,7 @@ export default function SchemaItem(props: Props) {
|
|
|
196
204
|
<div>
|
|
197
205
|
<strong>
|
|
198
206
|
{translate({
|
|
199
|
-
id:
|
|
207
|
+
id: "theme.openapi.schemaItem.constantValue",
|
|
200
208
|
message: "Constant value:",
|
|
201
209
|
})}{" "}
|
|
202
210
|
</strong>
|
|
@@ -14,17 +14,18 @@ import React, {
|
|
|
14
14
|
LegacyRef,
|
|
15
15
|
} from "react";
|
|
16
16
|
|
|
17
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
18
|
+
import clsx from "clsx";
|
|
19
|
+
import flatten from "lodash/flatten";
|
|
20
|
+
|
|
21
|
+
import { useScrollPositionBlocker } from "@theme/utils/scrollUtils";
|
|
17
22
|
import {
|
|
18
23
|
sanitizeTabsChildren,
|
|
19
24
|
type TabItemProps,
|
|
20
25
|
TabProps,
|
|
21
26
|
TabsProvider,
|
|
22
|
-
useScrollPositionBlocker,
|
|
23
27
|
useTabsContextValue,
|
|
24
|
-
} from "@
|
|
25
|
-
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
26
|
-
import clsx from "clsx";
|
|
27
|
-
import flatten from "lodash/flatten";
|
|
28
|
+
} from "@theme/utils/tabsUtils";
|
|
28
29
|
|
|
29
30
|
export interface SchemaTabsProps extends TabProps {
|
|
30
31
|
/**
|
|
@@ -14,7 +14,6 @@ import Markdown from "@theme/Markdown";
|
|
|
14
14
|
import ResponseHeaders from "@theme/ResponseHeaders";
|
|
15
15
|
import ResponseSchema from "@theme/ResponseSchema";
|
|
16
16
|
import TabItem from "@theme/TabItem";
|
|
17
|
-
import { OPENAPI_STATUS_CODES } from "@theme/translationIds";
|
|
18
17
|
import type { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
|
|
19
18
|
|
|
20
19
|
interface Props {
|
|
@@ -55,7 +54,7 @@ const StatusCodes: React.FC<Props> = ({ label, id, responses }: any) => {
|
|
|
55
54
|
<summary>
|
|
56
55
|
<strong>
|
|
57
56
|
{translate({
|
|
58
|
-
id:
|
|
57
|
+
id: "theme.openapi.statusCodes.responseHeaders",
|
|
59
58
|
message: "Response Headers",
|
|
60
59
|
})}
|
|
61
60
|
</strong>
|
|
@@ -67,7 +66,7 @@ const StatusCodes: React.FC<Props> = ({ label, id, responses }: any) => {
|
|
|
67
66
|
)}
|
|
68
67
|
<ResponseSchema
|
|
69
68
|
title={translate({
|
|
70
|
-
id:
|
|
69
|
+
id: "theme.openapi.statusCodes.schemaTitle",
|
|
71
70
|
message: "Schema",
|
|
72
71
|
})}
|
|
73
72
|
body={{ content: response.content }}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* Swizzled from @docusaurus/theme-classic/src/theme/TabItem/index.tsx (MIT).
|
|
6
|
+
* Re-points useTabs to our vendored tabsUtils so that <TabItem> reads the same
|
|
7
|
+
* context our swizzled <Tabs> and OpenAPI tab variants (ApiTabs, MimeTabs,
|
|
8
|
+
* SchemaTabs, etc.) provide. See:
|
|
9
|
+
* https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
* ========================================================================== */
|
|
14
|
+
|
|
15
|
+
import React, { type ReactNode } from "react";
|
|
16
|
+
|
|
17
|
+
import clsx from "clsx";
|
|
18
|
+
|
|
19
|
+
import { type TabItemProps, useTabs } from "@theme/utils/tabsUtils";
|
|
20
|
+
|
|
21
|
+
type Props = TabItemProps;
|
|
22
|
+
import styles from "./styles.module.css";
|
|
23
|
+
|
|
24
|
+
function TabItemPanel({
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
hidden,
|
|
28
|
+
}: {
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
className?: string;
|
|
31
|
+
hidden?: boolean;
|
|
32
|
+
}) {
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
role="tabpanel"
|
|
36
|
+
className={clsx(styles.tabItem, className)}
|
|
37
|
+
{...{ hidden }}
|
|
38
|
+
>
|
|
39
|
+
{children}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export default function TabItem({
|
|
45
|
+
children,
|
|
46
|
+
className,
|
|
47
|
+
value,
|
|
48
|
+
}: Props): ReactNode {
|
|
49
|
+
const { selectedValue, lazy } = useTabs();
|
|
50
|
+
const isSelected = value === selectedValue;
|
|
51
|
+
|
|
52
|
+
if (!isSelected && lazy) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<TabItemPanel className={className} hidden={!isSelected}>
|
|
58
|
+
{children}
|
|
59
|
+
</TabItemPanel>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* Swizzled from @docusaurus/theme-classic/src/theme/Tabs/index.tsx (MIT).
|
|
6
|
+
* Re-points the internal hooks (useTabs, useTabsContextValue, etc.) to our
|
|
7
|
+
* vendored tabsUtils so that the entire <Tabs>/<TabItem> pair runs through a
|
|
8
|
+
* single React context owned by this package. See:
|
|
9
|
+
* https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
* ========================================================================== */
|
|
14
|
+
|
|
15
|
+
import React, { type ReactNode } from "react";
|
|
16
|
+
|
|
17
|
+
import { ThemeClassNames } from "@docusaurus/theme-common";
|
|
18
|
+
import useIsBrowser from "@docusaurus/useIsBrowser";
|
|
19
|
+
import clsx from "clsx";
|
|
20
|
+
|
|
21
|
+
import { useScrollPositionBlocker } from "@theme/utils/scrollUtils";
|
|
22
|
+
import {
|
|
23
|
+
sanitizeTabsChildren,
|
|
24
|
+
type TabsProps,
|
|
25
|
+
TabsProvider,
|
|
26
|
+
useTabs,
|
|
27
|
+
useTabsContextValue,
|
|
28
|
+
} from "@theme/utils/tabsUtils";
|
|
29
|
+
import styles from "./styles.module.css";
|
|
30
|
+
|
|
31
|
+
type Props = TabsProps;
|
|
32
|
+
|
|
33
|
+
function TabList({ className }: { className?: string }) {
|
|
34
|
+
const { selectedValue, selectValue, tabValues, block } = useTabs();
|
|
35
|
+
|
|
36
|
+
const tabRefs: (HTMLLIElement | null)[] = [];
|
|
37
|
+
const { blockElementScrollPositionUntilNextRender } =
|
|
38
|
+
useScrollPositionBlocker();
|
|
39
|
+
|
|
40
|
+
const handleTabChange = (
|
|
41
|
+
event:
|
|
42
|
+
| React.FocusEvent<HTMLLIElement>
|
|
43
|
+
| React.MouseEvent<HTMLLIElement>
|
|
44
|
+
| React.KeyboardEvent<HTMLLIElement>
|
|
45
|
+
) => {
|
|
46
|
+
const newTab = event.currentTarget;
|
|
47
|
+
const newTabIndex = tabRefs.indexOf(newTab);
|
|
48
|
+
const newTabValue = tabValues[newTabIndex]!.value;
|
|
49
|
+
|
|
50
|
+
if (newTabValue !== selectedValue) {
|
|
51
|
+
blockElementScrollPositionUntilNextRender(newTab);
|
|
52
|
+
selectValue(newTabValue);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
|
|
57
|
+
let focusElement: HTMLLIElement | null = null;
|
|
58
|
+
|
|
59
|
+
switch (event.key) {
|
|
60
|
+
case "Enter": {
|
|
61
|
+
handleTabChange(event);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
case "ArrowRight": {
|
|
65
|
+
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
66
|
+
focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "ArrowLeft": {
|
|
70
|
+
const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
|
|
71
|
+
focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
focusElement?.focus();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
<ul
|
|
83
|
+
role="tablist"
|
|
84
|
+
aria-orientation="horizontal"
|
|
85
|
+
className={clsx(
|
|
86
|
+
"tabs",
|
|
87
|
+
{
|
|
88
|
+
"tabs--block": block,
|
|
89
|
+
},
|
|
90
|
+
className
|
|
91
|
+
)}
|
|
92
|
+
>
|
|
93
|
+
{tabValues.map(({ value, label, attributes }) => (
|
|
94
|
+
<li
|
|
95
|
+
// TODO extract TabListItem
|
|
96
|
+
role="tab"
|
|
97
|
+
tabIndex={selectedValue === value ? 0 : -1}
|
|
98
|
+
aria-selected={selectedValue === value}
|
|
99
|
+
key={value}
|
|
100
|
+
ref={(ref) => {
|
|
101
|
+
tabRefs.push(ref);
|
|
102
|
+
}}
|
|
103
|
+
onKeyDown={handleKeydown}
|
|
104
|
+
onClick={handleTabChange}
|
|
105
|
+
{...attributes}
|
|
106
|
+
className={clsx(
|
|
107
|
+
"tabs__item",
|
|
108
|
+
styles.tabItem,
|
|
109
|
+
attributes?.className as string,
|
|
110
|
+
{
|
|
111
|
+
"tabs__item--active": selectedValue === value,
|
|
112
|
+
}
|
|
113
|
+
)}
|
|
114
|
+
>
|
|
115
|
+
{label ?? value}
|
|
116
|
+
</li>
|
|
117
|
+
))}
|
|
118
|
+
</ul>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function TabContent({ children }: { children: ReactNode }) {
|
|
123
|
+
return <div className="margin-top--md">{children}</div>;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function TabsContainer({
|
|
127
|
+
className,
|
|
128
|
+
children,
|
|
129
|
+
}: {
|
|
130
|
+
className?: string;
|
|
131
|
+
children: ReactNode;
|
|
132
|
+
}): ReactNode {
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
className={clsx(
|
|
136
|
+
ThemeClassNames.tabs.container,
|
|
137
|
+
// former name kept for backward compatibility
|
|
138
|
+
// see https://github.com/facebook/docusaurus/pull/4086
|
|
139
|
+
"tabs-container",
|
|
140
|
+
styles.tabList
|
|
141
|
+
)}
|
|
142
|
+
>
|
|
143
|
+
<TabList className={className} />
|
|
144
|
+
<TabContent>{children}</TabContent>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export default function Tabs(props: Props): ReactNode {
|
|
150
|
+
const isBrowser = useIsBrowser();
|
|
151
|
+
const value = useTabsContextValue(props);
|
|
152
|
+
return (
|
|
153
|
+
<TabsProvider
|
|
154
|
+
value={value}
|
|
155
|
+
// Remount tabs after hydration
|
|
156
|
+
// Temporary fix for https://github.com/facebook/docusaurus/issues/5653
|
|
157
|
+
key={String(isBrowser)}
|
|
158
|
+
>
|
|
159
|
+
<TabsContainer className={props.className}>
|
|
160
|
+
{sanitizeTabsChildren(props.children)}
|
|
161
|
+
</TabsContainer>
|
|
162
|
+
</TabsProvider>
|
|
163
|
+
);
|
|
164
|
+
}
|
|
@@ -5,117 +5,41 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
* ========================================================================== */
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
SHOW_OPTIONAL: "theme.openapi.paramOptions.showOptional",
|
|
45
|
-
HIDE_OPTIONAL: "theme.openapi.paramOptions.hideOptional",
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const OPENAPI_FORM_FILE_UPLOAD = {
|
|
49
|
-
CLEAR_BUTTON: "theme.openapi.formFileUpload.clearButton",
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const OPENAPI_FORM = {
|
|
53
|
-
FIELD_REQUIRED: "theme.openapi.form.fieldRequired",
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export const OPENAPI_AUTH = {
|
|
57
|
-
BEARER_TOKEN: "theme.openapi.auth.bearerToken",
|
|
58
|
-
USERNAME: "theme.openapi.auth.username",
|
|
59
|
-
PASSWORD: "theme.openapi.auth.password",
|
|
60
|
-
SECURITY_SCHEME: "theme.openapi.auth.securityScheme",
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const OPENAPI_RESPONSE_EXAMPLES = {
|
|
64
|
-
EXAMPLE: "theme.openapi.responseExamples.example",
|
|
65
|
-
AUTO_EXAMPLE: "theme.openapi.responseExamples.autoExample",
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const OPENAPI_BODY = {
|
|
69
|
-
EXAMPLE_FROM_SCHEMA: "theme.openapi.body.exampleFromSchema",
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export const OPENAPI_STATUS_CODES = {
|
|
73
|
-
RESPONSE_HEADERS: "theme.openapi.statusCodes.responseHeaders",
|
|
74
|
-
SCHEMA_TITLE: "theme.openapi.statusCodes.schemaTitle",
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
export const OPENAPI_SCHEMA = {
|
|
78
|
-
NO_SCHEMA: "theme.openapi.schema.noSchema",
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export const OPENAPI_SCHEMA_EXPANSION = {
|
|
82
|
-
BUTTON_LABEL: "theme.openapi.schema.expansion.button",
|
|
83
|
-
MENU_LABEL: "theme.openapi.schema.expansion.menu",
|
|
84
|
-
ALL: "theme.openapi.schema.expansion.all",
|
|
85
|
-
DEPTH_OPTION: "theme.openapi.schema.expansion.depthOption",
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const OPENAPI_SCHEMA_ITEM = {
|
|
89
|
-
CHARACTERS: "theme.openapi.schemaItem.characters",
|
|
90
|
-
NON_EMPTY: "theme.openapi.schemaItem.nonEmpty",
|
|
91
|
-
REQUIRED: "theme.openapi.schemaItem.required",
|
|
92
|
-
DEPRECATED: "theme.openapi.schemaItem.deprecated",
|
|
93
|
-
NULLABLE: "theme.openapi.schemaItem.nullable",
|
|
94
|
-
DEFAULT_VALUE: "theme.openapi.schemaItem.defaultValue",
|
|
95
|
-
EXAMPLE: "theme.openapi.schemaItem.example",
|
|
96
|
-
EXAMPLES: "theme.openapi.schemaItem.examples",
|
|
97
|
-
DESCRIPTION: "theme.openapi.schemaItem.description",
|
|
98
|
-
CONSTANT_VALUE: "theme.openapi.schemaItem.constantValue",
|
|
99
|
-
ENUM_VALUE: "theme.openapi.schemaItem.enumValue",
|
|
100
|
-
ENUM_DESCRIPTION: "theme.openapi.schemaItem.enumDescription",
|
|
101
|
-
POSSIBLE_VALUES: "theme.openapi.schemaItem.possibleValues",
|
|
102
|
-
EXPRESSION: "theme.openapi.schemaItem.expression",
|
|
103
|
-
ONE_OF: "theme.openapi.schemaItem.oneOf",
|
|
104
|
-
ANY_OF: "theme.openapi.schemaItem.anyOf",
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const OPENAPI_PARAMS_DETAILS = {
|
|
108
|
-
PARAMETERS_TITLE: "theme.openapi.paramsDetails.parametersTitle",
|
|
109
|
-
};
|
|
8
|
+
/*
|
|
9
|
+
* The central dictionary of translation-id constants that used to live here
|
|
10
|
+
* (OPENAPI_REQUEST, OPENAPI_SCHEMA_ITEM, ...) has been removed. Each
|
|
11
|
+
* `translate({ id, message })` / `<Translate id="...">` call site now passes
|
|
12
|
+
* its id as an inline string literal instead.
|
|
13
|
+
*
|
|
14
|
+
* WHY THE DICTIONARY WAS REMOVED
|
|
15
|
+
* ------------------------------
|
|
16
|
+
* `docusaurus write-translations` only performs STATIC analysis of the source
|
|
17
|
+
* code (via @docusaurus/babel) — it never runs the site. To collect a string
|
|
18
|
+
* it evaluates the argument of every `translate()` / `<Translate>` call with
|
|
19
|
+
* Babel's `path.evaluate()` and keeps it only when the result is `confident`.
|
|
20
|
+
*
|
|
21
|
+
* An id referenced through an imported constant, e.g.
|
|
22
|
+
*
|
|
23
|
+
* import { OPENAPI_REQUEST } from "@theme/translationIds";
|
|
24
|
+
* translate({ id: OPENAPI_REQUEST.COLLAPSE_ALL, message: "Collapse all" });
|
|
25
|
+
*
|
|
26
|
+
* is a member expression on a binding imported from another module. Babel
|
|
27
|
+
* cannot statically resolve a cross-module binding, so `evaluate()` returns
|
|
28
|
+
* `confident === false`, the extractor skips the call (emitting a warning), and
|
|
29
|
+
* NOTHING is written to the locale `code.json`. As a result `write-translations`
|
|
30
|
+
* produced an empty template and downstream projects had no ids to translate,
|
|
31
|
+
* even though the strings rendered fine at runtime (the inlined constant value
|
|
32
|
+
* matched the runtime lookup key).
|
|
33
|
+
*
|
|
34
|
+
* The id and message must therefore be static string literals AT THE CALL SITE.
|
|
35
|
+
* This is the approach Docusaurus' own theme-classic uses and what its i18n
|
|
36
|
+
* guide mandates ("Text labels must be static"):
|
|
37
|
+
*
|
|
38
|
+
* - https://docusaurus.io/docs/i18n/tutorial#translate-your-react-code
|
|
39
|
+
* - https://docusaurus.io/docs/docusaurus-core#translate
|
|
40
|
+
*
|
|
41
|
+
* Keep this note here so the removal of the constants is discoverable; do not
|
|
42
|
+
* reintroduce a shared id dictionary for `translate()` arguments.
|
|
43
|
+
*/
|
|
110
44
|
|
|
111
|
-
export
|
|
112
|
-
NAME: "theme.openapi.securitySchemes.name",
|
|
113
|
-
TYPE: "theme.openapi.securitySchemes.type",
|
|
114
|
-
SCOPES: "theme.openapi.securitySchemes.scopes",
|
|
115
|
-
IN: "theme.openapi.securitySchemes.in",
|
|
116
|
-
FLOWS: "theme.openapi.securitySchemes.flows",
|
|
117
|
-
DESCRIPTION: "theme.openapi.securitySchemes.description",
|
|
118
|
-
SCHEME: "theme.openapi.securitySchemes.scheme",
|
|
119
|
-
BEARER_FORMAT: "theme.openapi.securitySchemes.bearerFormat",
|
|
120
|
-
OPEN_ID_CONNECT_URL: "theme.openapi.securitySchemes.openIdConnectUrl",
|
|
121
|
-
};
|
|
45
|
+
export {};
|