docusaurus-theme-openapi-docs 3.0.0-beta.1 → 3.0.0-beta.10

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 (142) hide show
  1. package/lib/markdown/utils.d.ts +3 -2
  2. package/lib/markdown/utils.js +1 -1
  3. package/lib/markdown/utils.test.d.ts +1 -0
  4. package/lib/markdown/utils.test.js +43 -0
  5. package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.d.ts +13 -0
  6. package/lib/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/index.js +199 -124
  7. package/lib/theme/ApiExplorer/Accept/index.d.ts +2 -2
  8. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
  9. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
  10. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
  11. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
  12. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
  13. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +115 -96
  14. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
  15. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
  16. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
  17. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
  18. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
  19. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +200 -120
  20. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
  21. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
  22. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
  23. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
  24. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
  25. package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
  26. package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
  27. package/lib/theme/ApiExplorer/Authorization/slice.d.ts +1 -1
  28. package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
  29. package/lib/theme/ApiExplorer/Body/index.js +8 -1
  30. package/lib/theme/ApiExplorer/Body/slice.d.ts +3 -3
  31. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
  32. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
  33. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +4 -14
  34. package/lib/theme/ApiExplorer/CodeSnippets/index.js +86 -8
  35. package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +3 -0
  36. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +48 -0
  37. package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
  38. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +18 -2
  39. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +15 -0
  40. package/lib/theme/ApiExplorer/CodeTabs/index.js +131 -76
  41. package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
  42. package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
  43. package/lib/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  44. package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
  45. package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
  46. package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
  47. package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
  48. package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
  49. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
  50. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
  51. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
  52. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
  53. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
  54. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +4 -4
  55. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
  56. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
  57. package/lib/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  58. package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
  59. package/lib/theme/ApiExplorer/ParamOptions/slice.d.ts +1 -1
  60. package/lib/theme/ApiExplorer/Request/_Request.scss +4 -2
  61. package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
  62. package/lib/theme/ApiExplorer/Request/makeRequest.js +50 -1
  63. package/lib/theme/ApiExplorer/Response/_Response.scss +4 -2
  64. package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
  65. package/lib/theme/ApiExplorer/Response/index.js +19 -19
  66. package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
  67. package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
  68. package/lib/theme/ApiExplorer/buildPostmanRequest.d.ts +1 -1
  69. package/lib/theme/ApiExplorer/index.d.ts +2 -2
  70. package/lib/theme/ApiExplorer/index.js +1 -1
  71. package/lib/theme/ApiExplorer/storage-utils.d.ts +1 -1
  72. package/lib/theme/ApiItem/index.js +28 -3
  73. package/lib/theme/ApiItem/store.d.ts +6 -6
  74. package/lib/theme/ApiLogo/index.d.ts +2 -2
  75. package/lib/theme/ApiTabs/_ApiTabs.scss +3 -1
  76. package/lib/theme/ApiTabs/index.d.ts +7 -0
  77. package/lib/theme/ApiTabs/index.js +167 -103
  78. package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
  79. package/lib/theme/DiscriminatorTabs/index.js +152 -98
  80. package/lib/theme/Markdown/index.js +37 -0
  81. package/lib/theme/MimeTabs/index.d.ts +6 -0
  82. package/lib/theme/MimeTabs/index.js +169 -118
  83. package/lib/theme/OperationTabs/_OperationTabs.scss +71 -0
  84. package/lib/theme/OperationTabs/index.d.ts +3 -0
  85. package/lib/theme/OperationTabs/index.js +234 -0
  86. package/lib/theme/ParamsItem/index.d.ts +23 -0
  87. package/lib/theme/ParamsItem/index.js +170 -111
  88. package/lib/theme/ResponseSamples/index.d.ts +8 -0
  89. package/lib/theme/ResponseSamples/index.js +18 -13
  90. package/lib/theme/SchemaItem/index.d.ts +12 -0
  91. package/lib/theme/SchemaItem/index.js +121 -89
  92. package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  93. package/lib/theme/SchemaTabs/index.d.ts +3 -0
  94. package/lib/theme/SchemaTabs/index.js +148 -95
  95. package/lib/theme/styles.scss +5 -0
  96. package/lib/types.d.ts +4 -4
  97. package/package.json +8 -7
  98. package/src/markdown/utils.test.ts +49 -0
  99. package/src/markdown/utils.ts +5 -3
  100. package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
  101. package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
  102. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
  103. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +4 -4
  104. package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
  105. package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
  106. package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +12 -2
  107. package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
  108. package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
  109. package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
  110. package/src/theme/ApiExplorer/Body/index.tsx +3 -1
  111. package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
  112. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
  113. package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
  114. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +53 -0
  115. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +18 -2
  116. package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +64 -25
  117. package/src/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  118. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +4 -4
  119. package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  120. package/src/theme/ApiExplorer/Request/_Request.scss +4 -2
  121. package/src/theme/ApiExplorer/Request/makeRequest.ts +59 -4
  122. package/src/theme/ApiExplorer/Response/_Response.scss +4 -2
  123. package/src/theme/ApiExplorer/Response/index.tsx +2 -2
  124. package/src/theme/ApiExplorer/index.tsx +1 -1
  125. package/src/theme/ApiItem/index.tsx +22 -3
  126. package/src/theme/ApiLogo/index.tsx +1 -1
  127. package/src/theme/ApiTabs/_ApiTabs.scss +3 -1
  128. package/src/theme/ApiTabs/{index.js → index.tsx} +75 -31
  129. package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +63 -28
  130. package/src/theme/Markdown/index.js +37 -0
  131. package/src/theme/MimeTabs/{index.js → index.tsx} +64 -30
  132. package/src/theme/OperationTabs/_OperationTabs.scss +71 -0
  133. package/src/theme/OperationTabs/index.tsx +218 -0
  134. package/src/theme/ParamsItem/{index.js → index.tsx} +48 -17
  135. package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
  136. package/src/theme/SchemaItem/{index.js → index.tsx} +24 -18
  137. package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  138. package/src/theme/SchemaTabs/{index.js → index.tsx} +62 -29
  139. package/src/theme/styles.scss +5 -0
  140. package/src/theme-classic.d.ts +69 -2
  141. package/src/theme-openapi.d.ts +6 -0
  142. package/tsconfig.json +4 -1
@@ -1,24 +1,69 @@
1
+ "use strict";
1
2
  /* ============================================================================
2
3
  * Copyright (c) Palo Alto Networks
3
4
  *
4
5
  * This source code is licensed under the MIT license found in the
5
6
  * LICENSE file in the root directory of this source tree.
6
7
  * ========================================================================== */
7
-
8
- import React, { cloneElement, useRef, useEffect, useState } from "react";
9
-
10
- import {
11
- useScrollPositionBlocker,
12
- useTabs,
13
- } from "@docusaurus/theme-common/internal";
14
- import useIsBrowser from "@docusaurus/useIsBrowser";
15
- import clsx from "clsx";
16
- import flatten from "lodash/flatten";
17
-
8
+ var __createBinding =
9
+ (this && this.__createBinding) ||
10
+ (Object.create
11
+ ? function (o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ var desc = Object.getOwnPropertyDescriptor(m, k);
14
+ if (
15
+ !desc ||
16
+ ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
17
+ ) {
18
+ desc = {
19
+ enumerable: true,
20
+ get: function () {
21
+ return m[k];
22
+ },
23
+ };
24
+ }
25
+ Object.defineProperty(o, k2, desc);
26
+ }
27
+ : function (o, m, k, k2) {
28
+ if (k2 === undefined) k2 = k;
29
+ o[k2] = m[k];
30
+ });
31
+ var __setModuleDefault =
32
+ (this && this.__setModuleDefault) ||
33
+ (Object.create
34
+ ? function (o, v) {
35
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
36
+ }
37
+ : function (o, v) {
38
+ o["default"] = v;
39
+ });
40
+ var __importStar =
41
+ (this && this.__importStar) ||
42
+ function (mod) {
43
+ if (mod && mod.__esModule) return mod;
44
+ var result = {};
45
+ if (mod != null)
46
+ for (var k in mod)
47
+ if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
48
+ __createBinding(result, mod, k);
49
+ __setModuleDefault(result, mod);
50
+ return result;
51
+ };
52
+ var __importDefault =
53
+ (this && this.__importDefault) ||
54
+ function (mod) {
55
+ return mod && mod.__esModule ? mod : { default: mod };
56
+ };
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ const react_1 = __importStar(require("react"));
59
+ const internal_1 = require("@docusaurus/theme-common/internal");
60
+ const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
61
+ const clsx_1 = __importDefault(require("clsx"));
62
+ const flatten_1 = __importDefault(require("lodash/flatten"));
18
63
  function TabList({ className, block, selectedValue, selectValue, tabValues }) {
19
64
  const tabRefs = [];
20
- const { blockElementScrollPositionUntilNextRender } =
21
- useScrollPositionBlocker();
65
+ const { blockElementScrollPositionUntilNextRender } = (0,
66
+ internal_1.useScrollPositionBlocker)();
22
67
  const handleTabChange = (event) => {
23
68
  const newTab = event.currentTarget;
24
69
  const newTabIndex = tabRefs.indexOf(newTab);
@@ -50,133 +95,141 @@ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
50
95
  }
51
96
  focusElement?.focus();
52
97
  };
53
-
54
- const tabItemListContainerRef = useRef(null);
55
- const [showTabArrows, setShowTabArrows] = useState(false);
56
-
57
- useEffect(() => {
98
+ const tabItemListContainerRef = (0, react_1.useRef)(null);
99
+ const [showTabArrows, setShowTabArrows] = (0, react_1.useState)(false);
100
+ (0, react_1.useEffect)(() => {
58
101
  const resizeObserver = new ResizeObserver((entries) => {
59
102
  for (let entry of entries) {
60
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
61
- setShowTabArrows(true);
62
- } else {
63
- setShowTabArrows(false);
64
- }
103
+ requestAnimationFrame(() => {
104
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
105
+ setShowTabArrows(true);
106
+ } else {
107
+ setShowTabArrows(false);
108
+ }
109
+ });
65
110
  }
66
111
  });
67
-
68
112
  resizeObserver.observe(tabItemListContainerRef.current);
69
-
70
113
  return () => {
71
114
  resizeObserver.disconnect();
72
115
  };
73
116
  }, []);
74
-
75
117
  const handleRightClick = () => {
76
118
  tabItemListContainerRef.current.scrollLeft += 90;
77
119
  };
78
-
79
120
  const handleLeftClick = () => {
80
121
  tabItemListContainerRef.current.scrollLeft -= 90;
81
122
  };
82
-
83
- return (
84
- <div className="openapi-tabs__schema-tabs-container">
85
- {showTabArrows && (
86
- <button
87
- className="openapi-tabs__arrow left"
88
- onClick={handleLeftClick}
89
- />
90
- )}
91
- <ul
92
- ref={tabItemListContainerRef}
93
- role="tablist"
94
- aria-orientation="horizontal"
95
- className={clsx(
123
+ return react_1.default.createElement(
124
+ "div",
125
+ { className: "openapi-tabs__schema-tabs-container" },
126
+ showTabArrows &&
127
+ react_1.default.createElement("button", {
128
+ className: "openapi-tabs__arrow left",
129
+ onClick: handleLeftClick,
130
+ }),
131
+ react_1.default.createElement(
132
+ "ul",
133
+ {
134
+ ref: tabItemListContainerRef,
135
+ role: "tablist",
136
+ "aria-orientation": "horizontal",
137
+ className: (0, clsx_1.default)(
96
138
  "openapi-tabs__schema-list-container",
97
139
  "tabs",
98
140
  {
99
141
  "tabs--block": block,
100
142
  },
101
143
  className
102
- )}
103
- >
104
- {tabValues.map(({ value, label, attributes }) => (
105
- <li
144
+ ),
145
+ },
146
+ tabValues.map(({ value, label, attributes }) =>
147
+ react_1.default.createElement(
148
+ "li",
149
+ {
106
150
  // TODO extract TabListItem
107
- role="tab"
108
- tabIndex={selectedValue === value ? 0 : -1}
109
- aria-selected={selectedValue === value}
110
- key={value}
111
- ref={(tabControl) => tabRefs.push(tabControl)}
112
- onKeyDown={handleKeydown}
113
- onClick={handleTabChange}
114
- {...attributes}
115
- className={clsx(
151
+ role: "tab",
152
+ tabIndex: selectedValue === value ? 0 : -1,
153
+ "aria-selected": selectedValue === value,
154
+ key: value,
155
+ ref: (tabControl) => tabRefs.push(tabControl),
156
+ onKeyDown: handleKeydown,
157
+ onClick: handleTabChange,
158
+ ...attributes,
159
+ className: (0, clsx_1.default)(
116
160
  "tabs__item",
117
161
  "openapi-tabs__schema-item",
118
162
  attributes?.className,
119
163
  {
120
164
  active: selectedValue === value,
121
165
  }
122
- )}
123
- >
124
- <span className="openapi-tabs__schema-label">{label ?? value}</span>
125
- </li>
126
- ))}
127
- </ul>
128
- {showTabArrows && (
129
- <button
130
- className="openapi-tabs__arrow right"
131
- onClick={handleRightClick}
132
- />
133
- )}
134
- </div>
166
+ ),
167
+ },
168
+ react_1.default.createElement(
169
+ "span",
170
+ { className: "openapi-tabs__schema-label" },
171
+ label ?? value
172
+ )
173
+ )
174
+ )
175
+ ),
176
+ showTabArrows &&
177
+ react_1.default.createElement("button", {
178
+ className: "openapi-tabs__arrow right",
179
+ onClick: handleRightClick,
180
+ })
135
181
  );
136
182
  }
137
183
  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
-
184
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
185
+ Boolean
186
+ );
187
+ const flattenedChildTabs = (0, flatten_1.default)(childTabs);
142
188
  if (lazy) {
143
- const selectedTabItem = flattenedChildren.find(
189
+ const selectedTabItem = flattenedChildTabs.find(
144
190
  (tabItem) => tabItem.props.value === selectedValue
145
191
  );
146
192
  if (!selectedTabItem) {
147
193
  // fail-safe or fail-fast? not sure what's best here
148
194
  return null;
149
195
  }
150
- return cloneElement(selectedTabItem, { className: "margin-top--md" });
196
+ return (0, react_1.cloneElement)(selectedTabItem, {
197
+ className: "margin-top--md",
198
+ });
151
199
  }
152
- return (
153
- <div className="margin-top--md">
154
- {children.map((tabItem, i) =>
155
- cloneElement(tabItem, {
156
- key: i,
157
- hidden: tabItem.props.value !== selectedValue,
158
- })
159
- )}
160
- </div>
200
+ return react_1.default.createElement(
201
+ "div",
202
+ { className: "margin-top--md" },
203
+ childTabs.map((tabItem, i) =>
204
+ (0, react_1.cloneElement)(tabItem, {
205
+ key: i,
206
+ hidden: tabItem.props.value !== selectedValue,
207
+ })
208
+ )
161
209
  );
162
210
  }
163
211
  function TabsComponent(props) {
164
- const tabs = useTabs(props);
165
- return (
166
- <div className="openapi-tabs__schema-container">
167
- <TabList {...props} {...tabs} />
168
- <TabContent {...props} {...tabs} />
169
- </div>
212
+ const tabs = (0, internal_1.useTabs)(props);
213
+ return react_1.default.createElement(
214
+ "div",
215
+ { className: "openapi-tabs__schema-container" },
216
+ react_1.default.createElement(TabList, { ...props, ...tabs }),
217
+ react_1.default.createElement(TabContent, { ...props, ...tabs })
170
218
  );
171
219
  }
172
- export default function SchemaTabs(props) {
173
- const isBrowser = useIsBrowser();
174
- return (
175
- <TabsComponent
220
+ function SchemaTabs(props) {
221
+ const isBrowser = (0, useIsBrowser_1.default)();
222
+ return react_1.default.createElement(
223
+ TabsComponent,
224
+ // Remount tabs after hydration
225
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
226
+ {
176
227
  // Remount tabs after hydration
177
228
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
178
- key={String(isBrowser)}
179
- {...props}
180
- />
229
+ key: String(isBrowser),
230
+ ...props,
231
+ },
232
+ (0, internal_1.sanitizeTabsChildren)(props.children)
181
233
  );
182
234
  }
235
+ exports.default = SchemaTabs;
@@ -36,6 +36,7 @@
36
36
  @use "./DiscriminatorTabs/DiscriminatorTabs";
37
37
  @use "./MimeTabs/MimeTabs";
38
38
  @use "./SchemaTabs/SchemaTabs";
39
+ @use "./OperationTabs/OperationTabs";
39
40
  /* Code Samples */
40
41
  @use "./ResponseSamples/ResponseSamples";
41
42
  /* Markdown Styling */
@@ -158,3 +159,7 @@
158
159
  .openapi-left-panel__container {
159
160
  border-right: thin solid var(--ifm-toc-border-color);
160
161
  }
162
+
163
+ .openapi-tabs__heading {
164
+ margin-bottom: 1rem;
165
+ }
package/lib/types.d.ts CHANGED
@@ -9,8 +9,8 @@ export interface ThemeConfig {
9
9
  interface Map<T> {
10
10
  [key: string]: T;
11
11
  }
12
- export declare type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
13
- export declare type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
12
+ export type JSONSchema = JSONSchema4 | JSONSchema6 | JSONSchema7;
13
+ export type SchemaObject = Omit<JSONSchema, "type" | "allOf" | "oneOf" | "anyOf" | "not" | "items" | "properties" | "additionalProperties"> & {
14
14
  type?: "string" | "number" | "integer" | "boolean" | "object" | "array";
15
15
  allOf?: SchemaObject[];
16
16
  oneOf?: SchemaObject[];
@@ -43,14 +43,14 @@ export interface ExternalDocumentationObject {
43
43
  description?: string;
44
44
  url: string;
45
45
  }
46
- export declare type FileChange = {
46
+ export type FileChange = {
47
47
  author?: string;
48
48
  /** Date can be any
49
49
  * [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
50
50
  */
51
51
  date?: Date | string;
52
52
  };
53
- export declare type DocFrontMatter = {
53
+ export type DocFrontMatter = {
54
54
  /**
55
55
  * The last part of the doc ID (will be refactored in the future to be the
56
56
  * full ID instead)
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": "3.0.0-beta.1",
4
+ "version": "3.0.0-beta.10",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -28,14 +28,15 @@
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": "^3.0.0",
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": "^3.0.0",
39
+ "@docusaurus/theme-common": "^3.0.1",
39
40
  "@hookform/error-message": "^2.0.1",
40
41
  "@paloaltonetworks/postman-code-generators": "1.1.15-patch.2",
41
42
  "@paloaltonetworks/postman-collection": "^4.1.0",
@@ -43,12 +44,12 @@
43
44
  "clsx": "^1.1.1",
44
45
  "copy-text-to-clipboard": "^3.1.0",
45
46
  "crypto-js": "^4.1.1",
46
- "docusaurus-plugin-openapi-docs": "^3.0.0-beta.1",
47
+ "docusaurus-plugin-openapi-docs": "^3.0.0-beta.10",
47
48
  "docusaurus-plugin-sass": "^0.2.3",
48
49
  "file-saver": "^2.0.5",
49
50
  "lodash": "^4.17.20",
50
51
  "node-polyfill-webpack-plugin": "^2.0.1",
51
- "prism-react-renderer": "^2.1.0",
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": "9641610aae936a5d9193f43068a2fdd337da0416"
72
+ "gitHead": "82d70be14358052625d00e637b1eeba52a14b706"
72
73
  }
@@ -0,0 +1,49 @@
1
+ /* ============================================================================
2
+ * Copyright (c) Palo Alto Networks
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ * ========================================================================== */
7
+
8
+ import { guard } from "./utils";
9
+
10
+ describe("guard", () => {
11
+ it("should guard empty strings", () => {
12
+ const actual = guard("", (_) => {
13
+ throw new Error("Should not be called");
14
+ });
15
+ expect(actual).toBe("");
16
+ });
17
+
18
+ it("should guard undefined", () => {
19
+ const actual = guard(undefined, (value) => {
20
+ throw new Error("Should not be called");
21
+ });
22
+ expect(actual).toBe("");
23
+ });
24
+
25
+ it("should guard false booleans", () => {
26
+ const actual = guard(false, (value) => `${value}`);
27
+ expect(actual).toBe("");
28
+ });
29
+
30
+ it("should not guard strings", () => {
31
+ const actual = guard("hello", (value) => value);
32
+ expect(actual).toBe("hello");
33
+ });
34
+
35
+ it("should not guard numbers", () => {
36
+ const actual = guard(1, (value) => `${value}`);
37
+ expect(actual).toBe("1");
38
+ });
39
+
40
+ it("should not guard numbers equals to 0", () => {
41
+ const actual = guard(0, (value) => `${value}`);
42
+ expect(actual).toBe("0");
43
+ });
44
+
45
+ it("should not guard true booleans", () => {
46
+ const actual = guard(true, (value) => `${value}`);
47
+ expect(actual).toBe("true");
48
+ });
49
+ });
@@ -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
 
@@ -24,7 +26,7 @@ export function guard<T>(
24
26
  value: T | undefined | string,
25
27
  cb: (value: T) => Children
26
28
  ): string {
27
- if (!!value) {
29
+ if (!!value || value === 0) {
28
30
  const children = cb(value as T);
29
31
  return render(children);
30
32
  }
@@ -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 {
@@ -9,14 +9,28 @@ import React, { useEffect } from "react";
9
9
 
10
10
  import { usePrismTheme } from "@docusaurus/theme-common";
11
11
  import { translate } from "@docusaurus/Translate";
12
- import Container from "@theme/ApiDemoPanel/ApiCodeBlock/Container";
13
- import CopyButton from "@theme/ApiDemoPanel/ApiCodeBlock/CopyButton";
14
- import ExitButton from "@theme/ApiDemoPanel/ApiCodeBlock/ExitButton";
15
- import Line from "@theme/ApiDemoPanel/ApiCodeBlock/Line";
12
+ // @ts-ignore
13
+ import Container from "@theme/ApiExplorer/ApiCodeBlock/Container";
14
+ // @ts-ignore
15
+ import CopyButton from "@theme/ApiExplorer/ApiCodeBlock/CopyButton";
16
+ // @ts-ignore
17
+ import ExitButton from "@theme/ApiExplorer/ApiCodeBlock/ExitButton";
18
+ // @ts-ignore
19
+ import Line from "@theme/ApiExplorer/ApiCodeBlock/Line";
16
20
  import clsx from "clsx";
17
- import Highlight, { defaultProps } from "prism-react-renderer";
21
+ import { Highlight, type Language } from "prism-react-renderer";
18
22
  import Modal from "react-modal";
19
23
 
24
+ interface Props {
25
+ code: string;
26
+ className: string;
27
+ language: Language;
28
+ showLineNumbers: boolean;
29
+ blockClassName: string;
30
+ title: string;
31
+ lineClassNames: string[];
32
+ }
33
+
20
34
  export default function ExpandButton({
21
35
  code,
22
36
  className,
@@ -25,7 +39,7 @@ export default function ExpandButton({
25
39
  blockClassName,
26
40
  title,
27
41
  lineClassNames,
28
- }) {
42
+ }: Props): React.JSX.Element {
29
43
  const prismTheme = usePrismTheme();
30
44
 
31
45
  function openModal() {
@@ -111,7 +125,6 @@ export default function ExpandButton({
111
125
  )}
112
126
  <div className="openapi-explorer__code-block-content">
113
127
  <Highlight
114
- {...defaultProps}
115
128
  theme={prismTheme}
116
129
  code={code}
117
130
  language={language ?? "text"}
@@ -139,7 +152,7 @@ export default function ExpandButton({
139
152
  line={line}
140
153
  getLineProps={getLineProps}
141
154
  getTokenProps={getTokenProps}
142
- classNames={lineClassNames[i]}
155
+ classNames={lineClassNames}
143
156
  showLineNumbers={showLineNumbers}
144
157
  />
145
158
  ))}
@@ -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 } 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();
@@ -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"