@composable-os/pack-content 0.0.0-stage → 0.1.0-beta.7

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/LICENSE ADDED
@@ -0,0 +1,109 @@
1
+ # Functional Source License, Version 1.1, ALv2 Future License
2
+
3
+ > This licence covers the repository except the directories listed in NOTICE. In particular, the
4
+ > assistant packages `packages/agent-*` (agent-core, agent-a2ui, agent-voice, agent-plugins) are
5
+ > licensed under the MIT License; see the LICENSE file in each of those directories (ADR 0350).
6
+
7
+ ## Abbreviation
8
+
9
+ FSL-1.1-ALv2
10
+
11
+ ## Notice
12
+
13
+ Copyright 2026 Tim O'Connell
14
+
15
+ ## Terms and Conditions
16
+
17
+ ### Licensor ("We")
18
+
19
+ The party offering the Software under these Terms and Conditions.
20
+
21
+ ### The Software
22
+
23
+ The "Software" is each version of the software that we make available under
24
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
25
+ Conditions with the Software.
26
+
27
+ ### License Grant
28
+
29
+ Subject to your compliance with this License Grant and the Patents,
30
+ Redistribution and Trademark clauses below, we hereby grant you the right to
31
+ use, copy, modify, create derivative works, publicly perform, publicly display
32
+ and redistribute the Software for any Permitted Purpose identified below.
33
+
34
+ ### Permitted Purpose
35
+
36
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
37
+ means making the Software available to others in a commercial product or
38
+ service that:
39
+
40
+ 1. substitutes for the Software;
41
+
42
+ 2. substitutes for any other product or service we offer using the Software
43
+ that exists as of the date we make the Software available; or
44
+
45
+ 3. offers the same or substantially similar functionality as the Software.
46
+
47
+ Permitted Purposes specifically include using the Software:
48
+
49
+ 1. for your internal use and access;
50
+
51
+ 2. for non-commercial education;
52
+
53
+ 3. for non-commercial research; and
54
+
55
+ 4. in connection with professional services that you provide to a licensee
56
+ using the Software in accordance with these Terms and Conditions.
57
+
58
+ ### Patents
59
+
60
+ To the extent your use for a Permitted Purpose would necessarily infringe our
61
+ patents, the license grant above includes a license under our patents. If you
62
+ make a claim against any party that the Software infringes or contributes to
63
+ the infringement of any patent, then your patent license to the Software ends
64
+ immediately.
65
+
66
+ ### Redistribution
67
+
68
+ The Terms and Conditions apply to all copies, modifications and derivatives of
69
+ the Software.
70
+
71
+ If you redistribute any copies, modifications or derivatives of the Software,
72
+ you must include a copy of or a link to these Terms and Conditions and not
73
+ remove any copyright notices provided in or with the Software.
74
+
75
+ ### Disclaimer
76
+
77
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
78
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
79
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
80
+
81
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
82
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
83
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
84
+
85
+ ### Trademarks
86
+
87
+ Except for displaying the License Details and identifying us as the origin of
88
+ the Software, you have no right under these Terms and Conditions to use our
89
+ trademarks, trade names, service marks or product names.
90
+
91
+ ## Grant of Future License
92
+
93
+ We hereby irrevocably grant you an additional license to use the Software under
94
+ the Apache License, Version 2.0 that is effective on the second anniversary of
95
+ the date we make the Software available. On or after that date, you may use the
96
+ Software under the Apache License, Version 2.0, in which case the following
97
+ will apply:
98
+
99
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
100
+ this file except in compliance with the License.
101
+
102
+ You may obtain a copy of the License at
103
+
104
+ http://www.apache.org/licenses/LICENSE-2.0
105
+
106
+ Unless required by applicable law or agreed to in writing, software distributed
107
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
108
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
109
+ specific language governing permissions and limitations under the License.
@@ -0,0 +1,11 @@
1
+ import type { ContentHooks } from "@composable-os/pack-content/client";
2
+ export declare function PostScreen({ content, slug, openUrl, mediaUrl, onRedirect, width, }: {
3
+ content: Pick<ContentHooks, "usePost">;
4
+ slug: string;
5
+ openUrl: (url: string) => void;
6
+ /** Absolute: `hostMediaUrl(hostUrl)`, the host's `/api/v1/media/<id>?w=<width>`. */
7
+ mediaUrl: (id: string, width: number) => string;
8
+ onRedirect: (slug: string) => void;
9
+ /** The screen's width in device pixels, for the pictures. */
10
+ width?: number;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { postDate } from "@composable-os/pack-content/client";
3
+ import { Image, ScrollView, StyleSheet, Text, View } from "react-native";
4
+ import { RichTextView } from "../content-native-rich-text/rich-text-view.js";
5
+ import { theme } from "../native-base/theme.js";
6
+ export function PostScreen({ content, slug, openUrl, mediaUrl, onRedirect, width, }) {
7
+ const { data, isPending, error } = content.usePost(slug);
8
+ if (isPending)
9
+ return _jsx(Text, { style: styles.muted, children: "Loading\u2026" });
10
+ if (error || !data) {
11
+ return (_jsx(Text, { accessibilityRole: "alert", children: "This post is not here. It may have moved or ended." }));
12
+ }
13
+ if (data.kind === "redirect") {
14
+ onRedirect(data.slug);
15
+ return _jsx(Text, { style: styles.muted, children: "This post has moved." });
16
+ }
17
+ const v = data.values;
18
+ return (_jsxs(ScrollView, { contentContainerStyle: styles.page, children: [_jsxs(View, { style: styles.header, children: [_jsx(Text, { style: styles.title, accessibilityRole: "header", children: v.title }), postDate(data) ? _jsx(Text, { style: styles.muted, children: postDate(data) }) : null, v.byline ? _jsx(Text, { style: styles.muted, children: v.byline }) : null] }), v.cover ? (_jsx(Image, { source: { uri: mediaUrl(v.cover.media, width ?? 960) }, accessibilityLabel: v.cover.alt, style: styles.cover, resizeMode: "cover" })) : null, _jsx(RichTextView, { value: v.body, openUrl: openUrl, mediaUrl: mediaUrl, ...(width ? { width } : {}) })] }));
19
+ }
20
+ const styles = StyleSheet.create({
21
+ page: { padding: theme.space.md, gap: theme.space.md },
22
+ header: { gap: theme.space.xs },
23
+ title: { fontSize: theme.font.title, fontWeight: "700", color: theme.color.text },
24
+ muted: { color: theme.color.muted, fontSize: theme.font.small },
25
+ cover: { width: "100%", aspectRatio: 16 / 9, borderRadius: theme.radius },
26
+ });
@@ -0,0 +1,24 @@
1
+ import { type Block, type RichText as RichTextValue } from "@composable-os/pack-content/client";
2
+ import type { ReactNode } from "react";
3
+ export type NativeBlockRenderer<T extends Block["type"]> = (props: {
4
+ block: Extract<Block, {
5
+ type: T;
6
+ }>;
7
+ }) => ReactNode;
8
+ export interface RichTextViewProps {
9
+ value: RichTextValue | null | undefined;
10
+ /** Opens an address: a link, a button's, a video's. */
11
+ openUrl: (url: string) => void;
12
+ /**
13
+ * Where a picture is, absolute: the host's public media route,
14
+ * `hostMediaUrl(hostUrl)` (`https://<host>/api/v1/media/<id>?w=<width>`).
15
+ */
16
+ mediaUrl: (id: string, width: number) => string;
17
+ /** The width the pictures are shown at, in device pixels (the screen's). */
18
+ width?: number;
19
+ components?: {
20
+ [T in Block["type"]]?: NativeBlockRenderer<T>;
21
+ };
22
+ }
23
+ /** A rich text document. An empty or missing one draws nothing. */
24
+ export declare function RichTextView({ value, openUrl, mediaUrl, width, components, }: RichTextViewProps): import("react").JSX.Element | null;
@@ -0,0 +1,122 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Rich text for the mobile app (stage 28, ADR 0440): a post's body drawn block by block with React
3
+ // Native's own components, from the same structured data the web block draws. Every block type and
4
+ // mark has its element here; its look is the native base layer's theme. Pass `components` to use
5
+ // the app's own for a block type, and `openUrl` (React Native's `Linking.openURL`, or the app's
6
+ // in-app browser) for links, buttons and videos.
7
+ //
8
+ // No web view: an embed is a tappable card that opens the video (or the link) outside the app.
9
+ import { embedKind, } from "@composable-os/pack-content/client";
10
+ import { Image, Pressable, StyleSheet, Text, View } from "react-native";
11
+ import { theme } from "../native-base/theme.js";
12
+ function Runs({ content, openUrl, style, }) {
13
+ return (_jsx(Text, { style: [styles.body, style], children: (content ?? []).map((run, i) => {
14
+ if (run.type === "break") {
15
+ return (_jsx(Text, { testID: "rt-mark-break", children: "\n" }, i));
16
+ }
17
+ const marks = [
18
+ run.bold ? styles.bold : null,
19
+ run.italic ? styles.italic : null,
20
+ run.code ? styles.code : null,
21
+ run.href ? styles.link : null,
22
+ ];
23
+ const ids = [
24
+ run.bold ? "bold" : "",
25
+ run.italic ? "italic" : "",
26
+ run.code ? "code" : "",
27
+ run.href ? "link" : "",
28
+ ].filter(Boolean);
29
+ const href = run.href;
30
+ return (_jsx(Text
31
+ // biome-ignore lint/suspicious/noArrayIndexKey: runs are positional.
32
+ , { style: marks, ...(ids.length ? { testID: `rt-mark-${ids.join("-")}` } : {}), ...(href ? { onPress: () => openUrl(href), accessibilityRole: "link" } : {}), children: run.text }, i));
33
+ }) }));
34
+ }
35
+ function ListView({ body, openUrl, depth, }) {
36
+ return (_jsx(View, { testID: `rt-block-list-${body.style}`, style: { paddingLeft: depth * theme.space.md }, children: body.items.map((item, i) => (_jsxs(View, { children: [_jsxs(View, { style: styles.listRow, children: [_jsx(Text, { style: styles.body, children: body.style === "ordered" ? `${i + 1}.` : "•" }), _jsx(Runs, { content: item.content, openUrl: openUrl, style: styles.listText })] }), item.list ? _jsx(ListView, { body: item.list, openUrl: openUrl, depth: depth + 1 }) : null] }, i))) }));
37
+ }
38
+ const TONE_COLOR = {
39
+ info: "#0ea5e9",
40
+ note: theme.color.muted,
41
+ success: "#10b981",
42
+ warning: "#f59e0b",
43
+ };
44
+ function DefaultBlock({ block, openUrl, mediaUrl, width, }) {
45
+ switch (block.type) {
46
+ case "paragraph":
47
+ return (_jsx(View, { testID: "rt-block-paragraph", children: _jsx(Runs, { content: block.content, openUrl: openUrl }) }));
48
+ case "heading":
49
+ return (_jsx(View, { testID: "rt-block-heading", accessibilityRole: "header", children: _jsx(Runs, { content: block.content, openUrl: openUrl, style: {
50
+ fontSize: Math.max(theme.font.title - (block.level - 1) * 2, theme.font.body),
51
+ fontWeight: "700",
52
+ } }) }));
53
+ case "list":
54
+ return _jsx(ListView, { body: block, openUrl: openUrl, depth: 0 });
55
+ case "quote":
56
+ return (_jsxs(View, { testID: "rt-block-quote", style: styles.quote, children: [_jsx(Runs, { content: block.content, openUrl: openUrl, style: styles.italic }), block.attribution ? _jsx(Text, { style: styles.muted, children: block.attribution }) : null] }));
57
+ case "image":
58
+ return (_jsxs(View, { testID: "rt-block-image", children: [_jsx(Image, { source: { uri: mediaUrl(block.media, width) }, accessibilityLabel: block.alt, style: styles.picture, resizeMode: "cover" }), block.caption?.length ? (_jsx(Runs, { content: block.caption, openUrl: openUrl, style: styles.muted })) : null] }));
59
+ case "divider":
60
+ return _jsx(View, { testID: "rt-block-divider", style: styles.divider });
61
+ case "embed": {
62
+ const kind = embedKind(block.url);
63
+ return (_jsxs(Pressable, { testID: `rt-block-embed-${kind.kind}`, accessibilityRole: "link", onPress: () => openUrl(block.url), style: styles.embed, children: [_jsx(Text, { style: styles.bold, children: kind.kind === "link"
64
+ ? "Open link"
65
+ : `Play the ${kind.kind === "youtube" ? "YouTube" : "Vimeo"} video` }), block.caption ? _jsx(Text, { style: styles.muted, children: block.caption }) : null] }));
66
+ }
67
+ case "callout":
68
+ return (_jsx(View, { testID: `rt-block-callout-${block.tone}`, style: [styles.callout, { borderLeftColor: TONE_COLOR[block.tone] }], children: _jsx(Runs, { content: block.content, openUrl: openUrl }) }));
69
+ case "button":
70
+ return (_jsx(Pressable, { testID: "rt-block-button", accessibilityRole: "button", onPress: () => openUrl(block.href), style: styles.button, children: _jsx(Text, { style: styles.buttonText, children: block.label }) }));
71
+ }
72
+ }
73
+ /** A rich text document. An empty or missing one draws nothing. */
74
+ export function RichTextView({ value, openUrl, mediaUrl, width = 960, components = {}, }) {
75
+ const blocks = value?.blocks ?? [];
76
+ if (!blocks.length)
77
+ return null;
78
+ return (_jsx(View, { style: styles.document, testID: "rt-document", children: blocks.map((block, i) => {
79
+ const custom = components[block.type];
80
+ return (_jsx(View, { children: custom ? (custom({ block })) : (_jsx(DefaultBlock, { block: block, openUrl: openUrl, mediaUrl: mediaUrl, width: width })) }, i));
81
+ }) }));
82
+ }
83
+ const styles = StyleSheet.create({
84
+ document: { gap: theme.space.md },
85
+ body: { fontSize: theme.font.body, color: theme.color.text, lineHeight: theme.font.body * 1.5 },
86
+ bold: { fontWeight: "700" },
87
+ italic: { fontStyle: "italic" },
88
+ code: { fontFamily: "Courier", backgroundColor: theme.color.surface },
89
+ link: { textDecorationLine: "underline", color: theme.color.primary },
90
+ muted: { color: theme.color.muted, fontSize: theme.font.small },
91
+ listRow: { flexDirection: "row", gap: theme.space.sm },
92
+ listText: { flex: 1 },
93
+ quote: {
94
+ borderLeftWidth: 4,
95
+ borderLeftColor: theme.color.border,
96
+ paddingLeft: theme.space.md,
97
+ gap: theme.space.xs,
98
+ },
99
+ picture: { width: "100%", aspectRatio: 16 / 9, borderRadius: theme.radius },
100
+ divider: { height: StyleSheet.hairlineWidth, backgroundColor: theme.color.border },
101
+ embed: {
102
+ borderWidth: 1,
103
+ borderColor: theme.color.border,
104
+ borderRadius: theme.radius,
105
+ padding: theme.space.md,
106
+ gap: theme.space.xs,
107
+ },
108
+ callout: {
109
+ borderLeftWidth: 4,
110
+ backgroundColor: theme.color.surface,
111
+ borderRadius: theme.radius,
112
+ padding: theme.space.md,
113
+ },
114
+ button: {
115
+ backgroundColor: theme.color.primary,
116
+ borderRadius: theme.radius,
117
+ paddingVertical: theme.space.sm,
118
+ paddingHorizontal: theme.space.md,
119
+ alignSelf: "flex-start",
120
+ },
121
+ buttonText: { color: theme.color.onPrimary, fontSize: theme.font.body, fontWeight: "600" },
122
+ });
@@ -0,0 +1,35 @@
1
+ import type { ContentHooks, PublicPost } from "@composable-os/pack-content/client";
2
+ import { postHead } from "@composable-os/pack-content/client";
3
+ /** A post's article: shared by the page and the preview. */
4
+ export declare function PostArticle({ post, mediaBase, mediaUrl, preview, }: {
5
+ post: PublicPost;
6
+ /** Another origin for the pictures than this site's /api/media route. */
7
+ mediaBase?: string;
8
+ mediaUrl?: (id: string, width: number) => string;
9
+ preview?: boolean;
10
+ }): import("react").JSX.Element;
11
+ export declare function PostPage({ content, slug, onRedirect, mediaUrl, mediaBase, }: {
12
+ content: Pick<ContentHooks, "usePost">;
13
+ slug: string;
14
+ /** The post's address now, for an old one: send a 301 there. */
15
+ onRedirect: (slug: string) => void;
16
+ mediaUrl?: (id: string, width: number) => string;
17
+ mediaBase?: string;
18
+ }): import("react").JSX.Element;
19
+ /** The working copy of a post, for whoever holds a preview link. */
20
+ export declare function PostPreview({ content, slug, token, mediaUrl, mediaBase, }: {
21
+ content: Pick<ContentHooks, "usePreview">;
22
+ slug: string;
23
+ token: string;
24
+ mediaUrl?: (id: string, width: number) => string;
25
+ mediaBase?: string;
26
+ }): import("react").JSX.Element;
27
+ /**
28
+ * A post page's head (ADR 0470): <title>, the description, the share picture (Open Graph and
29
+ * Twitter cards), the canonical link and `noindex`, as React 19 elements, which React hoists into
30
+ * the document's <head> wherever this is rendered. Render it beside `PostArticle` on the server
31
+ * (TanStack Start) or, in an Astro page, use `postHead()` in the frontmatter instead.
32
+ */
33
+ export declare function PostHead({ post, ...options }: {
34
+ post: PublicPost;
35
+ } & Parameters<typeof postHead>[1]): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { mediaPath, postDate, postHead } from "@composable-os/pack-content/client";
3
+ import { RichText } from "../content-rich-text/rich-text.js";
4
+ /** A post's article: shared by the page and the preview. */
5
+ export function PostArticle({ post, mediaBase = "", mediaUrl = (id, width) => mediaPath(id, width, mediaBase), preview = false, }) {
6
+ const v = post.values;
7
+ return (_jsxs("article", { className: "mx-auto grid max-w-3xl gap-6", "data-post": post.id, children: [preview ? (_jsx("p", { role: "status", className: "rounded bg-muted p-2 text-sm", children: "Preview: this is the draft, not what readers see." })) : null, _jsxs("header", { className: "grid gap-2", children: [_jsx("h1", { className: "text-3xl font-semibold", children: v.title }), postDate(post) ? (_jsx("time", { dateTime: v.date ?? v.publishedAt ?? undefined, className: "text-muted-foreground", children: postDate(post) })) : null, v.byline ? (_jsx("p", { className: "text-muted-foreground", "data-byline": "", children: v.byline })) : null] }), v.cover ? (_jsx("img", { src: mediaUrl(v.cover.media, 1280), alt: v.cover.alt, className: "w-full rounded-lg object-cover", style: v.cover.focal
8
+ ? { objectPosition: `${v.cover.focal.x * 100}% ${v.cover.focal.y * 100}%` }
9
+ : undefined })) : null, _jsx(RichText, { value: v.body, mediaUrl: mediaUrl })] }));
10
+ }
11
+ export function PostPage({ content, slug, onRedirect, mediaUrl, mediaBase, }) {
12
+ const { data, isPending, error } = content.usePost(slug);
13
+ if (isPending)
14
+ return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
15
+ if (error || !data)
16
+ return _jsx("p", { role: "alert", children: "This post is not here. It may have moved or ended." });
17
+ if (data.kind === "redirect") {
18
+ onRedirect(data.slug);
19
+ return _jsx("p", { children: "This post has moved." });
20
+ }
21
+ return (_jsx(PostArticle, { post: data, ...(mediaUrl ? { mediaUrl } : {}), ...(mediaBase ? { mediaBase } : {}) }));
22
+ }
23
+ /** The working copy of a post, for whoever holds a preview link. */
24
+ export function PostPreview({ content, slug, token, mediaUrl, mediaBase, }) {
25
+ const { data, isPending, error } = content.usePreview(slug, token);
26
+ if (isPending)
27
+ return _jsx("p", { "aria-busy": "true", children: "Loading\u2026" });
28
+ if (error || !data)
29
+ return _jsx("p", { role: "alert", children: "This preview link has ended or is not for this post." });
30
+ return (_jsx(PostArticle, { post: data, preview: true, ...(mediaUrl ? { mediaUrl } : {}), ...(mediaBase ? { mediaBase } : {}) }));
31
+ }
32
+ /**
33
+ * A post page's head (ADR 0470): <title>, the description, the share picture (Open Graph and
34
+ * Twitter cards), the canonical link and `noindex`, as React 19 elements, which React hoists into
35
+ * the document's <head> wherever this is rendered. Render it beside `PostArticle` on the server
36
+ * (TanStack Start) or, in an Astro page, use `postHead()` in the frontmatter instead.
37
+ */
38
+ export function PostHead({ post, ...options }) {
39
+ const head = postHead(post, options);
40
+ return (_jsxs(_Fragment, { children: [_jsx("title", { children: head.title }), head.description ? _jsx("meta", { name: "description", content: head.description }) : null, _jsx("meta", { property: "og:title", content: head.title }), head.description ? _jsx("meta", { property: "og:description", content: head.description }) : null, head.image ? _jsx("meta", { property: "og:image", content: head.image.url }) : null, head.image ? _jsx("meta", { property: "og:image:alt", content: head.image.alt }) : null, _jsx("meta", { name: "twitter:card", content: head.image ? "summary_large_image" : "summary" }), head.canonical ? _jsx("link", { rel: "canonical", href: head.canonical }) : null, head.canonical ? _jsx("meta", { property: "og:url", content: head.canonical }) : null, head.robots ? _jsx("meta", { name: "robots", content: head.robots }) : null] }));
41
+ }
@@ -0,0 +1,15 @@
1
+ import type { ContentHooks } from "@composable-os/pack-content/client";
2
+ export declare function PostList({ content, hrefOf, category, after, olderHref, mediaBase, mediaUrl, }: {
3
+ content: Pick<ContentHooks, "usePosts">;
4
+ /** The page a post is read on: `(slug) => "/blog/" + slug`. */
5
+ hrefOf: (slug: string) => string;
6
+ /** Only posts of this category (its id). */
7
+ category?: string;
8
+ /** The page's cursor: what the previous page's "Older posts" link carried. */
9
+ after?: string;
10
+ /** The address of the next page, given its cursor: `(c) => "/blog?after=" + c`. */
11
+ olderHref?: (cursor: string) => string;
12
+ /** Another origin for the pictures than this site's /api/media route. */
13
+ mediaBase?: string;
14
+ mediaUrl?: (id: string, width: number) => string;
15
+ }): import("react").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { mediaPath, plainText, postDate } from "@composable-os/pack-content/client";
3
+ import { Button } from "../ui-button/button.js";
4
+ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
5
+ /** A post's summary: its excerpt, else the start of its body. */
6
+ function summary(post) {
7
+ if (post.values.excerpt)
8
+ return post.values.excerpt;
9
+ const words = plainText(post.values.body);
10
+ return words.length > 200 ? `${words.slice(0, 197).trimEnd()}…` : words;
11
+ }
12
+ export function PostList({ content, hrefOf, category, after, olderHref, mediaBase = "", mediaUrl = (id, width) => mediaPath(id, width, mediaBase), }) {
13
+ const { data, isPending, error } = content.usePosts({
14
+ limit: 20,
15
+ ...(category ? { filter: { field: "category", op: "eq", value: category } } : {}),
16
+ ...(after ? { cursor: after } : {}),
17
+ });
18
+ if (isPending)
19
+ return _jsx("p", { "aria-busy": "true", children: "Loading posts\u2026" });
20
+ if (error)
21
+ return _jsx("p", { role: "alert", children: "We could not load the posts. Try again in a moment." });
22
+ if (!data?.items.length)
23
+ return _jsx("p", { children: "Nothing has been posted yet." });
24
+ return (_jsxs("div", { className: "grid gap-6", children: [_jsx("ul", { className: "grid gap-4", children: data.items.map((post) => (_jsx("li", { children: _jsxs(Card, { children: [post.values.cover ? (_jsx("img", { src: mediaUrl(post.values.cover.media, 640), alt: post.values.cover.alt, className: "w-full rounded-t-lg object-cover" })) : null, _jsxs(CardHeader, { children: [_jsx(CardTitle, { children: _jsx("a", { href: hrefOf(post.values.slug ?? ""), className: "hover:underline", children: post.values.title }) }), postDate(post) || post.values.byline ? (_jsx(CardDescription, { children: [postDate(post), post.values.byline].filter(Boolean).join(" · ") })) : null] }), _jsx(CardContent, { children: _jsx("p", { children: summary(post) }) })] }) }, post.id))) }), data.nextCursor && olderHref ? (_jsx(Button, { variant: "outline", asChild: true, children: _jsx("a", { href: olderHref(data.nextCursor), children: "Older posts" }) })) : null] }));
25
+ }
@@ -0,0 +1,28 @@
1
+ import { type Block, type RichText as RichTextValue } from "@composable-os/pack-content/client";
2
+ import type { ReactNode } from "react";
3
+ /** A block's own element, to replace the default one for its type. */
4
+ export type BlockRenderer<T extends Block["type"]> = (props: {
5
+ block: Extract<Block, {
6
+ type: T;
7
+ }>;
8
+ children?: ReactNode;
9
+ }) => ReactNode;
10
+ export interface RichTextProps {
11
+ value: RichTextValue | null | undefined;
12
+ /**
13
+ * Where a picture is: by default `/api/media/<id>?w=` on this site, which the client template's
14
+ * media route forwards to the host. `mediaBase` puts another origin in front; `mediaUrl`
15
+ * replaces the address altogether.
16
+ */
17
+ mediaUrl?: (id: string, width: number) => string;
18
+ mediaBase?: string;
19
+ /** The app's own element for any block type, in place of the one here. */
20
+ components?: {
21
+ [T in Block["type"]]?: BlockRenderer<T>;
22
+ };
23
+ className?: string;
24
+ }
25
+ /** A rich text document. An empty or missing one draws nothing. */
26
+ export declare function RichText({ value, mediaBase, mediaUrl, components, className, }: RichTextProps): import("react").JSX.Element | null;
27
+ /** A document's first paragraph as text, for a summary where the post has no excerpt. */
28
+ export declare function firstParagraph(value: RichTextValue | null | undefined): string;
@@ -0,0 +1,85 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // Rich text for the web (stage 28, ADR 0440): a post's body drawn block by block with React
3
+ // elements, never as HTML. Every block type and mark of the platform's schema has its element
4
+ // here; restyle them with the classes, or pass `components` to use the app's own for any of them.
5
+ //
6
+ // Nothing is injected as markup: text is React text (escaped by React), a link's address is the
7
+ // host's checked one, a picture is the host's media route, and a video is played from YouTube's
8
+ // or Vimeo's own player address built from the id, never from the raw URL. An embed that is
9
+ // neither is a link.
10
+ import { embedKind, embedPlayer, inlineText, mediaPath, } from "@composable-os/pack-content/client";
11
+ import { Button } from "../ui-button/button.js";
12
+ const WIDTHS = [640, 960, 1280];
13
+ /** One run of text with its marks, as nested elements. */
14
+ function Run({ run }) {
15
+ if (run.type === "break")
16
+ return _jsx("br", { "data-mark": "break" });
17
+ let node = run.text;
18
+ if (run.code)
19
+ node = _jsx("code", { "data-mark": "code", children: node });
20
+ if (run.italic)
21
+ node = _jsx("em", { "data-mark": "italic", children: node });
22
+ if (run.bold)
23
+ node = _jsx("strong", { "data-mark": "bold", children: node });
24
+ if (run.href) {
25
+ const external = /^https?:/.test(run.href);
26
+ node = (_jsx("a", { "data-mark": "link", href: run.href, className: "underline underline-offset-2", ...(external ? { rel: "noopener noreferrer" } : {}), children: node }));
27
+ }
28
+ return _jsx(_Fragment, { children: node });
29
+ }
30
+ function Runs({ content }) {
31
+ return (_jsx(_Fragment, { children: (content ?? []).map((run, i) => (_jsx(Run, { run: run }, i))) }));
32
+ }
33
+ function List({ body }) {
34
+ const items = body.items.map((item, i) => (_jsxs("li", { children: [_jsx(Runs, { content: item.content }), item.list ? _jsx(List, { body: item.list }) : null] }, i)));
35
+ return body.style === "ordered" ? (_jsx("ol", { "data-block": "list", "data-style": "ordered", className: "list-decimal pl-6", children: items })) : (_jsx("ul", { "data-block": "list", "data-style": "bullet", className: "list-disc pl-6", children: items }));
36
+ }
37
+ const TONES = {
38
+ info: "border-sky-500",
39
+ note: "border-muted-foreground",
40
+ success: "border-emerald-500",
41
+ warning: "border-amber-500",
42
+ };
43
+ function DefaultBlock({ block, mediaUrl, }) {
44
+ switch (block.type) {
45
+ case "paragraph":
46
+ return (_jsx("p", { "data-block": "paragraph", children: _jsx(Runs, { content: block.content }) }));
47
+ case "heading": {
48
+ // A post's title is its h1: the body's headings start one below it.
49
+ const level = Math.min(Math.max(block.level + 1, 2), 6);
50
+ const Tag = `h${level}`;
51
+ return (_jsx(Tag, { "data-block": "heading", "data-level": block.level, className: "font-semibold", children: _jsx(Runs, { content: block.content }) }));
52
+ }
53
+ case "list":
54
+ return _jsx(List, { body: block });
55
+ case "quote":
56
+ return (_jsxs("figure", { "data-block": "quote", children: [_jsx("blockquote", { className: "border-l-4 pl-4 italic", children: _jsx(Runs, { content: block.content }) }), block.attribution ? (_jsx("figcaption", { className: "text-muted-foreground", children: block.attribution })) : null] }));
57
+ case "image":
58
+ return (_jsxs("figure", { "data-block": "image", children: [_jsx("img", { src: mediaUrl(block.media, 960), srcSet: WIDTHS.map((w) => `${mediaUrl(block.media, w)} ${w}w`).join(", "), sizes: "(min-width: 768px) 768px, 100vw", alt: block.alt, loading: "lazy", className: "w-full rounded-lg" }), block.caption?.length ? (_jsx("figcaption", { className: "text-muted-foreground", children: _jsx(Runs, { content: block.caption }) })) : null] }));
59
+ case "divider":
60
+ return _jsx("hr", { "data-block": "divider" });
61
+ case "embed": {
62
+ const kind = embedKind(block.url);
63
+ return (_jsxs("figure", { "data-block": "embed", "data-embed": kind.kind, children: [kind.kind === "link" ? (_jsx("a", { href: block.url, rel: "noopener noreferrer", className: "underline", children: block.caption ?? block.url })) : (_jsx("iframe", { src: embedPlayer(kind), title: block.caption ?? (kind.kind === "youtube" ? "YouTube video" : "Vimeo video"), allow: "encrypted-media; picture-in-picture; fullscreen", sandbox: "allow-scripts allow-same-origin allow-presentation", loading: "lazy", className: "aspect-video w-full rounded-lg" })), block.caption && kind.kind !== "link" ? (_jsx("figcaption", { className: "text-muted-foreground", children: block.caption })) : null] }));
64
+ }
65
+ case "callout":
66
+ return (_jsx("aside", { "data-block": "callout", "data-tone": block.tone, role: "note", className: `rounded-lg border-l-4 bg-muted p-4 ${TONES[block.tone]}`, children: _jsx(Runs, { content: block.content }) }));
67
+ case "button":
68
+ return (_jsx("p", { "data-block": "button", children: _jsx(Button, { asChild: true, children: _jsx("a", { href: block.href, children: block.label }) }) }));
69
+ }
70
+ }
71
+ /** A rich text document. An empty or missing one draws nothing. */
72
+ export function RichText({ value, mediaBase = "", mediaUrl = (id, width) => mediaPath(id, width, mediaBase), components = {}, className, }) {
73
+ const blocks = value?.blocks ?? [];
74
+ if (!blocks.length)
75
+ return null;
76
+ return (_jsx("div", { className: className ?? "grid gap-4", "data-rich-text": "", children: blocks.map((block, i) => {
77
+ const custom = components[block.type];
78
+ return (_jsx("div", { className: "contents", children: custom ? (custom({ block })) : (_jsx(DefaultBlock, { block: block, mediaUrl: mediaUrl })) }, i));
79
+ }) }));
80
+ }
81
+ /** A document's first paragraph as text, for a summary where the post has no excerpt. */
82
+ export function firstParagraph(value) {
83
+ const first = value?.blocks.find((b) => b.type === "paragraph");
84
+ return first && first.type === "paragraph" ? inlineText(first.content) : "";
85
+ }