ct-rich-text-editor 1.1.8 → 1.1.9

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 CHANGED
@@ -34,8 +34,8 @@ import 'ct-rich-text-editor/style.css';
34
34
 
35
35
  ```jsx
36
36
  import React from 'react';
37
- import {
38
- ConfigurableEditorWithAuth,
37
+ import {
38
+ ConfigurableEditorWithAuth,
39
39
  EditorProvider,
40
40
  defaultEditorConfig
41
41
  } from 'ct-rich-text-editor';
@@ -44,7 +44,12 @@ import 'ct-rich-text-editor/style.css';
44
44
 
45
45
  function App() {
46
46
  const apiKey = 'your-api-key'; // Replace with your actual API key
47
-
47
+
48
+ const handleContentChange = (html) => {
49
+ console.log('Editor HTML content:', html);
50
+ // Handle the HTML content (save to state, send to server, etc.)
51
+ };
52
+
48
53
  return (
49
54
  <EditorProvider
50
55
  defaultFontFamilies={defaultEditorConfig.defaultFontFamilies}
@@ -52,6 +57,8 @@ function App() {
52
57
  >
53
58
  <ConfigurableEditorWithAuth
54
59
  apiKey={apiKey}
60
+ onChange={handleContentChange}
61
+ initialContent="<p>Welcome to the editor!</p>"
55
62
  onAuthSuccess={() => console.log('Authentication successful')}
56
63
  onAuthError={(error) => console.error('Authentication error:', error)}
57
64
  />
@@ -79,20 +86,13 @@ The main editor component with authentication.
79
86
  #### Props
80
87
 
81
88
  - `apiKey`: Your API key for authentication (required)
89
+ - `initialContent`: Initial HTML content for the editor (optional) - string
90
+ - `onChange`: Callback function when editor content changes (optional) - receives HTML string
91
+ - `defaultFontFamilies`: Array of font names for the font selector (optional)
92
+ - `mentionUserList`: Array of usernames for mention functionality (optional)
82
93
  - `onAuthSuccess`: Callback function when authentication is successful (optional)
83
94
  - `onAuthError`: Callback function when authentication fails (optional)
84
- - `showToolbar`: Boolean to show/hide the toolbar (optional, default: true)
85
- - `showFloatingMenu`: Boolean to show/hide the floating menu (optional, default: true)
86
- - `showHtmlView`: Boolean to show/hide HTML view option (optional, default: true)
87
- - `initialContent`: Initial content for the editor (optional)
88
- - `onChange`: Callback function when editor content changes (optional)
89
- - `readOnly`: Boolean to make editor read-only (optional, default: false)
90
- - `placeholder`: Placeholder text when editor is empty (optional)
91
- - `theme`: Custom theme object for styling (optional)
92
- - `plugins`: Array of custom plugins (optional)
93
- - `aiEnabled`: Boolean to enable/disable AI features (optional, default: false)
94
- - `onAiResponse`: Callback function for AI responses (optional)
95
- - `onAiError`: Callback function for AI errors (optional)
95
+ - `customVerifyKey`: Custom function to verify API key (optional)
96
96
 
97
97
  ## Examples
98
98
 
@@ -116,7 +116,61 @@ function App() {
116
116
  }
117
117
  ```
118
118
 
119
- ### Editor with Custom Configuration
119
+ ### Editor with Content Handling
120
+
121
+ ```jsx
122
+ import React, { useState } from 'react';
123
+ import { ConfigurableEditorWithAuth, EditorProvider } from 'ct-rich-text-editor';
124
+ import 'ct-rich-text-editor/style.css';
125
+
126
+ function App() {
127
+ const [editorContent, setEditorContent] = useState('');
128
+
129
+ const handleContentChange = (html) => {
130
+ setEditorContent(html);
131
+ console.log('Current content:', html);
132
+ // You can also save to localStorage, send to API, etc.
133
+ };
134
+
135
+ const handleSave = () => {
136
+ // Save the HTML content to your backend or localStorage
137
+ localStorage.setItem('saved-content', editorContent);
138
+ console.log('Content saved!');
139
+ };
140
+
141
+ const loadSavedContent = () => {
142
+ const saved = '<p>Start writing your content here...</p>';
143
+ return saved
144
+ };
145
+
146
+ return (
147
+ <div>
148
+ <EditorProvider>
149
+ <ConfigurableEditorWithAuth
150
+ apiKey="your-api-key"
151
+ initialContent={loadSavedContent()}
152
+ onChange={handleContentChange}
153
+ defaultFontFamilies={['Arial', 'Helvetica', 'Times New Roman']}
154
+ mentionUserList={['@john', '@jane', '@bob']}
155
+ onAuthSuccess={() => console.log('Ready to edit!')}
156
+ onAuthError={(error) => console.error('Auth failed:', error)}
157
+ />
158
+ </EditorProvider>
159
+
160
+ <button onClick={handleSave} style={{ marginTop: '10px', padding: '10px' }}>
161
+ Save Content
162
+ </button>
163
+
164
+ <div style={{ marginTop: '20px', padding: '10px', background: '#f5f5f5' }}>
165
+ <h3>Current HTML Content:</h3>
166
+ <pre>{editorContent}</pre>
167
+ </div>
168
+ </div>
169
+ );
170
+ }
171
+ ```
172
+
173
+ ### Custom API Key Verification
120
174
 
121
175
  ```jsx
122
176
  import React from 'react';
@@ -124,18 +178,34 @@ import { ConfigurableEditorWithAuth, EditorProvider } from 'ct-rich-text-editor'
124
178
  import 'ct-rich-text-editor/style.css';
125
179
 
126
180
  function App() {
181
+ const customVerifyKey = async (apiKey) => {
182
+ try {
183
+ const response = await fetch('/api/verify-key', {
184
+ method: 'POST',
185
+ headers: { 'Content-Type': 'application/json' },
186
+ body: JSON.stringify({ apiKey })
187
+ });
188
+
189
+ const data = await response.json();
190
+
191
+ return {
192
+ success: data.valid,
193
+ message: data.message || 'API key verified'
194
+ };
195
+ } catch (error) {
196
+ return {
197
+ success: false,
198
+ message: 'Failed to verify API key'
199
+ };
200
+ }
201
+ };
202
+
127
203
  return (
128
204
  <EditorProvider>
129
205
  <ConfigurableEditorWithAuth
130
206
  apiKey="your-api-key"
131
- showToolbar={true}
132
- showFloatingMenu={true}
133
- showHtmlView={true}
134
- readOnly={false}
135
- placeholder="Start typing..."
136
- aiEnabled={true}
137
- onAiResponse={(response) => console.log('AI Response:', response)}
138
- onAiError={(error) => console.error('AI Error:', error)}
207
+ customVerifyKey={customVerifyKey}
208
+ onChange={(html) => console.log('Content changed:', html)}
139
209
  />
140
210
  </EditorProvider>
141
211
  );
@@ -4,7 +4,7 @@ import { ApiResponse } from '../api/auth';
4
4
  interface ConfigurableEditorWithAuthProps {
5
5
  apiKey: string;
6
6
  initialContent?: string;
7
- onChange?: (content: string) => void;
7
+ onChange?: (html: string) => void;
8
8
  defaultFontFamilies?: string[];
9
9
  mentionUserList?: string[];
10
10
  onAuthSuccess?: () => void;