@lexical/react 0.1.15 → 0.1.18

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 (87) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +5 -729
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -19
  3. package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +1 -1
  4. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  5. package/DEPRECATED_useLexicalCharacterLimit.dev.js +9 -10
  6. package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -7
  7. package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
  10. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  11. package/DEPRECATED_useLexicalHistory.dev.js +5 -307
  12. package/DEPRECATED_useLexicalHistory.prod.js +1 -7
  13. package/DEPRECATED_useLexicalList.dev.js +29 -25
  14. package/DEPRECATED_useLexicalList.prod.js +3 -1
  15. package/DEPRECATED_useLexicalPlainText.dev.js +8 -662
  16. package/DEPRECATED_useLexicalPlainText.prod.js +2 -14
  17. package/DEPRECATED_useLexicalRichText.dev.js +8 -747
  18. package/DEPRECATED_useLexicalRichText.prod.js +2 -17
  19. package/LICENSE +1 -1
  20. package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
  21. package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
  22. package/LexicalAutoFocusPlugin.js +9 -0
  23. package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
  24. package/LexicalAutoFocusPlugin.prod.js +7 -0
  25. package/LexicalAutoLinkPlugin.dev.js +12 -15
  26. package/LexicalAutoLinkPlugin.prod.js +6 -6
  27. package/LexicalAutoScrollPlugin.d.ts +13 -0
  28. package/LexicalAutoScrollPlugin.dev.js +82 -0
  29. package/LexicalAutoScrollPlugin.js +9 -0
  30. package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
  31. package/LexicalAutoScrollPlugin.prod.js +8 -0
  32. package/LexicalCharacterLimitPlugin.dev.js +9 -10
  33. package/LexicalCharacterLimitPlugin.prod.js +7 -7
  34. package/LexicalClearEditorPlugin.dev.js +15 -19
  35. package/LexicalClearEditorPlugin.prod.js +1 -1
  36. package/LexicalCollaborationPlugin.d.ts +6 -3
  37. package/LexicalCollaborationPlugin.dev.js +30 -41
  38. package/LexicalCollaborationPlugin.js.flow +7 -4
  39. package/LexicalCollaborationPlugin.prod.js +10 -9
  40. package/LexicalComposer.d.ts +2 -2
  41. package/LexicalComposer.dev.js +3 -19
  42. package/LexicalComposer.js.flow +2 -2
  43. package/LexicalComposer.prod.js +2 -3
  44. package/LexicalContentEditable.dev.js +3 -1
  45. package/LexicalContentEditable.prod.js +2 -2
  46. package/LexicalHashtagPlugin.dev.js +20 -94
  47. package/LexicalHashtagPlugin.prod.js +4 -7
  48. package/LexicalHistoryPlugin.dev.js +5 -307
  49. package/LexicalHistoryPlugin.prod.js +1 -7
  50. package/LexicalHorizontalRuleNode.d.ts +3 -1
  51. package/LexicalHorizontalRuleNode.dev.js +2 -0
  52. package/LexicalHorizontalRuleNode.js.flow +6 -2
  53. package/LexicalHorizontalRuleNode.prod.js +2 -2
  54. package/LexicalLinkPlugin.dev.js +19 -20
  55. package/LexicalLinkPlugin.prod.js +4 -3
  56. package/LexicalListPlugin.dev.js +29 -25
  57. package/LexicalListPlugin.prod.js +3 -2
  58. package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
  59. package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
  60. package/LexicalMarkdownShortcutPlugin.js +9 -0
  61. package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
  62. package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
  63. package/LexicalNestedComposer.dev.js +20 -15
  64. package/LexicalNestedComposer.prod.js +3 -3
  65. package/LexicalOnChangePlugin.dev.js +1 -1
  66. package/LexicalOnChangePlugin.prod.js +1 -1
  67. package/LexicalPlainTextPlugin.dev.js +6 -359
  68. package/LexicalPlainTextPlugin.prod.js +4 -11
  69. package/LexicalRichTextPlugin.dev.js +6 -444
  70. package/LexicalRichTextPlugin.prod.js +4 -12
  71. package/LexicalTablePlugin.dev.js +27 -30
  72. package/LexicalTablePlugin.prod.js +3 -3
  73. package/LexicalTreeView.dev.js +1 -1
  74. package/LexicalTreeView.prod.js +1 -1
  75. package/package.json +17 -13
  76. package/useLexicalIsTextContentEmpty.dev.js +1 -1
  77. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  78. package/useLexicalNodeSelection.dev.js +1 -1
  79. package/useLexicalNodeSelection.prod.js +1 -1
  80. package/useLexicalTextEntity.d.ts +19 -0
  81. package/useLexicalTextEntity.dev.js +29 -0
  82. package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
  83. package/useLexicalTextEntity.js.flow +18 -0
  84. package/useLexicalTextEntity.prod.js +7 -0
  85. package/LexicalAutoFormatterPlugin.dev.js +0 -766
  86. package/LexicalAutoFormatterPlugin.js +0 -9
  87. package/LexicalAutoFormatterPlugin.prod.js +0 -25
@@ -7,7 +7,4 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- type UnsubscribeFn = () => void;
11
- declare export default function withSubscriptions(
12
- ...unsubscribe: Array<UnsubscribeFn>
13
- ): () => void;
10
+ declare export default function LexicalMarkdownShortcutPlugin(): React$Node;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ var b=require("@lexical/react/LexicalComposerContext"),c=require("@lexical/markdown"),d=require("@lexical/react/LexicalHorizontalRuleNode"),e=require("react");function f(a){e.useEffect(()=>c.registerMarkdownShortcuts(a,d.$createHorizontalRuleNode),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();f(a);return null};
@@ -6,9 +6,9 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var LexicalComposer = require('@lexical/react/LexicalComposer');
10
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
11
10
  var LexicalOnChangePlugin = require('@lexical/react/LexicalOnChangePlugin');
11
+ var lexical = require('lexical');
12
12
  var React = require('react');
13
13
 
14
14
  /**
@@ -33,8 +33,7 @@ function LexicalNestedComposer({
33
33
 
34
34
  const [nestedEditor, setNestedEditor] = React.useState(null);
35
35
  const {
36
- decoratorEditor,
37
- theme
36
+ decoratorEditor
38
37
  } = initialConfig;
39
38
  React.useEffect(() => {
40
39
  if (!decoratorEditor.isEmpty() && nestedEditor !== null) {
@@ -42,6 +41,22 @@ function LexicalNestedComposer({
42
41
  } // eslint-disable-next-line react-hooks/exhaustive-deps
43
42
 
44
43
  }, [nestedEditor]);
44
+ const composerContext = React.useMemo(() => {
45
+ const [parentEditor, parentContextContext] = parentContext;
46
+ const composerTheme = initialConfig.theme || parentContextContext.getTheme() || undefined;
47
+ const context = LexicalComposerContext.createLexicalComposerContext(parentContext, composerTheme);
48
+ const editor = lexical.createEditor({
49
+ context,
50
+ namespace: parentEditor._config.namespace,
51
+ nodes: Array.from(parentEditor._nodes.values()).map(registeredNode => registeredNode.klass),
52
+ onError: parentEditor._onError,
53
+ parentEditor,
54
+ theme: composerTheme
55
+ });
56
+ return [editor, context];
57
+ }, // We only do this for init
58
+ // eslint-disable-next-line react-hooks/exhaustive-deps
59
+ []);
45
60
  const onChange = React.useCallback((editorState, nextNestedEditor) => {
46
61
  if (!editorState.isEmpty()) {
47
62
  decoratorEditor.set(nextNestedEditor);
@@ -50,18 +65,8 @@ function LexicalNestedComposer({
50
65
  }
51
66
  }, // eslint-disable-next-line react-hooks/exhaustive-deps
52
67
  []);
53
- return /*#__PURE__*/React.createElement(LexicalComposer, {
54
- initialConfig: React.useMemo(() => {
55
- const [parentEditor] = parentContext;
56
- return {
57
- editor: decoratorEditor.editor,
58
- namespace: parentEditor._config.namespace,
59
- nodes: Array.from(parentEditor._nodes.values()).map(registeredNode => registeredNode.klass),
60
- onError: parentEditor._onError,
61
- theme
62
- }; // We only do this for init
63
- // eslint-disable-next-line react-hooks/exhaustive-deps
64
- }, [])
68
+ return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
69
+ value: composerContext
65
70
  }, /*#__PURE__*/React.createElement(LexicalOnChangePlugin, {
66
71
  onChange: onChange
67
72
  }), children);
@@ -4,6 +4,6 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var a=require("@lexical/react/LexicalComposer"),h=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/react/LexicalOnChangePlugin"),l=require("react");
8
- module.exports=function({initialConfig:e={},children:m}){const g=l.useContext(h.LexicalComposerContext);if(null==g)throw Error("Unexpected parent context null on a nested composer");const [f,n]=l.useState(null),{decoratorEditor:c,theme:p}=e;l.useEffect(()=>{c.isEmpty()||null===f||c.init(f)},[f]);e=l.useCallback((b,d)=>{b.isEmpty()?n(d):c.set(d)},[]);return l.createElement(a,{initialConfig:l.useMemo(()=>{const [b]=g;return{editor:c.editor,namespace:b._config.namespace,nodes:Array.from(b._nodes.values()).map(d=>
9
- d.klass),onError:b._onError,theme:p}},[])},l.createElement(k,{onChange:e}),m)};
7
+ var a=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/LexicalOnChangePlugin"),m=require("lexical"),n=require("react");
8
+ module.exports=function({initialConfig:h={},children:p}){const e=n.useContext(a.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #72; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const [f,q]=n.useState(null),{decoratorEditor:g}=h;n.useEffect(()=>{g.isEmpty()||null===f||g.init(f)},[f]);const t=n.useMemo(()=>{const [b,c]=e,k=h.theme||c.getTheme()||void 0,l=a.createLexicalComposerContext(e,k);return[m.createEditor({context:l,
9
+ namespace:b._config.namespace,nodes:Array.from(b._nodes.values()).map(r=>r.klass),onError:b._onError,parentEditor:b,theme:k}),l]},[]),u=n.useCallback((b,c)=>{b.isEmpty()?q(c):g.set(c)},[]);return n.createElement(a.LexicalComposerContext.Provider,{value:t},n.createElement(d,{onChange:u}),p)};
@@ -46,7 +46,7 @@ function OnChangePlugin({
46
46
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
47
47
  useLayoutEffect(() => {
48
48
  if (onChange) {
49
- return editor.addListener('update', ({
49
+ return editor.registerUpdateListener(({
50
50
  editorState,
51
51
  dirtyElements,
52
52
  dirtyLeaves,
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var c=require("@lexical/react/LexicalComposerContext"),f=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
8
- module.exports=function({ignoreInitialChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){const [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.addListener("update",({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m})=>{e&&0===k.size&&0===l.size||d&&m.isEmpty()||a(h,b)})},[b,d,e,a]);return null};
8
+ module.exports=function({ignoreInitialChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){const [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.registerUpdateListener(({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m})=>{e&&0===k.size&&0===l.size||d&&m.isEmpty()||a(h,b)})},[b,d,e,a]);return null};
@@ -10,9 +10,9 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
10
  var React = require('react');
11
11
  var text = require('@lexical/text');
12
12
  var reactDom = require('react-dom');
13
- var clipboard = require('@lexical/clipboard');
14
- var selection = require('@lexical/selection');
15
- var lexical = require('lexical');
13
+ var dragon = require('@lexical/dragon');
14
+ var plainText = require('@lexical/plain-text');
15
+ var utils = require('@lexical/utils');
16
16
 
17
17
  /**
18
18
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -46,7 +46,7 @@ var useLayoutEffect = useLayoutEffectImpl;
46
46
  function useLexicalCanShowPlaceholder(editor) {
47
47
  const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
48
48
  useLayoutEffect(() => {
49
- return editor.addListener('update', ({
49
+ return editor.registerUpdateListener(({
50
50
  editorState
51
51
  }) => {
52
52
  const isComposing = editor.isComposing();
@@ -69,7 +69,7 @@ function useDecorators(editor) {
69
69
  const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
70
70
 
71
71
  useLayoutEffect(() => {
72
- return editor.addListener('decorator', nextDecorators => {
72
+ return editor.registerDecoratorListener(nextDecorators => {
73
73
  reactDom.flushSync(() => {
74
74
  setDecorators(nextDecorators);
75
75
  });
@@ -94,199 +94,6 @@ function useDecorators(editor) {
94
94
  }, [decorators, editor]);
95
95
  }
96
96
 
97
- /**
98
- * Copyright (c) Meta Platforms, Inc. and affiliates.
99
- *
100
- * This source code is licensed under the MIT license found in the
101
- * LICENSE file in the root directory of this source tree.
102
- *
103
- *
104
- */
105
- function onPasteForPlainText(event, editor) {
106
- event.preventDefault();
107
- editor.update(() => {
108
- const selection = lexical.$getSelection();
109
- const clipboardData = event.clipboardData;
110
-
111
- if (clipboardData != null && lexical.$isRangeSelection(selection)) {
112
- clipboard.$insertDataTransferForPlainText(clipboardData, selection);
113
- }
114
- });
115
- }
116
- function onCutForPlainText(event, editor) {
117
- onCopyForPlainText(event, editor);
118
- editor.update(() => {
119
- const selection = lexical.$getSelection();
120
-
121
- if (lexical.$isRangeSelection(selection)) {
122
- selection.removeText();
123
- }
124
- });
125
- }
126
- function onCopyForPlainText(event, editor) {
127
- event.preventDefault();
128
- editor.update(() => {
129
- const clipboardData = event.clipboardData;
130
- const selection = lexical.$getSelection();
131
-
132
- if (selection !== null) {
133
- if (clipboardData != null) {
134
- const htmlString = clipboard.getHtmlContent(editor);
135
-
136
- if (htmlString !== null) {
137
- clipboardData.setData('text/html', htmlString);
138
- }
139
-
140
- clipboardData.setData('text/plain', selection.getTextContent());
141
- }
142
- }
143
- });
144
- }
145
-
146
- /**
147
- * Copyright (c) Meta Platforms, Inc. and affiliates.
148
- *
149
- * This source code is licensed under the MIT license found in the
150
- * LICENSE file in the root directory of this source tree.
151
- *
152
- *
153
- */
154
- // Convoluted logic to make this work with Flow. Order matters.
155
- const options = {
156
- tag: 'history-merge'
157
- };
158
- const setEditorOptions = options;
159
- const updateOptions = options;
160
- function initializeEditor(editor, initialEditorState) {
161
- if (initialEditorState === null) {
162
- return;
163
- } else if (initialEditorState === undefined) {
164
- editor.update(() => {
165
- const root = lexical.$getRoot();
166
- const firstChild = root.getFirstChild();
167
-
168
- if (firstChild === null) {
169
- const paragraph = lexical.$createParagraphNode();
170
- root.append(paragraph);
171
- const activeElement = document.activeElement;
172
-
173
- if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
174
- paragraph.select();
175
- }
176
- }
177
- }, updateOptions);
178
- } else if (initialEditorState !== null) {
179
- switch (typeof initialEditorState) {
180
- case 'string':
181
- {
182
- const parsedEditorState = editor.parseEditorState(initialEditorState);
183
- editor.setEditorState(parsedEditorState, setEditorOptions);
184
- break;
185
- }
186
-
187
- case 'object':
188
- {
189
- editor.setEditorState(initialEditorState, setEditorOptions);
190
- break;
191
- }
192
-
193
- case 'function':
194
- {
195
- editor.update(initialEditorState, updateOptions);
196
- break;
197
- }
198
- }
199
- }
200
- }
201
-
202
- /**
203
- * Copyright (c) Meta Platforms, Inc. and affiliates.
204
- *
205
- * This source code is licensed under the MIT license found in the
206
- * LICENSE file in the root directory of this source tree.
207
- *
208
- *
209
- */
210
- function useLexicalDragonSupport(editor) {
211
- React.useEffect(() => {
212
- const handler = event => {
213
- const rootElement = editor.getRootElement();
214
-
215
- if (document.activeElement !== rootElement) {
216
- return;
217
- }
218
-
219
- const data = event.data;
220
-
221
- if (typeof data === 'string') {
222
- let parsedData;
223
-
224
- try {
225
- parsedData = JSON.parse(data);
226
- } catch (e) {
227
- return;
228
- }
229
-
230
- if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
231
- const payload = parsedData.payload;
232
-
233
- if (payload && payload.functionId === 'makeChanges') {
234
- const args = payload.args;
235
-
236
- if (args) {
237
- const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
238
- editor.update(() => {
239
- const selection = lexical.$getSelection();
240
-
241
- if (lexical.$isRangeSelection(selection)) {
242
- const anchor = selection.anchor;
243
- let anchorNode = anchor.getNode();
244
- let setSelStart = 0;
245
- let setSelEnd = 0;
246
-
247
- if (lexical.$isTextNode(anchorNode)) {
248
- // set initial selection
249
- if (elementStart >= 0 && elementLength >= 0) {
250
- setSelStart = elementStart;
251
- setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
252
-
253
- selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
254
- }
255
- }
256
-
257
- if (setSelStart !== setSelEnd || text !== '') {
258
- selection.insertRawText(text);
259
- anchorNode = anchor.getNode();
260
- }
261
-
262
- if (lexical.$isTextNode(anchorNode)) {
263
- // set final selection
264
- setSelStart = selStart;
265
- setSelEnd = selStart + selLength;
266
- const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
267
-
268
- setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
269
- setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
270
- selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
271
- } // block the chrome extension from handling this event
272
-
273
-
274
- event.stopImmediatePropagation();
275
- }
276
- });
277
- }
278
- }
279
- }
280
- }
281
- };
282
-
283
- window.addEventListener('message', handler, true);
284
- return () => {
285
- window.removeEventListener('message', handler, true);
286
- };
287
- }, [editor]);
288
- }
289
-
290
97
  /**
291
98
  * Copyright (c) Meta Platforms, Inc. and affiliates.
292
99
  *
@@ -297,169 +104,9 @@ function useLexicalDragonSupport(editor) {
297
104
  */
298
105
  function usePlainTextSetup(editor, initialEditorState) {
299
106
  useLayoutEffect(() => {
300
- const removeListener = editor.addListener('command', (type, payload) => {
301
- const selection$1 = lexical.$getSelection();
302
-
303
- if (!lexical.$isRangeSelection(selection$1)) {
304
- return false;
305
- }
306
-
307
- switch (type) {
308
- case 'deleteCharacter':
309
- {
310
- const isBackward = payload;
311
- selection$1.deleteCharacter(isBackward);
312
- return true;
313
- }
314
-
315
- case 'deleteWord':
316
- {
317
- const isBackward = payload;
318
- selection$1.deleteWord(isBackward);
319
- return true;
320
- }
321
-
322
- case 'deleteLine':
323
- {
324
- const isBackward = payload;
325
- selection$1.deleteLine(isBackward);
326
- return true;
327
- }
328
-
329
- case 'insertText':
330
- {
331
- const eventOrText = payload;
332
-
333
- if (typeof eventOrText === 'string') {
334
- selection$1.insertText(eventOrText);
335
- } else {
336
- const dataTransfer = eventOrText.dataTransfer;
337
-
338
- if (dataTransfer != null) {
339
- clipboard.$insertDataTransferForPlainText(dataTransfer, selection$1);
340
- } else {
341
- const data = eventOrText.data;
342
-
343
- if (data) {
344
- selection$1.insertText(data);
345
- }
346
- }
347
- }
348
-
349
- return true;
350
- }
351
-
352
- case 'removeText':
353
- selection$1.removeText();
354
- return true;
355
-
356
- case 'insertLineBreak':
357
- const selectStart = payload;
358
- selection$1.insertLineBreak(selectStart);
359
- return true;
360
-
361
- case 'insertParagraph':
362
- selection$1.insertLineBreak();
363
- return true;
364
-
365
- case 'indentContent':
366
- case 'outdentContent':
367
- case 'insertHorizontalRule':
368
- case 'insertImage':
369
- case 'insertTable':
370
- case 'formatElement':
371
- case 'formatText':
372
- {
373
- return true;
374
- }
375
-
376
- case 'keyArrowLeft':
377
- {
378
- const event = payload;
379
- const isHoldingShift = event.shiftKey;
380
-
381
- if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
382
- event.preventDefault();
383
- selection.$moveCharacter(selection$1, isHoldingShift, true);
384
- return true;
385
- }
386
-
387
- return false;
388
- }
389
-
390
- case 'keyArrowRight':
391
- {
392
- const event = payload;
393
- const isHoldingShift = event.shiftKey;
394
-
395
- if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
396
- event.preventDefault();
397
- selection.$moveCharacter(selection$1, isHoldingShift, false);
398
- return true;
399
- }
400
-
401
- return false;
402
- }
403
-
404
- case 'keyBackspace':
405
- {
406
- const event = payload;
407
- event.preventDefault();
408
- return editor.execCommand('deleteCharacter', true);
409
- }
410
-
411
- case 'keyDelete':
412
- {
413
- const event = payload;
414
- event.preventDefault();
415
- return editor.execCommand('deleteCharacter', false);
416
- }
417
-
418
- case 'keyEnter':
419
- {
420
- const event = payload;
421
- event.preventDefault();
422
- return editor.execCommand('insertLineBreak');
423
- }
424
-
425
- case 'copy':
426
- {
427
- const event = payload;
428
- onCopyForPlainText(event, editor);
429
- return true;
430
- }
431
-
432
- case 'cut':
433
- {
434
- const event = payload;
435
- onCutForPlainText(event, editor);
436
- return true;
437
- }
438
-
439
- case 'paste':
440
- {
441
- const event = payload;
442
- onPasteForPlainText(event, editor);
443
- return true;
444
- }
445
-
446
- case 'drop':
447
- case 'dragstart':
448
- {
449
- // TODO: Make drag and drop work at some point.
450
- const event = payload;
451
- event.preventDefault();
452
- return true;
453
- }
454
- }
455
-
456
- return false;
457
- }, 0);
458
- initializeEditor(editor, initialEditorState);
459
- return removeListener; // We only do this for init
107
+ return utils.mergeRegister(plainText.registerPlainText(editor, initialEditorState), dragon.registerDragonSupport(editor)); // We only do this for init
460
108
  // eslint-disable-next-line react-hooks/exhaustive-deps
461
109
  }, [editor]);
462
- useLexicalDragonSupport(editor);
463
110
  }
464
111
 
465
112
  /**
@@ -4,14 +4,7 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("@lexical/text"),u=require("react-dom"),v=require("@lexical/clipboard"),w=require("@lexical/selection"),x=require("lexical"),y="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
- function z(a){const [d,e]=h.useState(a.getEditorState().read(r.$canShowPlaceholderCurry(a.isComposing())));y(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(r.$canShowPlaceholderCurry(b));e(c)}),[a]);return d}
9
- function B(a){const [d,e]=h.useState(()=>a.getDecorators());y(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const t=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(t,f))}return c},[d,a])}function C(a,d){a.preventDefault();d.update(()=>{const e=x.$getSelection(),c=a.clipboardData;null!=c&&x.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}
10
- function D(a,d){E(a,d);d.update(()=>{const e=x.$getSelection();x.$isRangeSelection(e)&&e.removeText()})}function E(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=x.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const F={tag:"history-merge"};
11
- function G(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=x.$getRoot();if(null===e.getFirstChild()){const c=x.$createParagraphNode();e.append(c);e=document.activeElement;(null!==x.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},F);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,F);break;case "object":a.setEditorState(d,F);break;case "function":a.update(d,F)}}
12
- function H(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,t,A,I]=b;a.update(()=>{const q=x.$getSelection();if(x.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;x.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
13
- t)q.insertRawText(t),k=n.getNode();x.$isTextNode(k)&&(l=A,m=A+I,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
14
- function J(a,d){y(()=>{const e=a.addListener("command",(c,b)=>{const f=x.$getSelection();if(!x.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
15
- !0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!0))return b.preventDefault(),w.$moveCharacter(f,c,!0),!0;break;case "keyArrowRight":c=b.shiftKey;if(w.$shouldOverrideDefaultCharacterSelection(f,!1))return b.preventDefault(),w.$moveCharacter(f,c,!1),!0;break;
16
- case "keyBackspace":return b.preventDefault(),a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return E(b,a),!0;case "cut":return D(b,a),!0;case "paste":return C(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);G(a,d);return e},[a]);H(a)}
17
- module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=z(c);J(c,e);e=B(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
7
+ var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/plain-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ function t(a){const [c,e]=h.useState(a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing())));r(()=>a.registerUpdateListener(({editorState:b})=>{const f=a.isComposing();b=b.read(l.$canShowPlaceholderCurry(f));e(b)}),[a]);return c}
9
+ function u(a){const [c,e]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{e(b)})}),[a]);return h.useMemo(()=>{const b=[],f=Object.keys(c);for(let k=0;k<f.length;k++){var g=f[k];const v=c[g];g=a.getElementByKey(g);null!==g&&b.push(m.createPortal(v,g))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerPlainText(a,c),n.registerDragonSupport(a)),[a])}
10
+ module.exports=function({contentEditable:a,placeholder:c,initialEditorState:e}){const [b]=d.useLexicalComposerContext(),f=t(b);w(b,e);e=u(b);return h.createElement(h.Fragment,null,a,f&&c,e)};