/* esm.sh - @milkdown/plugin-block@7.22.3 */
import{browser as c,findParent as x}from"../../../prose@7.22.3/X-ZHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/prose.mjs";import{$ctx as d,$prose as S}from"../../../utils@7.22.3/X-ZEBtaWxrZG93bi9jb3JlQDcuMjIuMyxAbWlsa2Rvd24vY3R4QDcuMjIuMyxAbWlsa2Rvd24vcHJvc2VANy4yMi4zLHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/utils.mjs";import{NodeSelection as v,Plugin as D,PluginKey as T}from"../../../prose@7.22.3/X-ZHByb3NlbWlycm9yLW1vZGVsQDEuMjUuMTI/es2022/state.mjs";import{editorViewCtx as m}from"../../../core@7.22.3/X-ZEBtaWxrZG93bi9jdHhANy4yMi4zLEBtaWxrZG93bi9wcm9zZUA3LjIyLjMscHJvc2VtaXJyb3ItbW9kZWxAMS4yNS4xMg/es2022/core.mjs";import{throttle as P}from"../../../../lodash-es@^4.17.21?target=es2022";import{computePosition as M,flip as B,offset as N}from"../../../../@floating-ui/dom@^1.5.1?target=es2022";function h(t,i){return Object.assign(t,{meta:{package:"@milkdown/plugin-block",...i}}),t}var O=t=>!x(i=>i.type.name==="table")(t),p=d({filterNodes:O},"blockConfig");h(p,{displayName:"Ctx<blockConfig>"});function L(t,i,e){if(!t.dom.parentElement)return null;try{let r=t.posAtCoords({left:i.x,top:i.y})?.inside;if(r==null||r<0)return null;let s=t.state.doc.resolve(r),n=t.state.doc.nodeAt(r),o=t.nodeDOM(r),a=l=>{let E=s.depth>=1&&s.index(s.depth)===0;if(!(l||E))return;let f=s.before(s.depth);n=t.state.doc.nodeAt(f),o=t.nodeDOM(f),s=t.state.doc.resolve(f),e(s,n)||a(!0)};return a(!e(s,n)),!o||!n?null:{node:n,$pos:s,el:o}}catch{return null}}var y=c.ie&&c.ie_version<15||c.ios&&c.webkit_version<604,C=20,R=class{constructor(){this.#r=()=>{if(!this.#e)return null;let t=this.#e,i=this.#n;if(this.#s=null,i&&v.isSelectable(t.node)){let e=v.create(i.state.doc,t.$pos.pos);return i.dispatch(i.state.tr.setSelection(e)),i.focus(),this.#s=e,e}return null},this.#s=null,this.#e=null,this.#l=void 0,this.#i=!1,this.#a=()=>{this.#o?.({type:"hide"}),this.#e=null},this.#h=t=>{this.#e=t,this.#o?.({type:"show",active:t})},this.bind=(t,i)=>{this.#t=t,this.#o=i},this.addEvent=t=>{t.addEventListener("mousedown",this.#c),t.addEventListener("mouseup",this.#g),t.addEventListener("dragstart",this.#f),t.addEventListener("dragend",this.#m)},this.removeEvent=t=>{t.removeEventListener("mousedown",this.#c),t.removeEventListener("mouseup",this.#g),t.removeEventListener("dragstart",this.#f),t.removeEventListener("dragend",this.#m)},this.unBind=()=>{this.#o=void 0},this.#c=()=>{this.#l=this.#e?.el.getBoundingClientRect(),this.#r()},this.#g=()=>{if(!this.#i){requestAnimationFrame(()=>{this.#l&&this.#n?.focus()});return}this.#i=!1,this.#s=null},this.#f=t=>{this.#i=!0;let i=this.#n;if(!i)return;i.dom.dataset.dragging="true";let e=this.#s;if(t.dataTransfer&&e){let r=e.content();t.dataTransfer.effectAllowed="copyMove";let{dom:s,text:n}=i.serializeForClipboard(r);t.dataTransfer.clearData(),t.dataTransfer.setData(y?"Text":"text/html",s.innerHTML),y||t.dataTransfer.setData("text/plain",n);let o=this.#e?.el;o&&t.dataTransfer.setDragImage(o,0,0),i.dragging={slice:r,move:!0,node:e}}},this.#m=()=>{let t=this.#n;if(!t)return;this.#d(t);let i=t.dragging;window.setTimeout(()=>{t.dragging===i&&(t.dragging=null)},50)},this.keydownCallback=t=>(this.#a(),this.#i=!1,t.dom.dataset.dragging="false",!1),this.#p=P((t,i)=>{if(!t.editable)return;let e=t.dom.getBoundingClientRect(),r=e.left+e.width/2;if(!(t.root.elementFromPoint(r,i.clientY)instanceof Element)){this.#a();return}let s=this.#u;if(!s)return;let n=L(t,{x:r,y:i.clientY},s);if(!n){this.#a();return}this.#h(n)},200),this.mousemoveCallback=(t,i)=>(t.composing||!t.editable||this.#p(t,i),!1),this.dragoverCallback=(t,i)=>{if(this.#i){let e=this.#n?.dom.parentElement;if(!e)return!1;let r=e.scrollHeight>e.clientHeight,s=e.getBoundingClientRect();if(r){if(e.scrollTop>0&&Math.abs(i.y-s.y)<C)return e.scrollTop=e.scrollTop>10?e.scrollTop-10:0,!1;let n=Math.round(t.dom.getBoundingClientRect().height);if(Math.round(e.scrollTop+s.height)<n&&Math.abs(i.y-(s.height+s.y))<C)return e.scrollTop=e.scrollTop+10,!1}}return!1},this.dragenterCallback=t=>{t.dragging&&(this.#i=!0,t.dom.dataset.dragging="true")},this.dragleaveCallback=(t,i)=>{let e=i.clientX,r=i.clientY;(e<0||r<0||e>window.innerWidth||r>window.innerHeight)&&(this.#e=null,this.#d(t))},this.dropCallback=t=>(this.#d(t),!1),this.dragendCallback=t=>{this.#d(t)},this.#d=t=>{this.#i=!1,t.dom.dataset.dragging="false"}}#t;#r;#s;#e;#l;#i;get#u(){try{return this.#t?.get(p.key).filterNodes}catch{return}}get#n(){return this.#t?.get(m)}#o;#a;#h;#c;#g;#f;#m;#p;#d},k=d(()=>new R,"blockService"),u=d({},"blockServiceInstance");h(k,{displayName:"Ctx<blockService>"});h(u,{displayName:"Ctx<blockServiceInstance>"});var g=d({},"blockSpec");h(g,{displayName:"Ctx<blockSpec>"});var b=S(t=>{let i=new T("MILKDOWN_BLOCK"),e=t.get(k.key)();t.set(u.key,e);let r=t.get(g.key);return new D({key:i,...r,props:{...r.props,handleDOMEvents:{drop:s=>e.dropCallback(s),pointermove:(s,n)=>e.mousemoveCallback(s,n),keydown:s=>e.keydownCallback(s),dragover:(s,n)=>e.dragoverCallback(s,n),dragleave:(s,n)=>e.dragleaveCallback(s,n),dragenter:s=>e.dragenterCallback(s),dragend:s=>e.dragendCallback(s)}}})});h(b,{displayName:"Prose<block>"});var z=class{#t;#r;#s;#e;#l;#i;#u;#n;#o;#a;#h;get active(){return this.#e}constructor(t){this.#e=null,this.#i=!1,this.update=()=>{requestAnimationFrame(()=>{if(!this.#i)try{this.#c(),this.#i=!0}catch{}})},this.destroy=()=>{this.#s?.unBind(),this.#s?.removeEvent(this.#t),this.#t.remove()},this.show=i=>{let e=i.el,r=this.#r.get(m).dom,s={ctx:this.#r,active:i,editorDom:r,blockDom:this.#t},n={contextElement:e,getBoundingClientRect:()=>this.#a?this.#a(s):e.getBoundingClientRect()},o=[B()];if(this.#o){let a=this.#o(s),l=N(a);o.push(l)}M(n,this.#t,{placement:this.#h?this.#h(s):"left",middleware:[...o,...this.#u],...this.#n}).then(({x:a,y:l})=>{Object.assign(this.#t.style,{left:`${a}px`,top:`${l}px`}),this.#t.dataset.show="true"}).catch(console.error)},this.hide=()=>{this.#t.dataset.show="false"},this.#r=t.ctx,this.#t=t.content,this.#o=t.getOffset,this.#a=t.getPosition,this.#h=t.getPlacement,this.#u=t.middleware??[],this.#n=t.floatingUIOptions??{},this.#l=t.root,this.hide()}#c(){let t=this.#r.get(m);(this.#l??t.dom.parentElement??document.body).appendChild(this.#t);let i=this.#r.get(u.key);i.bind(this.#r,e=>{e.type==="hide"?(this.hide(),this.#e=null):e.type==="show"&&(this.show(e.active),this.#e=e.active)}),this.#s=i,this.#s.addEvent(this.#t),this.#t.draggable=!0}},w=[g,p,k,u,b];w.key=g.key;w.pluginKey=b.key;export{z as BlockProvider,R as BlockService,w as block,p as blockConfig,b as blockPlugin,k as blockService,u as blockServiceInstance,g as blockSpec,O as defaultNodeFilter};
//# sourceMappingURL=plugin-block.mjs.map