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