@bernierllc/content-editor-ui 0.1.1
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 +635 -0
- package/dist/content-editor.d.ts +7 -0
- package/dist/content-editor.d.ts.map +1 -0
- package/dist/content-editor.js +520 -0
- package/dist/content-editor.js.map +1 -0
- package/dist/editor-components.d.ts +61 -0
- package/dist/editor-components.d.ts.map +1 -0
- package/dist/editor-components.js +113 -0
- package/dist/editor-components.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +303 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/package.json +89 -0
package/README.md
ADDED
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
# @bernierllc/content-editor-ui
|
|
2
|
+
|
|
3
|
+
TipTap editor with Tamagui UI components for content management.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides a comprehensive content editor built with TipTap and Tamagui. It offers a rich WYSIWYG editing experience with customizable toolbars, status bars, auto-save functionality, and seamless integration with the content management suite.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **TipTap Integration**: Full-featured WYSIWYG editor with rich text capabilities
|
|
12
|
+
- **Tamagui UI**: Beautiful, accessible UI components with consistent theming
|
|
13
|
+
- **Auto-save Support**: Configurable auto-save with visual feedback
|
|
14
|
+
- **Customizable Toolbar**: Flexible toolbar with formatting, media, and custom tools
|
|
15
|
+
- **Status Bar**: Real-time statistics (word count, character count, reading time)
|
|
16
|
+
- **Media Upload**: Drag-and-drop media upload with progress tracking
|
|
17
|
+
- **Content Type Support**: Integration with content type registry
|
|
18
|
+
- **Keyboard Shortcuts**: Built-in shortcuts for common operations
|
|
19
|
+
- **Theme Support**: Light, dark, and auto themes
|
|
20
|
+
- **Accessibility**: Full accessibility support with ARIA labels and keyboard navigation
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm install @bernierllc/content-editor-ui
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import React from 'react';
|
|
32
|
+
import { ContentEditor } from '@bernierllc/content-editor-ui';
|
|
33
|
+
import { TamaguiProvider } from 'tamagui';
|
|
34
|
+
import { ContentData } from '@bernierllc/content-autosave-manager';
|
|
35
|
+
import { ContentType } from '@bernierllc/content-type-registry';
|
|
36
|
+
|
|
37
|
+
function MyContentEditor() {
|
|
38
|
+
const [content, setContent] = useState<ContentData>({
|
|
39
|
+
id: 'content-1',
|
|
40
|
+
data: { type: 'doc', content: [] },
|
|
41
|
+
metadata: { type: 'text' },
|
|
42
|
+
lastModified: new Date(),
|
|
43
|
+
version: 1
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const contentType: ContentType = {
|
|
47
|
+
id: 'text',
|
|
48
|
+
name: 'Text Content',
|
|
49
|
+
schema: {},
|
|
50
|
+
editorConfig: { component: null, fields: [] },
|
|
51
|
+
storageAdapter: {},
|
|
52
|
+
displayRenderer: { component: null },
|
|
53
|
+
metadata: { description: 'Plain text content' }
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const handleAutoSave = (content: ContentData) => {
|
|
57
|
+
console.log('Auto-saving content:', content);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const handleSave = (content: ContentData, saveType: 'draft' | 'publish') => {
|
|
61
|
+
console.log(`Saving as ${saveType}:`, content);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const handleChange = (content: ContentData) => {
|
|
65
|
+
setContent(content);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<TamaguiProvider>
|
|
70
|
+
<ContentEditor
|
|
71
|
+
content={content}
|
|
72
|
+
contentType={contentType}
|
|
73
|
+
onAutoSave={handleAutoSave}
|
|
74
|
+
onSave={handleSave}
|
|
75
|
+
onChange={handleChange}
|
|
76
|
+
config={{
|
|
77
|
+
placeholder: 'Start writing your content...',
|
|
78
|
+
showWordCount: true,
|
|
79
|
+
showCharCount: true,
|
|
80
|
+
showAutoSaveStatus: true,
|
|
81
|
+
theme: 'light'
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</TamaguiProvider>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### ContentEditor
|
|
92
|
+
|
|
93
|
+
The main editor component.
|
|
94
|
+
|
|
95
|
+
#### Props
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface ContentEditorProps {
|
|
99
|
+
content: ContentData; // Content data to edit
|
|
100
|
+
contentType: ContentType; // Content type configuration
|
|
101
|
+
config?: Partial<ContentEditorUIConfig>; // Editor configuration
|
|
102
|
+
onAutoSave?: (content: ContentData) => void; // Auto-save callback
|
|
103
|
+
onSave?: (content: ContentData, saveType: 'draft' | 'publish') => void; // Save callback
|
|
104
|
+
onChange?: (content: ContentData) => void; // Content change callback
|
|
105
|
+
onFocus?: () => void; // Focus callback
|
|
106
|
+
onBlur?: () => void; // Blur callback
|
|
107
|
+
onError?: (error: Error) => void; // Error callback
|
|
108
|
+
readOnly?: boolean; // Whether editor is read-only
|
|
109
|
+
disabled?: boolean; // Whether editor is disabled
|
|
110
|
+
customToolbarItems?: ToolbarItem[]; // Custom toolbar items
|
|
111
|
+
customStatusItems?: StatusItem[]; // Custom status bar items
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Configuration Options
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
interface ContentEditorUIConfig {
|
|
119
|
+
enabled: boolean; // Whether editor is enabled
|
|
120
|
+
theme: 'light' | 'dark' | 'auto'; // Editor theme
|
|
121
|
+
placeholder?: string; // Placeholder text
|
|
122
|
+
showWordCount: boolean; // Whether to show word count
|
|
123
|
+
showCharCount: boolean; // Whether to show character count
|
|
124
|
+
showAutoSaveStatus: boolean; // Whether to show auto-save status
|
|
125
|
+
showToolbar: boolean; // Whether to show toolbar
|
|
126
|
+
showStatusBar: boolean; // Whether to show status bar
|
|
127
|
+
height?: string | number; // Editor height
|
|
128
|
+
width?: string | number; // Editor width
|
|
129
|
+
className?: string; // Custom CSS classes
|
|
130
|
+
style?: React.CSSProperties; // Custom styles
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### ContentTypeSelector
|
|
135
|
+
|
|
136
|
+
Component for selecting content types.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
interface ContentTypeSelectorProps {
|
|
140
|
+
contentTypes: ContentType[]; // Available content types
|
|
141
|
+
selectedType?: ContentType; // Currently selected type
|
|
142
|
+
onChange: (contentType: ContentType) => void; // Change callback
|
|
143
|
+
disabled?: boolean; // Whether selector is disabled
|
|
144
|
+
placeholder?: string; // Custom placeholder
|
|
145
|
+
showDescriptions?: boolean; // Whether to show descriptions
|
|
146
|
+
showIcons?: boolean; // Whether to show icons
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### MediaUploader
|
|
151
|
+
|
|
152
|
+
Component for uploading media files.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
interface MediaUploaderProps {
|
|
156
|
+
accept?: string[]; // Accepted file types
|
|
157
|
+
maxSize?: number; // Maximum file size in bytes
|
|
158
|
+
onUpload: (file: File) => Promise<string>; // Upload callback
|
|
159
|
+
onProgress?: (progress: number) => void; // Progress callback
|
|
160
|
+
onError?: (error: Error) => void; // Error callback
|
|
161
|
+
disabled?: boolean; // Whether uploader is disabled
|
|
162
|
+
buttonText?: string; // Upload button text
|
|
163
|
+
showDragDrop?: boolean; // Whether to show drag and drop area
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### ContentEditorSettings
|
|
168
|
+
|
|
169
|
+
Component for configuring editor settings.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
interface ContentEditorSettingsProps {
|
|
173
|
+
settings: Record<string, any>; // Current settings
|
|
174
|
+
onChange: (settings: Record<string, any>) => void; // Change callback
|
|
175
|
+
isOpen: boolean; // Whether settings panel is open
|
|
176
|
+
onClose: () => void; // Close callback
|
|
177
|
+
disabled?: boolean; // Whether settings are disabled
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Examples
|
|
182
|
+
|
|
183
|
+
### Basic Editor with Auto-save
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
import React, { useState, useCallback } from 'react';
|
|
187
|
+
import { ContentEditor } from '@bernierllc/content-editor-ui';
|
|
188
|
+
import { ContentData } from '@bernierllc/content-autosave-manager';
|
|
189
|
+
|
|
190
|
+
function AutoSaveEditor() {
|
|
191
|
+
const [content, setContent] = useState<ContentData>({
|
|
192
|
+
id: 'content-1',
|
|
193
|
+
data: { type: 'doc', content: [] },
|
|
194
|
+
metadata: { type: 'text' },
|
|
195
|
+
lastModified: new Date(),
|
|
196
|
+
version: 1
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const handleAutoSave = useCallback(async (content: ContentData) => {
|
|
200
|
+
try {
|
|
201
|
+
// Save to server
|
|
202
|
+
await fetch('/api/content/autosave', {
|
|
203
|
+
method: 'POST',
|
|
204
|
+
headers: { 'Content-Type': 'application/json' },
|
|
205
|
+
body: JSON.stringify(content)
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
console.log('Auto-saved successfully');
|
|
209
|
+
} catch (error) {
|
|
210
|
+
console.error('Auto-save failed:', error);
|
|
211
|
+
}
|
|
212
|
+
}, []);
|
|
213
|
+
|
|
214
|
+
const handleSave = useCallback(async (content: ContentData, saveType: 'draft' | 'publish') => {
|
|
215
|
+
try {
|
|
216
|
+
await fetch('/api/content/save', {
|
|
217
|
+
method: 'POST',
|
|
218
|
+
headers: { 'Content-Type': 'application/json' },
|
|
219
|
+
body: JSON.stringify({ ...content, saveType })
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
console.log(`Saved as ${saveType}`);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
console.error('Save failed:', error);
|
|
225
|
+
}
|
|
226
|
+
}, []);
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<ContentEditor
|
|
230
|
+
content={content}
|
|
231
|
+
contentType={textContentType}
|
|
232
|
+
onAutoSave={handleAutoSave}
|
|
233
|
+
onSave={handleSave}
|
|
234
|
+
onChange={setContent}
|
|
235
|
+
config={{
|
|
236
|
+
placeholder: 'Start writing...',
|
|
237
|
+
showAutoSaveStatus: true,
|
|
238
|
+
showWordCount: true,
|
|
239
|
+
showCharCount: true
|
|
240
|
+
}}
|
|
241
|
+
/>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Editor with Custom Toolbar
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import React from 'react';
|
|
250
|
+
import { ContentEditor, ToolbarItem } from '@bernierllc/content-editor-ui';
|
|
251
|
+
|
|
252
|
+
function CustomToolbarEditor() {
|
|
253
|
+
const customToolbarItems: ToolbarItem[] = [
|
|
254
|
+
{
|
|
255
|
+
id: 'custom-button',
|
|
256
|
+
type: 'button',
|
|
257
|
+
label: 'Custom Action',
|
|
258
|
+
icon: '⭐',
|
|
259
|
+
tooltip: 'Perform custom action',
|
|
260
|
+
onClick: () => {
|
|
261
|
+
console.log('Custom action triggered');
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'custom-separator',
|
|
266
|
+
type: 'separator'
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
id: 'custom-component',
|
|
270
|
+
type: 'custom',
|
|
271
|
+
component: CustomToolbarComponent,
|
|
272
|
+
props: { customProp: 'value' }
|
|
273
|
+
}
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
return (
|
|
277
|
+
<ContentEditor
|
|
278
|
+
content={content}
|
|
279
|
+
contentType={contentType}
|
|
280
|
+
customToolbarItems={customToolbarItems}
|
|
281
|
+
config={{
|
|
282
|
+
showToolbar: true,
|
|
283
|
+
showFormatting: true,
|
|
284
|
+
showHeadings: true,
|
|
285
|
+
showLists: true,
|
|
286
|
+
showLink: true,
|
|
287
|
+
showImage: true
|
|
288
|
+
}}
|
|
289
|
+
/>
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function CustomToolbarComponent({ editor, customProp }: any) {
|
|
294
|
+
return (
|
|
295
|
+
<Button
|
|
296
|
+
onPress={() => {
|
|
297
|
+
// Custom toolbar action
|
|
298
|
+
editor.chain().focus().insertContent('Custom content').run();
|
|
299
|
+
}}
|
|
300
|
+
>
|
|
301
|
+
<Text>{customProp}</Text>
|
|
302
|
+
</Button>
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### Editor with Media Upload
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import React from 'react';
|
|
311
|
+
import { ContentEditor, MediaUploader } from '@bernierllc/content-editor-ui';
|
|
312
|
+
|
|
313
|
+
function MediaEditor() {
|
|
314
|
+
const handleMediaUpload = async (file: File): Promise<string> => {
|
|
315
|
+
const formData = new FormData();
|
|
316
|
+
formData.append('file', file);
|
|
317
|
+
|
|
318
|
+
const response = await fetch('/api/upload', {
|
|
319
|
+
method: 'POST',
|
|
320
|
+
body: formData
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
const result = await response.json();
|
|
324
|
+
return result.url;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
const handleUploadProgress = (progress: number) => {
|
|
328
|
+
console.log(`Upload progress: ${progress}%`);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const handleUploadError = (error: Error) => {
|
|
332
|
+
console.error('Upload error:', error);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return (
|
|
336
|
+
<YStack gap="$4">
|
|
337
|
+
<ContentEditor
|
|
338
|
+
content={content}
|
|
339
|
+
contentType={contentType}
|
|
340
|
+
config={{
|
|
341
|
+
showImage: true,
|
|
342
|
+
showToolbar: true
|
|
343
|
+
}}
|
|
344
|
+
/>
|
|
345
|
+
|
|
346
|
+
<MediaUploader
|
|
347
|
+
accept={['image/*', 'video/*', 'audio/*']}
|
|
348
|
+
maxSize={10 * 1024 * 1024} // 10MB
|
|
349
|
+
onUpload={handleMediaUpload}
|
|
350
|
+
onProgress={handleUploadProgress}
|
|
351
|
+
onError={handleUploadError}
|
|
352
|
+
showDragDrop={true}
|
|
353
|
+
buttonText="Upload Media"
|
|
354
|
+
/>
|
|
355
|
+
</YStack>
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
### Editor with Content Type Selection
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import React, { useState } from 'react';
|
|
364
|
+
import { ContentEditor, ContentTypeSelector } from '@bernierllc/content-editor-ui';
|
|
365
|
+
|
|
366
|
+
function MultiTypeEditor() {
|
|
367
|
+
const [selectedType, setSelectedType] = useState(contentTypes[0]);
|
|
368
|
+
const [content, setContent] = useState<ContentData>({
|
|
369
|
+
id: 'content-1',
|
|
370
|
+
data: { type: 'doc', content: [] },
|
|
371
|
+
metadata: { type: selectedType.id },
|
|
372
|
+
lastModified: new Date(),
|
|
373
|
+
version: 1
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
const handleTypeChange = (contentType: ContentType) => {
|
|
377
|
+
setSelectedType(contentType);
|
|
378
|
+
|
|
379
|
+
// Update content metadata
|
|
380
|
+
setContent(prev => ({
|
|
381
|
+
...prev,
|
|
382
|
+
metadata: { ...prev.metadata, type: contentType.id }
|
|
383
|
+
}));
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
<YStack gap="$4">
|
|
388
|
+
<ContentTypeSelector
|
|
389
|
+
contentTypes={contentTypes}
|
|
390
|
+
selectedType={selectedType}
|
|
391
|
+
onChange={handleTypeChange}
|
|
392
|
+
showDescriptions={true}
|
|
393
|
+
showIcons={true}
|
|
394
|
+
placeholder="Select content type..."
|
|
395
|
+
/>
|
|
396
|
+
|
|
397
|
+
<ContentEditor
|
|
398
|
+
content={content}
|
|
399
|
+
contentType={selectedType}
|
|
400
|
+
onChange={setContent}
|
|
401
|
+
config={{
|
|
402
|
+
placeholder: `Start writing ${selectedType.name.toLowerCase()}...`,
|
|
403
|
+
showWordCount: true,
|
|
404
|
+
showCharCount: true
|
|
405
|
+
}}
|
|
406
|
+
/>
|
|
407
|
+
</YStack>
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### Editor with Settings Panel
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
import React, { useState } from 'react';
|
|
416
|
+
import { ContentEditor, ContentEditorSettings } from '@bernierllc/content-editor-ui';
|
|
417
|
+
|
|
418
|
+
function ConfigurableEditor() {
|
|
419
|
+
const [settings, setSettings] = useState({
|
|
420
|
+
showWordCount: true,
|
|
421
|
+
showCharCount: true,
|
|
422
|
+
showAutoSaveStatus: true,
|
|
423
|
+
editorHeight: '400px',
|
|
424
|
+
placeholder: 'Start writing...',
|
|
425
|
+
theme: 'light'
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
const [isSettingsOpen, setIsSettingsOpen] = useState(false);
|
|
429
|
+
|
|
430
|
+
const handleSettingsChange = (newSettings: Record<string, any>) => {
|
|
431
|
+
setSettings(prev => ({ ...prev, ...newSettings }));
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
return (
|
|
435
|
+
<YStack gap="$4">
|
|
436
|
+
<XStack gap="$2" justifyContent="flex-end">
|
|
437
|
+
<Button onPress={() => setIsSettingsOpen(true)}>
|
|
438
|
+
<Text>Settings</Text>
|
|
439
|
+
</Button>
|
|
440
|
+
</XStack>
|
|
441
|
+
|
|
442
|
+
<ContentEditor
|
|
443
|
+
content={content}
|
|
444
|
+
contentType={contentType}
|
|
445
|
+
config={settings}
|
|
446
|
+
onChange={setContent}
|
|
447
|
+
/>
|
|
448
|
+
|
|
449
|
+
<ContentEditorSettings
|
|
450
|
+
settings={settings}
|
|
451
|
+
onChange={handleSettingsChange}
|
|
452
|
+
isOpen={isSettingsOpen}
|
|
453
|
+
onClose={() => setIsSettingsOpen(false)}
|
|
454
|
+
/>
|
|
455
|
+
</YStack>
|
|
456
|
+
);
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
### Editor with Custom Status Bar
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
import React from 'react';
|
|
464
|
+
import { ContentEditor, StatusItem } from '@bernierllc/content-editor-ui';
|
|
465
|
+
|
|
466
|
+
function CustomStatusEditor() {
|
|
467
|
+
const customStatusItems: StatusItem[] = [
|
|
468
|
+
{
|
|
469
|
+
id: 'custom-stat',
|
|
470
|
+
type: 'text',
|
|
471
|
+
label: 'Custom Stat',
|
|
472
|
+
value: '42',
|
|
473
|
+
color: '#007bff'
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
id: 'custom-progress',
|
|
477
|
+
type: 'progress',
|
|
478
|
+
label: 'Progress',
|
|
479
|
+
value: 75
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
id: 'custom-component',
|
|
483
|
+
type: 'custom',
|
|
484
|
+
component: CustomStatusComponent,
|
|
485
|
+
props: { data: 'custom data' }
|
|
486
|
+
}
|
|
487
|
+
];
|
|
488
|
+
|
|
489
|
+
return (
|
|
490
|
+
<ContentEditor
|
|
491
|
+
content={content}
|
|
492
|
+
contentType={contentType}
|
|
493
|
+
customStatusItems={customStatusItems}
|
|
494
|
+
config={{
|
|
495
|
+
showStatusBar: true,
|
|
496
|
+
showWordCount: true,
|
|
497
|
+
showCharCount: true,
|
|
498
|
+
showAutoSaveStatus: true
|
|
499
|
+
}}
|
|
500
|
+
/>
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function CustomStatusComponent({ statistics, data }: any) {
|
|
505
|
+
return (
|
|
506
|
+
<XStack gap="$1" alignItems="center">
|
|
507
|
+
<Text fontSize="$1" color="$gray">
|
|
508
|
+
{data}:
|
|
509
|
+
</Text>
|
|
510
|
+
<Text fontSize="$1" fontWeight="bold">
|
|
511
|
+
{statistics.wordCount * 2}
|
|
512
|
+
</Text>
|
|
513
|
+
</XStack>
|
|
514
|
+
);
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### Editor with Keyboard Shortcuts
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
import React from 'react';
|
|
522
|
+
import { ContentEditor } from '@bernierllc/content-editor-ui';
|
|
523
|
+
|
|
524
|
+
function KeyboardShortcutsEditor() {
|
|
525
|
+
const handleSave = (content: ContentData, saveType: 'draft' | 'publish') => {
|
|
526
|
+
console.log(`Saving as ${saveType}:`, content);
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<ContentEditor
|
|
531
|
+
content={content}
|
|
532
|
+
contentType={contentType}
|
|
533
|
+
onSave={handleSave}
|
|
534
|
+
config={{
|
|
535
|
+
placeholder: 'Use Ctrl+S to save draft, Ctrl+Shift+S to publish',
|
|
536
|
+
showToolbar: true,
|
|
537
|
+
showStatusBar: true
|
|
538
|
+
}}
|
|
539
|
+
/>
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### Editor with Error Handling
|
|
545
|
+
|
|
546
|
+
```typescript
|
|
547
|
+
import React, { useState } from 'react';
|
|
548
|
+
import { ContentEditor } from '@bernierllc/content-editor-ui';
|
|
549
|
+
import { Alert, Toast } from 'tamagui';
|
|
550
|
+
|
|
551
|
+
function ErrorHandlingEditor() {
|
|
552
|
+
const [error, setError] = useState<string | null>(null);
|
|
553
|
+
|
|
554
|
+
const handleError = (error: Error) => {
|
|
555
|
+
setError(error.message);
|
|
556
|
+
console.error('Editor error:', error);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
const handleAutoSaveError = (error: Error) => {
|
|
560
|
+
console.error('Auto-save error:', error);
|
|
561
|
+
// Show toast notification
|
|
562
|
+
Toast.show({
|
|
563
|
+
message: 'Auto-save failed. Please save manually.',
|
|
564
|
+
type: 'error'
|
|
565
|
+
});
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
return (
|
|
569
|
+
<YStack gap="$4">
|
|
570
|
+
{error && (
|
|
571
|
+
<Alert type="error">
|
|
572
|
+
<Text>{error}</Text>
|
|
573
|
+
</Alert>
|
|
574
|
+
)}
|
|
575
|
+
|
|
576
|
+
<ContentEditor
|
|
577
|
+
content={content}
|
|
578
|
+
contentType={contentType}
|
|
579
|
+
onError={handleError}
|
|
580
|
+
onAutoSaveError={handleAutoSaveError}
|
|
581
|
+
config={{
|
|
582
|
+
showAutoSaveStatus: true,
|
|
583
|
+
showStatusBar: true
|
|
584
|
+
}}
|
|
585
|
+
/>
|
|
586
|
+
</YStack>
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
## Keyboard Shortcuts
|
|
592
|
+
|
|
593
|
+
The editor supports the following keyboard shortcuts:
|
|
594
|
+
|
|
595
|
+
- **Ctrl/Cmd + S**: Save as draft
|
|
596
|
+
- **Ctrl/Cmd + Shift + S**: Publish
|
|
597
|
+
- **Ctrl/Cmd + B**: Bold
|
|
598
|
+
- **Ctrl/Cmd + I**: Italic
|
|
599
|
+
- **Ctrl/Cmd + U**: Underline
|
|
600
|
+
- **Ctrl/Cmd + K**: Add link
|
|
601
|
+
- **Ctrl/Cmd + Shift + K**: Remove link
|
|
602
|
+
|
|
603
|
+
## Theming
|
|
604
|
+
|
|
605
|
+
The editor supports Tamagui theming and can be customized with:
|
|
606
|
+
|
|
607
|
+
- **Light Theme**: Default light theme
|
|
608
|
+
- **Dark Theme**: Dark theme for low-light environments
|
|
609
|
+
- **Auto Theme**: Automatically switches based on system preference
|
|
610
|
+
|
|
611
|
+
## Accessibility
|
|
612
|
+
|
|
613
|
+
The editor is fully accessible with:
|
|
614
|
+
|
|
615
|
+
- **ARIA Labels**: All interactive elements have proper labels
|
|
616
|
+
- **Keyboard Navigation**: Full keyboard support
|
|
617
|
+
- **Screen Reader Support**: Compatible with screen readers
|
|
618
|
+
- **Focus Management**: Proper focus handling
|
|
619
|
+
- **High Contrast Support**: Works with high contrast modes
|
|
620
|
+
|
|
621
|
+
## TypeScript Support
|
|
622
|
+
|
|
623
|
+
This package is written in TypeScript and provides full type definitions. All interfaces and types are exported for use in your own code.
|
|
624
|
+
|
|
625
|
+
## License
|
|
626
|
+
|
|
627
|
+
UNLICENSED - See LICENSE file for details.
|
|
628
|
+
|
|
629
|
+
## Contributing
|
|
630
|
+
|
|
631
|
+
Contributions are welcome! Please see the contributing guidelines for more information.
|
|
632
|
+
|
|
633
|
+
## Support
|
|
634
|
+
|
|
635
|
+
For support and questions, please open an issue on GitHub.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-editor.d.ts","sourceRoot":"","sources":["../src/content-editor.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAmD,MAAM,OAAO,CAAC;AA6CxE,OAAO,EACL,kBAAkB,EAWnB,MAAM,SAAS,CAAC;AAqDjB;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAkUtD,CAAC"}
|