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/src/types.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  * ========================================================================== */
7
7
 
8
+ import type { FrontMatterTag } from "@docusaurus/utils";
8
9
  import type { JSONSchema4, JSONSchema6, JSONSchema7 } from "json-schema";
9
10
 
10
11
  export interface ThemeConfig {
@@ -68,3 +69,114 @@ export interface ExternalDocumentationObject {
68
69
  description?: string;
69
70
  url: string;
70
71
  }
72
+
73
+ export type FileChange = {
74
+ author?: string;
75
+ /** Date can be any
76
+ * [parsable date string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).
77
+ */
78
+ date?: Date | string;
79
+ };
80
+
81
+ export type DocFrontMatter = {
82
+ /**
83
+ * The last part of the doc ID (will be refactored in the future to be the
84
+ * full ID instead)
85
+ * @see {@link DocMetadata.id}
86
+ */
87
+ id?: string;
88
+ /**
89
+ * Will override the default title collected from h1 heading.
90
+ * @see {@link DocMetadata.title}
91
+ */
92
+ title?: string;
93
+ /**
94
+ * Front matter tags, unnormalized.
95
+ * @see {@link DocMetadata.tags}
96
+ */
97
+ tags?: FrontMatterTag[];
98
+ /**
99
+ * If there isn't a Markdown h1 heading (which, if there is, we don't
100
+ * remove), this front matter will cause the front matter title to not be
101
+ * displayed in the doc page.
102
+ */
103
+ hide_title?: boolean;
104
+ /** Hide the TOC on the right. */
105
+ hide_table_of_contents?: boolean;
106
+ /** Used in the head meta. */
107
+ keywords?: string[];
108
+ /** Used in the head meta. Should use `assets.image` in priority. */
109
+ image?: string;
110
+ /**
111
+ * Will override the default excerpt.
112
+ * @see {@link DocMetadata.description}
113
+ */
114
+ description?: string;
115
+ /**
116
+ * Custom slug appended after /<baseUrl>/<routeBasePath>/<versionPath>
117
+ * @see {@link DocMetadata.slug}
118
+ */
119
+ slug?: string;
120
+ /** Customizes the sidebar label for this doc. Will default to its title. */
121
+ sidebar_label?: string;
122
+ /**
123
+ * Controls the position of a doc inside the generated sidebar slice when
124
+ * using autogenerated sidebar items.
125
+ *
126
+ * @see https://docusaurus.io/docs/sidebar#autogenerated-sidebar-metadata
127
+ */
128
+ sidebar_position?: number;
129
+ /**
130
+ * Gives the corresponding sidebar label a special class name when using
131
+ * autogenerated sidebars.
132
+ */
133
+ sidebar_class_name?: string;
134
+ /**
135
+ * Will be propagated to the final sidebars data structure. Useful if you
136
+ * have swizzled sidebar-related code or simply querying doc data through
137
+ * sidebars.
138
+ */
139
+ sidebar_custom_props?: { [key: string]: unknown };
140
+ /**
141
+ * Changes the sidebar association of the current doc. Use `null` to make
142
+ * the current doc not associated to any sidebar.
143
+ */
144
+ displayed_sidebar?: string | null;
145
+ /**
146
+ * Customizes the pagination label for this doc. Will default to the sidebar
147
+ * label.
148
+ */
149
+ pagination_label?: string;
150
+ /** Overrides the default URL computed for this doc. */
151
+ custom_edit_url?: string | null;
152
+ /**
153
+ * Whether number prefix parsing is disabled on this doc.
154
+ * @see https://docusaurus.io/docs/sidebar#using-number-prefixes
155
+ */
156
+ parse_number_prefixes?: boolean;
157
+ /**
158
+ * Minimum TOC heading level. Must be between 2 and 6 and lower or equal to
159
+ * the max value.
160
+ */
161
+ toc_min_heading_level?: number;
162
+ /** Maximum TOC heading level. Must be between 2 and 6. */
163
+ toc_max_heading_level?: number;
164
+ /**
165
+ * The ID of the documentation you want the "Next" pagination to link to.
166
+ * Use `null` to disable showing "Next" for this page.
167
+ * @see {@link DocMetadata.next}
168
+ */
169
+ pagination_next?: string | null;
170
+ /**
171
+ * The ID of the documentation you want the "Previous" pagination to link
172
+ * to. Use `null` to disable showing "Previous" for this page.
173
+ * @see {@link DocMetadata.prev}
174
+ */
175
+ pagination_prev?: string | null;
176
+ /** Should this doc be excluded from production builds? */
177
+ draft?: boolean;
178
+ /** Allows overriding the last updated author and/or date. */
179
+ last_update?: FileChange;
180
+ /** Provides OpenAPI Docs with a reference path to their respective Info Doc */
181
+ info_path?: string;
182
+ };
@@ -1,252 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _themeCommon = require("@docusaurus/theme-common");
11
-
12
- var _react2 = _interopRequireDefault(require("@monaco-editor/react"));
13
-
14
- var _stylesModule = _interopRequireDefault(require("./styles.module.css"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- /* ============================================================================
23
- * Copyright (c) Palo Alto Networks
24
- *
25
- * This source code is licensed under the MIT license found in the
26
- * LICENSE file in the root directory of this source tree.
27
- * ========================================================================== */
28
- function VSCode({
29
- value,
30
- language,
31
- onChange
32
- }) {
33
- var _ref;
34
-
35
- const [focused, setFocused] = (0, _react.useState)(false);
36
- const isDarkTheme = (_ref = (0, _themeCommon.useColorMode)().colorMode === "dark") !== null && _ref !== void 0 ? _ref : false;
37
-
38
- function handleEditorWillMount(monaco) {
39
- const styles = getComputedStyle(document.documentElement);
40
-
41
- function getColor(property) {
42
- // Weird chrome bug, returns " #ffffff " instead of "#ffffff", see: https://github.com/cloud-annotations/docusaurus-openapi/issues/144
43
- const color = styles.getPropertyValue(property).trim();
44
- const isColorRgb = color.includes("rgb");
45
- const isColorHexShortened = color.length === 4; // Convert "rgb(r, g, b)" to color hex code
46
-
47
- const getColorHex = color => {
48
- const rgbValues = color.substring(4).split(")")[0].split(",");
49
- const [r, g, b] = rgbValues;
50
-
51
- const colorToHex = rgb => {
52
- const hexadecimal = parseInt(rgb).toString(16);
53
- return hexadecimal.length === 1 ? "0" + hexadecimal : hexadecimal;
54
- };
55
-
56
- return "#" + colorToHex(r) + colorToHex(g) + colorToHex(b);
57
- }; // Extend shortened hex codes ie. "#aaa" => "#aaaaaa" or "#xyz" => "#xxyyzz"
58
-
59
-
60
- const getFullColorHex = color => {
61
- let fullColorHex = "#";
62
- const hexValues = color.slice(1);
63
-
64
- for (let i = 0; i < hexValues.length; i++) {
65
- for (let j = 0; j < 2; j++) {
66
- fullColorHex += hexValues[i];
67
- }
68
- }
69
-
70
- return fullColorHex.toLowerCase();
71
- };
72
-
73
- if (isColorRgb) {
74
- return getColorHex(color);
75
- } else if (isColorHexShortened) {
76
- return getFullColorHex(color);
77
- } else {
78
- return color;
79
- }
80
- }
81
-
82
- const LIGHT_BACKGROUND = getColor("--openapi-monaco-background-color-light");
83
- const LIGHT_BRIGHT = getColor("--openapi-code-bright-light");
84
- const LIGHT_DIM = getColor("--openapi-code-dim-light");
85
- const LIGHT_BLUE = getColor("--openapi-code-blue-light");
86
- const LIGHT_GREEN = getColor("--openapi-code-green-light");
87
- const LIGHT_SELECT = getColor("--openapi-code-select-light");
88
- const DARK_BACKGROUND = getColor("--openapi-monaco-background-color-dark");
89
- const DARK_BRIGHT = getColor("--openapi-code-bright-dark");
90
- const DARK_DIM = getColor("--openapi-code-dim-dark");
91
- const DARK_BLUE = getColor("--openapi-code-blue-dark");
92
- const DARK_GREEN = getColor("--openapi-code-green-dark");
93
- const DARK_SELECT = getColor("--openapi-code-select-dark");
94
- monaco.editor.defineTheme("OpenApiDark", {
95
- base: "vs-dark",
96
- inherit: true,
97
- rules: [{
98
- token: "",
99
- foreground: DARK_BRIGHT
100
- }, {
101
- token: "string.key.json",
102
- foreground: DARK_BRIGHT
103
- }, {
104
- token: "string.value.json",
105
- foreground: DARK_GREEN
106
- }, {
107
- token: "number",
108
- foreground: DARK_BLUE
109
- }, {
110
- token: "keyword.json",
111
- foreground: DARK_BLUE
112
- }, {
113
- token: "delimiter",
114
- foreground: DARK_DIM
115
- }, {
116
- token: "tag.xml",
117
- foreground: DARK_DIM
118
- }, {
119
- token: "metatag.xml",
120
- foreground: DARK_DIM
121
- }, {
122
- token: "attribute.name.xml",
123
- foreground: DARK_BRIGHT
124
- }, {
125
- token: "attribute.value.xml",
126
- foreground: DARK_GREEN
127
- }, {
128
- token: "metatag.xml",
129
- foreground: DARK_BLUE
130
- }, {
131
- token: "tag.xml",
132
- foreground: DARK_BLUE
133
- }],
134
- colors: {
135
- "editor.background": DARK_BACKGROUND,
136
- "editor.lineHighlightBackground": DARK_BACKGROUND,
137
- "editorBracketMatch.background": DARK_BACKGROUND,
138
- "editorBracketMatch.border": DARK_BACKGROUND,
139
- "editor.selectionBackground": DARK_SELECT
140
- }
141
- });
142
- monaco.editor.defineTheme("OpenApiLight", {
143
- base: "vs",
144
- inherit: true,
145
- rules: [{
146
- token: "",
147
- foreground: LIGHT_BRIGHT
148
- }, {
149
- token: "string.key.json",
150
- foreground: LIGHT_BRIGHT
151
- }, {
152
- token: "string.value.json",
153
- foreground: LIGHT_GREEN
154
- }, {
155
- token: "number",
156
- foreground: LIGHT_BLUE
157
- }, {
158
- token: "keyword.json",
159
- foreground: LIGHT_BLUE
160
- }, {
161
- token: "delimiter",
162
- foreground: LIGHT_DIM
163
- }, {
164
- token: "tag.xml",
165
- foreground: LIGHT_DIM
166
- }, {
167
- token: "metatag.xml",
168
- foreground: LIGHT_DIM
169
- }, {
170
- token: "attribute.name.xml",
171
- foreground: LIGHT_BRIGHT
172
- }, {
173
- token: "attribute.value.xml",
174
- foreground: LIGHT_GREEN
175
- }, {
176
- token: "metatag.xml",
177
- foreground: LIGHT_BLUE
178
- }, {
179
- token: "tag.xml",
180
- foreground: LIGHT_BLUE
181
- }],
182
- colors: {
183
- "editor.background": LIGHT_BACKGROUND,
184
- "editor.lineHighlightBackground": LIGHT_BACKGROUND,
185
- "editorBracketMatch.background": LIGHT_BACKGROUND,
186
- "editorBracketMatch.border": LIGHT_BACKGROUND,
187
- "editor.selectionBackground": LIGHT_SELECT
188
- }
189
- });
190
- }
191
-
192
- return <div className={focused ? _stylesModule.default.monacoFocus : _stylesModule.default.monaco}>
193
- <_react2.default value={value} language={language} theme={isDarkTheme ? "OpenApiDark" : "OpenApiLight"} beforeMount={handleEditorWillMount} options={{
194
- lineNumbers: "off",
195
- scrollBeyondLastLine: false,
196
- scrollBeyondLastColumn: 3,
197
- readOnly: false,
198
- minimap: {
199
- enabled: false
200
- },
201
- fontFamily: "SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace",
202
- fontSize: 14.4,
203
- overviewRulerLanes: 0,
204
- folding: false,
205
- lineDecorationsWidth: 0,
206
- contextmenu: false,
207
- scrollbar: {
208
- horizontal: "hidden"
209
- }
210
- }} onMount={editor => {
211
- editor.onDidFocusEditorText(() => {
212
- setFocused(true);
213
- });
214
- editor.onDidBlurEditorText(() => {
215
- setFocused(false);
216
- });
217
- editor.onDidChangeModelDecorations(() => {
218
- updateEditorHeight(); // typing
219
-
220
- requestAnimationFrame(updateEditorHeight); // folding
221
- });
222
- let prevHeight = 0;
223
-
224
- const updateEditorHeight = () => {
225
- var _editor$getModel;
226
-
227
- onChange(editor.getValue());
228
- const editorElement = editor.getDomNode();
229
-
230
- if (!editorElement) {
231
- return;
232
- }
233
-
234
- const lineHeight = 22;
235
- const lineCount = ((_editor$getModel = editor.getModel()) === null || _editor$getModel === void 0 ? void 0 : _editor$getModel.getLineCount()) || 1;
236
- const height = editor.getTopForLineNumber(lineCount + 1) + lineHeight;
237
- const clippedHeight = Math.min(height, 500);
238
-
239
- if (prevHeight !== clippedHeight) {
240
- prevHeight = clippedHeight;
241
- editorElement.style.height = `${clippedHeight}px`;
242
- editor.layout();
243
- }
244
- };
245
-
246
- updateEditorHeight();
247
- }} />
248
- </div>;
249
- }
250
-
251
- var _default = VSCode;
252
- exports.default = _default;
@@ -1,19 +0,0 @@
1
- .monacoBase {
2
- margin-top: calc(var(--ifm-pre-padding) / 2);
3
- border-radius: 4px;
4
- padding: var(--ifm-pre-padding);
5
- background-color: var(--openapi-monaco-background-color);
6
- }
7
-
8
- .monaco {
9
- composes: monacoBase;
10
-
11
- box-shadow: 0 0 0 1px var(--openapi-monaco-border-color);
12
- border: 2px solid transparent;
13
- }
14
-
15
- .monacoFocus {
16
- composes: monacoBase;
17
-
18
- border: 2px solid var(--openapi-input-border);
19
- }