fumadocs-openapi 10.9.1 → 10.10.1
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/css/generated/shared.css +61 -45
- package/dist/_openapi/types.d.ts +27 -1
- package/dist/index.d.ts +5 -4
- package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.js +1 -1
- package/dist/playground/client.d.ts +1 -1
- package/dist/requests/generators/all.d.ts +1 -1
- package/dist/requests/generators/all.js +1 -0
- package/dist/scalar/client.js +1 -4
- package/dist/types.d.ts +3 -16
- package/dist/ui/base.d.ts +2 -1
- package/dist/ui/base.js +4 -19
- package/dist/ui/client/index.d.ts +15 -10
- package/dist/ui/components/accordion.js +36 -11
- package/dist/ui/components/dialog.js +29 -32
- package/dist/ui/components/heading.js +22 -0
- package/dist/ui/components/select-tab.js +24 -9
- package/dist/ui/contexts/api.js +1 -7
- package/dist/ui/create-client.d.ts +2 -1
- package/dist/ui/create-client.js +8 -26
- package/dist/ui/operation/client.js +1 -1
- package/dist/ui/operation/index.js +145 -141
- package/dist/ui/operation/request-tabs.js +4 -1
- package/dist/ui/operation/response-tabs.js +4 -1
- package/dist/ui/operation/usage-tabs/index.js +2 -8
- package/dist/ui/schema/client.js +339 -289
- package/dist/utils/auto-anchor.client.js +20 -0
- package/dist/utils/auto-anchor.js +17 -0
- package/dist/utils/merge-refs.js +11 -0
- package/dist/utils/pages/builder.d.ts +2 -4
- package/dist/utils/pages/preset-auto.d.ts +1 -2
- package/package.json +5 -6
package/dist/types.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { MediaAdapter } from "./requests/media/adapter.js";
|
|
2
1
|
import { InlineCodeUsageGenerator } from "./requests/generators/index.js";
|
|
3
2
|
import { boundary_d_exports } from "./ui/client/boundary.js";
|
|
4
|
-
import {
|
|
3
|
+
import { OpenAPIV3_2 } from "./_openapi/types.js";
|
|
5
4
|
import { CreateAPIPageOptions } from "./ui/base.js";
|
|
6
5
|
import { OpenAPIOptions } from "./server/index.js";
|
|
7
6
|
import { NoReference } from "./utils/schema/index.js";
|
|
8
7
|
import { DereferencedDocument } from "./utils/document/dereference.js";
|
|
9
|
-
import { HTMLAttributes, ReactNode } from "react";
|
|
10
8
|
|
|
11
9
|
//#region src/types.d.ts
|
|
12
10
|
type Document = OpenAPIV3_2.Document;
|
|
@@ -17,14 +15,8 @@ type ReferenceObject = OpenAPIV3_2.ReferenceObject;
|
|
|
17
15
|
type PathItemObject = OpenAPIV3_2.PathItemObject;
|
|
18
16
|
type TagObject = OpenAPIV3_2.TagObject;
|
|
19
17
|
type ServerObject = OpenAPIV3_2.ServerObject;
|
|
20
|
-
type CallbackObject = OpenAPIV3_2.CallbackObject;
|
|
21
|
-
type ServerVariableObject = OpenAPIV3.ServerVariableObject;
|
|
22
18
|
type ResponseObject = OpenAPIV3_2.ResponseObject;
|
|
23
|
-
type OAuth2SecurityScheme = OpenAPIV3_2.OAuth2SecurityScheme;
|
|
24
19
|
type HttpMethods = OpenAPIV3_2.HttpMethods;
|
|
25
|
-
type ExampleObject = OpenAPIV3_2.ExampleObject;
|
|
26
|
-
type MediaTypeObject = OpenAPIV3_2.MediaTypeObject;
|
|
27
|
-
type RequestBodyObject = OpenAPIV3_2.RequestBodyObject;
|
|
28
20
|
type MethodInformation = NoReference<OperationObject> & {
|
|
29
21
|
method: HttpMethods;
|
|
30
22
|
'x-codeSamples'?: InlineCodeUsageGenerator[];
|
|
@@ -32,19 +24,14 @@ type MethodInformation = NoReference<OperationObject> & {
|
|
|
32
24
|
'x-exclusiveCodeSample'?: string;
|
|
33
25
|
};
|
|
34
26
|
type RequireKeys<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
35
|
-
interface RenderContext extends Pick<OpenAPIOptions, 'proxyUrl'>, Omit<RequireKeys<CreateAPIPageOptions, 'renderMarkdown' | 'generateTypeScriptDefinitions'
|
|
27
|
+
interface RenderContext extends Pick<OpenAPIOptions, 'proxyUrl'>, Omit<RequireKeys<CreateAPIPageOptions, 'renderMarkdown' | 'generateTypeScriptDefinitions' | 'renderCodeBlock' | 'mediaAdapters' | 'codeUsages'>, 'renderHeading' | 'generateTypeScriptSchema'> {
|
|
36
28
|
/**
|
|
37
29
|
* dereferenced schema
|
|
38
30
|
*/
|
|
39
31
|
schema: DereferencedDocument;
|
|
40
32
|
clientBoundary: typeof boundary_d_exports;
|
|
41
|
-
mediaAdapters: Record<string, MediaAdapter>;
|
|
42
|
-
renderHeading: (depth: number, text: string | ReactNode, props?: HTMLAttributes<HTMLHeadingElement> & {
|
|
43
|
-
id?: string;
|
|
44
|
-
}) => ReactNode;
|
|
45
|
-
renderCodeBlock: (lang: string, code: string) => ReactNode;
|
|
46
33
|
}
|
|
47
34
|
type DistributiveOmit<T, K extends PropertyKey> = T extends unknown ? Omit<T, K> : never;
|
|
48
35
|
type Awaitable<T> = T | Promise<T>;
|
|
49
36
|
//#endregion
|
|
50
|
-
export { Awaitable,
|
|
37
|
+
export { Awaitable, DistributiveOmit, Document, HttpMethods, MethodInformation, OperationObject, ParameterObject, PathItemObject, ReferenceObject, RenderContext, ResponseObject, SecuritySchemeObject, ServerObject, TagObject };
|
package/dist/ui/base.d.ts
CHANGED
|
@@ -147,10 +147,11 @@ interface CreateAPIPageOptions {
|
|
|
147
147
|
children: ReactNode;
|
|
148
148
|
}) => ReactNode;
|
|
149
149
|
/**
|
|
150
|
-
* replace the
|
|
150
|
+
* replace the renderer
|
|
151
151
|
*/
|
|
152
152
|
render?: (props: APIPlaygroundProps) => ReactNode;
|
|
153
153
|
};
|
|
154
|
+
/** @deprecated no longer used */
|
|
154
155
|
renderHeading?: (props: HTMLAttributes<HTMLHeadingElement>, depth: number) => ReactNode;
|
|
155
156
|
renderCodeBlock?: (props: {
|
|
156
157
|
lang: string;
|
package/dist/ui/base.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { parseSecurities } from "../utils/schema/index.js";
|
|
2
2
|
import { defaultAdapters } from "../requests/media/adapter.js";
|
|
3
|
+
import { createCodeUsageGeneratorRegistry } from "../requests/generators/index.js";
|
|
4
|
+
import { registerDefault } from "../requests/generators/all.js";
|
|
3
5
|
import { ClientCodeBlockProvider } from "./components/codeblock.js";
|
|
4
6
|
import { encodeInternalRef } from "../utils/schema/ref.js";
|
|
5
7
|
import { APIPage } from "./api-page.js";
|
|
6
8
|
import { pickSchema } from "../utils/schema/pick.js";
|
|
7
9
|
import { PlaygroundAuthProvider } from "./client/boundary.lazy.js";
|
|
8
|
-
import Slugger from "github-slugger";
|
|
9
10
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
10
11
|
import { jsx } from "react/jsx-runtime";
|
|
11
|
-
import { Heading } from "fumadocs-ui/components/heading";
|
|
12
12
|
import { createRehypeCode } from "fumadocs-core/mdx-plugins/rehype-code.core";
|
|
13
13
|
import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
|
|
14
14
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
@@ -62,7 +62,6 @@ function createAPIPage(server, options) {
|
|
|
62
62
|
let processed;
|
|
63
63
|
if (typeof document === "string") processed = await server.getSchema(document);
|
|
64
64
|
else processed = document;
|
|
65
|
-
const slugger = new Slugger();
|
|
66
65
|
const { ApiProvider, PlaygroundClient, SchemaUI, ServerProvider, UsageTab, UsageTabsSelector } = await import("./client/boundary.lazy.js");
|
|
67
66
|
const ctx = {
|
|
68
67
|
schema: processed,
|
|
@@ -76,6 +75,7 @@ function createAPIPage(server, options) {
|
|
|
76
75
|
UsageTabsSelector
|
|
77
76
|
},
|
|
78
77
|
...options,
|
|
78
|
+
codeUsages: options.codeUsages ?? registerDefault(createCodeUsageGeneratorRegistry()),
|
|
79
79
|
mediaAdapters: {
|
|
80
80
|
...defaultAdapters,
|
|
81
81
|
...options.mediaAdapters
|
|
@@ -85,21 +85,6 @@ function createAPIPage(server, options) {
|
|
|
85
85
|
provider: options.playground?.provider ?? renderPlaygroundProviderDefault,
|
|
86
86
|
render: options.playground?.render ?? renderPlaygroundDefault
|
|
87
87
|
},
|
|
88
|
-
renderHeading(depth, text, props) {
|
|
89
|
-
const id = typeof text === "string" ? slugger.slug(text) : props?.id;
|
|
90
|
-
if (!id) throw new Error("missing 'id' for non-string children");
|
|
91
|
-
if (options.renderHeading) return options.renderHeading({
|
|
92
|
-
id,
|
|
93
|
-
children: text,
|
|
94
|
-
...props
|
|
95
|
-
}, depth);
|
|
96
|
-
return /* @__PURE__ */ jsx(Heading, {
|
|
97
|
-
id,
|
|
98
|
-
as: `h${depth}`,
|
|
99
|
-
...props,
|
|
100
|
-
children: text
|
|
101
|
-
}, id);
|
|
102
|
-
},
|
|
103
88
|
generateTypeScriptDefinitions: options.generateTypeScriptDefinitions ?? ((schema, ctx) => {
|
|
104
89
|
if (options.generateTypeScriptSchema && ctx._internal_legacy) {
|
|
105
90
|
const { statusCode, contentType } = ctx._internal_legacy;
|
|
@@ -122,7 +107,7 @@ function createAPIPage(server, options) {
|
|
|
122
107
|
processor ??= createMarkdownProcessor();
|
|
123
108
|
return (await processor.process({ value: text })).result;
|
|
124
109
|
},
|
|
125
|
-
async renderCodeBlock(lang, code) {
|
|
110
|
+
async renderCodeBlock({ lang, code }) {
|
|
126
111
|
if (options.renderCodeBlock) return options.renderCodeBlock({
|
|
127
112
|
lang,
|
|
128
113
|
code
|
|
@@ -2,12 +2,24 @@ import { MediaAdapter } from "../../requests/media/adapter.js";
|
|
|
2
2
|
import { PlaygroundClientOptions } from "../../playground/client.js";
|
|
3
3
|
import { CodeUsageGeneratorRegistry } from "../../requests/generators/index.js";
|
|
4
4
|
import { ExampleRequestItem } from "../operation/get-example-requests.js";
|
|
5
|
-
import { FC } from "react";
|
|
5
|
+
import { ComponentProps, FC } from "react";
|
|
6
6
|
|
|
7
7
|
//#region src/ui/client/index.d.ts
|
|
8
8
|
interface APIPageClientOptions {
|
|
9
9
|
playground?: PlaygroundClientOptions;
|
|
10
|
-
operation?:
|
|
10
|
+
operation?: {
|
|
11
|
+
APIExampleSelector?: FC<{
|
|
12
|
+
items: ExampleRequestItem[];
|
|
13
|
+
value: string | undefined;
|
|
14
|
+
onValueChange: (id: string) => void;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
components?: {
|
|
18
|
+
Heading?: FC<ComponentProps<'h1'> & {
|
|
19
|
+
id: string;
|
|
20
|
+
depth: number;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
11
23
|
/**
|
|
12
24
|
* Set a prefix for `localStorage` keys.
|
|
13
25
|
*
|
|
@@ -25,13 +37,6 @@ interface APIPageClientOptions {
|
|
|
25
37
|
*/
|
|
26
38
|
codeUsages?: CodeUsageGeneratorRegistry;
|
|
27
39
|
}
|
|
28
|
-
interface OperationClientOptions {
|
|
29
|
-
APIExampleSelector?: FC<{
|
|
30
|
-
items: ExampleRequestItem[];
|
|
31
|
-
value: string | undefined;
|
|
32
|
-
onValueChange: (id: string) => void;
|
|
33
|
-
}>;
|
|
34
|
-
}
|
|
35
40
|
declare function defineClientConfig(options?: APIPageClientOptions): APIPageClientOptions;
|
|
36
41
|
//#endregion
|
|
37
|
-
export { APIPageClientOptions,
|
|
42
|
+
export { APIPageClientOptions, defineClientConfig };
|
|
@@ -1,27 +1,52 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../../utils/cn.js";
|
|
3
|
+
import { anchorIdStartsWith } from "../../utils/auto-anchor.js";
|
|
4
|
+
import { AnchorSection, useAnchorId } from "../../utils/auto-anchor.client.js";
|
|
5
|
+
import { createContext, use, useEffect, useMemo, useState } from "react";
|
|
3
6
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
7
|
import { ChevronRight } from "lucide-react";
|
|
5
8
|
import * as Primitive from "@radix-ui/react-accordion";
|
|
6
9
|
//#region src/ui/components/accordion.tsx
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const Context = createContext(null);
|
|
11
|
+
function Accordions({ type, defaultValue, ...props }) {
|
|
12
|
+
const [value, setValue] = useState(() => type === "multiple" ? defaultValue ?? [] : defaultValue ?? "");
|
|
13
|
+
return /* @__PURE__ */ jsx(Context, {
|
|
14
|
+
value: useMemo(() => ({
|
|
15
|
+
type,
|
|
16
|
+
setValue
|
|
17
|
+
}), [type]),
|
|
18
|
+
children: /* @__PURE__ */ jsx(Primitive.Root, {
|
|
19
|
+
type,
|
|
20
|
+
value,
|
|
21
|
+
onValueChange: setValue,
|
|
22
|
+
...props
|
|
23
|
+
})
|
|
11
24
|
});
|
|
12
25
|
}
|
|
13
|
-
function AccordionItem(props) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
26
|
+
function AccordionItem({ value, className, anchorSegments, ...props }) {
|
|
27
|
+
const ctx = use(Context);
|
|
28
|
+
const id = useAnchorId(anchorSegments ?? false);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (id && anchorIdStartsWith(window.location.hash.slice(1), id)) ctx.setValue(ctx.type === "single" ? value : [value]);
|
|
31
|
+
}, [
|
|
32
|
+
value,
|
|
33
|
+
id,
|
|
34
|
+
ctx
|
|
35
|
+
]);
|
|
36
|
+
const content = /* @__PURE__ */ jsx(Primitive.Item, {
|
|
37
|
+
value,
|
|
38
|
+
className: cn("scroll-m-20 border-b last:border-b-0", className),
|
|
39
|
+
...props
|
|
18
40
|
});
|
|
41
|
+
return anchorSegments ? /* @__PURE__ */ jsx(AnchorSection, {
|
|
42
|
+
segments: anchorSegments,
|
|
43
|
+
children: content
|
|
44
|
+
}) : content;
|
|
19
45
|
}
|
|
20
46
|
function AccordionContent(props) {
|
|
21
47
|
return /* @__PURE__ */ jsx(Primitive.Content, {
|
|
22
48
|
...props,
|
|
23
|
-
className: cn("overflow-hidden data-[state=closed]:animate-fd-accordion-up data-[state=open]:animate-fd-accordion-down", props.className)
|
|
24
|
-
children: props.children
|
|
49
|
+
className: cn("overflow-hidden data-[state=closed]:animate-fd-accordion-up data-[state=open]:animate-fd-accordion-down", props.className)
|
|
25
50
|
});
|
|
26
51
|
}
|
|
27
52
|
function AccordionHeader(props) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useTranslations } from "../client/i18n.js";
|
|
3
3
|
import { cn } from "../../utils/cn.js";
|
|
4
|
-
import * as React from "react";
|
|
5
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
5
|
import { X } from "lucide-react";
|
|
7
6
|
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
@@ -10,13 +9,14 @@ import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
|
10
9
|
const Dialog = DialogPrimitive.Root;
|
|
11
10
|
const DialogTrigger = DialogPrimitive.Trigger;
|
|
12
11
|
const DialogPortal = DialogPrimitive.Portal;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
function DialogOverlay({ className, ref, ...props }) {
|
|
13
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Overlay, {
|
|
14
|
+
ref,
|
|
15
|
+
className: cn("fixed inset-0 z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-fd-fade-in data-[state=closed]:animate-fd-fade-out", className),
|
|
16
|
+
...props
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function DialogContent({ className, children, ref, ...props }) {
|
|
20
20
|
const t = useTranslations();
|
|
21
21
|
return /* @__PURE__ */ jsxs(DialogPortal, { children: [/* @__PURE__ */ jsx(DialogOverlay, {}), /* @__PURE__ */ jsxs(DialogPrimitive.Content, {
|
|
22
22
|
ref,
|
|
@@ -31,29 +31,26 @@ const DialogContent = React.forwardRef(({ className, children, ...props }, ref)
|
|
|
31
31
|
children: /* @__PURE__ */ jsx(X, {})
|
|
32
32
|
})]
|
|
33
33
|
})] });
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
...props
|
|
56
|
-
}));
|
|
57
|
-
DialogDescription.displayName = DialogPrimitive.Description.displayName;
|
|
34
|
+
}
|
|
35
|
+
function DialogHeader({ className, ...props }) {
|
|
36
|
+
return /* @__PURE__ */ jsx("div", {
|
|
37
|
+
className: cn("flex flex-col gap-1.5 text-center sm:text-start", className),
|
|
38
|
+
...props
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function DialogTitle({ className, ref, ...props }) {
|
|
42
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Title, {
|
|
43
|
+
ref,
|
|
44
|
+
className: cn("text-lg font-semibold leading-none tracking-tight", className),
|
|
45
|
+
...props
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function DialogDescription({ className, ref, ...props }) {
|
|
49
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Description, {
|
|
50
|
+
ref,
|
|
51
|
+
className: cn("text-sm text-fd-muted-foreground", className),
|
|
52
|
+
...props
|
|
53
|
+
});
|
|
54
|
+
}
|
|
58
55
|
//#endregion
|
|
59
56
|
export { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useApiContext } from "../contexts/api.js";
|
|
3
|
+
import { useAnchorId } from "../../utils/auto-anchor.client.js";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { Heading } from "fumadocs-ui/components/heading";
|
|
6
|
+
//#region src/ui/components/heading.tsx
|
|
7
|
+
function Heading$1({ id: _id, depth, ...props }) {
|
|
8
|
+
const id = useAnchorId([_id]);
|
|
9
|
+
const Component = useApiContext().client.components?.Heading;
|
|
10
|
+
if (Component) return /* @__PURE__ */ jsx(Component, {
|
|
11
|
+
id,
|
|
12
|
+
depth,
|
|
13
|
+
...props
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx(Heading, {
|
|
16
|
+
id,
|
|
17
|
+
as: `h${depth}`,
|
|
18
|
+
...props
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { Heading$1 as Heading };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../../utils/cn.js";
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
4
|
-
import {
|
|
4
|
+
import { anchorIdStartsWith } from "../../utils/auto-anchor.js";
|
|
5
|
+
import { AnchorSection, useAnchorId } from "../../utils/auto-anchor.client.js";
|
|
6
|
+
import { createContext, use, useEffect, useMemo, useState } from "react";
|
|
5
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
8
|
//#region src/ui/components/select-tab.tsx
|
|
7
9
|
const Context = createContext(null);
|
|
@@ -15,14 +17,24 @@ function SelectTabs({ defaultValue, children }) {
|
|
|
15
17
|
children
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
|
-
function SelectTab({ value, ...props }) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
20
|
+
function SelectTab({ value, anchorSegments, ...props }) {
|
|
21
|
+
const { value: currentValue, setValue } = use(Context);
|
|
22
|
+
const id = useAnchorId(anchorSegments ?? false);
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (id && anchorIdStartsWith(window.location.hash.slice(1), id)) setValue(value);
|
|
25
|
+
}, [
|
|
26
|
+
id,
|
|
27
|
+
value,
|
|
28
|
+
setValue
|
|
29
|
+
]);
|
|
30
|
+
if (value !== currentValue) return;
|
|
31
|
+
const content = /* @__PURE__ */ jsx("div", { ...props });
|
|
32
|
+
return anchorSegments ? /* @__PURE__ */ jsx(AnchorSection, {
|
|
33
|
+
segments: anchorSegments,
|
|
34
|
+
children: content
|
|
35
|
+
}) : content;
|
|
24
36
|
}
|
|
25
|
-
function SelectTabTrigger({ items, className, ...props }) {
|
|
37
|
+
function SelectTabTrigger({ items, className, placeholder, ...props }) {
|
|
26
38
|
const { value, setValue } = use(Context);
|
|
27
39
|
return /* @__PURE__ */ jsxs(Select, {
|
|
28
40
|
value: value ?? "",
|
|
@@ -30,7 +42,10 @@ function SelectTabTrigger({ items, className, ...props }) {
|
|
|
30
42
|
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
31
43
|
className: cn("not-prose w-fit min-w-0 *:min-w-0", className),
|
|
32
44
|
...props,
|
|
33
|
-
children: /* @__PURE__ */ jsx(SelectValue, {
|
|
45
|
+
children: /* @__PURE__ */ jsx(SelectValue, {
|
|
46
|
+
placeholder,
|
|
47
|
+
children: value && items.find((item) => item.value === value)?.label
|
|
48
|
+
})
|
|
34
49
|
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map(({ label, value }) => /* @__PURE__ */ jsx(SelectItem, {
|
|
35
50
|
value,
|
|
36
51
|
children: label
|
package/dist/ui/contexts/api.js
CHANGED
|
@@ -21,16 +21,10 @@ function useServerContext() {
|
|
|
21
21
|
function ApiProvider({ children, shikiOptions, client, schemes }) {
|
|
22
22
|
return /* @__PURE__ */ jsx(ApiContext, {
|
|
23
23
|
value: useMemo(() => {
|
|
24
|
-
let codeUsages;
|
|
25
|
-
if (client.codeUsages) codeUsages = createCodeUsageGeneratorRegistry(client.codeUsages);
|
|
26
|
-
else {
|
|
27
|
-
codeUsages = createCodeUsageGeneratorRegistry();
|
|
28
|
-
registerDefault(codeUsages);
|
|
29
|
-
}
|
|
30
24
|
return {
|
|
31
25
|
shikiOptions,
|
|
32
26
|
client,
|
|
33
|
-
codeUsages,
|
|
27
|
+
codeUsages: client.codeUsages ?? registerDefault(createCodeUsageGeneratorRegistry()),
|
|
34
28
|
schemes,
|
|
35
29
|
mediaAdapters: {
|
|
36
30
|
...defaultAdapters,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { APIPageClientOptions } from "./client/index.js";
|
|
1
2
|
import { ApiPageProps } from "./api-page.js";
|
|
2
3
|
import { CreateAPIPageOptions } from "./base.js";
|
|
3
4
|
import { Document } from "../types.js";
|
|
@@ -11,7 +12,7 @@ interface ClientApiPagePayload {
|
|
|
11
12
|
bundled: Document;
|
|
12
13
|
proxyUrl?: string;
|
|
13
14
|
}
|
|
14
|
-
type CreateClientAPIPageOptions = Omit<
|
|
15
|
+
type CreateClientAPIPageOptions = Partial<Omit<CreateAPIPageOptions, 'generateTypeScriptSchema' | 'client'> & Omit<APIPageClientOptions, 'mediaAdapters' | 'codeUsages'>>;
|
|
15
16
|
/**
|
|
16
17
|
* Create `<APIPage />` for non-RSC environment, note that this may be unstable, and doesn't support the full set of features.
|
|
17
18
|
*/
|
package/dist/ui/create-client.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
import { parseSecurities } from "../utils/schema/index.js";
|
|
2
3
|
import { defaultAdapters } from "../requests/media/adapter.js";
|
|
4
|
+
import { createCodeUsageGeneratorRegistry } from "../requests/generators/index.js";
|
|
5
|
+
import { registerDefault } from "../requests/generators/all.js";
|
|
3
6
|
import { ClientCodeBlock, ClientCodeBlockProvider } from "./components/codeblock.js";
|
|
4
7
|
import { AuthProvider } from "../playground/auth.js";
|
|
5
8
|
import { dereferenceDocument } from "../utils/document/dereference.js";
|
|
6
9
|
import { APIPage } from "./api-page.js";
|
|
7
10
|
import { boundary_exports } from "./client/boundary.js";
|
|
8
|
-
import { slug } from "github-slugger";
|
|
9
11
|
import { Children, useMemo } from "react";
|
|
10
12
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
11
13
|
import { jsx } from "react/jsx-runtime";
|
|
12
|
-
import { Heading } from "fumadocs-ui/components/heading";
|
|
13
14
|
import { remarkGfm } from "fumadocs-core/mdx-plugins/remark-gfm";
|
|
14
15
|
import defaultMdxComponents from "fumadocs-ui/mdx";
|
|
15
16
|
import { remark } from "remark";
|
|
@@ -80,7 +81,9 @@ function createClientAPIPage({ shiki = defaultShikiFactory, shikiOptions = { the
|
|
|
80
81
|
shikiOptions,
|
|
81
82
|
generateTypeScriptDefinitions,
|
|
82
83
|
clientBoundary: boundary_exports,
|
|
84
|
+
client: options,
|
|
83
85
|
...options,
|
|
86
|
+
codeUsages: options.codeUsages ?? registerDefault(createCodeUsageGeneratorRegistry()),
|
|
84
87
|
mediaAdapters: {
|
|
85
88
|
...defaultAdapters,
|
|
86
89
|
...options.mediaAdapters
|
|
@@ -90,35 +93,14 @@ function createClientAPIPage({ shiki = defaultShikiFactory, shikiOptions = { the
|
|
|
90
93
|
provider: options.playground?.provider ?? renderPlaygroundProviderDefault,
|
|
91
94
|
render: options.playground?.render ?? renderPlaygroundDefault
|
|
92
95
|
},
|
|
93
|
-
renderHeading(depth, text, props) {
|
|
94
|
-
const id = typeof text === "string" ? slug(text) : props?.id;
|
|
95
|
-
if (!id) throw new Error("missing 'id' for non-string children");
|
|
96
|
-
if (options.renderHeading) return options.renderHeading({
|
|
97
|
-
id,
|
|
98
|
-
children: text,
|
|
99
|
-
...props
|
|
100
|
-
}, depth);
|
|
101
|
-
return /* @__PURE__ */ jsx(Heading, {
|
|
102
|
-
id,
|
|
103
|
-
as: `h${depth}`,
|
|
104
|
-
...props,
|
|
105
|
-
children: text
|
|
106
|
-
}, id);
|
|
107
|
-
},
|
|
108
96
|
renderMarkdown(text) {
|
|
109
97
|
if (options.renderMarkdown) return options.renderMarkdown(text);
|
|
110
98
|
processor ??= createMarkdownProcessor();
|
|
111
99
|
return processor.processSync({ value: text }).result;
|
|
112
100
|
},
|
|
113
|
-
renderCodeBlock(
|
|
114
|
-
if (options.renderCodeBlock) return options.renderCodeBlock(
|
|
115
|
-
|
|
116
|
-
code
|
|
117
|
-
});
|
|
118
|
-
return /* @__PURE__ */ jsx(ClientCodeBlock, {
|
|
119
|
-
lang,
|
|
120
|
-
code
|
|
121
|
-
});
|
|
101
|
+
renderCodeBlock(props) {
|
|
102
|
+
if (options.renderCodeBlock) return options.renderCodeBlock(props);
|
|
103
|
+
return /* @__PURE__ */ jsx(ClientCodeBlock, { ...props });
|
|
122
104
|
}
|
|
123
105
|
}), [payload.proxyUrl, processed]);
|
|
124
106
|
return /* @__PURE__ */ jsx(ClientCodeBlockProvider, {
|
|
@@ -56,7 +56,7 @@ function CopyTypeScriptPanel({ name, code, className }) {
|
|
|
56
56
|
const t = useTranslations();
|
|
57
57
|
const useTypeText = t.useTypeInTypeScript.replace("{name}", name);
|
|
58
58
|
return /* @__PURE__ */ jsxs("div", {
|
|
59
|
-
className: cn("flex items-start justify-between gap-2 bg-fd-card text-fd-card-foreground border rounded-xl p-3 not-prose
|
|
59
|
+
className: cn("flex items-start justify-between gap-2 bg-fd-card text-fd-card-foreground border rounded-xl p-3 not-prose", className),
|
|
60
60
|
children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("p", {
|
|
61
61
|
className: "font-medium text-sm mb-2",
|
|
62
62
|
children: t.typeScriptDefinitions
|