smartrte-react 0.1.9 β 0.1.10
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 +699 -0
- package/package.json +41 -13
package/README.md
ADDED
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
# Smart RTE (Rich Text Editor) - React
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/smartrte-react)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
A powerful, feature-rich Rich Text Editor built for React applications with support for tables, formulas (LaTeX/KaTeX), media management, and advanced text formatting.
|
|
7
|
+
|
|
8
|
+
## π Features
|
|
9
|
+
|
|
10
|
+
- **π Rich Text Editing**: Full-featured WYSIWYG editor with all standard formatting options
|
|
11
|
+
- **π Advanced Table Support**: Create, edit, merge, split cells, and customize tables
|
|
12
|
+
- **π’ Mathematical Formulas**: LaTeX/KaTeX integration for rendering mathematical expressions
|
|
13
|
+
- **πΌοΈ Media Management**: Image upload, resize, drag-and-drop, and custom media manager integration
|
|
14
|
+
- **π¨ Styling Options**: Font sizes (8-96pt), text colors, background colors, and more
|
|
15
|
+
- **π Link Management**: Easy insertion and editing of hyperlinks
|
|
16
|
+
- **π± Responsive**: Works seamlessly across different screen sizes
|
|
17
|
+
- **β‘ Lightweight**: Minimal dependencies, optimized for performance
|
|
18
|
+
- **π― TypeScript Support**: Fully typed for better developer experience
|
|
19
|
+
- **π§ Customizable**: Toggle features on/off, custom media managers, and more
|
|
20
|
+
|
|
21
|
+
## π¦ Installation
|
|
22
|
+
|
|
23
|
+
### Using npm
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install smartrte-react
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Using yarn
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add smartrte-react
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Using pnpm
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm add smartrte-react
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## π Quick Start
|
|
42
|
+
|
|
43
|
+
### Basic Usage
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import React, { useState } from 'react';
|
|
47
|
+
import { ClassicEditor } from 'smartrte-react';
|
|
48
|
+
|
|
49
|
+
function App() {
|
|
50
|
+
const [content, setContent] = useState('<p>Start typing...</p>');
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<div>
|
|
54
|
+
<ClassicEditor
|
|
55
|
+
value={content}
|
|
56
|
+
onChange={(html) => setContent(html)}
|
|
57
|
+
placeholder="Type hereβ¦"
|
|
58
|
+
/>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default App;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## π Documentation
|
|
67
|
+
|
|
68
|
+
### Component API
|
|
69
|
+
|
|
70
|
+
#### ClassicEditor Props
|
|
71
|
+
|
|
72
|
+
| Prop | Type | Default | Description |
|
|
73
|
+
|------|------|---------|-------------|
|
|
74
|
+
| `value` | `string` | `undefined` | HTML content of the editor |
|
|
75
|
+
| `onChange` | `(html: string) => void` | `undefined` | Callback fired when content changes |
|
|
76
|
+
| `placeholder` | `string` | `"Type hereβ¦"` | Placeholder text when editor is empty |
|
|
77
|
+
| `minHeight` | `number \| string` | `200` | Minimum height of the editor (in pixels) |
|
|
78
|
+
| `maxHeight` | `number \| string` | `500` | Maximum height of the editor (in pixels) |
|
|
79
|
+
| `readOnly` | `boolean` | `false` | Make the editor read-only |
|
|
80
|
+
| `table` | `boolean` | `true` | Enable/disable table functionality |
|
|
81
|
+
| `media` | `boolean` | `true` | Enable/disable media/image functionality |
|
|
82
|
+
| `formula` | `boolean` | `true` | Enable/disable formula/LaTeX functionality |
|
|
83
|
+
| `mediaManager` | `MediaManagerAdapter` | `undefined` | Custom media manager for handling images |
|
|
84
|
+
|
|
85
|
+
### Advanced Examples
|
|
86
|
+
|
|
87
|
+
#### Complete Example with All Features
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
import React, { useState } from 'react';
|
|
91
|
+
import { ClassicEditor, MediaManagerAdapter } from 'smartrte-react';
|
|
92
|
+
|
|
93
|
+
// Custom media manager implementation
|
|
94
|
+
const customMediaManager: MediaManagerAdapter = {
|
|
95
|
+
async search(query) {
|
|
96
|
+
// Implement your media search logic
|
|
97
|
+
const response = await fetch(`/api/media/search?q=${query.text}`);
|
|
98
|
+
const data = await response.json();
|
|
99
|
+
return {
|
|
100
|
+
items: data.items.map(item => ({
|
|
101
|
+
id: item.id,
|
|
102
|
+
url: item.url,
|
|
103
|
+
thumbnailUrl: item.thumbnailUrl,
|
|
104
|
+
title: item.title,
|
|
105
|
+
})),
|
|
106
|
+
};
|
|
107
|
+
},
|
|
108
|
+
async upload(file) {
|
|
109
|
+
// Implement your file upload logic
|
|
110
|
+
const formData = new FormData();
|
|
111
|
+
formData.append('file', file);
|
|
112
|
+
const response = await fetch('/api/media/upload', {
|
|
113
|
+
method: 'POST',
|
|
114
|
+
body: formData,
|
|
115
|
+
});
|
|
116
|
+
const data = await response.json();
|
|
117
|
+
return {
|
|
118
|
+
id: data.id,
|
|
119
|
+
url: data.url,
|
|
120
|
+
thumbnailUrl: data.thumbnailUrl,
|
|
121
|
+
title: data.title,
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function AdvancedEditor() {
|
|
127
|
+
const [content, setContent] = useState('');
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<ClassicEditor
|
|
131
|
+
value={content}
|
|
132
|
+
onChange={(html) => {
|
|
133
|
+
console.log('Content changed:', html);
|
|
134
|
+
setContent(html);
|
|
135
|
+
}}
|
|
136
|
+
placeholder="Start editing..."
|
|
137
|
+
minHeight={300}
|
|
138
|
+
maxHeight={800}
|
|
139
|
+
table={true}
|
|
140
|
+
media={true}
|
|
141
|
+
formula={true}
|
|
142
|
+
mediaManager={customMediaManager}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default AdvancedEditor;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### Read-Only Mode
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
import { ClassicEditor } from 'smartrte-react';
|
|
154
|
+
|
|
155
|
+
function ReadOnlyEditor({ content }) {
|
|
156
|
+
return (
|
|
157
|
+
<ClassicEditor
|
|
158
|
+
value={content}
|
|
159
|
+
readOnly={true}
|
|
160
|
+
minHeight={200}
|
|
161
|
+
/>
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
#### Minimal Editor (No Tables, Media, or Formulas)
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { ClassicEditor } from 'smartrte-react';
|
|
170
|
+
|
|
171
|
+
function MinimalEditor() {
|
|
172
|
+
const [content, setContent] = useState('');
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<ClassicEditor
|
|
176
|
+
value={content}
|
|
177
|
+
onChange={setContent}
|
|
178
|
+
table={false}
|
|
179
|
+
media={false}
|
|
180
|
+
formula={false}
|
|
181
|
+
placeholder="Simple text editor"
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Next.js Integration
|
|
188
|
+
|
|
189
|
+
For Next.js applications, you may need to use dynamic imports to avoid SSR issues:
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import dynamic from 'next/dynamic';
|
|
193
|
+
import { useState } from 'react';
|
|
194
|
+
|
|
195
|
+
const ClassicEditor = dynamic(
|
|
196
|
+
() => import('smartrte-react').then(mod => mod.ClassicEditor),
|
|
197
|
+
{ ssr: false }
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
export default function Page() {
|
|
201
|
+
const [content, setContent] = useState('');
|
|
202
|
+
|
|
203
|
+
return (
|
|
204
|
+
<div>
|
|
205
|
+
<ClassicEditor
|
|
206
|
+
value={content}
|
|
207
|
+
onChange={setContent}
|
|
208
|
+
placeholder="Start typing..."
|
|
209
|
+
/>
|
|
210
|
+
</div>
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## π§ Features Deep Dive
|
|
216
|
+
|
|
217
|
+
### Text Formatting
|
|
218
|
+
|
|
219
|
+
The editor supports all standard text formatting options:
|
|
220
|
+
|
|
221
|
+
- **Bold**, *Italic*, <u>Underline</u>, ~~Strikethrough~~
|
|
222
|
+
- Font sizes from 8pt to 96pt
|
|
223
|
+
- Text color and background color
|
|
224
|
+
- Headings (H1-H6)
|
|
225
|
+
- Paragraph, blockquote, code block
|
|
226
|
+
- Ordered and unordered lists
|
|
227
|
+
- Text alignment (left, center, right, justify)
|
|
228
|
+
- Superscript and subscript
|
|
229
|
+
|
|
230
|
+
### Tables
|
|
231
|
+
|
|
232
|
+
Full-featured table support includes:
|
|
233
|
+
|
|
234
|
+
- Create tables with custom rows and columns
|
|
235
|
+
- Add/delete rows and columns
|
|
236
|
+
- Merge and split cells
|
|
237
|
+
- Toggle header rows/cells
|
|
238
|
+
- Cell background colors
|
|
239
|
+
- Cell borders toggle
|
|
240
|
+
- Right-click context menu for table operations
|
|
241
|
+
- Keyboard navigation (Tab, Shift+Tab, Arrow keys)
|
|
242
|
+
|
|
243
|
+
**Keyboard Shortcuts:**
|
|
244
|
+
- `Tab` - Move to next cell
|
|
245
|
+
- `Shift+Tab` - Move to previous cell
|
|
246
|
+
- `Arrow keys` - Navigate between cells
|
|
247
|
+
- Right-click on cell - Open context menu
|
|
248
|
+
|
|
249
|
+
### Mathematical Formulas
|
|
250
|
+
|
|
251
|
+
LaTeX/KaTeX support for mathematical expressions:
|
|
252
|
+
|
|
253
|
+
```tsx
|
|
254
|
+
// The editor automatically loads KaTeX
|
|
255
|
+
// Users can insert formulas using the formula button
|
|
256
|
+
// Examples of supported LaTeX:
|
|
257
|
+
// - E=mc^2
|
|
258
|
+
// - \frac{a}{b}
|
|
259
|
+
// - \sqrt{x}
|
|
260
|
+
// - \sum_{i=1}^{n} x_i
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
**Required External Dependency:**
|
|
264
|
+
|
|
265
|
+
To use formulas, include KaTeX in your HTML:
|
|
266
|
+
|
|
267
|
+
```html
|
|
268
|
+
<!-- In your public/index.html or _app.tsx -->
|
|
269
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css">
|
|
270
|
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.js"></script>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Media Management
|
|
274
|
+
|
|
275
|
+
Built-in image support with optional custom media manager:
|
|
276
|
+
|
|
277
|
+
**Default behavior:**
|
|
278
|
+
- Local file upload
|
|
279
|
+
- Drag and drop images
|
|
280
|
+
- Image resize handles
|
|
281
|
+
- Right-click context menu for image operations
|
|
282
|
+
|
|
283
|
+
**Custom Media Manager Implementation:**
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { MediaManagerAdapter, MediaItem, MediaSearchQuery } from 'smartrte-react';
|
|
287
|
+
|
|
288
|
+
const myMediaManager: MediaManagerAdapter = {
|
|
289
|
+
async search(query: MediaSearchQuery) {
|
|
290
|
+
// Search your media library
|
|
291
|
+
return {
|
|
292
|
+
items: [/* array of MediaItem */],
|
|
293
|
+
hasMore: false,
|
|
294
|
+
nextPage: undefined,
|
|
295
|
+
};
|
|
296
|
+
},
|
|
297
|
+
|
|
298
|
+
async upload(file: File) {
|
|
299
|
+
// Upload file to your server
|
|
300
|
+
return {
|
|
301
|
+
id: 'unique-id',
|
|
302
|
+
url: 'https://example.com/image.jpg',
|
|
303
|
+
thumbnailUrl: 'https://example.com/thumb.jpg',
|
|
304
|
+
title: 'Image title',
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
};
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## π¨ Styling
|
|
311
|
+
|
|
312
|
+
The editor comes with built-in styles. You can customize the appearance by wrapping it in a container:
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
<div style={{
|
|
316
|
+
border: '1px solid #ddd',
|
|
317
|
+
borderRadius: '8px',
|
|
318
|
+
overflow: 'hidden',
|
|
319
|
+
}}>
|
|
320
|
+
<ClassicEditor
|
|
321
|
+
value={content}
|
|
322
|
+
onChange={setContent}
|
|
323
|
+
/>
|
|
324
|
+
</div>
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
## π οΈ Development
|
|
328
|
+
|
|
329
|
+
### Prerequisites
|
|
330
|
+
|
|
331
|
+
- Node.js 18+
|
|
332
|
+
- pnpm 9.10.0+
|
|
333
|
+
- Rust (for WASM compilation)
|
|
334
|
+
- wasm-pack
|
|
335
|
+
|
|
336
|
+
### Setting Up Development Environment
|
|
337
|
+
|
|
338
|
+
1. **Clone the repository**
|
|
339
|
+
|
|
340
|
+
```bash
|
|
341
|
+
git clone https://github.com/yourusername/smart-rte.git
|
|
342
|
+
cd smart-rte
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
2. **Install dependencies**
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
pnpm install
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
3. **Build the project**
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
# Build WASM core
|
|
355
|
+
pnpm build:wasm
|
|
356
|
+
|
|
357
|
+
# Build TypeScript packages
|
|
358
|
+
pnpm build:ts
|
|
359
|
+
|
|
360
|
+
# Or build everything
|
|
361
|
+
pnpm build
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
4. **Run the development playground**
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
cd packages/react/playground
|
|
368
|
+
pnpm install
|
|
369
|
+
pnpm dev
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
The playground will be available at `http://localhost:5173`
|
|
373
|
+
|
|
374
|
+
### Project Structure
|
|
375
|
+
|
|
376
|
+
```
|
|
377
|
+
smart-rte/
|
|
378
|
+
βββ packages/
|
|
379
|
+
β βββ react/ # Main React package (smartrte-react)
|
|
380
|
+
β β βββ src/
|
|
381
|
+
β β β βββ components/
|
|
382
|
+
β β β β βββ ClassicEditor.tsx # Main editor component
|
|
383
|
+
β β β β βββ MediaManager.tsx # Media management component
|
|
384
|
+
β β β βββ index.ts
|
|
385
|
+
β β βββ playground/ # Development playground
|
|
386
|
+
β β βββ package.json
|
|
387
|
+
β βββ core-wasm/ # WASM bindings
|
|
388
|
+
β βββ classic-embed/ # Standalone bundle
|
|
389
|
+
βββ rust/ # Rust core
|
|
390
|
+
β βββ smart_rte_core/
|
|
391
|
+
βββ apps/ # Example applications
|
|
392
|
+
βββ package.json
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Building for Production
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
# Build the React package
|
|
399
|
+
cd packages/react
|
|
400
|
+
pnpm build
|
|
401
|
+
|
|
402
|
+
# This creates:
|
|
403
|
+
# - dist/index.js - ES module
|
|
404
|
+
# - dist/index.d.ts - TypeScript definitions
|
|
405
|
+
# - dist/embed.js - Standalone embed bundle
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### Running Tests
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# Run vitest
|
|
412
|
+
pnpm test
|
|
413
|
+
|
|
414
|
+
# Run E2E tests with Playwright
|
|
415
|
+
pnpm e2e
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### Running Storybook
|
|
419
|
+
|
|
420
|
+
```bash
|
|
421
|
+
cd packages/react
|
|
422
|
+
pnpm storybook
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Storybook will be available at `http://localhost:6006`
|
|
426
|
+
|
|
427
|
+
## π Publishing
|
|
428
|
+
|
|
429
|
+
### For Package Maintainers
|
|
430
|
+
|
|
431
|
+
The package is published to npm as `smartrte-react`.
|
|
432
|
+
|
|
433
|
+
```bash
|
|
434
|
+
# Make sure you're in packages/react
|
|
435
|
+
cd packages/react
|
|
436
|
+
|
|
437
|
+
# Update version in package.json
|
|
438
|
+
# Then publish
|
|
439
|
+
pnpm publish
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
The `prepublishOnly` script automatically runs `build:all` before publishing.
|
|
443
|
+
|
|
444
|
+
### Version Management
|
|
445
|
+
|
|
446
|
+
We follow [Semantic Versioning](https://semver.org/):
|
|
447
|
+
|
|
448
|
+
- **MAJOR** version for incompatible API changes
|
|
449
|
+
- **MINOR** version for backwards-compatible functionality
|
|
450
|
+
- **PATCH** version for backwards-compatible bug fixes
|
|
451
|
+
|
|
452
|
+
## π€ Contributing
|
|
453
|
+
|
|
454
|
+
We welcome contributions! Here's how you can help:
|
|
455
|
+
|
|
456
|
+
### Reporting Bugs
|
|
457
|
+
|
|
458
|
+
1. Check if the bug has already been reported in [Issues](https://github.com/yourusername/smart-rte/issues)
|
|
459
|
+
2. If not, create a new issue with:
|
|
460
|
+
- Clear title and description
|
|
461
|
+
- Steps to reproduce
|
|
462
|
+
- Expected vs actual behavior
|
|
463
|
+
- Screenshots if applicable
|
|
464
|
+
- Your environment (browser, OS, React version)
|
|
465
|
+
|
|
466
|
+
### Suggesting Features
|
|
467
|
+
|
|
468
|
+
1. Check [existing feature requests](https://github.com/yourusername/smart-rte/issues?q=is%3Aissue+label%3Aenhancement)
|
|
469
|
+
2. Create a new issue with:
|
|
470
|
+
- Clear description of the feature
|
|
471
|
+
- Use cases
|
|
472
|
+
- Proposed API (if applicable)
|
|
473
|
+
|
|
474
|
+
### Pull Requests
|
|
475
|
+
|
|
476
|
+
1. **Fork** the repository
|
|
477
|
+
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
|
|
478
|
+
3. **Make** your changes
|
|
479
|
+
4. **Test** your changes thoroughly
|
|
480
|
+
5. **Commit** with clear messages (`git commit -m 'Add amazing feature'`)
|
|
481
|
+
6. **Push** to your fork (`git push origin feature/amazing-feature`)
|
|
482
|
+
7. **Open** a Pull Request
|
|
483
|
+
|
|
484
|
+
#### PR Guidelines
|
|
485
|
+
|
|
486
|
+
- Follow the existing code style
|
|
487
|
+
- Add tests for new features
|
|
488
|
+
- Update documentation
|
|
489
|
+
- Keep PRs focused on a single feature/fix
|
|
490
|
+
- Write clear commit messages
|
|
491
|
+
|
|
492
|
+
### Development Workflow
|
|
493
|
+
|
|
494
|
+
```bash
|
|
495
|
+
# 1. Create a feature branch
|
|
496
|
+
git checkout -b feature/my-feature
|
|
497
|
+
|
|
498
|
+
# 2. Make changes and test
|
|
499
|
+
pnpm dev # Run playground
|
|
500
|
+
pnpm test # Run tests
|
|
501
|
+
|
|
502
|
+
# 3. Build to ensure no errors
|
|
503
|
+
pnpm build
|
|
504
|
+
|
|
505
|
+
# 4. Commit and push
|
|
506
|
+
git add .
|
|
507
|
+
git commit -m "feat: add my feature"
|
|
508
|
+
git push origin feature/my-feature
|
|
509
|
+
|
|
510
|
+
# 5. Create PR on GitHub
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## π Troubleshooting
|
|
514
|
+
|
|
515
|
+
### Common Issues
|
|
516
|
+
|
|
517
|
+
#### Issue: Editor not showing/rendering
|
|
518
|
+
|
|
519
|
+
**Solution:** Make sure React and React-DOM are installed as peer dependencies:
|
|
520
|
+
|
|
521
|
+
```bash
|
|
522
|
+
npm install react@18 react-dom@18
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
#### Issue: Formula rendering not working
|
|
526
|
+
|
|
527
|
+
**Solution:** Ensure KaTeX is loaded in your HTML:
|
|
528
|
+
|
|
529
|
+
```html
|
|
530
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css">
|
|
531
|
+
<script src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.js"></script>
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### Issue: TypeScript errors
|
|
535
|
+
|
|
536
|
+
**Solution:** Make sure you have the latest type definitions:
|
|
537
|
+
|
|
538
|
+
```bash
|
|
539
|
+
npm install --save-dev @types/react@18 @types/react-dom@18
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
#### Issue: Build errors in Next.js
|
|
543
|
+
|
|
544
|
+
**Solution:** Use dynamic imports to disable SSR:
|
|
545
|
+
|
|
546
|
+
```tsx
|
|
547
|
+
const ClassicEditor = dynamic(
|
|
548
|
+
() => import('smartrte-react').then(mod => mod.ClassicEditor),
|
|
549
|
+
{ ssr: false }
|
|
550
|
+
);
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
#### Issue: Images not uploading
|
|
554
|
+
|
|
555
|
+
**Solution:** Check that the `media` prop is set to `true` and implement a custom `mediaManager` if you need server-side uploads.
|
|
556
|
+
|
|
557
|
+
## π Security
|
|
558
|
+
|
|
559
|
+
### Reporting Security Issues
|
|
560
|
+
|
|
561
|
+
If you discover a security vulnerability, please email [security@yourdomain.com] instead of using the issue tracker.
|
|
562
|
+
|
|
563
|
+
### Content Sanitization
|
|
564
|
+
|
|
565
|
+
**β οΈ Important:** The editor outputs raw HTML. Always sanitize user-generated content before displaying it to prevent XSS attacks.
|
|
566
|
+
|
|
567
|
+
Recommended libraries:
|
|
568
|
+
- [DOMPurify](https://github.com/cure53/DOMPurify)
|
|
569
|
+
- [sanitize-html](https://github.com/apostrophecms/sanitize-html)
|
|
570
|
+
|
|
571
|
+
Example:
|
|
572
|
+
|
|
573
|
+
```tsx
|
|
574
|
+
import DOMPurify from 'dompurify';
|
|
575
|
+
|
|
576
|
+
function DisplayContent({ html }) {
|
|
577
|
+
const sanitized = DOMPurify.sanitize(html);
|
|
578
|
+
return <div dangerouslySetInnerHTML={{ __html: sanitized }} />;
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
## π License
|
|
583
|
+
|
|
584
|
+
This project is licensed under the MIT License - see the [LICENSE](../../dart/smartrte_flutter/LICENSE) file for details.
|
|
585
|
+
|
|
586
|
+
```
|
|
587
|
+
MIT License
|
|
588
|
+
|
|
589
|
+
Copyright (c) 2025 Smart RTE Contributors
|
|
590
|
+
|
|
591
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
592
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
593
|
+
in the Software without restriction, including without limitation the rights
|
|
594
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
595
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
596
|
+
furnished to do so, subject to the following conditions:
|
|
597
|
+
|
|
598
|
+
The above copyright notice and this permission notice shall be included in all
|
|
599
|
+
copies or substantial portions of the Software.
|
|
600
|
+
|
|
601
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
602
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
603
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
604
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
605
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
606
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
607
|
+
SOFTWARE.
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
## π₯ Authors & Contributors
|
|
611
|
+
|
|
612
|
+
- **Smart RTE Team** - Initial work and maintenance
|
|
613
|
+
|
|
614
|
+
See the list of [contributors](https://github.com/yourusername/smart-rte/contributors) who participated in this project.
|
|
615
|
+
|
|
616
|
+
## π Acknowledgments
|
|
617
|
+
|
|
618
|
+
- [KaTeX](https://katex.org/) - For mathematical formula rendering
|
|
619
|
+
- [React](https://reactjs.org/) - The UI library
|
|
620
|
+
- [Vite](https://vitejs.dev/) - Build tool
|
|
621
|
+
- All our amazing [contributors](https://github.com/yourusername/smart-rte/contributors)
|
|
622
|
+
|
|
623
|
+
## π Support
|
|
624
|
+
|
|
625
|
+
- **Documentation:** You're reading it! π
|
|
626
|
+
- **Issues:** [GitHub Issues](https://github.com/yourusername/smart-rte/issues)
|
|
627
|
+
- **Discussions:** [GitHub Discussions](https://github.com/yourusername/smart-rte/discussions)
|
|
628
|
+
- **Twitter:** [@smartrte](https://twitter.com/smartrte) (if applicable)
|
|
629
|
+
|
|
630
|
+
## πΊοΈ Roadmap
|
|
631
|
+
|
|
632
|
+
### Current Version (0.1.x)
|
|
633
|
+
|
|
634
|
+
- β
Rich text editing
|
|
635
|
+
- β
Table support
|
|
636
|
+
- β
Formula support (LaTeX/KaTeX)
|
|
637
|
+
- β
Media management
|
|
638
|
+
- β
TypeScript support
|
|
639
|
+
|
|
640
|
+
### Upcoming Features
|
|
641
|
+
|
|
642
|
+
- π Collaborative editing
|
|
643
|
+
- π Undo/Redo improvements
|
|
644
|
+
- π Code syntax highlighting
|
|
645
|
+
- π Markdown import/export
|
|
646
|
+
- π Custom toolbar configuration
|
|
647
|
+
- π Mobile optimization
|
|
648
|
+
- π Accessibility improvements (ARIA labels, keyboard shortcuts)
|
|
649
|
+
|
|
650
|
+
## π Browser Support
|
|
651
|
+
|
|
652
|
+
| Browser | Version |
|
|
653
|
+
|---------|---------|
|
|
654
|
+
| Chrome | Last 2 versions |
|
|
655
|
+
| Firefox | Last 2 versions |
|
|
656
|
+
| Safari | Last 2 versions |
|
|
657
|
+
| Edge | Last 2 versions |
|
|
658
|
+
|
|
659
|
+
## π Related Packages
|
|
660
|
+
|
|
661
|
+
- **@smartrte/classic-embed** - Standalone script-tag bundle
|
|
662
|
+
- **smartrte-flutter** - Flutter/Dart implementation
|
|
663
|
+
- **smart-rte-core** - Rust core library
|
|
664
|
+
|
|
665
|
+
## π‘ Tips & Best Practices
|
|
666
|
+
|
|
667
|
+
1. **Performance**: For large documents, consider implementing lazy loading or pagination
|
|
668
|
+
2. **State Management**: Use React state or a state management library (Redux, Zustand) for complex applications
|
|
669
|
+
3. **Validation**: Always validate and sanitize HTML content before storing or displaying
|
|
670
|
+
4. **Accessibility**: Test with screen readers and keyboard navigation
|
|
671
|
+
5. **Mobile**: Test on mobile devices as touch interactions may differ
|
|
672
|
+
6. **Auto-save**: Implement auto-save functionality to prevent data loss
|
|
673
|
+
|
|
674
|
+
## π Learning Resources
|
|
675
|
+
|
|
676
|
+
### For Entry-Level Developers
|
|
677
|
+
|
|
678
|
+
1. **Getting Started with React**: [React Official Tutorial](https://react.dev/learn)
|
|
679
|
+
2. **Understanding Rich Text Editors**: [MDN ContentEditable](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/contenteditable)
|
|
680
|
+
3. **TypeScript Basics**: [TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
|
|
681
|
+
|
|
682
|
+
### For Mid-Level Developers
|
|
683
|
+
|
|
684
|
+
1. **Advanced React Patterns**: Hooks, Context, Performance Optimization
|
|
685
|
+
2. **Component Design**: Building reusable, maintainable components
|
|
686
|
+
3. **State Management**: When and how to use external state management
|
|
687
|
+
|
|
688
|
+
### For Senior Developers
|
|
689
|
+
|
|
690
|
+
1. **Architecture**: Designing scalable editor implementations
|
|
691
|
+
2. **Performance**: Optimization techniques for large documents
|
|
692
|
+
3. **Extensibility**: Building plugin systems and custom extensions
|
|
693
|
+
4. **Cross-platform**: Adapting the editor for different frameworks
|
|
694
|
+
|
|
695
|
+
---
|
|
696
|
+
|
|
697
|
+
**Happy Editing! π**
|
|
698
|
+
|
|
699
|
+
If you find this package useful, please consider giving it a β on [GitHub](https://github.com/yourusername/smart-rte)!
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartrte-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
|
+
"description": "A powerful, feature-rich Rich Text Editor for React with support for tables, mathematical formulas (LaTeX/KaTeX), and media management",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"module": "dist/index.js",
|
|
@@ -9,18 +10,34 @@
|
|
|
9
10
|
"dist",
|
|
10
11
|
"README.md"
|
|
11
12
|
],
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react",
|
|
15
|
+
"editor",
|
|
16
|
+
"rich-text-editor",
|
|
17
|
+
"wysiwyg",
|
|
18
|
+
"rte",
|
|
19
|
+
"text-editor",
|
|
20
|
+
"contenteditable",
|
|
21
|
+
"table-editor",
|
|
22
|
+
"latex",
|
|
23
|
+
"katex",
|
|
24
|
+
"formula-editor",
|
|
25
|
+
"media-manager",
|
|
26
|
+
"image-editor",
|
|
27
|
+
"react-component",
|
|
28
|
+
"typescript"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/ayush1852017/smart-rte.git",
|
|
33
|
+
"directory": "packages/react"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/ayush1852017/smart-rte#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/ayush1852017/smart-rte/issues"
|
|
23
38
|
},
|
|
39
|
+
"author": "Smart RTE Contributors",
|
|
40
|
+
"license": "MIT",
|
|
24
41
|
"publishConfig": {
|
|
25
42
|
"access": "public"
|
|
26
43
|
},
|
|
@@ -42,5 +59,16 @@
|
|
|
42
59
|
"@playwright/test": "^1.48.2",
|
|
43
60
|
"react": "18.3.1",
|
|
44
61
|
"react-dom": "18.3.1"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc -p tsconfig.json",
|
|
65
|
+
"build:embed": "vite build",
|
|
66
|
+
"build:all": "pnpm run build && pnpm run build:embed",
|
|
67
|
+
"dev": "pnpm build",
|
|
68
|
+
"lint": "eslint . || true",
|
|
69
|
+
"test": "vitest run || true",
|
|
70
|
+
"storybook": "storybook dev -p 6006",
|
|
71
|
+
"build-storybook": "storybook build",
|
|
72
|
+
"e2e": "playwright test || true"
|
|
45
73
|
}
|
|
46
|
-
}
|
|
74
|
+
}
|