docusaurus-theme-openapi-docs 1.0.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/LICENSE +21 -0
- package/babel.config.js +35 -0
- package/lib/index.js +48 -0
- package/lib/markdown/createDescription.js +20 -0
- package/lib/markdown/schema.js +121 -0
- package/lib/markdown/utils.js +45 -0
- package/lib/theme/ApiDemoPanel/Accept/index.js +41 -0
- package/lib/theme/ApiDemoPanel/Accept/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/auth-types.js +32 -0
- package/lib/theme/ApiDemoPanel/Authorization/index.js +174 -0
- package/lib/theme/ApiDemoPanel/Authorization/slice.js +137 -0
- package/lib/theme/ApiDemoPanel/Body/index.js +185 -0
- package/lib/theme/ApiDemoPanel/Body/slice.js +105 -0
- package/lib/theme/ApiDemoPanel/ContentType/index.js +41 -0
- package/lib/theme/ApiDemoPanel/ContentType/slice.js +32 -0
- package/lib/theme/ApiDemoPanel/Curl/index.js +236 -0
- package/lib/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib/theme/ApiDemoPanel/Execute/index.js +85 -0
- package/lib/theme/ApiDemoPanel/Execute/makeRequest.js +202 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/index.js +32 -0
- package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/index.js +97 -0
- package/lib/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib/theme/ApiDemoPanel/FormItem/index.js +35 -0
- package/lib/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/index.js +52 -0
- package/lib/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib/theme/ApiDemoPanel/FormSelect/index.js +39 -0
- package/lib/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/index.js +30 -0
- package/lib/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib/theme/ApiDemoPanel/MethodEndpoint/index.js +60 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/index.js +248 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/slice.js +35 -0
- package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib/theme/ApiDemoPanel/Response/index.js +75 -0
- package/lib/theme/ApiDemoPanel/Response/slice.js +37 -0
- package/lib/theme/ApiDemoPanel/SecuritySchemes/index.js +51 -0
- package/lib/theme/ApiDemoPanel/Server/index.js +109 -0
- package/lib/theme/ApiDemoPanel/Server/slice.js +41 -0
- package/lib/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib/theme/ApiDemoPanel/VSCode/index.js +252 -0
- package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib/theme/ApiDemoPanel/buildPostmanRequest.js +329 -0
- package/lib/theme/ApiDemoPanel/hooks.js +20 -0
- package/lib/theme/ApiDemoPanel/index.js +134 -0
- package/lib/theme/ApiDemoPanel/persistanceMiddleware.js +44 -0
- package/lib/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib/theme/ApiDemoPanel/storage-utils.js +47 -0
- package/lib/theme/ApiDemoPanel/store.js +48 -0
- package/lib/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib/theme/ApiItem/index.js +160 -0
- package/lib/theme/ApiItem/styles.module.css +109 -0
- package/lib/theme/ParamsItem/index.js +68 -0
- package/lib/theme/ParamsItem/styles.module.css +24 -0
- package/lib/theme/SchemaItem/index.js +58 -0
- package/lib/theme/SchemaItem/styles.module.css +24 -0
- package/lib/theme/Tabs/index.js +258 -0
- package/lib/theme/Tabs/styles.module.css +118 -0
- package/lib/theme-classic.d.ts +8 -0
- package/lib/theme-openapi.d.ts +48 -0
- package/lib/theme-translations.d.ts +9 -0
- package/lib/types.js +1 -0
- package/lib-next/index.js +38 -0
- package/lib-next/markdown/createDescription.js +13 -0
- package/lib-next/markdown/schema.js +115 -0
- package/lib-next/markdown/utils.js +31 -0
- package/lib-next/theme/ApiDemoPanel/Accept/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/Accept/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/auth-types.js +22 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/index.js +203 -0
- package/lib-next/theme/ApiDemoPanel/Authorization/slice.js +101 -0
- package/lib-next/theme/ApiDemoPanel/Body/index.js +210 -0
- package/lib-next/theme/ApiDemoPanel/Body/slice.js +89 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/index.js +33 -0
- package/lib-next/theme/ApiDemoPanel/ContentType/slice.js +19 -0
- package/lib-next/theme/ApiDemoPanel/Curl/index.js +264 -0
- package/lib-next/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/lib-next/theme/ApiDemoPanel/Execute/index.js +74 -0
- package/lib-next/theme/ApiDemoPanel/Execute/makeRequest.js +183 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +19 -0
- package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/index.js +113 -0
- package/lib-next/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/index.js +29 -0
- package/lib-next/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/index.js +49 -0
- package/lib-next/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/index.js +28 -0
- package/lib-next/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/index.js +23 -0
- package/lib-next/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/lib-next/theme/ApiDemoPanel/MethodEndpoint/index.js +53 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/index.js +284 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/lib-next/theme/ApiDemoPanel/Response/index.js +65 -0
- package/lib-next/theme/ApiDemoPanel/Response/slice.js +22 -0
- package/lib-next/theme/ApiDemoPanel/SecuritySchemes/index.js +48 -0
- package/lib-next/theme/ApiDemoPanel/Server/index.js +114 -0
- package/lib-next/theme/ApiDemoPanel/Server/slice.js +25 -0
- package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/index.js +265 -0
- package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/lib-next/theme/ApiDemoPanel/buildPostmanRequest.js +310 -0
- package/lib-next/theme/ApiDemoPanel/hooks.js +9 -0
- package/lib-next/theme/ApiDemoPanel/index.js +110 -0
- package/lib-next/theme/ApiDemoPanel/persistanceMiddleware.js +38 -0
- package/lib-next/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/lib-next/theme/ApiDemoPanel/storage-utils.js +35 -0
- package/lib-next/theme/ApiDemoPanel/store.js +30 -0
- package/lib-next/theme/ApiDemoPanel/styles.module.css +44 -0
- package/lib-next/theme/ApiItem/index.js +171 -0
- package/lib-next/theme/ApiItem/styles.module.css +109 -0
- package/lib-next/theme/ParamsItem/index.js +68 -0
- package/lib-next/theme/ParamsItem/styles.module.css +24 -0
- package/lib-next/theme/SchemaItem/index.js +58 -0
- package/lib-next/theme/SchemaItem/styles.module.css +24 -0
- package/lib-next/theme/Tabs/index.js +258 -0
- package/lib-next/theme/Tabs/styles.module.css +118 -0
- package/lib-next/theme-classic.d.ts +8 -0
- package/lib-next/theme-openapi.d.ts +48 -0
- package/lib-next/theme-translations.d.ts +9 -0
- package/lib-next/types.js +1 -0
- package/package.json +68 -0
- package/src/index.ts +42 -0
- package/src/markdown/createDescription.ts +13 -0
- package/src/markdown/schema.ts +115 -0
- package/src/markdown/utils.ts +39 -0
- package/src/theme/ApiDemoPanel/Accept/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/Accept/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Authorization/auth-types.ts +26 -0
- package/src/theme/ApiDemoPanel/Authorization/index.tsx +211 -0
- package/src/theme/ApiDemoPanel/Authorization/slice.ts +145 -0
- package/src/theme/ApiDemoPanel/Body/index.tsx +218 -0
- package/src/theme/ApiDemoPanel/Body/slice.ts +133 -0
- package/src/theme/ApiDemoPanel/ContentType/index.tsx +35 -0
- package/src/theme/ApiDemoPanel/ContentType/slice.ts +29 -0
- package/src/theme/ApiDemoPanel/Curl/index.tsx +280 -0
- package/src/theme/ApiDemoPanel/Curl/styles.module.css +84 -0
- package/src/theme/ApiDemoPanel/Execute/index.tsx +88 -0
- package/src/theme/ApiDemoPanel/Execute/makeRequest.ts +184 -0
- package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +27 -0
- package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +26 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/index.tsx +116 -0
- package/src/theme/ApiDemoPanel/FormFileUpload/styles.module.css +75 -0
- package/src/theme/ApiDemoPanel/FormItem/index.tsx +28 -0
- package/src/theme/ApiDemoPanel/FormItem/styles.module.css +7 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/index.tsx +54 -0
- package/src/theme/ApiDemoPanel/FormMultiSelect/styles.module.css +38 -0
- package/src/theme/ApiDemoPanel/FormSelect/index.tsx +36 -0
- package/src/theme/ApiDemoPanel/FormSelect/styles.module.css +51 -0
- package/src/theme/ApiDemoPanel/FormTextInput/index.tsx +32 -0
- package/src/theme/ApiDemoPanel/FormTextInput/styles.module.css +21 -0
- package/src/theme/ApiDemoPanel/MethodEndpoint/index.tsx +55 -0
- package/src/theme/ApiDemoPanel/ParamOptions/index.tsx +316 -0
- package/src/theme/ApiDemoPanel/ParamOptions/slice.ts +37 -0
- package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +180 -0
- package/src/theme/ApiDemoPanel/Response/index.tsx +66 -0
- package/src/theme/ApiDemoPanel/Response/slice.ts +31 -0
- package/src/theme/ApiDemoPanel/SecuritySchemes/index.tsx +49 -0
- package/src/theme/ApiDemoPanel/Server/index.tsx +103 -0
- package/src/theme/ApiDemoPanel/Server/slice.ts +40 -0
- package/src/theme/ApiDemoPanel/Server/styles.module.css +61 -0
- package/src/theme/ApiDemoPanel/VSCode/index.tsx +205 -0
- package/src/theme/ApiDemoPanel/VSCode/styles.module.css +19 -0
- package/src/theme/ApiDemoPanel/buildPostmanRequest.ts +307 -0
- package/src/theme/ApiDemoPanel/hooks.ts +13 -0
- package/src/theme/ApiDemoPanel/index.tsx +118 -0
- package/src/theme/ApiDemoPanel/persistanceMiddleware.ts +46 -0
- package/src/theme/ApiDemoPanel/postman-collection.d.ts +10 -0
- package/src/theme/ApiDemoPanel/storage-utils.ts +39 -0
- package/src/theme/ApiDemoPanel/store.ts +41 -0
- package/src/theme/ApiDemoPanel/styles.module.css +44 -0
- package/src/theme/ApiItem/index.tsx +171 -0
- package/src/theme/ApiItem/styles.module.css +109 -0
- package/src/theme/ParamsItem/index.js +68 -0
- package/src/theme/ParamsItem/styles.module.css +24 -0
- package/src/theme/SchemaItem/index.js +58 -0
- package/src/theme/SchemaItem/styles.module.css +24 -0
- package/src/theme/Tabs/index.js +258 -0
- package/src/theme/Tabs/styles.module.css +118 -0
- package/src/theme-classic.d.ts +8 -0
- package/src/theme-openapi.d.ts +48 -0
- package/src/theme-translations.d.ts +9 -0
- package/src/types.ts +70 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,114 @@
|
|
|
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 FloatingButton from "../FloatingButton";
|
|
9
|
+
import { useTypedDispatch, useTypedSelector } from "../hooks";
|
|
10
|
+
import FormItem from "./../FormItem";
|
|
11
|
+
import FormSelect from "./../FormSelect";
|
|
12
|
+
import FormTextInput from "./../FormTextInput";
|
|
13
|
+
import { setServer, setServerVariable } from "./slice";
|
|
14
|
+
import styles from "./styles.module.css";
|
|
15
|
+
|
|
16
|
+
function Server() {
|
|
17
|
+
const [isEditing, setIsEditing] = useState(false);
|
|
18
|
+
const value = useTypedSelector((state) => state.server.value);
|
|
19
|
+
const options = useTypedSelector((state) => state.server.options);
|
|
20
|
+
const dispatch = useTypedDispatch();
|
|
21
|
+
|
|
22
|
+
if (options.length <= 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (options.length <= 1 && value?.variables === undefined) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isEditing) {
|
|
31
|
+
let url = "";
|
|
32
|
+
|
|
33
|
+
if (value) {
|
|
34
|
+
url = value.url.replace(/\/$/, "");
|
|
35
|
+
|
|
36
|
+
if (value.variables) {
|
|
37
|
+
Object.keys(value.variables).forEach((variable) => {
|
|
38
|
+
url = url.replace(
|
|
39
|
+
`{${variable}}`,
|
|
40
|
+
value.variables?.[variable].default ?? ""
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<FloatingButton onClick={() => setIsEditing(true)} label="Edit">
|
|
48
|
+
<pre
|
|
49
|
+
style={{
|
|
50
|
+
background: "var(--openapi-card-background-color)",
|
|
51
|
+
paddingRight: "60px",
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<code>{url}</code>
|
|
55
|
+
</pre>
|
|
56
|
+
</FloatingButton>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<div className={styles.optionsPanel}>
|
|
62
|
+
<button
|
|
63
|
+
className={styles.showMoreButton}
|
|
64
|
+
onClick={() => setIsEditing(false)}
|
|
65
|
+
>
|
|
66
|
+
Hide
|
|
67
|
+
</button>
|
|
68
|
+
<FormItem label="Endpoint">
|
|
69
|
+
<FormSelect
|
|
70
|
+
options={options.map((s) => s.url)}
|
|
71
|
+
onChange={(e) => dispatch(setServer(e.target.value))}
|
|
72
|
+
/>
|
|
73
|
+
</FormItem>
|
|
74
|
+
{value?.variables &&
|
|
75
|
+
Object.keys(value.variables).map((key) => {
|
|
76
|
+
if (value.variables?.[key].enum !== undefined) {
|
|
77
|
+
return (
|
|
78
|
+
<FormItem label={key}>
|
|
79
|
+
<FormSelect
|
|
80
|
+
options={value.variables[key].enum}
|
|
81
|
+
onChange={(e) => {
|
|
82
|
+
dispatch(
|
|
83
|
+
setServerVariable({
|
|
84
|
+
key,
|
|
85
|
+
value: e.target.value,
|
|
86
|
+
})
|
|
87
|
+
);
|
|
88
|
+
}}
|
|
89
|
+
/>
|
|
90
|
+
</FormItem>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<FormItem label={key}>
|
|
96
|
+
<FormTextInput
|
|
97
|
+
placeholder={value.variables?.[key].default}
|
|
98
|
+
onChange={(e) => {
|
|
99
|
+
dispatch(
|
|
100
|
+
setServerVariable({
|
|
101
|
+
key,
|
|
102
|
+
value: e.target.value,
|
|
103
|
+
})
|
|
104
|
+
);
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
</FormItem>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</div>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default Server;
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { createSlice } from "@reduxjs/toolkit";
|
|
8
|
+
const initialState = {};
|
|
9
|
+
export const slice = createSlice({
|
|
10
|
+
name: "server",
|
|
11
|
+
initialState,
|
|
12
|
+
reducers: {
|
|
13
|
+
setServer: (state, action) => {
|
|
14
|
+
state.value = state.options.find((s) => s.url === action.payload);
|
|
15
|
+
},
|
|
16
|
+
setServerVariable: (state, action) => {
|
|
17
|
+
if (state.value?.variables) {
|
|
18
|
+
state.value.variables[action.payload.key].default =
|
|
19
|
+
action.payload.value;
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
export const { setServer, setServerVariable } = slice.actions;
|
|
25
|
+
export default slice.reducer;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
.showMoreButton {
|
|
2
|
+
-webkit-appearance: none;
|
|
3
|
+
-moz-appearance: none;
|
|
4
|
+
appearance: none;
|
|
5
|
+
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
font-size: var(--ifm-code-font-size);
|
|
8
|
+
/* font-weight: var(--ifm-button-font-weight); */
|
|
9
|
+
/* line-height: 1.5; */
|
|
10
|
+
|
|
11
|
+
padding: 0;
|
|
12
|
+
|
|
13
|
+
user-select: none;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
|
|
16
|
+
border: 0px solid transparent;
|
|
17
|
+
|
|
18
|
+
display: block;
|
|
19
|
+
/* width: 100%; */
|
|
20
|
+
|
|
21
|
+
background-color: transparent;
|
|
22
|
+
|
|
23
|
+
color: var(--ifm-color-primary);
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
margin-top: var(--ifm-pre-padding);
|
|
26
|
+
margin-bottom: 0;
|
|
27
|
+
text-align: left;
|
|
28
|
+
display: block;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.showMoreButton:focus {
|
|
32
|
+
outline: 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.showMoreButton:hover {
|
|
36
|
+
/* text-decoration: underline; */
|
|
37
|
+
/* background-color: red; */
|
|
38
|
+
color: var(--ifm-color-primary-hover);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.showMoreButton:first-child {
|
|
42
|
+
margin-top: 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.optionsPanel:empty {
|
|
46
|
+
display: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.optionsPanel {
|
|
50
|
+
background: var(--openapi-card-background-color);
|
|
51
|
+
border-radius: var(--openapi-card-border-radius);
|
|
52
|
+
color: var(--ifm-pre-color);
|
|
53
|
+
line-height: var(--ifm-pre-line-height);
|
|
54
|
+
margin-bottom: var(--ifm-spacing-vertical);
|
|
55
|
+
margin-top: 0;
|
|
56
|
+
overflow: auto;
|
|
57
|
+
padding: var(--ifm-pre-padding);
|
|
58
|
+
|
|
59
|
+
/* hack for view calculation when monaco is hidden */
|
|
60
|
+
position: relative;
|
|
61
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
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;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|