@lexical/rich-text 0.3.0 → 0.3.3

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.
@@ -17,9 +17,13 @@ import type {
17
17
  SerializedElementNode,
18
18
  } from 'lexical';
19
19
  import {ElementNode} from 'lexical';
20
- import {Spread} from 'libdefs/globals';
20
+ import type {Spread} from 'lexical';
21
21
 
22
- export type InitialEditorStateType = null | string | EditorState | (() => void);
22
+ export type InitialEditorStateType =
23
+ | null
24
+ | string
25
+ | EditorState
26
+ | ((editor: LexicalEditor) => void);
23
27
 
24
28
  export declare class QuoteNode extends ElementNode {
25
29
  static getType(): string;
@@ -35,7 +39,7 @@ export function $createQuoteNode(): QuoteNode;
35
39
  export function $isQuoteNode(
36
40
  node: LexicalNode | null | undefined,
37
41
  ): node is QuoteNode;
38
- export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
42
+ export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
39
43
  export declare class HeadingNode extends ElementNode {
40
44
  __tag: HeadingTagType;
41
45
  static getType(): string;
@@ -61,7 +65,7 @@ export function registerRichText(
61
65
 
62
66
  export type SerializedHeadingNode = Spread<
63
67
  {
64
- tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
68
+ tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
65
69
  type: 'heading';
66
70
  version: 1;
67
71
  },
@@ -173,6 +173,10 @@ class HeadingNode extends lexical.ElementNode {
173
173
  h5: node => ({
174
174
  conversion: convertHeadingElement,
175
175
  priority: 0
176
+ }),
177
+ h6: node => ({
178
+ conversion: convertHeadingElement,
179
+ priority: 0
176
180
  })
177
181
  };
178
182
  }
@@ -220,7 +224,7 @@ function convertHeadingElement(domNode) {
220
224
  const nodeName = domNode.nodeName.toLowerCase();
221
225
  let node = null;
222
226
 
223
- if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5') {
227
+ if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
224
228
  node = $createHeadingNode(nodeName);
225
229
  }
226
230
 
@@ -249,9 +253,8 @@ function initializeEditor(editor, initialEditorState) {
249
253
  } else if (initialEditorState === undefined) {
250
254
  editor.update(() => {
251
255
  const root = lexical.$getRoot();
252
- const firstChild = root.getFirstChild();
253
256
 
254
- if (firstChild === null) {
257
+ if (root.isEmpty()) {
255
258
  const paragraph = lexical.$createParagraphNode();
256
259
  root.append(paragraph);
257
260
  const activeElement = document.activeElement;
@@ -278,7 +281,13 @@ function initializeEditor(editor, initialEditorState) {
278
281
 
279
282
  case 'function':
280
283
  {
281
- editor.update(initialEditorState, updateOptions);
284
+ editor.update(() => {
285
+ const root = lexical.$getRoot();
286
+
287
+ if (root.isEmpty()) {
288
+ initialEditorState(editor);
289
+ }
290
+ }, updateOptions);
282
291
  break;
283
292
  }
284
293
  }
@@ -299,33 +308,50 @@ function onPasteForRichText(event, editor) {
299
308
 
300
309
  function onCopyForRichText(event, editor) {
301
310
  event.preventDefault();
302
- editor.update(() => {
311
+ const selection = lexical.$getSelection();
312
+
313
+ if (selection !== null) {
303
314
  const clipboardData = event.clipboardData;
304
- const selection = lexical.$getSelection();
315
+ const htmlString = clipboard.$getHtmlContent(editor);
316
+ const lexicalString = clipboard.$getLexicalContent(editor);
305
317
 
306
- if (selection !== null) {
307
- if (clipboardData != null) {
308
- const htmlString = clipboard.$getHtmlContent(editor);
318
+ if (clipboardData != null) {
319
+ if (htmlString !== null) {
320
+ clipboardData.setData('text/html', htmlString);
321
+ }
309
322
 
310
- if (htmlString !== null) {
311
- clipboardData.setData('text/html', htmlString);
312
- }
323
+ if (lexicalString !== null) {
324
+ clipboardData.setData('application/x-lexical-editor', lexicalString);
325
+ }
313
326
 
314
- clipboardData.setData('text/plain', selection.getTextContent());
327
+ const plainString = selection.getTextContent();
328
+ clipboardData.setData('text/plain', plainString);
329
+ } else {
330
+ const clipboard = navigator.clipboard;
331
+
332
+ if (clipboard != null) {
333
+ // Most browsers only support a single item in the clipboard at one time.
334
+ // So we optimize by only putting in HTML.
335
+ const data = [new ClipboardItem({
336
+ 'text/html': new Blob([htmlString], {
337
+ type: 'text/html'
338
+ })
339
+ })];
340
+ clipboard.write(data);
315
341
  }
316
342
  }
317
- });
343
+ }
318
344
  }
319
345
 
320
346
  function onCutForRichText(event, editor) {
321
347
  onCopyForRichText(event, editor);
322
- editor.update(() => {
323
- const selection = lexical.$getSelection();
348
+ const selection = lexical.$getSelection();
324
349
 
325
- if (lexical.$isRangeSelection(selection)) {
326
- selection.removeText();
327
- }
328
- });
350
+ if (lexical.$isRangeSelection(selection)) {
351
+ selection.removeText();
352
+ } else if (lexical.$isNodeSelection(selection)) {
353
+ selection.getNodes().forEach(node => node.remove());
354
+ }
329
355
  }
330
356
 
331
357
  function handleIndentAndOutdent(insertTab, indentOrOutdent) {
@@ -357,6 +383,11 @@ function handleIndentAndOutdent(insertTab, indentOrOutdent) {
357
383
  }
358
384
  }
359
385
 
386
+ function isTargetWithinDecorator(target) {
387
+ const node = lexical.$getNearestNodeFromDOMNode(target);
388
+ return lexical.$isDecoratorNode(node);
389
+ }
390
+
360
391
  function registerRichText(editor, initialEditorState) {
361
392
  const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
362
393
  const selection = lexical.$getSelection();
@@ -535,6 +566,10 @@ function registerRichText(editor, initialEditorState) {
535
566
 
536
567
  return false;
537
568
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
569
+ if (isTargetWithinDecorator(event.target)) {
570
+ return false;
571
+ }
572
+
538
573
  const selection = lexical.$getSelection();
539
574
 
540
575
  if (!lexical.$isRangeSelection(selection)) {
@@ -556,6 +591,10 @@ function registerRichText(editor, initialEditorState) {
556
591
 
557
592
  return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
558
593
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
594
+ if (isTargetWithinDecorator(event.target)) {
595
+ return false;
596
+ }
597
+
559
598
  const selection = lexical.$getSelection();
560
599
 
561
600
  if (!lexical.$isRangeSelection(selection)) {
@@ -628,23 +667,11 @@ function registerRichText(editor, initialEditorState) {
628
667
  event.preventDefault();
629
668
  return true;
630
669
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
631
- const selection = lexical.$getSelection();
632
-
633
- if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
634
- onCopyForRichText(event, editor);
635
- return true;
636
- }
637
-
638
- return false;
670
+ onCopyForRichText(event, editor);
671
+ return true;
639
672
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
640
- const selection = lexical.$getSelection();
641
-
642
- if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
643
- onCutForRichText(event, editor);
644
- return true;
645
- }
646
-
647
- return false;
673
+ onCutForRichText(event, editor);
674
+ return true;
648
675
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
649
676
  const selection = lexical.$getSelection();
650
677
 
@@ -16,7 +16,11 @@ import type {
16
16
  LexicalEditor,
17
17
  } from 'lexical';
18
18
  import {ElementNode} from 'lexical';
19
- export type InitialEditorStateType = null | string | EditorState | (() => void);
19
+ export type InitialEditorStateType =
20
+ | null
21
+ | string
22
+ | EditorState
23
+ | ((editor: LexicalEditor) => void);
20
24
 
21
25
  declare export class QuoteNode extends ElementNode {
22
26
  static getType(): string;
@@ -31,7 +35,7 @@ declare export function $createQuoteNode(): QuoteNode;
31
35
  declare export function $isQuoteNode(
32
36
  node: ?LexicalNode,
33
37
  ): boolean %checks(node instanceof QuoteNode);
34
- export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
38
+ export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
35
39
  declare export class HeadingNode extends ElementNode {
36
40
  __tag: HeadingTagType;
37
41
  static getType(): string;
@@ -4,24 +4,25 @@
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"),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);
7
+ '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);
8
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)})}function D(b,e){b.preventDefault();e.update(()=>{let f=b.clipboardData,c=l.$getSelection();if(null!==c&&null!=f){let d=a.$getHtmlContent(e);null!==d&&f.setData("text/html",d);f.setData("text/plain",c.getTextContent())}})}
16
- function E(b,e){D(b,e);e.update(()=>{let f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}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};
17
- 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},
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);
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,
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()&&
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;
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=
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=>{const d=l.$getSelection();return l.$isRangeSelection(d)||
27
- l.$isGridSelection(d)?(D(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)?(E(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)?(C(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));B(b,e);return f}
9
+ 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:w,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=
10
+ 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}
11
+ 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,
12
+ priority:0}),h6:()=>({conversion:z,priority:0})}}static importJSON(a){let e=A(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}}
13
+ function z(a){a=a.nodeName.toLowerCase();let e=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)e=A(a);return{node:e}}function w(){return{node:x()}}function A(a){return new y(a)}
14
+ function B(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)}}
15
+ function C(a,e){a.preventDefault();e.update(()=>{let f=l.$getSelection(),c=a.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&b.$insertDataTransferForRichText(c,f,e)})}
16
+ function D(a,e){a.preventDefault();var f=l.$getSelection();if(null!==f){a=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)))}}
17
+ function E(a,e){D(a,e);a=l.$getSelection();l.$isRangeSelection(a)?a.removeText():l.$isNodeSelection(a)&&a.getNodes().forEach(f=>f.remove())}function F(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 v=f[g];var d=v.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(v),d.canInsertTab()?a(v):d.canIndent()&&e(d))}}}function G(a){a=l.$getNearestNodeFromDOMNode(a);return l.$isDecoratorNode(a)}
18
+ exports.$createHeadingNode=A;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;
19
+ 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),
20
+ 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},
21
+ 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);
22
+ 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,()=>{F(()=>{a.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d=
23
+ c.getIndent();10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{F(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_LEFT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,
24
+ !0)?(c.preventDefault(),h.$moveCharacter(d,g,!0),!0):!1},l.COMMAND_PRIORITY_EDITOR),a.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),a.registerCommand(l.KEY_BACKSPACE_COMMAND,c=>{if(G(c.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=
25
+ d);return d.isCollapsed()&&0===c.offset&&0<k.$getNearestBlockElementAncestorOrThrow(c.getNode()).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(G(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,
26
+ 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),
27
+ 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=>
28
+ {D(c,a);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.CUT_COMMAND,c=>{E(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)?(C(c,a),!0):!1},l.COMMAND_PRIORITY_EDITOR));B(a,e);return f}
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "rich-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.3.0",
10
+ "version": "0.3.3",
11
11
  "main": "LexicalRichText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.3.0",
14
- "@lexical/selection": "0.3.0",
15
- "@lexical/clipboard": "0.3.0",
16
- "@lexical/utils": "0.3.0"
13
+ "lexical": "0.3.3",
14
+ "@lexical/selection": "0.3.3",
15
+ "@lexical/clipboard": "0.3.3",
16
+ "@lexical/utils": "0.3.3"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",