@lexical/react 0.1.8 → 0.1.11
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 +3 -38
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +202 -74
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +21 -16
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +23 -21
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +18 -15
- package/DEPRECATED_useLexicalHistory.prod.js +7 -7
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +79 -70
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +124 -250
- package/DEPRECATED_useLexicalRichText.prod.js +25 -29
- package/LexicalAutoFormatterPlugin.dev.js +202 -74
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -17
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalAutoLinkPlugin.prod.js +4 -4
- package/LexicalCharacterLimitPlugin.dev.js +23 -21
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.dev.js +52 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +7 -0
- package/LexicalCollaborationPlugin.dev.js +31 -36
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -8
- package/LexicalComposer.dev.js +8 -6
- package/LexicalComposer.js.flow +23 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalComposerContext.prod.js +1 -1
- package/LexicalContentEditable.dev.js +14 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.js.flow +20 -0
- package/LexicalHashtagPlugin.prod.js +1 -1
- package/LexicalHistoryPlugin.dev.js +18 -15
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +7 -7
- package/LexicalHorizontalRuleNode.dev.js +66 -0
- package/LexicalHorizontalRuleNode.js +9 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalHorizontalRuleNode.prod.js +8 -0
- package/LexicalLinkPlugin.dev.js +0 -1
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalLinkPlugin.prod.js +3 -3
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalNestedComposer.prod.js +1 -1
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalOnChangePlugin.prod.js +1 -1
- package/LexicalPlainTextPlugin.dev.js +72 -44
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -11
- package/LexicalRichTextPlugin.dev.js +115 -222
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +21 -25
- package/LexicalTablePlugin.dev.js +43 -39
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- 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 +5 -4
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalDecoratorMap.prod.js +1 -1
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalIsTextContentEmpty.prod.js +1 -1
- 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.js.flow +13 -0
- package/withSubscriptions.prod.js +1 -1
- package/LexicalBootstrapPlugin.dev.js +0 -124
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
- package/LexicalHorizontalRulePlugin.dev.js +0 -51
- package/LexicalHorizontalRulePlugin.js +0 -9
- package/LexicalHorizontalRulePlugin.prod.js +0 -7
|
@@ -18,15 +18,15 @@ var react = require('react');
|
|
|
18
18
|
*
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
21
|
+
const HISTORY_MERGE = 0;
|
|
22
|
+
const HISTORY_PUSH = 1;
|
|
23
|
+
const DISCARD_HISTORY_CANDIDATE = 2;
|
|
24
24
|
const OTHER = 0;
|
|
25
25
|
const COMPOSING_CHARACTER = 1;
|
|
26
26
|
const INSERT_CHARACTER_AFTER_SELECTION = 2;
|
|
27
27
|
const DELETE_CHARACTER_BEFORE_SELECTION = 3;
|
|
28
28
|
const DELETE_CHARACTER_AFTER_SELECTION = 4;
|
|
29
|
-
const EditorPriority
|
|
29
|
+
const EditorPriority = 0;
|
|
30
30
|
|
|
31
31
|
function getDirtyNodes(editorState, dirtyLeavesSet, dirtyElementsSet) {
|
|
32
32
|
const dirtyLeaves = Array.from(dirtyLeavesSet);
|
|
@@ -73,7 +73,7 @@ function getChangeType(prevEditorState, nextEditorState, dirtyLeavesSet, dirtyEl
|
|
|
73
73
|
return COMPOSING_CHARACTER;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
if (nextSelection
|
|
76
|
+
if (!lexical.$isRangeSelection(nextSelection) || !lexical.$isRangeSelection(prevSelection) || !prevSelection.isCollapsed() || !nextSelection.isCollapsed()) {
|
|
77
77
|
return OTHER;
|
|
78
78
|
}
|
|
79
79
|
|
|
@@ -148,18 +148,21 @@ function createMergeActionGetter(editor, delay) {
|
|
|
148
148
|
if (tags.has('historic')) {
|
|
149
149
|
prevChangeType = OTHER;
|
|
150
150
|
prevChangeTime = changeTime;
|
|
151
|
-
return
|
|
151
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const changeType = getChangeType(prevEditorState, nextEditorState, dirtyLeaves, dirtyElements, editor.isComposing());
|
|
155
155
|
|
|
156
156
|
const mergeAction = (() => {
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
const shouldPushHistory = tags.has('history-push');
|
|
158
|
+
const shouldMergeHistory = !shouldPushHistory && tags.has('history-merge');
|
|
159
|
+
|
|
160
|
+
if (shouldMergeHistory) {
|
|
161
|
+
return HISTORY_MERGE;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
if (prevEditorState === null) {
|
|
162
|
-
return
|
|
165
|
+
return HISTORY_PUSH;
|
|
163
166
|
}
|
|
164
167
|
|
|
165
168
|
const selection = nextEditorState._selection;
|
|
@@ -168,19 +171,19 @@ function createMergeActionGetter(editor, delay) {
|
|
|
168
171
|
|
|
169
172
|
if (!hasDirtyNodes) {
|
|
170
173
|
if (prevSelection === null && selection !== null) {
|
|
171
|
-
return
|
|
174
|
+
return HISTORY_MERGE;
|
|
172
175
|
}
|
|
173
176
|
|
|
174
|
-
return
|
|
177
|
+
return DISCARD_HISTORY_CANDIDATE;
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
const isSameEditor = currentHistoryEntry === null || currentHistoryEntry.editor === editor;
|
|
178
181
|
|
|
179
|
-
if (changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
180
|
-
return
|
|
182
|
+
if (shouldPushHistory === false && changeType !== OTHER && changeType === prevChangeType && changeTime < prevChangeTime + delay && isSameEditor) {
|
|
183
|
+
return HISTORY_MERGE;
|
|
181
184
|
}
|
|
182
185
|
|
|
183
|
-
return
|
|
186
|
+
return HISTORY_PUSH;
|
|
184
187
|
})();
|
|
185
188
|
|
|
186
189
|
prevChangeTime = changeTime;
|
|
@@ -217,7 +220,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
217
220
|
|
|
218
221
|
const mergeAction = getMergeAction(prevEditorState, editorState, current, dirtyLeaves, dirtyElements, tags);
|
|
219
222
|
|
|
220
|
-
if (mergeAction ===
|
|
223
|
+
if (mergeAction === HISTORY_PUSH) {
|
|
221
224
|
if (redoStack.length !== 0) {
|
|
222
225
|
historyState.redoStack = [];
|
|
223
226
|
}
|
|
@@ -228,7 +231,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
228
231
|
});
|
|
229
232
|
editor.execCommand('canUndo', true);
|
|
230
233
|
}
|
|
231
|
-
} else if (mergeAction ===
|
|
234
|
+
} else if (mergeAction === DISCARD_HISTORY_CANDIDATE) {
|
|
232
235
|
return;
|
|
233
236
|
} // Else we merge
|
|
234
237
|
|
|
@@ -312,7 +315,7 @@ function useHistory(editor, externalHistoryState, delay = 1000) {
|
|
|
312
315
|
}
|
|
313
316
|
};
|
|
314
317
|
|
|
315
|
-
return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority
|
|
318
|
+
return withSubscriptions(editor.addListener('command', applyCommand, EditorPriority), editor.addListener('update', applyChange));
|
|
316
319
|
}, [clearHistory, delay, editor, historyState]);
|
|
317
320
|
}
|
|
318
321
|
function createEmptyHistoryState() {
|
|
@@ -349,7 +352,7 @@ function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity)
|
|
|
349
352
|
}
|
|
350
353
|
function $isParentElementRTL(selection) {
|
|
351
354
|
const anchorNode = selection.anchor.getNode();
|
|
352
|
-
const parent = anchorNode.getParentOrThrow();
|
|
355
|
+
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
353
356
|
return parent.getDirection() === 'rtl';
|
|
354
357
|
}
|
|
355
358
|
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
@@ -357,31 +360,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
357
360
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
358
361
|
}
|
|
359
362
|
|
|
360
|
-
/**
|
|
361
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
362
|
-
*
|
|
363
|
-
* This source code is licensed under the MIT license found in the
|
|
364
|
-
* LICENSE file in the root directory of this source tree.
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
*/
|
|
368
|
-
function getPossibleDecoratorNode(focus, isBackward) {
|
|
369
|
-
const focusOffset = focus.offset;
|
|
370
|
-
|
|
371
|
-
if (focus.type === 'element') {
|
|
372
|
-
const block = focus.getNode();
|
|
373
|
-
return block.getChildAtIndex(isBackward ? focusOffset - 1 : focusOffset);
|
|
374
|
-
} else {
|
|
375
|
-
const focusNode = focus.getNode();
|
|
376
|
-
|
|
377
|
-
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
378
|
-
return isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
363
|
/**
|
|
386
364
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
387
365
|
*
|
|
@@ -398,17 +376,16 @@ function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
|
398
376
|
}
|
|
399
377
|
}
|
|
400
378
|
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
401
|
-
const
|
|
402
|
-
return lexical.$isDecoratorNode(
|
|
379
|
+
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
380
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
403
381
|
}
|
|
404
382
|
function onPasteForPlainText(event, editor) {
|
|
405
383
|
event.preventDefault();
|
|
406
384
|
editor.update(() => {
|
|
407
|
-
lexical.$log('onPasteForPlainText');
|
|
408
385
|
const selection = lexical.$getSelection();
|
|
409
386
|
const clipboardData = event.clipboardData;
|
|
410
387
|
|
|
411
|
-
if (clipboardData != null && selection
|
|
388
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
412
389
|
$insertDataTransferForPlainText(clipboardData, selection);
|
|
413
390
|
}
|
|
414
391
|
});
|
|
@@ -416,10 +393,9 @@ function onPasteForPlainText(event, editor) {
|
|
|
416
393
|
function onCutForPlainText(event, editor) {
|
|
417
394
|
onCopyForPlainText(event, editor);
|
|
418
395
|
editor.update(() => {
|
|
419
|
-
lexical.$log('onCutForPlainText');
|
|
420
396
|
const selection = lexical.$getSelection();
|
|
421
397
|
|
|
422
|
-
if (selection
|
|
398
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
423
399
|
selection.removeText();
|
|
424
400
|
}
|
|
425
401
|
});
|
|
@@ -427,7 +403,6 @@ function onCutForPlainText(event, editor) {
|
|
|
427
403
|
function onCopyForPlainText(event, editor) {
|
|
428
404
|
event.preventDefault();
|
|
429
405
|
editor.update(() => {
|
|
430
|
-
lexical.$log('onCopyForPlainText');
|
|
431
406
|
const clipboardData = event.clipboardData;
|
|
432
407
|
const selection = lexical.$getSelection();
|
|
433
408
|
|
|
@@ -462,18 +437,53 @@ function onCopyForPlainText(event, editor) {
|
|
|
462
437
|
*
|
|
463
438
|
*
|
|
464
439
|
*/
|
|
465
|
-
|
|
440
|
+
// Convoluted logic to make this work with Flow. Order matters.
|
|
441
|
+
const options = {
|
|
442
|
+
tag: 'history-merge'
|
|
443
|
+
};
|
|
444
|
+
const setEditorOptions = options;
|
|
445
|
+
const updateOptions = options;
|
|
446
|
+
function initializeEditor(editor, initialEditorState) {
|
|
447
|
+
if (initialEditorState === null) {
|
|
448
|
+
return;
|
|
449
|
+
} else if (initialEditorState === undefined) {
|
|
450
|
+
editor.update(() => {
|
|
451
|
+
const root = lexical.$getRoot();
|
|
452
|
+
const firstChild = root.getFirstChild();
|
|
453
|
+
|
|
454
|
+
if (firstChild === null) {
|
|
455
|
+
const paragraph = lexical.$createParagraphNode();
|
|
456
|
+
root.append(paragraph);
|
|
457
|
+
const activeElement = document.activeElement;
|
|
458
|
+
|
|
459
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
460
|
+
paragraph.select();
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}, updateOptions);
|
|
464
|
+
} else if (initialEditorState !== null) {
|
|
465
|
+
switch (typeof initialEditorState) {
|
|
466
|
+
case 'string':
|
|
467
|
+
{
|
|
468
|
+
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
469
|
+
editor.setEditorState(parsedEditorState, setEditorOptions);
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
466
472
|
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
473
|
+
case 'object':
|
|
474
|
+
{
|
|
475
|
+
editor.setEditorState(initialEditorState, setEditorOptions);
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
case 'function':
|
|
480
|
+
{
|
|
481
|
+
editor.update(initialEditorState, updateOptions);
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
477
487
|
|
|
478
488
|
/**
|
|
479
489
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -512,10 +522,9 @@ function useLexicalDragonSupport(editor) {
|
|
|
512
522
|
if (args) {
|
|
513
523
|
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
|
|
514
524
|
editor.update(() => {
|
|
515
|
-
lexical.$log('useLexicalDragonSupport');
|
|
516
525
|
const selection = lexical.$getSelection();
|
|
517
526
|
|
|
518
|
-
if (selection
|
|
527
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
519
528
|
const anchor = selection.anchor;
|
|
520
529
|
let anchorNode = anchor.getNode();
|
|
521
530
|
let setSelStart = 0;
|
|
@@ -572,13 +581,12 @@ function useLexicalDragonSupport(editor) {
|
|
|
572
581
|
*
|
|
573
582
|
*
|
|
574
583
|
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
useLayoutEffect(() => {
|
|
584
|
+
function usePlainTextSetup(editor, initialEditorState) {
|
|
585
|
+
react.useEffect(() => {
|
|
578
586
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
579
587
|
const selection = lexical.$getSelection();
|
|
580
588
|
|
|
581
|
-
if (selection
|
|
589
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
582
590
|
return false;
|
|
583
591
|
}
|
|
584
592
|
|
|
@@ -732,9 +740,10 @@ function usePlainTextSetup(editor) {
|
|
|
732
740
|
}
|
|
733
741
|
|
|
734
742
|
return false;
|
|
735
|
-
},
|
|
736
|
-
editor
|
|
737
|
-
return removeListener;
|
|
743
|
+
}, 0);
|
|
744
|
+
initializeEditor(editor, initialEditorState);
|
|
745
|
+
return removeListener; // We only do this for init
|
|
746
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
738
747
|
}, [editor]);
|
|
739
748
|
useLexicalDragonSupport(editor);
|
|
740
749
|
}
|
|
@@ -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
|
-
|
|
8
|
-
function w(a,
|
|
9
|
-
|
|
10
|
-
function x(a,
|
|
11
|
-
function y(a,
|
|
12
|
-
{tag:"historic"})}return!0;case "redo":return
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
function
|
|
16
|
-
var
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
function
|
|
20
|
-
!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c
|
|
21
|
-
|
|
22
|
-
module.exports=function(a,e){H(a);z(a,e)};
|
|
7
|
+
var k=require("@lexical/react/withSubscriptions"),u=require("lexical"),v=require("react");
|
|
8
|
+
function w(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 x(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=w(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 y(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=x(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 z(a,d,f=1E3){return y(a,d,f)}function A(a){a=a.anchor.getNode();return"rtl"===(u.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function B(a,d){a=a.getData("text/plain");null!=a&&d.insertRawText(a)}
|
|
14
|
+
function C(a,d){a=u.$getDecoratorNode(a.focus,d);return u.$isDecoratorNode(a)&&!a.isIsolated()}function E(a,d){a.preventDefault();d.update(()=>{const f=u.$getSelection(),b=a.clipboardData;null!=b&&u.$isRangeSelection(f)&&B(b,f)})}function F(a,d){G(a,d);d.update(()=>{const f=u.$getSelection();u.$isRangeSelection(f)&&f.removeText()})}
|
|
15
|
+
function G(a,d){a.preventDefault();d.update(()=>{const f=a.clipboardData,b=u.$getSelection();if(null!==b&&null!=f){var c=window.getSelection();if(!c.isCollapsed){var e=c.getRangeAt(0);e&&(c=document.createElement("div"),e=e.cloneContents(),c.appendChild(e),f.setData("text/html",c.innerHTML));f.setData("text/plain",b.getTextContent())}}})}const H={tag:"history-merge"};
|
|
16
|
+
function I(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()}},H);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,H);break;case "object":a.setEditorState(d,H);break;case "function":a.update(d,H)}}
|
|
17
|
+
function J(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 K(a,d){v.useEffect(()=>{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?B(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=A(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=A(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 G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return E(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);I(a,d);return f},[a]);J(a)}module.exports=function(a,d){K(a);z(a,d)};
|