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

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
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-740",
4
+ "version": "0.0.0-751",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,27 +28,28 @@
28
28
  "watch": "concurrently --names \"lib,lib-next,tsc\" --kill-others \"yarn babel:lib --watch\" \"yarn babel:lib-next --watch\" \"yarn tsc --watch\""
29
29
  },
30
30
  "devDependencies": {
31
- "@docusaurus/types": ">=2.4.1 <=2.4.3",
31
+ "@docusaurus/types": "^3.0.1",
32
32
  "@types/crypto-js": "^4.1.0",
33
33
  "@types/file-saver": "^2.0.5",
34
34
  "@types/lodash": "^4.14.176",
35
- "concurrently": "^5.2.0"
35
+ "concurrently": "^5.2.0",
36
+ "eslint-plugin-prettier": "^5.0.1"
36
37
  },
37
38
  "dependencies": {
38
- "@docusaurus/theme-common": ">=2.4.1 <=2.4.3",
39
+ "@docusaurus/theme-common": "^3.0.1",
39
40
  "@hookform/error-message": "^2.0.1",
40
41
  "@reduxjs/toolkit": "^1.7.1",
41
42
  "clsx": "^1.1.1",
42
43
  "copy-text-to-clipboard": "^3.1.0",
43
44
  "crypto-js": "^4.1.1",
44
- "docusaurus-plugin-openapi-docs": "0.0.0-740",
45
+ "docusaurus-plugin-openapi-docs": "0.0.0-751",
45
46
  "docusaurus-plugin-sass": "^0.2.3",
46
47
  "file-saver": "^2.0.5",
47
48
  "lodash": "^4.17.20",
48
49
  "node-polyfill-webpack-plugin": "^2.0.1",
49
50
  "postman-code-generators": "^1.10.1",
50
51
  "postman-collection": "^4.4.0",
51
- "prism-react-renderer": "^1.3.5",
52
+ "prism-react-renderer": "^2.3.0",
52
53
  "react-hook-form": "^7.43.8",
53
54
  "react-live": "^4.0.0",
54
55
  "react-magic-dropzone": "^1.0.1",
@@ -68,5 +69,5 @@
68
69
  "engines": {
69
70
  "node": ">=14"
70
71
  },
71
- "gitHead": "ffc1156c334baa55d6abe7a181caae853556f2b0"
72
+ "gitHead": "87427f0ab49405d1aef03436e5c5babc9641dd45"
72
73
  }
@@ -5,7 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- export type Children = string | undefined | (string | undefined)[];
8
+ import { ReactNode } from "react";
9
+
10
+ export type Children = ReactNode | string | undefined | (string | undefined)[];
9
11
 
10
12
  export type Props = Record<string, any> & { children?: Children };
11
13
 
@@ -35,7 +37,7 @@ export function render(children: Children): string {
35
37
  if (Array.isArray(children)) {
36
38
  return children.filter((c) => c !== undefined).join("");
37
39
  }
38
- return children ?? "";
40
+ return (children as string) ?? "";
39
41
  }
40
42
 
41
43
  export function toString(value: any): string | undefined {
@@ -5,19 +5,22 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React from "react";
8
+ import React, { ComponentProps } from "react";
9
9
 
10
10
  import { ThemeClassNames, usePrismTheme } from "@docusaurus/theme-common";
11
11
  import { getPrismCssVariables } from "@docusaurus/theme-common/internal";
12
12
  import clsx from "clsx";
13
13
 
14
- export default function CodeBlockContainer({ as: As, ...props }) {
14
+ export default function CodeBlockContainer<T extends "div" | "pre">({
15
+ as: As,
16
+ ...props
17
+ }: { as: T } & ComponentProps<T>): React.JSX.Element {
15
18
  const prismTheme = usePrismTheme();
16
19
  const prismCssVariables = getPrismCssVariables(prismTheme);
17
20
  return (
18
21
  <As
19
22
  // Polymorphic components are hard to type, without `oneOf` generics
20
- {...props}
23
+ {...(props as any)}
21
24
  style={prismCssVariables}
22
25
  className={clsx(
23
26
  "openapi-explorer__code-block-container",
@@ -8,12 +8,16 @@
8
8
  import React from "react";
9
9
 
10
10
  import Container from "@theme/ApiExplorer/ApiCodeBlock/Container";
11
+ import type { Props } from "@theme/CodeBlock/Content/Element";
11
12
  import clsx from "clsx";
12
13
 
13
14
  // <pre> tags in markdown map to CodeBlocks. They may contain JSX children. When
14
15
  // the children is not a simple string, we just return a styled block without
15
16
  // actually highlighting.
16
- export default function CodeBlockJSX({ children, className }) {
17
+ export default function CodeBlockJSX({
18
+ children,
19
+ className,
20
+ }: Props): React.JSX.Element {
17
21
  return (
18
22
  <Container
19
23
  as="pre"
@@ -20,8 +20,9 @@ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
20
20
  import ExpandButton from "@theme/ApiExplorer/ApiCodeBlock/ExpandButton";
21
21
  import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
22
22
  import WordWrapButton from "@theme/ApiExplorer/ApiCodeBlock/WordWrapButton";
23
+ import type { Props } from "@theme/CodeBlock/Content/String";
23
24
  import clsx from "clsx";
24
- import Highlight, { defaultProps } from "prism-react-renderer";
25
+ import { Highlight, Language } from "prism-react-renderer";
25
26
 
26
27
  export default function CodeBlockString({
27
28
  children,
@@ -30,7 +31,7 @@ export default function CodeBlockString({
30
31
  title: titleProp,
31
32
  showLineNumbers: showLineNumbersProp,
32
33
  language: languageProp,
33
- }) {
34
+ }: Props): React.JSX.Element {
34
35
  const {
35
36
  prism: { defaultLanguage, magicComments },
36
37
  } = useThemeConfig();
@@ -65,7 +66,7 @@ export default function CodeBlockString({
65
66
  )}
66
67
  <div className="openapi-explorer__code-block-content">
67
68
  <Highlight
68
- {...defaultProps}
69
+ // {...defaultProps}
69
70
  theme={prismTheme}
70
71
  code={code}
71
72
  language={language ?? "text"}
@@ -120,12 +121,11 @@ export default function CodeBlockString({
120
121
  "openapi-explorer__expand-btn"
121
122
  )}
122
123
  code={code}
123
- language={language}
124
+ language={(language ?? "text") as Language}
124
125
  showLineNumbers={showLineNumbers}
125
126
  blockClassName={blockClassName}
126
127
  title={title}
127
128
  lineClassNames={lineClassNames}
128
- wordWrap={wordWrap}
129
129
  />
130
130
  </div>
131
131
  </div>
@@ -7,14 +7,17 @@
7
7
 
8
8
  import React, { useCallback, useState, useRef, useEffect } from "react";
9
9
 
10
+ import { CopyButtonProps } from "@docusaurus/theme-common/internal";
10
11
  import { translate } from "@docusaurus/Translate";
11
12
  import clsx from "clsx";
12
- // @ts-expect-error: TODO, we need to make theme-classic have type: module
13
13
  import copy from "copy-text-to-clipboard";
14
14
 
15
- export default function CopyButton({ code, className }) {
15
+ export default function CopyButton({
16
+ code,
17
+ className,
18
+ }: CopyButtonProps): React.JSX.Element {
16
19
  const [isCopied, setIsCopied] = useState(false);
17
- const copyTimeout = useRef(undefined);
20
+ const copyTimeout = useRef<number | undefined>(undefined);
18
21
  const handleCopyCode = useCallback(() => {
19
22
  copy(code);
20
23
  setIsCopied(true);
@@ -22,7 +25,9 @@ export default function CopyButton({ code, className }) {
22
25
  setIsCopied(false);
23
26
  }, 1000);
24
27
  }, [code]);
28
+
25
29
  useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
30
+
26
31
  return (
27
32
  <button
28
33
  type="button"
@@ -10,7 +10,15 @@ import React from "react";
10
10
  import { translate } from "@docusaurus/Translate";
11
11
  import clsx from "clsx";
12
12
 
13
- export default function ExitButton({ className, handler }) {
13
+ export interface Props {
14
+ readonly className: string;
15
+ readonly handler: () => void;
16
+ }
17
+
18
+ export default function ExitButton({
19
+ className,
20
+ handler,
21
+ }: Props): React.JSX.Element {
14
22
  return (
15
23
  <button
16
24
  type="button"
@@ -14,9 +14,19 @@ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
14
14
  import ExitButton from "@theme/ApiExplorer/ApiCodeBlock/ExitButton";
15
15
  import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
16
16
  import clsx from "clsx";
17
- import Highlight, { defaultProps } from "prism-react-renderer";
17
+ import { Highlight, Language } from "prism-react-renderer";
18
18
  import Modal from "react-modal";
19
19
 
20
+ export interface Props {
21
+ readonly code: string;
22
+ readonly className: string;
23
+ readonly language: Language;
24
+ readonly showLineNumbers: boolean;
25
+ readonly blockClassName: string;
26
+ readonly title: string | undefined;
27
+ readonly lineClassNames: { [lineIndex: number]: string[] };
28
+ }
29
+
20
30
  export default function ExpandButton({
21
31
  code,
22
32
  className,
@@ -25,7 +35,7 @@ export default function ExpandButton({
25
35
  blockClassName,
26
36
  title,
27
37
  lineClassNames,
28
- }) {
38
+ }: Props): React.JSX.Element {
29
39
  const [isModalOpen, setIsModalOpen] = useState(false);
30
40
  const prismTheme = usePrismTheme();
31
41
 
@@ -102,7 +112,7 @@ export default function ExpandButton({
102
112
  )}
103
113
  <div className="openapi-explorer__code-block-content">
104
114
  <Highlight
105
- {...defaultProps}
115
+ // {...defaultProps}
106
116
  theme={prismTheme}
107
117
  code={code}
108
118
  language={language ?? "text"}
@@ -7,6 +7,7 @@
7
7
 
8
8
  import React from "react";
9
9
 
10
+ import { LineProps } from "@docusaurus/theme-common/internal";
10
11
  import clsx from "clsx";
11
12
 
12
13
  export default function CodeBlockLine({
@@ -15,7 +16,7 @@ export default function CodeBlockLine({
15
16
  showLineNumbers,
16
17
  getLineProps,
17
18
  getTokenProps,
18
- }) {
19
+ }: LineProps): React.JSX.Element {
19
20
  if (line.length === 1 && line[0].content === "\n") {
20
21
  line[0].content = "";
21
22
  }
@@ -10,7 +10,17 @@ import React from "react";
10
10
  import { translate } from "@docusaurus/Translate";
11
11
  import clsx from "clsx";
12
12
 
13
- export default function WordWrapButton({ className, onClick, isEnabled }) {
13
+ export interface Props {
14
+ readonly className?: string;
15
+ readonly onClick: React.MouseEventHandler;
16
+ readonly isEnabled: boolean;
17
+ }
18
+
19
+ export default function WordWrapButton({
20
+ className,
21
+ onClick,
22
+ isEnabled,
23
+ }: Props): React.JSX.Element | null {
14
24
  const title = translate({
15
25
  id: "theme.CodeBlock.wordWrapToggle",
16
26
  message: "Toggle word wrap",
@@ -5,25 +5,30 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
- import React, { isValidElement } from "react";
8
+ import React, { isValidElement, ReactNode } from "react";
9
9
 
10
+ import { CodeBlockProps } from "@docusaurus/theme-common/internal";
10
11
  import useIsBrowser from "@docusaurus/useIsBrowser";
11
12
  import ElementContent from "@theme/ApiExplorer/ApiCodeBlock/Content/Element";
12
13
  import StringContent from "@theme/ApiExplorer/ApiCodeBlock/Content/String";
14
+
13
15
  /**
14
16
  * Best attempt to make the children a plain string so it is copyable. If there
15
17
  * are react elements, we will not be able to copy the content, and it will
16
18
  * return `children` as-is; otherwise, it concatenates the string children
17
19
  * together.
18
20
  */
19
- function maybeStringifyChildren(children) {
21
+ function maybeStringifyChildren(children: ReactNode): ReactNode {
20
22
  if (React.Children.toArray(children).some((el) => isValidElement(el))) {
21
23
  return children;
22
24
  }
23
25
  // The children is now guaranteed to be one/more plain strings
24
- return Array.isArray(children) ? children.join("") : children;
26
+ return Array.isArray(children) ? children.join("") : (children as string);
25
27
  }
26
- export default function ApiCodeBlock({ children: rawChildren, ...props }) {
28
+ export default function ApiCodeBlock({
29
+ children: rawChildren,
30
+ ...props
31
+ }: CodeBlockProps) {
27
32
  // The Prism theme on SSR is always the default theme but the site theme can
28
33
  // be in a different mode. React hydration doesn't update DOM styles that come
29
34
  // from SSR. Hence force a re-render after mounting to apply the current
@@ -34,7 +39,7 @@ export default function ApiCodeBlock({ children: rawChildren, ...props }) {
34
39
  typeof children === "string" ? StringContent : ElementContent;
35
40
  return (
36
41
  <CodeBlockComp key={String(isBrowser)} {...props}>
37
- {children}
42
+ {children as string}
38
43
  </CodeBlockComp>
39
44
  );
40
45
  }
@@ -172,9 +172,9 @@ function CodeSnippets({ postman, codeSamples }: Props) {
172
172
 
173
173
  // User-defined languages array
174
174
  // Can override languageSet, change order of langs, override options and variants
175
- const userDefinedLanguageSet = siteConfig?.themeConfig?.languageTabs as
176
- | Language[]
177
- | undefined;
175
+ const userDefinedLanguageSet =
176
+ (siteConfig?.themeConfig?.languageTabs as Language[] | undefined) ??
177
+ languageSet;
178
178
 
179
179
  // Filter languageSet by user-defined langs
180
180
  const filteredLanguageSet = languageSet.filter((ls) => {
@@ -189,8 +189,6 @@ function CodeSnippets({ postman, codeSamples }: Props) {
189
189
  codeSamples
190
190
  );
191
191
 
192
- console.log("merged", mergedLangs);
193
-
194
192
  // Read defaultLang from localStorage
195
193
  const defaultLang: Language[] = mergedLangs.filter(
196
194
  (lang) =>