docusaurus-theme-openapi-docs 1.0.2 → 1.0.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 (59) hide show
  1. package/lib/theme/ApiDemoPanel/Body/index.js +11 -9
  2. package/lib/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  3. package/lib/theme/ApiDemoPanel/CodeTabs/index.js +188 -0
  4. package/lib/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  5. package/lib/theme/ApiDemoPanel/Curl/index.js +41 -110
  6. package/lib/theme/ApiDemoPanel/LiveEditor/index.js +61 -0
  7. package/lib/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  8. package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  9. package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +7 -2
  10. package/lib/theme/ApiDemoPanel/index.js +3 -7
  11. package/lib/theme/ApiItem/icons/bash-original.svg +1 -0
  12. package/lib/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  13. package/lib/theme/ApiItem/icons/javascript-original.svg +1 -0
  14. package/lib/theme/ApiItem/icons/linux-original.svg +1 -0
  15. package/lib/theme/ApiItem/icons/python-original.svg +1 -0
  16. package/lib/theme/ApiItem/index.js +2 -1
  17. package/lib/theme/ApiItem/styles.module.css +89 -0
  18. package/lib-next/theme/ApiDemoPanel/Body/index.js +11 -15
  19. package/lib-next/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  20. package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +214 -0
  21. package/lib-next/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  22. package/lib-next/theme/ApiDemoPanel/Curl/index.js +46 -135
  23. package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +49 -0
  24. package/lib-next/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  25. package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +9 -6
  26. package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +6 -2
  27. package/lib-next/theme/ApiDemoPanel/index.js +2 -7
  28. package/lib-next/theme/ApiItem/icons/bash-original.svg +1 -0
  29. package/lib-next/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  30. package/lib-next/theme/ApiItem/icons/javascript-original.svg +1 -0
  31. package/lib-next/theme/ApiItem/icons/linux-original.svg +1 -0
  32. package/lib-next/theme/ApiItem/icons/python-original.svg +1 -0
  33. package/lib-next/theme/ApiItem/index.js +2 -1
  34. package/lib-next/theme/ApiItem/styles.module.css +89 -0
  35. package/package.json +7 -9
  36. package/src/theme/ApiDemoPanel/Body/index.tsx +9 -13
  37. package/src/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  38. package/src/theme/ApiDemoPanel/CodeTabs/index.tsx +237 -0
  39. package/src/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  40. package/src/theme/ApiDemoPanel/Curl/index.tsx +45 -124
  41. package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +59 -0
  42. package/src/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  43. package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +6 -4
  44. package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +7 -2
  45. package/src/theme/ApiDemoPanel/index.tsx +8 -7
  46. package/src/theme/ApiItem/icons/bash-original.svg +1 -0
  47. package/src/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  48. package/src/theme/ApiItem/icons/javascript-original.svg +1 -0
  49. package/src/theme/ApiItem/icons/linux-original.svg +1 -0
  50. package/src/theme/ApiItem/icons/python-original.svg +1 -0
  51. package/src/theme/ApiItem/index.tsx +9 -5
  52. package/src/theme/ApiItem/styles.module.css +89 -0
  53. package/src/types.ts +112 -0
  54. package/lib/theme/ApiDemoPanel/VSCode/index.js +0 -252
  55. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  56. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +0 -265
  57. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  58. package/src/theme/ApiDemoPanel/VSCode/index.tsx +0 -205
  59. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
@@ -11,6 +11,23 @@
11
11
  margin-top: 0;
12
12
  }
13
13
 
14
+ :global(.version-button div) {
15
+ display: block;
16
+ }
17
+
18
+ :global(.version-button div > button > span::after) {
19
+ border-color: currentcolor transparent;
20
+ border-style: solid;
21
+ border-width: 0.4em 0.4em 0;
22
+ content: "";
23
+ margin-left: 0.3em;
24
+ position: relative;
25
+ transform: translateY(-50%);
26
+ display: inline-block;
27
+ font-size: 0.8rem;
28
+ top: 1px;
29
+ }
30
+
14
31
  /* default markdown margins look really silly in a table */
15
32
  :global(.theme-api-markdown table *:last-child) {
16
33
  margin-bottom: 0;
@@ -111,3 +128,75 @@
111
128
  margin-top: 0 !important;
112
129
  padding-left: 2px;
113
130
  }
131
+
132
+ :global(.code__tab--python::after) {
133
+ content: "";
134
+ width: 32px;
135
+ height: 32px;
136
+ background: url(./icons/python-original.svg);
137
+ margin-block: auto;
138
+ }
139
+
140
+ :global(.code__tab--python) {
141
+ color: var(--ifm-color-success);
142
+ padding-left: 2rem;
143
+ padding-right: 2rem;
144
+ }
145
+
146
+ :global(.code__tab--python.tabs__item--active) {
147
+ border-bottom-color: var(--ifm-color-success);
148
+ }
149
+
150
+ :global(.code__tab--go::after) {
151
+ content: "";
152
+ width: 32px;
153
+ height: 32px;
154
+ background: url(./icons/go-original-wordmark.svg);
155
+ margin-block: auto;
156
+ }
157
+
158
+ :global(.code__tab--go) {
159
+ color: var(--ifm-color-info);
160
+ padding-left: 2rem;
161
+ padding-right: 2rem;
162
+ }
163
+
164
+ :global(.code__tab--go.tabs__item--active) {
165
+ border-bottom-color: var(--ifm-color-info);
166
+ }
167
+
168
+ :global(.code__tab--javascript::after) {
169
+ content: "";
170
+ width: 32px;
171
+ height: 32px;
172
+ background: url(./icons/javascript-original.svg);
173
+ margin-block: auto;
174
+ }
175
+
176
+ :global(.code__tab--javascript) {
177
+ color: var(--ifm-color-warning);
178
+ padding-left: 2rem;
179
+ padding-right: 2rem;
180
+ }
181
+
182
+ :global(.code__tab--javascript.tabs__item--active) {
183
+ border-bottom-color: var(--ifm-color-warning);
184
+ }
185
+
186
+ :global(.code__tab--bash::after) {
187
+ content: "";
188
+ width: 32px;
189
+ height: 32px;
190
+ background: url(./icons/linux-original.svg);
191
+ margin-block: auto;
192
+ }
193
+
194
+ :global(.code__tab--bash) {
195
+ color: var(--ifm-color-danger);
196
+ padding-left: 2rem;
197
+ padding-right: 2rem;
198
+ }
199
+
200
+ :global(.code__tab--bash.tabs__item--active) {
201
+ border-bottom-color: var(--ifm-color-danger);
202
+ }
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": "1.0.2",
4
+ "version": "1.0.5",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -31,8 +31,8 @@
31
31
  "format:lib-next": "prettier --config ../../.prettierrc.json --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
32
32
  },
33
33
  "devDependencies": {
34
- "@docusaurus/module-type-aliases": "2.0.0-beta.18",
35
- "@docusaurus/types": "2.0.0-beta.18",
34
+ "@docusaurus/module-type-aliases": "2.0.0-beta.21",
35
+ "@docusaurus/types": "2.0.0-beta.21",
36
36
  "@types/concurrently": "^6.3.0",
37
37
  "@types/crypto-js": "^4.1.0",
38
38
  "@types/fs-extra": "^9.0.13",
@@ -42,21 +42,19 @@
42
42
  "concurrently": "^5.2.0"
43
43
  },
44
44
  "dependencies": {
45
- "@docusaurus/theme-common": "2.0.0-beta.18",
45
+ "@docusaurus/theme-common": "2.0.0-beta.21",
46
46
  "@mdx-js/react": "^1.6.21",
47
- "@monaco-editor/react": "^4.3.1",
48
47
  "@paloaltonetworks/postman-code-generators": "1.1.5-hotfix.5",
49
48
  "@paloaltonetworks/postman-collection": "^4.1.0",
50
49
  "@reduxjs/toolkit": "^1.7.1",
51
50
  "buffer": "^6.0.3",
52
51
  "clsx": "^1.1.1",
53
52
  "crypto-js": "^4.1.1",
54
- "docusaurus-plugin-openapi-docs": "^1.0.2",
53
+ "docusaurus-plugin-openapi-docs": "^1.0.5",
55
54
  "immer": "^9.0.7",
56
55
  "lodash": "^4.17.20",
57
- "monaco-editor": "^0.31.1",
58
- "prism-react-renderer": "^1.2.1",
59
56
  "process": "^0.11.10",
57
+ "react-live": "^3.1.1",
60
58
  "react-magic-dropzone": "^1.0.1",
61
59
  "react-markdown": "^8.0.1",
62
60
  "react-redux": "^7.2.0",
@@ -70,5 +68,5 @@
70
68
  "engines": {
71
69
  "node": ">=14"
72
70
  },
73
- "gitHead": "526f2d10bc187bc7095ac70d5b1453b9b92c114f"
71
+ "gitHead": "fe58997d349cdab4f113c4a7449cd650882dcab6"
74
72
  }
@@ -12,17 +12,18 @@ import { RequestBodyObject } from "docusaurus-plugin-openapi-docs/src/openapi/ty
12
12
  import ContentType from "../ContentType";
13
13
  import FormSelect from "../FormSelect";
14
14
  import { useTypedDispatch, useTypedSelector } from "../hooks";
15
+ import LiveApp from "../LiveEditor";
15
16
  import FormFileUpload from "./../FormFileUpload";
16
17
  import FormItem from "./../FormItem";
17
18
  import FormTextInput from "./../FormTextInput";
18
- import VSCode from "./../VSCode";
19
+ // @ts-ignore
20
+ import json2xml from "./json2xml";
19
21
  import {
20
22
  clearFormBodyKey,
21
23
  clearRawBody,
22
24
  setFileFormBody,
23
25
  setFileRawBody,
24
26
  setStringFormBody,
25
- setStringRawBody,
26
27
  } from "./slice";
27
28
 
28
29
  interface Props {
@@ -195,22 +196,17 @@ function Body({ requestBodyMetadata, jsonRequestBodyExample }: Props) {
195
196
  }
196
197
 
197
198
  if (contentType === "application/xml") {
199
+ if (jsonRequestBodyExample) {
200
+ exampleBodyString = json2xml(jsonRequestBodyExample);
201
+ }
198
202
  language = "xml";
199
203
  }
200
204
 
201
205
  return (
202
206
  <FormItem label="Body">
203
- <VSCode
204
- value={exampleBodyString}
205
- language={language}
206
- onChange={(value) => {
207
- if (value.trim() === "") {
208
- dispatch(clearRawBody());
209
- return;
210
- }
211
- dispatch(setStringRawBody(value));
212
- }}
213
- />
207
+ <LiveApp action={dispatch} language={language}>
208
+ {exampleBodyString}
209
+ </LiveApp>
214
210
  </FormItem>
215
211
  );
216
212
  }
@@ -0,0 +1,43 @@
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
+ export default function json2xml(o, tab) {
9
+ var toXml = function (v, name, ind) {
10
+ var xml = "";
11
+ if (v instanceof Array) {
12
+ for (var i = 0, n = v.length; i < n; i++)
13
+ xml += ind + toXml(v[i], name, ind + "\t") + "\n";
14
+ } else if (typeof v == "object") {
15
+ var hasChild = false;
16
+ xml += ind + "<" + name;
17
+ for (var m in v) {
18
+ if (m.charAt(0) === "@")
19
+ xml += " " + m.substr(1) + '="' + v[m].toString() + '"';
20
+ else hasChild = true;
21
+ }
22
+ xml += hasChild ? ">" : "/>";
23
+ if (hasChild) {
24
+ for (var m2 in v) {
25
+ if (m2 === "#text") xml += v[m2];
26
+ else if (m2 === "#cdata") xml += "<![CDATA[" + v[m2] + "]]>";
27
+ else if (m2.charAt(0) !== "@") xml += toXml(v[m2], m2, ind + "\t");
28
+ }
29
+ xml +=
30
+ (xml.charAt(xml.length - 1) === "\n" ? ind : "") +
31
+ "</" +
32
+ name +
33
+ ">";
34
+ }
35
+ } else {
36
+ xml += ind + "<" + name + ">" + v.toString() + "</" + name + ">";
37
+ }
38
+ return xml;
39
+ },
40
+ xml = "";
41
+ for (var m3 in o) xml += toXml(o[m3], m3, "");
42
+ return tab ? xml.replace(/\t/g, tab) : xml.replace(/\t|\n/g, "");
43
+ }
@@ -0,0 +1,237 @@
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 React, {
9
+ useState,
10
+ cloneElement,
11
+ isValidElement,
12
+ type ReactElement,
13
+ } from "react";
14
+
15
+ import {
16
+ useScrollPositionBlocker,
17
+ duplicates,
18
+ useTabGroupChoice,
19
+ } from "@docusaurus/theme-common";
20
+ import useIsBrowser from "@docusaurus/useIsBrowser";
21
+ import type { Props as TabItemProps } from "@theme/TabItem";
22
+ import clsx from "clsx";
23
+
24
+ import { languageSet } from "../Curl";
25
+ import styles from "./styles.module.css";
26
+
27
+ // A very rough duck type, but good enough to guard against mistakes while
28
+ // allowing customization
29
+ function isTabItem(
30
+ comp: ReactElement<object>
31
+ ): comp is ReactElement<TabItemProps> {
32
+ return "value" in comp.props;
33
+ }
34
+
35
+ export interface Props {
36
+ readonly lazy?: boolean;
37
+ readonly block?: boolean;
38
+ readonly children: readonly ReactElement<TabItemProps>[];
39
+ readonly defaultValue?: string | null;
40
+ readonly values?: readonly {
41
+ value: string;
42
+ label?: string;
43
+ attributes?: { [key: string]: unknown };
44
+ }[];
45
+ readonly groupId?: string;
46
+ readonly className?: string;
47
+ readonly action?: any;
48
+ }
49
+
50
+ function TabsComponent(props: Props): JSX.Element {
51
+ const {
52
+ lazy,
53
+ block,
54
+ defaultValue: defaultValueProp,
55
+ values: valuesProp,
56
+ groupId,
57
+ className,
58
+ action,
59
+ } = props;
60
+ const children = React.Children.map(props.children, (child) => {
61
+ if (isValidElement(child) && isTabItem(child)) {
62
+ return child;
63
+ }
64
+ // child.type.name will give non-sensical values in prod because of
65
+ // minification, but we assume it won't throw in prod.
66
+ throw new Error(
67
+ `Docusaurus error: Bad <Tabs> child <${
68
+ // @ts-expect-error: guarding against unexpected cases
69
+ typeof child.type === "string" ? child.type : child.type.name
70
+ }>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`
71
+ );
72
+ });
73
+ const values =
74
+ valuesProp ??
75
+ // Only pick keys that we recognize. MDX would inject some keys by default
76
+ children.map(({ props: { value, label, attributes } }) => ({
77
+ value,
78
+ label,
79
+ attributes,
80
+ }));
81
+ const dup = duplicates(values, (a, b) => a.value === b.value);
82
+ if (dup.length > 0) {
83
+ throw new Error(
84
+ `Docusaurus error: Duplicate values "${dup
85
+ .map((a) => a.value)
86
+ .join(", ")}" found in <Tabs>. Every value needs to be unique.`
87
+ );
88
+ }
89
+ // When defaultValueProp is null, don't show a default tab
90
+ const defaultValue =
91
+ defaultValueProp === null
92
+ ? defaultValueProp
93
+ : defaultValueProp ??
94
+ children.find((child) => child.props.default)?.props.value ??
95
+ children[0]!.props.value;
96
+ if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
97
+ throw new Error(
98
+ `Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
99
+ .map((a) => a.value)
100
+ .join(
101
+ ", "
102
+ )}. If you intend to show no default tab, use defaultValue={null} instead.`
103
+ );
104
+ }
105
+
106
+ const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
107
+ const [selectedValue, setSelectedValue] = useState(defaultValue);
108
+ const tabRefs: (HTMLLIElement | null)[] = [];
109
+ const { blockElementScrollPositionUntilNextRender } =
110
+ useScrollPositionBlocker();
111
+
112
+ if (groupId != null) {
113
+ const relevantTabGroupChoice = tabGroupChoices[groupId];
114
+ if (
115
+ relevantTabGroupChoice != null &&
116
+ relevantTabGroupChoice !== selectedValue &&
117
+ values.some((value) => value.value === relevantTabGroupChoice)
118
+ ) {
119
+ setSelectedValue(relevantTabGroupChoice);
120
+ }
121
+ }
122
+
123
+ const handleTabChange = (
124
+ event: React.FocusEvent<HTMLLIElement> | React.MouseEvent<HTMLLIElement>
125
+ ) => {
126
+ const newTab = event.currentTarget;
127
+ const newTabIndex = tabRefs.indexOf(newTab);
128
+ const newTabValue = values[newTabIndex]!.value;
129
+
130
+ if (newTabValue !== selectedValue) {
131
+ blockElementScrollPositionUntilNextRender(newTab);
132
+ setSelectedValue(newTabValue);
133
+ if (action) {
134
+ const newLanguage = languageSet.filter(
135
+ (lang) => lang.language === newTabValue
136
+ );
137
+ action(newLanguage[0]);
138
+ }
139
+
140
+ if (groupId != null) {
141
+ setTabGroupChoices(groupId, String(newTabValue));
142
+ }
143
+ }
144
+ };
145
+
146
+ const handleKeydown = (event: React.KeyboardEvent<HTMLLIElement>) => {
147
+ let focusElement: HTMLLIElement | null = null;
148
+
149
+ switch (event.key) {
150
+ case "ArrowRight": {
151
+ const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
152
+ focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
153
+ break;
154
+ }
155
+ case "ArrowLeft": {
156
+ const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
157
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1]!;
158
+ break;
159
+ }
160
+ default:
161
+ break;
162
+ }
163
+
164
+ focusElement?.focus();
165
+ };
166
+
167
+ return (
168
+ <div className={clsx("tabs-container", styles.tabList)}>
169
+ <ul
170
+ role="tablist"
171
+ aria-orientation="horizontal"
172
+ className={clsx(
173
+ "tabs",
174
+ {
175
+ "tabs--block": block,
176
+ },
177
+ styles.code__tabs,
178
+ className
179
+ )}
180
+ >
181
+ {values.map(({ value, label, attributes }) => (
182
+ <li
183
+ role="tab"
184
+ tabIndex={selectedValue === value ? 0 : -1}
185
+ aria-selected={selectedValue === value}
186
+ key={value}
187
+ ref={(tabControl) => tabRefs.push(tabControl)}
188
+ onKeyDown={handleKeydown}
189
+ onFocus={handleTabChange}
190
+ onClick={handleTabChange}
191
+ {...attributes}
192
+ className={clsx(
193
+ "tabs__item",
194
+ styles.tabItem,
195
+ attributes?.className as string,
196
+ {
197
+ "tabs__item--active": selectedValue === value,
198
+ }
199
+ )}
200
+ >
201
+ {label ?? value}
202
+ </li>
203
+ ))}
204
+ </ul>
205
+
206
+ {lazy ? (
207
+ cloneElement(
208
+ children.filter(
209
+ (tabItem) => tabItem.props.value === selectedValue
210
+ )[0]!,
211
+ { className: "margin-top--md" }
212
+ )
213
+ ) : (
214
+ <div className="margin-top--md">
215
+ {children.map((tabItem, i) =>
216
+ cloneElement(tabItem, {
217
+ key: i,
218
+ hidden: tabItem.props.value !== selectedValue,
219
+ })
220
+ )}
221
+ </div>
222
+ )}
223
+ </div>
224
+ );
225
+ }
226
+
227
+ export default function CodeTabs(props: Props): JSX.Element {
228
+ const isBrowser = useIsBrowser();
229
+ return (
230
+ <TabsComponent
231
+ // Remount tabs after hydration
232
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
233
+ key={String(isBrowser)}
234
+ {...props}
235
+ />
236
+ );
237
+ }
@@ -0,0 +1,11 @@
1
+ .tabList {
2
+ margin-bottom: var(--ifm-leading);
3
+ }
4
+
5
+ .tabItem {
6
+ margin-top: 0 !important;
7
+ }
8
+
9
+ .code__tabs {
10
+ justify-content: space-around;
11
+ }