docusaurus-theme-openapi-docs 5.0.2 → 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,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
5
|
+
*
|
|
6
|
+
* Vendored from @docusaurus/theme-common/src/utils/reactUtils.tsx (MIT).
|
|
7
|
+
* Only useShallowMemoObject is kept here — it is not re-exported by
|
|
8
|
+
* @docusaurus/theme-common (public or /internal). useEvent and
|
|
9
|
+
* ReactContextError are public APIs imported directly from the package.
|
|
10
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
* ========================================================================== */
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.useShallowMemoObject = useShallowMemoObject;
|
|
17
|
+
const react_1 = require("react");
|
|
18
|
+
function useShallowMemoObject(obj) {
|
|
19
|
+
const deps = Object.entries(obj);
|
|
20
|
+
deps.sort((a, b) => a[0].localeCompare(b[0]));
|
|
21
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
22
|
+
return (0, react_1.useMemo)(() => obj, deps.flat());
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export declare function ScrollControllerProvider({ children, }: {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
}): ReactNode;
|
|
5
|
+
export declare function useScrollPositionBlocker(): {
|
|
6
|
+
blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
5
|
+
*
|
|
6
|
+
* Vendored subset of @docusaurus/theme-common/src/utils/scrollUtils.tsx (MIT)
|
|
7
|
+
* to remove the dependency on @docusaurus/theme-common/internal. Only the
|
|
8
|
+
* ScrollControllerProvider + useScrollPositionBlocker surface is kept, since
|
|
9
|
+
* that's all our tab renderers need. The ScrollControllerProvider must be
|
|
10
|
+
* mounted in the React tree above any consumer of useScrollPositionBlocker
|
|
11
|
+
* (see ApiItem/index.tsx).
|
|
12
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the MIT license found in the
|
|
15
|
+
* LICENSE file in the root directory of this source tree.
|
|
16
|
+
* ========================================================================== */
|
|
17
|
+
var __createBinding =
|
|
18
|
+
(this && this.__createBinding) ||
|
|
19
|
+
(Object.create
|
|
20
|
+
? function (o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
23
|
+
if (
|
|
24
|
+
!desc ||
|
|
25
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
26
|
+
) {
|
|
27
|
+
desc = {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get: function () {
|
|
30
|
+
return m[k];
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}
|
|
36
|
+
: function (o, m, k, k2) {
|
|
37
|
+
if (k2 === undefined) k2 = k;
|
|
38
|
+
o[k2] = m[k];
|
|
39
|
+
});
|
|
40
|
+
var __setModuleDefault =
|
|
41
|
+
(this && this.__setModuleDefault) ||
|
|
42
|
+
(Object.create
|
|
43
|
+
? function (o, v) {
|
|
44
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
45
|
+
}
|
|
46
|
+
: function (o, v) {
|
|
47
|
+
o["default"] = v;
|
|
48
|
+
});
|
|
49
|
+
var __importStar =
|
|
50
|
+
(this && this.__importStar) ||
|
|
51
|
+
(function () {
|
|
52
|
+
var ownKeys = function (o) {
|
|
53
|
+
ownKeys =
|
|
54
|
+
Object.getOwnPropertyNames ||
|
|
55
|
+
function (o) {
|
|
56
|
+
var ar = [];
|
|
57
|
+
for (var k in o)
|
|
58
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
59
|
+
return ar;
|
|
60
|
+
};
|
|
61
|
+
return ownKeys(o);
|
|
62
|
+
};
|
|
63
|
+
return function (mod) {
|
|
64
|
+
if (mod && mod.__esModule) return mod;
|
|
65
|
+
var result = {};
|
|
66
|
+
if (mod != null)
|
|
67
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
68
|
+
if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
69
|
+
__setModuleDefault(result, mod);
|
|
70
|
+
return result;
|
|
71
|
+
};
|
|
72
|
+
})();
|
|
73
|
+
var __importDefault =
|
|
74
|
+
(this && this.__importDefault) ||
|
|
75
|
+
function (mod) {
|
|
76
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
77
|
+
};
|
|
78
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
79
|
+
exports.ScrollControllerProvider = ScrollControllerProvider;
|
|
80
|
+
exports.useScrollPositionBlocker = useScrollPositionBlocker;
|
|
81
|
+
const react_1 = __importStar(require("react"));
|
|
82
|
+
const useIsomorphicLayoutEffect_1 = __importDefault(
|
|
83
|
+
require("@docusaurus/useIsomorphicLayoutEffect")
|
|
84
|
+
);
|
|
85
|
+
const theme_common_1 = require("@docusaurus/theme-common");
|
|
86
|
+
function useScrollControllerContextValue() {
|
|
87
|
+
const scrollEventsEnabledRef = (0, react_1.useRef)(true);
|
|
88
|
+
return (0, react_1.useMemo)(
|
|
89
|
+
() => ({
|
|
90
|
+
scrollEventsEnabledRef,
|
|
91
|
+
enableScrollEvents: () => {
|
|
92
|
+
scrollEventsEnabledRef.current = true;
|
|
93
|
+
},
|
|
94
|
+
disableScrollEvents: () => {
|
|
95
|
+
scrollEventsEnabledRef.current = false;
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
[]
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const ScrollMonitorContext = react_1.default.createContext(undefined);
|
|
102
|
+
function ScrollControllerProvider({ children }) {
|
|
103
|
+
const value = useScrollControllerContextValue();
|
|
104
|
+
return react_1.default.createElement(
|
|
105
|
+
ScrollMonitorContext.Provider,
|
|
106
|
+
{ value: value },
|
|
107
|
+
children
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
function useScrollController() {
|
|
111
|
+
const context = (0, react_1.useContext)(ScrollMonitorContext);
|
|
112
|
+
if (context == null) {
|
|
113
|
+
throw new theme_common_1.ReactContextError("ScrollControllerProvider");
|
|
114
|
+
}
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
function useScrollPositionSaver() {
|
|
118
|
+
const lastElementRef = (0, react_1.useRef)({
|
|
119
|
+
elem: null,
|
|
120
|
+
top: 0,
|
|
121
|
+
});
|
|
122
|
+
const save = (0, react_1.useCallback)((elem) => {
|
|
123
|
+
lastElementRef.current = {
|
|
124
|
+
elem,
|
|
125
|
+
top: elem.getBoundingClientRect().top,
|
|
126
|
+
};
|
|
127
|
+
}, []);
|
|
128
|
+
const restore = (0, react_1.useCallback)(() => {
|
|
129
|
+
const {
|
|
130
|
+
current: { elem, top },
|
|
131
|
+
} = lastElementRef;
|
|
132
|
+
if (!elem) {
|
|
133
|
+
return { restored: false };
|
|
134
|
+
}
|
|
135
|
+
const newTop = elem.getBoundingClientRect().top;
|
|
136
|
+
const heightDiff = newTop - top;
|
|
137
|
+
if (heightDiff) {
|
|
138
|
+
window.scrollBy({ left: 0, top: heightDiff });
|
|
139
|
+
}
|
|
140
|
+
lastElementRef.current = { elem: null, top: 0 };
|
|
141
|
+
return { restored: heightDiff !== 0 };
|
|
142
|
+
}, []);
|
|
143
|
+
return (0, react_1.useMemo)(() => ({ save, restore }), [restore, save]);
|
|
144
|
+
}
|
|
145
|
+
function useScrollPositionBlocker() {
|
|
146
|
+
const scrollController = useScrollController();
|
|
147
|
+
const scrollPositionSaver = useScrollPositionSaver();
|
|
148
|
+
const nextLayoutEffectCallbackRef = (0, react_1.useRef)(undefined);
|
|
149
|
+
const blockElementScrollPositionUntilNextRender = (0, react_1.useCallback)(
|
|
150
|
+
(el) => {
|
|
151
|
+
scrollPositionSaver.save(el);
|
|
152
|
+
scrollController.disableScrollEvents();
|
|
153
|
+
nextLayoutEffectCallbackRef.current = () => {
|
|
154
|
+
const { restored } = scrollPositionSaver.restore();
|
|
155
|
+
nextLayoutEffectCallbackRef.current = undefined;
|
|
156
|
+
if (restored) {
|
|
157
|
+
const handleScrollRestoreEvent = () => {
|
|
158
|
+
scrollController.enableScrollEvents();
|
|
159
|
+
window.removeEventListener("scroll", handleScrollRestoreEvent);
|
|
160
|
+
};
|
|
161
|
+
window.addEventListener("scroll", handleScrollRestoreEvent);
|
|
162
|
+
} else {
|
|
163
|
+
scrollController.enableScrollEvents();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
},
|
|
167
|
+
[scrollController, scrollPositionSaver]
|
|
168
|
+
);
|
|
169
|
+
(0, useIsomorphicLayoutEffect_1.default)(() => {
|
|
170
|
+
queueMicrotask(() => nextLayoutEffectCallbackRef.current?.());
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
blockElementScrollPositionUntilNextRender,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
export interface TabValue {
|
|
3
|
+
readonly value: string;
|
|
4
|
+
readonly label?: string;
|
|
5
|
+
readonly attributes?: {
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
};
|
|
8
|
+
readonly default?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface TabsProps {
|
|
11
|
+
readonly lazy?: boolean;
|
|
12
|
+
readonly block?: boolean;
|
|
13
|
+
readonly children: ReactNode;
|
|
14
|
+
readonly defaultValue?: string | null;
|
|
15
|
+
readonly values?: readonly TabValue[];
|
|
16
|
+
readonly groupId?: string;
|
|
17
|
+
readonly className?: string;
|
|
18
|
+
readonly queryString?: string | boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TabProps extends TabsProps {
|
|
21
|
+
length?: number;
|
|
22
|
+
}
|
|
23
|
+
export interface TabItemProps {
|
|
24
|
+
readonly children: ReactNode;
|
|
25
|
+
readonly value: string;
|
|
26
|
+
readonly default?: boolean;
|
|
27
|
+
readonly label?: string;
|
|
28
|
+
readonly className?: string;
|
|
29
|
+
readonly attributes?: {
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export declare function sanitizeTabsChildren(children: ReactNode): ReactNode;
|
|
34
|
+
type TabsContextValue = {
|
|
35
|
+
selectedValue: string;
|
|
36
|
+
selectValue: (value: string) => void;
|
|
37
|
+
tabValues: readonly TabValue[];
|
|
38
|
+
lazy: boolean;
|
|
39
|
+
block: boolean;
|
|
40
|
+
};
|
|
41
|
+
export declare function useTabsContextValue(props: TabsProps): TabsContextValue;
|
|
42
|
+
export declare function useTabs(): TabsContextValue;
|
|
43
|
+
export declare function TabsProvider(props: {
|
|
44
|
+
children: ReactNode;
|
|
45
|
+
value: TabsContextValue;
|
|
46
|
+
}): ReactNode;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
5
|
+
*
|
|
6
|
+
* Vendored from @docusaurus/theme-common/src/utils/tabsUtils.tsx (MIT) to
|
|
7
|
+
* remove the dependency on @docusaurus/theme-common/internal. The
|
|
8
|
+
* useQueryStringValue dependency from theme-common's historyUtils is inlined
|
|
9
|
+
* below to avoid pulling another internal module.
|
|
10
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
* ========================================================================== */
|
|
15
|
+
var __createBinding =
|
|
16
|
+
(this && this.__createBinding) ||
|
|
17
|
+
(Object.create
|
|
18
|
+
? function (o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (
|
|
22
|
+
!desc ||
|
|
23
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
24
|
+
) {
|
|
25
|
+
desc = {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return m[k];
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
Object.defineProperty(o, k2, desc);
|
|
33
|
+
}
|
|
34
|
+
: function (o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
o[k2] = m[k];
|
|
37
|
+
});
|
|
38
|
+
var __setModuleDefault =
|
|
39
|
+
(this && this.__setModuleDefault) ||
|
|
40
|
+
(Object.create
|
|
41
|
+
? function (o, v) {
|
|
42
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
43
|
+
}
|
|
44
|
+
: function (o, v) {
|
|
45
|
+
o["default"] = v;
|
|
46
|
+
});
|
|
47
|
+
var __importStar =
|
|
48
|
+
(this && this.__importStar) ||
|
|
49
|
+
(function () {
|
|
50
|
+
var ownKeys = function (o) {
|
|
51
|
+
ownKeys =
|
|
52
|
+
Object.getOwnPropertyNames ||
|
|
53
|
+
function (o) {
|
|
54
|
+
var ar = [];
|
|
55
|
+
for (var k in o)
|
|
56
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
57
|
+
return ar;
|
|
58
|
+
};
|
|
59
|
+
return ownKeys(o);
|
|
60
|
+
};
|
|
61
|
+
return function (mod) {
|
|
62
|
+
if (mod && mod.__esModule) return mod;
|
|
63
|
+
var result = {};
|
|
64
|
+
if (mod != null)
|
|
65
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
66
|
+
if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
67
|
+
__setModuleDefault(result, mod);
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
})();
|
|
71
|
+
var __importDefault =
|
|
72
|
+
(this && this.__importDefault) ||
|
|
73
|
+
function (mod) {
|
|
74
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
75
|
+
};
|
|
76
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
|
+
exports.sanitizeTabsChildren = sanitizeTabsChildren;
|
|
78
|
+
exports.useTabsContextValue = useTabsContextValue;
|
|
79
|
+
exports.useTabs = useTabs;
|
|
80
|
+
exports.TabsProvider = TabsProvider;
|
|
81
|
+
const react_1 = __importStar(require("react"));
|
|
82
|
+
const router_1 = require("@docusaurus/router");
|
|
83
|
+
const theme_common_1 = require("@docusaurus/theme-common");
|
|
84
|
+
const useIsomorphicLayoutEffect_1 = __importDefault(
|
|
85
|
+
require("@docusaurus/useIsomorphicLayoutEffect")
|
|
86
|
+
);
|
|
87
|
+
const scrollUtils_1 = require("./scrollUtils");
|
|
88
|
+
function sanitizeTabsChildren(children) {
|
|
89
|
+
return react_1.default.Children.toArray(children).filter(
|
|
90
|
+
(child) => child !== "\n"
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function extractChildrenTabValues(children) {
|
|
94
|
+
function isTabItemWithValueProp(comp) {
|
|
95
|
+
const { props } = comp;
|
|
96
|
+
return !!props && typeof props === "object" && "value" in props;
|
|
97
|
+
}
|
|
98
|
+
const elements = react_1.default.Children.toArray(children).flatMap(
|
|
99
|
+
(child) => {
|
|
100
|
+
if (!child) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
if ((0, react_1.isValidElement)(child) && isTabItemWithValueProp(child)) {
|
|
104
|
+
return [child];
|
|
105
|
+
}
|
|
106
|
+
const badChildTypeName =
|
|
107
|
+
// @ts-expect-error: guarding against unexpected cases
|
|
108
|
+
typeof child.type === "string" ? child.type : child.type.name;
|
|
109
|
+
throw new Error(`Docusaurus error: Bad <Tabs> child <${badChildTypeName}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.
|
|
110
|
+
If you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.`);
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
return elements.map(
|
|
114
|
+
({ props: { value, label, attributes, default: isDefault } }) => ({
|
|
115
|
+
value,
|
|
116
|
+
label,
|
|
117
|
+
attributes,
|
|
118
|
+
default: isDefault,
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
function ensureNoDuplicateValue(values) {
|
|
123
|
+
const dup = (0, theme_common_1.duplicates)(
|
|
124
|
+
values,
|
|
125
|
+
(a, b) => a.value === b.value
|
|
126
|
+
);
|
|
127
|
+
if (dup.length > 0) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Docusaurus error: Duplicate values "${dup
|
|
130
|
+
.map((a) => `'${a.value}'`)
|
|
131
|
+
.join(", ")}" found in <Tabs>. Every value needs to be unique.`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function useTabValues(props) {
|
|
136
|
+
const { values: valuesProp, children } = props;
|
|
137
|
+
return (0, react_1.useMemo)(() => {
|
|
138
|
+
const values = valuesProp ?? extractChildrenTabValues(children);
|
|
139
|
+
ensureNoDuplicateValue(values);
|
|
140
|
+
return values;
|
|
141
|
+
}, [valuesProp, children]);
|
|
142
|
+
}
|
|
143
|
+
function isValidValue({ value, tabValues }) {
|
|
144
|
+
return tabValues.some((a) => a.value === value);
|
|
145
|
+
}
|
|
146
|
+
function getInitialStateValue({ defaultValue, tabValues }) {
|
|
147
|
+
if (tabValues.length === 0) {
|
|
148
|
+
throw new Error(
|
|
149
|
+
"Docusaurus error: the <Tabs> component requires at least one <TabItem> children component"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (defaultValue) {
|
|
153
|
+
if (!isValidValue({ value: defaultValue, tabValues })) {
|
|
154
|
+
throw new Error(
|
|
155
|
+
`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${tabValues
|
|
156
|
+
.map((a) => a.value)
|
|
157
|
+
.join(
|
|
158
|
+
", "
|
|
159
|
+
)}. If you intend to show no default tab, use defaultValue={null} instead.`
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
return defaultValue;
|
|
163
|
+
}
|
|
164
|
+
const defaultTabValue =
|
|
165
|
+
tabValues.find((tabValue) => tabValue.default) ?? tabValues[0];
|
|
166
|
+
if (!defaultTabValue) {
|
|
167
|
+
throw new Error("Unexpected error: 0 tabValues");
|
|
168
|
+
}
|
|
169
|
+
return defaultTabValue.value;
|
|
170
|
+
}
|
|
171
|
+
function getStorageKey(groupId) {
|
|
172
|
+
if (!groupId) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return `docusaurus.tab.${groupId}`;
|
|
176
|
+
}
|
|
177
|
+
function getQueryStringKey({ queryString = false, groupId }) {
|
|
178
|
+
if (typeof queryString === "string") {
|
|
179
|
+
return queryString;
|
|
180
|
+
}
|
|
181
|
+
if (queryString === false) {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
if (queryString === true && !groupId) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
`Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".`
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
return groupId ?? null;
|
|
190
|
+
}
|
|
191
|
+
// Inlined from @docusaurus/theme-common/internal historyUtils.useQueryStringValue
|
|
192
|
+
function useQueryStringValue(key) {
|
|
193
|
+
const history = (0, router_1.useHistory)();
|
|
194
|
+
return (0, react_1.useSyncExternalStore)(
|
|
195
|
+
history.listen,
|
|
196
|
+
() =>
|
|
197
|
+
key === null
|
|
198
|
+
? null
|
|
199
|
+
: new URLSearchParams(history.location.search).get(key),
|
|
200
|
+
() => null
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
function useTabQueryString({ queryString = false, groupId }) {
|
|
204
|
+
const history = (0, router_1.useHistory)();
|
|
205
|
+
const key = getQueryStringKey({ queryString, groupId });
|
|
206
|
+
const value = useQueryStringValue(key);
|
|
207
|
+
const setValue = (0, react_1.useCallback)(
|
|
208
|
+
(newValue) => {
|
|
209
|
+
if (!key) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const searchParams = new URLSearchParams(history.location.search);
|
|
213
|
+
searchParams.set(key, newValue);
|
|
214
|
+
history.replace({ ...history.location, search: searchParams.toString() });
|
|
215
|
+
},
|
|
216
|
+
[key, history]
|
|
217
|
+
);
|
|
218
|
+
return [value, setValue];
|
|
219
|
+
}
|
|
220
|
+
function useTabStorage({ groupId }) {
|
|
221
|
+
const key = getStorageKey(groupId);
|
|
222
|
+
const [value, storageSlot] = (0, theme_common_1.useStorageSlot)(key);
|
|
223
|
+
const setValue = (0, react_1.useCallback)(
|
|
224
|
+
(newValue) => {
|
|
225
|
+
if (!key) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
storageSlot.set(newValue);
|
|
229
|
+
},
|
|
230
|
+
[key, storageSlot]
|
|
231
|
+
);
|
|
232
|
+
return [value, setValue];
|
|
233
|
+
}
|
|
234
|
+
function useTabsContextValue(props) {
|
|
235
|
+
const { defaultValue, queryString = false, groupId } = props;
|
|
236
|
+
const tabValues = useTabValues(props);
|
|
237
|
+
const [selectedValue, setSelectedValue] = (0, react_1.useState)(() =>
|
|
238
|
+
getInitialStateValue({ defaultValue, tabValues })
|
|
239
|
+
);
|
|
240
|
+
const [queryStringValue, setQueryString] = useTabQueryString({
|
|
241
|
+
queryString,
|
|
242
|
+
groupId,
|
|
243
|
+
});
|
|
244
|
+
const [storageValue, setStorageValue] = useTabStorage({
|
|
245
|
+
groupId,
|
|
246
|
+
});
|
|
247
|
+
const valueToSync = (() => {
|
|
248
|
+
const value = queryStringValue ?? storageValue;
|
|
249
|
+
if (!isValidValue({ value, tabValues })) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
return value;
|
|
253
|
+
})();
|
|
254
|
+
(0, useIsomorphicLayoutEffect_1.default)(() => {
|
|
255
|
+
if (valueToSync) {
|
|
256
|
+
setSelectedValue(valueToSync);
|
|
257
|
+
}
|
|
258
|
+
}, [valueToSync]);
|
|
259
|
+
const selectValue = (0, react_1.useCallback)(
|
|
260
|
+
(newValue) => {
|
|
261
|
+
if (!isValidValue({ value: newValue, tabValues })) {
|
|
262
|
+
throw new Error(`Can't select invalid tab value=${newValue}`);
|
|
263
|
+
}
|
|
264
|
+
setSelectedValue(newValue);
|
|
265
|
+
setQueryString(newValue);
|
|
266
|
+
setStorageValue(newValue);
|
|
267
|
+
},
|
|
268
|
+
[setQueryString, setStorageValue, tabValues]
|
|
269
|
+
);
|
|
270
|
+
return {
|
|
271
|
+
selectedValue,
|
|
272
|
+
selectValue,
|
|
273
|
+
tabValues,
|
|
274
|
+
lazy: props.lazy ?? false,
|
|
275
|
+
block: props.block ?? false,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const TabsContext = (0, react_1.createContext)(null);
|
|
279
|
+
function useTabs() {
|
|
280
|
+
const contextValue = react_1.default.useContext(TabsContext);
|
|
281
|
+
if (!contextValue) {
|
|
282
|
+
throw new Error("useTabsContext() must be used within a Tabs component");
|
|
283
|
+
}
|
|
284
|
+
return contextValue;
|
|
285
|
+
}
|
|
286
|
+
function TabsProvider(props) {
|
|
287
|
+
// ScrollControllerProvider is mounted here so every tab consumer
|
|
288
|
+
// (our six OpenAPI tab variants + the swizzled @theme/Tabs) gets a working
|
|
289
|
+
// useScrollPositionBlocker without callers needing a separate provider.
|
|
290
|
+
return react_1.default.createElement(
|
|
291
|
+
scrollUtils_1.ScrollControllerProvider,
|
|
292
|
+
null,
|
|
293
|
+
react_1.default.createElement(
|
|
294
|
+
TabsContext.Provider,
|
|
295
|
+
{ value: props.value },
|
|
296
|
+
props.children
|
|
297
|
+
)
|
|
298
|
+
);
|
|
299
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
export type WordWrap = {
|
|
3
|
+
readonly codeBlockRef: RefObject<HTMLPreElement | null>;
|
|
4
|
+
readonly isEnabled: boolean;
|
|
5
|
+
readonly isCodeScrollable: boolean;
|
|
6
|
+
readonly toggle: () => void;
|
|
7
|
+
};
|
|
8
|
+
export declare function useCodeWordWrap(): WordWrap;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
5
|
+
*
|
|
6
|
+
* Vendored from @docusaurus/theme-common/src/hooks/useCodeWordWrap.ts (MIT)
|
|
7
|
+
* to remove the dependency on @docusaurus/theme-common/internal.
|
|
8
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
* ========================================================================== */
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.useCodeWordWrap = useCodeWordWrap;
|
|
15
|
+
const react_1 = require("react");
|
|
16
|
+
const useMutationObserver_1 = require("./useMutationObserver");
|
|
17
|
+
// Callback fires when the "hidden" attribute of a tabpanel changes
|
|
18
|
+
// See https://github.com/facebook/docusaurus/pull/7485
|
|
19
|
+
function useTabBecameVisibleCallback(codeBlockRef, callback) {
|
|
20
|
+
const [hiddenTabElement, setHiddenTabElement] = (0, react_1.useState)();
|
|
21
|
+
const updateHiddenTabElement = (0, react_1.useCallback)(() => {
|
|
22
|
+
setHiddenTabElement(
|
|
23
|
+
codeBlockRef.current?.closest("[role=tabpanel][hidden]")
|
|
24
|
+
);
|
|
25
|
+
}, [codeBlockRef, setHiddenTabElement]);
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
updateHiddenTabElement();
|
|
28
|
+
}, [updateHiddenTabElement]);
|
|
29
|
+
(0, useMutationObserver_1.useMutationObserver)(
|
|
30
|
+
hiddenTabElement,
|
|
31
|
+
(mutations) => {
|
|
32
|
+
mutations.forEach((mutation) => {
|
|
33
|
+
if (
|
|
34
|
+
mutation.type === "attributes" &&
|
|
35
|
+
mutation.attributeName === "hidden"
|
|
36
|
+
) {
|
|
37
|
+
callback();
|
|
38
|
+
updateHiddenTabElement();
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
attributes: true,
|
|
44
|
+
characterData: false,
|
|
45
|
+
childList: false,
|
|
46
|
+
subtree: false,
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function useCodeWordWrap() {
|
|
51
|
+
const [isEnabled, setIsEnabled] = (0, react_1.useState)(false);
|
|
52
|
+
const [isCodeScrollable, setIsCodeScrollable] = (0, react_1.useState)(false);
|
|
53
|
+
const codeBlockRef = (0, react_1.useRef)(null);
|
|
54
|
+
const toggle = (0, react_1.useCallback)(() => {
|
|
55
|
+
const codeElement = codeBlockRef.current.querySelector("code");
|
|
56
|
+
if (isEnabled) {
|
|
57
|
+
codeElement.removeAttribute("style");
|
|
58
|
+
} else {
|
|
59
|
+
codeElement.style.whiteSpace = "pre-wrap";
|
|
60
|
+
codeElement.style.overflowWrap = "anywhere";
|
|
61
|
+
}
|
|
62
|
+
setIsEnabled((value) => !value);
|
|
63
|
+
}, [codeBlockRef, isEnabled]);
|
|
64
|
+
const updateCodeIsScrollable = (0, react_1.useCallback)(() => {
|
|
65
|
+
const { scrollWidth, clientWidth } = codeBlockRef.current;
|
|
66
|
+
const isScrollable =
|
|
67
|
+
scrollWidth > clientWidth ||
|
|
68
|
+
codeBlockRef.current.querySelector("code").hasAttribute("style");
|
|
69
|
+
setIsCodeScrollable(isScrollable);
|
|
70
|
+
}, [codeBlockRef]);
|
|
71
|
+
useTabBecameVisibleCallback(codeBlockRef, updateCodeIsScrollable);
|
|
72
|
+
(0, react_1.useEffect)(() => {
|
|
73
|
+
updateCodeIsScrollable();
|
|
74
|
+
}, [isEnabled, updateCodeIsScrollable]);
|
|
75
|
+
(0, react_1.useEffect)(() => {
|
|
76
|
+
window.addEventListener("resize", updateCodeIsScrollable, {
|
|
77
|
+
passive: true,
|
|
78
|
+
});
|
|
79
|
+
return () => {
|
|
80
|
+
window.removeEventListener("resize", updateCodeIsScrollable);
|
|
81
|
+
};
|
|
82
|
+
}, [updateCodeIsScrollable]);
|
|
83
|
+
return { codeBlockRef, isEnabled, isCodeScrollable, toggle };
|
|
84
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Portions Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
4
|
+
* Portions Copyright (c) Palo Alto Networks
|
|
5
|
+
*
|
|
6
|
+
* Vendored from @docusaurus/theme-common/src/hooks/useMutationObserver.ts (MIT)
|
|
7
|
+
* to remove the dependency on @docusaurus/theme-common/internal.
|
|
8
|
+
* See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
|
|
9
|
+
*
|
|
10
|
+
* This source code is licensed under the MIT license found in the
|
|
11
|
+
* LICENSE file in the root directory of this source tree.
|
|
12
|
+
* ========================================================================== */
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.useMutationObserver = useMutationObserver;
|
|
15
|
+
const react_1 = require("react");
|
|
16
|
+
const theme_common_1 = require("@docusaurus/theme-common");
|
|
17
|
+
const reactUtils_1 = require("./reactUtils");
|
|
18
|
+
const DefaultOptions = {
|
|
19
|
+
attributes: true,
|
|
20
|
+
characterData: true,
|
|
21
|
+
childList: true,
|
|
22
|
+
subtree: true,
|
|
23
|
+
};
|
|
24
|
+
function useMutationObserver(target, callback, options = DefaultOptions) {
|
|
25
|
+
const stableCallback = (0, theme_common_1.useEvent)(callback);
|
|
26
|
+
const stableOptions = (0, reactUtils_1.useShallowMemoObject)(options);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
const observer = new MutationObserver(stableCallback);
|
|
29
|
+
if (target) {
|
|
30
|
+
observer.observe(target, stableOptions);
|
|
31
|
+
}
|
|
32
|
+
return () => observer.disconnect();
|
|
33
|
+
}, [target, stableCallback, stableOptions]);
|
|
34
|
+
}
|