fumadocs-openapi 6.0.5 → 6.0.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.
@@ -0,0 +1,15 @@
1
+ import type { MethodInformation, RenderContext } from '../../types.js';
2
+ import type { EndpointSample } from '../../utils/generate-sample.js';
3
+ import { type CodeSample } from '../../render/operation.js';
4
+ interface CustomProperty {
5
+ 'x-codeSamples'?: CodeSample[];
6
+ 'x-selectedCodeSample'?: string;
7
+ 'x-exclusiveCodeSample'?: string;
8
+ }
9
+ export declare function APIExample({ method, endpoint, ctx, }: {
10
+ method: MethodInformation & CustomProperty;
11
+ endpoint: EndpointSample;
12
+ ctx: RenderContext;
13
+ }): Promise<import("react/jsx-runtime").JSX.Element>;
14
+ export {};
15
+ //# sourceMappingURL=api-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA2BrD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAcD,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,QAAQ,EAAE,cAAc,CAAC;IACzB,GAAG,EAAE,aAAa,CAAC;CACpB,oDA2FA"}
@@ -0,0 +1,131 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as CURL from '../../requests/curl.js';
3
+ import * as JS from '../../requests/javascript.js';
4
+ import * as Go from '../../requests/go.js';
5
+ import * as Python from '../../requests/python.js';
6
+ import { Markdown } from '../../render/markdown.js';
7
+ import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
8
+ const defaultSamples = [
9
+ {
10
+ label: 'cURL',
11
+ source: CURL.getSampleRequest,
12
+ lang: 'bash',
13
+ },
14
+ {
15
+ label: 'JavaScript',
16
+ source: JS.getSampleRequest,
17
+ lang: 'js',
18
+ },
19
+ {
20
+ label: 'Go',
21
+ source: Go.getSampleRequest,
22
+ lang: 'go',
23
+ },
24
+ {
25
+ label: 'Python',
26
+ source: Python.getSampleRequest,
27
+ lang: 'python',
28
+ },
29
+ ];
30
+ export async function APIExample({ method, endpoint, ctx, }) {
31
+ const renderer = ctx.renderer;
32
+ const samples = new Map();
33
+ let children;
34
+ for (const [key, sample] of Object.entries(endpoint.body?.samples ?? {
35
+ // fallback for methods that have no request body, we also want to show examples for
36
+ _default: {},
37
+ })) {
38
+ samples.set(key, {
39
+ title: sample?.summary ?? key,
40
+ description: sample?.description,
41
+ samples: dedupe([
42
+ ...defaultSamples,
43
+ ...(ctx.generateCodeSamples
44
+ ? await ctx.generateCodeSamples(endpoint)
45
+ : []),
46
+ ...(method['x-codeSamples'] ?? []),
47
+ ]).flatMap((sample) => {
48
+ if (sample.source === false)
49
+ return [];
50
+ const result = typeof sample.source === 'function'
51
+ ? sample.source(endpoint, key)
52
+ : sample.source;
53
+ if (result === undefined)
54
+ return [];
55
+ return {
56
+ ...sample,
57
+ source: result,
58
+ };
59
+ }),
60
+ });
61
+ }
62
+ function renderRequest(sample) {
63
+ return (_jsx(renderer.Requests, { items: sample.samples.map((s) => s.label), children: sample.samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }));
64
+ }
65
+ if ((samples.size === 1 && samples.has('_default')) ||
66
+ (method['x-exclusiveCodeSample'] &&
67
+ samples.has(method['x-exclusiveCodeSample']))) {
68
+ // if exclusiveSampleKey is present, we don't use tabs
69
+ // if only the fallback or non described openapi legacy example is present, we don't use tabs
70
+ children = renderRequest(samples.get(method['x-exclusiveCodeSample'] ?? '_default'));
71
+ }
72
+ else if (samples.size > 0) {
73
+ const entries = Array.from(samples.entries());
74
+ children = (_jsx(renderer.Samples, { items: entries.map(([key, sample]) => ({
75
+ title: sample.title,
76
+ description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
77
+ value: key,
78
+ })), defaultValue: method['x-selectedCodeSample'], children: entries.map(([key, sample]) => (_jsx(renderer.Sample, { value: key, children: renderRequest(sample) }, key))) }));
79
+ }
80
+ return (_jsxs(renderer.APIExample, { children: [children, _jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint })] }));
81
+ }
82
+ /**
83
+ * Remove duplicated labels
84
+ */
85
+ function dedupe(samples) {
86
+ const set = new Set();
87
+ const out = [];
88
+ for (let i = samples.length - 1; i >= 0; i--) {
89
+ if (set.has(samples[i].label))
90
+ continue;
91
+ set.add(samples[i].label);
92
+ out.unshift(samples[i]);
93
+ }
94
+ return out;
95
+ }
96
+ function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
97
+ if (!operation.responses)
98
+ return null;
99
+ async function renderResponse(code) {
100
+ const types = [];
101
+ let description = operation.responses?.[code].description;
102
+ if (!description && code in endpoint.responses)
103
+ description = endpoint.responses[code].schema.description ?? '';
104
+ if (code in endpoint.responses) {
105
+ types.push({
106
+ lang: 'json',
107
+ label: 'Response',
108
+ code: JSON.stringify(endpoint.responses[code].sample, null, 2),
109
+ });
110
+ }
111
+ let ts;
112
+ if (generateTypeScriptSchema) {
113
+ ts = await generateTypeScriptSchema(endpoint, code);
114
+ }
115
+ else if (generateTypeScriptSchema === undefined) {
116
+ ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
117
+ }
118
+ if (ts) {
119
+ types.push({
120
+ code: ts,
121
+ lang: 'ts',
122
+ label: 'TypeScript',
123
+ });
124
+ }
125
+ return (_jsxs(renderer.Response, { value: code, children: [description ? _jsx(Markdown, { text: description }) : null, types.length > 0 ? (_jsx(renderer.ResponseTypes, { children: types.map((type) => (_jsx(renderer.ResponseType, { ...type }, type.lang))) })) : null] }));
126
+ }
127
+ const codes = Object.keys(operation.responses);
128
+ if (codes.length === 0)
129
+ return null;
130
+ return (_jsx(renderer.Responses, { items: codes, children: codes.map((code) => renderResponse(code)) }));
131
+ }
@@ -6,14 +6,12 @@ export interface CodeSample {
6
6
  label: string;
7
7
  source: string | ((endpoint: EndpointSample, exampleKey: string) => string | undefined) | false;
8
8
  }
9
- export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, selectedSampleKey, exclusiveSampleKey, }: {
9
+ export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
10
10
  type?: 'webhook' | 'operation';
11
11
  path: string;
12
12
  method: MethodInformation;
13
13
  ctx: RenderContext;
14
14
  hasHead?: boolean;
15
15
  headingLevel?: number;
16
- selectedSampleKey?: string;
17
- exclusiveSampleKey?: string;
18
16
  }): ReactElement;
19
17
  //# sourceMappingURL=operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAEL,KAAK,cAAc,EAEpB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EACF,MAAM,GACN,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACtE,KAAK,CAAC;CACX;AAQD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IA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Lf"}
@@ -1,12 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment } from 'react';
3
- import { generateSample, } from '../utils/generate-sample.js';
4
- import * as CURL from '../requests/curl.js';
5
- import * as JS from '../requests/javascript.js';
6
- import * as Go from '../requests/go.js';
7
- import * as Python from '../requests/python.js';
3
+ import { generateSample } from '../utils/generate-sample.js';
8
4
  import { getPreferredType } from '../utils/schema.js';
9
- import { getTypescriptSchema } from '../utils/get-typescript-schema.js';
10
5
  import { getSecurities, getSecurityPrefix } from '../utils/get-security.js';
11
6
  import { idToTitle } from '../utils/id-to-title.js';
12
7
  import { Markdown } from './markdown.js';
@@ -14,7 +9,8 @@ import { heading } from './heading.js';
14
9
  import { Schema } from './schema.js';
15
10
  import { createMethod } from '../server/create-method.js';
16
11
  import { methodKeys } from '../build-routes.js';
17
- export function Operation({ type = 'operation', path, method, ctx, hasHead, headingLevel = 2, selectedSampleKey, exclusiveSampleKey, }) {
12
+ import { APIExample } from '../render/operation/api-example.js';
13
+ export function Operation({ type = 'operation', path, method, ctx, hasHead, headingLevel = 2, }) {
18
14
  const body = method.requestBody;
19
15
  const security = method.security ?? ctx.schema.document.security;
20
16
  let headNode = null;
@@ -91,89 +87,12 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
91
87
  return (_jsxs(Fragment, { children: [heading(headingLevel, group, ctx), params] }, group));
92
88
  }), responseNode, callbacksNode] }));
93
89
  if (type === 'operation') {
94
- return (_jsxs(ctx.renderer.API, { children: [info, _jsx(APIExample, { method: method, endpoint: endpoint, ctx: ctx, selectedSampleKey: selectedSampleKey, exclusiveSampleKey: exclusiveSampleKey })] }));
90
+ return (_jsxs(ctx.renderer.API, { children: [info, _jsx(APIExample, { method: method, endpoint: endpoint, ctx: ctx })] }));
95
91
  }
96
92
  else {
97
93
  return info;
98
94
  }
99
95
  }
100
- const defaultSamples = [
101
- {
102
- label: 'cURL',
103
- source: CURL.getSampleRequest,
104
- lang: 'bash',
105
- },
106
- {
107
- label: 'JavaScript',
108
- source: JS.getSampleRequest,
109
- lang: 'js',
110
- },
111
- {
112
- label: 'Go',
113
- source: Go.getSampleRequest,
114
- lang: 'go',
115
- },
116
- {
117
- label: 'Python',
118
- source: Python.getSampleRequest,
119
- lang: 'python',
120
- },
121
- ];
122
- async function APIExample({ method, endpoint, ctx, selectedSampleKey, exclusiveSampleKey, }) {
123
- const renderer = ctx.renderer;
124
- const children = [];
125
- // fallback for methods that have no request body, we also want to show examples for
126
- const existingSamples = endpoint.body?.samples ?? {
127
- _default: {},
128
- };
129
- const samples = {};
130
- for (const exampleKey in existingSamples) {
131
- samples[exampleKey] = {
132
- title: existingSamples[exampleKey]?.summary ?? exampleKey,
133
- description: existingSamples[exampleKey]?.description,
134
- samples: dedupe([
135
- ...defaultSamples,
136
- ...(ctx.generateCodeSamples
137
- ? await ctx.generateCodeSamples(endpoint)
138
- : []),
139
- ...(method['x-codeSamples'] ?? []),
140
- ]).flatMap((sample) => {
141
- if (sample.source === false)
142
- return [];
143
- const result = typeof sample.source === 'function'
144
- ? sample.source(endpoint, exampleKey)
145
- : sample.source;
146
- if (result === undefined)
147
- return [];
148
- return {
149
- ...sample,
150
- source: result,
151
- };
152
- }),
153
- };
154
- }
155
- if (Object.keys(samples).length > 0) {
156
- const sampleTabs = [];
157
- const titles = [];
158
- if ((samples && Object.keys(samples).length === 1 && samples['_default']) ||
159
- (exclusiveSampleKey && samples[exclusiveSampleKey])) {
160
- // if exclusiveSampleKey is present, we don't use tabs
161
- // if only the fallback or non described openapi legacy example is present, we don't use tabs
162
- const sampleKey = exclusiveSampleKey ?? '_default';
163
- children.push(_jsx(renderer.Requests, { items: samples[sampleKey].samples.map((s) => s.label), children: samples[sampleKey].samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, `requests-${sampleKey}-${s.label}`))) }, `requests-${sampleKey}`));
164
- }
165
- else {
166
- for (const sampleKey in samples) {
167
- const title = samples[sampleKey].title;
168
- titles.push(title);
169
- sampleTabs.push(_jsxs(renderer.Sample, { value: title, children: [samples[sampleKey].description && (_jsx(Markdown, { text: samples[sampleKey].description })), _jsx(renderer.Requests, { items: samples[sampleKey].samples.map((s) => s.label), children: samples[sampleKey].samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, `requests-${sampleKey}-${s.label}`))) }, `requests-${sampleKey}`)] }, sampleKey));
170
- }
171
- children.push(_jsx(renderer.Samples, { items: titles, defaultValue: selectedSampleKey, children: sampleTabs }, "samples"));
172
- }
173
- }
174
- children.push(_jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint }, "responses"));
175
- return _jsx(renderer.APIExample, { children: children });
176
- }
177
96
  function WebhookCallback({ callback, ctx, headingLevel, }) {
178
97
  return Object.entries(callback).map(([path, pathItem]) => {
179
98
  const pathNodes = methodKeys.map((method) => {
@@ -185,20 +104,6 @@ function WebhookCallback({ callback, ctx, headingLevel, }) {
185
104
  return _jsx(Fragment, { children: pathNodes }, path);
186
105
  });
187
106
  }
188
- /**
189
- * Remove duplicated labels
190
- */
191
- function dedupe(samples) {
192
- const set = new Set();
193
- const out = [];
194
- for (let i = samples.length - 1; i >= 0; i--) {
195
- if (set.has(samples[i].label))
196
- continue;
197
- set.add(samples[i].label);
198
- out.unshift(samples[i]);
199
- }
200
- return out;
201
- }
202
107
  function AuthSection({ ctx: { schema: { document }, renderer, }, requirements, }) {
203
108
  let id = 0;
204
109
  const info = [];
@@ -219,41 +124,3 @@ function AuthSection({ ctx: { schema: { document }, renderer, }, requirements, }
219
124
  }
220
125
  return info;
221
126
  }
222
- async function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
223
- const items = [];
224
- const children = [];
225
- if (!operation.responses)
226
- return null;
227
- for (const code of Object.keys(operation.responses)) {
228
- const types = [];
229
- let description = operation.responses[code].description;
230
- if (!description && code in endpoint.responses)
231
- description = endpoint.responses[code].schema.description ?? '';
232
- if (code in endpoint.responses) {
233
- types.push({
234
- lang: 'json',
235
- label: 'Response',
236
- code: JSON.stringify(endpoint.responses[code].sample, null, 2),
237
- });
238
- }
239
- let ts;
240
- if (generateTypeScriptSchema) {
241
- ts = await generateTypeScriptSchema(endpoint, code);
242
- }
243
- else if (generateTypeScriptSchema === undefined) {
244
- ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
245
- }
246
- if (ts) {
247
- types.push({
248
- code: ts,
249
- lang: 'ts',
250
- label: 'TypeScript',
251
- });
252
- }
253
- items.push(code);
254
- children.push(_jsxs(renderer.Response, { value: code, children: [_jsx(Markdown, { text: description }), types.length > 0 ? (_jsx(renderer.ResponseTypes, { children: types.map((type) => (_jsx(renderer.ResponseType, { ...type }, type.lang))) })) : null] }, code));
255
- }
256
- if (items.length === 0)
257
- return null;
258
- return _jsx(renderer.Responses, { items: items, children: children });
259
- }
@@ -35,7 +35,11 @@ export interface SampleProps {
35
35
  children: ReactNode;
36
36
  }
37
37
  export interface SamplesProps {
38
- items: string[];
38
+ items: {
39
+ title: string;
40
+ description?: ReactNode;
41
+ value: string;
42
+ }[];
39
43
  children: ReactNode;
40
44
  defaultValue?: string;
41
45
  }
@@ -46,6 +50,7 @@ export interface ResponseTypeProps {
46
50
  }
47
51
  export interface RootProps {
48
52
  baseUrl?: string;
53
+ shikiOptions?: RenderContext['shikiOptions'];
49
54
  servers: ServerObject[];
50
55
  children: ReactNode;
51
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAYtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG9E,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,QAAQ,EAAE,SAAS,C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AAG,EAAE,aAAa,CAAC;KACpB,CAAC,CAAC;CACJ;AAED,YAAY,EACV,kBAAkB,EAClB,aAAa,EACb,qBAAqB,EACrB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,aAAa,CAC3B,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GAC1C,QAAQ,CAkDV"}
@@ -4,6 +4,7 @@ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
4
4
  import { CodeBlock } from '../render/codeblock.js';
5
5
  import { API, Root, APIInfo, APIExample, Property, ObjectCollapsible, } from '../ui/index.js';
6
6
  import { Playground } from '../render/playground.js';
7
+ import { Sample, Samples } from '../ui/client.js';
7
8
  export function createRenders(shikiOptions) {
8
9
  return {
9
10
  Root: (props) => (_jsx(Root, { shikiOptions: shikiOptions, ...props, children: props.children })),
@@ -17,8 +18,8 @@ export function createRenders(shikiOptions) {
17
18
  Property,
18
19
  ObjectCollapsible,
19
20
  Requests: (props) => (_jsx(Tabs, { groupId: "fumadocs_openapi_requests", ...props })),
20
- Samples: (props) => _jsx(Tabs, { ...props }),
21
- Sample: Tab,
21
+ Samples,
22
+ Sample,
22
23
  Request: (props) => (_jsx(Tab, { value: props.name, children: _jsx(CodeBlock, { lang: props.language, code: props.code, options: shikiOptions }) })),
23
24
  APIPlayground: Playground,
24
25
  };
@@ -24,14 +24,6 @@ export interface WebhookItem {
24
24
  export interface OperationItem {
25
25
  path: string;
26
26
  method: OpenAPIV3_1.HttpMethods;
27
- /**
28
- * The key of the sample to be selected
29
- */
30
- selectedSampleKey?: string;
31
- /**
32
- * Only this sample will be shown
33
- */
34
- exclusiveSampleKey?: string;
35
27
  }
36
28
  export declare function APIPage(props: ApiPageProps): Promise<import("react/jsx-runtime").JSX.Element>;
37
29
  export declare function getContext(schema: ProcessedDocument, options?: ApiPageContextProps & {
@@ -1 +1 @@
1
- {"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/server/api-page.tsx"],"names":[],"mappings":"AA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+18,7 @@ export async function APIPage(props) {
18
18
  if (!operation)
19
19
  return null;
20
20
  const method = createMethod(item.method, pathItem, operation);
21
- return (_jsx(Operation, { method: method, path: item.path, ctx: ctx, hasHead: hasHead, selectedSampleKey: item.selectedSampleKey, exclusiveSampleKey: item.exclusiveSampleKey }, `${item.path}:${item.method}`));
21
+ return (_jsx(Operation, { method: method, path: item.path, ctx: ctx, hasHead: hasHead }, `${item.path}:${item.method}`));
22
22
  }), webhooks?.map((item) => {
23
23
  const webhook = document.webhooks?.[item.name];
24
24
  if (!webhook)
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIjE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,YAAY,CA6BzD,CAAC"}
1
+ {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAGjE;;;;GAIG;AACH,eAAO,MAAM,UAAU,EAAE,oBAAoB,CAAC,YAAY,CAyBzD,CAAC"}
@@ -1,6 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cva } from 'class-variance-authority';
3
- import { getBadgeColor } from '../ui/components/variants.js';
2
+ import { MethodLabel } from '../ui/components/method-label.js';
4
3
  /**
5
4
  * Source API Integration
6
5
  *
@@ -16,19 +15,7 @@ export const attachFile = (node, file) => {
16
15
  method = meta.method;
17
16
  }
18
17
  if (method) {
19
- const color = getBadgeColor(method);
20
- node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx("span", { className: badgeVariants({ className: 'ms-auto text-nowrap', color }), children: method })] }));
18
+ node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx(MethodLabel, { className: "ms-auto text-xs text-nowrap", children: method })] }));
21
19
  }
22
20
  return node;
23
21
  };
24
- const badgeVariants = cva('rounded-full border px-1.5 text-xs font-medium', {
25
- variants: {
26
- color: {
27
- green: 'bg-green-400/20 text-green-600 dark:text-green-400',
28
- yellow: 'bg-yellow-400/20 text-yellow-600 dark:text-yellow-400',
29
- red: 'bg-red-400/20 text-red-600 dark:text-red-400',
30
- blue: 'bg-blue-400/20 text-blue-600 dark:text-blue-400',
31
- orange: 'bg-orange-400/20 text-orange-600 dark:text-orange-400',
32
- },
33
- },
34
- });
@@ -1,22 +1,18 @@
1
- import { type HTMLAttributes, type ReactNode } from 'react';
2
- import { type RootProps } from '../render/renderer.js';
3
- import type { RenderContext } from '../types.js';
4
- export declare const APIPlayground: import("react").ComponentType<import("../render/renderer.js").APIPlaygroundProps & {
1
+ export declare const APIPlayground: import("react").ComponentType<import("../render/playground.js").APIPlaygroundProps & {
5
2
  fields?: {
6
- auth?: import("./playground/index.js").CustomField<"authorization", import("../render/renderer.js").RequestSchema>;
7
- path?: import("./playground/index.js").CustomField<`path.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
8
- query?: import("./playground/index.js").CustomField<`query.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
9
- header?: import("./playground/index.js").CustomField<`header.${string}`, import("../render/renderer.js").PrimitiveRequestField>;
10
- body?: import("./playground/index.js").CustomField<"body", import("../render/renderer.js").RequestSchema>;
3
+ auth?: import("./playground/index.js").CustomField<"authorization", import("../render/playground.js").RequestSchema>;
4
+ path?: import("./playground/index.js").CustomField<`path.${string}`, import("../render/playground.js").PrimitiveRequestField>;
5
+ query?: import("./playground/index.js").CustomField<`query.${string}`, import("../render/playground.js").PrimitiveRequestField>;
6
+ header?: import("./playground/index.js").CustomField<`header.${string}`, import("../render/playground.js").PrimitiveRequestField>;
7
+ body?: import("./playground/index.js").CustomField<"body", import("../render/playground.js").RequestSchema>;
11
8
  };
12
9
  components?: Partial<{
13
10
  ResultDisplay: import("react").FC<{
14
11
  data: import("./playground/fetcher.js").FetchResult;
15
12
  }>;
16
13
  }>;
17
- } & HTMLAttributes<HTMLFormElement>>;
18
- export declare function Root({ children, baseUrl, className, shikiOptions, servers, ...props }: RootProps & {
19
- shikiOptions: RenderContext['shikiOptions'];
20
- } & HTMLAttributes<HTMLDivElement>): ReactNode;
14
+ } & import("react").HTMLAttributes<HTMLFormElement>>;
15
+ export declare const Samples: import("react").ComponentType<import("../render/renderer.js").SamplesProps>;
16
+ export declare const Sample: import("react").ComponentType<import("../render/renderer.js").SampleProps>;
21
17
  export { useSchemaContext } from './contexts/schema.js';
22
18
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAI5D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,aAAa;;YAkCy4C,CAAC;YAAuD,CAAC;aAAiE,CAAC;cAAmE,CAAC;YAAkE,CAAC;;;;;;;oCAhCpqD,CAAC;AAEF,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG;IACb,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;CAC7C,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG,SAAS,CAkB7C;AAED,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa;;YAa8+D,CAAC;YAAuD,CAAC;aAAiE,CAAC;cAAmE,CAAC;YAAkE,CAAC;;;;;;;oDAXzwE,CAAC;AAEF,eAAO,MAAM,OAAO,0EAEnB,CAAC;AAEF,eAAO,MAAM,MAAM,yEAElB,CAAC;AAEF,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC"}
package/dist/ui/client.js CHANGED
@@ -1,10 +1,6 @@
1
1
  'use client';
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { cn } from 'fumadocs-ui/components/api';
4
2
  import dynamic from 'next/dynamic';
5
- import { ApiProvider } from '../ui/contexts/api.js';
6
3
  export const APIPlayground = dynamic(() => import('./playground/index.js').then((mod) => mod.APIPlayground));
7
- export function Root({ children, baseUrl, className, shikiOptions, servers, ...props }) {
8
- return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { servers: servers, shikiOptions: shikiOptions, defaultBaseUrl: baseUrl, children: children }) }));
9
- }
4
+ export const Samples = dynamic(() => import('./sample-select.js').then((mod) => mod.Samples));
5
+ export const Sample = dynamic(() => import('./sample-select.js').then((mod) => mod.Sample));
10
6
  export { useSchemaContext } from './contexts/schema.js';
@@ -1,4 +1,10 @@
1
+ import { type VariantProps } from 'class-variance-authority';
1
2
  import type { HTMLAttributes } from 'react';
3
+ export declare const badgeVariants: (props?: ({
4
+ color?: "red" | "green" | "yellow" | "blue" | "orange" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
+ export declare function getBadgeColor(method: string): VariantProps<typeof badgeVariants>['color'];
7
+ export declare function Badge({ className, color, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'color'> & VariantProps<typeof badgeVariants>): import("react/jsx-runtime").JSX.Element;
2
8
  export declare function MethodLabel({ children, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
3
9
  children: string;
4
10
  }): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"method-label.d.ts","sourceRoot":"","sources":["../../../src/ui/components/method-label.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AA8B5C,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAC;CAClB,2CAcA"}
1
+ {"version":3,"file":"method-label.d.ts","sourceRoot":"","sources":["../../../src/ui/components/method-label.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,eAAO,MAAM,aAAa;;8EAUxB,CAAC;AAEH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,OAAO,CAAC,CAa7C;AAED,wBAAgB,KAAK,CAAC,EACpB,SAAS,EACT,KAAK,EACL,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,OAAO,CAAC,GAC/C,YAAY,CAAC,OAAO,aAAa,CAAC,2CAcnC;AAED,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,UAAU,CAAC,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAC;CAClB,2CAMA"}
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { cva } from 'class-variance-authority';
3
3
  import { cn } from 'fumadocs-ui/components/api';
4
- const variants = cva('font-mono font-medium', {
4
+ export const badgeVariants = cva('font-mono font-medium', {
5
5
  variants: {
6
6
  color: {
7
7
  green: 'text-green-600 dark:text-green-400',
@@ -12,7 +12,7 @@ const variants = cva('font-mono font-medium', {
12
12
  },
13
13
  },
14
14
  });
15
- function getBadgeColor(method) {
15
+ export function getBadgeColor(method) {
16
16
  switch (method.toUpperCase()) {
17
17
  case 'PUT':
18
18
  return 'yellow';
@@ -26,8 +26,12 @@ function getBadgeColor(method) {
26
26
  return 'green';
27
27
  }
28
28
  }
29
+ export function Badge({ className, color, ...props }) {
30
+ return (_jsx("span", { className: cn(badgeVariants({
31
+ color,
32
+ className,
33
+ })), ...props, children: props.children }));
34
+ }
29
35
  export function MethodLabel({ children, ...props }) {
30
- return (_jsx("span", { ...props, className: cn(variants({
31
- color: getBadgeColor(children),
32
- }), props.className), children: children.toUpperCase() }));
36
+ return (_jsx(Badge, { ...props, color: getBadgeColor(children), children: children.toUpperCase() }));
33
37
  }
@@ -6,7 +6,7 @@ import { cn } from 'fumadocs-ui/components/api';
6
6
  const Select = SelectPrimitive.Root;
7
7
  const SelectGroup = SelectPrimitive.Group;
8
8
  const SelectValue = SelectPrimitive.Value;
9
- const SelectTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn('flex h-10 items-center w-full rounded-md border px-3 py-2 text-start text-[13px] text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "ms-auto size-4 text-fd-muted-foreground" }) })] })));
9
+ const SelectTrigger = forwardRef(({ className, children, ...props }, ref) => (_jsxs(SelectPrimitive.Trigger, { ref: ref, className: cn('flex min-h-10 items-center w-full rounded-md border px-3 py-2 text-start text-[13px] text-fd-foreground hover:bg-fd-accent focus:outline-none focus:ring-2 focus:ring-fd-ring disabled:cursor-not-allowed disabled:opacity-50', className), ...props, children: [children, _jsx(SelectPrimitive.Icon, { asChild: true, children: _jsx(ChevronDown, { className: "ms-auto size-4 text-fd-muted-foreground" }) })] })));
10
10
  SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
11
11
  const SelectScrollUpButton = forwardRef(({ className, ...props }, ref) => (_jsx(SelectPrimitive.ScrollUpButton, { ref: ref, className: cn('flex items-center justify-center py-1', className), ...props, children: _jsx(ChevronUp, { className: "size-4" }) })));
12
12
  SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAE5C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,UAAU,cACR,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,gBAAgB,CAAC;IAC7D,SAAS,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAC7C;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAOD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA0ElB"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAE5C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,UAAU,cAAc;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,UAAU,cACR,SAAQ,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,gBAAgB,CAAC;IAC7D,SAAS,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAC7C;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAOD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA0ElB"}
@@ -1,3 +1,4 @@
1
+ 'use client';
1
2
  import { jsx as _jsx } from "react/jsx-runtime";
2
3
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
3
4
  const ApiContext = createContext(undefined);
@@ -1,6 +1,7 @@
1
1
  import { type HTMLAttributes, type ReactNode } from 'react';
2
- import type { PropertyProps } from '../render/renderer.js';
3
- export { Root, useSchemaContext, APIPlayground } from './client.js';
2
+ import type { PropertyProps, RootProps } from '../render/renderer.js';
3
+ export { useSchemaContext, APIPlayground } from './client.js';
4
+ export declare function Root({ children, baseUrl, className, shikiOptions, servers, ...props }: RootProps & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
4
5
  export declare function APIInfo({ className, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
5
6
  export declare function API({ children, ...props }: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
6
7
  export declare function Property({ name, type, required, deprecated, children, }: PropertyProps): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAQvD,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEjE,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAoBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AASlE,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE3D,wBAAgB,IAAI,CAAC,EACnB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,YAAY,EACZ,OAAO,EACP,GAAG,KAAK,EACT,EAAE,SAAS,GAAG,cAAc,CAAC,cAAc,CAAC,2CAkB5C;AAED,wBAAgB,OAAO,CAAC,EACtB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,2CAMhC;AAED,wBAAgB,GAAG,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAE,EAAE,cAAc,CAAC,cAAc,CAAC,2CAmBzE;AAED,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE,aAAa,2CAsBf;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,2CAY/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAiBA"}
package/dist/ui/index.js CHANGED
@@ -1,9 +1,13 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { buttonVariants, cn } from 'fumadocs-ui/components/api';
3
- import { badgeVariants } from '../ui/components/variants.js';
3
+ import { Badge } from '../ui/components/method-label.js';
4
4
  import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from 'fumadocs-ui/components/ui/collapsible';
5
5
  import { ChevronDown } from 'lucide-react';
6
- export { Root, useSchemaContext, APIPlayground } from './client.js';
6
+ import { ApiProvider } from '../ui/contexts/api.js';
7
+ export { useSchemaContext, APIPlayground } from './client.js';
8
+ export function Root({ children, baseUrl, className, shikiOptions, servers, ...props }) {
9
+ return (_jsx("div", { className: cn('flex flex-col gap-24 text-sm text-fd-muted-foreground', className), ...props, children: _jsx(ApiProvider, { servers: servers, shikiOptions: shikiOptions, defaultBaseUrl: baseUrl, children: children }) }));
10
+ }
7
11
  export function APIInfo({ className, ...props }) {
8
12
  return (_jsx("div", { className: cn('min-w-0 flex-1', className), ...props, children: props.children }));
9
13
  }
@@ -14,7 +18,7 @@ export function API({ children, ...props }) {
14
18
  }, children: children }));
15
19
  }
16
20
  export function Property({ name, type, required, deprecated, children, }) {
17
- return (_jsxs("div", { className: "rounded-xl border bg-fd-card p-3 prose-no-margin", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-center gap-4", children: [_jsx("code", { children: name }), required ? (_jsx("div", { className: cn(badgeVariants({ color: 'red' })), children: "Required" })) : null, deprecated ? (_jsx("div", { className: cn(badgeVariants({ color: 'yellow' })), children: "Deprecated" })) : null, _jsx("span", { className: "ms-auto text-xs font-mono text-fd-muted-foreground", children: type })] }), children] }));
21
+ return (_jsxs("div", { className: "rounded-xl border bg-fd-card p-3 prose-no-margin", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-center gap-4", children: [_jsx("code", { children: name }), required ? (_jsx(Badge, { color: "red", className: "text-xs", children: "Required" })) : null, deprecated ? (_jsx(Badge, { color: "yellow", className: "text-xs", children: "Deprecated" })) : null, _jsx("span", { className: "ms-auto text-xs font-mono text-fd-muted-foreground", children: type })] }), children] }));
18
22
  }
19
23
  export function APIExample(props) {
20
24
  return (_jsx("div", { ...props, className: cn('prose-no-margin md:sticky md:top-[var(--fd-api-info-top)] xl:w-[400px]', props.className), children: props.children }));
@@ -0,0 +1,4 @@
1
+ import type { SampleProps, SamplesProps } from '../render/renderer.js';
2
+ export declare function Samples({ items, defaultValue, children, }: SamplesProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function Sample({ value, children }: SampleProps): import("react").ReactNode;
4
+ //# sourceMappingURL=sample-select.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sample-select.d.ts","sourceRoot":"","sources":["../../src/ui/sample-select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWnE,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,YAA6B,EAC7B,QAAQ,GACT,EAAE,YAAY,2CA0Bd;AAWD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAW,6BAKtD"}
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { createContext, use, useState } from 'react';
3
+ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
4
+ const ActiveSampleContext = createContext('');
5
+ export function Samples({ items, defaultValue = items[0].value, children, }) {
6
+ const [value, setValue] = useState('');
7
+ const active = value === '' ? defaultValue : value;
8
+ const defaultItem = items.find((item) => item.value === defaultValue);
9
+ return (_jsxs(_Fragment, { children: [_jsxs(Select, { value: value, onValueChange: setValue, children: [_jsx(SelectTrigger, { className: "not-prose", children: _jsx(SelectValue, { placeholder: defaultItem ? _jsx(SelectDisplay, { ...defaultItem }) : null }) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: _jsx(SelectDisplay, { ...item }) }, item.value))) })] }), _jsx(ActiveSampleContext, { value: active, children: children })] }));
10
+ }
11
+ function SelectDisplay(item) {
12
+ return (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-medium text-sm", children: item.title }), _jsx("span", { className: "text-fd-muted-foreground", children: item.description })] }));
13
+ }
14
+ export function Sample({ value, children }) {
15
+ const active = use(ActiveSampleContext);
16
+ if (value !== active)
17
+ return;
18
+ return children;
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "6.0.5",
3
+ "version": "6.0.6",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -53,8 +53,8 @@
53
53
  "remark-rehype": "^11.1.1",
54
54
  "shiki": "^2.3.1",
55
55
  "xml-js": "^1.6.11",
56
- "fumadocs-core": "15.0.4",
57
- "fumadocs-ui": "15.0.4"
56
+ "fumadocs-core": "15.0.5",
57
+ "fumadocs-ui": "15.0.5"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@scalar/api-client-react": "^1.1.24",
@@ -1,6 +0,0 @@
1
- import { type VariantProps } from 'class-variance-authority';
2
- export declare const badgeVariants: (props?: ({
3
- color?: "red" | "green" | "yellow" | "blue" | "orange" | null | undefined;
4
- } & import("class-variance-authority/types").ClassProp) | undefined) => string;
5
- export declare function getBadgeColor(method: string): VariantProps<typeof badgeVariants>['color'];
6
- //# sourceMappingURL=variants.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../src/ui/components/variants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAElE,eAAO,MAAM,aAAa;;8EAazB,CAAC;AAEF,wBAAgB,aAAa,CAC3B,MAAM,EAAE,MAAM,GACb,YAAY,CAAC,OAAO,aAAa,CAAC,CAAC,OAAO,CAAC,CAa7C"}
@@ -1,26 +0,0 @@
1
- import { cva } from 'class-variance-authority';
2
- export const badgeVariants = cva('rounded-xl border px-1.5 py-1 text-xs font-medium leading-[12px]', {
3
- variants: {
4
- color: {
5
- green: 'bg-green-400/20 text-green-600 dark:text-green-400',
6
- yellow: 'bg-yellow-400/20 text-yellow-600 dark:text-yellow-400',
7
- red: 'bg-red-400/20 text-red-600 dark:text-red-400',
8
- blue: 'bg-blue-400/20 text-blue-600 dark:text-blue-400',
9
- orange: 'bg-orange-400/20 text-orange-600 dark:text-orange-400',
10
- },
11
- },
12
- });
13
- export function getBadgeColor(method) {
14
- switch (method) {
15
- case 'PUT':
16
- return 'yellow';
17
- case 'PATCH':
18
- return 'orange';
19
- case 'POST':
20
- return 'blue';
21
- case 'DELETE':
22
- return 'red';
23
- default:
24
- return 'green';
25
- }
26
- }