docusaurus-theme-openapi-docs 2.1.3 → 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 (95) hide show
  1. package/lib/markdown/utils.d.ts +2 -1
  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/ApiCodeBlock/Container/index.d.ts +4 -0
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
  6. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
  7. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
  8. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
  9. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +116 -97
  10. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
  11. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
  12. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
  13. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
  14. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
  15. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +201 -121
  16. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
  17. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
  18. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
  19. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
  20. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
  21. package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
  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 +19 -19
  32. package/lib/theme/ApiExplorer/index.js +0 -4
  33. package/lib/theme/ApiItem/Layout/index.js +3 -0
  34. package/lib/theme/ApiItem/index.js +6 -5
  35. package/lib/theme/ApiLogo/index.d.ts +2 -2
  36. package/lib/theme/ApiTabs/_ApiTabs.scss +3 -1
  37. package/lib/theme/ApiTabs/index.d.ts +7 -0
  38. package/lib/theme/ApiTabs/index.js +152 -98
  39. package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
  40. package/lib/theme/DiscriminatorTabs/index.js +146 -94
  41. package/lib/theme/MimeTabs/index.d.ts +6 -0
  42. package/lib/theme/MimeTabs/index.js +163 -114
  43. package/lib/theme/OperationTabs/_OperationTabs.scss +4 -1
  44. package/lib/theme/OperationTabs/index.d.ts +3 -0
  45. package/lib/theme/OperationTabs/index.js +148 -103
  46. package/lib/theme/ParamsItem/index.d.ts +23 -0
  47. package/lib/theme/ParamsItem/index.js +168 -123
  48. package/lib/theme/ResponseSamples/index.d.ts +8 -0
  49. package/lib/theme/ResponseSamples/index.js +18 -13
  50. package/lib/theme/SchemaItem/index.d.ts +12 -0
  51. package/lib/theme/SchemaItem/index.js +123 -88
  52. package/lib/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  53. package/lib/theme/SchemaTabs/index.d.ts +3 -0
  54. package/lib/theme/SchemaTabs/index.js +142 -91
  55. package/lib/theme/styles.scss +4 -0
  56. package/package.json +8 -7
  57. package/src/markdown/utils.ts +4 -2
  58. package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
  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/languages.json +1290 -0
  69. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +4 -2
  70. package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +56 -26
  71. package/src/theme/ApiExplorer/FloatingButton/_FloatingButton.scss +3 -1
  72. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +4 -4
  73. package/src/theme/ApiExplorer/ParamOptions/_ParamOptions.scss +2 -1
  74. package/src/theme/ApiExplorer/Request/_Request.scss +4 -6
  75. package/src/theme/ApiExplorer/Response/_Response.scss +4 -2
  76. package/src/theme/ApiExplorer/Response/index.tsx +2 -2
  77. package/src/theme/ApiExplorer/index.tsx +0 -3
  78. package/src/theme/ApiItem/Layout/index.tsx +3 -0
  79. package/src/theme/ApiItem/index.tsx +3 -4
  80. package/src/theme/ApiLogo/index.tsx +1 -1
  81. package/src/theme/ApiTabs/_ApiTabs.scss +3 -1
  82. package/src/theme/ApiTabs/{index.js → index.tsx} +60 -26
  83. package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
  84. package/src/theme/MimeTabs/{index.js → index.tsx} +58 -26
  85. package/src/theme/OperationTabs/_OperationTabs.scss +4 -1
  86. package/src/theme/OperationTabs/{index.js → index.tsx} +54 -25
  87. package/src/theme/ParamsItem/{index.js → index.tsx} +31 -14
  88. package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
  89. package/src/theme/SchemaItem/{index.js → index.tsx} +18 -9
  90. package/src/theme/SchemaTabs/_SchemaTabs.scss +0 -4
  91. package/src/theme/SchemaTabs/{index.js → index.tsx} +56 -25
  92. package/src/theme/styles.scss +4 -0
  93. package/src/theme-classic.d.ts +69 -2
  94. package/src/theme-openapi.d.ts +2 -0
  95. package/tsconfig.json +4 -1
@@ -1,22 +1,67 @@
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, useEffect, useState, useRef } from "react";
9
-
10
- import {
11
- useScrollPositionBlocker,
12
- useTabs,
13
- } from "@docusaurus/theme-common/internal";
14
- import useIsBrowser from "@docusaurus/useIsBrowser";
15
- import { setAccept } from "@theme/ApiExplorer/Accept/slice";
16
- import { setContentType } from "@theme/ApiExplorer/ContentType/slice";
17
- import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
18
- import clsx from "clsx";
19
-
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 slice_1 = __importDefault(require("@theme/ApiExplorer/Accept/slice"));
62
+ const slice_2 = require("@theme/ApiExplorer/ContentType/slice");
63
+ const hooks_1 = require("@theme/ApiItem/hooks");
64
+ const clsx_1 = __importDefault(require("clsx"));
20
65
  function TabList({
21
66
  className,
22
67
  block,
@@ -26,18 +71,21 @@ function TabList({
26
71
  schemaType,
27
72
  }) {
28
73
  const tabRefs = [];
29
- const { blockElementScrollPositionUntilNextRender } =
30
- useScrollPositionBlocker();
31
-
74
+ const { blockElementScrollPositionUntilNextRender } = (0,
75
+ internal_1.useScrollPositionBlocker)();
32
76
  // custom
33
- const dispatch = useTypedDispatch();
77
+ const dispatch = (0, hooks_1.useTypedDispatch)();
34
78
  const isRequestSchema = schemaType?.toLowerCase() === "request";
35
-
36
- const [selectedValue, setSelectedValue] = useState(selectedValueProp);
37
- const contentTypeVal = useTypedSelector((state) => state.contentType.value);
38
- const acceptTypeVal = useTypedSelector((state) => state.accept.value);
39
-
40
- useEffect(() => {
79
+ const [selectedValue, setSelectedValue] = (0, react_1.useState)(
80
+ selectedValueProp
81
+ );
82
+ const contentTypeVal = (0, hooks_1.useTypedSelector)(
83
+ (state) => state.contentType.value
84
+ );
85
+ const acceptTypeVal = (0, hooks_1.useTypedSelector)(
86
+ (state) => state.accept.value
87
+ );
88
+ (0, react_1.useEffect)(() => {
41
89
  if (tabRefs.length > 1) {
42
90
  if (isRequestSchema) {
43
91
  setSelectedValue(contentTypeVal);
@@ -47,7 +95,6 @@ function TabList({
47
95
  }
48
96
  // eslint-disable-next-line react-hooks/exhaustive-deps
49
97
  }, [contentTypeVal, acceptTypeVal]);
50
-
51
98
  const handleTabChange = (event) => {
52
99
  event.preventDefault();
53
100
  const newTab = event.currentTarget;
@@ -56,15 +103,14 @@ function TabList({
56
103
  // custom
57
104
  if (newTabValue !== selectedValue) {
58
105
  if (isRequestSchema) {
59
- dispatch(setContentType(newTabValue));
106
+ dispatch((0, slice_2.setContentType)(newTabValue));
60
107
  } else {
61
- dispatch(setAccept(newTabValue));
108
+ dispatch((0, slice_1.default)(newTabValue));
62
109
  }
63
110
  blockElementScrollPositionUntilNextRender(newTab);
64
111
  selectValue(newTabValue);
65
112
  }
66
113
  };
67
-
68
114
  const handleKeydown = (event) => {
69
115
  let focusElement = null;
70
116
  switch (event.key) {
@@ -87,15 +133,13 @@ function TabList({
87
133
  }
88
134
  focusElement?.focus();
89
135
  };
90
-
91
- const tabItemListContainerRef = useRef(null);
92
- const [showTabArrows, setShowTabArrows] = useState(false);
93
-
94
- useEffect(() => {
136
+ const tabItemListContainerRef = (0, react_1.useRef)(null);
137
+ const [showTabArrows, setShowTabArrows] = (0, react_1.useState)(false);
138
+ (0, react_1.useEffect)(() => {
95
139
  const resizeObserver = new ResizeObserver((entries) => {
96
140
  for (let entry of entries) {
97
141
  requestAnimationFrame(() => {
98
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
142
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
99
143
  setShowTabArrows(true);
100
144
  } else {
101
145
  setShowTabArrows(false);
@@ -103,121 +147,126 @@ function TabList({
103
147
  });
104
148
  }
105
149
  });
106
-
107
150
  resizeObserver.observe(tabItemListContainerRef.current);
108
-
109
151
  return () => {
110
152
  resizeObserver.disconnect();
111
153
  };
112
154
  }, []);
113
-
114
155
  const handleRightClick = () => {
115
156
  tabItemListContainerRef.current.scrollLeft += 90;
116
157
  };
117
-
118
158
  const handleLeftClick = () => {
119
159
  tabItemListContainerRef.current.scrollLeft -= 90;
120
160
  };
121
-
122
- return (
123
- <div className="tabs__container">
124
- <div className="openapi-tabs__mime-container">
125
- {showTabArrows && (
126
- <button
127
- className={clsx("openapi-tabs__arrow", "left")}
128
- onClick={handleLeftClick}
129
- />
130
- )}
131
- <ul
132
- ref={tabItemListContainerRef}
133
- role="tablist"
134
- aria-orientation="horizontal"
135
- className={clsx(
161
+ return react_1.default.createElement(
162
+ "div",
163
+ { className: "tabs__container" },
164
+ react_1.default.createElement(
165
+ "div",
166
+ { className: "openapi-tabs__mime-container" },
167
+ showTabArrows &&
168
+ react_1.default.createElement("button", {
169
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "left"),
170
+ onClick: handleLeftClick,
171
+ }),
172
+ react_1.default.createElement(
173
+ "ul",
174
+ {
175
+ ref: tabItemListContainerRef,
176
+ role: "tablist",
177
+ "aria-orientation": "horizontal",
178
+ className: (0, clsx_1.default)(
136
179
  "openapi-tabs__mime-list-container",
137
180
  "tabs",
138
181
  {
139
182
  "tabs--block": block,
140
183
  },
141
184
  className
142
- )}
143
- >
144
- {tabValues.map(({ value, label, attributes }) => {
145
- return (
146
- <li
147
- role="tab"
148
- tabIndex={selectedValue === value ? 0 : -1}
149
- aria-selected={selectedValue === value}
150
- key={value}
151
- ref={(tabControl) => tabRefs.push(tabControl)}
152
- onKeyDown={handleKeydown}
153
- onFocus={handleTabChange}
154
- onClick={(e) => handleTabChange(e)}
155
- {...attributes}
156
- className={clsx(
157
- "tabs__item",
158
- "openapi-tabs__mime-item",
159
- attributes?.className,
160
- {
161
- active: selectedValue === value,
162
- }
163
- )}
164
- >
165
- {label ?? value}
166
- </li>
167
- );
168
- })}
169
- </ul>
170
- {showTabArrows && (
171
- <button
172
- className={clsx("openapi-tabs__arrow", "right")}
173
- onClick={handleRightClick}
174
- />
175
- )}
176
- </div>
177
- </div>
185
+ ),
186
+ },
187
+ tabValues.map(({ value, label, attributes }) => {
188
+ return react_1.default.createElement(
189
+ "li",
190
+ {
191
+ role: "tab",
192
+ tabIndex: selectedValue === value ? 0 : -1,
193
+ "aria-selected": selectedValue === value,
194
+ key: value,
195
+ ref: (tabControl) => tabRefs.push(tabControl),
196
+ onKeyDown: handleKeydown,
197
+ onFocus: handleTabChange,
198
+ onClick: (e) => handleTabChange(e),
199
+ ...attributes,
200
+ className: (0, clsx_1.default)(
201
+ "tabs__item",
202
+ "openapi-tabs__mime-item",
203
+ attributes?.className,
204
+ {
205
+ active: selectedValue === value,
206
+ }
207
+ ),
208
+ },
209
+ label ?? value
210
+ );
211
+ })
212
+ ),
213
+ showTabArrows &&
214
+ react_1.default.createElement("button", {
215
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "right"),
216
+ onClick: handleRightClick,
217
+ })
218
+ )
178
219
  );
179
220
  }
180
221
  function TabContent({ lazy, children, selectedValue }) {
181
- // eslint-disable-next-line no-param-reassign
182
- children = Array.isArray(children) ? children : [children];
222
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
223
+ Boolean
224
+ );
183
225
  if (lazy) {
184
- const selectedTabItem = children.find(
226
+ const selectedTabItem = childTabs.find(
185
227
  (tabItem) => tabItem.props.value === selectedValue
186
228
  );
187
229
  if (!selectedTabItem) {
188
230
  // fail-safe or fail-fast? not sure what's best here
189
231
  return null;
190
232
  }
191
- return cloneElement(selectedTabItem, { className: "margin-top--md" });
233
+ return (0, react_1.cloneElement)(selectedTabItem, {
234
+ className: "margin-top--md",
235
+ });
192
236
  }
193
- return (
194
- <div className="margin-top--md">
195
- {children.map((tabItem, i) =>
196
- cloneElement(tabItem, {
197
- key: i,
198
- hidden: tabItem.props.value !== selectedValue,
199
- })
200
- )}
201
- </div>
237
+ return react_1.default.createElement(
238
+ "div",
239
+ { className: "margin-top--md" },
240
+ childTabs.map((tabItem, i) =>
241
+ (0, react_1.cloneElement)(tabItem, {
242
+ key: i,
243
+ hidden: tabItem.props.value !== selectedValue,
244
+ })
245
+ )
202
246
  );
203
247
  }
204
248
  function TabsComponent(props) {
205
- const tabs = useTabs(props);
206
- return (
207
- <div className="tabs-container">
208
- <TabList {...props} {...tabs} />
209
- <TabContent {...props} {...tabs} />
210
- </div>
249
+ const tabs = (0, internal_1.useTabs)(props);
250
+ return react_1.default.createElement(
251
+ "div",
252
+ { className: "tabs-container" },
253
+ react_1.default.createElement(TabList, { ...props, ...tabs }),
254
+ react_1.default.createElement(TabContent, { ...props, ...tabs })
211
255
  );
212
256
  }
213
- export default function MimeTabs(props) {
214
- const isBrowser = useIsBrowser();
215
- return (
216
- <TabsComponent
257
+ function MimeTabs(props) {
258
+ const isBrowser = (0, useIsBrowser_1.default)();
259
+ return react_1.default.createElement(
260
+ TabsComponent,
261
+ // Remount tabs after hydration
262
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
263
+ {
217
264
  // Remount tabs after hydration
218
265
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
219
- key={String(isBrowser)}
220
- {...props}
221
- />
266
+ key: String(isBrowser),
267
+ ...props,
268
+ },
269
+ (0, internal_1.sanitizeTabsChildren)(props.children)
222
270
  );
223
271
  }
272
+ exports.default = MimeTabs;
@@ -8,10 +8,13 @@
8
8
  .openapi-tabs__operation-container {
9
9
  display: flex;
10
10
  align-items: center;
11
- margin-top: 1rem;
12
11
  overflow: hidden;
13
12
  }
14
13
 
14
+ .openapi-tabs__operation-header {
15
+ margin-bottom: 0;
16
+ }
17
+
15
18
  .openapi-tabs__operation-item {
16
19
  display: flex;
17
20
  align-items: center;
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { TabProps } from "@docusaurus/theme-common/internal";
3
+ export default function OperationTabs(props: TabProps): React.JSX.Element;