pdeditor 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +313 -0
  2. package/package.json +6 -4
package/README.md ADDED
@@ -0,0 +1,313 @@
1
+ # Custom Text Editor
2
+
3
+ A feature-rich, lightweight WYSIWYG editor built with React and TypeScript. No external dependencies required beyond React.
4
+
5
+ ## 🚀 Features
6
+
7
+ ### Text Formatting
8
+ - **Bold**, *Italic*, <u>Underline</u>, ~~Strikethrough~~
9
+ - Subscript (x₂) and Superscript (x²)
10
+ - Text color and background color picker
11
+ - Font size control (Small, Normal, Large, Huge)
12
+
13
+ ### Paragraph Formatting
14
+ - Heading styles (H1-H6)
15
+ - Paragraph, Address, Quote formats
16
+ - Text alignment (Left, Center, Right, Justify)
17
+ - Blockquote
18
+ - Bullet and numbered lists
19
+ - Indent/Outdent
20
+
21
+ ### Advanced Features
22
+ - **Source Mode**: Toggle between visual and HTML view
23
+ - **Special Characters**: Insert symbols, Greek letters, math symbols (Ω button)
24
+ - **Find & Replace**: Search with match case, whole word, and cyclic options
25
+ - **Color Picker**: 80+ color swatches for text and background
26
+ - **Table Insert**: Interactive grid selector for creating tables
27
+ - **Fullscreen Mode**: Expand editor to fullscreen (ESC to exit)
28
+ - **Clipboard**: Copy, Paste, and Paste as Plain Text
29
+
30
+ ## 📦 Installation
31
+
32
+ ```bash
33
+ npm install pdeditor
34
+ ```
35
+
36
+ ## 🔧 Requirements
37
+
38
+ ### Peer Dependencies
39
+ ```json
40
+ {
41
+ "react": ">=17",
42
+ "react-dom": ">=17"
43
+ }
44
+ ```
45
+
46
+ ### Browser Support
47
+ - Modern browsers (Chrome, Firefox, Safari, Edge)
48
+ - ES2017+ support
49
+ - Fullscreen API (for fullscreen feature)
50
+ - Clipboard API (for paste plain text)
51
+
52
+ ## 💻 Usage
53
+
54
+ ### Basic Example
55
+
56
+ ```tsx
57
+ import React, { useState } from 'react';
58
+ import { CustomEditor } from 'pdeditor';
59
+
60
+ function App() {
61
+ const [content, setContent] = useState('<p>Start editing...</p>');
62
+
63
+ return (
64
+ <div>
65
+ <CustomEditor
66
+ value={content}
67
+ onChange={setContent}
68
+ />
69
+ </div>
70
+ );
71
+ }
72
+ ```
73
+
74
+ ### TypeScript
75
+
76
+ ```tsx
77
+ import React, { useState } from 'react';
78
+ import { CustomEditor } from 'pdeditor';
79
+
80
+ const MyEditor: React.FC = () => {
81
+ const [htmlContent, setHtmlContent] = useState<string>('');
82
+
83
+ const handleChange = (newContent: string) => {
84
+ setHtmlContent(newContent);
85
+ // Save to backend, localStorage, etc.
86
+ };
87
+
88
+ return (
89
+ <CustomEditor
90
+ value={htmlContent}
91
+ onChange={handleChange}
92
+ />
93
+ );
94
+ };
95
+ ```
96
+
97
+ ### Controlled Component
98
+
99
+ ```tsx
100
+ import React, { useState, useEffect } from 'react';
101
+ import { CustomEditor } from 'pdeditor';
102
+
103
+ function ControlledEditor() {
104
+ const [content, setContent] = useState('');
105
+
106
+ // Load initial content
107
+ useEffect(() => {
108
+ fetch('/api/content')
109
+ .then(res => res.json())
110
+ .then(data => setContent(data.html));
111
+ }, []);
112
+
113
+ // Auto-save on change
114
+ const handleChange = (newContent: string) => {
115
+ setContent(newContent);
116
+ // Debounce this in production
117
+ fetch('/api/content', {
118
+ method: 'POST',
119
+ body: JSON.stringify({ html: newContent })
120
+ });
121
+ };
122
+
123
+ return <CustomEditor value={content} onChange={handleChange} />;
124
+ }
125
+ ```
126
+
127
+ ## 📋 API Reference
128
+
129
+ ### Props
130
+
131
+ | Prop | Type | Required | Description |
132
+ |------|------|----------|-------------|
133
+ | `value` | `string` | No | HTML content to display in the editor |
134
+ | `onChange` | `(value: string) => void` | No | Callback fired when content changes |
135
+
136
+ ### Example with All Props
137
+
138
+ ```tsx
139
+ <CustomEditor
140
+ value="<p>Initial HTML content</p>"
141
+ onChange={(html) => console.log('Content changed:', html)}
142
+ />
143
+ ```
144
+
145
+ ## 🎨 Styling
146
+
147
+ The editor comes with default styling. You can wrap it in a container to customize:
148
+
149
+ ```tsx
150
+ <div style={{ maxWidth: '800px', margin: '0 auto' }}>
151
+ <CustomEditor value={content} onChange={setContent} />
152
+ </div>
153
+ ```
154
+
155
+ ### Custom Container Styling
156
+
157
+ ```tsx
158
+ <div className="editor-wrapper">
159
+ <CustomEditor value={content} onChange={setContent} />
160
+ </div>
161
+ ```
162
+
163
+ ```css
164
+ .editor-wrapper {
165
+ border: 2px solid #e0e0e0;
166
+ border-radius: 8px;
167
+ overflow: hidden;
168
+ box-shadow: 0 2px 8px rgba(0,0,0,0.1);
169
+ }
170
+ ```
171
+
172
+ ## 🛠️ Development
173
+
174
+ ### Setup
175
+
176
+ ```bash
177
+ # Clone the repository
178
+ git clone <repo-url>
179
+ cd pdeditor
180
+
181
+ # Install dependencies
182
+ npm install
183
+
184
+ # Build
185
+ npm run build
186
+ ```
187
+
188
+ ### Project Structure
189
+
190
+ ```
191
+ pdeditor/
192
+ ├── src/
193
+ │ └── index.tsx # Main editor component
194
+ ├── dist/ # Built files
195
+ ├── package.json
196
+ ├── tsconfig.json
197
+ └── README.md
198
+ ```
199
+
200
+ ## 🎯 Toolbar Features
201
+
202
+ ### Top Row
203
+ - **Source**: Toggle HTML source view
204
+ - **Style**: Paragraph, H1-H6, Pre
205
+ - **Format**: Normal, Address, Quote
206
+ - **Size**: Small, Normal, Large, Huge
207
+
208
+ ### Formatting
209
+ - **B**: Bold
210
+ - **I**: Italic
211
+ - **U**: Underline
212
+ - **S**: Strikethrough
213
+ - **x₂**: Subscript
214
+ - **x²**: Superscript
215
+
216
+ ### Colors
217
+ - **A**: Text color picker
218
+ - **◼**: Background color picker
219
+
220
+ ### Alignment
221
+ - Left, Center, Right, Justify
222
+
223
+ ### Lists & Indentation
224
+ - Bullet list
225
+ - Numbered list
226
+ - Indent/Outdent
227
+
228
+ ### Advanced
229
+ - **"**: Blockquote
230
+ - **Table**: Insert table with grid selector
231
+ - **Ω**: Special characters modal
232
+ - **🔍**: Find & Replace
233
+ - **Copy/Paste**: Clipboard operations
234
+ - **⊕**: Fullscreen toggle
235
+
236
+ ## 🔑 Keyboard Shortcuts
237
+
238
+ | Shortcut | Action |
239
+ |----------|--------|
240
+ | `Ctrl/Cmd + B` | Bold |
241
+ | `Ctrl/Cmd + I` | Italic |
242
+ | `Ctrl/Cmd + U` | Underline |
243
+ | `Ctrl/Cmd + C` | Copy |
244
+ | `Ctrl/Cmd + V` | Paste |
245
+ | `ESC` | Exit fullscreen |
246
+
247
+ ## 📝 Output Format
248
+
249
+ The editor outputs clean HTML:
250
+
251
+ ```html
252
+ <p>Regular paragraph with <strong>bold</strong> and <em>italic</em> text.</p>
253
+ <h1>Heading 1</h1>
254
+ <ul>
255
+ <li>List item 1</li>
256
+ <li>List item 2</li>
257
+ </ul>
258
+ <table border="1" style="border-collapse: collapse; width: 100%;">
259
+ <tr>
260
+ <td style="padding: 8px; border: 1px solid #ddd;">Cell 1</td>
261
+ <td style="padding: 8px; border: 1px solid #ddd;">Cell 2</td>
262
+ </tr>
263
+ </table>
264
+ ```
265
+
266
+ ## ⚠️ Important Notes
267
+
268
+ ### Content Security
269
+ - Always sanitize HTML output before rendering on your backend
270
+ - Use libraries like DOMPurify for XSS protection
271
+ - Validate content before saving to database
272
+
273
+ ### Performance
274
+ - For large documents, consider debouncing the `onChange` callback
275
+ - Use React.memo if embedding multiple editors
276
+
277
+ ### Browser Compatibility
278
+ - `document.execCommand()` is used for formatting (deprecated but widely supported)
279
+ - Fullscreen API requires user interaction to trigger
280
+ - Clipboard API may require HTTPS in production
281
+
282
+ ## 🐛 Troubleshooting
283
+
284
+ ### Editor not rendering
285
+ ```tsx
286
+ // Make sure React is imported
287
+ import React from 'react';
288
+ import { CustomEditor } from 'pdeditor';
289
+ ```
290
+
291
+ ### TypeScript errors
292
+ ```bash
293
+ # Ensure peer dependencies are installed
294
+ npm install react react-dom
295
+ npm install -D @types/react @types/react-dom
296
+ ```
297
+
298
+ ### Paste not working
299
+ - Paste requires clipboard permissions
300
+ - Use HTTPS in production
301
+ - Fallback to Ctrl+V if programmatic paste fails
302
+
303
+ ## 📄 License
304
+
305
+ ISC
306
+
307
+ ## 🤝 Contributing
308
+
309
+ Contributions welcome! Please open an issue or submit a PR.
310
+
311
+ ## 📧 Support
312
+
313
+ For issues and questions, please connect https://www.linkedin.com/in/prashant-dubey-81a102173/
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "pdeditor",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "index.js",
5
- "scripts": {
5
+ "scripts": {
6
6
  "build": "tsup src/index.tsx --dts"
7
7
  },
8
8
  "keywords": [],
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "type": "commonjs",
12
- "files": ["dist"],
12
+ "files": [
13
+ "dist"
14
+ ],
13
15
  "description": "",
14
16
  "devDependencies": {
15
17
  "@types/react": "^19.2.13",
@@ -17,7 +19,7 @@
17
19
  "tsup": "^8.5.1",
18
20
  "typescript": "^5.9.3"
19
21
  },
20
- "peerDependencies": {
22
+ "peerDependencies": {
21
23
  "react": ">=17",
22
24
  "react-dom": ">=17"
23
25
  },