@clarify-labs/renderer 0.7.1 → 0.8.0
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/output/{ThemeRoot-CLa0yvRQ.js → ClarifyShell-BxB_6Uhd.js} +292 -141
- package/output/ClarifyShell-BxB_6Uhd.js.map +1 -0
- package/output/{ThemeRoot-DYS-lcK-.cjs → ClarifyShell-DNN5erFD.cjs} +320 -145
- package/output/ClarifyShell-DNN5erFD.cjs.map +1 -0
- package/output/{OpenApiOperation-C4xZu4i0.cjs → OpenApiOperation-9SvCA_B4.cjs} +327 -83
- package/output/OpenApiOperation-9SvCA_B4.cjs.map +1 -0
- package/output/{OpenApiOperation-LIL7bqxW.js → OpenApiOperation-J41rHO2l.js} +323 -85
- package/output/OpenApiOperation-J41rHO2l.js.map +1 -0
- package/output/{PageActions-yoDRjkq8.js → PageActions-DR0asnKH.js} +30 -69
- package/output/PageActions-DR0asnKH.js.map +1 -0
- package/output/{PageActions-1RDCHcUY.cjs → PageActions-yycPlNyL.cjs} +35 -68
- package/output/PageActions-yycPlNyL.cjs.map +1 -0
- package/output/app/AppShell.d.ts +2 -3
- package/output/app/PageBanner.d.ts +0 -2
- package/output/app/PageFooter.d.ts +1 -5
- package/output/client.cjs +8 -8
- package/output/client.js +3 -3
- package/output/components/Code.d.ts +5 -1
- package/output/components/Mermaid.d.ts +7 -0
- package/output/components/index.d.ts +1 -0
- package/output/context.d.ts +1 -1
- package/output/core/i18n.d.ts +1 -1
- package/output/core/types.d.ts +7 -14
- package/output/index.cjs +27 -24
- package/output/index.cjs.map +1 -1
- package/output/index.d.ts +7 -4
- package/output/index.js +14 -14
- package/output/index.js.map +1 -1
- package/output/mdx/components.d.ts +4 -0
- package/output/mdx/primitives.d.ts +2 -0
- package/output/openapi/components/EndpointSections.d.ts +30 -0
- package/output/preview.cjs +2 -2
- package/output/preview.cjs.map +1 -1
- package/output/preview.js +2 -2
- package/output/preview.js.map +1 -1
- package/output/{render-CRTqZzyY.cjs → render-CWvm77UW.cjs} +10 -20
- package/output/render-CWvm77UW.cjs.map +1 -0
- package/output/{render-D0ls3d2j.js → render-mGozubG5.js} +10 -20
- package/output/render-mGozubG5.js.map +1 -0
- package/output/renderer.css +83 -24
- package/output/runtime/ClarifyShell.d.ts +22 -0
- package/output/server.cjs +10 -19
- package/output/server.cjs.map +1 -1
- package/output/server.js +10 -19
- package/output/server.js.map +1 -1
- package/output/shell/search/pagefind.d.ts +0 -1
- package/output/slots/RuntimeSlot.d.ts +58 -0
- package/output/slots/context.d.ts +20 -0
- package/output/slots/index.d.ts +5 -0
- package/output/slots/types.d.ts +50 -0
- package/output/utils/localized-text.d.ts +7 -0
- package/package.json +8 -3
- package/output/OpenApiOperation-C4xZu4i0.cjs.map +0 -1
- package/output/OpenApiOperation-LIL7bqxW.js.map +0 -1
- package/output/PageActions-1RDCHcUY.cjs.map +0 -1
- package/output/PageActions-yoDRjkq8.js.map +0 -1
- package/output/ThemeRoot-CLa0yvRQ.js.map +0 -1
- package/output/ThemeRoot-DYS-lcK-.cjs.map +0 -1
- package/output/render-CRTqZzyY.cjs.map +0 -1
- package/output/render-D0ls3d2j.js.map +0 -1
package/output/client.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as themeBootstrapScript, i as themeEditorPresets, n as ThemeEditor, r as applyThemeVariables, s as themeStorageKey } from "./
|
|
3
|
-
import { t as render } from "./render-
|
|
1
|
+
import { C as themeCookieName, S as storeThemePreference, _ as getStoredLocalePreference, b as readLocaleCookie, v as getStoredThemePreference, x as storeLocalePreference, y as localeCookieName } from "./PageActions-DR0asnKH.js";
|
|
2
|
+
import { a as themeBootstrapScript, i as themeEditorPresets, n as ThemeEditor, r as applyThemeVariables, s as themeStorageKey } from "./ClarifyShell-BxB_6Uhd.js";
|
|
3
|
+
import { t as render } from "./render-mGozubG5.js";
|
|
4
4
|
export { ThemeEditor, applyThemeVariables, getStoredLocalePreference, getStoredThemePreference, localeCookieName, readLocaleCookie, render, storeLocalePreference, storeThemePreference, themeBootstrapScript, themeCookieName, themeEditorPresets, themeStorageKey };
|
|
@@ -18,5 +18,9 @@ type CodeProps = ComponentPropsWithoutRef<'code'> & {
|
|
|
18
18
|
title?: string;
|
|
19
19
|
};
|
|
20
20
|
export declare function Code(arg0: CodeProps): import("react").JSX.Element;
|
|
21
|
-
|
|
21
|
+
type PreProps = ComponentPropsWithoutRef<typeof CodeGroup> & {
|
|
22
|
+
language?: string;
|
|
23
|
+
code?: string;
|
|
24
|
+
};
|
|
25
|
+
export declare function Pre(arg0: PreProps): string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null | undefined;
|
|
22
26
|
export {};
|
|
@@ -12,6 +12,7 @@ export { Heading } from './Heading';
|
|
|
12
12
|
export { LocalizedLink, useLocalizedHref } from './LocalizedLink';
|
|
13
13
|
export type { LocalizedLinkProps } from './LocalizedLink';
|
|
14
14
|
export { Logo } from './Logo';
|
|
15
|
+
export { Mermaid } from './Mermaid';
|
|
15
16
|
export { GridPattern, HeroPattern } from './patterns';
|
|
16
17
|
export { Prose } from './Prose';
|
|
17
18
|
export { Tag } from './Tag';
|
package/output/context.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { LocaleContext, OpenApisContext, useLocale, useOpenApis } from './core/context';
|
package/output/core/i18n.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type BuiltInLocale = 'en' | 'zh-CN';
|
|
2
|
-
export type BuiltInTextKey = 'actions.code' | 'actions.copy' | 'actions.copied' | 'builtWith.label' | 'builtWith.prefix' | 'callout.danger' | 'callout.info' | 'callout.note' | 'callout.success' | 'callout.tip' | 'callout.warning' | 'contentActions.copyContent' | 'contentActions.copyContentDescription' | 'contentActions.copyLink' | 'contentActions.copyLinkDescription' | 'contentActions.copyLlms' | 'contentActions.copyLlmsDescription' | 'contentActions.copiedLlms' | 'contentActions.editPage' | 'contentActions.editPageDescription' | 'contentActions.copyOptions' | 'contentActions.copiedContent' | 'contentActions.copiedLink' | 'contentActions.viewMarkdown' | 'contentActions.viewMarkdownDescription' | 'contentActions.viewOpenApi' | 'contentActions.viewOpenApiDescription' | 'feedback.no' | 'feedback.prompt' | 'feedback.thanks' | 'feedback.yes' | 'navigation.documentation' | 'navigation.next' | 'navigation.previous' | 'navigation.previousNext' | 'navigation.toggle' | 'navbar.home' | 'navbar.openLinks' | 'navbar.sections' | 'notFound.description' | 'notFound.home' | 'notFound.label' | 'notFound.title' | 'openapi.apiDocumentation' | 'openapi.bodyProperties' | 'openapi.collapse' | 'openapi.endpointNotFound' | 'openapi.example' | 'openapi.expand' | 'openapi.headers' | 'openapi.language' | 'openapi.client' | 'openapi.mediaType' | 'openapi.openApiReference' | 'openapi.operationParameter' | 'openapi.optional' | 'openapi.parameter' | 'openapi.pathParameters' | 'openapi.queryParameters' | 'openapi.request' | 'openapi.requestBody' | 'openapi.required' | 'openapi.requiredBadge' | 'openapi.response' | 'openapi.responses' | 'openapi.schemaExample' | 'openapi.scrollExamplesLeft' | 'openapi.scrollExamplesRight' | 'openapi.specNotFound' | 'openapi.specPathMissing' | 'openapi.status' | 'openapi.version' | 'search.button' | 'search.noResults' | 'search.placeholder' | 'search.shortcutCtrl' | 'renderError.componentStack' | 'renderError.description' | 'renderError.details' | 'renderError.message' | 'renderError.path' | 'renderError.reload' | 'renderError.stack' | 'renderError.timestamp' | 'renderError.title' | 'renderError.type' | 'theme.switchToDark' | 'theme.switchToLight' | 'language.switch';
|
|
2
|
+
export type BuiltInTextKey = 'actions.code' | 'actions.copy' | 'actions.copied' | 'builtWith.label' | 'builtWith.prefix' | 'callout.danger' | 'callout.info' | 'callout.note' | 'callout.success' | 'callout.tip' | 'callout.warning' | 'contentActions.copyContent' | 'contentActions.copyContentDescription' | 'contentActions.copyLink' | 'contentActions.copyLinkDescription' | 'contentActions.copyLlms' | 'contentActions.copyLlmsDescription' | 'contentActions.copiedLlms' | 'contentActions.editPage' | 'contentActions.editPageDescription' | 'contentActions.copyOptions' | 'contentActions.copiedContent' | 'contentActions.copiedLink' | 'contentActions.viewMarkdown' | 'contentActions.viewMarkdownDescription' | 'contentActions.viewOpenApi' | 'contentActions.viewOpenApiDescription' | 'feedback.no' | 'feedback.prompt' | 'feedback.thanks' | 'feedback.yes' | 'navigation.documentation' | 'navigation.next' | 'navigation.previous' | 'navigation.previousNext' | 'navigation.toggle' | 'navbar.home' | 'navbar.openLinks' | 'navbar.sections' | 'notFound.description' | 'notFound.home' | 'notFound.label' | 'notFound.title' | 'openapi.apiDocumentation' | 'openapi.bodyProperties' | 'openapi.collapse' | 'openapi.endpointNotFound' | 'openapi.example' | 'openapi.expand' | 'openapi.headers' | 'openapi.language' | 'openapi.client' | 'openapi.mediaType' | 'openapi.openApiReference' | 'openapi.operationParameter' | 'openapi.optional' | 'openapi.parameter' | 'openapi.pathParameters' | 'openapi.queryParameters' | 'openapi.request' | 'openapi.requestBody' | 'openapi.required' | 'openapi.requiredBadge' | 'openapi.response' | 'openapi.responses' | 'openapi.schemaExample' | 'openapi.scrollExamplesLeft' | 'openapi.scrollExamplesRight' | 'openapi.specNotFound' | 'openapi.specPathMissing' | 'openapi.status' | 'openapi.version' | 'search.button' | 'search.noResults' | 'search.placeholder' | 'search.shortcutCtrl' | 'renderError.componentStack' | 'renderError.description' | 'renderError.details' | 'renderError.message' | 'renderError.path' | 'renderError.reload' | 'renderError.stack' | 'renderError.timestamp' | 'renderError.title' | 'renderError.type' | 'theme.switchToDark' | 'theme.switchToLight' | 'language.switch' | 'mermaid.zoomIn' | 'mermaid.zoomOut' | 'mermaid.resetZoom' | 'mermaid.renderError' | 'mermaid.scrollHint';
|
|
3
3
|
export declare function resolveBuiltInLocale(locale?: string): BuiltInLocale;
|
|
4
4
|
export declare function translateBuiltInText(locale: string | undefined, key: BuiltInTextKey, replacements?: Record<string, string>): string;
|
|
5
5
|
export declare function useBuiltInText(locale?: string): (key: BuiltInTextKey, replacements?: Record<string, string>) => string;
|
package/output/core/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { OpenAPISpec } from '../openapi/lib/utils';
|
|
3
|
-
|
|
3
|
+
import { RuntimeSlots } from '../slots';
|
|
4
4
|
export type RouteComponent = ComponentType | (() => Promise<{
|
|
5
5
|
default: ComponentType;
|
|
6
6
|
}>);
|
|
@@ -58,19 +58,16 @@ export type NavbarLink = {
|
|
|
58
58
|
href: string;
|
|
59
59
|
external?: boolean;
|
|
60
60
|
};
|
|
61
|
-
export type
|
|
62
|
-
export type BannerConfigOptions = {
|
|
61
|
+
export type BannerConfig = {
|
|
63
62
|
content: LocalizedText;
|
|
64
63
|
dismissible?: boolean;
|
|
65
64
|
link?: NavbarLink;
|
|
66
65
|
};
|
|
67
|
-
export type
|
|
68
|
-
export type FooterLinksConfig = {
|
|
66
|
+
export type FooterConfig = {
|
|
69
67
|
links?: NavbarLink[];
|
|
70
68
|
socials?: Record<string, string>;
|
|
71
69
|
copyright?: LocalizedText;
|
|
72
70
|
};
|
|
73
|
-
export type FooterConfig = FooterLinksConfig | FooterComponentPath;
|
|
74
71
|
export type SourceConfig = {
|
|
75
72
|
repository: string;
|
|
76
73
|
branch?: string;
|
|
@@ -178,10 +175,8 @@ export type RenderOptions = {
|
|
|
178
175
|
navigation?: NavigationTree;
|
|
179
176
|
/** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
|
|
180
177
|
openApis?: Record<string, OpenAPISpec>;
|
|
181
|
-
/**
|
|
182
|
-
|
|
183
|
-
/** Custom footer component imported from a configured footer path. */
|
|
184
|
-
footerComponent?: ComponentType;
|
|
178
|
+
/** Plugin runtime UI slots imported from virtual:clarify-runtime-slots. */
|
|
179
|
+
runtimeSlots?: RuntimeSlots;
|
|
185
180
|
/** Whether to render the live theme editor inside the app tree. */
|
|
186
181
|
themeEditor?: boolean;
|
|
187
182
|
/** 挂载节点,默认 document.getElementById('root') */
|
|
@@ -199,10 +194,8 @@ export type ServerRenderOptions = {
|
|
|
199
194
|
navigation?: NavigationTree;
|
|
200
195
|
/** 从 virtual:clarify-openapi-registry 导入的 OpenAPI 规范表 */
|
|
201
196
|
openApis?: Record<string, OpenAPISpec>;
|
|
202
|
-
/**
|
|
203
|
-
|
|
204
|
-
/** Custom footer component imported from a configured footer path. */
|
|
205
|
-
footerComponent?: ComponentType;
|
|
197
|
+
/** Plugin runtime UI slots imported from virtual:clarify-runtime-slots. */
|
|
198
|
+
runtimeSlots?: RuntimeSlots;
|
|
206
199
|
/** Whether to render the live theme editor inside the app tree. */
|
|
207
200
|
themeEditor?: boolean;
|
|
208
201
|
/** 当前请求的 URL */
|
package/output/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_PageActions = require("./PageActions-
|
|
3
|
-
const
|
|
4
|
-
const require_OpenApiOperation = require("./OpenApiOperation-
|
|
2
|
+
const require_PageActions = require("./PageActions-yycPlNyL.cjs");
|
|
3
|
+
const require_ClarifyShell = require("./ClarifyShell-DNN5erFD.cjs");
|
|
4
|
+
const require_OpenApiOperation = require("./OpenApiOperation-9SvCA_B4.cjs");
|
|
5
5
|
const require_remark = require("./remark-Dv3owbSH.cjs");
|
|
6
|
-
const require_render = require("./render-
|
|
6
|
+
const require_render = require("./render-CWvm77UW.cjs");
|
|
7
7
|
let react_router_dom = require("react-router-dom");
|
|
8
8
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
9
|
//#region source/openapi/lib/spec-path.ts
|
|
@@ -26,23 +26,22 @@ function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
|
|
|
26
26
|
/**
|
|
27
27
|
* 为绝对 specPath 生成带 locale 前缀的候选模块 ID。
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。
|
|
29
|
+
* 所有 locale 的 spec 都注册在 `virtual:clarify-page/<locale>/...` 下,
|
|
30
|
+
* 因此绝对路径(如 `/api`)需要显式注入 locale 前缀才能命中。
|
|
31
|
+
* 相对路径会因为当前路由已含 locale 前缀而自动解析到正确的 spec。
|
|
33
32
|
*/
|
|
34
|
-
function localizeSpecModuleId(moduleId, specPath, locale,
|
|
35
|
-
if (!locale
|
|
33
|
+
function localizeSpecModuleId(moduleId, specPath, locale, _defaultLocale) {
|
|
34
|
+
if (!locale) return void 0;
|
|
36
35
|
if (!specPath.startsWith("/") || specPath.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
37
36
|
const rest = moduleId.slice(21);
|
|
38
37
|
if (rest.startsWith(`${locale}/`) || rest === locale) return void 0;
|
|
39
38
|
return `${VIRTUAL_PREFIX}${locale}/${rest}`;
|
|
40
39
|
}
|
|
41
40
|
function useOpenApiSpec(spec, specPath) {
|
|
42
|
-
const specs = require_PageActions.useOpenApis();
|
|
43
|
-
const location = (0, react_router_dom.useLocation)();
|
|
44
41
|
const config = require_PageActions.useConfig();
|
|
45
42
|
const locale = require_PageActions.useLocale();
|
|
43
|
+
const specs = require_PageActions.useOpenApis();
|
|
44
|
+
const location = (0, react_router_dom.useLocation)();
|
|
46
45
|
if (spec) return spec;
|
|
47
46
|
if (!specPath) return null;
|
|
48
47
|
const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix);
|
|
@@ -203,7 +202,8 @@ function OpenApiOperation(arg0) {
|
|
|
203
202
|
var builtInMDXComponents = {
|
|
204
203
|
...require_OpenApiOperation.primitives_exports,
|
|
205
204
|
Markdown: require_OpenApiOperation.Markdown,
|
|
206
|
-
Collapse: require_OpenApiOperation.Collapse
|
|
205
|
+
Collapse: require_OpenApiOperation.Collapse,
|
|
206
|
+
Mermaid: require_OpenApiOperation.Mermaid
|
|
207
207
|
};
|
|
208
208
|
var builtInOpenAPIComponents = {
|
|
209
209
|
OpenApiDocument,
|
|
@@ -238,8 +238,8 @@ function DocShell(arg0) {
|
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
//#endregion
|
|
241
|
-
exports.AppShell =
|
|
242
|
-
exports.BuiltWithClarify =
|
|
241
|
+
exports.AppShell = require_ClarifyShell.AppShell;
|
|
242
|
+
exports.BuiltWithClarify = require_ClarifyShell.BuiltWithClarify;
|
|
243
243
|
exports.Button = require_OpenApiOperation.Button;
|
|
244
244
|
exports.Callout = require_OpenApiOperation.Callout;
|
|
245
245
|
exports.Card = require_OpenApiOperation.Card;
|
|
@@ -247,7 +247,6 @@ exports.CardGroup = require_OpenApiOperation.CardGroup;
|
|
|
247
247
|
exports.Code = require_OpenApiOperation.Code;
|
|
248
248
|
exports.CodeGroup = require_OpenApiOperation.CodeGroup;
|
|
249
249
|
exports.Collapse = require_OpenApiOperation.Collapse;
|
|
250
|
-
exports.ConfigContext = require_PageActions.ConfigContext;
|
|
251
250
|
exports.DocShell = DocShell;
|
|
252
251
|
exports.Feedback = require_OpenApiOperation.Feedback;
|
|
253
252
|
exports.GridPattern = require_OpenApiOperation.GridPattern;
|
|
@@ -255,30 +254,34 @@ exports.Heading = require_OpenApiOperation.Heading;
|
|
|
255
254
|
exports.HeroPattern = require_OpenApiOperation.HeroPattern;
|
|
256
255
|
exports.Logo = require_OpenApiOperation.Logo;
|
|
257
256
|
exports.Markdown = require_OpenApiOperation.Markdown;
|
|
257
|
+
exports.Mermaid = require_OpenApiOperation.Mermaid;
|
|
258
258
|
exports.OpenApiDocument = OpenApiDocument;
|
|
259
259
|
exports.OpenApiOperation = OpenApiOperation;
|
|
260
260
|
exports.OpenApisContext = require_PageActions.OpenApisContext;
|
|
261
|
-
exports.PageBanner =
|
|
262
|
-
exports.PageFooter =
|
|
261
|
+
exports.PageBanner = require_ClarifyShell.PageBanner;
|
|
262
|
+
exports.PageFooter = require_ClarifyShell.PageFooter;
|
|
263
263
|
exports.Pre = require_OpenApiOperation.Pre;
|
|
264
264
|
exports.Prose = require_OpenApiOperation.Prose;
|
|
265
|
+
exports.RuntimeSlot = require_ClarifyShell.RuntimeSlot;
|
|
266
|
+
exports.RuntimeSlotsProvider = require_ClarifyShell.RuntimeSlotsProvider;
|
|
265
267
|
exports.SectionProvider = require_PageActions.SectionProvider;
|
|
268
|
+
exports.SlotProvider = require_ClarifyShell.SlotProvider;
|
|
266
269
|
exports.Tag = require_OpenApiOperation.Tag;
|
|
267
|
-
exports.ThemeEditor =
|
|
270
|
+
exports.ThemeEditor = require_ClarifyShell.ThemeEditor;
|
|
268
271
|
exports.ThemeProvider = require_PageActions.ThemeProvider;
|
|
269
272
|
exports.ThemeToggle = require_PageActions.ThemeToggle;
|
|
270
273
|
exports.WebFrame = require_OpenApiOperation.WebFrame;
|
|
271
|
-
exports.applyThemeVariables =
|
|
274
|
+
exports.applyThemeVariables = require_ClarifyShell.applyThemeVariables;
|
|
272
275
|
exports.markdownRemarkPlugins = require_remark.markdownRemarkPlugins;
|
|
273
276
|
exports.remToPx = require_PageActions.remToPx;
|
|
274
277
|
exports.render = require_render.render;
|
|
275
|
-
exports.themeBootstrapScript =
|
|
276
|
-
exports.themeEditorPresets =
|
|
277
|
-
exports.themePresets =
|
|
278
|
-
exports.useConfig = require_PageActions.useConfig;
|
|
278
|
+
exports.themeBootstrapScript = require_ClarifyShell.themeBootstrapScript;
|
|
279
|
+
exports.themeEditorPresets = require_ClarifyShell.themeEditorPresets;
|
|
280
|
+
exports.themePresets = require_ClarifyShell.themePresets;
|
|
279
281
|
exports.useMDXComponents = useMDXComponents;
|
|
280
282
|
exports.useOpenApis = require_PageActions.useOpenApis;
|
|
281
283
|
exports.useSectionStore = require_PageActions.useSectionStore;
|
|
284
|
+
exports.useSlot = require_ClarifyShell.useSlot;
|
|
282
285
|
exports.useTheme = require_PageActions.useTheme;
|
|
283
286
|
|
|
284
287
|
//# sourceMappingURL=index.cjs.map
|
package/output/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useConfig, useLocale, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\n/**\n * 为绝对 specPath 生成带 locale 前缀的候选模块 ID。\n *\n * 局部嵌入(OpenApiOperation / OpenApiDocument)通常使用 `/api` 这样的绝对路径。\n * 默认 locale 的 spec 注册在 `virtual:clarify-page/api`,而其他 locale 的 spec\n * 注册在 `virtual:clarify-page/<locale>/api`。相对路径会因为当前路由已含 locale 前缀\n * 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。\n */\nfunction localizeSpecModuleId(moduleId: string, specPath: string, locale: string | undefined, defaultLocale: string | undefined): string | undefined {\n if (!locale || locale === defaultLocale) return undefined\n // 仅处理绝对路径;相对路径已经基于含 locale 前缀的当前路由解析。\n if (!specPath.startsWith('/') || specPath.startsWith(VIRTUAL_PREFIX)) return undefined\n const rest = moduleId.slice(VIRTUAL_PREFIX.length)\n if (rest.startsWith(`${locale}/`) || rest === locale) return undefined\n return `${VIRTUAL_PREFIX}${locale}/${rest}`\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const specs = useOpenApis()\n const location = useLocation()\n const config = useConfig()\n const locale = useLocale()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale)\n\n if (localized && specs[localized]) return specs[localized]\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { PageTitleActions } from '../app/PageActions'\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase\">\n {t('openapi.openApiReference')}\n </p>\n <div className=\"clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between\">\n <h1 className=\"clarify-page-title min-w-0 flex-1\">{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n <PageTitleActions />\n </div>\n {spec.info?.description ? <Markdown className=\"lead mt-4 *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"mt-4 text-sm text-(--clarify-ui-text-faint)\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAiB,IAAoB;CAChE,MAAM,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5D,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MACX,MAAM,IAAI;MACL,IAAI,SAAS,KAClB,MAAM,KAAK,IAAI;CAGnB,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,SAAS,kBAAkB,UAAkB,kBAA2B,cAAc,IAAY;CAChG,IAAI,SAAS,WAAW,cAAc,GAAG,OAAO;CAEhD,MAAM,wBAAwB,YAAY,QAAQ,cAAc,EAAE;CAClE,MAAM,qBAAqB,SAAS,WAAW,GAAG,KAAK,yBAAyB,SAAS,MAAM,CAAC,EAAE,WAAW,GAAG,sBAAs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;AAEA,SAAgB,iBAAiB,MAAwC;CACvE,MAAM,EAAE,UAAU,MAAM,WAAW;CACnC,MAAM,IAAI,oBAAA,eAAe;CACzB,MAAM,OAAO,eAAe,KAAA,GAAW,QAAQ;CAE/C,IAAI,CAAC,MACH,OAAO,iBAAA,GAAA,kBAAA,KAAC,YAAD,EAAA,UAAa,EAAE,wBAAwB,EAAE,SAAS,CAAC,EAAc,CAAA;CAG1E,OAAO,iBAAA,GAAA,kBAAA,KAAC,0BAAD;EAAgC;EAAY;EAAc;CAAS,CAAA;AAC5E;;;ACjIA,IAAM,uBAAuB;CAC3B,GAAG,yBAAA;CACH,UAAA,yBAAA;CACA,UAAA,yBAAA;AACF;AAEA,IAAM,2BAA2B;CAC/B;CACA;AACF;AAEA,SAAgB,iBAAiB,aAAsC,CAAC,GAAG;CACzE,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF;;;ACbA,SAAgB,SAAS,MAAqB;CAC5C,MAAM,EAAE,OAAO,UAAU,aAAa;CAEtC,OACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;EAAM,WAAU;YACd,iBAAA,GAAA,kBAAA,MAAC,OAAD;GAAK,WAAU;aAAf,CACE,iBAAA,GAAA,kBAAA,MAAC,UAAD;IAAQ,WAAU;cAAlB,CACE,iBAAA,GAAA,kBAAA,KAAC,MAAD;KAAI,WAAU;eAAiD;IAAU,CAAA,GACxE,WAAW,iBAAA,GAAA,kBAAA,KAAC,KAAD;KAAG,WAAU;eAAgD;IAAY,CAAA,IAAI,IACnF;OACR,iBAAA,GAAA,kBAAA,KAAC,yBAAA,OAAD,EAAQ,SAAgB,CAAA,CACrB;;CACD,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useConfig, useLocale, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\n/**\n * 为绝对 specPath 生成带 locale 前缀的候选模块 ID。\n *\n * 所有 locale 的 spec 都注册在 `virtual:clarify-page/<locale>/...` 下,\n * 因此绝对路径(如 `/api`)需要显式注入 locale 前缀才能命中。\n * 相对路径会因为当前路由已含 locale 前缀而自动解析到正确的 spec。\n */\nfunction localizeSpecModuleId(moduleId: string, specPath: string, locale: string | undefined, _defaultLocale: string | undefined): string | undefined {\n if (!locale) return undefined\n // 仅处理绝对路径;相对路径已经基于含 locale 前缀的当前路由解析。\n if (!specPath.startsWith('/') || specPath.startsWith(VIRTUAL_PREFIX)) return undefined\n const rest = moduleId.slice(VIRTUAL_PREFIX.length)\n if (rest.startsWith(`${locale}/`) || rest === locale) return undefined\n return `${VIRTUAL_PREFIX}${locale}/${rest}`\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const config = useConfig()\n const locale = useLocale()\n const specs = useOpenApis()\n const location = useLocation()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale)\n\n if (localized && specs[localized]) return specs[localized]\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { PageTitleActions } from '../app/PageActions'\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase\">\n {t('openapi.openApiReference')}\n </p>\n <div className=\"clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between\">\n <h1 className=\"clarify-page-title min-w-0 flex-1\">{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n <PageTitleActions />\n </div>\n {spec.info?.description ? <Markdown className=\"lead mt-4 *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"mt-4 text-sm text-(--clarify-ui-text-faint)\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { Mermaid } from '../components/Mermaid'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n Mermaid,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAiB,IAAoB;CAChE,MAAM,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5D,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MACX,MAAM,IAAI;MACL,IAAI,SAAS,KAClB,MAAM,KAAK,IAAI;CAGnB,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,SAAS,kBAAkB,UAAkB,kBAA2B,cAAc,IAAY;CAChG,IAAI,SAAS,WAAW,cAAc,GAAG,OAAO;CAEhD,MAAM,wBAAwB,YAAY,QAAQ,cAAc,EAAE;CAClE,MAAM,qBAAqB,SAAS,WAAW,GAAG,KAAK,yBAAyB,SAAS,MAAM,CAAC,EAAE,WAAW,GAAG,sBAAsB,EAAE,IACpI,MAAM,SAAS,MAAM,sBAAsB,SAAS,CAAC,IACrD;CAEJ,IAAI,mBAAmB,WAAW,GAAG,GACnC,OAAO,iBAAiB,mBAAmB,QAAQ,OAAO,EAAE;CAE9D,MAAM,UAAU,qBAAqB,MAAM,KAAK,kBAAkB,QAAQ,OAAO,EAAE,EAAE,QAAQ,YAAY,EAAE,KAAK;CAIhH,OAAO,iBAAiB,oBAHE,yBAAyB,QAAQ,WAAW,GAAG,sBAAsB,EAAE,IAC7F,QAAQ,MAAM,s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;;AChIA,IAAM,uBAAuB;CAC3B,GAAG,yBAAA;CACH,UAAA,yBAAA;CACA,UAAA,yBAAA;CACA,SAAA,yBAAA;AACF;AAEA,IAAM,2BAA2B;CAC/B;CACA;AACF;AAEA,SAAgB,iBAAiB,aAAsC,CAAC,GAAG;CACzE,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF;;;ACfA,SAAgB,SAAS,MAAqB;CAC5C,MAAM,EAAE,OAAO,UAAU,aAAa;CAEtC,OACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;EAAM,WAAU;YACd,iBAAA,GAAA,kBAAA,MAAC,OAAD;GAAK,WAAU;aAAf,CACE,iBAAA,GAAA,kBAAA,MAAC,UAAD;IAAQ,WAAU;cAAlB,CACE,iBAAA,GAAA,kBAAA,KAAC,MAAD;KAAI,WAAU;eAAiD;IAAU,CAAA,GACxE,WAAW,iBAAA,GAAA,kBAAA,KAAC,KAAD;KAAG,WAAU;eAAgD;IAAY,CAAA,IAAI,IACnF;OACR,iBAAA,GAAA,kBAAA,KAAC,yBAAA,OAAD,EAAQ,SAAgB,CAAA,CACrB;;CACD,CAAA;AAEV"}
|
package/output/index.d.ts
CHANGED
|
@@ -3,14 +3,15 @@ import { BuiltWithClarify } from './app/BuiltWithClarify';
|
|
|
3
3
|
import { PageBanner } from './app/PageBanner';
|
|
4
4
|
import { PageFooter } from './app/PageFooter';
|
|
5
5
|
import { SectionProvider, useSectionStore, Section } from './app/SectionProvider';
|
|
6
|
-
import { Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, Feedback, GridPattern, Heading, HeroPattern, Logo, Pre, Prose, Tag, WebFrame } from './components';
|
|
7
|
-
import {
|
|
6
|
+
import { Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, Feedback, GridPattern, Heading, HeroPattern, Logo, Mermaid, Pre, Prose, Tag, WebFrame } from './components';
|
|
7
|
+
import { OpenApisContext, useOpenApis } from './context';
|
|
8
8
|
import { useMDXComponents } from './mdx/components';
|
|
9
9
|
import { DocShell } from './mdx/DocShell';
|
|
10
10
|
import { Markdown } from './mdx/Markdown';
|
|
11
11
|
import { markdownRemarkPlugins } from './mdx/remark';
|
|
12
12
|
import { OpenApiDocument, OpenApiOperation } from './openapi';
|
|
13
13
|
import { render } from './runtime/render';
|
|
14
|
+
import { SlotProvider, RuntimeSlot, RuntimeSlotsProvider, useSlot } from './slots';
|
|
14
15
|
import { applyThemeVariables, themeEditorPresets, ThemeEditor } from './theme/ThemeEditor';
|
|
15
16
|
import { ThemeProvider, useTheme } from './theme/ThemeProvider';
|
|
16
17
|
import { ThemeToggle } from './theme/ThemeToggle';
|
|
@@ -20,7 +21,9 @@ import { remToPx } from './utils/remToPx';
|
|
|
20
21
|
export type { OpenApiOperationProps, OpenApiDocumentProps, OpenAPIOperation, OpenAPISpec } from './openapi';
|
|
21
22
|
export type { ThemeEditorProps } from './theme/ThemeEditor';
|
|
22
23
|
export type { Config, RouteItem, RenderOptions, ServerRenderOptions, Section };
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
24
|
+
export type { RuntimeSlotEntry, RuntimeSlots, UISlotRegistration, UISlotName, SlotContext } from './slots';
|
|
25
|
+
export { AppShell, render, OpenApisContext, useOpenApis, BuiltWithClarify, PageBanner, PageFooter, ThemeProvider, ThemeToggle, ThemeEditor, useTheme, SectionProvider, useSectionStore, remToPx, applyThemeVariables, themeEditorPresets, themePresets, themeBootstrapScript };
|
|
26
|
+
export { Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, Pre, Prose, Heading, Logo, Mermaid, GridPattern, HeroPattern, Feedback, Tag, WebFrame };
|
|
25
27
|
export { DocShell, Markdown, useMDXComponents, markdownRemarkPlugins };
|
|
28
|
+
export { SlotProvider, RuntimeSlot, RuntimeSlotsProvider, useSlot };
|
|
26
29
|
export { OpenApiDocument, OpenApiOperation };
|
package/output/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { C as Code, D as
|
|
2
|
-
import {
|
|
3
|
-
import { a as themeBootstrapScript, c as AppShell, d as
|
|
1
|
+
import { A as Button, C as Code, D as Card, E as Mermaid, O as CardGroup, S as Collapse, T as Pre, _ as HeroPattern, b as Tag, f as Markdown, g as GridPattern, h as Prose, k as Callout, m as WebFrame, n as OpenApiOperation$1, p as primitives_exports, v as Logo, w as CodeGroup, x as Feedback, y as Heading } from "./OpenApiOperation-J41rHO2l.js";
|
|
2
|
+
import { M as useConfig, N as useLocale, O as useBuiltInText, P as useOpenApis, c as remToPx, g as useTheme, h as ThemeProvider, j as OpenApisContext, m as ThemeToggle, n as PageTitleActions, o as SectionProvider, s as useSectionStore } from "./PageActions-DR0asnKH.js";
|
|
3
|
+
import { a as themeBootstrapScript, c as AppShell, d as BuiltWithClarify, f as RuntimeSlot, h as useSlot, i as themeEditorPresets, l as PageFooter, m as SlotProvider, n as ThemeEditor, o as themePresets, p as RuntimeSlotsProvider, r as applyThemeVariables, u as PageBanner } from "./ClarifyShell-BxB_6Uhd.js";
|
|
4
4
|
import { t as markdownRemarkPlugins } from "./remark-Dd2WU50s.js";
|
|
5
|
-
import { t as render } from "./render-
|
|
5
|
+
import { t as render } from "./render-mGozubG5.js";
|
|
6
6
|
import { useLocation } from "react-router-dom";
|
|
7
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
8
|
//#region source/openapi/lib/spec-path.ts
|
|
@@ -25,23 +25,22 @@ function normalizeSpecPath(specPath, currentRoutePath, routePrefix = "") {
|
|
|
25
25
|
/**
|
|
26
26
|
* 为绝对 specPath 生成带 locale 前缀的候选模块 ID。
|
|
27
27
|
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。
|
|
28
|
+
* 所有 locale 的 spec 都注册在 `virtual:clarify-page/<locale>/...` 下,
|
|
29
|
+
* 因此绝对路径(如 `/api`)需要显式注入 locale 前缀才能命中。
|
|
30
|
+
* 相对路径会因为当前路由已含 locale 前缀而自动解析到正确的 spec。
|
|
32
31
|
*/
|
|
33
|
-
function localizeSpecModuleId(moduleId, specPath, locale,
|
|
34
|
-
if (!locale
|
|
32
|
+
function localizeSpecModuleId(moduleId, specPath, locale, _defaultLocale) {
|
|
33
|
+
if (!locale) return void 0;
|
|
35
34
|
if (!specPath.startsWith("/") || specPath.startsWith(VIRTUAL_PREFIX)) return void 0;
|
|
36
35
|
const rest = moduleId.slice(21);
|
|
37
36
|
if (rest.startsWith(`${locale}/`) || rest === locale) return void 0;
|
|
38
37
|
return `${VIRTUAL_PREFIX}${locale}/${rest}`;
|
|
39
38
|
}
|
|
40
39
|
function useOpenApiSpec(spec, specPath) {
|
|
41
|
-
const specs = useOpenApis();
|
|
42
|
-
const location = useLocation();
|
|
43
40
|
const config = useConfig();
|
|
44
41
|
const locale = useLocale();
|
|
42
|
+
const specs = useOpenApis();
|
|
43
|
+
const location = useLocation();
|
|
45
44
|
if (spec) return spec;
|
|
46
45
|
if (!specPath) return null;
|
|
47
46
|
const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix);
|
|
@@ -202,7 +201,8 @@ function OpenApiOperation(arg0) {
|
|
|
202
201
|
var builtInMDXComponents = {
|
|
203
202
|
...primitives_exports,
|
|
204
203
|
Markdown,
|
|
205
|
-
Collapse
|
|
204
|
+
Collapse,
|
|
205
|
+
Mermaid
|
|
206
206
|
};
|
|
207
207
|
var builtInOpenAPIComponents = {
|
|
208
208
|
OpenApiDocument,
|
|
@@ -237,6 +237,6 @@ function DocShell(arg0) {
|
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
239
|
//#endregion
|
|
240
|
-
export { AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse,
|
|
240
|
+
export { AppShell, BuiltWithClarify, Button, Callout, Card, CardGroup, Code, CodeGroup, Collapse, DocShell, Feedback, GridPattern, Heading, HeroPattern, Logo, Markdown, Mermaid, OpenApiDocument, OpenApiOperation, OpenApisContext, PageBanner, PageFooter, Pre, Prose, RuntimeSlot, RuntimeSlotsProvider, SectionProvider, SlotProvider, Tag, ThemeEditor, ThemeProvider, ThemeToggle, WebFrame, applyThemeVariables, markdownRemarkPlugins, remToPx, render, themeBootstrapScript, themeEditorPresets, themePresets, useMDXComponents, useOpenApis, useSectionStore, useSlot, useTheme };
|
|
241
241
|
|
|
242
242
|
//# sourceMappingURL=index.js.map
|
package/output/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useConfig, useLocale, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\n/**\n * 为绝对 specPath 生成带 locale 前缀的候选模块 ID。\n *\n * 局部嵌入(OpenApiOperation / OpenApiDocument)通常使用 `/api` 这样的绝对路径。\n * 默认 locale 的 spec 注册在 `virtual:clarify-page/api`,而其他 locale 的 spec\n * 注册在 `virtual:clarify-page/<locale>/api`。相对路径会因为当前路由已含 locale 前缀\n * 而自动解析到正确的 spec,但绝对路径不会,因此这里显式注入 locale 前缀。\n */\nfunction localizeSpecModuleId(moduleId: string, specPath: string, locale: string | undefined, defaultLocale: string | undefined): string | undefined {\n if (!locale || locale === defaultLocale) return undefined\n // 仅处理绝对路径;相对路径已经基于含 locale 前缀的当前路由解析。\n if (!specPath.startsWith('/') || specPath.startsWith(VIRTUAL_PREFIX)) return undefined\n const rest = moduleId.slice(VIRTUAL_PREFIX.length)\n if (rest.startsWith(`${locale}/`) || rest === locale) return undefined\n return `${VIRTUAL_PREFIX}${locale}/${rest}`\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const specs = useOpenApis()\n const location = useLocation()\n const config = useConfig()\n const locale = useLocale()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale)\n\n if (localized && specs[localized]) return specs[localized]\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { PageTitleActions } from '../app/PageActions'\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase\">\n {t('openapi.openApiReference')}\n </p>\n <div className=\"clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between\">\n <h1 className=\"clarify-page-title min-w-0 flex-1\">{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n <PageTitleActions />\n </div>\n {spec.info?.description ? <Markdown className=\"lead mt-4 *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"mt-4 text-sm text-(--clarify-ui-text-faint)\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAiB,IAAoB;CAChE,MAAM,SAAS,UAAU,MAAM,IAAI,MAAM,GAAG,EAAE,OAAO,OAAO;CAC5D,MAAM,QAAkB,CAAC;CACzB,KAAK,MAAM,QAAQ,OACjB,IAAI,SAAS,MACX,MAAM,IAAI;MACL,IAAI,SAAS,KAClB,MAAM,KAAK,IAAI;CAGnB,OAAO,MAAM,KAAK,GAAG;AACvB;AAEA,SAAS,kBAAkB,UAAkB,kBAA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EAAc,CAAA;CAG1E,OAAO,oBAAC,0BAAD;EAAgC;EAAY;EAAc;CAAS,CAAA;AAC5E;;;ACjIA,IAAM,uBAAuB;CAC3B,GAAG;CACH;CACA;AACF;AAEA,IAAM,2BAA2B;CAC/B;CACA;AACF;AAEA,SAAgB,iBAAiB,aAAsC,CAAC,GAAG;CACzE,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF;;;ACbA,SAAgB,SAAS,MAAqB;CAC5C,MAAM,EAAE,OAAO,UAAU,aAAa;CAEtC,OACE,oBAAC,QAAD;EAAM,WAAU;YACd,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,qBAAC,UAAD;IAAQ,WAAU;cAAlB,CACE,oBAAC,MAAD;KAAI,WAAU;eAAiD;IAAU,CAAA,GACxE,WAAW,oBAAC,KAAD;KAAG,WAAU;eAAgD;IAAY,CAAA,IAAI,IACnF;OACR,oBAAC,OAAD,EAAQ,SAAgB,CAAA,CACrB;;CACD,CAAA;AAEV"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../source/openapi/lib/spec-path.ts","../source/openapi/lib/utils.ts","../source/openapi/entry.tsx","../source/mdx/components.ts","../source/mdx/DocShell.tsx"],"sourcesContent":["import { useLocation } from 'react-router-dom'\n\nimport { useConfig, useLocale, useOpenApis } from '../../core/context'\n\nimport type { OpenAPISpec } from './utils'\n\nconst VIRTUAL_PREFIX = 'virtual:clarify-page/'\n\nfunction resolveRelativePath(fromDir: string, to: string): string {\n const parts = (fromDir + '/' + to).split('/').filter(Boolean)\n const stack: string[] = []\n for (const part of parts) {\n if (part === '..') {\n stack.pop()\n } else if (part !== '.') {\n stack.push(part)\n }\n }\n return stack.join('/')\n}\n\nfunction normalizeSpecPath(specPath: string, currentRoutePath?: string, routePrefix = ''): string {\n if (specPath.startsWith(VIRTUAL_PREFIX)) return specPath\n\n const normalizedRoutePrefix = routePrefix.replace(/^\\/+|\\/+$/g, '')\n const normalizedSpecPath = specPath.startsWith('/') && normalizedRoutePrefix && specPath.slice(1).startsWith(`${normalizedRoutePrefix}/`)\n ? '/' + specPath.slice(normalizedRoutePrefix.length + 2)\n : specPath\n\n if (normalizedSpecPath.startsWith('/')) {\n return VIRTUAL_PREFIX + normalizedSpecPath.replace(/^\\//, '')\n }\n const fromDir = currentRoutePath === '/' ? '' : currentRoutePath?.replace(/^\\//, '').replace(/\\/[^/]*$/, '') ?? ''\n const normalizedFromDir = normalizedRoutePrefix && fromDir.startsWith(`${normalizedRoutePrefix}/`)\n ? fromDir.slice(normalizedRoutePrefix.length + 1)\n : fromDir\n return VIRTUAL_PREFIX + resolveRelativePath(normalizedFromDir, normalizedSpecPath)\n}\n\n/**\n * 为绝对 specPath 生成带 locale 前缀的候选模块 ID。\n *\n * 所有 locale 的 spec 都注册在 `virtual:clarify-page/<locale>/...` 下,\n * 因此绝对路径(如 `/api`)需要显式注入 locale 前缀才能命中。\n * 相对路径会因为当前路由已含 locale 前缀而自动解析到正确的 spec。\n */\nfunction localizeSpecModuleId(moduleId: string, specPath: string, locale: string | undefined, _defaultLocale: string | undefined): string | undefined {\n if (!locale) return undefined\n // 仅处理绝对路径;相对路径已经基于含 locale 前缀的当前路由解析。\n if (!specPath.startsWith('/') || specPath.startsWith(VIRTUAL_PREFIX)) return undefined\n const rest = moduleId.slice(VIRTUAL_PREFIX.length)\n if (rest.startsWith(`${locale}/`) || rest === locale) return undefined\n return `${VIRTUAL_PREFIX}${locale}/${rest}`\n}\n\nexport function useOpenApiSpec(spec?: OpenAPISpec, specPath?: string): OpenAPISpec | null {\n const config = useConfig()\n const locale = useLocale()\n const specs = useOpenApis()\n const location = useLocation()\n\n if (spec) return spec\n if (!specPath) return null\n\n const normalized = normalizeSpecPath(specPath, location.pathname, config.routePrefix)\n const localized = localizeSpecModuleId(normalized, specPath, locale, config.i18n?.defaultLocale)\n\n if (localized && specs[localized]) return specs[localized]\n return specs[normalized] ?? null\n}\n","import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types'\n\nimport type { OpenApiRecord } from '../types'\n\nexport type OpenAPISpec = OpenAPIV3.Document | OpenAPIV3_1.Document\nexport type OpenAPIOperation = OpenAPIV3.OperationObject | OpenAPIV3_1.OperationObject\n\nexport const OPENAPI_HTTP_METHODS = ['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace'] as const\n\nexport type OpenAPIHttpMethod = typeof OPENAPI_HTTP_METHODS[number]\n\nexport function isOpenAPIHttpMethod(method: string): method is OpenAPIHttpMethod {\n return (OPENAPI_HTTP_METHODS as readonly string[]).includes(method.toLowerCase())\n}\n\nfunction isRecord(value: unknown): value is OpenApiRecord {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction resolveOpenApiRef(spec: OpenAPISpec, ref: string): unknown {\n if (!ref.startsWith('#/')) return undefined\n\n return ref\n .slice(2)\n .split('/')\n .map((part) => part.replace(/~1/g, '/').replace(/~0/g, '~'))\n .reduce<unknown>((current, part) => (isRecord(current) ? current[part] : undefined), spec)\n}\n\nfunction getPathItem(spec: OpenAPISpec, path: string): OpenApiRecord | undefined {\n const pathItem = spec.paths?.[path]\n const resolved = isRecord(pathItem) && typeof pathItem.$ref === 'string' ? resolveOpenApiRef(spec, pathItem.$ref) : pathItem\n return isRecord(resolved) ? resolved : undefined\n}\n\nexport function getOpenApiOperation(spec: OpenAPISpec, path: string, method: string): OpenAPIOperation | undefined {\n if (!isOpenAPIHttpMethod(method)) return undefined\n return getPathItem(spec, path)?.[method.toLowerCase() as OpenAPIHttpMethod] as OpenAPIOperation | undefined\n}\n\nexport function listOpenApiOperations(spec: OpenAPISpec): Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> {\n const paths = spec.paths ?? {}\n const operations: Array<{ path: string; method: OpenAPIHttpMethod; operation: OpenAPIOperation }> = []\n\n for (const path of Object.keys(paths)) {\n const pathItem = getPathItem(spec, path)\n if (!pathItem) continue\n for (const method of OPENAPI_HTTP_METHODS) {\n const operation = pathItem[method]\n if (operation) operations.push({ path, method, operation: operation as OpenAPIOperation })\n }\n }\n\n return operations\n}\n","import type { ReactNode } from 'react'\n\nimport { PageTitleActions } from '../app/PageActions'\nimport { Prose } from '../components/Prose'\nimport { useBuiltInText } from '../core/i18n'\nimport { Markdown } from '../mdx/Markdown'\n\nimport { OpenApiOperation as OpenApiOperationComponent } from './components/OpenApiOperation'\nimport { useOpenApiSpec } from './lib/spec-path'\nimport { getOpenApiOperation, listOpenApiOperations } from './lib/utils'\nimport type { OpenAPISpec } from './lib/utils'\n\ntype OpenApiPathsProps = { spec: OpenAPISpec; tagFilter?: string[] }\n\ntype OpenApiHeaderProps = { spec: OpenAPISpec }\n\ntype WarningBoxProps = {\n children: ReactNode\n tone?: 'amber' | 'red'\n}\n\nexport type OpenApiDocumentProps = {\n spec?: OpenAPISpec\n specPath?: string\n tagFilter?: string[]\n}\n\ntype OpenApiOperationWithSpecProps = {\n spec: OpenAPISpec\n path: string\n method: string\n}\n\nexport type OpenApiOperationProps = {\n specPath: string\n path: string\n method: string\n}\n\nfunction OpenApiHeader(arg0: OpenApiHeaderProps): ReactNode {\n const { spec } = arg0\n\n const t = useBuiltInText()\n return (\n <header className=\"clarify-openapi-header mb-16 border-b border-(--clarify-theme-tokens-colors-border) pb-8\">\n <p className=\"mb-3 text-xs/6 font-medium tracking-widest text-(--clarify-ui-accent-text) uppercase\">\n {t('openapi.openApiReference')}\n </p>\n <div className=\"clarify-page-title-row flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between\">\n <h1 className=\"clarify-page-title min-w-0 flex-1\">{spec.info?.title ?? t('openapi.apiDocumentation')}</h1>\n <PageTitleActions />\n </div>\n {spec.info?.description ? <Markdown className=\"lead mt-4 *:first:mt-0 *:last:mb-0\">{spec.info.description}</Markdown> : null}\n {spec.info?.version ? <p className=\"mt-4 text-sm text-(--clarify-ui-text-faint)\">{t('openapi.version', { version: spec.info.version })}</p> : null}\n </header>\n )\n}\n\nfunction operationMatchesTags(operationTags: string[] | undefined, filterTags: string[] | undefined): boolean {\n if (!filterTags?.length) return true\n return operationTags?.some(tag => filterTags.includes(tag)) ?? false\n}\n\nfunction OpenApiPaths(arg0: OpenApiPathsProps): ReactNode {\n const { spec, tagFilter } = arg0\n\n const entries = listOpenApiOperations(spec)\n .filter(({ operation }) => operationMatchesTags(operation.tags, tagFilter))\n .map(({ path, method, operation }) => ({\n path,\n method: method.toUpperCase(),\n operation,\n }))\n\n return (\n <div className=\"clarify-api-endpoints divide-y divide-zinc-200/70 dark:divide-white/10\">\n {entries.map(({ path, method, operation }) => (\n <OpenApiOperationComponent key={`${method}-${path}`} spec={spec} path={path} method={method} operation={operation} />\n ))}\n </div>\n )\n}\n\nfunction WarningBox(arg0: WarningBoxProps): ReactNode {\n const { children, tone = 'amber' } = arg0\n\n const classes = tone === 'red'\n ? 'rounded-lg border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-500/30 dark:bg-red-500/10 dark:text-red-200'\n : 'rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-700 dark:border-amber-500/30 dark:bg-amber-500/10 dark:text-amber-200'\n\n return <div className={`clarify-warning ${classes}`}>{children}</div>\n}\n\nexport function OpenApiDocument(arg0: OpenApiDocumentProps): ReactNode {\n const { spec, specPath, tagFilter } = arg0\n const t = useBuiltInText()\n const resolved = useOpenApiSpec(spec, specPath)\n\n if (!resolved) {\n return <WarningBox>{t('openapi.specNotFound', { specPath: specPath ?? t('openapi.specPathMissing') })}</WarningBox>\n }\n\n return (\n <article className=\"clarify-openapi-page flex h-full flex-col pt-16 pb-10\">\n <Prose className=\"flex-auto\">\n <OpenApiHeader spec={resolved} />\n <OpenApiPaths spec={resolved} tagFilter={tagFilter} />\n </Prose>\n </article>\n )\n}\n\nfunction OpenApiOperationWithSpec(arg0: OpenApiOperationWithSpecProps): ReactNode {\n const { spec, path, method } = arg0\n const t = useBuiltInText()\n const op = getOpenApiOperation(spec, path, method)\n\n if (!op) {\n return <WarningBox tone=\"red\">{t('openapi.endpointNotFound', { endpoint: `${method.toUpperCase()} ${path}` })}</WarningBox>\n }\n\n const normalizedMethod = method.toUpperCase()\n return <OpenApiOperationComponent key={`${normalizedMethod}-${path}`} spec={spec} path={path} method={normalizedMethod} operation={op} />\n}\n\nexport function OpenApiOperation(arg0: OpenApiOperationProps): ReactNode {\n const { specPath, path, method } = arg0\n const t = useBuiltInText()\n const spec = useOpenApiSpec(undefined, specPath)\n\n if (!spec) {\n return <WarningBox>{t('openapi.specNotFound', { specPath })}</WarningBox>\n }\n\n return <OpenApiOperationWithSpec spec={spec} path={path} method={method} />\n}\n","import { Collapse } from '../components/Collapse'\nimport { Mermaid } from '../components/Mermaid'\nimport { OpenApiDocument, OpenApiOperation } from '../openapi'\n\nimport { Markdown } from './Markdown'\nimport * as mdxPrimitives from './primitives'\n\nconst builtInMDXComponents = {\n ...mdxPrimitives,\n Markdown,\n Collapse,\n Mermaid,\n}\n\nconst builtInOpenAPIComponents = {\n OpenApiDocument,\n OpenApiOperation,\n}\n\nexport function useMDXComponents(components: Record<string, unknown> = {}) {\n return {\n ...components,\n ...builtInMDXComponents,\n ...builtInOpenAPIComponents,\n }\n}\n","import type { ReactNode } from 'react'\n\nimport { Prose } from '../components/Prose'\n\nexport type DocShellProps = {\n title: string\n subtitle?: string\n children: ReactNode\n}\n\nexport function DocShell(arg0: DocShellProps) {\n const { title, subtitle, children } = arg0\n\n return (\n <main className=\"clarify-doc-shell min-h-screen bg-(--clarify-theme-tokens-colors-background) px-6 py-10 text-(--clarify-theme-tokens-colors-foreground) md:px-10\">\n <div className=\"mx-auto max-w-6xl\">\n <header className=\"mb-10\">\n <h1 className=\"text-3xl font-bold tracking-tight md:text-5xl\">{title}</h1>\n {subtitle ? <p className=\"mt-3 max-w-2xl text-(--clarify-ui-text-soft)\">{subtitle}</p> : null}\n </header>\n <Prose>{children}</Prose>\n </div>\n </main>\n )\n}\n"],"mappings":";;;;;;;;AAMA,IAAM,iBAAiB;AAEvB,SAAS,oBAAoB,SAAi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AjG,GAAG,iBAAiB,GAAG,MAA0E;AAC1I;AAEA,SAAgB,iBAAiB,MAAwC;CACvE,MAAM,EAAE,UAAU,MAAM,WAAW;CACnC,MAAM,IAAI,eAAe;CACzB,MAAM,OAAO,eAAe,KAAA,GAAW,QAAQ;CAE/C,IAAI,CAAC,MACH,OAAO,oBAAC,YAAD,EAAA,UAAa,EAAE,wBAAwB,EAAE,SAAS,CAAC,EAAc,CAAA;CAG1E,OAAO,oBAAC,0BAAD;EAAgC;EAAY;EAAc;CAAS,CAAA;AAC5E;;;AChIA,IAAM,uBAAuB;CAC3B,GAAG;CACH;CACA;CACA;AACF;AAEA,IAAM,2BAA2B;CAC/B;CACA;AACF;AAEA,SAAgB,iBAAiB,aAAsC,CAAC,GAAG;CACzE,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;CACL;AACF;;;ACfA,SAAgB,SAAS,MAAqB;CAC5C,MAAM,EAAE,OAAO,UAAU,aAAa;CAEtC,OACE,oBAAC,QAAD;EAAM,WAAU;YACd,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,qBAAC,UAAD;IAAQ,WAAU;cAAlB,CACE,oBAAC,MAAD;KAAI,WAAU;eAAiD;IAAU,CAAA,GACxE,WAAW,oBAAC,KAAD;KAAG,WAAU;eAAgD;IAAY,CAAA,IAAI,IACnF;OACR,oBAAC,OAAD,EAAQ,SAAgB,CAAA,CACrB;;CACD,CAAA;AAEV"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Collapse } from '../components/Collapse';
|
|
2
|
+
import { Mermaid } from '../components/Mermaid';
|
|
2
3
|
import { OpenApiDocument, OpenApiOperation } from '../openapi';
|
|
3
4
|
import { Markdown } from './Markdown';
|
|
4
5
|
import * as mdxPrimitives from './primitives';
|
|
@@ -7,9 +8,11 @@ export declare function useMDXComponents(components?: Record<string, unknown>):
|
|
|
7
8
|
OpenApiOperation: typeof OpenApiOperation;
|
|
8
9
|
Markdown: typeof Markdown;
|
|
9
10
|
Collapse: typeof Collapse;
|
|
11
|
+
Mermaid: typeof Mermaid;
|
|
10
12
|
wrapper(arg0: {
|
|
11
13
|
children: import('react').ReactNode;
|
|
12
14
|
}): import("react").JSX.Element;
|
|
15
|
+
table(arg0: import('react').ComponentPropsWithoutRef<"table">): import("react").JSX.Element;
|
|
13
16
|
a(arg0: import('react').ComponentPropsWithoutRef<"a">): import("react").JSX.Element;
|
|
14
17
|
h1(arg0: import('react').ComponentPropsWithoutRef<"h1">): import("react").JSX.Element;
|
|
15
18
|
h2(props: Omit<import('react').ComponentPropsWithoutRef<typeof import('..').Heading>, "level">): import('react').FunctionComponentElement<Omit<import('react').DetailedHTMLProps<import('react').HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, "ref"> & {
|
|
@@ -31,6 +34,7 @@ export declare function useMDXComponents(components?: Record<string, unknown>):
|
|
|
31
34
|
}): import("react").JSX.Element;
|
|
32
35
|
Row(arg0: {
|
|
33
36
|
children: import('react').ReactNode;
|
|
37
|
+
className?: string;
|
|
34
38
|
}): import("react").JSX.Element;
|
|
35
39
|
Col(arg0: {
|
|
36
40
|
children: import('react').ReactNode;
|
|
@@ -5,6 +5,7 @@ type WrapperProps = {
|
|
|
5
5
|
children: ReactNode;
|
|
6
6
|
};
|
|
7
7
|
export declare function wrapper(arg0: WrapperProps): import("react").JSX.Element;
|
|
8
|
+
export declare function table(arg0: ComponentPropsWithoutRef<'table'>): import("react").JSX.Element;
|
|
8
9
|
export declare function a(arg0: ComponentPropsWithoutRef<'a'>): import("react").JSX.Element;
|
|
9
10
|
export declare function h1(arg0: ComponentPropsWithoutRef<'h1'>): import("react").JSX.Element;
|
|
10
11
|
export declare const code: typeof Code;
|
|
@@ -30,6 +31,7 @@ type NoteProps = {
|
|
|
30
31
|
export declare function Note(arg0: NoteProps): import("react").JSX.Element;
|
|
31
32
|
type RowProps = {
|
|
32
33
|
children: ReactNode;
|
|
34
|
+
className?: string;
|
|
33
35
|
};
|
|
34
36
|
export declare function Row(arg0: RowProps): import("react").JSX.Element;
|
|
35
37
|
type ColProps = {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { OpenAPIOperation, OpenAPISpec } from '../lib/utils';
|
|
3
|
+
import { MediaTypeEntry, OpenApiParameter, OpenApiRecord, OpenApiServer, RequestAuthInput } from '../types';
|
|
4
|
+
type EndpointRequestProps = {
|
|
5
|
+
spec: OpenAPISpec;
|
|
6
|
+
path: string;
|
|
7
|
+
method: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
groupedParameters: {
|
|
10
|
+
path: OpenApiParameter[];
|
|
11
|
+
query: OpenApiParameter[];
|
|
12
|
+
header: OpenApiParameter[];
|
|
13
|
+
};
|
|
14
|
+
parameters: OpenApiParameter[];
|
|
15
|
+
requestBody?: OpenApiRecord;
|
|
16
|
+
requestContents: MediaTypeEntry[];
|
|
17
|
+
requestSchema: unknown;
|
|
18
|
+
selectedRequestMediaType: string;
|
|
19
|
+
onSelectRequestMediaType: (value: string) => void;
|
|
20
|
+
selectedServer: OpenApiServer;
|
|
21
|
+
serverVariables: Record<string, string>;
|
|
22
|
+
auth?: RequestAuthInput;
|
|
23
|
+
};
|
|
24
|
+
export declare function EndpointRequest(arg0: EndpointRequestProps): ReactNode;
|
|
25
|
+
type EndpointResponseProps = {
|
|
26
|
+
spec: OpenAPISpec;
|
|
27
|
+
operation: OpenAPIOperation;
|
|
28
|
+
};
|
|
29
|
+
export declare function EndpointResponse(arg0: EndpointResponseProps): ReactNode;
|
|
30
|
+
export {};
|
package/output/preview.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_PageActions = require("./PageActions-
|
|
3
|
-
const require_OpenApiOperation = require("./OpenApiOperation-
|
|
2
|
+
const require_PageActions = require("./PageActions-yycPlNyL.cjs");
|
|
3
|
+
const require_OpenApiOperation = require("./OpenApiOperation-9SvCA_B4.cjs");
|
|
4
4
|
let react = require("react");
|
|
5
5
|
let react_router_dom = require("react-router-dom");
|
|
6
6
|
let lucide_react = require("lucide-react");
|