@lexical/rich-text 0.2.7 → 0.3.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.
- package/LexicalRichText.d.ts +30 -2
- package/LexicalRichText.dev.js +75 -59
- package/LexicalRichText.prod.js +19 -17
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
import type {
|
|
9
10
|
DOMConversionMap,
|
|
10
11
|
EditorConfig,
|
|
@@ -13,8 +14,11 @@ import type {
|
|
|
13
14
|
NodeKey,
|
|
14
15
|
ParagraphNode,
|
|
15
16
|
LexicalEditor,
|
|
17
|
+
SerializedElementNode,
|
|
16
18
|
} from 'lexical';
|
|
17
19
|
import {ElementNode} from 'lexical';
|
|
20
|
+
import {Spread} from 'libdefs/globals';
|
|
21
|
+
|
|
18
22
|
export type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
19
23
|
|
|
20
24
|
export declare class QuoteNode extends ElementNode {
|
|
@@ -25,9 +29,12 @@ export declare class QuoteNode extends ElementNode {
|
|
|
25
29
|
updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean;
|
|
26
30
|
insertNewAfter(): ParagraphNode;
|
|
27
31
|
collapseAtStart(): true;
|
|
32
|
+
importJSON(serializedNode: SerializedQuoteNode): QuoteNode;
|
|
28
33
|
}
|
|
29
34
|
export function $createQuoteNode(): QuoteNode;
|
|
30
|
-
export function $isQuoteNode(
|
|
35
|
+
export function $isQuoteNode(
|
|
36
|
+
node: LexicalNode | null | undefined,
|
|
37
|
+
): node is QuoteNode;
|
|
31
38
|
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
32
39
|
export declare class HeadingNode extends ElementNode {
|
|
33
40
|
__tag: HeadingTagType;
|
|
@@ -40,10 +47,31 @@ export declare class HeadingNode extends ElementNode {
|
|
|
40
47
|
static importDOM(): DOMConversionMap | null;
|
|
41
48
|
insertNewAfter(): ParagraphNode;
|
|
42
49
|
collapseAtStart(): true;
|
|
50
|
+
importJSON(serializedNode: SerializedHeadingNode): QuoteNode;
|
|
43
51
|
}
|
|
52
|
+
|
|
44
53
|
export function $createHeadingNode(headingTag: HeadingTagType): HeadingNode;
|
|
45
|
-
export function $isHeadingNode(
|
|
54
|
+
export function $isHeadingNode(
|
|
55
|
+
node: LexicalNode | null | undefined,
|
|
56
|
+
): node is HeadingNode;
|
|
46
57
|
export function registerRichText(
|
|
47
58
|
editor: LexicalEditor,
|
|
48
59
|
initialEditorState?: InitialEditorStateType,
|
|
49
60
|
): () => void;
|
|
61
|
+
|
|
62
|
+
export type SerializedHeadingNode = Spread<
|
|
63
|
+
{
|
|
64
|
+
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
65
|
+
type: 'heading';
|
|
66
|
+
version: 1;
|
|
67
|
+
},
|
|
68
|
+
SerializedElementNode
|
|
69
|
+
>;
|
|
70
|
+
|
|
71
|
+
export type SerializedQuoteNode = Spread<
|
|
72
|
+
{
|
|
73
|
+
type: 'quote';
|
|
74
|
+
version: 1;
|
|
75
|
+
},
|
|
76
|
+
SerializedElementNode
|
|
77
|
+
>;
|
package/LexicalRichText.dev.js
CHANGED
|
@@ -17,24 +17,16 @@ var lexical = require('lexical');
|
|
|
17
17
|
* This source code is licensed under the MIT license found in the
|
|
18
18
|
* LICENSE file in the root directory of this source tree.
|
|
19
19
|
*
|
|
20
|
-
*
|
|
21
20
|
*/
|
|
22
21
|
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;
|
|
22
|
+
const documentMode = // @ts-ignore
|
|
23
|
+
CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
33
24
|
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
34
25
|
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
35
26
|
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
36
|
-
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d
|
|
37
|
-
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) &&
|
|
27
|
+
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
28
|
+
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && // @ts-ignore
|
|
29
|
+
!window.MSStream; // Keep these in case we need to use them in the future.
|
|
38
30
|
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
39
31
|
// export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
40
32
|
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
@@ -45,7 +37,6 @@ const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !w
|
|
|
45
37
|
* This source code is licensed under the MIT license found in the
|
|
46
38
|
* LICENSE file in the root directory of this source tree.
|
|
47
39
|
*
|
|
48
|
-
*
|
|
49
40
|
*/
|
|
50
41
|
// Convoluted logic to make this work with Flow. Order matters.
|
|
51
42
|
const options = {
|
|
@@ -75,6 +66,29 @@ class QuoteNode extends lexical.ElementNode {
|
|
|
75
66
|
|
|
76
67
|
updateDOM(prevNode, dom) {
|
|
77
68
|
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static importDOM() {
|
|
72
|
+
return {
|
|
73
|
+
blockquote: node => ({
|
|
74
|
+
conversion: convertBlockquoteElement,
|
|
75
|
+
priority: 0
|
|
76
|
+
})
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static importJSON(serializedNode) {
|
|
81
|
+
const node = $createQuoteNode();
|
|
82
|
+
node.setFormat(serializedNode.format);
|
|
83
|
+
node.setIndent(serializedNode.indent);
|
|
84
|
+
node.setDirection(serializedNode.direction);
|
|
85
|
+
return node;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
exportJSON() {
|
|
89
|
+
return { ...super.exportJSON(),
|
|
90
|
+
type: 'quote'
|
|
91
|
+
};
|
|
78
92
|
} // Mutation
|
|
79
93
|
|
|
80
94
|
|
|
@@ -127,7 +141,6 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
127
141
|
const classNames = theme.heading;
|
|
128
142
|
|
|
129
143
|
if (classNames !== undefined) {
|
|
130
|
-
// $FlowFixMe: intentional cast
|
|
131
144
|
const className = classNames[tag];
|
|
132
145
|
utils.addClassNamesToElement(element, className);
|
|
133
146
|
}
|
|
@@ -162,6 +175,22 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
162
175
|
priority: 0
|
|
163
176
|
})
|
|
164
177
|
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static importJSON(serializedNode) {
|
|
181
|
+
const node = $createHeadingNode(serializedNode.tag);
|
|
182
|
+
node.setFormat(serializedNode.format);
|
|
183
|
+
node.setIndent(serializedNode.indent);
|
|
184
|
+
node.setDirection(serializedNode.direction);
|
|
185
|
+
return node;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
exportJSON() {
|
|
189
|
+
return { ...super.exportJSON(),
|
|
190
|
+
tag: this.getTag(),
|
|
191
|
+
type: 'heading',
|
|
192
|
+
version: 1
|
|
193
|
+
};
|
|
165
194
|
} // Mutation
|
|
166
195
|
|
|
167
196
|
|
|
@@ -200,6 +229,13 @@ function convertHeadingElement(domNode) {
|
|
|
200
229
|
};
|
|
201
230
|
}
|
|
202
231
|
|
|
232
|
+
function convertBlockquoteElement() {
|
|
233
|
+
const node = $createQuoteNode();
|
|
234
|
+
return {
|
|
235
|
+
node
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
203
239
|
function $createHeadingNode(headingTag) {
|
|
204
240
|
return new HeadingNode(headingTag);
|
|
205
241
|
}
|
|
@@ -270,16 +306,11 @@ function onCopyForRichText(event, editor) {
|
|
|
270
306
|
if (selection !== null) {
|
|
271
307
|
if (clipboardData != null) {
|
|
272
308
|
const htmlString = clipboard.$getHtmlContent(editor);
|
|
273
|
-
const lexicalString = clipboard.$getLexicalContent(editor);
|
|
274
309
|
|
|
275
310
|
if (htmlString !== null) {
|
|
276
311
|
clipboardData.setData('text/html', htmlString);
|
|
277
312
|
}
|
|
278
313
|
|
|
279
|
-
if (lexicalString !== null) {
|
|
280
|
-
clipboardData.setData('application/x-lexical-editor', lexicalString);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
314
|
clipboardData.setData('text/plain', selection.getTextContent());
|
|
284
315
|
}
|
|
285
316
|
}
|
|
@@ -345,29 +376,26 @@ function registerRichText(editor, initialEditorState) {
|
|
|
345
376
|
|
|
346
377
|
selection.deleteCharacter(isBackward);
|
|
347
378
|
return true;
|
|
348
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND,
|
|
379
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, isBackward => {
|
|
349
380
|
const selection = lexical.$getSelection();
|
|
350
381
|
|
|
351
382
|
if (!lexical.$isRangeSelection(selection)) {
|
|
352
383
|
return false;
|
|
353
384
|
}
|
|
354
385
|
|
|
355
|
-
const isBackward = payload;
|
|
356
386
|
selection.deleteWord(isBackward);
|
|
357
387
|
return true;
|
|
358
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND,
|
|
388
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_LINE_COMMAND, isBackward => {
|
|
359
389
|
const selection = lexical.$getSelection();
|
|
360
390
|
|
|
361
391
|
if (!lexical.$isRangeSelection(selection)) {
|
|
362
392
|
return false;
|
|
363
393
|
}
|
|
364
394
|
|
|
365
|
-
const isBackward = payload;
|
|
366
395
|
selection.deleteLine(isBackward);
|
|
367
396
|
return true;
|
|
368
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.
|
|
397
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
|
|
369
398
|
const selection = lexical.$getSelection();
|
|
370
|
-
const eventOrText = payload;
|
|
371
399
|
|
|
372
400
|
if (typeof eventOrText === 'string') {
|
|
373
401
|
if (lexical.$isRangeSelection(selection)) {
|
|
@@ -394,7 +422,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
394
422
|
}
|
|
395
423
|
|
|
396
424
|
return true;
|
|
397
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND,
|
|
425
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REMOVE_TEXT_COMMAND, () => {
|
|
398
426
|
const selection = lexical.$getSelection();
|
|
399
427
|
|
|
400
428
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -403,14 +431,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
403
431
|
|
|
404
432
|
selection.removeText();
|
|
405
433
|
return true;
|
|
406
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_TEXT_COMMAND,
|
|
434
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_TEXT_COMMAND, format => {
|
|
407
435
|
const selection = lexical.$getSelection();
|
|
408
436
|
|
|
409
437
|
if (!lexical.$isRangeSelection(selection)) {
|
|
410
438
|
return false;
|
|
411
439
|
}
|
|
412
440
|
|
|
413
|
-
const format = payload;
|
|
414
441
|
selection.formatText(format);
|
|
415
442
|
return true;
|
|
416
443
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, format => {
|
|
@@ -428,17 +455,16 @@ function registerRichText(editor, initialEditorState) {
|
|
|
428
455
|
}
|
|
429
456
|
|
|
430
457
|
return true;
|
|
431
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND,
|
|
458
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_LINE_BREAK_COMMAND, selectStart => {
|
|
432
459
|
const selection = lexical.$getSelection();
|
|
433
460
|
|
|
434
461
|
if (!lexical.$isRangeSelection(selection)) {
|
|
435
462
|
return false;
|
|
436
463
|
}
|
|
437
464
|
|
|
438
|
-
const selectStart = payload;
|
|
439
465
|
selection.insertLineBreak(selectStart);
|
|
440
466
|
return true;
|
|
441
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND,
|
|
467
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
|
|
442
468
|
const selection = lexical.$getSelection();
|
|
443
469
|
|
|
444
470
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -447,9 +473,9 @@ function registerRichText(editor, initialEditorState) {
|
|
|
447
473
|
|
|
448
474
|
selection.insertParagraph();
|
|
449
475
|
return true;
|
|
450
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND,
|
|
476
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
|
|
451
477
|
handleIndentAndOutdent(() => {
|
|
452
|
-
editor.dispatchCommand(lexical.
|
|
478
|
+
editor.dispatchCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND, '\t');
|
|
453
479
|
}, block => {
|
|
454
480
|
const indent = block.getIndent();
|
|
455
481
|
|
|
@@ -458,7 +484,7 @@ function registerRichText(editor, initialEditorState) {
|
|
|
458
484
|
}
|
|
459
485
|
});
|
|
460
486
|
return true;
|
|
461
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND,
|
|
487
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
|
|
462
488
|
handleIndentAndOutdent(node => {
|
|
463
489
|
if (lexical.$isTextNode(node)) {
|
|
464
490
|
const textContent = node.getTextContent();
|
|
@@ -476,14 +502,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
476
502
|
}
|
|
477
503
|
});
|
|
478
504
|
return true;
|
|
479
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND,
|
|
505
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, event => {
|
|
480
506
|
const selection$1 = lexical.$getSelection();
|
|
481
507
|
|
|
482
508
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
483
509
|
return false;
|
|
484
510
|
}
|
|
485
511
|
|
|
486
|
-
const event = payload;
|
|
487
512
|
const isHoldingShift = event.shiftKey;
|
|
488
513
|
|
|
489
514
|
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, true)) {
|
|
@@ -493,14 +518,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
493
518
|
}
|
|
494
519
|
|
|
495
520
|
return false;
|
|
496
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND,
|
|
521
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => {
|
|
497
522
|
const selection$1 = lexical.$getSelection();
|
|
498
523
|
|
|
499
524
|
if (!lexical.$isRangeSelection(selection$1)) {
|
|
500
525
|
return false;
|
|
501
526
|
}
|
|
502
527
|
|
|
503
|
-
const event = payload;
|
|
504
528
|
const isHoldingShift = event.shiftKey;
|
|
505
529
|
|
|
506
530
|
if (selection.$shouldOverrideDefaultCharacterSelection(selection$1, false)) {
|
|
@@ -510,14 +534,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
510
534
|
}
|
|
511
535
|
|
|
512
536
|
return false;
|
|
513
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND,
|
|
537
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
|
|
514
538
|
const selection = lexical.$getSelection();
|
|
515
539
|
|
|
516
540
|
if (!lexical.$isRangeSelection(selection)) {
|
|
517
541
|
return false;
|
|
518
542
|
}
|
|
519
543
|
|
|
520
|
-
const event = payload;
|
|
521
544
|
event.preventDefault();
|
|
522
545
|
const {
|
|
523
546
|
anchor
|
|
@@ -527,19 +550,18 @@ function registerRichText(editor, initialEditorState) {
|
|
|
527
550
|
const element = utils.$getNearestBlockElementAncestorOrThrow(anchor.getNode());
|
|
528
551
|
|
|
529
552
|
if (element.getIndent() > 0) {
|
|
530
|
-
return editor.dispatchCommand(lexical.OUTDENT_CONTENT_COMMAND);
|
|
553
|
+
return editor.dispatchCommand(lexical.OUTDENT_CONTENT_COMMAND, undefined);
|
|
531
554
|
}
|
|
532
555
|
}
|
|
533
556
|
|
|
534
557
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
535
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND,
|
|
558
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
|
|
536
559
|
const selection = lexical.$getSelection();
|
|
537
560
|
|
|
538
561
|
if (!lexical.$isRangeSelection(selection)) {
|
|
539
562
|
return false;
|
|
540
563
|
}
|
|
541
564
|
|
|
542
|
-
const event = payload;
|
|
543
565
|
event.preventDefault();
|
|
544
566
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, false);
|
|
545
567
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ENTER_COMMAND, event => {
|
|
@@ -568,18 +590,17 @@ function registerRichText(editor, initialEditorState) {
|
|
|
568
590
|
}
|
|
569
591
|
}
|
|
570
592
|
|
|
571
|
-
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND);
|
|
572
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND,
|
|
593
|
+
return editor.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND, undefined);
|
|
594
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
|
|
573
595
|
const selection = lexical.$getSelection();
|
|
574
596
|
|
|
575
597
|
if (!lexical.$isRangeSelection(selection)) {
|
|
576
598
|
return false;
|
|
577
599
|
}
|
|
578
600
|
|
|
579
|
-
const event = payload;
|
|
580
601
|
event.preventDefault();
|
|
581
|
-
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND);
|
|
582
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND,
|
|
602
|
+
return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined);
|
|
603
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, () => {
|
|
583
604
|
const selection = lexical.$getSelection();
|
|
584
605
|
|
|
585
606
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -593,37 +614,32 @@ function registerRichText(editor, initialEditorState) {
|
|
|
593
614
|
|
|
594
615
|
if (!lexical.$isRangeSelection(selection)) {
|
|
595
616
|
return false;
|
|
596
|
-
}
|
|
597
|
-
|
|
617
|
+
}
|
|
598
618
|
|
|
599
619
|
event.preventDefault();
|
|
600
620
|
return true;
|
|
601
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND,
|
|
621
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DRAGSTART_COMMAND, event => {
|
|
602
622
|
const selection = lexical.$getSelection();
|
|
603
623
|
|
|
604
624
|
if (!lexical.$isRangeSelection(selection)) {
|
|
605
625
|
return false;
|
|
606
|
-
}
|
|
607
|
-
|
|
626
|
+
}
|
|
608
627
|
|
|
609
|
-
const event = payload;
|
|
610
628
|
event.preventDefault();
|
|
611
629
|
return true;
|
|
612
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND,
|
|
630
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
|
|
613
631
|
const selection = lexical.$getSelection();
|
|
614
632
|
|
|
615
633
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
616
|
-
const event = payload;
|
|
617
634
|
onCopyForRichText(event, editor);
|
|
618
635
|
return true;
|
|
619
636
|
}
|
|
620
637
|
|
|
621
638
|
return false;
|
|
622
|
-
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND,
|
|
639
|
+
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
|
|
623
640
|
const selection = lexical.$getSelection();
|
|
624
641
|
|
|
625
642
|
if (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
626
|
-
const event = payload;
|
|
627
643
|
onCutForRichText(event, editor);
|
|
628
644
|
return true;
|
|
629
645
|
}
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,22 +4,24 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var a=require("@lexical/clipboard"),h=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");
|
|
8
|
-
|
|
9
|
-
class
|
|
10
|
-
|
|
11
|
-
({
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
'use strict';var a=require("@lexical/clipboard"),h=require("@lexical/selection"),k=require("@lexical/utils"),l=require("lexical");let m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,n=m&&"documentMode"in document?document.documentMode:null;m&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);m&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
8
|
+
let p=m&&"InputEvent"in window&&!n?"getTargetRanges"in new window.InputEvent("input"):!1,q=m&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),r=m&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,t={tag:"history-merge"};
|
|
9
|
+
class u extends l.ElementNode{static getType(){return"quote"}static clone(b){return new u(b.__key)}constructor(b){super(b)}createDOM(b){let e=document.createElement("blockquote");k.addClassNamesToElement(e,b.theme.quote);return e}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:w,priority:0})}}static importJSON(b){let e=x();e.setFormat(b.format);e.setIndent(b.indent);e.setDirection(b.direction);return e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let b=
|
|
10
|
+
l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){let b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}}function x(){return new u}
|
|
11
|
+
class y extends l.ElementNode{static getType(){return"heading"}static clone(b){return new y(b.__tag,b.__key)}constructor(b,e){super(e);this.__tag=b}getTag(){return this.__tag}createDOM(b){let e=this.__tag,f=document.createElement(e);b=b.theme.heading;void 0!==b&&k.addClassNamesToElement(f,b[e]);return f}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:z,priority:0}),h2:()=>({conversion:z,priority:0}),h3:()=>({conversion:z,priority:0}),h4:()=>({conversion:z,priority:0}),h5:()=>({conversion:z,
|
|
12
|
+
priority:0})}}static importJSON(b){let e=A(b.tag);e.setFormat(b.format);e.setIndent(b.indent);e.setDirection(b.direction);return e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let b=l.$createParagraphNode(),e=this.getDirection();b.setDirection(e);this.insertAfter(b);return b}collapseAtStart(){let b=l.$createParagraphNode();this.getChildren().forEach(e=>b.append(e));this.replace(b);return!0}extractWithChild(){return!0}}
|
|
13
|
+
function z(b){b=b.nodeName.toLowerCase();let e=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b)e=A(b);return{node:e}}function w(){return{node:x()}}function A(b){return new y(b)}
|
|
14
|
+
function B(b,e){if(null!==e)if(void 0===e)b.update(()=>{var f=l.$getRoot();if(null===f.getFirstChild()){let c=l.$createParagraphNode();f.append(c);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===b.getRootElement())&&c.select()}},t);else if(null!==e)switch(typeof e){case "string":e=b.parseEditorState(e);b.setEditorState(e,t);break;case "object":b.setEditorState(e,t);break;case "function":b.update(e,t)}}
|
|
15
|
+
function C(b,e){b.preventDefault();e.update(()=>{let f=l.$getSelection(),c=b.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&a.$insertDataTransferForRichText(c,f,e)})}function D(b,e){b.preventDefault();e.update(()=>{let f=b.clipboardData,c=l.$getSelection();if(null!==c&&null!=f){let d=a.$getHtmlContent(e);null!==d&&f.setData("text/html",d);f.setData("text/plain",c.getTextContent())}})}
|
|
16
|
+
function E(b,e){D(b,e);e.update(()=>{let f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}function F(b,e){var f=l.$getSelection();if(l.$isRangeSelection(f)){var c=new Set;f=f.getNodes();for(let g=0;g<f.length;g++){let v=f[g];var d=v.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(v),d.canInsertTab()?b(v):d.canIndent()&&e(d))}}}exports.$createHeadingNode=A;exports.$createQuoteNode=x;exports.$isHeadingNode=function(b){return b instanceof y};
|
|
17
|
+
exports.$isQuoteNode=function(b){return b instanceof u};exports.HeadingNode=y;exports.QuoteNode=u;
|
|
18
|
+
exports.registerRichText=function(b,e){let f=k.mergeRegister(b.registerCommand(l.CLICK_COMMAND,()=>{const c=l.$getSelection();return l.$isNodeSelection(c)?(c.clear(),!0):!1},0),b.registerCommand(l.DELETE_CHARACTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteCharacter(c);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DELETE_WORD_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteWord(c);return!0},l.COMMAND_PRIORITY_EDITOR),
|
|
19
|
+
b.registerCommand(l.DELETE_LINE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.deleteLine(c);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,c=>{const d=l.$getSelection();if("string"===typeof c)l.$isRangeSelection(d)?d.insertText(c):l.$isGridSelection(d);else{if(!l.$isRangeSelection(d)&&!l.$isGridSelection(d))return!1;const g=c.dataTransfer;null!=g?a.$insertDataTransferForRichText(g,d,b):l.$isRangeSelection(d)&&(c=c.data)&&d.insertText(c)}return!0},
|
|
18
20
|
l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.FORMAT_TEXT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.formatText(c);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.FORMAT_ELEMENT_COMMAND,c=>{var d=l.$getSelection();if(!l.$isRangeSelection(d)&&!l.$isNodeSelection(d))return!1;d=d.getNodes();for(const g of d)k.$getNearestBlockElementAncestorOrThrow(g).setFormat(c);
|
|
19
|
-
return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_LINE_BREAK_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(c);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{
|
|
20
|
-
10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{
|
|
21
|
+
return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_LINE_BREAK_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;d.insertLineBreak(c);return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{F(()=>{b.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d=
|
|
22
|
+
c.getIndent();10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{F(c=>{l.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_LEFT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,
|
|
21
23
|
!0)?(c.preventDefault(),h.$moveCharacter(d,g,!0),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ARROW_RIGHT_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;const g=c.shiftKey;return h.$shouldOverrideDefaultCharacterSelection(d,!1)?(c.preventDefault(),h.$moveCharacter(d,g,!1),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_BACKSPACE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=d);return d.isCollapsed()&&
|
|
22
|
-
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;c.preventDefault();return b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ENTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;
|
|
23
|
-
if(null!==c){if((r||q)&&p)return!1;c.preventDefault();if(c.shiftKey)return b.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return b.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=
|
|
24
|
-
if(!l.$isRangeSelection(c))return!1;b.blur();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.COPY_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||
|
|
25
|
-
(
|
|
24
|
+
0===c.offset&&0<k.$getNearestBlockElementAncestorOrThrow(c.getNode()).getIndent()?b.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_DELETE_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return b.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ENTER_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;
|
|
25
|
+
if(null!==c){if((r||q)&&p)return!1;c.preventDefault();if(c.shiftKey)return b.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return b.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=
|
|
26
|
+
l.$getSelection();if(!l.$isRangeSelection(c))return!1;b.blur();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.COPY_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||
|
|
27
|
+
l.$isGridSelection(d)?(D(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.CUT_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(E(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(C(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));B(b,e);return f}
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.3.0",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.
|
|
14
|
-
"@lexical/selection": "0.
|
|
15
|
-
"@lexical/clipboard": "0.
|
|
16
|
-
"@lexical/utils": "0.
|
|
13
|
+
"lexical": "0.3.0",
|
|
14
|
+
"@lexical/selection": "0.3.0",
|
|
15
|
+
"@lexical/clipboard": "0.3.0",
|
|
16
|
+
"@lexical/utils": "0.3.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|