@lexical/rich-text 0.5.0 → 0.5.1-next.1
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.dev.js +21 -44
- package/LexicalRichText.prod.js +21 -21
- package/package.json +5 -5
package/LexicalRichText.dev.js
CHANGED
|
@@ -19,6 +19,14 @@ var lexical = require('lexical');
|
|
|
19
19
|
*
|
|
20
20
|
*/
|
|
21
21
|
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
25
|
+
*
|
|
26
|
+
* This source code is licensed under the MIT license found in the
|
|
27
|
+
* LICENSE file in the root directory of this source tree.
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
22
30
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
23
31
|
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
24
32
|
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
@@ -290,52 +298,21 @@ function onPasteForRichText(event, editor) {
|
|
|
290
298
|
});
|
|
291
299
|
}
|
|
292
300
|
|
|
293
|
-
function
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (selection !== null) {
|
|
297
|
-
event.preventDefault();
|
|
298
|
-
const clipboardData = event instanceof KeyboardEvent ? null : event.clipboardData;
|
|
299
|
-
const htmlString = clipboard.$getHtmlContent(editor);
|
|
300
|
-
const lexicalString = clipboard.$getLexicalContent(editor);
|
|
301
|
-
|
|
302
|
-
if (clipboardData != null) {
|
|
303
|
-
if (htmlString !== null) {
|
|
304
|
-
clipboardData.setData('text/html', htmlString);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
if (lexicalString !== null) {
|
|
308
|
-
clipboardData.setData('application/x-lexical-editor', lexicalString);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const plainString = selection.getTextContent();
|
|
312
|
-
clipboardData.setData('text/plain', plainString);
|
|
313
|
-
} else {
|
|
314
|
-
const clipboard = navigator.clipboard;
|
|
315
|
-
|
|
316
|
-
if (clipboard != null) {
|
|
317
|
-
// Most browsers only support a single item in the clipboard at one time.
|
|
318
|
-
// So we optimize by only putting in HTML.
|
|
319
|
-
const data = [new ClipboardItem({
|
|
320
|
-
'text/html': new Blob([htmlString], {
|
|
321
|
-
type: 'text/html'
|
|
322
|
-
})
|
|
323
|
-
})];
|
|
324
|
-
clipboard.write(data);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
301
|
+
async function onCutForRichText(event, editor) {
|
|
302
|
+
if (editor.getEditorState().read(() => lexical.$getSelection()) == null) {
|
|
303
|
+
return;
|
|
327
304
|
}
|
|
328
|
-
}
|
|
329
305
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
306
|
+
await clipboard.copyToClipboard__EXPERIMENTAL(editor, event instanceof ClipboardEvent ? event : null);
|
|
307
|
+
editor.update(() => {
|
|
308
|
+
const selection = lexical.$getSelection();
|
|
333
309
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
310
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
311
|
+
selection.removeText();
|
|
312
|
+
} else if (lexical.$isNodeSelection(selection)) {
|
|
313
|
+
selection.getNodes().forEach(node => node.remove());
|
|
314
|
+
}
|
|
315
|
+
});
|
|
339
316
|
}
|
|
340
317
|
|
|
341
318
|
function handleIndentAndOutdent(insertTab, indentOrOutdent) {
|
|
@@ -705,7 +682,7 @@ function registerRichText(editor) {
|
|
|
705
682
|
event.preventDefault();
|
|
706
683
|
return true;
|
|
707
684
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.COPY_COMMAND, event => {
|
|
708
|
-
|
|
685
|
+
clipboard.copyToClipboard__EXPERIMENTAL(editor, event instanceof ClipboardEvent ? event : null);
|
|
709
686
|
return true;
|
|
710
687
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.CUT_COMMAND, event => {
|
|
711
688
|
onCutForRichText(event, editor);
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -4,25 +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 a=require("@lexical/clipboard"),f=require("@lexical/selection"),g=require("@lexical/utils"),h=require("lexical");let l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,m=l&&"documentMode"in document?document.documentMode:null;l&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);l&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
8
8
|
let n=l&&"InputEvent"in window&&!m?"getTargetRanges"in new window.InputEvent("input"):!1,p=l&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),q=l&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream;
|
|
9
|
-
class r extends h.ElementNode{static getType(){return"quote"}static clone(
|
|
10
|
-
h.$createParagraphNode(),
|
|
11
|
-
class x extends h.ElementNode{static getType(){return"heading"}static clone(
|
|
12
|
-
priority:0}),h6:()=>({conversion:y,priority:0}),p:
|
|
13
|
-
return
|
|
14
|
-
function B(
|
|
15
|
-
function C(
|
|
16
|
-
function D(
|
|
17
|
-
exports.$
|
|
18
|
-
exports.registerRichText=function(
|
|
19
|
-
|
|
20
|
-
(
|
|
21
|
-
d=d.getNodes();for(const e of d)g.$getNearestBlockElementAncestorOrThrow(e).setFormat(
|
|
22
|
-
()=>{
|
|
23
|
-
!
|
|
24
|
-
!0)?(e=
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if(!h.$isRangeSelection(d))return!1;
|
|
9
|
+
class r extends h.ElementNode{static getType(){return"quote"}static clone(c){return new r(c.__key)}constructor(c){super(c)}createDOM(c){let b=document.createElement("blockquote");g.addClassNamesToElement(b,c.theme.quote);return b}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:t,priority:0})}}static importJSON(c){let b=w();b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(){let c=
|
|
10
|
+
h.$createParagraphNode(),b=this.getDirection();c.setDirection(b);this.insertAfter(c);return c}collapseAtStart(){let c=h.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}}function w(){return new r}
|
|
11
|
+
class x extends h.ElementNode{static getType(){return"heading"}static clone(c){return new x(c.__tag,c.__key)}constructor(c,b){super(b);this.__tag=c}getTag(){return this.__tag}createDOM(c){let b=this.__tag,d=document.createElement(b);c=c.theme.heading;void 0!==c&&g.addClassNamesToElement(d,c[b]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:y,priority:0}),h2:()=>({conversion:y,priority:0}),h3:()=>({conversion:y,priority:0}),h4:()=>({conversion:y,priority:0}),h5:()=>({conversion:y,
|
|
12
|
+
priority:0}),h6:()=>({conversion:y,priority:0}),p:c=>{c=c.firstChild;return null!==c&&z(c)?{conversion:()=>({node:null}),priority:3}:null},span:c=>z(c)?{conversion:()=>({node:A("h1")}),priority:3}:null}}static importJSON(c){let b=A(c.tag);b.setFormat(c.format);b.setIndent(c.indent);b.setDirection(c.direction);return b}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(){let c=h.$createParagraphNode(),b=this.getDirection();c.setDirection(b);this.insertAfter(c);
|
|
13
|
+
return c}collapseAtStart(){let c=h.$createParagraphNode();this.getChildren().forEach(b=>c.append(b));this.replace(c);return!0}extractWithChild(){return!0}}function z(c){return"span"===c.nodeName.toLowerCase()?"26pt"===c.style.fontSize:!1}function y(c){c=c.nodeName.toLowerCase();let b=null;if("h1"===c||"h2"===c||"h3"===c||"h4"===c||"h5"===c||"h6"===c)b=A(c);return{node:b}}function t(){return{node:w()}}function A(c){return new x(c)}
|
|
14
|
+
function B(c,b){c.preventDefault();b.update(()=>{let d=h.$getSelection(),e=c instanceof InputEvent||c instanceof KeyboardEvent?null:c.clipboardData;null!=e&&(h.$isRangeSelection(d)||h.DEPRECATED_$isGridSelection(d))&&a.$insertDataTransferForRichText(e,d,b)},{tag:"paste"})}
|
|
15
|
+
async function C(c,b){null!=b.getEditorState().read(()=>h.$getSelection())&&(await a.copyToClipboard__EXPERIMENTAL(b,c instanceof ClipboardEvent?c:null),b.update(()=>{let d=h.$getSelection();h.$isRangeSelection(d)?d.removeText():h.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())}))}
|
|
16
|
+
function D(c,b){var d=h.$getSelection();if(h.$isRangeSelection(d)){var e=new Set;d=d.getNodes();for(let u=0;u<d.length;u++){let v=d[u];var k=v.getKey();e.has(k)||(e.add(k),k=g.$getNearestBlockElementAncestorOrThrow(v),k.canInsertTab()?c(v):k.canIndent()&&b(k))}}}function E(c){c=h.$getNearestNodeFromDOMNode(c);return h.$isDecoratorNode(c)}exports.$createHeadingNode=A;exports.$createQuoteNode=w;exports.$isHeadingNode=function(c){return c instanceof x};
|
|
17
|
+
exports.$isQuoteNode=function(c){return c instanceof r};exports.HeadingNode=x;exports.QuoteNode=r;
|
|
18
|
+
exports.registerRichText=function(c){return g.mergeRegister(c.registerCommand(h.CLICK_COMMAND,()=>{const b=h.$getSelection();return h.$isNodeSelection(b)?(b.clear(),!0):!1},0),c.registerCommand(h.DELETE_CHARACTER_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteCharacter(b);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.DELETE_WORD_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteWord(b);return!0},h.COMMAND_PRIORITY_EDITOR),
|
|
19
|
+
c.registerCommand(h.DELETE_LINE_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.deleteLine(b);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.CONTROLLED_TEXT_INSERTION_COMMAND,b=>{const d=h.$getSelection();if("string"===typeof b)h.$isRangeSelection(d)?d.insertText(b):h.DEPRECATED_$isGridSelection(d);else{if(!h.$isRangeSelection(d)&&!h.DEPRECATED_$isGridSelection(d))return!1;const e=b.dataTransfer;null!=e?a.$insertDataTransferForRichText(e,d,c):h.$isRangeSelection(d)&&
|
|
20
|
+
(b=b.data)&&d.insertText(b)}return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.REMOVE_TEXT_COMMAND,()=>{const b=h.$getSelection();if(!h.$isRangeSelection(b))return!1;b.removeText();return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.FORMAT_TEXT_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.formatText(b);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.FORMAT_ELEMENT_COMMAND,b=>{var d=h.$getSelection();if(!h.$isRangeSelection(d)&&!h.$isNodeSelection(d))return!1;
|
|
21
|
+
d=d.getNodes();for(const e of d)g.$getNearestBlockElementAncestorOrThrow(e).setFormat(b);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.INSERT_LINE_BREAK_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;d.insertLineBreak(b);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.INSERT_PARAGRAPH_COMMAND,()=>{const b=h.$getSelection();if(!h.$isRangeSelection(b))return!1;b.insertParagraph();return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.INDENT_CONTENT_COMMAND,
|
|
22
|
+
()=>{D(()=>{c.dispatchCommand(h.CONTROLLED_TEXT_INSERTION_COMMAND,"\t")},b=>{const d=b.getIndent();10!==d&&b.setIndent(d+1)});return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.OUTDENT_CONTENT_COMMAND,()=>{D(b=>{h.$isTextNode(b)&&(b=b.getTextContent(),"\t"===b[b.length-1]&&c.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!0))},b=>{const d=b.getIndent();0!==d&&b.setIndent(d-1)});return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ARROW_UP_COMMAND,b=>{const d=h.$getSelection();return h.$isNodeSelection(d)&&
|
|
23
|
+
!E(b.target)&&(b=d.getNodes(),0<b.length)?(b[0].selectPrevious(),!0):!1},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ARROW_DOWN_COMMAND,()=>{var b=h.$getSelection();return h.$isNodeSelection(b)&&(b=b.getNodes(),0<b.length)?(b[0].selectNext(0,0),!0):!1},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ARROW_LEFT_COMMAND,b=>{const d=h.$getSelection();if(h.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectPrevious(),!0}return h.$isRangeSelection(d)?f.$shouldOverrideDefaultCharacterSelection(d,
|
|
24
|
+
!0)?(e=b.shiftKey,b.preventDefault(),f.$moveCharacter(d,e,!0),!0):!1:!1},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ARROW_RIGHT_COMMAND,b=>{const d=h.$getSelection();if(h.$isNodeSelection(d)&&!E(b.target)){var e=d.getNodes();if(0<e.length)return b.preventDefault(),e[0].selectNext(0,0),!0}if(!h.$isRangeSelection(d))return!1;e=b.shiftKey;return f.$shouldOverrideDefaultCharacterSelection(d,!1)?(b.preventDefault(),f.$moveCharacter(d,e,!1),!0):!1},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_BACKSPACE_COMMAND,
|
|
25
|
+
b=>{if(E(b.target))return!1;const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;b.preventDefault();({anchor:b}=d);const e=b.getNode();return d.isCollapsed()&&0===b.offset&&!h.$isRootNode(e)&&0<g.$getNearestBlockElementAncestorOrThrow(e).getIndent()?c.dispatchCommand(h.OUTDENT_CONTENT_COMMAND,void 0):c.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!0)},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_DELETE_COMMAND,b=>{if(E(b.target))return!1;const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;
|
|
26
|
+
b.preventDefault();return c.dispatchCommand(h.DELETE_CHARACTER_COMMAND,!1)},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ENTER_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;if(null!==b){if((q||p)&&n)return!1;b.preventDefault();if(b.shiftKey)return c.dispatchCommand(h.INSERT_LINE_BREAK_COMMAND,!1)}return c.dispatchCommand(h.INSERT_PARAGRAPH_COMMAND,void 0)},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_TAB_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;
|
|
27
|
+
b.preventDefault();return c.dispatchCommand(b.shiftKey?h.OUTDENT_CONTENT_COMMAND:h.INDENT_CONTENT_COMMAND,void 0)},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.KEY_ESCAPE_COMMAND,()=>{const b=h.$getSelection();if(!h.$isRangeSelection(b))return!1;c.blur();return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.DROP_COMMAND,b=>{const d=h.$getSelection();if(!h.$isRangeSelection(d))return!1;b.preventDefault();return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.DRAGSTART_COMMAND,b=>{const d=h.$getSelection();
|
|
28
|
+
if(!h.$isRangeSelection(d))return!1;b.preventDefault();return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.COPY_COMMAND,b=>{a.copyToClipboard__EXPERIMENTAL(c,b instanceof ClipboardEvent?b:null);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.CUT_COMMAND,b=>{C(b,c);return!0},h.COMMAND_PRIORITY_EDITOR),c.registerCommand(h.PASTE_COMMAND,b=>{const d=h.$getSelection();return h.$isRangeSelection(d)||h.DEPRECATED_$isGridSelection(d)?(B(b,c),!0):!1},h.COMMAND_PRIORITY_EDITOR))}
|
package/package.json
CHANGED
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.5.
|
|
10
|
+
"version": "0.5.1-next.1",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.5.
|
|
14
|
-
"@lexical/selection": "0.5.
|
|
15
|
-
"@lexical/clipboard": "0.5.
|
|
16
|
-
"@lexical/utils": "0.5.
|
|
13
|
+
"lexical": "0.5.1-next.1",
|
|
14
|
+
"@lexical/selection": "0.5.1-next.1",
|
|
15
|
+
"@lexical/clipboard": "0.5.1-next.1",
|
|
16
|
+
"@lexical/utils": "0.5.1-next.1"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|