@lexical/rich-text 0.13.1 → 0.14.2
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.esm.js +766 -0
- package/LexicalRichText.dev.js +11 -6
- package/LexicalRichText.esm.js +18 -0
- package/LexicalRichText.js +1 -1
- package/LexicalRichText.prod.esm.js +7 -0
- package/LexicalRichText.prod.js +19 -19
- package/package.json +8 -6
|
@@ -0,0 +1,766 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { $insertDataTransferForRichText, copyToClipboard } from '@lexical/clipboard';
|
|
8
|
+
import { $shouldOverrideDefaultCharacterSelection, $moveCharacter } from '@lexical/selection';
|
|
9
|
+
import { addClassNamesToElement, isHTMLElement, objectKlassEquals, mergeRegister, $findMatchingParent, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
|
|
10
|
+
import { createCommand, ElementNode, $applyNodeReplacement, $createParagraphNode, 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, $isDecoratorNode, $getAdjacentNode, KEY_ARROW_DOWN_COMMAND, $getRoot, 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 } from 'lexical';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
+
*
|
|
15
|
+
* This source code is licensed under the MIT license found in the
|
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function caretFromPoint(x, y) {
|
|
21
|
+
if (typeof document.caretRangeFromPoint !== 'undefined') {
|
|
22
|
+
const range = document.caretRangeFromPoint(x, y);
|
|
23
|
+
if (range === null) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
node: range.startContainer,
|
|
28
|
+
offset: range.startOffset
|
|
29
|
+
};
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
} else if (document.caretPositionFromPoint !== 'undefined') {
|
|
32
|
+
// @ts-ignore FF - no types
|
|
33
|
+
const range = document.caretPositionFromPoint(x, y);
|
|
34
|
+
if (range === null) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
node: range.offsetNode,
|
|
39
|
+
offset: range.offset
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
// Gracefully handle IE
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
49
|
+
*
|
|
50
|
+
* This source code is licensed under the MIT license found in the
|
|
51
|
+
* LICENSE file in the root directory of this source tree.
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
59
|
+
*
|
|
60
|
+
* This source code is licensed under the MIT license found in the
|
|
61
|
+
* LICENSE file in the root directory of this source tree.
|
|
62
|
+
*
|
|
63
|
+
*/
|
|
64
|
+
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
|
+
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
68
|
+
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
69
|
+
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
|
+
|
|
72
|
+
// Keep these in case we need to use them in the future.
|
|
73
|
+
// export const IS_WINDOWS: boolean = CAN_USE_DOM && /Win/.test(navigator.platform);
|
|
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
|
+
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
79
|
+
|
|
80
|
+
/** @module @lexical/rich-text */
|
|
81
|
+
const DRAG_DROP_PASTE = createCommand('DRAG_DROP_PASTE_FILE');
|
|
82
|
+
/** @noInheritDoc */
|
|
83
|
+
class QuoteNode extends ElementNode {
|
|
84
|
+
static getType() {
|
|
85
|
+
return 'quote';
|
|
86
|
+
}
|
|
87
|
+
static clone(node) {
|
|
88
|
+
return new QuoteNode(node.__key);
|
|
89
|
+
}
|
|
90
|
+
constructor(key) {
|
|
91
|
+
super(key);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// View
|
|
95
|
+
|
|
96
|
+
createDOM(config) {
|
|
97
|
+
const element = document.createElement('blockquote');
|
|
98
|
+
addClassNamesToElement(element, config.theme.quote);
|
|
99
|
+
return element;
|
|
100
|
+
}
|
|
101
|
+
updateDOM(prevNode, dom) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
static importDOM() {
|
|
105
|
+
return {
|
|
106
|
+
blockquote: node => ({
|
|
107
|
+
conversion: convertBlockquoteElement,
|
|
108
|
+
priority: 0
|
|
109
|
+
})
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
exportDOM(editor) {
|
|
113
|
+
const {
|
|
114
|
+
element
|
|
115
|
+
} = super.exportDOM(editor);
|
|
116
|
+
if (element && isHTMLElement(element)) {
|
|
117
|
+
if (this.isEmpty()) {
|
|
118
|
+
element.append(document.createElement('br'));
|
|
119
|
+
}
|
|
120
|
+
const formatType = this.getFormatType();
|
|
121
|
+
element.style.textAlign = formatType;
|
|
122
|
+
const direction = this.getDirection();
|
|
123
|
+
if (direction) {
|
|
124
|
+
element.dir = direction;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
element
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
static importJSON(serializedNode) {
|
|
132
|
+
const node = $createQuoteNode();
|
|
133
|
+
node.setFormat(serializedNode.format);
|
|
134
|
+
node.setIndent(serializedNode.indent);
|
|
135
|
+
node.setDirection(serializedNode.direction);
|
|
136
|
+
return node;
|
|
137
|
+
}
|
|
138
|
+
exportJSON() {
|
|
139
|
+
return {
|
|
140
|
+
...super.exportJSON(),
|
|
141
|
+
type: 'quote'
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Mutation
|
|
146
|
+
|
|
147
|
+
insertNewAfter(_, restoreSelection) {
|
|
148
|
+
const newBlock = $createParagraphNode();
|
|
149
|
+
const direction = this.getDirection();
|
|
150
|
+
newBlock.setDirection(direction);
|
|
151
|
+
this.insertAfter(newBlock, restoreSelection);
|
|
152
|
+
return newBlock;
|
|
153
|
+
}
|
|
154
|
+
collapseAtStart() {
|
|
155
|
+
const paragraph = $createParagraphNode();
|
|
156
|
+
const children = this.getChildren();
|
|
157
|
+
children.forEach(child => paragraph.append(child));
|
|
158
|
+
this.replace(paragraph);
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
function $createQuoteNode() {
|
|
163
|
+
return $applyNodeReplacement(new QuoteNode());
|
|
164
|
+
}
|
|
165
|
+
function $isQuoteNode(node) {
|
|
166
|
+
return node instanceof QuoteNode;
|
|
167
|
+
}
|
|
168
|
+
/** @noInheritDoc */
|
|
169
|
+
class HeadingNode extends ElementNode {
|
|
170
|
+
/** @internal */
|
|
171
|
+
|
|
172
|
+
static getType() {
|
|
173
|
+
return 'heading';
|
|
174
|
+
}
|
|
175
|
+
static clone(node) {
|
|
176
|
+
return new HeadingNode(node.__tag, node.__key);
|
|
177
|
+
}
|
|
178
|
+
constructor(tag, key) {
|
|
179
|
+
super(key);
|
|
180
|
+
this.__tag = tag;
|
|
181
|
+
}
|
|
182
|
+
getTag() {
|
|
183
|
+
return this.__tag;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// View
|
|
187
|
+
|
|
188
|
+
createDOM(config) {
|
|
189
|
+
const tag = this.__tag;
|
|
190
|
+
const element = document.createElement(tag);
|
|
191
|
+
const theme = config.theme;
|
|
192
|
+
const classNames = theme.heading;
|
|
193
|
+
if (classNames !== undefined) {
|
|
194
|
+
const className = classNames[tag];
|
|
195
|
+
addClassNamesToElement(element, className);
|
|
196
|
+
}
|
|
197
|
+
return element;
|
|
198
|
+
}
|
|
199
|
+
updateDOM(prevNode, dom) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
static importDOM() {
|
|
203
|
+
return {
|
|
204
|
+
h1: node => ({
|
|
205
|
+
conversion: convertHeadingElement,
|
|
206
|
+
priority: 0
|
|
207
|
+
}),
|
|
208
|
+
h2: node => ({
|
|
209
|
+
conversion: convertHeadingElement,
|
|
210
|
+
priority: 0
|
|
211
|
+
}),
|
|
212
|
+
h3: node => ({
|
|
213
|
+
conversion: convertHeadingElement,
|
|
214
|
+
priority: 0
|
|
215
|
+
}),
|
|
216
|
+
h4: node => ({
|
|
217
|
+
conversion: convertHeadingElement,
|
|
218
|
+
priority: 0
|
|
219
|
+
}),
|
|
220
|
+
h5: node => ({
|
|
221
|
+
conversion: convertHeadingElement,
|
|
222
|
+
priority: 0
|
|
223
|
+
}),
|
|
224
|
+
h6: node => ({
|
|
225
|
+
conversion: convertHeadingElement,
|
|
226
|
+
priority: 0
|
|
227
|
+
}),
|
|
228
|
+
p: node => {
|
|
229
|
+
// domNode is a <p> since we matched it by nodeName
|
|
230
|
+
const paragraph = node;
|
|
231
|
+
const firstChild = paragraph.firstChild;
|
|
232
|
+
if (firstChild !== null && isGoogleDocsTitle(firstChild)) {
|
|
233
|
+
return {
|
|
234
|
+
conversion: () => ({
|
|
235
|
+
node: null
|
|
236
|
+
}),
|
|
237
|
+
priority: 3
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return null;
|
|
241
|
+
},
|
|
242
|
+
span: node => {
|
|
243
|
+
if (isGoogleDocsTitle(node)) {
|
|
244
|
+
return {
|
|
245
|
+
conversion: domNode => {
|
|
246
|
+
return {
|
|
247
|
+
node: $createHeadingNode('h1')
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
priority: 3
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
exportDOM(editor) {
|
|
258
|
+
const {
|
|
259
|
+
element
|
|
260
|
+
} = super.exportDOM(editor);
|
|
261
|
+
if (element && isHTMLElement(element)) {
|
|
262
|
+
if (this.isEmpty()) {
|
|
263
|
+
element.append(document.createElement('br'));
|
|
264
|
+
}
|
|
265
|
+
const formatType = this.getFormatType();
|
|
266
|
+
element.style.textAlign = formatType;
|
|
267
|
+
const direction = this.getDirection();
|
|
268
|
+
if (direction) {
|
|
269
|
+
element.dir = direction;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
element
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
static importJSON(serializedNode) {
|
|
277
|
+
const node = $createHeadingNode(serializedNode.tag);
|
|
278
|
+
node.setFormat(serializedNode.format);
|
|
279
|
+
node.setIndent(serializedNode.indent);
|
|
280
|
+
node.setDirection(serializedNode.direction);
|
|
281
|
+
return node;
|
|
282
|
+
}
|
|
283
|
+
exportJSON() {
|
|
284
|
+
return {
|
|
285
|
+
...super.exportJSON(),
|
|
286
|
+
tag: this.getTag(),
|
|
287
|
+
type: 'heading',
|
|
288
|
+
version: 1
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// Mutation
|
|
293
|
+
insertNewAfter(selection, restoreSelection = true) {
|
|
294
|
+
const anchorOffet = selection ? selection.anchor.offset : 0;
|
|
295
|
+
const newElement = anchorOffet === this.getTextContentSize() || !selection ? $createParagraphNode() : $createHeadingNode(this.getTag());
|
|
296
|
+
const direction = this.getDirection();
|
|
297
|
+
newElement.setDirection(direction);
|
|
298
|
+
this.insertAfter(newElement, restoreSelection);
|
|
299
|
+
if (anchorOffet === 0 && !this.isEmpty() && selection) {
|
|
300
|
+
const paragraph = $createParagraphNode();
|
|
301
|
+
paragraph.select();
|
|
302
|
+
this.replace(paragraph, true);
|
|
303
|
+
}
|
|
304
|
+
return newElement;
|
|
305
|
+
}
|
|
306
|
+
collapseAtStart() {
|
|
307
|
+
const newElement = !this.isEmpty() ? $createHeadingNode(this.getTag()) : $createParagraphNode();
|
|
308
|
+
const children = this.getChildren();
|
|
309
|
+
children.forEach(child => newElement.append(child));
|
|
310
|
+
this.replace(newElement);
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
extractWithChild() {
|
|
314
|
+
return true;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
function isGoogleDocsTitle(domNode) {
|
|
318
|
+
if (domNode.nodeName.toLowerCase() === 'span') {
|
|
319
|
+
return domNode.style.fontSize === '26pt';
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
function convertHeadingElement(element) {
|
|
324
|
+
const nodeName = element.nodeName.toLowerCase();
|
|
325
|
+
let node = null;
|
|
326
|
+
if (nodeName === 'h1' || nodeName === 'h2' || nodeName === 'h3' || nodeName === 'h4' || nodeName === 'h5' || nodeName === 'h6') {
|
|
327
|
+
node = $createHeadingNode(nodeName);
|
|
328
|
+
if (element.style !== null) {
|
|
329
|
+
node.setFormat(element.style.textAlign);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return {
|
|
333
|
+
node
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function convertBlockquoteElement(element) {
|
|
337
|
+
const node = $createQuoteNode();
|
|
338
|
+
if (element.style !== null) {
|
|
339
|
+
node.setFormat(element.style.textAlign);
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
node
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
function $createHeadingNode(headingTag) {
|
|
346
|
+
return $applyNodeReplacement(new HeadingNode(headingTag));
|
|
347
|
+
}
|
|
348
|
+
function $isHeadingNode(node) {
|
|
349
|
+
return node instanceof HeadingNode;
|
|
350
|
+
}
|
|
351
|
+
function onPasteForRichText(event, editor) {
|
|
352
|
+
event.preventDefault();
|
|
353
|
+
editor.update(() => {
|
|
354
|
+
const selection = $getSelection();
|
|
355
|
+
const clipboardData = objectKlassEquals(event, InputEvent) || objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
|
|
356
|
+
if (clipboardData != null && selection !== null) {
|
|
357
|
+
$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
358
|
+
}
|
|
359
|
+
}, {
|
|
360
|
+
tag: 'paste'
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
async function onCutForRichText(event, editor) {
|
|
364
|
+
await copyToClipboard(editor, objectKlassEquals(event, ClipboardEvent) ? event : null);
|
|
365
|
+
editor.update(() => {
|
|
366
|
+
const selection = $getSelection();
|
|
367
|
+
if ($isRangeSelection(selection)) {
|
|
368
|
+
selection.removeText();
|
|
369
|
+
} else if ($isNodeSelection(selection)) {
|
|
370
|
+
selection.getNodes().forEach(node => node.remove());
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Clipboard may contain files that we aren't allowed to read. While the event is arguably useless,
|
|
376
|
+
// in certain occasions, we want to know whether it was a file transfer, as opposed to text. We
|
|
377
|
+
// control this with the first boolean flag.
|
|
378
|
+
function eventFiles(event) {
|
|
379
|
+
let dataTransfer = null;
|
|
380
|
+
if (objectKlassEquals(event, DragEvent)) {
|
|
381
|
+
dataTransfer = event.dataTransfer;
|
|
382
|
+
} else if (objectKlassEquals(event, ClipboardEvent)) {
|
|
383
|
+
dataTransfer = event.clipboardData;
|
|
384
|
+
}
|
|
385
|
+
if (dataTransfer === null) {
|
|
386
|
+
return [false, [], false];
|
|
387
|
+
}
|
|
388
|
+
const types = dataTransfer.types;
|
|
389
|
+
const hasFiles = types.includes('Files');
|
|
390
|
+
const hasContent = types.includes('text/html') || types.includes('text/plain');
|
|
391
|
+
return [hasFiles, Array.from(dataTransfer.files), hasContent];
|
|
392
|
+
}
|
|
393
|
+
function handleIndentAndOutdent(indentOrOutdent) {
|
|
394
|
+
const selection = $getSelection();
|
|
395
|
+
if (!$isRangeSelection(selection)) {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
const alreadyHandled = new Set();
|
|
399
|
+
const nodes = selection.getNodes();
|
|
400
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
401
|
+
const node = nodes[i];
|
|
402
|
+
const key = node.getKey();
|
|
403
|
+
if (alreadyHandled.has(key)) {
|
|
404
|
+
continue;
|
|
405
|
+
}
|
|
406
|
+
const parentBlock = $getNearestBlockElementAncestorOrThrow(node);
|
|
407
|
+
const parentKey = parentBlock.getKey();
|
|
408
|
+
if (parentBlock.canIndent() && !alreadyHandled.has(parentKey)) {
|
|
409
|
+
alreadyHandled.add(parentKey);
|
|
410
|
+
indentOrOutdent(parentBlock);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return alreadyHandled.size > 0;
|
|
414
|
+
}
|
|
415
|
+
function $isTargetWithinDecorator(target) {
|
|
416
|
+
const node = $getNearestNodeFromDOMNode(target);
|
|
417
|
+
return $isDecoratorNode(node);
|
|
418
|
+
}
|
|
419
|
+
function $isSelectionAtEndOfRoot(selection) {
|
|
420
|
+
const focus = selection.focus;
|
|
421
|
+
return focus.key === 'root' && focus.offset === $getRoot().getChildrenSize();
|
|
422
|
+
}
|
|
423
|
+
function registerRichText(editor) {
|
|
424
|
+
const removeListener = mergeRegister(editor.registerCommand(CLICK_COMMAND, payload => {
|
|
425
|
+
const selection = $getSelection();
|
|
426
|
+
if ($isNodeSelection(selection)) {
|
|
427
|
+
selection.clear();
|
|
428
|
+
return true;
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}, 0), editor.registerCommand(DELETE_CHARACTER_COMMAND, isBackward => {
|
|
432
|
+
const selection = $getSelection();
|
|
433
|
+
if (!$isRangeSelection(selection)) {
|
|
434
|
+
return false;
|
|
435
|
+
}
|
|
436
|
+
selection.deleteCharacter(isBackward);
|
|
437
|
+
return true;
|
|
438
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_WORD_COMMAND, isBackward => {
|
|
439
|
+
const selection = $getSelection();
|
|
440
|
+
if (!$isRangeSelection(selection)) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
selection.deleteWord(isBackward);
|
|
444
|
+
return true;
|
|
445
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DELETE_LINE_COMMAND, isBackward => {
|
|
446
|
+
const selection = $getSelection();
|
|
447
|
+
if (!$isRangeSelection(selection)) {
|
|
448
|
+
return false;
|
|
449
|
+
}
|
|
450
|
+
selection.deleteLine(isBackward);
|
|
451
|
+
return true;
|
|
452
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CONTROLLED_TEXT_INSERTION_COMMAND, eventOrText => {
|
|
453
|
+
const selection = $getSelection();
|
|
454
|
+
if (typeof eventOrText === 'string') {
|
|
455
|
+
if (selection !== null) {
|
|
456
|
+
selection.insertText(eventOrText);
|
|
457
|
+
}
|
|
458
|
+
} else {
|
|
459
|
+
if (selection === null) {
|
|
460
|
+
return false;
|
|
461
|
+
}
|
|
462
|
+
const dataTransfer = eventOrText.dataTransfer;
|
|
463
|
+
if (dataTransfer != null) {
|
|
464
|
+
$insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
465
|
+
} else if ($isRangeSelection(selection)) {
|
|
466
|
+
const data = eventOrText.data;
|
|
467
|
+
if (data) {
|
|
468
|
+
selection.insertText(data);
|
|
469
|
+
}
|
|
470
|
+
return true;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return true;
|
|
474
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(REMOVE_TEXT_COMMAND, () => {
|
|
475
|
+
const selection = $getSelection();
|
|
476
|
+
if (!$isRangeSelection(selection)) {
|
|
477
|
+
return false;
|
|
478
|
+
}
|
|
479
|
+
selection.removeText();
|
|
480
|
+
return true;
|
|
481
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(FORMAT_TEXT_COMMAND, format => {
|
|
482
|
+
const selection = $getSelection();
|
|
483
|
+
if (!$isRangeSelection(selection)) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
selection.formatText(format);
|
|
487
|
+
return true;
|
|
488
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(FORMAT_ELEMENT_COMMAND, format => {
|
|
489
|
+
const selection = $getSelection();
|
|
490
|
+
if (!$isRangeSelection(selection) && !$isNodeSelection(selection)) {
|
|
491
|
+
return false;
|
|
492
|
+
}
|
|
493
|
+
const nodes = selection.getNodes();
|
|
494
|
+
for (const node of nodes) {
|
|
495
|
+
const element = $findMatchingParent(node, parentNode => $isElementNode(parentNode) && !parentNode.isInline());
|
|
496
|
+
if (element !== null) {
|
|
497
|
+
element.setFormat(format);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return true;
|
|
501
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_LINE_BREAK_COMMAND, selectStart => {
|
|
502
|
+
const selection = $getSelection();
|
|
503
|
+
if (!$isRangeSelection(selection)) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
selection.insertLineBreak(selectStart);
|
|
507
|
+
return true;
|
|
508
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
|
|
509
|
+
const selection = $getSelection();
|
|
510
|
+
if (!$isRangeSelection(selection)) {
|
|
511
|
+
return false;
|
|
512
|
+
}
|
|
513
|
+
selection.insertParagraph();
|
|
514
|
+
return true;
|
|
515
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INSERT_TAB_COMMAND, () => {
|
|
516
|
+
$insertNodes([$createTabNode()]);
|
|
517
|
+
return true;
|
|
518
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(INDENT_CONTENT_COMMAND, () => {
|
|
519
|
+
return handleIndentAndOutdent(block => {
|
|
520
|
+
const indent = block.getIndent();
|
|
521
|
+
block.setIndent(indent + 1);
|
|
522
|
+
});
|
|
523
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(OUTDENT_CONTENT_COMMAND, () => {
|
|
524
|
+
return handleIndentAndOutdent(block => {
|
|
525
|
+
const indent = block.getIndent();
|
|
526
|
+
if (indent > 0) {
|
|
527
|
+
block.setIndent(indent - 1);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_UP_COMMAND, event => {
|
|
531
|
+
const selection = $getSelection();
|
|
532
|
+
if ($isNodeSelection(selection) && !$isTargetWithinDecorator(event.target)) {
|
|
533
|
+
// If selection is on a node, let's try and move selection
|
|
534
|
+
// back to being a range selection.
|
|
535
|
+
const nodes = selection.getNodes();
|
|
536
|
+
if (nodes.length > 0) {
|
|
537
|
+
nodes[0].selectPrevious();
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
} else if ($isRangeSelection(selection)) {
|
|
541
|
+
const possibleNode = $getAdjacentNode(selection.focus, true);
|
|
542
|
+
if (!event.shiftKey && $isDecoratorNode(possibleNode) && !possibleNode.isIsolated() && !possibleNode.isInline()) {
|
|
543
|
+
possibleNode.selectPrevious();
|
|
544
|
+
event.preventDefault();
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
return false;
|
|
549
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_DOWN_COMMAND, event => {
|
|
550
|
+
const selection = $getSelection();
|
|
551
|
+
if ($isNodeSelection(selection)) {
|
|
552
|
+
// If selection is on a node, let's try and move selection
|
|
553
|
+
// back to being a range selection.
|
|
554
|
+
const nodes = selection.getNodes();
|
|
555
|
+
if (nodes.length > 0) {
|
|
556
|
+
nodes[0].selectNext(0, 0);
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
} else if ($isRangeSelection(selection)) {
|
|
560
|
+
if ($isSelectionAtEndOfRoot(selection)) {
|
|
561
|
+
event.preventDefault();
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
const possibleNode = $getAdjacentNode(selection.focus, false);
|
|
565
|
+
if (!event.shiftKey && $isDecoratorNode(possibleNode) && !possibleNode.isIsolated() && !possibleNode.isInline()) {
|
|
566
|
+
possibleNode.selectNext();
|
|
567
|
+
event.preventDefault();
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return false;
|
|
572
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_LEFT_COMMAND, event => {
|
|
573
|
+
const selection = $getSelection();
|
|
574
|
+
if ($isNodeSelection(selection)) {
|
|
575
|
+
// If selection is on a node, let's try and move selection
|
|
576
|
+
// back to being a range selection.
|
|
577
|
+
const nodes = selection.getNodes();
|
|
578
|
+
if (nodes.length > 0) {
|
|
579
|
+
event.preventDefault();
|
|
580
|
+
nodes[0].selectPrevious();
|
|
581
|
+
return true;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
if (!$isRangeSelection(selection)) {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
|
|
588
|
+
const isHoldingShift = event.shiftKey;
|
|
589
|
+
event.preventDefault();
|
|
590
|
+
$moveCharacter(selection, isHoldingShift, true);
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
return false;
|
|
594
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ARROW_RIGHT_COMMAND, event => {
|
|
595
|
+
const selection = $getSelection();
|
|
596
|
+
if ($isNodeSelection(selection) && !$isTargetWithinDecorator(event.target)) {
|
|
597
|
+
// If selection is on a node, let's try and move selection
|
|
598
|
+
// back to being a range selection.
|
|
599
|
+
const nodes = selection.getNodes();
|
|
600
|
+
if (nodes.length > 0) {
|
|
601
|
+
event.preventDefault();
|
|
602
|
+
nodes[0].selectNext(0, 0);
|
|
603
|
+
return true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (!$isRangeSelection(selection)) {
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
const isHoldingShift = event.shiftKey;
|
|
610
|
+
if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
|
|
611
|
+
event.preventDefault();
|
|
612
|
+
$moveCharacter(selection, isHoldingShift, false);
|
|
613
|
+
return true;
|
|
614
|
+
}
|
|
615
|
+
return false;
|
|
616
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_BACKSPACE_COMMAND, event => {
|
|
617
|
+
if ($isTargetWithinDecorator(event.target)) {
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
const selection = $getSelection();
|
|
621
|
+
if (!$isRangeSelection(selection)) {
|
|
622
|
+
return false;
|
|
623
|
+
}
|
|
624
|
+
event.preventDefault();
|
|
625
|
+
const {
|
|
626
|
+
anchor
|
|
627
|
+
} = selection;
|
|
628
|
+
const anchorNode = anchor.getNode();
|
|
629
|
+
if (selection.isCollapsed() && anchor.offset === 0 && !$isRootNode(anchorNode)) {
|
|
630
|
+
const element = $getNearestBlockElementAncestorOrThrow(anchorNode);
|
|
631
|
+
if (element.getIndent() > 0) {
|
|
632
|
+
return editor.dispatchCommand(OUTDENT_CONTENT_COMMAND, undefined);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, true);
|
|
636
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_DELETE_COMMAND, event => {
|
|
637
|
+
if ($isTargetWithinDecorator(event.target)) {
|
|
638
|
+
return false;
|
|
639
|
+
}
|
|
640
|
+
const selection = $getSelection();
|
|
641
|
+
if (!$isRangeSelection(selection)) {
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
event.preventDefault();
|
|
645
|
+
return editor.dispatchCommand(DELETE_CHARACTER_COMMAND, false);
|
|
646
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ENTER_COMMAND, event => {
|
|
647
|
+
const selection = $getSelection();
|
|
648
|
+
if (!$isRangeSelection(selection)) {
|
|
649
|
+
return false;
|
|
650
|
+
}
|
|
651
|
+
if (event !== null) {
|
|
652
|
+
// If we have beforeinput, then we can avoid blocking
|
|
653
|
+
// the default behavior. This ensures that the iOS can
|
|
654
|
+
// intercept that we're actually inserting a paragraph,
|
|
655
|
+
// and autocomplete, autocapitalize etc work as intended.
|
|
656
|
+
// This can also cause a strange performance issue in
|
|
657
|
+
// Safari, where there is a noticeable pause due to
|
|
658
|
+
// preventing the key down of enter.
|
|
659
|
+
if ((IS_IOS || IS_SAFARI || IS_APPLE_WEBKIT) && CAN_USE_BEFORE_INPUT) {
|
|
660
|
+
return false;
|
|
661
|
+
}
|
|
662
|
+
event.preventDefault();
|
|
663
|
+
if (event.shiftKey) {
|
|
664
|
+
return editor.dispatchCommand(INSERT_LINE_BREAK_COMMAND, false);
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return editor.dispatchCommand(INSERT_PARAGRAPH_COMMAND, undefined);
|
|
668
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(KEY_ESCAPE_COMMAND, () => {
|
|
669
|
+
const selection = $getSelection();
|
|
670
|
+
if (!$isRangeSelection(selection)) {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
editor.blur();
|
|
674
|
+
return true;
|
|
675
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DROP_COMMAND, event => {
|
|
676
|
+
const [, files] = eventFiles(event);
|
|
677
|
+
if (files.length > 0) {
|
|
678
|
+
const x = event.clientX;
|
|
679
|
+
const y = event.clientY;
|
|
680
|
+
const eventRange = caretFromPoint(x, y);
|
|
681
|
+
if (eventRange !== null) {
|
|
682
|
+
const {
|
|
683
|
+
offset: domOffset,
|
|
684
|
+
node: domNode
|
|
685
|
+
} = eventRange;
|
|
686
|
+
const node = $getNearestNodeFromDOMNode(domNode);
|
|
687
|
+
if (node !== null) {
|
|
688
|
+
const selection = $createRangeSelection();
|
|
689
|
+
if ($isTextNode(node)) {
|
|
690
|
+
selection.anchor.set(node.getKey(), domOffset, 'text');
|
|
691
|
+
selection.focus.set(node.getKey(), domOffset, 'text');
|
|
692
|
+
} else {
|
|
693
|
+
const parentKey = node.getParentOrThrow().getKey();
|
|
694
|
+
const offset = node.getIndexWithinParent() + 1;
|
|
695
|
+
selection.anchor.set(parentKey, offset, 'element');
|
|
696
|
+
selection.focus.set(parentKey, offset, 'element');
|
|
697
|
+
}
|
|
698
|
+
const normalizedSelection = $normalizeSelection__EXPERIMENTAL(selection);
|
|
699
|
+
$setSelection(normalizedSelection);
|
|
700
|
+
}
|
|
701
|
+
editor.dispatchCommand(DRAG_DROP_PASTE, files);
|
|
702
|
+
}
|
|
703
|
+
event.preventDefault();
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
const selection = $getSelection();
|
|
707
|
+
if ($isRangeSelection(selection)) {
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
return false;
|
|
711
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DRAGSTART_COMMAND, event => {
|
|
712
|
+
const [isFileTransfer] = eventFiles(event);
|
|
713
|
+
const selection = $getSelection();
|
|
714
|
+
if (isFileTransfer && !$isRangeSelection(selection)) {
|
|
715
|
+
return false;
|
|
716
|
+
}
|
|
717
|
+
return true;
|
|
718
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(DRAGOVER_COMMAND, event => {
|
|
719
|
+
const [isFileTransfer] = eventFiles(event);
|
|
720
|
+
const selection = $getSelection();
|
|
721
|
+
if (isFileTransfer && !$isRangeSelection(selection)) {
|
|
722
|
+
return false;
|
|
723
|
+
}
|
|
724
|
+
const x = event.clientX;
|
|
725
|
+
const y = event.clientY;
|
|
726
|
+
const eventRange = caretFromPoint(x, y);
|
|
727
|
+
if (eventRange !== null) {
|
|
728
|
+
const node = $getNearestNodeFromDOMNode(eventRange.node);
|
|
729
|
+
if ($isDecoratorNode(node)) {
|
|
730
|
+
// Show browser caret as the user is dragging the media across the screen. Won't work
|
|
731
|
+
// for DecoratorNode nor it's relevant.
|
|
732
|
+
event.preventDefault();
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
return true;
|
|
736
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(SELECT_ALL_COMMAND, () => {
|
|
737
|
+
$selectAll();
|
|
738
|
+
return true;
|
|
739
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(COPY_COMMAND, event => {
|
|
740
|
+
copyToClipboard(editor, objectKlassEquals(event, ClipboardEvent) ? event : null);
|
|
741
|
+
return true;
|
|
742
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CUT_COMMAND, event => {
|
|
743
|
+
onCutForRichText(event, editor);
|
|
744
|
+
return true;
|
|
745
|
+
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(PASTE_COMMAND, event => {
|
|
746
|
+
const [, files, hasTextContent] = eventFiles(event);
|
|
747
|
+
if (files.length > 0 && !hasTextContent) {
|
|
748
|
+
editor.dispatchCommand(DRAG_DROP_PASTE, files);
|
|
749
|
+
return true;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
// if inputs then paste within the input ignore creating a new node on paste event
|
|
753
|
+
if (isSelectionCapturedInDecoratorInput(event.target)) {
|
|
754
|
+
return false;
|
|
755
|
+
}
|
|
756
|
+
const selection = $getSelection();
|
|
757
|
+
if (selection !== null) {
|
|
758
|
+
onPasteForRichText(event, editor);
|
|
759
|
+
return true;
|
|
760
|
+
}
|
|
761
|
+
return false;
|
|
762
|
+
}, COMMAND_PRIORITY_EDITOR));
|
|
763
|
+
return removeListener;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
export { $createHeadingNode, $createQuoteNode, $isHeadingNode, $isQuoteNode, DRAG_DROP_PASTE, HeadingNode, QuoteNode, eventFiles, registerRichText };
|
package/LexicalRichText.dev.js
CHANGED
|
@@ -69,13 +69,14 @@ CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
|
69
69
|
const CAN_USE_BEFORE_INPUT = CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
|
|
70
70
|
const IS_SAFARI = CAN_USE_DOM && /Version\/[\d.]+.*Safari/.test(navigator.userAgent);
|
|
71
71
|
const IS_IOS = CAN_USE_DOM && /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
72
|
-
CAN_USE_DOM && /Android/.test(navigator.userAgent);
|
|
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
77
|
// export const canUseTextInputEvent: boolean = CAN_USE_DOM && 'TextEvent' in window && !documentMode;
|
|
78
78
|
|
|
79
|
+
CAN_USE_DOM && IS_ANDROID && IS_CHROME;
|
|
79
80
|
const IS_APPLE_WEBKIT = CAN_USE_DOM && /AppleWebKit\/[\d.]+/.test(navigator.userAgent) && !IS_CHROME;
|
|
80
81
|
|
|
81
82
|
/** @module @lexical/rich-text */
|
|
@@ -115,7 +116,9 @@ class QuoteNode extends lexical.ElementNode {
|
|
|
115
116
|
element
|
|
116
117
|
} = super.exportDOM(editor);
|
|
117
118
|
if (element && utils.isHTMLElement(element)) {
|
|
118
|
-
if (this.isEmpty())
|
|
119
|
+
if (this.isEmpty()) {
|
|
120
|
+
element.append(document.createElement('br'));
|
|
121
|
+
}
|
|
119
122
|
const formatType = this.getFormatType();
|
|
120
123
|
element.style.textAlign = formatType;
|
|
121
124
|
const direction = this.getDirection();
|
|
@@ -258,7 +261,9 @@ class HeadingNode extends lexical.ElementNode {
|
|
|
258
261
|
element
|
|
259
262
|
} = super.exportDOM(editor);
|
|
260
263
|
if (element && utils.isHTMLElement(element)) {
|
|
261
|
-
if (this.isEmpty())
|
|
264
|
+
if (this.isEmpty()) {
|
|
265
|
+
element.append(document.createElement('br'));
|
|
266
|
+
}
|
|
262
267
|
const formatType = this.getFormatType();
|
|
263
268
|
element.style.textAlign = formatType;
|
|
264
269
|
const direction = this.getDirection();
|
|
@@ -349,7 +354,7 @@ function onPasteForRichText(event, editor) {
|
|
|
349
354
|
event.preventDefault();
|
|
350
355
|
editor.update(() => {
|
|
351
356
|
const selection = lexical.$getSelection();
|
|
352
|
-
const clipboardData = event
|
|
357
|
+
const clipboardData = utils.objectKlassEquals(event, InputEvent) || utils.objectKlassEquals(event, KeyboardEvent) ? null : event.clipboardData;
|
|
353
358
|
if (clipboardData != null && selection !== null) {
|
|
354
359
|
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
355
360
|
}
|
|
@@ -374,9 +379,9 @@ async function onCutForRichText(event, editor) {
|
|
|
374
379
|
// control this with the first boolean flag.
|
|
375
380
|
function eventFiles(event) {
|
|
376
381
|
let dataTransfer = null;
|
|
377
|
-
if (event
|
|
382
|
+
if (utils.objectKlassEquals(event, DragEvent)) {
|
|
378
383
|
dataTransfer = event.dataTransfer;
|
|
379
|
-
} else if (event
|
|
384
|
+
} else if (utils.objectKlassEquals(event, ClipboardEvent)) {
|
|
380
385
|
dataTransfer = event.clipboardData;
|
|
381
386
|
}
|
|
382
387
|
if (dataTransfer === null) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import * as modDev from './LexicalRichText.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalRichText.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const $createHeadingNode = mod.$createHeadingNode;
|
|
11
|
+
export const $createQuoteNode = mod.$createQuoteNode;
|
|
12
|
+
export const $isHeadingNode = mod.$isHeadingNode;
|
|
13
|
+
export const $isQuoteNode = mod.$isQuoteNode;
|
|
14
|
+
export const DRAG_DROP_PASTE = mod.DRAG_DROP_PASTE;
|
|
15
|
+
export const HeadingNode = mod.HeadingNode;
|
|
16
|
+
export const QuoteNode = mod.QuoteNode;
|
|
17
|
+
export const eventFiles = mod.eventFiles;
|
|
18
|
+
export const registerRichText = mod.registerRichText;
|
package/LexicalRichText.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalRichText = process.env.NODE_ENV === 'development' ? require('./LexicalRichText.dev.js') : require('./LexicalRichText.prod.js')
|
|
8
|
+
const LexicalRichText = process.env.NODE_ENV === 'development' ? require('./LexicalRichText.dev.js') : require('./LexicalRichText.prod.js');
|
|
9
9
|
module.exports = LexicalRichText;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
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};
|
package/LexicalRichText.prod.js
CHANGED
|
@@ -5,28 +5,28 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'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;n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
9
|
-
n&&/
|
|
10
|
-
class
|
|
11
|
-
a}return{element:b}}static importJSON(b){let a=
|
|
12
|
-
class
|
|
13
|
-
priority:0}),h6:()=>({conversion:
|
|
14
|
-
a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(b,a=!0){let d=b?b.anchor.offset:0,e=d!==this.getTextContentSize()&&b?
|
|
15
|
-
b.append(a));this.replace(b);return!0}extractWithChild(){return!0}}function
|
|
16
|
-
function
|
|
17
|
-
function
|
|
18
|
-
function
|
|
19
|
-
exports.$isQuoteNode=function(b){return b instanceof
|
|
8
|
+
let n="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,p=n&&"documentMode"in document?document.documentMode:null;n&&/Mac|iPod|iPhone|iPad/.test(navigator.platform);n&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
|
|
9
|
+
let 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,u=n&&/Android/.test(navigator.userAgent),v=n&&/^(?=.*Chrome).*/i.test(navigator.userAgent);n&&u&&v;let w=n&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!v,x=k.createCommand("DRAG_DROP_PASTE_FILE");
|
|
10
|
+
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
|
+
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
|
+
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,
|
|
13
|
+
priority:0}),h6:()=>({conversion:D,priority:0}),p:b=>{b=b.firstChild;return null!==b&&E(b)?{conversion:()=>({node:null}),priority:3}:null},span:b=>E(b)?{conversion:()=>({node:F("h1")}),priority:3}:null}}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=a}return{element:b}}static importJSON(b){let a=F(b.tag);a.setFormat(b.format);a.setIndent(b.indent);
|
|
14
|
+
a.setDirection(b.direction);return a}exportJSON(){return{...super.exportJSON(),tag:this.getTag(),type:"heading",version:1}}insertNewAfter(b,a=!0){let d=b?b.anchor.offset:0,e=d!==this.getTextContentSize()&&b?F(this.getTag()):k.$createParagraphNode(),f=this.getDirection();e.setDirection(f);this.insertAfter(e,a);0===d&&!this.isEmpty()&&b&&(b=k.$createParagraphNode(),b.select(),this.replace(b,!0));return e}collapseAtStart(){let b=this.isEmpty()?k.$createParagraphNode():F(this.getTag());this.getChildren().forEach(a=>
|
|
15
|
+
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
|
+
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
|
+
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.$getNearestBlockElementAncestorOrThrow(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;exports.$isHeadingNode=function(b){return b instanceof C};
|
|
19
|
+
exports.$isQuoteNode=function(b){return b instanceof y};exports.DRAG_DROP_PASTE=x;exports.HeadingNode=C;exports.QuoteNode=y;exports.eventFiles=I;
|
|
20
20
|
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
21
|
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
22
|
()=>{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()),
|
|
23
23
|
null!==d&&d.setFormat(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_LINE_BREAK_COMMAND,a=>{const d=k.$getSelection();if(!k.$isRangeSelection(d))return!1;d.insertLineBreak(a);return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_PARAGRAPH_COMMAND,()=>{const a=k.$getSelection();if(!k.$isRangeSelection(a))return!1;a.insertParagraph();return!0},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.INSERT_TAB_COMMAND,()=>{k.$insertNodes([k.$createTabNode()]);return!0},k.COMMAND_PRIORITY_EDITOR),
|
|
24
|
-
b.registerCommand(k.INDENT_CONTENT_COMMAND,()=>
|
|
24
|
+
b.registerCommand(k.INDENT_CONTENT_COMMAND,()=>J(a=>{const d=a.getIndent();a.setIndent(d+1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.OUTDENT_CONTENT_COMMAND,()=>J(a=>{const d=a.getIndent();0<d&&a.setIndent(d-1)}),k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_UP_COMMAND,a=>{var d=k.$getSelection();if(k.$isNodeSelection(d)&&!K(a.target)){if(a=d.getNodes(),0<a.length)return a[0].selectPrevious(),!0}else if(k.$isRangeSelection(d)&&(d=k.$getAdjacentNode(d.focus,!0),!a.shiftKey&&k.$isDecoratorNode(d)&&
|
|
25
25
|
!d.isIsolated()&&!d.isInline()))return d.selectPrevious(),a.preventDefault(),!0;return!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_DOWN_COMMAND,a=>{var d=k.$getSelection();if(k.$isNodeSelection(d)){if(a=d.getNodes(),0<a.length)return a[0].selectNext(0,0),!0}else if(k.$isRangeSelection(d)){let e=d.focus;if("root"===e.key&&e.offset===k.$getRoot().getChildrenSize())return a.preventDefault(),!0;d=k.$getAdjacentNode(d.focus,!1);if(!a.shiftKey&&k.$isDecoratorNode(d)&&!d.isIsolated()&&!d.isInline())return d.selectNext(),
|
|
26
26
|
a.preventDefault(),!0}return!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_LEFT_COMMAND,a=>{const d=k.$getSelection();if(k.$isNodeSelection(d)){var e=d.getNodes();if(0<e.length)return a.preventDefault(),e[0].selectPrevious(),!0}return k.$isRangeSelection(d)?g.$shouldOverrideDefaultCharacterSelection(d,!0)?(e=a.shiftKey,a.preventDefault(),g.$moveCharacter(d,e,!0),!0):!1:!1},k.COMMAND_PRIORITY_EDITOR),b.registerCommand(k.KEY_ARROW_RIGHT_COMMAND,a=>{const d=k.$getSelection();if(k.$isNodeSelection(d)&&
|
|
27
|
-
!
|
|
28
|
-
!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(
|
|
29
|
-
if(!k.$isRangeSelection(d))return!1;if(null!==a){if((t||r||
|
|
30
|
-
if(null!==e){const {offset:m,node:
|
|
31
|
-
b.registerCommand(k.DRAGSTART_COMMAND,a=>{[a]=
|
|
32
|
-
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=>{
|
|
27
|
+
!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
|
+
!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
|
+
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:L}=e;var f=k.$getNearestNodeFromDOMNode(L);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
|
+
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
|
+
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/package.json
CHANGED
|
@@ -7,17 +7,19 @@
|
|
|
7
7
|
"rich-text"
|
|
8
8
|
],
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"version": "0.
|
|
10
|
+
"version": "0.14.2",
|
|
11
11
|
"main": "LexicalRichText.js",
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"lexical": "0.
|
|
14
|
-
"@lexical/selection": "0.
|
|
15
|
-
"@lexical/clipboard": "0.
|
|
16
|
-
"@lexical/utils": "0.
|
|
13
|
+
"lexical": "0.14.2",
|
|
14
|
+
"@lexical/selection": "0.14.2",
|
|
15
|
+
"@lexical/clipboard": "0.14.2",
|
|
16
|
+
"@lexical/utils": "0.14.2"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "https://github.com/facebook/lexical",
|
|
21
21
|
"directory": "packages/lexical-rich-text"
|
|
22
|
-
}
|
|
22
|
+
},
|
|
23
|
+
"module": "LexicalRichText.esm.js",
|
|
24
|
+
"sideEffects": false
|
|
23
25
|
}
|