@lexical/react 0.6.2 → 0.6.3

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.
@@ -74,9 +74,9 @@ function BlockWithAlignableContents({
74
74
 
75
75
  return false;
76
76
  }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.CLICK_COMMAND, event => {
77
- event.preventDefault();
78
-
79
77
  if (event.target === ref.current) {
78
+ event.preventDefault();
79
+
80
80
  if (!event.shiftKey) {
81
81
  clearSelection();
82
82
  }
@@ -6,5 +6,5 @@
6
6
  */
7
7
  'use strict';var a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),m=require("@lexical/react/useLexicalNodeSelection"),n=require("@lexical/utils"),u=require("lexical"),v=require("react");
8
8
  exports.BlockWithAlignableContents=function({children:w,format:p,nodeKey:g,className:q}){let [d]=a.useLexicalComposerContext(),[e,k,r]=m.useLexicalNodeSelection(g),t=v.useRef(null),l=v.useCallback(b=>{e&&u.$isNodeSelection(u.$getSelection())&&(b.preventDefault(),d.update(()=>{const c=u.$getNodeByKey(g);u.$isDecoratorNode(c)&&c.remove();k(!1)}));return!1},[d,e,g,k]);v.useEffect(()=>n.mergeRegister(d.registerCommand(u.FORMAT_ELEMENT_COMMAND,b=>{if(e){var c=u.$getSelection();if(u.$isNodeSelection(c)){var f=
9
- u.$getNodeByKey(g);h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(u.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},u.COMMAND_PRIORITY_LOW),d.registerCommand(u.CLICK_COMMAND,b=>{b.preventDefault();return b.target===t.current?(b.shiftKey||r(),k(!e),!0):!1},u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_DELETE_COMMAND,l,u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_BACKSPACE_COMMAND,
10
- l,u.COMMAND_PRIORITY_LOW)),[r,d,e,g,l,k]);return v.createElement("div",{className:[q.base,e?q.focus:null].filter(Boolean).join(" "),ref:t,style:{textAlign:p?p:void 0}},w)}
9
+ u.$getNodeByKey(g);h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(u.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},u.COMMAND_PRIORITY_LOW),d.registerCommand(u.CLICK_COMMAND,b=>b.target===t.current?(b.preventDefault(),b.shiftKey||r(),k(!e),!0):!1,u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_DELETE_COMMAND,l,u.COMMAND_PRIORITY_LOW),d.registerCommand(u.KEY_BACKSPACE_COMMAND,l,
10
+ u.COMMAND_PRIORITY_LOW)),[r,d,e,g,l,k]);return v.createElement("div",{className:[q.base,e?q.focus:null].filter(Boolean).join(" "),ref:t,style:{textAlign:p?p:void 0}},w)}
@@ -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
+ */
8
+ import { type Klass, type LexicalEditor, type LexicalNode, type NodeKey } from 'lexical';
9
+ export declare function NodeEventPlugin({ nodeType, eventType, eventListener, }: {
10
+ nodeType: Klass<LexicalNode>;
11
+ eventType: string;
12
+ eventListener: (event: Event, editor: LexicalEditor, nodeKey: NodeKey) => void;
13
+ }): null;
@@ -0,0 +1,65 @@
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 react = require('react');
11
+
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
+
21
+ /**
22
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
23
+ *
24
+ * This source code is licensed under the MIT license found in the
25
+ * LICENSE file in the root directory of this source tree.
26
+ *
27
+ */
28
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
29
+ var useLayoutEffect = useLayoutEffectImpl;
30
+
31
+ /**
32
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
33
+ *
34
+ * This source code is licensed under the MIT license found in the
35
+ * LICENSE file in the root directory of this source tree.
36
+ *
37
+ */
38
+ function NodeEventPlugin({
39
+ nodeType,
40
+ eventType,
41
+ eventListener
42
+ }) {
43
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
44
+ const listenerRef = react.useRef(eventListener);
45
+ listenerRef.current = eventListener;
46
+ useLayoutEffect(() => {
47
+ return editor.registerMutationListener(nodeType, mutations => {
48
+ editor.getEditorState().read(() => {
49
+ for (const [key, mutation] of mutations) {
50
+ const element = editor.getElementByKey(key);
51
+
52
+ if (mutation === 'created' && element !== null) {
53
+ element.addEventListener(eventType, event => {
54
+ listenerRef.current(event, editor, key);
55
+ });
56
+ }
57
+ }
58
+ });
59
+ }); // wW intentionally don't respect changes to eventType.
60
+ // eslint-disable-next-line react-hooks/exhaustive-deps
61
+ }, [editor, nodeType]);
62
+ return null;
63
+ }
64
+
65
+ exports.NodeEventPlugin = NodeEventPlugin;
@@ -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 LexicalNodeEventPlugin = process.env.NODE_ENV === 'development' ? require('./LexicalNodeEventPlugin.dev.js') : require('./LexicalNodeEventPlugin.prod.js')
9
+ module.exports = LexicalNodeEventPlugin;
@@ -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
+ 'use strict';var b=require("@lexical/react/LexicalComposerContext"),h=require("react"),k="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?h.useLayoutEffect:h.useEffect;
8
+ exports.NodeEventPlugin=function({nodeType:c,eventType:l,eventListener:d}){let [a]=b.useLexicalComposerContext(),e=h.useRef(d);e.current=d;k(()=>a.registerMutationListener(c,m=>{a.getEditorState().read(()=>{for(let [f,n]of m){let g=a.getElementByKey(f);"created"===n&&null!==g&&g.addEventListener(l,p=>{e.current(p,a,f)})}})}),[a,c]);return null}
package/package.json CHANGED
@@ -8,29 +8,29 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.6.2",
11
+ "version": "0.6.3",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.6.2",
14
- "@lexical/code": "0.6.2",
15
- "@lexical/dragon": "0.6.2",
16
- "@lexical/hashtag": "0.6.2",
17
- "@lexical/history": "0.6.2",
18
- "@lexical/link": "0.6.2",
19
- "@lexical/list": "0.6.2",
20
- "@lexical/mark": "0.6.2",
21
- "@lexical/markdown": "0.6.2",
22
- "@lexical/overflow": "0.6.2",
23
- "@lexical/plain-text": "0.6.2",
24
- "@lexical/rich-text": "0.6.2",
25
- "@lexical/selection": "0.6.2",
26
- "@lexical/table": "0.6.2",
27
- "@lexical/text": "0.6.2",
28
- "@lexical/utils": "0.6.2",
29
- "@lexical/yjs": "0.6.2",
13
+ "@lexical/clipboard": "0.6.3",
14
+ "@lexical/code": "0.6.3",
15
+ "@lexical/dragon": "0.6.3",
16
+ "@lexical/hashtag": "0.6.3",
17
+ "@lexical/history": "0.6.3",
18
+ "@lexical/link": "0.6.3",
19
+ "@lexical/list": "0.6.3",
20
+ "@lexical/mark": "0.6.3",
21
+ "@lexical/markdown": "0.6.3",
22
+ "@lexical/overflow": "0.6.3",
23
+ "@lexical/plain-text": "0.6.3",
24
+ "@lexical/rich-text": "0.6.3",
25
+ "@lexical/selection": "0.6.3",
26
+ "@lexical/table": "0.6.3",
27
+ "@lexical/text": "0.6.3",
28
+ "@lexical/utils": "0.6.3",
29
+ "@lexical/yjs": "0.6.3",
30
30
  "react-error-boundary": "^3.1.4"
31
31
  },
32
32
  "peerDependencies": {
33
- "lexical": "0.6.2",
33
+ "lexical": "0.6.3",
34
34
  "react": ">=17.x",
35
35
  "react-dom": ">=17.x"
36
36
  },