@lexical/rich-text 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalRichText.dev.js +8 -5
- package/LexicalRichText.prod.js +8 -8
- package/index.d.ts +2 -2
- package/package.json +5 -5
package/LexicalRichText.dev.js
CHANGED
|
@@ -247,8 +247,9 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
247
247
|
} // Mutation
|
|
248
248
|
|
|
249
249
|
|
|
250
|
-
insertNewAfter() {
|
|
251
|
-
const
|
|
250
|
+
insertNewAfter(selection) {
|
|
251
|
+
const selectionOffset = selection ? selection.anchor.offset : 0;
|
|
252
|
+
const newElement = selectionOffset < this.getTextContentSize() && selectionOffset > 0 ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
|
|
252
253
|
const direction = this.getDirection();
|
|
253
254
|
newElement.setDirection(direction);
|
|
254
255
|
this.insertAfter(newElement);
|
|
@@ -256,10 +257,12 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
collapseAtStart() {
|
|
259
|
-
const
|
|
260
|
+
const previousSibling = this.getPreviousSibling();
|
|
261
|
+
const isPreviouSiblingEmpty = !previousSibling || previousSibling && previousSibling.getTextContentSize() === 0;
|
|
262
|
+
const newElement = isPreviouSiblingEmpty ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
|
|
260
263
|
const children = this.getChildren();
|
|
261
|
-
children.forEach(child =>
|
|
262
|
-
this.replace(
|
|
264
|
+
children.forEach(child => newElement.append(child));
|
|
265
|
+
this.replace(newElement);
|
|
263
266
|
return true;
|
|
264
267
|
}
|
|
265
268
|
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),h=require("@lexical/utils"),k=require("lexical");let
|
|
8
|
-
let r=
|
|
7
|
+
'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),h=require("@lexical/utils"),k=require("lexical");let l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,n=l&&"documentMode"in document?document.documentMode:null;l&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);l&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
8
|
+
let r=l&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1,t=l&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),u=l&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,v=k.createCommand("DRAG_DROP_PASTE_FILE");
|
|
9
9
|
class y extends k.ElementNode{static getType(){return"quote"}static clone(c){return new y(c.__key)}constructor(c){super(c)}createDOM(c){let b=document.createElement("blockquote");h.addClassNamesToElement(b,c.theme.quote);return b}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:z,priority:0})}}static importJSON(c){let b=A();b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let c=
|
|
10
10
|
k.$createParagraphNode(),b=this.getDirection();c.setDirection(b);this.insertAfter(c);return c}collapseAtStart(){let c=k.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}}function A(){return k.$applyNodeReplacement(new y)}
|
|
11
11
|
class B extends k.ElementNode{static getType(){return"heading"}static clone(c){return new B(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&&h.addClassNamesToElement(d,c[b]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:C,priority:0}),h2:()=>({conversion:C,priority:0}),h3:()=>({conversion:C,priority:0}),h4:()=>({conversion:C,priority:0}),h5:()=>({conversion:C,
|
|
12
|
-
priority:0}),h6:()=>({conversion:C,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(){
|
|
13
|
-
return c}collapseAtStart(){let c=k.$createParagraphNode();this.getChildren().forEach(b
|
|
14
|
-
function F(c,b){c.preventDefault();b.update(()=>{let d=k.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(k.$isRangeSelection(d)||k.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
|
|
12
|
+
priority:0}),h6:()=>({conversion:C,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){c=c?c.anchor.offset:0;c=c<this.getTextContentSize()&&0<c?E(this.getTag()):k.$createParagraphNode();
|
|
13
|
+
let b=this.getDirection();c.setDirection(b);this.insertAfter(c);return c}collapseAtStart(){let c=this.getPreviousSibling(),b=!c||c&&0===c.getTextContentSize()?E(this.getTag()):k.$createParagraphNode();this.getChildren().forEach(d=>b.append(d));this.replace(b);return!0}extractWithChild(){return!0}}function D(c){return"span"===c.nodeName.toLowerCase()?"26pt"===c.style.fontSize:!1}
|
|
14
|
+
function C(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 z(){return{node:A()}}function E(c){return k.$applyNodeReplacement(new B(c))}function F(c,b){c.preventDefault();b.update(()=>{let d=k.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(k.$isRangeSelection(d)||k.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
|
|
15
15
|
async function G(c,b){await a.copyToClipboard__EXPERIMENTAL(b,c instanceof ClipboardEvent?c:null);b.update(()=>{let d=k.$getSelection();k.$isRangeSelection(d)?d.removeText():k.$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]}
|
|
16
|
-
function I(c,b){var d=k.$getSelection();if(k.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let f=0;f<d.length;f++){let
|
|
16
|
+
function I(c,b){var d=k.$getSelection();if(k.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let f=0;f<d.length;f++){let p=d[f],w=p.getKey();if(e.has(w))continue;let m=h.$getNearestBlockElementAncestorOrThrow(p),x=m.getKey();m.canInsertTab()?(c(p),e.add(w)):m.canIndent()&&!e.has(x)&&(e.add(x),b(m))}}}function J(c){c=k.$getNearestNodeFromDOMNode(c);return k.$isDecoratorNode(c)}exports.$createHeadingNode=E;exports.$createQuoteNode=A;exports.$isHeadingNode=function(c){return c instanceof B};
|
|
17
17
|
exports.$isQuoteNode=function(c){return c instanceof y};exports.DRAG_DROP_PASTE=v;exports.HeadingNode=B;exports.QuoteNode=y;exports.eventFiles=H;
|
|
18
18
|
exports.registerRichText=function(c){return h.mergeRegister(c.registerCommand(k.CLICK_COMMAND,()=>{const b=k.$getSelection();return k.$isNodeSelection(b)?(b.clear(),!0):!1},0),c.registerCommand(k.DELETE_CHARACTER_COMMAND,b=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteCharacter(b);return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.DELETE_WORD_COMMAND,b=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteWord(b);return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
19
19
|
c.registerCommand(k.DELETE_LINE_COMMAND,b=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteLine(b);return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.CONTROLLED_TEXT_INSERTION_COMMAND,b=>{const d=k.$getSelection();if("string"===typeof b)k.$isRangeSelection(d)?d.insertText(b):k.DEPRECATED_$isGridSelection(d);else{if(!k.$isRangeSelection(d)&&!k.DEPRECATED_$isGridSelection(d))return!1;const e=b.dataTransfer;null!=e?a.$insertDataTransferForRichText(e,d,c):k.$isRangeSelection(d)&&
|
|
@@ -25,6 +25,6 @@ d=d.getNodes();for(const e of d)h.$getNearestBlockElementAncestorOrThrow(e).setF
|
|
|
25
25
|
b=>{if(J(b.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;b.preventDefault();({anchor:b}=d);const e=b.getNode();return d.isCollapsed()&&0===b.offset&&!k.$isRootNode(e)&&0<h.$getNearestBlockElementAncestorOrThrow(e).getIndent()?c.dispatchCommand(k.OUTDENT_CONTENT_COMMAND,void 0):c.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!0)},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.KEY_DELETE_COMMAND,b=>{if(J(b.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;
|
|
26
26
|
b.preventDefault();return c.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!1)},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.KEY_ENTER_COMMAND,b=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;if(null!==b){if((u||t)&&r)return!1;b.preventDefault();if(b.shiftKey)return c.dispatchCommand(k.INSERT_LINE_BREAK_COMMAND,!1)}return c.dispatchCommand(k.INSERT_PARAGRAPH_COMMAND,void 0)},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.KEY_TAB_COMMAND,b=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;
|
|
27
27
|
b.preventDefault();return c.dispatchCommand(b.shiftKey?k.OUTDENT_CONTENT_COMMAND:k.INDENT_CONTENT_COMMAND,void 0)},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.KEY_ESCAPE_COMMAND,()=>{const b=k.$getSelection();if(!k.$isRangeSelection(b))return!1;c.blur();return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.DROP_COMMAND,b=>{const [,d]=H(b);if(0<d.length){var e=b.clientX;var f=b.clientY;e="undefined"!==typeof document.caretRangeFromPoint?document.caretRangeFromPoint(e,f):"undefined"!==document.caretPositionFromPoint?
|
|
28
|
-
document.caretPositionFromPoint(e,f):null;if(null!==e){const {startOffset:
|
|
29
|
-
e=k.$normalizeSelection__EXPERIMENTAL(
|
|
28
|
+
document.caretPositionFromPoint(e,f):null;if(null!==e){const {startOffset:p,endOffset:w,startContainer:m,endContainer:x}=e;e=k.$getNearestNodeFromDOMNode(m);f=k.$getNearestNodeFromDOMNode(x);if(null!==e&&null!==f){const q=k.$createRangeSelection();k.$isTextNode(e)?q.anchor.set(e.getKey(),p,"text"):q.anchor.set(e.getParentOrThrow().getKey(),e.getIndexWithinParent()+1,"element");k.$isTextNode(f)?q.focus.set(f.getKey(),w,"text"):q.focus.set(f.getParentOrThrow().getKey(),f.getIndexWithinParent()+1,"element");
|
|
29
|
+
e=k.$normalizeSelection__EXPERIMENTAL(q);k.$setSelection(e)}c.dispatchCommand(v,d)}b.preventDefault();return!0}b=k.$getSelection();return k.$isRangeSelection(b)?!0:!1},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.DRAGSTART_COMMAND,b=>{const [d]=H(b),e=k.$getSelection();if(d&&!k.$isRangeSelection(e))return!1;b.preventDefault();return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.DRAGOVER_COMMAND,b=>{const [d]=H(b),e=k.$getSelection();if(d&&!k.$isRangeSelection(e))return!1;b.preventDefault();
|
|
30
30
|
return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.COPY_COMMAND,b=>{a.copyToClipboard__EXPERIMENTAL(c,b instanceof ClipboardEvent?b:null);return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.CUT_COMMAND,b=>{G(b,c);return!0},k.COMMAND_PRIORITY_EDITOR),c.registerCommand(k.PASTE_COMMAND,b=>{const [,d,e]=H(b);if(0<d.length&&!e)return c.dispatchCommand(v,d),!0;const f=k.$getSelection();return k.$isRangeSelection(f)||k.DEPRECATED_$isGridSelection(f)?(F(b,c),!0):!1},k.COMMAND_PRIORITY_EDITOR))}
|
package/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
import type { DOMConversionMap, EditorConfig, LexicalCommand, LexicalEditor, LexicalNode, NodeKey, ParagraphNode, PasteCommandType, SerializedElementNode, Spread } from 'lexical';
|
|
9
|
+
import type { DOMConversionMap, EditorConfig, LexicalCommand, LexicalEditor, LexicalNode, NodeKey, ParagraphNode, PasteCommandType, RangeSelection, SerializedElementNode, Spread } from 'lexical';
|
|
10
10
|
import { ElementNode } from 'lexical';
|
|
11
11
|
export declare type SerializedHeadingNode = Spread<{
|
|
12
12
|
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
@@ -47,7 +47,7 @@ export declare class HeadingNode extends ElementNode {
|
|
|
47
47
|
static importDOM(): DOMConversionMap | null;
|
|
48
48
|
static importJSON(serializedNode: SerializedHeadingNode): HeadingNode;
|
|
49
49
|
exportJSON(): SerializedHeadingNode;
|
|
50
|
-
insertNewAfter(): ParagraphNode;
|
|
50
|
+
insertNewAfter(selection?: RangeSelection): ParagraphNode | HeadingNode;
|
|
51
51
|
collapseAtStart(): true;
|
|
52
52
|
extractWithChild(): boolean;
|
|
53
53
|
}
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.6.
|
|
10
|
+
"version": "0.6.4",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.6.
|
|
14
|
-
"@lexical/selection": "0.6.
|
|
15
|
-
"@lexical/clipboard": "0.6.
|
|
16
|
-
"@lexical/utils": "0.6.
|
|
13
|
+
"lexical": "0.6.4",
|
|
14
|
+
"@lexical/selection": "0.6.4",
|
|
15
|
+
"@lexical/clipboard": "0.6.4",
|
|
16
|
+
"@lexical/utils": "0.6.4"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|