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.
Files changed (103) 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 +193 -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/FloatingButton/index.js +4 -2
  7. package/lib/theme/ApiDemoPanel/FloatingButton/styles.module.css +3 -2
  8. package/lib/theme/ApiDemoPanel/LiveEditor/index.js +74 -0
  9. package/lib/theme/ApiDemoPanel/LiveEditor/styles.module.css +35 -0
  10. package/lib/theme/ApiDemoPanel/ParamOptions/styles.module.css +0 -4
  11. package/lib/theme/ApiDemoPanel/Server/index.js +1 -1
  12. package/lib/theme/ApiDemoPanel/Server/styles.module.css +0 -4
  13. package/lib/theme/ApiItem/Content/index.js +65 -0
  14. package/lib/theme/ApiItem/Footer/index.js +78 -0
  15. package/lib/theme/ApiItem/Footer/styles.module.css +18 -0
  16. package/lib/theme/ApiItem/Layout/icons/bash-original.svg +1 -0
  17. package/lib/theme/ApiItem/Layout/icons/go-original-wordmark.svg +1 -0
  18. package/lib/theme/ApiItem/Layout/icons/javascript-original.svg +1 -0
  19. package/lib/theme/ApiItem/Layout/icons/linux-original.svg +1 -0
  20. package/lib/theme/ApiItem/Layout/icons/python-original.svg +1 -0
  21. package/lib/theme/ApiItem/Layout/index.js +93 -0
  22. package/lib/theme/ApiItem/{styles.module.css → Layout/styles.module.css} +114 -4
  23. package/lib/theme/ApiItem/Metadata/index.js +32 -0
  24. package/lib/theme/ApiItem/Paginator/index.js +33 -0
  25. package/lib/theme/ApiItem/TOC/Desktop/index.js +31 -0
  26. package/lib/theme/ApiItem/TOC/Mobile/index.js +35 -0
  27. package/lib/theme/ApiItem/TOC/Mobile/styles.module.css +19 -0
  28. package/lib/theme/ApiItem/index.js +37 -126
  29. package/lib/theme/ApiTabs/index.js +17 -6
  30. package/lib/theme/ApiTabs/styles.module.css +0 -1
  31. package/lib/theme/SchemaTabs/index.js +258 -0
  32. package/lib/theme/SchemaTabs/styles.module.css +110 -0
  33. package/lib-next/theme/ApiDemoPanel/Body/index.js +11 -15
  34. package/lib-next/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  35. package/lib-next/theme/ApiDemoPanel/CodeTabs/index.js +215 -0
  36. package/lib-next/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  37. package/lib-next/theme/ApiDemoPanel/Curl/index.js +46 -135
  38. package/lib-next/theme/ApiDemoPanel/FloatingButton/index.js +6 -2
  39. package/lib-next/theme/ApiDemoPanel/FloatingButton/styles.module.css +3 -2
  40. package/lib-next/theme/ApiDemoPanel/LiveEditor/index.js +60 -0
  41. package/lib-next/theme/ApiDemoPanel/LiveEditor/styles.module.css +35 -0
  42. package/lib-next/theme/ApiDemoPanel/ParamOptions/styles.module.css +0 -4
  43. package/lib-next/theme/ApiDemoPanel/Server/index.js +1 -0
  44. package/lib-next/theme/ApiDemoPanel/Server/styles.module.css +0 -4
  45. package/lib-next/theme/ApiItem/Content/index.js +55 -0
  46. package/lib-next/theme/ApiItem/Footer/index.js +88 -0
  47. package/lib-next/theme/ApiItem/Footer/styles.module.css +18 -0
  48. package/lib-next/theme/ApiItem/Layout/icons/bash-original.svg +1 -0
  49. package/lib-next/theme/ApiItem/Layout/icons/go-original-wordmark.svg +1 -0
  50. package/lib-next/theme/ApiItem/Layout/icons/javascript-original.svg +1 -0
  51. package/lib-next/theme/ApiItem/Layout/icons/linux-original.svg +1 -0
  52. package/lib-next/theme/ApiItem/Layout/icons/python-original.svg +1 -0
  53. package/lib-next/theme/ApiItem/Layout/index.js +69 -0
  54. package/{src/theme/ApiItem → lib-next/theme/ApiItem/Layout}/styles.module.css +114 -4
  55. package/lib-next/theme/ApiItem/Metadata/index.js +21 -0
  56. package/lib-next/theme/ApiItem/Paginator/index.js +19 -0
  57. package/lib-next/theme/ApiItem/TOC/Desktop/index.js +22 -0
  58. package/lib-next/theme/ApiItem/TOC/Mobile/index.js +24 -0
  59. package/lib-next/theme/ApiItem/TOC/Mobile/styles.module.css +19 -0
  60. package/lib-next/theme/ApiItem/index.js +31 -133
  61. package/lib-next/theme/ApiTabs/index.js +17 -6
  62. package/lib-next/theme/ApiTabs/styles.module.css +0 -1
  63. package/lib-next/theme/SchemaTabs/index.js +258 -0
  64. package/lib-next/theme/SchemaTabs/styles.module.css +110 -0
  65. package/package.json +7 -9
  66. package/src/theme/ApiDemoPanel/Body/index.tsx +9 -13
  67. package/src/theme/ApiDemoPanel/Body/json2xml.js +43 -0
  68. package/src/theme/ApiDemoPanel/CodeTabs/index.tsx +238 -0
  69. package/src/theme/ApiDemoPanel/CodeTabs/styles.module.css +11 -0
  70. package/src/theme/ApiDemoPanel/Curl/index.tsx +45 -124
  71. package/src/theme/ApiDemoPanel/FloatingButton/index.tsx +6 -2
  72. package/src/theme/ApiDemoPanel/FloatingButton/styles.module.css +3 -2
  73. package/src/theme/ApiDemoPanel/LiveEditor/index.tsx +71 -0
  74. package/src/theme/ApiDemoPanel/LiveEditor/styles.module.css +35 -0
  75. package/src/theme/ApiDemoPanel/ParamOptions/styles.module.css +0 -4
  76. package/src/theme/ApiDemoPanel/Server/index.tsx +1 -0
  77. package/src/theme/ApiDemoPanel/Server/styles.module.css +0 -4
  78. package/src/theme/ApiItem/Content/index.tsx +57 -0
  79. package/src/theme/ApiItem/Footer/index.tsx +101 -0
  80. package/src/theme/ApiItem/Footer/styles.module.css +18 -0
  81. package/src/theme/ApiItem/Layout/icons/bash-original.svg +1 -0
  82. package/src/theme/ApiItem/Layout/icons/go-original-wordmark.svg +1 -0
  83. package/src/theme/ApiItem/Layout/icons/javascript-original.svg +1 -0
  84. package/src/theme/ApiItem/Layout/icons/linux-original.svg +1 -0
  85. package/src/theme/ApiItem/Layout/icons/python-original.svg +1 -0
  86. package/src/theme/ApiItem/Layout/index.tsx +78 -0
  87. package/{lib-next/theme/ApiItem → src/theme/ApiItem/Layout}/styles.module.css +114 -4
  88. package/src/theme/ApiItem/Metadata/index.tsx +24 -0
  89. package/src/theme/ApiItem/Paginator/index.tsx +21 -0
  90. package/src/theme/ApiItem/TOC/Desktop/index.tsx +25 -0
  91. package/src/theme/ApiItem/TOC/Mobile/index.tsx +28 -0
  92. package/src/theme/ApiItem/TOC/Mobile/styles.module.css +19 -0
  93. package/src/theme/ApiItem/index.tsx +31 -130
  94. package/src/theme/ApiTabs/index.js +17 -6
  95. package/src/theme/ApiTabs/styles.module.css +0 -1
  96. package/src/theme/SchemaTabs/index.js +258 -0
  97. package/src/theme/SchemaTabs/styles.module.css +110 -0
  98. package/lib/theme/ApiDemoPanel/VSCode/index.js +0 -252
  99. package/lib/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  100. package/lib-next/theme/ApiDemoPanel/VSCode/index.js +0 -265
  101. package/lib-next/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
  102. package/src/theme/ApiDemoPanel/VSCode/index.tsx +0 -205
  103. package/src/theme/ApiDemoPanel/VSCode/styles.module.css +0 -19
@@ -0,0 +1,258 @@
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
+ Children,
10
+ cloneElement,
11
+ isValidElement,
12
+ useEffect,
13
+ useRef,
14
+ useState,
15
+ } from "react";
16
+
17
+ import { duplicates } from "@docusaurus/theme-common";
18
+ import useIsBrowser from "@docusaurus/useIsBrowser";
19
+ import clsx from "clsx";
20
+
21
+ import styles from "./styles.module.css"; // A very rough duck type, but good enough to guard against mistakes while
22
+
23
+ const {
24
+ useScrollPositionBlocker,
25
+ useTabGroupChoice,
26
+ } = require("@docusaurus/theme-common/internal");
27
+
28
+ // allowing customization
29
+
30
+ function isTabItem(comp) {
31
+ return typeof comp.props.value !== "undefined";
32
+ }
33
+
34
+ function SchemaTabsComponent(props) {
35
+ const {
36
+ lazy,
37
+ block,
38
+ defaultValue: defaultValueProp,
39
+ values: valuesProp,
40
+ groupId,
41
+ className,
42
+ } = props;
43
+ const children = Children.map(props.children, (child) => {
44
+ if (isValidElement(child) && isTabItem(child)) {
45
+ return child;
46
+ } // child.type.name will give non-sensical values in prod because of
47
+ // minification, but we assume it won't throw in prod.
48
+
49
+ throw new Error(
50
+ `Docusaurus error: Bad <Tabs> child <${
51
+ // @ts-expect-error: guarding against unexpected cases
52
+ typeof child.type === "string" ? child.type : child.type.name
53
+ }>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`
54
+ );
55
+ });
56
+ const values =
57
+ valuesProp ?? // We only pick keys that we recognize. MDX would inject some keys by default
58
+ children.map(({ props: { value, label, attributes } }) => ({
59
+ value,
60
+ label,
61
+ attributes,
62
+ }));
63
+ const dup = duplicates(values, (a, b) => a.value === b.value);
64
+
65
+ if (dup.length > 0) {
66
+ throw new Error(
67
+ `Docusaurus error: Duplicate values "${dup
68
+ .map((a) => a.value)
69
+ .join(", ")}" found in <Tabs>. Every value needs to be unique.`
70
+ );
71
+ } // When defaultValueProp is null, don't show a default tab
72
+
73
+ const defaultValue =
74
+ defaultValueProp === null
75
+ ? defaultValueProp
76
+ : defaultValueProp ??
77
+ children.find((child) => child.props.default)?.props.value ??
78
+ children[0]?.props.value;
79
+
80
+ if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
81
+ throw new Error(
82
+ `Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
83
+ .map((a) => a.value)
84
+ .join(
85
+ ", "
86
+ )}. If you intend to show no default tab, use defaultValue={null} instead.`
87
+ );
88
+ }
89
+
90
+ const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoice();
91
+ const [selectedValue, setSelectedValue] = useState(defaultValue);
92
+ const tabRefs = [];
93
+ const { blockElementScrollPositionUntilNextRender } =
94
+ useScrollPositionBlocker();
95
+
96
+ if (groupId != null) {
97
+ const relevantTabGroupChoice = tabGroupChoices[groupId];
98
+
99
+ if (
100
+ relevantTabGroupChoice != null &&
101
+ relevantTabGroupChoice !== selectedValue &&
102
+ values.some((value) => value.value === relevantTabGroupChoice)
103
+ ) {
104
+ setSelectedValue(relevantTabGroupChoice);
105
+ }
106
+ }
107
+
108
+ const handleTabChange = (event) => {
109
+ const newTab = event.currentTarget;
110
+ const newTabIndex = tabRefs.indexOf(newTab);
111
+ const newTabValue = values[newTabIndex].value;
112
+
113
+ if (newTabValue !== selectedValue) {
114
+ blockElementScrollPositionUntilNextRender(newTab);
115
+ setSelectedValue(newTabValue);
116
+
117
+ if (groupId != null) {
118
+ setTabGroupChoices(groupId, newTabValue);
119
+ }
120
+ }
121
+ };
122
+
123
+ const handleKeydown = (event) => {
124
+ let focusElement = null;
125
+
126
+ switch (event.key) {
127
+ case "ArrowRight": {
128
+ const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
129
+ focusElement = tabRefs[nextTab] || tabRefs[0];
130
+ break;
131
+ }
132
+
133
+ case "ArrowLeft": {
134
+ const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
135
+ focusElement = tabRefs[prevTab] || tabRefs[tabRefs.length - 1];
136
+ break;
137
+ }
138
+
139
+ default:
140
+ break;
141
+ }
142
+
143
+ focusElement?.focus();
144
+ };
145
+
146
+ const tabItemListContainerRef = useRef(null);
147
+ const [showTabArrows, setShowTabArrows] = useState(false);
148
+
149
+ useEffect(() => {
150
+ const tabOffsetWidth = tabItemListContainerRef.current.offsetWidth;
151
+ const tabScrollWidth = tabItemListContainerRef.current.scrollWidth;
152
+
153
+ if (tabOffsetWidth < tabScrollWidth) {
154
+ setShowTabArrows(true);
155
+ }
156
+ }, []);
157
+
158
+ const handleRightClick = () => {
159
+ tabItemListContainerRef.current.scrollLeft += 90;
160
+ };
161
+
162
+ const handleLeftClick = () => {
163
+ tabItemListContainerRef.current.scrollLeft -= 90;
164
+ };
165
+
166
+ return (
167
+ <div className="tabs__container">
168
+ <div className={styles.schemaTabsTopSection}>
169
+ <div className={styles.schemaTabsContainer}>
170
+ {showTabArrows && (
171
+ <button
172
+ className={clsx(styles.tabArrow, styles.tabArrowLeft)}
173
+ onClick={handleLeftClick}
174
+ />
175
+ )}
176
+ <ul
177
+ ref={tabItemListContainerRef}
178
+ role="tablist"
179
+ aria-orientation="horizontal"
180
+ className={clsx(
181
+ styles.schemaTabsListContainer,
182
+ "tabs",
183
+ {
184
+ "tabs--block": block,
185
+ },
186
+ className
187
+ )}
188
+ >
189
+ {values.map(({ value, label, attributes }) => {
190
+ return (
191
+ <li
192
+ role="tab"
193
+ tabIndex={selectedValue === value ? 0 : -1}
194
+ aria-selected={selectedValue === value}
195
+ key={value}
196
+ ref={(tabControl) => tabRefs.push(tabControl)}
197
+ onKeyDown={handleKeydown}
198
+ onFocus={handleTabChange}
199
+ onClick={handleTabChange}
200
+ {...attributes}
201
+ className={clsx(
202
+ "tabs__item",
203
+ styles.tabItem,
204
+ attributes?.className,
205
+ {
206
+ [styles.schemaTabActive]: selectedValue === value,
207
+ }
208
+ )}
209
+ >
210
+ <span className={styles.schemaTabLabel}>
211
+ {label ?? value}
212
+ </span>
213
+ </li>
214
+ );
215
+ })}
216
+ </ul>
217
+ {showTabArrows && (
218
+ <button
219
+ className={clsx(styles.tabArrow, styles.tabArrowRight)}
220
+ onClick={handleRightClick}
221
+ />
222
+ )}
223
+ </div>
224
+ </div>
225
+ <hr />
226
+ {lazy ? (
227
+ cloneElement(
228
+ children.filter(
229
+ (tabItem) => tabItem.props.value === selectedValue
230
+ )[0],
231
+ {
232
+ className: clsx("margin-vert--md", styles.schemaTabsContainer),
233
+ }
234
+ )
235
+ ) : (
236
+ <div className={clsx("margin-vert--md", styles.schemaTabsContainer)}>
237
+ {children.map((tabItem, i) =>
238
+ cloneElement(tabItem, {
239
+ key: i,
240
+ hidden: tabItem.props.value !== selectedValue,
241
+ })
242
+ )}
243
+ </div>
244
+ )}
245
+ </div>
246
+ );
247
+ }
248
+
249
+ export default function SchemaTabs(props) {
250
+ const isBrowser = useIsBrowser();
251
+ return (
252
+ <SchemaTabsComponent // Remount tabs after hydration
253
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
254
+ key={String(isBrowser)}
255
+ {...props}
256
+ />
257
+ );
258
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
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
+ .tabItem {
9
+ display: flex;
10
+ align-items: center;
11
+ justify-content: center;
12
+ height: 1.8rem;
13
+ margin-top: 0 !important;
14
+ margin-right: 0.5rem;
15
+ border: 1px solid var(--openapi-code-dim-dark);
16
+ border-radius: var(--ifm-global-radius);
17
+ color: var(--openapi-code-dim-dark);
18
+ font-size: 12px;
19
+ }
20
+
21
+ .tabItem:hover {
22
+ color: var(--ifm-color-emphasis-500) !important;
23
+ }
24
+
25
+ .tabItem:last-child {
26
+ margin-right: 0 !important;
27
+ }
28
+
29
+ /* Open API Schema Tabs */
30
+ .schemaTabsTopSection {
31
+ margin-top: 1rem;
32
+ display: flex;
33
+ justify-content: space-between;
34
+ align-items: center;
35
+ }
36
+
37
+ .schemaTabsTopSection + hr {
38
+ display: none;
39
+ }
40
+
41
+ .schemaTabsContainer {
42
+ display: flex;
43
+ align-items: center;
44
+ max-width: 390px;
45
+ padding-left: 3px;
46
+ overflow: hidden;
47
+ }
48
+
49
+ .schemaTabsListContainer {
50
+ padding: 0 0.25rem;
51
+ overflow-y: hidden;
52
+ overflow-x: scroll;
53
+ scroll-behavior: smooth;
54
+ }
55
+
56
+ .schemaTabsListContainer::-webkit-scrollbar {
57
+ display: none;
58
+ }
59
+
60
+ .tabItem.schemaTabActive {
61
+ border: 1px solid var(--ifm-color-primary);
62
+ color: var(--ifm-color-primary);
63
+ }
64
+
65
+ .schemaTabLabel {
66
+ white-space: nowrap;
67
+ }
68
+
69
+ .schemaTabsContainer {
70
+ max-width: 600px;
71
+ }
72
+
73
+ /* Tab Arrows */
74
+ .tabArrow {
75
+ content: "";
76
+ height: 1.25rem;
77
+ width: 1.25rem;
78
+ padding: 0 0.75rem;
79
+ border: none;
80
+ min-width: 1.25rem;
81
+ background: var(--ifm-menu-link-sublist-icon) 50% / 2rem 2rem;
82
+ filter: var(--ifm-menu-link-sublist-icon-filter);
83
+ }
84
+
85
+ .tabArrow:hover {
86
+ cursor: pointer;
87
+ }
88
+
89
+ .tabArrowLeft {
90
+ transform: rotate(270deg);
91
+ }
92
+
93
+ .tabArrowRight {
94
+ transform: rotate(90deg);
95
+ }
96
+
97
+ @media screen and (max-width: 500px) {
98
+ .schemaTabsTopSection {
99
+ flex-direction: column;
100
+ align-items: flex-start;
101
+ }
102
+
103
+ .schemaTabsContainer {
104
+ width: 100%;
105
+ }
106
+
107
+ .tabItem {
108
+ height: 100%;
109
+ }
110
+ }
@@ -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
- }