eddyter 1.3.37 → 1.3.38
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 +483 -444
- package/dist/App.d.ts +3 -2
- package/dist/Provider/EditorProvider.d.ts +32 -26
- package/dist/Provider/LexicalProvider.d.ts +6 -5
- package/dist/api/ai/index.d.ts +32 -31
- package/dist/api/auth.d.ts +108 -108
- package/dist/api/config/axios.d.ts +2 -1
- package/dist/api/config/endpoints.d.ts +22 -22
- package/dist/api/featureSuggestion.d.ts +23 -23
- package/dist/api/linkPreview.d.ts +15 -15
- package/dist/api/transcript/index.d.ts +21 -21
- package/dist/assets/style.css +5284 -5362
- package/dist/{babel-d3085146.js → babel-d155920e.js} +3278 -3551
- package/dist/babel-d155920e.js.map +1 -0
- package/dist/components/AiPlugin/index.d.ts +6 -6
- package/dist/components/AlignMenu/AlignMenu.d.ts +9 -8
- package/dist/components/AlignMenu/AlignMenuDrop.d.ts +3 -2
- package/dist/components/AlignMenu/index.d.ts +1 -1
- package/dist/components/AutoExpandingDemo.d.ts +6 -5
- package/dist/components/BlockFormatMenu/BlockFormatMenu.d.ts +3 -2
- package/dist/components/BlockFormatMenu/constants.d.ts +14 -14
- package/dist/components/BlockFormatMenu/index.d.ts +1 -1
- package/dist/components/ChartEditDialog.d.ts +9 -8
- package/dist/components/ChartInsertDialog.d.ts +8 -7
- package/dist/components/CodeActionMenuPlugin/components/CopyButton/index.d.ts +7 -6
- package/dist/components/CodeActionMenuPlugin/components/PrettierButton/index.d.ts +9 -8
- package/dist/components/CodeActionMenuPlugin/index.d.ts +5 -4
- package/dist/components/CodeActionMenuPlugin/utils.d.ts +1 -1
- package/dist/components/ColorPicker/ColorPicker.d.ts +3 -2
- package/dist/components/ColorPicker/index.d.ts +1 -1
- package/dist/components/CommentSidebar/CommentSidebar.d.ts +8 -7
- package/dist/components/CommentSidebar/index.d.ts +1 -1
- package/dist/components/CommentToggle/CommentToggle.d.ts +8 -7
- package/dist/components/CommentToggle/index.d.ts +1 -1
- package/dist/components/CommentView/CommentView.d.ts +9 -8
- package/dist/components/CommentView/index.d.ts +1 -1
- package/dist/components/ConfigurableEditorWithAuth.d.ts +35 -22
- package/dist/components/ContentPreview/index.d.ts +38 -0
- package/dist/components/DatePicker/DatePickerWidget.d.ts +7 -6
- package/dist/components/EmojiPickerWidget/EmojiPickerWidget.d.ts +3 -2
- package/dist/components/EmojiPickerWidget/index.d.ts +1 -1
- package/dist/components/FeatureSuggestionDialog/index.d.ts +6 -6
- package/dist/components/FileUpload/InsertFileDialog.d.ts +7 -7
- package/dist/components/FileUpload/InsertFileUploadedDialogBody.d.ts +5 -4
- package/dist/components/FileView/index.d.ts +9 -8
- package/dist/components/FontFamilySelect/FontFamilyMenu.d.ts +7 -6
- package/dist/components/FontSizePicker/FontSizeControl.d.ts +3 -2
- package/dist/components/FormatTextMenu/FormatTextMenu.d.ts +3 -2
- package/dist/components/FormatTextMenu/FormatTextMenuDrop.d.ts +3 -2
- package/dist/components/FormatTextMenu/index.d.ts +1 -1
- package/dist/components/HighlightColorPicker/HighlightColorPicker.d.ts +7 -6
- package/dist/components/HtmlViewDisplay.d.ts +3 -2
- package/dist/components/ImageComparisonDialog/index.d.ts +11 -10
- package/dist/components/ImageGenerationDialog/ImageGenerationManager.d.ts +11 -10
- package/dist/components/ImageGenerationDialog/index.d.ts +11 -10
- package/dist/components/ImageInsertTest.d.ts +3 -2
- package/dist/components/ImageView/ImageDialog/ImageUploadDialogBody.d.ts +9 -8
- package/dist/components/ImageView/ImageDialog/index.d.ts +6 -5
- package/dist/components/ImageView/ImageResizer.d.ts +16 -15
- package/dist/components/ImageView/index.d.ts +17 -16
- package/dist/components/InsertMenu/InsertMenu.d.ts +9 -8
- package/dist/components/InsertMenu/InsertMenuDrop.d.ts +9 -8
- package/dist/components/InsertMenu/index.d.ts +1 -1
- package/dist/components/LanguageSelectorDialog/index.d.ts +8 -7
- package/dist/components/LinkPreviewHover/index.d.ts +40 -0
- package/dist/components/NotePanelMenu/NotePanelMenu.d.ts +6 -5
- package/dist/components/NotePanelMenu/index.d.ts +1 -1
- package/dist/components/NotePanelView/NotePanelView.d.ts +9 -8
- package/dist/components/NotePanelView/index.d.ts +1 -1
- package/dist/components/Placeholder/Placeholder.d.ts +3 -2
- package/dist/components/Placeholder/index.d.ts +1 -1
- package/dist/components/Placeholder/styles.d.ts +1 -1
- package/dist/components/ScopedEditor.d.ts +8 -8
- package/dist/components/SignatureCaption/index.d.ts +6 -5
- package/dist/components/TableColorPicker/index.d.ts +8 -7
- package/dist/components/TableModal/TableModal.d.ts +10 -9
- package/dist/components/TextEnhanceDialog/index.d.ts +10 -9
- package/dist/components/ToneAdjustDialog/index.d.ts +8 -7
- package/dist/components/Toolbar/Toolbar.d.ts +3 -2
- package/dist/components/Toolbar/index.d.ts +1 -1
- package/dist/components/Toolbar/styles.d.ts +6 -6
- package/dist/components/VoiceTranscriptIcon/VoiceTranscriptIcon.d.ts +2 -1
- package/dist/components/VoiceTranscriptIcon/index.d.ts +1 -1
- package/dist/components/ui/avatar.d.ts +6 -6
- package/dist/components/ui/badge.d.ts +9 -8
- package/dist/components/ui/button.d.ts +11 -10
- package/dist/components/ui/calendar.d.ts +8 -7
- package/dist/components/ui/card.d.ts +8 -8
- package/dist/components/ui/checkbox.d.ts +4 -4
- package/dist/components/ui/dialog.d.ts +19 -19
- package/dist/components/ui/dropdown-menu.d.ts +27 -27
- package/dist/components/ui/input.d.ts +3 -3
- package/dist/components/ui/label.d.ts +4 -4
- package/dist/components/ui/popover.d.ts +7 -7
- package/dist/components/ui/select.d.ts +13 -13
- package/dist/components/ui/separator.d.ts +4 -4
- package/dist/components/ui/sheet.d.ts +24 -24
- package/dist/components/ui/skeleton.d.ts +3 -3
- package/dist/components/ui/tabs.d.ts +7 -7
- package/dist/components/ui/textarea.d.ts +3 -3
- package/dist/components/ui/tooltip.d.ts +7 -7
- package/dist/constants.d.ts +22 -21
- package/dist/context/CommentContext.d.ts +43 -42
- package/dist/context/HtmlViewContext.d.ts +17 -16
- package/dist/context/ToolbarContext.d.ts +56 -55
- package/dist/editorConfig.d.ts +48 -48
- package/dist/{estree-164983f6.js → estree-b1fff53b.js} +1778 -1763
- package/dist/estree-b1fff53b.js.map +1 -0
- package/dist/hooks/useAutoExpandingHeight.d.ts +15 -15
- package/dist/hooks/useBlockFormat.d.ts +17 -16
- package/dist/hooks/useColorPicker.d.ts +6 -6
- package/dist/hooks/useCustomCommands.d.ts +3 -2
- package/dist/hooks/useDebounce.d.ts +1 -1
- package/dist/hooks/useEditorToolbar.d.ts +10 -9
- package/dist/hooks/useInsertMenu.d.ts +9 -9
- package/dist/hooks/useModal.d.ts +5 -5
- package/dist/hooks/useReactNativeBridge.d.ts +54 -54
- package/dist/hooks/useS3Uploader.d.ts +11 -11
- package/dist/hooks/useVoiceToText.d.ts +20 -20
- package/dist/{html-5586dbf6.js → html-f95ee5dc.js} +656 -701
- package/dist/html-f95ee5dc.js.map +1 -0
- package/dist/{html2pdf.bundle-d4225b87.js → html2pdf.bundle-d21122e4.js} +2 -2
- package/dist/html2pdf.bundle-d21122e4.js.map +1 -0
- package/dist/{html2pdf.bundle.min-4f1c3930.js → html2pdf.bundle.min-d6fba18e.js} +2 -2
- package/dist/html2pdf.bundle.min-d6fba18e.js.map +1 -0
- package/dist/{index-6717344b.js → index-0bc350db.js} +1475 -1537
- package/dist/index-0bc350db.js.map +1 -0
- package/dist/{index-35336e5d.js → index-39c10e00.js} +3 -3
- package/dist/index-39c10e00.js.map +1 -0
- package/dist/{index-da40f793.js → index-f51de846.js} +3 -3
- package/dist/index-f51de846.js.map +1 -0
- package/dist/index.d.ts +14 -10
- package/dist/index.js +7 -5
- package/dist/lib/utils.d.ts +2 -1
- package/dist/main.d.ts +1 -0
- package/dist/{markdown-d513479b.js → markdown-1d9e6c3f.js} +1789 -1836
- package/dist/markdown-1d9e6c3f.js.map +1 -0
- package/dist/nodes/ChartNode.d.ts +41 -40
- package/dist/nodes/CommentNode.d.ts +34 -33
- package/dist/nodes/CommentedTextNode.d.ts +29 -28
- package/dist/nodes/EmbedNode.d.ts +32 -31
- package/dist/nodes/FileNode.d.ts +32 -31
- package/dist/nodes/ImageNode.d.ts +65 -64
- package/dist/nodes/MentionNode.d.ts +75 -74
- package/dist/nodes/NotePanelNode.d.ts +31 -30
- package/dist/pages/ConfigurableEditor/ConfigurableEditor.d.ts +25 -24
- package/dist/pages/ConfigurableEditor/index.d.ts +2 -2
- package/dist/pages/NotFound.d.ts +2 -2
- package/dist/pages/RichTextEditor.d.ts +6 -6
- package/dist/pages/TextareaEditor.d.ts +6 -6
- package/dist/pages/styles.d.ts +5 -5
- package/dist/plugins/AIChatPlugin.d.ts +11 -10
- package/dist/plugins/AndroidKeyboardFixPlugin.d.ts +16 -16
- package/dist/plugins/AutocompletePlugin.d.ts +22 -22
- package/dist/plugins/CodeBlockNormalizerPlugin.d.ts +8 -8
- package/dist/plugins/CodeBlockSelectAllPlugin.d.ts +8 -8
- package/dist/plugins/CodeHighlightPlugin.d.ts +3 -2
- package/dist/plugins/CombinedAutocompletGrammarPlugin.d.ts +21 -20
- package/dist/plugins/CommentBubblePlugin.d.ts +3 -2
- package/dist/plugins/CommentPlugin.d.ts +7 -6
- package/dist/plugins/CustomHorizontalRulePlugin/CustomHorizontalRuleNode.d.ts +29 -28
- package/dist/plugins/CustomHorizontalRulePlugin/CustomHorizontalRulePlugin.d.ts +3 -3
- package/dist/plugins/CustomHorizontalRulePlugin/HorizontalRuleCustomizationDialog.d.ts +7 -6
- package/dist/plugins/CustomHorizontalRulePlugin/index.d.ts +3 -3
- package/dist/plugins/DragDropPastePlugin/index.d.ts +8 -8
- package/dist/plugins/EmbedPreviewPlugin/FloatingEmbedMenuPlugin.d.ts +4 -3
- package/dist/plugins/EmbedPreviewPlugin/index.d.ts +6 -5
- package/dist/plugins/FilePlugin.d.ts +8 -7
- package/dist/plugins/FloatingLinkEditorPlugin/index.d.ts +6 -5
- package/dist/plugins/FloatingTextFormatToolbarPlugin/index.d.ts +27 -26
- package/dist/plugins/GrammarCheckPlugin.d.ts +2 -1
- package/dist/plugins/HtmlCodeViewPlugin/index.d.ts +2 -2
- package/dist/plugins/HtmlImportPlugin.d.ts +5 -5
- package/dist/plugins/HtmlSyncPlugin.d.ts +3 -3
- package/dist/plugins/ImagePlugin.d.ts +7 -6
- package/dist/plugins/LinkPlugin/index.d.ts +6 -5
- package/dist/plugins/LinkPreviewPlugin/index.d.ts +4 -4
- package/dist/plugins/LocalStoragePlugin.d.ts +7 -6
- package/dist/plugins/MarkdownShortcutsPlugin/index.d.ts +20 -20
- package/dist/plugins/MentionsPlugin/index.d.ts +7 -6
- package/dist/plugins/NotePanelPlugin.d.ts +7 -6
- package/dist/plugins/PasteOptionsPlugin/index.d.ts +17 -17
- package/dist/plugins/RichTextPastePlugin/index.d.ts +6 -5
- package/dist/plugins/SignatureCanvasPlugin/SignatureCanvasDialog.d.ts +6 -5
- package/dist/plugins/SignatureCanvasPlugin/SignatureCanvasPlugin.d.ts +9 -9
- package/dist/plugins/SignatureCanvasPlugin/index.d.ts +2 -2
- package/dist/plugins/SlashCommandPlugin/index.d.ts +2 -2
- package/dist/plugins/TableActionMenuPlugin/index.d.ts +6 -5
- package/dist/plugins/TableCellResizer/index.d.ts +2 -1
- package/dist/plugins/TableHoverActionsPlugin/index.d.ts +4 -4
- package/dist/plugins/TablePlugin.d.ts +5 -4
- package/dist/plugins/Tableimageautoresizeplugin.d.ts +1 -1
- package/dist/plugins/TextEnhancePlugin.d.ts +6 -6
- package/dist/plugins/TreeViewPlugin.d.ts +3 -2
- package/dist/plugins/UsageTrackingPlugin.d.ts +15 -15
- package/dist/plugins/VoiceTranscriptPlugin.d.ts +22 -22
- package/dist/plugins/WordCountPlugin.d.ts +3 -2
- package/dist/{postcss-f084f74d.js → postcss-c2592f3f.js} +1357 -1378
- package/dist/postcss-c2592f3f.js.map +1 -0
- package/dist/services/chartService.d.ts +20 -0
- package/dist/standalone-bcc7f37a.js +2649 -0
- package/dist/standalone-bcc7f37a.js.map +1 -0
- package/dist/styles/PlaygroundEditorTheme.d.ts +3 -2
- package/dist/types.d.ts +150 -149
- package/dist/typescript-48c10f50.js +13601 -0
- package/dist/typescript-48c10f50.js.map +1 -0
- package/dist/ui/ColorPicker.d.ts +14 -13
- package/dist/ui/Icons.d.ts +48 -48
- package/dist/ui/TextInput.d.ts +11 -10
- package/dist/utils/dateFormats.d.ts +33 -33
- package/dist/utils/debounce.d.ts +6 -5
- package/dist/utils/editorStyleConverter.d.ts +17 -16
- package/dist/utils/export.d.ts +2 -1
- package/dist/utils/getDOMRangeRect.d.ts +13 -13
- package/dist/utils/getSelectedNode.d.ts +3 -2
- package/dist/utils/helper.d.ts +3 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/invarient.d.ts +1 -1
- package/dist/utils/setFloatingElemPosition.d.ts +8 -8
- package/dist/utils/setFloatingElemPositionForLinkEditor.d.ts +1 -1
- package/dist/utils/url.d.ts +9 -9
- package/package.json +149 -149
- package/dist/babel-d3085146.js.map +0 -1
- package/dist/estree-164983f6.js.map +0 -1
- package/dist/html-5586dbf6.js.map +0 -1
- package/dist/html2pdf.bundle-d4225b87.js.map +0 -1
- package/dist/html2pdf.bundle.min-4f1c3930.js.map +0 -1
- package/dist/index-35336e5d.js.map +0 -1
- package/dist/index-6717344b.js.map +0 -1
- package/dist/index-da40f793.js.map +0 -1
- package/dist/markdown-d513479b.js.map +0 -1
- package/dist/plugins/FloatingEnhanceButton/index.d.ts +0 -4
- package/dist/postcss-f084f74d.js.map +0 -1
- package/dist/standalone-5a8c6b7e.js +0 -2518
- package/dist/standalone-5a8c6b7e.js.map +0 -1
- package/dist/typescript-b1005db4.js +0 -13705
- package/dist/typescript-b1005db4.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,444 +1,483 @@
|
|
|
1
|
-
# Eddyter
|
|
2
|
-
|
|
3
|
-
A configurable rich text editor component with AI-powered features and API key authentication.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install eddyter
|
|
9
|
-
# or
|
|
10
|
-
yarn add eddyter
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Features
|
|
14
|
-
|
|
15
|
-
- Rich text editor with extensive formatting options
|
|
16
|
-
- API key authentication
|
|
17
|
-
- Configurable UI components (toolbar, floating menu)
|
|
18
|
-
- HTML view option
|
|
19
|
-
- Support for tables, images, links, and more
|
|
20
|
-
- AI chat integration (for premium plans)
|
|
21
|
-
- Environment-based API configuration
|
|
22
|
-
|
|
23
|
-
## React Native Integration
|
|
24
|
-
|
|
25
|
-
You can use Eddyter in React Native applications via WebView by loading a deployed version of the editor.
|
|
26
|
-
|
|
27
|
-
### Prerequisites
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npm install react-native-webview
|
|
31
|
-
# or
|
|
32
|
-
yarn add react-native-webview
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### RichTextEditor Component
|
|
36
|
-
|
|
37
|
-
Create a reusable `RichTextEditor` component that wraps the WebView:
|
|
38
|
-
|
|
39
|
-
```tsx
|
|
40
|
-
import React, { useRef, useState, useCallback } from 'react';
|
|
41
|
-
import { View, ActivityIndicator, Text, StyleSheet } from 'react-native';
|
|
42
|
-
import { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
43
|
-
|
|
44
|
-
interface RichTextEditorProps {
|
|
45
|
-
editorBaseUrl: string;
|
|
46
|
-
apiKey: string;
|
|
47
|
-
initialContent?: string;
|
|
48
|
-
theme?: 'light' | 'dark';
|
|
49
|
-
style?: object;
|
|
50
|
-
onChange?: (content: string) => void;
|
|
51
|
-
onReady?: () => void;
|
|
52
|
-
onAuthSuccess?: () => void;
|
|
53
|
-
onAuthError?: (error: string) => void;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
interface WebViewMessage {
|
|
57
|
-
type: string;
|
|
58
|
-
payload?: Record<string, unknown>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const RichTextEditor: React.FC<RichTextEditorProps> = ({
|
|
62
|
-
editorBaseUrl,
|
|
63
|
-
apiKey,
|
|
64
|
-
initialContent,
|
|
65
|
-
theme = 'light',
|
|
66
|
-
style,
|
|
67
|
-
onChange,
|
|
68
|
-
onReady,
|
|
69
|
-
onAuthSuccess,
|
|
70
|
-
onAuthError,
|
|
71
|
-
}) => {
|
|
72
|
-
const webViewRef = useRef<WebView>(null);
|
|
73
|
-
const [isLoading, setIsLoading] = useState(true);
|
|
74
|
-
const [error, setError] = useState<string | null>(null);
|
|
75
|
-
|
|
76
|
-
const buildEditorUrl = () => {
|
|
77
|
-
const baseUrl = editorBaseUrl.replace(/\/$/, '');
|
|
78
|
-
const params = new URLSearchParams();
|
|
79
|
-
if (apiKey) params.append('apiKey', apiKey);
|
|
80
|
-
if (theme) params.append('theme', theme);
|
|
81
|
-
return `${baseUrl}?${params.toString()}`;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const handleMessage = useCallback((event: WebViewMessageEvent) => {
|
|
85
|
-
try {
|
|
86
|
-
const message: WebViewMessage = JSON.parse(event.nativeEvent.data);
|
|
87
|
-
|
|
88
|
-
switch (message.type) {
|
|
89
|
-
case 'EDITOR_READY':
|
|
90
|
-
setIsLoading(false);
|
|
91
|
-
onReady?.();
|
|
92
|
-
// Send initial content after editor is ready
|
|
93
|
-
if (initialContent && webViewRef.current) {
|
|
94
|
-
webViewRef.current.postMessage(
|
|
95
|
-
JSON.stringify({
|
|
96
|
-
type: 'SET_CONTENT',
|
|
97
|
-
payload: { content: initialContent },
|
|
98
|
-
})
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
|
|
103
|
-
case 'CONTENT_CHANGE':
|
|
104
|
-
onChange?.(message.payload?.content as string || '');
|
|
105
|
-
break;
|
|
106
|
-
|
|
107
|
-
case 'AUTH_SUCCESS':
|
|
108
|
-
onAuthSuccess?.();
|
|
109
|
-
break;
|
|
110
|
-
|
|
111
|
-
case 'AUTH_ERROR':
|
|
112
|
-
onAuthError?.(message.payload?.error as string);
|
|
113
|
-
break;
|
|
114
|
-
}
|
|
115
|
-
} catch (e) {
|
|
116
|
-
console.warn('[RichTextEditor] Failed to parse message:', e);
|
|
117
|
-
}
|
|
118
|
-
}, [onChange, onReady, onAuthSuccess, onAuthError, initialContent]);
|
|
119
|
-
|
|
120
|
-
const handleError = useCallback((syntheticEvent: any) => {
|
|
121
|
-
const { nativeEvent } = syntheticEvent;
|
|
122
|
-
setError(nativeEvent.description || 'Failed to load editor');
|
|
123
|
-
setIsLoading(false);
|
|
124
|
-
}, []);
|
|
125
|
-
|
|
126
|
-
if (error) {
|
|
127
|
-
return (
|
|
128
|
-
<View style={styles.errorContainer}>
|
|
129
|
-
<Text style={styles.errorText}>Failed to load editor</Text>
|
|
130
|
-
<Text style={styles.errorDetail}>{error}</Text>
|
|
131
|
-
</View>
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<View style={[styles.container, style]}>
|
|
137
|
-
<WebView
|
|
138
|
-
ref={webViewRef}
|
|
139
|
-
source={{ uri: buildEditorUrl() }}
|
|
140
|
-
style={styles.webview}
|
|
141
|
-
onMessage={handleMessage}
|
|
142
|
-
onError={handleError}
|
|
143
|
-
javaScriptEnabled={true}
|
|
144
|
-
domStorageEnabled={true}
|
|
145
|
-
startInLoadingState={false}
|
|
146
|
-
scalesPageToFit={true}
|
|
147
|
-
allowsInlineMediaPlayback={true}
|
|
148
|
-
keyboardDisplayRequiresUserAction={false}
|
|
149
|
-
/>
|
|
150
|
-
{isLoading && (
|
|
151
|
-
<View style={styles.loadingOverlay}>
|
|
152
|
-
<ActivityIndicator size="large" color="#007AFF" />
|
|
153
|
-
</View>
|
|
154
|
-
)}
|
|
155
|
-
</View>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const styles = StyleSheet.create({
|
|
160
|
-
container: { flex: 1 },
|
|
161
|
-
webview: { flex: 1, backgroundColor: 'transparent' },
|
|
162
|
-
loadingOverlay: {
|
|
163
|
-
...StyleSheet.absoluteFillObject,
|
|
164
|
-
justifyContent: 'center',
|
|
165
|
-
alignItems: 'center',
|
|
166
|
-
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
167
|
-
},
|
|
168
|
-
errorContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 },
|
|
169
|
-
errorText: { fontSize: 18, fontWeight: 'bold', color: '#FF3B30' },
|
|
170
|
-
errorDetail: { fontSize: 14, color: '#666', marginTop: 8, textAlign: 'center' },
|
|
171
|
-
});
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Usage Example
|
|
175
|
-
|
|
176
|
-
```tsx
|
|
177
|
-
import React, { useState } from 'react';
|
|
178
|
-
import { View, KeyboardAvoidingView, Platform } from 'react-native';
|
|
179
|
-
import { RichTextEditor } from './components/RichTextEditor';
|
|
180
|
-
|
|
181
|
-
const EDITOR_CONFIG = {
|
|
182
|
-
editorBaseUrl: 'https://your-deployed-editor-url.com',
|
|
183
|
-
apiKey: 'your-api-key',
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
function NoteEditorScreen() {
|
|
187
|
-
const [content, setContent] = useState('');
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<KeyboardAvoidingView
|
|
191
|
-
style={{ flex: 1 }}
|
|
192
|
-
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
193
|
-
>
|
|
194
|
-
<RichTextEditor
|
|
195
|
-
editorBaseUrl={EDITOR_CONFIG.editorBaseUrl}
|
|
196
|
-
apiKey={EDITOR_CONFIG.apiKey}
|
|
197
|
-
theme="light"
|
|
198
|
-
initialContent="<p>Start writing...</p>"
|
|
199
|
-
onChange={setContent}
|
|
200
|
-
onReady={() => console.log('Editor ready')}
|
|
201
|
-
onAuthSuccess={() => console.log('Authenticated')}
|
|
202
|
-
onAuthError={(error) => console.error('Auth failed:', error)}
|
|
203
|
-
/>
|
|
204
|
-
</KeyboardAvoidingView>
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
### Message Protocol
|
|
210
|
-
|
|
211
|
-
The editor and React Native communicate via `postMessage`. Here are the supported message types:
|
|
212
|
-
|
|
213
|
-
| Message Type | Direction | Description |
|
|
214
|
-
|--------------|-----------|-------------|
|
|
215
|
-
| `EDITOR_READY` | Editor → RN | Editor has finished loading |
|
|
216
|
-
| `CONTENT_CHANGE` | Editor → RN | Content was modified (payload: `{ content: string }`) |
|
|
217
|
-
| `AUTH_SUCCESS` | Editor → RN | API key authentication succeeded |
|
|
218
|
-
| `AUTH_ERROR` | Editor → RN | Authentication failed (payload: `{ error: string }`) |
|
|
219
|
-
| `SET_CONTENT` | RN → Editor | Set editor content (payload: `{ content: string }`) |
|
|
220
|
-
|
|
221
|
-
### Sending Content to Editor
|
|
222
|
-
|
|
223
|
-
After receiving the `EDITOR_READY` message, you can programmatically set content:
|
|
224
|
-
|
|
225
|
-
```tsx
|
|
226
|
-
webViewRef.current?.postMessage(
|
|
227
|
-
JSON.stringify({
|
|
228
|
-
type: 'SET_CONTENT',
|
|
229
|
-
payload: { content: '<p>New content here</p>' },
|
|
230
|
-
})
|
|
231
|
-
);
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
## Usage
|
|
235
|
-
|
|
236
|
-
### Important: Importing Styles
|
|
237
|
-
To ensure proper styling of the editor components including tables, you must import the package's CSS:
|
|
238
|
-
|
|
239
|
-
```jsx
|
|
240
|
-
// Import the styles in your application
|
|
241
|
-
import 'eddyter/style.css';
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
### Basic Setup
|
|
245
|
-
|
|
246
|
-
```jsx
|
|
247
|
-
import React from 'react';
|
|
248
|
-
import {
|
|
249
|
-
ConfigurableEditorWithAuth,
|
|
250
|
-
EditorProvider,
|
|
251
|
-
defaultEditorConfig
|
|
252
|
-
} from 'eddyter';
|
|
253
|
-
// Import required styles
|
|
254
|
-
import 'eddyter/style.css';
|
|
255
|
-
|
|
256
|
-
function App() {
|
|
257
|
-
const apiKey = 'your-api-key'; // Replace with your actual API key
|
|
258
|
-
|
|
259
|
-
// Current logged-in user for comments
|
|
260
|
-
const currentUser = {
|
|
261
|
-
id: 'user-123',
|
|
262
|
-
name: 'John Doe',
|
|
263
|
-
email: 'john@example.com',
|
|
264
|
-
avatar: 'https://example.com/avatar.jpg' // optional
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const handleContentChange = (html) => {
|
|
268
|
-
console.log('Editor HTML content:', html);
|
|
269
|
-
// Handle the HTML content (save to state, send to server, etc.)
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
return (
|
|
273
|
-
<EditorProvider
|
|
274
|
-
defaultFontFamilies={defaultEditorConfig.defaultFontFamilies}
|
|
275
|
-
currentUser={currentUser}
|
|
276
|
-
>
|
|
277
|
-
<ConfigurableEditorWithAuth
|
|
278
|
-
apiKey={apiKey}
|
|
279
|
-
onChange={handleContentChange}
|
|
280
|
-
initialContent="<p>Welcome to the editor!</p>"
|
|
281
|
-
mentionUserList={["Alice", "Bob", "Charlie"]}
|
|
282
|
-
onAuthSuccess={() => console.log('Authentication successful')}
|
|
283
|
-
onAuthError={(error) => console.error('Authentication error:', error)}
|
|
284
|
-
/>
|
|
285
|
-
</EditorProvider>
|
|
286
|
-
);
|
|
287
|
-
}
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## API Reference
|
|
291
|
-
|
|
292
|
-
### EditorProvider
|
|
293
|
-
|
|
294
|
-
Provides authentication and configuration context for the editor.
|
|
295
|
-
|
|
296
|
-
#### Props
|
|
297
|
-
|
|
298
|
-
- `children`: React nodes to render
|
|
299
|
-
- `defaultFontFamilies`: Array of font names (optional)
|
|
300
|
-
- `currentUser`: Current logged-in user for comments (optional) - Object with `id`, `name`, `email`, and optional `avatar`
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
- `
|
|
311
|
-
- `
|
|
312
|
-
- `
|
|
313
|
-
- `
|
|
314
|
-
- `
|
|
315
|
-
- `
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
import '
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
import '
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
import '
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
1
|
+
# Eddyter
|
|
2
|
+
|
|
3
|
+
A configurable rich text editor component with AI-powered features and API key authentication.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install eddyter
|
|
9
|
+
# or
|
|
10
|
+
yarn add eddyter
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Rich text editor with extensive formatting options
|
|
16
|
+
- API key authentication
|
|
17
|
+
- Configurable UI components (toolbar, floating menu)
|
|
18
|
+
- HTML view option
|
|
19
|
+
- Support for tables, images, links, and more
|
|
20
|
+
- AI chat integration (for premium plans)
|
|
21
|
+
- Environment-based API configuration
|
|
22
|
+
|
|
23
|
+
## React Native Integration
|
|
24
|
+
|
|
25
|
+
You can use Eddyter in React Native applications via WebView by loading a deployed version of the editor.
|
|
26
|
+
|
|
27
|
+
### Prerequisites
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm install react-native-webview
|
|
31
|
+
# or
|
|
32
|
+
yarn add react-native-webview
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### RichTextEditor Component
|
|
36
|
+
|
|
37
|
+
Create a reusable `RichTextEditor` component that wraps the WebView:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import React, { useRef, useState, useCallback } from 'react';
|
|
41
|
+
import { View, ActivityIndicator, Text, StyleSheet } from 'react-native';
|
|
42
|
+
import { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
43
|
+
|
|
44
|
+
interface RichTextEditorProps {
|
|
45
|
+
editorBaseUrl: string;
|
|
46
|
+
apiKey: string;
|
|
47
|
+
initialContent?: string;
|
|
48
|
+
theme?: 'light' | 'dark';
|
|
49
|
+
style?: object;
|
|
50
|
+
onChange?: (content: string) => void;
|
|
51
|
+
onReady?: () => void;
|
|
52
|
+
onAuthSuccess?: () => void;
|
|
53
|
+
onAuthError?: (error: string) => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface WebViewMessage {
|
|
57
|
+
type: string;
|
|
58
|
+
payload?: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const RichTextEditor: React.FC<RichTextEditorProps> = ({
|
|
62
|
+
editorBaseUrl,
|
|
63
|
+
apiKey,
|
|
64
|
+
initialContent,
|
|
65
|
+
theme = 'light',
|
|
66
|
+
style,
|
|
67
|
+
onChange,
|
|
68
|
+
onReady,
|
|
69
|
+
onAuthSuccess,
|
|
70
|
+
onAuthError,
|
|
71
|
+
}) => {
|
|
72
|
+
const webViewRef = useRef<WebView>(null);
|
|
73
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
74
|
+
const [error, setError] = useState<string | null>(null);
|
|
75
|
+
|
|
76
|
+
const buildEditorUrl = () => {
|
|
77
|
+
const baseUrl = editorBaseUrl.replace(/\/$/, '');
|
|
78
|
+
const params = new URLSearchParams();
|
|
79
|
+
if (apiKey) params.append('apiKey', apiKey);
|
|
80
|
+
if (theme) params.append('theme', theme);
|
|
81
|
+
return `${baseUrl}?${params.toString()}`;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const handleMessage = useCallback((event: WebViewMessageEvent) => {
|
|
85
|
+
try {
|
|
86
|
+
const message: WebViewMessage = JSON.parse(event.nativeEvent.data);
|
|
87
|
+
|
|
88
|
+
switch (message.type) {
|
|
89
|
+
case 'EDITOR_READY':
|
|
90
|
+
setIsLoading(false);
|
|
91
|
+
onReady?.();
|
|
92
|
+
// Send initial content after editor is ready
|
|
93
|
+
if (initialContent && webViewRef.current) {
|
|
94
|
+
webViewRef.current.postMessage(
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
type: 'SET_CONTENT',
|
|
97
|
+
payload: { content: initialContent },
|
|
98
|
+
})
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'CONTENT_CHANGE':
|
|
104
|
+
onChange?.(message.payload?.content as string || '');
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
case 'AUTH_SUCCESS':
|
|
108
|
+
onAuthSuccess?.();
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'AUTH_ERROR':
|
|
112
|
+
onAuthError?.(message.payload?.error as string);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
} catch (e) {
|
|
116
|
+
console.warn('[RichTextEditor] Failed to parse message:', e);
|
|
117
|
+
}
|
|
118
|
+
}, [onChange, onReady, onAuthSuccess, onAuthError, initialContent]);
|
|
119
|
+
|
|
120
|
+
const handleError = useCallback((syntheticEvent: any) => {
|
|
121
|
+
const { nativeEvent } = syntheticEvent;
|
|
122
|
+
setError(nativeEvent.description || 'Failed to load editor');
|
|
123
|
+
setIsLoading(false);
|
|
124
|
+
}, []);
|
|
125
|
+
|
|
126
|
+
if (error) {
|
|
127
|
+
return (
|
|
128
|
+
<View style={styles.errorContainer}>
|
|
129
|
+
<Text style={styles.errorText}>Failed to load editor</Text>
|
|
130
|
+
<Text style={styles.errorDetail}>{error}</Text>
|
|
131
|
+
</View>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<View style={[styles.container, style]}>
|
|
137
|
+
<WebView
|
|
138
|
+
ref={webViewRef}
|
|
139
|
+
source={{ uri: buildEditorUrl() }}
|
|
140
|
+
style={styles.webview}
|
|
141
|
+
onMessage={handleMessage}
|
|
142
|
+
onError={handleError}
|
|
143
|
+
javaScriptEnabled={true}
|
|
144
|
+
domStorageEnabled={true}
|
|
145
|
+
startInLoadingState={false}
|
|
146
|
+
scalesPageToFit={true}
|
|
147
|
+
allowsInlineMediaPlayback={true}
|
|
148
|
+
keyboardDisplayRequiresUserAction={false}
|
|
149
|
+
/>
|
|
150
|
+
{isLoading && (
|
|
151
|
+
<View style={styles.loadingOverlay}>
|
|
152
|
+
<ActivityIndicator size="large" color="#007AFF" />
|
|
153
|
+
</View>
|
|
154
|
+
)}
|
|
155
|
+
</View>
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
const styles = StyleSheet.create({
|
|
160
|
+
container: { flex: 1 },
|
|
161
|
+
webview: { flex: 1, backgroundColor: 'transparent' },
|
|
162
|
+
loadingOverlay: {
|
|
163
|
+
...StyleSheet.absoluteFillObject,
|
|
164
|
+
justifyContent: 'center',
|
|
165
|
+
alignItems: 'center',
|
|
166
|
+
backgroundColor: 'rgba(255, 255, 255, 0.9)',
|
|
167
|
+
},
|
|
168
|
+
errorContainer: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20 },
|
|
169
|
+
errorText: { fontSize: 18, fontWeight: 'bold', color: '#FF3B30' },
|
|
170
|
+
errorDetail: { fontSize: 14, color: '#666', marginTop: 8, textAlign: 'center' },
|
|
171
|
+
});
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Usage Example
|
|
175
|
+
|
|
176
|
+
```tsx
|
|
177
|
+
import React, { useState } from 'react';
|
|
178
|
+
import { View, KeyboardAvoidingView, Platform } from 'react-native';
|
|
179
|
+
import { RichTextEditor } from './components/RichTextEditor';
|
|
180
|
+
|
|
181
|
+
const EDITOR_CONFIG = {
|
|
182
|
+
editorBaseUrl: 'https://your-deployed-editor-url.com',
|
|
183
|
+
apiKey: 'your-api-key',
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
function NoteEditorScreen() {
|
|
187
|
+
const [content, setContent] = useState('');
|
|
188
|
+
|
|
189
|
+
return (
|
|
190
|
+
<KeyboardAvoidingView
|
|
191
|
+
style={{ flex: 1 }}
|
|
192
|
+
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
|
|
193
|
+
>
|
|
194
|
+
<RichTextEditor
|
|
195
|
+
editorBaseUrl={EDITOR_CONFIG.editorBaseUrl}
|
|
196
|
+
apiKey={EDITOR_CONFIG.apiKey}
|
|
197
|
+
theme="light"
|
|
198
|
+
initialContent="<p>Start writing...</p>"
|
|
199
|
+
onChange={setContent}
|
|
200
|
+
onReady={() => console.log('Editor ready')}
|
|
201
|
+
onAuthSuccess={() => console.log('Authenticated')}
|
|
202
|
+
onAuthError={(error) => console.error('Auth failed:', error)}
|
|
203
|
+
/>
|
|
204
|
+
</KeyboardAvoidingView>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Message Protocol
|
|
210
|
+
|
|
211
|
+
The editor and React Native communicate via `postMessage`. Here are the supported message types:
|
|
212
|
+
|
|
213
|
+
| Message Type | Direction | Description |
|
|
214
|
+
|--------------|-----------|-------------|
|
|
215
|
+
| `EDITOR_READY` | Editor → RN | Editor has finished loading |
|
|
216
|
+
| `CONTENT_CHANGE` | Editor → RN | Content was modified (payload: `{ content: string }`) |
|
|
217
|
+
| `AUTH_SUCCESS` | Editor → RN | API key authentication succeeded |
|
|
218
|
+
| `AUTH_ERROR` | Editor → RN | Authentication failed (payload: `{ error: string }`) |
|
|
219
|
+
| `SET_CONTENT` | RN → Editor | Set editor content (payload: `{ content: string }`) |
|
|
220
|
+
|
|
221
|
+
### Sending Content to Editor
|
|
222
|
+
|
|
223
|
+
After receiving the `EDITOR_READY` message, you can programmatically set content:
|
|
224
|
+
|
|
225
|
+
```tsx
|
|
226
|
+
webViewRef.current?.postMessage(
|
|
227
|
+
JSON.stringify({
|
|
228
|
+
type: 'SET_CONTENT',
|
|
229
|
+
payload: { content: '<p>New content here</p>' },
|
|
230
|
+
})
|
|
231
|
+
);
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Usage
|
|
235
|
+
|
|
236
|
+
### Important: Importing Styles
|
|
237
|
+
To ensure proper styling of the editor components including tables, you must import the package's CSS:
|
|
238
|
+
|
|
239
|
+
```jsx
|
|
240
|
+
// Import the styles in your application
|
|
241
|
+
import 'eddyter/style.css';
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Basic Setup
|
|
245
|
+
|
|
246
|
+
```jsx
|
|
247
|
+
import React from 'react';
|
|
248
|
+
import {
|
|
249
|
+
ConfigurableEditorWithAuth,
|
|
250
|
+
EditorProvider,
|
|
251
|
+
defaultEditorConfig
|
|
252
|
+
} from 'eddyter';
|
|
253
|
+
// Import required styles
|
|
254
|
+
import 'eddyter/style.css';
|
|
255
|
+
|
|
256
|
+
function App() {
|
|
257
|
+
const apiKey = 'your-api-key'; // Replace with your actual API key
|
|
258
|
+
|
|
259
|
+
// Current logged-in user for comments
|
|
260
|
+
const currentUser = {
|
|
261
|
+
id: 'user-123',
|
|
262
|
+
name: 'John Doe',
|
|
263
|
+
email: 'john@example.com',
|
|
264
|
+
avatar: 'https://example.com/avatar.jpg' // optional
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const handleContentChange = (html) => {
|
|
268
|
+
console.log('Editor HTML content:', html);
|
|
269
|
+
// Handle the HTML content (save to state, send to server, etc.)
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
return (
|
|
273
|
+
<EditorProvider
|
|
274
|
+
defaultFontFamilies={defaultEditorConfig.defaultFontFamilies}
|
|
275
|
+
currentUser={currentUser}
|
|
276
|
+
>
|
|
277
|
+
<ConfigurableEditorWithAuth
|
|
278
|
+
apiKey={apiKey}
|
|
279
|
+
onChange={handleContentChange}
|
|
280
|
+
initialContent="<p>Welcome to the editor!</p>"
|
|
281
|
+
mentionUserList={["Alice", "Bob", "Charlie"]}
|
|
282
|
+
onAuthSuccess={() => console.log('Authentication successful')}
|
|
283
|
+
onAuthError={(error) => console.error('Authentication error:', error)}
|
|
284
|
+
/>
|
|
285
|
+
</EditorProvider>
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## API Reference
|
|
291
|
+
|
|
292
|
+
### EditorProvider
|
|
293
|
+
|
|
294
|
+
Provides authentication and configuration context for the editor.
|
|
295
|
+
|
|
296
|
+
#### Props
|
|
297
|
+
|
|
298
|
+
- `children`: React nodes to render
|
|
299
|
+
- `defaultFontFamilies`: Array of font names (optional)
|
|
300
|
+
- `currentUser`: Current logged-in user for comments (optional) - Object with `id`, `name`, `email`, and optional `avatar`
|
|
301
|
+
- `enableLinkPreview`: Enable automatic link preview on hover (optional, default: `true`)
|
|
302
|
+
- `apiKey`: API key for authentication (optional) - Required only if you need link preview to work immediately without opening the editor first
|
|
303
|
+
|
|
304
|
+
### ConfigurableEditorWithAuth
|
|
305
|
+
|
|
306
|
+
The main editor component with authentication.
|
|
307
|
+
|
|
308
|
+
#### Props
|
|
309
|
+
|
|
310
|
+
- `apiKey`: Your API key for authentication (required)
|
|
311
|
+
- `initialContent`: Initial HTML content for the editor (optional) - string
|
|
312
|
+
- `onChange`: Callback function when editor content changes (optional) - receives HTML string
|
|
313
|
+
- `defaultFontFamilies`: Array of font names for the font selector (optional)
|
|
314
|
+
- `mentionUserList`: Array of usernames for mention functionality (optional) - Array of strings like `["Alice", "Bob", "Charlie"]`
|
|
315
|
+
- `onAuthSuccess`: Callback function when authentication is successful (optional)
|
|
316
|
+
- `onAuthError`: Callback function when authentication fails (optional)
|
|
317
|
+
- `customVerifyKey`: Custom function to verify API key (optional)
|
|
318
|
+
|
|
319
|
+
## Examples
|
|
320
|
+
|
|
321
|
+
### Basic Editor with Authentication
|
|
322
|
+
|
|
323
|
+
```jsx
|
|
324
|
+
import React from 'react';
|
|
325
|
+
import { ConfigurableEditorWithAuth, EditorProvider } from 'eddyter';
|
|
326
|
+
import 'eddyter/style.css';
|
|
327
|
+
|
|
328
|
+
function App() {
|
|
329
|
+
return (
|
|
330
|
+
<EditorProvider>
|
|
331
|
+
<ConfigurableEditorWithAuth
|
|
332
|
+
apiKey="your-api-key"
|
|
333
|
+
onAuthSuccess={() => console.log('Authenticated')}
|
|
334
|
+
onAuthError={(error) => console.error(error)}
|
|
335
|
+
/>
|
|
336
|
+
</EditorProvider>
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
### Editor with Content Handling
|
|
342
|
+
|
|
343
|
+
```jsx
|
|
344
|
+
import React, { useState } from 'react';
|
|
345
|
+
import { ConfigurableEditorWithAuth, EditorProvider } from 'eddyter';
|
|
346
|
+
import 'eddyter/style.css';
|
|
347
|
+
|
|
348
|
+
function App() {
|
|
349
|
+
const [editorContent, setEditorContent] = useState('');
|
|
350
|
+
|
|
351
|
+
// Current user (typically from your auth system)
|
|
352
|
+
const currentUser = {
|
|
353
|
+
id: 'user-456',
|
|
354
|
+
name: 'Jane Smith',
|
|
355
|
+
email: 'jane@example.com'
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const handleContentChange = (html) => {
|
|
359
|
+
setEditorContent(html);
|
|
360
|
+
console.log('Current content:', html);
|
|
361
|
+
// You can also save to localStorage, send to API, etc.
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
const handleSave = () => {
|
|
365
|
+
// Save the HTML content to your backend or localStorage
|
|
366
|
+
localStorage.setItem('saved-content', editorContent);
|
|
367
|
+
console.log('Content saved!');
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const loadSavedContent = () => {
|
|
371
|
+
const saved = '<p>Start writing your content here...</p>';
|
|
372
|
+
return saved;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<div>
|
|
377
|
+
<EditorProvider currentUser={currentUser}>
|
|
378
|
+
<ConfigurableEditorWithAuth
|
|
379
|
+
apiKey="your-api-key"
|
|
380
|
+
initialContent={loadSavedContent()}
|
|
381
|
+
onChange={handleContentChange}
|
|
382
|
+
defaultFontFamilies={['Arial', 'Helvetica', 'Times New Roman']}
|
|
383
|
+
mentionUserList={['Alice', 'Bob', 'Charlie']}
|
|
384
|
+
onAuthSuccess={() => console.log('Ready to edit!')}
|
|
385
|
+
onAuthError={(error) => console.error('Auth failed:', error)}
|
|
386
|
+
/>
|
|
387
|
+
</EditorProvider>
|
|
388
|
+
|
|
389
|
+
<button onClick={handleSave} style={{ marginTop: '10px', padding: '10px' }}>
|
|
390
|
+
Save Content
|
|
391
|
+
</button>
|
|
392
|
+
|
|
393
|
+
<div style={{ marginTop: '20px', padding: '10px', background: '#f5f5f5' }}>
|
|
394
|
+
<h3>Current HTML Content:</h3>
|
|
395
|
+
<pre>{editorContent}</pre>
|
|
396
|
+
</div>
|
|
397
|
+
</div>
|
|
398
|
+
);
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Custom API Key Verification
|
|
403
|
+
|
|
404
|
+
```jsx
|
|
405
|
+
import React from 'react';
|
|
406
|
+
import { ConfigurableEditorWithAuth, EditorProvider } from 'eddyter';
|
|
407
|
+
import 'eddyter/style.css';
|
|
408
|
+
|
|
409
|
+
function App() {
|
|
410
|
+
const customVerifyKey = async (apiKey) => {
|
|
411
|
+
try {
|
|
412
|
+
const response = await fetch('/api/verify-key', {
|
|
413
|
+
method: 'POST',
|
|
414
|
+
headers: { 'Content-Type': 'application/json' },
|
|
415
|
+
body: JSON.stringify({ apiKey })
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
const data = await response.json();
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
success: data.valid,
|
|
422
|
+
message: data.message || 'API key verified'
|
|
423
|
+
};
|
|
424
|
+
} catch (error) {
|
|
425
|
+
return {
|
|
426
|
+
success: false,
|
|
427
|
+
message: 'Failed to verify API key'
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
return (
|
|
433
|
+
<EditorProvider>
|
|
434
|
+
<ConfigurableEditorWithAuth
|
|
435
|
+
apiKey="your-api-key"
|
|
436
|
+
customVerifyKey={customVerifyKey}
|
|
437
|
+
onChange={(html) => console.log('Content changed:', html)}
|
|
438
|
+
/>
|
|
439
|
+
</EditorProvider>
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
## Link Preview Feature
|
|
445
|
+
|
|
446
|
+
Eddyter includes automatic link preview on hover. When users hover over links in content wrapped by `EditorProvider`, a preview popup shows the link's title, description, and image.
|
|
447
|
+
|
|
448
|
+
### How It Works
|
|
449
|
+
|
|
450
|
+
- **Inside the editor**: Link preview works automatically after authentication
|
|
451
|
+
- **Outside the editor** (preview mode, saved content): Link preview works if the user has opened the editor at least once in the session (authentication stores the API key)
|
|
452
|
+
|
|
453
|
+
### Preview-Only Scenarios
|
|
454
|
+
|
|
455
|
+
If your application displays saved content without ever opening the editor (e.g., a read-only view), you need to pass `apiKey` to `EditorProvider`:
|
|
456
|
+
|
|
457
|
+
```jsx
|
|
458
|
+
import React from 'react';
|
|
459
|
+
import { EditorProvider } from 'eddyter';
|
|
460
|
+
import 'eddyter/style.css';
|
|
461
|
+
|
|
462
|
+
function ContentPreviewPage({ savedHtml }) {
|
|
463
|
+
return (
|
|
464
|
+
<EditorProvider apiKey="your-api-key">
|
|
465
|
+
<div dangerouslySetInnerHTML={{ __html: savedHtml }} />
|
|
466
|
+
</EditorProvider>
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
```
|
|
470
|
+
|
|
471
|
+
### Disabling Link Preview
|
|
472
|
+
|
|
473
|
+
To disable link preview entirely:
|
|
474
|
+
|
|
475
|
+
```jsx
|
|
476
|
+
<EditorProvider enableLinkPreview={false}>
|
|
477
|
+
{/* Your content */}
|
|
478
|
+
</EditorProvider>
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## License
|
|
482
|
+
|
|
483
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|