@lexical/react 0.1.11 → 0.1.14

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.
Files changed (55) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -7
  2. package/DEPRECATED_useLexical.prod.js +1 -1
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +14 -9
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +18 -18
  5. package/DEPRECATED_useLexicalPlainText.dev.js +33 -27
  6. package/DEPRECATED_useLexicalPlainText.prod.js +12 -12
  7. package/DEPRECATED_useLexicalRichText.dev.js +43 -388
  8. package/DEPRECATED_useLexicalRichText.prod.js +17 -25
  9. package/LexicalAutoFormatterPlugin.d.ts +9 -0
  10. package/LexicalAutoFormatterPlugin.dev.js +14 -9
  11. package/LexicalAutoFormatterPlugin.prod.js +18 -18
  12. package/LexicalAutoLinkPlugin.d.ts +20 -0
  13. package/LexicalCharacterLimitPlugin.d.ts +11 -0
  14. package/LexicalClearEditorPlugin.d.ts +14 -0
  15. package/LexicalClearEditorPlugin.dev.js +22 -1
  16. package/LexicalClearEditorPlugin.prod.js +2 -1
  17. package/LexicalCollaborationPlugin.d.ts +51 -0
  18. package/LexicalCollaborationPlugin.dev.js +39 -12
  19. package/LexicalCollaborationPlugin.js.flow +4 -2
  20. package/LexicalCollaborationPlugin.prod.js +8 -7
  21. package/LexicalComposer.d.ts +22 -0
  22. package/LexicalComposer.dev.js +28 -6
  23. package/LexicalComposer.js.flow +5 -4
  24. package/LexicalComposer.prod.js +3 -3
  25. package/LexicalComposerContext.d.ts +24 -0
  26. package/LexicalComposerContext.js.flow +1 -1
  27. package/LexicalContentEditable.d.ts +32 -0
  28. package/LexicalContentEditable.dev.js +22 -1
  29. package/LexicalContentEditable.prod.js +3 -3
  30. package/LexicalHashtagPlugin.d.ts +9 -0
  31. package/LexicalHashtagPlugin.dev.js +56 -1
  32. package/LexicalHashtagPlugin.js.flow +0 -10
  33. package/LexicalHashtagPlugin.prod.js +7 -4
  34. package/LexicalHistoryPlugin.d.ts +29 -0
  35. package/LexicalHorizontalRuleNode.d.ts +23 -0
  36. package/LexicalLinkPlugin.d.ts +9 -0
  37. package/LexicalListPlugin.d.ts +9 -0
  38. package/LexicalNestedComposer.d.ts +17 -0
  39. package/LexicalNestedComposer.dev.js +21 -11
  40. package/LexicalNestedComposer.js.flow +3 -6
  41. package/LexicalNestedComposer.prod.js +3 -2
  42. package/LexicalOnChangePlugin.d.ts +12 -0
  43. package/LexicalPlainTextPlugin.d.ts +15 -0
  44. package/LexicalPlainTextPlugin.dev.js +11 -26
  45. package/LexicalPlainTextPlugin.prod.js +8 -8
  46. package/LexicalRichTextPlugin.d.ts +15 -0
  47. package/LexicalRichTextPlugin.dev.js +24 -390
  48. package/LexicalRichTextPlugin.prod.js +13 -21
  49. package/LexicalTablePlugin.d.ts +9 -0
  50. package/LexicalTreeView.d.ts +17 -0
  51. package/package.json +9 -5
  52. package/useLexicalDecoratorMap.d.ts +14 -0
  53. package/useLexicalIsTextContentEmpty.d.ts +13 -0
  54. package/useLexicalNodeSelection.d.ts +12 -0
  55. package/withSubscriptions.d.ts +12 -0
@@ -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.
@@ -169,188 +170,6 @@ function useDecorators(editor) {
169
170
  *
170
171
  */
171
172
 
172
- function $cloneWithProperties(node) {
173
- const latest = node.getLatest();
174
- const constructor = latest.constructor;
175
- const clone = constructor.clone(latest);
176
- clone.__parent = latest.__parent;
177
-
178
- if (lexical.$isElementNode(latest) && lexical.$isElementNode(clone)) {
179
- clone.__children = Array.from(latest.__children);
180
- clone.__format = latest.__format;
181
- clone.__indent = latest.__indent;
182
- clone.__dir = latest.__dir;
183
- } else if (lexical.$isTextNode(latest) && lexical.$isTextNode(clone)) {
184
- clone.__format = latest.__format;
185
- clone.__style = latest.__style;
186
- clone.__mode = latest.__mode;
187
- clone.__detail = latest.__detail;
188
- } else if (lexical.$isDecoratorNode(latest) && lexical.$isDecoratorNode(clone)) {
189
- clone.__state = latest.__state;
190
- } // $FlowFixMe
191
-
192
-
193
- return clone;
194
- }
195
-
196
- function $getIndexFromPossibleClone(node, parent, nodeMap) {
197
- const parentClone = nodeMap.get(parent.getKey());
198
-
199
- if (lexical.$isElementNode(parentClone)) {
200
- return parentClone.__children.indexOf(node.getKey());
201
- }
202
-
203
- return node.getIndexWithinParent();
204
- }
205
-
206
- function $getParentAvoidingExcludedElements(node) {
207
- let parent = node.getParent();
208
-
209
- while (parent !== null && parent.excludeFromCopy()) {
210
- parent = parent.getParent();
211
- }
212
-
213
- return parent;
214
- }
215
-
216
- function $copyLeafNodeBranchToRoot(leaf, startingOffset, isLeftSide, range, nodeMap) {
217
- let node = leaf;
218
- let offset = startingOffset;
219
-
220
- while (node !== null) {
221
- const parent = $getParentAvoidingExcludedElements(node);
222
-
223
- if (parent === null) {
224
- break;
225
- }
226
-
227
- if (!lexical.$isElementNode(node) || !node.excludeFromCopy()) {
228
- const key = node.getKey();
229
- let clone = nodeMap.get(key);
230
- const needsClone = clone === undefined;
231
-
232
- if (needsClone) {
233
- clone = $cloneWithProperties(node);
234
- nodeMap.set(key, clone);
235
- }
236
-
237
- if (lexical.$isTextNode(clone) && !clone.isSegmented() && !clone.isToken()) {
238
- clone.__text = clone.__text.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : offset);
239
- } else if (lexical.$isElementNode(clone)) {
240
- clone.__children = clone.__children.slice(isLeftSide ? offset : 0, isLeftSide ? undefined : offset + 1);
241
- }
242
-
243
- if (lexical.$isRootNode(parent)) {
244
- if (needsClone) {
245
- // We only want to collect a range of top level nodes.
246
- // So if the parent is the root, we know this is a top level.
247
- range.push(key);
248
- }
249
-
250
- break;
251
- }
252
- }
253
-
254
- offset = $getIndexFromPossibleClone(node, parent, nodeMap);
255
- node = parent;
256
- }
257
- }
258
-
259
- function $cloneContents(selection) {
260
- if (!lexical.$isRangeSelection(selection)) {
261
- {
262
- throw Error(`TODO`);
263
- }
264
- }
265
-
266
- const anchor = selection.anchor;
267
- const focus = selection.focus;
268
- const anchorOffset = anchor.getCharacterOffset();
269
- const focusOffset = focus.getCharacterOffset();
270
- const anchorNode = anchor.getNode();
271
- const focusNode = focus.getNode();
272
- const anchorNodeParent = anchorNode.getParentOrThrow(); // Handle a single text node extraction
273
-
274
- if (anchorNode === focusNode && lexical.$isTextNode(anchorNode) && (anchorNodeParent.canBeEmpty() || anchorNodeParent.getChildrenSize() > 1)) {
275
- const clonedFirstNode = $cloneWithProperties(anchorNode);
276
- const isBefore = focusOffset > anchorOffset;
277
- const startOffset = isBefore ? anchorOffset : focusOffset;
278
- const endOffset = isBefore ? focusOffset : anchorOffset;
279
- clonedFirstNode.__text = clonedFirstNode.__text.slice(startOffset, endOffset);
280
- const key = clonedFirstNode.getKey();
281
- return {
282
- nodeMap: [[key, clonedFirstNode]],
283
- range: [key]
284
- };
285
- }
286
-
287
- const nodes = selection.getNodes();
288
-
289
- if (nodes.length === 0) {
290
- return {
291
- nodeMap: [],
292
- range: []
293
- };
294
- } // Check if we can use the parent of the nodes, if the
295
- // parent can't be empty, then it's important that we
296
- // also copy that element node along with its children.
297
-
298
-
299
- let nodesLength = nodes.length;
300
- const firstNode = nodes[0];
301
- const firstNodeParent = firstNode.getParent();
302
-
303
- if (firstNodeParent !== null && (!firstNodeParent.canBeEmpty() || lexical.$isRootNode(firstNodeParent))) {
304
- const parentChildren = firstNodeParent.__children;
305
- const parentChildrenLength = parentChildren.length;
306
-
307
- if (parentChildrenLength === nodesLength) {
308
- let areTheSame = true;
309
-
310
- for (let i = 0; i < parentChildren.length; i++) {
311
- if (parentChildren[i] !== nodes[i].__key) {
312
- areTheSame = false;
313
- break;
314
- }
315
- }
316
-
317
- if (areTheSame) {
318
- nodesLength++;
319
- nodes.push(firstNodeParent);
320
- }
321
- }
322
- }
323
-
324
- const lastNode = nodes[nodesLength - 1];
325
- const isBefore = anchor.isBefore(focus);
326
- const nodeMap = new Map();
327
- const range = []; // Do first node to root
328
-
329
- $copyLeafNodeBranchToRoot(firstNode, isBefore ? anchorOffset : focusOffset, true, range, nodeMap); // Copy all nodes between
330
-
331
- for (let i = 0; i < nodesLength; i++) {
332
- const node = nodes[i];
333
- const key = node.getKey();
334
-
335
- if (!nodeMap.has(key) && (!lexical.$isElementNode(node) || !node.excludeFromCopy())) {
336
- const clone = $cloneWithProperties(node);
337
-
338
- if (lexical.$isRootNode(node.getParent())) {
339
- range.push(node.getKey());
340
- }
341
-
342
- nodeMap.set(key, clone);
343
- }
344
- } // Do last node to root
345
-
346
-
347
- $copyLeafNodeBranchToRoot(lastNode, isBefore ? focusOffset : anchorOffset, false, range, nodeMap);
348
- return {
349
- nodeMap: Array.from(nodeMap.entries()),
350
- range
351
- };
352
- }
353
-
354
173
  function $moveCaretSelection(selection, isHoldingShift, isBackward, granularity) {
355
174
  selection.modify(isHoldingShift ? 'extend' : 'move', isBackward, granularity);
356
175
  }
@@ -363,6 +182,10 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
363
182
  const isRTL = $isParentElementRTL(selection);
364
183
  $moveCaretSelection(selection, isHoldingShift, isBackward ? !isRTL : isRTL, 'character');
365
184
  }
185
+ function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
186
+ const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
187
+ return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
188
+ }
366
189
 
367
190
  /**
368
191
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -372,197 +195,6 @@ function $moveCharacter(selection, isHoldingShift, isBackward) {
372
195
  *
373
196
  *
374
197
  */
375
-
376
- function $generateNodes(nodeRange) {
377
- const {
378
- range,
379
- nodeMap
380
- } = nodeRange;
381
- const parsedNodeMap = new Map(nodeMap);
382
- const nodes = [];
383
-
384
- for (let i = 0; i < range.length; i++) {
385
- const key = range[i];
386
- const parsedNode = parsedNodeMap.get(key);
387
-
388
- if (parsedNode !== undefined) {
389
- const node = lexical.$createNodeFromParse(parsedNode, parsedNodeMap);
390
- nodes.push(node);
391
- }
392
- }
393
-
394
- return nodes;
395
- }
396
-
397
- function getConversionFunction(domNode, editor) {
398
- const {
399
- nodeName
400
- } = domNode;
401
-
402
- const cachedConversions = editor._htmlConversions.get(nodeName.toLowerCase());
403
-
404
- let currentConversion = null;
405
-
406
- if (cachedConversions !== undefined) {
407
- cachedConversions.forEach(cachedConversion => {
408
- const domConversion = cachedConversion(domNode);
409
-
410
- if (domConversion !== null) {
411
- if (currentConversion === null || currentConversion.priority < domConversion.priority) {
412
- currentConversion = domConversion;
413
- }
414
- }
415
- });
416
- }
417
-
418
- return currentConversion !== null ? currentConversion.conversion : null;
419
- }
420
-
421
- function $createNodesFromDOM(node, editor, forChildMap = new Map()) {
422
- let lexicalNodes = [];
423
- let currentLexicalNode = null;
424
- const transformFunction = getConversionFunction(node, editor);
425
- const transformOutput = transformFunction ? transformFunction(node) : null;
426
- let postTransform = null;
427
-
428
- if (transformOutput !== null) {
429
- postTransform = transformOutput.after;
430
- currentLexicalNode = transformOutput.node;
431
-
432
- if (currentLexicalNode !== null) {
433
- lexicalNodes.push(currentLexicalNode);
434
- const forChildFunctions = Array.from(forChildMap.values());
435
-
436
- for (let i = 0; i < forChildFunctions.length; i++) {
437
- forChildFunctions[i](currentLexicalNode);
438
- }
439
- }
440
-
441
- if (transformOutput.forChild != null) {
442
- forChildMap.set(node.nodeName, transformOutput.forChild);
443
- }
444
- } // If the DOM node doesn't have a transformer, we don't know what
445
- // to do with it but we still need to process any childNodes.
446
-
447
-
448
- const children = node.childNodes;
449
- let childLexicalNodes = [];
450
-
451
- for (let i = 0; i < children.length; i++) {
452
- childLexicalNodes.push(...$createNodesFromDOM(children[i], editor, forChildMap));
453
- }
454
-
455
- if (postTransform != null) {
456
- childLexicalNodes = postTransform(childLexicalNodes);
457
- }
458
-
459
- if (currentLexicalNode == null) {
460
- // If it hasn't been converted to a LexicalNode, we hoist its children
461
- // up to the same level as it.
462
- lexicalNodes = lexicalNodes.concat(childLexicalNodes);
463
- } else {
464
- if (lexical.$isElementNode(currentLexicalNode)) {
465
- // If the current node is a ElementNode after conversion,
466
- // we can append all the children to it.
467
- currentLexicalNode.append(...childLexicalNodes);
468
- }
469
- }
470
-
471
- return lexicalNodes;
472
- }
473
-
474
- function $generateNodesFromDOM(dom, editor) {
475
- let lexicalNodes = [];
476
- const elements = dom.body ? Array.from(dom.body.childNodes) : [];
477
- const elementsLength = elements.length;
478
-
479
- for (let i = 0; i < elementsLength; i++) {
480
- const lexicalNode = $createNodesFromDOM(elements[i], editor);
481
-
482
- if (lexicalNode !== null) {
483
- lexicalNodes = lexicalNodes.concat(lexicalNode);
484
- }
485
- }
486
-
487
- return lexicalNodes;
488
- }
489
-
490
- function $insertDataTransferForRichText(dataTransfer, selection, editor) {
491
- const lexicalNodesString = dataTransfer.getData('application/x-lexical-editor');
492
-
493
- if (lexicalNodesString) {
494
- const namespace = editor._config.namespace;
495
-
496
- try {
497
- const lexicalClipboardData = JSON.parse(lexicalNodesString);
498
-
499
- if (lexicalClipboardData.namespace === namespace) {
500
- const nodeRange = lexicalClipboardData.state;
501
- const nodes = $generateNodes(nodeRange);
502
- selection.insertNodes(nodes);
503
- return;
504
- }
505
- } catch (e) {// Malformed, missing nodes..
506
- }
507
- }
508
-
509
- const textHtmlMimeType = 'text/html';
510
- const htmlString = dataTransfer.getData(textHtmlMimeType);
511
-
512
- if (htmlString) {
513
- const parser = new DOMParser();
514
- const dom = parser.parseFromString(htmlString, textHtmlMimeType);
515
- const nodes = $generateNodesFromDOM(dom, editor); // Wrap text and inline nodes in paragraph nodes so we have all blocks at the top-level
516
-
517
- const topLevelBlocks = [];
518
- let currentBlock = null;
519
-
520
- for (let i = 0; i < nodes.length; i++) {
521
- const node = nodes[i];
522
-
523
- if (!lexical.$isElementNode(node) || node.isInline()) {
524
- if (currentBlock === null) {
525
- currentBlock = lexical.$createParagraphNode();
526
- topLevelBlocks.push(currentBlock);
527
- }
528
-
529
- if (currentBlock !== null) {
530
- currentBlock.append(node);
531
- }
532
- } else {
533
- topLevelBlocks.push(node);
534
- currentBlock = null;
535
- }
536
- }
537
-
538
- selection.insertNodes(topLevelBlocks);
539
- return;
540
- }
541
-
542
- $insertDataTransferForPlainText(dataTransfer, selection);
543
- }
544
- function $insertDataTransferForPlainText(dataTransfer, selection) {
545
- const text = dataTransfer.getData('text/plain');
546
-
547
- if (text != null) {
548
- selection.insertRawText(text);
549
- }
550
- }
551
- function $shouldOverrideDefaultCharacterSelection(selection, isBackward) {
552
- const possibleNode = lexical.$getDecoratorNode(selection.focus, isBackward);
553
- return lexical.$isDecoratorNode(possibleNode) && !possibleNode.isIsolated();
554
- }
555
- function onPasteForRichText(event, editor) {
556
- event.preventDefault();
557
- editor.update(() => {
558
- const selection = lexical.$getSelection();
559
- const clipboardData = event.clipboardData;
560
-
561
- if (clipboardData != null && lexical.$isRangeSelection(selection)) {
562
- $insertDataTransferForRichText(clipboardData, selection, editor);
563
- }
564
- });
565
- }
566
198
  function onCutForRichText(event, editor) {
567
199
  onCopyForRichText(event, editor);
568
200
  editor.update(() => {
@@ -581,31 +213,33 @@ function onCopyForRichText(event, editor) {
581
213
 
582
214
  if (selection !== null) {
583
215
  if (clipboardData != null) {
584
- const domSelection = window.getSelection(); // If we haven't selected a range, then don't copy anything
216
+ const htmlString = clipboard.getHtmlContent(editor);
217
+ const lexicalString = clipboard.$getLexicalContent(editor);
585
218
 
586
- if (domSelection.isCollapsed) {
587
- return;
219
+ if (htmlString !== null) {
220
+ clipboardData.setData('text/html', htmlString);
588
221
  }
589
222
 
590
- const range = domSelection.getRangeAt(0);
591
-
592
- if (range) {
593
- const container = document.createElement('div');
594
- const frag = range.cloneContents();
595
- container.appendChild(frag);
596
- clipboardData.setData('text/html', container.innerHTML);
223
+ if (lexicalString !== null) {
224
+ clipboardData.setData('application/x-lexical-editor', lexicalString);
597
225
  }
598
226
 
599
227
  clipboardData.setData('text/plain', selection.getTextContent());
600
- const namespace = editor._config.namespace;
601
- clipboardData.setData('application/x-lexical-editor', JSON.stringify({
602
- namespace,
603
- state: $cloneContents(selection)
604
- }));
605
228
  }
606
229
  }
607
230
  });
608
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
+ }
609
243
 
610
244
  /**
611
245
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -760,7 +394,7 @@ function useLexicalDragonSupport(editor) {
760
394
  *
761
395
  */
762
396
  function useRichTextSetup(editor, initialEditorState) {
763
- React.useLayoutEffect(() => {
397
+ useLayoutEffect(() => {
764
398
  const removeListener = editor.addListener('command', (type, payload) => {
765
399
  const selection = lexical.$getSelection();
766
400
 
@@ -805,7 +439,7 @@ function useRichTextSetup(editor, initialEditorState) {
805
439
  const dataTransfer = eventOrText.dataTransfer;
806
440
 
807
441
  if (dataTransfer != null) {
808
- $insertDataTransferForRichText(dataTransfer, selection, editor);
442
+ clipboard.$insertDataTransferForRichText(dataTransfer, selection, editor);
809
443
  } else {
810
444
  const data = eventOrText.data;
811
445
 
@@ -4,24 +4,16 @@
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"),u=require("react"),y=require("lexical"),z=require("react-dom");function A(a,e=!0){if(a)return!1;a=y.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
- function B(a){if(!A(a,!1))return!1;a=y.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let c=0;c<e;c++){var f=a[c];if(y.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const d=f.length;for(let b=0;b<d;b++)if(!y.$isTextNode(f[c]))return!1}}return!0}function C(a){return()=>B(a)}var D="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?u.useLayoutEffect:u.useEffect;
9
- function E(a){const [e,f]=u.useState(a.getEditorState().read(C(a.isComposing())));D(()=>a.addListener("update",({editorState:c})=>{const d=a.isComposing();c=c.read(C(d));f(c)}),[a]);return e}function F(a){const [e,f]=u.useState(()=>a.getDecorators());D(()=>a.addListener("decorator",c=>{z.flushSync(()=>{f(c)})}),[a]);return u.useMemo(()=>{const c=[],d=Object.keys(e);for(let k=0;k<d.length;k++){var b=d[k];const h=e[b];b=a.getElementByKey(b);null!==b&&c.push(z.createPortal(h,b))}return c},[e,a])}
10
- function G(a){a=a.getLatest();const e=a.constructor.clone(a);e.__parent=a.__parent;y.$isElementNode(a)&&y.$isElementNode(e)?(e.__children=Array.from(a.__children),e.__format=a.__format,e.__indent=a.__indent,e.__dir=a.__dir):y.$isTextNode(a)&&y.$isTextNode(e)?(e.__format=a.__format,e.__style=a.__style,e.__mode=a.__mode,e.__detail=a.__detail):y.$isDecoratorNode(a)&&y.$isDecoratorNode(e)&&(e.__state=a.__state);return e}
11
- function H(a,e,f,c,d){for(var b=e;null!==a;){for(e=a.getParent();null!==e&&e.excludeFromCopy();)e=e.getParent();if(null===e)break;if(!y.$isElementNode(a)||!a.excludeFromCopy()){const k=a.getKey();let h=d.get(k);const l=void 0===h;l&&(h=G(a),d.set(k,h));!y.$isTextNode(h)||h.isSegmented()||h.isToken()?y.$isElementNode(h)&&(h.__children=h.__children.slice(f?b:0,f?void 0:b+1)):h.__text=h.__text.slice(f?b:0,f?void 0:b);if(y.$isRootNode(e)){l&&c.push(k);break}}b=d.get(e.getKey());b=y.$isElementNode(b)?
12
- b.__children.indexOf(a.getKey()):a.getIndexWithinParent();a=e}}function I(a){a=a.anchor.getNode();return"rtl"===(y.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function J(a,e){const {nodeName:f}=a;e=e._htmlConversions.get(f.toLowerCase());let c=null;void 0!==e&&e.forEach(d=>{d=d(a);null!==d&&(null===c||c.priority<d.priority)&&(c=d)});return null!==c?c.conversion:null}
13
- function K(a,e,f=new Map){let c=[],d=null;var b=J(a,e),k=b?b(a):null;b=null;if(null!==k){b=k.after;d=k.node;if(null!==d){c.push(d);var h=Array.from(f.values());for(let l=0;l<h.length;l++)h[l](d)}null!=k.forChild&&f.set(a.nodeName,k.forChild)}a=a.childNodes;k=[];for(h=0;h<a.length;h++)k.push(...K(a[h],e,f));null!=b&&(k=b(k));null==d?c=c.concat(k):y.$isElementNode(d)&&d.append(...k);return c}
14
- function L(a,e,f){var c=a.getData("application/x-lexical-editor");if(c){var d=f._config.namespace;try{const l=JSON.parse(c);if(l.namespace===d){const {range:t,nodeMap:m}=l.state;var b=new Map(m);c=[];for(d=0;d<t.length;d++){var k=b.get(t[d]);if(void 0!==k){var h=y.$createNodeFromParse(k,b);c.push(h)}}e.insertNodes(c);return}}catch(l){}}if(b=a.getData("text/html")){b=(new DOMParser).parseFromString(b,"text/html");a=[];b=b.body?Array.from(b.body.childNodes):[];k=b.length;for(h=0;h<k;h++)c=K(b[h],f),
15
- null!==c&&(a=a.concat(c));f=a;a=[];b=null;for(k=0;k<f.length;k++)h=f[k],!y.$isElementNode(h)||h.isInline()?(null===b&&(b=y.$createParagraphNode(),a.push(b)),null!==b&&b.append(h)):(a.push(h),b=null);e.insertNodes(a)}else f=a.getData("text/plain"),null!=f&&e.insertRawText(f)}function M(a,e){a=y.$getDecoratorNode(a.focus,e);return y.$isDecoratorNode(a)&&!a.isIsolated()}
16
- function N(a,e){a.preventDefault();e.update(()=>{const f=y.$getSelection(),c=a.clipboardData;null!=c&&y.$isRangeSelection(f)&&L(c,f,e)})}function O(a,e){P(a,e);e.update(()=>{const f=y.$getSelection();y.$isRangeSelection(f)&&f.removeText()})}
17
- function P(a,e){a.preventDefault();e.update(()=>{const f=a.clipboardData;var c=y.$getSelection();if(null!==c&&null!=f){var d=window.getSelection();if(!d.isCollapsed){var b=d.getRangeAt(0);b&&(d=document.createElement("div"),b=b.cloneContents(),d.appendChild(b),f.setData("text/html",d.innerHTML));f.setData("text/plain",c.getTextContent());d=e._config.namespace;b=f.setData;var k=JSON,h=k.stringify;{if(!y.$isRangeSelection(c))throw Error("Minified Lexical error #68; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");
18
- var l=c.anchor,t=c.focus;var m=l.getCharacterOffset();const x=t.getCharacterOffset();var n=l.getNode(),q=t.getNode(),p=n.getParentOrThrow();if(n===q&&y.$isTextNode(n)&&(p.canBeEmpty()||1<p.getChildrenSize()))c=G(n),n=x>m,c.__text=c.__text.slice(n?m:x,n?x:m),m=c.getKey(),m={nodeMap:[[m,c]],range:[m]};else if(c=c.getNodes(),0===c.length)m={nodeMap:[],range:[]};else{n=c.length;q=c[0];p=q.getParent();if(null!==p&&(!p.canBeEmpty()||y.$isRootNode(p))){var r=p.__children;if(r.length===n){var v=!0;for(var w=
19
- 0;w<r.length;w++)if(r[w]!==c[w].__key){v=!1;break}v&&(n++,c.push(p))}}p=c[n-1];l=l.isBefore(t);t=new Map;r=[];H(q,l?m:x,!0,r,t);for(q=0;q<n;q++)if(v=c[q],w=v.getKey(),!(t.has(w)||y.$isElementNode(v)&&v.excludeFromCopy())){const R=G(v);y.$isRootNode(v.getParent())&&r.push(v.getKey());t.set(w,R)}H(p,l?x:m,!1,r,t);m={nodeMap:Array.from(t.entries()),range:r}}}b.call(f,"application/x-lexical-editor",h.call(k,{namespace:d,state:m}))}}})}const Q={tag:"history-merge"};
20
- function S(a,e){if(null!==e)if(void 0===e)a.update(()=>{var f=y.$getRoot();if(null===f.getFirstChild()){const c=y.$createParagraphNode();f.append(c);f=document.activeElement;(null!==y.$getSelection()||null!==f&&f===a.getRootElement())&&c.select()}},Q);else if(null!==e)switch(typeof e){case "string":e=a.parseEditorState(e);a.setEditorState(e,Q);break;case "object":a.setEditorState(e,Q);break;case "function":a.update(e,Q)}}
21
- function T(a){u.useEffect(()=>{const e=f=>{var c=a.getRootElement();if(document.activeElement===c&&(c=f.data,"string"===typeof c)){try{var d=JSON.parse(c)}catch(b){return}if(d&&"nuanria_messaging"===d.protocol&&"request"===d.type&&(d=d.payload)&&"makeChanges"===d.functionId&&(d=d.args)){const [b,k,h,l,t]=d;a.update(()=>{const m=y.$getSelection();if(y.$isRangeSelection(m)){var n=m.anchor;let q=n.getNode(),p=0,r=0;y.$isTextNode(q)&&0<=b&&0<=k&&(p=b,r=b+k,m.setTextNodeRange(q,p,q,r));if(p!==r||""!==
22
- h)m.insertRawText(h),q=n.getNode();y.$isTextNode(q)&&(p=l,r=l+t,n=q.getTextContentSize(),p=p>n?n:p,r=r>n?n:r,m.setTextNodeRange(q,p,q,r));f.stopImmediatePropagation()}})}}};window.addEventListener("message",e,!0);return()=>{window.removeEventListener("message",e,!0)}},[a])}
23
- function U(a,e){u.useLayoutEffect(()=>{const f=a.addListener("command",(c,d)=>{var b=y.$getSelection();if("click"===c&&y.$isNodeSelection(b))return b.clear(),!0;if(!y.$isRangeSelection(b))return!1;switch(c){case "deleteCharacter":return b.deleteCharacter(d),!0;case "deleteWord":return b.deleteWord(d),!0;case "deleteLine":return b.deleteLine(d),!0;case "insertText":return"string"===typeof d?b.insertText(d):(c=d.dataTransfer,null!=c?L(c,b,a):(d=d.data)&&b.insertText(d)),!0;case "removeText":return b.removeText(),
24
- !0;case "formatText":return b.formatText(d),!0;case "formatElement":return b=b.anchor.getNode(),(y.$isElementNode(b)?b:b.getParentOrThrow()).setFormat(d),!0;case "insertLineBreak":return b.insertLineBreak(d),!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,
25
- d=b.getNode(),c="element"===b.type?b.getNode():b.getNode().getParentOrThrow(),c.canInsertTab()?"\t"===d.getTextContent()[b.offset-1]&&a.execCommand("deleteCharacter",!0):0!==c.getIndent()&&c.setIndent(c.getIndent()-1),!0;case "keyArrowLeft":c=d.shiftKey;if(M(b,!0))return d.preventDefault(),d=c,c=I(b),b.modify(d?"extend":"move",!c,"character"),!0;break;case "keyArrowRight":c=d.shiftKey;if(M(b,!1))return d.preventDefault(),d=c,c=I(b),b.modify(d?"extend":"move",c,"character"),!0;break;case "keyBackspace":return d.preventDefault(),
26
- {anchor:d}=b,b.isCollapsed()&&0===d.offset&&0<("element"===d.type?d.getNode():d.getNode().getParentOrThrow()).getIndent()?a.execCommand("outdentContent"):a.execCommand("deleteCharacter",!0);case "keyDelete":return d.preventDefault(),a.execCommand("deleteCharacter",!1);case "keyEnter":return d.preventDefault(),d.shiftKey?a.execCommand("insertLineBreak"):a.execCommand("insertParagraph");case "keyTab":return d.preventDefault(),a.execCommand(d.shiftKey?"outdentContent":"indentContent");case "keyEscape":return a.blur(),
27
- !0;case "copy":return P(d,a),!0;case "cut":return O(d,a),!0;case "paste":return N(d,a),!0;case "drop":case "dragstart":return d.preventDefault(),!0}return!1},0);S(a,e);return f},[a]);T(a)}module.exports=function({contentEditable:a,placeholder:e,initialEditorState:f}){const [c]=g.useLexicalComposerContext(),d=E(c);U(c,f);f=F(c);return u.createElement(u.Fragment,null,a,d&&e,f)};
7
+ var g=require("@lexical/react/LexicalComposerContext"),h=require("react"),r=require("lexical"),u=require("react-dom"),v=require("@lexical/clipboard");function w(a,e=!0){if(a)return!1;a=r.$getRoot().getTextContent();e&&(a=a.trim());return""===a}
8
+ function x(a){if(!w(a,!1))return!1;a=r.$getRoot().getChildren();const e=a.length;if(1<e)return!1;for(let d=0;d<e;d++){var f=a[d];if(r.$isElementNode(f)){if("paragraph"!==f.__type||0!==f.__indent)return!1;f=f.getChildren();const c=f.length;for(let b=0;b<c;b++)if(!r.$isTextNode(f[d]))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 [e,f]=h.useState(a.getEditorState().read(y(a.isComposing())));z(()=>a.addListener("update",({editorState:d})=>{const c=a.isComposing();d=d.read(y(c));f(d)}),[a]);return e}function C(a){const [e,f]=h.useState(()=>a.getDecorators());z(()=>a.addListener("decorator",d=>{u.flushSync(()=>{f(d)})}),[a]);return h.useMemo(()=>{const d=[],c=Object.keys(e);for(let p=0;p<c.length;p++){var b=c[p];const t=e[b];b=a.getElementByKey(b);null!==b&&d.push(u.createPortal(t,b))}return d},[e,a])}
10
+ function D(a){a=a.anchor.getNode();return"rtl"===(r.$isRootNode(a)?a:a.getParentOrThrow()).getDirection()}function E(a,e){a=r.$getDecoratorNode(a.focus,e);return r.$isDecoratorNode(a)&&!a.isIsolated()}function F(a,e){G(a,e);e.update(()=>{const f=r.$getSelection();r.$isRangeSelection(f)&&f.removeText()})}
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)};
@@ -0,0 +1,9 @@
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
+ export default function LexicalTablePlugin(): null;
@@ -0,0 +1,17 @@
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 {LexicalEditor} from 'lexical';
10
+ export default function TreeView(props: {
11
+ timeTravelPanelClassName: string;
12
+ timeTravelPanelSliderClassName: string;
13
+ timeTravelPanelButtonClassName: string;
14
+ timeTravelButtonClassName: string;
15
+ viewClassName: string;
16
+ editor: LexicalEditor;
17
+ }): React.ReactNode;
package/package.json CHANGED
@@ -12,12 +12,16 @@
12
12
  "rich-text"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.11",
15
+ "version": "0.1.14",
16
+ "dependencies": {
17
+ "@lexical/helpers": "0.1.14",
18
+ "@lexical/clipboard": "0.1.14",
19
+ "@lexical/list": "0.1.14",
20
+ "@lexical/table": "0.1.14",
21
+ "@lexical/yjs": "0.1.14"
22
+ },
16
23
  "peerDependencies": {
17
- "lexical": "0.1.11",
18
- "@lexical/helpers": "0.1.11",
19
- "@lexical/table": "0.1.11",
20
- "@lexical/yjs": "0.1.11",
24
+ "lexical": "0.1.14",
21
25
  "react": ">=17.x",
22
26
  "react-dom": ">=17.x"
23
27
  },
@@ -0,0 +1,14 @@
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 {DecoratorMap, DecoratorStateValue} from 'lexical';
10
+ export default function useLexicalDecoratorMap<V extends DecoratorStateValue>(
11
+ decoratorMap: DecoratorMap,
12
+ key: string,
13
+ initialValue: (() => V) | V,
14
+ ): [V, (arg0: DecoratorStateValue) => void];
@@ -0,0 +1,13 @@
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 {LexicalEditor} from 'lexical';
10
+ export default function useLexicalIsTextContentEmpty(
11
+ editor: LexicalEditor,
12
+ trim?: boolean,
13
+ ): boolean;
@@ -0,0 +1,12 @@
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 {NodeKey} from 'lexical';
10
+ export default function useLexicalNodeSelection(
11
+ key: NodeKey,
12
+ ): [boolean, (arg0: boolean) => void, () => void];
@@ -0,0 +1,12 @@
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
+ type UnsubscribeFn = () => void;
10
+ export default function withSubscriptions(
11
+ ...unsubscribe: Array<UnsubscribeFn>
12
+ ): () => void;