@lexical/rich-text
Advanced tools
Comparing version 0.6.5 to 0.7.0
@@ -31,3 +31,3 @@ /** @module @lexical/rich-text */ | ||
exportJSON(): SerializedElementNode; | ||
insertNewAfter(): ParagraphNode; | ||
insertNewAfter(_: RangeSelection, restoreSelection?: boolean): ParagraphNode; | ||
collapseAtStart(): true; | ||
@@ -51,3 +51,3 @@ } | ||
exportJSON(): SerializedHeadingNode; | ||
insertNewAfter(selection?: RangeSelection): ParagraphNode | HeadingNode; | ||
insertNewAfter(selection?: RangeSelection, restoreSelection?: boolean): ParagraphNode | HeadingNode; | ||
collapseAtStart(): true; | ||
@@ -54,0 +54,0 @@ extractWithChild(): boolean; |
@@ -129,7 +129,7 @@ /** | ||
insertNewAfter() { | ||
insertNewAfter(_, restoreSelection) { | ||
const newBlock = lexical.$createParagraphNode(); | ||
const direction = this.getDirection(); | ||
newBlock.setDirection(direction); | ||
this.insertAfter(newBlock); | ||
this.insertAfter(newBlock, restoreSelection); | ||
return newBlock; | ||
@@ -269,3 +269,3 @@ } | ||
insertNewAfter(selection) { | ||
insertNewAfter(selection, restoreSelection = true) { | ||
const anchorOffet = selection ? selection.anchor.offset : 0; | ||
@@ -275,3 +275,3 @@ const newElement = anchorOffet > 0 && anchorOffet < this.getTextContentSize() ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode(); | ||
newElement.setDirection(direction); | ||
this.insertAfter(newElement); | ||
this.insertAfter(newElement, restoreSelection); | ||
return newElement; | ||
@@ -409,3 +409,3 @@ } | ||
function isTargetWithinDecorator(target) { | ||
function $isTargetWithinDecorator(target) { | ||
const node = lexical.$getNearestNodeFromDOMNode(target); | ||
@@ -415,2 +415,7 @@ return lexical.$isDecoratorNode(node); | ||
function $isSelectionAtEndOfRoot(selection) { | ||
const focus = selection.focus; | ||
return focus.key === 'root' && focus.offset === lexical.$getRoot().getChildrenSize(); | ||
} | ||
function registerRichText(editor) { | ||
@@ -564,3 +569,3 @@ const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => { | ||
if (lexical.$isNodeSelection(selection) && !isTargetWithinDecorator(event.target)) { | ||
if (lexical.$isNodeSelection(selection) && !$isTargetWithinDecorator(event.target)) { | ||
// If selection is on a node, let's try and move selection | ||
@@ -574,2 +579,14 @@ // back to being a range selection. | ||
} | ||
} else if (lexical.$isRangeSelection(selection)) { | ||
const possibleNode = lexical.$getAdjacentNode(selection.focus, true); | ||
if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated()) { | ||
possibleNode.selectPrevious(); | ||
event.preventDefault(); | ||
return true; | ||
} else if (lexical.$isElementNode(possibleNode) && !possibleNode.isInline() && !possibleNode.canBeEmpty()) { | ||
possibleNode.select(); | ||
event.preventDefault(); | ||
return true; | ||
} | ||
} | ||
@@ -590,2 +607,15 @@ | ||
} | ||
} else if (lexical.$isRangeSelection(selection)) { | ||
if ($isSelectionAtEndOfRoot(selection)) { | ||
event.preventDefault(); | ||
return true; | ||
} | ||
const possibleNode = lexical.$getAdjacentNode(selection.focus, false); | ||
if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated()) { | ||
possibleNode.selectNext(); | ||
event.preventDefault(); | ||
return true; | ||
} | ||
} | ||
@@ -624,3 +654,3 @@ | ||
if (lexical.$isNodeSelection(selection$1) && !isTargetWithinDecorator(event.target)) { | ||
if (lexical.$isNodeSelection(selection$1) && !$isTargetWithinDecorator(event.target)) { | ||
// If selection is on a node, let's try and move selection | ||
@@ -651,3 +681,3 @@ // back to being a range selection. | ||
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => { | ||
if (isTargetWithinDecorator(event.target)) { | ||
if ($isTargetWithinDecorator(event.target)) { | ||
return false; | ||
@@ -678,3 +708,3 @@ } | ||
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => { | ||
if (isTargetWithinDecorator(event.target)) { | ||
if ($isTargetWithinDecorator(event.target)) { | ||
return false; | ||
@@ -718,11 +748,2 @@ } | ||
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND, undefined); | ||
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => { | ||
const selection = lexical.$getSelection(); | ||
if (!lexical.$isRangeSelection(selection)) { | ||
return false; | ||
} | ||
event.preventDefault(); | ||
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined); | ||
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, () => { | ||
@@ -729,0 +750,0 @@ const selection = lexical.$getSelection(); |
@@ -7,26 +7,27 @@ /** | ||
*/ | ||
'use strict';var c=require("@lexical/clipboard"),g=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");function m(b,a){return"undefined"!==typeof document.caretRangeFromPoint?(b=document.caretRangeFromPoint(b,a),null===b?null:{node:b.startContainer,offset:b.startOffset}):"undefined"!==document.caretPositionFromPoint?(b=document.caretPositionFromPoint(b,a),null===b?null:{node:b.offsetNode,offset:b.offset}):null} | ||
'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} | ||
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; | ||
p&&/^(?=.*Chrome).*/i.test(navigator.userAgent);let w=l.createCommand("DRAG_DROP_PASTE_FILE"); | ||
class x extends l.ElementNode{static getType(){return"quote"}static clone(b){return new x(b.__key)}constructor(b){super(b)}createDOM(b){let a=document.createElement("blockquote");k.addClassNamesToElement(a,b.theme.quote);return a}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:y,priority:0})}}static importJSON(b){let a=z();a.setFormat(b.format);a.setIndent(b.indent);a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let b= | ||
l.$createParagraphNode(),a=this.getDirection();b.setDirection(a);this.insertAfter(b);return b}collapseAtStart(){let b=l.$createParagraphNode();this.getChildren().forEach(a=>b.append(a));this.replace(b);return!0}}function z(){return l.$applyNodeReplacement(new x)} | ||
class A extends l.ElementNode{static getType(){return"heading"}static clone(b){return new A(b.__tag,b.__key)}constructor(b,a){super(a);this.__tag=b}getTag(){return this.__tag}createDOM(b){let a=this.__tag,d=document.createElement(a);b=b.theme.heading;void 0!==b&&k.addClassNamesToElement(d,b[a]);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, | ||
priority:0}),h6:()=>({conversion:B,priority:0}),p:b=>{b=b.firstChild;return null!==b&&D(b)?{conversion:()=>({node:null}),priority:3}:null},span:b=>D(b)?{conversion:()=>({node:E("h1")}),priority:3}:null}}static importJSON(b){let a=E(b.tag);a.setFormat(b.format);a.setIndent(b.indent);a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(b){b=b?b.anchor.offset:0;b=0<b&&b<this.getTextContentSize()?E(this.getTag()):l.$createParagraphNode(); | ||
let a=this.getDirection();b.setDirection(a);this.insertAfter(b);return b}collapseAtStart(){let b=this.isEmpty()?l.$createParagraphNode():E(this.getTag());this.getChildren().forEach(a=>b.append(a));this.replace(b);return!0}extractWithChild(){return!0}}function D(b){return"span"===b.nodeName.toLowerCase()?"26pt"===b.style.fontSize:!1}function B(b){b=b.nodeName.toLowerCase();let a=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b||"h6"===b)a=E(b);return{node:a}}function y(){return{node:z()}} | ||
function E(b){return l.$applyNodeReplacement(new A(b))}function F(b,a){b.preventDefault();a.update(()=>{let d=l.$getSelection(),e=b instanceof InputEvent||b instanceof KeyboardEvent?null:b.clipboardData;null!=e&&(l.$isRangeSelection(d)||l.DEPRECATED_$isGridSelection(d))&&c.$insertDataTransferForRichText(e,d,a)},{tag:"paste"})} | ||
async function G(b,a){await c.copyToClipboard__EXPERIMENTAL(a,b instanceof ClipboardEvent?b:null);a.update(()=>{let d=l.$getSelection();l.$isRangeSelection(d)?d.removeText():l.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}function H(b){let a=null;b instanceof DragEvent?a=b.dataTransfer:b instanceof ClipboardEvent&&(a=b.clipboardData);if(null===a)return[!1,[],!1];var d=a.types;b=d.includes("Files");d=d.includes("text/html")||d.includes("text/plain");return[b,Array.from(a.files),d]} | ||
function I(b,a){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()?(b(n),e.add(v)):h.canIndent()&&!e.has(C)&&(e.add(C),a(h))}}}function J(b){b=l.$getNearestNodeFromDOMNode(b);return l.$isDecoratorNode(b)}exports.$createHeadingNode=E;exports.$createQuoteNode=z;exports.$isHeadingNode=function(b){return b instanceof A}; | ||
exports.$isQuoteNode=function(b){return b instanceof x};exports.DRAG_DROP_PASTE=w;exports.HeadingNode=A;exports.QuoteNode=x;exports.eventFiles=H; | ||
exports.registerRichText=function(b){return k.mergeRegister(b.registerCommand(l.CLICK_COMMAND,()=>{const a=l.$getSelection();return l.$isNodeSelection(a)?(a.clear(),!0):!1},0),b.registerCommand(l.DELETE_CHARACTER_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteCharacter(a);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DELETE_WORD_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteWord(a);return!0},l.COMMAND_PRIORITY_EDITOR), | ||
b.registerCommand(l.DELETE_LINE_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteLine(a);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,a=>{const d=l.$getSelection();if("string"===typeof a)l.$isRangeSelection(d)?d.insertText(a):l.DEPRECATED_$isGridSelection(d);else{if(!l.$isRangeSelection(d)&&!l.DEPRECATED_$isGridSelection(d))return!1;const e=a.dataTransfer;null!=e?c.$insertDataTransferForRichText(e,d,b):l.$isRangeSelection(d)&& | ||
(a=a.data)&&d.insertText(a)}return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const a=l.$getSelection();if(!l.$isRangeSelection(a))return!1;a.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.FORMAT_TEXT_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.formatText(a);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.FORMAT_ELEMENT_COMMAND,a=>{var d=l.$getSelection();if(!l.$isRangeSelection(d)&&!l.$isNodeSelection(d))return!1; | ||
d=d.getNodes();for(const e of d)k.$getNearestBlockElementAncestorOrThrow(e).setFormat(a);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_LINE_BREAK_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(a);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const a=l.$getSelection();if(!l.$isRangeSelection(a))return!1;a.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INDENT_CONTENT_COMMAND, | ||
()=>{I(()=>{b.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},a=>{const d=a.getIndent();10!==d&&a.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{I(a=>{l.$isTextNode(a)&&(a=a.getTextContent(),"\t"===a[a.length-1]&&b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},a=>{const d=a.getIndent();0!==d&&a.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_UP_COMMAND,a=>{const d=l.$getSelection();return l.$isNodeSelection(d)&& | ||
!J(a.target)&&(a=d.getNodes(),0<a.length)?(a[0].selectPrevious(),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_DOWN_COMMAND,()=>{var a=l.$getSelection();return l.$isNodeSelection(a)&&(a=a.getNodes(),0<a.length)?(a[0].selectNext(0,0),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_LEFT_COMMAND,a=>{const d=l.$getSelection();if(l.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectPrevious(),!0}return l.$isRangeSelection(d)?g.$shouldOverrideDefaultCharacterSelection(d, | ||
!0)?(e=a.shiftKey,a.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,a=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!J(a.target)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectNext(0,0),!0}if(!l.$isRangeSelection(d))return!1;e=a.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(a.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_BACKSPACE_COMMAND, | ||
a=>{if(J(a.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;a.preventDefault();({anchor:a}=d);const e=a.getNode();return d.isCollapsed()&&0===a.offset&&!l.$isRootNode(e)&&0<k.$getNearestBlockElementAncestorOrThrow(e).getIndent()?b.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_DELETE_COMMAND,a=>{if(J(a.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1; | ||
a.preventDefault();return b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ENTER_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==a){if((u||t)&&r)return!1;a.preventDefault();if(a.shiftKey)return b.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_TAB_COMMAND,a=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1; | ||
a.preventDefault();return b.dispatchCommand(a.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const a=l.$getSelection();if(!l.$isRangeSelection(a))return!1;b.blur();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DROP_COMMAND,a=>{const [,d]=H(a);if(0<d.length){var e=m(a.clientX,a.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,f,"element");e.focus.set(h,f,"element")}e=l.$normalizeSelection__EXPERIMENTAL(e);l.$setSelection(e)}b.dispatchCommand(w,d)}a.preventDefault();return!0}a=l.$getSelection();return l.$isRangeSelection(a)?!0:!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGSTART_COMMAND,a=>{[a]=H(a);const d=l.$getSelection();return a&&!l.$isRangeSelection(d)? | ||
!1:!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGOVER_COMMAND,a=>{var [d]=H(a);const e=l.$getSelection();if(d&&!l.$isRangeSelection(e))return!1;d=m(a.clientX,a.clientY);null!==d&&(d=l.$getNearestNodeFromDOMNode(d.node),l.$isDecoratorNode(d)&&a.preventDefault());return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.COPY_COMMAND,a=>{c.copyToClipboard__EXPERIMENTAL(b,a instanceof ClipboardEvent?a:null);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CUT_COMMAND,a=>{G(a,b);return!0}, | ||
l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.PASTE_COMMAND,a=>{const [,d,e]=H(a);if(0<d.length&&!e)return b.dispatchCommand(w,d),!0;const f=l.$getSelection();return l.$isRangeSelection(f)||l.DEPRECATED_$isGridSelection(f)?(F(a,b),!0):!1},l.COMMAND_PRIORITY_EDITOR))} | ||
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, | ||
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)} | ||
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, | ||
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()): | ||
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}} | ||
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"})} | ||
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]} | ||
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}; | ||
exports.$isQuoteNode=function(c){return c instanceof x};exports.DRAG_DROP_PASTE=w;exports.HeadingNode=A;exports.QuoteNode=x;exports.eventFiles=H; | ||
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), | ||
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)&& | ||
(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; | ||
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, | ||
()=>{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)&& | ||
!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, | ||
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)? | ||
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), | ||
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= | ||
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, | ||
()=>{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, | ||
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= | ||
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(); | ||
return l.$isRangeSelection(f)||l.DEPRECATED_$isGridSelection(f)?(F(b,c),!0):!1},l.COMMAND_PRIORITY_EDITOR))} |
@@ -10,9 +10,9 @@ { | ||
"license": "MIT", | ||
"version": "0.6.5", | ||
"version": "0.7.0", | ||
"main": "LexicalRichText.js", | ||
"peerDependencies": { | ||
"lexical": "0.6.5", | ||
"@lexical/selection": "0.6.5", | ||
"@lexical/clipboard": "0.6.5", | ||
"@lexical/utils": "0.6.5" | ||
"lexical": "0.7.0", | ||
"@lexical/selection": "0.7.0", | ||
"@lexical/clipboard": "0.7.0", | ||
"@lexical/utils": "0.7.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44498
823