@crashbytes/contentful-richtext-editor 1.0.1 → 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.
Files changed (2) hide show
  1. package/README.md +271 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -0,0 +1,271 @@
1
+ # @crashbytes/contentful-richtext-editor
2
+
3
+ A modern, Tiptap-based rich text editor that's fully compatible with Contentful's rich text format. Provides the same editing experience as Contentful's native editor while maintaining perfect compatibility with Contentful's document structure.
4
+
5
+ ## Features
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
13
+
14
+ ## Supported Features
15
+
16
+ - **Text Formatting**: Bold, italic, underline
17
+ - **Headings**: H1 through H6
18
+ - **Lists**: Ordered and unordered lists
19
+ - **Links**: Hyperlinks with URL validation
20
+ - **Tables**: Full table support with headers
21
+ - **Quotes**: Blockquotes
22
+ - **Embedded Content**: Callbacks for Contentful entries and assets
23
+ - **Undo/Redo**: Full history support
24
+
25
+ ## Installation
26
+
27
+ npm install @crashbytes/contentful-richtext-editor
28
+
29
+ ## Basic Usage
30
+
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;
57
+
58
+ ## Advanced Usage
59
+
60
+ ### With Contentful Entry/Asset Embedding
61
+
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
+ }
88
+
89
+ ### Customizing Features
90
+
91
+ <ContentfulRichTextEditor
92
+ placeholder="Simple editor..."
93
+ disabledFeatures={['table', 'embed', 'quote']}
94
+ theme="minimal"
95
+ readonly={false}
96
+ onChange={handleChange}
97
+ />
98
+
99
+ ### With Initial Content
100
+
101
+ import { createEmptyDocument } from '@crashbytes/contentful-richtext-editor';
102
+
103
+ const initialContent = {
104
+ nodeType: 'document',
105
+ data: {},
106
+ content: [
107
+ {
108
+ nodeType: 'paragraph',
109
+ data: {},
110
+ content: [
111
+ {
112
+ nodeType: 'text',
113
+ value: 'Hello world!',
114
+ marks: [{ type: 'bold' }],
115
+ data: {}
116
+ }
117
+ ]
118
+ }
119
+ ]
120
+ };
121
+
122
+ <ContentfulRichTextEditor
123
+ initialValue={initialContent}
124
+ onChange={handleChange}
125
+ />
126
+
127
+ ## API Reference
128
+
129
+ ### Props
130
+
131
+ | Prop | Type | Default | Description |
132
+ |------|------|---------|-------------|
133
+ | `initialValue` | `Document` | `undefined` | Initial Contentful rich text document |
134
+ | `onChange` | `(document: Document) => void` | `undefined` | Callback when content changes |
135
+ | `onEmbedEntry` | `() => Promise<any> \| void` | `undefined` | Callback for embedding Contentful entries |
136
+ | `onEmbedAsset` | `() => Promise<any> \| void` | `undefined` | Callback for embedding Contentful assets |
137
+ | `placeholder` | `string` | `'Start writing...'` | Placeholder text |
138
+ | `readonly` | `boolean` | `false` | Whether editor is read-only |
139
+ | `className` | `string` | `''` | Additional CSS classes |
140
+ | `theme` | `'default' \| 'minimal' \| 'contentful'` | `'contentful'` | Visual theme |
141
+ | `disabledFeatures` | `Array<string>` | `[]` | Features to disable |
142
+
143
+ ### Disabled Features
144
+
145
+ You can disable specific features by passing them in the `disabledFeatures` array:
146
+
147
+ - `'bold'` - Bold text formatting
148
+ - `'italic'` - Italic text formatting
149
+ - `'underline'` - Underline text formatting
150
+ - `'link'` - Hyperlinks
151
+ - `'lists'` - Ordered and unordered lists
152
+ - `'headings'` - All heading levels
153
+ - `'quote'` - Blockquotes
154
+ - `'table'` - Tables
155
+ - `'embed'` - Embedded content
156
+
157
+ ### Utility Functions
158
+
159
+ import {
160
+ contentfulToTiptap,
161
+ tiptapToContentful,
162
+ validateContentfulDocument,
163
+ createEmptyDocument
164
+ } from '@crashbytes/contentful-richtext-editor';
165
+
166
+ // Convert between formats
167
+ const tiptapJson = contentfulToTiptap(contentfulDocument);
168
+ const contentfulDoc = tiptapToContentful(tiptapJson);
169
+
170
+ // Validation
171
+ const isValid = validateContentfulDocument(someDocument);
172
+
173
+ // Create empty document
174
+ const emptyDoc = createEmptyDocument();
175
+
176
+ ## Styling
177
+
178
+ The editor comes with default styles that match Contentful's design. Import the CSS:
179
+
180
+ import '@crashbytes/contentful-richtext-editor/dist/index.css';
181
+
182
+ ### Custom Styling
183
+
184
+ You can override the default styles by targeting the CSS classes:
185
+
186
+ .contentful-editor {
187
+ border: 2px solid #your-color;
188
+ }
189
+
190
+ .contentful-toolbar {
191
+ background: #your-background;
192
+ }
193
+
194
+ .contentful-editor-content {
195
+ font-family: 'Your Font', sans-serif;
196
+ }
197
+
198
+ ## Themes
199
+
200
+ ### Contentful Theme (Default)
201
+ Matches Contentful's native editor appearance.
202
+
203
+ ### Minimal Theme
204
+ Clean, minimal design with reduced visual elements.
205
+
206
+ ### Default Theme
207
+ Standard rich text editor appearance with serif fonts.
208
+
209
+ ## Integration with Next.js
210
+
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
+ }
229
+
230
+ ## TypeScript Support
231
+
232
+ This package is written in TypeScript and includes full type definitions. All Contentful rich text types are re-exported for convenience:
233
+
234
+ import type {
235
+ Document,
236
+ Block,
237
+ Inline,
238
+ Text,
239
+ ContentfulRichTextEditorProps
240
+ } from '@crashbytes/contentful-richtext-editor';
241
+
242
+ ## Browser Support
243
+
244
+ - Chrome 80+
245
+ - Firefox 78+
246
+ - Safari 13+
247
+ - Edge 80+
248
+
249
+ ## Contributing
250
+
251
+ Contributions are welcome! Please feel free to submit a Pull Request.
252
+
253
+ 1. Fork the repository
254
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
255
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
256
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
257
+ 5. Open a Pull Request
258
+
259
+ ## License
260
+
261
+ MIT © [CrashBytes](https://github.com/CrashBytes)
262
+
263
+ ## Related Packages
264
+
265
+ - [@contentful/rich-text-react-renderer](https://www.npmjs.com/package/@contentful/rich-text-react-renderer) - For rendering Contentful rich text
266
+ - [@contentful/rich-text-types](https://www.npmjs.com/package/@contentful/rich-text-types) - Contentful rich text type definitions
267
+ - [@tiptap/react](https://www.npmjs.com/package/@tiptap/react) - The underlying editor framework
268
+
269
+ ---
270
+
271
+ **Made with ❤️ for the Contentful community**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crashbytes/contentful-richtext-editor",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A Tiptap-based rich text editor compatible with Contentful's rich text format",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",