@lexical/react 0.4.0 → 0.5.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.
Files changed (58) hide show
  1. package/DEPRECATED_useLexical.js.flow +0 -1
  2. package/DEPRECATED_useLexicalPlainText.d.ts +2 -2
  3. package/DEPRECATED_useLexicalPlainText.dev.js +4 -4
  4. package/DEPRECATED_useLexicalPlainText.js.flow +0 -1
  5. package/DEPRECATED_useLexicalPlainText.prod.js +2 -2
  6. package/DEPRECATED_useLexicalRichText.d.ts +2 -2
  7. package/DEPRECATED_useLexicalRichText.dev.js +4 -4
  8. package/DEPRECATED_useLexicalRichText.js.flow +0 -1
  9. package/DEPRECATED_useLexicalRichText.prod.js +2 -2
  10. package/LexicalAutoEmbedPlugin.d.ts +0 -2
  11. package/LexicalAutoEmbedPlugin.dev.js +0 -1
  12. package/LexicalAutoEmbedPlugin.prod.js +4 -4
  13. package/LexicalAutoLinkPlugin.dev.js +2 -1
  14. package/LexicalAutoLinkPlugin.prod.js +3 -3
  15. package/LexicalBlockWithAlignableContents.dev.js +1 -1
  16. package/LexicalBlockWithAlignableContents.prod.js +1 -1
  17. package/LexicalCollaborationPlugin.d.ts +5 -1
  18. package/LexicalCollaborationPlugin.dev.js +54 -16
  19. package/LexicalCollaborationPlugin.js.flow +1 -0
  20. package/LexicalCollaborationPlugin.prod.js +9 -9
  21. package/LexicalComposer.d.ts +1 -2
  22. package/LexicalComposer.dev.js +16 -2
  23. package/LexicalComposer.js.flow +14 -7
  24. package/LexicalComposer.prod.js +3 -3
  25. package/LexicalContentEditable.dev.js +1 -1
  26. package/LexicalContentEditable.prod.js +1 -1
  27. package/LexicalHorizontalRuleNode.d.ts +4 -2
  28. package/LexicalHorizontalRuleNode.dev.js +24 -2
  29. package/LexicalHorizontalRuleNode.js.flow +0 -1
  30. package/LexicalHorizontalRuleNode.prod.js +5 -5
  31. package/LexicalNestedComposer.d.ts +4 -2
  32. package/LexicalNestedComposer.dev.js +25 -3
  33. package/LexicalNestedComposer.js.flow +1 -0
  34. package/LexicalNestedComposer.prod.js +3 -3
  35. package/LexicalOnChangePlugin.d.ts +1 -2
  36. package/LexicalOnChangePlugin.dev.js +3 -9
  37. package/LexicalOnChangePlugin.js.flow +0 -2
  38. package/LexicalOnChangePlugin.prod.js +2 -2
  39. package/LexicalPlainTextPlugin.d.ts +1 -3
  40. package/LexicalPlainTextPlugin.dev.js +4 -29
  41. package/LexicalPlainTextPlugin.js.flow +0 -1
  42. package/LexicalPlainTextPlugin.prod.js +4 -4
  43. package/LexicalRichTextPlugin.d.ts +1 -3
  44. package/LexicalRichTextPlugin.dev.js +4 -29
  45. package/LexicalRichTextPlugin.js.flow +0 -1
  46. package/LexicalRichTextPlugin.prod.js +4 -4
  47. package/LexicalTableOfContents__EXPERIMENTAL.js.flow +1 -1
  48. package/LexicalTablePlugin.dev.js +1 -1
  49. package/LexicalTablePlugin.prod.js +1 -1
  50. package/LexicalTreeView.dev.js +4 -4
  51. package/LexicalTreeView.prod.js +4 -4
  52. package/LexicalTypeaheadMenuPlugin.d.ts +5 -2
  53. package/LexicalTypeaheadMenuPlugin.dev.js +13 -10
  54. package/LexicalTypeaheadMenuPlugin.prod.js +16 -16
  55. package/package.json +19 -19
  56. package/shared/usePlainTextSetup.d.ts +1 -2
  57. package/shared/useRichTextSetup.d.ts +1 -2
  58. package/shared/useYjsCollaboration.d.ts +4 -1
@@ -18,7 +18,6 @@ import type {
18
18
  declare export function useLexical<EditorContext>(editorConfig?: {
19
19
  namespace?: string,
20
20
  onError: (error: Error) => void,
21
- initialEditorState?: EditorState,
22
21
  theme?: EditorThemeClasses,
23
22
  context?: EditorContext,
24
23
  nodes?: Array<Class<LexicalNode>>,
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
  import type { HistoryState } from './DEPRECATED_useLexicalHistory';
9
- import type { EditorState, LexicalEditor } from 'lexical';
10
- export declare function useLexicalPlainText(editor: LexicalEditor, externalHistoryState?: HistoryState, initialEditorState?: null | string | EditorState | (() => void)): void;
9
+ import type { LexicalEditor } from 'lexical';
10
+ export declare function useLexicalPlainText(editor: LexicalEditor, externalHistoryState?: HistoryState): void;
@@ -63,9 +63,9 @@ var useLayoutEffect = useLayoutEffectImpl;
63
63
  * LICENSE file in the root directory of this source tree.
64
64
  *
65
65
  */
66
- function usePlainTextSetup(editor, initialEditorState) {
66
+ function usePlainTextSetup(editor) {
67
67
  useLayoutEffect(() => {
68
- return utils.mergeRegister(plainText.registerPlainText(editor, initialEditorState), dragon.registerDragonSupport(editor)); // We only do this for init
68
+ return utils.mergeRegister(plainText.registerPlainText(editor), dragon.registerDragonSupport(editor)); // We only do this for init
69
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
70
  }, [editor]);
71
71
  }
@@ -77,8 +77,8 @@ function usePlainTextSetup(editor, initialEditorState) {
77
77
  * LICENSE file in the root directory of this source tree.
78
78
  *
79
79
  */
80
- function useLexicalPlainText(editor, externalHistoryState, initialEditorState) {
81
- usePlainTextSetup(editor, initialEditorState);
80
+ function useLexicalPlainText(editor, externalHistoryState) {
81
+ usePlainTextSetup(editor);
82
82
  useLexicalHistory(editor, externalHistoryState);
83
83
  }
84
84
 
@@ -14,5 +14,4 @@ import type {EditorState, LexicalEditor} from 'lexical';
14
14
  declare export function useLexicalPlainText(
15
15
  editor: LexicalEditor,
16
16
  externalHistoryState?: HistoryState,
17
- initialEditorState?: null | string | EditorState | (() => void),
18
17
  ): void;
@@ -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 history=require("@lexical/history"),d=require("react"),f=require("@lexical/dragon"),g=require("@lexical/plain-text"),h=require("@lexical/utils");function k(a,b,c=1E3){let e=d.useMemo(()=>b||history.createEmptyHistoryState(),[b]);d.useEffect(()=>history.registerHistory(a,e,c),[c,a,e])}function l(a,b,c=1E3){return k(a,b,c)}var m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;
8
- function n(a,b){m(()=>h.mergeRegister(g.registerPlainText(a,b),f.registerDragonSupport(a)),[a])}exports.useLexicalPlainText=function(a,b,c){n(a,c);l(a,b)}
7
+ 'use strict';var history=require("@lexical/history"),c=require("react"),f=require("@lexical/dragon"),g=require("@lexical/plain-text"),h=require("@lexical/utils");function k(a,b,d=1E3){let e=c.useMemo(()=>b||history.createEmptyHistoryState(),[b]);c.useEffect(()=>history.registerHistory(a,e,d),[d,a,e])}function l(a,b,d=1E3){return k(a,b,d)}var m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
8
+ function n(a){m(()=>h.mergeRegister(g.registerPlainText(a),f.registerDragonSupport(a)),[a])}exports.useLexicalPlainText=function(a,b){n(a);l(a,b)}
@@ -6,5 +6,5 @@
6
6
  *
7
7
  */
8
8
  import type { HistoryState } from './DEPRECATED_useLexicalHistory';
9
- import type { EditorState, LexicalEditor } from 'lexical';
10
- export declare function useLexicalRichText(editor: LexicalEditor, externalHistoryState?: HistoryState, initialEditorState?: null | string | EditorState | (() => void)): void;
9
+ import type { LexicalEditor } from 'lexical';
10
+ export declare function useLexicalRichText(editor: LexicalEditor, externalHistoryState?: HistoryState): void;
@@ -63,9 +63,9 @@ var useLayoutEffect = useLayoutEffectImpl;
63
63
  * LICENSE file in the root directory of this source tree.
64
64
  *
65
65
  */
66
- function useRichTextSetup(editor, initialEditorState) {
66
+ function useRichTextSetup(editor) {
67
67
  useLayoutEffect(() => {
68
- return utils.mergeRegister(richText.registerRichText(editor, initialEditorState), dragon.registerDragonSupport(editor)); // We only do this for init
68
+ return utils.mergeRegister(richText.registerRichText(editor), dragon.registerDragonSupport(editor)); // We only do this for init
69
69
  // eslint-disable-next-line react-hooks/exhaustive-deps
70
70
  }, [editor]);
71
71
  }
@@ -77,8 +77,8 @@ function useRichTextSetup(editor, initialEditorState) {
77
77
  * LICENSE file in the root directory of this source tree.
78
78
  *
79
79
  */
80
- function useLexicalRichText(editor, externalHistoryState, initialEditorState) {
81
- useRichTextSetup(editor, initialEditorState);
80
+ function useLexicalRichText(editor, externalHistoryState) {
81
+ useRichTextSetup(editor);
82
82
  useLexicalHistory(editor, externalHistoryState);
83
83
  }
84
84
 
@@ -14,5 +14,4 @@ import type {EditorState, LexicalEditor} from 'lexical';
14
14
  declare export function useLexicalRichText(
15
15
  editor: LexicalEditor,
16
16
  externalHistoryState?: HistoryState,
17
- initialEditorState?: null | string | EditorState | (() => void),
18
17
  ): void;
@@ -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 history=require("@lexical/history"),d=require("react"),f=require("@lexical/dragon"),g=require("@lexical/rich-text"),h=require("@lexical/utils");function k(a,b,c=1E3){let e=d.useMemo(()=>b||history.createEmptyHistoryState(),[b]);d.useEffect(()=>history.registerHistory(a,e,c),[c,a,e])}function l(a,b,c=1E3){return k(a,b,c)}var m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?d.useLayoutEffect:d.useEffect;
8
- function n(a,b){m(()=>h.mergeRegister(g.registerRichText(a,b),f.registerDragonSupport(a)),[a])}exports.useLexicalRichText=function(a,b,c){n(a,c);l(a,b)}
7
+ 'use strict';var history=require("@lexical/history"),c=require("react"),f=require("@lexical/dragon"),g=require("@lexical/rich-text"),h=require("@lexical/utils");function k(a,b,d=1E3){let e=c.useMemo(()=>b||history.createEmptyHistoryState(),[b]);c.useEffect(()=>history.registerHistory(a,e,d),[d,a,e])}function l(a,b,d=1E3){return k(a,b,d)}var m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?c.useLayoutEffect:c.useEffect;
8
+ function n(a){m(()=>h.mergeRegister(g.registerRichText(a),f.registerDragonSupport(a)),[a])}exports.useLexicalRichText=function(a,b){n(a);l(a,b)}
@@ -29,10 +29,8 @@ export declare type EmbedMenuProps = {
29
29
  export declare type EmbedMenuComponent = React.ComponentType<EmbedMenuProps>;
30
30
  export declare class AutoEmbedOption extends TypeaheadOption {
31
31
  title: string;
32
- icon?: JSX.Element;
33
32
  onSelect: (targetNode: LexicalNode | null) => void;
34
33
  constructor(title: string, options: {
35
- icon?: JSX.Element;
36
34
  onSelect: (targetNode: LexicalNode | null) => void;
37
35
  });
38
36
  }
@@ -27,7 +27,6 @@ class AutoEmbedOption extends LexicalTypeaheadMenuPlugin.TypeaheadOption {
27
27
  constructor(title, options) {
28
28
  super(title);
29
29
  this.title = title;
30
- this.icon = options.icon;
31
30
  this.onSelect = options.onSelect.bind(this);
32
31
  }
33
32
 
@@ -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 e=require("@lexical/link"),m=require("@lexical/react/LexicalComposerContext"),q=require("@lexical/react/LexicalTypeaheadMenuPlugin"),t=require("@lexical/utils"),u=require("lexical"),B=require("react"),C=require("react-dom");let D=u.createCommand();class E extends q.TypeaheadOption{constructor(g,n){super(g);this.title=g;this.icon=n.icon;this.onSelect=n.onSelect.bind(this)}}exports.AutoEmbedOption=E;exports.INSERT_EMBED_COMMAND=D;
8
- exports.LexicalAutoEmbedPlugin=function({embedConfigs:g,onOpenEmbedModalForConfig:n,getMenuOptions:v,menuComponent:F}){let [c]=m.useLexicalComposerContext(),[f,w]=B.useState(null),[h,x]=B.useState(null),p=B.useCallback(()=>{w(null);x(null)},[]),y=B.useCallback(b=>{c.getEditorState().read(()=>{const a=u.$getNodeByKey(b);if(e.$isLinkNode(a)){const d=g.find(k=>k.parseUrl(a.__url));null!=d&&(x(d),w(a.getKey()))}})},[c,g]);B.useEffect(()=>{let b=(a,{updateTags:d,dirtyLeaves:k})=>{for(const [l,r]of a)"created"===
9
- r&&d.has("paste")&&1===k.size?y(l):l===f&&p()};return t.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>c.registerMutationListener(a,(...d)=>b(...d))))},[y,c,g,f,p]);B.useEffect(()=>c.registerCommand(D,b=>{let a=g.find(({type:d})=>d===b);return a?(n(a),!0):!1},u.COMMAND_PRIORITY_EDITOR),[c,g,n]);let z=B.useCallback(()=>{if(null!=h&&null!=f){const b=c.getEditorState().read(()=>{const a=u.$getNodeByKey(f);return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(b)){const a=h.parseUrl(b.__url);null!=a&&
10
- (c.update(()=>{h.insertNode(c,a)}),b.isAttached()&&c.update(()=>{b.remove()}))}}},[h,c,f]),A=B.useMemo(()=>null!=h&&null!=f?v(h,z,p):[],[h,z,v,f,p]),G=B.useCallback((b,a,d)=>{c.update(()=>{b.onSelect(a);d()})},[c]);return null!=f?B.createElement(q.LexicalNodeMenuPlugin,{nodeKey:f,onClose:p,onSelectOption:G,options:A,menuRenderFn:(b,{selectedIndex:a,selectOptionAndCleanUp:d,setHighlightedIndex:k})=>b&&null!=f?C.createPortal(B.createElement(F,{options:A,selectedItemIndex:a,onOptionClick:(l,r)=>{k(r);
7
+ 'use strict';var e=require("@lexical/link"),m=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/react/LexicalTypeaheadMenuPlugin"),t=require("@lexical/utils"),u=require("lexical"),B=require("react"),C=require("react-dom");let D=u.createCommand();class E extends p.TypeaheadOption{constructor(g,q){super(g);this.title=g;this.onSelect=q.onSelect.bind(this)}}exports.AutoEmbedOption=E;exports.INSERT_EMBED_COMMAND=D;
8
+ exports.LexicalAutoEmbedPlugin=function({embedConfigs:g,onOpenEmbedModalForConfig:q,getMenuOptions:v,menuComponent:F}){let [c]=m.useLexicalComposerContext(),[f,w]=B.useState(null),[h,x]=B.useState(null),n=B.useCallback(()=>{w(null);x(null)},[]),y=B.useCallback(b=>{c.getEditorState().read(()=>{const a=u.$getNodeByKey(b);if(e.$isLinkNode(a)){const d=g.find(k=>k.parseUrl(a.__url));null!=d&&(x(d),w(a.getKey()))}})},[c,g]);B.useEffect(()=>{let b=(a,{updateTags:d,dirtyLeaves:k})=>{for(const [l,r]of a)"created"===
9
+ r&&d.has("paste")&&1===k.size?y(l):l===f&&n()};return t.mergeRegister(...[e.LinkNode,e.AutoLinkNode].map(a=>c.registerMutationListener(a,(...d)=>b(...d))))},[y,c,g,f,n]);B.useEffect(()=>c.registerCommand(D,b=>{let a=g.find(({type:d})=>d===b);return a?(q(a),!0):!1},u.COMMAND_PRIORITY_EDITOR),[c,g,q]);let z=B.useCallback(()=>{if(null!=h&&null!=f){const b=c.getEditorState().read(()=>{const a=u.$getNodeByKey(f);return e.$isLinkNode(a)?a:null});if(e.$isLinkNode(b)){const a=h.parseUrl(b.__url);null!=a&&
10
+ (c.update(()=>{h.insertNode(c,a)}),b.isAttached()&&c.update(()=>{b.remove()}))}}},[h,c,f]),A=B.useMemo(()=>null!=h&&null!=f?v(h,z,n):[],[h,z,v,f,n]),G=B.useCallback((b,a,d)=>{c.update(()=>{b.onSelect(a);d()})},[c]);return null!=f?B.createElement(p.LexicalNodeMenuPlugin,{nodeKey:f,onClose:n,onSelectOption:G,options:A,menuRenderFn:(b,{selectedIndex:a,selectOptionAndCleanUp:d,setHighlightedIndex:k})=>b&&null!=f?C.createPortal(B.createElement(F,{options:A,selectedItemIndex:a,onOptionClick:(l,r)=>{k(r);
11
11
  d(l)},onOptionMouseEnter:l=>{k(l)}}),b):null}):null};exports.URL_MATCHER=/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/
@@ -97,8 +97,9 @@ function handleLinkCreation(node, matchers, onChange) {
97
97
  [, middleNode, lastNode] = lastNode.splitText(matchOffset, matchOffset + matchLength);
98
98
  }
99
99
 
100
+ const nodeFormat = node.__format;
100
101
  const linkNode = link.$createAutoLinkNode(match.url);
101
- linkNode.append(lexical.$createTextNode(match.text));
102
+ linkNode.append(lexical.$createTextNode(match.text).setFormat(nodeFormat));
102
103
  middleNode.replace(linkNode);
103
104
  onChange(match.url, null);
104
105
  }
@@ -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"),p=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(a,c){for(let b=0;b<c.length;b++){let e=c[b](a);if(e)return e}return null}function y(a){a=a.getPreviousSibling();v.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
7
+ 'use strict';var h=require("@lexical/link"),m=require("@lexical/react/LexicalComposerContext"),p=require("@lexical/utils"),v=require("lexical"),w=require("react");function x(a,c){for(let b=0;b<c.length;b++){let e=c[b](a);if(e)return e}return null}function y(a){a=a.getPreviousSibling();v.$isElementNode(a)&&(a=a.getLastDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().endsWith(" ")}
8
8
  function A(a){a=a.getNextSibling();v.$isElementNode(a)&&(a=a.getFirstDescendant());return null===a||v.$isLineBreakNode(a)||v.$isTextNode(a)&&a.getTextContent().startsWith(" ")}
9
9
  function B(a,c,b){var e=a.getChildren();let d=e.length;for(let f=0;f<d;f++){let g=e[f];if(!v.$isTextNode(g)||!g.isSimpleText()){C(a);b(null,a.getURL());return}}e=a.getTextContent();c=x(e,c);null===c||c.text!==e?(C(a),b(null,a.getURL())):y(a)&&A(a)?(e=a.getURL(),null!==c&&e!==c.url&&(a.setURL(c.url),b(c.url,e))):(C(a),b(null,a.getURL()))}function C(a){let c=a.getChildren();var b=c.length;for(--b;0<=b;b--)a.insertAfter(c[b]);a.remove();return c.map(e=>e.getLatest())}
10
10
  function D(a,c,b){w.useEffect(()=>{if(!a.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.");let e=(d,f)=>{b&&b(d,f)};return p.mergeRegister(a.registerNodeTransform(v.TextNode,d=>{var f=d.getParentOrThrow();if(h.$isAutoLinkNode(f))B(f,c,e);else if(!h.$isLinkNode(f)){if(d.isSimpleText()){f=d.getTextContent();let E=f.length,u=f,
11
- z=0,t=d;for(var g;(g=x(u,c))&&null!==g;){var m=g.index,n=z+m;let q=g.length;var r=void 0;r=0<n?" "===f[n-1]:y(d);n=n+q<E?" "===f[n+q]:A(d);if(r&&n){var k=void 0;0===m?[k,t]=t.splitText(q):[,k,t]=t.splitText(m,m+q);r=h.$createAutoLinkNode(g.url);r.append(v.$createTextNode(g.text));k.replace(r);b&&b(g.url,null)}m+=q;u=u.substring(m);z+=m}}k=d.getPreviousSibling();g=d.getNextSibling();d=d.getTextContent();h.$isAutoLinkNode(k)&&!d.startsWith(" ")&&(C(k),k=k.getURL(),b&&b(null,k));h.$isAutoLinkNode(g)&&
12
- !d.endsWith(" ")&&(C(g),d=g.getURL(),b&&b(null,d))}}),a.registerNodeTransform(h.AutoLinkNode,d=>{B(d,c,e)}))},[a,c,b])}exports.AutoLinkPlugin=function({matchers:a,onChange:c}){let [b]=l.useLexicalComposerContext();D(b,a,c);return null}
11
+ z=0,r=d;for(var g;(g=x(u,c))&&null!==g;){var n=g.index,k=z+n;let q=g.length;var t=void 0;t=0<k?" "===f[k-1]:y(d);k=k+q<E?" "===f[k+q]:A(d);if(t&&k){var l=void 0;0===n?[l,r]=r.splitText(q):[,l,r]=r.splitText(n,n+q);t=d.__format;k=h.$createAutoLinkNode(g.url);k.append(v.$createTextNode(g.text).setFormat(t));l.replace(k);b&&b(g.url,null)}n+=q;u=u.substring(n);z+=n}}l=d.getPreviousSibling();g=d.getNextSibling();d=d.getTextContent();h.$isAutoLinkNode(l)&&!d.startsWith(" ")&&(C(l),l=l.getURL(),b&&b(null,
12
+ l));h.$isAutoLinkNode(g)&&!d.endsWith(" ")&&(C(g),d=g.getURL(),b&&b(null,d))}}),a.registerNodeTransform(h.AutoLinkNode,d=>{B(d,c,e)}))},[a,c,b])}exports.AutoLinkPlugin=function({matchers:a,onChange:c}){let [b]=m.useLexicalComposerContext();D(b,a,c);return null}
@@ -35,7 +35,7 @@ function BlockWithAlignableContents({
35
35
  editor.update(() => {
36
36
  const node = lexical.$getNodeByKey(nodeKey);
37
37
 
38
- if (lexical.$isDecoratorNode(node) && node.isTopLevel()) {
38
+ if (lexical.$isDecoratorNode(node)) {
39
39
  node.remove();
40
40
  }
41
41
 
@@ -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.isTopLevel()&&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=
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
- export declare function CollaborationPlugin({ id, providerFactory, shouldBootstrap, username, }: {
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 (firstChild === null) {
183
- const paragraph = lexical.$createParagraphNode();
184
- root.append(paragraph);
185
- const activeElement = document.activeElement;
186
-
187
- if (lexical.$getSelection() !== null || activeElement !== null && activeElement === editor.getRootElement()) {
188
- paragraph.select();
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);
@@ -33,6 +33,7 @@ export type ProviderFactory = (
33
33
 
34
34
  declare export function CollaborationPlugin(arg0: {
35
35
  id: string,
36
+ cursorsContainerRef?: {current: HTMLElement | null},
36
37
  providerFactory: ProviderFactory,
37
38
  shouldBootstrap: boolean,
38
39
  username?: string,
@@ -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"),k=require("react"),x=require("@lexical/utils"),F=require("@lexical/yjs"),G=require("lexical"),H=require("react-dom");
8
- function I(b,c,a,d,h,q,r){let p=k.useRef(!1),[n,v]=k.useState(d.get(c)),g=k.useMemo(()=>F.createBinding(b,a,c,n,d),[b,a,c,d,n]),t=k.useCallback(()=>{a.connect()},[a]),u=k.useCallback(()=>{try{a.disconnect()}catch(m){}},[a]);k.useEffect(()=>{let {root:m}=g,{awareness:y}=a,z=({status:l})=>{b.dispatchCommand(F.CONNECTED_COMMAND,"connected"===l)},A=l=>{r&&l&&m.isEmpty()&&0===m._xmlText._length&&!1===p.current&&J(b);p.current=!1},B=()=>{F.syncCursorPositions(g,a)},C=(l,w)=>{w.origin!==g&&F.syncYjsChangesToLexical(g,
9
- a,l)};F.initLocalState(a,h,q,document.activeElement===b.getRootElement());let D=l=>{K(b,g);v(l);d.set(c,l);p.current=!0};a.on("reload",D);a.on("status",z);a.on("sync",A);y.on("update",B);m.getSharedType().observeDeep(C);let O=b.registerUpdateListener(({prevEditorState:l,editorState:w,dirtyLeaves:L,dirtyElements:M,normalizedNodes:N,tags:E})=>{!1===E.has("skip-collab")&&F.syncLexicalUpdateToYjs(g,a,l,w,M,L,N,E)});t();return()=>{!1===p.current&&u();a.off("sync",A);a.off("status",z);a.off("reload",D);
10
- y.off("update",B);m.getSharedType().unobserveDeep(C);d.delete(c);O()}},[g,q,t,u,d,b,c,h,a,r]);let P=k.useMemo(()=>H.createPortal(k.createElement("div",{ref:m=>{g.cursorsContainer=m}}),document.body),[g]);k.useEffect(()=>b.registerCommand(F.TOGGLE_CONNECT_COMMAND,m=>{void 0!==t&&void 0!==u&&(m?(console.log("Collaboration connected!"),t()):(console.log("Collaboration disconnected!"),u()));return!0},G.COMMAND_PRIORITY_EDITOR),[t,u,b]);return[P,g]}
11
- function Q(b,c,a,d){k.useEffect(()=>x.mergeRegister(b.registerCommand(G.FOCUS_COMMAND,()=>{F.setLocalStateFocus(c,a,d,!0);return!0},G.COMMAND_PRIORITY_EDITOR),b.registerCommand(G.BLUR_COMMAND,()=>{F.setLocalStateFocus(c,a,d,!1);return!0},G.COMMAND_PRIORITY_EDITOR)),[d,b,a,c])}
12
- function R(b,c){let a=k.useMemo(()=>F.createUndoManager(c,c.root.getSharedType()),[c]);k.useEffect(()=>x.mergeRegister(b.registerCommand(G.UNDO_COMMAND,()=>{a.undo();return!0},G.COMMAND_PRIORITY_EDITOR),b.registerCommand(G.REDO_COMMAND,()=>{a.redo();return!0},G.COMMAND_PRIORITY_EDITOR)));return k.useCallback(()=>{a.clear()},[a])}
13
- function J(b){b.update(()=>{var c=G.$getRoot();if(null===c.getFirstChild()){let a=G.$createParagraphNode();c.append(a);c=document.activeElement;(null!==G.$getSelection()||null!==c&&c===b.getRootElement())&&a.select()}},{tag:"history-merge"})}
14
- function K(b,c){b.update(()=>{let d=G.$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 h=0;h<a.length;h++)c.removeChild(a[d])}}}}
15
- exports.CollaborationPlugin=function({id:b,providerFactory:c,shouldBootstrap:a,username:d}){let h=e.useCollaborationContext(d),{yjsDocMap:q,name:r,color:p}=h,[n]=f.useLexicalComposerContext();k.useEffect(()=>{h.isCollabActive=!0;return()=>{null==n._parentEditor&&(h.isCollabActive=!1)}},[h,n]);d=k.useMemo(()=>c(b,q),[b,c,q]);let [v,g]=I(n,b,d,q,r,p,a);h.clientID=g.clientID;R(n,g);Q(n,d,r,p);return v}
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}
@@ -5,8 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { Klass } from 'lexical';
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)[];
@@ -74,7 +74,7 @@ function LexicalComposer({
74
74
  useLayoutEffect(() => {
75
75
  const isEditable = initialConfig.editable;
76
76
  const [editor] = composerContext;
77
- editor.setEditable(isEditable || true); // We only do this for init
77
+ editor.setEditable(isEditable !== undefined ? isEditable : true); // We only do this for init
78
78
  // eslint-disable-next-line react-hooks/exhaustive-deps
79
79
  }, []);
80
80
  return /*#__PURE__*/React.createElement(LexicalComposerContext.LexicalComposerContext.Provider, {
@@ -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) ; else if (initialEditorState !== null) {
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
  {
@@ -7,20 +7,27 @@
7
7
  * @flow strict
8
8
  */
9
9
 
10
- import type {EditorThemeClasses, LexicalEditor, LexicalNode} from 'lexical';
11
- import type {InitialEditorStateType as InitialEditorStatePlainTextType} from '@lexical/plain-text';
12
- import type {InitialEditorStateType as InitialEditorStateRichTextType} from '@lexical/rich-text';
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
- readOnly?: boolean,
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,
@@ -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 c=require("@lexical/react/LexicalComposerContext"),f=require("lexical"),l=require("react"),m="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement?l.useLayoutEffect:l.useEffect;let n={tag:"history-merge"};
8
- function p(b,a){if(null!==a&&void 0!==a&&null!==a)switch(typeof a){case "string":let d=b.parseEditorState(a);b.setEditorState(d,n);break;case "object":b.setEditorState(a,n);break;case "function":b.update(()=>{f.$getRoot().isEmpty()&&a(b)},n)}}
9
- exports.LexicalComposer=function({initialConfig:b,children:a}){let d=l.useMemo(()=>{const {theme:e,namespace:g,editor__DEPRECATED:q,nodes:r,onError:t,editorState:u}=b,v=c.createLexicalComposerContext(null,e);let h=q||null;if(null===h){const k=f.createEditor({editable:!1,namespace:g,nodes:r,onError:w=>t(w,k),theme:e});p(k,u);h=k}return[h,v]},[]);m(()=>{let e=b.editable,[g]=d;g.setEditable(e||!0)},[]);return l.createElement(c.LexicalComposerContext.Provider,{value:d},a)}
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(true);
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(!0),F=k.useCallback(d=>{c.setRootElement(d)},[c]);l(()=>{h(c.isEditable());return c.registerEditableListener(d=>{h(d)})},
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
- isTopLevel(): true;
24
+ isInline(): false;
23
25
  updateDOM(): false;
24
26
  decorate(): JSX.Element;
25
27
  }
@@ -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
- isTopLevel() {
98
- return true;
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"),n=require("lexical"),p=require("react");let q=n.createCommand();
8
- function r({nodeKey:b}){let [f]=a.useLexicalComposerContext(),l=p.useRef(null),[e,g,m]=d.useLexicalNodeSelection(b),k=p.useCallback(c=>{e&&n.$isNodeSelection(n.$getSelection())&&(c.preventDefault(),c=n.$getNodeByKey(b),t(c)&&c.remove(),g(!1));return!1},[e,b,g]);p.useEffect(()=>h.mergeRegister(f.registerCommand(n.CLICK_COMMAND,c=>c.target===l.current?(c.shiftKey||m(),g(!e),!0):!1,n.COMMAND_PRIORITY_LOW),f.registerCommand(n.KEY_DELETE_COMMAND,k,n.COMMAND_PRIORITY_LOW),f.registerCommand(n.KEY_BACKSPACE_COMMAND,
9
- k,n.COMMAND_PRIORITY_LOW)),[m,f,e,k,g]);return p.createElement("hr",{ref:l,className:e?"selected":void 0})}
10
- class u extends n.DecoratorNode{static getType(){return"horizontalrule"}static clone(b){return new u(b.__key)}static importJSON(){return v()}exportJSON(){return{type:"horizontalrule",version:1}}createDOM(){let b=document.createElement("div");b.style.display="contents";return b}getTextContent(){return"\n"}isTopLevel(){return!0}updateDOM(){return!1}decorate(){return p.createElement(r,{nodeKey:this.__key})}}function v(){return new u}function t(b){return b instanceof u}
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();
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