@lexical/react 0.2.1 → 0.2.4

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.
@@ -19,7 +19,6 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- const LowPriority = 1;
23
22
  function useList(editor) {
24
23
  react.useEffect(() => {
25
24
  return utils.mergeRegister(editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
@@ -30,7 +29,7 @@ function useList(editor) {
30
29
  }
31
30
 
32
31
  return false;
33
- }, LowPriority), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
32
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
34
33
  const hasHandledIndention = list.outdentList();
35
34
 
36
35
  if (hasHandledIndention) {
@@ -38,16 +37,16 @@ function useList(editor) {
38
37
  }
39
38
 
40
39
  return false;
41
- }, LowPriority), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
40
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
42
41
  list.insertList(editor, 'ol');
43
42
  return true;
44
- }, LowPriority), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
43
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
45
44
  list.insertList(editor, 'ul');
46
45
  return true;
47
- }, LowPriority), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
46
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
48
47
  list.removeList(editor);
49
48
  return true;
50
- }, LowPriority), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
49
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
51
50
  const hasHandledInsertParagraph = list.$handleListInsertParagraph();
52
51
 
53
52
  if (hasHandledInsertParagraph) {
@@ -55,7 +54,7 @@ function useList(editor) {
55
54
  }
56
55
 
57
56
  return false;
58
- }, LowPriority));
57
+ }, lexical.COMMAND_PRIORITY_LOW));
59
58
  }, [editor]);
60
59
  }
61
60
 
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var b=require("@lexical/list"),c=require("@lexical/utils"),d=require("lexical"),e=require("react");
8
- function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>b.indentList()?!0:!1,1),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>b.outdentList()?!0:!1,1),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"ol");return!0},1),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"ul");return!0},1),a.registerCommand(b.REMOVE_LIST_COMMAND,()=>{b.removeList(a);return!0},1),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?
9
- !0:!1,1)),[a])}module.exports=function(a){f(a)};
8
+ function f(a){e.useEffect(()=>c.mergeRegister(a.registerCommand(d.INDENT_CONTENT_COMMAND,()=>b.indentList()?!0:!1,d.COMMAND_PRIORITY_LOW),a.registerCommand(d.OUTDENT_CONTENT_COMMAND,()=>b.outdentList()?!0:!1,d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_ORDERED_LIST_COMMAND,()=>{b.insertList(a,"ol");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.INSERT_UNORDERED_LIST_COMMAND,()=>{b.insertList(a,"ul");return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(b.REMOVE_LIST_COMMAND,()=>{b.removeList(a);
9
+ return!0},d.COMMAND_PRIORITY_LOW),a.registerCommand(d.INSERT_PARAGRAPH_COMMAND,()=>b.$handleListInsertParagraph()?!0:!1,d.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(a){f(a)};
@@ -8,6 +8,6 @@
8
8
 
9
9
  import {$ReadOnly} from 'utility-types';
10
10
  type Props = $ReadOnly<{
11
- scrollRef: { current: HTMLElement | null };
11
+ scrollRef: {current: HTMLElement | null};
12
12
  }>;
13
13
  export default function LexicalAutoScrollPlugin(props: Props): null;
@@ -9,4 +9,6 @@
9
9
  type Props = $ReadOnly<{
10
10
  scrollRef: {current: HTMLElement | null},
11
11
  }>;
12
- declare export default function LexicalAutoScrollPlugin(props: Props): React$Node;
12
+ declare export default function LexicalAutoScrollPlugin(
13
+ props: Props,
14
+ ): React$Node;
@@ -0,0 +1,102 @@
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 LexicalDecoratorBlockNode = require('@lexical/react/LexicalDecoratorBlockNode');
11
+ var useLexicalNodeSelection = require('@lexical/react/useLexicalNodeSelection');
12
+ var utils = require('@lexical/utils');
13
+ var lexical = require('lexical');
14
+ var React = require('react');
15
+
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 BlockWithAlignableContents({
25
+ children,
26
+ format,
27
+ nodeKey
28
+ }) {
29
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
30
+ const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey);
31
+ const ref = React.useRef();
32
+ const onDelete = React.useCallback(payload => {
33
+ if (isSelected && lexical.$isNodeSelection(lexical.$getSelection())) {
34
+ const event = payload;
35
+ event.preventDefault();
36
+ editor.update(() => {
37
+ const node = lexical.$getNodeByKey(nodeKey);
38
+
39
+ if (lexical.$isDecoratorNode(node) && node.isTopLevel()) {
40
+ node.remove();
41
+ }
42
+
43
+ setSelected(false);
44
+ });
45
+ }
46
+
47
+ return false;
48
+ }, [editor, isSelected, nodeKey, setSelected]);
49
+ React.useEffect(() => {
50
+ return utils.mergeRegister(editor.registerCommand(lexical.FORMAT_ELEMENT_COMMAND, payload => {
51
+ if (isSelected) {
52
+ const selection = lexical.$getSelection();
53
+
54
+ if (lexical.$isNodeSelection(selection)) {
55
+ const node = lexical.$getNodeByKey(nodeKey);
56
+
57
+ if (LexicalDecoratorBlockNode.$isDecoratorBlockNode(node)) {
58
+ node.setFormat(payload);
59
+ }
60
+ } else if (lexical.$isRangeSelection(selection)) {
61
+ const nodes = selection.getNodes();
62
+
63
+ for (const node of nodes) {
64
+ if (LexicalDecoratorBlockNode.$isDecoratorBlockNode(node)) {
65
+ node.setFormat(payload);
66
+ } else {
67
+ const element = utils.$getNearestBlockElementAncestorOrThrow(node);
68
+ element.setFormat(payload);
69
+ }
70
+ }
71
+ }
72
+
73
+ return true;
74
+ }
75
+
76
+ return false;
77
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.CLICK_COMMAND, payload => {
78
+ const event = payload;
79
+ event.preventDefault();
80
+
81
+ if (event.target === ref.current) {
82
+ if (!event.shiftKey) {
83
+ clearSelection();
84
+ }
85
+
86
+ setSelected(!isSelected);
87
+ return true;
88
+ }
89
+
90
+ return false;
91
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_DELETE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.KEY_BACKSPACE_COMMAND, onDelete, lexical.COMMAND_PRIORITY_LOW));
92
+ }, [clearSelection, editor, isSelected, nodeKey, onDelete, setSelected]);
93
+ return /*#__PURE__*/React.createElement("div", {
94
+ className: `embed-block${isSelected ? ' focused' : ''}`,
95
+ ref: ref,
96
+ style: {
97
+ textAlign: format
98
+ }
99
+ }, children);
100
+ }
101
+
102
+ exports.BlockWithAlignableContents = BlockWithAlignableContents;
@@ -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 LexicalBlockWithAlignableContents = process.env.NODE_ENV === 'development' ? require('./LexicalBlockWithAlignableContents.dev.js') : require('./LexicalBlockWithAlignableContents.prod.js')
9
+ module.exports = LexicalBlockWithAlignableContents;
@@ -0,0 +1,24 @@
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 {
11
+ ElementFormatType,
12
+ LexicalEditor,
13
+ EditorThemeClasses,
14
+ LexicalNode,
15
+ NodeKey,
16
+ } from 'lexical';
17
+
18
+ type Props = $ReadOnly<{
19
+ children: React$Node,
20
+ format: ?ElementFormatType,
21
+ nodeKey: NodeKey,
22
+ }>;
23
+
24
+ declare export function BlockWithAlignableContents(Props): React$Node;
@@ -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
+ var a=require("@lexical/react/LexicalComposerContext"),h=require("@lexical/react/LexicalDecoratorBlockNode"),m=require("@lexical/react/useLexicalNodeSelection"),n=require("@lexical/utils"),r=require("lexical"),t=require("react");
8
+ exports.BlockWithAlignableContents=function({children:u,format:v,nodeKey:g}){const [d]=a.useLexicalComposerContext(),[e,k,p]=m(g),q=t.useRef(),l=t.useCallback(b=>{e&&r.$isNodeSelection(r.$getSelection())&&(b.preventDefault(),d.update(()=>{const c=r.$getNodeByKey(g);r.$isDecoratorNode(c)&&c.isTopLevel()&&c.remove();k(!1)}));return!1},[d,e,g,k]);t.useEffect(()=>n.mergeRegister(d.registerCommand(r.FORMAT_ELEMENT_COMMAND,b=>{if(e){var c=r.$getSelection();if(r.$isNodeSelection(c)){var f=r.$getNodeByKey(g);
9
+ h.$isDecoratorBlockNode(f)&&f.setFormat(b)}else if(r.$isRangeSelection(c)){c=c.getNodes();for(f of c)h.$isDecoratorBlockNode(f)?f.setFormat(b):n.$getNearestBlockElementAncestorOrThrow(f).setFormat(b)}return!0}return!1},r.COMMAND_PRIORITY_LOW),d.registerCommand(r.CLICK_COMMAND,b=>{b.preventDefault();return b.target===q.current?(b.shiftKey||p(),k(!e),!0):!1},r.COMMAND_PRIORITY_LOW),d.registerCommand(r.KEY_DELETE_COMMAND,l,r.COMMAND_PRIORITY_LOW),d.registerCommand(r.KEY_BACKSPACE_COMMAND,l,r.COMMAND_PRIORITY_LOW)),
10
+ [p,d,e,g,l,k]);return t.createElement("div",{className:`embed-block${e?" focused":""}`,ref:q,style:{textAlign:v}},u)};
@@ -61,7 +61,7 @@ function LexicalClearEditorPlugin({
61
61
  }
62
62
  });
63
63
  return true;
64
- }, 0);
64
+ }, lexical.COMMAND_PRIORITY_EDITOR);
65
65
  }, [editor, onClear]);
66
66
  return null;
67
67
  }
@@ -5,4 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var a=require("@lexical/react/LexicalComposerContext"),d=require("lexical"),g=require("react"),h="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;
8
- module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.registerCommand(d.CLEAR_EDITOR_COMMAND,()=>{c.update(()=>{if(null==b){const e=d.$getRoot(),k=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==k&&f.select()}else b()});return!0},0),[c,b]);return null};
8
+ module.exports=function({onClear:b}){const [c]=a.useLexicalComposerContext();h(()=>c.registerCommand(d.CLEAR_EDITOR_COMMAND,()=>{c.update(()=>{if(null==b){const e=d.$getRoot(),k=d.$getSelection(),f=d.$createParagraphNode();e.clear();e.append(f);null!==k&&f.select()}else b()});return!0},d.COMMAND_PRIORITY_EDITOR),[c,b]);return null};
@@ -21,7 +21,6 @@ var reactDom = require('react-dom');
21
21
  *
22
22
  *
23
23
  */
24
- const EditorPriority = 0;
25
24
  function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
26
25
  const isReloadingDoc = React.useRef(false);
27
26
  const [doc, setDoc] = React.useState(docMap.get(id));
@@ -133,7 +132,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
133
132
  }
134
133
 
135
134
  return true;
136
- }, EditorPriority);
135
+ }, lexical.COMMAND_PRIORITY_EDITOR);
137
136
  }, [connect, disconnect, editor]);
138
137
  return [cursorsContainer, binding];
139
138
  }
@@ -142,10 +141,10 @@ function useYjsFocusTracking(editor, provider, name, color) {
142
141
  return utils.mergeRegister(editor.registerCommand(lexical.FOCUS_COMMAND, payload => {
143
142
  yjs.setLocalStateFocus(provider, name, color, true);
144
143
  return true;
145
- }, EditorPriority), editor.registerCommand(lexical.BLUR_COMMAND, payload => {
144
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.BLUR_COMMAND, payload => {
146
145
  yjs.setLocalStateFocus(provider, name, color, false);
147
146
  return true;
148
- }, EditorPriority));
147
+ }, lexical.COMMAND_PRIORITY_EDITOR));
149
148
  }, [color, editor, name, provider]);
150
149
  }
151
150
  function useYjsHistory(editor, binding) {
@@ -162,10 +161,10 @@ function useYjsHistory(editor, binding) {
162
161
  return utils.mergeRegister(editor.registerCommand(lexical.UNDO_COMMAND, () => {
163
162
  undo();
164
163
  return true;
165
- }, EditorPriority), editor.registerCommand(lexical.REDO_COMMAND, () => {
164
+ }, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.REDO_COMMAND, () => {
166
165
  redo();
167
166
  return true;
168
- }, EditorPriority));
167
+ }, lexical.COMMAND_PRIORITY_EDITOR));
169
168
  });
170
169
  const clearHistory = React.useCallback(() => {
171
170
  undoManager.clear();
@@ -4,13 +4,13 @@
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 e=require("@lexical/react/LexicalComposerContext"),g=require("react"),m=require("@lexical/utils"),x=require("@lexical/yjs"),F=require("lexical"),G=require("react-dom");
8
- function H(b,c,a,d,k,p,q){const n=g.useRef(!1),[r,v]=g.useState(d.get(c)),f=g.useMemo(()=>x.createBinding(b,a,c,r,d),[b,a,c,d,r]),t=g.useCallback(()=>{a.connect()},[a]),u=g.useCallback(()=>{try{a.disconnect()}catch(l){}},[a]);g.useEffect(()=>{const {root:l}=f,{awareness:y}=a,z=({status:h})=>{b.dispatchCommand(x.CONNECTED_COMMAND,"connected"===h)},A=h=>{q&&h&&l.isEmpty()&&0===l._xmlText._length&&!1===n.current&&I(b);n.current=!1},B=()=>{x.syncCursorPositions(f,a)},C=(h,w)=>{w.origin!==f&&x.syncYjsChangesToLexical(f,
9
- a,h)};x.initLocalState(a,k,p,document.activeElement===b.getRootElement());const D=h=>{J(b,f);v(h);d.set(c,h);n.current=!0};a.on("reload",D);a.on("status",z);a.on("sync",A);y.on("update",B);l.getSharedType().observeDeep(C);const R=b.registerUpdateListener(({prevEditorState:h,editorState:w,dirtyLeaves:O,dirtyElements:P,normalizedNodes:Q,tags:E})=>{!1===E.has("skip-collab")&&x.syncLexicalUpdateToYjs(f,a,h,w,P,O,Q,E)});t();return()=>{!1===n.current&&u();a.off("sync",A);a.off("status",z);a.off("reload",
10
- D);y.off("update",B);l.getSharedType().unobserveDeep(C);R()}},[f,p,t,u,d,b,c,k,a,q]);const S=g.useMemo(()=>G.createPortal(g.createElement("div",{ref:l=>{f.cursorsContainer=l}}),document.body),[f]);g.useEffect(()=>b.registerCommand(x.TOGGLE_CONNECT_COMMAND,l=>{void 0!==t&&void 0!==u&&(l?(console.log("Collaboration connected!"),t()):(console.log("Collaboration disconnected!"),u()));return!0},0),[t,u,b]);return[S,f]}
11
- function K(b,c,a,d){g.useEffect(()=>m.mergeRegister(b.registerCommand(F.FOCUS_COMMAND,()=>{x.setLocalStateFocus(c,a,d,!0);return!0},0),b.registerCommand(F.BLUR_COMMAND,()=>{x.setLocalStateFocus(c,a,d,!1);return!0},0)),[d,b,a,c])}
12
- function L(b,c){const a=g.useMemo(()=>x.createUndoManager(c,c.root.getSharedType()),[c]);g.useEffect(()=>m.mergeRegister(b.registerCommand(F.UNDO_COMMAND,()=>{a.undo();return!0},0),b.registerCommand(F.REDO_COMMAND,()=>{a.redo();return!0},0)));return g.useCallback(()=>{a.clear()},[a])}
7
+ var e=require("@lexical/react/LexicalComposerContext"),f=require("react"),h=require("@lexical/utils"),x=require("@lexical/yjs"),F=require("lexical"),G=require("react-dom");
8
+ function H(b,c,a,d,l,p,q){const n=f.useRef(!1),[r,v]=f.useState(d.get(c)),g=f.useMemo(()=>x.createBinding(b,a,c,r,d),[b,a,c,d,r]),t=f.useCallback(()=>{a.connect()},[a]),u=f.useCallback(()=>{try{a.disconnect()}catch(m){}},[a]);f.useEffect(()=>{const {root:m}=g,{awareness:y}=a,z=({status:k})=>{b.dispatchCommand(x.CONNECTED_COMMAND,"connected"===k)},A=k=>{q&&k&&m.isEmpty()&&0===m._xmlText._length&&!1===n.current&&I(b);n.current=!1},B=()=>{x.syncCursorPositions(g,a)},C=(k,w)=>{w.origin!==g&&x.syncYjsChangesToLexical(g,
9
+ a,k)};x.initLocalState(a,l,p,document.activeElement===b.getRootElement());const D=k=>{J(b,g);v(k);d.set(c,k);n.current=!0};a.on("reload",D);a.on("status",z);a.on("sync",A);y.on("update",B);m.getSharedType().observeDeep(C);const R=b.registerUpdateListener(({prevEditorState:k,editorState:w,dirtyLeaves:O,dirtyElements:P,normalizedNodes:Q,tags:E})=>{!1===E.has("skip-collab")&&x.syncLexicalUpdateToYjs(g,a,k,w,P,O,Q,E)});t();return()=>{!1===n.current&&u();a.off("sync",A);a.off("status",z);a.off("reload",
10
+ D);y.off("update",B);m.getSharedType().unobserveDeep(C);R()}},[g,p,t,u,d,b,c,l,a,q]);const S=f.useMemo(()=>G.createPortal(f.createElement("div",{ref:m=>{g.cursorsContainer=m}}),document.body),[g]);f.useEffect(()=>b.registerCommand(x.TOGGLE_CONNECT_COMMAND,m=>{void 0!==t&&void 0!==u&&(m?(console.log("Collaboration connected!"),t()):(console.log("Collaboration disconnected!"),u()));return!0},F.COMMAND_PRIORITY_EDITOR),[t,u,b]);return[S,g]}
11
+ function K(b,c,a,d){f.useEffect(()=>h.mergeRegister(b.registerCommand(F.FOCUS_COMMAND,()=>{x.setLocalStateFocus(c,a,d,!0);return!0},F.COMMAND_PRIORITY_EDITOR),b.registerCommand(F.BLUR_COMMAND,()=>{x.setLocalStateFocus(c,a,d,!1);return!0},F.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
+ function L(b,c){const a=f.useMemo(()=>x.createUndoManager(c,c.root.getSharedType()),[c]);f.useEffect(()=>h.mergeRegister(b.registerCommand(F.UNDO_COMMAND,()=>{a.undo();return!0},F.COMMAND_PRIORITY_EDITOR),b.registerCommand(F.REDO_COMMAND,()=>{a.redo();return!0},F.COMMAND_PRIORITY_EDITOR)));return f.useCallback(()=>{a.clear()},[a])}
13
13
  function I(b){b.update(()=>{var c=F.$getRoot();if(null===c.getFirstChild()){const a=F.$createParagraphNode();c.append(a);c=document.activeElement;(null!==F.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}},{tag:"history-merge"})}
14
- function J(b,c){b.update(()=>{const d=F.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursorsContainer,null!=b)){c=Array.from(c.cursors.values());for(let d=0;d<c.length;d++){var a=c[d].selection;if(a&&null!=a.selections){a=a.selections;for(let k=0;k<a.length;k++)b.removeChild(a[d])}}}}
15
- const M=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],N=M[Math.floor(Math.random()*M.length)],T=g.createContext({clientID:0,color:N[1],name:N[0],yjsDocMap:new Map});
16
- function U(b){const c=g.useContext(T);null!=b&&(c.name=b);return c}exports.CollaborationContext=T;exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d}){d=U(d);const {yjsDocMap:k,name:p,color:q}=d,[n]=e.useLexicalComposerContext(),r=g.useMemo(()=>c(b,k),[b,c,k]),[v,f]=H(n,b,r,k,p,q,a);d.clientID=f.clientID;L(n,f);K(n,r,p,q);return v};exports.useCollaborationContext=U;
14
+ function J(b,c){b.update(()=>{const d=F.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursorsContainer,null!=b)){c=Array.from(c.cursors.values());for(let d=0;d<c.length;d++){var a=c[d].selection;if(a&&null!=a.selections){a=a.selections;for(let l=0;l<a.length;l++)b.removeChild(a[d])}}}}
15
+ const M=[["Cat","255,165,0"],["Dog","0,200,55"],["Rabbit","160,0,200"],["Frog","0,172,200"],["Fox","197,200,0"],["Hedgehog","31,200,0"],["Pigeon","200,0,0"],["Squirrel","200,0,148"],["Bear","255,235,0"],["Tiger","86,255,0"],["Leopard","0,255,208"],["Zebra","0,243,255"],["Wolf","0,102,255"],["Owl","147,0,255"],["Gull","255,0,153"],["Squid","0,220,255"]],N=M[Math.floor(Math.random()*M.length)],T=f.createContext({clientID:0,color:N[1],name:N[0],yjsDocMap:new Map});
16
+ function U(b){const c=f.useContext(T);null!=b&&(c.name=b);return c}exports.CollaborationContext=T;exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d}){d=U(d);const {yjsDocMap:l,name:p,color:q}=d,[n]=e.useLexicalComposerContext(),r=f.useMemo(()=>c(b,l),[b,c,l]),[v,g]=H(n,b,r,l,p,q,a);d.clientID=g.clientID;L(n,g);K(n,r,p,q);return v};exports.useCollaborationContext=U;
@@ -0,0 +1,43 @@
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 lexical = require('lexical');
10
+
11
+ /**
12
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
13
+ *
14
+ * This source code is licensed under the MIT license found in the
15
+ * LICENSE file in the root directory of this source tree.
16
+ *
17
+ *
18
+ */
19
+ class DecoratorBlockNode extends lexical.DecoratorNode {
20
+ createDOM() {
21
+ return document.createElement('div');
22
+ }
23
+
24
+ updateDOM() {
25
+ return false;
26
+ }
27
+
28
+ setFormat(format) {
29
+ const self = this.getWritable();
30
+ self.__format = format;
31
+ }
32
+
33
+ }
34
+ function $createDecoratorBlockNode() {
35
+ return new DecoratorBlockNode();
36
+ }
37
+ function $isDecoratorBlockNode(node) {
38
+ return node instanceof DecoratorBlockNode;
39
+ }
40
+
41
+ exports.$createDecoratorBlockNode = $createDecoratorBlockNode;
42
+ exports.$isDecoratorBlockNode = $isDecoratorBlockNode;
43
+ exports.DecoratorBlockNode = DecoratorBlockNode;
@@ -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 LexicalDecoratorBlockNode = process.env.NODE_ENV === 'development' ? require('./LexicalDecoratorBlockNode.dev.js') : require('./LexicalDecoratorBlockNode.prod.js')
9
+ module.exports = LexicalDecoratorBlockNode;
@@ -0,0 +1,23 @@
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 {ElementFormatType, LexicalNode, LexicalCommand} from 'lexical';
11
+
12
+ import {DecoratorNode} from 'lexical';
13
+
14
+ declare export class DecoratorBlockNode<T> extends DecoratorNode<T> {
15
+ __format: ?ElementFormatType;
16
+ createDOM(): HTMLElement;
17
+ setFormat(format: ElementFormatType): void;
18
+ }
19
+
20
+ declare export function $createDecoratorBlockNode<T>(): DecoratorBlockNode<T>;
21
+ declare export function $isDecoratorBlockNode(
22
+ node: ?LexicalNode,
23
+ ): boolean %checks(node instanceof DecoratorBlockNode);
@@ -0,0 +1,7 @@
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 a=require("lexical");class c extends a.DecoratorNode{createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(b){this.getWritable().__format=b}}exports.$createDecoratorBlockNode=function(){return new c};exports.$isDecoratorBlockNode=function(b){return b instanceof c};exports.DecoratorBlockNode=c;
@@ -9,8 +9,8 @@
9
9
  import type {LexicalNode, LexicalCommand} from 'lexical';
10
10
  import {DecoratorNode} from 'lexical';
11
11
  export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element | null> {
12
- getType(): string;
13
- clone(node: HorizontalRuleNode): HorizontalRuleNode;
12
+ static getType(): string;
13
+ static clone(node: HorizontalRuleNode): HorizontalRuleNode;
14
14
  createDOM(): HTMLElement;
15
15
  getTextContent(): '\n';
16
16
  isTopLevel(): true;
@@ -20,6 +20,6 @@ export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element | null
20
20
  export function $createHorizontalRuleNode(): HorizontalRuleNode;
21
21
  export function $isHorizontalRuleNode(
22
22
  node: LexicalNode | null | undefined,
23
- ): boolean;
23
+ ): node is HorizontalRuleNode;
24
24
 
25
25
  export var INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void>;
@@ -19,7 +19,6 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- const EditorPriority = 0;
23
22
 
24
23
  function toggleLink(url) {
25
24
  const selection = lexical.$getSelection();
@@ -127,7 +126,7 @@ function LinkPlugin() {
127
126
  const url = payload;
128
127
  toggleLink(url);
129
128
  return true;
130
- }, EditorPriority);
129
+ }, lexical.COMMAND_PRIORITY_EDITOR);
131
130
  }, [editor]);
132
131
  return null;
133
132
  }
@@ -7,4 +7,4 @@
7
7
  var g=require("@lexical/link"),k=require("@lexical/react/LexicalComposerContext"),m=require("lexical"),n=require("react");
8
8
  function p(e){var b=m.$getSelection();null!==b&&m.$setSelection(b);b=m.$getSelection();if(null!==b)if(b=b.extract(),null===e)b.forEach(f=>{f=f.getParent();if(g.$isLinkNode(f)){const c=f.getChildren();for(let a=0;a<c.length;a++)f.insertBefore(c[a]);f.remove()}});else{if(1===b.length){var h=b[0];if(g.$isLinkNode(h)){h.setURL(e);return}h=h.getParent();if(g.$isLinkNode(h)){h.setURL(e);return}}let f=null,c=null;b.forEach(a=>{var d=a.getParent();if(d!==c&&null!==d&&(!m.$isElementNode(a)||a.isInline()))if(d.is(f)||
9
9
  (f=d,c=g.$createLinkNode(e),g.$isLinkNode(d)?null===a.getPreviousSibling()?d.insertBefore(c):d.insertAfter(c):a.insertBefore(c)),g.$isLinkNode(a)){if(null!==c){d=a.getChildren();for(let l=0;l<d.length;l++)c.append(d[l])}a.remove()}else null!==c&&c.append(a)})}}
10
- module.exports=function(){const [e]=k.useLexicalComposerContext();n.useEffect(()=>{if(!e.hasNodes([g.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");},[e]);n.useEffect(()=>e.registerCommand(g.TOGGLE_LINK_COMMAND,b=>{p(b);return!0},0),[e]);return null};
10
+ module.exports=function(){const [e]=k.useLexicalComposerContext();n.useEffect(()=>{if(!e.hasNodes([g.LinkNode]))throw Error("LinkPlugin: LinkNode not registered on editor");},[e]);n.useEffect(()=>e.registerCommand(g.TOGGLE_LINK_COMMAND,b=>{p(b);return!0},m.COMMAND_PRIORITY_EDITOR),[e]);return null};
@@ -20,7 +20,6 @@ var react = require('react');
20
20
  *
21
21
  *
22
22
  */
23
- const LowPriority = 1;
24
23
  function useList(editor) {
25
24
  react.useEffect(() => {
26
25
  return utils.mergeRegister(editor.registerCommand(lexical.INDENT_CONTENT_COMMAND, () => {
@@ -31,7 +30,7 @@ function useList(editor) {
31
30
  }
32
31
 
33
32
  return false;
34
- }, LowPriority), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
33
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.OUTDENT_CONTENT_COMMAND, () => {
35
34
  const hasHandledIndention = list.outdentList();
36
35
 
37
36
  if (hasHandledIndention) {
@@ -39,16 +38,16 @@ function useList(editor) {
39
38
  }
40
39
 
41
40
  return false;
42
- }, LowPriority), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
41
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_ORDERED_LIST_COMMAND, () => {
43
42
  list.insertList(editor, 'ol');
44
43
  return true;
45
- }, LowPriority), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
44
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.INSERT_UNORDERED_LIST_COMMAND, () => {
46
45
  list.insertList(editor, 'ul');
47
46
  return true;
48
- }, LowPriority), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
47
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(list.REMOVE_LIST_COMMAND, () => {
49
48
  list.removeList(editor);
50
49
  return true;
51
- }, LowPriority), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
50
+ }, lexical.COMMAND_PRIORITY_LOW), editor.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND, () => {
52
51
  const hasHandledInsertParagraph = list.$handleListInsertParagraph();
53
52
 
54
53
  if (hasHandledInsertParagraph) {
@@ -56,7 +55,7 @@ function useList(editor) {
56
55
  }
57
56
 
58
57
  return false;
59
- }, LowPriority));
58
+ }, lexical.COMMAND_PRIORITY_LOW));
60
59
  }, [editor]);
61
60
  }
62
61
 
@@ -5,5 +5,5 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  var b=require("@lexical/react/LexicalComposerContext"),c=require("@lexical/list"),d=require("@lexical/utils"),e=require("lexical"),f=require("react");
8
- function g(a){f.useEffect(()=>d.mergeRegister(a.registerCommand(e.INDENT_CONTENT_COMMAND,()=>c.indentList()?!0:!1,1),a.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>c.outdentList()?!0:!1,1),a.registerCommand(c.INSERT_ORDERED_LIST_COMMAND,()=>{c.insertList(a,"ol");return!0},1),a.registerCommand(c.INSERT_UNORDERED_LIST_COMMAND,()=>{c.insertList(a,"ul");return!0},1),a.registerCommand(c.REMOVE_LIST_COMMAND,()=>{c.removeList(a);return!0},1),a.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>c.$handleListInsertParagraph()?
9
- !0:!1,1)),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();g(a);return null};
8
+ function g(a){f.useEffect(()=>d.mergeRegister(a.registerCommand(e.INDENT_CONTENT_COMMAND,()=>c.indentList()?!0:!1,e.COMMAND_PRIORITY_LOW),a.registerCommand(e.OUTDENT_CONTENT_COMMAND,()=>c.outdentList()?!0:!1,e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_ORDERED_LIST_COMMAND,()=>{c.insertList(a,"ol");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.INSERT_UNORDERED_LIST_COMMAND,()=>{c.insertList(a,"ul");return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(c.REMOVE_LIST_COMMAND,()=>{c.removeList(a);
9
+ return!0},e.COMMAND_PRIORITY_LOW),a.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>c.$handleListInsertParagraph()?!0:!1,e.COMMAND_PRIORITY_LOW)),[a])}module.exports=function(){const [a]=b.useLexicalComposerContext();g(a);return null};
@@ -6,6 +6,7 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
+ var LexicalCollaborationPlugin = require('@lexical/react/LexicalCollaborationPlugin');
9
10
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
10
11
  var React = require('react');
11
12
 
@@ -44,10 +45,17 @@ function LexicalNestedComposer({
44
45
  return [initialEditor, context];
45
46
  }, // We only do this for init
46
47
  // eslint-disable-next-line react-hooks/exhaustive-deps
47
- []);
48
+ []); // If collaboration is enabled, make sure we don't render the children
49
+ // until the collaboration subdocument is ready.
50
+
51
+ const {
52
+ yjsDocMap
53
+ } = LexicalCollaborationPlugin.useCollaborationContext();
54
+ const isCollab = yjsDocMap.get('main') !== undefined;
55
+ const isCollabReady = yjsDocMap.has(initialEditor.getKey());
48
56
  return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
49
57
  value: composerContext
50
- }, children);
58
+ }, !isCollab || isCollabReady ? children : null);
51
59
  }
52
60
 
53
61
  module.exports = LexicalNestedComposer;
@@ -4,6 +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
- var b=require("@lexical/react/LexicalComposerContext"),c=require("react");
8
- module.exports=function({initialEditor:a,children:g,initialTheme:h}){const d=c.useContext(b.LexicalComposerContext);if(null==d)throw Error("Minified Lexical error #72; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const m=c.useMemo(()=>{const [f,k]=d,e=h||k.getTheme()||void 0,l=b.createLexicalComposerContext(d,e);void 0!==e&&(a._config.theme=e);a._parentEditor=f;a._nodes=f._nodes;return[a,l]},[]);return c.createElement(b.LexicalComposerContext.Provider,
9
- {value:m},g)};
7
+ var c=require("@lexical/react/LexicalCollaborationPlugin"),d=require("@lexical/react/LexicalComposerContext"),h=require("react");
8
+ module.exports=function({initialEditor:a,children:k,initialTheme:l}){const e=h.useContext(d.LexicalComposerContext);if(null==e)throw Error("Minified Lexical error #72; see codes.json for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");const p=h.useMemo(()=>{const [g,m]=e,f=l||m.getTheme()||void 0,n=d.createLexicalComposerContext(e,f);void 0!==f&&(a._config.theme=f);a._parentEditor=g;a._nodes=g._nodes;return[a,n]},[]);var {yjsDocMap:b}=c.useCollaborationContext();
9
+ const q=void 0!==b.get("main");b=b.has(a.getKey());return h.createElement(d.LexicalComposerContext.Provider,{value:p},!q||b?k:null)};
@@ -19,7 +19,6 @@ var react = require('react');
19
19
  *
20
20
  *
21
21
  */
22
- const EditorPriority = 0;
23
22
  function TablePlugin() {
24
23
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
25
24
  react.useEffect(() => {
@@ -67,7 +66,7 @@ function TablePlugin() {
67
66
  }
68
67
 
69
68
  return true;
70
- }, EditorPriority);
69
+ }, lexical.COMMAND_PRIORITY_EDITOR);
71
70
  }, [editor]);
72
71
  react.useEffect(() => {
73
72
  const tableSelections = new Map();
@@ -4,7 +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 e=require("@lexical/react/LexicalComposerContext"),g=require("@lexical/table"),k=require("lexical"),m=require("react");
8
- module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.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 c.registerCommand(g.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:f}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=g.$createTableNodeWithDimensions(Number(f),
9
- Number(h));k.$isRootNode(a)?(d=a.getChildAtIndex(d.offset),null!==d?d.insertBefore(b):a.append(b),b.insertBefore(k.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b);b.insertAfter(k.$createParagraphNode());b.getFirstChildOrThrow().getFirstChildOrThrow().select()}return!0},0)},[c]);m.useEffect(()=>{const a=new Map;return c.registerMutationListener(g.TableNode,h=>{for(const [f,d]of h)"created"===d?c.update(()=>{var b=c.getElementByKey(f);const l=k.$getNodeByKey(f);b&&l&&(b=g.applyTableHandlers(l,
10
- b,c),a.set(f,b))}):"destroyed"===d&&(h=a.get(f))&&(h.removeListeners(),a.delete(f))})},[c]);return null};
7
+ var e=require("@lexical/react/LexicalComposerContext"),f=require("@lexical/table"),k=require("lexical"),m=require("react");
8
+ module.exports=function(){const [c]=e.useLexicalComposerContext();m.useEffect(()=>{if(!c.hasNodes([f.TableNode,f.TableCellNode,f.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 c.registerCommand(f.INSERT_TABLE_COMMAND,a=>{const {columns:h,rows:g}=a;a=k.$getSelection();if(!k.$isRangeSelection(a))return!0;var d=a.focus;a=d.getNode();if(null!==a){const b=f.$createTableNodeWithDimensions(Number(g),
9
+ Number(h));k.$isRootNode(a)?(d=a.getChildAtIndex(d.offset),null!==d?d.insertBefore(b):a.append(b),b.insertBefore(k.$createParagraphNode())):a.getTopLevelElementOrThrow().insertAfter(b);b.insertAfter(k.$createParagraphNode());b.getFirstChildOrThrow().getFirstChildOrThrow().select()}return!0},k.COMMAND_PRIORITY_EDITOR)},[c]);m.useEffect(()=>{const a=new Map;return c.registerMutationListener(f.TableNode,h=>{for(const [g,d]of h)"created"===d?c.update(()=>{var b=c.getElementByKey(g);const l=k.$getNodeByKey(g);
10
+ b&&l&&(b=f.applyTableHandlers(l,b,c),a.set(g,b))}):"destroyed"===d&&(h=a.get(g))&&(h.removeListeners(),a.delete(g))})},[c]);return null};
package/package.json CHANGED
@@ -8,27 +8,27 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.2.1",
11
+ "version": "0.2.4",
12
12
  "dependencies": {
13
- "@lexical/clipboard": "0.2.1",
14
- "@lexical/list": "0.2.1",
15
- "@lexical/table": "0.2.1",
16
- "@lexical/yjs": "0.2.1",
17
- "@lexical/hashtag": "0.2.1",
18
- "@lexical/selection": "0.2.1",
19
- "@lexical/utils": "0.2.1",
20
- "@lexical/dragon": "0.2.1",
21
- "@lexical/plain-text": "0.2.1",
22
- "@lexical/rich-text": "0.2.1",
23
- "@lexical/code": "0.2.1",
24
- "@lexical/text": "0.2.1",
25
- "@lexical/link": "0.2.1",
26
- "@lexical/overflow": "0.2.1",
27
- "@lexical/history": "0.2.1",
28
- "@lexical/markdown": "0.2.1"
13
+ "@lexical/clipboard": "0.2.4",
14
+ "@lexical/list": "0.2.4",
15
+ "@lexical/table": "0.2.4",
16
+ "@lexical/yjs": "0.2.4",
17
+ "@lexical/hashtag": "0.2.4",
18
+ "@lexical/selection": "0.2.4",
19
+ "@lexical/utils": "0.2.4",
20
+ "@lexical/dragon": "0.2.4",
21
+ "@lexical/plain-text": "0.2.4",
22
+ "@lexical/rich-text": "0.2.4",
23
+ "@lexical/code": "0.2.4",
24
+ "@lexical/text": "0.2.4",
25
+ "@lexical/link": "0.2.4",
26
+ "@lexical/overflow": "0.2.4",
27
+ "@lexical/history": "0.2.4",
28
+ "@lexical/markdown": "0.2.4"
29
29
  },
30
30
  "peerDependencies": {
31
- "lexical": "0.2.1",
31
+ "lexical": "0.2.4",
32
32
  "react": ">=17.x",
33
33
  "react-dom": ">=17.x"
34
34
  },