@lexical/react 0.35.1-nightly.20250924.0 → 0.36.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 (154) hide show
  1. package/ExtensionComponent.d.ts +42 -0
  2. package/LexicalAutoEmbedPlugin.dev.js +2 -0
  3. package/LexicalAutoEmbedPlugin.dev.mjs +2 -0
  4. package/LexicalAutoEmbedPlugin.prod.js +1 -1
  5. package/LexicalAutoEmbedPlugin.prod.mjs +1 -1
  6. package/LexicalAutoLinkPlugin.d.ts +2 -17
  7. package/LexicalAutoLinkPlugin.dev.js +7 -309
  8. package/LexicalAutoLinkPlugin.dev.mjs +9 -310
  9. package/LexicalAutoLinkPlugin.js.flow +4 -18
  10. package/LexicalAutoLinkPlugin.prod.js +1 -1
  11. package/LexicalAutoLinkPlugin.prod.mjs +1 -1
  12. package/LexicalClearEditorPlugin.dev.js +2 -23
  13. package/LexicalClearEditorPlugin.dev.mjs +2 -23
  14. package/LexicalClearEditorPlugin.prod.js +1 -1
  15. package/LexicalClearEditorPlugin.prod.mjs +1 -1
  16. package/LexicalClickableLinkPlugin.dev.js +5 -70
  17. package/LexicalClickableLinkPlugin.dev.mjs +6 -71
  18. package/LexicalClickableLinkPlugin.prod.js +1 -1
  19. package/LexicalClickableLinkPlugin.prod.mjs +1 -1
  20. package/LexicalCollaborationContext.prod.js +1 -1
  21. package/LexicalCollaborationContext.prod.mjs +1 -1
  22. package/LexicalCollaborationPlugin.dev.mjs +2 -2
  23. package/LexicalCollaborationPlugin.prod.mjs +1 -1
  24. package/LexicalContentEditable.dev.js +2 -3
  25. package/LexicalContentEditable.dev.mjs +2 -3
  26. package/LexicalContentEditable.prod.js +1 -1
  27. package/LexicalContentEditable.prod.mjs +1 -1
  28. package/LexicalContextMenuPlugin.dev.js +2 -0
  29. package/LexicalContextMenuPlugin.dev.mjs +4 -2
  30. package/LexicalContextMenuPlugin.prod.js +1 -1
  31. package/LexicalContextMenuPlugin.prod.mjs +1 -1
  32. package/LexicalDecoratorBlockNode.dev.js +1 -0
  33. package/LexicalDecoratorBlockNode.dev.mjs +1 -0
  34. package/LexicalDecoratorBlockNode.js.flow +7 -0
  35. package/LexicalDecoratorBlockNode.prod.js +1 -1
  36. package/LexicalDecoratorBlockNode.prod.mjs +1 -1
  37. package/LexicalDraggableBlockPlugin.dev.js +6 -0
  38. package/LexicalDraggableBlockPlugin.dev.mjs +6 -0
  39. package/LexicalDraggableBlockPlugin.prod.js +1 -1
  40. package/LexicalDraggableBlockPlugin.prod.mjs +1 -1
  41. package/LexicalExtensionComponent.dev.js +53 -0
  42. package/LexicalExtensionComponent.dev.mjs +51 -0
  43. package/LexicalExtensionComponent.js +11 -0
  44. package/LexicalExtensionComponent.js.flow +12 -0
  45. package/LexicalExtensionComponent.mjs +12 -0
  46. package/LexicalExtensionComponent.node.mjs +10 -0
  47. package/LexicalExtensionComponent.prod.js +9 -0
  48. package/LexicalExtensionComponent.prod.mjs +9 -0
  49. package/LexicalExtensionComposer.d.ts +69 -0
  50. package/LexicalExtensionComposer.dev.js +105 -0
  51. package/LexicalExtensionComposer.dev.mjs +103 -0
  52. package/LexicalExtensionComposer.js +11 -0
  53. package/LexicalExtensionComposer.js.flow +20 -0
  54. package/LexicalExtensionComposer.mjs +12 -0
  55. package/LexicalExtensionComposer.node.mjs +10 -0
  56. package/LexicalExtensionComposer.prod.js +9 -0
  57. package/LexicalExtensionComposer.prod.mjs +9 -0
  58. package/LexicalHashtagPlugin.dev.js +1 -136
  59. package/LexicalHashtagPlugin.dev.mjs +3 -138
  60. package/LexicalHashtagPlugin.prod.js +1 -1
  61. package/LexicalHashtagPlugin.prod.mjs +1 -1
  62. package/LexicalHorizontalRuleNode.d.ts +10 -11
  63. package/LexicalHorizontalRuleNode.dev.js +12 -26
  64. package/LexicalHorizontalRuleNode.dev.mjs +14 -27
  65. package/LexicalHorizontalRuleNode.js.flow +2 -3
  66. package/LexicalHorizontalRuleNode.prod.js +1 -1
  67. package/LexicalHorizontalRuleNode.prod.mjs +1 -1
  68. package/LexicalLinkPlugin.d.ts +1 -1
  69. package/LexicalLinkPlugin.dev.js +7 -52
  70. package/LexicalLinkPlugin.dev.mjs +8 -53
  71. package/LexicalLinkPlugin.prod.js +1 -1
  72. package/LexicalLinkPlugin.prod.mjs +1 -1
  73. package/LexicalListPlugin.js.flow +5 -0
  74. package/LexicalMarkdownShortcutPlugin.dev.mjs +1 -1
  75. package/LexicalMarkdownShortcutPlugin.prod.mjs +1 -1
  76. package/LexicalNestedComposer.js.flow +10 -6
  77. package/LexicalNodeContextMenuPlugin.dev.js +10 -0
  78. package/LexicalNodeContextMenuPlugin.dev.mjs +11 -1
  79. package/LexicalNodeContextMenuPlugin.prod.js +1 -1
  80. package/LexicalNodeContextMenuPlugin.prod.mjs +1 -1
  81. package/LexicalNodeMenuPlugin.dev.js +2 -0
  82. package/LexicalNodeMenuPlugin.dev.mjs +4 -2
  83. package/LexicalNodeMenuPlugin.prod.js +1 -1
  84. package/LexicalNodeMenuPlugin.prod.mjs +1 -1
  85. package/LexicalPlainTextPlugin.d.ts +1 -1
  86. package/LexicalPlainTextPlugin.dev.js +85 -30
  87. package/LexicalPlainTextPlugin.dev.mjs +85 -30
  88. package/LexicalPlainTextPlugin.prod.js +1 -1
  89. package/LexicalPlainTextPlugin.prod.mjs +1 -1
  90. package/LexicalReactExtension.dev.js +187 -0
  91. package/LexicalReactExtension.dev.mjs +184 -0
  92. package/LexicalReactExtension.js +11 -0
  93. package/LexicalReactExtension.js.flow +68 -0
  94. package/LexicalReactExtension.mjs +13 -0
  95. package/LexicalReactExtension.node.mjs +11 -0
  96. package/LexicalReactExtension.prod.js +9 -0
  97. package/LexicalReactExtension.prod.mjs +9 -0
  98. package/LexicalReactPluginHostExtension.dev.js +189 -0
  99. package/LexicalReactPluginHostExtension.dev.mjs +181 -0
  100. package/LexicalReactPluginHostExtension.js +11 -0
  101. package/LexicalReactPluginHostExtension.js.flow +84 -0
  102. package/LexicalReactPluginHostExtension.mjs +18 -0
  103. package/LexicalReactPluginHostExtension.node.mjs +16 -0
  104. package/LexicalReactPluginHostExtension.prod.js +9 -0
  105. package/LexicalReactPluginHostExtension.prod.mjs +9 -0
  106. package/LexicalReactProviderExtension.dev.js +33 -0
  107. package/LexicalReactProviderExtension.dev.mjs +31 -0
  108. package/LexicalReactProviderExtension.js +11 -0
  109. package/LexicalReactProviderExtension.js.flow +12 -0
  110. package/LexicalReactProviderExtension.mjs +12 -0
  111. package/LexicalReactProviderExtension.node.mjs +10 -0
  112. package/LexicalReactProviderExtension.prod.js +9 -0
  113. package/LexicalReactProviderExtension.prod.mjs +9 -0
  114. package/LexicalRichTextPlugin.d.ts +1 -1
  115. package/LexicalRichTextPlugin.dev.js +85 -30
  116. package/LexicalRichTextPlugin.dev.mjs +85 -30
  117. package/LexicalRichTextPlugin.prod.js +1 -1
  118. package/LexicalRichTextPlugin.prod.mjs +1 -1
  119. package/LexicalTabIndentationPlugin.d.ts +2 -2
  120. package/LexicalTabIndentationPlugin.dev.js +3 -57
  121. package/LexicalTabIndentationPlugin.dev.mjs +3 -56
  122. package/LexicalTabIndentationPlugin.prod.js +1 -1
  123. package/LexicalTabIndentationPlugin.prod.mjs +1 -1
  124. package/LexicalTreeViewExtension.dev.js +57 -0
  125. package/LexicalTreeViewExtension.dev.mjs +54 -0
  126. package/LexicalTreeViewExtension.js +11 -0
  127. package/LexicalTreeViewExtension.js.flow +12 -0
  128. package/LexicalTreeViewExtension.mjs +13 -0
  129. package/LexicalTreeViewExtension.node.mjs +11 -0
  130. package/LexicalTreeViewExtension.prod.js +9 -0
  131. package/LexicalTreeViewExtension.prod.mjs +9 -0
  132. package/LexicalTypeaheadMenuPlugin.dev.js +2 -0
  133. package/LexicalTypeaheadMenuPlugin.dev.mjs +4 -2
  134. package/LexicalTypeaheadMenuPlugin.prod.js +1 -1
  135. package/LexicalTypeaheadMenuPlugin.prod.mjs +1 -1
  136. package/ReactExtension.d.ts +41 -0
  137. package/ReactPluginHostExtension.d.ts +56 -0
  138. package/ReactProviderExtension.d.ts +9 -0
  139. package/TreeViewExtension.d.ts +18 -0
  140. package/package.json +228 -17
  141. package/shared/LegacyDecorators.d.ts +23 -0
  142. package/shared/buildEditorComponent.d.ts +11 -0
  143. package/shared/mergeRefs.d.ts +2 -1
  144. package/shared/types.d.ts +89 -0
  145. package/shared/useReactDecorators.d.ts +12 -0
  146. package/useExtensionComponent.d.ts +10 -0
  147. package/useLexicalExtensionComponent.dev.js +37 -0
  148. package/useLexicalExtensionComponent.dev.mjs +34 -0
  149. package/useLexicalExtensionComponent.js +11 -0
  150. package/useLexicalExtensionComponent.js.flow +12 -0
  151. package/useLexicalExtensionComponent.mjs +13 -0
  152. package/useLexicalExtensionComponent.node.mjs +11 -0
  153. package/useLexicalExtensionComponent.prod.js +9 -0
  154. package/useLexicalExtensionComponent.prod.mjs +9 -0
@@ -14,9 +14,13 @@ import type {
14
14
  LexicalNodeReplacement,
15
15
  } from 'lexical';
16
16
 
17
- declare export function LexicalNestedComposer({
18
- children: React.Node,
19
- initialEditor: LexicalEditor,
20
- initialTheme?: EditorThemeClasses,
21
- initialNodes?: $ReadOnlyArray<Class<LexicalNode> | LexicalNodeReplacement>,
22
- }): React.Node;
17
+ export type LexicalNestedComposerProps = {
18
+ children?: React.Node;
19
+ initialEditor: LexicalEditor;
20
+ initialTheme?: EditorThemeClasses;
21
+ initialNodes?: $ReadOnlyArray<Class<LexicalNode> | LexicalNodeReplacement>;
22
+ skipCollabChecks?: void | true;
23
+ skipEditableListener?: void | true;
24
+ };
25
+
26
+ declare export function LexicalNestedComposer(props: LexicalNestedComposerProps): React.Node;
@@ -23,6 +23,8 @@ var jsxRuntime = require('react/jsx-runtime');
23
23
  */
24
24
 
25
25
  class MenuOption {
26
+ key;
27
+ ref;
26
28
  constructor(key) {
27
29
  this.key = key;
28
30
  this.ref = {
@@ -37,6 +39,12 @@ class MenuOption {
37
39
  }
38
40
  }
39
41
  class NodeContextMenuOption extends MenuOption {
42
+ type;
43
+ title;
44
+ icon;
45
+ disabled;
46
+ $onSelect;
47
+ $showOn;
40
48
  constructor(title, options) {
41
49
  super(title);
42
50
  this.type = 'item';
@@ -50,6 +58,8 @@ class NodeContextMenuOption extends MenuOption {
50
58
  }
51
59
  }
52
60
  class NodeContextMenuSeparator extends MenuOption {
61
+ type;
62
+ $showOn;
53
63
  constructor(options) {
54
64
  super('_separator');
55
65
  this.type = 'separator';
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
 
9
- import { useFloating, offset, flip, shift, autoUpdate, useRole, useDismiss, useListNavigation, useTypeahead, useInteractions, FloatingPortal, FloatingOverlay, FloatingFocusManager } from '@floating-ui/react';
9
+ import { useFloating, autoUpdate, offset, flip, shift, useRole, useDismiss, useListNavigation, useTypeahead, useInteractions, FloatingPortal, FloatingOverlay, FloatingFocusManager } from '@floating-ui/react';
10
10
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
11
11
  import { $getNearestNodeFromDOMNode } from 'lexical';
12
12
  import { forwardRef, useState, useRef, useEffect, createElement } from 'react';
@@ -21,6 +21,8 @@ import { jsx, jsxs } from 'react/jsx-runtime';
21
21
  */
22
22
 
23
23
  class MenuOption {
24
+ key;
25
+ ref;
24
26
  constructor(key) {
25
27
  this.key = key;
26
28
  this.ref = {
@@ -35,6 +37,12 @@ class MenuOption {
35
37
  }
36
38
  }
37
39
  class NodeContextMenuOption extends MenuOption {
40
+ type;
41
+ title;
42
+ icon;
43
+ disabled;
44
+ $onSelect;
45
+ $showOn;
38
46
  constructor(title, options) {
39
47
  super(title);
40
48
  this.type = 'item';
@@ -48,6 +56,8 @@ class NodeContextMenuOption extends MenuOption {
48
56
  }
49
57
  }
50
58
  class NodeContextMenuSeparator extends MenuOption {
59
+ type;
60
+ $showOn;
51
61
  constructor(options) {
52
62
  super('_separator');
53
63
  this.type = 'separator';
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const l=n.forwardRef((({className:e,disabled:t,...s},n)=>i.jsx("hr",{className:e}))),r=n.forwardRef((({className:e,label:t,disabled:s,icon:n,...a},l)=>i.jsxs("button",{...a,className:e,ref:l,role:"menuitem",disabled:s,children:[n,t]}))),o=n.forwardRef((({items:a,className:o,itemClassName:c,separatorClassName:u},d)=>{const[m]=t.useLexicalComposerContext(),[p,h]=n.useState(null),[f,x]=n.useState(!1),g=n.useRef([]),y=n.useRef([]),{refs:N,floatingStyles:b,context:k}=e.useFloating({middleware:[e.offset({alignmentAxis:4,mainAxis:5}),e.flip({fallbackPlacements:["left-start"]}),e.shift({padding:10})],onOpenChange:x,open:f,placement:"right-start",strategy:"fixed",whileElementsMounted:e.autoUpdate}),C=e.useRole(k,{role:"menu"}),w=e.useDismiss(k),R=e.useListNavigation(k,{activeIndex:p,listRef:g,onNavigate:h}),v=e.useTypeahead(k,{activeIndex:p,enabled:f,listRef:y,onMatch:h}),{getFloatingProps:O,getItemProps:$}=e.useInteractions([C,w,R,v]),[E,F]=n.useState([]);return n.useEffect((()=>{function e(e){e.preventDefault(),N.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];a&&m.read((()=>{const n=s.$getNearestNodeFromDOMNode(e.target);n&&(t=a.filter((e=>!e.$showOn||e.$showOn(n))))}));const n=t.map(((e,t)=>"separator"===e.type?{className:u,key:e.key+"-"+t,type:e.type}:{className:c,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>m.update((()=>e.$onSelect())),title:e.title,type:e.type}));y.current=n.map((e=>e.key)),F(n),x(!0)}return m.registerRootListener(((t,s)=>{null!==s&&s.removeEventListener("contextmenu",e),null!==t&&t.addEventListener("contextmenu",e)}))}),[a,c,u,N,m]),i.jsx(e.FloatingPortal,{children:f&&i.jsx(e.FloatingOverlay,{lockScroll:!0,children:i.jsx(e.FloatingFocusManager,{context:k,initialFocus:N.floating,children:i.jsx("div",{className:o,ref:N.setFloating,style:b,...O(),children:E.map(((e,t)=>"item"===e.type?n.createElement(r,{...$({...e,onClick(){e.onClick(),x(!1)},onMouseUp(){e.onClick(),x(!1)},ref(e){g.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):"separator"===e.type?n.createElement(l,{...$({...e,ref(e){g.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):void 0))})})})})}));exports.NodeContextMenuOption=class extends a{constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}},exports.NodeContextMenuPlugin=o,exports.NodeContextMenuSeparator=class extends a{constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}};
9
+ "use strict";var e=require("@floating-ui/react"),t=require("@lexical/react/LexicalComposerContext"),s=require("lexical"),n=require("react"),i=require("react/jsx-runtime");class a{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}const l=n.forwardRef((({className:e,disabled:t,...s},n)=>i.jsx("hr",{className:e}))),o=n.forwardRef((({className:e,label:t,disabled:s,icon:n,...a},l)=>i.jsxs("button",{...a,className:e,ref:l,role:"menuitem",disabled:s,children:[n,t]}))),r=n.forwardRef((({items:a,className:r,itemClassName:c,separatorClassName:u},d)=>{const[m]=t.useLexicalComposerContext(),[p,h]=n.useState(null),[f,x]=n.useState(!1),y=n.useRef([]),g=n.useRef([]),{refs:N,floatingStyles:b,context:k}=e.useFloating({middleware:[e.offset({alignmentAxis:4,mainAxis:5}),e.flip({fallbackPlacements:["left-start"]}),e.shift({padding:10})],onOpenChange:x,open:f,placement:"right-start",strategy:"fixed",whileElementsMounted:e.autoUpdate}),w=e.useRole(k,{role:"menu"}),C=e.useDismiss(k),$=e.useListNavigation(k,{activeIndex:p,listRef:y,onNavigate:h}),O=e.useTypeahead(k,{activeIndex:p,enabled:f,listRef:g,onMatch:h}),{getFloatingProps:R,getItemProps:v}=e.useInteractions([w,C,$,O]),[S,E]=n.useState([]);return n.useEffect((()=>{function e(e){e.preventDefault(),N.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];a&&m.read((()=>{const n=s.$getNearestNodeFromDOMNode(e.target);n&&(t=a.filter((e=>!e.$showOn||e.$showOn(n))))}));const n=t.map(((e,t)=>"separator"===e.type?{className:u,key:e.key+"-"+t,type:e.type}:{className:c,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>m.update((()=>e.$onSelect())),title:e.title,type:e.type}));g.current=n.map((e=>e.key)),E(n),x(!0)}return m.registerRootListener(((t,s)=>{null!==s&&s.removeEventListener("contextmenu",e),null!==t&&t.addEventListener("contextmenu",e)}))}),[a,c,u,N,m]),i.jsx(e.FloatingPortal,{children:f&&i.jsx(e.FloatingOverlay,{lockScroll:!0,children:i.jsx(e.FloatingFocusManager,{context:k,initialFocus:N.floating,children:i.jsx("div",{className:r,ref:N.setFloating,style:b,...R(),children:S.map(((e,t)=>"item"===e.type?n.createElement(o,{...v({...e,onClick(){e.onClick(),x(!1)},onMouseUp(){e.onClick(),x(!1)},ref(e){y.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):"separator"===e.type?n.createElement(l,{...v({...e,ref(e){y.current[t]=e},tabIndex:p===t?0:-1}),key:e.key}):void 0))})})})})}));exports.NodeContextMenuOption=class extends a{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}},exports.NodeContextMenuPlugin=r,exports.NodeContextMenuSeparator=class extends a{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useFloating as e,offset as t,flip as n,shift as s,autoUpdate as i,useRole as l,useDismiss as o,useListNavigation as r,useTypeahead as a,useInteractions as c,FloatingPortal as m,FloatingOverlay as d,FloatingFocusManager as h}from"@floating-ui/react";import{useLexicalComposerContext as p}from"@lexical/react/LexicalComposerContext";import{$getNearestNodeFromDOMNode as u}from"lexical";import{forwardRef as f,useState as y,useRef as x,useEffect as g,createElement as b}from"react";import{jsx as k,jsxs as w}from"react/jsx-runtime";class N{constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}class $ extends N{constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}}class C extends N{constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}}const v=f((({className:e,disabled:t,...n},s)=>k("hr",{className:e}))),O=f((({className:e,label:t,disabled:n,icon:s,...i},l)=>w("button",{...i,className:e,ref:l,role:"menuitem",disabled:n,children:[s,t]}))),R=f((({items:f,className:w,itemClassName:N,separatorClassName:$},C)=>{const[R]=p(),[E,I]=y(null),[S,L]=y(!1),P=x([]),F=x([]),{refs:M,floatingStyles:X,context:Y}=e({middleware:[t({alignmentAxis:4,mainAxis:5}),n({fallbackPlacements:["left-start"]}),s({padding:10})],onOpenChange:L,open:S,placement:"right-start",strategy:"fixed",whileElementsMounted:i}),A=l(Y,{role:"menu"}),j=o(Y),B=r(Y,{activeIndex:E,listRef:P,onNavigate:I}),D=a(Y,{activeIndex:E,enabled:S,listRef:F,onMatch:I}),{getFloatingProps:U,getItemProps:_}=c([A,j,B,D]),[q,z]=y([]);return g((()=>{function e(e){e.preventDefault(),M.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];f&&R.read((()=>{const n=u(e.target);n&&(t=f.filter((e=>!e.$showOn||e.$showOn(n))))}));const n=t.map(((e,t)=>"separator"===e.type?{className:$,key:e.key+"-"+t,type:e.type}:{className:N,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>R.update((()=>e.$onSelect())),title:e.title,type:e.type}));F.current=n.map((e=>e.key)),z(n),L(!0)}return R.registerRootListener(((t,n)=>{null!==n&&n.removeEventListener("contextmenu",e),null!==t&&t.addEventListener("contextmenu",e)}))}),[f,N,$,M,R]),k(m,{children:S&&k(d,{lockScroll:!0,children:k(h,{context:Y,initialFocus:M.floating,children:k("div",{className:w,ref:M.setFloating,style:X,...U(),children:q.map(((e,t)=>"item"===e.type?b(O,{..._({...e,onClick(){e.onClick(),L(!1)},onMouseUp(){e.onClick(),L(!1)},ref(e){P.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):"separator"===e.type?b(v,{..._({...e,ref(e){P.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):void 0))})})})})}));export{$ as NodeContextMenuOption,R as NodeContextMenuPlugin,C as NodeContextMenuSeparator};
9
+ import{useFloating as e,autoUpdate as t,offset as n,flip as s,shift as i,useRole as l,useDismiss as o,useListNavigation as r,useTypeahead as a,useInteractions as c,FloatingPortal as m,FloatingOverlay as d,FloatingFocusManager as h}from"@floating-ui/react";import{useLexicalComposerContext as p}from"@lexical/react/LexicalComposerContext";import{$getNearestNodeFromDOMNode as u}from"lexical";import{forwardRef as f,useState as y,useRef as x,useEffect as g,createElement as b}from"react";import{jsx as k,jsxs as $}from"react/jsx-runtime";class w{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}}class N extends w{type;title;icon;disabled;$onSelect;$showOn;constructor(e,t){super(e),this.type="item",this.title=e,this.disabled=t.disabled??!1,this.icon=t.icon??null,this.$onSelect=t.$onSelect,t.$showOn&&(this.$showOn=t.$showOn)}}class O extends w{type;$showOn;constructor(e){super("_separator"),this.type="separator",e&&e.$showOn&&(this.$showOn=e.$showOn)}}const C=f((({className:e,disabled:t,...n},s)=>k("hr",{className:e}))),v=f((({className:e,label:t,disabled:n,icon:s,...i},l)=>$("button",{...i,className:e,ref:l,role:"menuitem",disabled:n,children:[s,t]}))),R=f((({items:f,className:$,itemClassName:w,separatorClassName:N},O)=>{const[R]=p(),[E,S]=y(null),[I,L]=y(!1),P=x([]),F=x([]),{refs:M,floatingStyles:X,context:Y}=e({middleware:[n({alignmentAxis:4,mainAxis:5}),s({fallbackPlacements:["left-start"]}),i({padding:10})],onOpenChange:L,open:I,placement:"right-start",strategy:"fixed",whileElementsMounted:t}),A=l(Y,{role:"menu"}),j=o(Y),B=r(Y,{activeIndex:E,listRef:P,onNavigate:S}),D=a(Y,{activeIndex:E,enabled:I,listRef:F,onMatch:S}),{getFloatingProps:U,getItemProps:_}=c([A,j,B,D]),[q,z]=y([]);return g((()=>{function e(e){e.preventDefault(),M.setPositionReference({getBoundingClientRect:()=>({bottom:e.clientY,height:0,left:e.clientX,right:e.clientX,top:e.clientY,width:0,x:e.clientX,y:e.clientY})});let t=[];f&&R.read((()=>{const n=u(e.target);n&&(t=f.filter((e=>!e.$showOn||e.$showOn(n))))}));const n=t.map(((e,t)=>"separator"===e.type?{className:N,key:e.key+"-"+t,type:e.type}:{className:w,disabled:e.disabled,icon:e.icon,key:e.key,label:e.title,onClick:()=>R.update((()=>e.$onSelect())),title:e.title,type:e.type}));F.current=n.map((e=>e.key)),z(n),L(!0)}return R.registerRootListener(((t,n)=>{null!==n&&n.removeEventListener("contextmenu",e),null!==t&&t.addEventListener("contextmenu",e)}))}),[f,w,N,M,R]),k(m,{children:I&&k(d,{lockScroll:!0,children:k(h,{context:Y,initialFocus:M.floating,children:k("div",{className:$,ref:M.setFloating,style:X,...U(),children:q.map(((e,t)=>"item"===e.type?b(v,{..._({...e,onClick(){e.onClick(),L(!1)},onMouseUp(){e.onClick(),L(!1)},ref(e){P.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):"separator"===e.type?b(C,{..._({...e,ref(e){P.current[t]=e},tabIndex:E===t?0:-1}),key:e.key}):void 0))})})})})}));export{N as NodeContextMenuOption,R as NodeContextMenuPlugin,O as NodeContextMenuSeparator};
@@ -68,6 +68,8 @@ const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffec
68
68
  */
69
69
 
70
70
  class MenuOption {
71
+ key;
72
+ ref;
71
73
  constructor(key) {
72
74
  this.key = key;
73
75
  this.ref = {
@@ -7,8 +7,8 @@
7
7
  */
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
- import { createCommand, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW, $getSelection, $isRangeSelection, $getNodeByKey } from 'lexical';
11
- import React, { useLayoutEffect, useEffect, useState, useCallback, useMemo, useRef } from 'react';
10
+ import { createCommand, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, $getNodeByKey } from 'lexical';
11
+ import React, { useLayoutEffect, useEffect, useRef, useCallback, useState, useMemo } from 'react';
12
12
  import { mergeRegister } from '@lexical/utils';
13
13
  import { jsx } from 'react/jsx-runtime';
14
14
 
@@ -66,6 +66,8 @@ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
66
66
  */
67
67
 
68
68
  class MenuOption {
69
+ key;
70
+ ref;
69
71
  constructor(key) {
70
72
  this.key = key;
71
73
  this.ref = {
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),n=require("react"),l=require("@lexical/utils"),o=require("react/jsx-runtime");const r="startTransition";const i="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,u=i?n.useLayoutEffect:n.useEffect;const s=e=>{const t=document.getElementById("typeahead-menu");if(!t)return;const n=t.getBoundingClientRect();n.top+n.height>window.innerHeight&&t.scrollIntoView({block:"center"}),n.top<0&&t.scrollIntoView({block:"center"}),e.scrollIntoView({block:"nearest"})};function c(e,t){const n=e.getBoundingClientRect(),l=t.getBoundingClientRect();return n.top>=l.top-6&&n.top<=l.bottom+6}function a(t,l,o,r){const[i]=e.useLexicalComposerContext();n.useEffect((()=>{if(null!=l&&null!=t){const e=i.getRootElement(),t=null!=e?function(e,t){let n=getComputedStyle(e);const l="absolute"===n.position,o=/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let t=e;t=t.parentElement;)if(n=getComputedStyle(t),(!l||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX))return t;return document.body}(e):document.body;let n=!1,u=c(l,t);const s=function(){n||(window.requestAnimationFrame((function(){o(),n=!1})),n=!0);const e=c(l,t);e!==u&&(u=e,null!=r&&r(e))},a=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",s,{capture:!0,passive:!0}),a.observe(l),()=>{a.unobserve(l),window.removeEventListener("resize",o),document.removeEventListener("scroll",s,!0)}}}),[l,i,r,o,t])}const d=t.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function m({close:e,editor:o,anchorElementRef:r,resolution:i,options:c,menuRenderFn:a,onSelectOption:m,shouldSplitNodeWithQuery:f=!1,commandPriority:p=t.COMMAND_PRIORITY_LOW,preselectFirstItem:g=!0}){const[h,C]=n.useState(null),E=i.match&&i.match.matchingString;n.useEffect((()=>{g&&C(0)}),[E,g]);const y=n.useCallback((n=>{o.update((()=>{const l=null!=i.match&&f?function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return null;const l=n.anchor;if("text"!==l.type)return null;const o=l.getNode();if(!o.isSimpleText())return null;const r=l.offset,i=o.getTextContent().slice(0,r),u=e.replaceableString.length,s=r-function(e,t,n){let l=n;for(let n=l;n<=t.length;n++)e.slice(-n)===t.substring(0,n)&&(l=n);return l}(i,e.matchingString,u);if(s<0)return null;let c;return 0===s?[c]=o.splitText(r):[,c]=o.splitText(s,r),c}(i.match):null;m(n,l,e,i.match?i.match.matchingString:"")}))}),[o,f,i.match,m,e]),b=n.useCallback((e=>{const t=o.getRootElement();null!==t&&(t.setAttribute("aria-activedescendant","typeahead-item-"+e),C(e))}),[o]);n.useEffect((()=>()=>{const e=o.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")}),[o]),u((()=>{null===c?C(null):null===h&&g&&b(0)}),[c,h,b,g]),n.useEffect((()=>l.mergeRegister(o.registerCommand(d,(({option:e})=>!(!e.ref||null==e.ref.current)&&(s(e.ref.current),!0)),p))),[o,b,p]),n.useEffect((()=>l.mergeRegister(o.registerCommand(t.KEY_ARROW_DOWN_COMMAND,(e=>{const t=e;if(null!==c&&c.length){const e=null===h?0:h!==c.length-1?h+1:0;b(e);const n=c[e];null!=n.ref&&n.ref.current&&o.dispatchCommand(d,{index:e,option:n}),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(t.KEY_ARROW_UP_COMMAND,(e=>{const t=e;if(null!==c&&c.length){const e=null===h?c.length-1:0!==h?h-1:c.length-1;b(e);const n=c[e];null!=n.ref&&n.ref.current&&s(n.ref.current),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(t.KEY_ESCAPE_COMMAND,(t=>{const n=t;return n.preventDefault(),n.stopImmediatePropagation(),e(),!0}),p),o.registerCommand(t.KEY_TAB_COMMAND,(e=>{const t=e;return null!==c&&null!==h&&null!=c[h]&&(t.preventDefault(),t.stopImmediatePropagation(),y(c[h]),!0)}),p),o.registerCommand(t.KEY_ENTER_COMMAND,(e=>null!==c&&null!==h&&null!=c[h]&&(null!==e&&(e.preventDefault(),e.stopImmediatePropagation()),y(c[h]),!0)),p))),[y,e,o,c,h,b,p]);return a(r,n.useMemo((()=>({options:c,selectOptionAndCleanUp:y,selectedIndex:h,setHighlightedIndex:C})),[y,h,c]),i.match?i.match.matchingString:"")}function f(e,t){null!=t&&(e.className=t),e.setAttribute("aria-label","Typeahead menu"),e.setAttribute("role","listbox"),e.style.display="block",e.style.position="absolute"}exports.LexicalNodeMenuPlugin=function({options:l,nodeKey:u,onClose:s,onOpen:c,onSelectOption:d,menuRenderFn:p,anchorClassName:g,commandPriority:h=t.COMMAND_PRIORITY_LOW,parent:C}){const[E]=e.useLexicalComposerContext(),[y,b]=n.useState(null),R=function(t,l,o,r=(i?document.body:void 0),u=!0){const[s]=e.useLexicalComposerContext(),c=i?document.createElement("div"):null,d=n.useRef(c),m=n.useCallback((()=>{if(null===d.current||void 0===r)return;d.current.style.top=d.current.style.bottom;const e=s.getRootElement(),n=d.current,l=n.firstChild;if(null!==e&&null!==t){const{left:i,top:s,width:c,height:a}=t.getRect(),m=d.current.offsetHeight;if(n.style.top=`${s+m+3+(u?window.pageYOffset:0)}px`,n.style.left=`${i+window.pageXOffset}px`,n.style.height=`${a}px`,n.style.width=`${c}px`,null!==l){l.style.top=`${s}`;const t=l.getBoundingClientRect(),o=t.height,r=t.width,c=e.getBoundingClientRect();i+r>c.right&&(n.style.left=`${c.right-r+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+a&&(n.style.top=`${s-o-a+(u?window.pageYOffset:0)}px`)}n.isConnected||(f(n,o),r.append(n)),n.setAttribute("id","typeahead-menu"),e.setAttribute("aria-controls","typeahead-menu")}}),[s,t,u,o,r]);n.useEffect((()=>{const e=s.getRootElement();return null!==t&&m(),()=>{null!==e&&e.removeAttribute("aria-controls");const t=d.current;null!==t&&t.isConnected&&(t.remove(),t.removeAttribute("id"))}}),[s,m,t]);const p=n.useCallback((e=>{null!==t&&(e||l(null))}),[t,l]);return a(t,d.current,m,p),null!=c&&c===d.current&&(f(c,o),null!=r&&r.append(c)),d}(y,b,g,C),w=n.useCallback((()=>{b(null),null!=s&&null!==y&&s()}),[s,y]),x=n.useCallback((e=>{b(e),null!=c&&null===y&&c(e)}),[c,y]),v=n.useCallback((()=>{u?E.update((()=>{const e=t.$getNodeByKey(u),l=E.getElementByKey(u);var o;null!=e&&null!=l&&null==y&&(o=()=>x({getRect:()=>l.getBoundingClientRect()}),r in n?n[r](o):o())})):null==u&&null!=y&&w()}),[w,E,u,x,y]);return n.useEffect((()=>{v()}),[v,u]),n.useEffect((()=>{if(null!=u)return E.registerUpdateListener((({dirtyElements:e})=>{e.get(u)&&v()}))}),[E,v,u]),null===R.current||null===y||null===E?null:o.jsx(m,{close:w,resolution:y,editor:E,anchorElementRef:R,options:l,menuRenderFn:p,onSelectOption:d,commandPriority:h})},exports.MenuOption=class{constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}};
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("lexical"),n=require("react"),l=require("@lexical/utils"),o=require("react/jsx-runtime");const r="startTransition";const i="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,u=i?n.useLayoutEffect:n.useEffect;const s=e=>{const t=document.getElementById("typeahead-menu");if(!t)return;const n=t.getBoundingClientRect();n.top+n.height>window.innerHeight&&t.scrollIntoView({block:"center"}),n.top<0&&t.scrollIntoView({block:"center"}),e.scrollIntoView({block:"nearest"})};function c(e,t){const n=e.getBoundingClientRect(),l=t.getBoundingClientRect();return n.top>=l.top-6&&n.top<=l.bottom+6}function a(t,l,o,r){const[i]=e.useLexicalComposerContext();n.useEffect((()=>{if(null!=l&&null!=t){const e=i.getRootElement(),t=null!=e?function(e,t){let n=getComputedStyle(e);const l="absolute"===n.position,o=/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let t=e;t=t.parentElement;)if(n=getComputedStyle(t),(!l||"static"!==n.position)&&o.test(n.overflow+n.overflowY+n.overflowX))return t;return document.body}(e):document.body;let n=!1,u=c(l,t);const s=function(){n||(window.requestAnimationFrame((function(){o(),n=!1})),n=!0);const e=c(l,t);e!==u&&(u=e,null!=r&&r(e))},a=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",s,{capture:!0,passive:!0}),a.observe(l),()=>{a.unobserve(l),window.removeEventListener("resize",o),document.removeEventListener("scroll",s,!0)}}}),[l,i,r,o,t])}const d=t.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function m({close:e,editor:o,anchorElementRef:r,resolution:i,options:c,menuRenderFn:a,onSelectOption:m,shouldSplitNodeWithQuery:f=!1,commandPriority:p=t.COMMAND_PRIORITY_LOW,preselectFirstItem:g=!0}){const[h,C]=n.useState(null),E=i.match&&i.match.matchingString;n.useEffect((()=>{g&&C(0)}),[E,g]);const y=n.useCallback((n=>{o.update((()=>{const l=null!=i.match&&f?function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n)||!n.isCollapsed())return null;const l=n.anchor;if("text"!==l.type)return null;const o=l.getNode();if(!o.isSimpleText())return null;const r=l.offset,i=o.getTextContent().slice(0,r),u=e.replaceableString.length,s=r-function(e,t,n){let l=n;for(let n=l;n<=t.length;n++)e.slice(-n)===t.substring(0,n)&&(l=n);return l}(i,e.matchingString,u);if(s<0)return null;let c;return 0===s?[c]=o.splitText(r):[,c]=o.splitText(s,r),c}(i.match):null;m(n,l,e,i.match?i.match.matchingString:"")}))}),[o,f,i.match,m,e]),b=n.useCallback((e=>{const t=o.getRootElement();null!==t&&(t.setAttribute("aria-activedescendant","typeahead-item-"+e),C(e))}),[o]);n.useEffect((()=>()=>{const e=o.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")}),[o]),u((()=>{null===c?C(null):null===h&&g&&b(0)}),[c,h,b,g]),n.useEffect((()=>l.mergeRegister(o.registerCommand(d,(({option:e})=>!(!e.ref||null==e.ref.current)&&(s(e.ref.current),!0)),p))),[o,b,p]),n.useEffect((()=>l.mergeRegister(o.registerCommand(t.KEY_ARROW_DOWN_COMMAND,(e=>{const t=e;if(null!==c&&c.length){const e=null===h?0:h!==c.length-1?h+1:0;b(e);const n=c[e];null!=n.ref&&n.ref.current&&o.dispatchCommand(d,{index:e,option:n}),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(t.KEY_ARROW_UP_COMMAND,(e=>{const t=e;if(null!==c&&c.length){const e=null===h?c.length-1:0!==h?h-1:c.length-1;b(e);const n=c[e];null!=n.ref&&n.ref.current&&s(n.ref.current),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(t.KEY_ESCAPE_COMMAND,(t=>{const n=t;return n.preventDefault(),n.stopImmediatePropagation(),e(),!0}),p),o.registerCommand(t.KEY_TAB_COMMAND,(e=>{const t=e;return null!==c&&null!==h&&null!=c[h]&&(t.preventDefault(),t.stopImmediatePropagation(),y(c[h]),!0)}),p),o.registerCommand(t.KEY_ENTER_COMMAND,(e=>null!==c&&null!==h&&null!=c[h]&&(null!==e&&(e.preventDefault(),e.stopImmediatePropagation()),y(c[h]),!0)),p))),[y,e,o,c,h,b,p]);return a(r,n.useMemo((()=>({options:c,selectOptionAndCleanUp:y,selectedIndex:h,setHighlightedIndex:C})),[y,h,c]),i.match?i.match.matchingString:"")}function f(e,t){null!=t&&(e.className=t),e.setAttribute("aria-label","Typeahead menu"),e.setAttribute("role","listbox"),e.style.display="block",e.style.position="absolute"}exports.LexicalNodeMenuPlugin=function({options:l,nodeKey:u,onClose:s,onOpen:c,onSelectOption:d,menuRenderFn:p,anchorClassName:g,commandPriority:h=t.COMMAND_PRIORITY_LOW,parent:C}){const[E]=e.useLexicalComposerContext(),[y,b]=n.useState(null),R=function(t,l,o,r=(i?document.body:void 0),u=!0){const[s]=e.useLexicalComposerContext(),c=i?document.createElement("div"):null,d=n.useRef(c),m=n.useCallback((()=>{if(null===d.current||void 0===r)return;d.current.style.top=d.current.style.bottom;const e=s.getRootElement(),n=d.current,l=n.firstChild;if(null!==e&&null!==t){const{left:i,top:s,width:c,height:a}=t.getRect(),m=d.current.offsetHeight;if(n.style.top=`${s+m+3+(u?window.pageYOffset:0)}px`,n.style.left=`${i+window.pageXOffset}px`,n.style.height=`${a}px`,n.style.width=`${c}px`,null!==l){l.style.top=`${s}`;const t=l.getBoundingClientRect(),o=t.height,r=t.width,c=e.getBoundingClientRect();i+r>c.right&&(n.style.left=`${c.right-r+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+a&&(n.style.top=`${s-o-a+(u?window.pageYOffset:0)}px`)}n.isConnected||(f(n,o),r.append(n)),n.setAttribute("id","typeahead-menu"),e.setAttribute("aria-controls","typeahead-menu")}}),[s,t,u,o,r]);n.useEffect((()=>{const e=s.getRootElement();return null!==t&&m(),()=>{null!==e&&e.removeAttribute("aria-controls");const t=d.current;null!==t&&t.isConnected&&(t.remove(),t.removeAttribute("id"))}}),[s,m,t]);const p=n.useCallback((e=>{null!==t&&(e||l(null))}),[t,l]);return a(t,d.current,m,p),null!=c&&c===d.current&&(f(c,o),null!=r&&r.append(c)),d}(y,b,g,C),w=n.useCallback((()=>{b(null),null!=s&&null!==y&&s()}),[s,y]),x=n.useCallback((e=>{b(e),null!=c&&null===y&&c(e)}),[c,y]),v=n.useCallback((()=>{u?E.update((()=>{const e=t.$getNodeByKey(u),l=E.getElementByKey(u);var o;null!=e&&null!=l&&null==y&&(o=()=>x({getRect:()=>l.getBoundingClientRect()}),r in n?n[r](o):o())})):null==u&&null!=y&&w()}),[w,E,u,x,y]);return n.useEffect((()=>{v()}),[v,u]),n.useEffect((()=>{if(null!=u)return E.registerUpdateListener((({dirtyElements:e})=>{e.get(u)&&v()}))}),[E,v,u]),null===R.current||null===y||null===E?null:o.jsx(m,{close:w,resolution:y,editor:E,anchorElementRef:R,options:l,menuRenderFn:p,onSelectOption:d,commandPriority:h})},exports.MenuOption=class{key;ref;constructor(e){this.key=e,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(e){this.ref={current:e}}};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createCommand as e,KEY_ARROW_DOWN_COMMAND as n,KEY_ARROW_UP_COMMAND as o,KEY_ESCAPE_COMMAND as l,KEY_TAB_COMMAND as r,KEY_ENTER_COMMAND as i,COMMAND_PRIORITY_LOW as u,$getSelection as s,$isRangeSelection as c,$getNodeByKey as a}from"lexical";import m,{useLayoutEffect as d,useEffect as p,useState as f,useCallback as g,useMemo as h,useRef as y}from"react";import{mergeRegister as w}from"@lexical/utils";import{jsx as v}from"react/jsx-runtime";const b="startTransition";const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,x=C?d:p;class E{constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const R=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const n=e.getBoundingClientRect();n.top+n.height>window.innerHeight&&e.scrollIntoView({block:"center"}),n.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function I(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>=o.top-6&&n.top<=o.bottom+6}function O(e,n,o,l){const[r]=t();p((()=>{if(null!=n&&null!=e){const t=r.getRootElement(),e=null!=t?function(t,e){let n=getComputedStyle(t);const o="absolute"===n.position,l=/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let e=t;e=e.parentElement;)if(n=getComputedStyle(e),(!o||"static"!==n.position)&&l.test(n.overflow+n.overflowY+n.overflowX))return e;return document.body}(t):document.body;let i=!1,u=I(n,e);const s=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=I(n,e);t!==u&&(u=t,null!=l&&l(t))},c=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",s,{capture:!0,passive:!0}),c.observe(n),()=>{c.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",s,!0)}}}),[n,r,l,o,e])}const A=e("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function S({close:t,editor:e,anchorElementRef:a,resolution:m,options:d,menuRenderFn:y,onSelectOption:v,shouldSplitNodeWithQuery:b=!1,commandPriority:C=u,preselectFirstItem:E=!0}){const[I,O]=f(null),S=m.match&&m.match.matchingString;p((()=>{E&&O(0)}),[S,E]);const P=g((n=>{e.update((()=>{const e=null!=m.match&&b?function(t){const e=s();if(!c(e)||!e.isCollapsed())return null;const n=e.anchor;if("text"!==n.type)return null;const o=n.getNode();if(!o.isSimpleText())return null;const l=n.offset,r=o.getTextContent().slice(0,l),i=t.replaceableString.length,u=l-function(t,e,n){let o=n;for(let n=o;n<=e.length;n++)t.slice(-n)===e.substring(0,n)&&(o=n);return o}(r,t.matchingString,i);if(u<0)return null;let a;return 0===u?[a]=o.splitText(l):[,a]=o.splitText(u,l),a}(m.match):null;v(n,e,t,m.match?m.match.matchingString:"")}))}),[e,b,m.match,v,t]),T=g((t=>{const n=e.getRootElement();null!==n&&(n.setAttribute("aria-activedescendant","typeahead-item-"+t),O(t))}),[e]);p((()=>()=>{const t=e.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[e]),x((()=>{null===d?O(null):null===I&&E&&T(0)}),[d,I,T,E]),p((()=>w(e.registerCommand(A,(({option:t})=>!(!t.ref||null==t.ref.current)&&(R(t.ref.current),!0)),C))),[e,T,C]),p((()=>w(e.registerCommand(n,(t=>{const n=t;if(null!==d&&d.length){const t=null===I?0:I!==d.length-1?I+1:0;T(t);const o=d[t];null!=o.ref&&o.ref.current&&e.dispatchCommand(A,{index:t,option:o}),n.preventDefault(),n.stopImmediatePropagation()}return!0}),C),e.registerCommand(o,(t=>{const e=t;if(null!==d&&d.length){const t=null===I?d.length-1:0!==I?I-1:d.length-1;T(t);const n=d[t];null!=n.ref&&n.ref.current&&R(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),e.registerCommand(l,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),C),e.registerCommand(r,(t=>{const e=t;return null!==d&&null!==I&&null!=d[I]&&(e.preventDefault(),e.stopImmediatePropagation(),P(d[I]),!0)}),C),e.registerCommand(i,(t=>null!==d&&null!==I&&null!=d[I]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),P(d[I]),!0)),C))),[P,t,e,d,I,T,C]);return y(a,h((()=>({options:d,selectOptionAndCleanUp:P,selectedIndex:I,setHighlightedIndex:O})),[P,I,d]),m.match?m.match.matchingString:"")}function P(t,e){null!=e&&(t.className=e),t.setAttribute("aria-label","Typeahead menu"),t.setAttribute("role","listbox"),t.style.display="block",t.style.position="absolute"}function T({options:e,nodeKey:n,onClose:o,onOpen:l,onSelectOption:r,menuRenderFn:i,anchorClassName:s,commandPriority:c=u,parent:d}){const[h]=t(),[w,x]=f(null),E=function(e,n,o,l=(C?document.body:void 0),r=!0){const[i]=t(),u=C?document.createElement("div"):null,s=y(u),c=g((()=>{if(null===s.current||void 0===l)return;s.current.style.top=s.current.style.bottom;const t=i.getRootElement(),n=s.current,u=n.firstChild;if(null!==t&&null!==e){const{left:i,top:c,width:a,height:m}=e.getRect(),d=s.current.offsetHeight;if(n.style.top=`${c+d+3+(r?window.pageYOffset:0)}px`,n.style.left=`${i+window.pageXOffset}px`,n.style.height=`${m}px`,n.style.width=`${a}px`,null!==u){u.style.top=`${c}`;const e=u.getBoundingClientRect(),o=e.height,l=e.width,s=t.getBoundingClientRect();i+l>s.right&&(n.style.left=`${s.right-l+window.pageXOffset}px`),(c+o>window.innerHeight||c+o>s.bottom)&&c-s.top>o+m&&(n.style.top=`${c-o-m+(r?window.pageYOffset:0)}px`)}n.isConnected||(P(n,o),l.append(n)),n.setAttribute("id","typeahead-menu"),t.setAttribute("aria-controls","typeahead-menu")}}),[i,e,r,o,l]);p((()=>{const t=i.getRootElement();return null!==e&&c(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=s.current;null!==e&&e.isConnected&&(e.remove(),e.removeAttribute("id"))}}),[i,c,e]);const a=g((t=>{null!==e&&(t||n(null))}),[e,n]);return O(e,s.current,c,a),null!=u&&u===s.current&&(P(u,o),null!=l&&l.append(u)),s}(w,x,s,d),R=g((()=>{x(null),null!=o&&null!==w&&o()}),[o,w]),I=g((t=>{x(t),null!=l&&null===w&&l(t)}),[l,w]),A=g((()=>{n?h.update((()=>{const t=a(n),e=h.getElementByKey(n);var o;null!=t&&null!=e&&null==w&&(o=()=>I({getRect:()=>e.getBoundingClientRect()}),b in m?m[b](o):o())})):null==n&&null!=w&&R()}),[R,h,n,I,w]);return p((()=>{A()}),[A,n]),p((()=>{if(null!=n)return h.registerUpdateListener((({dirtyElements:t})=>{t.get(n)&&A()}))}),[h,A,n]),null===E.current||null===w||null===h?null:v(S,{close:R,resolution:w,editor:h,anchorElementRef:E,options:e,menuRenderFn:i,onSelectOption:r,commandPriority:c})}export{T as LexicalNodeMenuPlugin,E as MenuOption};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{createCommand as e,COMMAND_PRIORITY_LOW as n,KEY_ARROW_DOWN_COMMAND as o,KEY_ARROW_UP_COMMAND as l,KEY_ESCAPE_COMMAND as r,KEY_TAB_COMMAND as i,KEY_ENTER_COMMAND as u,$getSelection as s,$isRangeSelection as c,$getNodeByKey as a}from"lexical";import m,{useLayoutEffect as d,useEffect as p,useRef as f,useCallback as g,useState as h,useMemo as y}from"react";import{mergeRegister as w}from"@lexical/utils";import{jsx as v}from"react/jsx-runtime";const b="startTransition";const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,x=C?d:p;class E{key;ref;constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const R=t=>{const e=document.getElementById("typeahead-menu");if(!e)return;const n=e.getBoundingClientRect();n.top+n.height>window.innerHeight&&e.scrollIntoView({block:"center"}),n.top<0&&e.scrollIntoView({block:"center"}),t.scrollIntoView({block:"nearest"})};function I(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>=o.top-6&&n.top<=o.bottom+6}function O(e,n,o,l){const[r]=t();p((()=>{if(null!=n&&null!=e){const t=r.getRootElement(),e=null!=t?function(t,e){let n=getComputedStyle(t);const o="absolute"===n.position,l=/(auto|scroll)/;if("fixed"===n.position)return document.body;for(let e=t;e=e.parentElement;)if(n=getComputedStyle(e),(!o||"static"!==n.position)&&l.test(n.overflow+n.overflowY+n.overflowX))return e;return document.body}(t):document.body;let i=!1,u=I(n,e);const s=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=I(n,e);t!==u&&(u=t,null!=l&&l(t))},c=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",s,{capture:!0,passive:!0}),c.observe(n),()=>{c.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",s,!0)}}}),[n,r,l,o,e])}const A=e("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function S({close:t,editor:e,anchorElementRef:a,resolution:m,options:d,menuRenderFn:f,onSelectOption:v,shouldSplitNodeWithQuery:b=!1,commandPriority:C=n,preselectFirstItem:E=!0}){const[I,O]=h(null),S=m.match&&m.match.matchingString;p((()=>{E&&O(0)}),[S,E]);const P=g((n=>{e.update((()=>{const e=null!=m.match&&b?function(t){const e=s();if(!c(e)||!e.isCollapsed())return null;const n=e.anchor;if("text"!==n.type)return null;const o=n.getNode();if(!o.isSimpleText())return null;const l=n.offset,r=o.getTextContent().slice(0,l),i=t.replaceableString.length,u=l-function(t,e,n){let o=n;for(let n=o;n<=e.length;n++)t.slice(-n)===e.substring(0,n)&&(o=n);return o}(r,t.matchingString,i);if(u<0)return null;let a;return 0===u?[a]=o.splitText(l):[,a]=o.splitText(u,l),a}(m.match):null;v(n,e,t,m.match?m.match.matchingString:"")}))}),[e,b,m.match,v,t]),T=g((t=>{const n=e.getRootElement();null!==n&&(n.setAttribute("aria-activedescendant","typeahead-item-"+t),O(t))}),[e]);p((()=>()=>{const t=e.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[e]),x((()=>{null===d?O(null):null===I&&E&&T(0)}),[d,I,T,E]),p((()=>w(e.registerCommand(A,(({option:t})=>!(!t.ref||null==t.ref.current)&&(R(t.ref.current),!0)),C))),[e,T,C]),p((()=>w(e.registerCommand(o,(t=>{const n=t;if(null!==d&&d.length){const t=null===I?0:I!==d.length-1?I+1:0;T(t);const o=d[t];null!=o.ref&&o.ref.current&&e.dispatchCommand(A,{index:t,option:o}),n.preventDefault(),n.stopImmediatePropagation()}return!0}),C),e.registerCommand(l,(t=>{const e=t;if(null!==d&&d.length){const t=null===I?d.length-1:0!==I?I-1:d.length-1;T(t);const n=d[t];null!=n.ref&&n.ref.current&&R(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),e.registerCommand(r,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),C),e.registerCommand(i,(t=>{const e=t;return null!==d&&null!==I&&null!=d[I]&&(e.preventDefault(),e.stopImmediatePropagation(),P(d[I]),!0)}),C),e.registerCommand(u,(t=>null!==d&&null!==I&&null!=d[I]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),P(d[I]),!0)),C))),[P,t,e,d,I,T,C]);return f(a,y((()=>({options:d,selectOptionAndCleanUp:P,selectedIndex:I,setHighlightedIndex:O})),[P,I,d]),m.match?m.match.matchingString:"")}function P(t,e){null!=e&&(t.className=e),t.setAttribute("aria-label","Typeahead menu"),t.setAttribute("role","listbox"),t.style.display="block",t.style.position="absolute"}function T({options:e,nodeKey:o,onClose:l,onOpen:r,onSelectOption:i,menuRenderFn:u,anchorClassName:s,commandPriority:c=n,parent:d}){const[y]=t(),[w,x]=h(null),E=function(e,n,o,l=(C?document.body:void 0),r=!0){const[i]=t(),u=C?document.createElement("div"):null,s=f(u),c=g((()=>{if(null===s.current||void 0===l)return;s.current.style.top=s.current.style.bottom;const t=i.getRootElement(),n=s.current,u=n.firstChild;if(null!==t&&null!==e){const{left:i,top:c,width:a,height:m}=e.getRect(),d=s.current.offsetHeight;if(n.style.top=`${c+d+3+(r?window.pageYOffset:0)}px`,n.style.left=`${i+window.pageXOffset}px`,n.style.height=`${m}px`,n.style.width=`${a}px`,null!==u){u.style.top=`${c}`;const e=u.getBoundingClientRect(),o=e.height,l=e.width,s=t.getBoundingClientRect();i+l>s.right&&(n.style.left=`${s.right-l+window.pageXOffset}px`),(c+o>window.innerHeight||c+o>s.bottom)&&c-s.top>o+m&&(n.style.top=`${c-o-m+(r?window.pageYOffset:0)}px`)}n.isConnected||(P(n,o),l.append(n)),n.setAttribute("id","typeahead-menu"),t.setAttribute("aria-controls","typeahead-menu")}}),[i,e,r,o,l]);p((()=>{const t=i.getRootElement();return null!==e&&c(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=s.current;null!==e&&e.isConnected&&(e.remove(),e.removeAttribute("id"))}}),[i,c,e]);const a=g((t=>{null!==e&&(t||n(null))}),[e,n]);return O(e,s.current,c,a),null!=u&&u===s.current&&(P(u,o),null!=l&&l.append(u)),s}(w,x,s,d),R=g((()=>{x(null),null!=l&&null!==w&&l()}),[l,w]),I=g((t=>{x(t),null!=r&&null===w&&r(t)}),[r,w]),A=g((()=>{o?y.update((()=>{const t=a(o),e=y.getElementByKey(o);var n;null!=t&&null!=e&&null==w&&(n=()=>I({getRect:()=>e.getBoundingClientRect()}),b in m?m[b](n):n())})):null==o&&null!=w&&R()}),[R,y,o,I,w]);return p((()=>{A()}),[A,o]),p((()=>{if(null!=o)return y.registerUpdateListener((({dirtyElements:t})=>{t.get(o)&&A()}))}),[y,A,o]),null===E.current||null===w||null===y?null:v(S,{close:R,resolution:w,editor:y,anchorElementRef:E,options:e,menuRenderFn:u,onSelectOption:i,commandPriority:c})}export{T as LexicalNodeMenuPlugin,E as MenuOption};
@@ -6,7 +6,7 @@
6
6
  *
7
7
  */
8
8
  import type { JSX } from 'react';
9
- import { ErrorBoundaryType } from './shared/useDecorators';
9
+ import { type ErrorBoundaryType } from './shared/LegacyDecorators';
10
10
  export declare function PlainTextPlugin({ contentEditable, placeholder, ErrorBoundary, }: {
11
11
  contentEditable: JSX.Element;
12
12
  placeholder?: ((isEditable: boolean) => null | JSX.Element) | null | JSX.Element;
@@ -10,11 +10,13 @@
10
10
 
11
11
  var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
12
12
  var useLexicalEditable = require('@lexical/react/useLexicalEditable');
13
- var text = require('@lexical/text');
14
- var utils = require('@lexical/utils');
13
+ var extension = require('@lexical/extension');
14
+ var ReactProviderExtension = require('@lexical/react/ReactProviderExtension');
15
15
  var react = require('react');
16
16
  var reactDom = require('react-dom');
17
17
  var jsxRuntime = require('react/jsx-runtime');
18
+ var text = require('@lexical/text');
19
+ var utils = require('@lexical/utils');
18
20
  var dragon = require('@lexical/dragon');
19
21
  var plainText = require('@lexical/plain-text');
20
22
 
@@ -26,7 +28,11 @@ var plainText = require('@lexical/plain-text');
26
28
  *
27
29
  */
28
30
 
29
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
31
+ // Do not require this module directly! Use normal `invariant` calls.
32
+
33
+ function formatDevErrorMessage(message) {
34
+ throw new Error(message);
35
+ }
30
36
 
31
37
  /**
32
38
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -36,11 +42,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
36
42
  *
37
43
  */
38
44
 
39
-
40
- // This workaround is no longer necessary in React 19,
41
- // but we currently support React >=17.x
42
- // https://github.com/facebook/react/pull/26395
43
- const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
45
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
44
46
 
45
47
  /**
46
48
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -50,26 +52,11 @@ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffec
50
52
  *
51
53
  */
52
54
 
53
- function canShowPlaceholderFromCurrentEditorState(editor) {
54
- const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
55
- return currentCanShowPlaceholder;
56
- }
57
- function useCanShowPlaceholder(editor) {
58
- const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
59
- useLayoutEffectImpl(() => {
60
- function resetCanShowPlaceholder() {
61
- const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
62
- setCanShowPlaceholder(currentCanShowPlaceholder);
63
- }
64
- resetCanShowPlaceholder();
65
- return utils.mergeRegister(editor.registerUpdateListener(() => {
66
- resetCanShowPlaceholder();
67
- }), editor.registerEditableListener(() => {
68
- resetCanShowPlaceholder();
69
- }));
70
- }, [editor]);
71
- return canShowPlaceholder;
72
- }
55
+
56
+ // This workaround is no longer necessary in React 19,
57
+ // but we currently support React >=17.x
58
+ // https://github.com/facebook/react/pull/26395
59
+ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffect;
73
60
 
74
61
  /**
75
62
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -119,6 +106,72 @@ function useDecorators(editor, ErrorBoundary) {
119
106
  }, [ErrorBoundary, decorators, editor]);
120
107
  }
121
108
 
109
+ function isUsingReactExtension(editor) {
110
+ const builder = extension.LexicalBuilder.maybeFromEditor(editor);
111
+ if (builder && builder.hasExtensionByName(ReactProviderExtension.ReactProviderExtension.name)) {
112
+ for (const name of ['@lexical/plain-text', '@lexical/rich-text']) {
113
+ if (!!builder.hasExtensionByName(name)) {
114
+ formatDevErrorMessage(`LexicalBuilder: @lexical/react legacy text plugins conflict with the ${name} extension. Remove the legacy <RichTextPlugin/> or <PlainTextPlugin/> component.`);
115
+ }
116
+ }
117
+ return true;
118
+ }
119
+ return false;
120
+ }
121
+ function Decorators({
122
+ editor,
123
+ ErrorBoundary
124
+ }) {
125
+ return useDecorators(editor, ErrorBoundary);
126
+ }
127
+
128
+ /**
129
+ * @internal
130
+ *
131
+ * When using @lexical/extension, the ReactProvider is expected to handle
132
+ * rendering decorators. This component allows RichTextPlugin and
133
+ * PlainTextPlugin to be used in extension projects that have not yet
134
+ * migrated to use RichTextExtension or PlainTextExtension.
135
+ **/
136
+ function LegacyDecorators({
137
+ editor,
138
+ ErrorBoundary
139
+ }) {
140
+ return isUsingReactExtension(editor) ? null : /*#__PURE__*/jsxRuntime.jsx(Decorators, {
141
+ editor: editor,
142
+ ErrorBoundary: ErrorBoundary
143
+ });
144
+ }
145
+
146
+ /**
147
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
148
+ *
149
+ * This source code is licensed under the MIT license found in the
150
+ * LICENSE file in the root directory of this source tree.
151
+ *
152
+ */
153
+
154
+ function canShowPlaceholderFromCurrentEditorState(editor) {
155
+ const currentCanShowPlaceholder = editor.getEditorState().read(text.$canShowPlaceholderCurry(editor.isComposing()));
156
+ return currentCanShowPlaceholder;
157
+ }
158
+ function useCanShowPlaceholder(editor) {
159
+ const [canShowPlaceholder, setCanShowPlaceholder] = react.useState(() => canShowPlaceholderFromCurrentEditorState(editor));
160
+ useLayoutEffectImpl(() => {
161
+ function resetCanShowPlaceholder() {
162
+ const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
163
+ setCanShowPlaceholder(currentCanShowPlaceholder);
164
+ }
165
+ resetCanShowPlaceholder();
166
+ return utils.mergeRegister(editor.registerUpdateListener(() => {
167
+ resetCanShowPlaceholder();
168
+ }), editor.registerEditableListener(() => {
169
+ resetCanShowPlaceholder();
170
+ }));
171
+ }, [editor]);
172
+ return canShowPlaceholder;
173
+ }
174
+
122
175
  /**
123
176
  * Copyright (c) Meta Platforms, Inc. and affiliates.
124
177
  *
@@ -151,12 +204,14 @@ function PlainTextPlugin({
151
204
  ErrorBoundary
152
205
  }) {
153
206
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
154
- const decorators = useDecorators(editor, ErrorBoundary);
155
207
  usePlainTextSetup(editor);
156
208
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
157
209
  children: [contentEditable, /*#__PURE__*/jsxRuntime.jsx(Placeholder, {
158
210
  content: placeholder
159
- }), decorators]
211
+ }), /*#__PURE__*/jsxRuntime.jsx(LegacyDecorators, {
212
+ editor: editor,
213
+ ErrorBoundary: ErrorBoundary
214
+ })]
160
215
  });
161
216
  }
162
217
 
@@ -8,11 +8,13 @@
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
10
  import { useLexicalEditable } from '@lexical/react/useLexicalEditable';
11
- import { $canShowPlaceholderCurry } from '@lexical/text';
12
- import { mergeRegister } from '@lexical/utils';
11
+ import { LexicalBuilder } from '@lexical/extension';
12
+ import { ReactProviderExtension } from '@lexical/react/ReactProviderExtension';
13
13
  import { useLayoutEffect, useEffect, useState, useMemo, Suspense } from 'react';
14
14
  import { flushSync, createPortal } from 'react-dom';
15
15
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
16
+ import { $canShowPlaceholderCurry } from '@lexical/text';
17
+ import { mergeRegister } from '@lexical/utils';
16
18
  import { registerDragonSupport } from '@lexical/dragon';
17
19
  import { registerPlainText } from '@lexical/plain-text';
18
20
 
@@ -24,7 +26,11 @@ import { registerPlainText } from '@lexical/plain-text';
24
26
  *
25
27
  */
26
28
 
27
- const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
29
+ // Do not require this module directly! Use normal `invariant` calls.
30
+
31
+ function formatDevErrorMessage(message) {
32
+ throw new Error(message);
33
+ }
28
34
 
29
35
  /**
30
36
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -34,11 +40,7 @@ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !==
34
40
  *
35
41
  */
36
42
 
37
-
38
- // This workaround is no longer necessary in React 19,
39
- // but we currently support React >=17.x
40
- // https://github.com/facebook/react/pull/26395
41
- const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
43
+ const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
42
44
 
43
45
  /**
44
46
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -48,26 +50,11 @@ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
48
50
  *
49
51
  */
50
52
 
51
- function canShowPlaceholderFromCurrentEditorState(editor) {
52
- const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
53
- return currentCanShowPlaceholder;
54
- }
55
- function useCanShowPlaceholder(editor) {
56
- const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
57
- useLayoutEffectImpl(() => {
58
- function resetCanShowPlaceholder() {
59
- const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
60
- setCanShowPlaceholder(currentCanShowPlaceholder);
61
- }
62
- resetCanShowPlaceholder();
63
- return mergeRegister(editor.registerUpdateListener(() => {
64
- resetCanShowPlaceholder();
65
- }), editor.registerEditableListener(() => {
66
- resetCanShowPlaceholder();
67
- }));
68
- }, [editor]);
69
- return canShowPlaceholder;
70
- }
53
+
54
+ // This workaround is no longer necessary in React 19,
55
+ // but we currently support React >=17.x
56
+ // https://github.com/facebook/react/pull/26395
57
+ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
71
58
 
72
59
  /**
73
60
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -117,6 +104,72 @@ function useDecorators(editor, ErrorBoundary) {
117
104
  }, [ErrorBoundary, decorators, editor]);
118
105
  }
119
106
 
107
+ function isUsingReactExtension(editor) {
108
+ const builder = LexicalBuilder.maybeFromEditor(editor);
109
+ if (builder && builder.hasExtensionByName(ReactProviderExtension.name)) {
110
+ for (const name of ['@lexical/plain-text', '@lexical/rich-text']) {
111
+ if (!!builder.hasExtensionByName(name)) {
112
+ formatDevErrorMessage(`LexicalBuilder: @lexical/react legacy text plugins conflict with the ${name} extension. Remove the legacy <RichTextPlugin/> or <PlainTextPlugin/> component.`);
113
+ }
114
+ }
115
+ return true;
116
+ }
117
+ return false;
118
+ }
119
+ function Decorators({
120
+ editor,
121
+ ErrorBoundary
122
+ }) {
123
+ return useDecorators(editor, ErrorBoundary);
124
+ }
125
+
126
+ /**
127
+ * @internal
128
+ *
129
+ * When using @lexical/extension, the ReactProvider is expected to handle
130
+ * rendering decorators. This component allows RichTextPlugin and
131
+ * PlainTextPlugin to be used in extension projects that have not yet
132
+ * migrated to use RichTextExtension or PlainTextExtension.
133
+ **/
134
+ function LegacyDecorators({
135
+ editor,
136
+ ErrorBoundary
137
+ }) {
138
+ return isUsingReactExtension(editor) ? null : /*#__PURE__*/jsx(Decorators, {
139
+ editor: editor,
140
+ ErrorBoundary: ErrorBoundary
141
+ });
142
+ }
143
+
144
+ /**
145
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
146
+ *
147
+ * This source code is licensed under the MIT license found in the
148
+ * LICENSE file in the root directory of this source tree.
149
+ *
150
+ */
151
+
152
+ function canShowPlaceholderFromCurrentEditorState(editor) {
153
+ const currentCanShowPlaceholder = editor.getEditorState().read($canShowPlaceholderCurry(editor.isComposing()));
154
+ return currentCanShowPlaceholder;
155
+ }
156
+ function useCanShowPlaceholder(editor) {
157
+ const [canShowPlaceholder, setCanShowPlaceholder] = useState(() => canShowPlaceholderFromCurrentEditorState(editor));
158
+ useLayoutEffectImpl(() => {
159
+ function resetCanShowPlaceholder() {
160
+ const currentCanShowPlaceholder = canShowPlaceholderFromCurrentEditorState(editor);
161
+ setCanShowPlaceholder(currentCanShowPlaceholder);
162
+ }
163
+ resetCanShowPlaceholder();
164
+ return mergeRegister(editor.registerUpdateListener(() => {
165
+ resetCanShowPlaceholder();
166
+ }), editor.registerEditableListener(() => {
167
+ resetCanShowPlaceholder();
168
+ }));
169
+ }, [editor]);
170
+ return canShowPlaceholder;
171
+ }
172
+
120
173
  /**
121
174
  * Copyright (c) Meta Platforms, Inc. and affiliates.
122
175
  *
@@ -149,12 +202,14 @@ function PlainTextPlugin({
149
202
  ErrorBoundary
150
203
  }) {
151
204
  const [editor] = useLexicalComposerContext();
152
- const decorators = useDecorators(editor, ErrorBoundary);
153
205
  usePlainTextSetup(editor);
154
206
  return /*#__PURE__*/jsxs(Fragment, {
155
207
  children: [contentEditable, /*#__PURE__*/jsx(Placeholder, {
156
208
  content: placeholder
157
- }), decorators]
209
+ }), /*#__PURE__*/jsx(LegacyDecorators, {
210
+ editor: editor,
211
+ ErrorBoundary: ErrorBoundary
212
+ })]
158
213
  });
159
214
  }
160
215
 
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/react/useLexicalEditable"),r=require("@lexical/text"),n=require("@lexical/utils"),o=require("react"),i=require("react-dom"),c=require("react/jsx-runtime"),u=require("@lexical/dragon"),s=require("@lexical/plain-text");const l="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o.useLayoutEffect:o.useEffect;function a(e){return e.getEditorState().read(r.$canShowPlaceholderCurry(e.isComposing()))}function d({content:r}){const[i]=e.useLexicalComposerContext(),c=function(e){const[t,r]=o.useState((()=>a(e)));return l((()=>{function t(){const t=a(e);r(t)}return t(),n.mergeRegister(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(i),u=t.useLexicalEditable();return c?"function"==typeof r?r(u):r:null}exports.PlainTextPlugin=function({contentEditable:t,placeholder:r=null,ErrorBoundary:a}){const[x]=e.useLexicalComposerContext(),f=function(e,t){const[r,n]=o.useState((()=>e.getDecorators()));return l((()=>e.registerDecoratorListener((e=>{i.flushSync((()=>{n(e)}))}))),[e]),o.useEffect((()=>{n(e.getDecorators())}),[e]),o.useMemo((()=>{const n=[],u=Object.keys(r);for(let s=0;s<u.length;s++){const l=u[s],a=c.jsx(t,{onError:t=>e._onError(t),children:c.jsx(o.Suspense,{fallback:null,children:r[l]})}),d=e.getElementByKey(l);null!==d&&n.push(i.createPortal(a,d,l))}return n}),[t,r,e])}(x,a);return function(e){l((()=>n.mergeRegister(s.registerPlainText(e),u.registerDragonSupport(e))),[e])}(x),c.jsxs(c.Fragment,{children:[t,c.jsx(d,{content:r}),f]})};
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),r=require("@lexical/react/useLexicalEditable"),t=require("@lexical/extension"),n=require("@lexical/react/ReactProviderExtension"),o=require("react"),i=require("react-dom"),c=require("react/jsx-runtime"),a=require("@lexical/text"),s=require("@lexical/utils"),l=require("@lexical/dragon"),u=require("@lexical/plain-text");function d(e,...r){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(const e of r)n.append("v",e);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const x="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?o.useLayoutEffect:o.useEffect;function f({editor:e,ErrorBoundary:r}){return function(e,r){const[t,n]=o.useState((()=>e.getDecorators()));return x((()=>e.registerDecoratorListener((e=>{i.flushSync((()=>{n(e)}))}))),[e]),o.useEffect((()=>{n(e.getDecorators())}),[e]),o.useMemo((()=>{const n=[],a=Object.keys(t);for(let s=0;s<a.length;s++){const l=a[s],u=c.jsx(r,{onError:r=>e._onError(r),children:c.jsx(o.Suspense,{fallback:null,children:t[l]})}),d=e.getElementByKey(l);null!==d&&n.push(i.createPortal(u,d,l))}return n}),[r,t,e])}(e,r)}function g({editor:e,ErrorBoundary:r}){return function(e){const r=t.LexicalBuilder.maybeFromEditor(e);if(r&&r.hasExtensionByName(n.ReactProviderExtension.name)){for(const e of["@lexical/plain-text","@lexical/rich-text"])r.hasExtensionByName(e)&&d(320,e);return!0}return!1}(e)?null:c.jsx(f,{editor:e,ErrorBoundary:r})}function m(e){return e.getEditorState().read(a.$canShowPlaceholderCurry(e.isComposing()))}function E({content:t}){const[n]=e.useLexicalComposerContext(),i=function(e){const[r,t]=o.useState((()=>m(e)));return x((()=>{function r(){const r=m(e);t(r)}return r(),s.mergeRegister(e.registerUpdateListener((()=>{r()})),e.registerEditableListener((()=>{r()})))}),[e]),r}(n),c=r.useLexicalEditable();return i?"function"==typeof t?t(c):t:null}exports.PlainTextPlugin=function({contentEditable:r,placeholder:t=null,ErrorBoundary:n}){const[o]=e.useLexicalComposerContext();return function(e){x((()=>s.mergeRegister(u.registerPlainText(e),l.registerDragonSupport(e))),[e])}(o),c.jsxs(c.Fragment,{children:[r,c.jsx(E,{content:t}),c.jsx(g,{editor:o,ErrorBoundary:n})]})};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{$canShowPlaceholderCurry as r}from"@lexical/text";import{mergeRegister as o}from"@lexical/utils";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as l,Suspense as a}from"react";import{flushSync as u,createPortal as m}from"react-dom";import{jsx as s,jsxs as d,Fragment as f}from"react/jsx-runtime";import{registerDragonSupport as p}from"@lexical/dragon";import{registerPlainText as x}from"@lexical/plain-text";const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function E(t){return t.getEditorState().read(r(t.isComposing()))}function h({contentEditable:e,placeholder:r=null,ErrorBoundary:n}){const[E]=t(),h=function(t,e){const[r,o]=c((()=>t.getDecorators()));return g((()=>t.registerDecoratorListener((t=>{u((()=>{o(t)}))}))),[t]),i((()=>{o(t.getDecorators())}),[t]),l((()=>{const o=[],n=Object.keys(r);for(let i=0;i<n.length;i++){const c=n[i],l=s(e,{onError:e=>t._onError(e),children:s(a,{fallback:null,children:r[c]})}),u=t.getElementByKey(c);null!==u&&o.push(m(l,u,c))}return o}),[e,r,t])}(E,n);return function(t){g((()=>o(x(t),p(t))),[t])}(E),d(f,{children:[e,s(w,{content:r}),h]})}function w({content:r}){const[n]=t(),i=function(t){const[e,r]=c((()=>E(t)));return g((()=>{function e(){const e=E(t);r(e)}return e(),o(t.registerUpdateListener((()=>{e()})),t.registerEditableListener((()=>{e()})))}),[t]),e}(n),l=e();return i?"function"==typeof r?r(l):r:null}export{h as PlainTextPlugin};
9
+ import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{useLexicalEditable as e}from"@lexical/react/useLexicalEditable";import{LexicalBuilder as t}from"@lexical/extension";import{ReactProviderExtension as o}from"@lexical/react/ReactProviderExtension";import{useLayoutEffect as n,useEffect as i,useState as c,useMemo as a,Suspense as l}from"react";import{flushSync as s,createPortal as u}from"react-dom";import{jsx as d,jsxs as f,Fragment as m}from"react/jsx-runtime";import{$canShowPlaceholderCurry as p}from"@lexical/text";import{mergeRegister as x}from"@lexical/utils";import{registerDragonSupport as E}from"@lexical/dragon";import{registerPlainText as h}from"@lexical/plain-text";function g(r,...e){const t=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",r);for(const r of e)o.append("v",r);throw t.search=o.toString(),Error(`Minified Lexical error #${r}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const y="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?n:i;function w({editor:r,ErrorBoundary:e}){return function(r,e){const[t,o]=c((()=>r.getDecorators()));return y((()=>r.registerDecoratorListener((r=>{s((()=>{o(r)}))}))),[r]),i((()=>{o(r.getDecorators())}),[r]),a((()=>{const o=[],n=Object.keys(t);for(let i=0;i<n.length;i++){const c=n[i],a=d(e,{onError:e=>r._onError(e),children:d(l,{fallback:null,children:t[c]})}),s=r.getElementByKey(c);null!==s&&o.push(u(a,s,c))}return o}),[e,t,r])}(r,e)}function v({editor:r,ErrorBoundary:e}){return function(r){const e=t.maybeFromEditor(r);if(e&&e.hasExtensionByName(o.name)){for(const r of["@lexical/plain-text","@lexical/rich-text"])e.hasExtensionByName(r)&&g(320,r);return!0}return!1}(r)?null:d(w,{editor:r,ErrorBoundary:e})}function B(r){return r.getEditorState().read(p(r.isComposing()))}function L({contentEditable:e,placeholder:t=null,ErrorBoundary:o}){const[n]=r();return function(r){y((()=>x(h(r),E(r))),[r])}(n),f(m,{children:[e,d(b,{content:t}),d(v,{editor:n,ErrorBoundary:o})]})}function b({content:t}){const[o]=r(),n=function(r){const[e,t]=c((()=>B(r)));return y((()=>{function e(){const e=B(r);t(e)}return e(),x(r.registerUpdateListener((()=>{e()})),r.registerEditableListener((()=>{e()})))}),[r]),e}(o),i=e();return n?"function"==typeof t?t(i):t:null}export{L as PlainTextPlugin};