docusaurus-theme-openapi-docs 0.0.0-1241 → 0.0.0-1249
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/ApiItem/index.js +43 -32
- package/lib/theme/RequestSchema/index.js +58 -56
- package/lib/theme/ResponseSchema/index.js +25 -22
- package/lib/theme/Schema/index.js +15 -5
- package/lib/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
- package/lib/theme/SchemaExpansion/context.d.ts +24 -0
- package/lib/theme/SchemaExpansion/context.js +187 -0
- package/lib/theme/SchemaExpansion/index.d.ts +4 -0
- package/lib/theme/SchemaExpansion/index.js +315 -0
- package/lib/theme/styles.scss +1 -0
- package/lib/theme/translationIds.d.ts +6 -0
- package/lib/theme/translationIds.js +7 -0
- package/package.json +3 -3
- package/src/theme/ApiItem/index.tsx +25 -20
- package/src/theme/RequestSchema/index.tsx +38 -39
- package/src/theme/ResponseSchema/index.tsx +15 -15
- package/src/theme/Schema/index.tsx +17 -5
- package/src/theme/SchemaExpansion/_SchemaExpansion.scss +113 -0
- package/src/theme/SchemaExpansion/context.tsx +154 -0
- package/src/theme/SchemaExpansion/index.tsx +237 -0
- package/src/theme/styles.scss +1 -0
- package/src/theme/translationIds.ts +7 -0
- package/src/types.d.ts +18 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -29,6 +29,7 @@ const storage_utils_1 = require("@theme/ApiExplorer/storage-utils");
|
|
|
29
29
|
const Layout_1 = __importDefault(require("@theme/ApiItem/Layout"));
|
|
30
30
|
const CodeBlock_1 = __importDefault(require("@theme/CodeBlock"));
|
|
31
31
|
const Metadata_1 = __importDefault(require("@theme/DocItem/Metadata"));
|
|
32
|
+
const SchemaExpansion_1 = require("@theme/SchemaExpansion");
|
|
32
33
|
const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
|
|
33
34
|
const clsx_1 = __importDefault(require("clsx"));
|
|
34
35
|
const pako_1 = require("pako");
|
|
@@ -157,30 +158,34 @@ function ApiItem(props) {
|
|
|
157
158
|
react_redux_1.Provider,
|
|
158
159
|
{ store: store2 },
|
|
159
160
|
react_1.default.createElement(
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
react_1.default.createElement(
|
|
163
|
-
"div",
|
|
164
|
-
{ className: "col col--7 openapi-left-panel__container" },
|
|
165
|
-
react_1.default.createElement(MDXComponent, null)
|
|
166
|
-
),
|
|
161
|
+
SchemaExpansion_1.SchemaExpansionProvider,
|
|
162
|
+
null,
|
|
167
163
|
react_1.default.createElement(
|
|
168
164
|
"div",
|
|
169
|
-
{ className: "
|
|
165
|
+
{ className: (0, clsx_1.default)("row", "theme-api-markdown") },
|
|
166
|
+
react_1.default.createElement(
|
|
167
|
+
"div",
|
|
168
|
+
{ className: "col col--7 openapi-left-panel__container" },
|
|
169
|
+
react_1.default.createElement(MDXComponent, null)
|
|
170
|
+
),
|
|
170
171
|
react_1.default.createElement(
|
|
171
|
-
|
|
172
|
-
{
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
172
|
+
"div",
|
|
173
|
+
{ className: "col col--5 openapi-right-panel__container" },
|
|
174
|
+
react_1.default.createElement(
|
|
175
|
+
BrowserOnly_1.default,
|
|
176
|
+
{
|
|
177
|
+
fallback: react_1.default.createElement(
|
|
178
|
+
SkeletonLoader_1.default,
|
|
179
|
+
{ size: "lg" }
|
|
180
|
+
),
|
|
181
|
+
},
|
|
182
|
+
() => {
|
|
183
|
+
return react_1.default.createElement(ApiExplorer, {
|
|
184
|
+
item: api,
|
|
185
|
+
infoPath: infoPath,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
)
|
|
184
189
|
)
|
|
185
190
|
)
|
|
186
191
|
)
|
|
@@ -200,20 +205,26 @@ function ApiItem(props) {
|
|
|
200
205
|
Layout_1.default,
|
|
201
206
|
null,
|
|
202
207
|
react_1.default.createElement(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
react_1.default.createElement(
|
|
206
|
-
"div",
|
|
207
|
-
{ className: "col col--7 openapi-left-panel__container schema" },
|
|
208
|
-
react_1.default.createElement(MDXComponent, null)
|
|
209
|
-
),
|
|
208
|
+
SchemaExpansion_1.SchemaExpansionProvider,
|
|
209
|
+
null,
|
|
210
210
|
react_1.default.createElement(
|
|
211
211
|
"div",
|
|
212
|
-
{ className: "
|
|
212
|
+
{ className: (0, clsx_1.default)("row", "theme-api-markdown") },
|
|
213
|
+
react_1.default.createElement(
|
|
214
|
+
"div",
|
|
215
|
+
{
|
|
216
|
+
className: "col col--7 openapi-left-panel__container schema",
|
|
217
|
+
},
|
|
218
|
+
react_1.default.createElement(MDXComponent, null)
|
|
219
|
+
),
|
|
213
220
|
react_1.default.createElement(
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
|
|
221
|
+
"div",
|
|
222
|
+
{ className: "col col--5 openapi-right-panel__container" },
|
|
223
|
+
react_1.default.createElement(
|
|
224
|
+
CodeBlock_1.default,
|
|
225
|
+
{ language: "json", title: `${frontMatter.title}` },
|
|
226
|
+
JSON.stringify(sample, null, 2)
|
|
227
|
+
)
|
|
217
228
|
)
|
|
218
229
|
)
|
|
219
230
|
)
|
|
@@ -19,6 +19,7 @@ const Markdown_1 = __importDefault(require("@theme/Markdown"));
|
|
|
19
19
|
const MimeTabs_1 = __importDefault(require("@theme/MimeTabs")); // Assume these components exist
|
|
20
20
|
const ResponseExamples_1 = require("@theme/ResponseExamples");
|
|
21
21
|
const Schema_1 = __importDefault(require("@theme/Schema"));
|
|
22
|
+
const SchemaExpansion_1 = __importDefault(require("@theme/SchemaExpansion"));
|
|
22
23
|
const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
|
|
23
24
|
const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
|
|
24
25
|
const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
@@ -71,32 +72,35 @@ const RequestSchemaComponent = ({ title, body, style }) => {
|
|
|
71
72
|
open: true,
|
|
72
73
|
style: style,
|
|
73
74
|
summary: react_1.default.createElement(
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
"summary",
|
|
76
|
+
{
|
|
77
|
+
className:
|
|
78
|
+
"openapi-markdown__details-summary--with-control",
|
|
79
|
+
},
|
|
76
80
|
react_1.default.createElement(
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
"h3",
|
|
82
|
+
{
|
|
83
|
+
className:
|
|
84
|
+
"openapi-markdown__details-summary-header-body",
|
|
85
|
+
},
|
|
86
|
+
(0, Translate_1.translate)({
|
|
87
|
+
id: translationIds_1.OPENAPI_REQUEST.BODY_TITLE,
|
|
88
|
+
message: title,
|
|
89
|
+
}),
|
|
90
|
+
body.required === true &&
|
|
91
|
+
react_1.default.createElement(
|
|
92
|
+
"span",
|
|
93
|
+
{ className: "openapi-schema__required" },
|
|
94
|
+
(0, Translate_1.translate)({
|
|
95
|
+
id: translationIds_1.OPENAPI_SCHEMA_ITEM
|
|
96
|
+
.REQUIRED,
|
|
97
|
+
message: "required",
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
),
|
|
101
|
+
react_1.default.createElement(
|
|
102
|
+
SchemaExpansion_1.default,
|
|
103
|
+
null
|
|
100
104
|
)
|
|
101
105
|
),
|
|
102
106
|
},
|
|
@@ -179,38 +183,36 @@ const RequestSchemaComponent = ({ title, body, style }) => {
|
|
|
179
183
|
open: true,
|
|
180
184
|
style: style,
|
|
181
185
|
summary: react_1.default.createElement(
|
|
182
|
-
|
|
183
|
-
|
|
186
|
+
"summary",
|
|
187
|
+
{
|
|
188
|
+
className: "openapi-markdown__details-summary--with-control",
|
|
189
|
+
},
|
|
184
190
|
react_1.default.createElement(
|
|
185
|
-
"
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
})
|
|
211
|
-
)
|
|
212
|
-
)
|
|
213
|
-
)
|
|
191
|
+
"h3",
|
|
192
|
+
{
|
|
193
|
+
className: "openapi-markdown__details-summary-header-body",
|
|
194
|
+
},
|
|
195
|
+
(0, Translate_1.translate)({
|
|
196
|
+
id: translationIds_1.OPENAPI_REQUEST.BODY_TITLE,
|
|
197
|
+
message: title,
|
|
198
|
+
}),
|
|
199
|
+
firstBody.type === "array" &&
|
|
200
|
+
react_1.default.createElement(
|
|
201
|
+
"span",
|
|
202
|
+
{ style: { opacity: "0.6" } },
|
|
203
|
+
" array"
|
|
204
|
+
),
|
|
205
|
+
body.required &&
|
|
206
|
+
react_1.default.createElement(
|
|
207
|
+
"strong",
|
|
208
|
+
{ className: "openapi-schema__required" },
|
|
209
|
+
(0, Translate_1.translate)({
|
|
210
|
+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.REQUIRED,
|
|
211
|
+
message: "required",
|
|
212
|
+
})
|
|
213
|
+
)
|
|
214
|
+
),
|
|
215
|
+
react_1.default.createElement(SchemaExpansion_1.default, null)
|
|
214
216
|
),
|
|
215
217
|
},
|
|
216
218
|
react_1.default.createElement(
|
|
@@ -19,6 +19,7 @@ const Markdown_1 = __importDefault(require("@theme/Markdown"));
|
|
|
19
19
|
const MimeTabs_1 = __importDefault(require("@theme/MimeTabs")); // Assume these components exist
|
|
20
20
|
const ResponseExamples_1 = require("@theme/ResponseExamples");
|
|
21
21
|
const Schema_1 = __importDefault(require("@theme/Schema"));
|
|
22
|
+
const SchemaExpansion_1 = __importDefault(require("@theme/SchemaExpansion"));
|
|
22
23
|
const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
|
|
23
24
|
const SkeletonLoader_1 = __importDefault(require("@theme/SkeletonLoader"));
|
|
24
25
|
const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
@@ -83,29 +84,31 @@ const ResponseSchemaComponent = ({ title, body, style }) => {
|
|
|
83
84
|
open: true,
|
|
84
85
|
style: style,
|
|
85
86
|
summary: react_1.default.createElement(
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
"summary",
|
|
88
|
+
{
|
|
89
|
+
className:
|
|
90
|
+
"openapi-markdown__details-summary--with-control",
|
|
91
|
+
},
|
|
88
92
|
react_1.default.createElement(
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
93
|
+
"strong",
|
|
94
|
+
{
|
|
95
|
+
className:
|
|
96
|
+
"openapi-markdown__details-summary-response",
|
|
97
|
+
},
|
|
98
|
+
title,
|
|
99
|
+
body.required === true &&
|
|
100
|
+
react_1.default.createElement(
|
|
101
|
+
"span",
|
|
102
|
+
{ className: "openapi-schema__required" },
|
|
103
|
+
(0, Translate_1.translate)({
|
|
104
|
+
id: translationIds_1.OPENAPI_SCHEMA_ITEM.REQUIRED,
|
|
105
|
+
message: "required",
|
|
106
|
+
})
|
|
107
|
+
)
|
|
108
|
+
),
|
|
109
|
+
react_1.default.createElement(
|
|
110
|
+
SchemaExpansion_1.default,
|
|
111
|
+
null
|
|
109
112
|
)
|
|
110
113
|
),
|
|
111
114
|
},
|
|
@@ -77,6 +77,7 @@ const DiscriminatorTabs_1 = __importDefault(
|
|
|
77
77
|
require("@theme/DiscriminatorTabs")
|
|
78
78
|
);
|
|
79
79
|
const Markdown_1 = __importDefault(require("@theme/Markdown"));
|
|
80
|
+
const SchemaExpansion_1 = require("@theme/SchemaExpansion");
|
|
80
81
|
const SchemaItem_1 = __importDefault(require("@theme/SchemaItem"));
|
|
81
82
|
const SchemaTabs_1 = __importDefault(require("@theme/SchemaTabs"));
|
|
82
83
|
const TabItem_1 = __importDefault(require("@theme/TabItem"));
|
|
@@ -644,13 +645,18 @@ const SchemaNodeDetails = ({
|
|
|
644
645
|
schemaType,
|
|
645
646
|
schemaPath,
|
|
646
647
|
}) => {
|
|
648
|
+
const depth = (0, SchemaExpansion_1.useSchemaDepth)();
|
|
649
|
+
const { level } = (0, SchemaExpansion_1.useSchemaExpansion)();
|
|
650
|
+
const defaultOpen = depth < level;
|
|
647
651
|
return react_1.default.createElement(
|
|
648
652
|
SchemaItem_1.default,
|
|
649
653
|
{ collapsible: true },
|
|
650
654
|
react_1.default.createElement(
|
|
651
655
|
Details_1.default,
|
|
652
656
|
{
|
|
657
|
+
key: `level-${level}`,
|
|
653
658
|
className: "openapi-markdown__details",
|
|
659
|
+
open: defaultOpen,
|
|
654
660
|
summary: react_1.default.createElement(Summary, {
|
|
655
661
|
name: name,
|
|
656
662
|
schemaName: schemaName,
|
|
@@ -669,11 +675,15 @@ const SchemaNodeDetails = ({
|
|
|
669
675
|
react_1.default.createElement(MarkdownWrapper, {
|
|
670
676
|
text: (0, schema_1.getQualifierMessage)(schema),
|
|
671
677
|
}),
|
|
672
|
-
react_1.default.createElement(
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
678
|
+
react_1.default.createElement(
|
|
679
|
+
SchemaExpansion_1.SchemaDepthProvider,
|
|
680
|
+
{ depth: depth + 1 },
|
|
681
|
+
react_1.default.createElement(SchemaNode, {
|
|
682
|
+
schema: schema,
|
|
683
|
+
schemaType: schemaType,
|
|
684
|
+
schemaPath: schemaPath,
|
|
685
|
+
})
|
|
686
|
+
)
|
|
677
687
|
)
|
|
678
688
|
)
|
|
679
689
|
);
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
.openapi-schema-expansion {
|
|
9
|
+
position: relative;
|
|
10
|
+
display: inline-flex;
|
|
11
|
+
align-items: center;
|
|
12
|
+
margin-left: auto;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.openapi-schema-expansion__trigger {
|
|
16
|
+
appearance: none;
|
|
17
|
+
background: transparent;
|
|
18
|
+
border: none;
|
|
19
|
+
border-radius: var(--ifm-global-radius);
|
|
20
|
+
padding: 0;
|
|
21
|
+
width: 22px;
|
|
22
|
+
height: 22px;
|
|
23
|
+
flex: 0 0 22px;
|
|
24
|
+
display: inline-flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
justify-content: center;
|
|
27
|
+
color: var(--ifm-color-emphasis-600);
|
|
28
|
+
line-height: 0;
|
|
29
|
+
opacity: 0.7;
|
|
30
|
+
transition:
|
|
31
|
+
opacity 0.12s ease,
|
|
32
|
+
background-color 0.12s ease,
|
|
33
|
+
color 0.12s ease;
|
|
34
|
+
|
|
35
|
+
&:hover {
|
|
36
|
+
opacity: 1;
|
|
37
|
+
background-color: var(--ifm-color-emphasis-200);
|
|
38
|
+
color: var(--ifm-color-emphasis-900);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:focus-visible {
|
|
42
|
+
outline: 2px solid var(--ifm-color-primary);
|
|
43
|
+
outline-offset: 2px;
|
|
44
|
+
opacity: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
&[aria-expanded="true"] {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
background-color: var(--ifm-color-emphasis-200);
|
|
50
|
+
color: var(--ifm-color-emphasis-900);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.openapi-schema-expansion__popover {
|
|
55
|
+
position: fixed;
|
|
56
|
+
z-index: 1000;
|
|
57
|
+
display: inline-flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: 2px;
|
|
60
|
+
padding: 3px;
|
|
61
|
+
background-color: var(--ifm-background-surface-color);
|
|
62
|
+
border: 1px solid var(--ifm-color-emphasis-300);
|
|
63
|
+
border-radius: var(--ifm-global-radius);
|
|
64
|
+
box-shadow: var(--ifm-global-shadow-md);
|
|
65
|
+
white-space: nowrap;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.openapi-schema-expansion__option {
|
|
69
|
+
appearance: none;
|
|
70
|
+
background: transparent;
|
|
71
|
+
border: none;
|
|
72
|
+
border-radius: calc(var(--ifm-global-radius) - 2px);
|
|
73
|
+
padding: 2px 8px;
|
|
74
|
+
font-size: 0.8rem;
|
|
75
|
+
line-height: 1.4;
|
|
76
|
+
color: var(--ifm-color-emphasis-800);
|
|
77
|
+
transition:
|
|
78
|
+
background-color 0.12s ease,
|
|
79
|
+
color 0.12s ease;
|
|
80
|
+
|
|
81
|
+
&:hover {
|
|
82
|
+
background-color: var(--ifm-color-emphasis-200);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&:focus-visible {
|
|
86
|
+
outline: 2px solid var(--ifm-color-primary);
|
|
87
|
+
outline-offset: 1px;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.openapi-schema-expansion__option--active {
|
|
92
|
+
background-color: var(--ifm-color-primary);
|
|
93
|
+
color: var(--ifm-color-white);
|
|
94
|
+
|
|
95
|
+
&:hover {
|
|
96
|
+
background-color: var(--ifm-color-primary-dark);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.openapi-markdown__details-summary--with-control {
|
|
101
|
+
display: flex !important;
|
|
102
|
+
align-items: center;
|
|
103
|
+
gap: 0.5rem;
|
|
104
|
+
|
|
105
|
+
> h3,
|
|
106
|
+
> strong {
|
|
107
|
+
margin-bottom: 0;
|
|
108
|
+
display: inline-flex;
|
|
109
|
+
align-items: center;
|
|
110
|
+
flex-wrap: wrap;
|
|
111
|
+
gap: 0.4rem;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare const SCHEMA_EXPANSION_STORAGE_KEY = "docusaurus-openapi-schema-expansion-level";
|
|
3
|
+
export interface SchemaExpansionConfig {
|
|
4
|
+
enabled: boolean;
|
|
5
|
+
defaultLevel: number;
|
|
6
|
+
max: number;
|
|
7
|
+
persist: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface SchemaExpansionContextValue {
|
|
10
|
+
config: SchemaExpansionConfig;
|
|
11
|
+
level: number;
|
|
12
|
+
setLevel: (next: number) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function normalizeLevel(value: number | "all" | undefined): number;
|
|
15
|
+
export declare const SchemaExpansionProvider: React.FC<{
|
|
16
|
+
children: React.ReactNode;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const SchemaDepthProvider: React.FC<{
|
|
19
|
+
depth: number;
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}>;
|
|
22
|
+
export declare function useSchemaExpansion(): SchemaExpansionContextValue;
|
|
23
|
+
export declare function useSchemaDepth(): number;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* ============================================================================
|
|
3
|
+
* Copyright (c) Palo Alto Networks
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
var __createBinding =
|
|
9
|
+
(this && this.__createBinding) ||
|
|
10
|
+
(Object.create
|
|
11
|
+
? function (o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
14
|
+
if (
|
|
15
|
+
!desc ||
|
|
16
|
+
("get" in desc ? !m.__esModule : desc.writable || desc.configurable)
|
|
17
|
+
) {
|
|
18
|
+
desc = {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return m[k];
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
Object.defineProperty(o, k2, desc);
|
|
26
|
+
}
|
|
27
|
+
: function (o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
o[k2] = m[k];
|
|
30
|
+
});
|
|
31
|
+
var __setModuleDefault =
|
|
32
|
+
(this && this.__setModuleDefault) ||
|
|
33
|
+
(Object.create
|
|
34
|
+
? function (o, v) {
|
|
35
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
36
|
+
}
|
|
37
|
+
: function (o, v) {
|
|
38
|
+
o["default"] = v;
|
|
39
|
+
});
|
|
40
|
+
var __importStar =
|
|
41
|
+
(this && this.__importStar) ||
|
|
42
|
+
(function () {
|
|
43
|
+
var ownKeys = function (o) {
|
|
44
|
+
ownKeys =
|
|
45
|
+
Object.getOwnPropertyNames ||
|
|
46
|
+
function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o)
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
50
|
+
return ar;
|
|
51
|
+
};
|
|
52
|
+
return ownKeys(o);
|
|
53
|
+
};
|
|
54
|
+
return function (mod) {
|
|
55
|
+
if (mod && mod.__esModule) return mod;
|
|
56
|
+
var result = {};
|
|
57
|
+
if (mod != null)
|
|
58
|
+
for (var k = ownKeys(mod), i = 0; i < k.length; i++)
|
|
59
|
+
if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
60
|
+
__setModuleDefault(result, mod);
|
|
61
|
+
return result;
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
var __importDefault =
|
|
65
|
+
(this && this.__importDefault) ||
|
|
66
|
+
function (mod) {
|
|
67
|
+
return mod && mod.__esModule ? mod : { default: mod };
|
|
68
|
+
};
|
|
69
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
70
|
+
exports.SchemaDepthProvider =
|
|
71
|
+
exports.SchemaExpansionProvider =
|
|
72
|
+
exports.SCHEMA_EXPANSION_STORAGE_KEY =
|
|
73
|
+
void 0;
|
|
74
|
+
exports.normalizeLevel = normalizeLevel;
|
|
75
|
+
exports.useSchemaExpansion = useSchemaExpansion;
|
|
76
|
+
exports.useSchemaDepth = useSchemaDepth;
|
|
77
|
+
const react_1 = __importStar(require("react"));
|
|
78
|
+
const useDocusaurusContext_1 = __importDefault(
|
|
79
|
+
require("@docusaurus/useDocusaurusContext")
|
|
80
|
+
);
|
|
81
|
+
exports.SCHEMA_EXPANSION_STORAGE_KEY =
|
|
82
|
+
"docusaurus-openapi-schema-expansion-level";
|
|
83
|
+
const DEFAULT_CONFIG = {
|
|
84
|
+
enabled: false,
|
|
85
|
+
defaultLevel: 0,
|
|
86
|
+
max: 4,
|
|
87
|
+
persist: true,
|
|
88
|
+
};
|
|
89
|
+
const SchemaExpansionContext = (0, react_1.createContext)({
|
|
90
|
+
config: DEFAULT_CONFIG,
|
|
91
|
+
level: 0,
|
|
92
|
+
setLevel: () => {},
|
|
93
|
+
});
|
|
94
|
+
const SchemaDepthContext = (0, react_1.createContext)(0);
|
|
95
|
+
function normalizeLevel(value) {
|
|
96
|
+
if (value === "all") return Infinity;
|
|
97
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
|
|
98
|
+
return Math.floor(value);
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
function readConfig(themeConfig) {
|
|
103
|
+
const raw = themeConfig?.api?.schemaExpansion;
|
|
104
|
+
if (!raw) return DEFAULT_CONFIG;
|
|
105
|
+
const enabled = raw.enabled ?? false;
|
|
106
|
+
return {
|
|
107
|
+
enabled,
|
|
108
|
+
defaultLevel: normalizeLevel(raw.default),
|
|
109
|
+
max: typeof raw.max === "number" && raw.max > 0 ? Math.floor(raw.max) : 4,
|
|
110
|
+
// Persistence only matters when the reader can change the level via the
|
|
111
|
+
// UI control. When the control is hidden, fall back to the configured
|
|
112
|
+
// default on every visit so it isn't shadowed by a stale localStorage
|
|
113
|
+
// value from a session where the control used to be enabled.
|
|
114
|
+
persist: enabled ? (raw.persist ?? true) : false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function readPersistedLevel() {
|
|
118
|
+
if (typeof window === "undefined") return undefined;
|
|
119
|
+
try {
|
|
120
|
+
const stored = window.localStorage.getItem(
|
|
121
|
+
exports.SCHEMA_EXPANSION_STORAGE_KEY
|
|
122
|
+
);
|
|
123
|
+
if (stored === null) return undefined;
|
|
124
|
+
if (stored === "all") return Infinity;
|
|
125
|
+
const parsed = parseInt(stored, 10);
|
|
126
|
+
return Number.isFinite(parsed) && parsed >= 0 ? parsed : undefined;
|
|
127
|
+
} catch {
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function writePersistedLevel(level) {
|
|
132
|
+
if (typeof window === "undefined") return;
|
|
133
|
+
try {
|
|
134
|
+
const value = level === Infinity ? "all" : String(level);
|
|
135
|
+
window.localStorage.setItem(exports.SCHEMA_EXPANSION_STORAGE_KEY, value);
|
|
136
|
+
} catch {
|
|
137
|
+
// ignore quota / disabled storage
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const SchemaExpansionProvider = ({ children }) => {
|
|
141
|
+
const { siteConfig } = (0, useDocusaurusContext_1.default)();
|
|
142
|
+
const themeConfig = siteConfig.themeConfig;
|
|
143
|
+
const config = (0, react_1.useMemo)(
|
|
144
|
+
() => readConfig(themeConfig),
|
|
145
|
+
[themeConfig]
|
|
146
|
+
);
|
|
147
|
+
const [level, setLevelState] = (0, react_1.useState)(config.defaultLevel);
|
|
148
|
+
(0, react_1.useEffect)(() => {
|
|
149
|
+
if (!config.persist) return;
|
|
150
|
+
const persisted = readPersistedLevel();
|
|
151
|
+
if (persisted !== undefined) {
|
|
152
|
+
setLevelState(persisted);
|
|
153
|
+
}
|
|
154
|
+
}, [config.persist]);
|
|
155
|
+
const setLevel = (0, react_1.useCallback)(
|
|
156
|
+
(next) => {
|
|
157
|
+
setLevelState(next);
|
|
158
|
+
if (config.persist) {
|
|
159
|
+
writePersistedLevel(next);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
[config.persist]
|
|
163
|
+
);
|
|
164
|
+
const value = (0, react_1.useMemo)(
|
|
165
|
+
() => ({ config, level, setLevel }),
|
|
166
|
+
[config, level, setLevel]
|
|
167
|
+
);
|
|
168
|
+
return react_1.default.createElement(
|
|
169
|
+
SchemaExpansionContext.Provider,
|
|
170
|
+
{ value: value },
|
|
171
|
+
children
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
exports.SchemaExpansionProvider = SchemaExpansionProvider;
|
|
175
|
+
const SchemaDepthProvider = ({ depth, children }) =>
|
|
176
|
+
react_1.default.createElement(
|
|
177
|
+
SchemaDepthContext.Provider,
|
|
178
|
+
{ value: depth },
|
|
179
|
+
children
|
|
180
|
+
);
|
|
181
|
+
exports.SchemaDepthProvider = SchemaDepthProvider;
|
|
182
|
+
function useSchemaExpansion() {
|
|
183
|
+
return (0, react_1.useContext)(SchemaExpansionContext);
|
|
184
|
+
}
|
|
185
|
+
function useSchemaDepth() {
|
|
186
|
+
return (0, react_1.useContext)(SchemaDepthContext);
|
|
187
|
+
}
|