@payloadcms/richtext-lexical 3.60.0 → 3.61.0-canary.1

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.
@@ -1,2 +1,2 @@
1
- "use client";import{a as we,e as ke,f as _,h as De,i as Te,j as ve,k as Me,l as Le}from"./chunk-TLQLXR6Q.js";import{a as Re,b as R}from"./chunk-BZZVLW4U.js";import{jsx as F,jsxs as ge}from"react/jsx-runtime";import{FieldDescription as Dn,FieldError as Tn,FieldLabel as vn,RenderCustomComponent as bt,useEditDepth as Mn,useEffectEvent as Ln,useField as An}from"@payloadcms/ui";import{mergeFieldStyles as Bn}from"@payloadcms/ui/shared";import{dequal as In}from"dequal/lite";import Nt,{useCallback as Pt,useEffect as St,useMemo as _n,useState as Rt}from"react";import{ErrorBoundary as On}from"react-error-boundary";import"./bundled.css";import{jsx as O}from"react/jsx-runtime";import{LexicalComposer as Rn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as wn}from"@payloadcms/ui";import*as xt from"react";import{useMemo as kn}from"react";import{c as cn}from"react/compiler-runtime";import{jsx as E,jsxs as te}from"react/jsx-runtime";import{useLexicalComposerContext as dn}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as un}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as mn}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as fn}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as pn}from"@lexical/react/LexicalRichTextPlugin.js";import{useLexicalEditable as gn}from"@lexical/react/useLexicalEditable";import{BLUR_COMMAND as hn,COMMAND_PRIORITY_LOW as ht,FOCUS_COMMAND as yn}from"lexical";import*as q from"react";import{useEffect as xn,useState as En}from"react";import{jsx as Ae}from"react/jsx-runtime";import"react";var $=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Ae(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Ae(o.Component,{clientProps:e});import{c as Dt}from"react/compiler-runtime";import{copyToClipboard as Tt}from"@lexical/clipboard";import{useLexicalComposerContext as vt}from"@lexical/react/LexicalComposerContext.js";import{objectKlassEquals as Mt}from"@lexical/utils";import Be from"bson-objectid";import{COMMAND_PRIORITY_LOW as Lt,COPY_COMMAND as At}from"lexical";import{useEffect as Bt}from"react";function Ie(){let t=Dt(3),[e]=vt(),o,r;return t[0]!==e?(o=()=>e.registerCommand(At,n=>(Tt(e,Mt(n,ClipboardEvent)?n:null).then(()=>{if(!(n instanceof ClipboardEvent)||!n.clipboardData)throw new Error("No clipboard event");let c=n.clipboardData.getData("application/x-lexical-editor");if(!c)return!0;let i=JSON.parse(c),l=u=>{if("fields"in u&&typeof u.fields=="object"&&u.fields!==null&&"id"in u.fields?u.fields.id=new Be.default().toHexString():"id"in u&&(u.id=new Be.default().toHexString()),u.children)for(let y of u.children)l(y)};for(let u of i.nodes)l(u);let d=JSON.stringify(i);n.clipboardData.setData("application/x-lexical-editor",d)}).catch(c=>{throw n instanceof ClipboardEvent&&n.clipboardData?.setData("application/x-lexical-editor",""),c}),!0),Lt),r=[e],t[0]=e,t[1]=o,t[2]=r):(o=t[1],r=t[2]),Bt(o,r),null}import{c as It}from"react/compiler-runtime";import{useLexicalComposerContext as _t}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as ne,mergeRegister as Ot}from"@lexical/utils";import{$createNodeSelection as Ft,$getEditor as X,$getNearestNodeFromDOMNode as $t,$getSelection as re,$isDecoratorNode as K,$isElementNode as xe,$isLineBreakNode as Kt,$isNodeSelection as ie,$isRangeSelection as _e,$isRootOrShadowRoot as Ht,$isTextNode as jt,$setSelection as Oe,CLICK_COMMAND as zt,COMMAND_PRIORITY_LOW as W,KEY_ARROW_DOWN_COMMAND as Wt,KEY_ARROW_UP_COMMAND as Yt,KEY_BACKSPACE_COMMAND as Vt,KEY_DELETE_COMMAND as Gt,SELECTION_CHANGE_COMMAND as Ut}from"lexical";import{useEffect as qt}from"react";function Fe(){let t=It(3),[e]=_t(),o=oo,r,n;return t[0]!==e?(r=()=>Ot(e.registerCommand(zt,to,W),e.registerCommand(Gt,o,W),e.registerCommand(Vt,o,W),e.registerCommand(Ut,eo,W),e.registerCommand(Yt,Xt,W),e.registerCommand(Wt,Jt,W)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),qt(r,n),null}function Jt(t){let e=re();if(ie(e)){t.preventDefault();let i=e.getNodes()[0]?.getNextSibling();if(K(i)){let u=X().getElementByKey(i.getKey());return u&&Z({element:u,node:i}),!0}if(!xe(i))return!0;let l=i.getFirstDescendant()??i;return l&&(ne(l,se)?.selectEnd(),t.preventDefault()),!0}if(!_e(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=ne(r,Qt),c=n?.getNextSibling();if(!n||c!==$e(n))return!1;if(K(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Qt(t){return $e(t)!==null}function Xt(t){let e=re();if(ie(e)){let i=e.getNodes()[0]?.getPreviousSibling();if(K(i)){let u=X().getElementByKey(i.getKey());return u?(Z({element:u,node:i}),t.preventDefault(),!0):!1}if(!xe(i))return!1;let l=i.getLastDescendant()??i;return l?(ne(l,se)?.selectStart(),t.preventDefault(),!0):!1}if(!_e(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=ne(r,Zt),c=n?.getPreviousSibling();if(!n||c!==Ke(n))return!1;if(K(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Zt(t){return Ke(t)!==null}function eo(){let t=io();return document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),t?(t.element?.classList.add("decorator-selected"),!0):!1}function to(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=ro(t);if(!e)return!0;let{target:o}=t;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Oe(null):Z(e),!0}function oo(t){let e=re();return ie(e)?(t.preventDefault(),e.getNodes().forEach(no),!0):!1}function no(t){t.remove()}function ro(t){if(!(t.target instanceof HTMLElement))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!(e instanceof HTMLElement))return;let o=$t(e);return K(o)?{element:e,node:o}:void 0}function io(){let t=re();if(!ie(t))return;let e=t.getNodes();if(e.length!==1)return;let o=e[0];return K(o)?{decorator:o,element:X().getElementByKey(o.getKey())}:void 0}function Z({element:t,node:e}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=Ft();o.add(e.getKey()),Oe(o),t.scrollIntoView({behavior:"smooth",block:"nearest"}),t.classList.add("decorator-selected")}function se(t){if(K(t)&&!t.isInline())return!0;if(!xe(t)||Ht(t))return!1;let e=t.getFirstChild(),o=e===null||Kt(e)||jt(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&o}function $e(t){let e=t.getNextSibling();for(;e!==null;){if(se(e))return e;e=e.getNextSibling()}return null}function Ke(t){let e=t.getPreviousSibling();for(;e!==null;){if(se(e))return e;e=e.getPreviousSibling()}return null}import{jsx as Ee}from"react/jsx-runtime";import{useLexicalComposerContext as mo}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as fo,isHTMLElement as po}from"lexical";import*as We from"react";import{useCallback as go,useEffect as ze,useRef as ho,useState as yo}from"react";import{createPortal as xo}from"react-dom";var Y=(t,e,o,r,n=50,c=25)=>{let i=0;if(t&&!t.contains(r)){let{bottom:l,left:d,right:u,top:y}=t.getBoundingClientRect(),s=y+window.scrollY,a=l+window.scrollY;if(o<s-c||o>a+c||e<d-n||e>u+n)return-1;(e<d||e>u)&&(i=e<d?e-d:e-u)}return i};import{$getNodeByKey as ae}from"lexical";function V(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function le(t){let e=(d,u)=>d?parseFloat(window.getComputedStyle(d)[u]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),i=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:i}}import{$getRoot as so}from"lexical";function H(t){return t.getEditorState().read(()=>so().getChildrenKeys())}var lo=1,ao=-1,He=0,A={props:null,result:null};function co(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function G(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:i,y:l},startIndex:d=0,useEdgeAsDefault:u=!1}=t;if(o>0&&A.props&&A.result&&A.props.fuzzy===t.fuzzy&&A.props.horizontalOffset===t.horizontalOffset&&A.props.useEdgeAsDefault===t.useEdgeAsDefault&&co(A.props.point,t.point,o))return A.result;let y=e.getBoundingClientRect(),s=H(r),a={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(u){let g=r.getElementByKey(s[0]),m=r.getElementByKey(s[s.length-1]);if(g&&m){let[p,f]=[V(g),V(m)];if(l<p.top?(a.blockElem=g,a.distance=p.top-l,a.blockNode=ae(s[0]),a.foundAtIndex=0):l>f.bottom&&(a.distance=l-f.bottom,a.blockNode=ae(s[s.length-1]),a.blockElem=m,a.foundAtIndex=s.length-1),a?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let h=d,x=He;for(;h>=0&&h<s.length;){let g=s[h],m=r.getElementByKey(g);if(m===null)break;let p=new _(i+c,l),f=Me.fromDOMRect(V(m)),{marginBottom:C,marginTop:k}=le(m),S=f.generateNewRect({bottom:f.bottom+C,left:y.left,right:y.right,top:f.top-k}),{distance:b,isOnBottomSide:w,isOnTopSide:N}=S.distanceFromPoint(p);if(b===0){a.blockElem=m,a.blockNode=ae(g),a.foundAtIndex=h,a.distance=b,a.blockNode&&a.blockNode.getType()==="paragraph"&&a.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(a.blockElem=null,a.blockNode=null),a.isFoundNodeEmptyParagraph=!0);break}else n&&b<a.distance&&(a.blockElem=m,a.blockNode=ae(g),a.distance=b,a.foundAtIndex=h);x===He&&(N?x=ao:w?x=lo:x=1/0),h+=x}}),A.props=t,A.result={blockElem:a.blockElem,blockNode:a.blockNode,foundAtIndex:a.foundAtIndex,isFoundNodeEmptyParagraph:a.isFoundNodeEmptyParagraph},{blockElem:a.blockElem,blockNode:a.blockNode,foundAtIndex:a.foundAtIndex,isFoundNodeEmptyParagraph:a.isFoundNodeEmptyParagraph}}function ce(t,e){return!!t.closest(`.${e}`)}var uo=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function je(t){if(!t||uo.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function de(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),i=e.getBoundingClientRect(),l=o.getBoundingClientRect(),d;if(["lexical-block","lexical-upload","lexical-relationship"].some(s=>t.firstElementChild?.classList.contains(s)))d=n.top+8-l.top;else{let s=je(t)?parseInt(c.lineHeight,10):0;d=n.top+(s-i.height)/2-l.top}let y=r;e.style.opacity="1",e.style.transform=`translate(${y}px, ${d}px)`}var Eo="add-block-menu",ue=1/0;function Co(t){return t===0?1/0:ue>=0&&ue<t?ue:Math.floor(t/2)}function bo(t,e,o){let r=e.parentElement,{editorConfig:n}=R(),c=n?.admin?.hideGutter?-24:12,i=ho(null),[l,d]=yo(null);ze(()=>{function y(s){let a=s.target;if(!po(a))return;let h=Y(r,s.pageX,s.pageY,a);if(h===-1){d(null);return}if(ce(a,Eo))return;let x=H(t),{blockElem:g,blockNode:m,foundAtIndex:p}=G({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-h,point:new _(s.x,s.y),returnEmptyParagraphs:!0,startIndex:Co(x.length),useEdgeAsDefault:!1});ue=p,g&&m&&(l?.node!==m||l?.elem!==g)&&d({elem:g,node:m})}return document?.addEventListener("mousemove",y),()=>{document?.removeEventListener("mousemove",y)}},[r,e,t,l]),ze(()=>{i.current&&l?.node&&de(l?.elem,i.current,e,c)},[e,l,c]);let u=go(y=>{let s=l;s?.node&&(t.update(()=>{let a=!0;if((s?.node.getType()!=="paragraph"||s.node.getTextContent()!=="")&&(a=!1),!a){let h=fo();s?.node.insertAfter(h),setTimeout(()=>{s={elem:t.getElementByKey(h.getKey()),node:h},d(s)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),s?.node&&"select"in s.node&&typeof s.node.select=="function"&&s.node.select()})},1),setTimeout(()=>{t.dispatchCommand(Te,{node:s?.node})},2),y.stopPropagation(),y.preventDefault())},[t,l]);return xo(Ee(We.Fragment,{children:Ee("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:y=>{u(y)},ref:i,type:"button",children:Ee("div",{className:o?"icon":""})})}),e)}function Ye(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=mo();return bo(r,o,r._editable)}import{jsx as me,jsxs as Po}from"react/jsx-runtime";import{useLexicalComposerContext as So}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as Ue}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as qe,$getNodeByKey as Ro,isHTMLElement as Ce}from"lexical";import*as et from"react";import{useEffect as be,useRef as fe,useState as Je}from"react";import{createPortal as wo}from"react-dom";var Ve=0,No=-24;var j=0;function Ge(t,e,o,r,n,c,i,l,d,u=!1){let{height:y,top:s}=r.getBoundingClientRect(),{top:a,width:h}=i.getBoundingClientRect(),{marginBottom:x,marginTop:g}=le(r),m=s,p=c>=s+y/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(p&&n?.elem&&n?.elem===r.nextElementSibling||!p&&n?.elem&&n?.elem===r.previousElementSibling)&&(j++,j<200&&(f=!0));else{j++;let b=n?.boundingBox?.y,w=r.getBoundingClientRect().y;(p===n?.isBelow&&b===w||j<200)&&(f=!1)}if(f)return{isBelow:p,willStayInSamePosition:f};u?m+=y/2:p?m+=y+x/2:m-=g/2;let C=0;u||(p?C=-Ve:C=Ve);let k=m-a+C,S=No-e;return o.style.width=`calc(${h}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${S}px, calc(${k}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?p?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),j=0,{isBelow:p,willStayInSamePosition:f}}var ko="draggable-block-menu",Qe="application/x-lexical-drag-block",ee=1/0;function Xe(t){return t===0?1/0:ee>=0&&ee<t?ee:Math.floor(t/2)}function Do(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function Ze(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function To(t,e,o){let r=e.parentElement,n=fe(null),c=fe(null),i=fe(null),l=fe(!1),[d,u]=Je(null),[y,s]=Je(null),{editorConfig:a}=R(),h=a?.admin?.hideGutter?-44:-8;be(()=>{function m(p){let f=p.target;if(!Ce(f))return;let C=Y(r,p.pageX,p.pageY,f);if(C===-1){u(null);return}if(ce(f,ko))return;let k=H(t),{blockElem:S,foundAtIndex:b,isFoundNodeEmptyParagraph:w}=G({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-C,point:new _(p.x,p.y),startIndex:Xe(k.length),useEdgeAsDefault:!1,verbose:!1});ee=b,!(!S&&!w)&&d!==S&&u(S)}return document?.addEventListener("mousemove",m),()=>{document?.removeEventListener("mousemove",m)}},[r,e,t,d]),be(()=>{n.current&&de(d,n.current,e,h)},[e,d,h]),be(()=>{function m(f){if(!l.current)return!1;let[C]=Ue(f);if(C)return!1;let{pageY:k,target:S}=f;if(!Ce(S))return!1;let b=Y(r,f.pageX,f.pageY,S,100,50),w=H(t),{blockElem:N,foundAtIndex:M,isFoundNodeEmptyParagraph:I}=G({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-b,point:new _(f.x,f.y),startIndex:Xe(w.length),useEdgeAsDefault:!0,verbose:!0});ee=M;let D=c.current;if(N===null||D===null)return!1;if(d!==N){let{isBelow:T,willStayInSamePosition:J}=Ge(a?.admin?.hideGutter?"0px":"3rem",h+(a?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),D,N,y,k,e,f,i,I);f.preventDefault(),J||s({boundingBox:N.getBoundingClientRect(),elem:N,isBelow:T})}else y?.elem&&(Ze(D,y.elem),s({boundingBox:N.getBoundingClientRect(),elem:N,isBelow:!1}));return!0}function p(f){if(!l.current)return!1;let[C]=Ue(f);if(C)return!1;let{dataTransfer:k,pageY:S,target:b}=f,w=k?.getData(Qe)||"";return t.update(()=>{let N=Ro(w);if(!N||!Ce(b))return!1;let M=Y(r,f.pageX,f.pageY,b,100,50),{blockElem:I,isFoundNodeEmptyParagraph:D}=G({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-M,point:new _(f.x,f.y),useEdgeAsDefault:!0});if(!I)return!1;let T=qe(I);if(!T)return!1;if(T===N)return!0;let{height:J,top:he}=V(I),z=S>=he+J/2+window.scrollY;D?(T.insertBefore(N),T.remove()):z?T.insertAfter(N):T.insertBefore(N),d!==null&&u(null),document.querySelectorAll(".lexical-block-highlighter").forEach(v=>{v.remove()});let oe=t.getElementByKey(N.getKey());setTimeout(()=>{let v=oe?.getBoundingClientRect();if(!v)return;let P=document.createElement("div");P.className="lexical-block-highlighter",P.style.backgroundColor="var(--theme-elevation-1000",P.style.transition="opacity 0.5s ease-in-out",P.style.zIndex="1",P.style.pointerEvents="none",P.style.boxSizing="border-box",P.style.borderRadius="4px",P.style.position="absolute",document.body.appendChild(P),P.style.opacity="0.1",P.style.height=`${v.height+8}px`,P.style.width=`${v.width+8}px`,P.style.top=`${v.top+window.scrollY-4}px`,P.style.left=`${v.left-4}px`,setTimeout(()=>{P.style.opacity="0",setTimeout(()=>{P.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",m),document.addEventListener("drop",p),()=>{document.removeEventListener("dragover",m),document.removeEventListener("drop",p)}},[r,h,e,t,y,d,a?.admin?.hideGutter]);function x(m){let p=m.dataTransfer;if(!p||!d)return;Do(p,d);let f="";t.update(()=>{let C=qe(d);C&&(f=C.getKey())}),l.current=!0,p.setData(Qe,f)}function g(){l.current=!1,y?.elem&&Ze(c.current,y?.elem)}return wo(Po(et.Fragment,{children:[me("button",{"aria-label":"Drag to move",className:"icon draggable-block-menu",draggable:!0,onDragEnd:g,onDragStart:x,ref:n,type:"button",children:me("div",{className:o?"icon":""})}),me("div",{className:"draggable-block-target-line",ref:c}),me("div",{className:"debug-highlight",ref:i})]}),e)}function tt(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=So();return To(r,o,r._editable)}import{c as vo}from"react/compiler-runtime";import{jsx as Ne}from"react/jsx-runtime";import{useLexicalComposerContext as Mo}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Lo,$getRoot as Ao}from"lexical";import"react";var ot="insert-paragraph-at-end",nt=()=>{let t=vo(2),[e]=Mo(),{editorConfig:o}=R();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;return t[0]!==e?(r=Ne("div",{"aria-label":"Insert Paragraph",className:ot,onClick:()=>{e.update(Bo)},role:"button",tabIndex:0,children:Ne("div",{className:`${ot}-inside`,children:Ne("span",{children:"+"})})}),t[0]=e,t[1]=r):r=t[1],r};function Bo(){let t=Lo();Ao().append(t),t.select()}import{c as Io}from"react/compiler-runtime";import{useLexicalComposerContext as _o}from"@lexical/react/LexicalComposerContext";import*as rt from"react";var it=()=>{let t=Io(4),{editorConfig:e}=R(),[o]=_o(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>we(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),rt.useEffect(r,n),null};import{useLexicalComposerContext as Oo}from"@lexical/react/LexicalComposerContext";import{$getSelection as Fo,$isRangeSelection as $o,RootNode as Ko}from"lexical";import{useEffect as Ho}from"react";function st(){let[t]=Oo();return Ho(()=>t.registerNodeTransform(Ko,e=>{let o=Fo();if($o(o)){let r=o.anchor.getNode(),n=o.focus.getNode();(!r.isAttached()||!n.isAttached())&&(e.selectEnd(),console.warn("updateEditor: selection has been moved to the end of the editor because the previously selected nodes have been removed and selection wasn't moved to another node. Ensure selection changes after removing/replacing a selected node."))}return!1}),[t]),null}import{useLexicalComposerContext as jo}from"@lexical/react/LexicalComposerContext";import{$getSelection as zo,COMMAND_PRIORITY_LOW as Wo,SELECT_ALL_COMMAND as Yo}from"lexical";import{useEffect as Vo}from"react";function lt(){let[t]=jo();return Vo(()=>t.registerCommand(Yo,()=>{if(zo())return!1;let o=document.activeElement;return o instanceof HTMLInputElement&&o.select(),!0},Wo),[t]),null}import{jsx as U,jsxs as ct}from"react/jsx-runtime";import{useLexicalComposerContext as Uo}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as dt}from"@payloadcms/ui";import{useCallback as qo,useMemo as Jo,useState as Qo}from"react";import"react";import*as ut from"react-dom";import{c as Go}from"react/compiler-runtime";import"react";function at(t,e){let o=Go(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,i=n===void 0?1:n,l;return o[0]!==c||o[1]!==i||o[2]!==t?(l=d=>{let{query:u}=d,y="[^"+t+De+"\\s]",a=new RegExp("(^|\\s|\\()(["+t+"]((?:"+y+"){0,"+c+"}))$").exec(u);if(a!==null){let h=a[1],x=a[3];if(x.length>=i)return{leadOffset:a.index+h.length,matchingString:x,replaceableString:a[2]}}return null},o[0]=c,o[1]=i,o[2]=t,o[3]=l):l=o[3],l}var B="slash-menu-popup";function Xo({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:i}}=R(),{i18n:l}=dt(),d=`${B}__item ${B}__item-${e.key}`;t&&(d+=` ${B}__item--selected`);let u=e.key;return e.label&&(u=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:l,schemaPath:i}):e.label),u.length>25&&(u=u.substring(0,25)+"..."),ct("button",{"aria-selected":t,className:d,id:B+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&U(e.Icon,{}),U("span",{className:`${B}__item-text`,children:u})]},e.key)}function mt({anchorElem:t=document.body}){let[e]=Uo(),[o,r]=Qo(null),{editorConfig:n}=R(),{i18n:c}=dt(),{fieldProps:{featureClientSchemaMap:i,schemaPath:l}}=R(),d=at("/",{minLength:0}),u=qo(()=>{let s=[];for(let a of n.features.slashMenu.dynamicGroups)if(o){let h=a({editor:e,queryString:o});s=s.concat(h)}return s},[e,o,n?.features]),y=Jo(()=>{let s=[];for(let a of n?.features.slashMenu.groups??[])s.push(a);if(o){s=s.map(h=>{let x=h.items.filter(g=>{let m=g.key;return g.label&&(m=typeof g.label=="function"?g.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):g.label),new RegExp(o,"gi").exec(m)?!0:g.keywords!=null?g.keywords.some(p=>new RegExp(o,"gi").exec(p)):!1});return x.length?{...h,items:x}:null}),s=s.filter(h=>h!=null);let a=u();for(let h of a){let x=s.find(g=>g.key===h.key);x?s=s.filter(g=>g.key!==h.key):x={...h,items:[]},x?.items?.length&&(x.items=x.items.concat(x.items)),s.push(x)}}return s},[o,n?.features.slashMenu.groups,u,i,c,l]);return U(ve,{anchorElem:t,groups:y,menuRenderFn:(s,{selectedItemKey:a,selectItemAndCleanUp:h,setSelectedItemKey:x})=>s.current&&y.length?ut.createPortal(U("div",{className:B,children:y.map(g=>{let m=g.key;return g.label&&i&&(m=typeof g.label=="function"?g.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):g.label),ct("div",{className:`${B}__group ${B}__group-${g.key}`,children:[U("div",{className:`${B}__group-title`,children:m}),g.items.map((p,f)=>U(Xo,{index:f,isSelected:a===p.key,item:p,onClick:()=>{x(p.key),h(p)},onMouseEnter:()=>{x(p.key)},ref:C=>{p.ref={current:C}}},p.key))]},g.key)})}),s.current):null,onQueryChange:r,triggerFn:d})}import{c as Zo}from"react/compiler-runtime";import{useLexicalComposerContext as en}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as tn,TextNode as on}from"lexical";import{useEffect as nn}from"react";function ft(t){let e=Zo(6),{features:o}=t,[r]=en(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let i=rn(o.enabledFormats);if(i.length!==0)return r.registerNodeTransform(on,l=>{i.forEach(d=>{l.hasFormat(d)&&l.toggleFormat(d)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],nn(n,c),null}function rn(t){let e=Object.keys(tn),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as sn}from"react/compiler-runtime";import{jsx as pt}from"react/jsx-runtime";import{ContentEditable as ln}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as an}from"@payloadcms/ui";import"react";function gt(t){let e=sn(4),{className:o,editorConfig:r}=t,{t:n}=an(),c;return e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n?(c=pt(ln,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:pt("p",{className:"editor-placeholder",children:r?.admin?.placeholder??n("lexical:general:placeholder")})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c):c=e[3],c}var yt=t=>{let e=cn(12),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,i=R(),[l]=dn(),d=gn(),[u,y]=En(null),s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=m=>{m!==null&&y(m)},e[0]=s):s=e[0];let a=s,h,x;e[1]!==l||e[2]!==i?(h=()=>{if(!i?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}i?.parentEditor?.uuid&&i.parentEditor?.registerChild(i.uuid,i);let m=()=>{i.focusEditor(i)},p=()=>{i.blurEditor(i)},f=l.registerCommand(yn,()=>(m(),!0),ht),C=l.registerCommand(hn,()=>(p(),!0),ht);return()=>{f(),C(),i.parentEditor?.unregisterChild?.(i.uuid)}},x=[l,i],e[1]=l,e[2]=i,e[3]=h,e[4]=x):(h=e[3],x=e[4]),xn(h,x);let g;return e[5]!==o||e[6]!==r||e[7]!==u||e[8]!==d||e[9]!==n||e[10]!==c?(g=te(q.Fragment,{children:[o.features.plugins?.map(Cn),te("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(bn),E(pn,{contentEditable:E("div",{className:"editor-scroller",children:E("div",{className:"editor",ref:a,children:E(gt,{editorConfig:o})})}),ErrorBoundary:un}),E(st,{}),d&&E(nt,{}),E(Fe,{}),E(Ie,{}),E(ft,{features:o.features}),E(lt,{}),d&&E(fn,{ignoreSelectionChange:!0,onChange:(m,p,f)=>{(!f.has("focus")||f.size>1)&&c?.(m,p,f)}}),u&&te(q.Fragment,{children:[!n&&d&&te(q.Fragment,{children:[o.admin?.hideDraggableBlockElement?null:E(tt,{anchorElem:u}),o.admin?.hideAddBlockButton?null:E(Ye,{anchorElem:u})]}),o.features.plugins?.map(m=>{if(m.position==="floatingAnchorElem"&&!(m.desktopOnly===!0&&n))return E($,{anchorElem:u,clientProps:m.clientProps,plugin:m},m.key)}),d&&E(q.Fragment,{children:E(mt,{anchorElem:u})})]}),d&&te(q.Fragment,{children:[E(mn,{}),o?.features?.markdownTransformers?.length>0&&E(it,{})]}),o.features.plugins?.map(Nn),o.features.plugins?.map(Pn)]}),o.features.plugins?.map(Sn)]}),e[5]=o,e[6]=r,e[7]=u,e[8]=d,e[9]=n,e[10]=c,e[11]=g):g=e[11],g};function Cn(t){if(t.position==="aboveContainer")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function bn(t){if(t.position==="top")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Nn(t){if(t.position==="normal")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Pn(t){if(t.position==="bottom")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Sn(t){if(t.position==="belowContainer")return E($,{clientProps:t.clientProps,plugin:t},t.key)}var Et=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?O(o,{children:O(Et,{providers:e.slice(1),children:t})}):O(o,{children:t})},Ct=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:i,value:l}=t,d=R(),u=wn(),y=xt.useRef(null),s=kn(()=>{if(l&&typeof l!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(l));if(l&&Array.isArray(l)&&!("root"in l))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(l&&"jsonContent"in l)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:i!==!0,editorState:l!=null?JSON.stringify(l):void 0,namespace:o.lexical.namespace,nodes:Le({editorConfig:o}),onError:a=>{throw a},theme:o.lexical.theme}},[o]);return s?O(Rn,{initialConfig:s,children:O(Re,{editorConfig:o,editorContainerRef:y,fieldProps:r,parentContext:d?.editDepth===u?d:void 0,children:O(Et,{providers:o.features.providers,children:O(yt,{editorConfig:o,editorContainerRef:y,isSmallWidthViewport:n,onChange:c})})})},e+s.editable):O("p",{children:"Loading..."})};var pe="rich-text-lexical",Fn=t=>{let{editorConfig:e,field:o,field:{admin:{className:r,description:n,readOnly:c}={},label:i,localized:l,required:d},path:u,readOnly:y,validate:s}=t,a=y||c,h=Mn(),x=Pt((L,Q)=>typeof s=="function"?s(L,{...Q,required:d}):!0,[s,d]),{customComponents:{AfterInput:g,BeforeInput:m,Description:p,Error:f,Label:C}={},disabled:k,initialValue:S,path:b,setValue:w,showError:N,value:M}=An({potentiallyStalePath:u,validate:x}),I=a||k,[D,T]=Rt(!1),[J,he]=Rt(),ye=Nt.useRef(S),z=Nt.useRef(M);St(()=>{let L=()=>{let Q=window.matchMedia("(max-width: 768px)").matches;Q!==D&&T(Q)};return L(),window.addEventListener("resize",L),()=>{window.removeEventListener("resize",L)}},[D]);let Pe=[pe,"field-type",r,N&&"error",I&&`${pe}--read-only`,e?.admin?.hideGutter!==!0&&!D?`${pe}--show-gutter`:null].filter(Boolean).join(" "),oe=`${b}.${h}`,v=ke(),P=Pt(L=>{v(()=>{let Se=L.toJSON();z.current=Se,w(Se)})},[w,v]),wt=_n(()=>Bn(o),[o]),kt=Ln(L=>{z.current!==M&&!In(JSON.parse(JSON.stringify(z.current)),M)&&(ye.current=L,z.current=M,he(new Date))});return St(()=>{Object.is(S,ye.current)||kt(S)},[S]),ge("div",{className:Pe,style:wt,children:[F(bt,{CustomComponent:f,Fallback:F(Tn,{path:b,showError:N})}),C||F(vn,{label:i,localized:l,path:b,required:d}),ge("div",{className:`${pe}__wrap`,children:[ge(On,{fallbackRender:$n,onReset:()=>{},children:[m,F(Ct,{composerKey:oe,editorConfig:e,fieldProps:t,isSmallWidthViewport:D,onChange:P,readOnly:I,value:M},JSON.stringify({path:b,rerenderProviderKey:J})),g]}),F(bt,{CustomComponent:p,Fallback:F(Dn,{description:n,path:b})})]})]},oe)};function $n({error:t}){return ge("div",{className:"errorBoundary",role:"alert",children:[F("p",{children:"Something went wrong:"}),F("pre",{style:{color:"red"},children:t.message})]})}var Ms=Fn;export{Ms as RichText};
2
- //# sourceMappingURL=Field-YHS7VMOE.js.map
1
+ "use client";import{a as we,e as ke,f as _,h as De,i as Te,j as ve,k as Me,l as Le}from"./chunk-AFXLIYGL.js";import{a as Re,b as R}from"./chunk-BZZVLW4U.js";import{jsx as F,jsxs as ge}from"react/jsx-runtime";import{FieldDescription as Dn,FieldError as Tn,FieldLabel as vn,RenderCustomComponent as bt,useEditDepth as Mn,useEffectEvent as Ln,useField as An}from"@payloadcms/ui";import{mergeFieldStyles as Bn}from"@payloadcms/ui/shared";import{dequal as In}from"dequal/lite";import Nt,{useCallback as Pt,useEffect as St,useMemo as _n,useState as Rt}from"react";import{ErrorBoundary as On}from"react-error-boundary";import"./bundled.css";import{jsx as O}from"react/jsx-runtime";import{LexicalComposer as Rn}from"@lexical/react/LexicalComposer.js";import{useEditDepth as wn}from"@payloadcms/ui";import*as xt from"react";import{useMemo as kn}from"react";import{c as cn}from"react/compiler-runtime";import{jsx as E,jsxs as te}from"react/jsx-runtime";import{useLexicalComposerContext as dn}from"@lexical/react/LexicalComposerContext.js";import{LexicalErrorBoundary as un}from"@lexical/react/LexicalErrorBoundary.js";import{HistoryPlugin as mn}from"@lexical/react/LexicalHistoryPlugin.js";import{OnChangePlugin as fn}from"@lexical/react/LexicalOnChangePlugin.js";import{RichTextPlugin as pn}from"@lexical/react/LexicalRichTextPlugin.js";import{useLexicalEditable as gn}from"@lexical/react/useLexicalEditable";import{BLUR_COMMAND as hn,COMMAND_PRIORITY_LOW as ht,FOCUS_COMMAND as yn}from"lexical";import*as q from"react";import{useEffect as xn,useState as En}from"react";import{jsx as Ae}from"react/jsx-runtime";import"react";var $=({anchorElem:t,clientProps:e,plugin:o})=>o.position==="floatingAnchorElem"&&t?o.Component&&Ae(o.Component,{anchorElem:t,clientProps:e}):o.Component&&Ae(o.Component,{clientProps:e});import{c as Dt}from"react/compiler-runtime";import{copyToClipboard as Tt}from"@lexical/clipboard";import{useLexicalComposerContext as vt}from"@lexical/react/LexicalComposerContext.js";import{objectKlassEquals as Mt}from"@lexical/utils";import Be from"bson-objectid";import{COMMAND_PRIORITY_LOW as Lt,COPY_COMMAND as At}from"lexical";import{useEffect as Bt}from"react";function Ie(){let t=Dt(3),[e]=vt(),o,r;return t[0]!==e?(o=()=>e.registerCommand(At,n=>(Tt(e,Mt(n,ClipboardEvent)?n:null).then(()=>{if(!(n instanceof ClipboardEvent)||!n.clipboardData)throw new Error("No clipboard event");let c=n.clipboardData.getData("application/x-lexical-editor");if(!c)return!0;let i=JSON.parse(c),l=u=>{if("fields"in u&&typeof u.fields=="object"&&u.fields!==null&&"id"in u.fields?u.fields.id=new Be.default().toHexString():"id"in u&&(u.id=new Be.default().toHexString()),u.children)for(let y of u.children)l(y)};for(let u of i.nodes)l(u);let d=JSON.stringify(i);n.clipboardData.setData("application/x-lexical-editor",d)}).catch(c=>{throw n instanceof ClipboardEvent&&n.clipboardData?.setData("application/x-lexical-editor",""),c}),!0),Lt),r=[e],t[0]=e,t[1]=o,t[2]=r):(o=t[1],r=t[2]),Bt(o,r),null}import{c as It}from"react/compiler-runtime";import{useLexicalComposerContext as _t}from"@lexical/react/LexicalComposerContext";import{$findMatchingParent as ne,mergeRegister as Ot}from"@lexical/utils";import{$createNodeSelection as Ft,$getEditor as X,$getNearestNodeFromDOMNode as $t,$getSelection as re,$isDecoratorNode as K,$isElementNode as xe,$isLineBreakNode as Kt,$isNodeSelection as ie,$isRangeSelection as _e,$isRootOrShadowRoot as Ht,$isTextNode as jt,$setSelection as Oe,CLICK_COMMAND as zt,COMMAND_PRIORITY_LOW as W,KEY_ARROW_DOWN_COMMAND as Wt,KEY_ARROW_UP_COMMAND as Yt,KEY_BACKSPACE_COMMAND as Vt,KEY_DELETE_COMMAND as Gt,SELECTION_CHANGE_COMMAND as Ut}from"lexical";import{useEffect as qt}from"react";function Fe(){let t=It(3),[e]=_t(),o=oo,r,n;return t[0]!==e?(r=()=>Ot(e.registerCommand(zt,to,W),e.registerCommand(Gt,o,W),e.registerCommand(Vt,o,W),e.registerCommand(Ut,eo,W),e.registerCommand(Yt,Xt,W),e.registerCommand(Wt,Jt,W)),n=[e],t[0]=e,t[1]=r,t[2]=n):(r=t[1],n=t[2]),qt(r,n),null}function Jt(t){let e=re();if(ie(e)){t.preventDefault();let i=e.getNodes()[0]?.getNextSibling();if(K(i)){let u=X().getElementByKey(i.getKey());return u&&Z({element:u,node:i}),!0}if(!xe(i))return!0;let l=i.getFirstDescendant()??i;return l&&(ne(l,se)?.selectEnd(),t.preventDefault()),!0}if(!_e(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=ne(r,Qt),c=n?.getNextSibling();if(!n||c!==$e(n))return!1;if(K(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Qt(t){return $e(t)!==null}function Xt(t){let e=re();if(ie(e)){let i=e.getNodes()[0]?.getPreviousSibling();if(K(i)){let u=X().getElementByKey(i.getKey());return u?(Z({element:u,node:i}),t.preventDefault(),!0):!1}if(!xe(i))return!1;let l=i.getLastDescendant()??i;return l?(ne(l,se)?.selectStart(),t.preventDefault(),!0):!1}if(!_e(e))return!1;let r=(e.isBackward()?e.anchor:e.focus).getNode(),n=ne(r,Zt),c=n?.getPreviousSibling();if(!n||c!==Ke(n))return!1;if(K(c)){let i=X().getElementByKey(c.getKey());if(i)return Z({element:i,node:c}),t.preventDefault(),!0}return!1}function Zt(t){return Ke(t)!==null}function eo(){let t=io();return document.querySelector(".decorator-selected")?.classList.remove("decorator-selected"),t?(t.element?.classList.add("decorator-selected"),!0):!1}function to(t){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let e=ro(t);if(!e)return!0;let{target:o}=t;return!(o instanceof HTMLElement)||o.isContentEditable||o.closest('button, textarea, input, .react-select, .code-editor, .no-select-decorator, [role="button"]')?Oe(null):Z(e),!0}function oo(t){let e=re();return ie(e)?(t.preventDefault(),e.getNodes().forEach(no),!0):!1}function no(t){t.remove()}function ro(t){if(!(t.target instanceof HTMLElement))return;let e=t.target.closest('[data-lexical-decorator="true"]');if(!(e instanceof HTMLElement))return;let o=$t(e);return K(o)?{element:e,node:o}:void 0}function io(){let t=re();if(!ie(t))return;let e=t.getNodes();if(e.length!==1)return;let o=e[0];return K(o)?{decorator:o,element:X().getElementByKey(o.getKey())}:void 0}function Z({element:t,node:e}){document.querySelector(".decorator-selected")?.classList.remove("decorator-selected");let o=Ft();o.add(e.getKey()),Oe(o),t.scrollIntoView({behavior:"smooth",block:"nearest"}),t.classList.add("decorator-selected")}function se(t){if(K(t)&&!t.isInline())return!0;if(!xe(t)||Ht(t))return!1;let e=t.getFirstChild(),o=e===null||Kt(e)||jt(e)||e.isInline();return!t.isInline()&&t.canBeEmpty()!==!1&&o}function $e(t){let e=t.getNextSibling();for(;e!==null;){if(se(e))return e;e=e.getNextSibling()}return null}function Ke(t){let e=t.getPreviousSibling();for(;e!==null;){if(se(e))return e;e=e.getPreviousSibling()}return null}import{jsx as Ee}from"react/jsx-runtime";import{useLexicalComposerContext as mo}from"@lexical/react/LexicalComposerContext.js";import{$createParagraphNode as fo,isHTMLElement as po}from"lexical";import*as We from"react";import{useCallback as go,useEffect as ze,useRef as ho,useState as yo}from"react";import{createPortal as xo}from"react-dom";var Y=(t,e,o,r,n=50,c=25)=>{let i=0;if(t&&!t.contains(r)){let{bottom:l,left:d,right:u,top:y}=t.getBoundingClientRect(),s=y+window.scrollY,a=l+window.scrollY;if(o<s-c||o>a+c||e<d-n||e>u+n)return-1;(e<d||e>u)&&(i=e<d?e-d:e-u)}return i};import{$getNodeByKey as ae}from"lexical";function V(t){let e=t.getBoundingClientRect(),o=getComputedStyle(t).getPropertyValue("transform");if(!o||o==="none")return e;let r=o.split(",").pop();return e.y=e.y-Number(r?.replace(")","")),e}function le(t){let e=(d,u)=>d?parseFloat(window.getComputedStyle(d)[u]):0,{marginBottom:o,marginTop:r}=window.getComputedStyle(t),n=e(t.previousElementSibling,"marginBottom"),c=e(t.nextElementSibling,"marginTop"),i=Math.max(parseFloat(r),n);return{marginBottom:Math.max(parseFloat(o),c),marginTop:i}}import{$getRoot as so}from"lexical";function H(t){return t.getEditorState().read(()=>so().getChildrenKeys())}var lo=1,ao=-1,He=0,A={props:null,result:null};function co(t,e,o=20){let r=t.x-e.x,n=t.y-e.y;return r*r+n*n<=o*o}function G(t){let{anchorElem:e,cache_threshold:o=20,editor:r,fuzzy:n=!1,horizontalOffset:c=0,point:{x:i,y:l},startIndex:d=0,useEdgeAsDefault:u=!1}=t;if(o>0&&A.props&&A.result&&A.props.fuzzy===t.fuzzy&&A.props.horizontalOffset===t.horizontalOffset&&A.props.useEdgeAsDefault===t.useEdgeAsDefault&&co(A.props.point,t.point,o))return A.result;let y=e.getBoundingClientRect(),s=H(r),a={blockElem:null,blockNode:null,distance:1/0,foundAtIndex:-1,isFoundNodeEmptyParagraph:!1};return r.getEditorState().read(()=>{if(u){let g=r.getElementByKey(s[0]),m=r.getElementByKey(s[s.length-1]);if(g&&m){let[p,f]=[V(g),V(m)];if(l<p.top?(a.blockElem=g,a.distance=p.top-l,a.blockNode=ae(s[0]),a.foundAtIndex=0):l>f.bottom&&(a.distance=l-f.bottom,a.blockNode=ae(s[s.length-1]),a.blockElem=m,a.foundAtIndex=s.length-1),a?.blockElem)return{blockElem:null,isFoundNodeEmptyParagraph:!1}}}let h=d,x=He;for(;h>=0&&h<s.length;){let g=s[h],m=r.getElementByKey(g);if(m===null)break;let p=new _(i+c,l),f=Me.fromDOMRect(V(m)),{marginBottom:C,marginTop:k}=le(m),S=f.generateNewRect({bottom:f.bottom+C,left:y.left,right:y.right,top:f.top-k}),{distance:b,isOnBottomSide:w,isOnTopSide:N}=S.distanceFromPoint(p);if(b===0){a.blockElem=m,a.blockNode=ae(g),a.foundAtIndex=h,a.distance=b,a.blockNode&&a.blockNode.getType()==="paragraph"&&a.blockNode.getTextContent()===""&&(!n&&!t.returnEmptyParagraphs&&(a.blockElem=null,a.blockNode=null),a.isFoundNodeEmptyParagraph=!0);break}else n&&b<a.distance&&(a.blockElem=m,a.blockNode=ae(g),a.distance=b,a.foundAtIndex=h);x===He&&(N?x=ao:w?x=lo:x=1/0),h+=x}}),A.props=t,A.result={blockElem:a.blockElem,blockNode:a.blockNode,foundAtIndex:a.foundAtIndex,isFoundNodeEmptyParagraph:a.isFoundNodeEmptyParagraph},{blockElem:a.blockElem,blockNode:a.blockNode,foundAtIndex:a.foundAtIndex,isFoundNodeEmptyParagraph:a.isFoundNodeEmptyParagraph}}function ce(t,e){return!!t.closest(`.${e}`)}var uo=["IMG","INPUT","TEXTAREA","SELECT","BUTTON","VIDEO","OBJECT","EMBED","IFRAME","HR"];function je(t){if(!t||uo.includes(t.tagName)||t.offsetHeight===0||t.offsetWidth===0)return!1;let e=window.getComputedStyle(t);return!(e.display==="table-cell"||e.position==="absolute"||e.visibility==="hidden"||e.opacity==="0")}function de(t,e,o,r=0){if(!t){e.style.opacity="0",e.style.transform="translate(-10000px, -10000px)";return}let n=t.getBoundingClientRect(),c=window.getComputedStyle(t),i=e.getBoundingClientRect(),l=o.getBoundingClientRect(),d;if(["lexical-block","lexical-upload","lexical-relationship"].some(s=>t.firstElementChild?.classList.contains(s)))d=n.top+8-l.top;else{let s=je(t)?parseInt(c.lineHeight,10):0;d=n.top+(s-i.height)/2-l.top}let y=r;e.style.opacity="1",e.style.transform=`translate(${y}px, ${d}px)`}var Eo="add-block-menu",ue=1/0;function Co(t){return t===0?1/0:ue>=0&&ue<t?ue:Math.floor(t/2)}function bo(t,e,o){let r=e.parentElement,{editorConfig:n}=R(),c=n?.admin?.hideGutter?-24:12,i=ho(null),[l,d]=yo(null);ze(()=>{function y(s){let a=s.target;if(!po(a))return;let h=Y(r,s.pageX,s.pageY,a);if(h===-1){d(null);return}if(ce(a,Eo))return;let x=H(t),{blockElem:g,blockNode:m,foundAtIndex:p}=G({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-h,point:new _(s.x,s.y),returnEmptyParagraphs:!0,startIndex:Co(x.length),useEdgeAsDefault:!1});ue=p,g&&m&&(l?.node!==m||l?.elem!==g)&&d({elem:g,node:m})}return document?.addEventListener("mousemove",y),()=>{document?.removeEventListener("mousemove",y)}},[r,e,t,l]),ze(()=>{i.current&&l?.node&&de(l?.elem,i.current,e,c)},[e,l,c]);let u=go(y=>{let s=l;s?.node&&(t.update(()=>{let a=!0;if((s?.node.getType()!=="paragraph"||s.node.getTextContent()!=="")&&(a=!1),!a){let h=fo();s?.node.insertAfter(h),setTimeout(()=>{s={elem:t.getElementByKey(h.getKey()),node:h},d(s)},0)}}),setTimeout(()=>{t.update(()=>{t.focus(),s?.node&&"select"in s.node&&typeof s.node.select=="function"&&s.node.select()})},1),setTimeout(()=>{t.dispatchCommand(Te,{node:s?.node})},2),y.stopPropagation(),y.preventDefault())},[t,l]);return xo(Ee(We.Fragment,{children:Ee("button",{"aria-label":"Add block",className:"icon add-block-menu",onClick:y=>{u(y)},ref:i,type:"button",children:Ee("div",{className:o?"icon":""})})}),e)}function Ye(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=mo();return bo(r,o,r._editable)}import{jsx as me,jsxs as Po}from"react/jsx-runtime";import{useLexicalComposerContext as So}from"@lexical/react/LexicalComposerContext.js";import{eventFiles as Ue}from"@lexical/rich-text";import{$getNearestNodeFromDOMNode as qe,$getNodeByKey as Ro,isHTMLElement as Ce}from"lexical";import*as et from"react";import{useEffect as be,useRef as fe,useState as Je}from"react";import{createPortal as wo}from"react-dom";var Ve=0,No=-24;var j=0;function Ge(t,e,o,r,n,c,i,l,d,u=!1){let{height:y,top:s}=r.getBoundingClientRect(),{top:a,width:h}=i.getBoundingClientRect(),{marginBottom:x,marginTop:g}=le(r),m=s,p=c>=s+y/2+window.scrollY,f=!1;if(n?.elem)if(r!==n?.elem)(p&&n?.elem&&n?.elem===r.nextElementSibling||!p&&n?.elem&&n?.elem===r.previousElementSibling)&&(j++,j<200&&(f=!0));else{j++;let b=n?.boundingBox?.y,w=r.getBoundingClientRect().y;(p===n?.isBelow&&b===w||j<200)&&(f=!1)}if(f)return{isBelow:p,willStayInSamePosition:f};u?m+=y/2:p?m+=y+x/2:m-=g/2;let C=0;u||(p?C=-Ve:C=Ve);let k=m-a+C,S=No-e;return o.style.width=`calc(${h}px - ${t})`,o.style.opacity=".8",o.style.transform=`translate(${S}px, calc(${k}px - 2px))`,n?.elem&&(n.elem.style.opacity="",n?.elem===r?p?n.elem.style.marginTop="":n.elem.style.marginBottom="":(n.elem.style.marginBottom="",n.elem.style.marginTop="")),j=0,{isBelow:p,willStayInSamePosition:f}}var ko="draggable-block-menu",Qe="application/x-lexical-drag-block",ee=1/0;function Xe(t){return t===0?1/0:ee>=0&&ee<t?ee:Math.floor(t/2)}function Do(t,e){let{transform:o}=e.style;t.setDragImage(e,0,0),setTimeout(()=>{e.style.transform=o})}function Ze(t,e){t&&(t.style.opacity="0"),e&&(e.style.opacity="",e.style.marginBottom="",e.style.marginTop="")}function To(t,e,o){let r=e.parentElement,n=fe(null),c=fe(null),i=fe(null),l=fe(!1),[d,u]=Je(null),[y,s]=Je(null),{editorConfig:a}=R(),h=a?.admin?.hideGutter?-44:-8;be(()=>{function m(p){let f=p.target;if(!Ce(f))return;let C=Y(r,p.pageX,p.pageY,f);if(C===-1){u(null);return}if(ce(f,ko))return;let k=H(t),{blockElem:S,foundAtIndex:b,isFoundNodeEmptyParagraph:w}=G({anchorElem:e,cache_threshold:0,editor:t,horizontalOffset:-C,point:new _(p.x,p.y),startIndex:Xe(k.length),useEdgeAsDefault:!1,verbose:!1});ee=b,!(!S&&!w)&&d!==S&&u(S)}return document?.addEventListener("mousemove",m),()=>{document?.removeEventListener("mousemove",m)}},[r,e,t,d]),be(()=>{n.current&&de(d,n.current,e,h)},[e,d,h]),be(()=>{function m(f){if(!l.current)return!1;let[C]=Ue(f);if(C)return!1;let{pageY:k,target:S}=f;if(!Ce(S))return!1;let b=Y(r,f.pageX,f.pageY,S,100,50),w=H(t),{blockElem:N,foundAtIndex:M,isFoundNodeEmptyParagraph:I}=G({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-b,point:new _(f.x,f.y),startIndex:Xe(w.length),useEdgeAsDefault:!0,verbose:!0});ee=M;let D=c.current;if(N===null||D===null)return!1;if(d!==N){let{isBelow:T,willStayInSamePosition:J}=Ge(a?.admin?.hideGutter?"0px":"3rem",h+(a?.admin?.hideGutter?n?.current?.getBoundingClientRect()?.width??0:-(n?.current?.getBoundingClientRect()?.width??0)),D,N,y,k,e,f,i,I);f.preventDefault(),J||s({boundingBox:N.getBoundingClientRect(),elem:N,isBelow:T})}else y?.elem&&(Ze(D,y.elem),s({boundingBox:N.getBoundingClientRect(),elem:N,isBelow:!1}));return!0}function p(f){if(!l.current)return!1;let[C]=Ue(f);if(C)return!1;let{dataTransfer:k,pageY:S,target:b}=f,w=k?.getData(Qe)||"";return t.update(()=>{let N=Ro(w);if(!N||!Ce(b))return!1;let M=Y(r,f.pageX,f.pageY,b,100,50),{blockElem:I,isFoundNodeEmptyParagraph:D}=G({anchorElem:e,editor:t,fuzzy:!0,horizontalOffset:-M,point:new _(f.x,f.y),useEdgeAsDefault:!0});if(!I)return!1;let T=qe(I);if(!T)return!1;if(T===N)return!0;let{height:J,top:he}=V(I),z=S>=he+J/2+window.scrollY;D?(T.insertBefore(N),T.remove()):z?T.insertAfter(N):T.insertBefore(N),d!==null&&u(null),document.querySelectorAll(".lexical-block-highlighter").forEach(v=>{v.remove()});let oe=t.getElementByKey(N.getKey());setTimeout(()=>{let v=oe?.getBoundingClientRect();if(!v)return;let P=document.createElement("div");P.className="lexical-block-highlighter",P.style.backgroundColor="var(--theme-elevation-1000",P.style.transition="opacity 0.5s ease-in-out",P.style.zIndex="1",P.style.pointerEvents="none",P.style.boxSizing="border-box",P.style.borderRadius="4px",P.style.position="absolute",document.body.appendChild(P),P.style.opacity="0.1",P.style.height=`${v.height+8}px`,P.style.width=`${v.width+8}px`,P.style.top=`${v.top+window.scrollY-4}px`,P.style.left=`${v.left-4}px`,setTimeout(()=>{P.style.opacity="0",setTimeout(()=>{P.remove()},500)},1e3)},120)}),!0}return document.addEventListener("dragover",m),document.addEventListener("drop",p),()=>{document.removeEventListener("dragover",m),document.removeEventListener("drop",p)}},[r,h,e,t,y,d,a?.admin?.hideGutter]);function x(m){let p=m.dataTransfer;if(!p||!d)return;Do(p,d);let f="";t.update(()=>{let C=qe(d);C&&(f=C.getKey())}),l.current=!0,p.setData(Qe,f)}function g(){l.current=!1,y?.elem&&Ze(c.current,y?.elem)}return wo(Po(et.Fragment,{children:[me("button",{"aria-label":"Drag to move",className:"icon draggable-block-menu",draggable:!0,onDragEnd:g,onDragStart:x,ref:n,type:"button",children:me("div",{className:o?"icon":""})}),me("div",{className:"draggable-block-target-line",ref:c}),me("div",{className:"debug-highlight",ref:i})]}),e)}function tt(t){let{anchorElem:e}=t,o=e===void 0?document.body:e,[r]=So();return To(r,o,r._editable)}import{c as vo}from"react/compiler-runtime";import{jsx as Ne}from"react/jsx-runtime";import{useLexicalComposerContext as Mo}from"@lexical/react/LexicalComposerContext";import{$createParagraphNode as Lo,$getRoot as Ao}from"lexical";import"react";var ot="insert-paragraph-at-end",nt=()=>{let t=vo(2),[e]=Mo(),{editorConfig:o}=R();if(o?.admin?.hideInsertParagraphAtEnd)return null;let r;return t[0]!==e?(r=Ne("div",{"aria-label":"Insert Paragraph",className:ot,onClick:()=>{e.update(Bo)},role:"button",tabIndex:0,children:Ne("div",{className:`${ot}-inside`,children:Ne("span",{children:"+"})})}),t[0]=e,t[1]=r):r=t[1],r};function Bo(){let t=Lo();Ao().append(t),t.select()}import{c as Io}from"react/compiler-runtime";import{useLexicalComposerContext as _o}from"@lexical/react/LexicalComposerContext";import*as rt from"react";var it=()=>{let t=Io(4),{editorConfig:e}=R(),[o]=_o(),r,n;return t[0]!==o||t[1]!==e.features.markdownTransformers?(r=()=>we(o,e.features.markdownTransformers??[]),n=[o,e.features.markdownTransformers],t[0]=o,t[1]=e.features.markdownTransformers,t[2]=r,t[3]=n):(r=t[2],n=t[3]),rt.useEffect(r,n),null};import{useLexicalComposerContext as Oo}from"@lexical/react/LexicalComposerContext";import{$getSelection as Fo,$isRangeSelection as $o,RootNode as Ko}from"lexical";import{useEffect as Ho}from"react";function st(){let[t]=Oo();return Ho(()=>t.registerNodeTransform(Ko,e=>{let o=Fo();if($o(o)){let r=o.anchor.getNode(),n=o.focus.getNode();(!r.isAttached()||!n.isAttached())&&(e.selectEnd(),console.warn("updateEditor: selection has been moved to the end of the editor because the previously selected nodes have been removed and selection wasn't moved to another node. Ensure selection changes after removing/replacing a selected node."))}return!1}),[t]),null}import{useLexicalComposerContext as jo}from"@lexical/react/LexicalComposerContext";import{$getSelection as zo,COMMAND_PRIORITY_LOW as Wo,SELECT_ALL_COMMAND as Yo}from"lexical";import{useEffect as Vo}from"react";function lt(){let[t]=jo();return Vo(()=>t.registerCommand(Yo,()=>{if(zo())return!1;let o=document.activeElement;return o instanceof HTMLInputElement&&o.select(),!0},Wo),[t]),null}import{jsx as U,jsxs as ct}from"react/jsx-runtime";import{useLexicalComposerContext as Uo}from"@lexical/react/LexicalComposerContext.js";import{useTranslation as dt}from"@payloadcms/ui";import{useCallback as qo,useMemo as Jo,useState as Qo}from"react";import"react";import*as ut from"react-dom";import{c as Go}from"react/compiler-runtime";import"react";function at(t,e){let o=Go(4),{maxLength:r,minLength:n}=e,c=r===void 0?75:r,i=n===void 0?1:n,l;return o[0]!==c||o[1]!==i||o[2]!==t?(l=d=>{let{query:u}=d,y="[^"+t+De+"\\s]",a=new RegExp("(^|\\s|\\()(["+t+"]((?:"+y+"){0,"+c+"}))$").exec(u);if(a!==null){let h=a[1],x=a[3];if(x.length>=i)return{leadOffset:a.index+h.length,matchingString:x,replaceableString:a[2]}}return null},o[0]=c,o[1]=i,o[2]=t,o[3]=l):l=o[3],l}var B="slash-menu-popup";function Xo({isSelected:t,item:e,onClick:o,onMouseEnter:r,ref:n}){let{fieldProps:{featureClientSchemaMap:c,schemaPath:i}}=R(),{i18n:l}=dt(),d=`${B}__item ${B}__item-${e.key}`;t&&(d+=` ${B}__item--selected`);let u=e.key;return e.label&&(u=typeof e.label=="function"?e.label({featureClientSchemaMap:c,i18n:l,schemaPath:i}):e.label),u.length>25&&(u=u.substring(0,25)+"..."),ct("button",{"aria-selected":t,className:d,id:B+"__item-"+e.key,onClick:o,onMouseEnter:r,ref:n,role:"option",tabIndex:-1,type:"button",children:[e?.Icon&&U(e.Icon,{}),U("span",{className:`${B}__item-text`,children:u})]},e.key)}function mt({anchorElem:t=document.body}){let[e]=Uo(),[o,r]=Qo(null),{editorConfig:n}=R(),{i18n:c}=dt(),{fieldProps:{featureClientSchemaMap:i,schemaPath:l}}=R(),d=at("/",{minLength:0}),u=qo(()=>{let s=[];for(let a of n.features.slashMenu.dynamicGroups)if(o){let h=a({editor:e,queryString:o});s=s.concat(h)}return s},[e,o,n?.features]),y=Jo(()=>{let s=[];for(let a of n?.features.slashMenu.groups??[])s.push(a);if(o){s=s.map(h=>{let x=h.items.filter(g=>{let m=g.key;return g.label&&(m=typeof g.label=="function"?g.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):g.label),new RegExp(o,"gi").exec(m)?!0:g.keywords!=null?g.keywords.some(p=>new RegExp(o,"gi").exec(p)):!1});return x.length?{...h,items:x}:null}),s=s.filter(h=>h!=null);let a=u();for(let h of a){let x=s.find(g=>g.key===h.key);x?s=s.filter(g=>g.key!==h.key):x={...h,items:[]},x?.items?.length&&(x.items=x.items.concat(x.items)),s.push(x)}}return s},[o,n?.features.slashMenu.groups,u,i,c,l]);return U(ve,{anchorElem:t,groups:y,menuRenderFn:(s,{selectedItemKey:a,selectItemAndCleanUp:h,setSelectedItemKey:x})=>s.current&&y.length?ut.createPortal(U("div",{className:B,children:y.map(g=>{let m=g.key;return g.label&&i&&(m=typeof g.label=="function"?g.label({featureClientSchemaMap:i,i18n:c,schemaPath:l}):g.label),ct("div",{className:`${B}__group ${B}__group-${g.key}`,children:[U("div",{className:`${B}__group-title`,children:m}),g.items.map((p,f)=>U(Xo,{index:f,isSelected:a===p.key,item:p,onClick:()=>{x(p.key),h(p)},onMouseEnter:()=>{x(p.key)},ref:C=>{p.ref={current:C}}},p.key))]},g.key)})}),s.current):null,onQueryChange:r,triggerFn:d})}import{c as Zo}from"react/compiler-runtime";import{useLexicalComposerContext as en}from"@lexical/react/LexicalComposerContext";import{TEXT_TYPE_TO_FORMAT as tn,TextNode as on}from"lexical";import{useEffect as nn}from"react";function ft(t){let e=Zo(6),{features:o}=t,[r]=en(),n;e[0]!==r||e[1]!==o.enabledFormats?(n=()=>{let i=rn(o.enabledFormats);if(i.length!==0)return r.registerNodeTransform(on,l=>{i.forEach(d=>{l.hasFormat(d)&&l.toggleFormat(d)})})},e[0]=r,e[1]=o.enabledFormats,e[2]=n):n=e[2];let c;return e[3]!==r||e[4]!==o?(c=[r,o],e[3]=r,e[4]=o,e[5]=c):c=e[5],nn(n,c),null}function rn(t){let e=Object.keys(tn),o=new Set(t);return e.filter(r=>!o.has(r))}import{c as sn}from"react/compiler-runtime";import{jsx as pt}from"react/jsx-runtime";import{ContentEditable as ln}from"@lexical/react/LexicalContentEditable.js";import{useTranslation as an}from"@payloadcms/ui";import"react";function gt(t){let e=sn(4),{className:o,editorConfig:r}=t,{t:n}=an(),c;return e[0]!==o||e[1]!==r?.admin?.placeholder||e[2]!==n?(c=pt(ln,{"aria-placeholder":n("lexical:general:placeholder"),className:o??"ContentEditable__root",placeholder:pt("p",{className:"editor-placeholder",children:r?.admin?.placeholder??n("lexical:general:placeholder")})}),e[0]=o,e[1]=r?.admin?.placeholder,e[2]=n,e[3]=c):c=e[3],c}var yt=t=>{let e=cn(12),{editorConfig:o,editorContainerRef:r,isSmallWidthViewport:n,onChange:c}=t,i=R(),[l]=dn(),d=gn(),[u,y]=En(null),s;e[0]===Symbol.for("react.memo_cache_sentinel")?(s=m=>{m!==null&&y(m)},e[0]=s):s=e[0];let a=s,h,x;e[1]!==l||e[2]!==i?(h=()=>{if(!i?.uuid){console.error("Lexical Editor must be used within an EditorConfigProvider");return}i?.parentEditor?.uuid&&i.parentEditor?.registerChild(i.uuid,i);let m=()=>{i.focusEditor(i)},p=()=>{i.blurEditor(i)},f=l.registerCommand(yn,()=>(m(),!0),ht),C=l.registerCommand(hn,()=>(p(),!0),ht);return()=>{f(),C(),i.parentEditor?.unregisterChild?.(i.uuid)}},x=[l,i],e[1]=l,e[2]=i,e[3]=h,e[4]=x):(h=e[3],x=e[4]),xn(h,x);let g;return e[5]!==o||e[6]!==r||e[7]!==u||e[8]!==d||e[9]!==n||e[10]!==c?(g=te(q.Fragment,{children:[o.features.plugins?.map(Cn),te("div",{className:"editor-container",ref:r,children:[o.features.plugins?.map(bn),E(pn,{contentEditable:E("div",{className:"editor-scroller",children:E("div",{className:"editor",ref:a,children:E(gt,{editorConfig:o})})}),ErrorBoundary:un}),E(st,{}),d&&E(nt,{}),E(Fe,{}),E(Ie,{}),E(ft,{features:o.features}),E(lt,{}),d&&E(fn,{ignoreSelectionChange:!0,onChange:(m,p,f)=>{(!f.has("focus")||f.size>1)&&c?.(m,p,f)}}),u&&te(q.Fragment,{children:[!n&&d&&te(q.Fragment,{children:[o.admin?.hideDraggableBlockElement?null:E(tt,{anchorElem:u}),o.admin?.hideAddBlockButton?null:E(Ye,{anchorElem:u})]}),o.features.plugins?.map(m=>{if(m.position==="floatingAnchorElem"&&!(m.desktopOnly===!0&&n))return E($,{anchorElem:u,clientProps:m.clientProps,plugin:m},m.key)}),d&&E(q.Fragment,{children:E(mt,{anchorElem:u})})]}),d&&te(q.Fragment,{children:[E(mn,{}),o?.features?.markdownTransformers?.length>0&&E(it,{})]}),o.features.plugins?.map(Nn),o.features.plugins?.map(Pn)]}),o.features.plugins?.map(Sn)]}),e[5]=o,e[6]=r,e[7]=u,e[8]=d,e[9]=n,e[10]=c,e[11]=g):g=e[11],g};function Cn(t){if(t.position==="aboveContainer")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function bn(t){if(t.position==="top")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Nn(t){if(t.position==="normal")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Pn(t){if(t.position==="bottom")return E($,{clientProps:t.clientProps,plugin:t},t.key)}function Sn(t){if(t.position==="belowContainer")return E($,{clientProps:t.clientProps,plugin:t},t.key)}var Et=({children:t,providers:e})=>{if(!e?.length)return t;let o=e[0];return e.length>1?O(o,{children:O(Et,{providers:e.slice(1),children:t})}):O(o,{children:t})},Ct=t=>{let{composerKey:e,editorConfig:o,fieldProps:r,isSmallWidthViewport:n,onChange:c,readOnly:i,value:l}=t,d=R(),u=wn(),y=xt.useRef(null),s=kn(()=>{if(l&&typeof l!="object")throw new Error("The value passed to the Lexical editor is not an object. This is not supported. Please remove the data from the field and start again. This is the value that was passed in: "+JSON.stringify(l));if(l&&Array.isArray(l)&&!("root"in l))throw new Error("You have tried to pass in data from the old Slate editor to the new Lexical editor. The data structure is different, thus you will have to migrate your data. We offer a one-line migration script which migrates all your rich text fields: https://payloadcms.com/docs/lexical/migration#migration-via-migration-script-recommended");if(l&&"jsonContent"in l)throw new Error("You have tried to pass in data from payload-plugin-lexical. The data structure is different, thus you will have to migrate your data. Migration guide: https://payloadcms.com/docs/lexical/migration#migrating-from-payload-plugin-lexical");return{editable:i!==!0,editorState:l!=null?JSON.stringify(l):void 0,namespace:o.lexical.namespace,nodes:Le({editorConfig:o}),onError:a=>{throw a},theme:o.lexical.theme}},[o]);return s?O(Rn,{initialConfig:s,children:O(Re,{editorConfig:o,editorContainerRef:y,fieldProps:r,parentContext:d?.editDepth===u?d:void 0,children:O(Et,{providers:o.features.providers,children:O(yt,{editorConfig:o,editorContainerRef:y,isSmallWidthViewport:n,onChange:c})})})},e+s.editable):O("p",{children:"Loading..."})};var pe="rich-text-lexical",Fn=t=>{let{editorConfig:e,field:o,field:{admin:{className:r,description:n,readOnly:c}={},label:i,localized:l,required:d},path:u,readOnly:y,validate:s}=t,a=y||c,h=Mn(),x=Pt((L,Q)=>typeof s=="function"?s(L,{...Q,required:d}):!0,[s,d]),{customComponents:{AfterInput:g,BeforeInput:m,Description:p,Error:f,Label:C}={},disabled:k,initialValue:S,path:b,setValue:w,showError:N,value:M}=An({potentiallyStalePath:u,validate:x}),I=a||k,[D,T]=Rt(!1),[J,he]=Rt(),ye=Nt.useRef(S),z=Nt.useRef(M);St(()=>{let L=()=>{let Q=window.matchMedia("(max-width: 768px)").matches;Q!==D&&T(Q)};return L(),window.addEventListener("resize",L),()=>{window.removeEventListener("resize",L)}},[D]);let Pe=[pe,"field-type",r,N&&"error",I&&`${pe}--read-only`,e?.admin?.hideGutter!==!0&&!D?`${pe}--show-gutter`:null].filter(Boolean).join(" "),oe=`${b}.${h}`,v=ke(),P=Pt(L=>{v(()=>{let Se=L.toJSON();z.current=Se,w(Se)})},[w,v]),wt=_n(()=>Bn(o),[o]),kt=Ln(L=>{z.current!==M&&!In(JSON.parse(JSON.stringify(z.current)),M)&&(ye.current=L,z.current=M,he(new Date))});return St(()=>{Object.is(S,ye.current)||kt(S)},[S]),ge("div",{className:Pe,style:wt,children:[F(bt,{CustomComponent:f,Fallback:F(Tn,{path:b,showError:N})}),C||F(vn,{label:i,localized:l,path:b,required:d}),ge("div",{className:`${pe}__wrap`,children:[ge(On,{fallbackRender:$n,onReset:()=>{},children:[m,F(Ct,{composerKey:oe,editorConfig:e,fieldProps:t,isSmallWidthViewport:D,onChange:P,readOnly:I,value:M},JSON.stringify({path:b,rerenderProviderKey:J})),g]}),F(bt,{CustomComponent:p,Fallback:F(Dn,{description:n,path:b})})]})]},oe)};function $n({error:t}){return ge("div",{className:"errorBoundary",role:"alert",children:[F("p",{children:"Something went wrong:"}),F("pre",{style:{color:"red"},children:t.message})]})}var Ms=Fn;export{Ms as RichText};
2
+ //# sourceMappingURL=Field-YYMTSGSP.js.map