@nanisoft/prism-ui 0.5.1 → 0.6.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/blocks/cta-01/cta.d.ts +66 -6
- package/dist/blocks/cta-01/cta.d.ts.map +1 -1
- package/dist/blocks/cta-01/cta.js +8 -3
- package/dist/blocks/cta-01/index.d.ts +1 -0
- package/dist/blocks/cta-01/index.d.ts.map +1 -1
- package/dist/blocks/feature-grid-01/feature-grid.d.ts +57 -6
- package/dist/blocks/feature-grid-01/feature-grid.d.ts.map +1 -1
- package/dist/blocks/feature-grid-01/feature-grid.js +12 -2
- package/dist/blocks/feature-grid-01/index.d.ts +1 -0
- package/dist/blocks/feature-grid-01/index.d.ts.map +1 -1
- package/dist/blocks/hero-01/hero.d.ts +30 -1
- package/dist/blocks/hero-01/hero.d.ts.map +1 -1
- package/dist/blocks/hero-01/hero.js +14 -2
- package/dist/blocks/index.d.ts +10 -0
- package/dist/blocks/index.d.ts.map +1 -1
- package/dist/blocks/index.js +9 -0
- package/dist/blocks/instrument-panel-01/index.d.ts +3 -0
- package/dist/blocks/instrument-panel-01/index.d.ts.map +1 -0
- package/dist/blocks/instrument-panel-01/index.js +1 -0
- package/dist/blocks/instrument-panel-01/instrument-panel.d.ts +114 -0
- package/dist/blocks/instrument-panel-01/instrument-panel.d.ts.map +1 -0
- package/dist/blocks/instrument-panel-01/instrument-panel.js +64 -0
- package/dist/blocks/logo-strip-01/index.d.ts +3 -0
- package/dist/blocks/logo-strip-01/index.d.ts.map +1 -0
- package/dist/blocks/logo-strip-01/index.js +1 -0
- package/dist/blocks/logo-strip-01/logo-strip.d.ts +84 -0
- package/dist/blocks/logo-strip-01/logo-strip.d.ts.map +1 -0
- package/dist/blocks/logo-strip-01/logo-strip.js +40 -0
- package/dist/blocks/note-grid-01/index.d.ts +3 -0
- package/dist/blocks/note-grid-01/index.d.ts.map +1 -0
- package/dist/blocks/note-grid-01/index.js +1 -0
- package/dist/blocks/note-grid-01/note-grid.d.ts +79 -0
- package/dist/blocks/note-grid-01/note-grid.d.ts.map +1 -0
- package/dist/blocks/note-grid-01/note-grid.js +37 -0
- package/dist/blocks/pricing-01/pricing.js +1 -1
- package/dist/blocks/process-rail-01/index.d.ts +3 -0
- package/dist/blocks/process-rail-01/index.d.ts.map +1 -0
- package/dist/blocks/process-rail-01/index.js +1 -0
- package/dist/blocks/process-rail-01/process-rail.d.ts +99 -0
- package/dist/blocks/process-rail-01/process-rail.d.ts.map +1 -0
- package/dist/blocks/process-rail-01/process-rail.js +58 -0
- package/dist/blocks/product-grid-01/index.d.ts +3 -0
- package/dist/blocks/product-grid-01/index.d.ts.map +1 -0
- package/dist/blocks/product-grid-01/index.js +1 -0
- package/dist/blocks/product-grid-01/product-grid.d.ts +114 -0
- package/dist/blocks/product-grid-01/product-grid.d.ts.map +1 -0
- package/dist/blocks/product-grid-01/product-grid.js +51 -0
- package/dist/blocks/site-footer/index.d.ts +3 -0
- package/dist/blocks/site-footer/index.d.ts.map +1 -0
- package/dist/blocks/site-footer/index.js +1 -0
- package/dist/blocks/site-footer/site-footer.d.ts +135 -0
- package/dist/blocks/site-footer/site-footer.d.ts.map +1 -0
- package/dist/blocks/site-footer/site-footer.js +41 -0
- package/dist/blocks/site-header/index.d.ts +3 -0
- package/dist/blocks/site-header/index.d.ts.map +1 -0
- package/dist/blocks/site-header/index.js +1 -0
- package/dist/blocks/site-header/site-header.d.ts +142 -0
- package/dist/blocks/site-header/site-header.d.ts.map +1 -0
- package/dist/blocks/site-header/site-header.js +46 -0
- package/dist/blocks/stack-grid-01/index.d.ts +3 -0
- package/dist/blocks/stack-grid-01/index.d.ts.map +1 -0
- package/dist/blocks/stack-grid-01/index.js +1 -0
- package/dist/blocks/stack-grid-01/stack-grid.d.ts +118 -0
- package/dist/blocks/stack-grid-01/stack-grid.d.ts.map +1 -0
- package/dist/blocks/stack-grid-01/stack-grid.js +49 -0
- package/dist/blocks/status-ledger-01/index.d.ts +3 -0
- package/dist/blocks/status-ledger-01/index.d.ts.map +1 -0
- package/dist/blocks/status-ledger-01/index.js +1 -0
- package/dist/blocks/status-ledger-01/status-ledger.d.ts +131 -0
- package/dist/blocks/status-ledger-01/status-ledger.d.ts.map +1 -0
- package/dist/blocks/status-ledger-01/status-ledger.js +80 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/catalog.js +170 -0
- package/dist/components/index.d.ts +11 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +6 -0
- package/dist/components/ui/card.d.ts +25 -0
- package/dist/components/ui/card.d.ts.map +1 -1
- package/dist/components/ui/card.js +25 -0
- package/dist/components/ui/cta-link.d.ts +45 -0
- package/dist/components/ui/cta-link.d.ts.map +1 -0
- package/dist/components/ui/cta-link.js +81 -0
- package/dist/components/ui/diagram.d.ts +154 -0
- package/dist/components/ui/diagram.d.ts.map +1 -0
- package/dist/components/ui/diagram.js +150 -0
- package/dist/components/ui/fact-list.d.ts +90 -0
- package/dist/components/ui/fact-list.d.ts.map +1 -0
- package/dist/components/ui/fact-list.js +38 -0
- package/dist/components/ui/product-mark.d.ts +115 -0
- package/dist/components/ui/product-mark.d.ts.map +1 -0
- package/dist/components/ui/product-mark.js +82 -0
- package/dist/components/ui/product-switcher.d.ts +108 -0
- package/dist/components/ui/product-switcher.d.ts.map +1 -0
- package/dist/components/ui/product-switcher.js +47 -0
- package/dist/components/ui/prose.d.ts +88 -0
- package/dist/components/ui/prose.d.ts.map +1 -0
- package/dist/components/ui/prose.js +53 -0
- package/dist/components/ui/section.d.ts +24 -1
- package/dist/components/ui/section.d.ts.map +1 -1
- package/dist/components/ui/section.js +11 -2
- package/dist/components/ui/slider.d.ts.map +1 -1
- package/dist/components/ui/slider.js +7 -1
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -0
- package/dist/pages/blog-post-page/index.d.ts +174 -0
- package/dist/pages/blog-post-page/index.d.ts.map +1 -0
- package/dist/pages/blog-post-page/index.js +49 -0
- package/dist/pages/index.d.ts +4 -0
- package/dist/pages/index.d.ts.map +1 -1
- package/dist/pages/index.js +2 -0
- package/dist/pages/not-found-page/index.d.ts +112 -0
- package/dist/pages/not-found-page/index.d.ts.map +1 -0
- package/dist/pages/not-found-page/index.js +46 -0
- package/dist/provider/provider.d.ts +5 -0
- package/dist/provider/provider.d.ts.map +1 -1
- package/dist/provider/provider.js +129 -38
- package/dist/provider/theme-script.d.ts +41 -3
- package/dist/provider/theme-script.d.ts.map +1 -1
- package/dist/provider/theme-script.js +68 -17
- package/dist/styles.css +493 -12
- package/dist/theming/index.d.ts +132 -2
- package/dist/theming/index.d.ts.map +1 -1
- package/dist/theming/index.js +127 -1
- package/package.json +14 -4
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* One tag on a post, or one step in the trail to the next one.
|
|
4
|
+
*
|
|
5
|
+
* `href` is optional and a tag without one renders as text. A tag that goes
|
|
6
|
+
* somewhere is a link, a tag that does not is a word, and a post's tags are
|
|
7
|
+
* usually the words.
|
|
8
|
+
*/
|
|
9
|
+
export type BlogPostTag = {
|
|
10
|
+
/** The word on the tag. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Where the tag goes, for a tag that filters an archive. */
|
|
13
|
+
href?: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* One neighbour of this post: the title and where it is.
|
|
17
|
+
*
|
|
18
|
+
* `title` and `href` are both required. A next post with no title is an arrow
|
|
19
|
+
* with a destination and no promise about what is at the other end, which is the
|
|
20
|
+
* one thing a reader deciding whether to click cannot afford.
|
|
21
|
+
*/
|
|
22
|
+
export type BlogPostNeighbour = {
|
|
23
|
+
/** The post's title. */
|
|
24
|
+
title: string;
|
|
25
|
+
/** Where the post is. */
|
|
26
|
+
href: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* The two words the trail renders above the neighbouring posts' titles.
|
|
30
|
+
*
|
|
31
|
+
* Both are required, and both are the caller's: "Previous" and "Next" are this
|
|
32
|
+
* Page's own phrasing, a site that files posts newest-last says the opposite pair,
|
|
33
|
+
* and a Page that ships no copy ships no reader-facing copy either.
|
|
34
|
+
*/
|
|
35
|
+
export type BlogPostTrailLabels = {
|
|
36
|
+
/** The word above the previous post's title. */
|
|
37
|
+
previous: string;
|
|
38
|
+
/** The word above the next post's title. */
|
|
39
|
+
next: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The props a BlogPostPage takes.
|
|
43
|
+
*
|
|
44
|
+
* The post's own text is `children`, because a post's body is authored wherever it
|
|
45
|
+
* is authored - a Markdown file, a CMS, a headless store - and Prism owns the
|
|
46
|
+
* measure and the rhythm around it, not the words. Everything that is a *fact*
|
|
47
|
+
* about the post rather than its text is a prop: the title, the standfirst, the
|
|
48
|
+
* date, the tags and the neighbours.
|
|
49
|
+
*/
|
|
50
|
+
export type BlogPostPageProps = {
|
|
51
|
+
/**
|
|
52
|
+
* The post's title. It is the page's `h1`, so the page has exactly one and it
|
|
53
|
+
* is the post's name.
|
|
54
|
+
*/
|
|
55
|
+
title: string;
|
|
56
|
+
/**
|
|
57
|
+
* The standfirst: one or two sentences under the title that say what the post
|
|
58
|
+
* is about. It is a prop rather than the first paragraph of the body because a
|
|
59
|
+
* reader deciding whether to read needs it before the body starts, and because
|
|
60
|
+
* it is what an index, a feed and a search result show.
|
|
61
|
+
*/
|
|
62
|
+
description?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The publication date, already formatted for display, and the machine value
|
|
65
|
+
* for the `time` element's `dateTime`. Both are props, and the machine one is
|
|
66
|
+
* required: `dateTime` is what a reader's browser, a feed reader and a search
|
|
67
|
+
* engine use to order posts, and a formatted string is none of those.
|
|
68
|
+
*/
|
|
69
|
+
date: string;
|
|
70
|
+
/**
|
|
71
|
+
* The date in a machine-readable form, `YYYY-MM-DD`, carried on the `time`
|
|
72
|
+
* element. Required, and deliberately not derived from `date`: parsing a
|
|
73
|
+
* formatted date back into an ISO one is a guess about a locale, and a guess
|
|
74
|
+
* in a `datetime` attribute is a wrong date in a feed.
|
|
75
|
+
*/
|
|
76
|
+
dateTime: string;
|
|
77
|
+
/** Who wrote the post. A name, or a link to an author page. */
|
|
78
|
+
author?: ReactNode;
|
|
79
|
+
/**
|
|
80
|
+
* The tags on the post, in the order a reader should meet them. Omit them for a
|
|
81
|
+
* post with none: an empty row of badges is a row of nothing.
|
|
82
|
+
*/
|
|
83
|
+
tags?: readonly BlogPostTag[];
|
|
84
|
+
/** How long the post takes to read, in the consumer's own words. */
|
|
85
|
+
readingTime?: string;
|
|
86
|
+
/**
|
|
87
|
+
* The post's body. Any flow content: paragraphs, headings, lists, code, images,
|
|
88
|
+
* tables. `Prose` holds it to the reading measure and to the block rhythm.
|
|
89
|
+
*/
|
|
90
|
+
children: ReactNode;
|
|
91
|
+
/**
|
|
92
|
+
* The post before this one and the post after it, for the trail at the foot of
|
|
93
|
+
* the page. Omit the half there is no neighbour for; a "previous" link with no
|
|
94
|
+
* previous post is a link to nothing.
|
|
95
|
+
*/
|
|
96
|
+
previous?: BlogPostNeighbour;
|
|
97
|
+
next?: BlogPostNeighbour;
|
|
98
|
+
/**
|
|
99
|
+
* The two words the trail renders above the neighbouring posts' titles. Required
|
|
100
|
+
* whenever either neighbour is passed, because they are words a reader reads and
|
|
101
|
+
* a Page that ships no copy ships no reader-facing copy either.
|
|
102
|
+
*/
|
|
103
|
+
trailLabels: BlogPostTrailLabels;
|
|
104
|
+
/**
|
|
105
|
+
* The accessible name of the trail between the neighbouring posts. It is
|
|
106
|
+
* required whenever either neighbour is passed, because it is a word a reader
|
|
107
|
+
* hears and a Page that ships no copy ships no reader-facing copy either. "More
|
|
108
|
+
* posts" is the Page's own phrasing and a site that files posts by release calls
|
|
109
|
+
* the same landmark something else.
|
|
110
|
+
*/
|
|
111
|
+
trailLabel: string;
|
|
112
|
+
/**
|
|
113
|
+
* The way back to the archive the post is filed in, rendered as one call to
|
|
114
|
+
* action under the trail. A prop rather than a hardcoded "back to the index",
|
|
115
|
+
* because the words and the route belong to the site that publishes the post
|
|
116
|
+
* and a Page that held either would be a Page making a claim about a consumer's
|
|
117
|
+
* own site.
|
|
118
|
+
*/
|
|
119
|
+
indexLink?: BlogPostNeighbour;
|
|
120
|
+
/**
|
|
121
|
+
* A slot for what comes after the trail: a related-posts grid, a newsletter
|
|
122
|
+
* form, a call to action. A slot rather than a prop because every one of those
|
|
123
|
+
* is a Block, and a Page that took a Block per prop would be a Page whose
|
|
124
|
+
* interface lists the whole catalogue.
|
|
125
|
+
*/
|
|
126
|
+
footer?: ReactNode;
|
|
127
|
+
/**
|
|
128
|
+
* Layout only, exactly as on every Component. Changing a Prism-owned visual
|
|
129
|
+
* property from here is prohibited.
|
|
130
|
+
*/
|
|
131
|
+
className?: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* A complete blog post screen: the title, the standfirst, the byline, the body at
|
|
135
|
+
* the measure, and the trail to the neighbouring posts.
|
|
136
|
+
*
|
|
137
|
+
* All four NaniSoft sites publish a blog, each with four posts and the same
|
|
138
|
+
* frontmatter: a title, a description, a date and a list of tags. Each one then
|
|
139
|
+
* rendered that frontmatter in its own component, with its own wrapper, its own
|
|
140
|
+
* measure and its own treatment of the date, and each of them wrote the trail to
|
|
141
|
+
* the neighbouring posts separately or not at all.
|
|
142
|
+
*
|
|
143
|
+
* It is a Page rather than a Block because it is a whole screen and it is the
|
|
144
|
+
* screen a content pipeline targets: a route that reads one document and hands
|
|
145
|
+
* its frontmatter to this Page. The Page is what makes the frontmatter a
|
|
146
|
+
* contract, because a field that is not a prop is a field nothing checks.
|
|
147
|
+
*
|
|
148
|
+
* **The date is two props.** `date` is the words a reader sees and `dateTime` is
|
|
149
|
+
* the machine value on the `time` element, and they are kept apart because
|
|
150
|
+
* parsing a formatted date back into an ISO one is a guess about a locale. A
|
|
151
|
+
* wrong date in a `datetime` attribute is a wrong date in a feed reader and in a
|
|
152
|
+
* search result, and neither reader can see the string that was wrong. This is
|
|
153
|
+
* the arrangement every one of the four sites needs and none of them has, because
|
|
154
|
+
* each of them formats its date in one place and has nowhere else to put the ISO
|
|
155
|
+
* value.
|
|
156
|
+
*
|
|
157
|
+
* The body is `children` and it is held by `Prose`, not by a set of per-element
|
|
158
|
+
* props. A post's body is authored somewhere else - a Markdown pipeline, a CMS -
|
|
159
|
+
* and a Page that took `paragraphs` and `headings` as arrays would be a Page that
|
|
160
|
+
* had to be handed a parsed document, which is a second representation of
|
|
161
|
+
* something the consumer's own pipeline already owns.
|
|
162
|
+
*
|
|
163
|
+
* The trail is one `nav` with two links, and it renders only the halves it is
|
|
164
|
+
* given. A previous link on the oldest post is a link to the first post a reader
|
|
165
|
+
* has already read, and a next link on the newest is a promise the site cannot
|
|
166
|
+
* keep.
|
|
167
|
+
*
|
|
168
|
+
* It is a server Component. It fetches nothing, it holds no state and it imports
|
|
169
|
+
* no router, so a consumer renders it from a server route and hands it the
|
|
170
|
+
* document their pipeline produced.
|
|
171
|
+
*/
|
|
172
|
+
export declare function BlogPostPage({ title, description, date, dateTime, author, tags, readingTime, children, previous, next, trailLabels, trailLabel, indexLink, footer, className, }: BlogPostPageProps): import("react").JSX.Element;
|
|
173
|
+
export default BlogPostPage;
|
|
174
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/blog-post-page/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAQtC;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,6DAA6D;IAC7D,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,yBAAyB;IACzB,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,gDAAgD;IAChD,QAAQ,EAAE,MAAM,CAAA;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAA;CACb,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;;OAKG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;OAKG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;OAKG;IACH,QAAQ,EAAE,MAAM,CAAA;IAChB,+DAA+D;IAC/D,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;IAC7B,oEAAoE;IACpE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,QAAQ,EAAE,SAAS,CAAA;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,iBAAiB,CAAA;IAC5B,IAAI,CAAC,EAAE,iBAAiB,CAAA;IACxB;;;;OAIG;IACH,WAAW,EAAE,mBAAmB,CAAA;IAChC;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,WAAW,EACX,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,UAAU,EACV,SAAS,EACT,MAAM,EACN,SAAS,GACV,EAAE,iBAAiB,+BAgFnB;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Badge } from '../../components/ui/badge';
|
|
3
|
+
import { CtaLink } from '../../components/ui/cta-link';
|
|
4
|
+
import { Heading, Text } from '../../components/ui/typography';
|
|
5
|
+
import { Prose } from '../../components/ui/prose';
|
|
6
|
+
import { Section } from '../../components/ui/section';
|
|
7
|
+
/**
|
|
8
|
+
* A complete blog post screen: the title, the standfirst, the byline, the body at
|
|
9
|
+
* the measure, and the trail to the neighbouring posts.
|
|
10
|
+
*
|
|
11
|
+
* All four NaniSoft sites publish a blog, each with four posts and the same
|
|
12
|
+
* frontmatter: a title, a description, a date and a list of tags. Each one then
|
|
13
|
+
* rendered that frontmatter in its own component, with its own wrapper, its own
|
|
14
|
+
* measure and its own treatment of the date, and each of them wrote the trail to
|
|
15
|
+
* the neighbouring posts separately or not at all.
|
|
16
|
+
*
|
|
17
|
+
* It is a Page rather than a Block because it is a whole screen and it is the
|
|
18
|
+
* screen a content pipeline targets: a route that reads one document and hands
|
|
19
|
+
* its frontmatter to this Page. The Page is what makes the frontmatter a
|
|
20
|
+
* contract, because a field that is not a prop is a field nothing checks.
|
|
21
|
+
*
|
|
22
|
+
* **The date is two props.** `date` is the words a reader sees and `dateTime` is
|
|
23
|
+
* the machine value on the `time` element, and they are kept apart because
|
|
24
|
+
* parsing a formatted date back into an ISO one is a guess about a locale. A
|
|
25
|
+
* wrong date in a `datetime` attribute is a wrong date in a feed reader and in a
|
|
26
|
+
* search result, and neither reader can see the string that was wrong. This is
|
|
27
|
+
* the arrangement every one of the four sites needs and none of them has, because
|
|
28
|
+
* each of them formats its date in one place and has nowhere else to put the ISO
|
|
29
|
+
* value.
|
|
30
|
+
*
|
|
31
|
+
* The body is `children` and it is held by `Prose`, not by a set of per-element
|
|
32
|
+
* props. A post's body is authored somewhere else - a Markdown pipeline, a CMS -
|
|
33
|
+
* and a Page that took `paragraphs` and `headings` as arrays would be a Page that
|
|
34
|
+
* had to be handed a parsed document, which is a second representation of
|
|
35
|
+
* something the consumer's own pipeline already owns.
|
|
36
|
+
*
|
|
37
|
+
* The trail is one `nav` with two links, and it renders only the halves it is
|
|
38
|
+
* given. A previous link on the oldest post is a link to the first post a reader
|
|
39
|
+
* has already read, and a next link on the newest is a promise the site cannot
|
|
40
|
+
* keep.
|
|
41
|
+
*
|
|
42
|
+
* It is a server Component. It fetches nothing, it holds no state and it imports
|
|
43
|
+
* no router, so a consumer renders it from a server route and hands it the
|
|
44
|
+
* document their pipeline produced.
|
|
45
|
+
*/
|
|
46
|
+
export function BlogPostPage({ title, description, date, dateTime, author, tags, readingTime, children, previous, next, trailLabels, trailLabel, indexLink, footer, className, }) {
|
|
47
|
+
return (_jsxs(Section, { className: className, children: [_jsxs("article", { "data-slot": "blog-post", className: "flex flex-col gap-8", children: [_jsxs("header", { className: "flex flex-col gap-4", children: [_jsx(Heading, { as: "h1", size: "3xl", children: title }), description ? (_jsx(Text, { size: "lg", className: "text-muted-foreground max-w-measure", children: description })) : null, _jsxs("div", { className: "text-muted-foreground flex flex-wrap items-center gap-x-3 gap-y-2 text-sm", children: [author ? _jsx("span", { className: "text-foreground font-medium", children: author }) : null, _jsx("time", { dateTime: dateTime, children: date }), readingTime ? _jsx("span", { children: readingTime }) : null] }), tags && tags.length > 0 ? (_jsx("ul", { className: "flex flex-wrap items-center gap-2", children: tags.map((tag) => (_jsx("li", { children: tag.href ? (_jsx("a", { href: tag.href, className: "rounded-sm", "aria-label": `Posts tagged ${tag.label}`, children: _jsx(Badge, { variant: "secondary", children: tag.label }) })) : (_jsx(Badge, { variant: "secondary", children: tag.label })) }, tag.label))) })) : null] }), _jsx(Prose, { children: children }), previous || next ? (_jsxs("nav", { "aria-label": trailLabel, className: "border-border grid gap-4 border-t pt-6 sm:grid-cols-2", children: [previous ? (_jsxs("a", { href: previous.href, className: "flex flex-col gap-1 rounded-sm", children: [_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: trailLabels.previous }), _jsx("span", { className: "text-sm font-semibold", children: previous.title })] })) : null, next ? (_jsxs("a", { href: next.href, className: "flex flex-col gap-1 rounded-sm sm:items-end sm:text-right", children: [_jsx("span", { className: "text-muted-foreground text-xs font-medium tracking-wide uppercase", children: trailLabels.next }), _jsx("span", { className: "text-sm font-semibold", children: next.title })] })) : null] })) : null, footer ? _jsx("div", { className: "border-border border-t pt-8", children: footer }) : null] }), indexLink ? (_jsx("div", { className: "mt-10 flex justify-center", children: _jsx(CtaLink, { href: indexLink.href, variant: "outline", children: indexLink.title }) })) : null] }));
|
|
48
|
+
}
|
|
49
|
+
export default BlogPostPage;
|
package/dist/pages/index.d.ts
CHANGED
|
@@ -14,4 +14,8 @@ export { SettingsPage } from './settings-page';
|
|
|
14
14
|
export type { SettingsPageProps, SettingsPageTab } from './settings-page';
|
|
15
15
|
export { AuthPage } from './auth-page';
|
|
16
16
|
export type { AuthPageProps, AuthPageAside } from './auth-page';
|
|
17
|
+
export { NotFoundPage } from './not-found-page';
|
|
18
|
+
export type { NotFoundPageProps, NotFoundLink } from './not-found-page';
|
|
19
|
+
export { BlogPostPage } from './blog-post-page';
|
|
20
|
+
export type { BlogPostPageProps, BlogPostTag, BlogPostNeighbour, BlogPostTrailLabels } from './blog-post-page';
|
|
17
21
|
//# 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"}
|
|
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"}
|
package/dist/pages/index.js
CHANGED
|
@@ -10,3 +10,5 @@ export { MarketingPage } from './marketing-page';
|
|
|
10
10
|
export { DashboardPage } from './dashboard-page';
|
|
11
11
|
export { SettingsPage } from './settings-page';
|
|
12
12
|
export { AuthPage } from './auth-page';
|
|
13
|
+
export { NotFoundPage } from './not-found-page';
|
|
14
|
+
export { BlogPostPage } from './blog-post-page';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* One way out of a page that was not found.
|
|
4
|
+
*
|
|
5
|
+
* A destination, and the words for it. Both are required, because a not-found
|
|
6
|
+
* page with no way out is a dead end with a message on it, and a link with no
|
|
7
|
+
* words is a shape a reader has to guess at.
|
|
8
|
+
*/
|
|
9
|
+
export type NotFoundLink = {
|
|
10
|
+
/** The words of the link. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** Where it goes. */
|
|
13
|
+
href: string;
|
|
14
|
+
/**
|
|
15
|
+
* Opens the destination in a new browsing context, which defaults the link
|
|
16
|
+
* relationship to `noopener noreferrer`. Almost never right here: a reader who
|
|
17
|
+
* followed a broken link and is sent to a new tab has to find their way back.
|
|
18
|
+
*/
|
|
19
|
+
newTab?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* The props a NotFoundPage takes.
|
|
23
|
+
*
|
|
24
|
+
* Every string is a prop and the Page ships none. There is no "404", no "this
|
|
25
|
+
* page does not exist", no product name and no default set of links: a not-found
|
|
26
|
+
* page that hardcoded any of them would be a page that made a claim about a
|
|
27
|
+
* product it knows nothing about, and the one page on a site that every reader
|
|
28
|
+
* and no crawler will see is the worst place to hardcode a sentence.
|
|
29
|
+
*/
|
|
30
|
+
export type NotFoundPageProps = {
|
|
31
|
+
/**
|
|
32
|
+
* The status code, shown as the page's own `h1`. Required, and a string rather
|
|
33
|
+
* than a number because it is displayed, not computed: a Page never decides
|
|
34
|
+
* what code it is answering.
|
|
35
|
+
*/
|
|
36
|
+
code: string;
|
|
37
|
+
/**
|
|
38
|
+
* The headline under the code: the sentence that says what happened. It is the
|
|
39
|
+
* part a reader actually reads, and it is the caller's because every product
|
|
40
|
+
* says it differently - "No node here", "This page does not exist (yet)".
|
|
41
|
+
*/
|
|
42
|
+
title: string;
|
|
43
|
+
/**
|
|
44
|
+
* One or two sentences under the headline, for anything a reader should know
|
|
45
|
+
* before they follow one of the links: that the URL may be mistyped, that the
|
|
46
|
+
* page is planned, that a search would find it.
|
|
47
|
+
*/
|
|
48
|
+
description?: string;
|
|
49
|
+
/**
|
|
50
|
+
* The ways out, in the order a reader should see them. Put the destination
|
|
51
|
+
* most likely to help first; a not-found page that offers a homepage link
|
|
52
|
+
* before the documentation sends a reader further from what they wanted.
|
|
53
|
+
*/
|
|
54
|
+
links: readonly NotFoundLink[];
|
|
55
|
+
/**
|
|
56
|
+
* The accessible name of the row of ways out. It is required, because it is a
|
|
57
|
+
* word a reader hears and a Page that ships no copy ships no reader-facing copy
|
|
58
|
+
* either. "Ways out" is the Page's own phrasing; a site that files its
|
|
59
|
+
* destinations differently names the same landmark differently.
|
|
60
|
+
*/
|
|
61
|
+
linksLabel: string;
|
|
62
|
+
/**
|
|
63
|
+
* A slot for whatever else the site wants to say here: a search box, a list of
|
|
64
|
+
* recent posts, a contact address.
|
|
65
|
+
*/
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* Layout only, exactly as on every Component. Changing a Prism-owned visual
|
|
69
|
+
* property from here is prohibited.
|
|
70
|
+
*/
|
|
71
|
+
className?: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* A complete not-found screen: the code, what happened, and the ways out.
|
|
75
|
+
*
|
|
76
|
+
* All four NaniSoft sites compose one, each in its own `not-found` route, and
|
|
77
|
+
* three of them are the same six lines with a different product name on it: a
|
|
78
|
+
* display title carrying the code, one muted sentence, and two or three links.
|
|
79
|
+
* The fourth wrote the same thing in its own markup. Four hand-written screens
|
|
80
|
+
* for one shape.
|
|
81
|
+
*
|
|
82
|
+
* It is a Page rather than a Block because it is a whole screen: it owns the
|
|
83
|
+
* document's `h1`, it is what a router renders when a route does not resolve, and
|
|
84
|
+
* it composes `Section`, `Heading`, `Text`, `Prose` and `CtaLink` into the one
|
|
85
|
+
* arrangement of them that answers "this is not here". A Block would be a band
|
|
86
|
+
* of that arrangement, and the band's job is not separable from the screen's:
|
|
87
|
+
* there is one correct page here and it is short.
|
|
88
|
+
*
|
|
89
|
+
* **The code is the `h1` and the sentence is not.** A not-found page whose
|
|
90
|
+
* `h1` is "Page not found" gives a search engine and a screen reader nothing
|
|
91
|
+
* distinct to index, and the code is the one string on the page that is the same
|
|
92
|
+
* for every broken URL. The code takes the display step and the sentence takes
|
|
93
|
+
* the muted one, which is the reverse of what a reader sees first and the right
|
|
94
|
+
* way round for anything that reads the outline.
|
|
95
|
+
*
|
|
96
|
+
* The links are `CtaLink`, so each one is a native anchor with a destination a
|
|
97
|
+
* browser can show, copy and open in a new tab. A not-found page is the one place
|
|
98
|
+
* on a site where a reader most wants to see where a link goes before following
|
|
99
|
+
* it, because they have just followed one that went nowhere.
|
|
100
|
+
*
|
|
101
|
+
* The page carries no `noindex` and no `robots` directive, because this is a
|
|
102
|
+
* component and not a route: what a not-found response is indexed as is the
|
|
103
|
+
* consumer's server's decision, and a Page that declared it would be a Page
|
|
104
|
+
* making a claim about a deployment it cannot see.
|
|
105
|
+
*
|
|
106
|
+
* It is a server Component. It fetches nothing, it holds no state and it imports
|
|
107
|
+
* no router, which is what lets a consumer render it from whichever not-found
|
|
108
|
+
* route their framework names.
|
|
109
|
+
*/
|
|
110
|
+
export declare function NotFoundPage({ code, title, description, links, linksLabel, children, className, }: NotFoundPageProps): import("react").JSX.Element;
|
|
111
|
+
export default NotFoundPage;
|
|
112
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pages/not-found-page/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAOtC;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;;OAIG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;IAC9B;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAA;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,KAAK,EACL,WAAW,EACX,KAAK,EACL,UAAU,EACV,QAAQ,EACR,SAAS,GACV,EAAE,iBAAiB,+BA+BnB;AAED,eAAe,YAAY,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CtaLink } from '../../components/ui/cta-link';
|
|
3
|
+
import { Heading, Text } from '../../components/ui/typography';
|
|
4
|
+
import { Prose } from '../../components/ui/prose';
|
|
5
|
+
import { Section } from '../../components/ui/section';
|
|
6
|
+
/**
|
|
7
|
+
* A complete not-found screen: the code, what happened, and the ways out.
|
|
8
|
+
*
|
|
9
|
+
* All four NaniSoft sites compose one, each in its own `not-found` route, and
|
|
10
|
+
* three of them are the same six lines with a different product name on it: a
|
|
11
|
+
* display title carrying the code, one muted sentence, and two or three links.
|
|
12
|
+
* The fourth wrote the same thing in its own markup. Four hand-written screens
|
|
13
|
+
* for one shape.
|
|
14
|
+
*
|
|
15
|
+
* It is a Page rather than a Block because it is a whole screen: it owns the
|
|
16
|
+
* document's `h1`, it is what a router renders when a route does not resolve, and
|
|
17
|
+
* it composes `Section`, `Heading`, `Text`, `Prose` and `CtaLink` into the one
|
|
18
|
+
* arrangement of them that answers "this is not here". A Block would be a band
|
|
19
|
+
* of that arrangement, and the band's job is not separable from the screen's:
|
|
20
|
+
* there is one correct page here and it is short.
|
|
21
|
+
*
|
|
22
|
+
* **The code is the `h1` and the sentence is not.** A not-found page whose
|
|
23
|
+
* `h1` is "Page not found" gives a search engine and a screen reader nothing
|
|
24
|
+
* distinct to index, and the code is the one string on the page that is the same
|
|
25
|
+
* for every broken URL. The code takes the display step and the sentence takes
|
|
26
|
+
* the muted one, which is the reverse of what a reader sees first and the right
|
|
27
|
+
* way round for anything that reads the outline.
|
|
28
|
+
*
|
|
29
|
+
* The links are `CtaLink`, so each one is a native anchor with a destination a
|
|
30
|
+
* browser can show, copy and open in a new tab. A not-found page is the one place
|
|
31
|
+
* on a site where a reader most wants to see where a link goes before following
|
|
32
|
+
* it, because they have just followed one that went nowhere.
|
|
33
|
+
*
|
|
34
|
+
* The page carries no `noindex` and no `robots` directive, because this is a
|
|
35
|
+
* component and not a route: what a not-found response is indexed as is the
|
|
36
|
+
* consumer's server's decision, and a Page that declared it would be a Page
|
|
37
|
+
* making a claim about a deployment it cannot see.
|
|
38
|
+
*
|
|
39
|
+
* It is a server Component. It fetches nothing, it holds no state and it imports
|
|
40
|
+
* no router, which is what lets a consumer render it from whichever not-found
|
|
41
|
+
* route their framework names.
|
|
42
|
+
*/
|
|
43
|
+
export function NotFoundPage({ code, title, description, links, linksLabel, children, className, }) {
|
|
44
|
+
return (_jsx(Section, { className: className, children: _jsxs("div", { className: "flex flex-col items-start gap-6", children: [_jsx(Heading, { as: "h1", size: "4xl", className: "text-muted-foreground font-mono", children: code }), _jsxs("div", { className: "flex flex-col gap-3", children: [_jsx(Heading, { as: "h2", size: "2xl", children: title }), description ? _jsx(Text, { size: "lg", children: description }) : null] }), links.length > 0 ? (_jsx("nav", { "aria-label": linksLabel, className: "flex flex-wrap items-center gap-3", children: links.map((link, index) => (_jsx(CtaLink, { href: link.href, newTab: link.newTab, variant: index === 0 ? 'default' : 'outline', children: link.label }, link.href))) })) : null, children ? _jsx(Prose, { className: "mt-2", children: children }) : null] }) }));
|
|
45
|
+
}
|
|
46
|
+
export default NotFoundPage;
|
|
@@ -7,6 +7,11 @@
|
|
|
7
7
|
* the same two markup attributes the declarative form uses. There is no
|
|
8
8
|
* override, merge, token, className or style prop: the provider's only outputs
|
|
9
9
|
* are the document-element attributes and context (ticket 07).
|
|
10
|
+
*
|
|
11
|
+
* It resolves through `resolveTheme`, the one rule the boot script also
|
|
12
|
+
* implements, and it never writes `THEME_ORIGIN_ATTRIBUTE`: the script is that
|
|
13
|
+
* attribute's only writer, and two writers would turn a record of the origin
|
|
14
|
+
* into a race.
|
|
10
15
|
*/
|
|
11
16
|
import { type ReactNode } from 'react';
|
|
12
17
|
import { type Mode, type PackId } from '../theming';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider/provider.tsx"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/provider/provider.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAQL,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAEd,OAAO,EAML,KAAK,IAAI,EACT,KAAK,MAAM,EAEZ,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAC7B,UAAU,EAAE,MAAM,IAAI,CAAA;CACvB,CAAA;AAID,MAAM,MAAM,kBAAkB,GAAG;IAC/B,yEAAyE;IACzE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,sCAAsC;IACtC,WAAW,CAAC,EAAE,IAAI,CAAA;IAClB,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB,CAAA;AAyCD,wBAAgB,aAAa,CAAC,EAC5B,WAAuB,EACvB,WAAqB,EACrB,UAAgC,EAChC,QAAQ,GACT,EAAE,kBAAkB,+BAuHpB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,UAAU,CAM1C"}
|
|
@@ -9,67 +9,158 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
9
9
|
* the same two markup attributes the declarative form uses. There is no
|
|
10
10
|
* override, merge, token, className or style prop: the provider's only outputs
|
|
11
11
|
* are the document-element attributes and context (ticket 07).
|
|
12
|
+
*
|
|
13
|
+
* It resolves through `resolveTheme`, the one rule the boot script also
|
|
14
|
+
* implements, and it never writes `THEME_ORIGIN_ATTRIBUTE`: the script is that
|
|
15
|
+
* attribute's only writer, and two writers would turn a record of the origin
|
|
16
|
+
* into a race.
|
|
12
17
|
*/
|
|
13
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useState, } from 'react';
|
|
14
|
-
import { DEFAULT_STORAGE_KEY,
|
|
18
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
19
|
+
import { DEFAULT_STORAGE_KEY, PACK_ATTRIBUTE, readLegacyMode, resolveTheme, themeAttributes, } from '../theming';
|
|
15
20
|
const PrismThemeContext = createContext(null);
|
|
16
21
|
function applyDocumentAttributes(pack, mode) {
|
|
17
22
|
const root = document.documentElement;
|
|
18
23
|
const { 'data-pack': packAttribute, className } = themeAttributes({ pack, mode });
|
|
19
24
|
if (packAttribute)
|
|
20
|
-
root.setAttribute(
|
|
25
|
+
root.setAttribute(PACK_ATTRIBUTE, packAttribute);
|
|
21
26
|
else
|
|
22
|
-
root.removeAttribute(
|
|
27
|
+
root.removeAttribute(PACK_ATTRIBUTE);
|
|
23
28
|
if (className)
|
|
24
29
|
root.classList.add('dark');
|
|
25
30
|
else
|
|
26
31
|
root.classList.remove('dark');
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
/** One guarded read. A blocked or full store must not break the page. */
|
|
34
|
+
function read(key) {
|
|
35
|
+
try {
|
|
36
|
+
return localStorage.getItem(key);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** One guarded write. The attributes are already applied when this fails. */
|
|
43
|
+
function persist(key, pack, mode) {
|
|
44
|
+
try {
|
|
45
|
+
localStorage.setItem(key, JSON.stringify({ pack, mode }));
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// A blocked or full localStorage must not break theme switching. The
|
|
49
|
+
// attributes are already applied, so the visible behaviour is unchanged.
|
|
50
|
+
}
|
|
33
51
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
52
|
+
function retire(key) {
|
|
53
|
+
try {
|
|
54
|
+
localStorage.removeItem(key);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// Nothing to do: a key that cannot be removed is read again next load,
|
|
58
|
+
// recovers the same decision, and writes the same pair.
|
|
59
|
+
}
|
|
36
60
|
}
|
|
37
61
|
export function PrismProvider({ defaultPack = 'default', defaultMode = 'light', storageKey = DEFAULT_STORAGE_KEY, children, }) {
|
|
38
|
-
const [pack, setPackState] = useState(defaultPack);
|
|
39
|
-
const [mode, setModeState] = useState(defaultMode);
|
|
40
|
-
const [resolved, setResolved] = useState(false);
|
|
41
62
|
/*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
63
|
+
* The resolution, and whether a decision has been made. Two pieces of state
|
|
64
|
+
* for two different questions, which is why the old `resolved` flag was not
|
|
65
|
+
* enough on its own:
|
|
66
|
+
*
|
|
67
|
+
* - `theme` is null until the store has been read. It gates APPLY, because
|
|
68
|
+
* applying the default over a server-rendered pack before resolution is
|
|
69
|
+
* the flash the resolution order exists to prevent. It carries the
|
|
70
|
+
* origin, so the recovery below can read it without a second lookup.
|
|
71
|
+
* - `decided` is a ref, not state, because it must be readable by the write
|
|
72
|
+
* effect without causing a render, and settable synchronously by a caller
|
|
73
|
+
* whose state update has not been committed yet. It gates WRITE.
|
|
74
|
+
*
|
|
75
|
+
* A ref also cannot be re-rendered into an extra effect pass, which is what
|
|
76
|
+
* would have made the write fire once for the flag and once for the value.
|
|
77
|
+
*/
|
|
78
|
+
const [theme, setTheme] = useState(null);
|
|
79
|
+
const decided = useRef(false);
|
|
80
|
+
/*
|
|
81
|
+
* Resolution on mount, through the one shared rule: the stored value, then a
|
|
82
|
+
* key this line no longer writes, then what the server rendered, then the
|
|
83
|
+
* defaults. A server-rendered pack therefore survives hydration.
|
|
45
84
|
*/
|
|
46
85
|
useEffect(() => {
|
|
47
|
-
const
|
|
48
|
-
const next =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
86
|
+
const recovered = readLegacyMode(read);
|
|
87
|
+
const next = resolveTheme({
|
|
88
|
+
stored: read(storageKey),
|
|
89
|
+
legacy: recovered?.mode ?? null,
|
|
90
|
+
documentPack: document.documentElement.getAttribute(PACK_ATTRIBUTE),
|
|
91
|
+
documentDark: document.documentElement.classList.contains('dark'),
|
|
92
|
+
defaultPack,
|
|
93
|
+
defaultMode,
|
|
94
|
+
});
|
|
95
|
+
if (next.origin === 'legacy' && recovered) {
|
|
96
|
+
/*
|
|
97
|
+
* The recovery write. A decision taken from a key this line no longer
|
|
98
|
+
* writes is put in the key it does write, and the old key is retired in
|
|
99
|
+
* the same breath, which is what makes the clause self-disabling: the
|
|
100
|
+
* next load finds nothing to recover, so a reader is migrated once and
|
|
101
|
+
* the population the clause can still reach only ever shrinks.
|
|
102
|
+
*/
|
|
103
|
+
persist(storageKey, next.pack, next.mode);
|
|
104
|
+
retire(recovered.key);
|
|
105
|
+
}
|
|
106
|
+
// A caller that decided in a layout effect before this ran keeps its value.
|
|
107
|
+
if (!decided.current)
|
|
108
|
+
setTheme(next);
|
|
52
109
|
}, [storageKey, defaultPack, defaultMode]);
|
|
53
110
|
/*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
111
|
+
* Apply always, once there is a resolution; persist only on a decision.
|
|
112
|
+
*
|
|
113
|
+
* The first resolution from the document or the defaults writes nothing, so a
|
|
114
|
+
* visitor who never touched the toggle ends the load with an empty store and
|
|
115
|
+
* a site that changes its default reaches everyone who has not chosen.
|
|
56
116
|
*/
|
|
57
117
|
useEffect(() => {
|
|
58
|
-
if (!
|
|
118
|
+
if (!theme)
|
|
59
119
|
return;
|
|
60
|
-
applyDocumentAttributes(pack, mode);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
120
|
+
applyDocumentAttributes(theme.pack, theme.mode);
|
|
121
|
+
if (decided.current)
|
|
122
|
+
persist(storageKey, theme.pack, theme.mode);
|
|
123
|
+
}, [theme, storageKey]);
|
|
124
|
+
const setPack = useCallback((next) => {
|
|
125
|
+
decided.current = true;
|
|
126
|
+
setTheme((current) => ({
|
|
127
|
+
pack: next,
|
|
128
|
+
mode: current?.mode ?? defaultMode,
|
|
129
|
+
origin: 'stored',
|
|
130
|
+
}));
|
|
131
|
+
}, [defaultMode]);
|
|
132
|
+
const setMode = useCallback((next) => {
|
|
133
|
+
decided.current = true;
|
|
134
|
+
setTheme((current) => ({
|
|
135
|
+
pack: current?.pack ?? defaultPack,
|
|
136
|
+
mode: next,
|
|
137
|
+
origin: 'stored',
|
|
138
|
+
}));
|
|
139
|
+
}, [defaultPack]);
|
|
140
|
+
/*
|
|
141
|
+
* The pair is a closed union of two members, so the other one is the other
|
|
142
|
+
* member. Spelling it out costs nothing and does not hide the coupling behind
|
|
143
|
+
* an index into a list this file does not otherwise need.
|
|
144
|
+
*
|
|
145
|
+
* The three setters all fall back to the consumer's own default rather than
|
|
146
|
+
* to the neutral one, so a decision taken before the store has been read
|
|
147
|
+
* pairs the chosen axis with the site's default and not with a guess.
|
|
148
|
+
*/
|
|
149
|
+
const toggleMode = useCallback(() => {
|
|
150
|
+
decided.current = true;
|
|
151
|
+
setTheme((current) => ({
|
|
152
|
+
pack: current?.pack ?? defaultPack,
|
|
153
|
+
mode: current?.mode === 'dark' ? 'light' : 'dark',
|
|
154
|
+
origin: 'stored',
|
|
155
|
+
}));
|
|
156
|
+
}, [defaultPack]);
|
|
157
|
+
const value = useMemo(() => ({
|
|
158
|
+
pack: theme?.pack ?? defaultPack,
|
|
159
|
+
mode: theme?.mode ?? defaultMode,
|
|
160
|
+
setPack,
|
|
161
|
+
setMode,
|
|
162
|
+
toggleMode,
|
|
163
|
+
}), [theme, defaultPack, defaultMode, setPack, setMode, toggleMode]);
|
|
73
164
|
return _jsx(PrismThemeContext.Provider, { value: value, children: children });
|
|
74
165
|
}
|
|
75
166
|
/**
|