@lexical/react 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/LexicalAutoEmbedPlugin.dev.esm.js +131 -0
  2. package/LexicalAutoEmbedPlugin.esm.js +13 -0
  3. package/LexicalAutoEmbedPlugin.js +1 -1
  4. package/LexicalAutoEmbedPlugin.prod.esm.js +7 -0
  5. package/LexicalAutoFocusPlugin.dev.esm.js +42 -0
  6. package/LexicalAutoFocusPlugin.dev.js +0 -5
  7. package/LexicalAutoFocusPlugin.esm.js +10 -0
  8. package/LexicalAutoFocusPlugin.js +1 -1
  9. package/LexicalAutoFocusPlugin.prod.esm.js +7 -0
  10. package/LexicalAutoFocusPlugin.prod.js +1 -1
  11. package/LexicalAutoLinkPlugin.dev.esm.js +312 -0
  12. package/LexicalAutoLinkPlugin.dev.js +3 -1
  13. package/LexicalAutoLinkPlugin.esm.js +11 -0
  14. package/LexicalAutoLinkPlugin.js +1 -1
  15. package/LexicalAutoLinkPlugin.prod.esm.js +7 -0
  16. package/LexicalBlockWithAlignableContents.dev.esm.js +86 -0
  17. package/LexicalBlockWithAlignableContents.dev.js +1 -0
  18. package/LexicalBlockWithAlignableContents.esm.js +10 -0
  19. package/LexicalBlockWithAlignableContents.js +1 -1
  20. package/LexicalBlockWithAlignableContents.prod.esm.js +7 -0
  21. package/LexicalBlockWithAlignableContents.prod.js +1 -1
  22. package/LexicalCharacterLimitPlugin.d.ts +4 -1
  23. package/LexicalCharacterLimitPlugin.dev.esm.js +272 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +12 -4
  25. package/LexicalCharacterLimitPlugin.esm.js +10 -0
  26. package/LexicalCharacterLimitPlugin.js +1 -1
  27. package/LexicalCharacterLimitPlugin.prod.esm.js +7 -0
  28. package/LexicalCharacterLimitPlugin.prod.js +9 -9
  29. package/LexicalCheckListPlugin.dev.esm.js +203 -0
  30. package/LexicalCheckListPlugin.esm.js +10 -0
  31. package/LexicalCheckListPlugin.js +1 -1
  32. package/LexicalCheckListPlugin.prod.esm.js +7 -0
  33. package/LexicalClearEditorPlugin.dev.esm.js +64 -0
  34. package/LexicalClearEditorPlugin.esm.js +10 -0
  35. package/LexicalClearEditorPlugin.js +1 -1
  36. package/LexicalClearEditorPlugin.prod.esm.js +7 -0
  37. package/LexicalClickableLinkPlugin.dev.esm.js +95 -0
  38. package/LexicalClickableLinkPlugin.esm.js +10 -0
  39. package/LexicalClickableLinkPlugin.js +1 -1
  40. package/LexicalClickableLinkPlugin.prod.esm.js +7 -0
  41. package/LexicalCollaborationContext.dev.esm.js +36 -0
  42. package/LexicalCollaborationContext.esm.js +11 -0
  43. package/LexicalCollaborationContext.js +1 -1
  44. package/LexicalCollaborationContext.prod.esm.js +7 -0
  45. package/LexicalCollaborationPlugin.dev.esm.js +308 -0
  46. package/LexicalCollaborationPlugin.esm.js +10 -0
  47. package/LexicalCollaborationPlugin.js +1 -1
  48. package/LexicalCollaborationPlugin.prod.esm.js +7 -0
  49. package/LexicalComposer.dev.esm.js +129 -0
  50. package/LexicalComposer.esm.js +10 -0
  51. package/LexicalComposer.js +1 -1
  52. package/LexicalComposer.prod.esm.js +7 -0
  53. package/LexicalComposerContext.dev.esm.js +42 -0
  54. package/LexicalComposerContext.esm.js +12 -0
  55. package/LexicalComposerContext.js +1 -1
  56. package/LexicalComposerContext.prod.esm.js +7 -0
  57. package/LexicalContentEditable.dev.esm.js +107 -0
  58. package/LexicalContentEditable.dev.js +5 -1
  59. package/LexicalContentEditable.esm.js +10 -0
  60. package/LexicalContentEditable.js +1 -1
  61. package/LexicalContentEditable.prod.esm.js +7 -0
  62. package/LexicalContentEditable.prod.js +3 -3
  63. package/LexicalContextMenuPlugin.dev.esm.js +455 -0
  64. package/LexicalContextMenuPlugin.dev.js +3 -1
  65. package/LexicalContextMenuPlugin.esm.js +11 -0
  66. package/LexicalContextMenuPlugin.js +1 -1
  67. package/LexicalContextMenuPlugin.prod.esm.js +7 -0
  68. package/LexicalDecoratorBlockNode.dev.esm.js +46 -0
  69. package/LexicalDecoratorBlockNode.esm.js +11 -0
  70. package/LexicalDecoratorBlockNode.js +1 -1
  71. package/LexicalDecoratorBlockNode.prod.esm.js +7 -0
  72. package/LexicalEditorRefPlugin.dev.esm.js +40 -0
  73. package/LexicalEditorRefPlugin.dev.js +10 -5
  74. package/LexicalEditorRefPlugin.esm.js +10 -0
  75. package/LexicalEditorRefPlugin.js +1 -1
  76. package/LexicalEditorRefPlugin.prod.esm.js +7 -0
  77. package/LexicalEditorRefPlugin.prod.js +1 -1
  78. package/LexicalErrorBoundary.dev.esm.js +157 -0
  79. package/LexicalErrorBoundary.esm.js +10 -0
  80. package/LexicalErrorBoundary.js +1 -1
  81. package/LexicalErrorBoundary.prod.esm.js +7 -0
  82. package/LexicalHashtagPlugin.dev.esm.js +163 -0
  83. package/LexicalHashtagPlugin.esm.js +10 -0
  84. package/LexicalHashtagPlugin.js +1 -1
  85. package/LexicalHashtagPlugin.prod.esm.js +7 -0
  86. package/LexicalHistoryPlugin.dev.esm.js +41 -0
  87. package/LexicalHistoryPlugin.esm.js +11 -0
  88. package/LexicalHistoryPlugin.js +1 -1
  89. package/LexicalHistoryPlugin.prod.esm.js +7 -0
  90. package/LexicalHorizontalRuleNode.dev.esm.js +118 -0
  91. package/LexicalHorizontalRuleNode.dev.js +1 -0
  92. package/LexicalHorizontalRuleNode.esm.js +13 -0
  93. package/LexicalHorizontalRuleNode.js +1 -1
  94. package/LexicalHorizontalRuleNode.prod.esm.js +7 -0
  95. package/LexicalHorizontalRuleNode.prod.js +1 -1
  96. package/LexicalHorizontalRulePlugin.dev.esm.js +39 -0
  97. package/LexicalHorizontalRulePlugin.esm.js +10 -0
  98. package/LexicalHorizontalRulePlugin.js +1 -1
  99. package/LexicalHorizontalRulePlugin.prod.esm.js +7 -0
  100. package/LexicalLinkPlugin.dev.esm.js +79 -0
  101. package/LexicalLinkPlugin.dev.js +6 -2
  102. package/LexicalLinkPlugin.esm.js +10 -0
  103. package/LexicalLinkPlugin.js +1 -1
  104. package/LexicalLinkPlugin.prod.esm.js +7 -0
  105. package/LexicalLinkPlugin.prod.js +1 -1
  106. package/LexicalListPlugin.dev.esm.js +59 -0
  107. package/LexicalListPlugin.esm.js +10 -0
  108. package/LexicalListPlugin.js +1 -1
  109. package/LexicalListPlugin.prod.esm.js +7 -0
  110. package/LexicalMarkdownShortcutPlugin.dev.esm.js +49 -0
  111. package/LexicalMarkdownShortcutPlugin.esm.js +11 -0
  112. package/LexicalMarkdownShortcutPlugin.js +1 -1
  113. package/LexicalMarkdownShortcutPlugin.prod.esm.js +7 -0
  114. package/LexicalNestedComposer.dev.esm.js +105 -0
  115. package/LexicalNestedComposer.esm.js +10 -0
  116. package/LexicalNestedComposer.js +1 -1
  117. package/LexicalNestedComposer.prod.esm.js +7 -0
  118. package/LexicalNodeEventPlugin.dev.esm.js +56 -0
  119. package/LexicalNodeEventPlugin.esm.js +10 -0
  120. package/LexicalNodeEventPlugin.js +1 -1
  121. package/LexicalNodeEventPlugin.prod.esm.js +7 -0
  122. package/LexicalNodeMenuPlugin.dev.esm.js +466 -0
  123. package/LexicalNodeMenuPlugin.dev.js +3 -1
  124. package/LexicalNodeMenuPlugin.esm.js +11 -0
  125. package/LexicalNodeMenuPlugin.js +1 -1
  126. package/LexicalNodeMenuPlugin.prod.esm.js +7 -0
  127. package/LexicalOnChangePlugin.dev.esm.js +62 -0
  128. package/LexicalOnChangePlugin.esm.js +10 -0
  129. package/LexicalOnChangePlugin.js +1 -1
  130. package/LexicalOnChangePlugin.prod.esm.js +7 -0
  131. package/LexicalPlainTextPlugin.dev.esm.js +161 -0
  132. package/LexicalPlainTextPlugin.esm.js +10 -0
  133. package/LexicalPlainTextPlugin.js +1 -1
  134. package/LexicalPlainTextPlugin.prod.esm.js +7 -0
  135. package/LexicalRichTextPlugin.dev.esm.js +161 -0
  136. package/LexicalRichTextPlugin.esm.js +10 -0
  137. package/LexicalRichTextPlugin.js +1 -1
  138. package/LexicalRichTextPlugin.prod.esm.js +7 -0
  139. package/LexicalTabIndentationPlugin.dev.esm.js +76 -0
  140. package/LexicalTabIndentationPlugin.esm.js +11 -0
  141. package/LexicalTabIndentationPlugin.js +1 -1
  142. package/LexicalTabIndentationPlugin.prod.esm.js +7 -0
  143. package/LexicalTableOfContents.dev.esm.js +157 -0
  144. package/LexicalTableOfContents.esm.js +10 -0
  145. package/LexicalTableOfContents.js +1 -1
  146. package/LexicalTableOfContents.prod.esm.js +7 -0
  147. package/LexicalTablePlugin.dev.esm.js +163 -0
  148. package/LexicalTablePlugin.esm.js +10 -0
  149. package/LexicalTablePlugin.js +1 -1
  150. package/LexicalTablePlugin.prod.esm.js +7 -0
  151. package/LexicalTreeView.dev.esm.js +483 -0
  152. package/LexicalTreeView.dev.js +3 -1
  153. package/LexicalTreeView.esm.js +10 -0
  154. package/LexicalTreeView.js +1 -1
  155. package/LexicalTreeView.prod.esm.js +7 -0
  156. package/LexicalTypeaheadMenuPlugin.dev.esm.js +569 -0
  157. package/LexicalTypeaheadMenuPlugin.dev.js +3 -1
  158. package/LexicalTypeaheadMenuPlugin.esm.js +16 -0
  159. package/LexicalTypeaheadMenuPlugin.js +1 -1
  160. package/LexicalTypeaheadMenuPlugin.prod.esm.js +7 -0
  161. package/package.json +583 -20
  162. package/useLexicalEditable.dev.esm.js +82 -0
  163. package/useLexicalEditable.esm.js +10 -0
  164. package/useLexicalEditable.js +1 -1
  165. package/useLexicalEditable.prod.esm.js +7 -0
  166. package/useLexicalIsTextContentEmpty.dev.esm.js +51 -0
  167. package/useLexicalIsTextContentEmpty.esm.js +10 -0
  168. package/useLexicalIsTextContentEmpty.js +1 -1
  169. package/useLexicalIsTextContentEmpty.prod.esm.js +7 -0
  170. package/useLexicalNodeSelection.dev.esm.js +69 -0
  171. package/useLexicalNodeSelection.esm.js +10 -0
  172. package/useLexicalNodeSelection.js +1 -1
  173. package/useLexicalNodeSelection.prod.esm.js +7 -0
  174. package/useLexicalSubscription.dev.esm.js +63 -0
  175. package/useLexicalSubscription.esm.js +10 -0
  176. package/useLexicalSubscription.js +1 -1
  177. package/useLexicalSubscription.prod.esm.js +7 -0
  178. package/useLexicalTextEntity.dev.esm.js +26 -0
  179. package/useLexicalTextEntity.esm.js +10 -0
  180. package/useLexicalTextEntity.js +1 -1
  181. package/useLexicalTextEntity.prod.esm.js +7 -0
@@ -0,0 +1,118 @@
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 { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
+ import { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection';
9
+ import { mergeRegister } from '@lexical/utils';
10
+ import { createCommand, DecoratorNode, $applyNodeReplacement, $isNodeSelection, $getSelection, $getNodeByKey, CLICK_COMMAND, COMMAND_PRIORITY_LOW, KEY_DELETE_COMMAND, KEY_BACKSPACE_COMMAND } from 'lexical';
11
+ import * as React from 'react';
12
+ import { useCallback, useEffect } from 'react';
13
+
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+ const INSERT_HORIZONTAL_RULE_COMMAND = createCommand('INSERT_HORIZONTAL_RULE_COMMAND');
22
+ function HorizontalRuleComponent({
23
+ nodeKey
24
+ }) {
25
+ const [editor] = useLexicalComposerContext();
26
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
27
+ const onDelete = useCallback(event => {
28
+ if (isSelected && $isNodeSelection($getSelection())) {
29
+ event.preventDefault();
30
+ const node = $getNodeByKey(nodeKey);
31
+ if ($isHorizontalRuleNode(node)) {
32
+ node.remove();
33
+ return true;
34
+ }
35
+ }
36
+ return false;
37
+ }, [isSelected, nodeKey]);
38
+ useEffect(() => {
39
+ return mergeRegister(editor.registerCommand(CLICK_COMMAND, event => {
40
+ const hrElem = editor.getElementByKey(nodeKey);
41
+ if (event.target === hrElem) {
42
+ if (!event.shiftKey) {
43
+ clearSelection();
44
+ }
45
+ setSelected(!isSelected);
46
+ return true;
47
+ }
48
+ return false;
49
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_DELETE_COMMAND, onDelete, COMMAND_PRIORITY_LOW), editor.registerCommand(KEY_BACKSPACE_COMMAND, onDelete, COMMAND_PRIORITY_LOW));
50
+ }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
51
+ useEffect(() => {
52
+ const hrElem = editor.getElementByKey(nodeKey);
53
+ if (hrElem !== null) {
54
+ hrElem.className = isSelected ? 'selected' : '';
55
+ }
56
+ }, [editor, isSelected, nodeKey]);
57
+ return null;
58
+ }
59
+ class HorizontalRuleNode extends DecoratorNode {
60
+ static getType() {
61
+ return 'horizontalrule';
62
+ }
63
+ static clone(node) {
64
+ return new HorizontalRuleNode(node.__key);
65
+ }
66
+ static importJSON(serializedNode) {
67
+ return $createHorizontalRuleNode();
68
+ }
69
+ static importDOM() {
70
+ return {
71
+ hr: () => ({
72
+ conversion: convertHorizontalRuleElement,
73
+ priority: 0
74
+ })
75
+ };
76
+ }
77
+ exportJSON() {
78
+ return {
79
+ type: 'horizontalrule',
80
+ version: 1
81
+ };
82
+ }
83
+ exportDOM() {
84
+ return {
85
+ element: document.createElement('hr')
86
+ };
87
+ }
88
+ createDOM() {
89
+ return document.createElement('hr');
90
+ }
91
+ getTextContent() {
92
+ return '\n';
93
+ }
94
+ isInline() {
95
+ return false;
96
+ }
97
+ updateDOM() {
98
+ return false;
99
+ }
100
+ decorate() {
101
+ return /*#__PURE__*/React.createElement(HorizontalRuleComponent, {
102
+ nodeKey: this.__key
103
+ });
104
+ }
105
+ }
106
+ function convertHorizontalRuleElement() {
107
+ return {
108
+ node: $createHorizontalRuleNode()
109
+ };
110
+ }
111
+ function $createHorizontalRuleNode() {
112
+ return $applyNodeReplacement(new HorizontalRuleNode());
113
+ }
114
+ function $isHorizontalRuleNode(node) {
115
+ return node instanceof HorizontalRuleNode;
116
+ }
117
+
118
+ export { $createHorizontalRuleNode, $isHorizontalRuleNode, HorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND };
@@ -31,6 +31,7 @@ function HorizontalRuleComponent({
31
31
  const node = lexical.$getNodeByKey(nodeKey);
32
32
  if ($isHorizontalRuleNode(node)) {
33
33
  node.remove();
34
+ return true;
34
35
  }
35
36
  }
36
37
  return false;
@@ -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
+ import * as modDev from './LexicalHorizontalRuleNode.dev.esm.js';
8
+ import * as modProd from './LexicalHorizontalRuleNode.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const $createHorizontalRuleNode = mod.$createHorizontalRuleNode;
11
+ export const $isHorizontalRuleNode = mod.$isHorizontalRuleNode;
12
+ export const HorizontalRuleNode = mod.HorizontalRuleNode;
13
+ export const INSERT_HORIZONTAL_RULE_COMMAND = mod.INSERT_HORIZONTAL_RULE_COMMAND;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalHorizontalRuleNode = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRuleNode.dev.js') : require('./LexicalHorizontalRuleNode.prod.js')
8
+ const LexicalHorizontalRuleNode = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRuleNode.dev.js') : require('./LexicalHorizontalRuleNode.prod.js');
9
9
  module.exports = LexicalHorizontalRuleNode;
@@ -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{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLexicalNodeSelection as t}from"@lexical/react/useLexicalNodeSelection";import{mergeRegister as r}from"@lexical/utils";import{createCommand as n,DecoratorNode as o,$applyNodeReplacement as i,$isNodeSelection as c,$getSelection as a,$getNodeByKey as l,CLICK_COMMAND as u,COMMAND_PRIORITY_LOW as m,KEY_DELETE_COMMAND as s,KEY_BACKSPACE_COMMAND as p}from"lexical";import*as f from"react";import{useCallback as d,useEffect as x}from"react";const y=n("INSERT_HORIZONTAL_RULE_COMMAND");function O({nodeKey:n}){const[o]=e(),[i,f,y]=t(n),O=d((e=>{if(i&&c(a())){e.preventDefault();const t=l(n);if(E(t))return t.remove(),!0}return!1}),[i,n]);return x((()=>r(o.registerCommand(u,(e=>{const t=o.getElementByKey(n);return e.target===t&&(e.shiftKey||y(),f(!i),!0)}),m),o.registerCommand(s,O,m),o.registerCommand(p,O,m))),[y,o,i,n,O,f]),x((()=>{const e=o.getElementByKey(n);null!==e&&(e.className=i?"selected":"")}),[o,i,n]),null}class g extends o{static getType(){return"horizontalrule"}static clone(e){return new g(e.__key)}static importJSON(e){return C()}static importDOM(){return{hr:()=>({conversion:h,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){return document.createElement("hr")}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return f.createElement(O,{nodeKey:this.__key})}}function h(){return{node:C()}}function C(){return i(new g)}function E(e){return e instanceof g}export{C as $createHorizontalRuleNode,E as $isHorizontalRuleNode,g as HorizontalRuleNode,y as INSERT_HORIZONTAL_RULE_COMMAND};
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict';var a=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/react/useLexicalNodeSelection"),g=require("@lexical/utils"),k=require("lexical"),n=require("react");let p=k.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
8
- function q({nodeKey:b}){let [d]=a.useLexicalComposerContext(),[e,l,m]=f.useLexicalNodeSelection(b),h=n.useCallback(c=>{e&&k.$isNodeSelection(k.$getSelection())&&(c.preventDefault(),c=k.$getNodeByKey(b),r(c)&&c.remove());return!1},[e,b]);n.useEffect(()=>g.mergeRegister(d.registerCommand(k.CLICK_COMMAND,c=>{let v=d.getElementByKey(b);return c.target===v?(c.shiftKey||m(),l(!e),!0):!1},k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_DELETE_COMMAND,h,k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_BACKSPACE_COMMAND,
8
+ function q({nodeKey:b}){let [d]=a.useLexicalComposerContext(),[e,l,m]=f.useLexicalNodeSelection(b),h=n.useCallback(c=>e&&k.$isNodeSelection(k.$getSelection())&&(c.preventDefault(),c=k.$getNodeByKey(b),r(c))?(c.remove(),!0):!1,[e,b]);n.useEffect(()=>g.mergeRegister(d.registerCommand(k.CLICK_COMMAND,c=>{let v=d.getElementByKey(b);return c.target===v?(c.shiftKey||m(),l(!e),!0):!1},k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_DELETE_COMMAND,h,k.COMMAND_PRIORITY_LOW),d.registerCommand(k.KEY_BACKSPACE_COMMAND,
9
9
  h,k.COMMAND_PRIORITY_LOW)),[m,d,e,b,h,l]);n.useEffect(()=>{let c=d.getElementByKey(b);null!==c&&(c.className=e?"selected":"")},[d,e,b]);return null}
10
10
  class t extends k.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new t(b.__key)}static importJSON(){return u()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){return document.createElement("hr")}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return n.createElement(q,{nodeKey:this.__key})}}
11
11
  function w(){return{node:u()}}function u(){return k.$applyNodeReplacement(new t)}function r(b){return b instanceof t}exports.$createHorizontalRuleNode=u;exports.$isHorizontalRuleNode=r;exports.HorizontalRuleNode=t;exports.INSERT_HORIZONTAL_RULE_COMMAND=p
@@ -0,0 +1,39 @@
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 { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
+ import { INSERT_HORIZONTAL_RULE_COMMAND, $createHorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
9
+ import { $insertNodeToNearestRoot } from '@lexical/utils';
10
+ import { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } from 'lexical';
11
+ import { useEffect } from 'react';
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+ function HorizontalRulePlugin() {
21
+ const [editor] = useLexicalComposerContext();
22
+ useEffect(() => {
23
+ return editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, type => {
24
+ const selection = $getSelection();
25
+ if (!$isRangeSelection(selection)) {
26
+ return false;
27
+ }
28
+ const focusNode = selection.focus.getNode();
29
+ if (focusNode !== null) {
30
+ const horizontalRuleNode = $createHorizontalRuleNode();
31
+ $insertNodeToNearestRoot(horizontalRuleNode);
32
+ }
33
+ return true;
34
+ }, COMMAND_PRIORITY_EDITOR);
35
+ }, [editor]);
36
+ return null;
37
+ }
38
+
39
+ export { HorizontalRulePlugin };
@@ -0,0 +1,10 @@
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 './LexicalHorizontalRulePlugin.dev.esm.js';
8
+ import * as modProd from './LexicalHorizontalRulePlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const HorizontalRulePlugin = mod.HorizontalRulePlugin;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js')
8
+ const LexicalHorizontalRulePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalHorizontalRulePlugin.dev.js') : require('./LexicalHorizontalRulePlugin.prod.js');
9
9
  module.exports = LexicalHorizontalRulePlugin;
@@ -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{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{INSERT_HORIZONTAL_RULE_COMMAND as r,$createHorizontalRuleNode as t}from"@lexical/react/LexicalHorizontalRuleNode";import{$insertNodeToNearestRoot as e}from"@lexical/utils";import{$getSelection as i,$isRangeSelection as l,COMMAND_PRIORITY_EDITOR as c}from"lexical";import{useEffect as m}from"react";function n(){const[n]=o();return m((()=>n.registerCommand(r,(o=>{const r=i();if(!l(r))return!1;if(null!==r.focus.getNode()){const o=t();e(o)}return!0}),c)),[n]),null}export{n as HorizontalRulePlugin};
@@ -0,0 +1,79 @@
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 { LinkNode, TOGGLE_LINK_COMMAND, toggleLink } from '@lexical/link';
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { mergeRegister, objectKlassEquals } from '@lexical/utils';
10
+ import { COMMAND_PRIORITY_LOW, PASTE_COMMAND, $getSelection, $isRangeSelection, $isElementNode } from 'lexical';
11
+ import { useEffect } from 'react';
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+ function LinkPlugin({
21
+ validateUrl
22
+ }) {
23
+ const [editor] = useLexicalComposerContext();
24
+ useEffect(() => {
25
+ if (!editor.hasNodes([LinkNode])) {
26
+ throw new Error('LinkPlugin: LinkNode not registered on editor');
27
+ }
28
+ return mergeRegister(editor.registerCommand(TOGGLE_LINK_COMMAND, payload => {
29
+ if (payload === null) {
30
+ toggleLink(payload);
31
+ return true;
32
+ } else if (typeof payload === 'string') {
33
+ if (validateUrl === undefined || validateUrl(payload)) {
34
+ toggleLink(payload);
35
+ return true;
36
+ }
37
+ return false;
38
+ } else {
39
+ const {
40
+ url,
41
+ target,
42
+ rel,
43
+ title
44
+ } = payload;
45
+ toggleLink(url, {
46
+ rel,
47
+ target,
48
+ title
49
+ });
50
+ return true;
51
+ }
52
+ }, COMMAND_PRIORITY_LOW), validateUrl !== undefined ? editor.registerCommand(PASTE_COMMAND, event => {
53
+ const selection = $getSelection();
54
+ if (!$isRangeSelection(selection) || selection.isCollapsed() || !objectKlassEquals(event, ClipboardEvent)) {
55
+ return false;
56
+ }
57
+ const clipboardEvent = event;
58
+ if (clipboardEvent.clipboardData === null) {
59
+ return false;
60
+ }
61
+ const clipboardText = clipboardEvent.clipboardData.getData('text');
62
+ if (!validateUrl(clipboardText)) {
63
+ return false;
64
+ }
65
+ // If we select nodes that are elements then avoid applying the link.
66
+ if (!selection.getNodes().some(node => $isElementNode(node))) {
67
+ editor.dispatchCommand(TOGGLE_LINK_COMMAND, clipboardText);
68
+ event.preventDefault();
69
+ return true;
70
+ }
71
+ return false;
72
+ }, COMMAND_PRIORITY_LOW) : () => {
73
+ // Don't paste arbritrary text as a link when there's no validate function
74
+ });
75
+ }, [editor, validateUrl]);
76
+ return null;
77
+ }
78
+
79
+ export { LinkPlugin };
@@ -53,10 +53,14 @@ function LinkPlugin({
53
53
  }
54
54
  }, lexical.COMMAND_PRIORITY_LOW), validateUrl !== undefined ? editor.registerCommand(lexical.PASTE_COMMAND, event => {
55
55
  const selection = lexical.$getSelection();
56
- if (!lexical.$isRangeSelection(selection) || selection.isCollapsed() || !(event instanceof ClipboardEvent) || event.clipboardData == null) {
56
+ if (!lexical.$isRangeSelection(selection) || selection.isCollapsed() || !utils.objectKlassEquals(event, ClipboardEvent)) {
57
57
  return false;
58
58
  }
59
- const clipboardText = event.clipboardData.getData('text');
59
+ const clipboardEvent = event;
60
+ if (clipboardEvent.clipboardData === null) {
61
+ return false;
62
+ }
63
+ const clipboardText = clipboardEvent.clipboardData.getData('text');
60
64
  if (!validateUrl(clipboardText)) {
61
65
  return false;
62
66
  }
@@ -0,0 +1,10 @@
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 './LexicalLinkPlugin.dev.esm.js';
8
+ import * as modProd from './LexicalLinkPlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const LinkPlugin = mod.LinkPlugin;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalLinkPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalLinkPlugin.dev.js') : require('./LexicalLinkPlugin.prod.js')
8
+ const LexicalLinkPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalLinkPlugin.dev.js') : require('./LexicalLinkPlugin.prod.js');
9
9
  module.exports = LexicalLinkPlugin;
@@ -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{LinkNode as t,TOGGLE_LINK_COMMAND as r,toggleLink as e}from"@lexical/link";import{useLexicalComposerContext as o}from"@lexical/react/LexicalComposerContext";import{mergeRegister as i,objectKlassEquals as n}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as l,PASTE_COMMAND as a,$getSelection as m,$isRangeSelection as s,$isElementNode as c}from"lexical";import{useEffect as d}from"react";function u({validateUrl:u}){const[p]=o();return d((()=>{if(!p.hasNodes([t]))throw new Error("LinkPlugin: LinkNode not registered on editor");return i(p.registerCommand(r,(t=>{if(null===t)return e(t),!0;if("string"==typeof t)return!(void 0!==u&&!u(t))&&(e(t),!0);{const{url:r,target:o,rel:i,title:n}=t;return e(r,{rel:i,target:o,title:n}),!0}}),l),void 0!==u?p.registerCommand(a,(t=>{const e=m();if(!s(e)||e.isCollapsed()||!n(t,ClipboardEvent))return!1;const o=t;if(null===o.clipboardData)return!1;const i=o.clipboardData.getData("text");return!!u(i)&&(!e.getNodes().some((t=>c(t)))&&(p.dispatchCommand(r,i),t.preventDefault(),!0))}),l):()=>{})}),[p,u]),null}export{u as LinkPlugin};
@@ -6,4 +6,4 @@
6
6
  */
7
7
  'use strict';var b=require("@lexical/link"),c=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/utils"),l=require("lexical"),m=require("react");
8
8
  exports.LinkPlugin=function({validateUrl:d}){let [e]=c.useLexicalComposerContext();m.useEffect(()=>{if(!e.hasNodes([b.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");return k.mergeRegister(e.registerCommand(b.TOGGLE_LINK_COMMAND,a=>{if(null===a)return b.toggleLink(a),!0;if("string"===typeof a)return void 0===d||d(a)?(b.toggleLink(a),!0):!1;let {url:f,target:g,rel:h,title:n}=a;b.toggleLink(f,{rel:h,target:g,title:n});return!0},l.COMMAND_PRIORITY_LOW),void 0!==d?e.registerCommand(l.PASTE_COMMAND,
9
- a=>{let f=l.$getSelection();if(!l.$isRangeSelection(f)||f.isCollapsed()||!(a instanceof ClipboardEvent)||null==a.clipboardData)return!1;let g=a.clipboardData.getData("text");return d(g)?f.getNodes().some(h=>l.$isElementNode(h))?!1:(e.dispatchCommand(b.TOGGLE_LINK_COMMAND,g),a.preventDefault(),!0):!1},l.COMMAND_PRIORITY_LOW):()=>{})},[e,d]);return null}
9
+ a=>{let f=l.$getSelection();if(!l.$isRangeSelection(f)||f.isCollapsed()||!k.objectKlassEquals(a,ClipboardEvent)||null===a.clipboardData)return!1;let g=a.clipboardData.getData("text");return d(g)?f.getNodes().some(h=>l.$isElementNode(h))?!1:(e.dispatchCommand(b.TOGGLE_LINK_COMMAND,g),a.preventDefault(),!0):!1},l.COMMAND_PRIORITY_LOW):()=>{})},[e,d]);return null}
@@ -0,0 +1,59 @@
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 { INSERT_ORDERED_LIST_COMMAND, insertList, INSERT_UNORDERED_LIST_COMMAND, REMOVE_LIST_COMMAND, removeList, $handleListInsertParagraph, ListNode, ListItemNode } from '@lexical/list';
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { useEffect } from 'react';
10
+ import { mergeRegister } from '@lexical/utils';
11
+ import { COMMAND_PRIORITY_LOW, INSERT_PARAGRAPH_COMMAND } from 'lexical';
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+ function useList(editor) {
21
+ useEffect(() => {
22
+ return mergeRegister(editor.registerCommand(INSERT_ORDERED_LIST_COMMAND, () => {
23
+ insertList(editor, 'number');
24
+ return true;
25
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_UNORDERED_LIST_COMMAND, () => {
26
+ insertList(editor, 'bullet');
27
+ return true;
28
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(REMOVE_LIST_COMMAND, () => {
29
+ removeList(editor);
30
+ return true;
31
+ }, COMMAND_PRIORITY_LOW), editor.registerCommand(INSERT_PARAGRAPH_COMMAND, () => {
32
+ const hasHandledInsertParagraph = $handleListInsertParagraph();
33
+ if (hasHandledInsertParagraph) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }, COMMAND_PRIORITY_LOW));
38
+ }, [editor]);
39
+ }
40
+
41
+ /**
42
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
43
+ *
44
+ * This source code is licensed under the MIT license found in the
45
+ * LICENSE file in the root directory of this source tree.
46
+ *
47
+ */
48
+ function ListPlugin() {
49
+ const [editor] = useLexicalComposerContext();
50
+ useEffect(() => {
51
+ if (!editor.hasNodes([ListNode, ListItemNode])) {
52
+ throw new Error('ListPlugin: ListNode and/or ListItemNode not registered on editor');
53
+ }
54
+ }, [editor]);
55
+ useList(editor);
56
+ return null;
57
+ }
58
+
59
+ export { ListPlugin };
@@ -0,0 +1,10 @@
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 './LexicalListPlugin.dev.esm.js';
8
+ import * as modProd from './LexicalListPlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const ListPlugin = mod.ListPlugin;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalListPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalListPlugin.dev.js') : require('./LexicalListPlugin.prod.js')
8
+ const LexicalListPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalListPlugin.dev.js') : require('./LexicalListPlugin.prod.js');
9
9
  module.exports = LexicalListPlugin;
@@ -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{INSERT_ORDERED_LIST_COMMAND as r,insertList as e,INSERT_UNORDERED_LIST_COMMAND as o,REMOVE_LIST_COMMAND as t,removeList as i,$handleListInsertParagraph as m,ListNode as n,ListItemNode as l}from"@lexical/list";import{useLexicalComposerContext as s}from"@lexical/react/LexicalComposerContext";import{useEffect as a}from"react";import{mergeRegister as c}from"@lexical/utils";import{COMMAND_PRIORITY_LOW as d,INSERT_PARAGRAPH_COMMAND as f}from"lexical";function u(){const[u]=s();return a((()=>{if(!u.hasNodes([n,l]))throw new Error("ListPlugin: ListNode and/or ListItemNode not registered on editor")}),[u]),function(n){a((()=>c(n.registerCommand(r,(()=>(e(n,"number"),!0)),d),n.registerCommand(o,(()=>(e(n,"bullet"),!0)),d),n.registerCommand(t,(()=>(i(n),!0)),d),n.registerCommand(f,(()=>!!m()),d))),[n])}(u),null}export{u as ListPlugin};
@@ -0,0 +1,49 @@
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 { TRANSFORMERS, registerMarkdownShortcuts } from '@lexical/markdown';
8
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import { HorizontalRuleNode, $isHorizontalRuleNode, $createHorizontalRuleNode } from '@lexical/react/LexicalHorizontalRuleNode';
10
+ import { useEffect } from 'react';
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
+ const HR = {
20
+ dependencies: [HorizontalRuleNode],
21
+ export: node => {
22
+ return $isHorizontalRuleNode(node) ? '***' : null;
23
+ },
24
+ regExp: /^(---|\*\*\*|___)\s?$/,
25
+ replace: (parentNode, _1, _2, isImport) => {
26
+ const line = $createHorizontalRuleNode();
27
+
28
+ // TODO: Get rid of isImport flag
29
+ if (isImport || parentNode.getNextSibling() != null) {
30
+ parentNode.replace(line);
31
+ } else {
32
+ parentNode.insertBefore(line);
33
+ }
34
+ line.selectNext();
35
+ },
36
+ type: 'element'
37
+ };
38
+ const DEFAULT_TRANSFORMERS = [HR, ...TRANSFORMERS];
39
+ function MarkdownShortcutPlugin({
40
+ transformers = DEFAULT_TRANSFORMERS
41
+ }) {
42
+ const [editor] = useLexicalComposerContext();
43
+ useEffect(() => {
44
+ return registerMarkdownShortcuts(editor, transformers);
45
+ }, [editor, transformers]);
46
+ return null;
47
+ }
48
+
49
+ export { DEFAULT_TRANSFORMERS, MarkdownShortcutPlugin };
@@ -0,0 +1,11 @@
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 './LexicalMarkdownShortcutPlugin.dev.esm.js';
8
+ import * as modProd from './LexicalMarkdownShortcutPlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const DEFAULT_TRANSFORMERS = mod.DEFAULT_TRANSFORMERS;
11
+ export const MarkdownShortcutPlugin = mod.MarkdownShortcutPlugin;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalMarkdownShortcutPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalMarkdownShortcutPlugin.dev.js') : require('./LexicalMarkdownShortcutPlugin.prod.js')
8
+ const LexicalMarkdownShortcutPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalMarkdownShortcutPlugin.dev.js') : require('./LexicalMarkdownShortcutPlugin.prod.js');
9
9
  module.exports = LexicalMarkdownShortcutPlugin;
@@ -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{TRANSFORMERS as e,registerMarkdownShortcuts as r}from"@lexical/markdown";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{HorizontalRuleNode as o,$isHorizontalRuleNode as l,$createHorizontalRuleNode as n}from"@lexical/react/LexicalHorizontalRuleNode";import{useEffect as c}from"react";const i=[{dependencies:[o],export:e=>l(e)?"***":null,regExp:/^(---|\*\*\*|___)\s?$/,replace:(e,r,t,o)=>{const l=n();o||null!=e.getNextSibling()?e.replace(l):e.insertBefore(l),l.selectNext()},type:"element"},...e];function a({transformers:e=i}){const[o]=t();return c((()=>r(o,e)),[o,e]),null}export{i as DEFAULT_TRANSFORMERS,a as MarkdownShortcutPlugin};
@@ -0,0 +1,105 @@
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 { useCollaborationContext } from '@lexical/react/LexicalCollaborationContext';
8
+ import { LexicalComposerContext, createLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
9
+ import * as React from 'react';
10
+ import { useRef, useContext, useMemo, useEffect } from 'react';
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
+ function LexicalNestedComposer({
20
+ initialEditor,
21
+ children,
22
+ initialNodes,
23
+ initialTheme,
24
+ skipCollabChecks
25
+ }) {
26
+ const wasCollabPreviouslyReadyRef = useRef(false);
27
+ const parentContext = useContext(LexicalComposerContext);
28
+ if (parentContext == null) {
29
+ {
30
+ throw Error(`Unexpected parent context null on a nested composer`);
31
+ }
32
+ }
33
+ const [parentEditor, {
34
+ getTheme: getParentTheme
35
+ }] = parentContext;
36
+ const composerContext = useMemo(() => {
37
+ const composerTheme = initialTheme || getParentTheme() || undefined;
38
+ const context = createLexicalComposerContext(parentContext, composerTheme);
39
+ if (composerTheme !== undefined) {
40
+ initialEditor._config.theme = composerTheme;
41
+ }
42
+ initialEditor._parentEditor = parentEditor;
43
+ if (!initialNodes) {
44
+ const parentNodes = initialEditor._nodes = new Map(parentEditor._nodes);
45
+ for (const [type, entry] of parentNodes) {
46
+ initialEditor._nodes.set(type, {
47
+ exportDOM: entry.exportDOM,
48
+ klass: entry.klass,
49
+ replace: entry.replace,
50
+ replaceWithKlass: entry.replaceWithKlass,
51
+ transforms: new Set()
52
+ });
53
+ }
54
+ } else {
55
+ for (let klass of initialNodes) {
56
+ let replace = null;
57
+ let replaceWithKlass = null;
58
+ if (typeof klass !== 'function') {
59
+ const options = klass;
60
+ klass = options.replace;
61
+ replace = options.with;
62
+ replaceWithKlass = options.withKlass || null;
63
+ }
64
+ const registeredKlass = initialEditor._nodes.get(klass.getType());
65
+ initialEditor._nodes.set(klass.getType(), {
66
+ exportDOM: registeredKlass ? registeredKlass.exportDOM : undefined,
67
+ klass,
68
+ replace,
69
+ replaceWithKlass,
70
+ transforms: new Set()
71
+ });
72
+ }
73
+ }
74
+ initialEditor._config.namespace = parentEditor._config.namespace;
75
+ initialEditor._editable = parentEditor._editable;
76
+ return [initialEditor, context];
77
+ },
78
+ // We only do this for init
79
+ // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ []);
81
+
82
+ // If collaboration is enabled, make sure we don't render the children until the collaboration subdocument is ready.
83
+ const {
84
+ isCollabActive,
85
+ yjsDocMap
86
+ } = useCollaborationContext();
87
+ const isCollabReady = skipCollabChecks || wasCollabPreviouslyReadyRef.current || yjsDocMap.has(initialEditor.getKey());
88
+ useEffect(() => {
89
+ if (isCollabReady) {
90
+ wasCollabPreviouslyReadyRef.current = true;
91
+ }
92
+ }, [isCollabReady]);
93
+
94
+ // Update `isEditable` state of nested editor in response to the same change on parent editor.
95
+ useEffect(() => {
96
+ return parentEditor.registerEditableListener(editable => {
97
+ initialEditor.setEditable(editable);
98
+ });
99
+ }, [initialEditor, parentEditor]);
100
+ return /*#__PURE__*/React.createElement(LexicalComposerContext.Provider, {
101
+ value: composerContext
102
+ }, !isCollabActive || isCollabReady ? children : null);
103
+ }
104
+
105
+ export { LexicalNestedComposer };