@lexical/rich-text 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalRichText.d.ts +8 -4
- package/LexicalRichText.dev.js +31 -4
- package/LexicalRichText.js.flow +6 -2
- package/LexicalRichText.prod.js +21 -20
- package/package.json +5 -5
package/LexicalRichText.d.ts
CHANGED
|
@@ -17,9 +17,13 @@ import type {
|
|
|
17
17
|
SerializedElementNode,
|
|
18
18
|
} from 'lexical';
|
|
19
19
|
import {ElementNode} from 'lexical';
|
|
20
|
-
import {Spread} from '
|
|
20
|
+
import type {Spread} from 'lexical';
|
|
21
21
|
|
|
22
|
-
export type InitialEditorStateType =
|
|
22
|
+
export type InitialEditorStateType =
|
|
23
|
+
| null
|
|
24
|
+
| string
|
|
25
|
+
| EditorState
|
|
26
|
+
| ((editor: LexicalEditor) => void);
|
|
23
27
|
|
|
24
28
|
export declare class QuoteNode extends ElementNode {
|
|
25
29
|
static getType(): string;
|
|
@@ -35,7 +39,7 @@ export function $createQuoteNode(): QuoteNode;
|
|
|
35
39
|
export function $isQuoteNode(
|
|
36
40
|
node: LexicalNode | null | undefined,
|
|
37
41
|
): node is QuoteNode;
|
|
38
|
-
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
42
|
+
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
39
43
|
export declare class HeadingNode extends ElementNode {
|
|
40
44
|
__tag: HeadingTagType;
|
|
41
45
|
static getType(): string;
|
|
@@ -61,7 +65,7 @@ export function registerRichText(
|
|
|
61
65
|
|
|
62
66
|
export type SerializedHeadingNode = Spread<
|
|
63
67
|
{
|
|
64
|
-
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
68
|
+
tag: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
65
69
|
type: 'heading';
|
|
66
70
|
version: 1;
|
|
67
71
|
},
|
package/LexicalRichText.dev.js
CHANGED
|
@@ -173,6 +173,10 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
173
173
|
h5: node => ({
|
|
174
174
|
conversion: convertHeadingElement,
|
|
175
175
|
priority: 0
|
|
176
|
+
}),
|
|
177
|
+
h6: node => ({
|
|
178
|
+
conversion: convertHeadingElement,
|
|
179
|
+
priority: 0
|
|
176
180
|
})
|
|
177
181
|
};
|
|
178
182
|
}
|
|
@@ -220,7 +224,7 @@ function convertHeadingElement(domNode) {
|
|
|
220
224
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
221
225
|
let node = null;
|
|
222
226
|
|
|
223
|
-
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5') {
|
|
227
|
+
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
|
|
224
228
|
node = $createHeadingNode(nodeName);
|
|
225
229
|
}
|
|
226
230
|
|
|
@@ -249,9 +253,8 @@ function initializeEditor(editor, initialEditorState) {
|
|
|
249
253
|
} else if (initialEditorState === undefined) {
|
|
250
254
|
editor.update(() => {
|
|
251
255
|
const root = lexical.$getRoot();
|
|
252
|
-
const firstChild = root.getFirstChild();
|
|
253
256
|
|
|
254
|
-
if (
|
|
257
|
+
if (root.isEmpty()) {
|
|
255
258
|
const paragraph = lexical.$createParagraphNode();
|
|
256
259
|
root.append(paragraph);
|
|
257
260
|
const activeElement = document.activeElement;
|
|
@@ -278,7 +281,13 @@ function initializeEditor(editor, initialEditorState) {
|
|
|
278
281
|
|
|
279
282
|
case 'function':
|
|
280
283
|
{
|
|
281
|
-
editor.update(
|
|
284
|
+
editor.update(() => {
|
|
285
|
+
const root = lexical.$getRoot();
|
|
286
|
+
|
|
287
|
+
if (root.isEmpty()) {
|
|
288
|
+
initialEditorState(editor);
|
|
289
|
+
}
|
|
290
|
+
}, updateOptions);
|
|
282
291
|
break;
|
|
283
292
|
}
|
|
284
293
|
}
|
|
@@ -304,12 +313,17 @@ function onCopyForRichText(event, editor) {
|
|
|
304
313
|
if (selection !== null) {
|
|
305
314
|
const clipboardData = event.clipboardData;
|
|
306
315
|
const htmlString = clipboard.$getHtmlContent(editor);
|
|
316
|
+
const lexicalString = clipboard.$getLexicalContent(editor);
|
|
307
317
|
|
|
308
318
|
if (clipboardData != null) {
|
|
309
319
|
if (htmlString !== null) {
|
|
310
320
|
clipboardData.setData('text/html', htmlString);
|
|
311
321
|
}
|
|
312
322
|
|
|
323
|
+
if (lexicalString !== null) {
|
|
324
|
+
clipboardData.setData('application/x-lexical-editor', lexicalString);
|
|
325
|
+
}
|
|
326
|
+
|
|
313
327
|
const plainString = selection.getTextContent();
|
|
314
328
|
clipboardData.setData('text/plain', plainString);
|
|
315
329
|
} else {
|
|
@@ -369,6 +383,11 @@ function handleIndentAndOutdent(insertTab, indentOrOutdent) {
|
|
|
369
383
|
}
|
|
370
384
|
}
|
|
371
385
|
|
|
386
|
+
function isTargetWithinDecorator(target) {
|
|
387
|
+
const node = lexical.$getNearestNodeFromDOMNode(target);
|
|
388
|
+
return lexical.$isDecoratorNode(node);
|
|
389
|
+
}
|
|
390
|
+
|
|
372
391
|
function registerRichText(editor, initialEditorState) {
|
|
373
392
|
const removeListener = utils.mergeRegister(editor.registerCommand(lexical.CLICK_COMMAND, payload => {
|
|
374
393
|
const selection = lexical.$getSelection();
|
|
@@ -547,6 +566,10 @@ function registerRichText(editor, initialEditorState) {
|
|
|
547
566
|
|
|
548
567
|
return false;
|
|
549
568
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, event => {
|
|
569
|
+
if (isTargetWithinDecorator(event.target)) {
|
|
570
|
+
return false;
|
|
571
|
+
}
|
|
572
|
+
|
|
550
573
|
const selection = lexical.$getSelection();
|
|
551
574
|
|
|
552
575
|
if (!lexical.$isRangeSelection(selection)) {
|
|
@@ -568,6 +591,10 @@ function registerRichText(editor, initialEditorState) {
|
|
|
568
591
|
|
|
569
592
|
return editor.dispatchCommand(lexical.DELETE_CHARACTER_COMMAND, true);
|
|
570
593
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.KEY_DELETE_COMMAND, event => {
|
|
594
|
+
if (isTargetWithinDecorator(event.target)) {
|
|
595
|
+
return false;
|
|
596
|
+
}
|
|
597
|
+
|
|
571
598
|
const selection = lexical.$getSelection();
|
|
572
599
|
|
|
573
600
|
if (!lexical.$isRangeSelection(selection)) {
|
package/LexicalRichText.js.flow
CHANGED
|
@@ -16,7 +16,11 @@ import type {
|
|
|
16
16
|
LexicalEditor,
|
|
17
17
|
} from 'lexical';
|
|
18
18
|
import {ElementNode} from 'lexical';
|
|
19
|
-
export type InitialEditorStateType =
|
|
19
|
+
export type InitialEditorStateType =
|
|
20
|
+
| null
|
|
21
|
+
| string
|
|
22
|
+
| EditorState
|
|
23
|
+
| ((editor: LexicalEditor) => void);
|
|
20
24
|
|
|
21
25
|
declare export class QuoteNode extends ElementNode {
|
|
22
26
|
static getType(): string;
|
|
@@ -31,7 +35,7 @@ declare export function $createQuoteNode(): QuoteNode;
|
|
|
31
35
|
declare export function $isQuoteNode(
|
|
32
36
|
node: ?LexicalNode,
|
|
33
37
|
): boolean %checks(node instanceof QuoteNode);
|
|
34
|
-
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5';
|
|
38
|
+
export type HeadingTagType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
35
39
|
declare export class HeadingNode extends ElementNode {
|
|
36
40
|
__tag: HeadingTagType;
|
|
37
41
|
static getType(): string;
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,24 +4,25 @@
|
|
|
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
|
-
'use strict';var
|
|
7
|
+
'use strict';var b=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
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(
|
|
10
|
-
l.$createParagraphNode(),e=this.getDirection();
|
|
11
|
-
class y extends l.ElementNode{static getType(){return"heading"}static clone(
|
|
12
|
-
priority:0})}}static importJSON(
|
|
13
|
-
function z(
|
|
14
|
-
function B(
|
|
15
|
-
function C(
|
|
16
|
-
function D(
|
|
17
|
-
function F(
|
|
18
|
-
exports
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
0
|
|
25
|
-
|
|
26
|
-
l.$getSelection();if(!l.$isRangeSelection(
|
|
27
|
-
|
|
9
|
+
class u extends l.ElementNode{static getType(){return"quote"}static clone(a){return new u(a.__key)}constructor(a){super(a)}createDOM(a){let e=document.createElement("blockquote");k.addClassNamesToElement(e,a.theme.quote);return e}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:w,priority:0})}}static importJSON(a){let e=x();e.setFormat(a.format);e.setIndent(a.indent);e.setDirection(a.direction);return e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let a=
|
|
10
|
+
l.$createParagraphNode(),e=this.getDirection();a.setDirection(e);this.insertAfter(a);return a}collapseAtStart(){let a=l.$createParagraphNode();this.getChildren().forEach(e=>a.append(e));this.replace(a);return!0}}function x(){return new u}
|
|
11
|
+
class y extends l.ElementNode{static getType(){return"heading"}static clone(a){return new y(a.__tag,a.__key)}constructor(a,e){super(e);this.__tag=a}getTag(){return this.__tag}createDOM(a){let e=this.__tag,f=document.createElement(e);a=a.theme.heading;void 0!==a&&k.addClassNamesToElement(f,a[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}),h6:()=>({conversion:z,priority:0})}}static importJSON(a){let e=A(a.tag);e.setFormat(a.format);e.setIndent(a.indent);e.setDirection(a.direction);return e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let a=l.$createParagraphNode(),e=this.getDirection();a.setDirection(e);this.insertAfter(a);return a}collapseAtStart(){let a=l.$createParagraphNode();this.getChildren().forEach(e=>a.append(e));this.replace(a);return!0}extractWithChild(){return!0}}
|
|
13
|
+
function z(a){a=a.nodeName.toLowerCase();let e=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)e=A(a);return{node:e}}function w(){return{node:x()}}function A(a){return new y(a)}
|
|
14
|
+
function B(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=l.$getRoot();if(f.isEmpty()){let c=l.$createParagraphNode();f.append(c);f=document.activeElement;(null!==l.$getSelection()||null!==f&&f===a.getRootElement())&&c.select()}},t);else if(null!==e)switch(typeof e){case "string":let f=a.parseEditorState(e);a.setEditorState(f,t);break;case "object":a.setEditorState(e,t);break;case "function":a.update(()=>{l.$getRoot().isEmpty()&&e(a)},t)}}
|
|
15
|
+
function C(a,e){a.preventDefault();e.update(()=>{let f=l.$getSelection(),c=a.clipboardData;null!=c&&(l.$isRangeSelection(f)||l.$isGridSelection(f))&&b.$insertDataTransferForRichText(c,f,e)})}
|
|
16
|
+
function D(a,e){a.preventDefault();var f=l.$getSelection();if(null!==f){a=a.clipboardData;let c=b.$getHtmlContent(e);e=b.$getLexicalContent(e);null!=a?(null!==c&&a.setData("text/html",c),null!==e&&a.setData("application/x-lexical-editor",e),f=f.getTextContent(),a.setData("text/plain",f)):(f=navigator.clipboard,null!=f&&(a=[new ClipboardItem({"text/html":new Blob([c],{type:"text/html"})})],f.write(a)))}}
|
|
17
|
+
function E(a,e){D(a,e);a=l.$getSelection();l.$isRangeSelection(a)?a.removeText():l.$isNodeSelection(a)&&a.getNodes().forEach(f=>f.remove())}function F(a,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()?a(v):d.canIndent()&&e(d))}}}function G(a){a=l.$getNearestNodeFromDOMNode(a);return l.$isDecoratorNode(a)}
|
|
18
|
+
exports.$createHeadingNode=A;exports.$createQuoteNode=x;exports.$isHeadingNode=function(a){return a instanceof y};exports.$isQuoteNode=function(a){return a instanceof u};exports.HeadingNode=y;exports.QuoteNode=u;
|
|
19
|
+
exports.registerRichText=function(a,e){let f=k.mergeRegister(a.registerCommand(l.CLICK_COMMAND,()=>{const c=l.$getSelection();return l.$isNodeSelection(c)?(c.clear(),!0):!1},0),a.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),a.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),
|
|
20
|
+
a.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),a.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?b.$insertDataTransferForRichText(g,d,a):l.$isRangeSelection(d)&&(c=c.data)&&d.insertText(c)}return!0},
|
|
21
|
+
l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.REMOVE_TEXT_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.removeText();return!0},l.COMMAND_PRIORITY_EDITOR),a.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),a.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);
|
|
22
|
+
return!0},l.COMMAND_PRIORITY_EDITOR),a.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),a.registerCommand(l.INSERT_PARAGRAPH_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;c.insertParagraph();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.INDENT_CONTENT_COMMAND,()=>{F(()=>{a.dispatchCommand(l.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},c=>{const d=
|
|
23
|
+
c.getIndent();10!==d&&c.setIndent(d+1)});return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.OUTDENT_CONTENT_COMMAND,()=>{F(c=>{l.$isTextNode(c)&&(c=c.getTextContent(),"\t"===c[c.length-1]&&a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0))},c=>{const d=c.getIndent();0!==d&&c.setIndent(d-1)});return!0},l.COMMAND_PRIORITY_EDITOR),a.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,
|
|
24
|
+
!0)?(c.preventDefault(),h.$moveCharacter(d,g,!0),!0):!1},l.COMMAND_PRIORITY_EDITOR),a.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),a.registerCommand(l.KEY_BACKSPACE_COMMAND,c=>{if(G(c.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();({anchor:c}=
|
|
25
|
+
d);return d.isCollapsed()&&0===c.offset&&0<k.$getNearestBlockElementAncestorOrThrow(c.getNode()).getIndent()?a.dispatchCommand(l.OUTDENT_CONTENT_COMMAND,void 0):a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!0)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_DELETE_COMMAND,c=>{if(G(c.target))return!1;const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return a.dispatchCommand(l.DELETE_CHARACTER_COMMAND,!1)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_ENTER_COMMAND,
|
|
26
|
+
c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;if(null!==c){if((r||q)&&p)return!1;c.preventDefault();if(c.shiftKey)return a.dispatchCommand(l.INSERT_LINE_BREAK_COMMAND,!1)}return a.dispatchCommand(l.INSERT_PARAGRAPH_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.KEY_TAB_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return a.dispatchCommand(c.shiftKey?l.OUTDENT_CONTENT_COMMAND:l.INDENT_CONTENT_COMMAND,void 0)},l.COMMAND_PRIORITY_EDITOR),
|
|
27
|
+
a.registerCommand(l.KEY_ESCAPE_COMMAND,()=>{const c=l.$getSelection();if(!l.$isRangeSelection(c))return!1;a.blur();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.DROP_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.DRAGSTART_COMMAND,c=>{const d=l.$getSelection();if(!l.$isRangeSelection(d))return!1;c.preventDefault();return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.COPY_COMMAND,c=>
|
|
28
|
+
{D(c,a);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.CUT_COMMAND,c=>{E(c,a);return!0},l.COMMAND_PRIORITY_EDITOR),a.registerCommand(l.PASTE_COMMAND,c=>{const d=l.$getSelection();return l.$isRangeSelection(d)||l.$isGridSelection(d)?(C(c,a),!0):!1},l.COMMAND_PRIORITY_EDITOR));B(a,e);return f}
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.3.
|
|
10
|
+
"version": "0.3.3",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.3.
|
|
14
|
-
"@lexical/selection": "0.3.
|
|
15
|
-
"@lexical/clipboard": "0.3.
|
|
16
|
-
"@lexical/utils": "0.3.
|
|
13
|
+
"lexical": "0.3.3",
|
|
14
|
+
"@lexical/selection": "0.3.3",
|
|
15
|
+
"@lexical/clipboard": "0.3.3",
|
|
16
|
+
"@lexical/utils": "0.3.3"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|