@lexical/react 0.1.12 → 0.1.13
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.
- package/LexicalCollaborationPlugin.dev.js +0 -2
- package/LexicalCollaborationPlugin.prod.js +5 -5
- package/LexicalComposer.d.ts +1 -1
- package/LexicalComposer.dev.js +1 -1
- package/LexicalComposer.js.flow +3 -3
- package/LexicalComposer.prod.js +1 -1
- package/LexicalNestedComposer.d.ts +4 -7
- package/LexicalNestedComposer.dev.js +21 -11
- package/LexicalNestedComposer.js.flow +3 -6
- package/LexicalNestedComposer.prod.js +3 -2
- package/package.json +9 -6
|
@@ -32,7 +32,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
32
32
|
} catch (e) {// Do nothing
|
|
33
33
|
}
|
|
34
34
|
}, [provider]);
|
|
35
|
-
const bootstrapPropagationRef = React.useRef(true);
|
|
36
35
|
React.useEffect(() => {
|
|
37
36
|
const {
|
|
38
37
|
root
|
|
@@ -49,7 +48,6 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
49
48
|
|
|
50
49
|
const onSync = isSynced => {
|
|
51
50
|
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0) {
|
|
52
|
-
bootstrapPropagationRef.current = false;
|
|
53
51
|
initializeEditor(editor);
|
|
54
52
|
}
|
|
55
53
|
};
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
var d=require("@lexical/react/LexicalComposerContext"),g=require("react"),u=require("@lexical/yjs"),A=require("lexical"),B=require("react-dom");
|
|
8
|
-
function C(b,c,a,h,n,p,q){const e=g.useMemo(()=>u.createBinding(b,a,c,h),[b,a,c,h]),k=g.useCallback(()=>{a.connect()},[a]),l=g.useCallback(()=>{try{a.disconnect()}catch(f){}},[a])
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
function C(b,c,a,h,n,p,q){const e=g.useMemo(()=>u.createBinding(b,a,c,h),[b,a,c,h]),k=g.useCallback(()=>{a.connect()},[a]),l=g.useCallback(()=>{try{a.disconnect()}catch(f){}},[a]);g.useEffect(()=>{const {root:f}=e,{awareness:r}=a,w=({status:m})=>{b.execCommand("connected","connected"===m)},x=m=>{q&&m&&f.isEmpty()&&0===f._xmlText._length&&D(b)},y=()=>{u.syncCursorPositions(e,a)},z=(m,v)=>{v.origin!==e&&u.syncYjsChangesToLexical(e,a,m)};u.initLocalState(a,n,p,document.activeElement===b.getRootElement());
|
|
9
|
+
a.on("status",w);a.on("sync",x);r.on("update",y);f.getSharedType().observeDeep(z);const M=b.addListener("update",({prevEditorState:m,editorState:v,dirtyLeaves:I,dirtyElements:J,normalizedNodes:K,tags:L})=>{u.syncLexicalUpdateToYjs(e,a,m,v,J,I,K,L)});k();return()=>{l();a.off("sync",x);a.off("status",w);r.off("update",y);f.getSharedType().unobserveDeep(z);M()}},[e,p,k,l,b,n,a,q]);const t=g.useMemo(()=>B.createPortal(g.createElement("div",{ref:f=>{e.cursorsContainer=f}}),document.body),[e]);g.useEffect(()=>
|
|
10
|
+
b.addListener("command",(f,r)=>{"toggleConnect"===f&&void 0!==k&&void 0!==l&&(r?(console.log("Collaboration connected!"),k()):(console.log("Collaboration disconnected!"),l()));return!1},0),[k,l,b]);return[t,e]}function E(b,c){g.useEffect(()=>b.addListener("command",a=>{"focus"===a?u.setLocalStateFocus(c,!0):"blur"===a&&u.setLocalStateFocus(c,!1);return!1},0),[b,c])}
|
|
11
11
|
function F(b,c){const a=g.useMemo(()=>u.createUndoManager(c,c.root.getSharedType()),[c]);g.useEffect(()=>b.addListener("command",h=>"undo"===h?(a.undo(),!0):"redo"===h?(a.redo(),!0):!1,0));return g.useCallback(()=>{a.clear()},[a])}function D(b){b.update(()=>{var c=A.$getRoot();if(null===c.getFirstChild()){const a=A.$createParagraphNode();c.append(a);c=document.activeElement;(null!==A.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}},{tag:"history-merge"})}
|
|
12
|
-
const G=[["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"]],H=G[Math.floor(Math.random()*(G.length-1+1))],
|
|
13
|
-
function
|
|
12
|
+
const G=[["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"]],H=G[Math.floor(Math.random()*(G.length-1+1))],N=g.createContext({clientID:0,color:H[1],name:H[0],yjsDocMap:new Map});
|
|
13
|
+
function O(){return g.useContext(N)}exports.CollaborationContext=N;exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a}){const h=O(),{yjsDocMap:n,name:p,color:q}=h,[e]=d.useLexicalComposerContext(),k=g.useMemo(()=>c(b,n),[b,c,n]),[l,t]=C(e,b,k,n,p,q,a);h.clientID=t.clientID;F(e,t);E(e,k);return l};exports.useCollaborationContext=O;
|
package/LexicalComposer.d.ts
CHANGED
package/LexicalComposer.dev.js
CHANGED
package/LexicalComposer.js.flow
CHANGED
|
@@ -10,14 +10,14 @@
|
|
|
10
10
|
import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
|
|
11
11
|
|
|
12
12
|
type Props = {
|
|
13
|
-
initialConfig
|
|
13
|
+
initialConfig: $ReadOnly<{
|
|
14
14
|
editor?: LexicalEditor | null,
|
|
15
15
|
isReadOnly?: boolean,
|
|
16
16
|
namespace?: string,
|
|
17
|
-
nodes?:
|
|
17
|
+
nodes?: $ReadOnlyArray<Class<LexicalNode>>,
|
|
18
18
|
theme?: EditorThemeClasses,
|
|
19
19
|
onError: (error: Error, editor: LexicalEditor) => void,
|
|
20
|
-
}
|
|
20
|
+
}>,
|
|
21
21
|
children: React$Node,
|
|
22
22
|
};
|
|
23
23
|
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -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"),f=require("lexical"),n=require("react"),p="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?n.useLayoutEffect:n.useEffect;
|
|
8
|
-
module.exports=function({initialConfig:h
|
|
8
|
+
module.exports=function({initialConfig:h,children:q}){const d=n.useContext(b.LexicalComposerContext),m=n.useMemo(()=>{let a,e;const {theme:k,namespace:r,editor:t,nodes:u,onError:v}=h;if(null!=k)a=k;else if(null!=d){e=d[0];var c=d[1].getTheme();null!=c&&(a=c)}c=b.createLexicalComposerContext(d,a);let g=t||null;if(null===g){const l=f.createEditor({context:c,namespace:r,nodes:u,onError:w=>v(w,l),parentEditor:e,readOnly:!0,theme:a});g=l}return[g,c]},[]);p(()=>{const a=h.readOnly,[e]=m;e.setReadOnly(a||
|
|
9
9
|
!1)},[]);return n.createElement(b.LexicalComposerContext.Provider,{value:m},q)};
|
|
@@ -6,15 +6,12 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
|
|
9
|
+
import type {DecoratorEditor, EditorThemeClasses} from 'lexical';
|
|
10
|
+
|
|
11
11
|
export default function LexicalNestedComposer(arg0: {
|
|
12
|
-
initialConfig
|
|
13
|
-
namespace?: string;
|
|
12
|
+
initialConfig: {
|
|
14
13
|
decoratorEditor: DecoratorEditor;
|
|
15
|
-
nodes?: Array<Class<LexicalNode>>;
|
|
16
14
|
theme?: EditorThemeClasses;
|
|
17
|
-
onError?: (arg0: Error) => void;
|
|
18
15
|
};
|
|
19
|
-
children
|
|
16
|
+
children: React.ReactNode;
|
|
20
17
|
}): React.ReactNode;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var LexicalComposer = require('@lexical/react/LexicalComposer');
|
|
10
|
+
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
|
|
10
11
|
var LexicalOnChangePlugin = require('@lexical/react/LexicalOnChangePlugin');
|
|
11
12
|
var React = require('react');
|
|
12
13
|
|
|
@@ -22,13 +23,18 @@ function LexicalNestedComposer({
|
|
|
22
23
|
initialConfig = {},
|
|
23
24
|
children
|
|
24
25
|
}) {
|
|
26
|
+
const parentContext = React.useContext(LexicalComposerContext.LexicalComposerContext);
|
|
27
|
+
|
|
28
|
+
if (parentContext == null) {
|
|
29
|
+
{
|
|
30
|
+
throw Error(`Unexpected parent context null on a nested composer`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
25
34
|
const [nestedEditor, setNestedEditor] = React.useState(null);
|
|
26
35
|
const {
|
|
27
36
|
decoratorEditor,
|
|
28
|
-
|
|
29
|
-
theme,
|
|
30
|
-
nodes,
|
|
31
|
-
onError
|
|
37
|
+
theme
|
|
32
38
|
} = initialConfig;
|
|
33
39
|
React.useEffect(() => {
|
|
34
40
|
if (!decoratorEditor.isEmpty() && nestedEditor !== null) {
|
|
@@ -45,13 +51,17 @@ function LexicalNestedComposer({
|
|
|
45
51
|
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
46
52
|
[]);
|
|
47
53
|
return /*#__PURE__*/React.createElement(LexicalComposer, {
|
|
48
|
-
initialConfig: {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
initialConfig: React.useMemo(() => {
|
|
55
|
+
const [parentEditor] = parentContext;
|
|
56
|
+
return {
|
|
57
|
+
editor: decoratorEditor.editor,
|
|
58
|
+
namespace: parentEditor._config.namespace,
|
|
59
|
+
nodes: Array.from(parentEditor._nodes.values()).map(registeredNode => registeredNode.klass),
|
|
60
|
+
onError: parentEditor._onError,
|
|
61
|
+
theme
|
|
62
|
+
}; // We only do this for init
|
|
63
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
+
}, [])
|
|
55
65
|
}, /*#__PURE__*/React.createElement(LexicalOnChangePlugin, {
|
|
56
66
|
onChange: onChange
|
|
57
67
|
}), children);
|
|
@@ -10,12 +10,9 @@
|
|
|
10
10
|
import type {DecoratorEditor, EditorThemeClasses, LexicalNode} from 'lexical';
|
|
11
11
|
|
|
12
12
|
declare export default function LexicalNestedComposer({
|
|
13
|
-
initialConfig
|
|
14
|
-
namespace?: string,
|
|
13
|
+
initialConfig: $ReadOnly<{
|
|
15
14
|
decoratorEditor: DecoratorEditor,
|
|
16
|
-
nodes?: Array<Class<LexicalNode>>,
|
|
17
15
|
theme?: EditorThemeClasses,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
children?: React$Node,
|
|
16
|
+
}>,
|
|
17
|
+
children: React$Node,
|
|
21
18
|
}): React$Node;
|
|
@@ -4,5 +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 a=require("@lexical/react/LexicalComposer"),
|
|
8
|
-
module.exports=function({initialConfig:
|
|
7
|
+
var a=require("@lexical/react/LexicalComposer"),h=require("@lexical/react/LexicalComposerContext"),k=require("@lexical/react/LexicalOnChangePlugin"),l=require("react");
|
|
8
|
+
module.exports=function({initialConfig:e={},children:m}){const g=l.useContext(h.LexicalComposerContext);if(null==g)throw Error("Unexpected parent context null on a nested composer");const [f,n]=l.useState(null),{decoratorEditor:c,theme:p}=e;l.useEffect(()=>{c.isEmpty()||null===f||c.init(f)},[f]);e=l.useCallback((b,d)=>{b.isEmpty()?n(d):c.set(d)},[]);return l.createElement(a,{initialConfig:l.useMemo(()=>{const [b]=g;return{editor:c.editor,namespace:b._config.namespace,nodes:Array.from(b._nodes.values()).map(d=>
|
|
9
|
+
d.klass),onError:b._onError,theme:p}},[])},l.createElement(k,{onChange:e}),m)};
|
package/package.json
CHANGED
|
@@ -12,13 +12,16 @@
|
|
|
12
12
|
"rich-text"
|
|
13
13
|
],
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
15
|
+
"version": "0.1.13",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lexical/helpers": "0.1.13",
|
|
18
|
+
"@lexical/clipboard": "0.1.13",
|
|
19
|
+
"@lexical/list": "0.1.13",
|
|
20
|
+
"@lexical/table": "0.1.13",
|
|
21
|
+
"@lexical/yjs": "0.1.13"
|
|
22
|
+
},
|
|
16
23
|
"peerDependencies": {
|
|
17
|
-
"lexical": "0.1.
|
|
18
|
-
"@lexical/helpers": "0.1.12",
|
|
19
|
-
"@lexical/table": "0.1.12",
|
|
20
|
-
"@lexical/yjs": "0.1.12",
|
|
21
|
-
"@lexical/clipboard": "0.1.12",
|
|
24
|
+
"lexical": "0.1.13",
|
|
22
25
|
"react": ">=17.x",
|
|
23
26
|
"react-dom": ">=17.x"
|
|
24
27
|
},
|