@payloadcms/richtext-lexical 3.86.0-internal.8bd478e → 3.86.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.
@@ -0,0 +1,12 @@
1
+ var at=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";import{c as _e}from"react/compiler-runtime";import{useRef as Te}from"react";function pr(n){let t=_e(2),e=n===void 0?500:n,o=Te(void 0),r;return t[0]!==e?(r=c=>new Promise(i=>{let l=()=>{c(),i()};"requestIdleCallback"in window?("cancelIdleCallback"in window&&o.current!==void 0&&cancelIdleCallback(o.current),o.current=requestIdleCallback(l,{timeout:e})):we().then(l)}),t[0]=e,t[1]=r):r=t[1],r}function we(){return new Promise(n=>{setTimeout(n,100),requestAnimationFrame(()=>{setTimeout(n,0)})})}import{jsx as Ce}from"react/jsx-runtime";import{useControllableState as Se}from"@payloadcms/ui";import{createContext as Re,use as ke,useMemo as ye}from"react";var ft=Re({currentView:"default",inheritable:!1,setCurrentView:()=>{}}),Tr=n=>{let t=be(),e=n.currentView!==void 0,o=t.inheritable&&(!!t.views||!!t.hasExplicitCurrentView),r=e||t.inheritable&&!!t.hasExplicitCurrentView,{children:s,currentView:c,inheritable:i,views:l}={children:n.children,currentView:o?t.currentView:n.currentView,inheritable:t.inheritable||n.inheritable,views:o&&t.views?t.views:n.views},[a,f]=Se(c,"default"),p=l&&a!=="default"&&!l[a]?"default":a,m=ye(()=>{let g=l?l[p]:void 0;return{currentView:p,currentViewMap:g,hasExplicitCurrentView:r,inheritable:i,isControlledByParent:o,setCurrentView:f,views:l}},[p,i,r,o,f,l]);return Ce(ft,{value:m,children:s})};function be(){return ke(ft)}var G=class{_x;_y;constructor(t,e){this._x=t,this._y=e}calcDeltaXTo({x:t}){return this.x-t}calcDeltaYTo({y:t}){return this.y-t}calcDistanceTo(t){return Math.sqrt(Math.pow(this.calcDeltaXTo(t),2)+Math.pow(this.calcDeltaYTo(t),2))}calcHorizontalDistanceTo(t){return Math.abs(this.calcDeltaXTo(t))}calcVerticalDistance(t){return Math.abs(this.calcDeltaYTo(t))}equals({x:t,y:e}){return this.x===t&&this.y===e}get x(){return this._x}get y(){return this._y}};function ut(n){return n instanceof G}import{jsx as ze}from"react/jsx-runtime";import{useLexicalComposerContext as We}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as Ye}from"@lexical/utils";import{$getSelection as Y,$isRangeSelection as j,$isTextNode as je,COMMAND_PRIORITY_LOW as qe,createCommand as Qe,getDOMSelection as Je}from"lexical";import{useCallback as Ct,useEffect as St,useState as Ze}from"react";import*as W from"react";import{c as xt}from"react/compiler-runtime";import{useLexicalComposerContext as Et}from"@lexical/react/LexicalComposerContext.js";import{mergeRegister as dt}from"@lexical/utils";import{$getSelection as _t,$isRangeSelection as Oe,$setSelection as Ne,COMMAND_PRIORITY_LOW as mt,COMMAND_PRIORITY_NORMAL as $,createCommand as Fe,KEY_ARROW_DOWN_COMMAND as Ie,KEY_ARROW_UP_COMMAND as Me,KEY_ENTER_COMMAND as Le,KEY_ESCAPE_COMMAND as Ae,KEY_TAB_COMMAND as De}from"lexical";import{useCallback as z,useEffect as b,useLayoutEffect as $e,useMemo as Be,useRef as ve,useState as Pe}from"react";var He="slash-menu-popup",pt=n=>{let t=document.getElementById("slash-menu");if(!t)return;let e=t.getBoundingClientRect();e.top+e.height>window.innerHeight&&t.scrollIntoView({block:"center"}),e.top<0&&t.scrollIntoView({block:"center"}),n.scrollIntoView({block:"nearest"})};function Ke(n,t,e){let o=e;for(let r=o;r<=t.length;r++)n.substring(n.length-r)===t.substring(0,r)&&(o=r);return o}function Ue(n){let t=_t();if(!Oe(t)||!t.isCollapsed())return;let e=t.anchor;if(e.type!=="text")return;let o=e.getNode();if(!o.isSimpleText())return;let r=e.offset,s=o.getTextContent().slice(0,r),c=n.replaceableString.length,i=Ke(s,n.matchingString,c),l=r-i;if(l<0)return;let a;return l===0?[a]=o.splitText(r):[,a]=o.splitText(l,r),a}function Ve(n,t){let e=getComputedStyle(n),o=e.position==="absolute",r=t?/(auto|scroll|hidden)/:/(auto|scroll)/;if(e.position==="fixed")return document.body;for(let s=n;s=s.parentElement;)if(e=getComputedStyle(s),!(o&&e.position==="static")&&r.test(e.overflow+e.overflowY+e.overflowX))return s;return document.body}function gt(n,t){let e=n.getBoundingClientRect(),o=t.getBoundingClientRect();return e.top>o.top&&e.top<o.bottom}function Xe(n,t,e,o){let r=xt(7),[s]=Et(),c,i;r[0]!==s||r[1]!==e||r[2]!==o||r[3]!==n||r[4]!==t?(c=()=>{let l=t.current;if(l!=null&&n!=null){let a=s.getRootElement(),f=a!=null?Ve(a,!1):document.body,p=!1,m=gt(l,f),g=function(){p||(window.requestAnimationFrame(function(){e(),p=!1}),p=!0);let d=gt(l,f);d!==m&&(m=d,o?.(d))},u=new ResizeObserver(e);return window.addEventListener("resize",e),document.addEventListener("scroll",g,{capture:!0,passive:!0}),u.observe(l),()=>{u.disconnect(),window.removeEventListener("resize",e),document.removeEventListener("scroll",g,!0)}}},i=[s,o,e,n,t],r[0]=s,r[1]=e,r[2]=o,r[3]=n,r[4]=t,r[5]=c,r[6]=i):(c=r[5],i=r[6]),b(c,i)}var ht=Fe("SCROLL_TYPEAHEAD_OPTION_INTO_VIEW_COMMAND");function Tt({anchorElementRef:n,close:t,editor:e,groups:o,menuRenderFn:r,resolution:s,shouldSplitNodeWithQuery:c=!1}){let[i,l]=Pe(null),a=s.match&&s.match.matchingString||"",f=z(u=>{let d=e.getRootElement();d!==null&&(d.setAttribute("aria-activedescendant",`${He}__item-${u.key}`),l(u.key))},[e]),p=z(()=>{if(o!==null&&a!=null){let u=o.flatMap(d=>d.items);if(u.length){let d=u[0];f(d)}}},[o,f,a]);b(()=>{p()},[a,p]);let m=z(u=>{t(),e.update(()=>{let d=s.match!=null&&c?Ue(s.match):null;d&&d.remove()}),setTimeout(()=>{let d;e.read(()=>{d=_t()?.clone()}),e.update(()=>{d&&Ne(d)}),u.onSelect({editor:e,queryString:s.match?s.match.matchingString:""})},0)},[e,c,s.match,t]);b(()=>()=>{let u=e.getRootElement();u!==null&&u.removeAttribute("aria-activedescendant")},[e]),$e(()=>{o===null?l(null):i===null&&p()},[o,i,f,p]),b(()=>dt(e.registerCommand(ht,({item:u})=>u.ref&&u.ref.current!=null?(pt(u.ref.current),!0):!1,mt)),[e,f]),b(()=>dt(e.registerCommand(Ie,u=>{let d=u;if(o!==null&&o.length&&i!==null){let h=o.flatMap(T=>T.items),x=h.findIndex(T=>T.key===i),E=x!==h.length-1?x+1:0,_=h[E];if(!_)return!1;f(_),_.ref!=null&&_.ref.current&&e.dispatchCommand(ht,{index:E,item:_}),d.preventDefault(),d.stopImmediatePropagation()}return!0},$),e.registerCommand(Me,u=>{let d=u;if(o!==null&&o.length&&i!==null){let h=o.flatMap(T=>T.items),x=h.findIndex(T=>T.key===i),E=x!==0?x-1:h.length-1,_=h[E];if(!_)return!1;f(_),_.ref!=null&&_.ref.current&&pt(_.ref.current),d.preventDefault(),d.stopImmediatePropagation()}return!0},$),e.registerCommand(Ae,u=>{let d=u;return d.preventDefault(),d.stopImmediatePropagation(),t(),!0},mt),e.registerCommand(De,u=>{let d=u;if(o===null||i===null)return!1;let x=o.flatMap(E=>E.items).find(E=>E.key===i);return x?(d.preventDefault(),d.stopImmediatePropagation(),m(x),!0):!1},$),e.registerCommand(Le,u=>{if(o===null||i===null)return!1;let h=o.flatMap(x=>x.items).find(x=>x.key===i);return h?(u!==null&&(u.preventDefault(),u.stopImmediatePropagation()),m(h),!0):!1},$)),[m,t,e,o,i,f]);let g=Be(()=>({groups:o,selectedItemKey:i,selectItemAndCleanUp:m,setSelectedItemKey:l}),[m,i,o]);return r(n,g,s.match?s.match.matchingString:"")}function Ge(n,t){t!=null&&(n.className=t),n.setAttribute("aria-label","Slash menu"),n.setAttribute("role","listbox"),n.style.display="block",n.style.position="absolute"}function wt(n,t,e,o){let r=xt(14),[s]=Et(),c;r[0]===Symbol.for("react.memo_cache_sentinel")?(c=at?document.createElement("div"):null,r[0]=c):c=r[0];let i=ve(c),l;r[1]!==n||r[2]!==o||r[3]!==s||r[4]!==t?(l=()=>{if(i.current===null||parent===void 0)return;let u=s.getRootElement(),d=i.current,h=d.firstChild;if(u!==null&&t!==null){let{height:x,width:E}=t.getRect(),{left:_,top:T}=t.getRect(),y=T;if(T=T-(n.getBoundingClientRect().top+window.scrollY),_=_-(n.getBoundingClientRect().left+window.scrollX),d.style.left=`${_+window.scrollX}px`,d.style.height=`${x}px`,d.style.width=`${E}px`,h!==null){let w=h.getBoundingClientRect(),D=w.height,S=w.width,X=u.getBoundingClientRect(),ct=document.dir==="rtl"||document.documentElement.dir==="rtl",ge=n.getBoundingClientRect(),lt=Math.max(0,X.left);if(!ct&&_+S>X.right)d.style.left=`${X.right-S+window.scrollX}px`;else if(ct&&w.left<lt){let Ee=lt+S-ge.left;d.style.left=`${Ee+window.scrollX}px`}let he=y+D+32>window.innerHeight,xe=y<0;he&&!xe?d.style.top=`${T+32-D+window.scrollY-(x+24)}px`:d.style.top=`${T+window.scrollY+32}px`}d.isConnected||(Ge(d,o),n.append(d)),d.setAttribute("id","slash-menu"),i.current=d,u.setAttribute("aria-controls","slash-menu")}},r[1]=n,r[2]=o,r[3]=s,r[4]=t,r[5]=l):l=r[5];let a=l,f,p;r[6]!==s||r[7]!==a||r[8]!==t?(f=()=>{let u=s.getRootElement();if(t!==null)return a(),()=>{u!==null&&u.removeAttribute("aria-controls");let d=i.current;d!==null&&d.isConnected&&(d.remove(),d.removeAttribute("id"))}},p=[s,a,t],r[6]=s,r[7]=a,r[8]=t,r[9]=f,r[10]=p):(f=r[9],p=r[10]),b(f,p);let m;return r[11]!==t||r[12]!==e?(m=u=>{t!==null&&(u||e(null))},r[11]=t,r[12]=e,r[13]=m):m=r[13],Xe(t,i,a,m),i}var $r=`\\.,\\+\\*\\?\\$\\@\\|#{}\\(\\)\\^\\-\\[\\]\\\\/!%'"~=<>_:;`;function tn(n){let t=n.anchor;if(t.type!=="text")return null;let e=t.getNode();if(!e.isSimpleText())return null;let o=t.offset;return e.getTextContent().slice(0,o)}function Rt(n,t,e){let o=Je(e);if(o===null||!o.isCollapsed)return!1;let r=o.anchorNode,s=n,c=o.anchorOffset;if(r==null||c==null)return!1;try{t.setStart(r,s),t.setEnd(r,c>1?c:1)}catch{return!1}return!0}function en(n){let t;return n.getEditorState().read(()=>{let e=Y();j(e)&&(t=tn(e))}),t}function kt(n,t){return t!==0?!1:n.getEditorState().read(()=>{let e=Y();if(j(e)){let s=e.anchor.getNode().getPreviousSibling();return je(s)&&s.isTextEntity()}return!1})}function yt(n){W.startTransition?W.startTransition(n):n()}var nn=Qe("ENABLE_SLASH_MENU_COMMAND");function Br({anchorClassName:n,anchorElem:t,groups:e,menuRenderFn:o,onClose:r,onOpen:s,onQueryChange:c,triggerFn:i}){let[l]=We(),[a,f]=Ze(null),p=wt(t,a,f,n),m=Ct(()=>{f(null),r!=null&&a!==null&&r()},[r,a]),g=Ct(u=>{f(u),s!=null&&a===null&&s(u)},[s,a]);return St(()=>Ye(l.registerCommand(nn,({node:u})=>(l.getEditorState().read(()=>{let d={leadOffset:0,matchingString:"",replaceableString:""};if(!kt(l,d.leadOffset)&&u!==null){let h=l._window??window,x=h.document.createRange();Rt(d.leadOffset,x,h)!==null&&yt(()=>g({getRect:()=>x.getBoundingClientRect(),match:d}));return}}),!0),qe)),[l,g]),St(()=>{let u=()=>{l.getEditorState().read(()=>{let h=l._window??window,x=h.document.createRange(),E=Y(),_=en(l);if(!j(E)||!E.isCollapsed()||_===void 0||x===null){m();return}let T=i({editor:l,query:_});if(c(T?T.matchingString:null),T!==null&&!kt(l,T.leadOffset)&&Rt(T.leadOffset,x,h)!==null){yt(()=>g({getRect:()=>x.getBoundingClientRect(),match:T}));return}m()})},d=l.registerUpdateListener(u);return()=>{d()}},[l,i,c,a,m,g]),p.current===null||a===null||l===null?null:ze(Tt,{anchorElementRef:p,close:m,editor:l,groups:e,menuRenderFn:o,resolution:a,shouldSplitNodeWithQuery:!0})}var bt=class n{_bottom;_left;_right;_top;constructor(t,e,o,r){let[s,c]=e<=r?[e,r]:[r,e],[i,l]=t<=o?[t,o]:[o,t];this._top=s,this._right=l,this._left=i,this._bottom=c}static fromDOM(t){let{height:e,left:o,top:r,width:s}=t.getBoundingClientRect();return n.fromLWTH(o,s,r,e)}static fromDOMRect(t){let{height:e,left:o,top:r,width:s}=t;return n.fromLWTH(o,s,r,e)}static fromLTRB(t,e,o,r){return new n(t,e,o,r)}static fromLWTH(t,e,o,r){return new n(t,o,t+e,o+r)}static fromPoints(t,e){let{x:o,y:r}=t,{x:s,y:c}=e;return n.fromLTRB(o,r,s,c)}contains(t){if(ut(t)){let{x:c,y:i}=t,l=i<this._top,a=i>this._bottom,f=c<this._left,p=c>this._right;return{reason:{isOnBottomSide:a,isOnLeftSide:f,isOnRightSide:p,isOnTopSide:l},result:!l&&!a&&!f&&!p}}let{bottom:e,left:o,right:r,top:s}=t;return s>=this._top&&s<=this._bottom&&e>=this._top&&e<=this._bottom&&o>=this._left&&o<=this._right&&r>=this._left&&r<=this._right}distanceFromPoint(t){let e=this.contains(t);if(e.result)return{distance:0,isOnBottomSide:e.reason.isOnBottomSide,isOnLeftSide:e.reason.isOnLeftSide,isOnRightSide:e.reason.isOnRightSide,isOnTopSide:e.reason.isOnTopSide};let o=0,r=0;return t.x<this._left?o=this._left-t.x:t.x>this._right&&(o=t.x-this._right),t.y<this._top?r=this._top-t.y:t.y>this._bottom&&(r=t.y-this._bottom),{distance:Math.sqrt(o*o+r*r),isOnBottomSide:t.y>this._bottom,isOnLeftSide:t.x<this._left,isOnRightSide:t.x>this._right,isOnTopSide:t.y<this._top}}equals({bottom:t,left:e,right:o,top:r}){return r===this._top&&t===this._bottom&&e===this._left&&o===this._right}generateNewRect({bottom:t=this.bottom,left:e=this.left,right:o=this.right,top:r=this.top}){return new n(e,r,o,t)}intersectsWith(t){let{height:e,left:o,top:r,width:s}=t,{height:c,left:i,top:l,width:a}=this,f=o+s>=i+a?o+s:i+a,p=r+e>=l+c?r+e:l+c,m=o<=i?o:i,g=r<=l?r:l;return f-m<=s+a&&p-g<=e+c}get bottom(){return this._bottom}get height(){return Math.abs(this._bottom-this._top)}get left(){return this._left}get right(){return this._right}get top(){return this._top}get width(){return Math.abs(this._left-this._right)}};import q from"react";var L=new WeakMap;function Ur(n,t){L.has(n)||L.set(n,new Map);let e=L.get(n);for(let[o,r]of Object.entries(t))if(!(!r||typeof r!="object")){if(o==="blocks"){for(let[s,c]of Object.entries(r))e.set(`block:${s}`,c);continue}if(o==="inlineBlocks"){for(let[s,c]of Object.entries(r))e.set(`inlineBlock:${s}`,c);continue}e.set(o,r)}}function Vr(n){L.delete(n)}function Ot(n,t,e){let o=L.get(n);if(t==="block"&&e?.__fields?.blockType){let r=e.__fields.blockType;return o?.get(`block:${r}`)}if(t==="inlineBlock"&&e?.__fields?.blockType){let r=e.__fields.blockType;return o?.get(`inlineBlock:${r}`)}return o?.get(t)}function rn({node:n,nodeType:t}){if(!("getType"in n)||n.getType()!==t)return;let e=n;if(e.prototype._originalDecorate||(e.prototype._originalDecorate=e.prototype.decorate),e.prototype._originalCreateDOM||(e.prototype._originalCreateDOM=e.prototype.createDOM),e.prototype.decorate&&!e.prototype._decorateOverridden){e.prototype._decorateOverridden=!0;let o=!!e.prototype.createDOM;e.prototype.decorate=function(r,s){let c=Ot(r,t,this);if(c){if(c.Component)return c.Component({config:s,editor:r,isEditor:!0,isJSXConverter:!1,node:this});if(c.createDOM&&c.html){let l=typeof c.html=="function"?c.html({config:s,editor:r,isEditor:!0,isJSXConverter:!1,node:this}):c.html;return q.createElement("span",{dangerouslySetInnerHTML:{__html:l}})}if(c.html&&o&&!c.createDOM)return q.createElement(q.Fragment);if(t==="block"){let l=c;if(l.Block||l.Label)return e.prototype._originalDecorate.call(this,r,s,l.Block,l.Label)}else if(t==="inlineBlock"){let l=c;if(l.Block||l.Label)return e.prototype._originalDecorate.call(this,r,s,l.Block,l.Label)}}return e.prototype._originalDecorate.call(this,r,s)}}e.prototype.createDOM&&!e.prototype._createDOMOverridden&&(e.prototype._createDOMOverridden=!0,e.prototype.createDOM=function(o,r){let s=Ot(r,t,this);if(s){if(s.createDOM)return s.createDOM({config:o,editor:r,node:this});if(s.html){let c=typeof s.html=="function"?s.html({config:o,editor:r,isEditor:!0,isJSXConverter:!1,node:this}):s.html,i=document.createElement("div");return i.innerHTML=c,i.firstElementChild||i}}return e.prototype._originalCreateDOM.call(this,o,r)})}function Xr({editorConfig:n,nodeViews:t}){let e=on({nodes:n.features.nodes});if(t){let o=new Set;for(let[r,s]of Object.entries(t))!s||typeof s!="object"||(r==="blocks"&&Object.keys(s).length>0?o.add("block"):r==="inlineBlocks"&&Object.keys(s).length>0?o.add("inlineBlock"):o.add(r));for(let r of e)if("getType"in r){let s=r.getType();o.has(s)&&rn({node:r,nodeType:s})}}return e}function on({nodes:n}){return n.map(t=>"node"in t?t.node:t)}import{$getRoot as $n,$getState as Bn,$isDecoratorNode as re,$isElementNode as H,$isLineBreakNode as vn,$isTextNode as K}from"lexical";import{$createListItemNode as sn,$createListNode as cn,$isListItemNode as ln,$isListNode as O,ListItemNode as Z,ListNode as tt}from"@lexical/list";import{$createHeadingNode as an,$createQuoteNode as fn,$isHeadingNode as un,$isQuoteNode as Nt,HeadingNode as dn,QuoteNode as mn}from"@lexical/rich-text";import{$createLineBreakNode as pn,$isLineBreakNode as gn,$isTextNode as hn,$setState as xn,createState as En}from"lexical";var Ft=/^[\t ]*$/,At=/^(\s*)(\d+)\.\s/,Dt=/^(\s*)[-*+]\s/,$t=/^(\s*)(?:-\s)?\s?(\[(\s|x)?\])\s/i,Q=/^(#{1,6})\s/,Bt=/^>\s/,_n=/^[ \t]*(\\`\\`\\`|```)(\w+)?/,It=/[ \t]*(\\`\\`\\`|```)$/,Tn=/^[ \t]*```[^`]+(?:(?:`{1,2}|`{4,})[^`]+)*```(?:[^`]|$)/,wn=/^\|(.+)\|\s?$/,Cn=/^(\| ?:?-*:? ?)+\|\s?$/,Mt=/^[ \t]*<[a-z_][\w-]*(?:\s[^<>]*)?\/?>/i,Lt=/^[ \t]*<\/[a-z_][\w-]*\s*>/i,et=En("mdHardLineBreak",{parse:n=>typeof n=="string"&&/^(\\| {2,})$/.test(n)?n:""});function J(n){if(n.endsWith("\\"))return[n.slice(0,-1),"\\"];let t=n.match(/^(.*?\S)( {2,})$/);return t?[t[1],t[2]]:null}function Sn(n,t){for(let e=t-1;e>=0;e--){if(gn(n[e]))return!1;if(/\S/.test(n[e].getTextContent()))return!0}return!1}function Rn(n){let t=n.getChildren(),e=t.length-1,o=t[e];if(!hn(o))return null;let r=o.getTextContent(),s=J(r);if(s!==null){let[c,i]=s;return o.setTextContent(c),i}return/^ {2,}$/.test(r)&&Sn(t,e)?(o.setTextContent(""),r):null}function nt(n){let t=pn(),e=Rn(n);return e!==null&&xn(t,et,e),t}var kn=n=>(t,e,o)=>{let r=n(o);r.append(...e),t.replace(r),r.select(0,0)},vt=4;function yn(n){let t=n.match(/\t/g),e=n.match(/ /g),o=0;return t&&(o+=t.length),e&&(o+=Math.floor(e.length/vt)),o}var rt=n=>(t,e,o)=>{let r=t.getPreviousSibling(),s=t.getNextSibling(),c=sn(n==="check"?o[3]==="x":void 0);if(O(s)&&s.getListType()===n){let l=s.getFirstChild();l!==null?l.insertBefore(c):s.append(c),t.remove()}else if(O(r)&&r.getListType()===n)r.append(c),t.remove();else{let l=cn(n,n==="number"?Number(o[2]):void 0);l.append(c),t.replace(l)}c.append(...e),c.select(0,0);let i=yn(o[1]);i&&c.setIndent(i)},B=(n,t,e)=>{let o=[],r=n.getChildren(),s=0;for(let c of r)if(ln(c)){if(c.getChildrenSize()===1){let f=c.getFirstChild();if(O(f)){o.push(B(f,t,e+1));continue}}let i=" ".repeat(e*vt),l=n.getListType(),a=l==="number"?`${n.getStart()+s}. `:l==="check"?`- [${c.getChecked()?"x":" "}] `:"- ";o.push(i+a+t(c)),s++}return o.join(`
2
+ `)},Pt={type:"element",dependencies:[dn],export:(n,t)=>{if(!un(n))return null;let e=Number(n.getTag().slice(1));return"#".repeat(e)+" "+t(n)},regExp:Q,replace:kn(n=>{let t="h"+n[1].length;return an(t)})},Ht={type:"element",dependencies:[mn],export:(n,t)=>{if(!Nt(n))return null;let e=t(n).split(`
3
+ `),o=[];for(let r of e)o.push("> "+r);return o.join(`
4
+ `)},regExp:Bt,replace:(n,t,e,o)=>{if(o){let s=n.getPreviousSibling();if(Nt(s)){s.splice(s.getChildrenSize(),0,[nt(s),...t]),s.select(0,0),n.remove();return}}let r=fn();r.append(...t),n.replace(r),r.select(0,0)}},Kt={type:"element",dependencies:[tt,Z],export:(n,t)=>O(n)?B(n,t,0):null,regExp:Dt,replace:rt("bullet")},bn={type:"element",dependencies:[tt,Z],export:(n,t)=>O(n)?B(n,t,0):null,regExp:$t,replace:rt("check")},Ut={type:"element",dependencies:[tt,Z],export:(n,t)=>O(n)?B(n,t,0):null,regExp:At,replace:rt("number")},Vt={type:"text-format",format:["code"],tag:"`"},Xt={type:"text-format",format:["highlight"],tag:"=="},Gt={type:"text-format",format:["bold","italic"],tag:"***"},zt={type:"text-format",format:["bold","italic"],intraword:!1,tag:"___"},Wt={type:"text-format",format:["bold"],tag:"**"},Yt={type:"text-format",format:["bold"],intraword:!1,tag:"__"},jt={type:"text-format",format:["strikethrough"],tag:"~~"},qt={type:"text-format",format:["italic"],tag:"*"},Qt={type:"text-format",format:["italic"],intraword:!1,tag:"_"};function Jt(n,t){let e=n.split(`
5
+ `),o=!1,r=[],s=0;for(let c=0;c<e.length;c++){let i=e[c],l=r[r.length-1],a=c<e.length-1?J(i):null,f=l!==void 0&&J(l)!==null;if(Tn.test(i)){r.push(i);continue}if(It.test(i)){s===0&&(o=!0),s===1&&(o=!1),s>0&&s--,r.push(i);continue}if(_n.test(i)){o=!0,s++,r.push(i);continue}if(o){r.push(i);continue}Ft.test(i)||Ft.test(l)||!l||Q.test(l)||Q.test(i)||Bt.test(i)||At.test(i)||Dt.test(i)||$t.test(i)||wn.test(i)||Cn.test(i)||f||!t||Mt.test(i)||Lt.test(i)||Mt.test(l)||Lt.test(l)||It.test(l)?r.push(i):r[r.length-1]=l+" "+(a===null?i.trim():i.trimStart())}return r.join(`
6
+ `)}import{$isListItemNode as On,$isListNode as Zt}from"@lexical/list";import{$isHeadingNode as Nn,$isQuoteNode as Fn}from"@lexical/rich-text";import{$isParagraphNode as In,$isTextNode as Mn}from"lexical";var C={markdownFormatKind:null,regEx:/(?:)/,regExForAutoFormatting:/(?:)/,requiresParagraphStart:!1},R={...C,requiresParagraphStart:!0},Zr={...R,export:N(1),markdownFormatKind:"paragraphH1",regEx:/^# /,regExForAutoFormatting:/^# /},to={...R,export:N(2),markdownFormatKind:"paragraphH2",regEx:/^## /,regExForAutoFormatting:/^## /},eo={...R,export:N(3),markdownFormatKind:"paragraphH3",regEx:/^### /,regExForAutoFormatting:/^### /},no={...R,export:N(4),markdownFormatKind:"paragraphH4",regEx:/^#### /,regExForAutoFormatting:/^#### /},ro={...R,export:N(5),markdownFormatKind:"paragraphH5",regEx:/^##### /,regExForAutoFormatting:/^##### /},oo={...R,export:N(6),markdownFormatKind:"paragraphH6",regEx:/^###### /,regExForAutoFormatting:/^###### /},io={...R,export:An,markdownFormatKind:"paragraphBlockQuote",regEx:/^> /,regExForAutoFormatting:/^> /},so={...R,export:ot,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})- /,regExForAutoFormatting:/^(\s{0,10})- /},co={...R,export:ot,markdownFormatKind:"paragraphUnorderedList",regEx:/^(\s{0,10})\* /,regExForAutoFormatting:/^(\s{0,10})\* /},lo={...R,export:ot,markdownFormatKind:"paragraphOrderedList",regEx:/^(\s{0,10})(\d+)\.\s/,regExForAutoFormatting:/^(\s{0,10})(\d+)\.\s/},ao={...R,markdownFormatKind:"horizontalRule",regEx:/^\*\*\*$/,regExForAutoFormatting:/^\*\*\* /},fo={...R,markdownFormatKind:"horizontalRule",regEx:/^---$/,regExForAutoFormatting:/^--- /},uo={...C,exportFormat:"code",exportTag:"`",markdownFormatKind:"code",regEx:/(`)(\s*)([^`]*)(\s*)(`)()/,regExForAutoFormatting:/(`)(\s*\b)([^`]*)(\b\s*)(`)(\s)$/},mo={...C,exportFormat:"bold",exportTag:"**",markdownFormatKind:"bold",regEx:/(\*\*)(\s*)([^*]*)(\s*)(\*\*)()/,regExForAutoFormatting:/(\*\*)(\s*\b)([^*]*)(\b\s*)(\*\*)(\s)$/},po={...C,exportFormat:"italic",exportTag:"*",markdownFormatKind:"italic",regEx:/(\*)(\s*)([^*]*)(\s*)(\*)()/,regExForAutoFormatting:/(\*)(\s*\b)([^*]*)(\b\s*)(\*)(\s)$/},go={...C,exportFormat:"bold",exportTag:"_",markdownFormatKind:"bold",regEx:/(__)(\s*)([^_]*)(\s*)(__)()/,regExForAutoFormatting:/(__)(\s*)([^_]*)(\s*)(__)(\s)$/},ho={...C,exportFormat:"italic",exportTag:"_",markdownFormatKind:"italic",regEx:/(_)()([^_]*)()(_)()/,regExForAutoFormatting:/(_)()([^_]*)()(_)(\s)$/},xo={...C,exportFormat:"underline",exportTag:"<u>",exportTagClose:"</u>",markdownFormatKind:"underline",regEx:/(<u>)(\s*)([^<]*)(\s*)(<\/u>)()/,regExForAutoFormatting:/(<u>)(\s*\b)([^<]*)(\b\s*)(<\/u>)(\s)$/},Eo={...C,exportFormat:"strikethrough",exportTag:"~~",markdownFormatKind:"strikethrough",regEx:/(~~)(\s*)([^~]*)(\s*)(~~)()/,regExForAutoFormatting:/(~~)(\s*\b)([^~]*)(\b\s*)(~~)(\s)$/},_o={...C,markdownFormatKind:"strikethrough_italic_bold",regEx:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)()/,regExForAutoFormatting:/(~~_\*\*)(\s*\b)([^*_~]+)(\b\s*)(\*\*_~~)(\s)$/},To={...C,markdownFormatKind:"italic_bold",regEx:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)/,regExForAutoFormatting:/(_\*\*)(\s*\b)([^*_]+)(\b\s*)(\*\*_)(\s)$/},wo={...C,markdownFormatKind:"strikethrough_italic",regEx:/(~~_)(\s*)([^_~]+)(\s*)(_~~)/,regExForAutoFormatting:/(~~_)(\s*)([^_~]+)(\s*)(_~~)(\s)$/},Co={...C,markdownFormatKind:"strikethrough_bold",regEx:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)/,regExForAutoFormatting:/(~~\*\*)(\s*\b)([^*~]+)(\b\s*)(\*\*~~)(\s)$/},So={...C,markdownFormatKind:"link",regEx:/(\[)([^\]]*)(\]\()([^)]*)(\)*)()/,regExForAutoFormatting:/(\[)([^\]]*)(\]\()([^)]*)(\)*)(\s)$/};function N(n){return(t,e)=>Nn(t)&&t.getTag()==="h"+n?"#".repeat(n)+" "+e(t):null}function ot(n,t){return Zt(n)?te(n,t,0):null}var Ln=4;function te(n,t,e){let o=[],r=n.getChildren(),s=0;for(let c of r)if(On(c)){if(c.getChildrenSize()===1){let a=c.getFirstChild();if(Zt(a)){o.push(te(a,t,e+1));continue}}let i=" ".repeat(e*Ln),l=n.getListType()==="bullet"?"- ":`${n.getStart()+s}. `;o.push(i+l+t(c)),s++}return o.join(`
7
+ `)}function An(n,t){return Fn(n)?"> "+t(n):null}function v(n,t){let e={};for(let o of n){let r=t(o);r&&(e[r]?e[r].push(o):e[r]=[o])}return e}function F(n){let t=v(n,e=>e.type);return{element:t.element||[],multilineElement:t["multiline-element"]||[],textFormat:t["text-format"]||[],textMatch:t["text-match"]||[]}}var I=/[!-/:-@[-`{-~\s]/,Dn=/^\s{0,3}$/;function A(n){if(!In(n))return!1;let t=n.getFirstChild();return t==null||n.getChildrenSize()===1&&Mn(t)&&Dn.test(t.getTextContent())}function oe(n,t=!1){let e=F(n),o=[...e.multilineElement,...e.element],r=!t,s=e.textFormat.filter(c=>c.format.length===1).sort((c,i)=>c.format.includes("code")&&!i.format.includes("code")?1:!c.format.includes("code")&&i.format.includes("code")?-1:0);return c=>{let i=[],l=(c||$n()).getChildren();return l.forEach((a,f)=>{let p=Pn(a,o,s,e.textMatch);p!=null&&i.push(r&&f>0&&!A(a)&&!A(l[f-1])?`
8
+ `.concat(p):p)}),i.join(`
9
+ `)}}function Pn(n,t,e,o){for(let r of t){if(!r.export)continue;let s=r.export(n,c=>U(c,e,o));if(s!=null)return s}return H(n)?U(n,e,o):re(n)?n.getTextContent():null}function U(n,t,e,o,r){let s=[],c=n.getChildren();o||(o=[]),r||(r=[]);t:for(let i of c){for(let l of e){if(!l.export)continue;let a=l.export(i,f=>U(f,t,e,o,[...r,...o]),(f,p)=>ee(f,p,t,o,r));if(a!=null){s.push(a);continue t}}vn(i)?s.push(Hn(i)):K(i)?s.push(ee(i,i.getTextContent(),t,o,r)):H(i)?s.push(U(i,t,e,o,r)):re(i)&&s.push(i.getTextContent())}return s.join("")}function Hn(n){return Bn(n,et)+`
10
+ `}function ee(n,t,e,o,r){let s=t.trim(),c=s;n.hasFormat("code")||(c=c.replace(/([*_`~\\])/g,"\\$1"));let i="",l="",a="",f=ne(n,!0),p=ne(n,!1),m=new Set;for(let g of e){let u=g.format[0],d=g.tag;P(n,u)&&!m.has(u)&&(m.add(u),(!P(f,u)||!o.find(h=>h.tag===d))&&(o.push({format:u,tag:d}),i+=d))}for(let g=0;g<o.length;g++){let u=o[g],d=P(n,u.format),h=P(p,u.format);if(d&&h)continue;let x=[...o];for(;x.length>g;){let E=x.pop();r&&E&&r.find(_=>_.tag===E.tag)||(E&&typeof E.tag=="string"&&(d?h||(a+=E.tag):l+=E.tag),o.pop())}break}return c=i+c+a,l+t.replace(s,()=>c)}function ne(n,t){let e=t?n.getPreviousSibling():n.getNextSibling();if(!e){let o=n.getParentOrThrow();o.isInline()&&(e=t?o.getPreviousSibling():o.getNextSibling())}for(;e;){if(H(e)){if(!e.isInline())break;let o=t?e.getLastDescendant():e.getFirstDescendant();if(K(o))return o;e=t?e.getPreviousSibling():e.getNextSibling()}if(K(e))return e;if(!H(e))return null}return null}function P(n,t){return K(n)&&n.hasFormat(t)}import{$isListItemNode as Un,$isListNode as ae}from"@lexical/list";import{$isQuoteNode as Vn}from"@lexical/rich-text";import{$findMatchingParent as Xn}from"@lexical/utils";import{$createParagraphNode as Gn,$createTextNode as zn,$getRoot as Wn,$getSelection as Yn,$isParagraphNode as jn}from"lexical";import{$isTextNode as M}from"lexical";function ie(n,t){let e=n.getTextContent(),o=Kn(e,t);if(!o)return null;let r=o.index||0,s=r+o[0].length,c=t.transformersByTag[o[1]];return{endIndex:s,match:o,startIndex:r,transformer:c}}function Kn(n,t){let e=n.match(t.openTagsRegExp);if(e==null)return null;for(let o of e){let r=o.replace(/^\s/,""),s=t.fullMatchRegExpByTag[r];if(s==null)continue;let c=n.match(s),i=t.transformersByTag[r];if(c!=null&&i!=null){if(i.intraword!==!1)return c;let{index:l=0}=c,a=n[l-1],f=n[l+c[0].length];if((!a||I.test(a))&&(!f||I.test(f)))return c}}return null}function se(n,t,e,o,r){let s=n.getTextContent(),c,i,l;if(r[0]===s?l=n:t===0?[l,c]=n.splitText(e):[i,l,c]=n.splitText(t,e),l.setTextContent(r[2]),o)for(let a of o.format)l.hasFormat(a)||l.toggleFormat(a);return{nodeAfter:c,nodeBefore:i,transformedNode:l}}function ce(n,t){let e=n,o,r,s,c;for(let i of t){if(!i.replace||!i.importRegExp)continue;let l=e.getTextContent().match(i.importRegExp);if(!l)continue;let a=l.index||0,f=i.getEndIndex?i.getEndIndex(e,l):a+l[0].length;f!==!1&&(o===void 0||r===void 0||a<o&&f>r)&&(o=a,r=f,s=i,c=l)}return o===void 0||r===void 0||s===void 0||c===void 0?null:{endIndex:r,match:c,startIndex:o,transformer:s}}function le(n,t,e,o,r){let s,c,i;if(t===0?[i,s]=n.splitText(e):[c,i,s]=n.splitText(t,e),!o.replace)return null;let l=i?o.replace(i,r):void 0;return{nodeAfter:s,nodeBefore:c,transformedNode:l||void 0}}function k(n,t,e){let o=ie(n,t),r=ce(n,e);if(o&&r&&(o.startIndex<=r.startIndex&&o.endIndex>=r.endIndex?r=null:o=null),o){let i=se(n,o.startIndex,o.endIndex,o.transformer,o.match);i.nodeAfter&&M(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&k(i.nodeAfter,t,e),i.nodeBefore&&M(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&k(i.nodeBefore,t,e),i.transformedNode&&M(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&k(i.transformedNode,t,e)}else if(r){let i=le(n,r.startIndex,r.endIndex,r.transformer,r.match);if(!i)return;i.nodeAfter&&M(i.nodeAfter)&&!i.nodeAfter.hasFormat("code")&&k(i.nodeAfter,t,e),i.nodeBefore&&M(i.nodeBefore)&&!i.nodeBefore.hasFormat("code")&&k(i.nodeBefore,t,e),i.transformedNode&&M(i.transformedNode)&&!i.transformedNode.hasFormat("code")&&k(i.transformedNode,t,e)}let c=n.getTextContent().replace(/\\([*_`~])/g,"$1");n.setTextContent(c)}function fe(n,t=!1){let e=F(n),o=Jn(e.textFormat);return(r,s)=>{let c=r.split(`
11
+ `),i=c.length,l=s||Wn();l.clear();for(let f=0;f<i;f++){let p=c[f],[m,g]=qn(c,f,e.multilineElement,l);if(m){f=g;continue}Qn(p,l,e.element,o,e.textMatch)}let a=l.getChildren();for(let f of a)!t&&A(f)&&l.getChildrenSize()>1&&f.remove();Yn()!==null&&l.selectStart()}}function qn(n,t,e,o){for(let r of e){let{handleImportAfterStartMatch:s,regExpEnd:c,regExpStart:i,replace:l}=r,a=n[t]?.match(i);if(!a)continue;if(s){let u=s({lines:n,rootNode:o,startLineIndex:t,startMatch:a,transformer:r});if(u===null)continue;if(u)return u}let f=typeof c=="object"&&"regExp"in c?c.regExp:c,p=c&&typeof c=="object"&&"optional"in c?c.optional:!c,m=t,g=n.length;for(;m<g;){let u=f?n[m]?.match(f):null;if(!u&&(!p||p&&m<g-1)){m++;continue}if(u&&t===m&&u.index===a.index){m++;continue}let d=[];if(u&&t===m)d.push(n[t].slice(a[0].length,-u[0].length));else for(let h=t;h<=m;h++){let x=n[h];if(h===t){let E=x.slice(a[0].length);d.push(E)}else if(h===m&&u){let E=x.slice(0,-u[0].length);d.push(E)}else d.push(x)}if(l(o,null,a,u,d,!0)!==!1)return[!0,m];break}}return[!1,t]}function Qn(n,t,e,o,r){let s=zn(n),c=Gn();c.append(s),t.append(c);for(let{regExp:i,replace:l}of e){let a=n.match(i);if(a&&(s.setTextContent(n.slice(a[0].length)),l(c,[s],a,!0)!==!1))break}if(k(s,o,r),c.isAttached()&&n.length>0){let i=c.getPreviousSibling();if(jn(i)||Vn(i)||ae(i)){let l=i;if(ae(i)){let a=i.getLastDescendant();a==null?l=null:l=Xn(a,Un)}l!=null&&l.getTextContentSize()>0&&(l.splice(l.getChildrenSize(),0,[nt(l),...c.getChildren()]),c.remove())}}}function Jn(n){let t={},e={},o=[],r="(?<![\\\\])";for(let s of n){let{tag:c}=s;t[c]=s;let i=c.replace(/([*^+])/g,"\\$1");o.push(i),c.length===1?e[c]=new RegExp(`(?<![\\\\${i}])(${i})((\\\\${i})?.*?[^${i}\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?![\\\\${i}])`):e[c]=new RegExp(`(?<!\\\\)(${i})((\\\\${i})?.*?[^\\s](\\\\${i})?)((?<!\\\\)|(?<=\\\\\\\\))(${i})(?!\\\\)`)}return{fullMatchRegExpByTag:e,openTagsRegExp:new RegExp(`${r}(${o.join("|")})`,"g"),transformersByTag:t}}import{$createRangeSelection as Zn,$getSelection as it,$isLineBreakNode as tr,$isRangeSelection as st,$isRootOrShadowRoot as de,$isTextNode as me,$setSelection as er}from"lexical";function nr(n,t,e,o){let r=n.getParent();if(!de(r)||n.getFirstChild()!==t)return!1;let s=t.getTextContent();if(s[e-1]!==" ")return!1;for(let{regExp:c,replace:i}of o){let l=s.match(c);if(l&&l[0].length===(l[0].endsWith(" ")?e:e-1)){let a=t.getNextSiblings(),[f,p]=t.splitText(e);f?.remove();let m=p?[p,...a]:a;if(i(n,m,l,!1)!==!1)return!0}}return!1}function rr(n,t,e,o){let r=n.getParent();if(!de(r)||n.getFirstChild()!==t)return!1;let s=t.getTextContent();if(s[e-1]!==" ")return!1;for(let{regExpEnd:c,regExpStart:i,replace:l}of o){if(c&&!("optional"in c)||c&&"optional"in c&&!c.optional)continue;let a=s.match(i);if(a&&a[0].length===(a[0].endsWith(" ")?e:e-1)){let f=t.getNextSiblings(),[p,m]=t.splitText(e);p?.remove();let g=m?[m,...f]:f;if(l(n,g,a,null,null,!1)!==!1)return!0}}return!1}function or(n,t,e){let o=n.getTextContent(),r=o[t-1],s=e[r];if(s==null)return!1;t<o.length&&(o=o.slice(0,t));for(let c of s){if(!c.replace||!c.regExp)continue;let i=o.match(c.regExp);if(i===null)continue;let l=i.index||0,a=l+i[0].length,f;return l===0?[f]=n.splitText(a):[,f]=n.splitText(l,a),f&&(f.selectNext(0,0),c.replace(f,i)),!0}return!1}function ir(n,t,e){let o=n.getTextContent(),r=t-1,s=o[r],c=e[s];if(!c)return!1;for(let i of c){let{tag:l}=i,a=l.length,f=r-a+1;if(a>1&&!pe(o,f,l,0,a)||o[f-1]===" ")continue;let p=o[r+1];if(i.intraword===!1&&p&&!I.test(p))continue;let m=n,g=m,u=ue(o,f,l),d=g;for(;u<0&&(d=d.getPreviousSibling())&&!tr(d);)if(me(d)){let S=d.getTextContent();g=d,u=ue(S,S.length,l)}if(u<0||g===m&&u+a===f)continue;let h=g.getTextContent();if(u>0&&h[u-1]===s)continue;let x=h[u-1];if(i.intraword===!1&&x&&!I.test(x))continue;let E=m.getTextContent(),_=E.slice(0,f)+E.slice(r+1);m.setTextContent(_);let T=g===m?_:h;g.setTextContent(T.slice(0,u)+T.slice(u+a));let y=it(),w=Zn();er(w);let D=r-a*(g===m?2:1)+1;w.anchor.set(g.__key,u,"text"),w.focus.set(m.__key,D,"text");for(let S of i.format)w.hasFormat(S)||w.formatText(S);w.anchor.set(w.focus.key,w.focus.offset,w.focus.type);for(let S of i.format)w.hasFormat(S)&&w.toggleFormat(S);return st(y)&&(w.format=y.format),!0}return!1}function ue(n,t,e){let o=e.length;for(let r=t;r>=o;r--){let s=r-o;if(pe(n,s,e,0,o)&&n[s+o]!==" ")return s}return-1}function pe(n,t,e,o,r){for(let s=0;s<r;s++)if(n[t+s]!==e[o+s])return!1;return!0}function Wo(n,t=V){let e=F(t),o=v(e.textFormat,({tag:c})=>c[c.length-1]),r=v(e.textMatch,({trigger:c})=>c);for(let c of t){let i=c.type;if(i==="element"||i==="text-match"||i==="multiline-element"){let l=c.dependencies;for(let a of l)if(!n.hasNode(a))throw new Error("MarkdownShortcuts: missing dependency %s for transformer. Ensure node dependency is included in editor initial config."+a.getType())}}let s=(c,i,l)=>{nr(c,i,l,e.element)||rr(c,i,l,e.multilineElement)||or(i,l,r)||ir(i,l,o)};return n.registerUpdateListener(({dirtyLeaves:c,editorState:i,prevEditorState:l,tags:a})=>{if(a.has("collaboration")||a.has("historic")||n.isComposing())return;let f=i.read(it),p=l.read(it);if(!st(p)||!st(f)||!f.isCollapsed()||f.is(p))return;let m=f.anchor.key,g=f.anchor.offset,u=i._nodeMap.get(m);!me(u)||!c.has(m)||g!==1&&g>p.anchor.offset+1||n.update(()=>{if(u.hasFormat("code"))return;let d=u.getParent();d!==null&&s(d,u,f.anchor.offset)})})}var sr=[Pt,Ht,Kt,Ut],cr=[],lr=[Vt,Gt,zt,Wt,Yt,Xt,qt,Qt,jt],ar=[],V=[...sr,...cr,...lr,...ar];function Jo(n,t=V,e,o=!1,r=!0){let s=o?n:Jt(n,r);return fe(t,o)(s,e)}function Zo(n=V,t,e=!1){return oe(n,e)(t)}export{Wo as a,Jo as b,Zo as c,at as d,pr as e,Tr as f,be as g,G as h,ut as i,$r as j,nn as k,Br as l,bt as m,Ur as n,Vr as o,Xr as p};
12
+ //# sourceMappingURL=chunk-QAW5QKEM.js.map