@zenyui/tiptap-react-render 0.1.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/LICENSE.md +21 -0
- package/dist/cjs/index.js +2839 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types/index.d.ts +3 -0
- package/dist/cjs/types/index.d.ts.map +1 -0
- package/dist/cjs/types/samples.d.ts +3 -0
- package/dist/cjs/types/samples.d.ts.map +1 -0
- package/dist/cjs/types/tip-tap-render.d.ts +31 -0
- package/dist/cjs/types/tip-tap-render.d.ts.map +1 -0
- package/dist/cjs/types/tip-tap-render.test.d.ts +5 -0
- package/dist/cjs/types/tip-tap-render.test.d.ts.map +1 -0
- package/dist/esm/index.js +2837 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types/index.d.ts +3 -0
- package/dist/esm/types/index.d.ts.map +1 -0
- package/dist/esm/types/samples.d.ts +3 -0
- package/dist/esm/types/samples.d.ts.map +1 -0
- package/dist/esm/types/tip-tap-render.d.ts +31 -0
- package/dist/esm/types/tip-tap-render.d.ts.map +1 -0
- package/dist/esm/types/tip-tap-render.test.d.ts +5 -0
- package/dist/esm/types/tip-tap-render.test.d.ts.map +1 -0
- package/dist/index.d.ts +32 -0
- package/package.json +49 -0
- package/readme.md +77 -0
package/readme.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# TipTap React Render
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@zenyui/tiptap-react-render)
|
|
4
|
+
[](https://www.npmjs.com/package/@zenyui/tiptap-react-render)
|
|
5
|
+
|
|
6
|
+
This library renders [TipTap](https://tiptap.dev/) JSON payloads in React clients without embedding the editor.
|
|
7
|
+
|
|
8
|
+
### Installation
|
|
9
|
+
```sh
|
|
10
|
+
# npm
|
|
11
|
+
npm install @zenyui/tiptap-react-render
|
|
12
|
+
|
|
13
|
+
# yarn
|
|
14
|
+
yarn add @zenyui/tiptap-react-render
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Usage
|
|
18
|
+
```typescript
|
|
19
|
+
// handle the document
|
|
20
|
+
const doc: NodeHandler = (props) => (<>{props.children}</>)
|
|
21
|
+
|
|
22
|
+
// handle a paragraph
|
|
23
|
+
const paragraph: NodeHandler = (props) => {
|
|
24
|
+
return <p>{props.children}</p>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// handle text
|
|
28
|
+
const text: NodeHandler = (props) => {
|
|
29
|
+
// you could process text marks here from props.node.marks ...
|
|
30
|
+
return <span>{props.node.text}</span>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// handle an image
|
|
34
|
+
const img: NodeHandler = (props) => {
|
|
35
|
+
const { src, alt, title } = props.node;
|
|
36
|
+
return (<img src={src} alt={alt} title={title} />)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// create a handlers wrapper
|
|
40
|
+
const handlers: NodeHandlers = {
|
|
41
|
+
"doc": doc,
|
|
42
|
+
"text": text,
|
|
43
|
+
"paragraph": paragraph,
|
|
44
|
+
"img": img,
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// sample tip tap data
|
|
48
|
+
const data = {
|
|
49
|
+
type: "doc",
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
type: "paragraph",
|
|
53
|
+
content: [{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: "hello world"
|
|
56
|
+
}],
|
|
57
|
+
type: "paragraph",
|
|
58
|
+
content: [{
|
|
59
|
+
type: "img",
|
|
60
|
+
src: "https://some-url.com/img.jpg",
|
|
61
|
+
alt: "some alt text"
|
|
62
|
+
}]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// render it!
|
|
68
|
+
const rendered = <TipTapRender handlers={handlers} node={data} />
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Why?
|
|
72
|
+
|
|
73
|
+
Many folks render TipTap rich text by embedding the TipTap editor in a "read-only" mode. However, if you don't want to add TipTap as a dependency (or, like us, you're using a platform that can't support it like React Native), then this is a simple, lightweight tool for mapping TipTap nodes to presentation components!
|
|
74
|
+
|
|
75
|
+
We were inspired by Contentful's [rich-text-react-renderer](https://github.com/contentful/rich-text/tree/master/packages/rich-text-react-renderer) tool, so we built a similar one for TipTap payloads!
|
|
76
|
+
|
|
77
|
+
This repo was scaffolded using the [@alexeagleson/template-react-component-library](https://github.com/alexeagleson/template-react-component-library)
|