@lexical/react 0.4.1 → 0.5.1-next.0
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/DEPRECATED_useLexical.js.flow +0 -1
- package/DEPRECATED_useLexicalDecorators.d.ts +2 -1
- package/DEPRECATED_useLexicalDecorators.dev.js +125 -10
- package/DEPRECATED_useLexicalDecorators.js.flow +8 -0
- package/DEPRECATED_useLexicalDecorators.prod.js +6 -2
- package/DEPRECATED_useLexicalPlainText.d.ts +2 -2
- package/DEPRECATED_useLexicalPlainText.dev.js +4 -4
- package/DEPRECATED_useLexicalPlainText.js.flow +0 -1
- package/DEPRECATED_useLexicalPlainText.prod.js +2 -2
- package/DEPRECATED_useLexicalRichText.d.ts +2 -2
- package/DEPRECATED_useLexicalRichText.dev.js +4 -4
- package/DEPRECATED_useLexicalRichText.js.flow +0 -1
- package/DEPRECATED_useLexicalRichText.prod.js +2 -2
- package/LexicalAutoEmbedPlugin.d.ts +3 -13
- package/LexicalAutoEmbedPlugin.dev.js +3 -19
- package/LexicalAutoEmbedPlugin.js.flow +3 -11
- package/LexicalAutoEmbedPlugin.prod.js +4 -5
- package/LexicalAutoLinkPlugin.dev.js +49 -45
- package/LexicalAutoLinkPlugin.prod.js +6 -6
- package/LexicalBlockWithAlignableContents.dev.js +1 -1
- package/LexicalBlockWithAlignableContents.prod.js +1 -1
- package/LexicalCollaborationPlugin.d.ts +5 -1
- package/LexicalCollaborationPlugin.dev.js +54 -16
- package/LexicalCollaborationPlugin.js.flow +1 -0
- package/LexicalCollaborationPlugin.prod.js +9 -9
- package/LexicalComposer.d.ts +1 -2
- package/LexicalComposer.dev.js +15 -1
- package/LexicalComposer.js.flow +14 -7
- package/LexicalComposer.prod.js +3 -3
- package/LexicalContentEditable.dev.js +1 -1
- package/LexicalContentEditable.prod.js +1 -1
- package/LexicalHorizontalRuleNode.d.ts +4 -2
- package/LexicalHorizontalRuleNode.dev.js +25 -3
- package/LexicalHorizontalRuleNode.js.flow +0 -1
- package/LexicalHorizontalRuleNode.prod.js +5 -5
- package/LexicalNestedComposer.d.ts +4 -2
- package/LexicalNestedComposer.dev.js +25 -3
- package/LexicalNestedComposer.js.flow +1 -0
- package/LexicalNestedComposer.prod.js +3 -3
- package/LexicalOnChangePlugin.d.ts +1 -2
- package/LexicalOnChangePlugin.dev.js +3 -9
- package/LexicalOnChangePlugin.js.flow +0 -2
- package/LexicalOnChangePlugin.prod.js +2 -2
- package/LexicalPlainTextPlugin.d.ts +3 -3
- package/LexicalPlainTextPlugin.dev.js +111 -20
- package/LexicalPlainTextPlugin.js.flow +3 -1
- package/LexicalPlainTextPlugin.prod.js +6 -4
- package/LexicalRichTextPlugin.d.ts +3 -3
- package/LexicalRichTextPlugin.dev.js +111 -20
- package/LexicalRichTextPlugin.js.flow +3 -1
- package/LexicalRichTextPlugin.prod.js +6 -4
- package/LexicalTableOfContents__EXPERIMENTAL.js.flow +1 -1
- package/LexicalTablePlugin.dev.js +1 -1
- package/LexicalTablePlugin.prod.js +1 -1
- package/LexicalTreeView.dev.js +28 -13
- package/LexicalTreeView.prod.js +14 -13
- package/LexicalTypeaheadMenuPlugin.d.ts +20 -8
- package/LexicalTypeaheadMenuPlugin.dev.js +200 -57
- package/LexicalTypeaheadMenuPlugin.js.flow +19 -21
- package/LexicalTypeaheadMenuPlugin.prod.js +18 -14
- package/package.json +19 -19
- package/shared/ReactErrorBoundary.d.ts +63 -0
- package/shared/useDecorators.d.ts +8 -1
- package/shared/usePlainTextSetup.d.ts +1 -2
- package/shared/useRichTextSetup.d.ts +1 -2
- package/shared/useYjsCollaboration.d.ts +4 -1
|
@@ -4,9 +4,9 @@
|
|
|
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 h=require("@lexical/link"),l=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
'use strict';var h=require("@lexical/link"),l=require("@lexical/react/LexicalComposerContext"),m=require("@lexical/utils"),q=require("lexical"),y=require("react");function z(b,e){for(let c=0;c<e.length;c++){let a=e[c](b);if(a)return a}return null}let A=/[.,;\s]/;function C(b){b=b.getPreviousSibling();q.$isElementNode(b)&&(b=b.getLastDescendant());var e;!(e=null===b||q.$isLineBreakNode(b))&&(e=q.$isTextNode(b))&&(b=b.getTextContent(),e=A.test(b[b.length-1]));return e}
|
|
8
|
+
function D(b){b=b.getNextSibling();q.$isElementNode(b)&&(b=b.getFirstDescendant());return null===b||q.$isLineBreakNode(b)||q.$isTextNode(b)&&A.test(b.getTextContent()[0])}function E(b){let e=b.getChildren();var c=e.length;for(--c;0<=c;c--)b.insertAfter(e[c]);b.remove();return e.map(a=>a.getLatest())}
|
|
9
|
+
function F(b,e,c){y.useEffect(()=>{if(!b.hasNodes([h.AutoLinkNode]))throw Error("Minified Lexical error #77; visit https://lexical.dev/docs/error?code=77 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");return m.mergeRegister(b.registerNodeTransform(q.TextNode,a=>{var f=a.getParentOrThrow();if(h.$isAutoLinkNode(f))a:{a=f.getChildren();var d=a.length;for(var g=0;g<d;g++){var n=a[g];if(!q.$isTextNode(n)||!n.isSimpleText()){E(f);a=f.getURL();
|
|
10
|
+
c&&c(null,a);break a}}d=f.getTextContent();a=z(d,e);null===a||a.text!==d?(E(f),a=f.getURL(),c&&c(null,a)):C(f)&&D(f)?(d=f.getURL(),null!==a&&d!==a.url&&(f.setURL(a.url),c&&c(a.url,d))):(E(f),a=f.getURL(),c&&c(null,a))}else if(!h.$isLinkNode(f)){if(a.isSimpleText()){n=f=a.getTextContent();let k=0,u=a;for(;(d=z(n,e))&&null!==d;){let r=d.index,v=d.length,w=r+v;var t=k+r,p=k+w,x=f,B=a;(0<t?A.test(x[t-1]):C(B))&&(p<x.length?A.test(x[p]):D(B))?(0===k+r?[g,u]=u.splitText(k+v):[,g,u]=u.splitText(k+r,k+r+
|
|
11
|
+
v),t=h.$createAutoLinkNode(d.url),p=q.$createTextNode(d.text),p.setFormat(g.getFormat()),p.setDetail(g.getDetail()),t.append(p),g.replace(t),c&&c(d.url,null),k=0):k+=w;n=n.substring(w)}}g=a.getPreviousSibling();d=a.getNextSibling();a=a.getTextContent();h.$isAutoLinkNode(g)&&!A.test(a[0])&&(E(g),g=g.getURL(),c&&c(null,g));h.$isAutoLinkNode(d)&&!A.test(a[a.length-1])&&(E(d),a=d.getURL(),c&&c(null,a))}}))},[b,e,c])}
|
|
12
|
+
exports.AutoLinkPlugin=function({matchers:b,onChange:e}){let [c]=l.useLexicalComposerContext();F(c,b,e);return null}
|
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
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
|
-
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.
|
|
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
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
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)}
|
|
@@ -7,9 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import type { Doc } from 'yjs';
|
|
9
9
|
import { WebsocketProvider } from 'y-websocket';
|
|
10
|
-
|
|
10
|
+
import { InitialEditorStateType } from './LexicalComposer';
|
|
11
|
+
import { CursorsContainerRef } from './shared/useYjsCollaboration';
|
|
12
|
+
export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, cursorsContainerRef, initialEditorState, }: {
|
|
11
13
|
id: string;
|
|
12
14
|
providerFactory: (id: string, yjsDocMap: Map<string, Doc>) => WebsocketProvider;
|
|
13
15
|
shouldBootstrap: boolean;
|
|
14
16
|
username?: string;
|
|
17
|
+
cursorsContainerRef?: CursorsContainerRef;
|
|
18
|
+
initialEditorState?: InitialEditorStateType;
|
|
15
19
|
}): JSX.Element;
|
|
@@ -21,7 +21,7 @@ var reactDom = require('react-dom');
|
|
|
21
21
|
* LICENSE file in the root directory of this source tree.
|
|
22
22
|
*
|
|
23
23
|
*/
|
|
24
|
-
function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap) {
|
|
24
|
+
function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState) {
|
|
25
25
|
const isReloadingDoc = React.useRef(false);
|
|
26
26
|
const [doc, setDoc] = React.useState(docMap.get(id));
|
|
27
27
|
const binding = React.useMemo(() => yjs.createBinding(editor, provider, id, doc, docMap), [editor, provider, id, docMap, doc]);
|
|
@@ -50,7 +50,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
50
50
|
|
|
51
51
|
const onSync = isSynced => {
|
|
52
52
|
if (shouldBootstrap && isSynced && root.isEmpty() && root._xmlText._length === 0 && isReloadingDoc.current === false) {
|
|
53
|
-
initializeEditor(editor);
|
|
53
|
+
initializeEditor(editor, initialEditorState);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
isReloadingDoc.current = false;
|
|
@@ -107,7 +107,7 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
107
107
|
docMap.delete(id);
|
|
108
108
|
removeListener();
|
|
109
109
|
};
|
|
110
|
-
}, [binding, color, connect, disconnect, docMap, editor, id, name, provider, shouldBootstrap]);
|
|
110
|
+
}, [binding, color, connect, disconnect, docMap, editor, id, initialEditorState, name, provider, shouldBootstrap]);
|
|
111
111
|
const cursorsContainer = React.useMemo(() => {
|
|
112
112
|
const ref = element => {
|
|
113
113
|
binding.cursorsContainer = element;
|
|
@@ -115,8 +115,8 @@ function useYjsCollaboration(editor, id, provider, docMap, name, color, shouldBo
|
|
|
115
115
|
|
|
116
116
|
return /*#__PURE__*/reactDom.createPortal( /*#__PURE__*/React.createElement("div", {
|
|
117
117
|
ref: ref
|
|
118
|
-
}), document.body);
|
|
119
|
-
}, [binding]);
|
|
118
|
+
}), cursorsContainerRef && cursorsContainerRef.current || document.body);
|
|
119
|
+
}, [binding, cursorsContainerRef]);
|
|
120
120
|
React.useEffect(() => {
|
|
121
121
|
return editor.registerCommand(yjs.TOGGLE_CONNECT_COMMAND, payload => {
|
|
122
122
|
if (connect !== undefined && disconnect !== undefined) {
|
|
@@ -174,18 +174,54 @@ function useYjsHistory(editor, binding) {
|
|
|
174
174
|
return clearHistory;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
function initializeEditor(editor) {
|
|
177
|
+
function initializeEditor(editor, initialEditorState) {
|
|
178
178
|
editor.update(() => {
|
|
179
179
|
const root = lexical.$getRoot();
|
|
180
|
-
const firstChild = root.getFirstChild();
|
|
181
180
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
181
|
+
if (root.isEmpty()) {
|
|
182
|
+
if (initialEditorState) {
|
|
183
|
+
switch (typeof initialEditorState) {
|
|
184
|
+
case 'string':
|
|
185
|
+
{
|
|
186
|
+
const parsedEditorState = editor.parseEditorState(initialEditorState);
|
|
187
|
+
editor.setEditorState(parsedEditorState, {
|
|
188
|
+
tag: 'history-merge'
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
case 'object':
|
|
194
|
+
{
|
|
195
|
+
editor.setEditorState(initialEditorState, {
|
|
196
|
+
tag: 'history-merge'
|
|
197
|
+
});
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
case 'function':
|
|
202
|
+
{
|
|
203
|
+
editor.update(() => {
|
|
204
|
+
const root1 = lexical.$getRoot();
|
|
205
|
+
|
|
206
|
+
if (root1.isEmpty()) {
|
|
207
|
+
initialEditorState(editor);
|
|
208
|
+
}
|
|
209
|
+
}, {
|
|
210
|
+
tag: 'history-merge'
|
|
211
|
+
});
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
const paragraph = lexical.$createParagraphNode();
|
|
217
|
+
root.append(paragraph);
|
|
218
|
+
const {
|
|
219
|
+
activeElement
|
|
220
|
+
} = document;
|
|
221
|
+
|
|
222
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
223
|
+
paragraph.select();
|
|
224
|
+
}
|
|
189
225
|
}
|
|
190
226
|
}
|
|
191
227
|
}, {
|
|
@@ -247,7 +283,9 @@ function CollaborationPlugin({
|
|
|
247
283
|
id,
|
|
248
284
|
providerFactory,
|
|
249
285
|
shouldBootstrap,
|
|
250
|
-
username
|
|
286
|
+
username,
|
|
287
|
+
cursorsContainerRef,
|
|
288
|
+
initialEditorState
|
|
251
289
|
}) {
|
|
252
290
|
const collabContext = LexicalCollaborationContext.useCollaborationContext(username);
|
|
253
291
|
const {
|
|
@@ -267,7 +305,7 @@ function CollaborationPlugin({
|
|
|
267
305
|
};
|
|
268
306
|
}, [collabContext, editor]);
|
|
269
307
|
const provider = React.useMemo(() => providerFactory(id, yjsDocMap), [id, providerFactory, yjsDocMap]);
|
|
270
|
-
const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap);
|
|
308
|
+
const [cursors, binding] = useYjsCollaboration(editor, id, provider, yjsDocMap, name, color, shouldBootstrap, cursorsContainerRef, initialEditorState);
|
|
271
309
|
collabContext.clientID = binding.clientID;
|
|
272
310
|
useYjsHistory(editor, binding);
|
|
273
311
|
useYjsFocusTracking(editor, provider, name, color);
|
|
@@ -4,12 +4,12 @@
|
|
|
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/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),
|
|
8
|
-
function
|
|
9
|
-
a,
|
|
10
|
-
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
function
|
|
14
|
-
function
|
|
15
|
-
exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d}){let
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalCollaborationContext"),f=require("@lexical/react/LexicalComposerContext"),h=require("react"),z=require("@lexical/utils"),H=require("@lexical/yjs"),I=require("lexical"),J=require("react-dom");
|
|
8
|
+
function K(b,c,a,d,p,w,m,q,t){let r=h.useRef(!1),[n,x]=h.useState(d.get(c)),g=h.useMemo(()=>H.createBinding(b,a,c,n,d),[b,a,c,d,n]),u=h.useCallback(()=>{a.connect()},[a]),v=h.useCallback(()=>{try{a.disconnect()}catch(l){}},[a]);h.useEffect(()=>{let {root:l}=g,{awareness:A}=a,B=({status:k})=>{b.dispatchCommand(H.CONNECTED_COMMAND,"connected"===k)},C=k=>{m&&k&&l.isEmpty()&&0===l._xmlText._length&&!1===r.current&&L(b,t);r.current=!1},D=()=>{H.syncCursorPositions(g,a)},E=(k,y)=>{y.origin!==g&&H.syncYjsChangesToLexical(g,
|
|
9
|
+
a,k)};H.initLocalState(a,p,w,document.activeElement===b.getRootElement());let F=k=>{M(b,g);x(k);d.set(c,k);r.current=!0};a.on("reload",F);a.on("status",B);a.on("sync",C);A.on("update",D);l.getSharedType().observeDeep(E);let Q=b.registerUpdateListener(({prevEditorState:k,editorState:y,dirtyLeaves:N,dirtyElements:O,normalizedNodes:P,tags:G})=>{!1===G.has("skip-collab")&&H.syncLexicalUpdateToYjs(g,a,k,y,O,N,P,G)});u();return()=>{!1===r.current&&v();a.off("sync",C);a.off("status",B);a.off("reload",F);
|
|
10
|
+
A.off("update",D);l.getSharedType().unobserveDeep(E);d.delete(c);Q()}},[g,w,u,v,d,b,c,t,p,a,m]);let R=h.useMemo(()=>J.createPortal(h.createElement("div",{ref:l=>{g.cursorsContainer=l}}),q&&q.current||document.body),[g,q]);h.useEffect(()=>b.registerCommand(H.TOGGLE_CONNECT_COMMAND,l=>{void 0!==u&&void 0!==v&&(l?(console.log("Collaboration connected!"),u()):(console.log("Collaboration disconnected!"),v()));return!0},I.COMMAND_PRIORITY_EDITOR),[u,v,b]);return[R,g]}
|
|
11
|
+
function S(b,c,a,d){h.useEffect(()=>z.mergeRegister(b.registerCommand(I.FOCUS_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!0);return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.BLUR_COMMAND,()=>{H.setLocalStateFocus(c,a,d,!1);return!0},I.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
|
|
12
|
+
function T(b,c){let a=h.useMemo(()=>H.createUndoManager(c,c.root.getSharedType()),[c]);h.useEffect(()=>z.mergeRegister(b.registerCommand(I.UNDO_COMMAND,()=>{a.undo();return!0},I.COMMAND_PRIORITY_EDITOR),b.registerCommand(I.REDO_COMMAND,()=>{a.redo();return!0},I.COMMAND_PRIORITY_EDITOR)));return h.useCallback(()=>{a.clear()},[a])}
|
|
13
|
+
function L(b,c){b.update(()=>{var a=I.$getRoot();if(a.isEmpty())if(c)switch(typeof c){case "string":var d=b.parseEditorState(c);b.setEditorState(d,{tag:"history-merge"});break;case "object":b.setEditorState(c,{tag:"history-merge"});break;case "function":b.update(()=>{I.$getRoot().isEmpty()&&c(b)},{tag:"history-merge"})}else d=I.$createParagraphNode(),a.append(d),{activeElement:a}=document,(null!==I.$getSelection()||null!==a&&a===b.getRootElement())&&d.select()},{tag:"history-merge"})}
|
|
14
|
+
function M(b,c){b.update(()=>{let d=I.$getRoot();d.clear();d.select()},{tag:"skip-collab"});if(null!=c.cursors&&(b=c.cursors,null!=b&&(c=c.cursorsContainer,null!=c))){b=Array.from(b.values());for(let d=0;d<b.length;d++){var a=b[d].selection;if(a&&null!=a.selections){a=a.selections;for(let p=0;p<a.length;p++)c.removeChild(a[d])}}}}
|
|
15
|
+
exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d,cursorsContainerRef:p,initialEditorState:w}){let m=e.useCollaborationContext(d),{yjsDocMap:q,name:t,color:r}=m,[n]=f.useLexicalComposerContext();h.useEffect(()=>{m.isCollabActive=!0;return()=>{null==n._parentEditor&&(m.isCollabActive=!1)}},[m,n]);d=h.useMemo(()=>c(b,q),[b,c,q]);let [x,g]=K(n,b,d,q,t,r,a,p,w);m.clientID=g.clientID;T(n,g);S(n,d,t,r);return x}
|
package/LexicalComposer.d.ts
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import { EditorState, EditorThemeClasses, LexicalEditor, LexicalNode } from 'lexical';
|
|
8
|
+
import { EditorState, EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
|
|
10
9
|
export declare type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
|
|
11
10
|
declare type Props = {
|
|
12
11
|
children: JSX.Element | string | (JSX.Element | string)[];
|
package/LexicalComposer.dev.js
CHANGED
|
@@ -85,7 +85,21 @@ function LexicalComposer({
|
|
|
85
85
|
function initializeEditor(editor, initialEditorState) {
|
|
86
86
|
if (initialEditorState === null) {
|
|
87
87
|
return;
|
|
88
|
-
} else if (initialEditorState === undefined)
|
|
88
|
+
} else if (initialEditorState === undefined) {
|
|
89
|
+
editor.update(() => {
|
|
90
|
+
const root = lexical.$getRoot();
|
|
91
|
+
|
|
92
|
+
if (root.isEmpty()) {
|
|
93
|
+
const paragraph = lexical.$createParagraphNode();
|
|
94
|
+
root.append(paragraph);
|
|
95
|
+
const activeElement = document.activeElement;
|
|
96
|
+
|
|
97
|
+
if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
|
|
98
|
+
paragraph.select();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}, HISTORY_MERGE_OPTIONS);
|
|
102
|
+
} else if (initialEditorState !== null) {
|
|
89
103
|
switch (typeof initialEditorState) {
|
|
90
104
|
case 'string':
|
|
91
105
|
{
|
package/LexicalComposer.js.flow
CHANGED
|
@@ -7,20 +7,27 @@
|
|
|
7
7
|
* @flow strict
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
import type {
|
|
11
|
+
EditorThemeClasses,
|
|
12
|
+
LexicalEditor,
|
|
13
|
+
LexicalNode,
|
|
14
|
+
EditorState,
|
|
15
|
+
} from 'lexical';
|
|
16
|
+
|
|
17
|
+
export type InitialEditorStateType =
|
|
18
|
+
| null
|
|
19
|
+
| string
|
|
20
|
+
| EditorState
|
|
21
|
+
| ((editor: LexicalEditor) => void);
|
|
13
22
|
|
|
14
23
|
type Props = {
|
|
15
24
|
initialConfig: $ReadOnly<{
|
|
16
25
|
editor__DEPRECATED?: LexicalEditor | null,
|
|
17
|
-
|
|
26
|
+
editable?: boolean,
|
|
18
27
|
namespace: string,
|
|
19
28
|
nodes?: $ReadOnlyArray<Class<LexicalNode>>,
|
|
20
29
|
theme?: EditorThemeClasses,
|
|
21
|
-
editorState?:
|
|
22
|
-
| InitialEditorStateRichTextType
|
|
23
|
-
| InitialEditorStatePlainTextType,
|
|
30
|
+
editorState?: InitialEditorStateType,
|
|
24
31
|
onError: (error: Error, editor: LexicalEditor) => void,
|
|
25
32
|
}>,
|
|
26
33
|
children: React$Node,
|
package/LexicalComposer.prod.js
CHANGED
|
@@ -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
|
-
'use strict';var
|
|
8
|
-
function p(
|
|
9
|
-
exports.LexicalComposer=function({initialConfig:
|
|
7
|
+
'use strict';var e=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),g=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?g.useLayoutEffect:g.useEffect;let n={tag:"history-merge"};
|
|
8
|
+
function p(a,c){if(null!==c)if(void 0===c)a.update(()=>{var b=f.$getRoot();if(b.isEmpty()){let d=f.$createParagraphNode();b.append(d);b=document.activeElement;(null!==f.$getSelection()||null!==b&&b===a.getRootElement())&&d.select()}},n);else if(null!==c)switch(typeof c){case "string":let b=a.parseEditorState(c);a.setEditorState(b,n);break;case "object":a.setEditorState(c,n);break;case "function":a.update(()=>{f.$getRoot().isEmpty()&&c(a)},n)}}
|
|
9
|
+
exports.LexicalComposer=function({initialConfig:a,children:c}){let b=g.useMemo(()=>{const {theme:d,namespace:h,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=a,v=e.createLexicalComposerContext(null,d);let k=q||null;if(null===k){const l=f.createEditor({editable:!1,namespace:h,nodes:r,onError:w=>t(w,l),theme:d});p(l,u);k=l}return[k,v]},[]);m(()=>{let d=a.editable,[h]=b;h.setEditable(void 0!==d?d:!0)},[]);return g.createElement(e.LexicalComposerContext.Provider,{value:b},c)}
|
|
@@ -58,7 +58,7 @@ function ContentEditable({
|
|
|
58
58
|
testid
|
|
59
59
|
}) {
|
|
60
60
|
const [editor] = LexicalComposerContext.useLexicalComposerContext();
|
|
61
|
-
const [isEditable, setEditable] = React.useState(
|
|
61
|
+
const [isEditable, setEditable] = React.useState(false);
|
|
62
62
|
const ref = React.useCallback(rootElement => {
|
|
63
63
|
editor.setRootElement(rootElement);
|
|
64
64
|
}, [editor]);
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var b=require("@lexical/react/LexicalComposerContext"),k=require("react"),l="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?k.useLayoutEffect:k.useEffect;
|
|
8
|
-
exports.ContentEditable=function({ariaActiveDescendantID:m,ariaAutoComplete:n,ariaControls:p,ariaDescribedBy:q,ariaExpanded:r,ariaLabel:t,ariaLabelledBy:u,ariaMultiline:v,ariaOwneeID:w,ariaRequired:x,autoCapitalize:e,autoComplete:y,autoCorrect:f,className:z,id:A,role:g="textbox",spellCheck:B=!0,style:C,tabIndex:D,testid:E}){let [c]=b.useLexicalComposerContext(),[a,h]=k.useState(!
|
|
8
|
+
exports.ContentEditable=function({ariaActiveDescendantID:m,ariaAutoComplete:n,ariaControls:p,ariaDescribedBy:q,ariaExpanded:r,ariaLabel:t,ariaLabelledBy:u,ariaMultiline:v,ariaOwneeID:w,ariaRequired:x,autoCapitalize:e,autoComplete:y,autoCorrect:f,className:z,id:A,role:g="textbox",spellCheck:B=!0,style:C,tabIndex:D,testid:E}){let [c]=b.useLexicalComposerContext(),[a,h]=k.useState(!1),F=k.useCallback(d=>{c.setRootElement(d)},[c]);l(()=>{h(c.isEditable());return c.registerEditableListener(d=>{h(d)})},
|
|
9
9
|
[c]);return k.createElement("div",{"aria-activedescendant":a?m:null,"aria-autocomplete":a?n:null,"aria-controls":a?p:null,"aria-describedby":q,"aria-expanded":a?"combobox"===g?!!r:null:null,"aria-label":t,"aria-labelledby":u,"aria-multiline":v,"aria-owns":a?w:null,"aria-required":x,autoCapitalize:void 0!==e?String(e):void 0,autoComplete:y,autoCorrect:void 0!==f?String(f):void 0,className:z,contentEditable:a,"data-testid":E,id:A,ref:F,role:a?g:void 0,spellCheck:B,style:C,tabIndex:D})}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type { LexicalCommand, LexicalNode, SerializedLexicalNode } from 'lexical';
|
|
8
|
+
import type { DOMConversionMap, DOMExportOutput, LexicalCommand, LexicalNode, SerializedLexicalNode } from 'lexical';
|
|
9
9
|
import { DecoratorNode } from 'lexical';
|
|
10
10
|
export declare type SerializedHorizontalRuleNode = SerializedLexicalNode & {
|
|
11
11
|
type: 'horizontalrule';
|
|
@@ -16,10 +16,12 @@ export declare class HorizontalRuleNode extends DecoratorNode<JSX.Element> {
|
|
|
16
16
|
static getType(): string;
|
|
17
17
|
static clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
18
18
|
static importJSON(serializedNode: SerializedHorizontalRuleNode): HorizontalRuleNode;
|
|
19
|
+
static importDOM(): DOMConversionMap | null;
|
|
19
20
|
exportJSON(): SerializedLexicalNode;
|
|
21
|
+
exportDOM(): DOMExportOutput;
|
|
20
22
|
createDOM(): HTMLElement;
|
|
21
23
|
getTextContent(): '\n';
|
|
22
|
-
|
|
24
|
+
isInline(): false;
|
|
23
25
|
updateDOM(): false;
|
|
24
26
|
decorate(): JSX.Element;
|
|
25
27
|
}
|
|
@@ -19,7 +19,7 @@ var React = require('react');
|
|
|
19
19
|
* LICENSE file in the root directory of this source tree.
|
|
20
20
|
*
|
|
21
21
|
*/
|
|
22
|
-
const INSERT_HORIZONTAL_RULE_COMMAND = lexical.createCommand();
|
|
22
|
+
const INSERT_HORIZONTAL_RULE_COMMAND = lexical.createCommand('INSERT_HORIZONTAL_RULE_COMMAND');
|
|
23
23
|
|
|
24
24
|
function HorizontalRuleComponent({
|
|
25
25
|
nodeKey
|
|
@@ -77,6 +77,15 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
77
77
|
return $createHorizontalRuleNode();
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
static importDOM() {
|
|
81
|
+
return {
|
|
82
|
+
hr: () => ({
|
|
83
|
+
conversion: convertHorizontalRuleElement,
|
|
84
|
+
priority: 0
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
exportJSON() {
|
|
81
90
|
return {
|
|
82
91
|
type: 'horizontalrule',
|
|
@@ -84,6 +93,12 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
84
93
|
};
|
|
85
94
|
}
|
|
86
95
|
|
|
96
|
+
exportDOM() {
|
|
97
|
+
return {
|
|
98
|
+
element: document.createElement('hr')
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
87
102
|
createDOM() {
|
|
88
103
|
const div = document.createElement('div');
|
|
89
104
|
div.style.display = 'contents';
|
|
@@ -94,8 +109,8 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
94
109
|
return '\n';
|
|
95
110
|
}
|
|
96
111
|
|
|
97
|
-
|
|
98
|
-
return
|
|
112
|
+
isInline() {
|
|
113
|
+
return false;
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
updateDOM() {
|
|
@@ -109,6 +124,13 @@ class HorizontalRuleNode extends lexical.DecoratorNode {
|
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
}
|
|
127
|
+
|
|
128
|
+
function convertHorizontalRuleElement() {
|
|
129
|
+
return {
|
|
130
|
+
node: $createHorizontalRuleNode()
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
112
134
|
function $createHorizontalRuleNode() {
|
|
113
135
|
return new HorizontalRuleNode();
|
|
114
136
|
}
|
|
@@ -16,7 +16,6 @@ declare export class HorizontalRuleNode extends DecoratorNode<React$Node> {
|
|
|
16
16
|
static clone(node: HorizontalRuleNode): HorizontalRuleNode;
|
|
17
17
|
createDOM(): HTMLElement;
|
|
18
18
|
getTextContent(): '\n';
|
|
19
|
-
isTopLevel(): true;
|
|
20
19
|
updateDOM(): false;
|
|
21
20
|
decorate(): React$Node;
|
|
22
21
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
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 a=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/useLexicalNodeSelection"),h=require("@lexical/utils"),
|
|
8
|
-
function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),
|
|
9
|
-
k,
|
|
10
|
-
class u extends
|
|
11
|
-
exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
|
7
|
+
'use strict';var a=require("@lexical/react/LexicalComposerContext"),d=require("@lexical/react/useLexicalNodeSelection"),h=require("@lexical/utils"),l=require("lexical"),p=require("react");let q=l.createCommand("INSERT_HORIZONTAL_RULE_COMMAND");
|
|
8
|
+
function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),m=p.useRef(null),[e,g,n]=d.useLexicalNodeSelection(b),k=p.useCallback(c=>{e&&l.$isNodeSelection(l.$getSelection())&&(c.preventDefault(),c=l.$getNodeByKey(b),t(c)&&c.remove(),g(!1));return!1},[e,b,g]);p.useEffect(()=>h.mergeRegister(f.registerCommand(l.CLICK_COMMAND,c=>c.target===m.current?(c.shiftKey||n(),g(!e),!0):!1,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_DELETE_COMMAND,k,l.COMMAND_PRIORITY_LOW),f.registerCommand(l.KEY_BACKSPACE_COMMAND,
|
|
9
|
+
k,l.COMMAND_PRIORITY_LOW)),[n,f,e,k,g]);return p.createElement("hr",{ref:m,className:e?"selected":void 0})}
|
|
10
|
+
class u extends l.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new u(b.__key)}static importJSON(){return v()}static importDOM(){return{hr:()=>({conversion:w,priority:0})}}exportJSON(){return{type:"horizontalrule",version:1}}exportDOM(){return{element:document.createElement("hr")}}createDOM(){let b=document.createElement("div");b.style.display="contents";return b}getTextContent(){return"\n"}isInline(){return!1}updateDOM(){return!1}decorate(){return p.createElement(r,{nodeKey:this.__key})}}
|
|
11
|
+
function w(){return{node:v()}}function v(){return new u}function t(b){return b instanceof u}exports.$createHorizontalRuleNode=v;exports.$isHorizontalRuleNode=t;exports.HorizontalRuleNode=u;exports.INSERT_HORIZONTAL_RULE_COMMAND=q
|
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type { EditorThemeClasses, LexicalEditor } from 'lexical';
|
|
8
|
+
import type { EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from 'lexical';
|
|
9
9
|
import { ReactNode } from 'react';
|
|
10
|
-
export declare function LexicalNestedComposer({ initialEditor, children, initialTheme, }: {
|
|
10
|
+
export declare function LexicalNestedComposer({ initialEditor, children, initialNodes, initialTheme, skipCollabChecks, }: {
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
initialEditor: LexicalEditor;
|
|
13
13
|
initialTheme?: EditorThemeClasses;
|
|
14
|
+
initialNodes?: ReadonlyArray<Klass<LexicalNode>>;
|
|
15
|
+
skipCollabChecks?: true;
|
|
14
16
|
}): JSX.Element;
|
|
@@ -20,7 +20,9 @@ var React = require('react');
|
|
|
20
20
|
function LexicalNestedComposer({
|
|
21
21
|
initialEditor,
|
|
22
22
|
children,
|
|
23
|
-
|
|
23
|
+
initialNodes,
|
|
24
|
+
initialTheme,
|
|
25
|
+
skipCollabChecks
|
|
24
26
|
}) {
|
|
25
27
|
const wasCollabPreviouslyReadyRef = React.useRef(false);
|
|
26
28
|
const parentContext = React.useContext(LexicalComposerContext.LexicalComposerContext);
|
|
@@ -41,7 +43,27 @@ function LexicalNestedComposer({
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
initialEditor._parentEditor = parentEditor;
|
|
44
|
-
|
|
46
|
+
|
|
47
|
+
if (!initialNodes) {
|
|
48
|
+
const parentNodes = initialEditor._nodes = new Map(parentEditor._nodes);
|
|
49
|
+
|
|
50
|
+
for (const [type, entry] of parentNodes) {
|
|
51
|
+
initialEditor._nodes.set(type, {
|
|
52
|
+
klass: entry.klass,
|
|
53
|
+
transforms: new Set()
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
for (const klass of initialNodes) {
|
|
58
|
+
const type = klass.getType();
|
|
59
|
+
|
|
60
|
+
initialEditor._nodes.set(type, {
|
|
61
|
+
klass,
|
|
62
|
+
transforms: new Set()
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
45
67
|
initialEditor._config.namespace = parentEditor._config.namespace;
|
|
46
68
|
return [initialEditor, context];
|
|
47
69
|
}, // We only do this for init
|
|
@@ -53,7 +75,7 @@ function LexicalNestedComposer({
|
|
|
53
75
|
isCollabActive,
|
|
54
76
|
yjsDocMap
|
|
55
77
|
} = LexicalCollaborationContext.useCollaborationContext();
|
|
56
|
-
const isCollabReady = wasCollabPreviouslyReadyRef.current || yjsDocMap.has(initialEditor.getKey());
|
|
78
|
+
const isCollabReady = skipCollabChecks || wasCollabPreviouslyReadyRef.current || yjsDocMap.has(initialEditor.getKey());
|
|
57
79
|
React.useEffect(() => {
|
|
58
80
|
if (isCollabReady) {
|
|
59
81
|
wasCollabPreviouslyReadyRef.current = true;
|
|
@@ -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
|
-
'use strict';var b=require("@lexical/react/LexicalCollaborationContext"),
|
|
8
|
-
exports.LexicalNestedComposer=function({initialEditor:a,children:
|
|
9
|
-
|
|
7
|
+
'use strict';var b=require("@lexical/react/LexicalCollaborationContext"),e=require("@lexical/react/LexicalComposerContext"),m=require("react");
|
|
8
|
+
exports.LexicalNestedComposer=function({initialEditor:a,children:n,initialNodes:k,initialTheme:p,skipCollabChecks:q}){let l=m.useRef(!1),f=m.useContext(e.LexicalComposerContext);if(null==f)throw Error("Minified Lexical error #9; visit https://lexical.dev/docs/error?code=9 for the full message or use the non-minified dev environment for full errors and additional helpful warnings.");let w=m.useMemo(()=>{const [g,r]=f;var c=p||r.getTheme()||void 0;const t=e.createLexicalComposerContext(f,c);void 0!==
|
|
9
|
+
c&&(a._config.theme=c);a._parentEditor=g;if(k)for(var d of k)c=d.getType(),a._nodes.set(c,{klass:d,transforms:new Set});else{d=a._nodes=new Map(g._nodes);for(const [u,v]of d)a._nodes.set(u,{klass:v.klass,transforms:new Set})}a._config.namespace=g._config.namespace;return[a,t]},[]),{isCollabActive:x,yjsDocMap:y}=b.useCollaborationContext(),h=q||l.current||y.has(a.getKey());m.useEffect(()=>{h&&(l.current=!0)},[h]);return m.createElement(e.LexicalComposerContext.Provider,{value:w},!x||h?n:null)}
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
import type { EditorState, LexicalEditor } from 'lexical';
|
|
9
|
-
export declare function OnChangePlugin({ ignoreHistoryMergeTagChange,
|
|
9
|
+
export declare function OnChangePlugin({ ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange, }: {
|
|
10
10
|
ignoreHistoryMergeTagChange?: boolean;
|
|
11
|
-
ignoreInitialChange?: boolean;
|
|
12
11
|
ignoreSelectionChange?: boolean;
|
|
13
12
|
onChange: (editorState: EditorState, editor: LexicalEditor) => void;
|
|
14
13
|
}): null;
|
|
@@ -36,9 +36,7 @@ var useLayoutEffect = useLayoutEffectImpl;
|
|
|
36
36
|
*
|
|
37
37
|
*/
|
|
38
38
|
function OnChangePlugin({
|
|
39
|
-
|
|
40
|
-
ignoreHistoryMergeTagChange = false,
|
|
41
|
-
ignoreInitialChange = true,
|
|
39
|
+
ignoreHistoryMergeTagChange = true,
|
|
42
40
|
ignoreSelectionChange = false,
|
|
43
41
|
onChange
|
|
44
42
|
}) {
|
|
@@ -52,18 +50,14 @@ function OnChangePlugin({
|
|
|
52
50
|
prevEditorState,
|
|
53
51
|
tags
|
|
54
52
|
}) => {
|
|
55
|
-
if (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0 || ignoreHistoryMergeTagChange && tags.has('history-merge')) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (ignoreInitialChange && prevEditorState.isEmpty()) {
|
|
53
|
+
if (ignoreSelectionChange && dirtyElements.size === 0 && dirtyLeaves.size === 0 || ignoreHistoryMergeTagChange && tags.has('history-merge') || prevEditorState.isEmpty()) {
|
|
60
54
|
return;
|
|
61
55
|
}
|
|
62
56
|
|
|
63
57
|
onChange(editorState, editor);
|
|
64
58
|
});
|
|
65
59
|
}
|
|
66
|
-
}, [editor, ignoreHistoryMergeTagChange,
|
|
60
|
+
}, [editor, ignoreHistoryMergeTagChange, ignoreSelectionChange, onChange]);
|
|
67
61
|
return null;
|
|
68
62
|
}
|
|
69
63
|
|
|
@@ -11,8 +11,6 @@ import type {EditorState, LexicalEditor} from 'lexical';
|
|
|
11
11
|
|
|
12
12
|
declare export function OnChangePlugin({
|
|
13
13
|
ignoreHistoryMergeTagChange?: boolean,
|
|
14
|
-
// TODO 0.5 remove
|
|
15
|
-
ignoreInitialChange?: boolean,
|
|
16
14
|
ignoreSelectionChange?: boolean,
|
|
17
15
|
onChange: (editorState: EditorState, editor: LexicalEditor) => void,
|
|
18
16
|
}): null;
|
|
@@ -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/react/LexicalComposerContext"),
|
|
8
|
-
exports.OnChangePlugin=function({ignoreHistoryMergeTagChange:d=!
|
|
7
|
+
'use strict';var c=require("@lexical/react/LexicalComposerContext"),f=require("react"),g="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?f.useLayoutEffect:f.useEffect;
|
|
8
|
+
exports.OnChangePlugin=function({ignoreHistoryMergeTagChange:d=!0,ignoreSelectionChange:e=!1,onChange:a}){let [b]=c.useLexicalComposerContext();g(()=>{if(a)return b.registerUpdateListener(({editorState:h,dirtyElements:k,dirtyLeaves:l,prevEditorState:m,tags:n})=>{e&&0===k.size&&0===l.size||d&&n.has("history-merge")||m.isEmpty()||a(h,b)})},[b,d,e,a]);return null}
|