docusaurus-theme-openapi-docs 1.0.3 → 1.0.6

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 (46) 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/ApiItem/icons/bash-original.svg +1 -0
  9. package/lib/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  10. package/lib/theme/ApiItem/icons/javascript-original.svg +1 -0
  11. package/lib/theme/ApiItem/icons/linux-original.svg +1 -0
  12. package/lib/theme/ApiItem/icons/python-original.svg +1 -0
  13. package/lib/theme/ApiItem/styles.module.css +89 -0
  14. package/lib-next/theme/ApiDemoPanel/Body/index.js +11 -15
  15. package/lib-next/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  16. package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +214 -0
  17. package/lib-next/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  18. package/lib-next/theme/ApiDemoPanel/Curl/index.js +46 -135
  19. package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +49 -0
  20. package/lib-next/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  21. package/lib-next/theme/ApiItem/icons/bash-original.svg +1 -0
  22. package/lib-next/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  23. package/lib-next/theme/ApiItem/icons/javascript-original.svg +1 -0
  24. package/lib-next/theme/ApiItem/icons/linux-original.svg +1 -0
  25. package/lib-next/theme/ApiItem/icons/python-original.svg +1 -0
  26. package/lib-next/theme/ApiItem/styles.module.css +89 -0
  27. package/package.json +4 -6
  28. package/src/theme/ApiDemoPanel/Body/index.tsx +9 -13
  29. package/src/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  30. package/src/theme/ApiDemoPanel/CodeTabs/index.tsx +237 -0
  31. package/src/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  32. package/src/theme/ApiDemoPanel/Curl/index.tsx +45 -124
  33. package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +59 -0
  34. package/src/theme/ApiDemoPanel/LiveEditor/styles.module.css +34 -0
  35. package/src/theme/ApiItem/icons/bash-original.svg +1 -0
  36. package/src/theme/ApiItem/icons/go-original-wordmark.svg +1 -0
  37. package/src/theme/ApiItem/icons/javascript-original.svg +1 -0
  38. package/src/theme/ApiItem/icons/linux-original.svg +1 -0
  39. package/src/theme/ApiItem/icons/python-original.svg +1 -0
  40. package/src/theme/ApiItem/styles.module.css +89 -0
  41. package/lib/theme/ApiDemoPanel/VSCode/index.js +0 -252
  42. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  43. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +0 -265
  44. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  45. package/src/theme/ApiDemoPanel/VSCode/index.tsx +0 -205
  46. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
@@ -1,205 +0,0 @@
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, { useState } from "react";
9
-
10
- import { useColorMode } from "@docusaurus/theme-common";
11
- import Editor, { Monaco } from "@monaco-editor/react";
12
-
13
- import styles from "./styles.module.css";
14
-
15
- interface Props {
16
- value?: string;
17
- language?: string;
18
- onChange(value: string): any;
19
- }
20
-
21
- function VSCode({ value, language, onChange }: Props) {
22
- const [focused, setFocused] = useState(false);
23
- const isDarkTheme = useColorMode().colorMode === "dark" ?? false;
24
-
25
- function handleEditorWillMount(monaco: Monaco) {
26
- const styles = getComputedStyle(document.documentElement);
27
-
28
- function getColor(property: string) {
29
- // Weird chrome bug, returns " #ffffff " instead of "#ffffff", see: https://github.com/cloud-annotations/docusaurus-openapi/issues/144
30
- const color = styles.getPropertyValue(property).trim();
31
- const isColorRgb = color.includes("rgb");
32
- const isColorHexShortened = color.length === 4;
33
-
34
- // Convert "rgb(r, g, b)" to color hex code
35
- const getColorHex = (color: string) => {
36
- const rgbValues = color.substring(4).split(")")[0].split(",");
37
- const [r, g, b] = rgbValues;
38
-
39
- const colorToHex = (rgb: string) => {
40
- const hexadecimal = parseInt(rgb).toString(16);
41
- return hexadecimal.length === 1 ? "0" + hexadecimal : hexadecimal;
42
- };
43
-
44
- return "#" + colorToHex(r) + colorToHex(g) + colorToHex(b);
45
- };
46
-
47
- // Extend shortened hex codes ie. "#aaa" => "#aaaaaa" or "#xyz" => "#xxyyzz"
48
- const getFullColorHex = (color: string) => {
49
- let fullColorHex = "#";
50
- const hexValues = color.slice(1);
51
-
52
- for (let i = 0; i < hexValues.length; i++) {
53
- for (let j = 0; j < 2; j++) {
54
- fullColorHex += hexValues[i];
55
- }
56
- }
57
-
58
- return fullColorHex.toLowerCase();
59
- };
60
-
61
- if (isColorRgb) {
62
- return getColorHex(color);
63
- } else if (isColorHexShortened) {
64
- return getFullColorHex(color);
65
- } else {
66
- return color;
67
- }
68
- }
69
-
70
- const LIGHT_BACKGROUND = getColor(
71
- "--openapi-monaco-background-color-light"
72
- );
73
- const LIGHT_BRIGHT = getColor("--openapi-code-bright-light");
74
- const LIGHT_DIM = getColor("--openapi-code-dim-light");
75
- const LIGHT_BLUE = getColor("--openapi-code-blue-light");
76
- const LIGHT_GREEN = getColor("--openapi-code-green-light");
77
- const LIGHT_SELECT = getColor("--openapi-code-select-light");
78
-
79
- const DARK_BACKGROUND = getColor("--openapi-monaco-background-color-dark");
80
- const DARK_BRIGHT = getColor("--openapi-code-bright-dark");
81
- const DARK_DIM = getColor("--openapi-code-dim-dark");
82
- const DARK_BLUE = getColor("--openapi-code-blue-dark");
83
- const DARK_GREEN = getColor("--openapi-code-green-dark");
84
- const DARK_SELECT = getColor("--openapi-code-select-dark");
85
-
86
- monaco.editor.defineTheme("OpenApiDark", {
87
- base: "vs-dark",
88
- inherit: true,
89
- rules: [
90
- { token: "", foreground: DARK_BRIGHT },
91
- { token: "string.key.json", foreground: DARK_BRIGHT },
92
- { token: "string.value.json", foreground: DARK_GREEN },
93
- { token: "number", foreground: DARK_BLUE },
94
- { token: "keyword.json", foreground: DARK_BLUE },
95
- { token: "delimiter", foreground: DARK_DIM },
96
- { token: "tag.xml", foreground: DARK_DIM },
97
- { token: "metatag.xml", foreground: DARK_DIM },
98
- { token: "attribute.name.xml", foreground: DARK_BRIGHT },
99
- { token: "attribute.value.xml", foreground: DARK_GREEN },
100
- { token: "metatag.xml", foreground: DARK_BLUE },
101
- { token: "tag.xml", foreground: DARK_BLUE },
102
- ],
103
- colors: {
104
- "editor.background": DARK_BACKGROUND,
105
- "editor.lineHighlightBackground": DARK_BACKGROUND,
106
- "editorBracketMatch.background": DARK_BACKGROUND,
107
- "editorBracketMatch.border": DARK_BACKGROUND,
108
- "editor.selectionBackground": DARK_SELECT,
109
- },
110
- });
111
- monaco.editor.defineTheme("OpenApiLight", {
112
- base: "vs",
113
- inherit: true,
114
- rules: [
115
- { token: "", foreground: LIGHT_BRIGHT },
116
- { token: "string.key.json", foreground: LIGHT_BRIGHT },
117
- { token: "string.value.json", foreground: LIGHT_GREEN },
118
- { token: "number", foreground: LIGHT_BLUE },
119
- { token: "keyword.json", foreground: LIGHT_BLUE },
120
- { token: "delimiter", foreground: LIGHT_DIM },
121
- { token: "tag.xml", foreground: LIGHT_DIM },
122
- { token: "metatag.xml", foreground: LIGHT_DIM },
123
- { token: "attribute.name.xml", foreground: LIGHT_BRIGHT },
124
- { token: "attribute.value.xml", foreground: LIGHT_GREEN },
125
- { token: "metatag.xml", foreground: LIGHT_BLUE },
126
- { token: "tag.xml", foreground: LIGHT_BLUE },
127
- ],
128
- colors: {
129
- "editor.background": LIGHT_BACKGROUND,
130
- "editor.lineHighlightBackground": LIGHT_BACKGROUND,
131
- "editorBracketMatch.background": LIGHT_BACKGROUND,
132
- "editorBracketMatch.border": LIGHT_BACKGROUND,
133
- "editor.selectionBackground": LIGHT_SELECT,
134
- },
135
- });
136
- }
137
-
138
- return (
139
- <div className={focused ? styles.monacoFocus : styles.monaco}>
140
- <Editor
141
- value={value}
142
- language={language}
143
- theme={isDarkTheme ? "OpenApiDark" : "OpenApiLight"}
144
- beforeMount={handleEditorWillMount}
145
- options={{
146
- lineNumbers: "off",
147
- scrollBeyondLastLine: false,
148
- scrollBeyondLastColumn: 3,
149
- readOnly: false,
150
- minimap: { enabled: false },
151
- fontFamily:
152
- "SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace",
153
- fontSize: 14.4,
154
- overviewRulerLanes: 0,
155
- folding: false,
156
- lineDecorationsWidth: 0,
157
- contextmenu: false,
158
- scrollbar: {
159
- horizontal: "hidden",
160
- },
161
- }}
162
- onMount={(editor) => {
163
- editor.onDidFocusEditorText(() => {
164
- setFocused(true);
165
- });
166
- editor.onDidBlurEditorText(() => {
167
- setFocused(false);
168
- });
169
- editor.onDidChangeModelDecorations(() => {
170
- updateEditorHeight(); // typing
171
- requestAnimationFrame(updateEditorHeight); // folding
172
- });
173
-
174
- let prevHeight = 0;
175
-
176
- const updateEditorHeight = () => {
177
- onChange(editor.getValue());
178
- const editorElement = editor.getDomNode();
179
-
180
- if (!editorElement) {
181
- return;
182
- }
183
-
184
- const lineHeight = 22;
185
- const lineCount = editor.getModel()?.getLineCount() || 1;
186
- const height =
187
- editor.getTopForLineNumber(lineCount + 1) + lineHeight;
188
-
189
- const clippedHeight = Math.min(height, 500);
190
-
191
- if (prevHeight !== clippedHeight) {
192
- prevHeight = clippedHeight;
193
- editorElement.style.height = `${clippedHeight}px`;
194
- editor.layout();
195
- }
196
- };
197
-
198
- updateEditorHeight();
199
- }}
200
- />
201
- </div>
202
- );
203
- }
204
-
205
- export default VSCode;
@@ -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
- }