@alauda/doom 1.0.0-next.3 → 1.0.0-next.4
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/lib/runtime/components/OpenAPIPath.js +5 -4
- package/lib/runtime/components/OpenAPIRef.d.ts +2 -1
- package/lib/runtime/components/OpenAPIRef.js +7 -3
- package/lib/runtime/components/_HeadingTitle.d.ts +2 -1
- package/lib/runtime/components/_HeadingTitle.js +11 -5
- package/lib/runtime/components/_Markdown.js +1 -3
- package/package.json +1 -1
|
@@ -5,7 +5,7 @@ import openapisMap from 'doom-@api-openapisMap';
|
|
|
5
5
|
import virtual from 'doom-@api-virtual';
|
|
6
6
|
import BananaSlug from 'github-slugger';
|
|
7
7
|
import { OpenAPIV3 } from 'openapi-types';
|
|
8
|
-
import { Fragment, useMemo } from 'react';
|
|
8
|
+
import { Fragment, useId, useMemo } from 'react';
|
|
9
9
|
import { omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
10
10
|
import { OpenAPIProperties, OpenAPIProperty, OpenAPIRef } from './OpenAPIRef.js';
|
|
11
11
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
@@ -91,6 +91,7 @@ const getRefsForPath = (openapi, path, knownRefs) => {
|
|
|
91
91
|
export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathPrefix_, }) => {
|
|
92
92
|
const { page } = usePageData();
|
|
93
93
|
const pathPrefix = pathPrefix_ ?? (virtual.pathPrefix || '');
|
|
94
|
+
const uid = useId();
|
|
94
95
|
const slugger = useMemo(() => new BananaSlug(), []);
|
|
95
96
|
const [pathItem, openapi, openapiPath, refs] = useMemo(() => {
|
|
96
97
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
@@ -113,7 +114,7 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
113
114
|
console.error(`No OpenAPI path definition found for ${path}`);
|
|
114
115
|
return null;
|
|
115
116
|
}
|
|
116
|
-
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
117
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, uid: uid, level: 2, children: [pathPrefix, path] }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
117
118
|
if (!pathItem[method]) {
|
|
118
119
|
return null;
|
|
119
120
|
}
|
|
@@ -125,9 +126,9 @@ export const OpenAPIPath = ({ path, openapiPath: openapiPath_, pathPrefix: pathP
|
|
|
125
126
|
const requestBodySchema = requestBodyRef
|
|
126
127
|
? resolveRef(openapi, requestBodyRef)
|
|
127
128
|
: undefined;
|
|
128
|
-
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 3, children: [_jsx("code", { children: method }), summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBodySchema && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Request Body" }), _jsxs(X.p, { children: [_jsx(RefLink, { "$ref": requestBodyRef }), requestBodySchema.required && _jsx(Badge, { children: "required" })] })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }, method));
|
|
129
|
+
return (_jsxs(Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, uid: uid, level: 3, children: [_jsx("code", { children: method }), summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBodySchema && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Request Body" }), _jsxs(X.p, { children: [_jsx(RefLink, { "$ref": requestBodyRef }), requestBodySchema.required && _jsx(Badge, { children: "required" })] })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, uid: uid, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }, method));
|
|
129
130
|
}), refs?.map((ref) => {
|
|
130
|
-
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, collectRefs: false }, ref));
|
|
131
|
+
return (_jsx(OpenAPIRef, { schema: ref, openapiPath: openapiPath, uid: uid, collectRefs: false }, ref));
|
|
131
132
|
})] }));
|
|
132
133
|
};
|
|
133
134
|
export default OpenAPIPath;
|
|
@@ -8,6 +8,7 @@ export interface OpenAPIRefProps {
|
|
|
8
8
|
* The specific path to the OpenAPI schema, otherwise the first matched will be used.
|
|
9
9
|
*/
|
|
10
10
|
openapiPath?: string;
|
|
11
|
+
uid?: string;
|
|
11
12
|
collectRefs?: boolean;
|
|
12
13
|
}
|
|
13
14
|
export declare const OpenAPIProperty: ({ name, property, openapi, }: {
|
|
@@ -19,5 +20,5 @@ export declare const OpenAPIProperties: ({ properties, openapi, }: {
|
|
|
19
20
|
properties: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
20
21
|
openapi: OpenAPIV3_1.Document;
|
|
21
22
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
23
|
+
export declare const OpenAPIRef: ({ schema, openapiPath: openapiPath_, uid, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
23
24
|
export default OpenAPIRef;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { usePageData } from '@rspress/core/runtime';
|
|
3
3
|
import openapisMap from 'doom-@api-openapisMap';
|
|
4
|
-
import { useMemo } from 'react';
|
|
4
|
+
import { useId, useMemo } from 'react';
|
|
5
5
|
import { modelName, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
6
6
|
import { HeadingTitle } from './_HeadingTitle.js';
|
|
7
7
|
import { Markdown } from './_Markdown.js';
|
|
@@ -68,8 +68,12 @@ const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
|
68
68
|
collectRefs(refSchema);
|
|
69
69
|
return Array.from(refs);
|
|
70
70
|
};
|
|
71
|
-
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = true, }) => {
|
|
71
|
+
export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, uid, collectRefs = true, }) => {
|
|
72
72
|
const { page } = usePageData();
|
|
73
|
+
const innerUid = useId();
|
|
74
|
+
if (uid == null) {
|
|
75
|
+
uid = innerUid;
|
|
76
|
+
}
|
|
73
77
|
const [schemaItem, openapi, openapiPath] = useMemo(() => {
|
|
74
78
|
for (const [pathname, openapi] of Object.entries(openapisMap)) {
|
|
75
79
|
if (openapiPath_ && pathname !== openapiPath_) {
|
|
@@ -91,6 +95,6 @@ export const OpenAPIRef = ({ schema, openapiPath: openapiPath_, collectRefs = tr
|
|
|
91
95
|
return getRefsForSchema(openapi, schema, omitRoutePathRefs(page.routePath));
|
|
92
96
|
}
|
|
93
97
|
}, [collectRefs, openapi, page.routePath, schema]);
|
|
94
|
-
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema) => (_jsx(OpenAPIRef, { schema: schema, openapiPath: openapiPath, collectRefs: false }, schema)))] }));
|
|
98
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { uid: uid, slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema) => (_jsx(OpenAPIRef, { schema: schema, openapiPath: openapiPath, uid: uid, collectRefs: false }, schema)))] }));
|
|
95
99
|
};
|
|
96
100
|
export default OpenAPIRef;
|
|
@@ -3,7 +3,8 @@ import { type ReactNode } from 'react';
|
|
|
3
3
|
export interface HeadingTitleProps {
|
|
4
4
|
slug?: string;
|
|
5
5
|
slugger?: BananaSlug;
|
|
6
|
+
uid?: string;
|
|
6
7
|
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
7
8
|
children: ReactNode;
|
|
8
9
|
}
|
|
9
|
-
export declare const HeadingTitle: ({ slug, slugger, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const HeadingTitle: ({ slug, slugger, uid, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,14 +2,20 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import BananaSlug from 'github-slugger';
|
|
3
3
|
import { Children, useMemo } from 'react';
|
|
4
4
|
import { X } from './_X.js';
|
|
5
|
-
|
|
5
|
+
// TODO: use context to simplify the usage of `slugger` and `uid`
|
|
6
|
+
export const HeadingTitle = ({ slug, slugger, uid, level, children, }) => {
|
|
6
7
|
const HeadingComponents = useMemo(() => {
|
|
7
8
|
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
8
9
|
}, [X]);
|
|
9
10
|
const HeadingComponent = HeadingComponents[level];
|
|
10
|
-
const id = useMemo(() =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.
|
|
11
|
+
const id = useMemo(() => [
|
|
12
|
+
uid,
|
|
13
|
+
slug ||
|
|
14
|
+
slugger?.slug(Children.toArray(children)
|
|
15
|
+
.filter((it) => typeof it === 'string')
|
|
16
|
+
.join('')),
|
|
17
|
+
]
|
|
18
|
+
.filter(Boolean)
|
|
19
|
+
.join('-') || undefined, [slug, uid, children]);
|
|
14
20
|
return (_jsxs(HeadingComponent, { id: id, children: [children, _jsx(X.a, { className: "header-anchor", href: `#${id}`, "aria-hidden": true, children: "#" })] }));
|
|
15
21
|
};
|
|
@@ -3,6 +3,4 @@ import {} from 'react';
|
|
|
3
3
|
import ReactMarkdown from 'react-markdown';
|
|
4
4
|
import remarkGfm from 'remark-gfm';
|
|
5
5
|
import { X } from './_X.js';
|
|
6
|
-
export const Markdown = ({ children }) => {
|
|
7
|
-
return (children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: X, skipHtml: true, children: children })));
|
|
8
|
-
};
|
|
6
|
+
export const Markdown = ({ children }) => children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: X, skipHtml: true, children: children }));
|