50 lines
26 KiB
Diff
50 lines
26 KiB
Diff
diff --git a/LexicalRichText.dev.js b/LexicalRichText.dev.js
|
|
index a23f1faaf3da195b193a51e084a5cd2937dda6dc..b11110387e0543670921f98b1e9489c789d1d8cb 100644
|
|
--- a/LexicalRichText.dev.js
|
|
+++ b/LexicalRichText.dev.js
|
|
@@ -470,7 +470,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 3b2880f2f7a6db47c61ab8df357d773371cc9a1c..ccb522cf64f3c3cdfacb3d757064ecff7ee22eb9 100644
|
|
--- a/LexicalRichText.dev.mjs
|
|
+++ b/LexicalRichText.dev.mjs
|
|
@@ -468,7 +468,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.prod.js b/LexicalRichText.prod.js
|
|
index 562f23865ba4aa00e1322b21b64d65815f708698..a5a16f9e0970b8022a524df60399386900eb7c36 100644
|
|
--- a/LexicalRichText.prod.js
|
|
+++ b/LexicalRichText.prod.js
|
|
@@ -20,7 +20,7 @@ function I(b){let a=null;h.objectKlassEquals(b,DragEvent)?a=b.dataTransfer:h.obj
|
|
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.$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 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;
|
|
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)&&
|
|
diff --git a/LexicalRichText.prod.mjs b/LexicalRichText.prod.mjs
|
|
index 1eb500c4b8bbc39fb9647ed045073fbac37d28fc..99319b2455b869a33558e37fc3a65d12c7417803 100644
|
|
--- a/LexicalRichText.prod.mjs
|
|
+++ b/LexicalRichText.prod.mjs
|
|
@@ -6,4 +6,4 @@
|
|
*
|
|
*/
|
|
|
|
-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,$createParagraphNode as m,$applyNodeReplacement as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as C,$isRangeSelection as v,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 I,$isElementNode as O,INSERT_LINE_BREAK_COMMAND as T,INSERT_PARAGRAPH_COMMAND as A,INSERT_TAB_COMMAND as P,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as b,OUTDENT_CONTENT_COMMAND as F,KEY_ARROW_UP_COMMAND as M,$getAdjacentNode as K,$isDecoratorNode as k,KEY_ARROW_DOWN_COMMAND as J,KEY_ARROW_LEFT_COMMAND as q,KEY_ARROW_RIGHT_COMMAND as L,KEY_BACKSPACE_COMMAND as R,$isRootNode as z,KEY_DELETE_COMMAND as W,KEY_ENTER_COMMAND as X,KEY_ESCAPE_COMMAND as Y,DROP_COMMAND as B,$getNearestNodeFromDOMNode as G,$createRangeSelection as V,$isTextNode as j,$normalizeSelection__EXPERIMENTAL as H,$setSelection as Q,DRAGSTART_COMMAND as U,DRAGOVER_COMMAND as Z,SELECT_ALL_COMMAND as $,$selectAll as tt,COPY_COMMAND as et,CUT_COMMAND as nt,PASTE_COMMAND as rt,isSelectionCapturedInDecoratorInput as ot,$getRoot 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,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&&/^(?=.*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=m(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=m();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return f(new pt)}function Ct(t){return t instanceof pt}class vt extends d{static getType(){return"heading"}static clone(t){return new vt(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()):m(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=m();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?m():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 f(new vt(t))}function Et(t){return t instanceof vt}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 It(t){const e=p();if(!v(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=>O(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 Ot(t){const e=G(t);return k(e)}function Tt(o){return c(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(C,(t=>{const e=p();return!!v(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!v(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!v(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(v(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!v(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!v(e)&&(e.formatText(t),!0)}),y),o.registerCommand(I,(t=>{const e=p();if(!v(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=a(e,(t=>O(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(T,(t=>{const e=p();return!!v(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(A,(()=>{const t=p();return!!v(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(P,(()=>(S([_()]),!0)),y),o.registerCommand(b,(()=>It((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(F,(()=>It((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(M,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(v(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(v(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===it().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(q,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!v(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!v(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(R,(t=>{if(Ot(t.target))return!1;const e=p();if(!v(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!z(r)){if(u(r).getIndent()>0)return o.dispatchCommand(F,void 0)}return o.dispatchCommand(C,!0)}),y),o.registerCommand(W,(t=>{if(Ot(t.target))return!1;const e=p();return!!v(e)&&(t.preventDefault(),o.dispatchCommand(C,!1))}),y),o.registerCommand(X,(t=>{const e=p();if(!v(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(T,!1)}return o.dispatchCommand(A,void 0)}),y),o.registerCommand(Y,(()=>{const t=p();return!!v(t)&&(o.blur(),!0)}),y),o.registerCommand(B,(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=G(r);if(null!==i){const e=V();if(j(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=H(e);Q(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!v(n)}),y),o.registerCommand(U,(t=>{const[e]=Nt(t),n=p();return!(e&&!v(n))}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();if(e&&!v(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=G(r.node);k(e)&&t.preventDefault()}return!0}),y),o.registerCommand($,(()=>(tt(),!0)),y),o.registerCommand(et,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(nt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();v(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(rt,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(ot(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,Ct as $isQuoteNode,gt as DRAG_DROP_PASTE,vt as HeadingNode,pt as QuoteNode,Nt as eventFiles,Tt 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,$createParagraphNode as m,$applyNodeReplacement as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as C,$isRangeSelection as v,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 I,$isElementNode as O,INSERT_LINE_BREAK_COMMAND as T,INSERT_PARAGRAPH_COMMAND as A,INSERT_TAB_COMMAND as P,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as b,OUTDENT_CONTENT_COMMAND as F,KEY_ARROW_UP_COMMAND as M,$getAdjacentNode as K,$isDecoratorNode as k,KEY_ARROW_DOWN_COMMAND as J,KEY_ARROW_LEFT_COMMAND as q,KEY_ARROW_RIGHT_COMMAND as L,KEY_BACKSPACE_COMMAND as R,$isRootNode as z,KEY_DELETE_COMMAND as W,KEY_ENTER_COMMAND as X,KEY_ESCAPE_COMMAND as Y,DROP_COMMAND as B,$getNearestNodeFromDOMNode as G,$createRangeSelection as V,$isTextNode as j,$normalizeSelection__EXPERIMENTAL as H,$setSelection as Q,DRAGSTART_COMMAND as U,DRAGOVER_COMMAND as Z,SELECT_ALL_COMMAND as $,$selectAll as tt,COPY_COMMAND as et,CUT_COMMAND as nt,PASTE_COMMAND as rt,isSelectionCapturedInDecoratorInput as ot,$getRoot 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,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&&/^(?=.*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=m(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=m();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return f(new pt)}function Ct(t){return t instanceof pt}class vt extends d{static getType(){return"heading"}static clone(t){return new vt(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()):m(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=m();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?m():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 f(new vt(t))}function Et(t){return t instanceof vt}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 It(t){const e=p();if(!v(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=>O(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 Ot(t){const e=G(t);return k(e)}function Tt(o){return c(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(C,(t=>{const e=p();return!!v(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!v(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!v(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(v(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!v(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!v(e)&&(e.formatText(t),!0)}),y),o.registerCommand(I,(t=>{const e=p();if(!v(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=a(e,(t=>O(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(T,(t=>{const e=p();return!!v(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(A,(()=>{const t=p();return!!v(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(P,(()=>(S([_()]),!0)),y),o.registerCommand(b,(()=>It((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(F,(()=>It((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(M,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(v(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(v(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===it().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(q,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!v(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!v(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(R,(t=>{if(Ot(t.target))return!1;const e=p();if(!v(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!z(r)){if(u(r).getIndent()>0)return o.dispatchCommand(F,void 0)}return o.dispatchCommand(C,!0)}),y),o.registerCommand(W,(t=>{if(Ot(t.target))return!1;const e=p();return!!v(e)&&(t.preventDefault(),o.dispatchCommand(C,!1))}),y),o.registerCommand(X,(t=>{const e=p();if(!v(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(T,!1)}return o.dispatchCommand(A,void 0)}),y),o.registerCommand(Y,(()=>{const t=p();return!!v(t)&&(o.blur(),!0)}),y),o.registerCommand(B,(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=G(r);if(null!==i){const e=V();if(j(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=H(e);Q(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!v(n)}),y),o.registerCommand(U,(t=>{const[e]=Nt(t),n=p();return!(e&&!v(n))}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();if(e&&!v(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=G(r.node);k(e)&&t.preventDefault()}return!0}),y),o.registerCommand($,(()=>(tt(),!0)),y),o.registerCommand(et,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(nt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();v(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(rt,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(ot(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,Ct as $isQuoteNode,gt as DRAG_DROP_PASTE,vt as HeadingNode,pt as QuoteNode,Nt as eventFiles,Tt as registerRichText};
|