@lexical/react 0.1.9 → 0.1.12
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/DEPRECATED_useLexical.dev.js +5 -44
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +1 -1
- package/DEPRECATED_useLexicalHistory.prod.js +2 -2
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +98 -592
- package/DEPRECATED_useLexicalRichText.prod.js +17 -29
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +87 -41
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -19
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalCharacterLimitPlugin.dev.js +22 -19
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +73 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +49 -0
- package/LexicalCollaborationPlugin.dev.js +21 -11
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +29 -5
- package/LexicalComposer.js.flow +24 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +35 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHistoryPlugin.dev.js +1 -1
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +2 -2
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.d.ts +20 -0
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +77 -84
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +93 -586
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +13 -25
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTablePlugin.dev.js +23 -1
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.d.ts +17 -0
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.js.flow +19 -0
- package/LexicalTreeView.prod.js +9 -8
- package/README.md +0 -1
- package/package.json +6 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.prod.js +8 -0
- package/withSubscriptions.d.ts +12 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -4,4 +4,4 @@
|
|
|
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 b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0}return!1},1),[a])}module.exports=function(a){e(a)};
|
|
7
|
+
var b=require("@lexical/list"),d=require("react");function e(a){d.useEffect(()=>a.addListener("command",c=>{if("indentContent"===c){if(b.indentList())return!0}else if("outdentContent"===c){if(b.outdentList())return!0}else{if("insertOrderedList"===c)return b.insertList(a,"ol"),!0;if("insertUnorderedList"===c)return b.insertList(a,"ul"),!0;if("removeList"===c)return b.removeList(a),!0;if("insertParagraph"===c&&b.$handleListInsertParagraph())return!0}return!1},1),[a])}module.exports=function(a){e(a)};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
var withSubscriptions = require('@lexical/react/withSubscriptions');
|
|
10
10
|
var lexical = require('lexical');
|
|
11
11
|
var react = require('react');
|
|
12
|
+
var clipboard = require('@lexical/clipboard');
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -26,7 +27,7 @@ const COMPOSING_CHARACTER = 1;
|
|
|
26
27
|
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
27
28
|
const DELETE_CHARACTER_BEFORE_SELECTION = 3;
|
|
28
29
|
const DELETE_CHARACTER_AFTER_SELECTION = 4;
|
|
29
|
-
const EditorPriority
|
|
30
|
+
const EditorPriority = 0;
|
|
30
31
|
|
|
31
32
|
function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
|
|
32
33
|
const dirtyLeaves = Array.from(dirtyLeavesSet);
|
|
@@ -73,7 +74,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
|
|
|
73
74
|
return COMPOSING_CHARACTER;
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
if (nextSelection
|
|
77
|
+
if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
|
|
77
78
|
return OTHER;
|
|
78
79
|
}
|
|
79
80
|
|
|
@@ -315,7 +316,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
315
316
|
}
|
|
316
317
|
};
|
|
317
318
|
|
|
318
|
-
return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority
|
|
319
|
+
return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
|
|
319
320
|
}, [clearHistory, delay, editor, historyState]);
|
|
320
321
|
}
|
|
321
322
|
function createEmptyHistoryState() {
|
|
@@ -359,6 +360,10 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
359
360
|
const isRTL = $isParentElementRTL(selection);
|
|
360
361
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
361
362
|
}
|
|
363
|
+
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
364
|
+
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
365
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
366
|
+
}
|
|
362
367
|
|
|
363
368
|
/**
|
|
364
369
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -368,46 +373,7 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
368
373
|
*
|
|
369
374
|
*
|
|
370
375
|
*/
|
|
371
|
-
|
|
372
|
-
const parent = element.getParent();
|
|
373
|
-
let offset = focusOffset;
|
|
374
|
-
let block = element;
|
|
375
|
-
|
|
376
|
-
if (parent !== null) {
|
|
377
|
-
if (isBackward && focusOffset === 0) {
|
|
378
|
-
offset = block.getIndexWithinParent();
|
|
379
|
-
block = parent;
|
|
380
|
-
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
381
|
-
offset = block.getIndexWithinParent() + 1;
|
|
382
|
-
block = parent;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
function getPossibleDecoratorNode(focus, isBackward) {
|
|
390
|
-
const focusOffset = focus.offset;
|
|
391
|
-
|
|
392
|
-
if (focus.type === 'element') {
|
|
393
|
-
const block = focus.getNode();
|
|
394
|
-
return resolveElement(block, isBackward, focusOffset);
|
|
395
|
-
} else {
|
|
396
|
-
const focusNode = focus.getNode();
|
|
397
|
-
|
|
398
|
-
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
399
|
-
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
400
|
-
|
|
401
|
-
if (possibleNode === null) {
|
|
402
|
-
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
return possibleNode;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
return null;
|
|
410
|
-
}
|
|
376
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
411
377
|
|
|
412
378
|
/**
|
|
413
379
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -417,25 +383,25 @@ function getPossibleDecoratorNode(focus, isBackward) {
|
|
|
417
383
|
*
|
|
418
384
|
*
|
|
419
385
|
*/
|
|
420
|
-
|
|
421
|
-
|
|
386
|
+
const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
|
|
387
|
+
var useLayoutEffect = useLayoutEffectImpl;
|
|
422
388
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
389
|
+
/**
|
|
390
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
391
|
+
*
|
|
392
|
+
* This source code is licensed under the MIT license found in the
|
|
393
|
+
* LICENSE file in the root directory of this source tree.
|
|
394
|
+
*
|
|
395
|
+
*
|
|
396
|
+
*/
|
|
431
397
|
function onPasteForPlainText(event, editor) {
|
|
432
398
|
event.preventDefault();
|
|
433
399
|
editor.update(() => {
|
|
434
400
|
const selection = lexical.$getSelection();
|
|
435
401
|
const clipboardData = event.clipboardData;
|
|
436
402
|
|
|
437
|
-
if (clipboardData != null && selection
|
|
438
|
-
|
|
403
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
404
|
+
clipboard.$insertDataTransferForPlainText(clipboardData, selection);
|
|
439
405
|
}
|
|
440
406
|
});
|
|
441
407
|
}
|
|
@@ -444,7 +410,7 @@ function onCutForPlainText(event, editor) {
|
|
|
444
410
|
editor.update(() => {
|
|
445
411
|
const selection = lexical.$getSelection();
|
|
446
412
|
|
|
447
|
-
if (selection
|
|
413
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
448
414
|
selection.removeText();
|
|
449
415
|
}
|
|
450
416
|
});
|
|
@@ -457,19 +423,10 @@ function onCopyForPlainText(event, editor) {
|
|
|
457
423
|
|
|
458
424
|
if (selection !== null) {
|
|
459
425
|
if (clipboardData != null) {
|
|
460
|
-
const
|
|
426
|
+
const htmlString = clipboard.getHtmlContent(editor);
|
|
461
427
|
|
|
462
|
-
if (
|
|
463
|
-
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
const range = domSelection.getRangeAt(0);
|
|
467
|
-
|
|
468
|
-
if (range) {
|
|
469
|
-
const container = document.createElement('div');
|
|
470
|
-
const frag = range.cloneContents();
|
|
471
|
-
container.appendChild(frag);
|
|
472
|
-
clipboardData.setData('text/html', container.innerHTML);
|
|
428
|
+
if (htmlString !== null) {
|
|
429
|
+
clipboardData.setData('text/html', htmlString);
|
|
473
430
|
}
|
|
474
431
|
|
|
475
432
|
clipboardData.setData('text/plain', selection.getTextContent());
|
|
@@ -486,18 +443,53 @@ function onCopyForPlainText(event, editor) {
|
|
|
486
443
|
*
|
|
487
444
|
*
|
|
488
445
|
*/
|
|
489
|
-
|
|
446
|
+
// Convoluted logic to make this work with Flow. Order matters.
|
|
447
|
+
const options = {
|
|
448
|
+
tag: 'history-merge'
|
|
449
|
+
};
|
|
450
|
+
const setEditorOptions = options;
|
|
451
|
+
const updateOptions = options;
|
|
452
|
+
function initializeEditor(editor, initialEditorState) {
|
|
453
|
+
if (initialEditorState === null) {
|
|
454
|
+
return;
|
|
455
|
+
} else if (initialEditorState === undefined) {
|
|
456
|
+
editor.update(() => {
|
|
457
|
+
const root = lexical.$getRoot();
|
|
458
|
+
const firstChild = root.getFirstChild();
|
|
459
|
+
|
|
460
|
+
if (firstChild === null) {
|
|
461
|
+
const paragraph = lexical.$createParagraphNode();
|
|
462
|
+
root.append(paragraph);
|
|
463
|
+
const activeElement = document.activeElement;
|
|
464
|
+
|
|
465
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
466
|
+
paragraph.select();
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
}, updateOptions);
|
|
470
|
+
} else if (initialEditorState !== null) {
|
|
471
|
+
switch (typeof initialEditorState) {
|
|
472
|
+
case 'string':
|
|
473
|
+
{
|
|
474
|
+
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
475
|
+
editor.setEditorState(parsedEditorState, setEditorOptions);
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
490
478
|
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
479
|
+
case 'object':
|
|
480
|
+
{
|
|
481
|
+
editor.setEditorState(initialEditorState, setEditorOptions);
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
case 'function':
|
|
486
|
+
{
|
|
487
|
+
editor.update(initialEditorState, updateOptions);
|
|
488
|
+
break;
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
501
493
|
|
|
502
494
|
/**
|
|
503
495
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -538,7 +530,7 @@ function useLexicalDragonSupport(editor) {
|
|
|
538
530
|
editor.update(() => {
|
|
539
531
|
const selection = lexical.$getSelection();
|
|
540
532
|
|
|
541
|
-
if (selection
|
|
533
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
542
534
|
const anchor = selection.anchor;
|
|
543
535
|
let anchorNode = anchor.getNode();
|
|
544
536
|
let setSelStart = 0;
|
|
@@ -595,13 +587,12 @@ function useLexicalDragonSupport(editor) {
|
|
|
595
587
|
*
|
|
596
588
|
*
|
|
597
589
|
*/
|
|
598
|
-
|
|
599
|
-
function usePlainTextSetup(editor) {
|
|
590
|
+
function usePlainTextSetup(editor, initialEditorState) {
|
|
600
591
|
useLayoutEffect(() => {
|
|
601
592
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
602
593
|
const selection = lexical.$getSelection();
|
|
603
594
|
|
|
604
|
-
if (selection
|
|
595
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
605
596
|
return false;
|
|
606
597
|
}
|
|
607
598
|
|
|
@@ -637,7 +628,7 @@ function usePlainTextSetup(editor) {
|
|
|
637
628
|
const dataTransfer = eventOrText.dataTransfer;
|
|
638
629
|
|
|
639
630
|
if (dataTransfer != null) {
|
|
640
|
-
|
|
631
|
+
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
|
|
641
632
|
} else {
|
|
642
633
|
const data = eventOrText.data;
|
|
643
634
|
|
|
@@ -755,9 +746,10 @@ function usePlainTextSetup(editor) {
|
|
|
755
746
|
}
|
|
756
747
|
|
|
757
748
|
return false;
|
|
758
|
-
},
|
|
759
|
-
editor
|
|
760
|
-
return removeListener;
|
|
749
|
+
}, 0);
|
|
750
|
+
initializeEditor(editor, initialEditorState);
|
|
751
|
+
return removeListener; // We only do this for init
|
|
752
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
761
753
|
}, [editor]);
|
|
762
754
|
useLexicalDragonSupport(editor);
|
|
763
755
|
}
|
|
@@ -770,8 +762,8 @@ function usePlainTextSetup(editor) {
|
|
|
770
762
|
*
|
|
771
763
|
*
|
|
772
764
|
*/
|
|
773
|
-
function useLexicalPlainText(editor, externalHistoryState) {
|
|
774
|
-
usePlainTextSetup(editor);
|
|
765
|
+
function useLexicalPlainText(editor, externalHistoryState, initialEditorState) {
|
|
766
|
+
usePlainTextSetup(editor, initialEditorState);
|
|
775
767
|
useLexicalHistory(editor, externalHistoryState);
|
|
776
768
|
}
|
|
777
769
|
|
|
@@ -4,19 +4,18 @@
|
|
|
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
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return
|
|
13
|
-
p=null===
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
function
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);a.execCommand("bootstrapEditor");return d},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};
|
|
7
|
+
var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react"),w=require("@lexical/clipboard");
|
|
8
|
+
function x(a,d,f,b,c){if(null===a||0===f.size&&0===b.size)return 0;var e=d._selection,g=a._selection;if(c)return 1;if(!(u.$isRangeSelection(e)&&u.$isRangeSelection(g)&&g.isCollapsed()&&e.isCollapsed()))return 0;var h=Array.from(f);b=Array.from(b);f=d._nodeMap;c=[];for(var l=0;l<h.length;l++){const n=f.get(h[l]);void 0!==n&&c.push(n)}for(h=0;h<b.length;h++)b[h][1]&&(l=f.get(b[h][0]),void 0===l||u.$isRootNode(l)||c.push(l));if(0===c.length)return 0;if(1<c.length)return b=d._nodeMap,d=b.get(e.anchor.key),
|
|
9
|
+
g=b.get(g.anchor.key),d&&g&&!a._nodeMap.has(d.__key)&&u.$isTextNode(d)&&1===d.__text.length&&1===e.anchor.offset?2:0;d=c[0];a=a._nodeMap.get(d.__key);if(!u.$isTextNode(a)||!u.$isTextNode(d)||a.__mode!==d.__mode)return 0;a=a.__text;d=d.__text;if(a===d)return 0;e=e.anchor;g=g.anchor;if(e.key!==g.key||"text"!==e.type)return 0;e=e.offset;g=g.offset;a=d.length-a.length;return 1===a&&g===e-1?2:-1===a&&g===e+1?3:-1===a&&g===e?4:0}
|
|
10
|
+
function y(a,d){let f=Date.now(),b=0;return(c,e,g,h,l,n)=>{const t=Date.now();if(n.has("historic"))return b=0,f=t,2;const m=x(c,e,h,l,a.isComposing()),r=(()=>{const q=n.has("history-push");if(!q&&n.has("history-merge"))return 0;if(null===c)return 1;var p=e._selection;const D=c._selection;if(!(0<h.size||0<l.size))return null===D&&null!==p?0:2;p=null===g||g.editor===a;return!1===q&&0!==m&&m===b&&t<f+d&&p?0:1})();f=t;b=m;return r}}
|
|
11
|
+
function z(a,d,f=1E3){const b=v.useMemo(()=>d||{current:null,redoStack:[],undoStack:[]},[d]),c=v.useCallback(()=>{b.undoStack=[];b.redoStack=[];b.current=null},[b]);v.useEffect(()=>{const e=y(a,f);return k(a.addListener("command",g=>{switch(g){case "undo":g=b.redoStack;var h=b.undoStack;if(0!==h.length){var l=b.current;const n=h.pop();null!==l&&(g.push(l),a.execCommand("canRedo",!0));0===h.length&&a.execCommand("canUndo",!1);b.current=n;n.editor.setEditorState(n.editorState.clone(n.undoSelection),
|
|
12
|
+
{tag:"historic"})}return!0;case "redo":return g=b.redoStack,h=b.undoStack,0!==g.length&&(l=b.current,null!==l&&(h.push(l),a.execCommand("canUndo",!0)),h=g.pop(),0===g.length&&a.execCommand("canRedo",!1),b.current=h,h.editor.setEditorState(h.editorState,{tag:"historic"})),!0;case "clearEditor":return c(),!1;case "clearHistory":return c(),!0;default:return!1}},0),a.addListener("update",({editorState:g,prevEditorState:h,dirtyLeaves:l,dirtyElements:n,tags:t})=>{const m=b.current,r=b.redoStack,q=b.undoStack,
|
|
13
|
+
p=null===m?null:m.editorState;if(null===m||g!==p){l=e(h,g,m,l,n,t);if(1===l)0!==r.length&&(b.redoStack=[]),null!==m&&(q.push({...m,undoSelection:h.read(u.$getSelection)}),a.execCommand("canUndo",!0));else if(2===l)return;b.current={editor:a,editorState:g}}}))},[c,f,a,b])}function A(a,d,f=1E3){return z(a,d,f)}function B(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}
|
|
14
|
+
function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}var E="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?v.useLayoutEffect:v.useEffect;function F(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&w.$insertDataTransferForPlainText(b,f)})}
|
|
15
|
+
function G(a,d){H(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}function H(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){const c=w.getHtmlContent(d);null!==c&&f.setData("text/html",c);f.setData("text/plain",b.getTextContent())}})}const I={tag:"history-merge"};
|
|
16
|
+
function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var f=u.$getRoot();if(null===f.getFirstChild()){const b=u.$createParagraphNode();f.append(b);f=document.activeElement;(null!==u.$getSelection()||null!==f&&f===a.getRootElement())&&b.select()}},I);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,I);break;case "object":a.setEditorState(d,I);break;case "function":a.update(d,I)}}
|
|
17
|
+
function K(a){v.useEffect(()=>{const d=f=>{var b=a.getRootElement();if(document.activeElement===b&&(b=f.data,"string"===typeof b)){try{var c=JSON.parse(b)}catch(e){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [e,g,h,l,n]=c;a.update(()=>{const t=u.$getSelection();if(u.$isRangeSelection(t)){var m=t.anchor;let r=m.getNode(),q=0,p=0;u.$isTextNode(r)&&0<=e&&0<=g&&(q=e,p=e+g,t.setTextNodeRange(r,q,r,p));if(q!==p||""!==
|
|
18
|
+
h)t.insertRawText(h),r=m.getNode();u.$isTextNode(r)&&(q=l,p=l+n,m=r.getTextContentSize(),q=q>m?m:q,p=p>m?m:p,t.setTextNodeRange(r,q,r,p));f.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
19
|
+
function L(a,d){E(()=>{const f=a.addListener("command",(b,c)=>{const e=u.$getSelection();if(!u.$isRangeSelection(e))return!1;switch(b){case "deleteCharacter":return e.deleteCharacter(c),!0;case "deleteWord":return e.deleteWord(c),!0;case "deleteLine":return e.deleteLine(c),!0;case "insertText":return"string"===typeof c?e.insertText(c):(b=c.dataTransfer,null!=b?w.$insertDataTransferForPlainText(b,e):(c=c.data)&&e.insertText(c)),!0;case "removeText":return e.removeText(),!0;case "insertLineBreak":return e.insertLineBreak(c),
|
|
20
|
+
!0;case "insertParagraph":return e.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b=c.shiftKey;if(C(e,!0))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",!b,"character"),!0;break;case "keyArrowRight":b=c.shiftKey;if(C(e,!1))return c.preventDefault(),c=b,b=B(e),e.modify(c?"extend":"move",b,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
21
|
+
a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(c,a),!0;case "cut":return G(c,a),!0;case "paste":return F(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,d);return f},[a]);K(a)}module.exports=function(a,d,f){L(a,f);A(a,d)};
|