@lexical/react 0.14.5 → 0.16.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 (310) hide show
  1. package/LexicalAutoEmbedPlugin.dev.js +15 -11
  2. package/LexicalAutoEmbedPlugin.dev.mjs +5 -2
  3. package/LexicalAutoEmbedPlugin.js +2 -0
  4. package/LexicalAutoEmbedPlugin.mjs +2 -0
  5. package/LexicalAutoEmbedPlugin.node.mjs +2 -0
  6. package/LexicalAutoEmbedPlugin.prod.js +6 -5
  7. package/LexicalAutoEmbedPlugin.prod.mjs +3 -1
  8. package/LexicalAutoFocusPlugin.dev.js +3 -0
  9. package/LexicalAutoFocusPlugin.dev.mjs +3 -0
  10. package/LexicalAutoFocusPlugin.js +2 -0
  11. package/LexicalAutoFocusPlugin.mjs +2 -0
  12. package/LexicalAutoFocusPlugin.node.mjs +2 -0
  13. package/LexicalAutoFocusPlugin.prod.js +2 -0
  14. package/LexicalAutoFocusPlugin.prod.mjs +2 -0
  15. package/LexicalAutoLinkPlugin.dev.js +9 -4
  16. package/LexicalAutoLinkPlugin.dev.mjs +10 -5
  17. package/LexicalAutoLinkPlugin.js +2 -0
  18. package/LexicalAutoLinkPlugin.mjs +2 -0
  19. package/LexicalAutoLinkPlugin.node.mjs +2 -0
  20. package/LexicalAutoLinkPlugin.prod.js +12 -10
  21. package/LexicalAutoLinkPlugin.prod.mjs +3 -1
  22. package/LexicalBlockWithAlignableContents.dev.js +14 -9
  23. package/LexicalBlockWithAlignableContents.dev.mjs +11 -7
  24. package/LexicalBlockWithAlignableContents.js +2 -0
  25. package/LexicalBlockWithAlignableContents.mjs +2 -0
  26. package/LexicalBlockWithAlignableContents.node.mjs +2 -0
  27. package/LexicalBlockWithAlignableContents.prod.js +6 -4
  28. package/LexicalBlockWithAlignableContents.prod.mjs +3 -1
  29. package/LexicalCharacterLimitPlugin.dev.js +17 -12
  30. package/LexicalCharacterLimitPlugin.dev.mjs +12 -8
  31. package/LexicalCharacterLimitPlugin.js +2 -0
  32. package/LexicalCharacterLimitPlugin.mjs +2 -0
  33. package/LexicalCharacterLimitPlugin.node.mjs +2 -0
  34. package/LexicalCharacterLimitPlugin.prod.js +11 -9
  35. package/LexicalCharacterLimitPlugin.prod.mjs +3 -1
  36. package/LexicalCheckListPlugin.dev.js +5 -0
  37. package/LexicalCheckListPlugin.dev.mjs +5 -0
  38. package/LexicalCheckListPlugin.js +2 -0
  39. package/LexicalCheckListPlugin.mjs +2 -0
  40. package/LexicalCheckListPlugin.node.mjs +2 -0
  41. package/LexicalCheckListPlugin.prod.js +4 -2
  42. package/LexicalCheckListPlugin.prod.mjs +3 -1
  43. package/LexicalClearEditorPlugin.dev.js +9 -2
  44. package/LexicalClearEditorPlugin.dev.mjs +11 -4
  45. package/LexicalClearEditorPlugin.js +2 -0
  46. package/LexicalClearEditorPlugin.mjs +2 -0
  47. package/LexicalClearEditorPlugin.node.mjs +2 -0
  48. package/LexicalClearEditorPlugin.prod.js +3 -1
  49. package/LexicalClearEditorPlugin.prod.mjs +3 -1
  50. package/LexicalClickableLinkPlugin.d.ts +3 -1
  51. package/LexicalClickableLinkPlugin.dev.js +17 -15
  52. package/LexicalClickableLinkPlugin.dev.mjs +16 -15
  53. package/LexicalClickableLinkPlugin.js +2 -0
  54. package/LexicalClickableLinkPlugin.js.flow +3 -1
  55. package/LexicalClickableLinkPlugin.mjs +3 -0
  56. package/LexicalClickableLinkPlugin.node.mjs +3 -0
  57. package/LexicalClickableLinkPlugin.prod.js +6 -4
  58. package/LexicalClickableLinkPlugin.prod.mjs +3 -1
  59. package/LexicalCollaborationContext.dev.js +3 -0
  60. package/LexicalCollaborationContext.dev.mjs +3 -0
  61. package/LexicalCollaborationContext.js +2 -0
  62. package/LexicalCollaborationContext.mjs +2 -0
  63. package/LexicalCollaborationContext.node.mjs +2 -0
  64. package/LexicalCollaborationContext.prod.js +2 -0
  65. package/LexicalCollaborationContext.prod.mjs +2 -0
  66. package/LexicalCollaborationPlugin.dev.js +20 -2
  67. package/LexicalCollaborationPlugin.dev.mjs +6 -1
  68. package/LexicalCollaborationPlugin.js +2 -0
  69. package/LexicalCollaborationPlugin.mjs +2 -0
  70. package/LexicalCollaborationPlugin.node.mjs +2 -0
  71. package/LexicalCollaborationPlugin.prod.js +12 -10
  72. package/LexicalCollaborationPlugin.prod.mjs +3 -1
  73. package/LexicalComposer.dev.js +17 -8
  74. package/LexicalComposer.dev.mjs +16 -8
  75. package/LexicalComposer.js +2 -0
  76. package/LexicalComposer.mjs +2 -0
  77. package/LexicalComposer.node.mjs +2 -0
  78. package/LexicalComposer.prod.js +5 -4
  79. package/LexicalComposer.prod.mjs +3 -1
  80. package/LexicalComposerContext.dev.js +3 -0
  81. package/LexicalComposerContext.dev.mjs +3 -0
  82. package/LexicalComposerContext.js +2 -0
  83. package/LexicalComposerContext.mjs +2 -0
  84. package/LexicalComposerContext.node.mjs +2 -0
  85. package/LexicalComposerContext.prod.js +4 -2
  86. package/LexicalComposerContext.prod.mjs +3 -1
  87. package/LexicalContentEditable.dev.js +24 -23
  88. package/LexicalContentEditable.dev.mjs +22 -22
  89. package/LexicalContentEditable.js +2 -0
  90. package/LexicalContentEditable.mjs +2 -0
  91. package/LexicalContentEditable.node.mjs +2 -0
  92. package/LexicalContentEditable.prod.js +5 -3
  93. package/LexicalContentEditable.prod.mjs +3 -1
  94. package/LexicalContextMenuPlugin.dev.js +29 -7
  95. package/LexicalContextMenuPlugin.dev.mjs +17 -8
  96. package/LexicalContextMenuPlugin.js +2 -0
  97. package/LexicalContextMenuPlugin.js.flow +12 -0
  98. package/LexicalContextMenuPlugin.mjs +2 -0
  99. package/LexicalContextMenuPlugin.node.mjs +2 -0
  100. package/LexicalContextMenuPlugin.prod.js +18 -16
  101. package/LexicalContextMenuPlugin.prod.mjs +3 -1
  102. package/LexicalDecoratorBlockNode.d.ts +1 -0
  103. package/LexicalDecoratorBlockNode.dev.js +6 -0
  104. package/LexicalDecoratorBlockNode.dev.mjs +6 -0
  105. package/LexicalDecoratorBlockNode.js +2 -0
  106. package/LexicalDecoratorBlockNode.mjs +2 -0
  107. package/LexicalDecoratorBlockNode.node.mjs +2 -0
  108. package/LexicalDecoratorBlockNode.prod.js +3 -1
  109. package/LexicalDecoratorBlockNode.prod.mjs +3 -1
  110. package/LexicalEditorRefPlugin.dev.js +17 -1
  111. package/LexicalEditorRefPlugin.dev.mjs +3 -0
  112. package/LexicalEditorRefPlugin.js +2 -0
  113. package/LexicalEditorRefPlugin.js.flow +19 -0
  114. package/LexicalEditorRefPlugin.mjs +2 -0
  115. package/LexicalEditorRefPlugin.node.mjs +2 -0
  116. package/LexicalEditorRefPlugin.prod.js +3 -1
  117. package/LexicalEditorRefPlugin.prod.mjs +2 -0
  118. package/LexicalErrorBoundary.d.ts +3 -1
  119. package/LexicalErrorBoundary.dev.js +30 -10
  120. package/LexicalErrorBoundary.dev.mjs +13 -7
  121. package/LexicalErrorBoundary.js +2 -0
  122. package/LexicalErrorBoundary.js.flow +4 -1
  123. package/LexicalErrorBoundary.mjs +3 -0
  124. package/LexicalErrorBoundary.node.mjs +3 -0
  125. package/LexicalErrorBoundary.prod.js +6 -4
  126. package/LexicalErrorBoundary.prod.mjs +3 -1
  127. package/LexicalHashtagPlugin.dev.js +5 -2
  128. package/LexicalHashtagPlugin.dev.mjs +5 -2
  129. package/LexicalHashtagPlugin.js +2 -0
  130. package/LexicalHashtagPlugin.mjs +2 -0
  131. package/LexicalHashtagPlugin.node.mjs +2 -0
  132. package/LexicalHashtagPlugin.prod.js +2 -0
  133. package/LexicalHashtagPlugin.prod.mjs +2 -0
  134. package/LexicalHistoryPlugin.dev.js +4 -0
  135. package/LexicalHistoryPlugin.dev.mjs +4 -0
  136. package/LexicalHistoryPlugin.js +2 -0
  137. package/LexicalHistoryPlugin.mjs +2 -0
  138. package/LexicalHistoryPlugin.node.mjs +2 -0
  139. package/LexicalHistoryPlugin.prod.js +2 -0
  140. package/LexicalHistoryPlugin.prod.mjs +2 -0
  141. package/LexicalHorizontalRuleNode.d.ts +2 -2
  142. package/LexicalHorizontalRuleNode.dev.js +23 -12
  143. package/LexicalHorizontalRuleNode.dev.mjs +21 -11
  144. package/LexicalHorizontalRuleNode.js +2 -0
  145. package/LexicalHorizontalRuleNode.mjs +2 -0
  146. package/LexicalHorizontalRuleNode.node.mjs +2 -0
  147. package/LexicalHorizontalRuleNode.prod.js +7 -5
  148. package/LexicalHorizontalRuleNode.prod.mjs +3 -1
  149. package/LexicalHorizontalRulePlugin.dev.js +3 -0
  150. package/LexicalHorizontalRulePlugin.dev.mjs +3 -0
  151. package/LexicalHorizontalRulePlugin.js +2 -0
  152. package/LexicalHorizontalRulePlugin.mjs +2 -0
  153. package/LexicalHorizontalRulePlugin.node.mjs +2 -0
  154. package/LexicalHorizontalRulePlugin.prod.js +2 -0
  155. package/LexicalHorizontalRulePlugin.prod.mjs +2 -0
  156. package/LexicalLinkPlugin.dev.js +6 -3
  157. package/LexicalLinkPlugin.dev.mjs +7 -4
  158. package/LexicalLinkPlugin.js +2 -0
  159. package/LexicalLinkPlugin.mjs +2 -0
  160. package/LexicalLinkPlugin.node.mjs +2 -0
  161. package/LexicalLinkPlugin.prod.js +3 -1
  162. package/LexicalLinkPlugin.prod.mjs +3 -1
  163. package/LexicalListPlugin.dev.js +4 -0
  164. package/LexicalListPlugin.dev.mjs +4 -0
  165. package/LexicalListPlugin.js +2 -0
  166. package/LexicalListPlugin.mjs +2 -0
  167. package/LexicalListPlugin.node.mjs +2 -0
  168. package/LexicalListPlugin.prod.js +2 -0
  169. package/LexicalListPlugin.prod.mjs +2 -0
  170. package/LexicalMarkdownShortcutPlugin.dev.js +3 -0
  171. package/LexicalMarkdownShortcutPlugin.dev.mjs +3 -0
  172. package/LexicalMarkdownShortcutPlugin.js +2 -0
  173. package/LexicalMarkdownShortcutPlugin.mjs +2 -0
  174. package/LexicalMarkdownShortcutPlugin.node.mjs +2 -0
  175. package/LexicalMarkdownShortcutPlugin.prod.js +2 -0
  176. package/LexicalMarkdownShortcutPlugin.prod.mjs +2 -0
  177. package/LexicalNestedComposer.dev.js +14 -9
  178. package/LexicalNestedComposer.dev.mjs +8 -4
  179. package/LexicalNestedComposer.js +2 -0
  180. package/LexicalNestedComposer.mjs +2 -0
  181. package/LexicalNestedComposer.node.mjs +2 -0
  182. package/LexicalNestedComposer.prod.js +7 -5
  183. package/LexicalNestedComposer.prod.mjs +3 -1
  184. package/LexicalNodeEventPlugin.dev.js +3 -0
  185. package/LexicalNodeEventPlugin.dev.mjs +3 -0
  186. package/LexicalNodeEventPlugin.js +2 -0
  187. package/LexicalNodeEventPlugin.js.flow +12 -0
  188. package/LexicalNodeEventPlugin.mjs +2 -0
  189. package/LexicalNodeEventPlugin.node.mjs +2 -0
  190. package/LexicalNodeEventPlugin.prod.js +2 -0
  191. package/LexicalNodeEventPlugin.prod.mjs +2 -0
  192. package/LexicalNodeMenuPlugin.dev.js +30 -8
  193. package/LexicalNodeMenuPlugin.dev.mjs +17 -8
  194. package/LexicalNodeMenuPlugin.js +2 -0
  195. package/LexicalNodeMenuPlugin.mjs +2 -0
  196. package/LexicalNodeMenuPlugin.node.mjs +2 -0
  197. package/LexicalNodeMenuPlugin.prod.js +17 -15
  198. package/LexicalNodeMenuPlugin.prod.mjs +3 -1
  199. package/LexicalOnChangePlugin.dev.js +9 -2
  200. package/LexicalOnChangePlugin.dev.mjs +11 -4
  201. package/LexicalOnChangePlugin.js +2 -0
  202. package/LexicalOnChangePlugin.mjs +2 -0
  203. package/LexicalOnChangePlugin.node.mjs +2 -0
  204. package/LexicalOnChangePlugin.prod.js +3 -1
  205. package/LexicalOnChangePlugin.prod.mjs +3 -1
  206. package/LexicalPlainTextPlugin.dev.js +34 -19
  207. package/LexicalPlainTextPlugin.dev.mjs +31 -17
  208. package/LexicalPlainTextPlugin.js +2 -0
  209. package/LexicalPlainTextPlugin.js.flow +1 -1
  210. package/LexicalPlainTextPlugin.mjs +2 -0
  211. package/LexicalPlainTextPlugin.node.mjs +2 -0
  212. package/LexicalPlainTextPlugin.prod.js +6 -4
  213. package/LexicalPlainTextPlugin.prod.mjs +3 -1
  214. package/LexicalRichTextPlugin.dev.js +34 -19
  215. package/LexicalRichTextPlugin.dev.mjs +31 -17
  216. package/LexicalRichTextPlugin.js +2 -0
  217. package/LexicalRichTextPlugin.js.flow +1 -1
  218. package/LexicalRichTextPlugin.mjs +2 -0
  219. package/LexicalRichTextPlugin.node.mjs +2 -0
  220. package/LexicalRichTextPlugin.prod.js +6 -4
  221. package/LexicalRichTextPlugin.prod.mjs +3 -1
  222. package/LexicalTabIndentationPlugin.dev.js +5 -2
  223. package/LexicalTabIndentationPlugin.dev.mjs +5 -2
  224. package/LexicalTabIndentationPlugin.js +2 -0
  225. package/LexicalTabIndentationPlugin.mjs +2 -0
  226. package/LexicalTabIndentationPlugin.node.mjs +2 -0
  227. package/LexicalTabIndentationPlugin.prod.js +2 -0
  228. package/LexicalTabIndentationPlugin.prod.mjs +2 -0
  229. package/LexicalTableOfContents.d.ts +6 -13
  230. package/LexicalTableOfContents.dev.js +57 -10
  231. package/LexicalTableOfContents.dev.mjs +58 -11
  232. package/LexicalTableOfContents.js +2 -0
  233. package/LexicalTableOfContents.js.flow +3 -7
  234. package/LexicalTableOfContents.mjs +2 -0
  235. package/LexicalTableOfContents.node.mjs +2 -0
  236. package/LexicalTableOfContents.prod.js +6 -4
  237. package/LexicalTableOfContents.prod.mjs +3 -1
  238. package/LexicalTableOfContentsPlugin.d.ts +20 -0
  239. package/LexicalTableOfContentsPlugin.dev.js +198 -0
  240. package/LexicalTableOfContentsPlugin.dev.mjs +196 -0
  241. package/LexicalTableOfContentsPlugin.js +11 -0
  242. package/LexicalTableOfContentsPlugin.js.flow +18 -0
  243. package/LexicalTableOfContentsPlugin.mjs +12 -0
  244. package/LexicalTableOfContentsPlugin.node.mjs +10 -0
  245. package/LexicalTableOfContentsPlugin.prod.js +12 -0
  246. package/LexicalTableOfContentsPlugin.prod.mjs +9 -0
  247. package/LexicalTablePlugin.dev.js +28 -2
  248. package/LexicalTablePlugin.dev.mjs +31 -5
  249. package/LexicalTablePlugin.js +2 -0
  250. package/LexicalTablePlugin.mjs +2 -0
  251. package/LexicalTablePlugin.node.mjs +2 -0
  252. package/LexicalTablePlugin.prod.js +9 -5
  253. package/LexicalTablePlugin.prod.mjs +3 -1
  254. package/LexicalTreeView.d.ts +3 -1
  255. package/LexicalTreeView.dev.js +22 -4
  256. package/LexicalTreeView.dev.mjs +8 -3
  257. package/LexicalTreeView.js +2 -0
  258. package/LexicalTreeView.js.flow +2 -0
  259. package/LexicalTreeView.mjs +2 -0
  260. package/LexicalTreeView.node.mjs +2 -0
  261. package/LexicalTreeView.prod.js +5 -3
  262. package/LexicalTreeView.prod.mjs +3 -1
  263. package/LexicalTypeaheadMenuPlugin.dev.js +30 -8
  264. package/LexicalTypeaheadMenuPlugin.dev.mjs +17 -8
  265. package/LexicalTypeaheadMenuPlugin.js +2 -0
  266. package/LexicalTypeaheadMenuPlugin.mjs +2 -0
  267. package/LexicalTypeaheadMenuPlugin.node.mjs +2 -0
  268. package/LexicalTypeaheadMenuPlugin.prod.js +21 -19
  269. package/LexicalTypeaheadMenuPlugin.prod.mjs +3 -1
  270. package/package.json +50 -20
  271. package/shared/useCharacterLimit.d.ts +1 -1
  272. package/useLexicalEditable.d.ts +11 -1
  273. package/useLexicalEditable.dev.js +22 -3
  274. package/useLexicalEditable.dev.mjs +23 -5
  275. package/useLexicalEditable.js +2 -0
  276. package/useLexicalEditable.js.flow +4 -1
  277. package/useLexicalEditable.mjs +4 -1
  278. package/useLexicalEditable.node.mjs +4 -1
  279. package/useLexicalEditable.prod.js +4 -2
  280. package/useLexicalEditable.prod.mjs +3 -1
  281. package/useLexicalIsTextContentEmpty.dev.js +9 -2
  282. package/useLexicalIsTextContentEmpty.dev.mjs +11 -4
  283. package/useLexicalIsTextContentEmpty.js +2 -0
  284. package/useLexicalIsTextContentEmpty.mjs +2 -0
  285. package/useLexicalIsTextContentEmpty.node.mjs +2 -0
  286. package/useLexicalIsTextContentEmpty.prod.js +3 -1
  287. package/useLexicalIsTextContentEmpty.prod.mjs +3 -1
  288. package/useLexicalNodeSelection.dev.js +3 -0
  289. package/useLexicalNodeSelection.dev.mjs +4 -1
  290. package/useLexicalNodeSelection.js +2 -0
  291. package/useLexicalNodeSelection.mjs +2 -0
  292. package/useLexicalNodeSelection.node.mjs +2 -0
  293. package/useLexicalNodeSelection.prod.js +2 -0
  294. package/useLexicalNodeSelection.prod.mjs +3 -1
  295. package/useLexicalSubscription.d.ts +4 -1
  296. package/useLexicalSubscription.dev.js +12 -3
  297. package/useLexicalSubscription.dev.mjs +13 -5
  298. package/useLexicalSubscription.js +2 -0
  299. package/useLexicalSubscription.js.flow +4 -1
  300. package/useLexicalSubscription.mjs +4 -1
  301. package/useLexicalSubscription.node.mjs +4 -1
  302. package/useLexicalSubscription.prod.js +4 -2
  303. package/useLexicalSubscription.prod.mjs +3 -1
  304. package/useLexicalTextEntity.dev.js +3 -0
  305. package/useLexicalTextEntity.dev.mjs +3 -0
  306. package/useLexicalTextEntity.js +2 -0
  307. package/useLexicalTextEntity.mjs +2 -0
  308. package/useLexicalTextEntity.node.mjs +2 -0
  309. package/useLexicalTextEntity.prod.js +2 -0
  310. package/useLexicalTextEntity.prod.mjs +2 -0
@@ -3,15 +3,18 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
12
  var useLexicalEditable = require('@lexical/react/useLexicalEditable');
11
- var React = require('react');
12
13
  var text = require('@lexical/text');
13
14
  var utils = require('@lexical/utils');
15
+ var react = require('react');
14
16
  var reactDom = require('react-dom');
17
+ var jsxRuntime = require('react/jsx-runtime');
15
18
  var dragon = require('@lexical/dragon');
16
19
  var richText = require('@lexical/rich-text');
17
20
 
@@ -32,8 +35,12 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
32
35
  * LICENSE file in the root directory of this source tree.
33
36
  *
34
37
  */
35
- const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffect;
36
- var useLayoutEffect = useLayoutEffectImpl;
38
+
39
+
40
+ // This workaround is no longer necessary in React 19,
41
+ // but we currently support React >=17.x
42
+ // https://github.com/facebook/react/pull/26395
43
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
37
44
 
38
45
  /**
39
46
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -42,13 +49,14 @@ var useLayoutEffect = useLayoutEffectImpl;
42
49
  * LICENSE file in the root directory of this source tree.
43
50
  *
44
51
  */
52
+
45
53
  function canShowPlaceholderFromCurrentEditorState(editor) {
46
54
  const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
47
55
  return currentCanShowPlaceholder;
48
56
  }
49
57
  function useCanShowPlaceholder(editor) {
50
- const [canShowPlaceholder, setCanShowPlaceholder] = React.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
51
- useLayoutEffect(() => {
58
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
59
+ useLayoutEffectImpl(() => {
52
60
  function resetCanShowPlaceholder() {
53
61
  const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
54
62
  setCanShowPlaceholder(currentCanShowPlaceholder);
@@ -70,18 +78,19 @@ function useCanShowPlaceholder(editor) {
70
78
  * LICENSE file in the root directory of this source tree.
71
79
  *
72
80
  */
81
+
73
82
  function useDecorators(editor, ErrorBoundary) {
74
- const [decorators, setDecorators] = React.useState(() => editor.getDecorators());
83
+ const [decorators, setDecorators] = react.useState(() => editor.getDecorators());
75
84
 
76
85
  // Subscribe to changes
77
- useLayoutEffect(() => {
86
+ useLayoutEffectImpl(() => {
78
87
  return editor.registerDecoratorListener(nextDecorators => {
79
88
  reactDom.flushSync(() => {
80
89
  setDecorators(nextDecorators);
81
90
  });
82
91
  });
83
92
  }, [editor]);
84
- React.useEffect(() => {
93
+ react.useEffect(() => {
85
94
  // If the content editable mounts before the subscription is added, then
86
95
  // nothing will be rendered on initial pass. We can get around that by
87
96
  // ensuring that we set the value.
@@ -89,16 +98,18 @@ function useDecorators(editor, ErrorBoundary) {
89
98
  }, [editor]);
90
99
 
91
100
  // Return decorators defined as React Portals
92
- return React.useMemo(() => {
101
+ return react.useMemo(() => {
93
102
  const decoratedPortals = [];
94
103
  const decoratorKeys = Object.keys(decorators);
95
104
  for (let i = 0; i < decoratorKeys.length; i++) {
96
105
  const nodeKey = decoratorKeys[i];
97
- const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
98
- onError: e => editor._onError(e)
99
- }, /*#__PURE__*/React.createElement(React.Suspense, {
100
- fallback: null
101
- }, decorators[nodeKey]));
106
+ const reactDecorator = /*#__PURE__*/jsxRuntime.jsx(ErrorBoundary, {
107
+ onError: e => editor._onError(e),
108
+ children: /*#__PURE__*/jsxRuntime.jsx(react.Suspense, {
109
+ fallback: null,
110
+ children: decorators[nodeKey]
111
+ })
112
+ });
102
113
  const element = editor.getElementByKey(nodeKey);
103
114
  if (element !== null) {
104
115
  decoratedPortals.push( /*#__PURE__*/reactDom.createPortal(reactDecorator, element, nodeKey));
@@ -115,8 +126,9 @@ function useDecorators(editor, ErrorBoundary) {
115
126
  * LICENSE file in the root directory of this source tree.
116
127
  *
117
128
  */
129
+
118
130
  function useRichTextSetup(editor) {
119
- useLayoutEffect(() => {
131
+ useLayoutEffectImpl(() => {
120
132
  return utils.mergeRegister(richText.registerRichText(editor), dragon.registerDragonSupport(editor));
121
133
 
122
134
  // We only do this for init
@@ -131,6 +143,7 @@ function useRichTextSetup(editor) {
131
143
  * LICENSE file in the root directory of this source tree.
132
144
  *
133
145
  */
146
+
134
147
  function RichTextPlugin({
135
148
  contentEditable,
136
149
  placeholder,
@@ -139,16 +152,18 @@ function RichTextPlugin({
139
152
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
140
153
  const decorators = useDecorators(editor, ErrorBoundary);
141
154
  useRichTextSetup(editor);
142
- return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
143
- content: placeholder
144
- }), decorators);
155
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
156
+ children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
157
+ content: placeholder
158
+ }), decorators]
159
+ });
145
160
  }
146
161
  function Placeholder({
147
162
  content
148
163
  }) {
149
164
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
150
165
  const showPlaceholder = useCanShowPlaceholder(editor);
151
- const editable = useLexicalEditable();
166
+ const editable = useLexicalEditable.useLexicalEditable();
152
167
  if (!showPlaceholder) {
153
168
  return null;
154
169
  }
@@ -3,14 +3,16 @@
3
3
  *
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
  */
8
+
7
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
- import useLexicalEditable from '@lexical/react/useLexicalEditable';
9
- import * as React from 'react';
10
- import { useLayoutEffect as useLayoutEffect$1, useEffect, useState, useMemo, Suspense } from 'react';
10
+ import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
11
11
  import { $canShowPlaceholderCurry } from '@lexical/text';
12
12
  import { mergeRegister } from '@lexical/utils';
13
- import { createPortal, flushSync } from 'react-dom';
13
+ import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
14
+ import { flushSync, createPortal } from 'react-dom';
15
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
14
16
  import { registerDragonSupport } from '@lexical/dragon';
15
17
  import { registerRichText } from '@lexical/rich-text';
16
18
 
@@ -31,8 +33,12 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
31
33
  * LICENSE file in the root directory of this source tree.
32
34
  *
33
35
  */
34
- const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect$1 : useEffect;
35
- var useLayoutEffect = useLayoutEffectImpl;
36
+
37
+
38
+ // This workaround is no longer necessary in React 19,
39
+ // but we currently support React >=17.x
40
+ // https://github.com/facebook/react/pull/26395
41
+ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
36
42
 
37
43
  /**
38
44
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -41,13 +47,14 @@ var useLayoutEffect = useLayoutEffectImpl;
41
47
  * LICENSE file in the root directory of this source tree.
42
48
  *
43
49
  */
50
+
44
51
  function canShowPlaceholderFromCurrentEditorState(editor) {
45
52
  const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
46
53
  return currentCanShowPlaceholder;
47
54
  }
48
55
  function useCanShowPlaceholder(editor) {
49
56
  const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
50
- useLayoutEffect(() => {
57
+ useLayoutEffectImpl(() => {
51
58
  function resetCanShowPlaceholder() {
52
59
  const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
53
60
  setCanShowPlaceholder(currentCanShowPlaceholder);
@@ -69,11 +76,12 @@ function useCanShowPlaceholder(editor) {
69
76
  * LICENSE file in the root directory of this source tree.
70
77
  *
71
78
  */
79
+
72
80
  function useDecorators(editor, ErrorBoundary) {
73
81
  const [decorators, setDecorators] = useState(() => editor.getDecorators());
74
82
 
75
83
  // Subscribe to changes
76
- useLayoutEffect(() => {
84
+ useLayoutEffectImpl(() => {
77
85
  return editor.registerDecoratorListener(nextDecorators => {
78
86
  flushSync(() => {
79
87
  setDecorators(nextDecorators);
@@ -93,11 +101,13 @@ function useDecorators(editor, ErrorBoundary) {
93
101
  const decoratorKeys = Object.keys(decorators);
94
102
  for (let i = 0; i < decoratorKeys.length; i++) {
95
103
  const nodeKey = decoratorKeys[i];
96
- const reactDecorator = /*#__PURE__*/React.createElement(ErrorBoundary, {
97
- onError: e => editor._onError(e)
98
- }, /*#__PURE__*/React.createElement(Suspense, {
99
- fallback: null
100
- }, decorators[nodeKey]));
104
+ const reactDecorator = /*#__PURE__*/jsx(ErrorBoundary, {
105
+ onError: e => editor._onError(e),
106
+ children: /*#__PURE__*/jsx(Suspense, {
107
+ fallback: null,
108
+ children: decorators[nodeKey]
109
+ })
110
+ });
101
111
  const element = editor.getElementByKey(nodeKey);
102
112
  if (element !== null) {
103
113
  decoratedPortals.push( /*#__PURE__*/createPortal(reactDecorator, element, nodeKey));
@@ -114,8 +124,9 @@ function useDecorators(editor, ErrorBoundary) {
114
124
  * LICENSE file in the root directory of this source tree.
115
125
  *
116
126
  */
127
+
117
128
  function useRichTextSetup(editor) {
118
- useLayoutEffect(() => {
129
+ useLayoutEffectImpl(() => {
119
130
  return mergeRegister(registerRichText(editor), registerDragonSupport(editor));
120
131
 
121
132
  // We only do this for init
@@ -130,6 +141,7 @@ function useRichTextSetup(editor) {
130
141
  * LICENSE file in the root directory of this source tree.
131
142
  *
132
143
  */
144
+
133
145
  function RichTextPlugin({
134
146
  contentEditable,
135
147
  placeholder,
@@ -138,9 +150,11 @@ function RichTextPlugin({
138
150
  const [editor] = useLexicalComposerContext();
139
151
  const decorators = useDecorators(editor, ErrorBoundary);
140
152
  useRichTextSetup(editor);
141
- return /*#__PURE__*/React.createElement(React.Fragment, null, contentEditable, /*#__PURE__*/React.createElement(Placeholder, {
142
- content: placeholder
143
- }), decorators);
153
+ return /*#__PURE__*/jsxs(Fragment, {
154
+ children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
155
+ content: placeholder
156
+ }), decorators]
157
+ });
144
158
  }
145
159
  function Placeholder({
146
160
  content
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict'
8
10
  const LexicalRichTextPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalRichTextPlugin.dev.js') : require('./LexicalRichTextPlugin.prod.js');
9
11
  module.exports = LexicalRichTextPlugin;
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type {EditorState, LexicalEditor} from 'lexical';
11
11
 
12
- import typeof LexicalErrorBoundary from '@lexical/react/LexicalErrorBoundary';
12
+ import {typeof LexicalErrorBoundary} from '@lexical/react/LexicalErrorBoundary';
13
13
 
14
14
  import * as React from 'react';
15
15
 
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  import * as modDev from './LexicalRichTextPlugin.dev.mjs';
8
10
  import * as modProd from './LexicalRichTextPlugin.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
@@ -3,6 +3,8 @@
3
3
  *
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
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalRichTextPlugin.dev.mjs') : import('./LexicalRichTextPlugin.prod.mjs'));
8
10
  export const RichTextPlugin = mod.RichTextPlugin;
@@ -3,8 +3,10 @@
3
3
  *
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
  */
7
- 'use strict';var b=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),l=require("react"),m=require("@lexical/text"),n=require("@lexical/utils"),p=require("react-dom"),t=require("@lexical/dragon"),u=require("@lexical/rich-text"),v="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;
8
- function w(a){return a.getEditorState().read(m.$canShowPlaceholderCurry(a.isComposing()))}function x(a){let [d,c]=l.useState(()=>w(a));v(()=>{function e(){let f=w(a);c(f)}e();return n.mergeRegister(a.registerUpdateListener(()=>{e()}),a.registerEditableListener(()=>{e()}))},[a]);return d}
9
- function y(a,d){let [c,e]=l.useState(()=>a.getDecorators());v(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{e(f)})}),[a]);l.useEffect(()=>{e(a.getDecorators())},[a]);return l.useMemo(()=>{let f=[],q=Object.keys(c);for(let h=0;h<q.length;h++){let k=q[h],A=l.createElement(d,{onError:z=>a._onError(z)},l.createElement(l.Suspense,{fallback:null},c[k])),r=a.getElementByKey(k);null!==r&&f.push(p.createPortal(A,r,k))}return f},[d,c,a])}
10
- function B(a){v(()=>n.mergeRegister(u.registerRichText(a),t.registerDragonSupport(a)),[a])}function C({content:a}){var [d]=b.useLexicalComposerContext();d=x(d);let c=g();return d?"function"===typeof a?a(c):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:d,ErrorBoundary:c}){let [e]=b.useLexicalComposerContext();c=y(e,c);B(e);return l.createElement(l.Fragment,null,a,l.createElement(C,{content:d}),c)}
8
+
9
+ 'use strict';var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/react/useLexicalEditable"),h=require("@lexical/text"),m=require("@lexical/utils"),n=require("react"),p=require("react-dom"),q=require("react/jsx-runtime"),u=require("@lexical/dragon"),v=require("@lexical/rich-text");let w="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
10
+ function x(a){return a.getEditorState().read(h.$canShowPlaceholderCurry(a.isComposing()))}function y(a){let [c,b]=n.useState(()=>x(a));w(()=>{function d(){let f=x(a);b(f)}d();return m.mergeRegister(a.registerUpdateListener(()=>{d()}),a.registerEditableListener(()=>{d()}))},[a]);return c}
11
+ function z(a,c){let [b,d]=n.useState(()=>a.getDecorators());w(()=>a.registerDecoratorListener(f=>{p.flushSync(()=>{d(f)})}),[a]);n.useEffect(()=>{d(a.getDecorators())},[a]);return n.useMemo(()=>{let f=[],r=Object.keys(b);for(let k=0;k<r.length;k++){let l=r[k],B=q.jsx(c,{onError:A=>a._onError(A),children:q.jsx(n.Suspense,{fallback:null,children:b[l]})}),t=a.getElementByKey(l);null!==t&&f.push(p.createPortal(B,t,l))}return f},[c,b,a])}
12
+ function C(a){w(()=>m.mergeRegister(v.registerRichText(a),u.registerDragonSupport(a)),[a])}function D({content:a}){var [c]=e.useLexicalComposerContext();c=y(c);let b=g.useLexicalEditable();return c?"function"===typeof a?a(b):a:null}exports.RichTextPlugin=function({contentEditable:a,placeholder:c,ErrorBoundary:b}){let [d]=e.useLexicalComposerContext();b=z(d,b);C(d);return q.jsxs(q.Fragment,{children:[a,q.jsx(D,{content:c}),b]})}
@@ -3,5 +3,7 @@
3
3
  *
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
  */
7
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import t from"@lexical/react/useLexicalEditable";import*as r from"react";import{useLayoutEffect as o,useEffect as n,useState as c,useMemo as i,Suspense as l}from"react";import{$canShowPlaceholderCurry as a}from"@lexical/text";import{mergeRegister as m}from"@lexical/utils";import{createPortal as u,flushSync as s}from"react-dom";import{registerDragonSupport as f}from"@lexical/dragon";import{registerRichText as d}from"@lexical/rich-text";var p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o:n;function E(e){return e.getEditorState().read(a(e.isComposing()))}function x({contentEditable:t,placeholder:o,ErrorBoundary:a}){const[E]=e(),x=function(e,t){const[o,a]=c((()=>e.getDecorators()));return p((()=>e.registerDecoratorListener((e=>{s((()=>{a(e)}))}))),[e]),n((()=>{a(e.getDecorators())}),[e]),i((()=>{const n=[],c=Object.keys(o);for(let i=0;i<c.length;i++){const a=c[i],m=r.createElement(t,{onError:t=>e._onError(t)},r.createElement(l,{fallback:null},o[a])),s=e.getElementByKey(a);null!==s&&n.push(u(m,s,a))}return n}),[t,o,e])}(E,a);return function(e){p((()=>m(d(e),f(e))),[e])}(E),r.createElement(r.Fragment,null,t,r.createElement(g,{content:o}),x)}function g({content:r}){const[o]=e(),n=function(e){const[t,r]=c((()=>E(e)));return p((()=>{function t(){const t=E(e);r(t)}return t(),m(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(o),i=t();return n?"function"==typeof r?r(i):r:null}export{x as RichTextPlugin};
8
+
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as m,createPortal as u}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerRichText as x}from"@lexical/rich-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{m((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),m=t.getElementByKey(c);null!==m&&o.push(u(l,m,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as RichTextPlugin};
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
@@ -18,7 +20,8 @@ var react = require('react');
18
20
  * LICENSE file in the root directory of this source tree.
19
21
  *
20
22
  */
21
- function indentOverTab(selection) {
23
+
24
+ function $indentOverTab(selection) {
22
25
  // const handled = new Set();
23
26
  const nodes = selection.getNodes();
24
27
  const canIndentBlockNodes = utils.$filter(nodes, node => {
@@ -57,7 +60,7 @@ function registerTabIndentation(editor) {
57
60
  return false;
58
61
  }
59
62
  event.preventDefault();
60
- const command = indentOverTab(selection) ? event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND : lexical.INSERT_TAB_COMMAND;
63
+ const command = $indentOverTab(selection) ? event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND : lexical.INSERT_TAB_COMMAND;
61
64
  return editor.dispatchCommand(command, undefined);
62
65
  }, lexical.COMMAND_PRIORITY_EDITOR);
63
66
  }
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
10
  import { $filter, $getNearestBlockElementAncestorOrThrow } from '@lexical/utils';
9
11
  import { KEY_TAB_COMMAND, $getSelection, $isRangeSelection, OUTDENT_CONTENT_COMMAND, INDENT_CONTENT_COMMAND, INSERT_TAB_COMMAND, COMMAND_PRIORITY_EDITOR, $isBlockElementNode, $createRangeSelection, $normalizeSelection__EXPERIMENTAL } from 'lexical';
@@ -16,7 +18,8 @@ import { useEffect } from 'react';
16
18
  * LICENSE file in the root directory of this source tree.
17
19
  *
18
20
  */
19
- function indentOverTab(selection) {
21
+
22
+ function $indentOverTab(selection) {
20
23
  // const handled = new Set();
21
24
  const nodes = selection.getNodes();
22
25
  const canIndentBlockNodes = $filter(nodes, node => {
@@ -55,7 +58,7 @@ function registerTabIndentation(editor) {
55
58
  return false;
56
59
  }
57
60
  event.preventDefault();
58
- const command = indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
61
+ const command = $indentOverTab(selection) ? event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND : INSERT_TAB_COMMAND;
59
62
  return editor.dispatchCommand(command, undefined);
60
63
  }, COMMAND_PRIORITY_EDITOR);
61
64
  }
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict'
8
10
  const LexicalTabIndentationPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTabIndentationPlugin.dev.js') : require('./LexicalTabIndentationPlugin.prod.js');
9
11
  module.exports = LexicalTabIndentationPlugin;
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  import * as modDev from './LexicalTabIndentationPlugin.dev.mjs';
8
10
  import * as modProd from './LexicalTabIndentationPlugin.prod.mjs';
9
11
  const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalTabIndentationPlugin.dev.mjs') : import('./LexicalTabIndentationPlugin.prod.mjs'));
8
10
  export const TabIndentationPlugin = mod.TabIndentationPlugin;
9
11
  export const registerTabIndentation = mod.registerTabIndentation;
@@ -3,7 +3,9 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';var d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/utils"),f=require("lexical"),g=require("react");
8
10
  function h(b){var a=b.getNodes();if(0<e.$filter(a,c=>f.$isBlockElementNode(c)&&c.canIndent()?c:null).length)return!0;a=b.anchor;b=b.focus;b=b.isBefore(a)?b:a;a=b.getNode();a=e.$getNearestBlockElementAncestorOrThrow(a);if(a.canIndent()){a=a.getKey();let c=f.$createRangeSelection();c.anchor.set(a,0,"element");c.focus.set(a,0,"element");c=f.$normalizeSelection__EXPERIMENTAL(c);if(c.anchor.is(b))return!0}return!1}
9
11
  function k(b){return b.registerCommand(f.KEY_TAB_COMMAND,a=>{let c=f.$getSelection();if(!f.$isRangeSelection(c))return!1;a.preventDefault();a=h(c)?a.shiftKey?f.OUTDENT_CONTENT_COMMAND:f.INDENT_CONTENT_COMMAND:f.INSERT_TAB_COMMAND;return b.dispatchCommand(a,void 0)},f.COMMAND_PRIORITY_EDITOR)}exports.TabIndentationPlugin=function(){let [b]=d.useLexicalComposerContext();g.useEffect(()=>k(b));return null};exports.registerTabIndentation=k
@@ -3,5 +3,7 @@
3
3
  *
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
  */
8
+
7
9
  import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{$filter as t,$getNearestBlockElementAncestorOrThrow as n}from"@lexical/utils";import{KEY_TAB_COMMAND as r,$getSelection as o,$isRangeSelection as c,OUTDENT_CONTENT_COMMAND as i,INDENT_CONTENT_COMMAND as s,INSERT_TAB_COMMAND as l,COMMAND_PRIORITY_EDITOR as f,$isBlockElementNode as u,$createRangeSelection as a,$normalizeSelection__EXPERIMENTAL as m}from"lexical";import{useEffect as d}from"react";function p(e){return e.registerCommand(r,(r=>{const f=o();if(!c(f))return!1;r.preventDefault();const d=function(e){const r=e.getNodes();if(t(r,(e=>u(e)&&e.canIndent()?e:null)).length>0)return!0;const o=e.anchor,c=e.focus,i=c.isBefore(o)?c:o,s=i.getNode(),l=n(s);if(l.canIndent()){const e=l.getKey();let t=a();if(t.anchor.set(e,0,"element"),t.focus.set(e,0,"element"),t=m(t),t.anchor.is(i))return!0}return!1}(f)?r.shiftKey?i:s:l;return e.dispatchCommand(d,void 0)}),f)}function h(){const[t]=e();return d((()=>p(t))),null}export{h as TabIndentationPlugin,p as registerTabIndentation};
@@ -5,16 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- /// <reference types="react" />
9
- import type { LexicalEditor, NodeKey } from 'lexical';
10
- import { HeadingTagType } from '@lexical/rich-text';
11
- export type TableOfContentsEntry = [
12
- key: NodeKey,
13
- text: string,
14
- tag: HeadingTagType
15
- ];
16
- type Props = {
17
- children: (values: Array<TableOfContentsEntry>, editor: LexicalEditor) => JSX.Element;
18
- };
19
- export default function LexicalTableOfContentsPlugin({ children, }: Props): JSX.Element;
20
- export {};
8
+ /** @deprecated moved to @lexical/react/LexicalTableOfContentsPlugin */
9
+ import { type TableOfContentsEntry, TableOfContentsPlugin } from './LexicalTableOfContentsPlugin';
10
+ /** @deprecated use the module @lexical/react/LexicalTableOfContentsPlugin */
11
+ export { type TableOfContentsEntry };
12
+ /** @deprecated use module @lexical/react/LexicalTableOfContentsPlugin */
13
+ export default TableOfContentsPlugin;
@@ -3,11 +3,14 @@
3
3
  *
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
  */
8
+
7
9
  'use strict';
8
10
 
9
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
12
  var richText = require('@lexical/rich-text');
13
+ var utils = require('@lexical/utils');
11
14
  var lexical = require('lexical');
12
15
  var react = require('react');
13
16
 
@@ -18,6 +21,7 @@ var react = require('react');
18
21
  * LICENSE file in the root directory of this source tree.
19
22
  *
20
23
  */
24
+
21
25
  function toEntry(heading) {
22
26
  return [heading.getKey(), heading.getTextContent(), heading.getTag()];
23
27
  }
@@ -28,12 +32,20 @@ function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTable
28
32
  const newEntry = toEntry(newHeading);
29
33
  let newTableOfContents = [];
30
34
  if (prevHeading === null) {
35
+ // check if key already exists
36
+ if (currentTableOfContents.length > 0 && currentTableOfContents[0][0] === newHeading.__key) {
37
+ return currentTableOfContents;
38
+ }
31
39
  newTableOfContents = [newEntry, ...currentTableOfContents];
32
40
  } else {
33
41
  for (let i = 0; i < currentTableOfContents.length; i++) {
34
42
  const key = currentTableOfContents[i][0];
35
43
  newTableOfContents.push(currentTableOfContents[i]);
36
44
  if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
45
+ // check if key already exists
46
+ if (i + 1 < currentTableOfContents.length && currentTableOfContents[i + 1][0] === newHeading.__key) {
47
+ return currentTableOfContents;
48
+ }
37
49
  newTableOfContents.push(newEntry);
38
50
  }
39
51
  }
@@ -82,7 +94,14 @@ function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
82
94
  }
83
95
  return newTableOfContents;
84
96
  }
85
- function LexicalTableOfContentsPlugin({
97
+ function $getPreviousHeading(node) {
98
+ let prevHeading = utils.$getNextRightPreorderNode(node);
99
+ while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
100
+ prevHeading = utils.$getNextRightPreorderNode(prevHeading);
101
+ }
102
+ return prevHeading;
103
+ }
104
+ function TableOfContentsPlugin({
86
105
  children
87
106
  }) {
88
107
  const [tableOfContents, setTableOfContents] = react.useState([]);
@@ -100,6 +119,31 @@ function LexicalTableOfContentsPlugin({
100
119
  }
101
120
  setTableOfContents(currentTableOfContents);
102
121
  });
122
+ const removeRootUpdateListener = editor.registerUpdateListener(({
123
+ editorState,
124
+ dirtyElements
125
+ }) => {
126
+ editorState.read(() => {
127
+ const updateChildHeadings = node => {
128
+ for (const child of node.getChildren()) {
129
+ if (richText.$isHeadingNode(child)) {
130
+ const prevHeading = $getPreviousHeading(child);
131
+ currentTableOfContents = $updateHeadingPosition(prevHeading, child, currentTableOfContents);
132
+ setTableOfContents(currentTableOfContents);
133
+ } else if (lexical.$isElementNode(child)) {
134
+ updateChildHeadings(child);
135
+ }
136
+ }
137
+ };
138
+
139
+ // If a node is changes, all child heading positions need to be updated
140
+ lexical.$getRoot().getChildren().forEach(node => {
141
+ if (lexical.$isElementNode(node) && dirtyElements.get(node.__key)) {
142
+ updateChildHeadings(node);
143
+ }
144
+ });
145
+ });
146
+ });
103
147
 
104
148
  // Listen to updates to heading mutations and update state
105
149
  const removeHeaderMutationListener = editor.registerMutationListener(richText.HeadingNode, mutatedNodes => {
@@ -108,10 +152,7 @@ function LexicalTableOfContentsPlugin({
108
152
  if (mutation === 'created') {
109
153
  const newHeading = lexical.$getNodeByKey(nodeKey);
110
154
  if (newHeading !== null) {
111
- let prevHeading = newHeading.getPreviousSibling();
112
- while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
113
- prevHeading = prevHeading.getPreviousSibling();
114
- }
155
+ const prevHeading = $getPreviousHeading(newHeading);
115
156
  currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
116
157
  }
117
158
  } else if (mutation === 'destroyed') {
@@ -119,10 +160,7 @@ function LexicalTableOfContentsPlugin({
119
160
  } else if (mutation === 'updated') {
120
161
  const newHeading = lexical.$getNodeByKey(nodeKey);
121
162
  if (newHeading !== null) {
122
- let prevHeading = newHeading.getPreviousSibling();
123
- while (prevHeading !== null && !richText.$isHeadingNode(prevHeading)) {
124
- prevHeading = prevHeading.getPreviousSibling();
125
- }
163
+ const prevHeading = $getPreviousHeading(newHeading);
126
164
  currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
127
165
  }
128
166
  }
@@ -151,9 +189,18 @@ function LexicalTableOfContentsPlugin({
151
189
  return () => {
152
190
  removeHeaderMutationListener();
153
191
  removeTextNodeMutationListener();
192
+ removeRootUpdateListener();
154
193
  };
155
194
  }, [editor]);
156
195
  return children(tableOfContents, editor);
157
196
  }
158
197
 
159
- module.exports = LexicalTableOfContentsPlugin;
198
+ /**
199
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
200
+ *
201
+ * This source code is licensed under the MIT license found in the
202
+ * LICENSE file in the root directory of this source tree.
203
+ *
204
+ */
205
+
206
+ exports.default = TableOfContentsPlugin;