@lexical/react 0.1.8 → 0.1.11

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 (91) hide show
  1. package/DEPRECATED_useLexical.dev.js +3 -38
  2. package/DEPRECATED_useLexical.prod.js +1 -2
  3. package/DEPRECATED_useLexicalAutoFormatter.dev.js +202 -74
  4. package/DEPRECATED_useLexicalAutoFormatter.prod.js +21 -16
  5. package/DEPRECATED_useLexicalCanShowPlaceholder.prod.js +1 -1
  6. package/DEPRECATED_useLexicalCharacterLimit.dev.js +23 -21
  7. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  8. package/DEPRECATED_useLexicalDecorators.prod.js +1 -1
  9. package/DEPRECATED_useLexicalEditor.dev.js +1 -25
  10. package/DEPRECATED_useLexicalEditor.prod.js +1 -1
  11. package/DEPRECATED_useLexicalEditorEvents.prod.js +1 -1
  12. package/DEPRECATED_useLexicalHistory.dev.js +18 -15
  13. package/DEPRECATED_useLexicalHistory.prod.js +7 -7
  14. package/DEPRECATED_useLexicalList.dev.js +6 -0
  15. package/DEPRECATED_useLexicalList.prod.js +1 -1
  16. package/DEPRECATED_useLexicalPlainText.dev.js +79 -70
  17. package/DEPRECATED_useLexicalPlainText.prod.js +15 -16
  18. package/DEPRECATED_useLexicalRichText.dev.js +124 -250
  19. package/DEPRECATED_useLexicalRichText.prod.js +25 -29
  20. package/LexicalAutoFormatterPlugin.dev.js +202 -74
  21. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  22. package/LexicalAutoFormatterPlugin.prod.js +21 -17
  23. package/LexicalAutoLinkPlugin.js.flow +23 -0
  24. package/LexicalAutoLinkPlugin.prod.js +4 -4
  25. package/LexicalCharacterLimitPlugin.dev.js +23 -21
  26. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  27. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  28. package/LexicalClearEditorPlugin.dev.js +52 -0
  29. package/LexicalClearEditorPlugin.js +9 -0
  30. package/LexicalClearEditorPlugin.js.flow +14 -0
  31. package/LexicalClearEditorPlugin.prod.js +7 -0
  32. package/LexicalCollaborationPlugin.dev.js +31 -36
  33. package/LexicalCollaborationPlugin.js.flow +55 -0
  34. package/LexicalCollaborationPlugin.prod.js +7 -8
  35. package/LexicalComposer.dev.js +8 -6
  36. package/LexicalComposer.js.flow +23 -0
  37. package/LexicalComposer.prod.js +3 -3
  38. package/LexicalComposerContext.js.flow +27 -0
  39. package/LexicalComposerContext.prod.js +1 -1
  40. package/LexicalContentEditable.dev.js +14 -8
  41. package/LexicalContentEditable.js.flow +35 -0
  42. package/LexicalContentEditable.prod.js +3 -3
  43. package/LexicalHashtagPlugin.js.flow +20 -0
  44. package/LexicalHashtagPlugin.prod.js +1 -1
  45. package/LexicalHistoryPlugin.dev.js +18 -15
  46. package/LexicalHistoryPlugin.js.flow +34 -0
  47. package/LexicalHistoryPlugin.prod.js +7 -7
  48. package/LexicalHorizontalRuleNode.dev.js +66 -0
  49. package/LexicalHorizontalRuleNode.js +9 -0
  50. package/LexicalHorizontalRuleNode.js.flow +25 -0
  51. package/LexicalHorizontalRuleNode.prod.js +8 -0
  52. package/LexicalLinkPlugin.dev.js +0 -1
  53. package/LexicalLinkPlugin.js.flow +10 -0
  54. package/LexicalLinkPlugin.prod.js +3 -3
  55. package/LexicalListPlugin.dev.js +6 -0
  56. package/LexicalListPlugin.js.flow +10 -0
  57. package/LexicalListPlugin.prod.js +2 -2
  58. package/LexicalNestedComposer.js.flow +21 -0
  59. package/LexicalNestedComposer.prod.js +1 -1
  60. package/LexicalOnChangePlugin.js.flow +14 -0
  61. package/LexicalOnChangePlugin.prod.js +1 -1
  62. package/LexicalPlainTextPlugin.dev.js +72 -44
  63. package/LexicalPlainTextPlugin.js.flow +18 -0
  64. package/LexicalPlainTextPlugin.prod.js +12 -11
  65. package/LexicalRichTextPlugin.dev.js +115 -222
  66. package/LexicalRichTextPlugin.js.flow +18 -0
  67. package/LexicalRichTextPlugin.prod.js +21 -25
  68. package/LexicalTablePlugin.dev.js +43 -39
  69. package/LexicalTablePlugin.js.flow +10 -0
  70. package/LexicalTablePlugin.prod.js +4 -3
  71. package/LexicalTreeView.dev.js +10 -2
  72. package/LexicalTreeView.js.flow +19 -0
  73. package/LexicalTreeView.prod.js +9 -8
  74. package/README.md +0 -1
  75. package/package.json +5 -4
  76. package/useLexicalDecoratorMap.js.flow +16 -0
  77. package/useLexicalDecoratorMap.prod.js +1 -1
  78. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  79. package/useLexicalIsTextContentEmpty.prod.js +1 -1
  80. package/useLexicalNodeSelection.dev.js +70 -0
  81. package/useLexicalNodeSelection.js +9 -0
  82. package/useLexicalNodeSelection.js.flow +14 -0
  83. package/useLexicalNodeSelection.prod.js +8 -0
  84. package/withSubscriptions.js.flow +13 -0
  85. package/withSubscriptions.prod.js +1 -1
  86. package/LexicalBootstrapPlugin.dev.js +0 -124
  87. package/LexicalBootstrapPlugin.js +0 -9
  88. package/LexicalBootstrapPlugin.prod.js +0 -8
  89. package/LexicalHorizontalRulePlugin.dev.js +0 -51
  90. package/LexicalHorizontalRulePlugin.js +0 -9
  91. package/LexicalHorizontalRulePlugin.prod.js +0 -7
@@ -6,41 +6,11 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var lexical = require('lexical');
10
- var TableCellNode = require('lexical/TableCellNode');
11
- var TableNode = require('lexical/TableNode');
12
- var TableRowNode = require('lexical/TableRowNode');
13
9
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var table = require('@lexical/table');
11
+ var lexical = require('lexical');
14
12
  var react = require('react');
15
13
 
16
- /**
17
- * Copyright (c) Meta Platforms, Inc. and affiliates.
18
- *
19
- * This source code is licensed under the MIT license found in the
20
- * LICENSE file in the root directory of this source tree.
21
- *
22
- *
23
- */
24
- function $createTableNodeWithDimensions(rowCount, columnCount, includeHeader = true) {
25
- const tableNode = TableNode.$createTableNode();
26
-
27
- for (let iRow = 0; iRow < rowCount; iRow++) {
28
- const tableRowNode = TableRowNode.$createTableRowNode();
29
-
30
- for (let iColumn = 0; iColumn < columnCount; iColumn++) {
31
- const tableCellNode = TableCellNode.$createTableCellNode(iRow === 0 && includeHeader);
32
- const paragraphNode = lexical.$createParagraphNode();
33
- paragraphNode.append(lexical.$createTextNode());
34
- tableCellNode.append(paragraphNode);
35
- tableRowNode.append(tableCellNode);
36
- }
37
-
38
- tableNode.append(tableRowNode);
39
- }
40
-
41
- return tableNode;
42
- }
43
-
44
14
  /**
45
15
  * Copyright (c) Meta Platforms, Inc. and affiliates.
46
16
  *
@@ -53,7 +23,7 @@ const EditorPriority = 0;
53
23
  function TablePlugin() {
54
24
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
55
25
  react.useEffect(() => {
56
- if (!editor.hasNodes([TableNode.TableNode, TableCellNode.TableCellNode, TableRowNode.TableRowNode])) {
26
+ if (!editor.hasNodes([table.TableNode, table.TableCellNode, table.TableRowNode])) {
57
27
  {
58
28
  throw Error(`TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor`);
59
29
  }
@@ -65,19 +35,31 @@ function TablePlugin() {
65
35
  columns,
66
36
  rows
67
37
  } = payload;
68
- lexical.$log('handleAddTable');
69
38
  const selection = lexical.$getSelection();
70
39
 
71
- if (selection === null) {
40
+ if (!lexical.$isRangeSelection(selection)) {
72
41
  return true;
73
42
  }
74
43
 
75
- const focusNode = selection.focus.getNode();
44
+ const focus = selection.focus;
45
+ const focusNode = focus.getNode();
76
46
 
77
47
  if (focusNode !== null) {
78
- const topLevelNode = focusNode.getTopLevelElementOrThrow();
79
- const tableNode = $createTableNodeWithDimensions(rows, columns);
80
- topLevelNode.insertAfter(tableNode);
48
+ const tableNode = table.$createTableNodeWithDimensions(rows, columns);
49
+
50
+ if (lexical.$isRootNode(focusNode)) {
51
+ const target = focusNode.getChildAtIndex(focus.offset);
52
+
53
+ if (target !== null) {
54
+ target.insertBefore(tableNode);
55
+ } else {
56
+ focusNode.append(tableNode);
57
+ }
58
+ } else {
59
+ const topLevelNode = focusNode.getTopLevelElementOrThrow();
60
+ topLevelNode.insertAfter(tableNode);
61
+ }
62
+
81
63
  tableNode.insertAfter(lexical.$createParagraphNode());
82
64
  const firstCell = tableNode.getFirstChildOrThrow().getFirstChildOrThrow();
83
65
  firstCell.select();
@@ -89,6 +71,28 @@ function TablePlugin() {
89
71
  return false;
90
72
  }, EditorPriority);
91
73
  }, [editor]);
74
+ react.useEffect(() => {
75
+ const listeners = new Map();
76
+ return editor.addListener('mutation', table.TableNode, nodeMutations => {
77
+ // eslint-disable-next-line no-for-of-loops/no-for-of-loops
78
+ for (const [nodeKey, mutation] of nodeMutations) {
79
+ if (mutation === 'created') {
80
+ editor.update(() => {
81
+ const tableElement = editor.getElementByKey(nodeKey);
82
+ const tableNode = lexical.$getNodeByKey(nodeKey);
83
+
84
+ if (tableElement && tableNode) {
85
+ const removeListeners = table.$applyCustomTableHandlers(tableNode, tableElement, editor);
86
+ listeners.set(nodeKey, removeListeners);
87
+ }
88
+ });
89
+ } else if (mutation === 'destroyed') {
90
+ const cleanup = listeners.get(nodeKey);
91
+ if (cleanup) cleanup();
92
+ }
93
+ }
94
+ });
95
+ }, [editor]);
92
96
  return null;
93
97
  }
94
98
 
@@ -0,0 +1,10 @@
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
+ * @flow strict
8
+ */
9
+
10
+ declare export default function LexicalTablePlugin(): null;
@@ -4,6 +4,7 @@
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"),g=require("lexical/TableCellNode"),h=require("lexical/TableNode"),k=require("lexical/TableRowNode"),q=require("@lexical/react/LexicalComposerContext"),r=require("react");function t(d,a,b=!0){const f=h.$createTableNode();for(let e=0;e<d;e++){const l=k.$createTableRowNode();for(let m=0;m<a;m++){const n=g.$createTableCellNode(0===e&&b),p=c.$createParagraphNode();p.append(c.$createTextNode());n.append(p);l.append(n)}f.append(l)}return f}
8
- module.exports=function(){const [d]=q.useLexicalComposerContext();r.useEffect(()=>{if(!d.hasNodes([h.TableNode,g.TableCellNode,k.TableRowNode]))throw Error("TablePlugin: TableNode, TableCellNode or TableRowNode not registered on editor");return d.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:f,rows:e}=b;c.$log("handleAddTable");a=c.$getSelection();if(null===a)return!0;a=a.focus.getNode();null!==a&&(a=a.getTopLevelElementOrThrow(),b=t(e,f),a.insertAfter(b),b.insertAfter(c.$createParagraphNode()),
9
- b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[d]);return null};
7
+ var e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
8
+ module.exports=function(){const [d]=e.useLexicalComposerContext();m.useEffect(()=>{if(!d.hasNodes([g.TableNode,g.TableCellNode,g.TableRowNode]))throw Error("Minified Lexical error #54; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return d.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:h,rows:f}=b;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var c=a.focus;a=c.getNode();null!==a&&(b=g.$createTableNodeWithDimensions(f,
9
+ h),k.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(k.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[d]);m.useEffect(()=>{const a=new Map;return d.addListener("mutation",g.TableNode,b=>{for(const [c,h]of b)"created"===h?d.update(()=>{var f=d.getElementByKey(c);const l=k.$getNodeByKey(c);f&&l&&(f=g.$applyCustomTableHandlers(l,f,d),a.set(c,f))}):
10
+ "destroyed"===h&&(b=a.get(c))&&b()})},[d]);return null};
@@ -181,6 +181,14 @@ function printRangeSelection(selection) {
181
181
  return res;
182
182
  }
183
183
 
184
+ function printObjectSelection(selection) {
185
+ return `: node\n └ [${Array.from(selection._nodes).join(', ')}]`;
186
+ }
187
+
188
+ function printGridSelection(selection) {
189
+ return `: grid\n └ { grid: ${selection.gridKey}, anchorCell: ${selection.anchorCellKey}, focusCell: ${selection.focusCellKey} }`;
190
+ }
191
+
184
192
  function generateContent(editorState) {
185
193
  let res = ' root\n';
186
194
  const selectionString = editorState.read(() => {
@@ -200,7 +208,7 @@ function generateContent(editorState) {
200
208
  typeDisplay
201
209
  });
202
210
  });
203
- return selection === null ? ': null' : printRangeSelection(selection);
211
+ return selection === null ? ': null' : lexical.$isRangeSelection(selection) ? printRangeSelection(selection) : lexical.$isGridSelection(selection) ? printGridSelection(selection) : printObjectSelection(selection);
204
212
  });
205
213
  return res + '\n selection' + selectionString;
206
214
  }
@@ -279,7 +287,7 @@ function printSelectedCharsLine({
279
287
  typeDisplay
280
288
  }) {
281
289
  // No selection or node is not selected.
282
- if (!lexical.$isTextNode(node) || selection === null || !isSelected || lexical.$isElementNode(node)) {
290
+ if (!lexical.$isTextNode(node) || !lexical.$isRangeSelection(selection) || !isSelected || lexical.$isElementNode(node)) {
283
291
  return '';
284
292
  } // No selected characters.
285
293
 
@@ -0,0 +1,19 @@
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
+ * @flow strict
8
+ */
9
+
10
+ import type {LexicalEditor} from 'lexical';
11
+
12
+ declare export default function TreeView(props: {
13
+ timeTravelPanelClassName: string,
14
+ timeTravelPanelSliderClassName: string,
15
+ timeTravelPanelButtonClassName: string,
16
+ timeTravelButtonClassName: string,
17
+ viewClassName: string,
18
+ editor: LexicalEditor,
19
+ }): React$Node;
@@ -4,16 +4,17 @@
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"),q=require("react");const w=Object.freeze({"\t":"\\t","\n":"\\n"}),D=new RegExp(Object.keys(w).join("|"),"g"),E=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
7
+ var k=require("lexical"),q=require("react");const t=Object.freeze({"\t":"\\t","\n":"\\n"}),D=new RegExp(Object.keys(t).join("|"),"g"),E=Object.freeze({ancestorHasNextSibling:"|",ancestorIsLastChild:" ",hasNextSibling:"\u251c",isLastChild:"\u2514",selectedChar:"^",selectedLine:">"});
8
8
  function F(a){let b="";const c=G(a),e=a.anchor;a=a.focus;const d=e.offset,f=a.offset;b=b+`: range ${""!==c?`{ ${c} }`:""}`+`\n \u251c anchor { key: ${e.key}, offset: ${null===d?"null":d}, type: ${e.type} }`;return b+=`\n \u2514 focus { key: ${a.key}, offset: ${null===f?"null":f}, type: ${a.type} }`}
9
- function H(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();J(k.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected();var u=b,t=m?E.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(e)){var l=e.getTextContent(!0);const n=0===l.length?"(empty)":`"${K(l)}"`;l=[G(e),L(e),M(e)].filter(Boolean).join(", ");l=[n,0!==l.length?`{ ${l} }`:null].filter(Boolean).join(" ").trim()}else l="";b=u+`${t} ${r} ${f} ${g} ${l}\n`;b+=N({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,
10
- typeDisplay:g})});return null===c?": null":F(c)});return b+"\n selection"+a}function J(a,b,c=[]){a=a.getChildren();const e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?E.isLastChild:E.hasNextSibling));k.$isElementNode(d)&&J(d,b,c.concat(f===e-1?E.ancestorIsLastChild:E.ancestorHasNextSibling))})}function K(a){return Object.entries(w).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
9
+ function H(a){let b=" root\n";a=a.read(()=>{const c=k.$getSelection();J(k.$getRoot(),(e,d)=>{const f=`(${e.getKey()})`,g=e.getType()||"",m=e.isSelected();var v=b,u=m?E.selectedLine:" ",r=d.join(" ");if(k.$isTextNode(e)){var l=e.getTextContent(!0);const n=0===l.length?"(empty)":`"${K(l)}"`;l=[G(e),L(e),M(e)].filter(Boolean).join(", ");l=[n,0!==l.length?`{ ${l} }`:null].filter(Boolean).join(" ").trim()}else l="";b=v+`${u} ${r} ${f} ${g} ${l}\n`;b+=N({indent:d,isSelected:m,node:e,nodeKeyDisplay:f,selection:c,
10
+ typeDisplay:g})});return null===c?": null":k.$isRangeSelection(c)?F(c):k.$isGridSelection(c)?`: grid\n \u2514 { grid: ${c.gridKey}, anchorCell: ${c.anchorCellKey}, focusCell: ${c.focusCellKey} }`:`: node\n \u2514 [${Array.from(c._nodes).join(", ")}]`});return b+"\n selection"+a}
11
+ function J(a,b,c=[]){a=a.getChildren();const e=a.length;a.forEach((d,f)=>{b(d,c.concat(f===e-1?E.isLastChild:E.hasNextSibling));k.$isElementNode(d)&&J(d,b,c.concat(f===e-1?E.ancestorIsLastChild:E.ancestorHasNextSibling))})}function K(a){return Object.entries(t).reduce((b,[c,e])=>b.replace(new RegExp(c,"g"),String(e)),a)}
11
12
  const O=[a=>a.hasFormat("bold")&&"Bold",a=>a.hasFormat("code")&&"Code",a=>a.hasFormat("italic")&&"Italic",a=>a.hasFormat("strikethrough")&&"Strikethrough",a=>a.hasFormat("underline")&&"Underline"],P=[a=>a.isDirectionless()&&"Directionless",a=>a.isUnmergeable()&&"Unmergeable"],Q=[a=>a.isToken()&&"Token",a=>a.isSegmented()&&"Segmented",a=>a.isInert()&&"Inert"];function L(a){let b=P.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="detail: "+b);return b}
12
13
  function M(a){let b=Q.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="mode: "+b);return b}function G(a){let b=O.map(c=>c(a)).filter(Boolean).join(", ").toLocaleLowerCase();""!==b&&(b="format: "+b);return b}
13
- function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||null===d||!b||k.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,u=c.getTextContent(!0),t=u.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),v=m.getNode();n===v&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,g.offset]:
14
- c===n?[d,b]=n.isBefore(v)?[g.offset,t]:[0,g.offset]:c===v?[d,b]=v.isBefore(n)?[m.offset,t]:[0,m.offset]:[d,b]=[0,t]}c=(u.slice(0,d).match(D)||[]).length;g=(u.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
14
+ function N({indent:a,isSelected:b,node:c,nodeKeyDisplay:e,selection:d,typeDisplay:f}){if(!k.$isTextNode(c)||!k.$isRangeSelection(d)||!b||k.$isElementNode(c))return"";b=d.anchor;var g=d.focus;if(""===c.getTextContent()||b.getNode()===d.focus.getNode()&&b.offset===g.offset)return"";g=d.anchor;const m=d.focus,v=c.getTextContent(!0),u=v.length;b=d=-1;if("text"===g.type&&"text"===m.type){const n=g.getNode(),w=m.getNode();n===w&&c===n&&g.offset!==m.offset?[d,b]=g.offset<m.offset?[g.offset,m.offset]:[m.offset,
15
+ g.offset]:c===n?[d,b]=n.isBefore(w)?[g.offset,u]:[0,g.offset]:c===w?[d,b]=w.isBefore(n)?[m.offset,u]:[0,m.offset]:[d,b]=[0,u]}c=(v.slice(0,d).match(D)||[]).length;g=(v.slice(d,b).match(D)||[]).length;const [r,l]=[d+c,b+c+g];if(r===l)return"";c=a[a.length-1]===E.hasNextSibling?E.ancestorHasNextSibling:E.ancestorIsLastChild;a=[...a.slice(0,a.length-1),c];c=Array(r).fill(" ");d=Array(l-r).fill(E.selectedChar);e=Array(e.length+(f.length+3)).fill(" ");return[E.selectedLine,a.join(" "),[...e,...c,...d].join("")].join(" ")+
15
16
  "\n"}
16
- module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[u,t]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),v=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{t(H(f.getEditorState()));return f.addListener("update",({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());t([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
17
- m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=v.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
18
- {onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:v},u),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
17
+ module.exports=function({timeTravelButtonClassName:a,timeTravelPanelSliderClassName:b,timeTravelPanelButtonClassName:c,viewClassName:e,timeTravelPanelClassName:d,editor:f}){const [g,m]=q.useState([]),[v,u]=q.useState(""),[r,l]=q.useState(!1),n=q.useRef(0),w=q.useRef(null),B=q.useRef(null),[z,C]=q.useState(!1);q.useEffect(()=>{u(H(f.getEditorState()));return f.addListener("update",({editorState:h})=>{const p=f._compositionKey,x=H(f.getEditorState());u([x,null!==p&&`Composition key: ${p}`].filter(Boolean).join("\n\n"));r||
18
+ m(A=>[...A,[Date.now(),h]])})},[r,f]);const y=g.length;q.useEffect(()=>{if(z){let h;const p=()=>{const x=n.current;x===y-1?C(!1):h=setTimeout(()=>{n.current++;const A=n.current,I=B.current;null!==I&&(I.value=String(A));f.setEditorState(g[A][1]);p()},g[x+1][0]-g[x][0])};p();return()=>{window.clearTimeout(h)}}},[g,z,f,y]);q.useEffect(()=>{const h=w.current;if(null!==h)return h.__lexicalEditor=f,()=>{h.__lexicalEditor=null}},[f]);return q.createElement("div",{className:e},!r&&2<y&&q.createElement("button",
19
+ {onClick:()=>{const h=f.getRootElement();null!==h&&(h.contentEditable="false",n.current=y-1,l(!0))},className:a},"Time Travel"),q.createElement("pre",{ref:w},v),r&&q.createElement("div",{className:d},q.createElement("button",{className:c,onClick:()=>{C(!z)}},z?"Pause":"Play"),q.createElement("input",{className:b,ref:B,onChange:h=>{h=Number(h.target.value);const p=g[h];p&&(n.current=h,f.setEditorState(p[1]))},type:"range",min:"1",max:y-1}),q.createElement("button",{className:c,onClick:()=>{var h=f.getRootElement();
19
20
  if(null!==h){h.contentEditable="true";h=g.length-1;f.setEditorState(g[h][1]);const p=B.current;null!==p&&(p.value=String(h));l(!1);C(!1)}}},"Exit")))};
package/README.md CHANGED
@@ -70,7 +70,6 @@ function Editor() {
70
70
 
71
71
  return (
72
72
  <LexicalComposer initialConfig={initialConfig}>
73
- <LexicalBootstrapPlugin />
74
73
  <LexicalPlainTextPlugin
75
74
  contentEditable={<LexicalContentEditable />}
76
75
  placeholder={<div>Enter some text...</div>}
package/package.json CHANGED
@@ -12,11 +12,12 @@
12
12
  "rich-text"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.8",
15
+ "version": "0.1.11",
16
16
  "peerDependencies": {
17
- "lexical": "0.1.8",
18
- "@lexical/helpers": "0.1.8",
19
- "@lexical/yjs": "0.1.8",
17
+ "lexical": "0.1.11",
18
+ "@lexical/helpers": "0.1.11",
19
+ "@lexical/table": "0.1.11",
20
+ "@lexical/yjs": "0.1.11",
20
21
  "react": ">=17.x",
21
22
  "react-dom": ">=17.x"
22
23
  },
@@ -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
+ * @flow strict
8
+ */
9
+
10
+ import type {DecoratorMap, DecoratorStateValue} from 'lexical';
11
+
12
+ declare export default function useLexicalDecoratorMap<V: DecoratorStateValue>(
13
+ decoratorMap: DecoratorMap,
14
+ key: string,
15
+ initialValue: (() => V) | V,
16
+ ): [V, (DecoratorStateValue) => void];
@@ -4,5 +4,5 @@
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 e=require("lexical"),f=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
7
+ var e=require("lexical"),f=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
8
8
  module.exports=function(a,d,g){const [b,h]=f.useState(()=>{var c=a.get(d);c=void 0!==c?c:"function"===typeof g?g():g;return c}),[,m]=f.useState();l(()=>{a.get(d)!==b&&a.set(d,b)},[d,b,a]);l(()=>{if(e.isDecoratorArray(b))return b.observe(()=>{m({})})},[b]);l(()=>a.observe((c,k)=>{c===d&&(a._map.set(c,k),h(k))}),[a,d]);return[b,h]};
@@ -0,0 +1,15 @@
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
+ * @flow strict
8
+ */
9
+
10
+ import type {LexicalEditor} from 'lexical';
11
+
12
+ declare export default function useLexicalIsTextContentEmpty(
13
+ editor: LexicalEditor,
14
+ trim?: boolean,
15
+ ): boolean;
@@ -4,5 +4,5 @@
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"),e=require("react");function f(a,b=!0){if(a)return!1;a=c.$getRoot().getTextContent();b&&(a=a.trim());return""===a}function g(a,b){return()=>f(a,b)}var h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
7
+ var c=require("lexical"),e=require("react");function f(a,b=!0){if(a)return!1;a=c.$getRoot().getTextContent();b&&(a=a.trim());return""===a}function g(a,b){return()=>f(a,b)}var h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?e.useLayoutEffect:e.useEffect;
8
8
  module.exports=function(a,b){const [k,l]=e.useState(a.getEditorState().read(g(a.isComposing(),b)));h(()=>a.addListener("update",({editorState:d})=>{const m=a.isComposing();d=d.read(g(m,b));l(d)}),[a,b]);return k};
@@ -0,0 +1,70 @@
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
+ 'use strict';
8
+
9
+ var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
+ var lexical = require('lexical');
11
+ var react = require('react');
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
+
22
+ function isNodeSelected(editor, key) {
23
+ return editor.getEditorState().read(() => {
24
+ const node = lexical.$getNodeByKey(key);
25
+
26
+ if (node === null) {
27
+ return false;
28
+ }
29
+
30
+ return node.isSelected();
31
+ });
32
+ }
33
+
34
+ function useLexicalNodeSelection(key) {
35
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
36
+ const [isSelected, setIsSelected] = react.useState(() => isNodeSelected(editor, key));
37
+ react.useEffect(() => {
38
+ return editor.addListener('update', () => {
39
+ setIsSelected(isNodeSelected(editor, key));
40
+ });
41
+ }, [editor, key]);
42
+ const setSelected = react.useCallback(selected => {
43
+ editor.update(() => {
44
+ let selection = lexical.$getSelection();
45
+
46
+ if (!lexical.$isNodeSelection(selection)) {
47
+ selection = lexical.$createNodeSelection();
48
+ lexical.$setSelection(selection);
49
+ }
50
+
51
+ if (selected) {
52
+ selection.add(key);
53
+ } else {
54
+ selection.delete(key);
55
+ }
56
+ });
57
+ }, [editor, key]);
58
+ const clearSelected = react.useCallback(() => {
59
+ editor.update(() => {
60
+ const selection = lexical.$getSelection();
61
+
62
+ if (lexical.$isNodeSelection(selection)) {
63
+ selection.clear();
64
+ }
65
+ });
66
+ }, [editor]);
67
+ return [isSelected, setSelected, clearSelected];
68
+ }
69
+
70
+ module.exports = useLexicalNodeSelection;
@@ -0,0 +1,9 @@
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
+ 'use strict'
8
+ const useLexicalNodeSelection = process.env.NODE_ENV === 'development' ? require('./useLexicalNodeSelection.dev.js') : require('./useLexicalNodeSelection.prod.js')
9
+ module.exports = useLexicalNodeSelection;
@@ -0,0 +1,14 @@
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
+ * @flow strict
8
+ */
9
+
10
+ import type {NodeKey} from 'lexical';
11
+
12
+ declare export default function useLexicalNodeSelection(
13
+ key: NodeKey,
14
+ ): [boolean, (boolean) => void, () => void];
@@ -0,0 +1,8 @@
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
+ var c=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),h=require("react");function k(b,a){return b.getEditorState().read(()=>{const f=e.$getNodeByKey(a);return null===f?!1:f.isSelected()})}
8
+ module.exports=function(b){const [a]=c.useLexicalComposerContext(),[f,l]=h.useState(()=>k(a,b));h.useEffect(()=>a.addListener("update",()=>{l(k(a,b))}),[a,b]);const m=h.useCallback(g=>{a.update(()=>{let d=e.$getSelection();e.$isNodeSelection(d)||(d=e.$createNodeSelection(),e.$setSelection(d));g?d.add(b):d.delete(b)})},[a,b]),n=h.useCallback(()=>{a.update(()=>{const g=e.$getSelection();e.$isNodeSelection(g)&&g.clear()})},[a]);return[f,m,n]};
@@ -0,0 +1,13 @@
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
+ * @flow strict
8
+ */
9
+
10
+ type UnsubscribeFn = () => void;
11
+ declare export default function withSubscriptions(
12
+ ...unsubscribe: Array<UnsubscribeFn>
13
+ ): () => void;
@@ -4,4 +4,4 @@
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';module.exports=function(...a){return()=>{a.forEach(b=>b())}};
7
+ module.exports=function(...a){return()=>{a.forEach(b=>b())}};
@@ -1,124 +0,0 @@
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
- 'use strict';
8
-
9
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
- var lexical = require('lexical');
11
- var react = require('react');
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
- */
31
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
32
- var useLayoutEffect = useLayoutEffectImpl;
33
-
34
- /**
35
- * Copyright (c) Meta Platforms, Inc. and affiliates.
36
- *
37
- * This source code is licensed under the MIT license found in the
38
- * LICENSE file in the root directory of this source tree.
39
- *
40
- *
41
- */
42
- const BootstrapPriority = 0;
43
-
44
- function shouldSelectParagraph(editor) {
45
- const activeElement = document.activeElement;
46
- return lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement();
47
- }
48
-
49
- function initParagraph(root, editor) {
50
- const paragraph = lexical.$createParagraphNode();
51
- root.append(paragraph);
52
-
53
- if (shouldSelectParagraph(editor)) {
54
- paragraph.select();
55
- }
56
- }
57
-
58
- function defaultInitEditor(editor) {
59
- const root = lexical.$getRoot();
60
- const firstChild = root.getFirstChild();
61
-
62
- if (firstChild === null) {
63
- initParagraph(root, editor);
64
- }
65
- }
66
-
67
- function defaultClearEditor(editor) {
68
- const root = lexical.$getRoot();
69
- root.clear();
70
- initParagraph(root, editor);
71
- }
72
-
73
- function initEditor(editor, initialPayloadFn) {
74
- editor.update(() => {
75
- lexical.$log('initEditor');
76
- initialPayloadFn(editor);
77
- });
78
- }
79
-
80
- function clearEditor(editor, clearEditorFn, callbackFn) {
81
- editor.update(() => {
82
- lexical.$log('clearEditor');
83
- clearEditorFn(editor);
84
- }, {
85
- onUpdate: callbackFn
86
- });
87
- }
88
-
89
- function useBootstrapEditor(editor, initialPayloadFn, clearEditorFn) {
90
- useLayoutEffect(() => {
91
- return editor.addListener('command', (type, payload) => {
92
- if (type === 'bootstrapEditor') {
93
- initEditor(editor, initialPayloadFn != null ? initialPayloadFn : defaultInitEditor);
94
- return true;
95
- }
96
-
97
- if (type === 'clearEditor') {
98
- clearEditor(editor, clearEditorFn != null ? clearEditorFn : defaultClearEditor);
99
- return true;
100
- }
101
-
102
- return false;
103
- }, BootstrapPriority);
104
- }, [clearEditorFn, editor, initialPayloadFn]);
105
- }
106
-
107
- /**
108
- * Copyright (c) Meta Platforms, Inc. and affiliates.
109
- *
110
- * This source code is licensed under the MIT license found in the
111
- * LICENSE file in the root directory of this source tree.
112
- *
113
- *
114
- */
115
- function LexicalBootstrapPlugin({
116
- initialPayloadFn,
117
- clearEditorFn
118
- }) {
119
- const [editor] = LexicalComposerContext.useLexicalComposerContext();
120
- useBootstrapEditor(editor, initialPayloadFn, clearEditorFn);
121
- return null;
122
- }
123
-
124
- module.exports = LexicalBootstrapPlugin;
@@ -1,9 +0,0 @@
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
- 'use strict'
8
- const LexicalBootstrapPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalBootstrapPlugin.dev.js') : require('./LexicalBootstrapPlugin.prod.js')
9
- module.exports = LexicalBootstrapPlugin;
@@ -1,8 +0,0 @@
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
- 'use strict';var d=require("@lexical/react/LexicalComposerContext"),e=require("lexical"),f=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;function k(a,b){const c=e.$createParagraphNode();a.append(c);a=document.activeElement;(null!==e.$getSelection()||null!==a&&a===b.getRootElement())&&c.select()}function l(a){const b=e.$getRoot();null===b.getFirstChild()&&k(b,a)}
8
- function m(a){const b=e.$getRoot();b.clear();k(b,a)}function n(a,b){a.update(()=>{e.$log("initEditor");b(a)})}function p(a,b,c){a.update(()=>{e.$log("clearEditor");b(a)},{onUpdate:c})}function q(a,b,c){h(()=>a.addListener("command",g=>"bootstrapEditor"===g?(n(a,null!=b?b:l),!0):"clearEditor"===g?(p(a,null!=c?c:m),!0):!1,0),[c,a,b])}module.exports=function({initialPayloadFn:a,clearEditorFn:b}){const [c]=d.useLexicalComposerContext();q(c,a,b);return null};
@@ -1,51 +0,0 @@
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
- 'use strict';
8
-
9
- var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
- var lexical = require('lexical');
11
- var react = require('react');
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 EditorPriority = 0;
22
- function HorizontalRulePlugin() {
23
- const [editor] = LexicalComposerContext.useLexicalComposerContext();
24
- react.useEffect(() => {
25
- return editor.addListener('command', type => {
26
- if (type === 'insertHorizontalRule') {
27
- lexical.$log('insertHorizontalRule');
28
- const selection = lexical.$getSelection();
29
-
30
- if (selection === null) {
31
- return false;
32
- }
33
-
34
- const focusNode = selection.focus.getNode();
35
-
36
- if (focusNode !== null) {
37
- const horizontalRuleNode = lexical.$createHorizontalRuleNode();
38
- selection.insertParagraph();
39
- selection.focus.getNode().getTopLevelElementOrThrow().insertBefore(horizontalRuleNode);
40
- }
41
-
42
- return true;
43
- }
44
-
45
- return false;
46
- }, EditorPriority);
47
- }, [editor]);
48
- return null;
49
- }
50
-
51
- module.exports = HorizontalRulePlugin;