@lexical/rich-text 0.6.4 → 0.7.0
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/LexicalRichText.dev.js +89 -45
- package/LexicalRichText.prod.js +26 -24
- package/index.d.ts +2 -2
- package/package.json +5 -5
package/LexicalRichText.dev.js
CHANGED
|
@@ -20,10 +20,28 @@ var lexical = require('lexical');
|
|
|
20
20
|
*/
|
|
21
21
|
function caretFromPoint(x, y) {
|
|
22
22
|
if (typeof document.caretRangeFromPoint !== 'undefined') {
|
|
23
|
-
|
|
23
|
+
const range = document.caretRangeFromPoint(x, y);
|
|
24
|
+
|
|
25
|
+
if (range === null) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
node: range.startContainer,
|
|
31
|
+
offset: range.startOffset
|
|
32
|
+
}; // @ts-ignore
|
|
24
33
|
} else if (document.caretPositionFromPoint !== 'undefined') {
|
|
25
34
|
// @ts-ignore FF - no types
|
|
26
|
-
|
|
35
|
+
const range = document.caretPositionFromPoint(x, y);
|
|
36
|
+
|
|
37
|
+
if (range === null) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
node: range.offsetNode,
|
|
43
|
+
offset: range.offset
|
|
44
|
+
};
|
|
27
45
|
} else {
|
|
28
46
|
// Gracefully handle IE
|
|
29
47
|
return null;
|
|
@@ -53,8 +71,8 @@ const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentM
|
|
|
53
71
|
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
54
72
|
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; // Keep these in case we need to use them in the future.
|
|
55
73
|
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
56
|
-
|
|
57
|
-
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
74
|
+
|
|
75
|
+
CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent); // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
58
76
|
|
|
59
77
|
/** @module @lexical/rich-text */
|
|
60
78
|
const DRAG_DROP_PASTE = lexical.createCommand('DRAG_DROP_PASTE_FILE');
|
|
@@ -108,11 +126,11 @@ class QuoteNode extends lexical.ElementNode {
|
|
|
108
126
|
} // Mutation
|
|
109
127
|
|
|
110
128
|
|
|
111
|
-
insertNewAfter() {
|
|
129
|
+
insertNewAfter(_, restoreSelection) {
|
|
112
130
|
const newBlock = lexical.$createParagraphNode();
|
|
113
131
|
const direction = this.getDirection();
|
|
114
132
|
newBlock.setDirection(direction);
|
|
115
|
-
this.insertAfter(newBlock);
|
|
133
|
+
this.insertAfter(newBlock, restoreSelection);
|
|
116
134
|
return newBlock;
|
|
117
135
|
}
|
|
118
136
|
|
|
@@ -247,19 +265,17 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
247
265
|
} // Mutation
|
|
248
266
|
|
|
249
267
|
|
|
250
|
-
insertNewAfter(selection) {
|
|
251
|
-
const
|
|
252
|
-
const newElement =
|
|
268
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
269
|
+
const anchorOffet = selection ? selection.anchor.offset : 0;
|
|
270
|
+
const newElement = anchorOffet > 0 && anchorOffet < this.getTextContentSize() ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
|
|
253
271
|
const direction = this.getDirection();
|
|
254
272
|
newElement.setDirection(direction);
|
|
255
|
-
this.insertAfter(newElement);
|
|
273
|
+
this.insertAfter(newElement, restoreSelection);
|
|
256
274
|
return newElement;
|
|
257
275
|
}
|
|
258
276
|
|
|
259
277
|
collapseAtStart() {
|
|
260
|
-
const
|
|
261
|
-
const isPreviouSiblingEmpty = !previousSibling || previousSibling && previousSibling.getTextContentSize() === 0;
|
|
262
|
-
const newElement = isPreviouSiblingEmpty ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
|
|
278
|
+
const newElement = !this.isEmpty() ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
|
|
263
279
|
const children = this.getChildren();
|
|
264
280
|
children.forEach(child => newElement.append(child));
|
|
265
281
|
this.replace(newElement);
|
|
@@ -387,11 +403,16 @@ function handleIndentAndOutdent(insertTab, indentOrOutdent) {
|
|
|
387
403
|
}
|
|
388
404
|
}
|
|
389
405
|
|
|
390
|
-
function isTargetWithinDecorator(target) {
|
|
406
|
+
function $isTargetWithinDecorator(target) {
|
|
391
407
|
const node = lexical.$getNearestNodeFromDOMNode(target);
|
|
392
408
|
return lexical.$isDecoratorNode(node);
|
|
393
409
|
}
|
|
394
410
|
|
|
411
|
+
function $isSelectionAtEndOfRoot(selection) {
|
|
412
|
+
const focus = selection.focus;
|
|
413
|
+
return focus.key === 'root' && focus.offset === lexical.$getRoot().getChildrenSize();
|
|
414
|
+
}
|
|
415
|
+
|
|
395
416
|
function registerRichText(editor) {
|
|
396
417
|
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
|
|
397
418
|
const selection = lexical.$getSelection();
|
|
@@ -540,7 +561,7 @@ function registerRichText(editor) {
|
|
|
540
561
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => {
|
|
541
562
|
const selection = lexical.$getSelection();
|
|
542
563
|
|
|
543
|
-
if (lexical.$isNodeSelection(selection) &&
|
|
564
|
+
if (lexical.$isNodeSelection(selection) && !$isTargetWithinDecorator(event.target)) {
|
|
544
565
|
// If selection is on a node, let's try and move selection
|
|
545
566
|
// back to being a range selection.
|
|
546
567
|
const nodes = selection.getNodes();
|
|
@@ -549,6 +570,18 @@ function registerRichText(editor) {
|
|
|
549
570
|
nodes[0].selectPrevious();
|
|
550
571
|
return true;
|
|
551
572
|
}
|
|
573
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
|
574
|
+
const possibleNode = lexical.$getAdjacentNode(selection.focus, true);
|
|
575
|
+
|
|
576
|
+
if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated()) {
|
|
577
|
+
possibleNode.selectPrevious();
|
|
578
|
+
event.preventDefault();
|
|
579
|
+
return true;
|
|
580
|
+
} else if (lexical.$isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty()) {
|
|
581
|
+
possibleNode.select();
|
|
582
|
+
event.preventDefault();
|
|
583
|
+
return true;
|
|
584
|
+
}
|
|
552
585
|
}
|
|
553
586
|
|
|
554
587
|
return false;
|
|
@@ -564,6 +597,19 @@ function registerRichText(editor) {
|
|
|
564
597
|
nodes[0].selectNext(0, 0);
|
|
565
598
|
return true;
|
|
566
599
|
}
|
|
600
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
|
601
|
+
if ($isSelectionAtEndOfRoot(selection)) {
|
|
602
|
+
event.preventDefault();
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const possibleNode = lexical.$getAdjacentNode(selection.focus, false);
|
|
607
|
+
|
|
608
|
+
if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated()) {
|
|
609
|
+
possibleNode.selectNext();
|
|
610
|
+
event.preventDefault();
|
|
611
|
+
return true;
|
|
612
|
+
}
|
|
567
613
|
}
|
|
568
614
|
|
|
569
615
|
return false;
|
|
@@ -597,7 +643,7 @@ function registerRichText(editor) {
|
|
|
597
643
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => {
|
|
598
644
|
const selection$1 = lexical.$getSelection();
|
|
599
645
|
|
|
600
|
-
if (lexical.$isNodeSelection(selection$1) &&
|
|
646
|
+
if (lexical.$isNodeSelection(selection$1) && !$isTargetWithinDecorator(event.target)) {
|
|
601
647
|
// If selection is on a node, let's try and move selection
|
|
602
648
|
// back to being a range selection.
|
|
603
649
|
const nodes = selection$1.getNodes();
|
|
@@ -623,7 +669,7 @@ function registerRichText(editor) {
|
|
|
623
669
|
|
|
624
670
|
return false;
|
|
625
671
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
|
|
626
|
-
if (isTargetWithinDecorator(event.target)) {
|
|
672
|
+
if ($isTargetWithinDecorator(event.target)) {
|
|
627
673
|
return false;
|
|
628
674
|
}
|
|
629
675
|
|
|
@@ -649,7 +695,7 @@ function registerRichText(editor) {
|
|
|
649
695
|
|
|
650
696
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
651
697
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
|
|
652
|
-
if (isTargetWithinDecorator(event.target)) {
|
|
698
|
+
if ($isTargetWithinDecorator(event.target)) {
|
|
653
699
|
return false;
|
|
654
700
|
}
|
|
655
701
|
|
|
@@ -688,15 +734,6 @@ function registerRichText(editor) {
|
|
|
688
734
|
}
|
|
689
735
|
|
|
690
736
|
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND, undefined);
|
|
691
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
692
|
-
const selection = lexical.$getSelection();
|
|
693
|
-
|
|
694
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
695
|
-
return false;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
event.preventDefault();
|
|
699
|
-
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
700
737
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, () => {
|
|
701
738
|
const selection = lexical.$getSelection();
|
|
702
739
|
|
|
@@ -716,27 +753,22 @@ function registerRichText(editor) {
|
|
|
716
753
|
|
|
717
754
|
if (eventRange !== null) {
|
|
718
755
|
const {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
startContainer,
|
|
722
|
-
endContainer
|
|
756
|
+
offset: domOffset,
|
|
757
|
+
node: domNode
|
|
723
758
|
} = eventRange;
|
|
724
|
-
const
|
|
725
|
-
const endNode = lexical.$getNearestNodeFromDOMNode(endContainer);
|
|
759
|
+
const node = lexical.$getNearestNodeFromDOMNode(domNode);
|
|
726
760
|
|
|
727
|
-
if (
|
|
761
|
+
if (node !== null) {
|
|
728
762
|
const selection = lexical.$createRangeSelection();
|
|
729
763
|
|
|
730
|
-
if (lexical.$isTextNode(
|
|
731
|
-
selection.anchor.set(
|
|
764
|
+
if (lexical.$isTextNode(node)) {
|
|
765
|
+
selection.anchor.set(node.getKey(), domOffset, 'text');
|
|
766
|
+
selection.focus.set(node.getKey(), domOffset, 'text');
|
|
732
767
|
} else {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
selection.focus.set(endNode.getKey(), endOffset, 'text');
|
|
738
|
-
} else {
|
|
739
|
-
selection.focus.set(endNode.getParentOrThrow().getKey(), endNode.getIndexWithinParent() + 1, 'element');
|
|
768
|
+
const parentKey = node.getParentOrThrow().getKey();
|
|
769
|
+
const offset = node.getIndexWithinParent() + 1;
|
|
770
|
+
selection.anchor.set(parentKey, offset, 'element');
|
|
771
|
+
selection.focus.set(parentKey, offset, 'element');
|
|
740
772
|
}
|
|
741
773
|
|
|
742
774
|
const normalizedSelection = lexical.$normalizeSelection__EXPERIMENTAL(selection);
|
|
@@ -765,7 +797,6 @@ function registerRichText(editor) {
|
|
|
765
797
|
return false;
|
|
766
798
|
}
|
|
767
799
|
|
|
768
|
-
event.preventDefault();
|
|
769
800
|
return true;
|
|
770
801
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGOVER_COMMAND, event => {
|
|
771
802
|
const [isFileTransfer] = eventFiles(event);
|
|
@@ -775,7 +806,20 @@ function registerRichText(editor) {
|
|
|
775
806
|
return false;
|
|
776
807
|
}
|
|
777
808
|
|
|
778
|
-
event.
|
|
809
|
+
const x = event.clientX;
|
|
810
|
+
const y = event.clientY;
|
|
811
|
+
const eventRange = caretFromPoint(x, y);
|
|
812
|
+
|
|
813
|
+
if (eventRange !== null) {
|
|
814
|
+
const node = lexical.$getNearestNodeFromDOMNode(eventRange.node);
|
|
815
|
+
|
|
816
|
+
if (lexical.$isDecoratorNode(node)) {
|
|
817
|
+
// Show browser caret as the user is dragging the media across the screen. Won't work
|
|
818
|
+
// for DecoratorNode nor it's relevant.
|
|
819
|
+
event.preventDefault();
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
|
|
779
823
|
return true;
|
|
780
824
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
|
|
781
825
|
clipboard.copyToClipboard__EXPERIMENTAL(editor, event instanceof ClipboardEvent ? event : null);
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,27 +4,29 @@
|
|
|
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
|
-
'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),
|
|
8
|
-
let r=
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
exports
|
|
19
|
-
c.registerCommand(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
()
|
|
23
|
-
|
|
24
|
-
!
|
|
25
|
-
|
|
26
|
-
b.preventDefault()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
7
|
+
'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");function m(c,b){return"undefined"!==typeof document.caretRangeFromPoint?(c=document.caretRangeFromPoint(c,b),null===c?null:{node:c.startContainer,offset:c.startOffset}):"undefined"!==document.caretPositionFromPoint?(c=document.caretPositionFromPoint(c,b),null===c?null:{node:c.offsetNode,offset:c.offset}):null}
|
|
8
|
+
let p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,q=p&&"documentMode"in document?document.documentMode:null;p&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);let r=p&&"InputEvent"in window&&!q?"getTargetRanges"in new window.InputEvent("input"):!1,t=p&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),u=p&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;
|
|
9
|
+
p&&/^(?=.*Chrome).*/i.test(navigator.userAgent);let w=l.createCommand("DRAG_DROP_PASTE_FILE");
|
|
10
|
+
class x extends l.ElementNode{static getType(){return"quote"}static clone(c){return new x(c.__key)}constructor(c){super(c)}createDOM(c){let b=document.createElement("blockquote");k.addClassNamesToElement(b,c.theme.quote);return b}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:y,priority:0})}}static importJSON(c){let b=z();b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(c,
|
|
11
|
+
b){c=l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=l.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}}function z(){return l.$applyNodeReplacement(new x)}
|
|
12
|
+
class A extends l.ElementNode{static getType(){return"heading"}static clone(c){return new A(c.__tag,c.__key)}constructor(c,b){super(b);this.__tag=c}getTag(){return this.__tag}createDOM(c){let b=this.__tag,d=document.createElement(b);c=c.theme.heading;void 0!==c&&k.addClassNamesToElement(d,c[b]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:B,priority:0}),h2:()=>({conversion:B,priority:0}),h3:()=>({conversion:B,priority:0}),h4:()=>({conversion:B,priority:0}),h5:()=>({conversion:B,
|
|
13
|
+
priority:0}),h6:()=>({conversion:B,priority:0}),p:c=>{c=c.firstChild;return null!==c&&D(c)?{conversion:()=>({node:null}),priority:3}:null},span:c=>D(c)?{conversion:()=>({node:E("h1")}),priority:3}:null}}static importJSON(c){let b=E(c.tag);b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(c,b=!0){c=c?c.anchor.offset:0;c=0<c&&c<this.getTextContentSize()?E(this.getTag()):
|
|
14
|
+
l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=this.isEmpty()?l.$createParagraphNode():E(this.getTag());this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}extractWithChild(){return!0}}function D(c){return"span"===c.nodeName.toLowerCase()?"26pt"===c.style.fontSize:!1}function B(c){c=c.nodeName.toLowerCase();let b=null;if("h1"===c||"h2"===c||"h3"===c||"h4"===c||"h5"===c||"h6"===c)b=E(c);return{node:b}}
|
|
15
|
+
function y(){return{node:z()}}function E(c){return l.$applyNodeReplacement(new A(c))}function F(c,b){c.preventDefault();b.update(()=>{let d=l.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(l.$isRangeSelection(d)||l.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
|
|
16
|
+
async function G(c,b){await a.copyToClipboard__EXPERIMENTAL(b,c instanceof ClipboardEvent?c:null);b.update(()=>{let d=l.$getSelection();l.$isRangeSelection(d)?d.removeText():l.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}function H(c){let b=null;c instanceof DragEvent?b=c.dataTransfer:c instanceof ClipboardEvent&&(b=c.clipboardData);if(null===b)return[!1,[],!1];var d=b.types;c=d.includes("Files");d=d.includes("text/html")||d.includes("text/plain");return[c,Array.from(b.files),d]}
|
|
17
|
+
function I(c,b){var d=l.$getSelection();if(l.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let f=0;f<d.length;f++){let n=d[f],v=n.getKey();if(e.has(v))continue;let h=k.$getNearestBlockElementAncestorOrThrow(n),C=h.getKey();h.canInsertTab()?(c(n),e.add(v)):h.canIndent()&&!e.has(C)&&(e.add(C),b(h))}}}function J(c){c=l.$getNearestNodeFromDOMNode(c);return l.$isDecoratorNode(c)}exports.$createHeadingNode=E;exports.$createQuoteNode=z;exports.$isHeadingNode=function(c){return c instanceof A};
|
|
18
|
+
exports.$isQuoteNode=function(c){return c instanceof x};exports.DRAG_DROP_PASTE=w;exports.HeadingNode=A;exports.QuoteNode=x;exports.eventFiles=H;
|
|
19
|
+
exports.registerRichText=function(c){return k.mergeRegister(c.registerCommand(l.CLICK_COMMAND,()=>{const b=l.$getSelection();return l.$isNodeSelection(b)?(b.clear(),!0):!1},0),c.registerCommand(l.DELETE_CHARACTER_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteCharacter(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DELETE_WORD_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteWord(b);return!0},l.COMMAND_PRIORITY_EDITOR),
|
|
20
|
+
c.registerCommand(l.DELETE_LINE_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteLine(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,b=>{const d=l.$getSelection();if("string"===typeof b)l.$isRangeSelection(d)?d.insertText(b):l.DEPRECATED_$isGridSelection(d);else{if(!l.$isRangeSelection(d)&&!l.DEPRECATED_$isGridSelection(d))return!1;const e=b.dataTransfer;null!=e?a.$insertDataTransferForRichText(e,d,c):l.$isRangeSelection(d)&&
|
|
21
|
+
(b=b.data)&&d.insertText(b)}return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.FORMAT_TEXT_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.formatText(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.FORMAT_ELEMENT_COMMAND,b=>{var d=l.$getSelection();if(!l.$isRangeSelection(d)&&!l.$isNodeSelection(d))return!1;
|
|
22
|
+
d=d.getNodes();for(const e of d)k.$getNearestBlockElementAncestorOrThrow(e).setFormat(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INSERT_LINE_BREAK_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INDENT_CONTENT_COMMAND,
|
|
23
|
+
()=>{I(()=>{c.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},b=>{const d=b.getIndent();10!==d&&b.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{I(b=>{l.$isTextNode(b)&&(b=b.getTextContent(),"\t"===b[b.length-1]&&c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},b=>{const d=b.getIndent();0!==d&&b.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_UP_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)&&
|
|
24
|
+
!J(b.target)){if(b=d.getNodes(),0<b.length)return b[0].selectPrevious(),!0}else if(l.$isRangeSelection(d)){d=l.$getAdjacentNode(d.focus,!0);if(l.$isDecoratorNode(d)&&!d.isIsolated())return d.selectPrevious(),b.preventDefault(),!0;if(l.$isElementNode(d)&&!d.isInline()&&!d.canBeEmpty())return d.select(),b.preventDefault(),!0}return!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_DOWN_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)){if(b=d.getNodes(),0<b.length)return b[0].selectNext(0,
|
|
25
|
+
0),!0}else if(l.$isRangeSelection(d)){let e=d.focus;if("root"===e.key&&e.offset===l.$getRoot().getChildrenSize())return b.preventDefault(),!0;d=l.$getAdjacentNode(d.focus,!1);if(l.$isDecoratorNode(d)&&!d.isIsolated())return d.selectNext(),b.preventDefault(),!0}return!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_LEFT_COMMAND,b=>{const d=l.$getSelection();if(l.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectPrevious(),!0}return l.$isRangeSelection(d)?
|
|
26
|
+
g.$shouldOverrideDefaultCharacterSelection(d,!0)?(e=b.shiftKey,b.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,b=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!J(b.target)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectNext(0,0),!0}if(!l.$isRangeSelection(d))return!1;e=b.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(b.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),
|
|
27
|
+
c.registerCommand(l.KEY_BACKSPACE_COMMAND,b=>{if(J(b.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();({anchor:b}=d);const e=b.getNode();return d.isCollapsed()&&0===b.offset&&!l.$isRootNode(e)&&0<k.$getNearestBlockElementAncestorOrThrow(e).getIndent()?c.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_DELETE_COMMAND,b=>{if(J(b.target))return!1;const d=
|
|
28
|
+
l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();return c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ENTER_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==b){if((u||t)&&r)return!1;b.preventDefault();if(b.shiftKey)return c.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return c.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ESCAPE_COMMAND,
|
|
29
|
+
()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;c.blur();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DROP_COMMAND,b=>{const [,d]=H(b);if(0<d.length){var e=m(b.clientX,b.clientY);if(null!==e){const {offset:n,node:v}=e;var f=l.$getNearestNodeFromDOMNode(v);if(null!==f){e=l.$createRangeSelection();if(l.$isTextNode(f))e.anchor.set(f.getKey(),n,"text"),e.focus.set(f.getKey(),n,"text");else{const h=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(h,
|
|
30
|
+
f,"element");e.focus.set(h,f,"element")}e=l.$normalizeSelection__EXPERIMENTAL(e);l.$setSelection(e)}c.dispatchCommand(w,d)}b.preventDefault();return!0}b=l.$getSelection();return l.$isRangeSelection(b)?!0:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGSTART_COMMAND,b=>{[b]=H(b);const d=l.$getSelection();return b&&!l.$isRangeSelection(d)?!1:!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGOVER_COMMAND,b=>{var [d]=H(b);const e=l.$getSelection();if(d&&!l.$isRangeSelection(e))return!1;d=
|
|
31
|
+
m(b.clientX,b.clientY);null!==d&&(d=l.$getNearestNodeFromDOMNode(d.node),l.$isDecoratorNode(d)&&b.preventDefault());return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.COPY_COMMAND,b=>{a.copyToClipboard__EXPERIMENTAL(c,b instanceof ClipboardEvent?b:null);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.CUT_COMMAND,b=>{G(b,c);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.PASTE_COMMAND,b=>{const [,d,e]=H(b);if(0<d.length&&!e)return c.dispatchCommand(w,d),!0;const f=l.$getSelection();
|
|
32
|
+
return l.$isRangeSelection(f)||l.DEPRECATED_$isGridSelection(f)?(F(b,c),!0):!1},l.COMMAND_PRIORITY_EDITOR))}
|
package/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare class QuoteNode extends ElementNode {
|
|
|
28
28
|
static importDOM(): DOMConversionMap | null;
|
|
29
29
|
static importJSON(serializedNode: SerializedQuoteNode): QuoteNode;
|
|
30
30
|
exportJSON(): SerializedElementNode;
|
|
31
|
-
insertNewAfter(): ParagraphNode;
|
|
31
|
+
insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ParagraphNode;
|
|
32
32
|
collapseAtStart(): true;
|
|
33
33
|
}
|
|
34
34
|
export declare function $createQuoteNode(): QuoteNode;
|
|
@@ -47,7 +47,7 @@ export declare class HeadingNode extends ElementNode {
|
|
|
47
47
|
static importDOM(): DOMConversionMap | null;
|
|
48
48
|
static importJSON(serializedNode: SerializedHeadingNode): HeadingNode;
|
|
49
49
|
exportJSON(): SerializedHeadingNode;
|
|
50
|
-
insertNewAfter(selection?: RangeSelection): ParagraphNode | HeadingNode;
|
|
50
|
+
insertNewAfter(selection?: RangeSelection, restoreSelection?: boolean): ParagraphNode | HeadingNode;
|
|
51
51
|
collapseAtStart(): true;
|
|
52
52
|
extractWithChild(): boolean;
|
|
53
53
|
}
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.7.0",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.
|
|
14
|
-
"@lexical/selection": "0.
|
|
15
|
-
"@lexical/clipboard": "0.
|
|
16
|
-
"@lexical/utils": "0.
|
|
13
|
+
"lexical": "0.7.0",
|
|
14
|
+
"@lexical/selection": "0.7.0",
|
|
15
|
+
"@lexical/clipboard": "0.7.0",
|
|
16
|
+
"@lexical/utils": "0.7.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|