@lexical/rich-text 0.2.0 → 0.2.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.
- package/LexicalRichText.d.ts +5 -2
- package/LexicalRichText.dev.js +72 -31
- package/LexicalRichText.prod.js +19 -16
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -12,13 +12,16 @@ import type {
|
|
|
12
12
|
LexicalNode,
|
|
13
13
|
NodeKey,
|
|
14
14
|
ParagraphNode,
|
|
15
|
+
HeadingNode,
|
|
15
16
|
} from 'lexical';
|
|
17
|
+
import {ElementNode} from 'lexical';
|
|
18
|
+
|
|
16
19
|
export type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
17
20
|
|
|
18
21
|
export declare class QuoteNode extends ElementNode {
|
|
19
22
|
static getType(): string;
|
|
20
23
|
static clone(node: QuoteNode): QuoteNode;
|
|
21
|
-
constructor(key?: NodeKey)
|
|
24
|
+
constructor(key?: NodeKey);
|
|
22
25
|
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
23
26
|
updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean;
|
|
24
27
|
insertNewAfter(): ParagraphNode;
|
|
@@ -31,7 +34,7 @@ export declare class HeadingNode extends ElementNode {
|
|
|
31
34
|
__tag: HeadingTagType;
|
|
32
35
|
static getType(): string;
|
|
33
36
|
static clone(node: HeadingNode): HeadingNode;
|
|
34
|
-
constructor(tag: HeadingTagType, key?: NodeKey)
|
|
37
|
+
constructor(tag: HeadingTagType, key?: NodeKey);
|
|
35
38
|
getTag(): HeadingTagType;
|
|
36
39
|
createDOM<EditorContext>(config: EditorConfig<EditorContext>): HTMLElement;
|
|
37
40
|
updateDOM(prevNode: HeadingNode, dom: HTMLElement): boolean;
|
package/LexicalRichText.dev.js
CHANGED
|
@@ -11,6 +11,34 @@ var selection = require('@lexical/selection');
|
|
|
11
11
|
var utils = require('@lexical/utils');
|
|
12
12
|
var lexical = require('lexical');
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
|
+
*
|
|
17
|
+
* This source code is licensed under the MIT license found in the
|
|
18
|
+
* LICENSE file in the root directory of this source tree.
|
|
19
|
+
*
|
|
20
|
+
*
|
|
21
|
+
*/
|
|
22
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
26
|
+
*
|
|
27
|
+
* This source code is licensed under the MIT license found in the
|
|
28
|
+
* LICENSE file in the root directory of this source tree.
|
|
29
|
+
*
|
|
30
|
+
*
|
|
31
|
+
*/
|
|
32
|
+
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
33
|
+
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
34
|
+
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
35
|
+
CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
36
|
+
CAN_USE_DOM && /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
|
|
37
|
+
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.
|
|
38
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
39
|
+
// export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
40
|
+
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
41
|
+
|
|
14
42
|
/**
|
|
15
43
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
16
44
|
*
|
|
@@ -285,7 +313,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
285
313
|
const isBackward = payload;
|
|
286
314
|
selection.deleteCharacter(isBackward);
|
|
287
315
|
return true;
|
|
288
|
-
},
|
|
316
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, payload => {
|
|
289
317
|
const selection = lexical.$getSelection();
|
|
290
318
|
|
|
291
319
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -295,7 +323,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
295
323
|
const isBackward = payload;
|
|
296
324
|
selection.deleteWord(isBackward);
|
|
297
325
|
return true;
|
|
298
|
-
},
|
|
326
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, payload => {
|
|
299
327
|
const selection = lexical.$getSelection();
|
|
300
328
|
|
|
301
329
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -305,7 +333,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
305
333
|
const isBackward = payload;
|
|
306
334
|
selection.deleteLine(isBackward);
|
|
307
335
|
return true;
|
|
308
|
-
},
|
|
336
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_TEXT_COMMAND, payload => {
|
|
309
337
|
const selection = lexical.$getSelection();
|
|
310
338
|
|
|
311
339
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -333,7 +361,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
333
361
|
}
|
|
334
362
|
|
|
335
363
|
return true;
|
|
336
|
-
},
|
|
364
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, payload => {
|
|
337
365
|
const selection = lexical.$getSelection();
|
|
338
366
|
|
|
339
367
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -342,7 +370,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
342
370
|
|
|
343
371
|
selection.removeText();
|
|
344
372
|
return true;
|
|
345
|
-
},
|
|
373
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, payload => {
|
|
346
374
|
const selection = lexical.$getSelection();
|
|
347
375
|
|
|
348
376
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -352,18 +380,22 @@ function registerRichText(editor, initialEditorState) {
|
|
|
352
380
|
const format = payload;
|
|
353
381
|
selection.formatText(format);
|
|
354
382
|
return true;
|
|
355
|
-
},
|
|
383
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, format => {
|
|
356
384
|
const selection = lexical.$getSelection();
|
|
357
385
|
|
|
358
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
386
|
+
if (!lexical.$isRangeSelection(selection) && !lexical.$isNodeSelection(selection)) {
|
|
359
387
|
return false;
|
|
360
388
|
}
|
|
361
389
|
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
390
|
+
const nodes = selection.getNodes();
|
|
391
|
+
|
|
392
|
+
for (const node of nodes) {
|
|
393
|
+
const element = utils.$getNearestBlockElementAncestorOrThrow(node);
|
|
394
|
+
element.setFormat(format);
|
|
395
|
+
}
|
|
396
|
+
|
|
365
397
|
return true;
|
|
366
|
-
},
|
|
398
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, payload => {
|
|
367
399
|
const selection = lexical.$getSelection();
|
|
368
400
|
|
|
369
401
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -373,7 +405,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
373
405
|
const selectStart = payload;
|
|
374
406
|
selection.insertLineBreak(selectStart);
|
|
375
407
|
return true;
|
|
376
|
-
},
|
|
408
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, payload => {
|
|
377
409
|
const selection = lexical.$getSelection();
|
|
378
410
|
|
|
379
411
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -382,7 +414,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
382
414
|
|
|
383
415
|
selection.insertParagraph();
|
|
384
416
|
return true;
|
|
385
|
-
},
|
|
417
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => {
|
|
386
418
|
const selection = lexical.$getSelection();
|
|
387
419
|
|
|
388
420
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -402,7 +434,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
402
434
|
}
|
|
403
435
|
|
|
404
436
|
return true;
|
|
405
|
-
},
|
|
437
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => {
|
|
406
438
|
const selection = lexical.$getSelection();
|
|
407
439
|
|
|
408
440
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -428,7 +460,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
428
460
|
}
|
|
429
461
|
|
|
430
462
|
return true;
|
|
431
|
-
},
|
|
463
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
|
|
432
464
|
const selection$1 = lexical.$getSelection();
|
|
433
465
|
|
|
434
466
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -445,7 +477,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
445
477
|
}
|
|
446
478
|
|
|
447
479
|
return false;
|
|
448
|
-
},
|
|
480
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
|
|
449
481
|
const selection$1 = lexical.$getSelection();
|
|
450
482
|
|
|
451
483
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -462,7 +494,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
462
494
|
}
|
|
463
495
|
|
|
464
496
|
return false;
|
|
465
|
-
},
|
|
497
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, payload => {
|
|
466
498
|
const selection = lexical.$getSelection();
|
|
467
499
|
|
|
468
500
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -484,7 +516,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
484
516
|
}
|
|
485
517
|
|
|
486
518
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
487
|
-
},
|
|
519
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, payload => {
|
|
488
520
|
const selection = lexical.$getSelection();
|
|
489
521
|
|
|
490
522
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -494,22 +526,31 @@ function registerRichText(editor, initialEditorState) {
|
|
|
494
526
|
const event = payload;
|
|
495
527
|
event.preventDefault();
|
|
496
528
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
|
|
497
|
-
},
|
|
529
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
498
530
|
const selection = lexical.$getSelection();
|
|
499
531
|
|
|
500
532
|
if (!lexical.$isRangeSelection(selection)) {
|
|
501
533
|
return false;
|
|
502
534
|
}
|
|
503
535
|
|
|
504
|
-
|
|
505
|
-
|
|
536
|
+
if (event !== null) {
|
|
537
|
+
// If we have beforeinput, then we can avoid blocking
|
|
538
|
+
// the default behavior. This ensures that the iOS can
|
|
539
|
+
// intercept that we're actually inserting a paragraph,
|
|
540
|
+
// and autocomplete, autocapitialize etc work as intended.
|
|
541
|
+
if (IS_IOS) {
|
|
542
|
+
return false;
|
|
543
|
+
}
|
|
506
544
|
|
|
507
|
-
|
|
508
|
-
|
|
545
|
+
event.preventDefault();
|
|
546
|
+
|
|
547
|
+
if (event.shiftKey) {
|
|
548
|
+
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND);
|
|
549
|
+
}
|
|
509
550
|
}
|
|
510
551
|
|
|
511
552
|
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND);
|
|
512
|
-
},
|
|
553
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND, payload => {
|
|
513
554
|
const selection = lexical.$getSelection();
|
|
514
555
|
|
|
515
556
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -519,7 +560,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
519
560
|
const event = payload;
|
|
520
561
|
event.preventDefault();
|
|
521
562
|
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND);
|
|
522
|
-
},
|
|
563
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
|
|
523
564
|
const selection = lexical.$getSelection();
|
|
524
565
|
|
|
525
566
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -528,7 +569,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
528
569
|
|
|
529
570
|
editor.blur();
|
|
530
571
|
return true;
|
|
531
|
-
},
|
|
572
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => {
|
|
532
573
|
const selection = lexical.$getSelection();
|
|
533
574
|
|
|
534
575
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -538,7 +579,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
538
579
|
|
|
539
580
|
event.preventDefault();
|
|
540
581
|
return true;
|
|
541
|
-
},
|
|
582
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, payload => {
|
|
542
583
|
const selection = lexical.$getSelection();
|
|
543
584
|
|
|
544
585
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -549,7 +590,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
549
590
|
const event = payload;
|
|
550
591
|
event.preventDefault();
|
|
551
592
|
return true;
|
|
552
|
-
},
|
|
593
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, payload => {
|
|
553
594
|
const selection = lexical.$getSelection();
|
|
554
595
|
|
|
555
596
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -559,7 +600,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
559
600
|
}
|
|
560
601
|
|
|
561
602
|
return false;
|
|
562
|
-
},
|
|
603
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, payload => {
|
|
563
604
|
const selection = lexical.$getSelection();
|
|
564
605
|
|
|
565
606
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -569,7 +610,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
569
610
|
}
|
|
570
611
|
|
|
571
612
|
return false;
|
|
572
|
-
},
|
|
613
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
573
614
|
const selection = lexical.$getSelection();
|
|
574
615
|
|
|
575
616
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -578,7 +619,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
578
619
|
}
|
|
579
620
|
|
|
580
621
|
return false;
|
|
581
|
-
},
|
|
622
|
+
}, lexical.COMMAND_PRIORITY_EDITOR));
|
|
582
623
|
initializeEditor(editor, initialEditorState);
|
|
583
624
|
return removeListener;
|
|
584
625
|
}
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,19 +4,22 @@
|
|
|
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=
|
|
8
|
-
|
|
9
|
-
class
|
|
10
|
-
({
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
{const
|
|
16
|
-
c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.
|
|
17
|
-
if(!l.$isRangeSelection(c))return!1;c.
|
|
18
|
-
|
|
19
|
-
c
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1;
|
|
8
|
+
m&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent);const p=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,q={tag:"history-merge"};
|
|
9
|
+
class r extends l.ElementNode{static getType(){return"quote"}static clone(b){return new r(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 t extends l.ElementNode{static getType(){return"heading"}static clone(b){return new t(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:u,priority:0}),h2:()=>({conversion:u,priority:0}),h3:()=>({conversion:u,priority:0}),h4:()=>({conversion:u,priority:0}),h5:()=>
|
|
11
|
+
({conversion:u,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}}function u(b){b=b.nodeName.toLowerCase();let e=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b)e=v(b);return{node:e}}function v(b){return new t(b)}
|
|
12
|
+
function w(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()}},q);else if(null!==e)switch(typeof e){case "string":e=b.parseEditorState(e);b.setEditorState(e,q);break;case "object":b.setEditorState(e,q);break;case "function":b.update(e,q)}}
|
|
13
|
+
function x(b,e){b.preventDefault();e.update(()=>{const f=l.$getSelection(),c=b.clipboardData;null!=c&&l.$isRangeSelection(f)&&a.$insertDataTransferForRichText(c,f,e)})}function y(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 z(b,e){y(b,e);e.update(()=>{const f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}exports.$createHeadingNode=v;exports.$createQuoteNode=function(){return new r};exports.$isHeadingNode=function(b){return b instanceof t};exports.$isQuoteNode=function(b){return b instanceof r};exports.HeadingNode=t;exports.QuoteNode=r;
|
|
15
|
+
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),
|
|
16
|
+
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(!l.$isRangeSelection(d))return!1;if("string"===typeof c)d.insertText(c);else{const g=c.dataTransfer;null!=g?a.$insertDataTransferForRichText(g,d,b):(c=c.data)&&d.insertText(c)}return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const c=l.$getSelection();
|
|
17
|
+
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);return!0},l.COMMAND_PRIORITY_EDITOR),
|
|
18
|
+
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,()=>{var c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c=k.$getNearestBlockElementAncestorOrThrow(c.anchor.getNode());
|
|
19
|
+
c.canInsertTab()?b.dispatchCommand(l.INSERT_TEXT_COMMAND,"\t"):10!==c.getIndent()&&c.setIndent(c.getIndent()+1);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{var c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c=c.anchor;const d=c.getNode(),g=k.$getNearestBlockElementAncestorOrThrow(c.getNode());g.canInsertTab()?"\t"===d.getTextContent()[c.offset-1]&&b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0):0!==g.getIndent()&&g.setIndent(g.getIndent()-1);return!0},
|
|
20
|
+
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,!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,
|
|
21
|
+
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()&&0===c.offset&&0<k.$getNearestBlockElementAncestorOrThrow(c.getNode()).getIndent()?b.dispatchCommand(l.OUTDENT_CONTENT_COMMAND):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;
|
|
22
|
+
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;if(null!==c){if(p)return!1;c.preventDefault();if(c.shiftKey)return b.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND)}return b.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;
|
|
23
|
+
c.preventDefault();return b.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=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();
|
|
24
|
+
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)||l.$isGridSelection(d)?(y(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)?(z(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||
|
|
25
|
+
l.$isGridSelection(d)?(x(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));w(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.
|
|
10
|
+
"version": "0.2.3",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.2.
|
|
14
|
-
"@lexical/selection": "0.2.
|
|
15
|
-
"@lexical/clipboard": "0.2.
|
|
16
|
-
"@lexical/utils": "0.2.
|
|
13
|
+
"lexical": "0.2.3",
|
|
14
|
+
"@lexical/selection": "0.2.3",
|
|
15
|
+
"@lexical/clipboard": "0.2.3",
|
|
16
|
+
"@lexical/utils": "0.2.3"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|