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.
Files changed (114) hide show
  1. package/lib/markdown/schema.js +4 -5
  2. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +4 -2
  3. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +9 -6
  4. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +1 -1
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +1 -1
  6. package/lib/theme/ApiExplorer/Authorization/index.js +9 -10
  7. package/lib/theme/ApiExplorer/Body/index.js +4 -5
  8. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +1 -1
  9. package/lib/theme/ApiExplorer/CodeTabs/index.js +6 -5
  10. package/lib/theme/ApiExplorer/Export/index.js +9 -2
  11. package/lib/theme/ApiExplorer/FormFileUpload/index.js +1 -2
  12. package/lib/theme/ApiExplorer/FormLabel/index.js +1 -2
  13. package/lib/theme/ApiExplorer/FormTextInput/index.js +1 -2
  14. package/lib/theme/ApiExplorer/LiveEditor/index.js +1 -2
  15. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +5 -3
  16. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +1 -2
  17. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +1 -2
  18. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +1 -2
  19. package/lib/theme/ApiExplorer/ParamOptions/index.js +2 -3
  20. package/lib/theme/ApiExplorer/Request/index.js +17 -18
  21. package/lib/theme/ApiExplorer/Response/index.js +7 -11
  22. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +57 -50
  23. package/lib/theme/ApiExplorer/Server/index.js +2 -3
  24. package/lib/theme/ApiTabs/index.d.ts +1 -1
  25. package/lib/theme/ApiTabs/index.js +7 -7
  26. package/lib/theme/DiscriminatorTabs/index.d.ts +1 -1
  27. package/lib/theme/DiscriminatorTabs/index.js +6 -5
  28. package/lib/theme/Example/index.js +3 -4
  29. package/lib/theme/MimeTabs/index.d.ts +1 -1
  30. package/lib/theme/MimeTabs/index.js +6 -5
  31. package/lib/theme/OperationTabs/index.d.ts +1 -1
  32. package/lib/theme/OperationTabs/index.js +6 -5
  33. package/lib/theme/ParamsDetails/index.js +1 -2
  34. package/lib/theme/ParamsItem/index.js +7 -8
  35. package/lib/theme/RequestSchema/index.js +4 -6
  36. package/lib/theme/ResponseExamples/index.js +3 -4
  37. package/lib/theme/ResponseSchema/index.js +2 -3
  38. package/lib/theme/Schema/index.js +8 -9
  39. package/lib/theme/SchemaExpansion/index.js +4 -5
  40. package/lib/theme/SchemaItem/index.js +9 -10
  41. package/lib/theme/SchemaTabs/index.d.ts +1 -1
  42. package/lib/theme/SchemaTabs/index.js +6 -5
  43. package/lib/theme/StatusCodes/index.js +2 -4
  44. package/lib/theme/TabItem/index.d.ts +5 -0
  45. package/lib/theme/TabItem/index.js +51 -0
  46. package/lib/theme/TabItem/styles.module.css +3 -0
  47. package/lib/theme/Tabs/index.d.ts +5 -0
  48. package/lib/theme/Tabs/index.js +148 -0
  49. package/lib/theme/Tabs/styles.module.css +7 -0
  50. package/lib/theme/translationIds.d.ts +1 -99
  51. package/lib/theme/translationIds.js +0 -116
  52. package/lib/theme/utils/codeBlockUtils.d.ts +28 -0
  53. package/lib/theme/utils/codeBlockUtils.js +223 -0
  54. package/lib/theme/utils/reactUtils.d.ts +1 -0
  55. package/lib/theme/utils/reactUtils.js +23 -0
  56. package/lib/theme/utils/scrollUtils.d.ts +7 -0
  57. package/lib/theme/utils/scrollUtils.js +175 -0
  58. package/lib/theme/utils/tabsUtils.d.ts +47 -0
  59. package/lib/theme/utils/tabsUtils.js +299 -0
  60. package/lib/theme/utils/useCodeWordWrap.d.ts +8 -0
  61. package/lib/theme/utils/useCodeWordWrap.js +84 -0
  62. package/lib/theme/utils/useMutationObserver.d.ts +3 -0
  63. package/lib/theme/utils/useMutationObserver.js +34 -0
  64. package/package.json +4 -4
  65. package/src/markdown/schema.ts +4 -5
  66. package/src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx +2 -1
  67. package/src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx +8 -7
  68. package/src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx +1 -1
  69. package/src/theme/ApiExplorer/ApiCodeBlock/index.tsx +1 -1
  70. package/src/theme/ApiExplorer/Authorization/index.tsx +9 -10
  71. package/src/theme/ApiExplorer/Body/index.tsx +7 -5
  72. package/src/theme/ApiExplorer/CodeTabs/index.tsx +5 -5
  73. package/src/theme/ApiExplorer/Export/index.tsx +6 -2
  74. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +1 -2
  75. package/src/theme/ApiExplorer/FormLabel/index.tsx +1 -2
  76. package/src/theme/ApiExplorer/FormTextInput/index.tsx +1 -2
  77. package/src/theme/ApiExplorer/LiveEditor/index.tsx +1 -2
  78. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +5 -3
  79. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +1 -2
  80. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +1 -2
  81. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +1 -2
  82. package/src/theme/ApiExplorer/ParamOptions/index.tsx +2 -3
  83. package/src/theme/ApiExplorer/Request/index.tsx +23 -18
  84. package/src/theme/ApiExplorer/Response/index.tsx +10 -8
  85. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +60 -52
  86. package/src/theme/ApiExplorer/Server/index.tsx +8 -3
  87. package/src/theme/ApiTabs/index.tsx +8 -8
  88. package/src/theme/DiscriminatorTabs/index.tsx +6 -5
  89. package/src/theme/Example/index.tsx +3 -4
  90. package/src/theme/MimeTabs/index.tsx +9 -8
  91. package/src/theme/OperationTabs/index.tsx +5 -4
  92. package/src/theme/ParamsDetails/index.tsx +1 -2
  93. package/src/theme/ParamsItem/index.tsx +13 -8
  94. package/src/theme/RequestSchema/index.tsx +4 -5
  95. package/src/theme/ResponseExamples/index.tsx +3 -4
  96. package/src/theme/ResponseSchema/index.tsx +2 -3
  97. package/src/theme/Schema/index.tsx +8 -9
  98. package/src/theme/SchemaExpansion/index.tsx +4 -5
  99. package/src/theme/SchemaItem/index.tsx +18 -10
  100. package/src/theme/SchemaTabs/index.tsx +6 -5
  101. package/src/theme/StatusCodes/index.tsx +2 -3
  102. package/src/theme/TabItem/index.tsx +61 -0
  103. package/src/theme/TabItem/styles.module.css +3 -0
  104. package/src/theme/Tabs/index.tsx +164 -0
  105. package/src/theme/Tabs/styles.module.css +7 -0
  106. package/src/theme/translationIds.ts +37 -113
  107. package/src/theme/utils/codeBlockUtils.ts +296 -0
  108. package/src/theme/utils/reactUtils.ts +22 -0
  109. package/src/theme/utils/scrollUtils.tsx +153 -0
  110. package/src/theme/utils/tabsUtils.tsx +329 -0
  111. package/src/theme/utils/useCodeWordWrap.ts +110 -0
  112. package/src/theme/utils/useMutationObserver.ts +43 -0
  113. package/src/theme-classic.d.ts +0 -96
  114. package/tsconfig.tsbuildinfo +1 -1
@@ -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,3 @@
1
+ type Options = MutationObserverInit;
2
+ export declare function useMutationObserver(target: Element | undefined | null, callback: MutationCallback, options?: Options): void;
3
+ export {};
@@ -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
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-theme-openapi-docs",
3
3
  "description": "OpenAPI theme for Docusaurus.",
4
- "version": "0.0.0-1294",
4
+ "version": "0.0.0-1310",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -37,8 +37,8 @@
37
37
  "@types/pako": "^2.0.3",
38
38
  "@types/postman-collection": "^3.5.11",
39
39
  "@types/react-modal": "^3.16.3",
40
- "concurrently": "^9.2.0",
41
- "docusaurus-plugin-openapi-docs": "0.0.0-1294",
40
+ "concurrently": "^10.0.3",
41
+ "docusaurus-plugin-openapi-docs": "0.0.0-1310",
42
42
  "docusaurus-plugin-sass": "^0.2.6",
43
43
  "eslint-plugin-prettier": "^5.5.1"
44
44
  },
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14"
84
84
  },
85
- "gitHead": "dcce97d6a3cae4f76af8f02e81571e8ce5a394ac"
85
+ "gitHead": "349c9aa5c4072ee8a0d36c848b55bd121dbfdb85"
86
86
  }
@@ -7,7 +7,6 @@
7
7
 
8
8
  import { translate } from "@docusaurus/Translate";
9
9
 
10
- import { OPENAPI_SCHEMA_ITEM } from "../theme/translationIds";
11
10
  import { SchemaObject } from "../types";
12
11
 
13
12
  /**
@@ -158,7 +157,7 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
158
157
  }
159
158
 
160
159
  let message = `**${translate({
161
- id: OPENAPI_SCHEMA_ITEM.POSSIBLE_VALUES,
160
+ id: "theme.openapi.schemaItem.possibleValues",
162
161
  message: "Possible values:",
163
162
  })}** `;
164
163
 
@@ -177,11 +176,11 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
177
176
  let minLength;
178
177
  let maxLength;
179
178
  const charactersMessage = translate({
180
- id: OPENAPI_SCHEMA_ITEM.CHARACTERS,
179
+ id: "theme.openapi.schemaItem.characters",
181
180
  message: "characters",
182
181
  });
183
182
  const nonEmptyMessage = translate({
184
- id: OPENAPI_SCHEMA_ITEM.NON_EMPTY,
183
+ id: "theme.openapi.schemaItem.nonEmpty",
185
184
  message: "non-empty",
186
185
  });
187
186
  if (schema.minLength && schema.minLength > 1) {
@@ -246,7 +245,7 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
246
245
 
247
246
  if (schema.pattern) {
248
247
  const expressionMessage = translate({
249
- id: OPENAPI_SCHEMA_ITEM.EXPRESSION,
248
+ id: "theme.openapi.schemaItem.expression",
250
249
  message: "Value must match regular expression",
251
250
  });
252
251
  qualifierGroups.push(`${expressionMessage} \`${schema.pattern}\``);
@@ -8,9 +8,10 @@
8
8
  import React, { ComponentProps } from "react";
9
9
 
10
10
  import { ThemeClassNames, usePrismTheme } from "@docusaurus/theme-common";
11
- import { getPrismCssVariables } from "@docusaurus/theme-common/internal";
12
11
  import clsx from "clsx";
13
12
 
13
+ import { getPrismCssVariables } from "@theme/utils/codeBlockUtils";
14
+
14
15
  export default function CodeBlockContainer<T extends "div" | "pre">({
15
16
  as: As,
16
17
  ...props
@@ -8,13 +8,6 @@
8
8
  import React from "react";
9
9
 
10
10
  import { useThemeConfig, usePrismTheme } from "@docusaurus/theme-common";
11
- import {
12
- parseCodeBlockTitle,
13
- parseLanguage,
14
- parseLines,
15
- containsLineNumbers,
16
- useCodeWordWrap,
17
- } from "@docusaurus/theme-common/internal";
18
11
  import Container from "@theme/ApiExplorer/ApiCodeBlock/Container";
19
12
  import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
20
13
  import ExpandButton from "@theme/ApiExplorer/ApiCodeBlock/ExpandButton";
@@ -24,6 +17,14 @@ import type { Props } from "@theme/CodeBlock/Content/String";
24
17
  import clsx from "clsx";
25
18
  import { Highlight, Language } from "prism-react-renderer";
26
19
 
20
+ import {
21
+ containsLineNumbers,
22
+ parseCodeBlockTitle,
23
+ parseLanguage,
24
+ parseLines,
25
+ } from "@theme/utils/codeBlockUtils";
26
+ import { useCodeWordWrap } from "@theme/utils/useCodeWordWrap";
27
+
27
28
  export default function CodeBlockString({
28
29
  children,
29
30
  className: blockClassName = "",
@@ -7,7 +7,7 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
- import { LineProps } from "@docusaurus/theme-common/internal";
10
+ import type { Props as LineProps } from "@theme/CodeBlock/Line";
11
11
  import clsx from "clsx";
12
12
 
13
13
  export default function CodeBlockLine({
@@ -7,8 +7,8 @@
7
7
 
8
8
  import React, { isValidElement, ReactNode } from "react";
9
9
 
10
- import { CodeBlockProps } from "@docusaurus/theme-common/internal";
11
10
  import useIsBrowser from "@docusaurus/useIsBrowser";
11
+ import type { Props as CodeBlockProps } from "@theme/CodeBlock";
12
12
  import ElementContent from "@theme/ApiExplorer/ApiCodeBlock/Content/Element";
13
13
  import StringContent from "@theme/ApiExplorer/ApiCodeBlock/Content/String";
14
14
 
@@ -12,7 +12,6 @@ import FormItem from "@theme/ApiExplorer/FormItem";
12
12
  import FormSelect from "@theme/ApiExplorer/FormSelect";
13
13
  import FormTextInput from "@theme/ApiExplorer/FormTextInput";
14
14
  import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
15
- import { OPENAPI_AUTH } from "@theme/translationIds";
16
15
 
17
16
  import { setAuthData, setSelectedAuth } from "./slice";
18
17
 
@@ -37,7 +36,7 @@ function Authorization() {
37
36
  <FormItem>
38
37
  <FormSelect
39
38
  label={translate({
40
- id: OPENAPI_AUTH.SECURITY_SCHEME,
39
+ id: "theme.openapi.auth.securityScheme",
41
40
  message: "Security Scheme",
42
41
  })}
43
42
  options={optionKeys}
@@ -54,11 +53,11 @@ function Authorization() {
54
53
  <FormItem key={a.key + "-bearer"}>
55
54
  <FormTextInput
56
55
  label={translate({
57
- id: OPENAPI_AUTH.BEARER_TOKEN,
56
+ id: "theme.openapi.auth.bearerToken",
58
57
  message: "Bearer Token",
59
58
  })}
60
59
  placeholder={translate({
61
- id: OPENAPI_AUTH.BEARER_TOKEN,
60
+ id: "theme.openapi.auth.bearerToken",
62
61
  message: "Bearer Token",
63
62
  })}
64
63
  password
@@ -83,11 +82,11 @@ function Authorization() {
83
82
  <FormItem key={a.key + "-oauth2"}>
84
83
  <FormTextInput
85
84
  label={translate({
86
- id: OPENAPI_AUTH.BEARER_TOKEN,
85
+ id: "theme.openapi.auth.bearerToken",
87
86
  message: "Bearer Token",
88
87
  })}
89
88
  placeholder={translate({
90
- id: OPENAPI_AUTH.BEARER_TOKEN,
89
+ id: "theme.openapi.auth.bearerToken",
91
90
  message: "Bearer Token",
92
91
  })}
93
92
  password
@@ -113,11 +112,11 @@ function Authorization() {
113
112
  <FormItem>
114
113
  <FormTextInput
115
114
  label={translate({
116
- id: OPENAPI_AUTH.USERNAME,
115
+ id: "theme.openapi.auth.username",
117
116
  message: "Username",
118
117
  })}
119
118
  placeholder={translate({
120
- id: OPENAPI_AUTH.USERNAME,
119
+ id: "theme.openapi.auth.username",
121
120
  message: "Username",
122
121
  })}
123
122
  value={data[a.key].username ?? ""}
@@ -136,11 +135,11 @@ function Authorization() {
136
135
  <FormItem>
137
136
  <FormTextInput
138
137
  label={translate({
139
- id: OPENAPI_AUTH.PASSWORD,
138
+ id: "theme.openapi.auth.password",
140
139
  message: "Password",
141
140
  })}
142
141
  placeholder={translate({
143
- id: OPENAPI_AUTH.PASSWORD,
142
+ id: "theme.openapi.auth.password",
144
143
  message: "Password",
145
144
  })}
146
145
  password