@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
2 lines (1 loc) • 7.88 kB
JavaScript
import{n as b,t as B}from"./chunk-R43NMSZO.js";import{N as C,P as v,Q as g,T as w,U as T,pa as j,qa as R,ra as F}from"./chunk-XNCXGIZE.js";import{a as P,d as A}from"./chunk-OQJVATGH.js";function Y(t){return t.nodeType===1}function G(t){return Y(t)&&t.namespaceURI==="http://www.w3.org/1999/xhtml"}var ce=2**53-1;function J(t){let e=[[-1,t.state.doc]],n=[];for(;e.length>0;){let[o,r]=e.pop();if(o>=0){let l=t.nodeDOM(o);if(l&&G(l)){let{top:i,bottom:u,left:s,right:f}=l.getBoundingClientRect();n.push([o,[s,i,f,i]],[o+r.nodeSize,[s,u,f,u]])}}if(r.isBlock&&!r.isTextblock){let l=o+1;for(let i of r.children)e.push([l,i]),l+=i.nodeSize}}return n}function Q(t,e){let n=[],o,r,l=()=>{let c=t.dom.getBoundingClientRect(),p=t.state.doc;return n&&o&&r&&c.width===r.width&&c.height===r.height&&c.x===r.x&&c.y===r.y&&o.eq(p)||(r=c,o=p,n=J(t)),n},i=(c,p)=>{if(!t.editable||t.isDestroyed)return;let m=(y,S)=>{let[x,E]=y,[N,O]=S;return W(c,E)-W(c,O)||x-N},a=l();a.sort(m),a=a.slice(0,8);let h=a.find(y=>e?.({view:t,pos:y[0],event:p})!==!1);if(!(h&&_(t,h[0])))return h},u,s;return(c,p)=>(u&&Z(u,c)||(u=c,s=i(c,p)),s)}function Z(t,e){return t[0]===e[0]&&t[1]===e[1]}function z(t,e){return Math.abs(t[0]-e[0])+Math.abs(t[1]-e[1])}function W(t,e){return Math.min(z(t,[e[0],e[1]]),z(t,[e[2],e[3]]))}function _(t,e){let n=t.dragging;if(!n)return;let{move:o}=n;if(!o)return;let r=t.state.selection;if(!(r instanceof g))return;let{from:l,to:i}=r;return l<=e&&e<=i}function H(t){let e;return new w({key:new T("prosemirror-drop-indicator"),view:n=>(e=Q(n,t.onDrag),ee(n,e,t)),props:{handleDrop(n,o,r,l){if(!e)return!1;let i=e([o.clientX,o.clientY],o);if(!i)return!1;o.preventDefault();let u=i[0],s=n.state.tr;if(l){let{node:a}=n.dragging||{};a?a.replace(s):s.deleteSelection()}let f=s.mapping.map(u),c=r.openStart==0&&r.openEnd==0&&r.content.childCount==1,p=s.doc;if(c?s.replaceRangeWith(f,f,r.content.firstChild):s.replaceRange(f,f,r),s.doc.eq(p))return!0;let m=s.doc.resolve(f);if(c&&g.isSelectable(r.content.firstChild)&&m.nodeAfter&&m.nodeAfter.sameMarkup(r.content.firstChild))s.setSelection(new g(m));else{let a=s.mapping.map(u);s.mapping.maps[s.mapping.maps.length-1].forEach((h,y,S,x)=>a=x),s.setSelection($(n,m,s.doc.resolve(a)))}return n.focus(),n.dispatch(s.setMeta("uiEvent","drop")),!0}}})}function $(t,e,n,o){return t.someProp("createSelectionBetween",r=>r(t,e,n))||v.between(e,n,o)}function ee(t,e,n){let o=t.dom,r,l,i,u=!1,s=()=>{r&&clearTimeout(r),u=!1,r=setTimeout(()=>{u||n.onHide?.()},30)},f=p=>{u=!0;let{clientX:m,clientY:a}=p;if(l===m&&i===a)return;l=m,i=a;let h=e([m,a],p);if(h){let[y,[S,x,E,N]]=h,O={p1:{x:S,y:x},p2:{x:E,y:N}};n.onShow?.({view:t,pos:y,line:O})}else{s();return}};return o.addEventListener("dragover",f),o.addEventListener("dragend",s),o.addEventListener("drop",s),o.addEventListener("dragleave",s),{destroy:()=>{o.removeEventListener("dragover",f),o.removeEventListener("dragend",s),o.removeEventListener("drop",s),o.removeEventListener("dragleave",s)}}}var d=class t extends C{constructor(e){super(e,e)}map(e,n){let o=e.resolve(n.map(this.head));return t.valid(o)?new t(o):C.near(o)}content(){return A.empty}eq(e){return e instanceof t&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,n){if(typeof n.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new t(e.resolve(n.pos))}getBookmark(){return new L(this.anchor)}static valid(e){let n=e.parent;if(n.inlineContent||!te(e)||!ne(e))return!1;let o=n.type.spec.allowGapCursor;if(o!=null)return o;let r=n.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,n,o=!1){e:for(;;){if(!o&&t.valid(e))return e;let r=e.pos,l=null;for(let i=e.depth;;i--){let u=e.node(i);if(n>0?e.indexAfter(i)<u.childCount:e.index(i)>0){l=u.child(n>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;r+=n;let s=e.doc.resolve(r);if(t.valid(s))return s}for(;;){let i=n>0?l.firstChild:l.lastChild;if(!i){if(l.isAtom&&!l.isText&&!g.isSelectable(l)){e=e.doc.resolve(r+l.nodeSize*n),o=!1;continue e}break}l=i,r+=n;let u=e.doc.resolve(r);if(t.valid(u))return u}return null}}};d.prototype.visible=!1;d.findFrom=d.findGapCursorFrom;C.jsonID("gapcursor",d);var L=class t{constructor(e){this.pos=e}map(e){return new t(e.map(this.pos))}resolve(e){let n=e.resolve(this.pos);return d.valid(n)?new d(n):C.near(n)}};function K(t){return t.isAtom||t.spec.isolating||t.spec.createGapCursor}function te(t){for(let e=t.depth;e>=0;e--){let n=t.index(e),o=t.node(e);if(n==0){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(n-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||K(r.type))return!0;if(r.inlineContent)return!1}}return!0}function ne(t){for(let e=t.depth;e>=0;e--){let n=t.indexAfter(e),o=t.node(e);if(n==o.childCount){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(n);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||K(r.type))return!0;if(r.inlineContent)return!1}}return!0}function V(){return new w({props:{decorations:se,createSelectionBetween(t,e,n){return e.pos==n.pos&&d.valid(n)?new d(n):null},handleClick:oe,handleKeyDown:re,handleDOMEvents:{beforeinput:ie}}})}var re=j({ArrowLeft:I("horiz",-1),ArrowRight:I("horiz",1),ArrowUp:I("vert",-1),ArrowDown:I("vert",1)});function I(t,e){let n=t=="vert"?e>0?"down":"up":e>0?"right":"left";return function(o,r,l){let i=o.selection,u=e>0?i.$to:i.$from,s=i.empty;if(i instanceof v){if(!l.endOfTextblock(n)||u.depth==0)return!1;s=!1,u=o.doc.resolve(e>0?u.after():u.before())}let f=d.findGapCursorFrom(u,e,s);return f?(r&&r(o.tr.setSelection(new d(f))),!0):!1}}function oe(t,e,n){if(!t||!t.editable)return!1;let o=t.state.doc.resolve(e);if(!d.valid(o))return!1;let r=t.posAtCoords({left:n.clientX,top:n.clientY});return r&&r.inside>-1&&g.isSelectable(t.state.doc.nodeAt(r.inside))?!1:(t.dispatch(t.state.tr.setSelection(new d(o))),!0)}function ie(t,e){if(e.inputType!="insertCompositionText"||!(t.state.selection instanceof d))return!1;let{$from:n}=t.state.selection,o=n.parent.contentMatchAt(n.index()).findWrapping(t.state.schema.nodes.text);if(!o)return!1;let r=P.empty;for(let i=o.length-1;i>=0;i--)r=P.from(o[i].createAndFill(null,r));let l=t.state.tr.replace(n.pos,n.pos,new A(r,0,0));return l.setSelection(v.near(l.doc.resolve(n.pos+1))),t.dispatch(l),!1}function se(t){if(!(t.selection instanceof d))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",F.create(t.doc,[R.widget(t.selection.head,e,{key:"gapcursor"})])}function D(t,e){return Object.assign(t,{meta:{package:"@milkdown/plugin-cursor",...e}}),t}var M=B(null,"dropIndicatorState");D(M,{displayName:"Ctx<dropIndicatorState>"});var k=B({width:2,color:!1,class:"milkdown-drop-indicator"},"dropIndicatorConfig");D(k,{displayName:"Ctx<dropIndicatorConfig>"});var le=new T("MILKDOWN_DROP_INDICATOR_DOM"),q=b(t=>new w({key:le,view:e=>{let n=t.get(k.key),o=document.createElement("div");Object.assign(o.style,{position:"fixed",pointerEvents:"none",display:"none",backgroundColor:n.color,top:"0",left:"0"}),o.classList.add(n.class),o.classList.add("milkdown-drop-indicator"),e.dom.parentNode?.appendChild(o);let r=t.use(M.key),l=i=>{ue(o,i,n)};return r.on(l),{destroy:()=>{r.off(l),o.remove()}}}}));D(q,{displayName:"Prose<dropIndicatorDOM>"});function ue(t,e,n){if(!e){Object.assign(t.style,{display:"none"});return}let{line:o}=e,{width:r}=n,{p1:{x:l,y:i},p2:{x:u,y:s}}=o,f=i===s,c,p,m=i,a=l;f?(c=u-l,p=r,m-=r/2):(c=r,p=s-i,a-=r/2),m=Math.round(m),a=Math.round(a),Object.assign(t.style,{display:"block",width:`${c}px`,height:`${p}px`,transform:`translate(${a}px, ${m}px)`})}var U=b(t=>H({onShow:o=>{t.set(M.key,o)},onHide:()=>{t.set(M.key,null)},onDrag:()=>!0}));D(U,{displayName:"Prose<dropIndicator>"});var X=b(()=>V());D(X,{displayName:"Prose<gapCursor>"});var De=k,Se=[X,k,M,q,U].flat();export{M as a,k as b,q as c,U as d,X as e,De as f,Se as g};