@contentbit/react 0.4.1 → 0.5.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/README.md CHANGED
@@ -1,16 +1,19 @@
1
1
  # @contentbit/react
2
2
 
3
- React renderer for [Content Blocks](https://contentbit.dev) documents, with headless accessible defaults for every generic block.
3
+ Headless React renderer for [Content Blocks](https://contentbit.dev) documents.
4
4
 
5
5
  ```tsx
6
6
  import { ContentBlocks } from '@contentbit/react'
7
7
 
8
8
  <ContentBlocks
9
9
  document={result.document}
10
+ components={{ callout: CalloutBlock }}
10
11
  renderMarkdown={(md) => <Markdown source={md} />}
11
12
  />
12
13
  ```
13
14
 
14
- Pass `components` to override any block. A styled Tailwind pack is available through the shadcn registry: `pnpm dlx shadcn@latest add @contentbit/generic-pack`.
15
+ `components` maps block names to React components. A styled Tailwind pack is
16
+ available through the shadcn registry, where files are copied into your app:
17
+ `pnpm dlx shadcn@latest add @contentbit/generic-pack`.
15
18
 
16
19
  Docs: [contentbit.dev/docs](https://contentbit.dev/docs)
@@ -1,4 +1,4 @@
1
- import type { ContentNode, DocumentNode, ValidatedBlockNode } from '@contentbit/core';
1
+ import type { ContentNode, ValidatedBlockNode, ValidatedDocumentNode } from '@contentbit/core';
2
2
  import type { ComponentType, ReactNode } from 'react';
3
3
  export interface BlockRenderContext {
4
4
  renderMarkdown(md: string): ReactNode;
@@ -10,8 +10,8 @@ export interface BlockComponentProps<TData = unknown> {
10
10
  }
11
11
  export type BlockComponent = ComponentType<BlockComponentProps>;
12
12
  export interface ContentBlocksProps {
13
- document: DocumentNode;
14
- /** Per-block components; merged over the headless defaults. */
13
+ document: ValidatedDocumentNode;
14
+ /** Per-block components, keyed by block name. */
15
15
  components?: Record<string, BlockComponent>;
16
16
  /** Host markdown renderer for prose segments. Default: paragraphs of plain text. */
17
17
  renderMarkdown?: (md: string) => ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"content-blocks.d.ts","sourceRoot":"","sources":["../src/content-blocks.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAuBrD,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,SAAS,CAAA;CAC7C;AAED,MAAM,WAAW,mBAAmB,CAAC,KAAK,GAAG,OAAO;IAClD,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC/B,GAAG,EAAE,kBAAkB,CAAA;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAA;AAE/D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,YAAY,CAAA;IACtB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAC3C,oFAAoF;IACpF,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAA;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACzD;AAaD,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAqBlE"}
1
+ {"version":3,"file":"content-blocks.d.ts","sourceRoot":"","sources":["../src/content-blocks.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAqBrD,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,SAAS,CAAA;CAC7C;AAED,MAAM,WAAW,mBAAmB,CAAC,KAAK,GAAG,OAAO;IAClD,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAA;IAC/B,GAAG,EAAE,kBAAkB,CAAA;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAA;AAE/D,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,iDAAiD;IACjD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;IAC3C,oFAAoF;IACpF,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAA;IAC1C,oFAAoF;IACpF,QAAQ,CAAC,EAAE,aAAa,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACzD;AAaD,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,SAAS,CAqBlE"}
@@ -2,7 +2,6 @@
2
2
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
3
  import { isValidatedBlock } from '@contentbit/core';
4
4
  import { Fragment } from 'react';
5
- import { defaultComponents } from './components.js';
6
5
  // Warn once per block name in development when a valid block has no component.
7
6
  const warned = new Set();
8
7
  function warnMissingComponent(name) {
@@ -22,7 +21,7 @@ function DefaultFallback({ body }) {
22
21
  return _jsx(DefaultMarkdown, { md: body });
23
22
  }
24
23
  export function ContentBlocks(props) {
25
- const components = { ...defaultComponents, ...props.components };
24
+ const components = props.components ?? {};
26
25
  const renderMarkdown = props.renderMarkdown ?? ((md) => _jsx(DefaultMarkdown, { md: md }));
27
26
  const Fallback = props.fallback ?? DefaultFallback;
28
27
  const ctx = {
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { ContentBlocks, type BlockComponent, type BlockComponentProps, type BlockRenderContext, type ContentBlocksProps, } from './content-blocks.js';
2
- export { defaultComponents } from './components.js';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { ContentBlocks, } from './content-blocks.js';
2
- export { defaultComponents } from './components.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentbit/react",
3
- "version": "0.4.1",
4
- "description": "React renderer for Content Blocks documents, with headless accessible defaults.",
3
+ "version": "0.5.0",
4
+ "description": "Headless React renderer for validated Contentbit documents.",
5
5
  "keywords": [
6
6
  "content-blocks",
7
7
  "headless",
@@ -32,8 +32,7 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@contentbit/blocks": "0.4.1",
36
- "@contentbit/core": "0.4.1"
35
+ "@contentbit/core": "0.5.0"
37
36
  },
38
37
  "devDependencies": {
39
38
  "@testing-library/react": "^16.3.0",
@@ -42,7 +41,8 @@
42
41
  "react": "^19.2.3",
43
42
  "react-dom": "^19.2.3",
44
43
  "typescript": "^5.9.3",
45
- "vitest": "^4.0.17"
44
+ "vitest": "^4.0.17",
45
+ "@contentbit/blocks": "0.5.0"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "react": "^19.0.0"
@@ -1,3 +0,0 @@
1
- import type { BlockComponent } from './content-blocks.js';
2
- export declare const defaultComponents: Record<string, BlockComponent>;
3
- //# sourceMappingURL=components.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components.d.ts","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AA+JzD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAS5D,CAAA"}
@@ -1,55 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { splitProsCons } from '@contentbit/blocks';
4
- import { isValidatedBlock } from '@contentbit/core';
5
- import { useId, useState } from 'react';
6
- function childMarkdown(node) {
7
- return isValidatedBlock(node) ? node.data.markdown : node.body;
8
- }
9
- const Callout = ({ node, ctx }) => {
10
- const data = node.data;
11
- const type = String(node.props.type ?? 'note');
12
- const title = node.props.title;
13
- return (_jsxs("aside", { className: `cb-callout cb-callout-${type}`, children: [title ? _jsx("div", { className: "cb-callout-title", children: title }) : null, ctx.renderMarkdown(data.markdown)] }));
14
- };
15
- const Steps = ({ node }) => {
16
- const data = node.data;
17
- return (_jsx("ol", { className: "cb-steps", children: data.items.map((item, i) => (_jsx("li", { children: item.text }, i))) }));
18
- };
19
- const KeyMetrics = ({ node }) => {
20
- const data = node.data;
21
- return (_jsx("div", { className: "cb-key-metrics", children: data.rows.map((row, i) => (_jsxs("div", { className: "cb-key-metrics-item", children: [_jsx("span", { className: "cb-key-metrics-value", children: row.value }), _jsx("span", { className: "cb-key-metrics-label", children: row.label })] }, i))) }));
22
- };
23
- const QuickRef = ({ node }) => {
24
- const data = node.data;
25
- return (_jsx("dl", { className: "cb-quick-ref", children: data.rows.map((row, i) => (_jsxs("div", { className: "cb-quick-ref-row", children: [_jsx("dt", { children: row.key }), _jsx("dd", { children: row.value })] }, i))) }));
26
- };
27
- const Comparison = ({ node }) => {
28
- const data = node.data;
29
- return (_jsxs("table", { className: "cb-comparison", children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col" }), _jsx("th", { scope: "col", children: String(node.props.left) }), _jsx("th", { scope: "col", children: String(node.props.right) })] }) }), _jsx("tbody", { children: data.rows.map((row, i) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: row.label }), _jsx("td", { children: row.left }), _jsx("td", { children: row.right })] }, i))) })] }));
30
- };
31
- const ProsCons = ({ node }) => {
32
- const { pros, cons } = splitProsCons(node.data);
33
- return (_jsxs("div", { className: "cb-pros-cons", children: [_jsxs("div", { className: "cb-pros-cons-pros", children: [_jsx("div", { className: "cb-pros-cons-heading", children: "Pros" }), _jsx("ul", { children: pros.map((p, i) => (_jsx("li", { children: p }, i))) })] }), _jsxs("div", { className: "cb-pros-cons-cons", children: [_jsx("div", { className: "cb-pros-cons-heading", children: "Cons" }), _jsx("ul", { children: cons.map((c, i) => (_jsx("li", { children: c }, i))) })] })] }));
34
- };
35
- const Tabs = ({ node, ctx }) => {
36
- const data = node.data;
37
- const [active, setActive] = useState(0);
38
- const safeActive = active < data.blocks.length ? active : 0;
39
- const id = useId();
40
- return (_jsxs("div", { className: "cb-tabs", children: [_jsx("div", { role: "tablist", className: "cb-tab-bar", children: data.blocks.map((tab, i) => (_jsx("button", { type: "button", role: "tab", id: `${id}-tab-${i}`, "aria-selected": i === safeActive, "aria-controls": `${id}-panel-${i}`, className: "cb-tab-button", onClick: () => setActive(i), children: String(tab.props.title) }, i))) }), data.blocks.map((tab, i) => i === safeActive ? (_jsx("div", { role: "tabpanel", id: `${id}-panel-${i}`, "aria-labelledby": `${id}-tab-${i}`, className: "cb-tab-panel", children: ctx.renderMarkdown(childMarkdown(tab)) }, i)) : null)] }));
41
- };
42
- const Faq = ({ node, ctx }) => {
43
- const data = node.data;
44
- return (_jsx("div", { className: "cb-faq", children: data.blocks.map((item, i) => (_jsxs("details", { className: "cb-faq-item", children: [_jsx("summary", { children: String(item.props.question) }), ctx.renderMarkdown(childMarkdown(item))] }, i))) }));
45
- };
46
- export const defaultComponents = {
47
- callout: Callout,
48
- steps: Steps,
49
- 'key-metrics': KeyMetrics,
50
- 'quick-ref': QuickRef,
51
- comparison: Comparison,
52
- 'pros-cons': ProsCons,
53
- tabs: Tabs,
54
- faq: Faq,
55
- };