@lexical/react 0.14.4 → 0.15.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 (287) hide show
  1. package/LexicalAutoEmbedPlugin.dev.js +17 -1
  2. package/LexicalAutoEmbedPlugin.dev.mjs +3 -0
  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 -4
  7. package/LexicalAutoEmbedPlugin.prod.mjs +2 -0
  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 +20 -4
  23. package/LexicalBlockWithAlignableContents.dev.mjs +6 -3
  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 +2 -0
  29. package/LexicalCharacterLimitPlugin.dev.js +21 -4
  30. package/LexicalCharacterLimitPlugin.dev.mjs +7 -3
  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 +3 -0
  37. package/LexicalCheckListPlugin.dev.mjs +3 -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 +2 -0
  42. package/LexicalCheckListPlugin.prod.mjs +2 -0
  43. package/LexicalClearEditorPlugin.dev.js +5 -2
  44. package/LexicalClearEditorPlugin.dev.mjs +7 -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.dev.js +14 -13
  51. package/LexicalClickableLinkPlugin.dev.mjs +14 -13
  52. package/LexicalClickableLinkPlugin.js +2 -0
  53. package/LexicalClickableLinkPlugin.mjs +2 -0
  54. package/LexicalClickableLinkPlugin.node.mjs +2 -0
  55. package/LexicalClickableLinkPlugin.prod.js +5 -4
  56. package/LexicalClickableLinkPlugin.prod.mjs +3 -1
  57. package/LexicalCollaborationContext.dev.js +3 -0
  58. package/LexicalCollaborationContext.dev.mjs +3 -0
  59. package/LexicalCollaborationContext.js +2 -0
  60. package/LexicalCollaborationContext.mjs +2 -0
  61. package/LexicalCollaborationContext.node.mjs +2 -0
  62. package/LexicalCollaborationContext.prod.js +2 -0
  63. package/LexicalCollaborationContext.prod.mjs +2 -0
  64. package/LexicalCollaborationPlugin.dev.js +19 -2
  65. package/LexicalCollaborationPlugin.dev.mjs +4 -0
  66. package/LexicalCollaborationPlugin.js +2 -0
  67. package/LexicalCollaborationPlugin.mjs +2 -0
  68. package/LexicalCollaborationPlugin.node.mjs +2 -0
  69. package/LexicalCollaborationPlugin.prod.js +12 -10
  70. package/LexicalCollaborationPlugin.prod.mjs +2 -0
  71. package/LexicalComposer.dev.js +19 -3
  72. package/LexicalComposer.dev.mjs +7 -4
  73. package/LexicalComposer.js +2 -0
  74. package/LexicalComposer.mjs +2 -0
  75. package/LexicalComposer.node.mjs +2 -0
  76. package/LexicalComposer.prod.js +5 -3
  77. package/LexicalComposer.prod.mjs +3 -1
  78. package/LexicalComposerContext.dev.js +3 -0
  79. package/LexicalComposerContext.dev.mjs +3 -0
  80. package/LexicalComposerContext.js +2 -0
  81. package/LexicalComposerContext.mjs +2 -0
  82. package/LexicalComposerContext.node.mjs +2 -0
  83. package/LexicalComposerContext.prod.js +4 -2
  84. package/LexicalComposerContext.prod.mjs +3 -1
  85. package/LexicalContentEditable.dev.js +18 -3
  86. package/LexicalContentEditable.dev.mjs +6 -4
  87. package/LexicalContentEditable.js +2 -0
  88. package/LexicalContentEditable.mjs +2 -0
  89. package/LexicalContentEditable.node.mjs +2 -0
  90. package/LexicalContentEditable.prod.js +6 -3
  91. package/LexicalContentEditable.prod.mjs +3 -1
  92. package/LexicalContextMenuPlugin.dev.js +24 -7
  93. package/LexicalContextMenuPlugin.dev.mjs +11 -7
  94. package/LexicalContextMenuPlugin.js +2 -0
  95. package/LexicalContextMenuPlugin.js.flow +12 -0
  96. package/LexicalContextMenuPlugin.mjs +2 -0
  97. package/LexicalContextMenuPlugin.node.mjs +2 -0
  98. package/LexicalContextMenuPlugin.prod.js +18 -16
  99. package/LexicalContextMenuPlugin.prod.mjs +3 -1
  100. package/LexicalDecoratorBlockNode.d.ts +1 -0
  101. package/LexicalDecoratorBlockNode.dev.js +6 -0
  102. package/LexicalDecoratorBlockNode.dev.mjs +6 -0
  103. package/LexicalDecoratorBlockNode.js +2 -0
  104. package/LexicalDecoratorBlockNode.mjs +2 -0
  105. package/LexicalDecoratorBlockNode.node.mjs +2 -0
  106. package/LexicalDecoratorBlockNode.prod.js +3 -1
  107. package/LexicalDecoratorBlockNode.prod.mjs +3 -1
  108. package/LexicalEditorRefPlugin.dev.js +17 -1
  109. package/LexicalEditorRefPlugin.dev.mjs +3 -0
  110. package/LexicalEditorRefPlugin.js +2 -0
  111. package/LexicalEditorRefPlugin.js.flow +19 -0
  112. package/LexicalEditorRefPlugin.mjs +2 -0
  113. package/LexicalEditorRefPlugin.node.mjs +2 -0
  114. package/LexicalEditorRefPlugin.prod.js +3 -1
  115. package/LexicalEditorRefPlugin.prod.mjs +2 -0
  116. package/LexicalErrorBoundary.dev.js +21 -5
  117. package/LexicalErrorBoundary.dev.mjs +3 -0
  118. package/LexicalErrorBoundary.js +2 -0
  119. package/LexicalErrorBoundary.mjs +2 -0
  120. package/LexicalErrorBoundary.node.mjs +2 -0
  121. package/LexicalErrorBoundary.prod.js +6 -4
  122. package/LexicalErrorBoundary.prod.mjs +2 -0
  123. package/LexicalHashtagPlugin.dev.js +5 -2
  124. package/LexicalHashtagPlugin.dev.mjs +5 -2
  125. package/LexicalHashtagPlugin.js +2 -0
  126. package/LexicalHashtagPlugin.mjs +2 -0
  127. package/LexicalHashtagPlugin.node.mjs +2 -0
  128. package/LexicalHashtagPlugin.prod.js +2 -0
  129. package/LexicalHashtagPlugin.prod.mjs +2 -0
  130. package/LexicalHistoryPlugin.dev.js +4 -0
  131. package/LexicalHistoryPlugin.dev.mjs +4 -0
  132. package/LexicalHistoryPlugin.js +2 -0
  133. package/LexicalHistoryPlugin.mjs +2 -0
  134. package/LexicalHistoryPlugin.node.mjs +2 -0
  135. package/LexicalHistoryPlugin.prod.js +2 -0
  136. package/LexicalHistoryPlugin.prod.mjs +2 -0
  137. package/LexicalHorizontalRuleNode.dev.js +22 -6
  138. package/LexicalHorizontalRuleNode.dev.mjs +8 -5
  139. package/LexicalHorizontalRuleNode.js +2 -0
  140. package/LexicalHorizontalRuleNode.mjs +2 -0
  141. package/LexicalHorizontalRuleNode.node.mjs +2 -0
  142. package/LexicalHorizontalRuleNode.prod.js +7 -5
  143. package/LexicalHorizontalRuleNode.prod.mjs +2 -0
  144. package/LexicalHorizontalRulePlugin.dev.js +3 -0
  145. package/LexicalHorizontalRulePlugin.dev.mjs +3 -0
  146. package/LexicalHorizontalRulePlugin.js +2 -0
  147. package/LexicalHorizontalRulePlugin.mjs +2 -0
  148. package/LexicalHorizontalRulePlugin.node.mjs +2 -0
  149. package/LexicalHorizontalRulePlugin.prod.js +2 -0
  150. package/LexicalHorizontalRulePlugin.prod.mjs +2 -0
  151. package/LexicalLinkPlugin.dev.js +6 -3
  152. package/LexicalLinkPlugin.dev.mjs +7 -4
  153. package/LexicalLinkPlugin.js +2 -0
  154. package/LexicalLinkPlugin.mjs +2 -0
  155. package/LexicalLinkPlugin.node.mjs +2 -0
  156. package/LexicalLinkPlugin.prod.js +3 -1
  157. package/LexicalLinkPlugin.prod.mjs +3 -1
  158. package/LexicalListPlugin.dev.js +4 -0
  159. package/LexicalListPlugin.dev.mjs +4 -0
  160. package/LexicalListPlugin.js +2 -0
  161. package/LexicalListPlugin.mjs +2 -0
  162. package/LexicalListPlugin.node.mjs +2 -0
  163. package/LexicalListPlugin.prod.js +2 -0
  164. package/LexicalListPlugin.prod.mjs +2 -0
  165. package/LexicalMarkdownShortcutPlugin.dev.js +3 -0
  166. package/LexicalMarkdownShortcutPlugin.dev.mjs +3 -0
  167. package/LexicalMarkdownShortcutPlugin.js +2 -0
  168. package/LexicalMarkdownShortcutPlugin.mjs +2 -0
  169. package/LexicalMarkdownShortcutPlugin.node.mjs +2 -0
  170. package/LexicalMarkdownShortcutPlugin.prod.js +2 -0
  171. package/LexicalMarkdownShortcutPlugin.prod.mjs +2 -0
  172. package/LexicalNestedComposer.dev.js +17 -1
  173. package/LexicalNestedComposer.dev.mjs +3 -0
  174. package/LexicalNestedComposer.js +2 -0
  175. package/LexicalNestedComposer.mjs +2 -0
  176. package/LexicalNestedComposer.node.mjs +2 -0
  177. package/LexicalNestedComposer.prod.js +7 -5
  178. package/LexicalNestedComposer.prod.mjs +3 -1
  179. package/LexicalNodeEventPlugin.dev.js +3 -0
  180. package/LexicalNodeEventPlugin.dev.mjs +3 -0
  181. package/LexicalNodeEventPlugin.js +2 -0
  182. package/LexicalNodeEventPlugin.js.flow +12 -0
  183. package/LexicalNodeEventPlugin.mjs +2 -0
  184. package/LexicalNodeEventPlugin.node.mjs +2 -0
  185. package/LexicalNodeEventPlugin.prod.js +2 -0
  186. package/LexicalNodeEventPlugin.prod.mjs +2 -0
  187. package/LexicalNodeMenuPlugin.dev.js +25 -8
  188. package/LexicalNodeMenuPlugin.dev.mjs +11 -7
  189. package/LexicalNodeMenuPlugin.js +2 -0
  190. package/LexicalNodeMenuPlugin.mjs +2 -0
  191. package/LexicalNodeMenuPlugin.node.mjs +2 -0
  192. package/LexicalNodeMenuPlugin.prod.js +17 -15
  193. package/LexicalNodeMenuPlugin.prod.mjs +3 -1
  194. package/LexicalOnChangePlugin.dev.js +5 -2
  195. package/LexicalOnChangePlugin.dev.mjs +7 -4
  196. package/LexicalOnChangePlugin.js +2 -0
  197. package/LexicalOnChangePlugin.mjs +2 -0
  198. package/LexicalOnChangePlugin.node.mjs +2 -0
  199. package/LexicalOnChangePlugin.prod.js +3 -1
  200. package/LexicalOnChangePlugin.prod.mjs +3 -1
  201. package/LexicalPlainTextPlugin.dev.js +26 -7
  202. package/LexicalPlainTextPlugin.dev.mjs +13 -7
  203. package/LexicalPlainTextPlugin.js +2 -0
  204. package/LexicalPlainTextPlugin.mjs +2 -0
  205. package/LexicalPlainTextPlugin.node.mjs +2 -0
  206. package/LexicalPlainTextPlugin.prod.js +6 -4
  207. package/LexicalPlainTextPlugin.prod.mjs +3 -1
  208. package/LexicalRichTextPlugin.dev.js +26 -7
  209. package/LexicalRichTextPlugin.dev.mjs +13 -7
  210. package/LexicalRichTextPlugin.js +2 -0
  211. package/LexicalRichTextPlugin.mjs +2 -0
  212. package/LexicalRichTextPlugin.node.mjs +2 -0
  213. package/LexicalRichTextPlugin.prod.js +6 -4
  214. package/LexicalRichTextPlugin.prod.mjs +3 -1
  215. package/LexicalTabIndentationPlugin.dev.js +5 -2
  216. package/LexicalTabIndentationPlugin.dev.mjs +5 -2
  217. package/LexicalTabIndentationPlugin.js +2 -0
  218. package/LexicalTabIndentationPlugin.mjs +2 -0
  219. package/LexicalTabIndentationPlugin.node.mjs +2 -0
  220. package/LexicalTabIndentationPlugin.prod.js +2 -0
  221. package/LexicalTabIndentationPlugin.prod.mjs +2 -0
  222. package/LexicalTableOfContents.d.ts +1 -1
  223. package/LexicalTableOfContents.dev.js +47 -8
  224. package/LexicalTableOfContents.dev.mjs +48 -9
  225. package/LexicalTableOfContents.js +2 -0
  226. package/LexicalTableOfContents.mjs +2 -0
  227. package/LexicalTableOfContents.node.mjs +2 -0
  228. package/LexicalTableOfContents.prod.js +6 -4
  229. package/LexicalTableOfContents.prod.mjs +3 -1
  230. package/LexicalTablePlugin.dev.js +28 -2
  231. package/LexicalTablePlugin.dev.mjs +31 -5
  232. package/LexicalTablePlugin.js +2 -0
  233. package/LexicalTablePlugin.mjs +2 -0
  234. package/LexicalTablePlugin.node.mjs +2 -0
  235. package/LexicalTablePlugin.prod.js +9 -5
  236. package/LexicalTablePlugin.prod.mjs +3 -1
  237. package/LexicalTreeView.dev.js +18 -2
  238. package/LexicalTreeView.dev.mjs +3 -0
  239. package/LexicalTreeView.js +2 -0
  240. package/LexicalTreeView.mjs +2 -0
  241. package/LexicalTreeView.node.mjs +2 -0
  242. package/LexicalTreeView.prod.js +5 -3
  243. package/LexicalTreeView.prod.mjs +2 -0
  244. package/LexicalTypeaheadMenuPlugin.dev.js +25 -8
  245. package/LexicalTypeaheadMenuPlugin.dev.mjs +11 -7
  246. package/LexicalTypeaheadMenuPlugin.js +2 -0
  247. package/LexicalTypeaheadMenuPlugin.mjs +2 -0
  248. package/LexicalTypeaheadMenuPlugin.node.mjs +2 -0
  249. package/LexicalTypeaheadMenuPlugin.prod.js +21 -19
  250. package/LexicalTypeaheadMenuPlugin.prod.mjs +3 -1
  251. package/package.json +20 -19
  252. package/shared/useCharacterLimit.d.ts +1 -1
  253. package/useLexicalEditable.dev.js +6 -2
  254. package/useLexicalEditable.dev.mjs +8 -4
  255. package/useLexicalEditable.js +2 -0
  256. package/useLexicalEditable.mjs +2 -0
  257. package/useLexicalEditable.node.mjs +2 -0
  258. package/useLexicalEditable.prod.js +3 -1
  259. package/useLexicalEditable.prod.mjs +3 -1
  260. package/useLexicalIsTextContentEmpty.dev.js +5 -2
  261. package/useLexicalIsTextContentEmpty.dev.mjs +7 -4
  262. package/useLexicalIsTextContentEmpty.js +2 -0
  263. package/useLexicalIsTextContentEmpty.mjs +2 -0
  264. package/useLexicalIsTextContentEmpty.node.mjs +2 -0
  265. package/useLexicalIsTextContentEmpty.prod.js +3 -1
  266. package/useLexicalIsTextContentEmpty.prod.mjs +3 -1
  267. package/useLexicalNodeSelection.dev.js +3 -0
  268. package/useLexicalNodeSelection.dev.mjs +4 -1
  269. package/useLexicalNodeSelection.js +2 -0
  270. package/useLexicalNodeSelection.mjs +2 -0
  271. package/useLexicalNodeSelection.node.mjs +2 -0
  272. package/useLexicalNodeSelection.prod.js +2 -0
  273. package/useLexicalNodeSelection.prod.mjs +3 -1
  274. package/useLexicalSubscription.dev.js +5 -2
  275. package/useLexicalSubscription.dev.mjs +7 -4
  276. package/useLexicalSubscription.js +2 -0
  277. package/useLexicalSubscription.mjs +2 -0
  278. package/useLexicalSubscription.node.mjs +2 -0
  279. package/useLexicalSubscription.prod.js +3 -1
  280. package/useLexicalSubscription.prod.mjs +3 -1
  281. package/useLexicalTextEntity.dev.js +3 -0
  282. package/useLexicalTextEntity.dev.mjs +3 -0
  283. package/useLexicalTextEntity.js +2 -0
  284. package/useLexicalTextEntity.mjs +2 -0
  285. package/useLexicalTextEntity.node.mjs +2 -0
  286. package/useLexicalTextEntity.prod.js +2 -0
  287. package/useLexicalTextEntity.prod.mjs +2 -0
@@ -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,6 +94,13 @@ function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
82
94
  }
83
95
  return newTableOfContents;
84
96
  }
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
+ }
85
104
  function LexicalTableOfContentsPlugin({
86
105
  children
87
106
  }) {
@@ -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,6 +189,7 @@ function LexicalTableOfContentsPlugin({
151
189
  return () => {
152
190
  removeHeaderMutationListener();
153
191
  removeTextNodeMutationListener();
192
+ removeRootUpdateListener();
154
193
  };
155
194
  }, [editor]);
156
195
  return children(tableOfContents, editor);
@@ -3,10 +3,13 @@
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 { $isHeadingNode, HeadingNode } from '@lexical/rich-text';
9
- import { $getRoot, $getNodeByKey, TextNode } from 'lexical';
11
+ import { $getNextRightPreorderNode } from '@lexical/utils';
12
+ import { $getRoot, $isElementNode, $getNodeByKey, TextNode } from 'lexical';
10
13
  import { useState, useEffect } from 'react';
11
14
 
12
15
  /**
@@ -16,6 +19,7 @@ import { useState, useEffect } from 'react';
16
19
  * LICENSE file in the root directory of this source tree.
17
20
  *
18
21
  */
22
+
19
23
  function toEntry(heading) {
20
24
  return [heading.getKey(), heading.getTextContent(), heading.getTag()];
21
25
  }
@@ -26,12 +30,20 @@ function $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTable
26
30
  const newEntry = toEntry(newHeading);
27
31
  let newTableOfContents = [];
28
32
  if (prevHeading === null) {
33
+ // check if key already exists
34
+ if (currentTableOfContents.length > 0 && currentTableOfContents[0][0] === newHeading.__key) {
35
+ return currentTableOfContents;
36
+ }
29
37
  newTableOfContents = [newEntry, ...currentTableOfContents];
30
38
  } else {
31
39
  for (let i = 0; i < currentTableOfContents.length; i++) {
32
40
  const key = currentTableOfContents[i][0];
33
41
  newTableOfContents.push(currentTableOfContents[i]);
34
42
  if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
43
+ // check if key already exists
44
+ if (i + 1 < currentTableOfContents.length && currentTableOfContents[i + 1][0] === newHeading.__key) {
45
+ return currentTableOfContents;
46
+ }
35
47
  newTableOfContents.push(newEntry);
36
48
  }
37
49
  }
@@ -80,6 +92,13 @@ function $updateHeadingPosition(prevHeading, heading, currentTableOfContents) {
80
92
  }
81
93
  return newTableOfContents;
82
94
  }
95
+ function $getPreviousHeading(node) {
96
+ let prevHeading = $getNextRightPreorderNode(node);
97
+ while (prevHeading !== null && !$isHeadingNode(prevHeading)) {
98
+ prevHeading = $getNextRightPreorderNode(prevHeading);
99
+ }
100
+ return prevHeading;
101
+ }
83
102
  function LexicalTableOfContentsPlugin({
84
103
  children
85
104
  }) {
@@ -98,6 +117,31 @@ function LexicalTableOfContentsPlugin({
98
117
  }
99
118
  setTableOfContents(currentTableOfContents);
100
119
  });
120
+ const removeRootUpdateListener = editor.registerUpdateListener(({
121
+ editorState,
122
+ dirtyElements
123
+ }) => {
124
+ editorState.read(() => {
125
+ const updateChildHeadings = node => {
126
+ for (const child of node.getChildren()) {
127
+ if ($isHeadingNode(child)) {
128
+ const prevHeading = $getPreviousHeading(child);
129
+ currentTableOfContents = $updateHeadingPosition(prevHeading, child, currentTableOfContents);
130
+ setTableOfContents(currentTableOfContents);
131
+ } else if ($isElementNode(child)) {
132
+ updateChildHeadings(child);
133
+ }
134
+ }
135
+ };
136
+
137
+ // If a node is changes, all child heading positions need to be updated
138
+ $getRoot().getChildren().forEach(node => {
139
+ if ($isElementNode(node) && dirtyElements.get(node.__key)) {
140
+ updateChildHeadings(node);
141
+ }
142
+ });
143
+ });
144
+ });
101
145
 
102
146
  // Listen to updates to heading mutations and update state
103
147
  const removeHeaderMutationListener = editor.registerMutationListener(HeadingNode, mutatedNodes => {
@@ -106,10 +150,7 @@ function LexicalTableOfContentsPlugin({
106
150
  if (mutation === 'created') {
107
151
  const newHeading = $getNodeByKey(nodeKey);
108
152
  if (newHeading !== null) {
109
- let prevHeading = newHeading.getPreviousSibling();
110
- while (prevHeading !== null && !$isHeadingNode(prevHeading)) {
111
- prevHeading = prevHeading.getPreviousSibling();
112
- }
153
+ const prevHeading = $getPreviousHeading(newHeading);
113
154
  currentTableOfContents = $insertHeadingIntoTableOfContents(prevHeading, newHeading, currentTableOfContents);
114
155
  }
115
156
  } else if (mutation === 'destroyed') {
@@ -117,10 +158,7 @@ function LexicalTableOfContentsPlugin({
117
158
  } else if (mutation === 'updated') {
118
159
  const newHeading = $getNodeByKey(nodeKey);
119
160
  if (newHeading !== null) {
120
- let prevHeading = newHeading.getPreviousSibling();
121
- while (prevHeading !== null && !$isHeadingNode(prevHeading)) {
122
- prevHeading = prevHeading.getPreviousSibling();
123
- }
161
+ const prevHeading = $getPreviousHeading(newHeading);
124
162
  currentTableOfContents = $updateHeadingPosition(prevHeading, newHeading, currentTableOfContents);
125
163
  }
126
164
  }
@@ -149,6 +187,7 @@ function LexicalTableOfContentsPlugin({
149
187
  return () => {
150
188
  removeHeaderMutationListener();
151
189
  removeTextNodeMutationListener();
190
+ removeRootUpdateListener();
152
191
  };
153
192
  }, [editor]);
154
193
  return children(tableOfContents, editor);
@@ -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 LexicalTableOfContents = process.env.NODE_ENV === 'development' ? require('./LexicalTableOfContents.dev.js') : require('./LexicalTableOfContents.prod.js');
9
11
  module.exports = LexicalTableOfContents;
@@ -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 './LexicalTableOfContents.dev.mjs';
8
10
  import * as modProd from './LexicalTableOfContents.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('./LexicalTableOfContents.dev.mjs') : import('./LexicalTableOfContents.prod.mjs'));
8
10
  export default mod.default;
@@ -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 l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/rich-text"),q=require("lexical"),u=require("react");function w(n){return[n.getKey(),n.getTextContent(),n.getTag()]}
8
- module.exports=function({children:n}){let [x,r]=u.useState([]),[h]=l.useLexicalComposerContext();u.useEffect(()=>{let c=[];h.getEditorState().read(()=>{let p=q.$getRoot().getChildren();for(let a of p)m.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);r(c)});let y=h.registerMutationListener(m.HeadingNode,p=>{h.getEditorState().read(()=>{for(const [k,t]of p)if("created"===t){var a=q.$getNodeByKey(k);if(null!==a){for(var b=a.getPreviousSibling();null!==b&&!m.$isHeadingNode(b);)b=
9
- b.getPreviousSibling();var d=c;if(null===a)c=d;else{var g=w(a),e=[];if(null===b)e=[g,...d];else for(let f=0;f<d.length;f++){let v=d[f][0];e.push(d[f]);v===b.getKey()&&v!==a.getKey()&&e.push(g)}c=e}}}else if("destroyed"===t){b=k;a=c;d=[];for(let f of a)f[0]!==b&&d.push(f);c=d}else if("updated"===t&&(a=q.$getNodeByKey(k),null!==a)){for(b=a.getPreviousSibling();null!==b&&!m.$isHeadingNode(b);)b=b.getPreviousSibling();d=c;g=[];e=w(a);b||g.push(e);for(let f of d)f[0]!==a.getKey()&&(g.push(f),b&&f[0]===
10
- b.getKey()&&g.push(e));c=g}r(c)})}),z=h.registerMutationListener(q.TextNode,p=>{h.getEditorState().read(()=>{for(const [d,g]of p)if("updated"===g){var a=q.$getNodeByKey(d);if(null!==a&&(a=a.getParentOrThrow(),m.$isHeadingNode(a))){var b=c;let e=[];for(let k of b)k[0]===a.getKey()?e.push(w(a)):e.push(k);c=e;r(c)}}})});return()=>{y();z()}},[h]);return n(x,h)}
8
+
9
+ 'use strict';var h=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/rich-text"),v=require("@lexical/utils"),w=require("lexical"),x=require("react");function y(d){return[d.getKey(),d.getTextContent(),d.getTag()]}function z(d,t,n){let e=[],c=y(t);d||e.push(c);for(let r of n)r[0]!==t.getKey()&&(e.push(r),d&&r[0]===d.getKey()&&e.push(c));return e}function B(d){for(d=v.$getNextRightPreorderNode(d);null!==d&&!q.$isHeadingNode(d);)d=v.$getNextRightPreorderNode(d);return d}
10
+ module.exports=function({children:d}){let [t,n]=x.useState([]),[e]=h.useLexicalComposerContext();x.useEffect(()=>{let c=[];e.getEditorState().read(()=>{let l=w.$getRoot().getChildren();for(let a of l)q.$isHeadingNode(a)&&c.push([a.getKey(),a.getTextContent(),a.getTag()]);n(c)});let r=e.registerUpdateListener(({editorState:l,dirtyElements:a})=>{l.read(()=>{const f=b=>{for(const g of b.getChildren())q.$isHeadingNode(g)?(b=B(g),c=z(b,g,c),n(c)):w.$isElementNode(g)&&f(g)};w.$getRoot().getChildren().forEach(b=>
11
+ {w.$isElementNode(b)&&a.get(b.__key)&&f(b)})})}),C=e.registerMutationListener(q.HeadingNode,l=>{e.getEditorState().read(()=>{for(const [g,m]of l)if("created"===m){var a=w.$getNodeByKey(g);if(null!==a)a:{var f=B(a),b=c;if(null===a){c=b;break a}let k=y(a),u=[];if(null===f){if(0<b.length&&b[0][0]===a.__key){c=b;break a}u=[k,...b]}else for(let p=0;p<b.length;p++){let A=b[p][0];u.push(b[p]);if(A===f.getKey()&&A!==a.getKey()){if(p+1<b.length&&b[p+1][0]===a.__key){c=b;break a}u.push(k)}}c=u}}else if("destroyed"===
12
+ m){f=g;a=c;b=[];for(let k of a)k[0]!==f&&b.push(k);c=b}else"updated"===m&&(f=w.$getNodeByKey(g),null!==f&&(a=B(f),c=z(a,f,c)));n(c)})}),D=e.registerMutationListener(w.TextNode,l=>{e.getEditorState().read(()=>{for(const [b,g]of l)if("updated"===g){var a=w.$getNodeByKey(b);if(null!==a&&(a=a.getParentOrThrow(),q.$isHeadingNode(a))){var f=c;let m=[];for(let k of f)k[0]===a.getKey()?m.push(y(a)):m.push(k);c=m;n(c)}}})});return()=>{C();D();r()}},[e]);return d(t,e)}
@@ -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 t}from"@lexical/react/LexicalComposerContext";import{$isHeadingNode as e,HeadingNode as o}from"@lexical/rich-text";import{$getRoot as n,$getNodeByKey as r,TextNode as i}from"lexical";import{useState as s,useEffect as u}from"react";function l(t){return[t.getKey(),t.getTextContent(),t.getTag()]}function f(t,e,o){if(null===e)return o;const n=l(e);let r=[];if(null===t)r=[n,...o];else for(let i=0;i<o.length;i++){const s=o[i][0];r.push(o[i]),s===t.getKey()&&s!==e.getKey()&&r.push(n)}return r}function c(t,e){const o=[];for(const n of e)n[0]!==t&&o.push(n);return o}function g(t,e){const o=[];for(const n of e)n[0]===t.getKey()?o.push(l(t)):o.push(n);return o}function a(t,e,o){const n=[],r=l(e);t||n.push(r);for(const i of o)i[0]!==e.getKey()&&(n.push(i),t&&i[0]===t.getKey()&&n.push(r));return n}function p({children:l}){const[p,d]=s([]),[h]=t();return u((()=>{let t=[];h.getEditorState().read((()=>{const o=n().getChildren();for(const n of o)e(n)&&t.push([n.getKey(),n.getTextContent(),n.getTag()]);d(t)}));const s=h.registerMutationListener(o,(o=>{h.getEditorState().read((()=>{for(const[n,i]of o)if("created"===i){const o=r(n);if(null!==o){let n=o.getPreviousSibling();for(;null!==n&&!e(n);)n=n.getPreviousSibling();t=f(n,o,t)}}else if("destroyed"===i)t=c(n,t);else if("updated"===i){const o=r(n);if(null!==o){let n=o.getPreviousSibling();for(;null!==n&&!e(n);)n=n.getPreviousSibling();t=a(n,o,t)}}d(t)}))})),u=h.registerMutationListener(i,(o=>{h.getEditorState().read((()=>{for(const[n,i]of o)if("updated"===i){const o=r(n);if(null!==o){const n=o.getParentOrThrow();e(n)&&(t=g(n,t),d(t))}}}))}));return()=>{s(),u()}}),[h]),l(p,h)}export{p as default};
8
+
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{$isHeadingNode as e,HeadingNode as r}from"@lexical/rich-text";import{$getNextRightPreorderNode as n}from"@lexical/utils";import{$getRoot as o,$isElementNode as i,$getNodeByKey as s,TextNode as f}from"lexical";import{useState as c,useEffect as l}from"react";function u(t){return[t.getKey(),t.getTextContent(),t.getTag()]}function a(t,e,r){if(null===e)return r;const n=u(e);let o=[];if(null===t){if(r.length>0&&r[0][0]===e.__key)return r;o=[n,...r]}else for(let i=0;i<r.length;i++){const s=r[i][0];if(o.push(r[i]),s===t.getKey()&&s!==e.getKey()){if(i+1<r.length&&r[i+1][0]===e.__key)return r;o.push(n)}}return o}function g(t,e){const r=[];for(const n of e)n[0]!==t&&r.push(n);return r}function d(t,e){const r=[];for(const n of e)n[0]===t.getKey()?r.push(u(t)):r.push(n);return r}function h(t,e,r){const n=[],o=u(e);t||n.push(o);for(const i of r)i[0]!==e.getKey()&&(n.push(i),t&&i[0]===t.getKey()&&n.push(o));return n}function p(t){let r=n(t);for(;null!==r&&!e(r);)r=n(r);return r}function m({children:n}){const[u,m]=c([]),[y]=t();return l((()=>{let t=[];y.getEditorState().read((()=>{const r=o().getChildren();for(const n of r)e(n)&&t.push([n.getKey(),n.getTextContent(),n.getTag()]);m(t)}));const n=y.registerUpdateListener((({editorState:r,dirtyElements:n})=>{r.read((()=>{const r=n=>{for(const o of n.getChildren())if(e(o)){const e=p(o);t=h(e,o,t),m(t)}else i(o)&&r(o)};o().getChildren().forEach((t=>{i(t)&&n.get(t.__key)&&r(t)}))}))})),c=y.registerMutationListener(r,(e=>{y.getEditorState().read((()=>{for(const[r,n]of e)if("created"===n){const e=s(r);if(null!==e){const r=p(e);t=a(r,e,t)}}else if("destroyed"===n)t=g(r,t);else if("updated"===n){const e=s(r);if(null!==e){const r=p(e);t=h(r,e,t)}}m(t)}))})),l=y.registerMutationListener(f,(r=>{y.getEditorState().read((()=>{for(const[n,o]of r)if("updated"===o){const r=s(n);if(null!==r){const n=r.getParentOrThrow();e(n)&&(t=d(n,t),m(t))}}}))}));return()=>{c(),l(),n()}}),[y]),n(u,y)}export{m as default};
@@ -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');
@@ -19,6 +21,7 @@ var react = require('react');
19
21
  * LICENSE file in the root directory of this source tree.
20
22
  *
21
23
  */
24
+
22
25
  function TablePlugin({
23
26
  hasCellMerge = true,
24
27
  hasCellBackgroundColor = true,
@@ -31,7 +34,7 @@ function TablePlugin({
31
34
  throw Error(`TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor`);
32
35
  }
33
36
  }
34
- return editor.registerCommand(table.INSERT_TABLE_COMMAND, ({
37
+ return utils.mergeRegister(editor.registerCommand(table.INSERT_TABLE_COMMAND, ({
35
38
  columns,
36
39
  rows,
37
40
  includeHeaders
@@ -43,7 +46,30 @@ function TablePlugin({
43
46
  firstDescendant.select();
44
47
  }
45
48
  return true;
46
- }, lexical.COMMAND_PRIORITY_EDITOR);
49
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerNodeTransform(table.TableNode, node => {
50
+ const [gridMap] = table.$computeTableMapSkipCellCheck(node, null, null);
51
+ const maxRowLength = gridMap.reduce((curLength, row) => {
52
+ return Math.max(curLength, row.length);
53
+ }, 0);
54
+ for (let i = 0; i < gridMap.length; ++i) {
55
+ const rowLength = gridMap[i].length;
56
+ if (rowLength === maxRowLength) {
57
+ continue;
58
+ }
59
+ const lastCellMap = gridMap[i][rowLength - 1];
60
+ const lastRowCell = lastCellMap.cell;
61
+ for (let j = rowLength; j < maxRowLength; ++j) {
62
+ // TODO: inherit header state from another header or body
63
+ const newCell = table.$createTableCellNode(0);
64
+ newCell.append(lexical.$createParagraphNode());
65
+ if (lastRowCell !== null) {
66
+ lastRowCell.insertAfter(newCell);
67
+ } else {
68
+ utils.$insertFirst(lastRowCell, newCell);
69
+ }
70
+ }
71
+ }
72
+ }));
47
73
  }, [editor]);
48
74
  react.useEffect(() => {
49
75
  const tableSelections = new Map();
@@ -3,11 +3,13 @@
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 { TableNode, TableCellNode, TableRowNode, INSERT_TABLE_COMMAND, $createTableNodeWithDimensions, $isTableNode, $getNodeTriplet, $computeTableMap, $isTableRowNode, $isTableCellNode, $createTableCellNode, applyTableHandlers } from '@lexical/table';
9
- import { $insertNodeToNearestRoot, $insertFirst } from '@lexical/utils';
10
- import { $isTextNode, COMMAND_PRIORITY_EDITOR, $nodesOfType, $getNodeByKey } from 'lexical';
10
+ import { TableNode, TableCellNode, TableRowNode, INSERT_TABLE_COMMAND, $createTableNodeWithDimensions, $computeTableMapSkipCellCheck, $createTableCellNode, $isTableNode, $getNodeTriplet, $computeTableMap, $isTableRowNode, $isTableCellNode, applyTableHandlers } from '@lexical/table';
11
+ import { mergeRegister, $insertNodeToNearestRoot, $insertFirst } from '@lexical/utils';
12
+ import { $isTextNode, COMMAND_PRIORITY_EDITOR, $createParagraphNode, $nodesOfType, $getNodeByKey } from 'lexical';
11
13
  import { useEffect } from 'react';
12
14
 
13
15
  /**
@@ -17,6 +19,7 @@ import { useEffect } from 'react';
17
19
  * LICENSE file in the root directory of this source tree.
18
20
  *
19
21
  */
22
+
20
23
  function TablePlugin({
21
24
  hasCellMerge = true,
22
25
  hasCellBackgroundColor = true,
@@ -29,7 +32,7 @@ function TablePlugin({
29
32
  throw Error(`TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor`);
30
33
  }
31
34
  }
32
- return editor.registerCommand(INSERT_TABLE_COMMAND, ({
35
+ return mergeRegister(editor.registerCommand(INSERT_TABLE_COMMAND, ({
33
36
  columns,
34
37
  rows,
35
38
  includeHeaders
@@ -41,7 +44,30 @@ function TablePlugin({
41
44
  firstDescendant.select();
42
45
  }
43
46
  return true;
44
- }, COMMAND_PRIORITY_EDITOR);
47
+ }, COMMAND_PRIORITY_EDITOR), editor.registerNodeTransform(TableNode, node => {
48
+ const [gridMap] = $computeTableMapSkipCellCheck(node, null, null);
49
+ const maxRowLength = gridMap.reduce((curLength, row) => {
50
+ return Math.max(curLength, row.length);
51
+ }, 0);
52
+ for (let i = 0; i < gridMap.length; ++i) {
53
+ const rowLength = gridMap[i].length;
54
+ if (rowLength === maxRowLength) {
55
+ continue;
56
+ }
57
+ const lastCellMap = gridMap[i][rowLength - 1];
58
+ const lastRowCell = lastCellMap.cell;
59
+ for (let j = rowLength; j < maxRowLength; ++j) {
60
+ // TODO: inherit header state from another header or body
61
+ const newCell = $createTableCellNode(0);
62
+ newCell.append($createParagraphNode());
63
+ if (lastRowCell !== null) {
64
+ lastRowCell.insertAfter(newCell);
65
+ } else {
66
+ $insertFirst(lastRowCell, newCell);
67
+ }
68
+ }
69
+ }
70
+ }));
45
71
  }, [editor]);
46
72
  useEffect(() => {
47
73
  const tableSelections = new Map();
@@ -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 LexicalTablePlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTablePlugin.dev.js') : require('./LexicalTablePlugin.prod.js');
9
11
  module.exports = LexicalTablePlugin;
@@ -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 './LexicalTablePlugin.dev.mjs';
8
10
  import * as modProd from './LexicalTablePlugin.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('./LexicalTablePlugin.dev.mjs') : import('./LexicalTablePlugin.prod.mjs'));
8
10
  export const TablePlugin = mod.TablePlugin;
@@ -3,9 +3,13 @@
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"),q=require("@lexical/table"),r=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(l){let m=new URLSearchParams;m.append("code",l);for(let n=1;n<arguments.length;n++)m.append("v",arguments[n]);throw Error(`Minified Lexical error #${l}; visit https://lexical.dev/docs/error?${m} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
8
- exports.TablePlugin=function({hasCellMerge:l=!0,hasCellBackgroundColor:m=!0,hasTabHandler:n=!0}){let [d]=b.useLexicalComposerContext();w.useEffect(()=>{d.hasNodes([q.TableNode,q.TableCellNode,q.TableRowNode])||x(10);return d.registerCommand(q.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:h})=>{a=q.$createTableNodeWithDimensions(Number(e),Number(a),h);r.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0},v.COMMAND_PRIORITY_EDITOR)},[d]);w.useEffect(()=>
9
- {let a=new Map,e=c=>{const f=c.getKey(),k=d.getElementByKey(f);k&&!a.has(f)&&(c=q.applyTableHandlers(c,k,d,n),a.set(f,c))};d.getEditorState().read(()=>{let c=v.$nodesOfType(q.TableNode);for(let f of c)q.$isTableNode(f)&&e(f)});let h=d.registerMutationListener(q.TableNode,c=>{for(const [f,k]of c)"created"===k?d.getEditorState().read(()=>{const g=v.$getNodeByKey(f);q.$isTableNode(g)&&e(g)}):"destroyed"===k&&(c=a.get(f),void 0!==c&&(c.removeListeners(),a.delete(f)))});return()=>{h();for(let [,c]of a)c.removeListeners()}},
10
- [d,n]);w.useEffect(()=>{if(!l)return d.registerNodeTransform(q.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=q.$getNodeTriplet(a);[a]=q.$computeTableMap(e,a,a);let c=a.length,f=a[0].length;e=e.getFirstChild();if(!q.$isTableRowNode(e))throw Error("Expected TableNode first child to be a RowNode");let k=[];for(let g=0;g<c;g++){if(0!==g&&(e=e.getNextSibling(),!q.$isTableRowNode(e)))throw Error("Expected TableNode first child to be a RowNode");let u=null;for(let t=0;t<f;t++){var h=
11
- a[g][t];let p=h.cell;if(h.startRow===g&&h.startColumn===t)u=p,k.push(p);else if(1<p.getColSpan()||1<p.getRowSpan()){if(!q.$isTableCellNode(p))throw Error("Expected TableNode cell to be a TableCellNode");h=q.$createTableCellNode(p.__headerState);null!==u?u.insertAfter(h):r.$insertFirst(e,h)}}}for(let g of k)g.setColSpan(1),g.setRowSpan(1)}})},[d,l]);w.useEffect(()=>{if(!m)return d.registerNodeTransform(q.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},[d,m,l]);return null}
8
+
9
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/table"),r=require("@lexical/utils"),t=require("lexical"),u=require("react"),v;function y(l){let m=new URLSearchParams;m.append("code",l);for(let n=1;n<arguments.length;n++)m.append("v",arguments[n]);throw Error(`Minified Lexical error #${l}; visit https://lexical.dev/docs/error?${m} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
10
+ v=y&&y.__esModule&&Object.prototype.hasOwnProperty.call(y,"default")?y["default"]:y;
11
+ exports.TablePlugin=function({hasCellMerge:l=!0,hasCellBackgroundColor:m=!0,hasTabHandler:n=!0}){let [g]=c.useLexicalComposerContext();u.useEffect(()=>{g.hasNodes([q.TableNode,q.TableCellNode,q.TableRowNode])||v(10);return r.mergeRegister(g.registerCommand(q.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:f})=>{a=q.$createTableNodeWithDimensions(Number(e),Number(a),f);r.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();t.$isTextNode(a)&&a.select();return!0},t.COMMAND_PRIORITY_EDITOR),g.registerNodeTransform(q.TableNode,
12
+ a=>{[a]=q.$computeTableMapSkipCellCheck(a,null,null);let e=a.reduce((b,d)=>Math.max(b,d.length),0);for(let b=0;b<a.length;++b){var f=a[b].length;if(f===e)continue;let d=a[b][f-1].cell;for(;f<e;++f){let h=q.$createTableCellNode(0);h.append(t.$createParagraphNode());null!==d?d.insertAfter(h):r.$insertFirst(d,h)}}}))},[g]);u.useEffect(()=>{let a=new Map,e=b=>{const d=b.getKey(),h=g.getElementByKey(d);h&&!a.has(d)&&(b=q.applyTableHandlers(b,h,g,n),a.set(d,b))};g.getEditorState().read(()=>{let b=t.$nodesOfType(q.TableNode);
13
+ for(let d of b)q.$isTableNode(d)&&e(d)});let f=g.registerMutationListener(q.TableNode,b=>{for(const [d,h]of b)"created"===h?g.getEditorState().read(()=>{const k=t.$getNodeByKey(d);q.$isTableNode(k)&&e(k)}):"destroyed"===h&&(b=a.get(d),void 0!==b&&(b.removeListeners(),a.delete(d)))});return()=>{f();for(let [,b]of a)b.removeListeners()}},[g,n]);u.useEffect(()=>{if(!l)return g.registerNodeTransform(q.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=q.$getNodeTriplet(a);[a]=q.$computeTableMap(e,
14
+ a,a);let b=a.length,d=a[0].length;e=e.getFirstChild();q.$isTableRowNode(e)||v(175);let h=[];for(let k=0;k<b;k++){0!==k&&(e=e.getNextSibling(),q.$isTableRowNode(e)||v(175));let x=null;for(let w=0;w<d;w++){var f=a[k][w];let p=f.cell;if(f.startRow===k&&f.startColumn===w)x=p,h.push(p);else if(1<p.getColSpan()||1<p.getRowSpan())q.$isTableCellNode(p)||v(176),f=q.$createTableCellNode(p.__headerState),null!==x?x.insertAfter(f):r.$insertFirst(e,f)}}for(let k of h)k.setColSpan(1),k.setRowSpan(1)}})},[g,l]);
15
+ u.useEffect(()=>{if(!m)return g.registerNodeTransform(q.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},[g,m,l]);return null}
@@ -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{TableNode as t,TableCellNode as o,TableRowNode as r,INSERT_TABLE_COMMAND as n,$createTableNodeWithDimensions as l,$isTableNode as s,$getNodeTriplet as a,$computeTableMap as i,$isTableRowNode as c,$isTableCellNode as d,$createTableCellNode as f,applyTableHandlers as g}from"@lexical/table";import{$insertNodeToNearestRoot as u,$insertFirst as m}from"@lexical/utils";import{$isTextNode as p,COMMAND_PRIORITY_EDITOR as h,$nodesOfType as w,$getNodeByKey as C}from"lexical";import{useEffect as x}from"react";var b=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};function N({hasCellMerge:N=!0,hasCellBackgroundColor:S=!0,hasTabHandler:E=!0}){const[v]=e();return x((()=>(v.hasNodes([t,o,r])||b(10),v.registerCommand(n,(({columns:e,rows:t,includeHeaders:o})=>{const r=l(Number(t),Number(e),o);u(r);const n=r.getFirstDescendant();return p(n)&&n.select(),!0}),h))),[v]),x((()=>{const e=new Map,o=t=>{const o=t.getKey(),r=v.getElementByKey(o);if(r&&!e.has(o)){const n=g(t,r,v,E);e.set(o,n)}};v.getEditorState().read((()=>{const e=w(t);for(const t of e)s(t)&&o(t)}));const r=v.registerMutationListener(t,(t=>{for(const[r,n]of t)if("created"===n)v.getEditorState().read((()=>{const e=C(r);s(e)&&o(e)}));else if("destroyed"===n){const t=e.get(r);void 0!==t&&(t.removeListeners(),e.delete(r))}}));return()=>{r();for(const[,t]of e)t.removeListeners()}}),[v,E]),x((()=>{if(!N)return v.registerNodeTransform(o,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=a(e),[o]=i(t,e,e),r=o.length,n=o[0].length;let l=t.getFirstChild();if(!c(l))throw Error("Expected TableNode first child to be a RowNode");const s=[];for(let e=0;e<r;e++){if(0!==e&&(l=l.getNextSibling(),!c(l)))throw Error("Expected TableNode first child to be a RowNode");let t=null;for(let r=0;r<n;r++){const n=o[e][r],a=n.cell;if(n.startRow===e&&n.startColumn===r)t=a,s.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){if(!d(a))throw Error("Expected TableNode cell to be a TableCellNode");const e=f(a.__headerState);null!==t?t.insertAfter(e):m(l,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}}))}),[v,N]),x((()=>{if(!S)return v.registerNodeTransform(o,(e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)}))}),[v,S,N]),null}export{N as TablePlugin};
8
+
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{TableNode as t,TableCellNode as r,TableRowNode as o,INSERT_TABLE_COMMAND as n,$createTableNodeWithDimensions as l,$computeTableMapSkipCellCheck as s,$createTableCellNode as a,$isTableNode as i,$getNodeTriplet as c,$computeTableMap as f,$isTableRowNode as d,$isTableCellNode as u,applyTableHandlers as g}from"@lexical/table";import{mergeRegister as m,$insertNodeToNearestRoot as p,$insertFirst as h}from"@lexical/utils";import{$isTextNode as C,COMMAND_PRIORITY_EDITOR as x,$createParagraphNode as S,$nodesOfType as w,$getNodeByKey as v}from"lexical";import{useEffect as N}from"react";function b(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var y=b((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function L({hasCellMerge:b=!0,hasCellBackgroundColor:L=!0,hasTabHandler:M=!0}){const[R]=e();return N((()=>(R.hasNodes([t,r,o])||y(10),m(R.registerCommand(n,(({columns:e,rows:t,includeHeaders:r})=>{const o=l(Number(t),Number(e),r);p(o);const n=o.getFirstDescendant();return C(n)&&n.select(),!0}),x),R.registerNodeTransform(t,(e=>{const[t]=s(e,null,null),r=t.reduce(((e,t)=>Math.max(e,t.length)),0);for(let e=0;e<t.length;++e){const o=t[e].length;if(o===r)continue;const n=t[e][o-1].cell;for(let e=o;e<r;++e){const e=a(0);e.append(S()),null!==n?n.insertAfter(e):h(n,e)}}}))))),[R]),N((()=>{const e=new Map,r=t=>{const r=t.getKey(),o=R.getElementByKey(r);if(o&&!e.has(r)){const n=g(t,o,R,M);e.set(r,n)}};R.getEditorState().read((()=>{const e=w(t);for(const t of e)i(t)&&r(t)}));const o=R.registerMutationListener(t,(t=>{for(const[o,n]of t)if("created"===n)R.getEditorState().read((()=>{const e=v(o);i(e)&&r(e)}));else if("destroyed"===n){const t=e.get(o);void 0!==t&&(t.removeListeners(),e.delete(o))}}));return()=>{o();for(const[,t]of e)t.removeListeners()}}),[R,M]),N((()=>{if(!b)return R.registerNodeTransform(r,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=c(e),[r]=f(t,e,e),o=r.length,n=r[0].length;let l=t.getFirstChild();d(l)||y(175);const s=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),d(l)||y(175));let t=null;for(let o=0;o<n;o++){const n=r[e][o],i=n.cell;if(n.startRow===e&&n.startColumn===o)t=i,s.push(i);else if(i.getColSpan()>1||i.getRowSpan()>1){u(i)||y(176);const e=a(i.__headerState);null!==t?t.insertAfter(e):h(l,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}}))}),[R,b]),N((()=>{if(!L)return R.registerNodeTransform(r,(e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)}))}),[R,L,b]),null}export{L as TablePlugin};
@@ -3,13 +3,28 @@
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 devtoolsCore = require('@lexical/devtools-core');
10
12
  var utils = require('@lexical/utils');
11
13
  var React = require('react');
12
14
 
15
+ function _interopNamespaceDefault(e) {
16
+ var n = Object.create(null);
17
+ if (e) {
18
+ for (var k in e) {
19
+ n[k] = e[k];
20
+ }
21
+ }
22
+ n.default = e;
23
+ return n;
24
+ }
25
+
26
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
27
+
13
28
  /**
14
29
  * Copyright (c) Meta Platforms, Inc. and affiliates.
15
30
  *
@@ -17,6 +32,7 @@ var React = require('react');
17
32
  * LICENSE file in the root directory of this source tree.
18
33
  *
19
34
  */
35
+
20
36
  function TreeView({
21
37
  treeTypeButtonClassName,
22
38
  timeTravelButtonClassName,
@@ -26,7 +42,7 @@ function TreeView({
26
42
  timeTravelPanelClassName,
27
43
  editor
28
44
  }) {
29
- const treeElementRef = /*#__PURE__*/React.createRef();
45
+ const treeElementRef = /*#__PURE__*/React__namespace.createRef();
30
46
  const [editorCurrentState, setEditorCurrentState] = React.useState(editor.getEditorState());
31
47
  const commandsLog = devtoolsCore.useLexicalCommandsLog(editor);
32
48
  React.useEffect(() => {
@@ -56,7 +72,7 @@ function TreeView({
56
72
  }
57
73
  rootElement.contentEditable = isReadonly ? 'false' : 'true';
58
74
  };
59
- return /*#__PURE__*/React.createElement(devtoolsCore.TreeView, {
75
+ return /*#__PURE__*/React__namespace.createElement(devtoolsCore.TreeView, {
60
76
  treeTypeButtonClassName: treeTypeButtonClassName,
61
77
  timeTravelButtonClassName: timeTravelButtonClassName,
62
78
  timeTravelPanelSliderClassName: timeTravelPanelSliderClassName,
@@ -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 { useLexicalCommandsLog, TreeView as TreeView$1, generateContent } from '@lexical/devtools-core';
8
10
  import { mergeRegister } from '@lexical/utils';
9
11
  import * as React from 'react';
@@ -16,6 +18,7 @@ import { useState, useEffect } from 'react';
16
18
  * LICENSE file in the root directory of this source tree.
17
19
  *
18
20
  */
21
+
19
22
  function TreeView({
20
23
  treeTypeButtonClassName,
21
24
  timeTravelButtonClassName,
@@ -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 LexicalTreeView = process.env.NODE_ENV === 'development' ? require('./LexicalTreeView.dev.js') : require('./LexicalTreeView.prod.js');
9
11
  module.exports = LexicalTreeView;
@@ -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 './LexicalTreeView.dev.mjs';
8
10
  import * as modProd from './LexicalTreeView.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('./LexicalTreeView.dev.mjs') : import('./LexicalTreeView.prod.mjs'));
8
10
  export const TreeView = mod.TreeView;
@@ -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
  */
7
- 'use strict';var c=require("@lexical/devtools-core"),d=require("@lexical/utils"),h=require("react");
8
- exports.TreeView=function({treeTypeButtonClassName:k,timeTravelButtonClassName:l,timeTravelPanelSliderClassName:m,timeTravelPanelButtonClassName:n,viewClassName:p,timeTravelPanelClassName:q,editor:a}){let e=h.createRef(),[r,f]=h.useState(a.getEditorState()),t=c.useLexicalCommandsLog(a);h.useEffect(()=>d.mergeRegister(a.registerUpdateListener(({editorState:b})=>{f(b)}),a.registerEditableListener(()=>{f(a.getEditorState())})),[a]);h.useEffect(()=>{let b=e.current;if(null!==b)return b.__lexicalEditor=
9
- a,()=>{b.__lexicalEditor=null}},[a,e]);return h.createElement(c.TreeView,{treeTypeButtonClassName:k,timeTravelButtonClassName:l,timeTravelPanelSliderClassName:m,timeTravelPanelButtonClassName:n,viewClassName:p,timeTravelPanelClassName:q,setEditorReadOnly:b=>{const g=a.getRootElement();null!=g&&(g.contentEditable=b?"false":"true")},editorState:r,setEditorState:b=>a.setEditorState(b),generateContent:async function(b){return c.generateContent(a,t,b)},ref:e})}
8
+
9
+ 'use strict';var c=require("@lexical/devtools-core"),d=require("@lexical/utils"),e=require("react"),g=Object.create(null);if(e)for(var l in e)g[l]=e[l];g.default=e;
10
+ exports.TreeView=function({treeTypeButtonClassName:m,timeTravelButtonClassName:n,timeTravelPanelSliderClassName:p,timeTravelPanelButtonClassName:q,viewClassName:r,timeTravelPanelClassName:t,editor:a}){let f=g.createRef(),[u,h]=e.useState(a.getEditorState()),v=c.useLexicalCommandsLog(a);e.useEffect(()=>d.mergeRegister(a.registerUpdateListener(({editorState:b})=>{h(b)}),a.registerEditableListener(()=>{h(a.getEditorState())})),[a]);e.useEffect(()=>{let b=f.current;if(null!==b)return b.__lexicalEditor=
11
+ a,()=>{b.__lexicalEditor=null}},[a,f]);return g.createElement(c.TreeView,{treeTypeButtonClassName:m,timeTravelButtonClassName:n,timeTravelPanelSliderClassName:p,timeTravelPanelButtonClassName:q,viewClassName:r,timeTravelPanelClassName:t,setEditorReadOnly:b=>{const k=a.getRootElement();null!=k&&(k.contentEditable=b?"false":"true")},editorState:u,setEditorState:b=>a.setEditorState(b),generateContent:async function(b){return c.generateContent(a,v,b)},ref:f})}