@lexical/react 0.1.10 → 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 (59) hide show
  1. package/DEPRECATED_useLexicalAutoFormatter.dev.js +69 -28
  2. package/DEPRECATED_useLexicalAutoFormatter.prod.js +19 -18
  3. package/DEPRECATED_useLexicalCharacterLimit.dev.js +20 -17
  4. package/DEPRECATED_useLexicalCharacterLimit.prod.js +8 -8
  5. package/DEPRECATED_useLexicalList.dev.js +6 -0
  6. package/DEPRECATED_useLexicalList.prod.js +1 -1
  7. package/DEPRECATED_useLexicalPlainText.dev.js +61 -58
  8. package/DEPRECATED_useLexicalPlainText.prod.js +15 -15
  9. package/DEPRECATED_useLexicalRichText.dev.js +64 -61
  10. package/DEPRECATED_useLexicalRichText.prod.js +24 -25
  11. package/LexicalAutoFormatterPlugin.dev.js +69 -28
  12. package/LexicalAutoFormatterPlugin.js.flow +10 -0
  13. package/LexicalAutoFormatterPlugin.prod.js +20 -19
  14. package/LexicalAutoLinkPlugin.js.flow +23 -0
  15. package/LexicalCharacterLimitPlugin.dev.js +20 -17
  16. package/LexicalCharacterLimitPlugin.js.flow +12 -0
  17. package/LexicalCharacterLimitPlugin.prod.js +9 -8
  18. package/LexicalClearEditorPlugin.dev.js +52 -0
  19. package/LexicalClearEditorPlugin.js +9 -0
  20. package/LexicalClearEditorPlugin.js.flow +14 -0
  21. package/LexicalClearEditorPlugin.prod.js +7 -0
  22. package/LexicalCollaborationPlugin.dev.js +21 -11
  23. package/LexicalCollaborationPlugin.js.flow +55 -0
  24. package/LexicalCollaborationPlugin.prod.js +7 -7
  25. package/LexicalComposer.dev.js +7 -0
  26. package/LexicalComposer.js.flow +23 -0
  27. package/LexicalComposer.prod.js +3 -2
  28. package/LexicalComposerContext.js.flow +27 -0
  29. package/LexicalContentEditable.dev.js +14 -8
  30. package/LexicalContentEditable.js.flow +35 -0
  31. package/LexicalContentEditable.prod.js +3 -3
  32. package/LexicalHashtagPlugin.js.flow +20 -0
  33. package/LexicalHistoryPlugin.js.flow +34 -0
  34. package/LexicalHorizontalRuleNode.js.flow +25 -0
  35. package/LexicalLinkPlugin.js.flow +10 -0
  36. package/LexicalListPlugin.dev.js +6 -0
  37. package/LexicalListPlugin.js.flow +10 -0
  38. package/LexicalListPlugin.prod.js +2 -2
  39. package/LexicalNestedComposer.js.flow +21 -0
  40. package/LexicalOnChangePlugin.js.flow +14 -0
  41. package/LexicalPlainTextPlugin.dev.js +64 -60
  42. package/LexicalPlainTextPlugin.js.flow +18 -0
  43. package/LexicalPlainTextPlugin.prod.js +12 -12
  44. package/LexicalRichTextPlugin.dev.js +65 -61
  45. package/LexicalRichTextPlugin.js.flow +18 -0
  46. package/LexicalRichTextPlugin.prod.js +19 -20
  47. package/LexicalTablePlugin.dev.js +22 -0
  48. package/LexicalTablePlugin.js.flow +10 -0
  49. package/LexicalTablePlugin.prod.js +4 -3
  50. package/LexicalTreeView.js.flow +19 -0
  51. package/README.md +0 -1
  52. package/package.json +5 -5
  53. package/useLexicalDecoratorMap.js.flow +16 -0
  54. package/useLexicalIsTextContentEmpty.js.flow +15 -0
  55. package/useLexicalNodeSelection.js.flow +14 -0
  56. package/withSubscriptions.js.flow +13 -0
  57. package/LexicalBootstrapPlugin.dev.js +0 -122
  58. package/LexicalBootstrapPlugin.js +0 -9
  59. package/LexicalBootstrapPlugin.prod.js +0 -8
@@ -71,6 +71,28 @@ function TablePlugin() {
71
71
  return false;
72
72
  }, EditorPriority);
73
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]);
74
96
  return null;
75
97
  }
76
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
- var d=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/table"),g=require("lexical"),h=require("react");
8
- module.exports=function(){const [f]=d.useLexicalComposerContext();h.useEffect(()=>{if(!f.hasNodes([e.TableNode,e.TableCellNode,e.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 f.addListener("command",(a,b)=>{if("insertTable"===a){const {columns:k,rows:l}=b;a=g.$getSelection();if(!g.$isRangeSelection(a))return!0;var c=a.focus;a=c.getNode();null!==a&&(b=e.$createTableNodeWithDimensions(l,
9
- k),g.$isRootNode(a)?(c=a.getChildAtIndex(c.offset),null!==c?c.insertBefore(b):a.append(b)):a.getTopLevelElementOrThrow().insertAfter(b),b.insertAfter(g.$createParagraphNode()),b.getFirstChildOrThrow().getFirstChildOrThrow().select());return!0}return!1},0)},[f]);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};
@@ -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;
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,12 +12,12 @@
12
12
  "rich-text"
13
13
  ],
14
14
  "license": "MIT",
15
- "version": "0.1.10",
15
+ "version": "0.1.11",
16
16
  "peerDependencies": {
17
- "lexical": "0.1.10",
18
- "@lexical/helpers": "0.1.10",
19
- "@lexical/table": "0.1.10",
20
- "@lexical/yjs": "0.1.10",
17
+ "lexical": "0.1.11",
18
+ "@lexical/helpers": "0.1.11",
19
+ "@lexical/table": "0.1.11",
20
+ "@lexical/yjs": "0.1.11",
21
21
  "react": ">=17.x",
22
22
  "react-dom": ">=17.x"
23
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];
@@ -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;
@@ -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,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;
@@ -1,122 +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
- initialPayloadFn(editor);
76
- });
77
- }
78
-
79
- function clearEditor(editor, clearEditorFn, callbackFn) {
80
- editor.update(() => {
81
- clearEditorFn(editor);
82
- }, {
83
- onUpdate: callbackFn
84
- });
85
- }
86
-
87
- function useBootstrapEditor(editor, initialPayloadFn, clearEditorFn) {
88
- useLayoutEffect(() => {
89
- return editor.addListener('command', (type, payload) => {
90
- if (type === 'bootstrapEditor') {
91
- initEditor(editor, initialPayloadFn != null ? initialPayloadFn : defaultInitEditor);
92
- return true;
93
- }
94
-
95
- if (type === 'clearEditor') {
96
- clearEditor(editor, clearEditorFn != null ? clearEditorFn : defaultClearEditor);
97
- return true;
98
- }
99
-
100
- return false;
101
- }, BootstrapPriority);
102
- }, [clearEditorFn, editor, initialPayloadFn]);
103
- }
104
-
105
- /**
106
- * Copyright (c) Meta Platforms, Inc. and affiliates.
107
- *
108
- * This source code is licensed under the MIT license found in the
109
- * LICENSE file in the root directory of this source tree.
110
- *
111
- *
112
- */
113
- function LexicalBootstrapPlugin({
114
- initialPayloadFn,
115
- clearEditorFn
116
- }) {
117
- const [editor] = LexicalComposerContext.useLexicalComposerContext();
118
- useBootstrapEditor(editor, initialPayloadFn, clearEditorFn);
119
- return null;
120
- }
121
-
122
- 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
- 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(()=>{b(a)})}function p(a,b,c){a.update(()=>{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};