@octanejs/lexical 0.2.6 → 0.2.7

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 (33) hide show
  1. package/package.json +5 -5
  2. package/src/LexicalAutoEmbedPlugin.tsrx +73 -61
  3. package/src/LexicalAutoFocusPlugin.tsrx +14 -11
  4. package/src/LexicalAutoLinkPlugin.tsrx +6 -5
  5. package/src/LexicalBlockWithAlignableContents.tsrx +13 -14
  6. package/src/LexicalCharacterLimitPlugin.tsrx +3 -1
  7. package/src/LexicalCheckListPlugin.tsrx +4 -4
  8. package/src/LexicalClearEditorPlugin.tsrx +3 -4
  9. package/src/LexicalClickableLinkPlugin.tsrx +4 -5
  10. package/src/LexicalComposer.tsrx +1 -1
  11. package/src/LexicalContentEditable.tsrx +11 -9
  12. package/src/LexicalDraggableBlockPlugin.tsrx +17 -15
  13. package/src/LexicalEditorRefPlugin.tsrx +2 -2
  14. package/src/LexicalErrorBoundary.tsrx +10 -6
  15. package/src/LexicalHistoryPlugin.tsrx +5 -5
  16. package/src/LexicalLinkPlugin.tsrx +4 -5
  17. package/src/LexicalListPlugin.tsrx +7 -8
  18. package/src/LexicalMarkdownShortcutPlugin.tsrx +4 -6
  19. package/src/LexicalNestedComposer.tsrx +9 -6
  20. package/src/LexicalNodeContextMenuPlugin.tsrx +15 -13
  21. package/src/LexicalNodeEventPlugin.tsrx +5 -6
  22. package/src/LexicalNodeMenuPlugin.tsrx +29 -20
  23. package/src/LexicalOnChangePlugin.tsrx +11 -15
  24. package/src/LexicalPlainTextPlugin.tsrx +4 -5
  25. package/src/LexicalRichTextPlugin.tsrx +4 -5
  26. package/src/LexicalSelectionAlwaysOnDisplay.tsrx +3 -4
  27. package/src/LexicalTabIndentationPlugin.tsrx +8 -9
  28. package/src/LexicalTableOfContentsPlugin.tsrx +83 -82
  29. package/src/LexicalTablePlugin.tsrx +24 -27
  30. package/src/LexicalTypeaheadMenuPlugin.tsrx +48 -31
  31. package/src/shared/LexicalContentEditableElement.tsrx +52 -47
  32. package/src/shared/LexicalDecorators.tsrx +24 -22
  33. package/src/shared/LexicalMenu.tsrx +52 -38
@@ -51,12 +51,15 @@ export class NodeContextMenuOption extends MenuOption {
51
51
  $onSelect: () => void;
52
52
  $showOn?: (node: LexicalNode) => boolean;
53
53
 
54
- constructor(title: string, options: {
55
- disabled?: boolean;
56
- icon?: OctaneNode;
57
- $onSelect: () => void;
58
- $showOn?: (node: LexicalNode) => boolean;
59
- }) {
54
+ constructor(
55
+ title: string,
56
+ options: {
57
+ disabled?: boolean;
58
+ icon?: OctaneNode;
59
+ $onSelect: () => void;
60
+ $showOn?: (node: LexicalNode) => boolean;
61
+ },
62
+ ) {
60
63
  super(title);
61
64
  this.type = 'item';
62
65
  this.title = title;
@@ -113,13 +116,12 @@ interface Props {
113
116
  // item-only fields are optional (`type` is a plain string, so the union does not
114
117
  // discriminate), plus the item's resolved getItemProps() bag —
115
118
  // `Record<string, unknown>`, the @octanejs/floating-ui prop-getter return type.
116
- type ContextMenuListItem =
117
- MenuSeparatorType & {
118
- disabled?: boolean;
119
- icon?: OctaneNode | null;
120
- label?: string;
121
- itemProps: Record<string, unknown>;
122
- };
119
+ type ContextMenuListItem = MenuSeparatorType & {
120
+ disabled?: boolean;
121
+ icon?: OctaneNode | null;
122
+ label?: string;
123
+ itemProps: Record<string, unknown>;
124
+ };
123
125
 
124
126
  type ContextMenuListProps = {
125
127
  className: string | undefined;
@@ -28,12 +28,11 @@ export function NodeEventPlugin(props: Props) {
28
28
  editor.update(() => {
29
29
  const nearestNode = $getNearestNodeFromDOMNode(event.target as Node);
30
30
  if (nearestNode !== null) {
31
- const targetNode =
32
- isCaptured
33
- ? nearestNode instanceof nodeType
34
- ? nearestNode
35
- : null
36
- : $findMatchingParent(nearestNode, (node) => node instanceof nodeType);
31
+ const targetNode = isCaptured
32
+ ? nearestNode instanceof nodeType
33
+ ? nearestNode
34
+ : null
35
+ : $findMatchingParent(nearestNode, (node) => node instanceof nodeType);
37
36
  if (targetNode !== null) {
38
37
  listenerRef.current(event, editor, targetNode.getKey());
39
38
  return;
@@ -15,8 +15,12 @@ export type { MenuRenderFn, MenuResolution } from './shared/menuShared';
15
15
  * Props for the {@link LexicalNodeMenuPlugin} component.
16
16
  */
17
17
  export type NodeMenuPluginProps<TOption extends MenuOption> = {
18
- onSelectOption: (option: TOption, textNodeContainingQuery: | TextNode
19
- | null, closeMenu: () => void, matchingString: string) => void;
18
+ onSelectOption: (
19
+ option: TOption,
20
+ textNodeContainingQuery: TextNode | null,
21
+ closeMenu: () => void,
22
+ matchingString: string,
23
+ ) => void;
20
24
  options: TOption[];
21
25
  nodeKey: NodeKey | null;
22
26
  menuRenderFn?: MenuRenderFn<TOption>;
@@ -52,12 +56,15 @@ export function LexicalNodeMenuPlugin<TOption extends MenuOption>(
52
56
  }
53
57
  }, [onClose, resolution]);
54
58
 
55
- const openNodeMenu = useCallback((res: MenuResolution) => {
56
- setResolution(res);
57
- if (onOpen != null && resolution === null) {
58
- onOpen(res);
59
- }
60
- }, [onOpen, resolution]);
59
+ const openNodeMenu = useCallback(
60
+ (res: MenuResolution) => {
61
+ setResolution(res);
62
+ if (onOpen != null && resolution === null) {
63
+ onOpen(res);
64
+ }
65
+ },
66
+ [onOpen, resolution],
67
+ );
61
68
 
62
69
  const positionOrCloseMenu = useCallback(() => {
63
70
  if (nodeKey) {
@@ -66,8 +73,8 @@ export function LexicalNodeMenuPlugin<TOption extends MenuOption>(
66
73
  const domElement = editor.getElementByKey(nodeKey);
67
74
  if (node != null && domElement != null) {
68
75
  if (resolution == null) {
69
- startTransition(
70
- () => openNodeMenu({ getRect: () => domElement.getBoundingClientRect() }),
76
+ startTransition(() =>
77
+ openNodeMenu({ getRect: () => domElement.getBoundingClientRect() }),
71
78
  );
72
79
  }
73
80
  }
@@ -94,14 +101,16 @@ export function LexicalNodeMenuPlugin<TOption extends MenuOption>(
94
101
  if (anchorElementRef.current === null || resolution === null || editor === null) {
95
102
  return null;
96
103
  }
97
- return <LexicalMenu
98
- close={closeNodeMenu}
99
- resolution={resolution}
100
- editor={editor}
101
- anchorElementRef={anchorElementRef}
102
- options={options}
103
- menuRenderFn={menuRenderFn}
104
- onSelectOption={onSelectOption}
105
- commandPriority={commandPriority}
106
- />;
104
+ return (
105
+ <LexicalMenu
106
+ close={closeNodeMenu}
107
+ resolution={resolution}
108
+ editor={editor}
109
+ anchorElementRef={anchorElementRef}
110
+ options={options}
111
+ menuRenderFn={menuRenderFn}
112
+ onSelectOption={onSelectOption}
113
+ commandPriority={commandPriority}
114
+ />
115
+ );
107
116
  }
@@ -20,22 +20,18 @@ export function OnChangePlugin(props: Props) {
20
20
 
21
21
  useLayoutEffect(() => {
22
22
  if (onChange) {
23
- return editor.registerUpdateListener(({
24
- editorState,
25
- dirtyElements,
26
- dirtyLeaves,
27
- prevEditorState,
28
- tags,
29
- }) => {
30
- if (
31
- ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0 ||
32
- ignoreHistoryMergeTagChange && tags.has(HISTORY_MERGE_TAG) ||
23
+ return editor.registerUpdateListener(
24
+ ({ editorState, dirtyElements, dirtyLeaves, prevEditorState, tags }) => {
25
+ if (
26
+ (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0) ||
27
+ (ignoreHistoryMergeTagChange && tags.has(HISTORY_MERGE_TAG)) ||
33
28
  prevEditorState.isEmpty()
34
- ) {
35
- return;
36
- }
37
- onChange(editorState, editor, tags);
38
- });
29
+ ) {
30
+ return;
31
+ }
32
+ onChange(editorState, editor, tags);
33
+ },
34
+ );
39
35
  }
40
36
  }, [editor, ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange]);
41
37
 
@@ -9,11 +9,10 @@ import type { OctaneNode } from 'octane';
9
9
 
10
10
  // Octane analog of @lexical/react's ErrorBoundaryType (a component taking the
11
11
  // decorator subtree plus an onError callback).
12
- type ErrorBoundaryType =
13
- (props: {
14
- children: OctaneNode;
15
- onError: (error: Error) => void;
16
- }) => OctaneNode;
12
+ type ErrorBoundaryType = (props: {
13
+ children: OctaneNode;
14
+ onError: (error: Error) => void;
15
+ }) => OctaneNode;
17
16
 
18
17
  type Props = {
19
18
  contentEditable: OctaneNode;
@@ -11,11 +11,10 @@ import type { OctaneNode } from 'octane';
11
11
 
12
12
  // Octane analog of @lexical/react's ErrorBoundaryType (a component taking the
13
13
  // decorator subtree plus an onError callback).
14
- type ErrorBoundaryType =
15
- (props: {
16
- children: OctaneNode;
17
- onError: (error: Error) => void;
18
- }) => OctaneNode;
14
+ type ErrorBoundaryType = (props: {
15
+ children: OctaneNode;
16
+ onError: (error: Error) => void;
17
+ }) => OctaneNode;
19
18
 
20
19
  type Props = {
21
20
  contentEditable: OctaneNode;
@@ -3,10 +3,9 @@ import { selectionAlwaysOnDisplay } from '@lexical/utils';
3
3
  import { useLexicalComposerContext } from './LexicalComposerContext';
4
4
  import { useEffect } from 'octane';
5
5
 
6
- type Props =
7
- Readonly<{
8
- onReposition?: (node: readonly HTMLElement[]) => void;
9
- }>;
6
+ type Props = Readonly<{
7
+ onReposition?: (node: readonly HTMLElement[]) => void;
8
+ }>;
10
9
 
11
10
  export function SelectionAlwaysOnDisplay(props: Props) {
12
11
  const [editor] = useLexicalComposerContext();
@@ -10,10 +10,10 @@ export { registerTabIndentation } from '@lexical/extension';
10
10
  type Props = {
11
11
  maxIndent?: number;
12
12
  /**
13
- * By default, indents are set on all elements for which
14
- * {@link ElementNode.canIndent} returns true. This option allows you to set
15
- * indents for specific nodes without overriding the method for others.
16
- */
13
+ * By default, indents are set on all elements for which
14
+ * {@link ElementNode.canIndent} returns true. This option allows you to set
15
+ * indents for specific nodes without overriding the method for others.
16
+ */
17
17
  $canIndent?: CanIndentPredicate;
18
18
  };
19
19
 
@@ -22,11 +22,10 @@ export function TabIndentationPlugin(props: Props) {
22
22
  const maxIndent = props.maxIndent;
23
23
  const canIndent = props.$canIndent;
24
24
 
25
- useEffect(() => registerTabIndentation(editor, maxIndent, canIndent), [
26
- editor,
27
- maxIndent,
28
- canIndent,
29
- ]);
25
+ useEffect(
26
+ () => registerTabIndentation(editor, maxIndent, canIndent),
27
+ [editor, maxIndent, canIndent],
28
+ );
30
29
 
31
30
  return null;
32
31
  }
@@ -46,7 +46,7 @@ function $insertHeadingIntoTableOfContents(
46
46
  if (key === prevHeading.getKey() && key !== newHeading.getKey()) {
47
47
  if (
48
48
  i + 1 < currentTableOfContents.length &&
49
- currentTableOfContents[i + 1][0] === newHeading.__key
49
+ currentTableOfContents[i + 1][0] === newHeading.__key
50
50
  ) {
51
51
  return currentTableOfContents;
52
52
  }
@@ -127,11 +127,7 @@ export function TableOfContentsPlugin(props: Props) {
127
127
  const updateCurrentTableOfContents = (node: ElementNode) => {
128
128
  for (const child of node.getChildren()) {
129
129
  if ($isHeadingNode(child)) {
130
- currentTableOfContents.push([
131
- child.getKey(),
132
- child.getTextContent(),
133
- child.getTag(),
134
- ]);
130
+ currentTableOfContents.push([child.getKey(), child.getTextContent(), child.getTag()]);
135
131
  } else if ($isElementNode(child)) {
136
132
  updateCurrentTableOfContents(child);
137
133
  }
@@ -142,92 +138,97 @@ export function TableOfContentsPlugin(props: Props) {
142
138
  setTableOfContents(currentTableOfContents);
143
139
  });
144
140
 
145
- const removeRootUpdateListener = editor.registerUpdateListener(({
146
- editorState,
147
- dirtyElements,
148
- }) => {
149
- editorState.read(() => {
150
- const updateChildHeadings = (node: ElementNode) => {
151
- for (const child of node.getChildren()) {
152
- if ($isHeadingNode(child)) {
153
- const prevHeading = $getPreviousHeading(child);
154
- currentTableOfContents = $updateHeadingPosition(
155
- prevHeading,
156
- child,
157
- currentTableOfContents,
158
- );
159
- setTableOfContents(currentTableOfContents);
160
- } else if ($isElementNode(child)) {
161
- updateChildHeadings(child);
141
+ const removeRootUpdateListener = editor.registerUpdateListener(
142
+ ({ editorState, dirtyElements }) => {
143
+ editorState.read(() => {
144
+ const updateChildHeadings = (node: ElementNode) => {
145
+ for (const child of node.getChildren()) {
146
+ if ($isHeadingNode(child)) {
147
+ const prevHeading = $getPreviousHeading(child);
148
+ currentTableOfContents = $updateHeadingPosition(
149
+ prevHeading,
150
+ child,
151
+ currentTableOfContents,
152
+ );
153
+ setTableOfContents(currentTableOfContents);
154
+ } else if ($isElementNode(child)) {
155
+ updateChildHeadings(child);
156
+ }
162
157
  }
163
- }
164
- };
158
+ };
165
159
 
166
- $getRoot().getChildren().forEach((node) => {
167
- if ($isElementNode(node) && dirtyElements.get(node.__key)) {
168
- updateChildHeadings(node);
169
- }
160
+ $getRoot()
161
+ .getChildren()
162
+ .forEach((node) => {
163
+ if ($isElementNode(node) && dirtyElements.get(node.__key)) {
164
+ updateChildHeadings(node);
165
+ }
166
+ });
170
167
  });
171
- });
172
- });
173
-
174
- const removeHeaderMutationListener = editor.registerMutationListener(HeadingNode, (
175
- mutatedNodes,
176
- ) => {
177
- editor.read('latest', () => {
178
- for (const [nodeKey, mutation] of mutatedNodes) {
179
- if (mutation === 'created') {
180
- const newHeading = $getNodeByKey(nodeKey);
181
- if ($isHeadingNode(newHeading)) {
182
- const prevHeading = $getPreviousHeading(newHeading);
183
- currentTableOfContents = $insertHeadingIntoTableOfContents(
184
- prevHeading,
185
- newHeading,
186
- currentTableOfContents,
187
- );
188
- }
189
- } else if (mutation === 'destroyed') {
190
- currentTableOfContents = $deleteHeadingFromTableOfContents(
191
- nodeKey,
192
- currentTableOfContents,
193
- );
194
- } else if (mutation === 'updated') {
195
- const newHeading = $getNodeByKey(nodeKey);
196
- if ($isHeadingNode(newHeading)) {
197
- const prevHeading = $getPreviousHeading(newHeading);
198
- currentTableOfContents = $updateHeadingPosition(
199
- prevHeading,
200
- newHeading,
168
+ },
169
+ );
170
+
171
+ const removeHeaderMutationListener = editor.registerMutationListener(
172
+ HeadingNode,
173
+ (mutatedNodes) => {
174
+ editor.read('latest', () => {
175
+ for (const [nodeKey, mutation] of mutatedNodes) {
176
+ if (mutation === 'created') {
177
+ const newHeading = $getNodeByKey(nodeKey);
178
+ if ($isHeadingNode(newHeading)) {
179
+ const prevHeading = $getPreviousHeading(newHeading);
180
+ currentTableOfContents = $insertHeadingIntoTableOfContents(
181
+ prevHeading,
182
+ newHeading,
183
+ currentTableOfContents,
184
+ );
185
+ }
186
+ } else if (mutation === 'destroyed') {
187
+ currentTableOfContents = $deleteHeadingFromTableOfContents(
188
+ nodeKey,
201
189
  currentTableOfContents,
202
190
  );
203
- }
204
- }
205
- }
206
- setTableOfContents(currentTableOfContents);
207
- });
208
- }, { skipInitialization: true });
209
-
210
- const removeTextNodeMutationListener = editor.registerMutationListener(TextNode, (
211
- mutatedNodes,
212
- ) => {
213
- editor.read('latest', () => {
214
- for (const [nodeKey, mutation] of mutatedNodes) {
215
- if (mutation === 'updated') {
216
- const currNode = $getNodeByKey(nodeKey);
217
- if (currNode !== null) {
218
- const parentNode = currNode.getParentOrThrow();
219
- if ($isHeadingNode(parentNode)) {
220
- currentTableOfContents = $updateHeadingInTableOfContents(
221
- parentNode,
191
+ } else if (mutation === 'updated') {
192
+ const newHeading = $getNodeByKey(nodeKey);
193
+ if ($isHeadingNode(newHeading)) {
194
+ const prevHeading = $getPreviousHeading(newHeading);
195
+ currentTableOfContents = $updateHeadingPosition(
196
+ prevHeading,
197
+ newHeading,
222
198
  currentTableOfContents,
223
199
  );
224
- setTableOfContents(currentTableOfContents);
225
200
  }
226
201
  }
227
202
  }
228
- }
229
- });
230
- }, { skipInitialization: true });
203
+ setTableOfContents(currentTableOfContents);
204
+ });
205
+ },
206
+ { skipInitialization: true },
207
+ );
208
+
209
+ const removeTextNodeMutationListener = editor.registerMutationListener(
210
+ TextNode,
211
+ (mutatedNodes) => {
212
+ editor.read('latest', () => {
213
+ for (const [nodeKey, mutation] of mutatedNodes) {
214
+ if (mutation === 'updated') {
215
+ const currNode = $getNodeByKey(nodeKey);
216
+ if (currNode !== null) {
217
+ const parentNode = currNode.getParentOrThrow();
218
+ if ($isHeadingNode(parentNode)) {
219
+ currentTableOfContents = $updateHeadingInTableOfContents(
220
+ parentNode,
221
+ currentTableOfContents,
222
+ );
223
+ setTableOfContents(currentTableOfContents);
224
+ }
225
+ }
226
+ }
227
+ }
228
+ });
229
+ },
230
+ { skipInitialization: true },
231
+ );
231
232
 
232
233
  return () => {
233
234
  removeHeaderMutationListener();
@@ -17,46 +17,43 @@ import { useEffect, useState } from 'octane';
17
17
  */
18
18
  export interface TablePluginProps {
19
19
  /**
20
- * When `false` (default `true`), merged cell support (colspan and rowspan)
21
- * will be disabled and all tables will be forced into a regular grid with
22
- * 1x1 table cells.
23
- */
20
+ * When `false` (default `true`), merged cell support (colspan and rowspan)
21
+ * will be disabled and all tables will be forced into a regular grid with
22
+ * 1x1 table cells.
23
+ */
24
24
  hasCellMerge?: boolean;
25
25
  /**
26
- * When `false` (default `true`), the background color of TableCellNode will
27
- * always be removed.
28
- */
26
+ * When `false` (default `true`), the background color of TableCellNode will
27
+ * always be removed.
28
+ */
29
29
  hasCellBackgroundColor?: boolean;
30
30
  /**
31
- * When `true` (default `true`), the tab key can be used to navigate table
32
- * cells.
33
- */
31
+ * When `true` (default `true`), the tab key can be used to navigate table
32
+ * cells.
33
+ */
34
34
  hasTabHandler?: boolean;
35
35
  /**
36
- * When `true` (default `false`), tables will be wrapped in a `<div>` to
37
- * enable horizontal scrolling.
38
- */
36
+ * When `true` (default `false`), tables will be wrapped in a `<div>` to
37
+ * enable horizontal scrolling.
38
+ */
39
39
  hasHorizontalScroll?: boolean;
40
40
  /**
41
- * When `true` (default `false`), nested tables will be allowed.
42
- *
43
- * @experimental Nested tables are not officially supported.
44
- */
41
+ * When `true` (default `false`), nested tables will be allowed.
42
+ *
43
+ * @experimental Nested tables are not officially supported.
44
+ */
45
45
  hasNestedTables?: boolean;
46
46
  }
47
47
 
48
48
  export function TablePlugin(props: TablePluginProps) {
49
49
  const [editor] = useLexicalComposerContext();
50
- const hasCellMerge =
51
- props.hasCellMerge === undefined ? true : props.hasCellMerge;
50
+ const hasCellMerge = props.hasCellMerge === undefined ? true : props.hasCellMerge;
52
51
  const hasCellBackgroundColor =
53
52
  props.hasCellBackgroundColor === undefined ? true : props.hasCellBackgroundColor;
54
- const hasTabHandler =
55
- props.hasTabHandler === undefined ? true : props.hasTabHandler;
53
+ const hasTabHandler = props.hasTabHandler === undefined ? true : props.hasTabHandler;
56
54
  const hasHorizontalScroll =
57
55
  props.hasHorizontalScroll === undefined ? false : props.hasHorizontalScroll;
58
- const hasNestedTables =
59
- props.hasNestedTables === undefined ? false : props.hasNestedTables;
56
+ const hasNestedTables = props.hasNestedTables === undefined ? false : props.hasNestedTables;
60
57
 
61
58
  useEffect(() => {
62
59
  const hadHorizontalScroll = $isScrollableTablesActive(editor);
@@ -72,10 +69,10 @@ export function TablePlugin(props: TablePluginProps) {
72
69
  hasNestedTablesSignal.value = hasNestedTables;
73
70
  }
74
71
 
75
- useEffect(() => registerTablePlugin(editor, { hasNestedTables: hasNestedTablesSignal }), [
76
- editor,
77
- hasNestedTablesSignal,
78
- ]);
72
+ useEffect(
73
+ () => registerTablePlugin(editor, { hasNestedTables: hasNestedTablesSignal }),
74
+ [editor, hasNestedTablesSignal],
75
+ );
79
76
 
80
77
  useEffect(() => registerTableSelectionObserver(editor, hasTabHandler), [editor, hasTabHandler]);
81
78
 
@@ -18,15 +18,24 @@ import type { MenuOption, MenuRenderFn, MenuResolution, TriggerFn } from './shar
18
18
  export { MenuOption } from './LexicalMenuOption';
19
19
  export type { MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn } from './shared/menuShared';
20
20
  export { useDynamicPositioning } from './shared/useDynamicPositioning';
21
- export { getScrollParent, PUNCTUATION, SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND, useBasicTypeaheadTriggerMatch } from './LexicalTypeaheadMenuPluginUtils';
21
+ export {
22
+ getScrollParent,
23
+ PUNCTUATION,
24
+ SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND,
25
+ useBasicTypeaheadTriggerMatch,
26
+ } from './LexicalTypeaheadMenuPluginUtils';
22
27
 
23
28
  /**
24
29
  * Props for the {@link LexicalTypeaheadMenuPlugin} component.
25
30
  */
26
31
  export type TypeaheadMenuPluginProps<TOption extends MenuOption> = {
27
32
  onQueryChange: (matchingString: string | null) => void;
28
- onSelectOption: (option: TOption, textNodeContainingQuery: | TextNode
29
- | null, closeMenu: () => void, matchingString: string) => void;
33
+ onSelectOption: (
34
+ option: TOption,
35
+ textNodeContainingQuery: TextNode | null,
36
+ closeMenu: () => void,
37
+ matchingString: string,
38
+ ) => void;
30
39
  options: TOption[];
31
40
  triggerFn: TriggerFn;
32
41
  menuRenderFn?: MenuRenderFn<TOption>;
@@ -77,12 +86,15 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>(
77
86
  }
78
87
  }, [onClose, resolution]);
79
88
 
80
- const openTypeahead = useCallback((res: MenuResolution) => {
81
- setResolution(res);
82
- if (onOpen != null && resolution === null) {
83
- onOpen(res);
84
- }
85
- }, [onOpen, resolution]);
89
+ const openTypeahead = useCallback(
90
+ (res: MenuResolution) => {
91
+ setResolution(res);
92
+ if (onOpen != null && resolution === null) {
93
+ onOpen(res);
94
+ }
95
+ },
96
+ [onOpen, resolution],
97
+ );
86
98
 
87
99
  useEffect(() => {
88
100
  const updateListener = () => {
@@ -101,8 +113,10 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>(
101
113
  const selection = $getSelection();
102
114
  const text = getQueryTextForSearch(editor);
103
115
  if (
104
- !$isRangeSelection(selection) || !selection.isCollapsed() || text === null ||
105
- range === null
116
+ !$isRangeSelection(selection) ||
117
+ !selection.isCollapsed() ||
118
+ text === null ||
119
+ range === null
106
120
  ) {
107
121
  closeUnlessComposing();
108
122
  return;
@@ -111,7 +125,7 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>(
111
125
  onQueryChange(match ? match.matchingString : null);
112
126
  if (
113
127
  match !== null &&
114
- (ignoreEntityBoundary || !isSelectionOnEntityBoundary(editor, match.leadOffset))
128
+ (ignoreEntityBoundary || !isSelectionOnEntityBoundary(editor, match.leadOffset))
115
129
  ) {
116
130
  const isRangePositioned = tryToPositionRange(
117
131
  match.leadOffset,
@@ -120,8 +134,8 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>(
120
134
  editor.getRootElement(),
121
135
  );
122
136
  if (isRangePositioned !== null) {
123
- startTransition(
124
- () => openTypeahead({ getRect: () => range.getBoundingClientRect(), match }),
137
+ startTransition(() =>
138
+ openTypeahead({ getRect: () => range.getBoundingClientRect(), match }),
125
139
  );
126
140
  return;
127
141
  }
@@ -141,27 +155,30 @@ export function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>(
141
155
  ]);
142
156
 
143
157
  useEffect(
144
- () => editor.registerEditableListener((isEditable) => {
145
- if (!isEditable) {
146
- closeTypeahead();
147
- }
148
- }),
158
+ () =>
159
+ editor.registerEditableListener((isEditable) => {
160
+ if (!isEditable) {
161
+ closeTypeahead();
162
+ }
163
+ }),
149
164
  [editor, closeTypeahead],
150
165
  );
151
166
 
152
167
  if (resolution === null || editor === null || anchorElementRef.current === null) {
153
168
  return null;
154
169
  }
155
- return <LexicalMenu
156
- close={closeTypeahead}
157
- resolution={resolution}
158
- editor={editor}
159
- anchorElementRef={anchorElementRef}
160
- options={options}
161
- menuRenderFn={menuRenderFn}
162
- shouldSplitNodeWithQuery={true}
163
- onSelectOption={onSelectOption}
164
- commandPriority={commandPriority}
165
- preselectFirstItem={preselectFirstItem}
166
- />;
170
+ return (
171
+ <LexicalMenu
172
+ close={closeTypeahead}
173
+ resolution={resolution}
174
+ editor={editor}
175
+ anchorElementRef={anchorElementRef}
176
+ options={options}
177
+ menuRenderFn={menuRenderFn}
178
+ shouldSplitNodeWithQuery={true}
179
+ onSelectOption={onSelectOption}
180
+ commandPriority={commandPriority}
181
+ preselectFirstItem={preselectFirstItem}
182
+ />
183
+ );
167
184
  }