docusaurus-theme-openapi-docs 3.0.0-beta.3 → 3.0.0-beta.5

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 (115) 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/Accept/index.d.ts +2 -2
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.d.ts +4 -0
  6. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +25 -19
  7. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.d.ts +4 -0
  8. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/Element.js +27 -16
  9. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.d.ts +4 -0
  10. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +115 -96
  11. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.d.ts +3 -0
  12. package/lib/theme/ApiExplorer/ApiCodeBlock/CopyButton/index.js +115 -54
  13. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.d.ts +6 -0
  14. package/lib/theme/ApiExplorer/ApiCodeBlock/ExitButton/index.js +41 -30
  15. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.d.ts +14 -0
  16. package/lib/theme/ApiExplorer/ApiCodeBlock/ExpandButton/index.js +200 -120
  17. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +3 -0
  18. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.js +36 -24
  19. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.d.ts +7 -0
  20. package/lib/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/index.js +35 -28
  21. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +3 -0
  22. package/lib/theme/ApiExplorer/ApiCodeBlock/index.js +72 -14
  23. package/lib/theme/ApiExplorer/Authorization/index.d.ts +2 -2
  24. package/lib/theme/ApiExplorer/Body/index.d.ts +2 -2
  25. package/lib/theme/ApiExplorer/Body/index.js +8 -1
  26. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.d.ts +21 -0
  27. package/lib/theme/ApiExplorer/CodeSnippets/code-snippets-types.js +8 -0
  28. package/lib/theme/ApiExplorer/CodeSnippets/index.d.ts +4 -14
  29. package/lib/theme/ApiExplorer/CodeSnippets/index.js +87 -8
  30. package/lib/theme/ApiExplorer/CodeSnippets/languages.d.ts +2 -0
  31. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +32 -0
  32. package/lib/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
  33. package/lib/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
  34. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +14 -0
  35. package/lib/theme/ApiExplorer/CodeTabs/index.js +130 -78
  36. package/lib/theme/ApiExplorer/ContentType/index.d.ts +2 -2
  37. package/lib/theme/ApiExplorer/Export/index.d.ts +2 -2
  38. package/lib/theme/ApiExplorer/FloatingButton/index.d.ts +1 -1
  39. package/lib/theme/ApiExplorer/FormFileUpload/index.d.ts +2 -2
  40. package/lib/theme/ApiExplorer/FormItem/index.d.ts +1 -1
  41. package/lib/theme/ApiExplorer/FormMultiSelect/index.d.ts +1 -1
  42. package/lib/theme/ApiExplorer/FormSelect/index.d.ts +1 -1
  43. package/lib/theme/ApiExplorer/FormTextInput/index.d.ts +1 -1
  44. package/lib/theme/ApiExplorer/MethodEndpoint/index.d.ts +2 -2
  45. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.d.ts +2 -2
  46. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.d.ts +2 -2
  47. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.d.ts +2 -2
  48. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.d.ts +2 -2
  49. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.d.ts +2 -2
  50. package/lib/theme/ApiExplorer/ParamOptions/index.d.ts +2 -2
  51. package/lib/theme/ApiExplorer/Request/index.d.ts +2 -2
  52. package/lib/theme/ApiExplorer/Response/index.d.ts +2 -2
  53. package/lib/theme/ApiExplorer/SecuritySchemes/index.d.ts +2 -2
  54. package/lib/theme/ApiExplorer/Server/index.d.ts +2 -2
  55. package/lib/theme/ApiExplorer/index.d.ts +2 -2
  56. package/lib/theme/ApiExplorer/index.js +1 -1
  57. package/lib/theme/ApiItem/index.d.ts +2 -2
  58. package/lib/theme/ApiItem/index.js +4 -3
  59. package/lib/theme/ApiItem/store.d.ts +4 -4
  60. package/lib/theme/ApiLogo/index.d.ts +2 -2
  61. package/lib/theme/ApiTabs/index.d.ts +7 -0
  62. package/lib/theme/ApiTabs/index.js +155 -97
  63. package/lib/theme/DiscriminatorTabs/index.d.ts +3 -0
  64. package/lib/theme/DiscriminatorTabs/index.js +146 -94
  65. package/lib/theme/Markdown/index.js +37 -0
  66. package/lib/theme/MimeTabs/index.d.ts +6 -0
  67. package/lib/theme/MimeTabs/index.js +163 -114
  68. package/lib/theme/OperationTabs/_OperationTabs.scss +68 -0
  69. package/lib/theme/OperationTabs/index.d.ts +3 -0
  70. package/lib/theme/OperationTabs/index.js +232 -0
  71. package/lib/theme/ParamsItem/index.d.ts +22 -0
  72. package/lib/theme/ParamsItem/index.js +154 -109
  73. package/lib/theme/ResponseSamples/index.d.ts +8 -0
  74. package/lib/theme/ResponseSamples/index.js +18 -13
  75. package/lib/theme/SchemaItem/index.d.ts +12 -0
  76. package/lib/theme/SchemaItem/index.js +123 -89
  77. package/lib/theme/SchemaTabs/index.d.ts +3 -0
  78. package/lib/theme/SchemaTabs/index.js +142 -91
  79. package/lib/theme/styles.scss +1 -0
  80. package/package.json +4 -4
  81. package/src/markdown/utils.ts +4 -2
  82. package/src/theme/ApiDemoPanel/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +21 -8
  83. package/src/theme/ApiExplorer/ApiCodeBlock/Container/{index.js → index.tsx} +6 -3
  84. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{Element.js → Element.tsx} +5 -1
  85. package/src/theme/ApiExplorer/ApiCodeBlock/Content/{String.js → String.tsx} +4 -4
  86. package/src/theme/ApiExplorer/ApiCodeBlock/CopyButton/{index.js → index.tsx} +8 -3
  87. package/src/theme/ApiExplorer/ApiCodeBlock/ExitButton/{index.js → index.tsx} +9 -1
  88. package/src/theme/ApiExplorer/ApiCodeBlock/ExpandButton/{index.js → index.tsx} +12 -2
  89. package/src/theme/ApiExplorer/ApiCodeBlock/Line/{index.js → index.tsx} +2 -1
  90. package/src/theme/ApiExplorer/ApiCodeBlock/WordWrapButton/{index.js → index.tsx} +11 -1
  91. package/src/theme/ApiExplorer/ApiCodeBlock/{index.js → index.tsx} +10 -5
  92. package/src/theme/ApiExplorer/Body/index.tsx +3 -1
  93. package/src/theme/ApiExplorer/CodeSnippets/code-snippets-types.ts +55 -0
  94. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +94 -21
  95. package/src/theme/ApiExplorer/CodeSnippets/languages.json +0 -96
  96. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +37 -0
  97. package/src/theme/ApiExplorer/CodeTabs/_CodeTabs.scss +14 -0
  98. package/src/theme/ApiExplorer/CodeTabs/{index.js → index.tsx} +57 -25
  99. package/src/theme/ApiExplorer/index.tsx +1 -1
  100. package/src/theme/ApiItem/index.tsx +3 -4
  101. package/src/theme/ApiLogo/index.tsx +1 -1
  102. package/src/theme/ApiTabs/{index.js → index.tsx} +63 -25
  103. package/src/theme/DiscriminatorTabs/{index.js → index.tsx} +57 -24
  104. package/src/theme/Markdown/index.js +37 -0
  105. package/src/theme/MimeTabs/{index.js → index.tsx} +58 -26
  106. package/src/theme/OperationTabs/_OperationTabs.scss +68 -0
  107. package/src/theme/OperationTabs/index.tsx +216 -0
  108. package/src/theme/ParamsItem/{index.js → index.tsx} +28 -13
  109. package/src/theme/ResponseSamples/{index.js → index.tsx} +10 -1
  110. package/src/theme/SchemaItem/{index.js → index.tsx} +18 -9
  111. package/src/theme/SchemaTabs/{index.js → index.tsx} +56 -25
  112. package/src/theme/styles.scss +1 -0
  113. package/src/theme-classic.d.ts +69 -2
  114. package/src/theme-openapi.d.ts +4 -0
  115. package/tsconfig.json +4 -1
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import { TabProps } from "@docusaurus/theme-common/internal";
3
+ export interface Props {
4
+ schemaType: any;
5
+ }
6
+ export default function MimeTabs(props: Props & TabProps): React.JSX.Element;
@@ -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,138 @@ 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) {
141
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
98
142
  setShowTabArrows(true);
99
143
  } else {
100
144
  setShowTabArrows(false);
101
145
  }
102
146
  }
103
147
  });
104
-
105
148
  resizeObserver.observe(tabItemListContainerRef.current);
106
-
107
149
  return () => {
108
150
  resizeObserver.disconnect();
109
151
  };
110
152
  }, []);
111
-
112
153
  const handleRightClick = () => {
113
154
  tabItemListContainerRef.current.scrollLeft += 90;
114
155
  };
115
-
116
156
  const handleLeftClick = () => {
117
157
  tabItemListContainerRef.current.scrollLeft -= 90;
118
158
  };
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(
159
+ return react_1.default.createElement(
160
+ "div",
161
+ { className: "tabs__container" },
162
+ react_1.default.createElement(
163
+ "div",
164
+ { className: "openapi-tabs__mime-container" },
165
+ showTabArrows &&
166
+ react_1.default.createElement("button", {
167
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "left"),
168
+ onClick: handleLeftClick,
169
+ }),
170
+ react_1.default.createElement(
171
+ "ul",
172
+ {
173
+ ref: tabItemListContainerRef,
174
+ role: "tablist",
175
+ "aria-orientation": "horizontal",
176
+ className: (0, clsx_1.default)(
134
177
  "openapi-tabs__mime-list-container",
135
178
  "tabs",
136
179
  {
137
180
  "tabs--block": block,
138
181
  },
139
182
  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>
183
+ ),
184
+ },
185
+ tabValues.map(({ value, label, attributes }) => {
186
+ return react_1.default.createElement(
187
+ "li",
188
+ {
189
+ role: "tab",
190
+ tabIndex: selectedValue === value ? 0 : -1,
191
+ "aria-selected": selectedValue === value,
192
+ key: value,
193
+ ref: (tabControl) => tabRefs.push(tabControl),
194
+ onKeyDown: handleKeydown,
195
+ onFocus: handleTabChange,
196
+ onClick: (e) => handleTabChange(e),
197
+ ...attributes,
198
+ className: (0, clsx_1.default)(
199
+ "tabs__item",
200
+ "openapi-tabs__mime-item",
201
+ attributes?.className,
202
+ {
203
+ active: selectedValue === value,
204
+ }
205
+ ),
206
+ },
207
+ label ?? value
208
+ );
209
+ })
210
+ ),
211
+ showTabArrows &&
212
+ react_1.default.createElement("button", {
213
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "right"),
214
+ onClick: handleRightClick,
215
+ })
216
+ )
176
217
  );
177
218
  }
178
219
  function TabContent({ lazy, children, selectedValue }) {
179
- // eslint-disable-next-line no-param-reassign
180
- children = Array.isArray(children) ? children : [children];
220
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
221
+ Boolean
222
+ );
181
223
  if (lazy) {
182
- const selectedTabItem = children.find(
224
+ const selectedTabItem = childTabs.find(
183
225
  (tabItem) => tabItem.props.value === selectedValue
184
226
  );
185
227
  if (!selectedTabItem) {
186
228
  // fail-safe or fail-fast? not sure what's best here
187
229
  return null;
188
230
  }
189
- return cloneElement(selectedTabItem, { className: "margin-top--md" });
231
+ return (0, react_1.cloneElement)(selectedTabItem, {
232
+ className: "margin-top--md",
233
+ });
190
234
  }
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>
235
+ return react_1.default.createElement(
236
+ "div",
237
+ { className: "margin-top--md" },
238
+ childTabs.map((tabItem, i) =>
239
+ (0, react_1.cloneElement)(tabItem, {
240
+ key: i,
241
+ hidden: tabItem.props.value !== selectedValue,
242
+ })
243
+ )
200
244
  );
201
245
  }
202
246
  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>
247
+ const tabs = (0, internal_1.useTabs)(props);
248
+ return react_1.default.createElement(
249
+ "div",
250
+ { className: "tabs-container" },
251
+ react_1.default.createElement(TabList, { ...props, ...tabs }),
252
+ react_1.default.createElement(TabContent, { ...props, ...tabs })
209
253
  );
210
254
  }
211
- export default function MimeTabs(props) {
212
- const isBrowser = useIsBrowser();
213
- return (
214
- <TabsComponent
255
+ function MimeTabs(props) {
256
+ const isBrowser = (0, useIsBrowser_1.default)();
257
+ return react_1.default.createElement(
258
+ TabsComponent,
259
+ // Remount tabs after hydration
260
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
261
+ {
215
262
  // Remount tabs after hydration
216
263
  // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
217
- key={String(isBrowser)}
218
- {...props}
219
- />
264
+ key: String(isBrowser),
265
+ ...props,
266
+ },
267
+ (0, internal_1.sanitizeTabsChildren)(props.children)
220
268
  );
221
269
  }
270
+ exports.default = MimeTabs;
@@ -0,0 +1,68 @@
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
+ margin-top: 1rem;
12
+ overflow: hidden;
13
+ }
14
+
15
+ .openapi-tabs__operation-item {
16
+ display: flex;
17
+ align-items: center;
18
+ justify-content: center;
19
+ padding: 0.35rem 0.7rem;
20
+ border: 1px solid transparent;
21
+ margin-top: 0 !important;
22
+ margin-right: 0.5rem;
23
+ font-weight: var(--ifm-font-weight-bold);
24
+ font-size: 12px;
25
+ white-space: nowrap;
26
+ transition: 300ms;
27
+
28
+ &:hover {
29
+ background-color: transparent;
30
+ border: 1px solid var(--ifm-toc-border-color);
31
+ }
32
+
33
+ &.active {
34
+ border: 1px solid var(--ifm-tabs-color-active-border);
35
+ color: var(--ifm-tabs-color-active);
36
+ }
37
+
38
+ &:last-child {
39
+ margin-right: 0 !important;
40
+ }
41
+ }
42
+
43
+ .openapi-tabs__operation-list-container {
44
+ overflow-y: hidden;
45
+ overflow-x: scroll;
46
+ scroll-behavior: smooth;
47
+
48
+ &::-webkit-scrollbar {
49
+ display: none;
50
+ }
51
+ }
52
+
53
+ .openapi-tabs__operation-schema-container {
54
+ max-width: 600px;
55
+ }
56
+
57
+ @media screen and (max-width: 500px) {
58
+ .operationTabsTopSection {
59
+ flex-direction: column;
60
+ align-items: flex-start;
61
+ }
62
+
63
+ .operationTabsContainer {
64
+ width: 100%;
65
+ margin-top: var(--ifm-spacing-vertical);
66
+ padding: 0;
67
+ }
68
+ }
@@ -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,232 @@
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
+ if (entry.target.clientWidth < entry.target.scrollWidth) {
103
+ setShowTabArrows(true);
104
+ } else {
105
+ setShowTabArrows(false);
106
+ }
107
+ }
108
+ });
109
+ resizeObserver.observe(tabItemListContainerRef.current);
110
+ return () => {
111
+ resizeObserver.disconnect();
112
+ };
113
+ }, []);
114
+ const handleRightClick = () => {
115
+ tabItemListContainerRef.current.scrollLeft += 90;
116
+ };
117
+ const handleLeftClick = () => {
118
+ tabItemListContainerRef.current.scrollLeft -= 90;
119
+ };
120
+ return react_1.default.createElement(
121
+ "div",
122
+ { className: "tabs__container" },
123
+ react_1.default.createElement(
124
+ "div",
125
+ { className: "openapi-tabs__operation-container" },
126
+ showTabArrows &&
127
+ react_1.default.createElement("button", {
128
+ className: (0, clsx_1.default)("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)(
138
+ "openapi-tabs__operation-list-container",
139
+ "tabs",
140
+ {
141
+ "tabs--block": block,
142
+ },
143
+ className
144
+ ),
145
+ },
146
+ tabValues.map(({ value, label, attributes }) => {
147
+ return react_1.default.createElement(
148
+ "li",
149
+ {
150
+ // TODO extract TabListItem
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
+ onFocus: handleTabChange,
158
+ onClick: (e) => handleTabChange(e),
159
+ ...attributes,
160
+ className: (0, clsx_1.default)(
161
+ "tabs__item",
162
+ "openapi-tabs__operation-item",
163
+ attributes?.className,
164
+ {
165
+ active: selectedValue === value,
166
+ }
167
+ ),
168
+ },
169
+ label ?? value
170
+ );
171
+ })
172
+ ),
173
+ showTabArrows &&
174
+ react_1.default.createElement("button", {
175
+ className: (0, clsx_1.default)("openapi-tabs__arrow", "right"),
176
+ onClick: handleRightClick,
177
+ })
178
+ )
179
+ );
180
+ }
181
+ function TabContent({ lazy, children, selectedValue }) {
182
+ const childTabs = (Array.isArray(children) ? children : [children]).filter(
183
+ Boolean
184
+ );
185
+ if (lazy) {
186
+ const selectedTabItem = childTabs.find(
187
+ (tabItem) => tabItem.props.value === selectedValue
188
+ );
189
+ if (!selectedTabItem) {
190
+ // fail-safe or fail-fast? not sure what's best here
191
+ return null;
192
+ }
193
+ return (0, react_1.cloneElement)(selectedTabItem, {
194
+ className: "margin-top--md",
195
+ });
196
+ }
197
+ return react_1.default.createElement(
198
+ "div",
199
+ { className: "margin-top--md" },
200
+ childTabs.map((tabItem, i) =>
201
+ (0, react_1.cloneElement)(tabItem, {
202
+ key: i,
203
+ hidden: tabItem.props.value !== selectedValue,
204
+ })
205
+ )
206
+ );
207
+ }
208
+ function TabsComponent(props) {
209
+ const tabs = (0, internal_1.useTabs)(props);
210
+ return react_1.default.createElement(
211
+ "div",
212
+ { className: "tabs-container" },
213
+ react_1.default.createElement(TabList, { ...props, ...tabs }),
214
+ react_1.default.createElement(TabContent, { ...props, ...tabs })
215
+ );
216
+ }
217
+ function OperationTabs(props) {
218
+ const isBrowser = (0, useIsBrowser_1.default)();
219
+ return react_1.default.createElement(
220
+ TabsComponent,
221
+ // Remount tabs after hydration
222
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
223
+ {
224
+ // Remount tabs after hydration
225
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
226
+ key: String(isBrowser),
227
+ ...props,
228
+ },
229
+ (0, internal_1.sanitizeTabsChildren)(props.children)
230
+ );
231
+ }
232
+ exports.default = OperationTabs;