editcrafter 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +263 -60
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,73 +1,276 @@
1
- # React + TypeScript + Vite
1
+ # EditCrafter
2
2
 
3
- This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
3
+ A powerful, customizable rich text editor built with Tiptap for React applications. Features image management with bubble menus, table support, and extensive formatting options.
4
4
 
5
- Currently, two official plugins are available:
5
+ [![npm version](https://img.shields.io/npm/v/editcrafter.svg)](https://www.npmjs.com/package/editcrafter)
6
+ [![License](https://img.shields.io/npm/l/editcrafter.svg)](https://github.com/yourusername/editcrafter/blob/main/LICENSE)
6
7
 
7
- - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
8
- - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
8
+ ## Features
9
9
 
10
- ## React Compiler
10
+ - 🎨 **Rich Text Formatting**: Bold, italic, underline, strikethrough, code, superscript, subscript
11
+ - 🖼️ **Enhanced Image Support**: Upload images with alignment, sizing, and metadata controls
12
+ - 📊 **Table Editor**: Full-featured table support with resizing and cell merging
13
+ - 📝 **Multiple List Types**: Bullet lists, ordered lists, and task lists
14
+ - 🎯 **Text Alignment**: Left, center, right, and justify alignment
15
+ - 🌈 **Color & Highlighting**: Text color and highlight with multiple colors
16
+ - 🔗 **Link Management**: Easy link insertion and editing
17
+ - ✨ **Typography**: Smart typography with auto-formatting
18
+ - 🎭 **Custom Image Uploader**: Integrate with your own image upload service
19
+ - 📱 **Responsive**: Mobile-friendly toolbar that adapts to screen size
20
+ - 🌓 **Theme Support**: Built-in light/dark theme toggle
11
21
 
12
- The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
22
+ ## Installation
13
23
 
14
- ## Expanding the ESLint configuration
24
+ ```bash
25
+ npm install editcrafter
26
+ # or
27
+ yarn add editcrafter
28
+ # or
29
+ pnpm add editcrafter
30
+ ```
31
+
32
+ ## Quick Start
15
33
 
16
- If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
34
+ ### Basic Usage
17
35
 
18
- ```js
19
- export default defineConfig([
20
- globalIgnores(['dist']),
21
- {
22
- files: ['**/*.{ts,tsx}'],
23
- extends: [
24
- // Other configs...
36
+ ```tsx
37
+ import { SimpleEditor } from 'editcrafter';
38
+ import 'editcrafter/dist/editcrafter.css';
25
39
 
26
- // Remove tseslint.configs.recommended and replace with this
27
- tseslint.configs.recommendedTypeChecked,
28
- // Alternatively, use this for stricter rules
29
- tseslint.configs.strictTypeChecked,
30
- // Optionally, add this for stylistic rules
31
- tseslint.configs.stylisticTypeChecked,
40
+ function App() {
41
+ const handleContentChange = (html: string) => {
42
+ console.log('Content updated:', html);
43
+ };
32
44
 
33
- // Other configs...
34
- ],
35
- languageOptions: {
36
- parserOptions: {
37
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
38
- tsconfigRootDir: import.meta.dirname,
39
- },
40
- // other options...
41
- },
42
- },
43
- ])
45
+ return (
46
+ <SimpleEditor
47
+ onContentChange={handleContentChange}
48
+ placeholder="Start writing..."
49
+ />
50
+ );
51
+ }
44
52
  ```
45
53
 
46
- You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
47
-
48
- ```js
49
- // eslint.config.js
50
- import reactX from 'eslint-plugin-react-x'
51
- import reactDom from 'eslint-plugin-react-dom'
52
-
53
- export default defineConfig([
54
- globalIgnores(['dist']),
55
- {
56
- files: ['**/*.{ts,tsx}'],
57
- extends: [
58
- // Other configs...
59
- // Enable lint rules for React
60
- reactX.configs['recommended-typescript'],
61
- // Enable lint rules for React DOM
62
- reactDom.configs.recommended,
63
- ],
64
- languageOptions: {
65
- parserOptions: {
66
- project: ['./tsconfig.node.json', './tsconfig.app.json'],
67
- tsconfigRootDir: import.meta.dirname,
68
- },
69
- // other options...
70
- },
71
- },
72
- ])
54
+ ### With Tailwind CSS v4
55
+
56
+ Tailwind v4 changed how CSS is imported. Here's how to integrate EditCrafter:
57
+
58
+ ```tsx
59
+ // app.tsx or main.tsx
60
+ import { SimpleEditor } from 'editcrafter';
61
+ // Import the CSS file
62
+ import 'editcrafter/dist/editcrafter.css';
63
+
64
+ function App() {
65
+ return (
66
+ <div className="container mx-auto p-4">
67
+ <SimpleEditor placeholder="Write something amazing..." />
68
+ </div>
69
+ );
70
+ }
73
71
  ```
72
+
73
+ **In your Tailwind CSS file:**
74
+
75
+ ```css
76
+ /* app.css or global.css */
77
+ @import "tailwindcss";
78
+ @import "editcrafter/dist/editcrafter.css";
79
+ ```
80
+
81
+ ### With Initial Content
82
+
83
+ ```tsx
84
+ const initialContent = `
85
+ <h1>Welcome to EditCrafter</h1>
86
+ <p>This is a <strong>rich text editor</strong> built with Tiptap.</p>
87
+ `;
88
+
89
+ <SimpleEditor
90
+ initialValue={initialContent}
91
+ onContentChange={handleContentChange}
92
+ />
93
+ ```
94
+
95
+ ### Custom Image Uploader
96
+
97
+ EditCrafter supports custom image upload handlers:
98
+
99
+ ```tsx
100
+ const uploadImage = async (
101
+ file: File,
102
+ onProgress?: (event: { progress: number }) => void,
103
+ abortSignal?: AbortSignal
104
+ ): Promise<string> => {
105
+ const formData = new FormData();
106
+ formData.append('image', file);
107
+
108
+ const response = await fetch('/api/upload', {
109
+ method: 'POST',
110
+ body: formData,
111
+ signal: abortSignal,
112
+ });
113
+
114
+ const data = await response.json();
115
+ return data.url; // Return the uploaded image URL
116
+ };
117
+
118
+ <SimpleEditor
119
+ imageUploaderConfig={{
120
+ enabledefault: true,
121
+ defaultUploadHandler: uploadImage,
122
+ }}
123
+ />
124
+ ```
125
+
126
+ ### Custom Toolbar Button for Images
127
+
128
+ For more control over image insertion:
129
+
130
+ ```tsx
131
+ import { SimpleEditor } from 'editcrafter';
132
+
133
+ const CustomImageButton = ({ addImage }: { addImage: (url: string) => void }) => {
134
+ const handleClick = async () => {
135
+ // Your custom image selection logic
136
+ const imageUrl = await selectImageFromGallery();
137
+ addImage(imageUrl);
138
+ };
139
+
140
+ return <button onClick={handleClick}>Add Image</button>;
141
+ };
142
+
143
+ <SimpleEditor
144
+ imageUploaderConfig={{
145
+ enabledefault: false,
146
+ CustomToolbarButton: CustomImageButton,
147
+ }}
148
+ />
149
+ ```
150
+
151
+ ## Components
152
+
153
+ ### SimpleEditor
154
+
155
+ The main editor component.
156
+
157
+ **Props:**
158
+
159
+ | Prop | Type | Default | Description |
160
+ |------|------|---------|-------------|
161
+ | `initialValue` | `string` | `undefined` | Initial HTML content |
162
+ | `onContentChange` | `(html: string) => void` | `undefined` | Callback when content changes |
163
+ | `wrapperClassName` | `string` | `undefined` | Custom class for wrapper div |
164
+ | `contentClassName` | `string` | `undefined` | Custom class for content area |
165
+ | `imageUploaderConfig` | `ImageUploaderType` | `undefined` | Image upload configuration |
166
+ | `placeholder` | `string` | `"Start writing here..."` | Placeholder text |
167
+
168
+ ### CrafterPreview
169
+
170
+ Component for rendering saved HTML content (read-only).
171
+
172
+ ```tsx
173
+ import { CrafterPreview } from 'editcrafter';
174
+
175
+ <CrafterPreview
176
+ value={savedHtmlContent}
177
+ className="my-preview"
178
+ />
179
+ ```
180
+
181
+ **Props:**
182
+
183
+ | Prop | Type | Description |
184
+ |------|------|-------------|
185
+ | `value` | `string` | HTML content to display |
186
+ | `className` | `string` | Custom class for wrapper div |
187
+
188
+ ### EnhancedImage Extension
189
+
190
+ For advanced users who want to extend the editor:
191
+
192
+ ```tsx
193
+ import { useEditor } from '@tiptap/react';
194
+ import { EnhancedImage } from 'editcrafter';
195
+
196
+ const editor = useEditor({
197
+ extensions: [
198
+ // ... other extensions
199
+ EnhancedImage,
200
+ ],
201
+ });
202
+
203
+ // Set image with custom attributes
204
+ editor.chain().focus().setImage({
205
+ src: 'image.jpg',
206
+ alt: 'Description',
207
+ width: '500px',
208
+ align: 'center',
209
+ }).run();
210
+
211
+ // Update alignment
212
+ editor.chain().focus().setImageAlign('left').run();
213
+
214
+ // Update width
215
+ editor.chain().focus().setImageWidth('100%').run();
216
+ ```
217
+
218
+ ## Styling
219
+
220
+ EditCrafter comes with pre-built CSS that includes:
221
+ - Editor layout and typography
222
+ - Toolbar styling
223
+ - Image bubble menu
224
+ - Table styling
225
+ - Theme variables for customization
226
+
227
+ ### Custom Theming
228
+
229
+ Override CSS variables to customize the theme:
230
+
231
+ ```css
232
+ :root {
233
+ --tt-brand-color-500: #3b82f6;
234
+ --tt-surface-color: #ffffff;
235
+ --tt-text-color: #1f2937;
236
+ --tt-border-color: #e5e7eb;
237
+ --tt-radius-md: 0.5rem;
238
+ }
239
+
240
+ [data-theme="dark"] {
241
+ --tt-surface-color: #1f2937;
242
+ --tt-text-color: #f9fafb;
243
+ --tt-border-color: #374151;
244
+ }
245
+ ```
246
+
247
+ ## TypeScript Support
248
+
249
+ EditCrafter is written in TypeScript and includes full type definitions.
250
+
251
+ ```tsx
252
+ import type {
253
+ EditCrafterProps,
254
+ ImageUploaderType,
255
+ CrafterPreviewProps,
256
+ } from 'editcrafter';
257
+ ```
258
+
259
+ ## Browser Support
260
+
261
+ - Chrome (latest)
262
+ - Firefox (latest)
263
+ - Safari (latest)
264
+ - Edge (latest)
265
+
266
+ ## License
267
+
268
+ MIT
269
+
270
+ ## Contributing
271
+
272
+ Contributions are welcome! Please feel free to submit a Pull Request.
273
+
274
+ ## Support
275
+
276
+ If you encounter any issues or have questions, please [file an issue](https://github.com/yourusername/editcrafter/issues).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editcrafter",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "type": "module",
5
5
  "main": "./dist/editcrafter.umd.js",
6
6
  "module": "./dist/editcrafter.es.js",
@@ -42,6 +42,7 @@
42
42
  "@tiptap/pm": "^3.19.0",
43
43
  "@tiptap/react": "^3.19.0",
44
44
  "@tiptap/starter-kit": "^3.19.0",
45
+ "editcrafter": "^1.0.1",
45
46
  "html-react-parser": "^5.2.17",
46
47
  "lodash.throttle": "^4.1.1",
47
48
  "react": "^19.2.0",