@lexical/rich-text 0.2.4 → 0.2.7
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 +2 -3
- package/LexicalRichText.dev.js +71 -52
- package/LexicalRichText.js.flow +2 -2
- package/LexicalRichText.prod.js +18 -18
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -15,14 +15,13 @@ import type {
|
|
|
15
15
|
LexicalEditor,
|
|
16
16
|
} from 'lexical';
|
|
17
17
|
import {ElementNode} from 'lexical';
|
|
18
|
-
|
|
19
18
|
export type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
20
19
|
|
|
21
20
|
export declare class QuoteNode extends ElementNode {
|
|
22
21
|
static getType(): string;
|
|
23
22
|
static clone(node: QuoteNode): QuoteNode;
|
|
24
23
|
constructor(key?: NodeKey);
|
|
25
|
-
createDOM
|
|
24
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
26
25
|
updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean;
|
|
27
26
|
insertNewAfter(): ParagraphNode;
|
|
28
27
|
collapseAtStart(): true;
|
|
@@ -36,7 +35,7 @@ export declare class HeadingNode extends ElementNode {
|
|
|
36
35
|
static clone(node: HeadingNode): HeadingNode;
|
|
37
36
|
constructor(tag: HeadingTagType, key?: NodeKey);
|
|
38
37
|
getTag(): HeadingTagType;
|
|
39
|
-
createDOM
|
|
38
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
40
39
|
updateDOM(prevNode: HeadingNode, dom: HTMLElement): boolean;
|
|
41
40
|
static importDOM(): DOMConversionMap | null;
|
|
42
41
|
insertNewAfter(): ParagraphNode;
|
package/LexicalRichText.dev.js
CHANGED
|
@@ -32,8 +32,8 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
32
32
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
33
33
|
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
34
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);
|
|
35
|
+
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\.]+.*Safari/.test(navigator.userAgent);
|
|
37
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
38
|
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
39
39
|
// export const IS_CHROME: boolean = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
@@ -181,6 +181,10 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
181
181
|
return true;
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
extractWithChild() {
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
|
|
184
188
|
}
|
|
185
189
|
|
|
186
190
|
function convertHeadingElement(domNode) {
|
|
@@ -251,7 +255,7 @@ function onPasteForRichText(event, editor) {
|
|
|
251
255
|
const selection = lexical.$getSelection();
|
|
252
256
|
const clipboardData = event.clipboardData;
|
|
253
257
|
|
|
254
|
-
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
258
|
+
if (clipboardData != null && (lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection))) {
|
|
255
259
|
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
256
260
|
}
|
|
257
261
|
});
|
|
@@ -265,7 +269,7 @@ function onCopyForRichText(event, editor) {
|
|
|
265
269
|
|
|
266
270
|
if (selection !== null) {
|
|
267
271
|
if (clipboardData != null) {
|
|
268
|
-
const htmlString = clipboard
|
|
272
|
+
const htmlString = clipboard.$getHtmlContent(editor);
|
|
269
273
|
const lexicalString = clipboard.$getLexicalContent(editor);
|
|
270
274
|
|
|
271
275
|
if (htmlString !== null) {
|
|
@@ -293,6 +297,35 @@ function onCutForRichText(event, editor) {
|
|
|
293
297
|
});
|
|
294
298
|
}
|
|
295
299
|
|
|
300
|
+
function handleIndentAndOutdent(insertTab, indentOrOutdent) {
|
|
301
|
+
const selection = lexical.$getSelection();
|
|
302
|
+
|
|
303
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const alreadyHandled = new Set();
|
|
308
|
+
const nodes = selection.getNodes();
|
|
309
|
+
|
|
310
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
311
|
+
const node = nodes[i];
|
|
312
|
+
const key = node.getKey();
|
|
313
|
+
|
|
314
|
+
if (alreadyHandled.has(key)) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
alreadyHandled.add(key);
|
|
319
|
+
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(node);
|
|
320
|
+
|
|
321
|
+
if (parentBlock.canInsertTab()) {
|
|
322
|
+
insertTab(node);
|
|
323
|
+
} else if (parentBlock.canIndent()) {
|
|
324
|
+
indentOrOutdent(parentBlock);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
296
329
|
function registerRichText(editor, initialEditorState) {
|
|
297
330
|
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
|
|
298
331
|
const selection = lexical.$getSelection();
|
|
@@ -303,14 +336,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
303
336
|
}
|
|
304
337
|
|
|
305
338
|
return false;
|
|
306
|
-
}, 0), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND,
|
|
339
|
+
}, 0), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
|
|
307
340
|
const selection = lexical.$getSelection();
|
|
308
341
|
|
|
309
342
|
if (!lexical.$isRangeSelection(selection)) {
|
|
310
343
|
return false;
|
|
311
344
|
}
|
|
312
345
|
|
|
313
|
-
const isBackward = payload;
|
|
314
346
|
selection.deleteCharacter(isBackward);
|
|
315
347
|
return true;
|
|
316
348
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, payload => {
|
|
@@ -335,21 +367,22 @@ function registerRichText(editor, initialEditorState) {
|
|
|
335
367
|
return true;
|
|
336
368
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_TEXT_COMMAND, payload => {
|
|
337
369
|
const selection = lexical.$getSelection();
|
|
338
|
-
|
|
339
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
370
|
const eventOrText = payload;
|
|
344
371
|
|
|
345
372
|
if (typeof eventOrText === 'string') {
|
|
346
|
-
selection
|
|
373
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
374
|
+
selection.insertText(eventOrText);
|
|
375
|
+
} else if (lexical.$isGridSelection(selection)) ;
|
|
347
376
|
} else {
|
|
377
|
+
if (!lexical.$isRangeSelection(selection) && !lexical.$isGridSelection(selection)) {
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
|
|
348
381
|
const dataTransfer = eventOrText.dataTransfer;
|
|
349
382
|
|
|
350
383
|
if (dataTransfer != null) {
|
|
351
384
|
clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
352
|
-
} else {
|
|
385
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
|
353
386
|
const data = eventOrText.data;
|
|
354
387
|
|
|
355
388
|
if (data) {
|
|
@@ -415,50 +448,33 @@ function registerRichText(editor, initialEditorState) {
|
|
|
415
448
|
selection.insertParagraph();
|
|
416
449
|
return true;
|
|
417
450
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => {
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
421
|
-
return false;
|
|
422
|
-
} // Handle code blocks
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
const anchor = selection.anchor;
|
|
426
|
-
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(anchor.getNode());
|
|
427
|
-
|
|
428
|
-
if (parentBlock.canInsertTab()) {
|
|
451
|
+
handleIndentAndOutdent(() => {
|
|
429
452
|
editor.dispatchCommand(lexical.INSERT_TEXT_COMMAND, '\t');
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
parentBlock.setIndent(parentBlock.getIndent() + 1);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
453
|
+
}, block => {
|
|
454
|
+
const indent = block.getIndent();
|
|
435
455
|
|
|
456
|
+
if (indent !== 10) {
|
|
457
|
+
block.setIndent(indent + 1);
|
|
458
|
+
}
|
|
459
|
+
});
|
|
436
460
|
return true;
|
|
437
461
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => {
|
|
438
|
-
|
|
462
|
+
handleIndentAndOutdent(node => {
|
|
463
|
+
if (lexical.$isTextNode(node)) {
|
|
464
|
+
const textContent = node.getTextContent();
|
|
465
|
+
const character = textContent[textContent.length - 1];
|
|
439
466
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
const anchor = selection.anchor;
|
|
446
|
-
const anchorNode = anchor.getNode();
|
|
447
|
-
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(anchor.getNode());
|
|
448
|
-
|
|
449
|
-
if (parentBlock.canInsertTab()) {
|
|
450
|
-
const textContent = anchorNode.getTextContent();
|
|
451
|
-
const character = textContent[anchor.offset - 1];
|
|
452
|
-
|
|
453
|
-
if (character === '\t') {
|
|
454
|
-
editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
455
|
-
}
|
|
456
|
-
} else {
|
|
457
|
-
if (parentBlock.getIndent() !== 0) {
|
|
458
|
-
parentBlock.setIndent(parentBlock.getIndent() - 1);
|
|
467
|
+
if (character === '\t') {
|
|
468
|
+
editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
469
|
+
}
|
|
459
470
|
}
|
|
460
|
-
}
|
|
471
|
+
}, block => {
|
|
472
|
+
const indent = block.getIndent();
|
|
461
473
|
|
|
474
|
+
if (indent !== 0) {
|
|
475
|
+
block.setIndent(indent - 1);
|
|
476
|
+
}
|
|
477
|
+
});
|
|
462
478
|
return true;
|
|
463
479
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
|
|
464
480
|
const selection$1 = lexical.$getSelection();
|
|
@@ -538,14 +554,17 @@ function registerRichText(editor, initialEditorState) {
|
|
|
538
554
|
// the default behavior. This ensures that the iOS can
|
|
539
555
|
// intercept that we're actually inserting a paragraph,
|
|
540
556
|
// and autocomplete, autocapitialize etc work as intended.
|
|
541
|
-
|
|
557
|
+
// This can also cause a strange performance issue in
|
|
558
|
+
// Safari, where there is a noticeable pause due to
|
|
559
|
+
// preventing the key down of enter.
|
|
560
|
+
if ((IS_IOS || IS_SAFARI) && CAN_USE_BEFORE_INPUT) {
|
|
542
561
|
return false;
|
|
543
562
|
}
|
|
544
563
|
|
|
545
564
|
event.preventDefault();
|
|
546
565
|
|
|
547
566
|
if (event.shiftKey) {
|
|
548
|
-
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND);
|
|
567
|
+
return editor.dispatchCommand(lexical.INSERT_LINE_BREAK_COMMAND, false);
|
|
549
568
|
}
|
|
550
569
|
}
|
|
551
570
|
|
package/LexicalRichText.js.flow
CHANGED
|
@@ -22,7 +22,7 @@ declare export class QuoteNode extends ElementNode {
|
|
|
22
22
|
static getType(): string;
|
|
23
23
|
static clone(node: QuoteNode): QuoteNode;
|
|
24
24
|
constructor(key?: NodeKey): void;
|
|
25
|
-
createDOM
|
|
25
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
26
26
|
updateDOM(prevNode: QuoteNode, dom: HTMLElement): boolean;
|
|
27
27
|
insertNewAfter(): ParagraphNode;
|
|
28
28
|
collapseAtStart(): true;
|
|
@@ -38,7 +38,7 @@ declare export class HeadingNode extends ElementNode {
|
|
|
38
38
|
static clone(node: HeadingNode): HeadingNode;
|
|
39
39
|
constructor(tag: HeadingTagType, key?: NodeKey): void;
|
|
40
40
|
getTag(): HeadingTagType;
|
|
41
|
-
createDOM
|
|
41
|
+
createDOM(config: EditorConfig): HTMLElement;
|
|
42
42
|
updateDOM(prevNode: HeadingNode, dom: HTMLElement): boolean;
|
|
43
43
|
static importDOM(): DOMConversionMap | null;
|
|
44
44
|
insertNewAfter(): ParagraphNode;
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,22 +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="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
|
-
m&&/Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
|
|
9
|
-
class
|
|
10
|
-
class
|
|
11
|
-
({conversion:
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
function
|
|
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);
|
|
8
|
+
const 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,u={tag:"history-merge"};
|
|
9
|
+
class v extends l.ElementNode{static getType(){return"quote"}static clone(b){return new v(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 w extends l.ElementNode{static getType(){return"heading"}static clone(b){return new w(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:x,priority:0}),h2:()=>({conversion:x,priority:0}),h3:()=>({conversion:x,priority:0}),h4:()=>({conversion:x,priority:0}),h5:()=>
|
|
11
|
+
({conversion:x,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}extractWithChild(){return!0}}function x(b){b=b.nodeName.toLowerCase();let e=null;if("h1"===b||"h2"===b||"h3"===b||"h4"===b||"h5"===b)e=y(b);return{node:e}}function y(b){return new w(b)}
|
|
12
|
+
function z(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()}},u);else if(null!==e)switch(typeof e){case "string":e=b.parseEditorState(e);b.setEditorState(e,u);break;case "object":b.setEditorState(e,u);break;case "function":b.update(e,u)}}
|
|
13
|
+
function A(b,e){b.preventDefault();e.update(()=>{const f=l.$getSelection(),c=b.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&a.$insertDataTransferForRichText(c,f,e)})}function B(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 C(b,e){B(b,e);e.update(()=>{const f=l.$getSelection();l.$isRangeSelection(f)&&f.removeText()})}function D(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++){const t=f[g];var d=t.getKey();c.has(d)||(c.add(d),d=k.$getNearestBlockElementAncestorOrThrow(t),d.canInsertTab()?b(t):d.canIndent()&&e(d))}}}exports.$createHeadingNode=y;exports.$createQuoteNode=function(){return new v};
|
|
15
|
+
exports.$isHeadingNode=function(b){return b instanceof w};exports.$isQuoteNode=function(b){return b instanceof v};exports.HeadingNode=w;exports.QuoteNode=v;
|
|
15
16
|
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(
|
|
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);
|
|
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,()=>{
|
|
19
|
-
|
|
20
|
-
l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.
|
|
21
|
-
|
|
22
|
-
c.preventDefault();return b.dispatchCommand(l.
|
|
23
|
-
c
|
|
24
|
-
|
|
25
|
-
l.$isGridSelection(d)?(x(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));w(b,e);return f};
|
|
17
|
+
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("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
|
+
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,()=>{D(()=>{b.dispatchCommand(l.INSERT_TEXT_COMMAND,"\t")},c=>{const d=c.getIndent();
|
|
20
|
+
10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{D(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
|
+
!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=l.$getSelection();
|
|
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)||l.$isGridSelection(d)?
|
|
25
|
+
(B(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)?(C(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)?(A(c,b),!0):!1},l.COMMAND_PRIORITY_EDITOR));z(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.7",
|
|
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.7",
|
|
14
|
+
"@lexical/selection": "0.2.7",
|
|
15
|
+
"@lexical/clipboard": "0.2.7",
|
|
16
|
+
"@lexical/utils": "0.2.7"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|