@lexical/react 0.1.9 → 0.1.12
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_useLexical.dev.js +5 -44
- package/DEPRECATED_useLexical.prod.js +1 -2
- package/DEPRECATED_useLexicalAutoFormatter.dev.js +87 -41
- package/DEPRECATED_useLexicalAutoFormatter.prod.js +20 -18
- package/DEPRECATED_useLexicalCharacterLimit.dev.js +22 -19
- package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
- package/DEPRECATED_useLexicalEditor.dev.js +1 -25
- package/DEPRECATED_useLexicalEditor.prod.js +1 -1
- package/DEPRECATED_useLexicalHistory.dev.js +1 -1
- package/DEPRECATED_useLexicalHistory.prod.js +2 -2
- package/DEPRECATED_useLexicalList.dev.js +6 -0
- package/DEPRECATED_useLexicalList.prod.js +1 -1
- package/DEPRECATED_useLexicalPlainText.dev.js +81 -89
- package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
- package/DEPRECATED_useLexicalRichText.dev.js +98 -592
- package/DEPRECATED_useLexicalRichText.prod.js +17 -29
- package/LexicalAutoFormatterPlugin.d.ts +9 -0
- package/LexicalAutoFormatterPlugin.dev.js +87 -41
- package/LexicalAutoFormatterPlugin.js.flow +10 -0
- package/LexicalAutoFormatterPlugin.prod.js +21 -19
- package/LexicalAutoLinkPlugin.d.ts +20 -0
- package/LexicalAutoLinkPlugin.js.flow +23 -0
- package/LexicalCharacterLimitPlugin.d.ts +11 -0
- package/LexicalCharacterLimitPlugin.dev.js +22 -19
- package/LexicalCharacterLimitPlugin.js.flow +12 -0
- package/LexicalCharacterLimitPlugin.prod.js +9 -8
- package/LexicalClearEditorPlugin.d.ts +14 -0
- package/LexicalClearEditorPlugin.dev.js +73 -0
- package/LexicalClearEditorPlugin.js +9 -0
- package/LexicalClearEditorPlugin.js.flow +14 -0
- package/LexicalClearEditorPlugin.prod.js +8 -0
- package/LexicalCollaborationPlugin.d.ts +49 -0
- package/LexicalCollaborationPlugin.dev.js +21 -11
- package/LexicalCollaborationPlugin.js.flow +55 -0
- package/LexicalCollaborationPlugin.prod.js +7 -7
- package/LexicalComposer.d.ts +22 -0
- package/LexicalComposer.dev.js +29 -5
- package/LexicalComposer.js.flow +24 -0
- package/LexicalComposer.prod.js +3 -3
- package/LexicalComposerContext.d.ts +24 -0
- package/LexicalComposerContext.js.flow +27 -0
- package/LexicalContentEditable.d.ts +32 -0
- package/LexicalContentEditable.dev.js +35 -8
- package/LexicalContentEditable.js.flow +35 -0
- package/LexicalContentEditable.prod.js +3 -3
- package/LexicalHashtagPlugin.d.ts +9 -0
- package/LexicalHashtagPlugin.js.flow +10 -0
- package/LexicalHistoryPlugin.d.ts +29 -0
- package/LexicalHistoryPlugin.dev.js +1 -1
- package/LexicalHistoryPlugin.js.flow +34 -0
- package/LexicalHistoryPlugin.prod.js +2 -2
- package/LexicalHorizontalRuleNode.d.ts +23 -0
- package/LexicalHorizontalRuleNode.js.flow +25 -0
- package/LexicalLinkPlugin.d.ts +9 -0
- package/LexicalLinkPlugin.js.flow +10 -0
- package/LexicalListPlugin.d.ts +9 -0
- package/LexicalListPlugin.dev.js +6 -0
- package/LexicalListPlugin.js.flow +10 -0
- package/LexicalListPlugin.prod.js +2 -2
- package/LexicalNestedComposer.d.ts +20 -0
- package/LexicalNestedComposer.js.flow +21 -0
- package/LexicalOnChangePlugin.d.ts +12 -0
- package/LexicalOnChangePlugin.js.flow +14 -0
- package/LexicalPlainTextPlugin.d.ts +15 -0
- package/LexicalPlainTextPlugin.dev.js +77 -84
- package/LexicalPlainTextPlugin.js.flow +18 -0
- package/LexicalPlainTextPlugin.prod.js +12 -12
- package/LexicalRichTextPlugin.d.ts +15 -0
- package/LexicalRichTextPlugin.dev.js +93 -586
- package/LexicalRichTextPlugin.js.flow +18 -0
- package/LexicalRichTextPlugin.prod.js +13 -25
- package/LexicalTablePlugin.d.ts +9 -0
- package/LexicalTablePlugin.dev.js +23 -1
- package/LexicalTablePlugin.js.flow +10 -0
- package/LexicalTablePlugin.prod.js +4 -3
- package/LexicalTreeView.d.ts +17 -0
- package/LexicalTreeView.dev.js +10 -2
- package/LexicalTreeView.js.flow +19 -0
- package/LexicalTreeView.prod.js +9 -8
- package/README.md +0 -1
- package/package.json +6 -5
- package/useLexicalDecoratorMap.d.ts +14 -0
- package/useLexicalDecoratorMap.js.flow +16 -0
- package/useLexicalIsTextContentEmpty.d.ts +13 -0
- package/useLexicalIsTextContentEmpty.js.flow +15 -0
- package/useLexicalNodeSelection.d.ts +12 -0
- package/useLexicalNodeSelection.dev.js +70 -0
- package/useLexicalNodeSelection.js +9 -0
- package/useLexicalNodeSelection.js.flow +14 -0
- package/useLexicalNodeSelection.prod.js +8 -0
- package/withSubscriptions.d.ts +12 -0
- package/withSubscriptions.js.flow +13 -0
- package/LexicalBootstrapPlugin.dev.js +0 -122
- package/LexicalBootstrapPlugin.js +0 -9
- package/LexicalBootstrapPlugin.prod.js +0 -8
|
@@ -10,6 +10,7 @@ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var lexical = require('lexical');
|
|
12
12
|
var reactDom = require('react-dom');
|
|
13
|
+
var clipboard = require('@lexical/clipboard');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -181,54 +182,9 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
|
|
|
181
182
|
const isRTL = $isParentElementRTL(selection);
|
|
182
183
|
$moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
|
|
183
184
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*
|
|
188
|
-
* This source code is licensed under the MIT license found in the
|
|
189
|
-
* LICENSE file in the root directory of this source tree.
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
function resolveElement(element, isBackward, focusOffset) {
|
|
194
|
-
const parent = element.getParent();
|
|
195
|
-
let offset = focusOffset;
|
|
196
|
-
let block = element;
|
|
197
|
-
|
|
198
|
-
if (parent !== null) {
|
|
199
|
-
if (isBackward && focusOffset === 0) {
|
|
200
|
-
offset = block.getIndexWithinParent();
|
|
201
|
-
block = parent;
|
|
202
|
-
} else if (!isBackward && focusOffset === block.getChildrenSize()) {
|
|
203
|
-
offset = block.getIndexWithinParent() + 1;
|
|
204
|
-
block = parent;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return block.getChildAtIndex(isBackward ? offset - 1 : offset);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function getPossibleDecoratorNode(focus, isBackward) {
|
|
212
|
-
const focusOffset = focus.offset;
|
|
213
|
-
|
|
214
|
-
if (focus.type === 'element') {
|
|
215
|
-
const block = focus.getNode();
|
|
216
|
-
return resolveElement(block, isBackward, focusOffset);
|
|
217
|
-
} else {
|
|
218
|
-
const focusNode = focus.getNode();
|
|
219
|
-
|
|
220
|
-
if (isBackward && focusOffset === 0 || !isBackward && focusOffset === focusNode.getTextContentSize()) {
|
|
221
|
-
const possibleNode = isBackward ? focusNode.getPreviousSibling() : focusNode.getNextSibling();
|
|
222
|
-
|
|
223
|
-
if (possibleNode === null) {
|
|
224
|
-
return resolveElement(focusNode.getParentOrThrow(), isBackward, focusNode.getIndexWithinParent() + (isBackward ? 0 : 1));
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return possibleNode;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return null;
|
|
185
|
+
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
186
|
+
const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
|
|
187
|
+
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
232
188
|
}
|
|
233
189
|
|
|
234
190
|
/**
|
|
@@ -239,25 +195,14 @@ function getPossibleDecoratorNode(focus, isBackward) {
|
|
|
239
195
|
*
|
|
240
196
|
*
|
|
241
197
|
*/
|
|
242
|
-
function $insertDataTransferForPlainText(dataTransfer, selection) {
|
|
243
|
-
const text = dataTransfer.getData('text/plain');
|
|
244
|
-
|
|
245
|
-
if (text != null) {
|
|
246
|
-
selection.insertRawText(text);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
|
|
250
|
-
const possibleNode = getPossibleDecoratorNode(selection.focus, isBackward);
|
|
251
|
-
return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
|
|
252
|
-
}
|
|
253
198
|
function onPasteForPlainText(event, editor) {
|
|
254
199
|
event.preventDefault();
|
|
255
200
|
editor.update(() => {
|
|
256
201
|
const selection = lexical.$getSelection();
|
|
257
202
|
const clipboardData = event.clipboardData;
|
|
258
203
|
|
|
259
|
-
if (clipboardData != null && selection
|
|
260
|
-
|
|
204
|
+
if (clipboardData != null && lexical.$isRangeSelection(selection)) {
|
|
205
|
+
clipboard.$insertDataTransferForPlainText(clipboardData, selection);
|
|
261
206
|
}
|
|
262
207
|
});
|
|
263
208
|
}
|
|
@@ -266,7 +211,7 @@ function onCutForPlainText(event, editor) {
|
|
|
266
211
|
editor.update(() => {
|
|
267
212
|
const selection = lexical.$getSelection();
|
|
268
213
|
|
|
269
|
-
if (selection
|
|
214
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
270
215
|
selection.removeText();
|
|
271
216
|
}
|
|
272
217
|
});
|
|
@@ -279,19 +224,10 @@ function onCopyForPlainText(event, editor) {
|
|
|
279
224
|
|
|
280
225
|
if (selection !== null) {
|
|
281
226
|
if (clipboardData != null) {
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
if (domSelection.isCollapsed) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
227
|
+
const htmlString = clipboard.getHtmlContent(editor);
|
|
287
228
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (range) {
|
|
291
|
-
const container = document.createElement('div');
|
|
292
|
-
const frag = range.cloneContents();
|
|
293
|
-
container.appendChild(frag);
|
|
294
|
-
clipboardData.setData('text/html', container.innerHTML);
|
|
229
|
+
if (htmlString !== null) {
|
|
230
|
+
clipboardData.setData('text/html', htmlString);
|
|
295
231
|
}
|
|
296
232
|
|
|
297
233
|
clipboardData.setData('text/plain', selection.getTextContent());
|
|
@@ -300,6 +236,62 @@ function onCopyForPlainText(event, editor) {
|
|
|
300
236
|
});
|
|
301
237
|
}
|
|
302
238
|
|
|
239
|
+
/**
|
|
240
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
241
|
+
*
|
|
242
|
+
* This source code is licensed under the MIT license found in the
|
|
243
|
+
* LICENSE file in the root directory of this source tree.
|
|
244
|
+
*
|
|
245
|
+
*
|
|
246
|
+
*/
|
|
247
|
+
// Convoluted logic to make this work with Flow. Order matters.
|
|
248
|
+
const options = {
|
|
249
|
+
tag: 'history-merge'
|
|
250
|
+
};
|
|
251
|
+
const setEditorOptions = options;
|
|
252
|
+
const updateOptions = options;
|
|
253
|
+
function initializeEditor(editor, initialEditorState) {
|
|
254
|
+
if (initialEditorState === null) {
|
|
255
|
+
return;
|
|
256
|
+
} else if (initialEditorState === undefined) {
|
|
257
|
+
editor.update(() => {
|
|
258
|
+
const root = lexical.$getRoot();
|
|
259
|
+
const firstChild = root.getFirstChild();
|
|
260
|
+
|
|
261
|
+
if (firstChild === null) {
|
|
262
|
+
const paragraph = lexical.$createParagraphNode();
|
|
263
|
+
root.append(paragraph);
|
|
264
|
+
const activeElement = document.activeElement;
|
|
265
|
+
|
|
266
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
267
|
+
paragraph.select();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}, updateOptions);
|
|
271
|
+
} else if (initialEditorState !== null) {
|
|
272
|
+
switch (typeof initialEditorState) {
|
|
273
|
+
case 'string':
|
|
274
|
+
{
|
|
275
|
+
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
276
|
+
editor.setEditorState(parsedEditorState, setEditorOptions);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
case 'object':
|
|
281
|
+
{
|
|
282
|
+
editor.setEditorState(initialEditorState, setEditorOptions);
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
case 'function':
|
|
287
|
+
{
|
|
288
|
+
editor.update(initialEditorState, updateOptions);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
303
295
|
/**
|
|
304
296
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
305
297
|
*
|
|
@@ -339,7 +331,7 @@ function useLexicalDragonSupport(editor) {
|
|
|
339
331
|
editor.update(() => {
|
|
340
332
|
const selection = lexical.$getSelection();
|
|
341
333
|
|
|
342
|
-
if (selection
|
|
334
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
343
335
|
const anchor = selection.anchor;
|
|
344
336
|
let anchorNode = anchor.getNode();
|
|
345
337
|
let setSelStart = 0;
|
|
@@ -396,13 +388,12 @@ function useLexicalDragonSupport(editor) {
|
|
|
396
388
|
*
|
|
397
389
|
*
|
|
398
390
|
*/
|
|
399
|
-
|
|
400
|
-
function usePlainTextSetup(editor) {
|
|
391
|
+
function usePlainTextSetup(editor, initialEditorState) {
|
|
401
392
|
useLayoutEffect(() => {
|
|
402
393
|
const removeListener = editor.addListener('command', (type, payload) => {
|
|
403
394
|
const selection = lexical.$getSelection();
|
|
404
395
|
|
|
405
|
-
if (selection
|
|
396
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
406
397
|
return false;
|
|
407
398
|
}
|
|
408
399
|
|
|
@@ -438,7 +429,7 @@ function usePlainTextSetup(editor) {
|
|
|
438
429
|
const dataTransfer = eventOrText.dataTransfer;
|
|
439
430
|
|
|
440
431
|
if (dataTransfer != null) {
|
|
441
|
-
|
|
432
|
+
clipboard.$insertDataTransferForPlainText(dataTransfer, selection);
|
|
442
433
|
} else {
|
|
443
434
|
const data = eventOrText.data;
|
|
444
435
|
|
|
@@ -556,9 +547,10 @@ function usePlainTextSetup(editor) {
|
|
|
556
547
|
}
|
|
557
548
|
|
|
558
549
|
return false;
|
|
559
|
-
},
|
|
560
|
-
editor
|
|
561
|
-
return removeListener;
|
|
550
|
+
}, 0);
|
|
551
|
+
initializeEditor(editor, initialEditorState);
|
|
552
|
+
return removeListener; // We only do this for init
|
|
553
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
562
554
|
}, [editor]);
|
|
563
555
|
useLexicalDragonSupport(editor);
|
|
564
556
|
}
|
|
@@ -573,11 +565,12 @@ function usePlainTextSetup(editor) {
|
|
|
573
565
|
*/
|
|
574
566
|
function PlainTextPlugin({
|
|
575
567
|
contentEditable,
|
|
576
|
-
placeholder
|
|
568
|
+
placeholder,
|
|
569
|
+
initialEditorState
|
|
577
570
|
}) {
|
|
578
571
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
579
572
|
const showPlaceholder = useLexicalCanShowPlaceholder(editor);
|
|
580
|
-
usePlainTextSetup(editor);
|
|
573
|
+
usePlainTextSetup(editor, initialEditorState);
|
|
581
574
|
const decorators = useDecorators(editor);
|
|
582
575
|
return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, showPlaceholder && placeholder, decorators);
|
|
583
576
|
}
|
|
@@ -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
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {EditorState} from 'lexical';
|
|
11
|
+
|
|
12
|
+
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
13
|
+
|
|
14
|
+
declare export default function PlainTextPlugin({
|
|
15
|
+
contentEditable: React$Node,
|
|
16
|
+
initialEditorState?: InitialEditorStateType,
|
|
17
|
+
placeholder: React$Node,
|
|
18
|
+
}): React$Node;
|
|
@@ -4,15 +4,15 @@
|
|
|
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 g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom");function
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
k=n.getNode();t.$isTextNode(k)&&(l=B,m=B+
|
|
15
|
-
function
|
|
16
|
-
!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":b
|
|
17
|
-
|
|
18
|
-
module.exports=function({contentEditable:a,placeholder:e}){
|
|
7
|
+
var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),t=require("lexical"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,d=!0){if(a)return!1;a=t.$getRoot().getTextContent();d&&(a=a.trim());return""===a}
|
|
8
|
+
function x(a){if(!w(a,!1))return!1;a=t.$getRoot().getChildren();const d=a.length;if(1<d)return!1;for(let c=0;c<d;c++){var e=a[c];if(t.$isElementNode(e)){if("paragraph"!==e.__type||0!==e.__indent)return!1;e=e.getChildren();const b=e.length;for(let f=0;f<b;f++)if(!t.$isTextNode(e[c]))return!1}}return!0}function y(a){return()=>x(a)}var z="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
|
|
9
|
+
function A(a){const [d,e]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:c})=>{const b=a.isComposing();c=c.read(y(b));e(c)}),[a]);return d}function C(a){const [d,e]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",c=>{u.flushSync(()=>{e(c)})}),[a]);return h.useMemo(()=>{const c=[],b=Object.keys(d);for(let p=0;p<b.length;p++){var f=b[p];const r=d[f];f=a.getElementByKey(f);null!==f&&c.push(u.createPortal(r,f))}return c},[d,a])}
|
|
10
|
+
function D(a){a=a.anchor.getNode();return"rtl"===(t.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,d){a=t.$getDecoratorNode(a.focus,d);return t.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,d){a.preventDefault();d.update(()=>{const e=t.$getSelection(),c=a.clipboardData;null!=c&&t.$isRangeSelection(e)&&v.$insertDataTransferForPlainText(c,e)})}function G(a,d){H(a,d);d.update(()=>{const e=t.$getSelection();t.$isRangeSelection(e)&&e.removeText()})}
|
|
11
|
+
function H(a,d){a.preventDefault();d.update(()=>{const e=a.clipboardData,c=t.$getSelection();if(null!==c&&null!=e){const b=v.getHtmlContent(d);null!==b&&e.setData("text/html",b);e.setData("text/plain",c.getTextContent())}})}const I={tag:"history-merge"};
|
|
12
|
+
function J(a,d){if(null!==d)if(void 0===d)a.update(()=>{var e=t.$getRoot();if(null===e.getFirstChild()){const c=t.$createParagraphNode();e.append(c);e=document.activeElement;(null!==t.$getSelection()||null!==e&&e===a.getRootElement())&&c.select()}},I);else if(null!==d)switch(typeof d){case "string":d=a.parseEditorState(d);a.setEditorState(d,I);break;case "object":a.setEditorState(d,I);break;case "function":a.update(d,I)}}
|
|
13
|
+
function K(a){h.useEffect(()=>{const d=e=>{var c=a.getRootElement();if(document.activeElement===c&&(c=e.data,"string"===typeof c)){try{var b=JSON.parse(c)}catch(f){return}if(b&&"nuanria_messaging"===b.protocol&&"request"===b.type&&(b=b.payload)&&"makeChanges"===b.functionId&&(b=b.args)){const [f,p,r,B,L]=b;a.update(()=>{const q=t.$getSelection();if(t.$isRangeSelection(q)){var n=q.anchor;let k=n.getNode(),l=0,m=0;t.$isTextNode(k)&&0<=f&&0<=p&&(l=f,m=f+p,q.setTextNodeRange(k,l,k,m));if(l!==m||""!==
|
|
14
|
+
r)q.insertRawText(r),k=n.getNode();t.$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));e.stopImmediatePropagation()}})}}};window.addEventListener("message",d,!0);return()=>{window.removeEventListener("message",d,!0)}},[a])}
|
|
15
|
+
function M(a,d){z(()=>{const e=a.addListener("command",(c,b)=>{const f=t.$getSelection();if(!t.$isRangeSelection(f))return!1;switch(c){case "deleteCharacter":return f.deleteCharacter(b),!0;case "deleteWord":return f.deleteWord(b),!0;case "deleteLine":return f.deleteLine(b),!0;case "insertText":return"string"===typeof b?f.insertText(b):(c=b.dataTransfer,null!=c?v.$insertDataTransferForPlainText(c,f):(b=b.data)&&f.insertText(b)),!0;case "removeText":return f.removeText(),!0;case "insertLineBreak":return f.insertLineBreak(b),
|
|
16
|
+
!0;case "insertParagraph":return f.insertLineBreak(),!0;case "indentContent":case "outdentContent":case "insertHorizontalRule":case "insertImage":case "insertTable":case "formatElement":case "formatText":return!0;case "keyArrowLeft":c=b.shiftKey;if(E(f,!0))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=b.shiftKey;if(E(f,!1))return b.preventDefault(),b=c,c=D(f),f.modify(b?"extend":"move",c,"character"),!0;break;case "keyBackspace":return b.preventDefault(),
|
|
17
|
+
a.execCommand("deleteCharacter",!0);case "keyDelete":return b.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return b.preventDefault(),a.execCommand("insertLineBreak");case "copy":return H(b,a),!0;case "cut":return G(b,a),!0;case "paste":return F(b,a),!0;case "drop":case "dragstart":return b.preventDefault(),!0}return!1},0);J(a,d);return e},[a]);K(a)}
|
|
18
|
+
module.exports=function({contentEditable:a,placeholder:d,initialEditorState:e}){const [c]=g.useLexicalComposerContext(),b=A(c);M(c,e);e=C(c);return h.createElement(h.Fragment,null,a,b&&d,e)};
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {EditorState} from 'lexical';
|
|
10
|
+
type InitialEditorStateType = null | string | EditorState | (() => void);
|
|
11
|
+
export default function RichTextPlugin(arg0: {
|
|
12
|
+
contentEditable: React.ReactNode;
|
|
13
|
+
initialEditorState?: InitialEditorStateType;
|
|
14
|
+
placeholder: React.ReactNode;
|
|
15
|
+
}): React.ReactNode;
|