@lexical/react 0.9.2 → 0.11.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 (49) hide show
  1. package/LexicalAutoEmbedPlugin.d.ts +2 -2
  2. package/LexicalAutoEmbedPlugin.dev.js +4 -4
  3. package/LexicalAutoEmbedPlugin.js.flow +2 -2
  4. package/LexicalAutoEmbedPlugin.prod.js +2 -2
  5. package/LexicalClickableLinkPlugin.d.ts +10 -0
  6. package/LexicalClickableLinkPlugin.dev.js +115 -0
  7. package/LexicalClickableLinkPlugin.js +9 -0
  8. package/LexicalClickableLinkPlugin.js.flow +12 -0
  9. package/LexicalClickableLinkPlugin.prod.js +9 -0
  10. package/LexicalCollaborationPlugin.d.ts +2 -1
  11. package/LexicalCollaborationPlugin.dev.js +11 -10
  12. package/LexicalCollaborationPlugin.js.flow +13 -3
  13. package/LexicalCollaborationPlugin.prod.js +9 -9
  14. package/LexicalContentEditable.d.ts +1 -1
  15. package/LexicalContentEditable.dev.js +21 -10
  16. package/LexicalContentEditable.prod.js +3 -3
  17. package/LexicalContextMenuPlugin.d.ts +29 -0
  18. package/LexicalContextMenuPlugin.dev.js +508 -0
  19. package/LexicalContextMenuPlugin.js +9 -0
  20. package/LexicalContextMenuPlugin.prod.js +21 -0
  21. package/LexicalDecoratorBlockNode.d.ts +1 -0
  22. package/LexicalDecoratorBlockNode.dev.js +4 -0
  23. package/LexicalDecoratorBlockNode.prod.js +1 -1
  24. package/LexicalNodeEventPlugin.d.ts +1 -1
  25. package/LexicalNodeEventPlugin.dev.js +26 -33
  26. package/LexicalNodeEventPlugin.prod.js +2 -2
  27. package/LexicalNodeMenuPlugin.d.ts +22 -0
  28. package/LexicalNodeMenuPlugin.dev.js +521 -0
  29. package/LexicalNodeMenuPlugin.js +9 -0
  30. package/LexicalNodeMenuPlugin.js.flow +64 -0
  31. package/LexicalNodeMenuPlugin.prod.js +21 -0
  32. package/LexicalTabIndentationPlugin.d.ts +2 -0
  33. package/LexicalTabIndentationPlugin.dev.js +69 -10
  34. package/LexicalTabIndentationPlugin.js.flow +6 -0
  35. package/LexicalTabIndentationPlugin.prod.js +3 -1
  36. package/LexicalTablePlugin.d.ts +4 -1
  37. package/LexicalTablePlugin.dev.js +88 -2
  38. package/LexicalTablePlugin.js.flow +5 -1
  39. package/LexicalTablePlugin.prod.js +6 -4
  40. package/LexicalTreeView.d.ts +2 -1
  41. package/LexicalTreeView.dev.js +54 -9
  42. package/LexicalTreeView.prod.js +18 -17
  43. package/LexicalTypeaheadMenuPlugin.d.ts +10 -40
  44. package/LexicalTypeaheadMenuPlugin.dev.js +237 -210
  45. package/LexicalTypeaheadMenuPlugin.js.flow +7 -26
  46. package/LexicalTypeaheadMenuPlugin.prod.js +20 -20
  47. package/package.json +19 -19
  48. package/shared/LexicalMenu.d.ts +49 -0
  49. package/shared/useYjsCollaboration.d.ts +2 -2
@@ -7,6 +7,7 @@
7
7
  'use strict';
8
8
 
9
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var utils = require('@lexical/utils');
10
11
  var lexical = require('lexical');
11
12
  var react = require('react');
12
13
 
@@ -17,6 +18,72 @@ var react = require('react');
17
18
  * LICENSE file in the root directory of this source tree.
18
19
  *
19
20
  */
21
+
22
+ function $filter(nodes, filterFn) {
23
+ const result = [];
24
+
25
+ for (let i = 0; i < nodes.length; i++) {
26
+ const node = filterFn(nodes[i]);
27
+
28
+ if (node !== null) {
29
+ result.push(node);
30
+ }
31
+ }
32
+
33
+ return result;
34
+ }
35
+
36
+ function indentOverTab(selection) {
37
+ // const handled = new Set();
38
+ const nodes = selection.getNodes();
39
+ const canIndentBlockNodes = $filter(nodes, node => {
40
+ if (lexical.$isBlockElementNode(node) && node.canIndent()) {
41
+ return node;
42
+ }
43
+
44
+ return null;
45
+ }); // 1. If selection spans across canIndent block nodes: indent
46
+
47
+ if (canIndentBlockNodes.length > 0) {
48
+ return true;
49
+ } // 2. If first (anchor/focus) is at block start: indent
50
+
51
+
52
+ const anchor = selection.anchor;
53
+ const focus = selection.focus;
54
+ const first = focus.isBefore(anchor) ? focus : anchor;
55
+ const firstNode = first.getNode();
56
+ const firstBlock = utils.$getNearestBlockElementAncestorOrThrow(firstNode);
57
+
58
+ if (firstBlock.canIndent()) {
59
+ const firstBlockKey = firstBlock.getKey();
60
+ let selectionAtStart = lexical.$createRangeSelection();
61
+ selectionAtStart.anchor.set(firstBlockKey, 0, 'element');
62
+ selectionAtStart.focus.set(firstBlockKey, 0, 'element');
63
+ selectionAtStart = lexical.$normalizeSelection__EXPERIMENTAL(selectionAtStart);
64
+
65
+ if (selectionAtStart.anchor.is(first)) {
66
+ return true;
67
+ }
68
+ } // 3. Else: tab
69
+
70
+
71
+ return false;
72
+ }
73
+
74
+ function registerTabIndentation(editor) {
75
+ return editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
76
+ const selection = lexical.$getSelection();
77
+
78
+ if (!lexical.$isRangeSelection(selection)) {
79
+ return false;
80
+ }
81
+
82
+ event.preventDefault();
83
+ const command = indentOverTab(selection) ? event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND : lexical.INSERT_TAB_COMMAND;
84
+ return editor.dispatchCommand(command, undefined);
85
+ }, lexical.COMMAND_PRIORITY_EDITOR);
86
+ }
20
87
  /**
21
88
  * This plugin adds the ability to indent content using the tab key. Generally, we don't
22
89
  * recommend using this plugin as it could negatively affect acessibility for keyboard
@@ -26,18 +93,10 @@ var react = require('react');
26
93
  function TabIndentationPlugin() {
27
94
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
28
95
  react.useEffect(() => {
29
- return editor.registerCommand(lexical.KEY_TAB_COMMAND, event => {
30
- const selection = lexical.$getSelection();
31
-
32
- if (!lexical.$isRangeSelection(selection)) {
33
- return false;
34
- }
35
-
36
- event.preventDefault();
37
- return editor.dispatchCommand(event.shiftKey ? lexical.OUTDENT_CONTENT_COMMAND : lexical.INDENT_CONTENT_COMMAND, undefined);
38
- }, lexical.COMMAND_PRIORITY_EDITOR);
96
+ return registerTabIndentation(editor);
39
97
  });
40
98
  return null;
41
99
  }
42
100
 
43
101
  exports.TabIndentationPlugin = TabIndentationPlugin;
102
+ exports.registerTabIndentation = registerTabIndentation;
@@ -7,4 +7,10 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
+ import type {LexicalEditor} from 'lexical';
11
+
12
+ declare export function registerTabIndentation(
13
+ editor: LexicalEditor,
14
+ ): () => void;
15
+
10
16
  declare export function TabIndentationPlugin(): null;
@@ -4,4 +4,6 @@
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
- 'use strict';var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),e=require("react");exports.TabIndentationPlugin=function(){let [b]=a.useLexicalComposerContext();e.useEffect(()=>b.registerCommand(d.KEY_TAB_COMMAND,c=>{let f=d.$getSelection();if(!d.$isRangeSelection(f))return!1;c.preventDefault();return b.dispatchCommand(c.shiftKey?d.OUTDENT_CONTENT_COMMAND:d.INDENT_CONTENT_COMMAND,void 0)},d.COMMAND_PRIORITY_EDITOR));return null}
7
+ 'use strict';var d=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/utils"),h=require("lexical"),k=require("react");function l(b,a){let c=[];for(let e=0;e<b.length;e++){let f=a(b[e]);null!==f&&c.push(f)}return c}
8
+ function m(b){var a=b.getNodes();if(0<l(a,c=>h.$isBlockElementNode(c)&&c.canIndent()?c:null).length)return!0;a=b.anchor;b=b.focus;b=b.isBefore(a)?b:a;a=b.getNode();a=g.$getNearestBlockElementAncestorOrThrow(a);if(a.canIndent()){a=a.getKey();let c=h.$createRangeSelection();c.anchor.set(a,0,"element");c.focus.set(a,0,"element");c=h.$normalizeSelection__EXPERIMENTAL(c);if(c.anchor.is(b))return!0}return!1}
9
+ function n(b){return b.registerCommand(h.KEY_TAB_COMMAND,a=>{let c=h.$getSelection();if(!h.$isRangeSelection(c))return!1;a.preventDefault();a=m(c)?a.shiftKey?h.OUTDENT_CONTENT_COMMAND:h.INDENT_CONTENT_COMMAND:h.INSERT_TAB_COMMAND;return b.dispatchCommand(a,void 0)},h.COMMAND_PRIORITY_EDITOR)}exports.TabIndentationPlugin=function(){let [b]=d.useLexicalComposerContext();k.useEffect(()=>n(b));return null};exports.registerTabIndentation=n
@@ -6,4 +6,7 @@
6
6
  *
7
7
  */
8
8
  /// <reference types="react" />
9
- export declare function TablePlugin(): JSX.Element | null;
9
+ export declare function TablePlugin({ hasCellMerge, hasCellBackgroundColor, }: {
10
+ hasCellMerge?: boolean;
11
+ hasCellBackgroundColor?: boolean;
12
+ }): JSX.Element | null;
@@ -19,7 +19,21 @@ var react = require('react');
19
19
  * LICENSE file in the root directory of this source tree.
20
20
  *
21
21
  */
22
- function TablePlugin() {
22
+
23
+ function $insertFirst(parent, node) {
24
+ const firstChild = parent.getFirstChild();
25
+
26
+ if (firstChild !== null) {
27
+ firstChild.insertBefore(node);
28
+ } else {
29
+ parent.append(node);
30
+ }
31
+ }
32
+
33
+ function TablePlugin({
34
+ hasCellMerge = true,
35
+ hasCellBackgroundColor = true
36
+ }) {
23
37
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
24
38
  react.useEffect(() => {
25
39
  if (!editor.hasNodes([table.TableNode, table.TableCellNode, table.TableRowNode])) {
@@ -96,7 +110,79 @@ function TablePlugin() {
96
110
  tableSelection.removeListeners();
97
111
  }
98
112
  };
99
- }, [editor]);
113
+ }, [editor]); // Unmerge cells when the feature isn't enabled
114
+
115
+ react.useEffect(() => {
116
+ if (hasCellMerge) {
117
+ return;
118
+ }
119
+
120
+ return editor.registerNodeTransform(table.TableCellNode, node => {
121
+ if (node.getColSpan() > 1 || node.getRowSpan() > 1) {
122
+ // When we have rowSpan we have to map the entire Table to understand where the new Cells
123
+ // fit best; let's analyze all Cells at once to save us from further transform iterations
124
+ const [,, gridNode] = lexical.DEPRECATED_$getNodeTriplet(node);
125
+ const [gridMap] = lexical.DEPRECATED_$computeGridMap(gridNode, node, node); // TODO this function expects Tables to be normalized. Look into this once it exists
126
+
127
+ const rowsCount = gridMap.length;
128
+ const columnsCount = gridMap[0].length;
129
+ let row = gridNode.getFirstChild();
130
+
131
+ if (!lexical.DEPRECATED_$isGridRowNode(row)) {
132
+ throw Error(`Expected TableNode first child to be a RowNode`);
133
+ }
134
+
135
+ const unmerged = [];
136
+
137
+ for (let i = 0; i < rowsCount; i++) {
138
+ if (i !== 0) {
139
+ row = row.getNextSibling();
140
+
141
+ if (!lexical.DEPRECATED_$isGridRowNode(row)) {
142
+ throw Error(`Expected TableNode first child to be a RowNode`);
143
+ }
144
+ }
145
+
146
+ let lastRowCell = null;
147
+
148
+ for (let j = 0; j < columnsCount; j++) {
149
+ const cellMap = gridMap[i][j];
150
+ const cell = cellMap.cell;
151
+
152
+ if (cellMap.startRow === i && cellMap.startColumn === j) {
153
+ lastRowCell = cell;
154
+ unmerged.push(cell);
155
+ } else if (cell.getColSpan() > 1 || cell.getRowSpan() > 1) {
156
+ const newCell = table.$createTableCellNode(cell.__headerState);
157
+
158
+ if (lastRowCell !== null) {
159
+ lastRowCell.insertAfter(newCell);
160
+ } else {
161
+ $insertFirst(row, newCell);
162
+ }
163
+ }
164
+ }
165
+ }
166
+
167
+ for (const cell of unmerged) {
168
+ cell.setColSpan(1);
169
+ cell.setRowSpan(1);
170
+ }
171
+ }
172
+ });
173
+ }, [editor, hasCellMerge]); // Remove cell background color when feature is disabled
174
+
175
+ react.useEffect(() => {
176
+ if (hasCellBackgroundColor) {
177
+ return;
178
+ }
179
+
180
+ return editor.registerNodeTransform(table.TableCellNode, node => {
181
+ if (node.getBackgroundColor() !== null) {
182
+ node.setBackgroundColor(null);
183
+ }
184
+ });
185
+ }, [editor, hasCellBackgroundColor, hasCellMerge]);
100
186
  return null;
101
187
  }
102
188
 
@@ -7,4 +7,8 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- declare export function TablePlugin(): null;
10
+ type Props = $ReadOnly<{
11
+ hasCellMerge?: boolean,
12
+ hasCellBackgroundColor?: boolean,
13
+ }>;
14
+ declare export function TablePlugin(props: Props): null;
@@ -4,7 +4,9 @@
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
- 'use strict';var c=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),l=require("@lexical/utils"),n=require("lexical"),p=require("react");
8
- exports.TablePlugin=function(){let [e]=c.useLexicalComposerContext();p.useEffect(()=>{if(!e.hasNodes([g.TableNode,g.TableCellNode,g.TableRowNode]))throw Error("Minified Lexical error #10; visit https://lexical.dev/docs/error?code=10 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return e.registerCommand(g.INSERT_TABLE_COMMAND,({columns:a,rows:h,includeHeaders:k})=>{a=g.$createTableNodeWithDimensions(Number(h),Number(a),k);l.$insertNodeToNearestRoot(a);
9
- a=a.getFirstDescendant();n.$isTextNode(a)&&a.select();return!0},n.COMMAND_PRIORITY_EDITOR)},[e]);p.useEffect(()=>{let a=new Map,h=b=>{const d=b.getKey(),f=e.getElementByKey(d);f&&!a.has(d)&&(b=g.applyTableHandlers(b,f,e),a.set(d,b))};e.getEditorState().read(()=>{let b=n.$nodesOfType(g.TableNode);for(let d of b)g.$isTableNode(d)&&h(d)});let k=e.registerMutationListener(g.TableNode,b=>{for(const [d,f]of b)"created"===f?e.getEditorState().read(()=>{const m=n.$getNodeByKey(d);g.$isTableNode(m)&&h(m)}):
10
- "destroyed"===f&&(b=a.get(d),void 0!==b&&(b.removeListeners(),a.delete(d)))});return()=>{k();for(let [,b]of a)b.removeListeners()}},[e]);return null}
7
+ 'use strict';var c=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/table"),n=require("@lexical/utils"),v=require("lexical"),w=require("react");
8
+ exports.TablePlugin=function({hasCellMerge:q=!0,hasCellBackgroundColor:t=!0}){let [d]=c.useLexicalComposerContext();w.useEffect(()=>{if(!d.hasNodes([h.TableNode,h.TableCellNode,h.TableRowNode]))throw Error("Minified Lexical error #10; visit https://lexical.dev/docs/error?code=10 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return d.registerCommand(h.INSERT_TABLE_COMMAND,({columns:a,rows:e,includeHeaders:g})=>{a=h.$createTableNodeWithDimensions(Number(e),
9
+ Number(a),g);n.$insertNodeToNearestRoot(a);a=a.getFirstDescendant();v.$isTextNode(a)&&a.select();return!0},v.COMMAND_PRIORITY_EDITOR)},[d]);w.useEffect(()=>{let a=new Map,e=b=>{const f=b.getKey(),l=d.getElementByKey(f);l&&!a.has(f)&&(b=h.applyTableHandlers(b,l,d),a.set(f,b))};d.getEditorState().read(()=>{let b=v.$nodesOfType(h.TableNode);for(let f of b)h.$isTableNode(f)&&e(f)});let g=d.registerMutationListener(h.TableNode,b=>{for(const [f,l]of b)"created"===l?d.getEditorState().read(()=>{const m=
10
+ v.$getNodeByKey(f);h.$isTableNode(m)&&e(m)}):"destroyed"===l&&(b=a.get(f),void 0!==b&&(b.removeListeners(),a.delete(f)))});return()=>{g();for(let [,b]of a)b.removeListeners()}},[d]);w.useEffect(()=>{if(!q)return d.registerNodeTransform(h.TableCellNode,a=>{if(1<a.getColSpan()||1<a.getRowSpan()){var [,,e]=v.DEPRECATED_$getNodeTriplet(a);[a]=v.DEPRECATED_$computeGridMap(e,a,a);let f=a.length,l=a[0].length;e=e.getFirstChild();if(!v.DEPRECATED_$isGridRowNode(e))throw Error("Expected TableNode first child to be a RowNode");
11
+ let m=[];for(let k=0;k<f;k++){if(0!==k&&(e=e.getNextSibling(),!v.DEPRECATED_$isGridRowNode(e)))throw Error("Expected TableNode first child to be a RowNode");let r=null;for(let p=0;p<l;p++){var g=a[k][p],b=g.cell;if(g.startRow===k&&g.startColumn===p)r=b,m.push(b);else if(1<b.getColSpan()||1<b.getRowSpan())if(b=h.$createTableCellNode(b.__headerState),null!==r)r.insertAfter(b);else{g=e;let u=g.getFirstChild();null!==u?u.insertBefore(b):g.append(b)}}}for(let k of m)k.setColSpan(1),k.setRowSpan(1)}})},
12
+ [d,q]);w.useEffect(()=>{if(!t)return d.registerNodeTransform(h.TableCellNode,a=>{null!==a.getBackgroundColor()&&a.setBackgroundColor(null)})},[d,t,q]);return null}
@@ -7,8 +7,9 @@
7
7
  */
8
8
  /// <reference types="react" />
9
9
  import type { LexicalEditor } from 'lexical';
10
- export declare function TreeView({ timeTravelButtonClassName, timeTravelPanelSliderClassName, timeTravelPanelButtonClassName, viewClassName, timeTravelPanelClassName, editor, }: {
10
+ export declare function TreeView({ treeTypeButtonClassName, timeTravelButtonClassName, timeTravelPanelSliderClassName, timeTravelPanelButtonClassName, viewClassName, timeTravelPanelClassName, editor, }: {
11
11
  editor: LexicalEditor;
12
+ treeTypeButtonClassName: string;
12
13
  timeTravelButtonClassName: string;
13
14
  timeTravelPanelButtonClassName: string;
14
15
  timeTravelPanelClassName: string;
@@ -6,6 +6,7 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var html = require('@lexical/html');
9
10
  var link = require('@lexical/link');
10
11
  var mark = require('@lexical/mark');
11
12
  var utils = require('@lexical/utils');
@@ -33,6 +34,7 @@ const SYMBOLS = Object.freeze({
33
34
  selectedLine: '>'
34
35
  });
35
36
  function TreeView({
37
+ treeTypeButtonClassName,
36
38
  timeTravelButtonClassName,
37
39
  timeTravelPanelSliderClassName,
38
40
  timeTravelPanelButtonClassName,
@@ -43,6 +45,7 @@ function TreeView({
43
45
  const [timeStampedEditorStates, setTimeStampedEditorStates] = React.useState([]);
44
46
  const [content, setContent] = React.useState('');
45
47
  const [timeTravelEnabled, setTimeTravelEnabled] = React.useState(false);
48
+ const [showExportDOM, setShowExportDOM] = React.useState(false);
46
49
  const playingIndexRef = React.useRef(0);
47
50
  const treeElementRef = React.useRef(null);
48
51
  const inputRef = React.useRef(null);
@@ -52,20 +55,20 @@ function TreeView({
52
55
  const lastEditorStateRef = React.useRef(null);
53
56
  const commandsLog = useLexicalCommandsLog(editor);
54
57
  const generateTree = React.useCallback(editorState => {
55
- const treeText = generateContent(editor.getEditorState(), editor._config, commandsLog, editor._compositionKey, editor._editable);
58
+ const treeText = generateContent(editor, commandsLog, showExportDOM);
56
59
  setContent(treeText);
57
60
 
58
61
  if (!timeTravelEnabled) {
59
62
  setTimeStampedEditorStates(currentEditorStates => [...currentEditorStates, [Date.now(), editorState]]);
60
63
  }
61
- }, [commandsLog, editor, timeTravelEnabled]);
64
+ }, [commandsLog, editor, timeTravelEnabled, showExportDOM]);
62
65
  React.useEffect(() => {
63
66
  const editorState = editor.getEditorState();
64
67
 
65
- if (!showLimited && editorState._nodeMap.size > 1000) {
66
- setContent(generateContent(editorState, editor._config, commandsLog, editor._compositionKey, editor._editable));
68
+ if (!showLimited && editorState._nodeMap.size < 1000) {
69
+ setContent(generateContent(editor, commandsLog, showExportDOM));
67
70
  }
68
- }, [commandsLog, editor, showLimited]);
71
+ }, [commandsLog, editor, showLimited, showExportDOM]);
69
72
  React.useEffect(() => {
70
73
  return utils.mergeRegister(editor.registerUpdateListener(({
71
74
  editorState
@@ -81,10 +84,10 @@ function TreeView({
81
84
 
82
85
  generateTree(editorState);
83
86
  }), editor.registerEditableListener(() => {
84
- const treeText = generateContent(editor.getEditorState(), editor._config, commandsLog, editor._compositionKey, editor._editable);
87
+ const treeText = generateContent(editor, commandsLog, showExportDOM);
85
88
  setContent(treeText);
86
89
  }));
87
- }, [commandsLog, editor, isLimited, generateTree, showLimited]);
90
+ }, [commandsLog, editor, showExportDOM, isLimited, generateTree, showLimited]);
88
91
  const totalEditorStates = timeStampedEditorStates.length;
89
92
  React.useEffect(() => {
90
93
  if (isPlaying) {
@@ -160,7 +163,11 @@ function TreeView({
160
163
  cursor: 'pointer',
161
164
  padding: 5
162
165
  }
163
- }, "Show full tree")) : null, !timeTravelEnabled && (showLimited || !isLimited) && totalEditorStates > 2 && /*#__PURE__*/React.createElement("button", {
166
+ }, "Show full tree")) : null, !showLimited ? /*#__PURE__*/React.createElement("button", {
167
+ onClick: () => setShowExportDOM(!showExportDOM),
168
+ className: treeTypeButtonClassName,
169
+ type: "button"
170
+ }, showExportDOM ? 'Tree' : 'Export DOM') : null, !timeTravelEnabled && (showLimited || !isLimited) && totalEditorStates > 2 && /*#__PURE__*/React.createElement("button", {
164
171
  onClick: () => {
165
172
  const rootElement = editor.getRootElement();
166
173
 
@@ -275,7 +282,20 @@ function printGridSelection(selection) {
275
282
  return `: grid\n └ { grid: ${selection.gridKey}, anchorCell: ${selection.anchor.key}, focusCell: ${selection.focus.key} }`;
276
283
  }
277
284
 
278
- function generateContent(editorState, editorConfig, commandsLog, compositionKey, editable) {
285
+ function generateContent(editor, commandsLog, exportDOM) {
286
+ const editorState = editor.getEditorState();
287
+ const editorConfig = editor._config;
288
+ const compositionKey = editor._compositionKey;
289
+ const editable = editor._editable;
290
+
291
+ if (exportDOM) {
292
+ let htmlString = '';
293
+ editorState.read(() => {
294
+ htmlString = printPrettyHTML(html.$generateHtmlFromNodes(editor));
295
+ });
296
+ return htmlString;
297
+ }
298
+
279
299
  let res = ' root\n';
280
300
  const selectionString = editorState.read(() => {
281
301
  const selection = lexical.$getSelection();
@@ -464,6 +484,31 @@ function printSelectedCharsLine({
464
484
  return [SYMBOLS.selectedLine, indentionChars.join(' '), [...nodePrintSpaces, ...unselectedChars, ...selectedChars].join('')].join(' ') + '\n';
465
485
  }
466
486
 
487
+ function printPrettyHTML(str) {
488
+ const div = document.createElement('div');
489
+ div.innerHTML = str.trim();
490
+ return prettifyHTML(div, 0).innerHTML;
491
+ }
492
+
493
+ function prettifyHTML(node, level) {
494
+ const indentBefore = new Array(level++ + 1).join(' ');
495
+ const indentAfter = new Array(level - 1).join(' ');
496
+ let textNode;
497
+
498
+ for (let i = 0; i < node.children.length; i++) {
499
+ textNode = document.createTextNode('\n' + indentBefore);
500
+ node.insertBefore(textNode, node.children[i]);
501
+ prettifyHTML(node.children[i], level);
502
+
503
+ if (node.lastElementChild === node.children[i]) {
504
+ textNode = document.createTextNode('\n' + indentAfter);
505
+ node.appendChild(textNode);
506
+ }
507
+ }
508
+
509
+ return node;
510
+ }
511
+
467
512
  function $getSelectionStartEnd(node, selection) {
468
513
  const anchor = selection.anchor;
469
514
  const focus = selection.focus;
@@ -4,20 +4,21 @@
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
- 'use strict';var k=require("@lexical/link"),t=require("@lexical/mark"),u=require("@lexical/utils"),G=require("lexical"),K=require("react");let L=Object.freeze({"\t":"\\t","\n":"\\n"}),M=new RegExp(Object.keys(L).join("|"),"g"),N=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
- function O(a){let [c,d]=K.useState([]);K.useEffect(()=>{let l=new Set;for(let [g]of a._commands)l.add(a.registerCommand(g,b=>{d(e=>{e=[...e];e.push({payload:b,type:g.type?g.type:"UNKNOWN"});10<e.length&&e.shift();return e});return!1},G.COMMAND_PRIORITY_HIGH));return()=>l.forEach(g=>g())},[a]);return K.useMemo(()=>c,[c])}
9
- function R(a){let c="";var d=S(a);c+=`: range ${""!==d?`{ ${d} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;d=a.anchor;a=a.focus;let l=d.offset,g=a.offset;c+=`\n \u251c anchor { key: ${d.key}, offset: ${null===l?"null":l}, type: ${d.type} }`;return c+=`\n \u2514 focus { key: ${a.key}, offset: ${null===g?"null":g}, type: ${a.type} }`}
10
- function T(a,c,d,l,g){let b=" root\n";a=a.read(()=>{const e=G.$getSelection();U(G.$getRoot(),(h,y)=>{const v=`(${h.getKey()})`,r=h.getType()||"",z=h.isSelected(),n=t.$isMarkNode(h)?` id: [ ${h.getIDs().join(", ")} ] `:"";var x=b,E=z?N.selectedLine:" ",A=y.join(" ");if(G.$isTextNode(h)){var m=h.getTextContent();var p=0===m.length?"(empty)":`"${V(m)}"`;m=[S(h),W(h),X(h)].filter(Boolean).join(", ");m=[p,0!==m.length?`{ ${m} }`:null].filter(Boolean).join(" ").trim()}else if(k.$isLinkNode(h)){m=h.getURL();
11
- m=0===m.length?"(empty)":`"${V(m)}"`;p=h.getTarget();null!=p&&(p="target: "+p);var H=Boolean;var q=h.getRel();null!=q&&(q="rel: "+q);let B=h.getTitle();null!=B&&(B="title: "+B);p=[p,q,B].filter(H).join(", ");m=[m,0!==p.length?`{ ${p} }`:null].filter(Boolean).join(" ").trim()}else m="";b=x+`${E} ${A} ${v} ${r} ${n} ${m}\n`;b+=Y({indent:y,isSelected:z,node:h,nodeKeyDisplay:v,selection:e,typeDisplay:r})});return null===e?": null":G.$isRangeSelection(e)?R(e):G.DEPRECATED_$isGridSelection(e)?`: grid\n \u2514 { grid: ${e.gridKey}, anchorCell: ${e.anchor.key}, focusCell: ${e.focus.key} }`:
12
- `: node\n \u2514 [${Array.from(e._nodes).join(", ")}]`});b+="\n selection"+a;b+="\n\n commands:";if(d.length)for(let {type:e,payload:h}of d)b+=`\n \u2514 { type: ${e}, payload: ${h instanceof Event?h.constructor.name:h} }`;else b+="\n \u2514 None dispatched.";b+="\n\n editor:";b+=`\n \u2514 namespace ${c.namespace}`;null!==l&&(b+=`\n \u2514 compositionKey ${l}`);return b+=`\n \u2514 editable ${String(g)}`}
13
- function U(a,c,d=[]){a=a.getChildren();let l=a.length;a.forEach((g,b)=>{c(g,d.concat(b===l-1?N.isLastChild:N.hasNextSibling));G.$isElementNode(g)&&U(g,c,d.concat(b===l-1?N.ancestorIsLastChild:N.ancestorHasNextSibling))})}function V(a){return Object.entries(L).reduce((c,[d,l])=>c.replace(new RegExp(d,"g"),String(l)),a)}
14
- let Z=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],aa=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],ba=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
15
- function W(a){let c=aa.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="detail: "+c);return c}function X(a){let c=ba.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="mode: "+c);return c}function S(a){let c=Z.map(d=>d(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==c&&(c="format: "+c);return c}
16
- function Y({indent:a,isSelected:c,node:d,nodeKeyDisplay:l,selection:g,typeDisplay:b}){if(!G.$isTextNode(d)||!G.$isRangeSelection(g)||!c||G.$isElementNode(d))return"";c=g.anchor;var e=g.focus;if(""===d.getTextContent()||c.getNode()===g.focus.getNode()&&c.offset===e.offset)return"";e=g.anchor;let h=g.focus,y=d.getTextContent(),v=y.length;c=g=-1;if("text"===e.type&&"text"===h.type){let n=e.getNode(),x=h.getNode();n===x&&d===n&&e.offset!==h.offset?[g,c]=e.offset<h.offset?[e.offset,h.offset]:[h.offset,
17
- e.offset]:d===n?[g,c]=n.isBefore(x)?[e.offset,v]:[0,e.offset]:d===x?[g,c]=x.isBefore(n)?[h.offset,v]:[0,h.offset]:[g,c]=[0,v]}d=(y.slice(0,g).match(M)||[]).length;e=(y.slice(g,c).match(M)||[]).length;let [r,z]=[g+d,c+d+e];if(r===z)return"";d=a[a.length-1]===N.hasNextSibling?N.ancestorHasNextSibling:N.ancestorIsLastChild;a=[...a.slice(0,a.length-1),d];d=Array(r+1).fill(" ");g=Array(z-r).fill(N.selectedChar);l=Array(l.length+(b.length+3)).fill(" ");return[N.selectedLine,a.join(" "),[...l,...d,...g].join("")].join(" ")+
18
- "\n"}
19
- exports.TreeView=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:d,viewClassName:l,timeTravelPanelClassName:g,editor:b}){let [e,h]=K.useState([]),[y,v]=K.useState(""),[r,z]=K.useState(!1),n=K.useRef(0),x=K.useRef(null),E=K.useRef(null),[A,m]=K.useState(!1),[p,H]=K.useState(!1),[q,B]=K.useState(!1),I=K.useRef(null),C=O(b),J=K.useCallback(f=>{const w=T(b.getEditorState(),b._config,C,b._compositionKey,b._editable);v(w);r||h(F=>[...F,[Date.now(),f]])},
20
- [C,b,r]);K.useEffect(()=>{let f=b.getEditorState();!q&&1E3<f._nodeMap.size&&v(T(f,b._config,C,b._compositionKey,b._editable))},[C,b,q]);K.useEffect(()=>u.mergeRegister(b.registerUpdateListener(({editorState:f})=>{if(!q&&1E3<f._nodeMap.size&&(I.current=f,H(!0),!q))return;J(f)}),b.registerEditableListener(()=>{let f=T(b.getEditorState(),b._config,C,b._compositionKey,b._editable);v(f)})),[C,b,p,J,q]);let D=e.length;K.useEffect(()=>{if(A){let f,w=()=>{const F=n.current;F===D-1?m(!1):f=setTimeout(()=>
21
- {n.current++;const P=n.current,Q=E.current;null!==Q&&(Q.value=String(P));b.setEditorState(e[P][1]);w()},e[F+1][0]-e[F][0])};w();return()=>{clearTimeout(f)}}},[e,A,b,D]);K.useEffect(()=>{let f=x.current;if(null!==f)return f.__lexicalEditor=b,()=>{f.__lexicalEditor=null}},[b]);return K.createElement("div",{className:l},!q&&p?K.createElement("div",{style:{padding:20}},K.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),K.createElement("button",
22
- {onClick:()=>{B(!0);let f=I.current;null!==f&&(I.current=null,J(f))},style:{background:"transparent",border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,!r&&(q||!p)&&2<D&&K.createElement("button",{onClick:()=>{let f=b.getRootElement();null!==f&&(f.contentEditable="false",n.current=D-1,z(!0))},className:a,type:"button"},"Time Travel"),(q||!p)&&K.createElement("pre",{ref:x},y),r&&(q||!p)&&K.createElement("div",{className:g},K.createElement("button",{className:d,
23
- onClick:()=>{n.current===D-1&&(n.current=1);m(!A)},type:"button"},A?"Pause":"Play"),K.createElement("input",{className:c,ref:E,onChange:f=>{f=Number(f.target.value);let w=e[f];w&&(n.current=f,b.setEditorState(w[1]))},type:"range",min:"1",max:D-1}),K.createElement("button",{className:d,onClick:()=>{var f=b.getRootElement();if(null!==f){f.contentEditable="true";f=e.length-1;b.setEditorState(e[f][1]);let w=E.current;null!==w&&(w.value=String(f));z(!1);m(!1)}},type:"button"},"Exit")))}
7
+ 'use strict';var g=require("@lexical/html"),w=require("@lexical/link"),x=require("@lexical/mark"),I=require("@lexical/utils"),M=require("lexical"),N=require("react");let O=Object.freeze({"\t":"\\t","\n":"\\n"}),P=new RegExp(Object.keys(O).join("|"),"g"),Q=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
+ function R(a){let [b,c]=N.useState([]);N.useEffect(()=>{let l=new Set;for(let [e]of a._commands)l.add(a.registerCommand(e,p=>{c(d=>{d=[...d];d.push({payload:p,type:e.type?e.type:"UNKNOWN"});10<d.length&&d.shift();return d});return!1},M.COMMAND_PRIORITY_HIGH));return()=>l.forEach(e=>e())},[a]);return N.useMemo(()=>b,[b])}
9
+ function U(a){let b="";var c=V(a);b+=`: range ${""!==c?`{ ${c} }`:""} ${""!==a.style?`{ style: ${a.style} } `:""}`;c=a.anchor;a=a.focus;let l=c.offset,e=a.offset;b+=`\n \u251c anchor { key: ${c.key}, offset: ${null===l?"null":l}, type: ${c.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===e?"null":e}, type: ${a.type} }`}
10
+ function W(a,b,c){let l=a.getEditorState(),e=a._config,p=a._compositionKey,d=a._editable;if(c){let m="";l.read(()=>{var k=g.$generateHtmlFromNodes(a);let t=document.createElement("div");t.innerHTML=k.trim();m=X(t,0).innerHTML});return m}let h=" root\n";c=l.read(()=>{const m=M.$getSelection();Y(M.$getRoot(),(k,t)=>{const y=`(${k.getKey()})`,v=k.getType()||"",q=k.isSelected(),J=x.$isMarkNode(k)?` id: [ ${k.getIDs().join(", ")} ] `:"";var A=h,H=q?Q.selectedLine:" ",F=t.join(" ");if(M.$isTextNode(k)){var n=
11
+ k.getTextContent();var u=0===n.length?"(empty)":`"${Z(n)}"`;n=[V(k),aa(k),ba(k)].filter(Boolean).join(", ");n=[u,0!==n.length?`{ ${n} }`:null].filter(Boolean).join(" ").trim()}else if(w.$isLinkNode(k)){n=k.getURL();n=0===n.length?"(empty)":`"${Z(n)}"`;u=k.getTarget();null!=u&&(u="target: "+u);var B=Boolean;var C=k.getRel();null!=C&&(C="rel: "+C);let r=k.getTitle();null!=r&&(r="title: "+r);u=[u,C,r].filter(B).join(", ");n=[n,0!==u.length?`{ ${u} }`:null].filter(Boolean).join(" ").trim()}else n="";
12
+ h=A+`${H} ${F} ${y} ${v} ${J} ${n}\n`;h+=ca({indent:t,isSelected:q,node:k,nodeKeyDisplay:y,selection:m,typeDisplay:v})});return null===m?": null":M.$isRangeSelection(m)?U(m):M.DEPRECATED_$isGridSelection(m)?`: grid\n \u2514 { grid: ${m.gridKey}, anchorCell: ${m.anchor.key}, focusCell: ${m.focus.key} }`:`: node\n \u2514 [${Array.from(m._nodes).join(", ")}]`});h+="\n selection"+c;h+="\n\n commands:";if(b.length)for(let {type:m,payload:k}of b)h+=`\n \u2514 { type: ${m}, payload: ${k instanceof Event?
13
+ k.constructor.name:k} }`;else h+="\n \u2514 None dispatched.";h+="\n\n editor:";h+=`\n \u2514 namespace ${e.namespace}`;null!==p&&(h+=`\n \u2514 compositionKey ${p}`);return h+=`\n \u2514 editable ${String(d)}`}function Y(a,b,c=[]){a=a.getChildren();let l=a.length;a.forEach((e,p)=>{b(e,c.concat(p===l-1?Q.isLastChild:Q.hasNextSibling));M.$isElementNode(e)&&Y(e,b,c.concat(p===l-1?Q.ancestorIsLastChild:Q.ancestorHasNextSibling))})}
14
+ function Z(a){return Object.entries(O).reduce((b,[c,l])=>b.replace(new RegExp(c,"g"),String(l)),a)}
15
+ let da=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("subscript")&&"Subscript",a=>a.hasFormat("superscript")&&"Superscript",a=>a.hasFormat("underline")&&"Underline"],ea=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],fa=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented"];
16
+ function aa(a){let b=ea.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}function ba(a){let b=fa.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function V(a){let b=da.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
17
+ function ca({indent:a,isSelected:b,node:c,nodeKeyDisplay:l,selection:e,typeDisplay:p}){if(!M.$isTextNode(c)||!M.$isRangeSelection(e)||!b||M.$isElementNode(c))return"";b=e.anchor;var d=e.focus;if(""===c.getTextContent()||b.getNode()===e.focus.getNode()&&b.offset===d.offset)return"";d=e.anchor;let h=e.focus,m=c.getTextContent(),k=m.length;b=e=-1;if("text"===d.type&&"text"===h.type){let v=d.getNode(),q=h.getNode();v===q&&c===v&&d.offset!==h.offset?[e,b]=d.offset<h.offset?[d.offset,h.offset]:[h.offset,
18
+ d.offset]:c===v?[e,b]=v.isBefore(q)?[d.offset,k]:[0,d.offset]:c===q?[e,b]=q.isBefore(v)?[h.offset,k]:[0,h.offset]:[e,b]=[0,k]}c=(m.slice(0,e).match(P)||[]).length;d=(m.slice(e,b).match(P)||[]).length;let [t,y]=[e+c,b+c+d];if(t===y)return"";c=a[a.length-1]===Q.hasNextSibling?Q.ancestorHasNextSibling:Q.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(t+1).fill(" ");e=Array(y-t).fill(Q.selectedChar);l=Array(l.length+(p.length+3)).fill(" ");return[Q.selectedLine,a.join(" "),[...l,...c,...e].join("")].join(" ")+
19
+ "\n"}function X(a,b){let c=Array(b++ +1).join(" "),l=Array(b-1).join(" "),e;for(let p=0;p<a.children.length;p++)e=document.createTextNode("\n"+c),a.insertBefore(e,a.children[p]),X(a.children[p],b),a.lastElementChild===a.children[p]&&(e=document.createTextNode("\n"+l),a.appendChild(e));return a}
20
+ exports.TreeView=function({treeTypeButtonClassName:a,timeTravelButtonClassName:b,timeTravelPanelSliderClassName:c,timeTravelPanelButtonClassName:l,viewClassName:e,timeTravelPanelClassName:p,editor:d}){let [h,m]=N.useState([]),[k,t]=N.useState(""),[y,v]=N.useState(!1),[q,J]=N.useState(!1),A=N.useRef(0),H=N.useRef(null),F=N.useRef(null),[n,u]=N.useState(!1),[B,C]=N.useState(!1),[r,ha]=N.useState(!1),K=N.useRef(null),D=R(d),L=N.useCallback(f=>{const z=W(d,D,q);t(z);y||m(G=>[...G,[Date.now(),f]])},[D,
21
+ d,y,q]);N.useEffect(()=>{let f=d.getEditorState();!r&&1E3>f._nodeMap.size&&t(W(d,D,q))},[D,d,r,q]);N.useEffect(()=>I.mergeRegister(d.registerUpdateListener(({editorState:f})=>{if(!r&&1E3<f._nodeMap.size&&(K.current=f,C(!0),!r))return;L(f)}),d.registerEditableListener(()=>{let f=W(d,D,q);t(f)})),[D,d,q,B,L,r]);let E=h.length;N.useEffect(()=>{if(n){let f,z=()=>{const G=A.current;G===E-1?u(!1):f=setTimeout(()=>{A.current++;const S=A.current,T=F.current;null!==T&&(T.value=String(S));d.setEditorState(h[S][1]);
22
+ z()},h[G+1][0]-h[G][0])};z();return()=>{clearTimeout(f)}}},[h,n,d,E]);N.useEffect(()=>{let f=H.current;if(null!==f)return f.__lexicalEditor=d,()=>{f.__lexicalEditor=null}},[d]);return N.createElement("div",{className:e},!r&&B?N.createElement("div",{style:{padding:20}},N.createElement("span",{style:{marginRight:20}},"Detected large EditorState, this can impact debugging performance."),N.createElement("button",{onClick:()=>{ha(!0);let f=K.current;null!==f&&(K.current=null,L(f))},style:{background:"transparent",
23
+ border:"1px solid white",color:"white",cursor:"pointer",padding:5}},"Show full tree")):null,r?null:N.createElement("button",{onClick:()=>J(!q),className:a,type:"button"},q?"Tree":"Export DOM"),!y&&(r||!B)&&2<E&&N.createElement("button",{onClick:()=>{let f=d.getRootElement();null!==f&&(f.contentEditable="false",A.current=E-1,v(!0))},className:b,type:"button"},"Time Travel"),(r||!B)&&N.createElement("pre",{ref:H},k),y&&(r||!B)&&N.createElement("div",{className:p},N.createElement("button",{className:l,
24
+ onClick:()=>{A.current===E-1&&(A.current=1);u(!n)},type:"button"},n?"Pause":"Play"),N.createElement("input",{className:c,ref:F,onChange:f=>{f=Number(f.target.value);let z=h[f];z&&(A.current=f,d.setEditorState(z[1]))},type:"range",min:"1",max:E-1}),N.createElement("button",{className:l,onClick:()=>{var f=d.getRootElement();if(null!==f){f.contentEditable="true";f=h.length-1;d.setEditorState(h[f][1]);let z=F.current;null!==z&&(z.value=String(f));v(!1);u(!1)}},type:"button"},"Exit")))}
@@ -5,60 +5,30 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { LexicalCommand, LexicalEditor, NodeKey, TextNode } from 'lexical';
9
- import { MutableRefObject, ReactPortal } from 'react';
10
- export declare type QueryMatch = {
11
- leadOffset: number;
12
- matchingString: string;
13
- replaceableString: string;
14
- };
15
- export declare type Resolution = {
16
- match: QueryMatch;
17
- getRect: () => DOMRect;
18
- };
8
+ /// <reference types="react" />
9
+ import type { MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn } from './shared/LexicalMenu';
10
+ import { LexicalCommand, TextNode } from 'lexical';
11
+ import { MenuOption } from './shared/LexicalMenu';
19
12
  export declare const PUNCTUATION = "\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'\"~=<>_:;";
20
- export declare class TypeaheadOption {
21
- key: string;
22
- ref?: MutableRefObject<HTMLElement | null>;
23
- constructor(key: string);
24
- setRefElement(element: HTMLElement | null): void;
25
- }
26
- export declare type MenuRenderFn<TOption extends TypeaheadOption> = (anchorElementRef: MutableRefObject<HTMLElement | null>, itemProps: {
27
- selectedIndex: number | null;
28
- selectOptionAndCleanUp: (option: TOption) => void;
29
- setHighlightedIndex: (index: number) => void;
30
- options: Array<TOption>;
31
- }, matchingString: string) => ReactPortal | JSX.Element | null;
32
13
  export declare function getScrollParent(element: HTMLElement, includeHidden: boolean): HTMLElement | HTMLBodyElement;
33
- export declare function useDynamicPositioning(resolution: Resolution | null, targetElement: HTMLElement | null, onReposition: () => void, onVisibilityChange?: (isInView: boolean) => void): void;
14
+ export declare function useDynamicPositioning(resolution: MenuResolution | null, targetElement: HTMLElement | null, onReposition: () => void, onVisibilityChange?: (isInView: boolean) => void): void;
34
15
  export declare const SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND: LexicalCommand<{
35
16
  index: number;
36
- option: TypeaheadOption;
17
+ option: MenuOption;
37
18
  }>;
38
19
  export declare function useBasicTypeaheadTriggerMatch(trigger: string, { minLength, maxLength }: {
39
20
  minLength?: number;
40
21
  maxLength?: number;
41
22
  }): TriggerFn;
42
- export declare type TypeaheadMenuPluginProps<TOption extends TypeaheadOption> = {
23
+ export declare type TypeaheadMenuPluginProps<TOption extends MenuOption> = {
43
24
  onQueryChange: (matchingString: string | null) => void;
44
25
  onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
45
26
  options: Array<TOption>;
46
27
  menuRenderFn: MenuRenderFn<TOption>;
47
28
  triggerFn: TriggerFn;
48
- onOpen?: (resolution: Resolution) => void;
29
+ onOpen?: (resolution: MenuResolution) => void;
49
30
  onClose?: () => void;
50
31
  anchorClassName?: string;
51
32
  };
52
- export declare type TriggerFn = (text: string, editor: LexicalEditor) => QueryMatch | null;
53
- export declare function LexicalTypeaheadMenuPlugin<TOption extends TypeaheadOption>({ options, onQueryChange, onSelectOption, onOpen, onClose, menuRenderFn, triggerFn, anchorClassName, }: TypeaheadMenuPluginProps<TOption>): JSX.Element | null;
54
- declare type NodeMenuPluginProps<TOption extends TypeaheadOption> = {
55
- onSelectOption: (option: TOption, textNodeContainingQuery: TextNode | null, closeMenu: () => void, matchingString: string) => void;
56
- options: Array<TOption>;
57
- nodeKey: NodeKey | null;
58
- onClose?: () => void;
59
- onOpen?: (resolution: Resolution) => void;
60
- menuRenderFn: MenuRenderFn<TOption>;
61
- anchorClassName?: string;
62
- };
63
- export declare function LexicalNodeMenuPlugin<TOption extends TypeaheadOption>({ options, nodeKey, onClose, onOpen, onSelectOption, menuRenderFn, anchorClassName, }: NodeMenuPluginProps<TOption>): JSX.Element | null;
64
- export {};
33
+ export declare function LexicalTypeaheadMenuPlugin<TOption extends MenuOption>({ options, onQueryChange, onSelectOption, onOpen, onClose, menuRenderFn, triggerFn, anchorClassName, }: TypeaheadMenuPluginProps<TOption>): JSX.Element | null;
34
+ export { MenuOption, MenuRenderFn, MenuResolution, MenuTextMatch, TriggerFn };