@lexical/rich-text
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -9,5 +9,4 @@ /** @module @lexical/rich-text */ | ||
*/ | ||
import type { DOMConversionMap, EditorConfig, EditorState, LexicalEditor, LexicalNode, NodeKey, ParagraphNode, SerializedElementNode, Spread } from 'lexical'; | ||
import type { DOMConversionMap, EditorConfig, LexicalEditor, LexicalNode, NodeKey, ParagraphNode, SerializedElementNode, Spread } from 'lexical'; | ||
import { ElementNode } from 'lexical'; | ||
export declare type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void); | ||
export declare type SerializedHeadingNode = Spread<{ | ||
@@ -57,2 +56,2 @@ tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; | ||
export declare function $isHeadingNode(node: LexicalNode | null | undefined): node is HeadingNode; | ||
export declare function registerRichText(editor: LexicalEditor, initialEditorState?: InitialEditorStateType): () => void; | ||
export declare function registerRichText(editor: LexicalEditor): () => void; |
@@ -34,10 +34,3 @@ /** | ||
// Convoluted logic to make this work with Flow. Order matters. | ||
const options = { | ||
tag: 'history-merge' | ||
}; | ||
const setEditorOptions = options; | ||
const updateOptions = options; | ||
/** @noInheritDoc */ | ||
class QuoteNode extends lexical.ElementNode { | ||
@@ -287,49 +280,2 @@ static getType() { | ||
function initializeEditor(editor, initialEditorState) { | ||
if (initialEditorState === null) { | ||
return; | ||
} else if (initialEditorState === undefined) { | ||
editor.update(() => { | ||
const root = lexical.$getRoot(); | ||
if (root.isEmpty()) { | ||
const paragraph = lexical.$createParagraphNode(); | ||
root.append(paragraph); | ||
const activeElement = document.activeElement; | ||
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) { | ||
paragraph.select(); | ||
} | ||
} | ||
}, updateOptions); | ||
} else if (initialEditorState !== null) { | ||
switch (typeof initialEditorState) { | ||
case 'string': | ||
{ | ||
const parsedEditorState = editor.parseEditorState(initialEditorState); | ||
editor.setEditorState(parsedEditorState, setEditorOptions); | ||
break; | ||
} | ||
case 'object': | ||
{ | ||
editor.setEditorState(initialEditorState, setEditorOptions); | ||
break; | ||
} | ||
case 'function': | ||
{ | ||
editor.update(() => { | ||
const root = lexical.$getRoot(); | ||
if (root.isEmpty()) { | ||
initialEditorState(editor); | ||
} | ||
}, updateOptions); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
function onPasteForRichText(event, editor) { | ||
@@ -339,5 +285,5 @@ event.preventDefault(); | ||
const selection = lexical.$getSelection(); | ||
const clipboardData = event instanceof InputEvent ? null : event.clipboardData; | ||
const clipboardData = event instanceof InputEvent || event instanceof KeyboardEvent ? null : event.clipboardData; | ||
if (clipboardData != null && (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection))) { | ||
if (clipboardData != null && (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) { | ||
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor); | ||
@@ -432,3 +378,3 @@ } | ||
function registerRichText(editor, initialEditorState) { | ||
function registerRichText(editor) { | ||
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => { | ||
@@ -476,5 +422,5 @@ const selection = lexical.$getSelection(); | ||
selection.insertText(eventOrText); | ||
} else if (lexical.$isGridSelection(selection)) ; | ||
} else if (lexical.DEPRECATED_$isGridSelection(selection)) ; | ||
} else { | ||
if (!lexical.$isRangeSelection(selection) && !lexical.$isGridSelection(selection)) { | ||
if (!lexical.$isRangeSelection(selection) && !lexical.DEPRECATED_$isGridSelection(selection)) { | ||
return false; | ||
@@ -597,3 +543,3 @@ } | ||
if (lexical.$isNodeSelection(selection) && !isTargetWithinDecorator(event.target)) { | ||
if (lexical.$isNodeSelection(selection)) { | ||
// If selection is on a node, let's try and move selection | ||
@@ -613,3 +559,3 @@ // back to being a range selection. | ||
if (lexical.$isNodeSelection(selection$1) && !isTargetWithinDecorator(event.target)) { | ||
if (lexical.$isNodeSelection(selection$1)) { | ||
// If selection is on a node, let's try and move selection | ||
@@ -777,3 +723,3 @@ // back to being a range selection. | ||
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) { | ||
if (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection)) { | ||
onPasteForRichText(event, editor); | ||
@@ -785,3 +731,2 @@ return true; | ||
}, lexical.COMMAND_PRIORITY_EDITOR)); | ||
initializeEditor(editor, initialEditorState); | ||
return removeListener; | ||
@@ -788,0 +733,0 @@ } |
@@ -7,24 +7,23 @@ /** | ||
*/ | ||
'use strict';var b=require("@lexical/clipboard"),h=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,n=m&&"documentMode"in document?document.documentMode:null;m&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);m&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent); | ||
let p=m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1,q=m&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),r=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,t={tag:"history-merge"}; | ||
class u extends l.ElementNode{static getType(){return"quote"}static clone(a){return new u(a.__key)}constructor(a){super(a)}createDOM(a){let e=document.createElement("blockquote");k.addClassNamesToElement(e,a.theme.quote);return e}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:v,priority:0})}}static importJSON(a){let e=x();e.setFormat(a.format);e.setIndent(a.indent);e.setDirection(a.direction);return e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let a= | ||
l.$createParagraphNode(),e=this.getDirection();a.setDirection(e);this.insertAfter(a);return a}collapseAtStart(){let a=l.$createParagraphNode();this.getChildren().forEach(e=>a.append(e));this.replace(a);return!0}}function x(){return new u} | ||
class y extends l.ElementNode{static getType(){return"heading"}static clone(a){return new y(a.__tag,a.__key)}constructor(a,e){super(e);this.__tag=a}getTag(){return this.__tag}createDOM(a){let e=this.__tag,f=document.createElement(e);a=a.theme.heading;void 0!==a&&k.addClassNamesToElement(f,a[e]);return f}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:z,priority:0}),h2:()=>({conversion:z,priority:0}),h3:()=>({conversion:z,priority:0}),h4:()=>({conversion:z,priority:0}),h5:()=>({conversion:z, | ||
priority:0}),h6:()=>({conversion:z,priority:0}),p:a=>{a=a.firstChild;return null!==a&&A(a)?{conversion:()=>({node:null}),priority:3}:null},span:a=>A(a)?{conversion:()=>({node:B("h1")}),priority:3}:null}}static importJSON(a){let e=B(a.tag);e.setFormat(a.format);e.setIndent(a.indent);e.setDirection(a.direction);return e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let a=l.$createParagraphNode(),e=this.getDirection();a.setDirection(e);this.insertAfter(a); | ||
return a}collapseAtStart(){let a=l.$createParagraphNode();this.getChildren().forEach(e=>a.append(e));this.replace(a);return!0}extractWithChild(){return!0}}function A(a){return"span"===a.nodeName.toLowerCase()?"26pt"===a.style.fontSize:!1}function z(a){a=a.nodeName.toLowerCase();let e=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)e=B(a);return{node:e}}function v(){return{node:x()}}function B(a){return new y(a)} | ||
function C(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=l.$getRoot();if(f.isEmpty()){let c=l.$createParagraphNode();f.append(c);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===a.getRootElement())&&c.select()}},t);else if(null!==e)switch(typeof e){case "string":let f=a.parseEditorState(e);a.setEditorState(f,t);break;case "object":a.setEditorState(e,t);break;case "function":a.update(()=>{l.$getRoot().isEmpty()&&e(a)},t)}} | ||
function D(a,e){a.preventDefault();e.update(()=>{let f=l.$getSelection(),c=a instanceof InputEvent?null:a.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&b.$insertDataTransferForRichText(c,f,e)},{tag:"paste"})} | ||
function E(a,e){var f=l.$getSelection();if(null!==f){a.preventDefault();a=a instanceof KeyboardEvent?null:a.clipboardData;let c=b.$getHtmlContent(e);e=b.$getLexicalContent(e);null!=a?(null!==c&&a.setData("text/html",c),null!==e&&a.setData("application/x-lexical-editor",e),f=f.getTextContent(),a.setData("text/plain",f)):(f=navigator.clipboard,null!=f&&(a=[new ClipboardItem({"text/html":new Blob([c],{type:"text/html"})})],f.write(a)))}} | ||
function F(a,e){E(a,e);a=l.$getSelection();l.$isRangeSelection(a)?a.removeText():l.$isNodeSelection(a)&&a.getNodes().forEach(f=>f.remove())}function G(a,e){var f=l.$getSelection();if(l.$isRangeSelection(f)){var c=new Set;f=f.getNodes();for(let g=0;g<f.length;g++){let w=f[g];var d=w.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(w),d.canInsertTab()?a(w):d.canIndent()&&e(d))}}}function H(a){a=l.$getNearestNodeFromDOMNode(a);return l.$isDecoratorNode(a)} | ||
exports.$createHeadingNode=B;exports.$createQuoteNode=x;exports.$isHeadingNode=function(a){return a instanceof y};exports.$isQuoteNode=function(a){return a instanceof u};exports.HeadingNode=y;exports.QuoteNode=u; | ||
exports.registerRichText=function(a,e){let f=k.mergeRegister(a.registerCommand(l.CLICK_COMMAND,()=>{const c=l.$getSelection();return l.$isNodeSelection(c)?(c.clear(),!0):!1},0),a.registerCommand(l.DELETE_CHARACTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteCharacter(c);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.DELETE_WORD_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteWord(c);return!0},l.COMMAND_PRIORITY_EDITOR), | ||
a.registerCommand(l.DELETE_LINE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteLine(c);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,c=>{const d=l.$getSelection();if("string"===typeof c)l.$isRangeSelection(d)?d.insertText(c):l.$isGridSelection(d);else{if(!l.$isRangeSelection(d)&&!l.$isGridSelection(d))return!1;const g=c.dataTransfer;null!=g?b.$insertDataTransferForRichText(g,d,a):l.$isRangeSelection(d)&&(c=c.data)&&d.insertText(c)}return!0}, | ||
l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.FORMAT_TEXT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.formatText(c);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.FORMAT_ELEMENT_COMMAND,c=>{var d=l.$getSelection();if(!l.$isRangeSelection(d)&&!l.$isNodeSelection(d))return!1;d=d.getNodes();for(const g of d)k.$getNearestBlockElementAncestorOrThrow(g).setFormat(c); | ||
return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.INSERT_LINE_BREAK_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(c);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{G(()=>{a.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d= | ||
c.getIndent();10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{G(c=>{l.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ARROW_UP_COMMAND,c=>{const d=l.$getSelection();return l.$isNodeSelection(d)&&!H(c.target)&&(c=d.getNodes(),0<c.length)?(c[0].selectPrevious(), | ||
!0):!1},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ARROW_DOWN_COMMAND,c=>{const d=l.$getSelection();return l.$isNodeSelection(d)&&!H(c.target)&&(c=d.getNodes(),0<c.length)?(c[0].selectNext(0,0),!0):!1},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!H(c.target)){var g=d.getNodes();if(0<g.length)return c.preventDefault(),g[0].selectPrevious(),!0}return l.$isRangeSelection(d)?h.$shouldOverrideDefaultCharacterSelection(d, | ||
!0)?(g=c.shiftKey,c.preventDefault(),h.$moveCharacter(d,g,!0),!0):!1:!1},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,c=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!H(c.target)){var g=d.getNodes();if(0<g.length)return c.preventDefault(),g[0].selectNext(0,0),!0}if(!l.$isRangeSelection(d))return!1;g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,!1)?(c.preventDefault(),h.$moveCharacter(d,g,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_BACKSPACE_COMMAND, | ||
c=>{if(H(c.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=d);const g=c.getNode();return d.isCollapsed()&&0===c.offset&&!l.$isRootNode(g)&&0<k.$getNearestBlockElementAncestorOrThrow(g).getIndent()?a.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_DELETE_COMMAND,c=>{if(H(c.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1; | ||
c.preventDefault();return a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ENTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==c){if((r||q)&&p)return!1;c.preventDefault();if(c.shiftKey)return a.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return a.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1; | ||
c.preventDefault();return a.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;a.blur();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection(); | ||
if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.COPY_COMMAND,c=>{E(c,a);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.CUT_COMMAND,c=>{F(c,a);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(D(c,a),!0):!1},l.COMMAND_PRIORITY_EDITOR));C(a,e);return f} | ||
'use strict';var b=require("@lexical/clipboard"),f=require("@lexical/selection"),g=require("@lexical/utils"),h=require("lexical");let l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,m=l&&"documentMode"in document?document.documentMode:null;l&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);l&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent); | ||
let n=l&&"InputEvent"in window&&!m?"getTargetRanges"in new window.InputEvent("input"):!1,p=l&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),q=l&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream; | ||
class r extends h.ElementNode{static getType(){return"quote"}static clone(a){return new r(a.__key)}constructor(a){super(a)}createDOM(a){let c=document.createElement("blockquote");g.addClassNamesToElement(c,a.theme.quote);return c}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:t,priority:0})}}static importJSON(a){let c=w();c.setFormat(a.format);c.setIndent(a.indent);c.setDirection(a.direction);return c}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let a= | ||
h.$createParagraphNode(),c=this.getDirection();a.setDirection(c);this.insertAfter(a);return a}collapseAtStart(){let a=h.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}}function w(){return new r} | ||
class x extends h.ElementNode{static getType(){return"heading"}static clone(a){return new x(a.__tag,a.__key)}constructor(a,c){super(c);this.__tag=a}getTag(){return this.__tag}createDOM(a){let c=this.__tag,d=document.createElement(c);a=a.theme.heading;void 0!==a&&g.addClassNamesToElement(d,a[c]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:y,priority:0}),h2:()=>({conversion:y,priority:0}),h3:()=>({conversion:y,priority:0}),h4:()=>({conversion:y,priority:0}),h5:()=>({conversion:y, | ||
priority:0}),h6:()=>({conversion:y,priority:0}),p:a=>{a=a.firstChild;return null!==a&&z(a)?{conversion:()=>({node:null}),priority:3}:null},span:a=>z(a)?{conversion:()=>({node:A("h1")}),priority:3}:null}}static importJSON(a){let c=A(a.tag);c.setFormat(a.format);c.setIndent(a.indent);c.setDirection(a.direction);return c}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let a=h.$createParagraphNode(),c=this.getDirection();a.setDirection(c);this.insertAfter(a); | ||
return a}collapseAtStart(){let a=h.$createParagraphNode();this.getChildren().forEach(c=>a.append(c));this.replace(a);return!0}extractWithChild(){return!0}}function z(a){return"span"===a.nodeName.toLowerCase()?"26pt"===a.style.fontSize:!1}function y(a){a=a.nodeName.toLowerCase();let c=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)c=A(a);return{node:c}}function t(){return{node:w()}}function A(a){return new x(a)} | ||
function B(a,c){a.preventDefault();c.update(()=>{let d=h.$getSelection(),e=a instanceof InputEvent||a instanceof KeyboardEvent?null:a.clipboardData;null!=e&&(h.$isRangeSelection(d)||h.DEPRECATED_$isGridSelection(d))&&b.$insertDataTransferForRichText(e,d,c)},{tag:"paste"})} | ||
function C(a,c){var d=h.$getSelection();if(null!==d){a.preventDefault();a=a instanceof KeyboardEvent?null:a.clipboardData;let e=b.$getHtmlContent(c);c=b.$getLexicalContent(c);null!=a?(null!==e&&a.setData("text/html",e),null!==c&&a.setData("application/x-lexical-editor",c),d=d.getTextContent(),a.setData("text/plain",d)):(d=navigator.clipboard,null!=d&&(a=[new ClipboardItem({"text/html":new Blob([e],{type:"text/html"})})],d.write(a)))}} | ||
function D(a,c){C(a,c);a=h.$getSelection();h.$isRangeSelection(a)?a.removeText():h.$isNodeSelection(a)&&a.getNodes().forEach(d=>d.remove())}function E(a,c){var d=h.$getSelection();if(h.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let u=0;u<d.length;u++){let v=d[u];var k=v.getKey();e.has(k)||(e.add(k),k=g.$getNearestBlockElementAncestorOrThrow(v),k.canInsertTab()?a(v):k.canIndent()&&c(k))}}}function F(a){a=h.$getNearestNodeFromDOMNode(a);return h.$isDecoratorNode(a)} | ||
exports.$createHeadingNode=A;exports.$createQuoteNode=w;exports.$isHeadingNode=function(a){return a instanceof x};exports.$isQuoteNode=function(a){return a instanceof r};exports.HeadingNode=x;exports.QuoteNode=r; | ||
exports.registerRichText=function(a){return g.mergeRegister(a.registerCommand(h.CLICK_COMMAND,()=>{const c=h.$getSelection();return h.$isNodeSelection(c)?(c.clear(),!0):!1},0),a.registerCommand(h.DELETE_CHARACTER_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteCharacter(c);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.DELETE_WORD_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteWord(c);return!0},h.COMMAND_PRIORITY_EDITOR), | ||
a.registerCommand(h.DELETE_LINE_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteLine(c);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.CONTROLLED_TEXT_INSERTION_COMMAND,c=>{const d=h.$getSelection();if("string"===typeof c)h.$isRangeSelection(d)?d.insertText(c):h.DEPRECATED_$isGridSelection(d);else{if(!h.$isRangeSelection(d)&&!h.DEPRECATED_$isGridSelection(d))return!1;const e=c.dataTransfer;null!=e?b.$insertDataTransferForRichText(e,d,a):h.$isRangeSelection(d)&& | ||
(c=c.data)&&d.insertText(c)}return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.REMOVE_TEXT_COMMAND,()=>{const c=h.$getSelection();if(!h.$isRangeSelection(c))return!1;c.removeText();return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.FORMAT_TEXT_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.formatText(c);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.FORMAT_ELEMENT_COMMAND,c=>{var d=h.$getSelection();if(!h.$isRangeSelection(d)&&!h.$isNodeSelection(d))return!1; | ||
d=d.getNodes();for(const e of d)g.$getNearestBlockElementAncestorOrThrow(e).setFormat(c);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.INSERT_LINE_BREAK_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.insertLineBreak(c);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.INSERT_PARAGRAPH_COMMAND,()=>{const c=h.$getSelection();if(!h.$isRangeSelection(c))return!1;c.insertParagraph();return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.INDENT_CONTENT_COMMAND, | ||
()=>{E(()=>{a.dispatchCommand(h.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d=c.getIndent();10!==d&&c.setIndent(d+1)});return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.OUTDENT_CONTENT_COMMAND,()=>{E(c=>{h.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&a.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ARROW_UP_COMMAND,c=>{const d=h.$getSelection();return h.$isNodeSelection(d)&& | ||
!F(c.target)&&(c=d.getNodes(),0<c.length)?(c[0].selectPrevious(),!0):!1},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ARROW_DOWN_COMMAND,()=>{var c=h.$getSelection();return h.$isNodeSelection(c)&&(c=c.getNodes(),0<c.length)?(c[0].selectNext(0,0),!0):!1},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ARROW_LEFT_COMMAND,c=>{const d=h.$getSelection();if(h.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return c.preventDefault(),e[0].selectPrevious(),!0}return h.$isRangeSelection(d)?f.$shouldOverrideDefaultCharacterSelection(d, | ||
!0)?(e=c.shiftKey,c.preventDefault(),f.$moveCharacter(d,e,!0),!0):!1:!1},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ARROW_RIGHT_COMMAND,c=>{const d=h.$getSelection();if(h.$isNodeSelection(d)&&!F(c.target)){var e=d.getNodes();if(0<e.length)return c.preventDefault(),e[0].selectNext(0,0),!0}if(!h.$isRangeSelection(d))return!1;e=c.shiftKey;return f.$shouldOverrideDefaultCharacterSelection(d,!1)?(c.preventDefault(),f.$moveCharacter(d,e,!1),!0):!1},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_BACKSPACE_COMMAND, | ||
c=>{if(F(c.target))return!1;const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=d);const e=c.getNode();return d.isCollapsed()&&0===c.offset&&!h.$isRootNode(e)&&0<g.$getNearestBlockElementAncestorOrThrow(e).getIndent()?a.dispatchCommand(h.OUTDENT_CONTENT_COMMAND,void 0):a.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!0)},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_DELETE_COMMAND,c=>{if(F(c.target))return!1;const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1; | ||
c.preventDefault();return a.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!1)},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ENTER_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;if(null!==c){if((q||p)&&n)return!1;c.preventDefault();if(c.shiftKey)return a.dispatchCommand(h.INSERT_LINE_BREAK_COMMAND,!1)}return a.dispatchCommand(h.INSERT_PARAGRAPH_COMMAND,void 0)},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_TAB_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1; | ||
c.preventDefault();return a.dispatchCommand(c.shiftKey?h.OUTDENT_CONTENT_COMMAND:h.INDENT_CONTENT_COMMAND,void 0)},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.KEY_ESCAPE_COMMAND,()=>{const c=h.$getSelection();if(!h.$isRangeSelection(c))return!1;a.blur();return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.DROP_COMMAND,c=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;c.preventDefault();return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.DRAGSTART_COMMAND,c=>{const d=h.$getSelection(); | ||
if(!h.$isRangeSelection(d))return!1;c.preventDefault();return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.COPY_COMMAND,c=>{C(c,a);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.CUT_COMMAND,c=>{D(c,a);return!0},h.COMMAND_PRIORITY_EDITOR),a.registerCommand(h.PASTE_COMMAND,c=>{const d=h.$getSelection();return h.$isRangeSelection(d)||h.DEPRECATED_$isGridSelection(d)?(B(c,a),!0):!1},h.COMMAND_PRIORITY_EDITOR))} |
@@ -10,9 +10,9 @@ { | ||
"license": "MIT", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"main": "LexicalRichText.js", | ||
"peerDependencies": { | ||
"lexical": "0.4.1", | ||
"@lexical/selection": "0.4.1", | ||
"@lexical/clipboard": "0.4.1", | ||
"@lexical/utils": "0.4.1" | ||
"lexical": "0.5.0", | ||
"@lexical/selection": "0.5.0", | ||
"@lexical/clipboard": "0.5.0", | ||
"@lexical/utils": "0.5.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
@@ -5,2 +5,2 @@ # `@lexical/rich-text` | ||
You can use this package as a starting point, and then add additional command listeners to customize the functionality of your editor. If you don't want or need rich text functionality, you may want to consider using [@lexical/plain-text](https://lexical.dev/docs/api/lexical-plain-text) instead. | ||
You can use this package as a starting point, and then add additional command listeners to customize the functionality of your editor. If you don't want or need rich text functionality, you may want to consider using [@lexical/plain-text](https://lexical.dev/docs/packages/lexical-plain-text) instead. |
Sorry, the diff of this file is not supported yet
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
38046
713