@gitbook/react-openapi 1.5.4 → 1.5.6
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/CHANGELOG.md +13 -0
- package/dist/InteractiveSection.js +52 -30
- package/dist/Markdown.js +5 -1
- package/dist/OpenAPICodeSample.js +45 -9
- package/dist/OpenAPICodeSampleInteractive.js +41 -15
- package/dist/OpenAPICodeSampleSelector.js +34 -14
- package/dist/OpenAPICopyButton.js +21 -15
- package/dist/OpenAPIDisclosure.js +18 -10
- package/dist/OpenAPIDisclosureGroup.js +56 -30
- package/dist/OpenAPIExample.js +6 -4
- package/dist/OpenAPIMediaType.js +38 -17
- package/dist/OpenAPIOperation.d.ts +2 -2
- package/dist/OpenAPIOperation.js +26 -12
- package/dist/OpenAPIOperationContext.d.ts +2 -2
- package/dist/OpenAPIOperationContext.js +5 -3
- package/dist/OpenAPIPath.js +14 -5
- package/dist/OpenAPIPathItem.js +26 -12
- package/dist/OpenAPIPathMultipleServers.js +29 -12
- package/dist/OpenAPIPrefillContextProvider.d.ts +2 -1
- package/dist/OpenAPIPrefillContextProvider.js +5 -3
- package/dist/OpenAPIRequestBody.js +20 -10
- package/dist/OpenAPIRequestBodyHeaderType.js +5 -3
- package/dist/OpenAPIRequiredScopes.js +41 -26
- package/dist/OpenAPIResponse.js +34 -19
- package/dist/OpenAPIResponseExample.js +25 -8
- package/dist/OpenAPIResponseExampleContent.js +39 -18
- package/dist/OpenAPIResponses.js +40 -17
- package/dist/OpenAPISchema.js +212 -88
- package/dist/OpenAPISchemaName.js +44 -24
- package/dist/OpenAPISchemaServer.js +10 -2
- package/dist/OpenAPISecurities.js +125 -57
- package/dist/OpenAPISelect.js +27 -18
- package/dist/OpenAPISpec.js +27 -12
- package/dist/OpenAPITooltip.js +14 -6
- package/dist/OpenAPIWebhook.d.ts +2 -2
- package/dist/OpenAPIWebhook.js +23 -11
- package/dist/OpenAPIWebhookExample.js +18 -8
- package/dist/ScalarApiButton.js +50 -29
- package/dist/StaticSection.js +49 -15
- package/dist/common/OpenAPIColumnSpec.js +21 -9
- package/dist/common/OpenAPIOperationDescription.js +12 -6
- package/dist/common/OpenAPIStability.js +6 -3
- package/dist/common/OpenAPISummary.js +23 -12
- package/dist/formatPath.js +7 -4
- package/dist/schemas/OpenAPISchemaItem.js +18 -11
- package/dist/schemas/OpenAPISchemas.d.ts +2 -2
- package/dist/schemas/OpenAPISchemas.js +55 -31
- package/dist/translate.js +4 -6
- package/dist/util/example.js +6 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,7 @@ import { Section, SectionBody, SectionHeader, SectionHeaderContent } from "./Sta
|
|
|
5
5
|
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from "./OpenAPISelect.js";
|
|
6
6
|
import clsx from "classnames";
|
|
7
7
|
import { useRef } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { mergeProps, useButton, useDisclosure, useFocusRing } from "react-aria";
|
|
9
10
|
import { useDisclosureState } from "react-stately";
|
|
10
11
|
|
|
@@ -23,36 +24,57 @@ function InteractiveSection(props) {
|
|
|
23
24
|
const { isFocusVisible, focusProps } = useFocusRing();
|
|
24
25
|
const store = useSelectState(stateKey, defaultTab);
|
|
25
26
|
const selectedTab = tabs.find((tab) => tab.key === store.key) ?? tabs[0];
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
27
|
+
return /* @__PURE__ */ jsxs(Section, {
|
|
28
|
+
id,
|
|
29
|
+
className: clsx("openapi-section", toggeable ? "openapi-section-toggeable" : null, className, toggeable ? `${className}-${state.isExpanded ? "opened" : "closed"}` : null),
|
|
30
|
+
children: [
|
|
31
|
+
header ? /* @__PURE__ */ jsxs(SectionHeader, {
|
|
32
|
+
onClick: () => {
|
|
33
|
+
if (toggeable) state.toggle();
|
|
34
|
+
},
|
|
35
|
+
className,
|
|
36
|
+
children: [/* @__PURE__ */ jsxs(SectionHeaderContent, {
|
|
37
|
+
className,
|
|
38
|
+
children: [selectedTab?.body && toggeable ? /* @__PURE__ */ jsx("button", {
|
|
39
|
+
...mergeProps(buttonProps, focusProps),
|
|
40
|
+
ref: triggerRef,
|
|
41
|
+
className: clsx("openapi-section-toggle", `${className}-toggle`),
|
|
42
|
+
style: { outline: isFocusVisible ? "2px solid rgb(var(--primary-color-500) / 0.4)" : "none" },
|
|
43
|
+
children: toggleIcon
|
|
44
|
+
}) : null, header]
|
|
45
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
46
|
+
className: clsx("openapi-section-header-controls", `${className}-header-controls`),
|
|
47
|
+
onClick: (event) => {
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
},
|
|
50
|
+
children: tabs.length > 0 ? /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
51
|
+
stateKey,
|
|
52
|
+
items: tabs,
|
|
53
|
+
onChange: () => {
|
|
54
|
+
state.expand();
|
|
55
|
+
},
|
|
56
|
+
icon: selectIcon,
|
|
57
|
+
placement: "bottom end",
|
|
58
|
+
children: tabs.map((tab) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
59
|
+
id: tab.key,
|
|
60
|
+
value: tab,
|
|
61
|
+
children: tab.label
|
|
62
|
+
}, tab.key))
|
|
63
|
+
}) : null
|
|
64
|
+
})]
|
|
65
|
+
}) : null,
|
|
66
|
+
(!toggeable || state.isExpanded) && selectedTab?.body ? /* @__PURE__ */ jsx(SectionBody, {
|
|
67
|
+
ref: panelRef,
|
|
68
|
+
...panelProps,
|
|
69
|
+
className,
|
|
70
|
+
children: selectedTab?.body
|
|
71
|
+
}) : null,
|
|
72
|
+
overlay ? /* @__PURE__ */ jsx("div", {
|
|
73
|
+
className: clsx("openapi-section-overlay", `${className}-overlay`),
|
|
74
|
+
children: overlay
|
|
75
|
+
}) : null
|
|
76
|
+
]
|
|
77
|
+
});
|
|
56
78
|
}
|
|
57
79
|
|
|
58
80
|
//#endregion
|
package/dist/Markdown.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import clsx from "classnames";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
3
|
|
|
3
4
|
//#region src/Markdown.tsx
|
|
4
5
|
function Markdown(props) {
|
|
5
6
|
const { source, className } = props;
|
|
6
|
-
return
|
|
7
|
+
return /* @__PURE__ */ jsx("div", {
|
|
8
|
+
className: clsx("openapi-markdown", className),
|
|
9
|
+
dangerouslySetInnerHTML: { __html: source }
|
|
10
|
+
});
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
//#endregion
|
|
@@ -8,6 +8,7 @@ import { OpenAPICodeSampleBody } from "./OpenAPICodeSampleSelector.js";
|
|
|
8
8
|
import { resolvePrefillCodePlaceholderFromSecurityScheme, resolveURLWithPrefillCodePlaceholdersFromServer } from "./util/tryit-prefill.js";
|
|
9
9
|
import { ScalarApiButton } from "./ScalarApiButton.js";
|
|
10
10
|
import { codeSampleGenerators, parseHostAndPath } from "./code-samples.js";
|
|
11
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
11
12
|
|
|
12
13
|
//#region src/OpenAPICodeSample.tsx
|
|
13
14
|
const CUSTOM_CODE_SAMPLES_KEYS = [
|
|
@@ -26,7 +27,12 @@ function OpenAPICodeSample(props) {
|
|
|
26
27
|
if (data["x-codeSamples"] === false && !customCodeSamples) return null;
|
|
27
28
|
const samples = customCodeSamples ?? generateCodeSamples(props);
|
|
28
29
|
if (samples.length === 0) return null;
|
|
29
|
-
return
|
|
30
|
+
return /* @__PURE__ */ jsx(OpenAPICodeSampleBody, {
|
|
31
|
+
context: getOpenAPIClientContext(context),
|
|
32
|
+
data,
|
|
33
|
+
items: samples,
|
|
34
|
+
selectIcon: context.icons.chevronDown
|
|
35
|
+
});
|
|
30
36
|
}
|
|
31
37
|
/**
|
|
32
38
|
* Generate code samples for the operation.
|
|
@@ -102,8 +108,17 @@ function generateCodeSamples(props) {
|
|
|
102
108
|
return {
|
|
103
109
|
key: `default-${generator.id}`,
|
|
104
110
|
label: generator.label,
|
|
105
|
-
body:
|
|
106
|
-
|
|
111
|
+
body: /* @__PURE__ */ jsx(OpenAPIMediaTypeExamplesBody, {
|
|
112
|
+
method: data.method,
|
|
113
|
+
path: data.path,
|
|
114
|
+
renderers,
|
|
115
|
+
blockKey: context.blockKey
|
|
116
|
+
}),
|
|
117
|
+
footer: /* @__PURE__ */ jsx(OpenAPICodeSampleFooter, {
|
|
118
|
+
renderers,
|
|
119
|
+
data,
|
|
120
|
+
context
|
|
121
|
+
})
|
|
107
122
|
};
|
|
108
123
|
}
|
|
109
124
|
return {
|
|
@@ -121,7 +136,11 @@ function generateCodeSamples(props) {
|
|
|
121
136
|
}),
|
|
122
137
|
syntax: generator.syntax
|
|
123
138
|
}),
|
|
124
|
-
footer:
|
|
139
|
+
footer: /* @__PURE__ */ jsx(OpenAPICodeSampleFooter, {
|
|
140
|
+
data,
|
|
141
|
+
renderers: [],
|
|
142
|
+
context
|
|
143
|
+
})
|
|
125
144
|
};
|
|
126
145
|
});
|
|
127
146
|
}
|
|
@@ -133,10 +152,23 @@ function OpenAPICodeSampleFooter(props) {
|
|
|
133
152
|
const hasMultipleMediaTypes = renderers.length > 1 || renderers.some((renderer) => renderer.examples.length > 0);
|
|
134
153
|
if (hideTryItPanel && !hasMultipleMediaTypes) return null;
|
|
135
154
|
if (!validateHttpMethod(method) || !hasMultipleMediaTypes && servers.length === 0) return null;
|
|
136
|
-
return
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
155
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
156
|
+
className: "openapi-codesample-footer",
|
|
157
|
+
children: [hasMultipleMediaTypes ? /* @__PURE__ */ jsx(OpenAPIMediaTypeExamplesSelector, {
|
|
158
|
+
method: data.method,
|
|
159
|
+
path: data.path,
|
|
160
|
+
renderers,
|
|
161
|
+
selectIcon: context.icons.chevronDown,
|
|
162
|
+
blockKey: context.blockKey
|
|
163
|
+
}) : /* @__PURE__ */ jsx("span", {}), !hideTryItPanel && servers.length > 0 && /* @__PURE__ */ jsx(ScalarApiButton, {
|
|
164
|
+
context: getOpenAPIClientContext(context),
|
|
165
|
+
method,
|
|
166
|
+
path,
|
|
167
|
+
securities,
|
|
168
|
+
servers,
|
|
169
|
+
specUrl
|
|
170
|
+
})]
|
|
171
|
+
});
|
|
140
172
|
}
|
|
141
173
|
/**
|
|
142
174
|
* Get custom code samples for the operation.
|
|
@@ -155,7 +187,11 @@ function getCustomCodeSamples(props) {
|
|
|
155
187
|
code: sample.source,
|
|
156
188
|
syntax: sample.lang
|
|
157
189
|
}),
|
|
158
|
-
footer:
|
|
190
|
+
footer: /* @__PURE__ */ jsx(OpenAPICodeSampleFooter, {
|
|
191
|
+
renderers: [],
|
|
192
|
+
data,
|
|
193
|
+
context
|
|
194
|
+
})
|
|
159
195
|
}));
|
|
160
196
|
});
|
|
161
197
|
return customCodeSamples;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { createStateKey } from "./utils.js";
|
|
5
5
|
import { OpenAPISelect, OpenAPISelectItem, useSelectState } from "./OpenAPISelect.js";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
|
|
7
8
|
//#region src/OpenAPICodeSampleInteractive.tsx
|
|
8
9
|
function OpenAPIMediaTypeExamplesSelector(props) {
|
|
@@ -11,10 +12,19 @@ function OpenAPIMediaTypeExamplesSelector(props) {
|
|
|
11
12
|
const stateKey = createStateKey("request-body-media-type", blockKey);
|
|
12
13
|
const state = useSelectState(stateKey, renderers[0].mediaType);
|
|
13
14
|
const selected = renderers.find((r) => r.mediaType === state.key) || renderers[0];
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
16
|
+
className: "openapi-codesample-selectors",
|
|
17
|
+
children: [/* @__PURE__ */ jsx(MediaTypeSelector, {
|
|
18
|
+
selectIcon,
|
|
19
|
+
stateKey,
|
|
20
|
+
renderers
|
|
21
|
+
}), /* @__PURE__ */ jsx(ExamplesSelector, {
|
|
22
|
+
selectIcon,
|
|
23
|
+
method,
|
|
24
|
+
path,
|
|
25
|
+
renderer: selected
|
|
26
|
+
})]
|
|
27
|
+
});
|
|
18
28
|
}
|
|
19
29
|
function MediaTypeSelector(props) {
|
|
20
30
|
const { renderers, stateKey, selectIcon } = props;
|
|
@@ -23,11 +33,17 @@ function MediaTypeSelector(props) {
|
|
|
23
33
|
key: renderer.mediaType,
|
|
24
34
|
label: renderer.mediaType
|
|
25
35
|
}));
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
return /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
37
|
+
items,
|
|
38
|
+
icon: selectIcon,
|
|
39
|
+
stateKey,
|
|
40
|
+
placement: "bottom start",
|
|
41
|
+
children: items.map((item) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
42
|
+
id: item.key,
|
|
43
|
+
value: item,
|
|
44
|
+
children: item.label
|
|
45
|
+
}, item.key))
|
|
46
|
+
});
|
|
31
47
|
}
|
|
32
48
|
function ExamplesSelector(props) {
|
|
33
49
|
const { method, path, renderer, selectIcon } = props;
|
|
@@ -36,11 +52,17 @@ function ExamplesSelector(props) {
|
|
|
36
52
|
key: index,
|
|
37
53
|
label: example.example.summary || `Example ${index + 1}`
|
|
38
54
|
}));
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
55
|
+
return /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
56
|
+
items,
|
|
57
|
+
icon: selectIcon,
|
|
58
|
+
stateKey: `media-type-sample-${renderer.mediaType}-${method}-${path}`,
|
|
59
|
+
placement: "bottom start",
|
|
60
|
+
children: items.map((item) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
61
|
+
id: item.key,
|
|
62
|
+
value: item,
|
|
63
|
+
children: item.label
|
|
64
|
+
}, item.key))
|
|
65
|
+
});
|
|
44
66
|
}
|
|
45
67
|
function OpenAPIMediaTypeExamplesBody(props) {
|
|
46
68
|
const { renderers, method, path, blockKey } = props;
|
|
@@ -48,7 +70,11 @@ function OpenAPIMediaTypeExamplesBody(props) {
|
|
|
48
70
|
const mediaTypeState = useSelectState(createStateKey("request-body-media-type", blockKey), renderers[0].mediaType);
|
|
49
71
|
const selected = renderers.find((r) => r.mediaType === mediaTypeState.key) ?? renderers[0];
|
|
50
72
|
if (selected.examples.length === 0) return selected.element;
|
|
51
|
-
return
|
|
73
|
+
return /* @__PURE__ */ jsx(ExamplesBody, {
|
|
74
|
+
method,
|
|
75
|
+
path,
|
|
76
|
+
renderer: selected
|
|
77
|
+
});
|
|
52
78
|
}
|
|
53
79
|
function ExamplesBody(props) {
|
|
54
80
|
const { method, path, renderer } = props;
|
|
@@ -6,6 +6,7 @@ import { getOrCreateStoreByKey } from "./getOrCreateStoreByKey.js";
|
|
|
6
6
|
import { OpenAPISelect, OpenAPISelectItem } from "./OpenAPISelect.js";
|
|
7
7
|
import { OpenAPIPath } from "./OpenAPIPath.js";
|
|
8
8
|
import { useCallback } from "react";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import { useStore } from "zustand";
|
|
10
11
|
|
|
11
12
|
//#region src/OpenAPICodeSampleSelector.tsx
|
|
@@ -18,14 +19,25 @@ function useCodeSampleState(initialKey = "default") {
|
|
|
18
19
|
}
|
|
19
20
|
function OpenAPICodeSampleHeader(props) {
|
|
20
21
|
const { data, items, selectIcon, context } = props;
|
|
21
|
-
return
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(OpenAPIPath, {
|
|
23
|
+
context,
|
|
24
|
+
canCopy: false,
|
|
25
|
+
withServer: false,
|
|
26
|
+
data
|
|
27
|
+
}), items.length > 1 ? /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
28
|
+
icon: selectIcon,
|
|
29
|
+
items,
|
|
30
|
+
stateKey: "codesample",
|
|
31
|
+
placement: "bottom end",
|
|
32
|
+
children: items.map((item) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
33
|
+
id: item.key,
|
|
34
|
+
value: item,
|
|
35
|
+
children: item.label
|
|
36
|
+
}, item.key))
|
|
37
|
+
}) : items[0] ? /* @__PURE__ */ jsx("span", {
|
|
38
|
+
className: "openapi-codesample-label",
|
|
39
|
+
children: items[0].label
|
|
40
|
+
}) : null] });
|
|
29
41
|
}
|
|
30
42
|
function OpenAPICodeSampleBody(props) {
|
|
31
43
|
const { items, data, selectIcon, context } = props;
|
|
@@ -33,12 +45,20 @@ function OpenAPICodeSampleBody(props) {
|
|
|
33
45
|
const state = useCodeSampleState(items[0]?.key);
|
|
34
46
|
const selected = items.find((item) => item.key === state.key) || items[0];
|
|
35
47
|
if (!selected) return null;
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
return /* @__PURE__ */ jsx(StaticSection, {
|
|
49
|
+
header: /* @__PURE__ */ jsx(OpenAPICodeSampleHeader, {
|
|
50
|
+
context,
|
|
51
|
+
selectIcon,
|
|
52
|
+
data,
|
|
53
|
+
items
|
|
54
|
+
}),
|
|
55
|
+
className: "openapi-codesample",
|
|
56
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
57
|
+
id: selected.key,
|
|
58
|
+
className: "openapi-codesample-panel",
|
|
59
|
+
children: [selected.body ? selected.body : null, selected.footer ? selected.footer : null]
|
|
60
|
+
})
|
|
61
|
+
});
|
|
42
62
|
}
|
|
43
63
|
|
|
44
64
|
//#endregion
|
|
@@ -5,6 +5,7 @@ import { t } from "./translate.js";
|
|
|
5
5
|
import { OpenAPITooltip } from "./OpenAPITooltip.js";
|
|
6
6
|
import clsx from "classnames";
|
|
7
7
|
import { useState } from "react";
|
|
8
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { Button } from "react-aria-components";
|
|
9
10
|
|
|
10
11
|
//#region src/OpenAPICopyButton.tsx
|
|
@@ -23,21 +24,26 @@ function OpenAPICopyButton(props) {
|
|
|
23
24
|
}, 2e3);
|
|
24
25
|
});
|
|
25
26
|
};
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
return /* @__PURE__ */ jsxs(OpenAPITooltip, {
|
|
28
|
+
isDisabled: !withTooltip,
|
|
29
|
+
isOpen,
|
|
30
|
+
onOpenChange: setIsOpen,
|
|
31
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
32
|
+
type: "button",
|
|
33
|
+
preventFocusOnPress: true,
|
|
34
|
+
onPress: (e) => {
|
|
35
|
+
handleCopy();
|
|
36
|
+
onPress?.(e);
|
|
37
|
+
},
|
|
38
|
+
className: clsx("openapi-copy-button", className),
|
|
39
|
+
...props,
|
|
40
|
+
children
|
|
41
|
+
}), /* @__PURE__ */ jsx(OpenAPITooltip.Content, {
|
|
42
|
+
isOpen,
|
|
43
|
+
onOpenChange: setIsOpen,
|
|
44
|
+
children: copied ? /* @__PURE__ */ jsxs(Fragment$1, { children: [context.icons.check, t(context.translation, "copied")] }) : label || t(context.translation, "copy_to_clipboard")
|
|
45
|
+
})]
|
|
46
|
+
});
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
//#endregion
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import clsx from "classnames";
|
|
5
5
|
import { useState } from "react";
|
|
6
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
7
|
import { Button, Disclosure, DisclosurePanel } from "react-aria-components";
|
|
7
8
|
|
|
8
9
|
//#region src/OpenAPIDisclosure.tsx
|
|
@@ -12,16 +13,23 @@ import { Button, Disclosure, DisclosurePanel } from "react-aria-components";
|
|
|
12
13
|
function OpenAPIDisclosure(props) {
|
|
13
14
|
const { icon, header, label, children, className, defaultExpanded = false } = props;
|
|
14
15
|
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
return /* @__PURE__ */ jsxs(Disclosure, {
|
|
17
|
+
className: clsx("openapi-disclosure", className),
|
|
18
|
+
isExpanded,
|
|
19
|
+
onExpandedChange: setIsExpanded,
|
|
20
|
+
children: [/* @__PURE__ */ jsxs(Button, {
|
|
21
|
+
slot: "trigger",
|
|
22
|
+
className: "openapi-disclosure-trigger",
|
|
23
|
+
style: ({ isFocusVisible }) => ({ outline: isFocusVisible ? "2px solid rgb(var(--primary-color-500) / 0.4)" : "none" }),
|
|
24
|
+
children: [header, /* @__PURE__ */ jsxs("div", {
|
|
25
|
+
className: "openapi-disclosure-trigger-label",
|
|
26
|
+
children: [label ? /* @__PURE__ */ jsx("span", { children: typeof label === "function" ? label(isExpanded) : label }) : null, icon]
|
|
27
|
+
})]
|
|
28
|
+
}), isExpanded ? /* @__PURE__ */ jsx(DisclosurePanel, {
|
|
29
|
+
className: "openapi-disclosure-panel",
|
|
30
|
+
children
|
|
31
|
+
}) : null]
|
|
32
|
+
});
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
//#endregion
|
|
@@ -5,6 +5,7 @@ import { OpenAPISelect, OpenAPISelectItem, useSelectState } from "./OpenAPISelec
|
|
|
5
5
|
import { getOrCreateDisclosureStoreByKey } from "./getOrCreateDisclosureStoreByKey.js";
|
|
6
6
|
import clsx from "classnames";
|
|
7
7
|
import { createContext, useContext, useRef } from "react";
|
|
8
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
9
|
import { useStore } from "zustand";
|
|
9
10
|
import { mergeProps, useButton, useDisclosure, useFocusRing, useId as useId$1 } from "react-aria";
|
|
10
11
|
import { useDisclosureGroupState, useDisclosureState } from "react-stately";
|
|
@@ -28,9 +29,16 @@ function OpenAPIDisclosureGroup(props) {
|
|
|
28
29
|
onExpandedChange?.(keys);
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
return /* @__PURE__ */ jsx(DisclosureGroupStateContext.Provider, {
|
|
33
|
+
value: state,
|
|
34
|
+
children: groups.map((group) => /* @__PURE__ */ jsx(DisclosureItem, {
|
|
35
|
+
className,
|
|
36
|
+
selectStateKey,
|
|
37
|
+
selectIcon,
|
|
38
|
+
icon,
|
|
39
|
+
group
|
|
40
|
+
}, group.key))
|
|
41
|
+
});
|
|
34
42
|
}
|
|
35
43
|
function DisclosureItem(props) {
|
|
36
44
|
const { icon, group, selectStateKey, selectIcon, className } = props;
|
|
@@ -56,33 +64,51 @@ function DisclosureItem(props) {
|
|
|
56
64
|
const { isFocusVisible, focusProps } = useFocusRing();
|
|
57
65
|
const store = useSelectState(selectStateKey, group.tabs?.[0]?.key || "");
|
|
58
66
|
const selectedTab = group.tabs?.find((tab) => tab.key === store.key) || group.tabs?.[0];
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
68
|
+
className: clsx("openapi-disclosure-group", className),
|
|
69
|
+
"aria-expanded": state.isExpanded,
|
|
70
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
71
|
+
slot: "trigger",
|
|
72
|
+
ref: triggerRef,
|
|
73
|
+
...mergeProps(buttonProps, focusProps),
|
|
74
|
+
"aria-disabled": isDisabled,
|
|
75
|
+
style: { outline: isFocusVisible ? "2px solid rgb(var(--primary-color-500)/0.4)" : "none" },
|
|
76
|
+
className: "openapi-disclosure-group-trigger",
|
|
77
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
78
|
+
className: "openapi-disclosure-group-icon",
|
|
79
|
+
children: icon || /* @__PURE__ */ jsx("svg", {
|
|
80
|
+
viewBox: "0 0 24 24",
|
|
81
|
+
className: "openapi-disclosure-group-icon",
|
|
82
|
+
children: /* @__PURE__ */ jsx("path", { d: "m8.25 4.5 7.5 7.5-7.5 7.5" })
|
|
83
|
+
})
|
|
84
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
85
|
+
className: "openapi-disclosure-group-label",
|
|
86
|
+
children: [group.label, group.tabs ? /* @__PURE__ */ jsx("div", {
|
|
87
|
+
className: "openapi-disclosure-group-mediatype",
|
|
88
|
+
onClick: (e) => e.stopPropagation(),
|
|
89
|
+
children: group.tabs?.length > 1 ? /* @__PURE__ */ jsx(OpenAPISelect, {
|
|
90
|
+
icon: selectIcon,
|
|
91
|
+
stateKey: selectStateKey,
|
|
92
|
+
onChange: () => {
|
|
93
|
+
state.expand();
|
|
94
|
+
},
|
|
95
|
+
items: group.tabs,
|
|
96
|
+
placement: "bottom end",
|
|
97
|
+
children: group.tabs.map((tab) => /* @__PURE__ */ jsx(OpenAPISelectItem, {
|
|
98
|
+
id: tab.key,
|
|
99
|
+
value: tab,
|
|
100
|
+
children: tab.label
|
|
101
|
+
}, tab.key))
|
|
102
|
+
}) : group.tabs[0]?.label ? /* @__PURE__ */ jsx("span", { children: group.tabs[0].label }) : null
|
|
103
|
+
}) : null]
|
|
104
|
+
})]
|
|
105
|
+
}), state.isExpanded && selectedTab && /* @__PURE__ */ jsx("div", {
|
|
106
|
+
className: "openapi-disclosure-group-panel",
|
|
107
|
+
ref: panelRef,
|
|
108
|
+
...panelProps,
|
|
109
|
+
children: selectedTab.body
|
|
110
|
+
})]
|
|
111
|
+
});
|
|
86
112
|
}
|
|
87
113
|
|
|
88
114
|
//#endregion
|
package/dist/OpenAPIExample.js
CHANGED
|
@@ -2,6 +2,7 @@ import { json2xml } from "./json2xml.js";
|
|
|
2
2
|
import { stringifyOpenAPI } from "./stringifyOpenAPI.js";
|
|
3
3
|
import { t } from "./translate.js";
|
|
4
4
|
import yaml from "js-yaml";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
|
|
6
7
|
//#region src/OpenAPIExample.tsx
|
|
7
8
|
/**
|
|
@@ -13,7 +14,7 @@ function OpenAPIExample(props) {
|
|
|
13
14
|
example,
|
|
14
15
|
syntax
|
|
15
16
|
});
|
|
16
|
-
if (code === null) return
|
|
17
|
+
if (code === null) return /* @__PURE__ */ jsx(OpenAPIEmptyExample, { context });
|
|
17
18
|
return context.renderCodeBlock({
|
|
18
19
|
code,
|
|
19
20
|
syntax
|
|
@@ -32,9 +33,10 @@ function stringifyExample(args) {
|
|
|
32
33
|
*/
|
|
33
34
|
function OpenAPIEmptyExample(props) {
|
|
34
35
|
const { context } = props;
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
return /* @__PURE__ */ jsx("pre", {
|
|
37
|
+
className: "openapi-example-empty",
|
|
38
|
+
children: /* @__PURE__ */ jsx("p", { children: t(context.translation, "no_content") })
|
|
39
|
+
});
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
//#endregion
|