docusaurus-theme-openapi-docs 0.0.0-1295 → 0.0.0-1313

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 (57) hide show
  1. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +4 -2
  2. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +9 -6
  3. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +1 -1
  4. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +1 -1
  5. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +1 -1
  6. package/lib/theme/ApiExplorer/CodeTabs/index.js +6 -5
  7. package/lib/theme/ApiTabs/index.d.ts +1 -1
  8. package/lib/theme/ApiTabs/index.js +6 -5
  9. package/lib/theme/DiscriminatorTabs/index.d.ts +1 -1
  10. package/lib/theme/DiscriminatorTabs/index.js +6 -5
  11. package/lib/theme/MimeTabs/index.d.ts +1 -1
  12. package/lib/theme/MimeTabs/index.js +6 -5
  13. package/lib/theme/OperationTabs/index.d.ts +1 -1
  14. package/lib/theme/OperationTabs/index.js +6 -5
  15. package/lib/theme/SchemaTabs/index.d.ts +1 -1
  16. package/lib/theme/SchemaTabs/index.js +6 -5
  17. package/lib/theme/TabItem/index.d.ts +5 -0
  18. package/lib/theme/TabItem/index.js +51 -0
  19. package/lib/theme/TabItem/styles.module.css +3 -0
  20. package/lib/theme/Tabs/index.d.ts +5 -0
  21. package/lib/theme/Tabs/index.js +148 -0
  22. package/lib/theme/Tabs/styles.module.css +7 -0
  23. package/lib/theme/utils/codeBlockUtils.d.ts +28 -0
  24. package/lib/theme/utils/codeBlockUtils.js +223 -0
  25. package/lib/theme/utils/reactUtils.d.ts +1 -0
  26. package/lib/theme/utils/reactUtils.js +23 -0
  27. package/lib/theme/utils/scrollUtils.d.ts +7 -0
  28. package/lib/theme/utils/scrollUtils.js +175 -0
  29. package/lib/theme/utils/tabsUtils.d.ts +47 -0
  30. package/lib/theme/utils/tabsUtils.js +299 -0
  31. package/lib/theme/utils/useCodeWordWrap.d.ts +8 -0
  32. package/lib/theme/utils/useCodeWordWrap.js +84 -0
  33. package/lib/theme/utils/useMutationObserver.d.ts +3 -0
  34. package/lib/theme/utils/useMutationObserver.js +34 -0
  35. package/package.json +4 -4
  36. package/src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx +2 -1
  37. package/src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx +8 -7
  38. package/src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx +1 -1
  39. package/src/theme/ApiExplorer/ApiCodeBlock/index.tsx +1 -1
  40. package/src/theme/ApiExplorer/CodeTabs/index.tsx +5 -5
  41. package/src/theme/ApiTabs/index.tsx +7 -6
  42. package/src/theme/DiscriminatorTabs/index.tsx +6 -5
  43. package/src/theme/MimeTabs/index.tsx +9 -8
  44. package/src/theme/OperationTabs/index.tsx +5 -4
  45. package/src/theme/SchemaTabs/index.tsx +6 -5
  46. package/src/theme/TabItem/index.tsx +61 -0
  47. package/src/theme/TabItem/styles.module.css +3 -0
  48. package/src/theme/Tabs/index.tsx +164 -0
  49. package/src/theme/Tabs/styles.module.css +7 -0
  50. package/src/theme/utils/codeBlockUtils.ts +296 -0
  51. package/src/theme/utils/reactUtils.ts +22 -0
  52. package/src/theme/utils/scrollUtils.tsx +153 -0
  53. package/src/theme/utils/tabsUtils.tsx +329 -0
  54. package/src/theme/utils/useCodeWordWrap.ts +110 -0
  55. package/src/theme/utils/useMutationObserver.ts +43 -0
  56. package/src/theme-classic.d.ts +0 -96
  57. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,61 @@
1
+ /* ============================================================================
2
+ * Portions Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ * Portions Copyright (c) Palo Alto Networks
4
+ *
5
+ * Swizzled from @docusaurus/theme-classic/src/theme/TabItem/index.tsx (MIT).
6
+ * Re-points useTabs to our vendored tabsUtils so that <TabItem> reads the same
7
+ * context our swizzled <Tabs> and OpenAPI tab variants (ApiTabs, MimeTabs,
8
+ * SchemaTabs, etc.) provide. See:
9
+ * https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
10
+ *
11
+ * This source code is licensed under the MIT license found in the
12
+ * LICENSE file in the root directory of this source tree.
13
+ * ========================================================================== */
14
+
15
+ import React, { type ReactNode } from "react";
16
+
17
+ import clsx from "clsx";
18
+
19
+ import { type TabItemProps, useTabs } from "@theme/utils/tabsUtils";
20
+
21
+ type Props = TabItemProps;
22
+ import styles from "./styles.module.css";
23
+
24
+ function TabItemPanel({
25
+ children,
26
+ className,
27
+ hidden,
28
+ }: {
29
+ children: ReactNode;
30
+ className?: string;
31
+ hidden?: boolean;
32
+ }) {
33
+ return (
34
+ <div
35
+ role="tabpanel"
36
+ className={clsx(styles.tabItem, className)}
37
+ {...{ hidden }}
38
+ >
39
+ {children}
40
+ </div>
41
+ );
42
+ }
43
+
44
+ export default function TabItem({
45
+ children,
46
+ className,
47
+ value,
48
+ }: Props): ReactNode {
49
+ const { selectedValue, lazy } = useTabs();
50
+ const isSelected = value === selectedValue;
51
+
52
+ if (!isSelected && lazy) {
53
+ return null;
54
+ }
55
+
56
+ return (
57
+ <TabItemPanel className={className} hidden={!isSelected}>
58
+ {children}
59
+ </TabItemPanel>
60
+ );
61
+ }
@@ -0,0 +1,3 @@
1
+ .tabItem > *:last-child {
2
+ margin-bottom: 0;
3
+ }
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ .tabList {
2
+ margin-bottom: var(--ifm-leading);
3
+ }
4
+
5
+ .tabItem {
6
+ margin-top: 0 !important;
7
+ }
@@ -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
+ }