@rizom/brain-ui 0.0.0-stage → 0.2.0-alpha.650

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,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # @rizom/brain-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React components for Rizom Brain sites and plugin views. They render with the
4
+ selected theme's tokens (`text-theme`, `bg-theme-subtle`, `text-brand`), so a
5
+ section built from them follows whichever theme the brain runs.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ bun add @rizom/brain-ui
11
+ ```
12
+
13
+ `react` and `react-dom` are peer dependencies: the brain supplies the one React
14
+ tree a site renders into.
15
+
16
+ ## Components
17
+
18
+ | Export | Renders |
19
+ | ----------------- | ----------------------------------------------------------------------------------------------------------------------------- |
20
+ | `Card` | A card container, optionally a link (`href`), in a `vertical`, `horizontal` or `compact` variant |
21
+ | `CardTitle` | The card heading, optionally a link |
22
+ | `CardMetadata` | A metadata row under the title |
23
+ | `TagsList` | Tags as pills, truncated after `maxVisible` |
24
+ | `MarkdownContent` | Markdown as sanitized prose; in a brain's site build, `entity://image/<id>` references render as the build's optimized images |
25
+ | `formatDate` | A date as `short`, `medium`, `long` or `full` text, in `en-US` and UTC, optionally with the time |
26
+
27
+ Each component's props type is exported beside it (`CardProps`,
28
+ `CardTitleProps`, `CardMetadataProps`, `TagsListProps`,
29
+ `MarkdownContentProps`), as are `FormatDateOptions` and `DateFormatStyle`.
30
+
31
+ ```tsx
32
+ import {
33
+ Card,
34
+ CardMetadata,
35
+ CardTitle,
36
+ MarkdownContent,
37
+ TagsList,
38
+ formatDate,
39
+ } from "@rizom/brain-ui";
40
+
41
+ export function BookmarkCard(props: {
42
+ title: string;
43
+ url: string;
44
+ savedAt: string;
45
+ tags: string[];
46
+ note: string;
47
+ }) {
48
+ return (
49
+ <Card>
50
+ <CardTitle href={props.url}>{props.title}</CardTitle>
51
+ <CardMetadata>
52
+ Saved {formatDate(props.savedAt, { style: "medium" })}
53
+ </CardMetadata>
54
+ <TagsList tags={props.tags} />
55
+ <MarkdownContent markdown={props.note} />
56
+ </Card>
57
+ );
58
+ }
59
+ ```
60
+
61
+ ## License
62
+
63
+ Apache-2.0. See [`LICENSE`](./LICENSE).
@@ -0,0 +1,168 @@
1
+ import { JSX, ReactNode } from "react";
2
+ //#region src/variant-types.d.ts
3
+ type VariantValue<T extends number | string> = T | null | undefined;
4
+ //#endregion
5
+ //#region src/Card.d.ts
6
+ type CardVariant = "vertical" | "horizontal" | "compact";
7
+ interface CardVariantProps {
8
+ variant?: VariantValue<CardVariant>;
9
+ }
10
+ interface CardProps extends CardVariantProps {
11
+ href?: string | undefined;
12
+ className?: string;
13
+ children: ReactNode;
14
+ }
15
+ /**
16
+ * Generic card container component used across blog posts, decks, links, and other content.
17
+ *
18
+ * Provides consistent styling with support for vertical (default), horizontal, and compact layouts.
19
+ * Can optionally be wrapped in a link for clickable cards.
20
+ *
21
+ * @example Vertical card (default)
22
+ * ```tsx
23
+ * <Card>
24
+ * <CardImage src="..." alt="..." size="large" />
25
+ * <CardTitle>Title</CardTitle>
26
+ * <CardMetadata>Author • Date</CardMetadata>
27
+ * </Card>
28
+ * ```
29
+ *
30
+ * @example Horizontal card with link
31
+ * ```tsx
32
+ * <Card variant="horizontal" href="/post/slug">
33
+ * <CardImage src="..." alt="..." size="small" />
34
+ * <div>
35
+ * <CardTitle>Title</CardTitle>
36
+ * <CardMetadata>Metadata</CardMetadata>
37
+ * </div>
38
+ * </Card>
39
+ * ```
40
+ */
41
+ declare const Card: ({ href, variant, className, children }: CardProps) => JSX.Element;
42
+ //#endregion
43
+ //#region src/CardMetadata.d.ts
44
+ interface CardMetadataProps {
45
+ children: ReactNode;
46
+ className?: string;
47
+ }
48
+ /**
49
+ * Flexible metadata container for card components.
50
+ *
51
+ * Provides consistent styling for metadata sections like dates, authors,
52
+ * tags, categories, or any other supplementary information.
53
+ *
54
+ * This is a generic container - plugins can compose it with their own
55
+ * specific metadata components (like PostMetadata, DeckMetadata, etc.)
56
+ *
57
+ * @example With PostMetadata
58
+ * ```tsx
59
+ * <CardMetadata>
60
+ * <PostMetadata author="..." publishedAt="..." status="..." />
61
+ * </CardMetadata>
62
+ * ```
63
+ *
64
+ * @example With custom content
65
+ * ```tsx
66
+ * <CardMetadata>
67
+ * <div className="text-sm text-brand">
68
+ * Series: Ecosystem Architecture - Part 5
69
+ * </div>
70
+ * </CardMetadata>
71
+ * ```
72
+ */
73
+ declare const CardMetadata: ({ children, className }: CardMetadataProps) => JSX.Element;
74
+ //#endregion
75
+ //#region src/CardTitle.d.ts
76
+ interface CardTitleProps {
77
+ href?: string;
78
+ children: ReactNode;
79
+ className?: string;
80
+ }
81
+ /**
82
+ * Card title component with optional link.
83
+ *
84
+ * Renders as a styled heading with consistent typography.
85
+ * If href is provided, wraps the title in a link with hover effects.
86
+ *
87
+ * @example Title without link
88
+ * ```tsx
89
+ * <CardTitle>My Post Title</CardTitle>
90
+ * ```
91
+ *
92
+ * @example Title with link
93
+ * ```tsx
94
+ * <CardTitle href="/posts/my-post">My Post Title</CardTitle>
95
+ * ```
96
+ */
97
+ declare const CardTitle: ({ href, children, className }: CardTitleProps) => JSX.Element;
98
+ //#endregion
99
+ //#region src/MarkdownContent.d.ts
100
+ interface MarkdownContentProps {
101
+ markdown: string;
102
+ className?: string;
103
+ }
104
+ /**
105
+ * Renders markdown content with image optimization support.
106
+ *
107
+ * Combines `markdownToHtml` conversion with `ProseContent` rendering.
108
+ * When rendered inside an `ImageRendererProvider` (during site builds),
109
+ * entity://image references are automatically resolved to optimized
110
+ * `<img srcset="...">` tags.
111
+ *
112
+ * Replaces the common pattern:
113
+ * ```tsx
114
+ * const htmlContent = markdownToHtml(post.body);
115
+ * <ProseContent html={htmlContent} />
116
+ * ```
117
+ *
118
+ * With:
119
+ * ```tsx
120
+ * <MarkdownContent markdown={post.body} />
121
+ * ```
122
+ */
123
+ declare const MarkdownContent: ({ markdown, className }: MarkdownContentProps) => JSX.Element;
124
+ //#endregion
125
+ //#region src/TagsList.d.ts
126
+ interface TagVariantProps {
127
+ variant?: VariantValue<"default" | "muted" | "accent">;
128
+ size?: VariantValue<"xs" | "sm" | "md" | "lg">;
129
+ }
130
+ interface TagsListProps extends TagVariantProps {
131
+ tags: string[];
132
+ maxVisible?: number;
133
+ className?: string;
134
+ }
135
+ /**
136
+ * TagsList component - displays a list of tags/keywords with optional truncation
137
+ *
138
+ * @example
139
+ * ```tsx
140
+ * <TagsList tags={link.keywords} maxVisible={4} />
141
+ * ```
142
+ */
143
+ declare const TagsList: ({ tags, maxVisible, variant, size, className }: TagsListProps) => JSX.Element;
144
+ //#endregion
145
+ //#region src/utils/formatDate.d.ts
146
+ type DateFormatStyle = "short" | "medium" | "long" | "full";
147
+ interface FormatDateOptions {
148
+ style?: DateFormatStyle;
149
+ includeTime?: boolean;
150
+ }
151
+ /**
152
+ * Format a date string or Date object for display
153
+ *
154
+ * @param date - Date string or Date object to format
155
+ * @param options - Formatting options
156
+ * @returns Formatted date string
157
+ *
158
+ * @example
159
+ * ```tsx
160
+ * formatDate("2024-01-15") // "1/15/2024"
161
+ * formatDate("2024-01-15", { style: "medium" }) // "Jan 15, 2024"
162
+ * formatDate("2024-01-15", { style: "long" }) // "January 15, 2024"
163
+ * formatDate(date, { style: "long", includeTime: true }) // "January 15, 2024 at 3:30 PM"
164
+ * ```
165
+ */
166
+ declare const formatDate: (date: string | Date, options?: FormatDateOptions) => string;
167
+ //#endregion
168
+ export { Card, CardMetadata, type CardMetadataProps, type CardProps, CardTitle, type CardTitleProps, type DateFormatStyle, type FormatDateOptions, MarkdownContent, type MarkdownContentProps, TagsList, type TagsListProps, formatDate };
package/dist/index.js ADDED
@@ -0,0 +1,349 @@
1
+ // src/Card.tsx
2
+ import { cva } from "class-variance-authority";
3
+
4
+ // src/lib/utils.ts
5
+ import { clsx } from "clsx";
6
+ import { extendTailwindMerge } from "tailwind-merge";
7
+ var twMerge = extendTailwindMerge({
8
+ extend: {
9
+ classGroups: {
10
+ "font-size": [
11
+ {
12
+ text: [
13
+ "display-2xl",
14
+ "display-xl",
15
+ "display-lg",
16
+ "display-md",
17
+ "display-sm",
18
+ "heading-lg",
19
+ "heading-md",
20
+ "heading-sm",
21
+ "body-xl",
22
+ "body-lg",
23
+ "body-md",
24
+ "body-sm",
25
+ "body-xs",
26
+ "label-md",
27
+ "label-sm",
28
+ "label-xs"
29
+ ]
30
+ }
31
+ ]
32
+ }
33
+ }
34
+ });
35
+ function cn(...inputs) {
36
+ return twMerge(clsx(inputs));
37
+ }
38
+
39
+ // src/Card.tsx
40
+ import { jsx } from "react/jsx-runtime";
41
+ var cardVariants = cva("bg-theme-subtle rounded-lg border border-theme hover:shadow-lg transition-shadow", {
42
+ variants: {
43
+ variant: {
44
+ vertical: "flex flex-col p-6",
45
+ horizontal: "flex flex-col sm:flex-row items-start gap-4 p-6",
46
+ compact: "flex flex-col p-4"
47
+ }
48
+ },
49
+ defaultVariants: {
50
+ variant: "vertical"
51
+ }
52
+ });
53
+ var Card = ({
54
+ href,
55
+ variant,
56
+ className,
57
+ children
58
+ }) => {
59
+ const classes = cn(cardVariants({ variant }), className);
60
+ if (href) {
61
+ return /* @__PURE__ */ jsx("article", {
62
+ className: cn(classes, "group"),
63
+ children: /* @__PURE__ */ jsx("a", {
64
+ href,
65
+ className: "contents",
66
+ children
67
+ })
68
+ });
69
+ }
70
+ return /* @__PURE__ */ jsx("article", {
71
+ className: classes,
72
+ children
73
+ });
74
+ };
75
+ // src/CardMetadata.tsx
76
+ import { jsx as jsx2 } from "react/jsx-runtime";
77
+ var CardMetadata = ({
78
+ children,
79
+ className
80
+ }) => {
81
+ return /* @__PURE__ */ jsx2("div", {
82
+ className: cn("mb-3", className),
83
+ children
84
+ });
85
+ };
86
+ // src/CardTitle.tsx
87
+ import { jsx as jsx3 } from "react/jsx-runtime";
88
+ var CardTitle = ({
89
+ href,
90
+ children,
91
+ className
92
+ }) => {
93
+ const baseClasses = cn("text-2xl font-semibold mb-2 text-theme", className);
94
+ if (href) {
95
+ return /* @__PURE__ */ jsx3("h2", {
96
+ className: baseClasses,
97
+ children: /* @__PURE__ */ jsx3("a", {
98
+ href,
99
+ className: "hover:text-brand",
100
+ children
101
+ })
102
+ });
103
+ }
104
+ return /* @__PURE__ */ jsx3("h2", {
105
+ className: baseClasses,
106
+ children
107
+ });
108
+ };
109
+ // src/ProseContent.tsx
110
+ import { jsx as jsx4 } from "react/jsx-runtime";
111
+ var ProseContent = ({
112
+ html,
113
+ className
114
+ }) => {
115
+ return /* @__PURE__ */ jsx4("article", {
116
+ className: cn(`prose prose-lg max-w-none
117
+ prose-h1:text-4xl prose-h1:font-bold prose-h1:mb-8 prose-h1:mt-0
118
+ prose-h2:text-3xl prose-h2:font-semibold prose-h2:mt-16 prose-h2:mb-6 prose-h2:border-b prose-h2:pb-4
119
+ prose-h3:text-2xl prose-h3:font-semibold prose-h3:mt-10 prose-h3:mb-4
120
+ prose-p:text-lg prose-p:leading-relaxed prose-p:mb-6
121
+ prose-ul:my-6 prose-ul:space-y-3
122
+ prose-ol:my-6 prose-ol:space-y-3
123
+ prose-li:leading-relaxed
124
+ prose-code:px-1.5 prose-code:py-0.5 prose-code:rounded prose-code:text-sm prose-code:font-mono
125
+ prose-pre:rounded-lg prose-pre:my-6 prose-pre:p-4 prose-pre:overflow-x-auto prose-pre:text-sm
126
+ prose-blockquote:border-l-2 prose-blockquote:border-brand prose-blockquote:pl-6 prose-blockquote:py-2 prose-blockquote:mt-8 prose-blockquote:mb-2 prose-blockquote:text-lg prose-blockquote:leading-relaxed prose-blockquote:font-light prose-blockquote:not-italic
127
+ prose-hr:my-12
128
+ prose-img:rounded-lg prose-img:shadow-md prose-img:my-8`, className),
129
+ dangerouslySetInnerHTML: { __html: html }
130
+ });
131
+ };
132
+
133
+ // src/ImageRendererProvider.tsx
134
+ import { createElement as h } from "react";
135
+ import { useContext } from "react";
136
+
137
+ // src/markdown-html.ts
138
+ import { Marked } from "marked";
139
+ import sanitizeHtml from "sanitize-html";
140
+ var defaultMarked = new Marked({ gfm: true, breaks: true });
141
+ var SANITIZE_OPTIONS = {
142
+ allowedTags: [
143
+ "h1",
144
+ "h2",
145
+ "h3",
146
+ "h4",
147
+ "h5",
148
+ "h6",
149
+ "p",
150
+ "br",
151
+ "hr",
152
+ "ul",
153
+ "ol",
154
+ "li",
155
+ "blockquote",
156
+ "cite",
157
+ "code",
158
+ "pre",
159
+ "em",
160
+ "strong",
161
+ "del",
162
+ "ins",
163
+ "sub",
164
+ "sup",
165
+ "a",
166
+ "img",
167
+ "span",
168
+ "table",
169
+ "thead",
170
+ "tbody",
171
+ "tr",
172
+ "th",
173
+ "td",
174
+ "div"
175
+ ],
176
+ allowedAttributes: {
177
+ a: ["href", "title", "name"],
178
+ img: [
179
+ "src",
180
+ "srcset",
181
+ "sizes",
182
+ "alt",
183
+ "title",
184
+ "width",
185
+ "height",
186
+ "class",
187
+ "loading",
188
+ "decoding"
189
+ ],
190
+ code: ["class"],
191
+ pre: ["class"],
192
+ span: ["class"],
193
+ cite: ["class"],
194
+ div: ["class"],
195
+ th: ["align", "colspan", "rowspan", "scope"],
196
+ td: ["align", "colspan", "rowspan"]
197
+ },
198
+ allowedSchemes: ["http", "https", "mailto", "tel"],
199
+ allowedSchemesByTag: {
200
+ img: ["http", "https", "entity"]
201
+ },
202
+ allowProtocolRelative: false,
203
+ disallowedTagsMode: "discard"
204
+ };
205
+ function markdownToHtml(markdown, options) {
206
+ const { imageRenderer } = options ?? {};
207
+ const instance = imageRenderer ? new Marked({ gfm: true, breaks: true }).use({
208
+ renderer: {
209
+ image({ href, title, text }) {
210
+ return imageRenderer({
211
+ href,
212
+ alt: text,
213
+ ...title !== null ? { title } : {}
214
+ }) ?? false;
215
+ }
216
+ }
217
+ }) : defaultMarked;
218
+ const parsed = instance.parse(markdown);
219
+ if (typeof parsed !== "string") {
220
+ throw new Error("Markdown renderer received an async marked result");
221
+ }
222
+ let html = parsed;
223
+ html = html.replace(/<\/blockquote>\s*<p>(—|--|–)([\s\S]*?)<\/p>/g, `</blockquote>
224
+ <cite class="block-attribution"><span class="emdash">$1</span>$2</cite>`);
225
+ return sanitizeHtml(html, SANITIZE_OPTIONS);
226
+ }
227
+
228
+ // src/shared-context.ts
229
+ import { createContext } from "react";
230
+ function sharedContext(key, defaultValue) {
231
+ const symbol = Symbol.for(`@rizom/brain-ui/${key}`);
232
+ const existing = Reflect.get(globalThis, symbol);
233
+ if (existing !== undefined) {
234
+ return existing;
235
+ }
236
+ const context = createContext(defaultValue);
237
+ Object.defineProperty(globalThis, symbol, {
238
+ value: context,
239
+ enumerable: false,
240
+ configurable: false,
241
+ writable: false
242
+ });
243
+ return context;
244
+ }
245
+
246
+ // src/ImageRendererProvider.tsx
247
+ var ImageRendererContext = sharedContext("image-renderer@1", null);
248
+ function useImageRenderer() {
249
+ return useContext(ImageRendererContext);
250
+ }
251
+ function useMarkdownToHtml() {
252
+ const imageRenderer = useImageRenderer();
253
+ return (markdown) => markdownToHtml(markdown, imageRenderer ? { imageRenderer } : undefined);
254
+ }
255
+
256
+ // src/MarkdownContent.tsx
257
+ import { jsx as jsx5 } from "react/jsx-runtime";
258
+ var MarkdownContent = ({
259
+ markdown,
260
+ className
261
+ }) => {
262
+ const toHtml = useMarkdownToHtml();
263
+ return /* @__PURE__ */ jsx5(ProseContent, {
264
+ html: toHtml(markdown),
265
+ ...className && { className }
266
+ });
267
+ };
268
+ // src/TagsList.tsx
269
+ import { cva as cva2 } from "class-variance-authority";
270
+ import { jsx as jsx6, jsxs } from "react/jsx-runtime";
271
+ var tagVariants = cva2("rounded-full", {
272
+ variants: {
273
+ variant: {
274
+ default: "bg-theme-muted text-theme",
275
+ muted: "bg-theme text-theme-muted",
276
+ accent: "bg-accent/10 text-accent"
277
+ },
278
+ size: {
279
+ xs: "text-xs px-2 py-1",
280
+ sm: "text-sm px-3 py-1",
281
+ md: "text-sm px-3 py-1 font-medium",
282
+ lg: "text-sm px-4 py-2 font-medium"
283
+ }
284
+ },
285
+ defaultVariants: {
286
+ variant: "default",
287
+ size: "xs"
288
+ }
289
+ });
290
+ var TagsList = ({
291
+ tags,
292
+ maxVisible = 5,
293
+ variant,
294
+ size,
295
+ className
296
+ }) => {
297
+ const visibleTags = tags.slice(0, maxVisible);
298
+ const remainingCount = tags.length - maxVisible;
299
+ return /* @__PURE__ */ jsxs("div", {
300
+ className: cn("flex flex-wrap gap-2", className),
301
+ children: [
302
+ visibleTags.map((tag) => /* @__PURE__ */ jsx6("span", {
303
+ className: cn(tagVariants({ variant, size })),
304
+ children: tag
305
+ }, tag)),
306
+ remainingCount > 0 && /* @__PURE__ */ jsxs("span", {
307
+ className: cn(tagVariants({ size }), "bg-transparent text-theme-muted"),
308
+ children: [
309
+ "+",
310
+ remainingCount,
311
+ " more"
312
+ ]
313
+ })
314
+ ]
315
+ });
316
+ };
317
+ // src/utils/formatDate.ts
318
+ var LOCALE = "en-US";
319
+ var TIME_ZONE = "UTC";
320
+ var STYLE_OPTIONS = {
321
+ short: { year: "numeric", month: "numeric", day: "numeric" },
322
+ medium: { year: "numeric", month: "short", day: "numeric" },
323
+ long: { year: "numeric", month: "long", day: "numeric" },
324
+ full: { weekday: "long", year: "numeric", month: "long", day: "numeric" }
325
+ };
326
+ var formatDate = (date, options = {}) => {
327
+ const { style = "short", includeTime = false } = options;
328
+ const dateObj = typeof date === "string" ? new Date(date) : date;
329
+ if (includeTime) {
330
+ return dateObj.toLocaleString(LOCALE, {
331
+ ...STYLE_OPTIONS[style],
332
+ hour: "numeric",
333
+ minute: "2-digit",
334
+ timeZone: TIME_ZONE
335
+ });
336
+ }
337
+ return dateObj.toLocaleDateString(LOCALE, {
338
+ ...STYLE_OPTIONS[style],
339
+ timeZone: TIME_ZONE
340
+ });
341
+ };
342
+ export {
343
+ Card,
344
+ CardMetadata,
345
+ CardTitle,
346
+ MarkdownContent,
347
+ TagsList,
348
+ formatDate
349
+ };
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@rizom/brain-ui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0-alpha.650",
4
+ "description": "React components for Rizom Brain sites and plugin views",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "import": "./dist/index.js"
10
+ }
11
+ },
12
+ "main": "./dist/index.js",
13
+ "types": "./dist/index.d.ts",
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "bun scripts/build.ts",
19
+ "typecheck": "tsc --noEmit",
20
+ "test": "bun test",
21
+ "lint": "eslint . --max-warnings 0",
22
+ "lint:fix": "eslint . --max-warnings 0 --fix",
23
+ "prepack": "publish-manifest prepare",
24
+ "prepublishOnly": "bun scripts/build.ts"
25
+ },
26
+ "dependencies": {
27
+ "class-variance-authority": "^0.7.0",
28
+ "clsx": "^2.1.0",
29
+ "marked": "^18.0.5",
30
+ "sanitize-html": "^2.18.0",
31
+ "tailwind-merge": "^3.6.0"
32
+ },
33
+ "peerDependencies": {
34
+ "react": "^19.2.7",
35
+ "react-dom": "^19.2.7"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/rizom-ai/brains.git",
43
+ "directory": "packages/ui"
44
+ },
45
+ "license": "Apache-2.0",
46
+ "author": "Yeehaa <yeehaa@rizom.ai> (https://rizom.ai)",
47
+ "homepage": "https://github.com/rizom-ai/brains/tree/main/packages/ui#readme",
48
+ "bugs": {
49
+ "url": "https://github.com/rizom-ai/brains/issues"
50
+ },
51
+ "engines": {
52
+ "bun": ">=1.3.3"
53
+ }
54
+ }