@crashbytes/contentful-richtext-editor 1.0.2 → 1.0.3
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 +131 -151
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,12 +4,12 @@ A modern, Tiptap-based rich text editor that's fully compatible with Contentful'
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
✅ **Full Contentful Compatibility** - Seamless conversion between Contentful and Tiptap formats
|
|
8
|
-
✅ **Modern UI** - Clean, intuitive interface matching Contentful's design
|
|
9
|
-
✅ **TypeScript Support** - Complete type safety with Contentful's rich text types
|
|
10
|
-
✅ **Extensible** - Built on Tiptap v2 for easy customization
|
|
11
|
-
✅ **Lightweight** - Tree-shakeable, only import what you need
|
|
12
|
-
✅ **Responsive** - Works on desktop and mobile devices
|
|
7
|
+
- ✅ **Full Contentful Compatibility** - Seamless conversion between Contentful and Tiptap formats
|
|
8
|
+
- ✅ **Modern UI** - Clean, intuitive interface matching Contentful's design
|
|
9
|
+
- ✅ **TypeScript Support** - Complete type safety with Contentful's rich text types
|
|
10
|
+
- ✅ **Extensible** - Built on Tiptap v2 for easy customization
|
|
11
|
+
- ✅ **Lightweight** - Tree-shakeable, only import what you need
|
|
12
|
+
- ✅ **Responsive** - Works on desktop and mobile devices
|
|
13
13
|
|
|
14
14
|
## Supported Features
|
|
15
15
|
|
|
@@ -24,115 +24,105 @@ A modern, Tiptap-based rich text editor that's fully compatible with Contentful'
|
|
|
24
24
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
npm install @crashbytes/contentful-richtext-editor
|
|
29
|
-
```
|
|
27
|
+
npm install @crashbytes/contentful-richtext-editor
|
|
30
28
|
|
|
31
29
|
## Basic Usage
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
import
|
|
35
|
-
import
|
|
36
|
-
import '@
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
export default App;
|
|
60
|
-
```
|
|
31
|
+
import React, { useState } from 'react';
|
|
32
|
+
import { ContentfulRichTextEditor } from '@crashbytes/contentful-richtext-editor';
|
|
33
|
+
import '@crashbytes/contentful-richtext-editor/dist/index.css';
|
|
34
|
+
import { Document } from '@contentful/rich-text-types';
|
|
35
|
+
|
|
36
|
+
function App() {
|
|
37
|
+
const [content, setContent] = useState<Document>();
|
|
38
|
+
|
|
39
|
+
const handleChange = (document: Document) => {
|
|
40
|
+
setContent(document);
|
|
41
|
+
console.log('Contentful document:', document);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<div>
|
|
46
|
+
<h1>My Rich Text Editor</h1>
|
|
47
|
+
<ContentfulRichTextEditor
|
|
48
|
+
placeholder="Start writing your content..."
|
|
49
|
+
onChange={handleChange}
|
|
50
|
+
initialValue={content}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default App;
|
|
61
57
|
|
|
62
58
|
## Advanced Usage
|
|
63
59
|
|
|
64
60
|
### With Contentful Entry/Asset Embedding
|
|
65
61
|
|
|
66
|
-
|
|
67
|
-
import
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
62
|
+
import { ContentfulRichTextEditor } from '@crashbytes/contentful-richtext-editor';
|
|
63
|
+
import '@crashbytes/contentful-richtext-editor/dist/index.css';
|
|
64
|
+
|
|
65
|
+
function ContentfulEditor() {
|
|
66
|
+
const handleEmbedEntry = async () => {
|
|
67
|
+
// Your logic to select a Contentful entry
|
|
68
|
+
const entry = await openEntrySelector();
|
|
69
|
+
return entry;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const handleEmbedAsset = async () => {
|
|
73
|
+
// Your logic to select a Contentful asset
|
|
74
|
+
const asset = await openAssetSelector();
|
|
75
|
+
return asset;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<ContentfulRichTextEditor
|
|
80
|
+
placeholder="Write your travel tip..."
|
|
81
|
+
onChange={(doc) => saveToContentful(doc)}
|
|
82
|
+
onEmbedEntry={handleEmbedEntry}
|
|
83
|
+
onEmbedAsset={handleEmbedAsset}
|
|
84
|
+
theme="contentful"
|
|
85
|
+
/>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
76
88
|
|
|
77
|
-
|
|
78
|
-
// Your logic to select a Contentful asset
|
|
79
|
-
const asset = await openAssetSelector();
|
|
80
|
-
return asset;
|
|
81
|
-
};
|
|
89
|
+
### Customizing Features
|
|
82
90
|
|
|
83
|
-
return (
|
|
84
91
|
<ContentfulRichTextEditor
|
|
85
|
-
placeholder="
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
placeholder="Simple editor..."
|
|
93
|
+
disabledFeatures={['table', 'embed', 'quote']}
|
|
94
|
+
theme="minimal"
|
|
95
|
+
readonly={false}
|
|
96
|
+
onChange={handleChange}
|
|
90
97
|
/>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### Customizing Features
|
|
96
|
-
|
|
97
|
-
```tsx
|
|
98
|
-
<ContentfulRichTextEditor
|
|
99
|
-
placeholder="Simple editor..."
|
|
100
|
-
disabledFeatures={['table', 'embed', 'quote']}
|
|
101
|
-
theme="minimal"
|
|
102
|
-
readonly={false}
|
|
103
|
-
onChange={handleChange}
|
|
104
|
-
/>
|
|
105
|
-
```
|
|
106
98
|
|
|
107
99
|
### With Initial Content
|
|
108
100
|
|
|
109
|
-
|
|
110
|
-
import { createEmptyDocument } from '@crashbytes/contentful-richtext-editor';
|
|
101
|
+
import { createEmptyDocument } from '@crashbytes/contentful-richtext-editor';
|
|
111
102
|
|
|
112
|
-
const initialContent = {
|
|
113
|
-
|
|
114
|
-
data: {},
|
|
115
|
-
content: [
|
|
116
|
-
{
|
|
117
|
-
nodeType: 'paragraph',
|
|
103
|
+
const initialContent = {
|
|
104
|
+
nodeType: 'document',
|
|
118
105
|
data: {},
|
|
119
106
|
content: [
|
|
120
107
|
{
|
|
121
|
-
nodeType: '
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
108
|
+
nodeType: 'paragraph',
|
|
109
|
+
data: {},
|
|
110
|
+
content: [
|
|
111
|
+
{
|
|
112
|
+
nodeType: 'text',
|
|
113
|
+
value: 'Hello world!',
|
|
114
|
+
marks: [{ type: 'bold' }],
|
|
115
|
+
data: {}
|
|
116
|
+
}
|
|
117
|
+
]
|
|
125
118
|
}
|
|
126
119
|
]
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
};
|
|
120
|
+
};
|
|
130
121
|
|
|
131
|
-
<ContentfulRichTextEditor
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/>
|
|
135
|
-
```
|
|
122
|
+
<ContentfulRichTextEditor
|
|
123
|
+
initialValue={initialContent}
|
|
124
|
+
onChange={handleChange}
|
|
125
|
+
/>
|
|
136
126
|
|
|
137
127
|
## API Reference
|
|
138
128
|
|
|
@@ -166,50 +156,44 @@ You can disable specific features by passing them in the `disabledFeatures` arra
|
|
|
166
156
|
|
|
167
157
|
### Utility Functions
|
|
168
158
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
} from '@crashbytes/contentful-richtext-editor';
|
|
159
|
+
import {
|
|
160
|
+
contentfulToTiptap,
|
|
161
|
+
tiptapToContentful,
|
|
162
|
+
validateContentfulDocument,
|
|
163
|
+
createEmptyDocument
|
|
164
|
+
} from '@crashbytes/contentful-richtext-editor';
|
|
176
165
|
|
|
177
|
-
// Convert between formats
|
|
178
|
-
const tiptapJson = contentfulToTiptap(contentfulDocument);
|
|
179
|
-
const contentfulDoc = tiptapToContentful(tiptapJson);
|
|
166
|
+
// Convert between formats
|
|
167
|
+
const tiptapJson = contentfulToTiptap(contentfulDocument);
|
|
168
|
+
const contentfulDoc = tiptapToContentful(tiptapJson);
|
|
180
169
|
|
|
181
|
-
// Validation
|
|
182
|
-
const isValid = validateContentfulDocument(someDocument);
|
|
170
|
+
// Validation
|
|
171
|
+
const isValid = validateContentfulDocument(someDocument);
|
|
183
172
|
|
|
184
|
-
// Create empty document
|
|
185
|
-
const emptyDoc = createEmptyDocument();
|
|
186
|
-
```
|
|
173
|
+
// Create empty document
|
|
174
|
+
const emptyDoc = createEmptyDocument();
|
|
187
175
|
|
|
188
176
|
## Styling
|
|
189
177
|
|
|
190
178
|
The editor comes with default styles that match Contentful's design. Import the CSS:
|
|
191
179
|
|
|
192
|
-
|
|
193
|
-
import '@crashbytes/contentful-richtext-editor/dist/index.css';
|
|
194
|
-
```
|
|
180
|
+
import '@crashbytes/contentful-richtext-editor/dist/index.css';
|
|
195
181
|
|
|
196
182
|
### Custom Styling
|
|
197
183
|
|
|
198
184
|
You can override the default styles by targeting the CSS classes:
|
|
199
185
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
186
|
+
.contentful-editor {
|
|
187
|
+
border: 2px solid #your-color;
|
|
188
|
+
}
|
|
204
189
|
|
|
205
|
-
.contentful-toolbar {
|
|
206
|
-
|
|
207
|
-
}
|
|
190
|
+
.contentful-toolbar {
|
|
191
|
+
background: #your-background;
|
|
192
|
+
}
|
|
208
193
|
|
|
209
|
-
.contentful-editor-content {
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
```
|
|
194
|
+
.contentful-editor-content {
|
|
195
|
+
font-family: 'Your Font', sans-serif;
|
|
196
|
+
}
|
|
213
197
|
|
|
214
198
|
## Themes
|
|
215
199
|
|
|
@@ -224,40 +208,36 @@ Standard rich text editor appearance with serif fonts.
|
|
|
224
208
|
|
|
225
209
|
## Integration with Next.js
|
|
226
210
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
}
|
|
246
|
-
```
|
|
211
|
+
// pages/editor.tsx or app/editor/page.tsx
|
|
212
|
+
import dynamic from 'next/dynamic';
|
|
213
|
+
|
|
214
|
+
const ContentfulEditor = dynamic(
|
|
215
|
+
() => import('@crashbytes/contentful-richtext-editor').then(mod => mod.ContentfulRichTextEditor),
|
|
216
|
+
{ ssr: false }
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
export default function EditorPage() {
|
|
220
|
+
return (
|
|
221
|
+
<div>
|
|
222
|
+
<ContentfulEditor
|
|
223
|
+
placeholder="Write something amazing..."
|
|
224
|
+
onChange={(doc) => console.log(doc)}
|
|
225
|
+
/>
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
247
229
|
|
|
248
230
|
## TypeScript Support
|
|
249
231
|
|
|
250
232
|
This package is written in TypeScript and includes full type definitions. All Contentful rich text types are re-exported for convenience:
|
|
251
233
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
} from '@crashbytes/contentful-richtext-editor';
|
|
260
|
-
```
|
|
234
|
+
import type {
|
|
235
|
+
Document,
|
|
236
|
+
Block,
|
|
237
|
+
Inline,
|
|
238
|
+
Text,
|
|
239
|
+
ContentfulRichTextEditorProps
|
|
240
|
+
} from '@crashbytes/contentful-richtext-editor';
|
|
261
241
|
|
|
262
242
|
## Browser Support
|
|
263
243
|
|
package/package.json
CHANGED