@lexical/rich-text 0.2.8 → 0.3.1

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.
@@ -5,6 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
+
8
9
  import type {
9
10
  DOMConversionMap,
10
11
  EditorConfig,
@@ -13,8 +14,11 @@ import type {
13
14
  NodeKey,
14
15
  ParagraphNode,
15
16
  LexicalEditor,
17
+ SerializedElementNode,
16
18
  } from 'lexical';
17
19
  import {ElementNode} from 'lexical';
20
+ import {Spread} from 'libdefs/globals';
21
+
18
22
  export type InitialEditorStateType = null | string | EditorState | (() => void);
19
23
 
20
24
  export declare class QuoteNode extends ElementNode {
@@ -25,6 +29,7 @@ export declare class QuoteNode extends ElementNode {
25
29
  updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean;
26
30
  insertNewAfter(): ParagraphNode;
27
31
  collapseAtStart(): true;
32
+ importJSON(serializedNode: SerializedQuoteNode): QuoteNode;
28
33
  }
29
34
  export function $createQuoteNode(): QuoteNode;
30
35
  export function $isQuoteNode(
@@ -42,7 +47,9 @@ export declare class HeadingNode extends ElementNode {
42
47
  static importDOM(): DOMConversionMap | null;
43
48
  insertNewAfter(): ParagraphNode;
44
49
  collapseAtStart(): true;
50
+ importJSON(serializedNode: SerializedHeadingNode): QuoteNode;
45
51
  }
52
+
46
53
  export function $createHeadingNode(headingTag: HeadingTagType): HeadingNode;
47
54
  export function $isHeadingNode(
48
55
  node: LexicalNode | null | undefined,
@@ -51,3 +58,20 @@ export function registerRichText(
51
58
  editor: LexicalEditor,
52
59
  initialEditorState?: InitialEditorStateType,
53
60
  ): () => void;
61
+
62
+ export type SerializedHeadingNode = Spread<
63
+ {
64
+ tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
65
+ type: 'heading';
66
+ version: 1;
67
+ },
68
+ SerializedElementNode
69
+ >;
70
+
71
+ export type SerializedQuoteNode = Spread<
72
+ {
73
+ type: 'quote';
74
+ version: 1;
75
+ },
76
+ SerializedElementNode
77
+ >;
@@ -66,6 +66,29 @@ class QuoteNode extends lexical.ElementNode {
66
66
 
67
67
  updateDOM(prevNode, dom) {
68
68
  return false;
69
+ }
70
+
71
+ static importDOM() {
72
+ return {
73
+ blockquote: node => ({
74
+ conversion: convertBlockquoteElement,
75
+ priority: 0
76
+ })
77
+ };
78
+ }
79
+
80
+ static importJSON(serializedNode) {
81
+ const node = $createQuoteNode();
82
+ node.setFormat(serializedNode.format);
83
+ node.setIndent(serializedNode.indent);
84
+ node.setDirection(serializedNode.direction);
85
+ return node;
86
+ }
87
+
88
+ exportJSON() {
89
+ return { ...super.exportJSON(),
90
+ type: 'quote'
91
+ };
69
92
  } // Mutation
70
93
 
71
94
 
@@ -118,7 +141,6 @@ class HeadingNode extends lexical.ElementNode {
118
141
  const classNames = theme.heading;
119
142
 
120
143
  if (classNames !== undefined) {
121
- // $FlowFixMe: intentional cast
122
144
  const className = classNames[tag];
123
145
  utils.addClassNamesToElement(element, className);
124
146
  }
@@ -153,6 +175,22 @@ class HeadingNode extends lexical.ElementNode {
153
175
  priority: 0
154
176
  })
155
177
  };
178
+ }
179
+
180
+ static importJSON(serializedNode) {
181
+ const node = $createHeadingNode(serializedNode.tag);
182
+ node.setFormat(serializedNode.format);
183
+ node.setIndent(serializedNode.indent);
184
+ node.setDirection(serializedNode.direction);
185
+ return node;
186
+ }
187
+
188
+ exportJSON() {
189
+ return { ...super.exportJSON(),
190
+ tag: this.getTag(),
191
+ type: 'heading',
192
+ version: 1
193
+ };
156
194
  } // Mutation
157
195
 
158
196
 
@@ -191,6 +229,13 @@ function convertHeadingElement(domNode) {
191
229
  };
192
230
  }
193
231
 
232
+ function convertBlockquoteElement() {
233
+ const node = $createQuoteNode();
234
+ return {
235
+ node
236
+ };
237
+ }
238
+
194
239
  function $createHeadingNode(headingTag) {
195
240
  return new HeadingNode(headingTag);
196
241
  }
@@ -254,38 +299,45 @@ function onPasteForRichText(event, editor) {
254
299
 
255
300
  function onCopyForRichText(event, editor) {
256
301
  event.preventDefault();
257
- editor.update(() => {
258
- const clipboardData = event.clipboardData;
259
- const selection = lexical.$getSelection();
260
-
261
- if (selection !== null) {
262
- if (clipboardData != null) {
263
- const htmlString = clipboard.$getHtmlContent(editor);
264
- const lexicalString = clipboard.$getLexicalContent(editor);
302
+ const selection = lexical.$getSelection();
265
303
 
266
- if (htmlString !== null) {
267
- clipboardData.setData('text/html', htmlString);
268
- }
304
+ if (selection !== null) {
305
+ const clipboardData = event.clipboardData;
306
+ const htmlString = clipboard.$getHtmlContent(editor);
269
307
 
270
- if (lexicalString !== null) {
271
- clipboardData.setData('application/x-lexical-editor', lexicalString);
272
- }
308
+ if (clipboardData != null) {
309
+ if (htmlString !== null) {
310
+ clipboardData.setData('text/html', htmlString);
311
+ }
273
312
 
274
- clipboardData.setData('text/plain', selection.getTextContent());
313
+ const plainString = selection.getTextContent();
314
+ clipboardData.setData('text/plain', plainString);
315
+ } else {
316
+ const clipboard = navigator.clipboard;
317
+
318
+ if (clipboard != null) {
319
+ // Most browsers only support a single item in the clipboard at one time.
320
+ // So we optimize by only putting in HTML.
321
+ const data = [new ClipboardItem({
322
+ 'text/html': new Blob([htmlString], {
323
+ type: 'text/html'
324
+ })
325
+ })];
326
+ clipboard.write(data);
275
327
  }
276
328
  }
277
- });
329
+ }
278
330
  }
279
331
 
280
332
  function onCutForRichText(event, editor) {
281
333
  onCopyForRichText(event, editor);
282
- editor.update(() => {
283
- const selection = lexical.$getSelection();
334
+ const selection = lexical.$getSelection();
284
335
 
285
- if (lexical.$isRangeSelection(selection)) {
286
- selection.removeText();
287
- }
288
- });
336
+ if (lexical.$isRangeSelection(selection)) {
337
+ selection.removeText();
338
+ } else if (lexical.$isNodeSelection(selection)) {
339
+ selection.getNodes().forEach(node => node.remove());
340
+ }
289
341
  }
290
342
 
291
343
  function handleIndentAndOutdent(insertTab, indentOrOutdent) {
@@ -354,7 +406,7 @@ function registerRichText(editor, initialEditorState) {
354
406
 
355
407
  selection.deleteLine(isBackward);
356
408
  return true;
357
- }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_TEXT_COMMAND, eventOrText => {
409
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
358
410
  const selection = lexical.$getSelection();
359
411
 
360
412
  if (typeof eventOrText === 'string') {
@@ -435,7 +487,7 @@ function registerRichText(editor, initialEditorState) {
435
487
  return true;
436
488
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
437
489
  handleIndentAndOutdent(() => {
438
- editor.dispatchCommand(lexical.INSERT_TEXT_COMMAND, '\t');
490
+ editor.dispatchCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, '\t');
439
491
  }, block => {
440
492
  const indent = block.getIndent();
441
493
 
@@ -574,8 +626,7 @@ function registerRichText(editor, initialEditorState) {
574
626
 
575
627
  if (!lexical.$isRangeSelection(selection)) {
576
628
  return false;
577
- } // TODO: Make drag and drop work at some point.
578
-
629
+ }
579
630
 
580
631
  event.preventDefault();
581
632
  return true;
@@ -584,29 +635,16 @@ function registerRichText(editor, initialEditorState) {
584
635
 
585
636
  if (!lexical.$isRangeSelection(selection)) {
586
637
  return false;
587
- } // TODO: Make drag and drop work at some point.
588
-
638
+ }
589
639
 
590
640
  event.preventDefault();
591
641
  return true;
592
642
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
593
- const selection = lexical.$getSelection();
594
-
595
- if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
596
- onCopyForRichText(event, editor);
597
- return true;
598
- }
599
-
600
- return false;
643
+ onCopyForRichText(event, editor);
644
+ return true;
601
645
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
602
- const selection = lexical.$getSelection();
603
-
604
- if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
605
- onCutForRichText(event, editor);
606
- return true;
607
- }
608
-
609
- return false;
646
+ onCutForRichText(event, editor);
647
+ return true;
610
648
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
611
649
  const selection = lexical.$getSelection();
612
650
 
@@ -4,22 +4,24 @@
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
- var a=require("@lexical/clipboard"),h=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");const 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);
8
- const 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,u={tag:"history-merge"};
9
- class v extends l.ElementNode{static getType(){return"quote"}static clone(b){return new v(b.__key)}constructor(b){super(b)}createDOM(b){const e=document.createElement("blockquote");k.addClassNamesToElement(e,b.theme.quote);return e}updateDOM(){return!1}insertNewAfter(){const b=l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){const b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}}
10
- class w extends l.ElementNode{static getType(){return"heading"}static clone(b){return new w(b.__tag,b.__key)}constructor(b,e){super(e);this.__tag=b}getTag(){return this.__tag}createDOM(b){const e=this.__tag,f=document.createElement(e);b=b.theme.heading;void 0!==b&&k.addClassNamesToElement(f,b[e]);return f}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:x,priority:0}),h2:()=>({conversion:x,priority:0}),h3:()=>({conversion:x,priority:0}),h4:()=>({conversion:x,priority:0}),h5:()=>
11
- ({conversion:x,priority:0})}}insertNewAfter(){const b=l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){const b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}extractWithChild(){return!0}}function x(b){b=b.nodeName.toLowerCase();let e=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b)e=y(b);return{node:e}}function y(b){return new w(b)}
12
- function z(b,e){if(null!==e)if(void 0===e)b.update(()=>{var f=l.$getRoot();if(null===f.getFirstChild()){const c=l.$createParagraphNode();f.append(c);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===b.getRootElement())&&c.select()}},u);else if(null!==e)switch(typeof e){case "string":e=b.parseEditorState(e);b.setEditorState(e,u);break;case "object":b.setEditorState(e,u);break;case "function":b.update(e,u)}}
13
- function A(b,e){b.preventDefault();e.update(()=>{const f=l.$getSelection(),c=b.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&a.$insertDataTransferForRichText(c,f,e)})}function B(b,e){b.preventDefault();e.update(()=>{const f=b.clipboardData,c=l.$getSelection();if(null!==c&&null!=f){const d=a.$getHtmlContent(e),g=a.$getLexicalContent(e);null!==d&&f.setData("text/html",d);null!==g&&f.setData("application/x-lexical-editor",g);f.setData("text/plain",c.getTextContent())}})}
14
- function C(b,e){B(b,e);e.update(()=>{const f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}function D(b,e){var f=l.$getSelection();if(l.$isRangeSelection(f)){var c=new Set;f=f.getNodes();for(let g=0;g<f.length;g++){const t=f[g];var d=t.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(t),d.canInsertTab()?b(t):d.canIndent()&&e(d))}}}exports.$createHeadingNode=y;exports.$createQuoteNode=function(){return new v};
15
- exports.$isHeadingNode=function(b){return b instanceof w};exports.$isQuoteNode=function(b){return b instanceof v};exports.HeadingNode=w;exports.QuoteNode=v;
16
- exports.registerRichText=function(b,e){const f=k.mergeRegister(b.registerCommand(l.CLICK_COMMAND,()=>{const c=l.$getSelection();return l.$isNodeSelection(c)?(c.clear(),!0):!1},0),b.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),b.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),
17
- b.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),b.registerCommand(l.INSERT_TEXT_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?a.$insertDataTransferForRichText(g,d,b):l.$isRangeSelection(d)&&(c=c.data)&&d.insertText(c)}return!0},
7
+ 'use strict';var a=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);
8
+ 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"};
9
+ class u extends l.ElementNode{static getType(){return"quote"}static clone(b){return new u(b.__key)}constructor(b){super(b)}createDOM(b){let e=document.createElement("blockquote");k.addClassNamesToElement(e,b.theme.quote);return e}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:w,priority:0})}}static importJSON(b){let e=x();e.setFormat(b.format);e.setIndent(b.indent);e.setDirection(b.direction);return e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let b=
10
+ l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){let b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}}function x(){return new u}
11
+ class y extends l.ElementNode{static getType(){return"heading"}static clone(b){return new y(b.__tag,b.__key)}constructor(b,e){super(e);this.__tag=b}getTag(){return this.__tag}createDOM(b){let e=this.__tag,f=document.createElement(e);b=b.theme.heading;void 0!==b&&k.addClassNamesToElement(f,b[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,
12
+ priority:0})}}static importJSON(b){let e=A(b.tag);e.setFormat(b.format);e.setIndent(b.indent);e.setDirection(b.direction);return e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let b=l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){let b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}extractWithChild(){return!0}}
13
+ function z(b){b=b.nodeName.toLowerCase();let e=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b)e=A(b);return{node:e}}function w(){return{node:x()}}function A(b){return new y(b)}
14
+ function B(b,e){if(null!==e)if(void 0===e)b.update(()=>{var f=l.$getRoot();if(null===f.getFirstChild()){let c=l.$createParagraphNode();f.append(c);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===b.getRootElement())&&c.select()}},t);else if(null!==e)switch(typeof e){case "string":e=b.parseEditorState(e);b.setEditorState(e,t);break;case "object":b.setEditorState(e,t);break;case "function":b.update(e,t)}}
15
+ function C(b,e){b.preventDefault();e.update(()=>{let f=l.$getSelection(),c=b.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&a.$insertDataTransferForRichText(c,f,e)})}
16
+ function D(b,e){b.preventDefault();var f=l.$getSelection();null!==f&&(b=b.clipboardData,e=a.$getHtmlContent(e),null!=b?(null!==e&&b.setData("text/html",e),f=f.getTextContent(),b.setData("text/plain",f)):(f=navigator.clipboard,null!=f&&(b=[new ClipboardItem({"text/html":new Blob([e],{type:"text/html"})})],f.write(b))))}function E(b,e){D(b,e);b=l.$getSelection();l.$isRangeSelection(b)?b.removeText():l.$isNodeSelection(b)&&b.getNodes().forEach(f=>f.remove())}
17
+ function F(b,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 v=f[g];var d=v.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(v),d.canInsertTab()?b(v):d.canIndent()&&e(d))}}}exports.$createHeadingNode=A;exports.$createQuoteNode=x;exports.$isHeadingNode=function(b){return b instanceof y};exports.$isQuoteNode=function(b){return b instanceof u};exports.HeadingNode=y;exports.QuoteNode=u;
18
+ exports.registerRichText=function(b,e){let f=k.mergeRegister(b.registerCommand(l.CLICK_COMMAND,()=>{const c=l.$getSelection();return l.$isNodeSelection(c)?(c.clear(),!0):!1},0),b.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),b.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),
19
+ b.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),b.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?a.$insertDataTransferForRichText(g,d,b):l.$isRangeSelection(d)&&(c=c.data)&&d.insertText(c)}return!0},
18
20
  l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),b.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),b.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);
19
- return!0},l.COMMAND_PRIORITY_EDITOR),b.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),b.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{D(()=>{b.dispatchCommand(l.INSERT_TEXT_COMMAND,"\t")},c=>{const d=c.getIndent();
20
- 10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{D(c=>{l.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,
21
+ return!0},l.COMMAND_PRIORITY_EDITOR),b.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),b.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{F(()=>{b.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d=
22
+ c.getIndent();10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{F(c=>{l.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,
21
23
  !0)?(c.preventDefault(),h.$moveCharacter(d,g,!0),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,!1)?(c.preventDefault(),h.$moveCharacter(d,g,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_BACKSPACE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=d);return d.isCollapsed()&&
22
24
  0===c.offset&&0<k.$getNearestBlockElementAncestorOrThrow(c.getNode()).getIndent()?b.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_DELETE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ENTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;
23
25
  if(null!==c){if((r||q)&&p)return!1;c.preventDefault();if(c.shiftKey)return b.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return b.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=
24
- l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.blur();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.COPY_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||
25
- l.$isGridSelection(d)?(B(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CUT_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(C(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(A(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));z(b,e);return f};
26
+ l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.blur();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.COPY_COMMAND,c=>{D(c,b);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CUT_COMMAND,
27
+ c=>{E(c,b);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(C(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));B(b,e);return f}
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "rich-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.2.8",
11
- "main": "LexicalRichText.ts",
10
+ "version": "0.3.1",
11
+ "main": "LexicalRichText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.2.8",
14
- "@lexical/selection": "0.2.8",
15
- "@lexical/clipboard": "0.2.8",
16
- "@lexical/utils": "0.2.8"
13
+ "lexical": "0.3.1",
14
+ "@lexical/selection": "0.3.1",
15
+ "@lexical/clipboard": "0.3.1",
16
+ "@lexical/utils": "0.3.1"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",