@lexical/rich-text 0.2.1 → 0.2.4
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 +7 -4
- package/LexicalRichText.dev.js +60 -24
- package/LexicalRichText.prod.js +19 -16
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -12,26 +12,29 @@ import type {
|
|
|
12
12
|
LexicalNode,
|
|
13
13
|
NodeKey,
|
|
14
14
|
ParagraphNode,
|
|
15
|
+
LexicalEditor,
|
|
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;
|
|
25
28
|
collapseAtStart(): true;
|
|
26
29
|
}
|
|
27
30
|
export function $createQuoteNode(): QuoteNode;
|
|
28
|
-
export function $isQuoteNode(node: ?LexicalNode):
|
|
31
|
+
export function $isQuoteNode(node: ?LexicalNode): node is QuoteNode;
|
|
29
32
|
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
30
33
|
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;
|
|
@@ -40,7 +43,7 @@ export declare class HeadingNode extends ElementNode {
|
|
|
40
43
|
collapseAtStart(): true;
|
|
41
44
|
}
|
|
42
45
|
export function $createHeadingNode(headingTag: HeadingTagType): HeadingNode;
|
|
43
|
-
export function $isHeadingNode(node: ?LexicalNode):
|
|
46
|
+
export function $isHeadingNode(node: ?LexicalNode): node is HeadingNode;
|
|
44
47
|
export function registerRichText(
|
|
45
48
|
editor: LexicalEditor,
|
|
46
49
|
initialEditorState?: InitialEditorStateType,
|
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,10 +380,10 @@ 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
|
|
|
@@ -367,7 +395,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
367
395
|
}
|
|
368
396
|
|
|
369
397
|
return true;
|
|
370
|
-
},
|
|
398
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, payload => {
|
|
371
399
|
const selection = lexical.$getSelection();
|
|
372
400
|
|
|
373
401
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -377,7 +405,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
377
405
|
const selectStart = payload;
|
|
378
406
|
selection.insertLineBreak(selectStart);
|
|
379
407
|
return true;
|
|
380
|
-
},
|
|
408
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, payload => {
|
|
381
409
|
const selection = lexical.$getSelection();
|
|
382
410
|
|
|
383
411
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -386,7 +414,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
386
414
|
|
|
387
415
|
selection.insertParagraph();
|
|
388
416
|
return true;
|
|
389
|
-
},
|
|
417
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => {
|
|
390
418
|
const selection = lexical.$getSelection();
|
|
391
419
|
|
|
392
420
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -406,7 +434,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
406
434
|
}
|
|
407
435
|
|
|
408
436
|
return true;
|
|
409
|
-
},
|
|
437
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => {
|
|
410
438
|
const selection = lexical.$getSelection();
|
|
411
439
|
|
|
412
440
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -432,7 +460,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
432
460
|
}
|
|
433
461
|
|
|
434
462
|
return true;
|
|
435
|
-
},
|
|
463
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
|
|
436
464
|
const selection$1 = lexical.$getSelection();
|
|
437
465
|
|
|
438
466
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -449,7 +477,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
449
477
|
}
|
|
450
478
|
|
|
451
479
|
return false;
|
|
452
|
-
},
|
|
480
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, payload => {
|
|
453
481
|
const selection$1 = lexical.$getSelection();
|
|
454
482
|
|
|
455
483
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
@@ -466,7 +494,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
466
494
|
}
|
|
467
495
|
|
|
468
496
|
return false;
|
|
469
|
-
},
|
|
497
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, payload => {
|
|
470
498
|
const selection = lexical.$getSelection();
|
|
471
499
|
|
|
472
500
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -488,7 +516,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
488
516
|
}
|
|
489
517
|
|
|
490
518
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
491
|
-
},
|
|
519
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, payload => {
|
|
492
520
|
const selection = lexical.$getSelection();
|
|
493
521
|
|
|
494
522
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -498,7 +526,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
498
526
|
const event = payload;
|
|
499
527
|
event.preventDefault();
|
|
500
528
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
|
|
501
|
-
},
|
|
529
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
502
530
|
const selection = lexical.$getSelection();
|
|
503
531
|
|
|
504
532
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -506,6 +534,14 @@ function registerRichText(editor, initialEditorState) {
|
|
|
506
534
|
}
|
|
507
535
|
|
|
508
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
|
+
}
|
|
544
|
+
|
|
509
545
|
event.preventDefault();
|
|
510
546
|
|
|
511
547
|
if (event.shiftKey) {
|
|
@@ -514,7 +550,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
514
550
|
}
|
|
515
551
|
|
|
516
552
|
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND);
|
|
517
|
-
},
|
|
553
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND, payload => {
|
|
518
554
|
const selection = lexical.$getSelection();
|
|
519
555
|
|
|
520
556
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -524,7 +560,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
524
560
|
const event = payload;
|
|
525
561
|
event.preventDefault();
|
|
526
562
|
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND);
|
|
527
|
-
},
|
|
563
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, payload => {
|
|
528
564
|
const selection = lexical.$getSelection();
|
|
529
565
|
|
|
530
566
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -533,7 +569,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
533
569
|
|
|
534
570
|
editor.blur();
|
|
535
571
|
return true;
|
|
536
|
-
},
|
|
572
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DROP_COMMAND, event => {
|
|
537
573
|
const selection = lexical.$getSelection();
|
|
538
574
|
|
|
539
575
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -543,7 +579,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
543
579
|
|
|
544
580
|
event.preventDefault();
|
|
545
581
|
return true;
|
|
546
|
-
},
|
|
582
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, payload => {
|
|
547
583
|
const selection = lexical.$getSelection();
|
|
548
584
|
|
|
549
585
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -554,7 +590,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
554
590
|
const event = payload;
|
|
555
591
|
event.preventDefault();
|
|
556
592
|
return true;
|
|
557
|
-
},
|
|
593
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, payload => {
|
|
558
594
|
const selection = lexical.$getSelection();
|
|
559
595
|
|
|
560
596
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -564,7 +600,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
564
600
|
}
|
|
565
601
|
|
|
566
602
|
return false;
|
|
567
|
-
},
|
|
603
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, payload => {
|
|
568
604
|
const selection = lexical.$getSelection();
|
|
569
605
|
|
|
570
606
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -574,7 +610,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
574
610
|
}
|
|
575
611
|
|
|
576
612
|
return false;
|
|
577
|
-
},
|
|
613
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.PASTE_COMMAND, event => {
|
|
578
614
|
const selection = lexical.$getSelection();
|
|
579
615
|
|
|
580
616
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
@@ -583,7 +619,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
583
619
|
}
|
|
584
620
|
|
|
585
621
|
return false;
|
|
586
|
-
},
|
|
622
|
+
}, lexical.COMMAND_PRIORITY_EDITOR));
|
|
587
623
|
initializeEditor(editor, initialEditorState);
|
|
588
624
|
return removeListener;
|
|
589
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
|
-
|
|
18
|
-
const d=
|
|
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.4",
|
|
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.4",
|
|
14
|
+
"@lexical/selection": "0.2.4",
|
|
15
|
+
"@lexical/clipboard": "0.2.4",
|
|
16
|
+
"@lexical/utils": "0.2.4"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|