@lexical/rich-text 0.8.0 → 0.9.0

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.
@@ -18,24 +18,26 @@ var lexical = require('lexical');
18
18
  * LICENSE file in the root directory of this source tree.
19
19
  *
20
20
  */
21
-
22
21
  function caretFromPoint(x, y) {
23
22
  if (typeof document.caretRangeFromPoint !== 'undefined') {
24
23
  const range = document.caretRangeFromPoint(x, y);
24
+
25
25
  if (range === null) {
26
26
  return null;
27
27
  }
28
+
28
29
  return {
29
30
  node: range.startContainer,
30
31
  offset: range.startOffset
31
- };
32
- // @ts-ignore
32
+ }; // @ts-ignore
33
33
  } else if (document.caretPositionFromPoint !== 'undefined') {
34
34
  // @ts-ignore FF - no types
35
35
  const range = document.caretPositionFromPoint(x, y);
36
+
36
37
  if (range === null) {
37
38
  return null;
38
39
  }
40
+
39
41
  return {
40
42
  node: range.offsetNode,
41
43
  offset: range.offset
@@ -53,7 +55,6 @@ function caretFromPoint(x, y) {
53
55
  * LICENSE file in the root directory of this source tree.
54
56
  *
55
57
  */
56
-
57
58
  const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
58
59
 
59
60
  /**
@@ -68,37 +69,41 @@ CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
68
69
  CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
69
70
  const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
70
71
  const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
71
- const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
72
-
73
- // Keep these in case we need to use them in the future.
72
+ const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; // Keep these in case we need to use them in the future.
74
73
  // export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
75
- CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
76
- // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
74
+
75
+ const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent); // export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
76
+
77
+ const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
77
78
 
78
79
  /** @module @lexical/rich-text */
79
80
  const DRAG_DROP_PASTE = lexical.createCommand('DRAG_DROP_PASTE_FILE');
81
+
80
82
  /** @noInheritDoc */
81
83
  class QuoteNode extends lexical.ElementNode {
82
84
  static getType() {
83
85
  return 'quote';
84
86
  }
87
+
85
88
  static clone(node) {
86
89
  return new QuoteNode(node.__key);
87
90
  }
91
+
88
92
  constructor(key) {
89
93
  super(key);
90
- }
94
+ } // View
91
95
 
92
- // View
93
96
 
94
97
  createDOM(config) {
95
98
  const element = document.createElement('blockquote');
96
99
  utils.addClassNamesToElement(element, config.theme.quote);
97
100
  return element;
98
101
  }
102
+
99
103
  updateDOM(prevNode, dom) {
100
104
  return false;
101
105
  }
106
+
102
107
  static importDOM() {
103
108
  return {
104
109
  blockquote: node => ({
@@ -107,6 +112,7 @@ class QuoteNode extends lexical.ElementNode {
107
112
  })
108
113
  };
109
114
  }
115
+
110
116
  static importJSON(serializedNode) {
111
117
  const node = $createQuoteNode();
112
118
  node.setFormat(serializedNode.format);
@@ -114,14 +120,13 @@ class QuoteNode extends lexical.ElementNode {
114
120
  node.setDirection(serializedNode.direction);
115
121
  return node;
116
122
  }
123
+
117
124
  exportJSON() {
118
- return {
119
- ...super.exportJSON(),
125
+ return { ...super.exportJSON(),
120
126
  type: 'quote'
121
127
  };
122
- }
128
+ } // Mutation
123
129
 
124
- // Mutation
125
130
 
126
131
  insertNewAfter(_, restoreSelection) {
127
132
  const newBlock = lexical.$createParagraphNode();
@@ -130,6 +135,7 @@ class QuoteNode extends lexical.ElementNode {
130
135
  this.insertAfter(newBlock, restoreSelection);
131
136
  return newBlock;
132
137
  }
138
+
133
139
  collapseAtStart() {
134
140
  const paragraph = lexical.$createParagraphNode();
135
141
  const children = this.getChildren();
@@ -137,6 +143,7 @@ class QuoteNode extends lexical.ElementNode {
137
143
  this.replace(paragraph);
138
144
  return true;
139
145
  }
146
+
140
147
  }
141
148
  function $createQuoteNode() {
142
149
  return lexical.$applyNodeReplacement(new QuoteNode());
@@ -144,40 +151,46 @@ function $createQuoteNode() {
144
151
  function $isQuoteNode(node) {
145
152
  return node instanceof QuoteNode;
146
153
  }
154
+
147
155
  /** @noInheritDoc */
148
156
  class HeadingNode extends lexical.ElementNode {
149
157
  /** @internal */
150
-
151
158
  static getType() {
152
159
  return 'heading';
153
160
  }
161
+
154
162
  static clone(node) {
155
163
  return new HeadingNode(node.__tag, node.__key);
156
164
  }
165
+
157
166
  constructor(tag, key) {
158
167
  super(key);
159
168
  this.__tag = tag;
160
169
  }
170
+
161
171
  getTag() {
162
172
  return this.__tag;
163
- }
173
+ } // View
164
174
 
165
- // View
166
175
 
167
176
  createDOM(config) {
168
177
  const tag = this.__tag;
169
178
  const element = document.createElement(tag);
170
179
  const theme = config.theme;
171
180
  const classNames = theme.heading;
181
+
172
182
  if (classNames !== undefined) {
173
183
  const className = classNames[tag];
174
184
  utils.addClassNamesToElement(element, className);
175
185
  }
186
+
176
187
  return element;
177
188
  }
189
+
178
190
  updateDOM(prevNode, dom) {
179
191
  return false;
180
192
  }
193
+
181
194
  static importDOM() {
182
195
  return {
183
196
  h1: node => ({
@@ -208,6 +221,7 @@ class HeadingNode extends lexical.ElementNode {
208
221
  // domNode is a <p> since we matched it by nodeName
209
222
  const paragraph = node;
210
223
  const firstChild = paragraph.firstChild;
224
+
211
225
  if (firstChild !== null && isGoogleDocsTitle(firstChild)) {
212
226
  return {
213
227
  conversion: () => ({
@@ -216,6 +230,7 @@ class HeadingNode extends lexical.ElementNode {
216
230
  priority: 3
217
231
  };
218
232
  }
233
+
219
234
  return null;
220
235
  },
221
236
  span: node => {
@@ -229,10 +244,12 @@ class HeadingNode extends lexical.ElementNode {
229
244
  priority: 3
230
245
  };
231
246
  }
247
+
232
248
  return null;
233
249
  }
234
250
  };
235
251
  }
252
+
236
253
  static importJSON(serializedNode) {
237
254
  const node = $createHeadingNode(serializedNode.tag);
238
255
  node.setFormat(serializedNode.format);
@@ -240,16 +257,16 @@ class HeadingNode extends lexical.ElementNode {
240
257
  node.setDirection(serializedNode.direction);
241
258
  return node;
242
259
  }
260
+
243
261
  exportJSON() {
244
- return {
245
- ...super.exportJSON(),
262
+ return { ...super.exportJSON(),
246
263
  tag: this.getTag(),
247
264
  type: 'heading',
248
265
  version: 1
249
266
  };
250
- }
267
+ } // Mutation
268
+
251
269
 
252
- // Mutation
253
270
  insertNewAfter(selection, restoreSelection = true) {
254
271
  const anchorOffet = selection ? selection.anchor.offset : 0;
255
272
  const newElement = anchorOffet > 0 && anchorOffet < this.getTextContentSize() ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
@@ -258,6 +275,7 @@ class HeadingNode extends lexical.ElementNode {
258
275
  this.insertAfter(newElement, restoreSelection);
259
276
  return newElement;
260
277
  }
278
+
261
279
  collapseAtStart() {
262
280
  const newElement = !this.isEmpty() ? $createHeadingNode(this.getTag()) : lexical.$createParagraphNode();
263
281
  const children = this.getChildren();
@@ -265,43 +283,54 @@ class HeadingNode extends lexical.ElementNode {
265
283
  this.replace(newElement);
266
284
  return true;
267
285
  }
286
+
268
287
  extractWithChild() {
269
288
  return true;
270
289
  }
290
+
271
291
  }
292
+
272
293
  function isGoogleDocsTitle(domNode) {
273
294
  if (domNode.nodeName.toLowerCase() === 'span') {
274
295
  return domNode.style.fontSize === '26pt';
275
296
  }
297
+
276
298
  return false;
277
299
  }
300
+
278
301
  function convertHeadingElement(domNode) {
279
302
  const nodeName = domNode.nodeName.toLowerCase();
280
303
  let node = null;
304
+
281
305
  if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
282
306
  node = $createHeadingNode(nodeName);
283
307
  }
308
+
284
309
  return {
285
310
  node
286
311
  };
287
312
  }
313
+
288
314
  function convertBlockquoteElement() {
289
315
  const node = $createQuoteNode();
290
316
  return {
291
317
  node
292
318
  };
293
319
  }
320
+
294
321
  function $createHeadingNode(headingTag) {
295
322
  return lexical.$applyNodeReplacement(new HeadingNode(headingTag));
296
323
  }
297
324
  function $isHeadingNode(node) {
298
325
  return node instanceof HeadingNode;
299
326
  }
327
+
300
328
  function onPasteForRichText(event, editor) {
301
329
  event.preventDefault();
302
330
  editor.update(() => {
303
331
  const selection = lexical.$getSelection();
304
332
  const clipboardData = event instanceof InputEvent || event instanceof KeyboardEvent ? null : event.clipboardData;
333
+
305
334
  if (clipboardData != null && (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
306
335
  clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
307
336
  }
@@ -309,51 +338,63 @@ function onPasteForRichText(event, editor) {
309
338
  tag: 'paste'
310
339
  });
311
340
  }
341
+
312
342
  async function onCutForRichText(event, editor) {
313
- await clipboard.copyToClipboard__EXPERIMENTAL(editor, event instanceof ClipboardEvent ? event : null);
343
+ await clipboard.copyToClipboard(editor, event instanceof ClipboardEvent ? event : null);
314
344
  editor.update(() => {
315
345
  const selection = lexical.$getSelection();
346
+
316
347
  if (lexical.$isRangeSelection(selection)) {
317
348
  selection.removeText();
318
349
  } else if (lexical.$isNodeSelection(selection)) {
319
350
  selection.getNodes().forEach(node => node.remove());
320
351
  }
321
352
  });
322
- }
323
-
324
- // Clipboard may contain files that we aren't allowed to read. While the event is arguably useless,
353
+ } // Clipboard may contain files that we aren't allowed to read. While the event is arguably useless,
325
354
  // in certain ocassions, we want to know whether it was a file transfer, as opposed to text. We
326
355
  // control this with the first boolean flag.
356
+
357
+
327
358
  function eventFiles(event) {
328
359
  let dataTransfer = null;
360
+
329
361
  if (event instanceof DragEvent) {
330
362
  dataTransfer = event.dataTransfer;
331
363
  } else if (event instanceof ClipboardEvent) {
332
364
  dataTransfer = event.clipboardData;
333
365
  }
366
+
334
367
  if (dataTransfer === null) {
335
368
  return [false, [], false];
336
369
  }
370
+
337
371
  const types = dataTransfer.types;
338
372
  const hasFiles = types.includes('Files');
339
373
  const hasContent = types.includes('text/html') || types.includes('text/plain');
340
374
  return [hasFiles, Array.from(dataTransfer.files), hasContent];
341
375
  }
376
+
342
377
  function handleIndentAndOutdent(insertTab, indentOrOutdent) {
343
378
  const selection = lexical.$getSelection();
379
+
344
380
  if (!lexical.$isRangeSelection(selection)) {
345
381
  return;
346
382
  }
383
+
347
384
  const alreadyHandled = new Set();
348
385
  const nodes = selection.getNodes();
386
+
349
387
  for (let i = 0; i < nodes.length; i++) {
350
388
  const node = nodes[i];
351
389
  const key = node.getKey();
390
+
352
391
  if (alreadyHandled.has(key)) {
353
392
  continue;
354
393
  }
394
+
355
395
  const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(node);
356
396
  const parentKey = parentBlock.getKey();
397
+
357
398
  if (parentBlock.canInsertTab()) {
358
399
  insertTab(node);
359
400
  alreadyHandled.add(key);
@@ -363,45 +404,57 @@ function handleIndentAndOutdent(insertTab, indentOrOutdent) {
363
404
  }
364
405
  }
365
406
  }
407
+
366
408
  function $isTargetWithinDecorator(target) {
367
409
  const node = lexical.$getNearestNodeFromDOMNode(target);
368
410
  return lexical.$isDecoratorNode(node);
369
411
  }
412
+
370
413
  function $isSelectionAtEndOfRoot(selection) {
371
414
  const focus = selection.focus;
372
415
  return focus.key === 'root' && focus.offset === lexical.$getRoot().getChildrenSize();
373
416
  }
417
+
374
418
  function registerRichText(editor) {
375
419
  const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
376
420
  const selection = lexical.$getSelection();
421
+
377
422
  if (lexical.$isNodeSelection(selection)) {
378
423
  selection.clear();
379
424
  return true;
380
425
  }
426
+
381
427
  return false;
382
428
  }, 0), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
383
429
  const selection = lexical.$getSelection();
430
+
384
431
  if (!lexical.$isRangeSelection(selection)) {
385
432
  return false;
386
433
  }
434
+
387
435
  selection.deleteCharacter(isBackward);
388
436
  return true;
389
437
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
390
438
  const selection = lexical.$getSelection();
439
+
391
440
  if (!lexical.$isRangeSelection(selection)) {
392
441
  return false;
393
442
  }
443
+
394
444
  selection.deleteWord(isBackward);
395
445
  return true;
396
446
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
397
447
  const selection = lexical.$getSelection();
448
+
398
449
  if (!lexical.$isRangeSelection(selection)) {
399
450
  return false;
400
451
  }
452
+
401
453
  selection.deleteLine(isBackward);
402
454
  return true;
403
455
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
404
456
  const selection = lexical.$getSelection();
457
+
405
458
  if (typeof eventOrText === 'string') {
406
459
  if (lexical.$isRangeSelection(selection)) {
407
460
  selection.insertText(eventOrText);
@@ -410,55 +463,72 @@ function registerRichText(editor) {
410
463
  if (!lexical.$isRangeSelection(selection) && !lexical.DEPRECATED_$isGridSelection(selection)) {
411
464
  return false;
412
465
  }
466
+
413
467
  const dataTransfer = eventOrText.dataTransfer;
468
+
414
469
  if (dataTransfer != null) {
415
470
  clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
416
471
  } else if (lexical.$isRangeSelection(selection)) {
417
472
  const data = eventOrText.data;
473
+
418
474
  if (data) {
419
475
  selection.insertText(data);
420
476
  }
477
+
421
478
  return true;
422
479
  }
423
480
  }
481
+
424
482
  return true;
425
483
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, () => {
426
484
  const selection = lexical.$getSelection();
485
+
427
486
  if (!lexical.$isRangeSelection(selection)) {
428
487
  return false;
429
488
  }
489
+
430
490
  selection.removeText();
431
491
  return true;
432
492
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, format => {
433
493
  const selection = lexical.$getSelection();
494
+
434
495
  if (!lexical.$isRangeSelection(selection)) {
435
496
  return false;
436
497
  }
498
+
437
499
  selection.formatText(format);
438
500
  return true;
439
501
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, format => {
440
502
  const selection = lexical.$getSelection();
503
+
441
504
  if (!lexical.$isRangeSelection(selection) && !lexical.$isNodeSelection(selection)) {
442
505
  return false;
443
506
  }
507
+
444
508
  const nodes = selection.getNodes();
509
+
445
510
  for (const node of nodes) {
446
511
  const element = utils.$getNearestBlockElementAncestorOrThrow(node);
447
512
  element.setFormat(format);
448
513
  }
514
+
449
515
  return true;
450
516
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
451
517
  const selection = lexical.$getSelection();
518
+
452
519
  if (!lexical.$isRangeSelection(selection)) {
453
520
  return false;
454
521
  }
522
+
455
523
  selection.insertLineBreak(selectStart);
456
524
  return true;
457
525
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
458
526
  const selection = lexical.$getSelection();
527
+
459
528
  if (!lexical.$isRangeSelection(selection)) {
460
529
  return false;
461
530
  }
531
+
462
532
  selection.insertParagraph();
463
533
  return true;
464
534
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
@@ -466,6 +536,7 @@ function registerRichText(editor) {
466
536
  editor.dispatchCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, '\t');
467
537
  }, block => {
468
538
  const indent = block.getIndent();
539
+
469
540
  if (indent !== 10) {
470
541
  block.setIndent(indent + 1);
471
542
  }
@@ -476,12 +547,14 @@ function registerRichText(editor) {
476
547
  if (lexical.$isTextNode(node)) {
477
548
  const textContent = node.getTextContent();
478
549
  const character = textContent[textContent.length - 1];
550
+
479
551
  if (character === '\t') {
480
552
  editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
481
553
  }
482
554
  }
483
555
  }, block => {
484
556
  const indent = block.getIndent();
557
+
485
558
  if (indent !== 0) {
486
559
  block.setIndent(indent - 1);
487
560
  }
@@ -489,16 +562,19 @@ function registerRichText(editor) {
489
562
  return true;
490
563
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_UP_COMMAND, event => {
491
564
  const selection = lexical.$getSelection();
565
+
492
566
  if (lexical.$isNodeSelection(selection) && !$isTargetWithinDecorator(event.target)) {
493
567
  // If selection is on a node, let's try and move selection
494
568
  // back to being a range selection.
495
569
  const nodes = selection.getNodes();
570
+
496
571
  if (nodes.length > 0) {
497
572
  nodes[0].selectPrevious();
498
573
  return true;
499
574
  }
500
575
  } else if (lexical.$isRangeSelection(selection)) {
501
576
  const possibleNode = lexical.$getAdjacentNode(selection.focus, true);
577
+
502
578
  if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated() && !possibleNode.isInline()) {
503
579
  possibleNode.selectPrevious();
504
580
  event.preventDefault();
@@ -509,13 +585,16 @@ function registerRichText(editor) {
509
585
  return true;
510
586
  }
511
587
  }
588
+
512
589
  return false;
513
590
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
514
591
  const selection = lexical.$getSelection();
592
+
515
593
  if (lexical.$isNodeSelection(selection)) {
516
594
  // If selection is on a node, let's try and move selection
517
595
  // back to being a range selection.
518
596
  const nodes = selection.getNodes();
597
+
519
598
  if (nodes.length > 0) {
520
599
  nodes[0].selectNext(0, 0);
521
600
  return true;
@@ -525,93 +604,118 @@ function registerRichText(editor) {
525
604
  event.preventDefault();
526
605
  return true;
527
606
  }
607
+
528
608
  const possibleNode = lexical.$getAdjacentNode(selection.focus, false);
609
+
529
610
  if (lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated() && !possibleNode.isInline()) {
530
611
  possibleNode.selectNext();
531
612
  event.preventDefault();
532
613
  return true;
533
614
  }
534
615
  }
616
+
535
617
  return false;
536
618
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => {
537
619
  const selection$1 = lexical.$getSelection();
620
+
538
621
  if (lexical.$isNodeSelection(selection$1)) {
539
622
  // If selection is on a node, let's try and move selection
540
623
  // back to being a range selection.
541
624
  const nodes = selection$1.getNodes();
625
+
542
626
  if (nodes.length > 0) {
543
627
  event.preventDefault();
544
628
  nodes[0].selectPrevious();
545
629
  return true;
546
630
  }
547
631
  }
632
+
548
633
  if (!lexical.$isRangeSelection(selection$1)) {
549
634
  return false;
550
635
  }
636
+
551
637
  if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
552
638
  const isHoldingShift = event.shiftKey;
553
639
  event.preventDefault();
554
640
  selection.$moveCharacter(selection$1, isHoldingShift, true);
555
641
  return true;
556
642
  }
643
+
557
644
  return false;
558
645
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => {
559
646
  const selection$1 = lexical.$getSelection();
647
+
560
648
  if (lexical.$isNodeSelection(selection$1) && !$isTargetWithinDecorator(event.target)) {
561
649
  // If selection is on a node, let's try and move selection
562
650
  // back to being a range selection.
563
651
  const nodes = selection$1.getNodes();
652
+
564
653
  if (nodes.length > 0) {
565
654
  event.preventDefault();
566
655
  nodes[0].selectNext(0, 0);
567
656
  return true;
568
657
  }
569
658
  }
659
+
570
660
  if (!lexical.$isRangeSelection(selection$1)) {
571
661
  return false;
572
662
  }
663
+
573
664
  const isHoldingShift = event.shiftKey;
665
+
574
666
  if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
575
667
  event.preventDefault();
576
668
  selection.$moveCharacter(selection$1, isHoldingShift, false);
577
669
  return true;
578
670
  }
671
+
579
672
  return false;
580
673
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
581
674
  if ($isTargetWithinDecorator(event.target)) {
582
675
  return false;
583
676
  }
677
+
584
678
  const selection = lexical.$getSelection();
679
+
585
680
  if (!lexical.$isRangeSelection(selection)) {
586
681
  return false;
587
682
  }
683
+
588
684
  event.preventDefault();
589
685
  const {
590
686
  anchor
591
687
  } = selection;
592
688
  const anchorNode = anchor.getNode();
689
+
593
690
  if (selection.isCollapsed() && anchor.offset === 0 && !lexical.$isRootNode(anchorNode)) {
594
691
  const element = utils.$getNearestBlockElementAncestorOrThrow(anchorNode);
692
+
595
693
  if (element.getIndent() > 0) {
596
694
  return editor.dispatchCommand(lexical.OUTDENT_CONTENT_COMMAND, undefined);
597
695
  }
598
696
  }
697
+
599
698
  return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
600
699
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
601
700
  if ($isTargetWithinDecorator(event.target)) {
602
701
  return false;
603
702
  }
703
+
604
704
  const selection = lexical.$getSelection();
705
+
605
706
  if (!lexical.$isRangeSelection(selection)) {
606
707
  return false;
607
708
  }
709
+
608
710
  event.preventDefault();
609
711
  return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
610
712
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
611
713
  const selection = lexical.$getSelection();
714
+
612
715
  if (!lexical.$isRangeSelection(selection)) {
613
716
  return false;
614
717
  }
718
+
615
719
  if (event !== null) {
616
720
  // If we have beforeinput, then we can avoid blocking
617
721
  // the default behavior. This ensures that the iOS can
@@ -620,36 +724,45 @@ function registerRichText(editor) {
620
724
  // This can also cause a strange performance issue in
621
725
  // Safari, where there is a noticeable pause due to
622
726
  // preventing the key down of enter.
623
- if ((IS_IOS || IS_SAFARI) && CAN_USE_BEFORE_INPUT) {
727
+ if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
624
728
  return false;
625
729
  }
730
+
626
731
  event.preventDefault();
732
+
627
733
  if (event.shiftKey) {
628
734
  return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND, false);
629
735
  }
630
736
  }
737
+
631
738
  return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND, undefined);
632
739
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, () => {
633
740
  const selection = lexical.$getSelection();
741
+
634
742
  if (!lexical.$isRangeSelection(selection)) {
635
743
  return false;
636
744
  }
745
+
637
746
  editor.blur();
638
747
  return true;
639
748
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => {
640
749
  const [, files] = eventFiles(event);
750
+
641
751
  if (files.length > 0) {
642
752
  const x = event.clientX;
643
753
  const y = event.clientY;
644
754
  const eventRange = caretFromPoint(x, y);
755
+
645
756
  if (eventRange !== null) {
646
757
  const {
647
758
  offset: domOffset,
648
759
  node: domNode
649
760
  } = eventRange;
650
761
  const node = lexical.$getNearestNodeFromDOMNode(domNode);
762
+
651
763
  if (node !== null) {
652
764
  const selection = lexical.$createRangeSelection();
765
+
653
766
  if (lexical.$isTextNode(node)) {
654
767
  selection.anchor.set(node.getKey(), domOffset, 'text');
655
768
  selection.focus.set(node.getKey(), domOffset, 'text');
@@ -659,61 +772,78 @@ function registerRichText(editor) {
659
772
  selection.anchor.set(parentKey, offset, 'element');
660
773
  selection.focus.set(parentKey, offset, 'element');
661
774
  }
775
+
662
776
  const normalizedSelection = lexical.$normalizeSelection__EXPERIMENTAL(selection);
663
777
  lexical.$setSelection(normalizedSelection);
664
778
  }
779
+
665
780
  editor.dispatchCommand(DRAG_DROP_PASTE, files);
666
781
  }
782
+
667
783
  event.preventDefault();
668
784
  return true;
669
785
  }
786
+
670
787
  const selection = lexical.$getSelection();
788
+
671
789
  if (lexical.$isRangeSelection(selection)) {
672
790
  return true;
673
791
  }
792
+
674
793
  return false;
675
794
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
676
795
  const [isFileTransfer] = eventFiles(event);
677
796
  const selection = lexical.$getSelection();
797
+
678
798
  if (isFileTransfer && !lexical.$isRangeSelection(selection)) {
679
799
  return false;
680
800
  }
801
+
681
802
  return true;
682
803
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGOVER_COMMAND, event => {
683
804
  const [isFileTransfer] = eventFiles(event);
684
805
  const selection = lexical.$getSelection();
806
+
685
807
  if (isFileTransfer && !lexical.$isRangeSelection(selection)) {
686
808
  return false;
687
809
  }
810
+
688
811
  const x = event.clientX;
689
812
  const y = event.clientY;
690
813
  const eventRange = caretFromPoint(x, y);
814
+
691
815
  if (eventRange !== null) {
692
816
  const node = lexical.$getNearestNodeFromDOMNode(eventRange.node);
817
+
693
818
  if (lexical.$isDecoratorNode(node)) {
694
819
  // Show browser caret as the user is dragging the media across the screen. Won't work
695
820
  // for DecoratorNode nor it's relevant.
696
821
  event.preventDefault();
697
822
  }
698
823
  }
824
+
699
825
  return true;
700
826
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
701
- clipboard.copyToClipboard__EXPERIMENTAL(editor, event instanceof ClipboardEvent ? event : null);
827
+ clipboard.copyToClipboard(editor, event instanceof ClipboardEvent ? event : null);
702
828
  return true;
703
829
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
704
830
  onCutForRichText(event, editor);
705
831
  return true;
706
832
  }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
707
833
  const [, files, hasTextContent] = eventFiles(event);
834
+
708
835
  if (files.length > 0 && !hasTextContent) {
709
836
  editor.dispatchCommand(DRAG_DROP_PASTE, files);
710
837
  return true;
711
838
  }
839
+
712
840
  const selection = lexical.$getSelection();
841
+
713
842
  if (lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection)) {
714
843
  onPasteForRichText(event, editor);
715
844
  return true;
716
845
  }
846
+
717
847
  return false;
718
848
  }, lexical.COMMAND_PRIORITY_EDITOR));
719
849
  return removeListener;
@@ -5,28 +5,28 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var a=require("@lexical/clipboard"),g=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");function m(c,b){return"undefined"!==typeof document.caretRangeFromPoint?(c=document.caretRangeFromPoint(c,b),null===c?null:{node:c.startContainer,offset:c.startOffset}):"undefined"!==document.caretPositionFromPoint?(c=document.caretPositionFromPoint(c,b),null===c?null:{node:c.offsetNode,offset:c.offset}):null}
8
- let p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,q=p&&"documentMode"in document?document.documentMode:null;p&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);let r=p&&"InputEvent"in window&&!q?"getTargetRanges"in new window.InputEvent("input"):!1,t=p&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),u=p&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;
9
- p&&/^(?=.*Chrome).*/i.test(navigator.userAgent);let w=l.createCommand("DRAG_DROP_PASTE_FILE");
10
- class x extends l.ElementNode{static getType(){return"quote"}static clone(c){return new x(c.__key)}constructor(c){super(c)}createDOM(c){let b=document.createElement("blockquote");k.addClassNamesToElement(b,c.theme.quote);return b}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:y,priority:0})}}static importJSON(c){let b=z();b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(c,
11
- b){c=l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=l.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}}function z(){return l.$applyNodeReplacement(new x)}
12
- class A extends l.ElementNode{static getType(){return"heading"}static clone(c){return new A(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&&k.addClassNamesToElement(d,c[b]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:B,priority:0}),h2:()=>({conversion:B,priority:0}),h3:()=>({conversion:B,priority:0}),h4:()=>({conversion:B,priority:0}),h5:()=>({conversion:B,
13
- priority:0}),h6:()=>({conversion:B,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,b=!0){c=c?c.anchor.offset:0;c=0<c&&c<this.getTextContentSize()?E(this.getTag()):
14
- l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=this.isEmpty()?l.$createParagraphNode():E(this.getTag());this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}extractWithChild(){return!0}}function D(c){return"span"===c.nodeName.toLowerCase()?"26pt"===c.style.fontSize:!1}function B(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}}
15
- function y(){return{node:z()}}function E(c){return l.$applyNodeReplacement(new A(c))}function F(c,b){c.preventDefault();b.update(()=>{let d=l.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(l.$isRangeSelection(d)||l.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
16
- async function G(c,b){await a.copyToClipboard__EXPERIMENTAL(b,c instanceof ClipboardEvent?c:null);b.update(()=>{let d=l.$getSelection();l.$isRangeSelection(d)?d.removeText():l.$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]}
17
- function I(c,b){var d=l.$getSelection();if(l.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let f=0;f<d.length;f++){let n=d[f],v=n.getKey();if(e.has(v))continue;let h=k.$getNearestBlockElementAncestorOrThrow(n),C=h.getKey();h.canInsertTab()?(c(n),e.add(v)):h.canIndent()&&!e.has(C)&&(e.add(C),b(h))}}}function J(c){c=l.$getNearestNodeFromDOMNode(c);return l.$isDecoratorNode(c)}exports.$createHeadingNode=E;exports.$createQuoteNode=z;exports.$isHeadingNode=function(c){return c instanceof A};
18
- exports.$isQuoteNode=function(c){return c instanceof x};exports.DRAG_DROP_PASTE=w;exports.HeadingNode=A;exports.QuoteNode=x;exports.eventFiles=H;
8
+ let p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,q=p&&"documentMode"in document?document.documentMode:null;p&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
9
+ let r=p&&"InputEvent"in window&&!q?"getTargetRanges"in new window.InputEvent("input"):!1,t=p&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),u=p&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,w=p&&/^(?=.*Chrome).*/i.test(navigator.userAgent),x=p&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!w,y=l.createCommand("DRAG_DROP_PASTE_FILE");
10
+ class z extends l.ElementNode{static getType(){return"quote"}static clone(c){return new z(c.__key)}constructor(c){super(c)}createDOM(c){let b=document.createElement("blockquote");k.addClassNamesToElement(b,c.theme.quote);return b}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:A,priority:0})}}static importJSON(c){let b=B();b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(c,
11
+ b){c=l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=l.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}}function B(){return l.$applyNodeReplacement(new z)}
12
+ class D extends l.ElementNode{static getType(){return"heading"}static clone(c){return new D(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&&k.addClassNamesToElement(d,c[b]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:E,priority:0}),h2:()=>({conversion:E,priority:0}),h3:()=>({conversion:E,priority:0}),h4:()=>({conversion:E,priority:0}),h5:()=>({conversion:E,
13
+ priority:0}),h6:()=>({conversion:E,priority:0}),p:c=>{c=c.firstChild;return null!==c&&F(c)?{conversion:()=>({node:null}),priority:3}:null},span:c=>F(c)?{conversion:()=>({node:G("h1")}),priority:3}:null}}static importJSON(c){let b=G(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,b=!0){c=c?c.anchor.offset:0;c=0<c&&c<this.getTextContentSize()?G(this.getTag()):
14
+ l.$createParagraphNode();let d=this.getDirection();c.setDirection(d);this.insertAfter(c,b);return c}collapseAtStart(){let c=this.isEmpty()?l.$createParagraphNode():G(this.getTag());this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}extractWithChild(){return!0}}function F(c){return"span"===c.nodeName.toLowerCase()?"26pt"===c.style.fontSize:!1}function E(c){c=c.nodeName.toLowerCase();let b=null;if("h1"===c||"h2"===c||"h3"===c||"h4"===c||"h5"===c||"h6"===c)b=G(c);return{node:b}}
15
+ function A(){return{node:B()}}function G(c){return l.$applyNodeReplacement(new D(c))}function H(c,b){c.preventDefault();b.update(()=>{let d=l.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(l.$isRangeSelection(d)||l.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
16
+ async function I(c,b){await a.copyToClipboard(b,c instanceof ClipboardEvent?c:null);b.update(()=>{let d=l.$getSelection();l.$isRangeSelection(d)?d.removeText():l.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}function J(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]}
17
+ function K(c,b){var d=l.$getSelection();if(l.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let f=0;f<d.length;f++){let n=d[f],v=n.getKey();if(e.has(v))continue;let h=k.$getNearestBlockElementAncestorOrThrow(n),C=h.getKey();h.canInsertTab()?(c(n),e.add(v)):h.canIndent()&&!e.has(C)&&(e.add(C),b(h))}}}function L(c){c=l.$getNearestNodeFromDOMNode(c);return l.$isDecoratorNode(c)}exports.$createHeadingNode=G;exports.$createQuoteNode=B;exports.$isHeadingNode=function(c){return c instanceof D};
18
+ exports.$isQuoteNode=function(c){return c instanceof z};exports.DRAG_DROP_PASTE=y;exports.HeadingNode=D;exports.QuoteNode=z;exports.eventFiles=J;
19
19
  exports.registerRichText=function(c){return k.mergeRegister(c.registerCommand(l.CLICK_COMMAND,()=>{const b=l.$getSelection();return l.$isNodeSelection(b)?(b.clear(),!0):!1},0),c.registerCommand(l.DELETE_CHARACTER_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteCharacter(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DELETE_WORD_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteWord(b);return!0},l.COMMAND_PRIORITY_EDITOR),
20
20
  c.registerCommand(l.DELETE_LINE_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteLine(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,b=>{const d=l.$getSelection();if("string"===typeof b)l.$isRangeSelection(d)?d.insertText(b):l.DEPRECATED_$isGridSelection(d);else{if(!l.$isRangeSelection(d)&&!l.DEPRECATED_$isGridSelection(d))return!1;const e=b.dataTransfer;null!=e?a.$insertDataTransferForRichText(e,d,c):l.$isRangeSelection(d)&&
21
21
  (b=b.data)&&d.insertText(b)}return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.FORMAT_TEXT_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.formatText(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.FORMAT_ELEMENT_COMMAND,b=>{var d=l.$getSelection();if(!l.$isRangeSelection(d)&&!l.$isNodeSelection(d))return!1;
22
22
  d=d.getNodes();for(const e of d)k.$getNearestBlockElementAncestorOrThrow(e).setFormat(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INSERT_LINE_BREAK_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(b);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;b.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.INDENT_CONTENT_COMMAND,
23
- ()=>{I(()=>{c.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},b=>{const d=b.getIndent();10!==d&&b.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{I(b=>{l.$isTextNode(b)&&(b=b.getTextContent(),"\t"===b[b.length-1]&&c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},b=>{const d=b.getIndent();0!==d&&b.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_UP_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)&&
24
- !J(b.target)){if(b=d.getNodes(),0<b.length)return b[0].selectPrevious(),!0}else if(l.$isRangeSelection(d)){d=l.$getAdjacentNode(d.focus,!0);if(l.$isDecoratorNode(d)&&!d.isIsolated()&&!d.isInline())return d.selectPrevious(),b.preventDefault(),!0;if(l.$isElementNode(d)&&!d.isInline()&&!d.canBeEmpty())return d.select(),b.preventDefault(),!0}return!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_DOWN_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)){if(b=d.getNodes(),0<b.length)return b[0].selectNext(0,
23
+ ()=>{K(()=>{c.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},b=>{const d=b.getIndent();10!==d&&b.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{K(b=>{l.$isTextNode(b)&&(b=b.getTextContent(),"\t"===b[b.length-1]&&c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},b=>{const d=b.getIndent();0!==d&&b.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_UP_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)&&
24
+ !L(b.target)){if(b=d.getNodes(),0<b.length)return b[0].selectPrevious(),!0}else if(l.$isRangeSelection(d)){d=l.$getAdjacentNode(d.focus,!0);if(l.$isDecoratorNode(d)&&!d.isIsolated()&&!d.isInline())return d.selectPrevious(),b.preventDefault(),!0;if(l.$isElementNode(d)&&!d.isInline()&&!d.canBeEmpty())return d.select(),b.preventDefault(),!0}return!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_DOWN_COMMAND,b=>{var d=l.$getSelection();if(l.$isNodeSelection(d)){if(b=d.getNodes(),0<b.length)return b[0].selectNext(0,
25
25
  0),!0}else if(l.$isRangeSelection(d)){let e=d.focus;if("root"===e.key&&e.offset===l.$getRoot().getChildrenSize())return b.preventDefault(),!0;d=l.$getAdjacentNode(d.focus,!1);if(l.$isDecoratorNode(d)&&!d.isIsolated()&&!d.isInline())return d.selectNext(),b.preventDefault(),!0}return!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_LEFT_COMMAND,b=>{const d=l.$getSelection();if(l.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectPrevious(),!0}return l.$isRangeSelection(d)?
26
- g.$shouldOverrideDefaultCharacterSelection(d,!0)?(e=b.shiftKey,b.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,b=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!J(b.target)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectNext(0,0),!0}if(!l.$isRangeSelection(d))return!1;e=b.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(b.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),
27
- c.registerCommand(l.KEY_BACKSPACE_COMMAND,b=>{if(J(b.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();({anchor:b}=d);const e=b.getNode();return d.isCollapsed()&&0===b.offset&&!l.$isRootNode(e)&&0<k.$getNearestBlockElementAncestorOrThrow(e).getIndent()?c.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_DELETE_COMMAND,b=>{if(J(b.target))return!1;const d=
28
- l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();return c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ENTER_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==b){if((u||t)&&r)return!1;b.preventDefault();if(b.shiftKey)return c.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return c.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ESCAPE_COMMAND,
29
- ()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;c.blur();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DROP_COMMAND,b=>{const [,d]=H(b);if(0<d.length){var e=m(b.clientX,b.clientY);if(null!==e){const {offset:n,node:v}=e;var f=l.$getNearestNodeFromDOMNode(v);if(null!==f){e=l.$createRangeSelection();if(l.$isTextNode(f))e.anchor.set(f.getKey(),n,"text"),e.focus.set(f.getKey(),n,"text");else{const h=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(h,
30
- f,"element");e.focus.set(h,f,"element")}e=l.$normalizeSelection__EXPERIMENTAL(e);l.$setSelection(e)}c.dispatchCommand(w,d)}b.preventDefault();return!0}b=l.$getSelection();return l.$isRangeSelection(b)?!0:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGSTART_COMMAND,b=>{[b]=H(b);const d=l.$getSelection();return b&&!l.$isRangeSelection(d)?!1:!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGOVER_COMMAND,b=>{var [d]=H(b);const e=l.$getSelection();if(d&&!l.$isRangeSelection(e))return!1;d=
31
- m(b.clientX,b.clientY);null!==d&&(d=l.$getNearestNodeFromDOMNode(d.node),l.$isDecoratorNode(d)&&b.preventDefault());return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.COPY_COMMAND,b=>{a.copyToClipboard__EXPERIMENTAL(c,b instanceof ClipboardEvent?b:null);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.CUT_COMMAND,b=>{G(b,c);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.PASTE_COMMAND,b=>{const [,d,e]=H(b);if(0<d.length&&!e)return c.dispatchCommand(w,d),!0;const f=l.$getSelection();
32
- return l.$isRangeSelection(f)||l.DEPRECATED_$isGridSelection(f)?(F(b,c),!0):!1},l.COMMAND_PRIORITY_EDITOR))}
26
+ g.$shouldOverrideDefaultCharacterSelection(d,!0)?(e=b.shiftKey,b.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,b=>{const d=l.$getSelection();if(l.$isNodeSelection(d)&&!L(b.target)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectNext(0,0),!0}if(!l.$isRangeSelection(d))return!1;e=b.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(b.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),
27
+ c.registerCommand(l.KEY_BACKSPACE_COMMAND,b=>{if(L(b.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();({anchor:b}=d);const e=b.getNode();return d.isCollapsed()&&0===b.offset&&!l.$isRootNode(e)&&0<k.$getNearestBlockElementAncestorOrThrow(e).getIndent()?c.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_DELETE_COMMAND,b=>{if(L(b.target))return!1;const d=
28
+ l.$getSelection();if(!l.$isRangeSelection(d))return!1;b.preventDefault();return c.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ENTER_COMMAND,b=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==b){if((u||t||x)&&r)return!1;b.preventDefault();if(b.shiftKey)return c.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return c.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.KEY_ESCAPE_COMMAND,
29
+ ()=>{const b=l.$getSelection();if(!l.$isRangeSelection(b))return!1;c.blur();return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DROP_COMMAND,b=>{const [,d]=J(b);if(0<d.length){var e=m(b.clientX,b.clientY);if(null!==e){const {offset:n,node:v}=e;var f=l.$getNearestNodeFromDOMNode(v);if(null!==f){e=l.$createRangeSelection();if(l.$isTextNode(f))e.anchor.set(f.getKey(),n,"text"),e.focus.set(f.getKey(),n,"text");else{const h=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(h,
30
+ f,"element");e.focus.set(h,f,"element")}e=l.$normalizeSelection__EXPERIMENTAL(e);l.$setSelection(e)}c.dispatchCommand(y,d)}b.preventDefault();return!0}b=l.$getSelection();return l.$isRangeSelection(b)?!0:!1},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGSTART_COMMAND,b=>{[b]=J(b);const d=l.$getSelection();return b&&!l.$isRangeSelection(d)?!1:!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.DRAGOVER_COMMAND,b=>{var [d]=J(b);const e=l.$getSelection();if(d&&!l.$isRangeSelection(e))return!1;d=
31
+ m(b.clientX,b.clientY);null!==d&&(d=l.$getNearestNodeFromDOMNode(d.node),l.$isDecoratorNode(d)&&b.preventDefault());return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.COPY_COMMAND,b=>{a.copyToClipboard(c,b instanceof ClipboardEvent?b:null);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.CUT_COMMAND,b=>{I(b,c);return!0},l.COMMAND_PRIORITY_EDITOR),c.registerCommand(l.PASTE_COMMAND,b=>{const [,d,e]=J(b);if(0<d.length&&!e)return c.dispatchCommand(y,d),!0;const f=l.$getSelection();return l.$isRangeSelection(f)||
32
+ l.DEPRECATED_$isGridSelection(f)?(H(b,c),!0):!1},l.COMMAND_PRIORITY_EDITOR))}
package/package.json CHANGED
@@ -7,13 +7,13 @@
7
7
  "rich-text"
8
8
  ],
9
9
  "license": "MIT",
10
- "version": "0.8.0",
10
+ "version": "0.9.0",
11
11
  "main": "LexicalRichText.js",
12
12
  "peerDependencies": {
13
- "lexical": "0.8.0",
14
- "@lexical/selection": "0.8.0",
15
- "@lexical/clipboard": "0.8.0",
16
- "@lexical/utils": "0.8.0"
13
+ "lexical": "0.9.0",
14
+ "@lexical/selection": "0.9.0",
15
+ "@lexical/clipboard": "0.9.0",
16
+ "@lexical/utils": "0.9.0"
17
17
  },
18
18
  "repository": {
19
19
  "type": "git",