docusaurus-theme-openapi-docs 5.0.2 → 5.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 (137) hide show
  1. package/lib/markdown/schema.js +38 -15
  2. package/lib/markdown/schema.test.d.ts +1 -0
  3. package/lib/markdown/schema.test.js +86 -0
  4. package/lib/theme/ApiExplorer/ApiCodeBlock/Container/index.js +4 -2
  5. package/lib/theme/ApiExplorer/ApiCodeBlock/Content/String.js +9 -6
  6. package/lib/theme/ApiExplorer/ApiCodeBlock/Line/index.d.ts +1 -1
  7. package/lib/theme/ApiExplorer/ApiCodeBlock/index.d.ts +1 -1
  8. package/lib/theme/ApiExplorer/Authorization/index.js +9 -10
  9. package/lib/theme/ApiExplorer/Body/index.js +4 -5
  10. package/lib/theme/ApiExplorer/CodeSnippets/index.js +96 -61
  11. package/lib/theme/ApiExplorer/CodeSnippets/languages.js +12 -1
  12. package/lib/theme/ApiExplorer/CodeSnippets/languages.test.d.ts +1 -0
  13. package/lib/theme/ApiExplorer/CodeSnippets/languages.test.js +102 -0
  14. package/lib/theme/ApiExplorer/CodeTabs/index.d.ts +1 -1
  15. package/lib/theme/ApiExplorer/CodeTabs/index.js +6 -5
  16. package/lib/theme/ApiExplorer/Export/index.js +9 -2
  17. package/lib/theme/ApiExplorer/FormFileUpload/index.js +1 -2
  18. package/lib/theme/ApiExplorer/FormLabel/index.js +1 -2
  19. package/lib/theme/ApiExplorer/FormTextInput/index.js +1 -2
  20. package/lib/theme/ApiExplorer/LiveEditor/index.js +1 -2
  21. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.js +5 -3
  22. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.js +75 -4
  23. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.js +1 -2
  24. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.js +67 -4
  25. package/lib/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.js +65 -1
  26. package/lib/theme/ApiExplorer/ParamOptions/index.js +2 -3
  27. package/lib/theme/ApiExplorer/Request/index.js +17 -18
  28. package/lib/theme/ApiExplorer/Response/index.js +54 -12
  29. package/lib/theme/ApiExplorer/SecuritySchemes/index.js +57 -50
  30. package/lib/theme/ApiExplorer/Server/index.js +2 -3
  31. package/lib/theme/ApiItem/index.js +59 -33
  32. package/lib/theme/ApiTabs/index.d.ts +1 -1
  33. package/lib/theme/ApiTabs/index.js +7 -7
  34. package/lib/theme/DiscriminatorTabs/index.d.ts +1 -1
  35. package/lib/theme/DiscriminatorTabs/index.js +6 -5
  36. package/lib/theme/Example/index.js +3 -4
  37. package/lib/theme/MimeTabs/index.d.ts +1 -1
  38. package/lib/theme/MimeTabs/index.js +6 -5
  39. package/lib/theme/OperationTabs/index.d.ts +1 -1
  40. package/lib/theme/OperationTabs/index.js +6 -5
  41. package/lib/theme/ParamsDetails/index.js +1 -2
  42. package/lib/theme/ParamsItem/index.js +7 -8
  43. package/lib/theme/RequestSchema/index.js +57 -57
  44. package/lib/theme/ResponseExamples/index.js +3 -4
  45. package/lib/theme/ResponseSchema/index.js +26 -24
  46. package/lib/theme/Schema/index.js +148 -27
  47. package/lib/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
  48. package/lib/theme/SchemaExpansion/context.d.ts +24 -0
  49. package/lib/theme/SchemaExpansion/context.js +187 -0
  50. package/lib/theme/SchemaExpansion/index.d.ts +4 -0
  51. package/lib/theme/SchemaExpansion/index.js +314 -0
  52. package/lib/theme/SchemaItem/index.js +9 -10
  53. package/lib/theme/SchemaTabs/index.d.ts +1 -1
  54. package/lib/theme/SchemaTabs/index.js +6 -5
  55. package/lib/theme/StatusCodes/index.js +2 -4
  56. package/lib/theme/TabItem/index.d.ts +5 -0
  57. package/lib/theme/TabItem/index.js +51 -0
  58. package/lib/theme/TabItem/styles.module.css +3 -0
  59. package/lib/theme/Tabs/index.d.ts +5 -0
  60. package/lib/theme/Tabs/index.js +148 -0
  61. package/lib/theme/Tabs/styles.module.css +7 -0
  62. package/lib/theme/styles.scss +1 -0
  63. package/lib/theme/translationIds.d.ts +1 -93
  64. package/lib/theme/translationIds.js +0 -109
  65. package/lib/theme/utils/codeBlockUtils.d.ts +28 -0
  66. package/lib/theme/utils/codeBlockUtils.js +223 -0
  67. package/lib/theme/utils/reactUtils.d.ts +1 -0
  68. package/lib/theme/utils/reactUtils.js +23 -0
  69. package/lib/theme/utils/scrollUtils.d.ts +7 -0
  70. package/lib/theme/utils/scrollUtils.js +175 -0
  71. package/lib/theme/utils/tabsUtils.d.ts +47 -0
  72. package/lib/theme/utils/tabsUtils.js +299 -0
  73. package/lib/theme/utils/useCodeWordWrap.d.ts +8 -0
  74. package/lib/theme/utils/useCodeWordWrap.js +84 -0
  75. package/lib/theme/utils/useMutationObserver.d.ts +3 -0
  76. package/lib/theme/utils/useMutationObserver.js +34 -0
  77. package/package.json +4 -4
  78. package/src/markdown/schema.test.ts +102 -0
  79. package/src/markdown/schema.ts +42 -15
  80. package/src/theme/ApiExplorer/ApiCodeBlock/Container/index.tsx +2 -1
  81. package/src/theme/ApiExplorer/ApiCodeBlock/Content/String.tsx +8 -7
  82. package/src/theme/ApiExplorer/ApiCodeBlock/Line/index.tsx +1 -1
  83. package/src/theme/ApiExplorer/ApiCodeBlock/index.tsx +1 -1
  84. package/src/theme/ApiExplorer/Authorization/index.tsx +9 -10
  85. package/src/theme/ApiExplorer/Body/index.tsx +7 -5
  86. package/src/theme/ApiExplorer/CodeSnippets/index.tsx +103 -59
  87. package/src/theme/ApiExplorer/CodeSnippets/languages.test.ts +109 -0
  88. package/src/theme/ApiExplorer/CodeSnippets/languages.ts +13 -1
  89. package/src/theme/ApiExplorer/CodeTabs/index.tsx +5 -5
  90. package/src/theme/ApiExplorer/Export/index.tsx +6 -2
  91. package/src/theme/ApiExplorer/FormFileUpload/index.tsx +1 -2
  92. package/src/theme/ApiExplorer/FormLabel/index.tsx +1 -2
  93. package/src/theme/ApiExplorer/FormTextInput/index.tsx +1 -2
  94. package/src/theme/ApiExplorer/LiveEditor/index.tsx +1 -2
  95. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +5 -3
  96. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem.tsx +20 -4
  97. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem.tsx +1 -2
  98. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem.tsx +15 -4
  99. package/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem.tsx +11 -1
  100. package/src/theme/ApiExplorer/ParamOptions/index.tsx +2 -3
  101. package/src/theme/ApiExplorer/Request/index.tsx +23 -18
  102. package/src/theme/ApiExplorer/Response/index.tsx +63 -9
  103. package/src/theme/ApiExplorer/SecuritySchemes/index.tsx +60 -52
  104. package/src/theme/ApiExplorer/Server/index.tsx +8 -3
  105. package/src/theme/ApiItem/index.tsx +43 -21
  106. package/src/theme/ApiTabs/index.tsx +8 -8
  107. package/src/theme/DiscriminatorTabs/index.tsx +6 -5
  108. package/src/theme/Example/index.tsx +3 -4
  109. package/src/theme/MimeTabs/index.tsx +9 -8
  110. package/src/theme/OperationTabs/index.tsx +5 -4
  111. package/src/theme/ParamsDetails/index.tsx +1 -2
  112. package/src/theme/ParamsItem/index.tsx +13 -8
  113. package/src/theme/RequestSchema/index.tsx +38 -40
  114. package/src/theme/ResponseExamples/index.tsx +3 -4
  115. package/src/theme/ResponseSchema/index.tsx +16 -17
  116. package/src/theme/Schema/index.tsx +156 -27
  117. package/src/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
  118. package/src/theme/SchemaExpansion/context.tsx +154 -0
  119. package/src/theme/SchemaExpansion/index.tsx +236 -0
  120. package/src/theme/SchemaItem/index.tsx +18 -10
  121. package/src/theme/SchemaTabs/index.tsx +6 -5
  122. package/src/theme/StatusCodes/index.tsx +2 -3
  123. package/src/theme/TabItem/index.tsx +61 -0
  124. package/src/theme/TabItem/styles.module.css +3 -0
  125. package/src/theme/Tabs/index.tsx +164 -0
  126. package/src/theme/Tabs/styles.module.css +7 -0
  127. package/src/theme/styles.scss +1 -0
  128. package/src/theme/translationIds.ts +37 -106
  129. package/src/theme/utils/codeBlockUtils.ts +296 -0
  130. package/src/theme/utils/reactUtils.ts +22 -0
  131. package/src/theme/utils/scrollUtils.tsx +153 -0
  132. package/src/theme/utils/tabsUtils.tsx +329 -0
  133. package/src/theme/utils/useCodeWordWrap.ts +110 -0
  134. package/src/theme/utils/useMutationObserver.ts +43 -0
  135. package/src/theme-classic.d.ts +0 -96
  136. package/src/types.d.ts +27 -0
  137. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Portions Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * Portions Copyright (c) Palo Alto Networks
5
+ *
6
+ * Swizzled from @docusaurus/theme-classic/src/theme/TabItem/index.tsx (MIT).
7
+ * Re-points useTabs to our vendored tabsUtils so that <TabItem> reads the same
8
+ * context our swizzled <Tabs> and OpenAPI tab variants (ApiTabs, MimeTabs,
9
+ * SchemaTabs, etc.) provide. See:
10
+ * https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ * ========================================================================== */
15
+ var __importDefault =
16
+ (this && this.__importDefault) ||
17
+ function (mod) {
18
+ return mod && mod.__esModule ? mod : { default: mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.default = TabItem;
22
+ const react_1 = __importDefault(require("react"));
23
+ const clsx_1 = __importDefault(require("clsx"));
24
+ const tabsUtils_1 = require("@theme/utils/tabsUtils");
25
+ const styles_module_css_1 = __importDefault(require("./styles.module.css"));
26
+ function TabItemPanel({ children, className, hidden }) {
27
+ return react_1.default.createElement(
28
+ "div",
29
+ {
30
+ role: "tabpanel",
31
+ className: (0, clsx_1.default)(
32
+ styles_module_css_1.default.tabItem,
33
+ className
34
+ ),
35
+ hidden,
36
+ },
37
+ children
38
+ );
39
+ }
40
+ function TabItem({ children, className, value }) {
41
+ const { selectedValue, lazy } = (0, tabsUtils_1.useTabs)();
42
+ const isSelected = value === selectedValue;
43
+ if (!isSelected && lazy) {
44
+ return null;
45
+ }
46
+ return react_1.default.createElement(
47
+ TabItemPanel,
48
+ { className: className, hidden: !isSelected },
49
+ children
50
+ );
51
+ }
@@ -0,0 +1,3 @@
1
+ .tabItem > *:last-child {
2
+ margin-bottom: 0;
3
+ }
@@ -0,0 +1,5 @@
1
+ import { type ReactNode } from "react";
2
+ import { type TabsProps } from "@theme/utils/tabsUtils";
3
+ type Props = TabsProps;
4
+ export default function Tabs(props: Props): ReactNode;
5
+ export {};
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Portions Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * Portions Copyright (c) Palo Alto Networks
5
+ *
6
+ * Swizzled from @docusaurus/theme-classic/src/theme/Tabs/index.tsx (MIT).
7
+ * Re-points the internal hooks (useTabs, useTabsContextValue, etc.) to our
8
+ * vendored tabsUtils so that the entire <Tabs>/<TabItem> pair runs through a
9
+ * single React context owned by this package. See:
10
+ * https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
11
+ *
12
+ * This source code is licensed under the MIT license found in the
13
+ * LICENSE file in the root directory of this source tree.
14
+ * ========================================================================== */
15
+ var __importDefault =
16
+ (this && this.__importDefault) ||
17
+ function (mod) {
18
+ return mod && mod.__esModule ? mod : { default: mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.default = Tabs;
22
+ const react_1 = __importDefault(require("react"));
23
+ const theme_common_1 = require("@docusaurus/theme-common");
24
+ const useIsBrowser_1 = __importDefault(require("@docusaurus/useIsBrowser"));
25
+ const clsx_1 = __importDefault(require("clsx"));
26
+ const scrollUtils_1 = require("@theme/utils/scrollUtils");
27
+ const tabsUtils_1 = require("@theme/utils/tabsUtils");
28
+ const styles_module_css_1 = __importDefault(require("./styles.module.css"));
29
+ function TabList({ className }) {
30
+ const { selectedValue, selectValue, tabValues, block } = (0,
31
+ tabsUtils_1.useTabs)();
32
+ const tabRefs = [];
33
+ const { blockElementScrollPositionUntilNextRender } = (0,
34
+ scrollUtils_1.useScrollPositionBlocker)();
35
+ const handleTabChange = (event) => {
36
+ const newTab = event.currentTarget;
37
+ const newTabIndex = tabRefs.indexOf(newTab);
38
+ const newTabValue = tabValues[newTabIndex].value;
39
+ if (newTabValue !== selectedValue) {
40
+ blockElementScrollPositionUntilNextRender(newTab);
41
+ selectValue(newTabValue);
42
+ }
43
+ };
44
+ const handleKeydown = (event) => {
45
+ let focusElement = null;
46
+ switch (event.key) {
47
+ case "Enter": {
48
+ handleTabChange(event);
49
+ break;
50
+ }
51
+ case "ArrowRight": {
52
+ const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
53
+ focusElement = tabRefs[nextTab] ?? tabRefs[0];
54
+ break;
55
+ }
56
+ case "ArrowLeft": {
57
+ const prevTab = tabRefs.indexOf(event.currentTarget) - 1;
58
+ focusElement = tabRefs[prevTab] ?? tabRefs[tabRefs.length - 1];
59
+ break;
60
+ }
61
+ default:
62
+ break;
63
+ }
64
+ focusElement?.focus();
65
+ };
66
+ return react_1.default.createElement(
67
+ "ul",
68
+ {
69
+ role: "tablist",
70
+ "aria-orientation": "horizontal",
71
+ className: (0, clsx_1.default)(
72
+ "tabs",
73
+ {
74
+ "tabs--block": block,
75
+ },
76
+ className
77
+ ),
78
+ },
79
+ tabValues.map(({ value, label, attributes }) =>
80
+ react_1.default.createElement(
81
+ "li",
82
+ {
83
+ // TODO extract TabListItem
84
+ role: "tab",
85
+ tabIndex: selectedValue === value ? 0 : -1,
86
+ "aria-selected": selectedValue === value,
87
+ key: value,
88
+ ref: (ref) => {
89
+ tabRefs.push(ref);
90
+ },
91
+ onKeyDown: handleKeydown,
92
+ onClick: handleTabChange,
93
+ ...attributes,
94
+ className: (0, clsx_1.default)(
95
+ "tabs__item",
96
+ styles_module_css_1.default.tabItem,
97
+ attributes?.className,
98
+ {
99
+ "tabs__item--active": selectedValue === value,
100
+ }
101
+ ),
102
+ },
103
+ label ?? value
104
+ )
105
+ )
106
+ );
107
+ }
108
+ function TabContent({ children }) {
109
+ return react_1.default.createElement(
110
+ "div",
111
+ { className: "margin-top--md" },
112
+ children
113
+ );
114
+ }
115
+ function TabsContainer({ className, children }) {
116
+ return react_1.default.createElement(
117
+ "div",
118
+ {
119
+ className: (0, clsx_1.default)(
120
+ theme_common_1.ThemeClassNames.tabs.container,
121
+ // former name kept for backward compatibility
122
+ // see https://github.com/facebook/docusaurus/pull/4086
123
+ "tabs-container",
124
+ styles_module_css_1.default.tabList
125
+ ),
126
+ },
127
+ react_1.default.createElement(TabList, { className: className }),
128
+ react_1.default.createElement(TabContent, null, children)
129
+ );
130
+ }
131
+ function Tabs(props) {
132
+ const isBrowser = (0, useIsBrowser_1.default)();
133
+ const value = (0, tabsUtils_1.useTabsContextValue)(props);
134
+ return react_1.default.createElement(
135
+ tabsUtils_1.TabsProvider,
136
+ {
137
+ value: value,
138
+ // Remount tabs after hydration
139
+ // Temporary fix for https://github.com/facebook/docusaurus/issues/5653
140
+ key: String(isBrowser),
141
+ },
142
+ react_1.default.createElement(
143
+ TabsContainer,
144
+ { className: props.className },
145
+ (0, tabsUtils_1.sanitizeTabsChildren)(props.children)
146
+ )
147
+ );
148
+ }
@@ -0,0 +1,7 @@
1
+ .tabList {
2
+ margin-bottom: var(--ifm-leading);
3
+ }
4
+
5
+ .tabItem {
6
+ margin-top: 0 !important;
7
+ }
@@ -32,6 +32,7 @@
32
32
  /* Schema Styling */
33
33
  @use "./ParamsItem/ParamsItem";
34
34
  @use "./SchemaItem/SchemaItem";
35
+ @use "./SchemaExpansion/SchemaExpansion";
35
36
  /* Tabs Styling */
36
37
  @use "./ApiTabs/ApiTabs";
37
38
  @use "./DiscriminatorTabs/DiscriminatorTabs";
@@ -1,93 +1 @@
1
- export declare const OPENAPI_RESPONSE: {
2
- TITLE: string;
3
- CLEAR: string;
4
- PLACEHOLDER: string;
5
- HEADERS_TAB: string;
6
- };
7
- export declare const OPENAPI_TABS: {
8
- RESPONSES_LABEL: string;
9
- };
10
- export declare const OPENAPI_REQUEST: {
11
- BODY_TITLE: string;
12
- ACCEPT_TITLE: string;
13
- SEND_BUTTON: string;
14
- REQUIRED_LABEL: string;
15
- REQUEST_TITLE: string;
16
- COLLAPSE_ALL: string;
17
- EXPAND_ALL: string;
18
- BASE_URL_TITLE: string;
19
- AUTH_TITLE: string;
20
- PARAMETERS_TITLE: string;
21
- FETCHING_MESSAGE: string;
22
- CONNECTION_FAILED: string;
23
- ERROR_TIMEOUT: string;
24
- ERROR_NETWORK: string;
25
- ERROR_CORS: string;
26
- ERROR_UNKNOWN: string;
27
- };
28
- export declare const OPENAPI_SERVER: {
29
- EDIT_BUTTON: string;
30
- HIDE_BUTTON: string;
31
- };
32
- export declare const OPENAPI_PARAM_OPTIONS: {
33
- SHOW_OPTIONAL: string;
34
- HIDE_OPTIONAL: string;
35
- };
36
- export declare const OPENAPI_FORM_FILE_UPLOAD: {
37
- CLEAR_BUTTON: string;
38
- };
39
- export declare const OPENAPI_FORM: {
40
- FIELD_REQUIRED: string;
41
- };
42
- export declare const OPENAPI_AUTH: {
43
- BEARER_TOKEN: string;
44
- USERNAME: string;
45
- PASSWORD: string;
46
- SECURITY_SCHEME: string;
47
- };
48
- export declare const OPENAPI_RESPONSE_EXAMPLES: {
49
- EXAMPLE: string;
50
- AUTO_EXAMPLE: string;
51
- };
52
- export declare const OPENAPI_BODY: {
53
- EXAMPLE_FROM_SCHEMA: string;
54
- };
55
- export declare const OPENAPI_STATUS_CODES: {
56
- RESPONSE_HEADERS: string;
57
- SCHEMA_TITLE: string;
58
- };
59
- export declare const OPENAPI_SCHEMA: {
60
- NO_SCHEMA: string;
61
- };
62
- export declare const OPENAPI_SCHEMA_ITEM: {
63
- CHARACTERS: string;
64
- NON_EMPTY: string;
65
- REQUIRED: string;
66
- DEPRECATED: string;
67
- NULLABLE: string;
68
- DEFAULT_VALUE: string;
69
- EXAMPLE: string;
70
- EXAMPLES: string;
71
- DESCRIPTION: string;
72
- CONSTANT_VALUE: string;
73
- ENUM_VALUE: string;
74
- ENUM_DESCRIPTION: string;
75
- POSSIBLE_VALUES: string;
76
- EXPRESSION: string;
77
- ONE_OF: string;
78
- ANY_OF: string;
79
- };
80
- export declare const OPENAPI_PARAMS_DETAILS: {
81
- PARAMETERS_TITLE: string;
82
- };
83
- export declare const OPENAPI_SECURITY_SCHEMES: {
84
- NAME: string;
85
- TYPE: string;
86
- SCOPES: string;
87
- IN: string;
88
- FLOWS: string;
89
- DESCRIPTION: string;
90
- SCHEME: string;
91
- BEARER_FORMAT: string;
92
- OPEN_ID_CONNECT_URL: string;
93
- };
1
+ export {};
@@ -6,112 +6,3 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  * ========================================================================== */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.OPENAPI_SECURITY_SCHEMES =
10
- exports.OPENAPI_PARAMS_DETAILS =
11
- exports.OPENAPI_SCHEMA_ITEM =
12
- exports.OPENAPI_SCHEMA =
13
- exports.OPENAPI_STATUS_CODES =
14
- exports.OPENAPI_BODY =
15
- exports.OPENAPI_RESPONSE_EXAMPLES =
16
- exports.OPENAPI_AUTH =
17
- exports.OPENAPI_FORM =
18
- exports.OPENAPI_FORM_FILE_UPLOAD =
19
- exports.OPENAPI_PARAM_OPTIONS =
20
- exports.OPENAPI_SERVER =
21
- exports.OPENAPI_REQUEST =
22
- exports.OPENAPI_TABS =
23
- exports.OPENAPI_RESPONSE =
24
- void 0;
25
- exports.OPENAPI_RESPONSE = {
26
- TITLE: "theme.openapi.response.title",
27
- CLEAR: "theme.openapi.response.clear",
28
- PLACEHOLDER: "theme.openapi.response.placeholder",
29
- HEADERS_TAB: "theme.openapi.response.headersTab",
30
- };
31
- exports.OPENAPI_TABS = {
32
- RESPONSES_LABEL: "theme.openapi.tabs.responses.label",
33
- };
34
- exports.OPENAPI_REQUEST = {
35
- BODY_TITLE: "theme.openapi.request.body.title",
36
- ACCEPT_TITLE: "theme.openapi.request.accept.title",
37
- SEND_BUTTON: "theme.openapi.request.sendButton",
38
- REQUIRED_LABEL: "theme.openapi.request.requiredLabel",
39
- REQUEST_TITLE: "theme.openapi.request.title",
40
- COLLAPSE_ALL: "theme.openapi.request.collapseAll",
41
- EXPAND_ALL: "theme.openapi.request.expandAll",
42
- BASE_URL_TITLE: "theme.openapi.request.baseUrl.title",
43
- AUTH_TITLE: "theme.openapi.request.auth.title",
44
- PARAMETERS_TITLE: "theme.openapi.request.parameters.title",
45
- FETCHING_MESSAGE: "theme.openapi.request.fetchingMessage",
46
- CONNECTION_FAILED: "theme.openapi.request.connectionFailed",
47
- ERROR_TIMEOUT: "theme.openapi.request.error.timeout",
48
- ERROR_NETWORK: "theme.openapi.request.error.network",
49
- ERROR_CORS: "theme.openapi.request.error.cors",
50
- ERROR_UNKNOWN: "theme.openapi.request.error.unknown",
51
- };
52
- exports.OPENAPI_SERVER = {
53
- EDIT_BUTTON: "theme.openapi.server.editButton",
54
- HIDE_BUTTON: "theme.openapi.server.hideButton",
55
- };
56
- exports.OPENAPI_PARAM_OPTIONS = {
57
- SHOW_OPTIONAL: "theme.openapi.paramOptions.showOptional",
58
- HIDE_OPTIONAL: "theme.openapi.paramOptions.hideOptional",
59
- };
60
- exports.OPENAPI_FORM_FILE_UPLOAD = {
61
- CLEAR_BUTTON: "theme.openapi.formFileUpload.clearButton",
62
- };
63
- exports.OPENAPI_FORM = {
64
- FIELD_REQUIRED: "theme.openapi.form.fieldRequired",
65
- };
66
- exports.OPENAPI_AUTH = {
67
- BEARER_TOKEN: "theme.openapi.auth.bearerToken",
68
- USERNAME: "theme.openapi.auth.username",
69
- PASSWORD: "theme.openapi.auth.password",
70
- SECURITY_SCHEME: "theme.openapi.auth.securityScheme",
71
- };
72
- exports.OPENAPI_RESPONSE_EXAMPLES = {
73
- EXAMPLE: "theme.openapi.responseExamples.example",
74
- AUTO_EXAMPLE: "theme.openapi.responseExamples.autoExample",
75
- };
76
- exports.OPENAPI_BODY = {
77
- EXAMPLE_FROM_SCHEMA: "theme.openapi.body.exampleFromSchema",
78
- };
79
- exports.OPENAPI_STATUS_CODES = {
80
- RESPONSE_HEADERS: "theme.openapi.statusCodes.responseHeaders",
81
- SCHEMA_TITLE: "theme.openapi.statusCodes.schemaTitle",
82
- };
83
- exports.OPENAPI_SCHEMA = {
84
- NO_SCHEMA: "theme.openapi.schema.noSchema",
85
- };
86
- exports.OPENAPI_SCHEMA_ITEM = {
87
- CHARACTERS: "theme.openapi.schemaItem.characters",
88
- NON_EMPTY: "theme.openapi.schemaItem.nonEmpty",
89
- REQUIRED: "theme.openapi.schemaItem.required",
90
- DEPRECATED: "theme.openapi.schemaItem.deprecated",
91
- NULLABLE: "theme.openapi.schemaItem.nullable",
92
- DEFAULT_VALUE: "theme.openapi.schemaItem.defaultValue",
93
- EXAMPLE: "theme.openapi.schemaItem.example",
94
- EXAMPLES: "theme.openapi.schemaItem.examples",
95
- DESCRIPTION: "theme.openapi.schemaItem.description",
96
- CONSTANT_VALUE: "theme.openapi.schemaItem.constantValue",
97
- ENUM_VALUE: "theme.openapi.schemaItem.enumValue",
98
- ENUM_DESCRIPTION: "theme.openapi.schemaItem.enumDescription",
99
- POSSIBLE_VALUES: "theme.openapi.schemaItem.possibleValues",
100
- EXPRESSION: "theme.openapi.schemaItem.expression",
101
- ONE_OF: "theme.openapi.schemaItem.oneOf",
102
- ANY_OF: "theme.openapi.schemaItem.anyOf",
103
- };
104
- exports.OPENAPI_PARAMS_DETAILS = {
105
- PARAMETERS_TITLE: "theme.openapi.paramsDetails.parametersTitle",
106
- };
107
- exports.OPENAPI_SECURITY_SCHEMES = {
108
- NAME: "theme.openapi.securitySchemes.name",
109
- TYPE: "theme.openapi.securitySchemes.type",
110
- SCOPES: "theme.openapi.securitySchemes.scopes",
111
- IN: "theme.openapi.securitySchemes.in",
112
- FLOWS: "theme.openapi.securitySchemes.flows",
113
- DESCRIPTION: "theme.openapi.securitySchemes.description",
114
- SCHEME: "theme.openapi.securitySchemes.scheme",
115
- BEARER_FORMAT: "theme.openapi.securitySchemes.bearerFormat",
116
- OPEN_ID_CONNECT_URL: "theme.openapi.securitySchemes.openIdConnectUrl",
117
- };
@@ -0,0 +1,28 @@
1
+ import type { CSSProperties } from "react";
2
+ import type { PrismTheme } from "prism-react-renderer";
3
+ export type MagicCommentConfig = {
4
+ className: string;
5
+ line?: string;
6
+ block?: {
7
+ start: string;
8
+ end: string;
9
+ };
10
+ };
11
+ export declare function parseCodeBlockTitle(metastring?: string): string;
12
+ export declare function containsLineNumbers(metastring?: string): boolean;
13
+ type ParseCodeLinesParam = {
14
+ metastring: string | undefined;
15
+ language: string | undefined;
16
+ magicComments: MagicCommentConfig[];
17
+ };
18
+ type CodeLineClassNames = {
19
+ [lineIndex: number]: string[];
20
+ };
21
+ type ParsedCodeLines = {
22
+ code: string;
23
+ lineClassNames: CodeLineClassNames;
24
+ };
25
+ export declare function parseLines(code: string, params: ParseCodeLinesParam): ParsedCodeLines;
26
+ declare function parseClassNameLanguage(className: string | undefined): string | undefined;
27
+ export { parseClassNameLanguage as parseLanguage };
28
+ export declare function getPrismCssVariables(prismTheme: PrismTheme): CSSProperties;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ /* ============================================================================
3
+ * Portions Copyright (c) Meta Platforms, Inc. and affiliates.
4
+ * Portions Copyright (c) Palo Alto Networks
5
+ *
6
+ * Vendored subset of @docusaurus/theme-common/src/utils/codeBlockUtils.tsx (MIT)
7
+ * to remove the dependency on @docusaurus/theme-common/internal.
8
+ * See: https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/issues/1140
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ * ========================================================================== */
13
+ var __importDefault =
14
+ (this && this.__importDefault) ||
15
+ function (mod) {
16
+ return mod && mod.__esModule ? mod : { default: mod };
17
+ };
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.parseCodeBlockTitle = parseCodeBlockTitle;
20
+ exports.containsLineNumbers = containsLineNumbers;
21
+ exports.parseLines = parseLines;
22
+ exports.parseLanguage = parseClassNameLanguage;
23
+ exports.getPrismCssVariables = getPrismCssVariables;
24
+ const parse_numeric_range_1 = __importDefault(require("parse-numeric-range"));
25
+ const codeBlockTitleRegex = /title=(?<quote>["'])(?<title>.*?)\1/;
26
+ const metastringLinesRangeRegex = /\{(?<range>[\d,-]+)\}/;
27
+ const popularCommentPatterns = {
28
+ js: { start: "\\/\\/", end: "" },
29
+ jsBlock: { start: "\\/\\*", end: "\\*\\/" },
30
+ jsx: { start: "\\{\\s*\\/\\*", end: "\\*\\/\\s*\\}" },
31
+ bash: { start: "#", end: "" },
32
+ html: { start: "<!--", end: "-->" },
33
+ };
34
+ const commentPatterns = {
35
+ ...popularCommentPatterns,
36
+ lua: { start: "--", end: "" },
37
+ wasm: { start: "\\;\\;", end: "" },
38
+ tex: { start: "%", end: "" },
39
+ vb: { start: "['‘’]", end: "" },
40
+ vbnet: { start: "(?:_\\s*)?['‘’]", end: "" },
41
+ rem: { start: "[Rr][Ee][Mm]\\b", end: "" },
42
+ f90: { start: "!", end: "" },
43
+ ml: { start: "\\(\\*", end: "\\*\\)" },
44
+ cobol: { start: "\\*>", end: "" },
45
+ };
46
+ const popularCommentTypes = Object.keys(popularCommentPatterns);
47
+ function getCommentPattern(languages, magicCommentDirectives) {
48
+ const commentPattern = languages
49
+ .map((lang) => {
50
+ const { start, end } = commentPatterns[lang];
51
+ return `(?:${start}\\s*(${magicCommentDirectives
52
+ .flatMap((d) => [d.line, d.block?.start, d.block?.end].filter(Boolean))
53
+ .join("|")})\\s*${end})`;
54
+ })
55
+ .join("|");
56
+ return new RegExp(`^\\s*(?:${commentPattern})\\s*$`);
57
+ }
58
+ function getAllMagicCommentDirectiveStyles(lang, magicCommentDirectives) {
59
+ switch (lang) {
60
+ case "js":
61
+ case "javascript":
62
+ case "ts":
63
+ case "typescript":
64
+ return getCommentPattern(["js", "jsBlock"], magicCommentDirectives);
65
+ case "jsx":
66
+ case "tsx":
67
+ return getCommentPattern(
68
+ ["js", "jsBlock", "jsx"],
69
+ magicCommentDirectives
70
+ );
71
+ case "html":
72
+ return getCommentPattern(
73
+ ["js", "jsBlock", "html"],
74
+ magicCommentDirectives
75
+ );
76
+ case "python":
77
+ case "py":
78
+ case "bash":
79
+ return getCommentPattern(["bash"], magicCommentDirectives);
80
+ case "markdown":
81
+ case "md":
82
+ return getCommentPattern(["html", "jsx", "bash"], magicCommentDirectives);
83
+ case "tex":
84
+ case "latex":
85
+ case "matlab":
86
+ return getCommentPattern(["tex"], magicCommentDirectives);
87
+ case "lua":
88
+ case "haskell":
89
+ return getCommentPattern(["lua"], magicCommentDirectives);
90
+ case "sql":
91
+ return getCommentPattern(["lua", "jsBlock"], magicCommentDirectives);
92
+ case "wasm":
93
+ return getCommentPattern(["wasm"], magicCommentDirectives);
94
+ case "vb":
95
+ case "vba":
96
+ case "visual-basic":
97
+ return getCommentPattern(["vb", "rem"], magicCommentDirectives);
98
+ case "vbnet":
99
+ return getCommentPattern(["vbnet", "rem"], magicCommentDirectives);
100
+ case "batch":
101
+ return getCommentPattern(["rem"], magicCommentDirectives);
102
+ case "basic":
103
+ return getCommentPattern(["rem", "f90"], magicCommentDirectives);
104
+ case "fsharp":
105
+ return getCommentPattern(["js", "ml"], magicCommentDirectives);
106
+ case "ocaml":
107
+ case "sml":
108
+ return getCommentPattern(["ml"], magicCommentDirectives);
109
+ case "fortran":
110
+ return getCommentPattern(["f90"], magicCommentDirectives);
111
+ case "cobol":
112
+ return getCommentPattern(["cobol"], magicCommentDirectives);
113
+ default:
114
+ return getCommentPattern(popularCommentTypes, magicCommentDirectives);
115
+ }
116
+ }
117
+ function parseCodeBlockTitle(metastring) {
118
+ return metastring?.match(codeBlockTitleRegex)?.groups.title ?? "";
119
+ }
120
+ function containsLineNumbers(metastring) {
121
+ return Boolean(metastring?.includes("showLineNumbers"));
122
+ }
123
+ function parseCodeLinesFromMetastring(code, { metastring, magicComments }) {
124
+ if (metastring && metastringLinesRangeRegex.test(metastring)) {
125
+ const linesRange = metastring.match(metastringLinesRangeRegex).groups.range;
126
+ if (magicComments.length === 0) {
127
+ throw new Error(
128
+ `A highlight range has been given in code block's metastring (\`\`\` ${metastring}), but no magic comment config is available. Docusaurus applies the first magic comment entry's className for metastring ranges.`
129
+ );
130
+ }
131
+ const metastringRangeClassName = magicComments[0].className;
132
+ const lines = (0, parse_numeric_range_1.default)(linesRange)
133
+ .filter((n) => n > 0)
134
+ .map((n) => [n - 1, [metastringRangeClassName]]);
135
+ return { lineClassNames: Object.fromEntries(lines), code };
136
+ }
137
+ return null;
138
+ }
139
+ function parseCodeLinesFromContent(code, params) {
140
+ const { language, magicComments } = params;
141
+ if (language === undefined) {
142
+ return { lineClassNames: {}, code };
143
+ }
144
+ const directiveRegex = getAllMagicCommentDirectiveStyles(
145
+ language,
146
+ magicComments
147
+ );
148
+ const lines = code.split(/\r?\n/);
149
+ const blocks = Object.fromEntries(
150
+ magicComments.map((d) => [d.className, { start: 0, range: "" }])
151
+ );
152
+ const lineToClassName = Object.fromEntries(
153
+ magicComments
154
+ .filter((d) => d.line)
155
+ .map(({ className, line }) => [line, className])
156
+ );
157
+ const blockStartToClassName = Object.fromEntries(
158
+ magicComments
159
+ .filter((d) => d.block)
160
+ .map(({ className, block }) => [block.start, className])
161
+ );
162
+ const blockEndToClassName = Object.fromEntries(
163
+ magicComments
164
+ .filter((d) => d.block)
165
+ .map(({ className, block }) => [block.end, className])
166
+ );
167
+ for (let lineNumber = 0; lineNumber < lines.length; ) {
168
+ const line = lines[lineNumber];
169
+ const match = line.match(directiveRegex);
170
+ if (!match) {
171
+ lineNumber += 1;
172
+ continue;
173
+ }
174
+ const directive = match.slice(1).find((item) => item !== undefined);
175
+ if (lineToClassName[directive]) {
176
+ blocks[lineToClassName[directive]].range += `${lineNumber},`;
177
+ } else if (blockStartToClassName[directive]) {
178
+ blocks[blockStartToClassName[directive]].start = lineNumber;
179
+ } else if (blockEndToClassName[directive]) {
180
+ blocks[blockEndToClassName[directive]].range +=
181
+ `${blocks[blockEndToClassName[directive]].start}-${lineNumber - 1},`;
182
+ }
183
+ lines.splice(lineNumber, 1);
184
+ }
185
+ const lineClassNames = {};
186
+ Object.entries(blocks).forEach(([className, { range }]) => {
187
+ (0, parse_numeric_range_1.default)(range).forEach((l) => {
188
+ lineClassNames[l] ??= [];
189
+ lineClassNames[l].push(className);
190
+ });
191
+ });
192
+ return { code: lines.join("\n"), lineClassNames };
193
+ }
194
+ function parseLines(code, params) {
195
+ const newCode = code.replace(/\r?\n$/, "");
196
+ return (
197
+ parseCodeLinesFromMetastring(newCode, { ...params }) ??
198
+ parseCodeLinesFromContent(newCode, { ...params })
199
+ );
200
+ }
201
+ function parseClassNameLanguage(className) {
202
+ if (!className) {
203
+ return undefined;
204
+ }
205
+ const languageClassName = className
206
+ .split(" ")
207
+ .find((str) => str.startsWith("language-"));
208
+ return languageClassName?.replace(/language-/, "");
209
+ }
210
+ function getPrismCssVariables(prismTheme) {
211
+ const mapping = {
212
+ color: "--prism-color",
213
+ backgroundColor: "--prism-background-color",
214
+ };
215
+ const properties = {};
216
+ Object.entries(prismTheme.plain).forEach(([key, value]) => {
217
+ const varName = mapping[key];
218
+ if (varName && typeof value === "string") {
219
+ properties[varName] = value;
220
+ }
221
+ });
222
+ return properties;
223
+ }
@@ -0,0 +1 @@
1
+ export declare function useShallowMemoObject<O extends object>(obj: O): O;