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,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,135 +133,140 @@ 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
- if (entry.target.offsetWidth < entry.target.scrollWidth) {
98
- setShowTabArrows(true);
99
- } else {
100
- setShowTabArrows(false);
101
- }
141
+ requestAnimationFrame(() => {
142
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
143
+ setShowTabArrows(true);
144
+ } else {
145
+ setShowTabArrows(false);
146
+ }
147
+ });
102
148
  }
103
149
  });
104
-
105
150
  resizeObserver.observe(tabItemListContainerRef.current);
106
-
107
151
  return () => {
108
152
  resizeObserver.disconnect();
109
153
  };
110
154
  }, []);
111
-
112
155
  const handleRightClick = () => {
113
156
  tabItemListContainerRef.current.scrollLeft += 90;
114
157
  };
115
-
116
158
  const handleLeftClick = () => {
117
159
  tabItemListContainerRef.current.scrollLeft -= 90;
118
160
  };
119
-
120
- return (
121
- <div className="tabs__container">
122
- <div className="openapi-tabs__mime-container">
123
- {showTabArrows && (
124
- <button
125
- className={clsx("openapi-tabs__arrow", "left")}
126
- onClick={handleLeftClick}
127
- />
128
- )}
129
- <ul
130
- ref={tabItemListContainerRef}
131
- role="tablist"
132
- aria-orientation="horizontal"
133
- 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)(
134
179
  "openapi-tabs__mime-list-container",
135
180
  "tabs",
136
181
  {
137
182
  "tabs--block": block,
138
183
  },
139
184
  className
140
- )}
141
- >
142
- {tabValues.map(({ value, label, attributes }) => {
143
- return (
144
- <li
145
- role="tab"
146
- tabIndex={selectedValue === value ? 0 : -1}
147
- aria-selected={selectedValue === value}
148
- key={value}
149
- ref={(tabControl) => tabRefs.push(tabControl)}
150
- onKeyDown={handleKeydown}
151
- onFocus={handleTabChange}
152
- onClick={(e) => handleTabChange(e)}
153
- {...attributes}
154
- className={clsx(
155
- "tabs__item",
156
- "openapi-tabs__mime-item",
157
- attributes?.className,
158
- {
159
- active: selectedValue === value,
160
- }
161
- )}
162
- >
163
- {label ?? value}
164
- </li>
165
- );
166
- })}
167
- </ul>
168
- {showTabArrows && (
169
- <button
170
- className={clsx("openapi-tabs__arrow", "right")}
171
- onClick={handleRightClick}
172
- />
173
- )}
174
- </div>
175
- </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
+ )
176
219
  );
177
220
  }
178
221
  function TabContent({ lazy, children, selectedValue }) {
179
- // eslint-disable-next-line no-param-reassign
180
- children = Array.isArray(children) ? children : [children];
222
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
223
+ Boolean
224
+ );
181
225
  if (lazy) {
182
- const selectedTabItem = children.find(
226
+ const selectedTabItem = childTabs.find(
183
227
  (tabItem) => tabItem.props.value === selectedValue
184
228
  );
185
229
  if (!selectedTabItem) {
186
230
  // fail-safe or fail-fast? not sure what's best here
187
231
  return null;
188
232
  }
189
- return cloneElement(selectedTabItem, { className: "margin-top--md" });
233
+ return (0, react_1.cloneElement)(selectedTabItem, {
234
+ className: "margin-top--md",
235
+ });
190
236
  }
191
- return (
192
- <div className="margin-top--md">
193
- {children.map((tabItem, i) =>
194
- cloneElement(tabItem, {
195
- key: i,
196
- hidden: tabItem.props.value !== selectedValue,
197
- })
198
- )}
199
- </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
+ )
200
246
  );
201
247
  }
202
248
  function TabsComponent(props) {
203
- const tabs = useTabs(props);
204
- return (
205
- <div className="tabs-container">
206
- <TabList {...props} {...tabs} />
207
- <TabContent {...props} {...tabs} />
208
- </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 })
209
255
  );
210
256
  }
211
- export default function MimeTabs(props) {
212
- const isBrowser = useIsBrowser();
213
- return (
214
- <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
+ {
215
264
  // Remount tabs after hydration
216
265
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
217
- key={String(isBrowser)}
218
- {...props}
219
- />
266
+ key: String(isBrowser),
267
+ ...props,
268
+ },
269
+ (0, internal_1.sanitizeTabsChildren)(props.children)
220
270
  );
221
271
  }
272
+ exports.default = MimeTabs;
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ .openapi-tabs__operation-container {
9
+ display: flex;
10
+ align-items: center;
11
+ overflow: hidden;
12
+ }
13
+
14
+ .openapi-tabs__operation-header {
15
+ margin-bottom: 0;
16
+ }
17
+
18
+ .openapi-tabs__operation-item {
19
+ display: flex;
20
+ align-items: center;
21
+ justify-content: center;
22
+ padding: 0.35rem 0.7rem;
23
+ border: 1px solid transparent;
24
+ margin-top: 0 !important;
25
+ margin-right: 0.5rem;
26
+ font-weight: var(--ifm-font-weight-bold);
27
+ font-size: 12px;
28
+ white-space: nowrap;
29
+ transition: 300ms;
30
+
31
+ &:hover {
32
+ background-color: transparent;
33
+ border: 1px solid var(--ifm-toc-border-color);
34
+ }
35
+
36
+ &.active {
37
+ border: 1px solid var(--ifm-tabs-color-active-border);
38
+ color: var(--ifm-tabs-color-active);
39
+ }
40
+
41
+ &:last-child {
42
+ margin-right: 0 !important;
43
+ }
44
+ }
45
+
46
+ .openapi-tabs__operation-list-container {
47
+ overflow-y: hidden;
48
+ overflow-x: scroll;
49
+ scroll-behavior: smooth;
50
+
51
+ &::-webkit-scrollbar {
52
+ display: none;
53
+ }
54
+ }
55
+
56
+ .openapi-tabs__operation-schema-container {
57
+ max-width: 600px;
58
+ }
59
+
60
+ @media screen and (max-width: 500px) {
61
+ .operationTabsTopSection {
62
+ flex-direction: column;
63
+ align-items: flex-start;
64
+ }
65
+
66
+ .operationTabsContainer {
67
+ width: 100%;
68
+ margin-top: var(--ifm-spacing-vertical);
69
+ padding: 0;
70
+ }
71
+ }
@@ -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;
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Copyright (c) Palo Alto Networks
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ * ========================================================================== */
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
+ function TabList({ className, block, selectedValue, selectValue, tabValues }) {
63
+ const tabRefs = [];
64
+ const { blockElementScrollPositionUntilNextRender } = (0,
65
+ internal_1.useScrollPositionBlocker)();
66
+ const handleTabChange = (event) => {
67
+ const newTab = event.currentTarget;
68
+ const newTabIndex = tabRefs.indexOf(newTab);
69
+ const newTabValue = tabValues[newTabIndex].value;
70
+ if (newTabValue !== selectedValue) {
71
+ blockElementScrollPositionUntilNextRender(newTab);
72
+ selectValue(newTabValue);
73
+ }
74
+ };
75
+ const handleKeydown = (event) => {
76
+ let focusElement = null;
77
+ switch (event.key) {
78
+ case "Enter": {
79
+ handleTabChange(event);
80
+ break;
81
+ }
82
+ case "ArrowRight": {
83
+ const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
84
+ focusElement = tabRefs[nextTab] ?? tabRefs[0];
85
+ break;
86
+ }
87
+ case "ArrowLeft": {
88
+ const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
89
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
90
+ break;
91
+ }
92
+ default:
93
+ break;
94
+ }
95
+ focusElement?.focus();
96
+ };
97
+ const tabItemListContainerRef = (0, react_1.useRef)(null);
98
+ const [showTabArrows, setShowTabArrows] = (0, react_1.useState)(false);
99
+ (0, react_1.useEffect)(() => {
100
+ const resizeObserver = new ResizeObserver((entries) => {
101
+ for (let entry of entries) {
102
+ requestAnimationFrame(() => {
103
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
104
+ setShowTabArrows(true);
105
+ } else {
106
+ setShowTabArrows(false);
107
+ }
108
+ });
109
+ }
110
+ });
111
+ resizeObserver.observe(tabItemListContainerRef.current);
112
+ return () => {
113
+ resizeObserver.disconnect();
114
+ };
115
+ }, []);
116
+ const handleRightClick = () => {
117
+ tabItemListContainerRef.current.scrollLeft += 90;
118
+ };
119
+ const handleLeftClick = () => {
120
+ tabItemListContainerRef.current.scrollLeft -= 90;
121
+ };
122
+ return react_1.default.createElement(
123
+ "div",
124
+ { className: "tabs__container" },
125
+ react_1.default.createElement(
126
+ "div",
127
+ { className: "openapi-tabs__operation-container" },
128
+ showTabArrows &&
129
+ react_1.default.createElement("button", {
130
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "left"),
131
+ onClick: handleLeftClick,
132
+ }),
133
+ react_1.default.createElement(
134
+ "ul",
135
+ {
136
+ ref: tabItemListContainerRef,
137
+ role: "tablist",
138
+ "aria-orientation": "horizontal",
139
+ className: (0, clsx_1.default)(
140
+ "openapi-tabs__operation-list-container",
141
+ "tabs",
142
+ {
143
+ "tabs--block": block,
144
+ },
145
+ className
146
+ ),
147
+ },
148
+ tabValues.map(({ value, label, attributes }) => {
149
+ return react_1.default.createElement(
150
+ "li",
151
+ {
152
+ // TODO extract TabListItem
153
+ role: "tab",
154
+ tabIndex: selectedValue === value ? 0 : -1,
155
+ "aria-selected": selectedValue === value,
156
+ key: value,
157
+ ref: (tabControl) => tabRefs.push(tabControl),
158
+ onKeyDown: handleKeydown,
159
+ onFocus: handleTabChange,
160
+ onClick: (e) => handleTabChange(e),
161
+ ...attributes,
162
+ className: (0, clsx_1.default)(
163
+ "tabs__item",
164
+ "openapi-tabs__operation-item",
165
+ attributes?.className,
166
+ {
167
+ active: selectedValue === value,
168
+ }
169
+ ),
170
+ },
171
+ label ?? value
172
+ );
173
+ })
174
+ ),
175
+ showTabArrows &&
176
+ react_1.default.createElement("button", {
177
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "right"),
178
+ onClick: handleRightClick,
179
+ })
180
+ )
181
+ );
182
+ }
183
+ function TabContent({ lazy, children, selectedValue }) {
184
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
185
+ Boolean
186
+ );
187
+ if (lazy) {
188
+ const selectedTabItem = childTabs.find(
189
+ (tabItem) => tabItem.props.value === selectedValue
190
+ );
191
+ if (!selectedTabItem) {
192
+ // fail-safe or fail-fast? not sure what's best here
193
+ return null;
194
+ }
195
+ return (0, react_1.cloneElement)(selectedTabItem, {
196
+ className: "margin-top--md",
197
+ });
198
+ }
199
+ return react_1.default.createElement(
200
+ "div",
201
+ { className: "margin-top--md" },
202
+ childTabs.map((tabItem, i) =>
203
+ (0, react_1.cloneElement)(tabItem, {
204
+ key: i,
205
+ hidden: tabItem.props.value !== selectedValue,
206
+ })
207
+ )
208
+ );
209
+ }
210
+ function TabsComponent(props) {
211
+ const tabs = (0, internal_1.useTabs)(props);
212
+ return react_1.default.createElement(
213
+ "div",
214
+ { className: "tabs-container" },
215
+ react_1.default.createElement(TabList, { ...props, ...tabs }),
216
+ react_1.default.createElement(TabContent, { ...props, ...tabs })
217
+ );
218
+ }
219
+ function OperationTabs(props) {
220
+ const isBrowser = (0, useIsBrowser_1.default)();
221
+ return react_1.default.createElement(
222
+ TabsComponent,
223
+ // Remount tabs after hydration
224
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
225
+ {
226
+ // Remount tabs after hydration
227
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
228
+ key: String(isBrowser),
229
+ ...props,
230
+ },
231
+ (0, internal_1.sanitizeTabsChildren)(props.children)
232
+ );
233
+ }
234
+ exports.default = OperationTabs;