@lexical/react 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/LexicalAutoEmbedPlugin.dev.esm.js +131 -0
  2. package/LexicalAutoEmbedPlugin.esm.js +13 -0
  3. package/LexicalAutoEmbedPlugin.js +1 -1
  4. package/LexicalAutoEmbedPlugin.prod.esm.js +7 -0
  5. package/LexicalAutoFocusPlugin.dev.esm.js +42 -0
  6. package/LexicalAutoFocusPlugin.dev.js +0 -5
  7. package/LexicalAutoFocusPlugin.esm.js +10 -0
  8. package/LexicalAutoFocusPlugin.js +1 -1
  9. package/LexicalAutoFocusPlugin.prod.esm.js +7 -0
  10. package/LexicalAutoFocusPlugin.prod.js +1 -1
  11. package/LexicalAutoLinkPlugin.dev.esm.js +312 -0
  12. package/LexicalAutoLinkPlugin.dev.js +3 -1
  13. package/LexicalAutoLinkPlugin.esm.js +11 -0
  14. package/LexicalAutoLinkPlugin.js +1 -1
  15. package/LexicalAutoLinkPlugin.prod.esm.js +7 -0
  16. package/LexicalBlockWithAlignableContents.dev.esm.js +86 -0
  17. package/LexicalBlockWithAlignableContents.dev.js +1 -0
  18. package/LexicalBlockWithAlignableContents.esm.js +10 -0
  19. package/LexicalBlockWithAlignableContents.js +1 -1
  20. package/LexicalBlockWithAlignableContents.prod.esm.js +7 -0
  21. package/LexicalBlockWithAlignableContents.prod.js +1 -1
  22. package/LexicalCharacterLimitPlugin.d.ts +4 -1
  23. package/LexicalCharacterLimitPlugin.dev.esm.js +272 -0
  24. package/LexicalCharacterLimitPlugin.dev.js +12 -4
  25. package/LexicalCharacterLimitPlugin.esm.js +10 -0
  26. package/LexicalCharacterLimitPlugin.js +1 -1
  27. package/LexicalCharacterLimitPlugin.prod.esm.js +7 -0
  28. package/LexicalCharacterLimitPlugin.prod.js +9 -9
  29. package/LexicalCheckListPlugin.dev.esm.js +203 -0
  30. package/LexicalCheckListPlugin.esm.js +10 -0
  31. package/LexicalCheckListPlugin.js +1 -1
  32. package/LexicalCheckListPlugin.prod.esm.js +7 -0
  33. package/LexicalClearEditorPlugin.dev.esm.js +64 -0
  34. package/LexicalClearEditorPlugin.esm.js +10 -0
  35. package/LexicalClearEditorPlugin.js +1 -1
  36. package/LexicalClearEditorPlugin.prod.esm.js +7 -0
  37. package/LexicalClickableLinkPlugin.dev.esm.js +95 -0
  38. package/LexicalClickableLinkPlugin.esm.js +10 -0
  39. package/LexicalClickableLinkPlugin.js +1 -1
  40. package/LexicalClickableLinkPlugin.prod.esm.js +7 -0
  41. package/LexicalCollaborationContext.dev.esm.js +36 -0
  42. package/LexicalCollaborationContext.esm.js +11 -0
  43. package/LexicalCollaborationContext.js +1 -1
  44. package/LexicalCollaborationContext.prod.esm.js +7 -0
  45. package/LexicalCollaborationPlugin.dev.esm.js +308 -0
  46. package/LexicalCollaborationPlugin.esm.js +10 -0
  47. package/LexicalCollaborationPlugin.js +1 -1
  48. package/LexicalCollaborationPlugin.prod.esm.js +7 -0
  49. package/LexicalComposer.dev.esm.js +129 -0
  50. package/LexicalComposer.esm.js +10 -0
  51. package/LexicalComposer.js +1 -1
  52. package/LexicalComposer.prod.esm.js +7 -0
  53. package/LexicalComposerContext.dev.esm.js +42 -0
  54. package/LexicalComposerContext.esm.js +12 -0
  55. package/LexicalComposerContext.js +1 -1
  56. package/LexicalComposerContext.prod.esm.js +7 -0
  57. package/LexicalContentEditable.dev.esm.js +107 -0
  58. package/LexicalContentEditable.dev.js +5 -1
  59. package/LexicalContentEditable.esm.js +10 -0
  60. package/LexicalContentEditable.js +1 -1
  61. package/LexicalContentEditable.prod.esm.js +7 -0
  62. package/LexicalContentEditable.prod.js +3 -3
  63. package/LexicalContextMenuPlugin.dev.esm.js +455 -0
  64. package/LexicalContextMenuPlugin.dev.js +3 -1
  65. package/LexicalContextMenuPlugin.esm.js +11 -0
  66. package/LexicalContextMenuPlugin.js +1 -1
  67. package/LexicalContextMenuPlugin.prod.esm.js +7 -0
  68. package/LexicalDecoratorBlockNode.dev.esm.js +46 -0
  69. package/LexicalDecoratorBlockNode.esm.js +11 -0
  70. package/LexicalDecoratorBlockNode.js +1 -1
  71. package/LexicalDecoratorBlockNode.prod.esm.js +7 -0
  72. package/LexicalEditorRefPlugin.dev.esm.js +40 -0
  73. package/LexicalEditorRefPlugin.dev.js +10 -5
  74. package/LexicalEditorRefPlugin.esm.js +10 -0
  75. package/LexicalEditorRefPlugin.js +1 -1
  76. package/LexicalEditorRefPlugin.prod.esm.js +7 -0
  77. package/LexicalEditorRefPlugin.prod.js +1 -1
  78. package/LexicalErrorBoundary.dev.esm.js +157 -0
  79. package/LexicalErrorBoundary.esm.js +10 -0
  80. package/LexicalErrorBoundary.js +1 -1
  81. package/LexicalErrorBoundary.prod.esm.js +7 -0
  82. package/LexicalHashtagPlugin.dev.esm.js +163 -0
  83. package/LexicalHashtagPlugin.esm.js +10 -0
  84. package/LexicalHashtagPlugin.js +1 -1
  85. package/LexicalHashtagPlugin.prod.esm.js +7 -0
  86. package/LexicalHistoryPlugin.dev.esm.js +41 -0
  87. package/LexicalHistoryPlugin.esm.js +11 -0
  88. package/LexicalHistoryPlugin.js +1 -1
  89. package/LexicalHistoryPlugin.prod.esm.js +7 -0
  90. package/LexicalHorizontalRuleNode.dev.esm.js +118 -0
  91. package/LexicalHorizontalRuleNode.dev.js +1 -0
  92. package/LexicalHorizontalRuleNode.esm.js +13 -0
  93. package/LexicalHorizontalRuleNode.js +1 -1
  94. package/LexicalHorizontalRuleNode.prod.esm.js +7 -0
  95. package/LexicalHorizontalRuleNode.prod.js +1 -1
  96. package/LexicalHorizontalRulePlugin.dev.esm.js +39 -0
  97. package/LexicalHorizontalRulePlugin.esm.js +10 -0
  98. package/LexicalHorizontalRulePlugin.js +1 -1
  99. package/LexicalHorizontalRulePlugin.prod.esm.js +7 -0
  100. package/LexicalLinkPlugin.dev.esm.js +79 -0
  101. package/LexicalLinkPlugin.dev.js +6 -2
  102. package/LexicalLinkPlugin.esm.js +10 -0
  103. package/LexicalLinkPlugin.js +1 -1
  104. package/LexicalLinkPlugin.prod.esm.js +7 -0
  105. package/LexicalLinkPlugin.prod.js +1 -1
  106. package/LexicalListPlugin.dev.esm.js +59 -0
  107. package/LexicalListPlugin.esm.js +10 -0
  108. package/LexicalListPlugin.js +1 -1
  109. package/LexicalListPlugin.prod.esm.js +7 -0
  110. package/LexicalMarkdownShortcutPlugin.dev.esm.js +49 -0
  111. package/LexicalMarkdownShortcutPlugin.esm.js +11 -0
  112. package/LexicalMarkdownShortcutPlugin.js +1 -1
  113. package/LexicalMarkdownShortcutPlugin.prod.esm.js +7 -0
  114. package/LexicalNestedComposer.dev.esm.js +105 -0
  115. package/LexicalNestedComposer.esm.js +10 -0
  116. package/LexicalNestedComposer.js +1 -1
  117. package/LexicalNestedComposer.prod.esm.js +7 -0
  118. package/LexicalNodeEventPlugin.dev.esm.js +56 -0
  119. package/LexicalNodeEventPlugin.esm.js +10 -0
  120. package/LexicalNodeEventPlugin.js +1 -1
  121. package/LexicalNodeEventPlugin.prod.esm.js +7 -0
  122. package/LexicalNodeMenuPlugin.dev.esm.js +466 -0
  123. package/LexicalNodeMenuPlugin.dev.js +3 -1
  124. package/LexicalNodeMenuPlugin.esm.js +11 -0
  125. package/LexicalNodeMenuPlugin.js +1 -1
  126. package/LexicalNodeMenuPlugin.prod.esm.js +7 -0
  127. package/LexicalOnChangePlugin.dev.esm.js +62 -0
  128. package/LexicalOnChangePlugin.esm.js +10 -0
  129. package/LexicalOnChangePlugin.js +1 -1
  130. package/LexicalOnChangePlugin.prod.esm.js +7 -0
  131. package/LexicalPlainTextPlugin.dev.esm.js +161 -0
  132. package/LexicalPlainTextPlugin.esm.js +10 -0
  133. package/LexicalPlainTextPlugin.js +1 -1
  134. package/LexicalPlainTextPlugin.prod.esm.js +7 -0
  135. package/LexicalRichTextPlugin.dev.esm.js +161 -0
  136. package/LexicalRichTextPlugin.esm.js +10 -0
  137. package/LexicalRichTextPlugin.js +1 -1
  138. package/LexicalRichTextPlugin.prod.esm.js +7 -0
  139. package/LexicalTabIndentationPlugin.dev.esm.js +76 -0
  140. package/LexicalTabIndentationPlugin.esm.js +11 -0
  141. package/LexicalTabIndentationPlugin.js +1 -1
  142. package/LexicalTabIndentationPlugin.prod.esm.js +7 -0
  143. package/LexicalTableOfContents.dev.esm.js +157 -0
  144. package/LexicalTableOfContents.esm.js +10 -0
  145. package/LexicalTableOfContents.js +1 -1
  146. package/LexicalTableOfContents.prod.esm.js +7 -0
  147. package/LexicalTablePlugin.dev.esm.js +163 -0
  148. package/LexicalTablePlugin.esm.js +10 -0
  149. package/LexicalTablePlugin.js +1 -1
  150. package/LexicalTablePlugin.prod.esm.js +7 -0
  151. package/LexicalTreeView.dev.esm.js +483 -0
  152. package/LexicalTreeView.dev.js +3 -1
  153. package/LexicalTreeView.esm.js +10 -0
  154. package/LexicalTreeView.js +1 -1
  155. package/LexicalTreeView.prod.esm.js +7 -0
  156. package/LexicalTypeaheadMenuPlugin.dev.esm.js +569 -0
  157. package/LexicalTypeaheadMenuPlugin.dev.js +3 -1
  158. package/LexicalTypeaheadMenuPlugin.esm.js +16 -0
  159. package/LexicalTypeaheadMenuPlugin.js +1 -1
  160. package/LexicalTypeaheadMenuPlugin.prod.esm.js +7 -0
  161. package/package.json +583 -20
  162. package/useLexicalEditable.dev.esm.js +82 -0
  163. package/useLexicalEditable.esm.js +10 -0
  164. package/useLexicalEditable.js +1 -1
  165. package/useLexicalEditable.prod.esm.js +7 -0
  166. package/useLexicalIsTextContentEmpty.dev.esm.js +51 -0
  167. package/useLexicalIsTextContentEmpty.esm.js +10 -0
  168. package/useLexicalIsTextContentEmpty.js +1 -1
  169. package/useLexicalIsTextContentEmpty.prod.esm.js +7 -0
  170. package/useLexicalNodeSelection.dev.esm.js +69 -0
  171. package/useLexicalNodeSelection.esm.js +10 -0
  172. package/useLexicalNodeSelection.js +1 -1
  173. package/useLexicalNodeSelection.prod.esm.js +7 -0
  174. package/useLexicalSubscription.dev.esm.js +63 -0
  175. package/useLexicalSubscription.esm.js +10 -0
  176. package/useLexicalSubscription.js +1 -1
  177. package/useLexicalSubscription.prod.esm.js +7 -0
  178. package/useLexicalTextEntity.dev.esm.js +26 -0
  179. package/useLexicalTextEntity.esm.js +10 -0
  180. package/useLexicalTextEntity.js +1 -1
  181. package/useLexicalTextEntity.prod.esm.js +7 -0
@@ -0,0 +1,569 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
8
+ import { createCommand, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW, $getSelection, $isRangeSelection, $isTextNode } from 'lexical';
9
+ import * as React from 'react';
10
+ import { useLayoutEffect as useLayoutEffect$1, useEffect, useState, useCallback, useMemo, useRef } from 'react';
11
+ import { mergeRegister } from '@lexical/utils';
12
+
13
+ /**
14
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
15
+ *
16
+ * This source code is licensed under the MIT license found in the
17
+ * LICENSE file in the root directory of this source tree.
18
+ *
19
+ */
20
+
21
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
22
+
23
+ /**
24
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
25
+ *
26
+ * This source code is licensed under the MIT license found in the
27
+ * LICENSE file in the root directory of this source tree.
28
+ *
29
+ */
30
+ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect$1 : useEffect;
31
+ var useLayoutEffect = useLayoutEffectImpl;
32
+
33
+ /**
34
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
35
+ *
36
+ * This source code is licensed under the MIT license found in the
37
+ * LICENSE file in the root directory of this source tree.
38
+ *
39
+ */
40
+ class MenuOption {
41
+ constructor(key) {
42
+ this.key = key;
43
+ this.ref = {
44
+ current: null
45
+ };
46
+ this.setRefElement = this.setRefElement.bind(this);
47
+ }
48
+ setRefElement(element) {
49
+ this.ref = {
50
+ current: element
51
+ };
52
+ }
53
+ }
54
+ const scrollIntoViewIfNeeded = target => {
55
+ const typeaheadContainerNode = document.getElementById('typeahead-menu');
56
+ if (!typeaheadContainerNode) {
57
+ return;
58
+ }
59
+ const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
60
+ if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {
61
+ typeaheadContainerNode.scrollIntoView({
62
+ block: 'center'
63
+ });
64
+ }
65
+ if (typeaheadRect.top < 0) {
66
+ typeaheadContainerNode.scrollIntoView({
67
+ block: 'center'
68
+ });
69
+ }
70
+ target.scrollIntoView({
71
+ block: 'nearest'
72
+ });
73
+ };
74
+
75
+ /**
76
+ * Walk backwards along user input and forward through entity title to try
77
+ * and replace more of the user's text with entity.
78
+ */
79
+ function getFullMatchOffset(documentText, entryText, offset) {
80
+ let triggerOffset = offset;
81
+ for (let i = triggerOffset; i <= entryText.length; i++) {
82
+ if (documentText.substr(-i) === entryText.substr(0, i)) {
83
+ triggerOffset = i;
84
+ }
85
+ }
86
+ return triggerOffset;
87
+ }
88
+
89
+ /**
90
+ * Split Lexical TextNode and return a new TextNode only containing matched text.
91
+ * Common use cases include: removing the node, replacing with a new node.
92
+ */
93
+ function $splitNodeContainingQuery(match) {
94
+ const selection = $getSelection();
95
+ if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
96
+ return null;
97
+ }
98
+ const anchor = selection.anchor;
99
+ if (anchor.type !== 'text') {
100
+ return null;
101
+ }
102
+ const anchorNode = anchor.getNode();
103
+ if (!anchorNode.isSimpleText()) {
104
+ return null;
105
+ }
106
+ const selectionOffset = anchor.offset;
107
+ const textContent = anchorNode.getTextContent().slice(0, selectionOffset);
108
+ const characterOffset = match.replaceableString.length;
109
+ const queryOffset = getFullMatchOffset(textContent, match.matchingString, characterOffset);
110
+ const startOffset = selectionOffset - queryOffset;
111
+ if (startOffset < 0) {
112
+ return null;
113
+ }
114
+ let newNode;
115
+ if (startOffset === 0) {
116
+ [newNode] = anchorNode.splitText(selectionOffset);
117
+ } else {
118
+ [, newNode] = anchorNode.splitText(startOffset, selectionOffset);
119
+ }
120
+ return newNode;
121
+ }
122
+
123
+ // Got from https://stackoverflow.com/a/42543908/2013580
124
+ function getScrollParent$1(element, includeHidden) {
125
+ let style = getComputedStyle(element);
126
+ const excludeStaticParent = style.position === 'absolute';
127
+ const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
128
+ if (style.position === 'fixed') {
129
+ return document.body;
130
+ }
131
+ for (let parent = element; parent = parent.parentElement;) {
132
+ style = getComputedStyle(parent);
133
+ if (excludeStaticParent && style.position === 'static') {
134
+ continue;
135
+ }
136
+ if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {
137
+ return parent;
138
+ }
139
+ }
140
+ return document.body;
141
+ }
142
+ function isTriggerVisibleInNearestScrollContainer(targetElement, containerElement) {
143
+ const tRect = targetElement.getBoundingClientRect();
144
+ const cRect = containerElement.getBoundingClientRect();
145
+ return tRect.top > cRect.top && tRect.top < cRect.bottom;
146
+ }
147
+
148
+ // Reposition the menu on scroll, window resize, and element resize.
149
+ function useDynamicPositioning(resolution, targetElement, onReposition, onVisibilityChange) {
150
+ const [editor] = useLexicalComposerContext();
151
+ useEffect(() => {
152
+ if (targetElement != null && resolution != null) {
153
+ const rootElement = editor.getRootElement();
154
+ const rootScrollParent = rootElement != null ? getScrollParent$1(rootElement, false) : document.body;
155
+ let ticking = false;
156
+ let previousIsInView = isTriggerVisibleInNearestScrollContainer(targetElement, rootScrollParent);
157
+ const handleScroll = function () {
158
+ if (!ticking) {
159
+ window.requestAnimationFrame(function () {
160
+ onReposition();
161
+ ticking = false;
162
+ });
163
+ ticking = true;
164
+ }
165
+ const isInView = isTriggerVisibleInNearestScrollContainer(targetElement, rootScrollParent);
166
+ if (isInView !== previousIsInView) {
167
+ previousIsInView = isInView;
168
+ if (onVisibilityChange != null) {
169
+ onVisibilityChange(isInView);
170
+ }
171
+ }
172
+ };
173
+ const resizeObserver = new ResizeObserver(onReposition);
174
+ window.addEventListener('resize', onReposition);
175
+ document.addEventListener('scroll', handleScroll, {
176
+ capture: true,
177
+ passive: true
178
+ });
179
+ resizeObserver.observe(targetElement);
180
+ return () => {
181
+ resizeObserver.unobserve(targetElement);
182
+ window.removeEventListener('resize', onReposition);
183
+ document.removeEventListener('scroll', handleScroll, true);
184
+ };
185
+ }
186
+ }, [targetElement, editor, onVisibilityChange, onReposition, resolution]);
187
+ }
188
+ const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND$1 = createCommand('SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND');
189
+ function LexicalMenu({
190
+ close,
191
+ editor,
192
+ anchorElementRef,
193
+ resolution,
194
+ options,
195
+ menuRenderFn,
196
+ onSelectOption,
197
+ shouldSplitNodeWithQuery = false,
198
+ commandPriority = COMMAND_PRIORITY_LOW
199
+ }) {
200
+ const [selectedIndex, setHighlightedIndex] = useState(null);
201
+ const matchingString = resolution.match && resolution.match.matchingString;
202
+ useEffect(() => {
203
+ setHighlightedIndex(0);
204
+ }, [matchingString]);
205
+ const selectOptionAndCleanUp = useCallback(selectedEntry => {
206
+ editor.update(() => {
207
+ const textNodeContainingQuery = resolution.match != null && shouldSplitNodeWithQuery ? $splitNodeContainingQuery(resolution.match) : null;
208
+ onSelectOption(selectedEntry, textNodeContainingQuery, close, resolution.match ? resolution.match.matchingString : '');
209
+ });
210
+ }, [editor, shouldSplitNodeWithQuery, resolution.match, onSelectOption, close]);
211
+ const updateSelectedIndex = useCallback(index => {
212
+ const rootElem = editor.getRootElement();
213
+ if (rootElem !== null) {
214
+ rootElem.setAttribute('aria-activedescendant', 'typeahead-item-' + index);
215
+ setHighlightedIndex(index);
216
+ }
217
+ }, [editor]);
218
+ useEffect(() => {
219
+ return () => {
220
+ const rootElem = editor.getRootElement();
221
+ if (rootElem !== null) {
222
+ rootElem.removeAttribute('aria-activedescendant');
223
+ }
224
+ };
225
+ }, [editor]);
226
+ useLayoutEffect(() => {
227
+ if (options === null) {
228
+ setHighlightedIndex(null);
229
+ } else if (selectedIndex === null) {
230
+ updateSelectedIndex(0);
231
+ }
232
+ }, [options, selectedIndex, updateSelectedIndex]);
233
+ useEffect(() => {
234
+ return mergeRegister(editor.registerCommand(SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND$1, ({
235
+ option
236
+ }) => {
237
+ if (option.ref && option.ref.current != null) {
238
+ scrollIntoViewIfNeeded(option.ref.current);
239
+ return true;
240
+ }
241
+ return false;
242
+ }, commandPriority));
243
+ }, [editor, updateSelectedIndex, commandPriority]);
244
+ useEffect(() => {
245
+ return mergeRegister(editor.registerCommand(KEY_ARROW_DOWN_COMMAND, payload => {
246
+ const event = payload;
247
+ if (options !== null && options.length && selectedIndex !== null) {
248
+ const newSelectedIndex = selectedIndex !== options.length - 1 ? selectedIndex + 1 : 0;
249
+ updateSelectedIndex(newSelectedIndex);
250
+ const option = options[newSelectedIndex];
251
+ if (option.ref != null && option.ref.current) {
252
+ editor.dispatchCommand(SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND$1, {
253
+ index: newSelectedIndex,
254
+ option
255
+ });
256
+ }
257
+ event.preventDefault();
258
+ event.stopImmediatePropagation();
259
+ }
260
+ return true;
261
+ }, commandPriority), editor.registerCommand(KEY_ARROW_UP_COMMAND, payload => {
262
+ const event = payload;
263
+ if (options !== null && options.length && selectedIndex !== null) {
264
+ const newSelectedIndex = selectedIndex !== 0 ? selectedIndex - 1 : options.length - 1;
265
+ updateSelectedIndex(newSelectedIndex);
266
+ const option = options[newSelectedIndex];
267
+ if (option.ref != null && option.ref.current) {
268
+ scrollIntoViewIfNeeded(option.ref.current);
269
+ }
270
+ event.preventDefault();
271
+ event.stopImmediatePropagation();
272
+ }
273
+ return true;
274
+ }, commandPriority), editor.registerCommand(KEY_ESCAPE_COMMAND, payload => {
275
+ const event = payload;
276
+ event.preventDefault();
277
+ event.stopImmediatePropagation();
278
+ close();
279
+ return true;
280
+ }, commandPriority), editor.registerCommand(KEY_TAB_COMMAND, payload => {
281
+ const event = payload;
282
+ if (options === null || selectedIndex === null || options[selectedIndex] == null) {
283
+ return false;
284
+ }
285
+ event.preventDefault();
286
+ event.stopImmediatePropagation();
287
+ selectOptionAndCleanUp(options[selectedIndex]);
288
+ return true;
289
+ }, commandPriority), editor.registerCommand(KEY_ENTER_COMMAND, event => {
290
+ if (options === null || selectedIndex === null || options[selectedIndex] == null) {
291
+ return false;
292
+ }
293
+ if (event !== null) {
294
+ event.preventDefault();
295
+ event.stopImmediatePropagation();
296
+ }
297
+ selectOptionAndCleanUp(options[selectedIndex]);
298
+ return true;
299
+ }, commandPriority));
300
+ }, [selectOptionAndCleanUp, close, editor, options, selectedIndex, updateSelectedIndex, commandPriority]);
301
+ const listItemProps = useMemo(() => ({
302
+ options,
303
+ selectOptionAndCleanUp,
304
+ selectedIndex,
305
+ setHighlightedIndex
306
+ }), [selectOptionAndCleanUp, selectedIndex, options]);
307
+ return menuRenderFn(anchorElementRef, listItemProps, resolution.match ? resolution.match.matchingString : '');
308
+ }
309
+ function useMenuAnchorRef(resolution, setResolution, className, parent = document.body) {
310
+ const [editor] = useLexicalComposerContext();
311
+ const anchorElementRef = useRef(document.createElement('div'));
312
+ const positionMenu = useCallback(() => {
313
+ anchorElementRef.current.style.top = anchorElementRef.current.style.bottom;
314
+ const rootElement = editor.getRootElement();
315
+ const containerDiv = anchorElementRef.current;
316
+ const menuEle = containerDiv.firstChild;
317
+ if (rootElement !== null && resolution !== null) {
318
+ const {
319
+ left,
320
+ top,
321
+ width,
322
+ height
323
+ } = resolution.getRect();
324
+ const anchorHeight = anchorElementRef.current.offsetHeight; // use to position under anchor
325
+ containerDiv.style.top = `${top + window.pageYOffset + anchorHeight + 3}px`;
326
+ containerDiv.style.left = `${left + window.pageXOffset}px`;
327
+ containerDiv.style.height = `${height}px`;
328
+ containerDiv.style.width = `${width}px`;
329
+ if (menuEle !== null) {
330
+ menuEle.style.top = `${top}`;
331
+ const menuRect = menuEle.getBoundingClientRect();
332
+ const menuHeight = menuRect.height;
333
+ const menuWidth = menuRect.width;
334
+ const rootElementRect = rootElement.getBoundingClientRect();
335
+ if (left + menuWidth > rootElementRect.right) {
336
+ containerDiv.style.left = `${rootElementRect.right - menuWidth + window.pageXOffset}px`;
337
+ }
338
+ if ((top + menuHeight > window.innerHeight || top + menuHeight > rootElementRect.bottom) && top - rootElementRect.top > menuHeight) {
339
+ containerDiv.style.top = `${top - menuHeight + window.pageYOffset - height}px`;
340
+ }
341
+ }
342
+ if (!containerDiv.isConnected) {
343
+ if (className != null) {
344
+ containerDiv.className = className;
345
+ }
346
+ containerDiv.setAttribute('aria-label', 'Typeahead menu');
347
+ containerDiv.setAttribute('id', 'typeahead-menu');
348
+ containerDiv.setAttribute('role', 'listbox');
349
+ containerDiv.style.display = 'block';
350
+ containerDiv.style.position = 'absolute';
351
+ parent.append(containerDiv);
352
+ }
353
+ anchorElementRef.current = containerDiv;
354
+ rootElement.setAttribute('aria-controls', 'typeahead-menu');
355
+ }
356
+ }, [editor, resolution, className, parent]);
357
+ useEffect(() => {
358
+ const rootElement = editor.getRootElement();
359
+ if (resolution !== null) {
360
+ positionMenu();
361
+ return () => {
362
+ if (rootElement !== null) {
363
+ rootElement.removeAttribute('aria-controls');
364
+ }
365
+ const containerDiv = anchorElementRef.current;
366
+ if (containerDiv !== null && containerDiv.isConnected) {
367
+ containerDiv.remove();
368
+ }
369
+ };
370
+ }
371
+ }, [editor, positionMenu, resolution]);
372
+ const onVisibilityChange = useCallback(isInView => {
373
+ if (resolution !== null) {
374
+ if (!isInView) {
375
+ setResolution(null);
376
+ }
377
+ }
378
+ }, [resolution, setResolution]);
379
+ useDynamicPositioning(resolution, anchorElementRef.current, positionMenu, onVisibilityChange);
380
+ return anchorElementRef;
381
+ }
382
+
383
+ /**
384
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
385
+ *
386
+ * This source code is licensed under the MIT license found in the
387
+ * LICENSE file in the root directory of this source tree.
388
+ *
389
+ */
390
+ const PUNCTUATION = '\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%\'"~=<>_:;';
391
+ function getTextUpToAnchor(selection) {
392
+ const anchor = selection.anchor;
393
+ if (anchor.type !== 'text') {
394
+ return null;
395
+ }
396
+ const anchorNode = anchor.getNode();
397
+ if (!anchorNode.isSimpleText()) {
398
+ return null;
399
+ }
400
+ const anchorOffset = anchor.offset;
401
+ return anchorNode.getTextContent().slice(0, anchorOffset);
402
+ }
403
+ function tryToPositionRange(leadOffset, range, editorWindow) {
404
+ const domSelection = editorWindow.getSelection();
405
+ if (domSelection === null || !domSelection.isCollapsed) {
406
+ return false;
407
+ }
408
+ const anchorNode = domSelection.anchorNode;
409
+ const startOffset = leadOffset;
410
+ const endOffset = domSelection.anchorOffset;
411
+ if (anchorNode == null || endOffset == null) {
412
+ return false;
413
+ }
414
+ try {
415
+ range.setStart(anchorNode, startOffset);
416
+ range.setEnd(anchorNode, endOffset);
417
+ } catch (error) {
418
+ return false;
419
+ }
420
+ return true;
421
+ }
422
+ function getQueryTextForSearch(editor) {
423
+ let text = null;
424
+ editor.getEditorState().read(() => {
425
+ const selection = $getSelection();
426
+ if (!$isRangeSelection(selection)) {
427
+ return;
428
+ }
429
+ text = getTextUpToAnchor(selection);
430
+ });
431
+ return text;
432
+ }
433
+ function isSelectionOnEntityBoundary(editor, offset) {
434
+ if (offset !== 0) {
435
+ return false;
436
+ }
437
+ return editor.getEditorState().read(() => {
438
+ const selection = $getSelection();
439
+ if ($isRangeSelection(selection)) {
440
+ const anchor = selection.anchor;
441
+ const anchorNode = anchor.getNode();
442
+ const prevSibling = anchorNode.getPreviousSibling();
443
+ return $isTextNode(prevSibling) && prevSibling.isTextEntity();
444
+ }
445
+ return false;
446
+ });
447
+ }
448
+ function startTransition(callback) {
449
+ if (React.startTransition) {
450
+ React.startTransition(callback);
451
+ } else {
452
+ callback();
453
+ }
454
+ }
455
+
456
+ // Got from https://stackoverflow.com/a/42543908/2013580
457
+ function getScrollParent(element, includeHidden) {
458
+ let style = getComputedStyle(element);
459
+ const excludeStaticParent = style.position === 'absolute';
460
+ const overflowRegex = includeHidden ? /(auto|scroll|hidden)/ : /(auto|scroll)/;
461
+ if (style.position === 'fixed') {
462
+ return document.body;
463
+ }
464
+ for (let parent = element; parent = parent.parentElement;) {
465
+ style = getComputedStyle(parent);
466
+ if (excludeStaticParent && style.position === 'static') {
467
+ continue;
468
+ }
469
+ if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {
470
+ return parent;
471
+ }
472
+ }
473
+ return document.body;
474
+ }
475
+ const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND = createCommand('SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND');
476
+ function useBasicTypeaheadTriggerMatch(trigger, {
477
+ minLength = 1,
478
+ maxLength = 75
479
+ }) {
480
+ return useCallback(text => {
481
+ const validChars = '[^' + trigger + PUNCTUATION + '\\s]';
482
+ const TypeaheadTriggerRegex = new RegExp('(^|\\s|\\()(' + '[' + trigger + ']' + '((?:' + validChars + '){0,' + maxLength + '})' + ')$');
483
+ const match = TypeaheadTriggerRegex.exec(text);
484
+ if (match !== null) {
485
+ const maybeLeadingWhitespace = match[1];
486
+ const matchingString = match[3];
487
+ if (matchingString.length >= minLength) {
488
+ return {
489
+ leadOffset: match.index + maybeLeadingWhitespace.length,
490
+ matchingString,
491
+ replaceableString: match[2]
492
+ };
493
+ }
494
+ }
495
+ return null;
496
+ }, [maxLength, minLength, trigger]);
497
+ }
498
+ function LexicalTypeaheadMenuPlugin({
499
+ options,
500
+ onQueryChange,
501
+ onSelectOption,
502
+ onOpen,
503
+ onClose,
504
+ menuRenderFn,
505
+ triggerFn,
506
+ anchorClassName,
507
+ commandPriority = COMMAND_PRIORITY_LOW,
508
+ parent
509
+ }) {
510
+ const [editor] = useLexicalComposerContext();
511
+ const [resolution, setResolution] = useState(null);
512
+ const anchorElementRef = useMenuAnchorRef(resolution, setResolution, anchorClassName, parent);
513
+ const closeTypeahead = useCallback(() => {
514
+ setResolution(null);
515
+ if (onClose != null && resolution !== null) {
516
+ onClose();
517
+ }
518
+ }, [onClose, resolution]);
519
+ const openTypeahead = useCallback(res => {
520
+ setResolution(res);
521
+ if (onOpen != null && resolution === null) {
522
+ onOpen(res);
523
+ }
524
+ }, [onOpen, resolution]);
525
+ useEffect(() => {
526
+ const updateListener = () => {
527
+ editor.getEditorState().read(() => {
528
+ const editorWindow = editor._window || window;
529
+ const range = editorWindow.document.createRange();
530
+ const selection = $getSelection();
531
+ const text = getQueryTextForSearch(editor);
532
+ if (!$isRangeSelection(selection) || !selection.isCollapsed() || text === null || range === null) {
533
+ closeTypeahead();
534
+ return;
535
+ }
536
+ const match = triggerFn(text, editor);
537
+ onQueryChange(match ? match.matchingString : null);
538
+ if (match !== null && !isSelectionOnEntityBoundary(editor, match.leadOffset)) {
539
+ const isRangePositioned = tryToPositionRange(match.leadOffset, range, editorWindow);
540
+ if (isRangePositioned !== null) {
541
+ startTransition(() => openTypeahead({
542
+ getRect: () => range.getBoundingClientRect(),
543
+ match
544
+ }));
545
+ return;
546
+ }
547
+ }
548
+ closeTypeahead();
549
+ });
550
+ };
551
+ const removeUpdateListener = editor.registerUpdateListener(updateListener);
552
+ return () => {
553
+ removeUpdateListener();
554
+ };
555
+ }, [editor, triggerFn, onQueryChange, resolution, closeTypeahead, openTypeahead]);
556
+ return resolution === null || editor === null ? null : /*#__PURE__*/React.createElement(LexicalMenu, {
557
+ close: closeTypeahead,
558
+ resolution: resolution,
559
+ editor: editor,
560
+ anchorElementRef: anchorElementRef,
561
+ options: options,
562
+ menuRenderFn: menuRenderFn,
563
+ shouldSplitNodeWithQuery: true,
564
+ onSelectOption: onSelectOption,
565
+ commandPriority: commandPriority
566
+ });
567
+ }
568
+
569
+ export { LexicalTypeaheadMenuPlugin, MenuOption, PUNCTUATION, SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND, getScrollParent, useBasicTypeaheadTriggerMatch, useDynamicPositioning };
@@ -54,7 +54,9 @@ class MenuOption {
54
54
  }
55
55
  const scrollIntoViewIfNeeded = target => {
56
56
  const typeaheadContainerNode = document.getElementById('typeahead-menu');
57
- if (!typeaheadContainerNode) return;
57
+ if (!typeaheadContainerNode) {
58
+ return;
59
+ }
58
60
  const typeaheadRect = typeaheadContainerNode.getBoundingClientRect();
59
61
  if (typeaheadRect.top + typeaheadRect.height > window.innerHeight) {
60
62
  typeaheadContainerNode.scrollIntoView({
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import * as modDev from './LexicalTypeaheadMenuPlugin.dev.esm.js';
8
+ import * as modProd from './LexicalTypeaheadMenuPlugin.prod.esm.js';
9
+ const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
10
+ export const LexicalTypeaheadMenuPlugin = mod.LexicalTypeaheadMenuPlugin;
11
+ export const MenuOption = mod.MenuOption;
12
+ export const PUNCTUATION = mod.PUNCTUATION;
13
+ export const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND = mod.SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND;
14
+ export const getScrollParent = mod.getScrollParent;
15
+ export const useBasicTypeaheadTriggerMatch = mod.useBasicTypeaheadTriggerMatch;
16
+ export const useDynamicPositioning = mod.useDynamicPositioning;
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  'use strict'
8
- const LexicalTypeaheadMenuPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTypeaheadMenuPlugin.dev.js') : require('./LexicalTypeaheadMenuPlugin.prod.js')
8
+ const LexicalTypeaheadMenuPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalTypeaheadMenuPlugin.dev.js') : require('./LexicalTypeaheadMenuPlugin.prod.js');
9
9
  module.exports = LexicalTypeaheadMenuPlugin;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createCommand as e,KEY_ARROW_DOWN_COMMAND as n,KEY_ARROW_UP_COMMAND as o,KEY_ESCAPE_COMMAND as r,KEY_TAB_COMMAND as l,KEY_ENTER_COMMAND as i,COMMAND_PRIORITY_LOW as s,$getSelection as u,$isRangeSelection as c,$isTextNode as a}from"lexical";import*as d from"react";import{useLayoutEffect as m,useEffect as f,useState as p,useCallback as g,useMemo as h,useRef as w}from"react";import{mergeRegister as y}from"@lexical/utils";var C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?m:f;class b{constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const v=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const n=e.getBoundingClientRect();n.top+n.height>window.innerHeight&&e.scrollIntoView({block:"center"}),n.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function E(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>o.top&&n.top<o.bottom}function x(e,n,o,r){const[l]=t();f((()=>{if(null!=n&&null!=e){const t=l.getRootElement(),e=null!=t?function(t,e){let n=getComputedStyle(t);const o="absolute"===n.position,r=e?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let e=t;e=e.parentElement;)if(n=getComputedStyle(e),(!o||"static"!==n.position)&&r.test(n.overflow+n.overflowY+n.overflowX))return e;return document.body}(t,!1):document.body;let i=!1,s=E(n,e);const u=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=E(n,e);t!==s&&(s=t,null!=r&&r(t))},c=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",u,{capture:!0,passive:!0}),c.observe(n),()=>{c.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",u,!0)}}}),[n,l,r,o,e])}const S=e("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function R({close:t,editor:e,anchorElementRef:a,resolution:d,options:m,menuRenderFn:w,onSelectOption:b,shouldSplitNodeWithQuery:E=!1,commandPriority:x=s}){const[R,O]=p(null),I=d.match&&d.match.matchingString;f((()=>{O(0)}),[I]);const T=g((n=>{e.update((()=>{const e=null!=d.match&&E?function(t){const e=u();if(!c(e)||!e.isCollapsed())return null;const n=e.anchor;if("text"!==n.type)return null;const o=n.getNode();if(!o.isSimpleText())return null;const r=n.offset,l=o.getTextContent().slice(0,r),i=t.replaceableString.length,s=r-function(t,e,n){let o=n;for(let n=o;n<=e.length;n++)t.substr(-n)===e.substr(0,n)&&(o=n);return o}(l,t.matchingString,i);if(s<0)return null;let a;return 0===s?[a]=o.splitText(r):[,a]=o.splitText(s,r),a}(d.match):null;b(n,e,t,d.match?d.match.matchingString:"")}))}),[e,E,d.match,b,t]),A=g((t=>{const n=e.getRootElement();null!==n&&(n.setAttribute("aria-activedescendant","typeahead-item-"+t),O(t))}),[e]);f((()=>()=>{const t=e.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[e]),C((()=>{null===m?O(null):null===R&&A(0)}),[m,R,A]),f((()=>y(e.registerCommand(S,(({option:t})=>!(!t.ref||null==t.ref.current)&&(v(t.ref.current),!0)),x))),[e,A,x]),f((()=>y(e.registerCommand(n,(t=>{const n=t;if(null!==m&&m.length&&null!==R){const t=R!==m.length-1?R+1:0;A(t);const o=m[t];null!=o.ref&&o.ref.current&&e.dispatchCommand(S,{index:t,option:o}),n.preventDefault(),n.stopImmediatePropagation()}return!0}),x),e.registerCommand(o,(t=>{const e=t;if(null!==m&&m.length&&null!==R){const t=0!==R?R-1:m.length-1;A(t);const n=m[t];null!=n.ref&&n.ref.current&&v(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),x),e.registerCommand(r,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),x),e.registerCommand(l,(t=>{const e=t;return null!==m&&null!==R&&null!=m[R]&&(e.preventDefault(),e.stopImmediatePropagation(),T(m[R]),!0)}),x),e.registerCommand(i,(t=>null!==m&&null!==R&&null!=m[R]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),T(m[R]),!0)),x))),[T,t,e,m,R,A,x]);return w(a,h((()=>({options:m,selectOptionAndCleanUp:T,selectedIndex:R,setHighlightedIndex:O})),[T,R,m]),d.match?d.match.matchingString:"")}const O="\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";function I(t,e){let n=getComputedStyle(t);const o="absolute"===n.position,r=e?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let e=t;e=e.parentElement;)if(n=getComputedStyle(e),(!o||"static"!==n.position)&&r.test(n.overflow+n.overflowY+n.overflowX))return e;return document.body}const T=e("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function A(t,{minLength:e=1,maxLength:n=75}){return g((o=>{const r=new RegExp("(^|\\s|\\()(["+t+"]((?:"+("[^"+t+O+"\\s]")+"){0,"+n+"}))$").exec(o);if(null!==r){const t=r[1],n=r[3];if(n.length>=e)return{leadOffset:r.index+t.length,matchingString:n,replaceableString:r[2]}}return null}),[n,e,t])}function N({options:e,onQueryChange:n,onSelectOption:o,onOpen:r,onClose:l,menuRenderFn:i,triggerFn:m,anchorClassName:h,commandPriority:y=s,parent:C}){const[b]=t(),[v,E]=p(null),S=function(e,n,o,r=document.body){const[l]=t(),i=w(document.createElement("div")),s=g((()=>{i.current.style.top=i.current.style.bottom;const t=l.getRootElement(),n=i.current,s=n.firstChild;if(null!==t&&null!==e){const{left:l,top:u,width:c,height:a}=e.getRect(),d=i.current.offsetHeight;if(n.style.top=`${u+window.pageYOffset+d+3}px`,n.style.left=`${l+window.pageXOffset}px`,n.style.height=`${a}px`,n.style.width=`${c}px`,null!==s){s.style.top=`${u}`;const e=s.getBoundingClientRect(),o=e.height,r=e.width,i=t.getBoundingClientRect();l+r>i.right&&(n.style.left=`${i.right-r+window.pageXOffset}px`),(u+o>window.innerHeight||u+o>i.bottom)&&u-i.top>o&&(n.style.top=u-o+window.pageYOffset-a+"px")}n.isConnected||(null!=o&&(n.className=o),n.setAttribute("aria-label","Typeahead menu"),n.setAttribute("id","typeahead-menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute",r.append(n)),i.current=n,t.setAttribute("aria-controls","typeahead-menu")}}),[l,e,o,r]);f((()=>{const t=l.getRootElement();if(null!==e)return s(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=i.current;null!==e&&e.isConnected&&e.remove()}}),[l,s,e]);const u=g((t=>{null!==e&&(t||n(null))}),[e,n]);return x(e,i.current,s,u),i}(v,E,h,C),O=g((()=>{E(null),null!=l&&null!==v&&l()}),[l,v]),I=g((t=>{E(t),null!=r&&null===v&&r(t)}),[r,v]);return f((()=>{const t=b.registerUpdateListener((()=>{b.getEditorState().read((()=>{const t=b._window||window,e=t.document.createRange(),o=u(),r=function(t){let e=null;return t.getEditorState().read((()=>{const t=u();c(t)&&(e=function(t){const e=t.anchor;if("text"!==e.type)return null;const n=e.getNode();if(!n.isSimpleText())return null;const o=e.offset;return n.getTextContent().slice(0,o)}(t))})),e}(b);if(!c(o)||!o.isCollapsed()||null===r||null===e)return void O();const l=m(r,b);if(n(l?l.matchingString:null),null!==l&&!function(t,e){return 0===e&&t.getEditorState().read((()=>{const t=u();if(c(t)){const e=t.anchor.getNode().getPreviousSibling();return a(e)&&e.isTextEntity()}return!1}))}(b,l.leadOffset)){const n=function(t,e,n){const o=n.getSelection();if(null===o||!o.isCollapsed)return!1;const r=o.anchorNode,l=t,i=o.anchorOffset;if(null==r||null==i)return!1;try{e.setStart(r,l),e.setEnd(r,i)}catch(t){return!1}return!0}(l.leadOffset,e,t);if(null!==n)return i=()=>I({getRect:()=>e.getBoundingClientRect(),match:l}),void(d.startTransition?d.startTransition(i):i())}var i;O()}))}));return()=>{t()}}),[b,m,n,v,O,I]),null===v||null===b?null:d.createElement(R,{close:O,resolution:v,editor:b,anchorElementRef:S,options:e,menuRenderFn:i,shouldSplitNodeWithQuery:!0,onSelectOption:o,commandPriority:y})}export{N as LexicalTypeaheadMenuPlugin,b as MenuOption,O as PUNCTUATION,T as SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND,I as getScrollParent,A as useBasicTypeaheadTriggerMatch,x as useDynamicPositioning};