@lexical/rich-text 0.2.2 → 0.2.5
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 -6
- package/LexicalRichText.dev.js +98 -47
- package/LexicalRichText.js.flow +2 -2
- package/LexicalRichText.prod.js +18 -17
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -12,23 +12,22 @@ import type {
|
|
|
12
12
|
LexicalNode,
|
|
13
13
|
NodeKey,
|
|
14
14
|
ParagraphNode,
|
|
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;
|
|
29
28
|
}
|
|
30
29
|
export function $createQuoteNode(): QuoteNode;
|
|
31
|
-
export function $isQuoteNode(node: ?LexicalNode):
|
|
30
|
+
export function $isQuoteNode(node: ?LexicalNode): node is QuoteNode;
|
|
32
31
|
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
33
32
|
export declare class HeadingNode extends ElementNode {
|
|
34
33
|
__tag: HeadingTagType;
|
|
@@ -36,14 +35,14 @@ 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;
|
|
43
42
|
collapseAtStart(): true;
|
|
44
43
|
}
|
|
45
44
|
export function $createHeadingNode(headingTag: HeadingTagType): HeadingNode;
|
|
46
|
-
export function $isHeadingNode(node: ?LexicalNode):
|
|
45
|
+
export function $isHeadingNode(node: ?LexicalNode): node is HeadingNode;
|
|
47
46
|
export function registerRichText(
|
|
48
47
|
editor: LexicalEditor,
|
|
49
48
|
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
|
+
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
|
+
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
|
*
|
|
@@ -223,7 +251,7 @@ function onPasteForRichText(event, editor) {
|
|
|
223
251
|
const selection = lexical.$getSelection();
|
|
224
252
|
const clipboardData = event.clipboardData;
|
|
225
253
|
|
|
226
|
-
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
254
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection) || lexical.$isGridSelection(selection)) {
|
|
227
255
|
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
228
256
|
}
|
|
229
257
|
});
|
|
@@ -265,6 +293,35 @@ function onCutForRichText(event, editor) {
|
|
|
265
293
|
});
|
|
266
294
|
}
|
|
267
295
|
|
|
296
|
+
function handleIndentAndOutdent(insertTab, indentOrOutdent) {
|
|
297
|
+
const selection = lexical.$getSelection();
|
|
298
|
+
|
|
299
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const alreadyHandled = new Set();
|
|
304
|
+
const nodes = selection.getNodes();
|
|
305
|
+
|
|
306
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
307
|
+
const node = nodes[i];
|
|
308
|
+
const key = node.getKey();
|
|
309
|
+
|
|
310
|
+
if (alreadyHandled.has(key)) {
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
alreadyHandled.add(key);
|
|
315
|
+
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(node);
|
|
316
|
+
|
|
317
|
+
if (parentBlock.canInsertTab()) {
|
|
318
|
+
insertTab(node);
|
|
319
|
+
} else if (parentBlock.canIndent()) {
|
|
320
|
+
indentOrOutdent(parentBlock);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
268
325
|
function registerRichText(editor, initialEditorState) {
|
|
269
326
|
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
|
|
270
327
|
const selection = lexical.$getSelection();
|
|
@@ -275,14 +332,13 @@ function registerRichText(editor, initialEditorState) {
|
|
|
275
332
|
}
|
|
276
333
|
|
|
277
334
|
return false;
|
|
278
|
-
}, 0), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND,
|
|
335
|
+
}, 0), editor.registerCommand(lexical.DELETE_CHARACTER_COMMAND, isBackward => {
|
|
279
336
|
const selection = lexical.$getSelection();
|
|
280
337
|
|
|
281
338
|
if (!lexical.$isRangeSelection(selection)) {
|
|
282
339
|
return false;
|
|
283
340
|
}
|
|
284
341
|
|
|
285
|
-
const isBackward = payload;
|
|
286
342
|
selection.deleteCharacter(isBackward);
|
|
287
343
|
return true;
|
|
288
344
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.DELETE_WORD_COMMAND, payload => {
|
|
@@ -307,21 +363,22 @@ function registerRichText(editor, initialEditorState) {
|
|
|
307
363
|
return true;
|
|
308
364
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INSERT_TEXT_COMMAND, payload => {
|
|
309
365
|
const selection = lexical.$getSelection();
|
|
310
|
-
|
|
311
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
366
|
const eventOrText = payload;
|
|
316
367
|
|
|
317
368
|
if (typeof eventOrText === 'string') {
|
|
318
|
-
selection
|
|
369
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
370
|
+
selection.insertText(eventOrText);
|
|
371
|
+
} else if (lexical.$isGridSelection(selection)) ;
|
|
319
372
|
} else {
|
|
373
|
+
if (!lexical.$isRangeSelection(selection) && !lexical.$isGridSelection(selection)) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
|
|
320
377
|
const dataTransfer = eventOrText.dataTransfer;
|
|
321
378
|
|
|
322
379
|
if (dataTransfer != null) {
|
|
323
380
|
clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
324
|
-
} else {
|
|
381
|
+
} else if (lexical.$isRangeSelection(selection)) {
|
|
325
382
|
const data = eventOrText.data;
|
|
326
383
|
|
|
327
384
|
if (data) {
|
|
@@ -387,50 +444,33 @@ function registerRichText(editor, initialEditorState) {
|
|
|
387
444
|
selection.insertParagraph();
|
|
388
445
|
return true;
|
|
389
446
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, payload => {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
393
|
-
return false;
|
|
394
|
-
} // Handle code blocks
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const anchor = selection.anchor;
|
|
398
|
-
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(anchor.getNode());
|
|
399
|
-
|
|
400
|
-
if (parentBlock.canInsertTab()) {
|
|
447
|
+
handleIndentAndOutdent(() => {
|
|
401
448
|
editor.dispatchCommand(lexical.INSERT_TEXT_COMMAND, '\t');
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
parentBlock.setIndent(parentBlock.getIndent() + 1);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
449
|
+
}, block => {
|
|
450
|
+
const indent = block.getIndent();
|
|
407
451
|
|
|
452
|
+
if (indent !== 10) {
|
|
453
|
+
block.setIndent(indent + 1);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
408
456
|
return true;
|
|
409
457
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, payload => {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
} // Handle code blocks
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
const anchor = selection.anchor;
|
|
418
|
-
const anchorNode = anchor.getNode();
|
|
419
|
-
const parentBlock = utils.$getNearestBlockElementAncestorOrThrow(anchor.getNode());
|
|
420
|
-
|
|
421
|
-
if (parentBlock.canInsertTab()) {
|
|
422
|
-
const textContent = anchorNode.getTextContent();
|
|
423
|
-
const character = textContent[anchor.offset - 1];
|
|
458
|
+
handleIndentAndOutdent(node => {
|
|
459
|
+
if (lexical.$isTextNode(node)) {
|
|
460
|
+
const textContent = node.getTextContent();
|
|
461
|
+
const character = textContent[textContent.length - 1];
|
|
424
462
|
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
} else {
|
|
429
|
-
if (parentBlock.getIndent() !== 0) {
|
|
430
|
-
parentBlock.setIndent(parentBlock.getIndent() - 1);
|
|
463
|
+
if (character === '\t') {
|
|
464
|
+
editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
465
|
+
}
|
|
431
466
|
}
|
|
432
|
-
}
|
|
467
|
+
}, block => {
|
|
468
|
+
const indent = block.getIndent();
|
|
433
469
|
|
|
470
|
+
if (indent !== 0) {
|
|
471
|
+
block.setIndent(indent - 1);
|
|
472
|
+
}
|
|
473
|
+
});
|
|
434
474
|
return true;
|
|
435
475
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_ARROW_LEFT_COMMAND, payload => {
|
|
436
476
|
const selection$1 = lexical.$getSelection();
|
|
@@ -506,6 +546,17 @@ function registerRichText(editor, initialEditorState) {
|
|
|
506
546
|
}
|
|
507
547
|
|
|
508
548
|
if (event !== null) {
|
|
549
|
+
// If we have beforeinput, then we can avoid blocking
|
|
550
|
+
// the default behavior. This ensures that the iOS can
|
|
551
|
+
// intercept that we're actually inserting a paragraph,
|
|
552
|
+
// and autocomplete, autocapitialize etc work as intended.
|
|
553
|
+
// This can also cause a strange performance issue in
|
|
554
|
+
// Safari, where there is a noticeable pause due to
|
|
555
|
+
// preventing the key down of enter.
|
|
556
|
+
if ((IS_IOS || IS_SAFARI) && CAN_USE_BEFORE_INPUT) {
|
|
557
|
+
return false;
|
|
558
|
+
}
|
|
559
|
+
|
|
509
560
|
event.preventDefault();
|
|
510
561
|
|
|
511
562
|
if (event.shiftKey) {
|
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,21 +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
|
|
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}}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;
|
|
14
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),
|
|
15
|
-
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(
|
|
16
|
-
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);
|
|
17
|
-
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,()=>{
|
|
18
|
-
|
|
19
|
-
l.COMMAND_PRIORITY_EDITOR),b.registerCommand(l.
|
|
20
|
-
|
|
21
|
-
c
|
|
22
|
-
l.
|
|
23
|
-
|
|
24
|
-
t(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)}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.5",
|
|
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.5",
|
|
14
|
+
"@lexical/selection": "0.2.5",
|
|
15
|
+
"@lexical/clipboard": "0.2.5",
|
|
16
|
+
"@lexical/utils": "0.2.5"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|