@nanisoft/prism-ui 0.6.0 → 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/dist/.tsbuildinfo +1 -1
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +40 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -0
- package/dist/components/ui/breadcrumb.d.ts +6 -2
- package/dist/components/ui/breadcrumb.d.ts.map +1 -1
- package/dist/components/ui/breadcrumb.js +5 -3
- package/dist/components/ui/dialog.d.ts +12 -1
- package/dist/components/ui/dialog.d.ts.map +1 -1
- package/dist/components/ui/dialog.js +2 -2
- package/dist/components/ui/live-region.d.ts +78 -0
- package/dist/components/ui/live-region.d.ts.map +1 -0
- package/dist/components/ui/live-region.js +48 -0
- package/dist/components/ui/mark.d.ts +44 -0
- package/dist/components/ui/mark.d.ts.map +1 -0
- package/dist/components/ui/mark.js +79 -0
- package/dist/components/ui/pagination.d.ts +24 -6
- package/dist/components/ui/pagination.d.ts.map +1 -1
- package/dist/components/ui/pagination.js +23 -9
- package/dist/components/ui/product-switcher.d.ts +7 -0
- package/dist/components/ui/product-switcher.d.ts.map +1 -1
- package/dist/components/ui/product-switcher.js +2 -2
- package/dist/components/ui/slider.d.ts +1 -1
- package/dist/components/ui/slider.d.ts.map +1 -1
- package/dist/components/ui/tree.d.ts +115 -0
- package/dist/components/ui/tree.d.ts.map +1 -0
- package/dist/components/ui/tree.js +137 -0
- package/dist/pages/docs-shell/docs-shell.d.ts +250 -0
- package/dist/pages/docs-shell/docs-shell.d.ts.map +1 -0
- package/dist/pages/docs-shell/docs-shell.js +197 -0
- package/dist/pages/docs-shell/index.d.ts +3 -0
- package/dist/pages/docs-shell/index.d.ts.map +1 -0
- package/dist/pages/docs-shell/index.js +1 -0
- package/dist/pages/index.d.ts +9 -2
- package/dist/pages/index.d.ts.map +1 -1
- package/dist/pages/index.js +8 -2
- package/dist/styles.css +93 -0
- package/gates/README.md +98 -0
- package/gates/cli.mjs +133 -0
- package/gates/hidden-state.mjs +243 -0
- package/gates/index.mjs +81 -0
- package/gates/laws.mjs +170 -0
- package/gates/links.mjs +187 -0
- package/gates/pack-boundary.mjs +421 -0
- package/gates/pin.mjs +130 -0
- package/gates/retired-line.mjs +314 -0
- package/gates/run.mjs +320 -0
- package/gates/runtime-token-read.mjs +129 -0
- package/gates/stylesheet-ownership.mjs +207 -0
- package/package.json +14 -2
|
@@ -36,10 +36,10 @@ import { cn } from '../../lib/utils';
|
|
|
36
36
|
* wants a menu rather than a row of marks composes `DropdownMenu` with the marks
|
|
37
37
|
* and does not use this.
|
|
38
38
|
*/
|
|
39
|
-
function ProductSwitcher({ products, currentId, size = 'sm', label
|
|
39
|
+
function ProductSwitcher({ products, currentId, size = 'sm', label, className, ...props }) {
|
|
40
40
|
if (products.length === 0)
|
|
41
41
|
return null;
|
|
42
|
-
return (_jsx("nav", { "data-slot": "product-switcher",
|
|
42
|
+
return (_jsx("nav", { "data-slot": "product-switcher", ...(label === undefined ? null : { 'aria-label': label }), className: cn('flex flex-wrap items-center gap-x-4 gap-y-2', className), ...props, children: products.map((product) => {
|
|
43
43
|
const current = product.id === currentId;
|
|
44
44
|
return (_jsx("a", { href: product.href, "aria-current": current ? 'page' : undefined, "data-current": current ? 'true' : undefined, className: "rounded-sm transition-opacity duration-fast ease-out hover:opacity-80", children: _jsx(ProductMark, { id: product.id, name: product.name, pack: product.pack, size: size }) }, product.id));
|
|
45
45
|
}) }));
|
|
@@ -5,7 +5,7 @@ import type { ComponentProps } from 'react';
|
|
|
5
5
|
* Declared here rather than re-exported from Base UI so no upstream type
|
|
6
6
|
* crosses the package seam (ticket 07 section 6).
|
|
7
7
|
*/
|
|
8
|
-
export interface SliderProps extends Omit<ComponentProps<'div'>, 'onChange'
|
|
8
|
+
export interface SliderProps extends Omit<ComponentProps<'div'>, 'onChange'> {
|
|
9
9
|
/** The current value, when the slider is controlled. */
|
|
10
10
|
value?: number;
|
|
11
11
|
/** The value the slider starts at, for an uncontrolled slider. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../../src/components/ui/slider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAI3C;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../../src/components/ui/slider.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAI3C;;;;;GAKG;AACH,MAAM,WAAW,WAAY,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC;IAC1E,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,iDAAiD;IACjD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,2DAA2D;IAC3D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,gEAAgE;IAChE,WAAW,CAAC,EAAE,YAAY,GAAG,UAAU,CAAA;IACvC,mDAAmD;IACnD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,sDAAsD;IACtD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kEAAkE;IAClE,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,mCAAmC;IACnC,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACxC;AAED;;;;;;;;GAQG;AACH,iBAAS,MAAM,CAAC,EACd,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,GAAG,KAAK,EACT,EAAE,WAAW,+BAiCb;AAED,OAAO,EAAE,MAAM,EAAE,CAAA"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* A node a reader can arrive at: a title and the address it is read at.
|
|
4
|
+
*
|
|
5
|
+
* `href` is required. A node in a tree that goes nowhere is an entry a reader can
|
|
6
|
+
* focus and not follow, and this Component renders every node with a destination
|
|
7
|
+
* as a native anchor so a reader can see where it goes before taking it.
|
|
8
|
+
*/
|
|
9
|
+
export type TreeNodePage = {
|
|
10
|
+
type: 'page';
|
|
11
|
+
/** The words the reader meets. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** The address the node is read at. */
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A label over a list of nodes, at any depth.
|
|
18
|
+
*
|
|
19
|
+
* `href` is the group's own index and it is optional on purpose. A group with no
|
|
20
|
+
* index is a place in the tree and not a route, so this Component renders it as a
|
|
21
|
+
* label: no anchor, no `href`, nothing focusable. Inventing a route for it would
|
|
22
|
+
* publish an address that resolves to nothing.
|
|
23
|
+
*
|
|
24
|
+
* `items` is required, because a group that renders a label and holds nothing is
|
|
25
|
+
* an empty entry rather than a group. Pass a node with no children rather than a
|
|
26
|
+
* group with none.
|
|
27
|
+
*/
|
|
28
|
+
export type TreeNodeGroup = {
|
|
29
|
+
type: 'group';
|
|
30
|
+
/** The words on the label. A status inside them stays inside them. */
|
|
31
|
+
title: string;
|
|
32
|
+
/** The group's own index, where it has one. Omit it for a label over a list. */
|
|
33
|
+
href?: string;
|
|
34
|
+
/** The nodes under this group, in the order a reader should meet them. */
|
|
35
|
+
items: readonly TreeNode[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* A rule between nodes, carrying a name that is usually empty.
|
|
39
|
+
*
|
|
40
|
+
* It is a label and never a link. The alternative spelling, a page node with an
|
|
41
|
+
* empty `href`, is a control that cannot be operated, so a rule is its own type.
|
|
42
|
+
*/
|
|
43
|
+
export type TreeNodeDivider = {
|
|
44
|
+
type: 'divider';
|
|
45
|
+
/** The words on the rule, which may be the empty string. */
|
|
46
|
+
title: string;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* One node in a tree, of any of the three kinds.
|
|
50
|
+
*
|
|
51
|
+
* The union is closed, and it is a union rather than one shape with optional
|
|
52
|
+
* fields because a reader meets three different things in a tree: a destination, a
|
|
53
|
+
* label over a list, and a rule. A single shape would make all three look alike,
|
|
54
|
+
* and "a place that is a heading, not a link" is the distinction the whole
|
|
55
|
+
* arrangement turns on.
|
|
56
|
+
*/
|
|
57
|
+
export type TreeNode = TreeNodePage | TreeNodeGroup | TreeNodeDivider;
|
|
58
|
+
/** The props the Tree accepts. */
|
|
59
|
+
export interface TreeProps {
|
|
60
|
+
/** The nodes, in the order a reader should meet them. */
|
|
61
|
+
nodes: readonly TreeNode[];
|
|
62
|
+
/**
|
|
63
|
+
* The address the reader is currently at, which is what marks the current node.
|
|
64
|
+
*
|
|
65
|
+
* The marking is the attribute and not a class, so it survives a theme change and
|
|
66
|
+
* does not depend on a colour a reader may not distinguish.
|
|
67
|
+
*/
|
|
68
|
+
currentHref?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The accessible name of the tree, read before its nodes.
|
|
71
|
+
*
|
|
72
|
+
* Required rather than defaulted, because a tree with no name is announced as
|
|
73
|
+
* "tree" and a page with two of them is a page where a reader cannot tell which
|
|
74
|
+
* is which. The name is the caller's word.
|
|
75
|
+
*/
|
|
76
|
+
label: string;
|
|
77
|
+
/** Layout only. */
|
|
78
|
+
className?: string;
|
|
79
|
+
/**
|
|
80
|
+
* The words a reader is told when the tree is empty, and optionally what to do
|
|
81
|
+
* about it.
|
|
82
|
+
*
|
|
83
|
+
* A tree that renders nothing is a control with nothing in it, so the empty case
|
|
84
|
+
* is authored rather than left to a caller to notice.
|
|
85
|
+
*/
|
|
86
|
+
empty?: {
|
|
87
|
+
message: string;
|
|
88
|
+
action?: ReactNode;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A tree of nodes, given as data.
|
|
93
|
+
*
|
|
94
|
+
* This is the third of the three primitives the expansion found missing, and the
|
|
95
|
+
* one with a different kind of work behind it: the implementation already existed
|
|
96
|
+
* as two private renderers inside the documentation Page, with its depth rule, its
|
|
97
|
+
* `aria-current` marking and its rule that a group with no index renders a label.
|
|
98
|
+
* What was missing was that it was unreachable, and that its data type was bound
|
|
99
|
+
* to documentation navigation rather than being a tree's own vocabulary. So this is
|
|
100
|
+
* a promotion rather than a second implementation, and the reasoning in the
|
|
101
|
+
* documentation Page is carried across rather than rewritten.
|
|
102
|
+
*
|
|
103
|
+
* **A flat list renders a flat tree.** An outline is a tree of depth one, so a
|
|
104
|
+
* caller passes leaves and gets leaves. A Component that required nesting to
|
|
105
|
+
* express a flat structure would make the common case the awkward one.
|
|
106
|
+
*
|
|
107
|
+
* **The Page keeps its own renderers and does not change.** Its two rules, that a
|
|
108
|
+
* section carries no status or count and that a group with no index is a label,
|
|
109
|
+
* are specific to a documentation rail and are reasoned at length in the design
|
|
110
|
+
* rules. A documentation rail is one shape a tree takes, not the shape. Whether the
|
|
111
|
+
* Page composes this Component later is a decision this ticket does not make.
|
|
112
|
+
*/
|
|
113
|
+
declare function Tree({ nodes, currentHref, label, className, empty }: TreeProps): import("react").JSX.Element;
|
|
114
|
+
export { Tree };
|
|
115
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/components/ui/tree.tsx"],"names":[],"mappings":"AAEA,OAAO,EAA8B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAIlE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,kCAAkC;IAClC,KAAK,EAA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} from '../../lib/utils';
|
|
5
|
+
/** Whether a group's subtree contains the current address, at any depth. */
|
|
6
|
+
function containsHref(nodes, currentHref) {
|
|
7
|
+
if (currentHref === undefined)
|
|
8
|
+
return false;
|
|
9
|
+
for (const node of nodes) {
|
|
10
|
+
if (node.type === 'page' && node.href === currentHref)
|
|
11
|
+
return true;
|
|
12
|
+
if (node.type === 'group') {
|
|
13
|
+
if (node.href === currentHref)
|
|
14
|
+
return true;
|
|
15
|
+
if (containsHref(node.items, currentHref))
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
/** Whether an address is the current one or lies under it, for a heading's emphasis. */
|
|
22
|
+
function under(href, currentHref) {
|
|
23
|
+
if (currentHref === undefined)
|
|
24
|
+
return false;
|
|
25
|
+
return currentHref === href || currentHref.startsWith(`${href}/`);
|
|
26
|
+
}
|
|
27
|
+
function TreeLevel({ nodes, currentHref, depth, }) {
|
|
28
|
+
return (_jsx("ul", { "data-slot": "tree-list", "data-depth": depth,
|
|
29
|
+
// `group` on the list, not `treeitem`: the items are the things a reader
|
|
30
|
+
// navigates between, and a `ul` of them is a group. `role="none"` on each
|
|
31
|
+
// item below removes the listitem role so that only the anchors and labels
|
|
32
|
+
// are the navigable things, which is what lets a caller's own keyboard model
|
|
33
|
+
// move between them without a roving tabindex fighting the document's.
|
|
34
|
+
role: "group", className: cn('border-border flex flex-col gap-1 border-l',
|
|
35
|
+
// One level of indent per nested group and none at the top, so the depth
|
|
36
|
+
// reads from the rule rather than from the words.
|
|
37
|
+
depth > 0 && 'ps-3'), children: nodes.map((node, index) => (_jsx(TreeItem, { node: node, currentHref: currentHref, depth: depth }, `${node.type}:${index}`))) }));
|
|
38
|
+
}
|
|
39
|
+
function TreeItem({ node, currentHref, depth, }) {
|
|
40
|
+
if (node.type === 'divider') {
|
|
41
|
+
// A rule between nodes. It is a label, so it is not focusable and a reader
|
|
42
|
+
// does not meet it as a destination, and the empty title renders no words
|
|
43
|
+
// above the hairline rather than a word a reader has to interpret.
|
|
44
|
+
return (_jsx("li", { "data-slot": "tree-divider", role: "none", className: "border-border mt-2 border-t pt-2 first:mt-0 first:border-t-0 first:pt-0", children: node.title ? (_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: node.title })) : null }));
|
|
45
|
+
}
|
|
46
|
+
if (node.type === 'group') {
|
|
47
|
+
return (_jsx("li", { "data-slot": "tree-group", role: "none", children: _jsxs("div", { className: "flex flex-col gap-1", children: [node.href === undefined ? (
|
|
48
|
+
/*
|
|
49
|
+
* A group with no index is a tree item that is not a destination, so it
|
|
50
|
+
* carries `role="treeitem"` and its level and nothing else. It is not a
|
|
51
|
+
* bare span: `aria-level` on an element with no role is prohibited
|
|
52
|
+
* rather than ignored, which the accessibility gate caught the first
|
|
53
|
+
* time this was rendered, and a reader needs the level to place a label
|
|
54
|
+
* that has no anchor to place it by.
|
|
55
|
+
*/
|
|
56
|
+
_jsx("span", { "data-slot": "tree-label", role: "treeitem", "aria-level": depth + 1, "aria-expanded": node.items.length > 0 ? true : undefined, className: cn('rounded-sm text-sm font-semibold tracking-tight', containsHref(node.items, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: node.title })) : (_jsx("a", { "data-slot": "tree-heading", href: node.href, role: "treeitem", "aria-level": depth + 1, "aria-expanded": node.items.length > 0 ? true : undefined, "aria-current": currentHref === node.href ? 'page' : undefined, className: cn('hover:text-foreground rounded-sm text-sm font-semibold tracking-tight transition-colors duration-fast ease-out', under(node.href, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: node.title })), node.items.length > 0 ? (_jsx(TreeLevel, { nodes: node.items, currentHref: currentHref, depth: depth + 1 })) : null] }) }));
|
|
57
|
+
}
|
|
58
|
+
return (_jsx("li", { "data-slot": "tree-item", role: "none", children: _jsx("a", { "data-slot": "tree-link", href: node.href,
|
|
59
|
+
// A destination in a tree is a `treeitem`, not a link with a level hung
|
|
60
|
+
// off it: the level belongs to the item, and a reader placing it in the
|
|
61
|
+
// tree is reading the item rather than the anchor inside it.
|
|
62
|
+
role: "treeitem", "aria-level": depth + 1, "aria-current": currentHref === node.href ? 'page' : undefined, className: cn('-ms-px block border-l-2 py-1 ps-3 text-sm transition-colors duration-fast ease-out', currentHref === node.href
|
|
63
|
+
? 'text-foreground border-primary font-medium'
|
|
64
|
+
: 'text-muted-foreground hover:text-foreground border-transparent'), children: node.title }) }));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A tree of nodes, given as data.
|
|
68
|
+
*
|
|
69
|
+
* This is the third of the three primitives the expansion found missing, and the
|
|
70
|
+
* one with a different kind of work behind it: the implementation already existed
|
|
71
|
+
* as two private renderers inside the documentation Page, with its depth rule, its
|
|
72
|
+
* `aria-current` marking and its rule that a group with no index renders a label.
|
|
73
|
+
* What was missing was that it was unreachable, and that its data type was bound
|
|
74
|
+
* to documentation navigation rather than being a tree's own vocabulary. So this is
|
|
75
|
+
* a promotion rather than a second implementation, and the reasoning in the
|
|
76
|
+
* documentation Page is carried across rather than rewritten.
|
|
77
|
+
*
|
|
78
|
+
* **A flat list renders a flat tree.** An outline is a tree of depth one, so a
|
|
79
|
+
* caller passes leaves and gets leaves. A Component that required nesting to
|
|
80
|
+
* express a flat structure would make the common case the awkward one.
|
|
81
|
+
*
|
|
82
|
+
* **The Page keeps its own renderers and does not change.** Its two rules, that a
|
|
83
|
+
* section carries no status or count and that a group with no index is a label,
|
|
84
|
+
* are specific to a documentation rail and are reasoned at length in the design
|
|
85
|
+
* rules. A documentation rail is one shape a tree takes, not the shape. Whether the
|
|
86
|
+
* Page composes this Component later is a decision this ticket does not make.
|
|
87
|
+
*/
|
|
88
|
+
function Tree({ nodes, currentHref, label, className, empty }) {
|
|
89
|
+
const root = useRef(null);
|
|
90
|
+
/**
|
|
91
|
+
* The keyboard model, and the reason it lives here rather than in a caller's.
|
|
92
|
+
*
|
|
93
|
+
* A tree is one Tab stop, and the arrow keys move inside it. That is the ARIA
|
|
94
|
+
* pattern, and a consumer who composes the markup themselves gets the Tab order
|
|
95
|
+
* of the document instead, which is every node in the tree and none of the
|
|
96
|
+
* arrows. A roving tabindex is the mechanism: one node is tabbable at a time and
|
|
97
|
+
* the arrows move which one.
|
|
98
|
+
*
|
|
99
|
+
* The flat order is collected from the DOM rather than computed from the node
|
|
100
|
+
* data, because the DOM is what a reader actually moves through and computing a
|
|
101
|
+
* second order from the data is a second list to fall behind the first. Only
|
|
102
|
+
* focusable nodes take part, so a label that is not a destination is skipped
|
|
103
|
+
* rather than focused and doing nothing.
|
|
104
|
+
*/
|
|
105
|
+
const onKeyDown = (event) => {
|
|
106
|
+
const keys = ['ArrowDown', 'ArrowUp', 'Home', 'End'];
|
|
107
|
+
if (!keys.includes(event.key))
|
|
108
|
+
return;
|
|
109
|
+
const root_ = root.current;
|
|
110
|
+
if (root_ === null)
|
|
111
|
+
return;
|
|
112
|
+
const items = [
|
|
113
|
+
...root_.querySelectorAll('[data-slot="tree-link"], [data-slot="tree-heading"]'),
|
|
114
|
+
];
|
|
115
|
+
if (items.length === 0)
|
|
116
|
+
return;
|
|
117
|
+
const at = items.indexOf(document.activeElement);
|
|
118
|
+
if (at === -1)
|
|
119
|
+
return;
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
const next = event.key === 'ArrowDown'
|
|
122
|
+
? Math.min(at + 1, items.length - 1)
|
|
123
|
+
: event.key === 'ArrowUp'
|
|
124
|
+
? Math.max(at - 1, 0)
|
|
125
|
+
: event.key === 'Home'
|
|
126
|
+
? 0
|
|
127
|
+
: items.length - 1;
|
|
128
|
+
items[next]?.focus();
|
|
129
|
+
};
|
|
130
|
+
if (nodes.length === 0) {
|
|
131
|
+
// A tree that renders nothing is a control with nothing in it, so the empty
|
|
132
|
+
// case is authored rather than left for a caller to notice.
|
|
133
|
+
return (_jsxs("div", { "data-slot": "tree-empty", className: cn('text-muted-foreground text-sm', className), children: [empty?.message ?? null, empty?.action] }));
|
|
134
|
+
}
|
|
135
|
+
return (_jsx("div", { "data-slot": "tree", ref: root, role: "tree", "aria-label": label, onKeyDown: onKeyDown, className: cn('flex flex-col', className), children: _jsx(TreeLevel, { nodes: nodes, currentHref: currentHref, depth: 0 }) }));
|
|
136
|
+
}
|
|
137
|
+
export { Tree };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* One page in a documentation tree: a title and the address it is read at.
|
|
4
|
+
*
|
|
5
|
+
* `href` is required. A page in the navigation that goes nowhere is an entry a
|
|
6
|
+
* reader can focus and not follow, and the Page renders every page entry as a
|
|
7
|
+
* native anchor so a reader can see where a destination is before taking it.
|
|
8
|
+
*/
|
|
9
|
+
export type DocsNavPage = {
|
|
10
|
+
type: 'page';
|
|
11
|
+
/** The words the reader meets. */
|
|
12
|
+
title: string;
|
|
13
|
+
/** The address the page is read at. */
|
|
14
|
+
href: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* One group in a documentation tree: a label and the pages under it, at any
|
|
18
|
+
* depth.
|
|
19
|
+
*
|
|
20
|
+
* `href` is the group's own index page, and it is optional on purpose. A group
|
|
21
|
+
* with no index is a place in the tree and not a route, so the Page renders it
|
|
22
|
+
* as a label: no anchor, no `href`, nothing focusable. Inventing a route for it
|
|
23
|
+
* would publish an address that resolves to nothing, and rendering an anchor
|
|
24
|
+
* with no `href` would publish a destination a reader can reach and cannot
|
|
25
|
+
* follow. AlphaLens already uses the absent case to mean exactly this, in every
|
|
26
|
+
* section whose folder holds no `index.mdx`, and Atlas and Nexus style those
|
|
27
|
+
* entries out of their own stylesheets with a rule that has now become dead.
|
|
28
|
+
*
|
|
29
|
+
* `items` is required, because a group that renders a label and holds nothing
|
|
30
|
+
* is an empty rail entry rather than a group. Pass a page with no children
|
|
31
|
+
* rather than a group with none.
|
|
32
|
+
*/
|
|
33
|
+
export type DocsNavGroup = {
|
|
34
|
+
type: 'group';
|
|
35
|
+
/** The words on the label. A status inside them stays inside them. */
|
|
36
|
+
title: string;
|
|
37
|
+
/**
|
|
38
|
+
* The group's own index page, where it has one. Omit it for a group that is
|
|
39
|
+
* only a heading over its pages.
|
|
40
|
+
*/
|
|
41
|
+
href?: string;
|
|
42
|
+
/** The pages under this group, in the order a reader should meet them. */
|
|
43
|
+
items: readonly DocsNavEntry[];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A rule between entries, carrying a name that is usually empty.
|
|
47
|
+
*
|
|
48
|
+
* It is a label and never a link. The alternative spelling, a page entry with an
|
|
49
|
+
* empty `href`, was what two of the three consumer sites shipped and had to
|
|
50
|
+
* restyle in their own stylesheets, because an anchor with no destination is a
|
|
51
|
+
* control that cannot be operated.
|
|
52
|
+
*/
|
|
53
|
+
export type DocsNavDivider = {
|
|
54
|
+
type: 'divider';
|
|
55
|
+
/** The words on the rule, which may be the empty string. */
|
|
56
|
+
title: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* One entry in a documentation tree, of any of the three kinds.
|
|
60
|
+
*
|
|
61
|
+
* The union is closed, and it is a union rather than one shape with optional
|
|
62
|
+
* fields because a reader meets three different things in a rail: a destination,
|
|
63
|
+
* a label over a list, and a rule. A single shape would make all three look
|
|
64
|
+
* alike, and "a place that is a heading, not a link" is the distinction the whole
|
|
65
|
+
* arrangement turns on.
|
|
66
|
+
*/
|
|
67
|
+
export type DocsNavEntry = DocsNavPage | DocsNavGroup | DocsNavDivider;
|
|
68
|
+
/**
|
|
69
|
+
* The two words the pager renders above the neighbouring pages' titles.
|
|
70
|
+
*
|
|
71
|
+
* Both are required, and both are the caller's: "Previous" and "Next" are this
|
|
72
|
+
* Page's own phrasing, a site that files its pages in the other direction says
|
|
73
|
+
* the opposite pair, and a Page that ships no copy ships no reader-facing copy
|
|
74
|
+
* either.
|
|
75
|
+
*/
|
|
76
|
+
export type DocsPagerLabels = {
|
|
77
|
+
/** The word above the previous page's title. */
|
|
78
|
+
previous: string;
|
|
79
|
+
/** The word above the next page's title. */
|
|
80
|
+
next: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The props a DocsShell takes.
|
|
84
|
+
*
|
|
85
|
+
* The navigation is data and the frame is the consumer's. Three sites publish
|
|
86
|
+
* full documentation sets and each of them has a different shape: Nexus files
|
|
87
|
+
* six sections of five pages, Atlas files four of which one holds nine pages
|
|
88
|
+
* under a single heading, and AlphaLens files six sections separated by rules
|
|
89
|
+
* and named for subject matter rather than for a documentation genre. The shape
|
|
90
|
+
* arrives in `nav` and the Page renders it, so none of the three had to be told
|
|
91
|
+
* which of the others it looks like.
|
|
92
|
+
*
|
|
93
|
+
* The document's own body is `children`, because a document is authored wherever
|
|
94
|
+
* it is authored, a Markdown pipeline or a CMS, and Prism owns the measure and
|
|
95
|
+
* the rhythm around the words rather than the words.
|
|
96
|
+
*/
|
|
97
|
+
export type DocsShellProps = {
|
|
98
|
+
/**
|
|
99
|
+
* The page's title, and the document's `h1`.
|
|
100
|
+
*
|
|
101
|
+
* It is optional because the three consumer sites do not agree about whether a
|
|
102
|
+
* documentation page has one: two render the frontmatter title as the page
|
|
103
|
+
* heading, and one lets the document's own Markdown own it. When it is absent
|
|
104
|
+
* the Page renders no heading at all rather than an empty one, so the document
|
|
105
|
+
* keeps exactly the outline its own content declares.
|
|
106
|
+
*/
|
|
107
|
+
title?: string;
|
|
108
|
+
/**
|
|
109
|
+
* One or two sentences under the title: what this part of the documentation
|
|
110
|
+
* covers. A `ReactNode` because a site that files a page for a pipeline states
|
|
111
|
+
* the pipeline's stage as markup rather than as a sentence.
|
|
112
|
+
*/
|
|
113
|
+
description?: ReactNode;
|
|
114
|
+
/**
|
|
115
|
+
* The documentation tree, in the order a reader should meet it. The whole
|
|
116
|
+
* shape arrives here, so the Page holds no opinion about how many sections a
|
|
117
|
+
* site has, how deep they nest, or what a section is called.
|
|
118
|
+
*/
|
|
119
|
+
nav?: readonly DocsNavEntry[];
|
|
120
|
+
/**
|
|
121
|
+
* The headings inside this page, in document order, for the contents rail.
|
|
122
|
+
*
|
|
123
|
+
* It is the consumer's document that knows its own outline, because Prism does
|
|
124
|
+
* not parse Markdown and a Page that guessed at it would guess wrong on every
|
|
125
|
+
* document rather than on some. Pass the whole outline or none: a partial one
|
|
126
|
+
* is a contents list that lies about the page.
|
|
127
|
+
*/
|
|
128
|
+
toc?: readonly DocsNavEntry[];
|
|
129
|
+
/**
|
|
130
|
+
* The address of the page being rendered. The rail marks it with
|
|
131
|
+
* `aria-current="page"` and the pager derives its two neighbours from it, so
|
|
132
|
+
* the same navigation renders a different pager for every page without the
|
|
133
|
+
* caller deriving anything.
|
|
134
|
+
*/
|
|
135
|
+
currentHref?: string;
|
|
136
|
+
/**
|
|
137
|
+
* The accessible name of the rail. Required whenever `nav` is passed, because
|
|
138
|
+
* it is a word a reader hears and a Page that ships no copy ships no
|
|
139
|
+
* reader-facing copy either.
|
|
140
|
+
*/
|
|
141
|
+
navLabel: string;
|
|
142
|
+
/**
|
|
143
|
+
* The accessible name of the contents rail. Required whenever `toc` is passed,
|
|
144
|
+
* for the same reason `navLabel` is.
|
|
145
|
+
*/
|
|
146
|
+
tocLabel: string;
|
|
147
|
+
/**
|
|
148
|
+
* The accessible name of the pager. Required whenever there is a neighbour to
|
|
149
|
+
* reach, for the same reason `navLabel` is.
|
|
150
|
+
*/
|
|
151
|
+
pagerLabel: string;
|
|
152
|
+
/**
|
|
153
|
+
* The two words the pager renders above the neighbouring pages' titles.
|
|
154
|
+
* Required whenever either neighbour exists, for the same reason `navLabel`
|
|
155
|
+
* is.
|
|
156
|
+
*/
|
|
157
|
+
pagerLabels: DocsPagerLabels;
|
|
158
|
+
/**
|
|
159
|
+
* The document's own body. Any flow content: paragraphs, headings, lists,
|
|
160
|
+
* code, images, tables. `Prose` holds it to the reading measure and to the
|
|
161
|
+
* block rhythm, and it is passed `fullWidth` so the document fills the column
|
|
162
|
+
* the frame gives it rather than sitting in a second measure inside one.
|
|
163
|
+
*/
|
|
164
|
+
children: ReactNode;
|
|
165
|
+
/**
|
|
166
|
+
* A slot above the frame, inside the container: a breadcrumb trail, a version
|
|
167
|
+
* picker, a search field. A slot rather than a prop because each of those is a
|
|
168
|
+
* Block, and a Page that took one per prop would be a Page whose interface
|
|
169
|
+
* lists the whole catalogue.
|
|
170
|
+
*/
|
|
171
|
+
header?: ReactNode;
|
|
172
|
+
/**
|
|
173
|
+
* A slot below the frame, inside the container: a feedback prompt, a link back
|
|
174
|
+
* to the section index, a support address.
|
|
175
|
+
*/
|
|
176
|
+
footer?: ReactNode;
|
|
177
|
+
/**
|
|
178
|
+
* Layout only, exactly as on every Component. Changing a Prism-owned visual
|
|
179
|
+
* property from here is prohibited.
|
|
180
|
+
*/
|
|
181
|
+
className?: string;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* A documentation screen: a navigation rail, the document, a contents rail and
|
|
185
|
+
* the pager to the neighbouring pages.
|
|
186
|
+
*
|
|
187
|
+
* **This is the Page the other three NaniSoft sites import, and the name is
|
|
188
|
+
* theirs.** All three already read `import { DocsShell, type DocsNavEntry }
|
|
189
|
+
* from '@nanisoft/prism-ui/pages'` in their own document template, and all three
|
|
190
|
+
* map their page tree into that shape in their own `lib/to-prism-tree`. A
|
|
191
|
+
* published name cannot be cheaply changed and there is no redirect lane for item
|
|
192
|
+
* routes, so the name follows the three import lines rather than this file's
|
|
193
|
+
* shape. It was `docs-shell` in the retired line, where it was an empty
|
|
194
|
+
* `div` plus a class name that each site then had to style from scratch, and it
|
|
195
|
+
* is `docs-shell` here because that is what the three call sites already say.
|
|
196
|
+
*
|
|
197
|
+
* **A section is a label, not a control.** It carries no status, no badge, no
|
|
198
|
+
* count, no collapse and no sort, and that is the whole of its interface. The
|
|
199
|
+
* reason is specific: AlphaLens files its documentation as a pipeline, where
|
|
200
|
+
* "Unified data contract (approved)" is a stage of the work and not a topic a
|
|
201
|
+
* reader may visit in any order, and every structural affordance says the
|
|
202
|
+
* opposite. A status in the title is part of the title and stays there as words:
|
|
203
|
+
* the Page reads no parentheses, matches no vocabulary, and renders no pill
|
|
204
|
+
* beside a heading that has one. A tree is data, and a Page that parsed a
|
|
205
|
+
* consumer's data would be a Page that had opinions about it.
|
|
206
|
+
*
|
|
207
|
+
* **A group with no index is a label rather than a route.** `href` is optional
|
|
208
|
+
* on `DocsNavGroup` for exactly that, and the absence means the label. The three
|
|
209
|
+
* consumer sites all write `url: node.index?.url ?? ''` in their own adapter
|
|
210
|
+
* today, which is the same fact spelled as an empty string, and two of the three
|
|
211
|
+
* then carry a stylesheet rule that styles the resulting anchor-with-no-href
|
|
212
|
+
* back into a label. Naming the case in the type makes those two rules dead
|
|
213
|
+
* rather than load-bearing, and the type is the only place that had to change.
|
|
214
|
+
*
|
|
215
|
+
* **The pager is derived from the navigation rather than passed.** The rail
|
|
216
|
+
* already knows every page and the order a reader meets them in, and deriving the
|
|
217
|
+
* two neighbours from that plus `currentHref` removes one derivation from each
|
|
218
|
+
* of the three sites. It is derived rather than passed for a second reason: a
|
|
219
|
+
* caller who passes neighbours can pass a neighbour that is not in the tree, and
|
|
220
|
+
* this is the one arrangement where a reader would notice.
|
|
221
|
+
*
|
|
222
|
+
* **The consumer supplies two orders and the Page imposes neither.** `nav` is in
|
|
223
|
+
* the order the rail shows, and `toc` is in the order the contents rail shows.
|
|
224
|
+
* Both are read as given: nothing is sorted, deduplicated or alphabetised, and a
|
|
225
|
+
* tree whose sections are named for subject matter reads in the order its
|
|
226
|
+
* author filed it. A Page that sorted its rail would flatten the one thing the
|
|
227
|
+
* three sites disagree about and cannot both be right about.
|
|
228
|
+
*
|
|
229
|
+
* **The rail is bounded in height.** Atlas files nineteen pages and AlphaLens
|
|
230
|
+
* files twenty-seven, so the taller tree is half again as long, and an unbounded
|
|
231
|
+
* rail on a tall tree is a rail that pushes the document below the fold before
|
|
232
|
+
* the reader has read a line of it. The rail and the contents rail are each
|
|
233
|
+
* capped against the viewport and scroll inside it, so a nineteen-page tree and a
|
|
234
|
+
* twenty-seven-page tree are both a full screen and neither is a page-long
|
|
235
|
+
* sidebar.
|
|
236
|
+
*
|
|
237
|
+
* It is a Page rather than a Block because it is a whole screen and it is the
|
|
238
|
+
* screen a content pipeline targets: a route that reads one document and hands
|
|
239
|
+
* it the page tree, the outline and the current address. A Block would be the
|
|
240
|
+
* rail, and the rail's job is not separable from the screen's, because the
|
|
241
|
+
* arrangement of rail, document, contents and pager is what the three sites each
|
|
242
|
+
* wrote separately and are here written once.
|
|
243
|
+
*
|
|
244
|
+
* It is a server Component. It fetches nothing, it holds no state and it imports
|
|
245
|
+
* no router, so a consumer renders it from whichever route their framework names
|
|
246
|
+
* and hands it the document their pipeline produced.
|
|
247
|
+
*/
|
|
248
|
+
export declare function DocsShell({ title, description, nav, toc, currentHref, navLabel, tocLabel, pagerLabel, pagerLabels, header, footer, className, children, }: DocsShellProps): import("react").JSX.Element;
|
|
249
|
+
export default DocsShell;
|
|
250
|
+
//# sourceMappingURL=docs-shell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs-shell.d.ts","sourceRoot":"","sources":["../../../src/pages/docs-shell/docs-shell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAMtC;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,kCAAkC;IAClC,KAAK,EAAE,MAAM,CAAA;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,CAAA;IACb,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,0EAA0E;IAC1E,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;CAC/B,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,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