@lexical/rich-text 0.14.4 → 0.15.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.dev.js +20 -19
- package/LexicalRichText.dev.mjs +21 -20
- package/LexicalRichText.js +2 -0
- package/LexicalRichText.mjs +2 -0
- package/LexicalRichText.node.mjs +2 -0
- package/LexicalRichText.prod.js +7 -5
- package/LexicalRichText.prod.mjs +3 -1
- package/package.json +5 -5
package/LexicalRichText.dev.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';
|
|
8
10
|
|
|
9
11
|
var clipboard = require('@lexical/clipboard');
|
|
@@ -63,20 +65,15 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
63
65
|
* LICENSE file in the root directory of this source tree.
|
|
64
66
|
*
|
|
65
67
|
*/
|
|
68
|
+
|
|
66
69
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
67
|
-
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
68
|
-
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
69
70
|
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
70
71
|
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
71
72
|
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
72
|
-
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
73
73
|
|
|
74
74
|
// Keep these in case we need to use them in the future.
|
|
75
75
|
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
76
76
|
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
77
|
-
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
78
|
-
|
|
79
|
-
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
80
77
|
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
81
78
|
|
|
82
79
|
/**
|
|
@@ -86,6 +83,7 @@ const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.user
|
|
|
86
83
|
* LICENSE file in the root directory of this source tree.
|
|
87
84
|
*
|
|
88
85
|
*/
|
|
86
|
+
|
|
89
87
|
const DRAG_DROP_PASTE = lexical.createCommand('DRAG_DROP_PASTE_FILE');
|
|
90
88
|
/** @noInheritDoc */
|
|
91
89
|
class QuoteNode extends lexical.ElementNode {
|
|
@@ -112,7 +110,7 @@ class QuoteNode extends lexical.ElementNode {
|
|
|
112
110
|
static importDOM() {
|
|
113
111
|
return {
|
|
114
112
|
blockquote: node => ({
|
|
115
|
-
conversion: convertBlockquoteElement,
|
|
113
|
+
conversion: $convertBlockquoteElement,
|
|
116
114
|
priority: 0
|
|
117
115
|
})
|
|
118
116
|
};
|
|
@@ -210,27 +208,27 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
210
208
|
static importDOM() {
|
|
211
209
|
return {
|
|
212
210
|
h1: node => ({
|
|
213
|
-
conversion: convertHeadingElement,
|
|
211
|
+
conversion: $convertHeadingElement,
|
|
214
212
|
priority: 0
|
|
215
213
|
}),
|
|
216
214
|
h2: node => ({
|
|
217
|
-
conversion: convertHeadingElement,
|
|
215
|
+
conversion: $convertHeadingElement,
|
|
218
216
|
priority: 0
|
|
219
217
|
}),
|
|
220
218
|
h3: node => ({
|
|
221
|
-
conversion: convertHeadingElement,
|
|
219
|
+
conversion: $convertHeadingElement,
|
|
222
220
|
priority: 0
|
|
223
221
|
}),
|
|
224
222
|
h4: node => ({
|
|
225
|
-
conversion: convertHeadingElement,
|
|
223
|
+
conversion: $convertHeadingElement,
|
|
226
224
|
priority: 0
|
|
227
225
|
}),
|
|
228
226
|
h5: node => ({
|
|
229
|
-
conversion: convertHeadingElement,
|
|
227
|
+
conversion: $convertHeadingElement,
|
|
230
228
|
priority: 0
|
|
231
229
|
}),
|
|
232
230
|
h6: node => ({
|
|
233
|
-
conversion: convertHeadingElement,
|
|
231
|
+
conversion: $convertHeadingElement,
|
|
234
232
|
priority: 0
|
|
235
233
|
}),
|
|
236
234
|
p: node => {
|
|
@@ -328,7 +326,7 @@ function isGoogleDocsTitle(domNode) {
|
|
|
328
326
|
}
|
|
329
327
|
return false;
|
|
330
328
|
}
|
|
331
|
-
function convertHeadingElement(element) {
|
|
329
|
+
function $convertHeadingElement(element) {
|
|
332
330
|
const nodeName = element.nodeName.toLowerCase();
|
|
333
331
|
let node = null;
|
|
334
332
|
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
|
|
@@ -341,7 +339,7 @@ function convertHeadingElement(element) {
|
|
|
341
339
|
node
|
|
342
340
|
};
|
|
343
341
|
}
|
|
344
|
-
function convertBlockquoteElement(element) {
|
|
342
|
+
function $convertBlockquoteElement(element) {
|
|
345
343
|
const node = $createQuoteNode();
|
|
346
344
|
if (element.style !== null) {
|
|
347
345
|
node.setFormat(element.style.textAlign);
|
|
@@ -398,7 +396,7 @@ function eventFiles(event) {
|
|
|
398
396
|
const hasContent = types.includes('text/html') || types.includes('text/plain');
|
|
399
397
|
return [hasFiles, Array.from(dataTransfer.files), hasContent];
|
|
400
398
|
}
|
|
401
|
-
function handleIndentAndOutdent(indentOrOutdent) {
|
|
399
|
+
function $handleIndentAndOutdent(indentOrOutdent) {
|
|
402
400
|
const selection = lexical.$getSelection();
|
|
403
401
|
if (!lexical.$isRangeSelection(selection)) {
|
|
404
402
|
return false;
|
|
@@ -411,7 +409,10 @@ function handleIndentAndOutdent(indentOrOutdent) {
|
|
|
411
409
|
if (alreadyHandled.has(key)) {
|
|
412
410
|
continue;
|
|
413
411
|
}
|
|
414
|
-
const parentBlock = utils.$
|
|
412
|
+
const parentBlock = utils.$findMatchingParent(node, parentNode => lexical.$isElementNode(parentNode) && !parentNode.isInline());
|
|
413
|
+
if (parentBlock === null) {
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
415
416
|
const parentKey = parentBlock.getKey();
|
|
416
417
|
if (parentBlock.canIndent() && !alreadyHandled.has(parentKey)) {
|
|
417
418
|
alreadyHandled.add(parentKey);
|
|
@@ -524,12 +525,12 @@ function registerRichText(editor) {
|
|
|
524
525
|
lexical.$insertNodes([lexical.$createTabNode()]);
|
|
525
526
|
return true;
|
|
526
527
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
|
|
527
|
-
return handleIndentAndOutdent(block => {
|
|
528
|
+
return $handleIndentAndOutdent(block => {
|
|
528
529
|
const indent = block.getIndent();
|
|
529
530
|
block.setIndent(indent + 1);
|
|
530
531
|
});
|
|
531
532
|
}, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
|
|
532
|
-
return handleIndentAndOutdent(block => {
|
|
533
|
+
return $handleIndentAndOutdent(block => {
|
|
533
534
|
const indent = block.getIndent();
|
|
534
535
|
if (indent > 0) {
|
|
535
536
|
block.setIndent(indent - 1);
|
package/LexicalRichText.dev.mjs
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import { $insertDataTransferForRichText, copyToClipboard } from '@lexical/clipboard';
|
|
8
10
|
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '@lexical/selection';
|
|
9
11
|
import { addClassNamesToElement, isHTMLElement, objectKlassEquals, mergeRegister, $findMatchingParent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
10
|
-
import { createCommand, ElementNode, $
|
|
12
|
+
import { createCommand, ElementNode, $createParagraphNode, $applyNodeReplacement, CLICK_COMMAND, $getSelection, $isNodeSelection, DELETE_CHARACTER_COMMAND, $isRangeSelection, COMMAND_PRIORITY_EDITOR, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, REMOVE_TEXT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, $isElementNode, INSERT_LINE_BREAK_COMMAND, INSERT_PARAGRAPH_COMMAND, INSERT_TAB_COMMAND, $insertNodes, $createTabNode, INDENT_CONTENT_COMMAND, OUTDENT_CONTENT_COMMAND, KEY_ARROW_UP_COMMAND, $getAdjacentNode, $isDecoratorNode, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_BACKSPACE_COMMAND, $isRootNode, KEY_DELETE_COMMAND, KEY_ENTER_COMMAND, KEY_ESCAPE_COMMAND, DROP_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $isTextNode, $normalizeSelection__EXPERIMENTAL, $setSelection, DRAGSTART_COMMAND, DRAGOVER_COMMAND, SELECT_ALL_COMMAND, $selectAll, COPY_COMMAND, CUT_COMMAND, PASTE_COMMAND, isSelectionCapturedInDecoratorInput, $getRoot } from 'lexical';
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -61,20 +63,15 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
|
|
|
61
63
|
* LICENSE file in the root directory of this source tree.
|
|
62
64
|
*
|
|
63
65
|
*/
|
|
66
|
+
|
|
64
67
|
const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.documentMode : null;
|
|
65
|
-
CAN_USE_DOM && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
66
|
-
CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
67
68
|
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
68
69
|
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
69
70
|
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
70
|
-
const IS_ANDROID = CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
71
71
|
|
|
72
72
|
// Keep these in case we need to use them in the future.
|
|
73
73
|
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
74
74
|
const IS_CHROME = CAN_USE_DOM && /^(?=.*Chrome).*/i.test(navigator.userAgent);
|
|
75
|
-
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
76
|
-
|
|
77
|
-
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
78
75
|
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
79
76
|
|
|
80
77
|
/**
|
|
@@ -84,6 +81,7 @@ const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.user
|
|
|
84
81
|
* LICENSE file in the root directory of this source tree.
|
|
85
82
|
*
|
|
86
83
|
*/
|
|
84
|
+
|
|
87
85
|
const DRAG_DROP_PASTE = createCommand('DRAG_DROP_PASTE_FILE');
|
|
88
86
|
/** @noInheritDoc */
|
|
89
87
|
class QuoteNode extends ElementNode {
|
|
@@ -110,7 +108,7 @@ class QuoteNode extends ElementNode {
|
|
|
110
108
|
static importDOM() {
|
|
111
109
|
return {
|
|
112
110
|
blockquote: node => ({
|
|
113
|
-
conversion: convertBlockquoteElement,
|
|
111
|
+
conversion: $convertBlockquoteElement,
|
|
114
112
|
priority: 0
|
|
115
113
|
})
|
|
116
114
|
};
|
|
@@ -208,27 +206,27 @@ class HeadingNode extends ElementNode {
|
|
|
208
206
|
static importDOM() {
|
|
209
207
|
return {
|
|
210
208
|
h1: node => ({
|
|
211
|
-
conversion: convertHeadingElement,
|
|
209
|
+
conversion: $convertHeadingElement,
|
|
212
210
|
priority: 0
|
|
213
211
|
}),
|
|
214
212
|
h2: node => ({
|
|
215
|
-
conversion: convertHeadingElement,
|
|
213
|
+
conversion: $convertHeadingElement,
|
|
216
214
|
priority: 0
|
|
217
215
|
}),
|
|
218
216
|
h3: node => ({
|
|
219
|
-
conversion: convertHeadingElement,
|
|
217
|
+
conversion: $convertHeadingElement,
|
|
220
218
|
priority: 0
|
|
221
219
|
}),
|
|
222
220
|
h4: node => ({
|
|
223
|
-
conversion: convertHeadingElement,
|
|
221
|
+
conversion: $convertHeadingElement,
|
|
224
222
|
priority: 0
|
|
225
223
|
}),
|
|
226
224
|
h5: node => ({
|
|
227
|
-
conversion: convertHeadingElement,
|
|
225
|
+
conversion: $convertHeadingElement,
|
|
228
226
|
priority: 0
|
|
229
227
|
}),
|
|
230
228
|
h6: node => ({
|
|
231
|
-
conversion: convertHeadingElement,
|
|
229
|
+
conversion: $convertHeadingElement,
|
|
232
230
|
priority: 0
|
|
233
231
|
}),
|
|
234
232
|
p: node => {
|
|
@@ -326,7 +324,7 @@ function isGoogleDocsTitle(domNode) {
|
|
|
326
324
|
}
|
|
327
325
|
return false;
|
|
328
326
|
}
|
|
329
|
-
function convertHeadingElement(element) {
|
|
327
|
+
function $convertHeadingElement(element) {
|
|
330
328
|
const nodeName = element.nodeName.toLowerCase();
|
|
331
329
|
let node = null;
|
|
332
330
|
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
|
|
@@ -339,7 +337,7 @@ function convertHeadingElement(element) {
|
|
|
339
337
|
node
|
|
340
338
|
};
|
|
341
339
|
}
|
|
342
|
-
function convertBlockquoteElement(element) {
|
|
340
|
+
function $convertBlockquoteElement(element) {
|
|
343
341
|
const node = $createQuoteNode();
|
|
344
342
|
if (element.style !== null) {
|
|
345
343
|
node.setFormat(element.style.textAlign);
|
|
@@ -396,7 +394,7 @@ function eventFiles(event) {
|
|
|
396
394
|
const hasContent = types.includes('text/html') || types.includes('text/plain');
|
|
397
395
|
return [hasFiles, Array.from(dataTransfer.files), hasContent];
|
|
398
396
|
}
|
|
399
|
-
function handleIndentAndOutdent(indentOrOutdent) {
|
|
397
|
+
function $handleIndentAndOutdent(indentOrOutdent) {
|
|
400
398
|
const selection = $getSelection();
|
|
401
399
|
if (!$isRangeSelection(selection)) {
|
|
402
400
|
return false;
|
|
@@ -409,7 +407,10 @@ function handleIndentAndOutdent(indentOrOutdent) {
|
|
|
409
407
|
if (alreadyHandled.has(key)) {
|
|
410
408
|
continue;
|
|
411
409
|
}
|
|
412
|
-
const parentBlock = $
|
|
410
|
+
const parentBlock = $findMatchingParent(node, parentNode => $isElementNode(parentNode) && !parentNode.isInline());
|
|
411
|
+
if (parentBlock === null) {
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
413
414
|
const parentKey = parentBlock.getKey();
|
|
414
415
|
if (parentBlock.canIndent() && !alreadyHandled.has(parentKey)) {
|
|
415
416
|
alreadyHandled.add(parentKey);
|
|
@@ -522,12 +523,12 @@ function registerRichText(editor) {
|
|
|
522
523
|
$insertNodes([$createTabNode()]);
|
|
523
524
|
return true;
|
|
524
525
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INDENT_CONTENT_COMMAND, () => {
|
|
525
|
-
return handleIndentAndOutdent(block => {
|
|
526
|
+
return $handleIndentAndOutdent(block => {
|
|
526
527
|
const indent = block.getIndent();
|
|
527
528
|
block.setIndent(indent + 1);
|
|
528
529
|
});
|
|
529
530
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(OUTDENT_CONTENT_COMMAND, () => {
|
|
530
|
-
return handleIndentAndOutdent(block => {
|
|
531
|
+
return $handleIndentAndOutdent(block => {
|
|
531
532
|
const indent = block.getIndent();
|
|
532
533
|
if (indent > 0) {
|
|
533
534
|
block.setIndent(indent - 1);
|
package/LexicalRichText.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict'
|
|
8
10
|
const LexicalRichText = process.env.NODE_ENV === 'development' ? require('./LexicalRichText.dev.js') : require('./LexicalRichText.prod.js');
|
|
9
11
|
module.exports = LexicalRichText;
|
package/LexicalRichText.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
import * as modDev from './LexicalRichText.dev.mjs';
|
|
8
10
|
import * as modProd from './LexicalRichText.prod.mjs';
|
|
9
11
|
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
package/LexicalRichText.node.mjs
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalRichText.dev.mjs') : import('./LexicalRichText.prod.mjs'));
|
|
8
10
|
export const $createHeadingNode = mod.$createHeadingNode;
|
|
9
11
|
export const $createQuoteNode = mod.$createQuoteNode;
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
8
|
+
|
|
7
9
|
'use strict';var c=require("@lexical/clipboard"),g=require("@lexical/selection"),h=require("@lexical/utils"),k=require("lexical");function l(b,a){return"undefined"!==typeof document.caretRangeFromPoint?(b=document.caretRangeFromPoint(b,a),null===b?null:{node:b.startContainer,offset:b.startOffset}):"undefined"!==document.caretPositionFromPoint?(b=document.caretPositionFromPoint(b,a),null===b?null:{node:b.offsetNode,offset:b.offset}):null}
|
|
8
|
-
let n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,p=n&&"documentMode"in document?document.documentMode:null
|
|
9
|
-
|
|
10
|
+
let n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,p=n&&"documentMode"in document?document.documentMode:null,q=n&&"InputEvent"in window&&!p?"getTargetRanges"in new window.InputEvent("input"):!1,r=n&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),t=n&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,v=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent),w=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!v,x=
|
|
11
|
+
k.createCommand("DRAG_DROP_PASTE_FILE");
|
|
10
12
|
class y extends k.ElementNode{static getType(){return"quote"}static clone(b){return new y(b.__key)}constructor(b){super(b)}createDOM(b){let a=document.createElement("blockquote");h.addClassNamesToElement(a,b.theme.quote);return a}updateDOM(){return!1}static importDOM(){return{blockquote:()=>({conversion:z,priority:0})}}exportDOM(b){({element:b}=super.exportDOM(b));if(b&&h.isHTMLElement(b)){this.isEmpty()&&b.append(document.createElement("br"));var a=this.getFormatType();b.style.textAlign=a;if(a=this.getDirection())b.dir=
|
|
11
13
|
a}return{element:b}}static importJSON(b){let a=A();a.setFormat(b.format);a.setIndent(b.indent);a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(b,a){b=k.$createParagraphNode();let d=this.getDirection();b.setDirection(d);this.insertAfter(b,a);return b}collapseAtStart(){let b=k.$createParagraphNode();this.getChildren().forEach(a=>b.append(a));this.replace(b);return!0}}function A(){return k.$applyNodeReplacement(new y)}
|
|
12
14
|
class C extends k.ElementNode{static getType(){return"heading"}static clone(b){return new C(b.__tag,b.__key)}constructor(b,a){super(a);this.__tag=b}getTag(){return this.__tag}createDOM(b){let a=this.__tag,d=document.createElement(a);b=b.theme.heading;void 0!==b&&h.addClassNamesToElement(d,b[a]);return d}updateDOM(){return!1}static importDOM(){return{h1:()=>({conversion:D,priority:0}),h2:()=>({conversion:D,priority:0}),h3:()=>({conversion:D,priority:0}),h4:()=>({conversion:D,priority:0}),h5:()=>({conversion:D,
|
|
@@ -15,8 +17,8 @@ a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),t
|
|
|
15
17
|
b.append(a));this.replace(b);return!0}extractWithChild(){return!0}}function E(b){return"span"===b.nodeName.toLowerCase()?"26pt"===b.style.fontSize:!1}function D(b){let a=b.nodeName.toLowerCase(),d=null;if("h1"===a||"h2"===a||"h3"===a||"h4"===a||"h5"===a||"h6"===a)d=F(a),null!==b.style&&d.setFormat(b.style.textAlign);return{node:d}}function z(b){let a=A();null!==b.style&&a.setFormat(b.style.textAlign);return{node:a}}function F(b){return k.$applyNodeReplacement(new C(b))}
|
|
16
18
|
function G(b,a){b.preventDefault();a.update(()=>{let d=k.$getSelection(),e=h.objectKlassEquals(b,InputEvent)||h.objectKlassEquals(b,KeyboardEvent)?null:b.clipboardData;null!=e&&null!==d&&c.$insertDataTransferForRichText(e,d,a)},{tag:"paste"})}async function H(b,a){await c.copyToClipboard(a,h.objectKlassEquals(b,ClipboardEvent)?b:null);a.update(()=>{let d=k.$getSelection();k.$isRangeSelection(d)?d.removeText():k.$isNodeSelection(d)&&d.getNodes().forEach(e=>e.remove())})}
|
|
17
19
|
function I(b){let a=null;h.objectKlassEquals(b,DragEvent)?a=b.dataTransfer:h.objectKlassEquals(b,ClipboardEvent)&&(a=b.clipboardData);if(null===a)return[!1,[],!1];var d=a.types;b=d.includes("Files");d=d.includes("text/html")||d.includes("text/plain");return[b,Array.from(a.files),d]}
|
|
18
|
-
function J(b){var a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;let d=new Set;a=a.getNodes();for(let m=0;m<a.length;m++){var e=a[m],f=e.getKey();d.has(f)||(e=h.$
|
|
19
|
-
exports.$isQuoteNode=function(b){return b instanceof y};exports.DRAG_DROP_PASTE=x;exports.HeadingNode=C;exports.QuoteNode=y;exports.eventFiles=I;
|
|
20
|
+
function J(b){var a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;let d=new Set;a=a.getNodes();for(let m=0;m<a.length;m++){var e=a[m],f=e.getKey();d.has(f)||(e=h.$findMatchingParent(e,u=>k.$isElementNode(u)&&!u.isInline()),null!==e&&(f=e.getKey(),e.canIndent()&&!d.has(f)&&(d.add(f),b(e))))}return 0<d.size}function K(b){b=k.$getNearestNodeFromDOMNode(b);return k.$isDecoratorNode(b)}exports.$createHeadingNode=F;exports.$createQuoteNode=A;
|
|
21
|
+
exports.$isHeadingNode=function(b){return b instanceof C};exports.$isQuoteNode=function(b){return b instanceof y};exports.DRAG_DROP_PASTE=x;exports.HeadingNode=C;exports.QuoteNode=y;exports.eventFiles=I;
|
|
20
22
|
exports.registerRichText=function(b){return h.mergeRegister(b.registerCommand(k.CLICK_COMMAND,()=>{const a=k.$getSelection();return k.$isNodeSelection(a)?(a.clear(),!0):!1},0),b.registerCommand(k.DELETE_CHARACTER_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteCharacter(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DELETE_WORD_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteWord(a);return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
21
23
|
b.registerCommand(k.DELETE_LINE_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.deleteLine(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CONTROLLED_TEXT_INSERTION_COMMAND,a=>{const d=k.$getSelection();if("string"===typeof a)null!==d&&d.insertText(a);else{if(null===d)return!1;const e=a.dataTransfer;null!=e?c.$insertDataTransferForRichText(e,d,b):k.$isRangeSelection(d)&&(a=a.data)&&d.insertText(a)}return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.REMOVE_TEXT_COMMAND,
|
|
22
24
|
()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;a.removeText();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.FORMAT_TEXT_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.formatText(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.FORMAT_ELEMENT_COMMAND,a=>{var d=k.$getSelection();if(!k.$isRangeSelection(d)&&!k.$isNodeSelection(d))return!1;d=d.getNodes();for(const e of d)d=h.$findMatchingParent(e,f=>k.$isElementNode(f)&&!f.isInline()),
|
|
@@ -27,6 +29,6 @@ a.preventDefault(),!0}return!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.K
|
|
|
27
29
|
!K(a.target)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectNext(0,0),!0}if(!k.$isRangeSelection(d))return!1;e=a.shiftKey;return g.$shouldOverrideDefaultCharacterSelection(d,!1)?(a.preventDefault(),g.$moveCharacter(d,e,!1),!0):!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_BACKSPACE_COMMAND,a=>{if(K(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();({anchor:a}=d);const e=a.getNode();return d.isCollapsed()&&0===a.offset&&
|
|
28
30
|
!k.$isRootNode(e)&&0<h.$getNearestBlockElementAncestorOrThrow(e).getIndent()?b.dispatchCommand(k.OUTDENT_CONTENT_COMMAND,void 0):b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_DELETE_COMMAND,a=>{if(K(a.target))return!1;const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;a.preventDefault();return b.dispatchCommand(k.DELETE_CHARACTER_COMMAND,!1)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ENTER_COMMAND,a=>{const d=k.$getSelection();
|
|
29
31
|
if(!k.$isRangeSelection(d))return!1;if(null!==a){if((t||r||w)&&q)return!1;a.preventDefault();if(a.shiftKey)return b.dispatchCommand(k.INSERT_LINE_BREAK_COMMAND,!1)}return b.dispatchCommand(k.INSERT_PARAGRAPH_COMMAND,void 0)},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ESCAPE_COMMAND,()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;b.blur();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DROP_COMMAND,a=>{const [,d]=I(a);if(0<d.length){var e=l(a.clientX,a.clientY);
|
|
30
|
-
if(null!==e){const {offset:m,node:
|
|
32
|
+
if(null!==e){const {offset:m,node:u}=e;var f=k.$getNearestNodeFromDOMNode(u);if(null!==f){e=k.$createRangeSelection();if(k.$isTextNode(f))e.anchor.set(f.getKey(),m,"text"),e.focus.set(f.getKey(),m,"text");else{const B=f.getParentOrThrow().getKey();f=f.getIndexWithinParent()+1;e.anchor.set(B,f,"element");e.focus.set(B,f,"element")}e=k.$normalizeSelection__EXPERIMENTAL(e);k.$setSelection(e)}b.dispatchCommand(x,d)}a.preventDefault();return!0}a=k.$getSelection();return k.$isRangeSelection(a)?!0:!1},k.COMMAND_PRIORITY_EDITOR),
|
|
31
33
|
b.registerCommand(k.DRAGSTART_COMMAND,a=>{[a]=I(a);const d=k.$getSelection();return a&&!k.$isRangeSelection(d)?!1:!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.DRAGOVER_COMMAND,a=>{var [d]=I(a);const e=k.$getSelection();if(d&&!k.$isRangeSelection(e))return!1;d=l(a.clientX,a.clientY);null!==d&&(d=k.$getNearestNodeFromDOMNode(d.node),k.$isDecoratorNode(d)&&a.preventDefault());return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.SELECT_ALL_COMMAND,()=>{k.$selectAll();return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
32
34
|
b.registerCommand(k.COPY_COMMAND,a=>{c.copyToClipboard(b,h.objectKlassEquals(a,ClipboardEvent)?a:null);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.CUT_COMMAND,a=>{H(a,b);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.PASTE_COMMAND,a=>{const [,d,e]=I(a);return 0<d.length&&!e?(b.dispatchCommand(x,d),!0):k.isSelectionCapturedInDecoratorInput(a.target)?!1:null!==k.$getSelection()?(G(a,b),!0):!1},k.COMMAND_PRIORITY_EDITOR))}
|
package/LexicalRichText.prod.mjs
CHANGED
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
*
|
|
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
|
*/
|
|
7
|
-
import{$insertDataTransferForRichText as t,copyToClipboard as e}from"@lexical/clipboard";import{$shouldOverrideDefaultCharacterSelection as n,$moveCharacter as r}from"@lexical/selection";import{addClassNamesToElement as o,isHTMLElement as i,objectKlassEquals as s,mergeRegister as a,$findMatchingParent as c,$getNearestBlockElementAncestorOrThrow as u}from"@lexical/utils";import{createCommand as l,ElementNode as d,$applyNodeReplacement as m,$createParagraphNode as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as v,$isRangeSelection as C,COMMAND_PRIORITY_EDITOR as y,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as x,CONTROLLED_TEXT_INSERTION_COMMAND as w,REMOVE_TEXT_COMMAND as E,FORMAT_TEXT_COMMAND as N,FORMAT_ELEMENT_COMMAND as A,$isElementNode as P,INSERT_LINE_BREAK_COMMAND as O,INSERT_PARAGRAPH_COMMAND as T,INSERT_TAB_COMMAND as I,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as F,OUTDENT_CONTENT_COMMAND as M,KEY_ARROW_UP_COMMAND as b,$isDecoratorNode as K,$getAdjacentNode as k,KEY_ARROW_DOWN_COMMAND as J,$getRoot as q,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as R,KEY_BACKSPACE_COMMAND as z,$isRootNode as W,KEY_DELETE_COMMAND as X,KEY_ENTER_COMMAND as Y,KEY_ESCAPE_COMMAND as B,DROP_COMMAND as G,$getNearestNodeFromDOMNode as V,$createRangeSelection as j,$isTextNode as H,$normalizeSelection__EXPERIMENTAL as Q,$setSelection as U,DRAGSTART_COMMAND as Z,DRAGOVER_COMMAND as $,SELECT_ALL_COMMAND as tt,$selectAll as et,COPY_COMMAND as nt,CUT_COMMAND as rt,PASTE_COMMAND as ot,isSelectionCapturedInDecoratorInput as it}from"lexical";function st(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const at="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ct=at&&"documentMode"in document?document.documentMode:null;at&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),at&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);const ut=!(!at||!("InputEvent"in window)||ct)&&"getTargetRanges"in new window.InputEvent("input"),lt=at&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),dt=at&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,mt=(at&&/Android/.test(navigator.userAgent),at&&/^(?=.*Chrome).*/i.test(navigator.userAgent)),ft=at&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!mt,gt=l("DRAG_DROP_PASTE_FILE");class pt extends d{static getType(){return"quote"}static clone(t){return new pt(t.__key)}constructor(t){super(t)}createDOM(t){const e=document.createElement("blockquote");return o(e,t.theme.quote),e}updateDOM(t,e){return!1}static importDOM(){return{blockquote:t=>({conversion:xt,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=ht();return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(t,e){const n=f(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=f();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return m(new pt)}function vt(t){return t instanceof pt}class Ct extends d{static getType(){return"heading"}static clone(t){return new Ct(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t}getTag(){return this.__tag}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];o(n,t)}return n}updateDOM(t,e){return!1}static importDOM(){return{h1:t=>({conversion:Dt,priority:0}),h2:t=>({conversion:Dt,priority:0}),h3:t=>({conversion:Dt,priority:0}),h4:t=>({conversion:Dt,priority:0}),h5:t=>({conversion:Dt,priority:0}),h6:t=>({conversion:Dt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&yt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>yt(t)?{conversion:t=>({node:wt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=wt(t.tag);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=n!==this.getTextContentSize()&&t?wt(this.getTag()):f(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=f();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?f():wt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return!0}}function yt(t){return"span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Dt(t){const e=t.nodeName.toLowerCase();let n=null;return"h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=wt(e),null!==t.style&&n.setFormat(t.style.textAlign)),{node:n}}function xt(t){const e=ht();return null!==t.style&&e.setFormat(t.style.textAlign),{node:e}}function wt(t){return m(new Ct(t))}function Et(t){return t instanceof Ct}function Nt(t){let e=null;if(s(t,DragEvent)?e=t.dataTransfer:s(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(e.files),o]}function At(t){const e=p();if(!C(e))return!1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=u(o),a=s.getKey();s.canIndent()&&!n.has(a)&&(n.add(a),t(s))}return n.size>0}function Pt(t){const e=V(t);return K(e)}function Ot(o){return a(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(v,(t=>{const e=p();return!!C(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!C(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!C(e)&&(e.deleteLine(t),!0)}),y),o.registerCommand(w,(e=>{const n=p();if("string"==typeof e)null!==n&&n.insertText(e);else{if(null===n)return!1;const r=e.dataTransfer;if(null!=r)t(r,n,o);else if(C(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!C(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!C(e)&&(e.formatText(t),!0)}),y),o.registerCommand(A,(t=>{const e=p();if(!C(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=c(e,(t=>P(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(O,(t=>{const e=p();return!!C(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(T,(()=>{const t=p();return!!C(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(I,(()=>(S([_()]),!0)),y),o.registerCommand(F,(()=>At((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(M,(()=>At((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(b,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(C(e)){const n=k(e.focus,!0);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return!1}),y),o.registerCommand(J,(t=>{const e=p();if(h(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if(C(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===q().getChildrenSize()}(e))return t.preventDefault(),!0;const n=k(e.focus,!1);if(!t.shiftKey&&K(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!C(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(R,(t=>{const e=p();if(h(e)&&!Pt(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!C(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(z,(t=>{if(Pt(t.target))return!1;const e=p();if(!C(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!W(r)){if(u(r).getIndent()>0)return o.dispatchCommand(M,void 0)}return o.dispatchCommand(v,!0)}),y),o.registerCommand(X,(t=>{if(Pt(t.target))return!1;const e=p();return!!C(e)&&(t.preventDefault(),o.dispatchCommand(v,!1))}),y),o.registerCommand(Y,(t=>{const e=p();if(!C(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(O,!1)}return o.dispatchCommand(T,void 0)}),y),o.registerCommand(B,(()=>{const t=p();return!!C(t)&&(o.blur(),!0)}),y),o.registerCommand(G,(t=>{const[,e]=Nt(t);if(e.length>0){const n=st(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,i=V(r);if(null!==i){const e=j();if(H(i))e.anchor.set(i.getKey(),t,"text"),e.focus.set(i.getKey(),t,"text");else{const t=i.getParentOrThrow().getKey(),n=i.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element")}const n=Q(e);U(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!C(n)}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();return!(e&&!C(n))}),y),o.registerCommand($,(t=>{const[e]=Nt(t),n=p();if(e&&!C(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=V(r.node);K(e)&&t.preventDefault()}return!0}),y),o.registerCommand(tt,(()=>(et(),!0)),y),o.registerCommand(nt,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(rt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();C(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(ot,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(it(e.target))return!1;return null!==p()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=p(),o=s(e,InputEvent)||s(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&t(o,r,n)}),{tag:"paste"})}(e,o),!0)}),y))}export{wt as $createHeadingNode,ht as $createQuoteNode,Et as $isHeadingNode,vt as $isQuoteNode,gt as DRAG_DROP_PASTE,Ct as HeadingNode,pt as QuoteNode,Nt as eventFiles,Ot as registerRichText};
|
|
8
|
+
|
|
9
|
+
import{$insertDataTransferForRichText as t,copyToClipboard as e}from"@lexical/clipboard";import{$shouldOverrideDefaultCharacterSelection as n,$moveCharacter as r}from"@lexical/selection";import{addClassNamesToElement as o,isHTMLElement as i,objectKlassEquals as s,mergeRegister as c,$findMatchingParent as a,$getNearestBlockElementAncestorOrThrow as u}from"@lexical/utils";import{createCommand as l,ElementNode as d,$createParagraphNode as m,$applyNodeReplacement as f,CLICK_COMMAND as g,$getSelection as p,$isNodeSelection as h,DELETE_CHARACTER_COMMAND as C,$isRangeSelection as v,COMMAND_PRIORITY_EDITOR as y,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as x,CONTROLLED_TEXT_INSERTION_COMMAND as w,REMOVE_TEXT_COMMAND as E,FORMAT_TEXT_COMMAND as N,FORMAT_ELEMENT_COMMAND as I,$isElementNode as O,INSERT_LINE_BREAK_COMMAND as T,INSERT_PARAGRAPH_COMMAND as A,INSERT_TAB_COMMAND as P,$insertNodes as S,$createTabNode as _,INDENT_CONTENT_COMMAND as b,OUTDENT_CONTENT_COMMAND as F,KEY_ARROW_UP_COMMAND as M,$getAdjacentNode as K,$isDecoratorNode as k,KEY_ARROW_DOWN_COMMAND as J,KEY_ARROW_LEFT_COMMAND as q,KEY_ARROW_RIGHT_COMMAND as L,KEY_BACKSPACE_COMMAND as R,$isRootNode as z,KEY_DELETE_COMMAND as W,KEY_ENTER_COMMAND as X,KEY_ESCAPE_COMMAND as Y,DROP_COMMAND as B,$getNearestNodeFromDOMNode as G,$createRangeSelection as V,$isTextNode as j,$normalizeSelection__EXPERIMENTAL as H,$setSelection as Q,DRAGSTART_COMMAND as U,DRAGOVER_COMMAND as Z,SELECT_ALL_COMMAND as $,$selectAll as tt,COPY_COMMAND as et,CUT_COMMAND as nt,PASTE_COMMAND as rt,isSelectionCapturedInDecoratorInput as ot,$getRoot as it}from"lexical";function st(t,e){if(void 0!==document.caretRangeFromPoint){const n=document.caretRangeFromPoint(t,e);return null===n?null:{node:n.startContainer,offset:n.startOffset}}if("undefined"!==document.caretPositionFromPoint){const n=document.caretPositionFromPoint(t,e);return null===n?null:{node:n.offsetNode,offset:n.offset}}return null}const ct="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,at=ct&&"documentMode"in document?document.documentMode:null,ut=!(!ct||!("InputEvent"in window)||at)&&"getTargetRanges"in new window.InputEvent("input"),lt=ct&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),dt=ct&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,mt=ct&&/^(?=.*Chrome).*/i.test(navigator.userAgent),ft=ct&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!mt,gt=l("DRAG_DROP_PASTE_FILE");class pt extends d{static getType(){return"quote"}static clone(t){return new pt(t.__key)}constructor(t){super(t)}createDOM(t){const e=document.createElement("blockquote");return o(e,t.theme.quote),e}updateDOM(t,e){return!1}static importDOM(){return{blockquote:t=>({conversion:xt,priority:0})}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=ht();return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),type:"quote"}}insertNewAfter(t,e){const n=m(),r=this.getDirection();return n.setDirection(r),this.insertAfter(n,e),n}collapseAtStart(){const t=m();return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}}function ht(){return f(new pt)}function Ct(t){return t instanceof pt}class vt extends d{static getType(){return"heading"}static clone(t){return new vt(t.__tag,t.__key)}constructor(t,e){super(e),this.__tag=t}getTag(){return this.__tag}createDOM(t){const e=this.__tag,n=document.createElement(e),r=t.theme.heading;if(void 0!==r){const t=r[e];o(n,t)}return n}updateDOM(t,e){return!1}static importDOM(){return{h1:t=>({conversion:Dt,priority:0}),h2:t=>({conversion:Dt,priority:0}),h3:t=>({conversion:Dt,priority:0}),h4:t=>({conversion:Dt,priority:0}),h5:t=>({conversion:Dt,priority:0}),h6:t=>({conversion:Dt,priority:0}),p:t=>{const e=t.firstChild;return null!==e&&yt(e)?{conversion:()=>({node:null}),priority:3}:null},span:t=>yt(t)?{conversion:t=>({node:wt("h1")}),priority:3}:null}}exportDOM(t){const{element:e}=super.exportDOM(t);if(e&&i(e)){this.isEmpty()&&e.append(document.createElement("br"));const t=this.getFormatType();e.style.textAlign=t;const n=this.getDirection();n&&(e.dir=n)}return{element:e}}static importJSON(t){const e=wt(t.tag);return e.setFormat(t.format),e.setIndent(t.indent),e.setDirection(t.direction),e}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(t,e=!0){const n=t?t.anchor.offset:0,r=n!==this.getTextContentSize()&&t?wt(this.getTag()):m(),o=this.getDirection();if(r.setDirection(o),this.insertAfter(r,e),0===n&&!this.isEmpty()&&t){const t=m();t.select(),this.replace(t,!0)}return r}collapseAtStart(){const t=this.isEmpty()?m():wt(this.getTag());return this.getChildren().forEach((e=>t.append(e))),this.replace(t),!0}extractWithChild(){return!0}}function yt(t){return"span"===t.nodeName.toLowerCase()&&"26pt"===t.style.fontSize}function Dt(t){const e=t.nodeName.toLowerCase();let n=null;return"h1"!==e&&"h2"!==e&&"h3"!==e&&"h4"!==e&&"h5"!==e&&"h6"!==e||(n=wt(e),null!==t.style&&n.setFormat(t.style.textAlign)),{node:n}}function xt(t){const e=ht();return null!==t.style&&e.setFormat(t.style.textAlign),{node:e}}function wt(t){return f(new vt(t))}function Et(t){return t instanceof vt}function Nt(t){let e=null;if(s(t,DragEvent)?e=t.dataTransfer:s(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,r=n.includes("Files"),o=n.includes("text/html")||n.includes("text/plain");return[r,Array.from(e.files),o]}function It(t){const e=p();if(!v(e))return!1;const n=new Set,r=e.getNodes();for(let e=0;e<r.length;e++){const o=r[e],i=o.getKey();if(n.has(i))continue;const s=a(o,(t=>O(t)&&!t.isInline()));if(null===s)continue;const c=s.getKey();s.canIndent()&&!n.has(c)&&(n.add(c),t(s))}return n.size>0}function Ot(t){const e=G(t);return k(e)}function Tt(o){return c(o.registerCommand(g,(t=>{const e=p();return!!h(e)&&(e.clear(),!0)}),0),o.registerCommand(C,(t=>{const e=p();return!!v(e)&&(e.deleteCharacter(t),!0)}),y),o.registerCommand(D,(t=>{const e=p();return!!v(e)&&(e.deleteWord(t),!0)}),y),o.registerCommand(x,(t=>{const e=p();return!!v(e)&&(e.deleteLine(t),!0)}),y),o.registerCommand(w,(e=>{const n=p();if("string"==typeof e)null!==n&&n.insertText(e);else{if(null===n)return!1;const r=e.dataTransfer;if(null!=r)t(r,n,o);else if(v(n)){const t=e.data;return t&&n.insertText(t),!0}}return!0}),y),o.registerCommand(E,(()=>{const t=p();return!!v(t)&&(t.removeText(),!0)}),y),o.registerCommand(N,(t=>{const e=p();return!!v(e)&&(e.formatText(t),!0)}),y),o.registerCommand(I,(t=>{const e=p();if(!v(e)&&!h(e))return!1;const n=e.getNodes();for(const e of n){const n=a(e,(t=>O(t)&&!t.isInline()));null!==n&&n.setFormat(t)}return!0}),y),o.registerCommand(T,(t=>{const e=p();return!!v(e)&&(e.insertLineBreak(t),!0)}),y),o.registerCommand(A,(()=>{const t=p();return!!v(t)&&(t.insertParagraph(),!0)}),y),o.registerCommand(P,(()=>(S([_()]),!0)),y),o.registerCommand(b,(()=>It((t=>{const e=t.getIndent();t.setIndent(e+1)}))),y),o.registerCommand(F,(()=>It((t=>{const e=t.getIndent();e>0&&t.setIndent(e-1)}))),y),o.registerCommand(M,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const t=e.getNodes();if(t.length>0)return t[0].selectPrevious(),!0}else if(v(e)){const n=K(e.focus,!0);if(!t.shiftKey&&k(n)&&!n.isIsolated()&&!n.isInline())return n.selectPrevious(),t.preventDefault(),!0}return!1}),y),o.registerCommand(J,(t=>{const e=p();if(h(e)){const t=e.getNodes();if(t.length>0)return t[0].selectNext(0,0),!0}else if(v(e)){if(function(t){const e=t.focus;return"root"===e.key&&e.offset===it().getChildrenSize()}(e))return t.preventDefault(),!0;const n=K(e.focus,!1);if(!t.shiftKey&&k(n)&&!n.isIsolated()&&!n.isInline())return n.selectNext(),t.preventDefault(),!0}return!1}),y),o.registerCommand(q,(t=>{const e=p();if(h(e)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectPrevious(),!0}if(!v(e))return!1;if(n(e,!0)){const n=t.shiftKey;return t.preventDefault(),r(e,n,!0),!0}return!1}),y),o.registerCommand(L,(t=>{const e=p();if(h(e)&&!Ot(t.target)){const n=e.getNodes();if(n.length>0)return t.preventDefault(),n[0].selectNext(0,0),!0}if(!v(e))return!1;const o=t.shiftKey;return!!n(e,!1)&&(t.preventDefault(),r(e,o,!1),!0)}),y),o.registerCommand(R,(t=>{if(Ot(t.target))return!1;const e=p();if(!v(e))return!1;t.preventDefault();const{anchor:n}=e,r=n.getNode();if(e.isCollapsed()&&0===n.offset&&!z(r)){if(u(r).getIndent()>0)return o.dispatchCommand(F,void 0)}return o.dispatchCommand(C,!0)}),y),o.registerCommand(W,(t=>{if(Ot(t.target))return!1;const e=p();return!!v(e)&&(t.preventDefault(),o.dispatchCommand(C,!1))}),y),o.registerCommand(X,(t=>{const e=p();if(!v(e))return!1;if(null!==t){if((dt||lt||ft)&&ut)return!1;if(t.preventDefault(),t.shiftKey)return o.dispatchCommand(T,!1)}return o.dispatchCommand(A,void 0)}),y),o.registerCommand(Y,(()=>{const t=p();return!!v(t)&&(o.blur(),!0)}),y),o.registerCommand(B,(t=>{const[,e]=Nt(t);if(e.length>0){const n=st(t.clientX,t.clientY);if(null!==n){const{offset:t,node:r}=n,i=G(r);if(null!==i){const e=V();if(j(i))e.anchor.set(i.getKey(),t,"text"),e.focus.set(i.getKey(),t,"text");else{const t=i.getParentOrThrow().getKey(),n=i.getIndexWithinParent()+1;e.anchor.set(t,n,"element"),e.focus.set(t,n,"element")}const n=H(e);Q(n)}o.dispatchCommand(gt,e)}return t.preventDefault(),!0}const n=p();return!!v(n)}),y),o.registerCommand(U,(t=>{const[e]=Nt(t),n=p();return!(e&&!v(n))}),y),o.registerCommand(Z,(t=>{const[e]=Nt(t),n=p();if(e&&!v(n))return!1;const r=st(t.clientX,t.clientY);if(null!==r){const e=G(r.node);k(e)&&t.preventDefault()}return!0}),y),o.registerCommand($,(()=>(tt(),!0)),y),o.registerCommand(et,(t=>(e(o,s(t,ClipboardEvent)?t:null),!0)),y),o.registerCommand(nt,(t=>(async function(t,n){await e(n,s(t,ClipboardEvent)?t:null),n.update((()=>{const t=p();v(t)?t.removeText():h(t)&&t.getNodes().forEach((t=>t.remove()))}))}(t,o),!0)),y),o.registerCommand(rt,(e=>{const[,n,r]=Nt(e);if(n.length>0&&!r)return o.dispatchCommand(gt,n),!0;if(ot(e.target))return!1;return null!==p()&&(function(e,n){e.preventDefault(),n.update((()=>{const r=p(),o=s(e,InputEvent)||s(e,KeyboardEvent)?null:e.clipboardData;null!=o&&null!==r&&t(o,r,n)}),{tag:"paste"})}(e,o),!0)}),y))}export{wt as $createHeadingNode,ht as $createQuoteNode,Et as $isHeadingNode,Ct as $isQuoteNode,gt as DRAG_DROP_PASTE,vt as HeadingNode,pt as QuoteNode,Nt as eventFiles,Tt as registerRichText};
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.15.0",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"types": "index.d.ts",
|
|
13
13
|
"repository": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@lexical/clipboard": "0.
|
|
39
|
-
"@lexical/selection": "0.
|
|
40
|
-
"@lexical/utils": "0.
|
|
41
|
-
"lexical": "0.
|
|
38
|
+
"@lexical/clipboard": "0.15.0",
|
|
39
|
+
"@lexical/selection": "0.15.0",
|
|
40
|
+
"@lexical/utils": "0.15.0",
|
|
41
|
+
"lexical": "0.15.0"
|
|
42
42
|
}
|
|
43
43
|
}
|