docusaurus-theme-openapi-docs 0.0.0-740 → 0.0.0-750

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 (97) hide show
  1. package/lib/markdown/utils.d.ts +2 -1
  2. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
  3. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
  4. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
  6. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
  7. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +116 -97
  8. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
  9. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
  10. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
  11. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
  12. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
  13. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +201 -121
  14. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
  15. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
  16. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
  17. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
  18. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
  19. package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
  20. package/lib/theme/ApiExplorer/Body/slice.d.ts +8 -8
  21. package/lib/theme/ApiExplorer/CodeSnippets/index.js +2 -2
  22. package/lib/theme/ApiExplorer/CodeSnippets/languages.json +1290 -0
  23. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +4 -2
  24. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +15 -0
  25. package/lib/theme/ApiExplorer/CodeTabs/index.js +122 -76
  26. package/lib/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  27. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +4 -4
  28. package/lib/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  29. package/lib/theme/ApiExplorer/Request/_Request.scss +4 -6
  30. package/lib/theme/ApiExplorer/Response/_Response.scss +4 -2
  31. package/lib/theme/ApiExplorer/Response/index.js +23 -20
  32. package/lib/theme/ApiExplorer/index.js +0 -4
  33. package/lib/theme/ApiExplorer/persistanceMiddleware.js +6 -6
  34. package/lib/theme/ApiItem/Layout/index.js +3 -0
  35. package/lib/theme/ApiItem/index.js +6 -5
  36. package/lib/theme/ApiLogo/index.d.ts +2 -2
  37. package/lib/theme/ApiTabs/_ApiTabs.scss +3 -1
  38. package/lib/theme/ApiTabs/index.d.ts +7 -0
  39. package/lib/theme/ApiTabs/index.js +152 -98
  40. package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
  41. package/lib/theme/DiscriminatorTabs/index.js +146 -94
  42. package/lib/theme/MimeTabs/index.d.ts +6 -0
  43. package/lib/theme/MimeTabs/index.js +163 -114
  44. package/lib/theme/OperationTabs/_OperationTabs.scss +4 -1
  45. package/lib/theme/OperationTabs/index.d.ts +3 -0
  46. package/lib/theme/OperationTabs/index.js +148 -103
  47. package/lib/theme/ParamsItem/index.d.ts +23 -0
  48. package/lib/theme/ParamsItem/index.js +168 -123
  49. package/lib/theme/ResponseSamples/index.d.ts +8 -0
  50. package/lib/theme/ResponseSamples/index.js +18 -13
  51. package/lib/theme/SchemaItem/index.d.ts +12 -0
  52. package/lib/theme/SchemaItem/index.js +123 -88
  53. package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  54. package/lib/theme/SchemaTabs/index.d.ts +3 -0
  55. package/lib/theme/SchemaTabs/index.js +148 -93
  56. package/lib/theme/styles.scss +4 -0
  57. package/package.json +8 -7
  58. package/src/markdown/utils.ts +4 -2
  59. package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
  60. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
  61. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +5 -5
  62. package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
  63. package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
  64. package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +13 -3
  65. package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
  66. package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
  67. package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
  68. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +3 -5
  69. package/src/theme/ApiExplorer/CodeSnippets/languages.json +1290 -0
  70. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +4 -2
  71. package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +56 -26
  72. package/src/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  73. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +4 -4
  74. package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  75. package/src/theme/ApiExplorer/Request/_Request.scss +4 -6
  76. package/src/theme/ApiExplorer/Response/_Response.scss +4 -2
  77. package/src/theme/ApiExplorer/Response/index.tsx +6 -3
  78. package/src/theme/ApiExplorer/index.tsx +0 -3
  79. package/src/theme/ApiExplorer/persistanceMiddleware.ts +6 -6
  80. package/src/theme/ApiItem/Layout/index.tsx +3 -0
  81. package/src/theme/ApiItem/index.tsx +3 -4
  82. package/src/theme/ApiLogo/index.tsx +1 -1
  83. package/src/theme/ApiTabs/_ApiTabs.scss +3 -1
  84. package/src/theme/ApiTabs/{index.js → index.tsx} +60 -26
  85. package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
  86. package/src/theme/MimeTabs/{index.js → index.tsx} +57 -25
  87. package/src/theme/OperationTabs/_OperationTabs.scss +4 -1
  88. package/src/theme/OperationTabs/{index.js → index.tsx} +54 -25
  89. package/src/theme/ParamsItem/{index.js → index.tsx} +31 -14
  90. package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
  91. package/src/theme/SchemaItem/{index.js → index.tsx} +18 -9
  92. package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  93. package/src/theme/SchemaTabs/{index.js → index.tsx} +64 -28
  94. package/src/theme/styles.scss +4 -0
  95. package/src/theme-classic.d.ts +69 -2
  96. package/src/theme-openapi.d.ts +3 -0
  97. package/tsconfig.json +4 -1
@@ -5,18 +5,29 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React from "react";
8
+ import React, { ReactNode } from "react";
9
9
 
10
10
  import CodeBlock from "@theme/CodeBlock";
11
- /* eslint-disable import/no-extraneous-dependencies*/
12
11
  import clsx from "clsx";
13
- import { createDescription } from "docusaurus-theme-openapi-docs/lib/markdown/createDescription";
14
- /* eslint-disable import/no-extraneous-dependencies*/
15
- import { guard } from "docusaurus-theme-openapi-docs/lib/markdown/utils";
16
12
  import ReactMarkdown from "react-markdown";
17
13
  import rehypeRaw from "rehype-raw";
18
14
 
19
- function SchemaItem({
15
+ import { createDescription } from "../../markdown/createDescription";
16
+ import { guard } from "../../markdown/utils";
17
+
18
+ export interface Props {
19
+ children: ReactNode;
20
+ collapsible: boolean;
21
+ name: string;
22
+ qualifierMessage: string | undefined;
23
+ required: boolean;
24
+ schemaName: string;
25
+ // TODO should probably be typed
26
+ schema: any;
27
+ discriminator: boolean;
28
+ }
29
+
30
+ export default function SchemaItem({
20
31
  children: collapsibleSchemaContent,
21
32
  collapsible,
22
33
  name,
@@ -24,7 +35,7 @@ function SchemaItem({
24
35
  required,
25
36
  schemaName,
26
37
  schema,
27
- }) {
38
+ }: Props) {
28
39
  let deprecated;
29
40
  let schemaDescription;
30
41
  let defaultValue;
@@ -116,5 +127,3 @@ function SchemaItem({
116
127
  </div>
117
128
  );
118
129
  }
119
-
120
- export default SchemaItem;
@@ -5,10 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- .openapi-tabs__schema-container {
9
- margin-top: 1rem;
10
- }
11
-
12
8
  .openapi-tabs__schema-item {
13
9
  display: flex;
14
10
  align-items: center;
@@ -5,31 +5,56 @@
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
+ LegacyRef,
15
+ } from "react";
9
16
 
10
17
  import {
18
+ sanitizeTabsChildren,
19
+ TabProps,
11
20
  useScrollPositionBlocker,
12
21
  useTabs,
13
22
  } from "@docusaurus/theme-common/internal";
23
+ import { TabItemProps } from "@docusaurus/theme-common/lib/utils/tabsUtils";
14
24
  import useIsBrowser from "@docusaurus/useIsBrowser";
15
25
  import clsx from "clsx";
16
26
  import flatten from "lodash/flatten";
17
27
 
18
- function TabList({ className, block, selectedValue, selectValue, tabValues }) {
19
- const tabRefs = [];
28
+ function TabList({
29
+ className,
30
+ block,
31
+ selectedValue,
32
+ selectValue,
33
+ tabValues,
34
+ }: TabProps & ReturnType<typeof useTabs>) {
35
+ const tabRefs: (HTMLLIElement | null)[] = [];
20
36
  const { blockElementScrollPositionUntilNextRender } =
21
37
  useScrollPositionBlocker();
22
- const handleTabChange = (event) => {
38
+
39
+ const handleTabChange = (
40
+ event:
41
+ | React.FocusEvent<HTMLLIElement>
42
+ | React.MouseEvent<HTMLLIElement>
43
+ | React.KeyboardEvent<HTMLLIElement>
44
+ ) => {
23
45
  const newTab = event.currentTarget;
24
46
  const newTabIndex = tabRefs.indexOf(newTab);
25
47
  const newTabValue = tabValues[newTabIndex].value;
48
+
26
49
  if (newTabValue !== selectedValue) {
27
50
  blockElementScrollPositionUntilNextRender(newTab);
28
51
  selectValue(newTabValue);
29
52
  }
30
53
  };
31
- const handleKeydown = (event) => {
32
- let focusElement = null;
54
+
55
+ const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
56
+ let focusElement: HTMLLIElement | null = null;
57
+
33
58
  switch (event.key) {
34
59
  case "Enter": {
35
60
  handleTabChange(event);
@@ -37,28 +62,29 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
37
62
  }
38
63
  case "ArrowRight": {
39
64
  const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
40
- focusElement = tabRefs[nextTab] ?? tabRefs[0];
65
+ focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
41
66
  break;
42
67
  }
43
68
  case "ArrowLeft": {
44
69
  const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
45
- focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
70
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
46
71
  break;
47
72
  }
48
73
  default:
49
74
  break;
50
75
  }
76
+
51
77
  focusElement?.focus();
52
78
  };
53
79
 
54
- const tabItemListContainerRef = useRef(null);
55
- const [showTabArrows, setShowTabArrows] = useState(false);
80
+ const tabItemListContainerRef = useRef<HTMLUListElement>(null);
81
+ const [showTabArrows, setShowTabArrows] = useState<boolean>(false);
56
82
 
57
83
  useEffect(() => {
58
84
  const resizeObserver = new ResizeObserver((entries) => {
59
85
  for (let entry of entries) {
60
86
  requestAnimationFrame(() => {
61
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
87
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
62
88
  setShowTabArrows(true);
63
89
  } else {
64
90
  setShowTabArrows(false);
@@ -67,21 +93,25 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
67
93
  }
68
94
  });
69
95
 
70
- resizeObserver.observe(tabItemListContainerRef.current);
96
+ resizeObserver.observe(tabItemListContainerRef.current!);
71
97
 
72
98
  return () => {
73
99
  resizeObserver.disconnect();
74
100
  };
75
101
  }, []);
76
102
 
77
- const handleRightClick = (e) => {
103
+ const handleRightClick = (e: any) => {
78
104
  e.preventDefault();
79
- tabItemListContainerRef.current.scrollLeft += 90;
105
+ if (tabItemListContainerRef.current) {
106
+ tabItemListContainerRef.current.scrollLeft += 90;
107
+ }
80
108
  };
81
109
 
82
- const handleLeftClick = (e) => {
110
+ const handleLeftClick = (e: any) => {
83
111
  e.preventDefault();
84
- tabItemListContainerRef.current.scrollLeft -= 90;
112
+ if (tabItemListContainerRef.current) {
113
+ tabItemListContainerRef.current.scrollLeft -= 90;
114
+ }
85
115
  };
86
116
 
87
117
  return (
@@ -93,7 +123,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
93
123
  />
94
124
  )}
95
125
  <ul
96
- ref={tabItemListContainerRef}
126
+ ref={tabItemListContainerRef as LegacyRef<HTMLUListElement>}
97
127
  role="tablist"
98
128
  aria-orientation="horizontal"
99
129
  className={clsx(
@@ -119,7 +149,7 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
119
149
  className={clsx(
120
150
  "tabs__item",
121
151
  "openapi-tabs__schema-item",
122
- attributes?.className,
152
+ attributes?.className as string,
123
153
  {
124
154
  active: selectedValue === value,
125
155
  }
@@ -138,13 +168,17 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
138
168
  </div>
139
169
  );
140
170
  }
141
- function TabContent({ lazy, children, selectedValue }) {
142
- // eslint-disable-next-line no-param-reassign
143
- children = Array.isArray(children) ? children : [children];
144
- const flattenedChildren = flatten(children);
145
-
171
+ function TabContent({
172
+ lazy,
173
+ children,
174
+ selectedValue,
175
+ }: TabProps & ReturnType<typeof useTabs>) {
176
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
177
+ Boolean
178
+ ) as ReactElement<TabItemProps>[];
179
+ const flattenedChildTabs = flatten(childTabs);
146
180
  if (lazy) {
147
- const selectedTabItem = flattenedChildren.find(
181
+ const selectedTabItem = flattenedChildTabs.find(
148
182
  (tabItem) => tabItem.props.value === selectedValue
149
183
  );
150
184
  if (!selectedTabItem) {
@@ -155,7 +189,7 @@ function TabContent({ lazy, children, selectedValue }) {
155
189
  }
156
190
  return (
157
191
  <div className="margin-top--md">
158
- {children.map((tabItem, i) =>
192
+ {childTabs.map((tabItem, i) =>
159
193
  cloneElement(tabItem, {
160
194
  key: i,
161
195
  hidden: tabItem.props.value !== selectedValue,
@@ -164,7 +198,7 @@ function TabContent({ lazy, children, selectedValue }) {
164
198
  </div>
165
199
  );
166
200
  }
167
- function TabsComponent(props) {
201
+ function TabsComponent(props: TabProps): React.JSX.Element {
168
202
  const tabs = useTabs(props);
169
203
  return (
170
204
  <div className="openapi-tabs__schema-container">
@@ -173,7 +207,7 @@ function TabsComponent(props) {
173
207
  </div>
174
208
  );
175
209
  }
176
- export default function SchemaTabs(props) {
210
+ export default function SchemaTabs(props: TabProps): React.JSX.Element {
177
211
  const isBrowser = useIsBrowser();
178
212
  return (
179
213
  <TabsComponent
@@ -181,6 +215,8 @@ export default function SchemaTabs(props) {
181
215
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
182
216
  key={String(isBrowser)}
183
217
  {...props}
184
- />
218
+ >
219
+ {sanitizeTabsChildren(props.children)}
220
+ </TabsComponent>
185
221
  );
186
222
  }
@@ -159,3 +159,7 @@
159
159
  .openapi-left-panel__container {
160
160
  border-right: thin solid var(--ifm-toc-border-color);
161
161
  }
162
+
163
+ .openapi-tabs__heading {
164
+ margin-bottom: 1rem;
165
+ }
@@ -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] };
@@ -72,6 +74,7 @@ declare module "@theme/ApiExplorer/Accept" {
72
74
  }
73
75
 
74
76
  declare module "@theme/ApiExplorer/Accept/slice" {
77
+ export { setAccept };
75
78
  export default accept as Reducer<State, AnyAction>;
76
79
  }
77
80
 
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
  }