fumadocs-openapi 10.6.1 → 10.6.3
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 +14 -2
- package/dist/_virtual/_rolldown/runtime.js +13 -0
- package/dist/playground/client.d.ts +1 -1
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +2 -3
- package/dist/playground/client.js.map +1 -1
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +3 -3
- package/dist/playground/index.js.map +1 -1
- package/dist/requests/generators/curl.js +2 -2
- package/dist/requests/generators/curl.js.map +1 -1
- package/dist/requests/generators/go.js +5 -5
- package/dist/requests/generators/go.js.map +1 -1
- package/dist/requests/generators/java.js +13 -13
- package/dist/requests/generators/java.js.map +1 -1
- package/dist/requests/generators/javascript.js +2 -2
- package/dist/requests/generators/javascript.js.map +1 -1
- package/dist/requests/string-utils.js +4 -3
- package/dist/requests/string-utils.js.map +1 -1
- package/dist/server/create.d.ts +1 -1
- package/dist/types.d.ts +4 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts.map +1 -1
- package/dist/ui/api-page.js +2 -3
- package/dist/ui/api-page.js.map +1 -1
- package/dist/ui/base.d.ts +3 -3
- package/dist/ui/base.js +9 -0
- package/dist/ui/base.js.map +1 -1
- package/dist/ui/client/boundary.d.ts +12 -0
- package/dist/ui/client/boundary.d.ts.map +1 -0
- package/dist/ui/client/boundary.js +19 -0
- package/dist/ui/client/boundary.js.map +1 -0
- package/dist/ui/client/boundary.lazy.js +20 -0
- package/dist/ui/client/boundary.lazy.js.map +1 -0
- package/dist/ui/client/index.d.ts +1 -1
- package/dist/ui/components/{server-tab.js → select-tab.js} +11 -11
- package/dist/ui/components/select-tab.js.map +1 -0
- package/dist/ui/contexts/api.d.ts +27 -0
- package/dist/ui/contexts/api.d.ts.map +1 -0
- package/dist/ui/create-client.d.ts.map +1 -1
- package/dist/ui/create-client.js +2 -0
- package/dist/ui/create-client.js.map +1 -1
- package/dist/ui/operation/index.js +2 -3
- package/dist/ui/operation/index.js.map +1 -1
- package/dist/ui/operation/usage-tabs/client.d.ts +15 -0
- package/dist/ui/operation/usage-tabs/client.d.ts.map +1 -0
- package/dist/ui/operation/usage-tabs/index.js +2 -3
- package/dist/ui/operation/usage-tabs/index.js.map +1 -1
- package/dist/ui/schema/client.d.ts +9 -1
- package/dist/ui/schema/client.d.ts.map +1 -1
- package/dist/ui/schema/client.js +17 -6
- package/dist/ui/schema/client.js.map +1 -1
- package/dist/ui/schema/index.d.ts.map +1 -1
- package/dist/ui/schema/index.js +19 -10
- package/dist/ui/schema/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/playground/lazy.js +0 -8
- package/dist/playground/lazy.js.map +0 -1
- package/dist/ui/components/server-tab.js.map +0 -1
- package/dist/ui/contexts/api.lazy.js +0 -9
- package/dist/ui/contexts/api.lazy.js.map +0 -1
- package/dist/ui/operation/usage-tabs/lazy.js +0 -9
- package/dist/ui/operation/usage-tabs/lazy.js.map +0 -1
- package/dist/ui/schema/lazy.js +0 -8
- package/dist/ui/schema/lazy.js.map +0 -1
- package/dist/utils/lazy.js +0 -13
- package/dist/utils/lazy.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string-utils.js","names":[],"sources":["../../src/requests/string-utils.ts"],"sourcesContent":["// @ts-expect-error -- nothing\nimport js2xml from 'xml-js/lib/js2xml';\n\n/**\n * Convert input value to hardcoded string (with quotes)\n */\nexport function inputToString(\n value: unknown,\n format:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml' = 'application/json',\n): string {\n if (typeof value === 'string') return value;\n\n if (format === 'application/json') {\n return JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-ndjson') {\n return Array.isArray(value)\n ? value.map((v) => JSON.stringify(v)).join('\\n')\n : JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-www-form-urlencoded') {\n const params = new URLSearchParams();\n if (typeof value !== 'object')\n throw new Error(\n `For url encoded data, \\`value\\` must be an object, but received: ${typeof value}`,\n );\n\n for (const key in value) {\n if (value[key as keyof object]) params.set(key, String(value[key as keyof object]));\n }\n\n return params.toString();\n }\n\n return js2xml(value, { compact: true, spaces: 2 });\n}\n\nexport function escapeString(str: string, delimit?: string): string {\n if (!delimit) return JSON.stringify(str);\n\n return `${delimit}${str.replaceAll(delimit, `\\\\${delimit}`)}${delimit}`;\n}\n\nexport function
|
|
1
|
+
{"version":3,"file":"string-utils.js","names":[],"sources":["../../src/requests/string-utils.ts"],"sourcesContent":["// @ts-expect-error -- nothing\nimport js2xml from 'xml-js/lib/js2xml';\n\n/**\n * Convert input value to hardcoded string (with quotes)\n */\nexport function inputToString(\n value: unknown,\n format:\n | 'application/x-www-form-urlencoded'\n | 'application/x-ndjson'\n | 'application/json'\n | 'application/xml' = 'application/json',\n): string {\n if (typeof value === 'string') return value;\n\n if (format === 'application/json') {\n return JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-ndjson') {\n return Array.isArray(value)\n ? value.map((v) => JSON.stringify(v)).join('\\n')\n : JSON.stringify(value, null, 2);\n }\n\n if (format === 'application/x-www-form-urlencoded') {\n const params = new URLSearchParams();\n if (typeof value !== 'object')\n throw new Error(\n `For url encoded data, \\`value\\` must be an object, but received: ${typeof value}`,\n );\n\n for (const key in value) {\n if (value[key as keyof object]) params.set(key, String(value[key as keyof object]));\n }\n\n return params.toString();\n }\n\n return js2xml(value, { compact: true, spaces: 2 });\n}\n\nexport function escapeString(str: string, delimit?: string): string {\n if (!delimit) return JSON.stringify(str);\n\n return `${delimit}${str.replaceAll(delimit, `\\\\${delimit}`)}${delimit}`;\n}\n\nexport function indent(code: string, tab: number = 1) {\n const p = ' '.repeat(tab);\n return code\n .split('\\n')\n .map((v) => (v.length === 0 ? v : p + v))\n .join('\\n');\n}\n"],"mappings":";;;;;AAMA,SAAgB,cACd,OACA,SAIwB,oBAChB;AACR,KAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,KAAI,WAAW,mBACb,QAAO,KAAK,UAAU,OAAO,MAAM,EAAE;AAGvC,KAAI,WAAW,uBACb,QAAO,MAAM,QAAQ,MAAM,GACvB,MAAM,KAAK,MAAM,KAAK,UAAU,EAAE,CAAC,CAAC,KAAK,KAAK,GAC9C,KAAK,UAAU,OAAO,MAAM,EAAE;AAGpC,KAAI,WAAW,qCAAqC;EAClD,MAAM,SAAS,IAAI,iBAAiB;AACpC,MAAI,OAAO,UAAU,SACnB,OAAM,IAAI,MACR,oEAAoE,OAAO,QAC5E;AAEH,OAAK,MAAM,OAAO,MAChB,KAAI,MAAM,KAAsB,QAAO,IAAI,KAAK,OAAO,MAAM,KAAqB,CAAC;AAGrF,SAAO,OAAO,UAAU;;AAG1B,QAAO,OAAO,OAAO;EAAE,SAAS;EAAM,QAAQ;EAAG,CAAC;;AAGpD,SAAgB,aAAa,KAAa,SAA0B;AAClE,KAAI,CAAC,QAAS,QAAO,KAAK,UAAU,IAAI;AAExC,QAAO,GAAG,UAAU,IAAI,WAAW,SAAS,KAAK,UAAU,GAAG;;AAGhE,SAAgB,OAAO,MAAc,MAAc,GAAG;CACpD,MAAM,IAAI,KAAK,OAAO,IAAI;AAC1B,QAAO,KACJ,MAAM,KAAK,CACX,KAAK,MAAO,EAAE,WAAW,IAAI,IAAI,IAAI,EAAG,CACxC,KAAK,KAAK"}
|
package/dist/server/create.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createProxy } from "./proxy.js";
|
|
2
1
|
import { InlineCodeUsageGenerator } from "../requests/generators/index.js";
|
|
2
|
+
import { createProxy } from "./proxy.js";
|
|
3
3
|
import { Document } from "../types.js";
|
|
4
4
|
import { ProcessedDocument } from "../utils/process-document.js";
|
|
5
5
|
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { OpenAPIV3, OpenAPIV3_2 } from "./_openapi/types.js";
|
|
2
|
-
import { NoReference } from "./utils/schema/index.js";
|
|
3
1
|
import { MediaAdapter } from "./requests/media/adapter.js";
|
|
2
|
+
import { NoReference } from "./utils/schema/index.js";
|
|
4
3
|
import { InlineCodeUsageGenerator } from "./requests/generators/index.js";
|
|
4
|
+
import { boundary_d_exports } from "./ui/client/boundary.js";
|
|
5
|
+
import { OpenAPIV3, OpenAPIV3_2 } from "./_openapi/types.js";
|
|
5
6
|
import { OpenAPIOptions } from "./server/create.js";
|
|
6
7
|
import { CreateAPIPageOptions } from "./ui/base.js";
|
|
7
8
|
import { ProcessedDocument } from "./utils/process-document.js";
|
|
@@ -36,6 +37,7 @@ interface RenderContext extends Pick<OpenAPIOptions, 'proxyUrl'>, Omit<RequireKe
|
|
|
36
37
|
* dereferenced schema
|
|
37
38
|
*/
|
|
38
39
|
schema: ProcessedDocument;
|
|
40
|
+
clientBoundary: typeof boundary_d_exports;
|
|
39
41
|
mediaAdapters: Record<string, MediaAdapter>;
|
|
40
42
|
renderHeading: (depth: number, text: string | ReactNode, props?: HTMLAttributes<HTMLHeadingElement> & {
|
|
41
43
|
id?: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;;KASY,QAAA,GAAW,WAAA,CAAY,QAAA;AAAA,KACvB,eAAA,GAAkB,WAAA,CAAY,eAAA;AAAA,KAC9B,eAAA,GAAkB,WAAA,CAAY,eAAA;AAAA,KAC9B,oBAAA,GAAuB,WAAA,CAAY,oBAAA;AAAA,KACnC,eAAA,GAAkB,WAAA,CAAY,eAAA;AAAA,KAC9B,cAAA,GAAiB,WAAA,CAAY,cAAA;AAAA,KAC7B,SAAA,GAAY,WAAA,CAAY,SAAA;AAAA,KACxB,YAAA,GAAe,WAAA,CAAY,YAAA;AAAA,KAC3B,cAAA,GAAiB,WAAA,CAAY,cAAA;AAAA,KAC7B,oBAAA,GAAuB,SAAA,CAAU,oBAAA;AAAA,KACjC,cAAA,GAAiB,WAAA,CAAY,cAAA;AAAA,KAC7B,oBAAA,GAAuB,WAAA,CAAY,oBAAA;AAAA,KACnC,WAAA,GAAc,WAAA,CAAY,WAAA;AAAA,KAC1B,aAAA,GAAgB,WAAA,CAAY,aAAA;AAAA,KAC5B,eAAA,GAAkB,WAAA,CAAY,eAAA;AAAA,KAC9B,iBAAA,GAAoB,WAAA,CAAY,iBAAA;AAAA,KAEhC,iBAAA,GAAoB,WAAA,CAAY,eAAA;EAC1C,MAAA;EACA,eAAA,GAAkB,wBAAA;EAClB,sBAAA;EACA,uBAAA;AAAA;AAAA,KAGG,WAAA,oBAA+B,CAAA,IAAK,IAAA,CAAK,CAAA,EAAG,CAAA,IAAK,QAAA,CAAS,IAAA,CAAK,CAAA,EAAG,CAAA;AAAA,UAEtD,aAAA,SAEb,IAAA,CAAK,cAAA,eACL,IAAA,CACE,WAAA,CAAY,oBAAA;EA1BN;;;EAgCV,MAAA,EAAQ,iBAAA;EACR,cAAA,SADyB,kBAAA;EAGzB,aAAA,EAAe,MAAA,SAAe,YAAA;EAE9B,aAAA,GACE,KAAA,UACA,IAAA,WAAe,SAAA,EACf,KAAA,GAAQ,cAAA,CAAe,kBAAA;IAAwB,EAAA;EAAA,MAC5C,SAAA;EACL,eAAA,GAAkB,IAAA,UAAc,IAAA,aAAiB,SAAA;AAAA;AAAA,KAGvC,gBAAA,cAA8B,WAAA,IAAe,CAAA,mBAAoB,IAAA,CAAK,CAAA,EAAG,CAAA;AAAA,KACzE,SAAA,MAAe,CAAA,GAAI,OAAA,CAAQ,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-page.d.ts","names":[],"sources":["../../src/ui/api-page.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"api-page.d.ts","names":[],"sources":["../../src/ui/api-page.tsx"],"mappings":";;UAIiB,YAAA;EACf,QAAA;EACA,SAAA;EACA,eAAA;EAH2B;;;EAQ3B,UAAA,GAAa,aAAA;EAEb,QAAA,GAAW,WAAA;AAAA;AAAA,UAGI,WAAA;EALF;;;EASb,IAAA;EACA,MAAA,EAAQ,WAAA;AAAA;AAAA,UAGO,aAAA;;;;EAIf,IAAA;EAPQ;;;EAWR,MAAA,EAAQ,WAAA;AAAA"}
|
package/dist/ui/api-page.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createMethod } from "../utils/schema/index.js";
|
|
2
|
-
import { ApiProviderLazy, ServerProviderLazy } from "./contexts/api.lazy.js";
|
|
3
2
|
import { Operation } from "./operation/index.js";
|
|
4
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
4
|
//#region src/ui/api-page.tsx
|
|
@@ -45,10 +44,10 @@ function APIPage({ showTitle: hasHead = false, showDescription, operations, webh
|
|
|
45
44
|
};
|
|
46
45
|
})
|
|
47
46
|
}, ctx);
|
|
48
|
-
return /* @__PURE__ */ jsx(
|
|
47
|
+
return /* @__PURE__ */ jsx(ctx.clientBoundary.ApiProvider, {
|
|
49
48
|
shikiOptions: ctx.shikiOptions,
|
|
50
49
|
client: ctx.client ?? {},
|
|
51
|
-
children: /* @__PURE__ */ jsx(
|
|
50
|
+
children: /* @__PURE__ */ jsx(ctx.clientBoundary.ServerProvider, {
|
|
52
51
|
servers: dereferenced.servers,
|
|
53
52
|
children: content
|
|
54
53
|
})
|
package/dist/ui/api-page.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-page.js","names":[],"sources":["../../src/ui/api-page.tsx"],"sourcesContent":["import { Operation } from '@/ui/operation';\nimport type { HttpMethods, RenderContext, ServerObject } from '@/types';\nimport { createMethod } from '@/utils/schema';\
|
|
1
|
+
{"version":3,"file":"api-page.js","names":[],"sources":["../../src/ui/api-page.tsx"],"sourcesContent":["import { Operation } from '@/ui/operation';\nimport type { HttpMethods, RenderContext, ServerObject } from '@/types';\nimport { createMethod } from '@/utils/schema';\n\nexport interface ApiPageProps {\n document: string;\n showTitle?: boolean;\n showDescription?: boolean;\n\n /**\n * An array of operations\n */\n operations?: OperationItem[];\n\n webhooks?: WebhookItem[];\n}\n\nexport interface WebhookItem {\n /**\n * webhook name in `webhooks`\n */\n name: string;\n method: HttpMethods;\n}\n\nexport interface OperationItem {\n /**\n * the path of operation in `paths`\n */\n path: string;\n /**\n * the HTTP method of operation\n */\n method: HttpMethods;\n}\n\nexport function APIPage({\n showTitle: hasHead = false,\n showDescription,\n operations,\n webhooks,\n ctx,\n}: Omit<ApiPageProps, 'document'> & {\n ctx: RenderContext;\n}) {\n const { dereferenced } = ctx.schema;\n let { renderPageLayout } = ctx.content ?? {};\n renderPageLayout ??= (slots) => (\n <div className=\"flex flex-col gap-24 text-sm @container\">\n {slots.operations?.map((op) => op.children)}\n {slots.webhooks?.map((op) => op.children)}\n </div>\n );\n\n const content = renderPageLayout(\n {\n operations: operations?.map((item) => {\n const pathItem = dereferenced.paths?.[item.path];\n if (!pathItem)\n throw new Error(`[Fumadocs OpenAPI] Path not found in OpenAPI schema: ${item.path}`);\n\n const operation = pathItem[item.method];\n if (!operation)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in operation: ${item.path}`,\n );\n\n const method = createMethod(item.method, pathItem, operation);\n\n return {\n item,\n children: (\n <Operation\n key={`${item.path}:${item.method}`}\n method={method}\n path={item.path}\n ctx={ctx}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n webhooks: webhooks?.map((item) => {\n const webhook = dereferenced.webhooks?.[item.name];\n if (!webhook)\n throw new Error(`[Fumadocs OpenAPI] Webhook not found in OpenAPI schema: ${item.name}`);\n\n const hook = webhook[item.method];\n if (!hook)\n throw new Error(\n `[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`,\n );\n\n return {\n item,\n children: (\n <Operation\n type=\"webhook\"\n key={`${item.name}:${item.method}`}\n method={createMethod(item.method, webhook, hook)}\n ctx={ctx}\n path={`/${item.name}`}\n showTitle={hasHead}\n showDescription={showDescription}\n />\n ),\n };\n }),\n },\n ctx,\n );\n\n return (\n <ctx.clientBoundary.ApiProvider shikiOptions={ctx.shikiOptions} client={ctx.client ?? {}}>\n <ctx.clientBoundary.ServerProvider servers={dereferenced.servers as ServerObject[]}>\n {content}\n </ctx.clientBoundary.ServerProvider>\n </ctx.clientBoundary.ApiProvider>\n );\n}\n"],"mappings":";;;;AAoCA,SAAgB,QAAQ,EACtB,WAAW,UAAU,OACrB,iBACA,YACA,UACA,OAGC;CACD,MAAM,EAAE,iBAAiB,IAAI;CAC7B,IAAI,EAAE,qBAAqB,IAAI,WAAW,EAAE;AAC5C,uBAAsB,UACpB,qBAAC,OAAD;EAAK,WAAU;YAAf,CACG,MAAM,YAAY,KAAK,OAAO,GAAG,SAAS,EAC1C,MAAM,UAAU,KAAK,OAAO,GAAG,SAAS,CACrC;;CAGR,MAAM,UAAU,iBACd;EACE,YAAY,YAAY,KAAK,SAAS;GACpC,MAAM,WAAW,aAAa,QAAQ,KAAK;AAC3C,OAAI,CAAC,SACH,OAAM,IAAI,MAAM,wDAAwD,KAAK,OAAO;GAEtF,MAAM,YAAY,SAAS,KAAK;AAChC,OAAI,CAAC,UACH,OAAM,IAAI,MACR,6BAA6B,KAAK,OAAO,2BAA2B,KAAK,OAC1E;AAIH,UAAO;IACL;IACA,UACE,oBAAC,WAAD;KAEE,QAPS,aAAa,KAAK,QAAQ,UAAU,UAAU;KAQvD,MAAM,KAAK;KACN;KACL,WAAW;KACM;KACjB,EANK,GAAG,KAAK,KAAK,GAAG,KAAK,SAM1B;IAEL;IACD;EACF,UAAU,UAAU,KAAK,SAAS;GAChC,MAAM,UAAU,aAAa,WAAW,KAAK;AAC7C,OAAI,CAAC,QACH,OAAM,IAAI,MAAM,2DAA2D,KAAK,OAAO;GAEzF,MAAM,OAAO,QAAQ,KAAK;AAC1B,OAAI,CAAC,KACH,OAAM,IAAI,MACR,6BAA6B,KAAK,OAAO,yBAAyB,KAAK,OACxE;AAEH,UAAO;IACL;IACA,UACE,oBAAC,WAAD;KACE,MAAK;KAEL,QAAQ,aAAa,KAAK,QAAQ,SAAS,KAAK;KAC3C;KACL,MAAM,IAAI,KAAK;KACf,WAAW;KACM;KACjB,EANK,GAAG,KAAK,KAAK,GAAG,KAAK,SAM1B;IAEL;IACD;EACH,EACD,IACD;AAED,QACE,oBAAC,IAAI,eAAe,aAApB;EAAgC,cAAc,IAAI;EAAc,QAAQ,IAAI,UAAU,EAAE;YACtF,oBAAC,IAAI,eAAe,gBAApB;GAAmC,SAAS,aAAa;aACtD;GACiC,CAAA;EACL,CAAA"}
|
package/dist/ui/base.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { NoReference } from "../utils/schema/index.js";
|
|
2
1
|
import { MediaAdapter } from "../requests/media/adapter.js";
|
|
2
|
+
import { NoReference } from "../utils/schema/index.js";
|
|
3
3
|
import { CodeUsageGeneratorRegistry, InlineCodeUsageGenerator } from "../requests/generators/index.js";
|
|
4
|
-
import { OpenAPIServer } from "../server/create.js";
|
|
5
|
-
import { ApiPageProps, OperationItem, WebhookItem } from "./api-page.js";
|
|
6
4
|
import { ExampleRequestItem } from "./operation/get-example-requests.js";
|
|
7
5
|
import { APIPageClientOptions } from "./client/index.js";
|
|
8
6
|
import { SchemaUIOptions } from "./schema/index.js";
|
|
7
|
+
import { OpenAPIServer } from "../server/create.js";
|
|
8
|
+
import { ApiPageProps, OperationItem, WebhookItem } from "./api-page.js";
|
|
9
9
|
import { ResponseTab } from "./operation/response-tabs.js";
|
|
10
10
|
import { ClientCodeBlockProvider } from "./components/codeblock.js";
|
|
11
11
|
import { Awaitable, MethodInformation, RenderContext } from "../types.js";
|
package/dist/ui/base.js
CHANGED
|
@@ -40,9 +40,18 @@ function createAPIPage(server, options) {
|
|
|
40
40
|
if (typeof document === "string") processed = await server.getSchema(document);
|
|
41
41
|
else processed = document;
|
|
42
42
|
const slugger = new Slugger();
|
|
43
|
+
const { ApiProvider, PlaygroundClient, SchemaUI, ServerProvider, UsageTab, UsageTabsSelector } = await import("./client/boundary.lazy.js");
|
|
43
44
|
const ctx = {
|
|
44
45
|
schema: processed,
|
|
45
46
|
proxyUrl: server.options.proxyUrl,
|
|
47
|
+
clientBoundary: {
|
|
48
|
+
ApiProvider,
|
|
49
|
+
PlaygroundClient,
|
|
50
|
+
SchemaUI,
|
|
51
|
+
ServerProvider,
|
|
52
|
+
UsageTab,
|
|
53
|
+
UsageTabsSelector
|
|
54
|
+
},
|
|
46
55
|
...options,
|
|
47
56
|
mediaAdapters: {
|
|
48
57
|
...defaultAdapters,
|
package/dist/ui/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","names":[],"sources":["../../src/ui/base.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport Slugger from 'github-slugger';\nimport type { Awaitable, MethodInformation, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters, MediaAdapter } from '@/requests/media/adapter';\nimport type { FC, HTMLAttributes, ReactNode } from 'react';\nimport type { OpenAPIServer } from '@/server';\nimport type { APIPageClientOptions } from './client';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { createRehypeCode } from 'fumadocs-core/mdx-plugins/rehype-code.core';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';\nimport type { SchemaUIOptions } from './schema';\nimport type { ResponseTab } from './operation/response-tabs';\nimport { APIPage, type ApiPageProps, type OperationItem, type WebhookItem } from './api-page';\nimport type { CodeUsageGeneratorRegistry, InlineCodeUsageGenerator } from '@/requests/generators';\nimport type { JSONSchema } from 'json-schema-typed';\nimport type { BundledTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from 'shiki';\nimport { highlightHast, type ShikiFactory } from 'fumadocs-core/highlight/shiki';\nimport type { ExampleRequestItem } from './operation/get-example-requests';\nimport { compile } from '@fumari/json-schema-ts';\n\nexport interface GenerateTypeScriptDefinitionsContext extends RenderContext {\n operation: NoReference<MethodInformation>;\n readOnly: boolean;\n writeOnly: boolean;\n /** @deprecated */\n _internal_legacy?: {\n statusCode: string;\n contentType: string;\n };\n}\n\nexport interface CreateAPIPageOptions {\n /**\n * Generate TypeScript definitions from response schema.\n *\n * Pass `false` to disable it.\n *\n * @param method - the operation object\n * @param statusCode - status code\n * @deprecated use `generateTypeScriptDefinitions` instead.\n */\n generateTypeScriptSchema?:\n | ((\n method: NoReference<MethodInformation>,\n statusCode: string,\n contentType: string,\n ctx: RenderContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate TypeScript definitions from JSON schema.\n *\n * Pass `false` to disable it.\n */\n generateTypeScriptDefinitions?:\n | ((\n schema: JSONSchema,\n ctx: GenerateTypeScriptDefinitionsContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate example code usage for all endpoints.\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n\n /**\n * Generate example code usage for each endpoint.\n */\n generateCodeSamples?: (method: MethodInformation) => InlineCodeUsageGenerator[];\n\n shiki: ShikiFactory;\n renderMarkdown?: (md: string) => ReactNode;\n shikiOptions: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BundledTheme>;\n\n /**\n * Show full response schema instead of only example response & Typescript definitions.\n *\n * @default true\n */\n showResponseSchema?: boolean;\n\n /**\n * Support other media types (for server-side generation).\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * Customise page content\n */\n content?: {\n renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => ReactNode;\n\n renderRequestTabs?: (\n items: ExampleRequestItem[],\n ctx: RenderContext & {\n route: string;\n operation: NoReference<MethodInformation>;\n },\n ) => ReactNode;\n\n renderAPIExampleLayout?: (\n slots: {\n selector: ReactNode;\n usageTabs: ReactNode;\n responseTabs: ReactNode;\n },\n ctx: RenderContext,\n ) => ReactNode;\n\n /**\n * @param generators - codegens for API example usages\n */\n renderAPIExampleUsageTabs?: (\n generators: CodeUsageGeneratorRegistry,\n ctx: RenderContext,\n ) => ReactNode;\n\n /**\n * renderer of the entire page's layout (containing all operations & webhooks UI)\n */\n renderPageLayout?: (\n slots: {\n operations?: {\n item: OperationItem;\n children: ReactNode;\n }[];\n webhooks?: {\n item: WebhookItem;\n children: ReactNode;\n }[];\n },\n ctx: RenderContext,\n ) => ReactNode;\n\n renderOperationLayout?: (\n slots: {\n header: ReactNode;\n description: ReactNode;\n apiExample: ReactNode;\n apiPlayground: ReactNode;\n\n authSchemes: ReactNode;\n parameters: ReactNode;\n body: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n },\n ctx: RenderContext,\n method: NoReference<MethodInformation>,\n ) => ReactNode;\n\n renderWebhookLayout?: (slots: {\n header: ReactNode;\n description: ReactNode;\n authSchemes: ReactNode;\n parameters: ReactNode;\n body: ReactNode;\n requests: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n }) => ReactNode;\n };\n\n /**\n * Info UI for JSON schemas\n */\n schemaUI?: {\n render?: (options: SchemaUIOptions, ctx: RenderContext) => ReactNode;\n\n /**\n * Show examples under the generated content of JSON schemas.\n *\n * @defaultValue false\n */\n showExample?: boolean;\n };\n\n /**\n * Customise API playground\n */\n playground?: {\n /**\n * @defaultValue true\n */\n enabled?: boolean;\n /**\n * replace the server-side renderer\n */\n render?: (props: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n }) => Awaitable<ReactNode>;\n };\n\n renderHeading?: (props: HTMLAttributes<HTMLHeadingElement>, depth: number) => ReactNode;\n renderCodeBlock?: (props: { lang: string; code: string }) => ReactNode;\n\n client?: APIPageClientOptions;\n}\n\nexport interface ServerApiPageProps extends Omit<ApiPageProps, 'document'> {\n document: string | ProcessedDocument;\n}\n\nexport function createAPIPage(\n server: OpenAPIServer,\n options: CreateAPIPageOptions,\n): FC<ServerApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: defaultMdxComponents,\n });\n };\n }\n\n return remark()\n .use(remarkGfm)\n .use(remarkRehype)\n .use(createRehypeCode(options.shiki), {\n langs: [],\n lazy: true,\n defaultColor: false,\n ...options.shikiOptions,\n })\n .use(rehypeReact);\n }\n\n return async function APIPageWrapper({ document, ...props }) {\n let processed: ProcessedDocument;\n if (typeof document === 'string') {\n processed = await server.getSchema(document);\n } else {\n processed = document;\n }\n\n const slugger = new Slugger();\n\n const ctx: RenderContext = {\n schema: processed,\n proxyUrl: server.options.proxyUrl,\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n renderHeading(depth, text, props) {\n const id = typeof text === 'string' ? slugger.slug(text) : props?.id;\n if (!id) throw new Error(\"missing 'id' for non-string children\");\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n generateTypeScriptDefinitions:\n options.generateTypeScriptDefinitions ??\n ((schema, ctx) => {\n if (options.generateTypeScriptSchema && ctx._internal_legacy) {\n const { statusCode, contentType } = ctx._internal_legacy;\n return options.generateTypeScriptSchema(ctx.operation, statusCode, contentType, ctx);\n }\n\n if (typeof schema !== 'object') return;\n try {\n return compile(schema, {\n name: 'Response',\n readOnly: ctx.readOnly,\n writeOnly: ctx.writeOnly,\n getSchemaId: ctx.schema.getRawRef,\n });\n } catch (e) {\n console.warn('Failed to generate typescript schema:', e);\n }\n }),\n async renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n const out = await processor.process({\n value: text,\n });\n\n return out.result as ReactNode;\n },\n async renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n const hast = await highlightHast(await options.shiki.getOrInit(), code, {\n lang,\n defaultColor: false,\n ...options.shikiOptions,\n });\n const rendered = toJsxRuntime(hast, {\n ...JsxRuntime,\n components: {\n pre: Pre,\n },\n });\n\n return <CodeBlock className=\"my-0\">{rendered}</CodeBlock>;\n },\n };\n\n return <APIPage {...props} ctx={ctx} />;\n };\n}\n\nexport { ClientCodeBlockProvider } from './components/codeblock';\n"],"mappings":";;;;;;;;;;;;;;;;;AAuNA,SAAgB,cACd,QACA,SACwB;CACxB,IAAI;CAEJ,SAAS,0BAA0B;EACjC,SAAS,cAAuB;AAC9B,QAAK,YAAY,MAAW,SAAc;AACxC,WAAO,aAAa,MAAM;KACxB,aAAa;KACb,UAAU,KAAK;KACf,GAAG;KACH,YAAY;KACb,CAAC;;;AAIN,SAAO,QAAQ,CACZ,IAAI,UAAU,CACd,IAAI,aAAa,CACjB,IAAI,iBAAiB,QAAQ,MAAM,EAAE;GACpC,OAAO,EAAE;GACT,MAAM;GACN,cAAc;GACd,GAAG,QAAQ;GACZ,CAAC,CACD,IAAI,YAAY;;AAGrB,QAAO,eAAe,eAAe,EAAE,UAAU,GAAG,SAAS;EAC3D,IAAI;AACJ,MAAI,OAAO,aAAa,SACtB,aAAY,MAAM,OAAO,UAAU,SAAS;MAE5C,aAAY;EAGd,MAAM,UAAU,IAAI,SAAS;EAE7B,MAAM,MAAqB;GACzB,QAAQ;GACR,UAAU,OAAO,QAAQ;GACzB,GAAG;GACH,eAAe;IACb,GAAG;IACH,GAAG,QAAQ;IACZ;GACD,cAAc,OAAO,MAAM,OAAO;IAChC,MAAM,KAAK,OAAO,SAAS,WAAW,QAAQ,KAAK,KAAK,GAAG,OAAO;AAClE,QAAI,CAAC,GAAI,OAAM,IAAI,MAAM,uCAAuC;AAEhE,QAAI,QAAQ,cACV,QAAO,QAAQ,cAAc;KAAE;KAAI,UAAU;KAAM,GAAG;KAAO,EAAE,MAAM;AAGvE,WACE,oBAAC,SAAD;KAAa;KAAa,IAAI,IAAI;KAAiB,GAAI;eACpD;KACO,EAFY,GAEZ;;GAGd,+BACE,QAAQ,mCACN,QAAQ,QAAQ;AAChB,QAAI,QAAQ,4BAA4B,IAAI,kBAAkB;KAC5D,MAAM,EAAE,YAAY,gBAAgB,IAAI;AACxC,YAAO,QAAQ,yBAAyB,IAAI,WAAW,YAAY,aAAa,IAAI;;AAGtF,QAAI,OAAO,WAAW,SAAU;AAChC,QAAI;AACF,YAAO,QAAQ,QAAQ;MACrB,MAAM;MACN,UAAU,IAAI;MACd,WAAW,IAAI;MACf,aAAa,IAAI,OAAO;MACzB,CAAC;aACK,GAAG;AACV,aAAQ,KAAK,yCAAyC,EAAE;;;GAG9D,MAAM,eAAe,MAAM;AACzB,QAAI,QAAQ,eAAgB,QAAO,QAAQ,eAAe,KAAK;AAC/D,kBAAc,yBAAyB;AAMvC,YAJY,MAAM,UAAU,QAAQ,EAClC,OAAO,MACR,CAAC,EAES;;GAEb,MAAM,gBAAgB,MAAM,MAAM;AAChC,QAAI,QAAQ,gBACV,QAAO,QAAQ,gBAAgB;KAAE;KAAM;KAAM,CAAC;AAehD,WAAO,oBAAC,WAAD;KAAW,WAAU;eAPX,aALJ,MAAM,cAAc,MAAM,QAAQ,MAAM,WAAW,EAAE,MAAM;MACtE;MACA,cAAc;MACd,GAAG,QAAQ;MACZ,CAAC,EACkC;MAClC,GAAG;MACH,YAAY,EACV,KAAK,KACN;MACF,CAAC;KAEuD,CAAA;;GAE5D;AAED,SAAO,oBAAC,SAAD;GAAS,GAAI;GAAY;GAAO,CAAA"}
|
|
1
|
+
{"version":3,"file":"base.js","names":[],"sources":["../../src/ui/base.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport Slugger from 'github-slugger';\nimport type { Awaitable, MethodInformation, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters, MediaAdapter } from '@/requests/media/adapter';\nimport type { FC, HTMLAttributes, ReactNode } from 'react';\nimport type { OpenAPIServer } from '@/server';\nimport type { APIPageClientOptions } from './client';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { createRehypeCode } from 'fumadocs-core/mdx-plugins/rehype-code.core';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';\nimport type { SchemaUIOptions } from './schema';\nimport type { ResponseTab } from './operation/response-tabs';\nimport { APIPage, type ApiPageProps, type OperationItem, type WebhookItem } from './api-page';\nimport type { CodeUsageGeneratorRegistry, InlineCodeUsageGenerator } from '@/requests/generators';\nimport type { JSONSchema } from 'json-schema-typed';\nimport type { BundledTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from 'shiki';\nimport { highlightHast, type ShikiFactory } from 'fumadocs-core/highlight/shiki';\nimport type { ExampleRequestItem } from './operation/get-example-requests';\nimport { compile } from '@fumari/json-schema-ts';\n\nexport interface GenerateTypeScriptDefinitionsContext extends RenderContext {\n operation: NoReference<MethodInformation>;\n readOnly: boolean;\n writeOnly: boolean;\n /** @deprecated */\n _internal_legacy?: {\n statusCode: string;\n contentType: string;\n };\n}\n\nexport interface CreateAPIPageOptions {\n /**\n * Generate TypeScript definitions from response schema.\n *\n * Pass `false` to disable it.\n *\n * @param method - the operation object\n * @param statusCode - status code\n * @deprecated use `generateTypeScriptDefinitions` instead.\n */\n generateTypeScriptSchema?:\n | ((\n method: NoReference<MethodInformation>,\n statusCode: string,\n contentType: string,\n ctx: RenderContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate TypeScript definitions from JSON schema.\n *\n * Pass `false` to disable it.\n */\n generateTypeScriptDefinitions?:\n | ((\n schema: JSONSchema,\n ctx: GenerateTypeScriptDefinitionsContext,\n ) => Awaitable<string | undefined>)\n | false;\n\n /**\n * Generate example code usage for all endpoints.\n */\n codeUsages?: CodeUsageGeneratorRegistry;\n\n /**\n * Generate example code usage for each endpoint.\n */\n generateCodeSamples?: (method: MethodInformation) => InlineCodeUsageGenerator[];\n\n shiki: ShikiFactory;\n renderMarkdown?: (md: string) => ReactNode;\n shikiOptions: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BundledTheme>;\n\n /**\n * Show full response schema instead of only example response & Typescript definitions.\n *\n * @default true\n */\n showResponseSchema?: boolean;\n\n /**\n * Support other media types (for server-side generation).\n */\n mediaAdapters?: Record<string, MediaAdapter>;\n\n /**\n * Customise page content\n */\n content?: {\n renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => ReactNode;\n\n renderRequestTabs?: (\n items: ExampleRequestItem[],\n ctx: RenderContext & {\n route: string;\n operation: NoReference<MethodInformation>;\n },\n ) => ReactNode;\n\n renderAPIExampleLayout?: (\n slots: {\n selector: ReactNode;\n usageTabs: ReactNode;\n responseTabs: ReactNode;\n },\n ctx: RenderContext,\n ) => ReactNode;\n\n /**\n * @param generators - codegens for API example usages\n */\n renderAPIExampleUsageTabs?: (\n generators: CodeUsageGeneratorRegistry,\n ctx: RenderContext,\n ) => ReactNode;\n\n /**\n * renderer of the entire page's layout (containing all operations & webhooks UI)\n */\n renderPageLayout?: (\n slots: {\n operations?: {\n item: OperationItem;\n children: ReactNode;\n }[];\n webhooks?: {\n item: WebhookItem;\n children: ReactNode;\n }[];\n },\n ctx: RenderContext,\n ) => ReactNode;\n\n renderOperationLayout?: (\n slots: {\n header: ReactNode;\n description: ReactNode;\n apiExample: ReactNode;\n apiPlayground: ReactNode;\n\n authSchemes: ReactNode;\n parameters: ReactNode;\n body: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n },\n ctx: RenderContext,\n method: NoReference<MethodInformation>,\n ) => ReactNode;\n\n renderWebhookLayout?: (slots: {\n header: ReactNode;\n description: ReactNode;\n authSchemes: ReactNode;\n parameters: ReactNode;\n body: ReactNode;\n requests: ReactNode;\n responses: ReactNode;\n callbacks: ReactNode;\n }) => ReactNode;\n };\n\n /**\n * Info UI for JSON schemas\n */\n schemaUI?: {\n render?: (options: SchemaUIOptions, ctx: RenderContext) => ReactNode;\n\n /**\n * Show examples under the generated content of JSON schemas.\n *\n * @defaultValue false\n */\n showExample?: boolean;\n };\n\n /**\n * Customise API playground\n */\n playground?: {\n /**\n * @defaultValue true\n */\n enabled?: boolean;\n /**\n * replace the server-side renderer\n */\n render?: (props: {\n path: string;\n method: MethodInformation;\n ctx: RenderContext;\n }) => Awaitable<ReactNode>;\n };\n\n renderHeading?: (props: HTMLAttributes<HTMLHeadingElement>, depth: number) => ReactNode;\n renderCodeBlock?: (props: { lang: string; code: string }) => ReactNode;\n\n client?: APIPageClientOptions;\n}\n\nexport interface ServerApiPageProps extends Omit<ApiPageProps, 'document'> {\n document: string | ProcessedDocument;\n}\n\nexport function createAPIPage(\n server: OpenAPIServer,\n options: CreateAPIPageOptions,\n): FC<ServerApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: defaultMdxComponents,\n });\n };\n }\n\n return remark()\n .use(remarkGfm)\n .use(remarkRehype)\n .use(createRehypeCode(options.shiki), {\n langs: [],\n lazy: true,\n defaultColor: false,\n ...options.shikiOptions,\n })\n .use(rehypeReact);\n }\n\n return async function APIPageWrapper({ document, ...props }) {\n let processed: ProcessedDocument;\n if (typeof document === 'string') {\n processed = await server.getSchema(document);\n } else {\n processed = document;\n }\n\n const slugger = new Slugger();\n const { ApiProvider, PlaygroundClient, SchemaUI, ServerProvider, UsageTab, UsageTabsSelector } =\n await import('@/ui/client/boundary.lazy');\n\n const ctx: RenderContext = {\n schema: processed,\n proxyUrl: server.options.proxyUrl,\n clientBoundary: {\n ApiProvider,\n PlaygroundClient,\n SchemaUI,\n ServerProvider,\n UsageTab,\n UsageTabsSelector,\n },\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n renderHeading(depth, text, props) {\n const id = typeof text === 'string' ? slugger.slug(text) : props?.id;\n if (!id) throw new Error(\"missing 'id' for non-string children\");\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n generateTypeScriptDefinitions:\n options.generateTypeScriptDefinitions ??\n ((schema, ctx) => {\n if (options.generateTypeScriptSchema && ctx._internal_legacy) {\n const { statusCode, contentType } = ctx._internal_legacy;\n return options.generateTypeScriptSchema(ctx.operation, statusCode, contentType, ctx);\n }\n\n if (typeof schema !== 'object') return;\n try {\n return compile(schema, {\n name: 'Response',\n readOnly: ctx.readOnly,\n writeOnly: ctx.writeOnly,\n getSchemaId: ctx.schema.getRawRef,\n });\n } catch (e) {\n console.warn('Failed to generate typescript schema:', e);\n }\n }),\n async renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n const out = await processor.process({\n value: text,\n });\n\n return out.result as ReactNode;\n },\n async renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n const hast = await highlightHast(await options.shiki.getOrInit(), code, {\n lang,\n defaultColor: false,\n ...options.shikiOptions,\n });\n const rendered = toJsxRuntime(hast, {\n ...JsxRuntime,\n components: {\n pre: Pre,\n },\n });\n\n return <CodeBlock className=\"my-0\">{rendered}</CodeBlock>;\n },\n };\n\n return <APIPage {...props} ctx={ctx} />;\n };\n}\n\nexport { ClientCodeBlockProvider } from './components/codeblock';\n"],"mappings":";;;;;;;;;;;;;;;;;AAuNA,SAAgB,cACd,QACA,SACwB;CACxB,IAAI;CAEJ,SAAS,0BAA0B;EACjC,SAAS,cAAuB;AAC9B,QAAK,YAAY,MAAW,SAAc;AACxC,WAAO,aAAa,MAAM;KACxB,aAAa;KACb,UAAU,KAAK;KACf,GAAG;KACH,YAAY;KACb,CAAC;;;AAIN,SAAO,QAAQ,CACZ,IAAI,UAAU,CACd,IAAI,aAAa,CACjB,IAAI,iBAAiB,QAAQ,MAAM,EAAE;GACpC,OAAO,EAAE;GACT,MAAM;GACN,cAAc;GACd,GAAG,QAAQ;GACZ,CAAC,CACD,IAAI,YAAY;;AAGrB,QAAO,eAAe,eAAe,EAAE,UAAU,GAAG,SAAS;EAC3D,IAAI;AACJ,MAAI,OAAO,aAAa,SACtB,aAAY,MAAM,OAAO,UAAU,SAAS;MAE5C,aAAY;EAGd,MAAM,UAAU,IAAI,SAAS;EAC7B,MAAM,EAAE,aAAa,kBAAkB,UAAU,gBAAgB,UAAU,sBACzE,MAAM,OAAO;EAEf,MAAM,MAAqB;GACzB,QAAQ;GACR,UAAU,OAAO,QAAQ;GACzB,gBAAgB;IACd;IACA;IACA;IACA;IACA;IACA;IACD;GACD,GAAG;GACH,eAAe;IACb,GAAG;IACH,GAAG,QAAQ;IACZ;GACD,cAAc,OAAO,MAAM,OAAO;IAChC,MAAM,KAAK,OAAO,SAAS,WAAW,QAAQ,KAAK,KAAK,GAAG,OAAO;AAClE,QAAI,CAAC,GAAI,OAAM,IAAI,MAAM,uCAAuC;AAEhE,QAAI,QAAQ,cACV,QAAO,QAAQ,cAAc;KAAE;KAAI,UAAU;KAAM,GAAG;KAAO,EAAE,MAAM;AAGvE,WACE,oBAAC,SAAD;KAAa;KAAa,IAAI,IAAI;KAAiB,GAAI;eACpD;KACO,EAFY,GAEZ;;GAGd,+BACE,QAAQ,mCACN,QAAQ,QAAQ;AAChB,QAAI,QAAQ,4BAA4B,IAAI,kBAAkB;KAC5D,MAAM,EAAE,YAAY,gBAAgB,IAAI;AACxC,YAAO,QAAQ,yBAAyB,IAAI,WAAW,YAAY,aAAa,IAAI;;AAGtF,QAAI,OAAO,WAAW,SAAU;AAChC,QAAI;AACF,YAAO,QAAQ,QAAQ;MACrB,MAAM;MACN,UAAU,IAAI;MACd,WAAW,IAAI;MACf,aAAa,IAAI,OAAO;MACzB,CAAC;aACK,GAAG;AACV,aAAQ,KAAK,yCAAyC,EAAE;;;GAG9D,MAAM,eAAe,MAAM;AACzB,QAAI,QAAQ,eAAgB,QAAO,QAAQ,eAAe,KAAK;AAC/D,kBAAc,yBAAyB;AAMvC,YAJY,MAAM,UAAU,QAAQ,EAClC,OAAO,MACR,CAAC,EAES;;GAEb,MAAM,gBAAgB,MAAM,MAAM;AAChC,QAAI,QAAQ,gBACV,QAAO,QAAQ,gBAAgB;KAAE;KAAM;KAAM,CAAC;AAehD,WAAO,oBAAC,WAAD;KAAW,WAAU;eAPX,aALJ,MAAM,cAAc,MAAM,QAAQ,MAAM,WAAW,EAAE,MAAM;MACtE;MACA,cAAc;MACd,GAAG,QAAQ;MACZ,CAAC,EACkC;MAClC,GAAG;MACH,YAAY,EACV,KAAK,KACN;MACF,CAAC;KAEuD,CAAA;;GAE5D;AAED,SAAO,oBAAC,SAAD;GAAS,GAAI;GAAY;GAAO,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import PlaygroundClient from "../../playground/client.js";
|
|
2
|
+
import { ApiProvider, ServerProvider } from "../contexts/api.js";
|
|
3
|
+
import { UsageTab, UsageTabsSelector } from "../operation/usage-tabs/client.js";
|
|
4
|
+
import { SchemaUI } from "../schema/client.js";
|
|
5
|
+
|
|
6
|
+
//#region src/ui/client/boundary.d.ts
|
|
7
|
+
declare namespace boundary_d_exports {
|
|
8
|
+
export { ApiProvider, PlaygroundClient, SchemaUI, ServerProvider, UsageTab, UsageTabsSelector };
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { boundary_d_exports };
|
|
12
|
+
//# sourceMappingURL=boundary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","names":[],"sources":["../../../src/ui/client/boundary.tsx"],"mappings":""}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { __exportAll } from "../../_virtual/_rolldown/runtime.js";
|
|
3
|
+
import { ApiProvider, ServerProvider } from "../contexts/api.js";
|
|
4
|
+
import PlaygroundClient from "../../playground/client.js";
|
|
5
|
+
import { UsageTab, UsageTabsSelector } from "../operation/usage-tabs/client.js";
|
|
6
|
+
import { SchemaUI } from "../schema/client.js";
|
|
7
|
+
//#region src/ui/client/boundary.tsx
|
|
8
|
+
var boundary_exports = /* @__PURE__ */ __exportAll({
|
|
9
|
+
ApiProvider: () => ApiProvider,
|
|
10
|
+
PlaygroundClient: () => PlaygroundClient,
|
|
11
|
+
SchemaUI: () => SchemaUI,
|
|
12
|
+
ServerProvider: () => ServerProvider,
|
|
13
|
+
UsageTab: () => UsageTab,
|
|
14
|
+
UsageTabsSelector: () => UsageTabsSelector
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { boundary_exports };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.js","names":[],"sources":["../../../src/ui/client/boundary.tsx"],"sourcesContent":["'use client';\n\nexport { ApiProvider, ServerProvider } from '@/ui/contexts/api';\nexport { UsageTab, UsageTabsSelector } from '@/ui/operation/usage-tabs/client';\nexport { SchemaUI } from '@/ui/schema/client';\nexport { default as PlaygroundClient } from '@/playground/client';\n"],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { lazy } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/ui/client/boundary.lazy.tsx
|
|
5
|
+
const ApiProvider = wrapLazy(() => import("../contexts/api.js").then((mod) => ({ default: mod.ApiProvider })));
|
|
6
|
+
const ServerProvider = wrapLazy(() => import("../contexts/api.js").then((mod) => ({ default: mod.ServerProvider })));
|
|
7
|
+
const UsageTabsSelector = wrapLazy(() => import("../operation/usage-tabs/client.js").then((mod) => ({ default: mod.UsageTabsSelector })));
|
|
8
|
+
const UsageTab = wrapLazy(() => import("../operation/usage-tabs/client.js").then((mod) => ({ default: mod.UsageTab })));
|
|
9
|
+
const SchemaUI = wrapLazy(() => import("../schema/client.js").then((mod) => ({ default: mod.SchemaUI })));
|
|
10
|
+
const PlaygroundClient = wrapLazy(() => import("../../playground/client.js"));
|
|
11
|
+
function wrapLazy(load) {
|
|
12
|
+
const V = lazy(load);
|
|
13
|
+
return function wrapper(props) {
|
|
14
|
+
return /* @__PURE__ */ jsx(V, { ...props });
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ApiProvider, PlaygroundClient, SchemaUI, ServerProvider, UsageTab, UsageTabsSelector };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=boundary.lazy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"boundary.lazy.js","names":[],"sources":["../../../src/ui/client/boundary.lazy.tsx"],"sourcesContent":["'use client';\n\nimport { type ComponentType, lazy } from 'react';\n\n// the boundary between server & lazy client components\n\nexport const ApiProvider = wrapLazy(() =>\n import('@/ui/contexts/api').then((mod) => ({ default: mod.ApiProvider })),\n);\n\nexport const ServerProvider = wrapLazy(() =>\n import('@/ui/contexts/api').then((mod) => ({ default: mod.ServerProvider })),\n);\n\nexport const UsageTabsSelector = wrapLazy(() =>\n import('@/ui/operation/usage-tabs/client').then((mod) => ({ default: mod.UsageTabsSelector })),\n);\n\nexport const UsageTab = wrapLazy(() =>\n import('@/ui/operation/usage-tabs/client').then((mod) => ({ default: mod.UsageTab })),\n);\n\nexport const SchemaUI = wrapLazy(() =>\n import('@/ui/schema/client').then((mod) => ({ default: mod.SchemaUI })),\n);\n\nexport const PlaygroundClient = wrapLazy(() => import('@/playground/client'));\n\n// Waku wraps all export functions of a \"use client\" file in `React.lazy`, but `lazy(lazy(() => ...))` causes error.\n// we wrap another layer of component such that it is valid\n// TODO: perhaps we can remove it once Waku migrated to vite-rsc\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- type infer\nfunction wrapLazy<T extends ComponentType<any>>(load: () => Promise<{ default: T }>): T {\n const V = lazy(load);\n\n return function wrapper(props) {\n return <V {...props} />;\n } as T;\n}\n"],"mappings":";;;;AAMA,MAAa,cAAc,eACzB,OAAO,sBAAqB,MAAM,SAAS,EAAE,SAAS,IAAI,aAAa,EAAE,CAC1E;AAED,MAAa,iBAAiB,eAC5B,OAAO,sBAAqB,MAAM,SAAS,EAAE,SAAS,IAAI,gBAAgB,EAAE,CAC7E;AAED,MAAa,oBAAoB,eAC/B,OAAO,qCAAoC,MAAM,SAAS,EAAE,SAAS,IAAI,mBAAmB,EAAE,CAC/F;AAED,MAAa,WAAW,eACtB,OAAO,qCAAoC,MAAM,SAAS,EAAE,SAAS,IAAI,UAAU,EAAE,CACtF;AAED,MAAa,WAAW,eACtB,OAAO,uBAAsB,MAAM,SAAS,EAAE,SAAS,IAAI,UAAU,EAAE,CACxE;AAED,MAAa,mBAAmB,eAAe,OAAO,8BAAuB;AAM7E,SAAS,SAAuC,MAAwC;CACtF,MAAM,IAAI,KAAK,KAAK;AAEpB,QAAO,SAAS,QAAQ,OAAO;AAC7B,SAAO,oBAAC,GAAD,EAAG,GAAI,OAAS,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MediaAdapter } from "../../requests/media/adapter.js";
|
|
2
|
-
import { CodeUsageGeneratorRegistry } from "../../requests/generators/index.js";
|
|
3
2
|
import { PlaygroundClientOptions } from "../../playground/client.js";
|
|
3
|
+
import { CodeUsageGeneratorRegistry } from "../../requests/generators/index.js";
|
|
4
4
|
import { ExampleRequestItem } from "../operation/get-example-requests.js";
|
|
5
5
|
import { FC } from "react";
|
|
6
6
|
|
|
@@ -3,34 +3,34 @@ import { cn } from "../../utils/cn.js";
|
|
|
3
3
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./select.js";
|
|
4
4
|
import { createContext, use, useMemo, useState } from "react";
|
|
5
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
//#region src/ui/components/
|
|
6
|
+
//#region src/ui/components/select-tab.tsx
|
|
7
7
|
const Context = createContext(null);
|
|
8
8
|
function SelectTabs({ defaultValue, children }) {
|
|
9
|
-
const [
|
|
9
|
+
const [value, setValue] = useState(defaultValue ?? null);
|
|
10
10
|
return /* @__PURE__ */ jsx(Context, {
|
|
11
11
|
value: useMemo(() => ({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}), [
|
|
12
|
+
value,
|
|
13
|
+
setValue
|
|
14
|
+
}), [value]),
|
|
15
15
|
children
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
function SelectTab({ value, ...props }) {
|
|
19
|
-
if (value !== use(Context)?.
|
|
19
|
+
if (value !== use(Context)?.value) return;
|
|
20
20
|
return /* @__PURE__ */ jsx("div", {
|
|
21
21
|
...props,
|
|
22
22
|
children: props.children
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
function SelectTabTrigger({ items, className, ...props }) {
|
|
26
|
-
const {
|
|
26
|
+
const { value, setValue } = use(Context);
|
|
27
27
|
return /* @__PURE__ */ jsxs(Select, {
|
|
28
|
-
value:
|
|
29
|
-
onValueChange:
|
|
28
|
+
value: value ?? "",
|
|
29
|
+
onValueChange: setValue,
|
|
30
30
|
children: [/* @__PURE__ */ jsx(SelectTrigger, {
|
|
31
31
|
className: cn("not-prose w-fit min-w-0 *:min-w-0", className),
|
|
32
32
|
...props,
|
|
33
|
-
children: /* @__PURE__ */ jsx(SelectValue, {})
|
|
33
|
+
children: /* @__PURE__ */ jsx(SelectValue, { children: value && items.find((item) => item.value === value)?.label })
|
|
34
34
|
}), /* @__PURE__ */ jsx(SelectContent, { children: items.map(({ label, value }) => /* @__PURE__ */ jsx(SelectItem, {
|
|
35
35
|
value,
|
|
36
36
|
children: label
|
|
@@ -40,4 +40,4 @@ function SelectTabTrigger({ items, className, ...props }) {
|
|
|
40
40
|
//#endregion
|
|
41
41
|
export { SelectTab, SelectTabTrigger, SelectTabs };
|
|
42
42
|
|
|
43
|
-
//# sourceMappingURL=
|
|
43
|
+
//# sourceMappingURL=select-tab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-tab.js","names":[],"sources":["../../../src/ui/components/select-tab.tsx"],"sourcesContent":["'use client';\n\nimport { cn } from '@/utils/cn';\nimport { SelectTrigger, Select, SelectValue, SelectContent, SelectItem } from './select';\nimport { type ReactNode, useState, useMemo, type ComponentProps, createContext, use } from 'react';\n\nconst Context = createContext<{\n value: string | null;\n setValue: (type: string) => void;\n} | null>(null);\n\nexport function SelectTabs({\n defaultValue,\n children,\n}: {\n defaultValue?: string;\n children: ReactNode;\n}) {\n const [value, setValue] = useState<string | null>(defaultValue ?? null);\n\n return <Context value={useMemo(() => ({ value, setValue }), [value])}>{children}</Context>;\n}\n\nexport function SelectTab({\n value,\n ...props\n}: ComponentProps<'div'> & {\n value: string;\n}) {\n const ctx = use(Context);\n if (value !== ctx?.value) return;\n\n return <div {...props}>{props.children}</div>;\n}\n\nexport function SelectTabTrigger({\n items,\n className,\n ...props\n}: ComponentProps<typeof SelectTrigger> & {\n items: {\n label: ReactNode;\n value: string;\n }[];\n}) {\n const { value, setValue } = use(Context)!;\n\n return (\n <Select value={value ?? ''} onValueChange={setValue}>\n <SelectTrigger className={cn('not-prose w-fit min-w-0 *:min-w-0', className)} {...props}>\n <SelectValue>{value && items.find((item) => item.value === value)?.label}</SelectValue>\n </SelectTrigger>\n <SelectContent>\n {items.map(({ label, value }) => (\n <SelectItem key={value} value={value}>\n {label}\n </SelectItem>\n ))}\n </SelectContent>\n </Select>\n );\n}\n"],"mappings":";;;;;;AAMA,MAAM,UAAU,cAGN,KAAK;AAEf,SAAgB,WAAW,EACzB,cACA,YAIC;CACD,MAAM,CAAC,OAAO,YAAY,SAAwB,gBAAgB,KAAK;AAEvE,QAAO,oBAAC,SAAD;EAAS,OAAO,eAAe;GAAE;GAAO;GAAU,GAAG,CAAC,MAAM,CAAC;EAAG;EAAmB,CAAA;;AAG5F,SAAgB,UAAU,EACxB,OACA,GAAG,SAGF;AAED,KAAI,UADQ,IAAI,QAAQ,EACL,MAAO;AAE1B,QAAO,oBAAC,OAAD;EAAK,GAAI;YAAQ,MAAM;EAAe,CAAA;;AAG/C,SAAgB,iBAAiB,EAC/B,OACA,WACA,GAAG,SAMF;CACD,MAAM,EAAE,OAAO,aAAa,IAAI,QAAQ;AAExC,QACE,qBAAC,QAAD;EAAQ,OAAO,SAAS;EAAI,eAAe;YAA3C,CACE,oBAAC,eAAD;GAAe,WAAW,GAAG,qCAAqC,UAAU;GAAE,GAAI;aAChF,oBAAC,aAAD,EAAA,UAAc,SAAS,MAAM,MAAM,SAAS,KAAK,UAAU,MAAM,EAAE,OAAoB,CAAA;GACzE,CAAA,EAChB,oBAAC,eAAD,EAAA,UACG,MAAM,KAAK,EAAE,OAAO,YACnB,oBAAC,YAAD;GAA+B;aAC5B;GACU,EAFI,MAEJ,CACb,EACY,CAAA,CACT"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { APIPageClientOptions } from "../client/index.js";
|
|
2
|
+
import { RenderContext, ServerObject } from "../../types.js";
|
|
3
|
+
import { ReactNode } from "react";
|
|
4
|
+
import * as _$react_jsx_runtime0 from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/ui/contexts/api.d.ts
|
|
7
|
+
interface InheritFromContext extends Pick<RenderContext, 'shikiOptions'> {
|
|
8
|
+
client: APIPageClientOptions;
|
|
9
|
+
}
|
|
10
|
+
type ApiProviderProps = InheritFromContext;
|
|
11
|
+
declare function ApiProvider({
|
|
12
|
+
children,
|
|
13
|
+
shikiOptions,
|
|
14
|
+
client
|
|
15
|
+
}: ApiProviderProps & {
|
|
16
|
+
children: ReactNode;
|
|
17
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
18
|
+
declare function ServerProvider({
|
|
19
|
+
servers,
|
|
20
|
+
children
|
|
21
|
+
}: {
|
|
22
|
+
servers?: ServerObject[];
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
}): _$react_jsx_runtime0.JSX.Element;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { ApiProvider, ServerProvider };
|
|
27
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","names":[],"sources":["../../../src/ui/contexts/api.tsx"],"mappings":";;;;;;UAYU,kBAAA,SAA2B,IAAA,CAAK,aAAA;EACxC,MAAA,EAAQ,oBAAA;AAAA;AAAA,KAUE,gBAAA,GAAmB,kBAAA;AAAA,iBA8Bf,WAAA,CAAA;EACd,QAAA;EACA,YAAA;EACA;AAAA,GACC,gBAAA;EAAqB,QAAA,EAAU,SAAA;AAAA,IAAW,oBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,iBA4B7B,cAAA,CAAA;EACd,OAAA;EACA;AAAA;EAEA,OAAA,GAAU,YAAA;EACV,QAAA,EAAU,SAAA;AAAA,IACX,oBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-client.d.ts","names":[],"sources":["../../src/ui/create-client.tsx"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"create-client.d.ts","names":[],"sources":["../../src/ui/create-client.tsx"],"mappings":";;;;;;UA8BiB,kBAAA,SAA2B,IAAA,CAAK,YAAA;EAC/C,OAAA,EAAS,oBAAA;AAAA;AAAA,UAGM,oBAAA;EACf,OAAA,EAAS,QAAA;EACT,QAAA;AAAA;AAAA,KAGU,0BAAA,GAA6B,IAAA,CACvC,OAAA,CAAQ,oBAAA;;;;iBAOM,mBAAA,CAAA;EACd,KAAA;EACA,YAAA;EACA,6BAAA;EAAA,GAcG;AAAA,IACF,0BAAA,GAAkC,EAAA,CAAG,kBAAA"}
|
package/dist/ui/create-client.js
CHANGED
|
@@ -2,6 +2,7 @@ import { defaultAdapters } from "../requests/media/adapter.js";
|
|
|
2
2
|
import { ClientCodeBlock, ClientCodeBlockProvider } from "./components/codeblock.js";
|
|
3
3
|
import { dereferenceSync } from "../utils/schema/dereference.js";
|
|
4
4
|
import { APIPage } from "./api-page.js";
|
|
5
|
+
import { boundary_exports } from "./client/boundary.js";
|
|
5
6
|
import { slug } from "github-slugger";
|
|
6
7
|
import { Children, useMemo } from "react";
|
|
7
8
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
@@ -72,6 +73,7 @@ function createClientAPIPage({ shiki = defaultShikiFactory, shikiOptions = { the
|
|
|
72
73
|
shiki,
|
|
73
74
|
shikiOptions,
|
|
74
75
|
generateTypeScriptDefinitions,
|
|
76
|
+
clientBoundary: boundary_exports,
|
|
75
77
|
...options,
|
|
76
78
|
mediaAdapters: {
|
|
77
79
|
...defaultAdapters,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-client.js","names":[],"sources":["../../src/ui/create-client.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport type { Document, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters } from '@/requests/media/adapter';\nimport {\n Children,\n type ComponentProps,\n type ReactElement,\n useMemo,\n type FC,\n type ReactNode,\n} from 'react';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { APIPage, type ApiPageProps } from './api-page';\nimport type { CreateAPIPageOptions } from './base';\nimport { defaultShikiFactory } from 'fumadocs-core/highlight/shiki/full';\nimport { compile } from '@fumari/json-schema-ts';\nimport { ClientCodeBlock, ClientCodeBlockProvider } from './components/codeblock';\nimport { dereferenceSync } from '@/utils/schema/dereference';\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport { slug } from 'github-slugger';\n\nexport interface ClientApiPageProps extends Omit<ApiPageProps, 'document'> {\n payload: ClientApiPagePayload;\n}\n\nexport interface ClientApiPagePayload {\n bundled: Document;\n proxyUrl?: string;\n}\n\nexport type CreateClientAPIPageOptions = Omit<\n Partial<CreateAPIPageOptions>,\n 'generateTypeScriptSchema'\n>;\n\n/**\n * Create `<APIPage />` for non-RSC environment, note that this may be unstable, and doesn't support the full set of features.\n */\nexport function createClientAPIPage({\n shiki = defaultShikiFactory,\n shikiOptions = { themes: { light: 'github-light', dark: 'github-dark' } },\n generateTypeScriptDefinitions = (schema, ctx) => {\n if (typeof schema !== 'object') return;\n\n try {\n return compile(schema, {\n name: 'Response',\n readOnly: ctx.readOnly,\n writeOnly: ctx.writeOnly,\n getSchemaId: ctx.schema.getRawRef,\n });\n } catch (e) {\n console.warn('Failed to generate typescript schema:', e);\n }\n },\n ...options\n}: CreateClientAPIPageOptions = {}): FC<ClientApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n const mdxComponents = {\n ...defaultMdxComponents,\n img: undefined,\n pre: MarkdownPre,\n };\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: mdxComponents,\n });\n };\n }\n\n return remark().use(remarkGfm).use(remarkRehype).use(rehypeReact);\n }\n\n return function ClientAPIPage({ payload, ...props }) {\n const processed = useMemo<ProcessedDocument>(() => {\n const dereferenceMap = new Map<object, string>();\n\n return {\n bundled: payload.bundled,\n dereferenced: dereferenceSync(payload.bundled as JSONSchema, (schema, ref) => {\n dereferenceMap.set(schema as object, ref);\n }) as NoReference<Document>,\n getRawRef(obj) {\n return dereferenceMap.get(obj);\n },\n };\n }, [payload.bundled]);\n\n const ctx: RenderContext = useMemo(\n () => ({\n schema: processed,\n proxyUrl: payload.proxyUrl,\n shiki,\n shikiOptions,\n generateTypeScriptDefinitions,\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n renderHeading(depth, text, props) {\n const id = typeof text === 'string' ? slug(text) : props?.id;\n if (!id) throw new Error(\"missing 'id' for non-string children\");\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n return processor.processSync({\n value: text,\n }).result as ReactNode;\n },\n renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n return <ClientCodeBlock lang={lang} code={code} />;\n },\n }),\n [payload.proxyUrl, processed],\n );\n\n return (\n <ClientCodeBlockProvider factory={shiki}>\n <APIPage {...props} ctx={ctx} />\n </ClientCodeBlockProvider>\n );\n };\n}\n\nfunction MarkdownPre(props: ComponentProps<'pre'>) {\n const code = Children.only(props.children) as ReactElement;\n const codeProps = code.props as ComponentProps<'code'>;\n const content = codeProps.children;\n if (typeof content !== 'string') return null;\n\n const lang =\n codeProps.className\n ?.split(' ')\n .find((v) => v.startsWith('language-'))\n ?.slice('language-'.length) ?? 'text';\n\n return <ClientCodeBlock lang={lang} code={content.trimEnd()} />;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-client.js","names":["ClientBoundary"],"sources":["../../src/ui/create-client.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */\nimport type { Document, RenderContext } from '@/types';\nimport type { NoReference } from '@/utils/schema';\nimport type { ProcessedDocument } from '@/utils/process-document';\nimport { defaultAdapters } from '@/requests/media/adapter';\nimport {\n Children,\n type ComponentProps,\n type ReactElement,\n useMemo,\n type FC,\n type ReactNode,\n} from 'react';\nimport { Heading } from 'fumadocs-ui/components/heading';\nimport { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';\nimport defaultMdxComponents from 'fumadocs-ui/mdx';\nimport { remark } from 'remark';\nimport remarkRehype from 'remark-rehype';\nimport { toJsxRuntime } from 'hast-util-to-jsx-runtime';\nimport * as JsxRuntime from 'react/jsx-runtime';\nimport { APIPage, type ApiPageProps } from './api-page';\nimport type { CreateAPIPageOptions } from './base';\nimport { defaultShikiFactory } from 'fumadocs-core/highlight/shiki/full';\nimport { compile } from '@fumari/json-schema-ts';\nimport { ClientCodeBlock, ClientCodeBlockProvider } from './components/codeblock';\nimport { dereferenceSync } from '@/utils/schema/dereference';\nimport type { JSONSchema } from 'json-schema-typed/draft-2020-12';\nimport { slug } from 'github-slugger';\nimport * as ClientBoundary from '@/ui/client/boundary';\n\nexport interface ClientApiPageProps extends Omit<ApiPageProps, 'document'> {\n payload: ClientApiPagePayload;\n}\n\nexport interface ClientApiPagePayload {\n bundled: Document;\n proxyUrl?: string;\n}\n\nexport type CreateClientAPIPageOptions = Omit<\n Partial<CreateAPIPageOptions>,\n 'generateTypeScriptSchema'\n>;\n\n/**\n * Create `<APIPage />` for non-RSC environment, note that this may be unstable, and doesn't support the full set of features.\n */\nexport function createClientAPIPage({\n shiki = defaultShikiFactory,\n shikiOptions = { themes: { light: 'github-light', dark: 'github-dark' } },\n generateTypeScriptDefinitions = (schema, ctx) => {\n if (typeof schema !== 'object') return;\n\n try {\n return compile(schema, {\n name: 'Response',\n readOnly: ctx.readOnly,\n writeOnly: ctx.writeOnly,\n getSchemaId: ctx.schema.getRawRef,\n });\n } catch (e) {\n console.warn('Failed to generate typescript schema:', e);\n }\n },\n ...options\n}: CreateClientAPIPageOptions = {}): FC<ClientApiPageProps> {\n let processor: ReturnType<typeof createMarkdownProcessor>;\n const mdxComponents = {\n ...defaultMdxComponents,\n img: undefined,\n pre: MarkdownPre,\n };\n\n function createMarkdownProcessor() {\n function rehypeReact(this: any) {\n this.compiler = (tree: any, file: any) => {\n return toJsxRuntime(tree, {\n development: false,\n filePath: file.path,\n ...JsxRuntime,\n components: mdxComponents,\n });\n };\n }\n\n return remark().use(remarkGfm).use(remarkRehype).use(rehypeReact);\n }\n\n return function ClientAPIPage({ payload, ...props }) {\n const processed = useMemo<ProcessedDocument>(() => {\n const dereferenceMap = new Map<object, string>();\n\n return {\n bundled: payload.bundled,\n dereferenced: dereferenceSync(payload.bundled as JSONSchema, (schema, ref) => {\n dereferenceMap.set(schema as object, ref);\n }) as NoReference<Document>,\n getRawRef(obj) {\n return dereferenceMap.get(obj);\n },\n };\n }, [payload.bundled]);\n\n const ctx: RenderContext = useMemo(\n () => ({\n schema: processed,\n proxyUrl: payload.proxyUrl,\n shiki,\n shikiOptions,\n generateTypeScriptDefinitions,\n clientBoundary: ClientBoundary,\n ...options,\n mediaAdapters: {\n ...defaultAdapters,\n ...options.mediaAdapters,\n },\n renderHeading(depth, text, props) {\n const id = typeof text === 'string' ? slug(text) : props?.id;\n if (!id) throw new Error(\"missing 'id' for non-string children\");\n\n if (options.renderHeading) {\n return options.renderHeading({ id, children: text, ...props }, depth);\n }\n\n return (\n <Heading id={id} key={id} as={`h${depth}` as `h1`} {...props}>\n {text}\n </Heading>\n );\n },\n renderMarkdown(text) {\n if (options.renderMarkdown) return options.renderMarkdown(text);\n processor ??= createMarkdownProcessor();\n\n return processor.processSync({\n value: text,\n }).result as ReactNode;\n },\n renderCodeBlock(lang, code) {\n if (options.renderCodeBlock) {\n return options.renderCodeBlock({ lang, code });\n }\n\n return <ClientCodeBlock lang={lang} code={code} />;\n },\n }),\n [payload.proxyUrl, processed],\n );\n\n return (\n <ClientCodeBlockProvider factory={shiki}>\n <APIPage {...props} ctx={ctx} />\n </ClientCodeBlockProvider>\n );\n };\n}\n\nfunction MarkdownPre(props: ComponentProps<'pre'>) {\n const code = Children.only(props.children) as ReactElement;\n const codeProps = code.props as ComponentProps<'code'>;\n const content = codeProps.children;\n if (typeof content !== 'string') return null;\n\n const lang =\n codeProps.className\n ?.split(' ')\n .find((v) => v.startsWith('language-'))\n ?.slice('language-'.length) ?? 'text';\n\n return <ClientCodeBlock lang={lang} code={content.trimEnd()} />;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AA+CA,SAAgB,oBAAoB,EAClC,QAAQ,qBACR,eAAe,EAAE,QAAQ;CAAE,OAAO;CAAgB,MAAM;CAAe,EAAE,EACzE,iCAAiC,QAAQ,QAAQ;AAC/C,KAAI,OAAO,WAAW,SAAU;AAEhC,KAAI;AACF,SAAO,QAAQ,QAAQ;GACrB,MAAM;GACN,UAAU,IAAI;GACd,WAAW,IAAI;GACf,aAAa,IAAI,OAAO;GACzB,CAAC;UACK,GAAG;AACV,UAAQ,KAAK,yCAAyC,EAAE;;GAG5D,GAAG,YAC2B,EAAE,EAA0B;CAC1D,IAAI;CACJ,MAAM,gBAAgB;EACpB,GAAG;EACH,KAAK,KAAA;EACL,KAAK;EACN;CAED,SAAS,0BAA0B;EACjC,SAAS,cAAuB;AAC9B,QAAK,YAAY,MAAW,SAAc;AACxC,WAAO,aAAa,MAAM;KACxB,aAAa;KACb,UAAU,KAAK;KACf,GAAG;KACH,YAAY;KACb,CAAC;;;AAIN,SAAO,QAAQ,CAAC,IAAI,UAAU,CAAC,IAAI,aAAa,CAAC,IAAI,YAAY;;AAGnE,QAAO,SAAS,cAAc,EAAE,SAAS,GAAG,SAAS;EACnD,MAAM,YAAY,cAAiC;GACjD,MAAM,iCAAiB,IAAI,KAAqB;AAEhD,UAAO;IACL,SAAS,QAAQ;IACjB,cAAc,gBAAgB,QAAQ,UAAwB,QAAQ,QAAQ;AAC5E,oBAAe,IAAI,QAAkB,IAAI;MACzC;IACF,UAAU,KAAK;AACb,YAAO,eAAe,IAAI,IAAI;;IAEjC;KACA,CAAC,QAAQ,QAAQ,CAAC;EAErB,MAAM,MAAqB,eAClB;GACL,QAAQ;GACR,UAAU,QAAQ;GAClB;GACA;GACA;GACA,gBAAgBA;GAChB,GAAG;GACH,eAAe;IACb,GAAG;IACH,GAAG,QAAQ;IACZ;GACD,cAAc,OAAO,MAAM,OAAO;IAChC,MAAM,KAAK,OAAO,SAAS,WAAW,KAAK,KAAK,GAAG,OAAO;AAC1D,QAAI,CAAC,GAAI,OAAM,IAAI,MAAM,uCAAuC;AAEhE,QAAI,QAAQ,cACV,QAAO,QAAQ,cAAc;KAAE;KAAI,UAAU;KAAM,GAAG;KAAO,EAAE,MAAM;AAGvE,WACE,oBAAC,SAAD;KAAa;KAAa,IAAI,IAAI;KAAiB,GAAI;eACpD;KACO,EAFY,GAEZ;;GAGd,eAAe,MAAM;AACnB,QAAI,QAAQ,eAAgB,QAAO,QAAQ,eAAe,KAAK;AAC/D,kBAAc,yBAAyB;AAEvC,WAAO,UAAU,YAAY,EAC3B,OAAO,MACR,CAAC,CAAC;;GAEL,gBAAgB,MAAM,MAAM;AAC1B,QAAI,QAAQ,gBACV,QAAO,QAAQ,gBAAgB;KAAE;KAAM;KAAM,CAAC;AAGhD,WAAO,oBAAC,iBAAD;KAAuB;KAAY;KAAQ,CAAA;;GAErD,GACD,CAAC,QAAQ,UAAU,UAAU,CAC9B;AAED,SACE,oBAAC,yBAAD;GAAyB,SAAS;aAChC,oBAAC,SAAD;IAAS,GAAI;IAAY;IAAO,CAAA;GACR,CAAA;;;AAKhC,SAAS,YAAY,OAA8B;CAEjD,MAAM,YADO,SAAS,KAAK,MAAM,SAAS,CACnB;CACvB,MAAM,UAAU,UAAU;AAC1B,KAAI,OAAO,YAAY,SAAU,QAAO;AAQxC,QAAO,oBAAC,iBAAD;EAAiB,MALtB,UAAU,WACN,MAAM,IAAI,CACX,MAAM,MAAM,EAAE,WAAW,YAAY,CAAC,EACrC,MAAM,EAAmB,IAAI;EAEC,MAAM,QAAQ,SAAS;EAAI,CAAA"}
|
|
@@ -11,9 +11,8 @@ import { Schema } from "../schema/index.js";
|
|
|
11
11
|
import { AccordionContent, AccordionHeader, AccordionItem, AccordionTrigger, Accordions } from "../components/accordion.js";
|
|
12
12
|
import { UsageTabs } from "./usage-tabs/index.js";
|
|
13
13
|
import { RequestTabs } from "./request-tabs.js";
|
|
14
|
-
import { ServerProviderLazy } from "../contexts/api.lazy.js";
|
|
15
14
|
import { getExampleRequests } from "./get-example-requests.js";
|
|
16
|
-
import { SelectTab, SelectTabTrigger, SelectTabs } from "../components/
|
|
15
|
+
import { SelectTab, SelectTabTrigger, SelectTabs } from "../components/select-tab.js";
|
|
17
16
|
import { Fragment, use, useMemo } from "react";
|
|
18
17
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
19
18
|
//#region src/ui/operation/index.tsx
|
|
@@ -254,7 +253,7 @@ function Operation({ type = "operation", path, method, ctx, showTitle, showDescr
|
|
|
254
253
|
examples: exampleRequests,
|
|
255
254
|
children: content
|
|
256
255
|
});
|
|
257
|
-
if (method.servers) content = /* @__PURE__ */ jsx(
|
|
256
|
+
if (method.servers) content = /* @__PURE__ */ jsx(ctx.clientBoundary.ServerProvider, {
|
|
258
257
|
servers: method.servers,
|
|
259
258
|
children: content
|
|
260
259
|
});
|