@contentbit/react 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -2
- package/dist/content-blocks.d.ts +13 -4
- package/dist/content-blocks.d.ts.map +1 -1
- package/dist/content-blocks.js +8 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -3,15 +3,23 @@
|
|
|
3
3
|
Headless React renderer for [Content Blocks](https://contentbit.dev) documents.
|
|
4
4
|
|
|
5
5
|
```tsx
|
|
6
|
-
import { ContentBlocks } from '@contentbit/react'
|
|
6
|
+
import { defineBlockComponent, defineBlockComponents, ContentBlocks } from '@contentbit/react'
|
|
7
|
+
|
|
8
|
+
const CalloutBlock = defineBlockComponent(calloutBlock, ({ node, ctx }) => (
|
|
9
|
+
<aside>{ctx.renderMarkdown(node.data.markdown)}</aside>
|
|
10
|
+
))
|
|
11
|
+
const components = defineBlockComponents([calloutBlock], { callout: CalloutBlock })
|
|
7
12
|
|
|
8
13
|
<ContentBlocks
|
|
9
14
|
document={result.document}
|
|
10
|
-
components={
|
|
15
|
+
components={components}
|
|
11
16
|
renderMarkdown={(md) => <Markdown source={md} />}
|
|
12
17
|
/>
|
|
13
18
|
```
|
|
14
19
|
|
|
20
|
+
The helpers infer the block name, validated Zod props, and parsed content data,
|
|
21
|
+
and reject misspelled component-map keys.
|
|
22
|
+
|
|
15
23
|
`components` maps block names to React components. A styled Tailwind pack is
|
|
16
24
|
available through the shadcn registry, where files are copied into your app:
|
|
17
25
|
`pnpm dlx shadcn@latest add @contentbit/generic-pack`.
|
package/dist/content-blocks.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
|
-
import type { ContentNode,
|
|
1
|
+
import type { BlockData, BlockDefinition, BlockName, BlockProps, BlockPropsOf, ContentNode, ProcessedDocumentNode, ValidatedBlockNode } from '@contentbit/core';
|
|
2
2
|
import type { ComponentType, ReactNode } from 'react';
|
|
3
3
|
export interface BlockRenderContext {
|
|
4
4
|
renderMarkdown(md: string): ReactNode;
|
|
5
5
|
renderNodes(nodes: ContentNode[]): ReactNode;
|
|
6
6
|
}
|
|
7
|
-
export interface BlockComponentProps<TData = unknown> {
|
|
8
|
-
node: ValidatedBlockNode<TData>;
|
|
7
|
+
export interface BlockComponentProps<TData = unknown, TProps extends BlockProps = BlockProps, TName extends string = string> {
|
|
8
|
+
node: ValidatedBlockNode<TData, TProps, TName>;
|
|
9
9
|
ctx: BlockRenderContext;
|
|
10
10
|
}
|
|
11
11
|
export type BlockComponent = ComponentType<BlockComponentProps>;
|
|
12
|
+
export type BlockComponentFor<TDefinition extends BlockDefinition> = ComponentType<BlockComponentProps<BlockData<TDefinition>, BlockPropsOf<TDefinition>, BlockName<TDefinition>>>;
|
|
13
|
+
export type BlockComponentsFor<TDefinitions extends ReadonlyArray<BlockDefinition>> = {
|
|
14
|
+
[TDefinition in TDefinitions[number] as BlockName<TDefinition>]?: BlockComponentFor<TDefinition>;
|
|
15
|
+
};
|
|
16
|
+
/** Preserve a block definition's inferred name, props, and data in its React adapter. */
|
|
17
|
+
export declare function defineBlockComponent<TDefinition extends BlockDefinition>(_definition: TDefinition, component: BlockComponentFor<TDefinition>): BlockComponentFor<TDefinition>;
|
|
18
|
+
/** Check component keys against a block pack and return a renderer-ready map. */
|
|
19
|
+
export declare function defineBlockComponents<const TDefinitions extends ReadonlyArray<BlockDefinition>>(_definitions: TDefinitions, components: BlockComponentsFor<TDefinitions>): Record<string, BlockComponent>;
|
|
12
20
|
export interface ContentBlocksProps {
|
|
13
|
-
document
|
|
21
|
+
/** A processed document; invalid blocks flow through `fallback`. */
|
|
22
|
+
document: ProcessedDocumentNode;
|
|
14
23
|
/** Per-block components, keyed by block name. */
|
|
15
24
|
components?: Record<string, BlockComponent>;
|
|
16
25
|
/** Host markdown renderer for prose segments. Default: paragraphs of plain text. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-blocks.d.ts","sourceRoot":"","sources":["../src/content-blocks.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"content-blocks.d.ts","sourceRoot":"","sources":["../src/content-blocks.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,eAAe,EACf,SAAS,EACT,UAAU,EACV,YAAY,EACZ,WAAW,EACX,qBAAqB,EACrB,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AACzB,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,CAClC,KAAK,GAAG,OAAO,EACf,MAAM,SAAS,UAAU,GAAG,UAAU,EACtC,KAAK,SAAS,MAAM,GAAG,MAAM;IAE7B,IAAI,EAAE,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;IAC9C,GAAG,EAAE,kBAAkB,CAAA;CACxB;AAED,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC,mBAAmB,CAAC,CAAA;AAE/D,MAAM,MAAM,iBAAiB,CAAC,WAAW,SAAS,eAAe,IAAI,aAAa,CAChF,mBAAmB,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC,CAC/F,CAAA;AAED,MAAM,MAAM,kBAAkB,CAAC,YAAY,SAAS,aAAa,CAAC,eAAe,CAAC,IAAI;KACnF,WAAW,IAAI,YAAY,CAAC,MAAM,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC;CACjG,CAAA;AAED,yFAAyF;AACzF,wBAAgB,oBAAoB,CAAC,WAAW,SAAS,eAAe,EACtE,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,iBAAiB,CAAC,WAAW,CAAC,GACxC,iBAAiB,CAAC,WAAW,CAAC,CAEhC;AAED,iFAAiF;AACjF,wBAAgB,qBAAqB,CAAC,KAAK,CAAC,YAAY,SAAS,aAAa,CAAC,eAAe,CAAC,EAC7F,YAAY,EAAE,YAAY,EAC1B,UAAU,EAAE,kBAAkB,CAAC,YAAY,CAAC,GAC3C,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAEhC;AAED,MAAM,WAAW,kBAAkB;IACjC,oEAAoE;IACpE,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"}
|
package/dist/content-blocks.js
CHANGED
|
@@ -11,6 +11,14 @@ function warnMissingComponent(name) {
|
|
|
11
11
|
console.warn(`[contentbit] no component registered for block "${name}" — rendering the raw-body fallback. ` +
|
|
12
12
|
'Pass it via the `components` prop.');
|
|
13
13
|
}
|
|
14
|
+
/** Preserve a block definition's inferred name, props, and data in its React adapter. */
|
|
15
|
+
export function defineBlockComponent(_definition, component) {
|
|
16
|
+
return component;
|
|
17
|
+
}
|
|
18
|
+
/** Check component keys against a block pack and return a renderer-ready map. */
|
|
19
|
+
export function defineBlockComponents(_definitions, components) {
|
|
20
|
+
return components;
|
|
21
|
+
}
|
|
14
22
|
function DefaultMarkdown({ md }) {
|
|
15
23
|
return md
|
|
16
24
|
.trim()
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { ContentBlocks, type BlockComponent, type BlockComponentProps, type BlockRenderContext, type ContentBlocksProps, } from './content-blocks.js';
|
|
1
|
+
export { ContentBlocks, defineBlockComponent, defineBlockComponents, type BlockComponent, type BlockComponentFor, type BlockComponentProps, type BlockComponentsFor, type BlockRenderContext, type ContentBlocksProps, } from './content-blocks.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,GACxB,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { ContentBlocks, } from './content-blocks.js';
|
|
1
|
+
export { ContentBlocks, defineBlockComponent, defineBlockComponents, } from './content-blocks.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentbit/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Headless React renderer for validated Contentbit documents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"content-blocks",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@contentbit/core": "0.
|
|
35
|
+
"@contentbit/core": "0.7.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@testing-library/react": "^16.3.0",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"react-dom": "^19.2.3",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
44
|
"vitest": "^4.0.17",
|
|
45
|
-
"
|
|
45
|
+
"zod": "^4.0.0",
|
|
46
|
+
"@contentbit/blocks": "0.7.0"
|
|
46
47
|
},
|
|
47
48
|
"peerDependencies": {
|
|
48
49
|
"react": "^19.0.0"
|