docusaurus-theme-openapi-docs 3.0.0-beta.2 → 3.0.0-beta.4

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 (110) hide show
  1. package/lib/markdown/utils.d.ts +3 -2
  2. package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.d.ts +13 -0
  3. package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +199 -124
  4. package/lib/theme/ApiExplorer/Accept/index.d.ts +2 -2
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
  6. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
  7. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
  8. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
  9. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
  10. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +115 -96
  11. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
  12. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
  13. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
  14. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
  15. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
  16. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +200 -120
  17. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
  18. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
  19. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
  20. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
  21. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
  22. package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
  23. package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
  24. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +1 -1
  25. package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
  26. package/lib/theme/ApiExplorer/Body/slice.d.ts +3 -3
  27. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +2 -2
  28. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +4 -2
  29. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +11 -0
  30. package/lib/theme/ApiExplorer/CodeTabs/index.js +125 -78
  31. package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
  32. package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
  33. package/lib/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  34. package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
  35. package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
  36. package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
  37. package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
  38. package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
  39. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
  40. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
  41. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
  42. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
  43. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
  44. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +4 -4
  45. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
  46. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
  47. package/lib/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  48. package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
  49. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +1 -1
  50. package/lib/theme/ApiExplorer/Request/_Request.scss +4 -2
  51. package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
  52. package/lib/theme/ApiExplorer/Response/_Response.scss +4 -2
  53. package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
  54. package/lib/theme/ApiExplorer/Response/index.js +19 -19
  55. package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
  56. package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
  57. package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +1 -1
  58. package/lib/theme/ApiExplorer/index.d.ts +2 -2
  59. package/lib/theme/ApiExplorer/storage-utils.d.ts +1 -1
  60. package/lib/theme/ApiItem/index.d.ts +2 -2
  61. package/lib/theme/ApiItem/index.js +4 -3
  62. package/lib/theme/ApiItem/store.d.ts +6 -6
  63. package/lib/theme/ApiLogo/index.d.ts +2 -2
  64. package/lib/theme/ApiTabs/index.d.ts +3 -0
  65. package/lib/theme/ApiTabs/index.js +148 -98
  66. package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
  67. package/lib/theme/DiscriminatorTabs/index.js +146 -94
  68. package/lib/theme/MimeTabs/index.d.ts +6 -0
  69. package/lib/theme/MimeTabs/index.js +163 -114
  70. package/lib/theme/ParamsItem/index.d.ts +22 -0
  71. package/lib/theme/ParamsItem/index.js +156 -111
  72. package/lib/theme/ResponseSamples/index.d.ts +8 -0
  73. package/lib/theme/ResponseSamples/index.js +18 -13
  74. package/lib/theme/SchemaItem/index.d.ts +12 -0
  75. package/lib/theme/SchemaItem/index.js +123 -89
  76. package/lib/theme/SchemaTabs/index.d.ts +3 -0
  77. package/lib/theme/SchemaTabs/index.js +142 -91
  78. package/lib/types.d.ts +4 -4
  79. package/package.json +8 -7
  80. package/src/markdown/utils.ts +4 -2
  81. package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
  82. package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
  83. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
  84. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +4 -4
  85. package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
  86. package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
  87. package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +12 -2
  88. package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
  89. package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
  90. package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
  91. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +4 -2
  92. package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +48 -25
  93. package/src/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  94. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +4 -4
  95. package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  96. package/src/theme/ApiExplorer/Request/_Request.scss +4 -2
  97. package/src/theme/ApiExplorer/Response/_Response.scss +4 -2
  98. package/src/theme/ApiExplorer/Response/index.tsx +2 -2
  99. package/src/theme/ApiItem/index.tsx +3 -4
  100. package/src/theme/ApiLogo/index.tsx +1 -1
  101. package/src/theme/ApiTabs/{index.js → index.tsx} +56 -25
  102. package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
  103. package/src/theme/MimeTabs/{index.js → index.tsx} +58 -26
  104. package/src/theme/ParamsItem/{index.js → index.tsx} +30 -15
  105. package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
  106. package/src/theme/SchemaItem/{index.js → index.tsx} +18 -9
  107. package/src/theme/SchemaTabs/{index.js → index.tsx} +56 -25
  108. package/src/theme-classic.d.ts +69 -2
  109. package/src/theme-openapi.d.ts +2 -0
  110. package/tsconfig.json +4 -1
@@ -5,31 +5,55 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React, { cloneElement, useRef, useEffect, useState } from "react";
8
+ import React, {
9
+ cloneElement,
10
+ useRef,
11
+ useEffect,
12
+ useState,
13
+ ReactElement,
14
+ } from "react";
9
15
 
10
16
  import {
17
+ sanitizeTabsChildren,
18
+ TabProps,
11
19
  useScrollPositionBlocker,
12
20
  useTabs,
13
21
  } from "@docusaurus/theme-common/internal";
22
+ import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
14
23
  import useIsBrowser from "@docusaurus/useIsBrowser";
15
24
  import clsx from "clsx";
16
25
  import flatten from "lodash/flatten";
17
26
 
18
- function TabList({ className, block, selectedValue, selectValue, tabValues }) {
19
- const tabRefs = [];
27
+ function TabList({
28
+ className,
29
+ block,
30
+ selectedValue,
31
+ selectValue,
32
+ tabValues,
33
+ }: TabProps & ReturnType<typeof useTabs>) {
34
+ const tabRefs: (HTMLLIElement | null)[] = [];
20
35
  const { blockElementScrollPositionUntilNextRender } =
21
36
  useScrollPositionBlocker();
22
- const handleTabChange = (event) => {
37
+
38
+ const handleTabChange = (
39
+ event:
40
+ | React.FocusEvent<HTMLLIElement>
41
+ | React.MouseEvent<HTMLLIElement>
42
+ | React.KeyboardEvent<HTMLLIElement>
43
+ ) => {
23
44
  const newTab = event.currentTarget;
24
45
  const newTabIndex = tabRefs.indexOf(newTab);
25
46
  const newTabValue = tabValues[newTabIndex].value;
47
+
26
48
  if (newTabValue !== selectedValue) {
27
49
  blockElementScrollPositionUntilNextRender(newTab);
28
50
  selectValue(newTabValue);
29
51
  }
30
52
  };
31
- const handleKeydown = (event) => {
32
- let focusElement = null;
53
+
54
+ const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
55
+ let focusElement: HTMLLIElement | null = null;
56
+
33
57
  switch (event.key) {
34
58
  case "Enter": {
35
59
  handleTabChange(event);
@@ -37,27 +61,28 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
37
61
  }
38
62
  case "ArrowRight": {
39
63
  const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
40
- focusElement = tabRefs[nextTab] ?? tabRefs[0];
64
+ focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
41
65
  break;
42
66
  }
43
67
  case "ArrowLeft": {
44
68
  const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
45
- focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
69
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
46
70
  break;
47
71
  }
48
72
  default:
49
73
  break;
50
74
  }
75
+
51
76
  focusElement?.focus();
52
77
  };
53
78
 
54
- const tabItemListContainerRef = useRef(null);
55
- const [showTabArrows, setShowTabArrows] = useState(false);
79
+ const tabItemListContainerRef = useRef<HTMLUListElement>(null);
80
+ const [showTabArrows, setShowTabArrows] = useState<boolean>(false);
56
81
 
57
82
  useEffect(() => {
58
83
  const resizeObserver = new ResizeObserver((entries) => {
59
84
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
85
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
61
86
  setShowTabArrows(true);
62
87
  } else {
63
88
  setShowTabArrows(false);
@@ -65,7 +90,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
65
90
  }
66
91
  });
67
92
 
68
- resizeObserver.observe(tabItemListContainerRef.current);
93
+ resizeObserver.observe(tabItemListContainerRef.current!);
69
94
 
70
95
  return () => {
71
96
  resizeObserver.disconnect();
@@ -73,11 +98,11 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
73
98
  }, []);
74
99
 
75
100
  const handleRightClick = () => {
76
- tabItemListContainerRef.current.scrollLeft += 90;
101
+ tabItemListContainerRef.current!.scrollLeft += 90;
77
102
  };
78
103
 
79
104
  const handleLeftClick = () => {
80
- tabItemListContainerRef.current.scrollLeft -= 90;
105
+ tabItemListContainerRef.current!.scrollLeft -= 90;
81
106
  };
82
107
 
83
108
  return (
@@ -115,7 +140,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
115
140
  className={clsx(
116
141
  "tabs__item",
117
142
  "openapi-tabs__schema-item",
118
- attributes?.className,
143
+ attributes?.className as string,
119
144
  {
120
145
  active: selectedValue === value,
121
146
  }
@@ -134,13 +159,17 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
134
159
  </div>
135
160
  );
136
161
  }
137
- function TabContent({ lazy, children, selectedValue }) {
138
- // eslint-disable-next-line no-param-reassign
139
- children = Array.isArray(children) ? children : [children];
140
- const flattenedChildren = flatten(children);
141
-
162
+ function TabContent({
163
+ lazy,
164
+ children,
165
+ selectedValue,
166
+ }: TabProps & ReturnType<typeof useTabs>) {
167
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
168
+ Boolean
169
+ ) as ReactElement<TabItemProps>[];
170
+ const flattenedChildTabs = flatten(childTabs);
142
171
  if (lazy) {
143
- const selectedTabItem = flattenedChildren.find(
172
+ const selectedTabItem = flattenedChildTabs.find(
144
173
  (tabItem) => tabItem.props.value === selectedValue
145
174
  );
146
175
  if (!selectedTabItem) {
@@ -151,7 +180,7 @@ function TabContent({ lazy, children, selectedValue }) {
151
180
  }
152
181
  return (
153
182
  <div className="margin-top--md">
154
- {children.map((tabItem, i) =>
183
+ {childTabs.map((tabItem, i) =>
155
184
  cloneElement(tabItem, {
156
185
  key: i,
157
186
  hidden: tabItem.props.value !== selectedValue,
@@ -160,7 +189,7 @@ function TabContent({ lazy, children, selectedValue }) {
160
189
  </div>
161
190
  );
162
191
  }
163
- function TabsComponent(props) {
192
+ function TabsComponent(props: TabProps): React.JSX.Element {
164
193
  const tabs = useTabs(props);
165
194
  return (
166
195
  <div className="openapi-tabs__schema-container">
@@ -169,7 +198,7 @@ function TabsComponent(props) {
169
198
  </div>
170
199
  );
171
200
  }
172
- export default function SchemaTabs(props) {
201
+ export default function SchemaTabs(props: TabProps): React.JSX.Element {
173
202
  const isBrowser = useIsBrowser();
174
203
  return (
175
204
  <TabsComponent
@@ -177,6 +206,8 @@ export default function SchemaTabs(props) {
177
206
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
178
207
  key={String(isBrowser)}
179
208
  {...props}
180
- />
209
+ >
210
+ {sanitizeTabsChildren(props.children)}
211
+ </TabsComponent>
181
212
  );
182
213
  }
@@ -8,6 +8,73 @@
8
8
  /// <reference types="@docusaurus/theme-classic" />
9
9
 
10
10
  declare module "@docusaurus/theme-common/internal" {
11
- function useDoc(): any;
12
- export const { useDoc };
11
+ import { CSSProperties, ReactNode, RefObject } from "react";
12
+
13
+ import type { PropDocContent } from "@docusaurus/plugin-content-docs";
14
+ import { MagicCommentConfig } from "@docusaurus/theme-common/lib/utils/codeBlockUtils";
15
+ import {
16
+ TabsProps as ITabsProps,
17
+ TabValue,
18
+ } from "@docusaurus/theme-common/lib/utils/tabsUtils";
19
+ import { Props as ICodeBlockProps } from "@theme/CodeBlock";
20
+ import { Props as ICopyButtonProps } from "@theme/CodeBlock/CopyButton";
21
+ import { Props as ILineProps } from "@theme/CodeBlock/Line";
22
+ import { PrismTheme } from "prism-react-renderer";
23
+
24
+ export interface TabProps extends ITabsProps {}
25
+
26
+ export interface CopyButtonProps extends ICopyButtonProps {}
27
+ export interface LineProps extends ILineProps {}
28
+ export interface CodeBlockProps extends ICodeBlockProps {}
29
+
30
+ export function useDoc();
31
+
32
+ export function usePrismTheme(): PrismTheme;
33
+
34
+ export function sanitizeTabsChildren(children: TabProps["children"]);
35
+
36
+ export function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties;
37
+
38
+ export function parseCodeBlockTitle(metastring?: string): string;
39
+
40
+ export function parseLanguage(className: string): string | undefined;
41
+
42
+ export function containsLineNumbers(metastring?: string): boolean;
43
+
44
+ export function useScrollPositionBlocker(): {
45
+ blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
46
+ };
47
+
48
+ export function DocProvider({
49
+ children,
50
+ content,
51
+ }: {
52
+ children: ReactNode;
53
+ content: PropDocContent;
54
+ });
55
+
56
+ export function useTabs(props: TabProps): {
57
+ selectedValue: string;
58
+ selectValue: (value: string) => void;
59
+ tabValues: readonly TabValue[];
60
+ };
61
+
62
+ export function parseLines(
63
+ content: string,
64
+ options: {
65
+ metastring: string | undefined;
66
+ language: string | undefined;
67
+ magicComments: MagicCommentConfig[];
68
+ }
69
+ ): {
70
+ lineClassNames: { [lineIndex: number]: string[] };
71
+ code: string;
72
+ };
73
+
74
+ export function useCodeWordWrap(): {
75
+ readonly codeBlockRef: RefObject<HTMLPreElement>;
76
+ readonly isEnabled: boolean;
77
+ readonly isCodeScrollable: boolean;
78
+ readonly toggle: () => void;
79
+ };
13
80
  }
@@ -7,6 +7,8 @@
7
7
 
8
8
  /// <reference types="docusaurus-plugin-openapi-docs" />
9
9
 
10
+ /* eslint-disable @typescript-eslint/no-use-before-define */
11
+
10
12
  declare module "@docusaurus/plugin-content-docs-types" {
11
13
  // Makes all properties visible when hovering over the type
12
14
  type Expand<T extends Record<string, unknown>> = { [P in keyof T]: T[P] };
package/tsconfig.json CHANGED
@@ -7,7 +7,10 @@
7
7
  "target": "ESNext",
8
8
  "noEmit": false,
9
9
  "outDir": "lib",
10
- "jsx": "react"
10
+ "jsx": "react",
11
+ "paths": {
12
+ "@theme/*": ["./src/theme/*"]
13
+ }
11
14
  },
12
15
  "include": ["src"]
13
16
  }