shelving 1.217.0 → 1.218.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/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type DocumentationElementProps } from "../../util/element.js";
|
|
3
3
|
/**
|
|
4
|
-
* Page renderer for a `tree-documentation` element.
|
|
5
|
-
* - Renders title, signatures (one per overload), content, parameters, returns, throws,
|
|
6
|
-
* -
|
|
4
|
+
* Page renderer for a `tree-documentation` element (also used for `tree-file` elements, whose props are a compatible subset).
|
|
5
|
+
* - Renders title, signatures (one per overload), content, parameters, returns, throws, and examples.
|
|
6
|
+
* - Child symbols are grouped by `kind` into card sections (Functions, Classes, Methods, Properties, …), each under its own heading.
|
|
7
|
+
* - All sections are conditional — only render when they have entries.
|
|
7
8
|
*/
|
|
8
9
|
export declare function DocumentationPage({ title, name, kind, description, content, signatures, params, returns, throws, examples, children, }: DocumentationElementProps): ReactNode;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { queryElements } from "../../util/element.js";
|
|
2
3
|
import { Definition, Definitions } from "../block/Definitions.js";
|
|
3
4
|
import { Flex } from "../block/Flex.js";
|
|
4
5
|
import { Heading } from "../block/Heading.js";
|
|
@@ -13,13 +14,28 @@ import { Page } from "../page/Page.js";
|
|
|
13
14
|
import { TreeCards } from "../tree/TreeCards.js";
|
|
14
15
|
import { DocumentationKind } from "./DocumentationKind.js";
|
|
15
16
|
const DEFAULT_TYPE = "unknown";
|
|
17
|
+
/** Documentation `kind`s grouped into card sections, in display order — pluralised, sentence-case headings. */
|
|
18
|
+
const KIND_SECTIONS = [
|
|
19
|
+
["function", "Functions"],
|
|
20
|
+
["class", "Classes"],
|
|
21
|
+
["interface", "Interfaces"],
|
|
22
|
+
["type", "Types"],
|
|
23
|
+
["constant", "Constants"],
|
|
24
|
+
["method", "Methods"],
|
|
25
|
+
["property", "Properties"],
|
|
26
|
+
];
|
|
16
27
|
/**
|
|
17
|
-
* Page renderer for a `tree-documentation` element.
|
|
18
|
-
* - Renders title, signatures (one per overload), content, parameters, returns, throws,
|
|
19
|
-
* -
|
|
28
|
+
* Page renderer for a `tree-documentation` element (also used for `tree-file` elements, whose props are a compatible subset).
|
|
29
|
+
* - Renders title, signatures (one per overload), content, parameters, returns, throws, and examples.
|
|
30
|
+
* - Child symbols are grouped by `kind` into card sections (Functions, Classes, Methods, Properties, …), each under its own heading.
|
|
31
|
+
* - All sections are conditional — only render when they have entries.
|
|
20
32
|
*/
|
|
21
33
|
export function DocumentationPage({ title, name, kind, description, content, signatures, params, returns, throws, examples, children, }) {
|
|
22
34
|
const { url } = requireMeta();
|
|
23
35
|
const path = (url?.pathname ?? "/");
|
|
24
|
-
return (_jsxs(Page, { title: title ?? name, description: description, children: [_jsx(Title, { children: _jsxs(Flex, { left: true, children: [title ?? name, kind && _jsx(DocumentationKind, { kind: kind })] }) }), signatures?.map(sig => (_jsx(Preformatted, { children: sig }, sig))), content && (_jsx(Prose, { children: _jsx(Markup, { children: content }) })), params?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Parameters" }), _jsx(Definitions, { row: true, children: params.map(({ name, type = DEFAULT_TYPE, description = "", optional }) => (_jsx(Definition, { term: _jsxs(_Fragment, { children: [_jsx(Code, { children: name }), ": ", _jsx(Code, { children: type }), optional && _jsx(_Fragment, { children: " (optional)" })] }), children: description }, `${name}-${type}-${description}`))) })] })), returns?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Returns" }), _jsx(Definitions, { row: true, children: returns.map(({ type = DEFAULT_TYPE, description = "" }) => (_jsx(Definition, { term: _jsx(Code, { children: type }), children: description }, `${type}-${description}`))) })] })), throws?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Throws" }), _jsx(Definitions, { row: true, children: throws.map(({ type = DEFAULT_TYPE, description = "" }) => (_jsx(Definition, { term: _jsx(Code, { children: type }), children: description }, `${type}-${description}`))) })] })), examples?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Examples" }), examples.map(({ description }) => (_jsx(Preformatted, { children: description }, description)))] })),
|
|
36
|
+
return (_jsxs(Page, { title: title ?? name, description: description, children: [_jsx(Title, { children: _jsxs(Flex, { left: true, children: [title ?? name, kind && _jsx(DocumentationKind, { kind: kind })] }) }), signatures?.map(sig => (_jsx(Preformatted, { children: sig }, sig))), content && (_jsx(Prose, { children: _jsx(Markup, { children: content }) })), params?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Parameters" }), _jsx(Definitions, { row: true, children: params.map(({ name, type = DEFAULT_TYPE, description = "", optional }) => (_jsx(Definition, { term: _jsxs(_Fragment, { children: [_jsx(Code, { children: name }), ": ", _jsx(Code, { children: type }), optional && _jsx(_Fragment, { children: " (optional)" })] }), children: description }, `${name}-${type}-${description}`))) })] })), returns?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Returns" }), _jsx(Definitions, { row: true, children: returns.map(({ type = DEFAULT_TYPE, description = "" }) => (_jsx(Definition, { term: _jsx(Code, { children: type }), children: description }, `${type}-${description}`))) })] })), throws?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Throws" }), _jsx(Definitions, { row: true, children: throws.map(({ type = DEFAULT_TYPE, description = "" }) => (_jsx(Definition, { term: _jsx(Code, { children: type }), children: description }, `${type}-${description}`))) })] })), examples?.length && (_jsxs(Section, { children: [_jsx(Heading, { children: "Examples" }), examples.map(({ description }) => (_jsx(Preformatted, { children: description }, description)))] })), KIND_SECTIONS.map(([kind, label]) => {
|
|
37
|
+
// Pre-filter the children for this kind; only render the section when it has cards.
|
|
38
|
+
const group = Array.from(queryElements(children, { "props.kind": kind }));
|
|
39
|
+
return group.length ? (_jsxs(Section, { children: [_jsx(Heading, { children: label }), _jsx(TreeCards, { path: path, children: group })] }, kind)) : null;
|
|
40
|
+
})] }));
|
|
25
41
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
+
import type { DocumentationElement } from "../../util/element.js";
|
|
4
|
+
import { DocumentationPage } from "./DocumentationPage.js";
|
|
5
|
+
|
|
6
|
+
/** Make a minimal `tree-documentation` child element of a given kind. */
|
|
7
|
+
function doc(name: string, kind: string): DocumentationElement {
|
|
8
|
+
return { type: "tree-documentation", key: name, props: { name, kind } };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe("DocumentationPage", () => {
|
|
12
|
+
test("groups child symbols into kind-based sections, in order", () => {
|
|
13
|
+
const html = renderToStaticMarkup(
|
|
14
|
+
<DocumentationPage name="array">
|
|
15
|
+
{[doc("getThing", "function"), doc("Widget", "class"), doc("getOther", "function")]}
|
|
16
|
+
</DocumentationPage>,
|
|
17
|
+
);
|
|
18
|
+
expect(html).toContain("Functions");
|
|
19
|
+
expect(html).toContain("Classes");
|
|
20
|
+
// Sections render in `KIND_SECTIONS` order — functions before classes.
|
|
21
|
+
expect(html.indexOf("Functions")).toBeLessThan(html.indexOf("Classes"));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("renders a section only for kinds that have children", () => {
|
|
25
|
+
const html = renderToStaticMarkup(
|
|
26
|
+
<DocumentationPage name="Store" kind="class">
|
|
27
|
+
{[doc("get", "method"), doc("size", "property")]}
|
|
28
|
+
</DocumentationPage>,
|
|
29
|
+
);
|
|
30
|
+
expect(html).toContain("Methods");
|
|
31
|
+
expect(html).toContain("Properties");
|
|
32
|
+
expect(html).not.toContain("Functions");
|
|
33
|
+
expect(html).not.toContain("Interfaces");
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type
|
|
2
|
+
import { type DocumentationElementProps, type Element, queryElements, type TreeElement } from "../../util/element.js";
|
|
3
3
|
import type { AbsolutePath } from "../../util/path.js";
|
|
4
|
+
import type { Query } from "../../util/query.js";
|
|
4
5
|
import { Definition, Definitions } from "../block/Definitions.js";
|
|
5
6
|
import { Flex } from "../block/Flex.js";
|
|
6
7
|
import { Heading } from "../block/Heading.js";
|
|
@@ -17,10 +18,22 @@ import { DocumentationKind } from "./DocumentationKind.js";
|
|
|
17
18
|
|
|
18
19
|
const DEFAULT_TYPE = "unknown";
|
|
19
20
|
|
|
21
|
+
/** Documentation `kind`s grouped into card sections, in display order — pluralised, sentence-case headings. */
|
|
22
|
+
const KIND_SECTIONS: ReadonlyArray<readonly [kind: string, label: string]> = [
|
|
23
|
+
["function", "Functions"],
|
|
24
|
+
["class", "Classes"],
|
|
25
|
+
["interface", "Interfaces"],
|
|
26
|
+
["type", "Types"],
|
|
27
|
+
["constant", "Constants"],
|
|
28
|
+
["method", "Methods"],
|
|
29
|
+
["property", "Properties"],
|
|
30
|
+
];
|
|
31
|
+
|
|
20
32
|
/**
|
|
21
|
-
* Page renderer for a `tree-documentation` element.
|
|
22
|
-
* - Renders title, signatures (one per overload), content, parameters, returns, throws,
|
|
23
|
-
* -
|
|
33
|
+
* Page renderer for a `tree-documentation` element (also used for `tree-file` elements, whose props are a compatible subset).
|
|
34
|
+
* - Renders title, signatures (one per overload), content, parameters, returns, throws, and examples.
|
|
35
|
+
* - Child symbols are grouped by `kind` into card sections (Functions, Classes, Methods, Properties, …), each under its own heading.
|
|
36
|
+
* - All sections are conditional — only render when they have entries.
|
|
24
37
|
*/
|
|
25
38
|
export function DocumentationPage({
|
|
26
39
|
title,
|
|
@@ -105,7 +118,16 @@ export function DocumentationPage({
|
|
|
105
118
|
))}
|
|
106
119
|
</Section>
|
|
107
120
|
)}
|
|
108
|
-
|
|
121
|
+
{KIND_SECTIONS.map(([kind, label]) => {
|
|
122
|
+
// Pre-filter the children for this kind; only render the section when it has cards.
|
|
123
|
+
const group = Array.from(queryElements(children, { "props.kind": kind } as Query<Element>)) as TreeElement[];
|
|
124
|
+
return group.length ? (
|
|
125
|
+
<Section key={kind}>
|
|
126
|
+
<Heading>{label}</Heading>
|
|
127
|
+
<TreeCards path={path}>{group}</TreeCards>
|
|
128
|
+
</Section>
|
|
129
|
+
) : null;
|
|
130
|
+
})}
|
|
109
131
|
</Page>
|
|
110
132
|
);
|
|
111
133
|
}
|