@lax-wp/editor 0.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 (121) hide show
  1. package/README.md +724 -0
  2. package/dist/components/Editor.d.ts +6 -0
  3. package/dist/components/EditorShell.d.ts +1 -0
  4. package/dist/components/PresentationControls.d.ts +6 -0
  5. package/dist/components/base/Button.d.ts +14 -0
  6. package/dist/components/base/Button1.d.ts +24 -0
  7. package/dist/components/base/ColorPicker.d.ts +14 -0
  8. package/dist/components/base/index.d.ts +1 -0
  9. package/dist/components/common/ScrollbarWrapper.d.ts +5 -0
  10. package/dist/components/common/SkeletonLine.d.ts +6 -0
  11. package/dist/components/common/SvgIcon.d.ts +15 -0
  12. package/dist/components/footer/index.d.ts +5 -0
  13. package/dist/components/menubar/BubbleMenuContent.d.ts +6 -0
  14. package/dist/components/menubar/bubble-menu/DefaultBubbleMenuContent.d.ts +1 -0
  15. package/dist/components/menubar/bubble-menu/ImageMenuContent.d.ts +1 -0
  16. package/dist/components/menubar/bubble-menu/LinkActions.d.ts +4 -0
  17. package/dist/components/menubar/bubble-menu/LinkMenuContent.d.ts +1 -0
  18. package/dist/components/menubar/bubble-menu/index.d.ts +4 -0
  19. package/dist/components/node/ImageNode.d.ts +5 -0
  20. package/dist/components/shared/BasicFontStyleOptions.d.ts +1 -0
  21. package/dist/components/shared/ClearTextFormatButton.d.ts +1 -0
  22. package/dist/components/shared/FontSizeStepper.d.ts +1 -0
  23. package/dist/components/shared/InsertLinkButton.d.ts +4 -0
  24. package/dist/components/shared/ParagraphAlignmentOptions.d.ts +1 -0
  25. package/dist/components/toolbar/ClassicToolbar.d.ts +8 -0
  26. package/dist/components/toolbar/Divider.d.ts +1 -0
  27. package/dist/components/toolbar/FontStyleOptions.d.ts +4 -0
  28. package/dist/components/toolbar/HeadingOptions.d.ts +6 -0
  29. package/dist/components/toolbar/HomeOptions.d.ts +6 -0
  30. package/dist/components/toolbar/InsertOptions.d.ts +6 -0
  31. package/dist/components/toolbar/ItemGroup.d.ts +6 -0
  32. package/dist/components/toolbar/LinkActionsModal.d.ts +14 -0
  33. package/dist/components/toolbar/LinkModal.d.ts +16 -0
  34. package/dist/components/toolbar/OrderedListTypeDropdownContent.d.ts +7 -0
  35. package/dist/components/toolbar/ParagraphStyleOption.d.ts +6 -0
  36. package/dist/components/toolbar/ProfessionalToolbar.d.ts +8 -0
  37. package/dist/components/toolbar/RenderToolbarTabContent.d.ts +6 -0
  38. package/dist/components/toolbar/ScrollableContent.d.ts +14 -0
  39. package/dist/components/toolbar/Toolbar.d.ts +10 -0
  40. package/dist/components/toolbar/ToolbarButtonItem.d.ts +15 -0
  41. package/dist/components/toolbar/ToolbarDropdown.d.ts +5 -0
  42. package/dist/components/toolbar/UnorderedListTypeDropdownContent.d.ts +7 -0
  43. package/dist/components/toolbar/export/index.d.ts +1 -0
  44. package/dist/components/toolbar/home/FontStyleOptions.d.ts +1 -0
  45. package/dist/components/toolbar/home/HeadingOptions.d.ts +1 -0
  46. package/dist/components/toolbar/home/OrderedListTypeDropdownContent.d.ts +5 -0
  47. package/dist/components/toolbar/home/ParagraphStyleOption.d.ts +1 -0
  48. package/dist/components/toolbar/home/UnorderedListTypeDropdownContent.d.ts +5 -0
  49. package/dist/components/toolbar/home/index.d.ts +1 -0
  50. package/dist/components/toolbar/index.d.ts +11 -0
  51. package/dist/components/toolbar/insert/CodeBlockToolbar.d.ts +8 -0
  52. package/dist/components/toolbar/insert/DividerDropdownContent.d.ts +5 -0
  53. package/dist/components/toolbar/insert/ImageUploadForm.d.ts +6 -0
  54. package/dist/components/toolbar/insert/LinkForm.d.ts +10 -0
  55. package/dist/components/toolbar/insert/index.d.ts +1 -0
  56. package/dist/components/toolbar/page/PageBackgroundColorPicker.d.ts +8 -0
  57. package/dist/components/toolbar/page/PageMarginPicker.d.ts +8 -0
  58. package/dist/components/toolbar/page/PageOrientationSelector.d.ts +8 -0
  59. package/dist/components/toolbar/page/PageSizeSelector.d.ts +13 -0
  60. package/dist/components/toolbar/page/index.d.ts +1 -0
  61. package/dist/components/toolbar/table/TableSelector.d.ts +8 -0
  62. package/dist/components/toolbar/table/index.d.ts +1 -0
  63. package/dist/config/editorConfig.d.ts +43 -0
  64. package/dist/constants/AI.d.ts +2 -0
  65. package/dist/constants/CodeBlock.d.ts +8 -0
  66. package/dist/constants/Common.d.ts +8 -0
  67. package/dist/constants/DividerLineTypes.d.ts +4 -0
  68. package/dist/constants/Fonts.d.ts +8 -0
  69. package/dist/constants/Footer.d.ts +1 -0
  70. package/dist/constants/Heading.d.ts +42 -0
  71. package/dist/constants/Image.d.ts +15 -0
  72. package/dist/constants/LinkConstants.d.ts +4 -0
  73. package/dist/constants/PageBackground.d.ts +4 -0
  74. package/dist/constants/Paragraphs.d.ts +12 -0
  75. package/dist/constants/TinkConstants.d.ts +4 -0
  76. package/dist/constants/Toolbar.d.ts +25 -0
  77. package/dist/constants/base.d.ts +1 -0
  78. package/dist/constants/index.d.ts +6 -0
  79. package/dist/contexts/EditorShellContext.d.ts +15 -0
  80. package/dist/contexts/ToolbarContext.d.ts +25 -0
  81. package/dist/editor.css +1 -0
  82. package/dist/extensions/AIAutoCompletion.d.ts +38 -0
  83. package/dist/extensions/CodeBlockWithToolbar.d.ts +28 -0
  84. package/dist/extensions/CustomImageExtension.d.ts +15 -0
  85. package/dist/extensions/HorizontalRuleWithStyle.d.ts +10 -0
  86. package/dist/extensions/Indent.d.ts +15 -0
  87. package/dist/extensions/ListItemWithDepthLimit.d.ts +4 -0
  88. package/dist/extensions/OnBlurHighlight.d.ts +2 -0
  89. package/dist/extensions/OrderedListWithType.d.ts +9 -0
  90. package/dist/extensions/PageBackground.d.ts +20 -0
  91. package/dist/extensions/PageBreak.d.ts +16 -0
  92. package/dist/extensions/PageMargin.d.ts +79 -0
  93. package/dist/extensions/UnorderedListWithType.d.ts +9 -0
  94. package/dist/extensions/VariableTable.d.ts +4 -0
  95. package/dist/extensions/VariableText.d.ts +39 -0
  96. package/dist/extensions/index.d.ts +2 -0
  97. package/dist/hooks/useCodeEditor.d.ts +25 -0
  98. package/dist/hooks/useExport.d.ts +7 -0
  99. package/dist/hooks/useFontStyleMethods.d.ts +19 -0
  100. package/dist/hooks/useHeadingStyleMethods.d.ts +3 -0
  101. package/dist/hooks/useHomeOptionMethods.d.ts +13 -0
  102. package/dist/hooks/useHorizontalScroll.d.ts +13 -0
  103. package/dist/hooks/useImageAlignment.d.ts +12 -0
  104. package/dist/hooks/useImageResize.d.ts +17 -0
  105. package/dist/hooks/useImageUpload.d.ts +17 -0
  106. package/dist/hooks/useInsertOptionMethods.d.ts +4 -0
  107. package/dist/hooks/useLinks.d.ts +15 -0
  108. package/dist/hooks/usePageMethods.d.ts +56 -0
  109. package/dist/hooks/useParagraphStyleMethods.d.ts +16 -0
  110. package/dist/hooks/usePresentationMode.d.ts +7 -0
  111. package/dist/hooks/useTableMethods.d.ts +12 -0
  112. package/dist/hooks/useTiptapEditorState.d.ts +40 -0
  113. package/dist/hooks/useZoom.d.ts +7 -0
  114. package/dist/index.d.ts +5 -0
  115. package/dist/index.es.js +64287 -0
  116. package/dist/index.umd.js +196 -0
  117. package/dist/lax-wp-editor.css +1 -0
  118. package/dist/utils/Common.d.ts +1 -0
  119. package/dist/utils/svgIconRegistry.d.ts +1 -0
  120. package/dist/vite.svg +1 -0
  121. package/package.json +117 -0
package/README.md ADDED
@@ -0,0 +1,724 @@
1
+ # Lax WP Editor
2
+
3
+ A modern, feature-rich WordPress-style editor built with React and TipTap. This editor provides a clean, intuitive interface for rich text editing with customizable toolbars and extensive formatting options.
4
+
5
+ ## Table of Contents
6
+
7
+ - [Recent Updates](#recent-updates)
8
+ - [Features](#features)
9
+ - [Installation](#installation)
10
+ - [Quick Start](#quick-start)
11
+ - [Configuration](#configuration)
12
+ - [Basic Configuration](#basic-configuration)
13
+ - [AI Autocompletion](#ai-autocompletion)
14
+ - [Export Functionality](#export-functionality)
15
+ - [Variable Text Feature](#variable-text-feature)
16
+ - [Configuration Options Reference](#configuration-options-reference)
17
+ - [Components](#components)
18
+ - [Hooks](#hooks)
19
+ - [API Reference](#api-reference)
20
+ - [Examples](#examples)
21
+ - [Development](#development)
22
+ - [Contributing](#contributing)
23
+ - [License](#license)
24
+
25
+ ## Recent Updates
26
+
27
+ ### v2.0.0 - Latest Release
28
+
29
+ #### ✨ Export Functionality
30
+ - Added comprehensive export system with support for multiple formats
31
+ - Export your content as Text (.txt), JSON (.json), Markdown (.md), or HTML (.html)
32
+ - New **Export** tab in the toolbar for quick access to all export options
33
+ - `useExport` hook for programmatic export functionality
34
+
35
+ #### 📝 Variable Text Feature
36
+ - Dynamic variable text support for mail merge and templates
37
+ - Insert variables programmatically from your application
38
+ - `onEditorReady` callback provides `insertVariable` method
39
+ - Variables display actual values or `{{variableName}}` placeholders
40
+ - Supports manual typing with `{{variableName}}` syntax
41
+
42
+ #### 🎨 Toolbar Enhancements
43
+ - Improved toolbar dropdown with visual icons for each mode
44
+ - Better visual distinction between Professional, Classic, and Hide Toolbar modes
45
+ - Enhanced toolbar tab interface with 5 tabs: Home, Insert, Table, Page, and Export
46
+ - Smoother transitions between toolbar types
47
+
48
+ #### 🖼️ Custom Image Support
49
+ - Resizable images with drag handles
50
+ - Image alignment (left, center, right)
51
+ - Bubble menu for image options
52
+ - Inline and block image support
53
+
54
+ ## Features
55
+
56
+ - 🎨 **Modern UI**: Clean, responsive design with customizable themes
57
+ - 📝 **Rich Text Editing**: Full-featured WYSIWYG editor with TipTap
58
+ - 🛠️ **Flexible Toolbars**: Professional and Classic toolbar modes with tabbed interface
59
+ - 📄 **Page Management**: Multiple page sizes and orientations
60
+ - 📤 **Export Options**: Export your content as Text, HTML, Markdown, or JSON
61
+ - 📝 **Variable Text**: Dynamic variables for mail merge and template systems
62
+ - 🖼️ **Image Support**: Resizable images with alignment and custom styling
63
+ - 🎯 **Customizable**: Easy to integrate and customize
64
+ - 📱 **Responsive**: Works seamlessly on desktop and mobile
65
+ - 🔧 **TypeScript**: Full TypeScript support with type definitions
66
+
67
+ ## Installation
68
+
69
+ ```bash
70
+ npm install lax-wp-editor
71
+ # or
72
+ yarn add lax-wp-editor
73
+ # or
74
+ pnpm add lax-wp-editor
75
+ ```
76
+
77
+ ## Quick Start
78
+
79
+ ```tsx
80
+ import React from 'react';
81
+ import { Editor } from 'lax-wp-editor'; // CSS is automatically included!
82
+
83
+ function App() {
84
+ return (
85
+ <div style={{ height: '100vh', width: '100%' }}>
86
+ <Editor />
87
+ </div>
88
+ );
89
+ }
90
+
91
+ export default App;
92
+ ```
93
+
94
+ > **✨ New in v1.2.0:** CSS is now automatically imported! You no longer need to manually import the styles.
95
+ >
96
+ > **For older versions (v1.1.x), you need to manually import styles:**
97
+ > ```tsx
98
+ > import 'lax-wp-editor/styles';
99
+ > // or
100
+ > import 'lax-wp-editor/dist/lax-wp-editor.css';
101
+ > ```
102
+
103
+ ## Configuration
104
+
105
+ The editor accepts a `config` prop with the following options:
106
+
107
+ ### Basic Configuration
108
+
109
+ ```tsx
110
+ import { Editor, type EditorConfig } from 'lax-wp-editor';
111
+
112
+ function App() {
113
+ const config: EditorConfig = {
114
+ // Initial content (HTML string)
115
+ content: '<p>Your initial content here</p>',
116
+
117
+ // Toolbar type: 'professional' or 'classic'
118
+ defaultToolbar: 'professional',
119
+
120
+ // Enable/disable features
121
+ showBubbleMenu: true, // Show bubble menu on text selection
122
+ showFloatingMenu: false, // Show floating menu on empty lines
123
+ showPageSizeSelector: true, // Show page size selector
124
+ enablePagination: true, // Enable pagination
125
+
126
+ // Content change callback with debounce
127
+ debounceTimeForContentChange: 300, // Debounce time in milliseconds (default: 300ms)
128
+ onContentChange: (editor) => {
129
+ const html = editor.getHTML();
130
+ console.log('Content changed:', html);
131
+ },
132
+ };
133
+
134
+ return (
135
+ <div style={{ height: '100vh', width: '100%' }}>
136
+ <Editor config={config} />
137
+ </div>
138
+ );
139
+ }
140
+ ```
141
+
142
+ ### AI Autocompletion
143
+
144
+ You can enable AI autocompletion by providing your own completion function:
145
+
146
+ ```tsx
147
+ import { Editor, type EditorConfig } from 'lax-wp-editor';
148
+
149
+ function App() {
150
+ const config: EditorConfig = {
151
+ aiAutocompletion: {
152
+ enabled: true,
153
+ minWordsToTriggerAutoCompletion: 5, // Trigger after 5 words (default: 3)
154
+ debounceTime: 300, // Wait 300ms before calling API (default: 100ms)
155
+
156
+ // Required: Provide your custom fetch function
157
+ fetchCompletion: async (text: string) => {
158
+ const response = await fetch('https://your-api.com/completions', {
159
+ method: 'POST',
160
+ headers: {
161
+ 'Content-Type': 'application/json',
162
+ 'Authorization': 'Bearer YOUR_API_KEY',
163
+ },
164
+ body: JSON.stringify({ prompt: text }),
165
+ });
166
+ const data = await response.json();
167
+ return data.completion; // Return the completion text
168
+ },
169
+ },
170
+ };
171
+
172
+ return (
173
+ <div style={{ height: '100vh', width: '100%' }}>
174
+ <Editor config={config} />
175
+ </div>
176
+ );
177
+ }
178
+ ```
179
+
180
+ > **⚠️ Important:** AI autocompletion requires you to provide a `fetchCompletion` function. The editor does not include a default AI service.
181
+
182
+ **Keyboard Shortcuts for AI Autocompletion:**
183
+ - `Tab` - Accept suggestion
184
+ - `Escape` - Dismiss suggestion
185
+ - `Ctrl+Shift+Space` (Windows/Linux) or `Cmd+Shift+Space` (Mac) - Toggle autocompletion on/off
186
+
187
+ ### Export Functionality
188
+
189
+ The editor includes a comprehensive export system that allows users to download their content in multiple formats:
190
+
191
+ ```tsx
192
+ import { Editor, useExport } from 'lax-wp-editor';
193
+
194
+ function MyEditorComponent({ editor }) {
195
+ const {
196
+ downloadTextFile,
197
+ downloadJsonFile,
198
+ downloadMarkdownFile,
199
+ downloadHtmlFile
200
+ } = useExport(editor);
201
+
202
+ return (
203
+ <div>
204
+ <button onClick={downloadTextFile}>Export as Text</button>
205
+ <button onClick={downloadJsonFile}>Export as JSON</button>
206
+ <button onClick={downloadMarkdownFile}>Export as Markdown</button>
207
+ <button onClick={downloadHtmlFile}>Export as HTML</button>
208
+ </div>
209
+ );
210
+ }
211
+ ```
212
+
213
+ **Available Export Formats:**
214
+
215
+ | Format | Description | Method |
216
+ |--------|-------------|--------|
217
+ | **Text** | Plain text (.txt) | `downloadTextFile()` |
218
+ | **JSON** | TipTap JSON format (.json) | `downloadJsonFile()` |
219
+ | **Markdown** | Markdown format (.md) | `downloadMarkdownFile()` |
220
+ | **HTML** | HTML format (.html) | `downloadHtmlFile()` |
221
+
222
+ > **💡 Tip:** The Export tab is built into the toolbar and provides quick access to all export formats. You can also use the `useExport` hook to create custom export buttons.
223
+
224
+ ### Variable Text Feature
225
+
226
+ The editor supports dynamic variable text that can be inserted programmatically from your application. Variables are displayed as placeholders that get replaced with actual values.
227
+
228
+ **Enable Variable Text:**
229
+
230
+ ```tsx
231
+ import { useState } from 'react';
232
+ import { Editor } from 'lax-wp-editor';
233
+
234
+ function App() {
235
+ const [insertVariable, setInsertVariable] = useState<((key: string, value?: string) => void) | null>(null);
236
+
237
+ const handleInsertName = () => {
238
+ insertVariable?.('userName');
239
+ };
240
+
241
+ const handleInsertEmailWithValue = () => {
242
+ insertVariable?.('email', 'newemail@example.com');
243
+ };
244
+
245
+ return (
246
+ <div>
247
+ <button onClick={handleInsertName}>Insert User Name</button>
248
+ <button onClick={handleInsertEmailWithValue}>Insert Email</button>
249
+
250
+ <Editor
251
+ config={{
252
+ enableVariableText: true,
253
+ variableValues: {
254
+ userName: 'John Doe',
255
+ email: 'john@example.com',
256
+ company: 'Acme Inc',
257
+ },
258
+ onEditorReady: ({ insertVariable: insert }) => {
259
+ // Store the insertVariable method when editor is ready
260
+ setInsertVariable(() => insert);
261
+ },
262
+ }}
263
+ />
264
+ </div>
265
+ );
266
+ }
267
+ ```
268
+
269
+ **Variable Text Configuration:**
270
+
271
+ | Option | Type | Description |
272
+ |--------|------|-------------|
273
+ | `enableVariableText` | `boolean` | Enable/disable variable text feature |
274
+ | `variableValues` | `Record<string, string>` | Key-value pairs for variable replacements |
275
+ | `onEditorReady` | `(methods) => void` | Callback that provides editor methods including `insertVariable` |
276
+
277
+ **Insert Variable Method:**
278
+
279
+ ```tsx
280
+ insertVariable(key: string, value?: string)
281
+ ```
282
+
283
+ - **`key`**: The variable name/key
284
+ - **`value`**: (Optional) Update the variable value before inserting
285
+
286
+ **How Variables Work:**
287
+
288
+ 1. Variables are inserted as special nodes in the editor
289
+ 2. They display the value from `variableValues` config
290
+ 3. If no value exists, they display as `{{variableName}}`
291
+ 4. Variables can be typed manually using `{{variableName}}` syntax (if enabled)
292
+ 5. Users can insert variables programmatically from outside the editor
293
+
294
+ **Example Use Cases:**
295
+
296
+ - Mail merge functionality
297
+ - Template systems
298
+ - Dynamic content generation
299
+ - Personalized documents
300
+
301
+ ### Configuration Options Reference
302
+
303
+ | Option | Type | Default | Description |
304
+ |--------|------|---------|-------------|
305
+ | `content` | `string` | `""` | Initial HTML content for the editor |
306
+ | `defaultToolbar` | `'professional' \| 'classic'` | `'professional'` | Toolbar style |
307
+ | `showBubbleMenu` | `boolean` | `true` | Show bubble menu on text selection |
308
+ | `showFloatingMenu` | `boolean` | `false` | Show floating menu on empty lines |
309
+ | `showPageSizeSelector` | `boolean` | `true` | Show page size selector |
310
+ | `enablePagination` | `boolean` | `true` | Enable pagination |
311
+ | `debounceTimeForContentChange` | `number` | `300` | Debounce time (ms) for `onContentChange` callback |
312
+ | `onContentChange` | `(editor: Editor) => void` | `undefined` | Callback when content changes (debounced) |
313
+ | `enableVariableText` | `boolean` | `false` | Enable variable text feature |
314
+ | `variableValues` | `Record<string, string>` | `{}` | Variable name to value mappings |
315
+ | `onEditorReady` | `(methods) => void` | `undefined` | Callback with editor methods when ready |
316
+ | `onShare` | `() => void` | `undefined` | Callback when share button is clicked |
317
+ | `aiAutocompletion` | `AIAutocompletionConfig` | See below | AI autocompletion configuration |
318
+
319
+ **AIAutocompletionConfig:**
320
+
321
+ | Option | Type | Default | Description |
322
+ |--------|------|---------|-------------|
323
+ | `enabled` | `boolean` | `false` | Enable/disable AI autocompletion |
324
+ | `minWordsToTriggerAutoCompletion` | `number` | `3` | Minimum words to trigger autocompletion |
325
+ | `debounceTime` | `number` | `100` | Debounce time (ms) before calling API |
326
+ | `fetchCompletion` | `(text: string) => Promise<string>` | `undefined` | **Required** - Custom fetch function for AI completions |
327
+
328
+ ### Important: Fixing ProseMirror Duplication Error
329
+
330
+ If you encounter the `localsInner` error, it's caused by multiple versions of ProseMirror packages in **your application's** dependency tree.
331
+
332
+ **Official Tiptap Solution:**
333
+
334
+ This package already uses `@tiptap/pm` for all ProseMirror functionality (as recommended by Tiptap). However, you need to ensure your application also deduplicates ProseMirror versions.
335
+
336
+ **1. In your application directory, check for duplicate ProseMirror versions:**
337
+ ```bash
338
+ npm ls prosemirror-view
339
+ # or
340
+ yarn list prosemirror-view
341
+ ```
342
+
343
+ **2. If you see multiple versions, add this to YOUR APPLICATION's `package.json`:**
344
+
345
+ **For Yarn users:**
346
+ ```json
347
+ {
348
+ "resolutions": {
349
+ "prosemirror-view": "^1.41.0",
350
+ "prosemirror-state": "^1.4.3",
351
+ "prosemirror-model": "^1.25.0",
352
+ "prosemirror-transform": "^1.10.0"
353
+ }
354
+ }
355
+ ```
356
+
357
+ **For npm users (v8.3.0+):**
358
+ ```json
359
+ {
360
+ "overrides": {
361
+ "prosemirror-view": "^1.41.0",
362
+ "prosemirror-state": "^1.4.3",
363
+ "prosemirror-model": "^1.25.0",
364
+ "prosemirror-transform": "^1.10.0"
365
+ }
366
+ }
367
+ ```
368
+
369
+ **For pnpm users:**
370
+ ```json
371
+ {
372
+ "pnpm": {
373
+ "overrides": {
374
+ "prosemirror-view": "^1.41.0",
375
+ "prosemirror-state": "^1.4.3",
376
+ "prosemirror-model": "^1.25.0",
377
+ "prosemirror-transform": "^1.10.0"
378
+ }
379
+ }
380
+ }
381
+ ```
382
+
383
+ **3. Clean install in YOUR APPLICATION:**
384
+ ```bash
385
+ # In your application directory (not lax-wp-editor)
386
+ rm -rf node_modules package-lock.json # or yarn.lock / pnpm-lock.yaml
387
+ npm install # or yarn / pnpm install
388
+ ```
389
+
390
+ **4. Verify all packages are deduped:**
391
+ ```bash
392
+ npm ls prosemirror-view
393
+ # All instances should show "deduped" and point to the same version
394
+ ```
395
+
396
+ > **Note:** This package uses `@tiptap/pm` internally (not direct ProseMirror imports) to prevent version conflicts. The deduplication step is only needed if other packages in your project import ProseMirror directly.
397
+
398
+ ## Basic Usage
399
+
400
+ ### Simple Editor
401
+
402
+ ```tsx
403
+ import { Editor, ToolbarProvider } from 'lax-wp-editor';
404
+ import 'lax-wp-editor/styles';
405
+
406
+ function MyEditor() {
407
+ return (
408
+ <ToolbarProvider>
409
+ <Editor />
410
+ </ToolbarProvider>
411
+ );
412
+ }
413
+ ```
414
+
415
+ ### Custom Configuration
416
+
417
+ ```tsx
418
+ import { Editor, ToolbarProvider, defaultEditorConfig } from 'lax-wp-editor';
419
+ import 'lax-wp-editor/styles';
420
+
421
+ function MyEditor() {
422
+ const config = {
423
+ ...defaultEditorConfig,
424
+ // Add your custom configuration
425
+ };
426
+
427
+ return (
428
+ <ToolbarProvider>
429
+ <Editor config={config} />
430
+ </ToolbarProvider>
431
+ );
432
+ }
433
+ ```
434
+
435
+ ### Different Toolbar Types
436
+
437
+ The editor supports three toolbar modes:
438
+
439
+ 1. **Professional** - Multi-row toolbar with all options visible
440
+ 2. **Classic** - Single-row compact toolbar with grouped controls
441
+ 3. **Hide Toolbar** - No toolbar (presentation mode)
442
+
443
+ ```tsx
444
+ import { Editor, ToolbarProvider, TOOLBAR_TYPES_ENUM } from 'lax-wp-editor';
445
+ import 'lax-wp-editor/styles';
446
+
447
+ function MyEditor() {
448
+ return (
449
+ <ToolbarProvider initialToolbar={TOOLBAR_TYPES_ENUM.CLASSIC}>
450
+ <Editor />
451
+ </ToolbarProvider>
452
+ );
453
+ }
454
+ ```
455
+
456
+ Users can switch between toolbar modes using the built-in toolbar dropdown menu, which includes icons for each mode:
457
+ - 📊 **Classic** - Compact view
458
+ - 🎛️ **Professional** - Full view
459
+ - 👁️ **Hide Toolbar** - Hidden view
460
+
461
+ ## Components
462
+
463
+ ### Main Components
464
+
465
+ - **`Editor`**: The main editor component
466
+ - **`ToolbarProvider`**: Context provider for toolbar state
467
+ - **`Toolbar`**: Main toolbar component with tabbed interface
468
+ - **`ProfessionalToolbar`**: Professional-style toolbar (multi-row layout)
469
+ - **`ClassicToolbar`**: Classic-style toolbar (single-row layout)
470
+ - **`ToolbarDropdown`**: Dropdown to switch between toolbar modes
471
+
472
+ ### Toolbar Tabs
473
+
474
+ The editor includes a tabbed toolbar interface with the following tabs:
475
+
476
+ - **`Home`**: Basic formatting options (bold, italic, underline, alignment, etc.)
477
+ - **`Insert`**: Insert elements (tables, images, dividers, etc.)
478
+ - **`Table`**: Table-specific operations (add/remove rows/columns, merge cells, etc.)
479
+ - **`Page`**: Page settings (size, orientation, margins, background)
480
+ - **`Export`**: Export content in multiple formats (Text, JSON, Markdown, HTML)
481
+
482
+ ### Individual Toolbar Components
483
+
484
+ - **`HeadingOptions`**: Heading selection dropdown
485
+ - **`HomeOptions`**: Basic formatting options
486
+ - **`FontStyleOptions`**: Font styling options
487
+ - **`ParagraphStyleOption`**: Paragraph styling
488
+ - **`ExportOptions`**: Export functionality for multiple file formats
489
+ - **`TableOptions`**: Table manipulation controls
490
+ - **`InsertOptions`**: Insert various elements into the document
491
+
492
+ ### Utility Components
493
+
494
+ - **`SvgIcon`**: SVG icon component
495
+ - **`PageSizeSelector`**: Page size and orientation selector
496
+ - **`Button`**: Base button component
497
+ - **`ColorPicker`**: Color picker for text and background colors
498
+
499
+ ## Hooks
500
+
501
+ - **`useTiptapEditorState`**: Access editor state
502
+ - **`useHeadingStyleMethods`**: Heading manipulation methods
503
+ - **`useFontStyleMethods`**: Font styling methods
504
+ - **`useHomeOptionMethods`**: Basic formatting methods
505
+ - **`useParagraphStyleMethods`**: Paragraph styling methods
506
+ - **`usePageMethods`**: Page size and layout management
507
+ - **`useExport`**: Export content in multiple formats (Text, JSON, Markdown, HTML)
508
+ - **`useTableMethods`**: Table manipulation methods
509
+ - **`useLinks`**: Link management methods
510
+ - **`usePresentationMode`**: Presentation mode controls
511
+ - **`useZoom`**: Zoom controls for the editor
512
+
513
+ ## Configuration
514
+
515
+ ### Editor Configuration
516
+
517
+ ```tsx
518
+ import { EditorConfig } from 'lax-wp-editor';
519
+
520
+ const config: EditorConfig = {
521
+ // Your configuration options
522
+ };
523
+ ```
524
+
525
+ ### Toolbar Types
526
+
527
+ ```tsx
528
+ import { TOOLBAR_TYPES_ENUM } from 'lax-wp-editor';
529
+
530
+ // Available toolbar types:
531
+ TOOLBAR_TYPES_ENUM.PROFESSIONAL // Professional toolbar (multi-row, all options visible)
532
+ TOOLBAR_TYPES_ENUM.CLASSIC // Classic toolbar (single-row, compact)
533
+ TOOLBAR_TYPES_ENUM.HIDE_TOOLBAR // Hide toolbar completely
534
+ ```
535
+
536
+ The toolbar includes 5 tabs:
537
+ - **Home**: Text formatting, alignment, lists, etc.
538
+ - **Insert**: Tables, images, dividers, and other insertable elements
539
+ - **Table**: Table-specific operations (add/remove rows/columns, merge cells)
540
+ - **Page**: Page layout settings (size, orientation, margins, background)
541
+ - **Export**: Download content in various formats (Text, JSON, Markdown, HTML)
542
+
543
+ ## Styling
544
+
545
+ The package includes default styles that you can import:
546
+
547
+ ```tsx
548
+ import 'lax-wp-editor/styles';
549
+ ```
550
+
551
+ You can also customize the styles by overriding CSS variables or using your own CSS.
552
+
553
+ ## TypeScript Support
554
+
555
+ The package includes full TypeScript definitions:
556
+
557
+ ```tsx
558
+ import { Editor, EditorConfig, PageSize } from 'lax-wp-editor';
559
+ ```
560
+
561
+ ## API Reference
562
+
563
+ ### Editor Props
564
+
565
+ | Prop | Type | Default | Description |
566
+ |------|------|---------|-------------|
567
+ | `config` | `EditorConfig` | `defaultEditorConfig` | Editor configuration |
568
+ | `onUpdate` | `(content: string) => void` | - | Callback when content changes |
569
+ | `initialContent` | `string` | - | Initial editor content |
570
+
571
+ ### ToolbarProvider Props
572
+
573
+ | Prop | Type | Default | Description |
574
+ |------|------|---------|-------------|
575
+ | `initialToolbar` | `ToolbarType` | `PROFESSIONAL` | Initial toolbar type |
576
+ | `children` | `ReactNode` | - | Child components |
577
+
578
+ ### ToolbarDropdown Props
579
+
580
+ | Prop | Type | Default | Description |
581
+ |------|------|---------|-------------|
582
+ | `onToolbarChange` | `(toolbarType: string) => void` | - | Callback when toolbar type changes |
583
+
584
+ ### useExport Hook
585
+
586
+ Returns an object with the following methods:
587
+
588
+ | Method | Description |
589
+ |--------|-------------|
590
+ | `downloadTextFile()` | Downloads content as plain text (.txt) |
591
+ | `downloadJsonFile()` | Downloads content as TipTap JSON format (.json) |
592
+ | `downloadMarkdownFile()` | Downloads content as Markdown (.md) |
593
+ | `downloadHtmlFile()` | Downloads content as HTML (.html) |
594
+
595
+ ## Examples
596
+
597
+ ### Custom Toolbar
598
+
599
+ ```tsx
600
+ import { Editor, Toolbar, HeadingOptions, HomeOptions } from 'lax-wp-editor';
601
+
602
+ function CustomEditor() {
603
+ return (
604
+ <div>
605
+ <Toolbar>
606
+ <HeadingOptions />
607
+ <HomeOptions />
608
+ </Toolbar>
609
+ <Editor />
610
+ </div>
611
+ );
612
+ }
613
+ ```
614
+
615
+ ### Page Size Management
616
+
617
+ ```tsx
618
+ import { Editor, PageSizeSelector, usePageMethods } from 'lax-wp-editor';
619
+
620
+ function EditorWithPageSize() {
621
+ const { pageSize, setPageSize } = usePageMethods();
622
+
623
+ return (
624
+ <div>
625
+ <PageSizeSelector />
626
+ <Editor />
627
+ </div>
628
+ );
629
+ }
630
+ ```
631
+
632
+ ### Export Functionality
633
+
634
+ ```tsx
635
+ import { Editor, useExport } from 'lax-wp-editor';
636
+
637
+ function EditorWithExport() {
638
+ const editorRef = useRef(null);
639
+ const {
640
+ downloadTextFile,
641
+ downloadJsonFile,
642
+ downloadMarkdownFile,
643
+ downloadHtmlFile
644
+ } = useExport(editorRef.current);
645
+
646
+ return (
647
+ <div>
648
+ <div className="export-buttons">
649
+ <button onClick={downloadTextFile}>Download as Text</button>
650
+ <button onClick={downloadJsonFile}>Download as JSON</button>
651
+ <button onClick={downloadMarkdownFile}>Download as Markdown</button>
652
+ <button onClick={downloadHtmlFile}>Download as HTML</button>
653
+ </div>
654
+ <Editor ref={editorRef} />
655
+ </div>
656
+ );
657
+ }
658
+ ```
659
+
660
+ ### Switching Toolbar Modes
661
+
662
+ ```tsx
663
+ import { Editor, ToolbarProvider, ToolbarDropdown } from 'lax-wp-editor';
664
+
665
+ function EditorWithToolbarSwitch() {
666
+ return (
667
+ <ToolbarProvider>
668
+ <ToolbarDropdown onToolbarChange={(type) => console.log('Toolbar changed to:', type)} />
669
+ <Editor />
670
+ </ToolbarProvider>
671
+ );
672
+ }
673
+ ```
674
+
675
+ ## Development
676
+
677
+ ### Building the Package
678
+
679
+ ```bash
680
+ npm run build
681
+ ```
682
+
683
+ ### Linting
684
+
685
+ ```bash
686
+ npm run lint
687
+ ```
688
+
689
+ ## Keywords
690
+
691
+ `wysiwyg`, `editor`, `react`, `tiptap`, `wordpress`, `rich-text`, `text-editor`, `markdown`, `html-editor`, `document-editor`, `export`, `typescript`
692
+
693
+ ## Contributing
694
+
695
+ Contributions are welcome! Here's how you can help:
696
+
697
+ 1. Fork the repository
698
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
699
+ 3. Commit your changes (`git commit -m 'Add some amazing feature'`)
700
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
701
+ 5. Open a Pull Request
702
+
703
+ Please make sure to:
704
+ - Follow the existing code style
705
+ - Add tests for new features
706
+ - Update documentation as needed
707
+ - Test your changes thoroughly
708
+
709
+ ## License
710
+
711
+ MIT © Rifat Hasan Shaun
712
+
713
+ ## Author
714
+
715
+ **Rifat Hasan Shaun**
716
+ - Email: mdrifathasanshaun@gmail.com
717
+ - GitHub: [@rifat-shaun](https://github.com/rifat-shaun)
718
+
719
+ ## Support
720
+
721
+ If you have any questions or need help, please:
722
+ - Open an issue on [GitHub](https://github.com/rifat-shaun/wp-editor/issues)
723
+ - Check the [documentation](https://github.com/rifat-shaun/wp-editor#readme)
724
+ - Review the examples in this README