@lexical/react 0.38.3-nightly.20251210.0 → 0.39.1-nightly.20251229.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.
@@ -311,8 +311,7 @@ function getBlockElement(anchorElem, editor, event, useEdgeAsDefault = false) {
311
311
  }
312
312
  function setMenuPosition(targetElem, floatingElem, anchorElem) {
313
313
  if (!targetElem) {
314
- floatingElem.style.opacity = '0';
315
- floatingElem.style.transform = 'translate(-10000px, -10000px)';
314
+ floatingElem.style.display = 'none';
316
315
  return;
317
316
  }
318
317
  const targetRect = targetElem.getBoundingClientRect();
@@ -326,8 +325,9 @@ function setMenuPosition(targetElem, floatingElem, anchorElem) {
326
325
  // middle
327
326
  targetCalculateHeight = targetRect.bottom - targetRect.top;
328
327
  }
329
- const top = targetRect.top + (targetCalculateHeight - floatingElemRect.height) / 2 - anchorElementRect.top + anchorElem.scrollTop;
328
+ const top = targetRect.top + (targetCalculateHeight - (floatingElemRect.height || targetCalculateHeight)) / 2 - anchorElementRect.top + anchorElem.scrollTop;
330
329
  const left = SPACE;
330
+ floatingElem.style.display = 'flex';
331
331
  floatingElem.style.opacity = '1';
332
332
  floatingElem.style.transform = `translate(${left}px, ${top}px)`;
333
333
  }
@@ -309,8 +309,7 @@ function getBlockElement(anchorElem, editor, event, useEdgeAsDefault = false) {
309
309
  }
310
310
  function setMenuPosition(targetElem, floatingElem, anchorElem) {
311
311
  if (!targetElem) {
312
- floatingElem.style.opacity = '0';
313
- floatingElem.style.transform = 'translate(-10000px, -10000px)';
312
+ floatingElem.style.display = 'none';
314
313
  return;
315
314
  }
316
315
  const targetRect = targetElem.getBoundingClientRect();
@@ -324,8 +323,9 @@ function setMenuPosition(targetElem, floatingElem, anchorElem) {
324
323
  // middle
325
324
  targetCalculateHeight = targetRect.bottom - targetRect.top;
326
325
  }
327
- const top = targetRect.top + (targetCalculateHeight - floatingElemRect.height) / 2 - anchorElementRect.top + anchorElem.scrollTop;
326
+ const top = targetRect.top + (targetCalculateHeight - (floatingElemRect.height || targetCalculateHeight)) / 2 - anchorElementRect.top + anchorElem.scrollTop;
328
327
  const left = SPACE;
328
+ floatingElem.style.display = 'flex';
329
329
  floatingElem.style.opacity = '1';
330
330
  floatingElem.style.transform = `translate(${left}px, ${top}px)`;
331
331
  }
@@ -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{_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="application/x-lexical-drag-block";let u=1/0;function g(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 h(t,e,o,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.getEditorState().read(()=>r.$getRoot().getChildrenKeys())}(e);let h=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?h=t:o.y/l>s.bottom&&(h=r),h)return}}let t=0===(r=c.length)?1/0:u>=0&&u<r?u:Math.floor(r/2);var r;let m=0;for(;t>=0&&t<c.length;){const r=c[t],i=e.getElementByKey(r);if(null===i)break;const f=n.calculateZoomLevel(i),p=new l(o.x/f,o.y/f),d=a.fromDOM(i),{marginTop:_,marginBottom:y}=g(i),x=d.generateNewRect({bottom:d.bottom+y,left:s.left,right:s.right,top:d.top-_}),{result:b,reason:{isOnTopSide:T,isOnBottomSide:C}}=x.contains(p);if(b){h=i,u=t;break}0===m&&(m=T?-1:C?1:1/0),t+=m}}),h}function m(t,l,a,u,m,f,p,d,_){const y=l.parentElement,x=o.useRef(!1),[b,T]=o.useState(null),C=o.useCallback(t=>{T(t),_&&_(t)},[_]);return o.useEffect(()=>{function e(e){const r=e.target;if(!n.isHTMLElement(r))return void C(null);if(d(r))return;const o=h(l,t,e);C(o)}function r(){C(null)}return null!=y&&(y.addEventListener("mousemove",e),y.addEventListener("mouseleave",r)),()=>{null!=y&&(y.removeEventListener("mousemove",e),y.removeEventListener("mouseleave",r))}},[y,l,t,d,C]),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;e.style.opacity="1",e.style.transform=`translate(4px, ${a}px)`}(b,a.current,l)},[l,b,a]),o.useEffect(()=>{function o(r){if(!x.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=h(l,t,r,!0),c=u.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}=g(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const h=u-s-2+r.scrollTop;t.style.transform=`translate(24px, ${h}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,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(!x.current)return!1;const[i]=e.eventFiles(o);if(i)return!1;const{target:s,dataTransfer:a,pageY:u}=o,g=null!=a?a.getData(c):"",m=r.$getNodeByKey(g);if(!m)return!1;if(!n.isHTMLElement(s))return!1;const f=h(l,t,o,!0);if(!f)return!1;const p=r.$getNearestNodeFromDOMNode(f);if(!p)return!1;if(p===m)return!0;const d=f.getBoundingClientRect().top;return u/n.calculateZoomLevel(s)>=d?p.insertAfter(m):p.insertBefore(m),C(null),!0}(o),r.COMMAND_PRIORITY_HIGH))},[l,t,u,C]),i.createPortal(s.jsxs(s.Fragment,{children:[s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!b)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,b);let o="";t.update(()=>{const t=r.$getNearestNodeFromDOMNode(b);t&&(o=t.getKey())}),x.current=!0,n.setData(c,o)},onDragEnd:function(){var t;x.current=!1,(t=u.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:m&&f}),p]}),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 m(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="application/x-lexical-drag-block";let u=1/0;function g(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 h(t,e,o,i=!1){const s=t.getBoundingClientRect(),c=function(t){return t.getEditorState().read(()=>r.$getRoot().getChildrenKeys())}(e);let h=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?h=t:o.y/l>s.bottom&&(h=r),h)return}}let t=0===(r=c.length)?1/0:u>=0&&u<r?u:Math.floor(r/2);var r;let m=0;for(;t>=0&&t<c.length;){const r=c[t],i=e.getElementByKey(r);if(null===i)break;const f=n.calculateZoomLevel(i),p=new l(o.x/f,o.y/f),d=a.fromDOM(i),{marginTop:_,marginBottom:y}=g(i),x=d.generateNewRect({bottom:d.bottom+y,left:s.left,right:s.right,top:d.top-_}),{result:b,reason:{isOnTopSide:T,isOnBottomSide:C}}=x.contains(p);if(b){h=i,u=t;break}0===m&&(m=T?-1:C?1:1/0),t+=m}}),h}function m(t,l,a,u,m,f,p,d,_){const y=l.parentElement,x=o.useRef(!1),[b,T]=o.useState(null),C=o.useCallback(t=>{T(t),_&&_(t)},[_]);return o.useEffect(()=>{function e(e){const r=e.target;if(!n.isHTMLElement(r))return void C(null);if(d(r))return;const o=h(l,t,e);C(o)}function r(){C(null)}return null!=y&&(y.addEventListener("mousemove",e),y.addEventListener("mouseleave",r)),()=>{null!=y&&(y.removeEventListener("mousemove",e),y.removeEventListener("mouseleave",r))}},[y,l,t,d,C]),o.useEffect(()=>{a.current&&function(t,e,n){if(!t)return void(e.style.display="none");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||l))/2-s.top+n.scrollTop;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${a}px)`}(b,a.current,l)},[l,b,a]),o.useEffect(()=>{function o(r){if(!x.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=h(l,t,r,!0),c=u.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}=g(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const h=u-s-2+r.scrollTop;t.style.transform=`translate(24px, ${h}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,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(!x.current)return!1;const[i]=e.eventFiles(o);if(i)return!1;const{target:s,dataTransfer:a,pageY:u}=o,g=null!=a?a.getData(c):"",m=r.$getNodeByKey(g);if(!m)return!1;if(!n.isHTMLElement(s))return!1;const f=h(l,t,o,!0);if(!f)return!1;const p=r.$getNearestNodeFromDOMNode(f);if(!p)return!1;if(p===m)return!0;const d=f.getBoundingClientRect().top;return u/n.calculateZoomLevel(s)>=d?p.insertAfter(m):p.insertBefore(m),C(null),!0}(o),r.COMMAND_PRIORITY_HIGH))},[l,t,u,C]),i.createPortal(s.jsxs(s.Fragment,{children:[s.jsx("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!b)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,b);let o="";t.update(()=>{const t=r.$getNearestNodeFromDOMNode(b);t&&(o=t.getKey())}),x.current=!0,n.setData(c,o)},onDragEnd:function(){var t;x.current=!1,(t=u.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:m&&f}),p]}),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 m(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 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="application/x-lexical-drag-block";let C=1/0;function w(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 v(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:C>=0&&C<a?C:Math.floor(a/2);var a;let c=0;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}=w(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,C=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function D(t,h,b,T,C,D,R,E,S){const M=h.parentElement,L=m(!1),[O,K]=g(null),Y=f(t=>{K(t),S&&S(t)},[S]);return p(()=>{function e(e){const n=e.target;if(!r(n))return void Y(null);if(E(n))return;const o=v(h,t,e);Y(o)}function n(){Y(null)}return null!=M&&(M.addEventListener("mousemove",e),M.addEventListener("mouseleave",n)),()=>{null!=M&&(M.removeEventListener("mousemove",e),M.removeEventListener("mouseleave",n))}},[M,h,t,E,Y]),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;e.style.opacity="1",e.style.transform=`translate(4px, ${a}px)`}(O,b.current,h)},[h,O,b]),p(()=>{function m(n){if(!L.current)return!1;const[i]=e(n);if(i)return!1;const{pageY:s,target:l}=n;if(!r(l))return!1;const a=v(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}=w(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const h=u-s-2+r.scrollTop;t.style.transform=`translate(24px, ${h}px)`,t.style.width=l-48+"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(!L.current)return!1;const[i]=e(n);if(i)return!1;const{target:s,dataTransfer:l,pageY:a}=n,m=null!=l?l.getData(B):"",g=c(m);if(!g)return!1;if(!r(s))return!1;const f=v(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),Y(null),!0}(n),a))},[h,t,T,Y]),d(y(_,{children:[x("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!O)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,O);let r="";t.update(()=>{const t=u(O);t&&(r=t.getKey())}),L.current=!0,n.setData(B,r)},onDragEnd:function(){var t;L.current=!1,(t=T.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:C&&D}),R]}),h)}function R({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return D(a,e,n,r,a._editable,o,i,s,l)}export{R 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 g,useState as m,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="application/x-lexical-drag-block";let C=1/0;function w(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 v(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:C>=0&&C<a?C:Math.floor(a/2);var a;let c=0;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),g=T.fromDOM(a),{marginTop:m,marginBottom:f}=w(a),p=g.generateNewRect({bottom:g.bottom+f,left:i.left,right:i.right,top:g.top-m}),{result:d,reason:{isOnTopSide:y,isOnBottomSide:_}}=p.contains(h);if(d){l=a,C=t;break}0===c&&(c=y?-1:_?1:1/0),t+=c}}),l}function D(t,h,b,T,C,D,R,E,S){const M=h.parentElement,L=g(!1),[O,K]=m(null),Y=f(t=>{K(t),S&&S(t)},[S]);return p(()=>{function e(e){const n=e.target;if(!r(n))return void Y(null);if(E(n))return;const o=v(h,t,e);Y(o)}function n(){Y(null)}return null!=M&&(M.addEventListener("mousemove",e),M.addEventListener("mouseleave",n)),()=>{null!=M&&(M.removeEventListener("mousemove",e),M.removeEventListener("mouseleave",n))}},[M,h,t,E,Y]),p(()=>{b.current&&function(t,e,n){if(!t)return void(e.style.display="none");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||l))/2-s.top+n.scrollTop;e.style.display="flex",e.style.opacity="1",e.style.transform=`translate(4px, ${a}px)`}(O,b.current,h)},[h,O,b]),p(()=>{function g(n){if(!L.current)return!1;const[i]=e(n);if(i)return!1;const{pageY:s,target:l}=n;if(!r(l))return!1;const a=v(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}=w(e);let u=o;n>=o?u+=i+c/2:u-=a/2;const h=u-s-2+r.scrollTop;t.style.transform=`translate(24px, ${h}px)`,t.style.width=l-48+"px",t.style.opacity=".4"}(c,a,s/o(l),h),n.preventDefault(),!0)}return n(t.registerCommand(i,t=>g(t),s),t.registerCommand(l,n=>function(n){if(!L.current)return!1;const[i]=e(n);if(i)return!1;const{target:s,dataTransfer:l,pageY:a}=n,g=null!=l?l.getData(B):"",m=c(g);if(!m)return!1;if(!r(s))return!1;const f=v(h,t,n,!0);if(!f)return!1;const p=u(f);if(!p)return!1;if(p===m)return!0;const d=f.getBoundingClientRect().top;return a/o(s)>=d?p.insertAfter(m):p.insertBefore(m),Y(null),!0}(n),a))},[h,t,T,Y]),d(y(_,{children:[x("div",{draggable:!0,onDragStart:function(e){const n=e.dataTransfer;if(!n||!O)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,O);let r="";t.update(()=>{const t=u(O);t&&(r=t.getKey())}),L.current=!0,n.setData(B,r)},onDragEnd:function(){var t;L.current=!1,(t=T.current)&&(t.style.opacity="0",t.style.transform="translate(-10000px, -10000px)")},children:C&&D}),R]}),h)}function R({anchorElem:e=document.body,menuRef:n,targetLineRef:r,menuComponent:o,targetLineComponent:i,isOnMenu:s,onElementChanged:l}){const[a]=t();return D(a,e,n,r,a._editable,o,i,s,l)}export{R as DraggableBlockPlugin_EXPERIMENTAL};
package/package.json CHANGED
@@ -8,26 +8,26 @@
8
8
  "rich-text"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.38.3-nightly.20251210.0",
11
+ "version": "0.39.1-nightly.20251229.0",
12
12
  "dependencies": {
13
13
  "@floating-ui/react": "^0.27.16",
14
- "@lexical/devtools-core": "0.38.3-nightly.20251210.0",
15
- "@lexical/dragon": "0.38.3-nightly.20251210.0",
16
- "@lexical/extension": "0.38.3-nightly.20251210.0",
17
- "@lexical/hashtag": "0.38.3-nightly.20251210.0",
18
- "@lexical/history": "0.38.3-nightly.20251210.0",
19
- "@lexical/link": "0.38.3-nightly.20251210.0",
20
- "@lexical/list": "0.38.3-nightly.20251210.0",
21
- "@lexical/mark": "0.38.3-nightly.20251210.0",
22
- "@lexical/markdown": "0.38.3-nightly.20251210.0",
23
- "@lexical/overflow": "0.38.3-nightly.20251210.0",
24
- "@lexical/plain-text": "0.38.3-nightly.20251210.0",
25
- "@lexical/rich-text": "0.38.3-nightly.20251210.0",
26
- "@lexical/table": "0.38.3-nightly.20251210.0",
27
- "@lexical/text": "0.38.3-nightly.20251210.0",
28
- "@lexical/utils": "0.38.3-nightly.20251210.0",
29
- "@lexical/yjs": "0.38.3-nightly.20251210.0",
30
- "lexical": "0.38.3-nightly.20251210.0",
14
+ "@lexical/devtools-core": "0.39.1-nightly.20251229.0",
15
+ "@lexical/dragon": "0.39.1-nightly.20251229.0",
16
+ "@lexical/extension": "0.39.1-nightly.20251229.0",
17
+ "@lexical/hashtag": "0.39.1-nightly.20251229.0",
18
+ "@lexical/history": "0.39.1-nightly.20251229.0",
19
+ "@lexical/link": "0.39.1-nightly.20251229.0",
20
+ "@lexical/list": "0.39.1-nightly.20251229.0",
21
+ "@lexical/mark": "0.39.1-nightly.20251229.0",
22
+ "@lexical/markdown": "0.39.1-nightly.20251229.0",
23
+ "@lexical/overflow": "0.39.1-nightly.20251229.0",
24
+ "@lexical/plain-text": "0.39.1-nightly.20251229.0",
25
+ "@lexical/rich-text": "0.39.1-nightly.20251229.0",
26
+ "@lexical/table": "0.39.1-nightly.20251229.0",
27
+ "@lexical/text": "0.39.1-nightly.20251229.0",
28
+ "@lexical/utils": "0.39.1-nightly.20251229.0",
29
+ "@lexical/yjs": "0.39.1-nightly.20251229.0",
30
+ "lexical": "0.39.1-nightly.20251229.0",
31
31
  "react-error-boundary": "^6.0.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -36,7 +36,7 @@
36
36
  },
37
37
  "repository": {
38
38
  "type": "git",
39
- "url": "https://github.com/facebook/lexical",
39
+ "url": "git+https://github.com/facebook/lexical.git",
40
40
  "directory": "packages/lexical-react"
41
41
  },
42
42
  "exports": {
@@ -1546,4 +1546,4 @@
1546
1546
  "@types/jest-axe": "^3.5.9",
1547
1547
  "jest-axe": "^10.0.0"
1548
1548
  }
1549
- }
1549
+ }