@tarviks/lexical-rich-editor 1.0.1 → 1.0.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vikram Singh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,198 +1,198 @@
1
- # lexical-rich-editor
2
-
3
- A production-ready, feature-rich **rich text editor** built on Meta's [Lexical](https://lexical.dev) framework with a Fluent UI toolbar. Supports AI autocomplete, spell/grammar check, tables, images, YouTube embeds, code blocks, and more.
4
-
5
- ## Install
6
-
7
- ```bash
8
- yarn add lexical-rich-editor
9
- # or
10
- npm install lexical-rich-editor
11
- ```
12
-
13
- ### Peer dependencies
14
-
15
- ```bash
16
- yarn add lexical \
17
- @lexical/react @lexical/code @lexical/link @lexical/list \
18
- @lexical/rich-text @lexical/table @lexical/utils @lexical/selection @lexical/html \
19
- @fluentui/react @fluentui/react-components @fluentui/react-icons \
20
- react react-dom
21
- ```
22
-
23
- ## Quick start
24
-
25
- ```tsx
26
- import { useRef, useState } from 'react';
27
- import {
28
- ContentEditorComponent,
29
- ContentEditorLevel,
30
- ContentEditorRef,
31
- } from 'lexical-rich-editor';
32
-
33
- function MyEditor() {
34
- const [value, setValue] = useState('');
35
- const editorRef = useRef<ContentEditorRef>(null);
36
-
37
- return (
38
- <div style={{ height: 400 }}>
39
- <ContentEditorComponent
40
- ref={editorRef}
41
- namespace="my-editor"
42
- value={value}
43
- onChange={setValue}
44
- level={ContentEditorLevel.Pro}
45
- placeholder="Start typing…"
46
- showFloatingToolbar
47
- />
48
- </div>
49
- );
50
- }
51
- ```
52
-
53
- ## Editor levels
54
-
55
- | Level | Toolbar features |
56
- |---|---|
57
- | `ContentEditorLevel.None` | No toolbar — plain editable area |
58
- | `ContentEditorLevel.Basic` | Bold, italic, underline, lists, links |
59
- | `ContentEditorLevel.Standard` | Basic + tables |
60
- | `ContentEditorLevel.Pro` | Full — images, YouTube, fonts, colors, code, page breaks |
61
-
62
- ## AI Autocomplete
63
-
64
- Pass any async function that returns suggestions — the editor handles debounce, ghost text, and cancellation:
65
-
66
- ```tsx
67
- <ContentEditorComponent
68
- suggestFn={async (text, cursorIndex) => {
69
- const res = await fetch('/api/suggest', {
70
- method: 'POST',
71
- body: JSON.stringify({ text, cursorIndex }),
72
- });
73
- return res.json();
74
- // Supported shapes: string[] | { generated_text: string } | { suggestions: string[] }
75
- }}
76
- onSuggestionAccept={({ suggestionText, triggerText, method }) => {
77
- // method: 'tab' | 'enter' | 'click'
78
- sendRewardSignal({ suggestionText, triggerText });
79
- }}
80
- suggestIdleMs={300} // debounce delay (default 300ms)
81
- />
82
- ```
83
-
84
- ## Spell & Grammar check
85
-
86
- ```tsx
87
- <ContentEditorComponent
88
- spellCheckFn={async (text) => {
89
- const res = await fetch('/api/spellcheck', {
90
- method: 'POST',
91
- body: JSON.stringify({ text }),
92
- });
93
- return res.json();
94
- // Supported shapes:
95
- // { misspelled_words: string[], suggestions: Record<string, string[]>, grammar_correction?: string }
96
- // { misspelled: string[], suggestions: Record<string, string[]>, improved_text?: string }
97
- // SpellCheckIssue[]
98
- }}
99
- onSpellCheckAccept={({ original, replacement, type }) => {
100
- // type: 'spelling' | 'grammar' | 'style'
101
- }}
102
- spellCheckIdleMs={1200} // debounce delay (default 1200ms)
103
- spellCheckEnabled={true}
104
- />
105
- ```
106
-
107
- ## Ref API
108
-
109
- ```tsx
110
- const editorRef = useRef<ContentEditorRef>(null);
111
-
112
- // Get current HTML string
113
- const html = editorRef.current?.getValue();
114
-
115
- // Set content from HTML
116
- editorRef.current?.setValue('<p>Hello <strong>world</strong></p>');
117
-
118
- // Clear the editor
119
- editorRef.current?.clear();
120
-
121
- // Focus / blur
122
- editorRef.current?.focus();
123
- editorRef.current?.blur();
124
-
125
- // Check state
126
- const empty = editorRef.current?.isEmpty();
127
- const focused = editorRef.current?.isFocused();
128
-
129
- // Insert / update a named block (e.g. email signature)
130
- editorRef.current?.upsertBlock({
131
- kind: 'signature',
132
- html: '<p>Best regards,<br/>John Doe</p>',
133
- position: 'end',
134
- });
135
-
136
- // Remove a block
137
- editorRef.current?.removeBlock('signature');
138
-
139
- // Check if a block exists
140
- const has = editorRef.current?.hasBlock('signature');
141
-
142
- // Raw Lexical editor (advanced)
143
- const lexicalEditor = editorRef.current?.getEditor();
144
- ```
145
-
146
- ## Props
147
-
148
- | Prop | Type | Default | Description |
149
- |---|---|---|---|
150
- | `value` | `string` | required | Controlled HTML value |
151
- | `onChange` | `(html: string) => void` | required | Change handler |
152
- | `namespace` | `string` | `undefined` | Lexical namespace |
153
- | `level` | `ContentEditorLevel` | `Basic` | Toolbar feature level |
154
- | `readOnly` | `boolean` | `false` | Non-interactive mode |
155
- | `placeholder` | `string` | `undefined` | Placeholder text |
156
- | `width` | `string` | `'100%'` | Container width |
157
- | `height` | `string` | `'100%'` | Container height |
158
- | `margin` | `string\|number` | `'5px auto'` | Container margin |
159
- | `autoFocus` | `boolean` | `false` | Focus on mount |
160
- | `showFloatingToolbar` | `boolean` | `false` | Floating format bar on selection |
161
- | `wordLimit` | `number` | `undefined` | Max word count (shows counter) |
162
- | `onWordLimitExceeded` | `fn` | `undefined` | Fires when limit is crossed |
163
- | `suggestFn` | `async fn` | `undefined` | Simple autocomplete API |
164
- | `useQuery` | `fn` | `undefined` | Advanced autocomplete with cancellation |
165
- | `suggestIdleMs` | `number` | `300` | Autocomplete debounce (ms) |
166
- | `spellCheckFn` | `async fn` | `undefined` | Simple spell check API |
167
- | `useSpellCheck` | `fn` | `undefined` | Advanced spell check with cancellation |
168
- | `spellCheckIdleMs` | `number` | `1200` | Spell check debounce (ms) |
169
- | `spellCheckEnabled` | `boolean` | `true` | Toggle spell check without unmounting |
170
- | `onSuggestionAccept` | `fn` | `undefined` | Fires on autocomplete accept |
171
- | `onSuggestionShown` | `fn` | `undefined` | Fires when suggestion is shown |
172
- | `onSpellCheckAccept` | `fn` | `undefined` | Fires on spell check accept |
173
- | `onFocus` | `fn` | `undefined` | Focus event |
174
- | `onBlur` | `fn` | `undefined` | Blur event |
175
-
176
- ## Development
177
-
178
- ```bash
179
- # Clone
180
- git clone https://github.com/capsitech/lexical-rich-editor
181
-
182
- # Install root deps (for building)
183
- yarn install
184
-
185
- # Run example app
186
- cd example && yarn install && yarn dev
187
- ```
188
-
189
- ## Build & publish
190
-
191
- ```bash
192
- yarn build # outputs to dist/
193
- npm publish # publishes to npm
194
- ```
195
-
196
- ## License
197
-
198
- MIT
1
+ # lexical-rich-editor
2
+
3
+ A production-ready, feature-rich **rich text editor** built on Meta's [Lexical](https://lexical.dev) framework with a Fluent UI toolbar. Supports AI autocomplete, spell/grammar check, tables, images, YouTube embeds, code blocks, and more.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ yarn add lexical-rich-editor
9
+ # or
10
+ npm install lexical-rich-editor
11
+ ```
12
+
13
+ ### Peer dependencies
14
+
15
+ ```bash
16
+ yarn add lexical \
17
+ @lexical/react @lexical/code @lexical/link @lexical/list \
18
+ @lexical/rich-text @lexical/table @lexical/utils @lexical/selection @lexical/html \
19
+ @fluentui/react @fluentui/react-components @fluentui/react-icons \
20
+ react react-dom
21
+ ```
22
+
23
+ ## Quick start
24
+
25
+ ```tsx
26
+ import { useRef, useState } from 'react';
27
+ import {
28
+ ContentEditorComponent,
29
+ ContentEditorLevel,
30
+ ContentEditorRef,
31
+ } from 'lexical-rich-editor';
32
+
33
+ function MyEditor() {
34
+ const [value, setValue] = useState('');
35
+ const editorRef = useRef<ContentEditorRef>(null);
36
+
37
+ return (
38
+ <div style={{ height: 400 }}>
39
+ <ContentEditorComponent
40
+ ref={editorRef}
41
+ namespace="my-editor"
42
+ value={value}
43
+ onChange={setValue}
44
+ level={ContentEditorLevel.Pro}
45
+ placeholder="Start typing…"
46
+ showFloatingToolbar
47
+ />
48
+ </div>
49
+ );
50
+ }
51
+ ```
52
+
53
+ ## Editor levels
54
+
55
+ | Level | Toolbar features |
56
+ |---|---|
57
+ | `ContentEditorLevel.None` | No toolbar — plain editable area |
58
+ | `ContentEditorLevel.Basic` | Bold, italic, underline, lists, links |
59
+ | `ContentEditorLevel.Standard` | Basic + tables |
60
+ | `ContentEditorLevel.Pro` | Full — images, YouTube, fonts, colors, code, page breaks |
61
+
62
+ ## AI Autocomplete
63
+
64
+ Pass any async function that returns suggestions — the editor handles debounce, ghost text, and cancellation:
65
+
66
+ ```tsx
67
+ <ContentEditorComponent
68
+ suggestFn={async (text, cursorIndex) => {
69
+ const res = await fetch('/api/suggest', {
70
+ method: 'POST',
71
+ body: JSON.stringify({ text, cursorIndex }),
72
+ });
73
+ return res.json();
74
+ // Supported shapes: string[] | { generated_text: string } | { suggestions: string[] }
75
+ }}
76
+ onSuggestionAccept={({ suggestionText, triggerText, method }) => {
77
+ // method: 'tab' | 'enter' | 'click'
78
+ sendRewardSignal({ suggestionText, triggerText });
79
+ }}
80
+ suggestIdleMs={300} // debounce delay (default 300ms)
81
+ />
82
+ ```
83
+
84
+ ## Spell & Grammar check
85
+
86
+ ```tsx
87
+ <ContentEditorComponent
88
+ spellCheckFn={async (text) => {
89
+ const res = await fetch('/api/spellcheck', {
90
+ method: 'POST',
91
+ body: JSON.stringify({ text }),
92
+ });
93
+ return res.json();
94
+ // Supported shapes:
95
+ // { misspelled_words: string[], suggestions: Record<string, string[]>, grammar_correction?: string }
96
+ // { misspelled: string[], suggestions: Record<string, string[]>, improved_text?: string }
97
+ // SpellCheckIssue[]
98
+ }}
99
+ onSpellCheckAccept={({ original, replacement, type }) => {
100
+ // type: 'spelling' | 'grammar' | 'style'
101
+ }}
102
+ spellCheckIdleMs={1200} // debounce delay (default 1200ms)
103
+ spellCheckEnabled={true}
104
+ />
105
+ ```
106
+
107
+ ## Ref API
108
+
109
+ ```tsx
110
+ const editorRef = useRef<ContentEditorRef>(null);
111
+
112
+ // Get current HTML string
113
+ const html = editorRef.current?.getValue();
114
+
115
+ // Set content from HTML
116
+ editorRef.current?.setValue('<p>Hello <strong>world</strong></p>');
117
+
118
+ // Clear the editor
119
+ editorRef.current?.clear();
120
+
121
+ // Focus / blur
122
+ editorRef.current?.focus();
123
+ editorRef.current?.blur();
124
+
125
+ // Check state
126
+ const empty = editorRef.current?.isEmpty();
127
+ const focused = editorRef.current?.isFocused();
128
+
129
+ // Insert / update a named block (e.g. email signature)
130
+ editorRef.current?.upsertBlock({
131
+ kind: 'signature',
132
+ html: '<p>Best regards,<br/>John Doe</p>',
133
+ position: 'end',
134
+ });
135
+
136
+ // Remove a block
137
+ editorRef.current?.removeBlock('signature');
138
+
139
+ // Check if a block exists
140
+ const has = editorRef.current?.hasBlock('signature');
141
+
142
+ // Raw Lexical editor (advanced)
143
+ const lexicalEditor = editorRef.current?.getEditor();
144
+ ```
145
+
146
+ ## Props
147
+
148
+ | Prop | Type | Default | Description |
149
+ |---|---|---|---|
150
+ | `value` | `string` | required | Controlled HTML value |
151
+ | `onChange` | `(html: string) => void` | required | Change handler |
152
+ | `namespace` | `string` | `undefined` | Lexical namespace |
153
+ | `level` | `ContentEditorLevel` | `Basic` | Toolbar feature level |
154
+ | `readOnly` | `boolean` | `false` | Non-interactive mode |
155
+ | `placeholder` | `string` | `undefined` | Placeholder text |
156
+ | `width` | `string` | `'100%'` | Container width |
157
+ | `height` | `string` | `'100%'` | Container height |
158
+ | `margin` | `string\|number` | `'5px auto'` | Container margin |
159
+ | `autoFocus` | `boolean` | `false` | Focus on mount |
160
+ | `showFloatingToolbar` | `boolean` | `false` | Floating format bar on selection |
161
+ | `wordLimit` | `number` | `undefined` | Max word count (shows counter) |
162
+ | `onWordLimitExceeded` | `fn` | `undefined` | Fires when limit is crossed |
163
+ | `suggestFn` | `async fn` | `undefined` | Simple autocomplete API |
164
+ | `useQuery` | `fn` | `undefined` | Advanced autocomplete with cancellation |
165
+ | `suggestIdleMs` | `number` | `300` | Autocomplete debounce (ms) |
166
+ | `spellCheckFn` | `async fn` | `undefined` | Simple spell check API |
167
+ | `useSpellCheck` | `fn` | `undefined` | Advanced spell check with cancellation |
168
+ | `spellCheckIdleMs` | `number` | `1200` | Spell check debounce (ms) |
169
+ | `spellCheckEnabled` | `boolean` | `true` | Toggle spell check without unmounting |
170
+ | `onSuggestionAccept` | `fn` | `undefined` | Fires on autocomplete accept |
171
+ | `onSuggestionShown` | `fn` | `undefined` | Fires when suggestion is shown |
172
+ | `onSpellCheckAccept` | `fn` | `undefined` | Fires on spell check accept |
173
+ | `onFocus` | `fn` | `undefined` | Focus event |
174
+ | `onBlur` | `fn` | `undefined` | Blur event |
175
+
176
+ ## Development
177
+
178
+ ```bash
179
+ # Clone
180
+ git clone https://github.com/capsitech/lexical-rich-editor
181
+
182
+ # Install root deps (for building)
183
+ yarn install
184
+
185
+ # Run example app
186
+ cd example && yarn install && yarn dev
187
+ ```
188
+
189
+ ## Build & publish
190
+
191
+ ```bash
192
+ yarn build # outputs to dist/
193
+ npm publish # publishes to npm
194
+ ```
195
+
196
+ ## License
197
+
198
+ MIT