@nanisoft/prism-ui 0.6.0 → 0.7.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.
@@ -1 +1 @@
1
- {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,aAAa,yCAA0C,CAAA;AACpE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAExD,eAAO,MAAM,oBAAoB,sHAQvB,CAAA;AACV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAErE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,QAAQ,GAAG,YAAY,CAAA;CAChC;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,WAAW,EA0pBzC,CAAA;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,GAAE,SAAS,WAAW,EAAY,GAAG,WAAW,EAAE,CAEnF;AAED,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAE1D,CAAA"}
1
+ {"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,aAAa,yCAA0C,CAAA;AACpE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAA;AAExD,eAAO,MAAM,oBAAoB,sHAQvB,CAAA;AACV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAA;AAErE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,WAAW,CAAA;IACjB,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAA;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,MAAM,EAAE,QAAQ,GAAG,YAAY,CAAA;CAChC;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,WAAW,EAqqBzC,CAAA;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,GAAE,SAAS,WAAW,EAAY,GAAG,WAAW,EAAE,CAEnF;AAED,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAE1D,CAAA"}
package/dist/catalog.js CHANGED
@@ -664,6 +664,16 @@ export const catalog = [
664
664
  exports: ['BlogPostPage'],
665
665
  status: 'stable',
666
666
  },
667
+ {
668
+ name: 'DocsShell',
669
+ slug: 'docs-shell',
670
+ kind: 'page',
671
+ category: null,
672
+ description: 'A documentation screen: a navigation rail whose shape arrives as data, the document at the measure, a contents rail, and a pager derived from the navigation rather than passed.',
673
+ source: 'src/pages/docs-shell/index.tsx',
674
+ exports: ['DocsShell'],
675
+ status: 'stable',
676
+ },
667
677
  ];
668
678
  /** Returns the catalogue ordered for display and keyed for lookup. */
669
679
  export function buildCatalog(items = catalog) {
@@ -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,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,SAAS,CAAA;IACf,4DAA4D;IAC5D,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,YAAY,GAAG,cAAc,CAAA;AAEtE;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB;;;;OAIG;IACH,GAAG,CAAC,EAAE,SAAS,YAAY,EAAE,CAAA;IAC7B;;;;;;;OAOG;IACH,GAAG,CAAC,EAAE,SAAS,YAAY,EAAE,CAAA;IAC7B;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,WAAW,EAAE,eAAe,CAAA;IAC5B;;;;;OAKG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;OAGG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,WAAW,EACX,GAAG,EACH,GAAG,EACH,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,WAAW,EACX,MAAM,EACN,MAAM,EACN,SAAS,EACT,QAAQ,GACT,EAAE,cAAc,+BAmFhB;AA4QD,eAAe,SAAS,CAAA"}
@@ -0,0 +1,197 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Prose } from '../../components/ui/prose';
3
+ import { Heading, Text } from '../../components/ui/typography';
4
+ import { cn } from '../../lib/utils';
5
+ /**
6
+ * A documentation screen: a navigation rail, the document, a contents rail and
7
+ * the pager to the neighbouring pages.
8
+ *
9
+ * **This is the Page the other three NaniSoft sites import, and the name is
10
+ * theirs.** All three already read `import { DocsShell, type DocsNavEntry }
11
+ * from '@nanisoft/prism-ui/pages'` in their own document template, and all three
12
+ * map their page tree into that shape in their own `lib/to-prism-tree`. A
13
+ * published name cannot be cheaply changed and there is no redirect lane for item
14
+ * routes, so the name follows the three import lines rather than this file's
15
+ * shape. It was `docs-shell` in the retired line, where it was an empty
16
+ * `div` plus a class name that each site then had to style from scratch, and it
17
+ * is `docs-shell` here because that is what the three call sites already say.
18
+ *
19
+ * **A section is a label, not a control.** It carries no status, no badge, no
20
+ * count, no collapse and no sort, and that is the whole of its interface. The
21
+ * reason is specific: AlphaLens files its documentation as a pipeline, where
22
+ * "Unified data contract (approved)" is a stage of the work and not a topic a
23
+ * reader may visit in any order, and every structural affordance says the
24
+ * opposite. A status in the title is part of the title and stays there as words:
25
+ * the Page reads no parentheses, matches no vocabulary, and renders no pill
26
+ * beside a heading that has one. A tree is data, and a Page that parsed a
27
+ * consumer's data would be a Page that had opinions about it.
28
+ *
29
+ * **A group with no index is a label rather than a route.** `href` is optional
30
+ * on `DocsNavGroup` for exactly that, and the absence means the label. The three
31
+ * consumer sites all write `url: node.index?.url ?? ''` in their own adapter
32
+ * today, which is the same fact spelled as an empty string, and two of the three
33
+ * then carry a stylesheet rule that styles the resulting anchor-with-no-href
34
+ * back into a label. Naming the case in the type makes those two rules dead
35
+ * rather than load-bearing, and the type is the only place that had to change.
36
+ *
37
+ * **The pager is derived from the navigation rather than passed.** The rail
38
+ * already knows every page and the order a reader meets them in, and deriving the
39
+ * two neighbours from that plus `currentHref` removes one derivation from each
40
+ * of the three sites. It is derived rather than passed for a second reason: a
41
+ * caller who passes neighbours can pass a neighbour that is not in the tree, and
42
+ * this is the one arrangement where a reader would notice.
43
+ *
44
+ * **The consumer supplies two orders and the Page imposes neither.** `nav` is in
45
+ * the order the rail shows, and `toc` is in the order the contents rail shows.
46
+ * Both are read as given: nothing is sorted, deduplicated or alphabetised, and a
47
+ * tree whose sections are named for subject matter reads in the order its
48
+ * author filed it. A Page that sorted its rail would flatten the one thing the
49
+ * three sites disagree about and cannot both be right about.
50
+ *
51
+ * **The rail is bounded in height.** Atlas files nineteen pages and AlphaLens
52
+ * files twenty-seven, so the taller tree is half again as long, and an unbounded
53
+ * rail on a tall tree is a rail that pushes the document below the fold before
54
+ * the reader has read a line of it. The rail and the contents rail are each
55
+ * capped against the viewport and scroll inside it, so a nineteen-page tree and a
56
+ * twenty-seven-page tree are both a full screen and neither is a page-long
57
+ * sidebar.
58
+ *
59
+ * It is a Page rather than a Block because it is a whole screen and it is the
60
+ * screen a content pipeline targets: a route that reads one document and hands
61
+ * it the page tree, the outline and the current address. A Block would be the
62
+ * rail, and the rail's job is not separable from the screen's, because the
63
+ * arrangement of rail, document, contents and pager is what the three sites each
64
+ * wrote separately and are here written once.
65
+ *
66
+ * It is a server Component. It fetches nothing, it holds no state and it imports
67
+ * no router, so a consumer renders it from whichever route their framework names
68
+ * and hands it the document their pipeline produced.
69
+ */
70
+ export function DocsShell({ title, description, nav, toc, currentHref, navLabel, tocLabel, pagerLabel, pagerLabels, header, footer, className, children, }) {
71
+ const rail = nav && nav.length > 0 ? nav : undefined;
72
+ const contents = toc && toc.length > 0 ? toc : undefined;
73
+ const neighbours = currentHref === undefined ? undefined : deriveNeighbours(nav ?? [], currentHref);
74
+ return (_jsxs("div", { "data-slot": "docs-shell", className: cn('mx-auto w-full max-w-6xl px-6 py-10 lg:px-8', className), children: [header, _jsxs("div", { "data-slot": "docs-shell-frame", className: cn('flex flex-col gap-8 lg:flex-row lg:gap-10',
75
+ // One column for the document, and a third for whichever rails are
76
+ // present. The frame is sized by what the consumer passed rather than
77
+ // by a fixed three-column grid, so a tree with no contents rail leaves
78
+ // the document the width the two remaining columns divide between
79
+ // them.
80
+ contents ? 'lg:grid lg:grid-cols-[15rem_minmax(0,1fr)] xl:grid-cols-[15rem_minmax(0,1fr)_13rem]' : 'lg:grid lg:grid-cols-[15rem_minmax(0,1fr)]'), children: [rail ? (_jsx("aside", { "data-slot": "docs-rail", className: "hidden lg:col-start-1 lg:row-start-1 lg:block", children: _jsx("nav", { "aria-label": navLabel, className: "lg:sticky lg:top-20 lg:max-h-[calc(100svh-7rem)] lg:overflow-y-auto lg:pe-4", children: _jsx(NavList, { entries: rail, currentHref: currentHref, depth: 0 }) }) })) : null, _jsxs("article", { "data-slot": "docs-article", className: "flex min-w-0 flex-col gap-8", children: [title ? (_jsxs("header", { className: "flex flex-col gap-3", children: [_jsx(Heading, { as: "h1", size: "3xl", children: title }), description ? (_jsx(Text, { size: "lg", tone: "muted", className: "max-w-measure", children: description })) : null] })) : description ? (_jsx(Text, { size: "lg", tone: "muted", className: "max-w-measure", children: description })) : null, _jsx(Prose, { fullWidth: true, children: children }), neighbours ? (_jsx(Pager, { previous: neighbours.previous, next: neighbours.next, label: pagerLabel, labels: pagerLabels })) : null] }), contents ? (_jsx("aside", { "data-slot": "docs-contents", className: "hidden lg:col-start-3 lg:row-start-1 lg:block", children: _jsx("nav", { "aria-label": tocLabel, className: "lg:sticky lg:top-20 lg:max-h-[calc(100svh-7rem)] lg:overflow-y-auto", children: _jsx(NavList, { entries: contents, currentHref: currentHref, depth: 0 }) }) })) : null] }), footer] }));
81
+ }
82
+ /* ------------------------------------------------------------------ *
83
+ * The rail
84
+ * ------------------------------------------------------------------ */
85
+ /**
86
+ * One level of the tree as a list, at whatever depth it sits.
87
+ *
88
+ * The nesting is a rule rather than a special case: the tree is the shape the
89
+ * navigation has, and one level of that is the whole renderer. A tree one deep
90
+ * and a tree seven deep are the same code with different data, which is what
91
+ * lets one Page carry a site that files nine pages under a heading and a site
92
+ * that files six sections separated by rules.
93
+ */
94
+ function NavList({ entries, currentHref, depth, }) {
95
+ return (_jsx("ul", { "data-slot": "docs-nav-list", "data-depth": depth, className: cn('border-border flex flex-col gap-1 border-l',
96
+ // One level of indent per nested group, and none at the top, so the
97
+ // depth reads from the rule rather than from the words.
98
+ depth > 0 && 'ps-3'), children: entries.map((entry, index) => (_jsx(NavNode, { entry: entry, currentHref: currentHref, depth: depth }, `${entry.type}:${index}`))) }));
99
+ }
100
+ /**
101
+ * One entry, in whichever of the three shapes it arrives.
102
+ *
103
+ * The switch is on `type` rather than on the presence of fields, so an entry
104
+ * that arrives malformed falls to the last arm and renders nothing rather than
105
+ * rendering a destination it has no address for.
106
+ */
107
+ function NavNode({ entry, currentHref, depth, }) {
108
+ if (entry.type === 'divider') {
109
+ // A rule between entries. It is a label, so it is not focusable and a reader
110
+ // does not meet it as a destination, and the empty title renders no words
111
+ // above the hairline rather than a word a reader has to interpret.
112
+ return (_jsx("li", { "data-slot": "docs-nav-divider", className: "border-border mt-2 border-t pt-2 first:mt-0 first:border-t-0 first:pt-0", children: entry.title ? (_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: entry.title })) : null }));
113
+ }
114
+ if (entry.type === 'group') {
115
+ return (_jsx("li", { "data-slot": "docs-nav-group", children: _jsxs("div", { className: "flex flex-col gap-1", children: [entry.href === undefined ? (_jsx("span", { "data-slot": "docs-nav-label", className: cn('rounded-sm text-sm font-semibold tracking-tight', containsHref(entry, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: entry.title })) : (_jsx("a", { "data-slot": "docs-nav-heading", href: entry.href, "aria-current": currentHref === entry.href ? 'page' : undefined, className: cn('hover:text-foreground rounded-sm text-sm font-semibold tracking-tight transition-colors duration-fast ease-out', under(entry.href, currentHref) ? 'text-foreground' : 'text-muted-foreground'), children: entry.title })), entry.items.length > 0 ? (_jsx(NavList, { entries: entry.items, currentHref: currentHref, depth: depth + 1 })) : null] }) }));
116
+ }
117
+ return (_jsx("li", { "data-slot": "docs-nav-page", children: _jsx("a", { "data-slot": "docs-nav-link", href: entry.href, "aria-current": currentHref === entry.href ? 'page' : undefined, className: cn('-ms-px block border-l-2 py-1 ps-3 text-sm transition-colors duration-fast ease-out', currentHref === entry.href
118
+ ? 'text-foreground border-primary font-medium'
119
+ : 'text-muted-foreground hover:text-foreground border-transparent'), children: entry.title }) }));
120
+ }
121
+ /**
122
+ * Every page the tree holds, in the order a reader meets them.
123
+ *
124
+ * A group's own index page comes before the pages under it, because that is the
125
+ * order the tree states and the Page does not reorder it. A group with no index
126
+ * contributes its children and nothing else, which is the second thing that
127
+ * makes an absent `href` a label rather than a route: there is no page there for
128
+ * the pager to reach either. A divider contributes nothing at all.
129
+ */
130
+ function flatten(entries, into = []) {
131
+ for (const entry of entries) {
132
+ if (entry.type === 'page') {
133
+ into.push({ title: entry.title, href: entry.href });
134
+ continue;
135
+ }
136
+ if (entry.type === 'group') {
137
+ if (entry.href !== undefined)
138
+ into.push({ title: entry.title, href: entry.href });
139
+ flatten(entry.items, into);
140
+ }
141
+ }
142
+ return into;
143
+ }
144
+ /**
145
+ * The pages either side of `currentHref`, or nothing when it is not in the tree.
146
+ *
147
+ * It returns `undefined` rather than a pair of blanks when the address is not in
148
+ * the navigation, because a pager with two empty halves is a rule above nothing
149
+ * and a reader cannot tell it from a page that has no neighbours.
150
+ */
151
+ function deriveNeighbours(entries, currentHref) {
152
+ const flat = flatten(entries);
153
+ const at = flat.findIndex((entry) => entry.href === currentHref);
154
+ if (at === -1)
155
+ return undefined;
156
+ return { previous: flat[at - 1], next: flat[at + 1] };
157
+ }
158
+ /**
159
+ * The two pages either side of this one, rendered as native links.
160
+ *
161
+ * Each half renders only when there is a page for it. A "previous" link on the
162
+ * first page is a link to the page the reader has already read, and a "next"
163
+ * link on the last is a promise the site cannot keep.
164
+ */
165
+ function Pager({ previous, next, label, labels, }) {
166
+ if (!previous && !next)
167
+ return null;
168
+ return (_jsxs("nav", { "aria-label": label, "data-slot": "docs-pager", className: "border-border mt-4 flex flex-wrap items-start justify-between gap-4 border-t pt-6", children: [previous ? (_jsxs("a", { href: previous.href, className: "hover:text-foreground flex flex-col rounded-sm transition-colors duration-fast ease-out", children: [_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: labels.previous }), _jsx("span", { className: "text-sm font-semibold", children: previous.title })] })) : (_jsx("span", {})), next ? (_jsxs("a", { href: next.href, className: "hover:text-foreground ms-auto flex flex-col rounded-sm text-right transition-colors duration-fast ease-out", children: [_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: labels.next }), _jsx("span", { className: "text-sm font-semibold", children: next.title })] })) : null] }));
169
+ }
170
+ /* ------------------------------------------------------------------ *
171
+ * The current address
172
+ * ------------------------------------------------------------------ */
173
+ /** Under a route, or at it, and never under a route that merely starts the same. */
174
+ function under(href, currentHref) {
175
+ return (href !== undefined &&
176
+ currentHref !== undefined &&
177
+ (currentHref === href || currentHref.startsWith(`${href}/`)));
178
+ }
179
+ /**
180
+ * Whether the current page is inside this group.
181
+ *
182
+ * A group with a route answers for that route and everything under it. A group
183
+ * without one has no route to answer with, so it asks its children, which is the
184
+ * only way a label can still show a reader that they are inside it.
185
+ */
186
+ function containsHref(group, currentHref) {
187
+ if (under(group.href, currentHref))
188
+ return true;
189
+ return group.items.some((entry) => {
190
+ if (entry.type === 'page')
191
+ return under(entry.href, currentHref);
192
+ if (entry.type === 'group')
193
+ return containsHref(entry, currentHref);
194
+ return false;
195
+ });
196
+ }
197
+ export default DocsShell;
@@ -0,0 +1,3 @@
1
+ export { DocsShell, default } from './docs-shell';
2
+ export type { DocsShellProps, DocsNavEntry, DocsNavPage, DocsNavGroup, DocsNavDivider, DocsPagerLabels, } from './docs-shell';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/docs-shell/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACjD,YAAY,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAA"}
@@ -0,0 +1 @@
1
+ export { DocsShell, default } from './docs-shell';
@@ -3,8 +3,13 @@
3
3
  *
4
4
  * A Page is a shipped, installable screen model composed of Blocks and
5
5
  * Components that receives application-owned navigation, content and data
6
- * (ticket 07). The v1 roster ships four Pages. Each is also importable on its
7
- * own subpath, `@nanisoft/prism-ui/pages/<slug>`.
6
+ * (ticket 07). Each is also importable on its own subpath,
7
+ * `@nanisoft/prism-ui/pages/<slug>`.
8
+ *
9
+ * `DocsShell` and `DocsNavEntry` keep the names the three consumer sites already
10
+ * import, so the name follows those import lines rather than this file's shape.
11
+ * A published name cannot be cheaply changed and there is no redirect lane for
12
+ * item routes.
8
13
  */
9
14
  export { MarketingPage } from './marketing-page';
10
15
  export type { MarketingPageProps } from './marketing-page';
@@ -18,4 +23,6 @@ export { NotFoundPage } from './not-found-page';
18
23
  export type { NotFoundPageProps, NotFoundLink } from './not-found-page';
19
24
  export { BlogPostPage } from './blog-post-page';
20
25
  export type { BlogPostPageProps, BlogPostTag, BlogPostNeighbour, BlogPostTrailLabels } from './blog-post-page';
26
+ export { DocsShell } from './docs-shell';
27
+ export type { DocsShellProps, DocsNavEntry, DocsNavPage, DocsNavGroup, DocsNavDivider, DocsPagerLabels, } from './docs-shell';
21
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pages/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/pages/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAChD,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAC9C,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,YAAY,EAAE,iBAAiB,EAAE,WAAW,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAC9G,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,YAAY,EACV,cAAc,EACd,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,cAAc,EACd,eAAe,GAChB,MAAM,cAAc,CAAA"}
@@ -3,8 +3,13 @@
3
3
  *
4
4
  * A Page is a shipped, installable screen model composed of Blocks and
5
5
  * Components that receives application-owned navigation, content and data
6
- * (ticket 07). The v1 roster ships four Pages. Each is also importable on its
7
- * own subpath, `@nanisoft/prism-ui/pages/<slug>`.
6
+ * (ticket 07). Each is also importable on its own subpath,
7
+ * `@nanisoft/prism-ui/pages/<slug>`.
8
+ *
9
+ * `DocsShell` and `DocsNavEntry` keep the names the three consumer sites already
10
+ * import, so the name follows those import lines rather than this file's shape.
11
+ * A published name cannot be cheaply changed and there is no redirect lane for
12
+ * item routes.
8
13
  */
9
14
  export { MarketingPage } from './marketing-page';
10
15
  export { DashboardPage } from './dashboard-page';
@@ -12,3 +17,4 @@ export { SettingsPage } from './settings-page';
12
17
  export { AuthPage } from './auth-page';
13
18
  export { NotFoundPage } from './not-found-page';
14
19
  export { BlogPostPage } from './blog-post-page';
20
+ export { DocsShell } from './docs-shell';