183 lines
47 KiB
Diff
183 lines
47 KiB
Diff
diff --git a/LexicalRichText.dev.js b/LexicalRichText.dev.js
|
|
index a3b5c0e76d59f15704819590692a7dac93d41a37..96089d34908e286703d6c008ba1e2d5a8cb77a5a 100644
|
|
--- a/LexicalRichText.dev.js
|
|
+++ b/LexicalRichText.dev.js
|
|
@@ -3,7 +3,9 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
'use strict';
|
|
|
|
var clipboard = require('@lexical/clipboard');
|
|
@@ -411,7 +413,10 @@ function handleIndentAndOutdent(indentOrOutdent) {
|
|
if (alreadyHandled.has(key)) {
|
|
continue;
|
|
}
|
|
- const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(node);
|
|
+ const parentBlock = utils.$findMatchingParent(node, parentNode => lexical.$isElementNode(parentNode) && !parentNode.isInline());
|
|
+ if (parentBlock === null) {
|
|
+ continue;
|
|
+ }
|
|
const parentKey = parentBlock.getKey();
|
|
if (parentBlock.canIndent() && !alreadyHandled.has(parentKey)) {
|
|
alreadyHandled.add(parentKey);
|
|
@@ -469,7 +474,7 @@ function registerRichText(editor) {
|
|
}
|
|
const dataTransfer = eventOrText.dataTransfer;
|
|
if (dataTransfer != null) {
|
|
- clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
+ clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor, eventOrText);
|
|
} else if (lexical.$isRangeSelection(selection)) {
|
|
const data = eventOrText.data;
|
|
if (data) {
|
|
diff --git a/LexicalRichText.dev.mjs b/LexicalRichText.dev.mjs
|
|
index 06552f21b6ac4b0758a35da486c5f7b219d701fe..69e9c7321f09e864e76b14dd89cca95fcd99910c 100644
|
|
--- a/LexicalRichText.dev.mjs
|
|
+++ b/LexicalRichText.dev.mjs
|
|
@@ -3,7 +3,9 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
import { $insertDataTransferForRichText, copyToClipboard } from '@lexical/clipboard';
|
|
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '@lexical/selection';
|
|
import { addClassNamesToElement, isHTMLElement, objectKlassEquals, mergeRegister, $findMatchingParent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
@@ -409,7 +411,10 @@ function handleIndentAndOutdent(indentOrOutdent) {
|
|
if (alreadyHandled.has(key)) {
|
|
continue;
|
|
}
|
|
- const parentBlock = $getNearestBlockElementAncestorOrThrow(node);
|
|
+ const parentBlock = $findMatchingParent(node, parentNode => $isElementNode(parentNode) && !parentNode.isInline());
|
|
+ if (parentBlock === null) {
|
|
+ continue;
|
|
+ }
|
|
const parentKey = parentBlock.getKey();
|
|
if (parentBlock.canIndent() && !alreadyHandled.has(parentKey)) {
|
|
alreadyHandled.add(parentKey);
|
|
@@ -467,7 +472,7 @@ function registerRichText(editor) {
|
|
}
|
|
const dataTransfer = eventOrText.dataTransfer;
|
|
if (dataTransfer != null) {
|
|
- $insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
+ $insertDataTransferForRichText(dataTransfer, selection, editor, eventOrText);
|
|
} else if ($isRangeSelection(selection)) {
|
|
const data = eventOrText.data;
|
|
if (data) {
|
|
diff --git a/LexicalRichText.js b/LexicalRichText.js
|
|
index 122ed25dc87e94acbd2af57519aee75aae357475..adf85437f4369491d0260b8a20de4ee3d52af214 100644
|
|
--- a/LexicalRichText.js
|
|
+++ b/LexicalRichText.js
|
|
@@ -3,7 +3,9 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
'use strict'
|
|
const LexicalRichText = process.env.NODE_ENV === 'development' ? require('./LexicalRichText.dev.js') : require('./LexicalRichText.prod.js');
|
|
module.exports = LexicalRichText;
|
|
\ No newline at end of file
|
|
diff --git a/LexicalRichText.mjs b/LexicalRichText.mjs
|
|
index a662073c786ddee88068585cb780882fa9a54b95..2d88655cd657da5a0d593796e62e3523bd853e8a 100644
|
|
--- a/LexicalRichText.mjs
|
|
+++ b/LexicalRichText.mjs
|
|
@@ -3,7 +3,9 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
import * as modDev from './LexicalRichText.dev.mjs';
|
|
import * as modProd from './LexicalRichText.prod.mjs';
|
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
diff --git a/LexicalRichText.node.mjs b/LexicalRichText.node.mjs
|
|
index cac1a134ac8633f222f7b36c9e40f495e22d2a85..19516e418bacb5e5ae218d6dd72cd4ef5a714ab8 100644
|
|
--- a/LexicalRichText.node.mjs
|
|
+++ b/LexicalRichText.node.mjs
|
|
@@ -3,7 +3,9 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalRichText.dev.mjs') : import('./LexicalRichText.prod.mjs'));
|
|
export const $createHeadingNode = mod.$createHeadingNode;
|
|
export const $createQuoteNode = mod.$createQuoteNode;
|
|
diff --git a/LexicalRichText.prod.js b/LexicalRichText.prod.js
|
|
index 2c24e0de17ab5435322614bd3d34c2583ef368b6..db5738ab58ce426bd04a53dc8148c0b34c715ea4 100644
|
|
--- a/LexicalRichText.prod.js
|
|
+++ b/LexicalRichText.prod.js
|
|
@@ -3,30 +3,32 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
+
|
|
'use strict';var c=require("@lexical/clipboard"),g=require("@lexical/selection"),h=require("@lexical/utils"),k=require("lexical");function l(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}
|
|
let n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,p=n&&"documentMode"in document?document.documentMode:null;n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
-let q=n&&"InputEvent"in window&&!p?"getTargetRanges"in new window.InputEvent("input"):!1,r=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),t=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=n&&/Android/.test(navigator.userAgent),v=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent);n&&u&&v;let w=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!v,x=k.createCommand("DRAG_DROP_PASTE_FILE");
|
|
-class y extends k.ElementNode{static getType(){return"quote"}static clone(b){return new y(b.__key)}constructor(b){super(b)}createDOM(b){let a=document.createElement("blockquote");h.addClassNamesToElement(a,b.theme.quote);return a}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:z,priority:0})}}exportDOM(b){({element:b}=super.exportDOM(b));if(b&&h.isHTMLElement(b)){this.isEmpty()&&b.append(document.createElement("br"));var a=this.getFormatType();b.style.textAlign=a;if(a=this.getDirection())b.dir=
|
|
-a}return{element:b}}static importJSON(b){let a=A();a.setFormat(b.format);a.setIndent(b.indent);a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(b,a){b=k.$createParagraphNode();let d=this.getDirection();b.setDirection(d);this.insertAfter(b,a);return b}collapseAtStart(){let b=k.$createParagraphNode();this.getChildren().forEach(a=>b.append(a));this.replace(b);return!0}}function A(){return k.$applyNodeReplacement(new y)}
|
|
-class C extends k.ElementNode{static getType(){return"heading"}static clone(b){return new C(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&&h.addClassNamesToElement(d,b[a]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:D,priority:0}),h2:()=>({conversion:D,priority:0}),h3:()=>({conversion:D,priority:0}),h4:()=>({conversion:D,priority:0}),h5:()=>({conversion:D,
|
|
-priority:0}),h6:()=>({conversion:D,priority:0}),p:b=>{b=b.firstChild;return null!==b&&E(b)?{conversion:()=>({node:null}),priority:3}:null},span:b=>E(b)?{conversion:()=>({node:F("h1")}),priority:3}:null}}exportDOM(b){({element:b}=super.exportDOM(b));if(b&&h.isHTMLElement(b)){this.isEmpty()&&b.append(document.createElement("br"));var a=this.getFormatType();b.style.textAlign=a;if(a=this.getDirection())b.dir=a}return{element:b}}static importJSON(b){let a=F(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,a=!0){let d=b?b.anchor.offset:0,e=d!==this.getTextContentSize()&&b?F(this.getTag()):k.$createParagraphNode(),f=this.getDirection();e.setDirection(f);this.insertAfter(e,a);0===d&&!this.isEmpty()&&b&&(b=k.$createParagraphNode(),b.select(),this.replace(b,!0));return e}collapseAtStart(){let b=this.isEmpty()?k.$createParagraphNode():F(this.getTag());this.getChildren().forEach(a=>
|
|
-b.append(a));this.replace(b);return!0}extractWithChild(){return!0}}function E(b){return"span"===b.nodeName.toLowerCase()?"26pt"===b.style.fontSize:!1}function D(b){let a=b.nodeName.toLowerCase(),d=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)d=F(a),null!==b.style&&d.setFormat(b.style.textAlign);return{node:d}}function z(b){let a=A();null!==b.style&&a.setFormat(b.style.textAlign);return{node:a}}function F(b){return k.$applyNodeReplacement(new C(b))}
|
|
-function G(b,a){b.preventDefault();a.update(()=>{let d=k.$getSelection(),e=h.objectKlassEquals(b,InputEvent)||h.objectKlassEquals(b,KeyboardEvent)?null:b.clipboardData;null!=e&&null!==d&&c.$insertDataTransferForRichText(e,d,a)},{tag:"paste"})}async function H(b,a){await c.copyToClipboard(a,h.objectKlassEquals(b,ClipboardEvent)?b:null);a.update(()=>{let d=k.$getSelection();k.$isRangeSelection(d)?d.removeText():k.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}
|
|
-function I(b){let a=null;h.objectKlassEquals(b,DragEvent)?a=b.dataTransfer:h.objectKlassEquals(b,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 J(b){var a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;let d=new Set;a=a.getNodes();for(let m=0;m<a.length;m++){var e=a[m],f=e.getKey();d.has(f)||(e=h.$getNearestBlockElementAncestorOrThrow(e),f=e.getKey(),e.canIndent()&&!d.has(f)&&(d.add(f),b(e)))}return 0<d.size}function K(b){b=k.$getNearestNodeFromDOMNode(b);return k.$isDecoratorNode(b)}exports.$createHeadingNode=F;exports.$createQuoteNode=A;exports.$isHeadingNode=function(b){return b instanceof C};
|
|
-exports.$isQuoteNode=function(b){return b instanceof y};exports.DRAG_DROP_PASTE=x;exports.HeadingNode=C;exports.QuoteNode=y;exports.eventFiles=I;
|
|
+let q=n&&"InputEvent"in window&&!p?"getTargetRanges"in new window.InputEvent("input"):!1,r=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),t=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,v=n&&/Android/.test(navigator.userAgent),w=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent);n&&v&&w;let x=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!w,y=k.createCommand("DRAG_DROP_PASTE_FILE");
|
|
+class z extends k.ElementNode{static getType(){return"quote"}static clone(b){return new z(b.__key)}constructor(b){super(b)}createDOM(b){let a=document.createElement("blockquote");h.addClassNamesToElement(a,b.theme.quote);return a}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:A,priority:0})}}exportDOM(b){({element:b}=super.exportDOM(b));if(b&&h.isHTMLElement(b)){this.isEmpty()&&b.append(document.createElement("br"));var a=this.getFormatType();b.style.textAlign=a;if(a=this.getDirection())b.dir=
|
|
+a}return{element:b}}static importJSON(b){let a=B();a.setFormat(b.format);a.setIndent(b.indent);a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(b,a){b=k.$createParagraphNode();let d=this.getDirection();b.setDirection(d);this.insertAfter(b,a);return b}collapseAtStart(){let b=k.$createParagraphNode();this.getChildren().forEach(a=>b.append(a));this.replace(b);return!0}}function B(){return k.$applyNodeReplacement(new z)}
|
|
+class D extends k.ElementNode{static getType(){return"heading"}static clone(b){return new D(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&&h.addClassNamesToElement(d,b[a]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:E,priority:0}),h2:()=>({conversion:E,priority:0}),h3:()=>({conversion:E,priority:0}),h4:()=>({conversion:E,priority:0}),h5:()=>({conversion:E,
|
|
+priority:0}),h6:()=>({conversion:E,priority:0}),p:b=>{b=b.firstChild;return null!==b&&F(b)?{conversion:()=>({node:null}),priority:3}:null},span:b=>F(b)?{conversion:()=>({node:G("h1")}),priority:3}:null}}exportDOM(b){({element:b}=super.exportDOM(b));if(b&&h.isHTMLElement(b)){this.isEmpty()&&b.append(document.createElement("br"));var a=this.getFormatType();b.style.textAlign=a;if(a=this.getDirection())b.dir=a}return{element:b}}static importJSON(b){let a=G(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,a=!0){let d=b?b.anchor.offset:0,e=d!==this.getTextContentSize()&&b?G(this.getTag()):k.$createParagraphNode(),f=this.getDirection();e.setDirection(f);this.insertAfter(e,a);0===d&&!this.isEmpty()&&b&&(b=k.$createParagraphNode(),b.select(),this.replace(b,!0));return e}collapseAtStart(){let b=this.isEmpty()?k.$createParagraphNode():G(this.getTag());this.getChildren().forEach(a=>
|
|
+b.append(a));this.replace(b);return!0}extractWithChild(){return!0}}function F(b){return"span"===b.nodeName.toLowerCase()?"26pt"===b.style.fontSize:!1}function E(b){let a=b.nodeName.toLowerCase(),d=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)d=G(a),null!==b.style&&d.setFormat(b.style.textAlign);return{node:d}}function A(b){let a=B();null!==b.style&&a.setFormat(b.style.textAlign);return{node:a}}function G(b){return k.$applyNodeReplacement(new D(b))}
|
|
+function H(b,a){b.preventDefault();a.update(()=>{let d=k.$getSelection(),e=h.objectKlassEquals(b,InputEvent)||h.objectKlassEquals(b,KeyboardEvent)?null:b.clipboardData;null!=e&&null!==d&&c.$insertDataTransferForRichText(e,d,a)},{tag:"paste"})}async function I(b,a){await c.copyToClipboard(a,h.objectKlassEquals(b,ClipboardEvent)?b:null);a.update(()=>{let d=k.$getSelection();k.$isRangeSelection(d)?d.removeText():k.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}
|
|
+function J(b){let a=null;h.objectKlassEquals(b,DragEvent)?a=b.dataTransfer:h.objectKlassEquals(b,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 K(b){var a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;let d=new Set;a=a.getNodes();for(let m=0;m<a.length;m++){var e=a[m],f=e.getKey();d.has(f)||(e=h.$findMatchingParent(e,u=>k.$isElementNode(u)&&!u.isInline()),null!==e&&(f=e.getKey(),e.canIndent()&&!d.has(f)&&(d.add(f),b(e))))}return 0<d.size}function L(b){b=k.$getNearestNodeFromDOMNode(b);return k.$isDecoratorNode(b)}exports.$createHeadingNode=G;exports.$createQuoteNode=B;
|
|
+exports.$isHeadingNode=function(b){return b instanceof D};exports.$isQuoteNode=function(b){return b instanceof z};exports.DRAG_DROP_PASTE=y;exports.HeadingNode=D;exports.QuoteNode=z;exports.eventFiles=J;
|
|
exports.registerRichText=function(b){return h.mergeRegister(b.registerCommand(k.CLICK_COMMAND,()=>{const a=k.$getSelection();return k.$isNodeSelection(a)?(a.clear(),!0):!1},0),b.registerCommand(k.DELETE_CHARACTER_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteCharacter(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DELETE_WORD_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteWord(a);return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
-b.registerCommand(k.DELETE_LINE_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteLine(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CONTROLLED_TEXT_INSERTION_COMMAND,a=>{const d=k.$getSelection();if("string"===typeof a)null!==d&&d.insertText(a);else{if(null===d)return!1;const e=a.dataTransfer;null!=e?c.$insertDataTransferForRichText(e,d,b):k.$isRangeSelection(d)&&(a=a.data)&&d.insertText(a)}return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.REMOVE_TEXT_COMMAND,
|
|
+b.registerCommand(k.DELETE_LINE_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteLine(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CONTROLLED_TEXT_INSERTION_COMMAND,a=>{const d=k.$getSelection();if("string"===typeof a)null!==d&&d.insertText(a);else{if(null===d)return!1;const e=a.dataTransfer;null!=e?c.$insertDataTransferForRichText(e,d,b,a):k.$isRangeSelection(d)&&(a=a.data)&&d.insertText(a)}return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.REMOVE_TEXT_COMMAND,
|
|
()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;a.removeText();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.FORMAT_TEXT_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.formatText(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.FORMAT_ELEMENT_COMMAND,a=>{var d=k.$getSelection();if(!k.$isRangeSelection(d)&&!k.$isNodeSelection(d))return!1;d=d.getNodes();for(const e of d)d=h.$findMatchingParent(e,f=>k.$isElementNode(f)&&!f.isInline()),
|
|
null!==d&&d.setFormat(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_LINE_BREAK_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.insertLineBreak(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_PARAGRAPH_COMMAND,()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;a.insertParagraph();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_TAB_COMMAND,()=>{k.$insertNodes([k.$createTabNode()]);return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
-b.registerCommand(k.INDENT_CONTENT_COMMAND,()=>J(a=>{const d=a.getIndent();a.setIndent(d+1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.OUTDENT_CONTENT_COMMAND,()=>J(a=>{const d=a.getIndent();0<d&&a.setIndent(d-1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_UP_COMMAND,a=>{var d=k.$getSelection();if(k.$isNodeSelection(d)&&!K(a.target)){if(a=d.getNodes(),0<a.length)return a[0].selectPrevious(),!0}else if(k.$isRangeSelection(d)&&(d=k.$getAdjacentNode(d.focus,!0),!a.shiftKey&&k.$isDecoratorNode(d)&&
|
|
+b.registerCommand(k.INDENT_CONTENT_COMMAND,()=>K(a=>{const d=a.getIndent();a.setIndent(d+1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.OUTDENT_CONTENT_COMMAND,()=>K(a=>{const d=a.getIndent();0<d&&a.setIndent(d-1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_UP_COMMAND,a=>{var d=k.$getSelection();if(k.$isNodeSelection(d)&&!L(a.target)){if(a=d.getNodes(),0<a.length)return a[0].selectPrevious(),!0}else if(k.$isRangeSelection(d)&&(d=k.$getAdjacentNode(d.focus,!0),!a.shiftKey&&k.$isDecoratorNode(d)&&
|
|
!d.isIsolated()&&!d.isInline()))return d.selectPrevious(),a.preventDefault(),!0;return!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_DOWN_COMMAND,a=>{var d=k.$getSelection();if(k.$isNodeSelection(d)){if(a=d.getNodes(),0<a.length)return a[0].selectNext(0,0),!0}else if(k.$isRangeSelection(d)){let e=d.focus;if("root"===e.key&&e.offset===k.$getRoot().getChildrenSize())return a.preventDefault(),!0;d=k.$getAdjacentNode(d.focus,!1);if(!a.shiftKey&&k.$isDecoratorNode(d)&&!d.isIsolated()&&!d.isInline())return d.selectNext(),
|
|
a.preventDefault(),!0}return!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_LEFT_COMMAND,a=>{const d=k.$getSelection();if(k.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectPrevious(),!0}return k.$isRangeSelection(d)?g.$shouldOverrideDefaultCharacterSelection(d,!0)?(e=a.shiftKey,a.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_RIGHT_COMMAND,a=>{const d=k.$getSelection();if(k.$isNodeSelection(d)&&
|
|
-!K(a.target)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectNext(0,0),!0}if(!k.$isRangeSelection(d))return!1;e=a.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(a.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_BACKSPACE_COMMAND,a=>{if(K(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();({anchor:a}=d);const e=a.getNode();return d.isCollapsed()&&0===a.offset&&
|
|
-!k.$isRootNode(e)&&0<h.$getNearestBlockElementAncestorOrThrow(e).getIndent()?b.dispatchCommand(k.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_DELETE_COMMAND,a=>{if(K(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();return b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!1)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ENTER_COMMAND,a=>{const d=k.$getSelection();
|
|
-if(!k.$isRangeSelection(d))return!1;if(null!==a){if((t||r||w)&&q)return!1;a.preventDefault();if(a.shiftKey)return b.dispatchCommand(k.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(k.INSERT_PARAGRAPH_COMMAND,void 0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ESCAPE_COMMAND,()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;b.blur();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DROP_COMMAND,a=>{const [,d]=I(a);if(0<d.length){var e=l(a.clientX,a.clientY);
|
|
-if(null!==e){const {offset:m,node:L}=e;var f=k.$getNearestNodeFromDOMNode(L);if(null!==f){e=k.$createRangeSelection();if(k.$isTextNode(f))e.anchor.set(f.getKey(),m,"text"),e.focus.set(f.getKey(),m,"text");else{const B=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(B,f,"element");e.focus.set(B,f,"element")}e=k.$normalizeSelection__EXPERIMENTAL(e);k.$setSelection(e)}b.dispatchCommand(x,d)}a.preventDefault();return!0}a=k.$getSelection();return k.$isRangeSelection(a)?!0:!1},k.COMMAND_PRIORITY_EDITOR),
|
|
-b.registerCommand(k.DRAGSTART_COMMAND,a=>{[a]=I(a);const d=k.$getSelection();return a&&!k.$isRangeSelection(d)?!1:!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DRAGOVER_COMMAND,a=>{var [d]=I(a);const e=k.$getSelection();if(d&&!k.$isRangeSelection(e))return!1;d=l(a.clientX,a.clientY);null!==d&&(d=k.$getNearestNodeFromDOMNode(d.node),k.$isDecoratorNode(d)&&a.preventDefault());return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.SELECT_ALL_COMMAND,()=>{k.$selectAll();return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
-b.registerCommand(k.COPY_COMMAND,a=>{c.copyToClipboard(b,h.objectKlassEquals(a,ClipboardEvent)?a:null);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CUT_COMMAND,a=>{H(a,b);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.PASTE_COMMAND,a=>{const [,d,e]=I(a);return 0<d.length&&!e?(b.dispatchCommand(x,d),!0):k.isSelectionCapturedInDecoratorInput(a.target)?!1:null!==k.$getSelection()?(G(a,b),!0):!1},k.COMMAND_PRIORITY_EDITOR))}
|
|
+!L(a.target)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectNext(0,0),!0}if(!k.$isRangeSelection(d))return!1;e=a.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(a.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_BACKSPACE_COMMAND,a=>{if(L(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();({anchor:a}=d);const e=a.getNode();return d.isCollapsed()&&0===a.offset&&
|
|
+!k.$isRootNode(e)&&0<h.$getNearestBlockElementAncestorOrThrow(e).getIndent()?b.dispatchCommand(k.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_DELETE_COMMAND,a=>{if(L(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();return b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!1)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ENTER_COMMAND,a=>{const d=k.$getSelection();
|
|
+if(!k.$isRangeSelection(d))return!1;if(null!==a){if((t||r||x)&&q)return!1;a.preventDefault();if(a.shiftKey)return b.dispatchCommand(k.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(k.INSERT_PARAGRAPH_COMMAND,void 0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ESCAPE_COMMAND,()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;b.blur();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DROP_COMMAND,a=>{const [,d]=J(a);if(0<d.length){var e=l(a.clientX,a.clientY);
|
|
+if(null!==e){const {offset:m,node:u}=e;var f=k.$getNearestNodeFromDOMNode(u);if(null!==f){e=k.$createRangeSelection();if(k.$isTextNode(f))e.anchor.set(f.getKey(),m,"text"),e.focus.set(f.getKey(),m,"text");else{const C=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(C,f,"element");e.focus.set(C,f,"element")}e=k.$normalizeSelection__EXPERIMENTAL(e);k.$setSelection(e)}b.dispatchCommand(y,d)}a.preventDefault();return!0}a=k.$getSelection();return k.$isRangeSelection(a)?!0:!1},k.COMMAND_PRIORITY_EDITOR),
|
|
+b.registerCommand(k.DRAGSTART_COMMAND,a=>{[a]=J(a);const d=k.$getSelection();return a&&!k.$isRangeSelection(d)?!1:!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DRAGOVER_COMMAND,a=>{var [d]=J(a);const e=k.$getSelection();if(d&&!k.$isRangeSelection(e))return!1;d=l(a.clientX,a.clientY);null!==d&&(d=k.$getNearestNodeFromDOMNode(d.node),k.$isDecoratorNode(d)&&a.preventDefault());return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.SELECT_ALL_COMMAND,()=>{k.$selectAll();return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
+b.registerCommand(k.COPY_COMMAND,a=>{c.copyToClipboard(b,h.objectKlassEquals(a,ClipboardEvent)?a:null);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CUT_COMMAND,a=>{I(a,b);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.PASTE_COMMAND,a=>{const [,d,e]=J(a);return 0<d.length&&!e?(b.dispatchCommand(y,d),!0):k.isSelectionCapturedInDecoratorInput(a.target)?!1:null!==k.$getSelection()?(H(a,b),!0):!1},k.COMMAND_PRIORITY_EDITOR))}
|
|
diff --git a/LexicalRichText.prod.mjs b/LexicalRichText.prod.mjs
|
|
index bff5a184ddf85e2f70e5f64b6981fadd3ea60ec3..937b15cf9e911d9bc884d7de96a00be45ee5d9c5 100644
|
|
--- a/LexicalRichText.prod.mjs
|
|
+++ b/LexicalRichText.prod.mjs
|
|
@@ -3,5 +3,7 @@
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
+ *
|
|
*/
|
|
-import{$insertDataTransferForRichText as t,copyToClipboard as e}from"@lexical/clipboard";import{$shouldOverrideDefaultCharacterSelection as n,$moveCharacter as r}from"@lexical/selection";import{addClassNamesToElement as o,isHTMLElement as i,objectKlassEquals as s,mergeRegister as a,$findMatchingParent as c,$getNearestBlockElementAncestorOrThrow as u}from"@lexical/utils";import{createCommand as l,ElementNode as d,$applyNodeReplacement as m,$createParagraphNode as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as v,$isRangeSelection as C,COMMAND_PRIORITY_EDITOR as y,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as x,CONTROLLED_TEXT_INSERTION_COMMAND as w,REMOVE_TEXT_COMMAND as E,FORMAT_TEXT_COMMAND as N,FORMAT_ELEMENT_COMMAND as A,$isElementNode as P,INSERT_LINE_BREAK_COMMAND as O,INSERT_PARAGRAPH_COMMAND as T,INSERT_TAB_COMMAND as I,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as F,OUTDENT_CONTENT_COMMAND as M,KEY_ARROW_UP_COMMAND as b,$isDecoratorNode as K,$getAdjacentNode as k,KEY_ARROW_DOWN_COMMAND as J,$getRoot as q,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as R,KEY_BACKSPACE_COMMAND as z,$isRootNode as W,KEY_DELETE_COMMAND as X,KEY_ENTER_COMMAND as Y,KEY_ESCAPE_COMMAND as B,DROP_COMMAND as G,$getNearestNodeFromDOMNode as V,$createRangeSelection as j,$isTextNode as H,$normalizeSelection__EXPERIMENTAL as Q,$setSelection as U,DRAGSTART_COMMAND as Z,DRAGOVER_COMMAND as $,SELECT_ALL_COMMAND as tt,$selectAll as et,COPY_COMMAND as nt,CUT_COMMAND as rt,PASTE_COMMAND as ot,isSelectionCapturedInDecoratorInput as it}from"lexical";function st(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const at="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ct=at&&"documentMode"in document?document.documentMode:null;at&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),at&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);const ut=!(!at||!("InputEvent"in window)||ct)&&"getTargetRanges"in new window.InputEvent("input"),lt=at&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),dt=at&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,mt=(at&&/Android/.test(navigator.userAgent),at&&/^(?=.*Chrome).*/i.test(navigator.userAgent)),ft=at&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!mt,gt=l("DRAG_DROP_PASTE_FILE");class pt extends d{static getType(){return"quote"}static clone(t){return new pt(t.__key)}constructor(t){super(t)}createDOM(t){const e=document.createElement("blockquote");return o(e,t.theme.quote),e}updateDOM(t,e){return!1}static importDOM(){return{blockquote:t=>({conversion:xt,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=ht();return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(t,e){const n=f(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=f();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return m(new pt)}function vt(t){return t instanceof pt}class Ct extends d{static getType(){return"heading"}static clone(t){return new Ct(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t}getTag(){return this.__tag}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];o(n,t)}return n}updateDOM(t,e){return!1}static importDOM(){return{h1:t=>({conversion:Dt,priority:0}),h2:t=>({conversion:Dt,priority:0}),h3:t=>({conversion:Dt,priority:0}),h4:t=>({conversion:Dt,priority:0}),h5:t=>({conversion:Dt,priority:0}),h6:t=>({conversion:Dt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&yt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>yt(t)?{conversion:t=>({node:wt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=wt(t.tag);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=n!==this.getTextContentSize()&&t?wt(this.getTag()):f(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=f();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?f():wt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return!0}}function yt(t){return"span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Dt(t){const e=t.nodeName.toLowerCase();let n=null;return"h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=wt(e),null!==t.style&&n.setFormat(t.style.textAlign)),{node:n}}function xt(t){const e=ht();return null!==t.style&&e.setFormat(t.style.textAlign),{node:e}}function wt(t){return m(new Ct(t))}function Et(t){return t instanceof Ct}function Nt(t){let e=null;if(s(t,DragEvent)?e=t.dataTransfer:s(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(e.files),o]}function At(t){const e=p();if(!C(e))return!1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=u(o),a=s.getKey();s.canIndent()&&!n.has(a)&&(n.add(a),t(s))}return n.size>0}function Pt(t){const e=V(t);return K(e)}function Ot(o){return a(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(v,(t=>{const e=p();return!!C(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!C(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!C(e)&&(e.deleteLine(t),!0)}),y),o.registerCommand(w,(e=>{const n=p();if("string"==typeof e)null!==n&&n.insertText(e);else{if(null===n)return!1;const r=e.dataTransfer;if(null!=r)t(r,n,o);else if(C(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!C(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!C(e)&&(e.formatText(t),!0)}),y),o.registerCommand(A,(t=>{const e=p();if(!C(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=c(e,(t=>P(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(O,(t=>{const e=p();return!!C(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(T,(()=>{const t=p();return!!C(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(I,(()=>(S([_()]),!0)),y),o.registerCommand(F,(()=>At((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(M,(()=>At((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(b,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(C(e)){const n=k(e.focus,!0);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return!1}),y),o.registerCommand(J,(t=>{const e=p();if(h(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if(C(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===q().getChildrenSize()}(e))return t.preventDefault(),!0;const n=k(e.focus,!1);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!C(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(R,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!C(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(z,(t=>{if(Pt(t.target))return!1;const e=p();if(!C(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!W(r)){if(u(r).getIndent()>0)return o.dispatchCommand(M,void 0)}return o.dispatchCommand(v,!0)}),y),o.registerCommand(X,(t=>{if(Pt(t.target))return!1;const e=p();return!!C(e)&&(t.preventDefault(),o.dispatchCommand(v,!1))}),y),o.registerCommand(Y,(t=>{const e=p();if(!C(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(O,!1)}return o.dispatchCommand(T,void 0)}),y),o.registerCommand(B,(()=>{const t=p();return!!C(t)&&(o.blur(),!0)}),y),o.registerCommand(G,(t=>{const[,e]=Nt(t);if(e.length>0){const n=st(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,i=V(r);if(null!==i){const e=j();if(H(i))e.anchor.set(i.getKey(),t,"text"),e.focus.set(i.getKey(),t,"text");else{const t=i.getParentOrThrow().getKey(),n=i.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element")}const n=Q(e);U(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!C(n)}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();return!(e&&!C(n))}),y),o.registerCommand($,(t=>{const[e]=Nt(t),n=p();if(e&&!C(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=V(r.node);K(e)&&t.preventDefault()}return!0}),y),o.registerCommand(tt,(()=>(et(),!0)),y),o.registerCommand(nt,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(rt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();C(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(ot,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(it(e.target))return!1;return null!==p()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=p(),o=s(e,InputEvent)||s(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&t(o,r,n)}),{tag:"paste"})}(e,o),!0)}),y))}export{wt as $createHeadingNode,ht as $createQuoteNode,Et as $isHeadingNode,vt as $isQuoteNode,gt as DRAG_DROP_PASTE,Ct as HeadingNode,pt as QuoteNode,Nt as eventFiles,Ot as registerRichText};
|
|
+
|
|
+import{$insertDataTransferForRichText as t,copyToClipboard as e}from"@lexical/clipboard";import{$shouldOverrideDefaultCharacterSelection as n,$moveCharacter as r}from"@lexical/selection";import{addClassNamesToElement as o,isHTMLElement as i,objectKlassEquals as s,mergeRegister as c,$findMatchingParent as a,$getNearestBlockElementAncestorOrThrow as u}from"@lexical/utils";import{createCommand as l,ElementNode as d,$applyNodeReplacement as m,$createParagraphNode as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as v,$isRangeSelection as C,COMMAND_PRIORITY_EDITOR as y,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as x,CONTROLLED_TEXT_INSERTION_COMMAND as w,REMOVE_TEXT_COMMAND as E,FORMAT_TEXT_COMMAND as N,FORMAT_ELEMENT_COMMAND as A,$isElementNode as P,INSERT_LINE_BREAK_COMMAND as I,INSERT_PARAGRAPH_COMMAND as O,INSERT_TAB_COMMAND as T,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as F,OUTDENT_CONTENT_COMMAND as M,KEY_ARROW_UP_COMMAND as b,$isDecoratorNode as K,$getAdjacentNode as k,KEY_ARROW_DOWN_COMMAND as J,$getRoot as q,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as R,KEY_BACKSPACE_COMMAND as z,$isRootNode as W,KEY_DELETE_COMMAND as X,KEY_ENTER_COMMAND as Y,KEY_ESCAPE_COMMAND as B,DROP_COMMAND as G,$getNearestNodeFromDOMNode as V,$createRangeSelection as j,$isTextNode as H,$normalizeSelection__EXPERIMENTAL as Q,$setSelection as U,DRAGSTART_COMMAND as Z,DRAGOVER_COMMAND as $,SELECT_ALL_COMMAND as tt,$selectAll as et,COPY_COMMAND as nt,CUT_COMMAND as rt,PASTE_COMMAND as ot,isSelectionCapturedInDecoratorInput as it}from"lexical";function st(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const ct="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,at=ct&&"documentMode"in document?document.documentMode:null;ct&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),ct&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);const ut=!(!ct||!("InputEvent"in window)||at)&&"getTargetRanges"in new window.InputEvent("input"),lt=ct&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),dt=ct&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,mt=(ct&&/Android/.test(navigator.userAgent),ct&&/^(?=.*Chrome).*/i.test(navigator.userAgent)),ft=ct&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!mt,gt=l("DRAG_DROP_PASTE_FILE");class pt extends d{static getType(){return"quote"}static clone(t){return new pt(t.__key)}constructor(t){super(t)}createDOM(t){const e=document.createElement("blockquote");return o(e,t.theme.quote),e}updateDOM(t,e){return!1}static importDOM(){return{blockquote:t=>({conversion:xt,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=ht();return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(t,e){const n=f(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=f();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return m(new pt)}function vt(t){return t instanceof pt}class Ct extends d{static getType(){return"heading"}static clone(t){return new Ct(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t}getTag(){return this.__tag}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];o(n,t)}return n}updateDOM(t,e){return!1}static importDOM(){return{h1:t=>({conversion:Dt,priority:0}),h2:t=>({conversion:Dt,priority:0}),h3:t=>({conversion:Dt,priority:0}),h4:t=>({conversion:Dt,priority:0}),h5:t=>({conversion:Dt,priority:0}),h6:t=>({conversion:Dt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&yt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>yt(t)?{conversion:t=>({node:wt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=wt(t.tag);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=n!==this.getTextContentSize()&&t?wt(this.getTag()):f(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=f();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?f():wt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return!0}}function yt(t){return"span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Dt(t){const e=t.nodeName.toLowerCase();let n=null;return"h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=wt(e),null!==t.style&&n.setFormat(t.style.textAlign)),{node:n}}function xt(t){const e=ht();return null!==t.style&&e.setFormat(t.style.textAlign),{node:e}}function wt(t){return m(new Ct(t))}function Et(t){return t instanceof Ct}function Nt(t){let e=null;if(s(t,DragEvent)?e=t.dataTransfer:s(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(e.files),o]}function At(t){const e=p();if(!C(e))return!1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=a(o,(t=>P(t)&&!t.isInline()));if(null===s)continue;const c=s.getKey();s.canIndent()&&!n.has(c)&&(n.add(c),t(s))}return n.size>0}function Pt(t){const e=V(t);return K(e)}function It(o){return c(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(v,(t=>{const e=p();return!!C(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!C(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!C(e)&&(e.deleteLine(t),!0)}),y),o.registerCommand(w,(e=>{const n=p();if("string"==typeof e)null!==n&&n.insertText(e);else{if(null===n)return!1;const r=e.dataTransfer;if(null!=r)t(r,n,o,e);else if(C(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!C(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!C(e)&&(e.formatText(t),!0)}),y),o.registerCommand(A,(t=>{const e=p();if(!C(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=a(e,(t=>P(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(I,(t=>{const e=p();return!!C(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(O,(()=>{const t=p();return!!C(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(T,(()=>(S([_()]),!0)),y),o.registerCommand(F,(()=>At((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(M,(()=>At((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(b,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(C(e)){const n=k(e.focus,!0);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return!1}),y),o.registerCommand(J,(t=>{const e=p();if(h(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if(C(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===q().getChildrenSize()}(e))return t.preventDefault(),!0;const n=k(e.focus,!1);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!C(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(R,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!C(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(z,(t=>{if(Pt(t.target))return!1;const e=p();if(!C(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!W(r)){if(u(r).getIndent()>0)return o.dispatchCommand(M,void 0)}return o.dispatchCommand(v,!0)}),y),o.registerCommand(X,(t=>{if(Pt(t.target))return!1;const e=p();return!!C(e)&&(t.preventDefault(),o.dispatchCommand(v,!1))}),y),o.registerCommand(Y,(t=>{const e=p();if(!C(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(I,!1)}return o.dispatchCommand(O,void 0)}),y),o.registerCommand(B,(()=>{const t=p();return!!C(t)&&(o.blur(),!0)}),y),o.registerCommand(G,(t=>{const[,e]=Nt(t);if(e.length>0){const n=st(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,i=V(r);if(null!==i){const e=j();if(H(i))e.anchor.set(i.getKey(),t,"text"),e.focus.set(i.getKey(),t,"text");else{const t=i.getParentOrThrow().getKey(),n=i.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element")}const n=Q(e);U(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!C(n)}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();return!(e&&!C(n))}),y),o.registerCommand($,(t=>{const[e]=Nt(t),n=p();if(e&&!C(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=V(r.node);K(e)&&t.preventDefault()}return!0}),y),o.registerCommand(tt,(()=>(et(),!0)),y),o.registerCommand(nt,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(rt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();C(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(ot,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(it(e.target))return!1;return null!==p()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=p(),o=s(e,InputEvent)||s(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&t(o,r,n)}),{tag:"paste"})}(e,o),!0)}),y))}export{wt as $createHeadingNode,ht as $createQuoteNode,Et as $isHeadingNode,vt as $isQuoteNode,gt as DRAG_DROP_PASTE,Ct as HeadingNode,pt as QuoteNode,Nt as eventFiles,It as registerRichText};
|