docusaurus-theme-openapi-docs 5.0.1 → 5.1.0
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 +38 -15
- package/lib/markdown/schema.test.d.ts +1 -0
- package/lib/markdown/schema.test.js +86 -0
- 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/CodeSnippets/index.js +96 -61
- package/lib/theme/ApiExplorer/CodeSnippets/languages.js +12 -1
- package/lib/theme/ApiExplorer/CodeSnippets/languages.test.d.ts +1 -0
- package/lib/theme/ApiExplorer/CodeSnippets/languages.test.js +102 -0
- 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 +75 -4
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +1 -2
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +67 -4
- package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.js +65 -1
- 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 +54 -12
- package/lib/theme/ApiExplorer/SecuritySchemes/index.js +57 -50
- package/lib/theme/ApiExplorer/Server/index.js +2 -3
- package/lib/theme/ApiItem/index.js +59 -33
- 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 +57 -57
- package/lib/theme/ResponseExamples/index.js +3 -4
- package/lib/theme/ResponseSchema/index.js +26 -24
- package/lib/theme/Schema/index.js +148 -27
- package/lib/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
- package/lib/theme/SchemaExpansion/context.d.ts +24 -0
- package/lib/theme/SchemaExpansion/context.js +187 -0
- package/lib/theme/SchemaExpansion/index.d.ts +4 -0
- package/lib/theme/SchemaExpansion/index.js +314 -0
- 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/styles.scss +1 -0
- package/lib/theme/translationIds.d.ts +1 -93
- package/lib/theme/translationIds.js +0 -109
- 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.test.ts +102 -0
- package/src/markdown/schema.ts +42 -15
- 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/CodeSnippets/index.tsx +103 -59
- package/src/theme/ApiExplorer/CodeSnippets/languages.test.ts +109 -0
- package/src/theme/ApiExplorer/CodeSnippets/languages.ts +13 -1
- 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 +20 -4
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +1 -2
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +15 -4
- package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx +11 -1
- 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 +63 -9
- package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +60 -52
- package/src/theme/ApiExplorer/Server/index.tsx +8 -3
- package/src/theme/ApiItem/index.tsx +43 -21
- 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 +38 -40
- package/src/theme/ResponseExamples/index.tsx +3 -4
- package/src/theme/ResponseSchema/index.tsx +16 -17
- package/src/theme/Schema/index.tsx +156 -27
- package/src/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
- package/src/theme/SchemaExpansion/context.tsx +154 -0
- package/src/theme/SchemaExpansion/index.tsx +236 -0
- 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/styles.scss +1 -0
- package/src/theme/translationIds.ts +37 -106
- 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/src/types.d.ts +27 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -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
|
+
}
|
package/src/theme/styles.scss
CHANGED
|
@@ -5,110 +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_ITEM = {
|
|
82
|
-
CHARACTERS: "theme.openapi.schemaItem.characters",
|
|
83
|
-
NON_EMPTY: "theme.openapi.schemaItem.nonEmpty",
|
|
84
|
-
REQUIRED: "theme.openapi.schemaItem.required",
|
|
85
|
-
DEPRECATED: "theme.openapi.schemaItem.deprecated",
|
|
86
|
-
NULLABLE: "theme.openapi.schemaItem.nullable",
|
|
87
|
-
DEFAULT_VALUE: "theme.openapi.schemaItem.defaultValue",
|
|
88
|
-
EXAMPLE: "theme.openapi.schemaItem.example",
|
|
89
|
-
EXAMPLES: "theme.openapi.schemaItem.examples",
|
|
90
|
-
DESCRIPTION: "theme.openapi.schemaItem.description",
|
|
91
|
-
CONSTANT_VALUE: "theme.openapi.schemaItem.constantValue",
|
|
92
|
-
ENUM_VALUE: "theme.openapi.schemaItem.enumValue",
|
|
93
|
-
ENUM_DESCRIPTION: "theme.openapi.schemaItem.enumDescription",
|
|
94
|
-
POSSIBLE_VALUES: "theme.openapi.schemaItem.possibleValues",
|
|
95
|
-
EXPRESSION: "theme.openapi.schemaItem.expression",
|
|
96
|
-
ONE_OF: "theme.openapi.schemaItem.oneOf",
|
|
97
|
-
ANY_OF: "theme.openapi.schemaItem.anyOf",
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
export const OPENAPI_PARAMS_DETAILS = {
|
|
101
|
-
PARAMETERS_TITLE: "theme.openapi.paramsDetails.parametersTitle",
|
|
102
|
-
};
|
|
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
|
+
*/
|
|
103
44
|
|
|
104
|
-
export
|
|
105
|
-
NAME: "theme.openapi.securitySchemes.name",
|
|
106
|
-
TYPE: "theme.openapi.securitySchemes.type",
|
|
107
|
-
SCOPES: "theme.openapi.securitySchemes.scopes",
|
|
108
|
-
IN: "theme.openapi.securitySchemes.in",
|
|
109
|
-
FLOWS: "theme.openapi.securitySchemes.flows",
|
|
110
|
-
DESCRIPTION: "theme.openapi.securitySchemes.description",
|
|
111
|
-
SCHEME: "theme.openapi.securitySchemes.scheme",
|
|
112
|
-
BEARER_FORMAT: "theme.openapi.securitySchemes.bearerFormat",
|
|
113
|
-
OPEN_ID_CONNECT_URL: "theme.openapi.securitySchemes.openIdConnectUrl",
|
|
114
|
-
};
|
|
45
|
+
export {};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* Vendored subset of @docusaurus/theme-common/src/utils/codeBlockUtils.tsx (MIT)
|
|
6
|
+
* to remove the dependency on @docusaurus/theme-common/internal.
|
|
7
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the MIT license found in the
|
|
10
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
|
+
* ========================================================================== */
|
|
12
|
+
|
|
13
|
+
import type { CSSProperties } from "react";
|
|
14
|
+
|
|
15
|
+
import rangeParser from "parse-numeric-range";
|
|
16
|
+
import type { PrismTheme, PrismThemeEntry } from "prism-react-renderer";
|
|
17
|
+
|
|
18
|
+
const codeBlockTitleRegex = /title=(?<quote>["'])(?<title>.*?)\1/;
|
|
19
|
+
const metastringLinesRangeRegex = /\{(?<range>[\d,-]+)\}/;
|
|
20
|
+
|
|
21
|
+
const popularCommentPatterns = {
|
|
22
|
+
js: { start: "\\/\\/", end: "" },
|
|
23
|
+
jsBlock: { start: "\\/\\*", end: "\\*\\/" },
|
|
24
|
+
jsx: { start: "\\{\\s*\\/\\*", end: "\\*\\/\\s*\\}" },
|
|
25
|
+
bash: { start: "#", end: "" },
|
|
26
|
+
html: { start: "<!--", end: "-->" },
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
const commentPatterns = {
|
|
30
|
+
...popularCommentPatterns,
|
|
31
|
+
lua: { start: "--", end: "" },
|
|
32
|
+
wasm: { start: "\\;\\;", end: "" },
|
|
33
|
+
tex: { start: "%", end: "" },
|
|
34
|
+
vb: { start: "['‘’]", end: "" },
|
|
35
|
+
vbnet: { start: "(?:_\\s*)?['‘’]", end: "" },
|
|
36
|
+
rem: { start: "[Rr][Ee][Mm]\\b", end: "" },
|
|
37
|
+
f90: { start: "!", end: "" },
|
|
38
|
+
ml: { start: "\\(\\*", end: "\\*\\)" },
|
|
39
|
+
cobol: { start: "\\*>", end: "" },
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
type CommentType = keyof typeof commentPatterns;
|
|
43
|
+
const popularCommentTypes = Object.keys(
|
|
44
|
+
popularCommentPatterns
|
|
45
|
+
) as CommentType[];
|
|
46
|
+
|
|
47
|
+
export type MagicCommentConfig = {
|
|
48
|
+
className: string;
|
|
49
|
+
line?: string;
|
|
50
|
+
block?: { start: string; end: string };
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function getCommentPattern(
|
|
54
|
+
languages: CommentType[],
|
|
55
|
+
magicCommentDirectives: MagicCommentConfig[]
|
|
56
|
+
) {
|
|
57
|
+
const commentPattern = languages
|
|
58
|
+
.map((lang) => {
|
|
59
|
+
const { start, end } = commentPatterns[lang];
|
|
60
|
+
return `(?:${start}\\s*(${magicCommentDirectives
|
|
61
|
+
.flatMap((d) => [d.line, d.block?.start, d.block?.end].filter(Boolean))
|
|
62
|
+
.join("|")})\\s*${end})`;
|
|
63
|
+
})
|
|
64
|
+
.join("|");
|
|
65
|
+
return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getAllMagicCommentDirectiveStyles(
|
|
69
|
+
lang: string,
|
|
70
|
+
magicCommentDirectives: MagicCommentConfig[]
|
|
71
|
+
) {
|
|
72
|
+
switch (lang) {
|
|
73
|
+
case "js":
|
|
74
|
+
case "javascript":
|
|
75
|
+
case "ts":
|
|
76
|
+
case "typescript":
|
|
77
|
+
return getCommentPattern(["js", "jsBlock"], magicCommentDirectives);
|
|
78
|
+
|
|
79
|
+
case "jsx":
|
|
80
|
+
case "tsx":
|
|
81
|
+
return getCommentPattern(
|
|
82
|
+
["js", "jsBlock", "jsx"],
|
|
83
|
+
magicCommentDirectives
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
case "html":
|
|
87
|
+
return getCommentPattern(
|
|
88
|
+
["js", "jsBlock", "html"],
|
|
89
|
+
magicCommentDirectives
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
case "python":
|
|
93
|
+
case "py":
|
|
94
|
+
case "bash":
|
|
95
|
+
return getCommentPattern(["bash"], magicCommentDirectives);
|
|
96
|
+
|
|
97
|
+
case "markdown":
|
|
98
|
+
case "md":
|
|
99
|
+
return getCommentPattern(["html", "jsx", "bash"], magicCommentDirectives);
|
|
100
|
+
|
|
101
|
+
case "tex":
|
|
102
|
+
case "latex":
|
|
103
|
+
case "matlab":
|
|
104
|
+
return getCommentPattern(["tex"], magicCommentDirectives);
|
|
105
|
+
|
|
106
|
+
case "lua":
|
|
107
|
+
case "haskell":
|
|
108
|
+
return getCommentPattern(["lua"], magicCommentDirectives);
|
|
109
|
+
|
|
110
|
+
case "sql":
|
|
111
|
+
return getCommentPattern(["lua", "jsBlock"], magicCommentDirectives);
|
|
112
|
+
|
|
113
|
+
case "wasm":
|
|
114
|
+
return getCommentPattern(["wasm"], magicCommentDirectives);
|
|
115
|
+
|
|
116
|
+
case "vb":
|
|
117
|
+
case "vba":
|
|
118
|
+
case "visual-basic":
|
|
119
|
+
return getCommentPattern(["vb", "rem"], magicCommentDirectives);
|
|
120
|
+
case "vbnet":
|
|
121
|
+
return getCommentPattern(["vbnet", "rem"], magicCommentDirectives);
|
|
122
|
+
|
|
123
|
+
case "batch":
|
|
124
|
+
return getCommentPattern(["rem"], magicCommentDirectives);
|
|
125
|
+
|
|
126
|
+
case "basic":
|
|
127
|
+
return getCommentPattern(["rem", "f90"], magicCommentDirectives);
|
|
128
|
+
|
|
129
|
+
case "fsharp":
|
|
130
|
+
return getCommentPattern(["js", "ml"], magicCommentDirectives);
|
|
131
|
+
|
|
132
|
+
case "ocaml":
|
|
133
|
+
case "sml":
|
|
134
|
+
return getCommentPattern(["ml"], magicCommentDirectives);
|
|
135
|
+
|
|
136
|
+
case "fortran":
|
|
137
|
+
return getCommentPattern(["f90"], magicCommentDirectives);
|
|
138
|
+
|
|
139
|
+
case "cobol":
|
|
140
|
+
return getCommentPattern(["cobol"], magicCommentDirectives);
|
|
141
|
+
|
|
142
|
+
default:
|
|
143
|
+
return getCommentPattern(popularCommentTypes, magicCommentDirectives);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function parseCodeBlockTitle(metastring?: string): string {
|
|
148
|
+
return metastring?.match(codeBlockTitleRegex)?.groups!.title ?? "";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function containsLineNumbers(metastring?: string): boolean {
|
|
152
|
+
return Boolean(metastring?.includes("showLineNumbers"));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
type ParseCodeLinesParam = {
|
|
156
|
+
metastring: string | undefined;
|
|
157
|
+
language: string | undefined;
|
|
158
|
+
magicComments: MagicCommentConfig[];
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
type CodeLineClassNames = { [lineIndex: number]: string[] };
|
|
162
|
+
|
|
163
|
+
type ParsedCodeLines = {
|
|
164
|
+
code: string;
|
|
165
|
+
lineClassNames: CodeLineClassNames;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
function parseCodeLinesFromMetastring(
|
|
169
|
+
code: string,
|
|
170
|
+
{ metastring, magicComments }: ParseCodeLinesParam
|
|
171
|
+
): ParsedCodeLines | null {
|
|
172
|
+
if (metastring && metastringLinesRangeRegex.test(metastring)) {
|
|
173
|
+
const linesRange = metastring.match(metastringLinesRangeRegex)!.groups!
|
|
174
|
+
.range!;
|
|
175
|
+
if (magicComments.length === 0) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`A highlight range has been given in code block's metastring (\`\`\` ${metastring}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
const metastringRangeClassName = magicComments[0]!.className;
|
|
181
|
+
const lines = rangeParser(linesRange)
|
|
182
|
+
.filter((n) => n > 0)
|
|
183
|
+
.map((n) => [n - 1, [metastringRangeClassName]] as [number, string[]]);
|
|
184
|
+
return { lineClassNames: Object.fromEntries(lines), code };
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function parseCodeLinesFromContent(
|
|
190
|
+
code: string,
|
|
191
|
+
params: ParseCodeLinesParam
|
|
192
|
+
): ParsedCodeLines {
|
|
193
|
+
const { language, magicComments } = params;
|
|
194
|
+
if (language === undefined) {
|
|
195
|
+
return { lineClassNames: {}, code };
|
|
196
|
+
}
|
|
197
|
+
const directiveRegex = getAllMagicCommentDirectiveStyles(
|
|
198
|
+
language,
|
|
199
|
+
magicComments
|
|
200
|
+
);
|
|
201
|
+
const lines = code.split(/\r?\n/);
|
|
202
|
+
const blocks = Object.fromEntries(
|
|
203
|
+
magicComments.map((d) => [d.className, { start: 0, range: "" }])
|
|
204
|
+
);
|
|
205
|
+
const lineToClassName: { [comment: string]: string } = Object.fromEntries(
|
|
206
|
+
magicComments
|
|
207
|
+
.filter((d) => d.line)
|
|
208
|
+
.map(({ className, line }) => [line!, className] as [string, string])
|
|
209
|
+
);
|
|
210
|
+
const blockStartToClassName: { [comment: string]: string } =
|
|
211
|
+
Object.fromEntries(
|
|
212
|
+
magicComments
|
|
213
|
+
.filter((d) => d.block)
|
|
214
|
+
.map(({ className, block }) => [block!.start, className])
|
|
215
|
+
);
|
|
216
|
+
const blockEndToClassName: { [comment: string]: string } = Object.fromEntries(
|
|
217
|
+
magicComments
|
|
218
|
+
.filter((d) => d.block)
|
|
219
|
+
.map(({ className, block }) => [block!.end, className])
|
|
220
|
+
);
|
|
221
|
+
for (let lineNumber = 0; lineNumber < lines.length; ) {
|
|
222
|
+
const line = lines[lineNumber]!;
|
|
223
|
+
const match = line.match(directiveRegex);
|
|
224
|
+
if (!match) {
|
|
225
|
+
lineNumber += 1;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
const directive = match
|
|
229
|
+
.slice(1)
|
|
230
|
+
.find((item: string | undefined) => item !== undefined)!;
|
|
231
|
+
if (lineToClassName[directive]) {
|
|
232
|
+
blocks[lineToClassName[directive]!]!.range += `${lineNumber},`;
|
|
233
|
+
} else if (blockStartToClassName[directive]) {
|
|
234
|
+
blocks[blockStartToClassName[directive]!]!.start = lineNumber;
|
|
235
|
+
} else if (blockEndToClassName[directive]) {
|
|
236
|
+
blocks[blockEndToClassName[directive]!]!.range += `${
|
|
237
|
+
blocks[blockEndToClassName[directive]!]!.start
|
|
238
|
+
}-${lineNumber - 1},`;
|
|
239
|
+
}
|
|
240
|
+
lines.splice(lineNumber, 1);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const lineClassNames: { [lineIndex: number]: string[] } = {};
|
|
244
|
+
Object.entries(blocks).forEach(([className, { range }]) => {
|
|
245
|
+
rangeParser(range).forEach((l) => {
|
|
246
|
+
lineClassNames[l] ??= [];
|
|
247
|
+
lineClassNames[l]!.push(className);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return { code: lines.join("\n"), lineClassNames };
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export function parseLines(
|
|
255
|
+
code: string,
|
|
256
|
+
params: ParseCodeLinesParam
|
|
257
|
+
): ParsedCodeLines {
|
|
258
|
+
const newCode = code.replace(/\r?\n$/, "");
|
|
259
|
+
return (
|
|
260
|
+
parseCodeLinesFromMetastring(newCode, { ...params }) ??
|
|
261
|
+
parseCodeLinesFromContent(newCode, { ...params })
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function parseClassNameLanguage(
|
|
266
|
+
className: string | undefined
|
|
267
|
+
): string | undefined {
|
|
268
|
+
if (!className) {
|
|
269
|
+
return undefined;
|
|
270
|
+
}
|
|
271
|
+
const languageClassName = className
|
|
272
|
+
.split(" ")
|
|
273
|
+
.find((str) => str.startsWith("language-"));
|
|
274
|
+
return languageClassName?.replace(/language-/, "");
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Upstream renamed `parseLanguage` to `parseClassNameLanguage`; the back-compat
|
|
278
|
+
// shim in @docusaurus/theme-common/internal re-exports it under the old name.
|
|
279
|
+
// We keep the old name here since our call sites still use it.
|
|
280
|
+
export { parseClassNameLanguage as parseLanguage };
|
|
281
|
+
|
|
282
|
+
export function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties {
|
|
283
|
+
const mapping: PrismThemeEntry = {
|
|
284
|
+
color: "--prism-color",
|
|
285
|
+
backgroundColor: "--prism-background-color",
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const properties: { [key: string]: string } = {};
|
|
289
|
+
Object.entries(prismTheme.plain).forEach(([key, value]) => {
|
|
290
|
+
const varName = mapping[key as keyof PrismThemeEntry];
|
|
291
|
+
if (varName && typeof value === "string") {
|
|
292
|
+
properties[varName] = value;
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
return properties;
|
|
296
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* Vendored from @docusaurus/theme-common/src/utils/reactUtils.tsx (MIT).
|
|
6
|
+
* Only useShallowMemoObject is kept here — it is not re-exported by
|
|
7
|
+
* @docusaurus/theme-common (public or /internal). useEvent and
|
|
8
|
+
* ReactContextError are public APIs imported directly from the package.
|
|
9
|
+
* See: 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 { useMemo } from "react";
|
|
16
|
+
|
|
17
|
+
export function useShallowMemoObject<O extends object>(obj: O): O {
|
|
18
|
+
const deps = Object.entries(obj);
|
|
19
|
+
deps.sort((a, b) => a[0].localeCompare(b[0]));
|
|
20
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
21
|
+
return useMemo(() => obj, deps.flat());
|
|
22
|
+
}
|