@lexical/react 0.1.14 → 0.1.17
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/DEPRECATED_useLexicalAutoFormatter.dev.js +5 -741
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +1 -21
- package/DEPRECATED_useLexicalCanShowPlaceholder.dev.js +4 -73
- package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -2
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +19 -72
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +7 -8
- package/DEPRECATED_useLexicalDecorators.dev.js +1 -1
- package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.dev.js +1 -1
- package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +5 -307
- package/DEPRECATED_useLexicalHistory.prod.js +1 -7
- package/DEPRECATED_useLexicalList.dev.js +29 -25
- package/DEPRECATED_useLexicalList.prod.js +3 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +8 -687
- package/DEPRECATED_useLexicalPlainText.prod.js +2 -15
- package/DEPRECATED_useLexicalRichText.dev.js +8 -772
- package/DEPRECATED_useLexicalRichText.prod.js +2 -17
- package/LICENSE +1 -1
- package/{withSubscriptions.prod.js → LexicalAutoFocusPlugin.d.ts} +3 -1
- package/{withSubscriptions.dev.js → LexicalAutoFocusPlugin.dev.js} +10 -5
- package/LexicalAutoFocusPlugin.js +9 -0
- package/{LexicalAutoFormatterPlugin.js.flow → LexicalAutoFocusPlugin.js.flow} +1 -1
- package/LexicalAutoFocusPlugin.prod.js +7 -0
- package/LexicalAutoLinkPlugin.dev.js +12 -15
- package/LexicalAutoLinkPlugin.prod.js +6 -6
- package/LexicalAutoScrollPlugin.d.ts +13 -0
- package/LexicalAutoScrollPlugin.dev.js +82 -0
- package/LexicalAutoScrollPlugin.js +9 -0
- package/{withSubscriptions.d.ts → LexicalAutoScrollPlugin.js.flow} +5 -5
- package/LexicalAutoScrollPlugin.prod.js +8 -0
- package/LexicalCharacterLimitPlugin.dev.js +19 -72
- package/LexicalCharacterLimitPlugin.prod.js +8 -9
- package/LexicalClearEditorPlugin.dev.js +15 -19
- package/LexicalClearEditorPlugin.prod.js +1 -1
- package/LexicalCollaborationPlugin.d.ts +8 -3
- package/LexicalCollaborationPlugin.dev.js +70 -47
- package/LexicalCollaborationPlugin.js.flow +9 -3
- package/LexicalCollaborationPlugin.prod.js +10 -8
- package/LexicalComposer.d.ts +2 -2
- package/LexicalComposer.dev.js +3 -19
- package/LexicalComposer.js.flow +2 -2
- package/LexicalComposer.prod.js +2 -3
- package/LexicalContentEditable.dev.js +3 -1
- package/LexicalContentEditable.prod.js +2 -2
- package/LexicalHashtagPlugin.dev.js +21 -92
- package/LexicalHashtagPlugin.prod.js +4 -7
- package/LexicalHistoryPlugin.dev.js +5 -307
- package/LexicalHistoryPlugin.prod.js +1 -7
- package/LexicalHorizontalRuleNode.d.ts +3 -1
- package/LexicalHorizontalRuleNode.dev.js +2 -0
- package/LexicalHorizontalRuleNode.js.flow +6 -2
- package/LexicalHorizontalRuleNode.prod.js +2 -2
- package/LexicalLinkPlugin.dev.js +19 -20
- package/LexicalLinkPlugin.prod.js +4 -3
- package/LexicalListPlugin.dev.js +29 -25
- package/LexicalListPlugin.prod.js +3 -2
- package/{LexicalAutoFormatterPlugin.d.ts → LexicalMarkdownShortcutPlugin.d.ts} +1 -1
- package/LexicalMarkdownShortcutPlugin.dev.js +42 -0
- package/LexicalMarkdownShortcutPlugin.js +9 -0
- package/{withSubscriptions.js.flow → LexicalMarkdownShortcutPlugin.js.flow} +1 -4
- package/LexicalMarkdownShortcutPlugin.prod.js +7 -0
- package/LexicalNestedComposer.dev.js +20 -15
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.dev.js +16 -3
- package/LexicalOnChangePlugin.prod.js +2 -1
- package/LexicalPlainTextPlugin.dev.js +9 -455
- package/LexicalPlainTextPlugin.prod.js +4 -12
- package/LexicalRichTextPlugin.dev.js +9 -540
- package/LexicalRichTextPlugin.prod.js +4 -13
- package/LexicalTablePlugin.dev.js +36 -35
- package/LexicalTablePlugin.prod.js +3 -3
- package/LexicalTreeView.dev.js +1 -1
- package/LexicalTreeView.prod.js +1 -1
- package/package.json +17 -11
- package/useLexicalIsTextContentEmpty.dev.js +4 -33
- package/useLexicalIsTextContentEmpty.prod.js +1 -2
- package/useLexicalNodeSelection.dev.js +1 -1
- package/useLexicalNodeSelection.prod.js +1 -1
- package/useLexicalTextEntity.d.ts +19 -0
- package/useLexicalTextEntity.dev.js +29 -0
- package/{withSubscriptions.js → useLexicalTextEntity.js} +2 -2
- package/useLexicalTextEntity.js.flow +18 -0
- package/useLexicalTextEntity.prod.js +7 -0
- package/LexicalAutoFormatterPlugin.dev.js +0 -778
- package/LexicalAutoFormatterPlugin.js +0 -9
- package/LexicalAutoFormatterPlugin.prod.js +0 -27
|
@@ -8,78 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
10
|
var React = require('react');
|
|
11
|
-
var
|
|
11
|
+
var text = require('@lexical/text');
|
|
12
12
|
var reactDom = require('react-dom');
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
17
|
-
*
|
|
18
|
-
* This source code is licensed under the MIT license found in the
|
|
19
|
-
* LICENSE file in the root directory of this source tree.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*/
|
|
23
|
-
function $textContent() {
|
|
24
|
-
const root = lexical.$getRoot();
|
|
25
|
-
return root.getTextContent();
|
|
26
|
-
}
|
|
27
|
-
function $isTextContentEmpty(isEditorComposing, trim = true) {
|
|
28
|
-
if (isEditorComposing) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let text = $textContent();
|
|
33
|
-
|
|
34
|
-
if (trim) {
|
|
35
|
-
text = text.trim();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return text === '';
|
|
39
|
-
}
|
|
40
|
-
function $canShowPlaceholder(isComposing) {
|
|
41
|
-
if (!$isTextContentEmpty(isComposing, false)) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const root = lexical.$getRoot();
|
|
46
|
-
const children = root.getChildren();
|
|
47
|
-
const childrenLength = children.length;
|
|
48
|
-
|
|
49
|
-
if (childrenLength > 1) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < childrenLength; i++) {
|
|
54
|
-
const topBlock = children[i];
|
|
55
|
-
|
|
56
|
-
if (lexical.$isElementNode(topBlock)) {
|
|
57
|
-
if (topBlock.__type !== 'paragraph') {
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (topBlock.__indent !== 0) {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const topBlockChildren = topBlock.getChildren();
|
|
66
|
-
const topBlockChildrenLength = topBlockChildren.length;
|
|
67
|
-
|
|
68
|
-
for (let s = 0; s < topBlockChildrenLength; s++) {
|
|
69
|
-
const child = topBlockChildren[i];
|
|
70
|
-
|
|
71
|
-
if (!lexical.$isTextNode(child)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
function $canShowPlaceholderCurry(isEditorComposing) {
|
|
81
|
-
return () => $canShowPlaceholder(isEditorComposing);
|
|
82
|
-
}
|
|
13
|
+
var dragon = require('@lexical/dragon');
|
|
14
|
+
var richText = require('@lexical/rich-text');
|
|
15
|
+
var utils = require('@lexical/utils');
|
|
83
16
|
|
|
84
17
|
/**
|
|
85
18
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -111,13 +44,13 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
111
44
|
*
|
|
112
45
|
*/
|
|
113
46
|
function useLexicalCanShowPlaceholder(editor) {
|
|
114
|
-
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(
|
|
47
|
+
const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing())));
|
|
115
48
|
useLayoutEffect(() => {
|
|
116
|
-
return editor.
|
|
49
|
+
return editor.registerUpdateListener(({
|
|
117
50
|
editorState
|
|
118
51
|
}) => {
|
|
119
52
|
const isComposing = editor.isComposing();
|
|
120
|
-
const currentCanShowPlaceholder = editorState.read(
|
|
53
|
+
const currentCanShowPlaceholder = editorState.read(text.$canShowPlaceholderCurry(isComposing));
|
|
121
54
|
setCanShowPlaceholder(currentCanShowPlaceholder);
|
|
122
55
|
});
|
|
123
56
|
}, [editor]);
|
|
@@ -136,7 +69,7 @@ function useDecorators(editor) {
|
|
|
136
69
|
const [decorators, setDecorators] = React.useState(() => editor.getDecorators()); // Subscribe to changes
|
|
137
70
|
|
|
138
71
|
useLayoutEffect(() => {
|
|
139
|
-
return editor.
|
|
72
|
+
return editor.registerDecoratorListener(nextDecorators => {
|
|
140
73
|
reactDom.flushSync(() => {
|
|
141
74
|
setDecorators(nextDecorators);
|
|
142
75
|
});
|
|
@@ -161,230 +94,6 @@ function useDecorators(editor) {
|
|
|
161
94
|
}, [decorators, editor]);
|
|
162
95
|
}
|
|
163
96
|
|
|
164
|
-
/**
|
|
165
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
166
|
-
*
|
|
167
|
-
* This source code is licensed under the MIT license found in the
|
|
168
|
-
* LICENSE file in the root directory of this source tree.
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*/
|
|
172
|
-
|
|
173
|
-
function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
|
|
174
|
-
selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
|
|
175
|
-
}
|
|
176
|
-
function $isParentElementRTL(selection) {
|
|
177
|
-
const anchorNode = selection.anchor.getNode();
|
|
178
|
-
const parent = lexical.$isRootNode(anchorNode) ? anchorNode : anchorNode.getParentOrThrow();
|
|
179
|
-
return parent.getDirection() === 'rtl';
|
|
180
|
-
}
|
|
181
|
-
function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
182
|
-
const isRTL = $isParentElementRTL(selection);
|
|
183
|
-
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
184
|
-
}
|
|
185
|
-
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
186
|
-
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
187
|
-
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
192
|
-
*
|
|
193
|
-
* This source code is licensed under the MIT license found in the
|
|
194
|
-
* LICENSE file in the root directory of this source tree.
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*/
|
|
198
|
-
function onCutForRichText(event, editor) {
|
|
199
|
-
onCopyForRichText(event, editor);
|
|
200
|
-
editor.update(() => {
|
|
201
|
-
const selection = lexical.$getSelection();
|
|
202
|
-
|
|
203
|
-
if (lexical.$isRangeSelection(selection)) {
|
|
204
|
-
selection.removeText();
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
function onCopyForRichText(event, editor) {
|
|
209
|
-
event.preventDefault();
|
|
210
|
-
editor.update(() => {
|
|
211
|
-
const clipboardData = event.clipboardData;
|
|
212
|
-
const selection = lexical.$getSelection();
|
|
213
|
-
|
|
214
|
-
if (selection !== null) {
|
|
215
|
-
if (clipboardData != null) {
|
|
216
|
-
const htmlString = clipboard.getHtmlContent(editor);
|
|
217
|
-
const lexicalString = clipboard.$getLexicalContent(editor);
|
|
218
|
-
|
|
219
|
-
if (htmlString !== null) {
|
|
220
|
-
clipboardData.setData('text/html', htmlString);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (lexicalString !== null) {
|
|
224
|
-
clipboardData.setData('application/x-lexical-editor', lexicalString);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
clipboardData.setData('text/plain', selection.getTextContent());
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
function onPasteForRichText(event, editor) {
|
|
233
|
-
event.preventDefault();
|
|
234
|
-
editor.update(() => {
|
|
235
|
-
const selection = lexical.$getSelection();
|
|
236
|
-
const clipboardData = event.clipboardData;
|
|
237
|
-
|
|
238
|
-
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
239
|
-
clipboard.$insertDataTransferForRichText(clipboardData, selection, editor);
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
246
|
-
*
|
|
247
|
-
* This source code is licensed under the MIT license found in the
|
|
248
|
-
* LICENSE file in the root directory of this source tree.
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
// Convoluted logic to make this work with Flow. Order matters.
|
|
253
|
-
const options = {
|
|
254
|
-
tag: 'history-merge'
|
|
255
|
-
};
|
|
256
|
-
const setEditorOptions = options;
|
|
257
|
-
const updateOptions = options;
|
|
258
|
-
function initializeEditor(editor, initialEditorState) {
|
|
259
|
-
if (initialEditorState === null) {
|
|
260
|
-
return;
|
|
261
|
-
} else if (initialEditorState === undefined) {
|
|
262
|
-
editor.update(() => {
|
|
263
|
-
const root = lexical.$getRoot();
|
|
264
|
-
const firstChild = root.getFirstChild();
|
|
265
|
-
|
|
266
|
-
if (firstChild === null) {
|
|
267
|
-
const paragraph = lexical.$createParagraphNode();
|
|
268
|
-
root.append(paragraph);
|
|
269
|
-
const activeElement = document.activeElement;
|
|
270
|
-
|
|
271
|
-
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
272
|
-
paragraph.select();
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}, updateOptions);
|
|
276
|
-
} else if (initialEditorState !== null) {
|
|
277
|
-
switch (typeof initialEditorState) {
|
|
278
|
-
case 'string':
|
|
279
|
-
{
|
|
280
|
-
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
281
|
-
editor.setEditorState(parsedEditorState, setEditorOptions);
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
case 'object':
|
|
286
|
-
{
|
|
287
|
-
editor.setEditorState(initialEditorState, setEditorOptions);
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
case 'function':
|
|
292
|
-
{
|
|
293
|
-
editor.update(initialEditorState, updateOptions);
|
|
294
|
-
break;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
302
|
-
*
|
|
303
|
-
* This source code is licensed under the MIT license found in the
|
|
304
|
-
* LICENSE file in the root directory of this source tree.
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*/
|
|
308
|
-
function useLexicalDragonSupport(editor) {
|
|
309
|
-
React.useEffect(() => {
|
|
310
|
-
const handler = event => {
|
|
311
|
-
const rootElement = editor.getRootElement();
|
|
312
|
-
|
|
313
|
-
if (document.activeElement !== rootElement) {
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
const data = event.data;
|
|
318
|
-
|
|
319
|
-
if (typeof data === 'string') {
|
|
320
|
-
let parsedData;
|
|
321
|
-
|
|
322
|
-
try {
|
|
323
|
-
parsedData = JSON.parse(data);
|
|
324
|
-
} catch (e) {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
if (parsedData && parsedData.protocol === 'nuanria_messaging' && parsedData.type === 'request') {
|
|
329
|
-
const payload = parsedData.payload;
|
|
330
|
-
|
|
331
|
-
if (payload && payload.functionId === 'makeChanges') {
|
|
332
|
-
const args = payload.args;
|
|
333
|
-
|
|
334
|
-
if (args) {
|
|
335
|
-
const [elementStart, elementLength, text, selStart, selLength, formatCommand] = args; // TODO: we should probably handle formatCommand somehow?
|
|
336
|
-
editor.update(() => {
|
|
337
|
-
const selection = lexical.$getSelection();
|
|
338
|
-
|
|
339
|
-
if (lexical.$isRangeSelection(selection)) {
|
|
340
|
-
const anchor = selection.anchor;
|
|
341
|
-
let anchorNode = anchor.getNode();
|
|
342
|
-
let setSelStart = 0;
|
|
343
|
-
let setSelEnd = 0;
|
|
344
|
-
|
|
345
|
-
if (lexical.$isTextNode(anchorNode)) {
|
|
346
|
-
// set initial selection
|
|
347
|
-
if (elementStart >= 0 && elementLength >= 0) {
|
|
348
|
-
setSelStart = elementStart;
|
|
349
|
-
setSelEnd = elementStart + elementLength; // If the offset is more than the end, make it the end
|
|
350
|
-
|
|
351
|
-
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
if (setSelStart !== setSelEnd || text !== '') {
|
|
356
|
-
selection.insertRawText(text);
|
|
357
|
-
anchorNode = anchor.getNode();
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (lexical.$isTextNode(anchorNode)) {
|
|
361
|
-
// set final selection
|
|
362
|
-
setSelStart = selStart;
|
|
363
|
-
setSelEnd = selStart + selLength;
|
|
364
|
-
const anchorNodeTextLength = anchorNode.getTextContentSize(); // If the offset is more than the end, make it the end
|
|
365
|
-
|
|
366
|
-
setSelStart = setSelStart > anchorNodeTextLength ? anchorNodeTextLength : setSelStart;
|
|
367
|
-
setSelEnd = setSelEnd > anchorNodeTextLength ? anchorNodeTextLength : setSelEnd;
|
|
368
|
-
selection.setTextNodeRange(anchorNode, setSelStart, anchorNode, setSelEnd);
|
|
369
|
-
} // block the chrome extension from handling this event
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
event.stopImmediatePropagation();
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
window.addEventListener('message', handler, true);
|
|
382
|
-
return () => {
|
|
383
|
-
window.removeEventListener('message', handler, true);
|
|
384
|
-
};
|
|
385
|
-
}, [editor]);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
97
|
/**
|
|
389
98
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
390
99
|
*
|
|
@@ -395,249 +104,9 @@ function useLexicalDragonSupport(editor) {
|
|
|
395
104
|
*/
|
|
396
105
|
function useRichTextSetup(editor, initialEditorState) {
|
|
397
106
|
useLayoutEffect(() => {
|
|
398
|
-
|
|
399
|
-
const selection = lexical.$getSelection();
|
|
400
|
-
|
|
401
|
-
if (type === 'click' && lexical.$isNodeSelection(selection)) {
|
|
402
|
-
selection.clear();
|
|
403
|
-
return true;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
if (!lexical.$isRangeSelection(selection)) {
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
switch (type) {
|
|
411
|
-
case 'deleteCharacter':
|
|
412
|
-
{
|
|
413
|
-
const isBackward = payload;
|
|
414
|
-
selection.deleteCharacter(isBackward);
|
|
415
|
-
return true;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
case 'deleteWord':
|
|
419
|
-
{
|
|
420
|
-
const isBackward = payload;
|
|
421
|
-
selection.deleteWord(isBackward);
|
|
422
|
-
return true;
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
case 'deleteLine':
|
|
426
|
-
{
|
|
427
|
-
const isBackward = payload;
|
|
428
|
-
selection.deleteLine(isBackward);
|
|
429
|
-
return true;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
case 'insertText':
|
|
433
|
-
{
|
|
434
|
-
const eventOrText = payload;
|
|
435
|
-
|
|
436
|
-
if (typeof eventOrText === 'string') {
|
|
437
|
-
selection.insertText(eventOrText);
|
|
438
|
-
} else {
|
|
439
|
-
const dataTransfer = eventOrText.dataTransfer;
|
|
440
|
-
|
|
441
|
-
if (dataTransfer != null) {
|
|
442
|
-
clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
|
|
443
|
-
} else {
|
|
444
|
-
const data = eventOrText.data;
|
|
445
|
-
|
|
446
|
-
if (data) {
|
|
447
|
-
selection.insertText(data);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
case 'removeText':
|
|
456
|
-
selection.removeText();
|
|
457
|
-
return true;
|
|
458
|
-
|
|
459
|
-
case 'formatText':
|
|
460
|
-
{
|
|
461
|
-
const format = payload;
|
|
462
|
-
selection.formatText(format);
|
|
463
|
-
return true;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
case 'formatElement':
|
|
467
|
-
{
|
|
468
|
-
const format = payload;
|
|
469
|
-
const node = selection.anchor.getNode();
|
|
470
|
-
const element = lexical.$isElementNode(node) ? node : node.getParentOrThrow();
|
|
471
|
-
element.setFormat(format);
|
|
472
|
-
return true;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
case 'insertLineBreak':
|
|
476
|
-
const selectStart = payload;
|
|
477
|
-
selection.insertLineBreak(selectStart);
|
|
478
|
-
return true;
|
|
479
|
-
|
|
480
|
-
case 'insertParagraph':
|
|
481
|
-
selection.insertParagraph();
|
|
482
|
-
return true;
|
|
483
|
-
|
|
484
|
-
case 'indentContent':
|
|
485
|
-
{
|
|
486
|
-
// Handle code blocks
|
|
487
|
-
const anchor = selection.anchor;
|
|
488
|
-
const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
|
|
489
|
-
|
|
490
|
-
if (parentBlock.canInsertTab()) {
|
|
491
|
-
editor.execCommand('insertText', '\t');
|
|
492
|
-
} else {
|
|
493
|
-
if (parentBlock.getIndent() !== 10) {
|
|
494
|
-
parentBlock.setIndent(parentBlock.getIndent() + 1);
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return true;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
case 'outdentContent':
|
|
502
|
-
{
|
|
503
|
-
// Handle code blocks
|
|
504
|
-
const anchor = selection.anchor;
|
|
505
|
-
const anchorNode = anchor.getNode();
|
|
506
|
-
const parentBlock = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
|
|
507
|
-
|
|
508
|
-
if (parentBlock.canInsertTab()) {
|
|
509
|
-
const textContent = anchorNode.getTextContent();
|
|
510
|
-
const character = textContent[anchor.offset - 1];
|
|
511
|
-
|
|
512
|
-
if (character === '\t') {
|
|
513
|
-
editor.execCommand('deleteCharacter', true);
|
|
514
|
-
}
|
|
515
|
-
} else {
|
|
516
|
-
if (parentBlock.getIndent() !== 0) {
|
|
517
|
-
parentBlock.setIndent(parentBlock.getIndent() - 1);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
case 'keyArrowLeft':
|
|
525
|
-
{
|
|
526
|
-
const event = payload;
|
|
527
|
-
const isHoldingShift = event.shiftKey;
|
|
528
|
-
|
|
529
|
-
if ($shouldOverrideDefaultCharacterSelection(selection, true)) {
|
|
530
|
-
event.preventDefault();
|
|
531
|
-
$moveCharacter(selection, isHoldingShift, true);
|
|
532
|
-
return true;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
return false;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
case 'keyArrowRight':
|
|
539
|
-
{
|
|
540
|
-
const event = payload;
|
|
541
|
-
const isHoldingShift = event.shiftKey;
|
|
542
|
-
|
|
543
|
-
if ($shouldOverrideDefaultCharacterSelection(selection, false)) {
|
|
544
|
-
event.preventDefault();
|
|
545
|
-
$moveCharacter(selection, isHoldingShift, false);
|
|
546
|
-
return true;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
return false;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
case 'keyBackspace':
|
|
553
|
-
{
|
|
554
|
-
const event = payload;
|
|
555
|
-
event.preventDefault();
|
|
556
|
-
const {
|
|
557
|
-
anchor
|
|
558
|
-
} = selection;
|
|
559
|
-
|
|
560
|
-
if (selection.isCollapsed() && anchor.offset === 0) {
|
|
561
|
-
const element = anchor.type === 'element' ? anchor.getNode() : anchor.getNode().getParentOrThrow();
|
|
562
|
-
|
|
563
|
-
if (element.getIndent() > 0) {
|
|
564
|
-
return editor.execCommand('outdentContent');
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return editor.execCommand('deleteCharacter', true);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
case 'keyDelete':
|
|
572
|
-
{
|
|
573
|
-
const event = payload;
|
|
574
|
-
event.preventDefault();
|
|
575
|
-
return editor.execCommand('deleteCharacter', false);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
case 'keyEnter':
|
|
579
|
-
{
|
|
580
|
-
const event = payload;
|
|
581
|
-
event.preventDefault();
|
|
582
|
-
|
|
583
|
-
if (event.shiftKey) {
|
|
584
|
-
return editor.execCommand('insertLineBreak');
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
return editor.execCommand('insertParagraph');
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
case 'keyTab':
|
|
591
|
-
{
|
|
592
|
-
const event = payload;
|
|
593
|
-
event.preventDefault();
|
|
594
|
-
return editor.execCommand(event.shiftKey ? 'outdentContent' : 'indentContent');
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
case 'keyEscape':
|
|
598
|
-
{
|
|
599
|
-
editor.blur();
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
case 'copy':
|
|
604
|
-
{
|
|
605
|
-
const event = payload;
|
|
606
|
-
onCopyForRichText(event, editor);
|
|
607
|
-
return true;
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
case 'cut':
|
|
611
|
-
{
|
|
612
|
-
const event = payload;
|
|
613
|
-
onCutForRichText(event, editor);
|
|
614
|
-
return true;
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
case 'paste':
|
|
618
|
-
{
|
|
619
|
-
const event = payload;
|
|
620
|
-
onPasteForRichText(event, editor);
|
|
621
|
-
return true;
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
case 'drop':
|
|
625
|
-
case 'dragstart':
|
|
626
|
-
{
|
|
627
|
-
// TODO: Make drag and drop work at some point.
|
|
628
|
-
const event = payload;
|
|
629
|
-
event.preventDefault();
|
|
630
|
-
return true;
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
return false;
|
|
635
|
-
}, 0);
|
|
636
|
-
initializeEditor(editor, initialEditorState);
|
|
637
|
-
return removeListener; // We only do this for init
|
|
107
|
+
return utils.mergeRegister(richText.registerRichText(editor, initialEditorState), dragon.registerDragonSupport(editor)); // We only do this for init
|
|
638
108
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
639
109
|
}, [editor]);
|
|
640
|
-
useLexicalDragonSupport(editor);
|
|
641
110
|
}
|
|
642
111
|
|
|
643
112
|
/**
|
|
@@ -4,16 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function G(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData,d=r.$getSelection();if(null!==d&&null!=f){const c=v.getHtmlContent(e),b=v.$getLexicalContent(e);null!==c&&f.setData("text/html",c);null!==b&&f.setData("application/x-lexical-editor",b);f.setData("text/plain",d.getTextContent())}})}function H(a,e){a.preventDefault();e.update(()=>{const f=r.$getSelection(),d=a.clipboardData;null!=d&&r.$isRangeSelection(f)&&v.$insertDataTransferForRichText(d,f,e)})}const I={tag:"history-merge"};
|
|
12
|
-
function J(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=r.$getRoot();if(null===f.getFirstChild()){const d=r.$createParagraphNode();f.append(d);f=document.activeElement;(null!==r.$getSelection()||null!==f&&f===a.getRootElement())&&d.select()}},I);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,I);break;case "object":a.setEditorState(e,I);break;case "function":a.update(e,I)}}
|
|
13
|
-
function K(a){h.useEffect(()=>{const e=f=>{var d=a.getRootElement();if(document.activeElement===d&&(d=f.data,"string"===typeof d)){try{var c=JSON.parse(d)}catch(b){return}if(c&&"nuanria_messaging"===c.protocol&&"request"===c.type&&(c=c.payload)&&"makeChanges"===c.functionId&&(c=c.args)){const [b,p,t,B,L]=c;a.update(()=>{const q=r.$getSelection();if(r.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;r.$isTextNode(k)&&0<=b&&0<=p&&(l=b,m=b+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
|
|
14
|
-
t)q.insertRawText(t),k=n.getNode();r.$isTextNode(k)&&(l=B,m=B+L,n=k.getTextContentSize(),l=l>n?n:l,m=m>n?n:m,q.setTextNodeRange(k,l,k,m));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
|
|
15
|
-
function M(a,e){z(()=>{const f=a.addListener("command",(d,c)=>{var b=r.$getSelection();if("click"===d&&r.$isNodeSelection(b))return b.clear(),!0;if(!r.$isRangeSelection(b))return!1;switch(d){case "deleteCharacter":return b.deleteCharacter(c),!0;case "deleteWord":return b.deleteWord(c),!0;case "deleteLine":return b.deleteLine(c),!0;case "insertText":return"string"===typeof c?b.insertText(c):(d=c.dataTransfer,null!=d?v.$insertDataTransferForRichText(d,b,a):(c=c.data)&&b.insertText(c)),!0;case "removeText":return b.removeText(),
|
|
16
|
-
!0;case "formatText":return b.formatText(c),!0;case "formatElement":return b=b.anchor.getNode(),(r.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(c),!0;case "insertLineBreak":return b.insertLineBreak(c),!0;case "insertParagraph":return b.insertParagraph(),!0;case "indentContent":return b=b.anchor,b="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),b.canInsertTab()?a.execCommand("insertText","\t"):10!==b.getIndent()&&b.setIndent(b.getIndent()+1),!0;case "outdentContent":return b=b.anchor,
|
|
17
|
-
c=b.getNode(),d="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),d.canInsertTab()?"\t"===c.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==d.getIndent()&&d.setIndent(d.getIndent()-1),!0;case "keyArrowLeft":d=c.shiftKey;if(E(b,!0))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",!d,"character"),!0;break;case "keyArrowRight":d=c.shiftKey;if(E(b,!1))return c.preventDefault(),c=d,d=D(b),b.modify(c?"extend":"move",d,"character"),!0;break;case "keyBackspace":return c.preventDefault(),
|
|
18
|
-
{anchor:c}=b,b.isCollapsed()&&0===c.offset&&0<("element"===c.type?c.getNode():c.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return c.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return c.preventDefault(),c.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return c.preventDefault(),a.execCommand(c.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
|
|
19
|
-
!0;case "copy":return G(c,a),!0;case "cut":return F(c,a),!0;case "paste":return H(c,a),!0;case "drop":case "dragstart":return c.preventDefault(),!0}return!1},0);J(a,e);return f},[a]);K(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [d]=g.useLexicalComposerContext(),c=A(d);M(d,f);f=C(d);return h.createElement(h.Fragment,null,a,c&&e,f)};
|
|
7
|
+
var d=require("@lexical/react/LexicalComposerContext"),h=require("react"),l=require("@lexical/text"),m=require("react-dom"),n=require("@lexical/dragon"),p=require("@lexical/rich-text"),q=require("@lexical/utils"),r="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
8
|
+
function t(a){const [c,e]=h.useState(a.getEditorState().read(l.$canShowPlaceholderCurry(a.isComposing())));r(()=>a.registerUpdateListener(({editorState:b})=>{const f=a.isComposing();b=b.read(l.$canShowPlaceholderCurry(f));e(b)}),[a]);return c}
|
|
9
|
+
function u(a){const [c,e]=h.useState(()=>a.getDecorators());r(()=>a.registerDecoratorListener(b=>{m.flushSync(()=>{e(b)})}),[a]);return h.useMemo(()=>{const b=[],f=Object.keys(c);for(let k=0;k<f.length;k++){var g=f[k];const v=c[g];g=a.getElementByKey(g);null!==g&&b.push(m.createPortal(v,g))}return b},[c,a])}function w(a,c){r(()=>q.mergeRegister(p.registerRichText(a,c),n.registerDragonSupport(a)),[a])}
|
|
10
|
+
module.exports=function({contentEditable:a,placeholder:c,initialEditorState:e}){const [b]=d.useLexicalComposerContext(),f=t(b);w(b,e);e=u(b);return h.createElement(h.Fragment,null,a,f&&c,e)};
|