@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
@@ -6,10 +6,9 @@
6
6
  *
7
7
  */
8
8
 
9
- import { $isLinkNode } from '@lexical/link';
9
+ import { namedSignals } from '@lexical/extension';
10
+ import { registerClickableLink } from '@lexical/link';
10
11
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
11
- import { $findMatchingParent, isHTMLAnchorElement } from '@lexical/utils';
12
- import { isDOMNode, getNearestEditorFromDOMNode, $getNearestNodeFromDOMNode, $isElementNode, $getSelection, $isRangeSelection } from 'lexical';
13
12
  import { useEffect } from 'react';
14
13
 
15
14
  /**
@@ -20,80 +19,16 @@ import { useEffect } from 'react';
20
19
  *
21
20
  */
22
21
 
23
- function findMatchingDOM(startNode, predicate) {
24
- let node = startNode;
25
- while (node != null) {
26
- if (predicate(node)) {
27
- return node;
28
- }
29
- node = node.parentNode;
30
- }
31
- return null;
32
- }
33
22
  function ClickableLinkPlugin({
34
23
  newTab = true,
35
24
  disabled = false
36
25
  }) {
37
26
  const [editor] = useLexicalComposerContext();
38
27
  useEffect(() => {
39
- const onClick = event => {
40
- const target = event.target;
41
- if (!isDOMNode(target)) {
42
- return;
43
- }
44
- const nearestEditor = getNearestEditorFromDOMNode(target);
45
- if (nearestEditor === null) {
46
- return;
47
- }
48
- let url = null;
49
- let urlTarget = null;
50
- nearestEditor.update(() => {
51
- const clickedNode = $getNearestNodeFromDOMNode(target);
52
- if (clickedNode !== null) {
53
- const maybeLinkNode = $findMatchingParent(clickedNode, $isElementNode);
54
- if (!disabled) {
55
- if ($isLinkNode(maybeLinkNode)) {
56
- url = maybeLinkNode.sanitizeUrl(maybeLinkNode.getURL());
57
- urlTarget = maybeLinkNode.getTarget();
58
- } else {
59
- const a = findMatchingDOM(target, isHTMLAnchorElement);
60
- if (a !== null) {
61
- url = a.href;
62
- urlTarget = a.target;
63
- }
64
- }
65
- }
66
- }
67
- });
68
- if (url === null || url === '') {
69
- return;
70
- }
71
-
72
- // Allow user to select link text without following url
73
- const selection = editor.getEditorState().read($getSelection);
74
- if ($isRangeSelection(selection) && !selection.isCollapsed()) {
75
- event.preventDefault();
76
- return;
77
- }
78
- const isMiddle = event.type === 'auxclick' && event.button === 1;
79
- window.open(url, newTab || isMiddle || event.metaKey || event.ctrlKey || urlTarget === '_blank' ? '_blank' : '_self');
80
- event.preventDefault();
81
- };
82
- const onMouseUp = event => {
83
- if (event.button === 1) {
84
- onClick(event);
85
- }
86
- };
87
- return editor.registerRootListener((rootElement, prevRootElement) => {
88
- if (prevRootElement !== null) {
89
- prevRootElement.removeEventListener('click', onClick);
90
- prevRootElement.removeEventListener('mouseup', onMouseUp);
91
- }
92
- if (rootElement !== null) {
93
- rootElement.addEventListener('click', onClick);
94
- rootElement.addEventListener('mouseup', onMouseUp);
95
- }
96
- });
28
+ return registerClickableLink(editor, namedSignals({
29
+ disabled,
30
+ newTab
31
+ }));
97
32
  }, [editor, newTab, disabled]);
98
33
  return null;
99
34
  }
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/link"),t=require("@lexical/react/LexicalComposerContext"),n=require("@lexical/utils"),r=require("lexical"),l=require("react");exports.ClickableLinkPlugin=function({newTab:i=!0,disabled:o=!1}){const[u]=t.useLexicalComposerContext();return l.useEffect((()=>{const t=t=>{const l=t.target;if(!r.isDOMNode(l))return;const s=r.getNearestEditorFromDOMNode(l);if(null===s)return;let a=null,c=null;if(s.update((()=>{const t=r.$getNearestNodeFromDOMNode(l);if(null!==t){const i=n.$findMatchingParent(t,r.$isElementNode);if(!o)if(e.$isLinkNode(i))a=i.sanitizeUrl(i.getURL()),c=i.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(l,n.isHTMLAnchorElement);null!==e&&(a=e.href,c=e.target)}}})),null===a||""===a)return;const d=u.getEditorState().read(r.$getSelection);if(r.$isRangeSelection(d)&&!d.isCollapsed())return void t.preventDefault();const f="auxclick"===t.type&&1===t.button;window.open(a,i||f||t.metaKey||t.ctrlKey||"_blank"===c?"_blank":"_self"),t.preventDefault()},l=e=>{1===e.button&&t(e)};return u.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",l)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",l))}))}),[u,i,o]),null};
9
+ "use strict";var e=require("@lexical/extension"),i=require("@lexical/link"),l=require("@lexical/react/LexicalComposerContext"),r=require("react");exports.ClickableLinkPlugin=function({newTab:n=!0,disabled:a=!1}){const[t]=l.useLexicalComposerContext();return r.useEffect((()=>i.registerClickableLink(t,e.namedSignals({disabled:a,newTab:n}))),[t,n,a]),null};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{$isLinkNode as e}from"@lexical/link";import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as n,isHTMLAnchorElement as r}from"@lexical/utils";import{isDOMNode as l,getNearestEditorFromDOMNode as o,$getNearestNodeFromDOMNode as i,$isElementNode as u,$getSelection as a,$isRangeSelection as c}from"lexical";import{useEffect as s}from"react";function f({newTab:f=!0,disabled:m=!1}){const[p]=t();return s((()=>{const t=t=>{const s=t.target;if(!l(s))return;const d=o(s);if(null===d)return;let v=null,x=null;if(d.update((()=>{const t=i(s);if(null!==t){const l=n(t,u);if(!m)if(e(l))v=l.sanitizeUrl(l.getURL()),x=l.getTarget();else{const e=function(e,t){let n=e;for(;null!=n;){if(t(n))return n;n=n.parentNode}return null}(s,r);null!==e&&(v=e.href,x=e.target)}}})),null===v||""===v)return;const g=p.getEditorState().read(a);if(c(g)&&!g.isCollapsed())return void t.preventDefault();const L="auxclick"===t.type&&1===t.button;window.open(v,f||L||t.metaKey||t.ctrlKey||"_blank"===x?"_blank":"_self"),t.preventDefault()},s=e=>{1===e.button&&t(e)};return p.registerRootListener(((e,n)=>{null!==n&&(n.removeEventListener("click",t),n.removeEventListener("mouseup",s)),null!==e&&(e.addEventListener("click",t),e.addEventListener("mouseup",s))}))}),[p,f,m]),null}export{f as ClickableLinkPlugin};
9
+ import{namedSignals as e}from"@lexical/extension";import{registerClickableLink as o}from"@lexical/link";import{useLexicalComposerContext as r}from"@lexical/react/LexicalComposerContext";import{useEffect as i}from"react";function t({newTab:t=!0,disabled:l=!1}){const[n]=r();return i((()=>o(n,e({disabled:l,newTab:t}))),[n,t,l]),null}export{t as ClickableLinkPlugin};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var r=require("react"),e=require("react/jsx-runtime");const o=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],n=o[Math.floor(Math.random()*o.length)],t=r.createContext(null);function l(){return{color:n[1],isCollabActive:!1,name:n[0],yjsDocMap:new Map}}const a=l();exports.CollaborationContext=t,exports.LexicalCollaboration=function({children:o}){const n=r.useMemo((()=>l()),[]);return e.jsx(t.Provider,{value:n,children:o})},exports.useCollaborationContext=function(e,o){let n=r.useContext(t);return null==n&&function(r,...e){const o=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",r);for(const r of e)n.append("v",r);o.search=n.toString(),console.warn(`Minified Lexical warning #${r}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(291),n=n??a,null!=e&&(n.name=e),null!=o&&(n.color=o),n};
9
+ "use strict";var r=require("react"),e=require("react/jsx-runtime");const o=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],n=o[Math.floor(Math.random()*o.length)],t=r.createContext(null);function l(){return{color:n[1],isCollabActive:!1,name:n[0],yjsDocMap:new Map}}const a=l();exports.CollaborationContext=t,exports.LexicalCollaboration=function({children:o}){const n=r.useMemo((()=>l()),[]);return e.jsx(t.Provider,{value:n,children:o})},exports.useCollaborationContext=function(e,o){let n=r.useContext(t);return null==n&&function(r,...e){const o=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",r);for(const r of e)n.append("v",r);o.search=n.toString(),console.warn(`Minified Lexical warning #${r}; visit ${o.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(319),n=n??a,null!=e&&(n.name=e),null!=o&&(n.color=o),n};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{createContext as r,useMemo as n,useContext as e}from"react";import{jsx as o}from"react/jsx-runtime";const t=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],i=t[Math.floor(Math.random()*t.length)],l=r(null);function a(){return{color:i[1],isCollabActive:!1,name:i[0],yjsDocMap:new Map}}const g=a();function c({children:r}){const e=n((()=>a()),[]);return o(l.Provider,{value:e,children:r})}function b(r,n){let o=e(l);return null==o&&function(r,...n){const e=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",r);for(const r of n)o.append("v",r);e.search=o.toString(),console.warn(`Minified Lexical warning #${r}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(291),o=o??g,null!=r&&(o.name=r),null!=n&&(o.color=n),o}export{l as CollaborationContext,c as LexicalCollaboration,b as useCollaborationContext};
9
+ import{createContext as r,useMemo as n,useContext as e}from"react";import{jsx as o}from"react/jsx-runtime";const t=[["Cat","rgb(125, 50, 0)"],["Dog","rgb(100, 0, 0)"],["Rabbit","rgb(150, 0, 0)"],["Frog","rgb(200, 0, 0)"],["Fox","rgb(200, 75, 0)"],["Hedgehog","rgb(0, 75, 0)"],["Pigeon","rgb(0, 125, 0)"],["Squirrel","rgb(75, 100, 0)"],["Bear","rgb(125, 100, 0)"],["Tiger","rgb(0, 0, 150)"],["Leopard","rgb(0, 0, 200)"],["Zebra","rgb(0, 0, 250)"],["Wolf","rgb(0, 100, 150)"],["Owl","rgb(0, 100, 100)"],["Gull","rgb(100, 0, 100)"],["Squid","rgb(150, 0, 150)"]],i=t[Math.floor(Math.random()*t.length)],l=r(null);function a(){return{color:i[1],isCollabActive:!1,name:i[0],yjsDocMap:new Map}}const g=a();function c({children:r}){const e=n((()=>a()),[]);return o(l.Provider,{value:e,children:r})}function b(r,n){let o=e(l);return null==o&&function(r,...n){const e=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",r);for(const r of n)o.append("v",r);e.search=o.toString(),console.warn(`Minified Lexical warning #${r}; visit ${e.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}(319),o=o??g,null!=r&&(o.name=r),null!=n&&(o.color=n),o}export{l as CollaborationContext,c as LexicalCollaboration,b as useCollaborationContext};
@@ -8,11 +8,11 @@
8
8
 
9
9
  import { useCollaborationContext } from '@lexical/react/LexicalCollaborationContext';
10
10
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
11
- import { initLocalState, syncLexicalUpdateToYjs, TOGGLE_CONNECT_COMMAND, syncCursorPositions, setLocalStateFocus, createUndoManager, CONNECTED_COMMAND, syncYjsChangesToLexical, createBinding } from '@lexical/yjs';
11
+ import { syncCursorPositions, initLocalState, syncLexicalUpdateToYjs, TOGGLE_CONNECT_COMMAND, createUndoManager, setLocalStateFocus, CONNECTED_COMMAND, syncYjsChangesToLexical, createBinding } from '@lexical/yjs';
12
12
  import * as React from 'react';
13
13
  import { useRef, useCallback, useEffect, useMemo, useState } from 'react';
14
14
  import { mergeRegister } from '@lexical/utils';
15
- import { SKIP_COLLAB_TAG, COMMAND_PRIORITY_EDITOR, FOCUS_COMMAND, BLUR_COMMAND, UNDO_COMMAND, REDO_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection } from 'lexical';
15
+ import { SKIP_COLLAB_TAG, COMMAND_PRIORITY_EDITOR, UNDO_COMMAND, REDO_COMMAND, FOCUS_COMMAND, BLUR_COMMAND, CAN_UNDO_COMMAND, CAN_REDO_COMMAND, $getRoot, HISTORY_MERGE_TAG, $createParagraphNode, $getSelection } from 'lexical';
16
16
  import { createPortal } from 'react-dom';
17
17
  import { UndoManager } from 'yjs';
18
18
  import { jsx, Fragment } from 'react/jsx-runtime';
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useCollaborationContext as t}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{initLocalState as o,syncLexicalUpdateToYjs as r,TOGGLE_CONNECT_COMMAND as n,syncCursorPositions as s,setLocalStateFocus as c,createUndoManager as a,CONNECTED_COMMAND as i,syncYjsChangesToLexical as l,createBinding as d}from"@lexical/yjs";import*as u from"react";import{useRef as m,useCallback as f,useEffect as p,useMemo as g,useState as C}from"react";import{mergeRegister as y}from"@lexical/utils";import{SKIP_COLLAB_TAG as h,COMMAND_PRIORITY_EDITOR as E,FOCUS_COMMAND as x,BLUR_COMMAND as b,UNDO_COMMAND as v,REDO_COMMAND as S,CAN_UNDO_COMMAND as k,CAN_REDO_COMMAND as D,$getRoot as j,HISTORY_MERGE_TAG as w,$createParagraphNode as R,$getSelection as F}from"lexical";import{createPortal as L}from"react-dom";import{UndoManager as P}from"yjs";import{jsx as T,Fragment as A}from"react/jsx-runtime";function B(t,e,c,a,d,u,C,y,x,b,v,S,k=s){const D=m(!1),A=f((()=>c.connect()),[c]),B=f((()=>{try{c.disconnect()}catch(t){}}),[c]);p((()=>{const{root:n}=y,{awareness:s}=c,m=({status:e})=>{t.dispatchCommand(i,"connected"===e)},f=e=>{C&&e&&n.isEmpty()&&0===n._xmlText._length&&!1===D.current&&function(t,e){t.update((()=>{const o=j();if(o.isEmpty())if(e)switch(typeof e){case"string":{const o=t.parseEditorState(e);t.setEditorState(o,{tag:w});break}case"object":t.setEditorState(e,{tag:w});break;case"function":t.update((()=>{j().isEmpty()&&e(t)}),{tag:w})}else{const e=R();o.append(e);const{activeElement:r}=document;(null!==F()||null!==r&&r===t.getRootElement())&&e.select()}}),{tag:w})}(t,v),D.current=!1},p=()=>{k(y,c)},g=(t,e)=>{const o=e.origin;if(o!==y){l(y,c,t,o instanceof P,k)}};o(c,d,u,document.activeElement===t.getRootElement(),S||{});const E=o=>{!function(t,e){if(t.update((()=>{const t=j();t.clear(),t.select()}),{tag:h}),null==e.cursors)return;const o=e.cursors;if(null==o)return;const r=e.cursorsContainer;if(null==r)return;const n=Array.from(o.values());for(let t=0;t<n.length;t++){const e=n[t].selection;if(e&&null!=e.selections){const o=e.selections;for(let e=0;e<o.length;e++)r.removeChild(o[t])}}}(t,y),x(o),a.set(e,o),D.current=!0};c.on("reload",E),c.on("status",m),c.on("sync",f),s.on("update",p),n.getSharedType().observeDeep(g);const b=t.registerUpdateListener((({prevEditorState:t,editorState:e,dirtyLeaves:o,dirtyElements:n,normalizedNodes:s,tags:a})=>{!1===a.has(h)&&r(y,c,t,e,n,o,s,a)})),L=A();return()=>{!1===D.current&&(L?L.then(B):B()),c.off("sync",f),c.off("status",m),c.off("reload",E),s.off("update",p),n.getSharedType().unobserveDeep(g),a.delete(e),b()}}),[y,u,A,B,a,t,e,v,d,c,C,S,x,k]);const M=g((()=>L(T("div",{ref:t=>{y.cursorsContainer=t}}),b&&b.current||document.body)),[y,b]);return p((()=>t.registerCommand(n,(t=>(t?(console.log("Collaboration connected!"),A()):(console.log("Collaboration disconnected!"),B()),!0)),E)),[A,B,t]),M}function M(t,e){const o=g((()=>a(e,e.root.getSharedType())),[e]);p((()=>y(t.registerCommand(v,(()=>(o.undo(),!0)),E),t.registerCommand(S,(()=>(o.redo(),!0)),E))));const r=f((()=>{o.clear()}),[o]);return u.useEffect((()=>{const e=()=>{t.dispatchCommand(k,o.undoStack.length>0),t.dispatchCommand(D,o.redoStack.length>0)};return o.on("stack-item-added",e),o.on("stack-item-popped",e),o.on("stack-cleared",e),()=>{o.off("stack-item-added",e),o.off("stack-item-popped",e),o.off("stack-cleared",e)}}),[t,o]),r}function _({id:o,providerFactory:r,shouldBootstrap:n,username:s,cursorColor:c,cursorsContainerRef:a,initialEditorState:i,excludedProperties:l,awarenessData:u,syncCursorPositionsFn:f}){const g=m(!1),y=m(!1),h=t(s,c),{yjsDocMap:E,name:x,color:b}=h,[v]=e();p((()=>(h.isCollabActive=!0,()=>{null==v._parentEditor&&(h.isCollabActive=!1)})),[h,v]);const[S,k]=C(),[D,j]=C();p((()=>{if(y.current)return;y.current=!0;const t=r(o,E);return k(t),j(E.get(o)),()=>{t.disconnect()}}),[o,r,E]);const[w,R]=C();return p((()=>{if(!S)return;if(g.current)return;g.current=!0;const t=d(v,S,o,D||E.get(o),E,l);return R(t),()=>{t.root.destroy(t)}}),[v,S,o,E,D,l]),S&&w?T(z,{awarenessData:u,binding:w,collabContext:h,color:b,cursorsContainerRef:a,editor:v,id:o,initialEditorState:i,name:x,provider:S,setDoc:j,shouldBootstrap:n,yjsDocMap:E,syncCursorPositionsFn:f}):T(A,{})}function z({editor:t,id:e,provider:o,yjsDocMap:r,name:n,color:s,shouldBootstrap:a,cursorsContainerRef:i,initialEditorState:l,awarenessData:d,collabContext:u,binding:m,setDoc:f,syncCursorPositionsFn:g}){const C=B(t,e,o,r,n,s,a,m,f,i,l,d,g);return M(t,m),function(t,e,o,r,n){p((()=>y(t.registerCommand(x,(()=>(c(e,o,r,!0,n||{}),!1)),E),t.registerCommand(b,(()=>(c(e,o,r,!1,n||{}),!1)),E))),[r,t,o,e,n])}(t,o,n,s,d),C}export{_ as CollaborationPlugin};
9
+ import{useCollaborationContext as t}from"@lexical/react/LexicalCollaborationContext";import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{syncCursorPositions as o,initLocalState as r,syncLexicalUpdateToYjs as n,TOGGLE_CONNECT_COMMAND as s,createUndoManager as c,setLocalStateFocus as a,CONNECTED_COMMAND as i,syncYjsChangesToLexical as l,createBinding as d}from"@lexical/yjs";import*as u from"react";import{useRef as m,useCallback as f,useEffect as p,useMemo as g,useState as C}from"react";import{mergeRegister as y}from"@lexical/utils";import{SKIP_COLLAB_TAG as h,COMMAND_PRIORITY_EDITOR as E,UNDO_COMMAND as x,REDO_COMMAND as b,FOCUS_COMMAND as v,BLUR_COMMAND as S,CAN_UNDO_COMMAND as k,CAN_REDO_COMMAND as D,$getRoot as j,HISTORY_MERGE_TAG as w,$createParagraphNode as R,$getSelection as F}from"lexical";import{createPortal as L}from"react-dom";import{UndoManager as P}from"yjs";import{jsx as T,Fragment as A}from"react/jsx-runtime";function B(t,e,c,a,d,u,C,y,x,b,v,S,k=o){const D=m(!1),A=f((()=>c.connect()),[c]),B=f((()=>{try{c.disconnect()}catch(t){}}),[c]);p((()=>{const{root:o}=y,{awareness:s}=c,m=({status:e})=>{t.dispatchCommand(i,"connected"===e)},f=e=>{C&&e&&o.isEmpty()&&0===o._xmlText._length&&!1===D.current&&function(t,e){t.update((()=>{const o=j();if(o.isEmpty())if(e)switch(typeof e){case"string":{const o=t.parseEditorState(e);t.setEditorState(o,{tag:w});break}case"object":t.setEditorState(e,{tag:w});break;case"function":t.update((()=>{j().isEmpty()&&e(t)}),{tag:w})}else{const e=R();o.append(e);const{activeElement:r}=document;(null!==F()||null!==r&&r===t.getRootElement())&&e.select()}}),{tag:w})}(t,v),D.current=!1},p=()=>{k(y,c)},g=(t,e)=>{const o=e.origin;if(o!==y){l(y,c,t,o instanceof P,k)}};r(c,d,u,document.activeElement===t.getRootElement(),S||{});const E=o=>{!function(t,e){if(t.update((()=>{const t=j();t.clear(),t.select()}),{tag:h}),null==e.cursors)return;const o=e.cursors;if(null==o)return;const r=e.cursorsContainer;if(null==r)return;const n=Array.from(o.values());for(let t=0;t<n.length;t++){const e=n[t].selection;if(e&&null!=e.selections){const o=e.selections;for(let e=0;e<o.length;e++)r.removeChild(o[t])}}}(t,y),x(o),a.set(e,o),D.current=!0};c.on("reload",E),c.on("status",m),c.on("sync",f),s.on("update",p),o.getSharedType().observeDeep(g);const b=t.registerUpdateListener((({prevEditorState:t,editorState:e,dirtyLeaves:o,dirtyElements:r,normalizedNodes:s,tags:a})=>{!1===a.has(h)&&n(y,c,t,e,r,o,s,a)})),L=A();return()=>{!1===D.current&&(L?L.then(B):B()),c.off("sync",f),c.off("status",m),c.off("reload",E),s.off("update",p),o.getSharedType().unobserveDeep(g),a.delete(e),b()}}),[y,u,A,B,a,t,e,v,d,c,C,S,x,k]);const M=g((()=>L(T("div",{ref:t=>{y.cursorsContainer=t}}),b&&b.current||document.body)),[y,b]);return p((()=>t.registerCommand(s,(t=>(t?(console.log("Collaboration connected!"),A()):(console.log("Collaboration disconnected!"),B()),!0)),E)),[A,B,t]),M}function M(t,e){const o=g((()=>c(e,e.root.getSharedType())),[e]);p((()=>y(t.registerCommand(x,(()=>(o.undo(),!0)),E),t.registerCommand(b,(()=>(o.redo(),!0)),E))));const r=f((()=>{o.clear()}),[o]);return u.useEffect((()=>{const e=()=>{t.dispatchCommand(k,o.undoStack.length>0),t.dispatchCommand(D,o.redoStack.length>0)};return o.on("stack-item-added",e),o.on("stack-item-popped",e),o.on("stack-cleared",e),()=>{o.off("stack-item-added",e),o.off("stack-item-popped",e),o.off("stack-cleared",e)}}),[t,o]),r}function _({id:o,providerFactory:r,shouldBootstrap:n,username:s,cursorColor:c,cursorsContainerRef:a,initialEditorState:i,excludedProperties:l,awarenessData:u,syncCursorPositionsFn:f}){const g=m(!1),y=m(!1),h=t(s,c),{yjsDocMap:E,name:x,color:b}=h,[v]=e();p((()=>(h.isCollabActive=!0,()=>{null==v._parentEditor&&(h.isCollabActive=!1)})),[h,v]);const[S,k]=C(),[D,j]=C();p((()=>{if(y.current)return;y.current=!0;const t=r(o,E);return k(t),j(E.get(o)),()=>{t.disconnect()}}),[o,r,E]);const[w,R]=C();return p((()=>{if(!S)return;if(g.current)return;g.current=!0;const t=d(v,S,o,D||E.get(o),E,l);return R(t),()=>{t.root.destroy(t)}}),[v,S,o,E,D,l]),S&&w?T(z,{awarenessData:u,binding:w,collabContext:h,color:b,cursorsContainerRef:a,editor:v,id:o,initialEditorState:i,name:x,provider:S,setDoc:j,shouldBootstrap:n,yjsDocMap:E,syncCursorPositionsFn:f}):T(A,{})}function z({editor:t,id:e,provider:o,yjsDocMap:r,name:n,color:s,shouldBootstrap:c,cursorsContainerRef:i,initialEditorState:l,awarenessData:d,collabContext:u,binding:m,setDoc:f,syncCursorPositionsFn:g}){const C=B(t,e,o,r,n,s,c,m,f,i,l,d,g);return M(t,m),function(t,e,o,r,n){p((()=>y(t.registerCommand(v,(()=>(a(e,o,r,!0,n||{}),!1)),E),t.registerCommand(S,(()=>(a(e,o,r,!1,n||{}),!1)),E))),[r,t,o,e,n])}(t,o,n,s,d),C}export{_ as CollaborationPlugin};
@@ -45,17 +45,16 @@ const useLayoutEffectImpl = CAN_USE_DOM ? react.useLayoutEffect : react.useEffec
45
45
  * LICENSE file in the root directory of this source tree.
46
46
  *
47
47
  */
48
- // Source: https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx
49
48
 
50
49
  function mergeRefs(...refs) {
51
50
  return value => {
52
- refs.forEach(ref => {
51
+ for (const ref of refs) {
53
52
  if (typeof ref === 'function') {
54
53
  ref(value);
55
54
  } else if (ref != null) {
56
55
  ref.current = value;
57
56
  }
58
- });
57
+ }
59
58
  };
60
59
  }
61
60
 
@@ -43,17 +43,16 @@ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
43
43
  * LICENSE file in the root directory of this source tree.
44
44
  *
45
45
  */
46
- // Source: https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx
47
46
 
48
47
  function mergeRefs(...refs) {
49
48
  return value => {
50
- refs.forEach(ref => {
49
+ for (const ref of refs) {
51
50
  if (typeof ref === 'function') {
52
51
  ref(value);
53
52
  } else if (ref != null) {
54
53
  ref.current = value;
55
54
  }
56
- });
55
+ }
57
56
  };
58
57
  }
59
58
 
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("react/jsx-runtime"),i=require("@lexical/text"),r=require("@lexical/utils");const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function o({editor:e,ariaActiveDescendant:i,ariaAutoComplete:r,ariaControls:o,ariaDescribedBy:l,ariaErrorMessage:s,ariaExpanded:d,ariaInvalid:u,ariaLabel:c,ariaLabelledBy:f,ariaMultiline:b,ariaOwns:x,ariaRequired:m,autoCapitalize:E,className:p,id:C,role:v="textbox",spellCheck:w=!0,style:y,tabIndex:g,"data-testid":L,...h},q){const[j,R]=t.useState(e.isEditable()),S=t.useCallback((t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)}),[e]),D=t.useMemo((()=>function(...e){return t=>{e.forEach((e=>{"function"==typeof e?e(t):null!=e&&(e.current=t)}))}}(q,S)),[S,q]);return n((()=>(R(e.isEditable()),e.registerEditableListener((e=>{R(e)})))),[e]),a.jsx("div",{"aria-activedescendant":j?i:void 0,"aria-autocomplete":j?r:"none","aria-controls":j?o:void 0,"aria-describedby":l,...null!=s?{"aria-errormessage":s}:{},"aria-expanded":j&&"combobox"===v?!!d:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":c,"aria-labelledby":f,"aria-multiline":b,"aria-owns":j?x:void 0,"aria-readonly":!j||void 0,"aria-required":m,autoCapitalize:E,className:p,contentEditable:j,"data-testid":L,id:C,ref:D,role:v,spellCheck:w,style:y,tabIndex:g,...h})}const l=t.forwardRef(o);function s(e){return e.getEditorState().read(i.$canShowPlaceholderCurry(e.isComposing()))}const d=t.forwardRef(u);function u(t,i){const{placeholder:r,...n}=t,[o]=e.useLexicalComposerContext();return a.jsxs(a.Fragment,{children:[a.jsx(l,{editor:o,...n,ref:i}),null!=r&&a.jsx(c,{editor:o,content:r})]})}function c({content:e,editor:i}){const o=function(e){const[a,i]=t.useState((()=>s(e)));return n((()=>{function t(){const t=s(e);i(t)}return t(),r.mergeRegister(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),a}(i),[l,d]=t.useState(i.isEditable());if(t.useLayoutEffect((()=>(d(i.isEditable()),i.registerEditableListener((e=>{d(e)})))),[i]),!o)return null;let u=null;return"function"==typeof e?u=e(l):null!==e&&(u=e),null===u?null:a.jsx("div",{"aria-hidden":!0,children:u})}exports.ContentEditable=d,exports.ContentEditableElement=l;
9
+ "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("react"),a=require("react/jsx-runtime"),i=require("@lexical/text"),r=require("@lexical/utils");const n="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t.useLayoutEffect:t.useEffect;function o({editor:e,ariaActiveDescendant:i,ariaAutoComplete:r,ariaControls:o,ariaDescribedBy:l,ariaErrorMessage:s,ariaExpanded:d,ariaInvalid:u,ariaLabel:c,ariaLabelledBy:f,ariaMultiline:b,ariaOwns:x,ariaRequired:m,autoCapitalize:E,className:p,id:C,role:v="textbox",spellCheck:w=!0,style:y,tabIndex:g,"data-testid":L,...h},q){const[j,R]=t.useState(e.isEditable()),S=t.useCallback((t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)}),[e]),D=t.useMemo((()=>function(...e){return t=>{for(const a of e)"function"==typeof a?a(t):null!=a&&(a.current=t)}}(q,S)),[S,q]);return n((()=>(R(e.isEditable()),e.registerEditableListener((e=>{R(e)})))),[e]),a.jsx("div",{"aria-activedescendant":j?i:void 0,"aria-autocomplete":j?r:"none","aria-controls":j?o:void 0,"aria-describedby":l,...null!=s?{"aria-errormessage":s}:{},"aria-expanded":j&&"combobox"===v?!!d:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":c,"aria-labelledby":f,"aria-multiline":b,"aria-owns":j?x:void 0,"aria-readonly":!j||void 0,"aria-required":m,autoCapitalize:E,className:p,contentEditable:j,"data-testid":L,id:C,ref:D,role:v,spellCheck:w,style:y,tabIndex:g,...h})}const l=t.forwardRef(o);function s(e){return e.getEditorState().read(i.$canShowPlaceholderCurry(e.isComposing()))}const d=t.forwardRef(u);function u(t,i){const{placeholder:r,...n}=t,[o]=e.useLexicalComposerContext();return a.jsxs(a.Fragment,{children:[a.jsx(l,{editor:o,...n,ref:i}),null!=r&&a.jsx(c,{editor:o,content:r})]})}function c({content:e,editor:i}){const o=function(e){const[a,i]=t.useState((()=>s(e)));return n((()=>{function t(){const t=s(e);i(t)}return t(),r.mergeRegister(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),a}(i),[l,d]=t.useState(i.isEditable());if(t.useLayoutEffect((()=>(d(i.isEditable()),i.registerEditableListener((e=>{d(e)})))),[i]),!o)return null;let u=null;return"function"==typeof e?u=e(l):null!==e&&(u=e),null===u?null:a.jsx("div",{"aria-hidden":!0,children:u})}exports.ContentEditable=d,exports.ContentEditableElement=l;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{jsx as l,jsxs as d,Fragment as c}from"react/jsx-runtime";import{$canShowPlaceholderCurry as s}from"@lexical/text";import{mergeRegister as u}from"@lexical/utils";const m="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t:i;function f({editor:e,ariaActiveDescendant:t,ariaAutoComplete:i,ariaControls:a,ariaDescribedBy:d,ariaErrorMessage:c,ariaExpanded:s,ariaInvalid:u,ariaLabel:f,ariaLabelledBy:b,ariaMultiline:p,ariaOwns:x,ariaRequired:E,autoCapitalize:v,className:w,id:y,role:C="textbox",spellCheck:g=!0,style:h,tabIndex:L,"data-testid":D,...I},R){const[k,q]=r(e.isEditable()),z=n((t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)}),[e]),A=o((()=>function(...e){return t=>{e.forEach((e=>{"function"==typeof e?e(t):null!=e&&(e.current=t)}))}}(R,z)),[z,R]);return m((()=>(q(e.isEditable()),e.registerEditableListener((e=>{q(e)})))),[e]),l("div",{"aria-activedescendant":k?t:void 0,"aria-autocomplete":k?i:"none","aria-controls":k?a:void 0,"aria-describedby":d,...null!=c?{"aria-errormessage":c}:{},"aria-expanded":k&&"combobox"===C?!!s:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":f,"aria-labelledby":b,"aria-multiline":p,"aria-owns":k?x:void 0,"aria-readonly":!k||void 0,"aria-required":E,autoCapitalize:v,className:w,contentEditable:k,"data-testid":D,id:y,ref:A,role:C,spellCheck:g,style:h,tabIndex:L,...I})}const b=a(f);function p(e){return e.getEditorState().read(s(e.isComposing()))}const x=a(E);function E(t,i){const{placeholder:a,...r}=t,[n]=e();return d(c,{children:[l(b,{editor:n,...r,ref:i}),null!=a&&l(v,{editor:n,content:a})]})}function v({content:e,editor:i}){const a=function(e){const[t,i]=r((()=>p(e)));return m((()=>{function t(){const t=p(e);i(t)}return t(),u(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(i),[n,o]=r(i.isEditable());if(t((()=>(o(i.isEditable()),i.registerEditableListener((e=>{o(e)})))),[i]),!a)return null;let d=null;return"function"==typeof e?d=e(n):null!==e&&(d=e),null===d?null:l("div",{"aria-hidden":!0,children:d})}export{x as ContentEditable,b as ContentEditableElement};
9
+ import{useLexicalComposerContext as e}from"@lexical/react/LexicalComposerContext";import{useLayoutEffect as t,useEffect as i,forwardRef as a,useState as r,useCallback as n,useMemo as o}from"react";import{jsx as l,jsxs as d,Fragment as c}from"react/jsx-runtime";import{$canShowPlaceholderCurry as s}from"@lexical/text";import{mergeRegister as u}from"@lexical/utils";const m="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement?t:i;function f({editor:e,ariaActiveDescendant:t,ariaAutoComplete:i,ariaControls:a,ariaDescribedBy:d,ariaErrorMessage:c,ariaExpanded:s,ariaInvalid:u,ariaLabel:f,ariaLabelledBy:b,ariaMultiline:p,ariaOwns:x,ariaRequired:E,autoCapitalize:v,className:w,id:y,role:C="textbox",spellCheck:g=!0,style:L,tabIndex:h,"data-testid":D,...I},R){const[k,q]=r(e.isEditable()),z=n((t=>{t&&t.ownerDocument&&t.ownerDocument.defaultView?e.setRootElement(t):e.setRootElement(null)}),[e]),A=o((()=>function(...e){return t=>{for(const i of e)"function"==typeof i?i(t):null!=i&&(i.current=t)}}(R,z)),[z,R]);return m((()=>(q(e.isEditable()),e.registerEditableListener((e=>{q(e)})))),[e]),l("div",{"aria-activedescendant":k?t:void 0,"aria-autocomplete":k?i:"none","aria-controls":k?a:void 0,"aria-describedby":d,...null!=c?{"aria-errormessage":c}:{},"aria-expanded":k&&"combobox"===C?!!s:void 0,...null!=u?{"aria-invalid":u}:{},"aria-label":f,"aria-labelledby":b,"aria-multiline":p,"aria-owns":k?x:void 0,"aria-readonly":!k||void 0,"aria-required":E,autoCapitalize:v,className:w,contentEditable:k,"data-testid":D,id:y,ref:A,role:C,spellCheck:g,style:L,tabIndex:h,...I})}const b=a(f);function p(e){return e.getEditorState().read(s(e.isComposing()))}const x=a(E);function E(t,i){const{placeholder:a,...r}=t,[n]=e();return d(c,{children:[l(b,{editor:n,...r,ref:i}),null!=a&&l(v,{editor:n,content:a})]})}function v({content:e,editor:i}){const a=function(e){const[t,i]=r((()=>p(e)));return m((()=>{function t(){const t=p(e);i(t)}return t(),u(e.registerUpdateListener((()=>{t()})),e.registerEditableListener((()=>{t()})))}),[e]),t}(i),[n,o]=r(i.isEditable());if(t((()=>(o(i.isEditable()),i.registerEditableListener((e=>{o(e)})))),[i]),!a)return null;let d=null;return"function"==typeof e?d=e(n):null!==e&&(d=e),null===d?null:l("div",{"aria-hidden":!0,children:d})}export{x as ContentEditable,b as ContentEditableElement};
@@ -60,6 +60,8 @@ const useLayoutEffectImpl = CAN_USE_DOM ? React.useLayoutEffect : React.useEffec
60
60
  */
61
61
 
62
62
  class MenuOption {
63
+ key;
64
+ ref;
63
65
  constructor(key) {
64
66
  this.key = key;
65
67
  this.ref = {
@@ -8,9 +8,9 @@
8
8
 
9
9
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
10
10
  import { mergeRegister, calculateZoomLevel } from '@lexical/utils';
11
- import { createCommand, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, COMMAND_PRIORITY_LOW, $getSelection, $isRangeSelection, isDOMNode } from 'lexical';
11
+ import { createCommand, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND, KEY_ENTER_COMMAND, $getSelection, $isRangeSelection, isDOMNode } from 'lexical';
12
12
  import * as React from 'react';
13
- import { useLayoutEffect, useEffect, useState, useCallback, useMemo, useRef } from 'react';
13
+ import { useLayoutEffect, useEffect, useRef, useCallback, useState, useMemo } from 'react';
14
14
  import { jsx } from 'react/jsx-runtime';
15
15
 
16
16
  /**
@@ -46,6 +46,8 @@ const useLayoutEffectImpl = CAN_USE_DOM ? useLayoutEffect : useEffect;
46
46
  */
47
47
 
48
48
  class MenuOption {
49
+ key;
50
+ ref;
49
51
  constructor(key) {
50
52
  this.key = key;
51
53
  this.ref = {
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("@lexical/react/LexicalComposerContext"),t=require("@lexical/utils"),n=require("lexical"),l=require("react"),o=require("react/jsx-runtime");function r(e){var t=Object.create(null);if(e)for(var n in e)t[n]=e[n];return t.default=e,t}var i=r(l);const u="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,s=u?l.useLayoutEffect:l.useEffect;const c=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 a(e,t){const n=e.getBoundingClientRect(),l=t.getBoundingClientRect();return n.top>=l.top-6&&n.top<=l.bottom+6}function m(t,n,o,r){const[i]=e.useLexicalComposerContext();l.useEffect((()=>{if(null!=n&&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 l=!1,u=a(n,t);const s=function(){l||(window.requestAnimationFrame((function(){o(),l=!1})),l=!0);const e=a(n,t);e!==u&&(u=e,null!=r&&r(e))},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,i,r,o,t])}const d=n.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function f({close:e,editor:o,anchorElementRef:r,resolution:i,options:u,menuRenderFn:a,onSelectOption:m,shouldSplitNodeWithQuery:f=!1,commandPriority:p=n.COMMAND_PRIORITY_LOW,preselectFirstItem:g=!0}){const[h,C]=l.useState(null),E=i.match&&i.match.matchingString;l.useEffect((()=>{g&&C(0)}),[E,g]);const v=l.useCallback((t=>{o.update((()=>{const l=null!=i.match&&f?function(e){const t=n.$getSelection();if(!n.$isRangeSelection(t)||!t.isCollapsed())return null;const l=t.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(t,l,e,i.match?i.match.matchingString:"")}))}),[o,f,i.match,m,e]),R=l.useCallback((e=>{const t=o.getRootElement();null!==t&&(t.setAttribute("aria-activedescendant","typeahead-item-"+e),C(e))}),[o]);l.useEffect((()=>()=>{const e=o.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")}),[o]),s((()=>{null===u?C(null):null===h&&g&&R(0)}),[u,h,R,g]),l.useEffect((()=>t.mergeRegister(o.registerCommand(d,(({option:e})=>!(!e.ref||null==e.ref.current)&&(c(e.ref.current),!0)),p))),[o,R,p]),l.useEffect((()=>t.mergeRegister(o.registerCommand(n.KEY_ARROW_DOWN_COMMAND,(e=>{const t=e;if(null!==u&&u.length){const e=null===h?0:h!==u.length-1?h+1:0;R(e);const n=u[e];null!=n.ref&&n.ref.current&&o.dispatchCommand(d,{index:e,option:n}),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(n.KEY_ARROW_UP_COMMAND,(e=>{const t=e;if(null!==u&&u.length){const e=null===h?u.length-1:0!==h?h-1:u.length-1;R(e);const n=u[e];null!=n.ref&&n.ref.current&&c(n.ref.current),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(n.KEY_ESCAPE_COMMAND,(t=>{const n=t;return n.preventDefault(),n.stopImmediatePropagation(),e(),!0}),p),o.registerCommand(n.KEY_TAB_COMMAND,(e=>{const t=e;return null!==u&&null!==h&&null!=u[h]&&(t.preventDefault(),t.stopImmediatePropagation(),v(u[h]),!0)}),p),o.registerCommand(n.KEY_ENTER_COMMAND,(e=>null!==u&&null!==h&&null!=u[h]&&(null!==e&&(e.preventDefault(),e.stopImmediatePropagation()),v(u[h]),!0)),p))),[v,e,o,u,h,R,p]);return a(r,l.useMemo((()=>({options:u,selectOptionAndCleanUp:v,selectedIndex:h,setHighlightedIndex:C})),[v,h,u]),i.match?i.match.matchingString:"")}function p(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.LexicalContextMenuPlugin=function({options:r,onWillOpen:s,onClose:c,onOpen:a,onSelectOption:d,menuRenderFn:g,anchorClassName:h,commandPriority:C=n.COMMAND_PRIORITY_LOW,parent:E}){const[v]=e.useLexicalComposerContext(),[R,b]=l.useState(null),w=i.useRef(null),x=function(t,n,o,r=(u?document.body:void 0),i=!0){const[s]=e.useLexicalComposerContext(),c=u?document.createElement("div"):null,a=l.useRef(c),d=l.useCallback((()=>{if(null===a.current||void 0===r)return;a.current.style.top=a.current.style.bottom;const e=s.getRootElement(),n=a.current,l=n.firstChild;if(null!==e&&null!==t){const{left:u,top:s,width:c,height:m}=t.getRect(),d=a.current.offsetHeight;if(n.style.top=`${s+d+3+(i?window.pageYOffset:0)}px`,n.style.left=`${u+window.pageXOffset}px`,n.style.height=`${m}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();u+r>c.right&&(n.style.left=`${c.right-r+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+m&&(n.style.top=`${s-o-m+(i?window.pageYOffset:0)}px`)}n.isConnected||(p(n,o),r.append(n)),n.setAttribute("id","typeahead-menu"),e.setAttribute("aria-controls","typeahead-menu")}}),[s,t,i,o,r]);l.useEffect((()=>{const e=s.getRootElement();return null!==t&&d(),()=>{null!==e&&e.removeAttribute("aria-controls");const t=a.current;null!==t&&t.isConnected&&(t.remove(),t.removeAttribute("id"))}}),[s,d,t]);const f=l.useCallback((e=>{null!==t&&(e||n(null))}),[t,n]);return m(t,a.current,d,f),null!=c&&c===a.current&&(p(c,o),null!=r&&r.append(c)),a}(R,b,h,E),O=l.useCallback((()=>{b(null),null!=c&&null!==R&&c()}),[c,R]),y=l.useCallback((e=>{b(e),null!=a&&null===R&&a(e)}),[a,R]),A=l.useCallback((e=>{e.preventDefault(),null!=s&&s(e);const n=t.calculateZoomLevel(e.target);y({getRect:()=>new DOMRect(e.clientX/n,e.clientY/n,1,1)})}),[y,s]),M=l.useCallback((e=>{null!==R&&null!=w.current&&null!=e.target&&n.isDOMNode(e.target)&&!w.current.contains(e.target)&&O()}),[O,R]);return l.useEffect((()=>{const e=v.getRootElement();if(e)return e.addEventListener("contextmenu",A),()=>e.removeEventListener("contextmenu",A)}),[v,A]),l.useEffect((()=>(document.addEventListener("click",M),()=>document.removeEventListener("click",M))),[v,M]),null===x.current||null===R||null===v?null:o.jsx(f,{close:O,resolution:R,editor:v,anchorElementRef:x,options:r,menuRenderFn:(e,t)=>g(e,t,{setMenuRef:e=>{w.current=e}}),onSelectOption:d,commandPriority:C})},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/utils"),n=require("lexical"),l=require("react"),o=require("react/jsx-runtime");function r(e){var t=Object.create(null);if(e)for(var n in e)t[n]=e[n];return t.default=e,t}var i=r(l);const u="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,s=u?l.useLayoutEffect:l.useEffect;const c=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 a(e,t){const n=e.getBoundingClientRect(),l=t.getBoundingClientRect();return n.top>=l.top-6&&n.top<=l.bottom+6}function m(t,n,o,r){const[i]=e.useLexicalComposerContext();l.useEffect((()=>{if(null!=n&&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 l=!1,u=a(n,t);const s=function(){l||(window.requestAnimationFrame((function(){o(),l=!1})),l=!0);const e=a(n,t);e!==u&&(u=e,null!=r&&r(e))},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,i,r,o,t])}const d=n.createCommand("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function f({close:e,editor:o,anchorElementRef:r,resolution:i,options:u,menuRenderFn:a,onSelectOption:m,shouldSplitNodeWithQuery:f=!1,commandPriority:p=n.COMMAND_PRIORITY_LOW,preselectFirstItem:g=!0}){const[h,C]=l.useState(null),E=i.match&&i.match.matchingString;l.useEffect((()=>{g&&C(0)}),[E,g]);const v=l.useCallback((t=>{o.update((()=>{const l=null!=i.match&&f?function(e){const t=n.$getSelection();if(!n.$isRangeSelection(t)||!t.isCollapsed())return null;const l=t.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(t,l,e,i.match?i.match.matchingString:"")}))}),[o,f,i.match,m,e]),R=l.useCallback((e=>{const t=o.getRootElement();null!==t&&(t.setAttribute("aria-activedescendant","typeahead-item-"+e),C(e))}),[o]);l.useEffect((()=>()=>{const e=o.getRootElement();null!==e&&e.removeAttribute("aria-activedescendant")}),[o]),s((()=>{null===u?C(null):null===h&&g&&R(0)}),[u,h,R,g]),l.useEffect((()=>t.mergeRegister(o.registerCommand(d,(({option:e})=>!(!e.ref||null==e.ref.current)&&(c(e.ref.current),!0)),p))),[o,R,p]),l.useEffect((()=>t.mergeRegister(o.registerCommand(n.KEY_ARROW_DOWN_COMMAND,(e=>{const t=e;if(null!==u&&u.length){const e=null===h?0:h!==u.length-1?h+1:0;R(e);const n=u[e];null!=n.ref&&n.ref.current&&o.dispatchCommand(d,{index:e,option:n}),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(n.KEY_ARROW_UP_COMMAND,(e=>{const t=e;if(null!==u&&u.length){const e=null===h?u.length-1:0!==h?h-1:u.length-1;R(e);const n=u[e];null!=n.ref&&n.ref.current&&c(n.ref.current),t.preventDefault(),t.stopImmediatePropagation()}return!0}),p),o.registerCommand(n.KEY_ESCAPE_COMMAND,(t=>{const n=t;return n.preventDefault(),n.stopImmediatePropagation(),e(),!0}),p),o.registerCommand(n.KEY_TAB_COMMAND,(e=>{const t=e;return null!==u&&null!==h&&null!=u[h]&&(t.preventDefault(),t.stopImmediatePropagation(),v(u[h]),!0)}),p),o.registerCommand(n.KEY_ENTER_COMMAND,(e=>null!==u&&null!==h&&null!=u[h]&&(null!==e&&(e.preventDefault(),e.stopImmediatePropagation()),v(u[h]),!0)),p))),[v,e,o,u,h,R,p]);return a(r,l.useMemo((()=>({options:u,selectOptionAndCleanUp:v,selectedIndex:h,setHighlightedIndex:C})),[v,h,u]),i.match?i.match.matchingString:"")}function p(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.LexicalContextMenuPlugin=function({options:r,onWillOpen:s,onClose:c,onOpen:a,onSelectOption:d,menuRenderFn:g,anchorClassName:h,commandPriority:C=n.COMMAND_PRIORITY_LOW,parent:E}){const[v]=e.useLexicalComposerContext(),[R,b]=l.useState(null),w=i.useRef(null),x=function(t,n,o,r=(u?document.body:void 0),i=!0){const[s]=e.useLexicalComposerContext(),c=u?document.createElement("div"):null,a=l.useRef(c),d=l.useCallback((()=>{if(null===a.current||void 0===r)return;a.current.style.top=a.current.style.bottom;const e=s.getRootElement(),n=a.current,l=n.firstChild;if(null!==e&&null!==t){const{left:u,top:s,width:c,height:m}=t.getRect(),d=a.current.offsetHeight;if(n.style.top=`${s+d+3+(i?window.pageYOffset:0)}px`,n.style.left=`${u+window.pageXOffset}px`,n.style.height=`${m}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();u+r>c.right&&(n.style.left=`${c.right-r+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+m&&(n.style.top=`${s-o-m+(i?window.pageYOffset:0)}px`)}n.isConnected||(p(n,o),r.append(n)),n.setAttribute("id","typeahead-menu"),e.setAttribute("aria-controls","typeahead-menu")}}),[s,t,i,o,r]);l.useEffect((()=>{const e=s.getRootElement();return null!==t&&d(),()=>{null!==e&&e.removeAttribute("aria-controls");const t=a.current;null!==t&&t.isConnected&&(t.remove(),t.removeAttribute("id"))}}),[s,d,t]);const f=l.useCallback((e=>{null!==t&&(e||n(null))}),[t,n]);return m(t,a.current,d,f),null!=c&&c===a.current&&(p(c,o),null!=r&&r.append(c)),a}(R,b,h,E),O=l.useCallback((()=>{b(null),null!=c&&null!==R&&c()}),[c,R]),y=l.useCallback((e=>{b(e),null!=a&&null===R&&a(e)}),[a,R]),A=l.useCallback((e=>{e.preventDefault(),null!=s&&s(e);const n=t.calculateZoomLevel(e.target);y({getRect:()=>new DOMRect(e.clientX/n,e.clientY/n,1,1)})}),[y,s]),M=l.useCallback((e=>{null!==R&&null!=w.current&&null!=e.target&&n.isDOMNode(e.target)&&!w.current.contains(e.target)&&O()}),[O,R]);return l.useEffect((()=>{const e=v.getRootElement();if(e)return e.addEventListener("contextmenu",A),()=>e.removeEventListener("contextmenu",A)}),[v,A]),l.useEffect((()=>(document.addEventListener("click",M),()=>document.removeEventListener("click",M))),[v,M]),null===x.current||null===R||null===v?null:o.jsx(f,{close:O,resolution:R,editor:v,anchorElementRef:x,options:r,menuRenderFn:(e,t)=>g(e,t,{setMenuRef:e=>{w.current=e}}),onSelectOption:d,commandPriority:C})},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{mergeRegister as e,calculateZoomLevel as n}from"@lexical/utils";import{createCommand as o,KEY_ARROW_DOWN_COMMAND as l,KEY_ARROW_UP_COMMAND as r,KEY_ESCAPE_COMMAND as i,KEY_TAB_COMMAND as u,KEY_ENTER_COMMAND as c,COMMAND_PRIORITY_LOW as s,$getSelection as a,$isRangeSelection as m,isDOMNode as d}from"lexical";import*as p from"react";import{useLayoutEffect as f,useEffect as g,useState as h,useCallback as v,useMemo as w,useRef as y}from"react";import{jsx as b}from"react/jsx-runtime";const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,E=C?f:g;class R{constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const x=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 O(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>=o.top-6&&n.top<=o.bottom+6}function I(e,n,o,l){const[r]=t();g((()=>{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=O(n,e);const c=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=O(n,e);t!==u&&(u=t,null!=l&&l(t))},s=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",c,{capture:!0,passive:!0}),s.observe(n),()=>{s.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",c,!0)}}}),[n,r,l,o,e])}const A=o("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function S({close:t,editor:n,anchorElementRef:o,resolution:d,options:p,menuRenderFn:f,onSelectOption:y,shouldSplitNodeWithQuery:b=!1,commandPriority:C=s,preselectFirstItem:R=!0}){const[O,I]=h(null),S=d.match&&d.match.matchingString;g((()=>{R&&I(0)}),[S,R]);const L=v((e=>{n.update((()=>{const n=null!=d.match&&b?function(t){const e=a();if(!m(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 c;return 0===u?[c]=o.splitText(l):[,c]=o.splitText(u,l),c}(d.match):null;y(e,n,t,d.match?d.match.matchingString:"")}))}),[n,b,d.match,y,t]),P=v((t=>{const e=n.getRootElement();null!==e&&(e.setAttribute("aria-activedescendant","typeahead-item-"+t),I(t))}),[n]);g((()=>()=>{const t=n.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[n]),E((()=>{null===p?I(null):null===O&&R&&P(0)}),[p,O,P,R]),g((()=>e(n.registerCommand(A,(({option:t})=>!(!t.ref||null==t.ref.current)&&(x(t.ref.current),!0)),C))),[n,P,C]),g((()=>e(n.registerCommand(l,(t=>{const e=t;if(null!==p&&p.length){const t=null===O?0:O!==p.length-1?O+1:0;P(t);const o=p[t];null!=o.ref&&o.ref.current&&n.dispatchCommand(A,{index:t,option:o}),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),n.registerCommand(r,(t=>{const e=t;if(null!==p&&p.length){const t=null===O?p.length-1:0!==O?O-1:p.length-1;P(t);const n=p[t];null!=n.ref&&n.ref.current&&x(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),n.registerCommand(i,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),C),n.registerCommand(u,(t=>{const e=t;return null!==p&&null!==O&&null!=p[O]&&(e.preventDefault(),e.stopImmediatePropagation(),L(p[O]),!0)}),C),n.registerCommand(c,(t=>null!==p&&null!==O&&null!=p[O]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),L(p[O]),!0)),C))),[L,t,n,p,O,P,C]);return f(o,w((()=>({options:p,selectOptionAndCleanUp:L,selectedIndex:O,setHighlightedIndex:I})),[L,O,p]),d.match?d.match.matchingString:"")}function L(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 P({options:e,onWillOpen:o,onClose:l,onOpen:r,onSelectOption:i,menuRenderFn:u,anchorClassName:c,commandPriority:a=s,parent:m}){const[f]=t(),[w,E]=h(null),R=p.useRef(null),x=function(e,n,o,l=(C?document.body:void 0),r=!0){const[i]=t(),u=C?document.createElement("div"):null,c=y(u),s=v((()=>{if(null===c.current||void 0===l)return;c.current.style.top=c.current.style.bottom;const t=i.getRootElement(),n=c.current,u=n.firstChild;if(null!==t&&null!==e){const{left:i,top:s,width:a,height:m}=e.getRect(),d=c.current.offsetHeight;if(n.style.top=`${s+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=`${s}`;const e=u.getBoundingClientRect(),o=e.height,l=e.width,c=t.getBoundingClientRect();i+l>c.right&&(n.style.left=`${c.right-l+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+m&&(n.style.top=`${s-o-m+(r?window.pageYOffset:0)}px`)}n.isConnected||(L(n,o),l.append(n)),n.setAttribute("id","typeahead-menu"),t.setAttribute("aria-controls","typeahead-menu")}}),[i,e,r,o,l]);g((()=>{const t=i.getRootElement();return null!==e&&s(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=c.current;null!==e&&e.isConnected&&(e.remove(),e.removeAttribute("id"))}}),[i,s,e]);const a=v((t=>{null!==e&&(t||n(null))}),[e,n]);return I(e,c.current,s,a),null!=u&&u===c.current&&(L(u,o),null!=l&&l.append(u)),c}(w,E,c,m),O=v((()=>{E(null),null!=l&&null!==w&&l()}),[l,w]),A=v((t=>{E(t),null!=r&&null===w&&r(t)}),[r,w]),P=v((t=>{t.preventDefault(),null!=o&&o(t);const e=n(t.target);A({getRect:()=>new DOMRect(t.clientX/e,t.clientY/e,1,1)})}),[A,o]),D=v((t=>{null!==w&&null!=R.current&&null!=t.target&&d(t.target)&&!R.current.contains(t.target)&&O()}),[O,w]);return g((()=>{const t=f.getRootElement();if(t)return t.addEventListener("contextmenu",P),()=>t.removeEventListener("contextmenu",P)}),[f,P]),g((()=>(document.addEventListener("click",D),()=>document.removeEventListener("click",D))),[f,D]),null===x.current||null===w||null===f?null:b(S,{close:O,resolution:w,editor:f,anchorElementRef:x,options:e,menuRenderFn:(t,e)=>u(t,e,{setMenuRef:t=>{R.current=t}}),onSelectOption:i,commandPriority:a})}export{P as LexicalContextMenuPlugin,R as MenuOption};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{mergeRegister as e,calculateZoomLevel as n}from"@lexical/utils";import{createCommand as o,COMMAND_PRIORITY_LOW as l,KEY_ARROW_DOWN_COMMAND as r,KEY_ARROW_UP_COMMAND as i,KEY_ESCAPE_COMMAND as u,KEY_TAB_COMMAND as c,KEY_ENTER_COMMAND as s,$getSelection as a,$isRangeSelection as m,isDOMNode as d}from"lexical";import*as p from"react";import{useLayoutEffect as f,useEffect as g,useRef as h,useCallback as v,useState as w,useMemo as y}from"react";import{jsx as b}from"react/jsx-runtime";const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,E=C?f:g;class R{key;ref;constructor(t){this.key=t,this.ref={current:null},this.setRefElement=this.setRefElement.bind(this)}setRefElement(t){this.ref={current:t}}}const x=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 O(t,e){const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();return n.top>=o.top-6&&n.top<=o.bottom+6}function I(e,n,o,l){const[r]=t();g((()=>{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=O(n,e);const c=function(){i||(window.requestAnimationFrame((function(){o(),i=!1})),i=!0);const t=O(n,e);t!==u&&(u=t,null!=l&&l(t))},s=new ResizeObserver(o);return window.addEventListener("resize",o),document.addEventListener("scroll",c,{capture:!0,passive:!0}),s.observe(n),()=>{s.unobserve(n),window.removeEventListener("resize",o),document.removeEventListener("scroll",c,!0)}}}),[n,r,l,o,e])}const A=o("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function S({close:t,editor:n,anchorElementRef:o,resolution:d,options:p,menuRenderFn:f,onSelectOption:h,shouldSplitNodeWithQuery:b=!1,commandPriority:C=l,preselectFirstItem:R=!0}){const[O,I]=w(null),S=d.match&&d.match.matchingString;g((()=>{R&&I(0)}),[S,R]);const L=v((e=>{n.update((()=>{const n=null!=d.match&&b?function(t){const e=a();if(!m(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 c;return 0===u?[c]=o.splitText(l):[,c]=o.splitText(u,l),c}(d.match):null;h(e,n,t,d.match?d.match.matchingString:"")}))}),[n,b,d.match,h,t]),P=v((t=>{const e=n.getRootElement();null!==e&&(e.setAttribute("aria-activedescendant","typeahead-item-"+t),I(t))}),[n]);g((()=>()=>{const t=n.getRootElement();null!==t&&t.removeAttribute("aria-activedescendant")}),[n]),E((()=>{null===p?I(null):null===O&&R&&P(0)}),[p,O,P,R]),g((()=>e(n.registerCommand(A,(({option:t})=>!(!t.ref||null==t.ref.current)&&(x(t.ref.current),!0)),C))),[n,P,C]),g((()=>e(n.registerCommand(r,(t=>{const e=t;if(null!==p&&p.length){const t=null===O?0:O!==p.length-1?O+1:0;P(t);const o=p[t];null!=o.ref&&o.ref.current&&n.dispatchCommand(A,{index:t,option:o}),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),n.registerCommand(i,(t=>{const e=t;if(null!==p&&p.length){const t=null===O?p.length-1:0!==O?O-1:p.length-1;P(t);const n=p[t];null!=n.ref&&n.ref.current&&x(n.ref.current),e.preventDefault(),e.stopImmediatePropagation()}return!0}),C),n.registerCommand(u,(e=>{const n=e;return n.preventDefault(),n.stopImmediatePropagation(),t(),!0}),C),n.registerCommand(c,(t=>{const e=t;return null!==p&&null!==O&&null!=p[O]&&(e.preventDefault(),e.stopImmediatePropagation(),L(p[O]),!0)}),C),n.registerCommand(s,(t=>null!==p&&null!==O&&null!=p[O]&&(null!==t&&(t.preventDefault(),t.stopImmediatePropagation()),L(p[O]),!0)),C))),[L,t,n,p,O,P,C]);return f(o,y((()=>({options:p,selectOptionAndCleanUp:L,selectedIndex:O,setHighlightedIndex:I})),[L,O,p]),d.match?d.match.matchingString:"")}function L(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 P({options:e,onWillOpen:o,onClose:r,onOpen:i,onSelectOption:u,menuRenderFn:c,anchorClassName:s,commandPriority:a=l,parent:m}){const[f]=t(),[y,E]=w(null),R=p.useRef(null),x=function(e,n,o,l=(C?document.body:void 0),r=!0){const[i]=t(),u=C?document.createElement("div"):null,c=h(u),s=v((()=>{if(null===c.current||void 0===l)return;c.current.style.top=c.current.style.bottom;const t=i.getRootElement(),n=c.current,u=n.firstChild;if(null!==t&&null!==e){const{left:i,top:s,width:a,height:m}=e.getRect(),d=c.current.offsetHeight;if(n.style.top=`${s+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=`${s}`;const e=u.getBoundingClientRect(),o=e.height,l=e.width,c=t.getBoundingClientRect();i+l>c.right&&(n.style.left=`${c.right-l+window.pageXOffset}px`),(s+o>window.innerHeight||s+o>c.bottom)&&s-c.top>o+m&&(n.style.top=`${s-o-m+(r?window.pageYOffset:0)}px`)}n.isConnected||(L(n,o),l.append(n)),n.setAttribute("id","typeahead-menu"),t.setAttribute("aria-controls","typeahead-menu")}}),[i,e,r,o,l]);g((()=>{const t=i.getRootElement();return null!==e&&s(),()=>{null!==t&&t.removeAttribute("aria-controls");const e=c.current;null!==e&&e.isConnected&&(e.remove(),e.removeAttribute("id"))}}),[i,s,e]);const a=v((t=>{null!==e&&(t||n(null))}),[e,n]);return I(e,c.current,s,a),null!=u&&u===c.current&&(L(u,o),null!=l&&l.append(u)),c}(y,E,s,m),O=v((()=>{E(null),null!=r&&null!==y&&r()}),[r,y]),A=v((t=>{E(t),null!=i&&null===y&&i(t)}),[i,y]),P=v((t=>{t.preventDefault(),null!=o&&o(t);const e=n(t.target);A({getRect:()=>new DOMRect(t.clientX/e,t.clientY/e,1,1)})}),[A,o]),D=v((t=>{null!==y&&null!=R.current&&null!=t.target&&d(t.target)&&!R.current.contains(t.target)&&O()}),[O,y]);return g((()=>{const t=f.getRootElement();if(t)return t.addEventListener("contextmenu",P),()=>t.removeEventListener("contextmenu",P)}),[f,P]),g((()=>(document.addEventListener("click",D),()=>document.removeEventListener("click",D))),[f,D]),null===x.current||null===y||null===f?null:b(S,{close:O,resolution:y,editor:f,anchorElementRef:x,options:e,menuRenderFn:(t,e)=>c(t,e,{setMenuRef:t=>{R.current=t}}),onSelectOption:u,commandPriority:a})}export{P as LexicalContextMenuPlugin,R as MenuOption};
@@ -19,6 +19,7 @@ var lexical = require('lexical');
19
19
  */
20
20
 
21
21
  class DecoratorBlockNode extends lexical.DecoratorNode {
22
+ __format;
22
23
  constructor(format, key) {
23
24
  super(key);
24
25
  this.__format = format || '';
@@ -17,6 +17,7 @@ import { DecoratorNode } from 'lexical';
17
17
  */
18
18
 
19
19
  class DecoratorBlockNode extends DecoratorNode {
20
+ __format;
20
21
  constructor(format, key) {
21
22
  super(key);
22
23
  this.__format = format || '';
@@ -12,6 +12,7 @@ import type {
12
12
  LexicalNode,
13
13
  LexicalCommand,
14
14
  NodeKey,
15
+ SerializedDecoratorNode
15
16
  } from 'lexical';
16
17
 
17
18
  import {DecoratorNode} from 'lexical';
@@ -26,3 +27,9 @@ declare export class DecoratorBlockNode<T> extends DecoratorNode<T> {
26
27
  declare export function $isDecoratorBlockNode(
27
28
  node: ?LexicalNode,
28
29
  ): node is DecoratorBlockNode<{...}>;
30
+
31
+ export type SerializedDecoratorBlockNode = {
32
+ ...SerializedDecoratorNode,
33
+ format: ElementFormatType,
34
+ ...
35
+ };
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var r=require("lexical");class t extends r.DecoratorNode{constructor(r,t){super(t),this.__format=r||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(r){return super.updateFromJSON(r).setFormat(r.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(r){const t=this.getWritable();return t.__format=r,t}isInline(){return!1}}exports.$isDecoratorBlockNode=function(r){return r instanceof t},exports.DecoratorBlockNode=t;
9
+ "use strict";var r=require("lexical");class t extends r.DecoratorNode{__format;constructor(r,t){super(t),this.__format=r||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(r){return super.updateFromJSON(r).setFormat(r.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(r){const t=this.getWritable();return t.__format=r,t}isInline(){return!1}}exports.$isDecoratorBlockNode=function(r){return r instanceof t},exports.DecoratorBlockNode=t;
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{DecoratorNode as t}from"lexical";class r extends t{constructor(t,r){super(r),this.__format=t||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}isInline(){return!1}}function e(t){return t instanceof r}export{e as $isDecoratorBlockNode,r as DecoratorBlockNode};
9
+ import{DecoratorNode as t}from"lexical";class r extends t{__format;constructor(t,r){super(r),this.__format=t||""}exportJSON(){return{...super.exportJSON(),format:this.__format||""}}updateFromJSON(t){return super.updateFromJSON(t).setFormat(t.format||"")}canIndent(){return!1}createDOM(){return document.createElement("div")}updateDOM(){return!1}setFormat(t){const r=this.getWritable();return r.__format=t,r}isInline(){return!1}}function e(t){return t instanceof r}export{e as $isDecoratorBlockNode,r as DecoratorBlockNode};
@@ -24,6 +24,8 @@ var jsxRuntime = require('react/jsx-runtime');
24
24
  *
25
25
  */
26
26
  class Point {
27
+ _x;
28
+ _y;
27
29
  constructor(x, y) {
28
30
  this._x = x;
29
31
  this._y = y;
@@ -72,6 +74,10 @@ function isPoint(x) {
72
74
  *
73
75
  */
74
76
  class Rectangle {
77
+ _left;
78
+ _top;
79
+ _right;
80
+ _bottom;
75
81
  constructor(left, top, right, bottom) {
76
82
  const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];
77
83
  const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];
@@ -22,6 +22,8 @@ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
22
22
  *
23
23
  */
24
24
  class Point {
25
+ _x;
26
+ _y;
25
27
  constructor(x, y) {
26
28
  this._x = x;
27
29
  this._y = y;
@@ -70,6 +72,10 @@ function isPoint(x) {
70
72
  *
71
73
  */
72
74
  class Rectangle {
75
+ _left;
76
+ _top;
77
+ _right;
78
+ _bottom;
73
79
  constructor(left, top, right, bottom) {
74
80
  const [physicTop, physicBottom] = top <= bottom ? [top, bottom] : [bottom, top];
75
81
  const [physicLeft, physicRight] = left <= right ? [left, right] : [right, left];
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),r=require("lexical"),o=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");class l{constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class a{constructor(t,e,n,r){const[o,i]=e<=r?[e,r]:[r,e],[s,l]=t<=n?[t,n]:[n,t];this._top=o,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:r}){return t===this._top&&n===this._bottom&&e===this._left&&r===this._right}contains(t){if(t instanceof l){const{x:e,y:n}=t,r=n<this._top,o=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:o,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:r},result:!(r||o||i||s)}}{const{top:e,left:n,bottom:r,right:o}=t;return e>=this._top&&e<=this._bottom&&r>=this._top&&r<=this._bottom&&n>=this._left&&n<=this._right&&o>=this._left&&o<=this._right}}intersectsWith(t){const{left:e,top:n,width:r,height:o}=t,{left:i,top:s,width:l,height:a}=this;return(e+r>=i+l?e+r:i+l)-(e<=i?e:i)<=r+l&&(n+o>=s+a?n+o:s+a)-(n<=s?n:s)<=o+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:r=this.bottom}){return new a(t,e,n,r)}static fromLTRB(t,e,n,r){return new a(t,e,n,r)}static fromLWTH(t,e,n,r){return new a(t,n,t+e,n+r)}static fromPoints(t,e){const{y:n,x:r}=t,{y:o,x:i}=e;return a.fromLTRB(r,n,i,o)}static fromDOM(t){const{top:e,width:n,left:r,height:o}=t.getBoundingClientRect();return a.fromLWTH(r,n,e,o)}}const c=4,u=2,g="application/x-lexical-drag-block",h=28,m=1,f=-1,p=0;let d=1/0;function y(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:r}=window.getComputedStyle(t),o=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),o);return{marginBottom:Math.max(parseFloat(r),i),marginTop:s}}function _(t,e,o,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.getEditorState().read((()=>r.$getRoot().getChildrenKeys()))}(e);let u=null;return e.getEditorState().read((()=>{if(i){const[t,r]=[e.getElementByKey(c[0]),e.getElementByKey(c[c.length-1])],[i,s]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&s){const e=n.calculateZoomLevel(t),l=n.calculateZoomLevel(r);if(o.y/e<i.top?u=t:o.y/l>s.bottom&&(u=r),u)return}}let t=0===(r=c.length)?1/0:d>=0&&d<r?d:Math.floor(r/2);var r;let g=p;for(;t>=0&&t<c.length;){const r=c[t],i=e.getElementByKey(r);if(null===i)break;const h=n.calculateZoomLevel(i),_=new l(o.x/h,o.y/h),x=a.fromDOM(i),{marginTop:b,marginBottom:T}=y(i),C=x.generateNewRect({bottom:x.bottom+T,left:s.left,right:s.right,top:x.top-b}),{result:R,reason:{isOnTopSide:v,isOnBottomSide:M}}=C.contains(_);if(R){u=i,d=t;break}g===p&&(g=v?f:M?m:1/0),t+=g}})),u}function x(t,l,a,m,f,p,d,x,b){const T=l.parentElement,C=o.useRef(!1),[R,v]=o.useState(null),M=o.useCallback((t=>{v(t),b&&b(t)}),[b]);return o.useEffect((()=>{function e(e){const r=e.target;if(!n.isHTMLElement(r))return void M(null);if(x(r))return;const o=_(l,t,e);M(o)}function r(){M(null)}return null!=T&&(T.addEventListener("mousemove",e),T.addEventListener("mouseleave",r)),()=>{null!=T&&(T.removeEventListener("mousemove",e),T.removeEventListener("mouseleave",r))}}),[T,l,t,x,M]),o.useEffect((()=>{a.current&&function(t,e,n){if(!t)return e.style.opacity="0",void(e.style.transform="translate(-10000px, -10000px)");const r=t.getBoundingClientRect(),o=window.getComputedStyle(t),i=e.getBoundingClientRect(),s=n.getBoundingClientRect();let l=parseInt(o.lineHeight,10);isNaN(l)&&(l=r.bottom-r.top);const a=r.top+(l-i.height)/2-s.top+n.scrollTop,u=c;e.style.opacity="1",e.style.transform=`translate(${u}px, ${a}px)`}(R,a.current,l)}),[l,R,a]),o.useEffect((()=>{function o(r){if(!C.current)return!1;const[o]=e.eventFiles(r);if(o)return!1;const{pageY:i,target:s}=r;if(!n.isHTMLElement(s))return!1;const a=_(l,t,r,!0),g=m.current;return null!==a&&null!==g&&(function(t,e,n,r){const{top:o,height:i}=e.getBoundingClientRect(),{top:s,width:l}=r.getBoundingClientRect(),{marginTop:a,marginBottom:g}=y(e);let m=o;n>=o?m+=i+g/2:m-=a/2;const f=m-s-u+r.scrollTop,p=h-c;t.style.transform=`translate(${p}px, ${f}px)`,t.style.width=l-2*(h-c)+"px",t.style.opacity=".4"}(g,a,i/n.calculateZoomLevel(s),l),r.preventDefault(),!0)}return n.mergeRegister(t.registerCommand(r.DRAGOVER_COMMAND,(t=>o(t)),r.COMMAND_PRIORITY_LOW),t.registerCommand(r.DROP_COMMAND,(o=>function(o){if(!C.current)return!1;const[i]=e.eventFiles(o);if(i)return!1;const{target:s,dataTransfer:a,pageY:c}=o,u=null!=a?a.getData(g):"",h=r.$getNodeByKey(u);if(!h)return!1;if(!n.isHTMLElement(s))return!1;const m=_(l,t,o,!0);if(!m)return!1;const f=r.$getNearestNodeFromDOMNode(m);if(!f)return!1;if(f===h)return!0;const p=m.getBoundingClientRect().top;return c/n.calculateZoomLevel(s)>=p?f.insertAfter(h):f.insertBefore(h),M(null),!0}(o)),r.COMMAND_PRIORITY_HIGH))}),[l,t,m,M]),i.createPortal(s.jsxs(s.Fragment,{children:[s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!R)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout((()=>{e.style.transform=n}))}(n,R);let o="";t.update((()=>{const t=r.$getNearestNodeFromDOMNode(R);t&&(o=t.getKey())})),C.current=!0,n.setData(g,o)},onDragEnd:function(){var t;C.current=!1,(t=m.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:f&&p}),d]}),l)}exports.DraggableBlockPlugin_EXPERIMENTAL=function({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t.useLexicalComposerContext();return x(a,e,n,r,a._editable,o,i,s,l)};
9
+ "use strict";var t=require("@lexical/react/LexicalComposerContext"),e=require("@lexical/rich-text"),n=require("@lexical/utils"),r=require("lexical"),o=require("react"),i=require("react-dom"),s=require("react/jsx-runtime");class l{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class a{_left;_top;_right;_bottom;constructor(t,e,n,r){const[o,i]=e<=r?[e,r]:[r,e],[s,l]=t<=n?[t,n]:[n,t];this._top=o,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:r}){return t===this._top&&n===this._bottom&&e===this._left&&r===this._right}contains(t){if(t instanceof l){const{x:e,y:n}=t,r=n<this._top,o=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:o,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:r},result:!(r||o||i||s)}}{const{top:e,left:n,bottom:r,right:o}=t;return e>=this._top&&e<=this._bottom&&r>=this._top&&r<=this._bottom&&n>=this._left&&n<=this._right&&o>=this._left&&o<=this._right}}intersectsWith(t){const{left:e,top:n,width:r,height:o}=t,{left:i,top:s,width:l,height:a}=this;return(e+r>=i+l?e+r:i+l)-(e<=i?e:i)<=r+l&&(n+o>=s+a?n+o:s+a)-(n<=s?n:s)<=o+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:r=this.bottom}){return new a(t,e,n,r)}static fromLTRB(t,e,n,r){return new a(t,e,n,r)}static fromLWTH(t,e,n,r){return new a(t,n,t+e,n+r)}static fromPoints(t,e){const{y:n,x:r}=t,{y:o,x:i}=e;return a.fromLTRB(r,n,i,o)}static fromDOM(t){const{top:e,width:n,left:r,height:o}=t.getBoundingClientRect();return a.fromLWTH(r,n,e,o)}}const c=4,u=2,g="application/x-lexical-drag-block",h=28,m=1,f=-1,p=0;let d=1/0;function _(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:r}=window.getComputedStyle(t),o=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),o);return{marginBottom:Math.max(parseFloat(r),i),marginTop:s}}function y(t,e,o,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.getEditorState().read((()=>r.$getRoot().getChildrenKeys()))}(e);let u=null;return e.getEditorState().read((()=>{if(i){const[t,r]=[e.getElementByKey(c[0]),e.getElementByKey(c[c.length-1])],[i,s]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&s){const e=n.calculateZoomLevel(t),l=n.calculateZoomLevel(r);if(o.y/e<i.top?u=t:o.y/l>s.bottom&&(u=r),u)return}}let t=0===(r=c.length)?1/0:d>=0&&d<r?d:Math.floor(r/2);var r;let g=p;for(;t>=0&&t<c.length;){const r=c[t],i=e.getElementByKey(r);if(null===i)break;const h=n.calculateZoomLevel(i),y=new l(o.x/h,o.y/h),x=a.fromDOM(i),{marginTop:b,marginBottom:T}=_(i),C=x.generateNewRect({bottom:x.bottom+T,left:s.left,right:s.right,top:x.top-b}),{result:R,reason:{isOnTopSide:v,isOnBottomSide:M}}=C.contains(y);if(R){u=i,d=t;break}g===p&&(g=v?f:M?m:1/0),t+=g}})),u}function x(t,l,a,m,f,p,d,x,b){const T=l.parentElement,C=o.useRef(!1),[R,v]=o.useState(null),M=o.useCallback((t=>{v(t),b&&b(t)}),[b]);return o.useEffect((()=>{function e(e){const r=e.target;if(!n.isHTMLElement(r))return void M(null);if(x(r))return;const o=y(l,t,e);M(o)}function r(){M(null)}return null!=T&&(T.addEventListener("mousemove",e),T.addEventListener("mouseleave",r)),()=>{null!=T&&(T.removeEventListener("mousemove",e),T.removeEventListener("mouseleave",r))}}),[T,l,t,x,M]),o.useEffect((()=>{a.current&&function(t,e,n){if(!t)return e.style.opacity="0",void(e.style.transform="translate(-10000px, -10000px)");const r=t.getBoundingClientRect(),o=window.getComputedStyle(t),i=e.getBoundingClientRect(),s=n.getBoundingClientRect();let l=parseInt(o.lineHeight,10);isNaN(l)&&(l=r.bottom-r.top);const a=r.top+(l-i.height)/2-s.top+n.scrollTop,u=c;e.style.opacity="1",e.style.transform=`translate(${u}px, ${a}px)`}(R,a.current,l)}),[l,R,a]),o.useEffect((()=>{function o(r){if(!C.current)return!1;const[o]=e.eventFiles(r);if(o)return!1;const{pageY:i,target:s}=r;if(!n.isHTMLElement(s))return!1;const a=y(l,t,r,!0),g=m.current;return null!==a&&null!==g&&(function(t,e,n,r){const{top:o,height:i}=e.getBoundingClientRect(),{top:s,width:l}=r.getBoundingClientRect(),{marginTop:a,marginBottom:g}=_(e);let m=o;n>=o?m+=i+g/2:m-=a/2;const f=m-s-u+r.scrollTop,p=h-c;t.style.transform=`translate(${p}px, ${f}px)`,t.style.width=l-2*(h-c)+"px",t.style.opacity=".4"}(g,a,i/n.calculateZoomLevel(s),l),r.preventDefault(),!0)}return n.mergeRegister(t.registerCommand(r.DRAGOVER_COMMAND,(t=>o(t)),r.COMMAND_PRIORITY_LOW),t.registerCommand(r.DROP_COMMAND,(o=>function(o){if(!C.current)return!1;const[i]=e.eventFiles(o);if(i)return!1;const{target:s,dataTransfer:a,pageY:c}=o,u=null!=a?a.getData(g):"",h=r.$getNodeByKey(u);if(!h)return!1;if(!n.isHTMLElement(s))return!1;const m=y(l,t,o,!0);if(!m)return!1;const f=r.$getNearestNodeFromDOMNode(m);if(!f)return!1;if(f===h)return!0;const p=m.getBoundingClientRect().top;return c/n.calculateZoomLevel(s)>=p?f.insertAfter(h):f.insertBefore(h),M(null),!0}(o)),r.COMMAND_PRIORITY_HIGH))}),[l,t,m,M]),i.createPortal(s.jsxs(s.Fragment,{children:[s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!R)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout((()=>{e.style.transform=n}))}(n,R);let o="";t.update((()=>{const t=r.$getNearestNodeFromDOMNode(R);t&&(o=t.getKey())})),C.current=!0,n.setData(g,o)},onDragEnd:function(){var t;C.current=!1,(t=m.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:f&&p}),d]}),l)}exports.DraggableBlockPlugin_EXPERIMENTAL=function({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t.useLexicalComposerContext();return x(a,e,n,r,a._editable,o,i,s,l)};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{mergeRegister as n,isHTMLElement as r,calculateZoomLevel as o}from"@lexical/utils";import{DRAGOVER_COMMAND as i,COMMAND_PRIORITY_LOW as s,DROP_COMMAND as a,COMMAND_PRIORITY_HIGH as l,$getNodeByKey as c,$getNearestNodeFromDOMNode as u,$getRoot as h}from"lexical";import{useRef as m,useState as g,useCallback as f,useEffect as p}from"react";import{createPortal as d}from"react-dom";import{jsxs as y,Fragment as x,jsx as _}from"react/jsx-runtime";class b{constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class T{constructor(t,e,n,r){const[o,i]=e<=r?[e,r]:[r,e],[s,a]=t<=n?[t,n]:[n,t];this._top=o,this._right=a,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:r}){return t===this._top&&n===this._bottom&&e===this._left&&r===this._right}contains(t){if(t instanceof b){const{x:e,y:n}=t,r=n<this._top,o=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:o,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:r},result:!(r||o||i||s)}}{const{top:e,left:n,bottom:r,right:o}=t;return e>=this._top&&e<=this._bottom&&r>=this._top&&r<=this._bottom&&n>=this._left&&n<=this._right&&o>=this._left&&o<=this._right}}intersectsWith(t){const{left:e,top:n,width:r,height:o}=t,{left:i,top:s,width:a,height:l}=this;return(e+r>=i+a?e+r:i+a)-(e<=i?e:i)<=r+a&&(n+o>=s+l?n+o:s+l)-(n<=s?n:s)<=o+l}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:r=this.bottom}){return new T(t,e,n,r)}static fromLTRB(t,e,n,r){return new T(t,e,n,r)}static fromLWTH(t,e,n,r){return new T(t,n,t+e,n+r)}static fromPoints(t,e){const{y:n,x:r}=t,{y:o,x:i}=e;return T.fromLTRB(r,n,i,o)}static fromDOM(t){const{top:e,width:n,left:r,height:o}=t.getBoundingClientRect();return T.fromLWTH(r,n,e,o)}}const B=4,C=2,w="application/x-lexical-drag-block",v=28,D=1,R=-1,E=0;let S=1/0;function M(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:r}=window.getComputedStyle(t),o=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),o);return{marginBottom:Math.max(parseFloat(r),i),marginTop:s}}function L(t,e,n,r=!1){const i=t.getBoundingClientRect(),s=function(t){return t.getEditorState().read((()=>h().getChildrenKeys()))}(e);let a=null;return e.getEditorState().read((()=>{if(r){const[t,r]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,l]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&l){const e=o(t),s=o(r);if(n.y/e<i.top?a=t:n.y/s>l.bottom&&(a=r),a)return}}let t=0===(l=s.length)?1/0:S>=0&&S<l?S:Math.floor(l/2);var l;let c=E;for(;t>=0&&t<s.length;){const r=s[t],l=e.getElementByKey(r);if(null===l)break;const u=o(l),h=new b(n.x/u,n.y/u),m=T.fromDOM(l),{marginTop:g,marginBottom:f}=M(l),p=m.generateNewRect({bottom:m.bottom+f,left:i.left,right:i.right,top:m.top-g}),{result:d,reason:{isOnTopSide:y,isOnBottomSide:x}}=p.contains(h);if(d){a=l,S=t;break}c===E&&(c=y?R:x?D:1/0),t+=c}})),a}function O(t,h,b,T,D,R,E,S,O){const K=h.parentElement,Y=m(!1),[H,N]=g(null),$=f((t=>{N(t),O&&O(t)}),[O]);return p((()=>{function e(e){const n=e.target;if(!r(n))return void $(null);if(S(n))return;const o=L(h,t,e);$(o)}function n(){$(null)}return null!=K&&(K.addEventListener("mousemove",e),K.addEventListener("mouseleave",n)),()=>{null!=K&&(K.removeEventListener("mousemove",e),K.removeEventListener("mouseleave",n))}}),[K,h,t,S,$]),p((()=>{b.current&&function(t,e,n){if(!t)return e.style.opacity="0",void(e.style.transform="translate(-10000px, -10000px)");const r=t.getBoundingClientRect(),o=window.getComputedStyle(t),i=e.getBoundingClientRect(),s=n.getBoundingClientRect();let a=parseInt(o.lineHeight,10);isNaN(a)&&(a=r.bottom-r.top);const l=r.top+(a-i.height)/2-s.top+n.scrollTop,c=B;e.style.opacity="1",e.style.transform=`translate(${c}px, ${l}px)`}(H,b.current,h)}),[h,H,b]),p((()=>{function m(n){if(!Y.current)return!1;const[i]=e(n);if(i)return!1;const{pageY:s,target:a}=n;if(!r(a))return!1;const l=L(h,t,n,!0),c=T.current;return null!==l&&null!==c&&(function(t,e,n,r){const{top:o,height:i}=e.getBoundingClientRect(),{top:s,width:a}=r.getBoundingClientRect(),{marginTop:l,marginBottom:c}=M(e);let u=o;n>=o?u+=i+c/2:u-=l/2;const h=u-s-C+r.scrollTop,m=v-B;t.style.transform=`translate(${m}px, ${h}px)`,t.style.width=a-2*(v-B)+"px",t.style.opacity=".4"}(c,l,s/o(a),h),n.preventDefault(),!0)}return n(t.registerCommand(i,(t=>m(t)),s),t.registerCommand(a,(n=>function(n){if(!Y.current)return!1;const[i]=e(n);if(i)return!1;const{target:s,dataTransfer:a,pageY:l}=n,m=null!=a?a.getData(w):"",g=c(m);if(!g)return!1;if(!r(s))return!1;const f=L(h,t,n,!0);if(!f)return!1;const p=u(f);if(!p)return!1;if(p===g)return!0;const d=f.getBoundingClientRect().top;return l/o(s)>=d?p.insertAfter(g):p.insertBefore(g),$(null),!0}(n)),l))}),[h,t,T,$]),d(y(x,{children:[_("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!H)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout((()=>{e.style.transform=n}))}(n,H);let r="";t.update((()=>{const t=u(H);t&&(r=t.getKey())})),Y.current=!0,n.setData(w,r)},onDragEnd:function(){var t;Y.current=!1,(t=T.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:D&&R}),E]}),h)}function K({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:a}){const[l]=t();return O(l,e,n,r,l._editable,o,i,s,a)}export{K as DraggableBlockPlugin_EXPERIMENTAL};
9
+ import{useLexicalComposerContext as t}from"@lexical/react/LexicalComposerContext";import{eventFiles as e}from"@lexical/rich-text";import{mergeRegister as n,isHTMLElement as r,calculateZoomLevel as o}from"@lexical/utils";import{DRAGOVER_COMMAND as i,COMMAND_PRIORITY_LOW as s,DROP_COMMAND as l,COMMAND_PRIORITY_HIGH as a,$getNodeByKey as c,$getNearestNodeFromDOMNode as u,$getRoot as h}from"lexical";import{useRef as m,useState as g,useCallback as f,useEffect as p}from"react";import{createPortal as d}from"react-dom";import{jsxs as y,Fragment as _,jsx as x}from"react/jsx-runtime";class b{_x;_y;constructor(t,e){this._x=t,this._y=e}get x(){return this._x}get y(){return this._y}equals({x:t,y:e}){return this.x===t&&this.y===e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}}class T{_left;_top;_right;_bottom;constructor(t,e,n,r){const[o,i]=e<=r?[e,r]:[r,e],[s,l]=t<=n?[t,n]:[n,t];this._top=o,this._right=l,this._left=s,this._bottom=i}get top(){return this._top}get right(){return this._right}get bottom(){return this._bottom}get left(){return this._left}get width(){return Math.abs(this._left-this._right)}get height(){return Math.abs(this._bottom-this._top)}equals({top:t,left:e,bottom:n,right:r}){return t===this._top&&n===this._bottom&&e===this._left&&r===this._right}contains(t){if(t instanceof b){const{x:e,y:n}=t,r=n<this._top,o=n>this._bottom,i=e<this._left,s=e>this._right;return{reason:{isOnBottomSide:o,isOnLeftSide:i,isOnRightSide:s,isOnTopSide:r},result:!(r||o||i||s)}}{const{top:e,left:n,bottom:r,right:o}=t;return e>=this._top&&e<=this._bottom&&r>=this._top&&r<=this._bottom&&n>=this._left&&n<=this._right&&o>=this._left&&o<=this._right}}intersectsWith(t){const{left:e,top:n,width:r,height:o}=t,{left:i,top:s,width:l,height:a}=this;return(e+r>=i+l?e+r:i+l)-(e<=i?e:i)<=r+l&&(n+o>=s+a?n+o:s+a)-(n<=s?n:s)<=o+a}generateNewRect({left:t=this.left,top:e=this.top,right:n=this.right,bottom:r=this.bottom}){return new T(t,e,n,r)}static fromLTRB(t,e,n,r){return new T(t,e,n,r)}static fromLWTH(t,e,n,r){return new T(t,n,t+e,n+r)}static fromPoints(t,e){const{y:n,x:r}=t,{y:o,x:i}=e;return T.fromLTRB(r,n,i,o)}static fromDOM(t){const{top:e,width:n,left:r,height:o}=t.getBoundingClientRect();return T.fromLWTH(r,n,e,o)}}const B=4,C=2,w="application/x-lexical-drag-block",v=28,D=1,R=-1,E=0;let S=1/0;function M(t){const e=(t,e)=>t?parseFloat(window.getComputedStyle(t)[e]):0,{marginTop:n,marginBottom:r}=window.getComputedStyle(t),o=e(t.previousElementSibling,"marginBottom"),i=e(t.nextElementSibling,"marginTop"),s=Math.max(parseFloat(n),o);return{marginBottom:Math.max(parseFloat(r),i),marginTop:s}}function L(t,e,n,r=!1){const i=t.getBoundingClientRect(),s=function(t){return t.getEditorState().read((()=>h().getChildrenKeys()))}(e);let l=null;return e.getEditorState().read((()=>{if(r){const[t,r]=[e.getElementByKey(s[0]),e.getElementByKey(s[s.length-1])],[i,a]=[null!=t?t.getBoundingClientRect():void 0,null!=r?r.getBoundingClientRect():void 0];if(i&&a){const e=o(t),s=o(r);if(n.y/e<i.top?l=t:n.y/s>a.bottom&&(l=r),l)return}}let t=0===(a=s.length)?1/0:S>=0&&S<a?S:Math.floor(a/2);var a;let c=E;for(;t>=0&&t<s.length;){const r=s[t],a=e.getElementByKey(r);if(null===a)break;const u=o(a),h=new b(n.x/u,n.y/u),m=T.fromDOM(a),{marginTop:g,marginBottom:f}=M(a),p=m.generateNewRect({bottom:m.bottom+f,left:i.left,right:i.right,top:m.top-g}),{result:d,reason:{isOnTopSide:y,isOnBottomSide:_}}=p.contains(h);if(d){l=a,S=t;break}c===E&&(c=y?R:_?D:1/0),t+=c}})),l}function O(t,h,b,T,D,R,E,S,O){const K=h.parentElement,Y=m(!1),[H,N]=g(null),$=f((t=>{N(t),O&&O(t)}),[O]);return p((()=>{function e(e){const n=e.target;if(!r(n))return void $(null);if(S(n))return;const o=L(h,t,e);$(o)}function n(){$(null)}return null!=K&&(K.addEventListener("mousemove",e),K.addEventListener("mouseleave",n)),()=>{null!=K&&(K.removeEventListener("mousemove",e),K.removeEventListener("mouseleave",n))}}),[K,h,t,S,$]),p((()=>{b.current&&function(t,e,n){if(!t)return e.style.opacity="0",void(e.style.transform="translate(-10000px, -10000px)");const r=t.getBoundingClientRect(),o=window.getComputedStyle(t),i=e.getBoundingClientRect(),s=n.getBoundingClientRect();let l=parseInt(o.lineHeight,10);isNaN(l)&&(l=r.bottom-r.top);const a=r.top+(l-i.height)/2-s.top+n.scrollTop,c=B;e.style.opacity="1",e.style.transform=`translate(${c}px, ${a}px)`}(H,b.current,h)}),[h,H,b]),p((()=>{function m(n){if(!Y.current)return!1;const[i]=e(n);if(i)return!1;const{pageY:s,target:l}=n;if(!r(l))return!1;const a=L(h,t,n,!0),c=T.current;return null!==a&&null!==c&&(function(t,e,n,r){const{top:o,height:i}=e.getBoundingClientRect(),{top:s,width:l}=r.getBoundingClientRect(),{marginTop:a,marginBottom:c}=M(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const h=u-s-C+r.scrollTop,m=v-B;t.style.transform=`translate(${m}px, ${h}px)`,t.style.width=l-2*(v-B)+"px",t.style.opacity=".4"}(c,a,s/o(l),h),n.preventDefault(),!0)}return n(t.registerCommand(i,(t=>m(t)),s),t.registerCommand(l,(n=>function(n){if(!Y.current)return!1;const[i]=e(n);if(i)return!1;const{target:s,dataTransfer:l,pageY:a}=n,m=null!=l?l.getData(w):"",g=c(m);if(!g)return!1;if(!r(s))return!1;const f=L(h,t,n,!0);if(!f)return!1;const p=u(f);if(!p)return!1;if(p===g)return!0;const d=f.getBoundingClientRect().top;return a/o(s)>=d?p.insertAfter(g):p.insertBefore(g),$(null),!0}(n)),a))}),[h,t,T,$]),d(y(_,{children:[x("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!H)return;!function(t,e){const{transform:n}=e.style;e.style.transform="translateZ(0)",t.setDragImage(e,0,0),setTimeout((()=>{e.style.transform=n}))}(n,H);let r="";t.update((()=>{const t=u(H);t&&(r=t.getKey())})),Y.current=!0,n.setData(w,r)},onDragEnd:function(){var t;Y.current=!1,(t=T.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:D&&R}),E]}),h)}function K({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return O(a,e,n,r,a._editable,o,i,s,l)}export{K as DraggableBlockPlugin_EXPERIMENTAL};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ 'use strict';
10
+
11
+ var useExtensionComponent = require('@lexical/react/useExtensionComponent');
12
+ var jsxRuntime = require('react/jsx-runtime');
13
+
14
+ /**
15
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ *
20
+ */
21
+
22
+ /**
23
+ * A convenient way to get an Extension's output Component with {@link useExtensionComponent}
24
+ * and construct it in one step.
25
+ *
26
+ * @example
27
+ * Usage
28
+ * ```tsx
29
+ * return (
30
+ * <ExtensionComponent
31
+ * lexical:extension={TreeViewExtension}
32
+ * viewClassName="tree-view-output" />
33
+ * );
34
+ * ```
35
+ *
36
+ * @example
37
+ * Alternative without ExtensionComponent
38
+ * ```tsx
39
+ * const TreeViewComponent = useExtensionComponent(TreeViewExtension);
40
+ * return (<TreeViewComponent viewClassName="tree-view-output" />);
41
+ * ```
42
+ */
43
+ function ExtensionComponent({
44
+ 'lexical:extension': extension,
45
+ ...props
46
+ }) {
47
+ const Component = useExtensionComponent.useExtensionComponent(extension);
48
+ return /*#__PURE__*/jsxRuntime.jsx(Component, {
49
+ ...props
50
+ });
51
+ }
52
+
53
+ exports.ExtensionComponent = ExtensionComponent;